Merge remote branch 'origin/platal-1.0.0'
[platal.git] / plugins / function.display_address.php
1 <?php
2 /***************************************************************************
3 * Copyright (C) 2003-2010 Polytechnique.org *
4 * http://opensource.polytechnique.org/ *
5 * *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation; either version 2 of the License, or *
9 * (at your option) any later version. *
10 * *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program; if not, write to the Free Software *
18 * Foundation, Inc., *
19 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
20 ***************************************************************************/
21
22 function display_address_isIdentity($idt, $value, $test_reverse = true)
23 {
24 $value = strtolower(replace_accent($value));
25 $idt = strtolower(replace_accent($idt));
26 $idt = preg_replace('/[^a-z]/', '', $idt);
27
28 $value = preg_replace('/[^a-z]/', '', $value);
29 if (strpos($value, $idt) !== false || strpos($idt, $value) !== false || levenshtein($value, $idt) < strlen($idt) / 3) {
30 return true;
31 }
32
33 if ($test_reverse) {
34 return display_address_isIdentity($idt, implode(' ', array_reverse(explode(' ', $value))), false);
35 }
36 return false;
37 }
38
39 function smarty_function_display_address($param, &$smarty)
40 {
41 require_once('geocoding.inc.php');
42 $adr = $param['adr'];
43 $txtad = $adr->text;
44 if (!$txtad) {
45 $txthtml = '';
46 if ($adr->phones() && count($adr->phones())) {
47 require_once 'function.display_phones.php';
48 $txthtml .= smarty_function_display_phones(array('tels' => $adr->phones()), $smarty);
49 } elseif (isset($param['phones']) && count($param['phones'])) {
50 require_once 'function.display_phones.php';
51 $txthtml .= smarty_function_display_phones(array('tels' => $param['phones']), $smarty);
52 }
53 if (!isset($param['nodiv']) && $txthtml != '' && isset($param['pos'])) {
54 $txthtml = '<div class="adresse" style="float: ' . $param['pos'] . '">' . $txthtml . '</div>';
55 }
56 return $txthtml;
57 }
58
59 $lines = explode("\n", $txtad);
60 $idt = array_shift($lines);
61 $restore = true;
62
63 if (!display_address_isIdentity($param['for'], $idt)) {
64 array_unshift($lines, $idt);
65 $idt = $param['for'];
66 $restore = false;
67 }
68
69 $txthtml = "";
70 $map = "<a href=\"http://maps.google.fr/?q="
71 . urlencode(implode(", ", $lines) . " ($idt)")
72 . "\"><img src=\"images/icons/map.gif\" alt=\"Google Maps\" title=\"Carte\"/></a>";
73 $comment = "";
74 if ($adr->comment != "")
75 {
76 $commentHtml = str_replace(array('&', '"'), array('&amp;', '&quot;'), $adr->comment);
77 $commentJs = str_replace(array('\\', '\''), array('\\\\', '\\\''), $commentHtml);
78 $comment = "<img style=\"margin-left: 5px;\" src=\"images/icons/comments.gif\""
79 . " onmouseover=\"return overlib('"
80 . $commentJs
81 . "',WIDTH,250);\""
82 . " onmouseout=\"nd();\""
83 . " alt=\"Commentaire\" title=\""
84 . $commentHtml
85 . "\"/>";
86 }
87 if ($restore) {
88 array_unshift($lines, $idt);
89 }
90 if ($param['titre'])
91 {
92 if ($param['titre_div'])
93 $txthtml .= "<div class='titre'>".pl_entity_decode($param['titre'])."&nbsp;".$map.$comment."</div>\n";
94 else
95 $txthtml .= "<em>".pl_entity_decode($param['titre'])."&nbsp;</em>".$map.$comment."<br />\n";
96 }
97 foreach ($lines as $line)
98 {
99 $txthtml .= "<strong>" . pl_entities($line) . "</strong><br/>\n";
100 }
101 if ($adr->phones() != null) {
102 require_once 'function.display_phones.php';
103 $txthtml .= smarty_function_display_phones(array('tels' => $adr->phones()),$smarty);
104 } else if ($param['phones'] != null) {
105 require_once 'function.display_phones.php';
106 $txthtml .= smarty_function_display_phones(array('tels' => $param['phones']),$smarty);
107 }
108 if (!$param['nodiv']) {
109 $pos = $param['pos'] ? " style='float: " . $param['pos'] . "'" : '';
110 $txthtml = "<div class='adresse' $pos>\n".$txthtml."</div>\n";
111 }
112 return $txthtml;
113 }
114
115 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
116 ?>