Example #1
0
    <p>As well as a Javascript library, sda_stream is also a PHP library. You can create your page without using any Javascript if necessary.</p>
    <p>This has the benefits of hiding your API key, and allowing you to cache API requests. See <a href="example-php-request.html">example-php-request.html</a> for further details.</p>
    <ul>
      <li>Include stream.php into your app.</li>
      <li>Create a new SDAStream object, passing it the channel data, API key and other info.</li>
      <li>Call SDAStream::get(), which returns online and offline arrays of channel data.</li>
      <li>Use this data to do your own thing.</li>
    </ul>
    <p>See the result below.</p>
    <?php 
require '../stream.php';
require '../config.php';
if (!is_array($channels) || !isset($key)) {
    die('Config not provided by config.php');
}
$stream = new SDAStream(array('channels' => $channels, 'key' => $key, 'timer' => $timer, 'cache' => $cache));
list($online, $offline) = $stream->get();
?>
    <div id="wrapper">
      <div id="online">
        <?php 
if (count($online) > 0) {
    print '<h2>Running Now...</h2>';
}
foreach ($online as $entry) {
    print <<<HTML
        <div class="entry">
          <h3><a href="{$entry['url']}">{$entry['user']['userName']}</a></h3>
          {$entry['embedTag']}
          <div class="synopsis">{$entry['synopsis']}</div>
        </div>
Example #2
0
    {
        if (!$this->fields) {
            return $c;
        }
        $n = array('uid' => $c['uid']);
        $n['result'] = self::loop_fields($c['result'], $this->fields);
        return $n;
    }
    private static function loop_fields($c, $f)
    {
        $out = array();
        foreach ($f as $k => $e) {
            if (is_array($e)) {
                $out[$k] = self::loop_fields($c[$k], $e);
            } else {
                $out[$e] = $c[$e];
            }
        }
        return $out;
    }
}
// Return the API in JSON format if this file is being requested, not included
if (reset(get_included_files()) == __FILE__) {
    include 'config.php';
    if (!is_array($channels) || !isset($key)) {
        die('Config not provided by config.php');
    }
    $stream = new SDAStream(array('channels' => $channels, 'key' => $key, 'timer' => $timer, 'cache' => $cache, 'fields' => $fields));
    $stream->headers();
    echo $stream->get('json');
}