예제 #1
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;
}
예제 #2
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;
    }
}
예제 #3
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;
    }
}
예제 #4
0
 function testExistence()
 {
     $i = new folksoDBinteract($this->dbc);
     $this->assertTrue($i->resourcep('http://example.com/1'), 'Not reporting existence of example.com/1 (resourcep)');
     $dbc2 = new folksoDBconnect('localhost', 'tester_dude', 'testy', 'testostonomie');
     $i2 = new folksoDBinteract($dbc2);
     $this->assertTrue($i2->tagp('tagone'), 'Not reporting existence of "tagone"');
     $this->assertFalse($i2->db_error(), 'tagp() is returning an DB error');
     $this->assertTrue($i2->tagp(1), 'numeric tagp not reporting existence of tag 1');
     $this->assertEqual($i2->db->real_escape_string('tagone'), 'tagone', 'Strangeness using real_escape_string');
     $this->assertFalse($i2->tagp('false tag'), 'Reporting existence of non-existant tag');
     $this->assertFalse($i2->tagp(199), 'Reporting existence of non-existant tag (numeric)');
 }
예제 #5
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));
    }
}
예제 #6
0
 /**
  * writes new user to DB. Should only be used for new users. Do not
  * use for existing users, which will throw exceptions.
  */
 public function writeNewUser()
 {
     if (!$this->Writeable()) {
         throw new Exception('User object is not writeable, cannot write to DB');
     }
     if ($this->exists($this->loginId)) {
         throw new Exception('User already exists, cannot be created');
     }
     $i = new folksoDBinteract($this->dbc);
     if ($i->db_error()) {
         throw new Exception('DB connect error: ' . $i->error_info());
     }
     $i->sp_query(sprintf("call create_user(" . "'%s', '%s', '%s', '%s', '', %d, '%s', '%s', '%s')", $i->dbescape($this->nick), $i->dbescape($this->firstName), $i->dbescape($this->lastName), $i->dbescape($this->email), $i->dbescape($this->loginId), $i->dbescape($this->institution), $i->dbescape($this->pays), $i->dbescape($this->fonction)));
     if ($i->result_status == 'DBERR') {
         throw new Exception('DB query error on create FB user: ' . $i->error_info());
     }
 }
예제 #7
0
 /**
  * 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;
     }
 }
예제 #8
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;
}
예제 #9
0
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;
}
예제 #10
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;
}
예제 #11
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));
         }
     }
 }