Merge branch 'master' of github.com:joshtronic/pickles

This commit is contained in:
Josh Sherman 2011-08-13 13:39:44 -04:00
commit 056c2d1212
6 changed files with 459 additions and 5 deletions

43
classes/API/Common.php Normal file
View file

@ -0,0 +1,43 @@
<?php
/**
* Common API Class File for PICKLES
*
* PHP version 5
*
* Licensed under The MIT License
* Redistribution of these files must retain the above copyright notice.
*
* @author Josh Sherman <josh@gravityblvd.com>
* @copyright Copyright 2007-2011, Josh Sherman
* @license http://www.opensource.org/licenses/mit-license.html
* @package PICKLES
* @link http://p.ickl.es
*/
/**
* Common API Interface
*
* Parent class that our API interface classes should be extending. Contains
* execution of parental functions but may contain more down the road.
*/
abstract class API_Common extends Object
{
/**
* Constructor
*/
public function __construct()
{
parent::__construct();
}
/**
* Destructor
*/
public function __destruct()
{
parent::__destruct();
}
}
?>

185
classes/API/Tinychat.php Normal file
View file

@ -0,0 +1,185 @@
<?php
/**
* Tinychat Class File for PICKLES
*
* PHP version 5
*
* Licensed under The MIT License
* Redistribution of these files must retain the above copyright notice.
*
* @author Josh Sherman <josh@gravityblvd.com>
* @copyright Copyright 2007-2011, Josh Sherman
* @license http://www.opensource.org/licenses/mit-license.html
* @package PICKLES
* @link http://p.ickl.es
*/
/**
* Tinychat API Interface
*
* @link http://tinychat.com/developer/docs
*/
class API_Tinychat extends API_Common
{
/**
* Public Key
*
* @access private
* @var string
*/
private $public_key = null;
/**
* Secret Key
*
* @access private
* @var string
*/
private $secret_key = null;
/**
* Constructor
*
* Assigns our public and secret keys from the configuration.
*/
public function __construct()
{
parent::__construct();
if (isset($this->config->api['tinychat'], $this->config->api['tinychat']['public_key'], $this->config->api['tinychat']['secret_key']))
{
$this->public_key = $this->config->api['tinychat']['public_key'];
$this->secret_key = $this->config->api['tinychat']['secret_key'];
}
else
{
throw new Exception('Unable to load TinyChat configuration.');
}
}
/**
* Execute
*
* Constructs a valid API call, executes it and returns the results.
*
* @param string $codephrase name of the API call being called
* @param string $authentication post-codephrase portion of the auth string
* @param array $parameters key / value pairs for additional data
* @return array results of the API call
*/
private function execute($codephrase, $authentication, $parameters = null)
{
// Assembles and hashes the authentication token
$authentication = md5($this->secret_key . ':' . $authentication);
// Assembles any additional parameters
$additional = '';
if ($parameters && is_array($parameters))
{
foreach ($parameters as $key => $value)
{
$additional .= '&' . $key . '=' . $value;
}
}
// Executes the API call
$results = file_get_contents('http://tinychat.apigee.com/' . $codephrase . '?result=json&key=' . $this->public_key . '&auth=' . $authentication . $additional);
return json_decode($results, true);
}
/**
* List Rooms
*
* Pulls all rooms for the API application.
*
* @return array API results
*/
public function listRooms()
{
return $this->execute('roomlist', 'roomlist');
}
/**
* Room Info
*
* Pulls the information for a room.
*
* @param string $room name of the room
* @param boolean $with_ip whether or not to include users IP addresses
* @return array API results
*/
public function roomInfo($room, $with_ip = false)
{
return $this->execute('roominfo', $room . ':roominfo', array('room' => $room, 'with_ip' => ($with_ip ? 1 : 0)));
}
/**
* Set Room Password
*
* Sets the password for the room, only users with the correct password
* will be able to enter.
*
* @param string $room name of the room
* @param string $password password to use, blank for no password
* @return array API results
*/
public function setRoomPassword($room, $password = '')
{
return $this->execute('setroompassword', $room . ':setroompassword', array('room' => $room, 'password' => $password));
}
/**
* Set Broadcast Password
*
* Sets the password to allow broadcasting in the room. Only users with the
* correct password will be able to broadcast.
*
* @param string $room name of the room
* @param string $password password to use, blank for no password
* @return array API results
*/
public function setBroadcastPassword($room, $password = '')
{
return $this->execute('setbroadcastpassword', $room . ':setbroadcastpassword', array('room' => $room, 'password' => $password));
}
/**
* Generate HTML
*
* Creates the HTML to place a chat on a site.
*
* @todo List params...
* @return array API results
*/
public function generateHTML($room, $join = false, $nick = false, $change = false, $login = false, $oper = false, $owner = false, $bcast = false, $api = false, $colorbk = false, $tcdisplay = false, $autoop = false, $urlsuper = false, $langdefault = false)
{
return '
<script type="text/javascript">
var tinychat = {'
. 'room: "' . $room . '",'
. ($join ? 'join: "auto",' : '')
. ($nick ? 'nick: "' . $nick . '",' : '')
. ($change ? 'change: "none",' : '')
. ($login ? 'login: "' . $login . '",' : '')
. ($oper ? 'oper: "none",' : '')
. ($owner ? 'owner: "none",' : '')
. ($bcast ? 'bcast: "restrict",' : '')
. ($api ? 'api: "' . $api . '",' : '')
. ($colorbk ? 'colorbk: "' . $colorbk . '",' : '')
. ($tcdisplay ? 'tcdisplay: "vidonly",' : '')
/* @todo Implement $autoop, it's an array and needs validated */
. ($urlsuper ? 'urlsuper: "' . $urlsuper . '",' : '')
. ($langdefault ? 'langdefault: "' . $langdefault . '",' : '')
. 'key: "' . $this->public_key . '"'
. '};
</script>
<script src="http://tinychat.com/js/embed.js"></script>
<div id="client"></div>
';
}
}
?>

View file

@ -131,7 +131,9 @@ class Config extends Object
}
else
{
if ((preg_match('/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/', $host) && $_SERVER['SERVER_ADDR'] == $host) || $_SERVER['SERVER_NAME'] == $host)
if ((preg_match('/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/', $host)
&& $_SERVER['SERVER_ADDR'] == $host)
|| $_SERVER['HTTP_HOST'] == $host)
{
// Sets the environment and makes a run for it
$environment = $name;

View file

@ -95,7 +95,7 @@ class Dynamic extends Object
}
else
{
throw new Exception('Supplied reference does not exist');
throw new Exception('Supplied reference does not exist (' . $reference . ')');
}
}
}

