convert most red photos to zmg

This commit is contained in:
friendica 2013-05-28 04:50:16 -07:00
parent e81e11382f
commit 08a4ffd663
5 changed files with 20 additions and 18 deletions

View File

@ -4170,9 +4170,9 @@ function fix_private_photos($s, $uid, $item = null, $cid = 0) {
$orig_body = $s; $orig_body = $s;
$new_body = ''; $new_body = '';
$img_start = strpos($orig_body, '[img'); $img_start = strpos($orig_body, '[zmg');
$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_st_close + 1), '[/img]') : false); $img_len = ($img_start !== false ? strpos(substr($orig_body, $img_start + $img_st_close + 1), '[/zmg]') : 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
@ -4222,7 +4222,7 @@ function fix_private_photos($s, $uid, $item = null, $cid = 0) {
$type = $r[0]['type']; $type = $r[0]['type'];
// If a custom width and height were specified, apply before embedding // 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)) { if(preg_match("/\[zmg\=([0-9]*)x([0-9]*)\]/is", substr($orig_body, $img_start, $img_st_close), $match)) {
logger('fix_private_photos: scaling photo', LOGGER_DEBUG); logger('fix_private_photos: scaling photo', LOGGER_DEBUG);
$width = intval($match[1]); $width = intval($match[1]);
@ -4244,14 +4244,14 @@ function fix_private_photos($s, $uid, $item = null, $cid = 0) {
} }
} }
$new_body = $new_body . substr($orig_body, 0, $img_start + $img_st_close) . $image . '[/img]'; $new_body = $new_body . substr($orig_body, 0, $img_start + $img_st_close) . $image . '[/zmg]';
$orig_body = substr($orig_body, $img_start + $img_st_close + $img_len + strlen('[/img]')); $orig_body = substr($orig_body, $img_start + $img_st_close + $img_len + strlen('[/zmg]'));
if($orig_body === false) if($orig_body === false)
$orig_body = ''; $orig_body = '';
$img_start = strpos($orig_body, '[img'); $img_start = strpos($orig_body, '[zmg');
$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_st_close + 1), '[/img]') : false); $img_len = ($img_start !== false ? strpos(substr($orig_body, $img_start + $img_st_close + 1), '[/zmg]') : false);
} }
$new_body = $new_body . $orig_body; $new_body = $new_body . $orig_body;

View File

