1 <?php
2 3 4 5 6 7
8
9 namespace foundation\helpers;
10
11 use foundation\enum\Enum;
12
13 14 15 16 17 18
19 class Icon
20 {
21 22 23 24 25 26 27
28 public static function icon($icon, $htmlOptions = array(), $tagName = 'i')
29 {
30 if (is_string($icon)) {
31 if (strpos($icon, 'foundicon-') === false) {
32 $icon = 'foundicon-' . implode(' foundicon-', array_unique(explode(' ', $icon)));
33 }
34 ArrayHelper::addValue('class', $icon, $htmlOptions);
35 return \CHtml::openTag($tagName, $htmlOptions) . \CHtml::closeTag($tagName);
36 }
37 return '';
38 }
39
40 41 42 43 44 45
46 public static function registerIconFontSet($fontName, $forceCopyAssets = false)
47 {
48 if (!in_array($fontName, static::getAvailableIconFontSets())) {
49 return false;
50 }
51
52 $fontPath = \Yii::getPathOfAlias('foundation.fonts.foundation_icons_' . $fontName);
53 $fontUrl = \Yii::app()->assetManager->publish($fontPath, true, -1, $forceCopyAssets);
54
55 \Yii::app()->clientScript->registerCssFile($fontUrl . "/stylesheets/{$fontName}_foundicons.css");
56
57 if (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE 7.0')) {
58 \Yii::app()->clientScript->registerCssFile($fontUrl . "/stylesheets/{$fontName}_foundicons_ie7.css");
59 }
60 }
61
62 63 64 65
66 public static function getAvailableIconFontSets()
67 {
68 return array(
69 Enum::ICONS_SET_ACCESSIBILITY,
70 Enum::ICONS_SET_GENERAL,
71 Enum::ICONS_SET_GENERAL_ENCLOSED,
72 Enum::ICONS_SET_SOCIAL
73 );
74 }
75 }