Issues (2473)

Branch: master

Security Analysis    no vulnerabilities found

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

mod/event_calendar/start.php (5 issues)

Labels
Severity

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
/**
4
 *  Event calendar plugin
5
 *
6
 * @package event_calendar
7
 * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU Public License version 2
8
 * @author Kevin Jardine <[email protected]>
9
 * @copyright Radagast Solutions 2008
10
 * @link http://radagast.biz/
11
 */
12
13
elgg_register_event_handler('init','system','event_calendar_init');
14
15
function event_calendar_init() {
16
17
	elgg_register_library('elgg:event_calendar', elgg_get_plugins_path() . 'event_calendar/models/model.php');
18
19
	elgg_register_plugin_hook_handler('cron', 'fiveminute', 'event_calendar_handle_reminders_cron', 400);
20
	elgg_register_plugin_hook_handler('entity:url', 'object', 'event_calendar_url');
21
	elgg_register_plugin_hook_handler('prepare', 'notification:create:object:event_calendar', 'event_calendar_prepare_notification');
22
23
	// Register a page handler, so we can have nice URLs
24
	elgg_register_page_handler('event_calendar', 'event_calendar_page_handler');
25
26
	// Register granular notification
27
	elgg_register_notification_event('object', 'event_calendar', array('create'));
28
29
	// Set up site menu
30
	$site_calendar = elgg_get_plugin_setting('site_calendar', 'event_calendar');
31
	if (!$site_calendar || $site_calendar != 'no') {
32
		// add a site navigation item
33
		$item = new ElggMenuItem('event_calendar', elgg_echo('item:object:event_calendar'), 'event_calendar/list/');
34
		elgg_register_menu_item('site', $item);
35
	}
36
	// make event calendar title and description searchable
37
	elgg_register_entity_type('object', 'event_calendar');
38
39
	// make legacy tags searchable
40
	elgg_register_tag_metadata_name('event_tags');
41
42
	// register the plugin's JavaScript
43
	$plugin_js = elgg_get_simplecache_url('js', 'event_calendar/event_calendar');
44
	elgg_register_simplecache_view('js/event_calendar/event_calendar');
45
	elgg_register_js('elgg.event_calendar', $plugin_js);
46
47
	// ajax event summary popup
48
	elgg_register_ajax_view('event_calendar/popup');
49
50
	//add to group profile page
51
	$group_calendar = elgg_get_plugin_setting('group_calendar', 'event_calendar');
52
	if (!$group_calendar || $group_calendar != 'no') {
53
		elgg_register_plugin_hook_handler('register', 'menu:owner_block', 'event_calendar_owner_block_menu');
54
		$group_profile_display = elgg_get_plugin_setting('group_profile_display', 'event_calendar');
55
		elgg_extend_view('groups/tool_latest', 'event_calendar/group_module');
56
	}
57
58
	//add to the css
59
	elgg_extend_view('css/elgg', 'event_calendar/css');
60
	$event_calendar_listing_format = elgg_get_plugin_setting('listing_format', 'event_calendar');
61
	
62
	if (elgg_is_active_plugin('event_poll') || ($event_calendar_listing_format == 'full')) {
63
		elgg_extend_view('css/elgg', 'fullcalendar/css');
64
		$plugin_js = elgg_get_simplecache_url('js', 'event_calendar/fullcalendar');
65
		elgg_register_simplecache_view('js/event_calendar/fullcalendar');
66
		elgg_register_js('elgg.full_calendar', $plugin_js);
67
	}
68
69
	//add a widget
70
	elgg_register_widget_type('event_calendar', elgg_echo("event_calendar:widget_title"), elgg_echo('event_calendar:widget:description'));
71
72
	// Index page and group profile page widgets and widget title urls if Widget Manager plugin is available
73
	if (elgg_is_active_plugin('widget_manager')) {
74
		//add index widget for Widget Manager plugin
75
		elgg_register_widget_type('index_event_calendar', elgg_echo("event_calendar:widget_title"), elgg_echo('event_calendar:widget:description'), array("index"));
76
		elgg_register_widget_type('groups_event_calendar', elgg_echo("event_calendar:widget_title"), elgg_echo('event_calendar:widget:description'), array("groups"));
77
		//register title urls for widgets
78
		elgg_register_plugin_hook_handler("entity:url", "object", "event_calendar_widget_urls");
79
	}
80
81
	// add the event calendar group tool option
82
	$event_calendar_group_default = elgg_get_plugin_setting('group_default', 'event_calendar');
83
	if (!$event_calendar_group_default || ($event_calendar_group_default == 'yes')) {
84
		add_group_tool_option('event_calendar', elgg_echo('event_calendar:enable_event_calendar'), true);
85
	} else {
86
		add_group_tool_option('event_calendar', elgg_echo('event_calendar:enable_event_calendar'), false);
87
	}
88
89
	// if autogroup is set, listen and respond to join/leave events
90
	if (elgg_get_plugin_setting('autogroup', 'event_calendar') == 'yes') {
91
		elgg_register_event_handler('join', 'group', 'event_calendar_handle_join');
92
		elgg_register_event_handler('leave', 'group', 'event_calendar_handle_leave');
93
	}
94
95
	// entity menu
96
	elgg_register_plugin_hook_handler('register', 'menu:entity', 'event_calendar_entity_menu_setup');
97
	elgg_register_plugin_hook_handler('prepare', 'menu:entity', 'event_calendar_entity_menu_prepare');
98
99
	// register actions
100
	$action_path = elgg_get_plugins_path() . 'event_calendar/actions/event_calendar';
101
102
	elgg_register_action("event_calendar/edit","$action_path/edit.php");
103
	elgg_register_action("event_calendar/delete","$action_path/delete.php");
104
	elgg_register_action("event_calendar/add_personal","$action_path/add_personal.php");
105
	elgg_register_action("event_calendar/add_ics","$action_path/add_ics.php");
106
	elgg_register_action("event_calendar/remove_personal","$action_path/remove_personal.php");
107
	elgg_register_action("event_calendar/request_personal_calendar","$action_path/request_personal_calendar.php");
108
	elgg_register_action("event_calendar/toggle_personal_calendar","$action_path/toggle_personal_calendar.php");
109
	elgg_register_action("event_calendar/killrequest","$action_path/killrequest.php");
110
	elgg_register_action("event_calendar/addtocalendar","$action_path/addtocalendar.php");
111
	elgg_register_action("event_calendar/add_to_group","$action_path/add_to_group.php");
112
	elgg_register_action("event_calendar/remove_from_group","$action_path/remove_from_group.php");
113
	elgg_register_action("event_calendar/add_to_group_members","$action_path/add_to_group_members.php");
114
	elgg_register_action("event_calendar/remove_from_group_members","$action_path/remove_from_group_members.php");
115
	elgg_register_action("event_calendar/manage_subscribers","$action_path/manage_subscribers.php");
116
	elgg_register_action("event_calendar/modify_full_calendar","$action_path/modify_full_calendar.php");
117
	elgg_register_action("event_calendar/join_conference","$action_path/join_conference.php");
118
	elgg_register_action("event_calendar/upgrade", "$action_path/upgrade.php", 'admin');
119
120
	// check for pending event_calendar upgrades when a site upgrade is made
121
	elgg_register_event_handler('upgrade', 'system', 'event_calendar_check_pending_upgrades');
122
}
123
124
/**
125
 * Add a menu item to an ownerblock
126
 */
