/** * Display the view */ public function display($tpl = null) { JHTML::_('behavior.mootools'); JHTML::_('behavior.keepalive'); $this->container = RokCommon_Service::getContainer(); $this->form = $this->get('Form'); $this->item = $this->get('Item'); $this->state = $this->get('State'); $this->articles = $this->getModel()->getArticles($this->item->id, $this->item->params); $this->layout = isset($this->item->params['layout']) ? $this->item->params['layout'] : $this->form->getFieldAttribute('layout', 'default', 'text', 'params'); $this->provider = isset($this->item->params['provider']) ? $this->item->params['provider'] : $this->form->getFieldAttribute('provider', 'default', 'text', 'params'); if (!isset($this->container[sprintf('roksprocket.layouts.%s', $this->layout)])) { JError::raiseWarning(500, rc__(ROKSPROCKET_UNABLE_TO_FIND_LAYOUT_ERROR, $this->layout)); $app = JFactory::getApplication(); $app->redirect(JRoute::_(sprintf('index.php?option=%s&view=modules', RokSprocket_Helper::getRedirectionOption()), false)); return false; } $this->perItemForm = $this->getModel()->getPerItemsForm($this->layout); /** @var $i18n RokCommon_I18N */ $i18n = $this->container->i18n; foreach ($this->container['roksprocket.layouts'] as $layout_type => $layoutinfo) { $layout_lang_paths = $this->container[sprintf('roksprocket.layouts.%s.paths', $layout_type)]; foreach ($layout_lang_paths as $lang_path) { @$i18n->loadLanguageFiles('roksprocket_layout_' . $layout_type, $lang_path); } } $load_more_total = count($this->articles); $module_params = new RokCommon_Registry($this->item->params); $limit = 10; if ($load_more_total > $limit) { $this->articles = $this->articles->trim($limit); $load_more = 'true'; } else { $load_more = 'false'; } $load_more_script = sprintf('RokSprocket.Paging = {more: %s, page: 1, next_page: 2, amount: %d};', $load_more, $load_more_total); // Check for errors. if (count($errors = $this->get('Errors'))) { JError::raiseError(500, implode("\n", $errors)); return false; } // Read cookie for showing/hide per-article items if (!isset($_COOKIE['roksprocket-showitems'])) { $showitems_cookie = 1; setcookie("roksprocket-showitems", $showitems_cookie, time() + 60 * 60 * 24 * 365, '/'); } else { $showitems_cookie = $_COOKIE['roksprocket-showitems']; } $this->showitems = (bool) $showitems_cookie; $siteURL = JURI::root(true); $adminURL = JURI::base(true); $this->addToolbar(); $this->compileLess(); $this->compileJS(); RokCommon_Header::addInlineScript("RokSprocket.params = 'jform_params';RokSprocket.SiteURL = '" . $siteURL . "'; RokSprocket.AdminURL = '" . $adminURL . "'; RokSprocket.URL = RokSprocket.AdminURL + '/index.php?option=" . JRequest::getString('option') . "&task=ajax&format=raw';" . $load_more_script); RokCommon_Header::addStyle($siteURL . '/components/com_roksprocket/fields/filters/css/datepicker.css'); parent::display($tpl); }
/** * Method to display a view. * * @param bool $cachable * @param bool $urlparams * * @internal param \If $boolean true, the view output will be cached * @internal param \An $array array of safe url parameters and their variable types, for valid values see {@link JFilterInput::clean()}. * * @return JController This object to support chaining. * @since 1.5 */ public function display($cachable = false, $urlparams = false) { require_once JPATH_ADMINISTRATOR . '/components/com_modules/helpers/modules.php'; // Load the submenu. ModulesHelper::addSubmenu(JRequest::getCmd('view', 'modules')); $view = JRequest::getCmd('view', 'modules'); $layout = JRequest::getCmd('layout', 'default'); $id = JRequest::getInt('id'); // Check for edit form. if ($view == 'module' && $layout == 'edit' && !$this->checkEditId('com_roksprocket.edit.module', $id)) { // Somehow the person just went to the form - we don't allow that. $this->setError(JText::sprintf('JLIB_APPLICATION_ERROR_UNHELD_ID', $id)); $this->setMessage($this->getError(), 'error'); $this->setRedirect(JRoute::_(sprintf('index.php?option=%s&view=modules', RokSprocket_Helper::getRedirectionOption()), false)); return false; } parent::display(); }
/** * Method to clone an existing module. * @since 1.6 */ public function duplicate() { // Check for request forgeries JSession::checkToken() or jexit(JText::_('JINVALID_TOKEN')); $app = JFactory::getApplication(); $input = $app->input; $pks = $input->get('cid', array(), 'array'); JArrayHelper::toInteger($pks); try { if (empty($pks)) { throw new Exception(JText::_('COM_MODULES_ERROR_NO_MODULES_SELECTED')); } /** @var $model RokSprocketModelModule */ $model = $this->getModel(); $model->duplicate($pks); $this->setMessage(JText::plural('COM_MODULES_N_MODULES_DUPLICATED', count($pks))); } catch (Exception $e) { JError::raiseWarning(500, $e->getMessage()); } $this->setRedirect(sprintf('index.php?option=%s&view=modules', RokSprocket_Helper::getRedirectionOption()) . $this->getRedirectToListAppend(), false); }
/** * Method to get a single record. * * @param integer $pk The id of the primary key. * * @return mixed Object on success, false on failure. * * @since 1.6 */ public function getItem($pk = null) { // Initialise variables. $pk = !empty($pk) ? (int) $pk : (int) $this->getState('module.id'); $db = $this->getDbo(); if (!isset($this->_cache[$pk])) { // Give Addons a chance to load the menu item $event = new RokCommon_Event($this, 'roksprocket.module.get'); $passed_pk = $pk != 0 ? $pk : null; $this->dispatcher->filter($event, array('primary_key' => $passed_pk, 'menu_item' => null, 'extension_id' => (int) $this->getState('extension.id'))); $addonreturn = $event->getReturnValue(); if ($event->isProcessed()) { $this->_cache[$pk] = $addonreturn['menu_item']; } if (!isset($this->_cache[$pk]) || null == $this->_cache[$pk]) { $false = false; // Get a row instance. $table = $this->getTable(); // Attempt to load the row. $return = $table->load($pk); // Check for a table object error. if ($return === false && ($error = $table->getError())) { $this->setError($error); return $false; } // Check if we are creating a new extension. if (empty($pk)) { if ($extensionId = (int) $this->getState('extension.id')) { $query = $db->getQuery(true); $query->select('element, client_id'); $query->from('#__extensions'); $query->where('extension_id = ' . $extensionId); $query->where('type = ' . $db->quote('module')); $db->setQuery($query); $extension = $db->loadObject(); if (empty($extension)) { if ($error = $db->getErrorMsg()) { $this->setError($error); } else { $this->setError('COM_MODULES_ERROR_CANNOT_FIND_MODULE'); } return false; } // Extension found, prime some module values. $table->module = $extension->element; $table->client_id = $extension->client_id; } else { $app = JFactory::getApplication(); $app->redirect(JRoute::_(sprintf('index.php?option=%s&view=modules', RokSprocket_Helper::getRedirectionOption()), false)); return false; } } // Convert to the JObject before adding other data. $properties = $table->getProperties(1); $this->_cache[$pk] = JArrayHelper::toObject($properties, 'JObject'); // Convert the params field to an array. $registry = new JRegistry(); $registry->loadString($table->params); $this->_cache[$pk]->params = $registry->toArray(); // Determine the page assignment mode. $db->setQuery('SELECT menuid' . ' FROM #__modules_menu' . ' WHERE moduleid = ' . $pk); $assigned = $db->loadColumn(); if (empty($pk)) { // If this is a new module, assign to all pages. $assignment = 0; } elseif (empty($assigned)) { // For an existing module it is assigned to none. $assignment = '-'; } else { if ($assigned[0] > 0) { $assignment = +1; } elseif ($assigned[0] < 0) { $assignment = -1; } else { $assignment = 0; } } $this->_cache[$pk]->assigned = $assigned; $this->_cache[$pk]->assignment = $assignment; // Get the module XML. $client = JApplicationHelper::getClientInfo($table->client_id); $path = JPath::clean($client->path . '/modules/' . $table->module . '/' . $table->module . '.xml'); if (file_exists($path)) { $this->_cache[$pk]->xml = simplexml_load_file($path); } else { $this->_cache[$pk]->xml = null; } $this->_cache[$pk]->edit_display_options = new RokCommon_Registry(); } } return $this->_cache[$pk]; }