first commit

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

View File

@ -0,0 +1,294 @@
<?php
/**
* @package Joomla.Platform
* @subpackage HTML
*
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
defined('JPATH_PLATFORM') or die;
/**
* Extended Utility class for all HTML drawing classes.
*
* @package Joomla.Platform
* @subpackage HTML
* @since 1.6
*/
abstract class JHtmlAccess
{
/**
* A cached array of the asset groups
*
* @var array
* @since 1.6
*/
protected static $asset_groups = null;
/**
* Displays a list of the available access view levels
*
* @param string $name The form field name.
* @param string $selected The name of the selected section.
* @param string $attribs Additional attributes to add to the select field.
* @param mixed $params True to add "All Sections" option or and array of options
* @param string $id The form field id
*
* @return string The required HTML for the SELECT tag.
*
* @see JFormFieldAccessLevel
* @since 1.6
*/
public static function level($name, $selected, $attribs = '', $params = true, $id = false)
{
$db = JFactory::getDbo();
$query = $db->getQuery(true)
->select('a.id AS value, a.title AS text')
->from('#__viewlevels AS a')
->group('a.id, a.title, a.ordering')
->order('a.ordering ASC')
->order($db->quoteName('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 JHtml::_(
'select.genericlist',
$options,
$name,
array(
'list.attr' => $attribs,
'list.select' => $selected,
'id' => $id
)
);
}
/**
* Displays a list of the available user groups.
*
* @param string $name The form field name.
* @param string $selected The name of the selected section.
* @param string $attribs Additional attributes to add to the select field.
* @param boolean $allowAll True to add "All Groups" option.
*
* @return string The required HTML for the SELECT tag.
*
* @see JFormFieldUsergroup
* @since 1.6
*/
public static function usergroup($name, $selected, $attribs = '', $allowAll = true)
{
$db = JFactory::getDbo();
$query = $db->getQuery(true)
->select('a.id AS value, a.title AS text, COUNT(DISTINCT b.id) AS level')
->from($db->quoteName('#__usergroups') . ' AS a')
->join('LEFT', $db->quoteName('#__usergroups') . ' AS b ON a.lft > b.lft AND a.rgt < b.rgt')
->group('a.id, a.title, a.lft, a.rgt')
->order('a.lft ASC');
$db->setQuery($query);
$options = $db->loadObjectList();
for ($i = 0, $n = count($options); $i < $n; $i++)
{
$options[$i]->text = str_repeat('- ', $options[$i]->level) . $options[$i]->text;
}
// If all usergroups is allowed, push it into the array.
if ($allowAll)
{
array_unshift($options, JHtml::_('select.option', '', JText::_('JOPTION_ACCESS_SHOW_ALL_GROUPS')));
}
return JHtml::_('select.genericlist', $options, $name, array('list.attr' => $attribs, 'list.select' => $selected));
}
/**
* Returns a UL list of user groups with check boxes
*
* @param string $name The name of the checkbox controls array
* @param array $selected An array of the checked boxes
* @param boolean $checkSuperAdmin If false only super admins can add to super admin groups
*
* @return string
*
* @since 1.6
*/
public static function usergroups($name, $selected, $checkSuperAdmin = false)
{
static $count;
$count++;
$isSuperAdmin = JFactory::getUser()->authorise('core.admin');
$db = JFactory::getDbo();
$query = $db->getQuery(true)
->select('a.*, COUNT(DISTINCT b.id) AS level')
->from($db->quoteName('#__usergroups') . ' AS a')
->join('LEFT', $db->quoteName('#__usergroups') . ' AS b ON a.lft > b.lft AND a.rgt < b.rgt')
->group('a.id, a.title, a.lft, a.rgt, a.parent_id')
->order('a.lft ASC');
$db->setQuery($query);
$groups = $db->loadObjectList();
$html = array();
for ($i = 0, $n = count($groups); $i < $n; $i++)
{
$item = &$groups[$i];
// If checkSuperAdmin is true, only add item if the user is superadmin or the group is not super admin
if ((!$checkSuperAdmin) || $isSuperAdmin || (!JAccess::checkGroup($item->id, 'core.admin')))
{
// Setup the variable attributes.
$eid = $count . 'group_' . $item->id;
// Don't call in_array unless something is selected
$checked = '';
if ($selected)
{
$checked = in_array($item->id, $selected) ? ' checked="checked"' : '';
}
$rel = ($item->parent_id > 0) ? ' rel="' . $count . 'group_' . $item->parent_id . '"' : '';
// Build the HTML for the item.
$html[] = ' <div class="control-group">';
$html[] = ' <div class="controls">';
$html[] = ' <label class="checkbox" for="' . $eid . '">';
$html[] = ' <input type="checkbox" name="' . $name . '[]" value="' . $item->id . '" id="' . $eid . '"';
$html[] = ' ' . $checked . $rel . ' />';
$html[] = ' ' . str_repeat('<span class="gi">|&mdash;</span>', $item->level) . $item->title;
$html[] = ' </label>';
$html[] = ' </div>';
$html[] = ' </div>';
}
}
return implode("\n", $html);
}
/**
* Returns a UL list of actions with check boxes
*
* @param string $name The name of the checkbox controls array
* @param array $selected An array of the checked boxes
* @param string $component The component the permissions apply to
* @param string $section The section (within a component) the permissions apply to
*
* @return string
*
* @see JAccess
* @since 1.6
*/
public static function actions($name, $selected, $component, $section = 'global')
{
static $count;
$count++;
$actions = JAccess::getActionsFromFile(
JPATH_ADMINISTRATOR . '/components/' . $component . '/access.xml',
"/access/section[@name='" . $section . "']/"
);
$html = array();
$html[] = '<ul class="checklist access-actions">';
for ($i = 0, $n = count($actions); $i < $n; $i++)
{
$item = &$actions[$i];
// Setup the variable attributes.
$eid = $count . 'action_' . $item->id;
$checked = in_array($item->id, $selected) ? ' checked="checked"' : '';
// Build the HTML for the item.
$html[] = ' <li>';
$html[] = ' <input type="checkbox" name="' . $name . '[]" value="' . $item->id . '" id="' . $eid . '"';
$html[] = ' ' . $checked . ' />';
$html[] = ' <label for="' . $eid . '">';
$html[] = ' ' . JText::_($item->title);
$html[] = ' </label>';
$html[] = ' </li>';
}
$html[] = '</ul>';
return implode("\n", $html);
}
/**
* Gets a list of the asset groups as an array of JHtml compatible options.
*
* @return mixed An array or false if an error occurs
*
* @since 1.6
*/
public static function assetgroups()
{
if (empty(static::$asset_groups))
{
$db = JFactory::getDbo();
$query = $db->getQuery(true)
->select('a.id AS value, a.title AS text')
->from($db->quoteName('#__viewlevels') . ' AS a')
->group('a.id, a.title, a.ordering')
->order('a.ordering ASC');
$db->setQuery($query);
static::$asset_groups = $db->loadObjectList();
}
return static::$asset_groups;
}
/**
* Displays a Select list of the available asset groups
*
* @param string $name The name of the select element
* @param mixed $selected The selected asset group id
* @param string $attribs Optional attributes for the select field
* @param array $config An array of options for the control
*
* @return mixed An HTML string or null if an error occurs
*
* @since 1.6
*/
public static function assetgrouplist($name, $selected, $attribs = null, $config = array())
{
static $count;
$options = static::assetgroups();
if (isset($config['title']))
{
array_unshift($options, JHtml::_('select.option', '', $config['title']));
}
return JHtml::_(
'select.genericlist',
$options,
$name,
array(
'id' => isset($config['id']) ? $config['id'] : 'assetgroups_' . (++$count),
'list.attr' => (is_null($attribs) ? 'class="inputbox" size="3"' : $attribs),
'list.select' => (int) $selected
)
);
}
}

View File

@ -0,0 +1,159 @@
<?php
/**
* @package Joomla.Libraries
* @subpackage HTML
*
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
defined('JPATH_BASE') or die;
/**
* Extended Utility class for batch processing widgets.
*
* @package Joomla.Libraries
* @subpackage HTML
* @since 1.7
*/
abstract class JHtmlBatch
{
/**
* Display a batch widget for the access level selector.
*
* @return string The necessary HTML for the widget.
*
* @since 1.7
*/
public static function access()
{
JHtml::_('bootstrap.tooltip');
// Create the batch selector to change an access level on a selection list.
return
'<label id="batch-access-lbl" for="batch-access" class="hasToolip"'
. 'title="' . JHtml::tooltipText('JLIB_HTML_BATCH_ACCESS_LABEL', 'JLIB_HTML_BATCH_ACCESS_LABEL_DESC') . '">'
. JText::_('JLIB_HTML_BATCH_ACCESS_LABEL')
. '</label>'
. JHtml::_(
'access.assetgrouplist',
'batch[assetgroup_id]', '',
'class="inputbox"',
array(
'title' => JText::_('JLIB_HTML_BATCH_NOCHANGE'),
'id' => 'batch-access'
)
);
return implode("\n", $lines);
}
/**
* Displays a batch widget for moving or copying items.
*
* @param string $extension The extension that owns the category.
*
* @return string The necessary HTML for the widget.
*
* @since 1.7
*/
public static function item($extension)
{
// Create the copy/move options.
$options = array(
JHtml::_('select.option', 'c', JText::_('JLIB_HTML_BATCH_COPY')),
JHtml::_('select.option', 'm', JText::_('JLIB_HTML_BATCH_MOVE'))
);
// Create the batch selector to change select the category by which to move or copy.
return
'<label id="batch-choose-action-lbl" for="batch-choose-action">' . JText::_('JLIB_HTML_BATCH_MENU_LABEL') . '</label>'
. '<div id="batch-choose-action" class="control-group">'
. '<select name="batch[category_id]" class="inputbox" id="batch-category-id">'
. '<option value="">' . JText::_('JSELECT') . '</option>'
. JHtml::_('select.options', JHtml::_('category.options', $extension))
. '</select>'
. '</div>'
. '<div id="batch-move-copy" class="control-group radio">'
. JHtml::_('select.radiolist', $options, 'batch[move_copy]', '', 'value', 'text', 'm')
. '</div><hr />';
}
/**
* Display a batch widget for the language selector.
*
* @return string The necessary HTML for the widget.
*
* @since 2.5
*/
public static function language()
{
JHtml::_('bootstrap.tooltip');
// Create the batch selector to change the language on a selection list.
return
'<label id="batch-language-lbl" for="batch-language-id" class="hasToolip"'
. ' title="' . JHtml::tooltipText('JLIB_HTML_BATCH_LANGUAGE_LABEL', 'JLIB_HTML_BATCH_LANGUAGE_LABEL_DESC') . '">'
. JText::_('JLIB_HTML_BATCH_LANGUAGE_LABEL')
. '</label>'
. '<select name="batch[language_id]" class="inputbox" id="batch-language-id">'
. '<option value="">' . JText::_('JLIB_HTML_BATCH_LANGUAGE_NOCHANGE') . '</option>'
. JHtml::_('select.options', JHtml::_('contentlanguage.existing', true, true), 'value', 'text')
. '</select>';
}
/**
* Display a batch widget for the user selector.
*
* @param boolean $noUser Choose to display a "no user" option
*
* @return string The necessary HTML for the widget.
*
* @since 2.5
*/
public static function user($noUser = true)
{
JHtml::_('bootstrap.tooltip');
$optionNo = '';
if ($noUser)
{
$optionNo = '<option value="0">' . JText::_('JLIB_HTML_BATCH_USER_NOUSER') . '</option>';
}
// Create the batch selector to select a user on a selection list.
return
'<label id="batch-user-lbl" for="batch-user" class="hasTooltip"'
. ' title="' . JHtml::tooltipText('JLIB_HTML_BATCH_USER_LABEL', 'JLIB_HTML_BATCH_USER_LABEL_DESC') . '">'
. JText::_('JLIB_HTML_BATCH_USER_LABEL')
. '</label>'
. '<select name="batch[user_id]" class="inputbox" id="batch-user-id">'
. '<option value="">' . JText::_('JLIB_HTML_BATCH_USER_NOCHANGE') . '</option>'
. $optionNo
. JHtml::_('select.options', JHtml::_('user.userlist'), 'value', 'text')
. '</select>';
}
/**
* Display a batch widget for the tag selector.
*
* @return string The necessary HTML for the widget.
*
* @since 3.1
*/
public static function tag()
{
JHtml::_('bootstrap.tooltip');
// Create the batch selector to tag items on a selection list.
return
'<label id="batch-tag-lbl" for="batch-tag-id" class="hasTooltip"'
. ' title="' . JHtml::tooltipText('JLIB_HTML_BATCH_TAG_LABEL', 'JLIB_HTML_BATCH_TAG_LABEL_DESC') . '">'
. JText::_('JLIB_HTML_BATCH_TAG_LABEL')
. '</label>'
. '<select name="batch[tag]" class="inputbox" id="batch-tag-id">'
. '<option value="">' . JText::_('JLIB_HTML_BATCH_TAG_NOCHANGE') . '</option>'
. JHtml::_('select.options', JHtml::_('tag.tags', array('filter.published' => array(1))), 'value', 'text')
. '</select>';
}
}

View File

@ -0,0 +1,781 @@
<?php
/**
* @package Joomla.Libraries
* @subpackage HTML
*
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
defined('JPATH_PLATFORM') or die;
/**
* Utility class for JavaScript behaviors
*
* @package Joomla.Libraries
* @subpackage HTML
* @since 1.5
*/
abstract class JHtmlBehavior
{
/**
* Array containing information for loaded files
*
* @var array
* @since 2.5
*/
protected static $loaded = array();
/**
* Method to load the MooTools framework into the document head
*
* If debugging mode is on an uncompressed version of MooTools is included for easier debugging.
*
* @param boolean $extras Flag to determine whether to load MooTools More in addition to Core
* @param mixed $debug Is debugging mode on? [optional]
*
* @return void
*
* @since 1.6
*/
public static function framework($extras = false, $debug = null)
{
$type = $extras ? 'more' : 'core';
// Only load once
if (!empty(static::$loaded[__METHOD__][$type]))
{
return;
}
// If no debugging value is set, use the configuration setting
if ($debug === null)
{
$config = JFactory::getConfig();
$debug = $config->get('debug');
}
if ($type != 'core' && empty(static::$loaded[__METHOD__]['core']))
{
static::framework(false, $debug);
}
JHtml::_('script', 'system/mootools-' . $type . '.js', false, true, false, false, $debug);
JHtml::_('script', 'system/core.js', false, true);
static::$loaded[__METHOD__][$type] = true;
return;
}
/**
* Add unobtrusive JavaScript support for image captions.
*
* @param string $selector The selector for which a caption behaviour is to be applied.
*
* @return void
*
* @since 1.5
*/
public static function caption($selector = 'img.caption')
{
// Only load once
if (isset(static::$loaded[__METHOD__][$selector]))
{
return;
}
// Include MooTools framework
static::framework();
JHtml::_('script', 'system/caption.js', true, true);
// Attach caption to document
JFactory::getDocument()->addScriptDeclaration(
"window.addEvent('load', function() {
new JCaption('" . $selector . "');
});"
);
// Set static array
static::$loaded[__METHOD__][$selector] = true;
}
/**
* Add unobtrusive JavaScript support for form validation.
*
* To enable form validation the form tag must have class="form-validate".
* Each field that needs to be validated needs to have class="validate".
* Additional handlers can be added to the handler for username, password,
* numeric and email. To use these add class="validate-email" and so on.
*
* @return void
*
* @since 1.5
*/
public static function formvalidation()
{
// Only load once
if (isset(static::$loaded[__METHOD__]))
{
return;
}
// Add validate.js language strings
JText::script('JLIB_FORM_FIELD_INVALID');
// Include MooTools More framework
static::framework('more');
JHtml::_('script', 'system/validate.js', true, true);
static::$loaded[__METHOD__] = true;
}
/**
* Add unobtrusive JavaScript support for submenu switcher support
*
* @return void
*
* @since 1.5
*/
public static function switcher()
{
// Only load once
if (isset(static::$loaded[__METHOD__]))
{
return;
}
// Include MooTools framework
static::framework();
JHtml::_('script', 'system/switcher.js', true, true);
$script = "
document.switcher = null;
window.addEvent('domready', function(){
toggler = document.id('submenu');
element = document.id('config-document');
if (element) {
document.switcher = new JSwitcher(toggler, element, {cookieName: toggler.getProperty('class')});
}
});";
JFactory::getDocument()->addScriptDeclaration($script);
static::$loaded[__METHOD__] = true;
}
/**
* Add unobtrusive JavaScript support for a combobox effect.
*
* Note that this control is only reliable in absolutely positioned elements.
* Avoid using a combobox in a slider or dynamic pane.
*
* @return void
*
* @since 1.5
*/
public static function combobox()
{
if (isset(static::$loaded[__METHOD__]))
{
return;
}
// Include MooTools framework
static::framework();
JHtml::_('script', 'system/combobox.js', true, true);
static::$loaded[__METHOD__] = true;
}
/**
* Add unobtrusive JavaScript support for a hover tooltips.
*
* Add a title attribute to any element in the form
* title="title::text"
*
* Uses the core Tips class in MooTools.
*
* @param string $selector The class selector for the tooltip.
* @param array $params An array of options for the tooltip.
* Options for the tooltip can be:
* - maxTitleChars integer The maximum number of characters in the tooltip title (defaults to 50).
* - offsets object The distance of your tooltip from the mouse (defaults to {'x': 16, 'y': 16}).
* - showDelay integer The millisecond delay the show event is fired (defaults to 100).
* - hideDelay integer The millisecond delay the hide hide is fired (defaults to 100).
* - className string The className your tooltip container will get.
* - fixed boolean If set to true, the toolTip will not follow the mouse.
* - onShow function The default function for the show event, passes the tip element
* and the currently hovered element.
* - onHide function The default function for the hide event, passes the currently
* hovered element.
*
* @return void
*
* @since 1.5
*/
public static function tooltip($selector = '.hasTip', $params = array())
{
$sig = md5(serialize(array($selector, $params)));
if (isset(static::$loaded[__METHOD__][$sig]))
{
return;
}
// Include MooTools framework
static::framework(true);
// Setup options object
$opt['maxTitleChars'] = (isset($params['maxTitleChars']) && ($params['maxTitleChars'])) ? (int) $params['maxTitleChars'] : 50;
// Offsets needs an array in the format: array('x'=>20, 'y'=>30)
$opt['offset'] = (isset($params['offset']) && (is_array($params['offset']))) ? $params['offset'] : null;
$opt['showDelay'] = (isset($params['showDelay'])) ? (int) $params['showDelay'] : null;
$opt['hideDelay'] = (isset($params['hideDelay'])) ? (int) $params['hideDelay'] : null;
$opt['className'] = (isset($params['className'])) ? $params['className'] : null;
$opt['fixed'] = (isset($params['fixed']) && ($params['fixed'])) ? true : false;
$opt['onShow'] = (isset($params['onShow'])) ? '\\' . $params['onShow'] : null;
$opt['onHide'] = (isset($params['onHide'])) ? '\\' . $params['onHide'] : null;
$options = JHtml::getJSObject($opt);
// Attach tooltips to document
JFactory::getDocument()->addScriptDeclaration(
"window.addEvent('domready', function() {
$$('$selector').each(function(el) {
var title = el.get('title');
if (title) {
var parts = title.split('::', 2);
el.store('tip:title', parts[0]);
el.store('tip:text', parts[1]);
}
});
var JTooltips = new Tips($$('$selector'), $options);
});"
);
// Set static array
static::$loaded[__METHOD__][$sig] = true;
return;
}
/**
* Add unobtrusive JavaScript support for modal links.
*
* @param string $selector The selector for which a modal behaviour is to be applied.
* @param array $params An array of parameters for the modal behaviour.
* Options for the modal behaviour can be:
* - ajaxOptions
* - size
* - shadow
* - overlay
* - onOpen
* - onClose
* - onUpdate
* - onResize
* - onShow
* - onHide
*
* @return void
*
* @since 1.5
*/
public static function modal($selector = 'a.modal', $params = array())
{
$document = JFactory::getDocument();
// Load the necessary files if they haven't yet been loaded
if (!isset(static::$loaded[__METHOD__]))
{
// Include MooTools framework
static::framework(true);
// Load the JavaScript and css
JHtml::_('script', 'system/modal.js', true, true);
JHtml::_('stylesheet', 'system/modal.css', array(), true);
}
$sig = md5(serialize(array($selector, $params)));
if (isset(static::$loaded[__METHOD__][$sig]))
{
return;
}
// Setup options object
$opt['ajaxOptions'] = (isset($params['ajaxOptions']) && (is_array($params['ajaxOptions']))) ? $params['ajaxOptions'] : null;
$opt['handler'] = (isset($params['handler'])) ? $params['handler'] : null;
$opt['parseSecure'] = (isset($params['parseSecure'])) ? (bool) $params['parseSecure'] : null;
$opt['closable'] = (isset($params['closable'])) ? (bool) $params['closable'] : null;
$opt['closeBtn'] = (isset($params['closeBtn'])) ? (bool) $params['closeBtn'] : null;
$opt['iframePreload'] = (isset($params['iframePreload'])) ? (bool) $params['iframePreload'] : null;
$opt['iframeOptions'] = (isset($params['iframeOptions']) && (is_array($params['iframeOptions']))) ? $params['iframeOptions'] : null;
$opt['size'] = (isset($params['size']) && (is_array($params['size']))) ? $params['size'] : null;
$opt['shadow'] = (isset($params['shadow'])) ? $params['shadow'] : null;
$opt['overlay'] = (isset($params['overlay'])) ? $params['overlay'] : null;
$opt['onOpen'] = (isset($params['onOpen'])) ? $params['onOpen'] : null;
$opt['onClose'] = (isset($params['onClose'])) ? $params['onClose'] : null;
$opt['onUpdate'] = (isset($params['onUpdate'])) ? $params['onUpdate'] : null;
$opt['onResize'] = (isset($params['onResize'])) ? $params['onResize'] : null;
$opt['onMove'] = (isset($params['onMove'])) ? $params['onMove'] : null;
$opt['onShow'] = (isset($params['onShow'])) ? $params['onShow'] : null;
$opt['onHide'] = (isset($params['onHide'])) ? $params['onHide'] : null;
if (isset($params['fullScreen']) && (bool) $params['fullScreen'])
{
$opt['size'] = array('x' => '\\window.getSize().x-80', 'y' => '\\window.getSize().y-80');
}
$options = JHtml::getJSObject($opt);
// Attach modal behavior to document
$document
->addScriptDeclaration(
"
window.addEvent('domready', function() {
SqueezeBox.initialize(" . $options . ");
SqueezeBox.assign($$('" . $selector . "'), {
parse: 'rel'
});
});"
);
// Set static array
static::$loaded[__METHOD__][$sig] = true;
return;
}
/**
* JavaScript behavior to allow shift select in grids
*
* @param string $id The id of the form for which a multiselect behaviour is to be applied.
*
* @return void
*
* @since 1.7
*/
public static function multiselect($id = 'adminForm')
{
// Only load once
if (isset(static::$loaded[__METHOD__][$id]))
{
return;
}
// Include MooTools framework
static::framework();
JHtml::_('script', 'system/multiselect.js', true, true);
// Attach multiselect to document
JFactory::getDocument()->addScriptDeclaration(
"window.addEvent('domready', function() {
new Joomla.JMultiSelect('" . $id . "');
});"
);
// Set static array
static::$loaded[__METHOD__][$id] = true;
return;
}
/**
* Add unobtrusive javascript support for a collapsible tree.
*
* @param string $id An index
* @param array $params An array of options.
* @param array $root The root node
*
* @return void
*
* @since 1.5
*/
public static function tree($id, $params = array(), $root = array())
{
// Include MooTools framework
static::framework();
JHtml::_('script', 'system/mootree.js', true, true, false, false);
JHtml::_('stylesheet', 'system/mootree.css', array(), true);
if (isset(static::$loaded[__METHOD__][$id]))
{
return;
}
// Setup options object
$opt['div'] = (array_key_exists('div', $params)) ? $params['div'] : $id . '_tree';
$opt['mode'] = (array_key_exists('mode', $params)) ? $params['mode'] : 'folders';
$opt['grid'] = (array_key_exists('grid', $params)) ? '\\' . $params['grid'] : true;
$opt['theme'] = (array_key_exists('theme', $params)) ? $params['theme'] : JHtml::_('image', 'system/mootree.gif', '', array(), true, true);
// Event handlers
$opt['onExpand'] = (array_key_exists('onExpand', $params)) ? '\\' . $params['onExpand'] : null;
$opt['onSelect'] = (array_key_exists('onSelect', $params)) ? '\\' . $params['onSelect'] : null;
$opt['onClick'] = (array_key_exists('onClick', $params)) ? '\\' . $params['onClick']
: '\\function(node){ window.open(node.data.url, node.data.target != null ? node.data.target : \'_self\'); }';
$options = JHtml::getJSObject($opt);
// Setup root node
$rt['text'] = (array_key_exists('text', $root)) ? $root['text'] : 'Root';
$rt['id'] = (array_key_exists('id', $root)) ? $root['id'] : null;
$rt['color'] = (array_key_exists('color', $root)) ? $root['color'] : null;
$rt['open'] = (array_key_exists('open', $root)) ? '\\' . $root['open'] : true;
$rt['icon'] = (array_key_exists('icon', $root)) ? $root['icon'] : null;
$rt['openicon'] = (array_key_exists('openicon', $root)) ? $root['openicon'] : null;
$rt['data'] = (array_key_exists('data', $root)) ? $root['data'] : null;
$rootNode = JHtml::getJSObject($rt);
$treeName = (array_key_exists('treeName', $params)) ? $params['treeName'] : '';
$js = ' window.addEvent(\'domready\', function(){
tree' . $treeName . ' = new MooTreeControl(' . $options . ',' . $rootNode . ');
tree' . $treeName . '.adopt(\'' . $id . '\');})';
// Attach tooltips to document
$document = JFactory::getDocument();
$document->addScriptDeclaration($js);
// Set static array
static::$loaded[__METHOD__][$id] = true;
return;
}
/**
* Add unobtrusive JavaScript support for a calendar control.
*
* @return void
*
* @since 1.5
*/
public static function calendar()
{
// Only load once
if (isset(static::$loaded[__METHOD__]))
{
return;
}
$document = JFactory::getDocument();
$tag = JFactory::getLanguage()->getTag();
JHtml::_('stylesheet', 'system/calendar-jos.css', array(' title' => JText::_('JLIB_HTML_BEHAVIOR_GREEN'), ' media' => 'all'), true);
JHtml::_('script', $tag . '/calendar.js', false, true);
JHtml::_('script', $tag . '/calendar-setup.js', false, true);
$translation = static::calendartranslation();
if ($translation)
{
$document->addScriptDeclaration($translation);
}
static::$loaded[__METHOD__] = true;
}
/**
* Add unobtrusive JavaScript support for a color picker.
*
* @return void
*
* @since 1.7
*/
public static function colorpicker()
{
// Only load once
if (isset(static::$loaded[__METHOD__]))
{
return;
}
// Include jQuery
JHtml::_('jquery.framework');
JHtml::_('script', 'jui/jquery.minicolors.min.js', false, true);
JHtml::_('stylesheet', 'jui/jquery.minicolors.css', false, true);
JFactory::getDocument()->addScriptDeclaration("
jQuery(document).ready(function (){
jQuery('.minicolors').each(function() {
jQuery(this).minicolors({
control: jQuery(this).attr('data-control') || 'hue',
position: jQuery(this).attr('data-position') || 'right',
theme: 'bootstrap'
});
});
});
"
);
static::$loaded[__METHOD__] = true;
}
/**
* Add unobtrusive JavaScript support for a simple color picker.
*
* @return void
*
* @since 3.1
*/
public static function simplecolorpicker()
{
// Only load once
if (isset(static::$loaded[__METHOD__]))
{
return;
}
// Include jQuery
JHtml::_('jquery.framework');
JHtml::_('script', 'jui/jquery.simplecolors.min.js', false, true);
JHtml::_('stylesheet', 'jui/jquery.simplecolors.css', false, true);
JFactory::getDocument()->addScriptDeclaration("
jQuery(document).ready(function (){
jQuery('select.simplecolors').simplecolors();
});
"
);
static::$loaded[__METHOD__] = true;
}
/**
* Keep session alive, for example, while editing or creating an article.
*
* @return void
*
* @since 1.5
*/
public static function keepalive()
{
// Only load once
if (isset(static::$loaded[__METHOD__]))
{
return;
}
// Include MooTools framework
static::framework();
$config = JFactory::getConfig();
$lifetime = ($config->get('lifetime') * 60000);
$refreshTime = ($lifetime <= 60000) ? 30000 : $lifetime - 60000;
// Refresh time is 1 minute less than the liftime assined in the configuration.php file.
// The longest refresh period is one hour to prevent integer overflow.
if ($refreshTime > 3600000 || $refreshTime <= 0)
{
$refreshTime = 3600000;
}
$document = JFactory::getDocument();
$script = '';
$script .= 'function keepAlive() {';
$script .= ' var myAjax = new Request({method: "get", url: "index.php"}).send();';
$script .= '}';
$script .= ' window.addEvent("domready", function()';
$script .= '{ keepAlive.periodical(' . $refreshTime . '); }';
$script .= ');';
$document->addScriptDeclaration($script);
static::$loaded[__METHOD__] = true;
return;
}
/**
* Highlight some words via Javascript.
*
* @param array $terms Array of words that should be highlighted.
* @param string $start ID of the element that marks the begin of the section in which words
* should be highlighted. Note this element will be removed from the DOM.
* @param string $end ID of the element that end this section.
* Note this element will be removed from the DOM.
* @param string $className Class name of the element highlights are wrapped in.
* @param string $tag Tag that will be used to wrap the highlighted words.
*
* @return void
*
* @since 2.5
*/
public static function highlighter(array $terms, $start = 'highlighter-start', $end = 'highlighter-end', $className = 'highlight', $tag = 'span')
{
$sig = md5(serialize(array($terms, $start, $end)));
if (isset(static::$loaded[__METHOD__][$sig]))
{
return;
}
JHtml::_('script', 'system/highlighter.js', true, true);
$terms = str_replace('"', '\"', $terms);
$document = JFactory::getDocument();
$document->addScriptDeclaration("
window.addEvent('domready', function () {
var start = document.id('" . $start . "');
var end = document.id('" . $end . "');
if (!start || !end || !Joomla.Highlighter) {
return true;
}
highlighter = new Joomla.Highlighter({
startElement: start,
endElement: end,
className: '" . $className . "',
onlyWords: false,
tag: '" . $tag . "'
}).highlight([\"" . implode('","', $terms) . "\"]);
start.dispose();
end.dispose();
});
");
static::$loaded[__METHOD__][$sig] = true;
return;
}
/**
* Break us out of any containing iframes
*
* @return void
*
* @since 1.5
*/
public static function noframes()
{
// Only load once
if (isset(static::$loaded[__METHOD__]))
{
return;
}
// Include MooTools framework
static::framework();
$js = "window.addEvent('domready', function () {if (top == self) {document.documentElement.style.display = 'block'; }" .
" else {top.location = self.location; }});";
$document = JFactory::getDocument();
$document->addStyleDeclaration('html { display:none }');
$document->addScriptDeclaration($js);
JResponse::setHeader('X-Frames-Options', 'SAMEORIGIN');
static::$loaded[__METHOD__] = true;
}
/**
* Internal method to get a JavaScript object notation string from an array
*
* @param array $array The array to convert to JavaScript object notation
*
* @return string JavaScript object notation representation of the array
*
* @since 1.5
* @deprecated 13.3 (Platform) & 4.0 (CMS) - Use JHtml::getJSObject() instead.
*/
protected static function _getJSObject($array = array())
{
JLog::add('JHtmlBehavior::_getJSObject() is deprecated. JHtml::getJSObject() instead..', JLog::WARNING, 'deprecated');
return JHtml::getJSObject($array);
}
/**
* Internal method to translate the JavaScript Calendar
*
* @return string JavaScript that translates the object
*
* @since 1.5
*/
protected static function calendartranslation()
{
static $jsscript = 0;
// Guard clause, avoids unnecessary nesting
if ($jsscript)
{
return false;
}
$jsscript = 1;
// To keep the code simple here, run strings through JText::_() using array_map()
$callback = array('JText','_');
$weekdays_full = array_map(
$callback, array(
'SUNDAY', 'MONDAY', 'TUESDAY', 'WEDNESDAY', 'THURSDAY', 'FRIDAY', 'SATURDAY', 'SUNDAY'
)
);
$weekdays_short = array_map(
$callback,
array(
'SUN', 'MON', 'TUE', 'WED', 'THU', 'FRI', 'SAT', 'SUN'
)
);
$months_long = array_map(
$callback, array(
'JANUARY', 'FEBRUARY', 'MARCH', 'APRIL', 'MAY', 'JUNE',
'JULY', 'AUGUST', 'SEPTEMBER', 'OCTOBER', 'NOVEMBER', 'DECEMBER'
)
);
$months_short = array_map(
$callback, array(
'JANUARY_SHORT', 'FEBRUARY_SHORT', 'MARCH_SHORT', 'APRIL_SHORT', 'MAY_SHORT', 'JUNE_SHORT',
'JULY_SHORT', 'AUGUST_SHORT', 'SEPTEMBER_SHORT', 'OCTOBER_SHORT', 'NOVEMBER_SHORT', 'DECEMBER_SHORT'
)
);
// This will become an object in Javascript but define it first in PHP for readability
$text = array(
'INFO' => JText::_('JLIB_HTML_BEHAVIOR_ABOUT_THE_CALENDAR'),
'ABOUT' => "DHTML Date/Time Selector\n"
. "(c) dynarch.com 2002-2005 / Author: Mihai Bazon\n"
. "For latest version visit: http://www.dynarch.com/projects/calendar/\n"
. "Distributed under GNU LGPL. See http://gnu.org/licenses/lgpl.html for details."
. "\n\n"
. JText::_('JLIB_HTML_BEHAVIOR_DATE_SELECTION')
. JText::_('JLIB_HTML_BEHAVIOR_YEAR_SELECT')
. JText::_('JLIB_HTML_BEHAVIOR_MONTH_SELECT')
. JText::_('JLIB_HTML_BEHAVIOR_HOLD_MOUSE'),
'ABOUT_TIME' => "\n\n"
. "Time selection:\n"
. "- Click on any of the time parts to increase it\n"
. "- or Shift-click to decrease it\n"
. "- or click and drag for faster selection.",
'PREV_YEAR' => JText::_('JLIB_HTML_BEHAVIOR_PREV_YEAR_HOLD_FOR_MENU'),
'PREV_MONTH' => JText::_('JLIB_HTML_BEHAVIOR_PREV_MONTH_HOLD_FOR_MENU'),
'GO_TODAY' => JText::_('JLIB_HTML_BEHAVIOR_GO_TODAY'),
'NEXT_MONTH' => JText::_('JLIB_HTML_BEHAVIOR_NEXT_MONTH_HOLD_FOR_MENU'),
'SEL_DATE' => JText::_('JLIB_HTML_BEHAVIOR_SELECT_DATE'),
'DRAG_TO_MOVE' => JText::_('JLIB_HTML_BEHAVIOR_DRAG_TO_MOVE'),
'PART_TODAY' => JText::_('JLIB_HTML_BEHAVIOR_TODAY'),
'DAY_FIRST' => JText::_('JLIB_HTML_BEHAVIOR_DISPLAY_S_FIRST'),
'WEEKEND' => "0,6",
'CLOSE' => JText::_('JLIB_HTML_BEHAVIOR_CLOSE'),
'TODAY' => JText::_('JLIB_HTML_BEHAVIOR_TODAY'),
'TIME_PART' => JText::_('JLIB_HTML_BEHAVIOR_SHIFT_CLICK_OR_DRAG_TO_CHANGE_VALUE'),
'DEF_DATE_FORMAT' => "%Y-%m-%d",
'TT_DATE_FORMAT' => JText::_('JLIB_HTML_BEHAVIOR_TT_DATE_FORMAT'),
'WK' => JText::_('JLIB_HTML_BEHAVIOR_WK'),
'TIME' => JText::_('JLIB_HTML_BEHAVIOR_TIME')
);
return 'Calendar._DN = ' . json_encode($weekdays_full) . ';'
. ' Calendar._SDN = ' . json_encode($weekdays_short) . ';'
. ' Calendar._FD = 0;'
. ' Calendar._MN = ' . json_encode($months_long) . ';'
. ' Calendar._SMN = ' . json_encode($months_short) . ';'
. ' Calendar._TT = ' . json_encode($text) . ';';
}
}

View File

@ -0,0 +1,852 @@
<?php
/**
* @package Joomla.Libraries
* @subpackage HTML
*
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
defined('JPATH_PLATFORM') or die;
/**
* Utility class for Bootstrap elements.
*
* @package Joomla.Libraries
* @subpackage HTML
* @since 3.0
*/
abstract class JHtmlBootstrap
{
/**
* @var array Array containing information for loaded files
* @since 3.0
*/
protected static $loaded = array();
/**
* Add javascript support for the Bootstrap affix plugin
*
* @param string $selector Unique selector for the element to be affixed.
* @param array $params An array of options.
* Options for the affix plugin can be:
* - offset number|function|object Pixels to offset from screen when calculating position of scroll.
* If a single number is provided, the offset will be applied in both top
* and left directions. To listen for a single direction, or multiple
* unique offsets, just provide an object offset: { x: 10 }.
* Use a function when you need to dynamically provide an offset
* (useful for some responsive designs).
*
* @return void
*
* @since 3.1
*/
public static function affix($selector = 'affix', $params = array())
{
$sig = md5(serialize(array($selector, $params)));
if (!isset(static::$loaded[__METHOD__][$sig]))
{
// Include Bootstrap framework
static::framework();
// Setup options object
$opt['offset'] = isset($params['offset']) ? $params['offset'] : 10;
$options = JHtml::getJSObject($opt);
// Attach the carousel to document
JFactory::getDocument()->addScriptDeclaration(
"(function($){
$('#$selector').affix($options);
})(jQuery);"
);
// Set static array
static::$loaded[__METHOD__][$sig] = true;
}
return;
}
/**
* Add javascript support for Bootstrap alerts
*
* @param string $selector Common class for the alerts
*
* @return void
*
* @since 3.0
*/
public static function alert($selector = 'alert')
{
// Only load once
if (isset(static::$loaded[__METHOD__][$selector]))
{
return;
}
// Include Bootstrap framework
static::framework();
// Attach the alerts to the document
JFactory::getDocument()->addScriptDeclaration(
"(function($){
$('.$selector').alert();
})(jQuery);"
);
static::$loaded[__METHOD__][$selector] = true;
return;
}
/**
* Add javascript support for Bootstrap buttons
*
* @param string $selector Common class for the buttons
*
* @return void
*
* @since 3.1
*/
public static function button($selector = 'button')
{
// Only load once
if (isset(static::$loaded[__METHOD__][$selector]))
{
return;
}
// Include Bootstrap framework
static::framework();
// Attach the alerts to the document
JFactory::getDocument()->addScriptDeclaration(
"(function($){
$('.$selector').button();
})(jQuery);"
);
static::$loaded[__METHOD__][$selector] = true;
return;
}
/**
* Add javascript support for Bootstrap carousels
*
* @param string $selector Common class for the carousels.
* @param array $params An array of options for the modal.
* Options for the modal can be:
* - interval number The amount of time to delay between automatically cycling an item.
* If false, carousel will not automatically cycle.
* - pause string Pauses the cycling of the carousel on mouseenter and resumes the cycling
* of the carousel on mouseleave.
*
* @return void
*
* @since 3.0
*/
public static function carousel($selector = 'carousel', $params = array())
{
$sig = md5(serialize(array($selector, $params)));
if (!isset(static::$loaded[__METHOD__][$sig]))
{
// Include Bootstrap framework
static::framework();
// Setup options object
$opt['interval'] = isset($params['interval']) ? (int) $params['interval'] : 5000;
$opt['pause'] = isset($params['pause']) ? $params['pause'] : 'hover';
$options = JHtml::getJSObject($opt);
// Attach the carousel to document
JFactory::getDocument()->addScriptDeclaration(
"(function($){
$('.$selector').carousel($options);
})(jQuery);"
);
// Set static array
static::$loaded[__METHOD__][$sig] = true;
}
return;
}
/**
* Add javascript support for Bootstrap dropdowns
*
* @param string $selector Common class for the dropdowns
*
* @return void
*
* @since 3.0
*/
public static function dropdown($selector = 'dropdown-toggle')
{
// Only load once
if (isset(static::$loaded[__METHOD__][$selector]))
{
return;
}
// Include Bootstrap framework
static::framework();
// Attach the dropdown to the document
JFactory::getDocument()->addScriptDeclaration(
"(function($){
$('.$selector').dropdown();
})(jQuery);"
);
static::$loaded[__METHOD__][$selector] = true;
return;
}
/**
* Method to load the Bootstrap JavaScript framework into the document head
*
* If debugging mode is on an uncompressed version of Bootstrap is included for easier debugging.
*
* @param mixed $debug Is debugging mode on? [optional]
*
* @return void
*
* @since 3.0
*/
public static function framework($debug = null)
{
// Only load once
if (!empty(static::$loaded[__METHOD__]))
{
return;
}
// Load jQuery
JHtml::_('jquery.framework');
// If no debugging value is set, use the configuration setting
if ($debug === null)
{
$config = JFactory::getConfig();
$debug = (boolean) $config->get('debug');
}
JHtml::_('script', 'jui/bootstrap.min.js', false, true, false, false, $debug);
static::$loaded[__METHOD__] = true;
return;
}
/**
* Add javascript support for Bootstrap modals
*
* @param string $selector The ID selector for the modal.
* @param array $params An array of options for the modal.
* Options for the modal can be:
* - backdrop boolean Includes a modal-backdrop element.
* - keyboard boolean Closes the modal when escape key is pressed.
* - show boolean Shows the modal when initialized.
* - remote string An optional remote URL to load
*
* @return void
*
* @since 3.0
*/
public static function modal($selector = 'modal', $params = array())
{
$sig = md5(serialize(array($selector, $params)));
if (!isset(static::$loaded[__METHOD__][$sig]))
{
// Include Bootstrap framework
static::framework();
// Setup options object
$opt['backdrop'] = isset($params['backdrop']) ? (boolean) $params['backdrop'] : true;
$opt['keyboard'] = isset($params['keyboard']) ? (boolean) $params['keyboard'] : true;
$opt['show'] = isset($params['show']) ? (boolean) $params['show'] : true;
$opt['remote'] = isset($params['remote']) ? $params['remote'] : '';
$options = JHtml::getJSObject($opt);
// Attach the modal to document
JFactory::getDocument()->addScriptDeclaration(
"(function($){
$('#$selector').modal($options);
})(jQuery);"
);
// Set static array
static::$loaded[__METHOD__][$sig] = true;
}
return;
}
/**
* Method to render a Bootstrap modal
*
* @param string $selector The ID selector for the modal.
* @param array $params An array of options for the modal.
* @param string $footer Optional markup for the modal footer
*
* @return string HTML markup for a modal
*
* @since 3.0
*/
public static function renderModal($selector = 'modal', $params = array(), $footer = '')
{
// Ensure the behavior is loaded
static::modal($selector, $params);
$html = "<div class=\"modal hide fade\" id=\"" . $selector . "\">\n";
$html .= "<div class=\"modal-header\">\n";
$html .= "<button type=\"button\" class=\"close\" data-dismiss=\"modal\">×</button>\n";
$html .= "<h3>" . $params['title'] . "</h3>\n";
$html .= "</div>\n";
$html .= "<div id=\"" . $selector . "-container\">\n";
$html .= "</div>\n";
$html .= "</div>\n";
$html .= "<script>";
$html .= "jQuery('#" . $selector . "').on('show', function () {\n";
$html .= "document.getElementById('" . $selector . "-container').innerHTML = '<div class=\"modal-body\"><iframe class=\"iframe\" src=\""
. $params['url'] . "\" height=\"" . $params['height'] . "\" width=\"" . $params['width'] . "\"></iframe></div>" . $footer . "';\n";
$html .= "});\n";
$html .= "</script>";
return $html;
}
/**
* Add javascript support for Bootstrap popovers
*
* Use element's Title as popover content
*
* @param string $selector Selector for the tooltip
* @param array $params An array of options for the tooltip.
* Options for the tooltip can be:
* animation boolean apply a css fade transition to the tooltip
* html boolean Insert HTML into the tooltip. If false, jQuery's text method will be used to insert
* content into the dom.
* placement string|function how to position the tooltip - top | bottom | left | right
* selector string If a selector is provided, tooltip objects will be delegated to the specified targets.
* trigger string how tooltip is triggered - hover | focus | manual
* title string|function default title value if `title` tag isn't present
* content string|function default content value if `data-content` attribute isn't present
* delay number|object delay showing and hiding the tooltip (ms) - does not apply to manual trigger type
* If a number is supplied, delay is applied to both hide/show
* Object structure is: delay: { show: 500, hide: 100 }
* container string|boolean Appends the popover to a specific element: { container: 'body' }
*
* @return void
*
* @since 3.0
*/
public static function popover($selector = '.hasPopover', $params = array())
{
// Only load once
if (isset(static::$loaded[__METHOD__][$selector]))
{
return;
}
// Include Bootstrap framework
static::framework();
$opt['animation'] = isset($params['animation']) ? $params['animation'] : null;
$opt['html'] = isset($params['html']) ? $params['html'] : true;
$opt['placement'] = isset($params['placement']) ? $params['placement'] : null;
$opt['selector'] = isset($params['selector']) ? $params['selector'] : null;
$opt['title'] = isset($params['title']) ? $params['title'] : null;
$opt['trigger'] = isset($params['trigger']) ? $params['trigger'] : 'hover';
$opt['content'] = isset($params['content']) ? $params['content'] : null;
$opt['delay'] = isset($params['delay']) ? $params['delay'] : null;
$opt['container'] = isset($params['container']) ? $params['container'] : false;
$options = JHtml::getJSObject($opt);
// Attach the popover to the document
JFactory::getDocument()->addScriptDeclaration(
"jQuery(document).ready(function()
{
jQuery('" . $selector . "').popover(" . $options . ");
});"
);
static::$loaded[__METHOD__][$selector] = true;
return;
}
/**
* Add javascript support for Bootstrap ScrollSpy
*
* @param string $selector The ID selector for the ScrollSpy element.
* @param array $params An array of options for the ScrollSpy.
* Options for the modal can be:
* - offset number Pixels to offset from top when calculating position of scroll.
*
* @return void
*
* @since 3.0
*/
public static function scrollspy($selector = 'navbar', $params = array())
{
$sig = md5(serialize(array($selector, $params)));
if (!isset(static::$loaded[__METHOD__][$sig]))
{
// Include Bootstrap framework
static::framework();
// Setup options object
$opt['offset'] = isset($params['offset']) ? (int) $params['offset'] : 10;
$options = JHtml::getJSObject($opt);
// Attach ScrollSpy to document
JFactory::getDocument()->addScriptDeclaration(
"(function($){
$('#$selector').scrollspy($options);
})(jQuery);"
);
// Set static array
static::$loaded[__METHOD__][$sig] = true;
}
return;
}
/**
* Add javascript support for Bootstrap tooltips
*
* Add a title attribute to any element in the form
* title="title::text"
*
* @param string $selector The ID selector for the tooltip.
* @param array $params An array of options for the tooltip.
* Options for the tooltip can be:
* - animation boolean Apply a CSS fade transition to the tooltip
* - html boolean Insert HTML into the tooltip. If false, jQuery's text method will be used to insert
* content into the dom.
* - placement string|function How to position the tooltip - top | bottom | left | right
* - selector string If a selector is provided, tooltip objects will be delegated to the specified targets.
* - title string|function Default title value if `title` tag isn't present
* - trigger string How tooltip is triggered - hover | focus | manual
* - delay integer Delay showing and hiding the tooltip (ms) - does not apply to manual trigger type
* If a number is supplied, delay is applied to both hide/show
* Object structure is: delay: { show: 500, hide: 100 }
* - container string|boolean Appends the popover to a specific element: { container: 'body' }
*
* @return void
*
* @since 3.0
*/
public static function tooltip($selector = '.hasTooltip', $params = array())
{
if (!isset(static::$loaded[__METHOD__][$selector]))
{
// Include Bootstrap framework
static::framework();
// Setup options object
$opt['animation'] = isset($params['animation']) ? (boolean) $params['animation'] : null;
$opt['html'] = isset($params['html']) ? (boolean) $params['html'] : null;
$opt['placement'] = isset($params['placement']) ? (string) $params['placement'] : null;
$opt['selector'] = isset($params['selector']) ? (string) $params['selector'] : null;
$opt['title'] = isset($params['title']) ? (string) $params['title'] : null;
$opt['trigger'] = isset($params['trigger']) ? (string) $params['trigger'] : null;
$opt['delay'] = isset($params['delay']) ? (int) $params['delay'] : null;
$opt['container'] = isset($params['container']) ? (int) $params['container'] : false;
$opt['template'] = isset($params['template']) ? (string) $params['template'] : null;
$options = JHtml::getJSObject($opt);
// Attach tooltips to document
JFactory::getDocument()->addScriptDeclaration(
"jQuery(document).ready(function()
{
jQuery('" . $selector . "').tooltip(" . $options . ");
});"
);
// Set static array
static::$loaded[__METHOD__][$selector] = true;
}
return;
}
/**
* Add javascript support for Bootstrap typeahead
*
* @param string $selector The selector for the typeahead element.
* @param array $params An array of options for the typeahead element.
* Options for the tooltip can be:
* - source array, function The data source to query against. May be an array of strings or a function.
* The function is passed two arguments, the query value in the input field and the
* process callback. The function may be used synchronously by returning the data
* source directly or asynchronously via the process callback's single argument.
* - items number The max number of items to display in the dropdown.
* - minLength number The minimum character length needed before triggering autocomplete suggestions
* - matcher function The method used to determine if a query matches an item. Accepts a single argument,
* the item against which to test the query. Access the current query with this.query.
* Return a boolean true if query is a match.
* - sorter function Method used to sort autocomplete results. Accepts a single argument items and has
* the scope of the typeahead instance. Reference the current query with this.query.
* - updater function The method used to return selected item. Accepts a single argument, the item and
* has the scope of the typeahead instance.
* - highlighter function Method used to highlight autocomplete results. Accepts a single argument item and
* has the scope of the typeahead instance. Should return html.
*
* @return void
*
* @since 3.0
*/
public static function typeahead($selector = '.typeahead', $params = array())
{
if (!isset(static::$loaded[__METHOD__][$selector]))
{
// Include Bootstrap framework
static::framework();
// Setup options object
$opt['source'] = isset($params['source']) ? $params['source'] : '[]';
$opt['items'] = isset($params['items']) ? (int) $params['items'] : 8;
$opt['minLength'] = isset($params['minLength']) ? (int) $params['minLength'] : 1;
$opt['matcher'] = isset($params['matcher']) ? (string) $params['matcher'] : null;
$opt['sorter'] = isset($params['sorter']) ? (string) $params['sorter'] : null;
$opt['updater'] = isset($params['updater']) ? (string) $params['updater'] : null;
$opt['highlighter'] = isset($params['highlighter']) ? (int) $params['highlighter'] : null;
$options = JHtml::getJSObject($opt);
// Attach tooltips to document
JFactory::getDocument()->addScriptDeclaration(
"jQuery(document).ready(function()
{
jQuery('" . $selector . "').typeahead(" . $options . ");
});"
);
// Set static array
static::$loaded[__METHOD__][$selector] = true;
}
return;
}
/**
* Add javascript support for Bootstrap accordians and insert the accordian
*
* @param string $selector The ID selector for the tooltip.
* @param array $params An array of options for the tooltip.
* Options for the tooltip can be:
* - parent selector If selector then all collapsible elements under the specified parent will be closed when this
* collapsible item is shown. (similar to traditional accordion behavior)
* - toggle boolean Toggles the collapsible element on invocation
* - active string Sets the active slide during load
*
* @return string HTML for the accordian
*
* @since 3.0
*/
public static function startAccordion($selector = 'myAccordian', $params = array())
{
$sig = md5(serialize(array($selector, $params)));
if (!isset(static::$loaded[__METHOD__][$sig]))
{
// Include Bootstrap framework
static::framework();
// Setup options object
$opt['parent'] = isset($params['parent']) ? (boolean) $params['parent'] : false;
$opt['toggle'] = isset($params['toggle']) ? (boolean) $params['toggle'] : true;
$opt['active'] = isset($params['active']) ? (string) $params['active'] : '';
$options = JHtml::getJSObject($opt);
// Attach accordion to document
JFactory::getDocument()->addScriptDeclaration(
"(function($){
$('#$selector').collapse($options);
})(jQuery);"
);
// Set static array
static::$loaded[__METHOD__][$sig] = true;
static::$loaded[__METHOD__]['active'] = $opt['active'];
}
return '<div id="' . $selector . '" class="accordion">';
}
/**
* Close the current accordion
*
* @return string HTML to close the accordian
*
* @since 3.0
*/
public static function endAccordion()
{
return '</div>';
}
/**
* Begins the display of a new accordion slide.
*
* @param string $selector Identifier of the accordion group.
* @param string $text Text to display.
* @param string $id Identifier of the slide.
* @param string $class Class of the accordion group.
*
* @return string HTML to add the slide
*
* @since 3.0
*/
public static function addSlide($selector, $text, $id, $class = '')
{
$in = (static::$loaded['JHtmlBootstrap::startAccordion']['active'] == $id) ? ' in' : '';
$class = (!empty($class)) ? ' ' . $class : '';
$html = '<div class="accordion-group' . $class . '">'
. '<div class="accordion-heading">'
. '<strong><a href="#' . $id . '" data-parent="#' . $selector . '" data-toggle="collapse" class="accordion-toggle">'
. $text
. '</a></strong>'
. '</div>'
. '<div class="accordion-body collapse' . $in . '" id="' . $id . '">'
. '<div class="accordion-inner">';
return $html;
}
/**
* Close the current slide
*
* @return string HTML to close the slide
*
* @since 3.0
*/
public static function endSlide()
{
return '</div></div></div>';
}
/**
* Creates a tab pane
*
* @param string $selector The pane identifier.
* @param array $params The parameters for the pane
*
* @return string
*
* @since 3.1
*/
public static function startTabSet($selector = 'myTab', $params = array())
{
$sig = md5(serialize(array($selector, $params)));
if (!isset(static::$loaded[__METHOD__][$sig]))
{
// Include Bootstrap framework
static::framework();
// Setup options object
$opt['active'] = (isset($params['active']) && ($params['active'])) ? (string) $params['active'] : '';
// Attach tabs to document
JFactory::getDocument()
->addScriptDeclaration(JLayoutHelper::render('libraries.cms.html.bootstrap.starttabsetscript', array('selector' => $selector)));
// Set static array
static::$loaded[__METHOD__][$sig] = true;
static::$loaded[__METHOD__][$selector]['active'] = $opt['active'];
}
$html = JLayoutHelper::render('libraries.cms.html.bootstrap.starttabset', array('selector' => $selector));
return $html;
}
/**
* Close the current tab pane
*
* @return string HTML to close the pane
*
* @since 3.1
*/
public static function endTabSet()
{
$html = JLayoutHelper::render('libraries.cms.html.bootstrap.endtabset');
return $html;
}
/**
* Begins the display of a new tab content panel.
*
* @param string $selector Identifier of the panel.
* @param string $id The ID of the div element
* @param string $title The title text for the new UL tab
*
* @return string HTML to start a new panel
*
* @since 3.1
*/
public static function addTab($selector, $id, $title)
{
static $tabScriptLayout = null;
static $tabLayout = null;
$tabScriptLayout = is_null($tabScriptLayout) ? new JLayoutFile('libraries.cms.html.bootstrap.addtabscript') : $tabScriptLayout;
$tabLayout = is_null($tabLayout) ? new JLayoutFile('libraries.cms.html.bootstrap.addtab') : $tabLayout;
$active = (static::$loaded['JHtmlBootstrap::startTabSet'][$selector]['active'] == $id) ? ' active' : '';
// Inject tab into UL
JFactory::getDocument()
->addScriptDeclaration($tabScriptLayout->render(array('selector' => $selector,'id' => $id, 'active' => $active, 'title' => $title)));
$html = $tabLayout->render(array('id' => $id, 'active' => $active));
return $html;
}
/**
* Close the current tab content panel
*
* @return string HTML to close the pane
*
* @since 3.1
*/
public static function endTab()
{
$html = JLayoutHelper::render('libraries.cms.html.bootstrap.endtab');
return $html;
}
/**
* Creates a tab pane
*
* @param string $selector The pane identifier.
* @param array $params The parameters for the pane
*
* @return string
*
* @since 3.0
* @deprecated 4.0 Use JHtml::_('bootstrap.startTabSet') instead.
*/
public static function startPane($selector = 'myTab', $params = array())
{
$sig = md5(serialize(array($selector, $params)));
if (!isset(static::$loaded['JHtmlBootstrap::startTabSet'][$sig]))
{
// Include Bootstrap framework
static::framework();
// Setup options object
$opt['active'] = isset($params['active']) ? (string) $params['active'] : '';
// Attach tooltips to document
JFactory::getDocument()->addScriptDeclaration(
"(function($){
$('#$selector a').click(function (e) {
e.preventDefault();
$(this).tab('show');
});
})(jQuery);"
);
// Set static array
static::$loaded['JHtmlBootstrap::startTabSet'][$sig] = true;
static::$loaded['JHtmlBootstrap::startTabSet'][$selector]['active'] = $opt['active'];
}
return '<div class="tab-content" id="' . $selector . 'Content">';
}
/**
* Close the current tab pane
*
* @return string HTML to close the pane
*
* @since 3.0
* @deprecated 4.0 Use JHtml::_('bootstrap.endTabSet') instead.
*/
public static function endPane()
{
return '</div>';
}
/**
* Begins the display of a new tab content panel.
*
* @param string $selector Identifier of the panel.
* @param string $id The ID of the div element
*
* @return string HTML to start a new panel
*
* @since 3.0
* @deprecated 4.0 Use JHtml::_('bootstrap.addTab') instead.
*/
public static function addPanel($selector, $id)
{
$active = (static::$loaded['JHtmlBootstrap::startTabSet'][$selector]['active'] == $id) ? ' active' : '';
return '<div id="' . $id . '" class="tab-pane' . $active . '">';
}
/**
* Close the current tab content panel
*
* @return string HTML to close the pane
*
* @since 3.0
* @deprecated 4.0 Use JHtml::_('bootstrap.endTab') instead.
*/
public static function endPanel()
{
return '</div>';
}
/**
* Loads CSS files needed by Bootstrap
*
* @param boolean $includeMainCss If true, main bootstrap.css files are loaded
* @param string $direction rtl or ltr direction. If empty, ltr is assumed
* @param array $attribs Optional array of attributes to be passed to JHtml::_('stylesheet')
*
* @return void
*
* @since 3.0
*/
public static function loadCss($includeMainCss = true, $direction = 'ltr', $attribs = array())
{
// Load Bootstrap main CSS
if ($includeMainCss)
{
JHtml::_('stylesheet', 'jui/bootstrap.min.css', $attribs, true);
JHtml::_('stylesheet', 'jui/bootstrap-responsive.min.css', $attribs, true);
JHtml::_('stylesheet', 'jui/bootstrap-extended.css', $attribs, true);
}
// Load Bootstrap RTL CSS
if ($direction === 'rtl')
{
JHtml::_('stylesheet', 'jui/bootstrap-rtl.css', $attribs, true);
}
}
}

