This commit is contained in:
Zach Prezkuta 2012-07-07 18:47:13 -06:00
parent 173b3a1b9a
commit da2ccebed8
4 changed files with 33 additions and 19 deletions

View File

@ -66,10 +66,10 @@ function bb_extract_images($body) {
if(! strcmp(substr($orig_body, $img_start + $img_st_close, 5), 'data:')) { if(! strcmp(substr($orig_body, $img_start + $img_st_close, 5), 'data:')) {
// This is an embedded image // This is an embedded image
$saved_image[$cnt] = substr($orig_body, $img_start + $img_st_close, $img_end - $img_start); $saved_image[$cnt] = substr($orig_body, $img_start + $img_st_close, $img_end - ($img_start + $img_st_close));
$cnt++;
$new_body = $new_body . substr($orig_body, 0, $img_start) . '[$#saved_image' . $cnt . '#$]'; $new_body = $new_body . substr($orig_body, 0, $img_start) . '[$#saved_image' . $cnt . '#$]';
$cnt++;
} }
else else
$new_body = $new_body . substr($orig_body, 0, $img_end + strlen('[/img]')); $new_body = $new_body . substr($orig_body, 0, $img_end + strlen('[/img]'));

View File

@ -22,10 +22,10 @@ function item_extract_images($body) {
if(! strcmp(substr($orig_body, $img_start + $img_st_close, 5), 'data:')) { if(! strcmp(substr($orig_body, $img_start + $img_st_close, 5), 'data:')) {
// This is an embedded image // This is an embedded image
$saved_image[$cnt] = substr($orig_body, $img_start + $img_st_close, $img_end - $img_start); $saved_image[$cnt] = substr($orig_body, $img_start + $img_st_close, $img_end - ($img_start + $img_st_close));
$cnt++;
$new_body = $new_body . substr($orig_body, 0, $img_start) . '[!#saved_image' . $cnt . '#!]'; $new_body = $new_body . substr($orig_body, 0, $img_start) . '[!#saved_image' . $cnt . '#!]';
$cnt++;
} }
else else
$new_body = $new_body . substr($orig_body, 0, $img_end + strlen('[/img]')); $new_body = $new_body . substr($orig_body, 0, $img_end + strlen('[/img]'));
@ -48,22 +48,29 @@ function item_extract_images($body) {
if(! function_exists('item_redir_and_replace_images')) { if(! function_exists('item_redir_and_replace_images')) {
function item_redir_and_replace_images($body, $images, $cid) { function item_redir_and_replace_images($body, $images, $cid) {
$newbody = $body; $origbody = $body;
$newbody = '';
for($i = 0; $i < count($images); $i++) { for($i = 0; $i < count($images); $i++) {
$search = '/\[url\=(.*?)\]\[!#saved_image' . $i . '#!\]\[\/url\]' . '/is'; $search = '/\[url\=(.*?)\]\[!#saved_image' . $i . '#!\]\[\/url\]' . '/is';
$replace = '[url=' . z_path() . '/redir/' . $cid $replace = '[url=' . z_path() . '/redir/' . $cid
. '?f=1&url=' . '$1' . '][!#saved_image' . $i . '#!][/url]' ; . '?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; $cnt = 0;
foreach($images as $image) { foreach($images as $image) {
// We're depending on the property of 'foreach' (specified on the PHP website) that // 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 // it loops over the array starting from the first element and going sequentially
// to the last element // 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++; $cnt++;
} }

View File

@ -326,7 +326,7 @@ function limit_body_size($body) {
} }
else { else {
$new_body = $new_body . substr($orig_body, 0, $img_start); $new_body = $new_body . substr($orig_body, 0, $img_start);
$textlen += $img_start $textlen += $img_start;
} }
$new_body = $new_body . substr($orig_body, $img_start, $img_end - $img_start); $new_body = $new_body . substr($orig_body, $img_start, $img_end - $img_start);
@ -3192,7 +3192,7 @@ function fix_private_photos($s, $uid, $item = null, $cid = 0) {
$img_start = strpos($orig_body, '[img'); $img_start = strpos($orig_body, '[img');
$img_st_close = ($img_start !== false ? strpos(substr($orig_body, $img_start), ']') : false); $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]') : 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) ) { while( ($img_st_close !== false) && ($img_len !== false) ) {
$img_st_close++; // make it point to AFTER the closing bracket $img_st_close++; // make it point to AFTER the closing bracket
@ -3277,10 +3277,10 @@ function fix_private_photos($s, $uid, $item = null, $cid = 0) {
$img_start = strpos($orig_body, '[img'); $img_start = strpos($orig_body, '[img');
$img_st_close = ($img_start !== false ? strpos(substr($orig_body, $img_start), ']') : false); $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]') : false); $img_len = ($img_start !== false ? strpos(substr($orig_body, $img_start + $img_st_close + 1), '[/img]') : false);
} }
$new_body = $new_body + $orig_body; $new_body = $new_body . $orig_body;
return($new_body); return($new_body);
} }

View File

@ -109,10 +109,10 @@ function item_extract_images($body) {
if(! strcmp(substr($orig_body, $img_start + $img_st_close, 5), 'data:')) { if(! strcmp(substr($orig_body, $img_start + $img_st_close, 5), 'data:')) {
// This is an embedded image // This is an embedded image
$saved_image[$cnt] = substr($orig_body, $img_start + $img_st_close, $img_end - $img_start); $saved_image[$cnt] = substr($orig_body, $img_start + $img_st_close, $img_end - ($img_start + $img_st_close));
$cnt++;
$new_body = $new_body . substr($orig_body, 0, $img_start) . '[!#saved_image' . $cnt . '#!]'; $new_body = $new_body . substr($orig_body, 0, $img_start) . '[!#saved_image' . $cnt . '#!]';
$cnt++;
} }
else else
$new_body = $new_body . substr($orig_body, 0, $img_end + strlen('[/img]')); $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')) { if(! function_exists('item_redir_and_replace_images')) {
function item_redir_and_replace_images($body, $images, $cid) { function item_redir_and_replace_images($body, $images, $cid) {
$newbody = $body; $origbody = $body;
$newbody = '';
for($i = 0; $i < count($images); $i++) { for($i = 0; $i < count($images); $i++) {
$search = '/\[url\=(.*?)\]\[!#saved_image' . $i . '#!\]\[\/url\]' . '/is'; $search = '/\[url\=(.*?)\]\[!#saved_image' . $i . '#!\]\[\/url\]' . '/is';
$replace = '[url=' . z_path() . '/redir/' . $cid $replace = '[url=' . z_path() . '/redir/' . $cid
. '?f=1&url=' . '$1' . '][!#saved_image' . $i . '#!][/url]' ; . '?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; $cnt = 0;
foreach($images as $image) { foreach($images as $image) {
// We're depending on the property of 'foreach' (specified on the PHP website) that // 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 // it loops over the array starting from the first element and going sequentially
// to the last element // 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++; $cnt++;
} }