С версии: 2.0
Наследование: extends JFor\JForm
Пример #1
0
Файл: Tag.php Проект: Joal01/fof
 /**
  * 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;
 }
Пример #2
0
 /**
  * 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;
 }
Пример #3
0
 /**
  * Translate a list of objects with JText::_().
  *
  * @param   \stdClass  $item  The component object
  * @param   string     $type  The extension type (e.g. component)
  *
  * @since   2.1
  *
  * @return  string  $text  The translated name of the extension
  *
  * @see administrator/com_installer/models/extension.php
  */
 public function translate($item, $type)
 {
     $platform = $this->form->getContainer()->platform;
     // Map the manifest cache to $item. This is needed to get the name from the
     // manifest_cache and NOT from the name column, else some JText::_() translations fails.
     $mData = json_decode($item->manifest_cache);
     if ($mData) {
         foreach ($mData as $key => $value) {
             if ($key == 'type') {
                 // Ignore the type field
                 continue;
             }
             $item->{$key} = $value;
         }
     }
     $lang = $platform->getLanguage();
     switch ($type) {
         case 'component':
             $source = JPATH_ADMINISTRATOR . '/components/' . $item->element;
             $lang->load("{$item->element}.sys", JPATH_ADMINISTRATOR, null, false, false) || $lang->load("{$item->element}.sys", $source, null, false, false) || $lang->load("{$item->element}.sys", JPATH_ADMINISTRATOR, $lang->getDefault(), false, false) || $lang->load("{$item->element}.sys", $source, $lang->getDefault(), false, false);
             break;
     }
     $text = JText::_($item->name);
     return $text;
 }
Пример #4
0
 /**
  * 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)
     $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;
 }
Пример #5
0
 /**
  * Builds the query for the ordering list.
  *
  * @since 2.3.2
  *
  * @return \JDatabaseQuery  The query for the ordering form field
  */
 protected function getQuery()
 {
     $ordering = $this->name;
     $title = $this->element['ordertitle'] ? (string) $this->element['ordertitle'] : $this->item->getFieldAlias('title');
     $db = $this->form->getContainer()->platform->getDbo();
     $query = $db->getQuery(true);
     $query->select(array($db->quoteName($ordering, 'value'), $db->quoteName($title, 'text')))->from($db->quoteName($this->item->getTableName()))->order($ordering);
     return $query;
 }
Пример #6
0
 /**
  * Returns the options for this control
  *
  * Adapted from JHtmlAccess::usergroup
  *
  * @return  \stdClass[]
  */
 protected function getOptions()
 {
     $db = $this->form->getContainer()->platform->getDbo();
     $query = $db->getQuery(true)->select('a.id AS value, a.title AS text, COUNT(DISTINCT b.id) AS level')->from($db->quoteName('#__usergroups') . ' AS a')->join('LEFT', $db->quoteName('#__usergroups') . ' AS b ON a.lft > b.lft AND a.rgt < b.rgt')->group('a.id, a.title, a.lft, a.rgt')->order('a.lft ASC');
     $db->setQuery($query);
     $options = $db->loadObjectList();
     for ($i = 0, $n = count($options); $i < $n; $i++) {
         $options[$i]->text = str_repeat('- ', $options[$i]->level) . $options[$i]->text;
     }
 }
