<?php require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . 'common.php'; // create and configure the node connecton object $node = new Services_HyperEstraier_Node(); $node->setUrl($uri); $node->setAuth($user, $pass); // create a document object $doc = new Services_HyperEstraier_Document(); // add attributes to the document object $doc->addAttribute('@uri', 'http://estraier.example.com/example.txt'); $doc->addAttribute('@title', 'Bridge Over The Troubled Water'); // add the body text to the document object $doc->addText('Like a bridge over the troubled water,'); $doc->addText('I will ease your mind.'); // register the document object to the node if (!$node->putDocument($doc)) { fprintf(STDERR, "error: %d\n", $node->status); if (Services_HyperEstraier_Error::hasErrors()) { fputs(STDERR, print_r(Services_HyperEstraier_Error::getErrors(), true)); } } else { fputs(STDOUT, "success.\n"); }
/** * Edit attributes of a document. * * @param object $doc Services_HyperEstraier_Document * which is a document object. * @return bool True if success, else false. * @access public */ public function editDocument(Services_HyperEstraier_Document $doc) { $this->_status = -1; if (!$this->_url) { return false; } $turl = $this->_url . '/edit_doc'; $reqheads = array('content-type' => 'text/x-estraier-draft'); $reqbody = $doc->dumpDraft(); $res = Services_HyperEstraier_Utility::shuttleUrl($turl, $this->_auth, $this->_pxhost, $this->_pxport, $this->_timeout, $reqheads, $reqbody); if (!$res) { return false; } $this->_status = $res->getResponseCode(); return $res->isSuccess(); }
/** * Register the text. * * @param string $url The url of a node server. * Also includes the username and the password. * @param string $text A text data. * @param array $attrs Associated array of the attributes. * At least, requires `@uri' attribute. * @param array $keywords A list of keywords. (optional) * @return bool True if success, else false. * @throws InvalidArgumentException * @access public * @static */ public static function register($url, $text, array $attrs, array $keywords = null) { $node = self::_getNode($url); $doc = new Services_HyperEstraier_Document(); foreach (preg_split('/(?:\\r\\n|\\r|\\n)+/', trim($text)) as $line) { if (substr($line, 0, 1) == "\t") { $doc->addHiddenText($line); } else { $doc->addText($line); } } foreach ($attributes as $name => $value) { $doc->addAttribute($name, $value); } if ($keywords) { $doc->setKeywords($keywords); } return $node->putDocument($doc); }