first commit

This commit is contained in:
alazhar
2020-01-02 22:20:31 +07:00
commit 10eb3340ad
5753 changed files with 631345 additions and 0 deletions

View File

@ -0,0 +1,610 @@
<?php
/**
* @package Joomla.Platform
* @subpackage Form
*
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
defined('JPATH_PLATFORM') or die;
/**
* Abstract Form Field class for the Joomla Platform.
*
* @package Joomla.Platform
* @subpackage Form
* @since 11.1
*/
abstract class JFormField
{
/**
* The description text for the form field. Usually used in tooltips.
*
* @var string
* @since 11.1
*/
protected $description;
/**
* The SimpleXMLElement object of the <field /> XML element that describes the form field.
*
* @var SimpleXMLElement
* @since 11.1
*/
protected $element;
/**
* The JForm object of the form attached to the form field.
*
* @var JForm
* @since 11.1
*/
protected $form;
/**
* The form control prefix for field names from the JForm object attached to the form field.
*
* @var string
* @since 11.1
*/
protected $formControl;
/**
* The hidden state for the form field.
*
* @var boolean
* @since 11.1
*/
protected $hidden = false;
/**
* True to translate the field label string.
*
* @var boolean
* @since 11.1
*/
protected $translateLabel = true;
/**
* True to translate the field description string.
*
* @var boolean
* @since 11.1
*/
protected $translateDescription = true;
/**
* The document id for the form field.
*
* @var string
* @since 11.1
*/
protected $id;
/**
* The input for the form field.
*
* @var string
* @since 11.1
*/
protected $input;
/**
* The label for the form field.
*
* @var string
* @since 11.1
*/
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 11.1
*/
protected $multiple = false;
/**
* The name of the form field.
*
* @var string
* @since 11.1
*/
protected $name;
/**
* The name of the field.
*
* @var string
* @since 11.1
*/
protected $fieldname;
/**
* The group of the field.
*
* @var string
* @since 11.1
*/
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 11.1
*/
protected $required = false;
/**
* The form field type.
*
* @var string
* @since 11.1
*/
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 11.1
*/
protected $validate;
/**
* The value of the form field.
*
* @var mixed
* @since 11.1
*/
protected $value;
/**
* The label's CSS class of the form field
*
* @var mixed
* @since 11.1
*/
protected $labelClass;
/**
* The count value for generated name field
*
* @var integer
* @since 11.1
*/
protected static $count = 0;
/**
* The string used for generated fields names
*
* @var string
* @since 11.1
*/
protected static $generated_fieldname = '__field';
/**
* Method to instantiate the form field object.
*
* @param JForm $form The form to attach to the form field object.
*
* @since 11.1
*/
public function __construct($form = null)
{
// If there is a form passed into the constructor set the form and form control properties.
if ($form instanceof JForm)
{
$this->form = $form;
$this->formControl = $form->getFormControl();
}
// Detect the field type if not set
if (!isset($this->type))
{
$parts = JStringNormalise::fromCamelCase(get_called_class(), true);
if ($parts[0] == 'J')
{
$this->type = JString::ucfirst($parts[count($parts) - 1], '_');
}
else
{
$this->type = JString::ucfirst($parts[0], '_') . JString::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 the the value.
*
* @return mixed The property value or null.
*
* @since 11.1
*/
public function __get($name)
{
switch ($name)
{
case 'description':
case 'formControl':
case 'hidden':
case 'id':
case 'multiple':
case 'name':
case 'required':
case 'type':
case 'validate':
case 'value':
case 'labelClass':
case 'fieldname':
case 'group':
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 null;
}
/**
* Method to attach a JForm object to the field.
*
* @param JForm $form The JForm object to attach to the form field.
*
* @return JFormField The form field object so that the method can be used in a chain.
*
* @since 11.1
*/
public function setForm(JForm $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 11.1
*/
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;
// Get some important attributes from the form field element.
$class = (string) $element['class'];
$id = (string) $element['id'];
$multiple = (string) $element['multiple'];
$name = (string) $element['name'];
$required = (string) $element['required'];
// Set the required and validation options.
$this->required = ($required == 'true' || $required == 'required' || $required == '1');
$this->validate = (string) $element['validate'];
// Add the required class if the field is required.
if ($this->required)
{
if ($class)
{
if (strpos($class, 'required') === false)
{
$this->element['class'] = $class . ' required';
}
}
else
{
$this->element['class'] = 'required';
}
}
// Set the multiple values option.
$this->multiple = ($multiple == 'true' || $multiple == 'multiple');
// Allow for field classes to force the multiple values option.
if (isset($this->forceMultiple))
{
$this->multiple = (bool) $this->forceMultiple;
}
// Set the field description text.
$this->description = (string) $element['description'];
// Set the visibility.
$this->hidden = ((string) $element['type'] == 'hidden' || (string) $element['hidden'] == 'true');
// Determine whether to translate the field label and/or description.
$this->translateLabel = !((string) $this->element['translate_label'] == 'false' || (string) $this->element['translate_label'] == '0');
$this->translateDescription = !((string) $this->element['translate_description'] == 'false'
|| (string) $this->element['translate_description'] == '0');
// Set the group of the field.
$this->group = $group;
// Set the field name and id.
$this->fieldname = $this->getFieldName($name);
$this->name = $this->getName($this->fieldname);
$this->id = $this->getId($id, $this->fieldname);
// Set the field default value.
$this->value = $value;
// Set the CSS class of field label
$this->labelClass = (string) $element['labelclass'];
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 11.1
*/
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);
return $id;
}
/**
* Method to get the field input markup.
*
* @return string The field input markup.
*
* @since 11.1
*/
abstract protected function getInput();
/**
* Method to get the field title.
*
* @return string The field title.
*
* @since 11.1
*/
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 11.1
*/
protected function getLabel()
{
$label = '';
if ($this->hidden)
{
return $label;
}
// Get the label text from the XML element, defaulting to the element name.
$text = $this->element['label'] ? (string) $this->element['label'] : (string) $this->element['name'];
$text = $this->translateLabel ? JText::_($text) : $text;
// Build the class for the label.
$class = !empty($this->description) ? 'hasTooltip' : '';
$class = $this->required == true ? $class . ' required' : $class;
$class = !empty($this->labelClass) ? $class . ' ' . $this->labelClass : $class;
// Add the opening label tag and main attributes attributes.
$label .= '<label id="' . $this->id . '-lbl" for="' . $this->id . '" class="' . $class . '"';
// If a description is specified, use it to build a tooltip.
if (!empty($this->description))
{
JHtml::_('bootstrap.tooltip');
$label .= ' title="' . JHtml::tooltipText(trim($text, ':'), JText::_($this->description), 0) . '"';
}
// Add the label text and closing tag.
if ($this->required)
{
$label .= '>' . $text . '<span class="star">&#160;*</span></label>';
}
else
{
$label .= '>' . $text . '</label>';
}
return $label;
}
/**
* 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 11.1
*/
protected function getName($fieldName)
{
$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 11.1
*/
protected function getFieldName($fieldName)
{
if ($fieldName)
{
return $fieldName;
}
else
{
self::$count = self::$count + 1;
return self::$generated_fieldname . self::$count;
}
}
}

View File

@ -0,0 +1,60 @@
<?php
/**
* @package Joomla.Platform
* @subpackage Form
*
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
defined('JPATH_PLATFORM') or die;
JFormHelper::loadFieldClass('list');
/**
* Form Field class for the Joomla Platform.
* Provides a list of access levels. Access levels control what users in specific
* groups can see.
*
* @package Joomla.Platform
* @subpackage Form
* @see JAccess
* @since 11.1
*/
class JFormFieldAccessLevel extends JFormFieldList
{
/**
* The form field type.
*
* @var string
* @since 11.1
*/
public $type = 'AccessLevel';
/**
* Method to get the field input markup.
*
* @return string The field input markup.
*
* @since 11.1
*/
protected function getInput()
{
$attr = '';
// Initialize some field attributes.
$attr .= $this->element['class'] ? ' class="' . (string) $this->element['class'] . '"' : '';
$attr .= ((string) $this->element['disabled'] == 'true') ? ' disabled="disabled"' : '';
$attr .= $this->element['size'] ? ' size="' . (int) $this->element['size'] . '"' : '';
$attr .= $this->multiple ? ' multiple="multiple"' : '';
$attr .= $this->required ? ' required="required" aria-required="true"' : '';
// Initialize JavaScript field attributes.
$attr .= $this->element['onchange'] ? ' onchange="' . (string) $this->element['onchange'] . '"' : '';
// Get the field options.
$options = $this->getOptions();
return JHtml::_('access.level', $this->name, $this->value, $attr, $options, $this->id);
}
}

View File

@ -0,0 +1,54 @@
<?php
/**
* @package Joomla.Platform
* @subpackage Form
*
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
defined('JPATH_PLATFORM') or die;
JFormHelper::loadFieldClass('list');
/**
* Form Field class for the Joomla Platform.
* Provides a list of available cache handlers
*
* @package Joomla.Platform
* @subpackage Form
* @see JCache
* @since 11.1
*/
class JFormFieldCacheHandler extends JFormFieldList
{
/**
* The form field type.
*
* @var string
* @since 11.1
*/
public $type = 'CacheHandler';
/**
* Method to get the field options.
*
* @return array The field option objects.
*
* @since 11.1
*/
protected function getOptions()
{
$options = array();
// Convert to name => name array.
foreach (JCache::getStores() as $store)
{
$options[] = JHtml::_('select.option', $store, JText::_('JLIB_FORM_VALUE_CACHE_' . $store), 'value', 'text');
}
$options = array_merge(parent::getOptions(), $options);
return $options;
}
}

View File

@ -0,0 +1,119 @@
<?php
/**
* @package Joomla.Platform
* @subpackage Form
*
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
defined('JPATH_PLATFORM') or die;
/**
* Form Field class for the Joomla Platform.
*
* Provides a pop up date picker linked to a button.
* Optionally may be filtered to use user's or server's time zone.
*
* @package Joomla.Platform
* @subpackage Form
* @since 11.1
*/
class JFormFieldCalendar extends JFormField
{
/**
* The form field type.
*
* @var string
* @since 11.1
*/
public $type = 'Calendar';
/**
* Method to get the field input markup.
*
* @return string The field input markup.
*
* @since 11.1
*/
protected function getInput()
{
// Initialize some field attributes.
$format = $this->element['format'] ? (string) $this->element['format'] : '%Y-%m-%d';
// Build the attributes array.
$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['class'])
{
$attributes['class'] = (string) $this->element['class'];
}
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'];
}
if ($this->required)
{
$attributes['required'] = 'required';
$attributes['aria-required'] = 'true';
}
// Handle the special case for "now".
if (strtoupper($this->value) == 'NOW')
{
$this->value = strftime($format);
}
// Get some system objects.
$config = JFactory::getConfig();
$user = JFactory::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 = JFactory::getDate($this->value, 'UTC');
$date->setTimezone(new DateTimeZone($config->get('offset')));
// Transform the date string.
$this->value = $date->format('Y-m-d H:i:s', true, false);
}
break;
case 'USER_UTC':
// Convert a date to UTC based on the user timezone.
if ((int) $this->value)
{
// Get a date object based on the correct timezone.
$date = JFactory::getDate($this->value, 'UTC');
$date->setTimezone(new DateTimeZone($user->getParam('timezone', $config->get('offset'))));
// Transform the date string.
$this->value = $date->format('Y-m-d H:i:s', true, false);
}
break;
}
return JHtml::_('calendar', $this->value, $this->name, $this->id, $format, $attributes);
}
}

