function collate_files($dir) { $files_modified = ''; foreach (Helpers::list_files($dir, '/.*/', false) as $file) { $files_modified .= $file . ':' . filemtime($file); if (is_dir($file)) { $files_modified .= $this->collate_files($file); } } return $files_modified; }
function template_name() { $txts = array_keys(Helpers::list_files($this->file_path, '/\\.txt$/')); # return first matched .txt file return !empty($txts) ? preg_replace('/\\.txt$/', '', $txts[0]) : false; }
static function site_last_modified($dir = false) { if (!$dir) { $dir = Config::$content_folder; } $last_updated = 0; foreach (Helpers::list_files($dir, '/.*/', false) as $file) { if (filemtime($file) > $last_updated) { $last_updated = filemtime($file); } if (is_dir($file)) { $child_updated = self::site_last_modified($file); if ($child_updated > $last_updated) { $last_updated = $child_updated; } } } return $last_updated; }
static function create_asset_collections($page) { # page.files $page->files = Helpers::list_files($page->file_path, '/(?<!thumb|_lge|_sml)\\.(?!yml)([\\w\\d]+?)$/i', false); # page.images $page->images = Helpers::list_files($page->file_path, '/(?<!thumb|_lge|_sml)\\.(gif|jpg|png|jpeg)$/i', false); # page.numbered_images $page->numbered_images = Helpers::list_files($page->file_path, '/^\\d+[^\\/]*(?<!thumb|_lge|_sml)\\.(gif|jpg|png|jpeg)$/i', false); # page.video $page->video = Helpers::list_files($page->file_path, '/\\.(mov|mp4|m4v)$/i', false); # page.swf, page.html, page.doc, page.pdf, page.mp3, etc. # create a variable for each file type included within the page's folder (excluding .yml files) $assets = self::get_file_types($page->file_path); foreach ($assets as $asset_type => $asset_files) { $page->{$asset_type} = $asset_files; } }
static function create_asset_collections($page) { # page.files $page->files = Helpers::list_files($page->file_path, '/(?<!thumb|_lge|_sml)\\.(?!yml)([\\w\\d]+?)$/i', false); # page.images $page->images = Helpers::list_files($page->file_path, '/(?<!thumb|_lge|_sml)\\.(gif|jpg|png|jpeg)$/i', false); # page.numbered_images $page->numbered_images = Helpers::list_files($page->file_path, '/^\\d+[^\\/]*(?<!thumb|_lge|_sml)\\.(gif|jpg|png|jpeg)$/i', false); # page.video $page->video = Helpers::list_files($page->file_path, '/\\.(mov|mp4|m4v)$/i', false); # page.txt $page->txt = Helpers::list_files($page->file_path, '/\\.(txt)$/i', false); # Save each txt file as page variable foreach ($page->data['txt'] as $filename => $file_path) { $var_name = preg_replace('/\\.(txt)/', '', $filename); if (is_readable($file_path)) { ob_start(); include $file_path; $content = ob_get_contents(); ob_end_clean(); $relative_path = preg_replace('/^\\.\\//', Helpers::relative_root_path(), $page->file_path); # replace the only var in your content - page.path for your inline html with images and stuff if (is_string($content)) { $content = preg_replace('/{{\\s*path\\s*}}/', $relative_path . '/', $content); } $page->{$var_name} = Markdown($content); } else { $page->{$var_name} = ''; } } # page.swf, page.html, page.doc, page.pdf, page.mp3, etc. # create a variable for each file type included within the page's folder (excluding .yml files) $assets = self::get_file_types($page->file_path); foreach ($assets as $asset_type => $asset_files) { $page->{$asset_type} = $asset_files; } }
static function template_name($file_path) { $txts = array_keys(Helpers::list_files($file_path, '/\\.(yml)/')); # return first matched .yml file return !empty($txts) ? preg_replace('/\\.(yml)/', '', $txts[0]) : false; }
static function create_asset_collections($page) { # $images $page->images = Helpers::list_files($page->file_path, '/(?<!thumb|_lge|_sml)\\.(gif|jpg|png|jpeg)$/i', false); # $video $page->video = Helpers::list_files($page->file_path, '/\\.(mov|mp4|m4v)$/i', false); # $swf, $html, $doc, $pdf, $mp3, etc. # create a variable for each file type included within the page's folder (excluding .txt files) $assets = self::get_file_types($page->file_path); foreach ($assets as $asset_type => $asset_files) { eval('$page->' . $asset_type . '=$asset_files;'); } # create asset collections (any assets within a folder beginning with an underscore) $asset_collections = self::get_asset_collections($page->file_path); foreach ($asset_collections as $collection_name => $collection_files) { eval('$page->' . $collection_name . '=$collection_files;'); } }
static function template_name($file_path) { $txts = array_keys(Helpers::list_files($file_path, '/\\.txt$/')); # return first matched .txt file return !empty($txts) ? preg_replace('/([^.]*\\.)?([^.]*)\\.txt$/', '\\2', $txts[0]) : false; }
static function template_name($file_path) { $txts = array_keys(Helpers::list_files($file_path, '/\.(txt|css|md)$/')); # return first matched .txt,.md, or .css file return (!empty($txts)) ? preg_replace('/\.(txt|css|md)$/', '', $txts[0]) : false; }
static function parse_loop($page, $dir, $loop_html) { $files = Helpers::list_files($dir, '/^\\d+?\\./', true); $html = ''; foreach ($files as $key => $file) { // if file is not a category and is not the index page, add it to the pages list if (!preg_match('/index/', $file) && !Helpers::is_category($file, $dir)) { $file_name_clean = preg_replace('/^\\d+?\\./', '', $file); // store the url and name of the navigation item $replacements = array('/@url/' => $page->link_path . $file_name_clean . '/', '/@name/' => ucfirst(preg_replace('/-/', ' ', $file_name_clean))); $html .= preg_replace(array_keys($replacements), array_values($replacements), $loop_html); } } return $html; }
static function last_modified($dir) { $last_modified = 0; if (is_dir($dir)) { foreach (Helpers::list_files($dir, '/.*/', false) as $file) { if (!is_dir($file)) { $last_modified = filemtime($file) > $last_modified ? filemtime($file) : $last_modified; } } } return $last_modified; }