]> git.mxchange.org Git - friendica.git/blob - include/html2bbcode.php
Support bbcode size tag - I may regret this...
[friendica.git] / include / html2bbcode.php
1 <?php
2
3 /**
4  * html2bbcode
5  */
6
7
8 function html2bbcode($s) {
9
10         // Tags to Find
11
12         $htmltags = array(
13                 '/\n/is',
14                 '/\<pre\>(.*?)\<\/pre\>/is',
15                 '/\<p(.*?)\>/is',
16                 '/\<\/p\>/is',
17                 '/\<b\>(.*?)\<\/b\>/is',
18                 '/\<i\>(.*?)\<\/i\>/is',
19                 '/\<u\>(.*?)\<\/u\>/is',
20                 '/\<ul\>(.*?)\<\/ul\>/is',
21                 '/\<li\>(.*?)\<\/li\>/is',
22                 '/\<img(.*?) src=\"(.*?)\" (.*?)\>/is',
23                 '/\<div(.*?)\>(.*?)\<\/div\>/is',
24                 '/\<br(.*?)\>/is',
25                 '/\<strong\>(.*?)\<\/strong\>/is',
26                 '/\<a (.*?)href=\"(.*?)\"(.*?)\>(.*?)\<\/a\>/is',
27                 '/\<code\>(.*?)\<\/code\>/is',
28                 '/\<span style=\"color:(.*?)\"\>(.*?)\<\/span\>/is',
29                 '/\<span style=\"font-size:(.*?)\"\>(.*?)\<\/span\>/is',
30                 '/\<blockquote\>(.*?)\<\/blockquote\>/is',
31                 '/\<video(.*?) src=\"(.*?)\" (.*?)\>(.*?)\<\/video\>/is',
32                 '/\<audio(.*?) src=\"(.*?)\" (.*?)\>(.*?)\<\/audio\>/is',
33
34         );
35
36         // Replace with
37
38         $bbtags = array(
39                 '',
40                 '[code]$1[/code]',
41                 '',
42                 "\n",
43                 '[b]$1[/b]',
44                 '[i]$1[/i]',
45                 '[u]$1[/u]',
46                 '[list]$1[/list]',
47                 '[*]$1',
48                 '[img]$2[/img]',
49                 '$2',
50                 "\n",
51                 '[b]$1[/b]',
52                 '[url=$2]$4[/url]',
53                 '[code]$1[/code]',
54                 '[color="$1"]$2[/color]',
55                 '[size=$1]$2[/size]',
56                 '[quote]$1[/quote]',
57                 '[video]$1[/video]',
58                 '[audio]$1[/audio]',
59         );
60
61         // Replace $htmltags in $text with $bbtags
62         $text = preg_replace ($htmltags, $bbtags, $s);
63
64         call_hooks('html2bbcode', $text);
65
66         // Strip all other HTML tags
67         $text = strip_tags($text);
68         return $text;
69 }
70