After digging into shorturls a bit I noticed that they don't work when the client's request is redirected (after submitting a form without any valid data for instance)
To resolve this I wrote a hack for pnRedirect and I'm posting it here for feedback and sharing.
Open /includes/pnAPI.php and paste part 1 around line 1005 between the part where it says:
return "$proto$server$path/";
}
and the part where it says
/**
* Carry out a redirect
Part 1:
//------------------- ShortURLS redirect hack Start part 1 ----------------------------------------------->function redirect_get_template
($tpl_name, &
$tpl_source, &
$smarty_obj){ $tpl_source =
'{$url}';
return true;
}function redirect_get_timestamp
($tpl_name, &
$tpl_timestamp, &
$smarty_obj){ $tpl_timestamp =
time();
return true;
}function redirect_get_secure
($tpl_name, &
$smarty_obj){ // assume all templates are secure return true;
}function redirect_get_trusted
($tpl_name, &
$smarty_obj){ // not used for templates}//<------------------ ShortURLS redirect hack End part 1 ------------------------------------------------
Now paste part 2 a little lower (around line 1055 if you already pasted the first code snippet) between where it says:
and the part where it says:
if (preg_match('!^http!',
$redirecturl)) { // Absolute URL - simple redirect header("Location: $redirecturl");
Part2:
//------------------- ShortURLS redirect hack Start part 2 -----------------------------------------------> if(pnModGetVar
('Xanthia',
'shorturls') ==
1) { //we need quotes or the outputfilter won't recognize the url $redirecturl =
'"'.
$redirecturl.
'"';
//Get a reference to Smarty (pnRender doesn't seem to work) $pnSmarty =&
new Smarty
('Xanthia');
//Configure the Smarty instance $pnSmarty->
caching=
false;
$pnSmarty->
use_sub_dirs=
false;
$pnSmarty->
compile_dir=pnConfigGetVar
('temp') .
'/Xanthia_compiled';
$pnSmarty->
plugins_dir=
'../../../modules/Xanthia/plugins';
// create a custom resource using the functions pasted in earlier $pnSmarty->
register_resource("redirect",
array("redirect_get_template",
"redirect_get_timestamp",
"redirect_get_secure",
"redirect_get_trusted"));
$pnSmarty->
assign('url',
$redirecturl);
$pnSmarty->
load_filter('output',
'shorturls');
//use the custom resource $redirecturl =
$pnSmarty->
fetch("redirect:url.tpl");
//remove the quotes added earlier $redirecturl =
str_replace('"',
'',
$redirecturl);
}//<------------------ ShortURLS redirect hack End part 2 ------------------------------------------------
Now save and close the file and your shorturl-redirect should work.
Any feedback will be greatly appreciated.
Happy coding!