function checkCreateCDB() { $globalsres = sqlStatement("SELECT gl_name, gl_index, gl_value FROM globals WHERE gl_name IN \n ('couchdb_host','couchdb_user','couchdb_pass','couchdb_port','couchdb_dbase','document_storage_method')"); $options = array(); while ($globalsrow = sqlFetchArray($globalsres)) { $GLOBALS[$globalsrow['gl_name']] = $globalsrow['gl_value']; } $directory_created = false; if ($GLOBALS['document_storage_method'] != 0) { // /documents/temp/ folder is required for CouchDB if (!is_dir($GLOBALS['OE_SITE_DIR'] . '/documents/temp/')) { $directory_created = mkdir($GLOBALS['OE_SITE_DIR'] . '/documents/temp/', 0777, true); if (!$directory_created) { echo htmlspecialchars(xl("Failed to create temporary folder. CouchDB will not work."), ENT_NOQUOTES); } } $couch = new CouchDB(); if (!$couch->check_connection()) { echo "<script type='text/javascript'>alert('" . addslashes(xl("CouchDB Connection Failed.")) . "');</script>"; return; } if ($GLOBALS['couchdb_host'] || $GLOBALS['couchdb_port'] || $GLOBALS['couchdb_dbase']) { $couch->createDB($GLOBALS['couchdb_dbase']); $couch->createView($GLOBALS['couchdb_dbase']); } } return true; }
public function update() { $json_data = CouchDB::encode_json($this->data); if ($this->_rev) { return $this->db->send($this->_id . '?rev=' . $this->_rev, 'put', $json_data); } return $this->db->send($this->_id, 'put', $json_data); }
/** * * @return couchClient */ public static function client() { if (self::$_client == null) { $basepath = Pimple::instance()->getRessource('lib/phponcouch/'); require_once "{$basepath}/couch.php"; require_once "{$basepath}/couchAdmin.php"; require_once "{$basepath}/couchClient.php"; require_once "{$basepath}/couchDocument.php"; require_once "{$basepath}/couchReplicator.php"; self::$_client = new couchClient(Settings::get(self::URL), Settings::get(self::NAME)); } return self::$_client; }
public function loadFromSID($SID) { $result = CouchDB::client()->key($SID)->include_docs(true)->getView("session", 'all'); if (count($result->rows) > 0) { $this->document = current($result->rows)->doc; } if (!$this->document) { $this->document = new stdClass(); } $this->document->SID = $SID; $this->document->type = 'session'; $this->document->expires = SessionHandler::instance()->getExpires(); return $this; }
public static function save($userDoc) { if (!$userDoc->email) { return false; } //Ensure that type is always user $userDoc->type = 'user'; $result = CouchDB::client()->key($userDoc->email)->getView('users', 'by-email'); if (count($result->rows)) { return false; } CouchDB::client()->storeDoc($userDoc); return self::byEmail($userDoc->email); }
public function postToDesignDocForm($r) { $doc = new CouchDB_Document($this->db); $doc->_id = '_design/' . $r->get('title'); if ($r->get('rev')) { $doc->_rev = $r->get('rev'); } $views = '{' . trim($r->get('views')) . '}'; $views = html_entity_decode($views, ENT_COMPAT, 'UTF-8'); $php = CouchDB::decode_json($views); $doc->views = $php->views; $doc->save(); $r->renderRedirect('home'); }
private function action($form) { $u = new User(); $u->username = strtolower($form->email); $u->screenname = $form->screenname; $u->password = $form->password; $u->lastLogin = time(); $u->isValid = false; $u->columns['bitmap_normal']->value = User::kProfileDefaultNormal; $u->columns['bitmap_bigger']->value = User::kProfileDefaultBigger; $u->save(); //echo $u->bitmap_normal; //exit; //$session = Application::session(); //$session->regenerate(true); //$session->id = $u->id; //$session->screenname = $u->screenname; //$session->isAuthenticated = true; $session = session_currentSession(); session_regenerateCurrentSession(); session_setValueForKey($u->id, 'id'); session_setValueForKey($u->screenname, 'screenname'); session_setValueForKey(true, 'isAuthenticated'); // generate a random key for the user to authenticate against: $stream = fopen('/dev/random', 'r'); $bytes = fread($stream, 512); fclose($stream); $key = hash('md5', base64_encode($bytes)); $authorized = array('type' => 'authorization', 'user' => $u->id, 'key' => $key); $db = new CouchDB(array('database' => Configuration::kDatabaseName)); $db->put(json_encode($authorized)); $email = array(); $email['recipients'][] = $u->username; $email['key'] = $key; email_sendAccountCreate($email); header('location:/'); }
<?php define("DATABASE_NAME", 'foxy-orders'); $couchdb = new CouchDB(DATABASE_NAME); try { $response = $couchdb->getDoc('preferences'); } catch (CouchDBException $e) { die($e->getMessage() . "\n"); } $preferences = $response->getBodyAsObject(); if (!$preferences || !$preferences->shared_secret || !$preferences->install_url) { die("Foxycouch hasn't been set up properly -- please make sure there is a document with ID 'preferences' that has 'shared_secret' and 'install_url' fields in the " . DATABASE_NAME . " database"); }
<?php require_once "couchdb.php"; $db = new CouchDB('hn'); $result = $db->get_item('_design/entries/_view/latest?limit=30&descending=true'); $rows = $result->getBody(true)->rows; ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.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" /> <link rel="stylesheet" href="css/screen.css" type="text/css" media="screen, projection" /> <link rel="stylesheet" href="css/print.css" type="text/css" media="print" /> <!--[if IE]><link rel="stylesheet" href="css/ie.css" type="text/css" media="screen, projection" /><![endif]--> <link rel="stylesheet" href="css/main.css" type="text/css" media="screen, projection" /> <script type="text/javascript" src="js/jquery.js"></script> <title>Hacker News (local)</title> </head> <body> <div class="container"> <div id="header"> <h2 class="site_id"><a href=".">news.ycombinator.local</a></h2> </div> <div id="stuff" class="main_content"> <div class="pad_28"> <ol> <?php foreach ($rows as $r) { echo "<li>";
function getBody($decode_json = false) { return $decode_json ? CouchDB::decode_json($this->body) : $this->body; }
<?php $options = array('host' => 'sync.renegde.com', 'port' => 80); $db = new CouchDB($options); $map = "function(doc) { emit(doc._id, doc);}"; $response = $db->temp_view($map); print_r($response);
//STOP FAKE REGISTER GLOBALS $fake_register_globals = false; // require_once dirname(__FILE__) . "/../../interface/globals.php"; require_once dirname(__FILE__) . "/../parse_patient_xml.php"; require_once dirname(__FILE__) . "/../classes/Document.class.php"; require_once dirname(__FILE__) . "/../classes/CouchDB.class.php"; if ($_REQUEST["ccr_ajax"] == "yes") { $doc_id = $_REQUEST["document_id"]; $d = new Document($doc_id); $url = $d->get_url(); $storagemethod = $d->get_storagemethod(); $couch_docid = $d->get_couch_docid(); $couch_revid = $d->get_couch_revid(); if ($storagemethod == 1) { $couch = new CouchDB(); $data = array($GLOBALS['couchdb_dbase'], $couch_docid); $resp = $couch->retrieve_doc($data); $content = $resp->data; if ($content == '' && $GLOBALS['couchdb_log'] == 1) { $log_content = date('Y-m-d H:i:s') . " ==> Retrieving document\r\n"; $log_content = date('Y-m-d H:i:s') . " ==> URL: " . $url . "\r\n"; $log_content .= date('Y-m-d H:i:s') . " ==> CouchDB Document Id: " . $couch_docid . "\r\n"; $log_content .= date('Y-m-d H:i:s') . " ==> CouchDB Revision Id: " . $couch_revid . "\r\n"; $log_content .= date('Y-m-d H:i:s') . " ==> Failed to fetch document content from CouchDB.\r\n"; $log_content .= date('Y-m-d H:i:s') . " ==> Will try to download file from HardDisk if exists.\r\n\r\n"; $this->document_upload_download_log($d->get_foreign_id(), $log_content); die(xlt("File retrieval from CouchDB failed")); } $content = base64_decode($content); } else {
* Copyright (C) 2009 Adam Venturella * * LICENSE: * * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy * of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR * PURPOSE. See the License for the specific language governing permissions and * limitations under the License. * * Author: Adam Venturella - aventurella@gmail.com * * @package Sample * @author Adam Venturella <*****@*****.**> * @copyright Copyright (C) 2009 Adam Venturella * @license http://www.apache.org/licenses/LICENSE-2.0 Apache 2.0 * **/ /** * Sample */ require 'couchdb/CouchDB.php'; $newdb = 'newdb'; $options = array('database' => $newdb); $db = new CouchDB($options); echo '<pre>', print_r($db->info(), true), '</pre>';
<?php $user =& User::singleton(); if (!$user->hasPermission('dataquery_view')) { header("HTTP/1.1 403 Forbidden"); exit; } require_once __DIR__ . '/../../../vendor/autoload.php'; $client = new NDB_Client(); $client->makeCommandLine(); $client->initialize(__DIR__ . "/../../../project/config.xml"); $cdb = CouchDB::singleton(); $category = $_REQUEST['category']; $results = $cdb->queryView("DQG-2.0", "datadictionary", array("reduce" => "false", "startkey" => "[\"{$category}\"]", "endkey" => "[\"{$category}\", \"ZZZZZZZZ\"]")); print json_encode($results);
/** * Create a new document and store its data. * This is a mix of new code and code moved from C_Document.class.php. * * @param string $patient_id Patient pid; if not known then this may be a simple directory name * @param integer $category_id The desired document category ID * @param string $filename Desired filename, may be modified for uniqueness * @param string $mimetype MIME type * @param string &$data The actual data to store (not encoded) * @param string $higher_level_path Optional subdirectory within the local document repository * @param string $path_depth Number of directory levels in $higher_level_path, if specified * @param integer $owner Owner/user/service that is requesting this action * @return string Empty string if success, otherwise error message text */ function createDocument($patient_id, $category_id, $filename, $mimetype, &$data, $higher_level_path = '', $path_depth = 1, $owner = 0) { // The original code used the encounter ID but never set it to anything. // That was probably a mistake, but we reference it here for documentation // and leave it empty. Logically, documents are not tied to encounters. $encounter_id = ''; $this->storagemethod = $GLOBALS['document_storage_method']; $this->mimetype = $mimetype; if ($this->storagemethod == 1) { // Store it using CouchDB. $couch = new CouchDB(); $docname = $_SESSION['authId'] . $filename . $patient_id . $encounter_id . date("%Y-%m-%d H:i:s"); $docid = $couch->stringToId($docname); $json = json_encode(base64_encode($data)); $db = $GLOBALS['couchdb_dbase']; $couchdata = array($db, $docid, $patient_id, $encounter_id, $mimetype, $json); $resp = $couch->check_saveDOC($couchdata); if (!$resp->id || !$resp->_rev) { // Not sure what this is supposed to do. The references to id, rev, // _id and _rev seem pretty weird. $couchdata = array($db, $docid, $patient_id, $encounter_id); $resp = $couch->retrieve_doc($couchdata); $docid = $resp->_id; $revid = $resp->_rev; } else { $docid = $resp->id; $revid = $resp->rev; } if (!$docid && !$revid) { return xl('CouchDB save failed'); } $this->url = $filename; $this->couch_docid = $docid; $this->couch_revid = $revid; } else { // Storing document files locally. $repository = $GLOBALS['oer_config']['documents']['repository']; $higher_level_path = preg_replace("/[^A-Za-z0-9\\/]/", "_", $higher_level_path); if (!empty($higher_level_path) && (is_numeric($patient_id) && $patient_id > 0)) { // Allow higher level directory structure in documents directory and a patient is mapped. $filepath = $repository . $higher_level_path . "/"; } else { if (!empty($higher_level_path)) { // Allow higher level directory structure in documents directory and there is no patient mapping // (will create up to 10000 random directories and increment the path_depth by 1). $filepath = $repository . $higher_level_path . '/' . rand(1, 10000) . '/'; ++$path_depth; } else { if (!is_numeric($patient_id) || !($patient_id > 0)) { // This is the default action except there is no patient mapping (when patient_id is 00 or direct) // (will create up to 10000 random directories and set the path_depth to 2). $filepath = $repository . $patient_id . '/' . rand(1, 10000) . '/'; $path_depth = 2; $patient_id = 0; } else { // This is the default action where the patient is used as one level directory structure in documents directory. $filepath = $repository . $patient_id . '/'; $path_depth = 1; } } } if (!file_exists($filepath)) { if (!mkdir($filepath, 0700, true)) { return xl('Unable to create patient document subdirectory'); } } // Filename modification to force valid characters and uniqueness. $filename = preg_replace("/[^a-zA-Z0-9_.]/", "_", $filename); $fnsuffix = 0; $fn1 = $filename; $fn2 = ''; $fn3 = ''; $dotpos = strrpos($filename, '.'); if ($dotpos !== FALSE) { $fn1 = substr($filename, 0, $dotpos); $fn2 = '.'; $fn3 = substr($filename, $dotpos + 1); } while (file_exists($filepath . $filename)) { if (++$fnsuffix > 10000) { return xl('Failed to compute a unique filename'); } $filename = $fn1 . '_' . $fnsuffix . $fn2 . $fn3; } $this->url = "file://" . $filepath . $filename; if (is_numeric($path_depth)) { // this is for when directory structure is more than one level $this->path_depth = $path_depth; } // Store the file into its proper directory. if (file_put_contents($filepath . $filename, $data) === FALSE) { return xl('Failed to create') . " {$filepath}{$filename}"; } } $this->size = strlen($data); $this->hash = sha1($data); $this->type = $this->type_array['file_url']; $this->owner = $owner ? $owner : $_SESSION['authUserID']; $this->set_foreign_id($patient_id); $this->persist(); $this->populate(); if (is_numeric($this->get_id()) && is_numeric($category_id)) { $sql = "REPLACE INTO categories_to_documents set " . "category_id = '{$category_id}', " . "document_id = '" . $this->get_id() . "'"; $this->_db->Execute($sql); } return ''; }
function change_patient($new_patient_id) { $couch_docid = $this->get_couch_docid(); $couch_revid = $this->get_couch_revid(); // Set the new patient in CouchDB. if ($couch_docid && $couch_revid) { $couch = new CouchDB(); $db = $GLOBALS['couchdb_dbase']; $data = array($db, $couch_docid); $couchresp = $couch->retrieve_doc($data); // CouchDB doesnot support updating a single value in a document. // Have to retrieve the entire document, update the necessary value and save again list($db, $docid, $revid, $patient_id, $encounter, $type, $json) = $data; $data = array($db, $couch_docid, $couch_revid, $new_patient_id, $couchresp->encounter, $couchresp->mimetype, json_encode($couchresp->data)); $resp = $couch->update_doc($data); // Sometimes the response from CouchDB is not available, still it would // have saved in the DB. Hence check one more time. if (!$resp->_id || !$resp->_rev) { $data = array($db, $couch_docid, $new_patient_id, $couchresp->encounter); $resp = $couch->retrieve_doc($data); } if ($resp->_rev == $couch_revid) { return false; } else { $this->set_couch_revid($resp->_rev); } } // Set the new patient in mysql. $this->set_foreign_id($new_patient_id); $this->persist(); // Return true for success. return true; }
* Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy * of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR * PURPOSE. See the License for the specific language governing permissions and * limitations under the License. * * Author: Adam Venturella - aventurella@gmail.com * * @package Sample * @author Adam Venturella <*****@*****.**> * @copyright Copyright (C) 2009 Adam Venturella * @license http://www.apache.org/licenses/LICENSE-2.0 Apache 2.0 * **/ /** * Sample */ require 'couchdb/CouchDB.php'; $newdb = 'newdb'; $options = array('database' => $newdb); $db = new CouchDB($options); $db->compact($newdb); // OR if the 'database' key was specified in the options, // and you wish to create that database, you can call compact // with no arguments. //$db->compact();
public static function get($projectId) { return CouchDB::client()->getDoc($projectId); }
<?php $type = $_GET['type']; $tag = $_GET['tag']; require_once "couchdb.php"; $db = new CouchDB('taskbin'); $result = $db->get_item('_design/tasks/_view/' . $type); $total_rows = $result->getBody(true)->total_rows; $rows = $result->getBody(true)->rows; $rows = array_reverse($rows); switch ($type) { case 'inbox': $ref = 'a'; break; case 'next': $ref = 'b'; break; case 'someday': $ref = 'c'; break; default: $ref = ''; } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.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" /> <link rel="stylesheet" href="css/screen.css" type="text/css" media="screen, projection" />
* * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR * PURPOSE. See the License for the specific language governing permissions and * limitations under the License. * * Author: Adam Venturella - aventurella@gmail.com * * @package Sample * @author Adam Venturella <*****@*****.**> * @copyright Copyright (C) 2009 Adam Venturella * @license http://www.apache.org/licenses/LICENSE-2.0 Apache 2.0 * **/ /** * Sample */ require 'couchdb/CouchDB.php'; $newdb = 'newdb'; $options = array('database' => $newdb); $db = new CouchDB($options); $map = <<<MAP \tfunction(doc) \t{ \t\tif(doc.type == 'category') \t\t{ \t\t\temit(doc._id, doc); \t\t} \t} MAP; $db->create_view('myviews/categories', $map);
function get_couch_url($pid, $encounter) { $couch_docid = $this->get_couch_docid(); $couch_url = $this->get_url(); $couch = new CouchDB(); $data = array($GLOBALS['couchdb_dbase'], $couch_docid, $pid, $encounter); $resp = $couch->retrieve_doc($data); $content = $resp->data; $temp_url = $couch_url; $temp_url = $GLOBALS['OE_SITE_DIR'] . '/documents/temp/' . $pid . '_' . $couch_url; $f_CDB = fopen($temp_url, 'w'); fwrite($f_CDB, base64_decode($content)); fclose($f_CDB); return $temp_url; }
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR * PURPOSE. See the License for the specific language governing permissions and * limitations under the License. * * Author: Adam Venturella - aventurella@gmail.com * * @package Sample * @author Adam Venturella <*****@*****.**> * @copyright Copyright (C) 2009 Adam Venturella * @license http://www.apache.org/licenses/LICENSE-2.0 Apache 2.0 * **/ /** * Sample */ require 'couchdb/CouchDB.php'; $newdb = 'newdb'; $options = array('database' => $newdb); $db = new CouchDB($options); $document_id = 'target_documnet_id'; $document_revision = 'revision_id'; $attachmentName = 'avatar'; $attachmentPath = '/path/to/file.png'; $attachment['name'] = $attachmentName; $attachment['path'] = $attachmentPath; // The system will currently figure out the content type for gif, jpeg, and png // if the attachment is not one of those 3 then it will assume binary/octet-stream // unless the 'content-type' key is provided. $db->put_attachment($attachment, $document_id); // avoid an extra lookup by provding the latest document revsion: // $db->put_attachment($attachment, $document_id, $document_revision);
function validate_action_process($patient_id = "", $document_id) { $d = new Document($document_id); if ($d->couch_docid && $d->couch_revid) { $file_path = $GLOBALS['OE_SITE_DIR'] . '/documents/temp/'; $url = $file_path . $d->get_url(); $couch = new CouchDB(); $data = array($GLOBALS['couchdb_dbase'], $d->couch_docid); $resp = $couch->retrieve_doc($data); $content = $resp->data; //--------Temporarily writing the file for calculating the hash--------// //-----------Will be removed after calculating the hash value----------// $temp_file = fopen($url, "w"); fwrite($temp_file, base64_decode($content)); fclose($temp_file); } else { $url = $d->get_url(); //strip url of protocol handler $url = preg_replace("|^(.*)://|", "", $url); //change full path to current webroot. this is for documents that may have //been moved from a different filesystem and the full path in the database //is not current. this is also for documents that may of been moved to //different patients. Note that the path_depth is used to see how far down //the path to go. For example, originally the path_depth was always 1, which //only allowed things like documents/1/<file>, but now can have more structured //directories. For example a path_depth of 2 can give documents/encounters/1/<file> // etc. // NOTE that $from_filename and basename($url) are the same thing $from_all = explode("/", $url); $from_filename = array_pop($from_all); $from_pathname_array = array(); for ($i = 0; $i < $d->get_path_depth(); $i++) { $from_pathname_array[] = array_pop($from_all); } $from_pathname_array = array_reverse($from_pathname_array); $from_pathname = implode("/", $from_pathname_array); $temp_url = $GLOBALS['OE_SITE_DIR'] . '/documents/' . $from_pathname . '/' . $from_filename; if (file_exists($temp_url)) { $url = $temp_url; } if ($_POST['process'] != "true") { die("process is '" . $_POST['process'] . "', expected 'true'"); return; } } $d = new Document($document_id); $current_hash = sha1_file($url); $messages = xl('Current Hash') . ": " . $current_hash . "<br>"; $messages .= xl('Stored Hash') . ": " . $d->get_hash() . "<br>"; if ($d->get_hash() == '') { $d->hash = $current_hash; $d->persist(); $d->populate(); $messages .= xl('Hash did not exist for this file. A new hash was generated.'); } else { if ($current_hash != $d->get_hash()) { $messages .= xl('Hash does not match. Data integrity has been compromised.'); } else { $messages .= xl('Document passed integrity check.'); } } $this->_state = false; $this->assign("messages", $messages); if ($d->couch_docid && $d->couch_revid) { //Removing the temporary file which is used to create the hash unlink($GLOBALS['OE_SITE_DIR'] . '/documents/temp/' . $d->get_url()); } return $this->view_action($patient_id, $document_id); }
* http://www.apache.org/licenses/LICENSE-2.0 * * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR * PURPOSE. See the License for the specific language governing permissions and * limitations under the License. * * Author: Adam Venturella - aventurella@gmail.com * * @package Sample * @author Adam Venturella <*****@*****.**> * @copyright Copyright (C) 2009 Adam Venturella * @license http://www.apache.org/licenses/LICENSE-2.0 Apache 2.0 * **/ /** * Sample */ require 'couchdb/CouchDB.php'; $newdb = 'newdb'; $options = array('database' => $newdb); $db = new CouchDB($options); $document_id = 'target_documnet_id'; $document_revision = 'revision_id'; $attachmentName = 'avatar'; // assumes a documnet exists with a given id, and that document has an attachment // named 'avatar' $data = $db->attachment($document_id, $attachmentName); // be aware, that if the attachments represents an image, or any other binary data, $data // will contain that raw information echo $data;
* Copyright (C) 2009 Adam Venturella * * LICENSE: * * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy * of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR * PURPOSE. See the License for the specific language governing permissions and * limitations under the License. * * Author: Adam Venturella - aventurella@gmail.com * * @package Sample * @author Adam Venturella <*****@*****.**> * @copyright Copyright (C) 2009 Adam Venturella * @license http://www.apache.org/licenses/LICENSE-2.0 Apache 2.0 * **/ /** * Sample */ require 'couchdb/CouchDB.php'; // need to be a server administrator to create users $options = array('authorization' => 'basic', 'username' => 'admin', 'password' => 'admin'); $db = new CouchDB($options); $db->user_update('testuser', 'secretpassword', '*****@*****.**', array('foo', 'bar'));
function result() { $options = array('database' => Configuration::kDatabaseName); $db = new CouchDB($options); return $db->view('categories/all'); }
function __construct() { $this->SQLDB = Database::singleton(); $this->CouchDB = CouchDB::singleton(); }
* PURPOSE. See the License for the specific language governing permissions and * limitations under the License. * * Author: Adam Venturella - aventurella@gmail.com * * @package Sample * @author Adam Venturella <*****@*****.**> * @copyright Copyright (C) 2009 Adam Venturella * @license http://www.apache.org/licenses/LICENSE-2.0 Apache 2.0 * **/ /** * Sample */ require 'couchdb/CouchDB.php'; /* Note that you DO NOT have to be an administrator to view a users info. You will most likely want to set: [couch_httpd_auth] require_valid_user = true in your local.ini or default.ini on OS X you can find them here if you compiled from source: /usr/local/etc/couchdb and set your users roles/acl accordingly to exclude the users db */ $db = new CouchDB(); $user = $db->user('testuser'); print_r($user);
* * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy * of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR * PURPOSE. See the License for the specific language governing permissions and * limitations under the License. * * Author: Adam Venturella - aventurella@gmail.com * * @package Sample * @author Adam Venturella <*****@*****.**> * @copyright Copyright (C) 2009 Adam Venturella * @license http://www.apache.org/licenses/LICENSE-2.0 Apache 2.0 * **/ /** * Sample */ require 'couchdb/CouchDB.php'; $newdb = 'newdb'; $options = array('database' => $newdb); $db = new CouchDB($options); $document_id = 'target_documnet_id'; // Get an existing document $document = $db->document($document_id); echo '<pre>', print_r($document, true), '</pre>';
* http://www.apache.org/licenses/LICENSE-2.0 * * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR * PURPOSE. See the License for the specific language governing permissions and * limitations under the License. * * Author: Adam Venturella - aventurella@gmail.com * * @package Sample * @author Adam Venturella <*****@*****.**> * @copyright Copyright (C) 2009 Adam Venturella * @license http://www.apache.org/licenses/LICENSE-2.0 Apache 2.0 * **/ /** * Sample */ require 'couchdb/CouchDB.php'; $newdb = 'newdb'; $options = array('database' => $newdb); $db = new CouchDB($options); $query_options = array('key' => '*****@*****.**'); $view = $db->view('users/all'); $viewWithQueryOptions = $db->view('users/all', $query_options); // get the first result: echo '<p>', print_r($viewWithQueryOptions[0], true), '</p>'; // loop over all of the results foreach ($view as $row) { echo '<pre>', print_r($row, true), '</pre>'; }