0byt3m1n1-V2
Path:
/
home
/
a
/
c
/
a
/
academiac
/
www
/
[
Home
]
File: html.php.tar
home/academiac/www/administrator/components/com_virtuemart/helpers/html.php 0000604 00000051704 15137216503 0023441 0 ustar 00 <?php /** * HTML helper class * * This class was developed to provide some standard HTML functions. * * @package VirtueMart * @subpackage Helpers * @author RickG * @copyright Copyright (c) 2004-2008 Soeren Eberhardt-Biermann, 2009 VirtueMart Team. All rights reserved. */ // Check to ensure this file is included in Joomla! defined('_JEXEC') or die(); /** * HTML Helper * * @package VirtueMart * @subpackage Helpers * @author RickG */ class VmHTML{ /** * Default values for options. Organized by option group. * * @var array * @since 11.1 */ 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)); /** * Converts all special chars to html entities * * @param string $string * @param string $quote_style * @param boolean $only_special_chars Only Convert Some Special Chars ? ( <, >, &, ... ) * @return string */ static function shopMakeHtmlSafe( $string, $quote_style='ENT_QUOTES', $use_entities=false ) { if( defined( $quote_style )) { $quote_style = constant($quote_style); } if( $use_entities ) { $string = @htmlentities( $string, constant($quote_style), self::vmGetCharset() ); } else { $string = @htmlspecialchars( $string, $quote_style, self::vmGetCharset() ); } return $string; } /** * Returns the charset string from the global _ISO constant * * @return string UTF-8 by default * @since 1.0.5 */ static function vmGetCharset() { $iso = explode( '=', @constant('_ISO') ); if( !empty( $iso[1] )) { return $iso[1]; } else { return 'UTF-8'; } } /** * Generate HTML code for a row using VmHTML function * works also with shopfunctions, for example * $html .= VmHTML::row (array('ShopFunctions', 'renderShopperGroupList'), * 'VMCUSTOM_BUYER_GROUP_SHOPPER', $field->shopper_groups, TRUE, 'custom_param['.$row.'][shopper_groups][]', ' '); * * @func string : function to call * @label string : Text Label * @args array : arguments * @return string: HTML code for row table */ static function row($func,$label){ $VmHTML="VmHTML"; if (!is_array($func)) { $func = array($VmHTML, $func); } $passedArgs = func_get_args(); array_shift( $passedArgs );//remove function array_shift( $passedArgs );//remove label $args = array(); foreach ($passedArgs as $k => $v) { $args[] = &$passedArgs[$k]; } $lang =JFactory::getLanguage(); if($lang->hasKey($label.'_TIP')){ $labelHint = vmText::_($label.'_TIP'); $label = '<span class="hasTip" title="'.vmText::_($label.'_TIP').'">'.vmText::_($label).'</span>' ; } //Fallback else if($lang->hasKey($label.'_EXPLAIN')){ $labelHint = vmText::_($label.'_EXPLAIN'); $label = '<span class="hasTip" title="'.vmText::_($label.'_EXPLAIN').'">'.vmText::_($label).'</span>' ; } else { $label = vmText::_($label); } $html = ' <tr> <td class="key"> '.$label.' </td> <td> '.call_user_func_array($func, $args).' </td> </tr>'; return $html ; } /* simple value display */ static function value( $value ){ $lang =JFactory::getLanguage(); return $lang->hasKey($value) ? vmText::_($value) : $value; } /** * The sense is unclear ! * @deprecated * @param $value * @return mixed */ static function raw( $value ){ return $value; } /** * Generate HTML code for a checkbox * * @param string Name for the checkbox * @param mixed Current value of the checkbox * @param mixed Value to assign when checkbox is checked * @param mixed Value to assign when checkbox is not checked * @return string HTML code for checkbox */ static function checkbox($name, $value, $checkedValue=1, $uncheckedValue=0, $extraAttribs = '', $id = null) { if (!$id) $id=$name ; if ($value == $checkedValue) { $checked = 'checked="checked"'; } else { $checked = ''; } $htmlcode = '<input type="hidden" name="' . $name . '" value="' . $uncheckedValue . '" />'; $htmlcode .= '<input '.$extraAttribs.' id="' . $id . '" type="checkbox" name="' . $name . '" value="' . $checkedValue . '" ' . $checked . ' />'; return $htmlcode; } /** * * @author Patrick Kohl * @param array $options( value & text) * @param string $name option name * @param string $defaut defaut value * @param string $key option value * @param string $text option text * @param boolean $zero add a '0' value in the option * return a select list */ public static function select($name, $options, $default = '0',$attrib = "onchange='submit();'",$key ='value' ,$text ='text', $zero=true, $chosenDropDowns=true,$tranlsate=true){ if ($zero==true) { $option = array($key =>"0", $text => vmText::_('COM_VIRTUEMART_LIST_EMPTY_OPTION')); $options = array_merge(array($option), $options); } if ($chosenDropDowns) { vmJsApi::chosenDropDowns(); $attrib .= ' class="vm-chzn-select"'; } return VmHTML::genericlist($options,$name,$attrib,$key,$text,$default,false,$tranlsate); } /** * Generates an HTML selection list. * @author Joomla 2.5.14 * @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 11.1 */ 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'] . self::options($data, $options) . $baseIndent . '</select>' . $options['format.eol']; return $html; } /** * Generates the option tags for an HTML select list (with no select tag * surrounding the options). * @author Joomla 2.5.14 * @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 * "<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 11.1 */ public static function options($arr, $optKey = 'value', $optText = 'text', $selected = null, $translate = false) { $options = array_merge( JHtml::$formatOptions, self::$_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 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 = vmText::_($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 = vmText::_($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; } /** * Prints an HTML dropdown box named $name using $arr to * load the drop down. If $value is in $arr, then $value * will be the selected option in the dropdown. * @author gday * @author soeren * * @param string $name The name of the select element * @param string $value The pre-selected value * @param array $arr The array containing $key and $val * @param int $size The size of the select element * @param string $multiple use "multiple=\"multiple\" to have a multiple choice select list * @param string $extra More attributes when needed * @return string HTML drop-down list */ static function selectList($name, $value, $arrIn, $size=1, $multiple="", $extra="", $data_placeholder='') { $html = ''; if( empty( $arrIn ) ) { $arr = array(); } else { if(!is_array($arrIn)){ $arr=array($arrIn); } else { $arr=$arrIn; } } if (!empty($data_placeholder)) { $data_placeholder='data-placeholder="'.vmText::_($data_placeholder).'"'; } $html = '<select class="inputbox" id="'.$name.'" name="'.$name.'" size="'.$size.'" '.$multiple.' '.$extra.' '.$data_placeholder.' >'; while (list($key, $val) = each($arr)) { // foreach ($arr as $key=>$val){ $selected = ""; if( is_array( $value )) { if( in_array( $key, $value )) { $selected = 'selected="selected"'; } } else { if(strtolower($value) == strtolower($key) ) { $selected = 'selected="selected"'; } } $html .= '<option value="'.$key.'" '.$selected.'>'.self::shopMakeHtmlSafe($val); $html .= '</option>'; } $html .= '</select>'; return $html; } /** * Creates a Radio Input List * * @param string $name * @param string $value default value * @param string $arr * @param string $extra * @return string */ static function radioList($name, $value, &$arr, $extra="", $separator='<br />') { $html = ''; if( empty( $arr ) ) { $arr = array(); } $html = ''; $i = 0; foreach($arr as $key => $val) { $checked = ''; if( is_array( $value )) { if( in_array( $key, $value )) { $checked = 'checked="checked"'; } } else { if(strtolower($value) == strtolower($key) ) { $checked = 'checked="checked"'; } } $html .= '<input type="radio" name="'.$name.'" id="'.$name.$i.'" value="'.htmlspecialchars($key, ENT_QUOTES).'" '.$checked.' '.$extra." />\n"; $html .= '<label for="'.$name.$i++.'">'.$val."</label>".$separator."\n"; } return $html; } /** * Creates radio List * @param array $radios * @param string $name * @param string $default * @return string */ static function radio( $name, $radios, $default,$key='value',$text='text') { return '<fieldset class="radio">'.JHTML::_('select.radiolist', $radios, $name, '', $key, $text, $default).'</fieldset>'; } /** * Creating rows with boolean list * * @author Patrick Kohl * @param string $label * @param string $name * @param string $value * */ public static function booleanlist ( $name, $value,$class='class="inputbox"'){ return '<fieldset class="radio">'.JHTML::_( 'select.booleanlist', $name , $class , $value).'</fieldset>' ; } /** * Creating rows with input fields * * @author Patrick Kohl * @param string $text * @param string $name * @param string $value */ public static function input($name,$value,$class='class="inputbox"',$readonly='',$size='37',$maxlength='255',$more=''){ return '<input type="text" '.$readonly.' '.$class.' id="'.$name.'" name="'.$name.'" size="'.$size.'" maxlength="'.$maxlength.'" value="'.htmlspecialchars($value).'" />'.$more; } /** * Creating rows with input fields * * @author Patrick Kohl * @param string $text * @param string $name * @param string $value */ public static function textarea($name,$value,$class='class="inputbox"',$cols='100',$rows="4"){ return '<textarea '.$class.' id="'.$name.'" name="'.$name.'" cols="'.$cols.'" rows="'.$rows.'"/>'.$value.'</textarea >'; } /** * render editor code * * @author Patrick Kohl * @param string $text * @param string $name * @param string $value */ public static function editor($name,$value,$size='100%',$height='300',$hide = array('pagebreak', 'readmore')){ $editor =JFactory::getEditor(); return $editor->display($name, $value, $size, $height, null, null ,$hide ) ; } /** * renders the hidden input * @author Max Milbers */ public static function inputHidden($values){ $html=''; foreach($values as $k=>$v){ $html .= '<input type="hidden" name="'.$k.'" value="'.$v.'" />'; } return $html; } /** * @author Patrick Kohl * @var $type type of regular Expression to validate * $type can be I integer, F Float, A date, M, time, T text, L link, U url, P phone *@bool $required field is required *@Int $min minimum of char *@Int $max max of char *@var $match original ID field to compare with this such as Email, passsword *@ Return $html class for validate javascript **/ public static function validate($type='',$required=true, $min=null,$max=null,$match=null) { if ($required) $validTxt = 'required'; else $validTxt = 'optional'; if (isset($min)) $validTxt .= ',minSize['.$min.']'; if (isset($max)) $validTxt .= ',maxSize['.$max.']'; static $validateID=0 ; $validateID++; if ($type=='S' ) return 'id="validate'.$validateID.'" class="validate[required,minSize[2],maxSize[255]]"'; $validate = array ( 'I'=>'onlyNumberSp', 'F'=>'number','D'=>'dateTime','A'=>'date','M'=>'time','T'=>'Text','L'=>'link','U'=>'url','P'=>'phone'); if (isset ($validate[$type])) $validTxt .= ',custom['.$validate[$type].']'; $html ='id="validate'.$validateID.'" class="validate['.$validTxt.']"'; return $html ; } } home/academiac/www/libraries/joomla/html/html.php 0000644 00000066632 15137261242 0016105 0 ustar 00 <?php /** * @package Joomla.Platform * @subpackage HTML * * @copyright Copyright (C) 2005 - 2014 Open Source Matters, Inc. All rights reserved. * @license GNU General Public License version 2 or later; see LICENSE */ defined('JPATH_PLATFORM') or die; JHtml::addIncludePath(JPATH_PLATFORM . '/joomla/html/html'); jimport('joomla.environment.uri'); jimport('joomla.environment.browser'); jimport('joomla.filesystem.file'); /** * Utility class for all HTML drawing classes * * @package Joomla.Platform * @subpackage HTML * @since 11.1 */ abstract class JHtml { /** * Option values related to the generation of HTML output. Recognized * options are: * fmtDepth, integer. The current indent depth. * fmtEol, string. The end of line string, default is linefeed. * fmtIndent, string. The string to use for indentation, default is * tab. * * @var array * @since 11.1 */ public static $formatOptions = array('format.depth' => 0, 'format.eol' => "\n", 'format.indent' => "\t"); /** * An array to hold included paths * * @var array * @since 11.1 */ protected static $includePaths = array(); /** * An array to hold method references * * @var array * @since 11.1 */ protected static $registry = array(); /** * Method to extract a key * * @param string $key The name of helper method to load, (prefix).(class).function * prefix and class are optional and can be used to load custom html helpers. * * @return array Contains lowercase key, prefix, file, function. * * @since 11.1 */ protected static function extract($key) { $key = preg_replace('#[^A-Z0-9_\.]#i', '', $key); // Check to see whether we need to load a helper file $parts = explode('.', $key); $prefix = (count($parts) == 3 ? array_shift($parts) : 'JHtml'); $file = (count($parts) == 2 ? array_shift($parts) : ''); $func = array_shift($parts); return array(strtolower($prefix . '.' . $file . '.' . $func), $prefix, $file, $func); } /** * Class loader method * * Additional arguments may be supplied and are passed to the sub-class. * Additional include paths are also able to be specified for third-party use * * @param string $key The name of helper method to load, (prefix).(class).function * prefix and class are optional and can be used to load custom * html helpers. * * @return mixed JHtml::call($function, $args) or False on error * * @since 11.1 */ public static function _($key) { list($key, $prefix, $file, $func) = self::extract($key); if (array_key_exists($key, self::$registry)) { $function = self::$registry[$key]; $args = func_get_args(); // Remove function name from arguments array_shift($args); return JHtml::call($function, $args); } $className = $prefix . ucfirst($file); if (!class_exists($className)) { jimport('joomla.filesystem.path'); if ($path = JPath::find(JHtml::$includePaths, strtolower($file) . '.php')) { require_once $path; if (!class_exists($className)) { JError::raiseError(500, JText::sprintf('JLIB_HTML_ERROR_NOTFOUNDINFILE', $className, $func)); return false; } } else { JError::raiseError(500, JText::sprintf('JLIB_HTML_ERROR_NOTSUPPORTED_NOFILE', $prefix, $file)); return false; } } $toCall = array($className, $func); if (is_callable($toCall)) { JHtml::register($key, $toCall); $args = func_get_args(); // Remove function name from arguments array_shift($args); return JHtml::call($toCall, $args); } else { JError::raiseError(500, JText::sprintf('JLIB_HTML_ERROR_NOTSUPPORTED', $className, $func)); return false; } } /** * Registers a function to be called with a specific key * * @param string $key The name of the key * @param string $function Function or method * * @return boolean True if the function is callable * * @since 11.1 */ public static function register($key, $function) { list($key) = self::extract($key); if (is_callable($function)) { self::$registry[$key] = $function; return true; } return false; } /** * Removes a key for a method from registry. * * @param string $key The name of the key * * @return boolean True if a set key is unset * * @since 11.1 */ public static function unregister($key) { list($key) = self::extract($key); if (isset(self::$registry[$key])) { unset(self::$registry[$key]); return true; } return false; } /** * Test if the key is registered. * * @param string $key The name of the key * * @return boolean True if the key is registered. * * @since 11.1 */ public static function isRegistered($key) { list($key) = self::extract($key); return isset(self::$registry[$key]); } /** * Function caller method * * @param string $function Function or method to call * @param array $args Arguments to be passed to function * * @return mixed Function result or false on error. * * @see http://php.net/manual/en/function.call-user-func-array.php * @since 11.1 */ protected static function call($function, $args) { if (is_callable($function)) { // PHP 5.3 workaround $temp = array(); foreach ($args as &$arg) { $temp[] = &$arg; } return call_user_func_array($function, $temp); } else { JError::raiseError(500, JText::_('JLIB_HTML_ERROR_FUNCTION_NOT_SUPPORTED')); return false; } } /** * Write a <a></a> element * * @param string $url The relative URL to use for the href attribute * @param string $text The target attribute to use * @param array $attribs An associative array of attributes to add * * @return string <a></a> string * * @since 11.1 */ public static function link($url, $text, $attribs = null) { if (is_array($attribs)) { $attribs = JArrayHelper::toString($attribs); } return '<a href="' . $url . '" ' . $attribs . '>' . $text . '</a>'; } /** * Write a <iframe></iframe> element * * @param string $url The relative URL to use for the src attribute * @param string $name The target attribute to use * @param array $attribs An associative array of attributes to add * @param string $noFrames The message to display if the iframe tag is not supported * * @return string <iframe></iframe> element or message if not supported * * @since 11.1 */ public static function iframe($url, $name, $attribs = null, $noFrames = '') { if (is_array($attribs)) { $attribs = JArrayHelper::toString($attribs); } return '<iframe src="' . $url . '" ' . $attribs . ' name="' . $name . '">' . $noFrames . '</iframe>'; } /** * Compute the files to be include * * @param string $file path to file * @param boolean $relative path to file is relative to /media folder * @param boolean $detect_browser detect browser to include specific browser files * @param string $folder folder name to search into (images, css, js, ...) * * @return array files to be included * * @see JBrowser * @since 11.1 * * @deprecated 12.1 */ protected static function _includeRelativeFiles($file, $relative, $detect_browser, $folder) { JLog::add('JHtml::_includeRelativeFiles() is deprecated. Use JHtml::includeRelativeFiles().', JLog::WARNING, 'deprecated'); return self::includeRelativeFiles($folder, $file, $relative, $detect_browser, false); } /** * Compute the files to be include * * @param string $folder folder name to search into (images, css, js, ...) * @param string $file path to file * @param boolean $relative path to file is relative to /media folder * @param boolean $detect_browser detect browser to include specific browser files * @param boolean $detect_debug detect debug to include compressed files if debug is on * * @return array files to be included * * @see JBrowser * @since 11.1 */ protected static function includeRelativeFiles($folder, $file, $relative, $detect_browser, $detect_debug) { // If http is present in filename if (strpos($file, 'http') === 0) { $includes = array($file); } else { // Extract extension and strip the file $strip = JFile::stripExt($file); $ext = JFile::getExt($file); // Detect browser and compute potential files if ($detect_browser) { $navigator = JBrowser::getInstance(); $browser = $navigator->getBrowser(); $major = $navigator->getMajor(); $minor = $navigator->getMinor(); // Try to include files named filename.ext, filename_browser.ext, filename_browser_major.ext, filename_browser_major_minor.ext // where major and minor are the browser version names $potential = array($strip, $strip . '_' . $browser, $strip . '_' . $browser . '_' . $major, $strip . '_' . $browser . '_' . $major . '_' . $minor); } else { $potential = array($strip); } // If relative search in template directory or media directory if ($relative) { // Get the template $app = JFactory::getApplication(); $template = $app->getTemplate(); // Prepare array of files $includes = array(); // For each potential files foreach ($potential as $strip) { $files = array(); // Detect debug mode if ($detect_debug && JFactory::getConfig()->get('debug')) { $files[] = $strip . '-uncompressed.' . $ext; } $files[] = $strip . '.' . $ext; // Loop on 1 or 2 files and break on first found foreach ($files as $file) { // If the file is in the template folder if (file_exists(JPATH_THEMES . "/$template/$folder/$file")) { $includes[] = JURI::base(true) . "/templates/$template/$folder/$file"; break; } else { // If the file contains any /: it can be in an media extension subfolder if (strpos($file, '/')) { // Divide the file extracting the extension as the first part before / list($extension, $file) = explode('/', $file, 2); // If the file yet contains any /: it can be a plugin if (strpos($file, '/')) { // Divide the file extracting the element as the first part before / list($element, $file) = explode('/', $file, 2); // Try to deal with plugins group in the media folder if (file_exists(JPATH_ROOT . "/media/$extension/$element/$folder/$file")) { $includes[] = JURI::root(true) . "/media/$extension/$element/$folder/$file"; break; } // Try to deal with classical file in a a media subfolder called element elseif (file_exists(JPATH_ROOT . "/media/$extension/$folder/$element/$file")) { $includes[] = JURI::root(true) . "/media/$extension/$folder/$element/$file"; break; } // Try to deal with system files in the template folder elseif (file_exists(JPATH_THEMES . "/$template/$folder/system/$element/$file")) { $includes[] = JURI::root(true) . "/templates/$template/$folder/system/$element/$file"; break; } // Try to deal with system files in the media folder elseif (file_exists(JPATH_ROOT . "/media/system/$folder/$element/$file")) { $includes[] = JURI::root(true) . "/media/system/$folder/$element/$file"; break; } } // Try to deals in the extension media folder elseif (file_exists(JPATH_ROOT . "/media/$extension/$folder/$file")) { $includes[] = JURI::root(true) . "/media/$extension/$folder/$file"; break; } // Try to deal with system files in the template folder elseif (file_exists(JPATH_THEMES . "/$template/$folder/system/$file")) { $includes[] = JURI::root(true) . "/templates/$template/$folder/system/$file"; break; } // Try to deal with system files in the media folder elseif (file_exists(JPATH_ROOT . "/media/system/$folder/$file")) { $includes[] = JURI::root(true) . "/media/system/$folder/$file"; break; } } // Try to deal with system files in the media folder elseif (file_exists(JPATH_ROOT . "/media/system/$folder/$file")) { $includes[] = JURI::root(true) . "/media/system/$folder/$file"; break; } } } } } // If not relative and http is not present in filename else { $includes = array(); foreach ($potential as $strip) { // Detect debug mode if ($detect_debug && JFactory::getConfig()->get('debug') && file_exists(JPATH_ROOT . "/$strip-uncompressed.$ext")) { $includes[] = JURI::root(true) . "/$strip-uncompressed.$ext"; } elseif (file_exists(JPATH_ROOT . "/$strip.$ext")) { $includes[] = JURI::root(true) . "/$strip.$ext"; } } } } return $includes; } /** * Write a <img></img> element * * @param string $file The relative or absolute URL to use for the src attribute * @param string $alt The alt text. * @param string $attribs The target attribute to use * @param array $relative An associative array of attributes to add * @param boolean $path_only If set to true, it tries to find an override for the file in the template * * @return string * * @since 11.1 */ public static function image($file, $alt, $attribs = null, $relative = false, $path_only = false) { if (is_array($attribs)) { $attribs = JArrayHelper::toString($attribs); } $includes = self::includeRelativeFiles('images', $file, $relative, false, false); // If only path is required if ($path_only) { if (count($includes)) { return $includes[0]; } else { return null; } } else { return '<img src="' . (count($includes) ? $includes[0] : '') . '" alt="' . $alt . '" ' . $attribs . ' />'; } } /** * Write a <link rel="stylesheet" style="text/css" /> element * * @param string $file path to file * @param array $attribs attributes to be added to the stylesheet * @param boolean $relative path to file is relative to /media folder * @param boolean $path_only return the path to the file only * @param boolean $detect_browser detect browser to include specific browser css files * will try to include file, file_*browser*, file_*browser*_*major*, file_*browser*_*major*_*minor* * <table> * <tr><th>Navigator</th> <th>browser</th> <th>major.minor</th></tr> * * <tr><td>Safari 3.0.x</td> <td>konqueror</td> <td>522.x</td></tr> * <tr><td>Safari 3.1.x and 3.2.x</td> <td>konqueror</td> <td>525.x</td></tr> * <tr><td>Safari 4.0 to 4.0.2</td> <td>konqueror</td> <td>530.x</td></tr> * <tr><td>Safari 4.0.3 to 4.0.4</td> <td>konqueror</td> <td>531.x</td></tr> * <tr><td>iOS 4.0 Safari</td> <td>konqueror</td> <td>532.x</td></tr> * <tr><td>Safari 5.0</td> <td>konqueror</td> <td>533.x</td></tr> * * <tr><td>Google Chrome 1.0</td> <td>konqueror</td> <td>528.x</td></tr> * <tr><td>Google Chrome 2.0</td> <td>konqueror</td> <td>530.x</td></tr> * <tr><td>Google Chrome 3.0 and 4.x</td> <td>konqueror</td> <td>532.x</td></tr> * <tr><td>Google Chrome 5.0</td> <td>konqueror</td> <td>533.x</td></tr> * * <tr><td>Internet Explorer 5.5</td> <td>msie</td> <td>5.5</td></tr> * <tr><td>Internet Explorer 6.x</td> <td>msie</td> <td>6.x</td></tr> * <tr><td>Internet Explorer 7.x</td> <td>msie</td> <td>7.x</td></tr> * <tr><td>Internet Explorer 8.x</td> <td>msie</td> <td>8.x</td></tr> * * <tr><td>Firefox</td> <td>mozilla</td> <td>5.0</td></tr> * </table> * a lot of others * @param boolean $detect_debug detect debug to search for compressed files if debug is on * * @return mixed nothing if $path_only is false, null, path or array of path if specific css browser files were detected * * @see JBrowser * @since 11.1 */ public static function stylesheet($file, $attribs = array(), $relative = false, $path_only = false, $detect_browser = true, $detect_debug = true) { // Need to adjust for the change in API from 1.5 to 1.6. // Function stylesheet($filename, $path = 'media/system/css/', $attribs = array()) if (is_string($attribs)) { JLog::add('The used parameter set in JHtml::stylesheet() is deprecated.', JLog::WARNING, 'deprecated'); // Assume this was the old $path variable. $file = $attribs . $file; } if (is_array($relative)) { // Assume this was the old $attribs variable. $attribs = $relative; $relative = false; } $includes = self::includeRelativeFiles('css', $file, $relative, $detect_browser, $detect_debug); // If only path is required if ($path_only) { if (count($includes) == 0) { return null; } elseif (count($includes) == 1) { return $includes[0]; } else { return $includes; } } // If inclusion is required else { $document = JFactory::getDocument(); foreach ($includes as $include) { $document->addStylesheet($include, 'text/css', null, $attribs); } } } /** * Write a <script></script> element * * @param string $file path to file * @param boolean $framework load the JS framework * @param boolean $relative path to file is relative to /media folder * @param boolean $path_only return the path to the file only * @param boolean $detect_browser detect browser to include specific browser js files * @param boolean $detect_debug detect debug to search for compressed files if debug is on * * @return mixed nothing if $path_only is false, null, path or array of path if specific js browser files were detected * * @see JHtml::stylesheet * @since 11.1 */ public static function script($file, $framework = false, $relative = false, $path_only = false, $detect_browser = true, $detect_debug = true) { // Need to adjust for the change in API from 1.5 to 1.6. // function script($filename, $path = 'media/system/js/', $mootools = true) if (is_string($framework)) { JLog::add('The used parameter set in JHtml::script() is deprecated.', JLog::WARNING, 'deprecated'); // Assume this was the old $path variable. $file = $framework . $file; $framework = $relative; } // Include MooTools framework if ($framework) { JHtml::_('behavior.framework'); } $includes = self::includeRelativeFiles('js', $file, $relative, $detect_browser, $detect_debug); // If only path is required if ($path_only) { if (count($includes) == 0) { return null; } elseif (count($includes) == 1) { return $includes[0]; } else { return $includes; } } // If inclusion is required else { $document = JFactory::getDocument(); foreach ($includes as $include) { $document->addScript($include); } } } /** * Add the /media/system/js/core Javascript file. * * @param boolean $debug True if debugging is enabled. * * @return void * * @since 11.1 * @deprecated 12.1 Use JHtml::_('behavior.framework'); instead. */ public static function core($debug = null) { JLog::add('JHtml::core() is deprecated. Use JHtml::_(\'behavior.framework\');.', JLog::WARNING, 'deprecated'); JHtml::_('behavior.framework', false, $debug); } /** * Set format related options. * * Updates the formatOptions array with all valid values in the passed * array. See {@see JHtml::$formatOptions} for details. * * @param array $options Option key/value pairs. * * @return void * * @since 11.1 */ public static function setFormatOptions($options) { foreach ($options as $key => $val) { if (isset(self::$formatOptions[$key])) { self::$formatOptions[$key] = $val; } } } /** * Returns formated date according to a given format and time zone. * * @param string $input String in a format accepted by date(), defaults to "now". * @param string $format Format optional format for strftime * @param mixed $tz Time zone to be used for the date. Special cases: boolean true for user * setting, boolean false for server setting. * @param boolean $gregorian True to use Gregorian calenar * * @return string A date translated by the given format and time zone. * * @see strftime * @since 11.1 */ public static function date($input = 'now', $format = null, $tz = true, $gregorian = false) { // Get some system objects. $config = JFactory::getConfig(); $user = JFactory::getUser(); // UTC date converted to user time zone. if ($tz === true) { // Get a date object based on UTC. $date = JFactory::getDate($input, 'UTC'); // Set the correct time zone based on the user configuration. $date->setTimeZone(new DateTimeZone($user->getParam('timezone', $config->get('offset')))); } // UTC date converted to server time zone. elseif ($tz === false) { // Get a date object based on UTC. $date = JFactory::getDate($input, 'UTC'); // Set the correct time zone based on the server configuration. $date->setTimeZone(new DateTimeZone($config->get('offset'))); } // No date conversion. elseif ($tz === null) { $date = JFactory::getDate($input); } // UTC date converted to given time zone. else { // Get a date object based on UTC. $date = JFactory::getDate($input, 'UTC'); // Set the correct time zone based on the server configuration. $date->setTimeZone(new DateTimeZone($tz)); } // If no format is given use the default locale based format. if (!$format) { $format = JText::_('DATE_FORMAT_LC1'); } // format is an existing language key elseif (JFactory::getLanguage()->hasKey($format)) { $format = JText::_($format); } if ($gregorian) { return $date->format($format, true); } else { return $date->calendar($format, true); } } /** * Creates a tooltip with an image as button * * @param string $tooltip The tip string * @param mixed $title The title of the tooltip or an associative array with keys contained in * {'title','image','text','href','alt'} and values corresponding to parameters of the same name. * @param string $image The image for the tip, if no text is provided * @param string $text The text for the tip * @param string $href An URL that will be used to create the link * @param string $alt The alt attribute for img tag * @param string $class CSS class for the tool tip * * @return string * * @since 11.1 */ public static function tooltip($tooltip, $title = '', $image = 'tooltip.png', $text = '', $href = '', $alt = 'Tooltip', $class = 'hasTip') { if (is_array($title)) { if (isset($title['image'])) { $image = $title['image']; } if (isset($title['text'])) { $text = $title['text']; } if (isset($title['href'])) { $href = $title['href']; } if (isset($title['alt'])) { $alt = $title['alt']; } if (isset($title['class'])) { $class = $title['class']; } if (isset($title['title'])) { $title = $title['title']; } else { $title = ''; } } $tooltip = htmlspecialchars($tooltip, ENT_COMPAT, 'UTF-8'); $title = htmlspecialchars($title, ENT_COMPAT, 'UTF-8'); $alt = htmlspecialchars($alt, ENT_COMPAT, 'UTF-8'); if (!$text) { $text = self::image($image, $alt, null, true); } if ($href) { $tip = '<a href="' . $href . '">' . $text . '</a>'; } else { $tip = $text; } if ($title) { $tooltip = $title . '::' . $tooltip; } return '<span class="' . $class . '" title="' . $tooltip . '">' . $tip . '</span>'; } /** * Displays a calendar control field * * @param string $value The date value * @param string $name The name of the text field * @param string $id The id of the text field * @param string $format The date format * @param array $attribs Additional HTML attributes * * @return string HTML markup for a calendar field * * @since 11.1 */ public static function calendar($value, $name, $id, $format = '%Y-%m-%d', $attribs = null) { static $done; if ($done === null) { $done = array(); } $readonly = isset($attribs['readonly']) && $attribs['readonly'] == 'readonly'; $disabled = isset($attribs['disabled']) && $attribs['disabled'] == 'disabled'; if (is_array($attribs)) { $attribs = JArrayHelper::toString($attribs); } if (!$readonly && !$disabled) { // Load the calendar behavior self::_('behavior.calendar'); self::_('behavior.tooltip'); // Only display the triggers once for each control. if (!in_array($id, $done)) { $document = JFactory::getDocument(); $document ->addScriptDeclaration( 'window.addEvent(\'domready\', function() {Calendar.setup({ // Id of the input field inputField: "' . $id . '", // Format of the input field ifFormat: "' . $format . '", // Trigger for the calendar (button ID) button: "' . $id . '_img", // Alignment (defaults to "Bl") align: "Tl", singleClick: true, firstDay: ' . JFactory::getLanguage()->getFirstDay() . ' });});' ); $done[] = $id; } return '<input type="text" title="' . (0 !== (int) $value ? self::_('date', $value, null, null) : '') . '" name="' . $name . '" id="' . $id . '" value="' . htmlspecialchars($value, ENT_COMPAT, 'UTF-8') . '" ' . $attribs . ' />' . self::_('image', 'system/calendar.png', JText::_('JLIB_HTML_CALENDAR'), array('class' => 'calendar', 'id' => $id . '_img'), true); } else { return '<input type="text" title="' . (0 !== (int) $value ? self::_('date', $value, null, null) : '') . '" value="' . (0 !== (int) $value ? self::_('date', $value, 'Y-m-d H:i:s', null) : '') . '" ' . $attribs . ' /><input type="hidden" name="' . $name . '" id="' . $id . '" value="' . htmlspecialchars($value, ENT_COMPAT, 'UTF-8') . '" />'; } } /** * Add a directory where JHtml should search for helpers. You may * either pass a string or an array of directories. * * @param string $path A path to search. * * @return array An array with directory elements * * @since 11.1 */ public static function addIncludePath($path = '') { // Force path to array settype($path, 'array'); // Loop through the path directories foreach ($path as $dir) { if (!empty($dir) && !in_array($dir, JHtml::$includePaths)) { jimport('joomla.filesystem.path'); array_unshift(JHtml::$includePaths, JPath::clean($dir)); } } return JHtml::$includePaths; } } home/academiac/www/libraries/joomla/document/html/html.php 0000644 00000040562 15137561476 0017731 0 ustar 00 <?php /** * @package Joomla.Platform * @subpackage Document * * @copyright Copyright (C) 2005 - 2014 Open Source Matters, Inc. All rights reserved. * @license GNU General Public License version 2 or later; see LICENSE */ defined('JPATH_PLATFORM') or die; jimport('joomla.application.module.helper'); jimport('joomla.utilities.utility'); /** * DocumentHTML class, provides an easy interface to parse and display a HTML document * * @package Joomla.Platform * @subpackage Document * @since 11.1 */ class JDocumentHTML extends JDocument { /** * Array of Header <link> tags * * @var array * @since 11.1 */ public $_links = array(); /** * Array of custom tags * * @var array * @since 11.1 */ public $_custom = array(); /** * Name of the template * * @var string * @since 11.1 */ public $template = null; /** * Base url * * @var string * @since 11.1 */ public $baseurl = null; /** * Array of template parameters * * @var array * @since 11.1 */ public $params = null; /** * File name * * @var array * @since 11.1 */ public $_file = null; /** * String holding parsed template * * @var string * @since 11.1 */ protected $_template = ''; /** * Array of parsed template JDoc tags * * @var array * @since 11.1 */ protected $_template_tags = array(); /** * Integer with caching setting * * @var integer * @since 11.1 */ protected $_caching = null; /** * Class constructor * * @param array $options Associative array of options * * @since 11.1 */ public function __construct($options = array()) { parent::__construct($options); // Set document type $this->_type = 'html'; // Set default mime type and document metadata (meta data syncs with mime type by default) $this->setMimeEncoding('text/html'); } /** * Get the HTML document head data * * @return array The document head data in array form * * @since 11.1 */ public function getHeadData() { $data = array(); $data['title'] = $this->title; $data['description'] = $this->description; $data['link'] = $this->link; $data['metaTags'] = $this->_metaTags; $data['links'] = $this->_links; $data['styleSheets'] = $this->_styleSheets; $data['style'] = $this->_style; $data['scripts'] = $this->_scripts; $data['script'] = $this->_script; $data['custom'] = $this->_custom; return $data; } /** * Set the HTML document head data * * @param array $data The document head data in array form * * @return JDocumentHTML instance of $this to allow chaining * * @since 11.1 */ public function setHeadData($data) { if (empty($data) || !is_array($data)) { return; } $this->title = (isset($data['title']) && !empty($data['title'])) ? $data['title'] : $this->title; $this->description = (isset($data['description']) && !empty($data['description'])) ? $data['description'] : $this->description; $this->link = (isset($data['link']) && !empty($data['link'])) ? $data['link'] : $this->link; $this->_metaTags = (isset($data['metaTags']) && !empty($data['metaTags'])) ? $data['metaTags'] : $this->_metaTags; $this->_links = (isset($data['links']) && !empty($data['links'])) ? $data['links'] : $this->_links; $this->_styleSheets = (isset($data['styleSheets']) && !empty($data['styleSheets'])) ? $data['styleSheets'] : $this->_styleSheets; $this->_style = (isset($data['style']) && !empty($data['style'])) ? $data['style'] : $this->_style; $this->_scripts = (isset($data['scripts']) && !empty($data['scripts'])) ? $data['scripts'] : $this->_scripts; $this->_script = (isset($data['script']) && !empty($data['script'])) ? $data['script'] : $this->_script; $this->_custom = (isset($data['custom']) && !empty($data['custom'])) ? $data['custom'] : $this->_custom; return $this; } /** * Merge the HTML document head data * * @param array $data The document head data in array form * * @return JDocumentHTML instance of $this to allow chaining * * @since 11.1 */ public function mergeHeadData($data) { if (empty($data) || !is_array($data)) { return; } $this->title = (isset($data['title']) && !empty($data['title']) && !stristr($this->title, $data['title'])) ? $this->title . $data['title'] : $this->title; $this->description = (isset($data['description']) && !empty($data['description']) && !stristr($this->description, $data['description'])) ? $this->description . $data['description'] : $this->description; $this->link = (isset($data['link'])) ? $data['link'] : $this->link; if (isset($data['metaTags'])) { foreach ($data['metaTags'] as $type1 => $data1) { $booldog = $type1 == 'http-equiv' ? true : false; foreach ($data1 as $name2 => $data2) { $this->setMetaData($name2, $data2, $booldog); } } } $this->_links = (isset($data['links']) && !empty($data['links']) && is_array($data['links'])) ? array_unique(array_merge($this->_links, $data['links'])) : $this->_links; $this->_styleSheets = (isset($data['styleSheets']) && !empty($data['styleSheets']) && is_array($data['styleSheets'])) ? array_merge($this->_styleSheets, $data['styleSheets']) : $this->_styleSheets; if (isset($data['style'])) { foreach ($data['style'] as $type => $stdata) { if (!isset($this->_style[strtolower($type)]) || !stristr($this->_style[strtolower($type)], $stdata)) { $this->addStyleDeclaration($stdata, $type); } } } $this->_scripts = (isset($data['scripts']) && !empty($data['scripts']) && is_array($data['scripts'])) ? array_merge($this->_scripts, $data['scripts']) : $this->_scripts; if (isset($data['script'])) { foreach ($data['script'] as $type => $sdata) { if (!isset($this->_script[strtolower($type)]) || !stristr($this->_script[strtolower($type)], $sdata)) { $this->addScriptDeclaration($sdata, $type); } } } $this->_custom = (isset($data['custom']) && !empty($data['custom']) && is_array($data['custom'])) ? array_unique(array_merge($this->_custom, $data['custom'])) : $this->_custom; return $this; } /** * Adds <link> tags to the head of the document * * $relType defaults to 'rel' as it is the most common relation type used. * ('rev' refers to reverse relation, 'rel' indicates normal, forward relation.) * Typical tag: <link href="index.php" rel="Start"> * * @param string $href The link that is being related. * @param string $relation Relation of link. * @param string $relType Relation type attribute. Either rel or rev (default: 'rel'). * @param array $attribs Associative array of remaining attributes. * * @return JDocumentHTML instance of $this to allow chaining * * @since 11.1 */ public function addHeadLink($href, $relation, $relType = 'rel', $attribs = array()) { $this->_links[$href]['relation'] = $relation; $this->_links[$href]['relType'] = $relType; $this->_links[$href]['attribs'] = $attribs; return $this; } /** * Adds a shortcut icon (favicon) * * This adds a link to the icon shown in the favorites list or on * the left of the url in the address bar. Some browsers display * it on the tab, as well. * * @param string $href The link that is being related. * @param string $type File type * @param string $relation Relation of link * * @return JDocumentHTML instance of $this to allow chaining * * @since 11.1 */ public function addFavicon($href, $type = 'image/vnd.microsoft.icon', $relation = 'shortcut icon') { $href = str_replace('\\', '/', $href); $this->addHeadLink($href, $relation, 'rel', array('type' => $type)); return $this; } /** * Adds a custom HTML string to the head block * * @param string $html The HTML to add to the head * * @return JDocumentHTML instance of $this to allow chaining * * @since 11.1 */ public function addCustomTag($html) { $this->_custom[] = trim($html); return $this; } /** * Get the contents of a document include * * @param string $type The type of renderer * @param string $name The name of the element to render * @param array $attribs Associative array of remaining attributes. * * @return The output of the renderer * * @since 11.1 */ public function getBuffer($type = null, $name = null, $attribs = array()) { // If no type is specified, return the whole buffer if ($type === null) { return parent::$_buffer; } $result = null; if (isset(parent::$_buffer[$type][$name])) { return parent::$_buffer[$type][$name]; } // If the buffer has been explicitly turned off don't display or attempt to render if ($result === false) { return null; } $renderer = $this->loadRenderer($type); if ($this->_caching == true && $type == 'modules') { $cache = JFactory::getCache('com_modules', ''); $hash = md5(serialize(array($name, $attribs, $result, $renderer))); $cbuffer = $cache->get('cbuffer_' . $type); if (isset($cbuffer[$hash])) { return JCache::getWorkarounds($cbuffer[$hash], array('mergehead' => 1)); } else { $options = array(); $options['nopathway'] = 1; $options['nomodules'] = 1; $options['modulemode'] = 1; $this->setBuffer($renderer->render($name, $attribs, $result), $type, $name); $data = parent::$_buffer[$type][$name]; $tmpdata = JCache::setWorkarounds($data, $options); $cbuffer[$hash] = $tmpdata; $cache->store($cbuffer, 'cbuffer_' . $type); } } else { $this->setBuffer($renderer->render($name, $attribs, $result), $type, $name); } return parent::$_buffer[$type][$name]; } /** * Set the contents a document includes * * @param string $content The content to be set in the buffer. * @param array $options Array of optional elements. * * @return JDocumentHTML instance of $this to allow chaining * * @since 11.1 */ public function setBuffer($content, $options = array()) { // The following code is just for backward compatibility. if (func_num_args() > 1 && !is_array($options)) { $args = func_get_args(); $options = array(); $options['type'] = $args[1]; $options['name'] = (isset($args[2])) ? $args[2] : null; } parent::$_buffer[$options['type']][$options['name']] = $content; return $this; } /** * Parses the template and populates the buffer * * @param array $params Parameters for fetching the template * * @return JDocumentHTML instance of $this to allow chaining * * @since 11.1 */ public function parse($params = array()) { return $this->_fetchTemplate($params)->_parseTemplate(); } /** * Outputs the template to the browser. * * @param boolean $caching If true, cache the output * @param array $params Associative array of attributes * * @return The rendered data * * @since 11.1 */ public function render($caching = false, $params = array()) { $this->_caching = $caching; if (!empty($this->_template)) { $data = $this->_renderTemplate(); } else { $this->parse($params); $data = $this->_renderTemplate(); } parent::render(); return $data; } /** * Count the modules based on the given condition * * @param string $condition The condition to use * * @return integer Number of modules found * * @since 11.1 */ public function countModules($condition) { $operators = '(\+|\-|\*|\/|==|\!=|\<\>|\<|\>|\<=|\>=|and|or|xor)'; $words = preg_split('# ' . $operators . ' #', $condition, null, PREG_SPLIT_DELIM_CAPTURE); for ($i = 0, $n = count($words); $i < $n; $i += 2) { // odd parts (modules) $name = strtolower($words[$i]); $words[$i] = ((isset(parent::$_buffer['modules'][$name])) && (parent::$_buffer['modules'][$name] === false)) ? 0 : count(JModuleHelper::getModules($name)); } $str = 'return ' . implode(' ', $words) . ';'; return eval($str); } /** * Count the number of child menu items * * @return integer Number of child menu items * * @since 11.1 */ public function countMenuChildren() { static $children; if (!isset($children)) { $dbo = JFactory::getDbo(); $app = JFactory::getApplication(); $menu = $app->getMenu(); $active = $menu->getActive(); if ($active) { $query->getQuery(true); $query->select('COUNT(*)'); $query->from('#__menu'); $query->where('parent_id = ' . $active->id); $query->where('published = 1'); $children = $dbo->loadResult(); } else { $children = 0; } } return $children; } /** * Load a template file * * @param string $directory The name of the template * @param string $filename The actual filename * * @return string The contents of the template * * @since 11.1 */ protected function _loadTemplate($directory, $filename) { // $component = JApplicationHelper::getComponentName(); $contents = ''; // Check to see if we have a valid template file if (file_exists($directory . '/' . $filename)) { // Store the file path $this->_file = $directory . '/' . $filename; //get the file content ob_start(); require $directory . '/' . $filename; $contents = ob_get_contents(); ob_end_clean(); } // Try to find a favicon by checking the template and root folder $path = $directory . '/'; $dirs = array($path, JPATH_BASE . '/'); foreach ($dirs as $dir) { $icon = $dir . 'favicon.ico'; if (file_exists($icon)) { $path = str_replace(JPATH_BASE . '/', '', $dir); $path = str_replace('\\', '/', $path); $this->addFavicon(JURI::base(true) . '/' . $path . 'favicon.ico'); break; } } return $contents; } /** * Fetch the template, and initialise the params * * @param array $params Parameters to determine the template * * @return JDocumentHTML instance of $this to allow chaining * * @since 11.1 */ protected function _fetchTemplate($params = array()) { // Check $directory = isset($params['directory']) ? $params['directory'] : 'templates'; $filter = JFilterInput::getInstance(); $template = $filter->clean($params['template'], 'cmd'); $file = $filter->clean($params['file'], 'cmd'); if (!file_exists($directory . '/' . $template . '/' . $file)) { $template = 'system'; } // Load the language file for the template $lang = JFactory::getLanguage(); $lang->load('tpl_' . $template, JPATH_BASE, null, false, true) || $lang->load('tpl_' . $template, $directory . '/' . $template, null, false, true); // Assign the variables $this->template = $template; $this->baseurl = JURI::base(true); $this->params = isset($params['params']) ? $params['params'] : new JRegistry; // Load $this->_template = $this->_loadTemplate($directory . '/' . $template, $file); return $this; } /** * Parse a document template * * @return The parsed contents of the template * * @return JDocumentHTML instance of $this to allow chaining * * @since 11.1 */ protected function _parseTemplate() { $matches = array(); if (preg_match_all('#<jdoc:include\ type="([^"]+)" (.*)\/>#iU', $this->_template, $matches)) { $template_tags_first = array(); $template_tags_last = array(); // Step through the jdocs in reverse order. for ($i = count($matches[0]) - 1; $i >= 0; $i--) { $type = $matches[1][$i]; $attribs = empty($matches[2][$i]) ? array() : JUtility::parseAttributes($matches[2][$i]); $name = isset($attribs['name']) ? $attribs['name'] : null; // Separate buffers to be executed first and last if ($type == 'module' || $type == 'modules') { $template_tags_first[$matches[0][$i]] = array('type' => $type, 'name' => $name, 'attribs' => $attribs); } else { $template_tags_last[$matches[0][$i]] = array('type' => $type, 'name' => $name, 'attribs' => $attribs); } } // Reverse the last array so the jdocs are in forward order. $template_tags_last = array_reverse($template_tags_last); $this->_template_tags = $template_tags_first + $template_tags_last; } return $this; } /** * Render pre-parsed template * * @return string rendered template * * @since 11.1 */ protected function _renderTemplate() { $replace = array(); $with = array(); foreach ($this->_template_tags as $jdoc => $args) { $replace[] = $jdoc; $with[] = $this->getBuffer($args['type'], $args['name'], $args['attribs']); } return str_replace($replace, $with, $this->_template); } }
©
2018.