* * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ /** * This plugin allows you to easily include icons in your app. * Assuming you have a master repository of icons, sfIcon will * resize and cache your thumbnails using sfThumbnailCache. * * @package sfIcon * @author Jon Todd */ class sfIcon { /** * Width of the icon thumbnail in pixels * @access private * @var int */ private $width; /** * Height of the icon thumbnail in pixels * @access private * @var int */ private $height; /** * Name of master image * @access private * @var string */ private $masterImage; /** * Thumbnail constructor * @param string Master image name * @param int (optional) width * @param int (optional) height * @access public */ public function __construct($img,$w = null ,$h = null) { $this->masterImage = $img; $this->width = $w; $this->height = $h; } /** * Return url of the icon thumbnail relative to the web root * * @author Jon Todd */ public function getIcon() { // Get the full path to the base dir, by default this is the web root $baseDir = sfConfig::get('sf_icon_base_dir'); // Get icon paths relative to webroot $thumb = sfConfig::get('sf_icon_thumbnail_dir').'/'.$this->masterImage; $master = $baseDir.sfConfig::get('sf_icon_master_dir').'/'.$this->masterImage; $type = $this->getType(); return sfThumbnailCache::getNewInstance($master, $this->width,$this->height,true,true, $type['mime'],$this->stripExt($thumb).$type['ext'])->getURL(); } /** * If browser doesn't support default type then use gif */ private function getType() { $brows = sfBrowserDetect::getBrowser(); if(strtolower($brows['browser']) == 'ie' && $brows['majorver'] != '7') { return array('mime' => 'image/gif','ext' => '.gif'); } return array('mime' => sfConfig::get('sf_icon_thumb_mime'), 'ext' => sfConfig::get('sf_icon_thumb_ext')); } /** * Remove file extension from filename */ private function stripExt($f) { return substr($f, 0, strrpos($f, '.')); } } ?>