View File

@ -0,0 +1,166 @@
<?php
/**
* @package Joomla.Libraries
* @subpackage HTML
*
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
defined('JPATH_BASE') or die;
/**
* Utility class for categories
*
* @package Joomla.Libraries
* @subpackage HTML
* @since 1.5
*/
abstract class JHtmlCategory
{
/**
* Cached array of the category items.
*
* @var array
* @since 1.5
*/
protected static $items = array();
/**
* Returns an array of categories for the given extension.
*
* @param string $extension The extension option e.g. com_something.
* @param array $config An array of configuration options. By default, only
* published and unpublished categories are returned.
*
* @return array
*
* @since 1.5
*/
public static function options($extension, $config = array('filter.published' => array(0, 1)))
{
$hash = md5($extension . '.' . serialize($config));
if (!isset(static::$items[$hash]))
{
$config = (array) $config;
$db = JFactory::getDbo();
$query = $db->getQuery(true)
->select('a.id, a.title, a.level')
->from('#__categories AS a')
->where('a.parent_id > 0');
// Filter on extension.
$query->where('extension = ' . $db->quote($extension));
// Filter on the published state
if (isset($config['filter.published']))
{
if (is_numeric($config['filter.published']))
{
$query->where('a.published = ' . (int) $config['filter.published']);
}
elseif (is_array($config['filter.published']))
{
JArrayHelper::toInteger($config['filter.published']);
$query->where('a.published IN (' . implode(',', $config['filter.published']) . ')');
}
}
// Filter on the language
if (isset($config['filter.language']))
{
if (is_string($config['filter.language']))
{
$query->where('a.language = ' . $db->quote($config['filter.language']));
}
elseif (is_array($config['filter.language']))
{
foreach ($config['filter.language'] as &$language)
{
$language = $db->quote($language);
}
$query->where('a.language IN (' . implode(',', $config['filter.language']) . ')');
}
}
$query->order('a.lft');
$db->setQuery($query);
$items = $db->loadObjectList();
// Assemble the list options.
static::$items[$hash] = array();
foreach ($items as &$item)
{
$repeat = ($item->level - 1 >= 0) ? $item->level - 1 : 0;
$item->title = str_repeat('- ', $repeat) . $item->title;
static::$items[$hash][] = JHtml::_('select.option', $item->id, $item->title);
}
}
return static::$items[$hash];
}
/**
* Returns an array of categories for the given extension.
*
* @param string $extension The extension option.
* @param array $config An array of configuration options. By default, only published and unpublished categories are returned.
*
* @return array Categories for the extension
*
* @since 1.6
*/
public static function categories($extension, $config = array('filter.published' => array(0, 1)))
{
$hash = md5($extension . '.' . serialize($config));
if (!isset(static::$items[$hash]))
{
$config = (array) $config;
$db = JFactory::getDbo();
$query = $db->getQuery(true)
->select('a.id, a.title, a.level, a.parent_id')
->from('#__categories AS a')
->where('a.parent_id > 0');
// Filter on extension.
$query->where('extension = ' . $db->quote($extension));
// Filter on the published state
if (isset($config['filter.published']))
{
if (is_numeric($config['filter.published']))
{
$query->where('a.published = ' . (int) $config['filter.published']);
}
elseif (is_array($config['filter.published']))
{
JArrayHelper::toInteger($config['filter.published']);
$query->where('a.published IN (' . implode(',', $config['filter.published']) . ')');
}
}
$query->order('a.lft');
$db->setQuery($query);
$items = $db->loadObjectList();
// Assemble the list options.
static::$items[$hash] = array();
foreach ($items as &$item)
{
$repeat = ($item->level - 1 >= 0) ? $item->level - 1 : 0;
$item->title = str_repeat('- ', $repeat) . $item->title;
static::$items[$hash][] = JHtml::_('select.option', $item->id, $item->title);
}
// Special "Add to root" option:
static::$items[$hash][] = JHtml::_('select.option', '1', JText::_('JLIB_HTML_ADD_TO_ROOT'));
}
return static::$items[$hash];
}
}

