Commit | Line | Data |
---|---|---|
80ca1b4e | 1 | <?php |
2 | /*************************************************************************** | |
12262f13 | 3 | * Copyright (C) 2003-2011 Polytechnique.org * |
80ca1b4e | 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 | ||
3641a0e6 | 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 | ||
eaf30d86 PH |
33 | if ($test_reverse) { |
34 | return display_address_isIdentity($idt, implode(' ', array_reverse(explode(' ', $value))), false); | |
3641a0e6 | 35 | } |
36 | return false; | |
37 | } | |
80ca1b4e | 38 | |
26ba053e | 39 | function smarty_function_display_address($param, $smarty) |
92630203 | 40 | { |
3a5feb70 RB |
41 | $adr = $param['adr']; |
42 | $txtad = $adr->text; | |
fde60e9f SJ |
43 | if (!$txtad) { |
44 | $txthtml = ''; | |
45 | if ($adr->phones() && count($adr->phones())) { | |
46 | require_once 'function.display_phones.php'; | |
47 | $txthtml .= smarty_function_display_phones(array('tels' => $adr->phones()), $smarty); | |
48 | } elseif (isset($param['phones']) && count($param['phones'])) { | |
49 | require_once 'function.display_phones.php'; | |
50 | $txthtml .= smarty_function_display_phones(array('tels' => $param['phones']), $smarty); | |
51 | } | |
52 | if (!isset($param['nodiv']) && $txthtml != '' && isset($param['pos'])) { | |
53 | $txthtml = '<div class="adresse" style="float: ' . $param['pos'] . '">' . $txthtml . '</div>'; | |
54 | } | |
55 | return $txthtml; | |
bde2be3b | 56 | } |
80ca1b4e | 57 | |
a450ecb7 | 58 | $lines = explode("\n", $txtad); |
3641a0e6 | 59 | $idt = array_shift($lines); |
60 | $restore = true; | |
61 | ||
62 | if (!display_address_isIdentity($param['for'], $idt)) { | |
63 | array_unshift($lines, $idt); | |
64 | $idt = $param['for']; | |
65 | $restore = false; | |
66 | } | |
92630203 | 67 | |
80ca1b4e | 68 | $txthtml = ""; |
92630203 | 69 | $map = "<a href=\"http://maps.google.fr/?q=" |
1a5db4b8 | 70 | . urlencode(implode(", ", $lines) . " ($idt)") |
6261a1b5 | 71 | . "\"><img src=\"images/icons/map.gif\" alt=\"Google Maps\" title=\"Carte\"/></a>"; |
646a4582 | 72 | $comment = ""; |
439d5e1b | 73 | if ($adr->comment != "") |
646a4582 | 74 | { |
3a5feb70 | 75 | $commentHtml = str_replace(array('&', '"'), array('&', '"'), $adr->comment); |
646a4582 GB |
76 | $commentJs = str_replace(array('\\', '\''), array('\\\\', '\\\''), $commentHtml); |
77 | $comment = "<img style=\"margin-left: 5px;\" src=\"images/icons/comments.gif\"" | |
78 | . " onmouseover=\"return overlib('" | |
79 | . $commentJs | |
80 | . "',WIDTH,250);\"" | |
81 | . " onmouseout=\"nd();\"" | |
82 | . " alt=\"Commentaire\" title=\"" | |
83 | . $commentHtml | |
84 | . "\"/>"; | |
85 | } | |
3641a0e6 | 86 | if ($restore) { |
87 | array_unshift($lines, $idt); | |
88 | } | |
80ca1b4e | 89 | if ($param['titre']) |
90 | { | |
bf73c651 | 91 | if ($param['titre_div']) |
646a4582 | 92 | $txthtml .= "<div class='titre'>".pl_entity_decode($param['titre'])." ".$map.$comment."</div>\n"; |
6261a1b5 | 93 | else |
646a4582 | 94 | $txthtml .= "<em>".pl_entity_decode($param['titre'])." </em>".$map.$comment."<br />\n"; |
80ca1b4e | 95 | } |
96 | foreach ($lines as $line) | |
97 | { | |
d145d605 | 98 | $txthtml .= "<strong>" . pl_entities($line) . "</strong><br/>\n"; |
80ca1b4e | 99 | } |
413b6645 SJ |
100 | if ($adr->phones() != null) { |
101 | require_once 'function.display_phones.php'; | |
3a5feb70 | 102 | $txthtml .= smarty_function_display_phones(array('tels' => $adr->phones()),$smarty); |
efb74b8f | 103 | } else if (isset($param['phones']) && count($param['phones'])) { |
413b6645 SJ |
104 | require_once 'function.display_phones.php'; |
105 | $txthtml .= smarty_function_display_phones(array('tels' => $param['phones']),$smarty); | |
79a5acea | 106 | } |
6261a1b5 | 107 | if (!$param['nodiv']) { |
108 | $pos = $param['pos'] ? " style='float: " . $param['pos'] . "'" : ''; | |
109 | $txthtml = "<div class='adresse' $pos>\n".$txthtml."</div>\n"; | |
80ca1b4e | 110 | } |
111 | return $txthtml; | |
112 | } | |
113 | ||
a7de4ef7 | 114 | // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: |
80ca1b4e | 115 | ?> |