-
Notifications
You must be signed in to change notification settings - Fork 2
/
start.php
186 lines (162 loc) · 6.55 KB
/
start.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
<?php
elgg_register_event_handler('init', 'system', 'sched_conf_init');
elgg_register_event_handler('init', 'system', 'sched_conf_pagesetup');
/**
* Init plugin.
*/
function sched_conf_init() {
elgg_register_library('elgg:sched_conf', elgg_get_plugins_path() . 'sched_conf/models/model.php');
// add a site navigation item
$item = new ElggMenuItem('sched_conf', elgg_echo('sched_conf:site_menu_title'), 'sched_conf/add');
elgg_register_menu_item('site', $item);
// add to the main css
//elgg_extend_view('css/elgg', 'sched_conf/css');
// routing of urls
elgg_register_page_handler('sched_conf', 'sched_conf_page_handler');
// override the default url to view a conference object
elgg_register_entity_url_handler('object', 'conference', 'sched_conf_url_handler');
// entity menu
elgg_register_plugin_hook_handler('register', 'menu:entity', 'sched_conf_entity_menu_setup');
// Add group option
add_group_tool_option('conference', elgg_echo('sched_conf:enableconference'), true);
elgg_extend_view('groups/tool_latest', 'sched_conf/group_module');
// register actions
$action_path = elgg_get_plugins_path() . 'sched_conf/actions/sched_conf';
elgg_register_action('sched_conf/edit', "$action_path/edit.php");
elgg_register_action('sched_conf/delete', "$action_path/delete.php");
}
function sched_conf_pagesetup() {
// a bit of a kludge to check if we are on a listing page
if (elgg_is_logged_in()) {
$url = current_page_url();
if ((strpos($url,'event_calendar/list') !== FALSE)) {
elgg_register_menu_item('title', array(
'name' => 'add_conference',
'href' => 'sched_conf/add/',
'text' => elgg_echo('sched_conf:add_conf_title'),
'class' => 'elgg-button elgg-button-action',
));
} else if (strpos($url,'event_calendar/group') !== FALSE) {
$group_guid = elgg_get_page_owner_guid();
elgg_register_menu_item('title', array(
'name' => 'add_conference',
'href' => "sched_conf/add/".$group_guid,
'text' => elgg_echo('sched_conf:add_conf_title'),
'class' => 'elgg-button elgg-button-action',
));
}
}
}
/**
* Dispatches sched_conf pages.
*
* URLs take the form of
* Schedule a conference: sched_conf/add
* Schedule a group conference: sched_conf/add/<group_guid>
* Edit a conference: sched_conf/edit/<conf_guid>
* List site wide conferences: sched_conf/list/all
* List a user's conferences: sched_conf/list/owner/<username>
* List a group's conferences: sched_conf/list/group/<group_guid>
* View a conference: sched_conf/view/<conf_guid>/<title>
*
* Title is ignored
*
* @param array $page
* @return NULL
*/
function sched_conf_page_handler($page) {
elgg_load_library('elgg:sched_conf');
$page_type = $page[0];
switch ($page_type) {
case 'list':
echo sched_conf_get_page_content_list($page[1],$page[2]);
break;
case 'view':
echo sched_conf_get_page_content_view($page[1]);
break;
case 'add':
case 'edit':
gatekeeper();
echo sched_conf_get_page_content_edit($page_type, $page[1]);
break;
default:
return FALSE;
}
return TRUE;
}
function sched_conf_url_handler($entity) {
elgg_load_library('elgg:sched_conf');
$friendly_title = elgg_get_friendly_title($entity->title);
$event = sched_conf_get_event_for_conference($entity->guid);
return "event_calendar/view/{$event->guid}/$friendly_title";
}
// The current API appears to require that I repeat this although the only change is the handler
function sched_conf_entity_menu_setup($hook, $type, $return, $params) {
if (elgg_in_context('widgets')) {
return $return;
}
elgg_load_library('elgg:sched_conf');
$entity = $params['entity'];
$entity = sched_conf_get_event_for_conference($entity->guid);
$handler = elgg_extract('handler', $params, false);
if ($handler != 'sched_conf') {
return $return;
}
$user_guid = elgg_get_logged_in_user_guid();
$calendar_status = event_calendar_personal_can_manage($entity,$user_guid);
if (($calendar_status === TRUE) || ($calendar_status === 'open')) {
if (event_calendar_has_personal_event($entity->guid,$user_guid)) {
$options = array(
'name' => 'personal_calendar',
'text' => elgg_echo('event_calendar:remove_from_the_calendar_menu_text'),
'title' => elgg_echo('event_calendar:remove_from_my_calendar'),
'href' => elgg_add_action_tokens_to_url("action/event_calendar/remove_personal?guid={$entity->guid}"),
'priority' => 150,
);
$return[] = ElggMenuItem::factory($options);
} else {
if (!event_calendar_is_full($entity->guid) && !event_calendar_has_collision($entity->guid,$user_guid)) {
$options = array(
'name' => 'personal_calendar',
'text' => elgg_echo('event_calendar:add_to_the_calendar_menu_text'),
'title' => elgg_echo('event_calendar:add_to_my_calendar'),
'href' => elgg_add_action_tokens_to_url("action/event_calendar/add_personal?guid={$entity->guid}"),
'priority' => 150,
);
$return[] = ElggMenuItem::factory($options); }
}
} else if (($calendar_status === FALSE) || ($calendar_status === 'closed')) {
if (!event_calendar_has_personal_event($entity->guid,$user_guid) && !check_entity_relationship($user_guid, 'event_calendar_request', $entity->guid)) {
$options = array(
'name' => 'personal_calendar',
'text' => elgg_echo('event_calendar:make_request_title'),
'title' => elgg_echo('event_calendar:make_request_title'),
'href' => elgg_add_action_tokens_to_url("action/event_calendar/request_personal_calendar?guid={$entity->guid}"),
'priority' => 150,
);
$return[] = ElggMenuItem::factory($options);
}
}
$count = event_calendar_get_users_for_event($entity->guid,0,0,true);
if ($count == 1) {
$calendar_text = elgg_echo('event_calendar:personal_event_calendars_link_one');
} else {
$calendar_text = elgg_echo('event_calendar:personal_event_calendars_link',array($count));
}
$options = array(
'name' => 'calendar_listing',
'text' => $calendar_text,
'title' => elgg_echo('event_calendar:users_for_event_menu_title'),
'href' => "event_calendar/display_users/{$entity->guid}",
'priority' => 150,
);
$return[] = ElggMenuItem::factory($options);
/*if (elgg_is_admin_logged_in() && (elgg_get_plugin_setting('allow_featured', 'event_calendar') == 'yes')) {
if ($event->featured) {
add_submenu_item(elgg_echo('event_calendar:unfeature'), $CONFIG->url . "action/event_calendar/unfeature?event_id=".$event_id.'&'.event_calendar_security_fields(), 'eventcalendaractions');
} else {
add_submenu_item(elgg_echo('event_calendar:feature'), $CONFIG->url . "action/event_calendar/feature?event_id=".$event_id.'&'.event_calendar_security_fields(), 'eventcalendaractions');
}
}*/
return $return;
}