View File

@ -0,0 +1,64 @@
<?php
/**
* @package Joomla.Platform
* @subpackage Form
*
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
defined('JPATH_PLATFORM') or die;
/**
* Form Field class for the Joomla Platform.
* Single check box field.
* This is a boolean field with null for false and the specified option for true
*
* @package Joomla.Platform
* @subpackage Form
* @link http://www.w3.org/TR/html-markup/input.checkbox.html#input.checkbox
* @see JFormFieldCheckboxes
* @since 11.1
*/
class JFormFieldCheckbox extends JFormField
{
/**
* The form field type.
*
* @var string
* @since 11.1
*/
public $type = 'Checkbox';
/**
* Method to get the field input markup.
* The checked element sets the field to selected.
*
* @return string The field input markup.
*
* @since 11.1
*/
protected function getInput()
{
// Initialize some field attributes.
$class = $this->element['class'] ? ' class="' . (string) $this->element['class'] . '"' : '';
$disabled = ((string) $this->element['disabled'] == 'true') ? ' disabled="disabled"' : '';
$value = $this->element['value'] ? (string) $this->element['value'] : '1';
$required = $this->required ? ' required="required" aria-required="true"' : '';
if (empty($this->value))
{
$checked = (isset($this->element['checked'] )) ? ' checked="checked"' : '';
}
else
{
$checked = ' checked="checked"';
}
// Initialize JavaScript field attributes.
$onclick = $this->element['onclick'] ? ' onclick="' . (string) $this->element['onclick'] . '"' : '';
return '<input type="checkbox" name="' . $this->name . '" id="' . $this->id . '" value="'
. htmlspecialchars($value, ENT_COMPAT, 'UTF-8') . '"' . $class . $checked . $disabled . $onclick . $required . ' />';
}
}

View File

@ -0,0 +1,137 @@
<?php
/**
* @package Joomla.Platform
* @subpackage Form
*
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
defined('JPATH_PLATFORM') or die;
/**
* Form Field class for the Joomla Platform.
* Displays options as a list of check boxes.
* Multiselect may be forced to be true.
*
* @package Joomla.Platform
* @subpackage Form
* @see JFormFieldCheckbox
* @since 11.1
*/
class JFormFieldCheckboxes extends JFormField
{
/**
* The form field type.
*
* @var string
* @since 11.1
*/
protected $type = 'Checkboxes';
/**
* Flag to tell the field to always be in multiple values mode.
*
* @var boolean
* @since 11.1
*/
protected $forceMultiple = true;
/**
* Method to get the field input markup for check boxes.
*
* @return string The field input markup.
*
* @since 11.1
*/
protected function getInput()
{
$html = array();
// Initialize some field attributes.
$class = $this->element['class'] ? ' class="checkboxes ' . (string) $this->element['class'] . '"' : ' class="checkboxes"';
$checkedOptions = explode(',', (string) $this->element['checked']);
// Start the checkbox field output.
$html[] = '<fieldset id="' . $this->id . '"' . $class . '>';
// Get the field options.
$options = $this->getOptions();
// Build the checkbox field output.
$html[] = '<ul>';
foreach ($options as $i => $option)
{
// Initialize some option attributes.
if (!isset($this->value) || empty($this->value))
{
$checked = (in_array((string) $option->value, (array) $checkedOptions) ? ' checked="checked"' : '');
}
else
{
$value = !is_array($this->value) ? explode(',', $this->value) : $this->value;
$checked = (in_array((string) $option->value, $value) ? ' checked="checked"' : '');
}
$class = !empty($option->class) ? ' class="' . $option->class . '"' : '';
$required = !empty($option->required) ? ' required="required" aria-required="true"' : '';
$disabled = !empty($option->disable) ? ' disabled="disabled"' : '';
// Initialize some JavaScript option attributes.
$onclick = !empty($option->onclick) ? ' onclick="' . $option->onclick . '"' : '';
$html[] = '<li>';
$html[] = '<input type="checkbox" id="' . $this->id . $i . '" name="' . $this->name . '" value="'
. htmlspecialchars($option->value, ENT_COMPAT, 'UTF-8') . '"' . $checked . $class . $onclick . $disabled . $required . '/>';
$html[] = '<label for="' . $this->id . $i . '"' . $class . '>' . JText::_($option->text) . '</label>';
$html[] = '</li>';
}
$html[] = '</ul>';
// End the checkbox field output.
$html[] = '</fieldset>';
return implode($html);
}
/**
* Method to get the field options.
*
* @return array The field option objects.
*
* @since 11.1
*/
protected function getOptions()
{
$options = array();
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.
$tmp = JHtml::_(
'select.option', (string) $option['value'], trim((string) $option), '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;
}
reset($options);
return $options;
}
}

View File

@ -0,0 +1,140 @@
<?php
/**
* @package Joomla.Platform
* @subpackage Form
*
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
defined('JPATH_PLATFORM') or die;
/**
* Color Form Field class for the Joomla Platform.
* This implementation is designed to be compatible with HTML5's <input type="color">
*
* @package Joomla.Platform
* @subpackage Form
* @link http://www.w3.org/TR/html-markup/input.color.html
* @since 11.3
*/
class JFormFieldColor extends JFormField
{
/**
* The form field type.
*
* @var string
* @since 11.3
*/
protected $type = 'Color';
/**
* Method to get the field input markup.
*
* @return string The field input markup.
*
* @since 11.3
*/
protected function getInput()
{
// Control value can be: hue (default), saturation, brightness, wheel or simpel
$control = (string) $this->element['control'];
// Position of the panel can be: right (default), left, top or bottom
$position = $this->element['position'] ? (string) $this->element['position'] : 'right';
$position = ' data-position="' . $position . '"';
$onchange = $this->element['onchange'] ? ' onchange="' . (string) $this->element['onchange'] . '"' : '';
$class = (string) $this->element['class'];
$color = strtolower($this->value);
if (!$color || in_array($color, array('none', 'transparent')))
{
$color = 'none';
}
elseif ($color['0'] != '#')
{
$color = '#' . $color;
}
if ($control == 'simple')
{
$class = ' class="' . trim('simplecolors chzn-done ' . $class) . '"';
JHtml::_('behavior.simplecolorpicker');
$colors = strtolower((string) $this->element['colors']);
if (empty($colors))
{
$colors = array(
'none',
'#049cdb',
'#46a546',
'#9d261d',
'#ffc40d',
'#f89406',
'#c3325f',
'#7a43b6',
'#ffffff',
'#999999',
'#555555',
'#000000'
);
}
else
{
$colors = explode(',', $colors);
}
$split = (int) $this->element['split'];
if (!$split)
{
$count = count($colors);
if ($count % 5 == 0)
{
$split = 5;
}
else
{
if ($count % 4 == 0)
{
$split = 4;
}
}
}
$split = $split ? $split : 3;
$html = array();
$html[] = '<select name="' . $this->name . '" id="' . $this->id . '"'
. $class . $position . $onchange . ' style="visibility:hidden;width:22px;height:1px">';
foreach ($colors as $i => $c)
{
$html[] = '<option' . ($c == $color ? ' selected="selected"' : '') . '>' . $c . '</option>';
if (($i + 1) % $split == 0)
{
$html[] = '<option>-</option>';
}
}
$html[] = '</select>';
return implode('', $html);
}
else
{
$class = ' class="' . trim('minicolors ' . $class) . '"';
$control = $control ? ' data-control="' . $control . '"' : '';
$disabled = ((string) $this->element['disabled'] == 'true') ? ' disabled="disabled"' : '';
JHtml::_('behavior.colorpicker');
return '<input type="text" name="' . $this->name . '" id="' . $this->id . '"' . ' value="'
. htmlspecialchars($color, ENT_COMPAT, 'UTF-8') . '"' . $class . $position . $control . $disabled . $onchange . '/>';
}
}
}

View File

@ -0,0 +1,74 @@
<?php
/**
* @package Joomla.Platform
* @subpackage Form
*
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
defined('JPATH_PLATFORM') or die;
JFormHelper::loadFieldClass('list');
/**
* Form Field class for the Joomla Platform.
* Implements a combo box field.
*
* @package Joomla.Platform
* @subpackage Form
* @since 11.1
*/
class JFormFieldCombo extends JFormFieldList
{
/**
* The form field type.
*
* @var string
* @since 11.1
*/
public $type = 'Combo';
/**
* Method to get the field input markup for a combo box field.
*
* @return string The field input markup.
*
* @since 11.1
*/
protected function getInput()
{
$html = array();
$attr = '';
// Initialize some field attributes.
$attr .= $this->element['class'] ? ' class="combobox ' . (string) $this->element['class'] . '"' : ' class="combobox"';
$attr .= ((string) $this->element['readonly'] == 'true') ? ' readonly="readonly"' : '';
$attr .= ((string) $this->element['disabled'] == 'true') ? ' disabled="disabled"' : '';
$attr .= $this->element['size'] ? ' size="' . (int) $this->element['size'] . '"' : '';
$attr .= $this->required ? ' required="required" aria-required="true"' : '';
// Initialize JavaScript field attributes.
$attr .= $this->element['onchange'] ? ' onchange="' . (string) $this->element['onchange'] . '"' : '';
// Get the field options.
$options = $this->getOptions();
// Load the combobox behavior.
JHtml::_('behavior.combobox');
// Build the input for the combo box.
$html[] = '<input type="text" name="' . $this->name . '" id="' . $this->id . '" value="'
. htmlspecialchars($this->value, ENT_COMPAT, 'UTF-8') . '"' . $attr . '/>';
// Build the list for the combo box.
$html[] = '<ul id="combobox-' . $this->id . '" style="display:none;">';
foreach ($options as $option)
{
$html[] = '<li>' . $option->text . '</li>';
}
$html[] = '</ul>';
return implode($html);
}
}

View File

