/** * Method to do additional instant update according config change * * @param string Name of changed config parameter * @param mixed Recent config parameter value * @return void */ protected function instantUpdate($name, $value) { $input = JFactory::getApplication()->input; if ($name == 'disable_all_messages') { // Get name of messages table $table = '#__jsn_' . substr(JRequest::getCmd('option'), 4) . '_messages'; // Enable/disable all messages $db = JFactory::getDbo(); $db->setQuery("UPDATE `{$table}` SET published = " . (1 - $value) . " WHERE 1"); $db->query(); } elseif ($name == 'languagemanager') { // Get variable $lang = $input->getVar('languagemanager', array(), 'default', 'array'); // Install backend languages if (isset($lang['a'])) { JSNFactory::import('components.com_poweradmin.helpers.language'); JSNLanguageHelper::installSupportedExtLangs($lang['a']); JSNUtilsLanguage::install($lang['a']); } // Install frontend languages if (isset($lang['s'])) { JSNUtilsLanguage::install($lang['s'], true); } } else { return parent::instantUpdate($name, $value); } return true; }
/** * Method to do additional instant update according config change * * @param string $name Name of changed config parameter * @param mixed $value Recent config parameter value * * @return void */ protected function instantUpdate($name, $value) { if ($name == 'disable_all_messages') { // Get name of messages table $table = '#__jsn_' . substr(JFactory::getApplication()->input->getCmd('option'), 4) . '_messages'; // Enable/disable all messages $db = JFactory::getDbo(); $db->setQuery("UPDATE `{$table}` SET published = " . (1 - $value) . " WHERE 1"); $db->execute(); } else { return parent::instantUpdate($name, $value); } return true; }
/** * Save the submitted configuration data to database. * * @param array $config Parsed configuration declaration. * @param array $data The data to save. * * @return void */ public function save($config, $data) { $post = $_POST; if (!empty($post['form_email_notification'])) { $emailNotification = array(); foreach ($post['form_email_notification'] as $email) { if (!empty($email)) { $address = new stdClass(); $address->email_address = $email; $emailNotification[] = $address; } } $data['email_notification'] = json_encode($emailNotification); } parent::save($config, $data); }
/** * Save the submitted configuration data to database. * * @param array $config Parsed configuration declaration. * @param array $data The data to save. * * @return void */ public function save($config, $data) { $post = $_POST; if (!empty($post['form_email_notification'])) { $emailNotification = array(); foreach ($post['form_email_notification'] as $email) { if (!empty($email)) { $address = new stdClass(); $address->email_address = $email; $emailNotification[] = $address; } } $data['email_notification'] = json_encode($emailNotification); } else { $db = JFactory::getDBO(); $this->_db->setQuery("REPLACE INTO `#__jsn_uniform_config` (name, value) VALUES ('email_notification','')"); $this->_db->execute(); } parent::save($config, $data); }
/** * Finalize dependency installation. * * @return void */ public function finalize() { // Save live update notification setting to config table $model = new JSNConfigModel(); $form = $model->getForm(array(), true); $data = array('live_update_notification' => (string) $this->input->getInt('live_update_notification', 0)); try { $model->save($form, $data); } catch (Exception $e) { throw $e; } }
// Validate required variable !empty($component) or die(JText::_('JSN_EXTFW_CHOOSERS_REVIEW_ON_JED_MISSING_VAR')); // Define some common constants define('JPATH_COMPONENT', JPATH_ROOT . '/administrator/components/' . $component); define('JPATH_COMPONENT_ADMINISTRATOR', JPATH_COMPONENT); // Load component's constant definition file file_exists($define = JPATH_COMPONENT_ADMINISTRATOR . '/' . substr($component, 4) . '.defines.php') or file_exists($define = JPATH_COMPONENT_ADMINISTRATOR . '/defines.' . substr($component, 4) . '.php') or $define = null; $define == null or (require_once $define); // Get product configuration $config = JSNConfigHelper::get($component); // Execute requested task if ($app->input->getCmd('task') == 'switch') { // Set 'option' variable to request $app->input->set('option', $component); // Get config model $model = new JSNConfigModel(); // Turn on/off periodical popup asking for review $form = $model->getForm(array(), true, JPATH_ROOT . '/administrator/components/' . $component . '/config.xml'); $data = array('review_popup' => (int) $status); try { // Save new configuration $model->save($form, $data); } catch (Exception $e) { // Do nothing as this is a background process jexit($e->getMessage()); } jexit('SUCCESS'); } else { // Get product info $product = JSNUtilsXml::loadManifestCache($component, 'component'); }
/** * Contructor */ public function __construct() { parent::__construct(); }
/** * Check if there is new update for installed JoomlaShine product. * * @return mixed */ private function checkUpdate() { // Initialize extensions to check for update $exts = JSNVersion::isJoomlaCompatible('3.1') ? array($this->option) : JSNVersion::$products; // Get Joomla version $joomlaVersion = new JVersion(); // Get list of JoomlaShine product need to be checked for new update $checks = $products = array(); foreach ($exts as $product) { // Instantiate JSN Config model self::$_app->input->set('option', $product); $model = new JSNConfigModel(); // Only continue if product is installed if (is_readable(JPATH_ROOT . '/administrator/components/' . $product . '/config.xml')) { // Get product configuration $cfg = JSNConfigHelper::get($product); if (!$cfg->get('config-table-not-exists') and !$cfg->get('live_update_checking', 0)) { if (time() - $cfg->get('live_update_last_check', 0) >= (int) $cfg->get('live_update_check_interval', 6) * 60 * 60) { // Store necessary data to config table $form = $model->getForm(array(), true, JPATH_ROOT . '/administrator/components/' . $product . '/config.xml'); $data = array('live_update_checking' => 1); try { $model->save($form, $data); // Store product for checking new update later file_exists($define = JPATH_ROOT . '/administrator/components/' . $product . '/' . substr($product, 4) . '.defines.php') or file_exists($define = JPATH_ROOT . '/administrator/components/' . $product . '/defines.' . substr($product, 4) . '.php') or file_exists($define = JPATH_ROOT . '/administrator/components/' . $product . '/defines.php') or $define = null; if (!empty($define)) { if ($product == 'com_imageshow' and !class_exists('JSNISFactory')) { // JSN ImageShow specific fix if (file_exists(JPATH_ROOT . '/administrator/components/com_imageshow/classes/jsn_is_factory.php')) { require_once JPATH_ROOT . '/administrator/components/com_imageshow/classes/jsn_is_factory.php'; } else { // Do nothing as this is a background process continue; } } require_once $define; $products[JSNUtilsText::getConstant('IDENTIFIED_NAME')] = $product; $checks[JSNUtilsText::getConstant('IDENTIFIED_NAME')] = JSNUtilsText::getConstant('VERSION', $product); } } catch (Exception $e) { // Do nothing as this is a background process continue; } } } } } // Check update for installed JoomlaShine product if (count($products)) { if ($checks = JSNUpdateHelper::check($checks, $joomlaVersion->RELEASE)) { // Get database object $db = JFactory::getDbo(); foreach ($checks as $id => &$result) { // Instantiate JSN Config model self::$_app->input->set('option', $products[$id]); $model = new JSNConfigModel(); // Get product configuration $cfg = JSNConfigHelper::get($products[$id]); // Decode last update info $last = is_string($last = $cfg->get('live_update_last_notified', '{"version":"0.0.0"}')) ? json_decode($last) : $last; if ($result and version_compare($result->version, $last->version, '>')) { // Get product details if ($info = JSNUtilsXml::loadManifestCache($products[$id])) { $name = 'JSN ' . preg_replace('/^JSN\\s*/i', '', $info->name) . (($edition = JSNUtilsText::getConstant('EDITION', $products[$id])) ? ' ' . $edition : ''); if (!JSNVersion::isJoomlaCompatible('3.1')) { // Get extension ID $q = $db->getQuery(true); $q->select('extension_id'); $q->from('#__extensions'); $q->where("element = '" . $products[$id] . "'"); $q->where("type = 'component'", 'AND'); $db->setQuery($q); $eid = $db->loadResult(); // Check if update is stored before $q = $db->getQuery(true); $q->select('version'); $q->from('#__updates'); $q->where("extension_id = '{$eid}'"); $db->setQuery($q); // Store update info to Joomla updates table if ($current = $db->loadResult()) { $q = $db->getQuery(true); $q->update('#__updates'); $q->set("version = '{$result->version}'"); $q->where("extension_id = '{$eid}'"); $q->where("version = '{$current}'", 'AND'); } else { $q = $db->getQuery(true); $q->insert('#__updates'); $q->columns('extension_id, name, element, type, version'); $q->values("{$eid}, '{$name}', '{$products[$id]}', 'component', '{$result->version}'"); } $db->setQuery($q); $db->execute(); } else { // Generate XML content for latest update $xml[] = '<?xml version="1.0" encoding="utf-8"?>'; $xml[] = '<extensionset name="JoomlaShine Extensions" description="JoomlaShine Extensions Updates">'; $xml[] = ' <extension name="' . $name . '" element="' . $products[$id] . '" type="component" client="administrator" version="' . $result->version . '" detailsurl="" />'; $xml[] = '</extensionset>'; // Write XML content to a local cache file JFile::write(JFactory::getConfig()->get('tmp_path') . '/' . str_replace('com_', 'jsn_', $products[$id]) . '_update.xml', implode("\n", $xml)); } if ($cfg->get('live_update_notification', 0)) { // Get super administrator account to notify about update available if (!isset($admins)) { // Get Joomla config $joomlaConfig = JFactory::getConfig(); // Build query to get super administrator account $q = $db->getQuery(true); $q->select('u.id, u.email'); $q->from('#__user_usergroup_map AS g'); $q->join('INNER', '#__users AS u ON g.user_id = u.id'); $q->where('g.group_id = 8'); $q->where('u.sendEmail = 1'); $q->where('u.block = 0'); $db->setQuery($q); try { if (!($admins = $db->loadObjectList())) { return; } } catch (Exception $e) { return; } } // Generate replacement $substitutions = array('__SITE_NAME__' => $joomlaConfig->get('sitename'), '__SITE_URL__' => JUri::root(), '__PRODUCT__' => $name, '__CURRENT__' => JSNUtilsText::getConstant('VERSION', $products[$id]), '__NEW__' => $result->version, '__LINK__' => JUri::root() . 'administrator/index.php?option=' . $products[$id] . '&view=update'); // Initialize email subject and message $subject = JText::_('JSN_EXTFW_UPDATE_NOTIFICATION_SUBJECT'); $message = JText::_('JSN_EXTFW_UPDATE_NOTIFICATION_MESSAGE'); foreach ($substitutions as $k => $v) { $subject = str_replace($k, $v, $subject); $message = str_replace($k, $v, $message); } foreach ($admins as $admin) { // Initialize mailer then send update notification email try { $mailer = JFactory::getMailer(); $mailer->setSender(array($joomlaConfig->get('mailfrom'), $joomlaConfig->get('fromname'))); $mailer->addRecipient($admin->email); $mailer->setSubject($subject); $mailer->setBody($message); $mailer->Send(); } catch (Exception $e) { return; } } } } } // Store last check update time $form = $model->getForm(array(), true, JPATH_ROOT . '/administrator/components/' . $products[$id] . '/config.xml'); $data = array('live_update_checking' => '0', 'live_update_last_check' => time()); if ($result) { // Store last version notified $data['live_update_last_notified'] = json_encode($result); } try { $model->save($form, $data); } catch (Exception $e) { // Do nothing as this is a background process continue; } } } } // Restore current option self::$_app->input->set('option', $this->option); // In Joomla! 3.1, return generated XML content about latest update if (JSNVersion::isJoomlaCompatible('3.1')) { if (isset($xml)) { return implode("\n", $xml); } elseif (is_readable($cache = JFactory::getConfig()->get('tmp_path') . '/' . str_replace('com_', 'jsn_', $this->option) . '_update.xml')) { return JFile::read($cache); } else { return '<?xml version="1.0" encoding="utf-8"?><extensionset />'; } } }