Zikula: A Flexible Open Source Content Management System
home | forum | contact us

Dizkus

Bottom
Shorturls redirect-hack
  • Posted: 10.01.2006, 14:20
     
    ainigma32
    rank:
    Professional Professional
    registered:
     January 2004
    Status:
    offline
    last visit:
    22.03.06
    Posts:
    958
    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:

    Code

    return "$proto$server$path/";
    }
    and the part where it says

    Code

    /**
    * Carry out a redirect

    Part 1:

    Code

    //------------------- 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:

    Code

    // Always close session before redirect
        if (function_exists('session_write_close')) {
            session_write_close();
        }

    and the part where it says:

    Code

    if (preg_match('!^http!', $redirecturl)) {
            // Absolute URL - simple redirect
            header("Location: $redirecturl");

    Part2:

    Code

    //------------------- 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!
  • Posted: 31.01.2006, 12:44
     
    mikelawson
    rank:
    Helper Helper
    registered:
     December 2003
    Status:
    offline
    last visit:
    25.06.08
    Posts:
    334
    Worked like a charm!

    --
    www.appleproaudio.com
  • Posted: 08.02.2006, 07:18
     
    Slugger
    rank:
    Professional Professional
    registered:
     March 2003
    Status:
    offline
    last visit:
    13.08.06
    Posts:
    1185
    Parse error: parse error, unexpected T_STRING :?

Main Menu

Extensions Database

Documentation

Development

Login

Donate to Zikula