Exemplo n.º 1
0
 public function archive($month)
 {
     if ($month != NULL) {
         // only cache public content
         if (!($isAuthenticated = Fari_User::isAuthenticated('realname'))) {
             $this->view->cache('/themes/' . BLOG_THEME . '/archive', 'text/html', $month);
         }
         $articles = Blog::getArchive($month, $isAuthenticated);
         if (empty($articles)) {
             $this->redirect('/error404');
         }
         $this->view->articles = $articles;
         $this->view->title = Fari_Format::titleize($month);
         $this->view->display('/themes/' . BLOG_THEME . '/archive', 'text/html', $month);
     } else {
         $this->redirect('/error404');
     }
 }
Exemplo n.º 2
0
 public function view($slug, $highlight)
 {
     $slug = Fari_Escape::text($slug);
     $result = Fari_Db::selectRow('kb', '*', array('slug' => $slug));
     if (empty($result)) {
         // text not found
         $this->redirect('/error404');
         die;
     }
     // highlight keywords in the text
     if (!empty($highlight)) {
         $highlight = explode('-', $highlight);
         $this->view->text = Fari_Format::highlight($result, $highlight, array('tags', 'source', 'category', 'comments', 'text', 'title'));
     } else {
         $this->view->text = $result;
     }
     $this->view->display('view');
 }
/**
 * Create a textual representation of a time in the past/future
 * @param <type> $timestamp
 */
function timeAgoInWords($timestamp)
{
    assert('is_int($timestamp); // you need to pass a timestamp');
    echo Fari_Format::age($timestamp);
}
Exemplo n.º 4
0
            echo $row['category'];
            ?>
</a> &middot;
                                <a href="<?php 
            $this->url('/browse/source/' . $row['sourceSlug']);
            ?>
">
                                    <?php 
            echo $row['source'];
            ?>
                            <?php 
        }
        ?>
                            </a> &middot;
                            <?php 
        echo Fari_Format::age($row['date']);
        ?>
 &middot;
                            <span class="small"><?php 
        echo $row['tags'];
        ?>
</span>
                        </div>
                        <div class="span-2"></div>
                    </div>
                <?php 
    }
} else {
    ?>
                    <div id="view"><p>Nothing to display.</p></div>
                <?php 
Exemplo n.º 5
0
"
                           ><?php 
echo $text['source'];
?>
</a>
                    </div>
                    <div class="span-5 last">
                        <label>Tags:</label><br />
                        <?php 
echo $text['tags'];
?>
                    </div>
                    <div class="span-5 last">
                        <label>Age:</label><br />
                        <?php 
echo Fari_Format::age($text['date']);
?>
                    </div>
                    <div class="span-5 last">
                        <label>Starred:</label><br />
                        <h3><a class="star <?php 
echo $text['starred'];
?>
"
                               href="<?php 
$this->url('/text/star/' . $text['slug']);
?>
">&nbsp;</a></h3>
                    </div>
                    <?php 
if (!empty($text['comments'])) {
Exemplo n.º 6
0
 /**
  * Get used up memory, formatted.
  *
  * @return string Usage of memory in b, kb, etc.
  */
 public static function getMemory()
 {
     return Fari_Format::bytes(memory_get_usage());
 }
Exemplo n.º 7
0
 /**
  * Builds and returns an RSS feed (check data on db insert!).
  *
  * @param string $feedTitle Title of the feed
  * @param string $feedURL Link to the feed
  * @param string $feedDescription Description of this feed
  * @param string $items Database table
  * @param boolean $isDateInRSS Set to TRUE if dates in tn the $items table are already in RSS format
  * @return string RSS Feed
  */
 public function create($feedTitle, $feedURL, $feedDescription, $items, $isDateInRSS = FALSE)
 {
     // escape input
     $feedTitle = Fari_Escape::XML($feedTitle);
     $feedURL = Fari_Escape::XML($feedURL);
     $feedDescription = Fari_Escape::XML($feedDescription);
     // set publishing date in RSS format
     $feedPublished = date(DATE_RSS);
     // start dom string
     $DOMDocument = new DOMDocument('1.0', 'UTF-8');
     // form columns, we will use the info when traversing articles (and on the line below)
     $columns = $this->articleTitle . ', ' . $this->articleLink . ', ' . $this->articleDescription . ', ' . $this->articleDate;
     // get items from the database if we are not passing a formed array already
     if (!is_array($items)) {
         $items = Fari_Db::select($items, $columns);
     }
     // <rss>
     $rootNode = $DOMDocument->createElement('rss');
     // use RSS version 2.0 attribute
     $rootNode->setAttribute('version', '2.0');
     $DOMDocument->appendChild($rootNode);
     // <rss><channel>
     $channel = $rootNode->appendChild($DOMDocument->createElement('channel'));
     // create the header
     // <rss><channel><title>
     $channel->appendChild($DOMDocument->createElement('title', $feedTitle));
     // <rss><channel><link>
     $channel->appendChild($DOMDocument->createElement('link', $feedURL));
     // <rss><channel><description>
     $channel->appendChild($DOMDocument->createElement('description', $feedDescription));
     // <rss><channel><pubDate>
     $channel->appendChild($DOMDocument->createElement('pubDate', $feedPublished));
     // column to RSS form 'conversion', elements have to follow that order...
     $articleColumns = explode(', ', $columns);
     $RSSColumns = array('title', 'link', 'description', 'pubDate');
     // traverse items now
     foreach ($items as $article) {
         // <rss><channel><item>
         $articleNode = $channel->appendChild($DOMDocument->createElement('item'));
         // traverse the items array consisting of 4 elements
         for ($i = 0; $i < 4; $i++) {
             // <rss><channel><item><$column>
             // <$column> value, escaped
             $columnText = Fari_Escape::XML($article[$articleColumns[$i]]);
             // do we need to fix RSS pubDate?
             if ($RSSColumns[$i] == 'pubDate' && !$isDateInRSS) {
                 $columnText = Fari_Format::date($columnText, 'RSS');
             }
             $articleNode->appendChild($DOMDocument->createElement($RSSColumns[$i], $columnText));
         }
     }
     // generate XML and return
     $DOMDocument->formatOutput = TRUE;
     return $DOMDocument->saveXML();
 }
Exemplo n.º 8
0
 /**
  * Determine file/directory statistics for input item.
  *
  * @param DirectoryIterator $item Item passed from a DirectoryIterator
  * @return array Listing with stats
  */
 private static function _getItemStats(DirectoryIterator $item)
 {
     $list = array();
     // add filename
     $list['name'] = (string) $item;
     // add directory/file type
     $list['type'] = $item->getType();
     // add modification time
     $list['modified'] = date('Y-m-d H:i:s', $item->getMTime());
     // get permissions
     $list['permissions'] = $item->getPerms();
     // is writable?
     $list['writable'] = $item->isWritable() ? 1 : 0;
     // add path
     $list['path'] = $item->getPathName();
     $list['real_path'] = $item->getRealPath();
     // add size
     $list['size'] = Fari_Format::bytes($item->getSize());
     return $list;
 }