View File

@ -0,0 +1,47 @@
<?php
/**
* @package Joomla.Libraries
* @subpackage HTML
*
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
defined('JPATH_PLATFORM') or die;
/**
* Utility class to fire onContentPrepare for non-article based content.
*
* @package Joomla.Libraries
* @subpackage HTML
* @since 1.5
*/
abstract class JHtmlContent
{
/**
* Fire onContentPrepare for content that isn't part of an article.
*
* @param string $text The content to be transformed.
* @param array $params The content params.
* @param string $context The context of the content to be transformed.
*
* @return string The content after transformation.
*
* @since 1.5
*/
public static function prepare($text, $params = null, $context = 'text')
{
if ($params === null)
{
$params = new JObject;
}
$article = new stdClass;
$article->text = $text;
JPluginHelper::importPlugin('content');
$dispatcher = JEventDispatcher::getInstance();
$dispatcher->trigger('onContentPrepare', array($context, &$article, &$params, 0));
return $article->text;
}
}

View File

@ -0,0 +1,66 @@
<?php
/**
* @package Joomla.Libraries
* @subpackage HTML
*
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
defined('JPATH_PLATFORM') or die;
/**
* Utility class working with content language select lists
*
* @package Joomla.Libraries
* @subpackage HTML
* @since 1.6
*/
abstract class JHtmlContentLanguage
{
/**
* Cached array of the content language items.
*
* @var array
* @since 1.6
*/
protected static $items = null;
/**
* Get a list of the available content language items.
*
* @param boolean $all True to include All (*)
* @param boolean $translate True to translate All
*
* @return string
*
* @see JFormFieldContentLanguage
* @since 1.6
*/
public static function existing($all = false, $translate = false)
{
if (empty(static::$items))
{
// Get the database object and a new query object.
$db = JFactory::getDbo();
$query = $db->getQuery(true);
// Build the query.
$query->select('a.lang_code AS value, a.title AS text, a.title_native')
->from('#__languages AS a')
->where('a.published >= 0')
->order('a.title');
// Set the query and load the options.
$db->setQuery($query);
static::$items = $db->loadObjectList();
if ($all)
{
array_unshift(static::$items, new JObject(array('value' => '*', 'text' => $translate ? JText::alt('JALL', 'language') : 'JALL_LANGUAGE')));
}
}
return static::$items;
}
}

View File

@ -0,0 +1,89 @@
<?php
/**
* @package Joomla.Libraries
* @subpackage HTML
*
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
defined('JPATH_PLATFORM') or die;
/**
* Extended Utility class for handling date display.
*
* @package Joomla.Libraries
* @subpackage HTML
* @since 2.5
*/
abstract class JHtmlDate
{
/**
* Function to convert a static time into a relative measurement
*
* @param string $date The date to convert
* @param string $unit The optional unit of measurement to return
* if the value of the diff is greater than one
* @param string $time An optional time to compare to, defaults to now
*
* @return string The converted time string
*
* @since 2.5
*/
public static function relative($date, $unit = null, $time = null)
{
if (is_null($time))
{
// Get now
$time = JFactory::getDate('now');
}
// Get the difference in seconds between now and the time
$diff = strtotime($time) - strtotime($date);
// Less than a minute
if ($diff < 60)
{
return JText::_('JLIB_HTML_DATE_RELATIVE_LESSTHANAMINUTE');
}
// Round to minutes
$diff = round($diff / 60);
// 1 to 59 minutes
if ($diff < 60 || $unit == 'minute')
{
return JText::plural('JLIB_HTML_DATE_RELATIVE_MINUTES', $diff);
}
// Round to hours
$diff = round($diff / 60);
// 1 to 23 hours
if ($diff < 24 || $unit == 'hour')
{
return JText::plural('JLIB_HTML_DATE_RELATIVE_HOURS', $diff);
}
// Round to days
$diff = round($diff / 24);
// 1 to 6 days
if ($diff < 7 || $unit == 'day')
{
return JText::plural('JLIB_HTML_DATE_RELATIVE_DAYS', $diff);
}
// Round to weeks
$diff = round($diff / 7);
// 1 to 4 weeks
if ($diff <= 4 || $unit == 'week')
{
return JText::plural('JLIB_HTML_DATE_RELATIVE_WEEKS', $diff);
}
// Over a month, return the absolute time
return JHtml::_('date', $date);
}
}

View File

