Added @geoffoliver attributes.

Geoff likes to exploit the URI and inject key/value pairs into it. It's not something I do, but I was intrigued enough to implement it. Basic usage is /path/to/page/id:123/spam:eggs. The variables are removed from the request variable as to not bork module loading and are made available via Browser::get('variable');
This commit is contained in:
Josh Sherman 2013-02-04 23:34:09 -05:00
parent 2a31127152
commit cbb75e7064
3 changed files with 173 additions and 5 deletions

88
jar.php
View file

@ -314,7 +314,7 @@ class API_Tinychat extends API_Common
* Redistribution of these files must retain the above copyright notice.
*
* @author Josh Sherman <pickles@joshtronic.com>
* @copyright Copyright 2007-2012, Josh Sherman
* @copyright Copyright 2007-2013, Josh Sherman
* @license http://www.opensource.org/licenses/mit-license.html
* @package PICKLES
* @link https://github.com/joshtronic/pickles
@ -326,8 +326,72 @@ class API_Tinychat extends API_Common
* Just a simple collection of static functions to accomplish some of the more
* redundant browser-related tasks.
*/
class Browser
class Browser extends Object
{
/**
* Attributes
*
* Variables passed on the query string as /var:value/
*
* @access private
* @var array
*/
private $attributes = array();
/**
* Get instance of the object
*
* Let's the parent class do all the work
*
* @static
* @param string $class name of the class to instantiate
* @return object self::$instance instance of the Config class
*/
public static function getInstance($class = 'Browser')
{
return parent::getInstance($class);
}
/**
* Set browser variable
*
* Sets a variable in the attributes array for easier access later.
*
* @static
* @param string $variable name of the variable to set
* @param mixed $value the value to set to the variable
* @return boolean true
*/
public static function set($variable, $value)
{
$browser = Browser::getInstance();
$browser->attributes[$variable] = $value;
return true;
}
/**
* Get browser variable
*
* Gets a variable passed in from the browser. Currently only supports
* the custom attribute URI format /$variable:$value/.
*
* @static
* @param string $variable name of the variable to get
* @return mixed the value of the variable or boolean false if not set
*/
public static function get($variable)
{
$browser = Browser::getInstance();
if (isset($browser->attributes[$variable]))
{
return $browser->attributes[$variable];
}
return false;
}
/**
* Is Mobile
*
@ -1083,6 +1147,26 @@ class Controller extends Object
Error::fatal($_SERVER['SERVER_NAME'] . ' is currently<br />down for maintenance');
}
// Checks for attributes passed in the URI
if (strstr($_REQUEST['request'], ':'))
{
$parts = explode('/', $_REQUEST['request']);
$_REQUEST['request'] = '';
foreach ($parts as $part)
{
if (strstr($part, ':'))
{
list($variable, $value) = explode(':', $part);
Browser::set($variable, $value);
}
else
{
$_REQUEST['request'] .= ($_REQUEST['request'] ? '/' : '') . $part;
}
}
}
$_REQUEST['request'] = trim($_REQUEST['request']);
// Checks the passed request for validity