/**
  * Method to get the available options plugin item type. value & text
  *
  * @return    array    array associate value and text
  * @since       1.1.0
  */
 public static function types($excluded = array())
 {
     $options = array();
     if ($types = get_object_vars(FieldsandfiltersFactory::getTypes()->getTypes())) {
         while ($type = array_shift($types)) {
             if (!in_array($type->name, $excluded)) {
                 // load plugin language
                 $extension = 'plg_' . $type->type . '_' . $type->name;
                 KextensionsLanguage::load($extension, JPATH_ADMINISTRATOR);
                 $options[] = JHtml::_('select.option', $type->name, JText::_(strtoupper($extension)));
             }
         }
     }
     return $options;
 }
 /**
  * Method to perform sanity checks on the JTable instance properties to ensure
  * they are safe to store in the database.  Child classes should override this
  * method to make sure the data they are storing in the database is safe and
  * as expected before storage.
  *
  * @return  boolean  True if the instance is sane and able to be stored in the database.
  *
  * @link     http://docs.joomla.org/JTable/check
  * @since    1.1.0
  */
 public function check()
 {
     //If there is an ordering column and this is a new row then get the next ordering value
     if ($this->id == 0) {
         $this->ordering = self::getNextOrder();
     }
     try {
         // Check for exist mode field
         if (!in_array($this->mode, (array) FieldsandfiltersModes::getModes(null, array(), true))) {
             throw new RuntimeException(JText::_('COM_FIELDSANDFILTERS_DATABASE_ERROR_VALID_FIELD_MODE'));
             return false;
         }
         // Check for a field name.
         if (trim($this->name) == '') {
             throw new RuntimeException(JText::_('COM_FIELDSANDFILTERS_DATABASE_ERROR_VALID_FIELD_NAME'));
         }
         // Check for a field type.
         if (trim($this->type) == '') {
             throw new RuntimeException(JText::_('COM_FIELDSANDFILTERS_DATABASE_ERROR_VALID_FIELD_TYPE'));
         } elseif (!FieldsandfiltersFactory::getTypes()->getTypes()->get($this->type)) {
             throw new RuntimeException(JText::sprintf('COM_FIELDSANDFILTERS_DATABASE_ERROR_FIELD_TYPE_NOT_EXISTS', $this->type));
         }
         // Check for a field extension type id.
         if (!$this->content_type_id) {
             throw new RuntimeException(JText::_('COM_FIELDSANDFILTERS_DATABASE_ERROR_VALID_FIELD_CONTENT_TYPE_ID'));
         } elseif (!FieldsandfiltersFactory::getExtensions()->getExtensionsByTypeID($this->content_type_id)->get($this->content_type_id)) {
             throw new RuntimeException(JText::sprintf('COM_FIELDSANDFILTERS_DATABASE_ERROR_CONTENT_TYPE_ID_NOT_EXISTS', $this->content_type_id));
         }
     } catch (RuntimeException $e) {
         $this->setError($e->getMessage());
         return false;
     }
     // Check mode field
     if (in_array($this->mode, (array) FieldsandfiltersModes::getMode(FieldsandfiltersModes::MODE_FILTER))) {
         // Check for a field alias
         if (trim($this->alias) == '') {
             $this->alias = $this->name;
         }
         $this->alias = JApplication::stringURLSafe($this->alias);
         if (trim(str_replace('-', '', $this->alias)) == '') {
             $this->alias = JFactory::getDate()->format('Y-m-d-H-i-s');
         }
     } elseif (trim($this->alias) != '') {
         $this->alias = '';
     }
     return true;
 }
 /**
  * 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 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 setType($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_type']));
     $name = $options->get('name');
     $typeMode = $options->get('type_mode');
     $modes = FieldsandfiltersModes::getMode()->get($typeMode);
     $type = FieldsandfiltersFactory::getTypes()->getTypesByName($name)->get($name);
     if ($name && $modes && $type && $recordId == $options->get('id', 0)) {
         $data['type'] = $name;
         $data['type_mode'] = $typeMode;
         //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;
 }
 /**
  * @param    object $form A form object.
  * @param    mixed  $data The data expected for the form.
  *
  * @return    void
  * @since       1.1.0
  * @throws    Exception if there is an error in the form event.
  */
 protected function preprocessForm(JForm $form, $data, $group = 'content')
 {
     $data = $data instanceof JRegistry ? $data : new JRegistry($data);
     $fieldType = $data->get('type', $this->getState($this->getName() . '.type'));
     $typeMode = $data->get('type_mode', FieldsandfiltersModes::getModeName($data->get('mode', $this->getState($this->getName() . '.mode')), FieldsandfiltersModes::MODE_NAME_TYPE));
     try {
         if ($fieldType && $typeMode && ($type = FieldsandfiltersFactory::getTypes()->getTypes(true)->get($fieldType))) {
             $path = $type->forms->get($typeMode, new JObject())->get('path');
             $form::addFormPath($path);
             if (!$form->loadFile($typeMode, true, '/metadata/form/*')) {
                 throw new Exception(JText::_('JERROR_LOADFILE_FAILED'));
             }
             if ($layoutType = $data->get('params.type.' . $typeMode . '_layout', $this->getState($this->getName() . '.layoutType'))) {
                 $paths = array(JPath::clean(JPATH_PLUGINS . '/' . $type->type . '/' . $type->name . '/tmpl/' . $typeMode));
                 if (strpos($layoutType, ':') > 0 && strpos($layoutType, '_:') !== 0) {
                     list($template, $layoutType) = explode(':', $layoutType);
                     $paths[] = JPATH::clean(JPATH_SITE . '/templates/' . $template . '/html/plg_' . $type->type . '_' . $type->name . '/' . $typeMode);
                 }
                 $path = JPath::find($paths, $layoutType . '.xml');
                 if (is_file($path)) {
                     if (!$form->loadFile($path, true, '/form/*')) {
                         throw new Exception(JText::_('JERROR_LOADFILE_FAILED'));
                     }
                 }
             }
             // load plugin language
             KextensionsLanguage::load('plg_' . $type->type . '_' . $type->name, JPATH_ADMINISTRATOR);
         }
         $contentTypeId = $data->get('content_type_id', $this->getState($this->getName() . '.content_type_id'));
         $extensionForm = $data->get('extension_form', 'extension');
         // get extension type objet by type id or plugin type
         if ($contentTypeId && ($extension = FieldsandfiltersFactory::getExtensions()->getExtensionsByTypeID($contentTypeId, true, true)->get($contentTypeId))) {
             $path = $extension->forms->get($extensionForm, new JObject())->get('path');
             $form::addFormPath($path);
             if (!$form->loadFile($extensionForm, true, '/metadata/form/*')) {
                 throw new Exception(JText::_('JERROR_LOADFILE_FAILED'));
             }
             // load plugin language
             KextensionsLanguage::load('plg_' . $extension->type . '_' . $extension->name, JPATH_ADMINISTRATOR);
         }
     } catch (Exception $e) {
         $this->setError($e->getMessage());
         return;
     }
     // overwrite the mode default of the plugin type mode
     $form->setFieldAttribute('mode', 'default', FieldsandfiltersModes::getMode($form->getFieldAttribute('mode', 'value', 'field.text', 'properties')));
     // Trigger the default form events.
     parent::preprocessForm($form, $data, $group);
 }
<?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);
 /**
  * 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);
     $mode = (int) $this->form->getValue('mode', 0);
     $typesHelper = FieldsandfiltersFactory::getTypes();
     if ($mode && ($pluginType = $typesHelper->getTypes(true)->get($this->value))) {
         // Load Extensions Helper
         KextensionsLanguage::load('plg_' . $pluginType->type . '_' . $pluginType->name, JPATH_ADMINISTRATOR);
         $modeName = FieldsandfiltersModes::getModeName($mode, FieldsandfiltersModes::MODE_NAME_TYPE);
         $typeForm = $pluginType->forms->get($modeName, new JObject());
         if (isset($typeForm->group->title)) {
             $value = JText::_($typeForm->title) . ' [' . JText::_($typeForm->group->title) . ']';
         } else {
             if (isset($typeForm->title)) {
                 $value = JText::_($typeForm->title);
             }
         }
     }
     // Load the javascript and css
     JHtml::_('behavior.framework');
     JHtml::_('behavior.modal');
     $query = array('option' => 'com_fieldsandfilters', 'view' => 'plugins', 'tmpl' => 'component', 'layout' => 'types', '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);
 }