]> git.agnieray.net Git - galette.git/commitdiff
Links on dynamic fields; fixes #355
authorJohan Cwiklinski <johan@x-tnd.be>
Tue, 4 Sep 2012 07:05:16 +0000 (09:05 +0200)
committerJohan Cwiklinski <johan@x-tnd.be>
Tue, 4 Sep 2012 16:04:08 +0000 (18:04 +0200)
Display dynamic fields containing mails adresses as mailto links
Display dynamic fields containing URLs as links

galette/includes/smarty.inc.php
galette/lib/Galette/Core/GaletteMail.php
galette/templates/default/display_dynamic_fields.tpl

index 39d03821e8fa849350d4ba5e98b4778666c77697..44506b43706db0f6a4fe9ac68617d2c34b4eb6a9 100644 (file)
@@ -41,6 +41,8 @@ $template_subdir = 'templates/' . $preferences->pref_theme . '/';
 $tpl = new Galette\Core\Smarty($base_path);
 $tpl->muteExpectedErrors();
 
+$tpl->registerClass('GaletteMail', '\Galette\Core\GaletteMail');
+
 /**
 * Return member name. Smarty cannot directly use static functions
 *
index 9bee3dcd69c9b651fd1de33cc2c71ba124cecabb..30434b7cdd9222916e133d3ea5bf5019e100a7c2 100644 (file)
@@ -320,7 +320,30 @@ class GaletteMail
         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;
index c8264878878c2c0256aecc69dd5671324708ec58..b85d30e05af5894178350c79a232dd4c98f4ab73 100644 (file)
         <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:"&nbsp;"}<br/>
+            {/if}
                 {/section}
         </td>
     </tr>