function testExistence() { $i = new folksoDBinteract($this->dbc); $this->assertTrue($i->resourcep('http://example.com/1'), 'Not reporting existence of example.com/1 (resourcep)'); $dbc2 = new folksoDBconnect('localhost', 'tester_dude', 'testy', 'testostonomie'); $i2 = new folksoDBinteract($dbc2); $this->assertTrue($i2->tagp('tagone'), 'Not reporting existence of "tagone"'); $this->assertFalse($i2->db_error(), 'tagp() is returning an DB error'); $this->assertTrue($i2->tagp(1), 'numeric tagp not reporting existence of tag 1'); $this->assertEqual($i2->db->real_escape_string('tagone'), 'tagone', 'Strangeness using real_escape_string'); $this->assertFalse($i2->tagp('false tag'), 'Reporting existence of non-existant tag'); $this->assertFalse($i2->tagp(199), 'Reporting existence of non-existant tag (numeric)'); }
/** * Given a resource, this function fetches that resource and updates * its status in the database if anything has changed, in particular * the title field. * * If the resource is no longer available (returns 404), the resource * is removed. Is this too radical? * */ function reload(folksoQuery $q, folksoWsseCreds $cred, folksoDBconnect $dbc) { $i = new folksoDBinteract($dbc); if ($i->db_error()) { header('HTTP/1.0 501 Database connection error'); die($i->error_info()); } /** check initial url **/ $url = ''; if (is_numeric($q->res)) { $url = $i->url_from_id($q->res); if ($url = 0) { // no corresponding url header('HTTP/1.1 404 Resource not found.'); print "The numeric id " . $q->res . " that was provided does not correspond " . " to an existing resource. Perhaps the resource has been deleted."; return; } } else { $url = $q->res; if (!$i->resourcep($url)) { header('HTTP/1.1 404 Resource not found'); print "The url provided (" . $q->res . ") was not found in the database. " . "It must be added before it can be modified."; return; } } /** do request **/ $ch = curl_init($url); curl_setopt($ch, CURLOPT_USERAGENT, 'folksoClient'); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $result = curl_exec($ch); $result_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); /** react to request results **/ $rq = new folksoResupQuery(); switch ($result_code) { case '404': $i->query($rq->resremove($url)); header('http/1.1 200 Deleted'); print "Removed the resource {$url} from the system."; return; break; case '200': $i->query($rq->resmodtitle($url, $newtitle)); } }
function getNotes(folksoquery $q, folksoDBconnect $dbc, folksoSession $fks) { $r = new folksoResponse(); $u = $fks->userSession(null, 'folkso', 'redac'); if (!$u instanceof folksoUser || !$u->checkUserRight('folkso', 'redac')) { return $r->unAuthorized($u); } try { $i = new folksoDBinteract($dbc); $sql = "SELECT note, user_id, id \n\t" . "FROM note n \n\t" . "WHERE n.resource_id = "; if (is_numeric($q->res)) { $sql .= $q->res; } else { $sql .= "(SELECT id FROM resource r \n\t" . " WHERE r.uri_normal = url_whack('" . $q->res . "'))"; } $i->query($sql); } catch (dbException $e) { return $r->handleDBexception($e); } if ($i->result_status == 'NOROWS') { if ($i->resourcep($q->res)) { $r->setError(404, 'No notes associated with this resource', "No notes have been written yet. Write one if you want."); } else { $r->setError(404, 'Resource not found', "Sorry. The resource for which you requested an annotation" . " is not present in the database"); } return $r; } $r->setOk(200, 'Notes found'); // assuming 200 from here on $df = new folksoDisplayFactory(); $dd = $df->NoteList(); $dd->activate_style('xml'); $r->t($dd->startform()); $r->t($dd->title($q->res)); while ($row = $i->result->fetch_object()) { $r->t($dd->line($row->user_id, $row->id, $row->note)); } $r->t($dd->endform()); return $r; }