Ejemplo n.º 1
0
 /**
  * Checks to see if this Response should be used to respond to the query $q.
  *
  * If there are 'exclude' parameters, they are checked first. If any
  * of them are present, param_check returns 'false'.
  *
  * Then we check the 'required' parameters in $this->activate_params
  * and returns false if any of them are missing. If one of the
  * 'oneof' fields is present (and assuming conditions in the other
  * arrays are met), 'true' is returned.
  *
  * @param folksoQuery $q
  * @return boolean
  */
 private function param_check(folksoQuery $q)
 {
     if (is_array($this->activate_params['exclude'])) {
         foreach ($this->activate_params['exclude'] as $no) {
             if ($q->is_param($no)) {
                 return false;
             }
         }
     }
     $all_requireds = array();
     foreach (array($this->activate_params['required'], $this->activate_params['required_single'], $this->activate_params['required_multiple']) as $arr) {
         if (is_array($arr)) {
             $all_requireds = array_merge($all_requireds, $arr);
         }
     }
     foreach ($all_requireds as $p) {
         if (!$q->is_param($p)) {
             return false;
         }
     }
     if (is_array($this->activate_params['required_single'])) {
         foreach ($this->activate_params['required_single'] as $p) {
             if (!$q->is_single_param($p)) {
                 return false;
             }
         }
     }
     if (is_array($this->activate_params['required_multiple'])) {
         foreach ($this->activate_params['required_multiple'] as $p) {
             if (!$q->is_multiple_param($p)) {
                 return false;
             }
         }
     }
     $oneof = false;
     if (is_array($this->activate_params['oneof'])) {
         foreach ($this->activate_params['oneof'] as $p) {
             if ($q->is_param($p)) {
                 $oneof = true;
             }
         }
         if (!$oneof) {
             return false;
         }
     }
     return true;
 }
Ejemplo n.º 2
0
/**
 * VisitPage : add a resource (uri) to the resource index
 * 
 * Web parameters: POST + folksores + folksovisit
 * Optional: folksourititle
 *
 * This uses a cache in /tmp to reduce (drastically) the number of database connections.
 *
 * Optional parameters: urititle,
 * 
 */
function visitPage(folksoQuery $q, folksoDBconnect $dbc, folksoSession $fks)
{
    $ic = new folksoIndexCache('/tmp/cachetest', 5);
    $r = new folksoResponse();
    $page = new folksoUrl($q->res, $q->is_single_param('urititle') ? $q->get_param('urititle') : '');
    if (!$ic->data_to_cache(serialize($page))) {
        $r->setError(500, 'Internal server error: could not use cache');
        return $r;
    }
    try {
        if ($ic->cache_check()) {
            $pages_to_parse = $ic->retreive_cache();
            $i = new folksoDBinteract($dbc);
            $urls = array();
            $title = array();
            foreach ($pages_to_parse as $raw) {
                $item = unserialize($raw);
                $urls[] = $i->dbescape($item->get_url());
                $titles[] = $item->get_title();
            }
            $sql = "CALL bulk_visit('" . implode('&&&&&', $urls) . "', '" . implode('&&&&&', $titles) . "', 1)";
            if (!($lfh = fopen('/tmp/folksologfile', 'a'))) {
                $r->setError(500, 'Internal server error: could not open logfile');
            }
            fwrite($lfh, implode("\n", $urls) . "\n");
            fclose($lfh);
            $i->query($sql);
            if ($i->result_status == 'DBERR') {
                $r->dbQueryError($i->error_info());
                return $r;
            }
            $r->setOk(200, "200 Read cache'");
            $r->t("updated db");
        } else {
            $r->setOk(202, "Caching visit");
            $r->t('Caching visit. Results will be incorporated shortly.');
        }
    } catch (dbException $e) {
        return $r->handleDBexception($e);
    }
    return $r;
}