Example #1
0
File: user.php Project: josf/folkso
/**
 * Just a list of tags
 */
function getMyTags(folksoQuery $q, folksoDBconnect $dbc, folksoSession $fks)
{
    $r = new folksoResponse();
    $u = $fks->userSession();
    if (!$u instanceof folksoUser) {
        if (!$q->is_param('uid')) {
            return $r->unAuthorized($u);
            // add message about logging in?
        } else {
            $userid = $q->get_param('uid');
        }
    }
    $userid = $userid ? $userid : $u->userid;
    try {
        $i = new folksoDBinteract($dbc);
        $sql = sprintf('  select t.tagnorm, t.id, t.tagdisplay, count(te.tag_id) as cnt, tagtime' . ' from tag t ' . ' join tagevent te on t.id = te.tag_id ' . " where te.userid = '%s' " . ' group by t.tagnorm ' . ' order by tagtime ' . ' limit 50', $i->dbescape($userid));
        $i->query($sql);
    } catch (dbException $e) {
        return $r->handleDBexception($e);
    }
    if ($i->rowCount == 0) {
        return $r->setOk(204, 'No tags found');
    }
    $r->setOk(200, 'Tags found');
    $df = new folksoDisplayFactory();
    if ($q->content_type() == 'json') {
        $disp = $df->json(array('resid', 'tagnorm', 'link', 'tagdisplay', 'count'));
    } else {
        $disp = $df->simpleTagList('xml');
    }
    $r->t($disp->startform());
    while ($row = $i->result->fetch_object()) {
        $link = new folksoTagLink($row->tagnorm);
        $r->t($disp->line(htmlspecialchars($row->id), htmlspecialchars($row->tagnorm), htmlspecialchars($link->getLink()), htmlspecialchars($row->tagdisplay), htmlspecialchars($row->cnt)));
    }
    $r->t($disp->endform());
    return $r;
}
Example #2
0
/**
 * 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;
    }
}