improve Linker

This commit is contained in:
coderkun 2014-08-09 00:37:25 +02:00
commit fa8b0cadcd

View file

@ -43,72 +43,61 @@
/** /**
* Process a title and optional a date to create link parameters. * Mask parameters to be used in an URL.
* *
* @param string $title Titel * @param string $param1 First parameter
* @param string $date Date * @return string Masked parameters as string
* @return string Created link parameters
*/ */
public static function getLinkParams($title, $date=null) public static function createLinkParam($param1)
{ {
// Parameters return implode(
$param = ''; \nre\configs\CoreConfig::$classes['linker']['url']['delimiter'],
call_user_func_array(
// Mask special sign seperately '\nre\core\Linker::createLinkParams',
$specials = array('/', '?', '&'); func_get_args()
foreach($specials as &$special) {
$title = str_replace($special, rawurlencode(rawurlencode($special)), $title);
}
// Process title
$param .= str_replace(
' ',
'-',
substr(
$title,
0,
\nre\configs\CoreConfig::$classes['linker']['url']['length']
) )
); );
// Process date
if(!empty($date)) {
$param = substr($date, 0, 10).\nre\configs\CoreConfig::$classes['linker']['url']['delimiter'].$param;
}
// Mask and return parameters
return array(rawurlencode($param));
} }
/** /**
* Extract date and title from a parameter string. * Mask parameters to be used in an URL.
* *
* @param string $dateTitle Parameter string with date and title * @param string $param1 First parameter
* @return array Extracted date and title as associative array * @return string Masked parameters as array
*/ */
public static function extractDateTitle($dateTitle) public static function createLinkParams($param1)
{ {
// Get delimiter // Parameters
$delimiter = \nre\configs\CoreConfig::$classes[strtolower(get_class())]['url']['delimiter']; $linkParams = array();
$params = func_get_args();
// Split foreach($params as $param)
$dateTitle = explode($delimiter, $dateTitle); {
if(count($dateTitle) < 4) { // Delete critical signs
throw new IdNotFoundException(implode($delimiter, $dateTitle)); $specials = array('/', '?', '&', '#');
foreach($specials as &$special) {
$param = str_replace($special, '', $param);
}
// Process parameter
$param = str_replace(
' ',
\nre\configs\CoreConfig::$classes['linker']['url']['delimiter'],
substr(
$param,
0,
\nre\configs\CoreConfig::$classes['linker']['url']['length']
)
);
// Encode parameter
$linkParams[] = $param;
} }
// Get parts
$date = urldecode(implode($delimiter, array_slice($dateTitle, 0, 3)));
$title = urldecode(implode($delimiter, array_slice($dateTitle, 3)));
// Return link parameters
// Return date and title return $linkParams;
return array(
'date' => $date,
'title' => $title
);
} }
@ -148,7 +137,6 @@
if(count($reqParams) < $offset && $offset > 1) { if(count($reqParams) < $offset && $offset > 1) {
$reqParams[] = $this->request->getParam(2, 'action'); $reqParams[] = $this->request->getParam(2, 'action');
} }
$params = array_map('rawurlencode', $params);
$params = array_merge($reqParams, $params); $params = array_merge($reqParams, $params);
// Use Layout // Use Layout
@ -170,6 +158,9 @@
); );
} }
// Encode parameters
$params = array_map('rawurlencode', $params);
// Set parameters // Set parameters
call_user_func_array( call_user_func_array(
array( array(