@ -0,0 +1,84 @@
<?php
/**
* @package Joomla.Platform
* @subpackage Form
*
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
defined('JPATH_PLATFORM') or die;
JFormHelper::loadFieldClass('list');
/**
* Form Field class for the Joomla Platform.
* Provides a list of available database connections, optionally limiting to
* a given list.
*
* @package Joomla.Platform
* @subpackage Form
* @see JDatabaseDriver
* @since 11.3
*/
class JFormFieldDatabaseConnection extends JFormFieldList
{
/**
* The form field type.
*
* @var string
* @since 11.3
*/
public $type = 'DatabaseConnection';
/**
* Method to get the list of database options.
*
* This method produces a drop down list of available databases supported
* by JDatabaseDriver classes that are also supported by the application.
*
* @return array The field option objects.
*
* @since 11.3
* @see JDatabaseDriver
*/
protected function getOptions()
{
// This gets the connectors available in the platform and supported by the server.
$available = JDatabaseDriver::getConnectors();
/**
* This gets the list of database types supported by the application.
* This should be entered in the form definition as a comma separated list.
* If no supported databases are listed, it is assumed all available databases
* are supported.
*/
$supported = $this->element['supported'];
if (!empty($supported))
{
$supported = explode(',', $supported);
foreach ($supported as $support)
{
if (in_array($support, $available))
{
$options[$support] = JText::_(ucfirst($support));
}
}
}
else
{
foreach ($available as $support)
{
$options[$support] = JText::_(ucfirst($support));
}
}
// This will come into play if an application is installed that requires
// a database that is not available on the server.
if (empty($options))
{
$options[''] = JText::_('JNONE');
}
return $options;
}
}

View File

@ -0,0 +1,55 @@
<?php
/**
* @package Joomla.Platform
* @subpackage Form
*
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
defined('JPATH_PLATFORM') or die;
/**
* Form Field class for the Joomla Platform.
* Provides and input field for e-mail addresses
*
* @package Joomla.Platform
* @subpackage Form
* @link http://www.w3.org/TR/html-markup/input.email.html#input.email
* @see JFormRuleEmail
* @since 11.1
*/
class JFormFieldEMail extends JFormField
{
/**
* The form field type.
*
* @var string
* @since 11.1
*/
protected $type = 'Email';
/**
* Method to get the field input markup for e-mail addresses.
*
* @return string The field input markup.
*
* @since 11.1
*/
protected function getInput()
{
// Initialize some field attributes.
$size = $this->element['size'] ? ' size="' . (int) $this->element['size'] . '"' : '';
$maxLength = $this->element['maxlength'] ? ' maxlength="' . (int) $this->element['maxlength'] . '"' : '';
$class = $this->element['class'] ? ' ' . (string) $this->element['class'] : '';
$readonly = ((string) $this->element['readonly'] == 'true') ? ' readonly="readonly"' : '';
$disabled = ((string) $this->element['disabled'] == 'true') ? ' disabled="disabled"' : '';
$required = $this->required ? ' required="required" aria-required="true"' : '';
// Initialize JavaScript field attributes.
$onchange = $this->element['onchange'] ? ' onchange="' . (string) $this->element['onchange'] . '"' : '';
return '<input type="text" name="' . $this->name . '" class="' . $class . '" id="' . $this->id . '" value="'
. JStringPunycode::emailToUTF8($this->value, ENT_COMPAT, 'UTF-8') . '"' . $size . $disabled . $readonly . $onchange . $maxLength . $required . '/>';
}
}

View File

@ -0,0 +1,58 @@
<?php
/**
* @package Joomla.Platform
* @subpackage Form
*
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
defined('JPATH_PLATFORM') or die;
/**
* Form Field class for the Joomla Platform.
* Provides an input field for files
*
* @package Joomla.Platform
* @subpackage Form
* @link http://www.w3.org/TR/html-markup/input.file.html#input.file
* @since 11.1
*/
class JFormFieldFile extends JFormField
{
/**
* The form field type.
*
* @var string
* @since 11.1
*/
public $type = 'File';
/**
* Method to get the field input markup for the file field.
* Field attributes allow specification of a maximum file size and a string
* of accepted file extensions.
*
* @return string The field input markup.
*
* @since 11.1
*
* @note The field does not include an upload mechanism.
* @see JFormFieldMedia
*/
protected function getInput()
{
// Initialize some field attributes.
$accept = $this->element['accept'] ? ' accept="' . (string) $this->element['accept'] . '"' : '';
$size = $this->element['size'] ? ' size="' . (int) $this->element['size'] . '"' : '';
$class = $this->element['class'] ? ' class="' . (string) $this->element['class'] . '"' : '';
$disabled = ((string) $this->element['disabled'] == 'true') ? ' disabled="disabled"' : '';
$required = $this->required ? ' required="required" aria-required="true"' : '';
// Initialize JavaScript field attributes.
$onchange = $this->element['onchange'] ? ' onchange="' . (string) $this->element['onchange'] . '"' : '';
return '<input type="file" name="' . $this->name . '" id="' . $this->id . '" value=""' . $accept . $disabled . $class . $size
. $onchange . $required . ' />';
}
}

View File

@ -0,0 +1,105 @@
<?php
/**
* @package Joomla.Platform
* @subpackage Form
*
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
defined('JPATH_PLATFORM') or die;
jimport('joomla.filesystem.folder');
jimport('joomla.filesystem.file');
JFormHelper::loadFieldClass('list');
/**
* Supports an HTML select list of files
*
* @package Joomla.Platform
* @subpackage Form
* @since 11.1
*/
class JFormFieldFileList extends JFormFieldList
{
/**
* The form field type.
*
* @var string
* @since 11.1
*/
public $type = 'FileList';
/**
* Method to get the list of files for the field options.
* Specify the target directory with a directory attribute
* Attributes allow an exclude mask and stripping of extensions from file name.
* Default attribute may optionally be set to null (no file) or -1 (use a default).
*
* @return array The field option objects.
*
* @since 11.1
*/
protected function getOptions()
{
$options = array();
// Initialize some field attributes.
$filter = (string) $this->element['filter'];
$exclude = (string) $this->element['exclude'];
$stripExt = (string) $this->element['stripext'];
$hideNone = (string) $this->element['hide_none'];
$hideDefault = (string) $this->element['hide_default'];
// Get the path in which to search for file options.
$path = (string) $this->element['directory'];
if (!is_dir($path))
{
$path = JPATH_ROOT . '/' . $path;
}
// Prepend some default options based on field attributes.
if (!$hideNone)
{
$options[] = JHtml::_('select.option', '-1', JText::alt('JOPTION_DO_NOT_USE', preg_replace('/[^a-zA-Z0-9_\-]/', '_', $this->fieldname)));
}
if (!$hideDefault)
{
$options[] = JHtml::_('select.option', '', JText::alt('JOPTION_USE_DEFAULT', preg_replace('/[^a-zA-Z0-9_\-]/', '_', $this->fieldname)));
}
// Get a list of files in the search path with the given filter.
$files = JFolder::files($path, $filter);
// Build the options list from the list of files.
if (is_array($files))
{
foreach ($files as $file)
{
// Check to see if the file is in the exclude mask.
if ($exclude)
{
if (preg_match(chr(1) . $exclude . chr(1), $file))
{
continue;
}
}
// If the extension is to be stripped, do it.
if ($stripExt)
{
$file = JFile::stripExt($file);
}
$options[] = JHtml::_('select.option', $file, $file);
}
}
// Merge any additional options in the XML definition.
$options = array_merge(parent::getOptions(), $options);
return $options;
}
}

View File

@ -0,0 +1,94 @@
<?php
/**
* @package Joomla.Platform
* @subpackage Form
*
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
defined('JPATH_PLATFORM') or die;
jimport('joomla.filesystem.folder');
JFormHelper::loadFieldClass('list');
/**
* Supports an HTML select list of folder
*
* @package Joomla.Platform
* @subpackage Form
* @since 11.1
*/
class JFormFieldFolderList extends JFormFieldList
{
/**
* The form field type.
*
* @var string
* @since 11.1
*/
public $type = 'FolderList';
/**
* Method to get the field options.
*
* @return array The field option objects.
*
* @since 11.1
*/
protected function getOptions()
{
$options = array();
// Initialize some field attributes.
$filter = (string) $this->element['filter'];
$exclude = (string) $this->element['exclude'];
$hideNone = (string) $this->element['hide_none'];
$hideDefault = (string) $this->element['hide_default'];
// Get the path in which to search for file options.
$path = (string) $this->element['directory'];
if (!is_dir($path))
{
$path = JPATH_ROOT . '/' . $path;
}
// Prepend some default options based on field attributes.
if (!$hideNone)
{
$options[] = JHtml::_('select.option', '-1', JText::alt('JOPTION_DO_NOT_USE', preg_replace('/[^a-zA-Z0-9_\-]/', '_', $this->fieldname)));
}
if (!$hideDefault)
{
$options[] = JHtml::_('select.option', '', JText::alt('JOPTION_USE_DEFAULT', preg_replace('/[^a-zA-Z0-9_\-]/', '_', $this->fieldname)));
}
// Get a list of folders in the search path with the given filter.
$folders = JFolder::folders($path, $filter);
// Build the options list from the list of folders.
if (is_array($folders))
{
foreach ($folders as $folder)
{
// Check to see if the file is in the exclude mask.
if ($exclude)
{
if (preg_match(chr(1) . $exclude . chr(1), $folder))
{
continue;
}
}
$options[] = JHtml::_('select.option', $folder, $folder);
}
}
// Merge any additional options in the XML definition.
$options = array_merge(parent::getOptions(), $options);
return $options;
}
}

View File

