Current Path :
/
home
/
develito
/
httpdocs
/
components
/
com_dmod
/
models
/
Or
Select Your Path :
Upload File :
New :
File
Dir
/home/develito/httpdocs/components/com_dmod/models/dmod.php
<?php /*------------------------------------------------------------------------ # com_dmod - Dmod Module Manager # ------------------------------------------------------------------------ # author Jesus Vargas Garita # copyright Copyright (C) 2010 www.joomlahill.com. All Rights Reserved. # @license - http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL # Websites: http://www.joomlahill.com # Technical Support: Forum - http://www.joomlahill.com/forum -------------------------------------------------------------------------*/ defined('_JEXEC') or die; require_once JPATH_ADMINISTRATOR.'/components/com_modules/models/module.php'; class DmodModelDmod extends JModelItem { protected $_context = 'com_dmod.dmod'; protected function populateState() { $app = JFactory::getApplication('site'); $pk = JRequest::getInt('id'); $this->setState('dmod.id', $pk); $params = $app->getParams(); $this->setState('params', $params); $user = JFactory::getUser(); if ((!$user->authorise('core.edit.state', 'com_dmod')) && (!$user->authorise('core.edit', 'com_dmod'))){ $this->setState('filter.published', 1); $this->setState('filter.archived', 2); } } public function &getItem($pk = null) { $pk = (!empty($pk)) ? $pk : (int) $this->getState('dmod.id'); if ($this->_item === null) { $this->_item = array(); } if (!isset($this->_item[$pk])) { try { $db = $this->getDbo(); $query = $db->getQuery(true); $query->select($this->getState('item.select', 'a.*') . ',' . ' CASE WHEN CHAR_LENGTH(a.alias) THEN CONCAT_WS(\':\', a.id, a.alias) ELSE a.id END as slug, ' . ' CASE WHEN CHAR_LENGTH(c.alias) THEN CONCAT_WS(\':\', c.id, c.alias) ELSE c.id END AS catslug '); $query->from('#__dmod AS a'); $query->select('c.title AS category_title, c.alias AS category_alias, c.access AS category_access'); $query->join('LEFT', '#__categories AS c on c.id = a.catid'); $query->select('parent.title as parent_title, parent.id as parent_id, parent.path as parent_route, parent.alias as parent_alias'); $query->join('LEFT', '#__categories as parent ON parent.id = c.parent_id'); $query->where('a.id = ' . (int) $pk); $nullDate = $db->Quote($db->getNullDate()); $nowDate = $db->Quote(JFactory::getDate()->toSql()); $published = $this->getState('filter.published'); $archived = $this->getState('filter.archived'); if (is_numeric($published)) { $query->where('(a.published = ' . (int) $published . ' OR a.published =' . (int) $archived . ')'); } $db->setQuery($query); $data = $db->loadObject(); $this->setState('module.id', $data->module); if ($error = $db->getErrorMsg()) { throw new JException($error); } if (empty($data)) { throw new JException(JText::_('COM_DMOD_ERROR_DMOD_NOT_FOUND'), 404); } // Check for published state if filter set. if (((is_numeric($published)) || (is_numeric($archived))) && (($data->published != $published) && ($data->published != $archived))) { JError::raiseError(404, JText::_('COM_DMOD_ERROR_DMOD_NOT_FOUND')); } // Convert parameter fields to objects. $registry = new JRegistry; $registry->loadString($data->params); $data->params = clone $this->getState('params'); $data->params->merge($registry); $registry = new JRegistry; $registry->loadString($data->metadata); $data->metadata = $registry; // Compute access permissions. if ($access = $this->getState('filter.access')) { // If the access filter has been set, we already know this user can view. $data->params->set('access-view', true); } else { // If no access filter is set, the layout takes some responsibility for display of limited information. $user = JFactory::getUser(); $groups = $user->getAuthorisedViewLevels(); if ($data->catid == 0 || $data->category_access === null) { $data->params->set('access-view', in_array($data->access, $groups)); } else { $data->params->set('access-view', in_array($data->access, $groups) && in_array($data->category_access, $groups)); } } $this->_item[$pk] = $data; } catch (JException $e) { $this->setError($e); $this->_item[$pk] = false; } } return $this->_item[$pk]; } protected function getDmodQuery($pk = null) { // TODO: Cache on the fingerprint of the arguments $db = $this->getDbo(); $user = JFactory::getUser(); $pk = (!empty($pk)) ? $pk : (int) $this->getState('contact.id'); $query = $db->getQuery(true); if ($pk) { $query->select('a.*, cc.access as category_access, cc.title as category_name, ' . ' CASE WHEN CHAR_LENGTH(a.alias) THEN CONCAT_WS(\':\', a.id, a.alias) ELSE a.id END as slug, ' . ' CASE WHEN CHAR_LENGTH(cc.alias) THEN CONCAT_WS(\':\', cc.id, cc.alias) ELSE cc.id END AS catslug '); $query->from('#__dmod AS a'); $query->join('INNER', '#__categories AS cc on cc.id = a.catid'); $query->where('a.id = ' . (int) $pk); $published = $this->getState('filter.published'); $archived = $this->getState('filter.archived'); if (is_numeric($published)) { $query->where('a.published IN (1,2)'); $query->where('cc.published IN (1,2)'); } $groups = implode(',', $user->getAuthorisedViewLevels()); $query->where('a.access IN ('.$groups.')'); try { $db->setQuery($query); $result = $db->loadObject(); if ($error = $db->getErrorMsg()) { throw new Exception($error); } if (empty($result)) { throw new JException(JText::_('COM_DMOD_ERROR_DMOD_NOT_FOUND'), 404); } } catch (Exception $e) { $this->setError($e); return false; } if ($result) { return $result; } } } public function getModule() { $modModel = JModelLegacy::getInstance('Module', 'ModulesModel', array('ignore_request' => true)); $module = $modModel->getItem($this->getState('module.id')); $this->setState('module', $module); $buttons = 0; if ( $this->getState('params')->get('show_params') && $this->getState('params')->get('allow_test') ) : $buttons = 1; $post = JRequest::get( 'post' ); $form = JArrayHelper::getValue( $post, 'jform', array(), 'array' ); $test = JArrayHelper::getValue( $form, 'params', array(), 'array' ); if ($test) : if ($this->getState('params')->get('save_params')) : $registry = new JRegistry(); $registry->loadArray($test); $str = $registry->toString(); $this->saveParams($str); else : $buttons = 2; endif; $module->params = $test; endif; endif; $this->setState('buttons', $buttons); $module->user = substr( $module->module, 0, 4 ) == 'mod_' ? 0 : 1; return $module; } public function getModParams($data = array(), $loadData = true) { $module = $this->getModule(); JForm::addFormPath('administrator/components/com_modules/models/forms'); JForm::addFieldPath('administrator/components/com_modules/models/fields'); $form = JForm::getInstance('com_modules.module', 'module', array('control' => 'jform', 'load_data' => true), false, false ); // joomla.application.component.modelform preprocessForm $lang = JFactory::getLanguage(); $clientId = $module->client_id; $client = JApplicationHelper::getClientInfo($clientId); $formFile = JPath::clean($client->path.'/modules/'.$module->module.'/'.$module->module.'.xml'); $lang->load($module->module, $client->path, null, false, false) || $lang->load($module->module, $client->path.'/modules/'.$module->module, null, false, false) || $lang->load($module->module, $client->path, $lang->getDefault(), false, false) || $lang->load($module->module, $client->path.'/modules/'.$module->module, $lang->getDefault(), false, false); // Joomla Global Language $lang->load('', JPATH_ADMINISTRATOR, null, false, false) || $lang->load('', JPATH_ADMINISTRATOR, null, true); if (file_exists($formFile)) { // Get the module form. if (!$form->loadFile($formFile, false, '//config')) { throw new Exception(JText::_('JERROR_LOADFILE_FAILED')); } // Attempt to load the xml file. if (!$xml = simplexml_load_file($formFile)) { throw new Exception(JText::_('JERROR_LOADFILE_FAILED')); } } $form->bind($module); //var_dump($form); exit(); if (empty($form)) { return false; } return $form; } public function saveParams($params) { $id = $this->getState('module.id'); $db = JFactory::getDBO(); $query = "UPDATE #__modules SET params = '" . $params . "' WHERE id = ". $id; $db->setQuery( $query ); $db->query(); } }