Source for file CMS3_StandartOutputHandler.php

Documentation is available at CMS3_StandartOutputHandler.php

  1. <?php     
  2. //          (F)
  3. // CMS3 - A Three Content Management System.
  4. // Copyright (C) 2007  Jop... (Jonas F. Jensen).
  5. // 
  6. // This program is free software; you can redistribute it and/or
  7. // modify it under the terms of the GNU General Public License
  8. // as published by the Free Software Foundation; either version 2
  9. // of the License, or (at your option) any later version.
  10. // 
  11. // This program is distributed in the hope that it will be useful,
  12. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. // GNU General Public License for more details.
  15. //
  16. // You should have received a copy of the GNU General Public License
  17. // along with this program; if not, write to the Free Software
  18. // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
  19.  
  20. /**
  21. *This file defines CMS3_StandartOutputHandler
  22. *
  23. @package    StandartOutputHandler
  24. @author    Jonas F. Jensen <jopsen@gmail.com>
  25. @copyright    2007 Jonas F. Jensen.
  26. @license    http://www.gnu.org/licenses/gpl.txt
  27. */
  28.  
  29. /**
  30.  * class CMS3_StandartOutputHandler, a very simple OutputHandler; no configuration available only static template and sitemap.
  31.  */
  32. {
  33.  
  34.     /** Aggregations: */
  35.  
  36.     /** Compositions: */
  37.  
  38.      /*** Attributes: ***/
  39.  
  40.     protected $IsDisabled = false;
  41.     protected $Body = "";
  42.     protected $BodyList = null;
  43.     protected $Header = "";
  44.     protected $Title = "Untitled";
  45.     protected $Owner = null;
  46.     protected $Identifier = "";
  47.  
  48.     /**
  49.     *Sets the complete unique identifier.
  50.     *
  51.     *@param string Idenfitifer Complete unique identifier.
  52.     *@access public
  53.     */
  54.     public function SetIdentifier($Identifier ""){
  55.         $this->Identifier = $Identifier;
  56.     }
  57.  
  58.     /**
  59.      *
  60.      * @param CMS3_System Owner The CMS3_System that owns this plugin, gives the plugin ability to get data from
  61. CMS3_System
  62.  
  63.      * @return 
  64.      * @access public
  65.      */
  66.     public function Register(&$Owner )
  67.     {
  68.         //Just save a handle for now
  69.         $this->Owner =$Owner;
  70.     }
  71.  
  72.     /**
  73.      * Gets the pluginID of the plugin.
  74.      *
  75.      * @return string 
  76.      * @access public
  77.      */
  78.     public function GetPluginID){
  79.         return "StandartOutputHandler";
  80.     }
  81.  
  82.     /**
  83.      * Data provided by use of this method may be left out if the OutputHandler wishes
  84.      * to print something else the HTML, therefor don't add important information
  85.      * here.
  86.      *
  87.      * @param string line A line you wish to add to the header.
  88.  
  89.      * @access public
  90.      */
  91.     public function ExtentHeader$line )
  92.     {
  93.         $this->Header .= $line;
  94.     }
  95.  
  96.  
  97.     /**
  98.      *
  99.      * @param string title
  100.      * @access public
  101.      */
  102.     public function SetTitle$title {
  103.         $this->Title = $title;
  104.     // end of member function SetTitle
  105.  
  106.     
  107.     /**
  108.      * Set the body if the page, read parameter documentation.
  109.      *
  110.      * Embedments may be included in the body, they shall be formatted as follows: [[EMBED|<identifier>|EMBED]], where <identifier> is the identifier returned from the IEmbedable.
  111.      * 
  112.      * @param string body Body of the page, or description of a channel.
  113.  
  114.      * @param array List Parse a list, use this feature if you wish to parse a list. This will also
  115.      *  enable to OutputHandler to print a feed. This parameter is optional, if set the
  116.      *  first parameter will define the description of the channel, and every body and
  117.      *  title in this array will define an entry.
  118.      *  Array layout:
  119.      *  [body,body,...]
  120.      *  or
  121.      *  [[title,body],[title,body],...]
  122.  
  123.      * @return 
  124.      * @access public
  125.      */
  126.     public function SetBody$body,  $List null {
  127.         $this->Body = $body;
  128.         $this->BodyList = $List;
  129.     // end of member function SetBody
  130.  
  131.     
  132.     /**
  133.      * Print the content, should also be called from GetPage().
  134.      *
  135.      * @access public
  136.      */
  137.     public function Parse({
  138.         if(!$this->IsDisabled){
  139.             $Content $this->GetContent()// Get the content first, since embedments and header extensions from embedments are parsed here as well.
  140.  
  141.             //Generating sitemap from Ilinkable
  142.             $iLinks $this->Owner->GetImplementations("ILinkable");
  143.             $SiteMap "";
  144.             foreach($iLinks as $iLink)
  145.             {
  146.                 foreach($iLink->GetLinks(as $LinkEntry)
  147.                 {
  148.                     $SiteMap .= $this->ParseLinkEntry($LinkEntry);
  149.                 }
  150.             }
  151.  
  152.  
  153.             $Template file_get_contents($this->Owner->GetCMS3Path("data/" $this->GetPluginID("/template.htm");
  154.             $Template str_replace("CMS3URL"$this->Owner->GetCMS3URL(,$Template);
  155.             $Template str_replace("<!--TITLE-->",$this->Title ,$Template);
  156.             $Template str_replace("<!--SITEMAP-->",$SiteMap ,$Template);
  157.             $Template str_replace("<!--HEADEREXT-->",$this->GetHeader(,$Template);
  158.             $Template str_replace("<!--CONTENT-->",$Content ,$Template);
  159.  
  160.             print $Template;
  161.             $this->Disable();
  162.         }
  163.     // end of member function Parse
  164.  
  165.  
  166.     
  167.     protected function ParseLinkEntry($Entry)
  168.     {
  169.         $Text "<a href=\"" $Entry[1"\">" $Entry[0"</a><br />\n";
  170.         $IsFirst true;
  171.         if($Entry[2!= null){
  172.             foreach($Entry[2as $SubEntry)
  173.             {
  174.                 //Do only add this one time
  175.                 if($IsFirst)
  176.                 {
  177.                     $Text .= "<blockquote>\n";
  178.                     $IsFirst false;
  179.                 }
  180.                 $Text .= $this->ParseLinkEntry($SubEntry);
  181.             }
  182.         }
  183.         //Do only add this if there were any subentries
  184.         if(!$IsFirst)
  185.             $Text .= "</blockquote>";
  186.  
  187.         return $Text;
  188.     }
  189.  
  190.  
  191.     /**
  192.     *Gets content ready to be printed
  193.     *
  194.     *This does not include header, only the body content.
  195.     *
  196.     *@return string Content ready for print
  197.     */
  198.     public function GetContent(){
  199.         $Content "<p>" $this->ParseEmbedments($this->Body"</p>";
  200.         if(is_array($this->BodyList)){
  201.             foreach($this->BodyList as $key => $value){
  202.                 if(is_array($value)){
  203.                     $Content .= "<h2>" $this->ParseEmbedments($value[0]"</h2>";
  204.                     $Content .= "<p>" $this->ParseEmbedments($value[1]"</p>";
  205.                 }else{
  206.                     $Content .= "<p>" $this->ParseEmbedments($value"</p>";
  207.                 }
  208.             }
  209.         }
  210.         return $Content;
  211.     }
  212.  
  213.     /**
  214.     *Gets the header extension
  215.     *
  216.     *@return string Lines to be added to the header
  217.     */
  218.     public function GetHeader(){
  219.         return $this->Header;
  220.     }
  221.  
  222.  
  223.     /**
  224.      * Diable the OutputHandler, do this if you wish to print binary data.
  225.      *
  226.      * @return 
  227.      * @access public
  228.      */
  229.     public function Disable){
  230.         $this->IsDisabled = true;
  231.     }
  232.     // end of member function Disable
  233.  
  234.     
  235.     /**
  236.      * Gets to original identifier specified as <Namespace>/<PluginID>.<ext>
  237.      * Do this if you wish to extraxt the extention and parse manually.
  238.      *
  239.      * @return string 
  240.      * @access public
  241.      */
  242.     public function GetIdentifier){
  243.         return $this->Identifier;
  244.     }
  245.      // end of member function GetIdentifier
  246.  
  247.  
  248.     
  249.     /**
  250.      * Print an error code, if you use this method no other methods will be available.
  251.      *
  252.      * This method will print all 4xx and 5xx error codes specified in the RFC 2616, and some of the codes specified in the WebDAV extension.
  253.      * NOTE: This mehtod postes a soft error code in HTML, this may be improved later on.
  254.      *
  255.      * @param string msg The message you wish to print
  256.  
  257.      * @param int code The error code you wish to print eg. 404.
  258.  
  259.      * @return 
  260.      * @access public
  261.      */
  262.     public function PrintError$msg,  $code {
  263.         //Call parent,since the print error implementation is placed there
  264.         parent::PrintError($msg,$code);
  265.  
  266.         /*
  267.         I know this isn't needed since the parent implement all the logic, so it should be needed...
  268.         */
  269.     // end of member function PrintError
  270.  
  271.     
  272.     
  273.     
  274.     /**
  275.     *Finds and replaces all embedments, in a given string
  276.     *
  277.     *Currently not working since support for embeds isn't implemented yet.
  278.     *
  279.     *@param string Content The string you wish to clear of embedments
  280.     *@return string Content where all embedments have been included.
  281.     */
  282.     protected function ParseEmbedments($Content){
  283.         //TODO: Parse embedments
  284.         /*$Output = "";
  285.         //Only if there's embedments
  286.         if(sizeof($Exploded = explode("[[EMBED|",$Content)) > 0)
  287.         {
  288.             $Top = sizeof($Exploded);
  289.             for($i = 0; $i < $Top; $i += 2){
  290.                 $Output .= $Exploded[$i];
  291.                 $data = explode("|EMBED]]",$Exploded[$i +1] );
  292.                 $EmbedmentsOutputHandler = $this->Owner->GetEmbedment($data[0]);
  293.                 $Output .= $EmbedmentsOutputHandler->GetContent();
  294.                 $this->ExtentHeader($EmbedmentsOutputHandler->GetHeader());
  295.                 $Output .= $data[1];
  296.             }
  297.         }else{*/
  298.             $Output $Content;
  299.         //}
  300.         return $Output;
  301.     }
  302.  
  303. // end of CMS3_HTMLOutputHandler
  304. ?>

Documentation generated on Mon, 30 Apr 2007 01:59:09 +0200 by phpDocumentor 1.3.1