From 92458d9f43abb91f16e9901897e204518d7bc194 Mon Sep 17 00:00:00 2001 From: Ingo Schommer Date: Mon, 18 Feb 2013 14:41:49 +0100 Subject: [PATCH] Fixed line lengths --- control/HTTP.php | 16 ++++++++-------- control/HTTPResponse.php | 9 +++++++-- dev/Debug.php | 10 +++++++++- forms/Form.php | 4 +++- model/fieldtypes/HTMLText.php | 18 ++++++++++++++---- security/Member.php | 3 ++- 6 files changed, 43 insertions(+), 17 deletions(-) diff --git a/control/HTTP.php b/control/HTTP.php index 08fc73575..ae3b9e43d 100644 --- a/control/HTTP.php +++ b/control/HTTP.php @@ -288,7 +288,8 @@ class HTTP { $responseHeaders["Cache-Control"] = "max-age=" . self::$cache_age . ", must-revalidate, no-transform"; $responseHeaders["Pragma"] = ""; - // To do: User-Agent should only be added in situations where you *are* actually varying according to user-agent. + // To do: User-Agent should only be added in situations where you *are* actually + // varying according to user-agent. $responseHeaders['Vary'] = 'Cookie, X-Forwarded-Protocol, User-Agent, Accept'; } else { @@ -298,13 +299,12 @@ class HTTP { if(self::$modification_date && self::$cache_age > 0) { $responseHeaders["Last-Modified"] = self::gmt_date(self::$modification_date); - /* Chrome ignores Varies when redirecting back (http://code.google.com/p/chromium/issues/detail?id=79758) - which means that if you log out, you get redirected back to a page which Chrome then checks against last-modified (which passes, getting a 304) - when it shouldn't be trying to use that page at all because it's the "logged in" version. - - By also using and etag that includes both the modification date and all the varies values which we also check against we can catch - this and not return a 304 - */ + // Chrome ignores Varies when redirecting back (http://code.google.com/p/chromium/issues/detail?id=79758) + // which means that if you log out, you get redirected back to a page which Chrome then checks against + // last-modified (which passes, getting a 304) + // when it shouldn't be trying to use that page at all because it's the "logged in" version. + // By also using and etag that includes both the modification date and all the varies + // values which we also check against we can catch this and not return a 304 $etagParts = array(self::$modification_date, serialize($_COOKIE)); if (isset($_SERVER['HTTP_X_FORWARDED_PROTOCOL'])) $etagParts[] = $_SERVER['HTTP_X_FORWARDED_PROTOCOL']; if (isset($_SERVER['HTTP_USER_AGENT'])) $etagParts[] = $_SERVER['HTTP_USER_AGENT']; diff --git a/control/HTTPResponse.php b/control/HTTPResponse.php index 447da3c40..39de0580b 100644 --- a/control/HTTPResponse.php +++ b/control/HTTPResponse.php @@ -151,7 +151,8 @@ class SS_HTTPResponse { public function setBody($body) { $this->body = $body; - // Set content-length in bytes. Use mbstring to avoid problems with mb_internal_encoding() and mbstring.func_overload + // Set content-length in bytes. Use mbstring to avoid problems with + // mb_internal_encoding() and mbstring.func_overload $this->headers['Content-Length'] = mb_strlen($this->body,'8bit'); } @@ -232,7 +233,11 @@ class SS_HTTPResponse { } else { // It's critical that these status codes are sent; we need to report a failure if not. if($this->statusCode >= 300) { - user_error("Couldn't set response type to $this->statusCode because of output on line $line of $file", E_USER_WARNING); + user_error( + "Couldn't set response type to $this->statusCode because " . + "of output on line $line of $file", + E_USER_WARNING + ); } } diff --git a/dev/Debug.php b/dev/Debug.php index e29ee24ff..0decb7913 100644 --- a/dev/Debug.php +++ b/dev/Debug.php @@ -248,7 +248,15 @@ class Debug { ini_set('display_errors', 0); if(self::$send_warnings_to) { - return self::emailError(self::$send_warnings_to, $errno, $errstr, $errfile, $errline, $errcontext, "Warning"); + return self::emailError( + self::$send_warnings_to, + $errno, + $errstr, + $errfile, + $errline, + $errcontext, + "Warning" + ); } // Send out the error details to the logger for writing diff --git a/forms/Form.php b/forms/Form.php index 1f30b1371..151a7d371 100644 --- a/forms/Form.php +++ b/forms/Form.php @@ -715,7 +715,9 @@ class Form extends RequestHandler { $needsCacheDisabled = false; if ($this->getSecurityToken()->isEnabled()) $needsCacheDisabled = true; if ($this->FormMethod() != 'get') $needsCacheDisabled = true; - if (!($this->validator instanceof RequiredFields) || count($this->validator->getRequired())) $needsCacheDisabled = true; + if (!($this->validator instanceof RequiredFields) || count($this->validator->getRequired())) { + $needsCacheDisabled = true; + } // If we need to disable cache, do it if ($needsCacheDisabled) HTTP::set_cache_age(0); diff --git a/model/fieldtypes/HTMLText.php b/model/fieldtypes/HTMLText.php index 54e0ac9d6..47ddf62b3 100644 --- a/model/fieldtypes/HTMLText.php +++ b/model/fieldtypes/HTMLText.php @@ -144,11 +144,21 @@ class HTMLText extends Text { */ public function exists() { // If it's blank, it's blank - if(!parent::exists()) return false; + if(!parent::exists()) { + return false; + } + // If it's got a content tag - if(preg_match('/<(img|embed|object|iframe)[^>]*>/i', $this->value)) return true; - // If it's just one or two tags on its own (and not the above) it's empty. This might be

or

or whatever. - if(preg_match('/^[\\s]*(<[^>]+>[\\s]*){1,2}$/', $this->value)) return false; + if(preg_match('/<(img|embed|object|iframe)[^>]*>/i', $this->value)) { + return true; + } + + // If it's just one or two tags on its own (and not the above) it's empty. + // This might be

or

or whatever. + if(preg_match('/^[\\s]*(<[^>]+>[\\s]*){1,2}$/', $this->value)) { + return false; + } + // Otherwise its content is genuine content return true; } diff --git a/security/Member.php b/security/Member.php index ac61473a5..055083087 100644 --- a/security/Member.php +++ b/security/Member.php @@ -426,7 +426,8 @@ class Member extends DataObject implements TemplateGlobalProvider { Cookie::set('alc_enc', null); // // Clear the Remember Me cookie Cookie::forceExpiry('alc_enc'); - // Switch back to live in order to avoid infinite loops when redirecting to the login screen (if this login screen is versioned) + // Switch back to live in order to avoid infinite loops when + // redirecting to the login screen (if this login screen is versioned) Session::clear('readingMode'); $this->write();