getFilename(); $b_value = $b->getFilename(); return strcmp($b_value, $a_value); // Reversed to get descending } if ( $is_post ) { // Single post page $post_name = filter_var($_GET['post'], FILTER_SANITIZE_NUMBER_INT); $file_path = __DIR__.'/content/'.$post_name.'.'.FILE_EXT; if ( file_exists($file_path) ) { $file = fopen($file_path, 'r'); $post_title = trim(fgets($file),'#'); fclose($file); // Process the Markdown $parsedown = new Parsedown(); $content = $parsedown->text(file_get_contents($file_path)); } else { $content = '

Not Found

Sorry, couldn\'t find a post with that name. Please try again, or go to the home page to select a different post.

'; } } else { // Blog main page - list all posts $files = new DirectoryIterator(__DIR__.'/content/'); $files_array = []; foreach ($files as $file) { if ( $file->isFile() && $file->getExtension() == FILE_EXT ) { array_push($files_array, $file->getFileInfo()); } } usort($files_array, 'sortPosts'); // See sortPosts() function above foreach ($files_array as $file) { $filename_no_ext = $file->getBasename('.'.FILE_EXT); $file_pointer = $file->openFile(); $post_title = trim($file_pointer->fgets(),'#'); $content .= '

'.$post_title.' '.$filename_no_ext.'

'; } } // Appending file hashes to the hrefs allows us to cache the files indefinitely, // but immediately serve a new version once the file changes. $style_hash = hash('md5', file_get_contents(__DIR__.'/src/css/style-'.APPEARANCE.'.css')); $fonts_hash = hash('md5', file_get_contents(__DIR__.'/src/css/fonts.css')); $icon_hash = hash('md5', file_get_contents(__DIR__.'/img/favicon.png')); ?> <?php if ( !empty($_GET['post']) ) { echo $post_title.' - '; } ?><?php echo BLOG_TITLE; ?>

Blurbs

'.$content.''; ?>