/**
  * Answers a string containing the custom CSS for the CMS interface.
  *
  * @return string
  */
 public function getAwesomeIconCSS()
 {
     // Initialise Variables:
     $css = array();
     // Obtain Default ModelAdmin Icon:
     $dma_icon = Config::inst()->get('ModelAdmin', 'menu_icon', Config::FIRST_SET);
     // Obtain Viewable Menu Items:
     $menu_items = CMSMenu::get_viewable_menu_items();
     // Iterate Viewable Menu Items:
     foreach ($menu_items as $class => $item) {
         // Obtain Bitmap Icon:
         $bmp_icon = Config::inst()->get($class, 'menu_icon', Config::FIRST_SET);
         // Does this class have an awesome icon?
         if ($icon = Config::inst()->get($class, 'awesome_icon', Config::FIRST_SET)) {
             // Fix the prefix of the icon class name:
             $icon = $this->prefix($icon);
         } elseif ($class == 'Help') {
             // The icon for the Help menu item:
             $icon = 'fa-question-circle';
         } elseif ($bmp_icon == $dma_icon) {
             // Replace default ModelAdmin icon:
             $icon = 'fa-database';
         } else {
             // By default, fallback to the bitmap icon:
             $icon = false;
         }
         // Define CSS for this icon:
         if ($icon) {
             // Disable Bitmap Icon:
             $css[] = ".icon.icon-16.icon-" . strtolower($class) . " {";
             $css[] = "  background-image: none !important;";
             $css[] = "}";
             // Enable Awesome Icon:
             $css[] = ".icon.icon-16.icon-" . strtolower($class) . ":before {";
             $css[] = "  content: \"\\" . $this->getIconUnicode($icon) . "\";";
             $css[] = "}";
         }
     }
     // Answer CSS String:
     return implode("\n", $css);
 }
 /**
  * Answers a string containing the custom CSS for the CMS interface.
  *
  * @return string
  */
 public function getAwesomeIconCSS()
 {
     // Initialise Variables:
     $css = array();
     $menu_items = CMSMenu::get_viewable_menu_items();
     // Iterate Viewable Menu Items:
     foreach ($menu_items as $class => $item) {
         // Does this class have an awesome icon?
         if ($icon = Config::inst()->get($class, 'icon', Config::FIRST_SET)) {
             // Fix the prefix of the icon class name:
             $icon = $this->prefix($icon);
         } elseif ($class == 'Help') {
             // The icon for the Help menu item:
             $icon = 'help_outline';
         } else {
             // The default icon, for ModelAdmin menu items:
             $icon = 'content_copy';
         }
         // Define CSS for this icon:
         $css[] = ".icon.icon-16.icon-" . strtolower($class) . ":before { content: \"\\" . self::$icons[$icon] . "\"; }";
     }
     // Answer CSS String:
     return implode("\n", $css);
 }
