From 8ece5302f7021c22d2d614fa6e1323df42dca6db Mon Sep 17 00:00:00 2001 From: Ingo Schommer Date: Mon, 17 Dec 2007 21:49:49 +0000 Subject: [PATCH] Merged revisions 37547 via svnmerge from svn://svn.silverstripe.com/silverstripe/modules/sapphire/branches/2.0.1-uplay ........ r37547 | ischommer | 2007-06-29 12:36:56 +1200 (Fri, 29 Jun 2007) | 1 line added blocking ........ git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@47197 467b73ca-7a2a-4603-9d3b-597d59a354a9 --- core/Requirements.php | 42 ++++++++++++++++++++++++++++++++++++------ 1 file changed, 36 insertions(+), 6 deletions(-) diff --git a/core/Requirements.php b/core/Requirements.php index ea055cd04..7e76e14da 100644 --- a/core/Requirements.php +++ b/core/Requirements.php @@ -11,6 +11,7 @@ class Requirements { private static $customCSS = array(); private static $customHeadTags = ""; private static $disabled = array(); + private static $blocked = array(); /** * Register the given javascript file as required. @@ -132,6 +133,35 @@ class Requirements { } } + /** + * Needed to actively prevent the inclusion of a file, + * e.g. when using your own prototype.js. + * Blocking should only be used as an exception, because + * it is hard to trace back. You can just block items with an + * ID, so make sure you add an unique identifier to customCSS() and customScript(). + * + * @param string $fileOrID + */ + static function block($fileOrID) { + self::$blocked[$fileOrID] = $fileOrID; + } + + /** + * Removes an item from the blocking-list. + * CAUTION: Does not "re-add" any previously blocked elements. + * @param string $fileOrID + */ + static function unblock($fileOrID) { + unset(self::$blocked[$fileOrID]); + } + + /** + * Removes all items from the blocking-list. + */ + static function unblock_all() { + self::$blocked = array(); + } + /** * Restore requirements cleared by call to Requirements::clear */ @@ -154,30 +184,30 @@ class Requirements { $prefix = ""; $requirements = ''; - foreach(Requirements::$javascript as $file => $dummy) { + foreach(array_diff_key(self::$javascript,self::$blocked) as $file => $dummy) { if(substr($file,0,7) == 'http://' || Director::fileExists($file)) { $requirements .= "\n"; } } - if(Requirements::$customScript) { + if(self::$customScript) { $requirements .= "\n"; } - foreach(Requirements::$css as $file => $params) { + foreach(array_diff_key(self::$css,self::$blocked) as $file => $params) { if(Director::fileExists($file)) { $media = (isset($params['media'])) ? " media=\"{$params['media']}\"" : ""; $requirements .= "\n"; } } - foreach(Requirements::$customCSS as $css) { + foreach(array_diff_key(self::$customCSS,self::$blocked) as $css) { $requirements .= "\n"; } - $requirements .= Requirements::$customHeadTags; + $requirements .= self::$customHeadTags; if(isset($_GET['debug_profile'])) Profiler::unmark("Requirements::includeInHTML"); return eregi_replace("(]*>)", $requirements . "\\1", $content);