Slashblog
[ class tree: Slashblog ] [ index: Slashblog ] [ all elements ]

Source for file post.class.php

Documentation is available at post.class.php

  1. <?php
  2. /**
  3.  * Contains definition of Post, subclass of DataContainer. Post is a container of DataItems but has some extended functionality such as outputting to various sources and in different formats, and adding customized items such as time, ID, title etc.
  4.  * 
  5.  * @todo Add functions to simplyfy post creation, such as AddTitle, AddContent etc.
  6.  * 
  7.  * @author Daniel Nordstrom <dnordstrom@mankindorganization.com>
  8.  * @link www.mrnordstrom.com
  9.  */
  10.  
  11.  
  12. /**
  13.  * Contains a post, composed of several data fields/items. Has extended functionality specific to it's purpose as a container of not just data, but data composing a blogpost.
  14.  */
  15. class Post extends DataContainer {
  16.     
  17.     /**
  18.       * Constructor, calls constructor of parent DataContainer.
  19.       **/
  20.  
  21.     function __construct()
  22.     {
  23.         parent::__construct();
  24.     }
  25.     
  26.     /**
  27.      * Sets an author of the post. If no author field yet exists, it creates one.
  28.      */
  29.     public function SetAuthor($value)
  30.     {
  31.         if(!(parent::EditItem("AUTHOR"$value))) // If we can't edit it, it doesn't exist, so we...
  32.             parent::AddItem("AUTHOR"$value)// ...add it as a new item.
  33.     }
  34.     
  35.     /**
  36.      * Sets the timestamp of the post. If no timestamp field yet exists, it creates one.
  37.      */
  38.     public function SetDate()
  39.     {
  40.         if(!(parent::EditItem("DATE"date("d/m/y g:i A")))) // If we can't edit it, it doesn't exist, so we...
  41.             parent::AddItem("DATE"date("d/m/y g:i A"))// ...add it as a new item.
  42.     }
  43.     
  44.     /**
  45.      * Sets content of the post. If no content field yet exists, it creates one.
  46.      */
  47.     public function SetContent($value)
  48.     {
  49.         if(!(parent::EditItem("CONTENT"$value))) // If we can't edit it, it doesn't exist, so we...
  50.             parent::AddItem("CONTENT"$value)// ...add it as a new item.
  51.     }
  52.     
  53.     /**
  54.      * Sets tags of the post. If no tag field yet exists, it creates one.
  55.      */
  56.     public function SetTags($value)
  57.     {
  58.         if(!(parent::EditItem("TAGS"$value))) // If we can't edit it, it doesn't exist, so we...
  59.             parent::AddItem("TAGS"$value)// ...add it as a new item.
  60.     }
  61.     
  62.     /**
  63.      * Sets title of the post. If no title field yet exists, it creates one.
  64.      */
  65.     public function SetTitle($value)
  66.     {
  67.         if(!(parent::EditItem("TITLE"$value))) // If we can't edit it, it doesn't exist, so we...
  68.             parent::AddItem("TITLE"$value)// ...add it as a new item.
  69.     }
  70.     
  71.     /**
  72.      * Gets post author.
  73.      * 
  74.      * @return string $author Author of post.
  75.      */
  76.     public function GetAuthor()
  77.     {
  78.         return parent::GetValue("AUTHOR")// Return post author.
  79.     }
  80.  
  81.     /**
  82.      * Gets post title.
  83.      * 
  84.      * @return string $title Title of post.
  85.      */
  86.     public function GetTitle()
  87.     {
  88.         return parent::GetValue("TITLE")// Return post title.
  89.     }
  90.     
  91.     /**
  92.      * Gets post content.
  93.      * 
  94.      * @return string $content Content of post.
  95.      */
  96.     public function GetContent()
  97.     {
  98.         return parent::GetValue("CONTENT")// Return post content.
  99.     }
  100.     
  101.     /**
  102.      * Gets post tags.
  103.      * 
  104.      * @return string $tags Tags of post.
  105.      */
  106.     public function GetTags()
  107.     {
  108.         return parent::GetValue("TAGS")// Return post tags.
  109.     }
  110.     
  111.     /**
  112.      * Gets post date.
  113.      * 
  114.      * @return string $date Date of post.
  115.      */
  116.     public function GetDate()
  117.     {
  118.         return parent::GetValue("DATE")// Return post author.
  119.     }
  120.     
  121.     /**
  122.      * Gets post ID.
  123.      * 
  124.      * @return integer $id ID of post.
  125.      */
  126.     public function GetID()
  127.     {
  128.         return parent::GetValue("ID")// Return post author.
  129.     }
  130.     
  131.     /**
  132.      * Prints out post data text in our own format.
  133.      * 
  134.      * @param handle $handle File handle to use for writing.
  135.      */
  136.     public function AsText(
  137.     {
  138.         $string "STARTPOST" PHP_EOL;
  139.         foreach $this->items as $item )
  140.             $string .= $item->GetKey(PHP_EOL $item->GetValue(PHP_EOL;
  141.         $string .= "ENDPOST" PHP_EOL;
  142.         
  143.         return $string;
  144.     }
  145.     
  146.     /**
  147.      * Prints out post data as XML.
  148.      */
  149.     public function AsXML(
  150.     {
  151.         $string "<POST>" PHP_EOL;
  152.         foreach $this->items as $item // Append all items to XML string
  153.             $string .= "<" $item->GetKey(">" htmlentities($item->GetValue()) "</" $item->GetKey(">" PHP_EOL;
  154.         $string .= '</POST>' PHP_EOL;
  155.  
  156.         return $string;
  157.     }
  158.     
  159.     /**
  160.      * Prints out all items in container.
  161.      */
  162.     public function DumpToOutput(
  163.     {
  164.         foreach $this->items as $item )
  165.             print '[' $item->GetKey ('] => "' $item->GetValue ('";' PHP_EOL;
  166.     }
  167. }
  168.  
  169. ?>

Documentation generated on Mon, 26 May 2008 19:59:42 +0100 by phpDocumentor 1.4.0