예제 #1
0
 static function create_textfile_vars($page, $content = false)
 {
     # store contents of content file (if it exists, otherwise, pass back an empty string)
     if ($content) {
         $vars = sfYaml::load($content);
     } else {
         $content_file = sprintf('%s/%s', $page->file_path, $page->template_name);
         $content_file_path = file_exists($content_file . '.yml') ? $content_file . '.yml' : $content_file . '.txt';
         if (!file_exists($content_file_path)) {
             return;
         }
         # Correct formatting of fenced content
         $content = file_get_contents($content_file_path);
         $content = self::preparse_text($content);
         $vars = sfYaml::load($content);
     }
     # include shared variables for each page
     $vars = array_merge(self::get_shared_data(), $vars ? $vars : array());
     if (empty($vars)) {
         return;
     }
     global $current_page_template_file;
     if (!$current_page_template_file) {
         $current_page_template_file = $page->template_file;
     }
     $markdown_compatible = preg_match('/\\.(xml|html?|rss|rdf|atom|js|json)$/', $current_page_template_file);
     $relative_path = preg_replace('/^\\.\\//', Helpers::relative_root_path(), $page->file_path);
     $vars = self::parse_vars($vars, $markdown_compatible, $relative_path);
     foreach ($vars as $key => $value) {
         # set a variable with a name of 'key' on the page with a value of 'value'
         $page->{$key} = $value;
     }
 }
예제 #2
0
 static function create_textfile_vars($page)
 {
     # store contents of content file (if it exists, otherwise, pass back an empty string)
     $content_file_path = $page->file_path . '/' . $page->template_name . '.txt';
     $text = file_exists($content_file_path) ? file_get_contents($content_file_path) : '';
     # include shared variables for each page
     $shared = file_exists('./content/_shared.txt') ? file_get_contents('./content/_shared.txt') : '';
     # strip any $n matches from the text, as this will mess with any preg_replaces
     # they get put back in after the template has finished being parsed
     $text = preg_replace('/\\$(\\d+)/', "\$1", $text);
     # remove UTF-8 BOM and marker character in input, if present
     $merged_text = preg_replace('/^\\xEF\\xBB\\xBF|\\x1A/', '', array($shared, $text));
     # merge shared content into text
     $shared = preg_replace('/\\n\\s*?-\\s*?\\n?$/', '', $merged_text[0]);
     $content = preg_replace('/\\n\\s*?-\\s*?\\n?$/', '', $merged_text[1]);
     $text = $shared . "\n-\n" . $content;
     # standardize line endings
     $text = preg_replace('/\\r\\n?/', "\n", $text);
     # pull out each key/value pair from the content file
     $matches = preg_split("/\n\\s*?-\\s*?\n/", $text);
     foreach ($matches as $match) {
         # split the string by the first colon
         $colon_split = explode(':', $match, 2);
         # replace the only var in your content - @path for your inline html with images and stuff
         $relative_path = preg_replace('/^\\.\\//', Helpers::relative_root_path(), $page->file_path);
         $colon_split[1] = preg_replace('/\\@path/', $relative_path . '/', $colon_split[1]);
         # get template file type as $split_path[1]
         global $current_page_template_file;
         if (!$current_page_template_file) {
             $current_page_template_file = $page->template_file;
         }
         preg_match('/\\.([\\w\\d]+?)$/', $current_page_template_file, $split_path);
         # set a variable with a name of 'key' on the page with a value of 'value'
         # if the template type is xml or html & the 'value' contains a newline character, parse it as markdown
         if (strpos($colon_split[1], "\n") !== false && preg_match('/xml|htm|html|rss|rdf|atom/', $split_path[1])) {
             $page->{$colon_split}[0] = Markdown(trim($colon_split[1]));
         } else {
             $page->{$colon_split}[0] = trim($colon_split[1]);
         }
     }
 }
