/**
  * Method to load the jQuery Fieldsandfilters filters JavaScript framework into the document head
  *
  * If debugging mode is on an uncompressed version of jQuery is included for easier debugging.
  *
  * @return  void
  *
  * @since   1.2.0
  */
 public static function framework($debug = null)
 {
     // Only load once
     if (!empty(static::$loaded[__METHOD__])) {
         return;
     }
     // If no debugging value is set, use the configuration setting
     if ($debug === null) {
         $config = JFactory::getConfig();
         $debug = (bool) $config->get('debug');
     }
     $params = JComponentHelper::getParams('com_fieldsandfilters');
     // Import CSS
     JHtml::_('stylesheet', 'fieldsandfilters/filters/filters.css', array(), true, false, false, false, false);
     $loadingBackground = $params->get('loading_background_filters', 'loading-balls');
     if ($loadingBackground != -1) {
         JHtml::_('stylesheet', 'fieldsandfilters/filters/' . $loadingBackground . '.css', array(), true, false, false, false);
     }
     // Import JS
     if (FieldsandfiltersFactory::isVersion()) {
         JHtml::_('jquery.framework', (bool) $params->get('load_noconflict_javascript', 1));
     } elseif ($params->get('load_jquery_javascript', 1)) {
         JHtml::_('FieldsandfiltersHtml.joomla.jquery', (bool) $params->get('load_noconflict_javascript', 1));
     }
     JHtml::_('script', 'fieldsandfilters/core/jquery.fieldsandfilters.js', false, true, false, false, $debug);
     static::$loaded[__METHOD__] = true;
     return;
 }
 /**
  * Add the page title and toolbar.
  *
  * @since    1.1.0
  */
 protected function addToolbar()
 {
     $canDo = FieldsandfiltersHelper::getActions();
     JToolBarHelper::title(JText::_('COM_FIELDSANDFILTERS_TITLE_FIELDVALUES'), 'faf-field-values');
     if (FieldsandfiltersFactory::isVersion() && FieldsandfiltersFactory::isVersion('<', 3.2)) {
         JHtmlSidebar::setAction('index.php?option=com_fieldsandfilters&view=fieldvalues');
         JHtmlSidebar::addFilter(null, 'filter_field_id', JHtml::_('select.options', JHtml::_('FieldsandfiltersHtml.options.fields'), 'value', 'text', $this->state->get('filter.field_id'), false));
         JHtmlSidebar::addFilter(JText::_('JOPTION_SELECT_PUBLISHED'), 'filter_published', JHtml::_('select.options', JHtml::_('FieldsandfiltersHtml.options.states', array('adminonly' => false)), 'value', 'text', $this->state->get('filter.state'), false));
     }
     if ($canDo->get('core.create')) {
         JToolBarHelper::addNew('fieldvalue.add', 'JTOOLBAR_NEW');
     }
     if ($canDo->get('core.edit')) {
         JToolBarHelper::editList('fieldvalue.edit', 'JTOOLBAR_EDIT');
     }
     if ($canDo->get('core.edit.state')) {
         JToolBarHelper::divider();
         JToolBarHelper::custom('fieldvalues.publish', 'publish.png', 'publish_f2.png', 'JTOOLBAR_PUBLISH', true);
         JToolBarHelper::custom('fieldvalues.unpublish', 'unpublish.png', 'unpublish_f2.png', 'JTOOLBAR_UNPUBLISH', true);
         JToolBarHelper::deleteList('', 'fieldvalues.delete', 'JTOOLBAR_DELETE');
     }
     if ($canDo->get('core.admin')) {
         JToolBarHelper::divider();
         JToolBarHelper::preferences('com_fieldsandfilters');
     }
 }
 /**
  * @since       1.1.0
  */
 public static function getLayoutPath($type, $name, $layout = 'default')
 {
     // Create the plugin name
     $extension = 'plg_' . $type . '_' . $name;
     if (!($path = self::getPath($extension, $layout))) {
         if (FieldsandfiltersFactory::isVersion()) {
             $path = JPluginHelper::getLayoutPath($type, $name, $layout);
         } else {
             $template = JFactory::getApplication()->getTemplate();
             $defaultLayout = $layout;
             if (strpos($layout, ':') !== false) {
                 // Get the template and file name from the string
                 $temp = explode(':', $layout);
                 $template = $temp[0] == '_' ? $template : $temp[0];
                 $layout = $temp[1];
                 $defaultLayout = $temp[1] ? $temp[1] : 'default';
             }
             // Build the template and base path for the layout
             $tPath = JPATH_THEMES . '/' . $template . '/html/plg_' . $type . '_' . $name . '/' . $layout . '.php';
             $bPath = JPATH_BASE . '/plugins/' . $type . '/' . $name . '/tmpl/' . $defaultLayout . '.php';
             $dPath = JPATH_BASE . '/plugins/' . $type . '/' . $name . '/tmpl/default.php';
             // If the template has a layout override use it
             if (file_exists($tPath)) {
                 $path = $tPath;
             } elseif (file_exists($bPath)) {
                 $path = $bPath;
             } else {
                 $path = $dPath;
             }
         }
         self::setPath($path, $extension, $layout);
     }
     return $path;
 }
 /**
  * Method to auto-populate the model state.
  *
  * Note. Calling getState in this method will result in recursion.
  *
  * @since       1.1.0
  */
 protected function populateState($ordering = null, $direction = null)
 {
     // Initialise variables.
     $app = JFactory::getApplication();
     $filters = $app->getUserStateFromRequest($this->context . '.filter', 'filter', array(), 'array');
     // If the context is set, assume that stateful lists are used.
     // @deprecated v.1.2 && J3.x
     if (!FieldsandfiltersFactory::isVersion() && $this->context) {
         // Receive & set filters
         if ($filters) {
             foreach ($filters as $name => $value) {
                 $this->setState('filter.' . $name, $value);
             }
         }
     } else {
         $this->state->set('filter.content_type_id', JArrayHelper::getValue($filters, 'content_type_id', 0, 'int'));
     }
     // Load the parameters.
     $params = JComponentHelper::getParams('com_fieldsandfilters');
     $this->setState('params', $params);
     $contentTypeID = (int) $this->state->get('filter.content_type_id');
     if ($contentTypeID && ($extension = FieldsandfiltersFactory::getExtensions()->getExtensionsByTypeIDPivot('content_type_id', $contentTypeID)->get($contentTypeID))) {
         // Include the content plugins for the on delete events.
         JPluginHelper::importPlugin('fieldsandfiltersextensions');
         // Trigger the onContentBeforeDelete event.
         $app->triggerEvent('onFieldsandfiltersPopulateState', array($this->context . '.' . $extension->name, $this->state, &$this->filter_fields));
         $this->setState('filter.extension_name', $extension->name);
     }
     // List state information.
     parent::populateState($this->state->get('list.query.ordering', 'e.item_id'), 'asc');
 }
 /**
  * @since       1.2.0
  */
 public function onAfterInitialise()
 {
     JLoader::registerPrefix('Kextensions', JPATH_LIBRARIES . '/kextensions');
     JLoader::registerPrefix('Fieldsandfilters', JPATH_ADMINISTRATOR . '/components/com_fieldsandfilters/helpers');
     if (!FieldsandfiltersFactory::isVersion()) {
         $this->app = JFactory::getApplication();
     }
 }
 /**
  * Display the view
  *
  * @since    1.0.0
  */
 public function display($tpl = null)
 {
     $this->buttons = FieldsandfiltersHelper::getButtons(true, array('cpanel'));
     $this->addToolbar();
     if (is_null($tpl) && !FieldsandfiltersFactory::isVersion()) {
         $tpl = '2.5';
     }
     parent::display($tpl);
 }
 /**
  * Append an published only admin item to the current dropdown menu
  *
  * @param   string $checkboxId ID of corresponding checkbox of the record
  * @param   string $prefix     The task prefix
  *
  * @return  void
  *
  * @since       1.0.0
  */
 public static function onlyAdmin($checkboxId, $prefix = '')
 {
     $task = $prefix . 'onlyadmin';
     if (FieldsandfiltersFactory::isVersion('>=', 3.2)) {
         JHtml::_('actionsdropdown.addCustomItem', JText::_('COM_FIELDSANDFILTERS_HTML_ONLYADMIN'), 'dashboard', $checkboxId, $task);
     } else {
         JHtml::_('dropdown.addCustomItem', JText::_('COM_FIELDSANDFILTERS_HTML_ONLYADMIN'), 'javascript:void(0)', 'onclick="contextAction(\'' . $checkboxId . '\', \'' . $task . '\')"');
     }
     return;
 }
 /**
  * Method to get the data that should be injected in the form.
  *
  * @return    mixed    The data for the form.
  * @since    1.0.0
  */
 protected function loadFormData()
 {
     // Check the session for previously entered form data.
     $data = JFactory::getApplication()->getUserState('com_fieldsandfilters.edit.fieldvalue.data', array());
     if (empty($data)) {
         $data = $this->getItem();
     }
     if (FieldsandfiltersFactory::isVersion()) {
         $this->preprocessData('com_fieldsandfilters.fieldvalue', $data);
     }
     return $data;
 }
 /**
  * Constructor.
  *
  * @param   array $config An optional associative array of configuration settings.
  *
  * @see         JController
  * @since       1.0.0
  */
 public function __construct($config = array())
 {
     parent::__construct($config);
     // Define standard task mappings.
     // State Value = -1
     $this->registerTask('onlyadmin', 'publish');
     // Required Value = 0
     $this->registerTask('unrequired', 'required');
     /* @deprecated J3.x */
     if (!FieldsandfiltersFactory::isVersion()) {
         $this->input = JFactory::getApplication()->input;
     }
     /* @end deprecated J3.x */
 }
 /**
  * Display the view
  *
  * @since    1.0.0
  */
 public function display($tpl = null)
 {
     $this->state = $this->get('State');
     $this->item = $this->get('Item');
     $this->form = $this->get('Form');
     // Check for errors.
     if (count($errors = $this->get('Errors'))) {
         throw new Exception(implode("\n", $errors));
     }
     $this->addToolbar();
     if (FieldsandfiltersFactory::isVersion('<', 3.2) && is_null($tpl)) {
         $tpl = FieldsandfiltersFactory::isVersion() ? '3.1' : '2.5';
     }
     parent::display($tpl);
 }
 /**
  * Add the page title and toolbar.
  *
  * @since    1.1.0
  */
 protected function addToolbar()
 {
     $canDo = FieldsandfiltersHelper::getActions();
     JToolBarHelper::title(JText::_('COM_FIELDSANDFILTERS_TITLE_FIELDS'), 'faf-fields');
     if (FieldsandfiltersFactory::isVersion() && FieldsandfiltersFactory::isVersion('<', 3.2)) {
         JHtmlSidebar::setAction('index.php?option=com_fieldsandfilters&view=fields');
         JHtmlSidebar::addFilter(JText::_('JOPTION_SELECT_PUBLISHED'), 'filter_published', JHtml::_('select.options', JHtml::_('FieldsandfiltersHtml.options.states'), 'value', 'text', $this->state->get('filter.state'), false));
         JHtmlSidebar::addFilter(JText::_('COM_FIELDSANDFILTERS_OPTION_SELECT_EXTENSION'), 'filter_content_type_id', JHtml::_('select.options', JHtml::_('FieldsandfiltersHtml.options.extensions'), 'value', 'text', $this->state->get('filter.content_type_id'), false));
         JHtmlSidebar::addFilter(JText::_('COM_FIELDSANDFILTERS_OPTION_SELECT_TYPE'), 'filter_type', JHtml::_('select.options', JHtml::_('FieldsandfiltersHtml.options.types'), 'value', 'text', $this->state->get('filter.type'), false));
         /*
         JHtmlSidebar::addFilter(
         	JText::_('JOPTION_SELECT_ACCESS'),
         	'filter_access',
         	JHtml::_('select.options', JHtml::_('access.assetgroups'), 'value', 'text', $this->state->get('filter.access'), false)
         );
         
         JHtmlSidebar::addFilter(
         	JText::_('JOPTION_SELECT_LANGUAGE'),
         	'filter_language',
         	JHtml::_('select.options', JHtml::_('contentlanguage.existing'), 'value', 'text', $this->state->get('filter.language'), false)
         );
         */
     }
     if ($canDo->get('core.create')) {
         JToolBarHelper::addNew('field.add', 'JTOOLBAR_NEW');
     }
     if ($canDo->get('core.edit') && isset($this->items[0])) {
         JToolBarHelper::editList('field.edit', 'JTOOLBAR_EDIT');
     }
     if ($canDo->get('core.edit.state')) {
         JToolBarHelper::divider();
         JToolBarHelper::custom('fields.publish', 'publish.png', 'publish_f2.png', 'JTOOLBAR_PUBLISH', true);
         JToolBarHelper::custom('fields.unpublish', 'unpublish.png', 'unpublish_f2.png', 'JTOOLBAR_UNPUBLISH', true);
         JToolBarHelper::custom('fields.onlyadmin', 'dashboard.png', 'dashboard_f2.png', 'COM_FIELDSANDFILTERS_TOOLBAR_ONLYADMIN', true);
         JToolBarHelper::deleteList('', 'fields.delete', 'JTOOLBAR_DELETE');
         JToolBarHelper::divider();
         JToolBarHelper::custom('fields.required', 'star.png', 'star_f2.png', 'COM_FIELDSANDFILTERS_TOOLBAR_REQUIRED', true);
         JToolBarHelper::custom('fields.unrequired', 'star-empty.png', 'star-empty_f2.png', 'COM_FIELDSANDFILTERS_TOOLBAR_UNREQUIRED', true);
     }
     if ($canDo->get('core.admin')) {
         JToolBarHelper::divider();
         JToolBarHelper::preferences('com_fieldsandfilters');
     }
 }
 /**
  * Method to auto-populate the model state.
  *
  * Note. Calling getState in this method will result in recursion.
  *
  * @since       1.0.0
  */
 protected function populateState($ordering = null, $direction = null)
 {
     // If the context is set, assume that stateful lists are used.
     // @deprecated v.1.2 && J3.x
     if (!FieldsandfiltersFactory::isVersion() && $this->context) {
         $app = JFactory::getApplication();
         // Receive & set filters
         if ($filters = $app->getUserStateFromRequest($this->context . '.filter', 'filter', array(), 'array')) {
             foreach ($filters as $name => $value) {
                 $this->setState('filter.' . $name, $value);
             }
         }
     }
     // Load the parameters.
     $params = JComponentHelper::getParams('com_fieldsandfilters');
     $this->setState('params', $params);
     // List state information.
     parent::populateState('f.name', 'asc');
 }
 /**
  * Display the view
  *
  * @since    1.1.0
  */
 public function display($tpl = null)
 {
     $tpl = is_null($tpl) && !FieldsandfiltersFactory::isVersion() ? '2.5' : $tpl;
     switch ($this->getLayout()) {
         case 'types':
             // Load PluginTypes Helper - getTypesGroup
             $this->plugins = FieldsandfiltersFactory::getTypes()->getTypesGroup();
             break;
         case 'extensions':
             // Load PluginExtensions Helper -
             $this->plugins = FieldsandfiltersFactory::getExtensions()->getExtensionsGroup();
             break;
     }
     if (is_null($this->plugins)) {
         echo JText::sprintf('COM_FIELDSANDFILTERS_ERROR_NOT_PLUGINS_TPL', $this->getLayout());
         return false;
     }
     $this->addToolbar();
     parent::display($tpl);
 }
 /**
  * Sets the extension type of the field item currently being edited.
  *
  * @param   string $urlVar The name of the URL variable if different from the primary key
  *
  * @return  void
  * @since       1.1.0
  */
 function setExtension($urlVar = 'id')
 {
     // Get the posted values from the request.
     $data = $this->input->post->get('jform', array(), 'array');
     $recordId = $this->input->get($urlVar, 0, 'int');
     // Get the type.
     $options = new JRegistry(base64_decode($data['temp_extension']));
     $contentTypeId = (int) $options->get('content_type_id');
     $form = $options->get('form');
     $extension = FieldsandfiltersFactory::getExtensions()->getExtensionsByTypeID($contentTypeId)->get($contentTypeId);
     if ($contentTypeId && $extension && $extension->content_type_alias == $options->get('content_type_alias') && $recordId == $options->get('id', 0)) {
         $data['content_type_id'] = $contentTypeId;
         $data['extension_form'] = $form;
         //Save the data in the session.
         JFactory::getApplication()->setUserState('com_fieldsandfilters.edit.field.data', $data);
         $this->setRedirect(JRoute::_('index.php?option=' . $this->option . '&view=' . $this->view_item . $this->getRedirectToItemAppend($recordId, $urlVar), false));
         return true;
     }
     $this->setRedirect(JRoute::_('index.php?option=' . $this->option . '&view=' . $this->view_list, false));
     return false;
 }
 public static function setUserStateFieldID($context, $name = 'field_id')
 {
     $app = JFactory::getApplication();
     $userState = (array) $app->getUserState($context);
     if ($fieldID = $app->input->getInt($name)) {
         if ($fieldID != JArrayHelper::getValue($userState, $name)) {
             $userState[$name] = $fieldID;
             $app->setUserState($context, $userState);
             return true;
         }
     } else {
         if (!JArrayHelper::getValue($userState, $name)) {
             $filterMode = FieldsandfiltersModes::getMode(FieldsandfiltersModes::MODE_FILTER);
             $extensionsID = FieldsandfiltersFactory::getExtensions()->getExtensionsColumn('content_type_id');
             $fieldsID = FieldsandfiltersFactory::getFields()->getFieldsByModeIDColumn('id', $extensionsID, $filterMode, array(1, -1));
             $fieldID = current($fieldsID);
             $userState[$name] = $fieldID;
             $app->setUserState($context, $userState);
             return true;
         }
     }
     return false;
 }
 /**
  * @since       1.1.0
  */
 public function fields()
 {
     // Check for a valid token. If invalid, send a 403 with the error message.
     JSession::checkToken('request') or die;
     $app = JFactory::getApplication();
     $fieldID = $app->input->get('fid', 0, 'int');
     $extensionTypeID = $app->input->get('etid', 0, 'int');
     if ($app->input->get('format') == 'raw' && $extensionTypeID && $fieldID) {
         // Load PluginExtensions Helper
         if (!($extension = FieldsandfiltersFactory::getExtensions()->getExtensionsByTypeID($extensionTypeID)->get($extensionTypeID))) {
             // $app->enqueueMessage( JText::_( JText::_( 'COM_FILEDSANDFILTERS_FILTERS_ERROR_EXTENSION_NOT_EXISTS' ), 'error' ) );
         } else {
             if (!($field = FieldsandfiltersFactory::getFields()->getFieldsByID($extension->extension_type_id, $fieldID)->get($fieldID))) {
                 // $app->enqueueMessage( JText::_( JText::_( 'COM_FILEDSANDFILTERS_FILTERS_ERROR_FIELD_NOT_EXISTS' ), 'error' ) );
             } else {
                 JPluginHelper::importPlugin('fieldsandfilterstypes');
                 $context = 'com_fieldsandfilters.fields.' . $field->field_type;
                 $app->triggerEvent('onFieldsandfiltersFieldsRequestRaw', array($context, $field));
             }
         }
     }
     $this->setRedirect(JURI::root(true));
 }
 /**
  *
  * @since       1.1.0
  */
 protected function _getQuery()
 {
     // Get db and query
     $query = $this->_db->getQuery(true);
     $query->select('*')->from($this->_db->quoteName('#__fieldsandfilters_fields'))->where($this->_db->quoteName('state') . ' IN (' . implode(',', $this->_states) . ')')->where($this->_db->quoteName('content_type_id') . ' IN(' . implode(',', $this->_types) . ')');
     // Fields where contents type id
     if ($this->method == 'getFieldsByID') {
         $query->where($this->_db->quoteName('id') . ' IN (' . implode(',', $this->elements) . ')');
     } else {
         if ($this->method == 'getFieldsByModeID') {
             $query->where($this->_db->quoteName('mode') . ' IN (' . implode(',', $this->_modes) . ')');
         }
     }
     // We no need same elements id
     if (!empty($this->_notElements)) {
         JArrayHelper::toInteger($this->_notElements);
         $query->where($this->_db->quoteName('id') . ' NOT IN (' . implode(',', $this->_notElements) . ')');
     }
     $query->order($this->_db->quoteName('ordering') . ' ASC');
     /* @deprecated 1.2.0 */
     if (FieldsandfiltersFactory::useOldStructure()) {
         $query->select(array($this->_db->quoteName('id', 'field_id'), $this->_db->quoteName('name', 'field_name'), $this->_db->quoteName('alias', 'field_alias'), $this->_db->quoteName('type', 'field_type')));
     }
     /* @end deprecated 1.2.0 */
     return $query;
 }
 /**
  * Method to delete one or more records.
  *
  * @param   array &$pks An array of record primary keys.
  *
  * @return  boolean  True if successful, false if an error occurs.
  *
  * @since       1.1.0
  */
 public function delete(&$pks)
 {
     $app = JFactory::getApplication();
     $pks = (array) $pks;
     $table = $this->getTable();
     $dispatcher = FieldsandfiltersFactory::getDispatcher();
     // Include the content plugins for the on delete events.
     JPluginHelper::importPlugin('content');
     JPluginHelper::importPlugin('fieldsandfilterstypes');
     // Load PluginExtensions Helper
     $extensionsHelper = FieldsandfiltersFactory::getExtensions();
     // Iterate the items to delete each one.
     foreach ($pks as $i => $pk) {
         if (!$table->load($pk) || !$this->canDelete($table)) {
             throw new Exception($table->getError());
         }
         $extensionName = ($extension = $extensionsHelper->getExtensionsByTypeID($table->content_type_id)->get($table->content_type_id)) ? $extension->name : '';
         $context = $this->option . '.' . $this->name . '.' . $extensionName;
         // Trigger the onContentBeforeDelete event.
         $result = $app->triggerEvent($this->event_before_delete, array($context, $table));
         if (in_array(false, $result, true)) {
             throw new Exception($table->getError());
         }
         // Trigger the onFieldsandfiltersBeforeDeleteData event.
         $result = $app->triggerEvent('onFieldsandfiltersBeforeDeleteData', array($this->option . '.' . $this->name, $this->getItem($pk)));
         if (in_array(false, $result, true)) {
             throw new Exception($table->getError());
         }
         // delete fields data element
         if (!$table->deleteData($pk)) {
             throw new Exception($table->getError());
         }
         // delete fields connections element
         if (!$table->deleteConnections($pk)) {
             throw new Exception($table->getError());
         }
         if (!$table->delete($pk)) {
             throw new Exception($table->getError());
         }
         // Trigger the onContentAfterDelete event.
         $app->triggerEvent($this->event_after_delete, array($context, $table));
     }
     // Clear the component's cache
     $this->cleanCache();
     return true;
 }
 /**
  * @since         1.1.0
  * @deprecated    1.2.0
  * @use           FieldsandfiltersFieldsSite::getFieldsLayoutsByItemID()
  **/
 public static function getFieldsByItemIDWithTemplate($option = null, $itemID = null, $fieldsID = null, $getAllextensions = true, $params = false, $ordering = 'ordering')
 {
     $object = self::getFieldsByItemID($option, $itemID, $fieldsID, $getAllextensions);
     $templateFields = new JObject();
     $fields = $object->fields->getProperties();
     if (empty($fields)) {
         return $templateFields;
     }
     $fields = new JObject(JArrayHelper::pivot($fields, 'field_type'));
     JPluginHelper::importPlugin('fieldsandfilterstypes');
     FieldsandfiltersFactory::getDispatcher()->trigger('getFieldsandfiltersFieldsHTML', array($templateFields, $fields, $object->element, $params, $ordering));
     return $templateFields;
 }