Пример #7
0
 /**
  * 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())
 {
     $imgattr = array();
     if (isset($fieldOptions['id'])) {
         $imgattr['id'] = $fieldOptions['id'];
     }
     if ($this->class || isset($fieldOptions['class']) && $fieldOptions['class']) {
         $imgattr['class'] = $this->class . (isset($fieldOptions['class']) ? ' ' . $fieldOptions['class'] : '');
     }
     if ($this->element['style']) {
         $imgattr['style'] = (string) $this->element['style'];
     }
     if ($this->element['width']) {
         $imgattr['width'] = (string) $this->element['width'];
     }
     if ($this->element['height']) {
         $imgattr['height'] = (string) $this->element['height'];
     }
     if ($this->element['align']) {
         $imgattr['align'] = (string) $this->element['align'];
     }
     if ($this->element['rel']) {
         $imgattr['rel'] = (string) $this->element['rel'];
     }
     if ($this->element['alt']) {
         $alt = JText::_((string) $this->element['alt']);
     } else {
         $alt = null;
     }
     if ($this->element['title']) {
         $imgattr['title'] = JText::_((string) $this->element['title']);
     }
     $directory = '';
     if ($this->element['directory']) {
         $directory = (string) $this->element['directory'];
         $directory = trim($directory, '/\\') . '/';
     }
     $imagePath = $directory . $this->value;
     $platform = $this->form->getContainer()->platform;
     $baseDirs = $platform->getPlatformBaseDirs();
     if ($this->value && file_exists($baseDirs['root'] . '/' . $imagePath)) {
         $src = $platform->URIroot() . '/' . $imagePath;
         return JHtml::image($src, $alt, $imgattr);
     }
     // JHtml::image returns weird stuff when an empty path is provided, so let's be safe than sorry and return empty
     return '';
 }
Пример #8
0
 /**
  * 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'] : '');
     $params = $this->getOptions();
     $db = $this->form->getContainer()->platform->getDbo();
     $query = $db->getQuery(true)->select('a.id AS value, a.title AS text')->from('#__viewlevels AS a')->group('a.id, a.title, a.ordering')->order('a.ordering ASC')->order($db->qn('title') . ' ASC');
     // Get the options.
     $options = $db->setQuery($query)->loadObjectList();
     // If params is an array, push these options to the array
     if (is_array($params)) {
         $options = array_merge($params, $options);
     } elseif ($params) {
         array_unshift($options, JHtml::_('select.option', '', JText::_('JOPTION_ACCESS_SHOW_ALL_LEVELS')));
     }
     return '<span ' . ($id ? $id : '') . 'class="' . $class . '">' . htmlspecialchars(GenericList::getOptionName($options, $this->value), ENT_COMPAT, 'UTF-8') . '</span>';
 }
Пример #9
0
 /**
  * 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));
 }
Пример #10
0
 /**
  * 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())
 {
     $imgattr = array();
     if ($fieldOptions['id']) {
         $imgattr['id'] = $fieldOptions['id'];
     }
     if ($this->class || $fieldOptions['class']) {
         $imgattr['class'] = $this->class . (isset($fieldOptions['class']) ? ' ' . $fieldOptions['class'] : '');
     }
     if ($this->element['style']) {
         $imgattr['style'] = (string) $this->element['style'];
     }
     if ($this->element['width']) {
         $imgattr['width'] = (string) $this->element['width'];
     }
     if ($this->element['height']) {
         $imgattr['height'] = (string) $this->element['height'];
     }
     if ($this->element['align']) {
         $imgattr['align'] = (string) $this->element['align'];
     }
     if ($this->element['rel']) {
         $imgattr['rel'] = (string) $this->element['rel'];
     }
     if ($this->element['alt']) {
         $alt = JText::_((string) $this->element['alt']);
     } else {
         $alt = null;
     }
     if ($this->element['title']) {
         $imgattr['title'] = JText::_((string) $this->element['title']);
     }
     $path = (string) $this->element['directory'];
     $path = trim($path, '/' . DIRECTORY_SEPARATOR);
     if ($this->value && file_exists(JPATH_ROOT . '/' . $path . '/' . $this->value)) {
         $src = $this->form->getContainer()->platform->URIroot() . '/' . $path . '/' . $this->value;
     } else {
         $src = '';
     }
     return JHtml::image($src, $alt, $imgattr);
 }
Пример #11
0
 /**
  * Get the rendering of this field type for a repeatable (grid) display,
  * e.g. in a view listing many item (typically a "browse" task)
  *
  * @since 2.0
  *
  * @return  string  The field HTML
  *
  * @throws  DataModelRequired
  */
 public function getRepeatable()
 {
     // Should I support checked-out elements?
     $checkoutSupport = false;
     if (isset($this->element['checkout'])) {
         $checkoutSupportValue = (string) $this->element['checkout'];
         $checkoutSupport = in_array(strtolower($checkoutSupportValue), array('yes', 'true', 'on', 1));
     }
     if (!$this->item instanceof DataModel) {
         throw new DataModelRequired(__CLASS__);
     }
     // Is this record checked out?
     $userId = $this->form->getContainer()->platform->getUser()->get('id', 0);
     $checked_out = false;
     if ($checkoutSupport) {
         $checked_out = $this->item->isLocked($userId);
     }
     // Get the key id for this record
     $key_field = $this->item->getKeyName();
     $key_id = $this->item->{$key_field};
     // Get the HTML
     return JHtml::_('grid.id', $this->rowid, $key_id, $checked_out);
 }
