Source for file Proxy.php
Documentation is available at Proxy.php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
* LICENSE: This source file is subject to version 3.0 of the PHP license
* that is available through the world-wide-web at the following URI:
* http://www.php.net/license/3_0.txt. If you did not receive a copy of
* the PHP License and are unable to obtain it through the web, please
* send a note to license@php.net so we can mail you a copy immediately.
* @author Joe Stump <joe@joestump.net>
* @copyright 1997-2007 The PHP Group
* @license http://www.php.net/license/3_0.txt PHP License 3.0
* @link http://pear.php.net/package/Services_Digg
require_once 'Services/Digg.php';
require_once 'Services/Digg/Exception.php';
* This allows you to make JSON requests to the Digg API from your own website.
* Create a PHP script like the one below and then request it in the following
* http://www.example.com/myproxy.php?endPoint=/errors
* Replace the endPoint argument with any of the valid endpoints outlined in
* the Digg API documentation. All other arguments are passed onto the API
* require_once 'Services/Digg/Proxy.php';
* Services_Digg::$appKey = 'http://www.example.com/myproxy.php';
* $proxy = new Services_Digg_Proxy();
* @author Joe Stump <joe@joestump.net>
* Possible response codes
* @var array $responseCodes
private $responseCodes = array ('200' => 'OK',
'500' => 'Internal error');
* Pass through these headers
* @var array $passThrough
private $passThrough = array ();
* Add additional request headers
* @var array $requestHeaders
* @see Services_Digg_Proxy::addRequestHeader();
private $requestHeaders = array ();
* Takes either a GET or POST request and proxies a request to the Digg
* API via an HTTP_Request.
$req = array_merge($_GET, $_POST); // Support both GET and POST
if (!isset ($req['type'])) {
$req['type'] = 'json'; // Default to JSON
if (isset ($req['endPoint'])) {
$endPoint = $req['endPoint'];
foreach ($req as $key => $val) {
$sets[] = $key . '=' . urlencode ($val);
$uri = Services_Digg::$uri . $endPoint . '?' . implode ('&', $sets);
if (isset ($_SERVER['HTTP_REFERER'])) {
curl_setopt ($ch, CURLOPT_REFERER , $_SERVER['HTTP_REFERER']);
$h = $this->requestHeaders;
if (isset ($_SERVER['HTTP_X_FORWARDED_FOR'])) {
$h[] = 'X-Forwarded-For: ' . $_SERVER['HTTP_X_FORWARDED_FOR'];
} elseif (isset ($_SERVER['REMOTE_ADDR'])) {
$h[] = 'X-Forwarded-For: ' . $_SERVER['REMOTE_ADDR'];
curl_setopt($ch, CURLOPT_HEADERFUNCTION , array ($this, 'passHeaders'));
if ($response === false ) {
if (isset ($this->responseCodes[$code])) {
header('HTTP/1.1 ' . $code . ' ' . $this->responseCodes[$code]);
foreach ($this->passThrough as $header) {
* Pass through all headers
private function passHeaders ($ch, $header)
list ($h,) = explode (':', $header);
$this->passThrough[] = trim($header);
* Add an additional request header
* A way to set specific headers to be sent to the API if you wish to
* overload the request behavior.
$this->requestHeaders[] = $header;
Documentation generated on Tue, 04 Dec 2007 15:00:11 -0500 by phpDocumentor 1.4.0. PEAR Logo Copyright © PHP Group 2004.
|