change link parameter masking of framework

This commit is contained in:
coderkun 2014-01-17 16:25:26 +01:00
commit 2a5330e4be
2 changed files with 40 additions and 51 deletions

View file

@ -103,7 +103,7 @@
public static $classes = array( public static $classes = array(
'linker' => array( 'linker' => array(
'url' => array( 'url' => array(
'length' => 50, 'length' => 128,
'delimiter' => '-' 'delimiter' => '-'
) )
) )

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 Utils::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) { // Mask special signs seperately
throw new IdNotFoundException(implode($delimiter, $dateTitle)); $specials = array('/', '?', '&');
foreach($specials as &$special) {
$param = str_replace($special, rawurlencode(rawurlencode($special)), $param);
}
// Process parameter
$param = str_replace(
' ',
\nre\configs\CoreConfig::$classes['linker']['url']['delimiter'],
substr(
$title,
0,
\nre\configs\CoreConfig::$classes['linker']['url']['length']
)
);
// Encode parameter
$linkParams[] = rawurlencode($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 link parameters
return array( return $linkParams;
'date' => $date,
'title' => $title
);
} }