コード例 #1
0
ファイル: Awecms.php プロジェクト: rfjaimes/awegen
 public static function typeOf($var)
 {
     if (is_string($var)) {
         if (preg_match('/^[a-zA-Z0-9_.-]+@[a-zA-Z0-9-]+.[a-zA-Z0-9-.]+$/', $var)) {
             return 'email';
         }
         //if url
         if (Awecms::isUrl($var)) {
             //check for image url
             // Parse the url into individual components
             $url_parse = parse_url($var);
             // could be any kind of weird site like an ftp or something, restrict to http and https
             if ($url_parse['scheme'] == 'http' || $url_parse['scheme'] == 'https') {
                 // basename() strips off any preceding directories
                 if (isset($url_parse["path"])) {
                     $file = pathinfo(basename($url_parse["path"]));
                 }
                 if (isset($file['extension']) && in_array($file['extension'], array('jpg', 'png', 'gif', 'jpeg'))) {
                     return 'image_url';
                 }
             }
             return 'url';
         }
         return 'textfield';
     }
     return gettype($var);
 }
コード例 #2
0
ファイル: Share.php プロジェクト: awecode/awecms
 public function run()
 {
     $iconsDir = Yii::app()->assetManager->publish(__DIR__ . DIRECTORY_SEPARATOR . 'icons', false, -1);
     $rep = array('url' => $this->url, 'text' => $this->text, 'via' => $this->via);
     foreach ($this->networks as $name => $network) {
         if (!in_array(strtolower($name), array_map('strtolower', $this->shareTo))) {
             continue;
         }
         $url = str_replace(array_map('self::maskit', array_keys($rep)), array_values($rep), $network['format']);
         if (Awecms::isUrl($network['icon'])) {
             $icon = $network['icon'];
         } else {
             $icon = $iconsDir . '/' . $network['icon'];
         }
         $str = '<a href="' . $url . '"';
         if ($this->openInNewTab) {
             $str .= ' target="_blank"';
         }
         $str .= 'title="' . $network['tip'] . '"><img src="' . $icon . '" alt="' . $name . '"></a>';
         echo $str;
     }
     parent::run();
 }
コード例 #3
0
ファイル: MenuRenderer.php プロジェクト: awecode/awecms
 protected function renderMenuRecursive($items)
 {
     $count = 0;
     $n = count($items);
     foreach ($items as $item) {
         if ($item == array()) {
             continue;
         }
         $visible = FALSE;
         //handle roles here
         if (isset($item['role'])) {
             $roles = explode(',', $item['role']);
             if (in_array('all', $roles)) {
                 $visible = TRUE;
             } else {
                 if (Yii::app()->user->isGuest && in_array('guest', $roles)) {
                     $visible = TRUE;
                 } else {
                     if (Yii::app()->user->id && in_array('loggedIn', $roles)) {
                         $visible = TRUE;
                     } else {
                         if (Yii::app()->getModule('user')->isAdmin() && in_array('super', $roles)) {
                             $visible = TRUE;
                         } else {
                             if (Yii::app()->hasModule('role')) {
                                 foreach ($roles as $role) {
                                     if (Role::is($role)) {
                                         $visible = TRUE;
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         } else {
             $visible = TRUE;
         }
         //makes menu items visible if they have no roles index, e.g. with appended menu items
         if (!$visible) {
             continue;
         }
         $class = array();
         //handle links here
         if (isset($item['url'])) {
             //we use $link for finding if current menu item is active
             $link = $item['url'];
             if (Awecms::isUrl($item['url'])) {
                 //NOP
             } else {
                 if (substr($item['url'], 0, 2) == '//') {
                     //convert //foo to /foo
                     $item['url'] = substr($item['url'], 1);
                 } else {
                     if ($item['url'] == '/') {
                         $item['url'] = Yii::app()->baseUrl ? Yii::app()->baseUrl : '/';
                     } else {
                         $item['url'] = array($item['url']);
                     }
                 }
             }
         }
         if (isset($item['url'])) {
             $link = ltrim($link, '/');
             if ($link == Yii::app()->request->pathInfo) {
                 $class[] = $this->activeCssClass;
             }
         }
         $count++;
         $options = isset($item['itemOptions']) ? $item['itemOptions'] : array();
         //            if ($item['active'] && $this->activeCssClass != '')
         //                $class[] = $this->activeCssClass;
         if ($count === 1 && $this->firstItemCssClass != '') {
             $class[] = $this->firstItemCssClass;
         }
         if ($count === $n && $this->lastItemCssClass != '') {
             $class[] = $this->lastItemCssClass;
         }
         if ($class !== array()) {
             if (empty($options['class'])) {
                 $options['class'] = implode(' ', $class);
             } else {
                 $options['class'] .= ' ' . implode(' ', $class);
             }
         }
         echo CHtml::openTag('li', $options);
         if (isset($item['items']) && count($item['items'])) {
             if (empty($options['class'])) {
                 $options['class'] = ' ' . $this->dirCssClass;
             } else {
                 $options['class'] .= ' ' . $this->dirCssClass;
             }
         }
         //handle open-in-in-new-tab
         if (isset($item['target'])) {
             $options['target'] = $item['target'];
         }
         //set description as title
         if (isset($item['description'])) {
             $options['title'] = $item['description'];
         }
         $options['itemprop'] = 'url';
         $item['linkOptions'] = $options;
         $menu = $this->renderMenuItem($item);
         if (isset($this->itemTemplate) || isset($item['template'])) {
             $template = isset($item['template']) ? $item['template'] : $this->itemTemplate;
             echo strtr($template, array('{menu}' => $menu));
         } else {
             echo $menu;
         }
         if (isset($item['items']) && count($item['items'])) {
             echo "\n" . CHtml::openTag('ul', isset($item['submenuOptions']) ? $item['submenuOptions'] : $this->submenuHtmlOptions) . "\n";
             $this->renderMenuRecursive($item['items']);
             echo CHtml::closeTag('ul') . "\n";
         }
         echo CHtml::closeTag('li') . "\n";
     }
 }