Source for file CMS3_PackageInstaller.php

Documentation is available at CMS3_PackageInstaller.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_PackageInstaller
  22. *
  23. @package    PackageInstaller
  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.  *PackageManager provides the logic for installation and removal of packages.
  31.  *
  32.  *This plugin doesn't provide any user interface only API interface for package operations, must be staticly linked.
  33.  */
  34. class CMS3_PackageInstaller extends CMS3_System_Plugin implements ISystemCallbackIConfigure //TODO: Perhaps implement IProvidesHelp
  35. {
  36.  
  37.     //ISystemCallback implementation
  38.     //used for ajax save...
  39.  
  40.     
  41.     /**
  42.      * Handles a callback from ajax application.
  43.      *
  44.      * @param string data Data attached to this callback
  45.      * @return 
  46.      * @access public
  47.      */
  48.     public function SystemCallback$data ){
  49.         if($data == "Upload"){
  50.             //Check for error on HTTP level
  51.             if ($_FILES["image"]["error"0){
  52.                 //Determine the error:
  53.                         /* this is a modification of similar code found here: http://php.net/manual/en/features.file-upload.errors.php */
  54.                 switch ($_FILES["image"]["error"]{
  55.                     case UPLOAD_ERR_INI_SIZE:
  56.                         $msg "The uploaded file exceeds the upload_max_filesize directive (" ini_get("upload_max_filesize"") in php.ini.";
  57.                         break;
  58.                     case UPLOAD_ERR_FORM_SIZE:
  59.                         $msg "The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form.";
  60.                         break;
  61.                     case UPLOAD_ERR_PARTIAL:
  62.                         $msg "The uploaded file was only partially uploaded.";
  63.                         break;
  64.                     case UPLOAD_ERR_NO_FILE:
  65.                         $msg "No file was uploaded.";
  66.                         break;
  67.                     case UPLOAD_ERR_NO_TMP_DIR:
  68.                         $msg "Missing a temporary folder.";
  69.                         break;
  70.                     case UPLOAD_ERR_CANT_WRITE:
  71.                         $msg "Failed to write file to disk";
  72.                         break;
  73.                     default:
  74.                         $msg "Unknown File Error";
  75.                 }
  76.                 //Log the error to system log
  77.                 $this->Owner->Log($this->GetPluginID()"Error during upload, HTTP/php error code: " $msg);
  78.             }else{
  79.                 //Move the uploaded package using package manager
  80.                 if(!$this->Owner->GetPlugin("PackageManager")->UploadPackage($_FILES["package"]["tmp_name"]substr($_FILES["package"]["name"],0,-4)))
  81.                 {
  82.                     //Log possible move error
  83.                     $this->Owner->Log($this->GetPluginID()"Unable to move uploaded package: " $_FILES["package"]["name"]);
  84.                 }
  85.             }
  86.             //Redirect back to configuration guide... File upload isn't ajax since you can't do that, perhaps it possible using a iframe proxy.
  87.             header("Location: " $this->Owner->GetCMS3URL("System/Configure/PackageInstaller");
  88.         }elseif($data == "Verify"){
  89.             //print the output from PackageManager
  90.             print $this->Owner->GetPlugin("PackageManager")->VerifyPackage($_POST["SelectedPackage"]"Good signature" "Bad signature";
  91.         }elseif($data == "Install"){
  92.             //print the output from PackageManager
  93.             print $this->Owner->GetPlugin("PackageManager")->InstallPackage($_POST["SelectedPackage"]);
  94.         }else{
  95.             //Nothing smart to do, just return a soft 404
  96.             print "Error: 404, data not found.";
  97.         }
  98.     }
  99.  
  100.  
  101.     //IConfigure implementation
  102.  
  103.     
  104.     /**
  105.     * Gets an absolute address of an icon for this plugin
  106.     */
  107.     public function GetControlCenterIcon(){
  108.         return $this->Owner->GetCMS3URL("bin/" $this->GetPluginID("/config.png";
  109.     }
  110.  
  111.     /**
  112.     * Gets menu entry string
  113.     */
  114.     public function GetControlCenterMenuEntry(){
  115.         //TODO: i18n
  116.         return "Install package";
  117.     }
  118.  
  119.     /**
  120.      * Gets a dojo based ajax guide for configuration of the plugin.
  121.      *
  122.      * @param IEmbedmentOutputHandler OutputHandler
  123.      * @return IEmbedmentOutputHandler 
  124.      * @access public
  125.      */
  126.     public function &Configure($Identifier null&$EmbedmentOutputHandler ){
  127.         //Load templates from files
  128.         $Head file_get_contents($this->Owner->GetCMS3Path("data/" $this->GetPluginID("/ConfigHead.htm");
  129.         $Body file_get_contents($this->Owner->GetCMS3Path("data/" $this->GetPluginID("/ConfigBody.htm");
  130.  
  131.             //Generate content
  132.         foreach($this->Owner->GetPlugin("PackageManager")->ListPackages(as $Package)
  133.         {
  134.             $Options .= "<option value='" $Package "' >" $Package "</option>\n";
  135.         }
  136.         $Body str_replace("CMS3URL",$this->Owner->GetCMS3URL(,$Body);
  137.         $Body str_replace("OPTIONS",$Options ,$Body);
  138.  
  139.         //Parse the output
  140.         $EmbedmentOutputHandler->ExtentHeader($Head);
  141.         $EmbedmentOutputHandler->SetBody($Body);
  142.         return $EmbedmentOutputHandler;
  143.     }
  144.  
  145.  
  146.         //Implementation of IPlugin
  147.  
  148.     
  149.     /**
  150.      * Gets the pluginID of the plugin.
  151.      *
  152.      * @return string 
  153.      * @access public
  154.      */
  155.     public function GetPluginID)
  156.     {
  157.         return "PackageInstaller";
  158.     }
  159.  
  160.  
  161. }
  162.  
  163.  
  164. ?>

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