本文整理汇总了PHP中ErrorPage::get方法的典型用法代码示例。如果您正苦于以下问题:PHP ErrorPage::get方法的具体用法?PHP ErrorPage::get怎么用?PHP ErrorPage::get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ErrorPage
的用法示例。
在下文中一共展示了ErrorPage::get方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testLinkShortcodeHandler
public function testLinkShortcodeHandler()
{
$testFile = $this->objFromFixture('File', 'asdf');
$parser = new ShortcodeParser();
$parser->register('file_link', array('File', 'link_shortcode_handler'));
$fileShortcode = sprintf('[file_link,id=%d]', $testFile->ID);
$fileEnclosed = sprintf('[file_link,id=%d]Example Content[/file_link]', $testFile->ID);
$fileShortcodeExpected = $testFile->Link();
$fileEnclosedExpected = sprintf('<a href="%s" class="file" data-type="txt" data-size="977 KB">Example Content</a>', $testFile->Link());
$this->assertEquals($fileShortcodeExpected, $parser->parse($fileShortcode), 'Test that simple linking works.');
$this->assertEquals($fileEnclosedExpected, $parser->parse($fileEnclosed), 'Test enclosed content is linked.');
$testFile->delete();
$fileShortcode = '[file_link,id="-1"]';
$fileEnclosed = '[file_link,id="-1"]Example Content[/file_link]';
$this->assertEquals('', $parser->parse('[file_link]'), 'Test that invalid ID attributes are not parsed.');
$this->assertEquals('', $parser->parse('[file_link,id="text"]'));
$this->assertEquals('', $parser->parse('[file_link]Example Content[/file_link]'));
if (class_exists('ErrorPage')) {
$errorPage = ErrorPage::get()->filter('ErrorCode', 404)->First();
$this->assertEquals($errorPage->Link(), $parser->parse($fileShortcode), 'Test link to 404 page if no suitable matches.');
$this->assertEquals(sprintf('<a href="%s">Example Content</a>', $errorPage->Link()), $parser->parse($fileEnclosed));
} else {
$this->assertEquals('', $parser->parse($fileShortcode), 'Short code is removed if file record is not present.');
$this->assertEquals('', $parser->parse($fileEnclosed));
}
}
示例2: requireDefaultRecords
/**
* Ensures that there is always a 404 page by checking if there's an
* instance of ErrorPage with a 404 and 500 error code. If there is not,
* one is created when the DB is built.
*/
public function requireDefaultRecords()
{
parent::requireDefaultRecords();
if ($this->class === 'ErrorPage' && SiteTree::config()->create_default_pages) {
$defaultPages = $this->getDefaultRecords();
foreach ($defaultPages as $defaultData) {
$code = $defaultData['ErrorCode'];
$page = ErrorPage::get()->filter('ErrorCode', $code)->first();
$pageExists = !empty($page);
if (!$pageExists) {
$page = new ErrorPage($defaultData);
$page->write();
$page->publish('Stage', 'Live');
}
// Check if static files are enabled
if (!self::config()->enable_static_file) {
continue;
}
// Ensure this page has cached error content
$success = true;
if (!$page->hasStaticPage()) {
// Update static content
$success = $page->writeStaticPage();
} elseif ($pageExists) {
// If page exists and already has content, no alteration_message is displayed
continue;
}
if ($success) {
DB::alteration_message(sprintf('%s error page created', $code), 'created');
} else {
DB::alteration_message(sprintf('%s error page could not be created. Please check permissions', $code), 'error');
}
}
}
}
示例3: getByLink
public function getByLink($url)
{
if (!($page = Page::get_by_link($url))) {
$page = ErrorPage::get()->filter('ErrorCode', 404)->first();
}
$data = array('timepstamp' => time(), 'page' => $page->forAPI());
return $data;
}
示例4: onBeforeHTTPError
/**
* Retrieve the correct error page for the current multisite instance.
* @param integer
* @param SS_HTTPRequest
* @throws SS_HTTPResponse_Exception
*/
public function onBeforeHTTPError($code, $request)
{
$errorPage = ErrorPage::get()->filter(array('ErrorCode' => $code, 'SiteID' => Multisites::inst()->getCurrentSiteId()))->first();
if ($errorPage) {
Requirements::clear();
Requirements::clear_combined_files();
$response = ModelAsController::controller_for($errorPage)->handleRequest($request, DataModel::inst());
throw new SS_HTTPResponse_Exception($response, $code);
}
}
开发者ID:helpfulrobot,项目名称:sheadawson-silverstripe-multisites,代码行数:16,代码来源:MultisitesControllerExtension.php
示例5: requireDefaultRecords
public function requireDefaultRecords()
{
if (Config::inst()->get('UniversalErrorPage', 'ConvertOnDevBuild')) {
$ErrorPages = ErrorPage::get()->filter('ClassName', 'ErrorPage');
foreach ($ErrorPages as $ErrorPage) {
$ErrorPage->ClassName = 'UniversalErrorPage';
$ErrorPage->write();
$ErrorPage->doPublish();
DB::alteration_message("#{$ErrorPage->ID} {$ErrorPage->Title} changed to UniversalErrorPage.", "changed");
}
}
}
示例6: response_for
/**
* Get a {@link SS_HTTPResponse} to response to a HTTP error code if an
* {@link ErrorPage} for that code is present. First tries to serve it
* through the standard SilverStripe request method. Falls back to a static
* file generated when the user hit's save and publish in the CMS
*
* @param int $statusCode
*
* @return SS_HTTPResponse
*/
public static function response_for($statusCode)
{
// first attempt to dynamically generate the error page
$errorPage = ErrorPage::get()->filter(array("ErrorCode" => $statusCode))->first();
if ($errorPage) {
Requirements::clear();
Requirements::clear_combined_files();
return ModelAsController::controller_for($errorPage)->handleRequest(new SS_HTTPRequest('GET', ''), DataModel::inst());
}
// then fall back on a cached version
$cachedPath = self::get_filepath_for_errorcode($statusCode, class_exists('Translatable') ? Translatable::get_current_locale() : null);
if (file_exists($cachedPath)) {
$response = new SS_HTTPResponse();
$response->setStatusCode($statusCode);
$response->setBody(file_get_contents($cachedPath));
return $response;
}
}
示例7: handle
public static function handle($arguments, $content, ShortcodeParser $parser, $tag, array $extra = array())
{
if (!empty($arguments['id'])) {
$document = DMSDocument::get()->byID($arguments['id']);
if ($document && !$document->isHidden()) {
if ($content) {
return sprintf('<a href="%s">%s</a>', $document->Link(), $parser->parse($content));
} else {
if (isset($extra['element'])) {
$extra['element']->setAttribute('data-ext', $document->getExtension());
$extra['element']->setAttribute('data-size', $document->getFileSizeFormatted());
}
return $document->Link();
}
}
}
$error = ErrorPage::get()->filter('ErrorCode', '404')->First();
if ($error) {
return $error->Link();
}
return '';
}
示例8: httpError
/**
* Display an error page on invalid request.
*
* @parameter <{ERROR_CODE}> integer
* @parameter <{ERROR_MESSAGE}> string
*/
public function httpError($code, $message = null)
{
// Determine the error page for the given status code.
$errorPages = ClassInfo::exists('SiteTree') ? ErrorPage::get()->filter('ErrorCode', $code) : null;
// Allow extension customisation.
$this->extend('updateErrorPages', $errorPages);
// Retrieve the error page response.
if ($errorPages && ($errorPage = $errorPages->first())) {
Requirements::clear();
Requirements::clear_combined_files();
$response = ModelAsController::controller_for($errorPage)->handleRequest(new SS_HTTPRequest('GET', ''), DataModel::inst());
throw new SS_HTTPResponse_Exception($response, $code);
} else {
if ($errorPages && file_exists($cachedPage = ErrorPage::get_filepath_for_errorcode($code, class_exists('Translatable') ? Translatable::get_current_locale() : null))) {
$response = new SS_HTTPResponse();
$response->setStatusCode($code);
$response->setBody(file_get_contents($cachedPage));
throw new SS_HTTPResponse_Exception($response, $code);
} else {
return parent::httpError($code, $message);
}
}
}
示例9: link_shortcode_handler
/**
* Replace "[file_link id=n]" shortcode with an anchor tag or link to the file.
* @param $arguments array Arguments to the shortcode
* @param $content string Content of the returned link (optional)
* @param $parser object Specify a parser to parse the content (see {@link ShortCodeParser})
* @return string anchor HTML tag if content argument given, otherwise file path link
*/
public static function link_shortcode_handler($arguments, $content = null, $parser = null)
{
if (!isset($arguments['id']) || !is_numeric($arguments['id'])) {
return;
}
$record = DataObject::get_by_id('File', $arguments['id']);
if (!$record) {
if (class_exists('ErrorPage')) {
$record = ErrorPage::get()->filter("ErrorCode", 404)->first();
}
if (!$record) {
return;
}
// There were no suitable matches at all.
}
// build the HTML tag
if ($content) {
// build some useful meta-data (file type and size) as data attributes
$attrs = ' ';
if ($record instanceof File) {
foreach (array('class' => 'file', 'data-type' => $record->getExtension(), 'data-size' => $record->getSize()) as $name => $value) {
$attrs .= sprintf('%s="%s" ', $name, $value);
}
}
return sprintf('<a href="%s"%s>%s</a>', $record->Link(), rtrim($attrs), $parser->parse($content));
} else {
return $record->Link();
}
}
示例10: canView
/**
* Checks if a user can view the page
*
* The user can view the current page if:
* - They have the VIEW_DRAFT_CONTENT permission or
* - The current time is after the Embargo time (if set) and before the Expiry time (if set)
*
* @param Member $member
* @return boolean
*/
public function canView($member = null)
{
// if CMS user with sufficient rights:
if (Permission::check("VIEW_DRAFT_CONTENT")) {
//if(Permission::checkMember($member, 'VIEW_EMBARGOEXPIRY')) {
return true;
}
// Debug::dump($this->owner->URLSegment." "
// . $this->owner->Embargo . " "
// . date('d-M-Y h:i', strtotime($this->owner->Embargo))
// . " - " . $this->owner->Expiry);
// if on front, controller should be a subclass of ContentController (ties it to CMS, = ok...)
$ctr = Controller::curr();
if (is_subclass_of($ctr, "ContentController")) {
if ($this->owner->getScheduledStatus() || $this->owner->getExpiredStatus()) {
// if $this->owner is the actual page being visited (Director::get_current_page());
$curpage = Director::get_current_page();
if ($curpage->ID == $this->owner->ID) {
// we have to prevent visitors from actually visiting this page by redirecting to a 404
// This is a bit of a hack (redirect), but else visitors will be presented with a
// 'login' screen in order to acquire sufficient privileges to view the page)
$errorPage = ErrorPage::get()->filter('ErrorCode', 404)->first();
if ($errorPage) {
$ctr->redirect($errorPage->Link(), 404);
} else {
// fallback (hack): redirect to anywhere, with a 404
$ctr->redirect(rtrim($this->owner->Link(), '/') . "-404", 404);
//$ctr->redirect(Page::get()->first()->Link(), 404);
}
}
return false;
} else {
return true;
}
}
// else, allow
return true;
}
示例11: init
/**
* Diese Funktion wird beim Initialisieren ausgeführt
*
* @param string $skip param only added because it exists on parent::init()
* to avoid strict notice
*
* @return void
*
* @author Sebastian Diel <sdiel@pixeltricks.de>,
* Sascha Koehler <skoehler@pixeltricks.de>
* @since 23.06.2014
*/
public function init($skip = false)
{
SilvercartProduct::addExtendedSortableFrontendFields(array('relevance' => _t('SilvercartSearchResultsPage.RELEVANCESORT')));
parent::init(true);
if ($this->isProductDetailView()) {
// product detail views are not possible on SilvercartSearchResultsPage
$this->redirect(ErrorPage::get()->filter('ErrorCode', '404')->first()->Link());
}
$this->searchObjectHandler();
}
示例12: CheckoutLink
/**
* returns the link to finalise the Order
* @return String(URLSegment)
*/
function CheckoutLink()
{
$page = CheckoutPage::get()->First();
if ($page) {
return $page->Link();
} else {
$page = ErrorPage::get()->Filter(array("ErrorCode" => '404'))->First();
if ($page) {
return $page->Link();
}
}
}
示例13: viewversion
/**
* Action to return specific version of a product.
* This is really useful for sold products where you want to retrieve the actual version that you sold.
* @TODO: this is not correct yet, as the versions of product and productvariation are muddled up!
* @param HTTPRequest $request
*/
function viewversion($request)
{
$version = intval($request->param("ID"));
$product = $this->Product();
if ($product) {
$this->redirect($product->Link("viewversion/" . $product->ID . "/" . $version . "/"));
} else {
$page = ErrorPage::get()->Filter(array("ErrorCode" => '404'))->First();
if ($page) {
$this->redirect($page->Link());
return;
}
}
return array();
}
示例14: rerenderErrorPages
/**
* Re-renders the ErrorPage templates
*
* @return void
*
* @author Sebastian Diel <sdiel@pixeltricks.de>
* @since 04.06.2012
*/
public function rerenderErrorPages()
{
$errorPages = ErrorPage::get();
if ($errorPages->exists()) {
SilvercartConfig::$forceLoadingOfDefaultLayout = true;
foreach ($errorPages as $errorPage) {
$errorPage->doPublish();
}
SilvercartConfig::$forceLoadingOfDefaultLayout = false;
}
}
示例15: submittedbuyable
/**
* allows us to view out-dated buyables that have been deleted
* where only old versions exist.
* this method should redirect
* @param SS_HTTPRequest
* @return REDIRECT
*/
function submittedbuyable(SS_HTTPRequest $request)
{
$buyableClassName = Convert::raw2sql($this->getRequest()->param('ID'));
$buyableID = intval($this->getRequest()->param('OtherID'));
$version = intval($this->getRequest()->param('Version'));
if ($buyableClassName && $buyableID) {
if (EcommerceDBConfig::is_buyable($buyableClassName)) {
$bestBuyable = $buyableClassName::get()->byID($buyableID);
if ($bestBuyable instanceof ProductVariation) {
$link = $bestBuyable->Link("filterforvariations/" . $buyableID . "/?version=" . $version . "/");
$this->redirect($link);
return array();
}
if ($bestBuyable) {
//show singleton with old version
$link = $bestBuyable->Link("viewversion/" . $version . "/");
$this->redirect($link);
return array();
}
}
}
$errorPage404 = ErrorPage::get()->Filter(array("ErrorCode" => "404"))->First();
if ($errorPage404) {
return $this->redirect($errorPage404->Link());
}
return null;
}