static function parse_get(&$data, $template)
 {
     # match any gets
     preg_match('/([\\S\\s]*?)get[\\s]+?["\']\\/?(.*?)\\/?["\']\\s+?do\\s+?([\\S\\s]+?)end\\b([\\S\\s]*)$/', $template, $template_parts);
     # run the replacements on the pre-"get" part of the partial
     $template = self::parse($data, $template_parts[1]);
     # turn route into file path
     $file_path = Helpers::url_to_file_path($template_parts[2]);
     # store current data
     $current_data = $data;
     # if the route exists...
     if (file_exists($file_path)) {
         # check for any nested matches
         $template_parts = self::test_nested_matches($template_parts, 'get[\\s]+?["\']\\/?.*?\\/?["\']\\s+?do', 'end\\b');
         # set data object to match file path
         $data = AssetFactory::get($file_path);
         # run the replacements on the inner-"get" part of the partial
         $template .= self::parse($data, $template_parts[3]);
     }
     # revert context back to original
     $data = $current_data;
     # run the replacements on the post-"get" part of the partial
     $template .= self::parse($data, $template_parts[4]);
     return $template;
 }
Exemple #2
0
 function __construct($url, $content = false)
 {
     # store url and converted file path
     $this->file_path = Helpers::url_to_file_path($url);
     $this->url_path = $url;
     $this->template_name = self::template_name($this->file_path);
     $this->template_file = self::template_file($this->template_name);
     $this->template_type = self::template_type($this->template_file);
     # create/set all content variables
     PageData::create($this, $content);
 }
 function __construct($url)
 {
     # store url and converted file path
     $this->url_path = $url;
     $this->file_path = Helpers::url_to_file_path($this->url_path);
     $this->template_name = $this->template_name();
     $this->template_file = $this->template_file();
     # create/set all content variables
     PageData::create($this);
     # sort data array by key length
     #
     # this ensures that something like '@title' doesn't turn '@page_title'
     # into '@page_Contents of @title variable' in the final rendered template
     #
     uksort($this->data, array('Helpers', 'sort_by_length'));
 }
 function get($url, $current_url = '')
 {
     # strip leading & trailing slashes from $url
     $url = preg_replace(array('/^\\//', '/\\/$/'), '', $url);
     # if the current url is passed, then we use it to build up a relative context
     $url = $current_url . $url;
     # strip leading '../'s from the url if any exists
     $url = preg_replace('/^((\\.+)*\\/)*/', '', $url);
     # turn route into file path
     $file_path = Helpers::url_to_file_path($url);
     # check for children of the index page
     if (!$file_path) {
         return $file_path = Helpers::url_to_file_path('index/' . $url);
     }
     # create & return the new page object
     return AssetFactory::get($file_path);
 }
Exemple #5
0
 function __construct($get)
 {
     # sometimes when PHP release a new version, they do silly things - this
     # function is here to fix them
     $this->php_fixes();
     # it's easier to handle some redirection through php rather than relying on
     # a more complex .htaccess file to do all the work
     if ($this->handle_redirects()) {
         return;
     }
     # strip any leading or trailing slashes from the passed url
     $key = preg_replace(array('/\\/$/', '/^\\//'), '', key($get));
     # store file path for this current page
     $this->route = isset($key) ? $key : 'index';
     $file_path = Helpers::url_to_file_path($this->route);
     try {
         # create and render the current page
         $this->create_page($file_path);
     } catch (Exception $e) {
         if ($e->getMessage() == "404") {
             # return 404 headers
             header('HTTP/1.0 404 Not Found');
             if (file_exists('./content/404')) {
                 $this->create_page('./content/404', '404');
             } else {
                 if (file_exists('./public/404.html')) {
                     echo file_get_contents('./public/404.html');
                 } else {
                     echo '<h1>404</h1><h2>Page could not be found.</h2><p>Unfortunately, the page you were looking for does not exist here.</p>';
                 }
             }
         } else {
             echo '<h3>' . $e->getMessage() . '</h3>';
         }
     }
 }
Exemple #6
0
 function __construct($get)
 {
     # sometimes when PHP release a new version, they do silly things - this function is here to fix them
     $this->php_fixes();
     # it's easier to handle some redirection through php rather than relying on a more complex .htaccess file to do all the work
     if ($this->handle_redirects()) {
         return;
     }
     # strip any leading or trailing slashes from the passed url
     $key = key($get);
     # if the key isn't a URL path, then ignore it
     if (!preg_match('/\\//', $key)) {
         $key = false;
     }
     $key = preg_replace(array('/\\/$/', '/^\\//'), '', $key);
     # store file path for this current page
     $this->route = isset($key) ? $key : 'index';
     # TODO: Relative root path is set incorrectly (missing an extra ../)
     # strip any trailing extensions from the url
     $this->route = preg_replace('/[\\.][\\w\\d]+?$/', '', $this->route);
     $file_path = Helpers::url_to_file_path($this->route);
     try {
         # create and render the current page
         $this->create_page($file_path);
     } catch (Exception $e) {
         if ($e->getMessage() == "404") {
             # return 404 headers
             header('HTTP/1.0 404 Not Found');
             if (file_exists(Config::$content_folder . '/404')) {
                 $this->route = '404';
                 $this->create_page(Config::$content_folder . '/404');
             } else {
                 if (file_exists(Config::$root_folder . 'public/404.html')) {
                     echo file_get_contents(Config::$root_folder . 'public/404.html');
                 } else {
                     echo '<h1>404</h1><h2>Page could not be found.</h2><p>Unfortunately, the page you were looking for does not exist here.</p>';
                 }
             }
         } else {
             echo '<h3>' . $e->getMessage() . '</h3>';
         }
     }
 }