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,6 +270,41 @@ function photo_upload($channel, $observer, $args) {
} }
} }
if($args['item']) {
foreach($args['item'] as $i) {
$item = get_item_elements($i);
$force = false;
if($item['mid'] === $item['parent_mid']) {
$item['body'] = '[zrl=' . z_root() . '/photos/' . $channel['channel_address'] . '/image/' . $photo_hash . ']'
. $tag . z_root() . "/photo/{$photo_hash}-{$smallest}.".$ph->getExt() . '[/zmg]'
. '[/zrl]';
$item['sig'] = '';
$force = true;
}
$r = q("select id, edited from item where mid = '%s' and uid = %d limit 1",
dbesc($item['mid']),
intval($channel['channel_id'])
);
if($r) {
if(($item['edited'] > $r[0]['edited']) || $force) {
$item['id'] = $r[0]['id'];
$item['uid'] = $channel['channel_id'];
item_store_update($item);
continue;
}
}
else {
$item['aid'] = $channel['channel_account_id'];
$item['uid'] = $channel['channel_id'];
$item_result = item_store($item);
}
}
}
else {
$title = ''; $title = '';
$mid = item_message_id(); $mid = item_message_id();
@ -300,7 +335,7 @@ function photo_upload($channel, $observer, $args) {
$arr['plink'] = z_root() . '/channel/' . $channel['channel_address'] . '/?f=&mid=' . $arr['mid']; $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 // We should also put a width_x_height on large photos. Left as an exercise for
// devs looking fo simple stuff to fix. // devs looking for simple stuff to fix.
$larger = feature_enabled($channel['channel_id'], 'large_photos'); $larger = feature_enabled($channel['channel_id'], 'large_photos');
if($larger) { if($larger) {
@ -326,6 +361,7 @@ function photo_upload($channel, $observer, $args) {
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;