From 4192be6a6d91ce47ba47a05171497ae54d9e04e9 Mon Sep 17 00:00:00 2001
From: Lahmizzar Muinela <lahmizzar@devxive.com>
Date: Wed, 24 Apr 2013 16:01:50 -0400
Subject: [PATCH] adding minimum_perc for pulling translations

---
 install.script.php |   69 ++++++++++++++++++++++++++++------
 1 files changed, 56 insertions(+), 13 deletions(-)

diff --git a/install.script.php b/install.script.php
index 3ef55cb..dff2045 100644
--- a/install.script.php
+++ b/install.script.php
@@ -3,7 +3,7 @@
  * @package Projectfork
  * @subpackage Projectfork.Translations.Installer
  *
- * @copyright (C) 2006 - 2013 Projectfork Team. All rights reserved.
+ * @copyright (C) 2006 - 2013 Projectfork Translation Team. All rights reserved.
  * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL
  * @link http://www.projectfork.net
  **/
@@ -12,6 +12,7 @@
 class pkg_projectfork_languagesInstallerScript {
 	
 	protected $name = 'lang_pf4';
+	protected $uncomplete_lang = array("cs-CZ", "da-DK", "fa-IR", "fi-FI", "pt-PT", "sk-SK", "zh-TW", "ru-PO");
 	
 	public function uninstall($parent) {
 		$languages = JFactory::getLanguage()->getKnownLanguages();
@@ -21,38 +22,80 @@
 	}
 	
 	public function preflight($type, $parent) {
+		$lang = JFactory::getLanguage();
+		$lang->load('pkg_projectfork_languages', dirname(__FILE__) . '/installer', 'en-GB', true);
+		$lang->load('pkg_projectfork_languages', dirname(__FILE__) . '/installer', $lang->getTag(), true);
+		
 		if (!in_array($type, array('install', 'update'))) return true;
 		
 		$app = JFactory::getApplication();
 		
 		// Do not install if Projectfork 4 doesn't exist.
-//		if (!defined('PF_FRAMEWORK')) {
-//			$app->enqueueMessage(sprintf ( 'Projectfork %s has not been installed, aborting!', '4.x' ), 'notice');
-//			return false;
-//		}
-		
-			// Check the installed version of PF4 and the translation, give hints and tipps to do everything right!
+		$table = JTable::getInstance('extension');
+		$id = $table->find(array('type'=>'component', 'element'=>'com_projectfork'));
+		if($id) {
+			$app->enqueueMessage(sprintf(JText::_('PKG_PROJECTFORK_LANGUAGES_PFNOTINSTALLED'), '4.x'), 'error');
+			
+			$nopf_installed = '
+				<div style="display: inline-block;">
+					<div style="background: url(https://projectfork.net/templates/hydra/img/logo.png) no-repeat 50% 50% #698C00; height: 63px; width: 205px; border: 6px solid #567300; padding: 10px; border-top-left-radius: 5px; border-bottom-left-radius: 5px; float: left;"></div>
+					<div onclick="PFInstaller()" style="background-color: #698C00; cursor: pointer; height: 63px; border-width: 6px; border-style: solid; border-color: #567300; border-left: 0px; padding: 10px; color: white; font-size: 25px; line-height: 60px; float: left; text-indent: 0; text-align: center;">' . JText::_('PKG_PROJECTFORK_LANGUAGES_INSTALLNOW') . '</div>
+					<div onclick="PFDownload()" style="background-color: #42A9CA; cursor: pointer; height: 63px; border: 6px solid #2E88A5; padding: 10px; color: white; font-size: 25px; line-height: 60px; float: left; text-indent: 0; text-align: center;">' . JText::_('PKG_PROJECTFORK_LANGUAGES_DOWNLOAD_COMMUNITY') . '</div>
+					<div onclick="PFOrderPro()" style="background-color: #F7A700; cursor: pointer; height: 63px; border: 6px solid #BE8100; padding: 10px; color: white; font-size: 25px; line-height: 60px; float: left; text-indent: 0; text-align: center; border-top-right-radius: 5px; border-bottom-right-radius: 5px;">' . JText::_('PKG_PROJECTFORK_LANGUAGES_ORDER_PRO') . '</div>
+				</div>
+				<script type="text/javascript">
+					PFInstaller = function(pressbutton) {
+						var form = document.getElementById("adminForm");
+						form.install_url.value = "https://projectfork.net/downloads/projectfork-4/projectfork-4-4-0-0/pkgprojectfork4-0-0-zip?format=raw";
+						Joomla.submitbutton4();
+					}					
+					PFDownload = function(pressbutton) {
+						window.open("https://projectfork.net","_blank");
+					}					
+					PFOrderPro = function(pressbutton) {
+						window.open("https://projectfork.net/pro","_blank");
+					}					
+				</script>
+			';
+			$app->enqueueMessage($nopf_installed, 'notice');
+			return false;
+		}
 		
 		// Get list of languages to be installed. Only installs languages that are found in your system.
-		$source = $parent->getParent()->getPath('source').'/language';
+		$source = $parent->getParent()->getPath('source').'/languages';
 		$languages = JFactory::getLanguage()->getKnownLanguages();
 		
 		$files = $parent->manifest->files;
+		$installed_langs_html = '<div style="inline-block;"><ul>';
+		
 		foreach ($languages as $language) {
 			$search = JFolder::folders($source, $language['tag']); // no .zip files use "folders" instead
 			if (empty($search)) continue;
 			
-			// Generate something like <file type="file" client="site" id="com_kunena_fi-FI">com_kunena_fi-FI_v2.0.0.zip</file>
+			// Generate something like <file type="file" id="lang_pf4_en-GB">en-GB</file>
 			$file = $files->addChild('file', array_pop($search));
 			$file->addAttribute('type', 'file');
-			$file->addAttribute('id', $this->name.'_'.$language['tag']);
-			echo sprintf('Installing language %s - %s ...', $language['tag'], $language['name']) . '<br />';
+			$file->addAttribute('id', $this->name . '_' . $language['tag']);
+			$installed_langs_html .= '<li>' . sprintf('<b>%s - %s</b>', $language['tag'], $language['name']);
+			if(in_array($language['tag'], $this->uncomplete_lang)) {
+				$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>') . ')';
+			}
+			$installed_langs_html .= '</li>';
 		}
+		$installed_langs_html .= '</ul></div>';
 		
 		if (empty($files)) {
 			// No packages to install: replace failure message with something that's more descriptive.
-			$app->enqueueMessage(sprintf ( 'Your site is English only. There\'s no need to install a Projectfork Language Pack!' ), 'notice');
+			$app->enqueueMessage(sprintf(JText::_('PKG_PROJECTFORK_LANGUAGES_ENGLISH_ONLY')), 'notice');
 			return false;
+		} else {
+			// Override XML-DIV-NOPF-Installer-Placeholder if PF is installed
+			$success_html_output = '<div style="display: inline-block; margin-bottom: 25px;">';
+			$success_html_output .= '<div style="background: url(https://projectfork.net/templates/hydra/img/logo.png) no-repeat 50% 50% #698C00; height: 63px; width: 205px; border: 6px solid #567300; padding: 10px; border-top-left-radius: 5px; border-bottom-left-radius: 5px; float: left;"></div>';
+			$success_html_output .= '<div style="background-color: #698C00; height: 63px; border-width: 6px; border-style: solid; border-color: #567300; border-left: 0px; padding: 10px; color: white; font-size: 25px; line-height: 60px; float: left; text-indent: 0; text-align: center; border-top-right-radius: 5px; border-bottom-right-radius: 5px;">' . JText::_('PKG_PROJECTFORK_LANGUAGES_INSTALLED_DETECTED') . '</div>';
+			$success_html_output .= '</div>';
+			echo $success_html_output;
+			echo $installed_langs_html;
 		}
 		
 		return true;
@@ -61,7 +104,7 @@
 	public function uninstallLanguage($tag, $name) {
 		$table = JTable::getInstance('extension');
 		$id = $table->find(array('type'=>'file', 'element'=>"{$this->name}_{$tag}"));
-		if (!$id) return;
+		if(!$id) return;
 		
 		$installer = new JInstaller();
 		$installer->uninstall ( 'file', $id );

--
Gitblit v1.9.1