コード例 #1
0
ファイル: folksoResQuery-test.php プロジェクト: josf/folkso
 function testGetTags()
 {
     $rq = new folksoResQuery();
     $sql = $rq->getTags('http://www.example.com');
     $this->assertTrue(is_string($sql), 'No string returned');
     $this->assertTrue(strlen($sql) > 100, 'sql output is not long enough');
     $this->assertPattern('/example/', $sql, 'Not finding original url in sql');
     $sql_ean = $rq->getTags('http://www.example.com', 0, false, true);
     $this->assertPattern('/ean13/', $sql_ean, 'Not finding ean13 in sql ' . $sql_ean);
     print '==================' . $sql_ean;
 }
コード例 #2
0
ファイル: resource.php プロジェクト: josf/folkso
/**
 * Retrieve the tags associated with a given resource. Accepts uri or
 * id. 
 * 
 * Web parameters : GET + folksores 
 * Optional: metas only
 * Optional: limit
 * Optional: ean13 Includes EAN13 information if available, tagged as 'EAN13'. 
 */
function getTagsIds(folksoQuery $q, folksoDBconnect $dbc, folksoSession $fks)
{
    $r = new folksoResponse();
    try {
        $i = new folksoDBinteract($dbc);
        // check to see if resource is in db.
        if (!$i->resourcep($q->res)) {
            $r->setError(404, 'Resource not found');
            $r->errorBody("Resource not present in database");
            return $r;
        }
        $limit = 0;
        if ($q->is_param('limit') && is_numeric($q->get_param('limit'))) {
            $limit = $q->get_param('limit');
        }
        $metaonly = false;
        if ($q->is_param('metaonly')) {
            $metaonly = true;
        }
        $include_eans = false;
        if ($q->is_param('ean13')) {
            $include_eans = true;
        }
        $rq = new folksoResQuery();
        $select = $rq->getTags($i->dbescape($q->res), $limit, $metaonly, $include_eans);
        $i->query($select);
    } catch (dbException $e) {
        return $r->handleDBexception($e);
    }
    switch ($i->result_status) {
        case 'NOROWS':
            $r->setOk(204, 'No tags associated with resource');
            return $r;
            break;
        case 'OK':
            $r->setOk(200, 'Resource found');
            break;
    }
    // here everything should be ok (200)
    $df = new folksoDisplayFactory();
    $dd = $df->singleElementList();
    $xf = $df->Taglist();
    switch ($q->content_type()) {
        case 'text':
            $r->setType('text');
            $dd->activate_style('text');
            break;
        case 'html':
            $r->setType('html');
            $dd->activate_style('xhtml');
            break;
        case 'xml':
            $r->setType('xml');
            $xf->activate_style('xml');
            $r->t($xf->startform());
            while ($row = $i->result->fetch_object()) {
                $r->t($xf->line($row->id, $row->tagnorm, $row->tagdisplay, $row->popularity, $row->meta));
            }
            $r->t($xf->endform());
            return $r;
            break;
        default:
            $dd->activate_style('xhtml');
            break;
    }
    //    $row = $i->result->fetch_object(); //???
    $r->t($dd->title($row->uri_normal));
    $r->t($dd->startform());
    while ($row = $i->result->fetch_object()) {
        $r->t($dd->line($row->tagdisplay));
    }
    $r->t($dd->endform());
    return $r;
}