aboutsummaryrefslogtreecommitdiffstats
path: root/mod
diff options
context:
space:
mode:
authorZach Prezkuta <fermion@gmx.com>2012-07-07 18:47:13 -0600
committerZach Prezkuta <fermion@gmx.com>2012-07-07 18:50:33 -0600
commitda2ccebed8f1c87b0481ba476b4d13e601ce5feb (patch)
tree285173179d117fc8812d3389b01f393112b6281d /mod
parent173b3a1b9ad926937ec152e41756c5b63f6c5951 (diff)
downloadvolse-hubzilla-da2ccebed8f1c87b0481ba476b4d13e601ce5feb.tar.gz
volse-hubzilla-da2ccebed8f1c87b0481ba476b4d13e601ce5feb.tar.bz2
volse-hubzilla-da2ccebed8f1c87b0481ba476b4d13e601ce5feb.zip
fix bugs
Diffstat (limited to 'mod')
-rw-r--r--mod/message.php19
1 files changed, 13 insertions, 6 deletions
diff --git a/mod/message.php b/mod/message.php
index 4ffdebb12..1e9d731a4 100644
--- a/mod/message.php
+++ b/mod/message.php
@@ -109,10 +109,10 @@ function item_extract_images($body) {
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);
- $cnt++;
-
+ $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]'));
@@ -135,22 +135,29 @@ function item_extract_images($body) {
if(! function_exists('item_redir_and_replace_images')) {
function item_redir_and_replace_images($body, $images, $cid) {
- $newbody = $body;
+ $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]' ;
- $newbody = preg_replace($search, $replace, $newbody);
+ $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);
+ $newbody = str_replace('[!#saved_image' . $cnt . '#!]', '[img]' . $image . '[/img]', $newbody);
$cnt++;
}