/** * Typical dispatch method for MVC based architecture * * This function is provide as a default implementation, in most cases * you will need to override it in your own dispatchers. * * @param array An optional associative array of parameters to be passed in */ public function dispatch(array $params = array()) { // Set the default view in case no view is passed with the request $defaultView = array_key_exists('default_view', $params) ? $params['default_view'] : $this->getClassName('suffix'); // Require specific controller if requested $view = KInput::get('view', array('post', 'get'), 'cmd', null, $defaultView); $controller = KInput::get('controller', array('post', 'get'), 'cmd', null, $view); // Push the view back in the request in case a default view is used KInput::set('view', $view, 'get'); $path = $this->_basePath . DS . 'views'; //In case we are loading a child view set the view path accordingly if (strpos($controller, '.') !== false) { $result = explode('.', $controller); //Set the actual view name KInput::set('view', $result[1], 'get'); //Set the controller based on the parent $controller = $result[0]; //Set the path for the child view $path .= DS . $result[0]; } // Get/Create the controller $options = array('base_path' => $this->_basePath . DS . 'controllers', 'view_path' => $path); $controller = $this->getController($controller, '', '', $options); // Perform the Request task $controller->execute(KInput::get('task', array('post', 'get'), 'cmd')); // Redirect if set by the controller $controller->redirect(); }
public function onDatabaseAfterInsert(ArrayObject $args) { $language = KFactory::get('admin::com.nooku.model.nooku')->getLanguage(); if ($args['table'] == 'nooku_nodes' && $args['data']['iso_code'] == $language) { KInput::set('row_id', $args['data']['row_id'], 'post'); } }
public function onDatabaseAfterInsert(ArrayObject $args) { $language = KFactory::get('admin::com.nooku.model.nooku')->getLanguage(); $row_id = KInput::get('row_id', 'post', 'int'); if ($args['table'] == 'nooku_nodes' && $args['data']['iso_code'] == $language && empty($row_id)) { KInput::set('row_id', $args['data']['row_id'], 'post'); } //Clean the menu cache JFactory::getCache('mod_mainmenu')->clean(); }
public function onApplicationBeforeRedirect(ArrayObject $args) { if (in_array(KInput::get('task', 'post', 'cmd'), array('save'))) { $id = KInput::get('id', array('get', 'post'), 'int'); KInput::set('table_name', 'content', 'post'); KInput::set('row_id', $id, 'post'); $controller = KFactory::get('site::com.nooku.controller.metadata'); $controller->execute('save'); } }
public function save() { //Create the redirect URL $redirect = '&view=language&layout=form&id=' . KInput::get('id', 'get', 'int'); try { $prefix = KInput::get('iso_code_lang', 'post', 'alpha'); $suffix = KInput::get('iso_code_country', 'post', 'alpha'); // Recombine the iso_code KInput::set('iso_code', strtolower($prefix) . '-' . strtoupper($suffix), 'post'); } catch (KInputException $e) { $this->setRedirect($redirect, JText::_('The ISO code should consist of the language code and the country code (two letters each), eg "en-GB".')); return; } if (!trim(KInput::get('name', 'post', 'string')) || !trim(KInput::get('alias', 'post', 'string'))) { $this->setRedirect($redirect, JText::_('Please enter a name and an alias.')); return; } return parent::save(); }
/** * Method to upgrade a specific extension * * @package MageBridge * @access public * @param string $exension_name * @return bool */ private function update($extension_name = null) { // Do not continue if the extension name is empty if ($extension_name == null) { JError::raiseWarning('SOME_ERROR_CODE', JText::_('COM_MAGEBRIDGE_MODEL_UPDATE_INSTALL_NO_EXTENSION')); return false; } // Fetch a list of available packages $packages = MageBridgeUpdateHelper::getPackageList(); foreach ($packages as $package) { if ($package['name'] == $extension_name) { $extension = $package; break; } } // Do not continue if the extension does not appear from the list if ($extension == null) { JError::raiseWarning('SOME_ERROR_CODE', JText::_('COM_MAGEBRIDGE_MODEL_UPDATE_INSTALL_UNKNOWN_EXTENSION')); return false; } // Premature check for the component-directory to be writable if ($extension['type'] == 'component' && JFactory::getConfig()->get('ftp_enable') == 0) { if (is_dir(JPATH_ADMINISTRATOR . '/components/' . $extension['name']) && !is_writable(JPATH_ADMINISTRATOR . '/components/' . $extension['name'])) { JError::raiseWarning('SOME_ERROR_CODE', JText::sprintf('COM_MAGEBRIDGE_MODEL_UPDATE_INSTALL_DIR_NOT_WRITABLE', JPATH_ADMINISTRATOR . '/components/' . $extension['name'])); return false; } else { if (!is_dir(JPATH_ADMINISTRATOR . '/components/' . $extension['name']) && !is_writable(JPATH_ADMINISTRATOR . '/components')) { JError::raiseWarning('SOME_ERROR_CODE', JText::sprintf('COM_MAGEBRIDGE_MODEL_UPDATE_INSTALL_DIR_NOT_WRITABLE', JPATH_ADMINISTRATOR . '/components')); return false; } } } // Construct the update URL $extension_uri = $extension['name']; $extension_uri .= '_j25'; $extension_uri .= '.' . MagebridgeModelConfig::load('update_format'); $extension_url = $this->getUrl($extension_uri); // Either use fopen() or CURL if (ini_get('allow_url_fopen') == 1 && MagebridgeModelConfig::load('update_method') == 'joomla') { $package_file = JInstallerHelper::downloadPackage($extension_url, $extension_uri); } else { $package_file = MageBridgeUpdateHelper::downloadPackage($extension_url, $extension_uri); } // Simple check for the result if ($package_file == false) { JError::raiseWarning('SOME_ERROR_CODE', JText::sprintf('COM_MAGEBRIDGE_MODEL_UPDATE_INSTALL_DOWNLOAD_FAILED', $extension_uri)); return false; } // Check if the downloaded file exists $tmp_path = JFactory::getConfig()->get('tmp_path'); $package_path = $tmp_path . '/' . $package_file; if (!is_file($package_path)) { JError::raiseWarning('MB', JText::sprintf('COM_MAGEBRIDGE_MODEL_UPDATE_INSTALL_FILE_NOT_EXISTS', $package_path)); return false; } // Check if the file is readable if (!is_readable($package_path)) { JError::raiseWarning('MB', JText::sprintf('COM_MAGEBRIDGE_MODEL_UPDATE_INSTALL_FILE_NOT_READABLE', $package_path)); return false; } // Check if the downloaded file is abnormally small (so it might just contain a simple warning-text) if (filesize($package_path) < 128) { $contents = @file_get_contents($package_path); if (empty($contents)) { JError::raiseWarning('MB', JText::_('COM_MAGEBRIDGE_MODEL_UPDATE_INSTALL_FILE_EMPTY')); return false; } else { if (preg_match('/^Restricted/', $contents)) { JError::raiseWarning('MB', JText::sprintf('COM_MAGEBRIDGE_MODEL_UPDATE_INSTALL_NO_ACCESS')); return false; } } JError::raiseWarning('MB', JText::sprintf('COM_MAGEBRIDGE_MODEL_UPDATE_INSTALL_FILE_NO_ARCHIVE', $package_path)); return false; } // Now we assume this is an archive, so let's unpack it $package = JInstallerHelper::unpack($package_path); if ($package == false) { JError::raiseWarning('SOME_ERROR_CODE', JText::sprintf('COM_MAGEBRIDGE_MODEL_UPDATE_INSTALL_FILE_GONE', $extension['name'])); return false; } // Quick workaround to prevent Koowa proxying the database if (class_exists('KInput')) { KInput::set('option', 'com_installer', 'get'); } // Call the actual installer to install the package $installer = JInstaller::getInstance(); if ($installer->install($package['dir']) == false) { JError::raiseWarning('SOME_ERROR_CODE', JText::sprintf('COM_MAGEBRIDGE_MODEL_UPDATE_INSTALL_FAILED', $extension['name'])); return false; } // Get the name of downloaded package if (!is_file($package['packagefile'])) { $package['packagefile'] = JFactory::getConfig()->get('tmp_path') . '/' . $package['packagefile']; } // Clean up the installation @JInstallerHelper::cleanupInstall($package['packagefile'], $package['extractdir']); // Post install procedure if (isset($extension['post_install_query'])) { $query = trim($extension['post_install_query']); if (!empty($query)) { $db = JFactory::getDBO(); $db->setQuery($query); try { $db->execute(); } catch (Exception $e) { JError::raiseWarning('MB', JText::sprintf('COM_MAGEBRIDGE_MODEL_UPDATE_INSTALL_POSTQUERY_FAILED', $db->getErrorMsg())); return false; } if ($db->getErrorMsg()) { JError::raiseWarning('MB', JText::sprintf('COM_MAGEBRIDGE_MODEL_UPDATE_INSTALL_POSTQUERY_FAILED', $db->getErrorMsg())); return false; } } } return true; }
private function update($extension_name = null) { // Do not continue if the extension name is empty if ($extension_name == null) { JError::raiseWarning('SOME_ERROR_CODE', JText::_('No extension specified')); return false; } // Fetch a list of available packages $packages = MageBridgeUpdateHelper::getPackageList(); foreach ($packages as $package) { if ($package['name'] == $extension_name) { $extension = $package; break; } } // Do not continue if the extension does not appear from the list if ($extension == null) { JError::raiseWarning('SOME_ERROR_CODE', JText::_('Unknown extension')); return false; } // Premature check for the component-directory to be writable if ($extension['type'] == 'component' && JFactory::getConfig()->getValue('ftp_enable') == 0) { if (is_dir(JPATH_ADMINISTRATOR . '/components/' . $extension['name']) && !is_writable(JPATH_ADMINISTRATOR . '/components/' . $extension['name'])) { JError::raiseWarning('SOME_ERROR_CODE', JText::_('Component directory is not writable')); return false; } else { if (!is_dir(JPATH_ADMINISTRATOR . '/components/' . $extension['name']) && !is_writable(JPATH_ADMINISTRATOR . '/components')) { JError::raiseWarning('SOME_ERROR_CODE', JText::_('Components folder is not writable')); return false; } } } // Construct the update URL $extension_uri = $extension['name']; $extension_uri .= MageBridgeHelper::isJoomla15() ? '_j15' : '_j25'; $extension_uri .= '.' . MagebridgeModelConfig::load('update_format'); $extension_url = $this->getUrl($extension_uri); // Either use fopen() or CURL if (ini_get('allow_url_fopen') == 1 && MagebridgeModelConfig::load('update_method') == 'joomla') { $package_file = JInstallerHelper::downloadPackage($extension_url, $extension_uri); } else { $package_file = MageBridgeUpdateHelper::downloadPackage($extension_url, $extension_uri); } // Simple check for the result if ($package_file == false) { JError::raiseWarning('SOME_ERROR_CODE', JText::sprintf('Failed to download update for %s', $extension_uri)); return false; } // Check if the downloaded file exists $tmp_path = JFactory::getConfig()->getValue('config.tmp_path'); $package_path = $tmp_path . '/' . $package_file; if (!is_file($package_path)) { JError::raiseWarning('MB', JText::sprintf('File %s does not exist', $package_path)); return false; } // Check if the file is readable if (!is_readable($package_path)) { JError::raiseWarning('MB', JText::sprintf('File %s is not readable', $package_path)); return false; } // Check if the downloaded file is abnormally small (so it might just contain a simple warning-text) if (filesize($package_path) < 128) { $contents = @file_get_contents($package_path); if (empty($contents)) { JError::raiseWarning('MB', JText::sprintf('Valid archive but empty content.')); return false; } else { if (preg_match('/^Restricted/', $contents)) { JError::raiseWarning('MB', JText::sprintf('Not allowed to access updates.')); return false; } } JError::raiseWarning('MB', JText::sprintf('File %s is not a valid archive', $package_path)); return false; } // Now we assume this is an archive, so let's unpack it $package = JInstallerHelper::unpack($package_path); if ($package == false) { JError::raiseWarning('SOME_ERROR_CODE', JText::sprintf('Unable to find update for %s on local filesystem', $extension['name'])); return false; } // Quick workaround to prevent Koowa proxying the database if (class_exists('KInput')) { KInput::set('option', 'com_installer', 'get'); } // Call the actual installer to install the package $installer = JInstaller::getInstance(); if ($installer->install($package['dir']) == false) { JError::raiseWarning('SOME_ERROR_CODE', JText::sprintf('Failed to install %s', $extension['name'])); return false; } // Get the name of downloaded package if (!is_file($package['packagefile'])) { $package['packagefile'] = JFactory::getConfig()->getValue('config.tmp_path') . '/' . $package['packagefile']; } // Clean up the installation @JInstallerHelper::cleanupInstall($package['packagefile'], $package['extractdir']); // Post install procedure if (isset($extension['post_install_query'])) { $query = trim($extension['post_install_query']); if (!empty($query)) { $db = JFactory::getDBO(); $db->setQuery($query); $db->query(); if ($db->getErrorMsg()) { JError::raiseWarning('MB', JText::sprintf('Post install query failed: %s', $db->getErrorMsg())); return false; } } } return true; }
* @version $Id: nooku.php 923 2009-03-03 17:54:50Z johan $ * @category Nooku * @package Nooku_Administrator * @copyright Copyright (C) 2007 - 2009 Joomlatools. All rights reserved. * @license GNU GPLv2 <http://www.gnu.org/licenses/old-licenses/gpl-2.0.html> * @link http://www.nooku.org */ // no direct access defined('_JEXEC') or die('Restricted access'); // Check if Koowa is active if (!defined('KOOWA')) { JError::raiseWarning(0, JText::_("Koowa wasn't found. Please install the Koowa plugin and enable it.")); return; } // Check if Nooku is active if (!defined('NOOKU')) { JError::raiseWarning(0, JText::_("The Nooku plugin isn't enabled.")); return; } // Require the defines Koowa::import('admin::com.nooku.defines'); Koowa::import('admin::com.nooku.loader'); // Check if this is the first run include JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_nooku' . DS . 'configs' . DS . 'first_run.php'; if ($first_run) { KInput::set('view', 'installation', 'get'); KInput::set('task', 'finish', 'get'); } // Create the component dispatcher $dispatcher = KFactory::get('admin::com.nooku.dispatcher'); $dispatcher->dispatch(array('default_view' => 'dashboard'));