change attach_store to allow a predefined item to accompany a photo

This commit is contained in:
redmatrix 2015-08-26 22:13:20 -07:00
parent 54c88dfae9
commit 9cebd24987
2 changed files with 83 additions and 45 deletions

View File

@ -758,6 +758,8 @@ function attach_store($channel, $observer_hash, $options = '', $arr = null) {
$args['created'] = $created; $args['created'] = $created;
$args['edited'] = $edited; $args['edited'] = $edited;
if($arr['item'])
$args['item'] = $arr['item'];
$p = photo_upload($channel,$observer,$args); $p = photo_upload($channel,$observer,$args);
if($p['success']) { if($p['success']) {

View File

@ -270,62 +270,98 @@ function photo_upload($channel, $observer, $args) {
} }
} }
$title = ''; if($args['item']) {
$mid = item_message_id(); foreach($args['item'] as $i) {
$arr = array(); $item = get_item_elements($i);
$force = false;
if($lat && $lon) if($item['mid'] === $item['parent_mid']) {
$arr['coord'] = $lat . ' ' . $lon;
$arr['aid'] = $account_id; $item['body'] = '[zrl=' . z_root() . '/photos/' . $channel['channel_address'] . '/image/' . $photo_hash . ']'
$arr['uid'] = $channel_id; . $tag . z_root() . "/photo/{$photo_hash}-{$smallest}.".$ph->getExt() . '[/zmg]'
$arr['mid'] = $mid; . '[/zrl]';
$arr['parent_mid'] = $mid; $item['sig'] = '';
$arr['item_hidden'] = $item_hidden; $force = true;
$arr['resource_type'] = 'photo';
$arr['resource_id'] = $photo_hash;
$arr['owner_xchan'] = $channel['channel_hash'];
$arr['author_xchan'] = $observer['xchan_hash'];
$arr['title'] = $title;
$arr['allow_cid'] = $str_contact_allow;
$arr['allow_gid'] = $str_group_allow;
$arr['deny_cid'] = $str_contact_deny;
$arr['deny_gid'] = $str_group_deny;
$arr['verb'] = ACTIVITY_POST;
$arr['item_wall'] = 1;
$arr['item_origin'] = 1;
$arr['item_thread_top'] = 1;
$arr['plink'] = z_root() . '/channel/' . $channel['channel_address'] . '/?f=&mid=' . $arr['mid']; }
$r = q("select id, edited from item where mid = '%s' and uid = %d limit 1",
// We should also put a width_x_height on large photos. Left as an exercise for dbesc($item['mid']),
// devs looking fo simple stuff to fix. intval($channel['channel_id'])
);
$larger = feature_enabled($channel['channel_id'], 'large_photos'); if($r) {
if($larger) { if(($item['edited'] > $r[0]['edited']) || $force) {
$tag = '[zmg]'; $item['id'] = $r[0]['id'];
if($r2) $item['uid'] = $channel['channel_id'];
$smallest = 1; item_store_update($item);
else continue;
$smallest = 0; }
}
else {
$item['aid'] = $channel['channel_account_id'];
$item['uid'] = $channel['channel_id'];
$item_result = item_store($item);
}
}
} }
else { else {
if ($width_x_height) $title = '';
$tag = '[zmg=' . $width_x_height. ']'; $mid = item_message_id();
else
$tag = '[zmg]';
}
$arr['body'] = '[zrl=' . z_root() . '/photos/' . $channel['channel_address'] . '/image/' . $photo_hash . ']' $arr = array();
if($lat && $lon)
$arr['coord'] = $lat . ' ' . $lon;
$arr['aid'] = $account_id;
$arr['uid'] = $channel_id;
$arr['mid'] = $mid;
$arr['parent_mid'] = $mid;
$arr['item_hidden'] = $item_hidden;
$arr['resource_type'] = 'photo';
$arr['resource_id'] = $photo_hash;
$arr['owner_xchan'] = $channel['channel_hash'];
$arr['author_xchan'] = $observer['xchan_hash'];
$arr['title'] = $title;
$arr['allow_cid'] = $str_contact_allow;
$arr['allow_gid'] = $str_group_allow;
$arr['deny_cid'] = $str_contact_deny;
$arr['deny_gid'] = $str_group_deny;
$arr['verb'] = ACTIVITY_POST;
$arr['item_wall'] = 1;
$arr['item_origin'] = 1;
$arr['item_thread_top'] = 1;
$arr['plink'] = z_root() . '/channel/' . $channel['channel_address'] . '/?f=&mid=' . $arr['mid'];
// We should also put a width_x_height on large photos. Left as an exercise for
// devs looking for simple stuff to fix.
$larger = feature_enabled($channel['channel_id'], 'large_photos');
if($larger) {
$tag = '[zmg]';
if($r2)
$smallest = 1;
else
$smallest = 0;
}
else {
if ($width_x_height)
$tag = '[zmg=' . $width_x_height. ']';
else
$tag = '[zmg]';
}
$arr['body'] = '[zrl=' . z_root() . '/photos/' . $channel['channel_address'] . '/image/' . $photo_hash . ']'
. $tag . z_root() . "/photo/{$photo_hash}-{$smallest}.".$ph->getExt() . '[/zmg]' . $tag . z_root() . "/photo/{$photo_hash}-{$smallest}.".$ph->getExt() . '[/zmg]'
. '[/zrl]'; . '[/zrl]';
$result = item_store($arr); $result = item_store($arr);
$item_id = $result['item_id']; $item_id = $result['item_id'];
if($visible) if($visible)
proc_run('php', "include/notifier.php", 'wall-new', $item_id); proc_run('php', "include/notifier.php", 'wall-new', $item_id);
}
$ret['success'] = true; $ret['success'] = true;
$ret['item'] = $arr; $ret['item'] = $arr;