Example #1
0
 private static function append_pages()
 {
     // We only want pages linked by a menu somewhere
     $menus = Menu::all();
     foreach ($menus as $menu) {
         // Determine importance based on menu hierarchy
         $level = 0;
         $tmp = $menu;
         while ($tmp->parent !== null) {
             $level += 0.1;
             $tmp = $tmp->parent;
         }
         // Get the page
         $page = Page::where('permalink', $menu->url)->where('location_id', $menu->location_id)->first();
         if ($page != null) {
             array_push(static::$allPages, ['loc' => URL::to($menu->url), 'mod' => $page->updated_at->toDateString(), 'freq' => 'monthly', 'pri' => 0.7 + $level]);
         } else {
             // This was a static link
         }
     }
 }
 private function addPage($file, $folder)
 {
     $permalink = substr($file, strlen($this->pageDir) + 1, -5);
     // Remove .html
     if (Page::where('permalink', $permalink)->first()) {
         return;
     }
     // Create both a page...
     $page = new Page();
     $page->permalink = $permalink;
     // Defaults
     $page->description = "Reed's Metals sells and manufactures metal roofing panels and steel buildings. Contact Reed's for standing seam roofing, residential siding, and pre-engineered buildings";
     $page->keywords = "Reed's Metals, steel manufacturing, steel, metal, roofing, panels, metal buildings, metal roofing, steel buildings, pre-engineered buildings, standing seam, residential";
     // And a menu
     $menu = new Menu();
     $menu->url = $permalink;
     // But we'll delete the page if there's no content (a link)
     $hasContent = false;
     $handle = fopen($file, "r");
     if ($handle) {
         while (!feof($handle)) {
             $buffer = fgets($handle);
             if (strpos($buffer, '@content') !== false) {
                 $page->save();
                 // Just in case
                 $this->processContent($handle, $page);
                 $hasContent = true;
             } else {
                 if (strpos($buffer, '@title') !== false) {
                     // Remove "@title "
                     $page->title = trim(substr($buffer, 7, -1));
                     // Remove "\n"
                     $menu->title = $page->title;
                 } else {
                     if (strpos($buffer, '@description') !== false) {
                         // Remove "@description "
                         $page->description = substr($buffer, 13, -1);
                         // Remove "\n"
                     } else {
                         if (strpos($buffer, '@keywords') !== false) {
                             // Remove "@keywords "
                             $page->keywords = substr($buffer, 10, -1);
                             // Remove "\n"
                         } else {
                             if (strpos($buffer, '@link') !== false) {
                                 $menu->url = trim(substr($buffer, 5, -1));
                                 // Remove "\n"
                             } else {
                                 if (strpos($buffer, '@order') !== false) {
                                     $menu->order = substr($buffer, 6, -1);
                                     // Remove "\n"
                                 }
                             }
                         }
                     }
                 }
             }
         }
         fclose($handle);
     }
     $pageIsIndex = substr($file, -10) == 'index.html';
     if ($pageIsIndex) {
         $page->permalink = substr($page->permalink, 0, -6);
     }
     if ($hasContent) {
         $page->save();
     }
     // Now create a copy of this page PER LOCATION
     foreach ($this->locations as $location) {
         if ($hasContent) {
             $perLocationPage = new Page();
             $perLocationPage->fill($page->getAttributes());
             $perLocationPage->id = null;
             $perLocationPage->location()->associate($location);
             $perLocationPage->save();
         }
         if ($pageIsIndex) {
             // If this is an index, the parent menu IS this menu
             $perLocationMenu = Menu::where('title', $folder)->where('location_id', $location->id)->first();
             if ($perLocationMenu == null) {
                 // Create it
                 $perLocationMenu = new Menu();
                 $perLocationMenu->title = $folder;
                 $perLocationMenu->url = $page->permalink;
                 $perLocationMenu->location()->associate($location);
                 $perLocationMenu->save();
             } else {
                 // Update it
                 $perLocationMenu->url = $page->permalink;
                 $perLocationMenu->save();
             }
         } else {
             $perLocationMenu = new Menu();
             $perLocationMenu->fill($menu->getAttributes());
             $perLocationMenu->id = null;
             $perLocationMenu->location()->associate($location);
             if (!empty($folder)) {
                 // If lastFolder is a thing, we've got a parent
                 $parent = Menu::where('title', $folder)->where('location_id', $location->id)->first();
                 if ($parent == null) {
                     // Create it
                     $parent = new Menu();
                     $parent->title = $folder;
                     $parent->url = '/';
                     $parent->location()->associate($location);
                     $parent->save();
                 }
                 $perLocationMenu->parent()->associate($parent);
             }
             $perLocationMenu->save();
         }
     }
     echo "Created menu item: " . $page->title . "\n";
     unset($page);
     unset($menu);
 }