Ejemplo n.º 3
0
 /**
  * Returns the main menu of the CMS.  This is also used by init() 
  * to work out which sections the user has access to.
  * 
  * @param Boolean
  * @return SS_List
  */
 public function MainMenu($cached = true)
 {
     if (!isset($this->_cache_MainMenu) || !$cached) {
         // Don't accidentally return a menu if you're not logged in - it's used to determine access.
         if (!Member::currentUser()) {
             return new ArrayList();
         }
         // Encode into DO set
         $menu = new ArrayList();
         $menuItems = CMSMenu::get_viewable_menu_items();
         // extra styling for custom menu-icons
         $menuIconStyling = '';
         if ($menuItems) {
             foreach ($menuItems as $code => $menuItem) {
                 // alternate permission checks (in addition to LeftAndMain->canView())
                 if (isset($menuItem->controller) && $this->hasMethod('alternateMenuDisplayCheck') && !$this->alternateMenuDisplayCheck($menuItem->controller)) {
                     continue;
                 }
                 $linkingmode = "link";
                 if ($menuItem->controller && get_class($this) == $menuItem->controller) {
                     $linkingmode = "current";
                 } else {
                     if (strpos($this->Link(), $menuItem->url) !== false) {
                         if ($this->Link() == $menuItem->url) {
                             $linkingmode = "current";
                             // default menu is the one with a blank {@link url_segment}
                         } else {
                             if (singleton($menuItem->controller)->stat('url_segment') == '') {
                                 if ($this->Link() == $this->stat('url_base') . '/') {
                                     $linkingmode = "current";
                                 }
                             } else {
                                 $linkingmode = "current";
                             }
                         }
                     }
                 }
                 // already set in CMSMenu::populate_menu(), but from a static pre-controller
                 // context, so doesn't respect the current user locale in _t() calls - as a workaround,
                 // we simply call LeftAndMain::menu_title_for_class() again
                 // if we're dealing with a controller
                 if ($menuItem->controller) {
                     $defaultTitle = LeftAndMain::menu_title_for_class($menuItem->controller);
                     $title = _t("{$menuItem->controller}.MENUTITLE", $defaultTitle);
                 } else {
                     $title = $menuItem->title;
                 }
                 // Provide styling for custom $menu-icon. Done here instead of in
                 // CMSMenu::populate_menu(), because the icon is part of
                 // the CMS right pane for the specified class as well...
                 if ($menuItem->controller) {
                     $menuIcon = LeftAndMain::menu_icon_for_class($menuItem->controller);
                     if (!empty($menuIcon)) {
                         $menuIconStyling .= $menuIcon;
                     }
                 }
                 $menu->push(new ArrayData(array("MenuItem" => $menuItem, "Title" => Convert::raw2xml($title), "Code" => DBField::create_field('Text', $code), "Link" => $menuItem->url, "LinkingMode" => $linkingmode)));
             }
         }
         if ($menuIconStyling) {
             Requirements::customCSS($menuIconStyling);
         }
         $this->_cache_MainMenu = $menu;
     }
     return $this->_cache_MainMenu;
 }