127 View Code Duplication
function event_calendar_owner_block_menu($hook, $type, $return, $params) {
128
	elgg_load_library('elgg:event_calendar');
129
	if (elgg_instanceof($params['entity'], 'group')) {
130
		if (event_calendar_activated_for_group($params['entity'])) {
131
			$url = "event_calendar/group/{$params['entity']->guid}";
132
			$item = new ElggMenuItem('event_calendar', elgg_echo('event_calendar:group'), $url);
133
			$return[] = $item;
134
		}
135
	} else if (elgg_instanceof($params['entity'], 'user')) {
136
		$url = "event_calendar/owner/{$params['entity']->username}";
137
		$item = new ElggMenuItem('event_calendar', elgg_echo('event_calendar:widget_title'), $url);
138
		$return[] = $item;
139
	}
140
141
	return $return;
142
}
143
144
/**
145
 * Set url for event_calendar objects
146
 *
147
 * @param string $hook   entity:url
148
 * @param string $type   object
149
 * @param string $url    Current URL
150
 * @param array  $params Hook parameters
151
 * @return string The URL
152
 */
153 View Code Duplication
function event_calendar_url($hook, $type, $url, $params) {
154
	$entity = $params['entity'];
155
156
	if (!elgg_instanceof($entity, 'object', 'event_calendar')) {
157
		return $url;
158
	}
159
160
	$friendly_title = elgg_get_friendly_title($entity->title);
161
	return "event_calendar/view/{$entity->guid}/$friendly_title";
162
}
163
164
/**
165
 * Dispatches event calendar pages.
166
 *
167
 * URLs take the form of
168
 *  Site event calendar:			event_calendar/list/<start_date>/<display_mode>/<filter_context>/<region>
169
 *  Single event:       			event_calendar/view/<event_guid>/<title>
170
 *  New event:        				event_calendar/add
171
 *  Edit event:       				event_calendar/edit/<event_guid>
172
 *  Group event calendar:  			event_calendar/group/<group_guid>/<start_date>/<display_mode>/<filter_context>/<region>
173
 *  Add group event:   				event_calendar/add/<group_guid>
174
 *  Review requests:				event_calendar/review_requests/<event_guid>
175
 *  Display event subscribers:		event_calendar/display_users/<event_guid>
176
 *  Events for a user's calendar:	event_calendar/owner/<username>/<start_date>/<display_mode>/<filter_context>/<region>
177
 *
178
 * Title is ignored
179
 *
180
 * @param array $page
181
 * @return null
182
 */
