Your IP : 216.73.216.240
<?php
/**
* @package FFGate
* @author Yves Hoppe <yves@compojoom.com>
* @date 26.11.13
*
* @copyright Copyright (C) 2008 - 2013 compojoom.com - Yves Hoppe. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
defined('_JEXEC') or die('Restricted access');
/**
* Script file of Cnotes component
*
* @since 1.0.0
*/
class Com_FFgateInstallerScript extends CompojoomInstaller
{
/*
* The release value to be displayed and checked against throughout this file.
*/
public $release = '3.0';
public $minimum_joomla_release = '2.5';
public $extension = 'com_ffgate';
private $type = '';
private $installationQueue = array(
'modules' => array(
'admin' => array(
"mod_ccc_ffgate_icons" => array('ccc_ffgate_left', 1),
"mod_ccc_ffgate_newsfeed" => array('ccc_ffgate_slider', 1),
"mod_ccc_ffgate_update" => array('ccc_ffgate_slider', 1),
"mod_ccc_ffgate_overview" => array('ccc_ffgate_slider', 1),
"mod_ccc_ffgate_promotion" => array('ccc_ffgate_promotion', 1),
)
),
'plugins' => array()
);
/**
* method to uninstall the component
*
* @param object $parent - The parent obj
*
* @return void
*/
public function uninstall($parent)
{
$this->type = 'uninstall';
$this->parent = $parent;
$this->status->plugins = $this->uninstallPlugins($this->installationQueue['plugins']);
$this->status->modules = $this->uninstallModules($this->installationQueue['modules']);
echo $this->displayInfoUninstallation();
}
/**
* method to run after an install/update/discover method
*
* @param int $type - The type
* @param object $parent - The parent
*
* @return void
*/
public function postflight($type, $parent)
{
$this->loadLanguage();
// Let us install the modules
$this->status->plugins = $this->installPlugins($this->installationQueue['plugins']);
$this->status->modules = $this->installModules($this->installationQueue['modules']);
// Todo add update / reinstall check
$this->settingsContent();
echo $this->displayInfoInstallation();
}
/**
* Inserts the settings content into the database
*
* @param boolean $reset - Is this called from the installation
*
* @return void
*/
public function settingsContent($reset = false)
{
$db = JFactory::getDbo();
$query = "INSERT INTO `#__ffgate_settings` (`id`, `title`, `value`, `values`, `type`, `catdisp`) VALUES
(1, 'loadMootools', '1', '', 'bool', 'advanced'),
(2, 'showPoweredby', '1', '', 'bool', 'layout'),
(3, 'db_version', '1.1.2', '', 'text', 'hidden'),
(4, 'shareButton', '0', '', 'bool', 'layout'),
(5, 'disableScrolls', '1', '', 'bool', 'layout'),
(6, 'snowEffect', '0', '', 'bool', 'layout')
;";
$db->setQuery($query);
$rs = $db->execute();
if (!$reset)
{
$this->status->sql['#__ffgate_settings'] = $rs;
}
else
{
return $rs;
}
}
/**
* Displays the install informations
*
* @return string
*/
private function displayInfoInstallation()
{
$html[] = '<div class="header">' . JText::_('COM_FFGATE_INSTALLATION_SUCCESS') . '</div>';
$html[] = "<table class=\"table\" border=\"0\" width=\"100%\"><tbody>";
$html[] = "<tr><td width=\"18%\"><b>Extension:</b></td><td width=\"80%\">FFGate 1.1.0</td></tr>";
$html[] = "<tr><td width=\"18%\"><b>Copyright:</b></td><td width=\"80%\">Compojoom.com - Yves Hoppe</td></tr>";
$html[] = "<tr><td width=\"18%\"><b>Web:</b></td><td width=\"80%\"><a target=\"_blank\" href=\"http://compojoom.com\">http://compojoom.com</a></td></tr>";
$html[] = "<tr><td colspan=\"2\">";
$html[] = "<br /><strong>Thank you for installing FFGate!</strong><br /><br />";
$html[] .= '<p>To get the latest news and promotions:<br />
Like us on Facebook: <iframe src="//www.facebook.com/plugins/like.php?href=http%3A%2F%2Ffacebook.com%2Fcompojoom&send=false&layout=button_count&width=450&show_faces=true&font&colorscheme=light&action=like&height=21&appId=119257468194823"
scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:450px; height:21px;" allowTransparency="true"></iframe>
<br />Follow us on Twitter: <a href="https://twitter.com/compojoom" class="twitter-follow-button" data-show-count="false">Follow @compojoom</a>
<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="//platform.twitter.com/widgets.js";
fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script><br /><br />';
$html[] = "</td>";
$html[] = "</tr></tbody></table>";
if ($this->status->plugins)
{
$html[] = $this->renderPluginInfoInstall($this->status->plugins);
}
if ($this->status->modules)
{
$html[] = $this->renderModuleInfoInstall($this->status->modules);
}
return implode('', $html);
}
/**
* Displays the uninstall information
*
* @return string
*/
public function displayInfoUninstallation()
{
$html[] = $this->renderPluginInfoUninstall($this->status->plugins);
$html[] = $this->renderModuleInfoUninstall($this->status->modules);
return implode('', $html);
}
}
/**
* Class CompojoomInstaller
*
* @since 1.0.0
*/
class CompojoomInstaller
{
/**
* Loads the language
*
* @return void
*/
public function loadLanguage()
{
$extension = $this->extension;
$jlang = JFactory::getLanguage();
$path = $this->parent->getParent()->getPath('source') . '/administrator';
$jlang->load($extension, $path, 'en-GB', true);
$jlang->load($extension, $path, $jlang->getDefault(), true);
$jlang->load($extension, $path, null, true);
$jlang->load($extension . '.sys', $path, 'en-GB', true);
$jlang->load($extension . '.sys', $path, $jlang->getDefault(), true);
$jlang->load($extension . '.sys', $path, null, true);
}
/**
* The joomla framework doesn't tell us if the component has tables filled with data
*
* @return boolean
*/
private function newInstall()
{
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query->select('COUNT(*) as count')->from('#__ffgate_settings');
$db->setQuery($query);
if ($db->loadObject()->count)
{
return false;
}
return true;
}
/**
* Installs the module
*
* @param array $modulesToInstall - Modules to install
*
* @return array - Status
*/
public function installModules($modulesToInstall)
{
$src = $this->parent->getParent()->getPath('source');
$status = array();
// Modules installation
if (count($modulesToInstall))
{
foreach ($modulesToInstall as $folder => $modules)
{
if (count($modules))
{
foreach ($modules as $module => $modulePreferences)
{
// Install the module
if (empty($folder))
{
$folder = 'site';
}
$path = "$src/modules/$module";
if ($folder == 'admin')
{
$path = "$src/administrator/modules/$module";
}
if (!is_dir($path))
{
continue;
}
$db = JFactory::getDbo();
// Was the module alrady installed?
$sql = 'SELECT COUNT(*) FROM #__modules WHERE `module`=' . $db->Quote($module);
$db->setQuery($sql);
$count = $db->loadResult();
$installer = new JInstaller;
$result = $installer->install($path);
$status[] = array('name' => $module, 'client' => $folder, 'result' => $result);
// Modify where it's published and its published state
if (!$count)
{
list($modulePosition, $modulePublished) = $modulePreferences;
$sql = "UPDATE #__modules SET position=" . $db->Quote($modulePosition);
if ($modulePublished)
{
$sql .= ', published=1';
}
$sql .= ', params = ' . $db->quote($installer->getParams());
$sql .= ' WHERE `module`=' . $db->Quote($module);
$db->setQuery($sql);
$db->query();
// Get module id
$db->setQuery('SELECT id FROM #__modules WHERE module = ' . $db->quote($module));
$moduleId = $db->loadObject()->id;
// Insert the module on all pages, otherwise we can't use it
$query = 'INSERT INTO #__modules_menu(moduleid, menuid) VALUES (' . $db->quote($moduleId) . ' ,0 );';
$db->setQuery($query);
$db->query();
}
}
}
}
}
return $status;
}
/**
* Uninstalls the modules
*
* @param array $modulesToUninstall - Modules to uninstall
*
* @return array
*/
public function uninstallModules($modulesToUninstall)
{
$status = array();
if (count($modulesToUninstall))
{
$db = JFactory::getDbo();
foreach ($modulesToUninstall as $folder => $modules)
{
if (count($modules))
{
foreach ($modules as $module => $modulePreferences)
{
// Find the module ID
$db->setQuery('SELECT `extension_id` FROM #__extensions WHERE `element` = '
. $db->Quote($module) . ' AND `type` = "module"');
$id = $db->loadResult();
// Uninstall the module
$installer = new JInstaller;
$result = $installer->uninstall('module', $id, 1);
$status[] = array('name' => $module, 'client' => $folder, 'result' => $result);
}
}
}
}
return $status;
}
/**
* Installs the plugins
*
* @param array $plugins - The plugins
*
* @return array
*/
public function installPlugins($plugins)
{
$src = $this->parent->getParent()->getPath('source');
$db = JFactory::getDbo();
$status = array();
foreach ($plugins as $plugin => $published)
{
$parts = explode('_', $plugin);
$pluginType = $parts[1];
$pluginName = $parts[2];
$path = $src . "/plugins/$pluginType/$pluginName";
$query = "SELECT COUNT(*) FROM #__extensions WHERE element=" . $db->Quote($pluginName) . " AND folder=" . $db->Quote($pluginType);
$db->setQuery($query);
$count = $db->loadResult();
$installer = new JInstaller;
$result = $installer->install($path);
$status[] = array('name' => $plugin, 'group' => $pluginType, 'result' => $result);
if ($published && !$count)
{
$query = "UPDATE #__extensions SET enabled=1 WHERE element=" . $db->Quote($pluginName) . " AND folder=" . $db->Quote($pluginType);
$db->setQuery($query);
$db->query();
}
}
return $status;
}
/**
* Uninstalls the plugins
*
* @param array $plugins - The plugins
*
* @return array - The install informations
*/
public function uninstallPlugins($plugins)
{
$db = JFactory::getDbo();
$status = array();
foreach ($plugins as $plugin => $published)
{
$parts = explode('_', $plugin);
$pluginType = $parts[1];
$pluginName = $parts[2];
$db->setQuery('SELECT `extension_id` FROM #__extensions WHERE `type` = "plugin" AND `element` = '
. $db->Quote($pluginName) . ' AND `folder` = ' . $db->Quote($pluginType)
);
$id = $db->loadResult();
if ($id)
{
$installer = new JInstaller;
$result = $installer->uninstall('plugin', $id, 1);
$status[] = array('name' => $plugin, 'group' => $pluginType, 'result' => $result);
}
}
return $status;
}
/**
* Get a variable from the manifest file (actually, from the manifest cache).
*
* @param string $name - The key
*
* @return string
*/
public function getParam($name)
{
$db = JFactory::getDbo();
$db->setQuery('SELECT manifest_cache FROM #__extensions WHERE name = ' . $db->quote($name));
$manifest = json_decode($db->loadResult(), true);
return $manifest[$name];
}
/**
* Renders the module installation info
*
* @param array $modules - The modules
*
* @return string
*/
public function renderModuleInfoInstall($modules)
{
$rows = 0;
$html = array();
if (count($modules))
{
$html[] = '<table class="admintable table">';
$html[] = '<tr>';
$html[] = '<th>' . JText::_(strtoupper($this->extension) . '_MODULE') . '</th>';
$html[] = '<th>' . JText::_(strtoupper($this->extension) . '_CLIENT') . '</th>';
$html[] = '<th>' . JText::_(strtoupper($this->extension) . '_STATUS') . '</th>';
$html[] = '</tr>';
foreach ($modules as $module)
{
$html[] = '<tr class="row' . (++$rows % 2) . '">';
$html[] = '<td class="key">' . $module['name'] . '</td>';
$html[] = '<td class="key">' . ucfirst($module['client']) . '</td>';
$html[] = '<td>';
$html[] = '<span style="color:' . (($module['result']) ? 'green' : 'red') . '; font-weight: bold;">';
$html[] = ($module['result']) ? JText::_(strtoupper($this->extension) . '_MODULE_INSTALLED') : JText::_(strtoupper($this->extension) . '_MODULE_NOT_INSTALLED');
$html[] = '</span>';
$html[] = '</td>';
$html[] = '</tr>';
}
$html[] = '</table>';
}
return implode('', $html);
}
/**
* Renders the module uninstallation info
*
* @param array $modules - The modules
*
* @return string
*/
public function renderModuleInfoUninstall($modules)
{
$rows = 0;
$html = array();
if (count($modules))
{
$html[] = '<table class="admintable table">';
$html[] = '<tr>';
$html[] = '<th>' . JText::_(strtoupper($this->extension) . '_MODULE') . '</th>';
$html[] = '<th>' . JText::_(strtoupper($this->extension) . '_CLIENT') . '</th>';
$html[] = '<th>' . JText::_(strtoupper($this->extension) . '_STATUS') . '</th>';
$html[] = '</tr>';
foreach ($modules as $module)
{
$html[] = '<tr class="row' . (++$rows % 2) . '">';
$html[] = '<td class="key">' . $module['name'] . '</td>';
$html[] = '<td class="key">' . ucfirst($module['client']) . '</td>';
$html[] = '<td>';
$html[] = '<span style="color:' . (($module['result']) ? 'green' : 'red') . '; font-weight: bold;">';
$html[] = ($module['result']) ? JText::_(strtoupper($this->extension) . '_MODULE_UNINSTALLED') : JText::_(strtoupper($this->extension) . '_MODULE_COULD_NOT_UNINSTALL');
$html[] = '</span>';
$html[] = '</td>';
$html[] = '</tr>';
}
$html[] = '</table>';
}
return implode('', $html);
}
/**
* Renders the plugin installation info
*
* @param array $plugins - The plugins
*
* @return string
*/
public function renderPluginInfoInstall($plugins)
{
$rows = 0;
$html[] = '<table class="admintable table">';
if (count($plugins))
{
$html[] = '<tr>';
$html[] = '<th>' . JText::_(strtoupper($this->extension) . '_PLUGIN') . '</th>';
$html[] = '<th>' . JText::_(strtoupper($this->extension) . '_GROUP') . '</th>';
$html[] = '<th>' . JText::_(strtoupper($this->extension) . '_STATUS') . '</th>';
$html[] = '</tr>';
foreach ($plugins as $plugin)
{
$html[] = '<tr class="row' . (++$rows % 2) . '">';
$html[] = '<td class="key">' . $plugin['name'] . '</td>';
$html[] = '<td class="key">' . ucfirst($plugin['group']) . '</td>';
$html[] = '<td>';
$html[] = '<span style="color: ' . (($plugin['result']) ? 'green' : 'red') . '; font-weight: bold;">';
$html[] = ($plugin['result']) ? JText::_(strtoupper($this->extension) . '_PLUGIN_INSTALLED') : JText::_(strtoupper($this->extension) . 'PLUGIN_NOT_INSTALLED');
$html[] = '</span>';
$html[] = '</td>';
$html[] = '</tr>';
}
}
$html[] = '</table>';
return implode('', $html);
}
/**
* Renders the plugin uninstallation info
*
* @param array $plugins - The plugins
*
* @return string
*/
public function renderPluginInfoUninstall($plugins)
{
$rows = 0;
$html = array();
if (count($plugins))
{
$html[] = '<table class="admintable table">';
$html[] = '<tbody>';
$html[] = '<tr>';
$html[] = '<th>Plugin</th>';
$html[] = '<th>Group</th>';
$html[] = '<th></th>';
$html[] = '</tr>';
foreach ($plugins as $plugin)
{
$html[] = '<tr class="row' . (++$rows % 2) . '">';
$html[] = '<td class="key">' . $plugin['name'] . '</td>';
$html[] = '<td class="key">' . ucfirst($plugin['group']) . '</td>';
$html[] = '<td>';
$html[] = ' <span style="color:' . (($plugin['result']) ? 'green' : 'red') . '; font-weight: bold;">';
$html[] = ($plugin['result']) ? JText::_(strtoupper($this->extension) . '_PLUGIN_UNINSTALLED') : JText::_(strtoupper($this->extension) . '_PLUGIN_NOT_UNINSTALLED');
$html[] = '</span>';
$html[] = '</td>';
$html[] = ' </tr> ';
}
$html[] = '</tbody > ';
$html[] = '</table > ';
}
return implode('', $html);
}
/**
* method to run before an install/update/discover method
*
* @param int $type - The type
* @param object $parent - The parent obj
*
* @return void
*/
public function preflight($type, $parent)
{
$jversion = new JVersion;
// Extract the version number from the manifest file
$this->release = $parent->get("manifest")->version;
// Find mimimum required joomla version from the manifest file
$this->minimum_joomla_release = $parent->get("manifest")->attributes()->version;
if (version_compare($jversion->getShortVersion(), $this->minimum_joomla_release, 'lt'))
{
Jerror::raiseWarning(
null, 'Cannot install ' . $this->extension . ' in a Joomla release prior to '
. $this->minimum_joomla_release
);
return false;
}
// Abort if the component being installed is not newer than the currently installed version
if ($type == 'update')
{
$oldRelease = $this->getParam('version');
$rel = $oldRelease . ' to ' . $this->release;
if (!strstr($this->release, 'git_'))
{
if (version_compare($this->release, $oldRelease, 'lt'))
{
Jerror::raiseWarning(null, 'Incorrect version sequence. Cannot upgrade ' . $rel);
return false;
}
}
}
}
/**
* method to update the component
*
* @param object $parent - The parent
*
* @return void
*/
public function update($parent)
{
$this->parent = $parent;
}
/**
* method to install the component
*
* @param object $parent - The parent
*
* @return void
*/
public function install($parent)
{
$this->parent = $parent;
}
}