Skip to content

Commit adee9cc

Browse files
committed
Initial Vcard
Added Vcard feature
1 parent 948b0b6 commit adee9cc

File tree

12 files changed

+2009
-1054
lines changed

12 files changed

+2009
-1054
lines changed

app/Http/Controllers/UserController.php

Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Cohensive\OEmbed\Facades\OEmbed;
88
use Illuminate\Support\Facades\Schema;
99
use Illuminate\Support\Facades\Route;
10+
use JeroenDesloovere\VCard\VCard;
1011

1112
use Auth;
1213
use DB;
@@ -144,6 +145,8 @@ public function AddUpdateLink($id = 0)
144145
$data['linkTypeID'] = "6";
145146
} elseif ($bid == 44) {
146147
$data['linkTypeID'] = "7";
148+
} elseif ($bid == 96) {
149+
$data['linkTypeID'] = "8";
147150
} else {
148151
$data['linkTypeID'] = "1";
149152
}
@@ -245,6 +248,69 @@ public function saveLink(request $request)
245248
'button_id' => $button?->id,
246249
'title' => $LinkTitle,
247250
]);
251+
}elseif($linkType->typename == "vcard"){
252+
253+
$prefix = $request->input('prefix');
254+
$firstName = $request->input('first_name');
255+
$middleName = $request->input('middle_name');
256+
$lastName = $request->input('last_name');
257+
$suffix = $request->input('suffix');
258+
$nickname = $request->input('nickname');
259+
$organization = $request->input('organization');
260+
$title = $request->input('title');
261+
$role = $request->input('role');
262+
$workUrl = $request->input('work_url');
263+
$email = $request->input('email');
264+
$workEmail = $request->input('work_email');
265+
$homePhone = $request->input('home_phone');
266+
$workPhone = $request->input('work_phone');
267+
$cellPhone = $request->input('cell_phone');
268+
$homeAddressLabel = $request->input('home_address_label');
269+
$homeAddressStreet = $request->input('home_address_street');
270+
$homeAddressCity = $request->input('home_address_city');
271+
$homeAddressState = $request->input('home_address_state');
272+
$homeAddressZip = $request->input('home_address_zip');
273+
$homeAddressCountry = $request->input('home_address_country');
274+
$workAddressLabel = $request->input('work_address_label');
275+
$workAddressStreet = $request->input('work_address_street');
276+
$workAddressCity = $request->input('work_address_city');
277+
$workAddressState = $request->input('work_address_state');
278+
$workAddressZip = $request->input('work_address_zip');
279+
$workAddressCountry = $request->input('work_address_country');
280+
281+
// Create a new vCard instance
282+
$vCard = new VCard();
283+
284+
// Set the personal information
285+
$vCard->addName($lastName, $firstName, $middleName, $prefix, $suffix);
286+
$vCard->addRole($role);
287+
288+
// Set the organization information
289+
$vCard->addCompany($organization);
290+
$vCard->addJobtitle($title);
291+
$vCard->addUrl($workUrl);
292+
293+
// Set the phone numbers
294+
$vCard->addPhoneNumber($homePhone, 'HOME');
295+
$vCard->addPhoneNumber($workPhone, 'WORK');
296+
$vCard->addPhoneNumber($cellPhone, 'CELL');
297+
298+
// Set the email addresses
299+
$vCard->addEmail($email, 'HOME');
300+
$vCard->addEmail($workEmail, 'WORK');
301+
302+
// Set the addresses
303+
$vCard->addAddress($homeAddressStreet, null, null, $homeAddressCity, $homeAddressState, $homeAddressZip, $homeAddressCountry, 'HOME', $homeAddressLabel);
304+
$vCard->addAddress($workAddressStreet, null, null, $workAddressCity, $workAddressState, $workAddressZip, $workAddressCountry, 'WORK', $workAddressLabel);
305+
306+
// Generate the vCard file content
307+
$LinkURL = $vCard->getOutput();
308+
309+
$OrigLink->update([
310+
'link' => $LinkURL,
311+
'button_id' => 96,
312+
'title' => $LinkTitle,
313+
]);
248314
}else{
249315
$OrigLink->update([
250316
'link' => $LinkURL,
@@ -286,6 +352,65 @@ public function saveLink(request $request)
286352
}elseif($linkType->typename == "telephone"){
287353
$links->link = "tel:".$links->link;
288354
$links->button_id = $button?->id;
355+
}elseif($linkType->typename == "vcard"){
356+
357+
$prefix = $request->input('prefix');
358+
$firstName = $request->input('first_name');
359+
$middleName = $request->input('middle_name');
360+
$lastName = $request->input('last_name');
361+
$suffix = $request->input('suffix');
362+
$nickname = $request->input('nickname');
363+
$organization = $request->input('organization');
364+
$title = $request->input('title');
365+
$role = $request->input('role');
366+
$workUrl = $request->input('work_url');
367+
$email = $request->input('email');
368+
$workEmail = $request->input('work_email');
369+
$homePhone = $request->input('home_phone');
370+
$workPhone = $request->input('work_phone');
371+
$cellPhone = $request->input('cell_phone');
372+
$homeAddressLabel = $request->input('home_address_label');
373+
$homeAddressStreet = $request->input('home_address_street');
374+
$homeAddressCity = $request->input('home_address_city');
375+
$homeAddressState = $request->input('home_address_state');
376+
$homeAddressZip = $request->input('home_address_zip');
377+
$homeAddressCountry = $request->input('home_address_country');
378+
$workAddressLabel = $request->input('work_address_label');
379+
$workAddressStreet = $request->input('work_address_street');
380+
$workAddressCity = $request->input('work_address_city');
381+
$workAddressState = $request->input('work_address_state');
382+
$workAddressZip = $request->input('work_address_zip');
383+
$workAddressCountry = $request->input('work_address_country');
384+
385+
// Create a new vCard instance
386+
$vCard = new VCard();
387+
388+
// Set the personal information
389+
$vCard->addName($lastName, $firstName, $middleName, $prefix, $suffix);
390+
$vCard->addRole($role);
391+
392+
// Set the organization information
393+
$vCard->addCompany($organization);
394+
$vCard->addJobtitle($title);
395+
$vCard->addUrl($workUrl);
396+
397+
// Set the phone numbers
398+
$vCard->addPhoneNumber($homePhone, 'HOME');
399+
$vCard->addPhoneNumber($workPhone, 'WORK');
400+
$vCard->addPhoneNumber($cellPhone, 'CELL');
401+
402+
// Set the email addresses
403+
$vCard->addEmail($email, 'HOME');
404+
$vCard->addEmail($workEmail, 'WORK');
405+
406+
// Set the addresses
407+
$vCard->addAddress($homeAddressStreet, null, null, $homeAddressCity, $homeAddressState, $homeAddressZip, $homeAddressCountry, 'HOME', $homeAddressLabel);
408+
$vCard->addAddress($workAddressStreet, null, null, $workAddressCity, $workAddressState, $workAddressZip, $workAddressCountry, 'WORK', $workAddressLabel);
409+
410+
// Generate the vCard file content
411+
$links->link = $vCard->getOutput();
412+
413+
$links->button_id = 96;
289414
}else{
290415
$links->button_id = $button?->id;
291416
}
@@ -353,6 +478,28 @@ public function clickNumber(request $request)
353478
return redirect()->away($link);
354479
}
355480

481+
//Download Vcard
482+
public function vcard(Request $request)
483+
{
484+
$linkId = $request->id;
485+
$link = Link::findOrFail($linkId); // find the link with the given ID or throw an exception
486+
$buttonValue = $link->button_value;
487+
$content = $link->content;
488+
489+
Link::where('id', $linkId)->increment('click_number', 1);
490+
491+
// build the vCard string
492+
$vCard = "BEGIN:VCARD\r\nVERSION:3.0\r\n";
493+
$vCard .= "FN:$buttonValue\r\n";
494+
$vCard .= "NOTE:$content\r\n";
495+
$vCard .= "END:VCARD\r\n";
496+
497+
// return the vCard content as a downloadable response
498+
return response($vCard)
499+
->header('Content-Type', 'text/vcard')
500+
->header('Content-Disposition', 'attachment; filename=vcard.vcf');
501+
}
502+
356503
//Show link, click number, up link in links page
357504
public function showLinks()
358505
{

composer.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,19 @@
66
"license": "GPL-3.0-or-later",
77
"require": {
88
"php": "^7.3|^8.0",
9-
"codedge/laravel-selfupdater": "^3.6",
109
"awssat/laravel-visits": "^4.0",
10+
"codedge/laravel-selfupdater": "^3.6",
11+
"cohensive/oembed": "^0.16",
1112
"doctrine/dbal": "^3.0",
1213
"fideloper/proxy": "^4.4",
1314
"fruitcake/laravel-cors": "^3.0",
1415
"geo-sot/laravel-env-editor": "^2.0",
1516
"guzzlehttp/guzzle": "^7.4",
17+
"jeroendesloovere/vcard": "^1.7",
1618
"laravel/framework": "^9.52.4",
1719
"laravel/socialite": "^5.5",
1820
"laravel/tinker": "^2.5",
19-
"spatie/laravel-backup": "^8.17",
20-
"cohensive/oembed": "^0.16"
21+
"spatie/laravel-backup": "^8.17"
2122
},
2223
"require-dev": {
2324
"spatie/laravel-ignition": "^1.0",

0 commit comments

Comments
 (0)