primo commit

This commit is contained in:
2024-12-17 17:34:10 +01:00
commit e650f8df99
16435 changed files with 2451012 additions and 0 deletions

View File

@ -0,0 +1,38 @@
<?php
/**
* @package FrameworkOnFramework
* @subpackage form
* @copyright Copyright (C) 2010-2016 Nicholas K. Dionysopoulos / Akeeba Ltd. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
// Protect from unauthorized access
defined('F0F_INCLUDED') or die;
/**
* Generic interface that a F0F form field class must implement
*
* @package FrameworkOnFramework
* @since 2.0
*/
interface F0FFormField
{
/**
* Get the rendering of this field type for static display, e.g. in a single
* item view (typically a "read" task).
*
* @return string The field HTML
*
* @since 2.0
*/
public function getStatic();
/**
* Get the rendering of this field type for a repeatable (grid) display,
* e.g. in a view listing many item (typically a "browse" task)
*
* @return string The field HTML
*
* @since 2.0
*/
public function getRepeatable();
}

View File

@ -0,0 +1,156 @@
<?php
/**
* @package FrameworkOnFramework
* @subpackage form
* @subpackage form
* @copyright Copyright (C) 2010-2016 Nicholas K. Dionysopoulos / Akeeba Ltd. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
// Protect from unauthorized access
defined('F0F_INCLUDED') or die;
JFormHelper::loadFieldClass('accesslevel');
/**
* Form Field class for F0F
* Joomla! access levels
*
* @package FrameworkOnFramework
* @since 2.0
*/
class F0FFormFieldAccesslevel extends JFormFieldAccessLevel implements F0FFormField
{
protected $static;
protected $repeatable;
/** @var int A monotonically increasing number, denoting the row number in a repeatable view */
public $rowid;
/** @var F0FTable The item being rendered in a repeatable form field */
public $item;
/**
* Method to get certain otherwise inaccessible properties from the form field object.
*
* @param string $name The property name for which to the the value.
*
* @return mixed The property value or null.
*
* @since 2.0
*/
public function __get($name)
{
switch ($name)
{
case 'static':
if (empty($this->static))
{
$this->static = $this->getStatic();
}
return $this->static;
break;
case 'repeatable':
if (empty($this->repeatable))
{
$this->repeatable = $this->getRepeatable();
}
return $this->repeatable;
break;
default:
return parent::__get($name);
}
}
/**
* Get the rendering of this field type for static display, e.g. in a single
* item view (typically a "read" task).
*
* @since 2.0
*
* @return string The field HTML
*/
public function getStatic()
{
$class = $this->element['class'] ? ' class="' . (string) $this->element['class'] . '"' : '';
$params = $this->getOptions();
$db = F0FPlatform::getInstance()->getDbo();
$query = $db->getQuery(true);
$query->select('a.id AS value, a.title AS text');
$query->from('#__viewlevels AS a');
$query->group('a.id, a.title, a.ordering');
$query->order('a.ordering ASC');
$query->order($query->qn('title') . ' ASC');
// Get the options.
$db->setQuery($query);
$options = $db->loadObjectList();
// If params is an array, push these options to the array
if (is_array($params))
{
$options = array_merge($params, $options);
}
// If all levels is allowed, push it into the array.
elseif ($params)
{
array_unshift($options, JHtml::_('select.option', '', JText::_('JOPTION_ACCESS_SHOW_ALL_LEVELS')));
}
return '<span id="' . $this->id . '" ' . $class . '>' .
htmlspecialchars(F0FFormFieldList::getOptionName($options, $this->value), ENT_COMPAT, 'UTF-8') .
'</span>';
}
/**
* Get the rendering of this field type for a repeatable (grid) display,
* e.g. in a view listing many item (typically a "browse" task)
*
* @since 2.0
*
* @return string The field HTML
*/
public function getRepeatable()
{
$class = $this->element['class'] ? (string) $this->element['class'] : '';
$params = $this->getOptions();
$db = F0FPlatform::getInstance()->getDbo();
$query = $db->getQuery(true);
$query->select('a.id AS value, a.title AS text');
$query->from('#__viewlevels AS a');
$query->group('a.id, a.title, a.ordering');
$query->order('a.ordering ASC');
$query->order($query->qn('title') . ' ASC');
// Get the options.
$db->setQuery($query);
$options = $db->loadObjectList();
// If params is an array, push these options to the array
if (is_array($params))
{
$options = array_merge($params, $options);
}
// If all levels is allowed, push it into the array.
elseif ($params)
{
array_unshift($options, JHtml::_('select.option', '', JText::_('JOPTION_ACCESS_SHOW_ALL_LEVELS')));
}
return '<span class="' . $this->id . ' ' . $class . '">' .
htmlspecialchars(F0FFormFieldList::getOptionName($options, $this->value), ENT_COMPAT, 'UTF-8') .
'</span>';
}
}

View File

@ -0,0 +1,250 @@
<?php
/**
* @package FrameworkOnFramework
* @subpackage form
* @copyright Copyright (C) 2010-2016 Nicholas K. Dionysopoulos / Akeeba Ltd. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
// Protect from unauthorized access
defined('F0F_INCLUDED') or die;
JFormHelper::loadFieldClass('list');
/**
* Form Field class for F0F
* Supports a generic list of options.
*
* @package FrameworkOnFramework
* @since 2.0
*/
class F0FFormFieldActions extends JFormFieldList implements F0FFormField
{
protected $static;
protected $repeatable;
/** @var int A monotonically increasing number, denoting the row number in a repeatable view */
public $rowid;
/** @var F0FTable The item being rendered in a repeatable form field */
public $item;
/**
* Method to get certain otherwise inaccessible properties from the form field object.
*
* @param string $name The property name for which to the the value.
*
* @return mixed The property value or null.
*
* @since 2.0
*/
public function __get($name)
{
switch ($name)
{
case 'static':
if (empty($this->static))
{
$this->static = $this->getStatic();
}
return $this->static;
break;
case 'repeatable':
if (empty($this->repeatable))
{
$this->repeatable = $this->getRepeatable();
}
return $this->repeatable;
break;
default:
return parent::__get($name);
}
}
/**
* Get the field configuration
*
* @return array
*/
protected function getConfig()
{
// If no custom options were defined let's figure out which ones of the
// defaults we shall use...
$config = array(
'published' => 1,
'unpublished' => 1,
'archived' => 0,
'trash' => 0,
'all' => 0,
);
$stack = array();
if (isset($this->element['show_published']))
{
$config['published'] = F0FStringUtils::toBool($this->element['show_published']);
}
if (isset($this->element['show_unpublished']))
{
$config['unpublished'] = F0FStringUtils::toBool($this->element['show_unpublished']);
}
if (isset($this->element['show_archived']))
{
$config['archived'] = F0FStringUtils::toBool($this->element['show_archived']);
}
if (isset($this->element['show_trash']))
{
$config['trash'] = F0FStringUtils::toBool($this->element['show_trash']);
}
if (isset($this->element['show_all']))
{
$config['all'] = F0FStringUtils::toBool($this->element['show_all']);
}
return $config;
}
/**
* Method to get the field options.
*
* @since 2.0
*
* @return array The field option objects.
*/
protected function getOptions()
{
return null;
}
/**
* Method to get a
*
* @param string $enabledFieldName Name of the enabled/published field
*
* @return F0FFormFieldPublished Field
*/
protected function getPublishedField($enabledFieldName)
{
$attributes = array(
'name' => $enabledFieldName,
'type' => 'published',
);
if ($this->element['publish_up'])
{
$attributes['publish_up'] = (string) $this->element['publish_up'];
}
if ($this->element['publish_down'])
{
$attributes['publish_down'] = (string) $this->element['publish_down'];
}
foreach ($attributes as $name => $value)
{
if (!is_null($value))
{
$renderedAttributes[] = $name . '="' . $value . '"';
}
}
$publishedXml = new SimpleXMLElement('<field ' . implode(' ', $renderedAttributes) . ' />');
$publishedField = new F0FFormFieldPublished($this->form);
// Pass required objects to the field
$publishedField->item = $this->item;
$publishedField->rowid = $this->rowid;
$publishedField->setup($publishedXml, $this->item->{$enabledFieldName});
return $publishedField;
}
/**
* Get the rendering of this field type for static display, e.g. in a single
* item view (typically a "read" task).
*
* @since 2.0
*
* @return string The field HTML
*/
public function getStatic()
{
throw new Exception(__CLASS__ . ' cannot be used in single item display forms');
}
/**
* Get the rendering of this field type for a repeatable (grid) display,
* e.g. in a view listing many item (typically a "browse" task)
*
* @since 2.0
*
* @return string The field HTML
*/
public function getRepeatable()
{
if (!($this->item instanceof F0FTable))
{
throw new Exception(__CLASS__ . ' needs a F0FTable to act upon');
}
$config = $this->getConfig();
// Initialise
$prefix = '';
$checkbox = 'cb';
$publish_up = null;
$publish_down = null;
$enabled = true;
$html = '<div class="btn-group">';
// Render a published field
if ($publishedFieldName = $this->item->getColumnAlias('enabled'))
{
if ($config['published'] || $config['unpublished'])
{
// Generate a F0FFormFieldPublished field
$publishedField = $this->getPublishedField($publishedFieldName);
// Render the publish button
$html .= $publishedField->getRepeatable();
}
if ($config['archived'])
{
$archived = $this->item->{$publishedFieldName} == 2 ? true : false;
// Create dropdown items
$action = $archived ? 'unarchive' : 'archive';
JHtml::_('actionsdropdown.' . $action, 'cb' . $this->rowid, $prefix);
}
if ($config['trash'])
{
$trashed = $this->item->{$publishedFieldName} == -2 ? true : false;
$action = $trashed ? 'untrash' : 'trash';
JHtml::_('actionsdropdown.' . $action, 'cb' . $this->rowid, $prefix);
}
// Render dropdown list
if ($config['archived'] || $config['trash'])
{
$html .= JHtml::_('actionsdropdown.render', $this->item->title);
}
}
$html .= '</div>';
return $html;
}
}

View File

@ -0,0 +1,137 @@
<?php
/**
* @package FrameworkOnFramework
* @subpackage form
* @copyright Copyright (C) 2010-2016 Nicholas K. Dionysopoulos / Akeeba Ltd. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
// Protect from unauthorized access
defined('F0F_INCLUDED') or die;
JFormHelper::loadFieldClass('text');
/**
* Form Field class for the F0F framework
* Supports a button input.
*
* @package FrameworkOnFramework
* @since 2.0
*/
class F0FFormFieldButton extends F0FFormFieldText implements F0FFormField
{
protected $static;
protected $repeatable;
/**
* Method to get certain otherwise inaccessible properties from the form field object.
*
* @param string $name The property name for which to the the value.
*
* @return mixed The property value or null.
*
* @since 2.0
*/
public function __get($name)
{
switch ($name)
{
case 'static':
if (empty($this->static))
{
$this->static = $this->getStatic();
}
return $this->static;
break;
case 'repeatable':
if (empty($this->repeatable))
{
$this->repeatable = $this->getRepeatable();
}
return $this->repeatable;
break;
default:
return parent::__get($name);
}
}
/**
* Get the rendering of this field type for static display, e.g. in a single
* item view (typically a "read" task).
*
* @since 2.0
*
* @return string The field HTML
*/
public function getStatic()
{
return $this->getInput();
}
/**
* Get the rendering of this field type for a repeatable (grid) display,
* e.g. in a view listing many item (typically a "browse" task)
*
* @since 2.0
*
* @return string The field HTML
*/
public function getRepeatable()
{
return $this->getInput();
}
/**
* Get the rendering of this field type for static display, e.g. in a single
* item view (typically a "read" task).
*
* @since 2.0
*
* @return string The field HTML
*/
public function getInput()
{
$this->label = '';
$allowedElement = array('button', 'a');
if (in_array($this->element['htmlelement'], $allowedElement))
$type = $this->element['htmlelement'];
else
$type = 'button';
$text = $this->element['text'];
$class = $this->element['class'] ? (string) $this->element['class'] : '';
$icon = $this->element['icon'] ? (string) $this->element['icon'] : '';
$onclick = $this->element['onclick'] ? 'onclick="' . (string) $this->element['onclick'] . '"' : '';
$url = $this->element['url'] ? 'href="' . $this->parseFieldTags((string) $this->element['url']) . '"' : '';
$title = $this->element['title'] ? 'title="' . JText::_((string) $this->element['title']) . '"' : '';
$this->value = JText::_($text);
if ($icon)
{
$icon = '<span class="icon ' . $icon . '"></span>';
}
return '<' . $type . ' id="' . $this->id . '" class="btn ' . $class . '" ' .
$onclick . $url . $title . '>' .
$icon .
htmlspecialchars($this->value, ENT_COMPAT, 'UTF-8') .
'</' . $type . '>';
}
/**
* Method to get the field title.
*
* @return string The field title.
*/
protected function getTitle()
{
return null;
}
}

View File

@ -0,0 +1,102 @@
<?php
/**
* @package FrameworkOnFramework
* @subpackage form
* @copyright Copyright (C) 2010-2016 Nicholas K. Dionysopoulos / Akeeba Ltd. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
// Protect from unauthorized access
defined('F0F_INCLUDED') or die;
JFormHelper::loadFieldClass('cachehandler');
/**
* Form Field class for F0F
* Joomla! cache handlers
*
* @package FrameworkOnFramework
* @since 2.0
*/
class F0FFormFieldCachehandler extends JFormFieldCacheHandler implements F0FFormField
{
protected $static;
protected $repeatable;
/** @var F0FTable The item being rendered in a repeatable form field */
public $item;
/** @var int A monotonically increasing number, denoting the row number in a repeatable view */
public $rowid;
/**
* Method to get certain otherwise inaccessible properties from the form field object.
*
* @param string $name The property name for which to the the value.
*
* @return mixed The property value or null.
*
* @since 2.0
*/
public function __get($name)
{
switch ($name)
{
case 'static':
if (empty($this->static))
{
$this->static = $this->getStatic();
}
return $this->static;
break;
case 'repeatable':
if (empty($this->repeatable))
{
$this->repeatable = $this->getRepeatable();
}
return $this->repeatable;
break;
default:
return parent::__get($name);
}
}
/**
* Get the rendering of this field type for static display, e.g. in a single
* item view (typically a "read" task).
*
* @since 2.0
*
* @return string The field HTML
*/
public function getStatic()
{
$class = $this->element['class'] ? ' class="' . (string) $this->element['class'] . '"' : '';
return '<span id="' . $this->id . '" ' . $class . '>' .
htmlspecialchars(F0FFormFieldList::getOptionName($this->getOptions(), $this->value), ENT_COMPAT, 'UTF-8') .
'</span>';
}
/**
* Get the rendering of this field type for a repeatable (grid) display,
* e.g. in a view listing many item (typically a "browse" task)
*
* @since 2.0
*
* @return string The field HTML
*/
public function getRepeatable()
{
$class = $this->element['class'] ? (string) $this->element['class'] : '';
return '<span class="' . $this->id . ' ' . $class . '">' .
htmlspecialchars(F0FFormFieldList::getOptionName($this->getOptions(), $this->value), ENT_COMPAT, 'UTF-8') .
'</span>';
}
}

View File

@ -0,0 +1,211 @@
<?php
/**
* @package FrameworkOnFramework
* @subpackage form
* @copyright Copyright (C) 2010-2016 Nicholas K. Dionysopoulos / Akeeba Ltd. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
// Protect from unauthorized access
defined('F0F_INCLUDED') or die;
JFormHelper::loadFieldClass('calendar');
/**
* Form Field class for the F0F framework
* Supports a calendar / date field.
*
* @package FrameworkOnFramework
* @since 2.0
*/
class F0FFormFieldCalendar extends JFormFieldCalendar implements F0FFormField
{
protected $static;
protected $repeatable;
/** @var F0FTable The item being rendered in a repeatable form field */
public $item;
/** @var int A monotonically increasing number, denoting the row number in a repeatable view */
public $rowid;
/**
* Method to get certain otherwise inaccessible properties from the form field object.
*
* @param string $name The property name for which to the the value.
*
* @return mixed The property value or null.
*
* @since 2.0
*/
public function __get($name)
{
switch ($name)
{
// ATTENTION: Redirected getInput() to getStatic()
case 'input':
case 'static':
if (empty($this->static))
{
$this->static = $this->getStatic();
}
return $this->static;
break;
case 'repeatable':
if (empty($this->repeatable))
{
$this->repeatable = $this->getRepeatable();
}
return $this->repeatable;
break;
default:
return parent::__get($name);
}
}
/**
* Get the rendering of this field type for static display, e.g. in a single
* item view (typically a "read" task).
*
* @since 2.0
*
* @return string The field HTML
*/
public function getStatic()
{
return $this->getCalendar('static');
}
/**
* Get the rendering of this field type for a repeatable (grid) display,
* e.g. in a view listing many item (typically a "browse" task)
*
* @since 2.0
*
* @return string The field HTML
*/
public function getRepeatable()
{
return $this->getCalendar('repeatable');
}
/**
* Method to get the calendar input markup.
*
* @param string $display The display to render ('static' or 'repeatable')
*
* @return string The field input markup.
*
* @since 2.1.rc4
*/
protected function getCalendar($display)
{
// Initialize some field attributes.
$format = $this->element['format'] ? (string) $this->element['format'] : '%Y-%m-%d';
$class = $this->element['class'] ? (string) $this->element['class'] : '';
$default = $this->element['default'] ? (string) $this->element['default'] : '';
// PHP date doesn't use percentages (%) for the format, but the calendar Javascript
// DOES use it (@see: calendar-uncompressed.js). Therefore we have to convert it.
$formatJS = $format;
$formatPHP = str_replace(array('%', 'H:M:S', 'B'), array('', 'H:i:s', 'F'), $formatJS);
// Check for empty date values
if (empty($this->value) || $this->value == F0FPlatform::getInstance()->getDbo()->getNullDate() || $this->value == '0000-00-00')
{
$this->value = $default;
}
// Get some system objects.
$config = F0FPlatform::getInstance()->getConfig();
$user = JFactory::getUser();
// Format date if exists
if (!empty($this->value))
{
$date = F0FPlatform::getInstance()->getDate($this->value, 'UTC');
// 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->setTimezone(new DateTimeZone($config->get('offset')));
}
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->setTimezone(new DateTimeZone($user->getParam('timezone', $config->get('offset'))));
}
break;
default:
break;
}
// Transform the date string.
$this->value = $date->format($formatPHP, true, false);
}
if ($display == 'static')
{
// 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';
}
return JHtml::_('calendar', $this->value, $this->name, $this->id, $formatJS, $attributes);
}
else
{
return '<span class="' . $this->id . ' ' . $class . '">' .
htmlspecialchars($this->value, ENT_COMPAT, 'UTF-8') .
'</span>';
}
}
}

View File

@ -0,0 +1,93 @@
<?php
/**
* @package FrameworkOnFramework
* @subpackage form
* @copyright Copyright (C) 2010-2016 Nicholas K. Dionysopoulos / Akeeba Ltd. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
// Protect from unauthorized access
defined('F0F_INCLUDED') or die;
JFormHelper::loadFieldClass('captcha');
/**
* Form Field class for the F0F framework
* Supports a captcha field.
*
* @package FrameworkOnFramework
* @since 2.0
*/
class F0FFormFieldCaptcha extends JFormFieldCaptcha implements F0FFormField
{
protected $static;
protected $repeatable;
/** @var F0FTable The item being rendered in a repeatable form field */
public $item;
/** @var int A monotonically increasing number, denoting the row number in a repeatable view */
public $rowid;
/**
* Method to get certain otherwise inaccessible properties from the form field object.
*
* @param string $name The property name for which to the the value.
*
* @return mixed The property value or null.
*
* @since 2.0
*/
public function __get($name)
{
switch ($name)
{
case 'static':
if (empty($this->static))
{
$this->static = $this->getStatic();
}
return $this->static;
break;
case 'repeatable':
if (empty($this->repeatable))
{
$this->repeatable = $this->getRepeatable();
}
return $this->repeatable;
break;
default:
return parent::__get($name);
}
}
/**
* Get the rendering of this field type for static display, e.g. in a single
* item view (typically a "read" task).
*
* @since 2.0
*
* @return string The field HTML
*/
public function getStatic()
{
return $this->getInput();
}
/**
* Get the rendering of this field type for a repeatable (grid) display,
* e.g. in a view listing many item (typically a "browse" task)
*
* @since 2.0
*
* @return string The field HTML
*/
public function getRepeatable()
{
return $this->getInput();
}
}

View File

@ -0,0 +1,129 @@
<?php
/**
* @package FrameworkOnFramework
* @subpackage form
* @copyright Copyright (C) 2010-2016 Nicholas K. Dionysopoulos / Akeeba Ltd. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
// Protect from unauthorized access
defined('F0F_INCLUDED') or die;
JFormHelper::loadFieldClass('checkbox');
/**
* Form Field class for the F0F framework
* A single checkbox
*
* @package FrameworkOnFramework
* @since 2.0
*/
class F0FFormFieldCheckbox extends JFormFieldCheckbox implements F0FFormField
{
protected $static;
protected $repeatable;
/** @var F0FTable The item being rendered in a repeatable form field */
public $item;
/** @var int A monotonically increasing number, denoting the row number in a repeatable view */
public $rowid;
/**
* Method to get certain otherwise inaccessible properties from the form field object.
*
* @param string $name The property name for which to the the value.
*
* @return mixed The property value or null.
*
* @since 2.0
*/
public function __get($name)
{
switch ($name)
{
case 'static':
if (empty($this->static))
{
$this->static = $this->getStatic();
}
return $this->static;
break;
case 'repeatable':
if (empty($this->repeatable))
{
$this->repeatable = $this->getRepeatable();
}
return $this->repeatable;
break;
default:
return parent::__get($name);
}
}
/**
* Get the rendering of this field type for static display, e.g. in a single
* item view (typically a "read" task).
*
* @since 2.0
*
* @return string The field HTML
*/
public function getStatic()
{
$class = $this->element['class'] ? ' class="' . (string) $this->element['class'] . '"' : '';
$value = $this->element['value'] ? (string) $this->element['value'] : '1';
$disabled = ((string) $this->element['disabled'] == 'true') ? ' disabled="disabled"' : '';
$onclick = $this->element['onclick'] ? ' onclick="' . (string) $this->element['onclick'] . '"' : '';
$required = $this->required ? ' required="required" aria-required="true"' : '';
if (empty($this->value))
{
$checked = (isset($this->element['checked'])) ? ' checked="checked"' : '';
}
else
{
$checked = ' checked="checked"';
}
return '<span id="' . $this->id . '" ' . $class . '>' .
'<input type="checkbox" name="' . $this->name . '" id="' . $this->id . '"' . ' value="'
. htmlspecialchars($value, ENT_COMPAT, 'UTF-8') . '"' . $class . $checked . $disabled . $onclick . $required . ' />' .
'</span>';
}
/**
* Get the rendering of this field type for a repeatable (grid) display,
* e.g. in a view listing many item (typically a "browse" task)
*
* @since 2.0
*
* @return string The field HTML
*/
public function getRepeatable()
{
$class = $this->element['class'] ? (string) $this->element['class'] : '';
$value = $this->element['value'] ? (string) $this->element['value'] : '1';
$disabled = ((string) $this->element['disabled'] == 'true') ? ' disabled="disabled"' : '';
$onclick = $this->element['onclick'] ? ' onclick="' . (string) $this->element['onclick'] . '"' : '';
$required = $this->required ? ' required="required" aria-required="true"' : '';
if (empty($this->value))
{
$checked = (isset($this->element['checked'])) ? ' checked="checked"' : '';
}
else
{
$checked = ' checked="checked"';
}
return '<span class="' . $this->id . ' ' . $class . '">' .
'<input type="checkbox" name="' . $this->name . '" class="' . $this->id . ' ' . $class . '"' . ' value="'
. htmlspecialchars($value, ENT_COMPAT, 'UTF-8') . '"' . $checked . $disabled . $onclick . $required . ' />' .
'</span>';
}
}

View File

