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;
|
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;
|
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)
|
|
|
|
{
|
|
|
|
$littlelink_name = $request->littlelink;
|
|
|
|
$id = User::select('id')->where('littlelink_name', $littlelink_name)->value('id');
|
|
|
|
|
2022-03-24 14:44:33 +01:00
|
|
|
if (empty($id)) {
|
|
|
|
return abort(404);
|
|
|
|
}
|
2022-04-07 15:54:03 +02:00
|
|
|
|
2022-05-18 21:08:58 +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-03-24 14:44:33 +01:00
|
|
|
|
2022-04-11 13:31:11 +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();
|
2022-03-24 14:44:33 +01:00
|
|
|
|
|
|
|
return view('littlelink', ['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');
|
|
|
|
|
2021-04-16 01:00:00 +02:00
|
|
|
if (empty($id)) {
|
|
|
|
return abort(404);
|
|
|
|
}
|
2022-11-09 18:07:50 +01: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();
|
|
|
|
|
|
|
|
$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();
|
2021-04-16 01:00:00 +02:00
|
|
|
|
2021-07-06 10:40:16 +02:00
|
|
|
return view('littlelink', ['userinfo' => $userinfo, 'information' => $information, 'links' => $links, 'littlelink_name' => $littlelink_name]);
|
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
|
|
|
{
|
2022-11-08 16:11:59 +01:00
|
|
|
|
|
|
|
if ($id !== 0) {
|
|
|
|
$linkData = Link::find($id);
|
|
|
|
} else {
|
|
|
|
$linkData = new Link(['typename' => 'link', 'id'=>'0']);
|
|
|
|
}
|
|
|
|
$data['LinkTypes'] = LinkType::get();
|
|
|
|
$data['LinkData'] = $linkData;
|
|
|
|
$data['LinkID'] = $id;
|
2022-11-10 18:21:59 +01:00
|
|
|
$data['linkTypeID'] = "1";
|
2022-11-14 11:37:30 +01:00
|
|
|
$data['title'] = "Predefined Site";
|
2022-11-10 18:21:59 +01:00
|
|
|
|
|
|
|
if (Route::currentRouteName() != 'showButtons') {
|
|
|
|
$links = DB::table('links')->where('id', $id)->first();
|
|
|
|
|
|
|
|
$bid = $links->button_id;
|
2022-11-10 19:03:35 +01:00
|
|
|
|
2022-11-10 18:21:59 +01:00
|
|
|
if($bid == 1 or $bid == 2){
|
2022-11-16 16:33:00 +01:00
|
|
|
$data['linkTypeID'] = "2";
|
2022-11-10 18:21:59 +01:00
|
|
|
} elseif ($bid == 42) {
|
|
|
|
$data['linkTypeID'] = "3";
|
|
|
|
} elseif ($bid == 43) {
|
|
|
|
$data['linkTypeID'] = "4";
|
|
|
|
} else {
|
2022-11-16 16:33:00 +01:00
|
|
|
$data['linkTypeID'] = "1";
|
2022-11-10 18:21:59 +01:00
|
|
|
}
|
2022-11-10 19:03:35 +01:00
|
|
|
|
|
|
|
$data['title'] = LinkType::where('id', $data['linkTypeID'])->value('title');
|
2022-11-10 18:21:59 +01:00
|
|
|
}
|
2022-11-08 16:11:59 +01:00
|
|
|
|
|
|
|
foreach ($data['LinkTypes']->toArray() as $key => $val) {
|
|
|
|
if ($val['typename'] === $linkData['typename']) {
|
|
|
|
$data['SelectedLinkType'] = $val;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2022-11-14 09:33:21 +01: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
|
2022-11-08 16:11:59 +01:00
|
|
|
public function saveLink(request $request)
|
2021-04-16 01:00:00 +02:00
|
|
|
{
|
2022-11-08 16:11:59 +01:00
|
|
|
// if ($request->button == 'heading' or $request->button == 'space')
|
|
|
|
// $request->validate([
|
|
|
|
// 'link' => '',
|
|
|
|
// 'title' => '',
|
|
|
|
// 'button' => 'required'
|
|
|
|
// ]);
|
|
|
|
// else
|
|
|
|
// $request->validate([
|
|
|
|
// 'link' => 'required',
|
|
|
|
// 'title' => '',
|
|
|
|
// 'button' => 'required'
|
|
|
|
// ]);
|
2021-04-16 01:00:00 +02:00
|
|
|
|
2022-11-08 16:11:59 +01:00
|
|
|
$linkType = LinkType::find($request->linktype_id);
|
|
|
|
$LinkTitle = ($request->link_text ?? $request->link_title) ?? $request->title;
|
|
|
|
$LinkURL = $request->link_url ?? $request->link;
|
|
|
|
|
|
|
|
|
|
|
|
$OrigLink = Link::find($request->linkid);
|
|
|
|
|
|
|
|
|
|
|
|
// if (stringStartsWith($LinkURL, 'http://') == 'true' or stringStartsWith($LinkURL, 'https://') == 'true')
|
|
|
|
// $link1 = $LinkURL;
|
|
|
|
// elseif (!empty($LinkURL))
|
|
|
|
// $link1 = 'https://' . $LinkURL;
|
|
|
|
|
|
|
|
// if (stringEndsWith($LinkURL, '/') == 'true')
|
|
|
|
// $link = rtrim($link1, "/ ");
|
|
|
|
// else
|
|
|
|
// $link = $link1;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$customParams = [];
|
|
|
|
foreach ($request->all() as $key => $param) {
|
|
|
|
//echo $key . " = " . $param . "<br />";
|
|
|
|
if (str_starts_with($key, "_") || in_array($key, ['linktype_id', 'linktype_title', 'link_text', 'link_url']))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
$customParams[$key] = $param;
|
|
|
|
}
|
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();
|
2021-04-16 01:00:00 +02:00
|
|
|
|
2022-11-08 16:11:59 +01:00
|
|
|
if ($button && empty($LinkTitle))
|
|
|
|
$LinkTitle = ucwords($button->name);
|
|
|
|
|
|
|
|
if ($linkType->typename == 'video' && empty($LinkTitle)) {
|
|
|
|
$embed = OEmbed::get($LinkURL);
|
|
|
|
if ($embed) {
|
|
|
|
$LinkTitle = $embed->data()['title'];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$message = (ucwords($button?->name) ?? ucwords($linkType->typename)). " has been ";
|
|
|
|
|
|
|
|
if ($OrigLink) {
|
|
|
|
//EDITING EXISTING
|
2022-11-10 19:55:46 +01:00
|
|
|
|
|
|
|
$isCustomWebsite = $customParams['GetSiteIcon'] ?? null;
|
|
|
|
$SpacerHeight = $customParams['height'] ?? null;
|
|
|
|
|
|
|
|
if($linkType->typename == "link" and $isCustomWebsite == "1"){
|
|
|
|
$OrigLink->update([
|
|
|
|
'link' => $LinkURL,
|
|
|
|
'title' => $LinkTitle,
|
|
|
|
'button_id' => "2",
|
|
|
|
]);
|
|
|
|
}elseif($linkType->typename == "link"){
|
|
|
|
$OrigLink->update([
|
|
|
|
'link' => $LinkURL,
|
|
|
|
'title' => $LinkTitle,
|
|
|
|
'button_id' => "1",
|
|
|
|
]);
|
|
|
|
}elseif($linkType->typename == "spacer"){
|
|
|
|
$OrigLink->update([
|
|
|
|
'link' => $LinkURL,
|
2022-11-14 09:33:21 +01:00
|
|
|
'title' => $customParams['height'] ?? null,
|
2022-11-10 19:55:46 +01:00
|
|
|
'button_id' => "43",
|
|
|
|
]);
|
|
|
|
}elseif($linkType->typename == "heading"){
|
|
|
|
$OrigLink->update([
|
|
|
|
'link' => $LinkURL,
|
|
|
|
'title' => $LinkTitle,
|
|
|
|
'button_id' => "42",
|
|
|
|
]);
|
|
|
|
}else{
|
|
|
|
$OrigLink->update([
|
|
|
|
'link' => $LinkURL,
|
|
|
|
'title' => $LinkTitle,
|
|
|
|
'button_id' => $button?->id,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2022-11-08 16:11:59 +01:00
|
|
|
$message .="updated";
|
|
|
|
} else {
|
|
|
|
// ADDING NEW
|
|
|
|
|
|
|
|
$isCustomWebsite = $customParams['GetSiteIcon'] ?? null;
|
|
|
|
$SpacerHeight = $customParams['height'] ?? null;
|
|
|
|
|
|
|
|
$links = new Link;
|
|
|
|
$links->link = $LinkURL;
|
|
|
|
$links->user_id = $userId;
|
|
|
|
if($linkType->typename == "spacer"){
|
|
|
|
$links->title = $SpacerHeight;
|
|
|
|
}else{
|
|
|
|
$links->title = $LinkTitle;
|
|
|
|
}
|
|
|
|
if($linkType->typename == "link" and $isCustomWebsite == "1"){
|
|
|
|
$links->button_id = "2";
|
|
|
|
}elseif($linkType->typename == "link"){
|
|
|
|
$links->button_id = "1";
|
|
|
|
}elseif($linkType->typename == "spacer"){
|
|
|
|
$links->button_id = "43";
|
|
|
|
}elseif($linkType->typename == "heading"){
|
|
|
|
$links->button_id = "42";
|
|
|
|
}else{
|
|
|
|
$links->button_id = $button?->id;
|
|
|
|
}
|
|
|
|
// $links->type_params = json_encode($customParams);
|
|
|
|
// $links->typename = $linkType->typename;
|
|
|
|
$links->save();
|
|
|
|
|
|
|
|
$links->order = ($links->id - 1);
|
|
|
|
$links->save();
|
|
|
|
$message .= "added";
|
|
|
|
}
|
|
|
|
|
|
|
|
return Redirect('studio/links')
|
|
|
|
->with('success', $message);
|
|
|
|
|
|
|
|
// echo $customParams['GetSiteIcon'];
|
2021-04-16 01:00:00 +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;
|
2022-11-25 16:50:11 +01:00
|
|
|
$link = Link::find($linkId);
|
|
|
|
$link = $link->link;
|
2022-11-08 16:11:59 +01:00
|
|
|
|
2021-04-16 01:00:00 +02:00
|
|
|
Link::where('id', $linkId)->increment('click_number', 1);
|
|
|
|
|
|
|
|
return redirect()->away($link);
|
|
|
|
}
|
2022-11-08 16:11:59 +01: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
|
|
|
|
2022-04-11 13:06:34 +02:00
|
|
|
$data['links'] = Link::select('id', 'link', 'title', 'order', 'click_number', 'up_link', 'links.button_id')->where('user_id', $userId)->orderBy('up_link', 'asc')->orderBy('order', 'asc')->paginate(10);
|
2021-04-16 01:00:00 +02:00
|
|
|
return view('studio/links', $data);
|
|
|
|
}
|
|
|
|
|
2022-08-05 17:29:49 +02:00
|
|
|
//Show link, 20
|
|
|
|
public function showLinks20()
|
|
|
|
{
|
|
|
|
$userId = Auth::user()->id;
|
2022-08-14 21:05:26 +02:00
|
|
|
$data['pagePage'] = 20;
|
2022-08-05 17:29:49 +02:00
|
|
|
|
|
|
|
$data['links'] = Link::select('id', 'link', 'title', 'order', 'click_number', 'up_link', 'links.button_id')->where('user_id', $userId)->orderBy('up_link', 'asc')->orderBy('order', 'asc')->paginate(20);
|
|
|
|
return view('studio/links', $data);
|
|
|
|
}
|
|
|
|
|
|
|
|
//Show link, 30
|
|
|
|
public function showLinks30()
|
|
|
|
{
|
|
|
|
$userId = Auth::user()->id;
|
2022-08-14 21:05:26 +02:00
|
|
|
$data['pagePage'] = 30;
|
2022-08-05 17:29:49 +02:00
|
|
|
|
|
|
|
$data['links'] = Link::select('id', 'link', 'title', 'order', 'click_number', 'up_link', 'links.button_id')->where('user_id', $userId)->orderBy('up_link', 'asc')->orderBy('order', 'asc')->paginate(30);
|
|
|
|
return view('studio/links', $data);
|
|
|
|
}
|
|
|
|
|
|
|
|
//Show link, all
|
|
|
|
public function showLinksAll()
|
|
|
|
{
|
|
|
|
$userId = Auth::user()->id;
|
2022-08-14 21:05:26 +02:00
|
|
|
$data['pagePage'] = 0;
|
2022-08-05 17:29:49 +02:00
|
|
|
|
|
|
|
$data['links'] = Link::select('id', 'link', 'title', 'order', 'click_number', 'up_link', 'links.button_id')->where('user_id', $userId)->orderBy('up_link', 'asc')->orderBy('order', 'asc')->paginate(10000000000);
|
|
|
|
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
|
|
|
|
2022-11-28 19:44:02 +01:00
|
|
|
$directory = base_path("studio/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("studio/favicon/icons")."/".$linkId.".".$pathinfo);} catch (exception $e) {}
|
|
|
|
}
|
|
|
|
|
|
|
|
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([
|
|
|
|
'link' => 'required',
|
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
|
2022-11-08 16:11:59 +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)
|
|
|
|
public function editPage(request $request)
|
|
|
|
{
|
2022-11-08 16:11:59 +01:00
|
|
|
$request->validate([
|
2022-11-10 16:51:56 +01:00
|
|
|
'littlelink_name' => 'string|max:255|unique:users',
|
|
|
|
'name' => 'string|max:255|unique:users',
|
2022-11-08 16:11:59 +01:00
|
|
|
]);
|
|
|
|
|
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;
|
2021-04-16 01:00:00 +02:00
|
|
|
|
|
|
|
$profilePhoto = $request->file('image');
|
|
|
|
$pageName = $request->pageName;
|
2022-11-10 21:48:48 +01:00
|
|
|
$pageDescription = strip_tags($request->pageDescription,'<a><p><strong><i><ul><ol><li><blockquote><h2><h3><h4>');
|
|
|
|
$pageDescription = preg_replace("/<a([^>]*)>/i", "<a $1 rel=\"noopener noreferrer nofollow\">", $pageDescription);
|
2022-11-08 16:11:59 +01:00
|
|
|
$name = $request->Name;
|
2021-04-16 01:00:00 +02:00
|
|
|
|
2022-11-08 16:11:59 +01:00
|
|
|
User::where('id', $userId)->update(['littlelink_name' => $pageName, 'littlelink_description' => $pageDescription, 'name' => $name]);
|
|
|
|
|
|
|
|
if (!empty($profilePhoto)) {
|
|
|
|
$profilePhoto->move(base_path('/img'), $littlelink_name . ".png");
|
2021-04-16 01:00:00 +02:00
|
|
|
}
|
|
|
|
|
2022-05-13 16:09:00 +02:00
|
|
|
return Redirect('/studio/page');
|
2021-04-16 01:00:00 +02:00
|
|
|
}
|
|
|
|
|
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]);
|
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") {
|
|
|
|
$user = User::find($id);
|
|
|
|
|
|
|
|
Schema::disableForeignKeyConstraints();
|
|
|
|
$user->forceDelete();
|
|
|
|
Schema::enableForeignKeyConstraints();
|
|
|
|
}
|
|
|
|
|
|
|
|
return redirect('/');
|
|
|
|
}
|
2022-05-04 00:40:41 +02:00
|
|
|
}
|