X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;f=plugins%2Ffunction.display_address.php;h=b755e92fbdf77141d44708a890ad12d0e93437be;hb=cfefeac65aa41c78c02c145070c1c6b489f5a935;hp=fe5d355cbdf06fbc8a21ecf1dfcbbe6453b10653;hpb=92630203925015ac6f70faaf4aacd05d26e5924b;p=platal.git
diff --git a/plugins/function.display_address.php b/plugins/function.display_address.php
index fe5d355..b755e92 100644
--- a/plugins/function.display_address.php
+++ b/plugins/function.display_address.php
@@ -19,6 +19,22 @@
* 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);
+
+ $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)
{
@@ -30,20 +46,30 @@ function smarty_function_display_address($param, &$smarty)
!$param['adr']['fax'] &&
!$param['adr']['mobile']) return "";
+
$lines = explode("\n", $txtad);
- $idt = array_shift($lines);
+ $idt = array_shift($lines);
+ $restore = true;
+
+ if (!display_address_isIdentity($param['for'], $idt)) {
+ array_unshift($lines, $idt);
+ $idt = $param['for'];
+ $restore = false;
+ }
$txthtml = "";
$map = "";
- array_unshift($lines, $idt);
+ . urlencode(implode(", ", $lines) . " ($idt)")
+ . "\">
";
+ if ($restore) {
+ array_unshift($lines, $idt);
+ }
if ($param['titre'])
{
if ($param['titre_div'])
$txthtml .= "