Esempio n. 1
0
 function generate_pages()
 {
     //Get all page saved in the pages folder
     echo THEME . '/pages <br>';
     $location = THEME . '/pages';
     $pages = Mvc_Functions::directoryToArray($location, true);
     foreach ($pages as $page) {
         if (Mvc_Functions::get_extension($page) != 'twig') {
             continue;
         }
         //Determine page slug
         $new_loc = str_replace($location . '/', THEME . '/templates/', $page);
         $file = str_replace($location . '/', '', $page);
         $slug = str_replace('.twig', '', $file);
         $template = "templates/{$file}";
         // Determine the page Title
         $title = str_replace('/', ' | ', $slug);
         $title = ucwords(str_replace('-', ' ', $title));
         echo "NEW LOCATION: {$new_loc} | FILE: {$file} | TEMPLATE: {$template} | SLUG: {$slug} | TITLE: {$title} <br>";
         //Copy the file to the layouts location
         if (!is_dir(dirname($new_loc))) {
             mkdir(dirname($new_loc), 0777, true);
         }
         copy($page, $new_loc);
         //Create Page Bean
         $page = current(R::findOrDispense('page', 'slug = :slug', ['slug' => $slug]));
         $page->slug = $slug;
         $page->title = "{$title} | Durbanville Hills";
         $page->template = $template;
         $page->layout = "layouts/default.twig";
         R::store($page);
     }
 }
Esempio n. 2
0
 public function create_pages()
 {
     //Load Page files
     $files = Mvc_Functions::directoryToArray($this->theme . "/pages", true);
     //		var_dump($files);exit;
     //Loop throught the files and read theme seperately
     foreach ($files as $file) {
         if (is_dir($file)) {
             continue;
         }
         $id = $file . "-" . BASE_URL;
         //Check file last modified before loading
         $file_mod_time = current(R::findOrDispense('filem', 'filename = :file', ['file' => $id]));
         if (!$file_mod_time->getID()) {
             $file_mod_time->filename = $id;
             $file_mod_time->last_modified = filemtime($file);
             R::store($file_mod_time);
         } else {
             //				debug($file . ' === ' . filemtime($file) . ' ' . $file_mod_time->last_modified);
             if (filemtime($file) > $file_mod_time->last_modified) {
                 $file_mod_time->last_modified = filemtime($file);
                 R::store($file_mod_time);
             } else {
                 continue;
             }
         }
         list($config, $template) = explode("==", file_get_contents($file));
         list($config, $template) = preg_split('/(==\\n)|(==\\r)/', file_get_contents($file));
         //						parent::$lines = preg_split('/\r\n|\n|\r/', trim(file_get_contents('file.txt')));
         $config = new App_Config_Ini($config);
         if ($config->type) {
             $classname = "Theme_Type_" . ucfirst($config->type);
             if (class_exists($classname)) {
                 $class = new $classname($this);
                 if ($class instanceof Theme_Type) {
                     $class->create($file, $config, $template, filemtime($file));
                 }
             }
         } else {
             $class = new Theme_Type_Page($this);
             $class->create($file, $config, $template, filemtime($file));
         }
     }
     //Remove all pages saved in database that does not exist inside the pages folder
     $this->remove_old_pages();
 }