[ Index ]

PHP Cross Reference of vtigercrm-6.1.0

title

Body

[close]

/vtlib/Vtiger/ -> ThemeExport.php (source)

   1  <?php
   2  /*+**********************************************************************************
   3   * The contents of this file are subject to the vtiger CRM Public License Version 1.0
   4   * ("License"); You may not use this file except in compliance with the License
   5   * The Original Code is:  vtiger CRM Open Source
   6   * The Initial Developer of the Original Code is vtiger.
   7   * Portions created by vtiger are Copyright (C) vtiger.
   8   * All Rights Reserved.
   9   ************************************************************************************/
  10  include_once ('vtlib/Vtiger/Package.php');
  11  
  12  /**
  13   * Provides API to package vtiger CRM language files.
  14   * @package vtlib
  15   */
  16  class Vtiger_ThemeExport extends Vtiger_Package {
  17      const TABLENAME = 'vtiger_layoutskins';
  18  
  19      /**
  20       * Constructor
  21       */
  22      function __construct() {
  23              parent::__construct();
  24      }
  25  
  26      /**
  27       * Generate unique id for insertion
  28       * @access private
  29       */
  30      static function __getUniqueId() {
  31              global $adb;
  32              return $adb->getUniqueID(self::TABLENAME);
  33      }
  34  
  35      /**
  36       * Initialize Export
  37       * @access private
  38       */
  39      function __initExport($layoutName, $themeName) {
  40              // Security check to ensure file is withing the web folder.
  41              Vtiger_Utils::checkFileAccessForInclusion("layouts/$layoutName/skins/$themeName/style.less");
  42  
  43              $this->_export_modulexml_file = fopen($this->__getManifestFilePath(), 'w');
  44              $this->__write("<?xml version='1.0'?>\n");
  45      }
  46  
  47      /**
  48       * Export Module as a zip file.
  49       * @param Vtiger_Module Instance of module
  50       * @param Path Output directory path
  51       * @param String Zipfilename to use
  52       * @param Boolean True for sending the output as download
  53       */
  54      function export($layoutName, $themeName, $todir='', $zipfilename='', $directDownload=false) {
  55              $this->__initExport($layoutName, $themeName);
  56  
  57              // Call layout export function
  58              $this->export_Theme($layoutName, $themeName);
  59  
  60              $this->__finishExport();
  61  
  62              // Export as Zip
  63              if($zipfilename == '') $zipfilename = "$layoutName-$themeName" . date('YmdHis') . ".zip";
  64              $zipfilename = "$this->_export_tmpdir/$zipfilename";
  65  
  66              $zip = new Vtiger_Zip($zipfilename);
  67  
  68              // Add manifest file
  69              $zip->addFile($this->__getManifestFilePath(), "manifest.xml");
  70  
  71              // Copy module directory
  72              $zip->copyDirectoryFromDisk("layouts/$layoutName/skins/$themeName");
  73  
  74              $zip->save();
  75  
  76              if($todir) {
  77                      copy($zipfilename, $todir);
  78              }
  79              
  80              if($directDownload) {
  81                      $zip->forceDownload($zipfilename);
  82                      unlink($zipfilename);
  83              }
  84              $this->__cleanupExport();
  85      }
  86  
  87      /**
  88       * Export Language Handler
  89       * @access private
  90       */
  91      function export_Theme($layoutName, $themeName) {
  92              global $adb;
  93  
  94              $sqlresult = $adb->pquery("SELECT * FROM vtiger_layoutskins WHERE name = ?", array($themeName));
  95              $layoutresultrow = $adb->fetch_array($sqlresult);
  96  
  97              $resultThemename  = decode_html($layoutresultrow['name']);
  98              $resultThemelabel = decode_html($layoutresultrow['label']);
  99              $resultthemeparent = decode_html($layoutresultrow['parent']);
 100              
 101              if(!empty($resultThemename)){
 102                  $themeName = $resultThemename;
 103              }
 104              
 105              if(!empty($resultThemelabel)){
 106                  $themelabel = $resultThemename;
 107              }else{
 108                  $themelabel = $themeName;
 109              }
 110              
 111              if(!empty($resultthemeparent)){
 112                  $themeparent = $resultthemeparent;
 113              }else{
 114                  $themeparent = $layoutName;
 115              }
 116  
 117              $this->openNode('module');
 118              $this->outputNode(date('Y-m-d H:i:s'),'exporttime');
 119              $this->outputNode($themeName, 'name');
 120              $this->outputNode($themelabel, 'label');
 121              $this->outputNode($themeparent, 'parent');
 122  
 123              $this->outputNode('theme', 'type');
 124  
 125              // Export dependency information
 126              $this->export_Dependencies();
 127  
 128              $this->closeNode('module');
 129      }
 130  
 131      /**
 132       * Export vtiger dependencies
 133       * @access private
 134       */
 135      function export_Dependencies() {
 136              global $vtiger_current_version, $adb;
 137  
 138              $vtigerMinVersion = $vtiger_current_version;
 139              $vtigerMaxVersion = false;
 140  
 141              $this->openNode('dependencies');
 142              $this->outputNode($vtigerMinVersion, 'vtiger_version');
 143              if($vtigerMaxVersion !== false)    $this->outputNode($vtigerMaxVersion, 'vtiger_max_version');
 144              $this->closeNode('dependencies');
 145      }
 146  
 147  
 148      /**
 149       * Initialize Language Schema
 150       * @access private
 151       */
 152      static function __initSchema() {
 153              $hastable = Vtiger_Utils::CheckTable(self::TABLENAME);
 154              if(!$hastable) {
 155                      Vtiger_Utils::CreateTable(
 156                              self::TABLENAME,
 157                              '(id INT NOT NULL PRIMARY KEY,
 158                              name VARCHAR(50), label VARCHAR(30), parent VARCHAR(100), lastupdated DATETIME, isdefault INT(1), active INT(1))',
 159                              true
 160                      );
 161                      global $languages, $adb;
 162                      foreach($languages as $langkey=>$langlabel) {
 163                              $uniqueid = self::__getUniqueId();
 164                              $adb->pquery('INSERT INTO '.self::TABLENAME.'(id,name,label,parent,lastupdated,active) VALUES(?,?,?,?,?,?)',
 165                                      Array($uniqueid, $langlabel,$langkey,$langlabel,date('Y-m-d H:i:s',time()), 1));
 166                      }
 167              }
 168      }
 169  
 170      /**
 171       * Register language pack information.
 172       */
 173      static function register($label, $name='',$parent='', $isdefault=false, $isactive=true, $overrideCore=false) {
 174              self::__initSchema();
 175  
 176              $prefix = trim($prefix);
 177              // We will not allow registering core layouts unless forced
 178              if(strtolower($name) == 'vlayout' && $overrideCore == false) return;
 179  
 180              $useisdefault = ($isdefault)? 1 : 0;
 181              $useisactive  = ($isactive)?  1 : 0;
 182  
 183              global $adb;
 184              $checkres = $adb->pquery('SELECT * FROM '.self::TABLENAME.' WHERE name=?', Array($name));
 185              $datetime = date('Y-m-d H:i:s');
 186              if($adb->num_rows($checkres)) {
 187                      $id = $adb->query_result($checkres, 0, 'id');
 188                      $adb->pquery('UPDATE '.self::TABLENAME.' set label=?, name=?, parent=?, lastupdated=?, isdefault=?, active=? WHERE id=?',
 189                              Array($label, $name, $parent, $datetime, $useisdefault, $useisactive, $id));
 190              } else {
 191                      $uniqueid = self::__getUniqueId();
 192                      $adb->pquery('INSERT INTO '.self::TABLENAME.' (id,name,label,parent,lastupdated,isdefault,active) VALUES(?,?,?,?,?,?)',
 193                              Array($uniqueid, $name, $label, $parent, $datetime, $useisdefault, $useisactive));
 194              }
 195              self::log("Registering Language $label [$prefix] ... DONE");        
 196      }
 197  
 198  }


Generated: Fri Nov 28 20:08:37 2014 Cross-referenced by PHPXref 0.7.1