From fa8b0cadcdcddf4f8309bc6676aac47696b2453b Mon Sep 17 00:00:00 2001 From: coderkun Date: Sat, 9 Aug 2014 00:37:25 +0200 Subject: [PATCH] improve Linker --- core/Linker.inc | 93 ++++++++++++++++++++++--------------------------- 1 file changed, 42 insertions(+), 51 deletions(-) diff --git a/core/Linker.inc b/core/Linker.inc index 5496d2b9..a29c5b81 100644 --- a/core/Linker.inc +++ b/core/Linker.inc @@ -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 $date Date - * @return string Created link parameters + * @param string $param1 First parameter + * @return string Masked parameters as string */ - public static function getLinkParams($title, $date=null) + public static function createLinkParam($param1) { - // Parameters - $param = ''; - - // Mask special sign seperately - $specials = array('/', '?', '&'); - 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'] + return implode( + \nre\configs\CoreConfig::$classes['linker']['url']['delimiter'], + call_user_func_array( + '\nre\core\Linker::createLinkParams', + func_get_args() ) ); - - // 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 - * @return array Extracted date and title as associative array + * @param string $param1 First parameter + * @return string Masked parameters as array */ - public static function extractDateTitle($dateTitle) + public static function createLinkParams($param1) { - // Get delimiter - $delimiter = \nre\configs\CoreConfig::$classes[strtolower(get_class())]['url']['delimiter']; + // Parameters + $linkParams = array(); + $params = func_get_args(); - // Split - $dateTitle = explode($delimiter, $dateTitle); - if(count($dateTitle) < 4) { - throw new IdNotFoundException(implode($delimiter, $dateTitle)); + foreach($params as $param) + { + // Delete critical signs + $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 date and title - return array( - 'date' => $date, - 'title' => $title - ); + // Return link parameters + return $linkParams; } @@ -148,7 +137,6 @@ if(count($reqParams) < $offset && $offset > 1) { $reqParams[] = $this->request->getParam(2, 'action'); } - $params = array_map('rawurlencode', $params); $params = array_merge($reqParams, $params); // Use Layout @@ -170,6 +158,9 @@ ); } + // Encode parameters + $params = array_map('rawurlencode', $params); + // Set parameters call_user_func_array( array(