@ -0,0 +1,355 @@
<?php
/**
* @package Joomla.Libraries
* @subpackage HTML
*
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
defined('JPATH_PLATFORM') or die;
/**
* HTML utility class for building a dropdown menu
*
* @package Joomla.Libraries
* @subpackage HTML
* @since 3.0
*/
abstract class JHtmlDropdown
{
/**
* @var array Array containing information for loaded files
* @since 3.0
*/
protected static $loaded = array();
/**
* @var string HTML markup for the dropdown list
* @since 3.0
*/
protected static $dropDownList = null;
/**
* Method to inject needed script
*
* @return void
*
* @since 3.0
*/
public static function init()
{
// Only load once
if (isset(static::$loaded[__METHOD__]))
{
return;
}
// Depends on Bootstrap
JHtml::_('bootstrap.framework');
JFactory::getDocument()->addScriptDeclaration("
(function($){
$(document).ready(function (){
$('.has-context')
.mouseenter(function (){
$('.btn-group',$(this)).show();
})
.mouseleave(function (){
$('.btn-group',$(this)).hide();
$('.btn-group',$(this)).removeClass('open');
});
contextAction =function (cbId, task)
{
$('input[name=\"cid[]\"]').removeAttr('checked');
$('#' + cbId).attr('checked','checked');
Joomla.submitbutton(task);
}
});
})(jQuery);
"
);
// Set static array
static::$loaded[__METHOD__] = true;
return;
}
/**
* Method to start a new dropdown menu
*
* @return void
*
* @since 3.0
*/
public static function start()
{
// Only start once
if (isset(static::$loaded[__METHOD__]) && static::$loaded[__METHOD__] == true)
{
return;
}
$dropDownList = '<div class="btn-group" style="margin-left:6px;display:none">
<a href="#" data-toggle="dropdown" class="dropdown-toggle btn btn-mini">
<span class="caret"></span>
</a>
<ul class="dropdown-menu">';
static::$dropDownList = $dropDownList;
static::$loaded[__METHOD__] = true;
return;
}
/**
* Method to render current dropdown menu
*
* @return string HTML markup for the dropdown list
*
* @since 3.0
*/
public static function render()
{
$dropDownList = static::$dropDownList;
$dropDownList .= '</ul></div>';
static::$dropDownList = null;
static::$loaded['JHtmlDropdown::start'] = false;
return $dropDownList;
}
/**
* Append an edit item to the current dropdown menu
*
* @param integer $id Record ID
* @param string $prefix Task prefix
* @param string $customLink The custom link if dont use default Joomla action format
*
* @return void
*
* @since 3.0
*/
public static function edit($id, $prefix = '', $customLink = '')
{
static::start();
if (!$customLink)
{
$option = JFactory::getApplication()->input->getCmd('option');
$link = 'index.php?option=' . $option;
}
else
{
$link = $customLink;
}
$link .= '&task=' . $prefix . 'edit&id=' . $id;
$link = JRoute::_($link);
static::addCustomItem(JText::_('JACTION_EDIT'), $link);
return;
}
/**
* Append a publish item to the current dropdown menu
*
* @param string $checkboxId ID of corresponding checkbox of the record
* @param string $prefix The task prefix
*
* @return void
*
* @since 3.0
*/
public static function publish($checkboxId, $prefix = '')
{
$task = $prefix . 'publish';
static::addCustomItem(JText::_('JTOOLBAR_PUBLISH'), 'javascript:void(0)', 'onclick="contextAction(\'' . $checkboxId . '\', \'' . $task . '\')"');
return;
}
/**
* Append an unpublish item to the current dropdown menu
*
* @param string $checkboxId ID of corresponding checkbox of the record
* @param string $prefix The task prefix
*
* @return void
*
* @since 3.0
*/
public static function unpublish($checkboxId, $prefix = '')
{
$task = $prefix . 'unpublish';
static::addCustomItem(JText::_('JTOOLBAR_UNPUBLISH'), 'javascript:void(0)', 'onclick="contextAction(\'' . $checkboxId . '\', \'' . $task . '\')"');
return;
}
/**
* Append a featured item to the current dropdown menu
*
* @param string $checkboxId ID of corresponding checkbox of the record
* @param string $prefix The task prefix
*
* @return void
*
* @since 3.0
*/
public static function featured($checkboxId, $prefix = '')
{
$task = $prefix . 'featured';
static::addCustomItem(JText::_('JFEATURED'), 'javascript:void(0)', 'onclick="contextAction(\'' . $checkboxId . '\', \'' . $task . '\')"');
return;
}
/**
* Append an unfeatured item to the current dropdown menu
*
* @param string $checkboxId ID of corresponding checkbox of the record
* @param string $prefix The task prefix
*
* @return void
*
* @since 3.0
*/
public static function unfeatured($checkboxId, $prefix = '')
{
$task = $prefix . 'unfeatured';
static::addCustomItem(JText::_('JUNFEATURED'), 'javascript:void(0)', 'onclick="contextAction(\'' . $checkboxId . '\', \'' . $task . '\')"');
return;
}
/**
* Append an archive item to the current dropdown menu
*
* @param string $checkboxId ID of corresponding checkbox of the record
* @param string $prefix The task prefix
*
* @return void
*
* @since 3.0
*/
public static function archive($checkboxId, $prefix = '')
{
$task = $prefix . 'archive';
static::addCustomItem(JText::_('JTOOLBAR_ARCHIVE'), 'javascript:void(0)', 'onclick="contextAction(\'' . $checkboxId . '\', \'' . $task . '\')"');
return;
}
/**
* Append an unarchive item to the current dropdown menu
*
* @param string $checkboxId ID of corresponding checkbox of the record
* @param string $prefix The task prefix
*
* @return void
*
* @since 3.0
*/
public static function unarchive($checkboxId, $prefix = '')
{
$task = $prefix . 'unpublish';
static::addCustomItem(JText::_('JTOOLBAR_UNARCHIVE'), 'javascript:void(0)', 'onclick="contextAction(\'' . $checkboxId . '\', \'' . $task . '\')"');
return;
}
/**
* Append a trash item to the current dropdown menu
*
* @param string $checkboxId ID of corresponding checkbox of the record
* @param string $prefix The task prefix
*
* @return void
*
* @since 3.0
*/
public static function trash($checkboxId, $prefix = '')
{
$task = $prefix . 'trash';
static::addCustomItem(JText::_('JTOOLBAR_TRASH'), 'javascript:void(0)', 'onclick="contextAction(\'' . $checkboxId . '\', \'' . $task . '\')"');
return;
}
/**
* Append an untrash item to the current dropdown menu
*
* @param string $checkboxId ID of corresponding checkbox of the record
* @param string $prefix The task prefix
*
* @return void
*
* @since 3.0
*/
public static function untrash($checkboxId, $prefix = '')
{
$task = $prefix . 'publish';
static::addCustomItem(JText::_('JTOOLBAR_UNTRASH'), 'javascript:void(0)', 'onclick="contextAction(\'' . $checkboxId . '\', \'' . $task . '\')"');
return;
}
/**
* Append a checkin item to the current dropdown menu
*
* @param string $checkboxId ID of corresponding checkbox of the record
* @param string $prefix The task prefix
*
* @return void
*
* @since 3.0
*/
public static function checkin($checkboxId, $prefix = '')
{
$task = $prefix . 'checkin';
static::addCustomItem(JText::_('JTOOLBAR_CHECKIN'), 'javascript:void(0)', 'onclick="contextAction(\'' . $checkboxId . '\', \'' . $task . '\')"');
return;
}
/**
* Writes a divider between dropdown items
*
* @return void
*
* @since 3.0
*/
public static function divider()
{
static::$dropDownList .= '<li class="divider"></li>';
return;
}
/**
* Append a custom item to current dropdown menu
*
* @param string $label The label of item
* @param string $link The link of item
* @param string $linkAttributes Custom link attributes
* @param string $className Class name of item
* @param boolean $ajaxLoad True if using ajax load when item clicked
* @param string $jsCallBackFunc Javascript function name, called when ajax load successfully
*
* @return void
*
* @since 3.0
*/
public static function addCustomItem($label, $link = 'javascript:void(0)', $linkAttributes = '', $className = '', $ajaxLoad = false,
$jsCallBackFunc = null)
{
static::start();
if ($ajaxLoad)
{
$href = ' href = "javascript:void(0)" onclick="loadAjax(\'' . $link . '\', \'' . $jsCallBackFunc . '\')"';
}
else
{
$href = ' href = "' . $link . '" ';
}
$dropDownList = static::$dropDownList;
$dropDownList .= '<li class="' . $className . '"><a ' . $linkAttributes . $href . ' >';
$dropDownList .= $label;
$dropDownList .= '</a></li>';
static::$dropDownList = $dropDownList;
return;
}
}

View File

@ -0,0 +1,129 @@
<?php
/**
* @package Joomla.Libraries
* @subpackage HTML
*
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
defined('JPATH_PLATFORM') or die;
/**
* Utility class for cloaking email addresses
*
* @package Joomla.Libraries
* @subpackage HTML
* @since 1.5
*/
abstract class JHtmlEmail
{
/**
* Simple JavaScript email cloaker
*
* By default replaces an email with a mailto link with email cloaked
*
* @param string $mail The -mail address to cloak.
* @param boolean $mailto True if text and mailing address differ
* @param string $text Text for the link
* @param boolean $email True if text is an e-mail address
*
* @return string The cloaked email.
*
* @since 1.5
*/
public static function cloak($mail, $mailto = true, $text = '', $email = true)
{
// Convert text
$mail = static::convertEncoding($mail);
// Split email by @ symbol
$mail = explode('@', $mail);
$mail_parts = explode('.', $mail[1]);
// Random number
$rand = rand(1, 100000);
$replacement = "\n <script type='text/javascript'>";
$replacement .= "\n <!--";
$replacement .= "\n var prefix = '&#109;a' + 'i&#108;' + '&#116;o';";
$replacement .= "\n var path = 'hr' + 'ef' + '=';";
$replacement .= "\n var addy" . $rand . " = '" . @$mail[0] . "' + '&#64;';";
$replacement .= "\n addy" . $rand . " = addy" . $rand . " + '" . implode("' + '&#46;' + '", $mail_parts) . "';";
if ($mailto)
{
// Special handling when mail text is different from mail address
if ($text)
{
if ($email)
{
// Convert text
$text = static::convertEncoding($text);
// Split email by @ symbol
$text = explode('@', $text);
$text_parts = explode('.', $text[1]);
$replacement .= "\n var addy_text" . $rand . " = '" . @$text[0] . "' + '&#64;' + '" . implode("' + '&#46;' + '", @$text_parts)
. "';";
}
else
{
$replacement .= "\n var addy_text" . $rand . " = '" . $text . "';";
}
$replacement .= "\n document.write('<a ' + path + '\'' + prefix + ':' + addy" . $rand . " + '\'>');";
$replacement .= "\n document.write(addy_text" . $rand . ");";
$replacement .= "\n document.write('<\/a>');";
}
else
{
$replacement .= "\n document.write('<a ' + path + '\'' + prefix + ':' + addy" . $rand . " + '\'>');";
$replacement .= "\n document.write(addy" . $rand . ");";
$replacement .= "\n document.write('<\/a>');";
}
}
else
{
$replacement .= "\n document.write(addy" . $rand . ");";
}
$replacement .= "\n //-->";
$replacement .= '\n </script>';
// XHTML compliance no Javascript text handling
$replacement .= "<script type='text/javascript'>";
$replacement .= "\n <!--";
$replacement .= "\n document.write('<span style=\'display: none;\'>');";
$replacement .= "\n //-->";
$replacement .= "\n </script>";
$replacement .= JText::_('JLIB_HTML_CLOAKING');
$replacement .= "\n <script type='text/javascript'>";
$replacement .= "\n <!--";
$replacement .= "\n document.write('</');";
$replacement .= "\n document.write('span>');";
$replacement .= "\n //-->";
$replacement .= "\n </script>";
return $replacement;
}
/**
* Convert encoded text
*
* @param string $text Text to convert
*
* @return string The converted text.
*
* @since 1.5
*/
protected static function convertEncoding($text)
{
// Replace vowels with character encoding
$text = str_replace('a', '&#97;', $text);
$text = str_replace('e', '&#101;', $text);
$text = str_replace('i', '&#105;', $text);
$text = str_replace('o', '&#111;', $text);
$text = str_replace('u', '&#117;', $text);
return $text;
}
}

View File

@ -0,0 +1,35 @@
<?php
/**
* @package Joomla.Libraries
* @subpackage HTML
*
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
defined('JPATH_PLATFORM') or die;
/**
* Utility class for form elements
*
* @package Joomla.Libraries
* @subpackage HTML
* @since 1.5
*/
abstract class JHtmlForm
{
/**
* Displays a hidden token field to reduce the risk of CSRF exploits
*
* Use in conjunction with JSession::checkToken
*
* @return string A hidden input field with a token
*
* @see JSession::checkToken
* @since 1.5
*/
public static function token()
{
return '<input type="hidden" name="' . JSession::getFormToken() . '" value="1" />';
}
}

View File

@ -0,0 +1,147 @@
<?php
/**
* @package Joomla.Libraries
* @subpackage HTML
*
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
defined('JPATH_PLATFORM') or die;
/**
* Utility class for form related behaviors
*
* @package Joomla.Libraries
* @subpackage HTML
* @since 3.0
*/
abstract class JHtmlFormbehavior
{
/**
* @var array Array containing information for loaded files
* @since 3.0
*/
protected static $loaded = array();
/**
* Method to load the Chosen JavaScript framework and supporting CSS into the document head
*
* If debugging mode is on an uncompressed version of Chosen is included for easier debugging.
*
* @param string $selector Class for Chosen elements.
* @param mixed $debug Is debugging mode on? [optional]
*
* @return void
*
* @since 3.0
*/
public static function chosen($selector = '.advancedSelect', $debug = null)
{
if (isset(static::$loaded[__METHOD__][$selector]))
{
return;
}
// Include jQuery
JHtml::_('jquery.framework');
// Add chosen.jquery.js language strings
JText::script('JGLOBAL_SELECT_SOME_OPTIONS');
JText::script('JGLOBAL_SELECT_AN_OPTION');
JText::script('JGLOBAL_SELECT_NO_RESULTS_MATCH');
// If no debugging value is set, use the configuration setting
if ($debug === null)
{
$config = JFactory::getConfig();
$debug = (boolean) $config->get('debug');
}
JHtml::_('script', 'jui/chosen.jquery.min.js', false, true, false, false, $debug);
JHtml::_('stylesheet', 'jui/chosen.css', false, true);
JFactory::getDocument()->addScriptDeclaration("
jQuery(document).ready(function (){
jQuery('" . $selector . "').chosen({
disable_search_threshold : 10,
allow_single_deselect : true
});
});
"
);
static::$loaded[__METHOD__][$selector] = true;
return;
}
/**
* Method to load the AJAX Chosen library
*
* If debugging mode is on an uncompressed version of AJAX Chosen is included for easier debugging.
*
* @param JRegistry $options Options in a JRegistry object
* @param mixed $debug Is debugging mode on? [optional]
*
* @return void
*
* @since 3.0
*/
public static function ajaxchosen(JRegistry $options, $debug = null)
{
// Retrieve options/defaults
$selector = $options->get('selector', '.tagfield');
$type = $options->get('type', 'GET');
$url = $options->get('url', null);
$dataType = $options->get('dataType', 'json');
$jsonTermKey = $options->get('jsonTermKey', 'term');
$afterTypeDelay = $options->get('afterTypeDelay', '500');
$minTermLength = $options->get('minTermLength', '3');
JText::script('JGLOBAL_KEEP_TYPING');
JText::script('JGLOBAL_LOOKING_FOR');
// Ajax URL is mandatory
if (!empty($url))
{
if (isset(static::$loaded[__METHOD__][$selector]))
{
return;
}
// Include jQuery
JHtml::_('jquery.framework');
// Requires chosen to work
static::chosen($selector, $debug);
JHtml::_('script', 'jui/ajax-chosen.min.js', false, true, false, false, $debug);
JFactory::getDocument()->addScriptDeclaration("
(function($){
$(document).ready(function () {
$('" . $selector . "').ajaxChosen({
type: '" . $type . "',
url: '" . $url . "',
dataType: '" . $dataType . "',
jsonTermKey: '" . $jsonTermKey . "',
afterTypeDelay: '" . $afterTypeDelay . "',
minTermLength: '" . $minTermLength . "'
}, function (data) {
var results = [];
$.each(data, function (i, val) {
results.push({ value: val.value, text: val.text });
});
return results;
});
});
})(jQuery);
"
);
static::$loaded[__METHOD__][$selector] = true;
}
return;
}
}

355
libraries/cms/html/grid.php Normal file
View File

