Example #1
0
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;
    }
}
Example #2
0
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;
    }
}
Example #3
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)');
 }
Example #4
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());
     }
 }
Example #5
0
/**
 * 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));
    }
}
Example #6
0
 /**
  * @param $session_id (optional)
  */
 public function killSession($session_id = null)
 {
     $sid = $session_id ? $session_id : $this->sessionId;
     if ($this->validateSid($sid)) {
         $i = new folksoDBinteract($this->dbc);
         if ($i->db_error()) {
             trigger_error("Database connection error: " . $i->error_info(), E_USER_ERROR);
         }
         $i->query("delete from sessions where token = '" . $i->dbescape($sid) . "'");
     } else {
         trigger_error('invalid session id', E_USER_WARNING);
     }
 }
Example #7
0
/**
 * 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;
}