Created
May 27, 2010 19:08
-
-
Save kahlil/416211 to your computer and use it in GitHub Desktop.
PHP: Implementation for Contao CMS hooks to change various URLs
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
<?php if (!defined('TL_ROOT')) die('You can not access this file directly!'); | |
$GLOBALS['TL_HOOKS']['generateFrontendUrl'][] = array('RDKHooks', 'myGenerateFrontendUrl'); | |
$GLOBALS['TL_HOOKS']['getPageIdFromUrl'][] = array('RDKHooks', 'myGetPageIdFromUrl'); |
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
<?php if (!defined('TL_ROOT')) die('You can not access this file directly!'); | |
class RDKHooks extends Backend { | |
public function myGenerateFrontendUrl($objPage, $strParams, $strUrl) | |
{ | |
if( strstr($strUrl, 'rdk-artikel/items/') ) | |
{ | |
$alias = str_replace("rdk-artikel/items/", "", $strUrl); | |
$alias = str_replace(".html", "", $alias); | |
$this->import('Database'); | |
$res = $this->Database->prepare("Select publishingdate FROM rdk_articles WHERE alias=?") | |
->limit(1) | |
->execute($alias); | |
if($res->numRows){ | |
$row = $res->fetchAssoc(); | |
$m = date('m', $row['publishingdate']); | |
$y = date('Y', $row['publishingdate']); | |
switch($m){ | |
case '01': | |
$m = 'januar'; | |
break; | |
case '02': | |
$m = 'februar'; | |
break; | |
case '03': | |
$m = 'maerz'; | |
break; | |
case '04': | |
$m = 'april'; | |
break; | |
case '05': | |
$m = 'mai'; | |
break; | |
case '06': | |
$m = 'juni'; | |
break; | |
case '07': | |
$m = 'juli'; | |
break; | |
case '08': | |
$m = 'august'; | |
break; | |
case '09': | |
$m = 'september'; | |
break; | |
case '10': | |
$m = 'oktober'; | |
break; | |
case '11': | |
$m = 'november'; | |
break; | |
case '12': | |
$m = 'dezember'; | |
break; | |
} | |
} | |
//exit; | |
$strUrl = str_replace("rdk-artikel/items/", "$m-$y/", $strUrl); | |
} | |
// News | |
else if( strstr($strUrl, 'news/items/') ) | |
{ | |
$alias = str_replace("news/items/", "", $strUrl); | |
$alias = str_replace(".html", "", $alias); | |
$this->import('Database'); | |
$res = $this->Database->prepare("Select date FROM tl_news WHERE alias=?") | |
->limit(1) | |
->execute($alias); | |
if($res->numRows){ | |
$row = $res->fetchAssoc(); | |
$urlDate = date('Y/m/d/', $row['date']); | |
} | |
$strUrl = str_replace("items/", $urlDate, $strUrl); | |
} | |
// Ausgabenansicht Archiv | |
else if ( strstr($strUrl, '/issue/') ) | |
{ | |
$strUrl = str_replace("issue/", "", $strUrl); | |
} | |
return $strUrl; | |
} | |
public function myGetPageIdFromUrl($arrFragments) | |
{ | |
if(in_array('archiv-anzeige', $arrFragments) ) | |
{ | |
array_insert($arrFragments, 1, 'issue'); | |
return $arrFragments; | |
} | |
else if(in_array('rdk-artikel', $arrFragments) ) | |
{ | |
array_insert($arrFragments, 1, 'items'); | |
return $arrFragments; | |
} | |
else if( preg_match('/[a-z]+\-\d{4}/', $arrFragments[0]) ) | |
{ | |
array_insert($arrFragments, 0, 'rdk-artikel'); | |
array_insert($arrFragments, 1, 'items'); | |
array_insert($arrFragments, 2, $arrFragments[3]); | |
unset($arrFragments[3]); | |
unset($arrFragments[4]); | |
} | |
else if( in_array('news', $arrFragments) ) | |
{ | |
array_insert($arrFragments, 1, 'items'); | |
array_insert($arrFragments, 2, $arrFragments[5]); | |
unset($arrFragments[3]); | |
unset($arrFragments[4]); | |
unset($arrFragments[5]); | |
} | |
return $arrFragments; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment