77
88use Auth ;
99use DB ;
10+ use ZipArchive ;
1011
1112use App \Models \User ;
1213use App \Models \Button ;
1314use App \Models \Link ;
1415
16+
1517 //Function tests if string starts with certain string (used to test for illegal strings)
1618function stringStartsWith ($ haystack ,$ needle ,$ case =true ) {
1719 if ($ case ){
@@ -56,8 +58,8 @@ public function littlelink(request $request)
5658 return abort (404 );
5759 }
5860
59- $ userinfo = User::select ('name ' , 'littlelink_name ' , 'littlelink_description ' )->where ('id ' , $ id )->first ();
60- $ information = User::select ('name ' , 'littlelink_name ' , 'littlelink_description ' )->where ('id ' , $ id )->get ();
61+ $ userinfo = User::select ('name ' , 'littlelink_name ' , 'littlelink_description ' , ' theme ' )->where ('id ' , $ id )->first ();
62+ $ information = User::select ('name ' , 'littlelink_name ' , 'littlelink_description ' , ' theme ' )->where ('id ' , $ id )->get ();
6163
6264 $ 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 ();
6365
@@ -74,8 +76,8 @@ public function littlelinkhome(request $request)
7476 return abort (404 );
7577 }
7678
77- $ userinfo = User::select ('name ' , 'littlelink_name ' , 'littlelink_description ' )->where ('id ' , $ id )->first ();
78- $ information = User::select ('name ' , 'littlelink_name ' , 'littlelink_description ' )->where ('id ' , $ id )->get ();
79+ $ userinfo = User::select ('name ' , 'littlelink_name ' , 'littlelink_description ' , ' theme ' )->where ('id ' , $ id )->first ();
80+ $ information = User::select ('name ' , 'littlelink_name ' , 'littlelink_description ' , ' theme ' )->where ('id ' , $ id )->get ();
7981
8082 $ 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 ();
8183
@@ -301,8 +303,47 @@ public function editPage(request $request)
301303 return Redirect ('/studio/page ' );
302304 }
303305
306+ //Show custom theme
307+ public function showTheme (request $ request )
308+ {
309+ $ userId = Auth::user ()->id ;
310+
311+ $ data ['pages ' ] = User::where ('id ' , $ userId )->select ('littlelink_name ' , 'theme ' )->get ();
312+
313+ return view ('/studio/theme ' , $ data );
314+ }
315+
316+ //Save custom theme
317+ public function editTheme (request $ request )
318+ {
319+ $ request ->validate ([
320+ 'zip ' => 'sometimes|mimes:zip ' ,
321+ ]);
322+
323+ $ userId = Auth::user ()->id ;
324+
325+ $ zipfile = $ request ->file ('zip ' );
326+
327+ $ theme = $ request ->theme ;
328+
329+ User::where ('id ' , $ userId )->update (['theme ' => $ theme ]);
330+
331+ if (!empty ($ zipfile )){
332+
333+ $ zipfile ->move (base_path ('/themes ' ), "temp.zip " );
334+
335+ $ zip = new ZipArchive ;
336+ $ zip ->open (base_path () . '/themes/temp.zip ' );
337+ $ zip ->extractTo (base_path () . '/themes ' );
338+ $ zip ->close ();
339+ unlink (base_path () . '/themes/temp.zip ' );
340+ }
341+
342+ return Redirect ('/studio/theme ' );
343+ }
344+
304345 //Show user (name, email, password)
305- public function showProfile ()
346+ public function showProfile (request $ request )
306347 {
307348 $ userId = Auth::user ()->id ;
308349
0 commit comments