Ejemplo n.º 1
0
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 */
require_once 'geograph/global.inc.php';
init_session();
$smarty = new GeographPage();
$template = 'finder_places.tpl';
if (!empty($_GET['q'])) {
    $q = trim($_GET['q']);
    $fuzzy = !empty($_GET['f']);
    $sphinx = new sphinxwrapper($q);
    //gets a cleaned up verion of the query (suitable for filename etc)
    $cacheid = $sphinx->q . '.' . $fuzzy;
    $sphinx->pageSize = $pgsize = 15;
    $pg = !empty($_GET['page']) ? intval(str_replace('/', '', $_GET['page'])) : 0;
    if (empty($pg) || $pg < 1) {
        $pg = 1;
    }
    $cacheid .= "." . $pg;
    if (!$smarty->is_cached($template, $cacheid)) {
        $offset = ($pg - 1) * $sphinx->pageSize + 1;
        if ($offset < 1000 - $pgsize) {
            $sphinx->processQuery();
            $sphinx->sort = "score ASC, @relevance DESC, @id DESC";
            #$sphinx->sort = -1;
            #$sphinx->_getClient()->SetSortMode(SPH_SORT_EXPR,"(10-score) * @weight");
Ejemplo n.º 2
0
} elseif (isset($_GET['suggestor']) && ($mid = intval($_GET['suggestor']))) {
    $sql_where .= " and t.user_id={$mid}";
}
if (!empty($_GET['q'])) {
    if (isset($_GET['legacy']) || empty($CONF['sphinx_host'])) {
        if (strpos($_GET['q'], '!') === 0) {
            $q = $db->Quote("%" . preg_replace('/^!/', '', $_GET['q']) . "%");
            #$sql_where .= " and not (t.notes like $q or i.title like $q)";
            $sql_where .= " and not (t.notes like {$q} or i.title like {$q} or i.title2 like {$q})";
        } else {
            $q = $db->Quote("%{$_GET['q']}%");
            #$sql_where .= " and (t.notes like $q or i.title like $q)";
            $sql_where .= " and (t.notes like {$q} or i.title like {$q} or i.title2 like {$q})";
        }
    } else {
        $sphinx = new sphinxwrapper($_GET['q']);
        $sphinx->pageSize = $pgsize = 100;
        $ids = $sphinx->returnIds(1, 'tickets');
        if (!empty($ids) && count($ids)) {
            $sql_where .= " and t.gridimage_ticket_id IN(" . join(",", $ids) . ")";
        } else {
            $sql_where .= " and 0";
        }
        $smarty->assign('q', $sphinx->qclean);
    }
}
#################
# available values
$types = array('pending' => 'New Tickets', 'open' => "Open Tickets", 'closed' => "Closed Tickets", 'ongoing' => 'New or Open');
$modifers = array('recent' => 'All', '24' => "over 24 hours old", '7' => "over 7 days old");
$themes = array('any' => 'Any', 'tmod' => "on ticket I moderating/ed", 'mod' => "on images I moderated", 'comment' => "tickets I have commented on", 'suggest' => "tickets I suggested", 'all' => 'any involvement');
Ejemplo n.º 3
0
     //geotag the page
     require_once 'geograph/conversions.class.php';
     $conv = new Conversions();
     list($lat, $long) = $conv->gridsquare_to_wgs84($square);
     $smarty->assign('lat', $lat);
     $smarty->assign('long', $long);
     $smarty->assign_by_ref('square', $square);
     //get a token to show a suroudding geograph map
     $mosaic = new GeographMapMosaic();
     $smarty->assign('map_token', $mosaic->getGridSquareToken($square));
     if ($CONF['forums']) {
         $square->assignDiscussionToSmarty($smarty);
     }
     if (!empty($CONF['sphinx_host'])) {
         //look for images from here...
         $sphinx = new sphinxwrapper();
         if (!isset($viewpoint_count) && ($viewpoint_count = $sphinx->countImagesViewpoint($square->nateastings, $square->natnorthings, $square->reference_index, $square->grid_reference))) {
             $smarty->assign('viewpoint_count', $viewpoint_count);
             #$smarty->assign('viewpoint_query', $sphinx->q);
         }
         if (!isset($mention_count) && ($mention_count = $sphinx->countQuery("{$square->grid_reference} -grid_reference:{$square->grid_reference}", "_images"))) {
             $smarty->assign('mention_count', $mention_count);
         }
     }
     if ($square->natspecified && $square->natgrlen >= 6) {
         $conv = new Conversions('');
         list($gr6, $len) = $conv->national_to_gridref($square->getNatEastings(), $square->getNatNorthings(), 6, $square->reference_index, false);
         $smarty->assign('gridref6', $gr6);
     }
 } else {
     $smarty->assign('errormsg', $square->errormsg);
Ejemplo n.º 4
0
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 */
require_once 'geograph/global.inc.php';
init_session();
$smarty = new GeographPage();
$template = 'finder_discussions.tpl';
if (!empty($_GET['q'])) {
    $q = trim($_GET['q']);
    $q = preg_replace('/(-?)\\b(by):/', '@name $1', $q);
    $sphinx = new sphinxwrapper($q);
    //gets a cleaned up verion of the query (suitable for filename etc)
    $cacheid = $sphinx->q;
    $sphinx->pageSize = $pgsize = 15;
    $pg = !empty($_GET['page']) ? intval(str_replace('/', '', $_GET['page'])) : 0;
    if (empty($pg) || $pg < 1) {
        $pg = 1;
    }
    $cacheid .= "." . $pg;
    if (!$smarty->is_cached($template, $cacheid)) {
        $offset = ($pg - 1) * $sphinx->pageSize + 1;
        if (preg_match("/\\b([a-zA-Z]{1,3}) ?(\\d{2,5})[ \\.]?(\\d{2,5})\\b/", $sphinx->q, $m)) {
            $smarty->assign('gridref', $m[1] . $m[2] . $m[3]);
            $sphinx->q = " " . $sphinx->q;
        }
        if ($offset < 1000 - $pgsize) {
Ejemplo n.º 5
0
     $_GET['location'] = '(anywhere)';
 }
 if (!empty($_GET['location'])) {
     if (!empty($_GET['text'])) {
         $q = trim($_GET['text']) . ' near ' . trim($_GET['location']);
     } elseif (!empty($_GET['q'])) {
         $q = trim($_GET['q']) . ' near ' . trim($_GET['location']);
     } else {
         $q = 'near ' . trim($_GET['location']);
     }
 } else {
     $q = trim($_GET['q']);
 }
 //temporally redirect piclens full-text search directly to sphinx
 if (isset($_GET['source']) && ($_GET['source'] == 'piclens' || $_GET['source'] == 'fist')) {
     $sphinx = new sphinxwrapper($q);
     //gets a cleaned up verion of the query (suitable for filename etc)
     $cacheid = $sphinx->q;
     $sphinx->pageSize = $pgsize = 15;
     $sphinx->processQuery();
     $pg = !empty($_GET['page']) ? intval(str_replace('/', '', $_GET['page'])) : 0;
     if (empty($pg) || $pg < 1) {
         $pg = 1;
     }
     $ids = $sphinx->returnIds($pg, '_images');
     unset($q);
 } else {
     $cacheid = getTextKey();
     $pg = 1;
     //$q is used below
 }
Ejemplo n.º 6
0
    $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;
            $smarty->assign("search_count", $count);
            $smarty->assign_by_ref("image", $image);
            //we dont need the full assignToSmarty
        } else {
            $sphinx = new sphinxwrapper($mkey);
            $sphinx->processQuery();
            $count = $sphinx->countMatches('_images');
            $smarty->assign("search_count", $count);
            //fails quickly if not using memcached!
            $info = array($count, time());
            $memcache->name_set('sn', $mkey, $info, $memcache->compress, $memcache->period_med);
        }
    }
    if (!$smarty->is_cached($template, $cacheid)) {
        $smarty->assign('maincontentclass', 'content_photo' . $style);
        $image->assignToSmarty($smarty);
    }
} elseif (!empty($rejected)) {
    header("HTTP/1.0 410 Gone");
    header("Status: 410 Gone");
Ejemplo n.º 7
0
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 */
require_once 'geograph/global.inc.php';
init_session();
$smarty = new GeographPage();
$smarty->assign('noSphinx', empty($CONF['sphinx_host']));
$template = 'finder_contributors.tpl';
if (!empty($_GET['q']) && !empty($CONF['sphinx_host'])) {
    $q = trim($_GET['q']);
    $sphinx = new sphinxwrapper($q);
    //gets a cleaned up verion of the query (suitable for filename etc)
    $cacheid = $sphinx->q;
    $sphinx->pageSize = $pgsize = 15;
    $pg = !empty($_GET['page']) ? intval(str_replace('/', '', $_GET['page'])) : 0;
    if (empty($pg) || $pg < 1) {
        $pg = 1;
    }
    $cacheid .= "." . $pg;
    if (!$smarty->is_cached($template, $cacheid)) {
        $sphinx->processQuery();
        $ids = $sphinx->returnIds($pg, 'user');
        if (count($ids)) {
            $where = "user_id IN(" . join(",", $ids) . ")";
            $db = NewADOConnection($GLOBALS['DSN']);
            $limit = 25;
    /**
     * 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;
    }
Ejemplo n.º 9
0
 /**
  * get image list for particular query
  */
 function getImagesBySphinx($q, $pgsize = 15, $pg = 1)
 {
     $sphinx = new sphinxwrapper($q);
     $sphinx->pageSize = $pgsize;
     $sphinx->processQuery();
     $ids = $sphinx->returnIds($pg, '_images');
     if (count($ids)) {
         $this->resultCount = $sphinx->resultCount;
         return $this->getImagesByIdList($ids);
     } else {
         return 0;
     }
 }
Ejemplo n.º 10
0
 $smarty->assign_by_ref('square', $square);
 list($latdm, $longdm) = $conv->wgs84_to_friendly($lat, $long);
 $smarty->assign('latdm', $latdm);
 $smarty->assign('longdm', $longdm);
 $smarty->assign('el', $long > 0 ? 'E' : 'W');
 $smarty->assign('nl', $lat > 0 ? 'N' : 'S');
 $smarty->assign('lat_abs', abs($lat));
 $smarty->assign('long_abs', abs($long));
 //get a token to show a suroudding geograph map
 $mosaic = new GeographMapMosaic();
 $smarty->assign('map_token', $mosaic->getGridSquareToken($square));
 if (!empty($CONF['forums'])) {
     $square->assignDiscussionToSmarty($smarty);
 }
 //look for images from here...
 $sphinx = new sphinxwrapper();
 if ($viewpoint_count = $sphinx->countImagesViewpoint($square->getNatEastings(), $square->getNatNorthings(), $square->reference_index, $square->grid_reference)) {
     $smarty->assign('viewpoint_count', $viewpoint_count);
     $smarty->assign('viewpoint_query', $sphinx->q);
 }
 if ($square->natspecified && $square->natgrlen >= 6) {
     $conv = new Conversions('');
     list($gr6, $len) = $conv->national_to_gridref($square->getNatEastings(), $square->getNatNorthings(), 6, $square->reference_index, false);
     $smarty->assign('gridref6', $gr6);
 }
 //lets add an overview map too
 $overview = new GeographMapMosaic('largeoverview');
 $overview->setCentre($square->x, $square->y);
 //does call setAlignedOrigin
 $smarty->assign('marker', $overview->getSquarePoint($square));
 //lets add an rastermap too
Ejemplo n.º 11
0
 $smarty->assign_by_ref("orders", $orders);
 $extra .= "&amp;order={$order}";
 if (!empty($_GET['page'])) {
     $pg = intval($_GET['page']);
 } else {
     $pg = 1;
 }
 if (!empty($_GET['user_id']) && preg_match('/^\\d+$/', $_GET['user_id'])) {
     $where = "content.user_id = {$_GET['user_id']}";
     $extra .= "&amp;user_id={$_GET['user_id']}";
     $profile = new GeographUser($_GET['user_id']);
     $title = "By " . $profile->realname;
 } elseif (!empty($_GET['q']) && !empty($CONF['sphinx_host'])) {
     // --------------
     $q = trim($_GET['q']);
     $sphinx = new sphinxwrapper($q);
     $sphinx->pageSize = $pgsize = 25;
     if (preg_match('/\\bp(age|)(\\d+)\\s*$/', $q, $m)) {
         $pg = intval($m[2]);
         $sphinx->q = preg_replace('/\\bp(age|)\\d+\\s*$/', '', $sphinx->q);
     }
     $extra .= "&amp;q=" . urlencode($sphinx->q);
     $title = "Matching word search [ " . htmlentities($sphinx->q) . " ]";
     #$sphinx->processQuery();
     if (isset($CONF['forums']) && empty($CONF['forums']) || $USER->user_id == 0) {
         $sphinx->qoutput = $sphinx->q;
         $sphinx->q .= " @source -themed";
     }
     $ids = $sphinx->returnIds($pg, 'content_stemmed');
     $smarty->assign("query_info", $sphinx->query_info);
     if (count($ids)) {