move geoloc as is into a geoloc module. no rewrite planned at all
authorx2000habouzit <x2000habouzit@839d8a87-29fc-0310-9880-83ba4fa771e5>
Thu, 13 Jul 2006 11:45:23 +0000 (11:45 +0000)
committerx2000habouzit <x2000habouzit@839d8a87-29fc-0310-9880-83ba4fa771e5>
Thu, 13 Jul 2006 11:45:23 +0000 (11:45 +0000)
git-svn-id: svn+ssh://murphy/home/svn/platal/trunk@462 839d8a87-29fc-0310-9880-83ba4fa771e5

Makefile
htdocs/geoloc/dynamap.php [deleted file]
htdocs/geoloc/geolocInit.php [deleted file]
htdocs/geoloc/getCityInfos.php [deleted file]
htdocs/geoloc/getData.php [deleted file]
htdocs/geoloc/icon.php [deleted file]
htdocs/geoloc/index.php [deleted file]
modules/core.php
modules/geoloc.php [new file with mode: 0644]

index 6910a15..7b780d0 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -16,12 +16,6 @@ VCS_FILTER = ! -name .arch-ids ! -name CVS
 
 all: build
 
-devel: build htdocs/valid.html
-
-headers:
-       headache -c install.d/platal-dev/templates/header.conf -h install.d/platal-dev/templates/header \
-               `find templates -name '*.tpl' ! -path 'templates/xnet/skin.tpl' ! -path 'templates/skin/*.tpl' ! -name 'vcard.tpl' `
-
 build: spool/templates_c wiki include/platal/globals.inc.php banana
 
 clean:
@@ -45,11 +39,6 @@ spool/wiki.d:
 wiki/cookbook/e-protect.php:
        cd wiki/cookbook && ln -sf ../../install.d/wiki/e-protect.php
 
-htdocs/valid.html:
-       touch spool/templates_c/valid.html
-       chmod o+w spool/templates_c/valid.html
-       cd htdocs && ln -sf ../spool/templates_c/valid.html
-
 htdocs/uploads:
        cd htdocs && ln -sf ../spool/uploads
 