@ -0,0 +1,180 @@
<?php
/**
* @package Joomla.Platform
* @subpackage Form
*
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
defined('JPATH_PLATFORM') or die;
/**
* Form Field class for the Joomla Platform.
* Provides a grouped list select field.
*
* @package Joomla.Platform
* @subpackage Form
* @since 11.1
*/
class JFormFieldGroupedList extends JFormField
{
/**
* The form field type.
*
* @var string
* @since 11.1
*/
protected $type = 'GroupedList';
/**
* Method to get the field option groups.
*
* @return array The field option objects as a nested array in groups.
*
* @since 11.1
* @throws UnexpectedValueException
*/
protected function getGroups()
{
$groups = array();
$label = 0;
foreach ($this->element->children() as $element)
{
switch ($element->getName())
{
// The element is an <option />
case 'option':
// Initialize the group if necessary.
if (!isset($groups[$label]))
{
$groups[$label] = array();
}
// Create a new option object based on the <option /> element.
$tmp = JHtml::_(
'select.option', ($element['value']) ? (string) $element['value'] : trim((string) $element),
JText::alt(trim((string) $element), preg_replace('/[^a-zA-Z0-9_\-]/', '_', $this->fieldname)), 'value', 'text',
((string) $element['disabled'] == 'true')
);
// Set some option attributes.
$tmp->class = (string) $element['class'];
// Set some JavaScript option attributes.
$tmp->onclick = (string) $element['onclick'];
// Add the option.
$groups[$label][] = $tmp;
break;
// The element is a <group />
case 'group':
// Get the group label.
if ($groupLabel = (string) $element['label'])
{
$label = JText::_($groupLabel);
}
// Initialize the group if necessary.
if (!isset($groups[$label]))
{
$groups[$label] = array();
}
// Iterate through the children and build an array of options.
foreach ($element->children() as $option)
{
// Only add <option /> elements.
if ($option->getName() != 'option')
{
continue;
}
// Create a new option object based on the <option /> element.
$tmp = JHtml::_(
'select.option', ($option['value']) ? (string) $option['value'] : JText::_(trim((string) $option)),
JText::_(trim((string) $option)), '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.
$groups[$label][] = $tmp;
}
if ($groupLabel)
{
$label = count($groups);
}
break;
// Unknown element type.
default:
throw new UnexpectedValueException(sprintf('Unsupported element %s in JFormFieldGroupedList', $element->getName()), 500);
}
}
reset($groups);
return $groups;
}
/**
* Method to get the field input markup fora grouped list.
* Multiselect is enabled by using the multiple attribute.
*
* @return string The field input markup.
*
* @since 11.1
*/
protected function getInput()
{
$html = array();
$attr = '';
// Initialize some field attributes.
$attr .= $this->element['class'] ? ' class="' . (string) $this->element['class'] . '"' : '';
$attr .= ((string) $this->element['disabled'] == 'true') ? ' disabled="disabled"' : '';
$attr .= $this->element['size'] ? ' size="' . (int) $this->element['size'] . '"' : '';
$attr .= $this->multiple ? ' multiple="multiple"' : '';
$attr .= $this->required ? ' required="required" aria-required="true"' : '';
// Initialize JavaScript field attributes.
$attr .= $this->element['onchange'] ? ' onchange="' . (string) $this->element['onchange'] . '"' : '';
// Get the field groups.
$groups = (array) $this->getGroups();
// Create a read-only list (no name) with a hidden input to store the value.
if ((string) $this->element['readonly'] == 'true')
{
$html[] = JHtml::_(
'select.groupedlist', $groups, null,
array(
'list.attr' => $attr, 'id' => $this->id, 'list.select' => $this->value, 'group.items' => null, 'option.key.toHtml' => false,
'option.text.toHtml' => false
)
);
$html[] = '<input type="hidden" name="' . $this->name . '" value="' . $this->value . '"/>';
}
// Create a regular list.
else
{
$html[] = JHtml::_(
'select.groupedlist', $groups, $this->name,
array(
'list.attr' => $attr, 'id' => $this->id, 'list.select' => $this->value, 'group.items' => null, 'option.key.toHtml' => false,
'option.text.toHtml' => false
)
);
}
return implode($html);
}
}

View File

@ -0,0 +1,50 @@
<?php
/**
* @package Joomla.Platform
* @subpackage Form
*
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
defined('JPATH_PLATFORM') or die;
/**
* Form Field class for the Joomla Platform.
* Provides a hidden field
*
* @package Joomla.Platform
* @subpackage Form
* @link http://www.w3.org/TR/html-markup/input.hidden.html#input.hidden
* @since 11.1
*/
class JFormFieldHidden extends JFormField
{
/**
* The form field type.
*
* @var string
* @since 11.1
*/
protected $type = 'Hidden';
/**
* Method to get the field input markup.
*
* @return string The field input markup.
*
* @since 11.1
*/
protected function getInput()
{
// Initialize some field attributes.
$class = $this->element['class'] ? ' class="' . (string) $this->element['class'] . '"' : '';
$disabled = ((string) $this->element['disabled'] == 'true') ? ' disabled="disabled"' : '';
// Initialize JavaScript field attributes.
$onchange = $this->element['onchange'] ? ' onchange="' . (string) $this->element['onchange'] . '"' : '';
return '<input type="hidden" name="' . $this->name . '" id="' . $this->id . '" value="'
. htmlspecialchars($this->value, ENT_COMPAT, 'UTF-8') . '"' . $class . $disabled . $onchange . ' />';
}
}

View File

@ -0,0 +1,51 @@
<?php
/**
* @package Joomla.Platform
* @subpackage Form
*
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
defined('JPATH_PLATFORM') or die;
JFormHelper::loadFieldClass('filelist');
/**
* Supports an HTML select list of image
*
* @package Joomla.Platform
* @subpackage Form
* @since 11.1
*/
class JFormFieldImageList extends JFormFieldFileList
{
/**
* The form field type.
*
* @var string
* @since 11.1
*/
public $type = 'ImageList';
/**
* Method to get the list of images field options.
* Use the filter attribute to specify allowable file extensions.
*
* @return array The field option objects.
*
* @since 11.1
*/
protected function getOptions()
{
// Define the image file type filter.
$filter = '\.png$|\.gif$|\.jpg$|\.bmp$|\.ico$|\.jpeg$|\.psd$|\.eps$';
// Set the form field element attribute for file type filter.
$this->element->addAttribute('filter', $filter);
// Get the field options.
return parent::getOptions();
}
}

View File

@ -0,0 +1 @@
<!DOCTYPE html><title></title>

View File

@ -0,0 +1,87 @@
<?php
/**
* @package Joomla.Platform
* @subpackage Form
*
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
defined('JPATH_PLATFORM') or die;
JFormHelper::loadFieldClass('list');
/**
* Form Field class for the Joomla Platform.
* Provides a select list of integers with specified first, last and step values.
*
* @package Joomla.Platform
* @subpackage Form
* @since 11.1
*/
class JFormFieldInteger extends JFormFieldList
{
/**
* The form field type.
*
* @var string
* @since 11.1
*/
protected $type = 'Integer';
/**
* Method to get the field options.
*
* @return array The field option objects.
*
* @since 11.1
*/
protected function getOptions()
{
$options = array();
// Initialize some field attributes.
$first = (int) $this->element['first'];
$last = (int) $this->element['last'];
$step = (int) $this->element['step'];
// Sanity checks.
if ($step == 0)
{
// Step of 0 will create an endless loop.
return $options;
}
elseif ($first < $last && $step < 0)
{
// A negative step will never reach the last number.
return $options;
}
elseif ($first > $last && $step > 0)
{
// A position step will never reach the last number.
return $options;
}
elseif ($step < 0)
{
// Build the options array backwards.
for ($i = $first; $i >= $last; $i += $step)
{
$options[] = JHtml::_('select.option', $i);
}
}
else
{
// Build the options array.
for ($i = $first; $i <= $last; $i += $step)
{
$options[] = JHtml::_('select.option', $i);
}
}
// Merge any additional options in the XML definition.
$options = array_merge(parent::getOptions(), $options);
return $options;
}
}

View File

@ -0,0 +1,57 @@
<?php
/**
* @package Joomla.Platform
* @subpackage Form
*
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
defined('JPATH_PLATFORM') or die;
JFormHelper::loadFieldClass('list');
/**
* Form Field class for the Joomla Platform.
* Supports a list of installed application languages
*
* @package Joomla.Platform
* @subpackage Form
* @see JFormFieldContentLanguage for a select list of content languages.
* @since 11.1
*/
class JFormFieldLanguage extends JFormFieldList
{
/**
* The form field type.
*
* @var string
* @since 11.1
*/
protected $type = 'Language';
/**
* Method to get the field options.
*
* @return array The field option objects.
*
* @since 11.1
*/
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;
}
}

View File

@ -0,0 +1,118 @@
<?php
/**
* @package Joomla.Platform
* @subpackage Form
*
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
defined('JPATH_PLATFORM') or die;
/**
* Form Field class for the Joomla Platform.
* Supports a generic list of options.
*
* @package Joomla.Platform
* @subpackage Form
* @since 11.1
*/
class JFormFieldList extends JFormField
{
/**
* The form field type.
*
* @var string
* @since 11.1
*/
protected $type = 'List';
/**
* Method to get the field input markup for a generic list.
* Use the multiple attribute to enable multiselect.
*
* @return string The field input markup.
*
* @since 11.1
*/
protected function getInput()
{
$html = array();
$attr = '';
// Initialize some field attributes.
$attr .= $this->element['class'] ? ' class="' . (string) $this->element['class'] . '"' : '';
// To avoid user's confusion, readonly="true" should imply disabled="true".
if ((string) $this->element['readonly'] == 'true' || (string) $this->element['disabled'] == 'true')
{
$attr .= ' disabled="disabled"';
}
$attr .= $this->element['size'] ? ' size="' . (int) $this->element['size'] . '"' : '';
$attr .= $this->multiple ? ' multiple="multiple"' : '';
$attr .= $this->required ? ' required="required" aria-required="true"' : '';
// Initialize JavaScript field attributes.
$attr .= $this->element['onchange'] ? ' onchange="' . (string) $this->element['onchange'] . '"' : '';
// Get the field options.
$options = (array) $this->getOptions();
// Create a read-only list (no name) with a hidden input to store the value.
if ((string) $this->element['readonly'] == 'true')
{
$html[] = JHtml::_('select.genericlist', $options, '', trim($attr), 'value', 'text', $this->value, $this->id);
$html[] = '<input type="hidden" name="' . $this->name . '" value="' . $this->value . '"/>';
}
// Create a regular list.
else
{
$html[] = JHtml::_('select.genericlist', $options, $this->name, trim($attr), 'value', 'text', $this->value, $this->id);
}
return implode($html);
}
/**
* Method to get the field options.
*
* @return array The field option objects.
*
* @since 11.1
*/
protected function getOptions()
{
$options = array();
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.
$tmp = 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')
);
// 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;
}
reset($options);
return $options;
}
}

View File

@ -0,0 +1,75 @@
<?php
/**
* @package Joomla.Platform
* @subpackage Form
*
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
defined('JPATH_PLATFORM') or die;
/**
* Form Field class for the Joomla Platform.
* Supports a one line text field.
*
* @package Joomla.Platform
* @subpackage Form
* @link http://www.w3.org/TR/html-markup/input.text.html#input.text
* @since 11.1
*/
class JFormFieldNote extends JFormField
{
/**
* The form field type.
*
* @var string
*
* @since 11.1
*/
protected $type = 'Note';
/**
* Method to get the field label markup.
*
* @return string The field label markup.
*
* @since 11.1
*/
protected function getLabel()
{
if (empty($this->element['label']) && empty($this->element['description']))
{
return '';
}
$title = $this->element['label'] ? (string) $this->element['label'] : ($this->element['title'] ? (string) $this->element['title'] : '');
$heading = $this->element['heading'] ? (string) $this->element['heading'] : 'h4';
$description = (string) $this->element['description'];
$class = $this->element['class'] ? ' class="' . trim((string) $this->element['class']) . '"' : '';
$close = (string) $this->element['close'];
$html = array();
if ($close)
{
$close = $close == 'true' ? 'alert' : $close;
$html[] = '<button type="button" class="close" data-dismiss="' . $close . '">&times;</button>';
}
$html[] = !empty($title) ? '<' . $heading . '>' . JText::_($title) . '</' . $heading . '>' : '';
$html[] = !empty($description) ? JText::_($description) : '';
return '</div><div ' . $class . '>' . implode('', $html);
}
/**
* Method to get the field input markup.
*
* @return string The field input markup.
*
* @since 11.1
*/
protected function getInput()
{
return '';
}
}