Пример #12
0
Файл: Tag.php Проект: akeeba/fof
 /**
  * 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>';
 }
Пример #13
0
 /**
  * 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 '';
 }
Пример #14
0
 /**
  * Creates a new Form object
  *
  * @param   string  $name      The name of the form.
  * @param   string  $source    The form source filename without path and .xml extension e.g. "form.default" OR raw XML data
  * @param   string  $viewName  The name of the view you're getting the form for.
  * @param   array   $options   Options to the Form object
  * @param   bool    $replace   Should form fields be replaced if a field already exists with the same group/name?
  * @param   bool    $xpath     An optional xpath to search for the fields.
  *
  * @return  Form|null  The loaded form or null if the form filename doesn't exist
  *
  * @throws  \RuntimeException If the form exists but cannot be loaded
  */
 public function form($name, $source, $viewName, array $options = array(), $replace = true, $xpath = false)
 {
     // Get a new form instance
     $form = new Form($this->container, $name, $options);
     // If $source looks like raw XML data, parse it directly
     if (strpos($source, '<form') !== false) {
         if ($form->load($source, $replace, $xpath) === false) {
             throw new FormLoadData();
         }
         return $form;
     }
     $formFileName = $this->getFormFilename($source, $viewName);
     if (empty($formFileName)) {
         if ($this->scaffolding) {
             $scaffolding = new ScaffoldingBuilder($this->container);
             $xml = $scaffolding->make($source, $viewName);
             if (!is_null($xml)) {
                 return $this->form($name, $xml, $viewName, $options, $replace, $xpath);
             }
         }
         return null;
     }
     if ($form->loadFile($formFileName, $replace, $xpath) === false) {
         throw new FormLoadFile($source);
     }
     return $form;
 }
Пример #15
0
 /**
  * Renders a label for a fieldset.
  *
  * @param   object  $field  The field of the label to render
  * @param   Form   	&$form  The form to render
  * @param 	string  $title  The title of the label
  *
  * @return 	string  The rendered label
  */
 public function renderFieldsetLabel($field, Form &$form, $title)
 {
     $html = '';
     $labelClass = $field->labelClass ? $field->labelClass : $field->labelclass;
     // Joomla! 2.5/3.x use different case for the same name
     $required = $field->required;
     $tooltip = $form->getFieldAttribute($field->fieldname, 'tooltip', '', $field->group);
     if (!empty($tooltip)) {
         JHtml::_('bootstrap.tooltip');
         $tooltipText = '<strong>' . JText::_($title) . '</strong><br />' . JText::_($tooltip);
         $html .= "\t\t\t\t" . '<label class="control-label hasTooltip ' . $labelClass . '" for="' . $field->id . '" title="' . $tooltipText . '" rel="tooltip">';
     } else {
         $html .= "\t\t\t\t" . '<label class="control-label ' . $labelClass . '" for="' . $field->id . '">';
     }
     $html .= JText::_($title);
     if ($required) {
         $html .= ' *';
     }
     $html .= "</label>\n";
     return $html;
 }
Пример #16
0
 /**
  * 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">&ndash;</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>&#160; ';
             // 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);
 }
Пример #17
0
 /**
  * Renders a Form and returns the corresponding HTML
  *
  * @param   Form      &$form         The form to render
  * @param   DataModel $model         The model providing our data
  * @param   string    $formType      The form type: edit, browse or read
  * @param   boolean   $raw           If true, the raw form fields rendering (without the surrounding form tag) is
  *                                   returned.
  *
  * @return  string    The HTML rendering of the form
  */
 function renderForm(Form &$form, DataModel $model, $formType = null, $raw = false)
 {
     $useChosen = $form->getAttribute('chosen', 'select');
     $useChosen = in_array($useChosen, array('false', 'no', 'off', '0')) ? '' : $useChosen;
     if ($useChosen) {
         \JHtml::_('formbehavior.chosen', $useChosen);
     }
     if (is_null($formType)) {
         $formType = $form->getAttribute('type', 'edit');
     } else {
         $formType = strtolower($formType);
     }
     switch ($formType) {
         case 'browse':
             return $this->renderFormBrowse($form, $model);
             break;
         case 'read':
             if ($raw) {
                 return $this->renderFormRaw($form, $model, 'read');
             } else {
                 return $this->renderFormRead($form, $model);
             }
             break;
         default:
             if ($raw) {
                 return $this->renderFormRaw($form, $model, 'edit');
             } else {
                 return $this->renderFormEdit($form, $model);
             }
             break;
     }
 }
