Source for file CMS3_SemanticOutputHandler.php

Documentation is available at CMS3_SemanticOutputHandler.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_SemanticOutputHandler
  22. *
  23. @package    SemanticOutputHandler
  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_SemanticOutputHandler generates simple output readable with a xsl/xml complaint browser
  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 $Title = "Untitled";
  44.     protected $Owner = null;
  45.     protected $Identifier = "";
  46.  
  47.     /**
  48.     *Sets the complete unique identifier.
  49.     *
  50.     *@param string Idenfitifer Complete unique identifier.
  51.     *@access public
  52.     */
  53.     public function SetIdentifier($Identifier ""){
  54.         $this->Identifier = $Identifier;
  55.     }
  56.  
  57.     /**
  58.      *
  59.      * @param CMS3_System Owner The CMS3_System that owns this plugin, gives the plugin ability to get data from
  60. CMS3_System
  61.  
  62.      * @return 
  63.      * @access public
  64.      */
  65.     public function Register(&$Owner )
  66.     {
  67.         //Just save a handle for now
  68.         $this->Owner =$Owner;
  69.     }
  70.  
  71.     /**
  72.      * Gets the pluginID of the plugin.
  73.      *
  74.      * @return string 
  75.      * @access public
  76.      */
  77.     public function GetPluginID){
  78.         return "SemanticOutputHandler";
  79.     }
  80.  
  81.     /**
  82.      * Data provided by use of this method may be left out if the OutputHandler wishes
  83.      * to print something else the HTML, therefor don't add important information
  84.      * here.
  85.      *
  86.      * @param string line A line you wish to add to the header.
  87.  
  88.      * @access public
  89.      */
  90.     public function ExtentHeader$line )
  91.     {
  92.         //Semantic ouputhandler doesn't support header extensions
  93.         //But this was documentated in the specification of IOutputHandler, so plugins should be aware of this...
  94.         //this is also why the dojo toolkit was chosen for this system.
  95.  
  96.         /*
  97.             I know it's physically possible to include the headerextension in the xmlformat and then extract it during xsl transform...
  98.             But that would NOT look good in the xml feed.
  99.         */
  100.     }
  101.  
  102.  
  103.     /**
  104.      *
  105.      * @param string title
  106.      * @access public
  107.      */
  108.     public function SetTitle$title {
  109.         $this->Title = $title;
  110.     // end of member function SetTitle
  111.  
  112.     
  113.     /**
  114.      * Set the body if the page, read parameter documentation.
  115.      *
  116.      * 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.
  117.      * 
  118.      * @param string body Body of the page, or description of a channel.
  119.  
  120.      * @param array List Parse a list, use this feature if you wish to parse a list. This will also
  121.      *  enable to OutputHandler to print a feed. This parameter is optional, if set the
  122.      *  first parameter will define the description of the channel, and every body and
  123.      *  title in this array will define an entry.
  124.      *  Array layout:
  125.      *  [body,body,...]
  126.      *  or
  127.      *  [[title,body],[title,body],...]
  128.  
  129.      * @return 
  130.      * @access public
  131.      */
  132.     public function SetBody$body,  $List null {
  133.         $this->Body = $body;
  134.         $this->BodyList = $List;
  135.     // end of member function SetBody
  136.  
  137.     
  138.     /**
  139.      * Print the content, should also be called from GetPage().
  140.      *
  141.      *this prints a xml page with a very simple schema:
  142.      *<semanticpage>
  143.      *    <title>Page Title</title>
  144.      *    <content>
  145.      *        <para>Main paragraph</para>
  146.      *        <subpara>Sub paragraph<subpara>
  147.      *        <subpara headline="Optional headline of sub paragraph">Sub paragraph<subpara>
  148.      *        <subpara>Sub paragraph<subpara>
  149.      *        <subpara>Sub paragraph<subpara>
  150.      *        ...
  151.      *    </content>
  152.      *</semanticpage>
  153.      *
  154.      *
  155.      * @access public
  156.      */
  157.     public function Parse({
  158.         if(!$this->IsDisabled){
  159.             header('Content-Type: text/xml');
  160.             $Content $this->GetContent()// Get the content first
  161.             print "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
  162.             print "<?xml-stylesheet type=\"text/xsl\" href=\"" $this->Owner->GetCMS3URL("bin/" $this->GetPluginID("/template.xsl\"?>\n";
  163.             print "<semanticpage>\n\t<title>";
  164.             print $this->Title . "</title>\n";
  165.             print $Content;
  166.             print "\t<server>" $this->Owner->GetCMS3URL("</server>\n";
  167.             print "</semanticpage>";
  168.  
  169.             $this->Disable();
  170.         }
  171.     // end of member function Parse
  172.  
  173.  
  174.     
  175.     /**
  176.     *Gets content ready to be printed
  177.     *
  178.     *This does not include header, only the body content.
  179.     *
  180.     *@return string Content ready for print
  181.     */
  182.     public function GetContent(){
  183.         $Content "\t<content>\n\t\t<para><![CDATA[\n" $this->Body . "]]>\n\t\t</para>\n";
  184.         if(is_array($this->BodyList)){
  185.             foreach($this->BodyList as $key => $value){
  186.                 if(is_array($value)){
  187.                     $Content .= "\t\t<subpara headline=\"" $value[0"\" ><![CDATA[";
  188.                     $Content .= $value[1"]]></subpara>\n";
  189.                 }else{
  190.                     $Content .= "\t\t<subpara><![CDATA[" $value "]]></subpara>\n";
  191.                 }
  192.             }
  193.         }
  194.         return $Content "\t</content>\n";
  195.     }
  196.  
  197.     /**
  198.     *Gets the header extension
  199.     *
  200.     *@return string Lines to be added to the header
  201.     */
  202.     public function GetHeader(){
  203.         return $this->Header;
  204.     }
  205.  
  206.  
  207.     /**
  208.      * Diable the OutputHandler, do this if you wish to print binary data.
  209.      *
  210.      * @return 
  211.      * @access public
  212.      */
  213.     public function Disable){
  214.         $this->IsDisabled = true;
  215.     }
  216.     // end of member function Disable
  217.  
  218.     
  219.     /**
  220.      * Gets to original identifier specified as <Namespace>/<PluginID>.<ext>
  221.      * Do this if you wish to extraxt the extention and parse manually.
  222.      *
  223.      * @return string 
  224.      * @access public
  225.      */
  226.     public function GetIdentifier){
  227.         return $this->Identifier;
  228.     }
  229.      // end of member function GetIdentifier
  230.  
  231. // end of CMS3_HTMLOutputHandler
  232. ?>

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