@ -0,0 +1,128 @@
<?php
/**
* @package FrameworkOnFramework
* @subpackage form
* @copyright Copyright (C) 2010-2016 Nicholas K. Dionysopoulos / Akeeba Ltd. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
// Protect from unauthorized access
defined('F0F_INCLUDED') or die;
JFormHelper::loadFieldClass('checkboxes');
/**
* Form Field class for F0F
* Supports a list of checkbox.
*
* @package FrameworkOnFramework
* @since 2.0
*/
class F0FFormFieldCheckboxes extends JFormFieldCheckboxes implements F0FFormField
{
protected $static;
protected $repeatable;
/** @var F0FTable The item being rendered in a repeatable form field */
public $item;
/** @var int A monotonically increasing number, denoting the row number in a repeatable view */
public $rowid;
/**
* Method to get certain otherwise inaccessible properties from the form field object.
*
* @param string $name The property name for which to the the value.
*
* @return mixed The property value or null.
*
* @since 2.0
*/
public function __get($name)
{
switch ($name)
{
case 'static':
if (empty($this->static))
{
$this->static = $this->getStatic();
}
return $this->static;
break;
case 'repeatable':
if (empty($this->repeatable))
{
$this->repeatable = $this->getRepeatable();
}
return $this->repeatable;
break;
default:
return parent::__get($name);
}
}
/**
* Get the rendering of this field type for static display, e.g. in a single
* item view (typically a "read" task).
*
* @since 2.0
*
* @return string The field HTML
*/
public function getStatic()
{
return $this->getRepeatable();
}
/**
* Get the rendering of this field type for a repeatable (grid) display,
* e.g. in a view listing many item (typically a "browse" task)
*
* @since 2.0
*
* @return string The field HTML
*/
public function getRepeatable()
{
$class = $this->element['class'] ? (string) $this->element['class'] : $this->id;
$translate = $this->element['translate'] ? (string) $this->element['translate'] : false;
$html = '<span class="' . $class . '">';
foreach ($this->value as $value) {
$html .= '<span>';
if ($translate == true)
{
$html .= JText::_($value);
}
else
{
$html .= $value;
}
$html .= '</span>';
}
$html .= '</span>';
}
/**
* Get the rendering of this field type for static display, e.g. in a single
* item view (typically a "read" task).
*
* @since 2.0
*
* @return string The field HTML
*/
public function getInput()
{
// Used for J! 2.5 compatibility
$this->value = !is_array($this->value) ? explode(',', $this->value) : $this->value;
return parent::getInput();
}
}

View File

@ -0,0 +1,237 @@
<?php
/**
* @package FrameworkOnFramework
* @subpackage form
* @copyright Copyright (C) 2010-2016 Nicholas K. Dionysopoulos / Akeeba Ltd. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
// Protect from unauthorized access
defined('F0F_INCLUDED') or die;
JFormHelper::loadFieldClass('list');
/**
* Form Field class for F0F
* Components installed on the site
*
* @package FrameworkOnFramework
* @since 2.1
*/
class F0FFormFieldComponents extends JFormFieldList implements F0FFormField
{
protected $static;
protected $repeatable;
public $client_ids = null;
/** @var F0FTable The item being rendered in a repeatable form field */
public $item;
/** @var int A monotonically increasing number, denoting the row number in a repeatable view */
public $rowid;
/**
* Method to get certain otherwise inaccessible properties from the form field object.
*
* @param string $name The property name for which to the the value.
*
* @return mixed The property value or null.
*
* @since 2.1
*/
public function __get($name)
{
switch ($name)
{
case 'static':
if (empty($this->static))
{
$this->static = $this->getStatic();
}
return $this->static;
break;
case 'repeatable':
if (empty($this->repeatable))
{
$this->repeatable = $this->getRepeatable();
}
return $this->repeatable;
break;
default:
return parent::__get($name);
}
}
/**
* Get the rendering of this field type for static display, e.g. in a single
* item view (typically a "read" task).
*
* @since 2.1
*
* @return string The field HTML
*/
public function getStatic()
{
$class = $this->element['class'] ? ' class="' . (string) $this->element['class'] . '"' : '';
return '<span id="' . $this->id . '" ' . $class . '>' .
htmlspecialchars(F0FFormFieldList::getOptionName($this->getOptions(), $this->value), ENT_COMPAT, 'UTF-8') .
'</span>';
}
/**
* Get the rendering of this field type for a repeatable (grid) display,
* e.g. in a view listing many item (typically a "browse" task)
*
* @since 2.1
*
* @return string The field HTML
*/
public function getRepeatable()
{
$class = $this->element['class'] ? (string) $this->element['class'] : '';
return '<span class="' . $this->id . ' ' . $class . '">' .
htmlspecialchars(F0FFormFieldList::getOptionName($this->getOptions(), $this->value), ENT_COMPAT, 'UTF-8') .
'</span>';
}
/**
* Get a list of all installed components and also translates them.
*
* The manifest_cache is used to get the extension names, since JInstaller is also
* translating those names in stead of the name column. Else some of the translations
* fails.
*
* @since 2.1
*
* @return array An array of JHtml options.
*/
protected function getOptions()
{
$db = F0FPlatform::getInstance()->getDbo();
// Check for client_ids override
if ($this->client_ids !== null)
{
$client_ids = $this->client_ids;
}
else
{
$client_ids = $this->element['client_ids'];
}
$client_ids = explode(',', $client_ids);
// Calculate client_ids where clause
foreach ($client_ids as &$client_id)
{
$client_id = (int) trim($client_id);
$client_id = $db->q($client_id);
}
$query = $db->getQuery(true)
->select(
array(
$db->qn('name'),
$db->qn('element'),
$db->qn('client_id'),
$db->qn('manifest_cache'),
)
)
->from($db->qn('#__extensions'))
->where($db->qn('type') . ' = ' . $db->q('component'))
->where($db->qn('client_id') . ' IN (' . implode(',', $client_ids) . ')');
$db->setQuery($query);
$components = $db->loadObjectList('element');
// Convert to array of objects, so we can use sortObjects()
// Also translate component names with JText::_()
$aComponents = array();
$user = JFactory::getUser();
foreach ($components as $component)
{
// Don't show components in the list where the user doesn't have access for
// TODO: perhaps add an option for this
if (!$user->authorise('core.manage', $component->element))
{
continue;
}
$oData = (object) array(
'value' => $component->element,
'text' => $this->translate($component, 'component')
);
$aComponents[$component->element] = $oData;
}
// Reorder the components array, because the alphabetical
// ordering changed due to the JText::_() translation
uasort(
$aComponents,
function ($a, $b) {
return strcasecmp($a->text, $b->text);
}
);
return $aComponents;
}
/**
* Translate a list of objects with JText::_().
*
* @param array $item The array of objects
* @param string $type The extension type (e.g. component)
*
* @since 2.1
*
* @return string $text The translated name of the extension
*
* @see administrator/com_installer/models/extension.php
*/
public function translate($item, $type)
{
$platform = F0FPlatform::getInstance();
// Map the manifest cache to $item. This is needed to get the name from the
// manifest_cache and NOT from the name column, else some JText::_() translations fails.
$mData = json_decode($item->manifest_cache);
if ($mData)
{
foreach ($mData as $key => $value)
{
if ($key == 'type')
{
// Ignore the type field
continue;
}
$item->$key = $value;
}
}
$lang = $platform->getLanguage();
switch ($type)
{
case 'component':
$source = JPATH_ADMINISTRATOR . '/components/' . $item->element;
$lang->load("$item->element.sys", JPATH_ADMINISTRATOR, null, false, false)
|| $lang->load("$item->element.sys", $source, null, false, false)
|| $lang->load("$item->element.sys", JPATH_ADMINISTRATOR, $lang->getDefault(), false, false)
|| $lang->load("$item->element.sys", $source, $lang->getDefault(), false, false);
break;
}
$text = JText::_($item->name);
return $text;
}
}

View File

@ -0,0 +1,97 @@
<?php
/**
* @package FrameworkOnFramework
* @subpackage form
* @copyright Copyright (C) 2010-2016 Nicholas K. Dionysopoulos / Akeeba Ltd. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
// Protect from unauthorized access
defined('F0F_INCLUDED') or die;
JFormHelper::loadFieldClass('editor');
/**
* Form Field class for the F0F framework
* An editarea field for content creation and formatted HTML display
*
* @package FrameworkOnFramework
* @since 2.0
*/
class F0FFormFieldEditor extends JFormFieldEditor implements F0FFormField
{
protected $static;
protected $repeatable;
/** @var F0FTable The item being rendered in a repeatable form field */
public $item;
/** @var int A monotonically increasing number, denoting the row number in a repeatable view */
public $rowid;
/**
* Method to get certain otherwise inaccessible properties from the form field object.
*
* @param string $name The property name for which to the the value.
*
* @return mixed The property value or null.
*
* @since 2.0
*/
public function __get($name)
{
switch ($name)
{
case 'static':
if (empty($this->static))
{
$this->static = $this->getStatic();
}
return $this->static;
break;
case 'repeatable':
if (empty($this->repeatable))
{
$this->repeatable = $this->getRepeatable();
}
return $this->repeatable;
break;
default:
return parent::__get($name);
}
}
/**
* Get the rendering of this field type for static display, e.g. in a single
* item view (typically a "read" task).
*
* @since 2.0
*
* @return string The field HTML
*/
public function getStatic()
{
$class = $this->element['class'] ? ' class="' . (string) $this->element['class'] . '"' : '';
return '<div id="' . $this->id . '" ' . $class . '>' . $this->value . '</div>';
}
/**
* Get the rendering of this field type for a repeatable (grid) display,
* e.g. in a view listing many item (typically a "browse" task)
*
* @since 2.0
*
* @return string The field HTML
*/
public function getRepeatable()
{
$class = $this->element['class'] ? (string) $this->element['class'] : '';
return '<div class="' . $this->id . ' ' . $class . '">' . $this->value . '</div>';
}
}

View File

@ -0,0 +1,173 @@
<?php
/**
* @package FrameworkOnFramework
* @subpackage form
* @copyright Copyright (C) 2010-2016 Nicholas K. Dionysopoulos / Akeeba Ltd. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
// Protect from unauthorized access
defined('F0F_INCLUDED') or die;
JFormHelper::loadFieldClass('email');
/**
* Form Field class for the F0F framework
* Supports a one line text field.
*
* @package FrameworkOnFramework
* @since 2.0
*/
class F0FFormFieldEmail extends JFormFieldEMail implements F0FFormField
{
protected $static;
protected $repeatable;
/** @var F0FTable The item being rendered in a repeatable form field */
public $item;
/** @var int A monotonically increasing number, denoting the row number in a repeatable view */
public $rowid;
/**
* Method to get certain otherwise inaccessible properties from the form field object.
*
* @param string $name The property name for which to the the value.
*
* @return mixed The property value or null.
*
* @since 2.0
*/
public function __get($name)
{
switch ($name)
{
case 'static':
if (empty($this->static))
{
$this->static = $this->getStatic();
}
return $this->static;
break;
case 'repeatable':
if (empty($this->repeatable))
{
$this->repeatable = $this->getRepeatable();
}
return $this->repeatable;
break;
default:
return parent::__get($name);
}
}
/**
* Get the rendering of this field type for static display, e.g. in a single
* item view (typically a "read" task).
*
* @since 2.0
*
* @return string The field HTML
*/
public function getStatic()
{
$class = $this->element['class'] ? ' class="' . (string) $this->element['class'] . '"' : '';
$dolink = $this->element['show_link'] == 'true';
$empty_replacement = '';
if ($this->element['empty_replacement'])
{
$empty_replacement = (string) $this->element['empty_replacement'];
}
if (!empty($empty_replacement) && empty($this->value))
{
$this->value = JText::_($empty_replacement);
}
$innerHtml = htmlspecialchars($this->value, ENT_COMPAT, 'UTF-8');
if ($dolink)
{
$innerHtml = '<a href="mailto:' . $innerHtml . '">' .
$innerHtml . '</a>';
}
return '<span id="' . $this->id . '" ' . $class . '>' .
$innerHtml .
'</span>';
}
/**
* Get the rendering of this field type for a repeatable (grid) display,
* e.g. in a view listing many item (typically a "browse" task)
*
* @since 2.0
*
* @return string The field HTML
*/
public function getRepeatable()
{
// Initialise
$class = '';
$show_link = false;
$link_url = '';
$empty_replacement = '';
// Get field parameters
if ($this->element['class'])
{
$class = (string) $this->element['class'];
}
if ($this->element['show_link'] == 'true')
{
$show_link = true;
}
if ($this->element['url'])
{
$link_url = $this->element['url'];
}
else
{
$link_url = 'mailto:' . htmlspecialchars($this->value, ENT_COMPAT, 'UTF-8');
}
if ($this->element['empty_replacement'])
{
$empty_replacement = (string) $this->element['empty_replacement'];
}
// Get the (optionally formatted) value
if (!empty($empty_replacement) && empty($this->value))
{
$this->value = JText::_($empty_replacement);
}
$value = htmlspecialchars($this->value, ENT_COMPAT, 'UTF-8');
// Create the HTML
$html = '<span class="' . $this->id . ' ' . $class . '">';
if ($show_link)
{
$html .= '<a href="' . $link_url . '">';
}
$html .= $value;
if ($show_link)
{
$html .= '</a>';
}
$html .= '</span>';
return $html;
}
}

View File

@ -0,0 +1,134 @@
<?php
/**
* @package FrameworkOnFramework
* @subpackage form
* @copyright Copyright (C) 2010-2016 Nicholas K. Dionysopoulos / Akeeba Ltd. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
// Protect from unauthorized access
defined('F0F_INCLUDED') or die;
JFormHelper::loadFieldClass('list');
/**
* Form Field class for F0F
* Supports a generic list of options.
*
* @package FrameworkOnFramework
* @since 2.0
*/
class F0FFormFieldGroupedbutton extends JFormFieldText implements F0FFormField
{
protected $static;
protected $repeatable;
/** @var F0FTable The item being rendered in a repeatable form field */
public $item;
/** @var int A monotonically increasing number, denoting the row number in a repeatable view */
public $rowid;
/**
* Method to get certain otherwise inaccessible properties from the form field object.
*
* @param string $name The property name for which to the the value.
*
* @return mixed The property value or null.
*
* @since 2.0
*/
public function __get($name)
{
switch ($name)
{
case 'static':
if (empty($this->static))
{
$this->static = $this->getStatic();
}
return $this->static;
break;
case 'repeatable':
if (empty($this->repeatable))
{
$this->repeatable = $this->getRepeatable();
}
return $this->repeatable;
break;
default:
return parent::__get($name);
}
}
/**
* Get the rendering of this field type for static display, e.g. in a single
* item view (typically a "read" task).
*
* @since 2.0
*
* @return string The field HTML
*/
public function getStatic()
{
return $this->getInput();
}
/**
* Get the rendering of this field type for a repeatable (grid) display,
* e.g. in a view listing many item (typically a "browse" task)
*
* @since 2.0
*
* @return string The field HTML
*/
public function getRepeatable()
{
return $this->getInput();
}
/**
* Get the rendering of this field type for static display, e.g. in a single
* item view (typically a "read" task).
*
* @since 2.0
*
* @return string The field HTML
*/
public function getInput()
{
$class = $this->element['class'] ? (string) $this->element['class'] : '';
$html = '<div id="' . $this->id . '" class="btn-group ' . $class . '">';
foreach ($this->element->children() as $option)
{
$renderedAttributes = array();
foreach ($option->attributes() as $name => $value)
{
if (!is_null($value))
{
$renderedAttributes[] = $name . '="' . htmlentities($value) . '"';
}
}
$buttonXML = new SimpleXMLElement('<field ' . implode(' ', $renderedAttributes) . ' />');
$buttonField = new F0FFormFieldButton($this->form);
// Pass required objects to the field
$buttonField->item = $this->item;
$buttonField->rowid = $this->rowid;
$buttonField->setup($buttonXML, null);
$html .= $buttonField->getRepeatable();
}
$html .= '</div>';
return $html;
}
}

View File

@ -0,0 +1,185 @@
<?php
/**
* @package FrameworkOnFramework
* @subpackage form
* @copyright Copyright (C) 2010-2016 Nicholas K. Dionysopoulos / Akeeba Ltd. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
// Protect from unauthorized access
defined('F0F_INCLUDED') or die;
JFormHelper::loadFieldClass('groupedlist');
/**
* Form Field class for F0F
* Supports a generic list of options.
*
* @package FrameworkOnFramework
* @since 2.0
*/
class F0FFormFieldGroupedlist extends JFormFieldGroupedList implements F0FFormField
{
protected $static;
protected $repeatable;
/** @var F0FTable The item being rendered in a repeatable form field */
public $item;
/** @var int A monotonically increasing number, denoting the row number in a repeatable view */
public $rowid;
/**
* Method to get certain otherwise inaccessible properties from the form field object.
*
* @param string $name The property name for which to the the value.
*
* @return mixed The property value or null.
*
* @since 2.0
*/
public function __get($name)
{
switch ($name)
{
case 'static':
if (empty($this->static))
{
$this->static = $this->getStatic();
}
return $this->static;
break;
case 'repeatable':
if (empty($this->repeatable))
{
$this->repeatable = $this->getRepeatable();
}
return $this->repeatable;
break;
default:
return parent::__get($name);
}
}
/**
* Get the rendering of this field type for static display, e.g. in a single
* item view (typically a "read" task).
*
* @since 2.0
*
* @return string The field HTML
*/
public function getStatic()
{
$class = $this->element['class'] ? (string) $this->element['class'] : '';
$selected = self::getOptionName($this->getGroups(), $this->value);
if (is_null($selected))
{
$selected = array(
'group' => '',
'item' => ''
);
}
return '<span id="' . $this->id . '-group" class="fof-groupedlist-group ' . $class . '>' .
htmlspecialchars($selected['group'], ENT_COMPAT, 'UTF-8') .
'</span>' .
'<span id="' . $this->id . '-item" class="fof-groupedlist-item ' . $class . '>' .
htmlspecialchars($selected['item'], ENT_COMPAT, 'UTF-8') .
'</span>';
}
/**
* Get the rendering of this field type for a repeatable (grid) display,
* e.g. in a view listing many item (typically a "browse" task)
*
* @since 2.0
*
* @return string The field HTML
*/
public function getRepeatable()
{
$class = $this->element['class'] ? (string) $this->element['class'] : '';
$selected = self::getOptionName($this->getGroups(), $this->value);
if (is_null($selected))
{
$selected = array(
'group' => '',
'item' => ''
);
}
return '<span class="' . $this->id . '-group fof-groupedlist-group ' . $class . '">' .
htmlspecialchars($selected['group'], ENT_COMPAT, 'UTF-8') .
'</span>' .
'<span class="' . $this->id . '-item fof-groupedlist-item ' . $class . '">' .
htmlspecialchars($selected['item'], ENT_COMPAT, 'UTF-8') .
'</span>';
}
/**
* Gets the active option's label given an array of JHtml options
*
* @param array $data The JHtml options to parse
* @param mixed $selected The currently selected value
* @param string $groupKey Group name
* @param string $optKey Key name
* @param string $optText Value name
*
* @return mixed The label of the currently selected option
*/
public static function getOptionName($data, $selected = null, $groupKey = 'items', $optKey = 'value', $optText = 'text')
{
$ret = null;
foreach ($data as $dataKey => $group)
{
$label = $dataKey;
$noGroup = is_int($dataKey);
if (is_array($group))
{
$subList = $group[$groupKey];
$label = $group[$optText];
$noGroup = false;
}
elseif (is_object($group))
{
// Sub-list is in a property of an object
$subList = $group->$groupKey;
$label = $group->$optText;
$noGroup = false;
}
else
{
throw new RuntimeException('Invalid group contents.', 1);
}
if ($noGroup)
{
$label = '';
}
$match = F0FFormFieldList::getOptionName($data, $selected, $optKey, $optText);
if (!is_null($match))
{
$ret = array(
'group' => $label,
'item' => $match
);
break;
}
}
return $ret;
}
}

View File

@ -0,0 +1,93 @@
<?php
/**
* @package FrameworkOnFramework
* @subpackage form
* @copyright Copyright (C) 2010-2016 Nicholas K. Dionysopoulos / Akeeba Ltd. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
// Protect from unauthorized access
defined('F0F_INCLUDED') or die;
JFormHelper::loadFieldClass('hidden');
/**
* Form Field class for the F0F framework
* A hidden field
*
* @package FrameworkOnFramework
* @since 2.0
*/
class F0FFormFieldHidden extends JFormFieldHidden implements F0FFormField
{
protected $static;
protected $repeatable;
/** @var F0FTable The item being rendered in a repeatable form field */
public $item;
/** @var int A monotonically increasing number, denoting the row number in a repeatable view */
public $rowid;
/**
* Method to get certain otherwise inaccessible properties from the form field object.
*
* @param string $name The property name for which to the the value.
*
* @return mixed The property value or null.
*
* @since 2.0
*/
public function __get($name)
{
switch ($name)
{
case 'static':
if (empty($this->static))
{
$this->static = $this->getStatic();
}
return $this->static;
break;
case 'repeatable':
if (empty($this->repeatable))
{
$this->repeatable = $this->getRepeatable();
}
return $this->repeatable;
break;
default:
return parent::__get($name);
}
}
/**
* Get the rendering of this field type for static display, e.g. in a single
* item view (typically a "read" task).
*
* @since 2.0
*
* @return string The field HTML
*/
public function getStatic()
{
return $this->getInput();
}
/**
* Get the rendering of this field type for a repeatable (grid) display,
* e.g. in a view listing many item (typically a "browse" task)
*
* @since 2.0
*
* @return string The field HTML
*/
public function getRepeatable()
{
return $this->getInput();
}
}

View File

@ -0,0 +1,20 @@
<?php
/**
* @package FrameworkOnFramework
* @subpackage form
* @copyright Copyright (C) 2010-2016 Nicholas K. Dionysopoulos / Akeeba Ltd. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
// Protect from unauthorized access
defined('F0F_INCLUDED') or die;
/**
* Form Field class for the F0F framework
* Media selection field. This is an alias of the "media" field type.
*
* @package FrameworkOnFramework
* @since 2.0
*/
class F0FFormFieldImage extends F0FFormFieldMedia
{
}

View File

@ -0,0 +1,153 @@
<?php
/**
* @package FrameworkOnFramework
* @subpackage form
* @copyright Copyright (C) 2010-2016 Nicholas K. Dionysopoulos / Akeeba Ltd. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
// Protect from unauthorized access
defined('F0F_INCLUDED') or die;
JFormHelper::loadFieldClass('imagelist');
/**
* Form Field class for the F0F framework
* Media selection field.
*
* @package FrameworkOnFramework
* @since 2.0
*/
class F0FFormFieldImagelist extends JFormFieldImageList implements F0FFormField
{
protected $static;
protected $repeatable;
/** @var F0FTable The item being rendered in a repeatable form field */
public $item;
/** @var int A monotonically increasing number, denoting the row number in a repeatable view */
public $rowid;
/**
* Method to get certain otherwise inaccessible properties from the form field object.
*
* @param string $name The property name for which to the the value.
*
* @return mixed The property value or null.
*
* @since 2.0
*/
public function __get($name)
{
switch ($name)
{
case 'static':
if (empty($this->static))
{
$this->static = $this->getStatic();
}
return $this->static;
break;
case 'repeatable':
if (empty($this->repeatable))
{
$this->repeatable = $this->getRepeatable();
}
return $this->repeatable;
break;
default:
return parent::__get($name);
}
}
/**
* Get the rendering of this field type for static display, e.g. in a single
* item view (typically a "read" task).
*
* @since 2.0
*
* @return string The field HTML
*/
public function getStatic()
{
$imgattr = array(
'id' => $this->id
);
if ($this->element['class'])
{
$imgattr['class'] = (string) $this->element['class'];
}
if ($this->element['style'])
{
$imgattr['style'] = (string) $this->element['style'];
}
if ($this->element['width'])
{
$imgattr['width'] = (string) $this->element['width'];
}
if ($this->element['height'])
{
$imgattr['height'] = (string) $this->element['height'];
}
if ($this->element['align'])
{
$imgattr['align'] = (string) $this->element['align'];
}
if ($this->element['rel'])
{
$imgattr['rel'] = (string) $this->element['rel'];
}
if ($this->element['alt'])
{
$alt = JText::_((string) $this->element['alt']);
}
else
{
$alt = null;
}
if ($this->element['title'])
{
$imgattr['title'] = JText::_((string) $this->element['title']);
}
$path = (string) $this->element['directory'];
$path = trim($path, '/' . DIRECTORY_SEPARATOR);
if ($this->value && file_exists(JPATH_ROOT . '/' . $path . '/' . $this->value))
{
$src = F0FPlatform::getInstance()->URIroot() . '/' . $path . '/' . $this->value;
}
else
{
$src = '';
}
return JHtml::image($src, $alt, $imgattr);
}
/**
* Get the rendering of this field type for a repeatable (grid) display,
* e.g. in a view listing many item (typically a "browse" task)
*
* @since 2.0
*
* @return string The field HTML
*/
public function getRepeatable()
{
return $this->getStatic();
}
}

