Source for file CMS3_Help.php

Documentation is available at CMS3_Help.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_Help
  22. *
  23. @package    Help
  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. *The Help plugin displays help pages exposed with CMS3_Help_IProvidesHelp
  31. */
  32. {
  33.  
  34.         //ISystemCallback implementation
  35.  
  36.     
  37.     /**
  38.      * Handles a callback from ajax application.
  39.      *
  40.      * @param string data Data attached to this callback
  41.      * @return 
  42.      * @access public
  43.      */
  44.     public function SystemCallback$data ){
  45.         if($Content $this->ResolveIdentifier($data)){
  46.             $Title str_replace("/"" / "$data);
  47.             print "<h1>CMS3 / " $Title "</h1>" $Content;
  48.         }else{
  49.             print "The requested data could not be found.";
  50.         }
  51.     }
  52.  
  53.         //Implementation of ProvidesEditor
  54.  
  55.     
  56.     /**
  57.      * Shows help pages
  58.      *
  59.      * @param IEmbedmentOutputHandler EmbedmentOutputHandler Outputhandler the content MUST be parse to.
  60.     * @param string Identifier String at the end of the URL
  61.      * @return IEmbedmentOutputHandler 
  62.      * @access public
  63.      */
  64.     public function &ModifyContent($Identifier null&$EmbedmentOutputHandler){
  65.         //Load content from files
  66.         $Head file_get_contents($this->Owner->GetCMSPath "data/Help/HelpHead.htm");
  67.         $Body file_get_contents($this->Owner->GetCMSPath "data/Help/HelpBody.htm");
  68.  
  69.         //Generate treenodes
  70.         $TreeNodes "";
  71.         $ProvidesHelp $this->Owner->GetImplementations("CMS3_Help_IProvidesHelp");
  72.         foreach($ProvidesHelp as $Help){
  73.             $TreeNodes .= $this->ParseTreeNodes($Help->GetHelp());
  74.         }
  75.  
  76.         //Resolve identifier, if any
  77.         $Content false;
  78.         if(!is_null($Identifier&& $Identifier != ""){
  79.             if($Content $this->ResolveIdentifier($Identifier)){
  80.                 $Title str_replace("/"" / "$Identifier);
  81.                 $Content "<h1>CMS3 / " $Title "</h1>" $Content
  82.             }
  83.         }
  84.  
  85.         //If no identifier resolved, no content is set... just load something default
  86.         if(!$Content){
  87.             $Content  "<h1>CMS3 / Help</h1><p>Welcome to the CMS3 systems help plugin, this plugin will help you read help-pages provided by other plugins. In ordinary words you can browse system end-user documentation using the TreeView to the left.</p>";
  88.         }
  89.  
  90.         //Parse dynamic content to template
  91.         $Body str_replace("TREENODES"$TreeNodes ,$Body);
  92.         $Body str_replace("CONTENT"$Content ,$Body);
  93.  
  94.         $EmbedmentOutputHandler->ExtentHeader($Head);
  95.         $EmbedmentOutputHandler->SetBody($Body);
  96.         //TODO resolve Identifier: Title: CMS3 / PluginID / Subject / Subsubject /...
  97.         return $EmbedmentOutputHandler;
  98.     }
  99.  
  100.     /**
  101.     * Gets an absolute address of an icon for this plugin
  102.     */
  103.     public function GetSystemIcon(){
  104.         return $this->Owner->GetCMS3URL("bin/Help/help-browser.png";
  105.     }
  106.  
  107.     /**
  108.     * Gets menu entry string
  109.     */
  110.     public function GetSystemMenuEntry(){
  111.         return "Help";
  112.     }
  113.  
  114.         //Custom protected help function
  115.  
  116.     
  117.     /**
  118.     *Parse a list of entries into HTML TreeNodes
  119.     *
  120.     *@param array Entries List of entries to parse
  121.     *@param string Parent Identifier used by ResolveIdentifier
  122.     *@return string HTML/dojo representation of TreeNodes
  123.     */
  124.     protected function ParseTreeNodes($Entries$Parent ""){
  125.         $Output "";
  126.         foreach($Entries as $Entry){
  127.             $Output .= "<div dojoType='TreeNode' title='" $Entry[0"' object='" $this->Owner->GetCMS3URL("System/Callback/Help" $Parent "/" $Entry[0"'>";
  128.             $Output .= $this->ParseTreeNodes($Entry[2]$Parent "/" $Entry[0]);
  129.             $Output .= "</div>";
  130.         }
  131.         return $Output;
  132.     }
  133.  
  134.     /**
  135.     *Gets the content of a help page from its identifier
  136.     *
  137.     *@param string Identifier for the information you wish to retrive
  138.     *@param array Entries List of entries to search, defaults all help pages available
  139.     *@return string Content related the identifier, returns false if nothing was found within the searched entries
  140.     */
  141.     protected function ResolveIdentifier($Identifier$Entries null){
  142.         //If not set, get all entries available
  143.         if(is_null($Entries)){
  144.             $Entries array();
  145.             $ProvidesHelp $this->Owner->GetImplementations("CMS3_Help_IProvidesHelp");
  146.             //Foreach plugin that provides help
  147.             foreach($ProvidesHelp as $Help){
  148.                 //Get Top Level Array
  149.                 $TLA $Help->GetHelp();
  150.                 foreach($TLA as $TLEntry){
  151.                     //Join top level arrays to one
  152.                     $Entries[$TLEntry;
  153.                 }
  154.             }
  155.         }
  156.  
  157.         foreach($Entries as $Entry){
  158.             //If the entry is what we're looking for
  159.             if($Entry[0== $Identifier){
  160.                 return $Entry[1];
  161.             }
  162.  
  163.             //Check if it's owner of the one we're looking for
  164.             $IArray explode("/"$Identifier2);
  165.             if($Entry[0== $IArray[0]){
  166.                 if($Content $this->ResolveIdentifier($IArray[1]$Entry[2])){
  167.                     return $Content;
  168.                 }
  169.             }
  170.         }
  171.         //If not already returned return false
  172.         return false;
  173.     }
  174.  
  175.         //Implementation of IPlugin
  176.         /**
  177.      * Gets the pluginID of the plugin.
  178.      *
  179.      * @return string 
  180.      * @access public
  181.      */
  182.     public function GetPluginID){
  183.         return "Help";
  184.     }
  185.  
  186.  
  187. }
  188.  
  189.  
  190.  
  191. ?>

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