Example #1
0
<?php

require_once 'lib/jebson.php';
Jebson::init();
Example #2
0
 /**
  * Gets requested post filenames
  * @param int $page Page number.  Defaults to 1
  * @param string $order 'desc' or 'asc'. Defaults to 'desc'
  * @return array
  */
 public static function getPosts($page = false, $order = 'desc')
 {
     if ($handle = opendir(Config::$contentDirectory)) {
         $allPosts = array();
         // First create a list of available posts
         while (false !== ($entry = readdir($handle))) {
             if (substr($entry, 0, 1) != '.' && is_numeric(substr(str_replace('-', '', $entry), 0, 7))) {
                 $allPosts[] = $entry;
             }
         }
         closedir($handle);
         if ($order == 'desc') {
             rsort($allPosts);
         } else {
             asort($allPosts);
         }
         // Calculate total number of post pages and set instance var
         self::$totalPosts = count($allPosts);
         self::$totalPages = ceil(self::$totalPosts / Config::$postsPerPage);
         // Now pull out the posts we want to return
         $postCount = 0;
         $returnPosts = array();
         foreach ($allPosts as $post) {
             $postCount++;
             if (is_numeric($page)) {
                 if ($page == 1) {
                     $start = $page;
                     $stop = $page + Config::$postsPerPage - 1;
                 } else {
                     $start = $page * Config::$postsPerPage - (Config::$postsPerPage - 1);
                     $stop = $page * Config::$postsPerPage;
                 }
                 if (in_array($postCount, range($start, $stop))) {
                     $returnPosts[] = $post;
                 }
             } elseif (!is_numeric($page)) {
                 $returnPosts[] = $post;
             }
         }
         return $returnPosts;
     } else {
         // Exception here.  Can't open self::$contentDirectory
     }
 }