183
function event_calendar_page_handler($page) {
184
185
	elgg_load_library('elgg:event_calendar');
186
	$page_type = $page[0];
187
	switch ($page_type) {
188
		case 'list':
189 View Code Duplication
			if (isset($page[1])) {
190
				$start_date = $page[1];
191
				if (isset($page[2])) {
192
					$display_mode = $page[2];
193
					if (isset($page[3])) {
194
						$filter_mode = $page[3];
195
						if (isset($page[4])) {
196
							$region = $page[4];
197
						} else {
198
							$region = '';
199
						}
200
					} else {
201
						$filter_mode = '';
202
					}
203
				} else {
204
					$display_mode = '';
205
				}
206
			} else {
207
				$start_date = 0;
208
			}
209
			echo event_calendar_get_page_content_list($page_type, 0, $start_date, $display_mode, $filter_mode, $region);
0 ignored issues
show
The variable $display_mode does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
The variable $filter_mode does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
The variable $region does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
210
			break;
211
		case 'view':
212
			echo event_calendar_get_page_content_view($page[1]);
213
			break;
214
		case 'display_users':
215
			echo event_calendar_get_page_content_display_users($page[1]);
216
			break;
217
		case 'manage_users':
218
			echo event_calendar_get_page_content_manage_users($page[1]);
219
			break;
220
		case 'schedule':
221
		case 'add':
222
			if (isset($page[1])) {
223
				group_gatekeeper();
224
				$group_guid = $page[1];
225
			} else {
226
				gatekeeper();
227
				$group_guid = 0;
228
			}
229
			echo event_calendar_get_page_content_edit($page_type, $group_guid, $page[2]);
230
			break;
231
		case 'edit':
232
			gatekeeper();
233
			echo event_calendar_get_page_content_edit($page_type, $page[1]);
234
			break;
235
		case 'group':
236
			group_gatekeeper();
237
			if (isset($page[1])) {
238
				$group_guid = $page[1];
239 View Code Duplication
				if (isset($page[2])) {
240
					$start_date = $page[2];
241
					if (isset($page[3])) {
242
					$display_mode = $page[3];
243
					if (isset($page[4])) {
244
						$filter_mode = $page[4];
245
						if (isset($page[5])) {
246
							$region = $page[5];
247
						} else {
248
							$region = '';
249
						}
250
					} else {
251
						$filter_mode = '';
252
					}
253
					} else {
254
						$display_mode = '';
255
					}
256
				} else {
257
					$start_date = '';
258
				}
259
			} else {
260
				$group_guid = 0;
261
			}
262
			echo event_calendar_get_page_content_list($page_type, $group_guid, $start_date, $display_mode, $filter_mode, $region);
0 ignored issues
show
The variable $start_date does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
263
			break;
264
		case 'owner':
265
			if (isset($page[1])) {
266
				$username = $page[1];
267
				$user = get_user_by_username($username);
268
				$user_guid = $user->guid;
269 View Code Duplication
				if (isset($page[2])) {
270
					$start_date = $page[2];
271
					if (isset($page[3])) {
272
					$display_mode = $page[3];
273
					if (isset($page[4])) {
274
						$filter_mode = $page[4];
275
						if (isset($page[5])) {
276
							$region = $page[5];
277
						} else {
278
							$region = '';
279
						}
280
					} else {
281
						$filter_mode = '';
282
					}
283
					} else {
284
						$display_mode = '';
285
					}
286
				} else {
287
					$start_date = '';
288
				}
289
			} else {
290
				$group_guid = 0;
291
			}
292
			echo event_calendar_get_page_content_list($page_type, $user_guid, $start_date, $display_mode, $filter_mode, $region);
0 ignored issues
show
The variable $user_guid does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
293
			break;
294
		case 'review_requests':
295
			gatekeeper();
296
			echo event_calendar_get_page_content_review_requests($page[1]);
297
			break;
298
		case 'get_fullcalendar_events':
299
			echo event_calendar_get_page_content_fullcalendar_events($page[1], $page[2], $page[3], $page[4]);
300
			break;
301
		default:
302
			return false;
303
	}
304
	return true;
305
}
306
307
/**
308
 * Add particular event calendar links/info to entity menu
309
 */