Ejemplo n.º 4
0
 /**
  * Returns the main menu of the CMS.  This is also used by init() 
  * to work out which sections the user has access to.
  * 
  * @return DataObjectSet
  */
 public function MainMenu()
 {
     // Don't accidentally return a menu if you're not logged in - it's used to determine access.
     if (!Member::currentUser()) {
         return new DataObjectSet();
     }
     // Encode into DO set
     $menu = new DataObjectSet();
     $menuItems = CMSMenu::get_viewable_menu_items();
     if ($menuItems) {
         foreach ($menuItems as $code => $menuItem) {
             // alternate permission checks (in addition to LeftAndMain->canView())
             if (isset($menuItem->controller) && $this->hasMethod('alternateMenuDisplayCheck') && !$this->alternateMenuDisplayCheck($menuItem->controller)) {
                 continue;
             }
             $linkingmode = "";
             if (strpos($this->Link(), $menuItem->url) !== false) {
                 if ($this->Link() == $menuItem->url) {
                     $linkingmode = "current";
                     // default menu is the one with a blank {@link url_segment}
                 } else {
                     if (singleton($menuItem->controller)->stat('url_segment') == '') {
                         if ($this->Link() == $this->stat('url_base') . '/') {
                             $linkingmode = "current";
                         }
                     } else {
                         $linkingmode = "current";
                     }
                 }
             }
             // already set in CMSMenu::populate_menu(), but from a static pre-controller
             // context, so doesn't respect the current user locale in _t() calls - as a workaround,
             // we simply call LeftAndMain::menu_title_for_class() again
             // if we're dealing with a controller
             if ($menuItem->controller) {
                 $defaultTitle = LeftAndMain::menu_title_for_class($menuItem->controller);
                 $title = _t("{$menuItem->controller}.MENUTITLE", $defaultTitle);
             } else {
                 $title = $menuItem->title;
             }
             $menu->push(new ArrayData(array("MenuItem" => $menuItem, "Title" => Convert::raw2xml($title), "Code" => $code, "Link" => $menuItem->url, "LinkingMode" => $linkingmode)));
         }
     }
     // if no current item is found, assume that first item is shown
     //if(!isset($foundCurrent))
     return $menu;
 }
 /**
  * Returns Silvercart specific menus.
  * 
  * @return ArrayList
  *
  * @author Sascha Koehler <*****@*****.**>,
  *         Sebastian Diel <*****@*****.**>
  * @since 28.02.2013
  */
 public function SilvercartMenus()
 {
     $silvercartMenus = new ArrayList();
     $menuItems = CMSMenu::get_viewable_menu_items();
     $hiddenMenus = SilvercartConfig::getHiddenRegisteredMenus();
     foreach (SilvercartConfig::getRegisteredMenus() as $menu) {
         if (in_array($menu['code'], $hiddenMenus)) {
             continue;
         }
         $modelAdmins = new ArrayList();
         foreach ($menuItems as $code => $menuItem) {
             if (isset($menuItem->controller) && $this->owner->hasMethod('alternateMenuDisplayCheck') && !$this->owner->alternateMenuDisplayCheck($menuItem->controller)) {
                 continue;
             }
             if (empty($menuItem->controller)) {
                 continue;
             }
             if (in_array($menuItem->controller, self::$model_admins_to_ignore)) {
                 continue;
             }
             $menuCode = Config::inst()->get($menuItem->controller, 'menuCode');
             $menuSection = Config::inst()->get($menuItem->controller, 'menuSection');
             $menuSortIndex = Config::inst()->get($menuItem->controller, 'menuSortIndex');
             $url_segment = Config::inst()->get($menuItem->controller, 'url_segment');
             if ($menuCode == $menu['code'] || is_null($menuCode) && $menu['code'] == 'default') {
                 $defaultTitle = LeftAndMain::menu_title_for_class($menuItem->controller);
                 $title = _t("{$menuItem->controller}.MENUTITLE", $defaultTitle);
                 $linkingmode = "";
                 if (strpos($this->owner->Link(), $menuItem->url) !== false) {
                     if ($this->owner->Link() == $menuItem->url) {
                         $linkingmode = "current";
                         // default menu is the one with a blank {@link url_segment}
                     } elseif ($url_segment == '') {
                         if ($this->owner->Link() == $this->owner->stat('url_base') . '/') {
                             $linkingmode = "current";
                         }
                     } else {
                         $linkingmode = "current";
                     }
                 }
                 if (empty($menuSection)) {
                     $menuSection = 'base';
                 }
                 if (empty($menuSortIndex)) {
                     $menuSortIndex = 1000;
                 }
                 $modelAdmins->push(new ArrayData(array("MenuItem" => $menuItem, "Title" => Convert::raw2xml($title), "Code" => $code, 'MenuCode' => $menu['code'], "IsSection" => false, "Section" => $menuSection, "SortIndex" => $menuSortIndex, "Link" => $menuItem->url, "LinkingMode" => $linkingmode)));
                 unset($menuItems[$code]);
             }
         }
         $modelAdmins = $modelAdmins->sort('SortIndex', 'ASC');
         if ($modelAdmins->exists()) {
             $menu['name'] = _t('SilvercartStoreAdminMenu.' . strtoupper($menu['code']), $menu['name']);
             $silvercartMenus->push(new DataObject(array('name' => $menu['name'], 'code' => $menu['code'], 'Code' => $menu['code'], 'ModelAdmins' => $modelAdmins)));
         }
     }
     return $silvercartMenus;
 }
Ejemplo n.º 6
0
 public static function all_accessible_sites($includeMainSite = true, $mainSiteTitle = "Main site", $member = null)
 {
     // Rationalise member arguments
     if (!$member) {
         $member = Member::currentUser();
     }
     if (!$member) {
         return new ArrayList();
     }
     if (!is_object($member)) {
         $member = DataObject::get_by_id('Member', $member);
     }
     $subsites = new ArrayList();
     // Collect subsites for all sections.
     $menu = CMSMenu::get_viewable_menu_items();
     foreach ($menu as $candidate) {
         if ($candidate->controller) {
             $accessibleSites = singleton($candidate->controller)->sectionSites($includeMainSite, $mainSiteTitle, $member);
             // Replace existing keys so no one site appears twice.
             $subsites->merge($accessibleSites);
         }
     }
     $subsites->removeDuplicates();
     return $subsites;
 }