aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorfriendica <info@friendica.com>2012-07-07 21:55:15 -0700
committerfriendica <info@friendica.com>2012-07-07 21:55:15 -0700
commit63f10f6c6bb1ce794643b7511ab50cd810b79595 (patch)
tree3e773f767eff7c37e80e83cbfc8de02d330a58b7
parente94f7ed23d18e811e31cb4656a55b97f328534b7 (diff)
parenta3640b4e9f8c457c8761ccedf7757ce6dfe733c2 (diff)
downloadvolse-hubzilla-63f10f6c6bb1ce794643b7511ab50cd810b79595.tar.gz
volse-hubzilla-63f10f6c6bb1ce794643b7511ab50cd810b79595.tar.bz2
volse-hubzilla-63f10f6c6bb1ce794643b7511ab50cd810b79595.zip
Merge https://github.com/friendica/friendica into pull
-rw-r--r--include/bb2diaspora.php2
-rw-r--r--include/bbcode.php88
-rw-r--r--include/conversation.php102
-rwxr-xr-xinclude/items.php164
-rw-r--r--[-rwxr-xr-x]include/security.php0
-rw-r--r--mod/message.php101
-rw-r--r--mod/photos.php3
-rwxr-xr-x[-rw-r--r--]util/run_xgettext.sh0
-rw-r--r--[-rwxr-xr-x]view/theme/diabook/ch_directory_item.tpl0
-rw-r--r--[-rwxr-xr-x]view/theme/diabook/communityhome.tpl0
-rw-r--r--[-rwxr-xr-x]view/theme/diabook/contact_template.tpl0
-rw-r--r--[-rwxr-xr-x]view/theme/diabook/diabook-aerith/icons/block.pngbin335 -> 335 bytes
-rw-r--r--[-rwxr-xr-x]view/theme/diabook/diabook-blue/icons/block.pngbin335 -> 335 bytes
-rw-r--r--[-rwxr-xr-x]view/theme/diabook/diabook-dark/icons/block.pngbin335 -> 335 bytes
-rw-r--r--[-rwxr-xr-x]view/theme/diabook/diabook-green/icons/block.pngbin335 -> 335 bytes
-rw-r--r--[-rwxr-xr-x]view/theme/diabook/diabook-green/icons/notifications3.pngbin714 -> 714 bytes
-rw-r--r--[-rwxr-xr-x]view/theme/diabook/diabook-green/icons/notify3.pngbin534 -> 534 bytes
-rw-r--r--[-rwxr-xr-x]view/theme/diabook/diabook-pink/icons/block.pngbin335 -> 335 bytes
-rw-r--r--[-rwxr-xr-x]view/theme/diabook/diabook-pink/icons/notifications3.pngbin714 -> 714 bytes
-rw-r--r--[-rwxr-xr-x]view/theme/diabook/diabook-pink/icons/notify3.pngbin534 -> 534 bytes
-rw-r--r--[-rwxr-xr-x]view/theme/diabook/diabook-red/icons/block.pngbin335 -> 335 bytes
-rw-r--r--[-rwxr-xr-x]view/theme/diabook/directory_item.tpl0
-rw-r--r--[-rwxr-xr-x]view/theme/diabook/group_side.tpl0
-rw-r--r--[-rwxr-xr-x]view/theme/diabook/icons/attach.pngbin1069 -> 1069 bytes
-rw-r--r--[-rwxr-xr-x]view/theme/diabook/icons/audio.pngbin762 -> 762 bytes
-rw-r--r--[-rwxr-xr-x]view/theme/diabook/icons/block.pngbin335 -> 335 bytes
-rw-r--r--[-rwxr-xr-x]view/theme/diabook/icons/camera.pngbin685 -> 685 bytes
-rw-r--r--[-rwxr-xr-x]view/theme/diabook/icons/close_box.pngbin206 -> 206 bytes
-rw-r--r--[-rwxr-xr-x]view/theme/diabook/icons/contacts2.pngbin549 -> 549 bytes
-rw-r--r--[-rwxr-xr-x]view/theme/diabook/icons/drop.pngbin292 -> 292 bytes
-rw-r--r--[-rwxr-xr-x]view/theme/diabook/icons/expand.pngbin263 -> 263 bytes
-rw-r--r--[-rwxr-xr-x]view/theme/diabook/icons/file_as.pngbin352 -> 352 bytes
-rw-r--r--[-rwxr-xr-x]view/theme/diabook/icons/link.pngbin365 -> 365 bytes
-rw-r--r--[-rwxr-xr-x]view/theme/diabook/icons/lock.pngbin366 -> 366 bytes
-rw-r--r--[-rwxr-xr-x]view/theme/diabook/icons/lupe.pngbin697 -> 697 bytes
-rw-r--r--[-rwxr-xr-x]view/theme/diabook/icons/next.pngbin300 -> 300 bytes
-rw-r--r--[-rwxr-xr-x]view/theme/diabook/icons/notifications.pngbin926 -> 926 bytes
-rw-r--r--[-rwxr-xr-x]view/theme/diabook/icons/notifications3.pngbin714 -> 714 bytes
-rw-r--r--[-rwxr-xr-x]view/theme/diabook/icons/notify.pngbin1001 -> 1001 bytes
-rw-r--r--[-rwxr-xr-x]view/theme/diabook/icons/notify3.pngbin534 -> 534 bytes
-rw-r--r--[-rwxr-xr-x]view/theme/diabook/icons/pencil.pngbin286 -> 286 bytes
-rw-r--r--[-rwxr-xr-x]view/theme/diabook/icons/prev.pngbin336 -> 336 bytes
-rw-r--r--[-rwxr-xr-x]view/theme/diabook/icons/recycle.pngbin296 -> 296 bytes
-rw-r--r--[-rwxr-xr-x]view/theme/diabook/icons/remote.pngbin427 -> 427 bytes
-rw-r--r--[-rwxr-xr-x]view/theme/diabook/icons/scroll_top.pngbin296 -> 296 bytes
-rw-r--r--[-rwxr-xr-x]view/theme/diabook/icons/star.pngbin388 -> 388 bytes
-rw-r--r--[-rwxr-xr-x]view/theme/diabook/icons/starred.pngbin501 -> 501 bytes
-rw-r--r--[-rwxr-xr-x]view/theme/diabook/icons/tagged.pngbin353 -> 353 bytes
-rw-r--r--[-rwxr-xr-x]view/theme/diabook/icons/unlock.pngbin362 -> 362 bytes
-rw-r--r--[-rwxr-xr-x]view/theme/diabook/icons/unstarred.pngbin468 -> 468 bytes
-rw-r--r--[-rwxr-xr-x]view/theme/diabook/icons/video.pngbin472 -> 472 bytes
-rw-r--r--[-rwxr-xr-x]view/theme/diabook/icons/weblink.pngbin505 -> 505 bytes
-rw-r--r--[-rwxr-xr-x]view/theme/diabook/jot.tpl0
-rw-r--r--[-rwxr-xr-x]view/theme/diabook/mail_conv.tpl0
-rw-r--r--[-rwxr-xr-x]view/theme/diabook/search_item.tpl0
-rw-r--r--[-rwxr-xr-x]view/theme/diabook/theme.php0
56 files changed, 383 insertions, 77 deletions
diff --git a/include/bb2diaspora.php b/include/bb2diaspora.php
index 042177fd9..d0cb60302 100644
--- a/include/bb2diaspora.php
+++ b/include/bb2diaspora.php
@@ -346,7 +346,7 @@ function bb2diaspora($Text,$preserve_nl = false) {
// If we found an event earlier, strip out all the event code and replace with a reformatted version.
- if(x($ev,'desc') && x($ev,'start')) {
+ if(x($ev,'start')) {
$sub = format_event_diaspora($ev);
diff --git a/include/bbcode.php b/include/bbcode.php
index 55a879497..63dd9695e 100644
--- a/include/bbcode.php
+++ b/include/bbcode.php
@@ -47,6 +47,67 @@ function bb_unspacefy_and_trim($st) {
return $unspacefied;
}
+if(! function_exists('bb_extract_images')) {
+function bb_extract_images($body) {
+
+ $saved_image = array();
+ $orig_body = $body;
+ $new_body = '';
+
+ $cnt = 0;
+ $img_start = strpos($orig_body, '[img');
+ $img_st_close = ($img_start !== false ? strpos(substr($orig_body, $img_start), ']') : false);
+ $img_end = ($img_start !== false ? strpos(substr($orig_body, $img_start), '[/img]') : false);
+ while(($img_st_close !== false) && ($img_end !== false)) {
+
+ $img_st_close++; // make it point to AFTER the closing bracket
+ $img_end += $img_start;
+
+ if(! strcmp(substr($orig_body, $img_start + $img_st_close, 5), 'data:')) {
+ // This is an embedded image
+
+ $saved_image[$cnt] = substr($orig_body, $img_start + $img_st_close, $img_end - ($img_start + $img_st_close));
+ $new_body = $new_body . substr($orig_body, 0, $img_start) . '[$#saved_image' . $cnt . '#$]';
+
+ $cnt++;
+ }
+ else
+ $new_body = $new_body . substr($orig_body, 0, $img_end + strlen('[/img]'));
+
+ $orig_body = substr($orig_body, $img_end + strlen('[/img]'));
+
+ if($orig_body === false) // in case the body ends on a closing image tag
+ $orig_body = '';
+
+ $img_start = strpos($orig_body, '[img');
+ $img_st_close = ($img_start !== false ? strpos(substr($orig_body, $img_start), ']') : false);
+ $img_end = ($img_start !== false ? strpos(substr($orig_body, $img_start), '[/img]') : false);
+ }
+
+ $new_body = $new_body . $orig_body;
+
+ return array('body' => $new_body, 'images' => $saved_image);
+}}
+
+if(! function_exists('bb_replace_images')) {
+function bb_replace_images($body, $images) {
+
+ $newbody = $body;
+
+ $cnt = 0;
+ foreach($images as $image) {
+ // We're depending on the property of 'foreach' (specified on the PHP website) that
+ // it loops over the array starting from the first element and going sequentially
+ // to the last element
+ $newbody = str_replace('[$#saved_image' . $cnt . '#$]', '<img src="' . $image .'" alt="' . t('Image/photo') . '" />', $newbody);
+ $cnt++;
+ }
+
+ return $newbody;
+}}
+
+
+
// BBcode 2 HTML was written by WAY2WEB.net
// extended to work with Mistpark/Friendica - Mike Macgirvin
@@ -54,29 +115,21 @@ function bbcode($Text,$preserve_nl = false, $tryoembed = true) {
$a = get_app();
- // Hide all [noparse] contained bbtags spacefying them
+ // Hide all [noparse] contained bbtags by spacefying them
+ // POSSIBLE BUG --> Will the 'preg' functions crash if there's an embedded image?
$Text = preg_replace_callback("/\[noparse\](.*?)\[\/noparse\]/ism", 'bb_spacefy',$Text);
$Text = preg_replace_callback("/\[nobb\](.*?)\[\/nobb\]/ism", 'bb_spacefy',$Text);
$Text = preg_replace_callback("/\[pre\](.*?)\[\/pre\]/ism", 'bb_spacefy',$Text);
- // Extract a single private image which uses data url's since preg has issues with
- // large data sizes. Stash it away while we do bbcode conversion, and then put it back
+ // Extract the private images which use data url's since preg has issues with
+ // large data sizes. Stash them away while we do bbcode conversion, and then put them back
// in after we've done all the regex matching. We cannot use any preg functions to do this.
- $saved_image = '';
- $img_start = strpos($Text,'[img]data:');
- $img_end = strpos($Text,'[/img]');
-
- if($img_start !== false && $img_end !== false && $img_end > $img_start) {
- $start_fragment = substr($Text,0,$img_start);
- $img_start += strlen('[img]');
- $saved_image = substr($Text,$img_start,$img_end - $img_start);
- $end_fragment = substr($Text,$img_end + strlen('[/img]'));
-// logger('saved_image: ' . $saved_image,LOGGER_DEBUG);
- $Text = $start_fragment . '[$#saved_image#$]' . $end_fragment;
- }
+ $extracted = bb_extract_images($Text);
+ $Text = $extracted['body'];
+ $saved_image = $extracted['images'];
// If we find any event code, turn it into an event.
// After we're finished processing the bbcode we'll
@@ -333,8 +386,9 @@ function bbcode($Text,$preserve_nl = false, $tryoembed = true) {
// fix any escaped ampersands that may have been converted into links
$Text = preg_replace("/\<(.*?)(src|href)=(.*?)\&amp\;(.*?)\>/ism",'<$1$2=$3&$4>',$Text);
- if(strlen($saved_image))
- $Text = str_replace('[$#saved_image#$]','<img src="' . $saved_image .'" alt="' . t('Image/photo') . '" />',$Text);
+
+ if($saved_image)
+ $Text = bb_replace_images($Text, $saved_image);
call_hooks('bbcode',$Text);
diff --git a/include/conversation.php b/include/conversation.php
index bbb6a1f85..240cd374f 100644
--- a/include/conversation.php
+++ b/include/conversation.php
@@ -1,30 +1,92 @@
<?php
+// Note: the code in 'item_extract_images' and 'item_redir_and_replace_images'
+// is identical to the code in mod/message.php for 'item_extract_images' and
+// 'item_redir_and_replace_images'
+if(! function_exists('item_extract_images')) {
+function item_extract_images($body) {
+
+ $saved_image = array();
+ $orig_body = $body;
+ $new_body = '';
+
+ $cnt = 0;
+ $img_start = strpos($orig_body, '[img');
+ $img_st_close = ($img_start !== false ? strpos(substr($orig_body, $img_start), ']') : false);
+ $img_end = ($img_start !== false ? strpos(substr($orig_body, $img_start), '[/img]') : false);
+ while(($img_st_close !== false) && ($img_end !== false)) {
+
+ $img_st_close++; // make it point to AFTER the closing bracket
+ $img_end += $img_start;
+
+ if(! strcmp(substr($orig_body, $img_start + $img_st_close, 5), 'data:')) {
+ // This is an embedded image
+
+ $saved_image[$cnt] = substr($orig_body, $img_start + $img_st_close, $img_end - ($img_start + $img_st_close));
+ $new_body = $new_body . substr($orig_body, 0, $img_start) . '[!#saved_image' . $cnt . '#!]';
+
+ $cnt++;
+ }
+ else
+ $new_body = $new_body . substr($orig_body, 0, $img_end + strlen('[/img]'));
+
+ $orig_body = substr($orig_body, $img_end + strlen('[/img]'));
+
+ if($orig_body === false) // in case the body ends on a closing image tag
+ $orig_body = '';
+
+ $img_start = strpos($orig_body, '[img');
+ $img_st_close = ($img_start !== false ? strpos(substr($orig_body, $img_start), ']') : false);
+ $img_end = ($img_start !== false ? strpos(substr($orig_body, $img_start), '[/img]') : false);
+ }
+
+ $new_body = $new_body . $orig_body;
+
+ return array('body' => $new_body, 'images' => $saved_image);
+}}
+
+if(! function_exists('item_redir_and_replace_images')) {
+function item_redir_and_replace_images($body, $images, $cid) {
+
+ $origbody = $body;
+ $newbody = '';
+
+ for($i = 0; $i < count($images); $i++) {
+ $search = '/\[url\=(.*?)\]\[!#saved_image' . $i . '#!\]\[\/url\]' . '/is';
+ $replace = '[url=' . z_path() . '/redir/' . $cid
+ . '?f=1&url=' . '$1' . '][!#saved_image' . $i . '#!][/url]' ;
+
+ $img_end = strpos($origbody, '[!#saved_image' . $i . '#!][/url]') + strlen('[!#saved_image' . $i . '#!][/url]');
+ $process_part = substr($origbody, 0, $img_end);
+ $origbody = substr($origbody, $img_end);
+
+ $process_part = preg_replace($search, $replace, $process_part);
+ $newbody = $newbody . $process_part;
+ }
+ $newbody = $newbody . $origbody;
+
+ $cnt = 0;
+ foreach($images as $image) {
+ // We're depending on the property of 'foreach' (specified on the PHP website) that
+ // it loops over the array starting from the first element and going sequentially
+ // to the last element
+ $newbody = str_replace('[!#saved_image' . $cnt . '#!]', '[img]' . $image . '[/img]', $newbody);
+ $cnt++;
+ }
+
+ return $newbody;
+}}
+
+
+
/**
* Render actions localized
*/
function localize_item(&$item){
- $Text = $item['body'];
- $saved_image = '';
- $img_start = strpos($Text,'[img]data:');
- $img_end = strpos($Text,'[/img]');
-
- if($img_start !== false && $img_end !== false && $img_end > $img_start) {
- $start_fragment = substr($Text,0,$img_start);
- $img_start += strlen('[img]');
- $saved_image = substr($Text,$img_start,$img_end - $img_start);
- $end_fragment = substr($Text,$img_end + strlen('[/img]'));
- $Text = $start_fragment . '[!#saved_image#!]' . $end_fragment;
- $search = '/\[url\=(.*?)\]\[!#saved_image#!\]\[\/url\]' . '/is';
- $replace = '[url=' . z_path() . '/redir/' . $item['contact-id']
- . '?f=1&url=' . '$1' . '][!#saved_image#!][/url]' ;
-
- $Text = preg_replace($search,$replace,$Text);
-
- if(strlen($saved_image))
- $item['body'] = str_replace('[!#saved_image#!]', '[img]' . $saved_image . '[/img]',$Text);
- }
+ $extracted = item_extract_images($item['body']);
+ if($extracted['images'])
+ $item['body'] = item_redir_and_replace_images($extracted['body'], $extracted['images'], $item['contact-id']);
$xmlhead="<"."?xml version='1.0' encoding='UTF-8' ?".">";
if ($item['verb']=== ACTIVITY_LIKE || $item['verb']=== ACTIVITY_DISLIKE){
diff --git a/include/items.php b/include/items.php
index cf903ac13..36a027eec 100755
--- a/include/items.php
+++ b/include/items.php
@@ -4,6 +4,8 @@ require_once('include/bbcode.php');
require_once('include/oembed.php');
require_once('include/salmon.php');
require_once('include/crypto.php');
+require_once('include/Photo.php');
+
function get_feed_for(&$a, $dfrn_id, $owner_nick, $last_update, $direction = 0) {
@@ -278,7 +280,99 @@ function construct_activity_target($item) {
}
return '';
-}
+}
+
+/* limit_body_size()
+ *
+ * The purpose of this function is to apply system message length limits to
+ * imported messages without including any embedded photos in the length
+ */
+if(! function_exists('limit_body_size')) {
+function limit_body_size($body) {
+
+ logger('limit_body_size: start', LOGGER_DEBUG);
+
+ $maxlen = get_max_import_size();
+
+ // If the length of the body, including the embedded images, is smaller
+ // than the maximum, then don't waste time looking for the images
+ if($maxlen && (strlen($body) > $maxlen)) {
+
+ logger('limit_body_size: the total body length exceeds the limit', LOGGER_DEBUG);
+
+ $orig_body = $body;
+ $new_body = '';
+ $textlen = 0;
+ $max_found = false;
+
+ $img_start = strpos($orig_body, '[img');
+ $img_st_close = ($img_start !== false ? strpos(substr($orig_body, $img_start), ']') : false);
+ $img_end = ($img_start !== false ? strpos(substr($orig_body, $img_start), '[/img]') : false);
+ while(($img_st_close !== false) && ($img_end !== false)) {
+
+ $img_st_close++; // make it point to AFTER the closing bracket
+ $img_end += $img_start;
+ $img_end += strlen('[/img]');
+
+ if(! strcmp(substr($orig_body, $img_start + $img_st_close, 5), 'data:')) {
+ // This is an embedded image
+
+ if( ($textlen + $img_start) > $maxlen ) {
+ if($textlen < $maxlen) {
+ logger('limit_body_size: the limit happens before an embedded image', LOGGER_DEBUG);
+ $new_body = $new_body . substr($orig_body, 0, $maxlen - $textlen);
+ $textlen = $maxlen;
+ }
+ }
+ else {
+ $new_body = $new_body . substr($orig_body, 0, $img_start);
+ $textlen += $img_start;
+ }
+
+ $new_body = $new_body . substr($orig_body, $img_start, $img_end - $img_start);
+ }
+ else {
+
+ if( ($textlen + $img_end) > $maxlen ) {
+ if($textlen < $maxlen) {
+ logger('limit_body_size: the limit happens before the end of a non-embedded image', LOGGER_DEBUG);
+ $new_body = $new_body . substr($orig_body, 0, $maxlen - $textlen);
+ $textlen = $maxlen;
+ }
+ }
+ else {
+ $new_body = $new_body . substr($orig_body, 0, $img_end);
+ $textlen += $img_end;
+ }
+ }
+ $orig_body = substr($orig_body, $img_end);
+
+ if($orig_body === false) // in case the body ends on a closing image tag
+ $orig_body = '';
+
+ $img_start = strpos($orig_body, '[img');
+ $img_st_close = ($img_start !== false ? strpos(substr($orig_body, $img_start), ']') : false);
+ $img_end = ($img_start !== false ? strpos(substr($orig_body, $img_start), '[/img]') : false);
+ }
+
+ if( ($textlen + strlen($orig_body)) > $maxlen) {
+ if($textlen < $maxlen) {
+ logger('limit_body_size: the limit happens after the end of the last image', LOGGER_DEBUG);
+ $new_body = $new_body . substr($orig_body, 0, $maxlen - $textlen);
+ $textlen = $maxlen;
+ }
+ }
+ else {
+ logger('limit_body_size: the text size with embedded images extracted did not violate the limit', LOGGER_DEBUG);
+ $new_body = $new_body . $orig_body;
+ $textlen += strlen($orig_body);
+ }
+
+ return $new_body;
+ }
+ else
+ return $body;
+}}
@@ -414,9 +508,8 @@ function get_atom_elements($feed,$item) {
$res['body'] = notags(base64url_decode($res['body']));
}
- $maxlen = get_max_import_size();
- if($maxlen && (strlen($res['body']) > $maxlen))
- $res['body'] = substr($res['body'],0, $maxlen);
+
+ $res['body'] = limit_body_size($res['body']);
// It isn't certain at this point whether our content is plaintext or html and we'd be foolish to trust
// the content type. Our own network only emits text normally, though it might have been converted to
@@ -3088,20 +3181,33 @@ function atom_entry($item,$type,$author,$owner,$comment = false,$cid = 0) {
return $o;
}
-function fix_private_photos($s,$uid, $item = null, $cid = 0) {
+function fix_private_photos($s, $uid, $item = null, $cid = 0) {
$a = get_app();
logger('fix_private_photos', LOGGER_DEBUG);
$site = substr($a->get_baseurl(),strpos($a->get_baseurl(),'://'));
- if(preg_match("/\[img(.*?)\](.*?)\[\/img\]/is",$s,$matches)) {
- $image = $matches[2];
+ $orig_body = $s;
+ $new_body = '';
+
+ $img_start = strpos($orig_body, '[img');
+ $img_st_close = ($img_start !== false ? strpos(substr($orig_body, $img_start), ']') : false);
+ $img_len = ($img_start !== false ? strpos(substr($orig_body, $img_start + $img_st_close + 1), '[/img]') : false);
+ while( ($img_st_close !== false) && ($img_len !== false) ) {
+
+ $img_st_close++; // make it point to AFTER the closing bracket
+ $image = substr($orig_body, $img_start + $img_st_close, $img_len);
+
logger('fix_private_photos: found photo ' . $image, LOGGER_DEBUG);
+
+
if(stristr($image , $site . '/photo/')) {
+ // Only embed locally hosted photos
$replace = false;
$i = basename($image);
$i = str_replace(array('.jpg','.png'),array('',''),$i);
$x = strpos($i,'-');
+
if($x) {
$res = substr($i,$x+1);
$i = substr($i,0,$x);
@@ -3119,14 +3225,6 @@ function fix_private_photos($s,$uid, $item = null, $cid = 0) {
// 3. Otherwise, if we have an item, see if the item permissions match the photo
// permissions, regardless of order but first check to see if they're an exact
// match to save some processing overhead.
-
- // Currently we only embed one private photo per message so as not to hit import
- // size limits at the receiving end.
-
- // To embed multiples, we would need to parse out the embedded photos on message
- // receipt and limit size based only on the text component. Would also need to
- // ignore all photos during bbcode translation and item localisation, as these
- // will hit internal regex backtrace limits.
if(has_permissions($r[0])) {
if($cid) {
@@ -3141,15 +3239,45 @@ function fix_private_photos($s,$uid, $item = null, $cid = 0) {
}
}
if($replace) {
+ $data = $r[0]['data'];
+ $type = $r[0]['type'];
+
+ // If a custom width and height were specified, apply before embedding
+ if(preg_match("/\[img\=([0-9]*)x([0-9]*)\]/is", substr($orig_body, $img_start, $img_st_close), $match)) {
+ logger('fix_private_photos: scaling photo', LOGGER_DEBUG);
+
+ $width = intval($match[1]);
+ $height = intval($match[2]);
+
+ $ph = new Photo($data, $type);
+ if($ph->is_valid()) {
+ $ph->scaleImage(max($width, $height));
+ $data = $ph->imageString();
+ $type = $ph->getType();
+ }
+ }
+
logger('fix_private_photos: replacing photo', LOGGER_DEBUG);
- $s = str_replace($image, 'data:' . $r[0]['type'] . ';base64,' . base64_encode($r[0]['data']), $s);
- logger('fix_private_photos: replaced: ' . $s, LOGGER_DATA);
+ $image = 'data:' . $type . ';base64,' . base64_encode($data);
+ logger('fix_private_photos: replaced: ' . $image, LOGGER_DATA);
}
}
}
}
+
+ $new_body = $new_body . substr($orig_body, 0, $img_start + $img_st_close) . $image . '[/img]';
+ $orig_body = substr($orig_body, $img_start + $img_st_close + $img_len + strlen('[/img]'));
+ if($orig_body === false)
+ $orig_body = '';
+
+ $img_start = strpos($orig_body, '[img');
+ $img_st_close = ($img_start !== false ? strpos(substr($orig_body, $img_start), ']') : false);
+ $img_len = ($img_start !== false ? strpos(substr($orig_body, $img_start + $img_st_close + 1), '[/img]') : false);
}
- return($s);
+
+ $new_body = $new_body . $orig_body;
+
+ return($new_body);
}
diff --git a/include/security.php b/include/security.php
index af201d2af..af201d2af 100755..100644
--- a/include/security.php
+++ b/include/security.php
diff --git a/mod/message.php b/mod/message.php
index 80d2c6d99..1e9d731a4 100644
--- a/mod/message.php
+++ b/mod/message.php
@@ -88,6 +88,84 @@ function message_post(&$a) {
}
+// Note: the code in 'item_extract_images' and 'item_redir_and_replace_images'
+// is identical to the code in include/conversation.php
+if(! function_exists('item_extract_images')) {
+function item_extract_images($body) {
+
+ $saved_image = array();
+ $orig_body = $body;
+ $new_body = '';
+
+ $cnt = 0;
+ $img_start = strpos($orig_body, '[img');
+ $img_st_close = ($img_start !== false ? strpos(substr($orig_body, $img_start), ']') : false);
+ $img_end = ($img_start !== false ? strpos(substr($orig_body, $img_start), '[/img]') : false);
+ while(($img_st_close !== false) && ($img_end !== false)) {
+
+ $img_st_close++; // make it point to AFTER the closing bracket
+ $img_end += $img_start;
+
+ if(! strcmp(substr($orig_body, $img_start + $img_st_close, 5), 'data:')) {
+ // This is an embedded image
+
+ $saved_image[$cnt] = substr($orig_body, $img_start + $img_st_close, $img_end - ($img_start + $img_st_close));
+ $new_body = $new_body . substr($orig_body, 0, $img_start) . '[!#saved_image' . $cnt . '#!]';
+
+ $cnt++;
+ }
+ else
+ $new_body = $new_body . substr($orig_body, 0, $img_end + strlen('[/img]'));
+
+ $orig_body = substr($orig_body, $img_end + strlen('[/img]'));
+
+ if($orig_body === false) // in case the body ends on a closing image tag
+ $orig_body = '';
+
+ $img_start = strpos($orig_body, '[img');
+ $img_st_close = ($img_start !== false ? strpos(substr($orig_body, $img_start), ']') : false);
+ $img_end = ($img_start !== false ? strpos(substr($orig_body, $img_start), '[/img]') : false);
+ }
+
+ $new_body = $new_body . $orig_body;
+
+ return array('body' => $new_body, 'images' => $saved_image);
+}}
+
+if(! function_exists('item_redir_and_replace_images')) {
+function item_redir_and_replace_images($body, $images, $cid) {
+
+ $origbody = $body;
+ $newbody = '';
+
+ for($i = 0; $i < count($images); $i++) {
+ $search = '/\[url\=(.*?)\]\[!#saved_image' . $i . '#!\]\[\/url\]' . '/is';
+ $replace = '[url=' . z_path() . '/redir/' . $cid
+ . '?f=1&url=' . '$1' . '][!#saved_image' . $i . '#!][/url]' ;
+
+ $img_end = strpos($origbody, '[!#saved_image' . $i . '#!][/url]') + strlen('[!#saved_image' . $i . '#!][/url]');
+ $process_part = substr($origbody, 0, $img_end);
+ $origbody = substr($origbody, $img_end);
+
+ $process_part = preg_replace($search, $replace, $process_part);
+ $newbody = $newbody . $process_part;
+ }
+ $newbody = $newbody . $origbody;
+
+ $cnt = 0;
+ foreach($images as $image) {
+ // We're depending on the property of 'foreach' (specified on the PHP website) that
+ // it loops over the array starting from the first element and going sequentially
+ // to the last element
+ $newbody = str_replace('[!#saved_image' . $cnt . '#!]', '[img]' . $image . '[/img]', $newbody);
+ $cnt++;
+ }
+
+ return $newbody;
+}}
+
+
+
function message_content(&$a) {
$o = '';
@@ -345,26 +423,9 @@ function message_content(&$a) {
}
- $Text = $message['body'];
- $saved_image = '';
- $img_start = strpos($Text,'[img]data:');
- $img_end = strpos($Text,'[/img]');
-
- if($img_start !== false && $img_end !== false && $img_end > $img_start) {
- $start_fragment = substr($Text,0,$img_start);
- $img_start += strlen('[img]');
- $saved_image = substr($Text,$img_start,$img_end - $img_start);
- $end_fragment = substr($Text,$img_end + strlen('[/img]'));
- $Text = $start_fragment . '[!#saved_image#!]' . $end_fragment;
- $search = '/\[url\=(.*?)\]\[!#saved_image#!\]\[\/url\]' . '/is';
- $replace = '[url=' . z_path() . '/redir/' . $message['contact-id']
- . '?f=1&url=' . '$1' . '][!#saved_image#!][/url]' ;
-
- $Text = preg_replace($search,$replace,$Text);
-
- if(strlen($saved_image))
- $message['body'] = str_replace('[!#saved_image#!]', '[img]' . $saved_image . '[/img]',$Text);
- }
+ $extracted = item_extract_images($message['body']);
+ if($extracted['images'])
+ $message['body'] = item_redir_and_replace_images($extracted['body'], $extracted['images'], $message['contact-id']);
$mails[] = array(
'id' => $message['id'],
diff --git a/mod/photos.php b/mod/photos.php
index 624f0bdca..42cad42f9 100644
--- a/mod/photos.php
+++ b/mod/photos.php
@@ -740,7 +740,8 @@ function photos_post(&$a) {
killme();
}
- $ph->orient($src);
+ if($ph->getType() != 'image/png')
+ $ph->orient($src);
@unlink($src);
$max_length = get_config('system','max_image_length');
diff --git a/util/run_xgettext.sh b/util/run_xgettext.sh
index 6ea603c83..6ea603c83 100644..100755
--- a/util/run_xgettext.sh
+++ b/util/run_xgettext.sh
diff --git a/view/theme/diabook/ch_directory_item.tpl b/view/theme/diabook/ch_directory_item.tpl
index db1936e4b..db1936e4b 100755..100644
--- a/view/theme/diabook/ch_directory_item.tpl
+++ b/view/theme/diabook/ch_directory_item.tpl
diff --git a/view/theme/diabook/communityhome.tpl b/view/theme/diabook/communityhome.tpl
index caefed3b3..caefed3b3 100755..100644
--- a/view/theme/diabook/communityhome.tpl
+++ b/view/theme/diabook/communityhome.tpl
diff --git a/view/theme/diabook/contact_template.tpl b/view/theme/diabook/contact_template.tpl
index 48930b48a..48930b48a 100755..100644
--- a/view/theme/diabook/contact_template.tpl
+++ b/view/theme/diabook/contact_template.tpl
diff --git a/view/theme/diabook/diabook-aerith/icons/block.png b/view/theme/diabook/diabook-aerith/icons/block.png
index a0b1dffe9..a0b1dffe9 100755..100644
--- a/view/theme/diabook/diabook-aerith/icons/block.png
+++ b/view/theme/diabook/diabook-aerith/icons/block.png
Binary files differ
diff --git a/view/theme/diabook/diabook-blue/icons/block.png b/view/theme/diabook/diabook-blue/icons/block.png
index a0b1dffe9..a0b1dffe9 100755..100644
--- a/view/theme/diabook/diabook-blue/icons/block.png
+++ b/view/theme/diabook/diabook-blue/icons/block.png
Binary files differ
diff --git a/view/theme/diabook/diabook-dark/icons/block.png b/view/theme/diabook/diabook-dark/icons/block.png
index a0b1dffe9..a0b1dffe9 100755..100644
--- a/view/theme/diabook/diabook-dark/icons/block.png
+++ b/view/theme/diabook/diabook-dark/icons/block.png
Binary files differ
diff --git a/view/theme/diabook/diabook-green/icons/block.png b/view/theme/diabook/diabook-green/icons/block.png
index a0b1dffe9..a0b1dffe9 100755..100644
--- a/view/theme/diabook/diabook-green/icons/block.png
+++ b/view/theme/diabook/diabook-green/icons/block.png
Binary files differ
diff --git a/view/theme/diabook/diabook-green/icons/notifications3.png b/view/theme/diabook/diabook-green/icons/notifications3.png
index 2c9c791c0..2c9c791c0 100755..100644
--- a/view/theme/diabook/diabook-green/icons/notifications3.png
+++ b/view/theme/diabook/diabook-green/icons/notifications3.png
Binary files differ
diff --git a/view/theme/diabook/diabook-green/icons/notify3.png b/view/theme/diabook/diabook-green/icons/notify3.png
index 9b852d05b..9b852d05b 100755..100644
--- a/view/theme/diabook/diabook-green/icons/notify3.png
+++ b/view/theme/diabook/diabook-green/icons/notify3.png
Binary files differ
diff --git a/view/theme/diabook/diabook-pink/icons/block.png b/view/theme/diabook/diabook-pink/icons/block.png
index a0b1dffe9..a0b1dffe9 100755..100644
--- a/view/theme/diabook/diabook-pink/icons/block.png
+++ b/view/theme/diabook/diabook-pink/icons/block.png
Binary files differ
diff --git a/view/theme/diabook/diabook-pink/icons/notifications3.png b/view/theme/diabook/diabook-pink/icons/notifications3.png
index 2c9c791c0..2c9c791c0 100755..100644
--- a/view/theme/diabook/diabook-pink/icons/notifications3.png
+++ b/view/theme/diabook/diabook-pink/icons/notifications3.png
Binary files differ
diff --git a/view/theme/diabook/diabook-pink/icons/notify3.png b/view/theme/diabook/diabook-pink/icons/notify3.png
index 9b852d05b..9b852d05b 100755..100644
--- a/view/theme/diabook/diabook-pink/icons/notify3.png
+++ b/view/theme/diabook/diabook-pink/icons/notify3.png
Binary files differ
diff --git a/view/theme/diabook/diabook-red/icons/block.png b/view/theme/diabook/diabook-red/icons/block.png
index a0b1dffe9..a0b1dffe9 100755..100644
--- a/view/theme/diabook/diabook-red/icons/block.png
+++ b/view/theme/diabook/diabook-red/icons/block.png
Binary files differ
diff --git a/view/theme/diabook/directory_item.tpl b/view/theme/diabook/directory_item.tpl
index 70d197955..70d197955 100755..100644
--- a/view/theme/diabook/directory_item.tpl
+++ b/view/theme/diabook/directory_item.tpl
diff --git a/view/theme/diabook/group_side.tpl b/view/theme/diabook/group_side.tpl
index ce4b25fbf..ce4b25fbf 100755..100644
--- a/view/theme/diabook/group_side.tpl
+++ b/view/theme/diabook/group_side.tpl
diff --git a/view/theme/diabook/icons/attach.png b/view/theme/diabook/icons/attach.png
index 1958041cf..1958041cf 100755..100644
--- a/view/theme/diabook/icons/attach.png
+++ b/view/theme/diabook/icons/attach.png
Binary files differ
diff --git a/view/theme/diabook/icons/audio.png b/view/theme/diabook/icons/audio.png
index 8d779a409..8d779a409 100755..100644
--- a/view/theme/diabook/icons/audio.png
+++ b/view/theme/diabook/icons/audio.png
Binary files differ
diff --git a/view/theme/diabook/icons/block.png b/view/theme/diabook/icons/block.png
index a0b1dffe9..a0b1dffe9 100755..100644
--- a/view/theme/diabook/icons/block.png
+++ b/view/theme/diabook/icons/block.png
Binary files differ
diff --git a/view/theme/diabook/icons/camera.png b/view/theme/diabook/icons/camera.png
index a5c7f1236..a5c7f1236 100755..100644
--- a/view/theme/diabook/icons/camera.png
+++ b/view/theme/diabook/icons/camera.png
Binary files differ
diff --git a/view/theme/diabook/icons/close_box.png b/view/theme/diabook/icons/close_box.png
index 28e2675b8..28e2675b8 100755..100644
--- a/view/theme/diabook/icons/close_box.png
+++ b/view/theme/diabook/icons/close_box.png
Binary files differ
diff --git a/view/theme/diabook/icons/contacts2.png b/view/theme/diabook/icons/contacts2.png
index 7817279f4..7817279f4 100755..100644
--- a/view/theme/diabook/icons/contacts2.png
+++ b/view/theme/diabook/icons/contacts2.png
Binary files differ
diff --git a/view/theme/diabook/icons/drop.png b/view/theme/diabook/icons/drop.png
index 2abb82ef2..2abb82ef2 100755..100644
--- a/view/theme/diabook/icons/drop.png
+++ b/view/theme/diabook/icons/drop.png
Binary files differ
diff --git a/view/theme/diabook/icons/expand.png b/view/theme/diabook/icons/expand.png
index a46e88ea5..a46e88ea5 100755..100644
--- a/view/theme/diabook/icons/expand.png
+++ b/view/theme/diabook/icons/expand.png
Binary files differ
diff --git a/view/theme/diabook/icons/file_as.png b/view/theme/diabook/icons/file_as.png
index 16713fa53..16713fa53 100755..100644
--- a/view/theme/diabook/icons/file_as.png
+++ b/view/theme/diabook/icons/file_as.png
Binary files differ
diff --git a/view/theme/diabook/icons/link.png b/view/theme/diabook/icons/link.png
index 0ef666a67..0ef666a67 100755..100644
--- a/view/theme/diabook/icons/link.png
+++ b/view/theme/diabook/icons/link.png
Binary files differ
diff --git a/view/theme/diabook/icons/lock.png b/view/theme/diabook/icons/lock.png
index 7e34bf279..7e34bf279 100755..100644
--- a/view/theme/diabook/icons/lock.png
+++ b/view/theme/diabook/icons/lock.png
Binary files differ
diff --git a/view/theme/diabook/icons/lupe.png b/view/theme/diabook/icons/lupe.png
index f8b228347..f8b228347 100755..100644
--- a/view/theme/diabook/icons/lupe.png
+++ b/view/theme/diabook/icons/lupe.png
Binary files differ
diff --git a/view/theme/diabook/icons/next.png b/view/theme/diabook/icons/next.png
index 7b5e25b90..7b5e25b90 100755..100644
--- a/view/theme/diabook/icons/next.png
+++ b/view/theme/diabook/icons/next.png
Binary files differ
diff --git a/view/theme/diabook/icons/notifications.png b/view/theme/diabook/icons/notifications.png
index 347f1519e..347f1519e 100755..100644
--- a/view/theme/diabook/icons/notifications.png
+++ b/view/theme/diabook/icons/notifications.png
Binary files differ
diff --git a/view/theme/diabook/icons/notifications3.png b/view/theme/diabook/icons/notifications3.png
index 2c9c791c0..2c9c791c0 100755..100644
--- a/view/theme/diabook/icons/notifications3.png
+++ b/view/theme/diabook/icons/notifications3.png
Binary files differ
diff --git a/view/theme/diabook/icons/notify.png b/view/theme/diabook/icons/notify.png
index 355abb1eb..355abb1eb 100755..100644
--- a/view/theme/diabook/icons/notify.png
+++ b/view/theme/diabook/icons/notify.png
Binary files differ
diff --git a/view/theme/diabook/icons/notify3.png b/view/theme/diabook/icons/notify3.png
index 9b852d05b..9b852d05b 100755..100644
--- a/view/theme/diabook/icons/notify3.png
+++ b/view/theme/diabook/icons/notify3.png
Binary files differ
diff --git a/view/theme/diabook/icons/pencil.png b/view/theme/diabook/icons/pencil.png
index 772e49b17..772e49b17 100755..100644
--- a/view/theme/diabook/icons/pencil.png
+++ b/view/theme/diabook/icons/pencil.png
Binary files differ
diff --git a/view/theme/diabook/icons/prev.png b/view/theme/diabook/icons/prev.png
index 55c1464ba..55c1464ba 100755..100644
--- a/view/theme/diabook/icons/prev.png
+++ b/view/theme/diabook/icons/prev.png
Binary files differ
diff --git a/view/theme/diabook/icons/recycle.png b/view/theme/diabook/icons/recycle.png
index c3b8d2bf4..c3b8d2bf4 100755..100644
--- a/view/theme/diabook/icons/recycle.png
+++ b/view/theme/diabook/icons/recycle.png
Binary files differ
diff --git a/view/theme/diabook/icons/remote.png b/view/theme/diabook/icons/remote.png
index a560cc55e..a560cc55e 100755..100644
--- a/view/theme/diabook/icons/remote.png
+++ b/view/theme/diabook/icons/remote.png
Binary files differ
diff --git a/view/theme/diabook/icons/scroll_top.png b/view/theme/diabook/icons/scroll_top.png
index 0e7f7ae6a..0e7f7ae6a 100755..100644
--- a/view/theme/diabook/icons/scroll_top.png
+++ b/view/theme/diabook/icons/scroll_top.png
Binary files differ
diff --git a/view/theme/diabook/icons/star.png b/view/theme/diabook/icons/star.png
index 0b00cb189..0b00cb189 100755..100644
--- a/view/theme/diabook/icons/star.png
+++ b/view/theme/diabook/icons/star.png
Binary files differ
diff --git a/view/theme/diabook/icons/starred.png b/view/theme/diabook/icons/starred.png
index 2b82dfca3..2b82dfca3 100755..100644
--- a/view/theme/diabook/icons/starred.png
+++ b/view/theme/diabook/icons/starred.png
Binary files differ
diff --git a/view/theme/diabook/icons/tagged.png b/view/theme/diabook/icons/tagged.png
index 144649ef8..144649ef8 100755..100644
--- a/view/theme/diabook/icons/tagged.png
+++ b/view/theme/diabook/icons/tagged.png
Binary files differ
diff --git a/view/theme/diabook/icons/unlock.png b/view/theme/diabook/icons/unlock.png
index a0cda0ae5..a0cda0ae5 100755..100644
--- a/view/theme/diabook/icons/unlock.png
+++ b/view/theme/diabook/icons/unlock.png
Binary files differ
diff --git a/view/theme/diabook/icons/unstarred.png b/view/theme/diabook/icons/unstarred.png
index ba3183f5c..ba3183f5c 100755..100644
--- a/view/theme/diabook/icons/unstarred.png
+++ b/view/theme/diabook/icons/unstarred.png
Binary files differ
diff --git a/view/theme/diabook/icons/video.png b/view/theme/diabook/icons/video.png
index a03d1d818..a03d1d818 100755..100644
--- a/view/theme/diabook/icons/video.png
+++ b/view/theme/diabook/icons/video.png
Binary files differ
diff --git a/view/theme/diabook/icons/weblink.png b/view/theme/diabook/icons/weblink.png
index 216e78344..216e78344 100755..100644
--- a/view/theme/diabook/icons/weblink.png
+++ b/view/theme/diabook/icons/weblink.png
Binary files differ
diff --git a/view/theme/diabook/jot.tpl b/view/theme/diabook/jot.tpl
index 1d94cb6d3..1d94cb6d3 100755..100644
--- a/view/theme/diabook/jot.tpl
+++ b/view/theme/diabook/jot.tpl
diff --git a/view/theme/diabook/mail_conv.tpl b/view/theme/diabook/mail_conv.tpl
index 989f17878..989f17878 100755..100644
--- a/view/theme/diabook/mail_conv.tpl
+++ b/view/theme/diabook/mail_conv.tpl
diff --git a/view/theme/diabook/search_item.tpl b/view/theme/diabook/search_item.tpl
index 123834064..123834064 100755..100644
--- a/view/theme/diabook/search_item.tpl
+++ b/view/theme/diabook/search_item.tpl
diff --git a/view/theme/diabook/theme.php b/view/theme/diabook/theme.php
index 53048df6c..53048df6c 100755..100644
--- a/view/theme/diabook/theme.php
+++ b/view/theme/diabook/theme.php