Exemplo n.º 1
0
                $callback = $_REQUEST["jsonpcb"];
            }
            $oex = new OExchangeDiscoverer();
            $target = $oex->getTargetInfoFromXrd($xrdUrl);
            // Output
            outputTargetJson($callback, $target);
        } else {
            if ($cmd == "getCommonUserTargets") {
                header("Content-Type: application/json", true);
                $fromEmail = $_REQUEST["from"];
                $toEmailList = $_REQUEST["to"];
                if (isset($_REQUEST["jsonpcb"])) {
                    $callback = $_REQUEST["jsonpcb"];
                }
                $toEmails = explode(",", $toEmailList);
                $oex = new OExchangeDiscoverer();
                $matches = $oex->getCommonUserTargets($fromEmail, $toEmails);
                // Output
                outputMatchesJson($callback, $matches);
            } else {
                if (isset($cmd)) {
                    header("HTTP/1.0 404 Not Found", true, true);
                } else {
                    $page_title = "OExchange Demo Utility API";
                    include "../../pagetop-main.inc.php";
                    ?>
		<div id="contentpage">
            <h2 class="pagetitle">Demo Utility API</h2>
            <div class="bannertext">
                A simple GET/JSON-based API for various OExchange operations
            </div>
?>

	<script src="http://webintents.org/webintents.js"></script>
    
    <h2 class="pagetitle">WebIntents Proxy Registrar</h2>
    <div class="bannertext">
        Registers OExchange services as <a href="http://webintents.org">Share Intent</a> handlers
    </div>

    <hr/>
    
<?php 
if ($cmd == "reg") {
    // Going to register the provider defined by a specific XRD
    // Look it up, get info
    $disc = new OExchangeDiscoverer();
    $target = $disc->getTargetInfoFromXrd($xrdUrl);
    if (isset($target)) {
        ?>
			<h2>OExchange Target Found</h2>
			<p>
				We found an OExchange Target descriptor at <?php 
        echo $xrdUrl;
        ?>
:<br/>
			<?php 
        printTarget($target);
        ?>
			</p>
				
			<?php 
<?php

require_once "OExchangeDiscoverer.php";
$oex = new OExchangeDiscoverer();
echo "<h2>getTargetInfoFromXrd</h2>";
$target = $oex->getTargetInfoFromXrd("http://www.oexchange.org/demo/linkeater/oexchange.xrd");
printTarget($target);
echo "<h2>getTargetsOnHost</h2>";
$results = $oex->getTargetsOnHost("www.oexchange.org");
printTargetsAndXrdUrls($results);
echo "<h2>getTargetsForUser</h2>";
$targets = $oex->getTargetsForUser("*****@*****.**");
printTargets($targets);
function printTargets($targets)
{
    foreach ($targets as $target) {
        printTarget($target);
    }
}
function printTargetsAndXrdUrls($results)
{
    foreach ($results as $result) {
        echo "&nbsp;&nbsp;XRD: " . htmlspecialchars($result["xrd"]) . "<br/>";
        printTarget($result["target"]);
    }
}
function printTarget($target)
{
    echo "&nbsp;&nbsp;ID: " . htmlspecialchars($target->id) . "<br/>";
    echo "&nbsp;&nbsp;Name: " . htmlspecialchars($target->name) . "<br/>";
    echo "&nbsp;&nbsp;Prompt: " . $target->prompt . "<br/>";
Exemplo n.º 4
0
// Other parameters are just the oexchange parameters (but we will try to get referer if we need to)
if (!isset($_REQUEST["url"])) {
    if (isset($_SERVER['HTTP_REFERER']) && !strpos($_SERVER['HTTP_REFERER'], "offer.php")) {
        $_REQUEST["url"] = $_SERVER['HTTP_REFERER'];
    }
}
// If we don't have a parameter, is there any cookie that has the user's email in it?
if (!isset($me)) {
    if (isset($_COOKIE["wf_email"]) && sizeof($_COOKIE["wf_email"]) > 0) {
        $me = $_COOKIE["wf_email"];
    }
}
$cmd = getParamDflt($_REQUEST, "cmd", "share");
// Handle the different modes
if ($cmd == "share") {
    $oex = new OExchangeDiscoverer();
    // If we have a target URL, get the actual target/targets for that as well
    if (isset($targetUrl)) {
        if (strpos($targetUrl, "http") === 0) {
            // This is a URL, not a hostname
            $parts = parse_url($targetUrl);
            if (sizeof($parts["path"]) > 0) {
                // This looks like a full URL, try to look up an OExchange XRD at this location
                //echo "Attempting to find an oexchange xrd at " . $targetUrl . "<br/>";
                $target = $oex->getTargetInfoFromXrd($targetUrl);
            }
            if (!$target) {
                // Well, this URL wasn't for an XRD, try just the host part of it
                $results = $oex->getTargetsOnHost($parts["host"]);
                if (sizeof($results) > 0) {
                    $explicitTargets = array();