コード例 #1
0
 /**
  * @since       1.2.0
  *
  */
 public static function getParams($key, JObject $extensions, $default = null)
 {
     $value = $default;
     $isEmptyValue = true;
     // get module param
     if (!property_exists($extensions, 'module.off')) {
         $valueName = 'module.value';
         if (property_exists($extensions, $valueName)) {
             $value = $extensions->{$valueName};
             if ($value !== null && $value !== '') {
                 $isEmptyValue = false;
             }
         } else {
             if ($moduleID = (int) $extensions->get('module.id')) {
                 if (!is_null($value = KextensionsModule::getParams($moduleID)->get($key))) {
                     $isEmptyValue = false;
                 }
             }
         }
     }
     // get plugin param
     if ($isEmptyValue && !property_exists($extensions, 'plugin.off')) {
         $valueName = 'plugin.value';
         if (property_exists($extensions, $valueName)) {
             $value = $extensions->{$valueName};
             if ($value !== null && $value !== '') {
                 $isEmptyValue = false;
             }
         } else {
             if (($type = $extensions->get('plugin.type', 'fieldsandfiltersExtensions')) && ($name = $extensions->get('plugin.name'))) {
                 if (!is_null($value = KextensionsPlugin::getParams($type, $name)->get($key))) {
                     $isEmptyValue = false;
                 }
             }
         }
     }
     // get component param
     if ($isEmptyValue && !property_exists($extensions, 'component.off')) {
         $valueName = 'component.value';
         if (property_exists($extensions, $valueName)) {
             $value = $extensions->{$valueName};
             if ($value !== null && $value !== '') {
                 $isEmptyValue = false;
             }
         } else {
             if ($option = $extensions->get('component.option', 'com_fieldsandfilters')) {
                 if (!is_null($value = JComponentHelper::getParams($option)->get($key))) {
                     $isEmptyValue = false;
                 }
             }
         }
     }
     return !$isEmptyValue ? $value : $default;
 }
コード例 #2
0
 /**
  * onFieldsandfiltersPrepareFormField
  *
  * @param    KextensionsForm $form     The form to be altered.
  * @param    JObject         $data     The associated data for the form.
  * @param   boolean          $isNew    Is element is new
  * @param   string           $fieldset Fieldset name
  *
  * @return    boolean
  * @since    1.1.0
  */
 public function onFieldsandfiltersPrepareFormField(KextensionsForm $form, JObject $data, $isNew = false, $fieldset = 'fieldsandfilters')
 {
     if (!($fields = $data->get($this->_name))) {
         return true;
     }
     // Load Array Helper
     $fields = is_array($fields) ? $fields : array($fields);
     $staticMode = (array) FieldsandfiltersModes::getMode(FieldsandfiltersModes::MODE_STATIC);
     $syntax = KextensionsPlugin::getParams('system', 'fieldsandfilters')->get('syntax', '#{%s}');
     while ($field = array_shift($fields)) {
         $root = new SimpleXMLElement('<fields />');
         $root->addAttribute('name', 'data');
         if ($field->params->get('type.hidden', 0)) {
             $element = $root->addChild('field');
             $element->addAttribute('type', 'hidden');
         } else {
             if (!empty($field->description) && $field->params->get('base.admin_enabled_description', 0)) {
                 switch ($field->params->get('base.admin_description_type', 'description')) {
                     case 'tip':
                         $element = $root->addChild('field');
                         $element->addAttribute('description', $field->description);
                         $element->addAttribute('translate_description', 'false');
                         break;
                     case 'description':
                     default:
                         $element = $root->addChild('field');
                         $element->addAttribute('type', 'spacer');
                         $element->addAttribute('name', 'description_spacer_' . $field->id);
                         $element->addAttribute('label', $field->description);
                         $element->addAttribute('translate_label', 'false');
                         $element->addAttribute('fieldset', $fieldset);
                         $element = $root->addChild('field');
                         break;
                 }
             } else {
                 $element = $root->addChild('field');
             }
             $label = '<strong>' . $field->name . '</strong> ' . sprintf($syntax, $field->id);
             if ($field->state == -1) {
                 $label .= ' [' . JText::_('PLG_FIELDSANDFILTERS_FORM_ONLY_ADMIN') . ']';
             }
             if (in_array($field->mode, $staticMode)) {
                 $element->addAttribute('type', 'spacer');
                 $element->addAttribute('description', $field->data);
                 $element->addAttribute('translate_description', 'false');
                 $label .= ' [' . JText::_('PLG_FIELDSANDFILTERS_FORM_GROUP_STATIC_TITLE') . ']';
             } else {
                 if ($field->params->get('type.readonly', 0)) {
                     $element->addAttribute('class', 'readonly');
                 } else {
                     $element->addAttribute('class', 'inputbox');
                 }
                 $element->addAttribute('type', 'text');
                 if ($field->required) {
                     $element->addAttribute('required', 'true');
                 }
             }
             $element->addAttribute('labelclass', 'control-label');
             $element->addAttribute('label', $label);
             $element->addAttribute('translate_label', 'false');
         }
         $element->addAttribute('id', $field->id);
         $element->addAttribute('name', $field->id);
         $element->addAttribute('fieldset', $fieldset);
         // hr bottom spacer
         $element = $root->addChild('field');
         $element->addAttribute('type', 'spacer');
         $element->addAttribute('name', 'hr_bottom_spacer_' . $field->id);
         $element->addAttribute('hr', 'true');
         $element->addAttribute('fieldset', $fieldset);
         $form->addOrder($field->id, $field->ordering)->setField($field->id, $root);
     }
     return true;
 }