View File

@ -0,0 +1,101 @@
<?php
/**
* @package FrameworkOnFramework
* @subpackage form
* @copyright Copyright (C) 2010-2016 Nicholas K. Dionysopoulos / Akeeba Ltd. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
// Protect from unauthorized access
defined('F0F_INCLUDED') or die;
JFormHelper::loadFieldClass('integer');
/**
* Form Field class for the F0F framework
* Supports a one line text field.
*
* @package FrameworkOnFramework
* @since 2.0
*/
class F0FFormFieldInteger extends JFormFieldInteger implements F0FFormField
{
protected $static;
protected $repeatable;
/** @var F0FTable The item being rendered in a repeatable form field */
public $item;
/** @var int A monotonically increasing number, denoting the row number in a repeatable view */
public $rowid;
/**
* Method to get certain otherwise inaccessible properties from the form field object.
*
* @param string $name The property name for which to the the value.
*
* @return mixed The property value or null.
*
* @since 2.0
*/
public function __get($name)
{
switch ($name)
{
case 'static':
if (empty($this->static))
{
$this->static = $this->getStatic();
}
return $this->static;
break;
case 'repeatable':
if (empty($this->repeatable))
{
$this->repeatable = $this->getRepeatable();
}
return $this->repeatable;
break;
default:
return parent::__get($name);
}
}
/**
* Get the rendering of this field type for static display, e.g. in a single
* item view (typically a "read" task).
*
* @since 2.0
*
* @return string The field HTML
*/
public function getStatic()
{
$class = $this->element['class'] ? ' class="' . (string) $this->element['class'] . '"' : '';
return '<span id="' . $this->id . '" ' . $class . '>' .
htmlspecialchars($this->value, ENT_COMPAT, 'UTF-8') .
'</span>';
}
/**
* Get the rendering of this field type for a repeatable (grid) display,
* e.g. in a view listing many item (typically a "browse" task)
*
* @since 2.0
*
* @return string The field HTML
*/
public function getRepeatable()
{
$class = $this->element['class'] ? (string) $this->element['class'] : '';
return '<span class="' . $this->id . ' ' . $class . '">' .
htmlspecialchars(F0FFormFieldList::getOptionName($this->getOptions(), $this->value), ENT_COMPAT, 'UTF-8') .
'</span>';
}
}

View File

@ -0,0 +1,122 @@
<?php
/**
* @package FrameworkOnFramework
* @subpackage form
* @copyright Copyright (C) 2010-2016 Nicholas K. Dionysopoulos / Akeeba Ltd. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
// Protect from unauthorized access
defined('F0F_INCLUDED') or die;
JFormHelper::loadFieldClass('language');
/**
* Form Field class for F0F
* Available site languages
*
* @package FrameworkOnFramework
* @since 2.0
*/
class F0FFormFieldLanguage extends JFormFieldLanguage implements F0FFormField
{
protected $static;
protected $repeatable;
/** @var F0FTable The item being rendered in a repeatable form field */
public $item;
/** @var int A monotonically increasing number, denoting the row number in a repeatable view */
public $rowid;
/**
* Method to get certain otherwise inaccessible properties from the form field object.
*
* @param string $name The property name for which to the the value.
*
* @return mixed The property value or null.
*
* @since 2.0
*/
public function __get($name)
{
switch ($name)
{
case 'static':
if (empty($this->static))
{
$this->static = $this->getStatic();
}
return $this->static;
break;
case 'repeatable':
if (empty($this->repeatable))
{
$this->repeatable = $this->getRepeatable();
}
return $this->repeatable;
break;
default:
return parent::__get($name);
}
}
/**
* Method to get the field options.
*
* @since 2.0
*
* @return array The field option objects.
*/
protected function getOptions()
{
$options = parent::getOptions();
$noneoption = $this->element['none'] ? $this->element['none'] : null;
if ($noneoption)
{
array_unshift($options, JHtml::_('select.option', '*', JText::_($noneoption)));
}
return $options;
}
/**
* Get the rendering of this field type for static display, e.g. in a single
* item view (typically a "read" task).
*
* @since 2.0
*
* @return string The field HTML
*/
public function getStatic()
{
$class = $this->element['class'] ? ' class="' . (string) $this->element['class'] . '"' : '';
return '<span id="' . $this->id . '" ' . $class . '>' .
htmlspecialchars(F0FFormFieldList::getOptionName($this->getOptions(), $this->value), ENT_COMPAT, 'UTF-8') .
'</span>';
}
/**
* Get the rendering of this field type for a repeatable (grid) display,
* e.g. in a view listing many item (typically a "browse" task)
*
* @since 2.0
*
* @return string The field HTML
*/
public function getRepeatable()
{
$class = $this->element['class'] ? (string) $this->element['class'] : '';
return '<span class="' . $this->id . ' ' . $class . '">' .
htmlspecialchars(F0FFormFieldList::getOptionName($this->getOptions(), $this->value), ENT_COMPAT, 'UTF-8') .
'</span>';
}
}

View File

@ -0,0 +1,382 @@
<?php
/**
* @package FrameworkOnFramework
* @subpackage form
* @copyright Copyright (C) 2010-2016 Nicholas K. Dionysopoulos / Akeeba Ltd. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
// Protect from unauthorized access
defined('F0F_INCLUDED') or die;
JFormHelper::loadFieldClass('list');
/**
* Form Field class for F0F
* Supports a generic list of options.
*
* @package FrameworkOnFramework
* @since 2.0
*/
class F0FFormFieldList extends JFormFieldList implements F0FFormField
{
protected $static;
protected $repeatable;
/** @var F0FTable The item being rendered in a repeatable form field */
public $item;
/** @var int A monotonically increasing number, denoting the row number in a repeatable view */
public $rowid;
/**
* Method to get certain otherwise inaccessible properties from the form field object.
*
* @param string $name The property name for which to the the value.
*
* @return mixed The property value or null.
*
* @since 2.0
*/
public function __get($name)
{
switch ($name)
{
case 'static':
if (empty($this->static))
{
$this->static = $this->getStatic();
}
return $this->static;
break;
case 'repeatable':
if (empty($this->repeatable))
{
$this->repeatable = $this->getRepeatable();
}
return $this->repeatable;
break;
default:
return parent::__get($name);
}
}
/**
* Get the rendering of this field type for static display, e.g. in a single
* item view (typically a "read" task).
*
* @since 2.0
*
* @return string The field HTML
*/
public function getStatic()
{
$class = $this->element['class'] ? ' class="' . (string) $this->element['class'] . '"' : '';
return '<span id="' . $this->id . '" ' . $class . '>' .
htmlspecialchars(self::getOptionName($this->getOptions(), $this->value), ENT_COMPAT, 'UTF-8') .
'</span>';
}
/**
* Get the rendering of this field type for a repeatable (grid) display,
* e.g. in a view listing many item (typically a "browse" task)
*
* @since 2.0
*
* @return string The field HTML
*/
public function getRepeatable()
{
$show_link = false;
$link_url = '';
$class = $this->element['class'] ? (string) $this->element['class'] : '';
if ($this->element['show_link'] == 'true')
{
$show_link = true;
}
if ($this->element['url'])
{
$link_url = $this->element['url'];
}
else
{
$show_link = false;
}
if ($show_link && ($this->item instanceof F0FTable))
{
$link_url = $this->parseFieldTags($link_url);
}
else
{
$show_link = false;
}
$html = '<span class="' . $this->id . ' ' . $class . '">';
if ($show_link)
{
$html .= '<a href="' . $link_url . '">';
}
$html .= htmlspecialchars(self::getOptionName($this->getOptions(), $this->value), ENT_COMPAT, 'UTF-8');
if ($show_link)
{
$html .= '</a>';
}
$html .= '</span>';
return $html;
}
/**
* Gets the active option's label given an array of JHtml options
*
* @param array $data The JHtml options to parse
* @param mixed $selected The currently selected value
* @param string $optKey Key name
* @param string $optText Value name
*
* @return mixed The label of the currently selected option
*/
public static function getOptionName($data, $selected = null, $optKey = 'value', $optText = 'text')
{
$ret = null;
foreach ($data as $elementKey => &$element)
{
if (is_array($element))
{
$key = $optKey === null ? $elementKey : $element[$optKey];
$text = $element[$optText];
}
elseif (is_object($element))
{
$key = $optKey === null ? $elementKey : $element->$optKey;
$text = $element->$optText;
}
else
{
// This is a simple associative array
$key = $elementKey;
$text = $element;
}
if (is_null($ret))
{
$ret = $text;
}
elseif ($selected == $key)
{
$ret = $text;
}
}
return $ret;
}
/**
* Method to get the field options.
*
* Ordering is disabled by default. You can enable ordering by setting the
* 'order' element in your form field. The other order values are optional.
*
* - order What to order. Possible values: 'name' or 'value' (default = false)
* - order_dir Order direction. Possible values: 'asc' = Ascending or 'desc' = Descending (default = 'asc')
* - order_case_sensitive Order case sensitive. Possible values: 'true' or 'false' (default = false)
*
* @return array The field option objects.
*
* @since Ordering is available since F0F 2.1.b2.
*/
protected function getOptions()
{
// Ordering is disabled by default for backward compatibility
$order = false;
// Set default order direction
$order_dir = 'asc';
// Set default value for case sensitive sorting
$order_case_sensitive = false;
if ($this->element['order'] && $this->element['order'] !== 'false')
{
$order = $this->element['order'];
}
if ($this->element['order_dir'])
{
$order_dir = $this->element['order_dir'];
}
if ($this->element['order_case_sensitive'])
{
// Override default setting when the form element value is 'true'
if ($this->element['order_case_sensitive'] == 'true')
{
$order_case_sensitive = true;
}
}
// Create a $sortOptions array in order to apply sorting
$i = 0;
$sortOptions = array();
foreach ($this->element->children() as $option)
{
$name = JText::alt(trim((string) $option), preg_replace('/[^a-zA-Z0-9_\-]/', '_', $this->fieldname));
$sortOptions[$i] = new stdClass;
$sortOptions[$i]->option = $option;
$sortOptions[$i]->value = $option['value'];
$sortOptions[$i]->name = $name;
$i++;
}
// Only order if it's set
if ($order)
{
jimport('joomla.utilities.arrayhelper');
F0FUtilsArray::sortObjects($sortOptions, $order, $order_dir == 'asc' ? 1 : -1, $order_case_sensitive, false);
}
// Initialise the options
$options = array();
// Get the field $options
foreach ($sortOptions as $sortOption)
{
$option = $sortOption->option;
$name = $sortOption->name;
// Only add <option /> elements.
if ($option->getName() != 'option')
{
continue;
}
$tmp = JHtml::_('select.option', (string) $option['value'], $name, 'value', 'text', ((string) $option['disabled'] == 'true'));
// Set some option attributes.
$tmp->class = (string) $option['class'];
// Set some JavaScript option attributes.
$tmp->onclick = (string) $option['onclick'];
// Add the option object to the result set.
$options[] = $tmp;
}
// Do we have a class and method source for our options?
$source_file = empty($this->element['source_file']) ? '' : (string) $this->element['source_file'];
$source_class = empty($this->element['source_class']) ? '' : (string) $this->element['source_class'];
$source_method = empty($this->element['source_method']) ? '' : (string) $this->element['source_method'];
$source_key = empty($this->element['source_key']) ? '*' : (string) $this->element['source_key'];
$source_value = empty($this->element['source_value']) ? '*' : (string) $this->element['source_value'];
$source_translate = empty($this->element['source_translate']) ? 'true' : (string) $this->element['source_translate'];
$source_translate = in_array(strtolower($source_translate), array('true','yes','1','on')) ? true : false;
$source_format = empty($this->element['source_format']) ? '' : (string) $this->element['source_format'];
if ($source_class && $source_method)
{
// Maybe we have to load a file?
if (!empty($source_file))
{
$source_file = F0FTemplateUtils::parsePath($source_file, true);
if (F0FPlatform::getInstance()->getIntegrationObject('filesystem')->fileExists($source_file))
{
include_once $source_file;
}
}
// Make sure the class exists
if (class_exists($source_class, true))
{
// ...and so does the option
if (in_array($source_method, get_class_methods($source_class)))
{
// Get the data from the class
if ($source_format == 'optionsobject')
{
$options = array_merge($options, $source_class::$source_method());
}
else
{
// Get the data from the class
$source_data = $source_class::$source_method();
// Loop through the data and prime the $options array
foreach ($source_data as $k => $v)
{
$key = (empty($source_key) || ($source_key == '*')) ? $k : $v[$source_key];
$value = (empty($source_value) || ($source_value == '*')) ? $v : $v[$source_value];
if ($source_translate)
{
$value = JText::_($value);
}
$options[] = JHtml::_('select.option', $key, $value, 'value', 'text');
}
}
}
}
}
reset($options);
return $options;
}
/**
* Replace string with tags that reference fields
*
* @param string $text Text to process
*
* @return string Text with tags replace
*/
protected function parseFieldTags($text)
{
$ret = $text;
// Replace [ITEM:ID] in the URL with the item's key value (usually:
// the auto-incrementing numeric ID)
$keyfield = $this->item->getKeyName();
$replace = $this->item->$keyfield;
$ret = str_replace('[ITEM:ID]', $replace, $ret);
// Replace the [ITEMID] in the URL with the current Itemid parameter
$ret = str_replace('[ITEMID]', JFactory::getApplication()->input->getInt('Itemid', 0), $ret);
// Replace other field variables in the URL
$fields = $this->item->getTableFields();
foreach ($fields as $fielddata)
{
$fieldname = $fielddata->Field;
if (empty($fieldname))
{
$fieldname = $fielddata->column_name;
}
$search = '[ITEM:' . strtoupper($fieldname) . ']';
$replace = $this->item->$fieldname;
$ret = str_replace($search, $replace, $ret);
}
return $ret;
}
}

View File

@ -0,0 +1,150 @@
<?php
/**
* @package FrameworkOnFramework
* @subpackage form
* @copyright Copyright (C) 2010-2016 Nicholas K. Dionysopoulos / Akeeba Ltd. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
// Protect from unauthorized access
defined('F0F_INCLUDED') or die;
JFormHelper::loadFieldClass('media');
/**
* Form Field class for the F0F framework
* Media selection field.
*
* @package FrameworkOnFramework
* @since 2.0
*/
class F0FFormFieldMedia extends JFormFieldMedia implements F0FFormField
{
protected $static;
protected $repeatable;
/** @var F0FTable The item being rendered in a repeatable form field */
public $item;
/** @var int A monotonically increasing number, denoting the row number in a repeatable view */
public $rowid;
/**
* Method to get certain otherwise inaccessible properties from the form field object.
*
* @param string $name The property name for which to the the value.
*
* @return mixed The property value or null.
*
* @since 2.0
*/
public function __get($name)
{
switch ($name)
{
case 'static':
if (empty($this->static))
{
$this->static = $this->getStatic();
}
return $this->static;
break;
case 'repeatable':
if (empty($this->repeatable))
{
$this->repeatable = $this->getRepeatable();
}
return $this->repeatable;
break;
default:
return parent::__get($name);
}
}
/**
* Get the rendering of this field type for static display, e.g. in a single
* item view (typically a "read" task).
*
* @since 2.0
*
* @return string The field HTML
*/
public function getStatic()
{
$imgattr = array(
'id' => $this->id
);
if ($this->element['class'])
{
$imgattr['class'] = (string) $this->element['class'];
}
if ($this->element['style'])
{
$imgattr['style'] = (string) $this->element['style'];
}
if ($this->element['width'])
{
$imgattr['width'] = (string) $this->element['width'];
}
if ($this->element['height'])
{
$imgattr['height'] = (string) $this->element['height'];
}
if ($this->element['align'])
{
$imgattr['align'] = (string) $this->element['align'];
}
if ($this->element['rel'])
{
$imgattr['rel'] = (string) $this->element['rel'];
}
if ($this->element['alt'])
{
$alt = JText::_((string) $this->element['alt']);
}
else
{
$alt = null;
}
if ($this->element['title'])
{
$imgattr['title'] = JText::_((string) $this->element['title']);
}
if ($this->value && file_exists(JPATH_ROOT . '/' . $this->value))
{
$src = F0FPlatform::getInstance()->URIroot() . $this->value;
}
else
{
$src = '';
}
return JHtml::image($src, $alt, $imgattr);
}
/**
* Get the rendering of this field type for a repeatable (grid) display,
* e.g. in a view listing many item (typically a "browse" task)
*
* @since 2.0
*
* @return string The field HTML
*/
public function getRepeatable()
{
return $this->getStatic();
}
}

View File

@ -0,0 +1,290 @@
<?php
/**
* @package FrameworkOnFramework
* @subpackage form
* @copyright Copyright (C) 2010-2016 Nicholas K. Dionysopoulos / Akeeba Ltd. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
// Protect from unauthorized access
defined('F0F_INCLUDED') or die;
JFormHelper::loadFieldClass('list');
/**
* Form Field class for F0F
* Generic list from a model's results
*
* @package FrameworkOnFramework
* @since 2.0
*/
class F0FFormFieldModel extends F0FFormFieldList implements F0FFormField
{
protected $static;
protected $repeatable;
/**
* Method to get certain otherwise inaccessible properties from the form field object.
*
* @param string $name The property name for which to the the value.
*
* @return mixed The property value or null.
*
* @since 2.0
*/
public function __get($name)
{
switch ($name)
{
case 'static':
if (empty($this->static))
{
$this->static = $this->getStatic();
}
return $this->static;
break;
case 'repeatable':
if (empty($this->repeatable))
{
$this->repeatable = $this->getRepeatable();
}
return $this->repeatable;
break;
default:
return parent::__get($name);
}
}
/**
* Get the rendering of this field type for static display, e.g. in a single
* item view (typically a "read" task).
*
* @since 2.0
*
* @return string The field HTML
*/
public function getStatic()
{
$class = $this->element['class'] ? ' class="' . (string) $this->element['class'] . '"' : '';
return '<span id="' . $this->id . '" ' . $class . '>' .
htmlspecialchars(F0FFormFieldList::getOptionName($this->getOptions(), $this->value), ENT_COMPAT, 'UTF-8') .
'</span>';
}
/**
* Get the rendering of this field type for a repeatable (grid) display,
* e.g. in a view listing many item (typically a "browse" task)
*
* @since 2.0
*
* @return string The field HTML
*/
public function getRepeatable()
{
$class = $this->id;
$format_string = '';
$show_link = false;
$link_url = '';
$empty_replacement = '';
// Get field parameters
if ($this->element['class'])
{
$class = (string) $this->element['class'];
}
if ($this->element['format'])
{
$format_string = (string) $this->element['format'];
}
if ($this->element['show_link'] == 'true')
{
$show_link = true;
}
if ($this->element['url'])
{
$link_url = $this->element['url'];
}
else
{
$show_link = false;
}
if ($show_link && ($this->item instanceof F0FTable))
{
$link_url = $this->parseFieldTags($link_url);
}
else
{
$show_link = false;
}
if ($this->element['empty_replacement'])
{
$empty_replacement = (string) $this->element['empty_replacement'];
}
$value = F0FFormFieldList::getOptionName($this->getOptions(), $this->value);
// Get the (optionally formatted) value
if (!empty($empty_replacement) && empty($value))
{
$value = JText::_($empty_replacement);
}
if (empty($format_string))
{
$value = htmlspecialchars($value, ENT_COMPAT, 'UTF-8');
}
else
{
$value = sprintf($format_string, $value);
}
// Create the HTML
$html = '<span class="' . $class . '">';
if ($show_link)
{
$html .= '<a href="' . $link_url . '">';
}
$html .= $value;
if ($show_link)
{
$html .= '</a>';
}
$html .= '</span>';
return $html;
}
/**
* Method to get the field options.
*
* @return array The field option objects.
*/
protected function getOptions()
{
$options = array();
// Initialize some field attributes.
$key = $this->element['key_field'] ? (string) $this->element['key_field'] : 'value';
$value = $this->element['value_field'] ? (string) $this->element['value_field'] : (string) $this->element['name'];
$translate = $this->element['translate'] ? (string) $this->element['translate'] : false;
$applyAccess = $this->element['apply_access'] ? (string) $this->element['apply_access'] : 'false';
$modelName = (string) $this->element['model'];
$nonePlaceholder = (string) $this->element['none'];
if (!empty($nonePlaceholder))
{
$options[] = JHtml::_('select.option', null, JText::_($nonePlaceholder));
}
// Process field atrtibutes
$applyAccess = strtolower($applyAccess);
$applyAccess = in_array($applyAccess, array('yes', 'on', 'true', '1'));
// Explode model name into model name and prefix
$parts = F0FInflector::explode($modelName);
$mName = ucfirst(array_pop($parts));
$mPrefix = F0FInflector::implode($parts);
// Get the model object
$config = array('savestate' => 0);
$model = F0FModel::getTmpInstance($mName, $mPrefix, $config);
if ($applyAccess)
{
$model->applyAccessFiltering();
}
// Process state variables
foreach ($this->element->children() as $stateoption)
{
// Only add <option /> elements.
if ($stateoption->getName() != 'state')
{
continue;
}
$stateKey = (string) $stateoption['key'];
$stateValue = (string) $stateoption;
$model->setState($stateKey, $stateValue);
}
// Set the query and get the result list.
$items = $model->getItemList(true);
// Build the field options.
if (!empty($items))
{
foreach ($items as $item)
{
if ($translate == true)
{
$options[] = JHtml::_('select.option', $item->$key, JText::_($item->$value));
}
else
{
$options[] = JHtml::_('select.option', $item->$key, $item->$value);
}
}
}
// Merge any additional options in the XML definition.
$options = array_merge(parent::getOptions(), $options);
return $options;
}
/**
* Replace string with tags that reference fields
*
* @param string $text Text to process
*
* @return string Text with tags replace
*/
protected function parseFieldTags($text)
{
$ret = $text;
// Replace [ITEM:ID] in the URL with the item's key value (usually:
// the auto-incrementing numeric ID)
$keyfield = $this->item->getKeyName();
$replace = $this->item->$keyfield;
$ret = str_replace('[ITEM:ID]', $replace, $ret);
// Replace the [ITEMID] in the URL with the current Itemid parameter
$ret = str_replace('[ITEMID]', JFactory::getApplication()->input->getInt('Itemid', 0), $ret);
// Replace other field variables in the URL
$fields = $this->item->getTableFields();
foreach ($fields as $fielddata)
{
$fieldname = $fielddata->Field;
if (empty($fieldname))
{
$fieldname = $fielddata->column_name;
}
$search = '[ITEM:' . strtoupper($fieldname) . ']';
$replace = $this->item->$fieldname;
$ret = str_replace($search, $replace, $ret);
}
return $ret;
}
}

View File

