Lahmizzar Muinela
2014-03-09 fba4b32268522ece0edb6305110e75dcc66eee58
commit | author | age
66fc58 1 <?php
LM 2 /**
3  * @package Projectfork
4  * @subpackage Projectfork.Translations.Installer
5  *
fba4b3 6  * @copyright (C) 2012 - 2014 Projectfork Translation Team. All rights reserved.
66fc58 7  * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL
LM 8  * @link http://www.projectfork.net
9  **/
10 defined( '_JEXEC' ) or die();
11
12 class pkg_projectfork_languagesInstallerScript {
13     
14     protected $name = 'lang_pf4';
c7576f 15     protected $uncomplete_lang = array("da-DK", "fr-FR", "hu-HU", "pt-BR", "es-ES", "tr-TR", "nb-NO", "pl-PL", "ca-ES", "zh-TW", "nl-NL", "it-IT", "ja-JP", "ro-RO", "th-TH", "ru-RU", "el-GR", "cs-CZ", "pt-PT", "sv-SE", "sk-SK", "uk-UA", "nl-BE", "bg-BG", "fa-IR", "es-MX", "ar-AA");
66fc58 16     
LM 17     public function uninstall($parent) {
18         $languages = JFactory::getLanguage()->getKnownLanguages();
19         foreach ($languages as $language) {
20             echo $this->uninstallLanguage($language['tag'], $language['name']);
21         }
22     }
23     
24     public function preflight($type, $parent) {
686e50 25         $lang = JFactory::getLanguage();
LM 26         $lang->load('pkg_projectfork_languages', dirname(__FILE__) . '/installer', 'en-GB', true);
27         $lang->load('pkg_projectfork_languages', dirname(__FILE__) . '/installer', $lang->getTag(), true);
28         
66fc58 29         if (!in_array($type, array('install', 'update'))) return true;
LM 30         
31         $app = JFactory::getApplication();
32         
33         // Do not install if Projectfork 4 doesn't exist.
d0edc0 34         $table = JTable::getInstance('extension');
LM 35         $id = $table->find(array('type'=>'component', 'element'=>'com_projectfork'));
75a35a 36         if(!$id) {
686e50 37             $app->enqueueMessage(sprintf(JText::_('PKG_PROJECTFORK_LANGUAGES_PFNOTINSTALLED'), '4.x'), 'error');
d0edc0 38             return false;
LM 39         }
66fc58 40         
LM 41         // Get list of languages to be installed. Only installs languages that are found in your system.
c3405e 42         $source = $parent->getParent()->getPath('source').'/languages';
66fc58 43         $languages = JFactory::getLanguage()->getKnownLanguages();
LM 44         
45         $files = $parent->manifest->files;
75a35a 46         $installed_langs_html = '<ul>';
686e50 47         
66fc58 48         foreach ($languages as $language) {
LM 49             $search = JFolder::folders($source, $language['tag']); // no .zip files use "folders" instead
50             if (empty($search)) continue;
51             
d0edc0 52             // Generate something like <file type="file" id="lang_pf4_en-GB">en-GB</file>
66fc58 53             $file = $files->addChild('file', array_pop($search));
LM 54             $file->addAttribute('type', 'file');
d0edc0 55             $file->addAttribute('id', $this->name . '_' . $language['tag']);
4db6bd 56             $installed_langs_html .= '<li>' . sprintf('<b>%s</b> - %s', $language['tag'], $language['name']);
d0edc0 57             if(in_array($language['tag'], $this->uncomplete_lang)) {
686e50 58                 $installed_langs_html .= ' ... <span style="color: darkorange;">(' . sprintf(JText::_('PKG_PROJECTFORK_LANGUAGES_NOTFULL_TRANSLATED'), '<a href="https://github.com/projectfork/Translations/wiki" target="_blank">Projectfork Translations Team</a>') . ')';
d0edc0 59             }
686e50 60             $installed_langs_html .= '</li>';
66fc58 61         }
75a35a 62         $installed_langs_html .= '</ul>';
66fc58 63         
LM 64         if (empty($files)) {
75a35a 65             // No packages to install
686e50 66             $app->enqueueMessage(sprintf(JText::_('PKG_PROJECTFORK_LANGUAGES_ENGLISH_ONLY')), 'notice');
66fc58 67             return false;
686e50 68         } else {
75a35a 69             // Package was installation successfull with detected languages
LM 70             echo JText::_('PKG_PROJECTFORK_LANGUAGES_INSTALLED_DETECTED_SUCCESS') . $installed_langs_html;
66fc58 71         }
LM 72         
73         return true;
74     }
75     
76     public function uninstallLanguage($tag, $name) {
77         $table = JTable::getInstance('extension');
78         $id = $table->find(array('type'=>'file', 'element'=>"{$this->name}_{$tag}"));
d0edc0 79         if(!$id) return;
66fc58 80         
LM 81         $installer = new JInstaller();
82         $installer->uninstall ( 'file', $id );
83     }
84 }