コード例 #3
0
 /**
  * onFieldsandfiltersPrepareFormField
  *
  * @param    KextensionsForm $form     The form to be altered.
  * @param    JObject         $data     The associated data for the form.
  * @param   boolean          $isNew    Is element is new
  * @param   string           $fieldset Fieldset name
  *
  * @return    boolean
  * @since    1.1.0
  */
 public function onFieldsandfiltersPrepareFormField(KextensionsForm $form, JObject $data, $isNew = false, $fieldset = 'fieldsandfilters')
 {
     if (!($fields = $data->get($this->_name))) {
         return true;
     }
     $fields = is_array($fields) ? $fields : array($fields);
     $staticMode = (array) FieldsandfiltersModes::getMode(FieldsandfiltersModes::MODE_STATIC);
     $syntax = KextensionsPlugin::getParams('system', 'fieldsandfilters')->get('syntax', '#{%s}');
     while ($field = array_shift($fields)) {
         $root = new SimpleXMLElement('<fields />');
         $root->addAttribute('name', 'data');
         $rootJson = $root->addChild('fields');
         $rootJson->addAttribute('name', $field->id);
         $label = '<strong>' . $field->name . '</strong> ' . sprintf($syntax, $field->id);
         if ($field->state == -1) {
             $label .= ' [' . JText::_('PLG_FIELDSANDFILTERS_FORM_ONLY_ADMIN') . ']';
         }
         if (!($isStaticMode = in_array($field->mode, $staticMode))) {
             // name spacer
             $element = $rootJson->addChild('field');
             $element->addAttribute('type', 'spacer');
             $element->addAttribute('name', 'name_spacer_' . $field->id);
             $element->addAttribute('label', $label);
             $element->addAttribute('translate_label', 'false');
             $element->addAttribute('class', 'text');
             $element->addAttribute('fieldset', $fieldset);
         }
         if (!empty($field->description) && $field->params->get('base.admin_enabled_description', 0)) {
             switch ($field->params->get('base.admin_description_type', 'description')) {
                 case 'tip':
                     $element->addAttribute('description', $field->description);
                     $element->addAttribute('translate_description', 'false');
                     break;
                 case 'description':
                 default:
                     $element = $rootJson->addChild('field');
                     $element->addAttribute('type', 'spacer');
                     $element->addAttribute('name', 'description_spacer_' . $field->id);
                     $element->addAttribute('label', $field->description);
                     $element->addAttribute('translate_label', 'false');
                     $element->addAttribute('fieldset', $fieldset);
                     break;
             }
         }
         $element = $rootJson->addChild('field');
         $element->addAttribute('labelclass', 'control-label');
         $element->addAttribute('fieldset', $fieldset);
         if ($isStaticMode) {
             $label .= ' [' . JText::_('PLG_FIELDSANDFILTERS_FORM_GROUP_STATIC_TITLE') . ']';
             $element->addAttribute('type', 'spacer');
             $element->addAttribute('description', $field->data);
             $element->addAttribute('name', $field->id);
             $element->addAttribute('label', $label);
             $element->addAttribute('translate_label', 'false');
             $element->addAttribute('translate_description', 'false');
         } else {
             //image
             $element->addAttribute('name', 'image');
             $element->addAttribute('type', 'media');
             $element->addAttribute('class', 'inputbox');
             $element->addAttribute('label', 'PLG_FAF_TS_IE_FORM_IMAGE_LBL');
             $element->addAttribute('description', 'PLG_FAF_TS_IE_FORM_IMAGE_DESC');
             $element->addAttribute('filter', 'safehtml');
             if ($field->required) {
                 $element->addAttribute('required', 'true');
             }
             //src
             $element = $rootJson->addChild('field');
             $element->addAttribute('name', 'src');
             $element->addAttribute('type', 'hidden');
             $element->addAttribute('filter', 'safehtml');
             $element->addAttribute('fieldset', $fieldset);
             // caption
             $element = $rootJson->addChild('field');
             $element->addAttribute('name', 'caption');
             $element->addAttribute('type', 'text');
             $element->addAttribute('class', 'inputbox');
             $element->addAttribute('labelclass', 'control-label');
             $element->addAttribute('label', 'PLG_FAF_TS_IE_FORM_CAPTION_LBL');
             $element->addAttribute('description', 'PLG_FAF_TS_IE_FORM_CAPTION_DESC');
             $element->addAttribute('filter', 'safehtml');
             $element->addAttribute('fieldset', $fieldset);
             // alt
             $element = $rootJson->addChild('field');
             $element->addAttribute('name', 'alt');
             $element->addAttribute('type', 'text');
             $element->addAttribute('class', 'inputbox');
             $element->addAttribute('labelclass', 'control-label');
             $element->addAttribute('label', 'PLG_FAF_TS_IE_FORM_ALT_LBL');
             $element->addAttribute('description', 'PLG_FAF_TS_IE_FORM_ALT_DESC');
             $element->addAttribute('filter', 'safehtml');
             $element->addAttribute('fieldset', $fieldset);
             if ($field->params->get('type.create_thumb')) {
                 //src thumb
                 $element = $rootJson->addChild('field');
                 $element->addAttribute('name', 'src_thumb');
                 $element->addAttribute('type', 'hidden');
                 $element->addAttribute('filter', 'safehtml');
                 $element->addAttribute('fieldset', $fieldset);
             } else {
                 // link
                 $element = $rootJson->addChild('field');
                 $element->addAttribute('name', 'link');
                 $element->addAttribute('type', 'text');
                 $element->addAttribute('class', 'inputbox');
                 $element->addAttribute('labelclass', 'control-label');
                 $element->addAttribute('label', 'PLG_FAF_TS_IE_FORM_LINK_LBL');
                 $element->addAttribute('description', 'PLG_FAF_TS_IE_FORM_LINK_DESC');
                 $element->addAttribute('filter', 'safehtml');
                 $element->addAttribute('fieldset', $fieldset);
                 // link target
                 $element = $rootJson->addChild('field');
                 $element->addAttribute('name', 'target');
                 $element->addAttribute('type', 'list');
                 $element->addAttribute('class', 'inputbox');
                 $element->addAttribute('labelclass', 'control-label');
                 $element->addAttribute('label', 'PLG_FAF_TS_IE_FORM_TARGET_LBL');
                 $element->addAttribute('description', 'PLG_FAF_TS_IE_FORM_TARGET_DESC');
                 $element->addAttribute('fieldset', $fieldset);
                 KextensionsXML::addOptionsNode($element, array('PLG_FAF_TS_IE_FORM_TARGET_OPTION_DEFAULT' => '', 'PLG_FAF_TS_IE_FORM_TARGET_OPTION_BLANK' => 1, 'PLG_FAF_TS_IE_FORM_TARGET_OPTION_POPUP' => 2, 'PLG_FAF_TS_IE_FORM_TARGET_OPTION_MODAL' => 3, 'PLG_FAF_TS_IE_FORM_TARGET_OPTION_PARENT' => 4));
             }
         }
         // hr bottom spacer
         $element = $rootJson->addChild('field');
         $element->addAttribute('type', 'spacer');
         $element->addAttribute('name', 'hr_bottom_spacer_' . $field->id);
         $element->addAttribute('hr', 'true');
         $element->addAttribute('fieldset', $fieldset);
         $form->addOrder($field->id, $field->ordering)->setField($field->id, $root);
     }
     return true;
 }
