2021-04-16 01:00:00 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
|
|
|
use Illuminate\Http\Request;
|
|
|
|
use Illuminate\Support\Facades\Hash;
|
|
|
|
|
|
|
|
use Auth;
|
|
|
|
use DB;
|
2022-05-18 21:08:58 +02:00
|
|
|
use ZipArchive;
|
2021-04-16 01:00:00 +02:00
|
|
|
|
|
|
|
use App\Models\User;
|
|
|
|
use App\Models\Button;
|
|
|
|
use App\Models\Link;
|
|
|
|
|
2022-05-18 21:08:58 +02:00
|
|
|
|
2022-03-31 22:43:01 +02:00
|
|
|
//Function tests if string starts with certain string (used to test for illegal strings)
|
|
|
|
function stringStartsWith($haystack,$needle,$case=true) {
|
|
|
|
if ($case){
|
|
|
|
return strpos($haystack, $needle, 0) === 0;
|
|
|
|
}
|
|
|
|
return stripos($haystack, $needle, 0) === 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
//Function tests if string ends with certain string (used to test for illegal strings)
|
|
|
|
function stringEndsWith($haystack,$needle,$case=true) {
|
|
|
|
$expectedPosition = strlen($haystack) - strlen($needle);
|
|
|
|
if ($case){
|
|
|
|
return strrpos($haystack, $needle, 0) === $expectedPosition;
|
|
|
|
}
|
|
|
|
return strripos($haystack, $needle, 0) === $expectedPosition;
|
|
|
|
}
|
2021-04-16 01:00:00 +02:00
|
|
|
|
|
|
|
class UserController extends Controller
|
|
|
|
{
|
|
|
|
|
|
|
|
//Statistics of the number of clicks and links
|
|
|
|
public function index()
|
|
|
|
{
|
|
|
|
$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
|
|
|
|
|
|
|
$links = Link::where('user_id', $userId)->select('link')->count();
|
|
|
|
|
|
|
|
$clicks = Link::where('user_id', $userId)->sum('click_number');
|
|
|
|
|
2021-04-18 19:43:43 +02:00
|
|
|
return view('studio/index', ['littlelink_name' => $littlelink_name, 'links' => $links, 'clicks' => $clicks]);
|
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-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();
|
2021-04-16 01:00:00 +02:00
|
|
|
|
2022-04-28 16:54:57 +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();
|
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
|
|
|
}
|
|
|
|
|
|
|
|
//Show buttons for add link
|
|
|
|
public function showButtons()
|
|
|
|
{
|
2022-07-31 23:55:20 +02:00
|
|
|
$data['buttons'] = Button::select('name')->orderBy('name', 'asc')->get();
|
2021-04-16 01:00:00 +02:00
|
|
|
return view('studio/add-link', $data);
|
|
|
|
}
|
|
|
|
|
|
|
|
//Save add link
|
|
|
|
public function addLink(request $request)
|
|
|
|
{
|
2022-05-06 15:26:39 +02:00
|
|
|
if ($request->button == 'heading' or $request->button == 'space')
|
|
|
|
$request->validate([
|
|
|
|
'link' => '',
|
|
|
|
'title' => '',
|
|
|
|
'button' => 'required'
|
|
|
|
]);
|
|
|
|
else
|
2021-04-16 01:00:00 +02:00
|
|
|
$request->validate([
|
|
|
|
'link' => 'required',
|
2022-03-18 12:04:13 +01:00
|
|
|
'title' => '',
|
2021-04-16 01:00:00 +02:00
|
|
|
'button' => 'required'
|
|
|
|
]);
|
|
|
|
|
2022-07-15 17:46:26 +02:00
|
|
|
if ($request->button == 'phone')
|
|
|
|
$link1 = 'tel:' . $request->link;
|
2022-07-15 19:37:34 +02:00
|
|
|
elseif ($request->button == 'default email' or $request->button == 'default email_alt')
|
|
|
|
$link1 = 'mailto:' . $request->link;
|
2022-07-15 17:46:26 +02:00
|
|
|
elseif (stringStartsWith($request->link,'http://') == 'true' or stringStartsWith($request->link,'https://') == 'true')
|
2022-03-31 22:45:51 +02:00
|
|
|
$link1 = $request->link;
|
2022-03-31 22:43:01 +02:00
|
|
|
else
|
2022-03-31 22:45:51 +02:00
|
|
|
$link1 = 'https://' . $request->link;
|
|
|
|
if (stringEndsWith($request->link,'/') == 'true')
|
|
|
|
$link = rtrim($link1, "/ ");
|
|
|
|
else
|
|
|
|
$link = $link1;
|
2022-03-18 12:04:13 +01:00
|
|
|
if ($request->title == '')
|
|
|
|
$title = $request->button;
|
|
|
|
else
|
2021-07-06 10:40:16 +02:00
|
|
|
$title = $request->title;
|
2021-04-16 01:00:00 +02:00
|
|
|
$button = $request->button;
|
|
|
|
|
|
|
|
$userId = Auth::user()->id;
|
|
|
|
$buttonId = Button::select('id')->where('name' , $button)->value('id');
|
|
|
|
|
|
|
|
$links = new Link;
|
|
|
|
$links->link = $link;
|
|
|
|
$links->user_id = $userId;
|
2021-07-06 10:40:16 +02:00
|
|
|
$links->title = $title;
|
2021-04-16 01:00:00 +02:00
|
|
|
$links->button_id = $buttonId;
|
|
|
|
$links->save();
|
|
|
|
|
|
|
|
return back();
|
|
|
|
}
|
|
|
|
|
|
|
|
//Count the number of clicks and redirect to link
|
|
|
|
public function clickNumber(request $request)
|
|
|
|
{
|
|
|
|
$link = $request->link;
|
2021-07-06 12:19:09 +02:00
|
|
|
$query = $request->query();
|
2021-04-16 01:00:00 +02:00
|
|
|
$linkId = $request->id;
|
|
|
|
|
|
|
|
if(empty($link && $linkId))
|
|
|
|
{
|
|
|
|
return abort(404);
|
|
|
|
}
|
2021-07-06 12:19:09 +02:00
|
|
|
|
|
|
|
if(!empty($query)) {
|
2021-07-06 12:35:22 +02:00
|
|
|
$qs = [];
|
|
|
|
foreach($query as $qk => $qv) { $qs[] = $qk .'='. $qv; }
|
|
|
|
$link = $link .'?'. implode('&', $qs);
|
2021-07-06 12:19:09 +02:00
|
|
|
}
|
2021-04-16 01:00:00 +02:00
|
|
|
|
|
|
|
Link::where('id', $linkId)->increment('click_number', 1);
|
|
|
|
|
|
|
|
return redirect()->away($link);
|
|
|
|
}
|
|
|
|
|
|
|
|
//Show link, click number, up link in links page
|
|
|
|
public function showLinks()
|
|
|
|
{
|
|
|
|
$userId = Auth::user()->id;
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
//Delete link
|
|
|
|
public function deleteLink(request $request)
|
|
|
|
{
|
|
|
|
$linkId = $request->id;
|
|
|
|
|
|
|
|
Link::where('id', $linkId)->delete();
|
|
|
|
|
|
|
|
return back();
|
|
|
|
}
|
|
|
|
|
|
|
|
//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');
|
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');
|
2021-04-16 01:00:00 +02:00
|
|
|
|
2022-08-02 00:33:32 +02:00
|
|
|
|
|
|
|
$buttons = Button::select('id', 'name')->orderBy('name', 'asc')->get();
|
2021-04-16 01:00:00 +02:00
|
|
|
|
2022-07-31 13:35:52 +02: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-04-13 15:37:54 +02: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-03-31 22:43:01 +02:00
|
|
|
if (stringStartsWith($request->link,'http://') == 'true' or stringStartsWith($request->link,'https://') == 'true' or stringStartsWith($request->link,'mailto:') == 'true')
|
2022-03-31 22:45:51 +02:00
|
|
|
$link1 = $request->link;
|
2022-03-31 22:43:01 +02:00
|
|
|
else
|
2022-03-31 22:45:51 +02:00
|
|
|
$link1 = 'https://' . $request->link;
|
|
|
|
if (stringEndsWith($request->link,'/') == 'true')
|
|
|
|
$link = rtrim($link1, "/ ");
|
|
|
|
else
|
|
|
|
$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;
|
|
|
|
|
|
|
|
$buttonId = Button::select('id')->where('name' , $button)->value('id');
|
|
|
|
|
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-04-13 16:49:44 +02: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 =! "") {
|
2022-04-10 17:42:29 +02:00
|
|
|
Link::where('id', $linkId)->update(['custom_css' => $custom_css]);
|
2022-04-13 16:49:44 +02:00
|
|
|
} 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;
|
|
|
|
|
|
|
|
$data['pages'] = User::where('id', $userId)->select('littlelink_name', 'littlelink_description')->get();
|
|
|
|
|
|
|
|
return view('/studio/page', $data);
|
|
|
|
}
|
|
|
|
|
|
|
|
//Save littlelink page (name, description, logo)
|
|
|
|
public function editPage(request $request)
|
|
|
|
{
|
|
|
|
$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;
|
|
|
|
$pageDescription = $request->pageDescription;
|
|
|
|
|
|
|
|
User::where('id', $userId)->update(['littlelink_name' => $pageName, 'littlelink_description' => $pageDescription]);
|
|
|
|
|
|
|
|
if(!empty($profilePhoto)){
|
2022-02-14 12:47:57 +01:00
|
|
|
$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;
|
|
|
|
|
|
|
|
User::where('id', $userId)->update(['theme' => $theme]);
|
|
|
|
|
|
|
|
if(!empty($zipfile)){
|
|
|
|
|
|
|
|
$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');
|
|
|
|
}
|
|
|
|
|
|
|
|
return Redirect('/studio/theme');
|
|
|
|
}
|
|
|
|
|
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-03-31 21:31:00 +02: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]);
|
|
|
|
}
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
$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();
|
|
|
|
|
|
|
|
return view('components/theme', ['userinfo' => $userinfo, 'information' => $information, 'links' => $links, 'littlelink_name' => $littlelink_name]);
|
|
|
|
}
|
|
|
|
|
2022-05-04 00:40:41 +02:00
|
|
|
}
|