]> git.sur5r.net Git - contagged/blob - smarty/plugins/modifier.noteparser.php
18553cee10b67cfb90e428abd76de19bf7ad5a82
[contagged] / smarty / plugins / modifier.noteparser.php
1 <?php
2 /**
3  * Smarty plugin
4  * @package Smarty
5  * @subpackage plugins
6  */
7
8
9 /**
10  * Smarty plugin
11  *
12  * Type:     modifier
13  * Name:     noteparser
14  * Date:     Feb 26, 2003
15  * Purpose:  Converts plaintext notes to richer HTML (very simple)
16  * Example:  {$entry.note|noteparser}
17  * @author       Andreas Gohr <gohr@cosmocode.de>
18  * @param string
19  * @return string
20  */
21 function smarty_modifier_noteparser($string){
22     $string = htmlspecialchars($string);
23
24     $string = preg_replace('!\*\*Call\*\*!i','<img src="pix/phone.png" width="16" height="16" alt="Call" />',$string);
25     $string = preg_replace('!\*\*ToDo\*\*!i','<img src="pix/arrow_right.png" width="16" height="16" alt="ToDo" />',$string);
26     $string = preg_replace('!\*\*Mail\*\*!i','<img src="pix/email.png" width="16" height="16" alt="Mail" />',$string);
27     $string = preg_replace('!\*\*Note\*\*!i','<img src="pix/note.png" width="16" height="16" alt="note" />',$string);
28
29     $string = preg_replace('!\*\*(.*?)\*\*!','<b>\\1</b>',$string);
30     $string = preg_replace('!__(.*?)__!','<u>\\1</u>',$string);
31     $string = preg_replace('!//(.*?)//!','<i>\\1</i>',$string);
32
33     $string = preg_replace('!(https?://[\w;/?:@&=+$\-_.\!~*\\\']+)!i',
34                            '<a href="\\1">\\1</a>',$string);
35
36     $string = preg_replace('!\n\n+!','</p><p>',$string);
37     $string = nl2br($string);
38
39     return '<p>'.$string.'</p>';
40 }
41
42 /* vim: set expandtab: */
43
44 ?>