| Current Path : /home/digilove/www/41423/ |
| Current File : /home/digilove/www/41423/Form.tar |
Field/AuthorField.php 0000644 00000003021 15234515367 0010515 0 ustar 00 <?php
/**
* Joomla! Content Management System
*
* @copyright (C) 2013 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\CMS\Form\Field;
defined('JPATH_PLATFORM') or die;
use Joomla\CMS\Factory;
use Joomla\CMS\Form\FormHelper;
FormHelper::loadFieldClass('list');
/**
* Form Field to load a list of content authors
*
* @since 3.2
*/
class AuthorField extends \JFormFieldList
{
/**
* The form field type.
*
* @var string
* @since 3.2
*/
public $type = 'Author';
/**
* Cached array of the category items.
*
* @var array
* @since 3.2
*/
protected static $options = array();
/**
* Method to get the options to populate list
*
* @return array The field option objects.
*
* @since 3.2
*/
protected function getOptions()
{
// Accepted modifiers
$hash = md5($this->element);
if (!isset(static::$options[$hash]))
{
static::$options[$hash] = parent::getOptions();
$db = Factory::getDbo();
// Construct the query
$query = $db->getQuery(true)
->select('u.id AS value, u.name AS text')
->from('#__users AS u')
->join('INNER', '#__content AS c ON c.created_by = u.id')
->group('u.id, u.name')
->order('u.name');
// Setup the query
$db->setQuery($query);
// Return the result
if ($options = $db->loadObjectList())
{
static::$options[$hash] = array_merge(static::$options[$hash], $options);
}
}
return static::$options[$hash];
}
}
Field/CaptchaField.php 0000644 00000010230 15234515367 0010616 0 ustar 00 <?php
/**
* Joomla! Content Management System
*
* @copyright (C) 2011 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\CMS\Form\Field;
defined('JPATH_PLATFORM') or die;
use Joomla\CMS\Captcha\Captcha;
use Joomla\CMS\Factory;
use Joomla\CMS\Form\FormField;
/**
* Captcha field.
*
* @since 2.5
*/
class CaptchaField extends FormField
{
/**
* The field type.
*
* @var string
* @since 2.5
*/
protected $type = 'Captcha';
/**
* The captcha base instance of our type.
*
* @var Captcha
*/
protected $_captcha;
/**
* Method to get certain otherwise inaccessible properties from the form field object.
*
* @param string $name The property name for which to get the value.
*
* @return mixed The property value or null.
*
* @since 3.2
*/
public function __get($name)
{
switch ($name)
{
case 'plugin':
case 'namespace':
return $this->$name;
}
return parent::__get($name);
}
/**
* Method to set certain otherwise inaccessible properties of the form field object.
*
* @param string $name The property name for which to set the value.
* @param mixed $value The value of the property.
*
* @return void
*
* @since 3.2
*/
public function __set($name, $value)
{
switch ($name)
{
case 'plugin':
case 'namespace':
$this->$name = (string) $value;
break;
default:
parent::__set($name, $value);
}
}
/**
* Method to attach a JForm object to the field.
*
* @param \SimpleXMLElement $element The SimpleXMLElement object representing the `<field>` tag for the form field object.
* @param mixed $value The form field value to validate.
* @param string $group The field name group control value. This acts as an array container for the field.
* For example if the field has name="foo" and the group value is set to "bar" then the
* full field name would end up being "bar[foo]".
*
* @return boolean True on success.
*
* @since 2.5
*/
public function setup(\SimpleXMLElement $element, $value, $group = null)
{
$result = parent::setup($element, $value, $group);
$app = Factory::getApplication();
$default = $app->get('captcha');
if ($app->isClient('site'))
{
$default = $app->getParams()->get('captcha', $default);
}
$plugin = $this->element['plugin'] ?
(string) $this->element['plugin'] :
$default;
$this->plugin = $plugin;
if ($plugin === 0 || $plugin === '0' || $plugin === '' || $plugin === null)
{
$this->hidden = true;
return false;
}
else
{
// Force field to be required. There's no reason to have a captcha if it is not required.
// Obs: Don't put required="required" in the xml file, you just need to have validate="captcha"
$this->required = true;
if (strpos($this->class, 'required') === false)
{
$this->class .= ' required';
}
}
$this->namespace = $this->element['namespace'] ? (string) $this->element['namespace'] : $this->form->getName();
try
{
// Get an instance of the captcha class that we are using
$this->_captcha = Captcha::getInstance($this->plugin, array('namespace' => $this->namespace));
/**
* Give the captcha instance a possibility to react on the setup-process,
* e.g. by altering the XML structure of the field, for example hiding the label
* when using invisible captchas.
*/
$this->_captcha->setupField($this, $element);
}
catch (\RuntimeException $e)
{
$this->_captcha = null;
\JFactory::getApplication()->enqueueMessage($e->getMessage(), 'error');
return false;
}
return $result;
}
/**
* Method to get the field input.
*
* @return string The field input.
*
* @since 2.5
*/
protected function getInput()
{
if ($this->hidden || $this->_captcha == null)
{
return '';
}
try
{
return $this->_captcha->display($this->name, $this->id, $this->class);
}
catch (\RuntimeException $e)
{
\JFactory::getApplication()->enqueueMessage($e->getMessage(), 'error');
}
return '';
}
}
Field/ChromestyleField.php 0000644 00000013070 15234515367 0011556 0 ustar 00 <?php
/**
* Joomla! Content Management System
*
* @copyright (C) 2012 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\CMS\Form\Field;
defined('JPATH_PLATFORM') or die;
use Joomla\CMS\Factory;
use Joomla\CMS\Form\FormHelper;
FormHelper::loadFieldClass('groupedlist');
/**
* Chrome Styles field.
*
* @since 3.0
*/
class ChromestyleField extends \JFormFieldGroupedList
{
/**
* The form field type.
*
* @var string
* @since 3.0
*/
public $type = 'ChromeStyle';
/**
* The client ID.
*
* @var integer
* @since 3.2
*/
protected $clientId;
/**
* Method to get certain otherwise inaccessible properties from the form field object.
*
* @param string $name The property name for which to get the value.
*
* @return mixed The property value or null.
*
* @since 3.2
*/
public function __get($name)
{
switch ($name)
{
case 'clientId':
return $this->clientId;
}
return parent::__get($name);
}
/**
* Method to set certain otherwise inaccessible properties of the form field object.
*
* @param string $name The property name for which to get the value.
* @param mixed $value The value of the property.
*
* @return void
*
* @since 3.2
*/
public function __set($name, $value)
{
switch ($name)
{
case 'clientId':
$this->clientId = (string) $value;
break;
default:
parent::__set($name, $value);
}
}
/**
* Method to attach a JForm object to the field.
*
* @param \SimpleXMLElement $element The SimpleXMLElement object representing the `<field>` tag for the form field object.
* @param mixed $value The form field value to validate.
* @param string $group The field name group control value. This acts as an array container for the field.
* For example if the field has name="foo" and the group value is set to "bar" then the
* full field name would end up being "bar[foo]".
*
* @return boolean True on success.
*
* @see JFormField::setup()
* @since 3.2
*/
public function setup(\SimpleXMLElement $element, $value, $group = null)
{
$result = parent::setup($element, $value, $group);
if ($result === true)
{
// Get the client id.
$clientId = $this->element['client_id'];
if (!isset($clientId))
{
$clientName = $this->element['client'];
if (isset($clientName))
{
$client = \JApplicationHelper::getClientInfo($clientName, true);
$clientId = $client->id;
}
}
if (!isset($clientId) && $this->form instanceof \JForm)
{
$clientId = $this->form->getValue('client_id');
}
$this->clientId = (int) $clientId;
}
return $result;
}
/**
* Method to get the list of template chrome style options
* grouped by template.
*
* @return array The field option objects as a nested array in groups.
*
* @since 3.0
*/
protected function getGroups()
{
$groups = array();
// Add Module Style Field
$tmp = '---' . \JText::_('JLIB_FORM_VALUE_FROM_TEMPLATE') . '---';
$groups[$tmp][] = \JHtml::_('select.option', '0', \JText::_('JLIB_FORM_VALUE_INHERITED'));
$templateStyles = $this->getTemplateModuleStyles();
// Create one new option object for each available style, grouped by templates
foreach ($templateStyles as $template => $styles)
{
$template = ucfirst($template);
$groups[$template] = array();
foreach ($styles as $style)
{
$tmp = \JHtml::_('select.option', $template . '-' . $style, $style);
$groups[$template][] = $tmp;
}
}
reset($groups);
return $groups;
}
/**
* Method to get the templates module styles.
*
* @return array The array of styles, grouped by templates.
*
* @since 3.0
*/
protected function getTemplateModuleStyles()
{
$moduleStyles = array();
$templates = array($this->getSystemTemplate());
$templates = array_merge($templates, $this->getTemplates());
$path = JPATH_ADMINISTRATOR;
if ($this->clientId === 0)
{
$path = JPATH_SITE;
}
foreach ($templates as $template)
{
$modulesFilePath = $path . '/templates/' . $template->element . '/html/modules.php';
// Is there modules.php for that template?
if (file_exists($modulesFilePath))
{
$modulesFileData = file_get_contents($modulesFilePath);
preg_match_all('/function[\s\t]*modChrome\_([a-z0-9\-\_]*)[\s\t]*\(/i', $modulesFileData, $styles);
if (!array_key_exists($template->element, $moduleStyles))
{
$moduleStyles[$template->element] = array();
}
$moduleStyles[$template->element] = $styles[1];
}
}
return $moduleStyles;
}
/**
* Method to get the system template as an object.
*
* @return \stdClass The object of system template.
*
* @since 3.0
*/
protected function getSystemTemplate()
{
$template = new \stdClass;
$template->element = 'system';
$template->name = 'system';
return $template;
}
/**
* Return a list of templates
*
* @return array List of templates
*
* @since 3.2.1
*/
protected function getTemplates()
{
$db = Factory::getDbo();
// Get the database object and a new query object.
$query = $db->getQuery(true);
// Build the query.
$query->select('element, name')
->from('#__extensions')
->where('client_id = ' . $this->clientId)
->where('type = ' . $db->quote('template'))
->where('enabled = 1');
// Set the query and load the templates.
$db->setQuery($query);
return $db->loadObjectList('element');
}
}
Field/ContenthistoryField.php 0000644 00000003611 15234515367 0012314 0 ustar 00 <?php
/**
* Joomla! Content Management System
*
* @copyright (C) 2013 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\CMS\Form\Field;
defined('JPATH_PLATFORM') or die;
use Joomla\CMS\Form\FormField;
use Joomla\CMS\Session\Session;
use Joomla\CMS\Table\Table;
/**
* Field to select Content History from a modal list.
*
* @since 3.2
*/
class ContenthistoryField extends FormField
{
/**
* The form field type.
*
* @var string
* @since 3.2
*/
public $type = 'ContentHistory';
/**
* Layout to render the label
*
* @var string
*/
protected $layout = 'joomla.form.field.contenthistory';
/**
* Get the data that is going to be passed to the layout
*
* @return array
*/
public function getLayoutData()
{
// Get the basic field data
$data = parent::getLayoutData();
$typeId = Table::getInstance('Contenttype')->getTypeId($this->element['data-typeAlias']);
$itemId = $this->form->getValue('id');
$label = \JText::_('JTOOLBAR_VERSIONS');
$link = 'index.php?option=com_contenthistory&view=history&layout=modal&tmpl=component&field='
. $this->id . '&item_id=' . $itemId . '&type_id=' . $typeId . '&type_alias='
. $this->element['data-typeAlias'] . '&' . Session::getFormToken() . '=1';
$extraData = array(
'type' => $typeId,
'item' => $itemId,
'label' => $label,
'link' => $link,
);
return array_merge($data, $extraData);
}
/**
* Method to get the content history field input markup.
*
* @return string The field input markup.
*
* @since 3.2
*/
protected function getInput()
{
if (empty($this->layout))
{
throw new \UnexpectedValueException(sprintf('%s has no layout assigned.', $this->name));
}
return $this->getRenderer($this->layout)->render($this->getLayoutData());
}
}
Field/ContentlanguageField.php 0000644 00000001640 15234515367 0012376 0 ustar 00 <?php
/**
* Joomla! Content Management System
*
* @copyright (C) 2009 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\CMS\Form\Field;
defined('JPATH_PLATFORM') or die;
use Joomla\CMS\Form\FormHelper;
FormHelper::loadFieldClass('list');
/**
* Provides a list of content languages
*
* @see JFormFieldLanguage for a select list of application languages.
* @since 1.6
*/
class ContentlanguageField extends \JFormFieldList
{
/**
* The form field type.
*
* @var string
* @since 1.6
*/
public $type = 'ContentLanguage';
/**
* Method to get the field options for content languages.
*
* @return array The options the field is going to show.
*
* @since 1.6
*/
protected function getOptions()
{
return array_merge(parent::getOptions(), \JHtml::_('contentlanguage.existing'));
}
}
Field/ContenttypeField.php 0000644 00000004415 15234515367 0011577 0 ustar 00 <?php
/**
* Joomla! Content Management System
*
* @copyright (C) 2013 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\CMS\Form\Field;
defined('JPATH_PLATFORM') or die;
use Joomla\CMS\Factory;
use Joomla\CMS\Form\FormHelper;
FormHelper::loadFieldClass('list');
/**
* Content Type field.
*
* @since 3.1
*/
class ContenttypeField extends \JFormFieldList
{
/**
* A flexible tag list that respects access controls
*
* @var string
* @since 3.1
*/
public $type = 'Contenttype';
/**
* Method to get the field input for a list of content types.
*
* @return string The field input.
*
* @since 3.1
*/
protected function getInput()
{
if (!is_array($this->value))
{
if (is_object($this->value))
{
$this->value = $this->value->tags;
}
if (is_string($this->value))
{
$this->value = explode(',', $this->value);
}
}
return parent::getInput();
}
/**
* Method to get a list of content types
*
* @return array The field option objects.
*
* @since 3.1
*/
protected function getOptions()
{
$lang = Factory::getLanguage();
$db = Factory::getDbo();
$query = $db->getQuery(true)
->select('a.type_id AS value, a.type_title AS text, a.type_alias AS alias')
->from('#__content_types AS a')
->order('a.type_title ASC');
// Get the options.
$db->setQuery($query);
try
{
$options = $db->loadObjectList();
}
catch (\RuntimeException $e)
{
return array();
}
foreach ($options as $option)
{
// Make up the string from the component sys.ini file
$parts = explode('.', $option->alias);
$comp = array_shift($parts);
// Make sure the component sys.ini is loaded
$lang->load($comp . '.sys', JPATH_ADMINISTRATOR, null, false, true)
|| $lang->load($comp . '.sys', JPATH_ADMINISTRATOR . '/components/' . $comp, null, false, true);
$option->string = implode('_', $parts);
$option->string = $comp . '_CONTENT_TYPE_' . $option->string;
if ($lang->hasKey($option->string))
{
$option->text = \JText::_($option->string);
}
}
// Merge any additional options in the XML definition.
$options = array_merge(parent::getOptions(), $options);
return $options;
}
}
Field/EditorField.php 0000644 00000017016 15234515367 0010512 0 ustar 00 <?php
/**
* Joomla! Content Management System
*
* @copyright (C) 2009 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\CMS\Form\Field;
defined('JPATH_PLATFORM') or die;
use Joomla\CMS\Editor\Editor;
use Joomla\CMS\Factory;
use Joomla\CMS\Form\FormHelper;
FormHelper::loadFieldClass('textarea');
/**
* A textarea field for content creation
*
* @see JEditor
* @since 1.6
*/
class EditorField extends \JFormFieldTextarea
{
/**
* The form field type.
*
* @var string
* @since 1.6
*/
public $type = 'Editor';
/**
* The Editor object.
*
* @var Editor
* @since 1.6
*/
protected $editor;
/**
* The height of the editor.
*
* @var string
* @since 3.2
*/
protected $height;
/**
* The width of the editor.
*
* @var string
* @since 3.2
*/
protected $width;
/**
* The assetField of the editor.
*
* @var string
* @since 3.2
*/
protected $assetField;
/**
* The authorField of the editor.
*
* @var string
* @since 3.2
*/
protected $authorField;
/**
* The asset of the editor.
*
* @var string
* @since 3.2
*/
protected $asset;
/**
* The buttons of the editor.
*
* @var mixed
* @since 3.2
*/
protected $buttons;
/**
* The hide of the editor.
*
* @var array
* @since 3.2
*/
protected $hide;
/**
* The editorType of the editor.
*
* @var array
* @since 3.2
*/
protected $editorType;
/**
* Method to get certain otherwise inaccessible properties from the form field object.
*
* @param string $name The property name for which to get the value.
*
* @return mixed The property value or null.
*
* @since 3.2
*/
public function __get($name)
{
switch ($name)
{
case 'height':
case 'width':
case 'assetField':
case 'authorField':
case 'asset':
case 'buttons':
case 'hide':
case 'editorType':
return $this->$name;
}
return parent::__get($name);
}
/**
* Method to set certain otherwise inaccessible properties of the form field object.
*
* @param string $name The property name for which to set the value.
* @param mixed $value The value of the property.
*
* @return void
*
* @since 3.2
*/
public function __set($name, $value)
{
switch ($name)
{
case 'height':
case 'width':
case 'assetField':
case 'authorField':
case 'asset':
$this->$name = (string) $value;
break;
case 'buttons':
$value = (string) $value;
if ($value === 'true' || $value === 'yes' || $value === '1')
{
$this->buttons = true;
}
elseif ($value === 'false' || $value === 'no' || $value === '0')
{
$this->buttons = false;
}
else
{
$this->buttons = explode(',', $value);
}
break;
case 'hide':
$value = (string) $value;
$this->hide = $value ? explode(',', $value) : array();
break;
case 'editorType':
// Can be in the form of: editor="desired|alternative".
$this->editorType = explode('|', trim((string) $value));
break;
default:
parent::__set($name, $value);
}
}
/**
* Method to attach a JForm object to the field.
*
* @param \SimpleXMLElement $element The SimpleXMLElement object representing the `<field>` tag for the form field object.
* @param mixed $value The form field value to validate.
* @param string $group The field name group control value. This acts as an array container for the field.
* For example if the field has name="foo" and the group value is set to "bar" then the
* full field name would end up being "bar[foo]".
*
* @return boolean True on success.
*
* @see FormField::setup()
* @since 3.2
*/
public function setup(\SimpleXMLElement $element, $value, $group = null)
{
$result = parent::setup($element, $value, $group);
if ($result === true)
{
$this->height = $this->element['height'] ? (string) $this->element['height'] : '500';
$this->width = $this->element['width'] ? (string) $this->element['width'] : '100%';
$this->assetField = $this->element['asset_field'] ? (string) $this->element['asset_field'] : 'asset_id';
$this->authorField = $this->element['created_by_field'] ? (string) $this->element['created_by_field'] : 'created_by';
$this->asset = $this->form->getValue($this->assetField) ?: (string) $this->element['asset_id'];
$buttons = (string) $this->element['buttons'];
$hide = (string) $this->element['hide'];
$editorType = (string) $this->element['editor'];
if ($buttons === 'true' || $buttons === 'yes' || $buttons === '1')
{
$this->buttons = true;
}
elseif ($buttons === 'false' || $buttons === 'no' || $buttons === '0')
{
$this->buttons = false;
}
else
{
$this->buttons = !empty($hide) ? explode(',', $buttons) : array();
}
$this->hide = !empty($hide) ? explode(',', (string) $this->element['hide']) : array();
$this->editorType = !empty($editorType) ? explode('|', trim($editorType)) : array();
}
return $result;
}
/**
* Method to get the field input markup for the editor area
*
* @return string The field input markup.
*
* @since 1.6
*/
protected function getInput()
{
// Get an editor object.
$editor = $this->getEditor();
$params = array(
'autofocus' => $this->autofocus,
'readonly' => $this->readonly || $this->disabled,
'syntax' => (string) $this->element['syntax'],
);
return $editor->display(
$this->name,
htmlspecialchars($this->value, ENT_COMPAT, 'UTF-8'),
$this->width,
$this->height,
$this->columns,
$this->rows,
$this->buttons ? (is_array($this->buttons) ? array_merge($this->buttons, $this->hide) : $this->hide) : false,
$this->id,
$this->asset,
$this->form->getValue($this->authorField),
$params
);
}
/**
* Method to get an Editor object based on the form field.
*
* @return Editor The Editor object.
*
* @since 1.6
*/
protected function getEditor()
{
// Only create the editor if it is not already created.
if (empty($this->editor))
{
$editor = null;
if ($this->editorType)
{
// Get the list of editor types.
$types = $this->editorType;
// Get the database object.
$db = Factory::getDbo();
// Iterate over the types looking for an existing editor.
foreach ($types as $element)
{
// Build the query.
$query = $db->getQuery(true)
->select('element')
->from('#__extensions')
->where('element = ' . $db->quote($element))
->where('folder = ' . $db->quote('editors'))
->where('enabled = 1');
// Check of the editor exists.
$db->setQuery($query, 0, 1);
$editor = $db->loadResult();
// If an editor was found stop looking.
if ($editor)
{
break;
}
}
}
// Create the JEditor instance based on the given editor.
if ($editor === null)
{
$editor = Factory::getConfig()->get('editor');
}
$this->editor = Editor::getInstance($editor);
}
return $this->editor;
}
/**
* Method to get the JEditor output for an onSave event.
*
* @return string The JEditor object output.
*
* @since 1.6
* @deprecated 4.0 Will be removed without replacement
* @see Editor::save()
*/
public function save()
{
$editor = $this->getEditor();
if (!method_exists($editor, 'save'))
{
return '';
}
return $editor->save($this->id);
}
}
Field/FrontendlanguageField.php 0000644 00000003713 15234515367 0012546 0 ustar 00 <?php
/**
* Joomla! Content Management System
*
* @copyright (C) 2015 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\CMS\Form\Field;
defined('JPATH_PLATFORM') or die;
use Joomla\CMS\Factory;
use Joomla\CMS\Form\FormHelper;
FormHelper::loadFieldClass('list');
/**
* Provides a list of published content languages with home pages
*
* @see JFormFieldLanguage for a select list of application languages.
* @since 3.5
*/
class FrontendlanguageField extends \JFormFieldList
{
/**
* The form field type.
*
* @var string
* @since 3.5
*/
public $type = 'Frontend_Language';
/**
* Method to get the field options for frontend published content languages with homes.
*
* @return array The options the field is going to show.
*
* @since 3.5
*/
protected function getOptions()
{
// Get the database object and a new query object.
$db = Factory::getDbo();
$query = $db->getQuery(true);
$query->select('a.lang_code AS value, a.title AS text')
->from($db->quoteName('#__languages') . ' AS a')
->where('a.published = 1')
->order('a.title');
// Select the language home pages.
$query->select('l.home, l.language')
->innerJoin($db->quoteName('#__menu') . ' AS l ON l.language=a.lang_code AND l.home=1 AND l.published=1 AND l.language <> ' . $db->quote('*'))
->innerJoin($db->quoteName('#__extensions') . ' AS e ON e.element = a.lang_code')
->where('e.client_id = 0')
->where('e.enabled = 1')
->where('e.state = 0');
$db->setQuery($query);
try
{
$languages = $db->loadObjectList();
}
catch (\RuntimeException $e)
{
$languages = array();
if (Factory::getUser()->authorise('core.admin'))
{
Factory::getApplication()->enqueueMessage($e->getMessage(), 'error');
}
}
// Merge any additional options in the XML definition.
return array_merge(parent::getOptions(), $languages);
}
}
Field/HeadertagField.php 0000644 00000001760 15234515367 0011147 0 ustar 00 <?php
/**
* Joomla! Content Management System
*
* @copyright (C) 2012 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\CMS\Form\Field;
defined('JPATH_PLATFORM') or die;
use Joomla\CMS\Form\FormHelper;
FormHelper::loadFieldClass('list');
/**
* Form Field class for the Joomla! CMS.
*
* @since 3.0
*/
class HeadertagField extends \JFormFieldList
{
/**
* The form field type.
*
* @var string
* @since 3.0
*/
protected $type = 'HeaderTag';
/**
* Method to get the field options.
*
* @return array The field option objects.
*
* @since 3.0
*/
protected function getOptions()
{
$options = array();
$tags = array('h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'p', 'div');
// Create one new option object for each tag
foreach ($tags as $tag)
{
$tmp = \JHtml::_('select.option', $tag, $tag);
$options[] = $tmp;
}
reset($options);
return $options;
}
}
Field/HelpsiteField.php 0000644 00000003250 15234515367 0011034 0 ustar 00 <?php
/**
* Joomla! Content Management System
*
* @copyright (C) 2009 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\CMS\Form\Field;
defined('JPATH_PLATFORM') or die;
use Joomla\CMS\Form\FormHelper;
use Joomla\CMS\Help\Help;
FormHelper::loadFieldClass('list');
/**
* Form Field class for the Joomla Platform.
* Provides a select list of help sites.
*
* @since 1.6
* @deprecated 4.0 To be removed
*/
class HelpsiteField extends \JFormFieldList
{
/**
* The form field type.
*
* @var string
* @since 1.6
*/
public $type = 'Helpsite';
/**
* Method to get the help site field options.
*
* @return array The field option objects.
*
* @since 1.6
*/
protected function getOptions()
{
// Merge any additional options in the XML definition.
$options = array_merge(parent::getOptions(), Help::createSiteList(JPATH_ADMINISTRATOR . '/help/helpsites.xml', $this->value));
return $options;
}
/**
* Override to add refresh button
*
* @return string The field input markup.
*
* @since 3.2
*/
protected function getInput()
{
\JHtml::_('script', 'system/helpsite.js', array('version' => 'auto', 'relative' => true));
$showDefault = (string) $this->getAttribute('showDefault') === 'false' ? 'false' : 'true';
$html = parent::getInput();
$button = '<button
type="button"
class="btn btn-small"
id="helpsite-refresh"
rel="' . $this->id . '"
showDefault="' . $showDefault . '"
>
<span>' . \JText::_('JGLOBAL_HELPREFRESH_BUTTON') . '</span>
</button>';
return $html . $button;
}
}
Field/LastvisitdaterangeField.php 0000644 00000002746 15234515367 0013125 0 ustar 00 <?php
/**
* Joomla! Content Management System
*
* @copyright (C) 2016 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\CMS\Form\Field;
defined('JPATH_PLATFORM') or die;
use Joomla\CMS\Factory;
use Joomla\CMS\Form\Form;
use Joomla\CMS\Form\FormHelper;
FormHelper::loadFieldClass('predefinedlist');
/**
* Field to show a list of available date ranges to filter on last visit date.
*
* @since 3.6
*/
class LastvisitdaterangeField extends \JFormFieldPredefinedList
{
/**
* Method to instantiate the form field object.
*
* @param Form $form The form to attach to the form field object.
*
* @since 1.7.0
*/
public function __construct($form = null)
{
parent::__construct($form);
// Set the type
$this->type = 'LastvisitDateRange';
// Load the required language
$lang = Factory::getLanguage();
$lang->load('com_users', JPATH_ADMINISTRATOR);
// Set the pre-defined options
$this->predefinedOptions = array(
'today' => 'COM_USERS_OPTION_RANGE_TODAY',
'past_week' => 'COM_USERS_OPTION_RANGE_PAST_WEEK',
'past_1month' => 'COM_USERS_OPTION_RANGE_PAST_1MONTH',
'past_3month' => 'COM_USERS_OPTION_RANGE_PAST_3MONTH',
'past_6month' => 'COM_USERS_OPTION_RANGE_PAST_6MONTH',
'past_year' => 'COM_USERS_OPTION_RANGE_PAST_YEAR',
'post_year' => 'COM_USERS_OPTION_RANGE_POST_YEAR',
'never' => 'COM_USERS_OPTION_RANGE_NEVER',
);
}
}
Field/LimitboxField.php 0000644 00000004357 15234515367 0011057 0 ustar 00 <?php
/**
* Joomla! Content Management System
*
* @copyright (C) 2013 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\CMS\Form\Field;
defined('JPATH_PLATFORM') or die;
use Joomla\CMS\Form\FormHelper;
FormHelper::loadFieldClass('list');
/**
* Field to load a list of posible item count limits
*
* @since 3.2
*/
class LimitboxField extends \JFormFieldList
{
/**
* The form field type.
*
* @var string
* @since 3.2
*/
public $type = 'Limitbox';
/**
* Cached array of the category items.
*
* @var array
* @since 3.2
*/
protected static $options = array();
/**
* Default options
*
* @var array
*/
protected $defaultLimits = array(5, 10, 15, 20, 25, 30, 50, 100, 200, 500);
/**
* Method to get the options to populate to populate list
*
* @return array The field option objects.
*
* @since 3.2
*/
protected function getOptions()
{
// Accepted modifiers
$hash = md5($this->element->asXML());
if (!isset(static::$options[$hash]))
{
static::$options[$hash] = parent::getOptions();
$options = array();
$limits = $this->defaultLimits;
// Limits manually specified
if (isset($this->element['limits']))
{
$limits = explode(',', $this->element['limits']);
}
// User wants to add custom limits
if (isset($this->element['append']))
{
$limits = array_unique(array_merge($limits, explode(',', $this->element['append'])));
}
// User wants to remove some default limits
if (isset($this->element['remove']))
{
$limits = array_diff($limits, explode(',', $this->element['remove']));
}
// Order the options
asort($limits);
// Add an option to show all?
$showAll = isset($this->element['showall']) ? (string) $this->element['showall'] === 'true' : true;
if ($showAll)
{
$limits[] = 0;
}
if (!empty($limits))
{
foreach ($limits as $value)
{
$options[] = (object) array(
'value' => $value,
'text' => ($value != 0) ? \JText::_('J' . $value) : \JText::_('JALL'),
);
}
static::$options[$hash] = array_merge(static::$options[$hash], $options);
}
}
return static::$options[$hash];
}
}
Field/MediaField.php 0000644 00000014205 15234515367 0010300 0 ustar 00 <?php
/**
* Joomla! Content Management System
*
* @copyright (C) 2009 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\CMS\Form\Field;
defined('JPATH_PLATFORM') or die;
use Joomla\CMS\Component\ComponentHelper;
use Joomla\CMS\Form\FormField;
/**
* Provides a modal media selector including upload mechanism
*
* @since 1.6
*/
class MediaField extends FormField
{
/**
* The form field type.
*
* @var string
* @since 1.6
*/
protected $type = 'Media';
/**
* The authorField.
*
* @var string
* @since 3.2
*/
protected $authorField;
/**
* The asset.
*
* @var string
* @since 3.2
*/
protected $asset;
/**
* The link.
*
* @var string
* @since 3.2
*/
protected $link;
/**
* Modal width.
*
* @var integer
* @since 3.4.5
*/
protected $width;
/**
* Modal height.
*
* @var integer
* @since 3.4.5
*/
protected $height;
/**
* The authorField.
*
* @var string
* @since 3.2
*/
protected $preview;
/**
* The preview.
*
* @var string
* @since 3.2
*/
protected $directory;
/**
* The previewWidth.
*
* @var int
* @since 3.2
*/
protected $previewWidth;
/**
* The previewHeight.
*
* @var int
* @since 3.2
*/
protected $previewHeight;
/**
* Layout to render
*
* @var string
* @since 3.5
*/
protected $layout = 'joomla.form.field.media';
/**
* Method to get certain otherwise inaccessible properties from the form field object.
*
* @param string $name The property name for which to get the value.
*
* @return mixed The property value or null.
*
* @since 3.2
*/
public function __get($name)
{
switch ($name)
{
case 'authorField':
case 'asset':
case 'link':
case 'width':
case 'height':
case 'preview':
case 'directory':
case 'previewWidth':
case 'previewHeight':
return $this->$name;
}
return parent::__get($name);
}
/**
* Method to set certain otherwise inaccessible properties of the form field object.
*
* @param string $name The property name for which to set the value.
* @param mixed $value The value of the property.
*
* @return void
*
* @since 3.2
*/
public function __set($name, $value)
{
switch ($name)
{
case 'authorField':
case 'asset':
case 'link':
case 'width':
case 'height':
case 'preview':
case 'directory':
$this->$name = (string) $value;
break;
case 'previewWidth':
case 'previewHeight':
$this->$name = (int) $value;
break;
default:
parent::__set($name, $value);
}
}
/**
* Method to attach a JForm object to the field.
*
* @param \SimpleXMLElement $element The SimpleXMLElement object representing the `<field>` tag for the form field object.
* @param mixed $value The form field value to validate.
* @param string $group The field name group control value. This acts as an array container for the field.
* For example if the field has name="foo" and the group value is set to "bar" then the
* full field name would end up being "bar[foo]".
*
* @return boolean True on success.
*
* @see FormField::setup()
* @since 3.2
*/
public function setup(\SimpleXMLElement $element, $value, $group = null)
{
$result = parent::setup($element, $value, $group);
if ($result === true)
{
$assetField = $this->element['asset_field'] ? (string) $this->element['asset_field'] : 'asset_id';
$this->authorField = $this->element['created_by_field'] ? (string) $this->element['created_by_field'] : 'created_by';
$this->asset = $this->form->getValue($assetField) ?: (string) $this->element['asset_id'];
$this->link = (string) $this->element['link'];
$this->width = isset($this->element['width']) ? (int) $this->element['width'] : 800;
$this->height = isset($this->element['height']) ? (int) $this->element['height'] : 500;
$this->preview = (string) $this->element['preview'];
$this->directory = (string) $this->element['directory'];
$this->previewWidth = isset($this->element['preview_width']) ? (int) $this->element['preview_width'] : 200;
$this->previewHeight = isset($this->element['preview_height']) ? (int) $this->element['preview_height'] : 200;
}
return $result;
}
/**
* Method to get the field input markup for a media selector.
* Use attributes to identify specific created_by and asset_id fields
*
* @return string The field input markup.
*
* @since 1.6
*/
protected function getInput()
{
if (empty($this->layout))
{
throw new \UnexpectedValueException(sprintf('%s has no layout assigned.', $this->name));
}
return $this->getRenderer($this->layout)->render($this->getLayoutData());
}
/**
* Get the data that is going to be passed to the layout
*
* @return array
*/
public function getLayoutData()
{
// Get the basic field data
$data = parent::getLayoutData();
$asset = $this->asset;
if ($asset === '')
{
$asset = \JFactory::getApplication()->input->get('option');
}
if ($this->value && file_exists(JPATH_ROOT . '/' . $this->value))
{
$this->folder = explode('/', $this->value);
$this->folder = array_diff_assoc($this->folder, explode('/', ComponentHelper::getParams('com_media')->get('image_path', 'images')));
array_pop($this->folder);
$this->folder = implode('/', $this->folder);
}
elseif (file_exists(JPATH_ROOT . '/' . ComponentHelper::getParams('com_media')->get('image_path', 'images') . '/' . $this->directory))
{
$this->folder = $this->directory;
}
else
{
$this->folder = '';
}
$extraData = array(
'asset' => $asset,
'authorField' => $this->authorField,
'authorId' => $this->form->getValue($this->authorField),
'folder' => $this->folder,
'link' => $this->link,
'preview' => $this->preview,
'previewHeight' => $this->previewHeight,
'previewWidth' => $this->previewWidth,
);
return array_merge($data, $extraData);
}
}
Field/MenuField.php 0000644 00000005566 15234515367 0010177 0 ustar 00 <?php
/**
* Joomla! Content Management System
*
* @copyright (C) 2010 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\CMS\Form\Field;
defined('JPATH_PLATFORM') or die;
use Joomla\CMS\Factory;
use Joomla\CMS\Form\FormHelper;
// Import the com_menus helper.
require_once realpath(JPATH_ADMINISTRATOR . '/components/com_menus/helpers/menus.php');
FormHelper::loadFieldClass('GroupedList');
/**
* Supports an HTML select list of menus
*
* @since 1.6
*/
class MenuField extends \JFormFieldGroupedList
{
/**
* The form field type.
*
* @var string
* @since 1.6
*/
public $type = 'Menu';
/**
* Method to get the field option groups.
*
* @return array The field option objects as a nested array in groups.
*
* @since 1.7.0
* @throws \UnexpectedValueException
*/
protected function getGroups()
{
$clientId = (string) $this->element['clientid'];
$accessType = (string) $this->element['accesstype'];
$showAll = (string) $this->element['showAll'] == 'true';
$db = Factory::getDbo();
$query = $db->getQuery(true)
->select($db->qn(array('id', 'menutype', 'title', 'client_id'), array('id', 'value', 'text', 'client_id')))
->from($db->quoteName('#__menu_types'))
->order('client_id, title');
if (strlen($clientId))
{
$query->where('client_id = ' . (int) $clientId);
}
$menus = $db->setQuery($query)->loadObjectList();
if ($accessType)
{
$user = Factory::getUser();
foreach ($menus as $key => $menu)
{
switch ($accessType)
{
case 'create':
case 'manage':
if (!$user->authorise('core.' . $accessType, 'com_menus.menu.' . (int) $menu->id))
{
unset($menus[$key]);
}
break;
// Editing a menu item is a bit tricky, we have to check the current menutype for core.edit and all others for core.create
case 'edit':
$check = $this->value == $menu->value ? 'edit' : 'create';
if (!$user->authorise('core.' . $check, 'com_menus.menu.' . (int) $menu->id))
{
unset($menus[$key]);
}
break;
}
}
}
$opts = array();
// Protected menutypes can be shown if requested
if ($clientId == 1 && $showAll)
{
$opts[] = (object) array(
'value' => 'main',
'text' => \JText::_('COM_MENUS_MENU_TYPE_PROTECTED_MAIN_LABEL'),
'client_id' => 1,
);
}
$options = array_merge($opts, $menus);
$groups = array();
if (strlen($clientId))
{
$groups[0] = $options;
}
else
{
foreach ($options as $option)
{
// If client id is not specified we group the items.
$label = ($option->client_id == 1 ? \JText::_('JADMINISTRATOR') : \JText::_('JSITE'));
$groups[$label][] = $option;
}
}
// Merge any additional options in the XML definition.
return array_merge(parent::getGroups(), $groups);
}
}
Field/MenuitemField.php 0000644 00000013622 15234515367 0011046 0 ustar 00 <?php
/**
* Joomla! Content Management System
*
* @copyright (C) 2010 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\CMS\Form\Field;
defined('JPATH_PLATFORM') or die;
use Joomla\CMS\Factory;
use Joomla\CMS\Form\FormHelper;
FormHelper::loadFieldClass('groupedlist');
// Import the com_menus helper.
require_once realpath(JPATH_ADMINISTRATOR . '/components/com_menus/helpers/menus.php');
/**
* Supports an HTML grouped select list of menu item grouped by menu
*
* @since 1.6
*/
class MenuitemField extends \JFormFieldGroupedList
{
/**
* The form field type.
*
* @var string
* @since 1.6
*/
public $type = 'MenuItem';
/**
* The menu type.
*
* @var string
* @since 3.2
*/
protected $menuType;
/**
* The client id.
*
* @var string
* @since 3.2
*/
protected $clientId;
/**
* The language.
*
* @var array
* @since 3.2
*/
protected $language;
/**
* The published status.
*
* @var array
* @since 3.2
*/
protected $published;
/**
* The disabled status.
*
* @var array
* @since 3.2
*/
protected $disable;
/**
* Method to get certain otherwise inaccessible properties from the form field object.
*
* @param string $name The property name for which to get the value.
*
* @return mixed The property value or null.
*
* @since 3.2
*/
public function __get($name)
{
switch ($name)
{
case 'menuType':
case 'clientId':
case 'language':
case 'published':
case 'disable':
return $this->$name;
}
return parent::__get($name);
}
/**
* Method to set certain otherwise inaccessible properties of the form field object.
*
* @param string $name The property name for which to set the value.
* @param mixed $value The value of the property.
*
* @return void
*
* @since 3.2
*/
public function __set($name, $value)
{
switch ($name)
{
case 'menuType':
$this->menuType = (string) $value;
break;
case 'clientId':
$this->clientId = (int) $value;
break;
case 'language':
case 'published':
case 'disable':
$value = (string) $value;
$this->$name = $value ? explode(',', $value) : array();
break;
default:
parent::__set($name, $value);
}
}
/**
* Method to attach a JForm object to the field.
*
* @param \SimpleXMLElement $element The SimpleXMLElement object representing the `<field>` tag for the form field object.
* @param mixed $value The form field value to validate.
* @param string $group The field name group control value. This acts as an array container for the field.
* For example if the field has name="foo" and the group value is set to "bar" then the
* full field name would end up being "bar[foo]".
*
* @return boolean True on success.
*
* @see FormField::setup()
* @since 3.2
*/
public function setup(\SimpleXMLElement $element, $value, $group = null)
{
$result = parent::setup($element, $value, $group);
if ($result === true)
{
$this->menuType = (string) $this->element['menu_type'];
$this->clientId = (int) $this->element['client_id'];
$this->published = $this->element['published'] ? explode(',', (string) $this->element['published']) : array();
$this->disable = $this->element['disable'] ? explode(',', (string) $this->element['disable']) : array();
$this->language = $this->element['language'] ? explode(',', (string) $this->element['language']) : array();
}
return $result;
}
/**
* Method to get the field option groups.
*
* @return array The field option objects as a nested array in groups.
*
* @since 1.6
*/
protected function getGroups()
{
$groups = array();
$menuType = $this->menuType;
// Get the menu items.
$items = \MenusHelper::getMenuLinks($menuType, 0, 0, $this->published, $this->language, $this->clientId);
// Build group for a specific menu type.
if ($menuType)
{
// If the menutype is empty, group the items by menutype.
$db = Factory::getDbo();
$query = $db->getQuery(true)
->select($db->quoteName('title'))
->from($db->quoteName('#__menu_types'))
->where($db->quoteName('menutype') . ' = ' . $db->quote($menuType));
$db->setQuery($query);
try
{
$menuTitle = $db->loadResult();
}
catch (\RuntimeException $e)
{
$menuTitle = $menuType;
}
// Initialize the group.
$groups[$menuTitle] = array();
// Build the options array.
foreach ($items as $link)
{
$levelPrefix = str_repeat('- ', max(0, $link->level - 1));
// Displays language code if not set to All
if ($link->language !== '*')
{
$lang = ' (' . $link->language . ')';
}
else
{
$lang = '';
}
$groups[$menuTitle][] = \JHtml::_('select.option',
$link->value, $levelPrefix . $link->text . $lang,
'value',
'text',
in_array($link->type, $this->disable)
);
}
}
// Build groups for all menu types.
else
{
// Build the groups arrays.
foreach ($items as $menu)
{
// Initialize the group.
$groups[$menu->title] = array();
// Build the options array.
foreach ($menu->links as $link)
{
$levelPrefix = str_repeat('- ', max(0, $link->level - 1));
// Displays language code if not set to All
if ($link->language !== '*')
{
$lang = ' (' . $link->language . ')';
}
else
{
$lang = '';
}
$groups[$menu->title][] = \JHtml::_('select.option',
$link->value, $levelPrefix . $link->text . $lang,
'value',
'text',
in_array($link->type, $this->disable)
);
}
}
}
// Merge any additional groups in the XML definition.
$groups = array_merge(parent::getGroups(), $groups);
return $groups;
}
}
Field/ModuleorderField.php 0000644 00000006442 15234515367 0011546 0 ustar 00 <?php
/**
* Joomla! Content Management System
*
* @copyright (C) 2009 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\CMS\Form\Field;
defined('JPATH_PLATFORM') or die;
use Joomla\CMS\Form\FormField;
use Joomla\CMS\Session\Session;
/**
* Module Order field.
*
* @since 1.6
*/
class ModuleorderField extends FormField
{
/**
* The form field type.
*
* @var string
* @since 1.6
*/
protected $type = 'ModuleOrder';
/**
* Name of the layout being used to render the field
*
* @var string
* @since 3.6.3
*/
protected $layout = 'joomla.form.field.moduleorder';
/**
* Method to get certain otherwise inaccessible properties from the form field object.
*
* @param string $name The property name for which to get the value.
*
* @return mixed The property value or null.
*
* @since 3.6.3
*/
public function __get($name)
{
switch ($name)
{
case 'linked':
return $this->$name;
}
return parent::__get($name);
}
/**
* Method to set certain otherwise inaccessible properties of the form field object.
*
* @param string $name The property name for which to set the value.
* @param mixed $value The value of the property.
*
* @return void
*
* @since 3.6.3
*/
public function __set($name, $value)
{
switch ($name)
{
case 'linked':
$this->$name = (string) $value;
break;
default:
parent::__set($name, $value);
}
}
/**
* Method to attach a JForm object to the field.
*
* @param \SimpleXMLElement $element The SimpleXMLElement object representing the `<field>` tag for the form field object.
* @param mixed $value The form field value to validate.
* @param string $group The field name group control value. This acts as an array container for the field.
* For example if the field has name="foo" and the group value is set to "bar" then the
* full field name would end up being "bar[foo]".
*
* @return boolean True on success.
*
* @see FormField::setup()
* @since 3.6.3
*/
public function setup(\SimpleXMLElement $element, $value, $group = null)
{
$return = parent::setup($element, $value, $group);
if ($return)
{
$this->linked = isset($this->element['linked']) ? (int) $this->element['linked'] : 'position';
}
return $return;
}
/**
* Method to get the field input markup for the moduleorder field.
*
* @return string The field input markup.
*
* @since 1.6
*/
protected function getInput()
{
return $this->getRenderer($this->layout)->render($this->getLayoutData());
}
/**
* Method to get the data to be passed to the layout for rendering.
*
* @return array
*
* @since 3.6.3
*/
protected function getLayoutData()
{
$data = parent::getLayoutData();
$extraData = array(
'ordering' => $this->form->getValue('ordering'),
'clientId' => $this->form->getValue('client_id'),
'moduleId' => $this->form->getValue('id'),
'name' => $this->name,
'token' => Session::getFormToken() . '=1',
'element' => $this->form->getName() . '_' . $this->linked
);
return array_merge($data, $extraData);
}
}
Field/ModulepositionField.php 0000644 00000010075 15234515367 0012274 0 ustar 00 <?php
/**
* Joomla! Content Management System
*
* @copyright (C) 2009 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\CMS\Form\Field;
defined('JPATH_PLATFORM') or die;
use Joomla\CMS\Application\ApplicationHelper;
use Joomla\CMS\Factory;
use Joomla\CMS\Form\Form;
use Joomla\CMS\Form\FormHelper;
FormHelper::loadFieldClass('text');
/**
* Module Position field.
*
* @since 1.6
*/
class ModulepositionField extends \JFormFieldText
{
/**
* The form field type.
*
* @var string
* @since 1.6
*/
protected $type = 'ModulePosition';
/**
* The client ID.
*
* @var integer
* @since 3.2
*/
protected $clientId;
/**
* Method to get certain otherwise inaccessible properties from the form field object.
*
* @param string $name The property name for which to get the value.
*
* @return mixed The property value or null.
*
* @since 3.2
*/
public function __get($name)
{
switch ($name)
{
case 'clientId':
return $this->clientId;
}
return parent::__get($name);
}
/**
* Method to set certain otherwise inaccessible properties of the form field object.
*
* @param string $name The property name for which to set the value.
* @param mixed $value The value of the property.
*
* @return void
*
* @since 3.2
*/
public function __set($name, $value)
{
switch ($name)
{
case 'clientId':
$this->clientId = (string) $value;
break;
default:
parent::__set($name, $value);
}
}
/**
* Method to attach a JForm object to the field.
*
* @param \SimpleXMLElement $element The SimpleXMLElement object representing the `<field>` tag for the form field object.
* @param mixed $value The form field value to validate.
* @param string $group The field name group control value. This acts as an array container for the field.
* For example if the field has name="foo" and the group value is set to "bar" then the
* full field name would end up being "bar[foo]".
*
* @return boolean True on success.
*
* @see FormField::setup()
* @since 3.2
*/
public function setup(\SimpleXMLElement $element, $value, $group = null)
{
$result = parent::setup($element, $value, $group);
if ($result === true)
{
// Get the client id.
$clientId = $this->element['client_id'];
if (!isset($clientId))
{
$clientName = $this->element['client'];
if (isset($clientName))
{
$client = ApplicationHelper::getClientInfo($clientName, true);
$clientId = $client->id;
}
}
if (!isset($clientId) && $this->form instanceof Form)
{
$clientId = $this->form->getValue('client_id');
}
$this->clientId = (int) $clientId;
}
return $result;
}
/**
* Method to get the field input markup.
*
* @return string The field input markup.
*
* @since 1.6
*/
protected function getInput()
{
// Load the modal behavior script.
\JHtml::_('behavior.modal', 'a.modal');
// Build the script.
$script = array();
$script[] = ' function jSelectPosition_' . $this->id . '(name) {';
$script[] = ' document.getElementById("' . $this->id . '").value = name;';
$script[] = ' jModalClose();';
$script[] = ' }';
// Add the script to the document head.
Factory::getDocument()->addScriptDeclaration(implode("\n", $script));
// Setup variables for display.
$html = array();
$link = 'index.php?option=com_modules&view=positions&layout=modal&tmpl=component&function=jSelectPosition_' . $this->id
. '&client_id=' . $this->clientId;
// The current user display field.
$html[] = '<div class="input-append">';
$html[] = parent::getInput()
. '<a class="btn modal" title="' . \JText::_('COM_MODULES_CHANGE_POSITION_TITLE') . '" href="' . $link
. '" rel="{handler: \'iframe\', size: {x: 800, y: 450}}">'
. \JText::_('COM_MODULES_CHANGE_POSITION_BUTTON') . '</a>';
$html[] = '</div>';
return implode("\n", $html);
}
}
Field/ModuletagField.php 0000644 00000002031 15234515367 0011174 0 ustar 00 <?php
/**
* Joomla! Content Management System
*
* @copyright (C) 2012 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\CMS\Form\Field;
defined('JPATH_PLATFORM') or die;
use Joomla\CMS\Form\FormHelper;
FormHelper::loadFieldClass('list');
/**
* Module Tag field.
*
* @since 3.0
*/
class ModuletagField extends \JFormFieldList
{
/**
* The form field type.
*
* @var string
* @since 3.0
*/
protected $type = 'ModuleTag';
/**
* Method to get the field options.
*
* @return array The field option objects.
*
* @since 3.0
*/
protected function getOptions()
{
$options = array();
$tags = array('address', 'article', 'aside', 'details', 'div', 'footer', 'header', 'main', 'nav', 'section', 'summary');
// Create one new option object for each tag
foreach ($tags as $tag)
{
$tmp = \JHtml::_('select.option', $tag, $tag);
$options[] = $tmp;
}
reset($options);
return $options;
}
}
Field/OrderingField.php 0000644 00000011260 15234515367 0011030 0 ustar 00 <?php
/**
* Joomla! Content Management System
*
* @copyright (C) 2013 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\CMS\Form\Field;
defined('JPATH_PLATFORM') or die;
use Joomla\CMS\Factory;
use Joomla\CMS\Form\FormField;
use Joomla\CMS\UCM\UCMType;
/**
* Ordering field.
*
* @since 3.2
*/
class OrderingField extends FormField
{
/**
* The form field type.
*
* @var string
* @since 3.2
*/
protected $type = 'Ordering';
/**
* The form field content type.
*
* @var string
* @since 3.2
*/
protected $contentType;
/**
* Method to get certain otherwise inaccessible properties from the form field object.
*
* @param string $name The property name for which to get the value.
*
* @return mixed The property value or null.
*
* @since 3.2
*/
public function __get($name)
{
switch ($name)
{
case 'contentType':
return $this->contentType;
}
return parent::__get($name);
}
/**
* Method to set certain otherwise inaccessible properties of the form field object.
*
* @param string $name The property name for which to set the value.
* @param mixed $value The value of the property.
*
* @return void
*
* @since 3.2
*/
public function __set($name, $value)
{
switch ($name)
{
case 'contentType':
$this->contentType = (string) $value;
break;
default:
parent::__set($name, $value);
}
}
/**
* Method to attach a JForm object to the field.
*
* @param \SimpleXMLElement $element The SimpleXMLElement object representing the `<field>` tag for the form field object.
* @param mixed $value The form field value to validate.
* @param string $group The field name group control value. This acts as an array container for the field.
* For example if the field has name="foo" and the group value is set to "bar" then the
* full field name would end up being "bar[foo]".
*
* @return boolean True on success.
*
* @see FormField::setup()
* @since 3.2
*/
public function setup(\SimpleXMLElement $element, $value, $group = null)
{
$result = parent::setup($element, $value, $group);
if ($result === true)
{
$this->contentType = (string) $this->element['content_type'];
}
return $result;
}
/**
* Method to get the field input markup.
*
* @return string The field input markup.
*
* @since 3.2
*/
protected function getInput()
{
$html = array();
$attr = '';
// Initialize some field attributes.
$attr .= !empty($this->class) ? ' class="' . $this->class . '"' : '';
$attr .= $this->disabled ? ' disabled' : '';
$attr .= !empty($this->size) ? ' size="' . $this->size . '"' : '';
// Initialize JavaScript field attributes.
$attr .= !empty($this->onchange) ? ' onchange="' . $this->onchange . '"' : '';
$itemId = (int) $this->getItemId();
$query = $this->getQuery();
// Create a read-only list (no name) with a hidden input to store the value.
if ($this->readonly)
{
$html[] = \JHtml::_('list.ordering', '', $query, trim($attr), $this->value, $itemId ? 0 : 1);
$html[] = '<input type="hidden" name="' . $this->name . '" value="' . $this->value . '"/>';
}
else
{
// Create a regular list.
$html[] = \JHtml::_('list.ordering', $this->name, $query, trim($attr), $this->value, $itemId ? 0 : 1);
}
return implode($html);
}
/**
* Builds the query for the ordering list.
*
* @return \JDatabaseQuery The query for the ordering form field
*
* @since 3.2
*/
protected function getQuery()
{
$categoryId = (int) $this->form->getValue('catid');
$ucmType = new UCMType;
$ucmRow = $ucmType->getType($ucmType->getTypeId($this->contentType));
$ucmMapCommon = json_decode($ucmRow->field_mappings)->common;
if (is_object($ucmMapCommon))
{
$ordering = $ucmMapCommon->core_ordering;
$title = $ucmMapCommon->core_title;
}
elseif (is_array($ucmMapCommon))
{
$ordering = $ucmMapCommon[0]->core_ordering;
$title = $ucmMapCommon[0]->core_title;
}
$db = Factory::getDbo();
$query = $db->getQuery(true);
$query->select(array($db->quoteName($ordering, 'value'), $db->quoteName($title, 'text')))
->from($db->quoteName(json_decode($ucmRow->table)->special->dbtable))
->where($db->quoteName('catid') . ' = ' . (int) $categoryId)
->order('ordering');
return $query;
}
/**
* Retrieves the current Item's Id.
*
* @return integer The current item ID
*
* @since 3.2
*/
protected function getItemId()
{
return (int) $this->form->getValue('id');
}
}
Field/PluginstatusField.php 0000644 00000001336 15234515367 0011764 0 ustar 00 <?php
/**
* Joomla! Content Management System
*
* @copyright (C) 2017 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\CMS\Form\Field;
defined('JPATH_PLATFORM') or die;
use Joomla\CMS\Form\FormHelper;
FormHelper::loadFieldClass('predefinedlist');
/**
* Plugin Status field.
*
* @since 3.5
*/
class PluginstatusField extends \JFormFieldPredefinedList
{
/**
* The form field type.
*
* @var string
* @since 3.5
*/
public $type = 'Plugin_Status';
/**
* Available statuses
*
* @var array
* @since 3.5
*/
protected $predefinedOptions = array(
'0' => 'JDISABLED',
'1' => 'JENABLED',
);
}
Field/RedirectStatusField.php 0000644 00000001451 15234515367 0012225 0 ustar 00 <?php
/**
* Joomla! Content Management System
*
* @copyright (C) 2017 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\CMS\Form\Field;
defined('JPATH_PLATFORM') or die;
use Joomla\CMS\Form\FormHelper;
FormHelper::loadFieldClass('predefinedlist');
/**
* Redirect Status field.
*
* @since 3.8.0
*/
class RedirectStatusField extends \JFormFieldPredefinedList
{
/**
* The form field type.
*
* @var string
* @since 3.8.0
*/
public $type = 'Redirect_Status';
/**
* Available statuses
*
* @var array
* @since 3.8.0
*/
protected $predefinedOptions = array(
'-2' => 'JTRASHED',
'0' => 'JDISABLED',
'1' => 'JENABLED',
'2' => 'JARCHIVED',
'*' => 'JALL',
);
}
Field/RegistrationdaterangeField.php 0000644 00000002743 15234515367 0013612 0 ustar 00 <?php
/**
* Joomla! Content Management System
*
* @copyright (C) 2013 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\CMS\Form\Field;
defined('JPATH_PLATFORM') or die;
use Joomla\CMS\Factory;
use Joomla\CMS\Form\Form;
use Joomla\CMS\Form\FormHelper;
FormHelper::loadFieldClass('predefinedlist');
/**
* Registration Date Range field.
*
* @since 3.2
*/
class RegistrationdaterangeField extends \JFormFieldPredefinedList
{
/**
* The form field type.
*
* @var string
* @since 3.2
*/
protected $type = 'RegistrationDateRange';
/**
* Available options
*
* @var array
* @since 3.2
*/
protected $predefinedOptions = array(
'today' => 'COM_USERS_OPTION_RANGE_TODAY',
'past_week' => 'COM_USERS_OPTION_RANGE_PAST_WEEK',
'past_1month' => 'COM_USERS_OPTION_RANGE_PAST_1MONTH',
'past_3month' => 'COM_USERS_OPTION_RANGE_PAST_3MONTH',
'past_6month' => 'COM_USERS_OPTION_RANGE_PAST_6MONTH',
'past_year' => 'COM_USERS_OPTION_RANGE_PAST_YEAR',
'post_year' => 'COM_USERS_OPTION_RANGE_POST_YEAR',
);
/**
* Method to instantiate the form field object.
*
* @param Form $form The form to attach to the form field object.
*
* @since 1.7.0
*/
public function __construct($form = null)
{
parent::__construct($form);
// Load the required language
$lang = Factory::getLanguage();
$lang->load('com_users', JPATH_ADMINISTRATOR);
}
}
Field/StatusField.php 0000644 00000001437 15234515367 0010547 0 ustar 00 <?php
/**
* Joomla! Content Management System
*
* @copyright (C) 2013 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\CMS\Form\Field;
defined('JPATH_PLATFORM') or die;
use Joomla\CMS\Form\FormHelper;
FormHelper::loadFieldClass('predefinedlist');
/**
* Form Field to load a list of states
*
* @since 3.2
*/
class StatusField extends \JFormFieldPredefinedList
{
/**
* The form field type.
*
* @var string
* @since 3.2
*/
public $type = 'Status';
/**
* Available statuses
*
* @var array
* @since 3.2
*/
protected $predefinedOptions = array(
-2 => 'JTRASHED',
0 => 'JUNPUBLISHED',
1 => 'JPUBLISHED',
2 => 'JARCHIVED',
'*' => 'JALL',
);
}
Field/TagField.php 0000644 00000012754 15234515367 0010003 0 ustar 00 <?php
/**
* Joomla! Content Management System
*
* @copyright (C) 2013 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\CMS\Form\Field;
defined('JPATH_PLATFORM') or die;
use Joomla\CMS\Component\ComponentHelper;
use Joomla\CMS\Factory;
use Joomla\CMS\Form\FormHelper;
use Joomla\CMS\Helper\TagsHelper;
use Joomla\CMS\Language\Multilanguage;
use Joomla\Utilities\ArrayHelper;
FormHelper::loadFieldClass('list');
/**
* List of Tags field.
*
* @since 3.1
*/
class TagField extends \JFormFieldList
{
/**
* A flexible tag list that respects access controls
*
* @var string
* @since 3.1
*/
public $type = 'Tag';
/**
* Flag to work with nested tag field
*
* @var boolean
* @since 3.1
*/
public $isNested = null;
/**
* com_tags parameters
*
* @var \Joomla\Registry\Registry
* @since 3.1
*/
protected $comParams = null;
/**
* Constructor
*
* @since 3.1
*/
public function __construct()
{
parent::__construct();
// Load com_tags config
$this->comParams = ComponentHelper::getParams('com_tags');
}
/**
* Method to get the field input for a tag field.
*
* @return string The field input.
*
* @since 3.1
*/
protected function getInput()
{
// AJAX mode requires ajax-chosen
if (!$this->isNested())
{
// Get the field id
$id = isset($this->element['id']) ? $this->element['id'] : null;
$cssId = '#' . $this->getId($id, $this->element['name']);
// Load the ajax-chosen customised field
\JHtml::_('tag.ajaxfield', $cssId, $this->allowCustom());
}
if (!is_array($this->value) && !empty($this->value))
{
if ($this->value instanceof TagsHelper)
{
if (empty($this->value->tags))
{
$this->value = array();
}
else
{
$this->value = $this->value->tags;
}
}
// String in format 2,5,4
if (is_string($this->value))
{
$this->value = explode(',', $this->value);
}
}
return parent::getInput();
}
/**
* Method to get a list of tags
*
* @return array The field option objects.
*
* @since 3.1
*/
protected function getOptions()
{
$published = (string) $this->element['published'] ?: array(0, 1);
$app = Factory::getApplication();
$tag = $app->getLanguage()->getTag();
$db = Factory::getDbo();
$query = $db->getQuery(true)
->select('a.id AS value, a.path, a.title AS text, a.level, a.published, a.lft')
->from($db->qn('#__tags') . ' AS a');
// Limit Options in multilanguage
if ($app->isClient('site') && Multilanguage::isEnabled())
{
$lang = ComponentHelper::getParams('com_tags')->get('tag_list_language_filter');
if ($lang == 'current_language')
{
$query->where('a.language in (' . $db->quote($tag) . ',' . $db->quote('*') . ')');
}
}
// Filter language
elseif (!empty($this->element['language']))
{
if (strpos($this->element['language'], ',') !== false)
{
$language = implode(',', $db->quote(explode(',', $this->element['language'])));
}
else
{
$language = $db->quote($this->element['language']);
}
$query->where($db->quoteName('a.language') . ' IN (' . $language . ')');
}
$query->where($db->qn('a.lft') . ' > 0');
// Filter on the published state
if (is_numeric($published))
{
$query->where('a.published = ' . (int) $published);
}
elseif (is_array($published))
{
$published = ArrayHelper::toInteger($published);
$query->where('a.published IN (' . implode(',', $published) . ')');
}
$query->order('a.lft ASC');
// Get the options.
$db->setQuery($query);
try
{
$options = $db->loadObjectList();
}
catch (\RuntimeException $e)
{
return array();
}
// Block the possibility to set a tag as it own parent
if ($this->form->getName() === 'com_tags.tag')
{
$id = (int) $this->form->getValue('id', 0);
foreach ($options as $option)
{
if ($option->value == $id)
{
$option->disable = true;
}
}
}
// Merge any additional options in the XML definition.
$options = array_merge(parent::getOptions(), $options);
// Prepare nested data
if ($this->isNested())
{
$this->prepareOptionsNested($options);
}
else
{
$options = TagsHelper::convertPathsToNames($options);
}
return $options;
}
/**
* Add "-" before nested tags, depending on level
*
* @param array &$options Array of tags
*
* @return array The field option objects.
*
* @since 3.1
*/
protected function prepareOptionsNested(&$options)
{
if ($options)
{
foreach ($options as &$option)
{
$repeat = (isset($option->level) && $option->level - 1 >= 0) ? $option->level - 1 : 0;
$option->text = str_repeat('- ', $repeat) . $option->text;
}
}
return $options;
}
/**
* Determine if the field has to be tagnested
*
* @return boolean
*
* @since 3.1
*/
public function isNested()
{
if ($this->isNested === null)
{
// If mode="nested" || ( mode not set & config = nested )
if (isset($this->element['mode']) && (string) $this->element['mode'] === 'nested'
|| !isset($this->element['mode']) && $this->comParams->get('tag_field_ajax_mode', 1) == 0)
{
$this->isNested = true;
}
}
return $this->isNested;
}
/**
* Determines if the field allows or denies custom values
*
* @return boolean
*/
public function allowCustom()
{
if (isset($this->element['custom']) && (string) $this->element['custom'] === 'deny')
{
return false;
}
return true;
}
}
Field/TemplatestyleField.php 0000644 00000011222 15234515367 0012111 0 ustar 00 <?php
/**
* Joomla! Content Management System
*
* @copyright (C) 2009 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\CMS\Form\Field;
defined('JPATH_PLATFORM') or die;
use Joomla\CMS\Application\ApplicationHelper;
use Joomla\CMS\Factory;
use Joomla\CMS\Form\FormHelper;
FormHelper::loadFieldClass('groupedlist');
/**
* Supports a select grouped list of template styles
*
* @since 1.6
*/
class TemplatestyleField extends \JFormFieldGroupedList
{
/**
* The form field type.
*
* @var string
* @since 1.6
*/
public $type = 'TemplateStyle';
/**
* The client name.
*
* @var mixed
* @since 3.2
*/
protected $clientName;
/**
* The template.
*
* @var mixed
* @since 3.2
*/
protected $template;
/**
* Method to get certain otherwise inaccessible properties from the form field object.
*
* @param string $name The property name for which to get the value.
*
* @return mixed The property value or null.
*
* @since 3.2
*/
public function __get($name)
{
switch ($name)
{
case 'clientName':
case 'template':
return $this->$name;
}
return parent::__get($name);
}
/**
* Method to set certain otherwise inaccessible properties of the form field object.
*
* @param string $name The property name for which to set the value.
* @param mixed $value The value of the property.
*
* @return void
*
* @since 3.2
*/
public function __set($name, $value)
{
switch ($name)
{
case 'clientName':
case 'template':
$this->$name = (string) $value;
break;
default:
parent::__set($name, $value);
}
}
/**
* Method to attach a JForm object to the field.
*
* @param \SimpleXMLElement $element The SimpleXMLElement object representing the `<field>` tag for the form field object.
* @param mixed $value The form field value to validate.
* @param string $group The field name group control value. This acts as an array container for the field.
* For example if the field has name="foo" and the group value is set to "bar" then the
* full field name would end up being "bar[foo]".
*
* @return boolean True on success.
*
* @see FormField::setup()
* @since 3.2
*/
public function setup(\SimpleXMLElement $element, $value, $group = null)
{
$result = parent::setup($element, $value, $group);
if ($result === true)
{
// Get the clientName template.
$this->clientName = $this->element['client'] ? (string) $this->element['client'] : 'site';
$this->template = (string) $this->element['template'];
}
return $result;
}
/**
* Method to get the list of template style options grouped by template.
* Use the client attribute to specify a specific client.
* Use the template attribute to specify a specific template
*
* @return array The field option objects as a nested array in groups.
*
* @since 1.6
*/
protected function getGroups()
{
$groups = array();
$lang = Factory::getLanguage();
// Get the client and client_id.
$client = ApplicationHelper::getClientInfo($this->clientName, true);
// Get the template.
$template = $this->template;
// Get the database object and a new query object.
$db = Factory::getDbo();
$query = $db->getQuery(true);
// Build the query.
$query->select('s.id, s.title, e.name as name, s.template')
->from('#__template_styles as s')
->where('s.client_id = ' . (int) $client->id)
->order('template')
->order('title');
if ($template)
{
$query->where('s.template = ' . $db->quote($template));
}
$query->join('LEFT', '#__extensions as e on e.element=s.template')
->where('e.enabled = 1')
->where($db->quoteName('e.type') . ' = ' . $db->quote('template'));
// Set the query and load the styles.
$db->setQuery($query);
$styles = $db->loadObjectList();
// Build the grouped list array.
if ($styles)
{
foreach ($styles as $style)
{
$template = $style->template;
$lang->load('tpl_' . $template . '.sys', $client->path, null, false, true)
|| $lang->load('tpl_' . $template . '.sys', $client->path . '/templates/' . $template, null, false, true);
$name = \JText::_($style->name);
// Initialize the group if necessary.
if (!isset($groups[$name]))
{
$groups[$name] = array();
}
$groups[$name][] = \JHtml::_('select.option', $style->id, $style->title);
}
}
// Merge any additional groups in the XML definition.
$groups = array_merge(parent::getGroups(), $groups);
return $groups;
}
}
Field/UserField.php 0000644 00000007535 15234515367 0010207 0 ustar 00 <?php
/**
* Joomla! Content Management System
*
* @copyright (C) 2009 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\CMS\Form\Field;
defined('JPATH_PLATFORM') or die;
use Joomla\CMS\Factory;
use Joomla\CMS\Form\FormField;
use Joomla\CMS\User\User;
/**
* Field to select a user ID from a modal list.
*
* @since 1.6
*/
class UserField extends FormField
{
/**
* The form field type.
*
* @var string
* @since 1.6
*/
public $type = 'User';
/**
* Filtering groups
*
* @var array
* @since 3.5
*/
protected $groups = null;
/**
* Users to exclude from the list of users
*
* @var array
* @since 3.5
*/
protected $excluded = null;
/**
* Layout to render
*
* @var string
* @since 3.5
*/
protected $layout = 'joomla.form.field.user';
/**
* Method to attach a JForm object to the field.
*
* @param \SimpleXMLElement $element The SimpleXMLElement object representing the `<field>` tag for the form field object.
* @param mixed $value The form field value to validate.
* @param string $group The field name group control value. This acts as an array container for the field.
* For example if the field has name="foo" and the group value is set to "bar" then the
* full field name would end up being "bar[foo]".
*
* @return boolean True on success.
*
* @since 3.7.0
*
* @see JFormField::setup()
*/
public function setup(\SimpleXMLElement $element, $value, $group = null)
{
$return = parent::setup($element, $value, $group);
// If user can't access com_users the field should be readonly.
if ($return && !$this->readonly)
{
$this->readonly = !Factory::getUser()->authorise('core.manage', 'com_users');
}
return $return;
}
/**
* Method to get the user field input markup.
*
* @return string The field input markup.
*
* @since 1.6
*/
protected function getInput()
{
if (empty($this->layout))
{
throw new \UnexpectedValueException(sprintf('%s has no layout assigned.', $this->name));
}
return $this->getRenderer($this->layout)->render($this->getLayoutData());
}
/**
* Get the data that is going to be passed to the layout
*
* @return array
*
* @since 3.5
*/
public function getLayoutData()
{
// Get the basic field data
$data = parent::getLayoutData();
// Initialize value
$name = \JText::_('JLIB_FORM_SELECT_USER');
if (is_numeric($this->value))
{
$name = User::getInstance($this->value)->name;
}
// Handle the special case for "current".
elseif (strtoupper($this->value) === 'CURRENT')
{
// 'CURRENT' is not a reasonable value to be placed in the html
$current = Factory::getUser();
$this->value = $current->id;
$data['value'] = $this->value;
$name = $current->name;
}
// User lookup went wrong, we assign the value instead.
if ($name === null && $this->value)
{
$name = $this->value;
}
$extraData = array(
'userName' => $name,
'groups' => $this->getGroups(),
'excluded' => $this->getExcluded(),
);
return array_merge($data, $extraData);
}
/**
* Method to get the filtering groups (null means no filtering)
*
* @return mixed Array of filtering groups or null.
*
* @since 1.6
*/
protected function getGroups()
{
if (isset($this->element['groups']))
{
return explode(',', $this->element['groups']);
}
return;
}
/**
* Method to get the users to exclude from the list of users
*
* @return mixed Array of users to exclude or null to to not exclude them
*
* @since 1.6
*/
protected function getExcluded()
{
if (isset($this->element['exclude']))
{
return explode(',', $this->element['exclude']);
}
return;
}
}
Field/UseractiveField.php 0000644 00000002247 15234515367 0011376 0 ustar 00 <?php
/**
* Joomla! Content Management System
*
* @copyright (C) 2013 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\CMS\Form\Field;
defined('JPATH_PLATFORM') or die;
use Joomla\CMS\Factory;
use Joomla\CMS\Form\Form;
use Joomla\CMS\Form\FormHelper;
FormHelper::loadFieldClass('predefinedlist');
/**
* Field to show a list of available user active statuses
*
* @since 3.2
*/
class UseractiveField extends \JFormFieldPredefinedList
{
/**
* The form field type.
*
* @var string
* @since 3.2
*/
protected $type = 'UserActive';
/**
* Available statuses
*
* @var array
* @since 3.2
*/
protected $predefinedOptions = array(
'0' => 'COM_USERS_ACTIVATED',
'1' => 'COM_USERS_UNACTIVATED',
);
/**
* Method to instantiate the form field object.
*
* @param Form $form The form to attach to the form field object.
*
* @since 1.7.0
*/
public function __construct($form = null)
{
parent::__construct($form);
// Load the required language
$lang = Factory::getLanguage();
$lang->load('com_users', JPATH_ADMINISTRATOR);
}
}
Field/UsergrouplistField.php 0000644 00000005347 15234515367 0012157 0 ustar 00 <?php
/**
* Joomla! Content Management System
*
* @copyright (C) 2013 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\CMS\Form\Field;
defined('JPATH_PLATFORM') or die;
use Joomla\CMS\Access\Access;
use Joomla\CMS\Factory;
use Joomla\CMS\Form\FormHelper;
use Joomla\CMS\Helper\UserGroupsHelper;
FormHelper::loadFieldClass('list');
/**
* Field to load a dropdown list of available user groups
*
* @since 3.2
*/
class UsergrouplistField extends \JFormFieldList
{
/**
* The form field type.
*
* @var string
* @since 3.2
*/
protected $type = 'UserGroupList';
/**
* Cached array of the category items.
*
* @var array
* @since 3.2
*/
protected static $options = array();
/**
* Method to attach a JForm object to the field.
*
* @param \SimpleXMLElement $element The SimpleXMLElement object representing the `<field>` tag for the form field object.
* @param mixed $value The form field value to validate.
* @param string $group The field name group control value. This acts as an array container for the field.
* For example if the field has name="foo" and the group value is set to "bar" then the
* full field name would end up being "bar[foo]".
*
* @return boolean True on success.
*
* @since 1.7.0
*/
public function setup(\SimpleXMLElement $element, $value, $group = null)
{
if (is_string($value) && strpos($value, ',') !== false)
{
$value = explode(',', $value);
}
return parent::setup($element, $value, $group);
}
/**
* Method to get the options to populate list
*
* @return array The field option objects.
*
* @since 3.2
*/
protected function getOptions()
{
$options = parent::getOptions();
$checkSuperUser = (int) $this->getAttribute('checksuperusergroup', 0);
// Cache user groups base on checksuperusergroup attribute value
if (!isset(static::$options[$checkSuperUser]))
{
$groups = UserGroupsHelper::getInstance()->getAll();
$isSuperUser = Factory::getUser()->authorise('core.admin');
$cacheOptions = array();
foreach ($groups as $group)
{
// Don't show super user groups to non super users.
if ($checkSuperUser && !$isSuperUser && Access::checkGroup($group->id, 'core.admin'))
{
continue;
}
$cacheOptions[] = (object) array(
'text' => str_repeat('- ', $group->level) . $group->title,
'value' => $group->id,
'level' => $group->level,
);
}
static::$options[$checkSuperUser] = $cacheOptions;
}
return array_merge($options, static::$options[$checkSuperUser]);
}
}
Field/UserstateField.php 0000644 00000001365 15234515367 0011243 0 ustar 00 <?php
/**
* Joomla! Content Management System
*
* @copyright (C) 2013 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\CMS\Form\Field;
defined('JPATH_PLATFORM') or die;
use Joomla\CMS\Form\FormHelper;
FormHelper::loadFieldClass('predefinedlist');
/**
* Field to load a list of available users statuses
*
* @since 3.2
*/
class UserstateField extends \JFormFieldPredefinedList
{
/**
* The form field type.
*
* @var string
* @since 3.2
*/
protected $type = 'UserState';
/**
* Available statuses
*
* @var array
* @since 3.2
*/
protected $predefinedOptions = array(
'0' => 'JENABLED',
'1' => 'JDISABLED',
);
}
Rule/BooleanRule.php 0000644 00000001341 15234515367 0010405 0 ustar 00 <?php
/**
* Joomla! Content Management System
*
* @copyright (C) 2009 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\CMS\Form\Rule;
defined('JPATH_PLATFORM') or die;
use Joomla\CMS\Form\FormRule;
/**
* Form Rule class for the Joomla Platform.
*
* @since 1.7.0
*/
class BooleanRule extends FormRule
{
/**
* The regular expression to use in testing a form field value.
*
* @var string
* @since 1.7.0
*/
protected $regex = '^(?:[01]|true|false)$';
/**
* The regular expression modifiers to use when testing a form field value.
*
* @var string
* @since 1.7.0
*/
protected $modifiers = 'i';
}
Rule/CalendarRule.php 0000644 00000003656 15234515367 0010552 0 ustar 00 <?php
/**
* Joomla! Content Management System
*
* @copyright (C) 2017 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\CMS\Form\Rule;
defined('JPATH_PLATFORM') or die;
use Joomla\CMS\Date\Date;
use Joomla\CMS\Form\Form;
use Joomla\CMS\Form\FormRule;
use Joomla\Registry\Registry;
/**
* Form Rule class for the Joomla Platform
*
* @since 3.7.0
*/
class CalendarRule extends FormRule
{
/**
* Method to test the calendar value for a valid parts.
*
* @param \SimpleXMLElement $element The SimpleXMLElement object representing the `<field>` tag for the form field object.
* @param mixed $value The form field value to validate.
* @param string $group The field name group control value. This acts as an array container for the field.
* For example if the field has name="foo" and the group value is set to "bar" then the
* full field name would end up being "bar[foo]".
* @param Registry $input An optional Registry object with the entire data set to validate against the entire form.
* @param Form $form The form object for which the field is being tested.
*
* @return boolean True if the value is valid, false otherwise.
*
* @since 3.7.0
*/
public function test(\SimpleXMLElement $element, $value, $group = null, Registry $input = null, Form $form = null)
{
// If the field is empty and not required, the field is valid.
$required = ((string) $element['required'] == 'true' || (string) $element['required'] == 'required');
if (!$required && empty($value))
{
return true;
}
if (strtolower($value) == 'now')
{
return true;
}
try
{
return \JFactory::getDate($value) instanceof Date;
}
catch (\Exception $e)
{
return false;
}
}
}
Rule/CaptchaRule.php 0000644 00000004145 15234515367 0010376 0 ustar 00 <?php
/**
* Joomla! Content Management System
*
* @copyright (C) 2017 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\CMS\Form\Rule;
defined('JPATH_PLATFORM') or die;
use Joomla\CMS\Captcha\Captcha;
use Joomla\CMS\Form\Form;
use Joomla\CMS\Form\FormRule;
use Joomla\Registry\Registry;
/**
* Form Rule class for the Joomla Framework.
*
* @since 2.5
*/
class CaptchaRule extends FormRule
{
/**
* Method to test if the Captcha is correct.
*
* @param \SimpleXMLElement $element The SimpleXMLElement object representing the `<field>` tag for the form field object.
* @param mixed $value The form field value to validate.
* @param string $group The field name group control value. This acts as an array container for the field.
* For example if the field has name="foo" and the group value is set to "bar" then the
* full field name would end up being "bar[foo]".
* @param Registry $input An optional Registry object with the entire data set to validate against the entire form.
* @param Form $form The form object for which the field is being tested.
*
* @return boolean True if the value is valid, false otherwise.
*
* @since 2.5
*/
public function test(\SimpleXMLElement $element, $value, $group = null, Registry $input = null, Form $form = null)
{
$app = \JFactory::getApplication();
$plugin = $app->get('captcha');
if ($app->isClient('site'))
{
$plugin = $app->getParams()->get('captcha', $plugin);
}
$namespace = $element['namespace'] ?: $form->getName();
// Use 0 for none
if ($plugin === 0 || $plugin === '0')
{
return true;
}
try
{
$captcha = Captcha::getInstance((string) $plugin, array('namespace' => (string) $namespace));
return $captcha->checkAnswer($value);
}
catch (\RuntimeException $e)
{
\JFactory::getApplication()->enqueueMessage($e->getMessage(), 'error');
}
return false;
}
}
Rule/ColorRule.php 0000644 00000004061 15234515367 0010106 0 ustar 00 <?php
/**
* Joomla! Content Management System
*
* @copyright (C) 2017 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\CMS\Form\Rule;
defined('JPATH_PLATFORM') or die;
use Joomla\CMS\Form\Form;
use Joomla\CMS\Form\FormRule;
use Joomla\Registry\Registry;
/**
* Form Rule class for the Joomla Platform.
*
* @since 1.7.0
*/
class ColorRule extends FormRule
{
/**
* Method to test for a valid color in hexadecimal.
*
* @param \SimpleXMLElement $element The SimpleXMLElement object representing the `<field>` tag for the form field object.
* @param mixed $value The form field value to validate.
* @param string $group The field name group control value. This acts as an array container for the field.
* For example if the field has name="foo" and the group value is set to "bar" then the
* full field name would end up being "bar[foo]".
* @param Registry $input An optional Registry object with the entire data set to validate against the entire form.
* @param Form $form The form object for which the field is being tested.
*
* @return boolean True if the value is valid, false otherwise.
*
* @since 1.7.0
*/
public function test(\SimpleXMLElement $element, $value, $group = null, Registry $input = null, Form $form = null)
{
$value = trim($value);
// If the field is empty and not required, the field is valid.
$required = ((string) $element['required'] == 'true' || (string) $element['required'] == 'required');
if (!$required && empty($value))
{
return true;
}
if ($value[0] != '#')
{
return false;
}
// Remove the leading # if present to validate the numeric part
$value = ltrim($value, '#');
// The value must be 6 or 3 characters long
if (!((strlen($value) == 6 || strlen($value) == 3) && ctype_xdigit($value)))
{
return false;
}
return true;
}
}
Rule/CssIdentifierSubstringRule.php 0000644 00000005232 15234515367 0013465 0 ustar 00 <?php
/**
* Joomla! Content Management System
*
* @copyright Copyright (C) 2005 - 2020 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\CMS\Form\Rule;
defined('JPATH_PLATFORM') or die;
use Joomla\CMS\Form\Form;
use Joomla\CMS\Form\FormRule;
use Joomla\Registry\Registry;
/**
* Form Rule class for the Joomla Platform.
*
* @since 3.10.7
*/
class CssIdentifierSubstringRule extends FormRule
{
/**
* Method to test if a string is a valid CSS identifer substring
*
* @param \SimpleXMLElement $element The SimpleXMLElement object representing the `<field>` tag for the form field object.
* @param mixed $value The form field value to validate.
* @param string $group The field name group control value. This acts as an array container for the field.
* For example if the field has name="foo" and the group value is set to "bar" then the
* full field name would end up being "bar[foo]".
* @param Registry $input An optional Registry object with the entire data set to validate against the entire form.
* @param Form $form The form object for which the field is being tested.
*
* @return boolean True if the value is valid, false otherwise.
*
* @since 3.10.7
*/
public function test(\SimpleXMLElement $element, $value, $group = null, Registry $input = null, Form $form = null)
{
// If the field is empty and not required, the field is valid.
$required = ((string) $element['required'] === 'true' || (string) $element['required'] === 'required');
if (!$required && empty($value) && $value !== '0')
{
return true;
}
/**
* The following regex rules are based on the Html::cleanCssIdentifier method from Drupal
* https://github.com/drupal/drupal/blob/8.8.5/core/lib/Drupal/Component/Utility/Html.php#L116-L130
*
* with the addition for Joomla that we allow the colon (U+003A).
*/
/**
* Valid characters in a CSS identifier are:
* - the hyphen (U+002D)
* - a-z (U+0030 - U+0039)
* - A-Z (U+0041 - U+005A)
* - the underscore (U+005F)
* - the colon (U+003A)
* - 0-9 (U+0061 - U+007A)
* - ISO 10646 characters U+00A1 and higher
*/
// Make sure we allow multiple classes to be added
$cssIdentifiers = explode(' ', $value);
foreach ($cssIdentifiers as $identifier)
{
if (preg_match('/[^\\x{002D}\\x{0030}-\\x{0039}\\x{0041}-\\x{005A}\\x{005F}\\x{003A}\\x{0061}-\\x{007A}\\x{00A1}-\\x{FFFF}]/u', $identifier))
{
return false;
}
}
return true;
}
}
Rule/EmailRule.php 0000644 00000014010 15234515367 0010052 0 ustar 00 <?php
/**
* Joomla! Content Management System
*
* @copyright (C) 2009 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\CMS\Form\Rule;
defined('JPATH_PLATFORM') or die;
use Joomla\CMS\Component\ComponentHelper;
use Joomla\CMS\Form\Form;
use Joomla\CMS\Form\FormRule;
use Joomla\Registry\Registry;
/**
* Form Rule class for the Joomla Platform.
*
* @since 1.7.0
*/
class EmailRule extends FormRule
{
/**
* The regular expression to use in testing a form field value.
*
* @var string
* @since 1.7.0
* @link http://www.w3.org/TR/html-markup/input.email.html
*/
protected $regex = "^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$";
/**
* Method to test the email address and optionally check for uniqueness.
*
* @param \SimpleXMLElement $element The SimpleXMLElement object representing the `<field>` tag for the form field object.
* @param mixed $value The form field value to validate.
* @param string $group The field name group control value. This acts as an array container for the field.
* For example if the field has name="foo" and the group value is set to "bar" then the
* full field name would end up being "bar[foo]".
* @param Registry $input An optional Registry object with the entire data set to validate against the entire form.
* @param Form $form The form object for which the field is being tested.
*
* @return mixed Boolean true if field value is valid, Exception on failure.
*
* @since 1.7.0
*/
public function test(\SimpleXMLElement $element, $value, $group = null, Registry $input = null, Form $form = null)
{
// If the field is empty and not required, the field is valid.
$required = ((string) $element['required'] == 'true' || (string) $element['required'] == 'required');
if (!$required && empty($value))
{
return true;
}
// If the tld attribute is present, change the regular expression to require at least 2 characters for it.
$tld = ((string) $element['tld'] == 'tld' || (string) $element['tld'] == 'required');
if ($tld)
{
$this->regex = "^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])"
. '?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)+$';
}
// Determine if the multiple attribute is present
$multiple = ((string) $element['multiple'] == 'true' || (string) $element['multiple'] == 'multiple');
if (!$multiple)
{
// Handle idn email addresses by converting to punycode.
$value = \JStringPunycode::emailToPunycode($value);
// Test the value against the regular expression.
if (!parent::test($element, $value, $group, $input, $form))
{
return new \UnexpectedValueException(\JText::_('JLIB_DATABASE_ERROR_VALID_MAIL'));
}
}
else
{
$values = explode(',', $value);
foreach ($values as $value)
{
// Handle idn email addresses by converting to punycode.
$value = \JStringPunycode::emailToPunycode($value);
// Test the value against the regular expression.
if (!parent::test($element, $value, $group, $input, $form))
{
return new \UnexpectedValueException(\JText::_('JLIB_DATABASE_ERROR_VALID_MAIL'));
}
}
}
/**
* validDomains value should consist of component name and the name of domain list field in component's configuration, separated by a dot.
* This allows different components and contexts to use different lists.
* If value is incomplete, com_users.domains is used as fallback.
*/
$validDomains = (isset($element['validDomains']) && $element['validDomains'] != 'false');
if ($validDomains && !$multiple)
{
$config = explode('.', $element['validDomains'], 2);
if (count($config) > 1)
{
$domains = ComponentHelper::getParams($config[0])->get($config[1]);
}
else
{
$domains = ComponentHelper::getParams('com_users')->get('domains');
}
if ($domains)
{
$emailDomain = explode('@', $value);
$emailDomain = $emailDomain[1];
$emailParts = array_reverse(explode('.', $emailDomain));
$emailCount = count($emailParts);
$allowed = true;
foreach ($domains as $domain)
{
$domainParts = array_reverse(explode('.', $domain->name));
$status = 0;
// Don't run if the email has less segments than the rule.
if ($emailCount < count($domainParts))
{
continue;
}
foreach ($emailParts as $key => $emailPart)
{
if (!isset($domainParts[$key]) || $domainParts[$key] == $emailPart || $domainParts[$key] == '*')
{
$status++;
}
}
// All segments match, check whether to allow the domain or not.
if ($status === $emailCount)
{
if ($domain->rule == 0)
{
$allowed = false;
}
else
{
$allowed = true;
}
}
}
// If domain is not allowed, fail validation. Otherwise continue.
if (!$allowed)
{
return new \UnexpectedValueException(\JText::sprintf('JGLOBAL_EMAIL_DOMAIN_NOT_ALLOWED', $emailDomain));
}
}
}
// Check if we should test for uniqueness. This only can be used if multiple is not true
$unique = ((string) $element['unique'] == 'true' || (string) $element['unique'] == 'unique');
if ($unique && !$multiple)
{
// Get the database object and a new query object.
$db = \JFactory::getDbo();
$query = $db->getQuery(true);
// Build the query.
$query->select('COUNT(*)')
->from('#__users')
->where('email = ' . $db->quote($value));
// Get the extra field check attribute.
$userId = ($form instanceof Form) ? $form->getValue('id') : '';
$query->where($db->quoteName('id') . ' <> ' . (int) $userId);
// Set and query the database.
$db->setQuery($query);
$duplicate = (bool) $db->loadResult();
if ($duplicate)
{
return new \UnexpectedValueException(\JText::_('JLIB_DATABASE_ERROR_EMAIL_INUSE'));
}
}
return true;
}
}
Rule/EqualsRule.php 0000644 00000004574 15234515367 0010273 0 ustar 00 <?php
/**
* Joomla! Content Management System
*
* @copyright (C) 2017 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\CMS\Form\Rule;
defined('JPATH_PLATFORM') or die;
use Joomla\CMS\Form\Form;
use Joomla\CMS\Form\FormRule;
use Joomla\Registry\Registry;
/**
* Form Rule class for the Joomla Platform.
*
* @since 1.7.0
*/
class EqualsRule extends FormRule
{
/**
* Method to test if two values are equal. To use this rule, the form
* XML needs a validate attribute of equals and a field attribute
* that is equal to the field to test against.
*
* @param \SimpleXMLElement $element The SimpleXMLElement object representing the `<field>` tag for the form field object.
* @param mixed $value The form field value to validate.
* @param string $group The field name group control value. This acts as an array container for the field.
* For example if the field has name="foo" and the group value is set to "bar" then the
* full field name would end up being "bar[foo]".
* @param Registry $input An optional Registry object with the entire data set to validate against the entire form.
* @param Form $form The form object for which the field is being tested.
*
* @return boolean True if the value is valid, false otherwise.
*
* @since 1.7.0
* @throws \InvalidArgumentException
* @throws \UnexpectedValueException
*/
public function test(\SimpleXMLElement $element, $value, $group = null, Registry $input = null, Form $form = null)
{
$field = (string) $element['field'];
// Check that a validation field is set.
if (!$field)
{
throw new \UnexpectedValueException(sprintf('$field empty in %s::test', get_class($this)));
}
if (is_null($form))
{
throw new \InvalidArgumentException(sprintf('The value for $form must not be null in %s', get_class($this)));
}
if (is_null($input))
{
throw new \InvalidArgumentException(sprintf('The value for $input must not be null in %s', get_class($this)));
}
$test = $input->get($field);
if (isset($group) && $group !== '')
{
$test = $input->get($group . '.' . $field);
}
// Test the two values against each other.
return $value == $test;
}
}
Rule/ExistsRule.php 0000644 00000004236 15234515367 0010313 0 ustar 00 <?php
/**
* Joomla! Content Management System
*
* @copyright (C) 2018 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\CMS\Form\Rule;
defined('JPATH_PLATFORM') or die;
use Joomla\CMS\Factory;
use Joomla\CMS\Form\Form;
use Joomla\CMS\Form\FormRule;
use Joomla\Registry\Registry;
/**
* Form rule class to determine if a value exists in a database table.
*
* @since 3.9.0
*/
class ExistsRule extends FormRule
{
/**
* Method to test the username for uniqueness.
*
* @param \SimpleXMLElement $element The SimpleXMLElement object representing the `<field>` tag for the form field object.
* @param mixed $value The form field value to validate.
* @param string $group The field name group control value. This acts as an array container for the field.
* For example if the field has name="foo" and the group value is set to "bar" then the
* full field name would end up being "bar[foo]".
* @param Registry $input An optional Registry object with the entire data set to validate against the entire form.
* @param Form $form The form object for which the field is being tested.
*
* @return boolean True if the value is valid, false otherwise.
*
* @since 3.9.0
*/
public function test(\SimpleXMLElement $element, $value, $group = null, Registry $input = null, Form $form = null)
{
$value = trim($value);
$existsTable = (string) $element['exists_table'];
$existsColumn = (string) $element['exists_column'];
// We cannot validate without a table name
if ($existsTable === '')
{
return true;
}
// Assume a default column name of `id`
if ($existsColumn === '')
{
$existsColumn = 'id';
}
$db = Factory::getDbo();
// Set and query the database.
$exists = $db->setQuery(
$db->getQuery(true)
->select('COUNT(*)')
->from($db->quoteName($existsTable))
->where($db->quoteName($existsColumn) . ' = ' . $db->quote($value))
)->loadResult();
return (int) $exists > 0;
}
}
Rule/FilePathRule.php 0000644 00000005154 15234515367 0010530 0 ustar 00 <?php
/**
* Joomla! Content Management System
*
* @copyright Copyright (C) 2005 - 2020 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\CMS\Form\Rule;
defined('JPATH_PLATFORM') or die;
use Joomla\CMS\Filesystem\Path;
use Joomla\CMS\Form\Form;
use Joomla\CMS\Form\FormRule;
use Joomla\Registry\Registry;
/**
* Form Rule class for the Joomla Platform.
*
* @since 3.9.21
*/
class FilePathRule extends FormRule
{
/**
* Method to test if the file path is valid
*
* @param \SimpleXMLElement $element The SimpleXMLElement object representing the `<field>` tag for the form field object.
* @param mixed $value The form field value to validate.
* @param string $group The field name group control value. This acts as an array container for the field.
* For example if the field has name="foo" and the group value is set to "bar" then the
* full field name would end up being "bar[foo]".
* @param Registry $input An optional Registry object with the entire data set to validate against the entire form.
* @param Form $form The form object for which the field is being tested.
*
* @return boolean True if the value is valid, false otherwise.
*
* @since 3.9.21
*/
public function test(\SimpleXMLElement $element, $value, $group = null, Registry $input = null, Form $form = null)
{
$value = trim($value);
// If the field is empty and not required, the field is valid.
$required = ((string) $element['required'] == 'true' || (string) $element['required'] == 'required');
if (!$required && empty($value))
{
return true;
}
// Get the exclude setting from the xml
$exclude = (array) explode('|', (string) $element['exclude']);
// Exclude current folder '.' to be safe from full path disclosure
$exclude[] = '.';
// Check the exclude setting
$path = preg_split('/[\/\\\\]/', $value);
if (in_array(strtolower($path[0]), $exclude) || empty($path[0]))
{
return false;
}
// Prepend the root path
$value = JPATH_ROOT . '/' . $value;
// Check if $value is a valid path, which includes not allowing to break out of the current path
try
{
Path::check($value);
}
catch (\Exception $e)
{
// When there is an exception in the check path this is not valid
return false;
}
// When there are no exception this rule should pass.
// See: https://github.com/joomla/joomla-cms/issues/30500#issuecomment-683290162
return true;
}
}
Rule/ModuleLayoutRule.php 0000644 00000002044 15234515367 0011452 0 ustar 00 <?php
/**
* Joomla! Content Management System
*
* @copyright (C) 2021 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\CMS\Form\Rule;
defined('JPATH_PLATFORM') or die;
use Joomla\CMS\Form\FormRule;
/**
* Form Rule class for the Joomla Platform.
*
* @since 3.9.26
*/
class ModuleLayoutRule extends FormRule
{
/**
* The regular expression to use in testing a module layout field value.
*
* A valid module layout field value consists of
* - optionally a template name with only characters, numbers, hyphens and
* underscores, which can also be just "_" for layouts provided by the
* module, followed by a colon.
* - the base name of the layout file, not starting with a dot and with
* only characters, numbers, dots and hyphens but no underscores (see
* method "getInput" of the "ModuleLayout" field).
*
* @var string
* @since 3.9.26
*/
protected $regex = '^([A-Za-z0-9_-]+:)?[A-Za-z0-9-][A-Za-z0-9\.-]*$';
}
Rule/NotequalsRule.php 0000644 00000004251 15234515367 0011004 0 ustar 00 <?php
/**
* Joomla! Content Management System
*
* @copyright (C) 2017 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\CMS\Form\Rule;
defined('JPATH_PLATFORM') or die;
use Joomla\CMS\Form\Form;
use Joomla\CMS\Form\FormRule;
use Joomla\Registry\Registry;
/**
* Form Rule class for the Joomla Platform.
*
* @since 1.7.0
*/
class NotequalsRule extends FormRule
{
/**
* Method to test if two values are not equal. To use this rule, the form
* XML needs a validate attribute of equals and a field attribute
* that is equal to the field to test against.
*
* @param \SimpleXMLElement $element The SimpleXMLElement object representing the `<field>` tag for the form field object.
* @param mixed $value The form field value to validate.
* @param string $group The field name group control value. This acts as an array container for the field.
* For example if the field has name="foo" and the group value is set to "bar" then the
* full field name would end up being "bar[foo]".
* @param Registry $input An optional Registry object with the entire data set to validate against the entire form.
* @param Form $form The form object for which the field is being tested.
*
* @return boolean True if the value is valid, false otherwise.
*
* @since 1.7.0
* @throws \InvalidArgumentException
* @throws \UnexpectedValueException
*/
public function test(\SimpleXMLElement $element, $value, $group = null, Registry $input = null, Form $form = null)
{
$field = (string) $element['field'];
// Check that a validation field is set.
if (!$field)
{
throw new \UnexpectedValueException(sprintf('$field empty in %s::test', get_class($this)));
}
if ($input === null)
{
throw new \InvalidArgumentException(sprintf('The value for $input must not be null in %s', get_class($this)));
}
// Test the two values against each other.
if ($value != $input->get($field))
{
return true;
}
return false;
}
}
Rule/NumberRule.php 0000644 00000004152 15234515367 0010261 0 ustar 00 <?php
/**
* Joomla! Content Management System
*
* @copyright (C) 2017 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\CMS\Form\Rule;
defined('JPATH_PLATFORM') or die;
use Joomla\CMS\Form\Form;
use Joomla\CMS\Form\FormRule;
use Joomla\Registry\Registry;
/**
* Form Rule class for the Joomla Platform.
*
* @since 3.5
*/
class NumberRule extends FormRule
{
/**
* Method to test the range for a number value using min and max attributes.
*
* @param \SimpleXMLElement $element The SimpleXMLElement object representing the `<field>` tag for the form field object.
* @param mixed $value The form field value to validate.
* @param string $group The field name group control value. This acts as an array container for the field.
* For example if the field has name="foo" and the group value is set to "bar" then the
* full field name would end up being "bar[foo]".
* @param Registry $input An optional Registry object with the entire data set to validate against the entire form.
* @param Form $form The form object for which the field is being tested.
*
* @return boolean True if the value is valid, false otherwise.
*
* @since 3.5
*/
public function test(\SimpleXMLElement $element, $value, $group = null, Registry $input = null, Form $form = null)
{
// Check if the field is required.
$required = ((string) $element['required'] == 'true' || (string) $element['required'] == 'required');
// If the value is empty and the field is not required return True.
if (($value === '' || $value === null) && ! $required)
{
return true;
}
$float_value = (float) $value;
if (isset($element['min']))
{
$min = (float) $element['min'];
if ($min > $float_value)
{
return false;
}
}
if (isset($element['max']))
{
$max = (float) $element['max'];
if ($max < $float_value)
{
return false;
}
}
return true;
}
}
Rule/OptionsRule.php 0000644 00000005461 15234515367 0010470 0 ustar 00 <?php
/**
* Joomla! Content Management System
*
* @copyright (C) 2011 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\CMS\Form\Rule;
defined('JPATH_PLATFORM') or die;
use Joomla\CMS\Form\Form;
use Joomla\CMS\Form\FormRule;
use Joomla\Registry\Registry;
/**
* Form Rule class for the Joomla Platform.
* Requires the value entered be one of the options in a field of type="list"
*
* @since 1.7.0
*/
class OptionsRule extends FormRule
{
/**
* Method to test the value.
*
* @param \SimpleXMLElement $element The SimpleXMLElement object representing the `<field>` tag for the form field object.
* @param mixed $value The value to validate.
* @param string $group The field name group control value. This acts as an array container for the field.
* For example if the field has name="foo" and the group value is set to "bar" then the
* full field name would end up being "bar[foo]".
* @param Registry $input An optional Registry object with the entire data set to validate against the entire form.
* @param Form $form The form object for which the field is being tested.
*
* @return boolean True if the value is valid, false otherwise.
*
* @since 1.7.0
*/
public function test(\SimpleXMLElement $element, $value, $group = null, Registry $input = null, Form $form = null)
{
// Check if the field is required.
$required = ((string) $element['required'] == 'true' || (string) $element['required'] == 'required');
// Check if the value is empty.
$blank = empty($value) && $value !== '0' && $value !== 0 && $value !== 0.0;
if (!$required && $blank)
{
return true;
}
// Make an array of all available option values.
$options = array();
// Create the field
$field = null;
if ($form)
{
$field = $form->getField((string) $element->attributes()->name, $group);
}
// When the field exists, the real options are fetched.
// This is needed for fields which do have dynamic options like from a database.
if ($field && is_array($field->options))
{
foreach ($field->options as $opt)
{
$options[] = $opt->value;
}
}
else
{
foreach ($element->option as $opt)
{
$options[] = $opt->attributes()->value;
}
}
// There may be multiple values in the form of an array (if the element is checkboxes, for example).
if (is_array($value))
{
// If all values are in the $options array, $diff will be empty and the options valid.
$diff = array_diff($value, $options);
return empty($diff);
}
else
{
// In this case value must be a string
return in_array((string) $value, $options);
}
}
}
Rule/PasswordRule.php 0000644 00000014370 15234515367 0010636 0 ustar 00 <?php
/**
* Joomla! Content Management System
*
* @copyright (C) 2013 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\CMS\Form\Rule;
defined('JPATH_PLATFORM') or die;
use Joomla\CMS\Component\ComponentHelper;
use Joomla\CMS\Form\Form;
use Joomla\CMS\Form\FormRule;
use Joomla\Registry\Registry;
/**
* Form Rule class for the Joomla Platform.
*
* @since 3.1.2
*/
class PasswordRule extends FormRule
{
/**
* Method to test if two values are not equal. To use this rule, the form
* XML needs a validate attribute of equals and a field attribute
* that is equal to the field to test against.
*
* @param \SimpleXMLElement $element The SimpleXMLElement object representing the `<field>` tag for the form field object.
* @param mixed $value The form field value to validate.
* @param string $group The field name group control value. This acts as an array container for the field.
* For example if the field has name="foo" and the group value is set to "bar" then the
* full field name would end up being "bar[foo]".
* @param Registry $input An optional Registry object with the entire data set to validate against the entire form.
* @param Form $form The form object for which the field is being tested.
*
* @return boolean True if the value is valid, false otherwise.
*
* @since 3.1.2
* @throws \InvalidArgumentException
* @throws \UnexpectedValueException
*/
public function test(\SimpleXMLElement $element, $value, $group = null, Registry $input = null, Form $form = null)
{
$meter = isset($element['strengthmeter']) ? ' meter="0"' : '1';
$threshold = isset($element['threshold']) ? (int) $element['threshold'] : 66;
$minimumLength = isset($element['minimum_length']) ? (int) $element['minimum_length'] : 4;
$minimumIntegers = isset($element['minimum_integers']) ? (int) $element['minimum_integers'] : 0;
$minimumSymbols = isset($element['minimum_symbols']) ? (int) $element['minimum_symbols'] : 0;
$minimumUppercase = isset($element['minimum_uppercase']) ? (int) $element['minimum_uppercase'] : 0;
$minimumLowercase = isset($element['minimum_lowercase']) ? (int) $element['minimum_lowercase'] : 0;
// If we have parameters from com_users, use those instead.
// Some of these may be empty for legacy reasons.
$params = ComponentHelper::getParams('com_users');
if (!empty($params))
{
$minimumLengthp = $params->get('minimum_length');
$minimumIntegersp = $params->get('minimum_integers');
$minimumSymbolsp = $params->get('minimum_symbols');
$minimumUppercasep = $params->get('minimum_uppercase');
$minimumLowercasep = $params->get('minimum_lowercase');
$meterp = $params->get('meter');
$thresholdp = $params->get('threshold');
empty($minimumLengthp) ? : $minimumLength = (int) $minimumLengthp;
empty($minimumIntegersp) ? : $minimumIntegers = (int) $minimumIntegersp;
empty($minimumSymbolsp) ? : $minimumSymbols = (int) $minimumSymbolsp;
empty($minimumUppercasep) ? : $minimumUppercase = (int) $minimumUppercasep;
empty($minimumLowercasep) ? : $minimumLowercase = (int) $minimumLowercasep;
empty($meterp) ? : $meter = $meterp;
empty($thresholdp) ? : $threshold = $thresholdp;
}
// If the field is empty and not required, the field is valid.
$required = ((string) $element['required'] === 'true' || (string) $element['required'] === 'required');
if (!$required && empty($value))
{
return true;
}
$valueLength = strlen($value);
// Load language file of com_users component
\JFactory::getLanguage()->load('com_users');
// We set a maximum length to prevent abuse since it is unfiltered.
if ($valueLength > 4096)
{
\JFactory::getApplication()->enqueueMessage(\JText::_('COM_USERS_MSG_PASSWORD_TOO_LONG'), 'warning');
}
// We don't allow white space inside passwords
$valueTrim = trim($value);
// Set a variable to check if any errors are made in password
$validPassword = true;
if (strlen($valueTrim) !== $valueLength)
{
\JFactory::getApplication()->enqueueMessage(
\JText::_('COM_USERS_MSG_SPACES_IN_PASSWORD'),
'warning'
);
$validPassword = false;
}
// Minimum number of integers required
if (!empty($minimumIntegers))
{
$nInts = preg_match_all('/[0-9]/', $value, $imatch);
if ($nInts < $minimumIntegers)
{
\JFactory::getApplication()->enqueueMessage(
\JText::plural('COM_USERS_MSG_NOT_ENOUGH_INTEGERS_N', $minimumIntegers),
'warning'
);
$validPassword = false;
}
}
// Minimum number of symbols required
if (!empty($minimumSymbols))
{
$nsymbols = preg_match_all('[\W]', $value, $smatch);
if ($nsymbols < $minimumSymbols)
{
\JFactory::getApplication()->enqueueMessage(
\JText::plural('COM_USERS_MSG_NOT_ENOUGH_SYMBOLS_N', $minimumSymbols),
'warning'
);
$validPassword = false;
}
}
// Minimum number of upper case ASCII characters required
if (!empty($minimumUppercase))
{
$nUppercase = preg_match_all('/[A-Z]/', $value, $umatch);
if ($nUppercase < $minimumUppercase)
{
\JFactory::getApplication()->enqueueMessage(
\JText::plural('COM_USERS_MSG_NOT_ENOUGH_UPPERCASE_LETTERS_N', $minimumUppercase),
'warning'
);
$validPassword = false;
}
}
// Minimum number of lower case ASCII characters required
if (!empty($minimumLowercase))
{
$nLowercase = preg_match_all('/[a-z]/', $value, $umatch);
if ($nLowercase < $minimumLowercase)
{
\JFactory::getApplication()->enqueueMessage(
\JText::plural('COM_USERS_MSG_NOT_ENOUGH_LOWERCASE_LETTERS_N', $minimumLowercase),
'warning'
);
$validPassword = false;
}
}
// Minimum length option
if (!empty($minimumLength))
{
if (strlen((string) $value) < $minimumLength)
{
\JFactory::getApplication()->enqueueMessage(
\JText::plural('COM_USERS_MSG_PASSWORD_TOO_SHORT_N', $minimumLength),
'warning'
);
$validPassword = false;
}
}
// If valid has violated any rules above return false.
if (!$validPassword)
{
return false;
}
return true;
}
}
Rule/RulesRule.php 0000644 00000006644 15234515367 0010133 0 ustar 00 <?php
/**
* Joomla! Content Management System
*
* @copyright (C) 2009 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\CMS\Form\Rule;
defined('JPATH_PLATFORM') or die;
use Joomla\CMS\Access\Access;
use Joomla\CMS\Form\Form;
use Joomla\CMS\Form\FormRule;
use Joomla\Registry\Registry;
/**
* Form Rule class for the Joomla Platform.
*
* @since 1.7.0
*/
class RulesRule extends FormRule
{
/**
* Method to test the value.
*
* @param \SimpleXMLElement $element The SimpleXMLElement object representing the `<field>` tag for the form field object.
* @param mixed $value The form field value to validate.
* @param string $group The field name group control value. This acts as an array container for the field.
* For example if the field has name="foo" and the group value is set to "bar" then the
* full field name would end up being "bar[foo]".
* @param Registry $input An optional Registry object with the entire data set to validate against the entire form.
* @param Form $form The form object for which the field is being tested.
*
* @return boolean True if the value is valid, false otherwise.
*
* @since 1.7.0
*/
public function test(\SimpleXMLElement $element, $value, $group = null, Registry $input = null, Form $form = null)
{
// Get the possible field actions and the ones posted to validate them.
$fieldActions = self::getFieldActions($element);
$valueActions = self::getValueActions($value);
// Make sure that all posted actions are in the list of possible actions for the field.
foreach ($valueActions as $action)
{
if (!in_array($action, $fieldActions))
{
return false;
}
}
return true;
}
/**
* Method to get the list of permission action names from the form field value.
*
* @param mixed $value The form field value to validate.
*
* @return array A list of permission action names from the form field value.
*
* @since 1.7.0
*/
protected function getValueActions($value)
{
$actions = array();
// Iterate over the asset actions and add to the actions.
foreach ((array) $value as $name => $rules)
{
$actions[] = $name;
}
return $actions;
}
/**
* Method to get the list of possible permission action names for the form field.
*
* @param \SimpleXMLElement $element The \SimpleXMLElement object representing the `<field>` tag for the form field object.
*
* @return array A list of permission action names from the form field element definition.
*
* @since 1.7.0
*/
protected function getFieldActions(\SimpleXMLElement $element)
{
$actions = array();
// Initialise some field attributes.
$section = $element['section'] ? (string) $element['section'] : '';
$component = $element['component'] ? (string) $element['component'] : '';
// Get the asset actions for the element.
$elActions = Access::getActions($component, $section);
// Iterate over the asset actions and add to the actions.
foreach ($elActions as $item)
{
$actions[] = $item->name;
}
// Iterate over the children and add to the actions.
foreach ($element->children() as $el)
{
if ($el->getName() == 'action')
{
$actions[] = (string) $el['name'];
}
}
return $actions;
}
}
Rule/SubFormRule.php 0000644 00000004723 15234515367 0010412 0 ustar 00 <?php
/**
* Joomla! Content Management System
*
* @copyright (C) 2019 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\CMS\Form\Rule;
defined('JPATH_PLATFORM') or die;
use Joomla\Registry\Registry;
use Joomla\CMS\Form\Form;
use Joomla\CMS\Form\FormRule;
/**
* Form rule to validate subforms field-wise.
*
* @since 3.9.7
*/
class SubformRule extends FormRule
{
/**
* Method to test given values for a subform..
*
* @param \SimpleXMLElement $element The SimpleXMLElement object representing the `<field>` tag for the form field object.
* @param mixed $value The form field value to validate.
* @param string $group The field name group control value. This acts as as an array container for the field.
* For example if the field has name="foo" and the group value is set to "bar" then the
* full field name would end up being "bar[foo]".
* @param Registry $input An optional Registry object with the entire data set to validate against the entire form.
* @param Form $form The form object for which the field is being tested.
*
* @return boolean True if the value is valid, false otherwise.
*
* @since 3.9.7
*/
public function test(\SimpleXMLElement $element, $value, $group = null, Registry $input = null, Form $form = null)
{
// Get the form field object.
$field = $form->getField($element['name'], $group);
if (!($field instanceof \JFormFieldSubform))
{
throw new \UnexpectedValueException(sprintf('%s is no subform field.', $element['name']));
}
if ($value === null)
{
return true;
}
$subForm = $field->loadSubForm();
// Multiple values: Validate every row.
if ($field->multiple)
{
foreach ($value as $row)
{
if ($subForm->validate($row) === false)
{
// Pass the first error that occurred on the subform validation.
$errors = $subForm->getErrors();
if (!empty($errors[0]))
{
return $errors[0];
}
return false;
}
}
}
// Single value.
else
{
if ($subForm->validate($value) === false)
{
// Pass the first error that occurred on the subform validation.
$errors = $subForm->getErrors();
if (!empty($errors[0]))
{
return $errors[0];
}
return false;
}
}
return true;
}
}
Rule/TelRule.php 0000644 00000006200 15234515367 0007551 0 ustar 00 <?php
/**
* Joomla! Content Management System
*
* @copyright (C) 2011 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\CMS\Form\Rule;
defined('JPATH_PLATFORM') or die;
use Joomla\CMS\Form\Form;
use Joomla\CMS\Form\FormRule;
use Joomla\Registry\Registry;
/**
* Form Rule class for the Joomla Platform
*
* @since 1.7.0
*/
class TelRule extends FormRule
{
/**
* Method to test the url for a valid parts.
*
* @param \SimpleXMLElement $element The SimpleXMLElement object representing the `<field>` tag for the form field object.
* @param mixed $value The form field value to validate.
* @param string $group The field name group control value. This acts as an array container for the field.
* For example if the field has name="foo" and the group value is set to "bar" then the
* full field name would end up being "bar[foo]".
* @param Registry $input An optional Registry object with the entire data set to validate against the entire form.
* @param Form $form The form object for which the field is being tested.
*
* @return boolean True if the value is valid, false otherwise.
*
* @since 1.7.0
*/
public function test(\SimpleXMLElement $element, $value, $group = null, Registry $input = null, Form $form = null)
{
// If the field is empty and not required, the field is valid.
$required = ((string) $element['required'] == 'true' || (string) $element['required'] == 'required');
if (!$required && empty($value))
{
return true;
}
/*
* @link http://www.nanpa.com/
* @link http://tools.ietf.org/html/rfc4933
* @link http://www.itu.int/rec/T-REC-E.164/en
*
* Regex by Steve Levithan
* @link http://blog.stevenlevithan.com/archives/validate-phone-number
* @note that valid ITU-T and EPP must begin with +.
*/
$regexarray = array(
'NANP' => '/^(?:\+?1[-. ]?)?\(?([2-9][0-8][0-9])\)?[-. ]?([2-9][0-9]{2})[-. ]?([0-9]{4})$/',
'ITU-T' => '/^\+(?:[0-9] ?){6,14}[0-9]$/',
'EPP' => '/^\+[0-9]{1,3}\.[0-9]{4,14}(?:x.+)?$/',
);
if (isset($element['plan']))
{
$plan = (string) $element['plan'];
if ($plan == 'northamerica' || $plan == 'us')
{
$plan = 'NANP';
}
elseif ($plan == 'International' || $plan == 'int' || $plan == 'missdn' || !$plan)
{
$plan = 'ITU-T';
}
elseif ($plan == 'IETF')
{
$plan = 'EPP';
}
$regex = $regexarray[$plan];
// Test the value against the regular expression.
if (preg_match($regex, $value) == false)
{
return false;
}
}
else
{
/*
* If the rule is set but no plan is selected just check that there are between
* 7 and 15 digits inclusive and no illegal characters (but common number separators
* are allowed).
*/
$cleanvalue = preg_replace('/[+. \-(\)]/', '', $value);
$regex = '/^[0-9]{7,15}?$/';
if (preg_match($regex, $cleanvalue) == true)
{
return true;
}
else
{
return false;
}
}
return true;
}
}
Rule/UrlRule.php 0000644 00000010503 15234515367 0007570 0 ustar 00 <?php
/**
* Joomla! Content Management System
*
* @copyright (C) 2011 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\CMS\Form\Rule;
defined('JPATH_PLATFORM') or die;
use Joomla\CMS\Form\Form;
use Joomla\CMS\Form\FormRule;
use Joomla\Registry\Registry;
use Joomla\String\StringHelper;
use Joomla\Uri\UriHelper;
/**
* Form Rule class for the Joomla Platform.
*
* @since 1.7.0
*/
class UrlRule extends FormRule
{
/**
* Method to test an external or internal url for all valid parts.
*
* @param \SimpleXMLElement $element The SimpleXMLElement object representing the `<field>` tag for the form field object.
* @param mixed $value The form field value to validate.
* @param string $group The field name group control value. This acts as an array container for the field.
* For example if the field has name="foo" and the group value is set to "bar" then the
* full field name would end up being "bar[foo]".
* @param Registry $input An optional Registry object with the entire data set to validate against the entire form.
* @param Form $form The form object for which the field is being tested.
*
* @return boolean True if the value is valid, false otherwise.
*
* @since 1.7.0
* @link http://www.w3.org/Addressing/URL/url-spec.txt
* @see JString
*/
public function test(\SimpleXMLElement $element, $value, $group = null, Registry $input = null, Form $form = null)
{
// If the field is empty and not required, the field is valid.
$required = ((string) $element['required'] == 'true' || (string) $element['required'] == 'required');
if (!$required && empty($value))
{
return true;
}
$urlParts = UriHelper::parse_url($value);
// See http://www.w3.org/Addressing/URL/url-spec.txt
// Use the full list or optionally specify a list of permitted schemes.
if ($element['schemes'] == '')
{
$scheme = array('http', 'https', 'ftp', 'ftps', 'gopher', 'mailto', 'news', 'prospero', 'telnet', 'rlogin', 'sftp', 'tn3270', 'wais',
'mid', 'cid', 'nntp', 'tel', 'urn', 'ldap', 'file', 'fax', 'modem', 'git');
}
else
{
$scheme = explode(',', $element['schemes']);
}
/*
* Note that parse_url() does not always parse accurately without a scheme,
* but at least the path should be set always. Note also that parse_url()
* returns False for seriously malformed URLs instead of an associative array.
* @link https://www.php.net/manual/en/function.parse-url.php
*/
if ($urlParts === false || !array_key_exists('scheme', $urlParts))
{
/*
* The function parse_url() returned false (seriously malformed URL) or no scheme
* was found and the relative option is not set: in both cases the field is not valid.
*/
if ($urlParts === false || !$element['relative'])
{
$element->addAttribute('message', \JText::sprintf('JLIB_FORM_VALIDATE_FIELD_URL_SCHEMA_MISSING', $value, implode(', ', $scheme)));
return false;
}
// The best we can do for the rest is make sure that the path exists and is valid UTF-8.
if (!array_key_exists('path', $urlParts) || !StringHelper::valid((string) $urlParts['path']))
{
return false;
}
// The internal URL seems to be good.
return true;
}
// Scheme found, check all parts found.
$urlScheme = (string) $urlParts['scheme'];
$urlScheme = strtolower($urlScheme);
if (in_array($urlScheme, $scheme) == false)
{
return false;
}
// For some schemes here must be two slashes.
$scheme = array('http', 'https', 'ftp', 'ftps', 'gopher', 'wais', 'prospero', 'sftp', 'telnet', 'git');
if (in_array($urlScheme, $scheme) && substr($value, strlen($urlScheme), 3) !== '://')
{
return false;
}
// The best we can do for the rest is make sure that the strings are valid UTF-8
// and the port is an integer.
if (array_key_exists('host', $urlParts) && !StringHelper::valid((string) $urlParts['host']))
{
return false;
}
if (array_key_exists('port', $urlParts) && !is_int((int) $urlParts['port']))
{
return false;
}
if (array_key_exists('path', $urlParts) && !StringHelper::valid((string) $urlParts['path']))
{
return false;
}
return true;
}
}
Rule/UsernameRule.php 0000644 00000004056 15234515367 0010613 0 ustar 00 <?php
/**
* Joomla! Content Management System
*
* @copyright (C) 2017 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\CMS\Form\Rule;
defined('JPATH_PLATFORM') or die;
use Joomla\CMS\Form\Form;
use Joomla\CMS\Form\FormRule;
use Joomla\Registry\Registry;
/**
* Form Rule class for the Joomla Platform.
*
* @since 1.7.0
*/
class UsernameRule extends FormRule
{
/**
* Method to test the username for uniqueness.
*
* @param \SimpleXMLElement $element The SimpleXMLElement object representing the `<field>` tag for the form field object.
* @param mixed $value The form field value to validate.
* @param string $group The field name group control value. This acts as an array container for the field.
* For example if the field has name="foo" and the group value is set to "bar" then the
* full field name would end up being "bar[foo]".
* @param Registry $input An optional Registry object with the entire data set to validate against the entire form.
* @param Form $form The form object for which the field is being tested.
*
* @return boolean True if the value is valid, false otherwise.
*
* @since 1.7.0
*/
public function test(\SimpleXMLElement $element, $value, $group = null, Registry $input = null, Form $form = null)
{
// Get the database object and a new query object.
$db = \JFactory::getDbo();
$query = $db->getQuery(true);
// Build the query.
$query->select('COUNT(*)')
->from('#__users')
->where('username = ' . $db->quote($value));
// Get the extra field check attribute.
$userId = ($form instanceof Form) ? $form->getValue('id') : '';
$query->where($db->quoteName('id') . ' <> ' . (int) $userId);
// Set and query the database.
$db->setQuery($query);
$duplicate = (bool) $db->loadResult();
if ($duplicate)
{
return false;
}
return true;
}
}
Form.php 0000644 00000071360 15234515367 0006202 0 ustar 00 <?php
/**
* @package FOF
* @copyright Copyright (c)2010-2019 Nicholas K. Dionysopoulos / Akeeba Ltd
* @license GNU GPL version 2 or later
*/
namespace FOF30\Form;
use FOF30\Container\Container;
use FOF30\Form\Header\HeaderBase;
use FOF30\Model\DataModel;
use FOF30\View\DataView\DataViewInterface;
use JFactory;
use JForm;
use Joomla\Registry\Registry;
use JText;
use SimpleXMLElement;
defined('_JEXEC') or die;
/**
* Form is an extension to JForm which support not only edit views but also
* browse (record list) and read (single record display) views based on XML
* forms.
*
* @package FrameworkOnFramework
* @since 2.0
*
* @deprecated 3.1 Support for XML forms will be removed in FOF 4
*/
class Form extends JForm
{
/**
* The model attached to this view
*
* @var DataModel
*/
protected $model;
/**
* The view used to render this form
*
* @var DataViewInterface
*/
protected $view;
/**
* The Container this form belongs to
*
* @var \FOF30\Container\Container
*/
protected $container;
/**
* Map of entity objects for re-use.
* Prototypes for all fields and rules are here.
*
* Array's structure:
* <code>
* entities:
* {ENTITY_NAME}:
* {KEY}: {OBJECT}
* </code>
*
* @var array
*/
protected $entities = array();
/**
* Method to instantiate the form object.
*
* @param Container $container The component Container where this form belongs to
* @param string $name The name of the form.
* @param array $options An array of form options.
*/
public function __construct(Container $container, $name, array $options = array())
{
parent::__construct($name, $options);
$this->container = $container;
}
/**
* Returns the value of an attribute of the form itself
*
* @param string $attribute The name of the attribute
* @param mixed $default Optional default value to return
*
* @return mixed
*
* @since 2.0
*/
public function getAttribute($attribute, $default = null)
{
$value = $this->xml->attributes()->$attribute;
if (is_null($value))
{
return $default;
}
else
{
return (string)$value;
}
}
/**
* Loads the CSS files defined in the form, based on its cssfiles attribute
*
* @return void
*
* @since 2.0
*/
public function loadCSSFiles()
{
// Support for CSS files
$cssfiles = $this->getAttribute('cssfiles');
if (!empty($cssfiles))
{
$cssfiles = explode(',', $cssfiles);
foreach ($cssfiles as $cssfile)
{
$this->getView()->addCssFile(trim($cssfile));
}
}
// Support for LESS files
$lessfiles = $this->getAttribute('lessfiles');
if (!empty($lessfiles))
{
$lessfiles = explode(',', $lessfiles);
foreach ($lessfiles as $def)
{
$parts = explode('||', $def, 2);
$lessfile = $parts[0];
$alt = (count($parts) > 1) ? trim($parts[1]) : null;
$this->getView()->addLess(trim($lessfile), $alt);
}
}
}
/**
* Loads the Javascript files defined in the form, based on its jsfiles attribute
*
* @return void
*
* @since 2.0
*/
public function loadJSFiles()
{
$jsfiles = $this->getAttribute('jsfiles');
if (empty($jsfiles))
{
return;
}
$jsfiles = explode(',', $jsfiles);
foreach ($jsfiles as $jsfile)
{
$this->getView()->addJavascriptFile(trim($jsfile));
}
}
/**
* Returns a reference to the protected $data object, allowing direct
* access to and manipulation of the form's data.
*
* @return \JRegistry|Registry The form's data registry
*
* @since 2.0
*/
public function &getData()
{
return $this->data;
}
/**
* Method to load the form description from an XML file.
*
* The reset option works on a group basis. If the XML file references
* groups that have already been created they will be replaced with the
* fields in the new XML file unless the $reset parameter has been set
* to false.
*
* @param string $file The filesystem path of an XML file.
* @param bool $reset Flag to toggle whether form fields should be replaced if a field
* already exists with the same group/name.
* @param bool $xpath An optional xpath to search for the fields.
*
* @return boolean True on success, false otherwise.
*/
public function loadFile($file, $reset = true, $xpath = false)
{
// Check to see if the path is an absolute path.
if (!is_file($file))
{
return false;
}
// Attempt to load the XML file.
$xml = simplexml_load_file($file);
return $this->load($xml, $reset, $xpath);
}
/**
* Attaches a DataModel to this form
*
* @param DataModel &$model The model to attach to the form
*
* @return void
*/
public function setModel(DataModel &$model)
{
$this->model = $model;
}
/**
* Returns the DataModel attached to this form
*
* @return DataModel
*/
public function &getModel()
{
return $this->model;
}
/**
* Attaches a DataViewInterface to this form
*
* @param DataViewInterface &$view The view to attach to the form
*
* @return void
*/
public function setView(DataViewInterface &$view)
{
$this->view = $view;
}
/**
* Returns the DataViewInterface attached to this form
*
* @return DataViewInterface
*/
public function &getView()
{
return $this->view;
}
/**
* Method to get an array of FormHeader objects in the headerset.
*
* @return array The array of HeaderInterface objects in the headerset.
*
* @since 2.0
*/
public function getHeaderset()
{
$fields = array();
$elements = $this->findHeadersByGroup();
// If no field elements were found return empty.
if (empty($elements))
{
return $fields;
}
// Build the result array from the found field elements.
/** @var \SimpleXMLElement $element */
foreach ($elements as $element)
{
// Get the field groups for the element.
$attrs = $element->xpath('ancestor::headerset[@name]/@name');
$groups = array_map('strval', $attrs ? $attrs : array());
$group = implode('.', $groups);
// If the field is successfully loaded add it to the result array.
/** @var HeaderBase $field */
if ($field = $this->loadHeader($element, $group))
{
$fields[$field->id] = $field;
}
}
return $fields;
}
/**
* Method to get an array of <header /> elements from the form XML document which are
* in a control group by name.
*
* @param mixed $group The optional dot-separated form group path on which to find the fields.
* Null will return all fields. False will return fields not in a group.
* @param boolean $nested True to also include fields in nested groups that are inside of the
* group for which to find fields.
*
* @return \SimpleXMLElement|bool Boolean false on error or array of SimpleXMLElement objects.
*
* @since 2.0
*/
protected function &findHeadersByGroup($group = null, $nested = false)
{
$false = false;
$fields = array();
// Make sure there is a valid JForm XML document.
if (!($this->xml instanceof \SimpleXMLElement))
{
return $false;
}
// Get only fields in a specific group?
if ($group)
{
// Get the fields elements for a given group.
$elements = &$this->findHeader($group);
// Get all of the field elements for the fields elements.
/** @var \SimpleXMLElement $element */
foreach ($elements as $element)
{
// If there are field elements add them to the return result.
if ($tmp = $element->xpath('descendant::header'))
{
// If we also want fields in nested groups then just merge the arrays.
if ($nested)
{
$fields = array_merge($fields, $tmp);
}
// If we want to exclude nested groups then we need to check each field.
else
{
$groupNames = explode('.', $group);
foreach ($tmp as $field)
{
// Get the names of the groups that the field is in.
$attrs = $field->xpath('ancestor::headers[@name]/@name');
$names = array_map('strval', $attrs ? $attrs : array());
// If the field is in the specific group then add it to the return list.
if ($names == (array)$groupNames)
{
$fields = array_merge($fields, array($field));
}
}
}
}
}
}
elseif ($group === false)
{
// Get only field elements not in a group.
$fields = $this->xml->xpath('descendant::headers[not(@name)]/header | descendant::headers[not(@name)]/headerset/header ');
}
else
{
// Get an array of all the <header /> elements.
$fields = $this->xml->xpath('//header');
}
return $fields;
}
/**
* Method to get a header field represented as a HeaderInterface object.
*
* @param string $name The name of the header field.
* @param string $group The optional dot-separated form group path on which to find the field.
* @param mixed $value The optional value to use as the default for the field. (DEPRECATED)
*
* @return HeaderInterface|bool The HeaderInterface object for the field or boolean false on error.
*
* @since 2.0
*/
public function getHeader($name, $group = null, $value = null)
{
// Make sure there is a valid Form XML document.
if (!($this->xml instanceof \SimpleXMLElement))
{
return false;
}
// Attempt to find the field by name and group.
$element = $this->findHeader($name, $group);
// If the field element was not found return false.
if (!$element)
{
return false;
}
return $this->loadHeader($element, $group);
}
/**
* Method to get a header field represented as an XML element object.
*
* @param string $name The name of the form field.
* @param string $group The optional dot-separated form group path on which to find the field.
*
* @return mixed The XML element object for the field or boolean false on error.
*
* @since 2.0
*/
protected function findHeader($name, $group = null)
{
$element = false;
$fields = array();
// Make sure there is a valid JForm XML document.
if (!($this->xml instanceof \SimpleXMLElement))
{
return false;
}
// Let's get the appropriate field element based on the method arguments.
if ($group)
{
// Get the fields elements for a given group.
$elements = &$this->findGroup($group);
// Get all of the field elements with the correct name for the fields elements.
/** @var \SimpleXMLElement $element */
foreach ($elements as $element)
{
// If there are matching field elements add them to the fields array.
if ($tmp = $element->xpath('descendant::header[@name="' . $name . '"]'))
{
$fields = array_merge($fields, $tmp);
}
}
// Make sure something was found.
if (!$fields)
{
return false;
}
// Use the first correct match in the given group.
$groupNames = explode('.', $group);
/** @var \SimpleXMLElement $field */
foreach ($fields as &$field)
{
// Get the group names as strings for ancestor fields elements.
$attrs = $field->xpath('ancestor::headerfields[@name]/@name');
$names = array_map('strval', $attrs ? $attrs : array());
// If the field is in the exact group use it and break out of the loop.
if ($names == (array)$groupNames)
{
$element = &$field;
break;
}
}
}
else
{
// Get an array of fields with the correct name.
$fields = $this->xml->xpath('//header[@name="' . $name . '"]');
// Make sure something was found.
if (!$fields)
{
return false;
}
// Search through the fields for the right one.
foreach ($fields as &$field)
{
// If we find an ancestor fields element with a group name then it isn't what we want.
if ($field->xpath('ancestor::headerfields[@name]'))
{
continue;
}
// Found it!
else
{
$element = &$field;
break;
}
}
}
return $element;
}
/**
* Method to load, setup and return a HeaderInterface object based on field data.
*
* @param string $element The XML element object representation of the form field.
* @param string $group The optional dot-separated form group path on which to find the field.
*
* @return HeaderInterface|bool The HeaderInterface object for the field or boolean false on error.
*
* @since 2.0
*/
protected function loadHeader($element, $group = null)
{
// Make sure there is a valid SimpleXMLElement.
if (!($element instanceof \SimpleXMLElement))
{
return false;
}
// Get the field type.
$type = $element['type'] ? (string)$element['type'] : 'field';
// Load the JFormField object for the field.
$field = $this->loadHeaderType($type);
// If the object could not be loaded, get a text field object.
if ($field === false)
{
$field = $this->loadHeaderType('field');
}
// Setup the HeaderInterface object.
$field->setForm($this);
if ($field->setup($element, $group))
{
return $field;
}
else
{
return false;
}
}
/**
* Method to remove a header from the form definition.
*
* @param string $name The name of the form field for which remove.
* @param string $group The optional dot-separated form group path on which to find the field.
*
* @return boolean True on success, false otherwise.
*
* @throws \UnexpectedValueException
*/
public function removeHeader($name, $group = null)
{
// Make sure there is a valid JForm XML document.
if (!($this->xml instanceof SimpleXMLElement))
{
throw new \UnexpectedValueException(sprintf('%s::getFieldAttribute `xml` is not an instance of SimpleXMLElement', get_class($this)));
}
// Find the form field element from the definition.
$element = $this->findHeader($name, $group);
// If the element exists remove it from the form definition.
if ($element instanceof SimpleXMLElement)
{
$dom = dom_import_simplexml($element);
$dom->parentNode->removeChild($dom);
return true;
}
return false;
}
/**
* Proxy for {@link Helper::loadFieldType()}.
*
* @param string $type The field type.
* @param boolean $new Flag to toggle whether we should get a new instance of the object.
*
* @return FieldInterface|bool FieldInterface object on success, false otherwise.
*
* @since 2.0
*/
protected function loadFieldType($type, $new = true)
{
return $this->loadType('field', $type, $new);
}
/**
* Proxy for {@link Helper::loadHeaderType()}.
*
* @param string $type The field type.
* @param boolean $new Flag to toggle whether we should get a new instance of the object.
*
* @return HeaderInterface|bool HeaderInterface object on success, false otherwise.
*
* @since 2.0
*/
protected function loadHeaderType($type, $new = true)
{
return $this->loadType('header', $type, $new);
}
/**
* Proxy for {@link Helper::loadRuleType()}.
*
* @param string $type The rule type.
* @param boolean $new Flag to toggle whether we should get a new instance of the object.
*
* @return \JFormRule|bool JFormRule object on success, false otherwise.
*
* @see Helper::loadRuleType()
* @since 2.0
*/
protected function loadRuleType($type, $new = true)
{
return $this->loadType('rule', $type, $new);
}
/**
* Method to load a form entity object given a type.
* Each type is loaded only once and then used as a prototype for other objects of same type.
* Please, use this method only with those entities which support types (forms don't support them).
*
* @param string $entity The entity.
* @param string $type The entity type.
* @param boolean $new Flag to toggle whether we should get a new instance of the object.
*
* @return mixed Entity object on success, false otherwise.
*/
protected function loadType($entity, $type, $new = true)
{
// Reference to an array with current entity's type instances
$types = &$this->entities[$entity];
// Return an entity object if it already exists and we don't need a new one.
if (isset($types[$type]) && $new === false)
{
return $types[$type];
}
$class = $this->loadClass($entity, $type);
if ($class !== false)
{
// Instantiate a new type object.
$types[$type] = new $class;
return $types[$type];
}
else
{
return false;
}
}
/**
* Load a class for one of the form's entities of a particular type.
* Currently, it makes sense to use this method for the "field" and "rule" entities
* (but you can support more entities in your subclass).
*
* @param string $entity One of the form entities (field, header or rule).
* @param string $type Type of an entity.
*
* @return mixed Class name on success or false otherwise.
*
* @since 2.0
*/
public function loadClass($entity, $type)
{
// Get the prefixes for namespaced classes (FOF3 way)
$namespacedPrefixes = array(
$this->container->getNamespacePrefix(),
'FOF30\\',
);
// Get the prefixes for non-namespaced classes (FOF2 and Joomla! way)
$plainPrefixes = array('J');
// If the type is given as prefix.type add the custom type into the two prefix arrays
if (strpos($type, '.'))
{
list($prefix, $type) = explode('.', $type);
array_unshift($plainPrefixes, $prefix);
array_unshift($namespacedPrefixes, $prefix);
}
// First try to find the namespaced class
foreach ($namespacedPrefixes as $prefix)
{
$class = rtrim($prefix, '\\') . '\\Form\\' . ucfirst($entity) . '\\' . ucfirst($type);
if (class_exists($class, true))
{
return $class;
}
}
// TODO The rest of the code is legacy and will be removed in a future version
// Then try to find the non-namespaced class
$classes = array();
foreach ($plainPrefixes as $prefix)
{
$class = \JString::ucfirst($prefix, '_') . 'Form' . \JString::ucfirst($entity, '_') . \JString::ucfirst($type, '_');
if (class_exists($class, true))
{
return $class;
}
$classes[] = $class;
}
// Get the field search path array.
$reflector = new \ReflectionClass('\\JFormHelper');
$addPathMethod = $reflector->getMethod('addPath');
$addPathMethod->setAccessible(true);
$paths = $addPathMethod->invoke(null, $entity);
// If the type is complex, add the base type to the paths.
if ($pos = strpos($type, '_'))
{
// Add the complex type prefix to the paths.
for ($i = 0, $n = count($paths); $i < $n; $i++)
{
// Derive the new path.
$path = $paths[$i] . '/' . strtolower(substr($type, 0, $pos));
// If the path does not exist, add it.
if (!in_array($path, $paths))
{
$paths[] = $path;
}
}
// Break off the end of the complex type.
$type = substr($type, $pos + 1);
}
// Try to find the class file.
$type = strtolower($type) . '.php';
foreach ($paths as $path)
{
if ($file = \JPath::find($path, $type))
{
require_once $file;
foreach ($classes as $class)
{
if (class_exists($class, false))
{
return $class;
}
}
}
}
return false;
}
/**
* WARNING: THIS IS IGNORED IN FOF3!
*
* @param string $new IGNORED!
*
* @return void
*
* @deprecated 3.0
*/
public static function addFieldPath($new = null)
{
if ($new) {}; // Prevents phpStorm from freaking out about the unused $new parameter...
if (class_exists('JLog'))
{
\JLog::add(__CLASS__ . '::' . __METHOD__ . '() is deprecated since FOF 3.0 and should not be used.', \JLog::WARNING, 'deprecated');
}
}
/**
* WARNING: THIS IS IGNORED IN FOF3!
*
* @param string $new IGNORED!
*
* @return void
*
* @deprecated 3.0
*/
public static function addHeaderPath($new = null)
{
if ($new) {}; // Prevents phpStorm from freaking out about the unused $new parameter...
if (class_exists('JLog'))
{
\JLog::add(__CLASS__ . '::' . __METHOD__ . '() is deprecated since FOF 3.0 and should not be used.', \JLog::WARNING, 'deprecated');
}
}
/**
* WARNING: THIS IS IGNORED IN FOF3!
*
* @param string $new IGNORED!
*
* @return void
*
* @deprecated 3.0
*/
public static function addFormPath($new = null)
{
if ($new) {}; // Prevents phpStorm from freaking out about the unused $new parameter...
if (class_exists('JLog'))
{
\JLog::add(__CLASS__ . '::' . __METHOD__ . '() is deprecated since FOF 3.0 and should not be used.', \JLog::WARNING, 'deprecated');
}
}
/**
* WARNING: THIS IS IGNORED IN FOF3!
*
* @param string $new IGNORED!
*
* @return void
*
* @deprecated 3.0
*/
public static function addRulePath($new = null)
{
if ($new) {}; // Prevents phpStorm from freaking out about the unused $new parameter...
if (class_exists('JLog'))
{
\JLog::add(__CLASS__ . '::' . __METHOD__ . '() is deprecated since FOF 3.0 and should not be used.', \JLog::WARNING, 'deprecated');
}
}
/**
* Get a reference to the form's Container
*
* @return Container
*/
public function &getContainer()
{
return $this->container;
}
/**
* Set the form's Container
*
* @param Container $container
*/
public function setContainer($container)
{
$this->container = $container;
}
/**
* Method to bind data to the form.
*
* @param mixed $data An array or object of data to bind to the form.
*
* @return boolean True on success.
*
* @since 11.1
*/
public function bind($data)
{
$this->data = class_exists('JRegistry') ? new \JRegistry() : new Registry();
if (is_object($data) && ($data instanceof DataModel))
{
$maxDepth = (int) $this->getAttribute('relation_depth', '1');
return parent::bind($this->modelToBindSource($data, $maxDepth));
}
return parent::bind($data);
}
/**
* Method to bind data to the form for the group level.
*
* @param string $group The dot-separated form group path on which to bind the data.
* @param mixed $data An array or object of data to bind to the form for the group level.
*
* @return void
*
* @since 11.1
*/
protected function bindLevel($group, $data)
{
if (is_object($data) && ($data instanceof DataModel))
{
parent::bindLevel($group, $this->modelToBindSource($data));
return;
}
parent::bindLevel($group, $data);
}
/**
* Method to load, setup and return a JFormField object based on field data.
*
* @param string $element The XML element object representation of the form field.
* @param string $group The optional dot-separated form group path on which to find the field.
* @param mixed $value The optional value to use as the default for the field.
*
* @return mixed The JFormField object for the field or boolean false on error.
*
* @since 11.1
*/
protected function loadField($element, $group = null, $value = null)
{
// Make sure there is a valid SimpleXMLElement.
if (!($element instanceof SimpleXMLElement))
{
return false;
}
// Get the field type.
$type = $element['type'] ? (string) $element['type'] : 'text';
// Load the JFormField object for the field.
$field = $this->loadFieldType($type);
// If the object could not be loaded, get a text field object.
if ($field === false)
{
$field = $this->loadFieldType('text');
}
/*
* Get the value for the form field if not set.
* Default to the translated version of the 'default' attribute
* if 'translate_default' attribute if set to 'true' or '1'
* else the value of the 'default' attribute for the field.
*/
if ($value === null)
{
$default = (string) $element['default'];
if (($translate = $element['translate_default']) && ((string) $translate == 'true' || (string) $translate == '1'))
{
$lang = JFactory::getLanguage();
if ($lang->hasKey($default))
{
$debug = $lang->setDebug(false);
$default = JText::_($default);
$lang->setDebug($debug);
}
else
{
$default = JText::_($default);
}
}
$getValueFrom = (isset($element['name_from'])) ? (string) $element['name_from'] : (string) $element['name'];
$value = $this->getValue($getValueFrom, $group, $default);
}
// Setup the JFormField object.
$field->setForm($this);
if ($field->setup($element, $value, $group))
{
return $field;
}
else
{
return false;
}
}
/**
* Method to get a form field represented as an XML element object.
*
* @param string $name The name of the form field.
* @param string $group The optional dot-separated form group path on which to find the field.
*
* @return mixed The XML element object for the field or boolean false on error.
*
* @since 11.1
*/
protected function findField($name, $group = null)
{
$element = false;
$fields = array();
// Make sure there is a valid JForm XML document.
if (!($this->xml instanceof SimpleXMLElement))
{
return false;
}
// Let's get the appropriate field element based on the method arguments.
if ($group)
{
// Get the fields elements for a given group.
$elements = &$this->findGroup($group);
// Get all of the field elements with the correct name for the fields elements.
/** @var SimpleXMLElement $element */
foreach ($elements as $element)
{
// If there are matching field elements add them to the fields array.
if ($tmp = $element->xpath('descendant::field[@name="' . $name . '"]'))
{
$fields = array_merge($fields, $tmp);
}
elseif ($tmp = $element->xpath('descendant::field[@name_from="' . $name . '"]'))
{
$fields = array_merge($fields, $tmp);
}
}
// Make sure something was found.
if (!$fields)
{
return false;
}
// Use the first correct match in the given group.
$groupNames = explode('.', $group);
/** @var SimpleXMLElement $field */
foreach ($fields as &$field)
{
// Get the group names as strings for ancestor fields elements.
$attrs = $field->xpath('ancestor::fields[@name]/@name');
$names = array_map('strval', $attrs ? $attrs : array());
// If the field is in the exact group use it and break out of the loop.
if ($names == (array) $groupNames)
{
$element = &$field;
break;
}
}
}
else
{
// Get an array of fields with the correct name.
$fields = $this->xml->xpath('//field[@name="' . $name . '"]');
if (!$fields)
{
$fields = array();
}
$fieldsNameFrom = $this->xml->xpath('//field[@name_from="' . $name . '"]');
if ($fieldsNameFrom)
{
$fields = array_merge($fields, $fieldsNameFrom);
}
// Make sure something was found.
if (empty($fields))
{
return false;
}
// Search through the fields for the right one.
foreach ($fields as &$field)
{
// If we find an ancestor fields element with a group name then it isn't what we want.
if ($field->xpath('ancestor::fields[@name]'))
{
continue;
}
// Found it!
else
{
$element = &$field;
break;
}
}
}
return $element;
}
/**
* Converts a DataModel into data suitable for use with the form. The difference to the Model's getData() method is
* that we process hasOne and belongsTo relations. This is a recursive function which will be called at most
* $maxLevel deep. You can set this in the form XML file, in the relation_depth attribute.
*
* The $modelsProcessed array which is passed in successive recursions lets us prevent pointless Inception-style
* recursions, e.g. Model A is related to Model B is related to Model C is related to Model A. You clearly don't
* care to see a.b.c.a.b in the results. You just want a.b.c. Obviously c is indirectly related to a because that's
* where you began the recursion anyway.
*
* @param DataModel $model The item to dump its contents into an array
* @param int $maxLevel Maximum nesting level of relations to process. Default: 1.
* @param array $modelsProcessed Array of the fully qualified model class names already processed.
*
* @return array
* @throws DataModel\Relation\Exception\RelationNotFound
*/
protected function modelToBindSource(DataModel $model, $maxLevel = 1, $modelsProcessed = array())
{
$maxLevel--;
$data = $model->toArray();
$relations = $model->getRelations()->getRelationNames();
$relationTypes = $model->getRelations()->getRelationTypes();
$relationTypes = array_map(function ($x) {
return ltrim($x, '\\');
}, $relationTypes);
$relationTypes = array_flip($relationTypes);
if (is_array($relations) && count($relations) && ($maxLevel >= 0))
{
foreach ($relations as $relationName)
{
$rel = $model->getRelations()->getRelation($relationName);
$class = get_class($rel);
if (!isset($relationTypes[$class]))
{
continue;
}
if (!in_array($relationTypes[$class], array('hasOne', 'belongsTo')))
{
continue;
}
/** @var DataModel $relData */
$relData = $model->$relationName;
if (!($relData instanceof DataModel))
{
continue;
}
$modelType = get_class($relData);
if (in_array($modelType, $modelsProcessed))
{
continue;
}
$modelsProcessed[] = $modelType;
$relDataArray = $this->modelToBindSource($relData, $maxLevel, $modelsProcessed);
if (!is_array($relDataArray) || empty($relDataArray))
{
continue;
}
foreach ($relDataArray as $k => $v)
{
$data[$relationName . '.' . $k] = $v;
}
}
}
return $data;
}
}
FormField.php 0000644 00000055724 15234515367 0007154 0 ustar 00 <?php
/**
* Joomla! Content Management System
*
* @copyright (C) 2009 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\CMS\Form;
defined('JPATH_PLATFORM') or die;
use Joomla\CMS\Layout\FileLayout;
use Joomla\String\Normalise;
use Joomla\String\StringHelper;
/**
* Abstract Form Field class for the Joomla Platform.
*
* @since 1.7.0
*/
abstract class FormField
{
/**
* The description text for the form field. Usually used in tooltips.
*
* @var string
* @since 1.7.0
*/
protected $description;
/**
* The hint text for the form field used to display hint inside the field.
*
* @var string
* @since 3.2
*/
protected $hint;
/**
* The autocomplete state for the form field. If 'off' element will not be automatically
* completed by browser.
*
* @var mixed
* @since 3.2
*/
protected $autocomplete = 'on';
/**
* The spellcheck state for the form field.
*
* @var boolean
* @since 3.2
*/
protected $spellcheck = true;
/**
* The autofocus request for the form field. If true element will be automatically
* focused on document load.
*
* @var boolean
* @since 3.2
*/
protected $autofocus = false;
/**
* The SimpleXMLElement object of the `<field>` XML element that describes the form field.
*
* @var \SimpleXMLElement
* @since 1.7.0
*/
protected $element;
/**
* The Form object of the form attached to the form field.
*
* @var Form
* @since 1.7.0
*/
protected $form;
/**
* The form control prefix for field names from the JForm object attached to the form field.
*
* @var string
* @since 1.7.0
*/
protected $formControl;
/**
* The hidden state for the form field.
*
* @var boolean
* @since 1.7.0
*/
protected $hidden = false;
/**
* True to translate the field label string.
*
* @var boolean
* @since 1.7.0
*/
protected $translateLabel = true;
/**
* True to translate the field description string.
*
* @var boolean
* @since 1.7.0
*/
protected $translateDescription = true;
/**
* True to translate the field hint string.
*
* @var boolean
* @since 3.2
*/
protected $translateHint = true;
/**
* The document id for the form field.
*
* @var string
* @since 1.7.0
*/
protected $id;
/**
* The input for the form field.
*
* @var string
* @since 1.7.0
*/
protected $input;
/**
* The label for the form field.
*
* @var string
* @since 1.7.0
*/
protected $label;
/**
* The multiple state for the form field. If true then multiple values are allowed for the
* field. Most often used for list field types.
*
* @var boolean
* @since 1.7.0
*/
protected $multiple = false;
/**
* Allows extensions to create repeat elements
*
* @var mixed
* @since 3.2
*/
public $repeat = false;
/**
* The pattern (Reg Ex) of value of the form field.
*
* @var string
* @since 1.7.0
*/
protected $pattern;
/**
* The validation text of invalid value of the form field.
*
* @var string
* @since 4.0
*/
protected $validationtext;
/**
* The name of the form field.
*
* @var string
* @since 1.7.0
*/
protected $name;
/**
* The name of the field.
*
* @var string
* @since 1.7.0
*/
protected $fieldname;
/**
* The group of the field.
*
* @var string
* @since 1.7.0
*/
protected $group;
/**
* The required state for the form field. If true then there must be a value for the field to
* be considered valid.
*
* @var boolean
* @since 1.7.0
*/
protected $required = false;
/**
* The disabled state for the form field. If true then the field will be disabled and user can't
* interact with the field.
*
* @var boolean
* @since 3.2
*/
protected $disabled = false;
/**
* The readonly state for the form field. If true then the field will be readonly.
*
* @var boolean
* @since 3.2
*/
protected $readonly = false;
/**
* The form field type.
*
* @var string
* @since 1.7.0
*/
protected $type;
/**
* The validation method for the form field. This value will determine which method is used
* to validate the value for a field.
*
* @var string
* @since 1.7.0
*/
protected $validate;
/**
* The value of the form field.
*
* @var mixed
* @since 1.7.0
*/
protected $value;
/**
* The default value of the form field.
*
* @var mixed
* @since 1.7.0
*/
protected $default;
/**
* The size of the form field.
*
* @var integer
* @since 3.2
*/
protected $size;
/**
* The class of the form field
*
* @var mixed
* @since 3.2
*/
protected $class;
/**
* The label's CSS class of the form field
*
* @var mixed
* @since 1.7.0
*/
protected $labelclass;
/**
* The javascript onchange of the form field.
*
* @var string
* @since 3.2
*/
protected $onchange;
/**
* The javascript onclick of the form field.
*
* @var string
* @since 3.2
*/
protected $onclick;
/**
* The conditions to show/hide the field.
*
* @var string
* @since 3.7.0
*/
protected $showon;
/**
* The count value for generated name field
*
* @var integer
* @since 1.7.0
*/
protected static $count = 0;
/**
* The string used for generated fields names
*
* @var string
* @since 1.7.0
*/
protected static $generated_fieldname = '__field';
/**
* Name of the layout being used to render the field
*
* @var string
* @since 3.5
*/
protected $layout;
/**
* Layout to render the form field
*
* @var string
*/
protected $renderLayout = 'joomla.form.renderfield';
/**
* Layout to render the label
*
* @var string
*/
protected $renderLabelLayout = 'joomla.form.renderlabel';
/**
* Method to instantiate the form field object.
*
* @param Form $form The form to attach to the form field object.
*
* @since 1.7.0
*/
public function __construct($form = null)
{
// If there is a form passed into the constructor set the form and form control properties.
if ($form instanceof Form)
{
$this->form = $form;
$this->formControl = $form->getFormControl();
}
// Detect the field type if not set
if (!isset($this->type))
{
$parts = Normalise::fromCamelCase(get_called_class(), true);
if ($parts[0] == 'J')
{
$this->type = StringHelper::ucfirst($parts[count($parts) - 1], '_');
}
else
{
$this->type = StringHelper::ucfirst($parts[0], '_') . StringHelper::ucfirst($parts[count($parts) - 1], '_');
}
}
}
/**
* Method to get certain otherwise inaccessible properties from the form field object.
*
* @param string $name The property name for which to get the value.
*
* @return mixed The property value or null.
*
* @since 1.7.0
*/
public function __get($name)
{
switch ($name)
{
case 'description':
case 'hint':
case 'formControl':
case 'hidden':
case 'id':
case 'multiple':
case 'name':
case 'required':
case 'type':
case 'validate':
case 'value':
case 'class':
case 'layout':
case 'labelclass':
case 'size':
case 'onchange':
case 'onclick':
case 'fieldname':
case 'group':
case 'disabled':
case 'readonly':
case 'autofocus':
case 'autocomplete':
case 'spellcheck':
case 'validationtext':
case 'showon':
return $this->$name;
case 'input':
// If the input hasn't yet been generated, generate it.
if (empty($this->input))
{
$this->input = $this->getInput();
}
return $this->input;
case 'label':
// If the label hasn't yet been generated, generate it.
if (empty($this->label))
{
$this->label = $this->getLabel();
}
return $this->label;
case 'title':
return $this->getTitle();
}
return;
}
/**
* Method to set certain otherwise inaccessible properties of the form field object.
*
* @param string $name The property name for which to set the value.
* @param mixed $value The value of the property.
*
* @return void
*
* @since 3.2
*/
public function __set($name, $value)
{
switch ($name)
{
case 'class':
// Removes spaces from left & right and extra spaces from middle
$value = preg_replace('/\s+/', ' ', trim((string) $value));
case 'description':
case 'hint':
case 'value':
case 'labelclass':
case 'layout':
case 'onchange':
case 'onclick':
case 'validate':
case 'pattern':
case 'validationtext':
case 'group':
case 'showon':
case 'default':
$this->$name = (string) $value;
break;
case 'id':
$this->id = $this->getId((string) $value, $this->fieldname);
break;
case 'fieldname':
$this->fieldname = $this->getFieldName((string) $value);
break;
case 'name':
$this->fieldname = $this->getFieldName((string) $value);
$this->name = $this->getName($this->fieldname);
break;
case 'multiple':
// Allow for field classes to force the multiple values option.
$value = (string) $value;
$value = $value === '' && isset($this->forceMultiple) ? (string) $this->forceMultiple : $value;
case 'required':
case 'disabled':
case 'readonly':
case 'autofocus':
case 'hidden':
$value = (string) $value;
$this->$name = ($value === 'true' || $value === $name || $value === '1');
break;
case 'autocomplete':
$value = (string) $value;
$value = ($value == 'on' || $value == '') ? 'on' : $value;
$this->$name = ($value === 'false' || $value === 'off' || $value === '0') ? false : $value;
break;
case 'spellcheck':
case 'translateLabel':
case 'translateDescription':
case 'translateHint':
$value = (string) $value;
$this->$name = !($value === 'false' || $value === 'off' || $value === '0');
break;
case 'translate_label':
$value = (string) $value;
$this->translateLabel = $this->translateLabel && !($value === 'false' || $value === 'off' || $value === '0');
break;
case 'translate_description':
$value = (string) $value;
$this->translateDescription = $this->translateDescription && !($value === 'false' || $value === 'off' || $value === '0');
break;
case 'size':
$this->$name = (int) $value;
break;
default:
if (property_exists(__CLASS__, $name))
{
\JLog::add("Cannot access protected / private property $name of " . __CLASS__);
}
else
{
$this->$name = $value;
}
}
}
/**
* Method to attach a JForm object to the field.
*
* @param Form $form The JForm object to attach to the form field.
*
* @return FormField The form field object so that the method can be used in a chain.
*
* @since 1.7.0
*/
public function setForm(Form $form)
{
$this->form = $form;
$this->formControl = $form->getFormControl();
return $this;
}
/**
* Method to attach a JForm object to the field.
*
* @param \SimpleXMLElement $element The SimpleXMLElement object representing the `<field>` tag for the form field object.
* @param mixed $value The form field value to validate.
* @param string $group The field name group control value. This acts as as an array container for the field.
* For example if the field has name="foo" and the group value is set to "bar" then the
* full field name would end up being "bar[foo]".
*
* @return boolean True on success.
*
* @since 1.7.0
*/
public function setup(\SimpleXMLElement $element, $value, $group = null)
{
// Make sure there is a valid JFormField XML element.
if ((string) $element->getName() != 'field')
{
return false;
}
// Reset the input and label values.
$this->input = null;
$this->label = null;
// Set the XML element object.
$this->element = $element;
// Set the group of the field.
$this->group = $group;
$attributes = array(
'multiple', 'name', 'id', 'hint', 'class', 'description', 'labelclass', 'onchange', 'onclick', 'validate', 'pattern', 'validationtext', 'default',
'required', 'disabled', 'readonly', 'autofocus', 'hidden', 'autocomplete', 'spellcheck', 'translateHint', 'translateLabel',
'translate_label', 'translateDescription', 'translate_description', 'size', 'showon');
$this->default = isset($element['value']) ? (string) $element['value'] : $this->default;
// Set the field default value.
if ($element['multiple'] && is_string($value) && is_array(json_decode($value, true)))
{
$this->value = (array) json_decode($value);
}
else
{
$this->value = $value;
}
foreach ($attributes as $attributeName)
{
$this->__set($attributeName, $element[$attributeName]);
}
// Allow for repeatable elements
$repeat = (string) $element['repeat'];
$this->repeat = ($repeat == 'true' || $repeat == 'multiple' || (!empty($this->form->repeat) && $this->form->repeat == 1));
// Set the visibility.
$this->hidden = ($this->hidden || (string) $element['type'] == 'hidden');
$this->layout = !empty($this->element['layout']) ? (string) $this->element['layout'] : $this->layout;
// Add required to class list if field is required.
if ($this->required)
{
$this->class = trim($this->class . ' required');
}
return true;
}
/**
* Simple method to set the value
*
* @param mixed $value Value to set
*
* @return void
*
* @since 3.2
*/
public function setValue($value)
{
$this->value = $value;
}
/**
* Method to get the id used for the field input tag.
*
* @param string $fieldId The field element id.
* @param string $fieldName The field element name.
*
* @return string The id to be used for the field input tag.
*
* @since 1.7.0
*/
protected function getId($fieldId, $fieldName)
{
$id = '';
// If there is a form control set for the attached form add it first.
if ($this->formControl)
{
$id .= $this->formControl;
}
// If the field is in a group add the group control to the field id.
if ($this->group)
{
// If we already have an id segment add the group control as another level.
if ($id)
{
$id .= '_' . str_replace('.', '_', $this->group);
}
else
{
$id .= str_replace('.', '_', $this->group);
}
}
// If we already have an id segment add the field id/name as another level.
if ($id)
{
$id .= '_' . ($fieldId ? $fieldId : $fieldName);
}
else
{
$id .= ($fieldId ? $fieldId : $fieldName);
}
// Clean up any invalid characters.
$id = preg_replace('#\W#', '_', $id);
// If this is a repeatable element, add the repeat count to the ID
if ($this->repeat)
{
$repeatCounter = empty($this->form->repeatCounter) ? 0 : $this->form->repeatCounter;
$id .= '-' . $repeatCounter;
if (strtolower($this->type) == 'radio')
{
$id .= '-';
}
}
return $id;
}
/**
* Method to get the field input markup.
*
* @return string The field input markup.
*
* @since 1.7.0
*/
protected function getInput()
{
if (empty($this->layout))
{
throw new \UnexpectedValueException(sprintf('%s has no layout assigned.', $this->name));
}
return $this->getRenderer($this->layout)->render($this->getLayoutData());
}
/**
* Method to get the field title.
*
* @return string The field title.
*
* @since 1.7.0
*/
protected function getTitle()
{
$title = '';
if ($this->hidden)
{
return $title;
}
// Get the label text from the XML element, defaulting to the element name.
$title = $this->element['label'] ? (string) $this->element['label'] : (string) $this->element['name'];
$title = $this->translateLabel ? \JText::_($title) : $title;
return $title;
}
/**
* Method to get the field label markup.
*
* @return string The field label markup.
*
* @since 1.7.0
*/
protected function getLabel()
{
if ($this->hidden)
{
return '';
}
$data = $this->getLayoutData();
// Forcing the Alias field to display the tip below
$position = $this->element['name'] == 'alias' ? ' data-placement="bottom" ' : '';
// Here mainly for B/C with old layouts. This can be done in the layouts directly
$extraData = array(
'text' => $data['label'],
'for' => $this->id,
'classes' => explode(' ', $data['labelclass']),
'position' => $position,
);
return $this->getRenderer($this->renderLabelLayout)->render(array_merge($data, $extraData));
}
/**
* Method to get the name used for the field input tag.
*
* @param string $fieldName The field element name.
*
* @return string The name to be used for the field input tag.
*
* @since 1.7.0
*/
protected function getName($fieldName)
{
// To support repeated element, extensions can set this in plugin->onRenderSettings
$name = '';
// If there is a form control set for the attached form add it first.
if ($this->formControl)
{
$name .= $this->formControl;
}
// If the field is in a group add the group control to the field name.
if ($this->group)
{
// If we already have a name segment add the group control as another level.
$groups = explode('.', $this->group);
if ($name)
{
foreach ($groups as $group)
{
$name .= '[' . $group . ']';
}
}
else
{
$name .= array_shift($groups);
foreach ($groups as $group)
{
$name .= '[' . $group . ']';
}
}
}
// If we already have a name segment add the field name as another level.
if ($name)
{
$name .= '[' . $fieldName . ']';
}
else
{
$name .= $fieldName;
}
// If the field should support multiple values add the final array segment.
if ($this->multiple)
{
switch (strtolower((string) $this->element['type']))
{
case 'text':
case 'textarea':
case 'email':
case 'password':
case 'radio':
case 'calendar':
case 'editor':
case 'hidden':
break;
default:
$name .= '[]';
}
}
return $name;
}
/**
* Method to get the field name used.
*
* @param string $fieldName The field element name.
*
* @return string The field name
*
* @since 1.7.0
*/
protected function getFieldName($fieldName)
{
if ($fieldName)
{
return $fieldName;
}
else
{
self::$count = self::$count + 1;
return self::$generated_fieldname . self::$count;
}
}
/**
* Method to get an attribute of the field
*
* @param string $name Name of the attribute to get
* @param mixed $default Optional value to return if attribute not found
*
* @return mixed Value of the attribute / default
*
* @since 3.2
*/
public function getAttribute($name, $default = null)
{
if ($this->element instanceof \SimpleXMLElement)
{
$attributes = $this->element->attributes();
// Ensure that the attribute exists
if ($attributes->$name !== null)
{
return (string) $attributes->$name;
}
}
return $default;
}
/**
* Method to get a control group with label and input.
*
* @return string A string containing the html for the control group
*
* @since 3.2
* @deprecated 3.2.3 Use renderField() instead
*/
public function getControlGroup()
{
\JLog::add('FormField->getControlGroup() is deprecated use FormField->renderField().', \JLog::WARNING, 'deprecated');
return $this->renderField();
}
/**
* Render a layout of this field
*
* @param string $layoutId Layout identifier
* @param array $data Optional data for the layout
*
* @return string
*
* @since 3.5
*/
public function render($layoutId, $data = array())
{
$data = array_merge($this->getLayoutData(), $data);
return $this->getRenderer($layoutId)->render($data);
}
/**
* Method to get a control group with label and input.
*
* @param array $options Options to be passed into the rendering of the field
*
* @return string A string containing the html for the control group
*
* @since 3.2
*/
public function renderField($options = array())
{
if ($this->hidden)
{
return $this->getInput();
}
if (!isset($options['class']))
{
$options['class'] = '';
}
$options['rel'] = '';
if (empty($options['hiddenLabel']) && $this->getAttribute('hiddenLabel'))
{
$options['hiddenLabel'] = true;
}
if ($this->showon)
{
$options['rel'] = ' data-showon=\'' .
json_encode(FormHelper::parseShowOnConditions($this->showon, $this->formControl, $this->group)) . '\'';
$options['showonEnabled'] = true;
}
$data = array(
'input' => $this->getInput(),
'label' => $this->getLabel(),
'options' => $options,
);
return $this->getRenderer($this->renderLayout)->render($data);
}
/**
* Method to get the data to be passed to the layout for rendering.
*
* @return array
*
* @since 3.5
*/
protected function getLayoutData()
{
// Label preprocess
$label = $this->element['label'] ? (string) $this->element['label'] : (string) $this->element['name'];
$label = $this->translateLabel ? \JText::_($label) : $label;
// Description preprocess
$description = !empty($this->description) ? $this->description : null;
$description = !empty($description) && $this->translateDescription ? \JText::_($description) : $description;
$alt = preg_replace('/[^a-zA-Z0-9_\-]/', '_', $this->fieldname);
return array(
'autocomplete' => $this->autocomplete,
'autofocus' => $this->autofocus,
'class' => $this->class,
'description' => $description,
'disabled' => $this->disabled,
'field' => $this,
'group' => $this->group,
'hidden' => $this->hidden,
'hint' => $this->translateHint ? \JText::alt($this->hint, $alt) : $this->hint,
'id' => $this->id,
'label' => $label,
'labelclass' => $this->labelclass,
'multiple' => $this->multiple,
'name' => $this->name,
'onchange' => $this->onchange,
'onclick' => $this->onclick,
'pattern' => $this->pattern,
'validationtext' => $this->validationtext,
'readonly' => $this->readonly,
'repeat' => $this->repeat,
'required' => (bool) $this->required,
'size' => $this->size,
'spellcheck' => $this->spellcheck,
'validate' => $this->validate,
'value' => $this->value,
);
}
/**
* Allow to override renderer include paths in child fields
*
* @return array
*
* @since 3.5
*/
protected function getLayoutPaths()
{
$renderer = new FileLayout('default');
return $renderer->getDefaultIncludePaths();
}
/**
* Get the renderer
*
* @param string $layoutId Id to load
*
* @return FileLayout
*
* @since 3.5
*/
protected function getRenderer($layoutId = 'default')
{
$renderer = new FileLayout($layoutId);
$renderer->setDebug($this->isDebugEnabled());
$layoutPaths = $this->getLayoutPaths();
if ($layoutPaths)
{
$renderer->setIncludePaths($layoutPaths);
}
return $renderer;
}
/**
* Is debug enabled for this field
*
* @return boolean
*
* @since 3.5
*/
protected function isDebugEnabled()
{
return $this->getAttribute('debug', 'false') === 'true';
}
}
FormHelper.php 0000644 00000031506 15234515367 0007340 0 ustar 00 <?php
/**
* Joomla! Content Management System
*
* @copyright (C) 2010 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\CMS\Form;
defined('JPATH_PLATFORM') or die;
use Joomla\String\Normalise;
use Joomla\String\StringHelper;
\JLoader::import('joomla.filesystem.path');
/**
* Form's helper class.
* Provides a storage for filesystem's paths where Form's entities reside and methods for creating those entities.
* Also stores objects with entities' prototypes for further reusing.
*
* @since 1.7.0
*/
class FormHelper
{
/**
* Array with paths where entities(field, rule, form) can be found.
*
* Array's structure:
*
* paths:
* {ENTITY_NAME}:
* - /path/1
* - /path/2
*
* @var array
* @since 1.7.0
*/
protected static $paths;
/**
* The class namespaces.
*
* @var string
* @since 3.8.0
*/
protected static $prefixes = array('field' => array(), 'form' => array(), 'rule' => array());
/**
* Static array of Form's entity objects for re-use.
* Prototypes for all fields and rules are here.
*
* Array's structure:
* entities:
* {ENTITY_NAME}:
* {KEY}: {OBJECT}
*
* @var array
* @since 1.7.0
*/
protected static $entities = array('field' => array(), 'form' => array(), 'rule' => array());
/**
* Method to load a form field object given a type.
*
* @param string $type The field type.
* @param boolean $new Flag to toggle whether we should get a new instance of the object.
*
* @return FormField|boolean FormField object on success, false otherwise.
*
* @since 1.7.0
*/
public static function loadFieldType($type, $new = true)
{
return self::loadType('field', $type, $new);
}
/**
* Method to load a form rule object given a type.
*
* @param string $type The rule type.
* @param boolean $new Flag to toggle whether we should get a new instance of the object.
*
* @return FormRule|boolean FormRule object on success, false otherwise.
*
* @since 1.7.0
*/
public static function loadRuleType($type, $new = true)
{
return self::loadType('rule', $type, $new);
}
/**
* Method to load a form entity object given a type.
* Each type is loaded only once and then used as a prototype for other objects of same type.
* Please, use this method only with those entities which support types (forms don't support them).
*
* @param string $entity The entity.
* @param string $type The entity type.
* @param boolean $new Flag to toggle whether we should get a new instance of the object.
*
* @return mixed Entity object on success, false otherwise.
*
* @since 1.7.0
*/
protected static function loadType($entity, $type, $new = true)
{
// Reference to an array with current entity's type instances
$types = &self::$entities[$entity];
$key = md5($type);
// Return an entity object if it already exists and we don't need a new one.
if (isset($types[$key]) && $new === false)
{
return $types[$key];
}
$class = self::loadClass($entity, $type);
if ($class === false)
{
return false;
}
// Instantiate a new type object.
$types[$key] = new $class;
return $types[$key];
}
/**
* Attempt to import the JFormField class file if it isn't already imported.
* You can use this method outside of JForm for loading a field for inheritance or composition.
*
* @param string $type Type of a field whose class should be loaded.
*
* @return string|boolean Class name on success or false otherwise.
*
* @since 1.7.0
*/
public static function loadFieldClass($type)
{
return self::loadClass('field', $type);
}
/**
* Attempt to import the JFormRule class file if it isn't already imported.
* You can use this method outside of JForm for loading a rule for inheritance or composition.
*
* @param string $type Type of a rule whose class should be loaded.
*
* @return string|boolean Class name on success or false otherwise.
*
* @since 1.7.0
*/
public static function loadRuleClass($type)
{
return self::loadClass('rule', $type);
}
/**
* Load a class for one of the form's entities of a particular type.
* Currently, it makes sense to use this method for the "field" and "rule" entities
* (but you can support more entities in your subclass).
*
* @param string $entity One of the form entities (field or rule).
* @param string $type Type of an entity.
*
* @return string|boolean Class name on success or false otherwise.
*
* @since 1.7.0
*/
protected static function loadClass($entity, $type)
{
// Check if there is a class in the registered namespaces
foreach (self::addPrefix($entity) as $prefix)
{
// Treat underscores as namespace
$name = Normalise::toSpaceSeparated($type);
$name = str_ireplace(' ', '\\', ucwords($name));
// Compile the classname
$class = rtrim($prefix, '\\') . '\\' . ucfirst($name) . ucfirst($entity);
// Check if the class exists
if (class_exists($class))
{
return $class;
}
}
$prefix = 'J';
if (strpos($type, '.'))
{
list($prefix, $type) = explode('.', $type);
}
$class = StringHelper::ucfirst($prefix, '_') . 'Form' . StringHelper::ucfirst($entity, '_') . StringHelper::ucfirst($type, '_');
if (class_exists($class))
{
return $class;
}
// Get the field search path array.
$paths = self::addPath($entity);
// If the type is complex, add the base type to the paths.
if ($pos = strpos($type, '_'))
{
// Add the complex type prefix to the paths.
for ($i = 0, $n = count($paths); $i < $n; $i++)
{
// Derive the new path.
$path = $paths[$i] . '/' . strtolower(substr($type, 0, $pos));
// If the path does not exist, add it.
if (!in_array($path, $paths))
{
$paths[] = $path;
}
}
// Break off the end of the complex type.
$type = substr($type, $pos + 1);
}
// Try to find the class file.
$type = strtolower($type) . '.php';
foreach ($paths as $path)
{
$file = \JPath::find($path, $type);
if (!$file)
{
continue;
}
require_once $file;
if (class_exists($class))
{
break;
}
}
// Check for all if the class exists.
return class_exists($class) ? $class : false;
}
/**
* Method to add a path to the list of field include paths.
*
* @param mixed $new A path or array of paths to add.
*
* @return array The list of paths that have been added.
*
* @since 1.7.0
*/
public static function addFieldPath($new = null)
{
return self::addPath('field', $new);
}
/**
* Method to add a path to the list of form include paths.
*
* @param mixed $new A path or array of paths to add.
*
* @return array The list of paths that have been added.
*
* @since 1.7.0
*/
public static function addFormPath($new = null)
{
return self::addPath('form', $new);
}
/**
* Method to add a path to the list of rule include paths.
*
* @param mixed $new A path or array of paths to add.
*
* @return array The list of paths that have been added.
*
* @since 1.7.0
*/
public static function addRulePath($new = null)
{
return self::addPath('rule', $new);
}
/**
* Method to add a path to the list of include paths for one of the form's entities.
* Currently supported entities: field, rule and form. You are free to support your own in a subclass.
*
* @param string $entity Form's entity name for which paths will be added.
* @param mixed $new A path or array of paths to add.
*
* @return array The list of paths that have been added.
*
* @since 1.7.0
*/
protected static function addPath($entity, $new = null)
{
// Reference to an array with paths for current entity
$paths = &self::$paths[$entity];
// Add the default entity's search path if not set.
if (empty($paths))
{
// While we support limited number of entities (form, field and rule)
// we can do this simple pluralisation:
$entity_plural = $entity . 's';
/*
* But when someday we would want to support more entities, then we should consider adding
* an inflector class to "libraries/joomla/utilities" and use it here (or somebody can use a real inflector in his subclass).
* See also: pluralization snippet by Paul Osman in JControllerForm's constructor.
*/
$paths[] = __DIR__ . '/' . $entity_plural;
}
// Force the new path(s) to an array.
settype($new, 'array');
// Add the new paths to the stack if not already there.
foreach ($new as $path)
{
$path = trim($path);
if (!in_array($path, $paths))
{
array_unshift($paths, $path);
}
}
return $paths;
}
/**
* Method to add a namespace prefix to the list of field lookups.
*
* @param mixed $new A namespaces or array of namespaces to add.
*
* @return array The list of namespaces that have been added.
*
* @since 3.8.0
*/
public static function addFieldPrefix($new = null)
{
return self::addPrefix('field', $new);
}
/**
* Method to add a namespace to the list of form lookups.
*
* @param mixed $new A namespace or array of namespaces to add.
*
* @return array The list of namespaces that have been added.
*
* @since 3.8.0
*/
public static function addFormPrefix($new = null)
{
return self::addPrefix('form', $new);
}
/**
* Method to add a namespace to the list of rule lookups.
*
* @param mixed $new A namespace or array of namespaces to add.
*
* @return array The list of namespaces that have been added.
*
* @since 3.8.0
*/
public static function addRulePrefix($new = null)
{
return self::addPrefix('rule', $new);
}
/**
* Method to add a namespace to the list of namespaces for one of the form's entities.
* Currently supported entities: field, rule and form. You are free to support your own in a subclass.
*
* @param string $entity Form's entity name for which paths will be added.
* @param mixed $new A namespace or array of namespaces to add.
*
* @return array The list of namespaces that have been added.
*
* @since 3.8.0
*/
protected static function addPrefix($entity, $new = null)
{
// Reference to an array with namespaces for current entity
$prefixes = &self::$prefixes[$entity];
// Add the default entity's search namespace if not set.
if (empty($prefixes))
{
$prefixes[] = __NAMESPACE__ . '\\' . ucfirst($entity);
}
// Force the new namespace(s) to an array.
settype($new, 'array');
// Add the new paths to the stack if not already there.
foreach ($new as $prefix)
{
$prefix = trim($prefix);
if (in_array($prefix, $prefixes))
{
continue;
}
array_unshift($prefixes, $prefix);
}
return $prefixes;
}
/**
* Parse the show on conditions
*
* @param string $showOn Show on conditions.
* @param string $formControl Form name.
* @param string $group The dot-separated form group path.
*
* @return array Array with show on conditions.
*
* @since 3.7.0
*/
public static function parseShowOnConditions($showOn, $formControl = null, $group = null)
{
// Process the showon data.
if (!$showOn)
{
return array();
}
$formPath = $formControl ?: '';
if ($group)
{
$groups = explode('.', $group);
// An empty formControl leads to invalid shown property
// Use the 1st part of the group instead to avoid.
if (empty($formPath) && isset($groups[0]))
{
$formPath = $groups[0];
array_shift($groups);
}
foreach ($groups as $group)
{
$formPath .= '[' . $group . ']';
}
}
$showOnData = array();
$showOnParts = preg_split('#(\[AND\]|\[OR\])#', $showOn, -1, PREG_SPLIT_DELIM_CAPTURE);
$op = '';
foreach ($showOnParts as $showOnPart)
{
if (($showOnPart === '[AND]') || $showOnPart === '[OR]')
{
$op = trim($showOnPart, '[]');
continue;
}
$compareEqual = strpos($showOnPart, '!:') === false;
$showOnPartBlocks = explode(($compareEqual ? ':' : '!:'), $showOnPart, 2);
$dotPos = strpos($showOnPartBlocks[0], '.');
if ($dotPos === false)
{
$field = $formPath ? $formPath . '[' . $showOnPartBlocks[0] . ']' : $showOnPartBlocks[0];
}
else
{
if ($dotPos === 0)
{
$fieldName = substr($showOnPartBlocks[0], 1);
$field = $formControl ? $formControl . '[' . $fieldName . ']' : $fieldName;
}
else
{
if ($formControl)
{
$field = $formControl . ('[' . str_replace('.', '][', $showOnPartBlocks[0]) . ']');
}
else
{
$groupParts = explode('.', $showOnPartBlocks[0]);
$field = array_shift($groupParts) . '[' . join('][', $groupParts) . ']';
}
}
}
$showOnData[] = array(
'field' => $field,
'values' => explode(',', $showOnPartBlocks[1]),
'sign' => $compareEqual === true ? '=' : '!=',
'op' => $op,
);
if ($op !== '')
{
$op = '';
}
}
return $showOnData;
}
}
FormRule.php 0000644 00000005024 15234515367 0007024 0 ustar 00 <?php
/**
* Joomla! Content Management System
*
* @copyright (C) 2017 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\CMS\Form;
defined('JPATH_PLATFORM') or die;
use Joomla\Registry\Registry;
// Detect if we have full UTF-8 and unicode PCRE support.
if (!defined('JCOMPAT_UNICODE_PROPERTIES'))
{
/**
* Flag indicating UTF-8 and PCRE support is present
*
* @var boolean
* @since 1.6
*/
define('JCOMPAT_UNICODE_PROPERTIES', (bool) @preg_match('/\pL/u', 'a'));
}
/**
* Form Rule class for the Joomla Platform.
*
* @since 1.6
*/
class FormRule
{
/**
* The regular expression to use in testing a form field value.
*
* @var string
* @since 1.6
*/
protected $regex;
/**
* The regular expression modifiers to use when testing a form field value.
*
* @var string
* @since 1.6
*/
protected $modifiers;
/**
* Method to test the value.
*
* @param \SimpleXMLElement $element The SimpleXMLElement object representing the `<field>` tag for the form field object.
* @param mixed $value The form field value to validate.
* @param string $group The field name group control value. This acts as as an array container for the field.
* For example if the field has name="foo" and the group value is set to "bar" then the
* full field name would end up being "bar[foo]".
* @param Registry $input An optional Registry object with the entire data set to validate against the entire form.
* @param Form $form The form object for which the field is being tested.
*
* @return boolean True if the value is valid, false otherwise.
*
* @since 1.6
* @throws \UnexpectedValueException if rule is invalid.
*/
public function test(\SimpleXMLElement $element, $value, $group = null, Registry $input = null, Form $form = null)
{
// Check for a valid regex.
if (empty($this->regex))
{
throw new \UnexpectedValueException(sprintf('%s has invalid regex.', get_class($this)));
}
// Add unicode property support if available.
if (JCOMPAT_UNICODE_PROPERTIES)
{
$this->modifiers = (strpos($this->modifiers, 'u') !== false) ? $this->modifiers : $this->modifiers . 'u';
}
// Test the value against the regular expression.
if (preg_match(chr(1) . $this->regex . chr(1) . $this->modifiers, $value))
{
return true;
}
return false;
}
}
FormWrapper.php 0000644 00000006543 15234515367 0007544 0 ustar 00 <?php
/**
* Joomla! Content Management System
*
* @copyright (C) 2014 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\CMS\Form;
defined('JPATH_PLATFORM') or die;
/**
* Wrapper class for FormHelper
*
* @since 3.4
* @deprecated 4.0 Use `Joomla\CMS\Form\FormHelper` directly
*/
class FormWrapper
{
/**
* Helper wrapper method for loadFieldType
*
* @param string $type The field type.
* @param boolean $new Flag to toggle whether we should get a new instance of the object.
*
* @return mixed JFormField object on success, false otherwise.
*
* @see FormHelper::loadFieldType()
* @since 3.4
* @deprecated 4.0 Use `Joomla\CMS\Form\FormHelper` directly
*/
public function loadFieldType($type, $new = true)
{
return FormHelper::loadFieldType($type, $new);
}
/**
* Helper wrapper method for loadRuleType
*
* @param string $type The field type.
* @param boolean $new Flag to toggle whether we should get a new instance of the object.
*
* @return mixed JFormField object on success, false otherwise.
*
* @see FormHelper::loadRuleType()
* @since 3.4
* @deprecated 4.0 Use `Joomla\CMS\Form\FormHelper` directly
*/
public function loadRuleType($type, $new = true)
{
return FormHelper::loadRuleType($type, $new);
}
/**
* Helper wrapper method for loadFieldClass
*
* @param string $type Type of a field whose class should be loaded.
*
* @return mixed Class name on success or false otherwise.
*
* @see FormHelper::loadFieldClass()
* @since 3.4
* @deprecated 4.0 Use `Joomla\CMS\Form\FormHelper` directly
*/
public function loadFieldClass($type)
{
return FormHelper::loadFieldClass($type);
}
/**
* Helper wrapper method for loadRuleClass
*
* @param string $type Type of a rule whose class should be loaded.
*
* @return mixed Class name on success or false otherwise.
*
* @see FormHelper::loadRuleClass()
* @since 3.4
* @deprecated 4.0 Use `Joomla\CMS\Form\FormHelper` directly
*/
public function loadRuleClass($type)
{
return FormHelper::loadRuleClass($type);
}
/**
* Helper wrapper method for addFieldPath
*
* @param mixed $new A path or array of paths to add.
*
* @return array The list of paths that have been added.
*
* @see FormHelper::addFieldPath()
* @since 3.4
* @deprecated 4.0 Use `Joomla\CMS\Form\FormHelper` directly
*/
public function addFieldPath($new = null)
{
return FormHelper::addFieldPath($new);
}
/**
* Helper wrapper method for addFormPath
*
* @param mixed $new A path or array of paths to add.
*
* @return array The list of paths that have been added.
*
* @see FormHelper::addFormPath()
* @since 3.4
* @deprecated 4.0 Use `Joomla\CMS\Form\FormHelper` directly
*/
public function addFormPath($new = null)
{
return FormHelper::addFormPath($new);
}
/**
* Helper wrapper method for addRulePath
*
* @param mixed $new A path or array of paths to add.
*
* @return array The list of paths that have been added.
*
* @see FormHelper::addRulePath()
* @since 3.4
* @deprecated 4.0 Use `Joomla\CMS\Form\FormHelper` directly
*/
public function addRulePath($new = null)
{
return FormHelper::addRulePath($new);
}
}
FieldInterface.php 0000644 00000005251 15235405654 0010135 0 ustar 00 <?php
/**
* @package FOF
* @copyright Copyright (c)2010-2019 Nicholas K. Dionysopoulos / Akeeba Ltd
* @license GNU GPL version 2 or later
*/
namespace FOF30\Form;
defined('_JEXEC') or die;
/**
* Generic interface that a FOF form field class must implement
*
* @deprecated 3.1 Support for XML forms will be removed in FOF 4
*/
interface FieldInterface
{
/**
* Method to attach a JForm object to the field. Actually, we need a FOF Form object but there's no way to provide
* that type hint without issuing a string standards notice in PHP :(
*
* @param Form $form The JForm object to attach to the form field.
*
* @return FieldInterface The form field object so that the method can be used in a chain.
*/
public function setForm(\JForm $form);
/**
* Method to attach a Form object to the field.
*
* @param \SimpleXMLElement $element The SimpleXMLElement object representing the <field /> tag for the form field object.
* @param mixed $value The form field value to validate.
* @param string $group The field name group control value. This acts as as an array container for the field.
* For example if the field has name="foo" and the group value is set to "bar" then the
* full field name would end up being "bar[foo]".
*
* @return boolean True on success.
*/
public function setup(\SimpleXMLElement $element, $value, $group = null);
/**
* Simple method to set the value
*
* @param mixed $value Value to set
*
* @return void
*/
public function setValue($value);
/**
* Method to get an attribute of the field
*
* @param string $name Name of the attribute to get
* @param mixed $default Optional value to return if attribute not found
*
* @return mixed Value of the attribute / default
*/
public function getAttribute($name, $default = null);
/**
* Method to get a control group with label and input.
*
* @param array $options Options to be passed into the rendering of the field
*
* @return string A string containing the html for the control group
*/
public function renderField($options = array());
/**
* Get the rendering of this field type for static display, e.g. in a single
* item view (typically a "read" task).
*
* @return string The field HTML
*
* @since 2.0
*/
public function getStatic();
/**
* Get the rendering of this field type for a repeatable (grid) display,
* e.g. in a view listing many item (typically a "browse" task)
*
* @return string The field HTML
*
* @since 2.0
*/
public function getRepeatable();
}
HeaderInterface.php 0000644 00000002455 15235405654 0010305 0 ustar 00 <?php
/**
* @package FOF
* @copyright Copyright (c)2010-2019 Nicholas K. Dionysopoulos / Akeeba Ltd
* @license GNU GPL version 2 or later
*/
namespace FOF30\Form;
defined('_JEXEC') or die;
/**
* Generic interface that a FOF header field class must implement
*
* @deprecated 3.1 Support for XML forms will be removed in FOF 4
*/
interface HeaderInterface
{
/**
* Method to attach a Form object to the header.
*
* @param Form $form The Form object to attach to the form field.
*
* @return HeaderInterface The form field object so that the method can be used in a chain.
*
* @since 2.0
*/
public function setForm(Form $form);
/**
* Method to attach a Form object to the header.
*
* @param \SimpleXMLElement $element The SimpleXMLElement object representing the <header /> tag for the form header object.
* @param string $group The header name group control value. This acts as as an array container for the header.
* For example if the header has name="foo" and the group value is set to "bar" then the
* full header name would end up being "bar[foo]".
*
* @return boolean True on success.
*/
public function setup(\SimpleXMLElement $element, $group = null);
}
Exception/GetStaticNotAllowed.php 0000644 00000001205 15235405654 0013102 0 ustar 00 <?php
/**
* @package FOF
* @copyright Copyright (c)2010-2019 Nicholas K. Dionysopoulos / Akeeba Ltd
* @license GNU GPL version 2 or later
*/
namespace FOF30\Form\Exception;
use Exception;
defined('_JEXEC') or die;
/**
* Class GetStaticNotAllowed
* @package FOF30\Form\Exception
* @deprecated 3.1 Support for XML forms will be removed in FOF 4
*/
class GetStaticNotAllowed extends \LogicException
{
public function __construct($className, $code = 0, Exception $previous = null)
{
$message = \JText::sprintf('LIB_FOF_FORM_ERR_GETSTATIC_NOT_ALLOWED', $className);
parent::__construct($message, $code, $previous);
}
}
Exception/DataModelRequired.php 0000644 00000001206 15235405654 0012556 0 ustar 00 <?php
/**
* @package FOF
* @copyright Copyright (c)2010-2019 Nicholas K. Dionysopoulos / Akeeba Ltd
* @license GNU GPL version 2 or later
*/
namespace FOF30\Form\Exception;
use Exception;
defined('_JEXEC') or die;
/**
* Class DataModelRequired
* @package FOF30\Form\Exception
*
* @deprecated 3.1 Support for XML forms will be removed in FOF 4
*/
class DataModelRequired extends \RuntimeException
{
public function __construct($className, $code = 0, Exception $previous = null)
{
$message = \JText::sprintf('LIB_FOF_FORM_ERR_DATAMODEL_REQUIRED', $className);
parent::__construct($message, $code, $previous);
}
}
Exception/InvalidGroupContents.php 0000644 00000001235 15235405654 0013346 0 ustar 00 <?php
/**
* @package FOF
* @copyright Copyright (c)2010-2019 Nicholas K. Dionysopoulos / Akeeba Ltd
* @license GNU GPL version 2 or later
*/
namespace FOF30\Form\Exception;
use Exception;
defined('_JEXEC') or die;
/**
* Class InvalidGroupContents
* @package FOF30\Form\Exception
* @deprecated 3.1 Support for XML forms will be removed in FOF 4
*/
class InvalidGroupContents extends \InvalidArgumentException
{
public function __construct($className, $code = 1, Exception $previous = null)
{
$message = \JText::sprintf('LIB_FOF_FORM_ERR_GETOPTIONS_INVALID_GROUP_CONTENTS', $className);
parent::__construct($message, $code, $previous);
}
}
Exception/GetInputNotAllowed.php 0000644 00000001205 15235405654 0012752 0 ustar 00 <?php
/**
* @package FOF
* @copyright Copyright (c)2010-2019 Nicholas K. Dionysopoulos / Akeeba Ltd
* @license GNU GPL version 2 or later
*/
namespace FOF30\Form\Exception;
use Exception;
defined('_JEXEC') or die;
/**
* Class GetInputNotAllowed
* @package FOF30\Form\Exception
* @deprecated 3.1 Support for XML forms will be removed in FOF 4
*/
class GetInputNotAllowed extends \LogicException
{
public function __construct($className, $code = 0, Exception $previous = null)
{
$message = \JText::sprintf('LIB_FOF_FORM_ERR_GETINPUT_NOT_ALLOWED', $className);
parent::__construct($message, $code, $previous);
}
}
Field/Password.php 0000644 00000006003 15235405654 0010112 0 ustar 00 <?php
/**
* @package FOF
* @copyright Copyright (c)2010-2019 Nicholas K. Dionysopoulos / Akeeba Ltd
* @license GNU GPL version 2 or later
*/
namespace FOF30\Form\Field;
use FOF30\Form\FieldInterface;
use FOF30\Form\Form;
use FOF30\Model\DataModel;
defined('_JEXEC') or die;
\JFormHelper::loadFieldClass('password');
/**
* Form Field class for the FOF framework
* Supports a one line text field.
*
* @deprecated 3.1 Support for XML forms will be removed in FOF 4
*/
class Password extends \JFormFieldPassword implements FieldInterface
{
/**
* @var string Static field output
*/
protected $static;
/**
* @var string Repeatable field output
*/
protected $repeatable;
/**
* The Form object of the form attached to the form field.
*
* @var Form
*/
protected $form;
/**
* A monotonically increasing number, denoting the row number in a repeatable view
*
* @var int
*/
public $rowid;
/**
* The item being rendered in a repeatable form field
*
* @var DataModel
*/
public $item;
/**
* Method to get certain otherwise inaccessible properties from the form field object.
*
* @param string $name The property name for which to the the value.
*
* @return mixed The property value or null.
*
* @since 2.0
*/
public function __get($name)
{
switch ($name)
{
case 'static':
if (empty($this->static))
{
$this->static = $this->getStatic();
}
return $this->static;
break;
case 'repeatable':
if (empty($this->repeatable))
{
$this->repeatable = $this->getRepeatable();
}
return $this->repeatable;
break;
default:
return parent::__get($name);
}
}
/**
* Get the rendering of this field type for static display, e.g. in a single
* item view (typically a "read" task).
*
* @since 2.0
*
* @return string The field HTML
*/
public function getStatic()
{
if (isset($this->element['legacy']))
{
return $this->getInput();
}
$options = array(
'id' => $this->id
);
return $this->getFieldContents($options);
}
/**
* 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
*/
public function getRepeatable()
{
if (isset($this->element['legacy']))
{
return $this->getInput();
}
$options = array(
'class' => $this->id
);
return $this->getFieldContents($options);
}
/**
* 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'] : '');
return '<span ' . ($id ? $id : '') . 'class="' . $class . '">' .
htmlspecialchars($this->value, ENT_COMPAT, 'UTF-8') .
'</span>';
}
}
Field/Plugins.php 0000644 00000006041 15235405654 0007733 0 ustar 00 <?php
/**
* @package FOF
* @copyright Copyright (c)2010-2019 Nicholas K. Dionysopoulos / Akeeba Ltd
* @license GNU GPL version 2 or later
*/
namespace FOF30\Form\Field;
use FOF30\Form\FieldInterface;
use FOF30\Form\Form;
use FOF30\Model\DataModel;
defined('_JEXEC') or die;
\JFormHelper::loadFieldClass('plugins');
/**
* Form Field class for FOF
* Plugins installed on the site
*
* @deprecated 3.1 Support for XML forms will be removed in FOF 4
*/
class Plugins extends \JFormFieldPlugins implements FieldInterface
{
/**
* @var string Static field output
*/
protected $static;
/**
* @var string Repeatable field output
*/
protected $repeatable;
/**
* The Form object of the form attached to the form field.
*
* @var Form
*/
protected $form;
/**
* A monotonically increasing number, denoting the row number in a repeatable view
*
* @var int
*/
public $rowid;
/**
* The item being rendered in a repeatable form field
*
* @var DataModel
*/
public $item;
/**
* Method to get certain otherwise inaccessible properties from the form field object.
*
* @param string $name The property name for which to the the value.
*
* @return mixed The property value or null.
*
* @since 2.0
*/
public function __get($name)
{
switch ($name)
{
case 'static':
if (empty($this->static))
{
$this->static = $this->getStatic();
}
return $this->static;
break;
case 'repeatable':
if (empty($this->repeatable))
{
$this->repeatable = $this->getRepeatable();
}
return $this->repeatable;
break;
default:
return parent::__get($name);
}
}
/**
* Get the rendering of this field type for static display, e.g. in a single
* item view (typically a "read" task).
*
* @since 2.0
*
* @return string The field HTML
*/
public function getStatic()
{
if (isset($this->element['legacy']))
{
return $this->getInput();
}
$options = array(
'id' => $this->id
);
return $this->getFieldContents($options);
}
/**
* 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
*/
public function getRepeatable()
{
if (isset($this->element['legacy']))
{
return $this->getInput();
}
$options = array(
'class' => $this->id
);
return $this->getFieldContents($options);
}
/**
* 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'] : '');
return '<span ' . ($id ? $id : '') . 'class="' . $class . '">' .
htmlspecialchars(GenericList::getOptionName($this->getOptions(), $this->value), ENT_COMPAT, 'UTF-8') .
'</span>';
}
}
Field/Checkboxes.php 0000644 00000006431 15235405654 0010373 0 ustar 00 <?php
/**
* @package FOF
* @copyright Copyright (c)2010-2019 Nicholas K. Dionysopoulos / Akeeba Ltd
* @license GNU GPL version 2 or later
*/
namespace FOF30\Form\Field;
use FOF30\Form\FieldInterface;
use FOF30\Form\Form;
use FOF30\Model\DataModel;
use FOF30\Utils\StringHelper;
use JText;
defined('_JEXEC') or die;
\JFormHelper::loadFieldClass('checkboxes');
/**
* Form Field class for FOF
* Supports a list of checkbox.
*
* @deprecated 3.1 Support for XML forms will be removed in FOF 4
*/
class Checkboxes extends \JFormFieldCheckboxes implements FieldInterface
{
/**
* @var string Static field output
*/
protected $static;
/**
* @var string Repeatable field output
*/
protected $repeatable;
/**
* The Form object of the form attached to the form field.
*
* @var Form
*/
protected $form;
/**
* A monotonically increasing number, denoting the row number in a repeatable view
*
* @var int
*/
public $rowid;
/**
* The item being rendered in a repeatable form field
*
* @var DataModel
*/
public $item;
/**
* Method to get certain otherwise inaccessible properties from the form field object.
*
* @param string $name The property name for which to the the value.
*
* @return mixed The property value or null.
*
* @since 2.0
*/
public function __get($name)
{
switch ($name)
{
case 'static':
if (empty($this->static))
{
$this->static = $this->getStatic();
}
return $this->static;
break;
case 'repeatable':
if (empty($this->repeatable))
{
$this->repeatable = $this->getRepeatable();
}
return $this->repeatable;
break;
default:
return parent::__get($name);
}
}
/**
* Get the rendering of this field type for static display, e.g. in a single
* item view (typically a "read" task).
*
* @since 2.0
*
* @return string The field HTML
*/
public function getStatic()
{
if (isset($this->element['legacy']))
{
return $this->getInput();
}
$options = array(
'id' => $this->id
);
return $this->getFieldContents($options);
}
/**
* 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
*/
public function getRepeatable()
{
if (isset($this->element['legacy']))
{
return $this->getInput();
}
$options = array(
'class' => $this->id
);
return $this->getFieldContents($options);
}
/**
* 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'] : '');
$translate = StringHelper::toBool($this->element['translate']) ? true : false;
$html = '<span ' . ($id ? $id : '') . 'class="' . $class . '">';
foreach ($this->value as $value) {
$html .= '<span>';
if ($translate == true)
{
$html .= JText::_($value);
}
else
{
$html .= $value;
}
$html .= '</span>';
}
$html .= '</span>';
return $html;
}
}
Field/Button.php 0000644 00000006007 15235405654 0007567 0 ustar 00 <?php
/**
* @package FOF
* @copyright Copyright (c)2010-2019 Nicholas K. Dionysopoulos / Akeeba Ltd
* @license GNU GPL version 2 or later
*/
namespace FOF30\Form\Field;
use FOF30\Form\FieldInterface;
use FOF30\Form\Form;
use FOF30\Utils\StringHelper;
use JText;
defined('_JEXEC') or die;
\JFormHelper::loadFieldClass('text');
/**
* Form Field class for the FOF framework
* Supports a button input.
*
* @deprecated 3.1 Support for XML forms will be removed in FOF 4
*/
class Button extends Text implements FieldInterface
{
/**
* @var string Static field output
*/
protected $static;
/**
* @var string Repeatable field output
*/
protected $repeatable;
/**
* The Form object of the form attached to the form field.
*
* @var Form
*/
protected $form;
/**
* Get the rendering of this field type for static display, e.g. in a single
* item view (typically a "read" task).
*
* @since 2.0
*
* @return string The field HTML
*/
public function getStatic()
{
return $this->getInput();
}
/**
* 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
*/
public function getRepeatable()
{
return $this->getInput();
}
/**
* Get the rendering of this field type for static display, e.g. in a single
* item view (typically a "read" task).
*
* @since 2.0
*
* @return string The field HTML
*/
public function getInput()
{
$this->label = '';
$allowedElement = array('button', 'a');
if (in_array($this->element['htmlelement'], $allowedElement))
{
$type = $this->element['htmlelement'];
}
else
{
$type = 'button';
}
$text = $this->element['text'] ? (string) $this->element['text'] : '';
$class = $this->class ? $this->class : '';
$icon = $this->element['icon'] ? '<span class="icon ' . (string) $this->element['icon'] . '"></span> ' : '';
if ($this->element['listItemTask'])
{
$this->onclick = "listItemTask('cb" . $this->item->getId() . "', '" . (string)$this->element['listItemTask'] . "')";
}
$onclick = $this->onclick ? 'onclick="' . $this->onclick . '" ' : '';
$url = $this->element['url'] ? 'href="' . $this->parseFieldTags((string) $this->element['url']) . '" ' : '';
$title = $this->element['title'] ? 'title="' . JText::_((string) $this->element['title']) . '" ' : '';
$useValue = StringHelper::toBool((string) $this->element['use_value']);
if (!$useValue)
{
$this->value = JText::_($text);
}
$html = '<' . $type . ' id="' . $this->id . '" class="btn ' . $class . '" ' . $onclick . $url . $title . '>';
$html .= $icon . htmlspecialchars($this->value, ENT_COMPAT, 'UTF-8');
$html .= '</' . $type . '>';
return $html;
}
/**
* Method to get the field title.
*
* @return string The field title.
*/
protected function getTitle()
{
return null;
}
}
Field/TextArea.php 0000644 00000005775 15235405654 0010044 0 ustar 00 <?php
/**
* @package FOF
* @copyright Copyright (c)2010-2019 Nicholas K. Dionysopoulos / Akeeba Ltd
* @license GNU GPL version 2 or later
*/
namespace FOF30\Form\Field;
use FOF30\Form\FieldInterface;
use FOF30\Form\Form;
use FOF30\Model\DataModel;
defined('_JEXEC') or die;
\JFormHelper::loadFieldClass('textarea');
/**
* Form Field class for the FOF framework
* Supports a text area
*
* @deprecated 3.1 Support for XML forms will be removed in FOF 4
*/
class TextArea extends \JFormFieldTextarea implements FieldInterface
{
/**
* @var string Static field output
*/
protected $static;
/**
* @var string Repeatable field output
*/
protected $repeatable;
/**
* The Form object of the form attached to the form field.
*
* @var Form
*/
protected $form;
/**
* A monotonically increasing number, denoting the row number in a repeatable view
*
* @var int
*/
public $rowid;
/**
* The item being rendered in a repeatable form field
*
* @var DataModel
*/
public $item;
/**
* Method to get certain otherwise inaccessible properties from the form field object.
*
* @param string $name The property name for which to the the value.
*
* @return mixed The property value or null.
*
* @since 2.0
*/
public function __get($name)
{
switch ($name)
{
case 'static':
if (empty($this->static))
{
$this->static = $this->getStatic();
}
return $this->static;
break;
case 'repeatable':
if (empty($this->repeatable))
{
$this->repeatable = $this->getRepeatable();
}
return $this->repeatable;
break;
default:
return parent::__get($name);
}
}
/**
* Get the rendering of this field type for static display, e.g. in a single
* item view (typically a "read" task).
*
* @since 2.0
*
* @return string The field HTML
*/
public function getStatic()
{
if (isset($this->element['legacy']))
{
return $this->getInput();
}
$options = array(
'id' => $this->id
);
return $this->getFieldContents($options);
}
/**
* 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
*/
public function getRepeatable()
{
if (isset($this->element['legacy']))
{
return $this->getInput();
}
$options = array(
'class' => $this->id
);
return $this->getFieldContents($options);
}
/**
* 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'] : '');
return '<div ' . ($id ? $id : '') . 'class="' . $class . '">' .
htmlspecialchars(nl2br($this->value), ENT_COMPAT, 'UTF-8') .
'</div>';
}
}
Field/ViewTemplate.php 0000644 00000007736 15235405654 0010734 0 ustar 00 <?php
/**
* @package FOF
* @copyright Copyright (c)2010-2019 Nicholas K. Dionysopoulos / Akeeba Ltd
* @license GNU GPL version 2 or later
*/
namespace FOF30\Form\Field;
use FOF30\Container\Container;
use FOF30\Form\FieldInterface;
use FOF30\Form\Form;
use FOF30\Model\DataModel;
use FOF30\View\View;
defined('_JEXEC') or die;
\JFormHelper::loadFieldClass('text');
/**
* Form Field class for the FOF framework
* Displays a view template loaded from an outside source
*
* @deprecated 3.1 Support for XML forms will be removed in FOF 4
*/
class ViewTemplate extends \JFormField implements FieldInterface
{
/**
* @var string Static field output
*/
protected $static;
/**
* @var string Repeatable field output
*/
protected $repeatable;
/**
* The Form object of the form attached to the form field.
*
* @var Form
*/
protected $form;
/**
* A monotonically increasing number, denoting the row number in a repeatable view
*
* @var int
*/
public $rowid;
/**
* The item being rendered in a repeatable form field
*
* @var DataModel
*/
public $item;
/**
* Method to get certain otherwise inaccessible properties from the form field object.
*
* @param string $name The property name for which to the the value.
*
* @return mixed The property value or null.
*
* @since 2.0
*/
public function __get($name)
{
switch ($name)
{
case 'input':
if (empty($this->input))
{
$this->input = $this->getInput();
}
return $this->input;
break;
case 'static':
if (empty($this->static))
{
$this->static = $this->getStatic();
}
return $this->static;
break;
case 'repeatable':
if (empty($this->repeatable))
{
$this->repeatable = $this->getRepeatable();
}
return $this->repeatable;
break;
default:
return parent::__get($name);
}
}
/**
* Get the rendering of this field type for static display, e.g. in a single
* item view (typically a "read" task).
*
* @since 2.0
*
* @return string The field HTML
*/
public function getStatic()
{
return $this->getRenderedTemplate();
}
/**
* 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
*/
public function getRepeatable()
{
return $this->getRenderedTemplate(true);
}
/**
* Method to get the field input markup.
*
* @return string The field input markup.
*
* @since 11.1
*/
protected function getInput()
{
return $this->getRenderedTemplate();
}
/**
* 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(),
'rowid' => $isRepeatable ? $this->rowid : null,
'form' => $this->form,
'formType' => $this->form->getAttribute('type', 'edit'),
'fieldValue' => $this->value,
'fieldElement' => $this->element,
));
}
}
Field/SelectRow.php 0000644 00000006620 15235405654 0010224 0 ustar 00 <?php
/**
* @package FOF
* @copyright Copyright (c)2010-2019 Nicholas K. Dionysopoulos / Akeeba Ltd
* @license GNU GPL version 2 or later
*/
namespace FOF30\Form\Field;
use FOF30\Form\Exception\DataModelRequired;
use FOF30\Form\Exception\GetInputNotAllowed;
use FOF30\Form\Exception\GetStaticNotAllowed;
use FOF30\Form\FieldInterface;
use FOF30\Form\Form;
use FOF30\Model\DataModel;
use JHtml;
defined('_JEXEC') or die;
/**
* Form Field class for FOF
* Renders the checkbox in browse views which allows you to select rows
*
* @deprecated 3.1 Support for XML forms will be removed in FOF 4
*/
class SelectRow extends \JFormField implements FieldInterface
{
/**
* @var string Static field output
*/
protected $static;
/**
* @var string Repeatable field output
*/
protected $repeatable;
/**
* The Form object of the form attached to the form field.
*
* @var Form
*/
protected $form;
/**
* A monotonically increasing number, denoting the row number in a repeatable view
*
* @var int
*/
public $rowid;
/**
* The item being rendered in a repeatable form field
*
* @var DataModel
*/
public $item;
/**
* Method to get certain otherwise inaccessible properties from the form field object.
*
* @param string $name The property name for which to the the value.
*
* @return mixed The property value or null.
*
* @since 2.0
*/
public function __get($name)
{
switch ($name)
{
case 'static':
if (empty($this->static))
{
$this->static = $this->getStatic();
}
return $this->static;
break;
case 'repeatable':
if (empty($this->repeatable))
{
$this->repeatable = $this->getRepeatable();
}
return $this->repeatable;
break;
default:
return parent::__get($name);
}
}
/**
* Method to get the field input markup for this field type.
*
* @since 2.0
*
* @return string The field input markup.
*
* @throws GetInputNotAllowed
*/
protected function getInput()
{
throw new GetInputNotAllowed(__CLASS__);
}
/**
* Get the rendering of this field type for static display, e.g. in a single
* item view (typically a "read" task).
*
* @since 2.0
*
* @return string The field HTML
*
* @throws \LogicException
*/
public function getStatic()
{
throw new GetStaticNotAllowed(__CLASS__);
}
/**
* 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);
}
}
Field/GroupedButton.php 0000644 00000006271 15235405654 0011120 0 ustar 00 <?php
/**
* @package FOF
* @copyright Copyright (c)2010-2019 Nicholas K. Dionysopoulos / Akeeba Ltd
* @license GNU GPL version 2 or later
*/
namespace FOF30\Form\Field;
use FOF30\Form\FieldInterface;
use FOF30\Form\Form;
use FOF30\Model\DataModel;
defined('_JEXEC') or die;
\JFormHelper::loadFieldClass('text');
/**
* Form Field class for FOF
* Supports a generic list of options.
*
* @deprecated 3.1 Support for XML forms will be removed in FOF 4
*/
class GroupedButton extends \JFormFieldText implements FieldInterface
{
/**
* @var string Static field output
*/
protected $static;
/**
* @var string Repeatable field output
*/
protected $repeatable;
/**
* The Form object of the form attached to the form field.
*
* @var Form
*/
protected $form;
/**
* A monotonically increasing number, denoting the row number in a repeatable view
*
* @var int
*/
public $rowid;
/**
* The item being rendered in a repeatable form field
*
* @var DataModel
*/
public $item;
/**
* Method to get certain otherwise inaccessible properties from the form field object.
*
* @param string $name The property name for which to the the value.
*
* @return mixed The property value or null.
*
* @since 2.0
*/
public function __get($name)
{
switch ($name)
{
case 'static':
if (empty($this->static))
{
$this->static = $this->getStatic();
}
return $this->static;
break;
case 'repeatable':
if (empty($this->repeatable))
{
$this->repeatable = $this->getRepeatable();
}
return $this->repeatable;
break;
default:
return parent::__get($name);
}
}
/**
* Get the rendering of this field type for static display, e.g. in a single
* item view (typically a "read" task).
*
* @since 2.0
*
* @return string The field HTML
*/
public function getStatic()
{
return $this->getInput();
}
/**
* 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
*/
public function getRepeatable()
{
return $this->getInput();
}
/**
* Get the rendering of this field type for static display, e.g. in a single
* item view (typically a "read" task).
*
* @since 2.0
*
* @return string The field HTML
*/
public function getInput()
{
$class = $this->class ? $this->class : '';
$html = '<div id="' . $this->id . '" class="btn-group ' . $class . '">';
/** @var \SimpleXMLElement $option */
foreach ($this->element->children() as $option)
{
$renderedAttributes = array();
foreach ($option->attributes() as $name => $value)
{
if (!is_null($value))
{
$renderedAttributes[] = $name . '="' . htmlentities($value) . '"';
}
}
$buttonXML = new \SimpleXMLElement('<field ' . implode(' ', $renderedAttributes) . ' />');
$buttonField = new Button($this->form);
// Pass required objects to the field
$buttonField->item = $this->item;
$buttonField->rowid = $this->rowid;
$buttonField->setup($buttonXML, null);
$html .= $buttonField->getRepeatable();
}
$html .= '</div>';
return $html;
}
}
Field/Sql.php 0000644 00000006056 15235405654 0007057 0 ustar 00 <?php
/**
* @package FOF
* @copyright Copyright (c)2010-2019 Nicholas K. Dionysopoulos / Akeeba Ltd
* @license GNU GPL version 2 or later
*/
namespace FOF30\Form\Field;
use FOF30\Form\FieldInterface;
use FOF30\Form\Form;
use FOF30\Model\DataModel;
defined('_JEXEC') or die;
\JFormHelper::loadFieldClass('sql');
/**
* Form Field class for FOF
* Radio selection listGeneric list from an SQL statement
*
* @deprecated 3.1 Support for XML forms will be removed in FOF 4
*/
class Sql extends \JFormFieldSql implements FieldInterface
{
/**
* @var string Static field output
*/
protected $static;
/**
* @var string Repeatable field output
*/
protected $repeatable;
/**
* The Form object of the form attached to the form field.
*
* @var Form
*/
protected $form;
/**
* A monotonically increasing number, denoting the row number in a repeatable view
*
* @var int
*/
public $rowid;
/**
* The item being rendered in a repeatable form field
*
* @var DataModel
*/
public $item;
/**
* Method to get certain otherwise inaccessible properties from the form field object.
*
* @param string $name The property name for which to the the value.
*
* @return mixed The property value or null.
*
* @since 2.0
*/
public function __get($name)
{
switch ($name)
{
case 'static':
if (empty($this->static))
{
$this->static = $this->getStatic();
}
return $this->static;
break;
case 'repeatable':
if (empty($this->repeatable))
{
$this->repeatable = $this->getRepeatable();
}
return $this->repeatable;
break;
default:
return parent::__get($name);
}
}
/**
* Get the rendering of this field type for static display, e.g. in a single
* item view (typically a "read" task).
*
* @since 2.0
*
* @return string The field HTML
*/
public function getStatic()
{
if (isset($this->element['legacy']))
{
return $this->getInput();
}
$options = array(
'id' => $this->id
);
return $this->getFieldContents($options);
}
/**
* 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
*/
public function getRepeatable()
{
if (isset($this->element['legacy']))
{
return $this->getInput();
}
$options = array(
'class' => $this->id
);
return $this->getFieldContents($options);
}
/**
* 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'] : '');
return '<span ' . ($id ? $id : '') . 'class="' . $class . '">' .
htmlspecialchars(GenericList::getOptionName($this->getOptions(), $this->value), ENT_COMPAT, 'UTF-8') .
'</span>';
}
}
Field/Hidden.php 0000644 00000004245 15235405654 0007511 0 ustar 00 <?php
/**
* @package FOF
* @copyright Copyright (c)2010-2019 Nicholas K. Dionysopoulos / Akeeba Ltd
* @license GNU GPL version 2 or later
*/
namespace FOF30\Form\Field;
use FOF30\Form\FieldInterface;
use FOF30\Form\Form;
use FOF30\Model\DataModel;
defined('_JEXEC') or die;
\JFormHelper::loadFieldClass('hidden');
/**
* Form Field class for the FOF framework
* A hidden field
*
* @deprecated 3.1 Support for XML forms will be removed in FOF 4
*/
class Hidden extends \JFormFieldHidden implements FieldInterface
{
/**
* @var string Static field output
*/
protected $static;
/**
* @var string Repeatable field output
*/
protected $repeatable;
/**
* The Form object of the form attached to the form field.
*
* @var Form
*/
protected $form;
/**
* A monotonically increasing number, denoting the row number in a repeatable view
*
* @var int
*/
public $rowid;
/**
* The item being rendered in a repeatable form field
*
* @var DataModel
*/
public $item;
/**
* Method to get certain otherwise inaccessible properties from the form field object.
*
* @param string $name The property name for which to the the value.
*
* @return mixed The property value or null.
*
* @since 2.0
*/
public function __get($name)
{
switch ($name)
{
case 'static':
if (empty($this->static))
{
$this->static = $this->getStatic();
}
return $this->static;
break;
case 'repeatable':
if (empty($this->repeatable))
{
$this->repeatable = $this->getRepeatable();
}
return $this->repeatable;
break;
default:
return parent::__get($name);
}
}
/**
* Get the rendering of this field type for static display, e.g. in a single
* item view (typically a "read" task).
*
* @since 2.0
*
* @return string The field HTML
*/
public function getStatic()
{
return $this->getInput();
}
/**
* 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
*/
public function getRepeatable()
{
return $this->getInput();
}
}
Field/Tag.php 0000644 00000010253 15235405654 0007025 0 ustar 00 <?php
/**
* @package FOF
* @copyright Copyright (c)2010-2019 Nicholas K. Dionysopoulos / Akeeba Ltd
* @license GNU GPL version 2 or later
*/
namespace FOF30\Form\Field;
use FOF30\Form\FieldInterface;
use FOF30\Form\Form;
use FOF30\Model\DataModel;
defined('_JEXEC') or die;
\JFormHelper::loadFieldClass('tag');
/**
* Form Field class for FOF
* Tag Fields
*
* @deprecated 3.1 Support for XML forms will be removed in FOF 4
*/
class Tag extends \JFormFieldTag implements FieldInterface
{
/**
* @var string Static field output
*/
protected $static;
/**
* @var string Repeatable field output
*/
protected $repeatable;
/**
* The Form object of the form attached to the form field.
*
* @var Form
*/
protected $form;
/**
* A monotonically increasing number, denoting the row number in a repeatable view
*
* @var int
*/
public $rowid;
/**
* The item being rendered in a repeatable form field
*
* @var DataModel
*/
public $item;
/**
* Method to get certain otherwise inaccessible properties from the form field object.
*
* @param string $name The property name for which to the the value.
*
* @return mixed The property value or null.
*
* @since 2.0
*/
public function __get($name)
{
switch ($name)
{
case 'static':
if (empty($this->static))
{
$this->static = $this->getStatic();
}
return $this->static;
break;
case 'repeatable':
if (empty($this->repeatable))
{
$this->repeatable = $this->getRepeatable();
}
return $this->repeatable;
break;
default:
return parent::__get($name);
}
}
/**
* Get the rendering of this field type for static display, e.g. in a single
* item view (typically a "read" task).
*
* @since 2.0
*
* @return string The field HTML
*/
public function getStatic()
{
if (isset($this->element['legacy']))
{
return $this->getInput();
}
$options = array(
'id' => $this->id
);
return $this->getFieldContents($options);
}
/**
* 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.1
*
* @return string The field HTML
*/
public function getRepeatable()
{
if (isset($this->element['legacy']))
{
return $this->getInput();
}
$options = array(
'class' => $this->id
);
return $this->getFieldContents($options);
}
/**
* 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>';
}
}
Field/Actions.php 0000644 00000013477 15235405654 0007725 0 ustar 00 <?php
/**
* @package FOF
* @copyright Copyright (c)2010-2019 Nicholas K. Dionysopoulos / Akeeba Ltd
* @license GNU GPL version 2 or later
*/
namespace FOF30\Form\Field;
use FOF30\Form\Exception\DataModelRequired;
use FOF30\Form\Exception\GetStaticNotAllowed;
use FOF30\Form\FieldInterface;
use FOF30\Form\Form;
use FOF30\Model\DataModel;
use FOF30\Utils\StringHelper;
use JHtml;
defined('_JEXEC') or die;
\JFormHelper::loadFieldClass('list');
/**
* Form Field class for FOF
* Supports a generic list of options.
*
* @deprecated 3.1 Support for XML forms will be removed in FOF 4
*/
class Actions extends \JFormFieldList implements FieldInterface
{
/**
* @var string Static field output
*/
protected $static;
/**
* @var string Repeatable field output
*/
protected $repeatable;
/**
* The Form object of the form attached to the form field.
*
* @var Form
*/
protected $form;
/**
* A monotonically increasing number, denoting the row number in a repeatable view
*
* @var int
*/
public $rowid;
/**
* The item being rendered in a repeatable form field
*
* @var DataModel
*/
public $item;
/**
* Method to get certain otherwise inaccessible properties from the form field object.
*
* @param string $name The property name for which to the the value.
*
* @return mixed The property value or null.
*
* @since 2.0
*/
public function __get($name)
{
switch ($name)
{
case 'static':
if (empty($this->static))
{
$this->static = $this->getStatic();
}
return $this->static;
break;
case 'repeatable':
if (empty($this->repeatable))
{
$this->repeatable = $this->getRepeatable();
}
return $this->repeatable;
break;
default:
return parent::__get($name);
}
}
/**
* Get the field configuration
*
* @return array
*/
protected function getConfig()
{
// If no custom options were defined let's figure out which ones of the
// defaults we shall use...
$config = array(
'published' => 1,
'unpublished' => 1,
'archived' => 0,
'trash' => 0,
'all' => 0,
);
if (isset($this->element['show_published']))
{
$config['published'] = StringHelper::toBool($this->element['show_published']);
}
if (isset($this->element['show_unpublished']))
{
$config['unpublished'] = StringHelper::toBool($this->element['show_unpublished']);
}
if (isset($this->element['show_archived']))
{
$config['archived'] = StringHelper::toBool($this->element['show_archived']);
}
if (isset($this->element['show_trash']))
{
$config['trash'] = StringHelper::toBool($this->element['show_trash']);
}
if (isset($this->element['show_all']))
{
$config['all'] = StringHelper::toBool($this->element['show_all']);
}
return $config;
}
/**
* Method to get the field options.
*
* @since 2.0
*
* @return array The field option objects.
*/
protected function getOptions()
{
return null;
}
/**
* Method to get a
*
* @param string $enabledFieldName Name of the enabled/published field
*
* @return Published Field
*/
protected function getPublishedField($enabledFieldName)
{
$attributes = array(
'name' => $enabledFieldName,
'type' => 'published',
);
if ($this->element['publish_up'])
{
$attributes['publish_up'] = (string) $this->element['publish_up'];
}
if ($this->element['publish_down'])
{
$attributes['publish_down'] = (string) $this->element['publish_down'];
}
$renderedAttributes = array();
foreach ($attributes as $name => $value)
{
if (!is_null($value))
{
$renderedAttributes[] = $name . '="' . $value . '"';
}
}
$publishedXml = new \SimpleXMLElement('<field ' . implode(' ', $renderedAttributes) . ' />');
$publishedField = new Published($this->form);
// Pass required objects to the field
$publishedField->item = $this->item;
$publishedField->rowid = $this->rowid;
$publishedField->setup($publishedXml, $this->item->{$enabledFieldName});
return $publishedField;
}
/**
* Get the rendering of this field type for static display, e.g. in a single
* item view (typically a "read" task).
*
* @since 2.0
*
* @return string The field HTML
*
* @throws \LogicException
*/
public function getStatic()
{
throw new GetStaticNotAllowed(__CLASS__);
}
/**
* 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()
{
if (!($this->item instanceof DataModel))
{
throw new DataModelRequired(__CLASS__);
}
$config = $this->getConfig();
$html = '<div class="btn-group">';
// Render a published field
if ($this->item->hasField('enabled'))
{
$publishedFieldName = $this->item->getFieldAlias('enabled');
if ($config['published'] || $config['unpublished'])
{
// Generate a FieldInterfacePublished field
$publishedField = $this->getPublishedField($publishedFieldName);
// Render the publish button
$html .= $publishedField->getRepeatable();
}
if ($config['archived'])
{
$archived = $this->item->getFieldValue($publishedFieldName) == 2 ? true : false;
// Create dropdown items
$action = $archived ? 'unarchive' : 'archive';
JHtml::_('actionsdropdown.' . $action, 'cb' . $this->rowid);
}
if ($config['trash'])
{
$trashed = $this->item->getFieldValue($publishedFieldName) == -2 ? true : false;
$action = $trashed ? 'untrash' : 'trash';
JHtml::_('actionsdropdown.' . $action, 'cb' . $this->rowid);
}
// Render dropdown list
if ($config['archived'] || $config['trash'])
{
$html .= JHtml::_('actionsdropdown.render', $this->item->title);
}
}
$html .= '</div>';
return $html;
}
}
Field/Boolean.php 0000644 00000002616 15235405654 0007675 0 ustar 00 <?php
/**
* @package FOF
* @copyright Copyright (c)2010-2019 Nicholas K. Dionysopoulos / Akeeba Ltd
* @license GNU GPL version 2 or later
*/
namespace FOF30\Form\Field;
use FOF30\Form\FieldInterface;
use JHtml;
defined('_JEXEC') or die;
\JFormHelper::loadFieldClass('list');
/**
* Form Field class for FOF
* Supports a drop-down list of Yes/No (boolean) answers.
*
* @deprecated 3.1 Support for XML forms will be removed in FOF 4
*/
class Boolean extends GenericList implements FieldInterface
{
/**
* Method to get the field options.
*
* Ordering is disabled by default. You can enable ordering by setting the
* 'order' element in your form field. The other order values are optional.
*
* - order What to order. Possible values: 'name' or 'value' (default = false)
* - order_dir Order direction. Possible values: 'asc' = Ascending or 'desc' = Descending (default = 'asc')
* - order_case_sensitive Order case sensitive. Possible values: 'true' or 'false' (default = false)
*
* @return array The field option objects.
*
* @since Ordering is available since FOF 2.1.b2.
*/
protected function getOptions()
{
$options = parent::getOptions();
$defaultOptions = array(
JHtml::_('select.option', 1, \JText::_('JYES')),
JHtml::_('select.option', 0, \JText::_('JNO')),
);
$options = array_merge($defaultOptions, $options);
return $options;
}
}
Field/Numeric.php 0000644 00000001273 15235405654 0007716 0 ustar 00 <?php
/**
* @package FOF
* @copyright Copyright (c)2010-2019 Nicholas K. Dionysopoulos / Akeeba Ltd
* @license GNU GPL version 2 or later
*/
namespace FOF30\Form\Field;
defined('_JEXEC') or die;
\JFormHelper::loadFieldClass('number');
/**
* Backwards compatibility field. DO NOT USE IN PHP 7.2 AND LATER.
*
* @deprecated 3.1 Support for XML forms will be removed in FOF 4
*/
class Numeric extends Number
{
public function __construct($form = null)
{
parent::__construct($form);
$this->form->getModel()->getContainer()->platform->logDeprecated("The numeric field is deprecated and may cause fatal errors in PHP 7.2 and later. Use the number field type instead.");
}
}
Field/Editor.php 0000644 00000005760 15235405654 0007547 0 ustar 00 <?php
/**
* @package FOF
* @copyright Copyright (c)2010-2019 Nicholas K. Dionysopoulos / Akeeba Ltd
* @license GNU GPL version 2 or later
*/
namespace FOF30\Form\Field;
use FOF30\Form\FieldInterface;
use FOF30\Form\Form;
use FOF30\Model\DataModel;
defined('_JEXEC') or die;
\JFormHelper::loadFieldClass('editor');
/**
* Form Field class for the FOF framework
* An editarea field for content creation and formatted HTML display
*
* @deprecated 3.1 Support for XML forms will be removed in FOF 4
*/
class Editor extends \JFormFieldEditor implements FieldInterface
{
/**
* @var string Static field output
*/
protected $static;
/**
* @var string Repeatable field output
*/
protected $repeatable;
/**
* The Form object of the form attached to the form field.
*
* @var Form
*/
protected $form;
/**
* A monotonically increasing number, denoting the row number in a repeatable view
*
* @var int
*/
public $rowid;
/**
* The item being rendered in a repeatable form field
*
* @var DataModel
*/
public $item;
/**
* Method to get certain otherwise inaccessible properties from the form field object.
*
* @param string $name The property name for which to the the value.
*
* @return mixed The property value or null.
*
* @since 2.0
*/
public function __get($name)
{
switch ($name)
{
case 'static':
if (empty($this->static))
{
$this->static = $this->getStatic();
}
return $this->static;
break;
case 'repeatable':
if (empty($this->repeatable))
{
$this->repeatable = $this->getRepeatable();
}
return $this->repeatable;
break;
default:
return parent::__get($name);
}
}
/**
* Get the rendering of this field type for static display, e.g. in a single
* item view (typically a "read" task).
*
* @since 2.0
*
* @return string The field HTML
*/
public function getStatic()
{
if (isset($this->element['legacy']))
{
return $this->getInput();
}
$options = array(
'id' => $this->id
);
return $this->getFieldContents($options);
}
/**
* 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
*/
public function getRepeatable()
{
if (isset($this->element['legacy']))
{
return $this->getInput();
}
$options = array(
'class' => $this->id
);
return $this->getFieldContents($options);
}
/**
* 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'] : '');
return '<div ' . ($id ? $id : '') . 'class="' . $class . '">' . $this->value . '</div>';
}
}
Field/BooleanToggle.php 0000644 00000003001 15235405654 0011024 0 ustar 00 <?php
/**
* @package FOF
* @copyright Copyright (c)2010-2019 Nicholas K. Dionysopoulos / Akeeba Ltd
* @license GNU GPL version 2 or later
*/
namespace FOF30\Form\Field;
use FOF30\Form\FieldInterface;
use JHtml;
defined('_JEXEC') or die;
\JFormHelper::loadFieldClass('list');
/**
* Form Field class for FOF
* Supports a drop-down list of Yes/No (boolean) answers.
*
* @deprecated 3.1 Support for XML forms will be removed in FOF 4
*/
class BooleanToggle extends Radio implements FieldInterface
{
protected function getInput()
{
$this->class = 'btn-group btn-group-yesno ';
return parent::getInput();
}
/**
* Method to get the field options.
*
* Ordering is disabled by default. You can enable ordering by setting the
* 'order' element in your form field. The other order values are optional.
*
* - order What to order. Possible values: 'name' or 'value' (default = false)
* - order_dir Order direction. Possible values: 'asc' = Ascending or 'desc' = Descending (default = 'asc')
* - order_case_sensitive Order case sensitive. Possible values: 'true' or 'false' (default = false)
*
* @return array The field option objects.
*
* @since Ordering is available since FOF 2.1.b2.
*/
protected function getOptions()
{
$options = parent::getOptions();
$defaultOptions = array(
JHtml::_('select.option', 1, \JText::_('JYES')),
JHtml::_('select.option', 0, \JText::_('JNO')),
);
$options = array_merge($defaultOptions, $options);
return $options;
}
}
Field/Captcha.php 0000644 00000004263 15235405654 0007661 0 ustar 00 <?php
/**
* @package FOF
* @copyright Copyright (c)2010-2019 Nicholas K. Dionysopoulos / Akeeba Ltd
* @license GNU GPL version 2 or later
*/
namespace FOF30\Form\Field;
use FOF30\Form\FieldInterface;
use FOF30\Form\Form;
use FOF30\Model\DataModel;
defined('_JEXEC') or die;
\JFormHelper::loadFieldClass('captcha');
/**
* Form Field class for the FOF framework
* Supports a captcha field.
*
* @deprecated 3.1 Support for XML forms will be removed in FOF 4
*/
class Captcha extends \JFormFieldCaptcha implements FieldInterface
{
/**
* @var string Static field output
*/
protected $static;
/**
* @var string Repeatable field output
*/
protected $repeatable;
/**
* The Form object of the form attached to the form field.
*
* @var Form
*/
protected $form;
/**
* A monotonically increasing number, denoting the row number in a repeatable view
*
* @var int
*/
public $rowid;
/**
* The item being rendered in a repeatable form field
*
* @var DataModel
*/
public $item;
/**
* Method to get certain otherwise inaccessible properties from the form field object.
*
* @param string $name The property name for which to the the value.
*
* @return mixed The property value or null.
*
* @since 2.0
*/
public function __get($name)
{
switch ($name)
{
case 'static':
if (empty($this->static))
{
$this->static = $this->getStatic();
}
return $this->static;
break;
case 'repeatable':
if (empty($this->repeatable))
{
$this->repeatable = $this->getRepeatable();
}
return $this->repeatable;
break;
default:
return parent::__get($name);
}
}
/**
* Get the rendering of this field type for static display, e.g. in a single
* item view (typically a "read" task).
*
* @since 2.0
*
* @return string The field HTML
*/
public function getStatic()
{
return $this->getInput();
}
/**
* 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
*/
public function getRepeatable()
{
return $this->getInput();
}
}
Field/Timezone.php 0000644 00000006601 15235405654 0010106 0 ustar 00 <?php
/**
* @package FOF
* @copyright Copyright (c)2010-2019 Nicholas K. Dionysopoulos / Akeeba Ltd
* @license GNU GPL version 2 or later
*/
namespace FOF30\Form\Field;
use FOF30\Form\FieldInterface;
use FOF30\Form\Form;
use FOF30\Model\DataModel;
defined('_JEXEC') or die;
\JFormHelper::loadFieldClass('timezone');
/**
* Form Field class for FOF
* Supports a generic list of options.
*
* @deprecated 3.1 Support for XML forms will be removed in FOF 4
*/
class Timezone extends \JFormFieldTimezone implements FieldInterface
{
/**
* @var string Static field output
*/
protected $static;
/**
* @var string Repeatable field output
*/
protected $repeatable;
/**
* The Form object of the form attached to the form field.
*
* @var Form
*/
protected $form;
/**
* A monotonically increasing number, denoting the row number in a repeatable view
*
* @var int
*/
public $rowid;
/**
* The item being rendered in a repeatable form field
*
* @var DataModel
*/
public $item;
/**
* Method to get certain otherwise inaccessible properties from the form field object.
*
* @param string $name The property name for which to the the value.
*
* @return mixed The property value or null.
*
* @since 2.0
*/
public function __get($name)
{
switch ($name)
{
case 'static':
if (empty($this->static))
{
$this->static = $this->getStatic();
}
return $this->static;
break;
case 'repeatable':
if (empty($this->repeatable))
{
$this->repeatable = $this->getRepeatable();
}
return $this->repeatable;
break;
default:
return parent::__get($name);
}
}
/**
* Get the rendering of this field type for static display, e.g. in a single
* item view (typically a "read" task).
*
* @since 2.0
*
* @return string The field HTML
*/
public function getStatic()
{
if (isset($this->element['legacy']))
{
return $this->getInput();
}
$options = array(
'id' => $this->id
);
return $this->getFieldContents($options);
}
/**
* 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
*/
public function getRepeatable()
{
if (isset($this->element['legacy']))
{
return $this->getInput();
}
$options = array(
'class' => $this->id
);
return $this->getFieldContents($options);
}
/**
* 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']) ? $fieldOptions['id'] : null;
$class = $this->class . (isset($fieldOptions['class']) ? ' ' . $fieldOptions['class'] : '');
$selected = GroupedList::getOptionName($this->getGroups(), $this->value);
if (is_null($selected))
{
$selected = array(
'group' => '',
'item' => ''
);
}
return '<span ' . ($id ? 'id="' . $id . '-group" ' : '') . 'class="fof-groupedlist-group ' . $class . '>' .
htmlspecialchars($selected['group'], ENT_COMPAT, 'UTF-8') .
'</span>' .
'<span ' . ($id ? 'id="' . $id . '-item" ' : '') . 'class="fof-groupedlist-item ' . $class . '>' .
htmlspecialchars($selected['item'], ENT_COMPAT, 'UTF-8') .
'</span>';
}
}
Field/Media.php 0000644 00000010513 15235405654 0007330 0 ustar 00 <?php
/**
* @package FOF
* @copyright Copyright (c)2010-2019 Nicholas K. Dionysopoulos / Akeeba Ltd
* @license GNU GPL version 2 or later
*/
namespace FOF30\Form\Field;
use FOF30\Form\FieldInterface;
use FOF30\Form\Form;
use FOF30\Model\DataModel;
use JHtml;
use JText;
defined('_JEXEC') or die;
\JFormHelper::loadFieldClass('media');
/**
* Form Field class for the FOF framework
* Media selection field.
*
* @deprecated 3.1 Support for XML forms will be removed in FOF 4
*/
class Media extends \JFormFieldMedia implements FieldInterface
{
/**
* @var string Static field output
*/
protected $static;
/**
* @var string Repeatable field output
*/
protected $repeatable;
/**
* The Form object of the form attached to the form field.
*
* @var Form
*/
protected $form;
/**
* A monotonically increasing number, denoting the row number in a repeatable view
*
* @var int
*/
public $rowid;
/**
* The item being rendered in a repeatable form field
*
* @var DataModel
*/
public $item;
/**
* Method to get certain otherwise inaccessible properties from the form field object.
*
* @param string $name The property name for which to the the value.
*
* @return mixed The property value or null.
*
* @since 2.0
*/
public function __get($name)
{
switch ($name)
{
case 'static':
if (empty($this->static))
{
$this->static = $this->getStatic();
}
return $this->static;
break;
case 'repeatable':
if (empty($this->repeatable))
{
$this->repeatable = $this->getRepeatable();
}
return $this->repeatable;
break;
default:
return parent::__get($name);
}
}
/**
* Get the rendering of this field type for static display, e.g. in a single
* item view (typically a "read" task).
*
* @since 2.0
*
* @return string The field HTML
*/
public function getStatic()
{
if (isset($this->element['legacy']))
{
return $this->getInput();
}
$options = array(
'id' => $this->id
);
return $this->getFieldContents($options);
}
/**
* 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
*/
public function getRepeatable()
{
if (isset($this->element['legacy']))
{
return $this->getInput();
}
$options = array(
'class' => $this->id
);
return $this->getFieldContents($options);
}
/**
* 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 '';
}
}
Field/Radio.php 0000644 00000006022 15235405654 0007347 0 ustar 00 <?php
/**
* @package FOF
* @copyright Copyright (c)2010-2019 Nicholas K. Dionysopoulos / Akeeba Ltd
* @license GNU GPL version 2 or later
*/
namespace FOF30\Form\Field;
use FOF30\Form\FieldInterface;
use FOF30\Form\Form;
use FOF30\Model\DataModel;
defined('_JEXEC') or die;
\JFormHelper::loadFieldClass('radio');
/**
* Form Field class for FOF
* Radio selection list
*
* @deprecated 3.1 Support for XML forms will be removed in FOF 4
*/
class Radio extends \JFormFieldRadio implements FieldInterface
{
/**
* @var string Static field output
*/
protected $static;
/**
* @var string Repeatable field output
*/
protected $repeatable;
/**
* The Form object of the form attached to the form field.
*
* @var Form
*/
protected $form;
/**
* A monotonically increasing number, denoting the row number in a repeatable view
*
* @var int
*/
public $rowid;
/**
* The item being rendered in a repeatable form field
*
* @var DataModel
*/
public $item;
/**
* Method to get certain otherwise inaccessible properties from the form field object.
*
* @param string $name The property name for which to the the value.
*
* @return mixed The property value or null.
*
* @since 2.0
*/
public function __get($name)
{
switch ($name)
{
case 'static':
if (empty($this->static))
{
$this->static = $this->getStatic();
}
return $this->static;
break;
case 'repeatable':
if (empty($this->repeatable))
{
$this->repeatable = $this->getRepeatable();
}
return $this->repeatable;
break;
default:
return parent::__get($name);
}
}
/**
* Get the rendering of this field type for static display, e.g. in a single
* item view (typically a "read" task).
*
* @since 2.0
*
* @return string The field HTML
*/
public function getStatic()
{
if (isset($this->element['legacy']))
{
return $this->getInput();
}
$options = array(
'id' => $this->id
);
return $this->getFieldContents($options);
}
/**
* 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
*/
public function getRepeatable()
{
if (isset($this->element['legacy']))
{
return $this->getInput();
}
$options = array(
'class' => $this->id
);
return $this->getFieldContents($options);
}
/**
* 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'] : '');
return '<span ' . ($id ? $id : '') . 'class="' . $class . '">' .
htmlspecialchars(GenericList::getOptionName($this->getOptions(), $this->value), ENT_COMPAT, 'UTF-8') .
'</span>';
}
}
Field/Url.php 0000644 00000011577 15235405654 0007066 0 ustar 00 <?php
/**
* @package FOF
* @copyright Copyright (c)2010-2019 Nicholas K. Dionysopoulos / Akeeba Ltd
* @license GNU GPL version 2 or later
*/
namespace FOF30\Form\Field;
use FOF30\Form\FieldInterface;
use FOF30\Form\Form;
use FOF30\Model\DataModel;
use JText;
defined('_JEXEC') or die;
\JFormHelper::loadFieldClass('url');
/**
* Form Field class for the FOF framework
* Supports a URL text field.
*
* @deprecated 3.1 Support for XML forms will be removed in FOF 4
*/
class Url extends \JFormFieldUrl implements FieldInterface
{
/**
* @var string Static field output
*/
protected $static;
/**
* @var string Repeatable field output
*/
protected $repeatable;
/**
* The Form object of the form attached to the form field.
*
* @var Form
*/
protected $form;
/**
* A monotonically increasing number, denoting the row number in a repeatable view
*
* @var int
*/
public $rowid;
/**
* The item being rendered in a repeatable form field
*
* @var DataModel
*/
public $item;
/**
* Method to get certain otherwise inaccessible properties from the form field object.
*
* @param string $name The property name for which to the the value.
*
* @return mixed The property value or null.
*
* @since 2.0
*/
public function __get($name)
{
switch ($name)
{
case 'static':
if (empty($this->static))
{
$this->static = $this->getStatic();
}
return $this->static;
break;
case 'repeatable':
if (empty($this->repeatable))
{
$this->repeatable = $this->getRepeatable();
}
return $this->repeatable;
break;
default:
return parent::__get($name);
}
}
/**
* Get the rendering of this field type for static display, e.g. in a single
* item view (typically a "read" task).
*
* @since 2.0
*
* @return string The field HTML
*/
public function getStatic()
{
if (isset($this->element['legacy']))
{
return $this->getInput();
}
$options = array(
'id' => $this->id
);
return $this->getFieldContents($options);
}
/**
* 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
*/
public function getRepeatable()
{
if (isset($this->element['legacy']))
{
return $this->getInput();
}
$options = array(
'class' => $this->id
);
return $this->getFieldContents($options);
}
/**
* 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'] : '');
$show_link = $this->element['show_link'] == 'true';
$empty_replacement = $this->element['empty_replacement'] ? (string) $this->element['empty_replacement'] : '';
if (!empty($empty_replacement) && empty($this->value))
{
$this->value = JText::_($empty_replacement);
}
$value = htmlspecialchars($this->value, ENT_COMPAT, 'UTF-8');
$html = $value;
if ($show_link)
{
if ($this->element['url'])
{
$link_url = $this->parseFieldTags((string) $this->element['url']);
}
else
{
$link_url = $value;
}
$html = '<a href="' . $link_url . '">' .
$value . '</a>';
}
return '<span ' . ($id ? $id : '') . 'class="' . $class . '"">' .
$html .
'</span>';
}
/**
* 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;
}
}
Field/Language.php 0000644 00000007400 15235405654 0010035 0 ustar 00 <?php
/**
* @package FOF
* @copyright Copyright (c)2010-2019 Nicholas K. Dionysopoulos / Akeeba Ltd
* @license GNU GPL version 2 or later
*/
namespace FOF30\Form\Field;
use FOF30\Form\FieldInterface;
use FOF30\Form\Form;
use FOF30\Model\DataModel;
use JHtml;
use JText;
defined('_JEXEC') or die;
\JFormHelper::loadFieldClass('language');
/**
* Form Field class for FOF
* Available site languages
*
* @deprecated 3.1 Support for XML forms will be removed in FOF 4
*/
class Language extends \JFormFieldLanguage implements FieldInterface
{
protected static $cachedOptions = array();
/**
* @var string Static field output
*/
protected $static;
/**
* @var string Repeatable field output
*/
protected $repeatable;
/**
* The Form object of the form attached to the form field.
*
* @var Form
*/
protected $form;
/**
* A monotonically increasing number, denoting the row number in a repeatable view
*
* @var int
*/
public $rowid;
/**
* The item being rendered in a repeatable form field
*
* @var DataModel
*/
public $item;
/**
* Method to get certain otherwise inaccessible properties from the form field object.
*
* @param string $name The property name for which to the the value.
*
* @return mixed The property value or null.
*
* @since 2.0
*/
public function __get($name)
{
switch ($name)
{
case 'static':
if (empty($this->static))
{
$this->static = $this->getStatic();
}
return $this->static;
break;
case 'repeatable':
if (empty($this->repeatable))
{
$this->repeatable = $this->getRepeatable();
}
return $this->repeatable;
break;
default:
return parent::__get($name);
}
}
/**
* Method to get the field options.
*
* @since 2.0
*
* @return array The field option objects.
*/
protected function getOptions()
{
$client = (string) $this->element['client'];
if ($client != 'site' && $client != 'administrator')
{
$client = 'site';
}
if (!isset(static::$cachedOptions[$client]))
{
static::$cachedOptions[$client] = parent::getOptions();
}
$options = array_merge(static::$cachedOptions[$client]);
$noneoption = $this->element['none'] ? $this->element['none'] : null;
if ($noneoption)
{
array_unshift($options, JHtml::_('select.option', '*', JText::_($noneoption)));
}
return $options;
}
/**
* Get the rendering of this field type for static display, e.g. in a single
* item view (typically a "read" task).
*
* @since 2.0
*
* @return string The field HTML
*/
public function getStatic()
{
if (isset($this->element['legacy']))
{
return $this->getInput();
}
$options = array(
'id' => $this->id
);
return $this->getFieldContents($options);
}
/**
* 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
*/
public function getRepeatable()
{
if (isset($this->element['legacy']))
{
return $this->getInput();
}
$options = array(
'class' => $this->id
);
return $this->getFieldContents($options);
}
/**
* 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'] : '');
return '<span ' . ($id ? $id : '') . 'class="' . $class . '">' .
htmlspecialchars(GenericList::getOptionName($this->getOptions(), $this->value), ENT_COMPAT, 'UTF-8') .
'</span>';
}
}
Field/Model.php 0000644 00000020602 15235405654 0007351 0 ustar 00 <?php
/**
* @package FOF
* @copyright Copyright (c)2010-2019 Nicholas K. Dionysopoulos / Akeeba Ltd
* @license GNU GPL version 2 or later
*/
namespace FOF30\Form\Field;
use FOF30\Container\Container;
use FOF30\Form\FieldInterface;
use FOF30\Form\Form;
use FOF30\Model\DataModel;
use FOF30\Utils\StringHelper;
use JHtml;
use JText;
defined('_JEXEC') or die;
\JFormHelper::loadFieldClass('list');
/**
* Form Field class for FOF
* Generic list from a model's results
*
* @deprecated 3.1 Support for XML forms will be removed in FOF 4
*/
class Model extends GenericList implements FieldInterface
{
/**
* @var string Static field output
*/
protected $static;
/**
* @var string Repeatable field output
*/
protected $repeatable;
/**
* The Form object of the form attached to the form field.
*
* @var Form
*/
protected $form;
/**
* A monotonically increasing number, denoting the row number in a repeatable view
*
* @var int
*/
public $rowid;
/**
* The item being rendered in a repeatable form field
*
* @var DataModel
*/
public $item;
/**
* Options loaded from the model, cached for efficiency
*
* @var null|array
*/
protected static $loadedOptions = null;
/**
* Method to get certain otherwise inaccessible properties from the form field object.
*
* @param string $name The property name for which to the the value.
*
* @return mixed The property value or null.
*
* @since 2.0
*/
public function __get($name)
{
switch ($name)
{
case 'static':
if (empty($this->static))
{
$this->static = $this->getStatic();
}
return $this->static;
break;
case 'repeatable':
if (empty($this->repeatable))
{
$this->repeatable = $this->getRepeatable();
}
return $this->repeatable;
break;
default:
return parent::__get($name);
}
}
/**
* Get the rendering of this field type for static display, e.g. in a single
* item view (typically a "read" task).
*
* @since 2.0
*
* @return string The field HTML
*/
public function getStatic()
{
$class = $this->class ? 'class="' . $this->class . '"' : '';
return '<span id="' . $this->id . '" ' . $class . '>' .
htmlspecialchars(GenericList::getOptionName($this->getOptions(), $this->value), ENT_COMPAT, 'UTF-8') .
'</span>';
}
/**
* 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
*/
public function getRepeatable()
{
// Get field parameters
$class = $this->class ? $this->class : $this->id;
$format_string = $this->element['format'] ? (string) $this->element['format'] : '';
$link_url = $this->element['url'] ? (string) $this->element['url'] : '';
$empty_replacement = $this->element['empty_replacement'] ? (string) $this->element['empty_replacement'] : '';
if ($link_url && ($this->item instanceof DataModel))
{
$link_url = $this->parseFieldTags($link_url);
}
else
{
$link_url = false;
}
if ($this->element['empty_replacement'])
{
$empty_replacement = (string) $this->element['empty_replacement'];
}
// Ask GenericList::getOptionName to not automatically select the first value
$value = GenericList::getOptionName($this->getOptions(), $this->value, 'value', 'text', false);
// Get the (optionally formatted) value
if (!empty($empty_replacement) && empty($value))
{
$value = JText::_($empty_replacement);
}
if (empty($format_string))
{
$value = htmlspecialchars($value, ENT_COMPAT, 'UTF-8');
}
else
{
$value = sprintf($format_string, $value);
}
// Create the HTML
$html = '<span class="' . $class . '">';
if ($link_url)
{
$html .= '<a href="' . $link_url . '">';
}
$html .= $value;
if ($link_url)
{
$html .= '</a>';
}
$html .= '</span>';
return $html;
}
/**
* Method to get the field options.
*
* @param bool $forceReset
*
* @return array The field option objects.
*/
protected function getOptions($forceReset = false)
{
$myFormKey = $this->form->getName() . '#$#' . (string) $this->element['model'];
if ($forceReset && isset(static::$loadedOptions[$myFormKey]))
{
unset(static::$loadedOptions[$myFormKey]);
}
if (!isset(static::$loadedOptions[$myFormKey]))
{
$options = array();
// Initialize some field attributes.
$key = $this->element['key_field'] ? (string) $this->element['key_field'] : 'value';
$value = $this->element['value_field'] ? (string) $this->element['value_field'] : (string) $this->element['name'];
$valueReplace = StringHelper::toBool($this->element['parse_value']);
$translate = StringHelper::toBool($this->element['translate']);
$applyAccess = StringHelper::toBool($this->element['apply_access']);
$modelName = (string) $this->element['model'];
$nonePlaceholder = (string) $this->element['none'];
$with = $this->element['with'] ? (string) $this->element['with'] : null;
if (!is_null($with))
{
$with = trim($with);
$with = explode(',', $with);
$with = array_map('trim', $with);
}
if (!empty($nonePlaceholder))
{
$options[] = JHtml::_('select.option', null, JText::_($nonePlaceholder));
}
// Explode model name into component name and prefix
$componentName = $this->form->getContainer()->componentName;
$mName = $modelName;
if (strpos($modelName, '.') !== false)
{
list ($componentName, $mName) = explode('.', $mName, 2);
}
// Get the applicable container
$container = $this->form->getContainer();
if ($componentName != $container->componentName)
{
$container = Container::getInstance($componentName);
}
/** @var DataModel $model */
$model = $container->factory->model($mName)->setIgnoreRequest(true)->savestate(false);
// Get the model object
if ($applyAccess)
{
$model->applyAccessFiltering();
}
if (!is_null($with))
{
$model->with($with);
}
// Process state variables
/** @var \SimpleXMLElement $stateoption */
foreach ($this->element->children() as $stateoption)
{
// Only add <state /> elements.
if ($stateoption->getName() != 'state')
{
continue;
}
$stateKey = (string) $stateoption['key'];
$stateValue = (string) $stateoption;
$model->setState($stateKey, $stateValue);
}
// Set the query and get the result list.
$items = $model->get(true);
// Build the field options.
if (!empty($items))
{
foreach ($items as $item)
{
if ($translate == true)
{
$options[] = JHtml::_('select.option', $item->$key, JText::_($item->$value));
}
else
{
if ($valueReplace)
{
$text = $this->parseFieldTags($value, $item);
}
else
{
$text = $item->$value;
}
$options[] = JHtml::_('select.option', $item->$key, $text);
}
}
}
// Merge any additional options in the XML definition.
$options = array_merge(parent::getOptions(), $options);
static::$loadedOptions[$myFormKey] = $options;
}
return static::$loadedOptions[$myFormKey];
}
/**
* Replace string with tags that reference fields
*
* @param string $text Text to process
*
* @return string Text with tags replace
*/
protected function parseFieldTags($text, $item = null)
{
$ret = $text;
if ($item)
{
$this->item = $item;
}
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;
}
}
Field/SessionHandler.php 0000644 00000006062 15235405654 0011236 0 ustar 00 <?php
/**
* @package FOF
* @copyright Copyright (c)2010-2019 Nicholas K. Dionysopoulos / Akeeba Ltd
* @license GNU GPL version 2 or later
*/
namespace FOF30\Form\Field;
use FOF30\Form\FieldInterface;
use FOF30\Form\Form;
use FOF30\Model\DataModel;
defined('_JEXEC') or die;
\JFormHelper::loadFieldClass('sessionhandler');
/**
* Form Field class for FOF
* Joomla! session handlers
*
* @deprecated 3.1 Support for XML forms will be removed in FOF 4
*/
class SessionHandler extends \JFormFieldSessionHandler implements FieldInterface
{
/**
* @var string Static field output
*/
protected $static;
/**
* @var string Repeatable field output
*/
protected $repeatable;
/**
* The Form object of the form attached to the form field.
*
* @var Form
*/
protected $form;
/**
* A monotonically increasing number, denoting the row number in a repeatable view
*
* @var int
*/
public $rowid;
/**
* The item being rendered in a repeatable form field
*
* @var DataModel
*/
public $item;
/**
* Method to get certain otherwise inaccessible properties from the form field object.
*
* @param string $name The property name for which to the the value.
*
* @return mixed The property value or null.
*
* @since 2.0
*/
public function __get($name)
{
switch ($name)
{
case 'static':
if (empty($this->static))
{
$this->static = $this->getStatic();
}
return $this->static;
break;
case 'repeatable':
if (empty($this->repeatable))
{
$this->repeatable = $this->getRepeatable();
}
return $this->repeatable;
break;
default:
return parent::__get($name);
}
}
/**
* Get the rendering of this field type for static display, e.g. in a single
* item view (typically a "read" task).
*
* @since 2.0
*
* @return string The field HTML
*/
public function getStatic()
{
if (isset($this->element['legacy']))
{
return $this->getInput();
}
$options = array(
'id' => $this->id
);
return $this->getFieldContents($options);
}
/**
* 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
*/
public function getRepeatable()
{
if (isset($this->element['legacy']))
{
return $this->getInput();
}
$options = array(
'class' => $this->id
);
return $this->getFieldContents($options);
}
/**
* 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'] : '');
return '<span ' . ($id ? $id : '') . 'class="' . $class . '">' .
htmlspecialchars(GenericList::getOptionName($this->getOptions(), $this->value), ENT_COMPAT, 'UTF-8') .
'</span>';
}
}
Field/Text.php 0000644 00000017356 15235405654 0007251 0 ustar 00 <?php
/**
* @package FOF
* @copyright Copyright (c)2010-2019 Nicholas K. Dionysopoulos / Akeeba Ltd
* @license GNU GPL version 2 or later
*/
namespace FOF30\Form\Field;
use FOF30\Form\FieldInterface;
use FOF30\Form\Form;
use FOF30\Model\DataModel;
use JText;
defined('_JEXEC') or die;
\JFormHelper::loadFieldClass('text');
/**
* Form Field class for the FOF framework
* Supports a one line text field.
*
* @deprecated 3.1 Support for XML forms will be removed in FOF 4
*/
class Text extends \JFormFieldText implements FieldInterface
{
/**
* @var string Static field output
*/
protected $static;
/**
* @var string Repeatable field output
*/
protected $repeatable;
/**
* The Form object of the form attached to the form field.
*
* @var Form
*/
protected $form;
/**
* A monotonically increasing number, denoting the row number in a repeatable view
*
* @var int
*/
public $rowid;
/**
* The item being rendered in a repeatable form field
*
* @var DataModel
*/
public $item;
/**
* Method to get certain otherwise inaccessible properties from the form field object.
*
* @param string $name The property name for which to the the value.
*
* @return mixed The property value or null.
*
* @since 2.0
*/
public function __get($name)
{
switch ($name)
{
case 'static':
if (empty($this->static))
{
$this->static = $this->getStatic();
}
return $this->static;
break;
case 'repeatable':
if (empty($this->repeatable))
{
$this->repeatable = $this->getRepeatable();
}
return $this->repeatable;
break;
default:
return parent::__get($name);
}
}
/**
* Get the rendering of this field type for static display, e.g. in a single
* item view (typically a "read" task).
*
* @since 2.0
*
* @return string The field HTML
*/
public function getStatic()
{
if (is_array($this->value))
{
$this->value = empty($this->value) ? '' : print_r($this->value, true);
}
if (isset($this->element['legacy']))
{
return $this->getInput();
}
$class = $this->class ? ' class="' . $this->class . '"' : '';
$empty_replacement = $this->element['empty_replacement'] ? (string) $this->element['empty_replacement'] : '';
if (!empty($empty_replacement) && empty($this->value))
{
$this->value = JText::_($empty_replacement);
}
return '<span id="' . $this->id . '" ' . $class . '>' .
htmlspecialchars($this->value, ENT_COMPAT, 'UTF-8') .
'</span>';
}
/**
* 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
*/
public function getRepeatable()
{
if (is_array($this->value))
{
$this->value = print_r($this->value, true);
}
if (isset($this->element['legacy']))
{
return $this->getInput();
}
// 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));
}
// Initialise
$class = $this->class ? $this->class : $this->id;
$format_string = $this->element['format'] ? (string) $this->element['format'] : '';
$format_if_not_empty = in_array((string) $this->element['format_if_not_empty'], array('true', '1', 'on', 'yes'));
$parse_value = in_array((string) $this->element['parse_value'], array('true', '1', 'on', 'yes'));
$link_url = $this->element['url'] ? (string) $this->element['url'] : '';
$empty_replacement = $this->element['empty_replacement'] ? (string) $this->element['empty_replacement'] : '';
$format_source_file = empty($this->element['format_source_file']) ? '' : (string) $this->element['format_source_file'];
$format_source_class = empty($this->element['format_source_class']) ? '' : (string) $this->element['format_source_class'];
$format_source_method = empty($this->element['format_source_method']) ? '' : (string) $this->element['format_source_method'];
if ($link_url && ($this->item instanceof DataModel))
{
$link_url = $this->parseFieldTags($link_url);
}
else
{
$link_url = false;
}
// Get the (optionally formatted) value
$value = $this->value;
if (!empty($empty_replacement) && empty($this->value))
{
$value = JText::_($empty_replacement);
}
if ($parse_value)
{
$value = $this->parseFieldTags($value);
}
if (!empty($format_string) && (!$format_if_not_empty || ($format_if_not_empty && !empty($this->value))))
{
$format_string = $this->parseFieldTags($format_string);
$value = sprintf($format_string, $value);
}
elseif ($format_source_class && $format_source_method)
{
// Maybe we have to load a file?
if (!empty($format_source_file))
{
$format_source_file = $this->form->getContainer()->template->parsePath($format_source_file, true);
if ($this->form->getContainer()->filesystem->fileExists($format_source_file))
{
include_once $format_source_file;
}
}
// Make sure the class and method exist
if (class_exists($format_source_class, true) && in_array($format_source_method, get_class_methods($format_source_class)))
{
$value = $format_source_class::$format_source_method($value);
$value = $this->parseFieldTags($value);
}
else
{
$value = htmlspecialchars($value, ENT_COMPAT, 'UTF-8');
}
}
else
{
$value = htmlspecialchars($value, ENT_COMPAT, 'UTF-8');
}
// Create the HTML
$html = '<span class="' . $class . '">';
$userId = $this->form->getContainer()->platform->getUser()->id;
if ($checkoutSupport && $this->item->isLocked($userId))
{
$key_field = $this->item->getKeyName();
$key_id = $this->item->$key_field;
$lockedBy = '';
$lockedOn = '';
if ($this->item->hasField('locked_by'))
{
$lockedUser = $this->form->getContainer()->platform->getUser($this->item->getFieldValue('locked_by'));
$lockedBy = $lockedUser->name . ' (' . $lockedUser->username . ')';
}
if ($this->item->hasField('locked_on'))
{
$lockedOn = $this->item->getFieldValue('locked_on');
}
$html .= \JHtml::_('jgrid.checkedout', $key_id, $lockedBy, $lockedOn, '', true);
}
if ($link_url)
{
$html .= '<a href="' . $link_url . '">';
}
$html .= $value;
if ($link_url)
{
$html .= '</a>';
}
$html .= '</span>';
return $html;
}
/**
* 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;
}
}
Field/UserGroup.php 0000644 00000010732 15235405654 0010247 0 ustar 00 <?php
/**
* @package FOF
* @copyright Copyright (c)2010-2019 Nicholas K. Dionysopoulos / Akeeba Ltd
* @license GNU GPL version 2 or later
*/
namespace FOF30\Form\Field;
use FOF30\Form\FieldInterface;
use FOF30\Form\Form;
use FOF30\Model\DataModel;
use JHtml;
use JText;
defined('_JEXEC') or die;
\JFormHelper::loadFieldClass('usergroup');
/**
* Form Field class for FOF
* Joomla! user groups
*
* @deprecated 3.1 Support for XML forms will be removed in FOF 4
*/
class UserGroup extends \JFormFieldUsergroup implements FieldInterface
{
/**
* @var string Static field output
*/
protected $static;
/**
* @var string Repeatable field output
*/
protected $repeatable;
/**
* The Form object of the form attached to the form field.
*
* @var Form
*/
protected $form;
/**
* A monotonically increasing number, denoting the row number in a repeatable view
*
* @var int
*/
public $rowid;
/**
* The item being rendered in a repeatable form field
*
* @var DataModel
*/
public $item;
/**
* Method to get certain otherwise inaccessible properties from the form field object.
*
* @param string $name The property name for which to the the value.
*
* @return mixed The property value or null.
*
* @since 2.0
*/
public function __get($name)
{
switch ($name)
{
case 'static':
if (empty($this->static))
{
$this->static = $this->getStatic();
}
return $this->static;
break;
case 'repeatable':
if (empty($this->repeatable))
{
$this->repeatable = $this->getRepeatable();
}
return $this->repeatable;
break;
default:
return parent::__get($name);
}
}
/**
* Get the rendering of this field type for static display, e.g. in a single
* item view (typically a "read" task).
*
* @since 2.0
*
* @return string The field HTML
*/
public function getStatic()
{
if (isset($this->element['legacy']))
{
return $this->getInput();
}
$class = $this->class ? ' class="' . $this->class . '"' : '';
$params = $this->getOptions();
$db = $this->form->getContainer()->platform->getDbo();
$query = $db->getQuery(true)
->select('a.id AS value, a.title AS text')
->from('#__usergroups AS a')
->group('a.id, a.title')
->order('a.id 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);
}
// If all levels is allowed, push it into the array.
elseif ($params)
{
array_unshift($options, JHtml::_('select.option', '', JText::_('JOPTION_ACCESS_SHOW_ALL_LEVELS')));
}
return '<span id="' . $this->id . '" ' . $class . '>' .
htmlspecialchars(GenericList::getOptionName($options, $this->value), ENT_COMPAT, 'UTF-8') .
'</span>';
}
/**
* 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
*/
public function getRepeatable()
{
if (isset($this->element['legacy']))
{
return $this->getInput();
}
$class = $this->class ? $this->class : '';
$db = $this->form->getContainer()->platform->getDbo();
$query = $db->getQuery(true)
->select('a.id AS value, a.title AS text')
->from('#__usergroups AS a')
->group('a.id, a.title')
->order('a.id ASC')
->order($db->qn('title') . ' ASC');
// Get the options.
$options = $db->setQuery($query)->loadObjectList();
return '<span class="' . $this->id . ' ' . $class . '">' .
htmlspecialchars(GenericList::getOptionName($options, $this->value), ENT_COMPAT, 'UTF-8') .
'</span>';
}
/**
* 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;
}
}
}
Field/Published.php 0000644 00000012255 15235405654 0010235 0 ustar 00 <?php
/**
* @package FOF
* @copyright Copyright (c)2010-2019 Nicholas K. Dionysopoulos / Akeeba Ltd
* @license GNU GPL version 2 or later
*/
namespace FOF30\Form\Field;
use FOF30\Form\Exception\DataModelRequired;
use FOF30\Form\FieldInterface;
use FOF30\Form\Form;
use FOF30\Model\DataModel;
use JHtml;
use JText;
defined('_JEXEC') or die;
\JFormHelper::loadFieldClass('list');
/**
* Form Field class for FOF
* Supports a generic list of options.
*
* @deprecated 3.1 Support for XML forms will be removed in FOF 4
*/
class Published extends \JFormFieldList implements FieldInterface
{
/**
* @var string Static field output
*/
protected $static;
/**
* @var string Repeatable field output
*/
protected $repeatable;
/**
* The Form object of the form attached to the form field.
*
* @var Form
*/
protected $form;
/**
* A monotonically increasing number, denoting the row number in a repeatable view
*
* @var int
*/
public $rowid;
/**
* The item being rendered in a repeatable form field
*
* @var DataModel
*/
public $item;
/**
* Method to get certain otherwise inaccessible properties from the form field object.
*
* @param string $name The property name for which to the the value.
*
* @return mixed The property value or null.
*
* @since 2.0
*/
public function __get($name)
{
switch ($name)
{
case 'static':
if (empty($this->static))
{
$this->static = $this->getStatic();
}
return $this->static;
break;
case 'repeatable':
if (empty($this->repeatable))
{
$this->repeatable = $this->getRepeatable();
}
return $this->repeatable;
break;
default:
return parent::__get($name);
}
}
/**
* Method to get the field options.
*
* @since 2.0
*
* @return array The field option objects.
*/
protected function getOptions()
{
$options = parent::getOptions();
if (!empty($options))
{
return $options;
}
// If no custom options were defined let's figure out which ones of the
// defaults we shall use...
$config = array(
'published' => 1,
'unpublished' => 1,
'archived' => 0,
'trash' => 0,
'all' => 0,
);
$configMap = array(
'show_published' => array('published', 1),
'show_unpublished' => array('unpublished', 1),
'show_archived' => array('archived', 0),
'show_trash' => array('trash', 0),
'show_all' => array('all', 0),
);
foreach ($configMap as $attribute => $preferences)
{
list($configKey, $default) = $preferences;
switch (strtolower($this->element[$attribute]))
{
case 'true':
case '1':
case 'yes':
$config[$configKey] = true;
break;
case 'false':
case '0':
case 'no':
$config[$configKey] = false;
break;
default:
$config[$configKey] = $default;
}
}
$stack = array();
if ($config['published'])
{
$stack[] = JHtml::_('select.option', '1', JText::_('JPUBLISHED'));
}
if ($config['unpublished'])
{
$stack[] = JHtml::_('select.option', '0', JText::_('JUNPUBLISHED'));
}
if ($config['archived'])
{
$stack[] = JHtml::_('select.option', '2', JText::_('JARCHIVED'));
}
if ($config['trash'])
{
$stack[] = JHtml::_('select.option', '-2', JText::_('JTRASHED'));
}
if ($config['all'])
{
$stack[] = JHtml::_('select.option', '*', JText::_('JALL'));
}
return $stack;
}
/**
* Get the rendering of this field type for static display, e.g. in a single
* item view (typically a "read" task).
*
* @since 2.0
*
* @return string The field HTML
*/
public function getStatic()
{
$class = $this->class ? ' class="' . $this->class . '"' : '';
return '<span id="' . $this->id . '" ' . $class . '>' .
htmlspecialchars(GenericList::getOptionName($this->getOptions(), $this->value), ENT_COMPAT, 'UTF-8') .
'</span>';
}
/**
* 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()
{
if (!($this->item instanceof DataModel))
{
throw new DataModelRequired(__CLASS__);
}
$prefix = $this->element['prefix'] ? (string) $this->element['prefix'] : '';
$checkbox = $this->element['checkbox'] ? (string) $this->element['checkbox'] : 'cb';
$publish_up = $this->element['publish_up'] ? (string) $this->element['publish_up'] : null;
$publish_down = $this->element['publish_down'] ? (string) $this->element['publish_down'] : null;
$container = $this->form->getContainer();
$privilege = $this->element['acl_privilege'] ? $this->element['acl_privilege'] : 'core.edit.state';
$component = $this->element['acl_component'] ? $this->element['acl_component'] : $container->componentName;
$component = empty($component) ? null : $component;
$enabled = $container->platform->getUser()->authorise($privilege, $component);
// @todo Enforce ACL checks to determine if the field should be enabled or not
// Get the HTML
return JHTML::_('jgrid.published', $this->value, $this->rowid, $prefix, $enabled, $checkbox, $publish_up, $publish_down);
}
}
Field/Checkbox.php 0000644 00000007315 15235405654 0010045 0 ustar 00 <?php
/**
* @package FOF
* @copyright Copyright (c)2010-2019 Nicholas K. Dionysopoulos / Akeeba Ltd
* @license GNU GPL version 2 or later
*/
namespace FOF30\Form\Field;
use FOF30\Form\FieldInterface;
use FOF30\Form\Form;
use FOF30\Model\DataModel;
defined('_JEXEC') or die;
\JFormHelper::loadFieldClass('checkbox');
/**
* Form Field class for the FOF framework
* A single checkbox
*
* @deprecated 3.1 Support for XML forms will be removed in FOF 4
*/
class Checkbox extends \JFormFieldCheckbox implements FieldInterface
{
/**
* @var string Static field output
*/
protected $static;
/**
* @var string Repeatable field output
*/
protected $repeatable;
/**
* The Form object of the form attached to the form field.
*
* @var Form
*/
protected $form;
/**
* A monotonically increasing number, denoting the row number in a repeatable view
*
* @var int
*/
public $rowid;
/**
* The item being rendered in a repeatable form field
*
* @var DataModel
*/
public $item;
/**
* Method to get certain otherwise inaccessible properties from the form field object.
*
* @param string $name The property name for which to the the value.
*
* @return mixed The property value or null.
*
* @since 2.0
*/
public function __get($name)
{
switch ($name)
{
case 'static':
if (empty($this->static))
{
$this->static = $this->getStatic();
}
return $this->static;
break;
case 'repeatable':
if (empty($this->repeatable))
{
$this->repeatable = $this->getRepeatable();
}
return $this->repeatable;
break;
default:
return parent::__get($name);
}
}
/**
* Get the rendering of this field type for static display, e.g. in a single
* item view (typically a "read" task).
*
* @since 2.0
*
* @return string The field HTML
*/
public function getStatic()
{
if (isset($this->element['legacy']))
{
return $this->getInput();
}
$options = array(
'id' => $this->id
);
return $this->getFieldContents($options);
}
/**
* 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
*/
public function getRepeatable()
{
if (isset($this->element['legacy']))
{
return $this->getInput();
}
$options = array(
'class' => $this->id
);
return $this->getFieldContents($options);
}
/**
* 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'] : '');
$value = $this->element['value'] ? (string) $this->element['value'] : '1';
$disabled = $this->disabled ? ' disabled="disabled"' : '';
$required = $this->required ? ' required="required" aria-required="true"' : '';
$autofocus = $this->autofocus ? ' autofocus' : '';
$checked = $this->checked || !empty($this->value) ? ' checked' : '';
$onchange = $this->onchange ? ' onchange="' . $this->onchange . '"' : '';
$onclick = $this->onclick ? ' onclick="' . $this->onclick . '"' : '';
return '<span ' . ($id ? $id : '') . 'class="' . $class . '">' .
'<input type="checkbox" name="' . $this->name . '" ' . ($id ? $id : '') . 'class="' . $this->id . ' ' . $class . '"' . ' value="'
. htmlspecialchars($value, ENT_COMPAT, 'UTF-8') . '"' . $checked . $disabled . $onclick . $onchange
. $required . $autofocus . ' />' .
'</span>';
}
}
Field/ImageList.php 0000644 00000010433 15235405654 0010170 0 ustar 00 <?php
/**
* @package FOF
* @copyright Copyright (c)2010-2019 Nicholas K. Dionysopoulos / Akeeba Ltd
* @license GNU GPL version 2 or later
*/
namespace FOF30\Form\Field;
use FOF30\Form\FieldInterface;
use FOF30\Form\Form;
use FOF30\Model\DataModel;
use JHtml;
use JText;
defined('_JEXEC') or die;
\JFormHelper::loadFieldClass('imagelist');
/**
* Form Field class for the FOF framework
* Media selection field.
*
* @deprecated 3.1 Support for XML forms will be removed in FOF 4
*/
class ImageList extends \JFormFieldImageList implements FieldInterface
{
/**
* @var string Static field output
*/
protected $static;
/**
* @var string Repeatable field output
*/
protected $repeatable;
/**
* The Form object of the form attached to the form field.
*
* @var Form
*/
protected $form;
/**
* A monotonically increasing number, denoting the row number in a repeatable view
*
* @var int
*/
public $rowid;
/**
* The item being rendered in a repeatable form field
*
* @var DataModel
*/
public $item;
/**
* Method to get certain otherwise inaccessible properties from the form field object.
*
* @param string $name The property name for which to the the value.
*
* @return mixed The property value or null.
*
* @since 2.0
*/
public function __get($name)
{
switch ($name)
{
case 'static':
if (empty($this->static))
{
$this->static = $this->getStatic();
}
return $this->static;
break;
case 'repeatable':
if (empty($this->repeatable))
{
$this->repeatable = $this->getRepeatable();
}
return $this->repeatable;
break;
default:
return parent::__get($name);
}
}
/**
* Get the rendering of this field type for static display, e.g. in a single
* item view (typically a "read" task).
*
* @since 2.0
*
* @return string The field HTML
*/
public function getStatic()
{
if (isset($this->element['legacy']))
{
return $this->getInput();
}
$options = array(
'id' => $this->id
);
return $this->getFieldContents($options);
}
/**
* 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
*/
public function getRepeatable()
{
if (isset($this->element['legacy']))
{
return $this->getInput();
}
$options = array(
'class' => $this->id
);
return $this->getFieldContents($options);
}
/**
* 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();
$alt = null;
if (isset($fieldOptions['id']) && $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']);
}
if ($this->element['title'])
{
$imgattr['title'] = JText::_((string) $this->element['title']);
}
$path = (string) $this->element['directory'];
$path = trim($path, '/' . DIRECTORY_SEPARATOR);
$platform = $this->form->getContainer()->platform;
$baseDirs = $platform->getPlatformBaseDirs();
if ($this->value && file_exists($baseDirs['root'] . '/' . $path . '/' . $this->value))
{
$src = $platform->URIroot() . '/' . $path . '/' . $this->value;
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 '';
}
}
Field/Spacer.php 0000644 00000004270 15235405654 0007531 0 ustar 00 <?php
/**
* @package FOF
* @copyright Copyright (c)2010-2019 Nicholas K. Dionysopoulos / Akeeba Ltd
* @license GNU GPL version 2 or later
*/
namespace FOF30\Form\Field;
use FOF30\Form\FieldInterface;
use FOF30\Form\Form;
use FOF30\Model\DataModel;
defined('_JEXEC') or die;
\JFormHelper::loadFieldClass('spacer');
/**
* Form Field class for the FOF framework
* Spacer used between form elements
*
* @deprecated 3.1 Support for XML forms will be removed in FOF 4
*/
class Spacer extends \JFormFieldSpacer implements FieldInterface
{
/**
* @var string Static field output
*/
protected $static;
/**
* @var string Repeatable field output
*/
protected $repeatable;
/**
* The Form object of the form attached to the form field.
*
* @var Form
*/
protected $form;
/**
* A monotonically increasing number, denoting the row number in a repeatable view
*
* @var int
*/
public $rowid;
/**
* The item being rendered in a repeatable form field
*
* @var DataModel
*/
public $item;
/**
* Method to get certain otherwise inaccessible properties from the form field object.
*
* @param string $name The property name for which to the the value.
*
* @return mixed The property value or null.
*
* @since 2.0
*/
public function __get($name)
{
switch ($name)
{
case 'static':
if (empty($this->static))
{
$this->static = $this->getStatic();
}
return $this->static;
break;
case 'repeatable':
if (empty($this->repeatable))
{
$this->repeatable = $this->getRepeatable();
}
return $this->repeatable;
break;
default:
return parent::__get($name);
}
}
/**
* Get the rendering of this field type for static display, e.g. in a single
* item view (typically a "read" task).
*
* @since 2.0
*
* @return string The field HTML
*/
public function getStatic()
{
return $this->getInput();
}
/**
* 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
*/
public function getRepeatable()
{
return $this->getInput();
}
}
Field/Ordering.php 0000644 00000016516 15235405654 0010073 0 ustar 00 <?php
/**
* @package FOF
* @copyright Copyright (c)2010-2019 Nicholas K. Dionysopoulos / Akeeba Ltd
* @license GNU GPL version 2 or later
*/
namespace FOF30\Form\Field;
use FOF30\Form\Exception\DataModelRequired;
use FOF30\Form\Exception\GetStaticNotAllowed;
use FOF30\Form\FieldInterface;
use FOF30\Form\Form;
use FOF30\Model\DataModel;
use JHtml;
use JText;
defined('_JEXEC') or die;
/**
* Form Field class for FOF
* Renders the row ordering interface checkbox in browse views
*
* @deprecated 3.1 Support for XML forms will be removed in FOF 4
*/
class Ordering extends \JFormField implements FieldInterface
{
/**
* @var string Static field output
*/
protected $static;
/**
* @var string Repeatable field output
*/
protected $repeatable;
/**
* The Form object of the form attached to the form field.
*
* @var Form
*/
protected $form;
/**
* A monotonically increasing number, denoting the row number in a repeatable view
*
* @var int
*/
public $rowid;
/**
* The item being rendered in a repeatable form field
*
* @var DataModel
*/
public $item;
/**
* Method to get certain otherwise inaccessible properties from the form field object.
*
* @param string $name The property name for which to the the value.
*
* @return mixed The property value or null.
*
* @since 2.0
*/
public function __get($name)
{
switch ($name)
{
case 'static':
if (empty($this->static))
{
$this->static = $this->getStatic();
}
return $this->static;
break;
case 'repeatable':
if (empty($this->repeatable))
{
$this->repeatable = $this->getRepeatable();
}
return $this->repeatable;
break;
default:
return parent::__get($name);
}
}
/**
* Method to get the field input markup for this field type.
*
* @since 2.0
*
* @return string The field input markup.
*/
protected function getInput()
{
$html = array();
$attr = '';
// Initialize some field attributes.
$attr .= !empty($this->class) ? ' class="' . $this->class . '"' : '';
$attr .= $this->disabled ? ' disabled' : '';
$attr .= !empty($this->size) ? ' size="' . $this->size . '"' : '';
// Initialize JavaScript field attributes.
$attr .= !empty($this->onchange) ? ' onchange="' . $this->onchange . '"' : '';
$this->item = $this->form->getModel();
$keyfield = $this->item->getKeyName();
$itemId = $this->item->$keyfield;
$query = $this->getQuery();
// Create a read-only list (no name) with a hidden input to store the value.
if ($this->readonly)
{
$html[] = JHtml::_('list.ordering', '', $query, trim($attr), $this->value, $itemId ? 0 : 1);
$html[] = '<input type="hidden" name="' . $this->name . '" value="' . $this->value . '"/>';
}
else
{
// Create a regular list.
$html[] = JHtml::_('list.ordering', $this->name, $query, trim($attr), $this->value, $itemId ? 0 : 1);
}
return implode($html);
}
/**
* Get the rendering of this field type for static display, e.g. in a single
* item view (typically a "read" task).
*
* @since 2.0
*
* @return string The field HTML
*
* @throws \LogicException
*/
public function getStatic()
{
throw new GetStaticNotAllowed(__CLASS__);
}
/**
* 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()
{
if (!($this->item instanceof DataModel))
{
throw new DataModelRequired(__CLASS__);
}
$class = isset($this->class) ? $this->class : 'input-mini';
$icon = isset($this->element['icon']) ? $this->element['icon'] : 'icon-menu';
$dnd = isset($this->element['dragndrop']) ? (string) $this->element['dragndrop'] : 'notbroken';
if (strtolower($dnd) == 'notbroken')
{
$dnd = !version_compare(JVERSION, '3.5.0', 'ge');
}
else
{
$dnd = in_array(strtolower($dnd), array('1', 'true', 'yes', 'on', 'enabled'), true);
}
$html = '';
$view = $this->form->getView();
$ordering = $view->getLists()->order == $this->item->getFieldAlias('ordering');
if (!$view->hasAjaxOrderingSupport())
{
// Ye olde Joomla! 2.5 method
$disabled = $ordering ? '' : 'disabled="disabled"';
$html .= '<span>';
$html .= $view->getPagination()->orderUpIcon($this->rowid, true, 'orderup', 'Move Up', $ordering);
$html .= '</span><span>';
$html .= $view->getPagination()->orderDownIcon($this->rowid, $view->getPagination()->total, true, 'orderdown', 'Move Down', $ordering);
$html .= '</span>';
$html .= '<input type="text" name="order[]" size="5" value="' . $this->value . '" ' . $disabled;
$html .= 'class="text-area-order" style="text-align: center" />';
}
else
{
// The modern drag'n'drop method
if ($view->getPerms()->editstate)
{
$disableClassName = '';
$disabledLabel = '';
$hasAjaxOrderingSupport = $view->hasAjaxOrderingSupport();
if (!$hasAjaxOrderingSupport['saveOrder'])
{
$disabledLabel = JText::_('JORDERINGDISABLED');
$disableClassName = 'inactive tip-top';
}
$orderClass = $ordering ? 'order-enabled' : 'order-disabled';
$html .= '<div class="' . $orderClass . '">';
if ($dnd)
{
$html .= '<span class="sortable-handler ' . $disableClassName . '" title="' . $disabledLabel . '" rel="tooltip">';
$html .= '<span class="' . $icon . '"></span>';
$html .= '</span>';
}
if ($ordering)
{
/**
* Joomla! 3.5 and later: drag and drop reordering is broken when the ordering field is not hidden
* because some random bloke submitted that code and some supposedly responsible adult with commit
* rights committed it. I tried to file a PR to fix it and got the reply "can't test, won't test".
* OK, then. You blindly accepted code which did the EXACT OPPOSITE of what it promised and broke
* b/c. However, you won't accept the fix to your mess from someone who knows how Joomla! works and
* wasted 2 hours of his time to track down your mistake, fix it and explain why your actions
* resulted in a b/c break. You have to be kidding me!
*/
$joomla35IsBroken = version_compare(JVERSION, '3.5.0', 'ge') ? 'style="display: none"': '';
// When the developer has disabled Drag and Drop we will show the field regardless
$joomla35IsBroken = $dnd ? $joomla35IsBroken : '';
$html .= '<input type="text" name="order[]" ' . $joomla35IsBroken . ' size="5" class="' . $class . ' text-area-order" value="' . $this->value . '" />';
}
$html .= '</div>';
}
else
{
$html .= '<span class="sortable-handler inactive" >';
$html .= '<i class="' . $icon . '"></i>';
$html .= '</span>';
}
}
return $html;
}
/**
* 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;
}
}
Field/Email.php 0000644 00000011631 15235405654 0007342 0 ustar 00 <?php
/**
* @package FOF
* @copyright Copyright (c)2010-2019 Nicholas K. Dionysopoulos / Akeeba Ltd
* @license GNU GPL version 2 or later
*/
namespace FOF30\Form\Field;
use FOF30\Form\FieldInterface;
use FOF30\Form\Form;
use FOF30\Model\DataModel;
use FOF30\Utils\StringHelper;
defined('_JEXEC') or die;
\JFormHelper::loadFieldClass('email');
/**
* Form Field class for the FOF framework
* Supports a one line text field.
*
* @deprecated 3.1 Support for XML forms will be removed in FOF 4
*/
class Email extends \JFormFieldEMail implements FieldInterface
{
/**
* @var string Static field output
*/
protected $static;
/**
* @var string Repeatable field output
*/
protected $repeatable;
/**
* The Form object of the form attached to the form field.
*
* @var Form
*/
protected $form;
/**
* A monotonically increasing number, denoting the row number in a repeatable view
*
* @var int
*/
public $rowid;
/**
* The item being rendered in a repeatable form field
*
* @var DataModel
*/
public $item;
/**
* Method to get certain otherwise inaccessible properties from the form field object.
*
* @param string $name The property name for which to the the value.
*
* @return mixed The property value or null.
*
* @since 2.0
*/
public function __get($name)
{
switch ($name)
{
case 'static':
if (empty($this->static))
{
$this->static = $this->getStatic();
}
return $this->static;
break;
case 'repeatable':
if (empty($this->repeatable))
{
$this->repeatable = $this->getRepeatable();
}
return $this->repeatable;
break;
default:
return parent::__get($name);
}
}
/**
* Get the rendering of this field type for static display, e.g. in a single
* item view (typically a "read" task).
*
* @since 2.0
*
* @return string The field HTML
*/
public function getStatic()
{
if (isset($this->element['legacy']))
{
return $this->getInput();
}
$options = array(
'id' => $this->id
);
return $this->getFieldContents($options);
}
/**
* 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
*/
public function getRepeatable()
{
if (isset($this->element['legacy']))
{
return $this->getInput();
}
$options = array(
'class' => $this->id
);
return $this->getFieldContents($options);
}
/**
* 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'] : '');
$show_link = StringHelper::toBool((string) $this->element['show_link']);
$empty_replacement = $this->element['empty_replacement'] ? (string) $this->element['empty_replacement'] : '';
if (!empty($empty_replacement) && empty($this->value))
{
$replacement_key = (string) $this->element['empty_replacement'];
$this->value = \JText::_($replacement_key);
}
$value = htmlspecialchars($this->value, ENT_COMPAT, 'UTF-8');
$html = $value;
if ($show_link)
{
if ($this->element['url'])
{
$link_url = $this->parseFieldTags((string) $this->element['url']);
}
else
{
$link_url = $value;
}
$html = '<a href="mailto:' . $link_url . '">' .
$value . '</a>';
}
return '<span ' . ($id ? $id : '') . 'class="' . $class . '">' .
$html .
'</span>';
}
/**
* 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;
}
}
Field/GroupedList.php 0000644 00000011310 15235405654 0010546 0 ustar 00 <?php
/**
* @package FOF
* @copyright Copyright (c)2010-2019 Nicholas K. Dionysopoulos / Akeeba Ltd
* @license GNU GPL version 2 or later
*/
namespace FOF30\Form\Field;
use FOF30\Form\Exception\InvalidGroupContents;
use FOF30\Form\FieldInterface;
use FOF30\Form\Form;
use FOF30\Model\DataModel;
defined('_JEXEC') or die;
\JFormHelper::loadFieldClass('groupedlist');
/**
* Form Field class for FOF
* Supports a generic list of options.
*
* @deprecated 3.1 Support for XML forms will be removed in FOF 4
*/
class GroupedList extends \JFormFieldGroupedList implements FieldInterface
{
/**
* @var string Static field output
*/
protected $static;
/**
* @var string Repeatable field output
*/
protected $repeatable;
/**
* The Form object of the form attached to the form field.
*
* @var Form
*/
protected $form;
/**
* A monotonically increasing number, denoting the row number in a repeatable view
*
* @var int
*/
public $rowid;
/**
* The item being rendered in a repeatable form field
*
* @var DataModel
*/
public $item;
/**
* Method to get certain otherwise inaccessible properties from the form field object.
*
* @param string $name The property name for which to the the value.
*
* @return mixed The property value or null.
*
* @since 2.0
*/
public function __get($name)
{
switch ($name)
{
case 'static':
if (empty($this->static))
{
$this->static = $this->getStatic();
}
return $this->static;
break;
case 'repeatable':
if (empty($this->repeatable))
{
$this->repeatable = $this->getRepeatable();
}
return $this->repeatable;
break;
default:
return parent::__get($name);
}
}
/**
* Get the rendering of this field type for static display, e.g. in a single
* item view (typically a "read" task).
*
* @since 2.0
*
* @return string The field HTML
*/
public function getStatic()
{
if (isset($this->element['legacy']))
{
return $this->getInput();
}
$options = array(
'id' => $this->id
);
return $this->getFieldContents($options);
}
/**
* 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
*/
public function getRepeatable()
{
if (isset($this->element['legacy']))
{
return $this->getInput();
}
$options = array(
'class' => $this->id
);
return $this->getFieldContents($options);
}
/**
* 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']) ? $fieldOptions['id'] : null;
$class = $this->class . (isset($fieldOptions['class']) ? ' ' . $fieldOptions['class'] : '');
$selected = self::getOptionName($this->getGroups(), $this->value);
if (is_null($selected))
{
$selected = array(
'group' => '',
'item' => ''
);
}
return '<span ' . ($id ? 'id="' . $id . '-group" ' : '') . 'class="fof-groupedlist-group' . $class . '">' .
htmlspecialchars($selected['group'], ENT_COMPAT, 'UTF-8') .
'</span>' .
'<span ' . ($id ? 'id="' . $id . '-item" ' : '') . 'class="fof-groupedlist-item' . $class . '">' .
htmlspecialchars($selected['item'], ENT_COMPAT, 'UTF-8') .
'</span>';
}
/**
* Gets the active option's label given an array of JHtml options
*
* @param array $data The JHtml options to parse
* @param mixed $selected The currently selected value
* @param string $groupKey Group name
* @param string $optKey Key name
* @param string $optText Value name
*
* @return mixed The label of the currently selected option
*/
public static function getOptionName($data, $selected = null, $groupKey = 'items', $optKey = 'value', $optText = 'text')
{
if ($groupKey) {}; // Keeps phpStorm from freaking out
$ret = null;
foreach ($data as $dataKey => $group)
{
$noGroup = true;
if (is_array($group) || is_object($group))
{
$label = $dataKey;
// If the key is a string, most likely is the title of group
if(is_string($dataKey))
{
$noGroup = false;
}
}
else
{
throw new InvalidGroupContents(get_called_class());
}
if ($noGroup)
{
$label = '';
}
$match = GenericList::getOptionName($group, $selected, $optKey, $optText, false);
if (!is_null($match))
{
$ret = array(
'group' => $label,
'item' => $match
);
break;
}
}
return $ret;
}
}
Field/Tel.php 0000644 00000011664 15235405654 0007045 0 ustar 00 <?php
/**
* @package FOF
* @copyright Copyright (c)2010-2019 Nicholas K. Dionysopoulos / Akeeba Ltd
* @license GNU GPL version 2 or later
*/
namespace FOF30\Form\Field;
use FOF30\Form\FieldInterface;
use FOF30\Form\Form;
use FOF30\Model\DataModel;
use JText;
defined('_JEXEC') or die;
\JFormHelper::loadFieldClass('tel');
/**
* Form Field class for the FOF framework
* Supports a URL text field.
*
* @deprecated 3.1 Support for XML forms will be removed in FOF 4
*/
class Tel extends \JFormFieldTel implements FieldInterface
{
/**
* @var string Static field output
*/
protected $static;
/**
* @var string Repeatable field output
*/
protected $repeatable;
/**
* The Form object of the form attached to the form field.
*
* @var Form
*/
protected $form;
/**
* A monotonically increasing number, denoting the row number in a repeatable view
*
* @var int
*/
public $rowid;
/**
* The item being rendered in a repeatable form field
*
* @var DataModel
*/
public $item;
/**
* Method to get certain otherwise inaccessible properties from the form field object.
*
* @param string $name The property name for which to the the value.
*
* @return mixed The property value or null.
*
* @since 2.0
*/
public function __get($name)
{
switch ($name)
{
case 'static':
if (empty($this->static))
{
$this->static = $this->getStatic();
}
return $this->static;
break;
case 'repeatable':
if (empty($this->repeatable))
{
$this->repeatable = $this->getRepeatable();
}
return $this->repeatable;
break;
default:
return parent::__get($name);
}
}
/**
* Get the rendering of this field type for static display, e.g. in a single
* item view (typically a "read" task).
*
* @since 2.0
*
* @return string The field HTML
*/
public function getStatic()
{
if (isset($this->element['legacy']))
{
return $this->getInput();
}
$options = array(
'id' => $this->id
);
return $this->getFieldContents($options);
}
/**
* 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
*/
public function getRepeatable()
{
if (isset($this->element['legacy']))
{
return $this->getInput();
}
$options = array(
'class' => $this->id
);
return $this->getFieldContents($options);
}
/**
* 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'] : '');
$show_link = in_array((string) $this->element['show_link'], array('true', '1', 'on', 'yes'));
$empty_replacement = $this->element['empty_replacement'] ? (string) $this->element['empty_replacement'] : '';
if (!empty($empty_replacement) && empty($this->value))
{
$this->value = JText::_($empty_replacement);
}
$value = htmlspecialchars($this->value, ENT_COMPAT, 'UTF-8');
$html = $value;
if ($show_link)
{
if ($this->element['url'])
{
$link_url = $this->parseFieldTags((string) $this->element['url']);
}
else
{
$link_url = $value;
}
$html = '<a href="tel:' . $link_url . '">' .
$value . '</a>';
}
return '<span ' . ($id ? $id : '') . 'class="' . $class . '"">' .
$html .
'</span>';
}
/**
* 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;
}
}
Field/RowSelect.php 0000644 00000000610 15235405654 0010215 0 ustar 00 <?php
/**
* @package FOF
* @copyright Copyright (c)2010-2019 Nicholas K. Dionysopoulos / Akeeba Ltd
* @license GNU GPL version 2 or later
*/
namespace FOF30\Form\Field;
defined('_JEXEC') or die;
/**
* Form Field class for FOF
* Alias to RowSelect (common typo)
*
* @deprecated 3.1 Support for XML forms will be removed in FOF 4
*/
class RowSelect extends SelectRow
{
}
Field/Callback.php 0000644 00000007434 15235405654 0010015 0 ustar 00 <?php
/**
* @package FOF
* @copyright Copyright (c)2010-2019 Nicholas K. Dionysopoulos / Akeeba Ltd
* @license GNU GPL version 2 or later
*/
namespace FOF30\Form\Field;
use FOF30\Form\FieldInterface;
use FOF30\Form\Form;
use FOF30\Model\DataModel;
defined('_JEXEC') or die;
\JFormHelper::loadFieldClass('text');
/**
* Form Field class for the FOF framework
* Displays a field generated by a callback
*
* @deprecated 3.1 Support for XML forms will be removed in FOF 4
*/
class Callback extends \JFormField implements FieldInterface
{
/**
* @var string Static field output
*/
protected $static;
/**
* @var string Repeatable field output
*/
protected $repeatable;
/**
* The Form object of the form attached to the form field.
*
* @var Form
*/
protected $form;
/**
* A monotonically increasing number, denoting the row number in a repeatable view
*
* @var int
*/
public $rowid;
/**
* The item being rendered in a repeatable form field
*
* @var DataModel
*/
public $item;
/**
* Method to get certain otherwise inaccessible properties from the form field object.
*
* @param string $name The property name for which to the the value.
*
* @return mixed The property value or null.
*
* @since 2.0
*/
public function __get($name)
{
switch ($name)
{
case 'input':
if (empty($this->input))
{
$this->input = $this->getInput();
}
return $this->input;
break;
case 'static':
if (empty($this->static))
{
$this->static = $this->getStatic();
}
return $this->static;
break;
case 'repeatable':
if (empty($this->repeatable))
{
$this->repeatable = $this->getRepeatable();
}
return $this->repeatable;
break;
default:
return parent::__get($name);
}
}
/**
* Get the rendering of this field type for static display, e.g. in a single
* item view (typically a "read" task).
*
* @since 2.0
*
* @return string The field HTML
*/
public function getStatic()
{
return $this->getCallbackResults();
}
/**
* 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
*/
public function getRepeatable()
{
return $this->getCallbackResults();
}
/**
* Method to get the field input markup.
*
* @return string The field input markup.
*
* @since 11.1
*/
protected function getInput()
{
return $this->getCallbackResults();
}
/**
* 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 '';
}
}
Field/Title.php 0000644 00000002741 15235405654 0007376 0 ustar 00 <?php
/**
* @package FOF
* @copyright Copyright (c)2010-2019 Nicholas K. Dionysopoulos / Akeeba Ltd
* @license GNU GPL version 2 or later
*/
namespace FOF30\Form\Field;
use FOF30\Form\FieldInterface;
use JText;
defined('_JEXEC') or die;
\JFormHelper::loadFieldClass('text');
/**
* Form Field class for the FOF framework
* Supports a title field with an optional slug display below it.
*
* @deprecated 3.1 Support for XML forms will be removed in FOF 4
*/
class Title extends Text implements FieldInterface
{
/**
* 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
*/
public function getRepeatable()
{
// Initialise
$slug_field = isset($this->element['slug_field']) ? (string)$this->element['slug_field'] :
$this->item->getFieldAlias('slug');
$slug_format = $this->element['slug_format'] ? (string)$this->element['slug_format'] : '(%s)';
$slug_class = $this->element['slug_class'] ? (string)$this->element['slug_class'] : 'small';
$slug_separator = isset($this->element['slug_separator']) ? (string)$this->element['slug_separator'] : '<br />';
// Get the regular display
$html = parent::getRepeatable();
$slug = $this->item->$slug_field;
$html .= $slug_separator . '<span class="' . $slug_class . '">';
$html .= JText::sprintf($slug_format, $slug);
$html .= '</span>';
return $html;
}
}
Field/AccessLevel.php 0000644 00000010015 15235405654 0010477 0 ustar 00 <?php
/**
* @package FOF
* @copyright Copyright (c)2010-2019 Nicholas K. Dionysopoulos / Akeeba Ltd
* @license GNU GPL version 2 or later
*/
namespace FOF30\Form\Field;
use FOF30\Form\FieldInterface;
use FOF30\Form\Form;
use FOF30\Model\DataModel;
use JHtml;
use JText;
defined('_JEXEC') or die;
\JFormHelper::loadFieldClass('accesslevel');
/**
* Form Field class for FOF
* Joomla! access levels
*
* @deprecated 3.1 Support for XML forms will be removed in FOF 4
*/
class AccessLevel extends \JFormFieldAccessLevel implements FieldInterface
{
/**
* @var string Static field output
*/
protected $static;
/**
* @var string Repeatable field output
*/
protected $repeatable;
/**
* The Form object of the form attached to the form field.
*
* @var Form
*/
protected $form;
/**
* A monotonically increasing number, denoting the row number in a repeatable view
*
* @var int
*/
public $rowid;
/**
* The item being rendered in a repeatable form field
*
* @var DataModel
*/
public $item;
/**
* Method to get certain otherwise inaccessible properties from the form field object.
*
* @param string $name The property name for which to the the value.
*
* @return mixed The property value or null.
*
* @since 2.0
*/
public function __get($name)
{
switch ($name)
{
case 'static':
if (empty($this->static))
{
$this->static = $this->getStatic();
}
return $this->static;
break;
case 'repeatable':
if (empty($this->repeatable))
{
$this->repeatable = $this->getRepeatable();
}
return $this->repeatable;
break;
default:
return parent::__get($name);
}
}
/**
* Get the rendering of this field type for static display, e.g. in a single
* item view (typically a "read" task).
*
* @since 2.0
*
* @return string The field HTML
*/
public function getStatic()
{
if (isset($this->element['legacy']))
{
return $this->getInput();
}
$options = array(
'id' => $this->id
);
return $this->getFieldContents($options);
}
/**
* 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
*/
public function getRepeatable()
{
if (isset($this->element['legacy']))
{
return $this->getInput();
}
$options = array(
'class' => $this->id
);
return $this->getFieldContents($options);
}
/**
* 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())
{
/** @var array|null The select options coming from the access levels of the site */
static $defaultOptions = null;
$id = isset($fieldOptions['id']) ? 'id="' . $fieldOptions['id'] . '" ' : '';
$class = $this->class . (isset($fieldOptions['class']) ? ' ' . $fieldOptions['class'] : '');
$params = $this->getOptions();
if (is_null($defaultOptions))
{
$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.
$defaultOptions = $db->setQuery($query)->loadObjectList();
}
$options = $defaultOptions;
// If params is an array, push these options to the array
if (is_array($params))
{
$options = array_merge($params, $defaultOptions);
}
// If all levels is allowed, push it into the array.
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>';
}
}
Field/Images.php 0000644 00000004724 15235405654 0007525 0 ustar 00 <?php
/**
* @package FOF
* @copyright Copyright (c)2010-2019 Nicholas K. Dionysopoulos / Akeeba Ltd
* @license GNU GPL version 2 or later
*/
namespace FOF30\Form\Field;
use JHtml;
use JText;
defined('_JEXEC') or die;
\JFormHelper::loadFieldClass('imagelist');
/**
* Form Field class for the FOF framework
* Images field.
*
* @deprecated 3.1 Support for XML forms will be removed in FOF 4
*/
class Images extends ImageList
{
/**
* 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'] : '');
if (!is_array($this->value))
{
$this->value = (array) $this->value;
}
$html = '<span ' . ($id ? $id : '') . 'class="'. $class . '">';
foreach ($this->value as $image)
{
$imgattr = array();
$alt = null;
if ($class)
{
$imgattr['class'] = $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']);
}
if ($this->element['title'])
{
$imgattr['title'] = JText::_((string) $this->element['title']);
}
$path = (string) $this->element['directory'];
$path = trim($path, '/' . DIRECTORY_SEPARATOR);
$platform = $this->form->getContainer()->platform;
$baseDirs = $platform->getPlatformBaseDirs();
if ($image && file_exists($baseDirs['root'] . '/' . $path . '/' . $image))
{
$src = $platform->URIroot() . '/' . $path . '/' . $image;
$html .= JHtml::image($src, $alt, $imgattr);
}
else
{
// JHtml::image returns weird stuff when an empty path is provided, so let's be safe than sorry and return empty
$html .= '';
}
}
$html .= '</span>';
return $html;
}
}
Field/Color.php 0000644 00000005056 15235405654 0007375 0 ustar 00 <?php
/**
* @package FOF
* @copyright Copyright (c)2010-2019 Nicholas K. Dionysopoulos / Akeeba Ltd
* @license GNU GPL version 2 or later
*/
namespace FOF30\Form\Field;
use FOF30\Form\FieldInterface;
use FOF30\Form\Form;
use FOF30\Model\DataModel;
// no direct access
defined('_JEXEC') or die('Restricted access');
\JFormHelper::loadFieldClass('color');
/**
* Form Field class for the FOF framework
* Color field
*
* @deprecated 3.1 Support for XML forms will be removed in FOF 4
*/
class Color extends \JFormFieldColor implements FieldInterface
{
/**
* The Form object of the form attached to the form field.
*
* @var Form
*/
protected $form;
/**
* The item being rendered in a repeatable form field.
*
* @var DataModel
*/
public $item;
/**
* Repeatable field output.
*
* @var string
*/
protected $repeatable;
/**
* A monotonically increasing number, denoting the row number in a repeatable view.
*
* @var int
*/
public $rowid;
/**
* Static field output.
*
* @var string
*/
protected $static;
/**
* Method to get certain otherwise inaccessible properties from the form field
* object.
*
* @access public
* @param string $name The property name for which to the the value.
*
*
* @since 2.0
*
* @return mixed The property value or null.
*/
public function __get($name)
{
switch ($name)
{
case 'static':
if (empty($this->static))
{
$this->static = $this->getStatic();
}
return $this->static;
break;
case 'repeatable':
if (empty($this->repeatable))
{
$this->repeatable = $this->getRepeatable();
}
return $this->repeatable;
break;
default:
return parent::__get($name);
}
}
/**
* Get the rendering of this field type for a repeatable (grid) display, e.g.
* in a view listing many item (typically a "browse" task)
*
* @access public
*
*
* @since 2.0
*
* @return string The field HTML
*/
public function getRepeatable()
{
if (isset($this->element['legacy']))
{
return $this->getInput();
}
$class = $this->class ? $this->class : '';
$hexColor = '#' . ltrim($this->value, '#');
return '<div class="' . $this->id . ' ' . $class
. '" style="width:20px; height:20px; background-color:' . $hexColor . ';">' .
'</div>';
}
/**
* Get the rendering of this field type for static display, e.g. in a single
* item view (typically a "read" task).
*
* @access public
*
*
* @since 2.0
*
* @return string The field HTML
*/
public function getStatic()
{
// Return the joomla native control
return $this->getInput();
}
}
Field/Rules.php 0000644 00000025530 15235405654 0007410 0 ustar 00 <?php
/**
* @package FOF
* @copyright Copyright (c)2010-2019 Nicholas K. Dionysopoulos / Akeeba Ltd
* @license GNU GPL version 2 or later
*/
namespace FOF30\Form\Field;
use FOF30\Form\FieldInterface;
use FOF30\Form\Form;
use FOF30\Model\DataModel;
use JHtml;
use JText;
defined('_JEXEC') or die;
\JFormHelper::loadFieldClass('rules');
/**
* Form Field class for FOF
* Joomla! ACL Rules
*
* @deprecated 3.1 Support for XML forms will be removed in FOF 4
*/
class Rules extends \JFormFieldRules implements FieldInterface
{
/**
* @var string Static field output
*/
protected $static;
/**
* @var string Repeatable field output
*/
protected $repeatable;
/**
* The Form object of the form attached to the form field.
*
* @var Form
*/
protected $form;
/**
* A monotonically increasing number, denoting the row number in a repeatable view
*
* @var int
*/
public $rowid;
/**
* The item being rendered in a repeatable form field
*
* @var DataModel
*/
public $item;
/**
* Method to get certain otherwise inaccessible properties from the form field object.
*
* @param string $name The property name for which to the the value.
*
* @return mixed The property value or null.
*
* @since 2.0
*/
public function __get($name)
{
switch ($name)
{
// This field cannot provide a static display
case 'static':
return '';
break;
// This field cannot provide a repeateable display
case 'repeatable':
return '';
break;
default:
return parent::__get($name);
}
}
/**
* Get the rendering of this field type for static display, e.g. in a single
* item view (typically a "read" task).
*
* @since 2.0
*
* @return string The field HTML
*/
public function getStatic()
{
return '';
}
/**
* 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.1
*
* @return string The field HTML
*/
public function getRepeatable()
{
return '';
}
/**
* At the timing of this writing (2013-12-03), the Joomla "rules" field is buggy. When you are
* dealing with a new record it gets the default permissions from the root asset node, which
* is fine for the default permissions of Joomla articles, but unsuitable for third party software.
* We had to copy & paste the whole code, since we can't "inject" the correct asset id if one is
* not found. Our fixes are surrounded by `FOF Library fix` remarks.
*
* @return string The input field's HTML for this field type
*/
protected function getInput()
{
JHtml::_('bootstrap.tooltip');
// Initialise some field attributes.
$section = $this->section;
$component = $this->component;
$assetField = $this->assetField;
// Get the actions for the asset.
$actions = \JAccess::getActions($component, $section);
// Iterate over the children and add to the actions.
/** @var \SimpleXMLElement $el */
foreach ($this->element->children() as $el)
{
if ($el->getName() == 'action')
{
$actions[] = (object) array('name' => (string) $el['name'], 'title' => (string) $el['title'],
'description' => (string) $el['description']);
}
}
// Get the explicit rules for this asset.
if ($section == 'component')
{
// Need to find the asset id by the name of the component.
$db = $this->form->getContainer()->platform->getDbo();
$query = $db->getQuery(true)
->select($db->quoteName('id'))
->from($db->quoteName('#__assets'))
->where($db->quoteName('name') . ' = ' . $db->quote($component));
$assetId = (int) $db->setQuery($query)->loadResult();
}
else
{
// Find the asset id of the content.
// Note that for global configuration, com_config injects asset_id = 1 into the form.
$assetId = $this->form->getValue($assetField);
// ==== FOF Library fix - Start ====
// If there is no assetId (let's say we are dealing with a new record), let's ask the table
// to give it to us. Here you should implement your logic (ie getting default permissions from
// the component or from the category)
if(!$assetId)
{
$table = $this->form->getModel();
$assetId = $table->getAssetParentId();
}
// ==== FOF Library fix - End ====
}
// Full width format.
// Get the rules for just this asset (non-recursive).
$assetRules = \JAccess::getAssetRules($assetId);
// Get the available user groups.
$groups = $this->getUserGroups();
// Prepare output
$html = array();
// Description
$html[] = '<p class="rule-desc">' . JText::_('JLIB_RULES_SETTINGS_DESC') . '</p>';
// Begin tabs
$html[] = '<div id="permissions-sliders" class="tabbable tabs-left">';
// Building tab nav
$html[] = '<ul class="nav nav-tabs">';
foreach ($groups as $group)
{
// Initial Active Tab
$active = "";
if ($group->value == 1)
{
$active = "active";
}
$html[] = '<li class="' . $active . '">';
$html[] = '<a href="#permission-' . $group->value . '" data-toggle="tab">';
$html[] = str_repeat('<span class="level">–</span> ', $curLevel = $group->level) . $group->text;
$html[] = '</a>';
$html[] = '</li>';
}
$html[] = '</ul>';
$html[] = '<div class="tab-content">';
// Start a row for each user group.
foreach ($groups as $group)
{
// Initial Active Pane
$active = "";
if ($group->value == 1)
{
$active = " active";
}
$html[] = '<div class="tab-pane' . $active . '" id="permission-' . $group->value . '">';
$html[] = '<table class="table table-striped">';
$html[] = '<thead>';
$html[] = '<tr>';
$html[] = '<th class="actions" id="actions-th' . $group->value . '">';
$html[] = '<span class="acl-action">' . JText::_('JLIB_RULES_ACTION') . '</span>';
$html[] = '</th>';
$html[] = '<th class="settings" id="settings-th' . $group->value . '">';
$html[] = '<span class="acl-action">' . JText::_('JLIB_RULES_SELECT_SETTING') . '</span>';
$html[] = '</th>';
// The calculated setting is not shown for the root group of global configuration.
$canCalculateSettings = ($group->parent_id || !empty($component));
if ($canCalculateSettings)
{
$html[] = '<th id="aclactionth' . $group->value . '">';
$html[] = '<span class="acl-action">' . JText::_('JLIB_RULES_CALCULATED_SETTING') . '</span>';
$html[] = '</th>';
}
$html[] = '</tr>';
$html[] = '</thead>';
$html[] = '<tbody>';
foreach ($actions as $action)
{
$html[] = '<tr>';
$html[] = '<td headers="actions-th' . $group->value . '">';
$html[] = '<label for="' . $this->id . '_' . $action->name . '_' . $group->value . '" class="hasTooltip" title="'
. htmlspecialchars(JText::_($action->title) . ' ' . JText::_($action->description), ENT_COMPAT, 'UTF-8') . '">';
$html[] = JText::_($action->title);
$html[] = '</label>';
$html[] = '</td>';
$html[] = '<td headers="settings-th' . $group->value . '">';
$html[] = '<select class="input-small" name="' . $this->name . '[' . $action->name . '][' . $group->value . ']" id="' . $this->id . '_' . $action->name
. '_' . $group->value . '" title="'
. JText::sprintf('JLIB_RULES_SELECT_ALLOW_DENY_GROUP', JText::_($action->title), trim($group->text)) . '">';
$inheritedRule = \JAccess::checkGroup($group->value, $action->name, $assetId);
// Get the actual setting for the action for this group.
$assetRule = $assetRules->allow($action->name, $group->value);
// Build the dropdowns for the permissions sliders
// The parent group has "Not Set", all children can rightly "Inherit" from that.
$html[] = '<option value=""' . ($assetRule === null ? ' selected="selected"' : '') . '>'
. JText::_(empty($group->parent_id) && empty($component) ? 'JLIB_RULES_NOT_SET' : 'JLIB_RULES_INHERITED') . '</option>';
$html[] = '<option value="1"' . ($assetRule === true ? ' selected="selected"' : '') . '>' . JText::_('JLIB_RULES_ALLOWED')
. '</option>';
$html[] = '<option value="0"' . ($assetRule === false ? ' selected="selected"' : '') . '>' . JText::_('JLIB_RULES_DENIED')
. '</option>';
$html[] = '</select>  ';
// If this asset's rule is allowed, but the inherited rule is deny, we have a conflict.
if (($assetRule === true) && ($inheritedRule === false))
{
$html[] = JText::_('JLIB_RULES_CONFLICT');
}
$html[] = '</td>';
// Build the Calculated Settings column.
// The inherited settings column is not displayed for the root group in global configuration.
if ($canCalculateSettings)
{
$html[] = '<td headers="aclactionth' . $group->value . '">';
// This is where we show the current effective settings considering currrent group, path and cascade.
// Check whether this is a component or global. Change the text slightly.
if (\JAccess::checkGroup($group->value, 'core.admin', $assetId) !== true)
{
if ($inheritedRule === null)
{
$html[] = '<span class="label label-important">' . JText::_('JLIB_RULES_NOT_ALLOWED') . '</span>';
}
elseif ($inheritedRule === true)
{
$html[] = '<span class="label label-success">' . JText::_('JLIB_RULES_ALLOWED') . '</span>';
}
elseif ($inheritedRule === false)
{
if ($assetRule === false)
{
$html[] = '<span class="label label-important">' . JText::_('JLIB_RULES_NOT_ALLOWED') . '</span>';
}
else
{
$html[] = '<span class="label"><i class="icon-lock icon-white"></i> ' . JText::_('JLIB_RULES_NOT_ALLOWED_LOCKED')
. '</span>';
}
}
}
elseif (!empty($component))
{
$html[] = '<span class="label label-success"><i class="icon-lock icon-white"></i> ' . JText::_('JLIB_RULES_ALLOWED_ADMIN')
. '</span>';
}
else
{
// Special handling for groups that have global admin because they can't be denied.
// The admin rights can be changed.
if ($action->name === 'core.admin')
{
$html[] = '<span class="label label-success">' . JText::_('JLIB_RULES_ALLOWED') . '</span>';
}
elseif ($inheritedRule === false)
{
// Other actions cannot be changed.
$html[] = '<span class="label label-important"><i class="icon-lock icon-white"></i> '
. JText::_('JLIB_RULES_NOT_ALLOWED_ADMIN_CONFLICT') . '</span>';
}
else
{
$html[] = '<span class="label label-success"><i class="icon-lock icon-white"></i> ' . JText::_('JLIB_RULES_ALLOWED_ADMIN')
. '</span>';
}
}
$html[] = '</td>';
}
$html[] = '</tr>';
}
$html[] = '</tbody>';
$html[] = '</table></div>';
}
$html[] = '</div></div>';
$html[] = '<div class="alert">';
if ($section == 'component' || $section == null)
{
$html[] = JText::_('JLIB_RULES_SETTING_NOTES');
}
else
{
$html[] = JText::_('JLIB_RULES_SETTING_NOTES_ITEM');
}
$html[] = '</div>';
return implode("\n", $html);
}
}
Field/Relation.php 0000644 00000012315 15235405654 0010070 0 ustar 00 <?php
/**
* @package FOF
* @copyright Copyright (c)2010-2019 Nicholas K. Dionysopoulos / Akeeba Ltd
* @license GNU GPL version 2 or later
*/
namespace FOF30\Form\Field;
use FOF30\Model\DataModel;
use JHtml;
use JText;
defined('_JEXEC') or die;
/**
* Form Field class for FOF
* Relation list
*
* @deprecated 3.1 Support for XML forms will be removed in FOF 4
*/
class Relation extends GenericList
{
/**
* Get the rendering of this field type for static display, e.g. in a single
* item view (typically a "read" task).
*
* @since 2.0
*
* @return string The field HTML
*/
public function getStatic() {
return $this->getRepeatable();
}
/**
* 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
*/
public function getRepeatable()
{
$class = $this->class ? $this->class : $this->id;
$relationclass = $this->element['relationclass'] ? (string) $this->element['relationclass'] : '';
$value_field = $this->element['value_field'] ? (string) $this->element['value_field'] : 'title';
$translate = $this->element['translate'] ? (string) $this->element['translate'] : false;
$link_url = $this->element['url'] ? (string) $this->element['url'] : false;
if (!($link_url && $this->item instanceof DataModel))
{
$link_url = false;
}
if ($this->element['empty_replacement'])
{
$empty_replacement = (string) $this->element['empty_replacement'];
}
$relationName = $this->form->getModel()->getContainer()->inflector->pluralize($this->name);
$relations = $this->item->getRelations()->getData($relationName);
$rels = array();
foreach ($relations as $relation) {
$html = '<span class="' . $relationclass . '">';
if ($link_url)
{
$keyfield = $relation->getKeyName();
$this->_relationId = $relation->$keyfield;
$url = $this->parseFieldTags($link_url);
$html .= '<a href="' . $url . '">';
}
if (!isset($this->valueField))
{
$this->valueField = $relation->getFieldAlias($value_field);
}
$value = $relation->{$this->valueField};
// Get the (optionally formatted) value
if (!empty($empty_replacement) && empty($value))
{
$value = JText::_($empty_replacement);
}
if ($translate == true)
{
$html .= JText::_($value);
}
else
{
$html .= $value;
}
if ($link_url)
{
$html .= '</a>';
}
$html .= '</span>';
$rels[] = $html;
}
$html = '<span class="' . $class . '">';
$html .= implode(', ', $rels);
$html .= '</span>';
return $html;
}
/**
* Method to get the field options.
*
* @return array The field option objects.
*/
protected function getOptions()
{
$options = array();
$this->value = array();
$value_field = $this->element['value_field'] ? (string) $this->element['value_field'] : 'title';
$name = (string) $this->element['name'];
$class = $this->element['model'] ? (string) $this->element['model'] : $name;
$view = $this->form->getView()->getName();
$relation = $this->form->getModel()->getContainer()->inflector->pluralize($class);
/** @var DataModel $model */
$model = $this->form->getContainer()->factory->model($relation)->setIgnoreRequest(true)->savestate(false);
$key = $model->getIdFieldName();
$value = $model->getFieldAlias($value_field);
foreach ($model->get(true) as $option)
{
$options[] = JHtml::_('select.option', $option->$key, $option->$value);
}
if ($id = $this->form->getModel()->getId())
{
$model = $this->form->getModel();
$relations = $model->$name;
foreach ($relations as $item)
{
$this->value[] = $item->getId();
}
}
return $options;
}
/**
* 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 the [RELATION:ID] in the URL with the relation's key value
$ret = str_replace('[RELATION:ID]', $this->_relationId, $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;
}
}
Field/Number.php 0000644 00000006670 15235405654 0007552 0 ustar 00 <?php
/**
* @package FOF
* @copyright Copyright (c)2010-2019 Nicholas K. Dionysopoulos / Akeeba Ltd
* @license GNU GPL version 2 or later
*/
namespace FOF30\Form\Field;
use FOF30\Form\FieldInterface;
use FOF30\Form\Form;
use FOF30\Model\DataModel;
defined('_JEXEC') or die;
\JFormHelper::loadFieldClass('number');
/**
* Form Field class for the FOF framework
* Supports a numeric field and currency symbols.
*
* @deprecated 3.1 Support for XML forms will be removed in FOF 4
*/
class Number extends \JFormFieldNumber implements FieldInterface
{
/**
* @var string Static field output
*/
protected $static;
/**
* @var string Repeatable field output
*/
protected $repeatable;
/**
* The Form object of the form attached to the form field.
*
* @var Form
*/
protected $form;
/**
* A monotonically increasing number, denoting the row number in a repeatable view
*
* @var int
*/
public $rowid;
/**
* The item being rendered in a repeatable form field
*
* @var DataModel
*/
public $item;
/**
* Method to get certain otherwise inaccessible properties from the form field object.
*
* @param string $name The property name for which to the the value.
*
* @return mixed The property value or null.
*
* @since 2.0
*/
public function __get($name)
{
switch ($name)
{
case 'static':
if (empty($this->static))
{
$this->static = $this->getStatic();
}
return $this->static;
break;
case 'repeatable':
if (empty($this->repeatable))
{
$this->repeatable = $this->getRepeatable();
}
return $this->repeatable;
break;
default:
return parent::__get($name);
}
}
/**
* Get the rendering of this field type for static display, e.g. in a single
* item view (typically a "read" task).
*
* @since 2.0
*
* @return string The field HTML
*/
public function getStatic()
{
return $this->getRepeatable();
}
/**
* Print out the number as requested by the attributes
*/
public function getRepeatable()
{
$currencyPos = $this->getAttribute('currency_position', false);
$currencySymbol = $this->getAttribute('currency_symbol', false);
// Initialise
$class = $this->id;
// Get field parameters
if ($this->element['class'])
{
$class = (string) $this->element['class'];
}
// Start the HTML output
$html = '<span class="' . $class . '">';
// Prepend currency?
if ($currencyPos == 'before' && $currencySymbol)
{
$html .= $currencySymbol;
}
$number = $this->value;
// Should we format the number too?
$formatNumber = false;
if (isset($this->element['format_number']))
{
$formatNumberValue = (string)$this->element['format_number'];
$formatNumber = in_array(strtolower($formatNumberValue), array('yes', 'true', 'on', 1));
}
// Format the number correctly
if ($formatNumber)
{
$numDecimals = $this->getAttribute('decimals', 2);
$minNumDecimals = $this->getAttribute('min_decimals', 2);
$decimalsSep = $this->getAttribute('decimals_separator', '.');
$thousandSep = $this->getAttribute('thousand_separator', ',');
// Format the number
$number = number_format((float)$this->value, $numDecimals, $decimalsSep, $thousandSep);
}
// Put it all together
$html .= $number;
// Append currency?
if ($currencyPos == 'after' && $currencySymbol)
{
$html .= $currencySymbol;
}
// End the HTML output
$html .= '</span>';
return $html;
}
}
Field/CacheHandler.php 0000644 00000006050 15235405654 0010613 0 ustar 00 <?php
/**
* @package FOF
* @copyright Copyright (c)2010-2019 Nicholas K. Dionysopoulos / Akeeba Ltd
* @license GNU GPL version 2 or later
*/
namespace FOF30\Form\Field;
use FOF30\Form\FieldInterface;
use FOF30\Form\Form;
use FOF30\Model\DataModel;
defined('_JEXEC') or die;
\JFormHelper::loadFieldClass('cachehandler');
/**
* Form Field class for FOF
* Joomla! cache handlers
*
* @deprecated 3.1 Support for XML forms will be removed in FOF 4
*/
class CacheHandler extends \JFormFieldCacheHandler implements FieldInterface
{
/**
* @var string Static field output
*/
protected $static;
/**
* @var string Repeatable field output
*/
protected $repeatable;
/**
* The Form object of the form attached to the form field.
*
* @var Form
*/
protected $form;
/**
* A monotonically increasing number, denoting the row number in a repeatable view
*
* @var int
*/
public $rowid;
/**
* The item being rendered in a repeatable form field
*
* @var DataModel
*/
public $item;
/**
* Method to get certain otherwise inaccessible properties from the form field object.
*
* @param string $name The property name for which to the the value.
*
* @return mixed The property value or null.
*
* @since 2.0
*/
public function __get($name)
{
switch ($name)
{
case 'static':
if (empty($this->static))
{
$this->static = $this->getStatic();
}
return $this->static;
break;
case 'repeatable':
if (empty($this->repeatable))
{
$this->repeatable = $this->getRepeatable();
}
return $this->repeatable;
break;
default:
return parent::__get($name);
}
}
/**
* Get the rendering of this field type for static display, e.g. in a single
* item view (typically a "read" task).
*
* @since 2.0
*
* @return string The field HTML
*/
public function getStatic()
{
if (isset($this->element['legacy']))
{
return $this->getInput();
}
$options = array(
'id' => $this->id
);
return $this->getFieldContents($options);
}
/**
* 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
*/
public function getRepeatable()
{
if (isset($this->element['legacy']))
{
return $this->getInput();
}
$options = array(
'class' => $this->id
);
return $this->getFieldContents($options);
}
/**
* 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'] : '');
return '<span ' . ($id ? $id : '') . 'class="'. $class . '">' .
htmlspecialchars(GenericList::getOptionName($this->getOptions(), $this->value), ENT_COMPAT, 'UTF-8') .
'</span>';
}
}
Field/User.php 0000644 00000020330 15235405654 0007225 0 ustar 00 <?php
/**
* @package FOF
* @copyright Copyright (c)2010-2019 Nicholas K. Dionysopoulos / Akeeba Ltd
* @license GNU GPL version 2 or later
*/
namespace FOF30\Form\Field;
use FOF30\Form\FieldInterface;
use FOF30\Form\Form;
use FOF30\Model\DataModel;
defined('_JEXEC') or die;
\JFormHelper::loadFieldClass('user');
/**
* Form Field class for the FOF framework
* A user selection box / display field
*
* @deprecated 3.1 Support for XML forms will be removed in FOF 4
*/
class User extends \JFormFieldUser implements FieldInterface
{
/**
* @var string Static field output
*/
protected $static;
/**
* @var string Repeatable field output
*/
protected $repeatable;
/**
* The Form object of the form attached to the form field.
*
* @var Form
*/
protected $form;
/**
* A monotonically increasing number, denoting the row number in a repeatable view
*
* @var int
*/
public $rowid;
/**
* The item being rendered in a repeatable form field
*
* @var DataModel
*/
public $item;
/**
* Method to get certain otherwise inaccessible properties from the form field object.
*
* @param string $name The property name for which to the the value.
*
* @return mixed The property value or null.
*
* @since 2.0
*/
public function __get($name)
{
switch ($name)
{
case 'static':
if (empty($this->static))
{
$this->static = $this->getStatic();
}
return $this->static;
break;
case 'repeatable':
if (empty($this->repeatable))
{
$this->repeatable = $this->getRepeatable();
}
return $this->repeatable;
break;
default:
return parent::__get($name);
}
}
/**
* Get the rendering of this field type for static display, e.g. in a single
* item view (typically a "read" task).
*
* @since 2.0
*
* @return string The field HTML
*/
public function getStatic()
{
if (isset($this->element['legacy']))
{
return $this->getInput();
}
// Initialise
$show_username = !$this->element['show_username'] == 'false';
$show_email = $this->element['show_email'] == 'true';
$show_name = $this->element['show_name'] == 'true';
$show_id = $this->element['show_id'] == 'true';
$class = $this->class ? ' class="' . $this->class . '"' : '';
// Get the user record
$user = $this->form->getContainer()->platform->getUser($this->value);
// Render the HTML
$html = '<div id="' . $this->id . '" ' . $class . '>';
if ($show_username)
{
$html .= '<span class="fof-userfield-username">' . $user->username . '</span>';
}
if ($show_id)
{
$html .= '<span class="fof-userfield-id">' . $user->id . '</span>';
}
if ($show_name)
{
$html .= '<span class="fof-userfield-name">' . $user->name . '</span>';
}
if ($show_email)
{
$html .= '<span class="fof-userfield-email">' . $user->email . '</span>';
}
$html .= '</div>';
return $html;
}
/**
* 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
*/
public function getRepeatable()
{
static $userCache = array();
if (isset($this->element['legacy']))
{
return $this->getInput();
}
// Initialise
$show_username = !$this->element['show_username'] == 'false';
$show_email = !$this->element['show_email'] == 'false';
$show_name = !$this->element['show_name'] == 'false';
$show_id = !$this->element['show_id'] == 'false';
$show_avatar = !$this->element['show_avatar'] == 'false';
$show_link = $this->element['show_link'] == 'true';
$link_url = $this->element['link_url'] ? $this->element['link_url'] : null;
$avatar_method = 'gravatar';
$avatar_size = $this->element['avatar_size'] ? $this->element['avatar_size'] : 64;
$class = '';
// Get the user record
$key = is_numeric($this->value) ? $this->value : 'empty';
$key = ($key == 0) ? 'zero' : $key;
if (!array_key_exists($key, $userCache))
{
$userCache[$key] = $this->form->getContainer()->platform->getUser($this->value);
}
$user = $userCache[$key];
// Get the field parameters
if ($this->class)
{
$class = ' class="' . $this->class . '"';
}
if ($this->element['avatar_method'])
{
$avatar_method = strtolower($this->element['avatar_method']);
}
if (!$link_url && $this->form->getContainer()->platform->isBackend())
{
$link_url = 'index.php?option=com_users&task=user.edit&id=[USER:ID]';
}
elseif (!$link_url)
{
// If no link is defined in the front-end, we can't create a
// default link. Therefore, show no link.
$show_link = false;
}
// Post-process the link URL
if ($show_link)
{
$replacements = array(
'[USER:ID]' => $user->id,
'[USER:USERNAME]' => $user->username,
'[USER:EMAIL]' => $user->email,
'[USER:NAME]' => $user->name,
);
foreach ($replacements as $key => $value)
{
$link_url = str_replace($key, $value, $link_url);
}
$link_url = $this->parseFieldTags($link_url);
}
// Get the avatar image, if necessary
$avatar_url = '';
if ($show_avatar)
{
if ($avatar_method == 'plugin')
{
// Use the user plugins to get an avatar
$this->form->getContainer()->platform->importPlugin('user');
$jResponse = $this->form->getContainer()->platform->runPlugins('onUserAvatar', array($user, $avatar_size));
if (!empty($jResponse))
{
foreach ($jResponse as $response)
{
if ($response)
{
$avatar_url = $response;
}
}
}
if (empty($avatar_url))
{
$show_avatar = false;
}
}
else
{
// Fall back to the Gravatar method
$md5 = md5($user->email);
if ($this->form->getContainer()->platform->isCli())
{
$scheme = 'http';
}
else
{
$scheme = \JUri::getInstance()->getScheme();
}
if ($scheme == 'http')
{
$avatar_url = 'http://www.gravatar.com/avatar/' . $md5 . '.jpg?s='
. $avatar_size . '&d=mm';
}
else
{
$avatar_url = 'https://secure.gravatar.com/avatar/' . $md5 . '.jpg?s='
. $avatar_size . '&d=mm';
}
}
}
// Generate the HTML
$html = '<div id="' . $this->id . '" ' . $class . '>';
if ($show_avatar)
{
$html .= '<img src="' . $avatar_url . '" align="left" class="fof-usersfield-avatar" />';
}
if ($show_link)
{
$html .= '<a href="' . $link_url . '">';
}
if ($show_username)
{
$html .= '<span class="fof-usersfield-username">' . $user->username
. '</span>';
}
if ($show_id)
{
$html .= '<span class="fof-usersfield-id">' . $user->id
. '</span>';
}
if ($show_name)
{
$html .= '<span class="fof-usersfield-name">' . $user->name
. '</span>';
}
if ($show_email)
{
$html .= '<span class="fof-usersfield-email">' . $user->email
. '</span>';
}
if ($show_link)
{
$html .= '</a>';
}
$html .= '</div>';
return $html;
}
/**
* 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;
}
}
Field/Calendar.php 0000644 00000017641 15235405654 0010033 0 ustar 00 <?php
/**
* @package FOF
* @copyright Copyright (c)2010-2019 Nicholas K. Dionysopoulos / Akeeba Ltd
* @license GNU GPL version 2 or later
*/
namespace FOF30\Form\Field;
use FOF30\Date\Date;
use FOF30\Date\DateDecorator;
use FOF30\Form\FieldInterface;
use FOF30\Form\Form;
use FOF30\Model\DataModel;
use JHtml;
use JText;
use SimpleXMLElement;
defined('_JEXEC') or die;
\JFormHelper::loadFieldClass('calendar');
/**
* Form Field class for the FOF framework
* Supports a calendar / date field.
*
* @deprecated 3.1 Support for XML forms will be removed in FOF 4
*/
class Calendar extends \JFormFieldCalendar implements FieldInterface
{
/**
* @var string Static field output
*/
protected $static;
/**
* @var string Repeatable field output
*/
protected $repeatable;
/**
* The Form object of the form attached to the form field.
*
* @var Form
*/
protected $form;
/**
* A monotonically increasing number, denoting the row number in a repeatable view
*
* @var int
*/
public $rowid;
/**
* The item being rendered in a repeatable form field
*
* @var DataModel
*/
public $item;
/**
* Method to get certain otherwise inaccessible properties from the form field object.
*
* @param string $name The property name for which to the the value.
*
* @return mixed The property value or null.
*
* @since 2.0
*/
public function __get($name)
{
switch ($name)
{
// ATTENTION: Redirected getInput() to getStatic()
case 'input':
case 'static':
if (empty($this->static))
{
$this->static = $this->getStatic();
}
return $this->static;
break;
case 'repeatable':
if (empty($this->repeatable))
{
$this->repeatable = $this->getRepeatable();
}
return $this->repeatable;
break;
default:
return parent::__get($name);
}
}
/**
* Get the rendering of this field type for static display, e.g. in a single
* item view (typically a "read" task).
*
* @since 2.0
*
* @return string The field HTML
*/
public function getStatic()
{
return $this->getCalendar('static');
}
/**
* 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
*/
public function getRepeatable()
{
return $this->getCalendar('repeatable');
}
/**
* Overridden to enable time display by default in the FOF Calendar field. This is required for backwards
* compatibility: all previous Joomla! version would display the time and/or let you specify a time in the Calendar
* field. Joomla! 3.7 broke this, stripping away the time by default.
*
* @param SimpleXMLElement $element
* @param mixed $value
* @param null $group
*
* @return bool
*/
public function setup(SimpleXMLElement $element, $value, $group = null)
{
$ret = parent::setup($element, $value, $group);
// Show time by default in the FOF Calendar field
$showTimeValue = (string) $this->element['showtime'];
if (empty($showTimeValue))
{
$this->showtime = true;
}
return $ret;
}
/**
* 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.
$coreObject = \JFactory::getDate($this->value, 'UTC');
$date = new DateDecorator($coreObject);
$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.
$coreObject = \JFactory::getDate($this->value, 'UTC');
$date = new DateDecorator($coreObject);
$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->placeholder)
{
$attributes['placeholder'] = $this->placeholder;
}
if ($this->class)
{
$attributes['class'] = $this->class;
}
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->autocomplete)
{
$attributes['autocomplete'] = $this->autocomplete;
}
if ($this->autofocus)
{
$attributes['autofocus'] = $this->autofocus;
}
if ($this->filter)
{
$attributes['filter'] = $this->filter;
}
if ($this->today)
{
$attributes['todayBtn'] = $this->today;
}
if ($this->weeknumbers)
{
$attributes['weekNumbers'] = $this->weeknumbers;
}
if ($this->showtime)
{
$attributes['showTime'] = in_array(strtolower($this->showtime), ['true', '1', 'on', 'yes']);
}
elseif ($this->time)
{
$attributes['showTime'] = in_array(strtolower($this->time), ['true', '1', 'on', 'yes']);
}
if ($this->filltable)
{
$attributes['fillTable'] = in_array(strtolower($this->filltable), ['true', '1', 'on', 'yes']);
}
if ($this->timeformat)
{
$attributes['timeFormat'] = $this->timeformat;
}
if ($this->singleheader)
{
$attributes['singleHeader'] = in_array(strtolower($this->singleheader), ['true', '1', 'on', 'yes']);
}
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);
if (($format == '%Y-%m-%d') && isset($attributes['showTime']))
{
if ($attributes['showTime'])
{
$format = JText::_('DATE_FORMAT_CALENDAR_DATETIME');
}
else
{
$format = JText::_('DATE_FORMAT_CALENDAR_DATE');
}
}
return JHtml::_('calendar', $this->value, $this->name, $this->id, $format, $attributes);
}
else
{
if (!$this->value
&& (string) $this->element['empty_replacement'])
{
$replacement_key = (string) $this->element['empty_replacement'];
$value = \JText::_($replacement_key);
}
else
{
$date = new Date($this->value);
$value = strftime($format, $date->getTimestamp());
}
return '<span class="' . $this->id . ' ' . $class . '">' .
htmlspecialchars($value, ENT_COMPAT, 'UTF-8') .
'</span>';
}
}
}
Field/GenericList.php 0000644 00000025030 15235405654 0010521 0 ustar 00 <?php
/**
* @package FOF
* @copyright Copyright (c)2010-2019 Nicholas K. Dionysopoulos / Akeeba Ltd
* @license GNU GPL version 2 or later
*/
namespace FOF30\Form\Field;
use FOF30\Form\FieldInterface;
use FOF30\Form\Form;
use FOF30\Model\DataModel;
use FOF30\Utils\StringHelper;
use JHtml;
use Joomla\Utilities\ArrayHelper;
use JText;
defined('_JEXEC') or die;
\JFormHelper::loadFieldClass('list');
/**
* Form Field class for FOF
* Supports a generic list of options.
*
* @deprecated 3.1 Support for XML forms will be removed in FOF 4
*/
class GenericList extends \JFormFieldList implements FieldInterface
{
/**
* @var string Static field output
*/
protected $static;
/**
* @var string Repeatable field output
*/
protected $repeatable;
/**
* The Form object of the form attached to the form field.
*
* @var Form
*/
protected $form;
/**
* A monotonically increasing number, denoting the row number in a repeatable view
*
* @var int
*/
public $rowid;
/**
* The item being rendered in a repeatable form field
*
* @var DataModel
*/
public $item;
/**
* Method to get certain otherwise inaccessible properties from the form field object.
*
* @param string $name The property name for which to the the value.
*
* @return mixed The property value or null.
*
* @since 2.0
*/
public function __get($name)
{
switch ($name)
{
case 'static':
if (empty($this->static))
{
$this->static = $this->getStatic();
}
return $this->static;
break;
case 'repeatable':
if (empty($this->repeatable))
{
$this->repeatable = $this->getRepeatable();
}
return $this->repeatable;
break;
default:
return parent::__get($name);
}
}
/**
* Get the rendering of this field type for static display, e.g. in a single
* item view (typically a "read" task).
*
* @since 2.0
*
* @return string The field HTML
*/
public function getStatic()
{
if (isset($this->element['legacy']))
{
return $this->getInput();
}
$class = $this->class ? ' class="' . $this->class . '"' : '';
return '<span id="' . $this->id . '" ' . $class . '>' .
htmlspecialchars(self::getOptionName($this->getOptions(), $this->value), ENT_COMPAT, 'UTF-8') .
'</span>';
}
/**
* 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
*/
public function getRepeatable()
{
if (isset($this->element['legacy']))
{
return $this->getInput();
}
$class = $this->class ? $this->class : '';
$link_url = $this->element['url'];
if ($link_url && ($this->item instanceof DataModel))
{
$link_url = $this->parseFieldTags($link_url);
}
else
{
$link_url = false;
}
$html = '<span class="' . $this->id . ' ' . $class . '">';
if ($link_url)
{
$html .= '<a href="' . $link_url . '">';
}
$html .= htmlspecialchars(self::getOptionName($this->getOptions(), $this->value), ENT_COMPAT, 'UTF-8');
if ($link_url)
{
$html .= '</a>';
}
$html .= '</span>';
return $html;
}
/**
* Gets the active option's label given an array of JHtml options
*
* @param array $data The JHtml options to parse
* @param mixed $selected The currently selected value
* @param string $optKey Key name
* @param string $optText Value name
* @param bool $selectFirst Should I automatically select the first option?
*
* @return mixed The label of the currently selected option
*/
public static function getOptionName($data, $selected = null, $optKey = 'value', $optText = 'text', $selectFirst = true)
{
$ret = null;
foreach ($data as $elementKey => &$element)
{
if (is_array($element))
{
$key = $optKey === null ? $elementKey : $element[$optKey];
$text = $element[$optText];
}
elseif (is_object($element))
{
$key = $optKey === null ? $elementKey : $element->$optKey;
$text = $element->$optText;
}
else
{
// This is a simple associative array
$key = $elementKey;
$text = $element;
}
if (is_null($ret) && $selectFirst)
{
$ret = $text;
}
elseif ($selected == $key)
{
$ret = $text;
}
}
return $ret;
}
/**
* Method to get the field options.
*
* Ordering is disabled by default. You can enable ordering by setting the
* 'order' element in your form field. The other order values are optional.
*
* - order What to order. Possible values: 'name' or 'value' (default = false)
* - order_dir Order direction. Possible values: 'asc' = Ascending or 'desc' = Descending (default = 'asc')
* - order_case_sensitive Order case sensitive. Possible values: 'true' or 'false' (default = false)
*
* @return array The field option objects.
*
* @since Ordering is available since FOF 2.1.b2.
*/
protected function getOptions()
{
// Ordering is disabled by default for backward compatibility
$order = false;
// Set default order direction
$order_dir = 'asc';
// Set default value for case sensitive sorting
$order_case_sensitive = false;
if ($this->element['order'] && $this->element['order'] !== 'false')
{
$order = $this->element['order'];
}
if ($this->element['order_dir'])
{
$order_dir = $this->element['order_dir'];
}
if ($this->element['order_case_sensitive'])
{
// Override default setting when the form element value is 'true'
if ($this->element['order_case_sensitive'] == 'true')
{
$order_case_sensitive = true;
}
}
// Create a $sortOptions array in order to apply sorting
$i = 0;
$sortOptions = array();
foreach ($this->element->children() as $option)
{
$name = JText::alt(trim((string) $option), preg_replace('/[^a-zA-Z0-9_\-]/', '_', $this->fieldname));
$sortOptions[$i] = new \stdClass;
$sortOptions[$i]->option = $option;
$sortOptions[$i]->value = $option['value'];
$sortOptions[$i]->name = $name;
$i++;
}
// Only order if it's set
if ($order)
{
jimport('joomla.utilities.arrayhelper');
if (class_exists('JArrayHelper'))
{
\JArrayHelper::sortObjects($sortOptions, $order, $order_dir == 'asc' ? 1 : -1, $order_case_sensitive, false);
}
else
{
ArrayHelper::sortObjects($sortOptions, $order, $order_dir == 'asc' ? 1 : -1, $order_case_sensitive, false);
}
}
// Initialise the options
$options = array();
// Get the field $options
foreach ($sortOptions as $sortOption)
{
/** @var \SimpleXMLElement $option */
$option = $sortOption->option;
$name = $sortOption->name;
// Only add <option /> elements.
if ($option->getName() != 'option')
{
continue;
}
$tmp = JHtml::_('select.option', (string) $option['value'], $name, 'value', 'text', ((string) $option['disabled'] == 'true'));
// Set some option attributes.
$tmp->class = (string) $option['class'];
// Set some JavaScript option attributes.
$tmp->onclick = (string) $option['onclick'];
// Add the option object to the result set.
$options[] = $tmp;
}
// Do we have a class and method source for our options?
$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'];
$source_key = empty($this->element['source_key']) ? '*' : (string) $this->element['source_key'];
$source_value = empty($this->element['source_value']) ? '*' : (string) $this->element['source_value'];
$source_translate = is_null($this->element['source_translate']) ? 'true' : (string) $this->element['source_translate'];
$source_translate = StringHelper::toBool($source_translate) ? true : false;
$source_format = empty($this->element['source_format']) ? '' : (string) $this->element['source_format'];
if ($source_class && $source_method)
{
// 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)))
{
// Get the data from the class
if ($source_format == 'optionsobject')
{
$options = array_merge($options, $source_class::$source_method());
}
else
{
// Get the data from the class
$source_data = $source_class::$source_method();
// Loop through the data and prime the $options array
foreach ($source_data as $k => $v)
{
$key = (empty($source_key) || ($source_key == '*')) ? $k : @$v[$source_key];
$value = (empty($source_value) || ($source_value == '*')) ? $v : @$v[$source_value];
if ($source_translate)
{
$value = JText::_($value);
}
$options[] = JHtml::_('select.option', $key, $value, 'value', 'text');
}
}
}
}
}
reset($options);
return $options;
}
/**
* 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;
}
}
Field/Image.php 0000644 00000000660 15235405654 0007335 0 ustar 00 <?php
/**
* @package FOF
* @copyright Copyright (c)2010-2019 Nicholas K. Dionysopoulos / Akeeba Ltd
* @license GNU GPL version 2 or later
*/
namespace FOF30\Form\Field;
defined('_JEXEC') or die;
/**
* Form Field class for the FOF framework
* Media selection field. This is an alias of the "media" field type.
*
* @deprecated 3.1 Support for XML forms will be removed in FOF 4
*/
class Image extends Media
{
}
Field/Components.php 0000644 00000014672 15235405654 0010450 0 ustar 00 <?php
/**
* @package FOF
* @copyright Copyright (c)2010-2019 Nicholas K. Dionysopoulos / Akeeba Ltd
* @license GNU GPL version 2 or later
*/
namespace FOF30\Form\Field;
use FOF30\Form\FieldInterface;
use FOF30\Form\Form;
use FOF30\Model\DataModel;
use JText;
defined('_JEXEC') or die;
\JFormHelper::loadFieldClass('list');
/**
* Form Field class for FOF
* Components installed on the site
*
* @deprecated 3.1 Support for XML forms will be removed in FOF 4
*/
class Components extends \JFormFieldList implements FieldInterface
{
/**
* @var string Static field output
*/
protected $static;
/**
* @var string Repeatable field output
*/
protected $repeatable;
/**
* The Form object of the form attached to the form field.
*
* @var Form
*/
protected $form;
/**
* A monotonically increasing number, denoting the row number in a repeatable view
*
* @var int
*/
public $rowid;
/**
* The item being rendered in a repeatable form field
*
* @var DataModel
*/
public $item;
/**
* Override for the list of client IDs. Comma separated list, e.g. "0,1"
*
* @var string
*/
public $client_ids = null;
/**
* Method to get certain otherwise inaccessible properties from the form field object.
*
* @param string $name The property name for which to the the value.
*
* @return mixed The property value or null.
*
* @since 2.1
*/
public function __get($name)
{
switch ($name)
{
case 'static':
if (empty($this->static))
{
$this->static = $this->getStatic();
}
return $this->static;
break;
case 'repeatable':
if (empty($this->repeatable))
{
$this->repeatable = $this->getRepeatable();
}
return $this->repeatable;
break;
default:
return parent::__get($name);
}
}
/**
* Get the rendering of this field type for static display, e.g. in a single
* item view (typically a "read" task).
*
* @since 2.1
*
* @return string The field HTML
*/
public function getStatic()
{
$options = array(
'id' => $this->id
);
return $this->getFieldContents($options);
}
/**
* 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.1
*
* @return string The field HTML
*/
public function getRepeatable()
{
$options = array(
'class' => $this->id
);
return $this->getFieldContents($options);
}
/**
* 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'] : '');
return '<span ' . ($id ? $id : '') . 'class="' . $class . '">' .
htmlspecialchars(GenericList::getOptionName($this->getOptions(), $this->value), ENT_COMPAT, 'UTF-8') .
'</span>';
}
/**
* Get a list of all installed components and also translates them.
*
* The manifest_cache is used to get the extension names, since JInstaller is also
* translating those names in stead of the name column. Else some of the translations
* fails.
*
* @since 2.1
*
* @return array An array of JHtml options.
*/
protected function getOptions()
{
$db = $this->form->getContainer()->platform->getDbo();
// Check for client_ids override
if ($this->client_ids !== null)
{
$client_ids = $this->client_ids;
}
else
{
$client_ids = $this->element['client_ids'];
}
$client_ids = explode(',', $client_ids);
// Calculate client_ids where clause
foreach ($client_ids as &$client_id)
{
$client_id = (int) trim($client_id);
$client_id = $db->q($client_id);
}
$query = $db->getQuery(true)
->select(
array(
$db->qn('name'),
$db->qn('element'),
$db->qn('client_id'),
$db->qn('manifest_cache'),
)
)
->from($db->qn('#__extensions'))
->where($db->qn('type') . ' = ' . $db->q('component'))
->where($db->qn('client_id') . ' IN (' . implode(',', $client_ids) . ')');
$components = $db->setQuery($query)->loadObjectList('element');
// Convert to array of objects, so we can use sortObjects()
// Also translate component names with JText::_()
$aComponents = array();
$user = $this->form->getContainer()->platform->getUser();
foreach ($components as $component)
{
// Don't show components in the list where the user doesn't have access for
// TODO: perhaps add an option for this
if (!$user->authorise('core.manage', $component->element))
{
continue;
}
$oData = (object) array(
'value' => $component->element,
'text' => $this->translate($component, 'component')
);
$aComponents[$component->element] = $oData;
}
// Reorder the components array, because the alphabetical
// ordering changed due to the JText::_() translation
uasort(
$aComponents,
function ($a, $b) {
return strcasecmp($a->text, $b->text);
}
);
return $aComponents;
}
/**
* 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;
}
}
Field/Integer.php 0000644 00000005300 15235405654 0007704 0 ustar 00 <?php
/**
* @package FOF
* @copyright Copyright (c)2010-2019 Nicholas K. Dionysopoulos / Akeeba Ltd
* @license GNU GPL version 2 or later
*/
namespace FOF30\Form\Field;
use FOF30\Form\FieldInterface;
use FOF30\Form\Form;
use FOF30\Model\DataModel;
defined('_JEXEC') or die;
\JFormHelper::loadFieldClass('integer');
/**
* Form Field class for the FOF framework
* Supports a one line text field.
*
* @deprecated 3.1 Support for XML forms will be removed in FOF 4
*/
class Integer extends \JFormFieldInteger implements FieldInterface
{
/**
* @var string Static field output
*/
protected $static;
/**
* @var string Repeatable field output
*/
protected $repeatable;
/**
* The Form object of the form attached to the form field.
*
* @var Form
*/
protected $form;
/**
* A monotonically increasing number, denoting the row number in a repeatable view
*
* @var int
*/
public $rowid;
/**
* The item being rendered in a repeatable form field
*
* @var DataModel
*/
public $item;
/**
* Method to get certain otherwise inaccessible properties from the form field object.
*
* @param string $name The property name for which to the the value.
*
* @return mixed The property value or null.
*
* @since 2.0
*/
public function __get($name)
{
switch ($name)
{
case 'static':
if (empty($this->static))
{
$this->static = $this->getStatic();
}
return $this->static;
break;
case 'repeatable':
if (empty($this->repeatable))
{
$this->repeatable = $this->getRepeatable();
}
return $this->repeatable;
break;
default:
return parent::__get($name);
}
}
/**
* Get the rendering of this field type for static display, e.g. in a single
* item view (typically a "read" task).
*
* @since 2.0
*
* @return string The field HTML
*/
public function getStatic()
{
if (isset($this->element['legacy']))
{
return $this->getInput();
}
$class = $this->class ? ' class="' . $this->class . '"' : '';
return '<span id="' . $this->id . '" ' . $class . '>' .
htmlspecialchars($this->value, ENT_COMPAT, 'UTF-8') .
'</span>';
}
/**
* 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
*/
public function getRepeatable()
{
if (isset($this->element['legacy']))
{
return $this->getInput();
}
$class = $this->class ? $this->class : '';
return '<span class="' . $this->id . ' ' . $class . '">' .
htmlspecialchars(GenericList::getOptionName($this->getOptions(), $this->value), ENT_COMPAT, 'UTF-8') .
'</span>';
}
}
Header/SelectRow.php 0000644 00000000621 15235405654 0010364 0 ustar 00 <?php
/**
* @package FOF
* @copyright Copyright (c)2010-2019 Nicholas K. Dionysopoulos / Akeeba Ltd
* @license GNU GPL version 2 or later
*/
namespace FOF30\Form\Header;
use JText;
defined('_JEXEC') or die;
/**
* Row selection checkbox. Alias to RowSelect (common typo)
*
* @deprecated 3.1 Support for XML forms will be removed in FOF 4
*/
class SelectRow extends RowSelect
{
}
Header/Sql.php 0000644 00000003115 15235405654 0007215 0 ustar 00 <?php
/**
* @package FOF
* @copyright Copyright (c)2010-2019 Nicholas K. Dionysopoulos / Akeeba Ltd
* @license GNU GPL version 2 or later
*/
namespace FOF30\Form\Header;
use JHtml;
use JText;
defined('_JEXEC') or die;
/**
* Generic field header, with drop down filters based on a SQL query
*
* @deprecated 3.1 Support for XML forms will be removed in FOF 4
*/
class Sql extends Selectable
{
/**
* Create objects for the options
*
* @return array The array of option objects
*/
protected function getOptions()
{
$options = array();
// Initialize some field attributes.
$key = $this->element['key_field'] ? (string) $this->element['key_field'] : 'value';
$value = $this->element['value_field'] ? (string) $this->element['value_field'] : (string) $this->element['name'];
$translate = $this->element['translate'] ? (string) $this->element['translate'] : false;
$query = (string) $this->element['query'];
// Get the database object.
$db = $this->form->getContainer()->platform->getDbo();
// Set the query and get the result list.
$db->setQuery($query);
$items = $db->loadObjectlist();
// Build the field options.
if (!empty($items))
{
foreach ($items as $item)
{
if ($translate == true)
{
$options[] = JHtml::_('select.option', $item->$key, JText::_($item->$value));
}
else
{
$options[] = JHtml::_('select.option', $item->$key, $item->$value);
}
}
}
// Merge any additional options in the XML definition.
$options = array_merge(parent::getOptions(), $options);
return $options;
}
}
Header/Date.php 0000644 00000006171 15235405654 0007340 0 ustar 00 <?php
/**
* @package FOF
* @copyright Copyright (c)2010-2019 Nicholas K. Dionysopoulos / Akeeba Ltd
* @license GNU GPL version 2 or later
*/
namespace FOF30\Form\Header;
use JHtml;
use JText;
defined('_JEXEC') or die;
/**
* Generic field header, with text input (search) filter
*
* @deprecated 3.1 Support for XML forms will be removed in FOF 4
*/
class Date extends Field
{
/**
* Get the filter field
*
* @return string The HTML
*/
protected function getFilter()
{
// Initialize some field attributes.
$format = $this->element['format'] ? (string) $this->element['format'] : '%Y-%m-%d';
$attributes = array();
if ($this->element['size'])
{
$attributes['size'] = (int) $this->element['size'];
}
if ($this->element['maxlength'])
{
$attributes['maxlength'] = (int) $this->element['maxlength'];
}
if ($this->element['filterclass'])
{
$attributes['class'] = (string) $this->element['filterclass'];
}
if ((string) $this->element['readonly'] == 'true')
{
$attributes['readonly'] = 'readonly';
}
if ((string) $this->element['disabled'] == 'true')
{
$attributes['disabled'] = 'disabled';
}
if ($this->element['onchange'])
{
$attributes['onChange'] = (string) $this->element['onchange'];
}
else
{
$attributes['onChange'] = 'document.adminForm.submit()';
}
if ((string) $this->element['placeholder'])
{
$attributes['placeholder'] = JText::_((string) $this->element['placeholder']);
}
$name = $this->element['searchfieldname'] ? $this->element['searchfieldname'] : $this->name;
if ($this->element['searchfieldname'])
{
$model = $this->form->getModel();
$searchvalue = $model->getState((string) $this->element['searchfieldname']);
}
else
{
$searchvalue = $this->value;
}
// Get some system objects.
$config = $this->form->getContainer()->platform->getConfig();
$user = $this->form->getContainer()->platform->getUser();
// If a known filter is given use it.
switch (strtoupper((string) $this->element['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 = $this->form->getContainer()->platform->getDate($searchvalue, 'UTC');
$date->setTimezone(new \DateTimeZone($config->get('offset')));
// Transform the date string.
$searchvalue = $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) $searchvalue)
{
// Get a date object based on the correct timezone.
$date = $this->form->getContainer()->platform->getDate($this->value, 'UTC');
$date->setTimezone(new \DateTimeZone($user->getParam('timezone', $config->get('offset'))));
// Transform the date string.
$searchvalue = $date->format('Y-m-d H:i:s', true, false);
}
break;
}
return JHtml::_('calendar', $searchvalue, $name, $name, $format, $attributes);
}
/**
* Get the buttons HTML code
*
* @return string The HTML
*/
protected function getButtons()
{
return '';
}
}
Header/Filterable.php 0000644 00000005207 15235405654 0010533 0 ustar 00 <?php
/**
* @package FOF
* @copyright Copyright (c)2010-2019 Nicholas K. Dionysopoulos / Akeeba Ltd
* @license GNU GPL version 2 or later
*/
namespace FOF30\Form\Header;
use JText;
defined('_JEXEC') or die;
/**
* Generic field header, with text input (search) filter
*
* @deprecated 3.1 Support for XML forms will be removed in FOF 4
*/
class Filterable extends Searchable
{
/**
* Get the filter field
*
* @return string The HTML
*/
protected function getFilter()
{
$valide = array('yes', 'true', '1');
// Initialize some field(s) attributes.
$size = $this->element['size'] ? ' size="' . (int) $this->element['size'] . '"' : '';
$maxLength = $this->element['maxlength'] ? ' maxlength="' . (int) $this->element['maxlength'] . '"' : '';
$filterclass = $this->element['filterclass'] ? ' class="' . (string) $this->element['filterclass'] . '"' : '';
$placeholder = $this->element['placeholder'] ? $this->element['placeholder'] : $this->getLabel();
$name = $this->element['searchfieldname'] ? $this->element['searchfieldname'] : $this->name;
$placeholder = ' placeholder="' . JText::_($placeholder) . '"';
$single = in_array($this->element['single'], $valide) ? true : false;
$showMethod = in_array($this->element['showmethod'], $valide) ? true : false;
$method = $this->element['method'] ? $this->element['method'] : 'between';
$fromName = $this->element['fromname'] ? $this->element['fromname'] : 'from';
$toName = $this->element['toname'] ? $this->element['toname'] : 'to';
$values = $this->form->getModel()->getState($name);
$fromValue = $values[$fromName];
$toValue = $values[$toName];
// Initialize JavaScript field attributes.
if ($this->element['onchange'])
{
$onchange = ' onchange="' . (string) $this->element['onchange'] . '"';
}
else
{
$onchange = ' onchange="document.adminForm.submit();"';
}
if ($showMethod)
{
$html = '<input type="text" name="' . $name . '[method]" value="'. $method . '" />';
} else
{
$html = '<input type="hidden" name="' . $name . '[method]" value="'. $method . '" />';
}
$html .= '<input type="text" name="' . $name . '[from]" id="' . $this->id . '_' . $fromName . '"' . ' value="'
. htmlspecialchars($fromValue, ENT_COMPAT, 'UTF-8') . '"' . $filterclass . $size . $placeholder . $onchange . $maxLength . '/>';
if (!$single)
{
$html .= '<input type="text" name="' . $name . '[to]" id="' . $this->id . '_' . $toName . '"' . ' value="'
. htmlspecialchars($toValue, ENT_COMPAT, 'UTF-8') . '"' . $filterclass . $size . $placeholder . $onchange . $maxLength . '/>';
}
return $html;
}
}
Header/HeaderBase.php 0000644 00000030360 15235405654 0010443 0 ustar 00 <?php
/**
* @package FOF
* @copyright Copyright (c)2010-2019 Nicholas K. Dionysopoulos / Akeeba Ltd
* @license GNU GPL version 2 or later
*/
namespace FOF30\Form\Header;
use FOF30\Form\Form;
use FOF30\Form\HeaderInterface;
use SimpleXMLElement;
defined('_JEXEC') or die;
/**
* A base class for HeaderInterface fields, used to define the filters and the
* elements of the header row in repeatable (browse) views
*
* @package FrameworkOnFramework
* @since 2.0
*
* @deprecated 3.1 Support for XML forms will be removed in FOF 4
*/
abstract class HeaderBase
{
/**
* The description text for the form field. Usually used in tooltips.
*
* @var string
* @since 2.0
*/
protected $description;
/**
* The SimpleXMLElement object of the <field /> XML element that describes the header field.
*
* @var SimpleXMLElement
* @since 2.0
*/
protected $element;
/**
* The Form object of the form attached to the header field.
*
* @var Form
* @since 2.0
*/
protected $form;
/**
* The label for the header field.
*
* @var string
* @since 2.0
*/
protected $label;
/**
* The header HTML.
*
* @var string|null
* @since 2.0
*/
protected $header;
/**
* The filter HTML.
*
* @var string|null
* @since 2.0
*/
protected $filter;
/**
* The buttons HTML.
*
* @var string|null
* @since 2.0
*/
protected $buttons;
/**
* The options for a drop-down filter.
*
* @var array|null
* @since 2.0
*/
protected $options;
/**
* The name of the form field.
*
* @var string
* @since 2.0
*/
protected $name;
/**
* The name of the field.
*
* @var string
* @since 2.0
*/
protected $fieldname;
/**
* The group of the field.
*
* @var string
* @since 2.0
*/
protected $group;
/**
* The form field type.
*
* @var string
* @since 2.0
*/
protected $type;
/**
* The value of the filter.
*
* @var mixed
* @since 2.0
*/
protected $value;
/**
* The intended table data width (in pixels or percent).
*
* @var mixed
* @since 2.0
*/
protected $tdwidth;
/**
* The key of the filter value in the model state.
*
* @var mixed
* @since 2.0
*/
protected $filterSource;
/**
* The name of the filter field
*
* @var mixed
* @since 3.0
*/
protected $filterFieldName;
/**
* Is this a sortable column?
*
* @var bool
* @since 2.0
*/
protected $sortable = false;
/**
* Should we ignore the header (have the field act as just a filter)?
*
* @var bool
* @since 3.0
*/
protected $onlyFilter = false;
/**
* Method to instantiate the form field object.
*
* @param Form $form The form to attach to the form field object.
*
* @since 2.0
*/
public function __construct(Form $form = null)
{
// If there is a form passed into the constructor set the form and form control properties.
if ($form instanceof Form)
{
$this->form = $form;
}
}
/**
* Method to get certain otherwise inaccessible properties from the form field object.
*
* @param string $name The property name for which to the the value.
*
* @return mixed The property value or null.
*
* @since 2.0
*/
public function __get($name)
{
switch ($name)
{
case 'description':
case 'name':
case 'type':
case 'fieldname':
case 'group':
case 'tdwidth':
case 'filterSource':
case 'filterFieldName':
return $this->$name;
break;
case 'label':
if (empty($this->label))
{
$this->label = $this->getLabel();
}
return $this->label;
case 'value':
if (empty($this->value))
{
$this->value = $this->getValue();
}
return $this->value;
break;
case 'header':
if (empty($this->header))
{
$this->header = $this->onlyFilter ? '' : $this->getHeader();
}
return $this->header;
break;
case 'filter':
if (empty($this->filter))
{
$this->filter = $this->getFilter();
}
return $this->filter;
break;
case 'buttons':
if (empty($this->buttons))
{
$this->buttons = $this->getButtons();
}
return $this->buttons;
break;
case 'options':
if (empty($this->options))
{
$this->options = $this->getOptions();
}
return $this->options;
break;
case 'sortable':
if (empty($this->sortable))
{
$this->sortable = $this->getSortable();
}
return $this->sortable;
break;
}
return null;
}
/**
* Method to attach a JForm object to the field.
*
* @param Form $form The JForm object to attach to the form field.
*
* @return HeaderInterface The form field object so that the method can be used in a chain.
*
* @since 2.0
*/
public function setForm(Form $form)
{
$this->form = $form;
return $this;
}
/**
* Method to attach a Form object to the field.
*
* @param SimpleXMLElement $element The SimpleXMLElement object representing the <field /> tag for the form field object.
* @param string $group The field name group control value. This acts as as an array container for the field.
* For example if the field has name="foo" and the group value is set to "bar" then the
* full field name would end up being "bar[foo]".
*
* @return boolean True on success.
*
* @since 2.0
*/
public function setup(SimpleXMLElement $element, $group = null)
{
// Make sure there is a valid JFormField XML element.
if ((string) $element->getName() != 'header')
{
return false;
}
// Reset the internal fields
$this->label = null;
$this->header = null;
$this->filter = null;
$this->buttons = null;
$this->options = null;
$this->value = null;
$this->filterSource = null;
$this->filterFieldName = null;
// Set the XML element object.
$this->element = $element;
// Get some important attributes from the form field element.
$id = (string) $element['id'];
$name = (string) $element['name'];
$filterSource = (string) $element['filter_source'];
$filterFieldName = (string) $element['searchfieldname'];
$tdwidth = (string) $element['tdwidth'];
// Set the field description text.
$this->description = (string) $element['description'];
// Set the group of the field.
$this->group = $group;
// Set the td width of the field.
$this->tdwidth = $tdwidth;
// Set the field name and id.
$this->fieldname = $this->getFieldName($name);
$this->name = $this->getName($this->fieldname);
$this->id = $this->getId($id, $this->fieldname);
$this->filterSource = $this->getFilterSource($filterSource);
$this->filterFieldName = $this->getFilterFieldName($filterFieldName);
// Set the field default value.
$this->value = $this->getValue();
// Setup the onlyFilter property
$onlyFilter = $this->element['onlyFilter'] ? (string) $this->element['onlyFilter'] : false;
$this->onlyFilter = in_array($onlyFilter, array('yes', 'on', '1', 'true'));
return true;
}
/**
* Method to get the id used for the field input tag.
*
* @param string $fieldId The field element id.
* @param string $fieldName The field element name.
*
* @return string The id to be used for the field input tag.
*
* @since 2.0
*/
protected function getId($fieldId, $fieldName)
{
$id = '';
// If the field is in a group add the group control to the field id.
if ($this->group)
{
// If we already have an id segment add the group control as another level.
if ($id)
{
$id .= '_' . str_replace('.', '_', $this->group);
}
else
{
$id .= str_replace('.', '_', $this->group);
}
}
// If we already have an id segment add the field id/name as another level.
if ($id)
{
$id .= '_' . ($fieldId ? $fieldId : $fieldName);
}
else
{
$id .= ($fieldId ? $fieldId : $fieldName);
}
// Clean up any invalid characters.
$id = preg_replace('#\W#', '_', $id);
return $id;
}
/**
* Method to get the name used for the field input tag.
*
* @param string $fieldName The field element name.
*
* @return string The name to be used for the field input tag.
*
* @since 2.0
*/
protected function getName($fieldName)
{
$name = '';
// If the field is in a group add the group control to the field name.
if ($this->group)
{
// If we already have a name segment add the group control as another level.
$groups = explode('.', $this->group);
if ($name)
{
foreach ($groups as $group)
{
$name .= '[' . $group . ']';
}
}
else
{
$name .= array_shift($groups);
foreach ($groups as $group)
{
$name .= '[' . $group . ']';
}
}
}
// If we already have a name segment add the field name as another level.
if ($name)
{
$name .= '[' . $fieldName . ']';
}
else
{
$name .= $fieldName;
}
return $name;
}
/**
* Method to get the field name used.
*
* @param string $fieldName The field element name.
*
* @return string The field name
*
* @since 2.0
*/
protected function getFieldName($fieldName)
{
return $fieldName;
}
/**
* Method to get the field label.
*
* @return string The field label.
*
* @since 2.0
*/
protected function getLabel()
{
// Get the label text from the XML element, defaulting to the element name.
$title = $this->element['label'] ? (string) $this->element['label'] : '';
if (empty($title))
{
$viewObject = $this->form->getView();
$viewName = $viewObject->getName();
$componentName = $viewObject->getContainer()->componentName;
$title = $componentName . '_' .
$this->form->getModel()->getContainer()->inflector->pluralize($viewName) . '_FIELD_' .
(string) $this->element['name'];
$title = strtoupper($title);
$result = \JText::_($title);
if ($result === $title)
{
$title = ucfirst((string) $this->element['name']);
}
}
return $title;
}
/**
* 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);
}
/**
* Return the key of the filter value in the model state or, if it's not set,
* the name of the field.
*
* @param string $filterSource The filter source value to return
*
* @return string
*/
protected function getFilterSource($filterSource)
{
if ($filterSource)
{
return $filterSource;
}
else
{
return $this->name;
}
}
/**
* Return the name of the filter field
*
* @param string $filterFieldName The filter field name source value to return
*
* @return string
*/
protected function getFilterFieldName($filterFieldName)
{
if ($filterFieldName)
{
return $filterFieldName;
}
else
{
return $this->filterSource;
}
}
/**
* Is this a sortable field?
*
* @return boolean True if it's sortable
*/
protected function getSortable()
{
$sortable = ($this->element['sortable'] != 'false');
if ($sortable)
{
if (empty($this->header))
{
$this->header = $this->onlyFilter ? '' : $this->getHeader();
}
$sortable = !empty($this->header);
}
return $sortable;
}
/**
* Returns the HTML for the header row, or null if this element should
* render no header element
*
* @return string|null HTML code or null if nothing is to be rendered
*
* @since 2.0
*/
protected function getHeader()
{
return null;
}
/**
* Returns the HTML for a text filter to be rendered in the filter row,
* or null if this element should render no text input filter.
*
* @return string|null HTML code or null if nothing is to be rendered
*
* @since 2.0
*/
protected function getFilter()
{
return null;
}
/**
* Returns the HTML for the buttons to be rendered in the filter row,
* next to the text input filter, or null if this element should render no
* text input filter buttons.
*
* @return string|null HTML code or null if nothing is to be rendered
*
* @since 2.0
*/
protected function getButtons()
{
return null;
}
/**
* Returns the JHtml options for a drop-down filter. Do not include an
* empty option, it is added automatically.
*
* @return array The JHtml options for a drop-down filter
*
* @since 2.0
*/
protected function getOptions()
{
return array();
}
}
Header/Language.php 0000644 00000001633 15235405654 0010204 0 ustar 00 <?php
/**
* @package FOF
* @copyright Copyright (c)2010-2019 Nicholas K. Dionysopoulos / Akeeba Ltd
* @license GNU GPL version 2 or later
*/
namespace FOF30\Form\Header;
defined('_JEXEC') or die;
/**
* Language field header
*
* @deprecated 3.1 Support for XML forms will be removed in FOF 4
*/
class Language extends Selectable
{
/**
* Method to get the filter options.
*
* @return array The filter option objects.
*
* @since 2.0
*/
protected function getOptions()
{
// Initialize some field attributes.
$client = (string) $this->element['client'];
if ($client != 'site' && $client != 'administrator')
{
$client = 'site';
}
// Merge any additional options in the XML definition.
$options = array_merge(
parent::getOptions(), \JLanguageHelper::createLanguageList($this->value, constant('JPATH_' . strtoupper($client)), true, true)
);
return $options;
}
}
Header/Model.php 0000644 00000006550 15235405654 0007524 0 ustar 00 <?php
/**
* @package FOF
* @copyright Copyright (c)2010-2019 Nicholas K. Dionysopoulos / Akeeba Ltd
* @license GNU GPL version 2 or later
*/
namespace FOF30\Form\Header;
use FOF30\Container\Container;
use FOF30\Model\DataModel;
use JHtml;
use JText;
defined('_JEXEC') or die;
if (!class_exists('JFormFieldSql'))
{
require_once JPATH_LIBRARIES . '/joomla/form/fields/sql.php';
}
/**
* Form Field class for FOF
* Generic list from a model's results
*
* @deprecated 3.1 Support for XML forms will be removed in FOF 4
*/
class Model extends Selectable
{
/**
* Method to get the field options.
*
* @return array The field option objects.
*/
protected function getOptions()
{
$options = array();
// Initialize some field attributes.
$key = $this->element['key_field'] ? (string) $this->element['key_field'] : 'value';
$value = $this->element['value_field'] ? (string) $this->element['value_field'] : (string) $this->element['name'];
$applyAccess = $this->element['apply_access'] ? (string) $this->element['apply_access'] : 'false';
$modelName = (string) $this->element['model'];
$nonePlaceholder = (string) $this->element['none'];
$translate = empty($this->element['translate']) ? 'true' : (string) $this->element['translate'];
$translate = in_array(strtolower($translate), array('true','yes','1','on')) ? true : false;
$with = $this->element['with'] ? (string) $this->element['with'] : null;
if (!is_null($with))
{
$with = trim($with);
$with = explode(',', $with);
$with = array_map('trim', $with);
}
if (!empty($nonePlaceholder))
{
$options[] = JHtml::_('select.option', null, JText::_($nonePlaceholder));
}
// Process field atrtibutes
$applyAccess = strtolower($applyAccess);
$applyAccess = in_array($applyAccess, array('yes', 'on', 'true', '1'));
// Explode model name into component name and prefix
$componentName = $this->form->getContainer()->componentName;
$mName = $modelName;
if (strpos($modelName, '.') !== false)
{
list ($componentName, $mName) = explode('.', $mName, 2);
}
// Get the applicable container
$container = $this->form->getContainer();
if ($componentName != $container->componentName)
{
$container = Container::getInstance($componentName);
}
/** @var DataModel $model */
$model = $container->factory->model($mName)->setIgnoreRequest(true)->savestate(false);
if ($applyAccess)
{
$model->applyAccessFiltering();
}
if (!is_null($with))
{
$model->with($with);
}
// Process state variables
/** @var \SimpleXMLElement $stateoption */
foreach ($this->element->children() as $stateoption)
{
// Only add <option /> elements.
if ($stateoption->getName() != 'state')
{
continue;
}
$stateKey = (string) $stateoption['key'];
$stateValue = (string) $stateoption;
$model->setState($stateKey, $stateValue);
}
// Set the query and get the result list.
$items = $model->get(true);
// Build the field options.
if (!empty($items))
{
foreach ($items as $item)
{
if ($translate == true)
{
$options[] = JHtml::_('select.option', $item->$key, JText::_($item->$value));
}
else
{
$options[] = JHtml::_('select.option', $item->$key, $item->$value);
}
}
}
// Merge any additional options in the XML definition.
$options = array_merge(parent::getOptions(), $options);
return $options;
}
}
Header/Selectable.php 0000644 00000006334 15235405654 0010527 0 ustar 00 <?php
/**
* @package FOF
* @copyright Copyright (c)2010-2019 Nicholas K. Dionysopoulos / Akeeba Ltd
* @license GNU GPL version 2 or later
*/
namespace FOF30\Form\Header;
use JHtml;
use JText;
defined('_JEXEC') or die;
/**
* Generic field header, with drop down filters
*
* @deprecated 3.1 Support for XML forms will be removed in FOF 4
*/
class Selectable extends Field
{
/**
* Create objects for the options
*
* @return array The array of option objects
*/
protected function getOptions()
{
$options = array();
// Get the field $options
/** @var \SimpleXMLElement $option */
foreach ($this->element->children() as $option)
{
// Only add <option /> elements.
if ($option->getName() != 'option')
{
continue;
}
// Create a new option object based on the <option /> element.
$options[] = JHtml::_(
'select.option',
(string) $option['value'],
JText::alt(
trim((string) $option),
preg_replace('/[^a-zA-Z0-9_\-]/', '_', $this->fieldname)
),
'value', 'text', ((string) $option['disabled'] == 'true')
);
}
// Do we have a class and method source for our options?
$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'];
$source_key = empty($this->element['source_key']) ? '*' : (string) $this->element['source_key'];
$source_value = empty($this->element['source_value']) ? '*' : (string) $this->element['source_value'];
$source_translate = empty($this->element['source_translate']) ? 'true' : (string) $this->element['source_translate'];
$source_translate = in_array(strtolower($source_translate), array('true','yes','1','on')) ? true : false;
$source_format = empty($this->element['source_format']) ? '' : (string) $this->element['source_format'];
if ($source_class && $source_method)
{
// 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)))
{
// Get the data from the class
if ($source_format == 'optionsobject')
{
$options = array_merge($options, $source_class::$source_method());
}
else
{
$source_data = $source_class::$source_method();
// Loop through the data and prime the $options array
foreach ($source_data as $k => $v)
{
$key = (empty($source_key) || ($source_key == '*')) ? $k : @$v[$source_key];
$value = (empty($source_value) || ($source_value == '*')) ? $v : @$v[$source_value];
if ($source_translate)
{
$value = JText::_($value);
}
$options[] = JHtml::_('select.option', $key, $value, 'value', 'text');
}
}
}
}
}
reset($options);
return $options;
}
}
Header/Published.php 0000644 00000002234 15235405654 0010376 0 ustar 00 <?php
/**
* @package FOF
* @copyright Copyright (c)2010-2019 Nicholas K. Dionysopoulos / Akeeba Ltd
* @license GNU GPL version 2 or later
*/
namespace FOF30\Form\Header;
use JHtml;
defined('_JEXEC') or die;
/**
* Field header for Published (enabled) columns
*
* @deprecated 3.1 Support for XML forms will be removed in FOF 4
*/
class Published extends Selectable
{
/**
* Create objects for the options
*
* @return array The array of option objects
*/
protected function getOptions()
{
$config = array(
'published' => 1,
'unpublished' => 1,
'archived' => 0,
'trash' => 0,
'all' => 0,
);
if ($this->element['show_published'] == 'false')
{
$config['published'] = 0;
}
if ($this->element['show_unpublished'] == 'false')
{
$config['unpublished'] = 0;
}
if ($this->element['show_archived'] == 'true')
{
$config['archived'] = 1;
}
if ($this->element['show_trash'] == 'true')
{
$config['trash'] = 1;
}
if ($this->element['show_all'] == 'true')
{
$config['all'] = 1;
}
$options = JHtml::_('jgrid.publishedOptions', $config);
reset($options);
return $options;
}
}
Header/Ordering.php 0000644 00000005137 15235405654 0010235 0 ustar 00 <?php
/**
* @package FOF
* @copyright Copyright (c)2010-2019 Nicholas K. Dionysopoulos / Akeeba Ltd
* @license GNU GPL version 2 or later
*/
namespace FOF30\Form\Header;
use JHtml;
use JText;
defined('_JEXEC') or die;
/**
* Ordering field header
*
* @deprecated 3.1 Support for XML forms will be removed in FOF 4
*/
class Ordering extends Field
{
/**
* Get the header
*
* @return string The header HTML
*/
protected function getHeader()
{
$sortable = ($this->element['sortable'] != 'false');
$dnd = isset($this->element['dragndrop']) ? (string) $this->element['dragndrop'] : 'notbroken';
if (strtolower($dnd) == 'notbroken')
{
$dnd = !version_compare(JVERSION, '3.5.0', 'ge');
}
else
{
$dnd = in_array(strtolower($dnd), array('1', 'true', 'yes', 'on', 'enabled'), true);
}
if (!$sortable)
{
// Non sortable?! I'm not sure why you'd want that, but if you insist...
return JText::_('JGRID_HEADING_ORDERING');
}
$iconClass = isset($this->element['iconClass']) ? (string) $this->element['iconClass'] : 'icon-menu-2';
$class = isset($this->element['class']) ? (string) $this->element['class'] : 'btn btn-micro pull-right';
$view = $this->form->getView();
$model = $this->form->getModel();
// Drag'n'drop ordering support WITH a save order button
$html = JHtml::_(
'grid.sort',
'<i class="' . $iconClass . '"></i>',
'ordering',
$view->getLists()->order_Dir,
$view->getLists()->order,
null,
'asc',
'JGRID_HEADING_ORDERING'
);
$ordering = $view->getLists()->order == 'ordering';
/**
* Joomla! 3.5 and later: drag and drop reordering is broken when the ordering field is not hidden
* because some random bloke submitted that code and some supposedly responsible adult with commit
* rights committed it. I tried to file a PR to fix it and got the reply "can't test, won't test".
* OK, then. You blindly accepted code which did the EXACT OPPOSITE of what it promised and broke
* b/c. However, you won't accept the fix to your mess from someone who knows how Joomla! works and
* wasted 2 hours of his time to track down your mistake, fix it and explain why your actions
* resulted in a b/c break. You have to be kidding me!
*/
$joomla35IsBroken = version_compare(JVERSION, '3.5.0', 'ge');
if ($ordering && (!$joomla35IsBroken || !$dnd))
{
$html .= '<a href="javascript:saveorder(' . (count($model->get()) - 1) . ', \'saveorder\')" ' .
'rel="tooltip" class="save-order ' . $class . '" title="' . JText::_('JLIB_HTML_SAVE_ORDER') . '">'
. '<span class="icon-ok"></span></a>';
}
return $html;
}
}
Header/Searchable.php 0000644 00000005212 15235405654 0010507 0 ustar 00 <?php
/**
* @package FOF
* @copyright Copyright (c)2010-2019 Nicholas K. Dionysopoulos / Akeeba Ltd
* @license GNU GPL version 2 or later
*/
namespace FOF30\Form\Header;
use JText;
defined('_JEXEC') or die;
/**
* Generic field header, with text input (search) filter
*
* @deprecated 3.1 Support for XML forms will be removed in FOF 4
*/
class Searchable extends Field
{
/**
* Get the filter field
*
* @return string The HTML
*/
protected function getFilter()
{
// Initialize some field attributes.
$size = $this->element['size'] ? ' size="' . (int) $this->element['size'] . '"' : '';
$maxLength = $this->element['maxlength'] ? ' maxlength="' . (int) $this->element['maxlength'] . '"' : '';
$filterclass = $this->element['filterclass'] ? ' class="' . (string) $this->element['filterclass'] . '"' : '';
$placeholder = $this->element['placeholder'] ? $this->element['placeholder'] : $this->getLabel();
$name = $this->element['searchfieldname'] ? $this->element['searchfieldname'] : $this->name;
$placeholder = ' placeholder="' . JText::_($placeholder) . '"';
if ($this->element['searchfieldname'])
{
$model = $this->form->getModel();
$searchvalue = $model->getState((string) $this->element['searchfieldname']);
}
else
{
$searchvalue = $this->value;
}
// Initialize JavaScript field attributes.
if ($this->element['onchange'])
{
$onchange = ' onchange="' . (string) $this->element['onchange'] . '"';
}
else
{
$onchange = ' onchange="document.adminForm.submit();"';
}
return '<input type="text" name="' . $name . '" id="' . $this->id . '"' . ' value="'
. htmlspecialchars($searchvalue, ENT_COMPAT, 'UTF-8') . '"' . $filterclass . $size . $placeholder . $onchange . $maxLength . '/>';
}
/**
* Get the buttons HTML code
*
* @return string The HTML
*/
protected function getButtons()
{
$buttonclass = $this->element['buttonclass'] ? (string) $this->element['buttonclass'] : 'btn hasTip hasTooltip';
$buttonsState = strtolower($this->element['buttons']);
$show_buttons = !in_array($buttonsState, array('no', 'false', '0'));
if (!$show_buttons)
{
return '';
}
$html = '';
$html .= '<button class="' . $buttonclass . '" onclick="this.form.submit();" title="' . JText::_('JSEARCH_FILTER') . '" >' . "\n";
$html .= '<i class="icon-search"></i>';
$html .= '</button>' . "\n";
$html .= '<button class="' . $buttonclass . '" onclick="document.adminForm.' . $this->id . '.value=\'\';this.form.submit();" title="' . JText::_('JSEARCH_RESET') . '">' . "\n";
$html .= '<i class="icon-remove"></i>';
$html .= '</button>' . "\n";
return $html;
}
}
Header/RowSelect.php 0000644 00000001161 15235405654 0010364 0 ustar 00 <?php
/**
* @package FOF
* @copyright Copyright (c)2010-2019 Nicholas K. Dionysopoulos / Akeeba Ltd
* @license GNU GPL version 2 or later
*/
namespace FOF30\Form\Header;
use JText;
defined('_JEXEC') or die;
/**
* Row selection checkbox
*
* @deprecated 3.1 Support for XML forms will be removed in FOF 4
*/
class RowSelect extends Field
{
/**
* Get the header
*
* @return string The header HTML
*/
protected function getHeader()
{
return '<input type="checkbox" name="checkall-toggle" value="" title="'
. JText::_('JGLOBAL_CHECK_ALL')
. '" onclick="Joomla.checkAll(this)" />';
}
}
Header/AccessLevel.php 0000644 00000001652 15235405654 0010653 0 ustar 00 <?php
/**
* @package FOF
* @copyright Copyright (c)2010-2019 Nicholas K. Dionysopoulos / Akeeba Ltd
* @license GNU GPL version 2 or later
*/
namespace FOF30\Form\Header;
defined('_JEXEC') or die;
/**
* Access level field header
*
* @deprecated 3.1 Support for XML forms will be removed in FOF 4
*/
class AccessLevel extends Selectable
{
/**
* Method to get the list of access levels
*
* @return array A list of access levels.
*
* @since 2.0
*/
protected function getOptions()
{
$db = $this->form->getContainer()->platform->getDbo();
$query = $db->getQuery(true);
$query->select('a.id AS value, a.title AS text');
$query->from('#__viewlevels AS a');
$query->group('a.id, a.title, a.ordering');
$query->order('a.ordering ASC');
$query->order($query->qn('title') . ' ASC');
// Get the options.
$db->setQuery($query);
$options = $db->loadObjectList();
return $options;
}
}
Header/Field.php 0000644 00000001516 15235405654 0007504 0 ustar 00 <?php
/**
* @package FOF
* @copyright Copyright (c)2010-2019 Nicholas K. Dionysopoulos / Akeeba Ltd
* @license GNU GPL version 2 or later
*/
namespace FOF30\Form\Header;
use JHtml;
use JText;
defined('_JEXEC') or die;
/**
* Generic field header, without any filters
*
* @deprecated 3.1 Support for XML forms will be removed in FOF 4
*/
class Field extends HeaderBase
{
/**
* Get the header
*
* @return string The header HTML
*/
protected function getHeader()
{
$sortable = ($this->element['sortable'] != 'false');
$label = $this->getLabel();
if ($sortable)
{
$view = $this->form->getView();
return JHTML::_('grid.sort', $label, $this->name,
$view->getLists()->order_Dir, $view->getLists()->order,
$this->form->getModel()->task
);
}
else
{
return JText::_($label);
}
}
}
Element/BackgroundAnimation.php 0000644 00000001124 15235664445 0012601 0 ustar 00 <?php
namespace Nextend\SmartSlider3\Form\Element;
use Nextend\Framework\Asset\Js\Js;
use Nextend\Framework\Form\Element\AbstractChooser;
use Nextend\SmartSlider3\Slider\SliderType\Simple\SliderTypeSimple;
class BackgroundAnimation extends AbstractChooser {
protected function addScript() {
Js::addStaticGroup(SliderTypeSimple::getAssetsPath() . '/dist/smartslider-backgroundanimation.min.js', 'smartslider-backgroundanimation');
Js::addInline('new _N2.FormElementAnimationManager("' . $this->fieldID . '", "backgroundanimationManager");');
}
} Element/BackgroundImage.php 0000644 00000001211 15235664445 0011701 0 ustar 00 <?php
namespace Nextend\SmartSlider3\Form\Element;
use Nextend\Framework\Form\Element\IconTab;
class BackgroundImage extends IconTab {
protected $relatedAttribute = 'slide-background-type';
protected function fetchElement() {
$this->options = array(
'image' => 'ssi_16 ssi_16--image',
'video' => 'ssi_16 ssi_16--video',
'color' => 'ssi_16 ssi_16--color'
);
$this->tooltips = array(
'image' => n2_('Image'),
'video' => n2_('Video'),
'color' => n2_('Color')
);
return parent::fetchElement();
}
} Element/Columns.php 0000644 00000001760 15235664445 0010310 0 ustar 00 <?php
namespace Nextend\SmartSlider3\Form\Element;
use Nextend\Framework\Asset\Js\Js;
use Nextend\Framework\Form\Element\AbstractFieldHidden;
use Nextend\Framework\View\Html;
class Columns extends AbstractFieldHidden {
protected $hasTooltip = false;
public function __construct($insertAt, $name = '', $default = '', $parameters = array()) {
parent::__construct($insertAt, $name, false, $default, $parameters);
}
protected function fetchElement() {
Js::addInline('new _N2.FormElementColumns("' . $this->fieldID . '");');
return Html::tag('div', array(
'class' => 'n2_field_columns'
), Html::tag('div', array(
'class' => 'n2_field_columns__content'
), '') . Html::tag('div', array(
'class' => 'n2_field_columns__add',
'data-n2tip' => n2_('Add column')
), '<div class="ssi_16 ssi_16--plus"></div>') . parent::fetchElement());
}
} Element/ControlTypePicker.php 0000644 00000006235 15235664445 0012312 0 ustar 00 <?php
namespace Nextend\SmartSlider3\Form\Element;
use Nextend\Framework\Asset\Js\Js;
use Nextend\Framework\Form\Container\ContainerSubform;
use Nextend\Framework\Form\ContainerInterface;
use Nextend\Framework\Form\Element\AbstractFieldHidden;
use Nextend\Framework\Form\TraitFieldset;
use Nextend\Framework\Url\Url;
use Nextend\SmartSlider3\Widget\Group\AbstractWidgetGroup;
class ControlTypePicker extends AbstractFieldHidden {
protected $hasTooltip = false;
protected $options = array();
protected $plugins = array();
protected $ajaxUrl = '';
/**
* @var ContainerSubform
*/
protected $containerSubform;
/** @var AbstractWidgetGroup */
private $widgetGroup;
/**
* SubFormIcon constructor.
*
* @param TraitFieldset $insertAt
* @param string $name
* @param ContainerInterface $container
* @param string $ajaxUrl
* @param AbstractWidgetGroup $widgetGroup
* @param string $default
* @param array $parameters
*/
public function __construct($insertAt, $name, $container, $ajaxUrl, $widgetGroup, $default = '', $parameters = array()) {
$this->name = $name;
$this->widgetGroup = $widgetGroup;
$this->ajaxUrl = $ajaxUrl;
parent::__construct($insertAt, $name, false, $default, $parameters);
$this->initOptions();
$this->containerSubform = new ContainerSubform($container, $name . '-subform');
$this->getCurrentPlugin($this->getValue())
->renderFields($this->containerSubform);
}
protected function fetchElement() {
$html = '<div class="n2_field_control_type_picker">';
foreach ($this->options as $key => $option) {
$html .= '<div class="n2_field_control_type_picker__item" data-controltype="' . $key . '">';
$html .= '<img alt="" src="' . Url::pathToUri($option['path']) . '">';
$html .= '<div class="n2_field_control_type_picker__selected_marker"><i class="ssi_16 ssi_16--check"></i></div>';
$html .= '</div>';
}
$html .= parent::fetchElement();
$html .= '</div>';
Js::addInline('new _N2.FormElementControlTypePicker( "' . $this->fieldID . '", ' . json_encode(array(
'ajaxUrl' => $this->ajaxUrl,
'target' => $this->containerSubform->getId(),
'originalValue' => $this->getValue()
)) . ');');
return $html;
}
protected function getCurrentPlugin($value) {
if (!isset($this->plugins[$value])) {
list($value) = array_keys($this->plugins);
}
return $this->plugins[$value];
}
private function initOptions() {
$this->plugins = $this->widgetGroup->getWidgets();
foreach ($this->plugins as $name => $type) {
$this->options[$name] = array(
'path' => $type->getSubFormImagePath()
);
}
if (count($this->options) == 1) {
$this->parent->hide();
}
}
} Element/DatePicker.php 0000644 00000011664 15235664445 0010707 0 ustar 00 <?php
namespace Nextend\SmartSlider3\Form\Element;
use Nextend\Framework\Asset\Js\Js;
use Nextend\Framework\Form\AbstractField;
use Nextend\Framework\Form\ContainerInterface;
use Nextend\Framework\Form\Element\AbstractFieldHidden;
use Nextend\Framework\Form\Element\Grouping;
use Nextend\Framework\Form\Element\OnOff;
use Nextend\Framework\Form\Element\Select;
use Nextend\Framework\Form\Element\Text\Number;
use Nextend\Framework\Form\Element\Text\NumberSlider;
use Nextend\Framework\Form\TraitFieldset;
class DatePicker extends AbstractFieldHidden implements ContainerInterface {
use TraitFieldset;
protected $rowClass = 'n2_field_mixed ';
protected $onOffLabel = '';
protected $hasOnOff = true;
private $dateTimeFields = array();
public function __construct($insertAt, $name = '', $label = false, $default = '', $parameters = array()) {
$this->onOffLabel = $label;
parent::__construct($insertAt, $name, false, $default, $parameters);
}
protected function fetchElement() {
$this->addDatePicker();
$subElements = array();
foreach ($this->dateTimeFields as $dateTimeField) {
$dateTimeField->setExposeName(false);
$subElements[] = $dateTimeField->getID();
}
$html = '';
$element = $this->first;
while ($element) {
$element->setExposeName(false);
$html .= $this->decorateElement($element);
$element = $element->getNext();
}
$html .= parent::fetchElement();
Js::addInline('new _N2.FormElementDatePicker("' . $this->fieldID . '", ' . json_encode($subElements) . ', ' . json_encode($this->hasOnOff) . ');');
return $html;
}
/**
* @param AbstractField $element
*
* @return string
*/
public function decorateElement($element) {
return $this->parent->decorateElement($element);
}
protected function addDatePicker() {
$defaultParts = explode(' ', $this->defaultValue);
$defaultDateParts = explode('-', $defaultParts[0]);
$defaultTimeParts = explode(':', $defaultParts[1]);
$defaultArray = array_merge($defaultDateParts, $defaultTimeParts);
$valueParts = explode(' ', $this->getValue());
$valueDateParts = explode('-', $valueParts[0]);
$valueTimeParts = explode(':', $valueParts[1]);
$valueArray = array_merge($valueDateParts, $valueTimeParts);
$valueArray = $valueArray + $defaultArray;
$dateGroup = new Grouping($this, $this->name . '-date');
$controlName = $this->getControlName();
if ($this->hasOnOff) {
$this->dateTimeFields[] = new OnOff($dateGroup, $this->name . '-enable', $this->onOffLabel, 0, array(
'relatedFieldsOn' => array(
$controlName . $this->name . '-year',
$controlName . $this->name . '-month',
$controlName . $this->name . '-day',
$controlName . $this->name . '-hour',
$controlName . $this->name . '-minute'
)
));
}
//YEAR
$this->dateTimeFields[] = new Number($dateGroup, $this->name . '-year', n2_('Year'), $valueArray[0], array(
'wide' => 4,
'min' => 1970,
'max' => 9999
));
//MONTH
$months = array();
for ($i = 1; $i <= 12; $i++) {
$formattedValue = sprintf("%02d", $i);
$months[$formattedValue] = $formattedValue;
}
$this->dateTimeFields[] = new Select($dateGroup, $this->name . '-month', n2_('Month'), $valueArray[1], array(
'options' => $months
));
//DAY
$days = array();
for ($i = 1; $i <= 31; $i++) {
$formattedValue = sprintf("%02d", $i);
$days[$formattedValue] = $formattedValue;
}
$this->dateTimeFields[] = new Select($dateGroup, $this->name . '-day', n2_('Day'), $valueArray[2], array(
'options' => $days
));
$timeGroup = new Grouping($this, $this->name . '-time');
//HOUR
$hours = array();
for ($i = 0; $i < 24; $i++) {
$formattedValue = sprintf("%02d", $i);
$hours[$formattedValue] = $formattedValue;
}
$this->dateTimeFields[] = new Select($timeGroup, $this->name . '-hour', n2_('Hour'), $valueArray[3], array(
'options' => $hours
));
//MINUTE
$this->dateTimeFields[] = new NumberSlider($timeGroup, $this->name . '-minute', n2_('Minute'), $valueArray[4], array(
'wide' => 2,
'min' => 0,
'max' => 59
));
}
protected function setOnOff($hasOnOff) {
$this->hasOnOff = $hasOnOff;
}
} Element/PublishSlider.php 0000644 00000001750 15235664445 0011440 0 ustar 00 <?php
namespace Nextend\SmartSlider3\Form\Element;
use Nextend\Framework\Form\Element\AbstractFieldHidden;
use Nextend\Framework\Request\Request;
use Nextend\SmartSlider3\Application\Admin\Layout\Block\Slider\SliderPublish\BlockPublishSlider;
class PublishSlider extends AbstractFieldHidden {
protected $hasTooltip = false;
protected function fetchElement() {
ob_start();
$blockPublishSlider = new BlockPublishSlider($this->getForm());
$blockPublishSlider->setSliderID(Request::$GET->getInt('sliderid'));
$sliderAliasOrID = Request::$GET->getVar('slideraliasorid');
if (!empty($sliderAliasOrID)) {
if (is_numeric($sliderAliasOrID)) {
$blockPublishSlider->setSliderID($sliderAliasOrID);
} else {
$blockPublishSlider->setSliderAlias($sliderAliasOrID);
}
}
$blockPublishSlider->display();
return ob_get_clean();
}
} Element/WidgetArea.php 0000644 00000002130 15235664445 0010674 0 ustar 00 <?php
namespace Nextend\SmartSlider3\Form\Element;
use Nextend\Framework\Asset\Js\Js;
use Nextend\Framework\Form\Element\AbstractFieldHidden;
use Nextend\Framework\View\Html;
class WidgetArea extends AbstractFieldHidden {
protected $hasTooltip = false;
protected function fetchElement() {
$areas = '';
for ($i = 1; $i <= 12; $i++) {
$areas .= Html::tag('div', array(
'class' => 'n2_field_widget_area__area' . $this->isSelected($i),
'data-area' => $i
));
}
$html = Html::tag('div', array(
'class' => 'n2_field_widget_area'
), Html::tag('div', array(
'class' => 'n2_field_widget_area__inner'
)) . $areas . parent::fetchElement());
Js::addInline('new _N2.FormElementSliderWidgetArea("' . $this->fieldID . '");');
return $html;
}
function isSelected($i) {
if ($i == $this->getValue()) {
return ' n2_field_widget_area__area--selected';
}
return '';
}
} Element/Select/ResponsiveSubFormIcon.php 0000644 00000001346 15235664445 0014353 0 ustar 00 <?php
namespace Nextend\SmartSlider3\Form\Element\Select;
use Nextend\Framework\Form\Element\Select\SubFormIcon;
use Nextend\SmartSlider3\Slider\ResponsiveType\AbstractResponsiveTypeAdmin;
use Nextend\SmartSlider3\Slider\ResponsiveType\ResponsiveTypeFactory;
class ResponsiveSubFormIcon extends SubFormIcon {
/** @var AbstractResponsiveTypeAdmin[] */
protected $plugins = array();
protected function loadOptions() {
$this->plugins = ResponsiveTypeFactory::getAdminTypes();
foreach ($this->plugins as $name => $type) {
$this->options[$name] = array(
'label' => $type->getLabel(),
'icon' => $type->getIcon()
);
}
}
} Element/Radio/FlexAlign.php 0000644 00000001011 15235664445 0011564 0 ustar 00 <?php
namespace Nextend\SmartSlider3\Form\Element\Radio;
use Nextend\Framework\Form\Element\Radio\AbstractRadioIcon;
class FlexAlign extends AbstractRadioIcon {
protected $options = array(
'flex-start' => 'ssi_16 ssi_16--verticaltop',
'center' => 'ssi_16 ssi_16--verticalcenter',
'flex-end' => 'ssi_16 ssi_16--verticalbottom',
'space-between' => 'ssi_16 ssi_16--verticalbetween',
'space-around' => 'ssi_16 ssi_16--verticalaround'
);
} Element/Radio/HorizontalAlign.php 0000644 00000001645 15235664445 0013034 0 ustar 00 <?php
namespace Nextend\SmartSlider3\Form\Element\Radio;
use Nextend\Framework\Form\Element\Radio\AbstractRadioIcon;
class HorizontalAlign extends AbstractRadioIcon {
protected $inherit = false;
protected $options = array(
'left' => 'ssi_16 ssi_16--horizontalleft',
'center' => 'ssi_16 ssi_16--horizontalcenter',
'right' => 'ssi_16 ssi_16--horizontalright'
);
public function __construct($insertAt, $name = '', $label = '', $default = '', array $parameters = array()) {
parent::__construct($insertAt, $name, $label, $default, $parameters);
if ($this->inherit) {
$this->options = array(
'inherit' => 'ssi_16 ssi_16--none'
) + $this->options;
}
}
/**
* @param bool $inherit
*/
public function setInherit($inherit) {
$this->inherit = $inherit;
}
} Element/Radio/InnerAlign.php 0000644 00000001440 15235664445 0011747 0 ustar 00 <?php
namespace Nextend\SmartSlider3\Form\Element\Radio;
use Nextend\Framework\Form\Element\Radio\AbstractRadioIcon;
class InnerAlign extends AbstractRadioIcon {
protected $hasInherit = true;
protected function renderOptions() {
if ($this->hasInherit) {
$this->options['inherit'] = 'ssi_16 ssi_16--none';
}
$this->options = array_merge($this->options, array(
'left' => 'ssi_16 ssi_16--textleft',
'center' => 'ssi_16 ssi_16--textcenter',
'right' => 'ssi_16 ssi_16--textright'
));
return parent::renderOptions();
}
/**
* @param bool $hasInherit
*/
public function setHasInherit($hasInherit) {
$this->hasInherit = $hasInherit;
}
} Element/Radio/VerticalAlign.php 0000644 00000000571 15235664445 0012451 0 ustar 00 <?php
namespace Nextend\SmartSlider3\Form\Element\Radio;
use Nextend\Framework\Form\Element\Radio\AbstractRadioIcon;
class VerticalAlign extends AbstractRadioIcon {
protected $options = array(
'top' => 'ssi_16 ssi_16--verticaltop',
'middle' => 'ssi_16 ssi_16--verticalcenter',
'bottom' => 'ssi_16 ssi_16--verticalbottom'
);
} Element/Group/WidgetPosition.php 0000644 00000007107 15235664445 0012735 0 ustar 00 <?php
namespace Nextend\SmartSlider3\Form\Element\Group;
use Nextend\Framework\Asset\Js\Js;
use Nextend\Framework\Form\Element\Grouping;
use Nextend\Framework\Form\Element\OnOff;
use Nextend\Framework\Form\Element\Select;
use Nextend\Framework\Form\Element\Text;
use Nextend\Framework\Form\Element\Text\Number;
use Nextend\Framework\Form\Element\Unit;
use Nextend\Framework\View\Html;
use Nextend\SmartSlider3\Form\Element\WidgetArea;
class WidgetPosition extends Grouping {
protected $rowClass = '';
protected function fetchElement() {
$mode = new OnOff($this, $this->name . '-mode', n2_('Advanced'), 'simple');
$mode->setCustomValues('simple', 'advanced');
$mode->setRelatedFieldsOff(array(
'slider' . $this->name . '-simple'
));
$mode->setRelatedFieldsOn(array(
'slider' . $this->name . '-advanced'
));
$this->addSimple();
$this->addAdvanced();
Js::addInline('new _N2.FormElementWidgetPosition("' . $this->fieldID . '");');
$html = '';
$element = $this->first;
while ($element) {
$html .= $this->decorateElement($element);
$element = $element->getNext();
}
return Html::tag('div', array(
'id' => $this->fieldID,
'class' => 'n2_field_widget_position'
), Html::tag('div', array(
'class' => 'n2_field_widget_position__label'
), '') . '<i class="n2_field_widget_position__arrow ssi_16 ssi_16--selectarrow"></i>' . Html::tag('div', array(
'class' => 'n2_field_widget_position__popover'
), $html));
}
protected function addSimple() {
$simple = new Grouping($this, $this->name . '-simple');
new WidgetArea($simple, $this->name . '-area', false);
new Select($simple, $this->name . '-stack', n2_('Stack'), 1, array(
'options' => array(
1 => 1,
2 => 2,
3 => 3,
4 => 4,
5 => 5
)
));
new Number($simple, $this->name . '-offset', n2_('Offset'), 0, array(
'wide' => 4,
'unit' => 'px'
));
}
protected function addAdvanced() {
$advanced = new Grouping($this, $this->name . '-advanced');
new Select($advanced, $this->name . '-horizontal', n2_('Horizontal'), 'left', array(
'options' => array(
'left' => n2_('Left'),
'right' => n2_('Right')
)
));
$horizontalPosition = new Text($advanced, $this->name . '-horizontal-position', n2_('Position'), 0, array(
'style' => 'width:100px;'
));
new Unit($horizontalPosition, $this->name . '-horizontal-unit', false, 'px', array(
'units' => array(
'px',
'%'
)
));
new Select($advanced, $this->name . '-vertical', n2_('Vertical'), 'top', array(
'options' => array(
'top' => n2_('Top'),
'bottom' => n2_('Bottom')
)
));
$verticalPosition = new Text($advanced, $this->name . '-vertical-position', n2_('Position'), 0, array(
'style' => 'width:100px;'
));
new Unit($verticalPosition, $this->name . '-vertical-unit', false, 'px', array(
'units' => array(
'px',
'%'
)
));
}
}