<br /> <input type="submit" name="listsubmit" id="listsubmit" value="Start" /> </p> </form> <?php set_time_limit(3600 * 24); if (isset($_POST['listsubmit']) && isset($_POST['images']) && preg_match('/^(\\s*[1-9][0-9]*\\s*,)*\\s*[1-9][0-9]*\\s*$/', $_POST['images'])) { require_once 'geograph/gridimage.class.php'; echo "<h3>Rebuilding gridimage_search from gridimage for the given images</h3>"; flush(); $images = explode(',', $_POST['images']); foreach ($images as $image) { $gridimage_id = intval($image); echo "<p>Image {$gridimage_id}: "; $gridimage = new GridImage($gridimage_id); if ($gridimage->isValid()) { $gridimage->updateCachedTables(); echo "done"; } else { echo "<b>not found</b>"; } echo "</p>"; flush(); } } if (isset($_POST['recreate'])) { die("THIS IS TOO DANGEROUS - exiting for your own safety"); echo "<h3>Rebuilding gridimage_search from gridimage</h3>"; flush(); if ($_POST['use_new']) { echo "<p>Creating gridimage copy...</p>";
$ab = floor($_GET['id'] / 10000); $cacheid = "img{$ab}|{$_GET['id']}|{$isowner}_{$ismoderator}"; //is the image rejected? - only the owner and administrator should see it if ($image->moderation_status == 'rejected') { if ($isowner || $ismoderator) { //ok, we'll let it lie... } else { //clear the image $image = new GridImage(); $cacheid = 0; $rejected = true; } } } //do we have a valid image? if ($image->isValid()) { //what style should we use? $style = $USER->getStyle(); $cacheid .= $style; //when this image was modified $mtime = strtotime($image->upd_timestamp); //page is unqiue per user (the profile and links) $hash = $cacheid . '.' . $USER->user_id; //can't use IF_MODIFIED_SINCE for logged in users as has no concept as uniqueness customCacheControl($mtime, $hash, $USER->user_id == 0); if (!empty($CONF['sphinx_host']) && stripos($_SERVER['HTTP_REFERER'], $CONF['CONTENT_HOST']) === FALSE && stripos($_SERVER['HTTP_REFERER'], $_SERVER['HTTP_HOST']) === FALSE && preg_match('/\\b(q|query|qry|search|su|searchfor|s|qs|p|key|buscar|w)=([\\w%\\+\\.\\(\\)\\"\':]+)(\\&|$)/', $_SERVER['HTTP_REFERER'], $m) && !is_numeric($m[2]) && ($q = trim(preg_replace('/\\b(geograph|photo|image|picture|site:[\\w\\.-]+|inurl:[\\w\\.-]+)s?\\b/', '', urldecode($m[2])))) && strlen($q) > 3) { $smarty->assign("search_keywords", $q); $mkey = $image->grid_reference . ' ' . $q; $info =& $memcache->name_get('sn', $mkey); if (!empty($info)) { list($count, $when) = $info;
/** * run a standard search via sphinxsearch index * NOTE: $this->criteria->getSQLParts(...) needs to have been called before this function to populate sphinx criteria * @access private */ function ExecuteSphinxRecordSet($pg) { global $CONF; $db = $this->_getDB(); extract($this->criteria->sql, EXTR_PREFIX_ALL ^ EXTR_REFS, 'sql'); $sphinx = new sphinxwrapper($this->criteria->sphinx['query']); $this->fullText = 1; $sphinx->pageSize = $this->criteria->resultsperpage + 0; $page = ($pg - 1) * $sphinx->pageSize; if ($page > 1000) { //todo - hard-coded 1000 needs autodetecting! //lets jump to the last page of 'past results' $pg = intval(ceil(1000 / $sphinx->pageSize)); $this->currentPage = $pg; } //look for suggestions - this needs to be done before the filters are added - the same filters wont work on the gaz index if (isset($GLOBALS['smarty'])) { $suggestions = array(); if (empty($this->countOnly) && $sphinx->q && strlen($sphinx->q) < 64 && empty($this->criteria->sphinx['x'])) { $suggestions = $sphinx->didYouMean($sphinx->q); } elseif ($this->criteria->searchclass == 'Placename' && strpos($this->criteria->searchdesc, $this->criteria->searchq) == FALSE && (empty($this->criteria->searchtext) || $this->criteria->searchq == $this->criteria->searchtext) && isset($GLOBALS['smarty'])) { $suggestions = array(array('gr' => '(anywhere)', 'localities' => 'as text search', 'query' => $this->criteria->searchq)); } if (!empty($this->criteria->searchtext)) { if (is_numeric($this->criteria->searchtext)) { require_once 'geograph/gridsquare.class.php'; require_once 'geograph/gridimage.class.php'; $image = new GridImage(); $image->loadFromId($this->criteria->searchtext); if ($image->isValid() && ($image->moderation_status != 'rejected' && $image->moderation_status != 'pending' || $image->user_id == $GLOBALS['USER']->user_id)) { $suggestions += array(array('link' => "/photo/{$image->gridimage_id}", 'gr' => '(anywhere)', 'localities' => "Image by " . htmlentities($image->realname) . ", ID: {$image->gridimage_id}", 'query' => htmlentities2($image->title))); } } else { require_once "3rdparty/spellchecker.class.php"; $correction = SpellChecker::Correct($this->criteria->searchtext); if ($correction != $this->criteria->searchtext && levenshtein($correction, $this->criteria->searchtext) < 0.25 * strlen($correction)) { $suggestions += array(array('gr' => '(anywhere)', 'localities' => '', 'query' => $correction)); } } } if (!empty($suggestions) && count($suggestions)) { $GLOBALS['smarty']->assign("suggestions", $suggestions); } } //setup the sphinx wrapper if (!empty($this->criteria->sphinx['sort'])) { $sphinx->setSort($this->criteria->sphinx['sort']); } if (empty($this->criteria->sphinx['sort']) || $this->criteria->sphinx['sort'] == '@relevance DESC, @id DESC') { if (preg_match('/\\w+/', preg_replace('/(@\\w+ |\\w+:)\\w+/', '', $this->criteria->sphinx['query']))) { $this->criteria->searchdesc = str_replace('undefined', 'relevance', $this->criteria->searchdesc); } elseif (strlen($this->criteria->sphinx['query'])) { #$this->criteria->searchdesc = str_replace(', in undefined order','',$this->criteria->searchdesc); } } if (!empty($this->criteria->sphinx['d'])) { $sphinx->setSpatial($this->criteria->sphinx); } //this step is handled internally by search and setSpatial //$sphinx->processQuery(); if (!empty($CONF['fetch_on_demand'])) { $sphinx->upper_limit = $db->getOne("SELECT MAX(gridimage_id) FROM gridimage_search"); } if (is_array($this->criteria->sphinx['filters']) && count($this->criteria->sphinx['filters'])) { $sphinx->addFilters($this->criteria->sphinx['filters']); } //run the sphinx search $ids = $sphinx->returnIds($pg, empty($this->criteria->sphinx['exact']) ? '_images' : '_images_exact'); $this->resultCount = $sphinx->resultCount; $this->numberOfPages = $sphinx->numberOfPages; $this->maxResults = $sphinx->maxResults; $this->islimited = true; if (isset($GLOBALS['smarty']) && !empty($sphinx->res['words']) && (count($sphinx->res['words']) > 1 || !$this->resultCount)) { $GLOBALS['smarty']->assign("statistics", $sphinx->res['words']); } if ($this->countOnly || !$this->resultCount) { return 0; } if ($sql_order == ' dist_sqd ') { $this->sphinx_matches = $sphinx->res['matches']; $sql_fields = ',-1 as dist_sqd'; } // fetch from database $id_list = implode(',', $ids); if ($this->noCache) { $sql = <<<END /* i{$this->query_id} */ SELECT gi.*,x,y,gs.grid_reference,gi.realname as credit_realname,if(gi.realname!='',gi.realname,user.realname) as realname {$sql_fields} FROM gridimage AS gi INNER JOIN gridsquare AS gs USING(gridsquare_id) \tINNER JOIN user ON(gi.user_id=user.user_id) WHERE gi.gridimage_id IN ({$id_list}) ORDER BY FIELD(gi.gridimage_id,{$id_list}) END; } else { $sql = "/* i{$this->query_id} */ SELECT gi.* {$sql_fields} FROM gridimage_search as gi WHERE gridimage_id IN ({$id_list}) ORDER BY FIELD(gi.gridimage_id,{$id_list})"; } if (!empty($_GET['debug'])) { print "<BR><BR>{$sphinx->q}<BR><BR>{$sql}"; } list($usec, $sec) = explode(' ', microtime()); $querytime_before = (double) $usec + (double) $sec; $recordSet =& $db->Execute($sql); list($usec, $sec) = explode(' ', microtime()); $querytime_after = (double) $usec + (double) $sec; if ($this->display == 'excerpt') { $docs = array(); foreach ($ids as $c => $id) { $row = $rows[$id]; $docs[$c] = strip_tags(preg_replace('/<i>.*?<\\/i>/', ' ', $row['post_text'])); } $reply = $sphinx->BuildExcerpts($docs, empty($this->criteria->sphinx['exact']) ? 'gridimage' : 'gi_stemmmed', $sphinx->q); } $this->querytime = $querytime_after - $querytime_before + $sphinx->query_time; //finish off if (!empty($recordSet) && empty($_GET['BBOX']) && $this->display != 'reveal') { $db->Execute("replace into queries_count set id = {$this->query_id},`count` = {$this->resultCount}"); } return $recordSet; }