start.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415
  1. <?php
  2. /**
  3. * Event calendar plugin
  4. *
  5. * @package event_calendar
  6. * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU Public License version 2
  7. * @author Kevin Jardine <kevin@radagast.biz>
  8. * @copyright Radagast Solutions 2008-2011
  9. * @link http://radagast.biz/
  10. */
  11. elgg_register_event_handler('init','system','event_calendar_init');
  12. function event_calendar_init() {
  13. elgg_register_library('elgg:event_calendar', elgg_get_plugins_path() . 'event_calendar/models/model.php');
  14. elgg_register_plugin_hook_handler('cron', 'fiveminute', 'event_calendar_handle_reminders_cron',400);
  15. // Register a page handler, so we can have nice URLs
  16. elgg_register_page_handler('event_calendar','event_calendar_page_handler');
  17. // Register URL handler
  18. elgg_register_entity_url_handler('object', 'event_calendar','event_calendar_url');
  19. // Register granular notification for this type
  20. register_notification_object('object', 'event_calendar', elgg_echo('event_calendar:new_event'));
  21. elgg_extend_view('css/elements/forms', 'css/elements/forms/datepicker_multi');
  22. // Set up site menu
  23. $site_calendar = elgg_get_plugin_setting('site_calendar', 'event_calendar');
  24. if (!$site_calendar || $site_calendar != 'no') {
  25. // add a site navigation item
  26. $item = new ElggMenuItem('event_calendar', elgg_echo('item:object:event_calendar'), 'event_calendar/list/');
  27. elgg_register_menu_item('site', $item);
  28. }
  29. // make event calendar title and description searchable
  30. elgg_register_entity_type('object','event_calendar');
  31. // make legacy tags searchable
  32. if (function_exists('elgg_register_tag_metadata_name')) {
  33. elgg_register_tag_metadata_name('event_tags');
  34. }
  35. // register the plugin's JavaScript
  36. $plugin_js = elgg_get_simplecache_url('js', 'event_calendar/event_calendar');
  37. elgg_register_js('elgg.event_calendar', $plugin_js);
  38. //add to group profile page
  39. // TODO - are the left and right values still relevant for Elgg 1.8?
  40. $group_calendar = elgg_get_plugin_setting('group_calendar', 'event_calendar');
  41. if (!$group_calendar || $group_calendar != 'no') {
  42. elgg_register_plugin_hook_handler('register', 'menu:owner_block', 'event_calendar_owner_block_menu');
  43. $group_profile_display = elgg_get_plugin_setting('group_profile_display', 'event_calendar');
  44. if (!$group_profile_display || $group_profile_display == 'right') {
  45. //elgg_extend_view('groups/right_column', 'event_calendar/groupprofile_calendar');
  46. elgg_extend_view('groups/tool_latest', 'event_calendar/group_module');
  47. } else if ($group_profile_display == 'left') {
  48. elgg_extend_view('groups/tool_latest', 'event_calendar/group_module');
  49. //elgg_extend_view('groups/left_column', 'event_calendar/groupprofile_calendar');
  50. }
  51. }
  52. //add to the css
  53. elgg_extend_view('css/elgg', 'event_calendar/css');
  54. $event_calendar_listing_format = elgg_get_plugin_setting('listing_format', 'event_calendar');
  55. if (elgg_is_active_plugin('event_poll') || ($event_calendar_listing_format == 'full')) {
  56. elgg_extend_view('css/elgg', 'fullcalendar/css');
  57. $plugin_js = elgg_get_simplecache_url('js', 'event_calendar/fullcalendar');
  58. elgg_register_js('elgg.full_calendar', $plugin_js);
  59. }
  60. //add a widget
  61. elgg_register_widget_type('event_calendar',elgg_echo("event_calendar:widget_title"),elgg_echo('event_calendar:widget:description'),array('all','dashboard'));
  62. // add the event calendar group tool option
  63. $event_calendar_group_default = elgg_get_plugin_setting('group_default', 'event_calendar');
  64. if (!$event_calendar_group_default || ($event_calendar_group_default == 'yes')) {
  65. add_group_tool_option('event_calendar',elgg_echo('event_calendar:enable_event_calendar'),true);
  66. } else {
  67. add_group_tool_option('event_calendar',elgg_echo('event_calendar:enable_event_calendar'),false);
  68. }
  69. // if autogroup is set, listen and respond to join/leave events
  70. if (elgg_get_plugin_setting('autogroup', 'event_calendar') == 'yes') {
  71. elgg_register_event_handler('join', 'group', 'event_calendar_handle_join');
  72. elgg_register_event_handler('leave', 'group', 'event_calendar_handle_leave');
  73. }
  74. // entity menu
  75. elgg_register_plugin_hook_handler('register', 'menu:entity', 'event_calendar_entity_menu_setup');
  76. elgg_register_plugin_hook_handler('prepare', 'menu:entity', 'event_calendar_entity_menu_prepare');
  77. // register actions
  78. $action_path = elgg_get_plugins_path() . 'event_calendar/actions/event_calendar';
  79. elgg_register_action("event_calendar/edit","$action_path/edit.php");
  80. elgg_register_action("event_calendar/delete","$action_path/delete.php");
  81. elgg_register_action("event_calendar/add_personal","$action_path/add_personal.php");
  82. elgg_register_action("event_calendar/remove_personal","$action_path/remove_personal.php");
  83. elgg_register_action("event_calendar/request_personal_calendar","$action_path/request_personal_calendar.php");
  84. elgg_register_action("event_calendar/toggle_personal_calendar","$action_path/toggle_personal_calendar.php");
  85. elgg_register_action("event_calendar/killrequest","$action_path/killrequest.php");
  86. elgg_register_action("event_calendar/addtocalendar","$action_path/addtocalendar.php");
  87. elgg_register_action("event_calendar/add_to_group","$action_path/add_to_group.php");
  88. elgg_register_action("event_calendar/remove_from_group","$action_path/remove_from_group.php");
  89. elgg_register_action("event_calendar/add_to_group_members","$action_path/add_to_group_members.php");
  90. elgg_register_action("event_calendar/remove_from_group_members","$action_path/remove_from_group_members.php");
  91. elgg_register_action("event_calendar/manage_subscribers","$action_path/manage_subscribers.php");
  92. elgg_register_action("event_calendar/modify_full_calendar","$action_path/modify_full_calendar.php");
  93. elgg_register_action("event_calendar/join_conference","$action_path/join_conference.php");
  94. }
  95. /**
  96. * Add a menu item to an ownerblock
  97. */
  98. function event_calendar_owner_block_menu($hook, $type, $return, $params) {
  99. elgg_load_library('elgg:event_calendar');
  100. if (elgg_instanceof($params['entity'], 'group')) {
  101. if (event_calendar_activated_for_group($params['entity'])) {
  102. $url = "event_calendar/group/{$params['entity']->guid}";
  103. $item = new ElggMenuItem('event_calendar', elgg_echo('event_calendar:group'), $url);
  104. $return[] = $item;
  105. }
  106. }
  107. return $return;
  108. }
  109. function event_calendar_url($entity) {
  110. $friendly_title = elgg_get_friendly_title($entity->title);
  111. return "event_calendar/view/{$entity->guid}/$friendly_title";
  112. }
  113. /**
  114. * Dispatches event calendar pages.
  115. *
  116. * URLs take the form of
  117. * Site event calendar: event_calendar/list/<start_date>/<display_mode>/<filter_context>/<region>
  118. * Single event: event_calendar/view/<event_guid>/<title>
  119. * New event: event_calendar/add
  120. * Edit event: event_calendar/edit/<event_guid>
  121. * Group event calendar: event_calendar/group/<group_guid>/<start_date>/<display_mode>/<filter_context>/<region>
  122. * Add group event: event_calendar/add/<group_guid>
  123. * Review requests: event_calendar/review_requests/<event_guid>
  124. * Display event subscribers: event_calendar/display_users/<event_guid>
  125. * Events for a user's calendar: event_calendar/owner/<username>/<start_date>/<display_mode>/<filter_context>/<region>
  126. *
  127. * Title is ignored
  128. *
  129. * @param array $page
  130. * @return NULL
  131. */
  132. function event_calendar_page_handler($page) {
  133. elgg_load_library('elgg:event_calendar');
  134. $page_type = $page[0];
  135. switch ($page_type) {
  136. case 'list':
  137. if (isset($page[1])) {
  138. $start_date = $page[1];
  139. if (isset($page[2])) {
  140. $display_mode = $page[2];
  141. if (isset($page[3])) {
  142. $filter_mode = $page[3];
  143. if (isset($page[4])) {
  144. $region = $page[4];
  145. } else {
  146. $region = '';
  147. }
  148. } else {
  149. $filter_mode = '';
  150. }
  151. } else {
  152. $display_mode = '';
  153. }
  154. } else {
  155. $start_date = 0;
  156. }
  157. echo event_calendar_get_page_content_list($page_type,0,$start_date,$display_mode,$filter_mode,$region);
  158. break;
  159. case 'view':
  160. echo event_calendar_get_page_content_view($page[1]);
  161. break;
  162. case 'display_users':
  163. echo event_calendar_get_page_content_display_users($page[1]);
  164. break;
  165. case 'manage_users':
  166. echo event_calendar_get_page_content_manage_users($page[1]);
  167. break;
  168. case 'schedule':
  169. case 'add':
  170. if (isset($page[1])) {
  171. group_gatekeeper();
  172. $group_guid = $page[1];
  173. } else {
  174. gatekeeper();
  175. $group_guid = 0;
  176. }
  177. echo event_calendar_get_page_content_edit($page_type,$group_guid,$page[2]);
  178. break;
  179. case 'edit':
  180. gatekeeper();
  181. echo event_calendar_get_page_content_edit($page_type, $page[1]);
  182. break;
  183. case 'group':
  184. group_gatekeeper();
  185. if (isset($page[1])) {
  186. $group_guid = $page[1];
  187. if (isset($page[2])) {
  188. $start_date = $page[2];
  189. if (isset($page[3])) {
  190. $display_mode = $page[3];
  191. if (isset($page[4])) {
  192. $filter_mode = $page[4];
  193. if (isset($page[5])) {
  194. $region = $page[5];
  195. } else {
  196. $region = '';
  197. }
  198. } else {
  199. $filter_mode = '';
  200. }
  201. } else {
  202. $display_mode = '';
  203. }
  204. } else {
  205. $start_date = '';
  206. }
  207. } else {
  208. $group_guid = 0;
  209. }
  210. echo event_calendar_get_page_content_list($page_type,$group_guid,$start_date,$display_mode,$filter_mode,$region);
  211. break;
  212. case 'owner':
  213. if (isset($page[1])) {
  214. $username = $page[1];
  215. $user = get_user_by_username($username);
  216. $user_guid = $user->guid;
  217. if (isset($page[2])) {
  218. $start_date = $page[2];
  219. if (isset($page[3])) {
  220. $display_mode = $page[3];
  221. if (isset($page[4])) {
  222. $filter_mode = $page[4];
  223. if (isset($page[5])) {
  224. $region = $page[5];
  225. } else {
  226. $region = '';
  227. }
  228. } else {
  229. $filter_mode = '';
  230. }
  231. } else {
  232. $display_mode = '';
  233. }
  234. } else {
  235. $start_date = '';
  236. }
  237. } else {
  238. $group_guid = 0;
  239. }
  240. echo event_calendar_get_page_content_list($page_type,$user_guid,$start_date,$display_mode,$filter_mode,$region);
  241. break;
  242. case 'review_requests':
  243. gatekeeper();
  244. echo event_calendar_get_page_content_review_requests($page[1]);
  245. break;
  246. case 'get_fullcalendar_events':
  247. echo event_calendar_get_page_content_fullcalendar_events($page[1],$page[2],$page[3],$page[4]);
  248. break;
  249. default:
  250. return FALSE;
  251. }
  252. return TRUE;
  253. }
  254. /**
  255. * Add particular event calendar links/info to entity menu
  256. */
  257. function event_calendar_entity_menu_setup($hook, $type, $return, $params) {
  258. if (elgg_in_context('widgets')) {
  259. return $return;
  260. }
  261. $entity = $params['entity'];
  262. $handler = elgg_extract('handler', $params, false);
  263. if ($handler != 'event_calendar') {
  264. return $return;
  265. }
  266. if (elgg_is_active_plugin('event_poll') && $entity->canEdit() && $entity->schedule_type == 'poll') {
  267. $options = array(
  268. 'name' => 'schedule',
  269. 'text' => elgg_echo('event_poll:schedule_button'),
  270. 'title' => elgg_echo('event_poll:schedule_button'),
  271. 'href' => 'event_poll/vote/'.$entity->guid,
  272. 'priority' => 150,
  273. );
  274. $return[] = ElggMenuItem::factory($options);
  275. }
  276. $user_guid = elgg_get_logged_in_user_guid();
  277. if ($user_guid) {
  278. $calendar_status = event_calendar_personal_can_manage($entity,$user_guid);
  279. if ($calendar_status == 'open') {
  280. if (event_calendar_has_personal_event($entity->guid,$user_guid)) {
  281. $options = array(
  282. 'name' => 'personal_calendar',
  283. 'text' => elgg_echo('event_calendar:remove_from_the_calendar_menu_text'),
  284. 'title' => elgg_echo('event_calendar:remove_from_my_calendar'),
  285. 'href' => elgg_add_action_tokens_to_url("action/event_calendar/remove_personal?guid={$entity->guid}"),
  286. 'priority' => 150,
  287. );
  288. $return[] = ElggMenuItem::factory($options);
  289. } else {
  290. if (!event_calendar_is_full($entity->guid) && !event_calendar_has_collision($entity->guid,$user_guid)) {
  291. $options = array(
  292. 'name' => 'personal_calendar',
  293. 'text' => elgg_echo('event_calendar:add_to_the_calendar_menu_text'),
  294. 'title' => elgg_echo('event_calendar:add_to_my_calendar'),
  295. 'href' => elgg_add_action_tokens_to_url("action/event_calendar/add_personal?guid={$entity->guid}"),
  296. 'priority' => 150,
  297. );
  298. $return[] = ElggMenuItem::factory($options); }
  299. }
  300. } else if ($calendar_status == 'closed') {
  301. if (!event_calendar_has_personal_event($entity->guid,$user_guid) && !check_entity_relationship($user_guid, 'event_calendar_request', $entity->guid)) {
  302. $options = array(
  303. 'name' => 'personal_calendar',
  304. 'text' => elgg_echo('event_calendar:make_request_title'),
  305. 'title' => elgg_echo('event_calendar:make_request_title'),
  306. 'href' => elgg_add_action_tokens_to_url("action/event_calendar/request_personal_calendar?guid={$entity->guid}"),
  307. 'priority' => 150,
  308. );
  309. $return[] = ElggMenuItem::factory($options);
  310. }
  311. }
  312. }
  313. $count = event_calendar_get_users_for_event($entity->guid,0,0,true);
  314. if ($count == 1) {
  315. $calendar_text = elgg_echo('event_calendar:personal_event_calendars_link_one');
  316. } else {
  317. $calendar_text = elgg_echo('event_calendar:personal_event_calendars_link',array($count));
  318. }
  319. $options = array(
  320. 'name' => 'calendar_listing',
  321. 'text' => $calendar_text,
  322. 'title' => elgg_echo('event_calendar:users_for_event_menu_title'),
  323. 'href' => "event_calendar/display_users/{$entity->guid}",
  324. 'priority' => 150,
  325. );
  326. $return[] = ElggMenuItem::factory($options);
  327. /*if (elgg_is_admin_logged_in() && (elgg_get_plugin_setting('allow_featured', 'event_calendar') == 'yes')) {
  328. if ($event->featured) {
  329. elgg_register_menu_item(elgg_echo('event_calendar:unfeature'), $CONFIG->url . "action/event_calendar/unfeature?event_id=".$event_id.'&'.event_calendar_security_fields(), 'eventcalendaractions');
  330. } else {
  331. elgg_register_menu_item(elgg_echo('event_calendar:feature'), $CONFIG->url . "action/event_calendar/feature?event_id=".$event_id.'&'.event_calendar_security_fields(), 'eventcalendaractions');
  332. }
  333. }*/
  334. return $return;
  335. }
  336. function event_calendar_entity_menu_prepare($hook, $type, $return, $params) {
  337. // remove access level from listings
  338. if (elgg_in_context('event_calendar') && !elgg_in_context('event_calendar:view')) {
  339. $new_return = array();
  340. if (isset($return['default']) && is_array($return['default'])) {
  341. foreach($return['default'] AS $item) {
  342. if ($item->getName() != 'access') {
  343. $new_return[] = $item;
  344. }
  345. }
  346. }
  347. $return['default'] = $new_return;
  348. }
  349. return $return;
  350. }
  351. function event_calendar_handle_join($event, $object_type, $object) {
  352. elgg_load_library('elgg:event_calendar');
  353. $group = $object['group'];
  354. $user = $object['user'];
  355. $user_guid = $user->getGUID();
  356. $events = event_calendar_get_events_for_group($group->getGUID());
  357. foreach ($events as $event) {
  358. $event_id = $event->getGUID();
  359. event_calendar_add_personal_event($event_id,$user_guid);
  360. }
  361. }
  362. function event_calendar_handle_leave($event, $object_type, $object) {
  363. elgg_load_library('elgg:event_calendar');
  364. $group = $object['group'];
  365. $user = $object['user'];
  366. $user_guid = $user->getGUID();
  367. $events = event_calendar_get_events_for_group($group->getGUID());
  368. foreach ($events as $event) {
  369. $event_id = $event->getGUID();
  370. event_calendar_remove_personal_event($event_id,$user_guid);
  371. }
  372. }
  373. function event_calendar_handle_reminders_cron() {
  374. elgg_load_library('elgg:event_calendar');
  375. event_calendar_queue_reminders();
  376. }