[ Index ]

PHP Cross Reference of vtigercrm-6.1.0

title

Body

[close]

/vtlib/Vtiger/ -> LanguageExport.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_LanguageExport extends Vtiger_Package {
  17  
  18      const TABLENAME = 'vtiger_language';
  19  
  20      /**
  21       * Constructor
  22       */
  23  	function __construct() {
  24          parent::__construct();
  25      }
  26  
  27      /**
  28       * Generate unique id for insertion
  29       * @access private
  30       */
  31  	static function __getUniqueId() {
  32          global $adb;
  33          return $adb->getUniqueID(self::TABLENAME);
  34      }
  35      
  36      /**
  37       * Initialize Export
  38       * @access private
  39       */
  40  	function __initExport($languageCode) {
  41          // Security check to ensure file is withing the web folder.
  42          Vtiger_Utils::checkFileAccessForInclusion("languages/$languageCode/Vtiger.php");
  43          
  44          $this->_export_modulexml_file = fopen($this->__getManifestFilePath(), 'w');
  45          $this->__write("<?xml version='1.0'?>\n");
  46      }
  47      
  48      /**
  49       * Export Module as a zip file.
  50       * @param Vtiger_Module Instance of module
  51       * @param Path Output directory path
  52       * @param String Zipfilename to use
  53       * @param Boolean True for sending the output as download
  54       */
  55  	function export($languageCode, $todir='', $zipfilename='', $directDownload=false) {
  56  
  57          $this->__initExport($languageCode);
  58          
  59          // Call language export function
  60          $this->export_Language($languageCode);
  61  
  62          $this->__finishExport();
  63          
  64          // Export as Zip
  65          if($zipfilename == '') $zipfilename = "$languageCode-" . date('YmdHis') . ".zip";
  66          $zipfilename = "$this->_export_tmpdir/$zipfilename";
  67  
  68          $zip = new Vtiger_Zip($zipfilename);
  69  
  70          // Add manifest file
  71          $zip->addFile($this->__getManifestFilePath(), "manifest.xml");
  72  
  73          // Copy module directory
  74          $zip->copyDirectoryFromDisk("languages/$languageCode", "modules");
  75  
  76          $zip->save();
  77  
  78          if($todir) {
  79              copy($zipfilename, $todir);
  80          }
  81  
  82          if($directDownload) {
  83              $zip->forceDownload($zipfilename);
  84              unlink($zipfilename);
  85          }
  86          $this->__cleanupExport();
  87      }
  88      
  89      /**
  90       * Export Language Handler
  91       * @access private
  92       */
  93  	function export_Language($prefix) {
  94          global $adb;
  95  
  96          $sqlresult = $adb->pquery("SELECT * FROM vtiger_language WHERE prefix = ?", array($prefix));
  97          $languageresultrow = $adb->fetch_array($sqlresult);
  98  
  99          $langname  = decode_html($languageresultrow['name']);
 100          $langlabel = decode_html($languageresultrow['label']);
 101  
 102          $this->openNode('module');
 103          $this->outputNode(date('Y-m-d H:i:s'),'exporttime');
 104          $this->outputNode($langname, 'name');
 105          $this->outputNode($langlabel, 'label');
 106          $this->outputNode($prefix, 'prefix');
 107  
 108          $this->outputNode('language', 'type');
 109  
 110          // Export dependency information
 111          $this->export_Dependencies($moduleInstance);
 112  
 113          $this->closeNode('module');
 114      }
 115      
 116      /**
 117       * Export vtiger dependencies
 118       * @access private
 119       */
 120  	function export_Dependencies() {
 121          global $vtiger_current_version, $adb;
 122  
 123          $vtigerMinVersion = $vtiger_current_version;
 124          $vtigerMaxVersion = false;
 125  
 126          $this->openNode('dependencies');
 127          $this->outputNode($vtigerMinVersion, 'vtiger_version');
 128          if($vtigerMaxVersion !== false)    $this->outputNode($vtigerMaxVersion, 'vtiger_max_version');
 129          $this->closeNode('dependencies');
 130      }
 131  
 132  
 133      /**
 134       * Initialize Language Schema
 135       * @access private
 136       */
 137  	static function __initSchema() {
 138          $hastable = Vtiger_Utils::CheckTable(self::TABLENAME);
 139          if(!$hastable) {
 140              Vtiger_Utils::CreateTable(
 141                  self::TABLENAME,
 142                  '(id INT NOT NULL PRIMARY KEY,
 143                  name VARCHAR(50), prefix VARCHAR(10), label VARCHAR(30), lastupdated DATETIME, sequence INT, isdefault INT(1), active INT(1))',
 144                  true
 145              );
 146              global $languages, $adb;
 147              foreach($languages as $langkey=>$langlabel) {
 148                  $uniqueid = self::__getUniqueId();
 149                  $adb->pquery('INSERT INTO '.self::TABLENAME.'(id,name,prefix,label,lastupdated,active) VALUES(?,?,?,?,?,?)',
 150                      Array($uniqueid, $langlabel,$langkey,$langlabel,date('Y-m-d H:i:s',time()), 1));
 151              }
 152          }
 153      }
 154  
 155      /**
 156       * Register language pack information.
 157       */
 158  	static function register($prefix, $label, $name='', $isdefault=false, $isactive=true, $overrideCore=false) {
 159          self::__initSchema();
 160  
 161          $prefix = trim($prefix);
 162          // We will not allow registering core language unless forced
 163          if(strtolower($prefix) == 'en_us' && $overrideCore == false) return;
 164  
 165          $useisdefault = ($isdefault)? 1 : 0;
 166          $useisactive  = ($isactive)?  1 : 0;
 167  
 168          global $adb;
 169          $checkres = $adb->pquery('SELECT * FROM '.self::TABLENAME.' WHERE prefix=?', Array($prefix));
 170          $datetime = date('Y-m-d H:i:s');
 171          if($adb->num_rows($checkres)) {
 172              $id = $adb->query_result($checkres, 0, 'id');
 173              $adb->pquery('UPDATE '.self::TABLENAME.' set label=?, name=?, lastupdated=?, isdefault=?, active=? WHERE id=?',
 174                  Array($label, $name, $datetime, $useisdefault, $useisactive, $id));
 175          } else {
 176              $uniqueid = self::__getUniqueId();
 177              $adb->pquery('INSERT INTO '.self::TABLENAME.' (id,name,prefix,label,lastupdated,isdefault,active) VALUES(?,?,?,?,?,?,?)',
 178                  Array($uniqueid, $name, $prefix, $label, $datetime, $useisdefault, $useisactive));
 179          }
 180          self::log("Registering Language $label [$prefix] ... DONE");        
 181      }
 182  
 183      /**
 184       * De-Register language pack information
 185       * @param String Language prefix like (de_de) etc
 186       */
 187  	static function deregister($prefix) {
 188          $prefix = trim($prefix);
 189          // We will not allow deregistering core language
 190          if(strtolower($prefix) == 'en_us') return;
 191  
 192          self::__initSchema();
 193  
 194          global $adb;
 195          $checkres = $adb->pquery('DELETE FROM '.self::TABLENAME.' WHERE prefix=?', Array($prefix));
 196          self::log("Deregistering Language $prefix ... DONE");
 197      }
 198  
 199      /**
 200       * Get all the language information
 201       * @param Boolean true to include in-active languages also, false (default)
 202       */
 203  	static function getAll($includeInActive=false) {
 204          global $adb;
 205          $hastable = Vtiger_Utils::CheckTable(self::TABLENAME);
 206  
 207          $languageinfo = Array();
 208  
 209          if($hastable) {
 210              if($includeInActive) $result = $adb->pquery('SELECT * FROM '.self::TABLENAME, array());
 211              else $result = $adb->pquery('SELECT * FROM '.self::TABLENAME . ' WHERE active=?', array(1));
 212  
 213              for($index = 0; $index < $adb->num_rows($result); ++$index) {
 214                  $resultrow = $adb->fetch_array($result);
 215                  $prefix = $resultrow['prefix'];
 216                  $label  = $resultrow['label'];
 217                  $languageinfo[$prefix] = $label;
 218              }
 219          } else {
 220              global $languages;
 221              foreach($languages as $prefix=>$label) {
 222                  $languageinfo[$prefix] = $label;
 223              }
 224          }
 225          return $languageinfo;
 226      }
 227  }
 228  ?>


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