PageRenderTime 47ms CodeModel.GetById 22ms RepoModel.GetById 1ms app.codeStats 0ms

/vtlib/Vtiger/LanguageImport.php

https://bitbucket.org/yousef_fadila/vtiger
PHP | 138 lines | 78 code | 21 blank | 39 comment | 21 complexity | fb78c5eff98e788e292f4cb31de16a4b MD5 | raw file
Possible License(s): LGPL-2.1, GPL-2.0
  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/LanguageExport.php');
  11. /**
  12. * Provides API to import language into vtiger CRM
  13. * @package vtlib
  14. */
  15. class Vtiger_LanguageImport extends Vtiger_LanguageExport {
  16. /**
  17. * Constructor
  18. */
  19. function __construct() {
  20. parent::__construct();
  21. }
  22. function getPrefix() {
  23. return (string)$this->_modulexml->prefix;
  24. }
  25. /**
  26. * Initialize Import
  27. * @access private
  28. */
  29. function initImport($zipfile, $overwrite) {
  30. $this->__initSchema();
  31. $name = $this->getModuleNameFromZip($zipfile);
  32. }
  33. /**
  34. * Import Module from zip file
  35. * @param String Zip file name
  36. * @param Boolean True for overwriting existing module
  37. */
  38. function import($zipfile, $overwrite=false) {
  39. $this->initImport($zipfile, $overwrite);
  40. // Call module import function
  41. $this->import_Language($zipfile);
  42. }
  43. /**
  44. * Update Module from zip file
  45. * @param Object Instance of Language (to keep Module update API consistent)
  46. * @param String Zip file name
  47. * @param Boolean True for overwriting existing module
  48. */
  49. function update($instance, $zipfile, $overwrite=true) {
  50. $this->import($zipfile, $overwrite);
  51. }
  52. /**
  53. * Import Module
  54. * @access private
  55. */
  56. function import_Language($zipfile) {
  57. $name = $this->_modulexml->name;
  58. $prefix = $this->_modulexml->prefix;
  59. $label = $this->_modulexml->label;
  60. self::log("Importing $label [$prefix] ... STARTED");
  61. $unzip = new Vtiger_Unzip($zipfile);
  62. $filelist = $unzip->getList();
  63. foreach($filelist as $filename=>$fileinfo) {
  64. if(!$unzip->isdir($filename)) {
  65. if(strpos($filename, '/') === false) continue;
  66. $targetdir = substr($filename, 0, strripos($filename,'/'));
  67. $targetfile = basename($filename);
  68. $prefixparts = split('_', $prefix);
  69. $dounzip = false;
  70. if(is_dir($targetdir)) {
  71. // Case handling for jscalendar
  72. if(stripos($targetdir, 'jscalendar/lang') === 0
  73. && stripos($targetfile, "calendar-".$prefixparts[0].".js")===0) {
  74. if(file_exists("$targetdir/calendar-en.js")) {
  75. $dounzip = true;
  76. }
  77. }
  78. // Case handling for phpmailer
  79. else if(stripos($targetdir, 'modules/Emails/language') === 0
  80. && stripos($targetfile, "phpmailer.lang-$prefix.php")===0) {
  81. if(file_exists("$targetdir/phpmailer.lang-en_us.php")) {
  82. $dounzip = true;
  83. }
  84. }
  85. // Handle javascript language file
  86. else if(preg_match("/$prefix.lang.js/", $targetfile)) {
  87. $corelangfile = "$targetdir/en_us.lang.js";
  88. if(file_exists($corelangfile)) {
  89. $dounzip = true;
  90. }
  91. }
  92. // Handle php language file
  93. else if(preg_match("/$prefix.lang.php/", $targetfile)) {
  94. $corelangfile = "$targetdir/en_us.lang.php";
  95. if(file_exists($corelangfile)) {
  96. $dounzip = true;
  97. }
  98. }
  99. }
  100. if($dounzip) {
  101. if($unzip->unzip($filename, $filename) !== false) {
  102. self::log("Copying file $filename ... DONE");
  103. } else {
  104. self::log("Copying file $filename ... FAILED");
  105. }
  106. } else {
  107. self::log("Copying file $filename ... SKIPPED");
  108. }
  109. }
  110. }
  111. if($unzip) $unzip->close();
  112. self::register($prefix, $label, $name);
  113. self::log("Importing $label [$prefix] ... DONE");
  114. return;
  115. }
  116. }
  117. ?>