コード例 #1
0
function dispatch_JSONRequest()
{
    $res = null;
    $req = null;
    try {
        $req = JSONMessageDispatcher::getRequestFromEnv();
        if (!$req) {
            throw new Exception("No JSONMessage request data found!");
        }
        $res = JSONMessageDispatcher::getResponse($req);
        if (!$res) {
            throw new Exception("No JSONResponse found for JSONMessage type '" . $req->getType() . "'!");
        }
        echo $res->toJSON();
    } catch (Exception $e) {
        $res = new JSONResponse_Error($req, $e);
        //$res->setResult( 12, "WTF?" );
        //$res->setResult( 17, $e->getMessage() );
        echo $res->toJSON();
    }
    echo "\n";
}
コード例 #2
0
ファイル: JSONMessage.inc.php プロジェクト: reidab/wikiwym
 /**
    To be (optionally) run one time before using this class.  It
    adds default request handler search paths. If it is called
    after another path has been set then it does nothing.  Returns
    true if it does (or tries to do) anything, else false.
 
    By default it adds these paths:
 
    - DIR/response/local
    - DIR/response
 
    DIR = dirname(__FILE__)
 */
 public static function setupDefaultAutoloadPaths()
 {
     if (count(self::$DispatcherPath)) {
         return false;
     }
     $D = dirname(__FILE__);
     $rd = $D . '/response';
     foreach (array($rd, $rd . '/local') as $d) {
         if (@is_dir($d)) {
             JSONMessageDispatcher::addAutoloadDir($d);
         }
     }
     return true;
 }
コード例 #3
0
ファイル: getWikiPage.inc.php プロジェクト: reidab/wikiwym
        $pay = $req->getPayload();
        if (!@is_array($pay)) {
            throw new Exception($this->getType() . " requires a payload object!", 1);
        }
        $proj = @$pay['project'];
        if (!$proj) {
            throw new Exception($this->getType() . " requires a 'project' property in the payload!", 2);
        }
        $page = @$pay['page'];
        if (!$page) {
            throw new Exception($this->getType() . " requires a 'page' property in the payload!", 2);
        }
        $rev = (int) @$pay['r'];
        $url = 'http://' . $proj . '.googlecode.com/svn/wiki/' . $page . '.wiki' . ($rev ? '?r=' . $rev : '');
        $fh = @file_get_contents($url, 'r');
        if (false === $fh) {
            throw new Exception($this->getType() . " could not open URL [{$url}]!", 3);
        }
        $opay = array();
        $opay['url'] = $url;
        $opay['project'] = $proj;
        $opay['page'] = $page;
        if ($rev) {
            $opay['r'] = $rev;
        }
        $opay['content'] = $fh;
        $this->setPayload($opay);
    }
}
JSONMessageDispatcher::mapResponderFile(__FILE__, JSONResponse_GoCo_GetWikiPage);
コード例 #4
0
ファイル: cookie.inc.php プロジェクト: reidab/wikiwym
        $ar = @$payload['clearCookies'];
        if ($ar) {
            ++$got;
            $sessname = session_name();
            foreach ($_COOKIE as $k => $v) {
                if ($sessname === $k) {
                    continue;
                }
                $this->setCookie($k, false);
                //$this->log[] = "Unset cookie [$k].";
            }
            $ans['cleared'] = true;
            // we do this to force the payload to be-a {object} instead of [array]
            $this->setResult(0, $this->log[] = "Cookies cleared.");
        }
        $ar = @$payload['set'];
        if ($ar) {
            ++$got;
            $ans['set'] = $this->setEnv($ar);
        }
        if (!$got) {
            $this->setResult(1, "Usage error: no action specified.");
        }
        if (count($this->log)) {
            $ans['log'] = $this->log;
        }
        $this->setPayload($ans);
    }
}
JSONMessageDispatcher::mapResponderFile(__FILE__, 'JSONResponse_Cookie');
コード例 #5
0
ファイル: ChuckNorris.inc.php プロジェクト: reidab/wikiwym
            $ar[] = "The Big Bang happened when Chuck Norris went back in time to just before the Universe began and every atom in the Universe immediately decided it should get the hell away from there and fast. ";
            $ar[] = "Chuck Norris has no home security system. Chuck Norris welcomes intruders.  ";
            $ar[] = "Chuck Norris has the eyes of an angel and the soul of a saint.  He keeps them in a footlocker under his bed. ";
            self::$_quotes = $ar;
        }
        return self::$_quotes;
    }
    /**
        See JSONMessage constructor.
    */
    public function __construct(JSONRequest $req)
    {
        parent::__construct($req);
        $a = array();
        $q = self::quotes();
        $respay = $req->getPayload();
        if ($respay && @is_array($respay) && @$respay['fetchAll']) {
            $a['credits'] = array('originalListAuthor' => 'Brandon Checketts', 'originalURL' => 'http://www.apeleon.net/~microbit/brandon.html');
            $a['quotes'] = $q;
        } else {
            $c = count($q);
            $n = $c ? rand(0, $c - 1) : 0;
            $a['quote'] = $q[$n];
            $a['number'] = $n;
            $a['of'] = $c;
        }
        $this->setPayload($a);
    }
}
JSONMessageDispatcher::mapResponderFile(__FILE__, JSONResponse_ChuckNorris::ClassName);