X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;f=plugins%2Ffunction.display_address.php;h=25c991e16f1e9e0d985a45c3993d5eb6dac78585;hb=189db14d85791824e335cf2b7253891e7c6ea96f;hp=45cbb8e535e55da0d58ca56766fe5dafaf265443;hpb=a7de4ef724d1a3b0bf978a50ce7cc9d23412c7a0;p=platal.git diff --git a/plugins/function.display_address.php b/plugins/function.display_address.php index 45cbb8e..25c991e 100644 --- a/plugins/function.display_address.php +++ b/plugins/function.display_address.php @@ -19,8 +19,25 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * ***************************************************************************/ +function display_address_isIdentity($idt, $value, $test_reverse = true) +{ + $value = strtolower(replace_accent($value)); + $idt = strtolower(replace_accent($idt)); + $idt = preg_replace('/[^a-z]/', '', $idt); -function smarty_function_display_address($param, &$smarty) { + $value = preg_replace('/[^a-z]/', '', $value); + if (strpos($value, $idt) !== false || strpos($idt, $value) !== false || levenshtein($value, $idt) < strlen($idt) / 3) { + return true; + } + + if ($test_reverse) { + return display_address_isIdentity($idt, implode(' ', array_reverse(explode(' ', $value))), false); + } + return false; +} + +function smarty_function_display_address($param, &$smarty) +{ require_once('geoloc.inc.php'); $txtad = get_address_text($param['adr']); if (!$txtad && @@ -29,15 +46,30 @@ function smarty_function_display_address($param, &$smarty) { !$param['adr']['fax'] && !$param['adr']['mobile']) return ""; + $lines = explode("\n", $txtad); + $idt = array_shift($lines); + $restore = true; + + if (!display_address_isIdentity($param['for'], $idt)) { + array_unshift($lines, $idt); + $idt = $param['for']; + $restore = false; + } + $txthtml = ""; - $map = "\"Google"; + $map = "\"Google"; + if ($restore) { + array_unshift($lines, $idt); + } if ($param['titre']) { if ($param['titre_div']) $txthtml .= "
".$param['titre'].$map."
\n"; - else - $txthtml .= "".$param['titre']."".$map."
\n"; + else + $txthtml .= "".$param['titre']."".$map."
\n"; } foreach ($lines as $line) { @@ -50,12 +82,12 @@ function smarty_function_display_address($param, &$smarty) { if ($param['adr']['mobile']) $txthtml .= "
\nTél : \n".$param['adr']['mobile']."\n
\n"; if ($param['adr']['tels'] && count($param['adr']['tels'])) { - foreach ($param['adr']['tels'] as $tel) + foreach ($param['adr']['tels'] as $tel) $txthtml .= "
\n".$tel['tel_type']." : \n".$tel['tel']."\n
\n"; } - if (!$params['nodiv']) - { - $txthtml = "
\n".$txthtml."
\n"; + if (!$param['nodiv']) { + $pos = $param['pos'] ? " style='float: " . $param['pos'] . "'" : ''; + $txthtml = "
\n".$txthtml."
\n"; } return $txthtml; }