From 503c368f9ec08a70e4dbacd7b729568da6e4ea92 Mon Sep 17 00:00:00 2001 From: Klaus Weidenbach Date: Sat, 25 Feb 2017 19:12:41 +0100 Subject: :arrow_up: :hammer: Upgrade PHP Markdown library. The current version throws deprecated warning with PHP7.1 and PHPUnit. Upgrade the Markdown library to the current PHP Markdown Lib 1.7.0. Used composer to manage this library. --- include/markdown.php | 41 +++++++++++++++++++++-------------------- 1 file changed, 21 insertions(+), 20 deletions(-) (limited to 'include/markdown.php') diff --git a/include/markdown.php b/include/markdown.php index 7afdc6c54..43d973808 100644 --- a/include/markdown.php +++ b/include/markdown.php @@ -4,9 +4,10 @@ * @brief Some functions for BB conversions for Diaspora protocol. */ +use Michelf\MarkdownExtra; + require_once("include/oembed.php"); require_once("include/event.php"); -require_once("library/markdown.php"); require_once("include/html2bbcode.php"); require_once("include/bbcode.php"); require_once("library/markdownify/markdownify.php"); @@ -73,7 +74,7 @@ function bb_tag_preg_replace($pattern, $replace, $name, $s) { function share_shield($m) { return str_replace($m[1],'!=+=+=!' . base64url_encode($m[1]) . '=+!=+!=',$m[0]); -} +} function share_unshield($m) { $x = str_replace(array('!=+=+=!','=+!=+!='),array('',''),$m[1]); @@ -184,7 +185,7 @@ function markdown_to_bb($s, $use_zrl = false) { // This seems to work $s = preg_replace('/\#([^\s\#])/','#$1',$s); - $s = Markdown($s); + $s = MarkdownExtra::defaultTransform($s); $s = str_replace("\r","",$s); @@ -299,7 +300,7 @@ function bb2dmention_callback($match) { $r = q("select xchan_addr from xchan where xchan_url = '%s'", dbesc($match[2]) - ); + ); if($r) return '@{' . $match[3] . ' ; ' . $r[0]['xchan_addr'] . '}'; @@ -333,7 +334,7 @@ function bb2diaspora_itemwallwall(&$item,$uplink = false) { $has_meta = true; if($item['author_xchan'] != $item['owner_xchan']) { - if($item['mid'] == $item['parent_mid']) + if($item['mid'] == $item['parent_mid']) $wallwall = true; else { if(! $has_meta) { @@ -348,12 +349,12 @@ function bb2diaspora_itemwallwall(&$item,$uplink = false) { if(($wallwall) && (is_array($item['author'])) && $item['author']['xchan_url'] && $item['author']['xchan_name'] && $item['author']['xchan_photo_s']) { logger('bb2diaspora_itemwallwall: wall to wall post',LOGGER_DEBUG); // post will come across with the owner's identity. Throw a preamble onto the post to indicate the true author. - $item['body'] = "\n\n" - . '[quote]' - . '[img]' . $item['author']['xchan_photo_s'] . '[/img]' - . ' ' - . '[url=' . $item['author']['xchan_url'] . '][b]' . $item['author']['xchan_name'] . '[/b][/url]' . "\n\n" - . $item['body'] + $item['body'] = "\n\n" + . '[quote]' + . '[img]' . $item['author']['xchan_photo_s'] . '[/img]' + . ' ' + . '[url=' . $item['author']['xchan_url'] . '][b]' . $item['author']['xchan_name'] . '[/b][/url]' . "\n\n" + . $item['body'] . '[/quote]'; } @@ -490,7 +491,7 @@ function bb2diaspora($Text,$preserve_nl = false, $fordiaspora = true) { // Convert it to HTML - don't try oembed $Text = bbcode($Text, $preserve_nl, false); - // Markdownify does not preserve previously escaped html entities such as <> and &. + // Markdownify does not preserve previously escaped html entities such as <> and &. $Text = str_replace(array('<','>','&'),array('&_lt_;','&_gt_;','&_amp_;'),$Text); @@ -500,7 +501,7 @@ function bb2diaspora($Text,$preserve_nl = false, $fordiaspora = true) { - // It also adds backslashes to our attempt at getting around the html entity preservation for some weird reason. + // It also adds backslashes to our attempt at getting around the html entity preservation for some weird reason. $Text = str_replace(array('&\\_lt\\_;','&\\_gt\\_;','&\\_amp\\_;'),array('<','>','&'),$Text); @@ -510,7 +511,7 @@ function bb2diaspora($Text,$preserve_nl = false, $fordiaspora = true) { // So take off the angle brackets of any such URL $Text = preg_replace("//is", "http$1", $Text); - // Remove empty zrl links + // Remove empty zrl links $Text = preg_replace("/\[zrl\=\].*?\[\/zrl\]/is", "", $Text); // Remove all unconverted tags @@ -543,22 +544,22 @@ function format_event_diaspora($ev) { $o .= '**' . (($ev['summary']) ? bb2diaspora($ev['summary']) : bb2diaspora($ev['desc'])) . '**' . "\n"; $o .= t('Starts:') . ' ' . '[' - . (($ev['adjust']) ? day_translate(datetime_convert('UTC', 'UTC', + . (($ev['adjust']) ? day_translate(datetime_convert('UTC', 'UTC', $ev['start'] , $bd_format )) - : day_translate(datetime_convert('UTC', 'UTC', + : day_translate(datetime_convert('UTC', 'UTC', $ev['start'] , $bd_format))) . '](' . z_root() . '/localtime/?f=&time=' . urlencode(datetime_convert('UTC','UTC',$ev['start'])) . ")\n"; if(! $ev['nofinish']) - $o .= t('Finishes:') . ' ' . '[' - . (($ev['adjust']) ? day_translate(datetime_convert('UTC', 'UTC', + $o .= t('Finishes:') . ' ' . '[' + . (($ev['adjust']) ? day_translate(datetime_convert('UTC', 'UTC', $ev['finish'] , $bd_format )) - : day_translate(datetime_convert('UTC', 'UTC', + : day_translate(datetime_convert('UTC', 'UTC', $ev['finish'] , $bd_format ))) . '](' . z_root() . '/localtime/?f=&time=' . urlencode(datetime_convert('UTC','UTC',$ev['finish'])) . ")\n"; if(strlen($ev['location'])) - $o .= t('Location:') . bb2diaspora($ev['location']) + $o .= t('Location:') . bb2diaspora($ev['location']) . "\n"; $o .= "\n"; -- cgit v1.2.3 From 6c79e0c077971029343b2dff30017571ea118438 Mon Sep 17 00:00:00 2001 From: Klaus Weidenbach Date: Thu, 2 Mar 2017 23:25:04 +0100 Subject: :arrow_up: :hammer: Upgrade Markdownify library. The current version 2.0.0 (alpha) throws deprecated warning with PHP7.1 and PHPUnit. Upgrade the HTML to Markdown converter for PHP to the current Markdownify 2.2.1. Used composer to manage this library. --- include/markdown.php | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'include/markdown.php') diff --git a/include/markdown.php b/include/markdown.php index 43d973808..7e1f1c42c 100644 --- a/include/markdown.php +++ b/include/markdown.php @@ -5,12 +5,12 @@ */ use Michelf\MarkdownExtra; +use Markdownify\Converter; require_once("include/oembed.php"); require_once("include/event.php"); require_once("include/html2bbcode.php"); require_once("include/bbcode.php"); -require_once("library/markdownify/markdownify.php"); function get_bb_tag_pos($s, $name, $occurance = 1) { @@ -367,7 +367,6 @@ function bb2diaspora_itemwallwall(&$item,$uplink = false) { function bb2diaspora_itembody($item, $force_update = false, $have_channel = false, $uplink = false) { - if(! get_iconfig($item,'diaspora','fields')) { $force_update = true; } @@ -454,7 +453,7 @@ function bb2diaspora_itembody($item, $force_update = false, $have_channel = fals return html_entity_decode($body); } -function bb2diaspora($Text,$preserve_nl = false, $fordiaspora = true) { +function bb2diaspora($Text, $preserve_nl = false, $fordiaspora = true) { // Re-enabling the converter again. // The bbcode parser now handles youtube-links (and the other stuff) correctly. @@ -496,11 +495,10 @@ function bb2diaspora($Text,$preserve_nl = false, $fordiaspora = true) { $Text = str_replace(array('<','>','&'),array('&_lt_;','&_gt_;','&_amp_;'),$Text); // Now convert HTML to Markdown - $md = new Markdownify(false, false, false); + $md = new Converter(Converter::LINK_AFTER_CONTENT, false, false); $Text = $md->parseString($Text); - // It also adds backslashes to our attempt at getting around the html entity preservation for some weird reason. $Text = str_replace(array('&\\_lt\\_;','&\\_gt\\_;','&\\_amp\\_;'),array('<','>','&'),$Text); @@ -522,7 +520,7 @@ function bb2diaspora($Text,$preserve_nl = false, $fordiaspora = true) { $Text = trim($Text); - call_hooks('bb2diaspora',$Text); + call_hooks('bb2diaspora', $Text); return $Text; } -- cgit v1.2.3 From 660ea89521646251fc3a547cee7c38341dcb5d8f Mon Sep 17 00:00:00 2001 From: zotlabs Date: Mon, 8 May 2017 19:10:08 -0700 Subject: handle mastodon urls in markdown/bbcode conversion --- include/markdown.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'include/markdown.php') diff --git a/include/markdown.php b/include/markdown.php index 7e1f1c42c..a9617f72b 100644 --- a/include/markdown.php +++ b/include/markdown.php @@ -199,10 +199,10 @@ function markdown_to_bb($s, $use_zrl = false) { // Convert everything that looks like a link to a link if($use_zrl) { $s = str_replace(array('[img','/img]'),array('[zmg','/zmg]'),$s); - $s = preg_replace("/([^\]\=]|^)(https?\:\/\/)([a-zA-Z0-9\:\/\-\?\&\;\.\=\_\~\#\%\$\!\+\,\(\)]+)/ism", '$1[zrl=$2$3]$2$3[/zrl]',$s); + $s = preg_replace("/([^\]\=]|^)(https?\:\/\/)([a-zA-Z0-9\:\/\-\?\&\;\.\=\_\~\#\%\$\!\+\,\@\(\)]+)/ism", '$1[zrl=$2$3]$2$3[/zrl]',$s); } else { - $s = preg_replace("/([^\]\=]|^)(https?\:\/\/)([a-zA-Z0-9\:\/\-\?\&\;\.\=\_\~\#\%\$\!\+\,\(\)]+)/ism", '$1[url=$2$3]$2$3[/url]',$s); + $s = preg_replace("/([^\]\=]|^)(https?\:\/\/)([a-zA-Z0-9\:\/\-\?\&\;\.\=\_\~\#\%\$\!\+\,\@\(\)]+)/ism", '$1[url=$2$3]$2$3[/url]',$s); } // remove duplicate adjacent code tags -- cgit v1.2.3