310
function event_calendar_entity_menu_setup($hook, $type, $return, $params) {
311
	if (elgg_in_context('widgets_calendar')) {
312
		return $return;
313
	}
314
315
	$entity = $params['entity'];
316
	$handler = elgg_extract('handler', $params, false);
317
	if ($handler != 'event_calendar') {
318
		return $return;
319
	}
320 View Code Duplication
	if (elgg_is_active_plugin('event_poll') && $entity->canEdit() && $entity->schedule_type == 'poll') {
321
		$options = array(
322
			'name' => 'schedule',
323
			'text' => elgg_echo('event_poll:schedule_button'),
324
			'title' => elgg_echo('event_poll:schedule_button'),
325
			'href' => 'event_poll/vote/'.$entity->guid,
326
			'priority' => 150,
327
		);
328
		$return[] = ElggMenuItem::factory($options);
329
	}
330
	$user_guid = elgg_get_logged_in_user_guid();
331
	if ($user_guid) {
332
		$calendar_status = event_calendar_personal_can_manage($entity, $user_guid);
333
		if ($calendar_status == 'open') {
334
			if (event_calendar_has_personal_event($entity->guid, $user_guid)) {
335
				$options = array(
336
					'name' => 'personal_calendar',
337
					'text' => elgg_echo('event_calendar:remove_from_the_calendar_menu_text'),
338
					'title' => elgg_echo('event_calendar:remove_from_my_calendar'),
339
					'href' => elgg_add_action_tokens_to_url("action/event_calendar/remove_personal?guid={$entity->guid}"),
340
					'priority' => 150,
341
				);
342
				$return[] = ElggMenuItem::factory($options);
343 View Code Duplication
			} else {
344
				if (!event_calendar_is_full($entity->guid) && !event_calendar_has_collision($entity->guid, $user_guid)) {
345
					$options = array(
346
						'name' => 'personal_calendar',
347
						'text' => elgg_echo('event_calendar:add_to_the_calendar_menu_text'),
348
						'title' => elgg_echo('event_calendar:add_to_my_calendar'),
349
						'href' => elgg_add_action_tokens_to_url("action/event_calendar/add_personal?guid={$entity->guid}"),
350
						'priority' => 150,
351
					);
352
					$return[] = ElggMenuItem::factory($options);
353
				}
354
			}
355
		} else if ($calendar_status == 'closed') {
356 View Code Duplication
			if (!event_calendar_has_personal_event($entity->guid, $user_guid) && !check_entity_relationship($user_guid, 'event_calendar_request', $entity->guid)) {
357
				$options = array(
358
					'name' => 'personal_calendar',
359
					'text' => elgg_echo('event_calendar:make_request_title'),
360
					'title' => elgg_echo('event_calendar:make_request_title'),
361
					'href' => elgg_add_action_tokens_to_url("action/event_calendar/request_personal_calendar?guid={$entity->guid}"),
362
					'priority' => 150,
363
				);
364
				$return[] = ElggMenuItem::factory($options);
365
			}
366
		}
367
	}
368
369
	return $return;
370
}
371
372
function event_calendar_entity_menu_prepare($hook, $type, $return, $params) {
373
	// remove access level from listings
374
	if (elgg_in_context('event_calendar') && !elgg_in_context('event_calendar:view')) {
375
		$new_return = array();
376
		if (isset($return['default']) && is_array($return['default'])) {
377
			foreach($return['default'] as $item) {
378
				if ($item->getName() != 'access') {
379
					$new_return[] = $item;
380
				}
381
			}
382
		}
383
		$return['default'] = $new_return;
384
	}
385
386
	return $return;
387
}
388
389
function event_calendar_widget_urls($hook_name, $entity_type, $return_value, $params){
390
	$result = $return_value;
391
	$widget = $params["entity"];
392
393
	if(empty($result) && ($widget instanceof ElggWidget)) {
394
		$owner = $widget->getOwnerEntity();
395
396
		switch($widget->handler) {
397
			case "event_calendar":
398
				$result = "/event_calendar/owner/" . $owner->username;
399
				break;
400
			case "index_event_calendar":
401
				$result = "/event_calendar/list";
402
				break;
403
			case "groups_event_calendar":
404
				if($owner instanceof ElggGroup){
405
					$result = "/event_calendar/group/" . $owner->guid;
406
				} else {
407
					$result = "/event_calendar/list";
408
				}
409
				break;
410
		}
411
	}
412
	return $result;
413
}
414
415 View Code Duplication
function event_calendar_handle_join($event, $object_type, $object) {
416
	elgg_load_library('elgg:event_calendar');
417
	$group = $object['group'];
418
	$user = $object['user'];
419
	$user_guid = $user->getGUID();
420
	$events = event_calendar_get_events_for_group($group->getGUID());
421
	foreach ($events as $event) {
422
		$event_id = $event->getGUID();
423
		event_calendar_add_personal_event($event_id, $user_guid);
424
	}
425
}
426
427 View Code Duplication
function event_calendar_handle_leave($event, $object_type, $object) {
428
	elgg_load_library('elgg:event_calendar');
429
	$group = $object['group'];
430
	$user = $object['user'];
431
	$user_guid = $user->getGUID();
432
	$events = event_calendar_get_events_for_group($group->getGUID());
433
	foreach ($events as $event) {
434
		$event_id = $event->getGUID();
435
		event_calendar_remove_personal_event($event_id, $user_guid);
436
	}
437
}
438
439
function event_calendar_handle_reminders_cron() {
440
	elgg_load_library('elgg:event_calendar');
441
	event_calendar_queue_reminders();
442
}
443
444
function event_calendar_invalidate_cache($hook, $type, $return, $params){
445
  if(isset($params["plugin"]) && ($params["plugin"]->getID() == "event_calendar")){
446
    elgg_invalidate_simplecache();
447
  }
448
}
449
450
/**
451
 * Prepare a notification message about a new event
452
 *
453
 * @param string $hook         Hook name
454
 * @param string $type         Hook type
455
 * @param object $notification The notification to prepare
456
 * @param array  $params       Hook parameters
457
 * @return object Modified notification
458
 */
