Warning, file /webapps/ocs-webserver/application/modules/default/views/helpers/Bbcode2html.php was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 <?php
0002 
0003 /**
0004  *  ocs-webserver
0005  *
0006  *  Copyright 2016 by pling GmbH.
0007  *
0008  *    This file is part of ocs-webserver.
0009  *
0010  *    This program is free software: you can redistribute it and/or modify
0011  *    it under the terms of the GNU Affero General Public License as
0012  *    published by the Free Software Foundation, either version 3 of the
0013  *    License, or (at your option) any later version.
0014  *
0015  *    This program is distributed in the hope that it will be useful,
0016  *    but WITHOUT ANY WARRANTY; without even the implied warranty of
0017  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0018  *    GNU Affero General Public License for more details.
0019  *
0020  *    You should have received a copy of the GNU Affero General Public License
0021  *    along with this program.  If not, see <http://www.gnu.org/licenses/>.
0022  **/
0023 class Default_View_Helper_Bbcode2html extends Zend_View_Helper_Abstract
0024 {
0025 
0026     /**
0027      * transforms a string with bbcode markup into html
0028      *
0029      * @param string $txt
0030      * @param bool   $nl2br
0031      *
0032      * @return string
0033      */
0034     function Bbcode2html($txt, $nl2br = true, $forcecolor = '')
0035     {
0036 
0037         if (!empty($forcecolor)) {
0038             $fc = ' style="color:' . $forcecolor . ';"';
0039         } else {
0040             $fc = '';
0041         }
0042         $newtxt = htmlspecialchars($txt);
0043         if ($nl2br) {
0044             $newtxt = nl2br($newtxt);
0045         }
0046 
0047         $patterns = array(
0048             '`\[b\](.+?)\[/b\]`is',
0049             '`\[i\](.+?)\[/i\]`is',
0050             '`\[u\](.+?)\[/u\]`is',
0051             '`\[li\](.+?)\[/li\]`is',
0052             '`\[strike\](.+?)\[/strike\]`is',
0053             '`\[url\]([a-z0-9]+?://){1}([\w\-]+\.([\w\-]+\.)*[\w]+(:[0-9]+)?(/[^ \"\n\r\t<]*)?)\[/url\]`si',
0054             '`\[quote\](.+?)\[/quote\]`is',
0055             '`\[indent](.+?)\[/indent\]`is'
0056         );
0057 
0058         $replaces = array(
0059             '<strong' . $fc . '>\\1</strong>',
0060             '<em' . $fc . '>\\1</em>',
0061             '<span style="border-bottom: 1px dotted">\\1</span>',
0062             '<li' . $fc . ' style="margin-left:20px;">\\1</li>',
0063             '<strike' . $fc . '>\\1</strike>',
0064             '<a href="\1\2" rel="nofollow" target="_blank">\1\2</a>',
0065             '<strong' . $fc
0066             . '>Quote:</strong><div style="margin:0px 10px;padding:5px;background-color:#F7F7F7;border:1px dotted #CCCCCC;width:80%;"><em>\1</em></div>',
0067             '<pre' . $fc . '>\\1</pre>'
0068         );
0069 
0070         $newtxt = preg_replace($patterns, $replaces, $newtxt);
0071         return ($newtxt);
0072     }
0073 
0074 }