$tpl = new Galette\Core\Smarty($base_path);
$tpl->muteExpectedErrors();
+$tpl->registerClass('GaletteMail', '\Galette\Core\GaletteMail');
+
/**
* Return member name. Smarty cannot directly use static functions
*
if ( !$valid ) {
$log->log(
'[GaletteMail] Adresss `' . $address . '` is not valid ',
- KLogger::INFO
+ KLogger::DEBUG
+ );
+ }
+ return $valid;
+ }
+
+ /**
+ * Check if a string is an url
+ *
+ * @param string $url the url to check
+ *
+ * @return true if address is string is an url, false otherwise
+ */
+ public static function isUrl( $url )
+ {
+ global $log;
+ $valid = preg_match(
+ '|^http(s)?://[a-z0-9-]+(.[a-z0-9-]+)*(:[0-9]+)?(/.*)?$|i',
+ $url
+ );
+ if ( !$valid ) {
+ $log->log(
+ '[GaletteMail] `' . $url . '` is not an url',
+ KLogger::DEBUG
);
}
return $valid;
<th>{$field.field_name|escape}</th>
<td>
{section name="fieldLoop" start=1 loop=$field.field_repeat+1}
+ {if GaletteMail::isValidEmail($data.dyn[$field.field_id][$smarty.section.fieldLoop.index])}
+ {if $smarty.section.fieldLoop.index_prev > 0}<br />{/if}
+ <a href="mailto:{$data.dyn[$field.field_id][$smarty.section.fieldLoop.index]}">{$data.dyn[$field.field_id][$smarty.section.fieldLoop.index]}</a>
+ {else if GaletteMail::isUrl($data.dyn[$field.field_id][$smarty.section.fieldLoop.index])}
+ {if $smarty.section.fieldLoop.index_prev > 0}<br />{/if}
+ <a href="{$data.dyn[$field.field_id][$smarty.section.fieldLoop.index]}" target="_blank" title="{_T string="Open '%s' in a new window" replace=$data.dyn[$field.field_id][$smarty.section.fieldLoop.index] pattern="/%s/"}">{$data.dyn[$field.field_id][$smarty.section.fieldLoop.index]}</a>
+ {else}
{$data.dyn[$field.field_id][$smarty.section.fieldLoop.index]|nl2br|default:" "}<br/>
+ {/if}
{/section}
</td>
</tr>