コード例 #1
0
ファイル: resource.php プロジェクト: josf/folkso
/**
 * Tag cloud.
 *
 * Parameters: GET, folksoclouduri, res.
 *
 * Optional: folksolimit (limit number of tags returned).
 * Optional: folksobypop (pure popularity based cloud).
 * Optional: folksobydate (date based cloud).
 */
function tagCloudLocalPop(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;
        }
        // using the "limit" parameter
        $taglimit = 0;
        if ($q->is_param('limit') && is_numeric($q->get_param('limit'))) {
            $taglimit = $q->get_param('limit');
        }
        $rq = new folksoResQuery();
        if ($q->is_param('bypop')) {
            $sql = $rq->cloud_by_popularity($i->dbescape($q->res), $taglimit);
        } elseif ($q->is_param('bydate')) {
            $sql = $rq->cloud_by_date($i->dbescape($q->res), $taglimit);
        } else {
            $sql = $rq->basic_cloud($i->dbescape($q->res), $taglimit);
        }
        $i->query($sql);
        switch ($i->result_status) {
            case 'NOROWS':
                // probably impossible now
                $r->setOK(204, 'No tags associated with resource');
                return $r;
                break;
            case 'OK':
                if ($i->result->num_rows == 0) {
                    // should this be == 1 instead?
                    $r->setOK(204, 'No tags associated with resource');
                    return $r;
                } else {
                    $r->setOK(200, 'Cloud OK');
                }
                break;
        }
    } catch (dbException $e) {
        $r->handleDBexception($e);
    }
    $df = new folksoDisplayFactory();
    $dd = $df->cloud();
    //  $row1 = $i->result->fetch_object(); // popping the title line
    /** in CLOUDY
     * tagdisplay = r.title
     * tagnorm = r.uri_raw
     * tagid = r.id
     */
    switch ($q->content_type()) {
        case 'html':
            $dd->activate_style('xhtml');
            $r->setType('html');
            $r->t($dd->title($row1->tagdisplay));
            $r->t($dd->startform());
            // <ul>
            while ($row = $i->result->fetch_object()) {
                $r->t($dd->line($row->cloudweight, "resourceview.php?tagthing=" . $row->tagid, $row->tagdisplay) . "\n");
            }
            $r->t($dd->endform());
            return $r;
            break;
        case 'xml':
            $r->setType('xml');
            $dd->activate_style('xml');
            $r->t($dd->startform());
            $r->t($dd->title($q->res));
            while ($row = $i->result->fetch_object()) {
                $link = new folksoTagLink($row->tagnorm);
                $r->t($dd->line($row->tagid, $row->tagdisplay, htmlspecialchars($link->getLink()), $row->cloudweight, $row->tagnorm) . "\n");
            }
            $r->t($dd->endform());
            return $r;
            break;
        default:
            $r->setError(406, "Invalid or missing specified");
            $r->errorBody("Sorry, but you did not give a datatype and we are too lazy " . " right now to supply a default.");
            return $r;
    }
}