Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 976 lines (898 sloc) 29.222 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975
<?php
/**
* @package Joomla.Platform
* @subpackage HTML
*
* @copyright Copyright (C) 2005 - 2012 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.environment.browser');
jimport('joomla.filesystem.file');
jimport('joomla.filesystem.path');

/**
* 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
* @throws InvalidArgumentException
*/
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 self::call($function, $args);
}

$className = $prefix . ucfirst($file);

if (!class_exists($className))
{
$path = JPath::find(self::$includePaths, strtolower($file) . '.php');
if ($path)
{
require_once $path;

if (!class_exists($className))
{
throw new InvalidArgumentException(sprintf('%s not found.', $className), 500);
}
}
else
{
throw new InvalidArgumentException(sprintf('%s %s not found.', $prefix, $file), 500);
}
}

$toCall = array($className, $func);
if (is_callable($toCall))
{
self::register($key, $toCall);
$args = func_get_args();

// Remove function name from arguments
array_shift($args);
return self::call($toCall, $args);
}
else
{
throw new InvalidArgumentException(sprintf('%s::%s not found.', $className, $func), 500);
}
}

/**
* 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 callable $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
* @throws InvalidArgumentException
*/
protected static function call($function, $args)
{
if (!is_callable($function))
{
throw new InvalidArgumentException('Function not supported', 500);
}

// PHP 5.3 workaround
$temp = array();
foreach ($args as &$arg)
{
$temp[] = &$arg;
}
return call_user_func_array($function, $temp);
}

/**
* 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 included
*
* @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);

// Prepare array of files
$includes = array();

// 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();

// For each potential files
foreach ($potential as $strip)
{
$files = array();

// Detect debug mode
if ($detect_debug && JFactory::getConfig()->get('debug'))
{
/*
* Detect if we received a file in the format name.min.ext
* If so, strip the .min part out, otherwise append -uncompressed
*/
if (strrpos($strip, '.min', '-4'))
{
$position = strrpos($strip, '.min', '-4');
$filename = str_replace('.min', '.', $strip, $position);
$files[] = $filename . $ext;
}
else
{
$files[] = $strip . '-uncompressed.' . $ext;
}
}
$files[] = $strip . '.' . $ext;

