better event management
This commit is contained in:
parent
e22e94cd97
commit
a00103b7df
@ -142,8 +142,21 @@ function event_store($arr) {
|
|||||||
$arr['type'] = (($arr['type']) ? $arr['type'] : 'event' );
|
$arr['type'] = (($arr['type']) ? $arr['type'] : 'event' );
|
||||||
$arr['event_xchan'] = (($arr['event_xchan']) ? $arr['event_xchan'] : '');
|
$arr['event_xchan'] = (($arr['event_xchan']) ? $arr['event_xchan'] : '');
|
||||||
|
|
||||||
// Existing event being modified
|
$item = null;
|
||||||
|
|
||||||
|
if($arr['mid'] && $arr['uid']) {
|
||||||
|
$i = q("select * from item where mid = '%s' and uid = %d limit 1",
|
||||||
|
dbesc($arr['mid']),
|
||||||
|
intval($arr['uid'])
|
||||||
|
);
|
||||||
|
if($i) {
|
||||||
|
xchan_query($i);
|
||||||
|
$item = fetch_post_tags($i,true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Existing event being modified
|
||||||
|
dbg(1);
|
||||||
if($arr['id'] || $arr['event_hash']) {
|
if($arr['id'] || $arr['event_hash']) {
|
||||||
|
|
||||||
// has the event actually changed?
|
// has the event actually changed?
|
||||||
@ -160,7 +173,7 @@ function event_store($arr) {
|
|||||||
intval($arr['uid'])
|
intval($arr['uid'])
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
dbg(0);
|
||||||
if(! $r)
|
if(! $r)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
@ -170,7 +183,7 @@ function event_store($arr) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$event_hash = $r[0]['event_hash'];
|
$event_hash = $r[0]['event_hash'];
|
||||||
|
dbg(1);
|
||||||
// The event changed. Update it.
|
// The event changed. Update it.
|
||||||
|
|
||||||
$r = q("UPDATE `event` SET
|
$r = q("UPDATE `event` SET
|
||||||
@ -253,7 +266,7 @@ function event_store($arr) {
|
|||||||
$item_id = 0;
|
$item_id = 0;
|
||||||
|
|
||||||
call_hooks('event_updated', $arr['id']);
|
call_hooks('event_updated', $arr['id']);
|
||||||
|
dbg(0);
|
||||||
return $item_id;
|
return $item_id;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@ -265,7 +278,7 @@ function event_store($arr) {
|
|||||||
if(! $arr['mid'])
|
if(! $arr['mid'])
|
||||||
$arr['mid'] = item_message_id();
|
$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,
|
$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)
|
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' ) ",
|
VALUES ( %d, %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d, %d, '%s', '%s', '%s', '%s' ) ",
|
||||||
@ -302,24 +315,32 @@ function event_store($arr) {
|
|||||||
intval($arr['uid'])
|
intval($arr['uid'])
|
||||||
);
|
);
|
||||||
|
|
||||||
$wall = (($z) ? true : false);
|
|
||||||
|
|
||||||
$item_flags = ITEM_THREAD_TOP;
|
|
||||||
if($wall) {
|
|
||||||
$item_flags |= ITEM_WALL;
|
|
||||||
$item_flags |= ITEM_ORIGIN;
|
|
||||||
}
|
|
||||||
|
|
||||||
$private = (($arr['allow_cid'] || $arr['allow_gid'] || $arr['deny_cid'] || $arr['deny_gid']) ? 1 : 0);
|
$private = (($arr['allow_cid'] || $arr['allow_gid'] || $arr['deny_cid'] || $arr['deny_gid']) ? 1 : 0);
|
||||||
|
|
||||||
$item_arr = array();
|
$item_arr = array();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if($item) {
|
||||||
|
$item_arr['id'] = $item['id'];
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$wall = (($z) ? true : false);
|
||||||
|
|
||||||
|
$item_flags = ITEM_THREAD_TOP;
|
||||||
|
if($wall) {
|
||||||
|
$item_flags |= ITEM_WALL;
|
||||||
|
$item_flags |= ITEM_ORIGIN;
|
||||||
|
}
|
||||||
|
$item_arr['item_flags'] = $item_flags;
|
||||||
|
}
|
||||||
|
|
||||||
$item_arr['uid'] = $arr['uid'];
|
$item_arr['uid'] = $arr['uid'];
|
||||||
$item_arr['author_xchan'] = $arr['event_xchan'];
|
$item_arr['author_xchan'] = $arr['event_xchan'];
|
||||||
$item_arr['mid'] = $arr['mid'];
|
$item_arr['mid'] = $arr['mid'];
|
||||||
$item_arr['parent_mid'] = $arr['mid'];
|
$item_arr['parent_mid'] = $arr['mid'];
|
||||||
|
|
||||||
$item_arr['item_flags'] = $item_flags;
|
|
||||||
|
|
||||||
$item_arr['owner_xchan'] = (($wall) ? $z[0]['channel_hash'] : $arr['event_xchan']);
|
$item_arr['owner_xchan'] = (($wall) ? $z[0]['channel_hash'] : $arr['event_xchan']);
|
||||||
$item_arr['author_xchan'] = $arr['event_xchan'];
|
$item_arr['author_xchan'] = $arr['event_xchan'];
|
||||||
@ -362,11 +383,15 @@ function event_store($arr) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
$res = item_store($item_arr);
|
if($item)
|
||||||
|
$res = item_store_update($item_arr);
|
||||||
|
else
|
||||||
|
$res = item_store($item_arr);
|
||||||
|
|
||||||
$item_id = $res['item_id'];
|
$item_id = $res['item_id'];
|
||||||
|
|
||||||
call_hooks("event_created", $event['id']);
|
call_hooks("event_created", $event['id']);
|
||||||
|
dbg(0);
|
||||||
return $item_id;
|
return $item_id;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1452,36 +1452,6 @@ function process_delivery($sender,$arr,$deliveries,$relay,$public = false) {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// for events, extract the event info and create an event linked to an item
|
|
||||||
|
|
||||||
if((x($arr,'obj_type')) && (activity_match($arr['obj_type'],ACTIVITY_OBJ_EVENT))) {
|
|
||||||
require_once('include/event.php');
|
|
||||||
$ev = bbtoevent($arr['body']);
|
|
||||||
if(x($ev,'desc') && x($ev,'start')) {
|
|
||||||
$ev['event_xchan'] = $arr['author_xchan'];
|
|
||||||
$ev['uid'] = $channel['channel_id'];
|
|
||||||
$ev['account'] = $channel['channel_account_id'];
|
|
||||||
$ev['edited'] = $arr['edited'];
|
|
||||||
$ev['mid'] = $arr['mid'];
|
|
||||||
$ev['private'] = $arr['item_private'];
|
|
||||||
|
|
||||||
// is this an edit?
|
|
||||||
|
|
||||||
$r = q("SELECT resource_id FROM item where mid = '%s' and uid = %d and resource_type = 'event' limit 1",
|
|
||||||
dbesc($arr['mid']),
|
|
||||||
intval($channel['channel_id'])
|
|
||||||
);
|
|
||||||
if($r) {
|
|
||||||
$ev['event_hash'] = $r[0]['resource_id'];
|
|
||||||
}
|
|
||||||
|
|
||||||
$xyz = event_store($ev);
|
|
||||||
add_source_route($xyz,$sender['hash']);
|
|
||||||
|
|
||||||
$result = array($d['hash'],'event processed',$channel['channel_name'] . ' <' . $channel['channel_address'] . '@' . get_app()->get_hostname() . '>',$arr['mid']);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$r = q("select id, edited from item where mid = '%s' and uid = %d limit 1",
|
$r = q("select id, edited from item where mid = '%s' and uid = %d limit 1",
|
||||||
dbesc($arr['mid']),
|
dbesc($arr['mid']),
|
||||||
|
56
mod/addtocal.php
Normal file
56
mod/addtocal.php
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
<?php /** @file */
|
||||||
|
|
||||||
|
|
||||||
|
function addtocal_init(&$a) {
|
||||||
|
|
||||||
|
if(! local_user())
|
||||||
|
return;
|
||||||
|
|
||||||
|
if(argc() > 1) {
|
||||||
|
$post_id = intval(argv(1));
|
||||||
|
|
||||||
|
$r = q("select * from item where id = %d and uid = %d limit 1",
|
||||||
|
intval($post_id),
|
||||||
|
intval(local_user())
|
||||||
|
);
|
||||||
|
|
||||||
|
if(! $r)
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$arr = $r[0];
|
||||||
|
$channel = $a->get_channel();
|
||||||
|
|
||||||
|
if(! $channel)
|
||||||
|
return;
|
||||||
|
|
||||||
|
// for events, extract the event info and create an event linked to an item
|
||||||
|
|
||||||
|
if((x($arr,'obj_type')) && (activity_match($arr['obj_type'],ACTIVITY_OBJ_EVENT))) {
|
||||||
|
|
||||||
|
require_once('include/event.php');
|
||||||
|
$ev = bbtoevent($arr['body']);
|
||||||
|
|
||||||
|
if(x($ev,'description') && x($ev,'start')) {
|
||||||
|
$ev['event_xchan'] = $arr['author_xchan'];
|
||||||
|
$ev['uid'] = $channel['channel_id'];
|
||||||
|
$ev['account'] = $channel['channel_account_id'];
|
||||||
|
$ev['edited'] = $arr['edited'];
|
||||||
|
$ev['mid'] = $arr['mid'];
|
||||||
|
$ev['private'] = $arr['item_private'];
|
||||||
|
|
||||||
|
// is this an edit?
|
||||||
|
|
||||||
|
$r = q("SELECT resource_id FROM item where mid = '%s' and uid = %d and resource_type = 'event' limit 1",
|
||||||
|
dbesc($arr['mid']),
|
||||||
|
intval($channel['channel_id'])
|
||||||
|
);
|
||||||
|
if($r) {
|
||||||
|
$ev['event_hash'] = $r[0]['resource_id'];
|
||||||
|
}
|
||||||
|
|
||||||
|
$xyz = event_store($ev);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user