public function output() { // TODO: Refactor into a content-type option if (\Director::is_ajax()) { return $this->friendlyErrorMessage; } else { // TODO: Refactor this into CMS if (class_exists('ErrorPage')) { $errorFilePath = \ErrorPage::get_filepath_for_errorcode($this->statusCode, class_exists('Translatable') ? \Translatable::get_current_locale() : null); if (file_exists($errorFilePath)) { $content = file_get_contents($errorFilePath); if (!headers_sent()) { header('Content-Type: text/html'); } // $BaseURL is left dynamic in error-###.html, so that multi-domain sites don't get broken return str_replace('$BaseURL', \Director::absoluteBaseURL(), $content); } } $renderer = \Debug::create_debug_view(); $output = $renderer->renderHeader(); $output .= $renderer->renderInfo("Website Error", $this->friendlyErrorMessage, $this->friendlyErrorDetail); if (\Email::config()->admin_email) { $mailto = \Email::obfuscate(\Email::config()->admin_email); $output .= $renderer->renderParagraph('Contact an administrator: ' . $mailto . ''); } $output .= $renderer->renderFooter(); return $output; } }
public function testObfuscate() { $emailAddress = '*****@*****.**'; $direction = Email::obfuscate($emailAddress, 'direction'); $visible = Email::obfuscate($emailAddress, 'visible'); $hex = Email::obfuscate($emailAddress, 'hex'); $this->assertEquals('<span class="codedirection">moc.elpmaxe@1-tset</span>', $direction, 'obfuscate() correctly reverses the email direction'); $this->assertEquals('test [dash] 1 [at] example [dot] com', $visible, 'obfuscate() correctly obfuscates email characters'); $this->assertEquals('test-1@examp' . 'le.com', $hex, 'obfuscate() correctly returns hex representation of email'); }
/** * Return the obfuscated email */ public function ObfuscatedEmail() { return $this->Email ? Email::obfuscate($this->Email, 'hex') : null; }
/** * Render a user-facing error page, using the default HTML error template * rendered by {@link ErrorPage} if it exists. Doesn't use the standard {@link SS_HTTPResponse} class * the keep dependencies minimal. * * @uses ErrorPage * * @param int $statusCode HTTP Status Code (Default: 500) * @param string $friendlyErrorMessage User-focused error message. Should not contain code pointers * or "tech-speak". Used in the HTTP Header and ajax responses. * @param string $friendlyErrorDetail Detailed user-focused message. Is just used if no {@link ErrorPage} is found * for this specific status code. * @return string HTML error message for non-ajax requests, plaintext for ajax-request. */ public static function friendlyError($statusCode = 500, $friendlyErrorMessage = null, $friendlyErrorDetail = null) { if (!$friendlyErrorMessage) { $friendlyErrorMessage = Config::inst()->get('Debug', 'friendly_error_header'); } if (!$friendlyErrorDetail) { $friendlyErrorDetail = Config::inst()->get('Debug', 'friendly_error_detail'); } if (!headers_sent()) { $currController = Controller::has_curr() ? Controller::curr() : null; // Ensure the error message complies with the HTTP 1.1 spec $msg = strip_tags(str_replace(array("\n", "\r"), '', $friendlyErrorMessage)); if ($currController) { $response = $currController->getResponse(); $response->setStatusCode($statusCode, $msg); } else { header($_SERVER['SERVER_PROTOCOL'] . " {$statusCode} {$msg}"); } } if (Director::is_ajax()) { echo $friendlyErrorMessage; } else { if (class_exists('ErrorPage')) { $errorFilePath = ErrorPage::get_filepath_for_errorcode($statusCode, class_exists('Translatable') ? Translatable::get_current_locale() : null); if (file_exists($errorFilePath)) { $content = file_get_contents(ASSETS_PATH . "/error-{$statusCode}.html"); // $BaseURL is left dynamic in error-###.html, so that multi-domain sites don't get broken echo str_replace('$BaseURL', Director::absoluteBaseURL(), $content); } } else { $renderer = new DebugView(); $renderer->writeHeader(); $renderer->writeInfo("Website Error", $friendlyErrorMessage, $friendlyErrorDetail); if (Email::config()->admin_email) { $mailto = Email::obfuscate(Email::config()->admin_email); $renderer->writeParagraph('Contact an administrator: ' . $mailto . ''); } $renderer->writeFooter(); } } return false; }
/** * Email encoded in html character entities. * * @return string */ public function EncodedEmail() { // return CleanUtils::html_obfuscate($this->owner->Email); return Email::obfuscate($this->owner->Email, 'hex'); }
/** * Render a user-facing error page, using the default HTML error template * rendered by {@link ErrorPage} if it exists. Doesn't use the standard {@link SS_HTTPResponse} class * the keep dependencies minimal. * * @uses ErrorPage * * @param int $statusCode HTTP Status Code (Default: 500) * @param string $friendlyErrorMessage User-focused error message. Should not contain code pointers or "tech-speak". * Used in the HTTP Header and ajax responses. * @param string $friendlyErrorDetail Detailed user-focused message. Is just used if no {@link ErrorPage} is found * for this specific status code. * @return string HTML error message for non-ajax requests, plaintext for ajax-request. */ static function friendlyError($statusCode = 500, $friendlyErrorMessage = null, $friendlyErrorDetail = null) { if (!$friendlyErrorMessage) { $friendlyErrorMessage = self::$friendly_error_header; } if (!$friendlyErrorDetail) { $friendlyErrorDetail = self::$friendly_error_detail; } if (!headers_sent()) { header(sprintf('%s %d %s', $_SERVER['SERVER_PROTOCOL'], $statusCode, strip_tags(str_replace(array("\n", "\r"), '', $friendlyErrorMessage)))); } if (Director::is_ajax()) { echo $friendlyErrorMessage; } else { $errorFilePath = ErrorPage::get_filepath_for_errorcode($statusCode, Translatable::get_current_locale()); if (file_exists($errorFilePath)) { $content = file_get_contents(ASSETS_PATH . "/error-{$statusCode}.html"); // $BaseURL is left dynamic in error-###.html, so that multi-domain sites don't get broken echo str_replace('$BaseURL', Director::absoluteBaseURL(), $content); } else { $renderer = new DebugView(); $renderer->writeHeader(); $renderer->writeInfo("Website Error", $friendlyErrorMessage, $friendlyErrorDetail); if (Email::getAdminEmail()) { $mailto = Email::obfuscate(Email::getAdminEmail()); $renderer->writeParagraph('Contact an administrator: ' . $mailto . ''); } $renderer->writeFooter(); } } }
/** * Return the appropriate error content for the given status code * * @param int $statusCode * @return string Content in an appropriate format for the current request */ public function output($statusCode) { // TODO: Refactor into a content-type option if (\Director::is_ajax()) { return $this->getTitle(); } $renderer = \Debug::create_debug_view(); $output = $renderer->renderHeader(); $output .= $renderer->renderInfo("Website Error", $this->getTitle(), $this->getBody()); if (\Email::config()->admin_email) { $mailto = \Email::obfuscate(\Email::config()->admin_email); $output .= $renderer->renderParagraph('Contact an administrator: ' . $mailto . ''); } $output .= $renderer->renderFooter(); return $output; }
/** * Render a user-facing error page, using the default HTML error template * rendered by {@link ErrorPage} if it exists. Doesn't use the standard {@link HTTPResponse} class * the keep dependencies minimal. * * @uses ErrorPage * * @param int $statusCode HTTP Status Code (Default: 500) * @param string $friendlyErrorMessage User-focused error message. Should not contain code pointers or "tech-speak". * Used in the HTTP Header and ajax responses. * @param string $friendlyErrorDetail Detailed user-focused message. Is just used if no {@link ErrorPage} is found * for this specific status code. * @return string HTML error message for non-ajax requests, plaintext for ajax-request. */ static function friendlyError($statusCode = 500, $friendlyErrorMessage = null, $friendlyErrorDetail = null) { if (!$friendlyErrorMessage) { $friendlyErrorMessage = 'There has been an error'; } if (!$friendlyErrorDetail) { $friendlyErrorDetail = 'The website server has not been able to respond to your request.'; } if (!headers_sent()) { header($_SERVER['SERVER_PROTOCOL'] . " {$statusCode} {$friendlyErrorMessage}"); } if (Director::is_ajax()) { echo $friendlyErrorMessage; } else { $errorFilePath = ErrorPage::get_filepath_for_errorcode($statusCode, Translatable::get_current_locale()); if (file_exists($errorFilePath)) { echo file_get_contents($errorFilePath); } else { $renderer = new DebugView(); $renderer->writeHeader(); $renderer->writeInfo("Website Error", $friendlyErrorMessage, $friendlyErrorDetail); if (Email::getAdminEmail()) { $mailto = Email::obfuscate(Email::getAdminEmail()); $renderer->writeParagraph('Contact an administrator: ' . $mailto . ''); } $renderer->writeFooter(); } } }
/** * Render a user-facing error page, using the default HTML error template * rendered by {@link ErrorPage} if it exists. Doesn't use the standard {@link HTTPResponse} class * the keep dependencies minimal. * * @uses ErrorPage * * @param int $statusCode HTTP Status Code (Default: 500) * @param string $friendlyErrorMessage User-focused error message. Should not contain code pointers or "tech-speak". * Used in the HTTP Header and ajax responses. * @param string $friendlyErrorDetail Detailed user-focused message. Is just used if no {@link ErrorPage} is found * for this specific status code. * @return string HTML error message for non-ajax requests, plaintext for ajax-request. */ static function friendlyError($statusCode = 500, $friendlyErrorMessage = null, $friendlyErrorDetail = null) { if(!$friendlyErrorMessage) $friendlyErrorMessage = 'There has been an error'; if(!$friendlyErrorDetail) $friendlyErrorDetail = 'The website server has not been able to respond to your request.'; if(!headers_sent()) header($_SERVER['SERVER_PROTOCOL'] . " $statusCode $friendlyErrorMessage"); if(Director::is_ajax()) { echo $friendlyErrorMessage; } else { if(file_exists(ASSETS_PATH . "/error-$statusCode.html")) { echo file_get_contents(ASSETS_PATH . "/error-$statusCode.html"); } else { $renderer = new DebugView(); $renderer->writeHeader(); $renderer->writeInfo("Website Error", $friendlyErrorMessage, $friendlyErrorDetail); if(Email::getAdminEmail()) { $mailto = Email::obfuscate(Email::getAdminEmail()); $renderer->writeParagraph('Contact an administrator: ' . $mailto . ''); } $renderer->writeFooter(); } } }
/** * Render a user-facing error page, using the default HTML error template * rendered by {@link ErrorPage} if it exists. Doesn't use the standard {@link SS_HTTPResponse} class * the keep dependencies minimal. * * @uses ErrorPage * * @param int $statusCode HTTP Status Code (Default: 500) * @param string $friendlyErrorMessage User-focused error message. Should not contain code pointers * or "tech-speak". Used in the HTTP Header and ajax responses. * @param string $friendlyErrorDetail Detailed user-focused message. Is just used if no {@link ErrorPage} is found * for this specific status code. * @return string HTML error message for non-ajax requests, plaintext for ajax-request. */ public static function friendlyError($statusCode = 500, $friendlyErrorMessage = null, $friendlyErrorDetail = null) { // Ensure the error message complies with the HTTP 1.1 spec if (!$friendlyErrorMessage) { $friendlyErrorMessage = Config::inst()->get('Debug', 'friendly_error_header'); } $friendlyErrorMessage = strip_tags(str_replace(array("\n", "\r"), '', $friendlyErrorMessage)); if (!$friendlyErrorDetail) { $friendlyErrorDetail = Config::inst()->get('Debug', 'friendly_error_detail'); } if (!headers_sent()) { // Allow toggle between legacy behaviour and correctly setting HTTP response code // In 4.0 this should be fixed to always set this response code. if (Config::inst()->get('Debug', 'friendly_error_httpcode') || !Controller::has_curr()) { header($_SERVER['SERVER_PROTOCOL'] . " {$statusCode} {$friendlyErrorMessage}"); } } if (Director::is_ajax()) { echo $friendlyErrorMessage; } else { if (!headers_sent()) { header('Content-Type: text/html'); } if (class_exists('ErrorPage')) { $errorFilePath = ErrorPage::get_filepath_for_errorcode($statusCode, class_exists('Translatable') ? Translatable::get_current_locale() : null); if (file_exists($errorFilePath)) { $content = file_get_contents($errorFilePath); // $BaseURL is left dynamic in error-###.html, so that multi-domain sites don't get broken echo str_replace('$BaseURL', Director::absoluteBaseURL(), $content); } } else { $renderer = new DebugView(); $renderer->writeHeader(); $renderer->writeInfo("Website Error", $friendlyErrorMessage, $friendlyErrorDetail); if (Email::config()->admin_email) { $mailto = Email::obfuscate(Email::config()->admin_email); $renderer->writeParagraph('Contact an administrator: ' . $mailto . ''); } $renderer->writeFooter(); } } return false; }
/** * Returns a representation of this text * with all email addresses converted into html character entities. * * @return string */ public function EmailObfuscated() { $content = $this->owner->forTemplate(); $emailPattern = "/[A-Za-z0-9_-]+@[A-Za-z0-9_-]+\\.([A-Za-z0-9_-][A-Za-z0-9_]+)/"; if (preg_match_all($emailPattern, $content, $matches)) { $searches = array(); $replaces = array(); for ($i = 0; $i < count($matches[0]); $i++) { $link = $matches[0][$i]; $obfuscatedLink = Email::obfuscate($link, 'hex'); array_push($searches, $link); array_push($replaces, $obfuscatedLink); } $content = str_replace($searches, $replaces, $content); } return $content; }