228
jar.php Executable file → Normal file
View file

@ -1,5 +1,227 @@
<?php
/**
* Common API Class File for PICKLES
*
* PHP version 5
*
* Licensed under The MIT License
* Redistribution of these files must retain the above copyright notice.
*
* @author Josh Sherman <josh@gravityblvd.com>
* @copyright Copyright 2007-2011, Josh Sherman
* @license http://www.opensource.org/licenses/mit-license.html
* @package PICKLES
* @link http://p.ickl.es
*/
/**
* Common API Interface
*
* Parent class that our API interface classes should be extending. Contains
* execution of parental functions but may contain more down the road.
*/
abstract class API_Common extends Object
{
/**
* Constructor
*/
public function __construct()
{
parent::__construct();
}
/**
* Destructor
*/
public function __destruct()
{
parent::__destruct();
}
}
/**
* Tinychat Class File for PICKLES
*
* PHP version 5
*
* Licensed under The MIT License
* Redistribution of these files must retain the above copyright notice.
*
* @author Josh Sherman <josh@gravityblvd.com>
* @copyright Copyright 2007-2011, Josh Sherman
* @license http://www.opensource.org/licenses/mit-license.html
* @package PICKLES
* @link http://p.ickl.es
*/
/**
* Tinychat API Interface
*
* @link http://tinychat.com/developer/docs
*/
class API_Tinychat extends API_Common
{
/**
* Public Key
*
* @access private
* @var string
*/
private $public_key = null;
/**
* Secret Key
*
* @access private
* @var string
*/
private $secret_key = null;
/**
* Constructor
*
* Assigns our public and secret keys from the configuration.
*/
public function __construct()
{
parent::__construct();
if (isset($this->config->api['tinychat'], $this->config->api['tinychat']['public_key'], $this->config->api['tinychat']['secret_key']))
{
$this->public_key = $this->config->api['tinychat']['public_key'];
$this->secret_key = $this->config->api['tinychat']['secret_key'];
}
else
{
throw new Exception('Unable to load TinyChat configuration.');
}
}
/**
* Execute
*
* Constructs a valid API call, executes it and returns the results.
*
* @param string $codephrase name of the API call being called
* @param string $authentication post-codephrase portion of the auth string
* @param array $parameters key / value pairs for additional data
* @return array results of the API call
*/
private function execute($codephrase, $authentication, $parameters = null)
{
// Assembles and hashes the authentication token
$authentication = md5($this->secret_key . ':' . $authentication);
// Assembles any additional parameters
$additional = '';
if ($parameters && is_array($parameters))
{
foreach ($parameters as $key => $value)
{
$additional .= '&' . $key . '=' . $value;
}
}
// Executes the API call
$results = file_get_contents('http://tinychat.apigee.com/' . $codephrase . '?result=json&key=' . $this->public_key . '&auth=' . $authentication . $additional);
return json_decode($results, true);
}
/**
* List Rooms
*
* Pulls all rooms for the API application.
*
* @return array API results
*/
public function listRooms()
{
return $this->execute('roomlist', 'roomlist');
}
/**
* Room Info
*
* Pulls the information for a room.
*
* @param string $room name of the room
* @param boolean $with_ip whether or not to include users IP addresses
* @return array API results
*/
public function roomInfo($room, $with_ip = false)
{
return $this->execute('roominfo', $room . ':roominfo', array('room' => $room, 'with_ip' => ($with_ip ? 1 : 0)));
}
/**
* Set Room Password
*
* Sets the password for the room, only users with the correct password
* will be able to enter.
*
* @param string $room name of the room
* @param string $password password to use, blank for no password
* @return array API results
*/
public function setRoomPassword($room, $password = '')
{
return $this->execute('setroompassword', $room . ':setroompassword', array('room' => $room, 'password' => $password));
}
/**
* Set Broadcast Password
*
* Sets the password to allow broadcasting in the room. Only users with the
* correct password will be able to broadcast.
*
* @param string $room name of the room
* @param string $password password to use, blank for no password
* @return array API results
*/
public function setBroadcastPassword($room, $password = '')
{
return $this->execute('setbroadcastpassword', $room . ':setbroadcastpassword', array('room' => $room, 'password' => $password));
}
/**
* Generate HTML
*
* Creates the HTML to place a chat on a site.
*
* @todo List params...
* @return array API results
*/
public function generateHTML($room, $join = false, $nick = false, $change = false, $login = false, $oper = false, $owner = false, $bcast = false, $api = false, $colorbk = false, $tcdisplay = false, $autoop = false, $urlsuper = false, $langdefault = false)
{
return '
<script type="text/javascript">
var tinychat = {'
. 'room: "' . $room . '",'
. ($join ? 'join: "auto",' : '')
. ($nick ? 'nick: "' . $nick . '",' : '')
. ($change ? 'change: "none",' : '')
. ($login ? 'login: "' . $login . '",' : '')
. ($oper ? 'oper: "none",' : '')
. ($owner ? 'owner: "none",' : '')
. ($bcast ? 'bcast: "restrict",' : '')
. ($api ? 'api: "' . $api . '",' : '')
. ($colorbk ? 'colorbk: "' . $colorbk . '",' : '')
. ($tcdisplay ? 'tcdisplay: "vidonly",' : '')
/* @todo Implement $autoop, it's an array and needs validated */
. ($urlsuper ? 'urlsuper: "' . $urlsuper . '",' : '')
. ($langdefault ? 'langdefault: "' . $langdefault . '",' : '')
. 'key: "' . $this->public_key . '"'
. '};
</script>
<script src="http://tinychat.com/js/embed.js"></script>
<div id="client"></div>
';
}
}
/**
* Configuration Class File for PICKLES
*
@ -131,7 +353,9 @@ class Config extends Object
}
else
{
if ((preg_match('/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/', $host) && $_SERVER['SERVER_ADDR'] == $host) || $_SERVER['SERVER_NAME'] == $host)
if ((preg_match('/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/', $host)
&& $_SERVER['SERVER_ADDR'] == $host)
|| $_SERVER['HTTP_HOST'] == $host)
{
// Sets the environment and makes a run for it
$environment = $name;
@ -2403,7 +2627,7 @@ class Dynamic extends Object
}
else
{
throw new Exception('Supplied reference does not exist');
throw new Exception('Supplied reference does not exist (' . $reference . ')');
}
}
}

View file

@ -63,7 +63,7 @@ function readFileContents($directory)
foreach ($files as $file)
{
if (!in_array($file, array('.', '..')))
if (strpos($file, '.') !== 0)
{
$file = $directory . '/' . $file;