public static function addSubmenu($context) { // Avoid nonsense situation. if ($context == 'com_dpfields') { return; } $parts = DPFieldsHelper::extract($context); if (!$parts) { return; } $component = $parts[0]; $section = $parts[1]; // Try to find the component helper. $eName = str_replace('com_', '', $component); $file = JPath::clean(JPATH_ADMINISTRATOR . '/components/' . $component . '/helpers/' . $eName . '.php'); if (file_exists($file)) { require_once $file; $prefix = ucfirst(str_replace('com_', '', $component)); $cName = $prefix . 'Helper'; if (class_exists($cName)) { if (is_callable(array($cName, 'addSubmenu'))) { $lang = JFactory::getLanguage(); // Loading language file from the administrator/language // directory then // loading language file from the // administrator/components/*context*/language directory $lang->load($component, JPATH_BASE, null, false, true) || $lang->load($component, JPath::clean(JPATH_ADMINISTRATOR . '/components/' . $component), null, false, true); call_user_func(array($cName, 'addSubmenu'), 'fields' . (isset($section) ? '.' . $section : '')); } } } }
public function catchange() { JSession::checkToken() or jexit(JText::_('JINVALID_TOKEN')); $app = JFactory::getApplication(); $data = $this->input->get($this->input->get('formcontrol', 'jform'), array(), 'array'); $parts = DPFieldsHelper::extract($this->input->getCmd('context')); if ($parts) { if ((!isset($data['id']) || !$data['id']) && (isset($data['catid']) && $data['catid'])) { $data['dpfieldscatid'] = $data['catid']; $data['catid'] = null; } $app->setUserState($parts[0] . '.edit.' . $parts[1] . '.data', $data); } $app->redirect(base64_decode($this->input->get->getBase64('return'))); $app->close(); }
protected function _getAssetParentId(JTable $table = null, $id = null) { $parts = DPFieldsHelper::extract($this->context); $component = $parts ? $parts[0] : null; if ($component) { // Build the query to get the asset id for the parent category. $query = $this->_db->getQuery(true)->select($this->_db->quoteName('id'))->from($this->_db->quoteName('#__assets'))->where($this->_db->quoteName('name') . ' = ' . $this->_db->quote($component)); // Get the asset id from the database. $this->_db->setQuery($query); $assetId = null; if ($result = $this->_db->loadResult()) { $assetId = (int) $result; if ($assetId) { return $assetId; } } } return parent::_getAssetParentId($table, $id); }
public function display($tpl = null) { $this->state = $this->get('State'); $this->items = $this->get('Items'); $this->pagination = $this->get('Pagination'); $this->filterForm = $this->get('FilterForm'); $this->activeFilters = $this->get('ActiveFilters'); // Check for errors. if (count($errors = $this->get('Errors'))) { JError::raiseError(500, implode("\n", $errors)); return false; } $this->context = JFactory::getApplication()->input->getCmd('context'); $parts = DPFieldsHelper::extract($this->context); if (!$parts) { JError::raiseError(500, 'Invalid context!!'); return; } $this->component = $parts[0]; $this->section = $parts[1]; $this->addToolbar(); $this->sidebar = JHtmlSidebar::render(); parent::display($tpl); }
/** * Returns the fields for the given context. * If the item is an object the returned fields do have an additional field * "value" which represents the value for the given item. If the item has a * catid field, then additionally fields which belong to that category will * be returned. * Should the value being prepared to be shown in a HTML context * prepareValue must be set to true. Then no further escaping needs to be * don. * * @param string $context * @param stdClass $item * @param boolean $prepareValue * @return array */ public static function getFields($context, $item = null, $prepareValue = false) { if (self::$fieldsCache === null) { // Load the model JLoader::import('joomla.application.component.model'); JModelLegacy::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_dpfields/models', 'DPFieldsModel'); self::$fieldsCache = JModelLegacy::getInstance('Fields', 'DPFieldsModel', array('ignore_request' => true)); self::$fieldsCache->setState('filter.published', 1); self::$fieldsCache->setState('filter.language', JFactory::getLanguage()->getTag()); self::$fieldsCache->setState('list.limit', 0); } self::$fieldsCache->setState('filter.context', $context); if (is_array($item)) { $item = (object) $item; } // If item has catid parameter display only fields which belong to the // category if ($item && (isset($item->catid) || isset($item->dpfieldscatid))) { $catids = isset($item->catid) ? $item->catid : $item->dpfieldscatid; self::$fieldsCache->setState('filter.catid', is_array($catids) ? $catids : explode(',', $catids)); } $fields = self::$fieldsCache->getItems(); if ($item && isset($item->id)) { if (self::$fieldCache === null) { self::$fieldCache = JModelLegacy::getInstance('Field', 'DPFieldsModel', array('ignore_request' => true)); } $new = array(); foreach ($fields as $key => $original) { // Doing a clone, otherwise fields for different items will // always reference to the same object $field = clone $original; $field->value = self::$fieldCache->getFieldValue($field->id, $field->context, $item->id); if (!$field->value) { $field->value = $field->default_value; } $field->rawvalue = $field->value; if ($prepareValue) { $type = self::loadTypeObject($field->type, $field->context); if ($type) { $field->value = $type->prepareValueForDisplay($field->value, $field); } } $new[$key] = $field; } $fields = $new; } return $fields; }
private function getParts($context) { $parts = DPFieldsHelper::extract($context); if (!$parts) { return null; } // Check for supported contexts $component = $parts[0]; if (key_exists($component, $this->supportedContexts)) { $section = $this->supportedContexts[$component]; // All sections separated with a , after the first ones are aliases if (strpos($section, ',') !== false) { $sectionParts = explode(',', $section); if (in_array($parts[1], $sectionParts)) { $parts[1] = $sectionParts[0]; } } } else { if ($parts[1] == 'form') { // The context is not from a known one, we need to do a lookup $db = JFactory::getDbo(); $db->setQuery('select context from #__dpfields_fields where context like ' . $db->q($parts[0] . '.%') . ' group by context'); $tmp = $db->loadObjectList(); if (count($tmp) == 1) { $parts = DPFieldsHelper::extract($tmp[0]->context); if (count($parts) < 2) { return null; } } } } return $parts; }
protected function loadFormData() { // Check the session for previously entered form data. $app = JFactory::getApplication(); $data = $app->getUserState('com_dpfields.edit.' . $this->getName() . '.data', array()); if (empty($data)) { $data = $this->getItem(); // Pre-select some filters (Status, Language, Access) in edit form // if those have been selected in Category Manager if (!$data->id) { // Check for which context the Category Manager is used and // get selected fields $context = substr($app->getUserState('com_dpfields.fields.filter.context'), 4); $component = DPFieldsHelper::extract($context); $component = $component ? $component[0] : null; $filters = (array) $app->getUserState('com_dpfields.fields.' . $component . '.filter'); $data->set('published', $app->input->getInt('published', !empty($filters['published']) ? $filters['published'] : null)); $data->set('language', $app->input->getString('language', !empty($filters['language']) ? $filters['language'] : null)); $data->set('access', $app->input->getInt('access', !empty($filters['access']) ? $filters['access'] : JFactory::getConfig()->get('access'))); } } $this->preprocessData('com_dpfields.field', $data); return $data; }
JLoader::register('DPFieldsHelper', JPATH_ADMINISTRATOR . '/components/com_dpfields/helpers/dpfields.php'); $parts = explode('.', $context); $component = $parts[0]; // Load some output definitions $container = 'dl'; if (key_exists('container', $displayData) && $displayData['container']) { $container = $displayData['container']; } $class = 'article-info muted'; if (key_exists('container-class', $displayData) && $displayData['container-class']) { $class = $displayData['container-class']; } // Print the container tag echo '<' . $container . ' class="' . $class . '">'; // Loop trough the fields and print them foreach (DPFieldsHelper::getFields($context, $item, true) as $field) { // If the value is empty dp nothing if (!isset($field->value) || !$field->value) { continue; } $output = JLayoutHelper::render('field.render', array('label' => $field->label, 'value' => $field->value), null, array('component' => $component, 'client' => 0)); /* * Because the layout refreshes the paths before the render function is * called, so there is no way to load the layout overrides in the order * template -> context -> dpfields. * If there is no override in the context then we need to call the layout * from DPField. */ if (!$output) { $output = JLayoutHelper::render('field.render', array('label' => $field->label, 'value' => $field->value), null, array('component' => 'com_dpfields', 'client' => 0)); }
protected function getListQuery() { // Create a new query object. $db = $this->getDbo(); $query = $db->getQuery(true); $user = JFactory::getUser(); // Select the required fields from the table. $query->select($this->getState('list.select', 'a.*')); $query->from('#__dpfields_fields AS a'); // Join over the language $query->select('l.title AS language_title')->join('LEFT', $db->quoteName('#__languages') . ' AS l ON l.lang_code = a.language'); // Join over the users for the checked out user. $query->select('uc.name AS editor')->join('LEFT', '#__users AS uc ON uc.id=a.checked_out'); // Join over the asset groups. $query->select('ag.title AS access_level')->join('LEFT', '#__viewlevels AS ag ON ag.id = a.access'); // Join over the users for the author. $query->select('ua.name AS author_name')->join('LEFT', '#__users AS ua ON ua.id = a.created_user_id'); // Filter by context if ($context = $this->getState('filter.context')) { $query->where('a.context = ' . $db->quote($context)); } // Filter by access level. if ($access = $this->getState('filter.access')) { if (is_array($access)) { JArrayHelper::toInteger($access); $query->where('a.access in (' . implode(',', $access) . ')'); } else { $query->where('a.access = ' . (int) $access); } } if (($categories = $this->getState('filter.catid')) && $context) { $categories = (array) $categories; $condition = 'a.catid = 0 '; $parts = DPFieldsHelper::extract($context); if ($parts) { // Get the category $cat = JCategories::getInstance(str_replace('com_', '', $parts[0])); if ($cat) { foreach ($categories as $catId) { // Check if we have the actual category $parent = $cat->get($catId); if ($parent) { $condition .= 'or find_in_set(' . (int) $parent->id . ',a.catid) '; // Traverse the tree up to get all the fields which // are attached to a parent while ($parent->getParent() && $parent->getParent()->id != 'root') { $parent = $parent->getParent(); $condition .= 'or find_in_set(' . (int) $parent->id . ',a.catid) '; } } } } } $query->where('(' . $condition . ')'); } // Implement View Level Access if (!$user->authorise('core.admin')) { $groups = implode(',', $user->getAuthorisedViewLevels()); $query->where('a.access IN (' . $groups . ')'); } // Filter by published state $published = $this->getState('filter.published'); if (is_numeric($published)) { $query->where('a.state = ' . (int) $published); } elseif ($published === '') { $query->where('(a.state IN (0, 1))'); } // Filter by search in title $search = $this->getState('filter.search'); if (!empty($search)) { if (stripos($search, 'id:') === 0) { $query->where('a.id = ' . (int) substr($search, 3)); } elseif (stripos($search, 'author:') === 0) { $search = $db->quote('%' . $db->escape(substr($search, 7), true) . '%'); $query->where('(ua.name LIKE ' . $search . ' OR ua.username LIKE ' . $search . ')'); } else { $search = $db->quote('%' . str_replace(' ', '%', $db->escape(trim($search), true) . '%')); $query->where('(a.title LIKE ' . $search . ' OR a.alias LIKE ' . $search . ' OR a.note LIKE ' . $search . ')'); } } // Filter on the language. if ($language = $this->getState('filter.language')) { $query->where('a.language in (' . $db->quote($language) . ',' . $db->quote('*') . ')'); } // Filter by a single tag. $tagId = $this->getState('filter.tag'); if (is_numeric($tagId)) { $query->where($db->quoteName('tagmap.tag_id') . ' = ' . (int) $tagId)->join('LEFT', $db->quoteName('#__contentitem_tag_map', 'tagmap') . ' ON ' . $db->quoteName('tagmap.content_item_id') . ' = ' . $db->quoteName('a.id') . ' AND ' . $db->quoteName('tagmap.type_alias') . ' = ' . $db->quote($context . '.field')); } // Add the list ordering clause $listOrdering = $this->getState('list.ordering', 'a.ordering'); $listDirn = $db->escape($this->getState('list.direction', 'ASC')); if ($listOrdering == 'a.access') { $query->order('a.access ' . $listDirn); } else { $query->order($db->escape($listOrdering) . ' ' . $listDirn); } // Echo nl2br(str_replace('#__', 'j_', $query)); die(); return $query; }
if (!key_exists('item', $displayData) || !key_exists('context', $displayData)) { return; } // Setting up for display $item = $displayData['item']; if (!$item) { return; } $context = $displayData['context']; if (!$context) { return; } JLoader::register('DPFieldsHelper', JPATH_ADMINISTRATOR . '/components/com_dpfields/helpers/dpfields.php'); $parts = explode('.', $context); $component = $parts[0]; $fields = DPFieldsHelper::getFields($context, $item, true); if (!$fields) { return; } // Load some output definitions $container = 'dl'; if (key_exists('container', $displayData) && $displayData['container']) { $container = $displayData['container']; } $class = 'article-info muted'; if (key_exists('container-class', $displayData) && $displayData['container-class']) { $class = $displayData['container-class']; } // Print the container tag echo '<' . $container . ' class="' . $class . '">'; // Loop trough the fields and print them