@ -0,0 +1,218 @@
<?php
/**
* @package FrameworkOnFramework
* @subpackage form
* @copyright Copyright (C) 2010-2016 Nicholas K. Dionysopoulos / Akeeba Ltd. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
// Protect from unauthorized access
defined('F0F_INCLUDED') or die;
/**
* Form Field class for F0F
* Renders the row ordering interface checkbox in browse views
*
* @package FrameworkOnFramework
* @since 2.0
*/
class F0FFormFieldOrdering extends JFormField implements F0FFormField
{
protected $static;
protected $repeatable;
/** @var F0FTable The item being rendered in a repeatable form field */
public $item;
/** @var int A monotonically increasing number, denoting the row number in a repeatable view */
public $rowid;
/**
* Method to get certain otherwise inaccessible properties from the form field object.
*
* @param string $name The property name for which to the the value.
*
* @return mixed The property value or null.
*
* @since 2.0
*/
public function __get($name)
{
switch ($name)
{
case 'static':
if (empty($this->static))
{
$this->static = $this->getStatic();
}
return $this->static;
break;
case 'repeatable':
if (empty($this->repeatable))
{
$this->repeatable = $this->getRepeatable();
}
return $this->repeatable;
break;
default:
return parent::__get($name);
}
}
/**
* Method to get the field input markup for this field type.
*
* @since 2.0
*
* @return string The field input markup.
*/
protected function getInput()
{
$html = array();
$attr = '';
// Initialize some field attributes.
$attr .= !empty($this->class) ? ' class="' . $this->class . '"' : '';
$attr .= $this->disabled ? ' disabled' : '';
$attr .= !empty($this->size) ? ' size="' . $this->size . '"' : '';
// Initialize JavaScript field attributes.
$attr .= !empty($this->onchange) ? ' onchange="' . $this->onchange . '"' : '';
$this->item = $this->form->getModel()->getItem();
$keyfield = $this->item->getKeyName();
$itemId = $this->item->$keyfield;
$query = $this->getQuery();
// Create a read-only list (no name) with a hidden input to store the value.
if ($this->readonly)
{
$html[] = JHtml::_('list.ordering', '', $query, trim($attr), $this->value, $itemId ? 0 : 1);
$html[] = '<input type="hidden" name="' . $this->name . '" value="' . $this->value . '"/>';
}
else
{
// Create a regular list.
$html[] = JHtml::_('list.ordering', $this->name, $query, trim($attr), $this->value, $itemId ? 0 : 1);
}
return implode($html);
}
/**
* Get the rendering of this field type for static display, e.g. in a single
* item view (typically a "read" task).
*
* @since 2.0
*
* @return string The field HTML
*/
public function getStatic()
{
throw new Exception(__CLASS__ . ' cannot be used in single item display forms');
}
/**
* Get the rendering of this field type for a repeatable (grid) display,
* e.g. in a view listing many item (typically a "browse" task)
*
* @since 2.0
*
* @return string The field HTML
*/
public function getRepeatable()
{
if (!($this->item instanceof F0FTable))
{
throw new Exception(__CLASS__ . ' needs a F0FTable to act upon');
}
$class = isset($this->element['class']) ? $this->element['class'] : 'input-mini';
$icon = isset($this->element['icon']) ? $this->element['icon'] : 'icon-menu';
$html = '';
$view = $this->form->getView();
$ordering = $view->getLists()->order == 'ordering';
if (!$view->hasAjaxOrderingSupport())
{
// Ye olde Joomla! 2.5 method
$disabled = $ordering ? '' : 'disabled="disabled"';
$html .= '<span>';
$html .= $view->pagination->orderUpIcon($this->rowid, true, 'orderup', 'Move Up', $ordering);
$html .= '</span><span>';
$html .= $view->pagination->orderDownIcon($this->rowid, $view->pagination->total, true, 'orderdown', 'Move Down', $ordering);
$html .= '</span>';
$html .= '<input type="text" name="order[]" size="5" value="' . $this->value . '" ' . $disabled;
$html .= 'class="text-area-order" style="text-align: center" />';
}
else
{
// The modern drag'n'drop method
if ($view->getPerms()->editstate)
{
$disableClassName = '';
$disabledLabel = '';
$hasAjaxOrderingSupport = $view->hasAjaxOrderingSupport();
if (!$hasAjaxOrderingSupport['saveOrder'])
{
$disabledLabel = JText::_('JORDERINGDISABLED');
$disableClassName = 'inactive tip-top';
}
$orderClass = $ordering ? 'order-enabled' : 'order-disabled';
$html .= '<div class="' . $orderClass . '">';
$html .= '<span class="sortable-handler ' . $disableClassName . '" title="' . $disabledLabel . '" rel="tooltip">';
$html .= '<i class="' . $icon . '"></i>';
$html .= '</span>';
if ($ordering)
{
$html .= '<input type="text" name="order[]" size="5" class="' . $class . ' text-area-order" value="' . $this->value . '" />';
}
$html .= '</div>';
}
else
{
$html .= '<span class="sortable-handler inactive" >';
$html .= '<i class="' . $icon . '"></i>';
$html .= '</span>';
}
}
return $html;
}
/**
* Builds the query for the ordering list.
*
* @since 2.3.2
*
* @return F0FDatabaseQuery The query for the ordering form field
*/
protected function getQuery()
{
$ordering = $this->name;
$title = $this->element['ordertitle'] ? (string) $this->element['ordertitle'] : $this->item->getColumnAlias('title');
$db = F0FPlatform::getInstance()->getDbo();
$query = $db->getQuery(true);
$query->select(array($db->quoteName($ordering, 'value'), $db->quoteName($title, 'text')))
->from($db->quoteName($this->item->getTableName()))
->order($ordering);
return $query;
}
}

View File

@ -0,0 +1,101 @@
<?php
/**
* @package FrameworkOnFramework
* @subpackage form
* @copyright Copyright (C) 2010-2016 Nicholas K. Dionysopoulos / Akeeba Ltd. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
// Protect from unauthorized access
defined('F0F_INCLUDED') or die;
JFormHelper::loadFieldClass('password');
/**
* Form Field class for the F0F framework
* Supports a one line text field.
*
* @package FrameworkOnFramework
* @since 2.0
*/
class F0FFormFieldPassword extends JFormFieldPassword implements F0FFormField
{
protected $static;
protected $repeatable;
/** @var F0FTable The item being rendered in a repeatable form field */
public $item;
/** @var int A monotonically increasing number, denoting the row number in a repeatable view */
public $rowid;
/**
* Method to get certain otherwise inaccessible properties from the form field object.
*
* @param string $name The property name for which to the the value.
*
* @return mixed The property value or null.
*
* @since 2.0
*/
public function __get($name)
{
switch ($name)
{
case 'static':
if (empty($this->static))
{
$this->static = $this->getStatic();
}
return $this->static;
break;
case 'repeatable':
if (empty($this->repeatable))
{
$this->repeatable = $this->getRepeatable();
}
return $this->repeatable;
break;
default:
return parent::__get($name);
}
}
/**
* Get the rendering of this field type for static display, e.g. in a single
* item view (typically a "read" task).
*
* @since 2.0
*
* @return string The field HTML
*/
public function getStatic()
{
$class = $this->element['class'] ? ' class="' . (string) $this->element['class'] . '"' : '';
return '<span id="' . $this->id . '" ' . $class . '>' .
htmlspecialchars($this->value, ENT_COMPAT, 'UTF-8') .
'</span>';
}
/**
* Get the rendering of this field type for a repeatable (grid) display,
* e.g. in a view listing many item (typically a "browse" task)
*
* @since 2.0
*
* @return string The field HTML
*/
public function getRepeatable()
{
$class = $this->element['class'] ? (string) $this->element['class'] : '';
return '<span class="' . $this->id . ' ' . $class . '">' .
htmlspecialchars(F0FFormFieldList::getOptionName($this->getOptions(), $this->value), ENT_COMPAT, 'UTF-8') .
'</span>';
}
}

View File

@ -0,0 +1,101 @@
<?php
/**
* @package FrameworkOnFramework
* @subpackage form
* @copyright Copyright (C) 2010-2016 Nicholas K. Dionysopoulos / Akeeba Ltd. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
// Protect from unauthorized access
defined('F0F_INCLUDED') or die;
JFormHelper::loadFieldClass('plugins');
/**
* Form Field class for F0F
* Plugins installed on the site
*
* @package FrameworkOnFramework
* @since 2.0
*/
class F0FFormFieldPlugins extends JFormFieldPlugins implements F0FFormField
{
protected $static;
protected $repeatable;
/** @var F0FTable The item being rendered in a repeatable form field */
public $item;
/** @var int A monotonically increasing number, denoting the row number in a repeatable view */
public $rowid;
/**
* Method to get certain otherwise inaccessible properties from the form field object.
*
* @param string $name The property name for which to the the value.
*
* @return mixed The property value or null.
*
* @since 2.0
*/
public function __get($name)
{
switch ($name)
{
case 'static':
if (empty($this->static))
{
$this->static = $this->getStatic();
}
return $this->static;
break;
case 'repeatable':
if (empty($this->repeatable))
{
$this->repeatable = $this->getRepeatable();
}
return $this->repeatable;
break;
default:
return parent::__get($name);
}
}
/**
* Get the rendering of this field type for static display, e.g. in a single
* item view (typically a "read" task).
*
* @since 2.0
*
* @return string The field HTML
*/
public function getStatic()
{
$class = $this->element['class'] ? ' class="' . (string) $this->element['class'] . '"' : '';
return '<span id="' . $this->id . '" ' . $class . '>' .
htmlspecialchars(F0FFormFieldList::getOptionName($this->getOptions(), $this->value), ENT_COMPAT, 'UTF-8') .
'</span>';
}
/**
* Get the rendering of this field type for a repeatable (grid) display,
* e.g. in a view listing many item (typically a "browse" task)
*
* @since 2.0
*
* @return string The field HTML
*/
public function getRepeatable()
{
$class = $this->element['class'] ? (string) $this->element['class'] : '';
return '<span class="' . $this->id . ' ' . $class . '">' .
htmlspecialchars(F0FFormFieldList::getOptionName($this->getOptions(), $this->value), ENT_COMPAT, 'UTF-8') .
'</span>';
}
}

View File

@ -0,0 +1,216 @@
<?php
/**
* @package FrameworkOnFramework
* @subpackage form
* @copyright Copyright (C) 2010-2016 Nicholas K. Dionysopoulos / Akeeba Ltd. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
// Protect from unauthorized access
defined('F0F_INCLUDED') or die;
JFormHelper::loadFieldClass('list');
/**
* Form Field class for F0F
* Supports a generic list of options.
*
* @package FrameworkOnFramework
* @since 2.0
*/
class F0FFormFieldPublished extends JFormFieldList implements F0FFormField
{
protected $static;
protected $repeatable;
/** @var F0FTable The item being rendered in a repeatable form field */
public $item;
/** @var int A monotonically increasing number, denoting the row number in a repeatable view */
public $rowid;
/**
* Method to get certain otherwise inaccessible properties from the form field object.
*
* @param string $name The property name for which to the the value.
*
* @return mixed The property value or null.
*
* @since 2.0
*/
public function __get($name)
{
switch ($name)
{
case 'static':
if (empty($this->static))
{
$this->static = $this->getStatic();
}
return $this->static;
break;
case 'repeatable':
if (empty($this->repeatable))
{
$this->repeatable = $this->getRepeatable();
}
return $this->repeatable;
break;
default:
return parent::__get($name);
}
}
/**
* Method to get the field options.
*
* @since 2.0
*
* @return array The field option objects.
*/
protected function getOptions()
{
$options = parent::getOptions();
if (!empty($options))
{
return $options;
}
// If no custom options were defined let's figure out which ones of the
// defaults we shall use...
$config = array(
'published' => 1,
'unpublished' => 1,
'archived' => 0,
'trash' => 0,
'all' => 0,
);
$configMap = array(
'show_published' => array('published', 1),
'show_unpublished' => array('unpublished', 1),
'show_archived' => array('archived', 0),
'show_trash' => array('trash', 0),
'show_all' => array('all', 0),
);
foreach ($configMap as $attribute => $preferences)
{
list($configKey, $default) = $preferences;
switch (strtolower($this->element[$attribute]))
{
case 'true':
case '1':
case 'yes':
$config[$configKey] = true;
case 'false':
case '0':
case 'no':
$config[$configKey] = false;
default:
$config[$configKey] = $default;
}
}
if ($config['published'])
{
$stack[] = JHtml::_('select.option', '1', JText::_('JPUBLISHED'));
}
if ($config['unpublished'])
{
$stack[] = JHtml::_('select.option', '0', JText::_('JUNPUBLISHED'));
}
if ($config['archived'])
{
$stack[] = JHtml::_('select.option', '2', JText::_('JARCHIVED'));
}
if ($config['trash'])
{
$stack[] = JHtml::_('select.option', '-2', JText::_('JTRASHED'));
}
if ($config['all'])
{
$stack[] = JHtml::_('select.option', '*', JText::_('JALL'));
}
return $stack;
}
/**
* Get the rendering of this field type for static display, e.g. in a single
* item view (typically a "read" task).
*
* @since 2.0
*
* @return string The field HTML
*/
public function getStatic()
{
$class = $this->element['class'] ? ' class="' . (string) $this->element['class'] . '"' : '';
return '<span id="' . $this->id . '" ' . $class . '>' .
htmlspecialchars(F0FFormFieldList::getOptionName($this->getOptions(), $this->value), ENT_COMPAT, 'UTF-8') .
'</span>';
}
/**
* Get the rendering of this field type for a repeatable (grid) display,
* e.g. in a view listing many item (typically a "browse" task)
*
* @since 2.0
*
* @return string The field HTML
*/
public function getRepeatable()
{
if (!($this->item instanceof F0FTable))
{
throw new Exception(__CLASS__ . ' needs a F0FTable to act upon');
}
// Initialise
$prefix = '';
$checkbox = 'cb';
$publish_up = null;
$publish_down = null;
$enabled = true;
// Get options
if ($this->element['prefix'])
{
$prefix = (string) $this->element['prefix'];
}
if ($this->element['checkbox'])
{
$checkbox = (string) $this->element['checkbox'];
}
if ($this->element['publish_up'])
{
$publish_up = (string) $this->element['publish_up'];
}
if ($this->element['publish_down'])
{
$publish_down = (string) $this->element['publish_down'];
}
// @todo Enforce ACL checks to determine if the field should be enabled or not
// Get the HTML
return JHTML::_('jgrid.published', $this->value, $this->rowid, $prefix, $enabled, $checkbox, $publish_up, $publish_down);
}
}

View File

@ -0,0 +1,101 @@
<?php
/**
* @package FrameworkOnFramework
* @subpackage form
* @copyright Copyright (C) 2010-2016 Nicholas K. Dionysopoulos / Akeeba Ltd. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
// Protect from unauthorized access
defined('F0F_INCLUDED') or die;
JFormHelper::loadFieldClass('radio');
/**
* Form Field class for F0F
* Radio selection list
*
* @package FrameworkOnFramework
* @since 2.0
*/
class F0FFormFieldRadio extends JFormFieldRadio implements F0FFormField
{
protected $static;
protected $repeatable;
/** @var F0FTable The item being rendered in a repeatable form field */
public $item;
/** @var int A monotonically increasing number, denoting the row number in a repeatable view */
public $rowid;
/**
* Method to get certain otherwise inaccessible properties from the form field object.
*
* @param string $name The property name for which to the the value.
*
* @return mixed The property value or null.
*
* @since 2.0
*/
public function __get($name)
{
switch ($name)
{
case 'static':
if (empty($this->static))
{
$this->static = $this->getStatic();
}
return $this->static;
break;
case 'repeatable':
if (empty($this->repeatable))
{
$this->repeatable = $this->getRepeatable();
}
return $this->repeatable;
break;
default:
return parent::__get($name);
}
}
/**
* Get the rendering of this field type for static display, e.g. in a single
* item view (typically a "read" task).
*
* @since 2.0
*
* @return string The field HTML
*/
public function getStatic()
{
$class = $this->element['class'] ? ' class="' . (string) $this->element['class'] . '"' : '';
return '<span id="' . $this->id . '" ' . $class . '>' .
htmlspecialchars(F0FFormFieldList::getOptionName($this->getOptions(), $this->value), ENT_COMPAT, 'UTF-8') .
'</span>';
}
/**
* Get the rendering of this field type for a repeatable (grid) display,
* e.g. in a view listing many item (typically a "browse" task)
*
* @since 2.0
*
* @return string The field HTML
*/
public function getRepeatable()
{
$class = $this->element['class'] ? (string) $this->element['class'] : '';
return '<span class="' . $this->id . ' ' . $class . '">' .
htmlspecialchars(F0FFormFieldList::getOptionName($this->getOptions(), $this->value), ENT_COMPAT, 'UTF-8') .
'</span>';
}
}

View File

@ -0,0 +1,194 @@
<?php
/**
* @package FrameworkOnFramework
* @subpackage form
* @copyright Copyright (C) 2010-2016 Nicholas K. Dionysopoulos / Akeeba Ltd. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
// Protect from unauthorized access
defined('F0F_INCLUDED') or die;
/**
* Form Field class for F0F
* Relation list
*
* @package FrameworkOnFramework
* @since 2.0
*/
class F0FFormFieldRelation extends F0FFormFieldList
{
/**
* Get the rendering of this field type for static display, e.g. in a single
* item view (typically a "read" task).
*
* @since 2.0
*
* @return string The field HTML
*/
public function getStatic() {
return $this->getRepeatable();
}
/**
* Get the rendering of this field type for a repeatable (grid) display,
* e.g. in a view listing many item (typically a "browse" task)
*
* @since 2.0
*
* @return string The field HTML
*/
public function getRepeatable()
{
$class = $this->element['class'] ? (string) $this->element['class'] : $this->id;
$relationclass = $this->element['relationclass'] ? (string) $this->element['relationclass'] : '';
$value_field = $this->element['value_field'] ? (string) $this->element['value_field'] : 'title';
$translate = $this->element['translate'] ? (string) $this->element['translate'] : false;
$link_url = $this->element['url'] ? (string) $this->element['url'] : false;
if (!($link_url && $this->item instanceof F0FTable))
{
$link_url = false;
}
if ($this->element['empty_replacement'])
{
$empty_replacement = (string) $this->element['empty_replacement'];
}
$relationName = F0FInflector::pluralize($this->name);
$relations = $this->item->getRelations()->getMultiple($relationName);
foreach ($relations as $relation) {
$html = '<span class="' . $relationclass . '">';
if ($link_url)
{
$keyfield = $relation->getKeyName();
$this->_relationId = $relation->$keyfield;
$url = $this->parseFieldTags($link_url);
$html .= '<a href="' . $url . '">';
}
$value = $relation->get($relation->getColumnAlias($value_field));
// Get the (optionally formatted) value
if (!empty($empty_replacement) && empty($value))
{
$value = JText::_($empty_replacement);
}
if ($translate == true)
{
$html .= JText::_($value);
}
else
{
$html .= $value;
}
if ($link_url)
{
$html .= '</a>';
}
$html .= '</span>';
$rels[] = $html;
}
$html = '<span class="' . $class . '">';
$html .= implode(', ', $rels);
$html .= '</span>';
return $html;
}
/**
* Method to get the field options.
*
* @return array The field option objects.
*/
protected function getOptions()
{
$options = array();
$this->value = array();
$value_field = $this->element['value_field'] ? (string) $this->element['value_field'] : 'title';
$input = new F0FInput;
$component = ucfirst(str_replace('com_', '', $input->getString('option')));
$view = ucfirst($input->getString('view'));
$relation = F0FInflector::pluralize((string) $this->element['name']);
$model = F0FModel::getTmpInstance(ucfirst($relation), $component . 'Model');
$table = $model->getTable();
$key = $table->getKeyName();
$value = $table->getColumnAlias($value_field);
foreach ($model->getItemList(true) as $option)
{
$options[] = JHtml::_('select.option', $option->$key, $option->$value);
}
if ($id = F0FModel::getAnInstance($view)->getId())
{
$table = F0FTable::getInstance($view, $component . 'Table');
$table->load($id);
$relations = $table->getRelations()->getMultiple($relation);
foreach ($relations as $item)
{
$this->value[] = $item->getId();
}
}
return $options;
}
/**
* Replace string with tags that reference fields
*
* @param string $text Text to process
*
* @return string Text with tags replace
*/
protected function parseFieldTags($text)
{
$ret = $text;
// Replace [ITEM:ID] in the URL with the item's key value (usually:
// the auto-incrementing numeric ID)
$keyfield = $this->item->getKeyName();
$replace = $this->item->$keyfield;
$ret = str_replace('[ITEM:ID]', $replace, $ret);
// Replace the [ITEMID] in the URL with the current Itemid parameter
$ret = str_replace('[ITEMID]', JFactory::getApplication()->input->getInt('Itemid', 0), $ret);
// Replace the [RELATION:ID] in the URL with the relation's key value
$ret = str_replace('[RELATION:ID]', $this->_relationId, $ret);
// Replace other field variables in the URL
$fields = $this->item->getTableFields();
foreach ($fields as $fielddata)
{
$fieldname = $fielddata->Field;
if (empty($fieldname))
{
$fieldname = $fielddata->column_name;
}
$search = '[ITEM:' . strtoupper($fieldname) . ']';
$replace = $this->item->$fieldname;
$ret = str_replace($search, $replace, $ret);
}
return $ret;
}
}

View File

