Example #1
0
<?php

/*
 * A real quick example to get and update a doc.
 */
require_once './src/Sag.php';
$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
$school = $_POST['school'];
$discipline = $_POST['discipline'];
$sag = new Sag('127.0.0.1', '5984');
// Select the database that holds our blog's data.
$sag->setDatabase('sakib');
try {
    //Get a blog post (a StdClass)...
    $post = $sag->get('postID')->body;
    //...update its info...
    $post->views++;
    //..and send it back to the couch.
    if (!$sag->put($post->_id, $post)->body->ok) {
        error_log('Unable to log a view to CouchDB.');
    }
} catch (SagCouchException $e) {
    //The requested post doesn't exist - oh no!
    if ($e->getCode() == "404") {
        $e = new Exception("That post doesn't exist.");
    }
    throw $e;
} catch (SagException $e) {
    //We sent something to Sag that it didn't expect.
    error_log('Programmer error: ' . $e->getMessage());
$myUsername = $VcapSvs["username"];
$myPassword = $VcapSvs["password"];
try {
    // Let's login to the database.
    $sag = new Sag($myUsername . ".cloudant.com");
    $sag->login($myUsername, $myPassword);
    // Now that we are logged in, we can create a database to use
    $sag->createDatabase("mydatabase");
    $sag->setDatabase("mydatabase");
    if (!$sag->put("myId", '{"myKey":"Hello World from Cloudant!"}')->body->ok) {
        error_log('Unable to post a document to Cloudant.');
    } else {
        // We are now going to read a document from our cloudant database. We are going
        // to retrieve the value associated with myKey from the body of the document.
        //The SAG PHP library takes care of all the gory details and only retrieves the value.
        $resp = $sag->get('myId')->body->myKey;
        echo $resp;
    }
    // Assuming everything above was executed without error, we now are connected to the
    // database and have retrieved the value.
    //NOTE: Since we have a connection to the database, we can query the database for other
    //      documents and retrieve other variables at a later time. We do not need to connect
    //      to the database again.
} catch (Exception $e) {
    //We sent something to Sag that it didn't expect.
    echo '<p>There Was an Error Getting Data from Cloudant!!!</p>';
    echo $e->getMessage();
}
//-------------------------------------------------------------------------------
// Copyright IBM Corp. 2014
//
Example #3
0
 public function test_connectionFailure()
 {
     $badCouch = new Sag('example.com');
     $badCouch->setOpenTimeout(1);
     try {
         $badCouch->setDatabase('bwah');
         $badCouch->get('/asdf');
         $this->assertTrue(false);
         //shouldn't reach this line
     } catch (SagException $e) {
         $this->assertTrue(true);
     }
 }
 *  You should have received a copy of the GNU Affero General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
require_once 'config.php';
require_once 'utils.php';
$videoHeight = 360;
if (!isset($config) || !is_array($config)) {
    die("broken or missing configuration file?");
}
date_default_timezone_set(getConfig($config, 'time_zone', FALSE, 'Europe/Amsterdam'));
$dbName = getConfig($config, 'db_name', TRUE);
require_once "ext/sag/src/Sag.php";
$storage = new Sag();
$storage->setDatabase($dbName);
do {
    $toTranscode = $storage->get("_design/files/_view/get_media_status?limit=1&startkey=[\"WAITING\"]&endkey=[\"WAITING\",{}]")->body->rows;
    if (!empty($toTranscode)) {
        $t = $toTranscode[0];
        $id = $t->id;
        $info = $storage->get($id)->body;
        $info->transcodeStatus = 'PROGRESS';
        $storage->put($id, $info);
        $fileOwner = $info->fileOwner;
        $fileName = getConfig($config, 'file_storage_dir', TRUE) . DIRECTORY_SEPARATOR . base64_encode($fileOwner) . DIRECTORY_SEPARATOR . $info->fileName;
        if (isset($info->video)) {
            $transcodeFileName = getConfig($config, 'cache_dir', TRUE) . DIRECTORY_SEPARATOR . $info->video->transcode->{$videoHeight}->file;
            $newSize = $info->video->transcode->{$videoHeight}->width . "x" . $info->video->transcode->{$videoHeight}->height;
            // -vf transpose=1   (for rotating clockwise 90 degrees)
            $cmd = "ffmpeg -i \"{$fileName}\" -threads 2 -f webm -acodec libvorbis -vcodec libvpx -s {$newSize} -b 524288 -y {$transcodeFileName}";
        } elseif (isset($info->audio)) {
            $transcodeFileName = getConfig($config, 'cache_dir', TRUE) . DIRECTORY_SEPARATOR . $info->audio->transcode->file;
 *  You should have received a copy of the GNU Affero General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
require_once 'config.php';
require_once 'utils.php';
$videoHeight = 360;
if (!isset($config) || !is_array($config)) {
    die("broken or missing configuration file?");
}
date_default_timezone_set(getConfig($config, 'time_zone', FALSE, 'Europe/Amsterdam'));
$dbName = getConfig($config, 'db_name', TRUE);
require_once "ext/sag/src/Sag.php";
$storage = new Sag();
$storage->setDatabase($dbName);
do {
    $transcodingNow = $storage->get("_design/files/_view/get_media_status?limit=1&startkey=[\"PROGRESS\"]&endkey=[\"PROGRESS\",{}]")->body->rows;
    if (!empty($transcodingNow)) {
        $t = $transcodingNow[0];
        $id = $t->id;
        $info = $storage->get($id)->body;
        if (isset($info->video)) {
            $progress = determineProgress($info->video->transcode->{$videoHeight}->file . ".log", $info->video->duration);
        } elseif (isset($info->audio)) {
            $progress = determineProgress($info->audio->transcode->file . ".log", $info->audio->duration);
        }
        $info->transcodeProgress = $progress;
        $storage->put($id, $info);
    }
    sleep(10);
} while (TRUE);
function determineProgress($logFile, $mediaDuration)
Example #6
0
File: index.php Project: xwiz/sag
require_once '../../src/Sag.php';
session_start();
try {
    // We are going to get our page's content from Sag.
    $sag = new Sag('sbisbee.com');
    $sag->setDatabase('outlook');
    if ($_POST['login']) {
        echo '<p>Using login()';
        $_SESSION['AuthSession'] = $sag->login($_POST['username'], $_POST['password'], $sag::$AUTH_COOKIE);
    } else {
        if ($_SESSION['AuthSession']) {
            echo '<p>Using setCookie()';
            $sag->setCookie('AuthSession', $_SESSION['AuthSession']);
        }
    }
    $result = $sag->get('/');
} catch (Exception $e) {
    $error = $e->getMessage();
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  <head>
    <meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
    <title>proxyCookie example</title>
  </head>
  <body>
    <?php 
echo "<p>{$error}";
if ($result) {