View File

@ -0,0 +1,101 @@
<?php
/**
* @package Joomla.Platform
* @subpackage Form
*
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
defined('JPATH_PLATFORM') or die;
/**
* Form Field class for the Joomla Platform.
* Text field for passwords
*
* @package Joomla.Platform
* @subpackage Form
* @link http://www.w3.org/TR/html-markup/input.password.html#input.password
* @note Two password fields may be validated as matching using JFormRuleEquals
* @since 11.1
*/
class JFormFieldPassword extends JFormField
{
/**
* The form field type.
*
* @var string
* @since 11.1
*/
protected $type = 'Password';
/**
* Method to get the field input markup for password.
*
* @return string The field input markup.
*
* @since 11.1
*/
protected function getInput()
{
// Initialize some field attributes.
$size = $this->element['size'] ? ' size="' . (int) $this->element['size'] . '"' : '';
$maxLength = $this->element['maxlength'] ? ' maxlength="' . (int) $this->element['maxlength'] . '"' : '99';
$class = $this->element['class'] ? ' class="' . (string) $this->element['class'] . '"' : '';
$auto = ((string) $this->element['autocomplete'] == 'off') ? ' autocomplete="off"' : '';
$readonly = ((string) $this->element['readonly'] == 'true') ? ' readonly="readonly"' : '';
$disabled = ((string) $this->element['disabled'] == 'true') ? ' disabled="disabled"' : '';
$meter = ((string) $this->element['strengthmeter'] == 'true' ? ' $meter= 1' : ' $meter = 0');
$required = $this->required ? ' required="required" aria-required="true"' : '';
$threshold = $this->element['threshold'] ? (int) $this->element['threshold'] : 66;
$minimumLength = $this->element['minimum_length'] ? (int) $this->element['minimum_length'] : 4;
$minimumIntegers = $this->element['minimum_integers'] ? (int) $this->element['minimum_integers'] : 0;
$minimumSymbols = $this->element['minimum_symbols'] ? (int) $this->element['minimum_symbols'] : 0;
$minimumUppercase = $this->element['minimum_uppercase'] ? (int) $this->element['minimum_uppercase'] : 0;
// If we have parameters from com_users, use those instead.
// Some of these may be empty for legacy reasons.
$app = JFactory::getApplication();
if ($app->getClientId() != 2)
{
$params = JComponentHelper::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');
if (!empty($minimumLengthp))
{
$minimumLength = (int) $minimumLengthp;
}
empty($minimumIntegersp) ? : $minimumIntegers = (int) $minimumIntegersp;
empty($minimumSymbolsp) ? : $minimumSymbols = (int) $minimumSymbolsp;
empty($minimumUppercasep) ? : $minimumUppercase = (int) $minimumUppercasep;
}
}
$script = '';
if ($meter == 1)
{
JHtml::_('script', 'system/passwordstrength.js', true, true);
$script = '<script type="text/javascript">new Form.PasswordStrength("' . $this->id . '",
{
threshold: ' . $threshold . ',
onUpdate: function(element, strength, threshold) {
element.set("data-passwordstrength", strength);
}
}
);</script>';
}
return '<input type="password" name="' . $this->name . '" id="' . $this->id . '"' .
' value="' . htmlspecialchars($this->value, ENT_COMPAT, 'UTF-8') . '"' .
$auto . $class . $readonly . $disabled . $size . $maxLength . $required . '/>' . $script;
}
}

View File

@ -0,0 +1,78 @@
<?php
/**
* @package Joomla.Platform
* @subpackage Form
*
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
defined('JPATH_PLATFORM') or die;
JFormHelper::loadFieldClass('list');
/**
* Form Field class for the Joomla Framework.
*
* @package Joomla.Platform
* @subpackage Form
* @since 11.4
*/
class JFormFieldPlugins extends JFormFieldList
{
/**
* The field type.
*
* @var string
* @since 11.4
*/
protected $type = 'Plugins';
/**
* Method to get a list of options for a list input.
*
* @return array An array of JHtml options.
*
* @since 11.4
*/
protected function getOptions()
{
$folder = $this->element['folder'];
if (!empty($folder))
{
// Get list of plugins
$db = JFactory::getDbo();
$query = $db->getQuery(true)
->select('element AS value, name AS text')
->from('#__extensions')
->where('folder = ' . $db->quote($folder))
->where('enabled = 1')
->order('ordering, name');
$db->setQuery($query);
$options = $db->loadObjectList();
$lang = JFactory::getLanguage();
foreach ($options as $i => $item)
{
$source = JPATH_PLUGINS . '/' . $folder . '/' . $item->value;
$extension = 'plg_' . $folder . '_' . $item->value;
$lang->load($extension . '.sys', JPATH_ADMINISTRATOR, null, false, false)
|| $lang->load($extension . '.sys', $source, null, false, false)
|| $lang->load($extension . '.sys', JPATH_ADMINISTRATOR, $lang->getDefault(), false, false)
|| $lang->load($extension . '.sys', $source, $lang->getDefault(), false, false);
$options[$i]->text = JText::_($item->text);
}
}
else
{
JLog::add(JText::_('JFRAMEWORK_FORM_FIELDS_PLUGINS_ERROR_FOLDER_EMPTY'), JLog::WARNING, 'jerror');
}
// Merge any additional options in the XML definition.
$options = array_merge(parent::getOptions(), $options);
return $options;
}
}

View File

@ -0,0 +1,117 @@
<?php
/**
* @package Joomla.Platform
* @subpackage Form
*
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
defined('JPATH_PLATFORM') or die;
/**
* Form Field class for the Joomla Platform.
* Provides radio button inputs
*
* @package Joomla.Platform
* @subpackage Form
* @link http://www.w3.org/TR/html-markup/command.radio.html#command.radio
* @since 11.1
*/
class JFormFieldRadio extends JFormField
{
/**
* The form field type.
*
* @var string
* @since 11.1
*/
protected $type = 'Radio';
/**
* Method to get the radio button field input markup.
*
* @return string The field input markup.
*
* @since 11.1
*/
protected function getInput()
{
$html = array();
// Initialize some field attributes.
$class = $this->element['class'] ? ' class="radio ' . (string) $this->element['class'] . '"' : ' class="radio"';
// Start the radio field output.
$html[] = '<fieldset id="' . $this->id . '"' . $class . '>';
// Get the field options.
$options = $this->getOptions();
// Build the radio field output.
foreach ($options as $i => $option)
{
// Initialize some option attributes.
$checked = ((string) $option->value == (string) $this->value) ? ' checked="checked"' : '';
$class = !empty($option->class) ? ' class="' . $option->class . '"' : '';
$disabled = !empty($option->disable) ? ' disabled="disabled"' : '';
$required = !empty($option->required) ? ' required="required" aria-required="true"' : '';
// Initialize some JavaScript option attributes.
$onclick = !empty($option->onclick) ? ' onclick="' . $option->onclick . '"' : '';
$html[] = '<input type="radio" id="' . $this->id . $i . '" name="' . $this->name . '" value="'
. htmlspecialchars($option->value, ENT_COMPAT, 'UTF-8') . '"' . $checked . $class . $onclick . $disabled . $required . '/>';
$html[] = '<label for="' . $this->id . $i . '"' . $class . '>'
. JText::alt($option->text, preg_replace('/[^a-zA-Z0-9_\-]/', '_', $this->fieldname)) . '</label>';
}
// End the radio field output.
$html[] = '</fieldset>';
return implode($html);
}
/**
* Method to get the field options for radio buttons.
*
* @return array The field option objects.
*
* @since 11.1
*/
protected function getOptions()
{
$options = array();
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.
$tmp = JHtml::_(
'select.option', (string) $option['value'], trim((string) $option), '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;
}
reset($options);
return $options;
}
}

View File

