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; } }
unset($sitesearch_highlight[$config['Collection']['name']]); } } } $folders = ini_parse('inc/app/sitesearch/conf/folders.ini.php'); $domains = array(site_domain() => site_domain()); foreach ($folders as $name => $folder) { if (isset($folder['domain'])) { $domains[$folder['domain']] = $folder['domain']; } else { $sitesearch_allowed[] = $name; } } if (!empty($parameters['query'])) { loader_import('sitesearch.SiteSearch'); $searcher = new SiteSearch(); if (is_array($parameters['ctype'])) { $collections = $parameters['ctype']; foreach ($collections as $k => $ctype) { if (!in_array($ctype, $sitesearch_allowed)) { unset($collections[$k]); } } } elseif (!empty($parameters['ctype'])) { $collections = explode(',', $parameters['ctype']); foreach ($collections as $k => $ctype) { if (!in_array($ctype, $sitesearch_allowed)) { unset($collections[$k]); } } } else {
<?php /* Parameters contains: * - changelog: Summary of the changes * - collection: The collection the item belongs to * - key: The primary key value of the item * - message: A brief description of the event * - transition: The transition that triggered this service * * Note that services are triggered *after* the change has been * made. The only way you can undo changes in a service is by * using the cms.Versioning.Rex API if the collection in question * supports versioning (not all do). Also, you can, if necessary, * create further modifications to the document, also via the * Rex API. * * Transition is one of: * - delete */ $default_domain = conf('Site', 'domain'); $mtime = time(); $rex = new Rex($parameters['collection']); if (!$rex->collection || !$rex->info['Collection']['sitesearch_url']) { return; } loader_import('sitesearch.SiteSearch'); $search = new SiteSearch(); foreach ($parameters['key'] as $key) { $search->delete(site_prefix() . '/index/' . sprintf($rex->info['Collection']['sitesearch_url'], $key)); }
$sitesearch_allowed = array(); loader_import('saf.File.Directory'); foreach (Dir::fetch('inc/app/cms/conf/collections') as $file) { if (strpos($file, '.') === 0 || @is_dir('inc/app/cms/conf/collections/' . $file)) { continue; } $config = ini_parse('inc/app/cms/conf/collections/' . $file); if (isset($config['Collection']['sitesearch_url'])) { if (isset($config['Collection']['sitesearch_access']) && session_allowed($config['Collection']['sitesearch_access'], 'r', 'access')) { $sitesearch_allowed[] = $config['Collection']['name']; } } } if (!empty($parameters['query'])) { loader_import('sitesearch.SiteSearch'); $searcher = new SiteSearch(); if (is_array($parameters['ctype'])) { $collections = $parameters['ctype']; foreach ($collections as $k => $ctype) { if (!in_array($ctype, $sitesearch_allowed)) { unset($collections[$k]); } } } elseif (!empty($parameters['ctype'])) { $collections = explode(',', $parameters['ctype']); foreach ($collections as $k => $ctype) { if (!in_array($ctype, $sitesearch_allowed)) { unset($collections[$k]); } } } else {
$data->top_end = $end; list($prev, $next) = $logger->getTopDates($data->top_range, $data->top_date); $data->top_prev = $prev; $data->top_next = $next; $data->top = $logger->getTopSearches(10, $start, $end); // total searches if (empty($parameters['ttl_date'])) { $parameters['ttl_date'] = date('Y-m-d'); } $data->ttl_date = $parameters['ttl_date']; list($year, $month) = $logger->getTotalRange($data->ttl_date); $data->ttl_year = $year; $data->ttl_month = $month; list($prev, $next) = $logger->getTotalDates($data->ttl_date); $data->ttl_prev = $prev; $data->ttl_next = $next; $data->ttl = $logger->getTotalSearches($year, $month); $data->ttl_total = 0; $days = 0; foreach ($data->ttl as $day) { $data->ttl_total += $day->total; $days++; } if ($days > 0) { $data->ttl_avg = ceil($data->ttl_total / $days); } else { $data->ttl_avg = 0; } $searcher = new SiteSearch(); $data->uptime = @$searcher->uptime(); echo template_simple('stats_index.spt', $data);
$description = $parameters['data'][$rex->info['Collection']['summary_field']]; } if (!isset($rex->info['Collection']['keywords_field'])) { $keywords = ''; } elseif (strpos($rex->info['Collection']['keywords_field'], ',') !== false) { $op = ''; foreach (preg_split('/, ?/', $rex->info['Collection']['keywords_field']) as $f) { $keywords .= $op . $parameters['data'][$f]; $op = ', '; } } else { $keywords = $parameters['data'][$rex->info['Collection']['keywords_field']]; } $data = array('title' => $parameters['data'][$rex->title], 'url' => site_prefix() . '/index/' . sprintf($rex->info['Collection']['sitesearch_url'], $parameters['key']), 'description' => $description, 'keywords' => $keywords, 'body' => $parameters['data'][$rex->info['Collection']['body_field']], 'access' => $access, 'status' => $status, 'team' => $team, 'ctype' => $parameters['collection'], 'mtime' => (string) $mtime, 'domain' => $default_domain); if ($parameters['collection'] == 'sitellite_filesystem') { loader_import('sitesearch.Extractor'); $function = extractor_get_function('inc/data/' . $parameters['key']); if (!$function) { $data['body'] = $data['description']; } else { $new = $function('inc/data/' . $parameters['key']); if (!$new) { $data['body'] = $data['description']; } else { $data['body'] = $new; } } } loader_import('sitesearch.SiteSearch'); $search = new SiteSearch(); $search->addDocument($data);
} } } } catch (Exception $e) { // There was a problem opening the directory } return $pages; } } // helper function to sort matched pages alphabetically by title function by_title($a, $b) { return $a[1] == $b[1] ? strcmp($a[0], $b[0]) : $a[1] > $b[1]; } // SiteSearch object to do the searching $search = new SiteSearch(); // array to hold the pages that match the search term $matching_pages = array(); // directories underneath the document root to search $search_dirs = array('sports', 'movies', 'food'); // regular expression to use in searching files. The "S" pattern // modifier tells the PCRE engine to "study" the regex for greater // efficiency. $search->bodyRegex = '#<body>(.*' . preg_quote($_GET['term'], '#') . '.*)</body>#Sis'; // add the files that match in each directory to $matching pages foreach ($search_dirs as $dir) { $matching_pages = array_merge($matching_pages, $search->searchDir($_SERVER['DOCUMENT_ROOT'] . '/' . $dir)); } if (count($matching_pages)) { // sort the matching pages by title usort($matching_pages, 'by_title');
// BEGIN CLI KEEPOUT CHECKING if (php_sapi_name() !== 'cli') { // Add these lines to the very top of any file you don't want people to // be able to access directly. header('HTTP/1.1 404 Not Found'); echo "<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML 2.0//EN\">\n" . "<html><head>\n<title>404 Not Found</title>\n</head><body>\n<h1>Not Found</h1>\n" . "The requested URL " . $PHP_SELF . " was not found on this server.<p>\n<hr>\n" . $_SERVER['SERVER_SIGNATURE'] . "</body></html>"; exit; } // END CLI KEEPOUT CHECKING // sitesearch scheduler task loader_import('sitesearch.SiteSearch'); loader_import('sitesearch.Logger'); loader_import('sitesearch.Extractor'); loader_import('sitesearch.Functions'); loader_import('cms.Versioning.Rex'); $search = new SiteSearch(); $collections = Rex::getCollections(); $default_domain = conf('Site', 'domain'); $mtime = time(); $counts = array(); foreach ($collections as $collection) { $rex = new Rex($collection); if (!$rex->collection || !$rex->info['Collection']['sitesearch_url']) { continue; } $counts[$collection] = 0; foreach ($rex->getList(array()) as $item) { // index item $item = $rex->getCurrent($item->{$rex->key}); if (!$item) { continue;
} if (!isset($rex->info['Collection']['keywords_field'])) { $keywords = ''; } elseif (strpos($rex->info['Collection']['keywords_field'], ',') !== false) { $op = ''; foreach (preg_split('/, ?/', $rex->info['Collection']['keywords_field']) as $f) { $keywords .= $op . $parameters['data'][$f]; $op = ', '; } } else { $keywords = $parameters['data'][$rex->info['Collection']['keywords_field']]; } $data = array('title' => $parameters['data'][$rex->title], 'url' => site_prefix() . '/index/' . sprintf($rex->info['Collection']['sitesearch_url'], $parameters['key']), 'description' => $description, 'keywords' => $keywords, 'body' => $parameters['data'][$rex->info['Collection']['body_field']], 'access' => $access, 'status' => $status, 'team' => $team, 'ctype' => $parameters['collection'], 'mtime' => (string) $mtime, 'domain' => $default_domain); if ($parameters['collection'] == 'sitellite_filesystem') { loader_import('sitesearch.Extractor'); $function = extractor_get_function('inc/data/' . $parameters['key']); if (!$function) { $data['body'] = $data['description']; } else { $new = $function('inc/data/' . $parameters['key']); if (!$new) { $data['body'] = $data['description']; } else { $data['body'] = $new; } } } loader_import('sitesearch.SiteSearch'); $search = new SiteSearch(); $search->delete($data['url']); $search->addDocument($data);