@ -0,0 +1,630 @@
<?php
/**
* @package FrameworkOnFramework
* @subpackage form
* @copyright Copyright (C) 2010-2016 Nicholas K. Dionysopoulos / Akeeba Ltd. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
// Protect from unauthorized access
defined('F0F_INCLUDED') or die;
JFormHelper::loadFieldClass('rules');
/**
* Form Field class for F0F
* Joomla! ACL Rules
*
* @package FrameworkOnFramework
* @since 2.1
*/
class F0FFormFieldRules extends JFormFieldRules implements F0FFormField
{
protected $static;
protected $repeatable;
/** @var F0FTable The item being rendered in a repeatable form field */
public $item;
/** @var int A monotonically increasing number, denoting the row number in a repeatable view */
public $rowid;
/**
* Method to get certain otherwise inaccessible properties from the form field object.
*
* @param string $name The property name for which to the the value.
*
* @return mixed The property value or null.
*
* @since 2.0
*/
public function __get($name)
{
switch ($name)
{
// This field cannot provide a static display
case 'static':
return '';
break;
// This field cannot provide a repeateable display
case 'repeatable':
return '';
break;
default:
return parent::__get($name);
}
}
/**
* Get the rendering of this field type for static display, e.g. in a single
* item view (typically a "read" task).
*
* @since 2.0
*
* @return string The field HTML
*/
public function getStatic()
{
return '';
}
/**
* Get the rendering of this field type for a repeatable (grid) display,
* e.g. in a view listing many item (typically a "browse" task)
*
* @since 2.1
*
* @return string The field HTML
*/
public function getRepeatable()
{
return '';
}
/**
* At the timing of this writing (2013-12-03), the Joomla "rules" field is buggy. When you are
* dealing with a new record it gets the default permissions from the root asset node, which
* is fine for the default permissions of Joomla articles, but unsuitable for third party software.
* We had to copy & paste the whole code, since we can't "inject" the correct asset id if one is
* not found. Our fixes are surrounded by `F0F Library fix` remarks.
*
* @return string The input field's HTML for this field type
*/
public function getInput()
{
if (version_compare(JVERSION, '3.0', 'ge'))
{
return $this->getInput3x();
}
else
{
return $this->getInput25();
}
}
protected function getInput25()
{
JHtml::_('behavior.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 = F0FPlatform::getInstance()->getDbo();
$query = $db->getQuery(true);
$query->select($db->quoteName('id'));
$query->from($db->quoteName('#__assets'));
$query->where($db->quoteName('name') . ' = ' . $db->quote($component));
$db->setQuery($query);
$assetId = (int) $db->loadResult();
if ($error = $db->getErrorMsg())
{
JError::raiseNotice(500, $error);
}
}
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);
// ==== F0F Library fix - Start ====
// If there is no assetId (let's say we are dealing with a new record), let's ask the table
// to give it to us. Here you should implement your logic (ie getting default permissions from
// the component or from the category)
if(!$assetId)
{
$table = $this->form->getModel()->getTable();
$assetId = $table->getAssetParentId();
}
// ==== F0F Library fix - End ====
}
// Use the compact form for the content rules (deprecated).
//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();
// Build the form control.
$curLevel = 0;
// Prepare output
$html = array();
$html[] = '<div id="permissions-sliders" class="pane-sliders">';
$html[] = '<p class="rule-desc">' . JText::_('JLIB_RULES_SETTINGS_DESC') . '</p>';
$html[] = '<ul id="rules">';
// Start a row for each user group.
foreach ($groups as $group)
{
$difLevel = $group->level - $curLevel;
if ($difLevel > 0)
{
$html[] = '<li><ul>';
}
elseif ($difLevel < 0)
{
$html[] = str_repeat('</ul></li>', -$difLevel);
}
$html[] = '<li>';
$html[] = '<div class="panel">';
$html[] = '<h3 class="pane-toggler title"><a href="javascript:void(0);"><span>';
$html[] = str_repeat('<span class="level">|&ndash;</span> ', $curLevel = $group->level) . $group->text;
$html[] = '</span></a></h3>';
$html[] = '<div class="pane-slider content pane-hide">';
$html[] = '<div class="mypanel">';
$html[] = '<table class="group-rules">';
$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 class="hasTip" for="' . $this->id . '_' . $action->name . '_' . $group->value . '" 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 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="icon-16-unset">' . JText::_('JLIB_RULES_NOT_ALLOWED') . '</span>';
}
elseif ($inheritedRule === true)
{
$html[] = '<span class="icon-16-allowed">' . JText::_('JLIB_RULES_ALLOWED') . '</span>';
}
elseif ($inheritedRule === false)
{
if ($assetRule === false)
{
$html[] = '<span class="icon-16-denied">' . JText::_('JLIB_RULES_NOT_ALLOWED') . '</span>';
}
else
{
$html[] = '<span class="icon-16-denied"><span class="icon-16-locked">' . JText::_('JLIB_RULES_NOT_ALLOWED_LOCKED')
. '</span></span>';
}
}
}
elseif (!empty($component))
{
$html[] = '<span class="icon-16-allowed"><span class="icon-16-locked">' . JText::_('JLIB_RULES_ALLOWED_ADMIN')
. '</span></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="icon-16-allowed">' . JText::_('JLIB_RULES_ALLOWED') . '</span>';
}
elseif ($inheritedRule === false)
{
// Other actions cannot be changed.
$html[] = '<span class="icon-16-denied"><span class="icon-16-locked">'
. JText::_('JLIB_RULES_NOT_ALLOWED_ADMIN_CONFLICT') . '</span></span>';
}
else
{
$html[] = '<span class="icon-16-allowed"><span class="icon-16-locked">' . JText::_('JLIB_RULES_ALLOWED_ADMIN')
. '</span></span>';
}
}
$html[] = '</td>';
}
$html[] = '</tr>';
}
$html[] = '</tbody>';
$html[] = '</table></div>';
$html[] = '</div></div>';
$html[] = '</li>';
}
$html[] = str_repeat('</ul></li>', $curLevel);
$html[] = '</ul><div class="rule-notes">';
if ($section == 'component' || $section == null)
{
$html[] = JText::_('JLIB_RULES_SETTING_NOTES');
}
else
{
$html[] = JText::_('JLIB_RULES_SETTING_NOTES_ITEM');
}
$html[] = '</div></div>';
$js = "window.addEvent('domready', function(){ new Fx.Accordion($$('div#permissions-sliders.pane-sliders .panel h3.pane-toggler'),"
. "$$('div#permissions-sliders.pane-sliders .panel div.pane-slider'), {onActive: function(toggler, i) {toggler.addClass('pane-toggler-down');"
. "toggler.removeClass('pane-toggler');i.addClass('pane-down');i.removeClass('pane-hide');Cookie.write('jpanesliders_permissions-sliders"
. $component
. "',$$('div#permissions-sliders.pane-sliders .panel h3').indexOf(toggler));},"
. "onBackground: function(toggler, i) {toggler.addClass('pane-toggler');toggler.removeClass('pane-toggler-down');i.addClass('pane-hide');"
. "i.removeClass('pane-down');}, duration: 300, display: "
. JRequest::getInt('jpanesliders_permissions-sliders' . $component, 0, 'cookie') . ", show: "
. JRequest::getInt('jpanesliders_permissions-sliders' . $component, 0, 'cookie') . ", alwaysHide:true, opacity: false}); });";
JFactory::getDocument()->addScriptDeclaration($js);
return implode("\n", $html);
}
protected function getInput3x()
{
JHtml::_('bootstrap.tooltip');
// Initialise some field attributes.
$section = $this->section;
$component = $this->component;
$assetField = $this->assetField;
// Get the actions for the asset.
$actions = JAccess::getActions($component, $section);
// Iterate over the children and add to the actions.
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 = F0FPlatform::getInstance()->getDbo();
$query = $db->getQuery(true)
->select($db->quoteName('id'))
->from($db->quoteName('#__assets'))
->where($db->quoteName('name') . ' = ' . $db->quote($component));
$assetId = (int) $db->setQuery($query)->loadResult();
}
else
{
// Find the asset id of the content.
// Note that for global configuration, com_config injects asset_id = 1 into the form.
$assetId = $this->form->getValue($assetField);
// ==== F0F Library fix - Start ====
// If there is no assetId (let's say we are dealing with a new record), let's ask the table
// to give it to us. Here you should implement your logic (ie getting default permissions from
// the component or from the category)
if(!$assetId)
{
$table = $this->form->getModel()->getTable();
$assetId = $table->getAssetParentId();
}
// ==== F0F Library fix - End ====
}
// Full width format.
// Get the rules for just this asset (non-recursive).
$assetRules = JAccess::getAssetRules($assetId);
// Get the available user groups.
$groups = $this->getUserGroups();
// Prepare output
$html = array();
// Description
$html[] = '<p class="rule-desc">' . JText::_('JLIB_RULES_SETTINGS_DESC') . '</p>';
// Begin tabs
$html[] = '<div id="permissions-sliders" class="tabbable tabs-left">';
// Building tab nav
$html[] = '<ul class="nav nav-tabs">';
foreach ($groups as $group)
{
// Initial Active Tab
$active = "";
if ($group->value == 1)
{
$active = "active";
}
$html[] = '<li class="' . $active . '">';
$html[] = '<a href="#permission-' . $group->value . '" data-toggle="tab">';
$html[] = str_repeat('<span class="level">&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);
}
}

View File

@ -0,0 +1,124 @@
<?php
/**
* @package FrameworkOnFramework
* @subpackage form
* @copyright Copyright (C) 2010-2016 Nicholas K. Dionysopoulos / Akeeba Ltd. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
// Protect from unauthorized access
defined('F0F_INCLUDED') or die;
/**
* Form Field class for F0F
* Renders the checkbox in browse views which allows you to select rows
*
* @package FrameworkOnFramework
* @since 2.0
*/
class F0FFormFieldSelectrow extends JFormField implements F0FFormField
{
protected $static;
protected $repeatable;
/** @var F0FTable The item being rendered in a repeatable form field */
public $item;
/** @var int A monotonically increasing number, denoting the row number in a repeatable view */
public $rowid;
/**
* Method to get certain otherwise inaccessible properties from the form field object.
*
* @param string $name The property name for which to the the value.
*
* @return mixed The property value or null.
*
* @since 2.0
*/
public function __get($name)
{
switch ($name)
{
case 'static':
if (empty($this->static))
{
$this->static = $this->getStatic();
}
return $this->static;
break;
case 'repeatable':
if (empty($this->repeatable))
{
$this->repeatable = $this->getRepeatable();
}
return $this->repeatable;
break;
default:
return parent::__get($name);
}
}
/**
* Method to get the field input markup for this field type.
*
* @since 2.0
*
* @return string The field input markup.
*/
protected function getInput()
{
throw new Exception(__CLASS__ . ' cannot be used in input forms');
}
/**
* Get the rendering of this field type for static display, e.g. in a single
* item view (typically a "read" task).
*
* @since 2.0
*
* @return string The field HTML
*/
public function getStatic()
{
throw new Exception(__CLASS__ . ' cannot be used in single item display forms');
}
/**
* Get the rendering of this field type for a repeatable (grid) display,
* e.g. in a view listing many item (typically a "browse" task)
*
* @since 2.0
*
* @return string The field HTML
*/
public function getRepeatable()
{
if (!($this->item instanceof F0FTable))
{
throw new Exception(__CLASS__ . ' needs a F0FTable to act upon');
}
// Is this record checked out?
$checked_out = false;
$locked_by_field = $this->item->getColumnAlias('locked_by');
$myId = JFactory::getUser()->get('id', 0);
if (property_exists($this->item, $locked_by_field))
{
$locked_by = $this->item->$locked_by_field;
$checked_out = ($locked_by != 0 && $locked_by != $myId);
}
// Get the key id for this record
$key_field = $this->item->getKeyName();
$key_id = $this->item->$key_field;
// Get the HTML
return JHTML::_('grid.id', $this->rowid, $key_id, $checked_out);
}
}

View File

@ -0,0 +1,101 @@
<?php
/**
* @package FrameworkOnFramework
* @subpackage form
* @copyright Copyright (C) 2010-2016 Nicholas K. Dionysopoulos / Akeeba Ltd. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
// Protect from unauthorized access
defined('F0F_INCLUDED') or die;
JFormHelper::loadFieldClass('sessionhandler');
/**
* Form Field class for F0F
* Joomla! session handlers
*
* @package FrameworkOnFramework
* @since 2.0
*/
class F0FFormFieldSessionhandler extends JFormFieldSessionHandler implements F0FFormField
{
protected $static;
protected $repeatable;
/** @var F0FTable The item being rendered in a repeatable form field */
public $item;
/** @var int A monotonically increasing number, denoting the row number in a repeatable view */
public $rowid;
/**
* Method to get certain otherwise inaccessible properties from the form field object.
*
* @param string $name The property name for which to the the value.
*
* @return mixed The property value or null.
*
* @since 2.0
*/
public function __get($name)
{
switch ($name)
{
case 'static':
if (empty($this->static))
{
$this->static = $this->getStatic();
}
return $this->static;
break;
case 'repeatable':
if (empty($this->repeatable))
{
$this->repeatable = $this->getRepeatable();
}
return $this->repeatable;
break;
default:
return parent::__get($name);
}
}
/**
* Get the rendering of this field type for static display, e.g. in a single
* item view (typically a "read" task).
*
* @since 2.0
*
* @return string The field HTML
*/
public function getStatic()
{
$class = $this->element['class'] ? ' class="' . (string) $this->element['class'] . '"' : '';
return '<span id="' . $this->id . '" ' . $class . '>' .
htmlspecialchars(F0FFormFieldList::getOptionName($this->getOptions(), $this->value), ENT_COMPAT, 'UTF-8') .
'</span>';
}
/**
* Get the rendering of this field type for a repeatable (grid) display,
* e.g. in a view listing many item (typically a "browse" task)
*
* @since 2.0
*
* @return string The field HTML
*/
public function getRepeatable()
{
$class = $this->element['class'] ? (string) $this->element['class'] : '';
return '<span class="' . $this->id . ' ' . $class . '">' .
htmlspecialchars(F0FFormFieldList::getOptionName($this->getOptions(), $this->value), ENT_COMPAT, 'UTF-8') .
'</span>';
}
}

View File

@ -0,0 +1,93 @@
<?php
/**
* @package FrameworkOnFramework
* @subpackage form
* @copyright Copyright (C) 2010-2016 Nicholas K. Dionysopoulos / Akeeba Ltd. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
// Protect from unauthorized access
defined('F0F_INCLUDED') or die;
JFormHelper::loadFieldClass('spacer');
/**
* Form Field class for the F0F framework
* Spacer used between form elements
*
* @package FrameworkOnFramework
* @since 2.0
*/
class F0FFormFieldSpacer extends JFormFieldSpacer implements F0FFormField
{
protected $static;
protected $repeatable;
/** @var F0FTable The item being rendered in a repeatable form field */
public $item;
/** @var int A monotonically increasing number, denoting the row number in a repeatable view */
public $rowid;
/**
* Method to get certain otherwise inaccessible properties from the form field object.
*
* @param string $name The property name for which to the the value.
*
* @return mixed The property value or null.
*
* @since 2.0
*/
public function __get($name)
{
switch ($name)
{
case 'static':
if (empty($this->static))
{
$this->static = $this->getStatic();
}
return $this->static;
break;
case 'repeatable':
if (empty($this->repeatable))
{
$this->repeatable = $this->getRepeatable();
}
return $this->repeatable;
break;
default:
return parent::__get($name);
}
}
/**
* Get the rendering of this field type for static display, e.g. in a single
* item view (typically a "read" task).
*
* @since 2.0
*
* @return string The field HTML
*/
public function getStatic()
{
return $this->getInput();
}
/**
* Get the rendering of this field type for a repeatable (grid) display,
* e.g. in a view listing many item (typically a "browse" task)
*
* @since 2.0
*
* @return string The field HTML
*/
public function getRepeatable()
{
return $this->getInput();
}
}

View File

@ -0,0 +1,101 @@
<?php
/**
* @package FrameworkOnFramework
* @subpackage form
* @copyright Copyright (C) 2010-2016 Nicholas K. Dionysopoulos / Akeeba Ltd. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
// Protect from unauthorized access
defined('F0F_INCLUDED') or die;
JFormHelper::loadFieldClass('sql');
/**
* Form Field class for F0F
* Radio selection listGeneric list from an SQL statement
*
* @package FrameworkOnFramework
* @since 2.0
*/
class F0FFormFieldSql extends JFormFieldSql implements F0FFormField
{
protected $static;
protected $repeatable;
/** @var F0FTable The item being rendered in a repeatable form field */
public $item;
/** @var int A monotonically increasing number, denoting the row number in a repeatable view */
public $rowid;
/**
* Method to get certain otherwise inaccessible properties from the form field object.
*
* @param string $name The property name for which to the the value.
*
* @return mixed The property value or null.
*
* @since 2.0
*/
public function __get($name)
{
switch ($name)
{
case 'static':
if (empty($this->static))
{
$this->static = $this->getStatic();
}
return $this->static;
break;
case 'repeatable':
if (empty($this->repeatable))
{
$this->repeatable = $this->getRepeatable();
}
return $this->repeatable;
break;
default:
return parent::__get($name);
}
}
/**
* Get the rendering of this field type for static display, e.g. in a single
* item view (typically a "read" task).
*
* @since 2.0
*
* @return string The field HTML
*/
public function getStatic()
{
$class = $this->element['class'] ? ' class="' . (string) $this->element['class'] . '"' : '';
return '<span id="' . $this->id . '" ' . $class . '>' .
htmlspecialchars(F0FFormFieldList::getOptionName($this->getOptions(), $this->value), ENT_COMPAT, 'UTF-8') .
'</span>';
}
/**
* Get the rendering of this field type for a repeatable (grid) display,
* e.g. in a view listing many item (typically a "browse" task)
*
* @since 2.0
*
* @return string The field HTML
*/
public function getRepeatable()
{
$class = $this->element['class'] ? (string) $this->element['class'] : '';
return '<span class="' . $this->id . ' ' . $class . '">' .
htmlspecialchars(F0FFormFieldList::getOptionName($this->getOptions(), $this->value), ENT_COMPAT, 'UTF-8') .
'</span>';
}
}

View File

@ -0,0 +1,238 @@
<?php
/**
* @package FrameworkOnFramework
* @subpackage form
* @copyright Copyright (C) 2010-2016 Nicholas K. Dionysopoulos / Akeeba Ltd. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
// Protect from unauthorized access
defined('F0F_INCLUDED') or die;
JFormHelper::loadFieldClass('tag');
/**
* Form Field class for F0F
* Tag Fields
*
* @package FrameworkOnFramework
* @since 2.1
*/
class F0FFormFieldTag extends JFormFieldTag implements F0FFormField
{
protected $static;
protected $repeatable;
/** @var F0FTable The item being rendered in a repeatable form field */
public $item;
/** @var int A monotonically increasing number, denoting the row number in a repeatable view */
public $rowid;
/**
* Method to get certain otherwise inaccessible properties from the form field object.
*
* @param string $name The property name for which to the the value.
*
* @return mixed The property value or null.
*
* @since 2.0
*/
public function __get($name)
{
switch ($name)
{
case 'static':
if (empty($this->static))
{
$this->static = $this->getStatic();
}
return $this->static;
break;
case 'repeatable':
if (empty($this->repeatable))
{
$this->repeatable = $this->getRepeatable();
}
return $this->repeatable;
break;
default:
return parent::__get($name);
}
}
/**
* Method to get a list of tags
*
* @return array The field option objects.
*
* @since 3.1
*/
protected function getOptions()
{
$options = array();
$published = $this->element['published']? $this->element['published'] : array(0,1);
$db = F0FPlatform::getInstance()->getDbo();
$query = $db->getQuery(true)
->select('DISTINCT a.id AS value, a.path, a.title AS text, a.level, a.published, a.lft')
->from('#__tags AS a')
->join('LEFT', $db->quoteName('#__tags') . ' AS b ON a.lft > b.lft AND a.rgt < b.rgt');
if ($this->item instanceof F0FTable)
{
$item = $this->item;
}
else
{
$item = $this->form->getModel()->getItem();
}
if ($item instanceof F0FTable)
{
// Fake value for selected tags
$keyfield = $item->getKeyName();
$content_id = $item->$keyfield;
$type = $item->getContentType();
$selected_query = $db->getQuery(true);
$selected_query
->select('tag_id')
->from('#__contentitem_tag_map')
->where('content_item_id = ' . (int) $content_id)
->where('type_alias = ' . $db->quote($type));
$db->setQuery($selected_query);
$this->value = $db->loadColumn();
}
// Filter language
if (!empty($this->element['language']))
{
$query->where('a.language = ' . $db->quote($this->element['language']));
}
$query->where($db->qn('a.lft') . ' > 0');
// Filter to only load active items
// Filter on the published state
if (is_numeric($published))
{
$query->where('a.published = ' . (int) $published);
}
elseif (is_array($published))
{
F0FUtilsArray::toInteger($published);
$query->where('a.published IN (' . implode(',', $published) . ')');
}
$query->order('a.lft ASC');
// Get the options.
$db->setQuery($query);
try
{
$options = $db->loadObjectList();
}
catch (RuntimeException $e)
{
return false;
}
// Prepare nested data
if ($this->isNested())
{
$this->prepareOptionsNested($options);
}
else
{
$options = JHelperTags::convertPathsToNames($options);
}
return $options;
}
/**
* Get the rendering of this field type for static display, e.g. in a single
* item view (typically a "read" task).
*
* @since 2.0
*
* @return string The field HTML
*/
public function getStatic()
{
$class = $this->element['class'] ? (string) $this->element['class'] : '';
$translate = $this->element['translate'] ? (string) $this->element['translate'] : false;
$options = $this->getOptions();
$html = '';
foreach ($options as $option) {
$html .= '<span>';
if ($translate == true)
{
$html .= JText::_($option->text);
}
else
{
$html .= $option->text;
}
$html .= '</span>';
}
return '<span id="' . $this->id . '" class="' . $class . '">' .
$html .
'</span>';
}
/**
* Get the rendering of this field type for a repeatable (grid) display,
* e.g. in a view listing many item (typically a "browse" task)
*
* @since 2.1
*
* @return string The field HTML
*/
public function getRepeatable()
{
$class = $this->element['class'] ? (string) $this->element['class'] : '';
$translate = $this->element['translate'] ? (string) $this->element['translate'] : false;
$options = $this->getOptions();
$html = '';
foreach ($options as $option) {
$html .= '<span>';
if ($translate == true)
{
$html .= JText::_($option->text);
}
else
{
$html .= $option->text;
}
$html .= '</span>';
}
return '<span class="' . $this->id . ' ' . $class . '">' .
$html .
'</span>';
}
}

View File

@ -0,0 +1,165 @@
<?php
/**
* @package FrameworkOnFramework
* @subpackage form
* @copyright Copyright (C) 2010-2016 Nicholas K. Dionysopoulos / Akeeba Ltd. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
// Protect from unauthorized access
defined('F0F_INCLUDED') or die;
JFormHelper::loadFieldClass('tel');
/**
* Form Field class for the F0F framework
* Supports a URL text field.
*
* @package FrameworkOnFramework
* @since 2.0
*/
class F0FFormFieldTel extends JFormFieldTel implements F0FFormField
{
protected $static;
protected $repeatable;
/** @var F0FTable The item being rendered in a repeatable form field */
public $item;
/** @var int A monotonically increasing number, denoting the row number in a repeatable view */
public $rowid;
/**
* Method to get certain otherwise inaccessible properties from the form field object.
*
* @param string $name The property name for which to the the value.
*
* @return mixed The property value or null.
*
* @since 2.0
*/
public function __get($name)
{
switch ($name)
{
case 'static':
if (empty($this->static))
{
$this->static = $this->getStatic();
}
return $this->static;
break;
case 'repeatable':
if (empty($this->repeatable))
{
$this->repeatable = $this->getRepeatable();
}
return $this->repeatable;
break;
default:
return parent::__get($name);
}
}
/**
* Get the rendering of this field type for static display, e.g. in a single
* item view (typically a "read" task).
*
* @since 2.0
*
* @return string The field HTML
*/
public function getStatic()
{
$class = $this->element['class'] ? ' class="' . (string) $this->element['class'] . '"' : '';
$dolink = $this->element['show_link'] == 'true';
$empty_replacement = '';
if ($this->element['empty_replacement'])
{
$empty_replacement = (string) $this->element['empty_replacement'];
}
if (!empty($empty_replacement) && empty($this->value))
{
$this->value = JText::_($empty_replacement);
}
$innerHtml = htmlspecialchars($this->value, ENT_COMPAT, 'UTF-8');
if ($dolink)
{
$innerHtml = '<a href="tel:' . $innerHtml . '">' .
$innerHtml . '</a>';
}
return '<span id="' . $this->id . '" ' . $class . '>' .
$innerHtml .
'</span>';
}
/**
* Get the rendering of this field type for a repeatable (grid) display,
* e.g. in a view listing many item (typically a "browse" task)
*
* @since 2.0
*
* @return string The field HTML
*/
public function getRepeatable()
{
// Initialise
$class = $this->id;
$show_link = false;
$empty_replacement = '';
$link_url = 'tel:' . htmlspecialchars($this->value, ENT_COMPAT, 'UTF-8');
// Get field parameters
if ($this->element['class'])
{
$class = ' ' . (string) $this->element['class'];
}
if ($this->element['show_link'] == 'true')
{
$show_link = true;
}
if ($this->element['empty_replacement'])
{
$empty_replacement = (string) $this->element['empty_replacement'];
}
// Get the (optionally formatted) value
if (!empty($empty_replacement) && empty($this->value))
{
$this->value = JText::_($empty_replacement);
}
$value = htmlspecialchars($this->value, ENT_COMPAT, 'UTF-8');
// Create the HTML
$html = '<span class="' . $class . '">';
if ($show_link)
{
$html .= '<a href="' . $link_url . '">';
}
$html .= $value;
if ($show_link)
{
$html .= '</a>';
}
$html .= '</span>';
return $html;
}
}

View File

@ -0,0 +1,246 @@
<?php
/**
* @package FrameworkOnFramework
* @subpackage form
* @copyright Copyright (C) 2010-2016 Nicholas K. Dionysopoulos / Akeeba Ltd. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
// Protect from unauthorized access
defined('F0F_INCLUDED') or die;
JFormHelper::loadFieldClass('text');
/**
* Form Field class for the F0F framework
* Supports a one line text field.
*
* @package FrameworkOnFramework
* @since 2.0
*/
class F0FFormFieldText extends JFormFieldText implements F0FFormField
{
protected $static;
protected $repeatable;
/** @var F0FTable The item being rendered in a repeatable form field */
public $item;
/** @var int A monotonically increasing number, denoting the row number in a repeatable view */
public $rowid;
/**
* Method to get certain otherwise inaccessible properties from the form field object.
*
* @param string $name The property name for which to the the value.
*
* @return mixed The property value or null.
*
* @since 2.0
*/
public function __get($name)
{
switch ($name)
{
case 'static':
if (empty($this->static))
{
$this->static = $this->getStatic();
}
return $this->static;
break;
case 'repeatable':
if (empty($this->repeatable))
{
$this->repeatable = $this->getRepeatable();
}
return $this->repeatable;
break;
default:
return parent::__get($name);
}
}
/**
* Get the rendering of this field type for static display, e.g. in a single
* item view (typically a "read" task).
*
* @since 2.0
*
* @return string The field HTML
*/
public function getStatic()
{
$class = $this->element['class'] ? ' class="' . (string) $this->element['class'] . '"' : '';
$empty_replacement = '';
if ($this->element['empty_replacement'])
{
$empty_replacement = (string) $this->element['empty_replacement'];
}
if (!empty($empty_replacement) && empty($this->value))
{
$this->value = JText::_($empty_replacement);
}
return '<span id="' . $this->id . '" ' . $class . '>' .
htmlspecialchars($this->value, ENT_COMPAT, 'UTF-8') .
'</span>';
}
/**
* Get the rendering of this field type for a repeatable (grid) display,
* e.g. in a view listing many item (typically a "browse" task)
*
* @since 2.0
*
* @return string The field HTML
*/
public function getRepeatable()
{
// Initialise
$class = $this->id;
$format_string = '';
$format_if_not_empty = false;
$parse_value = false;
$show_link = false;
$link_url = '';
$empty_replacement = '';
// Get field parameters
if ($this->element['class'])
{
$class = (string) $this->element['class'];
}
if ($this->element['format'])
{
$format_string = (string) $this->element['format'];
}
if ($this->element['show_link'] == 'true')
{
$show_link = true;
}
if ($this->element['format_if_not_empty'] == 'true')
{
$format_if_not_empty = true;
}
if ($this->element['parse_value'] == 'true')
{
$parse_value = true;
}
if ($this->element['url'])
{
$link_url = $this->element['url'];
}
else
{
$show_link = false;
}
if ($show_link && ($this->item instanceof F0FTable))
{
$link_url = $this->parseFieldTags($link_url);
}
else
{
$show_link = false;
}
if ($this->element['empty_replacement'])
{
$empty_replacement = (string) $this->element['empty_replacement'];
}
// Get the (optionally formatted) value
$value = $this->value;
if (!empty($empty_replacement) && empty($this->value))
{
$value = JText::_($empty_replacement);
}
if ($parse_value)
{
$value = $this->parseFieldTags($value);
}
if (!empty($format_string) && (!$format_if_not_empty || ($format_if_not_empty && !empty($this->value))))
{
$format_string = $this->parseFieldTags($format_string);
$value = sprintf($format_string, $value);
}
else
{
$value = htmlspecialchars($value, ENT_COMPAT, 'UTF-8');
}
// Create the HTML
$html = '<span class="' . $class . '">';
if ($show_link)
{
$html .= '<a href="' . $link_url . '">';
}
$html .= $value;
if ($show_link)
{
$html .= '</a>';
}
$html .= '</span>';
return $html;
}
/**
* Replace string with tags that reference fields
*
* @param string $text Text to process
*
* @return string Text with tags replace
*/
protected function parseFieldTags($text)
{
$ret = $text;
// Replace [ITEM:ID] in the URL with the item's key value (usually:
// the auto-incrementing numeric ID)
$keyfield = $this->item->getKeyName();
$replace = $this->item->$keyfield;
$ret = str_replace('[ITEM:ID]', $replace, $ret);
// Replace the [ITEMID] in the URL with the current Itemid parameter
$ret = str_replace('[ITEMID]', JFactory::getApplication()->input->getInt('Itemid', 0), $ret);
// Replace other field variables in the URL
$fields = $this->item->getTableFields();
foreach ($fields as $fielddata)
{
$fieldname = $fielddata->Field;
if (empty($fieldname))
{
$fieldname = $fielddata->column_name;
}
$search = '[ITEM:' . strtoupper($fieldname) . ']';
$replace = $this->item->$fieldname;
$ret = str_replace($search, $replace, $ret);
}
return $ret;
}
}

View File

@ -0,0 +1,97 @@
<?php
/**
* @package FrameworkOnFramework
* @subpackage form
* @copyright Copyright (C) 2010-2016 Nicholas K. Dionysopoulos / Akeeba Ltd. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
// Protect from unauthorized access
defined('F0F_INCLUDED') or die;
JFormHelper::loadFieldClass('textarea');
/**
* Form Field class for the F0F framework
* Supports a text area
*
* @package FrameworkOnFramework
* @since 2.0
*/
class F0FFormFieldTextarea extends JFormFieldTextarea implements F0FFormField
{
protected $static;
protected $repeatable;
/** @var F0FTable The item being rendered in a repeatable form field */
public $item;
/** @var int A monotonically increasing number, denoting the row number in a repeatable view */
public $rowid;
/**
* Method to get certain otherwise inaccessible properties from the form field object.
*
* @param string $name The property name for which to the the value.
*
* @return mixed The property value or null.
*
* @since 2.0
*/
public function __get($name)
{
switch ($name)
{
case 'static':
if (empty($this->static))
{
$this->static = $this->getStatic();
}
return $this->static;
break;
case 'repeatable':
if (empty($this->repeatable))
{
$this->repeatable = $this->getRepeatable();
}
return $this->repeatable;
break;
default:
return parent::__get($name);
}
}
/**
* Get the rendering of this field type for static display, e.g. in a single
* item view (typically a "read" task).
*
* @since 2.0
*
* @return string The field HTML
*/
public function getStatic()
{
$class = $this->element['class'] ? ' class="' . (string) $this->element['class'] . '"' : '';
return '<div id="' . $this->id . '" ' . $class . '>' .
htmlspecialchars(nl2br($this->value), ENT_COMPAT, 'UTF-8') .
'</div>';
}
/**
* Get the rendering of this field type for a repeatable (grid) display,
* e.g. in a view listing many item (typically a "browse" task)
*
* @since 2.0
*
* @return string The field HTML
*/
public function getRepeatable()
{
return $this->getStatic();
}
}

View File

@ -0,0 +1,110 @@
<?php
/**
* @package FrameworkOnFramework
* @subpackage form
* @copyright Copyright (C) 2010-2016 Nicholas K. Dionysopoulos / Akeeba Ltd. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
// Protect from unauthorized access
defined('F0F_INCLUDED') or die;
JFormHelper::loadFieldClass('timezone');
/**
* Form Field class for F0F
* Supports a generic list of options.
*
* @package FrameworkOnFramework
* @since 2.0
*/
class F0FFormFieldTimezone extends JFormFieldTimezone implements F0FFormField
{
protected $static;
protected $repeatable;
/** @var F0FTable The item being rendered in a repeatable form field */
public $item;
/** @var int A monotonically increasing number, denoting the row number in a repeatable view */
public $rowid;
/**
* Method to get certain otherwise inaccessible properties from the form field object.
*
* @param string $name The property name for which to the the value.
*
* @return mixed The property value or null.
*
* @since 2.0
*/
public function __get($name)
{
switch ($name)
{
case 'static':
if (empty($this->static))
{
$this->static = $this->getStatic();
}
return $this->static;
break;
case 'repeatable':
if (empty($this->repeatable))
{
$this->repeatable = $this->getRepeatable();
}
return $this->repeatable;
break;
default:
return parent::__get($name);
}
}
/**
* Get the rendering of this field type for static display, e.g. in a single
* item view (typically a "read" task).
*
* @since 2.0
*
* @return string The field HTML
*/
public function getStatic()
{
$class = $this->element['class'] ? (string) $this->element['class'] : '';
$selected = F0FFormFieldGroupedlist::getOptionName($this->getOptions(), $this->value);
if (is_null($selected))
{
$selected = array(
'group' => '',
'item' => ''
);
}
return '<span id="' . $this->id . '-group" class="fof-groupedlist-group ' . $class . '>' .
htmlspecialchars($selected['group'], ENT_COMPAT, 'UTF-8') .
'</span>' .
'<span id="' . $this->id . '-item" class="fof-groupedlist-item ' . $class . '>' .
htmlspecialchars($selected['item'], ENT_COMPAT, 'UTF-8') .
'</span>';
}
/**
* Get the rendering of this field type for a repeatable (grid) display,
* e.g. in a view listing many item (typically a "browse" task)
*
* @since 2.0
*
* @return string The field HTML
*/
public function getRepeatable()
{
return $this->getStatic();
}
}

View File

@ -0,0 +1,67 @@
<?php
/**
* @package FrameworkOnFramework
* @subpackage form
* @copyright Copyright (C) 2010-2016 Nicholas K. Dionysopoulos / Akeeba Ltd. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
// Protect from unauthorized access
defined('F0F_INCLUDED') or die;
JFormHelper::loadFieldClass('text');
/**
* Form Field class for the F0F framework
* Supports a title field with an optional slug display below it.
*
* @package FrameworkOnFramework
* @since 2.0
*/
class F0FFormFieldTitle extends F0FFormFieldText implements F0FFormField
{
/**
* Get the rendering of this field type for a repeatable (grid) display,
* e.g. in a view listing many item (typically a "browse" task)
*
* @since 2.0
*
* @return string The field HTML
*/
public function getRepeatable()
{
// Initialise
$slug_format = '(%s)';
$slug_class = 'small';
// Get field parameters
if ($this->element['slug_field'])
{
$slug_field = (string) $this->element['slug_field'];
}
else
{
$slug_field = $this->item->getColumnAlias('slug');
}
if ($this->element['slug_format'])
{
$slug_format = (string) $this->element['slug_format'];
}
if ($this->element['slug_class'])
{
$slug_class = (string) $this->element['slug_class'];
}
// Get the regular display
$html = parent::getRepeatable();
$slug = $this->item->$slug_field;
$html .= '<br />' . '<span class="' . $slug_class . '">';
$html .= JText::sprintf($slug_format, $slug);
$html .= '</span>';
return $html;
}
}

View File

@ -0,0 +1,165 @@
<?php
/**
* @package FrameworkOnFramework
* @subpackage form
* @copyright Copyright (C) 2010-2016 Nicholas K. Dionysopoulos / Akeeba Ltd. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
// Protect from unauthorized access
defined('F0F_INCLUDED') or die;
JFormHelper::loadFieldClass('url');
/**
* Form Field class for the F0F framework
* Supports a URL text field.
*
* @package FrameworkOnFramework
* @since 2.0
*/
class F0FFormFieldUrl extends JFormFieldUrl implements F0FFormField
{
protected $static;
protected $repeatable;
/** @var F0FTable The item being rendered in a repeatable form field */
public $item;
/** @var int A monotonically increasing number, denoting the row number in a repeatable view */
public $rowid;
/**
* Method to get certain otherwise inaccessible properties from the form field object.
*
* @param string $name The property name for which to the the value.
*
* @return mixed The property value or null.
*
* @since 2.0
*/
public function __get($name)
{
switch ($name)
{
case 'static':
if (empty($this->static))
{
$this->static = $this->getStatic();
}
return $this->static;
break;
case 'repeatable':
if (empty($this->repeatable))
{
$this->repeatable = $this->getRepeatable();
}
return $this->repeatable;
break;
default:
return parent::__get($name);
}
}
/**
* Get the rendering of this field type for static display, e.g. in a single
* item view (typically a "read" task).
*
* @since 2.0
*
* @return string The field HTML
*/
public function getStatic()
{
$class = $this->element['class'] ? ' class="' . (string) $this->element['class'] . '"' : '';
$dolink = $this->element['show_link'] == 'true';
$empty_replacement = '';
if ($this->element['empty_replacement'])
{
$empty_replacement = (string) $this->element['empty_replacement'];
}
if (!empty($empty_replacement) && empty($this->value))
{
$this->value = JText::_($empty_replacement);
}
$innerHtml = htmlspecialchars($this->value, ENT_COMPAT, 'UTF-8');
if ($dolink)
{
$innerHtml = '<a href="' . $innerHtml . '">' .
$innerHtml . '</a>';
}
return '<span id="' . $this->id . '" ' . $class . '>' .
$innerHtml .
'</span>';
}
/**
* Get the rendering of this field type for a repeatable (grid) display,
* e.g. in a view listing many item (typically a "browse" task)
*
* @since 2.0
*
* @return string The field HTML
*/
public function getRepeatable()
{
// Initialise
$class = $this->id;
$show_link = false;
$empty_replacement = '';
$link_url = htmlspecialchars($this->value, ENT_COMPAT, 'UTF-8');
// Get field parameters
if ($this->element['class'])
{
$class .= ' ' . (string) $this->element['class'];
}
if ($this->element['show_link'] == 'true')
{
$show_link = true;
}
if ($this->element['empty_replacement'])
{
$empty_replacement = (string) $this->element['empty_replacement'];
}
// Get the (optionally formatted) value
if (!empty($empty_replacement) && empty($this->value))
{
$this->value = JText::_($empty_replacement);
}
$value = htmlspecialchars($this->value, ENT_COMPAT, 'UTF-8');
// Create the HTML
$html = '<span class="' . $class . '">';
if ($show_link)
{
$html .= '<a href="' . $link_url . '">';
}
$html .= $value;
if ($show_link)
{
$html .= '</a>';
}
$html .= '</span>';
return $html;
}
}

View File

@ -0,0 +1,349 @@
<?php
/**
* @package FrameworkOnFramework
* @subpackage form
* @copyright Copyright (C) 2010-2016 Nicholas K. Dionysopoulos / Akeeba Ltd. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
// Protect from unauthorized access
defined('F0F_INCLUDED') or die;
JFormHelper::loadFieldClass('user');
/**
* Form Field class for the F0F framework
* A user selection box / display field
*
* @package FrameworkOnFramework
* @since 2.0
*/
class F0FFormFieldUser extends JFormFieldUser implements F0FFormField
{
protected $static;
protected $repeatable;
/** @var F0FTable The item being rendered in a repeatable form field */
public $item;
/** @var int A monotonically increasing number, denoting the row number in a repeatable view */
public $rowid;
/**
* Method to get certain otherwise inaccessible properties from the form field object.
*
* @param string $name The property name for which to the the value.
*
* @return mixed The property value or null.
*
* @since 2.0
*/
public function __get($name)
{
switch ($name)
{
case 'static':
if (empty($this->static))
{
$this->static = $this->getStatic();
}
return $this->static;
break;
case 'repeatable':
if (empty($this->repeatable))
{
$this->repeatable = $this->getRepeatable();
}
return $this->repeatable;
break;
default:
return parent::__get($name);
}
}
/**
* Get the rendering of this field type for static display, e.g. in a single
* item view (typically a "read" task).
*
* @since 2.0
*
* @return string The field HTML
*/
public function getStatic()
{
// Initialise
$show_username = true;
$show_email = false;
$show_name = false;
$show_id = false;
$class = '';
// Get the field parameters
if ($this->element['class'])
{
$class = ' class="' . (string) $this->element['class'] . '"';
}
if ($this->element['show_username'] == 'false')
{
$show_username = false;
}
if ($this->element['show_email'] == 'true')
{
$show_email = true;
}
if ($this->element['show_name'] == 'true')
{
$show_name = true;
}
if ($this->element['show_id'] == 'true')
{
$show_id = true;
}
// Get the user record
$user = JFactory::getUser($this->value);
// Render the HTML
$html = '<div id="' . $this->id . '" ' . $class . '>';
if ($show_username)
{
$html .= '<span class="fof-userfield-username">' . $user->username . '</span>';
}
if ($show_id)
{
$html .= '<span class="fof-userfield-id">' . $user->id . '</span>';
}
if ($show_name)
{
$html .= '<span class="fof-userfield-name">' . $user->name . '</span>';
}
if ($show_email)
{
$html .= '<span class="fof-userfield-email">' . $user->email . '</span>';
}
$html .= '</div>';
return $html;
}
/**
* Get the rendering of this field type for a repeatable (grid) display,
* e.g. in a view listing many item (typically a "browse" task)
*
* @since 2.0
*
* @return string The field HTML
*/
public function getRepeatable()
{
// Initialise
$show_username = true;
$show_email = true;
$show_name = true;
$show_id = true;
$show_avatar = true;
$show_link = false;
$link_url = null;
$avatar_method = 'gravatar';
$avatar_size = 64;
$class = '';
// Get the user record
$user = JFactory::getUser($this->value);
// Get the field parameters
if ($this->element['class'])
{
$class = ' class="' . (string) $this->element['class'] . '"';
}
if ($this->element['show_username'] == 'false')
{
$show_username = false;
}
if ($this->element['show_email'] == 'false')
{
$show_email = false;
}
if ($this->element['show_name'] == 'false')
{
$show_name = false;
}
if ($this->element['show_id'] == 'false')
{
$show_id = false;
}
if ($this->element['show_avatar'] == 'false')
{
$show_avatar = false;
}
if ($this->element['avatar_method'])
{
$avatar_method = strtolower($this->element['avatar_method']);
}
if ($this->element['avatar_size'])
{
$avatar_size = $this->element['avatar_size'];
}
if ($this->element['show_link'] == 'true')
{
$show_link = true;
}
if ($this->element['link_url'])
{
$link_url = $this->element['link_url'];
}
else
{
if (F0FPlatform::getInstance()->isBackend())
{
// If no link is defined in the back-end, assume the user edit
// link in the User Manager component
$link_url = 'index.php?option=com_users&task=user.edit&id=[USER:ID]';
}
else
{
// If no link is defined in the front-end, we can't create a
// default link. Therefore, show no link.
$show_link = false;
}
}
// Post-process the link URL
if ($show_link)
{
$replacements = array(
'[USER:ID]' => $user->id,
'[USER:USERNAME]' => $user->username,
'[USER:EMAIL]' => $user->email,
'[USER:NAME]' => $user->name,
);
foreach ($replacements as $key => $value)
{
$link_url = str_replace($key, $value, $link_url);
}
}
// Get the avatar image, if necessary
if ($show_avatar)
{
$avatar_url = '';
if ($avatar_method == 'plugin')
{
// Use the user plugins to get an avatar
F0FPlatform::getInstance()->importPlugin('user');
$jResponse = F0FPlatform::getInstance()->runPlugins('onUserAvatar', array($user, $avatar_size));
if (!empty($jResponse))
{
foreach ($jResponse as $response)
{
if ($response)
{
$avatar_url = $response;
}
}
}
if (empty($avatar_url))
{
$show_avatar = false;
}
}
else
{
// Fall back to the Gravatar method
$md5 = md5($user->email);
if (F0FPlatform::getInstance()->isCli())
{
$scheme = 'http';
}
else
{
$scheme = JURI::getInstance()->getScheme();
}
if ($scheme == 'http')
{
$avatar_url = 'http://www.gravatar.com/avatar/' . $md5 . '.jpg?s='
. $avatar_size . '&d=mm';
}
else
{
$avatar_url = 'https://secure.gravatar.com/avatar/' . $md5 . '.jpg?s='
. $avatar_size . '&d=mm';
}
}
}
// Generate the HTML
$html = '<div id="' . $this->id . '" ' . $class . '>';
if ($show_avatar)
{
$html .= '<img src="' . $avatar_url . '" align="left" class="fof-usersfield-avatar" />';
}
if ($show_link)
{
$html .= '<a href="' . $link_url . '">';
}
if ($show_username)
{
$html .= '<span class="fof-usersfield-username">' . $user->username
. '</span>';
}
if ($show_id)
{
$html .= '<span class="fof-usersfield-id">' . $user->id
. '</span>';
}
if ($show_name)
{
$html .= '<span class="fof-usersfield-name">' . $user->name
. '</span>';
}
if ($show_email)
{
$html .= '<span class="fof-usersfield-email">' . $user->email
. '</span>';
}
if ($show_link)
{
$html .= '</a>';
}
$html .= '</div>';
return $html;
}
}

View File

@ -0,0 +1,143 @@
<?php
/**
* @package FrameworkOnFramework
* @subpackage form
* @subpackage form
* @copyright Copyright (C) 2010-2016 Nicholas K. Dionysopoulos / Akeeba Ltd. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
// Protect from unauthorized access
defined('_JEXEC') or die;
JFormHelper::loadFieldClass('usergroup');
/**
* Form Field class for F0F
* Joomla! user groups
*
* @package FrameworkOnFramework
* @since 2.0
*/
class F0FFormFieldUsergroup extends JFormFieldUsergroup implements F0FFormField
{
protected $static;
protected $repeatable;
/** @var int A monotonically increasing number, denoting the row number in a repeatable view */
public $rowid;
/** @var F0FTable The item being rendered in a repeatable form field */
public $item;
/**
* Method to get certain otherwise inaccessible properties from the form field object.
*
* @param string $name The property name for which to the the value.
*
* @return mixed The property value or null.
*
* @since 2.0
*/
public function __get($name)
{
switch ($name)
{
case 'static':
if (empty($this->static))
{
$this->static = $this->getStatic();
}
return $this->static;
break;
case 'repeatable':
if (empty($this->repeatable))
{
$this->repeatable = $this->getRepeatable();
}
return $this->repeatable;
break;
default:
return parent::__get($name);
}
}
/**
* Get the rendering of this field type for static display, e.g. in a single
* item view (typically a "read" task).
*
* @since 2.0
*
* @return string The field HTML
*/
public function getStatic()
{
$class = $this->element['class'] ? ' class="' . (string) $this->element['class'] . '"' : '';
$params = $this->getOptions();
$db = F0FPlatform::getInstance()->getDbo();
$query = $db->getQuery(true);
$query->select('a.id AS value, a.title AS text');
$query->from('#__usergroups AS a');
$query->group('a.id, a.title');
$query->order('a.id ASC');
$query->order($query->qn('title') . ' ASC');
// Get the options.
$db->setQuery($query);
$options = $db->loadObjectList();
// If params is an array, push these options to the array
if (is_array($params))
{
$options = array_merge($params, $options);
}
// If all levels is allowed, push it into the array.
elseif ($params)
{
array_unshift($options, JHtml::_('select.option', '', JText::_('JOPTION_ACCESS_SHOW_ALL_LEVELS')));
}
return '<span id="' . $this->id . '" ' . $class . '>' .
htmlspecialchars(F0FFormFieldList::getOptionName($options, $this->value), ENT_COMPAT, 'UTF-8') .
'</span>';
}
/**
* Get the rendering of this field type for a repeatable (grid) display,
* e.g. in a view listing many item (typically a "browse" task)
*
* @since 2.0
*
* @return string The field HTML
*/
public function getRepeatable()
{
$class = $this->element['class'] ? (string) $this->element['class'] : '';
$db = F0FPlatform::getInstance()->getDbo();
$query = $db->getQuery(true);
$query->select('a.id AS value, a.title AS text');
$query->from('#__usergroups AS a');
$query->group('a.id, a.title');
$query->order('a.id ASC');
$query->order($query->qn('title') . ' ASC');
// Get the options.
$db->setQuery($query);
$options = $db->loadObjectList();
return '<span class="' . $this->id . ' ' . $class . '">' .
htmlspecialchars(F0FFormFieldList::getOptionName($options, $this->value), ENT_COMPAT, 'UTF-8') .
'</span>';
}
}

659
libraries/f0f/form/form.php Normal file
View File

@ -0,0 +1,659 @@
<?php
/**
* @package FrameworkOnFramework
* @subpackage form
* @copyright Copyright (C) 2010-2016 Nicholas K. Dionysopoulos / Akeeba Ltd. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
// Protect from unauthorized access
defined('F0F_INCLUDED') or die;
if (version_compare(JVERSION, '2.5.0', 'lt'))
{
jimport('joomla.form.form');
jimport('joomla.form.formfield');
jimport('joomla.form.formrule');
}
/**
* F0FForm is an extension to JForm which support not only edit views but also
* browse (record list) and read (single record display) views based on XML
* forms.
*
* @package FrameworkOnFramework
* @since 2.0
*/
class F0FForm extends JForm
{
/**
* The model attached to this view
*
* @var F0FModel
*/
protected $model;
/**
* The view used to render this form
*
* @var F0FView
*/
protected $view;
/**
* Method to get an instance of a form.
*
* @param string $name The name of the form.
* @param string $data The name of an XML file or string to load as the form definition.
* @param array $options An array of form options.
* @param bool $replace Flag to toggle whether form fields should be replaced if a field
* already exists with the same group/name.
* @param bool|string $xpath An optional xpath to search for the fields.
*
* @return object F0FForm instance.
*
* @since 2.0
* @throws InvalidArgumentException if no data provided.
* @throws RuntimeException if the form could not be loaded.
*/
public static function getInstance($name, $data = null, $options = array(), $replace = true, $xpath = false)
{
// Reference to array with form instances
$forms = &self::$forms;
// Only instantiate the form if it does not already exist.
if (!isset($forms[$name]))
{
$data = trim($data);
if (empty($data))
{
throw new InvalidArgumentException(sprintf('F0FForm::getInstance(name, *%s*)', gettype($data)));
}
// Instantiate the form.
$forms[$name] = new F0FForm($name, $options);
// Load the data.
if (substr(trim($data), 0, 1) == '<')
{
if ($forms[$name]->load($data, $replace, $xpath) == false)
{
throw new RuntimeException('F0FForm::getInstance could not load form');
}
}
else
{
if ($forms[$name]->loadFile($data, $replace, $xpath) == false)
{
throw new RuntimeException('F0FForm::getInstance could not load file ' . $data . '.xml');
}
}
}
return $forms[$name];
}
/**
* Returns the value of an attribute of the form itself
*
* @param string $attribute The name of the attribute
* @param mixed $default Optional default value to return
*
* @return mixed
*
* @since 2.0
*/
public function getAttribute($attribute, $default = null)
{
$value = $this->xml->attributes()->$attribute;
if (is_null($value))
{
return $default;
}
else
{
return (string) $value;
}
}
/**
* Loads the CSS files defined in the form, based on its cssfiles attribute
*
* @return void
*
* @since 2.0
*/
public function loadCSSFiles()
{
// Support for CSS files
$cssfiles = $this->getAttribute('cssfiles');
if (!empty($cssfiles))
{
$cssfiles = explode(',', $cssfiles);
foreach ($cssfiles as $cssfile)
{
F0FTemplateUtils::addCSS(trim($cssfile));
}
}
// Support for LESS files
$lessfiles = $this->getAttribute('lessfiles');
if (!empty($lessfiles))
{
$lessfiles = explode(',', $lessfiles);
foreach ($lessfiles as $def)
{
$parts = explode('||', $def, 2);
$lessfile = $parts[0];
$alt = (count($parts) > 1) ? trim($parts[1]) : null;
F0FTemplateUtils::addLESS(trim($lessfile), $alt);
}
}
}
/**
* Loads the Javascript files defined in the form, based on its jsfiles attribute
*
* @return void
*
* @since 2.0
*/
public function loadJSFiles()
{
$jsfiles = $this->getAttribute('jsfiles');
if (empty($jsfiles))
{
return;
}
$jsfiles = explode(',', $jsfiles);
foreach ($jsfiles as $jsfile)
{
F0FTemplateUtils::addJS(trim($jsfile));
}
}
/**
* Returns a reference to the protected $data object, allowing direct
* access to and manipulation of the form's data.
*
* @return JRegistry The form's data registry
*
* @since 2.0
*/
public function getData()
{
return $this->data;
}
/**
* Attaches a F0FModel to this form
*
* @param F0FModel &$model The model to attach to the form
*
* @return void
*/
public function setModel(F0FModel &$model)
{
$this->model = $model;
}
/**
* Returns the F0FModel attached to this form
*
* @return F0FModel
*/
public function &getModel()
{
return $this->model;
}
/**
* Attaches a F0FView to this form
*
* @param F0FView &$view The view to attach to the form
*
* @return void
*/
public function setView(F0FView &$view)
{
$this->view = $view;
}
/**
* Returns the F0FView attached to this form
*
* @return F0FView
*/
public function &getView()
{
return $this->view;
}
/**
* Method to get an array of F0FFormHeader objects in the headerset.
*
* @return array The array of F0FFormHeader objects in the headerset.
*
* @since 2.0
*/
public function getHeaderset()
{
$fields = array();
$elements = $this->findHeadersByGroup();
// If no field elements were found return empty.
if (empty($elements))
{
return $fields;
}
// Build the result array from the found field elements.
foreach ($elements as $element)
{
// Get the field groups for the element.
$attrs = $element->xpath('ancestor::headers[@name]/@name');
$groups = array_map('strval', $attrs ? $attrs : array());
$group = implode('.', $groups);
// If the field is successfully loaded add it to the result array.
if ($field = $this->loadHeader($element, $group))
{
$fields[$field->id] = $field;
}
}
return $fields;
}
/**
* Method to get an array of <header /> elements from the form XML document which are
* in a control group by name.
*
* @param mixed $group The optional dot-separated form group path on which to find the fields.
* Null will return all fields. False will return fields not in a group.
* @param boolean $nested True to also include fields in nested groups that are inside of the
* group for which to find fields.
*
* @return mixed Boolean false on error or array of SimpleXMLElement objects.
*
* @since 2.0
*/
protected function &findHeadersByGroup($group = null, $nested = false)
{
$false = false;
$fields = array();
// Make sure there is a valid JForm XML document.
if (!($this->xml instanceof SimpleXMLElement))
{
return $false;
}
// Get only fields in a specific group?
if ($group)
{
// Get the fields elements for a given group.
$elements = &$this->findHeader($group);
// Get all of the field elements for the fields elements.
foreach ($elements as $element)
{
// If there are field elements add them to the return result.
if ($tmp = $element->xpath('descendant::header'))
{
// If we also want fields in nested groups then just merge the arrays.
if ($nested)
{
$fields = array_merge($fields, $tmp);
}
// If we want to exclude nested groups then we need to check each field.
else
{
$groupNames = explode('.', $group);
foreach ($tmp as $field)
{
// Get the names of the groups that the field is in.
$attrs = $field->xpath('ancestor::headers[@name]/@name');
$names = array_map('strval', $attrs ? $attrs : array());
// If the field is in the specific group then add it to the return list.
if ($names == (array) $groupNames)
{
$fields = array_merge($fields, array($field));
}
}
}
}
}
}
elseif ($group === false)
{
// Get only field elements not in a group.
$fields = $this->xml->xpath('descendant::headers[not(@name)]/header | descendant::headers[not(@name)]/headerset/header ');
}
else
{
// Get an array of all the <header /> elements.
$fields = $this->xml->xpath('//header');
}
return $fields;
}
/**
* Method to get a header field represented as a F0FFormHeader object.
*
* @param string $name The name of the header field.
* @param string $group The optional dot-separated form group path on which to find the field.
* @param mixed $value The optional value to use as the default for the field.
*
* @return mixed The F0FFormHeader object for the field or boolean false on error.
*
* @since 2.0
*/
public function getHeader($name, $group = null, $value = null)
{
// Make sure there is a valid F0FForm XML document.
if (!($this->xml instanceof SimpleXMLElement))
{
return false;
}
// Attempt to find the field by name and group.
$element = $this->findHeader($name, $group);
// If the field element was not found return false.
if (!$element)
{
return false;
}
return $this->loadHeader($element, $group, $value);
}
/**
* Method to get a header field represented as an XML element object.
*
* @param string $name The name of the form field.
* @param string $group The optional dot-separated form group path on which to find the field.
*
* @return mixed The XML element object for the field or boolean false on error.
*
* @since 2.0
*/
protected function findHeader($name, $group = null)
{
$element = false;
$fields = array();
// Make sure there is a valid JForm XML document.
if (!($this->xml instanceof SimpleXMLElement))
{
return false;
}
// Let's get the appropriate field element based on the method arguments.
if ($group)
{
// Get the fields elements for a given group.
$elements = &$this->findGroup($group);
// Get all of the field elements with the correct name for the fields elements.
foreach ($elements as $element)
{
// If there are matching field elements add them to the fields array.
if ($tmp = $element->xpath('descendant::header[@name="' . $name . '"]'))
{
$fields = array_merge($fields, $tmp);
}
}
// Make sure something was found.
if (!$fields)
{
return false;
}
// Use the first correct match in the given group.
$groupNames = explode('.', $group);
foreach ($fields as &$field)
{
// Get the group names as strings for ancestor fields elements.
$attrs = $field->xpath('ancestor::headerfields[@name]/@name');
$names = array_map('strval', $attrs ? $attrs : array());
// If the field is in the exact group use it and break out of the loop.
if ($names == (array) $groupNames)
{
$element = &$field;
break;
}
}
}
else
{
// Get an array of fields with the correct name.
$fields = $this->xml->xpath('//header[@name="' . $name . '"]');
// Make sure something was found.
if (!$fields)
{
return false;
}
// Search through the fields for the right one.
foreach ($fields as &$field)
{
// If we find an ancestor fields element with a group name then it isn't what we want.
if ($field->xpath('ancestor::headerfields[@name]'))
{
continue;
}
// Found it!
else
{
$element = &$field;
break;
}
}
}
return $element;
}
/**
* Method to load, setup and return a F0FFormHeader object based on field data.
*
* @param string $element The XML element object representation of the form field.
* @param string $group The optional dot-separated form group path on which to find the field.
* @param mixed $value The optional value to use as the default for the field.
*
* @return mixed The F0FFormHeader object for the field or boolean false on error.
*
* @since 2.0
*/
protected function loadHeader($element, $group = null, $value = null)
{
// Make sure there is a valid SimpleXMLElement.
if (!($element instanceof SimpleXMLElement))
{
return false;
}
// Get the field type.
$type = $element['type'] ? (string) $element['type'] : 'field';
// Load the JFormField object for the field.
$field = $this->loadHeaderType($type);
// If the object could not be loaded, get a text field object.
if ($field === false)
{
$field = $this->loadHeaderType('field');
}
// Setup the F0FFormHeader object.
$field->setForm($this);
if ($field->setup($element, $value, $group))
{
return $field;
}
else
{
return false;
}
}
/**
* Method to remove a header from the form definition.
*
* @param string $name The name of the form field for which remove.
* @param string $group The optional dot-separated form group path on which to find the field.
*
* @return boolean True on success, false otherwise.
*
* @throws UnexpectedValueException
*/
public function removeHeader($name, $group = null)
{
// Make sure there is a valid JForm XML document.
if (!($this->xml instanceof SimpleXMLElement))
{
throw new UnexpectedValueException(sprintf('%s::getFieldAttribute `xml` is not an instance of SimpleXMLElement', get_class($this)));
}
// Find the form field element from the definition.
$element = $this->findHeader($name, $group);
// If the element exists remove it from the form definition.
if ($element instanceof SimpleXMLElement)
{
$dom = dom_import_simplexml($element);
$dom->parentNode->removeChild($dom);
return true;
}
return false;
}
/**
* Proxy for {@link F0FFormHelper::loadFieldType()}.
*
* @param string $type The field type.
* @param boolean $new Flag to toggle whether we should get a new instance of the object.
*
* @return mixed F0FFormField object on success, false otherwise.
*
* @since 2.0
*/
protected function loadFieldType($type, $new = true)
{
return F0FFormHelper::loadFieldType($type, $new);
}
/**
* Proxy for {@link F0FFormHelper::loadHeaderType()}.
*
* @param string $type The field type.
* @param boolean $new Flag to toggle whether we should get a new instance of the object.
*
* @return mixed F0FFormHeader object on success, false otherwise.
*
* @since 2.0
*/
protected function loadHeaderType($type, $new = true)
{
return F0FFormHelper::loadHeaderType($type, $new);
}
/**
* Proxy for {@link F0FFormHelper::loadRuleType()}.
*
* @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.
*
* @see F0FFormHelper::loadRuleType()
* @since 2.0
*/
protected function loadRuleType($type, $new = true)
{
return F0FFormHelper::loadRuleType($type, $new);
}
/**
* Proxy for {@link F0FFormHelper::addFieldPath()}.
*
* @param mixed $new A path or array of paths to add.
*
* @return array The list of paths that have been added.
*
* @since 2.0
*/
public static function addFieldPath($new = null)
{
return F0FFormHelper::addFieldPath($new);
}
/**
* Proxy for {@link F0FFormHelper::addHeaderPath()}.
*
* @param mixed $new A path or array of paths to add.
*
* @return array The list of paths that have been added.
*
* @since 2.0
*/
public static function addHeaderPath($new = null)
{
return F0FFormHelper::addHeaderPath($new);
}
/**
* Proxy for F0FFormHelper::addFormPath().
*
* @param mixed $new A path or array of paths to add.
*
* @return array The list of paths that have been added.
*
* @see F0FFormHelper::addFormPath()
* @since 2.0
*/
public static function addFormPath($new = null)
{
return F0FFormHelper::addFormPath($new);
}
/**
* Proxy for F0FFormHelper::addRulePath().
*
* @param mixed $new A path or array of paths to add.
*
* @return array The list of paths that have been added.
*
* @see F0FFormHelper::addRulePath()
* @since 2.0
*/
public static function addRulePath($new = null)
{
return F0FFormHelper::addRulePath($new);
}
}

View File

@ -0,0 +1,579 @@
<?php
/**
* @package FrameworkOnFramework
* @subpackage form
* @copyright Copyright (C) 2010-2016 Nicholas K. Dionysopoulos / Akeeba Ltd. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
// Protect from unauthorized access
defined('F0F_INCLUDED') or die;
/**
* An interface for F0FFormHeader fields, used to define the filters and the
* elements of the header row in repeatable (browse) views
*
* @package FrameworkOnFramework
* @since 2.0
*/
abstract class F0FFormHeader
{
/**
* The description text for the form field. Usually used in tooltips.
*
* @var string
* @since 2.0
*/
protected $description;
/**
* The SimpleXMLElement object of the <field /> XML element that describes the header field.
*
* @var SimpleXMLElement
* @since 2.0
*/
protected $element;
/**
* The F0FForm object of the form attached to the header field.
*
* @var F0FForm
* @since 2.0
*/
protected $form;
/**
* The label for the header field.
*
* @var string
* @since 2.0
*/
protected $label;
/**
* The header HTML.
*
* @var string|null
* @since 2.0
*/
protected $header;
/**
* The filter HTML.
*
* @var string|null
* @since 2.0
*/
protected $filter;
/**
* The buttons HTML.
*
* @var string|null
* @since 2.0
*/
protected $buttons;
/**
* The options for a drop-down filter.
*
* @var array|null
* @since 2.0
*/
protected $options;
/**
* The name of the form field.
*
* @var string
* @since 2.0
*/
protected $name;
/**
* The name of the field.
*
* @var string
* @since 2.0
*/
protected $fieldname;
/**
* The group of the field.
*
* @var string
* @since 2.0
*/
protected $group;
/**
* The form field type.
*
* @var string
* @since 2.0
*/
protected $type;
/**
* The value of the filter.
*
* @var mixed
* @since 2.0
*/
protected $value;
/**
* The intended table data width (in pixels or percent).
*
* @var mixed
* @since 2.0
*/
protected $tdwidth;
/**
* The key of the filter value in the model state.
*
* @var mixed
* @since 2.0
*/
protected $filterSource;
/**
* Is this a sortable column?
*
* @var bool
* @since 2.0
*/
protected $sortable = false;
/**
* Method to instantiate the form field object.
*
* @param F0FForm $form The form to attach to the form field object.
*
* @since 2.0
*/
public function __construct(F0FForm $form = null)
{
// If there is a form passed into the constructor set the form and form control properties.
if ($form instanceof F0FForm)
{
$this->form = $form;
}
}
/**
* Method to get certain otherwise inaccessible properties from the form field object.
*
* @param string $name The property name for which to the the value.
*
* @return mixed The property value or null.
*
* @since 2.0
*/
public function __get($name)
{
switch ($name)
{
case 'description':
case 'name':
case 'type':
case 'fieldname':
case 'group':
case 'tdwidth':
return $this->$name;
break;
case 'label':
if (empty($this->label))
{
$this->label = $this->getLabel();
}
return $this->label;
case 'value':
if (empty($this->value))
{
$this->value = $this->getValue();
}
return $this->value;
break;
case 'header':
if (empty($this->header))
{
$this->header = $this->getHeader();
}
return $this->header;
break;
case 'filter':
if (empty($this->filter))
{
$this->filter = $this->getFilter();
}
return $this->filter;
break;
case 'buttons':
if (empty($this->buttons))
{
$this->buttons = $this->getButtons();
}
return $this->buttons;
break;
case 'options':
if (empty($this->options))
{
$this->options = $this->getOptions();
}
return $this->options;
break;
case 'sortable':
if (empty($this->sortable))
{
$this->sortable = $this->getSortable();
}
return $this->sortable;
break;
}
return null;
}
/**
* Method to attach a JForm object to the field.
*
* @param F0FForm $form The JForm object to attach to the form field.
*
* @return F0FFormHeader The form field object so that the method can be used in a chain.
*
* @since 2.0
*/
public function setForm(F0FForm $form)
{
$this->form = $form;
return $this;
}
/**
* Method to attach a F0FForm 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 2.0
*/
public function setup(SimpleXMLElement $element, $value, $group = null)
{
// Make sure there is a valid JFormField XML element.
if ((string) $element->getName() != 'header')
{
return false;
}
// Reset the internal fields
$this->label = null;
$this->header = null;
$this->filter = null;
$this->buttons = null;
$this->options = null;
$this->value = null;
$this->filterSource = null;
// 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'];
$name = (string) $element['name'];
$filterSource = (string) $element['filter_source'];
$tdwidth = (string) $element['tdwidth'];
// Set the field description text.
$this->description = (string) $element['description'];
// Set the group of the field.
$this->group = $group;
// Set the td width of the field.
$this->tdwidth = $tdwidth;
// Set the field name and id.
$this->fieldname = $this->getFieldName($name);
$this->name = $this->getName($this->fieldname);
$this->id = $this->getId($id, $this->fieldname);
$this->filterSource = $this->getFilterSource($filterSource);
// Set the field default value.
$this->value = $this->getValue();
return true;
}
/**
* Method to get the id used for the field input tag.
*
* @param string $fieldId The field element id.
* @param string $fieldName The field element name.
*
* @return string The id to be used for the field input tag.
*
* @since 2.0
*/
protected function getId($fieldId, $fieldName)
{
$id = '';
// If the field is in a group add the group control to the field id.
if ($this->group)
{
// If we already have an id segment add the group control as another level.
if ($id)
{
$id .= '_' . str_replace('.', '_', $this->group);
}
else
{
$id .= str_replace('.', '_', $this->group);
}
}
// If we already have an id segment add the field id/name as another level.
if ($id)
{
$id .= '_' . ($fieldId ? $fieldId : $fieldName);
}
else
{
$id .= ($fieldId ? $fieldId : $fieldName);
}
// Clean up any invalid characters.
$id = preg_replace('#\W#', '_', $id);
return $id;
}
/**
* Method to get the name used for the field input tag.
*
* @param string $fieldName The field element name.
*
* @return string The name to be used for the field input tag.
*
* @since 2.0
*/
protected function getName($fieldName)
{
$name = '';
// If the field is in a group add the group control to the field name.
if ($this->group)
{
// If we already have a name segment add the group control as another level.
$groups = explode('.', $this->group);
if ($name)
{
foreach ($groups as $group)
{
$name .= '[' . $group . ']';
}
}
else
{
$name .= array_shift($groups);
foreach ($groups as $group)
{
$name .= '[' . $group . ']';
}
}
}
// If we already have a name segment add the field name as another level.
if ($name)
{
$name .= '[' . $fieldName . ']';
}
else
{
$name .= $fieldName;
}
return $name;
}
/**
* Method to get the field name used.
*
* @param string $fieldName The field element name.
*
* @return string The field name
*
* @since 2.0
*/
protected function getFieldName($fieldName)
{
return $fieldName;
}
/**
* Method to get the field label.
*
* @return string The field label.
*
* @since 2.0
*/
protected function getLabel()
{
// Get the label text from the XML element, defaulting to the element name.
$title = $this->element['label'] ? (string) $this->element['label'] : '';
if (empty($title))
{
$view = $this->form->getView();
$params = $view->getViewOptionAndName();
$title = $params['option'] . '_' .
F0FInflector::pluralize($params['view']) . '_FIELD_' .
(string) $this->element['name'];
$title = strtoupper($title);
$result = JText::_($title);
if ($result === $title)
{
$title = ucfirst((string) $this->element['name']);
}
}
return $title;
}
/**
* Get the filter value for this header field
*
* @return mixed The filter value
*/
protected function getValue()
{
$model = $this->form->getModel();
return $model->getState($this->filterSource);
}
/**
* Return the key of the filter value in the model state or, if it's not set,
* the name of the field.
*
* @param string $filterSource The filter source value to return
*
* @return string
*/
protected function getFilterSource($filterSource)
{
if ($filterSource)
{
return $filterSource;
}
else
{
return $this->name;
}
}
/**
* Is this a sortable field?
*
* @return boolean True if it's sortable
*/
protected function getSortable()
{
$sortable = ($this->element['sortable'] != 'false');
if ($sortable)
{
if (empty($this->header))
{
$this->header = $this->getHeader();
}
$sortable = !empty($this->header);
}
return $sortable;
}
/**
* Returns the HTML for the header row, or null if this element should
* render no header element
*
* @return string|null HTML code or null if nothing is to be rendered
*
* @since 2.0
*/
protected function getHeader()
{
return null;
}
/**
* Returns the HTML for a text filter to be rendered in the filter row,
* or null if this element should render no text input filter.
*
* @return string|null HTML code or null if nothing is to be rendered
*
* @since 2.0
*/
protected function getFilter()
{
return null;
}
/**
* Returns the HTML for the buttons to be rendered in the filter row,
* next to the text input filter, or null if this element should render no
* text input filter buttons.
*
* @return string|null HTML code or null if nothing is to be rendered
*
* @since 2.0
*/
protected function getButtons()
{
return null;
}
/**
* Returns the JHtml options for a drop-down filter. Do not include an
* empty option, it is added automatically.
*
* @return array The JHtml options for a drop-down filter
*
* @since 2.0
*/
protected function getOptions()
{
return array();
}
}

View File

@ -0,0 +1,43 @@
<?php
/**
* @package FrameworkOnFramework
* @subpackage form
* @copyright Copyright (C) 2010-2016 Nicholas K. Dionysopoulos / Akeeba Ltd. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
// Protect from unauthorized access
defined('F0F_INCLUDED') or die;
/**
* Access level field header
*
* @package FrameworkOnFramework
* @since 2.0
*/
class F0FFormHeaderAccesslevel extends F0FFormHeaderFieldselectable
{
/**
* Method to get the list of access levels
*
* @return array A list of access levels.
*
* @since 2.0
*/
protected function getOptions()
{
$db = F0FPlatform::getInstance()->getDbo();
$query = $db->getQuery(true);
$query->select('a.id AS value, a.title AS text');
$query->from('#__viewlevels AS a');
$query->group('a.id, a.title, a.ordering');
$query->order('a.ordering ASC');
$query->order($query->qn('title') . ' ASC');
// Get the options.
$db->setQuery($query);
$options = $db->loadObjectList();
return $options;
}
}

View File

@ -0,0 +1,44 @@
<?php
/**
* @package FrameworkOnFramework
* @subpackage form
* @copyright Copyright (C) 2010-2016 Nicholas K. Dionysopoulos / Akeeba Ltd. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
// Protect from unauthorized access
defined('F0F_INCLUDED') or die;
/**
* Generic field header, without any filters
*
* @package FrameworkOnFramework
* @since 2.0
*/
class F0FFormHeaderField extends F0FFormHeader
{
/**
* Get the header
*
* @return string The header HTML
*/
protected function getHeader()
{
$sortable = ($this->element['sortable'] != 'false');
$label = $this->getLabel();
if ($sortable)
{
$view = $this->form->getView();
return JHTML::_('grid.sort', $label, $this->name,
$view->getLists()->order_Dir, $view->getLists()->order,
$this->form->getModel()->task
);
}
else
{
return JText::_($label);
}
}
}

View File

@ -0,0 +1,127 @@
<?php
/**
* @package FrameworkOnFramework
* @subpackage form
* @copyright Copyright (C) 2010-2016 Nicholas K. Dionysopoulos / Akeeba Ltd. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
// Protect from unauthorized access
defined('F0F_INCLUDED') or die;
/**
* Generic field header, with text input (search) filter
*
* @package FrameworkOnFramework
* @since 2.0
*/
class F0FFormHeaderFielddate extends F0FFormHeaderField
{
/**
* Get the filter field
*
* @return string The HTML
*/
protected function getFilter()
{
// Initialize some field attributes.
$format = $this->element['format'] ? (string) $this->element['format'] : '%Y-%m-%d';
$attributes = array();
if ($this->element['size'])
{
$attributes['size'] = (int) $this->element['size'];
}
if ($this->element['maxlength'])
{
$attributes['maxlength'] = (int) $this->element['maxlength'];
}
if ($this->element['filterclass'])
{
$attributes['class'] = (string) $this->element['filterclass'];
}
if ((string) $this->element['readonly'] == 'true')
{
$attributes['readonly'] = 'readonly';
}
if ((string) $this->element['disabled'] == 'true')
{
$attributes['disabled'] = 'disabled';
}
if ($this->element['onchange'])
{
$attributes['onchange'] = (string) $this->element['onchange'];
}
else
{
$onchange = 'document.adminForm.submit()';
}
if ((string) $this->element['placeholder'])
{
$attributes['placeholder'] = JText::_((string) $this->element['placeholder']);
}
$name = $this->element['searchfieldname'] ? $this->element['searchfieldname'] : $this->name;
if ($this->element['searchfieldname'])
{
$model = $this->form->getModel();
$searchvalue = $model->getState((string) $this->element['searchfieldname']);
}
else
{
$searchvalue = $this->value;
}
// Get some system objects.
$config = F0FPlatform::getInstance()->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 = F0FPlatform::getInstance()->getDate($searchvalue, 'UTC');
$date->setTimezone(new DateTimeZone($config->get('offset')));
// Transform the date string.
$searchvalue = $date->format('Y-m-d H:i:s', true, false);
}
break;
case 'USER_UTC':
// Convert a date to UTC based on the user timezone.
if ((int) $searchvalue)
{
// Get a date object based on the correct timezone.
$date = F0FPlatform::getInstance()->getDate($this->value, 'UTC');
$date->setTimezone(new DateTimeZone($user->getParam('timezone', $config->get('offset'))));
// Transform the date string.
$searchvalue = $date->format('Y-m-d H:i:s', true, false);
}
break;
}
return JHtml::_('calendar', $searchvalue, $name, $name, $format, $attributes);
}
/**
* Get the buttons HTML code
*
* @return string The HTML
*/
protected function getButtons()
{
return '';
}
}

View File

@ -0,0 +1,75 @@
<?php
/**
* @package FrameworkOnFramework
* @subpackage form
* @copyright Copyright (C) 2010-2016 Nicholas K. Dionysopoulos / Akeeba Ltd. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
// Protect from unauthorized access
defined('F0F_INCLUDED') or die;
/**
* Generic field header, with text input (search) filter
*
* @package FrameworkOnFramework
* @since 2.0
*/
class F0FFormHeaderFieldfilterable extends F0FFormHeaderFieldsearchable
{
/**
* Get the filter field
*
* @return string The HTML
*/
protected function getFilter()
{
$valide = array('yes', 'true', '1');
// Initialize some field(s) attributes.
$size = $this->element['size'] ? ' size="' . (int) $this->element['size'] . '"' : '';
$maxLength = $this->element['maxlength'] ? ' maxlength="' . (int) $this->element['maxlength'] . '"' : '';
$filterclass = $this->element['filterclass'] ? ' class="' . (string) $this->element['filterclass'] . '"' : '';
$placeholder = $this->element['placeholder'] ? $this->element['placeholder'] : $this->getLabel();
$name = $this->element['searchfieldname'] ? $this->element['searchfieldname'] : $this->name;
$placeholder = ' placeholder="' . JText::_($placeholder) . '"';
$single = in_array($this->element['single'], $valide) ? true : false;
$showMethod = in_array($this->element['showmethod'], $valide) ? true : false;
$method = $this->element['method'] ? $this->element['method'] : 'between';
$fromName = $this->element['fromname'] ? $this->element['fromname'] : 'from';
$toName = $this->element['toname'] ? $this->element['toname'] : 'to';
$values = $this->form->getModel()->getState($name);
$fromValue = $values[$fromName];
$toValue = $values[$toName];
// Initialize JavaScript field attributes.
if ($this->element['onchange'])
{
$onchange = ' onchange="' . (string) $this->element['onchange'] . '"';
}
else
{
$onchange = ' onchange="document.adminForm.submit();"';
}
if ($showMethod)
{
$html = '<input type="text" name="' . $name . '[method]" value="'. $method . '" />';
} else
{
$html = '<input type="hidden" name="' . $name . '[method]" value="'. $method . '" />';
}
$html .= '<input type="text" name="' . $name . '[from]" id="' . $this->id . '_' . $fromName . '"' . ' value="'
. htmlspecialchars($fromValue, ENT_COMPAT, 'UTF-8') . '"' . $filterclass . $size . $placeholder . $onchange . $maxLength . '/>';
if (!$single)
{
$html .= '<input type="text" name="' . $name . '[to]" id="' . $this->id . '_' . $toName . '"' . ' value="'
. htmlspecialchars($toValue, ENT_COMPAT, 'UTF-8') . '"' . $filterclass . $size . $placeholder . $onchange . $maxLength . '/>';
}
return $html;
}
}

View File

@ -0,0 +1,85 @@
<?php
/**
* @package FrameworkOnFramework
* @subpackage form
* @copyright Copyright (C) 2010-2016 Nicholas K. Dionysopoulos / Akeeba Ltd. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
// Protect from unauthorized access
defined('F0F_INCLUDED') or die;
/**
* Generic field header, with text input (search) filter
*
* @package FrameworkOnFramework
* @since 2.0
*/
class F0FFormHeaderFieldsearchable extends F0FFormHeaderField
{
/**
* Get the filter field
*
* @return string The HTML
*/
protected function getFilter()
{
// Initialize some field attributes.
$size = $this->element['size'] ? ' size="' . (int) $this->element['size'] . '"' : '';
$maxLength = $this->element['maxlength'] ? ' maxlength="' . (int) $this->element['maxlength'] . '"' : '';
$filterclass = $this->element['filterclass'] ? ' class="' . (string) $this->element['filterclass'] . '"' : '';
$placeholder = $this->element['placeholder'] ? $this->element['placeholder'] : $this->getLabel();
$name = $this->element['searchfieldname'] ? $this->element['searchfieldname'] : $this->name;
$placeholder = ' placeholder="' . JText::_($placeholder) . '"';
if ($this->element['searchfieldname'])
{
$model = $this->form->getModel();
$searchvalue = $model->getState((string) $this->element['searchfieldname']);
}
else
{
$searchvalue = $this->value;
}
// Initialize JavaScript field attributes.
if ($this->element['onchange'])
{
$onchange = ' onchange="' . (string) $this->element['onchange'] . '"';
}
else
{
$onchange = ' onchange="document.adminForm.submit();"';
}
return '<input type="text" name="' . $name . '" id="' . $this->id . '"' . ' value="'
. htmlspecialchars($searchvalue, ENT_COMPAT, 'UTF-8') . '"' . $filterclass . $size . $placeholder . $onchange . $maxLength . '/>';
}
/**
* Get the buttons HTML code
*
* @return string The HTML
*/
protected function getButtons()
{
$buttonclass = $this->element['buttonclass'] ? (string) $this->element['buttonclass'] : 'btn hasTip hasTooltip';
$buttonsState = strtolower($this->element['buttons']);
$show_buttons = !in_array($buttonsState, array('no', 'false', '0'));
if (!$show_buttons)
{
return '';
}
$html = '';
$html .= '<button class="' . $buttonclass . '" onclick="this.form.submit();" title="' . JText::_('JSEARCH_FILTER') . '" >' . "\n";
$html .= '<i class="icon-search"></i>';
$html .= '</button>' . "\n";
$html .= '<button class="' . $buttonclass . '" onclick="document.adminForm.' . $this->id . '.value=\'\';this.form.submit();" title="' . JText::_('JSEARCH_RESET') . '">' . "\n";
$html .= '<i class="icon-remove"></i>';
$html .= '</button>' . "\n";
return $html;
}
}

View File

@ -0,0 +1,109 @@
<?php
/**
* @package FrameworkOnFramework
* @subpackage form
* @copyright Copyright (C) 2010-2016 Nicholas K. Dionysopoulos / Akeeba Ltd. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
// Protect from unauthorized access
defined('F0F_INCLUDED') or die;
/**
* Generic field header, with drop down filters
*
* @package FrameworkOnFramework
* @since 2.0
*/
class F0FFormHeaderFieldselectable extends F0FFormHeaderField
{
/**
* Create objects for the options
*
* @return array The array of option objects
*/
protected function getOptions()
{
$options = array();
// Get the field $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.
$options[] = JHtml::_(
'select.option',
(string) $option['value'],
JText::alt(
trim((string) $option),
preg_replace('/[^a-zA-Z0-9_\-]/', '_', $this->fieldname)
),
'value', 'text', ((string) $option['disabled'] == 'true')
);
}
// Do we have a class and method source for our options?
$source_file = empty($this->element['source_file']) ? '' : (string) $this->element['source_file'];
$source_class = empty($this->element['source_class']) ? '' : (string) $this->element['source_class'];
$source_method = empty($this->element['source_method']) ? '' : (string) $this->element['source_method'];
$source_key = empty($this->element['source_key']) ? '*' : (string) $this->element['source_key'];
$source_value = empty($this->element['source_value']) ? '*' : (string) $this->element['source_value'];
$source_translate = empty($this->element['source_translate']) ? 'true' : (string) $this->element['source_translate'];
$source_translate = in_array(strtolower($source_translate), array('true','yes','1','on')) ? true : false;
$source_format = empty($this->element['source_format']) ? '' : (string) $this->element['source_format'];
if ($source_class && $source_method)
{
// Maybe we have to load a file?
if (!empty($source_file))
{
$source_file = F0FTemplateUtils::parsePath($source_file, true);
if (F0FPlatform::getInstance()->getIntegrationObject('filesystem')->fileExists($source_file))
{
include_once $source_file;
}
}
// Make sure the class exists
if (class_exists($source_class, true))
{
// ...and so does the option
if (in_array($source_method, get_class_methods($source_class)))
{
// Get the data from the class
if ($source_format == 'optionsobject')
{
$options = array_merge($options, $source_class::$source_method());
}
else
{
$source_data = $source_class::$source_method();
// Loop through the data and prime the $options array
foreach ($source_data as $k => $v)
{
$key = (empty($source_key) || ($source_key == '*')) ? $k : $v[$source_key];
$value = (empty($source_value) || ($source_value == '*')) ? $v : $v[$source_value];
if ($source_translate)
{
$value = JText::_($value);
}
$options[] = JHtml::_('select.option', $key, $value, 'value', 'text');
}
}
}
}
}
reset($options);
return $options;
}
}

View File

@ -0,0 +1,62 @@
<?php
/**
* @package FrameworkOnFramework
* @subpackage form
* @copyright Copyright (C) 2010-2016 Nicholas K. Dionysopoulos / Akeeba Ltd. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
// Protect from unauthorized access
defined('F0F_INCLUDED') or die;
/**
* Generic field header, with drop down filters based on a SQL query
*
* @package FrameworkOnFramework
* @since 2.0
*/
class F0FFormHeaderFieldsql extends F0FFormHeaderFieldselectable
{
/**
* Create objects for the options
*
* @return array The array of option objects
*/
protected function getOptions()
{
$options = array();
// Initialize some field attributes.
$key = $this->element['key_field'] ? (string) $this->element['key_field'] : 'value';
$value = $this->element['value_field'] ? (string) $this->element['value_field'] : (string) $this->element['name'];
$translate = $this->element['translate'] ? (string) $this->element['translate'] : false;
$query = (string) $this->element['query'];
// Get the database object.
$db = F0FPlatform::getInstance()->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,28 @@
<?php
/**
* @package FrameworkOnFramework
* @subpackage form
* @copyright Copyright (C) 2010-2016 Nicholas K. Dionysopoulos / Akeeba Ltd. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
// Protect from unauthorized access
defined('F0F_INCLUDED') or die;
/**
* Generic filter, text box entry with calendar button
*
* @package FrameworkOnFramework
* @since 2.3.3
*/
class F0FFormHeaderFilterdate extends F0FFormHeaderFielddate
{
/**
* Get the header
*
* @return string The header HTML
*/
protected function getHeader()
{
return '';
}
}

View File

@ -0,0 +1,28 @@
<?php
/**
* @package FrameworkOnFramework
* @subpackage form
* @copyright Copyright (C) 2010-2016 Nicholas K. Dionysopoulos / Akeeba Ltd. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
// Protect from unauthorized access
defined('F0F_INCLUDED') or die;
/**
* Generic filter, text box entry with optional buttons
*
* @package FrameworkOnFramework
* @since 2.0
*/
class F0FFormHeaderFilterfilterable extends F0FFormHeaderFieldfilterable
{
/**
* Get the header
*
* @return string The header HTML
*/
protected function getHeader()
{
return '';
}
}

View File

@ -0,0 +1,28 @@
<?php
/**
* @package FrameworkOnFramework
* @subpackage form
* @copyright Copyright (C) 2010-2016 Nicholas K. Dionysopoulos / Akeeba Ltd. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
// Protect from unauthorized access
defined('F0F_INCLUDED') or die;
/**
* Generic filter, text box entry with optional buttons
*
* @package FrameworkOnFramework
* @since 2.0
*/
class F0FFormHeaderFiltersearchable extends F0FFormHeaderFieldsearchable
{
/**
* Get the header
*
* @return string The header HTML
*/
protected function getHeader()
{
return '';
}
}

View File

@ -0,0 +1,28 @@
<?php
/**
* @package FrameworkOnFramework
* @subpackage form
* @copyright Copyright (C) 2010-2016 Nicholas K. Dionysopoulos / Akeeba Ltd. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
// Protect from unauthorized access
defined('F0F_INCLUDED') or die;
/**
* Generic filter, drop-down based on fixed options
*
* @package FrameworkOnFramework
* @since 2.0
*/
class F0FFormHeaderFilterselectable extends F0FFormHeaderFieldselectable
{
/**
* Get the header
*
* @return string The header HTML
*/
protected function getHeader()
{
return '';
}
}

View File

@ -0,0 +1,28 @@
<?php
/**
* @package FrameworkOnFramework
* @subpackage form
* @copyright Copyright (C) 2010-2016 Nicholas K. Dionysopoulos / Akeeba Ltd. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
// Protect from unauthorized access
defined('F0F_INCLUDED') or die;
/**
* Generic filter, drop-down based on SQL query
*
* @package FrameworkOnFramework
* @since 2.0
*/
class F0FFormHeaderFiltersql extends F0FFormHeaderFieldsql
{
/**
* Get the header
*
* @return string The header HTML
*/
protected function getHeader()
{
return '';
}
}

View File

@ -0,0 +1,43 @@
<?php
/**
* @package FrameworkOnFramework
* @subpackage form
* @copyright Copyright (C) 2010-2016 Nicholas K. Dionysopoulos / Akeeba Ltd. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
// Protect from unauthorized access
defined('F0F_INCLUDED') or die;
/**
* Language field header
*
* @package FrameworkOnFramework
* @since 2.0
*/
class F0FFormHeaderLanguage extends F0FFormHeaderFieldselectable
{
/**
* Method to get the filter options.
*
* @return array The filter option objects.
*
* @since 2.0
*/
protected function getOptions()
{
// Initialize some field attributes.
$client = (string) $this->element['client'];
if ($client != 'site' && $client != 'administrator')
{
$client = 'site';
}
// Merge any additional options in the XML definition.
$options = array_merge(
parent::getOptions(), JLanguageHelper::createLanguageList($this->value, constant('JPATH_' . strtoupper($client)), true, true)
);
return $options;
}
}

View File

@ -0,0 +1,105 @@
<?php
/**
* @package FrameworkOnFramework
* @subpackage form
* @copyright Copyright (C) 2010-2016 Nicholas K. Dionysopoulos / Akeeba Ltd. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
// Protect from unauthorized access
defined('F0F_INCLUDED') or die;
if (!class_exists('JFormFieldSql'))
{
require_once JPATH_LIBRARIES . '/joomla/form/fields/sql.php';
}
/**
* Form Field class for F0F
* Generic list from a model's results
*
* @package FrameworkOnFramework
* @since 2.0
*/
class F0FFormHeaderModel extends F0FFormHeaderFieldselectable
{
/**
* Method to get the field options.
*
* @return array The field option objects.
*/
protected function getOptions()
{
$options = array();
// Initialize some field attributes.
$key = $this->element['key_field'] ? (string) $this->element['key_field'] : 'value';
$value = $this->element['value_field'] ? (string) $this->element['value_field'] : (string) $this->element['name'];
$applyAccess = $this->element['apply_access'] ? (string) $this->element['apply_access'] : 'false';
$modelName = (string) $this->element['model'];
$nonePlaceholder = (string) $this->element['none'];
$translate = empty($this->element['translate']) ? 'true' : (string) $this->element['translate'];
$translate = in_array(strtolower($translate), array('true','yes','1','on')) ? true : false;
if (!empty($nonePlaceholder))
{
$options[] = JHtml::_('select.option', null, JText::_($nonePlaceholder));
}
// Process field atrtibutes
$applyAccess = strtolower($applyAccess);
$applyAccess = in_array($applyAccess, array('yes', 'on', 'true', '1'));
// Explode model name into model name and prefix
$parts = F0FInflector::explode($modelName);
$mName = ucfirst(array_pop($parts));
$mPrefix = F0FInflector::implode($parts);
// Get the model object
$config = array('savestate' => 0);
$model = F0FModel::getTmpInstance($mName, $mPrefix, $config);
if ($applyAccess)
{
$model->applyAccessFiltering();
}
// Process state variables
foreach ($this->element->children() as $stateoption)
{
// Only add <option /> elements.
if ($stateoption->getName() != 'state')
{
continue;
}
$stateKey = (string) $stateoption['key'];
$stateValue = (string) $stateoption;
$model->setState($stateKey, $stateValue);
}
// Set the query and get the result list.
$items = $model->getItemList(true);
// Build the field options.
if (!empty($items))
{
foreach ($items as $item)
{
if ($translate == true)
{
$options[] = JHtml::_('select.option', $item->$key, JText::_($item->$value));
}
else
{
$options[] = JHtml::_('select.option', $item->$key, $item->$value);
}
}
}
// Merge any additional options in the XML definition.
$options = array_merge(parent::getOptions(), $options);
return $options;
}
}

View File

@ -0,0 +1,73 @@
<?php
/**
* @package FrameworkOnFramework
* @subpackage form
* @copyright Copyright (C) 2010-2016 Nicholas K. Dionysopoulos / Akeeba Ltd. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
// Protect from unauthorized access
defined('F0F_INCLUDED') or die;
/**
* Ordering field header
*
* @package FrameworkOnFramework
* @since 2.0
*/
class F0FFormHeaderOrdering extends F0FFormHeader
{
/**
* Get the header
*
* @return string The header HTML
*/
protected function getHeader()
{
$sortable = ($this->element['sortable'] != 'false');
$view = $this->form->getView();
$model = $this->form->getModel();
$hasAjaxOrderingSupport = $view->hasAjaxOrderingSupport();
if (!$sortable)
{
// Non sortable?! I'm not sure why you'd want that, but if you insist...
return JText::_('JGRID_HEADING_ORDERING');
}
if (!$hasAjaxOrderingSupport)
{
// Ye olde Joomla! 2.5 method
$html = JHTML::_('grid.sort', 'JFIELD_ORDERING_LABEL', 'ordering', $view->getLists()->order_Dir, $view->getLists()->order, 'browse');
$html .= JHTML::_('grid.order', $model->getList());
return $html;
}
else
{
// The new, drag'n'drop ordering support WITH a save order button
$html = JHtml::_(
'grid.sort',
'<i class="icon-menu-2"></i>',
'ordering',
$view->getLists()->order_Dir,
$view->getLists()->order,
null,
'asc',
'JGRID_HEADING_ORDERING'
);
$ordering = $view->getLists()->order == 'ordering';
if ($ordering)
{
$html .= '<a href="javascript:saveorder(' . (count($model->getList()) - 1) . ', \'saveorder\')" ' .
'rel="tooltip" class="save-order btn btn-micro pull-right" title="' . JText::_('JLIB_HTML_SAVE_ORDER') . '">'
. '<span class="icon-ok"></span></a>';
}
return $html;
}
}
}

View File

@ -0,0 +1,67 @@
<?php
/**
* @package FrameworkOnFramework
* @subpackage form
* @copyright Copyright (C) 2010-2016 Nicholas K. Dionysopoulos / Akeeba Ltd. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
// Protect from unauthorized access
defined('F0F_INCLUDED') or die;
/**
* Field header for Published (enabled) columns
*
* @package FrameworkOnFramework
* @since 2.0
*/
class F0FFormHeaderPublished extends F0FFormHeaderFieldselectable
{
/**
* Create objects for the options
*
* @return array The array of option objects
*/
protected function getOptions()
{
$config = array(
'published' => 1,
'unpublished' => 1,
'archived' => 0,
'trash' => 0,
'all' => 0,
);
$stack = array();
if ($this->element['show_published'] == 'false')
{
$config['published'] = 0;
}
if ($this->element['show_unpublished'] == 'false')
{
$config['unpublished'] = 0;
}
if ($this->element['show_archived'] == 'true')
{
$config['archived'] = 1;
}
if ($this->element['show_trash'] == 'true')
{
$config['trash'] = 1;
}
if ($this->element['show_all'] == 'true')
{
$config['all'] = 1;
}
$options = JHtml::_('jgrid.publishedOptions', $config);
reset($options);
return $options;
}
}

View File

@ -0,0 +1,30 @@
<?php
/**
* @package FrameworkOnFramework
* @subpackage form
* @copyright Copyright (C) 2010-2016 Nicholas K. Dionysopoulos / Akeeba Ltd. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
// Protect from unauthorized access
defined('F0F_INCLUDED') or die;
/**
* Row selection checkbox
*
* @package FrameworkOnFramework
* @since 2.0
*/
class F0FFormHeaderRowselect extends F0FFormHeader
{
/**
* Get the header
*
* @return string The header HTML
*/
protected function getHeader()
{
return '<input type="checkbox" name="checkall-toggle" value="" title="'
. JText::_('JGLOBAL_CHECK_ALL')
. '" onclick="Joomla.checkAll(this)" />';
}
}

View File

@ -0,0 +1,232 @@
<?php
/**
* @package FrameworkOnFramework
* @subpackage form
* @copyright Copyright (C) 2010-2016 Nicholas K. Dionysopoulos / Akeeba Ltd. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
// Protect from unauthorized access
defined('F0F_INCLUDED') or die;
JLoader::import('joomla.form.helper');
/**
* F0FForm's helper class.
* Provides a storage for filesystem's paths where F0FForm's entities reside and
* methods for creating those entities. Also stores objects with entities'
* prototypes for further reusing.
*
* @package FrameworkOnFramework
* @since 2.0
*/
class F0FFormHelper extends JFormHelper
{
/**
* 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 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 loadHeaderType($type, $new = true)
{
return self::loadType('header', $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 F0FFormHeader 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 loadHeaderClass($type)
{
return self::loadClass('header', $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 2.0
*/
public static function loadClass($entity, $type)
{
if (strpos($type, '.'))
{
list($prefix, $type) = explode('.', $type);
$altPrefix = $prefix;
}
else
{
$prefix = 'F0F';
$altPrefix = 'J';
}
$class = JString::ucfirst($prefix, '_') . 'Form' . JString::ucfirst($entity, '_') . JString::ucfirst($type, '_');
$altClass = JString::ucfirst($altPrefix, '_') . 'Form' . JString::ucfirst($entity, '_') . JString::ucfirst($type, '_');
if (class_exists($class))
{
return $class;
}
elseif (class_exists($altClass))
{
return $altClass;
}
// 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';
$filesystem = F0FPlatform::getInstance()->getIntegrationObject('filesystem');
foreach ($paths as $path)
{
if ($file = $filesystem->pathFind($path, $type))
{
require_once $file;
if (class_exists($class))
{
break;
}
elseif (class_exists($altClass))
{
break;
}
}
}
// Check for all if the class exists.
if (class_exists($class))
{
return $class;
}
elseif (class_exists($altClass))
{
return $altClass;
}
else
{
return false;
}
}
/**
* Method to add a path to the list of header include paths.
*
* @param mixed $new A path or array of paths to add.
*
* @return array The list of paths that have been added.
*/
public static function addHeaderPath($new = null)
{
return self::addPath('header', $new);
}
}