function getAllMetas(folksoQuery $q, folksoWsseCreds $cred, folksoDBconnect $dbc) { $i = new folksoDBinteract($dbc); if ($i->db_error()) { header('HTTP/1.1 501 Database error'); die($i->error_info()); } $sql = 'SELECT id, tagdisplay FROM metatag WHERE id <> 1'; $i->query($sql); switch ($i->result_status) { case 'DBERR': header('HTTP/1.1 501 Database error'); die($i->error_info()); break; case 'NOROWS': header('HTTP/1.1 204 There is a problem with the metatag list'); return; break; case 'OK': header('HTTP/1.1 200 Metataglist sent'); header('Content-Type: text/xml'); break; } $df = new folksoDisplayFactory(); $dd = $df->MetatagList(); $dd->activate_style('xml'); print $dd->startform(); while ($row = $i->result->fetch_object()) { print $dd->line($row->id, $row->tagdisplay); } print $dd->endform(); }
function testOutput() { $this->assertEqual($this->dd->line("bob", "slob"), '<a href="bob">slob</a>'); $thing = array('xhtml' => 'Randy', 'default' => 'Slacker'); $this->assertEqual($this->dd->line("bob", $thing), '<a href="bob">Randy</a>'); $this->assertTrue($this->dd->activate_style('text')); print $this->dd->type; $this->assertEqual($this->dd->type, 'text'); $this->assertEqual($this->dd->line("bob", $thing), '-- bob : Slacker'); $this->assertEqual($this->dd->line("bob", array("default" => "something")), '-- bob : something'); $df = new folksoDisplayFactory(); $dd2 = $df->FancyResourceList(); $this->assertIsA($dd2, folksoDataDisplay); $dd2->activate_style('xml'); $this->assertEqual($dd2->type, 'xml'); $ltext = $dd2->line('abcXXXdef', 'WWW', 'Bob is a slob', 'plooof'); $this->assertPattern('/<numid>abcXXXdef/', $ltext); $this->assertPattern('/<url>WWW<\\/url>/', $ltext); }
/** * List of all the tags. */ function allTags(folksoQuery $q, folksoDBconnect $dbc, folksoSession $fks) { $r = new folksoResponse(); try { $i = new folksoDBinteract($dbc); $query = "SELECT t.tagdisplay AS display, t.id AS tagid, \n\t" . "t.tagnorm AS tagnorm, \n\t" . "(SELECT COUNT(*) FROM tagevent te WHERE te.tag_id = t.id) AS popularity \n" . "FROM tag t \n" . " ORDER BY display "; $i->query($query); } catch (dbException $e) { return $r->handleDBexception($e); } $r->setOk(200, 'There they are'); $df = new folksoDisplayFactory(); $dd = $df->TagList(); $dd->activate_style('xml'); $r->t($dd->startform()); while ($row = $i->result->fetch_object()) { $r->t($dd->line($row->tagid, $row->tagnorm, $row->display, $row->popularity, '')); } $r->t($dd->endform()); return $r; }
/** * Returns an xml list of resources associated with the same ean-13 as * the selected resource * * Web params: GET, folksores, folksoean13list */ function resEans(folksoQuery $q, folksoDBconnect $dbc, folksoSession $fks) { $r = new folksoResponse(); try { $i = new folksoDBinteract($dbc); if ($i->db_error()) { $r->dbConnectionError($i->error_info()); return $r; } $rq = new folksoResQuery(); $sql = $rq->resEans($i->dbescape($q->res)); $i->query($sql); } catch (dbConnectionException $e) { $r->dbConnectionError($e->getMessage()); return $r; } catch (dbQueryException $e) { $r->dbQueryError($e->getMessage() . $e->sqlquery); return $r; } switch ($i->result_status) { case 'NOROWS': $r->setError(404, 'Resource not found', "The requested resource is not present in the database.\n" . " Maybe it has not been indexed yet, or an erroneous identifier " . " was used. "); return $r; break; case 'OK': if ($i->result->num_rows == 1) { $r->setError(404, 'No EAN-13 data associated with this resource', "There is no EAN-13 data yet for the resource " . $q->res . "."); return $r; } else { $r->setOk(200, 'EAN-13 data found'); } } $title_line = $i->result->fetch_object(); /**popping the title that we are not using, but we could if we needed too (see note in ResQuery) **/ $df = new folksoDisplayFactory(); $dd = $df->associatedEan13resources(); $dd->activate_style('xml'); $r->t($dd->startform()); while ($row = $i->result->fetch_object()) { $r->t($dd->line($row->id, $row->url, $row->title)); } $r->t($dd->endform()); return $r; }
/** * * */ function getUserResByTag(folksoQuery $q, folksoDBconnect $dbc, folksoSession $fks) { $r = new folksoResponse(); try { $u = $fks->userSession(null); if (!$u instanceof folksoUser && !$q->is_param('user')) { return $r->setError(404, 'No user'); } elseif ($q->is_param('user')) { $u = new folksoUser($dbc); // we create a user object anyway $u->setUid($q->get_param('user')); if (!$u->exists($q->get_param('user'))) { return $r->setError(404, 'Missing or invalid user'); } } $i = new folksoDBinteract($dbc); $uq = new folksoUserQuery(); $sql = $uq->resourcesByTag($q->tag, $u->userid); $i->query($sql); /* these are inside the try block because exists() hits the DB */ if ($i->rowCount == 0) { if (isset($u->nick) || $u->exists()) { return $r->setOk(204, 'User has no resources with this tag'); } else { // no longer necessary return $r->setError(404, 'Unknown user'); } } } catch (dbException $e) { return $r->handleDBexception($e); } catch (badUseridException $e) { return $r->handleDBexception($e); // TODO: update this with new class } $r->setOk(200, 'Found'); $df = new folksoDisplayFactory(); if ($q->content_type() == 'json') { $dd = new folksoDataJson('resid', 'url', 'title'); } else { $dd = $df->ResourceList('xml'); } $r->t($dd->startform()); while ($row = $i->result->fetch_object()) { $r->t($dd->line($row->id, htmlspecialchars($row->uri_raw), htmlspecialchars($row->title))); } $r->t($dd->endform()); return $r; }