/** * Replace string with tags that reference fields * * @param string $text Text to process * * @return string Text with tags replace */ protected function parseFieldTags($text) { $ret = $text; // Replace [ITEM:ID] in the URL with the item's key value (usually: // the auto-incrementing numeric ID) if (is_null($this->item)) { $this->item = $this->form->getModel(); } $keyfield = $this->item->getKeyName(); $replace = $this->item->{$keyfield}; $ret = str_replace('[ITEM:ID]', $replace, $ret); // Replace the [ITEMID] in the URL with the current Itemid parameter $ret = str_replace('[ITEMID]', $this->form->getContainer()->input->getInt('Itemid', 0), $ret); // Replace other field variables in the URL $fields = $this->item->getTableFields(); foreach ($fields as $fielddata) { $fieldname = $fielddata->Field; if (empty($fieldname)) { $fieldname = $fielddata->column_name; } $search = '[ITEM:' . strtoupper($fieldname) . ']'; $replace = $this->item->{$fieldname}; if (!is_string($replace)) { continue; } $ret = str_replace($search, $replace, $ret); } return $ret; }
/** * Replace string with tags that reference fields * * @param string $text Text to process * * @return string Text with tags replace */ protected function parseFieldTags($text) { $ret = $text; // Replace [ITEM:ID] in the URL with the item's key value (usually: // the auto-incrementing numeric ID) if (is_null($this->item)) { $this->item = $this->form->getModel(); } $replace = $this->item->getId(); $ret = str_replace('[ITEM:ID]', $replace, $ret); // Replace the [ITEMID] in the URL with the current Itemid parameter $ret = str_replace('[ITEMID]', $this->form->getContainer()->input->getInt('Itemid', 0), $ret); // Replace the [TOKEN] in the URL with the Joomla! form token $ret = str_replace('[TOKEN]', \JFactory::getSession()->getFormToken(), $ret); // Replace other field variables in the URL $data = $this->item->getData(); foreach ($data as $field => $value) { // Skip non-processable values if (is_array($value) || is_object($value)) { continue; } $search = '[ITEM:' . strtoupper($field) . ']'; $ret = str_replace($search, $value, $ret); } return $ret; }
/** * Method to get a list of tags * * @return array The field option objects. * * @since 3.1 */ protected function getOptions() { $published = $this->element['published'] ? $this->element['published'] : array(0, 1); $db = $this->form->getContainer()->platform->getDbo(); $query = $db->getQuery(true)->select('a.id AS value, a.path, a.title AS text, a.level, a.published')->from('#__tags AS a')->join('LEFT', $db->quoteName('#__tags') . ' AS b ON a.lft > b.lft AND a.rgt < b.rgt'); if ($this->item instanceof DataModel) { $item = $this->item; } else { $item = $this->form->getModel(); } if ($item instanceof DataModel) { // Fake value for selected tags $keyfield = $item->getKeyName(); $content_id = $item->{$keyfield}; $type = $item->getContentType(); $selected_query = $db->getQuery(true); $selected_query->select('tag_id')->from('#__contentitem_tag_map')->where('content_item_id = ' . (int) $content_id)->where('type_alias = ' . $db->quote($type)); $db->setQuery($selected_query); $this->value = $db->loadColumn(); } // Ajax tag only loads assigned values if (!$this->isNested()) { // Only item assigned values $values = (array) $this->value; \JArrayHelper::toInteger($values); $query->where('a.id IN (' . implode(',', $values) . ')'); } // Filter language if (!empty($this->element['language'])) { $query->where('a.language = ' . $db->quote($this->element['language'])); } $query->where($db->quoteName('a.alias') . ' <> ' . $db->quote('root')); // Filter to only load active items // Filter on the published state if (is_numeric($published)) { $query->where('a.published = ' . (int) $published); } elseif (is_array($published)) { \JArrayHelper::toInteger($published); $query->where('a.published IN (' . implode(',', $published) . ')'); } $query->group('a.id, a.title, a.level, a.lft, a.rgt, a.parent_id, a.published, a.path')->order('a.lft ASC'); // Get the options. $db->setQuery($query); try { $options = $db->loadObjectList(); } catch (\RuntimeException $e) { return false; } // Prepare nested data if ($this->isNested()) { $this->prepareOptionsNested($options); } else { $options = \JHelperTags::convertPathsToNames($options); } return $options; }
/** * Returns the rendered view template * * @return string */ protected function getRenderedTemplate($isRepeatable = false) { $sourceTemplate = isset($this->element['source']) ? (string) $this->element['source'] : null; $sourceView = isset($this->element['source_view']) ? (string) $this->element['source_view'] : null; $sourceViewType = isset($this->element['source_view_type']) ? (string) $this->element['source_view_type'] : 'html'; $sourceComponent = isset($this->element['source_component']) ? (string) $this->element['source_component'] : null; if (empty($sourceTemplate)) { return ''; } $sourceContainer = empty($sourceComponent) ? $this->form->getContainer() : Container::getInstance($sourceComponent); if (empty($sourceView)) { $viewObject = new View($sourceContainer, array('name' => 'FAKE_FORM_VIEW')); } else { $viewObject = $sourceContainer->factory->view($sourceView, $sourceViewType); } $viewObject->populateFromModel($this->form->getModel()); return $viewObject->loadAnyTemplate($sourceTemplate, array('model' => $isRepeatable ? $this->item : $this->form->getModel(), 'form' => $this->form, 'formType' => $this->form->getAttribute('type', 'edit'), 'fieldValue' => $this->value, 'fieldElement' => $this->element)); }
/** * Returns the rendered view template * * @return string */ protected function getCallbackResults() { $source_file = empty($this->element['source_file']) ? '' : (string) $this->element['source_file']; $source_class = empty($this->element['source_class']) ? '' : (string) $this->element['source_class']; $source_method = empty($this->element['source_method']) ? '' : (string) $this->element['source_method']; if (empty($source_class) || empty($source_method)) { return ''; } // Maybe we have to load a file? if (!empty($source_file)) { $source_file = $this->form->getContainer()->template->parsePath($source_file, true); if ($this->form->getContainer()->filesystem->fileExists($source_file)) { include_once $source_file; } } // Make sure the class exists if (class_exists($source_class, true)) { // ...and so does the option if (in_array($source_method, get_class_methods($source_class))) { return $source_class::$source_method(array('model' => $this->form->getModel(), 'form' => $this->form, 'formType' => $this->form->getAttribute('type', 'edit'), 'fieldValue' => $this->value, 'fieldElement' => $this->element)); } } return ''; }
/** * Method to get the field input markup for this field type. * * @since 2.0 * * @return string The field input markup. */ protected function getInput() { $html = array(); $attr = ''; // Initialize some field attributes. $attr .= !empty($this->class) ? ' class="' . $this->class . '"' : ''; $attr .= $this->disabled ? ' disabled' : ''; $attr .= !empty($this->size) ? ' size="' . $this->size . '"' : ''; // Initialize JavaScript field attributes. $attr .= !empty($this->onchange) ? ' onchange="' . $this->onchange . '"' : ''; $this->item = $this->form->getModel(); $keyfield = $this->item->getKeyName(); $itemId = $this->item->{$keyfield}; $query = $this->getQuery(); // Create a read-only list (no name) with a hidden input to store the value. if ($this->readonly) { $html[] = JHtml::_('list.ordering', '', $query, trim($attr), $this->value, $itemId ? 0 : 1); $html[] = '<input type="hidden" name="' . $this->name . '" value="' . $this->value . '"/>'; } else { // Create a regular list. $html[] = JHtml::_('list.ordering', $this->name, $query, trim($attr), $this->value, $itemId ? 0 : 1); } return implode($html); }
/** * Method to get the field input markup. * * @param array $fieldOptions Options to be passed into the field * * @return string The field HTML */ public function getFieldContents(array $fieldOptions = array()) { $id = isset($fieldOptions['id']) ? 'id="' . $fieldOptions['id'] . '" ' : ''; $class = $this->class . (isset($fieldOptions['class']) ? ' ' . $fieldOptions['class'] : ''); $front_link = $this->element['front_link'] ? (string) $this->element['front_link'] : false; $translate = $this->element['translate'] ? (string) $this->element['translate'] : false; $tagIds = is_array($this->value) ? implode(',', $this->value) : $this->value; if (!$this->item instanceof DataModel) { $this->item = $this->form->getModel(); } if ($tagIds && $this->item instanceof DataModel) { $db = $this->form->getContainer()->platform->getDbo(); $query = $db->getQuery(true)->select(array($db->quoteName('id'), $db->quoteName('title')))->from($db->quoteName('#__tags'))->where($db->quoteName('id') . ' IN (' . $tagIds . ')'); $query->order($db->quoteName('title')); $db->setQuery($query); $tags = $db->loadObjectList(); $html = ''; foreach ($tags as $tag) { $html .= '<span>'; if ($front_link) { \JLoader::register('TagsHelperRoute', \JPATH_SITE . '/components/com_tags/helpers/route.php'); $html .= '<a href="' . \JRoute::_(\TagsHelperRoute::getTagRoute($tag->id)) . '">'; } if ($translate == true) { $html .= \JText::_($tag->title); } else { $html .= $tag->title; } if ($front_link) { $html .= '</a>'; } $html .= '</span>'; } } return '<span ' . ($id ? $id : '') . 'class="' . $class . '">' . $html . '</span>'; }
/** * At the timing of this writing (2013-12-03), the Joomla "rules" field is buggy. When you are * dealing with a new record it gets the default permissions from the root asset node, which * is fine for the default permissions of Joomla articles, but unsuitable for third party software. * We had to copy & paste the whole code, since we can't "inject" the correct asset id if one is * not found. Our fixes are surrounded by `FOF Library fix` remarks. * * @return string The input field's HTML for this field type */ protected function getInput() { JHtml::_('bootstrap.tooltip'); // Initialise some field attributes. $section = $this->section; $component = $this->component; $assetField = $this->assetField; // Get the actions for the asset. $actions = \JAccess::getActions($component, $section); // Iterate over the children and add to the actions. /** @var \SimpleXMLElement $el */ foreach ($this->element->children() as $el) { if ($el->getName() == 'action') { $actions[] = (object) array('name' => (string) $el['name'], 'title' => (string) $el['title'], 'description' => (string) $el['description']); } } // Get the explicit rules for this asset. if ($section == 'component') { // Need to find the asset id by the name of the component. $db = $this->form->getContainer()->platform->getDbo(); $query = $db->getQuery(true)->select($db->quoteName('id'))->from($db->quoteName('#__assets'))->where($db->quoteName('name') . ' = ' . $db->quote($component)); $assetId = (int) $db->setQuery($query)->loadResult(); } else { // Find the asset id of the content. // Note that for global configuration, com_config injects asset_id = 1 into the form. $assetId = $this->form->getValue($assetField); // ==== FOF Library fix - Start ==== // If there is no assetId (let's say we are dealing with a new record), let's ask the table // to give it to us. Here you should implement your logic (ie getting default permissions from // the component or from the category) if (!$assetId) { $table = $this->form->getModel(); $assetId = $table->getAssetParentId(); } // ==== FOF Library fix - End ==== } // Full width format. // Get the rules for just this asset (non-recursive). $assetRules = \JAccess::getAssetRules($assetId); // Get the available user groups. $groups = $this->getUserGroups(); // Prepare output $html = array(); // Description $html[] = '<p class="rule-desc">' . JText::_('JLIB_RULES_SETTINGS_DESC') . '</p>'; // Begin tabs $html[] = '<div id="permissions-sliders" class="tabbable tabs-left">'; // Building tab nav $html[] = '<ul class="nav nav-tabs">'; foreach ($groups as $group) { // Initial Active Tab $active = ""; if ($group->value == 1) { $active = "active"; } $html[] = '<li class="' . $active . '">'; $html[] = '<a href="#permission-' . $group->value . '" data-toggle="tab">'; $html[] = str_repeat('<span class="level">–</span> ', $curLevel = $group->level) . $group->text; $html[] = '</a>'; $html[] = '</li>'; } $html[] = '</ul>'; $html[] = '<div class="tab-content">'; // Start a row for each user group. foreach ($groups as $group) { // Initial Active Pane $active = ""; if ($group->value == 1) { $active = " active"; } $html[] = '<div class="tab-pane' . $active . '" id="permission-' . $group->value . '">'; $html[] = '<table class="table table-striped">'; $html[] = '<thead>'; $html[] = '<tr>'; $html[] = '<th class="actions" id="actions-th' . $group->value . '">'; $html[] = '<span class="acl-action">' . JText::_('JLIB_RULES_ACTION') . '</span>'; $html[] = '</th>'; $html[] = '<th class="settings" id="settings-th' . $group->value . '">'; $html[] = '<span class="acl-action">' . JText::_('JLIB_RULES_SELECT_SETTING') . '</span>'; $html[] = '</th>'; // The calculated setting is not shown for the root group of global configuration. $canCalculateSettings = $group->parent_id || !empty($component); if ($canCalculateSettings) { $html[] = '<th id="aclactionth' . $group->value . '">'; $html[] = '<span class="acl-action">' . JText::_('JLIB_RULES_CALCULATED_SETTING') . '</span>'; $html[] = '</th>'; } $html[] = '</tr>'; $html[] = '</thead>'; $html[] = '<tbody>'; foreach ($actions as $action) { $html[] = '<tr>'; $html[] = '<td headers="actions-th' . $group->value . '">'; $html[] = '<label for="' . $this->id . '_' . $action->name . '_' . $group->value . '" class="hasTooltip" title="' . htmlspecialchars(JText::_($action->title) . ' ' . JText::_($action->description), ENT_COMPAT, 'UTF-8') . '">'; $html[] = JText::_($action->title); $html[] = '</label>'; $html[] = '</td>'; $html[] = '<td headers="settings-th' . $group->value . '">'; $html[] = '<select class="input-small" name="' . $this->name . '[' . $action->name . '][' . $group->value . ']" id="' . $this->id . '_' . $action->name . '_' . $group->value . '" title="' . JText::sprintf('JLIB_RULES_SELECT_ALLOW_DENY_GROUP', JText::_($action->title), trim($group->text)) . '">'; $inheritedRule = \JAccess::checkGroup($group->value, $action->name, $assetId); // Get the actual setting for the action for this group. $assetRule = $assetRules->allow($action->name, $group->value); // Build the dropdowns for the permissions sliders // The parent group has "Not Set", all children can rightly "Inherit" from that. $html[] = '<option value=""' . ($assetRule === null ? ' selected="selected"' : '') . '>' . JText::_(empty($group->parent_id) && empty($component) ? 'JLIB_RULES_NOT_SET' : 'JLIB_RULES_INHERITED') . '</option>'; $html[] = '<option value="1"' . ($assetRule === true ? ' selected="selected"' : '') . '>' . JText::_('JLIB_RULES_ALLOWED') . '</option>'; $html[] = '<option value="0"' . ($assetRule === false ? ' selected="selected"' : '') . '>' . JText::_('JLIB_RULES_DENIED') . '</option>'; $html[] = '</select>  '; // If this asset's rule is allowed, but the inherited rule is deny, we have a conflict. if ($assetRule === true && $inheritedRule === false) { $html[] = JText::_('JLIB_RULES_CONFLICT'); } $html[] = '</td>'; // Build the Calculated Settings column. // The inherited settings column is not displayed for the root group in global configuration. if ($canCalculateSettings) { $html[] = '<td headers="aclactionth' . $group->value . '">'; // This is where we show the current effective settings considering currrent group, path and cascade. // Check whether this is a component or global. Change the text slightly. if (\JAccess::checkGroup($group->value, 'core.admin', $assetId) !== true) { if ($inheritedRule === null) { $html[] = '<span class="label label-important">' . JText::_('JLIB_RULES_NOT_ALLOWED') . '</span>'; } elseif ($inheritedRule === true) { $html[] = '<span class="label label-success">' . JText::_('JLIB_RULES_ALLOWED') . '</span>'; } elseif ($inheritedRule === false) { if ($assetRule === false) { $html[] = '<span class="label label-important">' . JText::_('JLIB_RULES_NOT_ALLOWED') . '</span>'; } else { $html[] = '<span class="label"><i class="icon-lock icon-white"></i> ' . JText::_('JLIB_RULES_NOT_ALLOWED_LOCKED') . '</span>'; } } } elseif (!empty($component)) { $html[] = '<span class="label label-success"><i class="icon-lock icon-white"></i> ' . JText::_('JLIB_RULES_ALLOWED_ADMIN') . '</span>'; } else { // Special handling for groups that have global admin because they can't be denied. // The admin rights can be changed. if ($action->name === 'core.admin') { $html[] = '<span class="label label-success">' . JText::_('JLIB_RULES_ALLOWED') . '</span>'; } elseif ($inheritedRule === false) { // Other actions cannot be changed. $html[] = '<span class="label label-important"><i class="icon-lock icon-white"></i> ' . JText::_('JLIB_RULES_NOT_ALLOWED_ADMIN_CONFLICT') . '</span>'; } else { $html[] = '<span class="label label-success"><i class="icon-lock icon-white"></i> ' . JText::_('JLIB_RULES_ALLOWED_ADMIN') . '</span>'; } } $html[] = '</td>'; } $html[] = '</tr>'; } $html[] = '</tbody>'; $html[] = '</table></div>'; } $html[] = '</div></div>'; $html[] = '<div class="alert">'; if ($section == 'component' || $section == null) { $html[] = JText::_('JLIB_RULES_SETTING_NOTES'); } else { $html[] = JText::_('JLIB_RULES_SETTING_NOTES_ITEM'); } $html[] = '</div>'; return implode("\n", $html); }
/** * Get the filter value for this header field * * @return mixed The filter value */ protected function getValue() { $model = $this->form->getModel(); return $model->getState($this->filterSource); }