testing new event code

This commit is contained in:
friendica 2014-05-29 21:25:19 -07:00
parent 22ed5b1d03
commit 832cbbec15
4 changed files with 14 additions and 64 deletions

View File

@ -201,7 +201,7 @@ class Item extends BaseObject {
} }
$has_event = false; $has_event = false;
if(activity_compare($item['obj_type'],ACTIVITY_OBJ_EVENT) && $conv->get_profile_owner() == local_user()) if(($item['obj_type'] === ACTIVITY_OBJ_EVENT) && $conv->get_profile_owner() == local_user())
$has_event = true; $has_event = true;
if($this->is_commentable()) { if($this->is_commentable()) {

View File

@ -135,6 +135,8 @@ function event_store_event($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 // Existing event being modified
if($arr['id'] || $arr['event_hash']) { if($arr['id'] || $arr['event_hash']) {
@ -154,6 +156,7 @@ function event_store_event($arr) {
); );
} }
if(! $r) if(! $r)
return false; return false;
@ -205,9 +208,6 @@ function event_store_event($arr) {
$hash = random_string(); $hash = random_string();
if(! $arr['mid'])
$arr['mid'] = item_message_id();
$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)
@ -261,13 +261,14 @@ function event_addtocal($item_id, $uid) {
intval($channel['channel_id']) intval($channel['channel_id'])
); );
if((! $r) || (! activity_match($r[0]['obj_type'],ACTIVITY_OBJ_EVENT))) if((! $r) || ($r[0]['obj_type'] !== ACTIVITY_OBJ_EVENT))
return false; return false;
$item = $r[0]; $item = $r[0];
$ev = bbtoevent($r[0]['body']); $ev = bbtoevent($r[0]['body']);
if(x($ev,'description') && x($ev,'start')) {
if(x($ev,'summary') && x($ev,'start')) {
$ev['event_xchan'] = $item['author_xchan']; $ev['event_xchan'] = $item['author_xchan'];
$ev['uid'] = $channel['channel_id']; $ev['uid'] = $channel['channel_id'];
$ev['account'] = $channel['channel_account_id']; $ev['account'] = $channel['channel_account_id'];
@ -284,6 +285,7 @@ function event_addtocal($item_id, $uid) {
$event = event_store_event($ev); $event = event_store_event($ev);
if($event) { if($event) {
$r = q("update item set resource_id = '%s', resource_type = 'event' where id = %d and uid = %d limit 1", $r = q("update item set resource_id = '%s', resource_type = 'event' where id = %d and uid = %d limit 1",
dbesc($event['event_hash']),
intval($item['id']), intval($item['id']),
intval($channel['channel_id']) intval($channel['channel_id'])
); );
@ -317,7 +319,7 @@ function event_store_item($arr,$event) {
} }
$r = q("SELECT * FROM item left join xchan on author_xchan = xchan_hash WHERE resource_id = '%s' AND resource_type = 'event' and uid = %d LIMIT 1", $r = q("SELECT * FROM item left join xchan on author_xchan = xchan_hash WHERE resource_id = '%s' AND resource_type = 'event' and uid = %d LIMIT 1",
dbesc($event['hash']), dbesc($event['event_hash']),
intval($arr['uid']) intval($arr['uid'])
); );
@ -386,6 +388,10 @@ function event_store_item($arr,$event) {
$item_arr['item_flags'] = $item_flags; $item_arr['item_flags'] = $item_flags;
} }
if(! $arr['mid'])
$arr['mid'] = item_message_id();
$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'];

View File

@ -1,56 +0,0 @@
<?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);
}
}
}

View File

@ -301,7 +301,7 @@ function enableOnUser(){
} }
function itemAddToCal(id) { function itemAddToCal(id) {
$.get('{{$baseurl}}/event/add/' + id); $.get('{{$baseurl}}/events/add/' + id);
if(timer) clearTimeout(timer); if(timer) clearTimeout(timer);
timer = setTimeout(NavUpdate,1000); timer = setTimeout(NavUpdate,1000);
} }