@ -211,7 +211,7 @@ function photo_upload($channel, $observer, $args) {
$arr['body'] = '[zrl=' . z_root() . '/photos/' . $channel['channel_address'] . '/image/' . $photo_hash . ']' $arr['body'] = '[zrl=' . z_root() . '/photos/' . $channel['channel_address'] . '/image/' . $photo_hash . ']'
. '[img]' . z_root() . "/photo/{$photo_hash}-{$smallest}.".$ph->getExt() . '[/img]' . '[zmg]' . z_root() . "/photo/{$photo_hash}-{$smallest}.".$ph->getExt() . '[/zmg]'
. '[/zrl]'; . '[/zrl]';
$item_id = item_store($arr); $item_id = item_store($arr);
@ -353,7 +353,7 @@ function photos_create_item($channel, $creator_hash, $photo, $visible = false) {
$arr['deny_gid'] = $photo['deny_gid']; $arr['deny_gid'] = $photo['deny_gid'];
$arr['body'] = '[zrl=' . z_root() . '/photos/' . $channel['channel_address'] . '/image/' . $photo['resource_id'] . ']' $arr['body'] = '[zrl=' . z_root() . '/photos/' . $channel['channel_address'] . '/image/' . $photo['resource_id'] . ']'
. '[img]' . z_root() . '/photo/' . $photo['resource_id'] . '-' . $photo['scale'] . '[/img]' . '[zmg]' . z_root() . '/photo/' . $photo['resource_id'] . '-' . $photo['scale'] . '[/zmg]'
. '[/zrl]'; . '[/zrl]';
$item_id = item_store($arr); $item_id = item_store($arr);

View File

@ -1144,12 +1144,13 @@ function prepare_text($text,$content_type = 'text/bbcode') {
function zidify_callback($match) { function zidify_callback($match) {
if (feature_enabled(local_user(),'sendzid')) { if (feature_enabled(local_user(),'sendzid')) {
$replace = '<a' . $match[1] . ' href="' . zid($match[2]) . '"';} $replace = '<a' . $match[1] . ' href="' . zid($match[2]) . '"';
}
else {
$replace = '<a' . $match[1] . 'class="zrl"' . $match[2] . ' href="' . zid($match[3]) . '"';
}
else {
$replace = '<a' . $match[1] . 'class="zrl"' . $match[2] . ' href="' . zid($match[3]) . '"';}
$x = str_replace($match[0],$replace,$match[0]); $x = str_replace($match[0],$replace,$match[0]);
return $x; return $x;
} }
@ -1174,7 +1175,8 @@ function zidify_links($s) {
} }
else { else {
$s = preg_replace_callback('/\<a(.*?)class\=\"zrl\"(.*?)href\=\"(.*?)\"/ism','zidify_callback',$s); $s = preg_replace_callback('/\<a(.*?)class\=\"zrl\"(.*?)href\=\"(.*?)\"/ism','zidify_callback',$s);
// FIXME zidify only img links from known Red servers. $s = preg_replace_callback('/\<img class\=\"zrl\"(.*?)src\=\"(.*?)\"/ism','zidify_img_callback',$s);
// FIXME - remove the following line and redo the regex for the prev line once all Red images are converted to zmg
$s = preg_replace_callback('/\<img(.*?)src\=\"(.*?)\"/ism','zidify_img_callback',$s); $s = preg_replace_callback('/\<img(.*?)src\=\"(.*?)\"/ism','zidify_img_callback',$s);
} }

View File

@ -936,8 +936,8 @@ function fix_attached_photo_permissions($uid,$xchan_hash,$body,
$str_contact_allow,$str_group_allow,$str_contact_deny,$str_group_deny) { $str_contact_allow,$str_group_allow,$str_contact_deny,$str_group_deny) {
$match = null; $match = null;
// match img and zmg image links
if(preg_match_all("/\[img\](.*?)\[\/img\]/",$body,$match)) { if(preg_match_all("/\[[zi]mg\](.*?)\[\/[zi]mg\]/",$body,$match)) {
$images = $match[1]; $images = $match[1];
if($images) { if($images) {
foreach($images as $image) { foreach($images as $image) {

View File

@ -491,7 +491,7 @@ function photos_post(&$a) {
$arr['origin'] = 1; $arr['origin'] = 1;
$arr['body'] = sprintf( t('%1$s was tagged in %2$s by %3$s'), '[zrl=' . $tagged[1] . ']' . $tagged[0] . '[/zrl]', '[zrl=' . $a->get_baseurl() . '/photos/' . $owner_record['nickname'] . '/image/' . $p[0]['resource-id'] . ']' . t('a photo') . '[/zrl]', '[zrl=' . $owner_record['url'] . ']' . $owner_record['name'] . '[/zrl]') ; $arr['body'] = sprintf( t('%1$s was tagged in %2$s by %3$s'), '[zrl=' . $tagged[1] . ']' . $tagged[0] . '[/zrl]', '[zrl=' . $a->get_baseurl() . '/photos/' . $owner_record['nickname'] . '/image/' . $p[0]['resource-id'] . ']' . t('a photo') . '[/zrl]', '[zrl=' . $owner_record['url'] . ']' . $owner_record['name'] . '[/zrl]') ;
$arr['body'] .= "\n\n" . '[zrl=' . $a->get_baseurl() . '/photos/' . $owner_record['nickname'] . '/image/' . $p[0]['resource_id'] . ']' . '[img]' . $a->get_baseurl() . "/photo/" . $p[0]['resource_id'] . '-' . $best . '.' . $ext . '[/img][/zrl]' . "\n" ; $arr['body'] .= "\n\n" . '[zrl=' . $a->get_baseurl() . '/photos/' . $owner_record['nickname'] . '/image/' . $p[0]['resource_id'] . ']' . '[zmg]' . $a->get_baseurl() . "/photo/" . $p[0]['resource_id'] . '-' . $best . '.' . $ext . '[/zmg][/zrl]' . "\n" ;
$arr['object'] = '<object><type>' . ACTIVITY_OBJ_PERSON . '</type><title>' . $tagged[0] . '</title><id>' . $tagged[1] . '/' . $tagged[0] . '</id>'; $arr['object'] = '<object><type>' . ACTIVITY_OBJ_PERSON . '</type><title>' . $tagged[0] . '</title><id>' . $tagged[1] . '/' . $tagged[0] . '</id>';
$arr['object'] .= '<link>' . xmlify('<link rel="alternate" type="text/html" href="' . $tagged[1] . '" />' . "\n"); $arr['object'] .= '<link>' . xmlify('<link rel="alternate" type="text/html" href="' . $tagged[1] . '" />' . "\n");