@ -0,0 +1,355 @@
<?php
/**
* @package Joomla.Platform
* @subpackage HTML
*
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
defined('JPATH_PLATFORM') or die;
/**
* Utility class for creating HTML Grids
*
* @package Joomla.Platform
* @subpackage HTML
* @since 1.5
*/
abstract class JHtmlGrid
{
/**
* Display a boolean setting widget.
*
* @param integer $i The row index.
* @param integer $value The value of the boolean field.
* @param string $taskOn Task to turn the boolean setting on.
* @param string $taskOff Task to turn the boolean setting off.
*
* @return string The boolean setting widget.
*
* @since 1.6
*/
public static function boolean($i, $value, $taskOn = null, $taskOff = null)
{
// Load the behavior.
static::behavior();
JHtml::_('bootstrap.tooltip');
// Build the title.
$title = ($value) ? JText::_('JYES') : JText::_('JNO');
$title = JHtml::tooltipText($title, JText::_('JGLOBAL_CLICK_TO_TOGGLE_STATE'), 0);
// Build the <a> tag.
$bool = ($value) ? 'true' : 'false';
$task = ($value) ? $taskOff : $taskOn;
$toggle = (!$task) ? false : true;
if ($toggle)
{
return '<a class="grid_' . $bool . ' hasToolip" title="' . $title . '" rel="{id:\'cb' . $i . '\', task:\'' . $task
. '\'}" href="#toggle"></a>';
}
else
{
return '<a class="grid_' . $bool . '"></a>';
}
}
/**
* Method to sort a column in a grid
*
* @param string $title The link title
* @param string $order The order field for the column
* @param string $direction The current direction
* @param string $selected The selected ordering
* @param string $task An optional task override
* @param string $new_direction An optional direction for the new column
* @param string $tip An optional text shown as tooltip title instead of $title
*
* @return string
*
* @since 1.5
*/
public static function sort($title, $order, $direction = 'asc', $selected = 0, $task = null, $new_direction = 'asc', $tip = '')
{
JHtml::_('bootstrap.tooltip');
$direction = strtolower($direction);
$icon = array('arrow-up-3', 'arrow-down-3');
$index = (int) ($direction == 'desc');
if ($order != $selected)
{
$direction = $new_direction;
}
else
{
$direction = ($direction == 'desc') ? 'asc' : 'desc';
}
$html = '<a href="#" onclick="Joomla.tableOrdering(\'' . $order . '\',\'' . $direction . '\',\'' . $task . '\');return false;"'
. ' class="hasTooltip" title="' . JHtml::tooltipText(($tip ? $tip : $title), 'JGLOBAL_CLICK_TO_SORT_THIS_COLUMN') . '">';
if (isset($title['0']) && $title['0'] == '<')
{
$html .= $title;
}
else
{
$html .= JText::_($title);
}
if ($order == $selected)
{
$html .= ' <i class="icon-' . $icon[$index] . '"></i>';
}
$html .= '</a>';
return $html;
}
/**
* Method to check all checkboxes in a grid
*
* @param string $name The name of the form element
* @param string $tip The text shown as tooltip title instead of $tip
* @param string $action The action to perform on clicking the checkbox
*
* @return string
*
* @since 3.1.2
*/
public static function checkall($name = 'checkall-toggle', $tip = 'JGLOBAL_CHECK_ALL', $action = 'Joomla.checkAll(this)')
{
JHtml::_('bootstrap.tooltip');
return '<input type="checkbox" name="' . $name . '" value="" class="hasTooltip" title="' . JHtml::tooltipText($tip) . '" onclick="' . $action . '" />';
}
/**
* Method to create a checkbox for a grid row.
*
* @param integer $rowNum The row index
* @param integer $recId The record id
* @param boolean $checkedOut True if item is checke out
* @param string $name The name of the form element
*
* @return mixed String of html with a checkbox if item is not checked out, null if checked out.
*
* @since 1.5
*/
public static function id($rowNum, $recId, $checkedOut = false, $name = 'cid')
{
return $checkedOut ? '' : '<input type="checkbox" id="cb' . $rowNum . '" name="' . $name . '[]" value="' . $recId
. '" onclick="Joomla.isChecked(this.checked);" />';
}
/**
* Displays a checked out icon.
*
* @param object &$row A data object (must contain checkedout as a property).
* @param integer $i The index of the row.
* @param string $identifier The property name of the primary key or index of the row.
*
* @return string
*
* @since 1.5
*/
public static function checkedOut(&$row, $i, $identifier = 'id')
{
$user = JFactory::getUser();
$userid = $user->get('id');
if ($row instanceof JTable)
{
$result = $row->isCheckedOut($userid);
}
else
{
$result = false;
}
if ($result)
{
return static::_checkedOut($row);
}
else
{
if ($identifier == 'id')
{
return JHtml::_('grid.id', $i, $row->$identifier);
}
else
{
return JHtml::_('grid.id', $i, $row->$identifier, $result, $identifier);
}
}
}
/**
* Method to create a clickable icon to change the state of an item
*
* @param mixed $value Either the scalar value or an object (for backward compatibility, deprecated)
* @param integer $i The index
* @param string $img1 Image for a positive or on value
* @param string $img0 Image for the empty or off value
* @param string $prefix An optional prefix for the task
*
* @return string
*
* @since 1.5
*/
public static function published($value, $i, $img1 = 'tick.png', $img0 = 'publish_x.png', $prefix = '')
{
if (is_object($value))
{
$value = $value->published;
}
$img = $value ? $img1 : $img0;
$task = $value ? 'unpublish' : 'publish';
$alt = $value ? JText::_('JPUBLISHED') : JText::_('JUNPUBLISHED');
$action = $value ? JText::_('JLIB_HTML_UNPUBLISH_ITEM') : JText::_('JLIB_HTML_PUBLISH_ITEM');
return '<a href="#" onclick="return listItemTask(\'cb' . $i . '\',\'' . $prefix . $task . '\')" title="' . $action . '">'
. JHtml::_('image', 'admin/' . $img, $alt, null, true) . '</a>';
}
/**
* Method to create a select list of states for filtering
* By default the filter shows only published and unpublished items
*
* @param string $filter_state The initial filter state
* @param string $published The JText string for published
* @param string $unpublished The JText string for Unpublished
* @param string $archived The JText string for Archived
* @param string $trashed The JText string for Trashed
*
* @return string
*
* @since 1.5
*/
public static function state($filter_state = '*', $published = 'Published', $unpublished = 'Unpublished', $archived = null, $trashed = null)
{
$state = array('' => '- ' . JText::_('JLIB_HTML_SELECT_STATE') . ' -', 'P' => JText::_($published), 'U' => JText::_($unpublished));
if ($archived)
{
$state['A'] = JText::_($archived);
}
if ($trashed)
{
$state['T'] = JText::_($trashed);
}
return JHtml::_(
'select.genericlist',
$state,
'filter_state',
array(
'list.attr' => 'class="inputbox" size="1" onchange="Joomla.submitform();"',
'list.select' => $filter_state,
'option.key' => null
)
);
}
/**
* Method to create an icon for saving a new ordering in a grid
*
* @param array $rows The array of rows of rows
* @param string $image The image [UNUSED]
* @param string $task The task to use, defaults to save order
*
* @return string
*
* @since 1.5
*/
public static function order($rows, $image = 'filesave.png', $task = 'saveorder')
{
return '<a href="javascript:saveorder(' . (count($rows) - 1) . ', \'' . $task . '\')" rel="tooltip" class="saveorder btn btn-micro pull-right" title="'
. JText::_('JLIB_HTML_SAVE_ORDER') . '"><i class="icon-menu-2"></i></a>';
}
/**
* Method to create a checked out icon with optional overlib in a grid.
*
* @param object &$row The row object
* @param boolean $overlib True if an overlib with checkout information should be created.
*
* @return string HTMl for the icon and overlib
*
* @since 1.5
*/
protected static function _checkedOut(&$row, $overlib = true)
{
$hover = '';
if ($overlib)
{
JHtml::_('bootstrap.tooltip');
$date = JHtml::_('date', $row->checked_out_time, JText::_('DATE_FORMAT_LC1'));
$time = JHtml::_('date', $row->checked_out_time, 'H:i');
$hover = '<span class="editlinktip hasTooltip" title="' . JHtml::tooltipText('JLIB_HTML_CHECKED_OUT', $row->editor) . '<br />' . $date . '<br />'
. $time . '">';
}
return $hover . JHtml::_('image', 'admin/checked_out.png', null, null, true) . '</span>';
}
/**
* Method to build the behavior script and add it to the document head.
*
* @return void
*
* @since 1.6
*/
public static function behavior()
{
static $loaded;
if (!$loaded)
{
// Build the behavior script.
$js = '
window.addEvent(\'domready\', function(){
actions = $$(\'a.move_up\');
actions.combine($$(\'a.move_down\'));
actions.combine($$(\'a.grid_true\'));
actions.combine($$(\'a.grid_false\'));
actions.combine($$(\'a.grid_trash\'));
actions.each(function(a){
a.addEvent(\'click\', function(){
args = JSON.decode(this.rel);
listItemTask(args.id, args.task);
});
});
$$(\'input.check-all-toggle\').each(function(el){
el.addEvent(\'click\', function(){
if (el.checked) {
document.id(this.form).getElements(\'input[type=checkbox]\').each(function(i){
i.checked = true;
})
}
else {
document.id(this.form).getElements(\'input[type=checkbox]\').each(function(i){
i.checked = false;
})
}
});
});
});';
// Add the behavior to the document head.
$document = JFactory::getDocument();
$document->addScriptDeclaration($js);
$loaded = true;
}
}
}

1093
libraries/cms/html/html.php Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,80 @@
<?php
/**
* @package Joomla.Libraries
* @subpackage HTML
*
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
defined('JPATH_BASE') or die;
/**
* Utility class for icons.
*
* @package Joomla.Libraries
* @subpackage HTML
* @since 2.5
*/
abstract class JHtmlIcons
{
/**
* Method to generate html code for a list of buttons
*
* @param array $buttons Array of buttons
*
* @return string
*
* @since 2.5
*/
public static function buttons($buttons)
{
$html = array();
foreach ($buttons as $button)
{
$html[] = JHtml::_('icons.button', $button);
}
return implode($html);
}
/**
* Method to generate html code for a list of buttons
*
* @param array $button Button properties
*
* @return string
*
* @since 2.5
*/
public static function button($button)
{
if (isset($button['access']))
{
if (is_bool($button['access']))
{
if ($button['access'] == false)
{
return '';
}
}
else
{
// Get the user object to verify permissions
$user = JFactory::getUser();
// Take each pair of permission, context values.
for ($i = 0, $n = count($button['access']); $i < $n; $i += 2)
{
if (!$user->authorise($button['access'][$i], $button['access'][$i + 1]))
{
return '';
}
}
}
}
// Instantiate a new JLayoutFile instance and render the layout
$layout = new JLayoutFile('joomla.quickicons.icon');
return $layout->render($button);
}
}

View File

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

View File

@ -0,0 +1,403 @@
<?php
/**
* @package Joomla.Libraries
* @subpackage HTML
*
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
defined('JPATH_PLATFORM') or die;
/**
* Utility class for creating HTML Grids
*
* @package Joomla.Libraries
* @subpackage HTML
* @since 1.6
*/
abstract class JHtmlJGrid
{
/**
* Returns an action on a grid
*
* @param integer $i The row index
* @param string $task The task to fire
* @param string|array $prefix An optional task prefix or an array of options
* @param string $text An optional text to display [unused - @deprecated 4.0]
* @param string $active_title An optional active tooltip to display if $enable is true
* @param string $inactive_title An optional inactive tooltip to display if $enable is true
* @param boolean $tip An optional setting for tooltip
* @param string $active_class An optional active HTML class
* @param string $inactive_class An optional inactive HTML class
* @param boolean $enabled An optional setting for access control on the action.
* @param boolean $translate An optional setting for translation.
* @param string $checkbox An optional prefix for checkboxes.
*
* @return string The HTML markup
*
* @since 1.6
*/
public static function action($i, $task, $prefix = '', $text = '', $active_title = '', $inactive_title = '', $tip = false, $active_class = '',
$inactive_class = '', $enabled = true, $translate = true, $checkbox = 'cb')
{
if (is_array($prefix))
{
$options = $prefix;
$active_title = array_key_exists('active_title', $options) ? $options['active_title'] : $active_title;
$inactive_title = array_key_exists('inactive_title', $options) ? $options['inactive_title'] : $inactive_title;
$tip = array_key_exists('tip', $options) ? $options['tip'] : $tip;
$active_class = array_key_exists('active_class', $options) ? $options['active_class'] : $active_class;
$inactive_class = array_key_exists('inactive_class', $options) ? $options['inactive_class'] : $inactive_class;
$enabled = array_key_exists('enabled', $options) ? $options['enabled'] : $enabled;
$translate = array_key_exists('translate', $options) ? $options['translate'] : $translate;
$checkbox = array_key_exists('checkbox', $options) ? $options['checkbox'] : $checkbox;
$prefix = array_key_exists('prefix', $options) ? $options['prefix'] : '';
}
if ($tip)
{
JHtml::_('bootstrap.tooltip');
$title = $enabled ? $active_title : $inactive_title;
$title = $translate ? JText::_($title) : $title;
$title = JHtml::tooltipText($title, '', 0);
}
if ($enabled)
{
$html[] = '<a class="btn btn-micro ' . ($active_class == "publish" ? 'active' : '') . ' ' . ($tip ? 'hasTooltip"' : '') . '"';
$html[] = ' href="javascript:void(0);" onclick="return listItemTask(\'' . $checkbox . $i . '\',\'' . $prefix . $task . '\')"';
$html[] = $tip ? ' title="' . $title . '"' : '';
$html[] = '>';
$html[] = '<i class="icon-' . $active_class . '">';
$html[] = '</i>';
$html[] = '</a>';
}
else
{
$html[] = '<a class="btn btn-micro disabled jgrid ' . ($tip ? 'hasTooltip"' : '') . '"';
$html[] = $tip ? ' title="' . $title . '"' : '';
$html[] = '>';
if ($active_class == "protected")
{
$html[] = '<i class="icon-lock"></i>';
}
else
{
$html[] = '<i class="icon-' . $inactive_class . '"></i>';
}
$html[] = '</a>';
}
return implode($html);
}
/**
* Returns a state on a grid
*
* @param array $states array of value/state. Each state is an array of the form
* (task, text, title,html active class, HTML inactive class)
* or ('task'=>task, 'text'=>text, 'active_title'=>active title,
* 'inactive_title'=>inactive title, 'tip'=>boolean, 'active_class'=>html active class,
* 'inactive_class'=>html inactive class)
* @param integer $value The state value.
* @param integer $i The row index
* @param string|array $prefix An optional task prefix or an array of options
* @param boolean $enabled An optional setting for access control on the action.
* @param boolean $translate An optional setting for translation.
* @param string $checkbox An optional prefix for checkboxes.
*
* @return string The HTML markup
*
* @since 1.6
*/
public static function state($states, $value, $i, $prefix = '', $enabled = true, $translate = true, $checkbox = 'cb')
{
if (is_array($prefix))
{
$options = $prefix;
$enabled = array_key_exists('enabled', $options) ? $options['enabled'] : $enabled;
$translate = array_key_exists('translate', $options) ? $options['translate'] : $translate;
$checkbox = array_key_exists('checkbox', $options) ? $options['checkbox'] : $checkbox;
$prefix = array_key_exists('prefix', $options) ? $options['prefix'] : '';
}
$state = JArrayHelper::getValue($states, (int) $value, $states[0]);
$task = array_key_exists('task', $state) ? $state['task'] : $state[0];
$text = array_key_exists('text', $state) ? $state['text'] : (array_key_exists(1, $state) ? $state[1] : '');
$active_title = array_key_exists('active_title', $state) ? $state['active_title'] : (array_key_exists(2, $state) ? $state[2] : '');
$inactive_title = array_key_exists('inactive_title', $state) ? $state['inactive_title'] : (array_key_exists(3, $state) ? $state[3] : '');
$tip = array_key_exists('tip', $state) ? $state['tip'] : (array_key_exists(4, $state) ? $state[4] : false);
$active_class = array_key_exists('active_class', $state) ? $state['active_class'] : (array_key_exists(5, $state) ? $state[5] : '');
$inactive_class = array_key_exists('inactive_class', $state) ? $state['inactive_class'] : (array_key_exists(6, $state) ? $state[6] : '');
return static::action(
$i, $task, $prefix, $text, $active_title, $inactive_title, $tip,
$active_class, $inactive_class, $enabled, $translate, $checkbox
);
}
/**
* Returns a published state on a grid
*
* @param integer $value The state value.
* @param integer $i The row index
* @param string|array $prefix An optional task prefix or an array of options
* @param boolean $enabled An optional setting for access control on the action.
* @param string $checkbox An optional prefix for checkboxes.
* @param string $publish_up An optional start publishing date.
* @param string $publish_down An optional finish publishing date.
*
* @return string The HTML markup
*
* @see JHtmlJGrid::state
* @since 1.6
*/
public static function published($value, $i, $prefix = '', $enabled = true, $checkbox = 'cb', $publish_up = null, $publish_down = null)
{
if (is_array($prefix))
{
$options = $prefix;
$enabled = array_key_exists('enabled', $options) ? $options['enabled'] : $enabled;
$checkbox = array_key_exists('checkbox', $options) ? $options['checkbox'] : $checkbox;
$prefix = array_key_exists('prefix', $options) ? $options['prefix'] : '';
}
$states = array(1 => array('unpublish', 'JPUBLISHED', 'JLIB_HTML_UNPUBLISH_ITEM', 'JPUBLISHED', true, 'publish', 'publish'),
0 => array('publish', 'JUNPUBLISHED', 'JLIB_HTML_PUBLISH_ITEM', 'JUNPUBLISHED', true, 'unpublish', 'unpublish'),
2 => array('unpublish', 'JARCHIVED', 'JLIB_HTML_UNPUBLISH_ITEM', 'JARCHIVED', true, 'archive', 'archive'),
-2 => array('publish', 'JTRASHED', 'JLIB_HTML_PUBLISH_ITEM', 'JTRASHED', true, 'trash', 'trash'));
// Special state for dates
if ($publish_up || $publish_down)
{
$nullDate = JFactory::getDbo()->getNullDate();
$nowDate = JFactory::getDate()->toUnix();
$tz = new DateTimeZone(JFactory::getUser()->getParam('timezone', JFactory::getConfig()->get('offset')));
$publish_up = ($publish_up != $nullDate) ? JFactory::getDate($publish_up, 'UTC')->setTimeZone($tz) : false;
$publish_down = ($publish_down != $nullDate) ? JFactory::getDate($publish_down, 'UTC')->setTimeZone($tz) : false;
// Create tip text, only we have publish up or down settings
$tips = array();
if ($publish_up)
{
$tips[] = JText::sprintf('JLIB_HTML_PUBLISHED_START', $publish_up->format(JDate::$format, true));
}
if ($publish_down)
{
$tips[] = JText::sprintf('JLIB_HTML_PUBLISHED_FINISHED', $publish_down->format(JDate::$format, true));
}
$tip = empty($tips) ? false : implode('<br/>', $tips);
// Add tips and special titles
foreach ($states as $key => $state)
{
// Create special titles for published items
if ($key == 1)
{
$states[$key][2] = $states[$key][3] = 'JLIB_HTML_PUBLISHED_ITEM';
if ($publish_up > $nullDate && $nowDate < $publish_up->toUnix())
{
$states[$key][2] = $states[$key][3] = 'JLIB_HTML_PUBLISHED_PENDING_ITEM';
$states[$key][5] = $states[$key][6] = 'pending';
}
if ($publish_down > $nullDate && $nowDate > $publish_down->toUnix())
{
$states[$key][2] = $states[$key][3] = 'JLIB_HTML_PUBLISHED_EXPIRED_ITEM';
$states[$key][5] = $states[$key][6] = 'expired';
}
}
// Add tips to titles
if ($tip)
{
$states[$key][1] = JText::_($states[$key][1]);
$states[$key][2] = JText::_($states[$key][2]) . '<br />' . $tip;
$states[$key][3] = JText::_($states[$key][3]) . '<br />' . $tip;
$states[$key][4] = true;
}
}
return static::state($states, $value, $i, array('prefix' => $prefix, 'translate' => !$tip), $enabled, true, $checkbox);
}
return static::state($states, $value, $i, $prefix, $enabled, true, $checkbox);
}
/**
* Returns a isDefault state on a grid
*
* @param integer $value The state value.
* @param integer $i The row index
* @param string|array $prefix An optional task prefix or an array of options
* @param boolean $enabled An optional setting for access control on the action.
* @param string $checkbox An optional prefix for checkboxes.
*
* @return string The HTML markup
*
* @see JHtmlJGrid::state
* @since 1.6
*/
public static function isdefault($value, $i, $prefix = '', $enabled = true, $checkbox = 'cb')
{
if (is_array($prefix))
{
$options = $prefix;
$enabled = array_key_exists('enabled', $options) ? $options['enabled'] : $enabled;
$checkbox = array_key_exists('checkbox', $options) ? $options['checkbox'] : $checkbox;
$prefix = array_key_exists('prefix', $options) ? $options['prefix'] : '';
}
$states = array(
0 => array('setDefault', '', 'JLIB_HTML_SETDEFAULT_ITEM', '', 1, 'unfeatured', 'unfeatured'),
1 => array('unsetDefault', 'JDEFAULT', 'JLIB_HTML_UNSETDEFAULT_ITEM', 'JDEFAULT', 1, 'featured', 'featured'),
);
return static::state($states, $value, $i, $prefix, $enabled, true, $checkbox);
}
/**
* Returns an array of standard published state filter options.
*
* @param array $config An array of configuration options.
* This array can contain a list of key/value pairs where values are boolean
* and keys can be taken from 'published', 'unpublished', 'archived', 'trash', 'all'.
* These pairs determine which values are displayed.
*
* @return string The HTML markup
*
* @since 1.6
*/
public static function publishedOptions($config = array())
{
// Build the active state filter options.
$options = array();
if (!array_key_exists('published', $config) || $config['published'])
{
$options[] = JHtml::_('select.option', '1', 'JPUBLISHED');
}
if (!array_key_exists('unpublished', $config) || $config['unpublished'])
{
$options[] = JHtml::_('select.option', '0', 'JUNPUBLISHED');
}
if (!array_key_exists('archived', $config) || $config['archived'])
{
$options[] = JHtml::_('select.option', '2', 'JARCHIVED');
}
if (!array_key_exists('trash', $config) || $config['trash'])
{
$options[] = JHtml::_('select.option', '-2', 'JTRASHED');
}
if (!array_key_exists('all', $config) || $config['all'])
{
$options[] = JHtml::_('select.option', '*', 'JALL');
}
return $options;
}
/**
* Returns a checked-out icon
*
* @param integer $i The row index.
* @param string $editorName The name of the editor.
* @param string $time The time that the object was checked out.
* @param string|array $prefix An optional task prefix or an array of options
* @param boolean $enabled True to enable the action.
* @param string $checkbox An optional prefix for checkboxes.
*
* @return string The HTML markup
*
* @since 1.6
*/
public static function checkedout($i, $editorName, $time, $prefix = '', $enabled = false, $checkbox = 'cb')
{
JHtml::_('bootstrap.tooltip');
if (is_array($prefix))
{
$options = $prefix;
$enabled = array_key_exists('enabled', $options) ? $options['enabled'] : $enabled;
$checkbox = array_key_exists('checkbox', $options) ? $options['checkbox'] : $checkbox;
$prefix = array_key_exists('prefix', $options) ? $options['prefix'] : '';
}
$text = $editorName . '<br />' . JHtml::_('date', $time, JText::_('DATE_FORMAT_LC')) . '<br />' . JHtml::_('date', $time, 'H:i');
$active_title = JHtml::tooltipText(JText::_('JLIB_HTML_CHECKIN'), $text, 0);
$inactive_title = JHtml::tooltipText(JText::_('JLIB_HTML_CHECKED_OUT'), $text, 0);
return static::action(
$i, 'checkin', $prefix, JText::_('JLIB_HTML_CHECKED_OUT'), $active_title, $inactive_title, true, 'checkedout',
'checkedout', $enabled, false, $checkbox
);
}
/**
* Creates a order-up action icon.
*
* @param integer $i The row index.
* @param string $task An optional task to fire.
* @param string|array $prefix An optional task prefix or an array of options
* @param string $text An optional text to display
* @param boolean $enabled An optional setting for access control on the action.
* @param string $checkbox An optional prefix for checkboxes.
*
* @return string The HTML markup
*
* @since 1.6
*/
public static function orderUp($i, $task = 'orderup', $prefix = '', $text = 'JLIB_HTML_MOVE_UP', $enabled = true, $checkbox = 'cb')
{
if (is_array($prefix))
{
$options = $prefix;
$text = array_key_exists('text', $options) ? $options['text'] : $text;
$enabled = array_key_exists('enabled', $options) ? $options['enabled'] : $enabled;
$checkbox = array_key_exists('checkbox', $options) ? $options['checkbox'] : $checkbox;
$prefix = array_key_exists('prefix', $options) ? $options['prefix'] : '';
}
return static::action($i, $task, $prefix, $text, $text, $text, false, 'uparrow', 'uparrow_disabled', $enabled, true, $checkbox);
}
/**
* Creates a order-down action icon.
*
* @param integer $i The row index.
* @param string $task An optional task to fire.
* @param string|array $prefix An optional task prefix or an array of options
* @param string $text An optional text to display
* @param boolean $enabled An optional setting for access control on the action.
* @param string $checkbox An optional prefix for checkboxes.
*
* @return string The HTML markup
*
* @since 1.6
*/
public static function orderDown($i, $task = 'orderdown', $prefix = '', $text = 'JLIB_HTML_MOVE_DOWN', $enabled = true, $checkbox = 'cb')
{
if (is_array($prefix))
{
$options = $prefix;
$text = array_key_exists('text', $options) ? $options['text'] : $text;
$enabled = array_key_exists('enabled', $options) ? $options['enabled'] : $enabled;
$checkbox = array_key_exists('checkbox', $options) ? $options['checkbox'] : $checkbox;
$prefix = array_key_exists('prefix', $options) ? $options['prefix'] : '';
}
return static::action($i, $task, $prefix, $text, $text, $text, false, 'downarrow', 'downarrow_disabled', $enabled, true, $checkbox);
}
}

View File

@ -0,0 +1,107 @@
<?php
/**
* @package Joomla.Libraries
* @subpackage HTML
*
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
defined('JPATH_PLATFORM') or die;
/**
* Utility class for jQuery JavaScript behaviors
*
* @package Joomla.Libraries
* @subpackage HTML
* @since 3.0
*/
abstract class JHtmlJquery
{
/**
* @var array Array containing information for loaded files
* @since 3.0
*/
protected static $loaded = array();
/**
* Method to load the jQuery JavaScript framework into the document head
*
* If debugging mode is on an uncompressed version of jQuery is included for easier debugging.
*
* @param boolean $noConflict True to load jQuery in noConflict mode [optional]
* @param mixed $debug Is debugging mode on? [optional]
*
* @return void
*
* @since 3.0
*/
public static function framework($noConflict = true, $debug = null)
{
// Only load once
if (!empty(static::$loaded[__METHOD__]))
{
return;
}
// If no debugging value is set, use the configuration setting
if ($debug === null)
{
$config = JFactory::getConfig();
$debug = (boolean) $config->get('debug');
}
JHtml::_('script', 'jui/jquery.min.js', false, true, false, false, $debug);
// Check if we are loading in noConflict
if ($noConflict)
{
JHtml::_('script', 'jui/jquery-noconflict.js', false, true, false, false, false);
}
static::$loaded[__METHOD__] = true;
return;
}
/**
* Method to load the jQuery UI JavaScript framework into the document head
*
* If debugging mode is on an uncompressed version of jQuery UI is included for easier debugging.
*
* @param array $components The jQuery UI components to load [optional]
* @param mixed $debug Is debugging mode on? [optional]
*
* @return void
*
* @since 3.0
*/
public static function ui(array $components = array('core'), $debug = null)
{
// Set an array containing the supported jQuery UI components handled by this method
$supported = array('core', 'sortable');
// Include jQuery
static::framework();
// If no debugging value is set, use the configuration setting
if ($debug === null)
{
$config = JFactory::getConfig();
$debug = (boolean) $config->get('debug');
}
// Load each of the requested components
foreach ($components as $component)
{
// Only attempt to load the component if it's supported in core and hasn't already been loaded
if (in_array($component, $supported) && empty(static::$loaded[__METHOD__][$component]))
{
JHtml::_('script', 'jui/jquery.ui.' . $component . '.min.js', false, true, false, false, $debug);
static::$loaded[__METHOD__][$component] = true;
}
}
return;
}
}

View File

@ -0,0 +1,18 @@
; Joomla! Project
; Copyright (C) 2005 - 2013 Open Source Matters. All rights reserved.
; License GNU General Public License version 2 or later; see LICENSE.txt, see LICENSE.php
; Note : All ini files need to be saved as UTF-8 - No BOM
JLIB_HTML_DATE_RELATIVE_DAYS="%s days ago"
JLIB_HTML_DATE_RELATIVE_DAYS_1="%s day ago"
JLIB_HTML_DATE_RELATIVE_DAYS_0="%s days ago"
JLIB_HTML_DATE_RELATIVE_HOURS="%s hours ago"
JLIB_HTML_DATE_RELATIVE_HOURS_1="%s hour ago"
JLIB_HTML_DATE_RELATIVE_HOURS_0="%s hours ago"
JLIB_HTML_DATE_RELATIVE_LESSTHANAMINUTE="Less than a minute ago"
JLIB_HTML_DATE_RELATIVE_MINUTES="%s minutes ago"
JLIB_HTML_DATE_RELATIVE_MINUTES_1="%s minute ago"
JLIB_HTML_DATE_RELATIVE_MINUTES_0="%s minutes ago"
JLIB_HTML_DATE_RELATIVE_WEEKS="%s weeks ago"
JLIB_HTML_DATE_RELATIVE_WEEKS_1="%s week ago"
JLIB_HTML_DATE_RELATIVE_WEEKS_0="%s weeks ago"

View File

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

View File

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

270
libraries/cms/html/list.php Normal file
View File

@ -0,0 +1,270 @@
<?php
/**
* @package Joomla.Libraries
* @subpackage HTML
*
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
defined('JPATH_PLATFORM') or die;
/**
* Utility class for creating different select lists
*
* @package Joomla.Libraries
* @subpackage HTML
* @since 1.5
*/
abstract class JHtmlList
{
/**
* Build the select list to choose an image
*
* @param string $name The name of the field
* @param string $active The selected item
* @param string $javascript Alternative javascript
* @param string $directory Directory the images are stored in
* @param string $extensions Allowed extensions
*
* @return array Image names
*
* @since 1.5
*/
public static function images($name, $active = null, $javascript = null, $directory = null, $extensions = "bmp|gif|jpg|png")
{
if (!$directory)
{
$directory = '/images/';
}
if (!$javascript)
{
$javascript = "onchange=\"if (document.forms.adminForm." . $name
. ".options[selectedIndex].value!='') {document.imagelib.src='..$directory' + document.forms.adminForm." . $name
. ".options[selectedIndex].value} else {document.imagelib.src='media/system/images/blank.png'}\"";
}
$imageFiles = new DirectoryIterator(JPATH_SITE . '/' . $directory);
$images = array(JHtml::_('select.option', '', JText::_('JOPTION_SELECT_IMAGE')));
foreach ($imageFiles as $file)
{
$fileName = $file->getFilename();
if (!$file->isFile())
{
continue;
}
if (preg_match('#(' . $extensions . ')$#', $fileName))
{
$images[] = JHtml::_('select.option', $fileName);
}
}
$images = JHtml::_(
'select.genericlist',
$images,
$name,
array(
'list.attr' => 'class="inputbox" size="1" ' . $javascript,
'list.select' => $active
)
);
return $images;
}
/**
* Returns an array of options
*
* @param string $query SQL with 'ordering' AS value and 'name field' AS text
* @param integer $chop The length of the truncated headline
*
* @return array An array of objects formatted for JHtml list processing
*
* @since 1.5
*/
public static function genericordering($query, $chop = 30)
{
$db = JFactory::getDbo();
$options = array();
$db->setQuery($query);
$items = $db->loadObjectList();
if (empty($items))
{
$options[] = JHtml::_('select.option', 1, JText::_('JOPTION_ORDER_FIRST'));
return $options;
}
$options[] = JHtml::_('select.option', 0, '0 ' . JText::_('JOPTION_ORDER_FIRST'));
for ($i = 0, $n = count($items); $i < $n; $i++)
{
$items[$i]->text = JText::_($items[$i]->text);
if (JString::strlen($items[$i]->text) > $chop)
{
$text = JString::substr($items[$i]->text, 0, $chop) . "...";
}
else
{
$text = $items[$i]->text;
}
$options[] = JHtml::_('select.option', $items[$i]->value, $items[$i]->value . '. ' . $text);
}
$options[] = JHtml::_('select.option', $items[$i - 1]->value + 1, ($items[$i - 1]->value + 1) . ' ' . JText::_('JOPTION_ORDER_LAST'));
return $options;
}
/**
* Build the select list for Ordering derived from a query
*
* @param integer $name The scalar value
* @param string $query The query
* @param string $attribs HTML tag attributes
* @param string $selected The selected item
* @param integer $neworder 1 if new and first, -1 if new and last, 0 or null if existing item
*
* @return string HTML markup for the select list
*
* @since 1.6
*/
public static function ordering($name, $query, $attribs = null, $selected = null, $neworder = null)
{
if (empty($attribs))
{
$attribs = 'class="inputbox" size="1"';
}
if (empty($neworder))
{
$orders = JHtml::_('list.genericordering', $query);
$html = JHtml::_('select.genericlist', $orders, $name, array('list.attr' => $attribs, 'list.select' => (int) $selected));
}
else
{
if ($neworder > 0)
{
$text = JText::_('JGLOBAL_NEWITEMSLAST_DESC');
}
elseif ($neworder <= 0)
{
$text = JText::_('JGLOBAL_NEWITEMSFIRST_DESC');
}
$html = '<input type="hidden" name="' . $name . '" value="' . (int) $selected . '" /><span class="readonly">' . $text . '</span>';
}
return $html;
}
/**
* Select list of active users
*
* @param string $name The name of the field
* @param string $active The active user
* @param integer $nouser If set include an option to select no user
* @param string $javascript Custom javascript
* @param string $order Specify a field to order by
*
* @return string The HTML for a list of users list of users
*
* @since 1.5
*/
public static function users($name, $active, $nouser = 0, $javascript = null, $order = 'name')
{
$db = JFactory::getDbo();
$query = $db->getQuery(true)
->select('u.id AS value, u.name AS text')
->from('#__users AS u')
->join('LEFT', '#__user_usergroup_map AS m ON m.user_id = u.id')
->where('u.block = 0')
->order($order)
->group('u.id');
$db->setQuery($query);
if ($nouser)
{
$users[] = JHtml::_('select.option', '0', JText::_('JOPTION_NO_USER'));
$users = array_merge($users, $db->loadObjectList());
}
else
{
$users = $db->loadObjectList();
}
$users = JHtml::_(
'select.genericlist',
$users,
$name,
array(
'list.attr' => 'class="inputbox" size="1" ' . $javascript,
'list.select' => $active
)
);
return $users;
}
/**
* Select list of positions - generally used for location of images
*
* @param string $name Name of the field
* @param string $active The active value
* @param string $javascript Alternative javascript
* @param boolean $none Null if not assigned
* @param boolean $center Null if not assigned
* @param boolean $left Null if not assigned
* @param boolean $right Null if not assigned
* @param boolean $id Null if not assigned
*
* @return array The positions
*
* @since 1.5
*/
public static function positions($name, $active = null, $javascript = null, $none = true, $center = true, $left = true, $right = true,
$id = false)
{
$pos = array();
if ($none)
{
$pos[''] = JText::_('JNONE');
}
if ($center)
{
$pos['center'] = JText::_('JGLOBAL_CENTER');
}
if ($left)
{
$pos['left'] = JText::_('JGLOBAL_LEFT');
}
if ($right)
{
$pos['right'] = JText::_('JGLOBAL_RIGHT');
}
$positions = JHtml::_(
'select.genericlist', $pos, $name,
array(
'id' => $id,
'list.attr' => 'class="inputbox" size="1"' . $javascript,
'list.select' => $active,
'option.key' => null,
)
);
return $positions;
}
}

357
libraries/cms/html/menu.php Normal file
View File

@ -0,0 +1,357 @@
<?php
/**
* @package Joomla.Libraries
* @subpackage HTML
*
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
defined('JPATH_PLATFORM') or die;
/**
* Utility class working with menu select lists
*
* @package Joomla.Libraries
* @subpackage HTML
* @since 1.5
*/
abstract class JHtmlMenu
{
/**
* Cached array of the menus.
*
* @var array
* @since 1.6
*/
protected static $menus = null;
/**
* Cached array of the menus items.
*
* @var array
* @since 1.6
*/
protected static $items = null;
/**
* Get a list of the available menus.
*
* @return string
*
* @since 1.6
*/
public static function menus()
{
if (empty(static::$menus))
{
$db = JFactory::getDbo();
$query = $db->getQuery(true)
->select('menutype AS value, title AS text')
->from($db->quoteName('#__menu_types'))
->order('title');
$db->setQuery($query);
static::$menus = $db->loadObjectList();
}
return static::$menus;
}
/**
* Returns an array of menu items grouped by menu.
*
* @param array $config An array of configuration options.
*
* @return array
*
* @since 1.6
*/
public static function menuitems($config = array())
{
if (empty(static::$items))
{
$db = JFactory::getDbo();
$query = $db->getQuery(true)
->select('menutype AS value, title AS text')
->from($db->quoteName('#__menu_types'))
->order('title');
$db->setQuery($query);
$menus = $db->loadObjectList();
$query->clear()
->select('a.id AS value, a.title AS text, a.level, a.menutype')
->from('#__menu AS a')
->where('a.parent_id > 0')
->where('a.type <> ' . $db->quote('url'))
->where('a.client_id = 0');
// Filter on the published state
if (isset($config['published']))
{
if (is_numeric($config['published']))
{
$query->where('a.published = ' . (int) $config['published']);
}
elseif ($config['published'] === '')
{
$query->where('a.published IN (0,1)');
}
}
$query->order('a.lft');
$db->setQuery($query);
$items = $db->loadObjectList();
// Collate menu items based on menutype
$lookup = array();
foreach ($items as &$item)
{
if (!isset($lookup[$item->menutype]))
{
$lookup[$item->menutype] = array();
}
$lookup[$item->menutype][] = &$item;
$item->text = str_repeat('- ', $item->level) . $item->text;
}
static::$items = array();
foreach ($menus as &$menu)
{
// Start group:
static::$items[] = JHtml::_('select.optgroup', $menu->text);
// Special "Add to this Menu" option:
static::$items[] = JHtml::_('select.option', $menu->value . '.1', JText::_('JLIB_HTML_ADD_TO_THIS_MENU'));
// Menu items:
if (isset($lookup[$menu->value]))
{
foreach ($lookup[$menu->value] as &$item)
{
static::$items[] = JHtml::_('select.option', $menu->value . '.' . $item->value, $item->text);
}
}
// Finish group:
static::$items[] = JHtml::_('select.optgroup', $menu->text);
}
}
return static::$items;
}
/**
* Displays an HTML select list of menu items.
*
* @param string $name The name of the control.
* @param string $selected The value of the selected option.
* @param string $attribs Attributes for the control.
* @param array $config An array of options for the control.
*
* @return string
*
* @since 1.6
*/
public static function menuitemlist($name, $selected = null, $attribs = null, $config = array())
{
static $count;
$options = static::menuitems($config);
return JHtml::_(
'select.genericlist', $options, $name,
array(
'id' => isset($config['id']) ? $config['id'] : 'assetgroups_' . (++$count),
'list.attr' => (is_null($attribs) ? 'class="inputbox" size="1"' : $attribs),
'list.select' => (int) $selected,
'list.translate' => false
)
);
}
/**
* Build the select list for Menu Ordering
*
* @param object &$row The row object
* @param integer $id The id for the row. Must exist to enable menu ordering
*
* @return string
*
* @since 1.5
*/
public static function ordering(&$row, $id)
{
if ($id)
{
$db = JFactory::getDbo();
$query = $db->getQuery(true)
->select('ordering AS value, title AS text')
->from($db->quoteName('#__menu'))
->where($db->quoteName('menutype') . ' = ' . $db->quote($row->menutype))
->where($db->quoteName('parent_id') . ' = ' . (int) $row->parent_id)
->where($db->quoteName('published') . ' != -2')
->order('ordering');
$order = JHtml::_('list.genericordering', $query);
$ordering = JHtml::_(
'select.genericlist', $order, 'ordering',
array('list.attr' => 'class="inputbox" size="1"', 'list.select' => (int) $row->ordering)
);
}
else
{
$ordering = '<input type="hidden" name="ordering" value="' . $row->ordering . '" />' . JText::_('JGLOBAL_NEWITEMSLAST_DESC');
}
return $ordering;
}
/**
* Build the multiple select list for Menu Links/Pages
*
* @param boolean $all True if all can be selected
* @param boolean $unassigned True if unassigned can be selected
*
* @return string
*
* @since 1.5
*/
public static function linkoptions($all = false, $unassigned = false)
{
$db = JFactory::getDbo();
// Get a list of the menu items
$query = $db->getQuery(true)
->select('m.id, m.parent_id, m.title, m.menutype')
->from($db->quoteName('#__menu') . ' AS m')
->where($db->quoteName('m.published') . ' = 1')
->order('m.menutype, m.parent_id, m.ordering');
$db->setQuery($query);
$mitems = $db->loadObjectList();
if (!$mitems)
{
$mitems = array();
}
// Establish the hierarchy of the menu
$children = array();
// First pass - collect children
foreach ($mitems as $v)
{
$pt = $v->parent_id;
$list = @$children[$pt] ? $children[$pt] : array();
array_push($list, $v);
$children[$pt] = $list;
}
// Second pass - get an indent list of the items
$list = static::treerecurse((int) $mitems[0]->parent_id, '', array(), $children, 9999, 0, 0);
// Code that adds menu name to Display of Page(s)
$mitems = array();
if ($all | $unassigned)
{
$mitems[] = JHtml::_('select.option', '<OPTGROUP>', JText::_('JOPTION_MENUS'));
if ($all)
{
$mitems[] = JHtml::_('select.option', 0, JText::_('JALL'));
}
if ($unassigned)
{
$mitems[] = JHtml::_('select.option', -1, JText::_('JOPTION_UNASSIGNED'));
}
$mitems[] = JHtml::_('select.option', '</OPTGROUP>');
}
$lastMenuType = null;
$tmpMenuType = null;
foreach ($list as $list_a)
{
if ($list_a->menutype != $lastMenuType)
{
if ($tmpMenuType)
{
$mitems[] = JHtml::_('select.option', '</OPTGROUP>');
}
$mitems[] = JHtml::_('select.option', '<OPTGROUP>', $list_a->menutype);
$lastMenuType = $list_a->menutype;
$tmpMenuType = $list_a->menutype;
}
$mitems[] = JHtml::_('select.option', $list_a->id, $list_a->title);
}
if ($lastMenuType !== null)
{
$mitems[] = JHtml::_('select.option', '</OPTGROUP>');
}
return $mitems;
}
/**
* Build the list representing the menu tree
*
* @param integer $id Id of the menu item
* @param string $indent The indentation string
* @param array $list The list to process
* @param array &$children The children of the current item
* @param integer $maxlevel The maximum number of levels in the tree
* @param integer $level The starting level
* @param string $type Type of link: component, URL, alias, separator
*
* @return array
*
* @since 1.5
*/
public static function treerecurse($id, $indent, $list, &$children, $maxlevel = 9999, $level = 0, $type = 1)
{
if (@$children[$id] && $level <= $maxlevel)
{
foreach ($children[$id] as $v)
{
$id = $v->id;
if ($type)
{
$pre = '<sup>|_</sup>&#160;';
$spacer = '.&#160;&#160;&#160;&#160;&#160;&#160;';
}
else
{
$pre = '- ';
$spacer = '&#160;&#160;';
}
if ($v->parent_id == 0)
{
$txt = $v->title;
}
else
{
$txt = $pre . $v->title;
}
$list[$id] = $v;
$list[$id]->treename = $indent . $txt;
$list[$id]->children = count(@$children[$id]);
$list = static::treerecurse($id, $indent . $spacer, $list, $children, $maxlevel, $level + 1, $type);
}
}
return $list;
}
}

View File

@ -0,0 +1,62 @@
<?php
/**
* @package Joomla.Libraries
* @subpackage HTML
*
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
defined('JPATH_PLATFORM') or die;
/**
* HTML helper class for rendering numbers.
*
* @package Joomla.Libraries
* @subpackage HTML
* @since 1.6
*/
abstract class JHtmlNumber
{
/**
* Converts bytes to more distinguishable formats such as:
* kilobytes, megabytes, etc.
*
* By default, the proper format will automatically be chosen.
* However, one of the allowed unit types may also be used instead.
*
* @param integer $bytes The number of bytes.
* @param string $unit The type of unit to return.
* @param integer $precision The number of digits to be used after the decimal place.
*
* @return string The number of bytes in the proper units.
*
* @since 1.6
*/
public static function bytes($bytes, $unit = 'auto', $precision = 2)
{
// No explicit casting $bytes to integer here, since it might overflow
// on 32-bit systems
$precision = (int) $precision;
if (empty($bytes))
{
return 0;
}
$unitTypes = array('b', 'kb', 'MB', 'GB', 'TB', 'PB');
// Default automatic method.
$i = floor(log($bytes, 1024));
// User supplied method:
if ($unit !== 'auto' && in_array($unit, $unitTypes))
{
$i = array_search($unit, $unitTypes, true);
}
// TODO Allow conversion of units where $bytes = '32M'.
return round($bytes / pow(1024, $i), $precision) . ' ' . $unitTypes[$i];
}
}

View File

@ -0,0 +1,225 @@
<?php
/**
* @package Joomla.Libraries
* @subpackage HTML
*
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
defined('JPATH_PLATFORM') or die;
/**
* Extended Utility class for all HTML drawing classes.
*
* @package Joomla.Libraries
* @subpackage HTML
* @since 1.6
*/
abstract class JHtmlRules
{
/**
* Creates the HTML for the permissions widget
*
* @param array $actions Array of action objects
* @param integer $assetId Id of a specific asset to create a widget for.
* @param integer $parent Id of the parent of the asset
* @param string $control The form control
* @param string $idPrefix Prefix for the ids assigned to specific action-group pairs
*
* @return string HTML for the permissions widget
*
* @see JAccess
* @see JFormFieldRules
* @since 1.6
*/
public static function assetFormWidget($actions, $assetId = null, $parent = null, $control = 'jform[rules]', $idPrefix = 'jform_rules')
{
$images = static::_getImagesArray();
// Get the user groups.
$groups = static::_getUserGroups();
// Get the incoming inherited rules as well as the asset specific rules.
$inheriting = JAccess::getAssetRules($parent ? $parent : static::_getParentAssetId($assetId), true);
$inherited = JAccess::getAssetRules($assetId, true);
$rules = JAccess::getAssetRules($assetId);
$html = array();
$html[] = '<div class="acl-options">';
$html[] = JHtml::_('tabs.start', 'acl-rules-' . $assetId, array('useCookie' => 1));
$html[] = JHtml::_('tabs.panel', JText::_('JLIB_HTML_ACCESS_SUMMARY'), 'summary');
$html[] = ' <p>' . JText::_('JLIB_HTML_ACCESS_SUMMARY_DESC') . '</p>';
$html[] = ' <table class="aclsummary-table" summary="' . JText::_('JLIB_HTML_ACCESS_SUMMARY_DESC') . '">';
$html[] = ' <caption>' . JText::_('JLIB_HTML_ACCESS_SUMMARY_DESC_CAPTION') . '</caption>';
$html[] = ' <tr>';
$html[] = ' <th class="col1 hidelabeltxt">' . JText::_('JLIB_RULES_GROUPS') . '</th>';
foreach ($actions as $i => $action)
{
$html[] = ' <th class="col' . ($i + 2) . '">' . JText::_($action->title) . '</th>';
}
$html[] = ' </tr>';
foreach ($groups as $i => $group)
{
$html[] = ' <tr class="row' . ($i % 2) . '">';
$html[] = ' <td class="col1">' . $group->text . '</td>';
foreach ($actions as $j => $action)
{
$html[] = ' <td class="col' . ($j + 2) . '">'
. ($assetId ? ($inherited->allow($action->name, $group->identities) ? $images['allow'] : $images['deny'])
: ($inheriting->allow($action->name, $group->identities) ? $images['allow'] : $images['deny'])) . '</td>';
}
$html[] = ' </tr>';
}
$html[] = ' </table>';
foreach ($actions as $action)
{
$actionTitle = JText::_($action->title);
$actionDesc = JText::_($action->description);
$html[] = JHtml::_('tabs.panel', $actionTitle, $action->name);
$html[] = ' <p>' . $actionDesc . '</p>';
$html[] = ' <table class="aclmodify-table" summary="' . strip_tags($actionDesc) . '">';
$html[] = ' <caption>' . JText::_('JLIB_HTML_ACCESS_MODIFY_DESC_CAPTION_ACL') . ' ' . $actionTitle . ' '
. JText::_('JLIB_HTML_ACCESS_MODIFY_DESC_CAPTION_TABLE') . '</caption>';
$html[] = ' <tr>';
$html[] = ' <th class="col1 hidelabeltxt">' . JText::_('JLIB_RULES_GROUP') . '</th>';
$html[] = ' <th class="col2">' . JText::_('JLIB_RULES_INHERIT') . '</th>';
$html[] = ' <th class="col3 hidelabeltxt">' . JText::_('JMODIFY') . '</th>';
$html[] = ' <th class="col4">' . JText::_('JCURRENT') . '</th>';
$html[] = ' </tr>';
foreach ($groups as $i => $group)
{
$selected = $rules->allow($action->name, $group->value);
$html[] = ' <tr class="row' . ($i % 2) . '">';
$html[] = ' <td class="col1">' . $group->text . '</td>';
$html[] = ' <td class="col2">'
. ($inheriting->allow($action->name, $group->identities) ? $images['allow-i'] : $images['deny-i']) . '</td>';
$html[] = ' <td class="col3">';
$html[] = ' <select id="' . $idPrefix . '_' . $action->name . '_' . $group->value
. '" class="inputbox" size="1" name="' . $control . '[' . $action->name . '][' . $group->value . ']" title="'
. JText::sprintf('JLIB_RULES_SELECT_ALLOW_DENY_GROUP', $actionTitle, $group->text) . '">';
$html[] = ' <option value=""' . ($selected === null ? ' selected="selected"' : '') . '>'
. JText::_('JLIB_RULES_INHERIT') . '</option>';
$html[] = ' <option value="1"' . ($selected === true ? ' selected="selected"' : '') . '>'
. JText::_('JLIB_RULES_ALLOWED') . '</option>';
$html[] = ' <option value="0"' . ($selected === false ? ' selected="selected"' : '') . '>'
. JText::_('JLIB_RULES_DENIED') . '</option>';
$html[] = ' </select>';
$html[] = ' </td>';
$html[] = ' <td class="col4">'
. ($assetId ? ($inherited->allow($action->name, $group->identities) ? $images['allow'] : $images['deny'])
: ($inheriting->allow($action->name, $group->identities) ? $images['allow'] : $images['deny'])) . '</td>';
$html[] = ' </tr>';
}
$html[] = ' </table>';
}
$html[] = JHtml::_('tabs.end');
// Build the footer with legend and special purpose buttons.
$html[] = ' <div class="clr"></div>';
$html[] = ' <ul class="acllegend fltlft">';
$html[] = ' <li class="acl-allowed">' . JText::_('JLIB_RULES_ALLOWED') . '</li>';
$html[] = ' <li class="acl-denied">' . JText::_('JLIB_RULES_DENIED') . '</li>';
$html[] = ' </ul>';
$html[] = '</div>';
return implode("\n", $html);
}
/**
* Get the id of the parent asset
*
* @param integer $assetId The asset for which the parentid will be returned
*
* @return integer The id of the parent asset
*
* @since 1.6
*/
protected static function _getParentAssetId($assetId)
{
// Get a database object.
$db = JFactory::getDbo();
$query = $db->getQuery(true);
// Get the user groups from the database.
$query->select($db->quoteName('parent_id'))
->from($db->quoteName('#__assets'))
->where($db->quoteName('id') . ' = ' . (int) $assetId);
$db->setQuery($query);
return (int) $db->loadResult();
}
/**
* Get the user groups
*
* @return array Array of user groups
*
* @since 1.6
*/
protected static function _getUserGroups()
{
// Get a database object.
$db = JFactory::getDbo();
// Get the user groups from the database.
$db->setQuery(
'SELECT a.id AS value, a.title AS text, b.id as parent'
. ' FROM #__usergroups AS a LEFT JOIN #__usergroups AS b ON a.lft >= b.lft AND a.rgt <= b.rgt'
. ' ORDER BY a.lft ASC, b.lft ASC'
);
$result = $db->loadObjectList();
$options = array();
// Pre-compute additional values.
foreach ($result as $option)
{
$end = end($options);
if ($end === false || $end->value != $option->value)
{
$end = $option;
$end->level = 0;
$options[] = $end;
}
else
{
$end->level++;
}
$end->identities[] = $option->parent;
}
return $options;
}
/**
* Get the array of images associate with specific permissions
*
* @return array An associative array of permissions and images
*
* @since 1.6
*/
protected static function _getImagesArray()
{
$images['allow-l'] = '<label class="icon-16-allow" title="' . JText::_('JLIB_RULES_ALLOWED') . '">' . JText::_('JLIB_RULES_ALLOWED')
. '</label>';
$images['deny-l'] = '<label class="icon-16-deny" title="' . JText::_('JLIB_RULES_DENIED') . '">' . JText::_('JLIB_RULES_DENIED') . '</label>';
$images['allow'] = '<a class="icon-16-allow" title="' . JText::_('JLIB_RULES_ALLOWED') . '"> </a>';
$images['deny'] = '<a class="icon-16-deny" title="' . JText::_('JLIB_RULES_DENIED') . '"> </a>';
$images['allow-i'] = '<a class="icon-16-allowinactive" title="' . JText::_('JRULE_ALLOWED_INHERITED') . '"> </a>';
$images['deny-i'] = '<a class="icon-16-denyinactive" title="' . JText::_('JRULE_DENIED_INHERITED') . '"> </a>';
return $images;
}
}

View File

@ -0,0 +1,736 @@
<?php
/**
* @package Joomla.Libraries
* @subpackage HTML
*
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
defined('JPATH_PLATFORM') or die;
/**
* Utility class for creating HTML select lists
*
* @package Joomla.Libraries
* @subpackage HTML
* @since 1.5
*/
abstract class JHtmlSelect
{
/**
* Default values for options. Organized by option group.
*
* @var array
* @since 1.5
*/
static protected $optionDefaults = array(
'option' => array('option.attr' => null, 'option.disable' => 'disable', 'option.id' => null, 'option.key' => 'value',
'option.key.toHtml' => true, 'option.label' => null, 'option.label.toHtml' => true, 'option.text' => 'text',
'option.text.toHtml' => true));
/**
* Generates a yes/no radio list.
*
* @param string $name The value of the HTML name attribute
* @param array $attribs Additional HTML attributes for the <select> tag
* @param string $selected The key that is selected
* @param string $yes Language key for Yes
* @param string $no Language key for no
* @param string $id The id for the field
*
* @return string HTML for the radio list
*
* @since 1.5
* @see JFormFieldRadio
*/
public static function booleanlist($name, $attribs = array(), $selected = null, $yes = 'JYES', $no = 'JNO', $id = false)
{
$arr = array(JHtml::_('select.option', '0', JText::_($no)), JHtml::_('select.option', '1', JText::_($yes)));
return JHtml::_('select.radiolist', $arr, $name, $attribs, 'value', 'text', (int) $selected, $id);
}
/**
* Generates an HTML selection list.
*
* @param array $data An array of objects, arrays, or scalars.
* @param string $name The value of the HTML name attribute.
* @param mixed $attribs Additional HTML attributes for the <select> tag. This
* can be an array of attributes, or an array of options. Treated as options
* if it is the last argument passed. Valid options are:
* Format options, see {@see JHtml::$formatOptions}.
* Selection options, see {@see JHtmlSelect::options()}.
* list.attr, string|array: Additional attributes for the select
* element.
* id, string: Value to use as the select element id attribute.
* Defaults to the same as the name.
* list.select, string|array: Identifies one or more option elements
* to be selected, based on the option key values.
* @param string $optKey The name of the object variable for the option value. If
* set to null, the index of the value array is used.
* @param string $optText The name of the object variable for the option text.
* @param mixed $selected The key that is selected (accepts an array or a string).
* @param mixed $idtag Value of the field id or null by default
* @param boolean $translate True to translate
*
* @return string HTML for the select list.
*
* @since 1.5
*/
public static function genericlist($data, $name, $attribs = null, $optKey = 'value', $optText = 'text', $selected = null, $idtag = false,
$translate = false)
{
// Set default options
$options = array_merge(JHtml::$formatOptions, array('format.depth' => 0, 'id' => false));
if (is_array($attribs) && func_num_args() == 3)
{
// Assume we have an options array
$options = array_merge($options, $attribs);
}
else
{
// Get options from the parameters
$options['id'] = $idtag;
$options['list.attr'] = $attribs;
$options['list.translate'] = $translate;
$options['option.key'] = $optKey;
$options['option.text'] = $optText;
$options['list.select'] = $selected;
}
$attribs = '';
if (isset($options['list.attr']))
{
if (is_array($options['list.attr']))
{
$attribs = JArrayHelper::toString($options['list.attr']);
}
else
{
$attribs = $options['list.attr'];
}
if ($attribs != '')
{
$attribs = ' ' . $attribs;
}
}
$id = $options['id'] !== false ? $options['id'] : $name;
$id = str_replace(array('[', ']'), '', $id);
$baseIndent = str_repeat($options['format.indent'], $options['format.depth']++);
$html = $baseIndent . '<select' . ($id !== '' ? ' id="' . $id . '"' : '') . ' name="' . $name . '"' . $attribs . '>' . $options['format.eol']
. static::options($data, $options) . $baseIndent . '</select>' . $options['format.eol'];
return $html;
}
/**
* Generates a grouped HTML selection list from nested arrays.
*
* @param array $data An array of groups, each of which is an array of options.
* @param string $name The value of the HTML name attribute
* @param array $options Options, an array of key/value pairs. Valid options are:
* Format options, {@see JHtml::$formatOptions}.
* Selection options. See {@see JHtmlSelect::options()}.
* group.id: The property in each group to use as the group id
* attribute. Defaults to none.
* group.label: The property in each group to use as the group
* label. Defaults to "text". If set to null, the data array index key is
* used.
* group.items: The property in each group to use as the array of
* items in the group. Defaults to "items". If set to null, group.id and
* group. label are forced to null and the data element is assumed to be a
* list of selections.
* id: Value to use as the select element id attribute. Defaults to
* the same as the name.
* list.attr: Attributes for the select element. Can be a string or
* an array of key/value pairs. Defaults to none.
* list.select: either the value of one selected option or an array
* of selected options. Default: none.
* list.translate: Boolean. If set, text and labels are translated via
* JText::_().
*
* @return string HTML for the select list
*
* @since 1.5
* @throws RuntimeException If a group has contents that cannot be processed.
*/
public static function groupedlist($data, $name, $options = array())
{
// Set default options and overwrite with anything passed in
$options = array_merge(
JHtml::$formatOptions,
array('format.depth' => 0, 'group.items' => 'items', 'group.label' => 'text', 'group.label.toHtml' => true, 'id' => false),
$options
);
// Apply option rules
if ($options['group.items'] === null)
{
$options['group.label'] = null;
}
$attribs = '';
if (isset($options['list.attr']))
{
if (is_array($options['list.attr']))
{
$attribs = JArrayHelper::toString($options['list.attr']);
}
else
{
$attribs = $options['list.attr'];
}
if ($attribs != '')
{
$attribs = ' ' . $attribs;
}
}
$id = $options['id'] !== false ? $options['id'] : $name;
$id = str_replace(array('[', ']'), '', $id);
// Disable groups in the options.
$options['groups'] = false;
$baseIndent = str_repeat($options['format.indent'], $options['format.depth']++);
$html = $baseIndent . '<select' . ($id !== '' ? ' id="' . $id . '"' : '') . ' name="' . $name . '"' . $attribs . '>' . $options['format.eol'];
$groupIndent = str_repeat($options['format.indent'], $options['format.depth']++);
foreach ($data as $dataKey => $group)
{
$label = $dataKey;
$id = '';
$noGroup = is_int($dataKey);
if ($options['group.items'] == null)
{
// Sub-list is an associative array
$subList = $group;
}
elseif (is_array($group))
{
// Sub-list is in an element of an array.
$subList = $group[$options['group.items']];
if (isset($group[$options['group.label']]))
{
$label = $group[$options['group.label']];
$noGroup = false;
}
if (isset($options['group.id']) && isset($group[$options['group.id']]))
{
$id = $group[$options['group.id']];
$noGroup = false;
}
}
elseif (is_object($group))
{
// Sub-list is in a property of an object
$subList = $group->$options['group.items'];
if (isset($group->$options['group.label']))
{
$label = $group->$options['group.label'];
$noGroup = false;
}
if (isset($options['group.id']) && isset($group->$options['group.id']))
{
$id = $group->$options['group.id'];
$noGroup = false;
}
}
else
{
throw new RuntimeException('Invalid group contents.', 1);
}
if ($noGroup)
{
$html .= static::options($subList, $options);
}
else
{
$html .= $groupIndent . '<optgroup' . (empty($id) ? '' : ' id="' . $id . '"') . ' label="'
. ($options['group.label.toHtml'] ? htmlspecialchars($label, ENT_COMPAT, 'UTF-8') : $label) . '">' . $options['format.eol']
. static::options($subList, $options) . $groupIndent . '</optgroup>' . $options['format.eol'];
}
}
$html .= $baseIndent . '</select>' . $options['format.eol'];
return $html;
}
/**
* Generates a selection list of integers.
*
* @param integer $start The start integer
* @param integer $end The end integer
* @param integer $inc The increment
* @param string $name The value of the HTML name attribute
* @param mixed $attribs Additional HTML attributes for the <select> tag, an array of
* attributes, or an array of options. Treated as options if it is the last
* argument passed.
* @param mixed $selected The key that is selected
* @param string $format The printf format to be applied to the number
*
* @return string HTML for the select list
*
* @since 1.5
*/
public static function integerlist($start, $end, $inc, $name, $attribs = null, $selected = null, $format = '')
{
// Set default options
$options = array_merge(JHtml::$formatOptions, array('format.depth' => 0, 'option.format' => '', 'id' => null));
if (is_array($attribs) && func_num_args() == 5)
{
// Assume we have an options array
$options = array_merge($options, $attribs);
// Extract the format and remove it from downstream options
$format = $options['option.format'];
unset($options['option.format']);
}
else
{
// Get options from the parameters
$options['list.attr'] = $attribs;
$options['list.select'] = $selected;
}
$start = (int) $start;
$end = (int) $end;
$inc = (int) $inc;
$data = array();
for ($i = $start; $i <= $end; $i += $inc)
{
$data[$i] = $format ? sprintf($format, $i) : $i;
}
// Tell genericlist() to use array keys
$options['option.key'] = null;
return JHtml::_('select.genericlist', $data, $name, $options);
}
/**
* Create a placeholder for an option group.
*
* @param string $text The text for the option
* @param string $optKey The returned object property name for the value
* @param string $optText The returned object property name for the text
*
* @return object
*
* @deprecated 4.0 Use JHtmlSelect::groupedList()
* @see JHtmlSelect::groupedList()
* @since 1.5
*/
public static function optgroup($text, $optKey = 'value', $optText = 'text')
{
JLog::add('JHtmlSelect::optgroup() is deprecated, use JHtmlSelect::groupedList() instead.', JLog::WARNING, 'deprecated');
// Set initial state
static $state = 'open';
// Toggle between open and close states:
switch ($state)
{
case 'open':
$obj = new stdClass;
$obj->$optKey = '<OPTGROUP>';
$obj->$optText = $text;
$state = 'close';
break;
case 'close':
$obj = new stdClass;
$obj->$optKey = '</OPTGROUP>';
$obj->$optText = $text;
$state = 'open';
break;
}
return $obj;
}
/**
* Create an object that represents an option in an option list.
*
* @param string $value The value of the option
* @param string $text The text for the option
* @param mixed $optKey If a string, the returned object property name for
* the value. If an array, options. Valid options are:
* attr: String|array. Additional attributes for this option.
* Defaults to none.
* disable: Boolean. If set, this option is disabled.
* label: String. The value for the option label.
* option.attr: The property in each option array to use for
* additional selection attributes. Defaults to none.
* option.disable: The property that will hold the disabled state.
* Defaults to "disable".
* option.key: The property that will hold the selection value.
* Defaults to "value".
* option.label: The property in each option array to use as the
* selection label attribute. If a "label" option is provided, defaults to
* "label", if no label is given, defaults to null (none).
* option.text: The property that will hold the the displayed text.
* Defaults to "text". If set to null, the option array is assumed to be a
* list of displayable scalars.
* @param string $optText The property that will hold the the displayed text. This
* parameter is ignored if an options array is passed.
* @param boolean $disable Not used.
*
* @return object
*
* @since 1.5
*/
public static function option($value, $text = '', $optKey = 'value', $optText = 'text', $disable = false)
{
$options = array('attr' => null, 'disable' => false, 'option.attr' => null, 'option.disable' => 'disable', 'option.key' => 'value',
'option.label' => null, 'option.text' => 'text');
if (is_array($optKey))
{
// Merge in caller's options
$options = array_merge($options, $optKey);
}
else
{
// Get options from the parameters
$options['option.key'] = $optKey;
$options['option.text'] = $optText;
$options['disable'] = $disable;
}
$obj = new stdClass;
$obj->$options['option.key'] = $value;
$obj->$options['option.text'] = trim($text) ? $text : $value;
/*
* If a label is provided, save it. If no label is provided and there is
* a label name, initialise to an empty string.
*/
$hasProperty = $options['option.label'] !== null;
if (isset($options['label']))
{
$labelProperty = $hasProperty ? $options['option.label'] : 'label';
$obj->$labelProperty = $options['label'];
}
elseif ($hasProperty)
{
$obj->$options['option.label'] = '';
}
// Set attributes only if there is a property and a value
if ($options['attr'] !== null)
{
$obj->$options['option.attr'] = $options['attr'];
}
// Set disable only if it has a property and a value
if ($options['disable'] !== null)
{
$obj->$options['option.disable'] = $options['disable'];
}
return $obj;
}
/**
* Generates the option tags for an HTML select list (with no select tag
* surrounding the options).
*
* @param array $arr An array of objects, arrays, or values.
* @param mixed $optKey If a string, this is the name of the object variable for
* the option value. If null, the index of the array of objects is used. If
* an array, this is a set of options, as key/value pairs. Valid options are:
* -Format options, {@see JHtml::$formatOptions}.
* -groups: Boolean. If set, looks for keys with the value
* "&lt;optgroup>" and synthesizes groups from them. Deprecated. Defaults
* true for backwards compatibility.
* -list.select: either the value of one selected option or an array
* of selected options. Default: none.
* -list.translate: Boolean. If set, text and labels are translated via
* JText::_(). Default is false.
* -option.id: The property in each option array to use as the
* selection id attribute. Defaults to none.
* -option.key: The property in each option array to use as the
* selection value. Defaults to "value". If set to null, the index of the
* option array is used.
* -option.label: The property in each option array to use as the
* selection label attribute. Defaults to null (none).
* -option.text: The property in each option array to use as the
* displayed text. Defaults to "text". If set to null, the option array is
* assumed to be a list of displayable scalars.
* -option.attr: The property in each option array to use for
* additional selection attributes. Defaults to none.
* -option.disable: The property that will hold the disabled state.
* Defaults to "disable".
* -option.key: The property that will hold the selection value.
* Defaults to "value".
* -option.text: The property that will hold the the displayed text.
* Defaults to "text". If set to null, the option array is assumed to be a
* list of displayable scalars.
* @param string $optText The name of the object variable for the option text.
* @param mixed $selected The key that is selected (accepts an array or a string)
* @param boolean $translate Translate the option values.
*
* @return string HTML for the select list
*
* @since 1.5
*/
public static function options($arr, $optKey = 'value', $optText = 'text', $selected = null, $translate = false)
{
$options = array_merge(
JHtml::$formatOptions,
static::$optionDefaults['option'],
array('format.depth' => 0, 'groups' => true, 'list.select' => null, 'list.translate' => false)
);
if (is_array($optKey))
{
// Set default options and overwrite with anything passed in
$options = array_merge($options, $optKey);
}
else
{
// Get options from the parameters
$options['option.key'] = $optKey;
$options['option.text'] = $optText;
$options['list.select'] = $selected;
$options['list.translate'] = $translate;
}
$html = '';
$baseIndent = str_repeat($options['format.indent'], $options['format.depth']);
foreach ($arr as $elementKey => &$element)
{
$attr = '';
$extra = '';
$label = '';
$id = '';
if (is_array($element))
{
$key = $options['option.key'] === null ? $elementKey : $element[$options['option.key']];
$text = $element[$options['option.text']];
if (isset($element[$options['option.attr']]))
{
$attr = $element[$options['option.attr']];
}
if (isset($element[$options['option.id']]))
{
$id = $element[$options['option.id']];
}
if (isset($element[$options['option.label']]))
{
$label = $element[$options['option.label']];
}
if (isset($element[$options['option.disable']]) && $element[$options['option.disable']])
{
$extra .= ' disabled="disabled"';
}
}
elseif (is_object($element))
{
$key = $options['option.key'] === null ? $elementKey : $element->$options['option.key'];
$text = $element->$options['option.text'];
if (isset($element->$options['option.attr']))
{
$attr = $element->$options['option.attr'];
}
if (isset($element->$options['option.id']))
{
$id = $element->$options['option.id'];
}
if (isset($element->$options['option.label']))
{
$label = $element->$options['option.label'];
}
if (isset($element->$options['option.disable']) && $element->$options['option.disable'])
{
$extra .= ' disabled="disabled"';
}
}
else
{
// This is a simple associative array
$key = $elementKey;
$text = $element;
}
/*
* The use of options that contain optgroup HTML elements was
* somewhat hacked for J1.5. J1.6 introduces the grouplist() method
* to handle this better. The old solution is retained through the
* "groups" option, which defaults true in J1.6, but should be
* deprecated at some point in the future.
*/
$key = (string) $key;
if ($options['groups'] && $key == '<OPTGROUP>')
{
$html .= $baseIndent . '<optgroup label="' . ($options['list.translate'] ? JText::_($text) : $text) . '">' . $options['format.eol'];
$baseIndent = str_repeat($options['format.indent'], ++$options['format.depth']);
}
elseif ($options['groups'] && $key == '</OPTGROUP>')
{
$baseIndent = str_repeat($options['format.indent'], --$options['format.depth']);
$html .= $baseIndent . '</optgroup>' . $options['format.eol'];
}
else
{
// If no string after hyphen - take hyphen out
$splitText = explode(' - ', $text, 2);
$text = $splitText[0];
if (isset($splitText[1]))
{
$text .= ' - ' . $splitText[1];
}
if ($options['list.translate'] && !empty($label))
{
$label = JText::_($label);
}
if ($options['option.label.toHtml'])
{
$label = htmlentities($label);
}
if (is_array($attr))
{
$attr = JArrayHelper::toString($attr);
}
else
{
$attr = trim($attr);
}
$extra = ($id ? ' id="' . $id . '"' : '') . ($label ? ' label="' . $label . '"' : '') . ($attr ? ' ' . $attr : '') . $extra;
if (is_array($options['list.select']))
{
foreach ($options['list.select'] as $val)
{
$key2 = is_object($val) ? $val->$options['option.key'] : $val;
if ($key == $key2)
{
$extra .= ' selected="selected"';
break;
}
}
}
elseif ((string) $key == (string) $options['list.select'])
{
$extra .= ' selected="selected"';
}
if ($options['list.translate'])
{
$text = JText::_($text);
}
// Generate the option, encoding as required
$html .= $baseIndent . '<option value="' . ($options['option.key.toHtml'] ? htmlspecialchars($key, ENT_COMPAT, 'UTF-8') : $key) . '"'
. $extra . '>';
$html .= $options['option.text.toHtml'] ? htmlentities(html_entity_decode($text, ENT_COMPAT, 'UTF-8'), ENT_COMPAT, 'UTF-8') : $text;
$html .= '</option>' . $options['format.eol'];
}
}
return $html;
}
/**
* Generates an HTML radio list.
*
* @param array $data An array of objects
* @param string $name The value of the HTML name attribute
* @param string $attribs Additional HTML attributes for the <select> tag
* @param mixed $optKey The key that is selected
* @param string $optText The name of the object variable for the option value
* @param string $selected The name of the object variable for the option text
* @param boolean $idtag Value of the field id or null by default
* @param boolean $translate True if options will be translated
*
* @return string HTML for the select list
*
* @since 1.5
*/
public static function radiolist($data, $name, $attribs = null, $optKey = 'value', $optText = 'text', $selected = null, $idtag = false,
$translate = false)
{
reset($data);
if (is_array($attribs))
{
$attribs = JArrayHelper::toString($attribs);
}
$id_text = $idtag ? $idtag : $name;
$html = '<div class="controls">';
foreach ($data as $obj)
{
$k = $obj->$optKey;
$t = $translate ? JText::_($obj->$optText) : $obj->$optText;
$id = (isset($obj->id) ? $obj->id : null);
$extra = '';
$extra .= $id ? ' id="' . $obj->id . '"' : '';
if (is_array($selected))
{
foreach ($selected as $val)
{
$k2 = is_object($val) ? $val->$optKey : $val;
if ($k == $k2)
{
$extra .= ' selected="selected"';
break;
}
}
}
else
{
$extra .= ((string) $k == (string) $selected ? ' checked="checked"' : '');
}
$html .= "\n\t" . '<label for="' . $id_text . $k . '" id="' . $id_text . $k . '-lbl" class="radio">';
$html .= "\n\t\n\t" . '<input type="radio" name="' . $name . '" id="' . $id_text . $k . '" value="' . $k . '" ' . $extra . ' '
. $attribs . '>' . $t;
$html .= "\n\t" . '</label>';
}
$html .= '</div>';
$html .= "\n";
return $html;
}
}

View File

@ -0,0 +1,152 @@
<?php
/**
* @package Joomla.Libraries
* @subpackage HTML
*
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
defined('JPATH_BASE') or die;
/**
* Utility class to render a list view sidebar
*
* @package Joomla.Libraries
* @subpackage HTML
* @since 3.0
*/
abstract class JHtmlSidebar
{
/**
* Menu entries
*
* @var array
* @since 3.0
*/
protected static $entries = array();
/**
* Filters
*
* @var array
* @since 3.0
*/
protected static $filters = array();
/**
* Value for the action attribute of the form.
*
* @var string
* @since 3.0
*/
protected static $action = '';
/**
* Render the sidebar.
*
* @return string The necessary HTML to display the sidebar
*
* @since 3.0
*/
public static function render()
{
// Collect display data
$data = new stdClass;
$data->list = static::getEntries();
$data->filters = static::getFilters();
$data->action = static::getAction();
$data->displayMenu = count($data->list);
$data->displayFilters = count($data->filters);
$data->hide = JFactory::getApplication()->input->getBool('hidemainmenu');
// Create a layout object and ask it to render the sidebar
$layout = new JLayoutFile('joomla.sidebars.submenu');
$sidebarHtml = $layout->render($data);
return $sidebarHtml;
}
/**
* Method to add a menu item to submenu.
*
* @param string $name Name of the menu item.
* @param string $link URL of the menu item.
* @param bool $active True if the item is active, false otherwise.
*
* @return void
*
* @since 3.0
*/
public static function addEntry($name, $link = '', $active = false)
{
array_push(static::$entries, array($name, $link, $active));
}
/**
* Returns an array of all submenu entries
*
* @return array
*
* @since 3.0
*/
public static function getEntries()
{
return static::$entries;
}
/**
* Method to add a filter to the submenu
*
* @param string $label Label for the menu item.
* @param string $name Name for the filter. Also used as id.
* @param string $options Options for the select field.
* @param bool $noDefault Don't the label as the empty option
*
* @return void
*
* @since 3.0
*/
public static function addFilter($label, $name, $options, $noDefault = false)
{
array_push(static::$filters, array('label' => $label, 'name' => $name, 'options' => $options, 'noDefault' => $noDefault));
}
/**
* Returns an array of all filters
*
* @return array
*
* @since 3.0
*/
public static function getFilters()
{
return static::$filters;
}
/**
* Set value for the action attribute of the filter form
*
* @param string $action Value for the action attribute of the form
*
* @return void
*
* @since 3.0
*/
public static function setAction($action)
{
static::$action = $action;
}
/**
* Get value for the action attribute of the filter form
*
* @return string
*
* @since 3.0
*/
public static function getAction()
{
return static::$action;
}
}

View File

@ -0,0 +1,120 @@
<?php
/**
* @package Joomla.Libraries
* @subpackage HTML
*
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
defined('JPATH_PLATFORM') or die;
/**
* Utility class for Sliders elements
*
* @package Joomla.Libraries
* @subpackage HTML
* @since 1.6
*/
abstract class JHtmlSliders
{
/**
* Creates a panes and loads the javascript behavior for it.
*
* @param string $group The pane identifier.
* @param array $params An array of options.
*
* @return string
*
* @since 1.6
*/
public static function start($group = 'sliders', $params = array())
{
static::loadBehavior($group, $params);
return '<div id="' . $group . '" class="pane-sliders"><div style="display:none;"><div>';
}
/**
* Close the current pane.
*
* @return string hTML to close the pane
*
* @since 1.6
*/
public static function end()
{
return '</div></div></div>';
}
/**
* Begins the display of a new panel.
*
* @param string $text Text to display.
* @param string $id Identifier of the panel.
*
* @return string HTML to start a panel
*
* @since 1.6
*/
public static function panel($text, $id)
{
return '</div></div><div class="panel"><h3 class="pane-toggler title" id="' . $id . '"><a href="javascript:void(0);"><span>' . $text
. '</span></a></h3><div class="pane-slider content">';
}
/**
* Load the JavaScript behavior.
*
* @param string $group The pane identifier.
* @param array $params Array of options.
*
* @return void
*
* @since 1.6
*/
protected static function loadBehavior($group, $params = array())
{
static $loaded = array();
if (!array_key_exists($group, $loaded))
{
// Get the JInput object
$input = JFactory::getApplication()->input;
$loaded[$group] = true;
// Include mootools framework.
JHtml::_('behavior.framework', true);
$document = JFactory::getDocument();
$display = (isset($params['startOffset']) && isset($params['startTransition']) && $params['startTransition'])
? (int) $params['startOffset'] : null;
$show = (isset($params['startOffset']) && !(isset($params['startTransition']) && $params['startTransition']))
? (int) $params['startOffset'] : null;
$opt['onActive'] = "\\function(toggler, i) {toggler.addClass('pane-toggler-down');" .
"toggler.removeClass('pane-toggler');i.addClass('pane-down');i.removeClass('pane-hide');Cookie.write('jpanesliders_"
. $group . "',$$('div#" . $group . ".pane-sliders > .panel > h3').indexOf(toggler));}";
$opt['onBackground'] = "\\function(toggler, i) {toggler.addClass('pane-toggler');" .
"toggler.removeClass('pane-toggler-down');i.addClass('pane-hide');i.removeClass('pane-down');if($$('div#"
. $group . ".pane-sliders > .panel > h3').length==$$('div#" . $group
. ".pane-sliders > .panel > h3.pane-toggler').length) Cookie.write('jpanesliders_" . $group . "',-1);}";
$opt['duration'] = (isset($params['duration'])) ? (int) $params['duration'] : 300;
$opt['display'] = (isset($params['useCookie']) && $params['useCookie']) ? $input->cookie->get('jpanesliders_' . $group, $display, 'integer')
: $display;
$opt['show'] = (isset($params['useCookie']) && $params['useCookie']) ? $input->cookie->get('jpanesliders_' . $group, $show, 'integer') : $show;
$opt['opacity'] = (isset($params['opacityTransition']) && ($params['opacityTransition'])) ? 'true' : 'false';
$opt['alwaysHide'] = (isset($params['allowAllClose']) && (!$params['allowAllClose'])) ? 'false' : 'true';
$options = JHtml::getJSObject($opt);
$js = "window.addEvent('domready', function(){ new Fx.Accordion($$('div#" . $group
. ".pane-sliders > .panel > h3.pane-toggler'), $$('div#" . $group . ".pane-sliders > .panel > div.pane-slider'), " . $options
. "); });";
$document->addScriptDeclaration($js);
}
}
}

View File

@ -0,0 +1,107 @@
<?php
/**
* @package Joomla.Libraries
* @subpackage HTML
*
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
defined('JPATH_PLATFORM') or die;
/**
* HTML utility class for creating a sortable table list
*
* @package Joomla.Libraries
* @subpackage HTML
* @since 3.0
*/
abstract class JHtmlSortablelist
{
/**
* @var array Array containing information for loaded files
* @since 3.0
*/
protected static $loaded = array();
/**
* Method to load the Sortable script and make table sortable
*
* @param string $tableId DOM id of the table
* @param string $formId DOM id of the form
* @param string $sortDir Sort direction
* @param string $saveOrderingUrl Save ordering url, ajax-load after an item dropped
* @param boolean $proceedSaveOrderButton Set whether a save order button is displayed
* @param boolean $nestedList Set whether the list is a nested list
*
* @return void
*
* @since 3.0
*/
public static function sortable($tableId, $formId, $sortDir = 'asc', $saveOrderingUrl, $proceedSaveOrderButton = true, $nestedList = false)
{
// Only load once
if (isset(static::$loaded[__METHOD__]))
{
return;
}
// Depends on jQuery UI
JHtml::_('jquery.ui', array('core', 'sortable'));
JHtml::_('script', 'jui/sortablelist.js', false, true);
JHtml::_('stylesheet', 'jui/sortablelist.css', false, true, false);
// Attach sortable to document
JFactory::getDocument()->addScriptDeclaration("
(function ($){
$(document).ready(function (){
var sortableList = new $.JSortableList('#" . $tableId . " tbody','" . $formId . "','" . $sortDir . "' , '" . $saveOrderingUrl . "','','" . $nestedList . "');
});
})(jQuery);
"
);
if ($proceedSaveOrderButton)
{
static::_proceedSaveOrderButton();
}
// Set static array
static::$loaded[__METHOD__] = true;
return;
}
/**
* Method to inject script for enabled and disable Save order button
* when changing value of ordering input boxes
*
* @return void
*
* @since 3.0
*/
public static function _proceedSaveOrderButton()
{
JFactory::getDocument()->addScriptDeclaration(
"(function ($){
$(document).ready(function (){
var saveOrderButton = $('.saveorder');
saveOrderButton.css({'opacity':'0.2', 'cursor':'default'}).attr('onclick','return false;');
var oldOrderingValue = '';
$('.text-area-order').focus(function ()
{
oldOrderingValue = $(this).attr('value');
})
.keyup(function (){
var newOrderingValue = $(this).attr('value');
if (oldOrderingValue != newOrderingValue)
{
saveOrderButton.css({'opacity':'1', 'cursor':'pointer'}).removeAttr('onclick')
}
});
});
})(jQuery);"
);
return;
}
}

View File

@ -0,0 +1,296 @@
<?php
/**
* @package Joomla.Platform
* @subpackage HTML
*
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
defined('JPATH_PLATFORM') or die;
/**
* HTML helper class for rendering manipulated strings.
*
* @package Joomla.Platform
* @subpackage HTML
* @since 1.6
*/
abstract class JHtmlString
{
/**
* Truncates text blocks over the specified character limit and closes
* all open HTML tags. The method will optionally not truncate an individual
* word, it will find the first space that is within the limit and
* truncate at that point. This method is UTF-8 safe.
*
* @param string $text The text to truncate.
* @param integer $length The maximum length of the text.
* @param boolean $noSplit Don't split a word if that is where the cutoff occurs (default: true).
* @param boolean $allowHtml Allow HTML tags in the output, and close any open tags (default: true).
*
* @return string The truncated text.
*
* @since 1.6
*/
public static function truncate($text, $length = 0, $noSplit = true, $allowHtml = true)
{
// Assume a lone open tag is invalid HTML.
if ($length == 1 && substr($text, 0, 1) == '<')
{
return '...';
}
// Check if HTML tags are allowed.
if (!$allowHtml)
{
// Deal with spacing issues in the input.
$text = str_replace('>', '> ', $text);
$text = str_replace(array('&nbsp;', '&#160;'), ' ', $text);
$text = JString::trim(preg_replace('#\s+#mui', ' ', $text));
// Strip the tags from the input and decode entities.
$text = strip_tags($text);
$text = html_entity_decode($text, ENT_QUOTES, 'UTF-8');
// Remove remaining extra spaces.
$text = str_replace('&nbsp;', ' ', $text);
$text = JString::trim(preg_replace('#\s+#mui', ' ', $text));
}
// Whether or not allowing HTML, truncate the item text if it is too long.
if ($length > 0 && JString::strlen($text) > $length)
{
$tmp = trim(JString::substr($text, 0, $length));
if (substr($tmp, 0, 1) == '<' && strpos($tmp, '>') === false)
{
return '...';
}
// $noSplit true means that we do not allow splitting of words.
if ($noSplit)
{
// Find the position of the last space within the allowed length.
$offset = JString::strrpos($tmp, ' ');
$tmp = JString::substr($tmp, 0, $offset + 1);
// If there are no spaces and the string is longer than the maximum
// we need to just use the ellipsis. In that case we are done.
if ($offset === false && strlen($text) > $length)
{
return '...';
}
if (JString::strlen($tmp) > $length - 3)
{
$tmp = trim(JString::substr($tmp, 0, JString::strrpos($tmp, ' ')));
}
}
if ($allowHtml)
{
// Put all opened tags into an array
preg_match_all("#<([a-z][a-z0-9]*)\b.*?(?!/)>#i", $tmp, $result);
$openedTags = $result[1];
// Some tags self close so they do not need a separate close tag.
$openedTags = array_diff($openedTags, array("img", "hr", "br"));
$openedTags = array_values($openedTags);
// Put all closed tags into an array
preg_match_all("#</([a-z]+)>#iU", $tmp, $result);
$closedTags = $result[1];
$numOpened = count($openedTags);
// All tags are closed so trim the text and finish.
if (count($closedTags) == $numOpened)
{
return trim($tmp) . '...';
}
// Closing tags need to be in the reverse order of opening tags.
$openedTags = array_reverse($openedTags);
// Close tags
for ($i = 0; $i < $numOpened; $i++)
{
if (!in_array($openedTags[$i], $closedTags))
{
$tmp .= "</" . $openedTags[$i] . ">";
}
else
{
unset($closedTags[array_search($openedTags[$i], $closedTags)]);
}
}
}
if ($tmp === false || strlen($text) > strlen($tmp))
{
$text = trim($tmp) . '...';
}
}
// Clean up any internal spaces created by the processing.
$text = str_replace(' </', '</', $text);
$text = str_replace(' ...', '...', $text);
return $text;
}
/**
* Method to extend the truncate method to more complex situations
*
* The goal is to get the proper length plain text string with as much of
* the html intact as possible with all tags properly closed.
*
* @param string $html The content of the introtext to be truncated
* @param integer $maxLength The maximum number of characters to render
* @param boolean $noSplit Don't split a word if that is where the cutoff occurs (default: true).
*
* @return string The truncated string. If the string is truncated an ellipsis
* (...) will be appended.
*
* @note If a maximum length of 3 or less is selected and the text has more than
* that number of characters an ellipsis will be displayed.
* This method will not create valid HTML from malformed HTML.
*
* @since 3.1
*/
public static function truncateComplex($html, $maxLength = 0, $noSplit = true)
{
// Start with some basic rules.
$baseLength = strlen($html);
// If the original HTML string is shorter than the $maxLength do nothing and return that.
if ($baseLength <= $maxLength || $maxLength == 0)
{
return $html;
}
// Take care of short simple cases.
if ($maxLength <= 3 && substr($html, 0, 1) != '<' && strpos(substr($html, 0, $maxLength - 1), '<') === false && $baseLength > $maxLength)
{
return '...';
}
// Deal with maximum length of 1 where the string starts with a tag.
if ($maxLength == 1 && substr($html, 0, 1) == '<')
{
$endTagPos = strlen(strstr($html, '>', true));
$tag = substr($html, 1, $endTagPos);
$l = $endTagPos + 1;
if ($noSplit)
{
return substr($html, 0, $l) . '</' . $tag . '...';
}
// TODO: $character doesn't seem to be used...
$character = substr(strip_tags($html), 0, 1);
return substr($html, 0, $l) . '</' . $tag . '...';
}
// First get the truncated plain text string. This is the rendered text we want to end up with.
$ptString = JHtml::_('string.truncate', $html, $maxLength, $noSplit, $allowHtml = false);
// It's all HTML, just return it.
if (strlen($ptString) == 0)
{
return $html;
}
// If the plain text is shorter than the max length the variable will not end in ...
// In that case we use the whole string.
if (substr($ptString, -3) != '...')
{
return $html;
}
// Regular truncate gives us the ellipsis but we want to go back for text and tags.
if ($ptString == '...')
{
$stripped = substr(strip_tags($html), 0, $maxLength);
$ptString = JHtml::_('string.truncate', $stripped, $maxLength, $noSplit, $allowHtml = false);
}
// We need to trim the ellipsis that truncate adds.
$ptString = rtrim($ptString, '.');
// Now deal with more complex truncation.
while ($maxLength <= $baseLength)
{
// Get the truncated string assuming HTML is allowed.
$htmlString = JHtml::_('string.truncate', $html, $maxLength, $noSplit, $allowHtml = true);
if ($htmlString == '...' && strlen($ptString) + 3 > $maxLength)
{
return $htmlString;
}
$htmlString = rtrim($htmlString, '.');
// Now get the plain text from the HTML string and trim it.
$htmlStringToPtString = JHtml::_('string.truncate', $htmlString, $maxLength, $noSplit, $allowHtml = false);
$htmlStringToPtString = rtrim($htmlStringToPtString, '.');
// If the new plain text string matches the original plain text string we are done.
if ($ptString == $htmlStringToPtString)
{
return $htmlString . '...';
}
// Get the number of HTML tag characters in the first $maxLength characters
$diffLength = strlen($ptString) - strlen($htmlStringToPtString);
if ($diffLength <= 0)
{
return $htmlString . '...';
}
// Set new $maxlength that adjusts for the HTML tags
$maxLength += $diffLength;
}
}
/**
* Abridges text strings over the specified character limit. The
* behavior will insert an ellipsis into the text replacing a section
* of variable size to ensure the string does not exceed the defined
* maximum length. This method is UTF-8 safe.
*
* For example, it transforms "Really long title" to "Really...title".
*
* Note that this method does not scan for HTML tags so will potentially break them.
*
* @param string $text The text to abridge.
* @param integer $length The maximum length of the text (default is 50).
* @param integer $intro The maximum length of the intro text (default is 30).
*
* @return string The abridged text.
*
* @since 1.6
*/
public static function abridge($text, $length = 50, $intro = 30)
{
// Abridge the item text if it is too long.
if (JString::strlen($text) > $length)
{
// Determine the remaining text length.
$remainder = $length - ($intro + 3);
// Extract the beginning and ending text sections.
$beg = JString::substr($text, 0, $intro);
$end = JString::substr($text, JString::strlen($text) - $remainder);
// Build the resulting string.
$text = $beg . '...' . $end;
}
return $text;
}
}

106
libraries/cms/html/tabs.php Normal file
View File

@ -0,0 +1,106 @@
<?php
/**
* @package Joomla.Libraries
* @subpackage HTML
*
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
defined('JPATH_PLATFORM') or die;
/**
* Utility class for Tabs elements.
*
* @package Joomla.Libraries
* @subpackage HTML
* @since 1.6
*/
abstract class JHtmlTabs
{
/**
* Creates a panes and creates the JavaScript object for it.
*
* @param string $group The pane identifier.
* @param array $params An array of option.
*
* @return string
*
* @since 1.6
*/
public static function start($group = 'tabs', $params = array())
{
static::loadBehavior($group, $params);
return '<dl class="tabs" id="' . $group . '"><dt style="display:none;"></dt><dd style="display:none;">';
}
/**
* Close the current pane
*
* @return string HTML to close the pane
*
* @since 1.6
*/
public static function end()
{
return '</dd></dl>';
}
/**
* Begins the display of a new panel.
*
* @param string $text Text to display.
* @param string $id Identifier of the panel.
*
* @return string HTML to start a new panel
*
* @since 1.6
*/
public static function panel($text, $id)
{
return '</dd><dt class="tabs ' . $id . '"><span><h3><a href="javascript:void(0);">' . $text . '</a></h3></span></dt><dd class="tabs">';
}
/**
* Load the JavaScript behavior.
*
* @param string $group The pane identifier.
* @param array $params Array of options.
*
* @return void
*
* @since 1.6
*/
protected static function loadBehavior($group, $params = array())
{
static $loaded = array();
if (!array_key_exists((string) $group, $loaded))
{
// Include MooTools framework
JHtml::_('behavior.framework', true);
$opt['onActive'] = (isset($params['onActive'])) ? '\\' . $params['onActive'] : null;
$opt['onBackground'] = (isset($params['onBackground'])) ? '\\' . $params['onBackground'] : null;
$opt['display'] = (isset($params['startOffset'])) ? (int) $params['startOffset'] : null;
$opt['useStorage'] = (isset($params['useCookie']) && $params['useCookie']) ? 'true' : 'false';
$opt['titleSelector'] = "dt.tabs";
$opt['descriptionSelector'] = "dd.tabs";
$options = JHtml::getJSObject($opt);
$js = ' window.addEvent(\'domready\', function(){
$$(\'dl#' . $group . '.tabs\').each(function(tabs){
new JTabs(tabs, ' . $options . ');
});
});';
$document = JFactory::getDocument();
$document->addScriptDeclaration($js);
JHtml::_('script', 'system/tabs.js', false, true);
$loaded[(string) $group] = true;
}
}
}

