コード例 #1
0
ファイル: tagcomplete.php プロジェクト: josf/folkso
function autocomplete(folksoQuery $q, folksoDBconnect $dbc, folksoSession $fks)
{
    $i = new folksoDBinteract($dbc);
    $r = new folksoResponse();
    if ($i->db_error()) {
        $r->dbConnectionError($i->error_info());
        return $r;
    }
    $sql = "SELECT tagdisplay " . "FROM tag " . "WHERE tagnorm like '" . $i->dbescape(strtolower($q->get_param('q'))) . "%'";
    $i->query($sql);
    switch ($i->result_status) {
        case 'DBERR':
            $r->dbQueryError($i->error_info());
            return $r;
            break;
        case 'NOROWS':
            $r->setOk(204, 'No matching tags');
            return $r;
            break;
        case 'OK':
            $r->setOk(200, 'OK I guess');
            while ($row = $i->result->fetch_object()) {
                /** For entirely numeric tags, we enclose them in quotes so that
                    they can be treated as text instead of as ids. **/
                if (is_numeric($row->tagdisplay)) {
                    $r->t('"' . $row->tagdisplay . '"' . "\n");
                } else {
                    $r->t($row->tagdisplay . "\n");
                }
            }
            return $r;
            break;
    }
}
コード例 #2
0
ファイル: metatag.php プロジェクト: josf/folkso
function metacomplete(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 tagdisplay " . " from metatag " . " where " . " tagnorm like '" . $i->dbescape(strtolower($q->get_param('q'))) . "%'";
    $i->query($sql);
    switch ($i->result_status) {
        case 'DBERR':
            header('HTTP/1.1 501 Database query error');
            die($i->error_info());
            break;
        case 'NOROWS':
            header('HTTP/1.1 204 No matching tags');
            return;
            break;
        case 'OK':
            header('HTTP/1.1 200 OK I guess');
            while ($row = $i->result->fetch_object()) {
                /** For entirely numeric tags, we enclose them in quotes so that
                    they can be treated as text instead of as ids. **/
                if (is_numeric($row->tagdisplay)) {
                    print '"' . $row->tagdisplay . '"' . "\n";
                } else {
                    print $row->tagdisplay . "\n";
                }
            }
            break;
    }
}
コード例 #3
0
ファイル: resupdate.php プロジェクト: josf/folkso
/**
 * 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));
    }
}
コード例 #4
0
ファイル: user.php プロジェクト: josf/folkso
/**
 *
 * 
 */
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;
}
コード例 #5
0
ファイル: folksoDBinteract-test.php プロジェクト: josf/folkso
 public function testLiveQueries()
 {
     $i = new folksoDBinteract($this->dbc);
     $this->assertIsA($i, folksoDBinteract, 'Problem with object creation');
     $this->assertFalse($i->db_error(), 'Database connection error');
     $sql = "select uri_normal as uri from resource where id = 1";
     $i->query($sql);
     $this->assertIsA($i->result, mysqli_result, '$i->result is not a mysqli_result object');
     $res = $i->result->fetch_object();
     $this->assertEqual($res->uri, 'example.com/1', 'Incorrect data from simple query: "' . $res->uri . '"');
     $ii = new folksoDBinteract($this->dbc);
     $ii->query("select uri_normal as uri from resource where id = 9999999");
     $this->assertEqual($ii->result_status, 'NOROWS', 'Not reporting NOROWS for dataless query');
     $iii = new folksoDBinteract($this->dbc);
     $this->assertTrue($iii->resourcep('http://example.com/1'), 'Not reporting existence of resource');
 }
コード例 #6
0
ファイル: folksoOIuser.php プロジェクト: josf/folkso
 /**
  * @param $id The id that we want to check
  * @return Boolean  true if a user with that id exists, false otherwise
  */
 public function exists($id)
 {
     if ($this->validateLoginId($id) === false) {
         return false;
         // should we warn?
     }
     $i = new folksoDBinteract($this->dbc);
     if ($i->db_error()) {
         trigger_error("Database connection error: " . $i->error_info(), E_USER_ERROR);
         return false;
     }
     $i->query("select userid from oi_users " . " where oid_url = '" . $i->dbescape($id) . "'");
     if ($i->result_status == 'OK') {
         return true;
     }
     return false;
 }
