Source for file CMS3_PlainHTML.php

Documentation is available at CMS3_PlainHTML.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_PlainHTML
  22. *
  23. @package    PlainHTML
  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 PlainHTML plugin provides ability to create plain HTML pages.
  31. */
  32. {
  33.  
  34.  
  35.     //ISystemCallback implementation
  36.     //used for ajax save...
  37.  
  38.     
  39.     /**
  40.      * Handles a callback from ajax application.
  41.      *
  42.      * @param string data Data attached to this callback
  43.      * @return 
  44.      * @access public
  45.      */
  46.     public function SystemCallback$data ){
  47.         //Callbacks from page editor
  48.         if($data == "Save"){
  49.             if($_POST["TODO"== "Create"){
  50.                 $Query "INSERT INTO CMS3_PlainHTML (Identifier, Body) VALUES ('" $_POST["Identifier""','" $_POST["Content""')";
  51.             }
  52.             if($_POST["TODO"== "Modify"){
  53.                 $Query "UPDATE CMS3_PlainHTML SET Body = '" $_POST["Content""' WHERE Identifier = '" $_POST["Identifier""' limit 1";
  54.             }
  55.             if(mysql_query($Query$this->Owner->GetDatabaseHandle())){
  56.                 $Output "True";
  57.             }else{
  58.                 $Output "Could not save data, please try agian or check the identifier.";
  59.                 //TODO: Log the error
  60.             }
  61.             if($_POST["IsAjaxCallback"== "true"){
  62.                 print $Output;
  63.             }else{
  64.                 $Link $this->Owner->GetCMS3URL("System/Edit/" $this->GetPluginID("/" $_POST["Identifier"];
  65.                 print "<html><head><META http-equiv='refreshcontent='5;URL=$Link'></head><body><h2>$Output</h2><a href='$Link'>Click here if you not automaticly redirected in 5 secounds...</a><br><i>It's recommended to activate javascript while using CMS3 backend.</i></body></html>";
  66.             }
  67.         //Some callbacks from page listings
  68.         }elseif($data == "GotoPage"){
  69.             //Create/Edit callback
  70.             if($_POST["Submitter"== "Create/Edit"){
  71.                 header("Location: " $this->Owner->GetCMS3URL("System/Edit/" $this->GetPluginID("/" $_POST["Identifier"]);
  72.             //Show callback
  73.             }elseif($_POST["Submitter"== "Show"){
  74.                 if($Namespace $this->Owner->GetNamespace($this->GetPluginID())){
  75.                     header("Location: " $this->Owner->GetCMS3URL($Namespace "/" $_POST["Identifier"]);
  76.                 }else{
  77.                     $Link $this->Owner->GetCMS3URL("System/Edit/" $this->GetPluginID();
  78.                     $Output "No namespace registed for this plugin";
  79.                     print "<html><head><META http-equiv='refreshcontent='5;URL=$Link'></head><body><h2>$Output</h2><a href='$Link'>Click here if you not automaticly redirected in 5 secounds...</a><br><i>It's recommended to activate javascript while using CMS3 backend.</i></body></html>";
  80.                 }
  81.             //None ajax delete callback
  82.             }elseif($_POST["Submitter"== "Delete"){
  83.                 $Link $this->Owner->GetCMS3URL("System/Edit/" $this->GetPluginID();
  84.                 if($this->DeletePage($_POST["Identifier"])){
  85.                     $Output "Page successfully deleted";
  86.                 }else{
  87.                     $Output "Page could not be deleted";
  88.                 }
  89.                 print "<html><head><META http-equiv='refreshcontent='5;URL=$Link'></head><body><h2>$Output</h2><a href='$Link'>Click here if you not automaticly redirected in 5 secounds...</a><br><i>It's recommended to activate javascript while using CMS3 backend.</i></body></html>";
  90.             }
  91.         //Ajax delete callback
  92.         }elseif($data == "Delete"){
  93.             if($this->DeletePage($_POST["Identifier"])){
  94.                     print "Page named: "$_POST["Identifier"." has been successfully deleted...";
  95.                 }else{
  96.                     print "Error: Page named: "$_POST["Identifier"." could not be deleted...";
  97.                 }
  98.         //Callback from config to save namespace (Ajax)
  99.         }elseif($data == "SaveNamespace"){
  100.             //Find old namespace
  101.             $OldNS $this->Owner->GetNamespace($this->GetPluginID());
  102.  
  103.             //Does old namespace exist?
  104.             if(!$OldNS){
  105.                 //If does not exist
  106.  
  107.                 //TODO: remove illegal chars...
  108.                 //Try to register new namespace
  109.                 if($this->Owner->RegisterNamespace($_POST["Namespace"]$this->GetPluginID())){
  110.                     print "TRUE";
  111.                 }else{
  112.                         //TODO i18n
  113.                     print "Registration failed, make sure you have chosen a unique namespace.";
  114.                 }
  115.             }else{
  116.                 //If does exist
  117.                 
  118.                 //Unregister current namespace (should not be able to fail)
  119.                 if($this->Owner->UnregisterNamespace($OldNS)) //NOTE: a plugin can't have two namespaces due to database layout.
  120.                 {
  121.                     //TODO: remove illegal chars...
  122.                     //Try to register new namespace
  123.                     if($this->Owner->RegisterNamespace($_POST["Namespace"]$this->GetPluginID())){
  124.                         print "TRUE";
  125.                     }else{
  126.                         //Try to reregister old namespace
  127.                         if($this->Owner->RegisterNamespace($OldNS$this->GetPluginID())){
  128.                                 //TODO i18n
  129.                             print "Registration failed, make sure you have chosen a unique namespace. You still have the old namespace.";
  130.                         }else{
  131.                                 //TODO i18n
  132.                             print "Registration failed, make sure you have chosen a unique namespace. You don't have any namespace now.";
  133.                             //Not owning any namespace
  134.                         }
  135.                     }
  136.                 }else{
  137.                     //Could not unregister current namespace
  138.                         //TODO: i18n
  139.                     $msg "Unregistration of current namespace failed."
  140.                     print $msg;
  141.                     $this->Owner->Log($this->GetPluginID()$msg);
  142.                 }
  143.             }
  144.  
  145.         //Callback from config to save default page (Ajax)
  146.         }elseif($data == "SaveDefaultPage"){
  147.             $Settings $this->LoadSettings();
  148.             $Settings["DefaultPage"$_POST["DefaultPage"];
  149.             //Save settings
  150.             if($this->SaveSettings($Settings)){
  151.                 print "TRUE";
  152.             }else{
  153.                 //TODO: i18n
  154.                 $msg "Failed to save settings.";
  155.                 print $msg;
  156.                 //Log this since it should not be happing:
  157.                 $this->Owner->Log($this->GetPluginID()$msg);
  158.             }
  159.         }else{
  160.             print "Error: 404, data not found.";
  161.         }
  162.     }
  163.  
  164.     /**
  165.     *Deletes a page
  166.     *
  167.     *@param string Identifier Title of the page to delete
  168.     *@return bool True/false, depending on success
  169.     */
  170.     protected function DeletePage($Identifier){
  171.         $Query "DELETE FROM CMS3_PlainHTML WHERE Identifier = '$Identifierlimit 1";
  172.         //TODO: Log error on fail
  173.         return mysql_query($Query$this->Owner->GetDatabaseHandle());
  174.     }
  175.  
  176.  
  177.         //IProvidesContent implementation
  178.         /**
  179.      * Print the page of a given identifier.
  180.      *
  181.      * @param string identifier Identifier of the requested page.
  182.  
  183.      * @param IOutputHandler OutputHandler OutputHandler used the parse the output. You may disable this OutputHandler with
  184.     *  OutputHandler->Disable() and print the content manually.
  185.  
  186.      * @return 
  187.      * @access public
  188.      */
  189.     public function &GetPage$identifier,  &$OutputHandler ){
  190.         //Handle identifier = "", by use of settings    
  191.         if($identifier == ""){
  192.             $Settings $this->LoadSettings();
  193.             $identifier $Settings["DefaultPage"];
  194.         }
  195.         
  196.         //Find the page requested
  197.         $Query "SELECT Body FROM CMS3_PlainHTML WHERE Identifier = '$identifierlimit 1";
  198.         $Result mysql_query($Query$this->Owner->GetDatabaseHandle());
  199.         if(mysql_num_rows($Result!= 0){
  200.             //Generate content
  201.             $Row mysql_fetch_array($ResultMYSQL_ASSOC);
  202.             $OutputHandler->SetBody($Row["Body"]);
  203.             $OutputHandler->SetTitle($identifier);
  204.  
  205.  
  206.             //Do some statistics
  207.             $CookieName "CMS3_" $this->GetPluginID("_" .  $identifier;
  208.             if($_COOKIE[$CookieName!= "True"){
  209.                 //Set cookie so we may remember where we are
  210.                 setcookie($CookieName"True")//TODO Set expire, path and domain to avoid conficts
  211.                 //Update the database
  212.                 $Query "UPDATE CMS3_PlainHTML SET Visits=(Visits + 1) WHERE Identifier = '$identifierlimit 1";
  213.                 if(!mysql_query($Query$this->Owner->GetDatabaseHandle())){
  214.                     //Log possible failure
  215.                     $this->Owner->LogMySQL($this->GetPluginID()"Unable to update counter at mysql_query"$this->Owner->GetDatabaseHandle());
  216.                 }
  217.             }
  218.  
  219.             //Parse content (Must be done after statistics since it requires header communication)
  220.             $OutputHandler->Parse();
  221.         }else{
  222.             $OutputHandler->PrintError("Page not found in collection$identifier."404);
  223.         }
  224.         return $OutputHandler;
  225.     }
  226.  
  227.  
  228.  
  229.         //IProvidesEditor implementation
  230.         /**
  231.      * Gets an Ajax guide for modification of the content.
  232.      *
  233.      * @param IEmbedmentOutputHandler EmbedmentOutputHandler Outputhandler the content MUST be parse to.
  234.      * @return IEmbedmentOutputHandler 
  235.      * @access public
  236.      */
  237.     public function &ModifyContent($Identifier null&$EmbedmentOutputHandler){
  238.         if($Identifier != ""){
  239.             //Printing the editor for an entry
  240.             $Query "SELECT Body FROM CMS3_PlainHTML WHERE Identifier = '$Identifierlimit 1";
  241.             $Result mysql_query($Query$this->Owner->GetDatabaseHandle());
  242.             if(mysql_num_rows($Result!= 0){
  243.                 $Row mysql_fetch_array($ResultMYSQL_ASSOC);
  244.                 $PageBody $Row["Body"];
  245.                 $TODO "Modify";
  246.             }else{
  247.                 $TODO "Create";
  248.                 $PageBody "New page\n<br/>\n<br/>\n<br/>";
  249.             }
  250.             $Head "<script type='text/javascript' src='" $this->Owner->GetCMS3URL("bin/System/js/dojo/src/lfx/html.js'></script>";
  251.             $Head .= file_get_contents($this->Owner->GetCMS3Path("data/PlainHTML/EditorHead.htm");
  252.             $Body file_get_contents($this->Owner->GetCMS3Path("data/PlainHTML/EditorBody.htm");
  253.             $Body .= "<h2>$TODO$Identifier</h2><form id='PlainHTMLaction='$this->Owner->GetCMS3URL("System/Callback/" $this->GetPluginID("/Savemethod='post'><input type='hiddenname='Identifiervalue='$Identifier' /><textarea name='ContentdojoType='Editor2style='width: 99%;background-colorwhite;border: 1px solid black;' rows=30 >$PageBody</textarea><br /><input type='submitvalue='Save' /><input type='hiddenname='IsAjaxCallbackid='IsAjaxvalue='false' /><input type='hiddenname='TODOid='TODOvalue='$TODO' /></form>";
  254.             $EmbedmentOutputHandler->SetBody($Body);
  255.             $EmbedmentOutputHandler->ExtentHeader($Head);
  256.         }else{
  257.             //List all pages, enable deletion, editing and creation of new pages
  258.  
  259.             //Get the header
  260.             $Head file_get_contents($this->Owner->GetCMS3Path("data/PlainHTML/ListHead.htm");
  261.             $Head str_replace("CMS3URL",$this->Owner->GetCMS3URL(,$Head);
  262.  
  263.             //Generate content
  264.             $Query "SELECT Identifier FROM CMS3_PlainHTML ORDER by Identifier";
  265.             $Result mysql_query($Query$this->Owner->GetDatabaseHandle());
  266.             $Options "";
  267.             if(mysql_num_rows($Result!= 0){
  268.                 while($Row mysql_fetch_array($ResultMYSQL_ASSOC))
  269.                 {
  270.                     $Options .= "<option value='" $Row["Identifier""'>" $Row["Identifier""</option>\n";
  271.                 }
  272.             }
  273.  
  274.             //Generate statistics
  275.             $Stats "";
  276.             $Query "SELECT Identifier,Visits FROM CMS3_PlainHTML ORDER by Visits";
  277.             $Result mysql_query($Query$this->Owner->GetDatabaseHandle());
  278.             if(mysql_num_rows($Result!= 0){
  279.                 while($Row mysql_fetch_array($ResultMYSQL_ASSOC))
  280.                 {
  281.                     $Stats .= "<tr><td>" $Row["Identifier""</td><td>" $Row["Visits""</td></tr>";
  282.                 }
  283.             }
  284.  
  285.             //Load template and fill in dynamic content
  286.             $Body file_get_contents($this->Owner->GetCMS3Path("data/PlainHTML/ListBody.htm");
  287.             $Body str_replace("CMS3URL",$this->Owner->GetCMS3URL(,$Body);
  288.             $Body str_replace("STATS",$Stats ,$Body);
  289.             $Body str_replace("OPTIONS",$Options ,$Body);
  290.  
  291.             //Parse it to the output handler
  292.             $EmbedmentOutputHandler->ExtentHeader($Head);
  293.             $EmbedmentOutputHandler->SetBody($Body);
  294.         }
  295.         return $EmbedmentOutputHandler;
  296.     }
  297.  
  298.     /**
  299.     * Gets an absolute address of an icon for this plugin
  300.     */
  301.     public function GetSystemIcon(){
  302.         return $this->Owner->GetCMS3URL("bin/" $this->GetPluginID("/writer.png";
  303.     }
  304.  
  305.     /**
  306.     * Gets menu entry string
  307.     */
  308.     public function GetSystemMenuEntry(){
  309.         return "Plain HTML pages";
  310.     }
  311.  
  312.     //Implementation of ILinkable
  313.  
  314.     
  315.     /**
  316.      * Gets a list of links that the plugins exposes
  317.      * 
  318.      * Each entry in the array is an array with 3 fields, one for the display name, one for the URL of the page, and one for an array of sub entries. Each sub entry consits of 3 fields, just like the toplevel entries.
  319.      * 
  320.      * @access public
  321.      * @return array 
  322.      */
  323.     public function GetLinks){
  324.         //Get out namespace
  325.         if($Namespace $this->Owner->GetNamespace($this->GetPluginID())){
  326.             //Get a URL
  327.             $URL $this->Owner->GetCMS3URL($Namespace "/";
  328.  
  329.             //Create an plugin entry
  330.             $Links array($Namespace,$URLarray());
  331.  
  332.             //Generate content
  333.             $Query "SELECT Identifier FROM CMS3_PlainHTML ORDER by Identifier";
  334.             $Result mysql_query($Query$this->Owner->GetDatabaseHandle());
  335.  
  336.             if(mysql_num_rows($Result!= 0){
  337.                 while($Row mysql_fetch_array($ResultMYSQL_ASSOC))
  338.                 {
  339.                     $Links[2][=array($Row["Identifier"]$URL $Row["Identifier"null)
  340.                 }
  341.             }
  342.  
  343.             //Add toplevel array and return it
  344.             return array($Links);
  345.         }else{
  346.             return array(array($this->GetPluginID()nullnull));
  347.         }
  348.     }
  349.  
  350.  
  351.         //IPlugin implementation
  352.         /**
  353.      * Gets the pluginID of the plugin.
  354.      *
  355.      * @return string 
  356.      * @access public
  357.      */
  358.     public function GetPluginID){
  359.         return "PlainHTML";
  360.     }
  361.  
  362.  
  363.     //IConfigure implementation
  364.  
  365.     
  366.     /**
  367.     * Gets an absolute address of an icon for this plugin
  368.     */
  369.     public function GetControlCenterIcon(){
  370.         return $this->Owner->GetCMS3URL("bin/" $this->GetPluginID("/config.png";
  371.     }
  372.  
  373.     /**
  374.     * Gets menu entry string
  375.     */
  376.     public function GetControlCenterMenuEntry(){
  377.         //TODO: i18n
  378.         return "Configure " $this->GetPluginID();
  379.     }
  380.  
  381.     /**
  382.      * Gets a dojo based ajax guide for configuration of the plugin.
  383.      *
  384.      * @param IEmbedmentOutputHandler OutputHandler
  385.      * @return IEmbedmentOutputHandler 
  386.      * @access public
  387.      */
  388.     public function &Configure($Identifier null&$EmbedmentOutputHandler ){
  389.         //Load templates from files
  390.         $Head file_get_contents($this->Owner->GetCMS3Path("data/" $this->GetPluginID("/ConfigHead.htm");
  391.         $Body file_get_contents($this->Owner->GetCMS3Path("data/" $this->GetPluginID("/ConfigBody.htm");
  392.  
  393.             //Generate content
  394.         //Load settings
  395.         $Settings $this->LoadSettings();
  396.         //Run list pages
  397.         $Query "SELECT Identifier FROM CMS3_PlainHTML ORDER BY Identifier";
  398.         $Result mysql_query($Query$this->Owner->GetDatabaseHandle());
  399.         $Options "";
  400.         if(mysql_num_rows($Result!= 0){
  401.             while($Row mysql_fetch_array($ResultMYSQL_ASSOC))
  402.             {
  403.                 if($Settings["DefaultPage"== $Row["Identifier"]){
  404.                      $Selected " selected=\"selected\"";
  405.                 }else{
  406.                     $Selected "";
  407.                 }
  408.                 $Options .= "<option value='" $Row["Identifier""'" $Selected ">" $Row["Identifier""</option>\n";
  409.             }
  410.         }
  411.         $Body str_replace("CMS3URL",$this->Owner->GetCMS3URL(,$Body);
  412.         $Body str_replace("OPTIONS",$Options ,$Body);
  413.         $Body str_replace("NAMESPACE",$this->Owner->GetNamespace($this->GetPluginID()) ,$Body);
  414.  
  415.         //Parse the output
  416.         $EmbedmentOutputHandler->ExtentHeader($Head);
  417.         $EmbedmentOutputHandler->SetBody($Body);
  418.         return $EmbedmentOutputHandler;
  419.     }
  420.  
  421.     /**
  422.     *Opens the settings file for writting
  423.     */
  424.     protected function &LoadSettings(){
  425.         //We're return be referance for performance issues...
  426.         $SettingsFile $this->Owner->GetCMS3Path("etc/" $this->GetPluginID("/settings.bin"//.bin since it a binary serialized string
  427.         if(file_exists($SettingsFile)){
  428.             //Read data from file
  429.             if(($data file_get_contents($SettingsFile)) === FALSE){
  430.                 $this->Owner->Log($this->GetPluginID()"Could not read date from settings file: ./etc/" $this->GetPluginID("/Settings.bin");
  431.                 return array();                
  432.             }
  433.             //Deserialize loaded data
  434.             return unserialize($data);
  435.         }else{
  436.             return array();
  437.         }
  438.     }
  439.  
  440.     /**
  441.     *Save settings to files...
  442.     */
  443.     protected function SaveSettings(&$Settings){
  444.         $SettingsFile $this->Owner->GetCMS3Path("etc/" $this->GetPluginID("/settings.bin"//.bin since it a binary serialized string
  445.         $SettingsPath $this->Owner->GetCMS3Path("etc/" $this->GetPluginID("/";
  446.         //Create dir if not there
  447.         if(!is_dir($SettingsPath)){
  448.             if(!mkdir($SettingsPath)){
  449.                 //Log error if couldn't be created
  450.                 $this->Owner->Log($this->GetPluginID()"Could not create directory for settings: ./etc/" $this->GetPluginID("/");
  451.                 return false;
  452.             }
  453.         }
  454.         //Check if file is writeable
  455.         if(file_exists($SettingsFile&& !is_writable($SettingsFile)){
  456.             //Log error if file isn't writeable
  457.             $this->Owner->Log($this->GetPluginID()"Settings file is not writeable: ./etc/" $this->GetPluginID("/Settings.bin");
  458.             return false;
  459.         }else{
  460.             //Open the file for writing
  461.             if(!$Handle fopen($SettingsFile"w")){
  462.                 $this->Owner->Log($this->GetPluginID()"Settings file could not be opened: ./etc/" $this->GetPluginID("/Settings.bin");
  463.                 return false;
  464.             }
  465.             //Write data to file
  466.             if(fwrite($Handle,serialize($Settings)) === FALSE){
  467.                 $this->Owner->Log($this->GetPluginID()"Settings could not be written to file: ./etc/" $this->GetPluginID("/Settings.bin");
  468.                 return false;
  469.             }
  470.             //Close filestream/handle
  471.             if(!fclose($Handle)){
  472.                 $this->Owner->Log($this->GetPluginID()"Could not close setting file correctly: ./etc/" $this->GetPluginID("/Settings.bin");
  473.             }
  474.             //Return true since we've saved the settings, doesn't really matter if file wasn't closed correctly 
  475.             return true;
  476.         }
  477.     }
  478.  
  479.         //Implementation of CMS3_Help_IProvidesHelp
  480.  
  481.     
  482.     /**
  483.     *Gets a list of the help available for this plugin
  484.     *
  485.     *This method returns a list of toplevel subjects, only one or two toplevel subjects, each toplevel subject is an array with 3 fields number zero a title, number one the body text of the help page (in HTML) and number 2 is an array of subsubjects. Each subsubject consists of the same as the toplevel subjects.
  486.     *
  487.     *Return array List of help subjects and subsubjects
  488.     */
  489.     public function GetHelp(){
  490.         //TODO Serialize this and store it in data, then deserialize whenever loading... (Should be done at build time)
  491.             //Or Use CSV as defined in RFC4180 this could improve performance and maintainability
  492.  
  493.         //Top Level Array
  494.         $TLA array();
  495.  
  496.         //Create toplevel entry
  497.         $TLA[0array();
  498.         $TLA[0][0$this->GetPluginID();
  499.             //TODO i18n
  500.         $TLA[0][1"<i>A free plugin by Jonas F. Jensen.</i>";
  501.         $TLA[0][1.= "<p>The PlainHTML plugin will let create and display plain html pages.</p><p>Curretly there's no help text provided, since it takes an awfull long time to write... But this should prove the concept of plugin specific help pages, and sub help pages... Meaning that this text is provided using an implementation of CMS3_Help_IProvidesHelp on the CMS3_plainHTML class of the PlainHTML plugin.<br />As a final thought notice that the help plugin showing this text, reads from URL, making it possible for plugins to link directly to their (sub) help pages.</p>";
  502.         //TODO: More text
  503.         
  504.         //Create array for subjects
  505.         $TLA[0][2array();
  506.  
  507.         //Create array for subject
  508.         $TLA[0][2][0array();
  509.         $TLA[0][2][0][0"Managing pages";
  510.         $TLA[0][2][0][1"TODO: Subpages Create, Edit (Using editor) , Display, Delete";
  511.         $TLA[0][2][0][2array();
  512.  
  513.         //Create array for subject
  514.         $TLA[0][2][1array();
  515.         $TLA[0][2][1][0"Create pages";
  516.         $TLA[0][2][1][1"TODO";
  517.         $TLA[0][2][1][2array();
  518.  
  519.         //Create array for subject
  520.         $TLA[0][2][2array();
  521.         $TLA[0][2][2][0"Display pages";
  522.         $TLA[0][2][2][1"TODO";
  523.         $TLA[0][2][2][2array();
  524.  
  525.         //Create array for subject
  526.         $TLA[0][2][3array();
  527.         $TLA[0][2][3][0"Configuration";
  528.         $TLA[0][2][3][1"TODO";
  529.         $TLA[0][2][3][2array();
  530.  
  531.         //Create array for subject
  532.         $TLA[0][2][4array();
  533.         $TLA[0][2][4][0"About";
  534.         $TLA[0][2][4][1"TODO";
  535.         $TLA[0][2][4][2array();
  536.  
  537.         return $TLA;
  538.     }
  539.  
  540.         //Implementation of IInstall
  541.  
  542.     
  543.     /**
  544.      * Runs a script to complet installation
  545.      *
  546.      * This creates database tables, and default data.
  547.      *
  548.      * @return bool True if installations script went okay, otherwise return false.
  549.      * @access public
  550.      */
  551.     public function Install()
  552.     {
  553.         //Create some default settings
  554.         $Settings["DefaultPage""Mainpage";
  555.         if(!$this->SaveSettings($Settings)){
  556.             $this->Owner->Log($this->GetPluginID()"Unable to create default settings");
  557.             //This is not a importent error, user will have to edit settings anyway, therefor we don't return false
  558.         }
  559.  
  560.         //Get database handle
  561.         $dbh $this->Owner->GetDatabaseHandle();
  562.  
  563.         //Create a table
  564.         if(!mysql_query("CREATE TABLE IF NOT EXISTS `CMS3_PlainHTML` (  `Identifier` varchar(255) character set latin1 NOT NULL, `Body` longtext character set latin1 NOT NULL, `Visits` int(11) NOT NULL default '0', PRIMARY KEY  (`Identifier`)  ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_danish_ci"$dbh )) 
  565.         {
  566.             $this->Owner->LogMySQL($this->GetPluginID()"Error during creating of tables "$dbh);
  567.             return false;
  568.         }
  569.  
  570.         //Create mainpage
  571.         if(mysql_query("INSERT INTO `CMS3_PlainHTML` (`Identifier`, `Body`, `Visits`) VALUES ('Mainpage', '<h1>Mainpage</h1>You have just installed the PlainHTML plugin for CMS3,<br>enter the backend to start editing pages.<br><br><br>', 2)"$dbh )) 
  572.         {
  573.             return true;
  574.         }else{    
  575.             $this->Owner->LogMySQL($this->GetPluginID()"Error during creating of sample data " ,$dbh);
  576.             return false;
  577.         }
  578.     }
  579.  
  580.         //Implementation of IRemove
  581.         /**
  582.      * Removes files and databases created after fysical installation
  583.      *
  584.      * @return bool true/false depending on success
  585.      * @access public
  586.      */
  587.     public function Remove)
  588.     {
  589.         //Unregister namespace
  590.         $this->Owner->UnregisterNamespace($this->Owner->GetNamespace($this->GetPluginID()));
  591.  
  592.         //Delete potential settingsfile
  593.         $SettingsFile $this->Owner->GetCMS3Path("etc/" $this->GetPluginID("/settings.bin"//.bin since it a binary serialized string
  594.         if(file_exists($SettingsFile))
  595.             unlink($SettingsFile);
  596.  
  597.         //Drop tables
  598.         $sql 'DROP TABLE CMS3_PlainHTML';
  599.         $dbh $this->Owner->GetDatabaseHandle();
  600.         if(mysql_query($sql,  $dbh)) 
  601.         {
  602.             return true;
  603.         }else{    
  604.             $this->Owner->LogMySQL($this->GetPluginID()"Error during deletion of database table " ,$dbh);
  605.             return false;
  606.         }
  607.     }
  608. }
  609.  
  610. ?>

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