<?php

/**
 * @package     com_fieldsandfilters
 * @copyright   Copyright (C) 2012 KES - Kulka Tomasz . All rights reserved.
 * @license     GNU General Public License version 3 or later; see License.txt
 * @author      KES - Kulka Tomasz <*****@*****.**> - http://www.kextensions.com
 */
// no direct access
defined('_JEXEC') or die;
// Load PluginTypes Helper
$typesHelper = FieldsandfiltersFactory::getTypes();
$valuesMode = (array) FieldsandfiltersModes::getMode(FieldsandfiltersModes::MODE_FILTER);
// Load PluginExtensions Helper
$extensionsHelper = FieldsandfiltersFactory::getExtensions();
JHtml::_('bootstrap.tooltip');
JHtml::_('behavior.multiselect');
JHtml::_('dropdown.init');
JHtml::_('formbehavior.chosen', 'select');
// Import CSS
JHtml::_('stylesheet', 'fieldsandfilters/administrator/fieldsandfilters.css', array(), true);
$app = JFactory::getApplication();
$user = JFactory::getUser();
$userId = $user->get('id');
$listOrder = $this->escape($this->state->get('list.ordering'));
$listDirn = $this->escape($this->state->get('list.direction'));
$canOrder = $user->authorise('core.edit.state', 'com_fieldsandfilters');
$saveOrder = $listOrder == 'f.ordering';
if ($saveOrder) {
    $saveOrderingUrl = 'index.php?option=com_fieldsandfilters&task=fields.saveOrderAjax&tmpl=component';
    JHtml::_('sortablelist.sortable', 'fieldList', 'adminForm', strtolower($listDirn), $saveOrderingUrl);
<?php

/**
 * @package     com_fieldsandfilters
 * @copyright   Copyright (C) 2012 KES - Kulka Tomasz . All rights reserved.
 * @license     GNU General Public License version 3 or later; see License.txt
 * @author      KES - Kulka Tomasz <*****@*****.**> -
 */
// No direct access
defined('_JEXEC') or die;
if (!FieldsandfiltersFactory::isVersion()) {
    jimport('joomla.application.component.controllerform');
}
/**
 * Element controller class.
 *
 * @since       1.0.0
 */
class FieldsandfiltersControllerElement extends JControllerForm
{
    /**
     * Gets the URL arguments to append to an item redirect.
     *
     * @param   integer $recordId The primary key id for the item.
     * @param   string  $urlVar   The name of the URL variable for the id.
     *
     * @return  string  The arguments to append to the redirect URL.
     *
     * @since       1.0.0
     */
    protected function getRedirectToItemAppend($recordId = null, $urlVar = 'id')
 /**
  * @since       1.1.0
  */
 public function onFieldsandfiltersRequestJSON($context, JObject $data)
 {
     if ($context != 'com_fieldsandfilters.filters.content') {
         return;
     }
     $app = JFactory::getApplication();
     $jinput = $app->input;
     $document = JFactory::getDocument();
     $basePath = sprintf('%s/%s/%s/overrides', JPATH_PLUGINS, $this->_type, $this->_name);
     $contentPath = JPATH_SITE . '/components/com_content';
     $id = $jinput->get('id', 0, 'int');
     $context = $jinput->get('context');
     if (!in_array($context, $this->_contexts)) {
         return false;
     }
     // Load PluginExtensions Helper
     $extension = FieldsandfiltersFactory::getExtensions()->getExtensionsByName($this->_name)->get($this->_name);
     if ($context == $this->_contexts['category'] && !$id || !$extension) {
         return false;
     }
     list($option, $class) = explode('.', $context);
     // set new jinput values
     $jinput->set('option', $option);
     $jinput->set('view', $class);
     $jinput->set('id', $jinput->get('id', 0, 'int'));
     // Include dependancies
     JLoader::import('com_content.helpers.route', JPATH_SITE . '/components');
     JLoader::import('com_content.helpers.query', JPATH_SITE . '/components');
     // Get controller Instance
     if (!($controller = KextensionsController::getInstance(null, 'contentController', array('base_path' => $contentPath, 'view_path' => $basePath . '/views')))) {
         return false;
     }
     // add model path
     $prefix = get_class($this);
     $controller->addModelPath($basePath . '/models', $prefix . 'Model');
     if (!($model = $controller->getModel($class, $prefix . 'Model', array('ignore_request' => false, 'table_path' => JPATH_ADMINISTRATOR . '/components/' . $option . '/tables')))) {
         return false;
     }
     $fieldsandfilters = $jinput->get('fieldsandfilters', array(), 'array');
     if (!empty($fieldsandfilters)) {
         $extensionsParams = new JObject(array('plugin.value' => $this->params->get('comparison_between_filters')));
         if ($moduleID = $jinput->get('module', 0, 'int')) {
             $extensionsParams->set('module.id', $moduleID);
         }
         $betweenFilters = FieldsandfiltersExtensionsHelper::getParams('comparison_between_filters', $extensionsParams, 'OR');
         $extensionsParams->set('plugin.value', $this->params->get('comparison_between_values_filters'));
         $betweenValues = FieldsandfiltersExtensionsHelper::getParams('comparison_between_values_filters', $extensionsParams, 'OR');
         $itemsID = FieldsandfiltersFiltersHelper::getItemsIDByFilters($extension->content_type_id, $fieldsandfilters, $model->getState('filter.published'), $betweenFilters, $betweenValues);
     } else {
         $itemsID = FieldsandfiltersFiltersHelper::getSimpleItemsID(false);
     }
     // load view
     if (!($view = $controller->getView($class, 'html', $prefix . 'View', array('base_path' => $contentPath, 'layout' => $jinput->get('layout', 'default'))))) {
         return false;
     }
     // For joomla 2.5 && Key Reference
     if (!FieldsandfiltersFactory::isVersion()) {
         $view->addTemplatePath(JPATH_THEMES . '/' . $app->getTemplate() . '/html/com_content/' . $class);
     }
     // set module to view
     $view->setModel($model, true);
     $view->document = $document;
     // add helpers
     JHtml::addIncludePath(JPATH_SITE . '/components/com_content/helpers');
     JHtml::addIncludePath(JPATH_SITE . '/components/com_content/helpers/html');
     KextensionsLanguage::load($option);
     $emptyItemsID = $itemsID->get('empty', false);
     $model->setState('fieldsandfilters.itemsID', (array) $itemsID->get('itemsID'));
     $model->setState('fieldsandfilters.emptyItemsID', $emptyItemsID);
     if ($jinput->get('random', false) && KextensionsModule::getParams($jinput->get('module'))->get('show_random', 0) && JComponentHelper::getParams('com_fieldsandfilters')->get('random_type_filters') == 'selected') {
         $model->setState('fieldsandfilters.random.selected', true);
         $model->setState('fieldsandfilters.random.limit', JComponentHelper::getParams('com_fieldsandfilters')->get('random_items_limit_filters', 0));
     }
     if (!$emptyItemsID) {
         ob_start();
         $view->display();
         $body = ob_get_contents();
         ob_end_clean();
     } else {
         $this->loadLanguage();
         $variables = new JObject();
         $variables->type = $this->_type;
         $variables->name = $this->_name;
         $variables->params = $this->params;
         $variables->extension = $extension;
         $body = KextensionsPlugin::renderLayout($variables, FieldsandfiltersPlugin::getLayout($this->params, 'empty_layout', 'empty'));
     }
     $itemsID = $model->getState('fieldsandfilters.itemsID', array());
     $fieldsID = $jinput->get('fields', array(), 'array');
     if (!empty($itemsID) && !empty($fieldsID) && !$emptyItemsID) {
         // Load Filters Helper
         $counts = (array) FieldsandfiltersFiltersHelper::getFiltersValuesCount($extension->content_type_id, $fieldsID, $itemsID, $model->getState('filter.published'));
         $data->set('counts', $counts);
     } else {
         if ($emptyItemsID) {
             // [TODO] when is empty display all fields with 0 counts or display special buttons to reset filters
             $data->set('empty', $emptyItemsID);
         }
     }
     $document->setBuffer($body, array('type' => 'component', 'name' => 'fieldsandfilters', 'title' => null));
     if (!$emptyItemsID) {
         // [TODO] move to another place because we need this only once
         $script[] = 'jQuery(document).ready(function($) {';
         $script[] = '	$("' . $this->params->get('selector_pagination_filters', '.pagination') . '").fieldsandfilters("pagination"' . ($app->get('sef', 0) ? ',{pagination: "start"}' : '') . ');';
         $script[] = '});';
         $document->addScriptDeclaration(implode("\n", $script));
     }
 }
 /**
  * Method to set certain otherwise inaccessible properties of the form field object.
  *
  * @param   string $name  The property name for which to the the value.
  * @param   mixed  $value The value of the property.
  *
  * @return  void
  *
  * @since   1.2.0 && J3.2
  */
 public function __set($name, $value)
 {
     switch ($name) {
         case 'exclude':
             $value = (string) $value;
             $this->{$name} = array_map('trim', explode(',', $value));
             break;
             /* @deprecated >= J3.2 */
         /* @deprecated >= J3.2 */
         case 'class':
             // Removes spaces from left & right and extra spaces from middle
             $value = preg_replace('/\\s+/', ' ', trim((string) $value));
             $this->{$name} = (string) $value;
             break;
         default:
             if (FieldsandfiltersFactory::isVersion('>=', 3.2)) {
                 parent::__set($name, $value);
             }
             break;
             /* @end deprecated >= J3.2 */
     }
 }
 /**
  * Get a types object.
  *
  * @see     FieldsandfiltersTypes
  * @since   1.2.0
  */
 public static function getTypes()
 {
     if (!self::$types) {
         self::$types = FieldsandfiltersTypes::getInstance();
     }
     return self::$types;
 }
 /**
  * Method to generate html code for a list of buttons
  *
  * @param   array|object $button Button properties
  *
  * @return  string
  *
  * @since       1.0.0
  */
 public static function button($button)
 {
     $user = JFactory::getUser();
     if (!empty($button['access'])) {
         if (is_bool($button['access'])) {
             if ($button['access'] == false) {
                 return '';
             }
         } else {
             // Take each pair of permission, context values.
             for ($i = 0, $n = count($button['access']); $i < $n; $i += 2) {
                 if (!$user->authorise($button['access'][$i], $button['access'][$i + 1])) {
                     return '';
                 }
             }
         }
     }
     $html[] = '<div class="icon"' . (empty($button['id']) ? '' : ' id="' . $button['id'] . '"') . '>';
     $html[] = '<a href="' . $button['link'] . '"';
     $html[] = empty($button['target']) ? '' : ' target="' . $button['target'] . '"';
     $html[] = empty($button['onclick']) ? '' : ' onclick="' . $button['onclick'] . '"';
     $html[] = empty($button['title']) ? '' : ' title="' . htmlspecialchars($button['title']) . '"';
     $html[] = '>';
     if (!empty($button['image'])) {
         $html[] = '<i class="icon-' . $button['image'] . (FieldsandfiltersFactory::isVersion('<') ? ' faf-j25' : '') . '"></i>';
     } else {
         $html[] = JHtml::_('image', empty($button['icon']) ? '' : $button['icon'], empty($button['alt']) ? null : htmlspecialchars($button['alt']), null, empty($button['relative']) ? false : (bool) $button['relative']);
     }
     $html[] = empty($button['text']) ? '' : '<span>' . $button['text'] . '</span>';
     $html[] = '</a>';
     $html[] = '</div>';
     return implode($html);
 }
 /**
  * @since       1.0.0
  */
 public static function createImage($name, JObject $jobject)
 {
     if (FieldsandfiltersFactory::isVersion('>=', 3.2)) {
         $jimage = new JImage();
     } else {
         $jimage = new KextensionsJoomlaImageImage();
     }
     $jimage->loadFile(JPath::clean(JPATH_ROOT . '/' . $jobject->get('path')));
     if (!$jimage->isLoaded()) {
         throw new RuntimeException(JText::_('COM_FIELDSANDFILTERS_ERROR_IMAGE_FILE_NOT_EXIST'));
     }
     // If the parent folder doesn't exist we must create it
     $folder = JPath::clean(self::getCacheFolder() . '/' . $jobject->get('folder'));
     $src = '';
     try {
         if (!($isFolder = is_dir($folder))) {
             jimport('joomla.filesystem.folder');
             $isFolder = JFolder::create($folder);
         }
         if ($isFolder) {
             $width = (int) $jobject->get('width');
             $height = (int) $jobject->get('height');
             $method = (int) $jobject->get('method');
             if (!$width || !$height) {
                 throw new UnexpectedValueException(JText::sprintf('COM_FIELDSANDFILTERS_ERROR_UNEXPECTED_VALUE_WIDTH_OR_HEIGHT', $name));
             } else {
                 switch ($method) {
                     // Generate cropping resize image
                     case $jimage::CROP_RESIZE:
                         $jimage->cropResize($width, $height, false);
                         break;
                         // Generate cropping image
                     // Generate cropping image
                     case $jimage::CROP:
                         $jimage->crop($width, $height, null, null, false);
                         break;
                         // Generate resizing image
                     // Generate resizing image
                     case $jimage::SCALE_FILL:
                     case $jimage::SCALE_INSIDE:
                     case $jimage::SCALE_OUTSIDE:
                     case $jimage::SCALE_FIT:
                     default:
                         $jimage->resize($width, $height, false, $method);
                         break;
                 }
                 // Parent image properties
                 $properties = $jimage::getImageFileProperties($jimage->getPath());
                 $quality = (int) $jobject->get('quality', 75);
                 $quality = (int) min(max($quality, 0), 100);
                 if ($properties->type == IMAGETYPE_PNG) {
                     $quality = (int) min(max(floor($quality / 10), 0), 9);
                     $quality = abs(9 - $quality);
                 }
                 if (!($name = $jobject->get('name'))) {
                     $name = self::createNameImage($jobject);
                 }
                 $imagePath = JPath::clean($folder . '/' . JFile::makeSafe($name));
                 // Save image file to disk
                 $jimage->toFile($imagePath, $properties->type, array('quality' => $quality));
                 if (is_file($imagePath)) {
                     $src = str_replace(JPath::clean(JPATH_ROOT . '/'), '', $imagePath);
                 }
             }
         }
     } catch (Exception $e) {
         $jimage->destroy();
         throw new Exception($e->getMessage());
     }
     $jimage->destroy();
     return $src;
 }
 /**
  * @since       1.1.0
  */
 public function fields()
 {
     // Is ajax requerst
     KextensionsRequest::isAjax() or die;
     // Check for a valid token. If invalid, send a 403 with the error message.
     JSession::checkToken('request') or $this->sendResponse(new Exception(JText::_('JINVALID_TOKEN'), 403));
     $app = JFactory::getApplication();
     $requestID = $app->input->get('requestID', 0, 'alnum');
     $fieldID = $app->input->get('fieldID', 0, 'int');
     $extensionTypeID = $app->input->get('extensionID', 0, 'int');
     try {
         // Check if exist requestID and extention type id
         if (!$requestID) {
             throw new Exception(JText::_('COM_FILEDSANDFILTERS_FILTERS_ERROR_REQUEST_ID'), 403);
         } elseif (!$extensionTypeID) {
             throw new Exception(JText::_('COM_FILEDSANDFILTERS_FILTERS_ERROR_REQUEST_ID'), 403);
         } elseif (!$fieldID) {
             throw new Exception(JText::_('COM_FILEDSANDFILTERS_FILTERS_ERROR_FIELD_ID'), 403);
         }
         // Load PluginExtensions Helper
         if (!($extension = FieldsandfiltersFactory::getExtensions()->getExtensionsByTypeID($extensionTypeID)->get($extensionTypeID))) {
             throw new Exception(JText::_('COM_FILEDSANDFILTERS_FILTERS_ERROR_EXTENSION_NOT_EXISTS'), 403);
         } elseif (!($field = FieldsandfiltersFactory::getFields()->getFieldsByID($extension->extension_type_id, $fieldID)->get($fieldID))) {
             throw new Exception(JText::_('COM_FILEDSANDFILTERS_FILTERS_ERROR_FIELD_NOT_EXISTS'), 403);
         }
         self::_prepareDocument();
         JPluginHelper::importPlugin('fieldsandfilterstypes');
         // Trigger the onFieldsandfiltersPrepareFormField event.
         $context = 'com_fieldsandfilters.fields.' . $field->field_type;
         $data = new JObject();
         $app->triggerEvent('onFieldsandfiltersRequestJSON', array($context, $field, $data));
         // Send the response.
         $this->sendResponse($data);
     } catch (Exception $e) {
         $this->sendResponse($e);
     }
 }
 /**
  * Method to get the available options field values item. value & text
  *
  * @return    array    array associate value and text
  * @since       1.1.0
  */
 public static function fieldValues($fieldID, $state = 1)
 {
     $options = array();
     $extenionsID = FieldsandfiltersFactory::getExtensions()->getExtensionsColumn('content_type_id');
     $field = FieldsandfiltersFactory::getFields()->getFieldsByID($extenionsID, $fieldID, $state, true);
     if (($field = $field->get($fieldID)) && ($values = $field->values->getProperties(true))) {
         while ($value = array_shift($values)) {
             $options[] = JHtml::_('select.option', $value->id, $value->value);
         }
     }
     return $options;
 }
 /**
  * Execute and display a template script.
  *
  * @param   string  $tpl  The name of the template file to parse; automatically searches through the template paths.
  *
  * @return  mixed  A string if successful, otherwise a Error object.
  */
 public function display($tpl = null)
 {
     // [TODO] FaF need more elastic solution
     $this->commonCategoryDisplay();
     // Prepare the data
     // Get the metrics for the structural page layout.
     $params = $this->params;
     $numLeading = $params->def('num_leading_articles', 1);
     $numIntro = $params->def('num_intro_articles', 4);
     $numLinks = $params->def('num_links', 4);
     // Compute the article slugs and prepare introtext (runs content plugins).
     foreach ($this->items as $item) {
         $item->slug = $item->alias ? $item->id . ':' . $item->alias : $item->id;
         $item->parent_slug = $item->parent_alias ? $item->parent_id . ':' . $item->parent_alias : $item->parent_id;
         // No link for ROOT category
         if ($item->parent_alias == 'root') {
             $item->parent_slug = null;
         }
         $item->catslug = $item->category_alias ? $item->catid . ':' . $item->category_alias : $item->catid;
         $item->event = new stdClass();
         // Only Joomla 3.x can use JEventDispatcher
         $dispatcher = FieldsandfiltersFactory::isVersion() ? JEventDispatcher::getInstance() : JDispatcher::getInstance();
         // Old plugins: Ensure that text property is available
         if (!isset($item->text)) {
             $item->text = $item->introtext;
         }
         JPluginHelper::importPlugin('content');
         $dispatcher->trigger('onContentPrepare', array('com_content.category', &$item, &$item->params, 0));
         // Old plugins: Use processed text as introtext
         $item->introtext = $item->text;
         $results = $dispatcher->trigger('onContentAfterTitle', array('com_content.category', &$item, &$item->params, 0));
         $item->event->afterDisplayTitle = trim(implode("\n", $results));
         $results = $dispatcher->trigger('onContentBeforeDisplay', array('com_content.category', &$item, &$item->params, 0));
         $item->event->beforeDisplayContent = trim(implode("\n", $results));
         $results = $dispatcher->trigger('onContentAfterDisplay', array('com_content.category', &$item, &$item->params, 0));
         $item->event->afterDisplayContent = trim(implode("\n", $results));
     }
     // Check for layout override only if this is not the active menu item
     // If it is the active menu item, then the view and category id will match
     $app = JFactory::getApplication();
     $active = $app->getMenu()->getActive();
     $menus = $app->getMenu();
     $pathway = $app->getPathway();
     $title = null;
     if (!$active || (strpos($active->link, 'view=category') === false || strpos($active->link, '&id=' . (string) $this->category->id) === false)) {
         // Get the layout from the merged category params
         if ($layout = $this->category->params->get('category_layout')) {
             $this->setLayout($layout);
         }
     } elseif (isset($active->query['layout'])) {
         // We need to set the layout from the query in case this is an alternative menu item (with an alternative layout)
         $this->setLayout($active->query['layout']);
     }
     // For blog layouts, preprocess the breakdown of leading, intro and linked articles.
     // This makes it much easier for the designer to just interrogate the arrays.
     if ($params->get('layout_type') == 'blog' || $this->getLayout() == 'blog') {
         //$max = count($this->items);
         foreach ($this->items as $i => $item) {
             if ($i < $numLeading) {
                 $this->lead_items[] = $item;
             } elseif ($i >= $numLeading && $i < $numLeading + $numIntro) {
                 $this->intro_items[] = $item;
             } elseif ($i < $numLeading + $numIntro + $numLinks) {
                 $this->link_items[] = $item;
             } else {
                 continue;
             }
         }
         $this->columns = max(1, $params->def('num_columns', 1));
         $order = $params->def('multi_column_order', 1);
         if ($order == 0 && $this->columns > 1) {
             // call order down helper
             $this->intro_items = ContentHelperQuery::orderDownColumns($this->intro_items, $this->columns);
         }
     }
     // Because the application sets a default page title,
     // we need to get it from the menu item itself
     $menu = $menus->getActive();
     if ($menu) {
         $this->params->def('page_heading', $this->params->get('page_title', $menu->title));
     }
     $title = $this->params->get('page_title', '');
     $id = (int) @$menu->query['id'];
     // Check for empty title and add site name if param is set
     if (empty($title)) {
         $title = $app->get('sitename');
     } elseif ($app->get('sitename_pagetitles', 0) == 1) {
         $title = JText::sprintf('JPAGETITLE', $app->get('sitename'), $title);
     } elseif ($app->get('sitename_pagetitles', 0) == 2) {
         $title = JText::sprintf('JPAGETITLE', $title, $app->get('sitename'));
     }
     if (empty($title)) {
         $title = $this->category->title;
     }
     $this->document->setTitle($title);
     if ($this->category->metadesc) {
         $this->document->setDescription($this->category->metadesc);
     } elseif (!$this->category->metadesc && $this->params->get('menu-meta_description')) {
         $this->document->setDescription($this->params->get('menu-meta_description'));
     }
     if ($this->category->metakey) {
         $this->document->setMetadata('keywords', $this->category->metakey);
     } elseif (!$this->category->metakey && $this->params->get('menu-meta_keywords')) {
         $this->document->setMetadata('keywords', $this->params->get('menu-meta_keywords'));
     }
     if ($this->params->get('robots')) {
         $this->document->setMetadata('robots', $this->params->get('robots'));
     }
     if (!is_object($this->category->metadata)) {
         $this->category->metadata = new JRegistry($this->category->metadata);
     }
     if ($app->get('MetaAuthor') == '1' && $this->category->get('author', '')) {
         $this->document->setMetaData('author', $this->category->get('author', ''));
     }
     $mdata = $this->category->metadata->toArray();
     foreach ($mdata as $k => $v) {
         if ($v) {
             $this->document->setMetadata($k, $v);
         }
     }
     // [TODO] FaF need more elastic solution
     // Only Joomla 3.x can use JViewCategory
     return FieldsandfiltersFactory::isVersion() ? JViewCategory::display($tpl) : JViewLegacy::display($tpl);
 }
 /**
  * Method to get the field input markup.
  *
  * @return    string    The field input markup.
  * @since       1.2.0
  */
 protected function getInput()
 {
     // Initialise variables
     $value = '';
     $html = array();
     $size = !empty($this->size) ? ' size="' . $this->size . '"' : '';
     $class = !empty($this->class) ? ' class="' . $this->class . '"' : 'class="inputbox"';
     $recordId = (int) $this->form->getValue('id', 0);
     $typeExtension = 'extension';
     if ($extension = FieldsandfiltersFactory::getExtensions()->getExtensionsPivot('content_type_id', true)->get($this->value)) {
         // Load Extensions Helper
         KextensionsLanguage::load('plg_' . $extension->type . '_' . $extension->name, JPATH_ADMINISTRATOR);
         $extensionForm = $extension->forms->get($typeExtension, new JObject());
         if (isset($extensionForm->group->title)) {
             $value = JText::_($extensionForm->title) . ' [' . JText::_($extensionForm->group->title) . ']';
         } elseif (isset($extensionForm->title)) {
             $value = JText::_($extensionForm->title);
         }
     }
     // Load the javascript and css
     JHtml::_('behavior.framework');
     JHtml::_('behavior.modal');
     $query = array('option' => 'com_fieldsandfilters', 'view' => 'plugins', 'tmpl' => 'component', 'layout' => 'extensions', 'recordId' => $recordId);
     $link = JRoute::_('index.php?' . JURI::buildQuery($query));
     if (FieldsandfiltersFactory::isVersion()) {
         $html[] = '<span class="input-append">';
         $html[] = '	<input type="text" readonly="readonly" disabled="disabled" value="' . $value . '"' . $size . $class . ' />';
         $html[] = '	<a class="btn btn-primary" onclick="SqueezeBox.fromElement(this, {handler:\'iframe\', size: {x: 600, y: 450}, url:\'' . $link . '\'})">';
         $html[] = '		<i class="icon-list icon-white"></i>';
         $html[] = JText::_('JSELECT');
         $html[] = '	</a>';
         $html[] = '</span>';
         $html[] = '<input class="input-small" type="hidden" name="' . $this->name . '" value="' . htmlspecialchars($this->value, ENT_COMPAT, 'UTF-8') . '" />';
     } else {
         $html[] = '<input type="text" readonly="readonly" disabled="disabled" value="' . $value . '"' . $size . $class . ' />';
         $html[] = '<input type="button" value="' . JText::_('JSELECT') . '" onclick="SqueezeBox.fromElement(this, {handler:\'iframe\', size: {x: 600, y: 450}, url:\'' . $link . '\'})" />';
         $html[] = '<input type="hidden" name="' . $this->name . '" value="' . htmlspecialchars($this->value, ENT_COMPAT, 'UTF-8') . '" />';
     }
     return implode("\n", $html);
 }