-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
1,050 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
Contao Page 410 | ||
====================== | ||
|
||
[![](https://img.shields.io/packagist/v/numero2/contao-page-410.svg?style=flat-square)](https://packagist.org/packages/numero2/contao-page-410) [![License: LGPL v3](https://img.shields.io/badge/License-LGPL%20v3-blue.svg?style=flat-square)](http://www.gnu.org/licenses/lgpl-3.0) | ||
|
||
About | ||
-- | ||
|
||
This extension adds a new page type for "410 Gone". | ||
|
||
|
||
System requirements | ||
-- | ||
|
||
* [Contao 4.13](https://github.com/contao/contao) or [Contao 5.3](https://github.com/contao/contao) (or newer) | ||
|
||
|
||
Installation | ||
-- | ||
|
||
* Install via Contao Manager or Composer (`composer require numero2/contao-page-410`) | ||
* In `public/.htaccess` add the following line to route 410 errors to Contao: | ||
``` | ||
ErrorDocument 410 /index.php | ||
``` | ||
* To specify which URL's should return a 410 page, add some proper redirects as well | ||
``` | ||
Redirect 410 /this-page/is-gone.html | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
{ | ||
"name": "numero2/contao-page-410", | ||
"type": "contao-module", | ||
"description": "Adds a new page type for 410 Gone", | ||
"license": "LGPL-3.0+", | ||
"authors": [{ | ||
"name": "numero2 - Agentur für digitales Marketing GbR", | ||
"homepage": "http://www.numero2.de" | ||
} | ||
], | ||
"require": { | ||
"contao/core-bundle": "^4.13 || ^5.0" | ||
}, | ||
"require-dev": { | ||
"contao/manager-plugin": "^2.0" | ||
}, | ||
"conflict": { | ||
"contao/core": "*", | ||
"contao/manager-plugin": "<2.0 || >=3.0" | ||
}, | ||
"extra": { | ||
"contao-manager-plugin": "numero2\\Page410Bundle\\ContaoManager\\Plugin" | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"numero2\\Page410Bundle\\": "src/" | ||
}, | ||
"classmap": [ | ||
"contao/" | ||
], | ||
"exclude-from-classmap": [ | ||
"contao/config/", | ||
"contao/dca/", | ||
"contao/languages/", | ||
"contao/templates/" | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
services: | ||
_defaults: | ||
autoconfigure: true | ||
|
||
_instanceof: | ||
Contao\CoreBundle\Controller\AbstractController: | ||
tags: | ||
- { name: container.service_subscriber, id: contao.csrf.token_manager } | ||
|
||
|
||
numero2\Page410Bundle\Controller\Page\GonePageController: | ||
arguments: | ||
- '@contao.framework' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
services: | ||
_defaults: | ||
autoconfigure: true | ||
|
||
|
||
numero2\Page410Bundle\EventListener\DataContainer\PageListener: | ||
arguments: | ||
- '@database_connection' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
services: | ||
|
||
numero2_page410.route_410_provider: | ||
decorates: contao.routing.route_404_provider | ||
class: numero2\Page410Bundle\Routing\Route410Provider | ||
arguments: | ||
- '@numero2_page410.route_410_provider.inner' | ||
- '@contao.framework' | ||
- '@contao.routing.locale_candidates' | ||
- '@Contao\CoreBundle\Routing\Page\PageRegistry' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
|
||
/** | ||
* Page 410 bundle for Contao Open Source CMS | ||
* | ||
* @author Benny Born <benny.born@numero2.de> | ||
* @author Michael Bösherz <michael.boesherz@numero2.de> | ||
* @license Commercial | ||
* @copyright Copyright (c) 2024, numero2 - Agentur für digitales Marketing GbR | ||
*/ | ||
|
||
|
||
use numero2\Page410Bundle\PageError410; | ||
|
||
|
||
/** | ||
* PAGE TYPES | ||
*/ | ||
$GLOBALS['TL_PTY']['error_410'] = PageError410::class; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
|
||
/** | ||
* Page 410 bundle for Contao Open Source CMS | ||
* | ||
* @author Benny Born <benny.born@numero2.de> | ||
* @author Michael Bösherz <michael.boesherz@numero2.de> | ||
* @license Commercial | ||
* @copyright Copyright (c) 2024, numero2 - Agentur für digitales Marketing GbR | ||
*/ | ||
|
||
|
||
/** | ||
* Add palettes to tl_page | ||
*/ | ||
$GLOBALS['TL_DCA']['tl_page']['palettes']['error_410'] = '{title_legend},title,type;{meta_legend},pageTitle,robots,description;{forward_legend},autoforward;{layout_legend:hide},includeLayout;{cache_legend:hide},includeCache;{chmod_legend:hide},includeChmod;{expert_legend:hide},cssClass;{publish_legend},published,start,stop'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?xml version="1.0" ?> | ||
<xliff version="1.1"> | ||
<file> | ||
<body> | ||
<trans-unit id="PTY.error_410.0"> | ||
<target>410 Nicht mehr verfügbar</target> | ||
</trans-unit> | ||
<trans-unit id="PTY.error_410.1"> | ||
<target>Ruft ein Besucher eine Seite auf, die nicht länger bereitgestellt und dauerhaft entfernt wurde, wird stattdessen eine 410-Fehlerseite geladen.</target> | ||
</trans-unit> | ||
</body> | ||
</file> | ||
</xliff> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?xml version="1.0" ?> | ||
<xliff version="1.1"> | ||
<file> | ||
<body> | ||
<trans-unit id="PTY.error_410.0"> | ||
<target>410 Gone</target> | ||
</trans-unit> | ||
<trans-unit id="PTY.error_410.1"> | ||
<target>If a visitor requests a page that is no longer available and that this condition is likely to be permanent, a 410 error page will be loaded instead.</target> | ||
</trans-unit> | ||
</body> | ||
</file> | ||
</xliff> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<?php | ||
|
||
/** | ||
* Page 410 bundle for Contao Open Source CMS | ||
* | ||
* @author Benny Born <benny.born@numero2.de> | ||
* @author Michael Bösherz <michael.boesherz@numero2.de> | ||
* @license Commercial | ||
* @copyright Copyright (c) 2024, numero2 - Agentur für digitales Marketing GbR | ||
*/ | ||
|
||
|
||
namespace numero2\Page410Bundle; | ||
|
||
use Contao\Date; | ||
use Contao\PageModel as CorePageModel; | ||
|
||
|
||
class PageModel extends CorePageModel { | ||
|
||
|
||
/** | ||
* Table name | ||
* @var string | ||
*/ | ||
protected static $strTable = 'tl_page'; | ||
|
||
|
||
/** | ||
* Find an error 410 page by its parent ID | ||
* | ||
* @param integer $intPid | ||
* @param array $arrOptions | ||
* | ||
* @return Contao\PageModel|null The model or null if there is no 403 page | ||
*/ | ||
public static function find410ByPid( $intPid, array $arrOptions=[] ) { | ||
|
||
$t = static::$strTable; | ||
$arrColumns = ["$t.pid=? AND $t.type='error_410'"]; | ||
|
||
if( !static::isPreviewMode($arrOptions) ) { | ||
$time = Date::floorToMinute(); | ||
$arrColumns[] = "$t.published='1' AND ($t.start='' OR $t.start<='$time') AND ($t.stop='' OR $t.stop>'$time')"; | ||
} | ||
|
||
if( !isset($arrOptions['order']) ) { | ||
$arrOptions['order'] = "$t.sorting"; | ||
} | ||
|
||
return static::findOneBy($arrColumns, $intPid, $arrOptions); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
<?php | ||
|
||
/** | ||
* Page 410 bundle for Contao Open Source CMS | ||
* | ||
* @author Benny Born <benny.born@numero2.de> | ||
* @author Michael Bösherz <michael.boesherz@numero2.de> | ||
* @license Commercial | ||
* @copyright Copyright (c) 2024, numero2 - Agentur für digitales Marketing GbR | ||
*/ | ||
|
||
|
||
namespace numero2\Page410Bundle; | ||
|
||
use Contao\CoreBundle\Exception\ForwardPageNotFoundException; | ||
use Contao\CoreBundle\Exception\PageNotFoundException; | ||
use Contao\Environment; | ||
use Contao\Frontend; | ||
use Contao\System; | ||
use Symfony\Component\HttpFoundation\Response; | ||
|
||
|
||
class PageError410 extends Frontend { | ||
|
||
|
||
/** | ||
* Generate an error 410 page | ||
*/ | ||
public function generate() { | ||
/** @var PageModel $objPage */ | ||
global $objPage; | ||
|
||
$obj410 = $this->prepare(); | ||
$objPage = $obj410->loadDetails(); | ||
|
||
// Reset inherited cache timeouts (see #231) | ||
if( !$objPage->includeCache ) { | ||
$objPage->cache = 0; | ||
$objPage->clientCache = 0; | ||
} | ||
|
||
/** @var PageRegular $objHandler */ | ||
$objHandler = new $GLOBALS['TL_PTY']['regular'](); | ||
|
||
header('HTTP/1.1 410 Gone'); | ||
$objHandler->generate($objPage); | ||
} | ||
|
||
|
||
/** | ||
* Return a response object | ||
* | ||
* @return Response | ||
*/ | ||
public function getResponse() { | ||
|
||
/** @var PageModel $objPage */ | ||
global $objPage; | ||
|
||
$obj410 = $this->prepare(); | ||
$objPage = $obj410->loadDetails(); | ||
|
||
// Reset inherited cache timeouts (see #231) | ||
if( !$objPage->includeCache ) { | ||
$objPage->cache = 0; | ||
$objPage->clientCache = 0; | ||
} | ||
|
||
/** @var PageRegular $objHandler */ | ||
$objHandler = new $GLOBALS['TL_PTY']['regular'](); | ||
|
||
return $objHandler->getResponse($objPage)->setStatusCode(410); | ||
} | ||
|
||
|
||
/** | ||
* Prepare the output | ||
* | ||
* @return PageModel | ||
* | ||
* @internal Do not call this method in your code. It will be made private in Contao 5.0. | ||
*/ | ||
protected function prepare() { | ||
|
||
// Find the matching root page | ||
$objRootPage = $this->getRootPageFromUrl(); | ||
|
||
// Forward if the language should be but is not set (see #4028) | ||
if( $objRootPage->urlPrefix && System::getContainer()->getParameter('contao.legacy_routing') ) { | ||
// Get the request string without the script name | ||
$strRequest = Environment::get('relativeRequest'); | ||
|
||
// Only redirect if there is no language fragment (see #4669) | ||
if( $strRequest && !preg_match('@^[a-z]{2}(-[A-Z]{2})?/@', $strRequest) ) { | ||
// Handle language fragments without trailing slash (see #7666) | ||
if( preg_match('@^[a-z]{2}(-[A-Z]{2})?$@', $strRequest) ) { | ||
$this->redirect(Environment::get('request') . '/', 301); | ||
} else { | ||
if( $strRequest == Environment::get('request') ) { | ||
$strRequest = $objRootPage->language . '/' . $strRequest; | ||
} else { | ||
$strRequest = Environment::get('script') . '/' . $objRootPage->language . '/' . $strRequest; | ||
} | ||
|
||
$this->redirect($strRequest); | ||
} | ||
} | ||
} | ||
|
||
// Look for a 410 page | ||
$obj410 = PageModel::find410ByPid($objRootPage->id); | ||
|
||
// Die if there is no page at all | ||
if( $obj410 === null ) { | ||
throw new PageNotFoundException('Page not found: ' . Environment::get('uri')); | ||
} | ||
|
||
// Forward to another page | ||
if( $obj410->autoforward && $obj410->jumpTo ) { | ||
$objNextPage = PageModel::findPublishedById($obj410->jumpTo); | ||
|
||
if( $objNextPage === null ) { | ||
|
||
System::getContainer()->get('monolog.logger.contao.error')->error('Forward page ID "' . $obj410->jumpTo . '" does not exist'); | ||
throw new ForwardPageNotFoundException('Forward page not found'); | ||
} | ||
|
||
$this->redirect($objNextPage->getFrontendUrl()); | ||
} | ||
|
||
return $obj410; | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.