PageRenderTime 37ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 1ms

/trunk/jfx-private/modules/core/actions/lang/install.php

http://jfxcms.googlecode.com/
PHP | 163 lines | 115 code | 28 blank | 20 comment | 16 complexity | ba8b717b420a2ebded1f57c8150f20a1 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1
  1. <?php
  2. ############### COPYLEFT GPLv3 LICENSE ###############
  3. ##
  4. ## JFX Version 0.2.9
  5. ## Website Management Software
  6. ## www.jfxcms.com
  7. ##
  8. ## Copyright 2009 GPLv3 - http://www.opensource.org/licenses/gpl-3.0.html
  9. ##
  10. ## Anthony Gallon
  11. ## oi_antz@hotmail.com
  12. ##
  13. ## Permission is hereby granted to any person having a copy of this software
  14. ## to freely use and modify as required so long as the copyright notices
  15. ## and branding remain intact.
  16. ##
  17. ## Full license details available at http://www.jfxcms.com/license
  18. ##
  19. ############### COPYLEFT GPLv3 LICENSE ###############
  20. $THEME->addBreadcrumb($this->adminUrl.'/lang/install/', $this->lang('ap_title_lang_install'));
  21. if(Antz_IntelliForm::submitted('new-language-form')){
  22. $error = false;
  23. $newKeyname = post('keyname');
  24. $copyLang = post('copyLang');
  25. if(strlen(trim($newKeyname))==0){
  26. $error = true;
  27. JFX::addError($this->lang('iso_blank_error'));
  28. JFX::addFormError('keyname');
  29. }
  30. $newKeyname = $DB->escape($newKeyname);
  31. if($DB->countRows($CONFIG->dbprefix.'languages', "keyname = '{$newKeyname}'")>0){
  32. $error = true;
  33. JFX::addError($this->lang('iso_already_used'));
  34. JFX::addFormError('keyname');
  35. }
  36. $copyLang = $DB->escape($copyLang);
  37. if($DB->countRows($CONFIG->dbprefix.'languages', "keyname = '{$copyLang}'")==0){
  38. $error = true;
  39. JFX::addError($this->lang('invalid_language'));
  40. JFX::addFormError('copyLang');
  41. }
  42. if(!$error){
  43. $flagDir = $CONFIG->imagesDir.'/flags/'.$newKeyname;
  44. if(isset($_FILES['small_img']) && file_exists($_FILES['small_img']['tmp_name'])){
  45. $fileinfo = fileinfo($_FILES['small_img']['tmp_name']);
  46. $ext = $fileinfo['extension'];
  47. $newFilename = $flagDir.'/small.'.$ext;
  48. copy($_FILES['small_img']['tmp_name'], $newFilename);
  49. JFX_Image::resize($newFilename, $JFX_LANG_IMAGE_SIZES['small']['width'], $JFX_LANG_IMAGE_SIZES['small']['height']);
  50. }
  51. if(isset($_FILES['med_img']) && file_exists($_FILES['med_img']['tmp_name'])){
  52. $fileinfo = fileinfo($_FILES['med_img']['tmp_name']);
  53. $ext = $fileinfo['extension'];
  54. $newFilename = $flagDir.'/medium.'.$ext;
  55. copy($_FILES['med_img']['tmp_name'], $newFilename);
  56. JFX_Image::resize($newFilename, $JFX_LANG_IMAGE_SIZES['med']['width'], $JFX_LANG_IMAGE_SIZES['med']['height']);
  57. }
  58. if(isset($_FILES['large_img']) && file_exists($_FILES['large_img']['tmp_name'])){
  59. $fileinfo = fileinfo($_FILES['large_img']['tmp_name']);
  60. $ext = $fileinfo['extension'];
  61. $newFilename = $flagDir.'/large.'.$ext;
  62. copy($_FILES['large_img']['tmp_name'], $newFilename);
  63. JFX_Image::resize($newFilename, $JFX_LANG_IMAGE_SIZES['large']['width'], $JFX_LANG_IMAGE_SIZES['large']['height']);
  64. }
  65. if(isset($_FILES['xtra_img']) && file_exists($_FILES['xtra_img']['tmp_name'])){
  66. $fileinfo = fileinfo($_FILES['xtra_img']['tmp_name']);
  67. $ext = $fileinfo['extension'];
  68. $newFilename = $flagDir.'/extra-large.'.$ext;
  69. copy($_FILES['xtra_img']['tmp_name'], $newFilename);
  70. JFX_Image::resize($newFilename, $JFX_LANG_IMAGE_SIZES['xtra']['width'], $JFX_LANG_IMAGE_SIZES['xtra']['height']);
  71. }
  72. $dbParams = array(
  73. 'keyname' => $newKeyname,
  74. 'is_active' => 1,
  75. 'flag_extension' => $ext,
  76. 'is_default' => 0
  77. );
  78. $DB->insert($CONFIG->dbprefix.'languages', $dbParams);
  79. // now we do the heavy lifting
  80. set_time_limit(0);
  81. $sysLangs = $DB->fetchAll("SELECT * FROM {$CONFIG->dbprefix}lang_system WHERE lang = '{$copyLang}'");
  82. foreach($sysLangs as $k=>$v){
  83. $v['lang'] = $newKeyname;
  84. $DB->insert($CONFIG->dbprefix.'lang_system', $v);
  85. };
  86. // lets break this next task into groups of module type and workspace id
  87. $workspaces = $DB->fetchAll("SELECT * FROM {$CONFIG->dbprefix}workspaces");
  88. $modules = array();
  89. $dh = opendir($CONFIG->modulesDir);
  90. while($file = readdir($dh)){
  91. if($file=='.' || $file=='..' || !is_dir($CONFIG->modulesDir.'/'.$file)) continue;
  92. $modules[] = $file;
  93. }
  94. foreach($workspaces as $ws){
  95. $wsid = $ws['id'];
  96. foreach($modules as $module){
  97. $langContent = $DB->fetchAll("SELECT * FROM {$CONFIG->dbprefix}lang_content WHERE lang = '{$copyLang}' AND workspace_id = '{$wsid}' AND module_key = '{$module}'");
  98. foreach($langContent as $k=>$v){
  99. $v['lang'] = $newKeyname;
  100. $DB->insert($CONFIG->dbprefix.'lang_content', $v);
  101. }
  102. }
  103. }
  104. unset($langContent, $workspaces, $modules);
  105. JFX::addSuccess($this->lang('language_copy_success'));
  106. JFX::redirect($CONFIG->adminUrl.'/lang/translate/?lang='.$newKeyname);
  107. }
  108. }
  109. $langs = $DB->fetchAll("SELECT * FROM {$CONFIG->dbprefix}languages ORDER BY keyname ASC");
  110. $copyLangOpts = array();
  111. foreach($langs as $k=>$v){
  112. $copyLangOpts[$v['keyname']] = $v['keyname'];
  113. }
  114. $newLangFormFields = array(
  115. array(
  116. 'type' => 'text',
  117. 'name' => 'keyname',
  118. 'value' => post('keyname', 'en_US'),
  119. 'label' => $this->lang('new_language_iso')
  120. ),
  121. array(
  122. 'type' => 'select',
  123. 'name' => 'copyLang',
  124. 'label' => $this->lang('new_language_origin'),
  125. 'options' => $copyLangOpts,
  126. 'value' => post('copyLang', 'en_US')
  127. ),
  128. array(
  129. 'type' => 'submit',
  130. 'label' => '&nbsp;',
  131. 'value' => $this->lang('new_language_submit')
  132. )
  133. );
  134. $newLangForm = JFX::makeRapidForm($newLangFormFields, $this->lang('new_language_legend'), 'new-language-form');
  135. echo $newLangForm;