YiiFoundation
  • Namespace
  • Class
  • Tree

Namespaces

  • foundation
    • enum
    • exception
    • helpers
    • widgets
      • base
  • PHP

Classes

  • Alert
  • ArrayHelper
  • Button
  • Foundation
  • Html
  • Icon
  • Nav
  • Panel
  • Pricing
  • Progress
  • Typo
 1 <?php
 2 /**
 3  * @copyright Copyright &copy; 2amigOS! Consulting Group 2013-
 4  * @license http://www.opensource.org/licenses/bsd-license.php New BSD License
 5  * @package foundation.components
 6  * @version 1.0.0
 7  */
 8 
 9 namespace foundation\helpers;
10 
11 use foundation\enum\Enum;
12 
13 /**
14  * Icon helper contains methods to work with Foundation icons -ie assets registrations (fonts), icon rendering.
15  *
16  * @author Antonio Ramirez <amigo.cobos@gmail.com>
17  * @package foundation\helpers
18  */
19 class Icon
20 {
21     /**
22      * Generates an icon.
23      * @param string $icon the icon type.
24      * @param array $htmlOptions additional HTML attributes.
25      * @param string $tagName the icon HTML tag.
26      * @return string the generated icon.
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      * Registers a specific Icon Set. They are registered individually
42      * @param $fontName
43      * @param $forceCopyAssets
44      * @return bool
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      * Returns foundation available sets
64      * @return array the available sets
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 }
YiiFoundation API documentation generated by ApiGen 2.8.0