@ -0,0 +1,311 @@
<?php
/**
* @package Joomla.Platform
* @subpackage Form
*
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
defined('JPATH_PLATFORM') or die;
/**
* Form Field class for the Joomla Platform.
* Field for assigning permissions to groups for a given asset
*
* @package Joomla.Platform
* @subpackage Form
* @see JAccess
* @since 11.1
*/
class JFormFieldRules extends JFormField
{
/**
* The form field type.
*
* @var string
* @since 11.1
*/
public $type = 'Rules';
/**
* Method to get the field input markup for Access Control Lists.
* Optionally can be associated with a specific component and section.
*
* TODO: Add access check.
*
* @return string The field input markup.
*
* @since 11.1
*/
protected function getInput()
{
JHtml::_('bootstrap.tooltip');
// Initialise some field attributes.
$section = $this->element['section'] ? (string) $this->element['section'] : '';
$component = $this->element['component'] ? (string) $this->element['component'] : '';
$assetField = $this->element['asset_field'] ? (string) $this->element['asset_field'] : 'asset_id';
// Get the actions for the asset.
$actions = JAccess::getActions($component, $section);
// Iterate over the children and add to the actions.
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 = JFactory::getDbo();
$query = $db->getQuery(true)
->select($db->quoteName('id'))
->from($db->quoteName('#__assets'))
->where($db->quoteName('name') . ' = ' . $db->quote($component));
$db->setQuery($query);
$assetId = (int) $db->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);
}
// Use the compact form for the content rules (deprecated).
/* @todo remove code:
if (!empty($component) && $section != 'component') {
return JHtml::_('rules.assetFormWidget', $actions, $assetId, $assetId ? null : $component, $this->name, $this->id);
}
*/
// Full width format.
// Get the rules for just this asset (non-recursive).
$assetRules = JAccess::getAssetRules($assetId);
// Get the available user groups.
$groups = $this->getUserGroups();
// Prepare output
$html = array();
// Description
$html[] = '<p class="rule-desc">' . JText::_('JLIB_RULES_SETTINGS_DESC') . '</p>';
// Begin tabs
$html[] = '<div id="permissions-sliders" class="tabbable tabs-left">';
// Building tab nav
$html[] = '<ul class="nav nav-tabs">';
foreach ($groups as $group)
{
// Initial Active Tab
$active = "";
if ($group->value == 1)
{
$active = "active";
}
$html[] = '<li class="' . $active . '">';
$html[] = '<a href="#permission-' . $group->value . '" data-toggle="tab">';
$html[] = str_repeat('<span class="level">&ndash;</span> ', $curLevel = $group->level) . $group->text;
$html[] = '</a>';
$html[] = '</li>';
}
$html[] = '</ul>';
$html[] = '<div class="tab-content">';
// Start a row for each user group.
foreach ($groups as $group)
{
// Initial Active Pane
$active = "";
if ($group->value == 1)
{
$active = " active";
}
$html[] = '<div class="tab-pane' . $active . '" id="permission-' . $group->value . '">';
$html[] = '<table class="table table-striped">';
$html[] = '<thead>';
$html[] = '<tr>';
$html[] = '<th class="actions" id="actions-th' . $group->value . '">';
$html[] = '<span class="acl-action">' . JText::_('JLIB_RULES_ACTION') . '</span>';
$html[] = '</th>';
$html[] = '<th class="settings" id="settings-th' . $group->value . '">';
$html[] = '<span class="acl-action">' . JText::_('JLIB_RULES_SELECT_SETTING') . '</span>';
$html[] = '</th>';
// The calculated setting is not shown for the root group of global configuration.
$canCalculateSettings = ($group->parent_id || !empty($component));
if ($canCalculateSettings)
{
$html[] = '<th id="aclactionth' . $group->value . '">';
$html[] = '<span class="acl-action">' . JText::_('JLIB_RULES_CALCULATED_SETTING') . '</span>';
$html[] = '</th>';
}
$html[] = '</tr>';
$html[] = '</thead>';
$html[] = '<tbody>';
foreach ($actions as $action)
{
$html[] = '<tr>';
$html[] = '<td headers="actions-th' . $group->value . '">';
$html[] = '<label for="' . $this->id . '_' . $action->name . '_' . $group->value . '" class="hasTooltip" title="'
. htmlspecialchars(JText::_($action->title) . ' ' . JText::_($action->description), ENT_COMPAT, 'UTF-8') . '">';
$html[] = JText::_($action->title);
$html[] = '</label>';
$html[] = '</td>';
$html[] = '<td headers="settings-th' . $group->value . '">';
$html[] = '<select class="input-small" name="' . $this->name . '[' . $action->name . '][' . $group->value . ']" id="' . $this->id . '_' . $action->name
. '_' . $group->value . '" title="'
. JText::sprintf('JLIB_RULES_SELECT_ALLOW_DENY_GROUP', JText::_($action->title), trim($group->text)) . '">';
$inheritedRule = JAccess::checkGroup($group->value, $action->name, $assetId);
// Get the actual setting for the action for this group.
$assetRule = $assetRules->allow($action->name, $group->value);
// Build the dropdowns for the permissions sliders
// The parent group has "Not Set", all children can rightly "Inherit" from that.
$html[] = '<option value=""' . ($assetRule === null ? ' selected="selected"' : '') . '>'
. JText::_(empty($group->parent_id) && empty($component) ? 'JLIB_RULES_NOT_SET' : 'JLIB_RULES_INHERITED') . '</option>';
$html[] = '<option value="1"' . ($assetRule === true ? ' selected="selected"' : '') . '>' . JText::_('JLIB_RULES_ALLOWED')
. '</option>';
$html[] = '<option value="0"' . ($assetRule === false ? ' selected="selected"' : '') . '>' . JText::_('JLIB_RULES_DENIED')
. '</option>';
$html[] = '</select>&#160; ';
// If this asset's rule is allowed, but the inherited rule is deny, we have a conflict.
if (($assetRule === true) && ($inheritedRule === false))
{
$html[] = JText::_('JLIB_RULES_CONFLICT');
}
$html[] = '</td>';
// Build the Calculated Settings column.
// The inherited settings column is not displayed for the root group in global configuration.
if ($canCalculateSettings)
{
$html[] = '<td headers="aclactionth' . $group->value . '">';
// This is where we show the current effective settings considering currrent group, path and cascade.
// Check whether this is a component or global. Change the text slightly.
if (JAccess::checkGroup($group->value, 'core.admin', $assetId) !== true)
{
if ($inheritedRule === null)
{
$html[] = '<span class="label label-important">' . JText::_('JLIB_RULES_NOT_ALLOWED') . '</span>';
}
elseif ($inheritedRule === true)
{
$html[] = '<span class="label label-success">' . JText::_('JLIB_RULES_ALLOWED') . '</span>';
}
elseif ($inheritedRule === false)
{
if ($assetRule === false)
{
$html[] = '<span class="label label-important">' . JText::_('JLIB_RULES_NOT_ALLOWED') . '</span>';
}
else
{
$html[] = '<span class="label"><i class="icon-lock icon-white"></i> ' . JText::_('JLIB_RULES_NOT_ALLOWED_LOCKED')
. '</span>';
}
}
}
elseif (!empty($component))
{
$html[] = '<span class="label label-success"><i class="icon-lock icon-white"></i> ' . JText::_('JLIB_RULES_ALLOWED_ADMIN')
. '</span>';
}
else
{
// Special handling for groups that have global admin because they can't be denied.
// The admin rights can be changed.
if ($action->name === 'core.admin')
{
$html[] = '<span class="label label-success">' . JText::_('JLIB_RULES_ALLOWED') . '</span>';
}
elseif ($inheritedRule === false)
{
// Other actions cannot be changed.
$html[] = '<span class="label label-important"><i class="icon-lock icon-white"></i> '
. JText::_('JLIB_RULES_NOT_ALLOWED_ADMIN_CONFLICT') . '</span>';
}
else
{
$html[] = '<span class="label label-success"><i class="icon-lock icon-white"></i> ' . JText::_('JLIB_RULES_ALLOWED_ADMIN')
. '</span>';
}
}
$html[] = '</td>';
}
$html[] = '</tr>';
}
$html[] = '</tbody>';
$html[] = '</table></div>';
}
$html[] = '</div></div>';
$html[] = '<div class="alert">';
if ($section == 'component' || $section == null)
{
$html[] = JText::_('JLIB_RULES_SETTING_NOTES');
}
else
{
$html[] = JText::_('JLIB_RULES_SETTING_NOTES_ITEM');
}
$html[] = '</div>';
return implode("\n", $html);
}
/**
* Get a list of the user groups.
*
* @return array
*
* @since 11.1
*/
protected function getUserGroups()
{
$db = JFactory::getDbo();
$query = $db->getQuery(true)
->select('a.id AS value, a.title AS text, COUNT(DISTINCT b.id) AS level, a.parent_id')
->from('#__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, a.parent_id')
->order('a.lft ASC');
$db->setQuery($query);
$options = $db->loadObjectList();
return $options;
}
}

View File

@ -0,0 +1,55 @@
<?php
/**
* @package Joomla.Platform
* @subpackage Form
*
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
defined('JPATH_PLATFORM') or die;
JFormHelper::loadFieldClass('list');
/**
* Form Field class for the Joomla Platform.
* Provides a select list of session handler options.
*
* @package Joomla.Platform
* @subpackage Form
* @since 11.1
*/
class JFormFieldSessionHandler extends JFormFieldList
{
/**
* The form field type.
*
* @var string
* @since 11.1
*/
protected $type = 'SessionHandler';
/**
* Method to get the session handler field options.
*
* @return array The field option objects.
*
* @since 11.1
*/
protected function getOptions()
{
$options = array();
// Get the options from JSession.
foreach (JSession::getStores() as $store)
{
$options[] = JHtml::_('select.option', $store, JText::_('JLIB_FORM_VALUE_SESSION_' . $store), 'value', 'text');
}
// Merge any additional options in the XML definition.
$options = array_merge(parent::getOptions(), $options);
return $options;
}
}

View File

@ -0,0 +1,108 @@
<?php
/**
* @package Joomla.Platform
* @subpackage Form
*
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
defined('JPATH_PLATFORM') or die;
/**
* Form Field class for the Joomla Platform.
* Provides spacer markup to be used in form layouts.
*
* @package Joomla.Platform
* @subpackage Form
* @since 11.1
*/
class JFormFieldSpacer extends JFormField
{
/**
* The form field type.
*
* @var string
* @since 11.1
*/
protected $type = 'Spacer';
/**
* Method to get the field input markup for a spacer.
* The spacer does not have accept input.
*
* @return string The field input markup.
*
* @since 11.1
*/
protected function getInput()
{
return ' ';
}
/**
* Method to get the field label markup for a spacer.
* Use the label text or name from the XML element as the spacer or
* Use a hr="true" to automatically generate plain hr markup
*
* @return string The field label markup.
*
* @since 11.1
*/
protected function getLabel()
{
$html = array();
$class = $this->element['class'] ? (string) $this->element['class'] : '';
$html[] = '<span class="spacer">';
$html[] = '<span class="before"></span>';
$html[] = '<span class="' . $class . '">';
if ((string) $this->element['hr'] == 'true')
{
$html[] = '<hr class="' . $class . '" />';
}
else
{
$label = '';
// Get the label text from the XML element, defaulting to the element name.
$text = $this->element['label'] ? (string) $this->element['label'] : (string) $this->element['name'];
$text = $this->translateLabel ? JText::_($text) : $text;
// Build the class for the label.
$class = !empty($this->description) ? 'hasTooltip' : '';
$class = $this->required == true ? $class . ' required' : $class;
// Add the opening label tag and main attributes attributes.
$label .= '<label id="' . $this->id . '-lbl" class="' . $class . '"';
// If a description is specified, use it to build a tooltip.
if (!empty($this->description))
{
JHtml::_('bootstrap.tooltip');
$label .= ' title="' . JHtml::tooltipText(trim($text, ':'), JText::_($this->description), 0) . '"';
}
// Add the label text and closing tag.
$label .= '>' . $text . '</label>';
$html[] = $label;
}
$html[] = '</span>';
$html[] = '<span class="after"></span>';
$html[] = '</span>';
return implode('', $html);
}
/**
* Method to get the field title.
*
* @return string The field title.
*
* @since 11.1
*/
protected function getTitle()
{
return $this->getLabel();
}
}

View File

@ -0,0 +1,77 @@
<?php
/**
* @package Joomla.Platform
* @subpackage Form
*
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
defined('JPATH_PLATFORM') or die;
JFormHelper::loadFieldClass('list');
/**
* Supports an custom SQL select list
*
* @package Joomla.Platform
* @subpackage Form
* @since 11.1
*/
class JFormFieldSQL extends JFormFieldList
{
/**
* The form field type.
*
* @var string
* @since 11.1
*/
public $type = 'SQL';
/**
* Method to get the custom field options.
* Use the query attribute to supply a query to generate the list.
*
* @return array The field option objects.
*
* @since 11.1
*/
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 = JFactory::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;
}
}

View File

