diff options
author | friendica <info@friendica.com> | 2014-05-29 17:52:11 -0700 |
---|---|---|
committer | friendica <info@friendica.com> | 2014-05-29 17:52:11 -0700 |
commit | dac7f689142f0bd569ae787699c4b9276cb804c6 (patch) | |
tree | 163427012c2e18f8eaaf055824e1e5c71099b12c /include/event.php | |
parent | a3487efd57b3b13463d3eba1d556e49f4948a6ce (diff) | |
download | volse-hubzilla-dac7f689142f0bd569ae787699c4b9276cb804c6.tar.gz volse-hubzilla-dac7f689142f0bd569ae787699c4b9276cb804c6.tar.bz2 volse-hubzilla-dac7f689142f0bd569ae787699c4b9276cb804c6.zip |
event_addtocal function for storing received events
Diffstat (limited to 'include/event.php')
-rw-r--r-- | include/event.php | 58 |
1 files changed, 52 insertions, 6 deletions
diff --git a/include/event.php b/include/event.php index 0dde6b1a5..cc8abb895 100644 --- a/include/event.php +++ b/include/event.php @@ -130,7 +130,7 @@ function ev_compare($a,$b) { function event_store_event($arr) { // Existing event being modified -dbg(1); + if($arr['id'] || $arr['event_hash']) { // has the event actually changed? @@ -147,17 +147,17 @@ dbg(1); intval($arr['uid']) ); } -dbg(0); + if(! $r) - return 0; + return false; if($r[0]['edited'] === $arr['edited']) { // Nothing has changed. Return the ID. - return $r[0]['id']; + return $r[0]; } $event_hash = $r[0]['event_hash']; -dbg(1); + // The event changed. Update it. $r = q("UPDATE `event` SET @@ -202,7 +202,7 @@ dbg(1); if(! $arr['mid']) $arr['mid'] = item_message_id(); -dbg(1); + $r = q("INSERT INTO event ( uid,aid,event_xchan,event_hash,created,edited,start,finish,summary,description,location,type, adjust,nofinish,allow_cid,allow_gid,deny_cid,deny_gid) VALUES ( %d, %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d, %d, '%s', '%s', '%s', '%s' ) ", @@ -239,7 +239,53 @@ dbg(1); } +function event_addtocal($item_id, $uid) { + + $c = q("select * from channel where channel_id = %d limit 1", + intval($uid) + ); + + if(! $c) + return false; + + $channel = $c[0]; + + $r = q("select * from item where id = %d and uid = %d limit 1", + intval($item_id), + intval($channel['channel_id']) + ); + + if((! $r) || (! activity_match($r[0]['obj_type'],ACTIVITY_OBJ_EVENT))) + return false; + $item = $r[0]; + + $ev = bbtoevent($r[0]['body']); + if(x($ev,'description') && x($ev,'start')) { + $ev['event_xchan'] = $item['author_xchan']; + $ev['uid'] = $channel['channel_id']; + $ev['account'] = $channel['channel_account_id']; + $ev['edited'] = $item['edited']; + $ev['mid'] = $item['mid']; + $ev['private'] = $item['item_private']; + + // is this an edit? + + if($item['resource_type'] === 'event') { + $ev['event_hash'] = $item['resource_id']; + } + + $event = event_store_event($ev); + if($event) { + $r = q("update item set resource_id = '%s', resource_type = 'event' where id = %d and uid = %d limit 1", + intval($item['id']), + intval($channel['channel_id']) + ); + return true; + } + } + return false; +} |