From 2f64684299784126bb3bc80fbe9978ec57d19a4c Mon Sep 17 00:00:00 2001 From: redmatrix Date: Wed, 25 May 2016 20:06:21 -0700 Subject: some event fixes, also change jquery-textcomplete to un-minified since the minified version appears to require a mapping file and causes a lot of server fetch errors trying to load it. --- Zotlabs/Module/Events.php | 2 +- include/bbcode.php | 1 + include/event.php | 59 ++++++++++++++++++++++++++++++----------------- view/php/theme_init.php | 2 +- 4 files changed, 41 insertions(+), 23 deletions(-) diff --git a/Zotlabs/Module/Events.php b/Zotlabs/Module/Events.php index 3440e0727..2b5e239f9 100644 --- a/Zotlabs/Module/Events.php +++ b/Zotlabs/Module/Events.php @@ -232,7 +232,7 @@ class Events extends \Zotlabs\Web\Controller { } if($share) - \Zotlabs\Daemon\Master(array('Notifier','event',$item_id)); + \Zotlabs\Daemon\Master::Summon(array('Notifier','event',$item_id)); } diff --git a/include/bbcode.php b/include/bbcode.php index 142a15d35..f47dc6f2e 100644 --- a/include/bbcode.php +++ b/include/bbcode.php @@ -981,6 +981,7 @@ function bbcode($Text, $preserve_nl = false, $tryoembed = true, $cache = false) $Text = preg_replace("/\[event\-summary\](.*?)\[\/event\-summary\]/ism",'',$Text); $Text = preg_replace("/\[event\-description\](.*?)\[\/event\-description\]/ism",'',$Text); $Text = preg_replace("/\[event\-finish\](.*?)\[\/event\-finish\]/ism",'',$Text); + $Text = preg_replace("/\[event\-id\](.*?)\[\/event\-id\]/ism",'',$Text); $Text = preg_replace("/\[event\-location\](.*?)\[\/event\-location\]/ism",'',$Text); $Text = preg_replace("/\[event\-adjust\](.*?)\[\/event\-adjust\]/ism",'',$Text); diff --git a/include/event.php b/include/event.php index 29ca5bb79..db67dac64 100644 --- a/include/event.php +++ b/include/event.php @@ -175,6 +175,9 @@ function format_event_bbcode($ev) { if($ev['location']) $o .= '[event-location]' . $ev['location'] . '[/event-location]'; + if($ev['event_hash']) + $o .= '[event-id]' . $ev['event_hash'] . '[/event-id]'; + if($ev['adjust']) $o .= '[event-adjust]' . $ev['adjust'] . '[/event-adjust]'; @@ -212,6 +215,9 @@ function bbtoevent($s) { if(preg_match("/\[event\-location\](.*?)\[\/event\-location\]/is",$s,$match)) $ev['location'] = $match[1]; $match = ''; + if(preg_match("/\[event\-id\](.*?)\[\/event\-id\]/is",$s,$match)) + $ev['event_hash'] = $match[1]; + $match = ''; if(preg_match("/\[event\-adjust\](.*?)\[\/event\-adjust\]/is",$s,$match)) $ev['adjust'] = $match[1]; if(array_key_exists('start',$ev)) { @@ -278,34 +284,41 @@ function event_store_event($arr) { else $arr['event_status_date'] = NULL_DATE; - // Existing event being modified - if($arr['id'] || $arr['event_hash']) { + $existing_event = null; - // has the event actually changed? + if($arr['event_hash']) { + $r = q("SELECT * FROM event WHERE event_hash = '%s' AND uid = %d LIMIT 1", + dbesc($arr['event_hash']), + intval($arr['uid']) + ); + if($r) { + $existing_event = $r[0]; + } + } - if($arr['event_hash']) { - $r = q("SELECT * FROM event WHERE event_hash = '%s' AND uid = %d LIMIT 1", - dbesc($arr['event_hash']), - intval($arr['uid']) - ); + if($arr['id']) { + $r = q("SELECT * FROM event WHERE id = %d AND uid = %d LIMIT 1", + intval($arr['id']), + intval($arr['uid']) + ); + if($r) { + $existing_event = $r[0]; } else { - $r = q("SELECT * FROM event WHERE id = %d AND uid = %d LIMIT 1", - intval($arr['id']), - intval($arr['uid']) - ); + return false; } + } - if(! $r) - return false; - if($r[0]['edited'] === $arr['edited']) { - // Nothing has changed. Return the ID. - return $r[0]; + if($existing_event) { + + if($existing_event['edited'] >= $arr['edited']) { + // Nothing has changed. + return $existing_event; } - $hash = $r[0]['event_hash']; + $hash = $existing_event['event_hash']; // The event changed. Update it. @@ -350,7 +363,7 @@ function event_store_event($arr) { dbesc($arr['allow_gid']), dbesc($arr['deny_cid']), dbesc($arr['deny_gid']), - intval($r[0]['id']), + intval($existing_event['id']), intval($arr['uid']) ); } else { @@ -360,6 +373,8 @@ function event_store_event($arr) { if(array_key_exists('external_id',$arr)) $hash = $arr['external_id']; + elseif(array_key_exists('event_hash',$arr)) + $hash = $arr['event_hash']; else $hash = random_string() . '@' . App::get_hostname(); @@ -436,7 +451,7 @@ function event_addtocal($item_id, $uid) { // is this an edit? - if($item['resource_type'] === 'event') { + if($item['resource_type'] === 'event' && (! $ev['event_hash'])) { $ev['event_hash'] = $item['resource_id']; } @@ -472,7 +487,6 @@ function event_addtocal($item_id, $uid) { if($z) { build_sync_packet($channel['channel_id'],array('event_item' => array(encode_item($sync_item[0],true)),'event' => $z)); } - return true; } } @@ -764,6 +778,9 @@ function event_store_item($arr, $event) { $prefix = ''; // $birthday = false; + if(($event) && array_key_exists('event_hash',$event) && (! array_key_exists('event_hash',$arr))) + $arr['event_hash'] = $event['event_hash']; + if($event['type'] === 'birthday') { if(! is_sys_channel($arr['uid'])) $prefix = t('This event has been added to your calendar.'); diff --git a/view/php/theme_init.php b/view/php/theme_init.php index 7c020a51f..648b144b3 100644 --- a/view/php/theme_init.php +++ b/view/php/theme_init.php @@ -21,7 +21,7 @@ head_add_js('spin.js'); head_add_js('jquery.spin.js'); head_add_js('jquery.textinputs.js'); head_add_js('autocomplete.js'); -head_add_js('library/jquery-textcomplete/jquery.textcomplete.min.js'); +head_add_js('library/jquery-textcomplete/jquery.textcomplete.js'); //head_add_js('library/colorbox/jquery.colorbox.js'); head_add_js('library/jquery.timeago.js'); head_add_js('library/readmore.js/readmore.js'); -- cgit v1.2.3