| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | namespace MeestorHok\Blue\Http\Controllers; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |   | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | use MeestorHok\Blue\Http\Controllers\Controller; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | use Illuminate\Http\Request; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | use SEO; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | use MeestorHok\Blue\Site; | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 9 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 10 |  |  | class SiteController extends Controller | 
            
                                                                        
                            
            
                                    
            
            
                | 11 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |     public function showCreateForm ()  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |         return SEO::make([ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |             'title' => 'Create Site', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |             'description' => 'You currently don\'t have a site! Create one now to get started!' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |         ], 'Blue::auth.new-site'); | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 18 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 19 |  |  |      | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |     public function createSite (Request $request) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |         $this->validate($request, [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |             'siteName' => 'required|unique:sites,title|max:100', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |             'slogan' => 'max:155', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |             'description' => 'required|max:255', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |             'keywords' => 'max:255', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |             'copyright' => 'max:100' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |         ], [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |             'siteName.required' => 'Your site must have a name!', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |             'siteName.unique' => 'You already own a site by that name.', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |             'description.required' => 'Tell us a little about the site.' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |         ]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |          | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |         $socialLinks = [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |             'facebook'  => insert_if_exists($request->useFacebook, $request->linkFacebook), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |             'twitter'   => insert_if_exists($request->useTwitter, $request->linkTwitter), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |             'instagram' => insert_if_exists($request->useInstagram, $request->linkInstagram), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |             'pinterest' => insert_if_exists($request->usePinterest, $request->linkPinterest), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |             'youtube'   => insert_if_exists($request->useYoutube, $request->linkYoutube), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |         ]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |          | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |         $data = [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |             'title' => $request->siteName, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |             'slogan' => $request->slogan, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |             'description' => $request->description, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |             'copyright' => $request->copyright, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |             'favicons' => SEO::generateFavicons(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |             'is_public_site' => is_null($request->hideFromSearchEngines), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |             'social_links' => json_encode($socialLinks), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |             'keywords' => $request->keywords | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |         ]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |          | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |         Site::create($data); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |          | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |         return redirect()->route('create.admin'); | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 56 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 57 |  |  |      | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |     public function showAdminForm () | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |         return SEO::make([ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |             'title' => 'Create Admin', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |             'description' => 'Register as the first admin on your new site!' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |         ], 'Blue::auth.new-admin'); | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 64 |  |  |     } | 
            
                                                        
            
                                    
            
            
                | 65 |  |  | } |