/*
* Loop on 1 or 2 files and break on first found.
* Add the content of the MD5SUM file located in the same folder to url to ensure cache browser refresh
* This MD5SUM file must represent the signature of the folder content
*/
foreach ($files as $file)
{
// If the file is in the template folder
$path = JPATH_THEMES . "/$template/$folder/$file";
if (file_exists($path))
{
$md5 = dirname($path) . '/MD5SUM';
$includes[] = JURI::base(true) . "/templates/$template/$folder/$file" .
(file_exists($md5) ? ('?' . file_get_contents($md5)) : '');
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
$path = JPATH_ROOT . "/media/$extension/$element/$folder/$file";
if (file_exists($path))
{
$md5 = dirname($path) . '/MD5SUM';
$includes[] = JURI::root(true) . "/media/$extension/$element/$folder/$file" .
(file_exists($md5) ? ('?' . file_get_contents($md5)) : '');
break;
}

// Try to deal with classical file in a a media subfolder called element
$path = JPATH_ROOT . "/media/$extension/$folder/$element/$file";
if (file_exists($path))
{
$md5 = dirname($path) . '/MD5SUM';
$includes[] = JURI::root(true) . "/media/$extension/$folder/$element/$file" .
(file_exists($md5) ? ('?' . file_get_contents($md5)) : '');
break;
}

// Try to deal with system files in the template folder
$path = JPATH_THEMES . "/$template/$folder/system/$element/$file";
if (file_exists($path))
{
$md5 = dirname($path) . '/MD5SUM';
$includes[] = JURI::root(true) . "/templates/$template/$folder/system/$element/$file" .
(file_exists($md5) ? ('?' . file_get_contents($md5)) : '');
break;
}

// Try to deal with system files in the media folder
$path = JPATH_ROOT . "/media/system/$folder/$element/$file";
if (file_exists($path))
{
$md5 = dirname($path) . '/MD5SUM';
$includes[] = JURI::root(true) . "/media/system/$folder/$element/$file" .
(file_exists($md5) ? ('?' . file_get_contents($md5)) : '');
break;
}
}
else
{
// Try to deals in the extension media folder
$path = JPATH_ROOT . "/media/$extension/$folder/$file";
if (file_exists($path))
{
$md5 = dirname($path) . '/MD5SUM';
$includes[] = JURI::root(true) . "/media/$extension/$folder/$file" .
(file_exists($md5) ? ('?' . file_get_contents($md5)) : '');
break;
}

// Try to deal with system files in the template folder
$path = JPATH_THEMES . "/$template/$folder/system/$file";
if (file_exists($path))
{
$md5 = dirname($path) . '/MD5SUM';
$includes[] = JURI::root(true) . "/templates/$template/$folder/system/$file" .
(file_exists($md5) ? ('?' . file_get_contents($md5)) : '');
break;
}

// Try to deal with system files in the media folder
$path = JPATH_ROOT . "/media/system/$folder/$file";
if (file_exists($path))
{
$md5 = dirname($path) . '/MD5SUM';
$includes[] = JURI::root(true) . "/media/system/$folder/$file" .
(file_exists($md5) ? ('?' . file_get_contents($md5)) : '');
break;
}
}
}
// Try to deal with system files in the media folder
else
{
$path = JPATH_ROOT . "/media/system/$folder/$file";
if (file_exists($path))
{
$md5 = dirname($path) . '/MD5SUM';
$includes[] = JURI::root(true) . "/media/system/$folder/$file" .
(file_exists($md5) ? ('?' . file_get_contents($md5)) : '');
break;
}
}
}
}
}
}
// If not relative and http is not present in filename
else
{
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.
* Add the content of the MD5SUM file located in the same folder to url to ensure cache browser refresh
* This MD5SUM file must represent the signature of the folder content
*/
foreach ($files as $file)
{
$path = JPATH_ROOT . "/$file";
if (file_exists($path))
{
$md5 = dirname($path) . '/MD5SUM';
$includes[] = JURI::root(true) . "/$file" .
(file_exists($md5) ? ('?' . file_get_contents($md5)) : '');
break;
}
}
}
}
}
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)
{
$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)
{
// Include MooTools framework
if ($framework)
{
self::_('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);
}
}
}

/**
* 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 The date format specification string (see {@link PHP_MANUAL#date})
* @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))
{
foreach (array('image', 'text', 'href', 'alt', 'class') as $param)
{
if (isset($title[$param]))
{
$$param = $title[$param];
}
}
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, self::$includePaths))
{
jimport('joomla.filesystem.path');
array_unshift(self::$includePaths, JPath::clean($dir));
}
}

return self::$includePaths;
}

/**
* 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 12.2
*/
public static function getJSObject(array $array = array())
{
$elements = array();
foreach ($array as $k => $v)
{
// Don't encode either of these types
if (is_null($v) || is_resource($v))
{
continue;
}

// Safely encode as a Javascript string
$key = json_encode((string) $k);

if (is_bool($v))
{
$elements[] = $key . ': ' . ($v ? 'true' : 'false');
}
elseif (is_numeric($v))
{
$elements[] = $key . ': ' . ($v + 0);
}
elseif (is_string($v))
{
if (strpos($v, '\\') === 0)
{
// Items such as functions and JSON objects are prefixed with \, strip the prefix and don't encode them
$elements[] = $key . ': ' . substr($v, 1);
}
else
{
// The safest way to insert a string
$elements[] = $key . ': ' . json_encode((string) $v);
}
}
else
{
$elements[] = $key . ': ' . self::getJSObject(is_object($v) ? get_object_vars($v) : $v);
}
}

return '{' . implode(',', $elements) . '}';

}
}
Something went wrong with that request. Please try again.