239
libraries/cms/html/tag.php Normal file
View File

@ -0,0 +1,239 @@
<?php
/**
* @package Joomla.Libraries
* @subpackage HTML
*
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
defined('JPATH_BASE') or die;
/**
* Utility class for tags
*
* @package Joomla.Libraries
* @subpackage HTML
* @since 3.1
*/
abstract class JHtmlTag
{
/**
* Cached array of the tag items.
*
* @var array
* @since 3.1
*/
protected static $items = array();
/**
* Returns an array of tags.
*
* @param array $config An array of configuration options. By default, only
* published and unpublished categories are returned.
*
* @return array
*
* @since 3.1
*/
public static function options($config = array('filter.published' => array(0, 1)))
{
$hash = md5(serialize($config));
if (!isset(static::$items[$hash]))
{
$config = (array) $config;
$db = JFactory::getDbo();
$query = $db->getQuery(true)
->select('a.id, a.title, a.level')
->from('#__tags AS a')
->where('a.parent_id > 0');
// Filter on the published state
if (isset($config['filter.published']))
{
if (is_numeric($config['filter.published']))
{
$query->where('a.published = ' . (int) $config['filter.published']);
}
elseif (is_array($config['filter.published']))
{
JArrayHelper::toInteger($config['filter.published']);
$query->where('a.published IN (' . implode(',', $config['filter.published']) . ')');
}
}
// Filter on the language
if (isset($config['filter.language']))
{
if (is_string($config['filter.language']))
{
$query->where('a.language = ' . $db->quote($config['filter.language']));
}
elseif (is_array($config['filter.language']))
{
foreach ($config['filter.language'] as &$language)
{
$language = $db->quote($language);
}
$query->where('a.language IN (' . implode(',', $config['filter.language']) . ')');
}
}
$query->order('a.lft');
$db->setQuery($query);
$items = $db->loadObjectList();
// Assemble the list options.
static::$items[$hash] = array();
foreach ($items as &$item)
{
$repeat = ($item->level - 1 >= 0) ? $item->level - 1 : 0;
$item->title = str_repeat('- ', $repeat) . $item->title;
static::$items[$hash][] = JHtml::_('select.option', $item->id, $item->title);
}
}
return static::$items[$hash];
}
/**
* Returns an array of tags.
*
* @param array $config An array of configuration options. By default, only published and unpublished tags are returned.
*
* @return array Tag data
*
* @since 3.1
*/
public static function tags($config = array('filter.published' => array(0, 1)))
{
$hash = md5(serialize($config));
$config = (array) $config;
$db = JFactory::getDbo();
$query = $db->getQuery(true)
->select('a.id, a.title, a.level, a.parent_id')
->from('#__tags AS a')
->where('a.parent_id > 0');
// Filter on the published state
if (isset($config['filter.published']))
{
if (is_numeric($config['filter.published']))
{
$query->where('a.published = ' . (int) $config['filter.published']);
}
elseif (is_array($config['filter.published']))
{
JArrayHelper::toInteger($config['filter.published']);
$query->where('a.published IN (' . implode(',', $config['filter.published']) . ')');
}
}
$query->order('a.lft');
$db->setQuery($query);
$items = $db->loadObjectList();
// Assemble the list options.
static::$items[$hash] = array();
foreach ($items as &$item)
{
$repeat = ($item->level - 1 >= 0) ? $item->level - 1 : 0;
$item->title = str_repeat('- ', $repeat) . $item->title;
static::$items[$hash][] = JHtml::_('select.option', $item->id, $item->title);
}
return static::$items[$hash];
}
/**
* This is just a proxy for the formbehavior.ajaxchosen method
*
* @param string $selector DOM id of the tag field
* @param boolean $allowCustom Flag to allow custom values
*
* @return void
*
* @since 3.1
*/
public static function ajaxfield($selector='#jform_tags', $allowCustom = true)
{
// Tags field ajax
$chosenAjaxSettings = new JRegistry(
array(
'selector' => $selector,
'type' => 'GET',
'url' => JUri::root() . 'index.php?option=com_tags&task=tags.searchAjax',
'dataType' => 'json',
'jsonTermKey' => 'like'
)
);
JHtml::_('formbehavior.ajaxchosen', $chosenAjaxSettings);
// Allow custom values ?
if ($allowCustom)
{
JFactory::getDocument()->addScriptDeclaration("
(function($){
$(document).ready(function () {
var customTagPrefix = '#new#';
// Method to add tags pressing enter
$('" . $selector . "_chzn input').keydown(function(event) {
// Tag is greater than 3 chars and enter pressed
if (this.value.length >= 3 && (event.which === 13 || event.which === 188)) {
// Search an highlighted result
var highlighted = $('" . $selector . "_chzn').find('li.active-result.highlighted').first();
// Add the highlighted option
if (event.which === 13 && highlighted.text() !== '')
{
// Extra check. If we have added a custom tag with this text remove it
var customOptionValue = customTagPrefix + highlighted.text();
$('" . $selector . " option').filter(function () { return $(this).val() == customOptionValue; }).remove();
// Select the highlighted result
var tagOption = $('" . $selector . " option').filter(function () { return $(this).html() == highlighted.text(); });
tagOption.attr('selected', 'selected');
}
// Add the custom tag option
else
{
var customTag = this.value;
// Extra check. Search if the custom tag already exists (typed faster than AJAX ready)
var tagOption = $('" . $selector . " option').filter(function () { return $(this).html() == customTag; });
if (tagOption.text() !== '')
{
tagOption.attr('selected', 'selected');
}
else
{
var option = $('<option>');
option.text(this.value).val(customTagPrefix + this.value);
option.attr('selected','selected');
// Append the option an repopulate the chosen field
$('" . $selector . "').append(option);
}
}
this.value = '';
$('" . $selector . "').trigger('liszt:updated');
event.preventDefault();
}
});
});
})(jQuery);
"
);
}
}
}