diff --git a/htdocs/geoloc/dynamap.php b/htdocs/geoloc/dynamap.php
deleted file mode 100644 (file)
index b2925c4..0000000
+++ /dev/null
@@ -1,44 +0,0 @@
-<?php
-/***************************************************************************
- *  Copyright (C) 2003-2006 Polytechnique.org                              *
- *  http://opensource.polytechnique.org/                                   *
- *                                                                         *
- *  This program is free software; you can redistribute it and/or modify   *
- *  it under the terms of the GNU General Public License as published by   *
- *  the Free Software Foundation; either version 2 of the License, or      *
- *  (at your option) any later version.                                    *
- *                                                                         *
- *  This program is distributed in the hope that it will be useful,        *
- *  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('xorg.inc.php');
-
-new_nonhtml_page('', AUTH_COOKIE);
-
-$querystring = "";
-foreach ($_GET as $v => $a)
-       if ($v != 'initfile')
-               $querystring .= '&'.urlencode($v).'='.urlencode($a);
-$initfile = urlencode('geolocInit.php?'.$querystring);
-
-if (urlencode(Env::get('initfile')) != $initfile)
-{
-       header("Location: dynamap.php?initfile=$initfile{$querystring}");
-       die();
-}
-
-header("Content-type: application/x-shockwave-flash");
-
-if ($globals->geoloc->use_map())
-       readfile($globals->geoloc->dynamap_path);
-
-?>
diff --git a/htdocs/geoloc/geolocInit.php b/htdocs/geoloc/geolocInit.php
deleted file mode 100644 (file)
index 6ecc2ca..0000000
+++ /dev/null
@@ -1,13 +0,0 @@
-<?php 
-require_once('xorg.inc.php');
-
-header("Content-type: text/xml");
-new_nonhtml_page('geoloc/geolocInit.tpl', AUTH_COOKIE);
-
-$querystring = "";
-foreach ($_GET as $v => $a)
-       if ($v != 'initfile')
-               $querystring .= '&'.urlencode($v).'='.urlencode($a);
-$page->assign('querystring',$querystring);
-$page->run();
-?>
diff --git a/htdocs/geoloc/getCityInfos.php b/htdocs/geoloc/getCityInfos.php
deleted file mode 100644 (file)
index 5014135..0000000
+++ /dev/null
@@ -1,53 +0,0 @@
-<?php
-/***************************************************************************
- *  Copyright (C) 2003-2006 Polytechnique.org                              *
- *  http://opensource.polytechnique.org/                                   *
- *                                                                         *
- *  This program is free software; you can redistribute it and/or modify   *
- *  it under the terms of the GNU General Public License as published by   *
- *  the Free Software Foundation; either version 2 of the License, or      *
- *  (at your option) any later version.                                    *
- *                                                                         *
- *  This program is distributed in the hope that it will be useful,        *
- *  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('xorg.inc.php');
-
-header("Content-type: text/xml");
-
-new_nonhtml_page('geoloc/getCityInfos.tpl', AUTH_COOKIE);
-// to debug sql use the next line
-//new_skinned_page('', AUTH_COOKIE);
-
-require_once('geoloc.inc.php');
-require_once('search.inc.php');
-
-$usual_fields = advancedSearchFromInput();
-$fields = new SFieldGroup(true, $usual_fields);
-$where = $fields->get_where_statement();
-if ($where) $where = "WHERE ".$where;
-
-$users = $globals->xdb->iterator("
-    SELECT u.user_id AS id, u.prenom, u.nom, u.promo
-      FROM adresses AS a 
-INNER JOIN auth_user_md5 AS u ON(u.user_id = a.uid)
-INNER JOIN auth_user_quick AS q ON(q.user_id = a.uid)
-        ".$fields->get_select_statement()."
-        ".$where."
-     GROUP BY u.user_id LIMIT 11",
-        $id);
-
-$page->assign('users', $users);
-
-$page->run();
-// vim:set et sw=4 sts=4 sws=4 foldmethod=marker:
-?>
diff --git a/htdocs/geoloc/getData.php b/htdocs/geoloc/getData.php
deleted file mode 100644 (file)
index d358631..0000000
+++ /dev/null
@@ -1,54 +0,0 @@
-<?php
-/***************************************************************************
- *  Copyright (C) 2003-2006 Polytechnique.org                              *
- *  http://opensource.polytechnique.org/                                   *
- *                                                                         *
- *  This program is free software; you can redistribute it and/or modify   *
- *  it under the terms of the GNU General Public License as published by   *
- *  the Free Software Foundation; either version 2 of the License, or      *
- *  (at your option) any later version.                                    *
- *                                                                         *
- *  This program is distributed in the hope that it will be useful,        *
- *  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('xorg.inc.php');
-
-// to debug sql use the next line
-if (Env::has('debug'))
-       new_simple_page('geoloc/getData.tpl', AUTH_COOKIE);
-else
-{
-       header("Content-type: text/xml");
-       new_nonhtml_page('geoloc/getData.tpl', AUTH_COOKIE);
-}
-
-require_once('geoloc.inc.php');
-require_once('search.inc.php');
-
-$querystring = "";
-foreach ($_GET as $v => $a)
-       if ($v != 'mapid')
-               $querystring .= urlencode($v).'='.urlencode($a).'&amp;';
-$page->assign('searchvars', $querystring);
-if (Env::has('mapid'))
-    $mapid = Env::getInt('mapid', -2);
-else
-    $mapid = false;
-    
-list($countries, $cities) = geoloc_getData_subcountries($mapid, advancedSearchFromInput(), 10);
-
-$page->assign('countries', $countries);
-$page->assign('cities', $cities);
-
-$page->run();
-// vim:set et sw=4 sts=4 sws=4 foldmethod=marker:
-?>
diff --git a/htdocs/geoloc/icon.php b/htdocs/geoloc/icon.php
deleted file mode 100644 (file)
index 07bd17c..0000000
+++ /dev/null
@@ -1,32 +0,0 @@
-<?php
-/***************************************************************************
- *  Copyright (C) 2003-2006 Polytechnique.org                              *
- *  http://opensource.polytechnique.org/                                   *
- *                                                                         *
- *  This program is free software; you can redistribute it and/or modify   *
- *  it under the terms of the GNU General Public License as published by   *
- *  the Free Software Foundation; either version 2 of the License, or      *
- *  (at your option) any later version.                                    *
- *                                                                         *
- *  This program is distributed in the hope that it will be useful,        *
- *  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('xorg.inc.php');
-
-new_nonhtml_page('', AUTH_COOKIE);
-
-header("Content-type: application/x-shockwave-flash");
-
-if ($globals->geoloc->use_map())
-       readfile($globals->geoloc->icon_path);
-
-?>
diff --git a/htdocs/geoloc/index.php b/htdocs/geoloc/index.php
deleted file mode 100644 (file)
index 8f13d57..0000000
+++ /dev/null
@@ -1,40 +0,0 @@
-<?php
-/***************************************************************************
- *  Copyright (C) 2003-2005 Polytechnique.org                              *
- *  http://opensource.polytechnique.org/                                   *
- *                                                                         *
- *  This program is free software; you can redistribute it and/or modify   *
- *  it under the terms of the GNU General Public License as published by   *
- *  the Free Software Foundation; either version 2 of the License, or      *
- *  (at your option) any later version.                                    *
- *                                                                         *
- *  This program is distributed in the hope that it will be useful,        *
- *  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('xorg.inc.php');
-new_skinned_page('geoloc/index.tpl', AUTH_COOKIE);
-
-$res = $globals->xdb->query('SELECT COUNT(DISTINCT uid) FROM adresses WHERE cityid IS NOT NULL');
-$page->assign('localises', $res->fetchOneCell());
-
-       require_once('search.inc.php');
-$fields = new SFieldGroup(true, advancedSearchFromInput());
-$search = $fields->get_url();
-if (Env::has('only_current') && Env::get('only_current') != 'on') $search .= '&only_current=';
-$search = preg_replace('/(^|&amp;)mapid=([0-9]+)(&amp;|$)/','\1\3', $search);
-if ($search)
-       $page->assign('dynamap_vars', $search);
-
-$page->assign('use_map', $globals->geoloc->use_map());
-$page->run();
-
-// vim:set et sws=4 sw=4 sts=4:
-?>
index 1998766..0ce18ee 100644 (file)
@@ -43,10 +43,18 @@ class CoreModule extends PLModule
             'exit'        => $this->make_hook('exit', AUTH_PUBLIC),
             'cacert.pem'  => $this->make_hook('cacert', AUTH_PUBLIC),
             'changelog'   => $this->make_hook('changelog', AUTH_PUBLIC),
-            'purge_cache' => $this->make_hook('purge_cache', AUTH_COOKIE, 'admin')
+            'purge_cache' => $this->make_hook('purge_cache', AUTH_COOKIE, 'admin'),
+
+            'valid.html'  => $this->make_hook('valid', AUTH_PUBLIC),
         );
     }
 
+    function handler_valid(&$page)
+    {
+        readfile($page->compile_dir.'/valid.html');
+        exit;
+    }
+
     function handler_index(&$page)
     {
         if (logged()) {
diff --git a/modules/geoloc.php b/modules/geoloc.php
new file mode 100644 (file)
index 0000000..db56da2
--- /dev/null
@@ -0,0 +1,186 @@
+<?php
+/***************************************************************************
+ *  Copyright (C) 2003-2006 Polytechnique.org                              *
+ *  http://opensource.polytechnique.org/                                   *
+ *                                                                         *
+ *  This program is free software; you can redistribute it and/or modify   *
+ *  it under the terms of the GNU General Public License as published by   *
+ *  the Free Software Foundation; either version 2 of the License, or      *
+ *  (at your option) any later version.                                    *
+ *                                                                         *
+ *  This program is distributed in the hope that it will be useful,        *
+ *  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                *
+ ***************************************************************************/
+
+class GeolocModule extends PLModule
+{
+    function handlers()
+    {
+        return array(
+            'geoloc'                  => $this->make_hook('default', AUTH_COOKIE),
+            'geoloc/icon.php'         => $this->make_hook('icon',    AUTH_COOKIE),
+            'geoloc/dynamap.php'      => $this->make_hook('dynamap', AUTH_COOKIE),
+            'geoloc/geolocInit.php'   => $this->make_hook('init',    AUTH_COOKIE),
+            'geoloc/getCityInfos.php' => $this->make_hook('city',    AUTH_COOKIE),
+            'geoloc/getData.php'      => $this->make_hook('data',    AUTH_COOKIE),
+        );
+    }
+
+    function _make_qs()
+    {
+        $querystring = "";
+
+        foreach ($_GET as $v => $a) {
+            if ($v != 'initfile') {
+                $querystring .= '&'.urlencode($v).'='.urlencode($a);
+            }
+        }
+
+        return $querystring;
+    }
+
+    function handler_default(&$page)
+    {
+        global $globals;
+
+        require_once 'search.inc.php';
+
+        $page->changeTpl('geoloc/index.tpl');
+
+        $res = $globals->xdb->query('SELECT COUNT(DISTINCT uid)
+                                       FROM adresses WHERE cityid IS NOT NULL');
+        $page->assign('localises', $res->fetchOneCell());
+
+        $fields = new SFieldGroup(true, advancedSearchFromInput());
+        $search = $fields->get_url();
+        if (Env::has('only_current') && Env::get('only_current') != 'on') {
+            $search .= '&only_current=';
+        }
+        $search = preg_replace('/(^|&amp;)mapid=([0-9]+)(&amp;|$)/','\1\3', $search);
+        if ($search) {
+            $page->assign('dynamap_vars', $search);
+        }
+
+        $page->assign('use_map', $globals->geoloc->use_map());
+
+        return PL_OK;
+    }
+
+    function handler_icon(&$page)
+    {
+        global $globals;
+
+        header("Content-type: application/x-shockwave-flash");
+
+        if ($globals->geoloc->use_map()) {
+            readfile($globals->geoloc->icon_path);
+            exit;
+        }
+
+        return PL_NOT_FOUND;
+    }
+
+    function handler_dynamap(&$page)
+    {
+        global $globals;
+
+        $querystring = $this->_make_qs();
+        $initfile    = urlencode('geolocInit.php?'.$querystring);
+
+        if (urlencode(Env::get('initfile')) != $initfile) {
+            header("Location: dynamap.php?initfile=$initfile{$querystring}");
+            die();
+        }
+
+        header("Content-type: application/x-shockwave-flash");
+
+        if ($globals->geoloc->use_map()) {
+            readfile($globals->geoloc->dynamap_path);
+            exit;
+        }
+
+        return PL_NOT_FOUND;
+    }
+
+    function handler_init(&$page)
+    {
+        global $globals;
+
+        new_nonhtml_page('geoloc/geolocInit.tpl', AUTH_COOKIE);
+
+        header('Content-type: text/xml');
+        $page->assign('querystring', $this->_make_qs());
+
+        return PL_OK;
+    }
+
+    function handler_city(&$page)
+    {
+        global $globals;
+
+        header("Content-type: text/xml");
+
+        new_nonhtml_page('geoloc/getCityInfos.tpl', AUTH_COOKIE);
+        // to debug sql use the next line
+        //new_skinned_page('', AUTH_COOKIE);
+
+        require_once('geoloc.inc.php');
+        require_once('search.inc.php');
+
+        $usual_fields = advancedSearchFromInput();
+        $fields = new SFieldGroup(true, $usual_fields);
+        $where = $fields->get_where_statement();
+        if ($where) $where = "WHERE ".$where;
+
+        $users = $globals->xdb->iterator("
+            SELECT u.user_id AS id, u.prenom, u.nom, u.promo
+              FROM adresses AS a 
+        INNER JOIN auth_user_md5 AS u ON(u.user_id = a.uid)
+        INNER JOIN auth_user_quick AS q ON(q.user_id = a.uid)
+                ".$fields->get_select_statement()."
+                ".$where."
+             GROUP BY u.user_id LIMIT 11", $id);
+
+        $page->assign('users', $users);
+
+        return PL_OK;
+    }
+
+    function handler_data(&$page)
+    {
+        global $globals;
+
+        // to debug sql use the next line
+        if (Env::has('debug')) {
+            $page->changeTpl('geoloc/getData.tpl');
+            $page->assign('simple', true);
+        } else {
+            header("Content-type: text/xml");
+            new_nonhtml_page('geoloc/getData.tpl', AUTH_COOKIE);
+        }
+
+        require_once 'geoloc.inc.php';
+        require_once 'search.inc.php';
+
+        $querystring = $this->_make_qs();
+        $page->assign('searchvars', $querystring);
+
+        $mapid = Env::has('mapid') ? Env::getInt('mapid', -2) : false;
+
+        list($countries, $cities) = geoloc_getData_subcountries($mapid, advancedSearchFromInput(), 10);
+
+        $page->assign('countries', $countries);
+        $page->assign('cities', $cities);
+
+        return PL_OK;
+    }
+}
+
+?>