Smarty
[ class tree: Smarty ] [ index: Smarty ] [ all elements ]

Source for file function.biticon.php

Documentation is available at function.biticon.php

  1. <?php
  2. /**
  3.  * Smarty plugin
  4.  * @package Smarty
  5.  * @subpackage plugins
  6.  * @link http://www.bitweaver.org/wiki/function_biticon function_biticon
  7.  */
  8.  
  9. /**
  10.  * biticon_first_match
  11.  *
  12.  * @param string $pDir Directory in which we want to search for the icon
  13.  * @param array $pFilename Icon name without the extension
  14.  * @access public
  15.  * @return Icon name with extension on success, FALSE on failure
  16.  */
  17. function biticon_first_match$pDir$pFilename {
  18.     ifis_dir$pDir )) {
  19.         global $gSniffer;
  20.  
  21.         // if this is MSIE < 7, we try png last.
  22.         if$gSniffer->_browser_info['browser'== 'ie' && $gSniffer->_browser_info['maj_ver'{
  23.             $extensions array'gif''jpg''png' );
  24.         else {
  25.             $extensions array'png''gif''jpg' );
  26.         }
  27.  
  28.         foreach$extensions as $ext {
  29.             ifis_file$pDir.$pFilename.'.'.$ext ) ) {
  30.                 return $pFilename.'.'.$ext;
  31.             }
  32.         }
  33.     }
  34.     return FALSE;
  35. }
  36.  
  37. /**
  38.  * Turn collected information into an html image
  39.  *
  40.  * @param boolean $pParams['url'] set to TRUE if you only want the url and nothing else
  41.  * @param string $pParams['iexplain'] Explanation of what the icon represents
  42.  * @param string $pParams['iforce'] takes following optins: icon, icon_text, text - will override system settings
  43.  * @param string $pFile Path to icon file
  44.  * @param string iforce  override site-wide setting how to display icons (can be set to 'icon', 'text' or 'icon_text')
  45.  * @access public
  46.  * @return Full <img> on success
  47.  */
  48. function biticon_output$pParams$pFile {
  49.     global $gBitSystem;
  50.     $iexplain = isset$pParams["iexplain"tra$pParams["iexplain"'please set iexplain';
  51.  
  52.     ifempty$pParams['iforce')) {
  53.         $pParams['iforce'NULL;
  54.     }
  55.  
  56.     ifisset$pParams["url")) {
  57.         $outstr $pFile;
  58.     else {
  59.         if(( $gBitSystem->getConfig'site_biticon_display_style' == 'text' || $pParams['iforce'== 'text' && $pParams['iforce'!= 'icon' {
  60.             $outstr =  $iexplain;
  61.         else {
  62.             $outstr='<img src="'.$pFile.'"';
  63.             ifisset$pParams["iexplain") ) {
  64.                 $outstr .= ' alt="'.tra$pParams["iexplain").'" title="'.tra$pParams["iexplain").'"';
  65.             else {
  66.                 $outstr .= ' alt=""';
  67.             }
  68.  
  69.             $ommit array'ilocation''ipackage''ipath''iname''iexplain''iforce''istyle''iclass' );
  70.             foreach$pParams as $name => $val {
  71.                 if!in_array$name$ommit ) ) {
  72.                     $outstr .= ' '.$name.'="'.$val.'"';
  73.                 }
  74.             }
  75.  
  76.             if!isset$pParams["iclass") ) {
  77.                 $outstr .= ' class="icon"';
  78.             else {
  79.                 $outstr .= ' class="'.$pParams["iclass"].'"';
  80.             }
  81.  
  82.             ifisset$pParams["onclick") ) {
  83.                 $outstr .=  ' onclick="'.$pParams["onclick"].'"';
  84.             }
  85.  
  86.             $outstr .= " />";
  87.  
  88.             if$gBitSystem->getConfig'site_biticon_display_style' == 'icon_text' && $pParams['iforce'!= 'icon' || $pParams['iforce'== 'icon_text' {
  89.                 $outstr .= '&nbsp;'.$iexplain;
  90.             }
  91.         }
  92.     }
  93.  
  94.     if!preg_match"#^broken\.#"$pFile )) {
  95.         if!biticon_write_cache$pParams$outstr )) {
  96.             echo tra'There was a problem writing the icon cache file' );
  97.         }
  98.     }
  99.  
  100.     return $outstr;
  101. }
  102.  
  103. /**
  104.  * smarty_function_biticon
  105.  *
  106.  * @param array $pParams['ipath'] subdirectory within icon directory
  107.  * @param array $pParams['iname'] name of the icon without extension
  108.  * @param array $pParams['ipackage'] package the icon should be searched for - if it's part of an icon theme, this should be set to 'icons'
  109.  * @param array $gBitSmarty Referenced object
  110.  * @access public
  111.  * @return final <img>
  112.  */
  113. function smarty_function_biticon$pParams&$gBitSmarty$pCheckSmall FALSE {
  114.     global $gBitSystem$gBitThemes$gSniffer;
  115.  
  116.     // this is needed in case everything goes horribly wrong
  117.     $copyParams $pParams;
  118.  
  119.     // ensure that ipath has a leading and trailing slash
  120.     if!empty$pParams['ipath')) {
  121.         $pParams['ipath'str_replace"//""/""/".$pParams['ipath']."/" );
  122.     else {
  123.         $pParams['ipath''/';
  124.     }
  125.  
  126.     // try to separate iname from ipath if we've been given some sloppy naming
  127.     ifstrstr$pParams['iname']'/' )) {
  128.         $pParams['iname'$pParams['ipath'].$pParams['iname'];
  129.         $boom explode'/'$pParams['iname');
  130.         $pParams['iname'array_pop$boom );
  131.         $pParams['ipath'str_replace"//""/""/".implode$boom'/' )."/" );
  132.     }
  133.  
  134.     // if we don't have an ipath yet, we will set it here
  135.     if$pParams['ipath'== '/' {
  136.         // iforce is generally only set in menus - we might need a parameter to identify menus more accurately
  137.         if!empty$pParams['ilocation')) {
  138.             if$pParams['ilocation'== 'menu' {
  139.                 $pParams['ipath'.= 'small/';
  140.                 $pParams['iforce''icon_text';
  141.             elseif$pParams['ilocation'== 'quicktag' {
  142.                 $pParams['ipath'.= 'small/';
  143.                 $pParams['iforce''icon';
  144.                 $pParams['iclass''quicktag icon';
  145.             }
  146.         else {
  147.             if!empty$pParams['isize')) {
  148.                 $pParams['ipath'.= $pParams['isize'].'/';
  149.             else {
  150.                 $pParams['ipath'.= $gBitSystem->getConfig'site_icon_size''small' ).'/';
  151.             }
  152.         }
  153.     }
  154.  
  155.     // this only happens when we haven't found the original icon we've been looking for
  156.     if$pCheckSmall {
  157.         $pParams['ipath'preg_replace"!/.*?/$!""/small/"$pParams['ipath');
  158.     }
  159.  
  160.     // we have one special case: pkg_icons don't have a size variant
  161.     ifstrstr$pParams['iname']'pkg_' && !strstr$pParams['ipath']'small' )) {
  162.         $pParams['ipath'preg_replace"!/.*?/$!""/"$pParams['ipath');
  163.     }
  164.  
  165.     // make sure ipackage is set correctly
  166.     if!empty$pParams['ipackage')) {
  167.         $pParams['ipackage'strtolower$pParams['ipackage');
  168.     else {
  169.         $pParams['ipackage''icons';
  170.     }
  171.  
  172.     // if the user is using a text-browser we force text instead of icons
  173.     if$gSniffer->_browser_info['browser'== 'lx' || $gSniffer->_browser_info['browser'== 'li' {
  174.         $pParams['iforce''text';
  175.     }
  176.  
  177.     // get out of here as quickly as possible if we've already cached the icon information before
  178.     if(( $ret biticon_read_cache$pParams )) && !defined'TEMPLATE_DEBUG' && TEMPLATE_DEBUG == TRUE )) {
  179.         return $ret;
  180.     }
  181.  
  182.     // first deal with most common scenario: icon style ( a selected iconset from config/iconsets/ )
  183.     if$pParams['ipackage'== 'icons' {
  184.         // get the current icon style
  185.         // istyle is a private parameter!!! - only used on theme manager page for icon preview!!!
  186.         // violators will be poked with soft cushions by the Cardinal himself!!!
  187.         $icon_style !empty$pParams['istyle'$pParams['istyle'$gBitSystem->getConfig'site_icon_style'DEFAULT_ICON_STYLE );
  188.  
  189.         ifFALSE !== $matchFile biticon_first_matchCONFIG_PKG_PATH."iconsets/$icon_style".$pParams['ipath']$pParams['iname'))) {
  190.             return biticon_output$pParamsCONFIG_PKG_URL."iconsets/$icon_style".$pParams['ipath'].$matchFile );
  191.         }
  192.  
  193.         if$icon_style != DEFAULT_ICON_STYLE && FALSE !== $matchFile biticon_first_matchCONFIG_PKG_PATH."iconsets/".DEFAULT_ICON_STYLE.$pParams['ipath']$pParams['iname'))) {
  194.             return biticon_output$pParamsCONFIG_PKG_URL."iconsets/".DEFAULT_ICON_STYLE.$pParams['ipath'].$matchFile );
  195.         }
  196.  
  197.         // if that didn't work, we'll try liberty
  198.         $pParams['ipath''/'.$gBitSystem->getConfig'site_icon_size''small' ).'/';
  199.         $pParams['ipackage''liberty';
  200.     }
  201.  
  202.     // since package icons reside in <pkg>/icons/ we don't need the small/ subdir
  203.     ifstrstr"/small/"$pParams['ipath')) {
  204.         $pParams['ipath'str_replace"small/"""$pParams['ipath');
  205.         $small TRUE;
  206.     }
  207.  
  208.     // first check themes/force
  209.     ifFALSE !== $matchFile biticon_first_matchTHEMES_PKG_PATH."force/icons/".$pParams['ipackage'].$pParams['ipath']$pParams['iname'))) {
  210.         return biticon_output$pParamsBIT_ROOT_URL."themes/force/icons/".$pParams['ipackage'].$pParams['ipath'].$matchFile );
  211.     }
  212.  
  213.     //if we have site styles, look there
  214.     ifFALSE !== $matchFile biticon_first_match$gBitThemes->getStylePath().'/icons/'.$pParams['ipackage'].$pParams['ipath']$pParams['iname'))) {
  215.         return biticon_output$pParams$gBitThemes->getStyleUrl().'/icons/'.$pParams['ipackage'].$pParams['ipath'].$matchFile );
  216.     }
  217.  
  218.     //Well, then lets look in the package location
  219.     ifFALSE !== $matchFile biticon_first_matchconstantstrtoupper$pParams['ipackage').'_PKG_PATH' )."icons".$pParams['ipath']$pParams['iname'))) {
  220.         return biticon_output$pParamsconstantstrtoupper$pParams['ipackage').'_PKG_URL' )."icons".$pParams['ipath'].$matchFile );
  221.     }
  222.  
  223.     // Still didn't find it! Well lets output something (return FALSE if only the url is requested)
  224.     ifisset$pParams['url')) {
  225.         return FALSE;
  226.     else {
  227.         // if we were looking for the large icon, we'll try the whole kaboodle again, looking for the small icon
  228.         ifempty$small && !$pCheckSmall {
  229.             return smarty_function_biticon$copyParams$gBitSmartyTRUE );
  230.         else {
  231.             return biticon_output$pParams"broken.icon.".$pParams['ipackage']."/".$pParams['ipath'].$pParams['iname');
  232.         }
  233.     }
  234. }
  235.  
  236. /**
  237.  * biticon_cache
  238.  *
  239.  * @param array $pParams 
  240.  * @access public
  241.  * @return cached icon string on sucess, FALSE on failure
  242.  */
  243. function biticon_read_cache$pParams {
  244.     $ret FALSE;
  245.     $cacheFile biticon_get_cache_file$pParams );
  246.     ifis_readable$cacheFile )) {
  247.         if$h fopen$cacheFile'r' )) {
  248.             $ret fread$hfilesize$cacheFile ));
  249.             fclose$h );
  250.         }
  251.     }
  252.  
  253.     return $ret;
  254. }
  255.  
  256. /**
  257.  * biticon_write_cache
  258.  *
  259.  * @param array $pParams 
  260.  * @access public
  261.  * @return TRUE on success, FALSE on failure
  262.  */
  263. function biticon_write_cache$pParams$pCacheString {
  264.     $ret FALSE;
  265.     if$cacheFile biticon_get_cache_file$pParams )) {
  266.         if$h fopen$cacheFile'w' )) {
  267.             $ret fwrite$h$pCacheString );
  268.             fclose$h );
  269.         }
  270.     }
  271.  
  272.     return$ret != );
  273. }
  274.  
  275. /**
  276.  * will get the path to the cache files based on the stuff in $pParams
  277.  *
  278.  * @param array $pParams 
  279.  * @access public
  280.  * @return full path to cachefile
  281.  */
  282. function biticon_get_cache_file$pParams {
  283.     global $gBitThemes$gBitSystem;
  284.  
  285.     // create a hash filename based on the parameters given
  286.     $hashstring '';
  287.     $ihash array'iforce''ipath''iname''iexplain''ipackage''url''istyle''id''style''onclick' );
  288.     foreach$pParams as $param => $value {
  289.         ifin_array$param$ihash )) {
  290.             $hashstring .= strtolower$value );
  291.         }
  292.     }
  293.  
  294.     // return path to cache file
  295.     return $gBitThemes->getIconCachePath().md5$hashstring.$gBitSystem->getConfig'site_biticon_display_style''icon' ));
  296. }
  297. ?>

Documentation generated on Wed, 29 Jul 2015 13:56:37 +0000 by phpDocumentor 1.5.0-lsces