@ -0,0 +1,34 @@
<?php
/**
* @package Joomla.Platform
* @subpackage Form
*
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
defined('JPATH_PLATFORM') or die;
JFormHelper::loadFieldClass('text');
/**
* Form Field class for the Joomla Platform.
* Supports a text field telephone numbers.
*
* @package Joomla.Platform
* @subpackage Form
* @link http://www.w3.org/TR/html-markup/input.tel.html
* @see JFormRuleTel for telephone number validation
* @see JHtmlTel for rendering of telephone numbers
* @since 11.1
*/
class JFormFieldTel extends JFormFieldText
{
/**
* The form field type.
*
* @var string
* @since 11.1
*/
protected $type = 'Tel';
}

View File

@ -0,0 +1,55 @@
<?php
/**
* @package Joomla.Platform
* @subpackage Form
*
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
defined('JPATH_PLATFORM') or die;
/**
* Form Field class for the Joomla Platform.
* Supports a one line text field.
*
* @package Joomla.Platform
* @subpackage Form
* @link http://www.w3.org/TR/html-markup/input.text.html#input.text
* @since 11.1
*/
class JFormFieldText extends JFormField
{
/**
* The form field type.
*
* @var string
*
* @since 11.1
*/
protected $type = 'Text';
/**
* Method to get the field input markup.
*
* @return string The field input markup.
*
* @since 11.1
*/
protected function getInput()
{
// Initialize some field attributes.
$size = $this->element['size'] ? ' size="' . (int) $this->element['size'] . '"' : '';
$maxLength = $this->element['maxlength'] ? ' maxlength="' . (int) $this->element['maxlength'] . '"' : '';
$class = $this->element['class'] ? ' class="' . (string) $this->element['class'] . '"' : '';
$readonly = ((string) $this->element['readonly'] == 'true') ? ' readonly="readonly"' : '';
$disabled = ((string) $this->element['disabled'] == 'true') ? ' disabled="disabled"' : '';
$required = $this->required ? ' required="required" aria-required="true"' : '';
// Initialize JavaScript field attributes.
$onchange = $this->element['onchange'] ? ' onchange="' . (string) $this->element['onchange'] . '"' : '';
return '<input type="text" name="' . $this->name . '" id="' . $this->id . '" value="'
. htmlspecialchars($this->value, ENT_COMPAT, 'UTF-8') . '"' . $class . $size . $disabled . $readonly . $onchange . $maxLength . $required . '/>';
}
}

View File

@ -0,0 +1,54 @@
<?php
/**
* @package Joomla.Platform
* @subpackage Form
*
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
defined('JPATH_PLATFORM') or die;
/**
* Form Field class for the Joomla Platform.
* Supports a multi line area for entry of plain text
*
* @package Joomla.Platform
* @subpackage Form
* @link http://www.w3.org/TR/html-markup/textarea.html#textarea
* @since 11.1
*/
class JFormFieldTextarea extends JFormField
{
/**
* The form field type.
*
* @var string
* @since 11.1
*/
protected $type = 'Textarea';
/**
* Method to get the textarea field input markup.
* Use the rows and columns attributes to specify the dimensions of the area.
*
* @return string The field input markup.
*
* @since 11.1
*/
protected function getInput()
{
// Initialize some field attributes.
$class = $this->element['class'] ? ' class="' . (string) $this->element['class'] . '"' : '';
$disabled = ((string) $this->element['disabled'] == 'true') ? ' disabled="disabled"' : '';
$columns = $this->element['cols'] ? ' cols="' . (int) $this->element['cols'] . '"' : '';
$rows = $this->element['rows'] ? ' rows="' . (int) $this->element['rows'] . '"' : '';
$required = $this->required ? ' required="required" aria-required="true"' : '';
// Initialize JavaScript field attributes.
$onchange = $this->element['onchange'] ? ' onchange="' . (string) $this->element['onchange'] . '"' : '';
return '<textarea name="' . $this->name . '" id="' . $this->id . '"' . $columns . $rows . $class . $disabled . $onchange . $required . '>'
. htmlspecialchars($this->value, ENT_COMPAT, 'UTF-8') . '</textarea>';
}
}

View File

@ -0,0 +1,107 @@
<?php
/**
* @package Joomla.Platform
* @subpackage Form
*
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
defined('JPATH_PLATFORM') or die;
JFormHelper::loadFieldClass('groupedlist');
/**
* Form Field class for the Joomla Platform.
*
* @package Joomla.Platform
* @subpackage Form
* @since 11.1
*/
class JFormFieldTimezone extends JFormFieldGroupedList
{
/**
* The form field type.
*
* @var string
* @since 11.1
*/
protected $type = 'Timezone';
/**
* The list of available timezone groups to use.
*
* @var array
*
* @since 11.1
*/
protected static $zones = array('Africa', 'America', 'Antarctica', 'Arctic', 'Asia', 'Atlantic', 'Australia', 'Europe', 'Indian', 'Pacific');
/**
* Method to get the time zone field option groups.
*
* @return array The field option objects as a nested array in groups.
*
* @since 11.1
*/
protected function getGroups()
{
$groups = array();
$keyField = $this->element['key_field'] ? (string) $this->element['key_field'] : 'id';
$keyValue = $this->form->getValue($keyField);
// If the timezone is not set use the server setting.
if (strlen($this->value) == 0 && empty($keyValue))
{
$this->value = JFactory::getConfig()->get('offset');
}
// Get the list of time zones from the server.
$zones = DateTimeZone::listIdentifiers();
// Build the group lists.
foreach ($zones as $zone)
{
// Time zones not in a group we will ignore.
if (strpos($zone, '/') === false)
{
continue;
}
// Get the group/locale from the timezone.
list ($group, $locale) = explode('/', $zone, 2);
// Only use known groups.
if (in_array($group, self::$zones))
{
// Initialize the group if necessary.
if (!isset($groups[$group]))
{
$groups[$group] = array();
}
// Only add options where a locale exists.
if (!empty($locale))
{
$groups[$group][$zone] = JHtml::_('select.option', $zone, str_replace('_', ' ', $locale), 'value', 'text', false);
}
}
}
// Sort the group lists.
ksort($groups);
foreach ($groups as &$location)
{
sort($location);
}
// Merge any additional groups in the XML definition.
$groups = array_merge(parent::getGroups(), $groups);
return $groups;
}
}

View File

@ -0,0 +1,57 @@
<?php
/**
* @package Joomla.Platform
* @subpackage Form
*
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
defined('JPATH_PLATFORM') or die;
JFormHelper::loadFieldClass('text');
/**
* Form Field class for the Joomla Platform.
* Supports a URL text field
*
* @package Joomla.Platform
* @subpackage Form
* @link http://www.w3.org/TR/html-markup/input.url.html#input.url
* @see JFormRuleUrl for validation of full urls
* @since 11.1
*/
class JFormFieldUrl extends JFormFieldText
{
/**
* The form field type.
*
* @var string
* @since 11.1
*/
protected $type = 'Url';
/**
* Method to get the field input markup.
*
* @return string The field input markup.
*
* @since 3.1.2 (CMS)
*/
protected function getInput()
{
// Initialize some field attributes.
$size = $this->element['size'] ? ' size="' . (int) $this->element['size'] . '"' : '';
$maxLength = $this->element['maxlength'] ? ' maxlength="' . (int) $this->element['maxlength'] . '"' : '';
$class = $this->element['class'] ? ' class="' . (string) $this->element['class'] . '" ' : '" ';
$readonly = ((string) $this->element['readonly'] == 'true') ? ' readonly="readonly"' : '';
$disabled = ((string) $this->element['disabled'] == 'true') ? ' disabled="disabled"' : '';
$required = $this->required ? ' required="required" aria-required="true"' : '';
// Initialize JavaScript field attributes.
$onchange = $this->element['onchange'] ? ' onchange="' . (string) $this->element['onchange'] . '"' : '';
return '<input type="url" name="' . $this->name . '"' . $class . ' id="' . $this->id . '" value="'
. JStringPunycode::urlToUTF8($this->value, ENT_COMPAT, 'UTF-8') . '"' . $size . $disabled . $readonly . $onchange . $maxLength . $required . '/>';
}
}

View File

@ -0,0 +1,81 @@
<?php
/**
* @package Joomla.Platform
* @subpackage Form
*
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
defined('JPATH_PLATFORM') or die;
/**
* Form Field class for the Joomla Platform.
* Supports a nested check box field listing user groups.
* Multiselect is available by default.
*
* @package Joomla.Platform
* @subpackage Form
* @since 11.1
*/
class JFormFieldUsergroup extends JFormField
{
/**
* The form field type.
*
* @var string
* @since 11.1
*/
protected $type = 'Usergroup';
/**
* Method to get the user group field input markup.
*
* @return string The field input markup.
*
* @since 11.1
*/
protected function getInput()
{
$options = array();
$attr = '';
// Initialize some field attributes.
$attr .= $this->element['class'] ? ' class="' . (string) $this->element['class'] . '"' : '';
$attr .= ((string) $this->element['disabled'] == 'true') ? ' disabled="disabled"' : '';
$attr .= $this->element['size'] ? ' size="' . (int) $this->element['size'] . '"' : '';
$attr .= $this->multiple ? ' multiple="multiple"' : '';
$attr .= $this->required ? ' required="required" aria-required="true"' : '';
// Initialize JavaScript field attributes.
$attr .= $this->element['onchange'] ? ' onchange="' . (string) $this->element['onchange'] . '"' : '';
// Iterate through the children and build an array of options.
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.
$tmp = JHtml::_(
'select.option', (string) $option['value'], trim((string) $option), '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;
}
return JHtml::_('access.usergroup', $this->name, $this->value, $attr, $options, $this->id);
}
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,315 @@
<?php
/**
* @package Joomla.Platform
* @subpackage Form
*
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
defined('JPATH_PLATFORM') or die;
jimport('joomla.filesystem.path');
/**
* JForm's helper class.
* Provides a storage for filesystem's paths where JForm's entities reside and methods for creating those entities.
* Also stores objects with entities' prototypes for further reusing.
*
* @package Joomla.Platform
* @subpackage Form
* @since 11.1
*/
class JFormHelper
{
/**
* Array with paths where entities(field, rule, form) can be found.
*
* Array's structure:
* <code>
* paths:
* {ENTITY_NAME}:
* - /path/1
* - /path/2
* </code>
*
* @var array
* @since 11.1
*
*/
protected static $paths;
/**
* Static array of JForm's 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
* @since 11.1
*/
protected static $entities = 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 mixed JFormField object on success, false otherwise.
*
* @since 11.1
*/
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 mixed JFormRule object on success, false otherwise.
*
* @since 11.1
*/
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 11.1
*/
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)
{
// Instantiate a new type object.
$types[$key] = new $class;
return $types[$key];
}
else
{
return false;
}
}
/**
* 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 mixed Class name on success or false otherwise.
*
* @since 11.1
*/
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 mixed Class name on success or false otherwise.
*
* @since 11.1
*/
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 mixed Class name on success or false otherwise.
*
* @since 11.1
*/
protected static function loadClass($entity, $type)
{
if (strpos($type, '.'))
{
list($prefix, $type) = explode('.', $type);
}
else
{
$prefix = 'J';
}
$class = JString::ucfirst($prefix, '_') . 'Form' . JString::ucfirst($entity, '_') . JString::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)
{
if ($file = JPath::find($path, $type))
{
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 11.1
*/
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 11.1
*/
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 11.1
*/
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 11.1
*/
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)
{
if (!in_array($path, $paths))
{
array_unshift($paths, trim($path));
}
}
return $paths;
}
}

