2021-04-16 01:00:00 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
|
|
|
use Illuminate\Http\Request;
|
|
|
|
use Illuminate\Support\Facades\Hash;
|
2022-11-08 16:11:59 +01:00
|
|
|
use Cohensive\OEmbed\Facades\OEmbed;
|
|
|
|
use Illuminate\Support\Facades\Schema;
|
2022-11-10 18:21:59 +01:00
|
|
|
use Illuminate\Support\Facades\Route;
|
2023-03-28 13:45:54 +02:00
|
|
|
use Illuminate\Support\Facades\Response;
|
2023-03-27 19:04:41 +02:00
|
|
|
use JeroenDesloovere\VCard\VCard;
|
2023-07-27 15:45:05 +02:00
|
|
|
use Illuminate\Validation\Rule;
|
|
|
|
use Illuminate\Support\Facades\Validator;
|
2023-11-17 17:05:50 +01:00
|
|
|
use Illuminate\Support\Facades\Mail;
|
|
|
|
use App\Mail\ReportSubmissionMail;
|
2023-11-24 17:48:08 +01:00
|
|
|
use GeoSot\EnvEditor\Facades\EnvEditor;
|
2021-04-16 01:00:00 +02:00
|
|
|
|
|
|
|
use Auth;
|
|
|
|
use DB;
|
2022-05-18 21:08:58 +02:00
|
|
|
use ZipArchive;
|
2022-09-13 13:47:21 +02:00
|
|
|
use File;
|
2021-04-16 01:00:00 +02:00
|
|
|
|
|
|
|
use App\Models\User;
|
|
|
|
use App\Models\Button;
|
|
|
|
use App\Models\Link;
|
2022-11-08 16:11:59 +01:00
|
|
|
use App\Models\LinkType;
|
2023-02-16 14:25:37 +01:00
|
|
|
use App\Models\UserData;
|
2021-04-16 01:00:00 +02:00
|
|
|
|
2022-05-18 21:08:58 +02:00
|
|
|
|
2022-11-08 16:11:59 +01:00
|
|
|
//Function tests if string starts with certain string (used to test for illegal strings)
|
|
|
|
function stringStartsWith($haystack, $needle, $case = true)
|
|
|
|
{
|
|
|
|
if ($case) {
|
2022-03-31 22:43:01 +02:00
|
|
|
return strpos($haystack, $needle, 0) === 0;
|
|
|
|
}
|
|
|
|
return stripos($haystack, $needle, 0) === 0;
|
|
|
|
}
|
|
|
|
|
2022-11-08 16:11:59 +01:00
|
|
|
//Function tests if string ends with certain string (used to test for illegal strings)
|
|
|
|
function stringEndsWith($haystack, $needle, $case = true)
|
|
|
|
{
|
2022-03-31 22:43:01 +02:00
|
|
|
$expectedPosition = strlen($haystack) - strlen($needle);
|
2022-11-08 16:11:59 +01:00
|
|
|
if ($case) {
|
2022-03-31 22:43:01 +02:00
|
|
|
return strrpos($haystack, $needle, 0) === $expectedPosition;
|
|
|
|
}
|
|
|
|
return strripos($haystack, $needle, 0) === $expectedPosition;
|
|
|
|
}
|
2021-04-16 01:00:00 +02:00
|
|
|
|
|
|
|
class UserController extends Controller
|
|
|
|
{
|
|
|
|
|
2022-11-08 16:11:59 +01:00
|
|
|
//Statistics of the number of clicks and links
|
2021-04-16 01:00:00 +02:00
|
|
|
public function index()
|
|
|
|
{
|
|
|
|
$userId = Auth::user()->id;
|
|
|
|
|
2021-04-18 19:43:43 +02:00
|
|
|
$littlelink_name = Auth::user()->littlelink_name;
|
2022-11-08 16:11:59 +01:00
|
|
|
$userinfo = User::find($userId);
|
2021-04-16 01:00:00 +02:00
|
|
|
|
|
|
|
$links = Link::where('user_id', $userId)->select('link')->count();
|
|
|
|
$clicks = Link::where('user_id', $userId)->sum('click_number');
|
2022-11-08 16:11:59 +01:00
|
|
|
$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]);
|
2021-04-16 01:00:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//Show littlelink page. example => http://127.0.0.1:8000/+admin
|
|
|
|
public function littlelink(request $request)
|
|
|
|
{
|
2023-12-12 00:27:48 +01:00
|
|
|
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');
|
|
|
|
}
|
2021-04-16 01:00:00 +02:00
|
|
|
|
2023-03-21 20:24:23 +01:00
|
|
|
if (empty($id)) {
|
|
|
|
return abort(404);
|
2022-03-24 14:44:33 +01:00
|
|
|
}
|
2023-03-21 20:24:23 +01:00
|
|
|
|
2023-12-05 16:09:45 +01:00
|
|
|
$userinfo = User::select('id', 'name', 'littlelink_name', 'littlelink_description', 'theme', 'role', 'block')->where('id', $id)->first();
|
2023-03-21 20:24:23 +01:00
|
|
|
$information = User::select('name', 'littlelink_name', 'littlelink_description', 'theme')->where('id', $id)->get();
|
|
|
|
|
2023-12-05 16:09:45 +01:00
|
|
|
if ($userinfo->block == 'yes') {
|
|
|
|
return abort(404);
|
|
|
|
}
|
|
|
|
|
2024-06-20 12:24:54 +02:00
|
|
|
$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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-03-21 20:24:23 +01:00
|
|
|
|
2023-12-06 16:57:35 +01:00
|
|
|
return view('linkstack.linkstack', ['userinfo' => $userinfo, 'information' => $information, 'links' => $links, 'littlelink_name' => $littlelink_name]);
|
2023-03-21 20:24:23 +01:00
|
|
|
}
|
|
|
|
|
2023-12-12 00:27:48 +01:00
|
|
|
//Show littlelink page as home page if set in config
|
|
|
|
public function littlelinkhome(request $request)
|
2023-10-08 17:45:49 +02:00
|
|
|
{
|
2023-12-12 00:27:48 +01:00
|
|
|
$littlelink_name = env('HOME_URL');
|
|
|
|
$id = User::select('id')->where('littlelink_name', $littlelink_name)->value('id');
|
2023-10-08 17:45:49 +02:00
|
|
|
|
|
|
|
if (empty($id)) {
|
|
|
|
return abort(404);
|
|
|
|
}
|
|
|
|
|
2023-12-12 00:27:48 +01:00
|
|
|
$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();
|
2023-10-08 17:54:53 +02:00
|
|
|
|
2023-12-12 00:27:48 +01:00
|
|
|
return view('linkstack.linkstack', ['userinfo' => $userinfo, 'information' => $information, 'links' => $links, 'littlelink_name' => $littlelink_name]);
|
2023-10-08 17:45:49 +02:00
|
|
|
}
|
|
|
|
|
2023-12-12 00:27:48 +01:00
|
|
|
//Redirect to user page
|
|
|
|
public function userRedirect(request $request)
|
2023-03-21 20:24:23 +01:00
|
|
|
{
|
2023-12-12 00:27:48 +01:00
|
|
|
$id = $request->id;
|
|
|
|
$user = User::select('littlelink_name')->where('id', $id)->value('littlelink_name');
|
2022-03-24 14:44:33 +01:00
|
|
|
|
2021-04-16 01:00:00 +02:00
|
|
|
if (empty($id)) {
|
|
|
|
return abort(404);
|
|
|
|
}
|
2022-11-09 18:07:50 +01:00
|
|
|
|
2023-12-12 00:27:48 +01:00
|
|
|
if (empty($user)) {
|
|
|
|
return abort(404);
|
|
|
|
}
|
2021-04-16 01:00:00 +02:00
|
|
|
|
2023-12-12 00:27:48 +01:00
|
|
|
return redirect(url('@'.$user));
|
2021-04-16 01:00:00 +02:00
|
|
|
}
|
|
|
|
|
2022-11-08 16:11:59 +01:00
|
|
|
//Show add/update form
|
|
|
|
public function AddUpdateLink($id = 0)
|
2021-04-16 01:00:00 +02:00
|
|
|
{
|
2024-06-18 14:58:08 +02:00
|
|
|
$linkData = $id ? Link::find($id) : new Link(['typename' => 'link', 'id' => '0']);
|
|
|
|
|
|
|
|
$data = [
|
|
|
|
'LinkTypes' => LinkType::get(),
|
|
|
|
'LinkData' => $linkData,
|
|
|
|
'LinkID' => $id,
|
2024-06-20 12:24:54 +02:00
|
|
|
'linkTypeID' => "predefined",
|
2024-06-18 14:58:08 +02:00
|
|
|
'title' => "Predefined Site",
|
|
|
|
];
|
2024-06-20 12:24:54 +02:00
|
|
|
|
2024-06-21 16:48:00 +02:00
|
|
|
$data['typename'] = $linkData->type ?? 'predefined';
|
2024-06-18 14:58:08 +02:00
|
|
|
|
2022-11-08 16:11:59 +01:00
|
|
|
return view('studio/edit-link', $data);
|
2021-04-16 01:00:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//Save add link
|
2024-06-18 14:58:08 +02:00
|
|
|
public function saveLink(Request $request)
|
2021-04-16 01:00:00 +02:00
|
|
|
{
|
2024-06-20 12:24:54 +02:00
|
|
|
// Step 1: Validate Request
|
|
|
|
// $request->validate([
|
|
|
|
// 'link' => 'sometimes|url',
|
|
|
|
// ]);
|
2024-06-18 14:58:08 +02:00
|
|
|
|
2024-06-20 12:24:54 +02:00
|
|
|
// 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') {
|
|
|
|
$button = Button::where('name', $request->button)->first();
|
|
|
|
$linkData = [
|
|
|
|
'link' => $LinkURL,
|
|
|
|
'title' => $LinkTitle ?? $button?->alt,
|
|
|
|
'user_id' => Auth::user()->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;
|
|
|
|
$linkData = handleLinkType($request, $linkType);
|
2024-06-21 16:48:00 +02:00
|
|
|
$linkData['button_id'] = $linkData['button_id'] ?? 1; // Set 'button_id' unless overwritten by handleLinkType
|
2024-06-20 12:24:54 +02:00
|
|
|
$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
|
2021-04-16 01:00:00 +02:00
|
|
|
$userId = Auth::user()->id;
|
2022-11-08 16:11:59 +01:00
|
|
|
$button = Button::where('name', $request->button)->first();
|
2024-06-18 14:58:08 +02:00
|
|
|
if ($button && empty($LinkTitle)) $LinkTitle = $button->alt;
|
2024-06-20 12:24:54 +02:00
|
|
|
|
|
|
|
// 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;
|
|
|
|
}
|
|
|
|
|
|
|
|
$filteredLinkData['type_params'] = json_encode($customParams);
|
|
|
|
|
2024-06-18 14:58:08 +02:00
|
|
|
if ($OrigLink) {
|
2024-06-20 12:24:54 +02:00
|
|
|
$currentValues = $OrigLink->getAttributes();
|
|
|
|
$nonNullFilteredLinkData = array_filter($filteredLinkData, function($value) {return !is_null($value);});
|
|
|
|
$updatedValues = array_merge($currentValues, $nonNullFilteredLinkData);
|
|
|
|
$OrigLink->update($updatedValues);
|
|
|
|
$message = "Link updated";
|
2022-11-08 16:11:59 +01:00
|
|
|
} else {
|
2024-06-20 12:24:54 +02:00
|
|
|
$link = new Link($filteredLinkData);
|
|
|
|
$link->user_id = $userId;
|
|
|
|
$link->save();
|
|
|
|
$message = "Link added";
|
2022-11-08 16:11:59 +01:00
|
|
|
}
|
2024-06-20 12:24:54 +02:00
|
|
|
|
|
|
|
// Step 8: Redirect
|
2024-06-18 14:58:08 +02:00
|
|
|
$redirectUrl = $request->input('param') == 'add_more' ? 'studio/add-link' : 'studio/links';
|
|
|
|
return Redirect($redirectUrl)->with('success', $message);
|
2021-04-16 01:00:00 +02:00
|
|
|
}
|
2024-06-18 14:58:08 +02:00
|
|
|
|
2022-08-14 21:05:26 +02:00
|
|
|
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',
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2022-08-14 21:42:40 +02:00
|
|
|
$newOrder = $perPage * ($currentPage - 1);
|
2022-08-14 21:05:26 +02:00
|
|
|
$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,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2022-11-08 16:11:59 +01:00
|
|
|
|
2021-04-16 01:00:00 +02:00
|
|
|
//Count the number of clicks and redirect to link
|
|
|
|
public function clickNumber(request $request)
|
|
|
|
{
|
|
|
|
$linkId = $request->id;
|
2023-10-18 23:45:43 +02:00
|
|
|
|
|
|
|
if (substr($linkId, -1) == '+') {
|
|
|
|
$linkWithoutPlus = str_replace('+', '', $linkId);
|
|
|
|
return redirect(url('info/'.$linkWithoutPlus));
|
|
|
|
}
|
|
|
|
|
2022-11-25 16:50:11 +01:00
|
|
|
$link = Link::find($linkId);
|
2023-10-18 23:45:43 +02:00
|
|
|
|
|
|
|
if (empty($link)) {
|
|
|
|
return abort(404);
|
|
|
|
}
|
|
|
|
|
2022-11-25 16:50:11 +01:00
|
|
|
$link = $link->link;
|
2022-11-08 16:11:59 +01:00
|
|
|
|
2023-10-18 23:45:43 +02:00
|
|
|
if (empty($linkId)) {
|
|
|
|
return abort(404);
|
|
|
|
}
|
|
|
|
|
2021-04-16 01:00:00 +02:00
|
|
|
Link::where('id', $linkId)->increment('click_number', 1);
|
|
|
|
|
2023-05-15 15:07:00 +02:00
|
|
|
$response = redirect()->away($link);
|
|
|
|
$response->header('X-Robots-Tag', 'noindex, nofollow');
|
|
|
|
|
|
|
|
return $response;
|
2021-04-16 01:00:00 +02:00
|
|
|
}
|
2022-11-08 16:11:59 +01:00
|
|
|
|
2023-03-27 19:04:41 +02:00
|
|
|
//Download Vcard
|
2023-03-28 13:45:54 +02:00
|
|
|
public function vcard(request $request)
|
2023-03-27 19:04:41 +02:00
|
|
|
{
|
|
|
|
$linkId = $request->id;
|
|
|
|
|
2023-03-28 13:45:54 +02:00
|
|
|
// Find the link with the specified ID
|
|
|
|
$link = Link::findOrFail($linkId);
|
2023-03-27 19:04:41 +02:00
|
|
|
|
2023-03-28 15:12:01 +02:00
|
|
|
$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']);
|
2023-03-28 17:05:29 +02:00
|
|
|
$vcard->addEmail($data['work_email'], 'WORK');
|
|
|
|
$vcard->addURL($data['work_url'], 'WORK');
|
2023-03-28 15:12:01 +02:00
|
|
|
$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');
|
|
|
|
|
2023-03-28 17:05:29 +02:00
|
|
|
|
|
|
|
// $vcard->addPhoto(base_path('img/1.png'));
|
|
|
|
|
2023-03-28 15:12:01 +02:00
|
|
|
// Generate the vCard file contents
|
|
|
|
$file_contents = $vcard->getOutput();
|
|
|
|
|
|
|
|
// Set the file headers for download
|
2023-03-28 13:45:54 +02:00
|
|
|
$headers = [
|
2023-03-28 15:12:01 +02:00
|
|
|
'Content-Type' => 'text/x-vcard',
|
|
|
|
'Content-Disposition' => 'attachment; filename="contact.vcf"'
|
2023-03-28 13:45:54 +02:00
|
|
|
];
|
2023-03-28 15:12:01 +02:00
|
|
|
|
2023-03-28 16:02:36 +02:00
|
|
|
Link::where('id', $linkId)->increment('click_number', 1);
|
|
|
|
|
2023-03-28 15:12:01 +02:00
|
|
|
// Return the file download response
|
|
|
|
return response()->make($file_contents, 200, $headers);
|
2023-03-27 19:04:41 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2021-04-16 01:00:00 +02:00
|
|
|
//Show link, click number, up link in links page
|
|
|
|
public function showLinks()
|
|
|
|
{
|
|
|
|
$userId = Auth::user()->id;
|
2022-08-14 21:05:26 +02:00
|
|
|
$data['pagePage'] = 10;
|
2021-04-16 01:00:00 +02:00
|
|
|
|
2024-06-21 16:48:00 +02:00
|
|
|
$data['links'] = Link::select()->where('user_id', $userId)->orderBy('up_link', 'asc')->orderBy('order', 'asc')->paginate(99999);
|
2022-08-05 17:29:49 +02:00
|
|
|
return view('studio/links', $data);
|
|
|
|
}
|
|
|
|
|
2021-04-16 01:00:00 +02:00
|
|
|
//Delete link
|
|
|
|
public function deleteLink(request $request)
|
|
|
|
{
|
|
|
|
$linkId = $request->id;
|
|
|
|
|
|
|
|
Link::where('id', $linkId)->delete();
|
2022-11-08 16:11:59 +01:00
|
|
|
|
2023-04-26 15:44:39 +02:00
|
|
|
$directory = base_path("assets/favicon/icons");
|
2022-11-28 19:44:02 +01:00
|
|
|
$files = scandir($directory);
|
|
|
|
foreach($files as $file) {
|
|
|
|
if (strpos($file, $linkId.".") !== false) {
|
|
|
|
$pathinfo = pathinfo($file, PATHINFO_EXTENSION);}}
|
|
|
|
if (isset($pathinfo)) {
|
2023-04-26 15:44:39 +02:00
|
|
|
try{File::delete(base_path("assets/favicon/icons")."/".$linkId.".".$pathinfo);} catch (exception $e) {}
|
2022-11-28 19:44:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return redirect('/studio/links');
|
2021-04-16 01:00:00 +02:00
|
|
|
}
|
|
|
|
|
2022-11-28 20:20:43 +01:00
|
|
|
//Delete icon
|
|
|
|
public function clearIcon(request $request)
|
|
|
|
{
|
|
|
|
$linkId = $request->id;
|
|
|
|
|
2023-04-26 15:44:39 +02:00
|
|
|
$directory = base_path("assets/favicon/icons");
|
2022-11-28 20:20:43 +01:00
|
|
|
$files = scandir($directory);
|
|
|
|
foreach($files as $file) {
|
|
|
|
if (strpos($file, $linkId.".") !== false) {
|
|
|
|
$pathinfo = pathinfo($file, PATHINFO_EXTENSION);}}
|
|
|
|
if (isset($pathinfo)) {
|
2023-04-26 15:44:39 +02:00
|
|
|
try{File::delete(base_path("assets/favicon/icons")."/".$linkId.".".$pathinfo);} catch (exception $e) {}
|
2022-11-28 20:20:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return redirect('/studio/links');
|
|
|
|
}
|
|
|
|
|
2021-04-16 01:00:00 +02:00
|
|
|
//Raise link on the littlelink page
|
|
|
|
public function upLink(request $request)
|
|
|
|
{
|
|
|
|
$linkId = $request->id;
|
|
|
|
$upLink = $request->up;
|
|
|
|
|
2022-11-08 16:11:59 +01:00
|
|
|
if ($upLink == 'yes') {
|
2021-04-16 01:00:00 +02:00
|
|
|
$up = 'no';
|
2022-11-08 16:11:59 +01:00
|
|
|
} elseif ($upLink == 'no') {
|
2021-04-16 01:00:00 +02:00
|
|
|
$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');
|
2021-07-06 10:40:16 +02:00
|
|
|
$title = Link::where('id', $linkId)->value('title');
|
|
|
|
$order = Link::where('id', $linkId)->value('order');
|
2022-04-07 16:30:26 +02:00
|
|
|
$custom_css = Link::where('id', $linkId)->value('custom_css');
|
2021-07-06 10:40:16 +02:00
|
|
|
$buttonId = Link::where('id', $linkId)->value('button_id');
|
2022-07-31 13:35:52 +02:00
|
|
|
$buttonName = Button::where('id', $buttonId)->value('name');
|
2022-11-08 16:11:59 +01:00
|
|
|
|
2022-08-02 00:34:18 +02:00
|
|
|
$buttons = Button::select('id', 'name')->orderBy('name', 'asc')->get();
|
2021-04-16 01:00:00 +02:00
|
|
|
|
2022-11-08 16:11:59 +01:00
|
|
|
return view('studio/edit-link', ['custom_css' => $custom_css, 'buttonId' => $buttonId, 'buttons' => $buttons, 'link' => $link, 'title' => $title, 'order' => $order, 'id' => $linkId, 'buttonName' => $buttonName]);
|
2021-04-16 01:00:00 +02:00
|
|
|
}
|
|
|
|
|
2022-04-13 16:49:44 +02:00
|
|
|
//Show custom CSS + custom icon
|
2022-04-10 17:42:29 +02:00
|
|
|
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');
|
2022-04-13 15:37:54 +02:00
|
|
|
$custom_icon = Link::where('id', $linkId)->value('custom_icon');
|
2022-04-10 17:42:29 +02:00
|
|
|
$buttonId = Link::where('id', $linkId)->value('button_id');
|
|
|
|
|
|
|
|
$buttons = Button::select('id', 'name')->get();
|
|
|
|
|
2022-11-08 16:11:59 +01:00
|
|
|
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]);
|
2022-04-10 17:42:29 +02:00
|
|
|
}
|
|
|
|
|
2021-04-16 01:00:00 +02:00
|
|
|
//Save edit link
|
|
|
|
public function editLink(request $request)
|
|
|
|
{
|
|
|
|
$request->validate([
|
2024-02-07 19:15:30 +01:00
|
|
|
'link' => 'required|exturl',
|
2021-07-06 10:40:16 +02:00
|
|
|
'title' => 'required',
|
2021-04-16 01:00:00 +02:00
|
|
|
'button' => 'required',
|
|
|
|
]);
|
|
|
|
|
2022-11-08 16:11:59 +01:00
|
|
|
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, "/ ");
|
2022-03-31 22:43:01 +02:00
|
|
|
else
|
2023-03-05 20:02:42 +01:00
|
|
|
$link = $link1;
|
2021-07-06 10:40:16 +02:00
|
|
|
$title = $request->title;
|
|
|
|
$order = $request->order;
|
2021-04-16 01:00:00 +02:00
|
|
|
$button = $request->button;
|
|
|
|
$linkId = $request->id;
|
|
|
|
|
2022-11-08 16:11:59 +01:00
|
|
|
$buttonId = Button::select('id')->where('name', $button)->value('id');
|
2021-04-16 01:00:00 +02:00
|
|
|
|
2022-04-08 18:27:43 +02:00
|
|
|
Link::where('id', $linkId)->update(['link' => $link, 'title' => $title, 'order' => $order, 'button_id' => $buttonId]);
|
2021-04-16 01:00:00 +02:00
|
|
|
|
|
|
|
return redirect('/studio/links');
|
|
|
|
}
|
|
|
|
|
2022-04-13 16:49:44 +02:00
|
|
|
//Save edit custom CSS + custom icon
|
2022-04-10 17:42:29 +02:00
|
|
|
public function editCSS(request $request)
|
|
|
|
{
|
|
|
|
$linkId = $request->id;
|
2022-04-13 16:49:44 +02:00
|
|
|
$custom_icon = $request->custom_icon;
|
2022-04-10 17:42:29 +02:00
|
|
|
$custom_css = $request->custom_css;
|
|
|
|
|
2022-11-08 16:11:59 +01:00
|
|
|
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([]);
|
|
|
|
}
|
2022-05-04 00:40:41 +02:00
|
|
|
return Redirect('#result');
|
2022-04-10 17:42:29 +02:00
|
|
|
}
|
|
|
|
|
2021-04-16 01:00:00 +02:00
|
|
|
//Show littlelinke page for edit
|
|
|
|
public function showPage(request $request)
|
|
|
|
{
|
|
|
|
$userId = Auth::user()->id;
|
|
|
|
|
2022-11-08 16:11:59 +01:00
|
|
|
$data['pages'] = User::where('id', $userId)->select('littlelink_name', 'littlelink_description', 'image', 'name')->get();
|
2021-04-16 01:00:00 +02:00
|
|
|
|
|
|
|
return view('/studio/page', $data);
|
|
|
|
}
|
|
|
|
|
|
|
|
//Save littlelink page (name, description, logo)
|
2023-07-27 15:45:05 +02:00
|
|
|
public function editPage(Request $request)
|
2021-04-16 01:00:00 +02:00
|
|
|
{
|
|
|
|
$userId = Auth::user()->id;
|
2021-04-18 19:43:43 +02:00
|
|
|
$littlelink_name = Auth::user()->littlelink_name;
|
2023-07-27 15:45:05 +02:00
|
|
|
|
|
|
|
$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
|
|
|
|
], [
|
2023-07-27 16:00:59 +02:00
|
|
|
'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'),
|
2023-07-27 15:45:05 +02:00
|
|
|
]);
|
|
|
|
|
|
|
|
if ($validator->fails()) {
|
|
|
|
return redirect('/studio/page')->withErrors($validator)->withInput();
|
|
|
|
}
|
|
|
|
|
2021-04-16 01:00:00 +02:00
|
|
|
$profilePhoto = $request->file('image');
|
2023-01-23 16:06:07 +01:00
|
|
|
$pageName = $request->littlelink_name;
|
2023-07-27 15:45:05 +02:00
|
|
|
$pageDescription = strip_tags($request->pageDescription, '<a><p><strong><i><ul><ol><li><blockquote><h2><h3><h4>');
|
2023-07-10 19:16:04 +02:00
|
|
|
$pageDescription = preg_replace("/<a([^>]*)>/i", "<a $1 rel=\"noopener noreferrer nofollow\">", $pageDescription);
|
2024-02-05 19:03:49 +01:00
|
|
|
$pageDescription = strip_tags_except_allowed_protocols($pageDescription);
|
2023-01-23 16:06:07 +01:00
|
|
|
$name = $request->name;
|
2023-02-16 15:38:17 +01:00
|
|
|
$checkmark = $request->checkmark;
|
2023-04-26 15:44:39 +02:00
|
|
|
$sharebtn = $request->sharebtn;
|
2024-01-02 20:27:15 +01:00
|
|
|
$tablinks = $request->tablinks;
|
2023-11-24 17:48:08 +01:00
|
|
|
|
2023-11-26 01:29:32 +01:00
|
|
|
if(env('HOME_URL') !== '' && $pageName != $littlelink_name && $littlelink_name == env('HOME_URL')){
|
2023-11-24 17:48:08 +01:00
|
|
|
EnvEditor::editKey('HOME_URL', $pageName);
|
|
|
|
}
|
2023-07-27 15:45:05 +02:00
|
|
|
|
|
|
|
User::where('id', $userId)->update([
|
|
|
|
'littlelink_name' => $pageName,
|
|
|
|
'littlelink_description' => $pageDescription,
|
|
|
|
'name' => $name
|
|
|
|
]);
|
|
|
|
|
2023-01-23 16:30:29 +01:00
|
|
|
if ($request->hasFile('image')) {
|
2024-02-07 00:49:23 +01:00
|
|
|
|
|
|
|
// Delete the user's current avatar if it exists
|
|
|
|
while (findAvatar($userId) !== "error.error") {
|
|
|
|
$avatarName = findAvatar($userId);
|
|
|
|
unlink(base_path($avatarName));
|
|
|
|
}
|
|
|
|
|
2023-07-27 15:45:05 +02:00
|
|
|
$fileName = $userId . '_' . time() . "." . $profilePhoto->extension();
|
|
|
|
$profilePhoto->move(base_path('assets/img'), $fileName);
|
2021-04-16 01:00:00 +02:00
|
|
|
}
|
2023-07-27 15:45:05 +02:00
|
|
|
|
|
|
|
if ($checkmark == "on") {
|
2023-02-16 15:38:17 +01:00
|
|
|
UserData::saveData($userId, 'checkmark', true);
|
|
|
|
} else {
|
|
|
|
UserData::saveData($userId, 'checkmark', false);
|
|
|
|
}
|
2023-07-27 15:45:05 +02:00
|
|
|
|
|
|
|
if ($sharebtn == "on") {
|
2023-04-26 15:44:39 +02:00
|
|
|
UserData::saveData($userId, 'disable-sharebtn', false);
|
|
|
|
} else {
|
|
|
|
UserData::saveData($userId, 'disable-sharebtn', true);
|
|
|
|
}
|
2024-01-02 20:27:15 +01:00
|
|
|
|
|
|
|
if ($tablinks == "on") {
|
|
|
|
UserData::saveData($userId, 'links-new-tab', true);
|
|
|
|
} else {
|
|
|
|
UserData::saveData($userId, 'links-new-tab', false);
|
|
|
|
}
|
2023-07-27 15:45:05 +02:00
|
|
|
|
2022-05-13 16:09:00 +02:00
|
|
|
return Redirect('/studio/page');
|
2021-04-16 01:00:00 +02:00
|
|
|
}
|
|
|
|
|
2023-02-13 16:22:11 +01:00
|
|
|
//Upload custom theme background image
|
2023-07-27 15:45:05 +02:00
|
|
|
public function themeBackground(Request $request)
|
2023-02-13 16:22:11 +01:00
|
|
|
{
|
|
|
|
$userId = Auth::user()->id;
|
|
|
|
$littlelink_name = Auth::user()->littlelink_name;
|
2023-07-27 15:45:05 +02:00
|
|
|
|
|
|
|
$request->validate([
|
|
|
|
'image' => 'required|image|mimes:jpeg,jpg,png,webp,gif|max:2048', // Max file size: 2MB
|
|
|
|
], [
|
2023-07-27 16:00:59 +02:00
|
|
|
'image.required' => __('messages.Please select an image'),
|
|
|
|
'image.image' => __('messages.The selected file must be an image'),
|
|
|
|
'image.mimes' => __('messages.The image must be') . ' JPEG, JPG, PNG, webP, GIF.',
|
|
|
|
'image.max' => __('messages.The image size should not exceed 2MB'),
|
2023-07-27 15:45:05 +02:00
|
|
|
]);
|
|
|
|
|
2023-02-13 16:22:11 +01:00
|
|
|
$customBackground = $request->file('image');
|
2023-07-27 15:45:05 +02:00
|
|
|
|
|
|
|
if ($customBackground) {
|
2023-04-26 15:44:39 +02:00
|
|
|
$directory = base_path('assets/img/background-img/');
|
2023-02-13 17:18:32 +01:00
|
|
|
$files = scandir($directory);
|
|
|
|
$pathinfo = "error.error";
|
2023-07-27 15:45:05 +02:00
|
|
|
foreach ($files as $file) {
|
|
|
|
if (strpos($file, $userId . '.') !== false) {
|
|
|
|
$pathinfo = $userId . "." . pathinfo($file, PATHINFO_EXTENSION);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-02-07 00:49:23 +01:00
|
|
|
// Delete the user's current background image if it exists
|
|
|
|
while (findBackground($userId) !== "error.error") {
|
|
|
|
$avatarName = "assets/img/background-img/" . findBackground(Auth::id());
|
|
|
|
unlink(base_path($avatarName));
|
2023-07-27 15:45:05 +02:00
|
|
|
}
|
2024-02-07 00:49:23 +01:00
|
|
|
|
2023-07-27 15:45:05 +02:00
|
|
|
$fileName = $userId . '_' . time() . "." . $customBackground->extension();
|
|
|
|
$customBackground->move(base_path('assets/img/background-img/'), $fileName);
|
|
|
|
|
|
|
|
if (extension_loaded('imagick')) {
|
|
|
|
$imagePath = base_path('assets/img/background-img/') . $fileName;
|
|
|
|
$image = new \Imagick($imagePath);
|
|
|
|
$image->stripImage();
|
|
|
|
$image->writeImage($imagePath);
|
|
|
|
}
|
|
|
|
|
|
|
|
return redirect('/studio/theme');
|
2023-02-13 16:22:11 +01:00
|
|
|
}
|
2023-07-27 15:45:05 +02:00
|
|
|
|
|
|
|
return redirect('/studio/theme')->with('error', 'Please select a valid image file.');
|
2023-02-13 16:22:11 +01:00
|
|
|
}
|
|
|
|
|
2023-02-13 18:40:18 +01:00
|
|
|
//Delete custom background image
|
|
|
|
public function removeBackground()
|
|
|
|
{
|
2024-02-07 15:20:07 +01:00
|
|
|
$userId = Auth::user()->id;
|
2023-02-13 18:40:18 +01:00
|
|
|
|
2024-02-07 15:20:07 +01:00
|
|
|
// Delete the user's current background image if it exists
|
|
|
|
while (findBackground($userId) !== "error.error") {
|
|
|
|
$avatarName = "assets/img/background-img/" . findBackground(Auth::id());
|
|
|
|
unlink(base_path($avatarName));
|
2023-02-13 18:40:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return back();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-05-18 21:08:58 +02:00
|
|
|
//Show custom theme
|
|
|
|
public function showTheme(request $request)
|
|
|
|
{
|
|
|
|
$userId = Auth::user()->id;
|
|
|
|
|
|
|
|
$data['pages'] = User::where('id', $userId)->select('littlelink_name', 'theme')->get();
|
|
|
|
|
|
|
|
return view('/studio/theme', $data);
|
|
|
|
}
|
|
|
|
|
|
|
|
//Save custom theme
|
|
|
|
public function editTheme(request $request)
|
|
|
|
{
|
|
|
|
$request->validate([
|
|
|
|
'zip' => 'sometimes|mimes:zip',
|
|
|
|
]);
|
|
|
|
|
|
|
|
$userId = Auth::user()->id;
|
|
|
|
|
|
|
|
$zipfile = $request->file('zip');
|
|
|
|
|
|
|
|
$theme = $request->theme;
|
2022-11-08 16:11:59 +01:00
|
|
|
$message = "";
|
|
|
|
|
2022-05-18 21:08:58 +02:00
|
|
|
User::where('id', $userId)->update(['theme' => $theme]);
|
|
|
|
|
|
|
|
|
|
|
|
|
2022-11-08 16:11:59 +01:00
|
|
|
if (!empty($zipfile)) {
|
2022-09-13 13:47:21 +02:00
|
|
|
|
2022-11-08 16:11:59 +01:00
|
|
|
$zipfile->move(base_path('/themes'), "temp.zip");
|
|
|
|
|
|
|
|
$zip = new ZipArchive;
|
|
|
|
$zip->open(base_path() . '/themes/temp.zip');
|
|
|
|
$zip->extractTo(base_path() . '/themes');
|
|
|
|
$zip->close();
|
|
|
|
unlink(base_path() . '/themes/temp.zip');
|
|
|
|
|
|
|
|
// Removes version numbers from folder.
|
|
|
|
|
|
|
|
$folder = base_path('themes');
|
|
|
|
$regex = '/[0-9.-]/';
|
|
|
|
$files = scandir($folder);
|
|
|
|
|
|
|
|
foreach ($files as $file) {
|
|
|
|
if ($file !== '.' && $file !== '..') {
|
|
|
|
if (preg_match($regex, $file)) {
|
|
|
|
$new_file = preg_replace($regex, '', $file);
|
|
|
|
File::copyDirectory($folder . '/' . $file, $folder . '/' . $new_file);
|
|
|
|
$dirname = $folder . '/' . $file;
|
|
|
|
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
|
|
|
|
system('rmdir ' . escapeshellarg($dirname) . ' /s /q');
|
|
|
|
} else {
|
|
|
|
system("rm -rf " . escapeshellarg($dirname));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-09-13 13:47:21 +02:00
|
|
|
}
|
2022-05-18 21:08:58 +02:00
|
|
|
}
|
|
|
|
|
2022-09-13 13:47:21 +02:00
|
|
|
|
2022-11-08 16:11:59 +01:00
|
|
|
return Redirect('/studio/theme')->with("success", $message);
|
2022-05-18 21:08:58 +02:00
|
|
|
}
|
|
|
|
|
2021-04-16 01:00:00 +02:00
|
|
|
//Show user (name, email, password)
|
2022-05-18 21:08:58 +02:00
|
|
|
public function showProfile(request $request)
|
2021-04-16 01:00:00 +02:00
|
|
|
{
|
|
|
|
$userId = Auth::user()->id;
|
|
|
|
|
2021-07-06 10:40:16 +02:00
|
|
|
$data['profile'] = User::where('id', $userId)->select('name', 'email', 'role')->get();
|
2021-04-16 01:00:00 +02:00
|
|
|
|
|
|
|
return view('/studio/profile', $data);
|
|
|
|
}
|
|
|
|
|
|
|
|
//Save user (name, email, password)
|
|
|
|
public function editProfile(request $request)
|
|
|
|
{
|
|
|
|
$request->validate([
|
2022-03-31 21:31:00 +02:00
|
|
|
'name' => 'sometimes|required|unique:users',
|
|
|
|
'email' => 'sometimes|required|email|unique:users',
|
|
|
|
'password' => 'sometimes|min:8',
|
2021-04-16 01:00:00 +02:00
|
|
|
]);
|
|
|
|
|
|
|
|
$userId = Auth::user()->id;
|
|
|
|
|
|
|
|
$name = $request->name;
|
|
|
|
$email = $request->email;
|
|
|
|
$password = Hash::make($request->password);
|
|
|
|
|
2022-11-08 16:11:59 +01:00
|
|
|
if ($request->name != '') {
|
|
|
|
User::where('id', $userId)->update(['name' => $name]);
|
|
|
|
} elseif ($request->email != '') {
|
|
|
|
User::where('id', $userId)->update(['email' => $email]);
|
|
|
|
} elseif ($request->password != '') {
|
|
|
|
User::where('id', $userId)->update(['password' => $password]);
|
2023-09-29 15:37:08 +02:00
|
|
|
Auth::logout();
|
2022-03-31 21:31:00 +02:00
|
|
|
}
|
2021-04-16 01:00:00 +02:00
|
|
|
return back();
|
|
|
|
}
|
2022-05-31 14:11:26 +02:00
|
|
|
|
|
|
|
//Show user theme credit page
|
|
|
|
public function theme(request $request)
|
|
|
|
{
|
|
|
|
$littlelink_name = $request->littlelink;
|
|
|
|
$id = User::select('id')->where('littlelink_name', $littlelink_name)->value('id');
|
|
|
|
|
|
|
|
if (empty($id)) {
|
|
|
|
return abort(404);
|
|
|
|
}
|
2022-11-08 16:11:59 +01:00
|
|
|
|
2022-05-31 14:11:26 +02:00
|
|
|
$userinfo = User::select('name', 'littlelink_name', 'littlelink_description', 'theme')->where('id', $id)->first();
|
|
|
|
$information = User::select('name', 'littlelink_name', 'littlelink_description', 'theme')->where('id', $id)->get();
|
2022-11-08 16:11:59 +01:00
|
|
|
|
2022-05-31 14:11:26 +02:00
|
|
|
$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('components/theme', ['userinfo' => $userinfo, 'information' => $information, 'links' => $links, 'littlelink_name' => $littlelink_name]);
|
|
|
|
}
|
|
|
|
|
2022-11-08 16:11:59 +01:00
|
|
|
//Delete existing user
|
|
|
|
public function deleteUser(request $request)
|
|
|
|
{
|
|
|
|
|
|
|
|
// echo $request->id;
|
|
|
|
// echo "<br>";
|
|
|
|
// echo Auth::id();
|
|
|
|
$id = $request->id;
|
|
|
|
|
|
|
|
if($id == Auth::id() and $id != "1") {
|
2023-09-20 13:35:48 +02:00
|
|
|
|
|
|
|
Link::where('user_id', $id)->delete();
|
|
|
|
|
2022-11-08 16:11:59 +01:00
|
|
|
$user = User::find($id);
|
|
|
|
|
|
|
|
Schema::disableForeignKeyConstraints();
|
|
|
|
$user->forceDelete();
|
|
|
|
Schema::enableForeignKeyConstraints();
|
|
|
|
}
|
|
|
|
|
|
|
|
return redirect('/');
|
|
|
|
}
|
2022-12-05 20:02:23 +01:00
|
|
|
|
2023-01-23 17:19:09 +01:00
|
|
|
//Delete profile picture
|
|
|
|
public function delProfilePicture()
|
|
|
|
{
|
2024-02-07 15:20:07 +01:00
|
|
|
$userId = Auth::user()->id;
|
2024-02-07 19:15:30 +01:00
|
|
|
|
2024-02-07 15:20:07 +01:00
|
|
|
// Delete the user's current avatar if it exists
|
|
|
|
while (findAvatar($userId) !== "error.error") {
|
|
|
|
$avatarName = findAvatar($userId);
|
|
|
|
unlink(base_path($avatarName));
|
2023-01-23 17:19:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return back();
|
|
|
|
}
|
|
|
|
|
2023-03-08 17:20:39 +01:00
|
|
|
//Export user links
|
|
|
|
public function exportLinks(request $request)
|
|
|
|
{
|
|
|
|
$userId = Auth::id();
|
|
|
|
$user = User::find($userId);
|
|
|
|
$links = Link::where('user_id', $userId)->get();
|
|
|
|
|
|
|
|
if (!$user) {
|
|
|
|
// handle the case where the user is null
|
|
|
|
return response()->json(['message' => 'User not found'], 404);
|
|
|
|
}
|
|
|
|
|
|
|
|
$userData['links'] = $links->toArray();
|
|
|
|
|
2023-03-08 18:01:23 +01:00
|
|
|
$domain = $_SERVER['HTTP_HOST'];
|
|
|
|
$date = date('Y-m-d_H-i-s');
|
|
|
|
$fileName = "links-$domain-$date.json";
|
2023-03-08 17:20:39 +01:00
|
|
|
$headers = [
|
|
|
|
'Content-Type' => 'application/json',
|
|
|
|
'Content-Disposition' => 'attachment; filename="'.$fileName.'"',
|
|
|
|
];
|
|
|
|
return response()->json($userData, 200, $headers);
|
|
|
|
|
|
|
|
return back();
|
|
|
|
}
|
|
|
|
|
|
|
|
//Export all user data
|
2023-03-09 00:59:52 +01:00
|
|
|
public function exportAll(Request $request)
|
2023-03-08 17:20:39 +01:00
|
|
|
{
|
|
|
|
$userId = Auth::id();
|
|
|
|
$user = User::find($userId);
|
|
|
|
$links = Link::where('user_id', $userId)->get();
|
2023-03-09 00:59:52 +01:00
|
|
|
|
2023-03-08 17:20:39 +01:00
|
|
|
if (!$user) {
|
|
|
|
// handle the case where the user is null
|
|
|
|
return response()->json(['message' => 'User not found'], 404);
|
|
|
|
}
|
2023-03-09 00:59:52 +01:00
|
|
|
|
2023-03-08 17:20:39 +01:00
|
|
|
$userData = $user->toArray();
|
|
|
|
$userData['links'] = $links->toArray();
|
|
|
|
|
2023-03-09 00:59:52 +01:00
|
|
|
if (file_exists(base_path(findAvatar($userId)))){
|
|
|
|
$imagePath = base_path(findAvatar($userId));
|
|
|
|
$imageData = base64_encode(file_get_contents($imagePath));
|
|
|
|
$userData['image_data'] = $imageData;
|
|
|
|
|
|
|
|
$imageExtension = pathinfo($imagePath, PATHINFO_EXTENSION);
|
|
|
|
$userData['image_extension'] = $imageExtension;
|
|
|
|
}
|
|
|
|
|
2023-03-08 18:01:23 +01:00
|
|
|
$domain = $_SERVER['HTTP_HOST'];
|
|
|
|
$date = date('Y-m-d_H-i-s');
|
|
|
|
$fileName = "user_data-$domain-$date.json";
|
2023-03-08 17:20:39 +01:00
|
|
|
$headers = [
|
|
|
|
'Content-Type' => 'application/json',
|
|
|
|
'Content-Disposition' => 'attachment; filename="'.$fileName.'"',
|
|
|
|
];
|
|
|
|
return response()->json($userData, 200, $headers);
|
2023-03-09 00:59:52 +01:00
|
|
|
|
2023-03-08 17:20:39 +01:00
|
|
|
return back();
|
2023-03-09 00:59:52 +01:00
|
|
|
}
|
2023-03-08 17:20:39 +01:00
|
|
|
|
2023-03-09 00:59:52 +01:00
|
|
|
public function importData(Request $request)
|
|
|
|
{
|
|
|
|
try {
|
|
|
|
// Get the JSON data from the uploaded file
|
|
|
|
if (!$request->hasFile('import') || !$request->file('import')->isValid()) {
|
|
|
|
throw new \Exception('File not uploaded or is faulty');
|
|
|
|
}
|
|
|
|
$file = $request->file('import');
|
|
|
|
$jsonString = $file->get();
|
|
|
|
$userData = json_decode($jsonString, true);
|
|
|
|
|
|
|
|
// Update the authenticated user's profile data if defined in the JSON file
|
|
|
|
$user = auth()->user();
|
|
|
|
if (isset($userData['name'])) {
|
|
|
|
$user->name = $userData['name'];
|
|
|
|
}
|
2024-02-10 18:03:31 +01:00
|
|
|
|
2023-03-09 00:59:52 +01:00
|
|
|
if (isset($userData['littlelink_description'])) {
|
2024-02-05 20:50:58 +01:00
|
|
|
$sanitizedText = $userData['littlelink_description'];
|
|
|
|
$sanitizedText = strip_tags($sanitizedText, '<a><p><strong><i><ul><ol><li><blockquote><h2><h3><h4>');
|
|
|
|
$sanitizedText = preg_replace("/<a([^>]*)>/i", "<a $1 rel=\"noopener noreferrer nofollow\">", $sanitizedText);
|
|
|
|
$sanitizedText = strip_tags_except_allowed_protocols($sanitizedText);
|
|
|
|
$user->littlelink_description = $sanitizedText;
|
2023-03-09 00:59:52 +01:00
|
|
|
}
|
2024-02-06 23:00:39 +01:00
|
|
|
|
2023-03-09 00:59:52 +01:00
|
|
|
if (isset($userData['image_data'])) {
|
2024-02-07 19:15:30 +01:00
|
|
|
|
|
|
|
$allowedExtensions = array('jpeg', 'jpg', 'png', 'webp');
|
|
|
|
$userExtension = strtolower($userData['image_extension']);
|
|
|
|
|
2024-02-06 23:00:39 +01:00
|
|
|
if (in_array($userExtension, $allowedExtensions)) {
|
2023-03-09 00:59:52 +01:00
|
|
|
// Decode the image data from Base64
|
|
|
|
$imageData = base64_decode($userData['image_data']);
|
2024-02-07 00:49:23 +01:00
|
|
|
|
|
|
|
// Delete the user's current avatar if it exists
|
|
|
|
while (findAvatar(Auth::id()) !== "error.error") {
|
|
|
|
$avatarName = findAvatar(Auth::id());
|
|
|
|
unlink(base_path($avatarName));
|
|
|
|
}
|
2023-03-09 00:59:52 +01:00
|
|
|
|
|
|
|
// Save the image to the correct path with the correct file name and extension
|
2024-02-06 23:00:39 +01:00
|
|
|
$filename = $user->id . '.' . $userExtension;
|
|
|
|
file_put_contents(base_path('assets/img/' . $filename), $imageData);
|
2023-03-09 00:59:52 +01:00
|
|
|
|
|
|
|
// Update the user's image field with the correct file name
|
|
|
|
$user->image = $filename;
|
2024-02-06 23:00:39 +01:00
|
|
|
}
|
2023-03-09 00:59:52 +01:00
|
|
|
}
|
2024-02-07 00:49:23 +01:00
|
|
|
|
2023-03-09 00:59:52 +01:00
|
|
|
$user->save();
|
|
|
|
|
|
|
|
// Delete all links for the authenticated user
|
|
|
|
Link::where('user_id', $user->id)->delete();
|
|
|
|
|
|
|
|
// Loop through each link in $userData and create a new link for the user
|
|
|
|
foreach ($userData['links'] as $linkData) {
|
2024-02-05 19:23:28 +01:00
|
|
|
|
|
|
|
$validatedData = Validator::make($linkData, [
|
2024-02-07 19:15:30 +01:00
|
|
|
'link' => 'nullable|exturl',
|
2024-02-05 19:23:28 +01:00
|
|
|
]);
|
|
|
|
|
|
|
|
if ($validatedData->fails()) {
|
2024-02-10 18:14:36 +01:00
|
|
|
throw new \Exception('Invalid link');
|
2024-02-05 19:23:28 +01:00
|
|
|
}
|
|
|
|
|
2023-03-09 00:59:52 +01:00
|
|
|
$newLink = new Link();
|
|
|
|
|
|
|
|
// Copy over the link data from $linkData to $newLink
|
|
|
|
$newLink->button_id = $linkData['button_id'];
|
|
|
|
$newLink->link = $linkData['link'];
|
2024-02-05 19:23:28 +01:00
|
|
|
|
|
|
|
// Sanitize the title
|
|
|
|
if ($linkData['button_id'] == 93) {
|
|
|
|
$sanitizedText = strip_tags($linkData['title'], '<a><p><strong><i><ul><ol><li><blockquote><h2><h3><h4>');
|
|
|
|
$sanitizedText = preg_replace("/<a([^>]*)>/i", "<a $1 rel=\"noopener noreferrer nofollow\">", $sanitizedText);
|
|
|
|
$sanitizedText = strip_tags_except_allowed_protocols($sanitizedText);
|
|
|
|
|
|
|
|
$newLink->title = $sanitizedText;
|
|
|
|
} else {
|
|
|
|
$newLink->title = $linkData['title'];
|
|
|
|
}
|
|
|
|
|
2023-03-09 00:59:52 +01:00
|
|
|
$newLink->order = $linkData['order'];
|
2024-02-05 16:40:51 +01:00
|
|
|
$newLink->click_number = 0;
|
2023-03-09 00:59:52 +01:00
|
|
|
$newLink->up_link = $linkData['up_link'];
|
|
|
|
$newLink->custom_css = $linkData['custom_css'];
|
|
|
|
$newLink->custom_icon = $linkData['custom_icon'];
|
2024-06-25 14:10:11 +02:00
|
|
|
$newLink->type = $linkData['type'];
|
|
|
|
$newLink->type_params = $linkData['type_params'];
|
2023-03-09 00:59:52 +01:00
|
|
|
|
|
|
|
// Set the user ID to the current user's ID
|
|
|
|
$newLink->user_id = $user->id;
|
|
|
|
|
|
|
|
// Save the new link to the database
|
|
|
|
$newLink->save();
|
|
|
|
}
|
2023-06-19 14:02:19 +02:00
|
|
|
return redirect('studio/profile')->with('success', __('messages.Profile updated successfully!'));
|
2023-03-09 00:59:52 +01:00
|
|
|
} catch (\Exception $e) {
|
2023-06-19 14:02:19 +02:00
|
|
|
return redirect('studio/profile')->with('error', __('messages.An error occurred while updating your profile.'));
|
2023-03-08 17:20:39 +01:00
|
|
|
}
|
|
|
|
}
|
2023-03-09 00:59:52 +01:00
|
|
|
|
2023-03-08 17:20:39 +01:00
|
|
|
|
2023-11-17 17:05:50 +01:00
|
|
|
// Hanle reports
|
|
|
|
function report(Request $request)
|
|
|
|
{
|
|
|
|
$formData = $request->all();
|
|
|
|
|
|
|
|
try {
|
|
|
|
Mail::to(env('ADMIN_EMAIL'))->send(new ReportSubmissionMail($formData));
|
|
|
|
|
|
|
|
return redirect('report')->with('success', __('messages.report_success'));
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
return redirect()->back()->with('error', __('messages.report_error'));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-05 20:02:23 +01:00
|
|
|
//Edit/save page icons
|
2024-02-04 17:49:53 +01:00
|
|
|
public function editIcons(Request $request)
|
2022-12-05 20:02:23 +01:00
|
|
|
{
|
2024-02-04 17:49:53 +01:00
|
|
|
$inputKeys = array_keys($request->except('_token'));
|
|
|
|
|
|
|
|
$validationRules = [];
|
|
|
|
|
|
|
|
foreach ($inputKeys as $platform) {
|
2024-02-07 19:15:30 +01:00
|
|
|
$validationRules[$platform] = 'nullable|exturl|max:255';
|
2024-02-04 17:49:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
$request->validate($validationRules);
|
|
|
|
|
|
|
|
foreach ($inputKeys as $platform) {
|
|
|
|
$link = $request->input($platform);
|
|
|
|
|
|
|
|
if (!empty($link)) {
|
|
|
|
$iconId = $this->searchIcon($platform);
|
|
|
|
|
|
|
|
if (!is_null($iconId)) {
|
|
|
|
$this->updateIcon($platform, $link);
|
|
|
|
} else {
|
|
|
|
$this->addIcon($platform, $link);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-12-05 20:02:23 +01:00
|
|
|
|
2024-02-04 17:49:53 +01:00
|
|
|
return redirect('studio/links#icons');
|
|
|
|
}
|
|
|
|
|
|
|
|
private function searchIcon($icon)
|
|
|
|
{
|
|
|
|
return DB::table('links')
|
2022-12-05 20:02:23 +01:00
|
|
|
->where('user_id', Auth::id())
|
|
|
|
->where('title', $icon)
|
|
|
|
->where('button_id', 94)
|
|
|
|
->value('id');
|
2024-02-04 17:49:53 +01:00
|
|
|
}
|
2022-12-05 20:02:23 +01:00
|
|
|
|
2024-02-04 17:49:53 +01:00
|
|
|
private function addIcon($icon, $link)
|
|
|
|
{
|
2022-12-05 22:58:06 +01:00
|
|
|
$userId = Auth::user()->id;
|
2022-12-05 20:02:23 +01:00
|
|
|
$links = new Link;
|
|
|
|
$links->link = $link;
|
2022-12-05 22:58:06 +01:00
|
|
|
$links->user_id = $userId;
|
2022-12-05 20:02:23 +01:00
|
|
|
$links->title = $icon;
|
2022-12-05 22:58:06 +01:00
|
|
|
$links->button_id = '94';
|
|
|
|
$links->save();
|
|
|
|
$links->order = ($links->id - 1);
|
2022-12-05 20:02:23 +01:00
|
|
|
$links->save();
|
|
|
|
}
|
|
|
|
|
2024-02-04 17:49:53 +01:00
|
|
|
private function updateIcon($icon, $link)
|
|
|
|
{
|
|
|
|
Link::where('id', $this->searchIcon($icon))->update([
|
2022-12-05 20:02:23 +01:00
|
|
|
'button_id' => 94,
|
|
|
|
'link' => $link,
|
|
|
|
'title' => $icon
|
|
|
|
]);
|
|
|
|
}
|
2023-02-16 14:25:37 +01:00
|
|
|
}
|