Main Page   File List   File Members   Related Pages  

htmlparse.inc.php

Go to the documentation of this file.
00001 <?php
00002 // $Header: /cvsroot/modphpcms/modphpcms/includes/htmlparse.inc.php,v 1.7 2004/06/08 14:56:08 fred87 Exp $
00003 
00024 function textToXHTML(&$text, $allowIMG, $NoTags = FALSE)
00025 {
00026         Iparse_markup($text, $allowIMG. $NoTags);
00027         if ($NoTags)
00028         {
00029                 $tagChars = "[:alnum:]/?.:&_-~=\"' ";
00030                 $pattern = "#<[$tagChars]+>#";
00031                 $text = preg_replace($pattern, '', $text);
00032         }
00033 }
00034 
00045 function RemoveHTML(&$text)
00046 {
00047         $text = str_replace('<', '&lt;', $text);
00048         $text = str_replace('>', '&gt;', $text);
00049 }
00050 
00062 function Iparse_markup(&$text, $allowIMG, $NoTags = FALSE)
00063 {
00064         /*
00065          * Idea taken from phpBB's bbcode.
00066          *
00067          * The implementation of phpBB's bbcode was used
00068          * as a source of reference.
00069          *
00070          */
00071 
00072         $image_lang = get_entry('lang', 'image');
00073         if ($image_lang == '')
00074         {
00075                 set_entry('lang', 'image', 'image');
00076                 $image_lang = 'image';
00077         }
00078 
00079         $hrefC = '[:alnum:]/?.:&_-~=';
00080         $normalC = "$hrefC @\[\]{}+\n\t";
00081 
00082         $text = str_replace('[br]', '<br />', $text);
00083         $text = str_replace('[hr]', '<hr />', $text);
00084         
00085         $text = str_replace('[b]', '<b>', $text);
00086         
00087         $text = str_replace('[/b]', '</b>', $text);
00088 
00089         $text = str_replace('[i]', '<i>', $text);
00090         $text = str_replace('[/i]', '</i>', $text);
00091 
00092         $text = str_replace('[u]', '<u>', $text);
00093         $text = str_replace('[/u]', '</u>', $text);
00094 
00095         $text = str_replace('[pre]', '<pre>', $text);
00096         $text = str_replace('[/pre]', '</pre>', $text);
00097         
00098         $text = str_replace('[ul]', '<ul>', $text);
00099         $text = str_replace('[/ul]', '</ul>', $text);
00100 
00101         $text = str_replace('[ol]', '<ol>', $text);
00102         $text = str_replace('[/ol]', '</ol>', $text);
00103         
00104         $text = str_replace('[quote]', "<div class=\"inpage_quote\">\n" . 
00105                 "<span class=\"inpage_quotetext\">\n", $text);
00106         $text = str_replace('[/quote]', '</span></div>', $text);
00107         
00108         $pattern = "#\\[quote ?= ?\"?([$normalC]+)\"?\\]#";
00109         $replacement = "<div class=\"inpage_quote\">\n" . 
00110                 "<span class=\"inpage_quotefrom\">\\1:</span>\n<br />\n" . 
00111                 "<span class=\"inpage_quotetext\">\n";
00112         $text = preg_replace($pattern, $replacement, $text);
00113 
00114         // this matches [img='path']description[/img] - man 7 regex
00115         $pattern = "#\\[img ?= ?(['\"])([$hrefC]+)\\1\\]([$normalC]+)\\[/img\\]#";      
00116         $allowIMG
00117                 ?       $replacement = "<img src='\\2' alt='\\3' border='1' class='inpage_img'/>"
00118                 :       $replacement = "[$image_lang]";
00119         $text = preg_replace($pattern, $replacement, $text);
00120 
00121         $pattern = "#\[link\]([$hrefC]+)\[/link\]#";
00122         $NoTags
00123                 ?       $replacement = "\\1"
00124                 :       $replacement = "<a href='\\1' class='inpage_link'>\\1</a>";
00125         $text = preg_replace($pattern, $replacement, $text);
00126         
00127         $pattern = "#\[email\]([$hrefC@]+)\[/email\]#";
00128         $NoTags
00129                 ?       $replacement = "\\1"
00130                 :       $replacement = '<a href=\'mailto:\\1\' class=\'inpage_link\'>\\1</a>';
00131         $text = preg_replace($pattern, $replacement, $text);
00132         
00133         $pattern = "#\[link ?= ?(['\"])([$hrefC]+)\\1\]([$normalC]+)\[/link\]#";
00134         $NoTags
00135                 ?       $replacement = "\\3"
00136                 :       $replacement = '<a href=\'\\2\' class=\'inpage_link\'>\\3</a>';
00137         $text = preg_replace($pattern, $replacement, $text);
00138 }
00139 ?>

Generated on Wed Jun 9 03:38:16 2004 for modphpcms by doxygen1.2.18