/** * Returns the main menu of the CMS. This is also used by init() * to work out which sections the user has access to. * * @param bool $cached * @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) { /** @var CMSMenuItem $menuItem */ 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() == AdminRootController::admin_url()) { $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() again // if we're dealing with a controller if ($menuItem->controller) { $title = LeftAndMain::menu_title($menuItem->controller); } 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, "AttributesHTML" => $menuItem->getAttributesHTML(), "Title" => Convert::raw2xml($title), "Code" => $code, "Icon" => strtolower($code), "Link" => $menuItem->url, "LinkingMode" => $linkingmode))); } } if ($menuIconStyling) { Requirements::customCSS($menuIconStyling); } $this->_cache_MainMenu = $menu; } return $this->_cache_MainMenu; }
/** * Encode an email-address to help protect it from spam bots. At the moment only simple string substitutions, which * are not 100% safe from email harvesting. * * @todo Integrate javascript-based solution * * @param string $email Email-address * @param string $method Method for obfuscating/encoding the address * - 'direction': Reverse the text and then use CSS to put the text direction back to normal * - 'visible': Simple string substitution ('@' to '[at]', '.' to '[dot], '-' to [dash]) * - 'hex': Hexadecimal URL-Encoding - useful for mailto: links * @return string */ public static function obfuscate($email, $method = 'visible') { switch ($method) { case 'direction': Requirements::customCSS('span.codedirection { unicode-bidi: bidi-override; direction: rtl; }', 'codedirectionCSS'); return '<span class="codedirection">' . strrev($email) . '</span>'; case 'visible': $obfuscated = array('@' => ' [at] ', '.' => ' [dot] ', '-' => ' [dash] '); return strtr($email, $obfuscated); case 'hex': $encoded = ''; for ($x = 0; $x < strlen($email); $x++) { $encoded .= '&#x' . bin2hex($email[$x]) . ';'; } return $encoded; default: user_error('Email::obfuscate(): Unknown obfuscation method', E_USER_NOTICE); return $email; } }