コード例 #4
0
 /**
  * @since       1.2.0
  **/
 public static function preparationContent(&$text, $context = '', $option = null, $itemID = null, array $excluded = array(), $syntax = null, $syntaxType = self::SYNTAX_SIMPLE)
 {
     $syntax = $syntax ? $syntax : KextensionsPlugin::getParams('system', 'fieldsandfilters')->get('syntax', '#{%s}');
     $syntaxType = $syntaxType ? $syntaxType : KextensionsPlugin::getParams('system', 'fieldsandfilters')->get('syntax_type', self::SYNTAX_SIMPLE);
     if (strpos($syntax, '%s') !== false) {
         $prefix = explode('%s', $syntax);
         // simple performance check to determine whether bot should process further
         if (!($prefix = $prefix[0]) || strpos($text, $prefix) === false) {
             return true;
         }
         /* @deprecated  1.2.0 */
         if ($syntaxType == self::SYNTAX_OLD) {
             $regex = '(?P<field_id>\\d+)(?:,(?P<item_id>\\d+)|)(?:,(?P<option>[\\w.-]+)|)';
         } else {
             $regex = '(?P<field_id>\\d+)(?:,(?P<item_id>\\d+|)(?::(?P<option>[\\w.-]+)|)|)(?:,(?P<context>[\\w.-]+)|)(?:,(?P<params>{.*?})|)';
         }
         $regex = '/' . sprintf($syntax, $regex) . '/i';
         // Find all instances of plugin and put in $matches for loadposition
         // $matches[0] is full pattern match
         preg_match_all($regex, $text, $matches, PREG_SET_ORDER);
         if (!$matches) {
             return true;
         }
         $jinput = JFactory::getApplication()->input;
         $itemID = ($itemID = (int) $itemID) ? $itemID : $jinput->get('id', 0, 'int');
         $option = $option ? $option : $jinput->get('option');
         $extensionsOptions = FieldsandfiltersFactory::getExtensions()->getExtensionsColumn('option');
         $combinations = array();
         $getAllextensions = true;
         $excludes = array();
         $isExtended = $syntaxType == self::SYNTAX_EXTENDED;
         foreach ($matches as $match) {
             /* field id */
             if (!($fieldID = (int) $match['field_id']) || in_array($fieldID, $excluded)) {
                 $excludes[] = $match[0];
                 continue;
             }
             /* context */
             if (!empty($match['context']) && $match['context'] != $context) {
                 $excludes[] = $match[0];
                 continue;
             }
             /* component - option + item id */
             $_itemID = isset($match['item_id']) && ($val = (int) $match['item_id']) ? $val : $itemID;
             $_option = !empty($match['option']) ? $match['option'] : $option;
             if (!in_array($_option, $extensionsOptions)) {
                 $excludes[] = $match[0];
                 continue;
             }
             $key = $_option . '-' . $_itemID;
             if (!array_key_exists($key, $combinations)) {
                 $combinations[$key] = array('item_id' => $_itemID, 'option' => $_option, 'fields_id' => array());
                 if ($isExtended) {
                     $combinations[$key]['elements'] = array();
                 } else {
                     $combinations[$key]['matches'] = array();
                 }
             }
             /* params */
             if ($isExtended) {
                 $keyElement = $params = null;
                 if (!empty($match['params'])) {
                     $params = new JRegistry($match['params']);
                     $keyElement = $params->toString();
                     if ($keyElement != '{}') {
                         $keyElement = md5($keyElement);
                     } else {
                         $keyElement = $params = null;
                     }
                 }
                 if (!array_key_exists($keyElement, $combinations[$key]['elements'])) {
                     $combinations[$key]['elements'][$keyElement] = array('matches' => array(), 'params' => $params);
                 }
                 $combinations[$key]['elements'][$keyElement]['matches'][$fieldID][] = $match[0];
             } else {
                 $combinations[$key]['matches'][$fieldID][] = $match[0];
             }
             if (!in_array($fieldID, $combinations[$key]['fields_id'])) {
                 $combinations[$key]['fields_id'][] = $fieldID;
             }
         }
         if (!empty($combinations)) {
             while ($combination = array_shift($combinations)) {
                 $object = self::getFieldsByItemID($combination['option'], $combination['item_id'], $combination['fields_id'], $getAllextensions);
                 if ($isExtended) {
                     $isFields = $object->fields->getProperties(true);
                     $isFields = !empty($isFields);
                     while ($element = array_shift($combination['elements'])) {
                         if (!$isFields) {
                             $excludes = array_merge($excludes, KextensionsArray::flatten($element['matches']));
                             continue;
                         }
                         $_object = clone $object;
                         $_fieldsID = array_keys($element['matches']);
                         foreach ($_fieldsID as $_fieldID) {
                             if (!isset($_object->fields->{$_fieldID})) {
                                 unset($_object->fields->{$_fieldID});
                                 $excludes = array_merge($excludes, $element['matches'][$_fieldID]);
                                 unset($element['matches'][$_fieldID]);
                             }
                         }
                         $fieldsLayouts = self::getFieldsLayouts($_object, $context, $element['params'], 'id');
                         foreach ($element['matches'] as $fieldID => &$match) {
                             $text = str_replace($match, $fieldsLayouts->get($fieldID, ''), $text);
                         }
                     }
                 } else {
                     $fieldsLayouts = self::getFieldsLayouts($object, $context, null, 'id');
                     foreach ($combination['matches'] as $fieldID => &$match) {
                         $text = str_replace($match, $fieldsLayouts->get($fieldID, ''), $text);
                     }
                 }
             }
         }
         if (!empty($excludes)) {
             $text = str_replace(array_unique($excludes), '', $text);
         }
     }
     return true;
 }
