Source

simpleblog / render.php

Full commit
<?php
/* Read our configuration file to determine which directories to look for 
   entries. Then after we find the directories, grab all *.entry files, parse 
   them and render a complete chronologically ordered list. Once done, return
   it to the list.
*/

// Configuration
require('blog.conf');
require('entries/active.conf');
// Useful Objects
require('pieces/Entry.php');

// Debug on or off?
$DEBUG = "";

$activeLocations = split(",",$DIRS);
if (!empty($DEBUG))
{
    print_r($activeLocations);
}

$entries = array();

foreach($activeLocations as $activeDir)
{
    // Let's qualify the directory first ...
    $activePath = $BASE . $activeDir;

    // Is it really a directory?
    if (!is_dir($activePath))
    {  
        if (!empty($DEBUG))
        {
            print_r("NOTE: Found an empty directory --> " . $activePath);
        }
        continue;
    }

    // Quick check if the directory is empty and if it is, next!
    // THANKS: http://minimalite.com/2010/02/php/is-directory-empty-in-php/
    if (($files = scandir($activePath)) && (count($files) <= 2))
    {
        continue;
    }

    // Add files with .entry extension to the "to parse list" 
    if ($handle = opendir($activePath))
    {
        while (false !== ($file = readdir($handle)))
        {
            if ($file != "." && $file != "..")
            {
                $info = pathinfo($file); 
                if ($info['extension'] == "entry")
                {
                    array_push($entries, $activePath . '/' . $file);
                }
            }
        }
        closedir($handle);
    } 
}

// Now let's parse and create an instance of our entries so we can publish
// them if the entry is set to be published

$blogRoll = "";

// They're all ini files
$count = 0;
foreach($entries as $entry)
{
    $extractedEntry = parse_ini_file($entry, true);
    if ($extractedEntry["publish"]["value"] == 1)
    {
        $count += 1;
        $entryObject = new Entry(
            $extractedEntry["author"]["value"],
            $extractedEntry["content"]["value"],
            $extractedEntry["date"]["value"],
            $extractedEntry["email"]["value"],
            $extractedEntry["publish"]["value"],
            $extractedEntry["title"]["value"]);
        echo $entryObject;
    }
}

if ($count == 0)
{
    echo "<div class=\"entry\">No entries posted yet.</div>";
}

?>