コード例 #7
0
ファイル: folksoFBuser.php プロジェクト: josf/folkso
 /**
  * @param $id The id that we want to check
  * @return Boolean  true if a user with that id exists, false otherwise
  */
 public function exists($id)
 {
     if ($this->validateLoginId($id) === false) {
         return false;
         // should we warn?
     }
     $i = new folksoDBinteract($this->dbc);
     if ($i->db_error()) {
         trigger_error("Database connection error: " . $i->error_info(), E_USER_ERROR);
     }
     $i->query("select userid  " . " from fb_users" . " where fb_uid = " . $i->dbescape($id));
     if ($i->result_status == 'OK') {
         $row = $i->result->fetch_object();
         $this->setUid($row->userid);
         return true;
     }
     return false;
 }
コード例 #8
0
ファイル: folksoSession.php プロジェクト: josf/folkso
 /**
  * Load user data from session id (cookie). Retuns folksoUser
  * obj. Caches the fkUser object. We might consider a "force reload"
  * option if there were a reason for it. This also means that if the
  * arguments (sid) change, the data returned will not. This should
  * not be a problem though.
  *
  * @param $sid Session ID.
  * @return folksoUser obj or false if user not found
  */
 public function userSession($sid = null, $service = null, $right = null)
 {
     if ($this->user instanceof folksoUser) {
         return $this->user;
     }
     $sid = $sid ? $sid : $this->sessionId;
     if ($this->validateSid($sid) === false) {
         return false;
         // exception?
     }
     $i = new folksoDBinteract($this->dbc);
     $sql = '';
     if (is_null($service) || is_null($right)) {
         $sql = 'select u.nick as nick, u.firstname as firstname, ' . '  u.lastname as lastname, u.email as email, u.userid  as userid' . ' from sessions s ' . ' join users u on u.userid = s.userid ' . " where s.token = '" . $sid . "'" . " and s.started > now() - 1209600 ";
     } else {
         $sql = 'select u.nick as nick, u.firstname as firstname, ' . '  u.lastname as lastname, u.email as email, u.userid  as userid, ' . ' dr.rightid, dr.service ' . ' from sessions s ' . ' join users u on u.userid = s.userid ' . ' left join users_rights ur on ur.userid = s.userid ' . ' left join rights dr on dr.rightid = ur.rightid ' . " where s.token = '" . $i->dbescape($sid) . "' " . " and dr.rightid = '" . $i->dbescape($right) . "' " . " and s.started > now() - 1209600 ";
     }
     $this->debug = $sql;
     $i->query($sql);
     if ($i->result_status == 'OK') {
         $u = new folksoUser($this->dbc);
         $res = $i->result->fetch_object();
         $u->loadUser(array('nick' => $res->nick, 'firstname' => $res->firstname, 'lastname' => $res->lastname, 'email' => $res->email, 'userid' => $res->userid));
         if ($right && $service && $res->rightid == $right && $res->service == $service) {
             $this->debug2 = 'we r here';
             $u->rights->addRight(new folksoRight($res->service, $res->rightid));
         }
         return $u;
     } else {
         return false;
     }
 }
コード例 #9
0
ファイル: tag.php プロジェクト: josf/folkso
/**
 * 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;
}
コード例 #10
0
ファイル: editresources.php プロジェクト: josf/folkso
function metatagSelectBoxOptions(folksoDBinteract $i)
{
    $i->query('SELECT tagdisplay FROM metatag WHERE id <> 1');
    $return = '';
    if ($i->result_status == 'DBERR') {
        alert('Problem with metatag autocomplete');
        print "''";
    } else {
        $return .= "<option></option>";
        while ($row = $i->result->fetch_object()) {
            $return .= "<option>" . $row->tagdisplay . "</option>\n";
        }
    }
    return $return;
}
コード例 #11
0
ファイル: resource.php プロジェクト: josf/folkso
/**
 * 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;
}
コード例 #12
0
ファイル: folksoUser.php プロジェクト: josf/folkso
 /**
  * @param 
  */
 public function loadAllRights()
 {
     $i = new folksoDBinteract($this->dbc);
     $i->query('select ur.rightid, r.service ' . ' from users_rights ur ' . ' join rights r on r.rightid = ur.rightid ' . " where userid = '" . $i->dbescape($this->userid) . "' ");
     while ($row = $i->result->fetch_object()) {
         if (!$this->rights->checkRight($row->service, $row->rightid)) {
             $this->rights->addRight(new folksoRight($row->service, $row->rightid));
         }
     }
 }