Source for file function.biticon.php
Documentation is available at function.biticon.php
* @link http://www.bitweaver.org/wiki/function_biticon function_biticon
* @param string $pDir Directory in which we want to search for the icon
* @param array $pFilename Icon name without the extension
* @return Icon name with extension on success, FALSE on failure
// if this is MSIE < 7, we try png last.
if( $gSniffer->_browser_info['browser'] == 'ie' && $gSniffer->_browser_info['maj_ver'] < 7 ) {
$extensions = array( 'gif', 'jpg', 'png' );
$extensions = array( 'png', 'gif', 'jpg' );
foreach( $extensions as $ext ) {
if( is_file( $pDir. $pFilename. '.'. $ext ) ) {
return $pFilename. '.'. $ext;
* Turn collected information into an html image
* @param boolean $pParams['url'] set to TRUE if you only want the url and nothing else
* @param string $pParams['iexplain'] Explanation of what the icon represents
* @param string $pParams['iforce'] takes following optins: icon, icon_text, text - will override system settings
* @param string $pFile Path to icon file
* @param string iforce override site-wide setting how to display icons (can be set to 'icon', 'text' or 'icon_text')
* @return Full <img> on success
$iexplain = isset ( $pParams["iexplain"] ) ? tra( $pParams["iexplain"] ) : 'please set iexplain';
if( empty( $pParams['iforce'] )) {
$pParams['iforce'] = NULL;
if( isset ( $pParams["url"] )) {
if(( $gBitSystem->getConfig( 'site_biticon_display_style' ) == 'text' || $pParams['iforce'] == 'text' ) && $pParams['iforce'] != 'icon' ) {
$outstr= '<img src="'. $pFile. '"';
if( isset ( $pParams["iexplain"] ) ) {
$outstr .= ' alt="'. tra( $pParams["iexplain"] ). '" title="'. tra( $pParams["iexplain"] ). '"';
$ommit = array( 'ilocation', 'ipackage', 'ipath', 'iname', 'iexplain', 'iforce', 'istyle', 'iclass' );
foreach( $pParams as $name => $val ) {
$outstr .= ' '. $name. '="'. $val. '"';
if( !isset ( $pParams["iclass"] ) ) {
$outstr .= ' class="icon"';
$outstr .= ' class="'. $pParams["iclass"]. '"';
if( isset ( $pParams["onclick"] ) ) {
$outstr .= ' onclick="'. $pParams["onclick"]. '"';
if( $gBitSystem->getConfig( 'site_biticon_display_style' ) == 'icon_text' && $pParams['iforce'] != 'icon' || $pParams['iforce'] == 'icon_text' ) {
$outstr .= ' '. $iexplain;
echo tra( 'There was a problem writing the icon cache file' );
* smarty_function_biticon
* @param array $pParams['ipath'] subdirectory within icon directory
* @param array $pParams['iname'] name of the icon without extension
* @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'
* @param array $gBitSmarty Referenced object
global $gBitSystem, $gBitThemes, $gSniffer;
// this is needed in case everything goes horribly wrong
// ensure that ipath has a leading and trailing slash
if( !empty( $pParams['ipath'] )) {
$pParams['ipath'] = str_replace( "//", "/", "/". $pParams['ipath']. "/" );
// try to separate iname from ipath if we've been given some sloppy naming
if( strstr( $pParams['iname'], '/' )) {
$pParams['iname'] = $pParams['ipath']. $pParams['iname'];
$boom = explode( '/', $pParams['iname'] );
// if we don't have an ipath yet, we will set it here
if( $pParams['ipath'] == '/' ) {
// iforce is generally only set in menus - we might need a parameter to identify menus more accurately
if( !empty( $pParams['ilocation'] )) {
if( $pParams['ilocation'] == 'menu' ) {
$pParams['ipath'] .= 'small/';
$pParams['iforce'] = 'icon_text';
} elseif( $pParams['ilocation'] == 'quicktag' ) {
$pParams['ipath'] .= 'small/';
$pParams['iforce'] = 'icon';
$pParams['iclass'] = 'quicktag icon';
if( !empty( $pParams['isize'] )) {
$pParams['ipath'] .= $pParams['isize']. '/';
$pParams['ipath'] .= $gBitSystem->getConfig( 'site_icon_size', 'small' ). '/';
// this only happens when we haven't found the original icon we've been looking for
$pParams['ipath'] = preg_replace( "!/.*?/$!", "/small/", $pParams['ipath'] );
// we have one special case: pkg_icons don't have a size variant
if( strstr( $pParams['iname'], 'pkg_' ) && !strstr( $pParams['ipath'], 'small' )) {
$pParams['ipath'] = preg_replace( "!/.*?/$!", "/", $pParams['ipath'] );
// make sure ipackage is set correctly
if( !empty( $pParams['ipackage'] )) {
$pParams['ipackage'] = strtolower( $pParams['ipackage'] );
$pParams['ipackage'] = 'icons';
// if the user is using a text-browser we force text instead of icons
if( $gSniffer->_browser_info['browser'] == 'lx' || $gSniffer->_browser_info['browser'] == 'li' ) {
$pParams['iforce'] = 'text';
// get out of here as quickly as possible if we've already cached the icon information before
// first deal with most common scenario: icon style ( a selected iconset from config/iconsets/ )
if( $pParams['ipackage'] == 'icons' ) {
// get the current icon style
// istyle is a private parameter!!! - only used on theme manager page for icon preview!!!
// violators will be poked with soft cushions by the Cardinal himself!!!
$icon_style = !empty( $pParams['istyle'] ) ? $pParams['istyle'] : $gBitSystem->getConfig( 'site_icon_style', DEFAULT_ICON_STYLE );
return biticon_output( $pParams, CONFIG_PKG_URL. "iconsets/$icon_style". $pParams['ipath']. $matchFile );
if( $icon_style != DEFAULT_ICON_STYLE && FALSE !== ( $matchFile = biticon_first_match( CONFIG_PKG_PATH. "iconsets/". DEFAULT_ICON_STYLE. $pParams['ipath'], $pParams['iname'] ))) {
return biticon_output( $pParams, CONFIG_PKG_URL. "iconsets/". DEFAULT_ICON_STYLE. $pParams['ipath']. $matchFile );
// if that didn't work, we'll try liberty
$pParams['ipath'] = '/'. $gBitSystem->getConfig( 'site_icon_size', 'small' ). '/';
$pParams['ipackage'] = 'liberty';
// since package icons reside in <pkg>/icons/ we don't need the small/ subdir
if( strstr( "/small/", $pParams['ipath'] )) {
$pParams['ipath'] = str_replace( "small/", "", $pParams['ipath'] );
// first check themes/force
//if we have site styles, look there
if( FALSE !== ( $matchFile = biticon_first_match( $gBitThemes->getStylePath(). '/icons/'. $pParams['ipackage']. $pParams['ipath'], $pParams['iname'] ))) {
return biticon_output( $pParams, $gBitThemes->getStyleUrl(). '/icons/'. $pParams['ipackage']. $pParams['ipath']. $matchFile );
//Well, then lets look in the package location
// Still didn't find it! Well lets output something (return FALSE if only the url is requested)
if( isset ( $pParams['url'] )) {
// if we were looking for the large icon, we'll try the whole kaboodle again, looking for the small icon
if( empty( $small ) && !$pCheckSmall ) {
return biticon_output( $pParams, "broken.icon.". $pParams['ipackage']. "/". $pParams['ipath']. $pParams['iname'] );
* @return cached icon string on sucess, FALSE on failure
if( $h = fopen( $cacheFile, 'r' )) {
* @return TRUE on success, FALSE on failure
if( $h = fopen( $cacheFile, 'w' )) {
$ret = fwrite( $h, $pCacheString );
* will get the path to the cache files based on the stuff in $pParams
* @return full path to cachefile
global $gBitThemes, $gBitSystem;
// create a hash filename based on the parameters given
$ihash = array( 'iforce', 'ipath', 'iname', 'iexplain', 'ipackage', 'url', 'istyle', 'id', 'style', 'onclick' );
foreach( $pParams as $param => $value ) {
// return path to cache file
return $gBitThemes->getIconCachePath(). md5( $hashstring. $gBitSystem->getConfig( 'site_biticon_display_style', 'icon' ));
|