コード例 #5
0
 /**
  * onFieldsandfiltersPrepareFormField
  *
  * @param    KextensionsForm $form     The form to be altered.
  * @param    JObject         $data     The associated data for the form.
  * @param   boolean          $isNew    Is element is new
  * @param   string           $fieldset Fieldset name
  *
  * @return    boolean
  * @since    1.1.0
  */
 public function onFieldsandfiltersPrepareFormField(KextensionsForm $form, JObject $data, $isNew = false, $fieldset = 'fieldsandfilters')
 {
     if (!($fields = $data->get($this->_name))) {
         return true;
     }
     JForm::addFieldPath(JPATH_ADMINISTRATOR . '/components/com_fieldsandfilters/models/fields');
     $fields = is_array($fields) ? $fields : array($fields);
     $syntax = KextensionsPlugin::getParams('system', 'fieldsandfilters')->get('syntax', '#{%s}');
     while ($field = array_shift($fields)) {
         $root = new SimpleXMLElement('<fields />');
         $root->addAttribute('name', 'connections');
         if (!empty($field->description) && $field->params->get('base.admin_enabled_description', 0)) {
             switch ($field->params->get('base.admin_description_type', 'description')) {
                 case 'tip':
                     $element = $root->addChild('field');
                     $element->addAttribute('description', $field->description);
                     $element->addAttribute('translate_description', 'false');
                     $element->addAttribute('fieldset', $fieldset);
                     break;
                 case 'description':
                 default:
                     $element = $root->addChild('field');
                     $element->addAttribute('type', 'spacer');
                     $element->addAttribute('name', 'description_spacer_' . $field->id);
                     $element->addAttribute('label', $field->description);
                     $element->addAttribute('translate_label', 'false');
                     $element->addAttribute('fieldset', $fieldset);
                     $element = $root->addChild('field');
                     $element->addAttribute('fieldset', $fieldset);
                     break;
             }
         } else {
             $element = $root->addChild('field');
             $element->addAttribute('fieldset', $fieldset);
         }
         $label = '<strong>' . $field->name . '</strong> ' . sprintf($syntax, $field->id);
         if ($field->state == -1) {
             $label .= ' [' . JText::_('PLG_FIELDSANDFILTERS_FORM_ONLY_ADMIN') . ']';
         }
         $element->addAttribute('id', $field->id);
         $element->addAttribute('name', $field->id);
         $element->addAttribute('class', 'inputbox');
         $element->addAttribute('labelclass', 'control-label');
         $element->addAttribute('label', $label);
         $element->addAttribute('translate_label', 'false');
         $element->addAttribute('filter', 'int_array');
         $element->addAttribute('translate_options', 'false');
         switch ($field->params->get('type.style', 'checkbox')) {
             case 'multiselect':
                 $element->addAttribute('multiple', 'true');
             case 'select':
                 $type = 'fieldsandfiltersList';
                 break;
             case 'checkbox':
             default:
                 $type = 'fieldsandfiltersCheckboxes';
                 break;
         }
         $element->addAttribute('type', $type);
         if ($field->required) {
             $element->addAttribute('required', 'true');
         }
         // FieldsandfiltersFieldValues
         $values = $field->values->getProperties();
         if (!empty($values)) {
             while ($value = array_shift($values)) {
                 $option = $element->addChild('option', $value->value . ' [' . $value->alias . ']');
                 $option->addAttribute('value', $value->id);
             }
             if ($isNew && ($default = $field->params->get('type.default'))) {
                 $default = array_unique((array) $default);
                 JArrayHelper::toInteger($default);
                 $form->setData('connections.' . $field->id, $default);
             }
         }
         // hr bottom spacer
         $element = $root->addChild('field');
         $element->addAttribute('type', 'spacer');
         $element->addAttribute('name', 'hr_bottom_spacer_' . $field->id);
         $element->addAttribute('hr', 'true');
         $element->addAttribute('fieldset', $fieldset);
         $form->addOrder($field->id, $field->ordering)->setField($field->id, $root);
     }
     return true;
 }