예제 #3
0
 static function create_textfile_vars($page)
 {
     # store contents of content file (if it exists, otherwise, pass back an empty string)
     $content_file_path = $page->file_path . '/' . $page->template_name . '.txt';
     $text = file_exists($content_file_path) ? file_get_contents($content_file_path) : '';
     # include shared variables for each page
     $shared = file_exists('./content/_shared.txt') ? file_get_contents('./content/_shared.txt') : '';
     # remove UTF-8 BOM and marker character in input, if present
     $merged_text = preg_replace('/^\\xEF\\xBB\\xBF|\\x1A/', '', array($shared, $text));
     # merge shared content into text
     $text = "\n" . $merged_text[0] . "\n-\n" . $merged_text[1] . "\n-\n";
     # standardize line endings
     $text = preg_replace('/\\r\\n?/', "\n", $text);
     # pull out each key/value pair from the content file
     preg_match_all('/(?<=\\n)([a-z\\d_\\-]+?:[\\S\\s]*?)\\n\\s*?-\\s*?\\n/', $text, $matches);
     foreach ($matches[1] as $match) {
         # split the string by the first colon
         $colon_split = explode(':', $match, 2);
         # replace the only var in your content - @path for your inline html with images and stuff
         $relative_path = preg_replace('/^\\.\\//', Helpers::relative_root_path(), $page->file_path);
         $colon_split[1] = preg_replace('/\\@path/', $relative_path . '/', $colon_split[1]);
         # set a variable with a name of 'key' on the page with a value of 'value'
         $page->{$colon_split}[0] = strpos($colon_split[1], "\n") === false ? trim($colon_split[1]) : Markdown(trim($colon_split[1]));
     }
 }
예제 #4
0
 function construct_link_path($file_path)
 {
     return preg_replace('/^\\.\\//', Helpers::relative_root_path(), $file_path);
 }
예제 #5
0
 static function create_vars($page)
 {
     # @url
     $page->url = Helpers::relative_root_path() . $page->url_path . '/';
     # @permalink
     $page->permalink = $page->url_path;
     # @slug
     $split_url = explode("/", $page->url_path);
     $page->slug = $split_url[count($split_url) - 1];
     # @page_name
     $page->page_name = ucfirst(preg_replace('/[-_](.)/e', "' '.strtoupper('\\1')", $page->data['@slug']));
     # @root_path
     $page->root_path = Helpers::relative_root_path();
     # @thumb
     $page->thumb = self::get_thumbnail($page->file_path);
     # @current_year
     $page->current_year = date('Y');
     # @stacey_version
     $page->stacey_version = Stacey::$version;
     # @domain_name
     $page->domain_name = $_SERVER['HTTP_HOST'];
     # @base_url
     $page->base_url = $_SERVER['HTTP_HOST'] . str_replace('/index.php', '', $_SERVER['PHP_SELF']);
     # @site_updated
     $page->site_updated = strval(date('c'));
     # @updated
     $page->updated = strval(date('c', Helpers::last_modified($page->file_path)));
     # @is_current_page
     $page->is_current_page = self::is_current_page($page->data['@base_url'], $page->data['@permalink']);
     # @siblings_count
     $page->siblings_count = strval(count($page->data['$siblings']));
     # @index
     $page->index = self::get_index($page->data['$siblings'], $page->file_path);
 }
예제 #6
0
 static function create_textfile_vars($page, $content = false)
 {
     # store contents of content file (if it exists, otherwise, pass back an empty string)
     if ($content) {
         $vars = sfYaml::load($content);
     } else {
         $content_file = sprintf('%s/%s', $page->file_path, $page->template_name);
         $content_file_path = file_exists($content_file . '.yml') ? $content_file . '.yml' : $content_file . '.txt';
         if (!file_exists($content_file_path)) {
             return;
         }
         $vars = sfYaml::load($content_file_path);
     }
     # include shared variables for each page
     $vars = array_merge(self::get_shared_data(), $vars ? $vars : array());
     if (empty($vars)) {
         return;
     }
     global $current_page_template_file;
     if (!$current_page_template_file) {
         $current_page_template_file = $page->template_file;
     }
     $markdown_compatible = preg_match('/\\.(xml|html?|rss|rdf|atom)$/', $current_page_template_file);
     $relative_path = preg_replace('/^\\.\\//', Helpers::relative_root_path(), $page->file_path);
     foreach ($vars as $key => $value) {
         # replace the only var in your content - page.path for your inline html with images and stuff
         if (is_string($value)) {
             $value = preg_replace('/{{\\s*path\\s*}}/', $relative_path . '/', $value);
         }
         # set a variable with a name of 'key' on the page with a value of 'value'
         # if the template type is xml or html & the 'value' contains a newline character, parse it as markdown
         if (!is_string($value)) {
             $page->{$key} = $value;
         } else {
             if ($markdown_compatible && strpos($value, "\n") !== false) {
                 $page->{$key} = Markdown(trim($value));
             } else {
                 $page->{$key} = trim($value);
             }
         }
     }
 }