StickyLinks: Let others see exactly what you see on a page

Home

StickyLinks makes use of URL rewrite plugins at this point in time. For example, you might want all google searches to have nothing but the q parameter so that irrespective of the exact URL you submit, you are able to view the history of that page which may have been submitted by someone else with different GET parameters, but the same q parameter. Of course, this is assuming that you are interested in the content only. StickyLinks allows you to develop and submit such URL rewriting modules.

You may develop modules using the guideline given below and mail them to me at dhruvbird at gmail dot com for inclusion in StickyLinks.

There is currently 1 module for google's search URL rewriting. The code is presented below for easy understanding.

<?php

class mod_google
{
  var $host_pat = FALSE;

  function mod_google()
  {
    $this->host_pat = "/google\./";
  }

  function rewrite($url)
  {
    $parts = parse_url($url);
    if ($parts == FALSE)
      return FALSE;

    if (!isset($parts['host']))
      return FALSE;

    if (preg_match($this->host_pat, $parts['host']) <= 0)
      return FALSE;

    if (!isset($parts['query']))
      return $url;

    $getVariable = array();
    parse_str($parts['query'], $getVariable);
    if (!isset($getVariable['q']))
      return $url;

    $urlPart = explode("?", $url, 2);

    return $urlPart[0] . "?q=" . $getVariable['q'];
  }

  function test()
  {
    echo $this->rewrite("http://www.google.co.in/search?hl=en&client=firefox-a&rls=org.mozilla:en-US:official&hs=Wfr&ei=YXFJS-GsJMqIkAWe24SKAw&sa=X&oi=spell&resnum=0&ct=result&cd=1&ved=0CAYQBSgA&q=php4+classes&spell=1") . "\n";
    echo $this->rewrite("http://www.google.co.in/") . "\n";
  }

}

/*
$mg=new mod_google();
$mg->test();
*/

Points to note:
  1. There is NO closing ?> tag
  2. The test function is optional
  3. The rewrite() function must return FALSE if the URL passed does not match this plugin. If the URL matches, it must return the rewritten URL (which may be the original URL in some cases)
  4. The file is to be named "mod_*.php" and the class name should be "mod_*"