Merge pull request #2932 from Hypolite/issue/missing-private-image-src
Fix Friendica private image URL replacing
This commit is contained in:
commit
af42e5e481
5 changed files with 109 additions and 87 deletions
|
@ -1,4 +1,6 @@
|
|||
<?php
|
||||
use \Friendica\Core\Config;
|
||||
|
||||
require_once("include/oembed.php");
|
||||
require_once('include/event.php');
|
||||
require_once('include/map.php');
|
||||
|
@ -1161,11 +1163,24 @@ function bbcode($Text,$preserve_nl = false, $tryoembed = true, $simplehtml = fal
|
|||
$Text = preg_replace('/\"\;/','"',$Text);
|
||||
|
||||
// fix any escaped ampersands that may have been converted into links
|
||||
$Text = preg_replace("/\<([^>]*?)(src|href)=(.*?)\&\;(.*?)\>/ism",'<$1$2=$3&$4>',$Text);
|
||||
$Text = preg_replace("/\<([^>]*?)(src|href)=\"(?!http|ftp|mailto|gopher|cid)(.*?)\>/ism",'<$1$2="">',$Text);
|
||||
$Text = preg_replace('/\<([^>]*?)(src|href)=(.*?)\&\;(.*?)\>/ism', '<$1$2=$3&$4>', $Text);
|
||||
|
||||
if($saved_image)
|
||||
// sanitizes src attributes (only relative redir URIs or http URLs)
|
||||
$Text = preg_replace('#<([^>]*?)(src)="(?!http|redir)(.*?)"(.*?)>#ism', '<$1$2=""$4 class="invalid-src" title="' . t('Invalid source protocol') . '">', $Text);
|
||||
|
||||
// sanitize href attributes (only whitelisted protocols URLs)
|
||||
// default value for backward compatibility
|
||||
$allowed_link_protocols = Config::get('system', 'allowed_link_protocols', array('ftp', 'mailto', 'gopher', 'cid'));
|
||||
|
||||
// Always allowed protocol even if config isn't set or not including it
|
||||
$allowed_link_protocols[] = 'http';
|
||||
|
||||
$regex = '#<([^>]*?)(href)="(?!' . implode('|', $allowed_link_protocols) . ')(.*?)"(.*?)>#ism';
|
||||
$Text = preg_replace($regex, '<$1$2="javascript:void(0)"$4 class="invalid-href" title="' . t('Invalid link protocol') . '">', $Text);
|
||||
|
||||
if($saved_image) {
|
||||
$Text = bb_replace_images($Text, $saved_image);
|
||||
}
|
||||
|
||||
// Clean up the HTML by loading and saving the HTML with the DOM.
|
||||
// Bad structured html can break a whole page.
|
||||
|
|
|
@ -771,7 +771,7 @@ function activity_match($haystack,$needle) {
|
|||
|
||||
/**
|
||||
* @brief Pull out all #hashtags and @person tags from $string.
|
||||
*
|
||||
*
|
||||
* We also get @person@domain.com - which would make
|
||||
* the regex quite complicated as tags can also
|
||||
* end a sentence. So we'll run through our results
|
||||
|
@ -1170,33 +1170,29 @@ function link_compare($a,$b) {
|
|||
return false;
|
||||
}}
|
||||
|
||||
|
||||
if(! function_exists('redir_private_images')) {
|
||||
/**
|
||||
* Find any non-embedded images in private items and add redir links to them
|
||||
* @brief Find any non-embedded images in private items and add redir links to them
|
||||
*
|
||||
* @param App $a
|
||||
* @param array $item
|
||||
* @param array &$item The field array of an item row
|
||||
*/
|
||||
function redir_private_images($a, &$item) {
|
||||
|
||||
function redir_private_images($a, &$item)
|
||||
{
|
||||
$matches = false;
|
||||
$cnt = preg_match_all('|\[img\](http[^\[]*?/photo/[a-fA-F0-9]+?(-[0-9]\.[\w]+?)?)\[\/img\]|', $item['body'], $matches, PREG_SET_ORDER);
|
||||
if($cnt) {
|
||||
//logger("redir_private_images: matches = " . print_r($matches, true));
|
||||
foreach($matches as $mtch) {
|
||||
if(strpos($mtch[1], '/redir') !== false)
|
||||
if ($cnt) {
|
||||
foreach ($matches as $mtch) {
|
||||
if (strpos($mtch[1], '/redir') !== false) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if((local_user() == $item['uid']) && ($item['private'] != 0) && ($item['contact-id'] != $a->contact['id']) && ($item['network'] == NETWORK_DFRN)) {
|
||||
//logger("redir_private_images: redir");
|
||||
$img_url = 'redir?f=1&quiet=1&url=' . $mtch[1] . '&conurl=' . $item['author-link'];
|
||||
$item['body'] = str_replace($mtch[0], "[img]".$img_url."[/img]", $item['body']);
|
||||
if ((local_user() == $item['uid']) && ($item['private'] != 0) && ($item['contact-id'] != $a->contact['id']) && ($item['network'] == NETWORK_DFRN)) {
|
||||
$img_url = 'redir?f=1&quiet=1&url=' . urlencode($mtch[1]) . '&conurl=' . urlencode($item['author-link']);
|
||||
$item['body'] = str_replace($mtch[0], '[img]' . $img_url . '[/img]', $item['body']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}}
|
||||
}
|
||||
|
||||
function put_item_in_cache(&$item, $update = false) {
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue