Commits

Adam Dutko committed 6e325c1

Initial commit.

Comments (0)

Files changed (7)

+entries/2*
+blog.conf
+entries/active.conf
+You should really add pagination instead of a scrollbar.

blog.conf.template

+<?php
+/* The base location of entries. */
+$BASE="/www/php/blog/entries/"
+?>
+/* This is the basic format of a blog entry: */
+
+[author]
+value = "Adam"
+
+[content]
+value = "I've started constructing a site for my new company. Thank you for visiting and I do hope you will enjoy the products RunByMany, Inc will be creating for you! Please use the <a href='#' onclick='contact();'>contact form</a> if you want to get in touch."
+
+[date]
+value = "2011/08/21"
+
+[email]
+value = "adam@foobar.com"
+
+[publish]
+value = 1

entries/active.conf.template

+<?php
+/* List all active directories here. */
+$DIRS="2013";
+?>
+<?php
+
+class Entry
+{
+    public $author;
+    public $content;
+    public $date;
+    public $email;
+    public $publish;
+
+    function __construct(
+        $author = "adam",
+        $content = "I'm sorry but you need to know the question first.",
+        $date = "19700101",
+        $email = "adam@foobar.com",
+        $publish = 0,
+        $title = "Not sure.")
+    {
+        $this->author = $author;
+        $this->content = $content;
+        $this->date = $date;
+        $this->email = $email;
+        $this->publish = $publish;
+        $this->title = $title;
+    }
+
+    function __destruct()
+    {
+    }
+
+    function __toString()
+    {
+        return "
+            <div class=\"entry\">
+                <p class=\"date\">$this->date</p>
+                <p class=\"byline\">$this->title by <a href=\"mailto:$this->email\">$this->author</a></p>
+                <p class=\"post\">$this->content</p> 
+            </div>
+        "; 
+    }
+
+    function setAuthor($author)
+    {
+        $this->author = $author;
+    }
+
+    function getAuthor()
+    {
+        return $this->author;
+    }
+
+    function setContent($content)
+    {
+        $this->content = $content;
+    }
+
+    function getContent()
+    {
+        return $this->content;
+    }
+
+    function setDate($date)
+    {
+        $this->date = $date;
+    }
+
+    function getDate()
+    {
+        return $this->date;
+    }
+
+    function setEmail($email)
+    {
+        $this->email = $email;
+    }
+  
+    function getEmail()
+    {
+        return $this->email;
+    }
+
+    function setPublish($publish)
+    {
+        $this->publish = $publish;
+    } 
+    
+    function getPublish()
+    {
+        return $this->publish;
+    }
+
+    function setTitle($title)
+    {
+        $this->title = $title;
+    }
+
+    function getTitle($title)
+    {
+        return $this->title;
+    }
+}
+
+?>
+<?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>";
+}
+
+?>
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.