View File

@ -0,0 +1,80 @@
<?php
/**
* @package Joomla.Libraries
* @subpackage HTML
*
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
defined('JPATH_PLATFORM') or die;
/**
* HTML helper class for rendering telephone numbers.
*
* @package Joomla.Libraries
* @subpackage HTML
* @since 1.6
*/
abstract class JHtmlTel
{
/**
* Converts strings of integers into more readable telephone format
*
* By default, the ITU-T format will automatically be used.
* However, one of the allowed unit types may also be used instead.
*
* @param integer $number The integers in a phone number with dot separated country code
* ccc.nnnnnnn where ccc represents country code and nnn represents the local number.
* @param string $displayplan The numbering plan used to display the numbers.
*
* @return string The formatted telephone number.
*
* @see JFormRuleTel
* @since 1.6
*/
public static function tel($number, $displayplan)
{
$number = explode('.', $number);
$countrycode = $number[0];
$number = $number[1];
if ($displayplan == 'ITU-T' || $displayplan == 'International' || $displayplan == 'int' || $displayplan == 'missdn' || $displayplan == null)
{
$display[0] = '+';
$display[1] = $countrycode;
$display[2] = ' ';
$display[3] = implode(str_split($number, 2), ' ');
}
elseif ($displayplan == 'NANP' || $displayplan == 'northamerica' || $displayplan == 'US')
{
$display[0] = '(';
$display[1] = substr($number, 0, 3);
$display[2] = ') ';
$display[3] = substr($number, 3, 3);
$display[4] = '-';
$display[5] = substr($number, 6, 4);
}
elseif ($displayplan == 'EPP' || $displayplan == 'IETF')
{
$display[0] = '+';
$display[1] = $countrycode;
$display[2] = '.';
$display[3] = $number;
}
elseif ($displayplan == 'ARPA' || $displayplan == 'ENUM')
{
$number = implode(str_split(strrev($number), 1), '.');
$display[0] = '+';
$display[1] = $number;
$display[2] = '.';
$display[3] = $countrycode;
$display[4] = '.e164.arpa';
}
$display = implode($display, '');
return $display;
}
}

