id; $littlelink_name = Auth::user()->littlelink_name; $userinfo = User::find($userId); $links = Link::where('user_id', $userId)->select('link')->count(); $clicks = Link::where('user_id', $userId)->sum('click_number'); $topLinks = Link::where('user_id', $userId)->orderby('click_number', 'desc') ->whereNotNull('link')->where('link', '<>', '') ->take(5)->get(); $pageStats = [ 'visitors' => [ 'all' => visits('App\Models\User', $littlelink_name)->count(), 'day' => visits('App\Models\User', $littlelink_name)->period('day')->count(), 'week' => visits('App\Models\User', $littlelink_name)->period('week')->count(), 'month' => visits('App\Models\User', $littlelink_name)->period('month')->count(), 'year' => visits('App\Models\User', $littlelink_name)->period('year')->count(), ], 'os' => visits('App\Models\User', $littlelink_name)->operatingSystems(), 'referers' => visits('App\Models\User', $littlelink_name)->refs(), 'countries' => visits('App\Models\User', $littlelink_name)->countries(), ]; return view('studio/index', ['greeting' => $userinfo->name, 'toplinks' => $topLinks, 'links' => $links, 'clicks' => $clicks, 'pageStats' => $pageStats]); } //Show littlelink page. example => http://127.0.0.1:8000/+admin public function littlelink(request $request) { if(isset($request->useif)){ $littlelink_name = User::select('littlelink_name')->where('id', $request->littlelink)->value('littlelink_name'); $id = $request->littlelink; } else { $littlelink_name = $request->littlelink; $id = User::select('id')->where('littlelink_name', $littlelink_name)->value('id'); } if (empty($id)) { return abort(404); } $userinfo = User::select('id', 'name', 'littlelink_name', 'littlelink_description', 'theme', 'role', 'block')->where('id', $id)->first(); $information = User::select('name', 'littlelink_name', 'littlelink_description', 'theme')->where('id', $id)->get(); if ($userinfo->block == 'yes') { return abort(404); } $links = DB::table('links') ->join('buttons', 'buttons.id', '=', 'links.button_id') ->select('links.*', 'buttons.name') // Assuming 'links.*' to fetch all columns including 'type_params' ->where('user_id', $id) ->orderBy('up_link', 'asc') ->orderBy('order', 'asc') ->get(); // Loop through each link to decode 'type_params' and merge it into the link object foreach ($links as $link) { if (!empty($link->type_params)) { // Decode the JSON string into an associative array $typeParams = json_decode($link->type_params, true); if (is_array($typeParams)) { // Merge the associative array into the link object foreach ($typeParams as $key => $value) { $link->$key = $value; } } } } return view('linkstack.linkstack', ['userinfo' => $userinfo, 'information' => $information, 'links' => $links, 'littlelink_name' => $littlelink_name]); } //Show littlelink page as home page if set in config public function littlelinkhome(request $request) { $littlelink_name = env('HOME_URL'); $id = User::select('id')->where('littlelink_name', $littlelink_name)->value('id'); if (empty($id)) { return abort(404); } $userinfo = User::select('id', 'name', 'littlelink_name', 'littlelink_description', 'theme', 'role', 'block')->where('id', $id)->first(); $information = User::select('name', 'littlelink_name', 'littlelink_description', 'theme')->where('id', $id)->get(); $links = DB::table('links')->join('buttons', 'buttons.id', '=', 'links.button_id')->select('links.link', 'links.id', 'links.button_id', 'links.title', 'links.custom_css', 'links.custom_icon', 'buttons.name')->where('user_id', $id)->orderBy('up_link', 'asc')->orderBy('order', 'asc')->get(); return view('linkstack.linkstack', ['userinfo' => $userinfo, 'information' => $information, 'links' => $links, 'littlelink_name' => $littlelink_name]); } //Redirect to user page public function userRedirect(request $request) { $id = $request->id; $user = User::select('littlelink_name')->where('id', $id)->value('littlelink_name'); if (empty($id)) { return abort(404); } if (empty($user)) { return abort(404); } return redirect(url('@'.$user)); } //Show add/update form public function AddUpdateLink($id = 0) { $linkData = $id ? Link::find($id) : new Link(['typename' => 'link', 'id' => '0']); $data = [ 'LinkTypes' => LinkType::get(), 'LinkData' => $linkData, 'LinkID' => $id, 'linkTypeID' => "predefined", 'title' => "Predefined Site", ]; $data['typename'] = $linkData->type ?? 'predefined'; return view('studio/edit-link', $data); } //Save add link public function saveLink(Request $request) { // Step 1: Validate Request // $request->validate([ // 'link' => 'sometimes|url', // ]); // Step 2: Determine Link Type and Title $linkType = LinkType::findByTypename($request->typename); $LinkTitle = $request->title; $LinkURL = $request->link; // Step 3: Load Link Type Logic if($request->typename == 'predefined' || $request->typename == 'link') { // Determine button id based on whether a custom or predefined button is used $button_id = ($request->typename == 'link') ? ($request->GetSiteIcon == 1 ? 2 : 1) : null; $button = ($request->typename != 'link') ? Button::where('name', $request->button)->first() : null; $linkData = [ 'link' => $LinkURL, 'title' => $LinkTitle ?? $button?->alt, 'user_id' => Auth::user()->id, 'button_id' => $button?->id ?? $button_id, 'type' => $request->typename // Save the link type ]; } else { $linkTypePath = base_path("blocks/{$linkType->typename}/handler.php"); if (file_exists($linkTypePath)) { include $linkTypePath; $result = handleLinkType($request, $linkType); // Extract rules and linkData from the result $rules = $result['rules']; $linkData = $result['linkData']; // Validate the request $validator = Validator::make($request->all(), $rules); // Check if validation fails if ($validator->fails()) { return back()->withErrors($validator)->withInput(); } $linkData['button_id'] = $linkData['button_id'] ?? 1; // Set 'button_id' unless overwritten by handleLinkType $linkData['type'] = $linkType->typename; // Ensure 'type' is included in $linkData } else { abort(404, "Link type logic not found."); } } // Step 4: Handle Custom Parameters // (Same as before) // Step 5: User and Button Information $userId = Auth::user()->id; $button = Button::where('name', $request->button)->first(); if ($button && empty($LinkTitle)) $LinkTitle = $button->alt; // Step 6: Prepare Link Data // (Handled by the included file) // Step 7: Save or Update Link $OrigLink = Link::find($request->linkid); $linkColumns = Schema::getColumnListing('links'); // Get all column names of links table $filteredLinkData = array_intersect_key($linkData, array_flip($linkColumns)); // Filter $linkData to only include keys that are columns in the links table // Combine remaining variables into one array and convert to JSON for the type_params column $customParams = array_diff_key($linkData, $filteredLinkData); // Check if $linkType->custom_html is defined and not null if (isset($linkType->custom_html)) { // Add $linkType->custom_html to the $customParams array $customParams['custom_html'] = $linkType->custom_html; } // Check if $linkType->ignore_container is defined and not null if (isset($linkType->ignore_container)) { // Add $linkType->ignore_container to the $customParams array $customParams['ignore_container'] = $linkType->ignore_container; } // Check if $linkType->include_libraries is defined and not null if (isset($linkType->include_libraries)) { // Add $linkType->include_libraries to the $customParams array $customParams['include_libraries'] = $linkType->include_libraries; } $filteredLinkData['type_params'] = json_encode($customParams); if ($OrigLink) { $currentValues = $OrigLink->getAttributes(); $nonNullFilteredLinkData = array_filter($filteredLinkData, function($value) {return !is_null($value);}); $updatedValues = array_merge($currentValues, $nonNullFilteredLinkData); $OrigLink->update($updatedValues); $message = "Link updated"; } else { $link = new Link($filteredLinkData); $link->user_id = $userId; $link->save(); $message = "Link added"; } // Step 8: Redirect $redirectUrl = $request->input('param') == 'add_more' ? 'studio/add-link' : 'studio/links'; return Redirect($redirectUrl)->with('success', $message); } public function sortLinks(Request $request) { $linkOrders = $request->input("linkOrders", []); $currentPage = $request->input("currentPage", 1); $perPage = $request->input("perPage", 0); if ($perPage == 0) { $currentPage = 1; } $linkOrders = array_unique(array_filter($linkOrders)); if (!$linkOrders || $currentPage < 1) { return response()->json([ 'status' => 'ERROR', ]); } $newOrder = $perPage * ($currentPage - 1); $linkNewOrders = []; foreach ($linkOrders as $linkId) { if ($linkId < 0) { continue; } $linkNewOrders[$linkId] = $newOrder; Link::where("id", $linkId) ->update([ 'order' => $newOrder ]); $newOrder++; } return response()->json([ 'status' => 'OK', 'linkOrders' => $linkNewOrders, ]); } //Count the number of clicks and redirect to link public function clickNumber(request $request) { $linkId = $request->id; if (substr($linkId, -1) == '+') { $linkWithoutPlus = str_replace('+', '', $linkId); return redirect(url('info/'.$linkWithoutPlus)); } $link = Link::find($linkId); if (empty($link)) { return abort(404); } $link = $link->link; if (empty($linkId)) { return abort(404); } Link::where('id', $linkId)->increment('click_number', 1); $response = redirect()->away($link); $response->header('X-Robots-Tag', 'noindex, nofollow'); return $response; } //Download Vcard public function vcard(request $request) { $linkId = $request->id; // Find the link with the specified ID $link = Link::findOrFail($linkId); $json = $link->link; // Decode the JSON to a PHP array $data = json_decode($json, true); // Create a new vCard object $vcard = new VCard(); // Set the vCard properties from the $data array $vcard->addName($data['last_name'], $data['first_name'], $data['middle_name'], $data['prefix'], $data['suffix']); $vcard->addCompany($data['organization']); $vcard->addJobtitle($data['vtitle']); $vcard->addRole($data['role']); $vcard->addEmail($data['email']); $vcard->addEmail($data['work_email'], 'WORK'); $vcard->addURL($data['work_url'], 'WORK'); $vcard->addPhoneNumber($data['home_phone'], 'HOME'); $vcard->addPhoneNumber($data['work_phone'], 'WORK'); $vcard->addPhoneNumber($data['cell_phone'], 'CELL'); $vcard->addAddress($data['home_address_street'], '', $data['home_address_city'], $data['home_address_state'], $data['home_address_zip'], $data['home_address_country'], 'HOME'); $vcard->addAddress($data['work_address_street'], '', $data['work_address_city'], $data['work_address_state'], $data['work_address_zip'], $data['work_address_country'], 'WORK'); // $vcard->addPhoto(base_path('img/1.png')); // Generate the vCard file contents $file_contents = $vcard->getOutput(); // Set the file headers for download $headers = [ 'Content-Type' => 'text/x-vcard', 'Content-Disposition' => 'attachment; filename="contact.vcf"' ]; Link::where('id', $linkId)->increment('click_number', 1); // Return the file download response return response()->make($file_contents, 200, $headers); } //Show link, click number, up link in links page public function showLinks() { $userId = Auth::user()->id; $data['pagePage'] = 10; $data['links'] = Link::select()->where('user_id', $userId)->orderBy('up_link', 'asc')->orderBy('order', 'asc')->paginate(99999); return view('studio/links', $data); } //Delete link public function deleteLink(request $request) { $linkId = $request->id; Link::where('id', $linkId)->delete(); $directory = base_path("assets/favicon/icons"); $files = scandir($directory); foreach($files as $file) { if (strpos($file, $linkId.".") !== false) { $pathinfo = pathinfo($file, PATHINFO_EXTENSION);}} if (isset($pathinfo)) { try{File::delete(base_path("assets/favicon/icons")."/".$linkId.".".$pathinfo);} catch (exception $e) {} } return redirect('/studio/links'); } //Delete icon public function clearIcon(request $request) { $linkId = $request->id; $directory = base_path("assets/favicon/icons"); $files = scandir($directory); foreach($files as $file) { if (strpos($file, $linkId.".") !== false) { $pathinfo = pathinfo($file, PATHINFO_EXTENSION);}} if (isset($pathinfo)) { try{File::delete(base_path("assets/favicon/icons")."/".$linkId.".".$pathinfo);} catch (exception $e) {} } return redirect('/studio/links'); } //Raise link on the littlelink page public function upLink(request $request) { $linkId = $request->id; $upLink = $request->up; if ($upLink == 'yes') { $up = 'no'; } elseif ($upLink == 'no') { $up = 'yes'; } Link::where('id', $linkId)->update(['up_link' => $up]); return back(); } //Show link to edit public function showLink(request $request) { $linkId = $request->id; $link = Link::where('id', $linkId)->value('link'); $title = Link::where('id', $linkId)->value('title'); $order = Link::where('id', $linkId)->value('order'); $custom_css = Link::where('id', $linkId)->value('custom_css'); $buttonId = Link::where('id', $linkId)->value('button_id'); $buttonName = Button::where('id', $buttonId)->value('name'); $buttons = Button::select('id', 'name')->orderBy('name', 'asc')->get(); return view('studio/edit-link', ['custom_css' => $custom_css, 'buttonId' => $buttonId, 'buttons' => $buttons, 'link' => $link, 'title' => $title, 'order' => $order, 'id' => $linkId, 'buttonName' => $buttonName]); } //Show custom CSS + custom icon public function showCSS(request $request) { $linkId = $request->id; $link = Link::where('id', $linkId)->value('link'); $title = Link::where('id', $linkId)->value('title'); $order = Link::where('id', $linkId)->value('order'); $custom_css = Link::where('id', $linkId)->value('custom_css'); $custom_icon = Link::where('id', $linkId)->value('custom_icon'); $buttonId = Link::where('id', $linkId)->value('button_id'); $buttons = Button::select('id', 'name')->get(); return view('studio/button-editor', ['custom_icon' => $custom_icon, 'custom_css' => $custom_css, 'buttonId' => $buttonId, 'buttons' => $buttons, 'link' => $link, 'title' => $title, 'order' => $order, 'id' => $linkId]); } //Save edit link public function editLink(request $request) { $request->validate([ 'link' => 'required|exturl', 'title' => 'required', 'button' => 'required', ]); if (stringStartsWith($request->link, 'http://') == 'true' or stringStartsWith($request->link, 'https://') == 'true' or stringStartsWith($request->link, 'mailto:') == 'true') $link1 = $request->link; else $link1 = 'https://' . $request->link; if (stringEndsWith($request->link, '/') == 'true') $link = rtrim($link1, "/ "); else $link = $link1; $title = $request->title; $order = $request->order; $button = $request->button; $linkId = $request->id; $buttonId = Button::select('id')->where('name', $button)->value('id'); Link::where('id', $linkId)->update(['link' => $link, 'title' => $title, 'order' => $order, 'button_id' => $buttonId]); return redirect('/studio/links'); } //Save edit custom CSS + custom icon public function editCSS(request $request) { $linkId = $request->id; $custom_icon = $request->custom_icon; $custom_css = $request->custom_css; if ($request->custom_css == "" and $request->custom_icon = !"") { Link::where('id', $linkId)->update(['custom_icon' => $custom_icon]); } elseif ($request->custom_icon == "" and $request->custom_css = !"") { Link::where('id', $linkId)->update(['custom_css' => $custom_css]); } else { Link::where('id', $linkId)->update([]); } return Redirect('#result'); } //Show littlelinke page for edit public function showPage(request $request) { $userId = Auth::user()->id; $data['pages'] = User::where('id', $userId)->select('littlelink_name', 'littlelink_description', 'image', 'name')->get(); return view('/studio/page', $data); } //Save littlelink page (name, description, logo) public function editPage(Request $request) { $userId = Auth::user()->id; $littlelink_name = Auth::user()->littlelink_name; $validator = Validator::make($request->all(), [ 'littlelink_name' => [ 'sometimes', 'max:255', 'string', 'isunique:users,id,'.$userId, ], 'name' => 'sometimes|max:255|string', 'image' => 'sometimes|image|mimes:jpeg,jpg,png,webp|max:2048', // Max file size: 2MB ], [ 'littlelink_name.unique' => __('messages.That handle has already been taken'), 'image.image' => __('messages.The selected file must be an image'), 'image.mimes' => __('messages.The image must be') . ' JPEG, JPG, PNG, webP.', 'image.max' => __('messages.The image size should not exceed 2MB'), ]); if ($validator->fails()) { return redirect('/studio/page')->withErrors($validator)->withInput(); } $profilePhoto = $request->file('image'); $pageName = $request->littlelink_name; $pageDescription = strip_tags($request->pageDescription, '