diff options
author | tonnerkiller <Benny@debenny.de> | 2014-08-16 15:48:44 +0200 |
---|---|---|
committer | tonnerkiller <Benny@debenny.de> | 2014-08-16 15:48:44 +0200 |
commit | bac1ed221472fae1ff86bd4091a341b2870ab941 (patch) | |
tree | 4775e781a3b6395958ffddec8f05eec11a8b4670 /util/wp/post_to_red | |
parent | 03678716fe657cb9498073f7fc7f74b5883f7faf (diff) | |
download | volse-hubzilla-bac1ed221472fae1ff86bd4091a341b2870ab941.tar.gz volse-hubzilla-bac1ed221472fae1ff86bd4091a341b2870ab941.tar.bz2 volse-hubzilla-bac1ed221472fae1ff86bd4091a341b2870ab941.zip |
Added "if(!function_exists('xpost_to_html2bbcode'))"
This function name is also used by post to friendica plugin
Both functions seem to be identical. If you have both plugins installed
you get an error because of the identical function name
This will avoid the attempt to load the function a second time in case
it was already loaded by the post to friendica plugin
Diffstat (limited to 'util/wp/post_to_red')
-rw-r--r-- | util/wp/post_to_red/post_to_red.php | 132 |
1 files changed, 68 insertions, 64 deletions
diff --git a/util/wp/post_to_red/post_to_red.php b/util/wp/post_to_red/post_to_red.php index 5146b8be1..ea6026ae2 100644 --- a/util/wp/post_to_red/post_to_red.php +++ b/util/wp/post_to_red/post_to_red.php @@ -418,72 +418,76 @@ function post_to_red_get_avatar($avatar,$id_or_email,$size,$default,$alt) { // from: // http://www.docgate.com/tutorial/php/how-to-convert-html-to-bbcode-with-php-script.html -function xpost_to_html2bbcode($text) { - $htmltags = array( - '/\<b\>(.*?)\<\/b\>/is', - '/\<i\>(.*?)\<\/i\>/is', - '/\<u\>(.*?)\<\/u\>/is', - '/\<ul.*?\>(.*?)\<\/ul\>/is', - '/\<li\>(.*?)\<\/li\>/is', - '/\<img(.*?) src=\"(.*?)\" alt=\"(.*?)\" title=\"Smile(y?)\" \/\>/is', // some smiley - '/\<img(.*?) src=\"http:\/\/(.*?)\" (.*?)\>/is', - '/\<img(.*?) src=\"(.*?)\" alt=\":(.*?)\" .*? \/\>/is', // some smiley - '/\<div class=\"quotecontent\"\>(.*?)\<\/div\>/is', - '/\<div class=\"codecontent\"\>(.*?)\<\/div\>/is', - '/\<div class=\"quotetitle\"\>(.*?)\<\/div\>/is', - '/\<div class=\"codetitle\"\>(.*?)\<\/div\>/is', - '/\<cite.*?\>(.*?)\<\/cite\>/is', - '/\<blockquote.*?\>(.*?)\<\/blockquote\>/is', - '/\<div\>(.*?)\<\/div\>/is', - '/\<code\>(.*?)\<\/code\>/is', - '/\<br(.*?)\>/is', - '/\<strong\>(.*?)\<\/strong\>/is', - '/\<em\>(.*?)\<\/em\>/is', - '/\<a href=\"mailto:(.*?)\"(.*?)\>(.*?)\<\/a\>/is', - '/\<a .*?href=\"(.*?)\"(.*?)\>http:\/\/(.*?)\<\/a\>/is', - '/\<a .*?href=\"(.*?)\"(.*?)\>(.*?)\<\/a\>/is' - ); - - $bbtags = array( - '[b]$1[/b]', - '[i]$1[/i]', - '[u]$1[/u]', - '[list]$1[/list]', - '[*]$1', - '$3', - '[img]http://$2[/img]' . "\n", - ':$3', - '[quote]$1[/quote]', - '[code]$1[/code]', - '', - '', - '', - '[quote]$1[/quote]', - '$1', - '[code]$1[/code]', - "\n", - '[b]$1[/b]', - '[i]$1[/i]', - '[email=$1]$3[/email]', - '[url]$1[/url]', - '[url=$1]$3[/url]' - ); - - $text = str_replace ("\n", ' ', $text); - $ntext = preg_replace ($htmltags, $bbtags, $text); - $ntext = preg_replace ($htmltags, $bbtags, $ntext); - - // for too large text and cannot handle by str_replace - if (!$ntext) { - $ntext = str_replace(array('<br>', '<br />'), "\n", $text); - $ntext = str_replace(array('<strong>', '</strong>'), array('[b]', '[/b]'), $ntext); - $ntext = str_replace(array('<em>', '</em>'), array('[i]', '[/i]'), $ntext); - } - $ntext = strip_tags($ntext); +//function exists also in post to friendica plugin; load only if not yet loaded by that plugin +if(!function_exists('xpost_to_html2bbcode')) { + function xpost_to_html2bbcode($text) { + $htmltags = array( + '/\<b\>(.*?)\<\/b\>/is', + '/\<i\>(.*?)\<\/i\>/is', + '/\<u\>(.*?)\<\/u\>/is', + '/\<ul.*?\>(.*?)\<\/ul\>/is', + '/\<li\>(.*?)\<\/li\>/is', + '/\<img(.*?) src=\"(.*?)\" alt=\"(.*?)\" title=\"Smile(y?)\" \/\>/is', // some smiley + '/\<img(.*?) src=\"http:\/\/(.*?)\" (.*?)\>/is', + '/\<img(.*?) src=\"(.*?)\" alt=\":(.*?)\" .*? \/\>/is', // some smiley + '/\<div class=\"quotecontent\"\>(.*?)\<\/div\>/is', + '/\<div class=\"codecontent\"\>(.*?)\<\/div\>/is', + '/\<div class=\"quotetitle\"\>(.*?)\<\/div\>/is', + '/\<div class=\"codetitle\"\>(.*?)\<\/div\>/is', + '/\<cite.*?\>(.*?)\<\/cite\>/is', + '/\<blockquote.*?\>(.*?)\<\/blockquote\>/is', + '/\<div\>(.*?)\<\/div\>/is', + '/\<code\>(.*?)\<\/code\>/is', + '/\<br(.*?)\>/is', + '/\<strong\>(.*?)\<\/strong\>/is', + '/\<em\>(.*?)\<\/em\>/is', + '/\<a href=\"mailto:(.*?)\"(.*?)\>(.*?)\<\/a\>/is', + '/\<a .*?href=\"(.*?)\"(.*?)\>http:\/\/(.*?)\<\/a\>/is', + '/\<a .*?href=\"(.*?)\"(.*?)\>(.*?)\<\/a\>/is' + ); + + $bbtags = array( + '[b]$1[/b]', + '[i]$1[/i]', + '[u]$1[/u]', + '[list]$1[/list]', + '[*]$1', + '$3', + '[img]http://$2[/img]' . "\n", + ':$3', + '[quote]$1[/quote]', + '[code]$1[/code]', + '', + '', + '', + '[quote]$1[/quote]', + '$1', + '[code]$1[/code]', + "\n", + '[b]$1[/b]', + '[i]$1[/i]', + '[email=$1]$3[/email]', + '[url]$1[/url]', + '[url=$1]$3[/url]' + ); + + $text = str_replace ("\n", ' ', $text); + $ntext = preg_replace ($htmltags, $bbtags, $text); + $ntext = preg_replace ($htmltags, $bbtags, $ntext); - $ntext = trim(html_entity_decode($ntext,ENT_QUOTES,'UTF-8')); - return $ntext; + // for too large text and cannot handle by str_replace + if (!$ntext) { + $ntext = str_replace(array('<br>', '<br />'), "\n", $text); + $ntext = str_replace(array('<strong>', '</strong>'), array('[b]', '[/b]'), $ntext); + $ntext = str_replace(array('<em>', '</em>'), array('[i]', '[/i]'), $ntext); + } + + $ntext = strip_tags($ntext); + + $ntext = trim(html_entity_decode($ntext,ENT_QUOTES,'UTF-8')); + return $ntext; + } } |