View File

@ -0,0 +1,86 @@
<?php
/**
* @package Joomla.Libraries
* @subpackage HTML
*
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
defined('JPATH_PLATFORM') or die;
/**
* Utility class working with users
*
* @package Joomla.Libraries
* @subpackage HTML
* @since 2.5
*/
abstract class JHtmlUser
{
/**
* Displays a list of user groups.
*
* @param boolean $includeSuperAdmin true to include super admin groups, false to exclude them
*
* @return array An array containing a list of user groups.
*
* @since 2.5
*/
public static function groups($includeSuperAdmin = false)
{
$db = JFactory::getDbo();
$query = $db->getQuery(true)
->select('a.id AS value, a.title AS text, COUNT(DISTINCT b.id) AS level')
->from($db->quoteName('#__usergroups') . ' AS a')
->join('LEFT', $db->quoteName('#__usergroups') . ' AS b ON a.lft > b.lft AND a.rgt < b.rgt')
->group('a.id, a.title, a.lft, a.rgt')
->order('a.lft ASC');
$db->setQuery($query);
$options = $db->loadObjectList();
for ($i = 0, $n = count($options); $i < $n; $i++)
{
$options[$i]->text = str_repeat('- ', $options[$i]->level) . $options[$i]->text;
$groups[] = JHtml::_('select.option', $options[$i]->value, $options[$i]->text);
}
// Exclude super admin groups if requested
if (!$includeSuperAdmin)
{
$filteredGroups = array();
foreach ($groups as $group)
{
if (!JAccess::checkGroup($group->value, 'core.admin'))
{
$filteredGroups[] = $group;
}
}
$groups = $filteredGroups;
}
return $groups;
}
/**
* Get a list of users.
*
* @return string
*
* @since 2.5
*/
public static function userlist()
{
$db = JFactory::getDbo();
$query = $db->getQuery(true)
->select('a.id AS value, a.name AS text')
->from('#__users AS a')
->where('a.block = 0')
->order('a.name');
$db->setQuery($query);
$items = $db->loadObjectList();
return $items;
}
}