Source code for file /joomla/html/html.php
Documentation is available at html.php
* @version $Id: html.php 6749 2007-03-01 22:54:50Z hackwar $
* @package Joomla.Framework
* @copyright Copyright (C) 2005 - 2007 Open Source Matters. All rights reserved.
* @license GNU/GPL, see LICENSE.php
* Joomla! is free software. This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
* is derivative of works licensed under the GNU General Public License or
* other free or open source software licenses.
* See COPYRIGHT.php for copyright notices and details.
* Utility class for all HTML drawing classes
* @package Joomla.Framework
* Write a <a></a> element
* @param string The relative URL to use for the href attribute
* @param string The target attribute to use
* @param array An associative array of attributes to add
* @param integer Set the SSL functionality
function Link($url, $text, $attribs =
null, $ssl =
0)
return '<a href="'.
$href.
'" '.
$attribs.
'>'.
$text.
'</a>';
* Write a <img></amg> element
* @param string The relative URL to use for the src attribute
* @param string The target attribute to use
* @param array An associative array of attributes to add
function Image($url, $alt, $attribs =
null)
$src =
substr( $url, 0, 4 ) !=
'http' ?
$mainframe->getCfg('live_site') .
$url :
$url;
return '<img src="'.
$src.
'" alt="'.
$alt.
'" '.
$attribs.
' />';
* Write a <script></script> element
* @param string The relative URL to use for the src attribute
* @param string The target attribute to use
* @param array An associative array of attributes to add
function Script($url, $attribs =
null)
$src =
$mainframe->getCfg('live_site') .
$url;
return '<script type="text/javascript" src="'.
$src.
'" '.
$attribs.
'></script>';
* Write a <iframe></iframe> element
* @param string The relative URL to use for the src attribute
* @param string The target attribute to use
* @param array An associative array of attributes to add
* @param integer Set the SSL functionality
function Iframe($url, $name, $attribs =
null, $ssl =
0)
return '<iframe src="'.
$src.
'" '.
$attribs.
' />';
* Returns formated date according to current local and adds time offset
* @param string date in an US English date format
* @param string format optional format for strftime
function Date($date, $format =
DATE_FORMAT_LC, $offset =
NULL)
$offset =
$config->getValue('config.offset');
$instance =
new JDate($date);
$instance->setOffset($offset);
return $instance->toFormat($format);
* @param int The row index
* @param int The record id
* @param string The name of the form element
function idBox( $rowNum, $recId, $checkedOut=
false, $name=
'cid' )
return '<input type="checkbox" id="cb'.
$rowNum.
'" name="'.
$name.
'[]" value="'.
$recId.
'" onclick="isChecked(this.checked);" />';
* simple Javascript Cloaking
* by default replaces an email with a mailto link with email cloacked
// split email by @ symbol
$mail_parts =
explode( '.', $mail[1] );
$rand =
rand( 1, 100000 );
$replacement =
"\n <script language='JavaScript' type='text/javascript'>";
$replacement .=
"\n <!--";
$replacement .=
"\n var prefix = 'ma' + 'il' + 'to';";
$replacement .=
"\n var path = 'hr' + 'ef' + '=';";
$replacement .=
"\n var addy".
$rand .
" = '".
@$mail[0] .
"' + '@';";
$replacement .=
"\n addy".
$rand .
" = addy".
$rand .
" + '".
implode( "' + '.' + '", $mail_parts ) .
"';";
// special handling when mail text is different from mail addy
// split email by @ symbol
$text_parts =
explode( '.', $text[1] );
$replacement .=
"\n var addy_text".
$rand .
" = '".
@$text[0] .
"' + '@' + '".
implode( "' + '.' + '", @$text_parts ) .
"';";
$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>' );";
$replacement .=
"\n document.write( '<a ' + path + '\'' + prefix + ':' + addy".
$rand .
" + '\'>' );";
$replacement .=
"\n document.write( addy".
$rand .
" );";
$replacement .=
"\n document.write( '<\/a>' );";
$replacement .=
"\n document.write( addy".
$rand .
" );";
$replacement .=
"\n //-->";
$replacement .=
'\n </script>';
// XHTML compliance `No Javascript` text handling
$replacement .=
"<script language='JavaScript' type='text/javascript'>";
$replacement .=
"\n <!--";
$replacement .=
"\n document.write( '<span style=\'display: none;\'>' );";
$replacement .=
"\n //-->";
$replacement .=
"\n </script>";
$replacement .=
JText::_('CLOAKING');
$replacement .=
"\n <script language='JavaScript' type='text/javascript'>";
$replacement .=
"\n <!--";
$replacement .=
"\n document.write( '</' );";
$replacement .=
"\n document.write( 'span>' );";
$replacement .=
"\n //-->";
$replacement .=
"\n </script>";
* Keep session alive, for example, while editing or creating an article.
setTimeout('frames[\'keepAliveFrame\'].location.href=\'index.php?option=com_admin&tmpl=component&task=keepalive\';', 60000);
$html =
"<iframe id=\"keepAliveFrame\" name=\"keepAliveFrame\" " .
"style=\"width:0px; height:0px; border: 0px\" " .
"src=\"index.php?option=com_admin&tmpl=component&task=keepalive\" " .
"onload=\"keepAlive();\"></iframe>";
$doc->addScriptDeclaration($js);
// replace vowels with character encoding
function _implode_assoc($inner_glue =
"=", $outer_glue =
"\n", $array =
null, $keepOuterKey =
false)
foreach($array as $key =>
$item)
// This is value is an array, go and do it again!
$output[] =
$key .
$inner_glue .
$item;
return implode($outer_glue, $output);
* Utility class for creating HTML select lists
* @package Joomla.Framework
function option( $value, $text=
'', $value_name=
'value', $text_name=
'text' )
$obj->$value_name =
$value;
$obj->$text_name =
trim( $text ) ?
$text :
$value;
* Generates an HTML select list
* @param array An array of objects
* @param string The value of the HTML name attribute
* @param string Additional HTML attributes for the <select> tag
* @param string The name of the object variable for the option value
* @param string The name of the object variable for the option text
* @param mixed The key that is selected (accepts an array or a string)
* @returns string HTML for the select list
function genericList( $arr, $tag_name, $tag_attribs, $key, $text, $selected=
NULL, $idtag=
false, $flag=
false )
$html =
'<select name="'.
$tag_name .
'" id="'.
$id .
'" '.
$tag_attribs .
'>';
// for ($i=0, $n=count( $arr ); $i < $n; $i++ ) {
$element =
& $arr[key($arr)]; // since current doesn't return a reference, need to do this
$id =
( isset
( $element['id'] ) ?
$element['id'] :
null );
$id =
( isset
( $element->id ) ?
$element->id :
null );
// This is real dirty, open to suggestions,
// barring doing a propper object to handle it
if ($k ===
'<OPTGROUP>') {
$html .=
'<optgroup label="' .
$t .
'">';
} else if ($k ===
'</OPTGROUP>') {
//if no string after hypen - take hypen out
$splitText =
explode( " - ", $t, 2 );
if(isset
($splitText[1])){ $t .=
" - ".
$splitText[1]; }
//$extra .= $id ? ' id="' . $arr[$i]->id . '"' : '';
foreach ($selected as $obj) {
$extra .=
' selected="selected"';
$extra .=
( $k ==
$selected ?
' selected="selected"' :
'' );
$html .=
'<option value="'.
$k .
'" '.
$extra .
'>' .
$t .
'</option>';
* Generates a select list of integers
* @param int The start integer
* @param int The end integer
* @param int The increment
* @param string The value of the HTML name attribute
* @param string Additional HTML attributes for the <select> tag
* @param mixed The key that is selected
* @param string The printf format to be applied to the number
* @returns string HTML for the select list
function integerList( $start, $end, $inc, $tag_name, $tag_attribs, $selected, $format=
"" )
for ($i=
$start; $i <=
$end; $i+=
$inc) {
$fi =
$format ?
sprintf( "$format", $i ) :
"$i";
* Generates an HTML radio list
* @param array An array of objects
* @param string The value of the HTML name attribute
* @param string Additional HTML attributes for the <select> tag
* @param mixed The key that is selected
* @param string The name of the object variable for the option value
* @param string The name of the object variable for the option text
* @returns string HTML for the select list
function radioList( $arr, $tag_name, $tag_attribs, $selected=
null, $key=
'value', $text=
'text', $idtag=
false )
for ($i=
0, $n=
count( $arr ); $i <
$n; $i++
) {
$id =
( isset
($arr[$i]->id) ?
@$arr[$i]->id :
null);
$extra .=
$id ?
" id=\"" .
$arr[$i]->id .
"\"" :
'';
foreach ($selected as $obj) {
$extra .=
" selected=\"selected\"";
$extra .=
($k ==
$selected ?
" checked=\"checked\"" :
'');
$html .=
"\n\t<input type=\"radio\" name=\"$tag_name\" id=\"$id_text$k\" value=\"".
$k.
"\"$extra $tag_attribs />";
$html .=
"\n\t<label for=\"$id_text$k\">$t</label>";
* Generates a yes/no radio list
* @param string The value of the HTML name attribute
* @param string Additional HTML attributes for the <select> tag
* @param mixed The key that is selected
* @returns string HTML for the radio list
function yesnoList( $tag_name, $tag_attribs, $selected, $yes=
'yes', $no=
'no', $id=
false ) {
return JHTMLSelect::radioList( $arr, $tag_name, $tag_attribs, (int)
$selected, 'value', 'text', $id );
* Utility class for drawing common HTML elements
* @package Joomla.Framework
* Function is only used in the administrator
<table cellspacing="0" cellpadding="4" border="0" align="center">
<img src="images/publish_y.png" width="16" height="16" border="0" alt="
<?php echo
JText::_( 'Pending' ); ?>" />
<?php echo
JText::_( 'Published, but is' ); ?> <u>
<?php echo
JText::_( 'Pending' ); ?></u> |
<img src="images/publish_g.png" width="16" height="16" border="0" alt="
<?php echo
JText::_( 'Visible' ); ?>" />
<?php echo
JText::_( 'Published and is' ); ?> <u>
<?php echo
JText::_( 'Current' ); ?></u> |
<img src="images/publish_r.png" width="16" height="16" border="0" alt="
<?php echo
JText::_( 'Finished' ); ?>" />
<?php echo
JText::_( 'Published, but has' ); ?> <u>
<?php echo
JText::_( 'Expired' ); ?></u> |
<img src="images/publish_x.png" width="16" height="16" border="0" alt="
<?php echo
JText::_( 'Finished' ); ?>" />
<?php echo
JText::_( 'Not Published' ); ?>
<td colspan="8" align="center">
<?php echo
JText::_( 'Click on icon to toggle state.' ); ?>
* Function is only used in the administrator
$date =
JHTML::Date( $row->checked_out_time, '%A, %d %B %Y' );
$time =
JHTML::Date( $row->checked_out_time, '%H:%M' );
$hover =
'<span class="editlinktip hasTip" title="'.
JText::_( 'Checked Out' ) .
'::'.
$text .
'<br />'.
$date .
'<br />'.
$time .
'">';
$checked =
$hover .
'<img src="images/checked_out.png"/></span>';
* Creates a tooltip with an image as button
function ToolTip($tooltip, $title=
'', $image=
'tooltip.png', $text=
'', $href=
'', $link=
1)
$url =
$mainframe->isAdmin() ?
$mainframe->getSiteURL() :
JURI::base();
$image =
$url .
'includes/js/ThemeOffice/'.
$image;
$text =
'<img src="'.
$image .
'" border="0" alt="'.
JText::_( 'Tooltip' ) .
'"/>';
$text =
JText::_( $text, true );
$style =
'style="text-decoration: none; color: #333;"';
$tip =
'<span class="editlinktip hasTip" title="'.
$title.
$tooltip.
'" '.
$style .
'><a href="'.
$href .
'">'.
$text .
'</a></span>';
$tip =
'<span class="editlinktip hasTip" title="'.
$title.
$tooltip.
'" '.
$style .
'>'.
$text .
'</span>';
* Loads all necessary files for JS Calendar
* Function is used in the administrator/site : move into JCalendar
$url =
$mainframe->isAdmin() ?
$mainframe->getSiteURL() :
JURI::base();
$doc->addStyleSheet( $url.
'includes/js/calendar/calendar-mos.css', 'text/css', null, array(' title' =>
JText::_( 'green' ) ,' media' =>
'all' ));
$doc->addScript( $url.
'includes/js/calendar/calendar_mini.js' );
$langScript =
JPATH_SITE.
DS.
'includes'.
DS.
'js'.
DS.
'calendar'.
DS.
'lang'.
DS.
'calendar-'.
$lang->getTag().
'.js';
$doc->addScript( $url.
'includes/js/calendar/lang/calendar-'.
$lang->getTag().
'.js' );
$doc->addScript( $url.
'includes/js/calendar/lang/calendar-en-GB.js' );
* Function is used only in the administrator : move to JHTMLGrid
$color_access =
'style="color: green;"';
$task_access =
'accessregistered';
} else if ( $row->access ==
1 ) {
$color_access =
'style="color: red;"';
$task_access =
'accessspecial';
$color_access =
'style="color: black;"';
$task_access =
'accesspublic';
$href =
JText::_( $row->groupname );
<a href="javascript:void(0);" onclick="return listItemTask(\'cb'.
$i .
'\',\''.
$task_access .
'\')" '.
$color_access .
'>
'.
JText::_( $row->groupname ) .
'
* Function is used only in the administrator : move to JHTMLGrid
$userid =
$user->get('id');
if(is_a($row, 'JTable')) {
$result =
$row->isCheckedOut($userid);
* Function is used only in the administrator : move to JHTMLGrid
$img =
$row->published ?
$imgY :
$imgX;
$task =
$row->published ?
'unpublish' :
'publish';
$alt =
$row->published ?
JText::_( 'Published' ) :
JText::_( 'Unpublished' );
$action =
$row->published ?
JText::_( 'Unpublish Item' ) :
JText::_( 'Publish item' );
<a href="javascript:void(0);" onclick="return listItemTask(\'cb'.
$i .
'\',\''.
$prefix.
$task .
'\')" title="'.
$action .
'">
<img src="images/'.
$img .
'" border="0" alt="'.
$alt .
'" />
* Function is used only in the administrator : move to JHTMLGrid
function selectState( $filter_state=
'*', $published=
'Published', $unpublished=
'Unpublished', $archived=
NULL )
return JHTMLSelect::genericList( $state, 'filter_state', 'class="inputbox" size="1" onchange="submitform( );"', 'value', 'text', $filter_state );
* Function is used only in the administrator : move to JHTMLGrid
function saveorderButton( $rows, $image=
'filesave.png', $task=
"saveorder" )
<a href="javascript:saveorder(
<?php echo
count( $rows )-
1; ?>, '
<?php echo
$task; ?>')" title="
<?php echo
JText::_( 'Save Order' ); ?>">
<?php echo
$image; ?></a>
* Function is used only in the administrator : move to JHTMLGrid
<a href="javascript:tableOrdering('
<?php echo
$ordering; ?>','
<?php echo
$lists['order_Dir']; ?>','
<?php echo
$task; ?>');" title="
<?php echo
JText::_( 'Order by' ); ?> <?php echo
JText::_( $text ); ?>">
<?php echo
JText::_( $text ); ?>
* Function is used only in the administrator : move to JHTMLGrid
if ( $current ==
$lists['order']) {
if ( $lists['order_Dir'] ==
'ASC' ) {
$image =
'sort_desc.png';
* Utility class for drawing admin menu HTML elements
* @package Joomla.Framework
* build the select list for Menu Ordering
* Function is only used in administrator/component/com_menus/views/item/tmpl/form.php
$query =
'SELECT ordering AS value, name AS text'
.
' WHERE menutype = \''.
$row->menutype
.
'\' AND parent = '.
$row->parent
$ordering =
'<input type="hidden" name="ordering" value="'.
$row->ordering .
'" />'.
JText::_( 'DESCNEWITEMSLAST' );
* build the select list for access level
* Function is used in administrator/site (com_content) : move into parameters
$query =
'SELECT id AS value, name AS text'
$groups =
$db->loadObjectList();
* build the multiple select list for Menu Links/Pages
* Function is only used in the administrator (multiple components)
// get a list of the menu items
$query =
'SELECT m.id, m.parent, m.name, m.menutype'
.
' WHERE m.published = 1'
.
' ORDER BY m.menutype, m.parent, m.ordering'
$mitems =
$db->loadObjectList();
// establish the hierarchy of the menu
// first pass - collect children
foreach ( $mitems as $v )
$list =
@$children[$pt] ?
$children[$pt] :
array();
// second pass - get an indent list of the items
// Code that adds menu name to Display of Page(s)
$mitems_spacer =
$mitems_temp[0]->menutype;
if ($all |
$unassigned) {
foreach ($list as $list_a)
if ($list_a->menutype !=
$lastMenuType)
$lastMenuType =
$list_a->menutype;
$tmpMenuType =
$list_a->menutype;
if ($lastMenuType !==
null) {
* build the select list to choose an image
* Function is only used in the administrator (multiple components) : duplicate with JElementImagelist
function Images( $name, &$active, $javascript=
NULL, $directory=
NULL )
$directory =
'/images/stories/';
$javascript =
"onchange=\"javascript:if (document.forms[0]." .
$name .
".options[selectedIndex].value!='') {document.imagelib.src='..$directory' + document.forms[0]." .
$name .
".options[selectedIndex].value} else {document.imagelib.src='../images/blank.png'}\"";
jimport( 'joomla.filesystem.folder' );
foreach ( $imageFiles as $file ) {
if ( eregi( "bmp|gif|jpg|png", $file ) ) {
$images =
JHTMLSelect::genericList( $images, $name, 'class="inputbox" size="1" '.
$javascript, 'value', 'text', $active );
* @param string SQL with ordering As value and 'name field' AS text
* @param integer The length of the truncated headline
* Function is only used in the administrator (com_plugins)
if (!($orders =
$db->loadObjectList())) {
if ($db->getErrorNum()) {
for ($i=
0, $n=
count( $orders ); $i <
$n; $i++
) {
$text =
$orders[$i]->text;
$order[] =
JHTMLSelect::option( $orders[$i]->value, $orders[$i]->value.
' ('.
$text.
')' );
* build the select list for Ordering of a specified Table
* Function is only used in the administrator (multiple components)
$text =
JText::_( 'descNewItemsFirst' );
$text =
JText::_( 'descNewItemsLast' );
$ordering =
'<input type="hidden" name="ordering" value="'.
$row->ordering .
'" />'.
$text;
* Select list of active users
* Function is only used in the administrator (multiple components) : function could create preformance issues
function UserSelect( $name, $active, $nouser=
0, $javascript=
NULL, $order=
'name', $reg=
1 )
// does not include registered users in the list
$query =
'SELECT id AS value, name AS text'
$users =
$db->loadObjectList();
$users =
JHTMLSelect::genericList( $users, $name, 'class="inputbox" size="1" '.
$javascript, 'value', 'text', $active );
* Select list of positions - generally used for location of images
* Function is only used in the administrator (com_categories, com_sections)
function Positions( $name, $active=
NULL, $javascript=
NULL, $none=
1, $center=
1, $left=
1, $right=
1, $id=
false )
$positions =
JHTMLSelect::genericList( $pos, $name, 'class="inputbox" size="1"'.
$javascript, 'value', 'text', $active, $id );
* Select list of active categories for components
* Function is used in the site/administrator : duplicate in JElementCategory
function ComponentCategory( $name, $section, $active=
NULL, $javascript=
NULL, $order=
'ordering', $size=
1, $sel_cat=
1 )
$query =
'SELECT id AS value, name AS text'
.
' WHERE section = "'.
$section .
'"'
$categories =
array_merge( $categories, $db->loadObjectList() );
$categories =
$db->loadObjectList();
if ( count( $categories ) <
1 ) {
$mainframe->redirect( 'index.php?option=com_categories§ion='.
$section, JText::_( 'You must create a category first.' ) );
$category =
JHTMLSelect::genericList( $categories, $name, 'class="inputbox" size="'.
$size .
'" '.
$javascript, 'value', 'text', $active );
* Select list of active sections
* Function is only used in the administrator : duplicate in JElementSection
function SelectSection( $name, $active=
NULL, $javascript=
NULL, $order=
'ordering' )
$query =
'SELECT id AS value, title AS text'
$sections =
array_merge( $categories, $db->loadObjectList() );
$category =
JHTMLSelect::genericList( $sections, $name, 'class="inputbox" size="1" '.
$javascript, 'value', 'text', $active );
* Checks to see if an image exists in the current templates image directory
* if it does it loads this image. Otherwise the default image is loaded.
* Also can be used in conjunction with the menulist param to create the chosen image
* load the default or use no image
* Function is only used in the site/administrator : move to JHTML::Image
function ImageCheck( $file, $directory=
'/images/M_images/', $param=
NULL, $param_directory=
'/images/M_images/', $alt=
NULL, $name=
'image', $type=
1, $align=
'top' )
$cur_template =
$mainframe->getTemplate();
$image =
$param_directory .
$param;
$image =
'<img src="'.
$image .
'" align="'.
$align .
'" alt="'.
$alt .
'" border="0" />';
} else if ( $param == -
1 ) {
$path =
JPATH_SITE .
'/templates/'.
$cur_template .
'/images/'.
$file;
if (!isset
( $paths[$path] ))
if ( file_exists( JPATH_SITE .
'/templates/'.
$cur_template .
'/images/'.
$file ) ) {
$paths[$path] =
'templates/'.
$cur_template .
'/images/'.
$file;
// outputs only path to image
$paths[$path] =
$directory .
$file;
if (substr($image, 0, 1 ) ==
"/") {
// outputs actual html <img> tag
$image =
'<img src="'.
$image .
'" alt="'.
$alt .
'" align="'.
$align .
'" border="0" />';
* Checks to see if an image exists in the current templates image directory
* if it does it loads this image. Otherwise the default image is loaded.
* Also can be used in conjunction with the menulist param to create the chosen image
* load the default or use no image
* Function is only used in the site/administrator : move to JHTML::Image (combine with ImageCheck)
function ImageCheckAdmin( $file, $directory=
'/images/', $param=
NULL, $param_directory=
'/images/', $alt=
NULL, $name=
NULL, $type=
1, $align=
'middle' )
$cur_template =
$mainframe->getTemplate();
$image =
$param_directory .
$param;
} else if ( $param == -
1 ) {
if ( file_exists( JPATH_ADMINISTRATOR .
'/templates/'.
$cur_template .
'/images/'.
$file ) ) {
$image =
'templates/'.
$cur_template .
'/images/'.
$file;
// compability with previous versions
if ( substr($directory, 0, 14 )==
"/administrator" ) {
$image =
substr($directory,15) .
$file;
$image =
$directory .
$file;
if (substr($image, 0, 1 ) ==
"/") {
// outputs actual html <img> tag
$image =
'<img src="'.
$image .
'" alt="'.
$alt .
'" align="'.
$align .
'" border="0" />';