diff --git a/include/api.php b/include/api.php index f1221ef0b6..b9187ca3aa 100644 --- a/include/api.php +++ b/include/api.php @@ -952,8 +952,6 @@ $start = $page*$count; - //$include_entities = (x($_REQUEST,'include_entities')?$_REQUEST['include_entities']:false); - $sql_extra = ''; if ($max_id > 0) $sql_extra .= ' AND `item`.`id` <= '.intval($max_id); @@ -1031,8 +1029,6 @@ $start = $page*$count; - //$include_entities = (x($_REQUEST,'include_entities')?$_REQUEST['include_entities']:false); - if ($max_id > 0) $sql_extra = 'AND `item`.`id` <= '.intval($max_id); if ($exclude_replies > 0) @@ -1100,7 +1096,6 @@ logger('API: api_statuses_show: '.$id); - //$include_entities = (x($_REQUEST,'include_entities')?$_REQUEST['include_entities']:false); $conversation = (x($_REQUEST,'conversation')?1:0); $sql_extra = ''; @@ -1169,8 +1164,6 @@ logger('API: api_conversation_show: '.$id); - //$include_entities = (x($_REQUEST,'include_entities')?$_REQUEST['include_entities']:false); - $sql_extra = ''; if ($max_id > 0) @@ -1225,8 +1218,6 @@ logger('API: api_statuses_repeat: '.$id); - //$include_entities = (x($_REQUEST,'include_entities')?$_REQUEST['include_entities']:false); - $r = q("SELECT `item`.*, `item`.`id` AS `item_id`, `item`.`network` AS `item_network`, `contact`.`nick` as `reply_author`, `contact`.`name`, `contact`.`photo` as `reply_photo`, `contact`.`url` as `reply_url`, `contact`.`rel`, `contact`.`network`, `contact`.`thumb`, `contact`.`dfrn-id`, `contact`.`self`, @@ -1328,8 +1319,6 @@ $start = $page*$count; - //$include_entities = (x($_REQUEST,'include_entities')?$_REQUEST['include_entities']:false); - // Ugly code - should be changed $myurl = $a->get_baseurl() . '/profile/'. $a->user['nickname']; $myurl = substr($myurl,strpos($myurl,'://')+3); @@ -1626,18 +1615,18 @@ function api_get_entitities($text, $bbcode) { /* To-Do: - * remove links to pictures if they are links of a picture - * Some video stuff isn't recognized * Links at the first character of the post * different sizes of pictures * caching picture data (using the id for that?) (See privacy_image_cache) */ - $include_entities = (x($_REQUEST,'include_entities')?$_REQUEST['include_entities']:true); + $include_entities = strtolower(x($_REQUEST,'include_entities')?$_REQUEST['include_entities']:"false"); -// To-Do -// if (!$include_entities OR ($include_entities == "false")) -// return false; + if ($include_entities != "true") + return array(); + + // Change pure links in text to bbcode uris + $bbcode = preg_replace("/([^\]\='".'"'."]|^)(https?\:\/\/[a-zA-Z0-9\:\/\-\?\&\;\.\=\_\~\#\%\$\!\+\,]+)/ism", '$1[url=$2]$2[/url]', $bbcode); $entities = array(); $entities["hashtags"] = array(); @@ -1645,14 +1634,24 @@ $entities["urls"] = array(); $entities["user_mentions"] = array(); - $bbcode = preg_replace("/\[bookmark\=([^\]]*)\](.*?)\[\/bookmark\]/ism",'[url=$1]$2[/url]',$bbcode); + $URLSearchString = "^\[\]"; + + $bbcode = preg_replace("/#\[url\=([$URLSearchString]*)\](.*?)\[\/url\]/ism",'#$2',$bbcode); + + $bbcode = preg_replace("/\[bookmark\=([$URLSearchString]*)\](.*?)\[\/bookmark\]/ism",'[url=$1]$2[/url]',$bbcode); //$bbcode = preg_replace("/\[url\](.*?)\[\/url\]/ism",'[url=$1]$1[/url]',$bbcode); $bbcode = preg_replace("/\[video\](.*?)\[\/video\]/ism",'[url=$1]$1[/url]',$bbcode); + + $bbcode = preg_replace("/\[youtube\]([A-Za-z0-9\-_=]+)(.*?)\[\/youtube\]/ism", + '[url=https://www.youtube.com/watch?v=$1]https://www.youtube.com/watch?v=$1[/url]', $bbcode); $bbcode = preg_replace("/\[youtube\](.*?)\[\/youtube\]/ism",'[url=$1]$1[/url]',$bbcode); + + $Text = preg_replace("/\[vimeo\]([0-9]+)(.*?)\[\/vimeo\]/ism", + '[url=https://vimeo.com/$1]https://vimeo.com/$1[/url]', $bbcode); $bbcode = preg_replace("/\[vimeo\](.*?)\[\/vimeo\]/ism",'[url=$1]$1[/url]',$bbcode); + $bbcode = preg_replace("/\[img\=([0-9]*)x([0-9]*)\](.*?)\[\/img\]/ism", '[img]$3[/img]', $bbcode); - $URLSearchString = "^\[\]"; //preg_match_all("/\[url\]([$URLSearchString]*)\[\/url\]/ism", $bbcode, $urls1); preg_match_all("/\[url\=([$URLSearchString]*)\](.*?)\[\/url\]/ism", $bbcode, $urls); @@ -1716,8 +1715,8 @@ $image = @imagecreatefromstring($img_str); if ($image) { $entities["media"][] = array( - "id" => $start, - "id_str" => (string)$start, + "id" => $start+1, + "id_str" => (string)$start+1, "indices" => array($start, $start+strlen($url)), "media_url" => $url, "media_url_https" => $url, @@ -1792,7 +1791,8 @@ // Workaround for ostatus messages where the title is identically to the body //$statusbody = trim(html2plain(bbcode(api_clean_plain_items($item['body']), false, false, 5, true), 0)); - $statusbody = trim(html2plain(bbcode(api_clean_plain_items($item['body']), false, false, 2, true), 0)); + $html = bbcode(api_clean_plain_items($item['body']), false, false, 2, true); + $statusbody = trim(html2plain($html, 0)); $statustitle = trim($item['title']); @@ -1836,7 +1836,12 @@ // Retweets are only valid for top postings - if (($item['owner-link'] != $item['author-link']) AND ($item["id"] == $item["parent"])) { + // It doesn't work reliable with the link if its a feed + $IsRetweet = ($item['owner-link'] != $item['author-link']); + if ($IsRetweet) + $IsRetweet = (($item['owner-name'] != $item['author-name']) OR ($item['owner-avatar'] != $item['author-avatar'])); + + if ($IsRetweet AND ($item["id"] == $item["parent"])) { $retweeted_status = $status; $retweeted_status["user"] = api_get_user($a,$item["author-link"]); @@ -2385,25 +2390,34 @@ function api_get_nick($profile) { } function api_clean_plain_items($Text) { + $include_entities = strtolower(x($_REQUEST,'include_entities')?$_REQUEST['include_entities']:"false"); + + if ($include_entities == "true") { + $URLSearchString = "^\[\]"; + + $Text = preg_replace("/#\[url\=([$URLSearchString]*)\](.*?)\[\/url\]/ism",'#$2',$Text); + $Text = preg_replace("/\[url\=([$URLSearchString]*)\](.*?)\[\/url\]/ism",'[url=$1]$1[/url]',$Text); + } + $Text = preg_replace_callback("((.*?)\[class=(.*?)\](.*?)\[\/class\])ism","api_cleanup_share",$Text); return($Text); } function api_cleanup_share($shared) { - if ($shared[2] != "type-link") - return($shared[3]); + if ($shared[2] != "type-link") + return($shared[0]); - if (!preg_match_all("/\[bookmark\=([^\]]*)\](.*?)\[\/bookmark\]/ism",$shared[3], $bookmark)) - return($shared[3]); + if (!preg_match_all("/\[bookmark\=([^\]]*)\](.*?)\[\/bookmark\]/ism",$shared[3], $bookmark)) + return($shared[0]); - $title = ""; - $link = ""; + $title = ""; + $link = ""; - if (isset($bookmark[2][0])) - $title = $bookmark[2][0]; + if (isset($bookmark[2][0])) + $title = $bookmark[2][0]; - if (isset($bookmark[1][0])) - $link = $bookmark[1][0]; + if (isset($bookmark[1][0])) + $link = $bookmark[1][0]; if (strpos($shared[1],$title) !== false) $title = ""; @@ -2411,16 +2425,16 @@ function api_cleanup_share($shared) { if (strpos($shared[1],$link) !== false) $link = ""; - $text = trim($shared[1]); + $text = trim($shared[1]); //if (strlen($text) < strlen($title)) if (($text == "") AND ($title != "")) $text .= "\n\n".trim($title); - if ($link != "") - $text .= "\n".trim($link); + if ($link != "") + $text .= "\n".trim($link); - return(trim($text)); + return(trim($text)); } function api_best_nickname(&$contacts) { diff --git a/include/bbcode.php b/include/bbcode.php index ee066f05a8..186caad7bc 100644 --- a/include/bbcode.php +++ b/include/bbcode.php @@ -322,7 +322,7 @@ function bb_ShareAttributes($match) { if ($avatar != "") $headline .= ''; - $headline .= sprintf(t('%s wrote the following post'.$reldate.':'), $profile, $author, $link); + $headline .= sprintf(t('%s wrote the following post'.$reldate.':'), $profile, $author, $link); $headline .= ""; @@ -369,7 +369,7 @@ function bb_ShareAttributesDiaspora($match) { $headline .= ''.html_entity_decode("♲ ", ENT_QUOTES, 'UTF-8').$userid.':'; //$headline .= sprintf(t(''. // html_entity_decode("♲ ", ENT_QUOTES, 'UTF-8'). - // '%s%s:'), $profile, $userid, $posted); + // '%s%s:'), $profile, $userid, $posted); $headline .= ""; $text = trim($match[1]); @@ -423,7 +423,7 @@ function bb_ShareAttributesForExport($match) { $headline = '
'; $headline .= sprintf(t(''. html_entity_decode("♲ ", ENT_QUOTES, 'UTF-8'). - '%s%s:'), $link, $userid, $posted); + '%s%s:'), $link, $userid, $posted); $headline .= "
"; $text = trim($match[1]); @@ -533,6 +533,23 @@ function GetProfileUsername($profile, $username) { return($username); } +function RemovePictureLinks($match) { + $ch = @curl_init($match[2]); + @curl_setopt($ch, CURLOPT_NOBODY, true); + @curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + @curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (compatible; Friendica)"); + @curl_exec($ch); + $curl_info = @curl_getinfo($ch); + + if (substr($curl_info["content_type"], 0, 6) == "image/") + $text = "[url=".$match[2]."]".$match[2]."[/url]"; + else + $text = "[url=".$match[1]."]".$match[1]."[/url]"; + + return($text); +} + + // BBcode 2 HTML was written by WAY2WEB.net // extended to work with Mistpark/Friendica - Mike Macgirvin @@ -632,19 +649,21 @@ function bbcode($Text,$preserve_nl = false, $tryoembed = true, $simplehtml = fal // if the HTML is used to generate plain text, then don't do this search, but replace all URL of that kind to text if (!$forplaintext) - $Text = preg_replace("/([^\]\='".'"'."]|^)(https?\:\/\/[a-zA-Z0-9\:\/\-\?\&\;\.\=\_\~\#\%\$\!\+\,]+)/ism", '$1$2', $Text); - else - $Text = preg_replace("(\[url\](.*?)\[\/url\])ism"," $1 ",$Text); + $Text = preg_replace("/([^\]\='".'"'."]|^)(https?\:\/\/[a-zA-Z0-9\:\/\-\?\&\;\.\=\_\~\#\%\$\!\+\,]+)/ism", '$1$2', $Text); + else { + $Text = preg_replace("(\[url\]([$URLSearchString]*)\[\/url\])ism"," $1 ",$Text); + $Text = preg_replace_callback("&\[url=([^\[\]]*)\]\[img\](.*)\[\/img\]\[\/url\]&Usi", 'RemovePictureLinks', $Text); + } if ($tryoembed) $Text = preg_replace_callback("/\[url\]([$URLSearchString]*)\[\/url\]/ism",'tryoembed',$Text); - $Text = preg_replace("/\[url\]([$URLSearchString]*)\[\/url\]/ism", '$1', $Text); - $Text = preg_replace("/\[url\=([$URLSearchString]*)\](.*?)\[\/url\]/ism", '$2', $Text); + $Text = preg_replace("/\[url\]([$URLSearchString]*)\[\/url\]/ism", '$1', $Text); + $Text = preg_replace("/\[url\=([$URLSearchString]*)\](.*?)\[\/url\]/ism", '$2', $Text); //$Text = preg_replace("/\[url\=([$URLSearchString]*)\]([$URLSearchString]*)\[\/url\]/ism", '$2', $Text); // Red compatibility, though the link can't be authenticated on Friendica - $Text = preg_replace("/\[zrl\=([$URLSearchString]*)\](.*?)\[\/zrl\]/ism", '$2', $Text); + $Text = preg_replace("/\[zrl\=([$URLSearchString]*)\](.*?)\[\/zrl\]/ism", '$2', $Text); // we may need to restrict this further if it picks up too many strays @@ -812,9 +831,9 @@ function bbcode($Text,$preserve_nl = false, $tryoembed = true, $simplehtml = fal $Text = preg_replace_callback("/\[audio\](.*?)\[\/audio\]/ism", 'tryoembed', $Text); } else { $Text = preg_replace("/\[video\](.*?)\[\/video\]/", - '$1', $Text); + '$1', $Text); $Text = preg_replace("/\[audio\](.*?)\[\/audio\]/", - '$1', $Text); + '$1', $Text); } // html5 video and audio @@ -840,7 +859,7 @@ function bbcode($Text,$preserve_nl = false, $tryoembed = true, $simplehtml = fal $Text = preg_replace("/\[youtube\]([A-Za-z0-9\-_=]+)(.*?)\[\/youtube\]/ism", '', $Text); else $Text = preg_replace("/\[youtube\]([A-Za-z0-9\-_=]+)(.*?)\[\/youtube\]/ism", - 'https://www.youtube.com/watch?v=$1', $Text); + 'https://www.youtube.com/watch?v=$1', $Text); if ($tryoembed) { $Text = preg_replace_callback("/\[vimeo\](https?:\/\/player.vimeo.com\/video\/[0-9]+).*?\[\/vimeo\]/ism",'tryoembed',$Text); @@ -854,7 +873,7 @@ function bbcode($Text,$preserve_nl = false, $tryoembed = true, $simplehtml = fal $Text = preg_replace("/\[vimeo\]([0-9]+)(.*?)\[\/vimeo\]/ism", '', $Text); else $Text = preg_replace("/\[vimeo\]([0-9]+)(.*?)\[\/vimeo\]/ism", - 'https://vimeo.com/$1', $Text); + 'https://vimeo.com/$1', $Text); // $Text = preg_replace("/\[youtube\](.*?)\[\/youtube\]/", '', $Text); diff --git a/include/conversation.php b/include/conversation.php index 5b9a11bde1..8e868afec7 100644 --- a/include/conversation.php +++ b/include/conversation.php @@ -558,13 +558,13 @@ function conversation(&$a, $items, $mode, $update, $preview = false) { $tag["url"] = $searchpath.strtolower($tag["term"]); if ($tag["type"] == TERM_HASHTAG) { - $hashtags[] = "#".$tag["term"].""; + $hashtags[] = "#".$tag["term"].""; $prefix = "#"; } elseif ($tag["type"] == TERM_MENTION) { - $mentions[] = "@".$tag["term"].""; + $mentions[] = "@".$tag["term"].""; $prefix = "@"; } - $tags[] = $prefix."".$tag["term"].""; + $tags[] = $prefix."".$tag["term"].""; } /*foreach(explode(',',$item['tag']) as $tag){ diff --git a/include/network.php b/include/network.php index a663a6d942..4bc50974b0 100644 --- a/include/network.php +++ b/include/network.php @@ -826,6 +826,10 @@ function add_fcontact($arr,$update = false) { function scale_external_images($srctext, $include_link = true, $scale_replace = false) { + // Suppress "view full size" + if (intval(get_config('system','no_view_full_size'))) + $include_link = false; + $a = get_app(); // Picture addresses can contain special characters diff --git a/include/text.php b/include/text.php index 4ce823ccd3..872bf74255 100644 --- a/include/text.php +++ b/include/text.php @@ -968,7 +968,7 @@ if(! function_exists('linkify')) { * @param string $s */ function linkify($s) { - $s = preg_replace("/(https?\:\/\/[a-zA-Z0-9\:\/\-\?\&\;\.\=\_\~\#\'\%\$\!\+]*)/", ' $1', $s); + $s = preg_replace("/(https?\:\/\/[a-zA-Z0-9\:\/\-\?\&\;\.\=\_\~\#\'\%\$\!\+]*)/", ' $1', $s); $s = preg_replace("/\<(.*?)(src|href)=(.*?)\&\;(.*?)\>/ism",'<$1$2=$3&$4>',$s); return($s); }} @@ -1301,13 +1301,13 @@ function prepare_body(&$item,$attach = false) { $tag["url"] = $searchpath.strtolower($tag["term"]); if ($tag["type"] == TERM_HASHTAG) { - $hashtags[] = "#".$tag["term"].""; + $hashtags[] = "#".$tag["term"].""; $prefix = "#"; } elseif ($tag["type"] == TERM_MENTION) { - $mentions[] = "@".$tag["term"].""; + $mentions[] = "@".$tag["term"].""; $prefix = "@"; } - $tags[] = $prefix."".$tag["term"].""; + $tags[] = $prefix."".$tag["term"].""; } } @@ -1418,7 +1418,7 @@ function prepare_body(&$item,$attach = false) { $title = ((strlen(trim($mtch[4]))) ? escape_tags(trim($mtch[4])) : escape_tags($mtch[1])); $title .= ' ' . $mtch[2] . ' ' . t('bytes'); - $as .= '' . $icon . ''; + $as .= '' . $icon . ''; } } } diff --git a/view/templates/event.tpl b/view/templates/event.tpl index 4788dcb380..961f0155b5 100644 --- a/view/templates/event.tpl +++ b/view/templates/event.tpl @@ -8,7 +8,7 @@ {{if $event.item.author_name}}{{$event.item.author_name}}{{/if}} {{$event.html}} - {{if $event.item.plink}}{{/if}} + {{if $event.item.plink}}{{/if}} {{if $event.edit}}{{/if}}
diff --git a/view/templates/events.tpl b/view/templates/events.tpl index 054200ca2d..f798a8e378 100644 --- a/view/templates/events.tpl +++ b/view/templates/events.tpl @@ -21,7 +21,7 @@ {{if $event.is_first}}
{{$event.d}}
{{/if}} {{if $event.item.author_name}}{{$event.item.author_name}}{{/if}} {{$event.html}} - {{if $event.item.plink}}{{/if}} + {{if $event.item.plink}}{{/if}} {{if $event.edit}}{{/if}}
diff --git a/view/templates/profile_vcard.tpl b/view/templates/profile_vcard.tpl index 3f4d3c711c..4734f55255 100644 --- a/view/templates/profile_vcard.tpl +++ b/view/templates/profile_vcard.tpl @@ -34,7 +34,7 @@ {{if $marital}}
{{$marital}}
{{$profile.marital}}
{{/if}} - {{if $homepage}}
{{$homepage}}
{{$profile.homepage}}
{{/if}} + {{if $homepage}}
{{$homepage}}
{{$profile.homepage}}
{{/if}} {{include file="diaspora_vcard.tpl"}} diff --git a/view/templates/wall_thread.tpl b/view/templates/wall_thread.tpl index c0e30c4cbf..6dc9e5c3a5 100644 --- a/view/templates/wall_thread.tpl +++ b/view/templates/wall_thread.tpl @@ -75,7 +75,7 @@ {{/if}} {{if $item.plink}} - + {{/if}} {{if $item.edpost}} diff --git a/view/theme/vier/templates/profile_vcard.tpl b/view/theme/vier/templates/profile_vcard.tpl index 9e0da287cf..0a54642528 100644 --- a/view/theme/vier/templates/profile_vcard.tpl +++ b/view/theme/vier/templates/profile_vcard.tpl @@ -52,7 +52,7 @@ {{if $marital}}
{{$marital}}
{{$profile.marital}}
{{/if}} - {{if $homepage}}
{{$homepage}}
{{$profile.homepage}}
{{/if}} + {{if $homepage}}
{{$homepage}}
{{$profile.homepage}}
{{/if}} {{include file="diaspora_vcard.tpl"}}