View File

@ -0,0 +1 @@
<!DOCTYPE html><title></title>

View File

@ -0,0 +1,81 @@
<?php
/**
* @package Joomla.Platform
* @subpackage Form
*
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
defined('JPATH_PLATFORM') or die;
// Detect if we have full UTF-8 and unicode PCRE support.
if (!defined('JCOMPAT_UNICODE_PROPERTIES'))
{
define('JCOMPAT_UNICODE_PROPERTIES', (bool) @preg_match('/\pL/u', 'a'));
}
/**
* Form Rule class for the Joomla Platform.
*
* @package Joomla.Platform
* @subpackage Form
* @since 11.1
*/
class JFormRule
{
/**
* The regular expression to use in testing a form field value.
*
* @var string
* @since 11.1
*/
protected $regex;
/**
* The regular expression modifiers to use when testing a form field value.
*
* @var string
* @since 11.1
*/
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 JRegistry $input An optional JRegistry object with the entire data set to validate against the entire form.
* @param JForm $form The form object for which the field is being tested.
*
* @return boolean True if the value is valid, false otherwise.
*
* @since 11.1
* @throws UnexpectedValueException if rule is invalid.
*/
public function test(SimpleXMLElement $element, $value, $group = null, JRegistry $input = null, JForm $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;
}
}

View File

@ -0,0 +1,36 @@
<?php
/**
* @package Joomla.Platform
* @subpackage Form
*
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
defined('JPATH_PLATFORM') or die;
/**
* Form Rule class for the Joomla Platform.
*
* @package Joomla.Platform
* @subpackage Form
* @since 11.1
*/
class JFormRuleBoolean extends JFormRule
{
/**
* The regular expression to use in testing a form field value.
*
* @var string
* @since 11.1
*/
protected $regex = '^(?:[01]|true|false)$';
/**
* The regular expression modifiers to use when testing a form field value.
*
* @var string
* @since 11.1
*/
protected $modifiers = 'i';
}

View File

@ -0,0 +1,62 @@
<?php
/**
* @package Joomla.Platform
* @subpackage Form
*
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
defined('JPATH_PLATFORM') or die;
/**
* Form Rule class for the Joomla Platform.
*
* @package Joomla.Platform
* @subpackage Form
* @since 11.2
*/
class JFormRuleColor extends JFormRule
{
/**
* 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 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 JRegistry $input An optional JRegistry object with the entire data set to validate against the entire form.
* @param JForm $form The form object for which the field is being tested.
*
* @return boolean True if the value is valid, false otherwise.
*
* @since 11.2
*/
public function test(SimpleXMLElement $element, $value, $group = null, JRegistry $input = null, JForm $form = null)
{
$value = trim($value);
if (empty($value))
{
// A color field can't be empty
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;
}
}

View File

@ -0,0 +1,128 @@
<?php
/**
* @package Joomla.Platform
* @subpackage Form
*
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
defined('JPATH_PLATFORM') or die;
/**
* Form Rule class for the Joomla Platform.
*
* @package Joomla.Platform
* @subpackage Form
* @since 11.1
*/
class JFormRuleEmail extends JFormRule
{
/**
* The regular expression to use in testing a form field value.
*
* @var string
* @since 11.1
* @see 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 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 JRegistry $input An optional JRegistry object with the entire data set to validate against the entire form.
* @param JForm $form The form object for which the field is being tested.
*
* @return boolean True if the value is valid, false otherwise.
*
* @since 11.1
*/
public function test(SimpleXMLElement $element, $value, $group = null, JRegistry $input = null, JForm $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-]{2,})$';
}
// Determine if the multiple attribute is present
$multiple = ((string) $element['multiple'] == 'true' || (string) $element['multiple'] == 'multiple');
if ($multiple)
{
$values = explode(',', $value);
}
if (!$multiple)
{
// Handle idn e-mail 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 false;
}
}
else
{
foreach ($values as $value)
{
// Handle idn e-mail 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 false;
}
}
}
// 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 JForm) ? $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;
}
}

View File

@ -0,0 +1,68 @@
<?php
/**
* @package Joomla.Platform
* @subpackage Form
*
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
defined('JPATH_PLATFORM') or die;
/**
* Form Rule class for the Joomla Platform.
*
* @package Joomla.Platform
* @subpackage Form
* @since 11.1
*/
class JFormRuleEquals extends JFormRule
{
/**
* 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 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 JRegistry $input An optional JRegistry object with the entire data set to validate against the entire form.
* @param JForm $form The form object for which the field is being tested.
*
* @return boolean True if the value is valid, false otherwise.
*
* @since 11.1
* @throws InvalidArgumentException
* @throws UnexpectedValueException
*/
public function test(SimpleXMLElement $element, $value, $group = null, JRegistry $input = null, JForm $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 the two values against each other.
if ($value == $input->get($field))
{
return true;
}
return false;
}
}

View File

@ -0,0 +1 @@
<!DOCTYPE html><title></title>

View File

@ -0,0 +1,48 @@
<?php
/**
* @package Joomla.Platform
* @subpackage Form
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
defined('JPATH_PLATFORM') or die;
/**
* Form Rule class for the Joomla Platform.
* Requires the value entered be one of the options in a field of type="list"
*
* @package Joomla.Platform
* @subpackage Form
* @since 11.1
*/
class JFormRuleOptions extends JFormRule
{
/**
* 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 JRegistry $input An optional JRegistry object with the entire data set to validate against the entire form.
* @param JForm $form The form object for which the field is being tested.
*
* @return boolean True if the value is valid, false otherwise.
*
* @since 11.1
*/
public function test(SimpleXMLElement $element, $value, $group = null, JRegistry $input = null, JForm $form = null)
{
// Check each value and return true if we get a match
foreach ($element->option as $option)
{
if ($value == (string) $option->attributes()->value)
{
return true;
}
}
return false;
}
}

View File

@ -0,0 +1,114 @@
<?php
/**
* @package Joomla.Platform
* @subpackage Form
*
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
defined('JPATH_PLATFORM') or die;
/**
* Form Rule class for the Joomla Platform.
*
* @package Joomla.Platform
* @subpackage Form
* @since 11.1
*/
class JFormRuleRules extends JFormRule
{
/**
* 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 JRegistry $input An optional JRegistry object with the entire data set to validate against the entire form.
* @param JForm $form The form object for which the field is being tested.
*
* @return boolean True if the value is valid, false otherwise.
*
* @since 11.1
*/
public function test(SimpleXMLElement $element, $value, $group = null, JRegistry $input = null, JForm $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 11.1
*/
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 11.1
*/
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 = JAccess::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;
}
}

View File

@ -0,0 +1,105 @@
<?php
/**
* @package Joomla.Platform
* @subpackage Form
*
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
defined('JPATH_PLATFORM') or die;
/**
* Form Rule class for the Joomla Platform
*
* @package Joomla.Platform
* @subpackage Form
* @since 11.1
*/
class JFormRuleTel extends JFormRule
{
/**
* 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 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 JRegistry $input An optional JRegistry object with the entire data set to validate against the entire form.
* @param JForm $form The form object for which the field is being tested.
*
* @return boolean True if the value is valid, false otherwise.
*
* @since 11.1
*/
public function test(SimpleXMLElement $element, $value, $group = null, JRegistry $input = null, JForm $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;
}
/*
* @see http://www.nanpa.com/
* @see http://tools.ietf.org/html/rfc4933
* @see http://www.itu.int/rec/T-REC-E.164/en
*
* Regex by Steve Levithan
* @see 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;
}
}

View File

@ -0,0 +1,98 @@
<?php
/**
* @package Joomla.Platform
* @subpackage Form
*
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
defined('JPATH_PLATFORM') or die;
/**
* Form Rule class for the Joomla Platform.
*
* @package Joomla.Platform
* @subpackage Form
* @since 11.1
*/
class JFormRuleUrl extends JFormRule
{
/**
* Method to test an external 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 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 JRegistry $input An optional JRegistry object with the entire data set to validate against the entire form.
* @param JForm $form The form object for which the field is being tested.
*
* @return boolean True if the value is valid, false otherwise.
*
* @since 11.1
* @link http://www.w3.org/Addressing/URL/url-spec.txt
* @see Jstring
*/
public function test(SimpleXMLElement $element, $value, $group = null, JRegistry $input = null, JForm $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 = JString::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', 'tn3270', 'wais', 'url',
'mid', 'cid', 'nntp', 'tel', 'urn', 'ldap', 'file', 'fax', 'modem', 'git');
}
else
{
$scheme = explode(',', $element['schemes']);
}
/*
* This rule is only for full URLs with schemes because parse_url does not parse
* accurately without a scheme.
* @see http://php.net/manual/en/function.parse-url.php
*/
if ($urlParts && !array_key_exists('scheme', $urlParts))
{
return false;
}
$urlScheme = (string) $urlParts['scheme'];
$urlScheme = strtolower($urlScheme);
if (in_array($urlScheme, $scheme) == false)
{
return false;
}
// For some schemes here must be two slashes.
if (($urlScheme == 'http' || $urlScheme == 'https' || $urlScheme == 'ftp' || $urlScheme == 'sftp' || $urlScheme == 'gopher'
|| $urlScheme == 'wais' || $urlScheme == 'gopher' || $urlScheme == 'prospero' || $urlScheme == 'telnet' || $urlScheme == 'git')
&& ((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) && !JString::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) && !JString::valid((string) $urlParts['path']))
{
return false;
}
return true;
}
}

View File

@ -0,0 +1,62 @@
<?php
/**
* @package Joomla.Platform
* @subpackage Form
*
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
defined('JPATH_PLATFORM') or die;
/**
* Form Rule class for the Joomla Platform.
*
* @package Joomla.Platform
* @subpackage Form
* @since 11.1
*/
class JFormRuleUsername extends JFormRule
{
/**
* 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 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 JRegistry $input An optional JRegistry object with the entire data set to validate against the entire form.
* @param JForm $form The form object for which the field is being tested.
*
* @return boolean True if the value is valid, false otherwise.
*
* @since 11.1
*/
public function test(SimpleXMLElement $element, $value, $group = null, JRegistry $input = null, JForm $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 JForm) ? $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;
}
}