\n
" . htmlentities($val, ENT_COMPAT, 'UTF-8') . "\n"; } } return $val; } /** * Show a debugging message * * @param string $message * @param bool $showHeader */ public static function message($message, $showHeader = true) { if (!Director::isLive()) { $caller = Debug::caller(); $file = basename($caller['file']); if (Director::is_cli()) { if ($showHeader) { echo "Debug (line $caller[line] of $file):\n "; } echo $message . "\n"; } else { echo " \n"; } } } /** * Create an instance of an appropriate DebugView object. * * @return DebugView */ public static function create_debug_view() { $service = Director::is_cli() || Director::is_ajax() ? 'SilverStripe\\Dev\\CliDebugView' : 'SilverStripe\\Dev\\DebugView'; return Injector::inst()->get($service); } /** * Check if the user has permissions to run URL debug tools, * else redirect them to log in. */ public static function require_developer_login() { if (Director::isDev()) { return; } if (isset($_SESSION['loggedInAs'])) { // We have to do some raw SQL here, because this method is called in Object::defineMethods(). // This means we have to be careful about what objects we create, as we don't want Object::defineMethods() // being called again. // This basically calls Permission::checkMember($_SESSION['loggedInAs'], 'ADMIN'); // @TODO - Rewrite safely using DataList::filter $memberID = $_SESSION['loggedInAs']; $permission = DB::prepared_query( ' SELECT "ID" FROM "Permission" INNER JOIN "Group_Members" ON "Permission"."GroupID" = "Group_Members"."GroupID" WHERE "Permission"."Code" = ? AND "Permission"."Type" = ? AND "Group_Members"."MemberID" = ?', array( 'ADMIN', // Code Permission::GRANT_PERMISSION, // Type $memberID // MemberID ) )->value(); if ($permission) { return; } } // This basically does the same as // Security::permissionFailure(null, "You need to login with developer access to make use of debugging tools.") // We have to do this because of how early this method is called in execution. $_SESSION['SilverStripe\\Security\\Security']['Message']['message'] = "You need to login with developer access to make use of debugging tools."; $_SESSION['SilverStripe\\Security\\Security']['Message']['type'] = 'warning'; $_SESSION['BackURL'] = $_SERVER['REQUEST_URI']; header($_SERVER['SERVER_PROTOCOL'] . " 302 Found"); header("Location: " . Director::baseURL() . Security::login_url()); die(); } }