459
function event_calendar_prepare_notification($hook, $type, $notification, $params) {
460
    $entity = $params['event']->getObject();
461
    $owner = $params['event']->getActor();
462
    $language = $params['language'];
463
464
    // Title for the notification
465
    $notification->subject = elgg_echo('event_calendar:notify:subject', array($entity->title), $language);
466
467
    // Message body for the notification
468
    $notification->body = elgg_echo('event_calendar:notify:body', array(
469
        $owner->name,
470
        $entity->title,
471
        $entity->description,
472
        $entity->getURL()
473
    ), $language);
474
475
    // The summary text is used e.g. by the site_notifications plugin
476
    $notification->summary = elgg_echo('event_calendar:notify:summary', array($entity->title), $language);
477
478
    return $notification;
479
}
480
481
function event_calendar_check_pending_upgrades() {
482
	elgg_load_library('elgg:event_calendar');
483
	elgg_delete_admin_notice('event_calendar_admin_notice_pending_upgrades');
484
	if (event_calendar_is_upgrade_available()) {
485
		$message = elgg_echo('event_calendar:admin_notice_pending_upgrades', array(elgg_normalize_url('admin/plugin_settings/event_calendar')));
486
		elgg_add_admin_notice('event_calendar_admin_notice_pending_upgrades', $message);
487
	}
488
}
489
490
elgg_register_plugin_hook_handler("setting", "plugin", "event_calendar_invalidate_cache");
491