Пример #18
0
 /**
  * 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);
 }
Пример #19
0
 /**
  * Method to get the calendar input markup.
  *
  * @param   string  $display  The display to render ('static' or 'repeatable')
  *
  * @return  string	The field input markup.
  *
  * @since   2.1.rc4
  */
 protected function getCalendar($display)
 {
     // Initialize some field attributes.
     $format = $this->format ? $this->format : '%Y-%m-%d';
     $class = $this->class ? $this->class : '';
     $default = $this->element['default'] ? (string) $this->element['default'] : '';
     // Get some system objects.
     $config = $this->form->getContainer()->platform->getConfig();
     $user = $this->form->getContainer()->platform->getUser();
     // Check for empty date values
     if (empty($this->value) || $this->value == $this->form->getContainer()->platform->getDbo()->getNullDate() || $this->value == '0000-00-00') {
         $this->value = $default;
     }
     // Handle the special case for "now".
     if (strtoupper($this->value) == 'NOW') {
         $this->value = strftime($format);
     }
     // If a known filter is given use it.
     switch (strtoupper($this->filter)) {
         case 'SERVER_UTC':
             // Convert a date to UTC based on the server timezone.
             if ((int) $this->value) {
                 // Get a date object based on the correct timezone.
                 $date = \JFactory::getDate($this->value, 'UTC');
                 $date->setTimezone(new \DateTimeZone($config->get('offset')));
                 // Transform the date string.
                 $this->value = $date->format('Y-m-d H:i:s', true, false);
             }
             break;
         case 'USER_UTC':
             // Convert a date to UTC based on the user timezone.
             if ((int) $this->value) {
                 // Get a date object based on the correct timezone.
                 $date = \JFactory::getDate($this->value, 'UTC');
                 $date->setTimezone(new \DateTimeZone($user->getParam('timezone', $config->get('offset'))));
                 // Transform the date string.
                 $this->value = $date->format('Y-m-d H:i:s', true, false);
             }
             break;
     }
     if ($display == 'static') {
         // Build the attributes array.
         $attributes = array();
         if ($this->size) {
             $attributes['size'] = $this->size;
         }
         if ($this->maxlength) {
             $attributes['maxlength'] = $this->maxlength;
         }
         if ($this->class) {
             $attributes['class'] = $this->class;
         }
         if ($this->readonly) {
             $attributes['readonly'] = 'readonly';
         }
         if ($this->disabled) {
             $attributes['disabled'] = 'disabled';
         }
         if ($this->onchange) {
             $attributes['onchange'] = $this->onchange;
         }
         if ($this->required) {
             $attributes['required'] = 'required';
             $attributes['aria-required'] = 'true';
         }
         // Including fallback code for HTML5 non supported browsers.
         JHtml::_('jquery.framework');
         JHtml::_('script', 'system/html5fallback.js', false, true);
         return JHtml::_('calendar', $this->value, $this->name, $this->id, $format, $attributes);
     } else {
         if (!$this->value && (string) $this->element['empty_replacement']) {
             $value = $this->element['empty_replacement'];
         } else {
             $jDate = new \JDate($this->value);
             $value = strftime($format, $jDate->getTimestamp());
         }
         return '<span class="' . $this->id . ' ' . $class . '">' . htmlspecialchars($value, ENT_COMPAT, 'UTF-8') . '</span>';
     }
 }
Пример #20
0
 /**
  * Method to validate the form data.
  *
  * @param   Form     $form   The form to validate against.
  * @param   array    $data   The data to validate.
  * @param   string   $group  The name of the field group to validate.
  *
  * @return  mixed   Array of filtered data if valid, false otherwise.
  *
  * @throws  BaseException|\Exception  On validation error
  *
  * @see     \JFormRule
  * @see     \JFilterInput
  *
  * @since   2.0
  */
 public function validateForm($form, $data, $group = null)
 {
     // Filter and validate the form data.
     $data = $form->filter($data);
     $return = $form->validate($data, $group);
     // Check for an error.
     if ($return instanceof \Exception) {
         throw $return;
     }
     // Check the validation results.
     if ($return === false) {
         // Get the validation messages from the form.
         foreach ($form->getErrors() as $message) {
             if ($message instanceof \Exception) {
                 throw $message;
             } else {
                 throw new BaseException($message);
             }
         }
         return false;
     }
     return $data;
 }