From 7ad5ac9ea41fa14c4c1950100cfee290509f2729 Mon Sep 17 00:00:00 2001 From: Pascal Corpet Date: Sat, 25 Jun 2005 18:16:23 +0000 Subject: [PATCH] synchro geoloc pour les admins git-archimport-id: opensource@polytechnique.org--2005/platal--mainline--0.9--patch-750 --- htdocs/admin/geoloc.php | 46 ++++++++++++++++++++++++++++++++++++++++++++++ include/geoloc.inc.php | 45 ++++++++++++++++++++++++++++++++++++++------- templates/admin/geoloc.tpl | 36 ++++++++++++++++++++++++++++++++++++ upgrade/0.9.8/00_admin.sql | 2 ++ upgrade/0.9.8/update.sh | 32 ++++++++++++++++++++++++++++++++ 5 files changed, 154 insertions(+), 7 deletions(-) create mode 100644 htdocs/admin/geoloc.php create mode 100644 templates/admin/geoloc.tpl create mode 100644 upgrade/0.9.8/00_admin.sql create mode 100755 upgrade/0.9.8/update.sh diff --git a/htdocs/admin/geoloc.php b/htdocs/admin/geoloc.php new file mode 100644 index 0000000..90148fa --- /dev/null +++ b/htdocs/admin/geoloc.php @@ -0,0 +1,46 @@ +xdb->iterRow("SELECT id FROM geoloc_city WHERE lat = 0 AND lon = 0"); + while ($a = $res->next()) if (synchro_city($a[0])) $nb_synchro++; +} + +if ($nb_synchro) + $page->trig(($nb_synchro > 1)?($nb_synchro." villes ont été synchronisées"):"Une ville a été synchronisée"); + +$res = $globals->xdb->query("SELECT COUNT(*) FROM geoloc_city WHERE lat = 0 AND lon = 0"); +$page->assign("nb_missinglat", $res->fetchOneCell()); + +$page->run(); + +// vim:set et sws=4 sts=4 sw=4: +?> diff --git a/include/geoloc.inc.php b/include/geoloc.inc.php index eaabbd0..4a1bf07 100644 --- a/include/geoloc.inc.php +++ b/include/geoloc.inc.php @@ -67,8 +67,11 @@ function _geoloc_region_smarty($params){ $page->register_function('geoloc_region', '_geoloc_region_smarty'); // }}} -// retrieve the infos on a text address -// store on the fly the info of the city concerned +// {{{ get_address_infos($txt) +/** retrieve the infos on a text address + * store on the fly the info of the city concerned + * @param $txt the raw text of an address + */ function get_address_infos($txt) { $url ="http://www.geoloc.org/adressparser/address.php?txt=".urlencode(utf8_encode($txt)); if (!($f = @fopen($url, 'r'))) return false; @@ -81,8 +84,12 @@ function get_address_infos($txt) { $globals->xdb->execute("REPLACE INTO geoloc_city VALUES ".$infos['sql']); return $infos; } +// }}} -// make the text of an address that can be read by a mailman +// {{{ get_address_text($adr) +/** make the text of an address that can be read by a mailman + * @param $adr an array with all the usual fields + */ function get_address_text($adr) { $t = ""; if ($adr['adr1']) $t.= $adr['adr1']; @@ -106,9 +113,13 @@ function get_address_text($adr) { if ($adr['countrytxt']) $t .= "\n".$adr['countrytxt']; return trim($t); } +// }}} -// compares if two address matches -// $b should be a complete valid address +// {{{ compare_addresses_text($a, $b) +/** compares if two address matches + * @param $a the raw text of an address + * @param $b the raw text of a complete valid address + */ function compare_addresses_text($a, $b) { $ta = strtoupper(preg_replace(array("/[0-9,\"'#~:;_\- ]/", "/\r\n/"), array("", "\n"), $a)); $tb = strtoupper(preg_replace(array("/[0-9,\"'#~:;_\- ]/", "/\r\n/"), array("", "\n"), $b)); @@ -121,6 +132,8 @@ function compare_addresses_text($a, $b) { return true; } +// }}} + function empty_address() { return Array( "adr1" => "", @@ -141,8 +154,11 @@ function cut_address($txt) { return array("adr1" => trim($a[1]), "adr2" => trim($a[3]), "adr3" => trim(str_replace("\n", " ", $a[5]))); } -// localize all the address of a user and modify the database -// if the new address match with the old one +// {{{ localize_addresses($uid) +/* localize all the address of a user and modify the database + * if the new address match with the old one + * @param $uid the id of the user + */ function localize_addresses($uid) { global $globals; $res = $globals->xdb->iterator("SELECT * FROM adresses WHERE uid = {?} and (cityid IS NULL OR cityid = 0)", $uid); @@ -169,6 +185,21 @@ function localize_addresses($uid) { } return $erreur; } +// }}} + +// {{{ synchro_city($id) +/** synchronise the local geoloc_city base to geoloc.org + * @param $id the id of the city to synchronize + */ + function synchro_city($id) { + $url ="http://www.geoloc.org/adressparser/cityFinder.php?method=id&id=".$id."&out=sql"; + if (!($f = @fopen($url, 'r'))) return false; + $s = fgets($f); + global $globals; + if ($s) + return $globals->xdb->execute("REPLACE INTO geoloc_city VALUES ".$s) > 0; + } + // }}} // vim:set et sw=4 sts=4 sws=4 foldmethod=marker: ?> diff --git a/templates/admin/geoloc.tpl b/templates/admin/geoloc.tpl new file mode 100644 index 0000000..5159741 --- /dev/null +++ b/templates/admin/geoloc.tpl @@ -0,0 +1,36 @@ +{**************************************************************************} +{* *} +{* Copyright (C) 2003-2004 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 *} +{* *} +{**************************************************************************} + +

Geoloc

+ +

Synchroniser des villes avec geoloc.org

+ +{if $nb_missinglat} +

[toutes les villes sans coordonnées ({$nb_missinglat})]

+{/if} + +
+

+La ville dont l'id est : +

+
+{* vim:set et sw=2 sts=2 sws=2: *} diff --git a/upgrade/0.9.8/00_admin.sql b/upgrade/0.9.8/00_admin.sql new file mode 100644 index 0000000..ae7fd08 --- /dev/null +++ b/upgrade/0.9.8/00_admin.sql @@ -0,0 +1,2 @@ +INSERT INTO admin_h2 VALUES(2, 11, 'Géoloc', 70); +INSERT INTO admin_a VALUES(11, 'Synchro', 'admin/geoloc.php',0); diff --git a/upgrade/0.9.8/update.sh b/upgrade/0.9.8/update.sh new file mode 100755 index 0000000..de82fc0 --- /dev/null +++ b/upgrade/0.9.8/update.sh @@ -0,0 +1,32 @@ +#!/bin/bash + +. ../inc/pervasive.sh + +mailman_stop +mailman_templates +mailman_start + + +########################################################### +for sql in *.sql +do + echo -n $sql + $MYSQL x4dat < $sql &>/dev/null || echo -n " ERROR" + echo . +done + +########################################################### + +echo "we will now upgrade the search table (this may be a long operation) + +please hit ^D to continue +" + +cat + +pushd ../../bin +./search.rebuild_db.php +popd + +########################################################### + -- 2.1.4