function getList($collection, $key, $conditions, $limit, $offset, $orderBy, $sort, $count) { global $db; if ($count) { $sql = 'select count(*) as total from ' . $collection; } else { $sql = 'select ' . $key . ' from ' . $collection; } $bind = array(); if (is_array($conditions) && count($conditions) > 0) { $sql .= ' where ' . NEWLINE; $op = ''; foreach ($conditions as $condition) { switch (strtolower(get_class($condition))) { case 'requal': $sql .= $op . $condition->field . ' = ?' . NEWLINE; $bind[] = $condition->value; break; case 'rnull': $sql .= $op . $condition->field . ' is null' . NEWLINE; break; case 'rlike': $sql .= $op . '('; $old = $op; $op = ''; foreach ($condition->getFields() as $field) { if (empty($field)) { continue; } $sql .= $op . $field . ' like ?' . NEWLINE; $bind[] = $condition->value; $op = ' or '; } $op = $old; $sql .= ') '; break; case 'rregex': $sql .= $op . $condition->field . ' regexp ?' . NEWLINE; $bind[] = $condition->value; break; case 'rallowed': $sql .= $op . $condition->allowed(); break; case 'rlist': $sql .= $op . $condition->field . ' in ('; $tmp = ''; foreach ($condition->getList() as $value) { $sql .= $tmp . '?'; $bind[] = $value; $tmp = ', '; } $sql .= ')' . NEWLINE; break; case 'rdaterange': $sql .= $op . '(unix_timestamp(?) <= unix_timestamp(' . $condition->field . ') and unix_timestamp(?) >= unix_timestamp(' . $condition->field . '))' . NEWLINE; $bind[] = $condition->from; $bind[] = $condition->to; break; case 'rrange': $sql .= $op . '(? <= ' . $condition->field . ' and ? >= ' . $condition->field . ')' . NEWLINE; $bind[] = $condition->from; $bind[] = $condition->to; break; case 'rliteral': $sql .= $op . $condition->expr . NEWLINE; break; case 'rsitesearch': $info = ini_parse('inc/app/cms/conf/collections/' . $collection . '.php'); if (!isset($info['Collection']['sitesearch_url'])) { break; } if (!loader_import('sitesearch.SiteSearch')) { break; } $searcher = new SiteSearch(); $res = @$searcher->query($condition->search, 100, 0, array($collection)); if (!$res || !is_array($res)) { break; } $ids = array(); foreach (array_keys($res['rows']) as $k) { $ids[] = array_shift(sscanf($res['rows'][$k]['url'], '/index/' . $info['Collection']['sitesearch_url'])); } $sql .= $op . $key . ' in("' . join('","', $ids) . '")' . NEWLINE; break; } $op = ' and '; } } if ($orderBy) { $sql .= ' order by ' . $orderBy; if ($sort) { $sql .= ' ' . $sort; } } /* echo '<pre>'; echo $sql . NEWLINEx2; print_r ($bind); echo '</pre>'; //exit; */ // info ($sql); // info ($bind, true); $q = $db->query($sql); if ($q->execute($bind)) { if ($count) { $res = $q->fetch(); $this->total = $res->total; $q->free(); return $res->total; } $this->total = $q->rows(); if ($limit > 0) { $list = $q->fetch($offset, $limit); } else { $list = array(); while ($row = $q->fetch()) { $list[] = $row; } } $q->free(); return $list; } else { $this->error = $q->error(); return false; } }
if (!in_array($ctype, $sitesearch_allowed)) { unset($collections[$k]); } } } else { $collections = $sitesearch_allowed; } if (is_array($parameters['domains'])) { $sites = $parameters['domains']; } elseif (!empty($parameters['domains'])) { $sites = explode(',', $parameters['domains']); } else { $sites = array('all'); } if (count($collections) > 0) { $res = @$searcher->query($parameters['query'], appconf('limit'), $cgi->offset, $collections, $sites); } else { $res = array(); } if (!$res) { echo '<p class="sitesearch-error">' . $searcher->error . '</p>'; $results = array(); $total = 0; } elseif (is_array($res['rows'])) { $results = $res['rows']; $total = $res['metadata']['hits']; } else { $results = array(); $total = 0; } } else {
if (!in_array($ctype, $sitesearch_allowed)) { unset($collections[$k]); } } } else { $collections = $sitesearch_allowed; } if (is_array($parameters['domain'])) { $domains = $parameters['domain']; } elseif (!empty($parameters['domain'])) { $domains = explode(',', $parameters['domain']); } else { $domains = array('all'); } if (count($collections) > 0) { $res = @$searcher->query($parameters['query'], $cgi->limit, $cgi->offset, $collections, $domains); } else { $res = array(); } if (!$res) { echo '<p class="sitesearch-error">' . $searcher->error . '</p>'; $results = array(); $total = 0; } elseif (is_array($res['rows'])) { $results = $res['rows']; $total = $res['metadata']['hits']; } else { $results = array(); $total = 0; } } else {