Completed
Push — edit_timezone ( d407c0 )
by
unknown
08:14
created

start.php ➔ _elgg_set_timezone_page()   B

Complexity

Conditions 7
Paths 8

Size

Total Lines 24

Duplication

Lines 24
Ratio 100 %

Importance

Changes 0
Metric Value
cc 7
nc 8
nop 0
dl 24
loc 24
rs 8.6026
c 0
b 0
f 0
1
<?php
2
/**
3
 * WET 4 Theme plugin
4
 *
5
 * @package wet4Theme
6
 */
7
8
elgg_register_event_handler('init', 'system', 'wet4_theme_init');
9
10
function wet4_theme_init()
11
{
12
13
	/* cyu - global change to sidebars, display when it is not the crawler
14
	 * the following batch of elgg_extend_view overwrites the elements in the page
15
	 */
16
	elgg_extend_view('page/elements/sidebar', 'page/elements/gsa_view_start', 1);
17
	elgg_extend_view('page/elements/sidebar', 'page/elements/gsa_view_end', 1000);
18
19
	elgg_extend_view('page/elements/footer', 'page/elements/gsa_view_start', 1);
20
	elgg_extend_view('page/elements/footer', 'page/elements/gsa_view_end', 1000);
21
22
	elgg_extend_view('navigation/breadcrumbs', 'page/elements/gsa_view_start', 1);
23
	elgg_extend_view('navigation/breadcrumbs', 'page/elements/gsa_view_end', 1000);
24
25
	elgg_extend_view('object/widget/elements/content', 'page/elements/gsa_view_start', 1);
26
	elgg_extend_view('object/widget/elements/content', 'page/elements/gsa_view_end', 1000);
27
28
	// cyu - are we overriding the settings page handler? (note: the one in this plugin does nothing)
29
	elgg_unregister_page_handler('settings');
30
	elgg_register_page_handler('settings', '_elgg_wet_user_settings_page_handler');
31
32
33
	//reload groups library to have our sidebar changes
34
35
	elgg_register_library('GCconnex_logging', elgg_get_plugins_path() . 'wet4/lib/logging.php');
36
	elgg_register_library('GCconnex_display_in_language', elgg_get_plugins_path() . 'wet4/lib/translate_display.php');
37
	elgg_register_library('wet:custom_core', elgg_get_plugins_path() . 'wet4/lib/custom_core.php');
38
39
	elgg_load_library('GCconnex_logging');
40
	elgg_load_library('GCconnex_display_in_language');
41
	elgg_load_library('wet:custom_core');
42
	//get rid of reply icon on river menu
43
	elgg_unregister_plugin_hook_handler('register', 'menu:river', 'discussion_add_to_river_menu');
44
45
	//change icons for blog entity
46
	elgg_unregister_plugin_hook_handler("register", "menu:entity", array("\ColdTrick\BlogTools\EntityMenu", "register"));
47
	elgg_register_plugin_hook_handler("register", "menu:entity", 'wet4_blog_entity_menu');
48
	//Friendly Time - Nick
49
	elgg_register_plugin_hook_handler('format', 'friendly:time', 'enhanced_friendly_time_hook');
50
	elgg_register_event_handler('pagesetup', 'system', 'wet4_theme_pagesetup', 1000);
51
	elgg_register_event_handler('pagesetup', 'system', 'wet4_riverItem_remove');
52
	elgg_unregister_event_handler('pagesetup', 'system', 'messages_notifier');
53
54
	elgg_register_plugin_hook_handler('register', 'menu:entity', 'wet4_elgg_entity_menu_setup');
55
	elgg_register_plugin_hook_handler('register', 'menu:entity', 'wet4_group_entity_menu_setup');
56
	elgg_register_plugin_hook_handler('register', 'menu:widget', 'wet4_widget_menu_setup');
57
	elgg_register_plugin_hook_handler('register', 'menu:page', 'wet4_elgg_page_menu_setup');
58
	elgg_register_plugin_hook_handler('register', 'menu:river', 'wet4_elgg_river_menu_setup');
59
	elgg_register_plugin_hook_handler('register', 'menu:title', 'consistent_menu_styler');
60
		elgg_register_plugin_hook_handler('register', 'menu:title2', 'consistent_menu_styler_alt');
61
62
	elgg_register_plugin_hook_handler('register', 'menu:entity', 'wet4_likes_entity_menu_setup', 400);
63
64
  //questions modifications
65
  elgg_register_action('object/question/save', elgg_get_plugins_path()."wet4/actions/object/question/save.php"); //add english/french toggle
66
  elgg_register_page_handler('questions', 'wet_questions_page_handler');
67
  elgg_unregister_plugin_hook_handler('register', 'menu:filter', 'questions_filter_menu_handler');
68
  elgg_register_plugin_hook_handler('register', 'menu:filter', 'wet_questions_filter_menu_handler');
69
70
	// theme specific CSS
71
	elgg_extend_view('css/elgg', 'wet4_theme/css');
72
	elgg_extend_view('css/elgg', 'wet4_theme/custom_css');
73
74
	//extending views to pass metadata to head.php
75
	elgg_extend_view("object/elements/full", "wet4_theme/track_page_entity", 451);
76
	elgg_extend_view('profile/wrapper', 'wet4_theme/pass');
77
78
	elgg_extend_view('forms/notificationsettings/save', 'forms/notificationsettings/groupsave');
79
80
	//register a page handler for friends
81
	elgg_unregister_page_handler('friends'); //unregister core page handler
82
	elgg_unregister_page_handler('dashboard'); //unregister dashboard handler to make our own
83
	elgg_register_page_handler('dashboard', 'wet4_dashboard_page_handler');
84
	elgg_register_page_handler('friends', '_wet4_friends_page_handler'); //register new page handler for data tables
85
	elgg_register_page_handler('friendsof', '_wet4_friends_page_handler');
86
	elgg_register_page_handler('activity', 'activity_page_handler');
87
	elgg_unregister_page_handler('messages');
88
	elgg_register_page_handler('messages', 'wet4_messages_page_handler');
89
90
	elgg_register_page_handler('collections', 'wet4_collections_page_handler');
91
92
	//register login as menu item into user menu
93
	elgg_register_event_handler('pagesetup', 'system', 'login_as_add_user_menu_link');
94
95
	//datatables css file
96
	elgg_extend_view('css/elgg', '//cdn.datatables.net/1.10.10/css/jquery.dataTables.css');
97
98
	elgg_register_simplecache_view('wet4/validate.js');
99
  elgg_require_js('wet4/validate');
100
101
	//elgg_unextend_view('page/elements/header', 'search/header');
102
	//elgg_extend_view('page/elements/sidebar', 'search/header', 0);
103
104
    //load datatables
105
    elgg_require_js("wet4/test");
106
107
    //the wire reply and thread
108
    elgg_register_ajax_view("thewire_tools/reply");
109
	  elgg_register_ajax_view("thewire_tools/thread");
110
		//viewing phot on newsfeed
111
    elgg_register_ajax_view("ajax/photo");
112
		//edit colleague circle
113
    elgg_register_ajax_view("friend_circle/edit");
114
		//verfiy department pop up
115
    elgg_register_ajax_view("verify_department/verify_department");
116
117
    //file tools
118
    elgg_register_ajax_view("file_tools/move");
119
    //message preview
120
    elgg_register_ajax_view("messages/message_preview");
121
122
	//the wire reply and thread
123
	elgg_register_ajax_view("thewire_tools/reply");
124
	elgg_register_ajax_view("thewire_tools/thread");
125
	//viewing phot on newsfeed
126
	elgg_register_ajax_view("ajax/photo");
127
	//edit colleague circle
128
	elgg_register_ajax_view("friend_circle/edit");
129
	//verfiy department pop up
130
	elgg_register_ajax_view("verify_department/verify_department");
131
132
	//file tools
133
	elgg_register_ajax_view("file_tools/move");
134
	//message preview
135
	elgg_register_ajax_view("messages/message_preview");
136
137
	//Group AJAX loading view
138
	elgg_extend_view("js/elgg", "js/wet4/discussion_quick_start");
139
140
  elgg_extend_view("js/elgg","js/wet4/language_ajax");
141
  elgg_extend_view("js/elgg","js/wet4/rotate_ajax");
142
143
  //Notification / Messages dropdown view
144
  elgg_register_ajax_view('ajax/notif_dd');
145
146
	elgg_register_plugin_hook_handler('head', 'page', 'wet4_theme_setup_head');
147
	elgg_register_plugin_hook_handler('register', 'menu:owner_block', 'my_owner_block_handler');
148
	elgg_register_plugin_hook_handler('register', 'menu:title', 'my_title_menu_handler');
149
	elgg_register_plugin_hook_handler('register', 'menu:filter', 'my_filter_menu_handler');
150
	elgg_register_plugin_hook_handler('register', 'menu:site', 'my_site_menu_handler');
151
	elgg_register_plugin_hook_handler('register', 'menu:river', 'river_handler');
152
153
	elgg_register_simplecache_view('wet4/test.js');
154
155
	//added since goups didnt have this action but called it
156
	elgg_register_action("discussion_reply/delete", elgg_get_plugins_path() . "/wet4/actions/discussion/reply/delete.php");
157
158
159
    //if(elgg_is_active_plugin('au_subgroups')){
160
    //    elgg_register_action("groups/invite", elgg_get_plugins_path() . "/wet4/actions/groups/invite.php");
161
    //}
162
 elgg_register_action("comment/join", elgg_get_plugins_path() . "groups/actions/groups/membership/join.php");
163
164
  elgg_register_action("file/move_folder", elgg_get_plugins_path() . "/wet4/actions/file/move.php");
165
  elgg_register_action("friends/collections/edit", elgg_get_plugins_path() . "/wet4/actions/friends/collections/edit.php");
166
  elgg_register_action("login", elgg_get_plugins_path() . "/wet4/actions/login.php", "public");
167
  elgg_register_action("widgets/delete", elgg_get_plugins_path() . "/wet4/actions/widgets/delete.php");
168
  elgg_register_action("user/requestnewpassword", elgg_get_plugins_path() . "/wet4/actions/user/requestnewpassword.php", "public");
169
  elgg_register_action('logout_as', elgg_get_plugins_path() . '/wet4/actions/logout_as.php'); //login as out
170
  elgg_register_action("question/autocomplete", elgg_get_plugins_path() . "/wet4/actions/object/question/autocomplete.php");
171
  elgg_register_action("deptactivity/filter", elgg_get_plugins_path() . "/wet4/actions/deptactivity/filter.php");
172
173
	//Verify the department action
174
	elgg_register_action("department/verify_department", elgg_get_plugins_path() . "/wet4/actions/department/verify_department.php");
175
176
	// bilingual content upgrade script
177
	elgg_register_action("wet4/update_to_json", elgg_get_plugins_path() . "/wet4/actions/bilingual_content/update_to_json.php");
178
179
	// event calendar content upgrade script
180
	elgg_register_action("wet4/merge_description", elgg_get_plugins_path() . "/wet4/actions/event_description/merge_description.php");
181
		
182
	// non-members do not get visible links to RSS feeds
183
	if (!elgg_is_logged_in()) {
184
		elgg_unregister_plugin_hook_handler('output:before', 'layout', 'elgg_views_add_rss_link');
185
	}
186
187
	// new widgets
188
	//registering wet 4 activity widget
189
190
	elgg_register_widget_type('suggested_friends', elgg_echo('sf:suggcolleagues'), elgg_echo('sf:suggcolleagues'), array('custom_index_widgets'), false);
191
	elgg_register_widget_type('feature_tour', 'feature_tour', 'feature_tour', array('custom_index_widgets'), false);
192
193
	if (elgg_is_logged_in()) {//for my the my groups widget on the home page
194
		$mygroups_title = elgg_echo('wet_mygroups:my_groups');
195
	} else {
196
		$mygroups_title = elgg_echo('wet_mygroups:my_groups_nolog');
197
	}
198
	//WET my groups widget
199
	elgg_register_widget_type('wet_mygroups_index', $mygroups_title, 'My Groups Index', array('custom_index_widgets'), true);
200
	elgg_register_widget_type('most_liked', elgg_echo('activity:module:weekly_likes'), elgg_echo('activity:module:weekly_likes'), array('dashboard','custom_index_widgets'), true);
201
202
203
	//Temp fix for river widget
204
	elgg_unregister_widget_type("group_river_widget");
205
206
	//extend views of plugin files to remove unwanted menu items
207
	$active_plugins = elgg_get_plugins();
208
	foreach ($active_plugins as $plugin) {
209
		$plugin_id = $plugin->getID();
210
		if (elgg_view_exists("usersettings/$plugin_id/edit") || elgg_view_exists("plugins/$plugin_id/usersettings")) {
211
			elgg_extend_view("usersettings/$plugin_id/edit", "forms/usersettings/menus");
212
			elgg_extend_view("plugins/$plugin_id/usersettings", "forms/usersettings/menus");
213
		}
214
	}
215
	elgg_extend_view("core/settings/statistics", "forms/usersettings/menus");
216
	elgg_extend_view('forms/account/settings', 'core/settings/account/landing_page');
217
218
219
	//set up metadata for user's landing page preference
220
	if (elgg_is_logged_in()) {
221
		$user = elgg_get_logged_in_user_entity();
222
		if (!isset($user->landingpage)) {
223
			$user->landingpage = 'news';
224
		}
225
	}
226
227
	//save new user settings on landing page
228
	elgg_register_plugin_hook_handler('usersettings:save', 'user', '_elgg_set_landing_page');
229
230
231
	elgg_register_page_handler('groups_autocomplete', 'groups_autocomplete');
232
233
234
	//newsfeed-like department pages
235
	if (elgg_is_logged_in() && elgg_get_plugin_setting('deptActivity', 'wet4')) {
236
237
		elgg_register_ajax_view('ajax/deptactivity_check');
238
		elgg_register_ajax_view('ajax/deptactivity_items');
239
		elgg_register_page_handler('department', 'department_page_handler');
240
241
		if (elgg_is_active_plugin('gc_newsfeed')) {
242
            elgg_extend_view('widgets/stream_newsfeed_index/content', 'dept_activity/tabs', 451);
243
            elgg_extend_view('widgets/newsfeed/content', 'dept_activity/tabs', 451);
244
		}
245
	}
246
247
    /// replacing friend-picker in email to group members
248
    elgg_register_action('wet4/group_tools/retrieve_group_members', elgg_get_plugins_path().'/wet4/actions/group_tools/retrieve_group_members.php');
249
    elgg_register_js('cluster-js-min', 'mod/wet4/vendors/clusterize.js/clusterize.min.js');
250
    elgg_register_js('cluster-js', 'mod/wet4/vendors/clusterize.js/clusterize.js');
251
252
	register_plugin_hook('format', 'friendly:title', 'wet_seo_friendly_urls');
253
254
255
	elgg_register_plugin_hook_handler('register', 'menu:site', 'remove_menu_item_handler');
256
257
	// Removing the "All site pages" from the main menu
258
	elgg_unregister_menu_item('site', 'file');
259
	elgg_unregister_menu_item('site', 'polls');
260
	elgg_unregister_menu_item('site', 'event_calendar');
261
	elgg_unregister_menu_item('site', 'photos');
262
	elgg_unregister_menu_item('site', 'bookmarks');
263
	elgg_unregister_menu_item('site', 'activity');
264
265
}
266
function remove_menu_item_handler($hook, $type, $menu, $params){
267
268
	foreach ($menu as $key => $item){
269
		if ($item->getName() == 'mission_main'){
270
			unset($menu[$key]);
271
		}
272
	}
273
	return $menu;
274
275
}
276
277
global $CONFIG;
278
$dbprefix = elgg_get_config('dbprefix');
279
// user default access if enabled
280
if ($CONFIG->remove_logged_in) {
281
	$query = "UPDATE {$dbprefix}entities SET access_id = 2 WHERE access_id = 1";//change access logged in to public
282
	update_data($query);
283
}
284
285
function department_page_handler()
286
{
287
	require_once elgg_get_plugins_path() . 'wet4/pages/department/activity.php';
288
	return true;
289
}
290
291
/*
292
 * groups_autocomplete
293
 * loads library for groups autocomplete in group creation form
294
 */
295
function groups_autocomplete()
296
{
297
	require_once elgg_get_plugins_path() . 'wet4/lib/groups_autocomplete.php';
298
	return true;
299
}
300
301
302
303
304
function _elgg_wet_user_settings_page_handler($page)
305
{
306
	global $CONFIG;
307
308
	if (!isset($page[0])) {
309
		$page[0] = 'user';
310
	}
311
312 View Code Duplication
	if (isset($page[1])) {
313
		$user = get_user_by_username($page[1]);
314
		elgg_set_page_owner_guid($user->guid);
315
	} else {
316
		$user = elgg_get_logged_in_user_entity();
317
		elgg_set_page_owner_guid($user->guid);
318
	}
319
320
	elgg_push_breadcrumb(elgg_echo('settings'), "settings/user/$user->username");
321
322
	switch ($page[0]) {
323
		case 'notifications':
324
			elgg_push_breadcrumb(elgg_echo('cp_notifications:name'));
325
			$path = elgg_get_plugins_path() . "/cp_notifications/" . "pages/cp_notifications/notification_setting.php";
326
			break;
327
		case 'statistics':
328
			elgg_push_breadcrumb(elgg_echo('usersettings:statistics:opt:linktext'));
329
			$path = $CONFIG->path . "pages/settings/statistics.php";
330
			break;
331
		case 'user':
332
			$path = $CONFIG->path . "pages/settings/account.php";
333
			break;
334
	}
335
336
	if (isset($path)) {
337
		require $path;
338
		return true;
339
	}
340
	return false;
341
}
342
343
344
345
346
/*
347
 * activity_page_handler
348
 * Override activity page handler
349
 */
350
function activity_page_handler($page)
351
{
352
	elgg_set_page_owner_guid(elgg_get_logged_in_user_guid());
353
354
	// make a URL segment available in page handler script
355
	$page_type = elgg_extract(0, $page, 'all');
356
	$page_type = preg_replace('[\W]', '', $page_type);
357 View Code Duplication
	if ($page_type == 'owner') {
358
		elgg_gatekeeper();
359
		$page_username = elgg_extract(1, $page, '');
360
		if ($page_username == elgg_get_logged_in_user_entity()->username) {
361
			$page_type = 'mine';
362
		} else {
363
			set_input('subject_username', $page_username);
364
		}
365
	}
366
	set_input('page_type', $page_type);
367
	@include(dirname(__FILE__) . "/pages/river.php");
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
368
	return true;
369
}
370
371
372
/*
373
 * _elgg_set_landing_page
374
 * Sets landing page from user settings
375
 */
376 View Code Duplication
function _elgg_set_landing_page()
377
{
378
	$page = strip_tags(get_input('landingpage'));
379
	$user_guid = get_input('guid');
380
381
	if ($user_guid) {
382
		$user = get_user($user_guid);
383
	} else {
384
		$user = elgg_get_logged_in_user_entity();
385
	}
386
387
	if ($user && $user->canEdit() && $page) {
388
		if ($page != $user->name) {
389
			$user->landingpage = $page;
390
			if ($user->save()) {
391
				return true;
392
			}
393
		} else {
394
			// no change
395
			return null;
396
		}
397
	}
398
	return false;
399
}
400
401 View Code Duplication
function _elgg_set_timezone_page()
402
{
403
	$page = strip_tags(get_input('new_timezone'));
404
	$user_guid = get_input('guid');
405
406
	if ($user_guid) {
407
		$user = get_user($user_guid);
408
	} else {
409
		$user = elgg_get_logged_in_user_entity();
410
	}
411
412
	if ($user && $user->canEdit() && $page) {
413
		if ($page != $user->name) {
414
			$user->new_timezone = $page;
415
			if ($user->save()) {
416
				return true;
417
			}
418
		} else {
419
			// no change
420
			return null;
421
		}
422
	}
423
	return false;
424
}
425
426
function consistent_menu_styler($hook, $type, $menu, $params) {
427
	$classes = array('btn', 'btn-primary', 'btn-md');
428
	if(elgg_get_context() != 'photos'){
429
		foreach ($menu as $key => $item) {
430
			$item->setLinkClass($classes);
431
		}
432
	}
433
434
	return $menu;
435
}
436
437
function consistent_menu_styler_alt($hook, $type, $menu, $params) {
438
	$classes = array('btn', 'btn-default', 'btn-md');
439
	foreach ($menu as $key => $item) {
440
							$item->setLinkClass($classes);
441
		 }
442
443
	return $menu;
444
}
445
446
447
/*
448
 * wet4_theme_pagesetup
449
 * Overrides various menu items to add font awesome icons, reorder items and add accessabilty
450
 */
451
function wet4_theme_pagesetup()
452
{
453
	if (elgg_is_logged_in()) {
454
		elgg_register_menu_item('topbar', array(
455
			'name' => 'account',
456
			'text' => elgg_echo('account'),
457
			'href' => "#",
458
			'priority' => 100,
459
			'section' => 'alt',
460
			'link_class' => 'elgg-topbar-dropdown',
461
		));
462
463 View Code Duplication
		if (elgg_is_active_plugin('dashboard')) {
464
			$item = elgg_unregister_menu_item('topbar', 'dashboard');
465
			if ($item) {
466
				$item->setText(elgg_echo('dashboard'));
467
				$item->setSection('default');
468
				elgg_register_menu_item('site', $item);
469
			}
470
		}
471
472
		$item = elgg_get_menu_item('topbar', 'usersettings');
473
		if ($item) {
474
			$item->setParentName('account');
475
			$item->setText(elgg_echo('settings'));
476
			$item->setPriority(103);
477
		}
478
479
		$item = elgg_get_menu_item('topbar', 'logout');
480
		if ($item) {
481
			$item->setParentName('account');
482
			$item->setText(elgg_echo('logout'));
483
			$item->setPriority(104);
484
		}
485
486
		$item = elgg_get_menu_item('topbar', 'administration');
487
		if ($item) {
488
			$item->setParentName('account');
489
			$item->setText(elgg_echo('admin'));
490
			$item->setPriority(101);
491
		}
492
493
		if (elgg_is_active_plugin('site_notifications')) {
494
			$item = elgg_get_menu_item('topbar', 'site_notifications');
495
			if ($item) {
496
				$item->setParentName('account');
497
				$item->setText(elgg_echo('site_notifications:topbar'));
498
				$item->setPriority(102);
499
			}
500
		}
501
502 View Code Duplication
		if (elgg_is_active_plugin('reportedcontent')) {
503
			$item = elgg_unregister_menu_item('footer', 'report_this');
504
			if ($item) {
505
				$item->setText(elgg_view_icon('report-this'));
506
				$item->setPriority(500);
507
				$item->setSection('default');
508
				elgg_register_menu_item('extras', $item);
509
			}
510
		}
511
512
513
		//style colleague requests tab
514
		$context = elgg_get_context();
515
		$page_owner = elgg_get_page_owner_entity();
516
517
		if (elgg_is_logged_in()) {
518
			$user = elgg_get_logged_in_user_guid();
519
		}
520
521
		if ($page_owner instanceof ElggUser && $page_owner->guid == $user) {
0 ignored issues
show
Bug introduced by
The variable $user 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...
522
			// Show menu link in the correct context
523
			if (in_array($context, array("friends", "friendsof", "collections"))) {
524
				$options = array(
525
					"type" => "user",
526
					"count" => true,
527
					"relationship" => "friendrequest",
528
					"relationship_guid" => $page_owner->getGUID(),
529
					"inverse_relationship" => true
530
				);
531
532
				$count = elgg_get_entities_from_relationship($options);
533
				$extra = "";
534
				if (!empty($count)) {
535
					$extra = '<span aria-hidden="true" class="notif-badge">' . $count . '</span>';
536
				}
537
538
				// add menu item
539
				$menu_item = array(
540
					"name" => "friend_request",
541
					"text" => elgg_echo("friend_request:menu") . $extra,
542
					"href" => "friend_request/" . $page_owner->username,
543
					"contexts" => array("friends", "friendsof", "collections")
544
				);
545
546
				elgg_register_menu_item("page", $menu_item);
547
			}
548
		}
549
550
		if (elgg_in_context('messages')) {
551
			elgg_unregister_menu_item("page", "friend_request");
552
		}
553
	}
554
555
556
	/*
557
	 *    Control colleague requests in topbar menu
558
	 *    taken from friend_request module
559
	 *    edited to place badge on colleagues instead of creating new icon
560
	 */
561
	$user = elgg_get_logged_in_user_entity();
562
563
	if ($user instanceof ElggUser) {
564
		$params = array(
565
			"name" => "Colleagues",
566
			"href" => "friends/" . $user->username,
567
			"text" => '<i class="fa fa-users fa-lg"></i><span class="hidden-xs wb-invisible">' . elgg_echo("userMenu:colleagues") . '</span>',
568
			"title" => elgg_echo('userMenu:colleagues'),
569
			"class" => '',
570
			'item_class' => '',
571
			'priority' => '1'
572
		);
573
574
		elgg_register_menu_item("user_menu", $params);
575
	}
576
577
578
	$context = elgg_get_context();
579
	$page_owner = elgg_get_page_owner_entity();
580
581
	// Remove link to friendsof
582
	elgg_unregister_menu_item("page", "friends:of");
583
584
	// Settings notifications tab in the User's setting page
585
	// cyu - allow site administrators to view user notification settings page
586
	elgg_unregister_menu_item('page', '2_a_user_notify');
587
	if ($page_owner instanceof ElggUser) {
588
		$params = array(
589
			"name" => "2_a_user_notify",
590
			"href" => "/settings/notifications/{$page_owner->username}",
591
			"text" => elgg_echo('notifications:subscriptions:changesettings'),
592
			'section' => 'configure',
593
			'priority' => '100',
594
			'context' => 'settings',
595
		);
596
597
		elgg_register_menu_item("page", $params);
598
	}
599
600
601
	if (!empty($user)) {
602
		$options = array(
603
			"type" => "user",
604
			"count" => true,
605
			"relationship" => "friendrequest",
606
			"relationship_guid" => $user->getGUID(),
607
			"inverse_relationship" => true
608
		);
609
610
		$count = elgg_get_entities_from_relationship($options);
611
		if (!empty($count)) {
612
			$countTitle = $count;
613
614
			//display 9+ instead of huge numbers in notif badge
615
			if ($count >= 10) {
616
				$count = '9+';
617
			}
618
619
			$params = array(
620
				"name" => "Colleagues",
621
				"href" => "friends/" . $user->username,
622
				"text" => '<i class="fa fa-users mrgn-rght-sm mrgn-tp-sm fa-lg"></i><span class="hidden-xs">'. elgg_echo("friends") . "</span><span class='notif-badge'>" . $count . "</span>",
623
				"title" => elgg_echo('userMenu:colleagues') . ' - ' . $countTitle . ' ' . elgg_echo('friend_request') .'(s)',
624
				"class" => '',
625
				'item_class' => '',
626
				'priority' => '1'
627
			);
628
629
			elgg_register_menu_item("user_menu", $params);
630
631
			//topbar
632
633
			$params = array(
634
				"name" => "friends",
635
				"href" => "friends/" . $user->username,
636
				"text" => elgg_echo("friends") . "<span class='badge'>" . $count . "</span>",
637
				"title" => elgg_echo('friends') . ' - Requests(' . $count .')',
638
				"class" => 'friend-icon',
639
			);
640
641
			elgg_register_menu_item("topbar", $params);
642
		}
643
	}
644
645
646
647
	//likes and stuff yo
648
	$item = elgg_get_menu_item('entity', 'likes');
649
	if ($item) {
650
		$item->setText('likes');
651
		$item->setItemClass('msg-icon');
652
	}
653
654
	$item = elgg_get_menu_item('entity', 'delete');
655
	if ($item) {
656
		echo '<div> What that mean?</div>';
657
	}
658
659 View Code Duplication
	if (elgg_is_logged_in() && elgg_get_config('allow_registration')) {
660
		$params = array(
661
				'name' => 'invite',
662
				'text' => elgg_echo('friends:invite'),
663
				'href' => "invite/". $user->username,
664
				'contexts' => array('friends'),
665
				'priority' => 300,
666
			);
667
		elgg_register_menu_item('page', $params);
668
	}
669
670
671
	//new folder button for files
672
673 View Code Duplication
	if (elgg_is_logged_in()) {
674
		$user = elgg_get_logged_in_user_entity();
675
		if ($user->canEdit()) {
676
			$params = array(
677
				'name' => 'new_folder',
678
				'text' => elgg_echo("file_tools:new:title"),
679
				'href' => "#",
680
				"id" => "file_tools_list_new_folder_toggle",
681
				'item_class' => 'mrgn-lft-sm',
682
				'context' => 'file',
683
			);
684
			elgg_register_menu_item('title2', $params);
685
		}
686
	}
687
}
688
689
690
691
/**
692
 * Register items for the html head
693
 *
694
 * @param string $hook Hook name ('head')
695
 * @param string $type Hook type ('page')
696
 * @param array  $data Array of items for head
697
 * @return array
698
 */
699
function wet4_theme_setup_head($hook, $type, $data)
700
{
701
702
    if( file_exists('mod/wet4_theme/graphics/homescreen.png') ){
703
    	$data['links']['apple-touch-icon'] = array(
704
    		'rel' => 'apple-touch-icon',
705
    		'href' => elgg_normalize_url('mod/wet4_theme/graphics/homescreen.png'),
706
    	);
707
    }
708
709
	return $data;
710
}
711
712
/*
713
 * wet4_likes_entity_menu_setup
714
 * Override likes entity menu to include font awesome icons and add accessability
715
 */
716
function wet4_likes_entity_menu_setup($hook, $type, $return, $params)
717
{
718
	// make the widget view produce the same entity menu as the other objects
719
720
	$entity = $params['entity'];
721
	$lang = get_current_language();
722
	$entContext = $entity->getType();
723
724
	//check if entity is an object or group
725 View Code Duplication
	if ($entContext == 'object') {
726
727
		//find subtype
728
		$contentType = $entity->getSubtype();
729
		//convert subtype into plain language
730
		$entContext = proper_subtypes($contentType);//$entity->getSubtype();
731
732
		//check to see if entity is one f the entities with a title
733
		if (!in_array($entity->getSubtype(), array('comment', 'discussion_reply', 'thewire'))) {
734
			if ($entity->title3) {
735
				$entName = gc_explode_translation($entity->title3, $lang);
736
			} else {
737
				$entName = $entity->title;
738
			}
739
		} else { //if not get owner instead of name
740
741
			$entName = $entity->getOwnerEntity()->name;
742
		}
743
	} elseif ($entContext == 'group') {
744
		$contentType = 'group';
745
		$entContext = elgg_echo('group');
746
		if ($entity->title3) {
747
			$entName = gc_explode_translation($entity->title3, $lang);
748
		} else {
749
			$entName = $entity->name;
750
		}
751
	}
752
753
	if ($entity->canAnnotate(0, 'likes')) {
754
		$hasLiked = \Elgg\Likes\DataService::instance()->currentUserLikesEntity($entity->guid);
755
756
		//pass type and entiey/owner name to function to return array of text
757
		$hiddenText = generate_hidden_text($contentType, $entName);
0 ignored issues
show
Bug introduced by
The variable $contentType 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...
Bug introduced by
The variable $entName 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...
758
759
		// Always register both. That makes it super easy to toggle with javascript
760
		$return[] = ElggMenuItem::factory(array(
761
			'name' => 'likes',
762
			'href' => elgg_add_action_tokens_to_url("/action/likes/add?guid={$entity->guid}"),
763
			'text' => '<i class="fa fa-thumbs-up fa-lg icon-unsel"></i><span class="wb-inv">'.$hiddenText['like'].'</span>',
764
			'title' => elgg_echo('likes:likethis') . ' ' . $entContext,
765
			'item_class' => $hasLiked ? 'hidden' : '',
766
			'priority' => 998,
767
		));
768
		$return[] = ElggMenuItem::factory(array(
769
			'name' => 'unlike',
770
			'href' => elgg_add_action_tokens_to_url("/action/likes/delete?guid={$entity->guid}"),
771
			'text' => '<i class="fa fa-thumbs-up fa-lg icon-sel"></i><span class="wb-inv">'.$hiddenText['unlike'].'</span>',
772
			'title' => elgg_echo('likes:remove') . ' ' . $entContext,
773
			'item_class' => $hasLiked ? 'pad-rght-xs' : 'hidden',
774
			'priority' => 998,
775
		));
776
	}
777
778
	// likes count
779
	$count = elgg_view('likes/count', array('entity' => $entity));
780 View Code Duplication
	if ($count) {
781
		$options = array(
782
			'name' => 'likes_count',
783
			'text' => $count,
784
			'href' => false,
785
			'priority' => 999,
786
			'item_class' => 'entity-menu-bubble',
787
		);
788
		$return[] = ElggMenuItem::factory($options);
789
	}
790
791
	return $return;
792
}
793
794
795
/*
796
 * wet4_elgg_page_menu_setup
797
 * Override page menu on user settings page
798
 */
799
function wet4_elgg_page_menu_setup($hook, $type, $return, $params)
800
{
801
	if (elgg_in_context('settings')) {
802
		$user = elgg_get_page_owner_entity();
803
804
		$dropdown = '<ul class="dropdown-menu pull-right subMenu">';
805
806
		$active_plugins = elgg_get_plugins();
807
808
		foreach ($active_plugins as $plugin) {
809
			$plugin_id = $plugin->getID();
810
			if (elgg_view_exists("usersettings/$plugin_id/edit") || elgg_view_exists("plugins/$plugin_id/usersettings")) {
811
				$params = array(
812
					'name' => $plugin_id,
813
					'text' => $plugin->getFriendlyName(),
814
					'href' => "settings/plugins/{$user->username}/$plugin_id",
815
				);
816
817
				$dropdown .= '<li><a href="' . elgg_get_site_url() . 'settings/plugins/' . $user->username . '/' . $plugin_id . '">' . $plugin->getFriendlyName() . '</a></li>';
818
			}
819
		}
820
821
		$dropdown .= '</ul>';
822
823
		return $return;
824
	}
825
}
826
827
/*
828
 * wet4_blog_entity_menu
829
 * Override blog entity menu to include font awesome icons and add accessability
830
 */
831
function wet4_blog_entity_menu($hook, $entity_type, $returnvalue, $params)
832
{
833
	if (empty($params) || !is_array($params)) {
834
		return $returnvalue;
835
	}
836
837
	$lang = get_current_language();
838
839
	$entity = elgg_extract("entity", $params);
840
	if (empty($entity) || !elgg_instanceof($entity, "object", "blog")) {
841
		return $returnvalue;
842
	}
843
844
	if ($entity->title3) {
845
		$entName = gc_explode_translation($entity->title3, $lang);
846
	} else {
847
		$entName = $entity->title;
848
	}
849
850
	// only published blogs
851
	if ($entity->status == "draft") {
852
		return $returnvalue;
853
	}
854
855 View Code Duplication
	if (!elgg_in_context("widgets") && elgg_is_admin_logged_in()) {
856
		$returnvalue[] = \ElggMenuItem::factory(array(
857
			"name" => "blog-feature",
858
			"text" => elgg_echo("blog_tools:toggle:feature"),
859
			"href" => "action/blog_tools/toggle_metadata?guid=" . $entity->getGUID() . "&metadata=featured",
860
			"item_class" => empty($entity->featured) ? "" : "hidden",
861
			"is_action" => true,
862
			"priority" => 175
863
		));
864
		$returnvalue[] = \ElggMenuItem::factory(array(
865
			"name" => "blog-unfeature",
866
			"text" => elgg_echo("blog_tools:toggle:unfeature"),
867
			"href" => "action/blog_tools/toggle_metadata?guid=" . $entity->getGUID() . "&metadata=featured",
868
			"item_class" => empty($entity->featured) ? "hidden" : "",
869
			"is_action" => true,
870
			"priority" => 176
871
		));
872
	}
873
874
	if ($entity->canComment() && elgg_is_logged_in()) {
875
		$returnvalue[] = \ElggMenuItem::factory(array(
876
			"name" => "comments",
877
			"text" => '<i class="fa fa-lg fa-comment icon-unsel"><span class="wb-inv">' . elgg_echo("entity:comment:link:blog", array($entName)) . '</span></i>',
878
			"title" => elgg_echo("comment:this"),
879
			"href" => $entity->getURL() . "#comments"
880
		));
881
	}
882
883
	return $returnvalue;
884
}
885
886
/*
887
 * my_owner_block_handler
888
 * Override owner_block menu to become tabs in profile
889
 */
890
function wet4_elgg_entity_menu_setup($hook, $type, $return, $params)
891
{
892
	//Have widgets show the same entity menu
893
894
	$entity = $params['entity'];
895
	$lang = get_current_language();
896
	/* @var \ElggEntity $entity */
897
	$handler = elgg_extract('handler', $params, false);
898
899
	//Nick -Remove empty comment and reply links from river menu
900
	foreach ($return as $key => $item) {
901
		if ($item && $item->getName() == 'access') {
902
			unset($return[$key]);
903
		}
904
	}
905
906
	$entContext = $entity->getType();
907
908
	//check if entity is an object or group
909 View Code Duplication
	if ($entContext == 'object') {
910
911
		//find subtype
912
		$contentType = $entity->getSubtype();
913
		//convert subtype into plain language
914
		$entContext = proper_subtypes($contentType);
915
916
		//check to see if entity is one f the entities with a title
917
		if (!in_array($entity->getSubtype(), array('comment', 'discussion_reply', 'thewire', 'answer'))) {
918
			if ($entity->title3) {
919
				$entName = gc_explode_translation($entity->title3, $lang);
920
			} else {
921
				$entName = $entity->title;
922
			}
923
		} else { //if not get owner instead of name
924
925
			$entName = $entity->getOwnerEntity()->name;
926
		}
927
	} elseif ($entContext == 'group') {
928
		$contentType = 'group';
929
		$entContext = elgg_echo('group');
930
		if ($entity->title3) {
931
			$entName = gc_explode_translation($entity->title3, $lang);
932
		} else {
933
			$entName = $entity->name;
934
		}
935
	}
936
937
	//pass type and entiey/owner name to function to return array of text
938
	$hiddenText = generate_hidden_text($contentType, $entName);
0 ignored issues
show
Bug introduced by
The variable $contentType 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...
Bug introduced by
The variable $entName 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...
939
	$blocked_subtypes = array('comment', 'discussion_reply');
940
	if (in_array($entity->getSubtype(), $blocked_subtypes) || elgg_instanceof($entity, 'user')) {
941
		//do not let comments or discussion replies to be reshared on the wire
942
	} else {
943
		// check is this item was shared on thewire
944
		$count = $entity->getEntitiesFromRelationship(array(
945
			'type' => 'object',
946
			'subtype' => 'thewire',
947
			'relationship' => 'reshare',
948
			'inverse_relationship' => true,
949
			'count' => true
950
		));
951
952
		if ($count) {
953
			if ($count >=2) {
954
				$share = elgg_echo('thewire:shares');
955
			} else {
956
				$share = elgg_echo('thewire:share');
957
			}
958
959
			// show counter
960
			$return[] = \ElggMenuItem::factory(array(
961
				'name' => 'thewire_tools_reshare_count',
962
				'text' => $count . $share,
963
				'title' => elgg_echo('thewire_tools:reshare:count'),
964
				'href' => 'ajax/view/thewire_tools/reshare_list?entity_guid=' . $entity->getGUID(),
965
				'link_class' => 'elgg-lightbox',
966
				'item_class' => ' entity-menu-bubble',
967
				'is_trusted' => true,
968
				'priority' => 501,
969
				'data-colorbox-opts' => json_encode(array(
970
					'maxHeight' => '85%'
971
				))
972
			));
973
		}
974
975
976
		if (elgg_is_logged_in()) {
977
			//reshare on the wire
978
			$options = array(
979
				'name' => 'thewire_tools_reshare',
980
				'text' => '<i class="fa fa-share-alt fa-lg icon-unsel"><span class="wb-inv">'.$hiddenText['share'].'</span></i>',
981
				'title' => elgg_echo('thewire_tools:reshare'),
982
				'href' => 'ajax/view/thewire_tools/reshare?reshare_guid=' . $entity->getGUID(),
983
				'link_class' => 'elgg-lightbox',
984
				'item_class' => '',
985
				'is_trusted' => true,
986
				'priority' => 500
987
			);
988
			$return[] = \ElggMenuItem::factory($options);
989
		} else {
990
			$options = array(
991
				'name' => 'thewire_tools_reshare',
992
				'text' => '',
993
				'item_class' => 'removeMe',
994
			);
995
			$return[] = \ElggMenuItem::factory($options);
996
		}
997
	}
998
999
	//only show reply on the wire with logged in user
1000
	if ($entity->getSubtype() == 'thewire' && elgg_is_logged_in()) {
1001
		$options = array(
1002
			'name' => 'reply',
1003
			'text' => '<i class="fa fa-reply fa-lg icon-unsel"><span class="wb-inv">'.$hiddenText['reply'].'</span></i>',
1004
			'title' => elgg_echo('reply'),
1005
			'href' => 'ajax/view/thewire_tools/reply?guid=' . $entity->getGUID(),
1006
			'link_class' => 'elgg-lightbox',
1007
			'is_trusted' => true,
1008
			'priority' => 100
1009
		);
1010
		$return[] = \ElggMenuItem::factory($options);
1011
	}
1012
1013
	if (($entity->countEntitiesFromRelationship("parent") || $entity->countEntitiesFromRelationship("parent", true))) {
1014
                $options = array(
1015
                    'name' => 'thread',
1016
                    'text' => elgg_echo('thewire:thread'),
1017
                    'href' => 'ajax/view/thewire_tools/thread?thread_id=' . $entity->wire_thread,
1018
                    'link_class' => 'elgg-lightbox',
1019
                    'is_trusted' => true,
1020
                    'priority' => 170,
1021
                );
1022
                $return[] = ElggMenuItem::factory($options);
1023
            }
1024
1025
	if ($entity->canEdit() && $handler) {
1026
        //checks so the edit icon is not placed on incorrect entities
1027
      if($handler != 'group_operators'){
1028
            if($entity->getSubtype() != 'thewire' && $entity->getSubtype() != 'discussion_reply'){
1029
                $options = array(
1030
                    'name' => 'edit',
1031
                    'text' => '<i class="fa fa-edit fa-lg icon-unsel"><span class="wb-inv">'.$hiddenText['edit'].'</span></i>',
1032
                    'title' => elgg_echo('edit:this') . ' ' . $entContext,
1033
                    'href' => "$handler/edit/{$entity->getGUID()}",
1034
                    'priority' => 299,
1035
                );
1036
                $return[] = \ElggMenuItem::factory($options);
1037
            }
1038
		// delete link
1039
1040
            if (elgg_is_logged_in() && $entity->getSubtype() != 'discussion_reply'){
1041
            		$options = array(
1042
            			'name' => 'delete',
1043
            			'text' => '<i class="fa fa-trash-o fa-lg icon-unsel"><span class="wb-inv">'.$hiddenText['delete'].'</span></i>',
1044
            			'title' => elgg_echo('delete:this') . ' ' . $entContext,
1045
            			'href' => "action/$handler/delete?guid={$entity->getGUID()}",
1046
            			'confirm' => elgg_echo('deleteconfirm'),
1047
            			'priority' => 300,
1048
            		);
1049
            		$return[] = \ElggMenuItem::factory($options);
1050
            }
1051
1052
						//remove delete icon on groups
1053
						if($entity instanceof ElggGroup){
1054
							foreach ($return as $key => $item) {
1055
								if($item->getName() == 'delete') {
1056
										unset($return[$key]);
1057
								}
1058
							}
1059
						}
1060
1061
            if (elgg_is_logged_in()){
1062
                $user = elgg_get_logged_in_user_entity();
1063
                $page_owner = elgg_get_page_owner_entity();
1064
                if($entity->getSubtype() == 'discussion_reply' ){
1065
									if($page_owner!=''||$page_owner!=null){
1066
										if($entity->owner_guid == $user['guid'] || elgg_is_admin_logged_in() || ($page_owner instanceof ElggGroup && $page_owner->getOwnerGUID() == $user['guid']) || $page_owner->canEdit()){
1067
				                    $options = array(
1068
				                    'name' => 'edit',
1069
				                    'text' => '<i class="fa fa-edit fa-lg icon-unsel"><span class="wb-inv">'.$hiddenText['edit'].'</span></i>',
1070
				                    'title' => elgg_echo('edit:this') . ' ' . $entContext,
1071
				                    'href' => "$handler/edit/{$entity->getGUID()}",
1072
				                    'priority' => 299,
1073
				                );
1074
				                $return[] = \ElggMenuItem::factory($options);
1075
1076
				                    $options = array(
1077
				                        'name' => 'delete',
1078
				                        'text' => '<i class="fa fa-trash-o fa-lg icon-unsel"><span class="wb-inv">'.$hiddenText['delete'].'</span></i>',
1079
				                        'title' => elgg_echo('delete:this') . ' ' . $entContext,
1080
				                        'href' => "action/$handler/delete?guid={$entity->getGUID()}",
1081
				                        'confirm' => elgg_echo('deleteconfirm'),
1082
				                        'priority' => 300,
1083
				                    );
1084
				                    $return[] = \ElggMenuItem::factory($options);
1085
					            }
1086
										}
1087
							}
1088
            }
1089
        }
1090
    }
1091
1092 View Code Duplication
    if($entity->getSubType() == 'file'){
1093
        // download link
1094
		$options = array(
1095
			'name' => 'download',
1096
			'text' => '<i class="fa fa-download fa-lg icon-unsel"><span class="wb-inv">'.$hiddenText['download'].'</span></i>',
1097
			'title' => 'Download File',
1098
			'href' => "file/download/{$entity->getGUID()}",
1099
			'priority' => 300,
1100
		);
1101
		$return[] = \ElggMenuItem::factory($options);
1102
	}
1103
1104
1105 View Code Duplication
	if ($entity->getSubType() == 'page_top') {
1106
		//history icon
1107
		$options = array(
1108
			'name' => 'history',
1109
			'text' => '<i class="fa fa-history fa-lg icon-unsel"><span class="wb-inv">' . $hiddenText['history'] . '</span></i>',
1110
			'title'=> elgg_echo('pages:history'),
1111
			'href' => "pages/history/$entity->guid",
1112
			'priority' => 150,
1113
		);
1114
		$return[] = \ElggMenuItem::factory($options);
1115
	}
1116
1117
	//opening and close dicussions
1118
	if (elgg_instanceof($entity, "object", "groupforumtopic") && $entity->canEdit() && elgg_is_active_plugin('group_tools')) {
1119
		$return[] = ElggMenuItem::factory(array(
1120
			"name" => "status_change_open",
1121
			"text" => '<i class="fa fa-lock fa-lg icon-unsel"><span class="wb-inv">'.$hiddenText['unlock'].'</span></i>',
1122
			"confirm" => elgg_echo("group_tools:discussion:confirm:open"),
1123
			"href" => "action/discussion/toggle_status?guid=" . $entity->getGUID(),
1124
			"is_trusted" => true,
1125
			"title" => elgg_echo('entity:unlock:link:groupforumtopic'),
1126
			"priority" => 200,
1127
			"item_class" => ($entity->status == "closed") ? "" : "hidden"
1128
		));
1129
		$return[] = ElggMenuItem::factory(array(
1130
			"name" => "status_change_close",
1131
			"text" => '<i class="fa fa-unlock fa-lg icon-unsel"><span class="wb-inv">'.$hiddenText['lock'].'</span></i>',
1132
			"confirm" => elgg_echo("group_tools:discussion:confirm:close"),
1133
			"href" => "action/discussion/toggle_status?guid=" . $entity->getGUID(),
1134
			"is_trusted" => true,
1135
			"title" => elgg_echo('entity:lock:link:groupforumtopic'),
1136
			"priority" => 201,
1137
			"item_class" => ($entity->status == "closed") ? "hidden" : ""
1138
		));
1139
	}
1140
1141
	//style comment for Questions mod and switch to FA icon
1142
	if ($entity->canComment()) {
1143
		if (elgg_extract('full_view', $params, false) || ($entity instanceof ElggAnswer)) {
1144
			$options = array(
1145
				'name' => 'comments',
1146
				"text" => '<span class="fa fa-lg fa-comment icon-unsel"><span class="wb-inv">' . elgg_echo("entity:comment:link:".$entity->getSubtype(), array($entName)) . '</span></span>',
1147
				"title" => elgg_echo("comment:this") . ' ' . $entContext,
1148
				'href' => "#comments-add-{$entity->getGUID()}",
1149
				'priority' => 288,
1150
				'rel' => 'toggle'
1151
			);
1152
			$return[] = \ElggMenuItem::factory($options);
1153
		}
1154
	}
1155
1156
	// WIP bookmark objects prototype
1157
	// TODO: conditional rendering on only objects + pass a better title sometimes
1158
	if(elgg_is_logged_in()) {
1159
		if (in_array($entity->getSubtype(), array('comment', 'discussion_reply', 'thewire', 'answer', 'group_profile', 'bookmarks')) || elgg_instanceof($entity, 'user')) {}else{
1160
			$user_guid = elgg_get_logged_in_user_guid();
1161
			$address = urlencode($entity->getUrl());
1162
			$nameEn = json_decode($entity->title)->en;
1163
			$nameFr = json_decode($entity->title)->fr;
1164
			$options = array(
1165
				'name' => 'bookmarkpage',
1166
				'text' => '<span class="fa fa-lg fa-bookmark icon-unsel"><span class="wb-invisible">'.elgg_echo('bookmarks:this').'</span></span>',
1167
				'href' => "bookmarks/add/$user_guid?address=$address&title=$nameEn&title2=$nameFr",
1168
				'title' => elgg_echo('bookmarks:this'),
1169
				'rel' => 'nofollow',
1170
			);
1171
			$return[] = \ElggMenuItem::factory($options);
1172
		}
1173
	}
1174
1175
	return $return;
1176
}
1177
1178
function wet4_group_entity_menu_setup($hook, $type, $value, $params) {
1179
	$handler = elgg_extract('handler', $params, false);
1180
	if ($handler != 'groups') {
1181
		return $value;
1182
	}
1183
	$entity = $params['entity'];
1184
	foreach ($value as $index => $item) {
1185
			$name = $item->getName();
1186
			if ($name == 'likes' || $name == 'likes_count' || $name == 'members' || $name == 'unlike' || $name == 'thewire_tools_reshare_count' || $name == 'bookmark') {
1187
					unset($value[$index]);
1188
			}
1189
	}
1190
1191
	if ($entity->isPublicMembership()) {
1192
		$mem = elgg_echo("groups:open");
1193
	} else {
1194
		$mem = elgg_echo("groups:closed");
1195
	}
1196
1197
	$options = array(
1198
		'name' => 'membership',
1199
		'text' => $mem,
1200
		'href' => false,
1201
		'priority' => 100,
1202
	);
1203
	$value[] = ElggMenuItem::factory($options);
1204
1205
	return $value;
1206
}
1207
1208
/*
1209
 * _wet4_friends_page_handler
1210
 * Override friends page handler to use wet4 pages
1211
 */
1212
function _wet4_friends_page_handler($page, $handler)
1213
{
1214
	//change the page handler for friends to user our own pages. This increases the limit of friends for data table parsing and such :)
1215
	elgg_set_context('friends');
1216
1217 View Code Duplication
	if (isset($page[0]) && $user = get_user_by_username($page[0])) {
1218
		elgg_set_page_owner_guid($user->getGUID());
1219
	}
1220
1221
	if (!elgg_get_page_owner_guid()) {
1222
		return false;
1223
	}
1224
	$plugin_path = elgg_get_plugins_path();
1225
	switch ($handler) {
1226
		case 'friends':
1227
			//use the pages in our theme instead of the core pages
1228
			require($plugin_path ."wet4/pages/friends/index.php");
1229
			break;
1230
		case 'friendsof':
1231
			require($plugin_path ."wet4/pages/friends/of.php");
1232
			break;
1233
		default:
1234
			return false;
1235
	}
1236
	return true;
1237
}
1238
1239
/*
1240
 * wet4_riverItem_remove
1241
 * Remove unwanted river items
1242
 */
1243
function wet4_riverItem_remove()
1244
{
1245
	elgg_unregister_menu_item('river', 'comment');
1246
	elgg_unregister_menu_item('river', 'reply');
1247
}
1248
1249
/*
1250
 * wet4_elgg_river_menu_setup
1251
 * Override river menu to use font awesome icons + add accessability
1252
 */
1253
function wet4_elgg_river_menu_setup($hook, $type, $return, $params)
1254
{
1255
	$user_guid = elgg_get_logged_in_user_guid();
1256
	if (elgg_is_logged_in()) {
1257
		$item = $params['item'];
1258
		$object = $item->getObjectEntity();
1259
		$lang = get_current_language();
1260
		// add comment link but annotations cannot be commented on
1261
1262
		if (!$object || !$object->canAnnotate(0, 'likes')) {
1263
			return;
1264
		}
1265
		//Nick -Remove empty comment and reply links from river menu
1266
		foreach ($return as $key => $item) {
1267
			switch ($item->getName()) {
1268
				case 'comment':
1269
				case 'reply':
1270
					unset($return[$key]);
1271
					break;
1272
			}
1273
		}
1274
1275
		$entContext = $object->getType();
1276
		//check if entity is an object or group
1277
		if ($entContext == 'object') {
1278
1279
			//find subtype
1280
			$contentType = $object->getSubtype();
1281
			//convert subtype into plain language
1282
			$entContext = proper_subtypes($contentType);
1283
1284
			//check to see if entity is one f the entities with a title
1285
			if (!in_array($object->getSubtype(), array('comment', 'discussion_reply', 'thewire', 'answer'))) {
1286
				if ($object->title3) {
1287
					$entName = gc_explode_translation($object->title3, $lang);
1288
				} else {
1289
					$entName = gc_explode_translation($object->title, $lang);
1290
				}
1291
			} else { //if not get owner instead of name
1292
				$entName = $object->getOwnerEntity()->name;
1293
			}
1294
		} elseif ($entContext == 'group') {
1295
			$contentType = 'group';
1296
			$entContext = elgg_echo('group');
1297
			if ($object->title3) {
1298
				$entName = gc_explode_translation($object->title3, $lang);
1299
			} else {
1300
				$entName = $object->name;
1301
			}
1302
		}
1303
1304
		//pass type and entiey/owner name to function to return array of text
1305
		$hiddenText = generate_hidden_text($contentType, $entName);
0 ignored issues
show
Bug introduced by
The variable $contentType 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...
Bug introduced by
The variable $entName 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...
1306
1307
		if ($entContext != 'user') {
1308
			$hasLiked = \Elgg\Likes\DataService::instance()->currentUserLikesEntity($object->guid);
1309
1310
			// Always register both. That makes it super easy to toggle with javascript
1311
			$return[] = ElggMenuItem::factory(array(
1312
				'name' => 'likes',
1313
				'href' => elgg_add_action_tokens_to_url("/action/likes/add?guid={$object->guid}"),
1314
				'text' => '<i class="fa fa-thumbs-up fa-lg icon-unsel"></i><span class="wb-inv">'.$hiddenText['like'].'</span>',
1315
				'title' => elgg_echo('likes:likethis') . ' ' . $entContext,
1316
				'item_class' => $hasLiked ? 'hidden' : '',
1317
				'priority' => 100,
1318
			));
1319
			$return[] = ElggMenuItem::factory(array(
1320
				'name' => 'unlike',
1321
				'href' => elgg_add_action_tokens_to_url("/action/likes/delete?guid={$object->guid}"),
1322
				'text' => '<i class="fa fa-thumbs-up fa-lg icon-sel"></i><span class="wb-inv">'.$hiddenText['unlike'].'</span>',
1323
				'title' => elgg_echo('likes:remove') . ' ' . $entContext,
1324
				'item_class' => $hasLiked ? '' : 'hidden',
1325
				'priority' => 100,
1326
			));
1327
1328
			// likes count
1329
			$count = elgg_view('likes/count', array('entity' => $object));
1330 View Code Duplication
			if ($count) {
1331
				$return[] = ElggMenuItem::factory(array(
1332
					'name' => 'likes_count',
1333
					'text' => $count,
1334
					'href' => false,
1335
					'priority' => 101,
1336
				));
1337
			}
1338
		}
1339
1340
		$blocked_subtypes = array('comment', 'discussion_reply');
1341 View Code Duplication
		if (in_array($object->getSubtype(), $blocked_subtypes) || elgg_instanceof($object, 'user')) {
1342
			//do not let comments or discussion replies to be reshared on the wire
1343
		} else {
1344
			$return[]= ElggMenuItem::factory(array(
1345
				'name' => 'thewire_tools_reshare',
1346
				'text' => '<i class="fa fa-share-alt fa-lg icon-unsel"><span class="wb-inv">'.$hiddenText['share'].'</span></i>',
1347
				'title' => elgg_echo('thewire_tools:reshare'),
1348
				'href' => 'ajax/view/thewire_tools/reshare?reshare_guid=' . $object->getGUID(),
1349
				'link_class' => 'elgg-lightbox',
1350
				'item_class' => '',
1351
				'is_trusted' => true,
1352
				'priority' => 500
1353
			));
1354
		}
1355
1356
		if (elgg_is_admin_logged_in()) {
1357
			$options = array(
1358
				'name' => 'delete',
1359
				'href' => elgg_add_action_tokens_to_url("action/river/delete?id=$item->id"),
1360
				'text' => '<i class="fa fa-trash-o fa-lg icon-unsel"><span class="wb-inv">Delete This</span></i>',
1361
				'title' => elgg_echo('river:delete'),
1362
				'confirm' => elgg_echo('deleteconfirm'),
1363
				'priority' => 200,
1364
			);
1365
			$return[] = \ElggMenuItem::factory($options);
1366
		}
1367
		// comment blog
1368 View Code Duplication
		if($object->getSubtype() == 'blog'){
1369
			if ($object->canComment()) {
1370
				$options = array(
1371
					"name" => "comments",
1372
					"text" => '<i class="fa fa-lg fa-comment icon-unsel"><span class="wb-inv">' . elgg_echo("entity:comment:link:blog", array($entName)) . '</span></i>',
1373
					"title" => elgg_echo("comment:this"),
1374
					"href" => $object->getURL() . "#comments"
1375
				);
1376
				$return[] = \ElggMenuItem::factory($options);
1377
			}
1378
		}
1379
		// reply discussion
1380 View Code Duplication
		if($object->getSubtype() == 'groupforumtopic'){
1381
			if ($object->status != "closed") {
1382
				$options = array(
1383
					"name" => "reply",
1384
					"text" => '<i class="fa fa-lg fa-reply icon-unsel"><span class="wb-inv">' . elgg_echo("entity:reply:groupdorumtopic",array($entName)) . '</span></i>',
1385
					"title" => elgg_echo("reply:this"),
1386
					"href" => $object->getURL() . "#reply"
1387
				);
1388
				$return[] = \ElggMenuItem::factory($options);
1389
			}
1390
		}
1391
		// add event calendar
1392
		if($object->getSubtype() == 'event_calendar'){
1393
			if (check_entity_relationship($user_guid, 'personal_event', $object->guid)) {
1394
				$options = array(
1395
					"name" => "calendar",
1396
					"text" => '<i class="fa fa-lg fa-calendar icon-unsel"><span class="wb-inv">' . elgg_echo("entity:remove:event_calendar",array($entName)) . '</span></i>',
1397
					"title" => elgg_echo("event_calendar:remove_from_my_calendar"),
1398
					"href" => elgg_add_action_tokens_to_url("action/event_calendar/remove_personal?guid={$object->guid}"),
1399
				);
1400
			}else{
1401
				$options = array(
1402
					"name" => "calendar",
1403
					"text" => '<i class="fa fa-lg fa-calendar icon-unsel"><span class="wb-inv">' . elgg_echo("entity:add:event_calendar",array($entName)) . '</span></i>',
1404
					"title" => elgg_echo("event_calendar:add_to_my_calendar"),
1405
					"href" => elgg_add_action_tokens_to_url("action/event_calendar/add_personal?guid={$object->guid}"),
1406
				);
1407
			}
1408
			$return[] = \ElggMenuItem::factory($options);
1409
		}
1410
		// download file
1411 View Code Duplication
		if($object->getSubType() == 'file'){
1412
			$options = array(
1413
				'name' => 'download',
1414
				'text' => '<i class="fa fa-download fa-lg icon-unsel"><span class="wb-inv">'.$hiddenText['download'].'</span></i>',
1415
				'title' => elgg_echo('download'),
1416
				'href' => "file/download/{$object->getGUID()}",
1417
				'priority' => 300,
1418
			);
1419
			$return[] = \ElggMenuItem::factory($options);
1420
		}
1421
		//question - answer
1422
		if($object->getSubtype() == 'question' || $object->getSubtype() == 'answer'){	
1423 View Code Duplication
			if ($object->canComment()) {	
1424
				$options = array(
1425
					'name' => 'comments',
1426
					"text" => '<span class="fa fa-lg fa-comment icon-unsel"><span class="wb-inv">' . elgg_echo("entity:comment:link:question", array($entName)) . '</span></span>',
1427
					"title" => elgg_echo("comment:this"),
1428
					'href' => $object->getURL() ."#commentsadd{$object->getGUID()}",
1429
					'priority' => 288,
1430
				);
1431
				$return[] = \ElggMenuItem::factory($options);
1432
			}
1433
		}
1434
	}
1435
1436
	return $return;
1437
}
1438
1439
/*
1440
 * my_filter_menu_handler
1441
 * Rearrange filter menu for The Wire
1442
 */
1443
function my_filter_menu_handler($hook, $type, $menu, $params)
1444
{
1445
	foreach ($menu as $key => $item) {
1446
		if (elgg_in_context('thewire')) {
1447
			switch ($item->getName()) {
1448
				case 'all':
1449
					$item->setPriority('1');
1450
					break;
1451
				case 'friend':
1452
					$item->setPriority('2');
1453
					break;
1454
				case 'mention':
1455
					$item->setText(elgg_echo('search'));
1456
					$item->setPriority('4');
1457
					break;
1458
				case 'mine':
1459
					$item->setPriority('3');
1460
					break;
1461
			}
1462
		}
1463
	}
1464
}
1465
1466
/*
1467
 * my_site_menu_handler
1468
 * Set href of groups link depending if a logged in user is using site
1469
 */
1470
function my_site_menu_handler($hook, $type, $menu, $params)
1471
{
1472
	if (!is_array($menu)) {
1473
		return;
1474
	}
1475
1476
	foreach ($menu as $key => $item) {
1477
		if ($item->getName() === 'groups') {
1478
			(elgg_is_logged_in()) ? $item->setHref(elgg_get_site_url().'groups/all?filter=yours') : $item->setHref(elgg_get_site_url().'groups/all?filter=popular');
1479
		}
1480
	}
1481
1482
}
1483
1484
/*
1485
 * my_title_menu_handler
1486
 * Add styles to phot album title menu
1487
 */
1488
function my_title_menu_handler($hook, $type, $menu, $params)
1489
{
1490
	if (!is_array($menu)) {
1491
		return;
1492
	}
1493
1494
	foreach ($menu as $key => $item) {
1495
		if ($item->getName() === 'slideshow') {
1496
			$item->setText(elgg_echo('album:slideshow'));
1497
		} elseif ($item->getName() === 'addphotos') {
1498
			$item->setItemClass('mrgn-rght-sm');
1499
		}
1500
	}
1501
}
1502
1503
/*
1504
 * my_owner_block_handler
1505
 * Override owner_block menu to become tabs in profile
1506
 */
1507
function my_owner_block_handler($hook, $type, $menu, $params){
1508
1509
    /*
1510
     *
1511
     * If new tool has been added to group tools
1512
     * Make sure the priority is less then 100
1513
     *
1514
     */
1515
1516
1517
        //rearrange menu items
1518 View Code Duplication
    if(elgg_get_context() == 'profile'){
1519
1520
        elgg_unregister_menu_item('owner_block', 'activity');
1521
1522
        //turn owner_block  menu into tabs
1523
        foreach ($menu as $key => $item){
1524
1525
            switch ($item->getName()) {
1526
                case 'discussion':
1527
                    $item->setText(elgg_echo('gprofile:discussion'));
1528
1529
                    $item->setPriority('1');
1530
                    break;
1531
                case 'file':
1532
                    $item->setText(elgg_echo('gprofile:files'));
1533
                    $item->setHref('#file');
1534
                    $item->setPriority('2');
1535
                    break;
1536
                case 'blog':
1537
                    $item->setText(elgg_echo('gprofile:blogs'));
1538
                    $item->setHref('#blog');
1539
                    $item->setPriority('3');
1540
                    break;
1541
                case 'event_calendar':
1542
                    $item->setText(elgg_echo('gprofile:events'));
1543
                    $item->setHref('#events');
1544
                    $item->setPriority('6');
1545
                    break;
1546
                case 'pages':
1547
                    $item->setText(elgg_echo('gprofile:pages'));
1548
                    $item->setHref('#page_top');
1549
                    $item->setPriority('7');
1550
                    break;
1551
                case 'bookmarks':
1552
                    $item->setText(elgg_echo('gprofile:bookmarks'));
1553
                    $item->setHref('#bookmarks');
1554
                    $item->setPriority('8');
1555
                    break;
1556
                case 'polls':
1557
                    $item->setText(elgg_echo('gprofile:polls'));
1558
                    $item->setHref('#poll');
1559
                    $item->setPriority('9');
1560
                    break;
1561
                case 'tasks':
1562
                    $item->setText(elgg_echo('gprofile:tasks'));
1563
                    $item->setHref('#task_top');
1564
                    $item->setPriority('10');
1565
                    break;
1566
                case 'photos':
1567
                    $item->setText(elgg_echo('gprofile:photos'));
1568
                    $item->addItemClass('removeMe');
1569
                    $item->setPriority('11');
1570
                    break;
1571
                case 'photo_albums':
1572
                    $item->setText(elgg_echo('gprofile:albumsCatch'));
1573
                    $item->setHref('#album');
1574
                    $item->setPriority('12');
1575
                    break;
1576
                case 'ideas':
1577
                    $item->setText(elgg_echo('gprofile:ideas'));
1578
                    $item->addItemClass('removeMe');
1579
                    $item->setPriority('12');
1580
                    break;
1581
1582
                case 'orgs':
1583
                    $item->setPriority('13');
1584
                    break;
1585
                case 'thewire':
1586
                    //$item->setText(elgg_echo('The Wire'));
1587
                    $item->setHref('#thewire');
1588
                    $item->setPriority('5');
1589
                    break;
1590
                case 'activity':
1591
                    $item->setText(elgg_echo('activity'));
1592
1593
                    $item->setPriority('13');
1594
                    $item->addItemClass('removeMe');
1595
                    break;
1596
                case 'user_invite_from_profile':
1597
                    $item->setPriority('13');
1598
                    break;
1599
								case 'questions':
1600
			              $item->setText(elgg_echo('widget:questions:title'));
1601
			              $item->setHref('#question');
1602
			              $item->setPriority('8');
1603
		                break;
1604
            }
1605
1606
        }
1607
1608
1609
1610
    }
1611
1612
1613
	//rearrange menu items
1614 View Code Duplication
	if (elgg_get_context() == 'profile') {
1615
		elgg_unregister_menu_item('owner_block', 'activity');
1616
1617
		//turn owner_block menu into tabs
1618
		foreach ($menu as $key => $item) {
1619
			switch ($item->getName()) {
1620
				case 'discussion':
1621
					$item->setText(elgg_echo('gprofile:discussion'));
1622
					$item->setPriority('1');
1623
					break;
1624
				case 'file':
1625
					$item->setText(elgg_echo('gprofile:files'));
1626
					$item->setHref('#file');
1627
					$item->setPriority('2');
1628
					break;
1629
				case 'blog':
1630
					$item->setText(elgg_echo('gprofile:blogs'));
1631
					$item->setHref('#blog');
1632
					$item->setPriority('3');
1633
					break;
1634
				case 'thewire':
1635
					$item->setHref('#thewire');
1636
					$item->setPriority('5');
1637
					break;
1638
				case 'event_calendar':
1639
					$item->setText(elgg_echo('gprofile:events'));
1640
					$item->setHref('#events');
1641
					$item->setPriority('6');
1642
					break;
1643
				case 'pages':
1644
					$item->setText(elgg_echo('gprofile:pages'));
1645
					$item->setHref('#page_top');
1646
					$item->setPriority('7');
1647
					break;
1648
				case 'bookmarks':
1649
					$item->setText(elgg_echo('gprofile:bookmarks'));
1650
					$item->setHref('#bookmarks');
1651
					$item->setPriority('8');
1652
					break;
1653
				case 'questions':
1654
					$item->setText(elgg_echo('widget:questions:title'));
1655
					$item->setHref('#question');
1656
					$item->setPriority('8');
1657
					break;
1658
				case 'polls':
1659
					$item->setText(elgg_echo('gprofile:polls'));
1660
					$item->setHref('#poll');
1661
					$item->setPriority('9');
1662
					break;
1663
				case 'tasks':
1664
					$item->setText(elgg_echo('gprofile:tasks'));
1665
					$item->setHref('#task_top');
1666
					$item->setPriority('10');
1667
					break;
1668
				case 'photos':
1669
					$item->setText(elgg_echo('gprofile:photos'));
1670
					$item->addItemClass('removeMe');
1671
					$item->setPriority('11');
1672
					break;
1673
				case 'photo_albums':
1674
					$item->setText(elgg_echo('gprofile:albumsCatch'));
1675
					$item->setHref('#album');
1676
					$item->setPriority('12');
1677
					break;
1678
				case 'ideas':
1679
					$item->setText(elgg_echo('gprofile:ideas'));
1680
					$item->addItemClass('removeMe');
1681
					$item->setPriority('12');
1682
					break;
1683
				case 'activity':
1684
					$item->setText('Activity');
1685
					$item->setPriority('13');
1686
					$item->addItemClass('removeMe');
1687
					break;
1688
				case 'user_invite_from_profile':
1689
				case 'orgs':
1690
					$item->setPriority('13');
1691
					break;
1692
			}
1693
		}
1694
	}
1695
}
1696
1697
/*
1698
 * river_handler
1699
 * Remove comment menu item
1700
 */
1701
function river_handler($hook, $type, $menu, $params)
1702
{
1703
}
1704
1705
/*
1706
 * wet4_dashboard_page_handler
1707
 * Override page handler for wet4 theme - dashboard
1708
 */
1709 View Code Duplication
function wet4_dashboard_page_handler()
1710
{
1711
	// Ensure that only logged-in users can see this page
1712
	elgg_gatekeeper();
1713
1714
	// Set context and title
1715
	elgg_set_context('dashboard');
1716
	elgg_set_page_owner_guid(elgg_get_logged_in_user_guid());
1717
	$title = elgg_echo('dashboard');
1718
1719
	// wrap intro message in a div
1720
	$intro_message = elgg_view('dashboard/blurb', array());
1721
1722
	$params = array(
1723
		'content' => $intro_message,
1724
		'num_columns' => 2,
1725
		'show_access' => false,
1726
	);
1727
	//use our own layouts for dashboard and stuff
1728
	$widgets = elgg_view_layout('db_widgets', $params);
1729
1730
	$body = elgg_view_layout('dashboard', array(
1731
		'title' => false,
1732
		'content' => $widgets
1733
	));
1734
1735
	echo elgg_view_page($title, $body);
1736
	return true;
1737
}
1738
1739
/*
1740
 * wet4_widget_menu_setup
1741
 * Override widget menu to use font awesome icons + add accessability
1742
 */
1743
function wet4_widget_menu_setup($hook, $type, $return, $params)
1744
{
1745
	$widget = $params['entity'];
1746
	$show_edit = elgg_extract('show_edit', $params, true);
1747
1748
	$options = array(
1749
		'name' => 'collapse',
1750
		'text' => '<i class="fa fa-lg icon-unsel"><span class="wb-inv">'. elgg_echo('wet:collapseWidget', array($widget->getTitle())).'</span></i> ',
1751
		'title' => elgg_echo('wet:collapseWidget', array($widget->getTitle())),
1752
		'href' => "#elgg-widget-content-$widget->guid",
1753
		'link_class' => 'elgg-widget-collapse-button ',
1754
		'rel' => 'toggle',
1755
		'priority' => 1,
1756
	);
1757
1758
	$return[] = \ElggMenuItem::factory($options);
1759
	if ($widget->canEdit()) {
1760
		$options = array(
1761
			'name' => 'delete',
1762
			'text' => '<i class="fa fa-trash-o fa-lg icon-unsel"><span class="wb-inv">'.elgg_echo('widget:delete', array($widget->getTitle())).'</span></i>',
1763
			'title' => elgg_echo('widget:delete', array($widget->getTitle())),
1764
			'href' => "action/widgets/delete?widget_guid=$widget->guid&context=" . $widget->getContainerGUID(),
1765
			'is_action' => true,
1766
			'link_class' => 'elgg-widget-delete-button',
1767
			'id' => "elgg-widget-delete-button-$widget->guid",
1768
			'data-elgg-widget-type' => $widget->handler,
1769
			'priority' => 900,
1770
		);
1771
		$return[] = \ElggMenuItem::factory($options);
1772
		// This is to maybe have a move button on widgets to move them with the keyboard.
1773
1774
		if ($show_edit) {
1775
			$options = array(
1776
				'name' => 'settings',
1777
				'text' => '<i class="fa fa-cog fa-lg icon-unsel"><span class="wb-inv">'.elgg_echo('widget:edit', array($widget->getTitle())).'</span></i>',
1778
				'title' => elgg_echo('widget:edit', array($widget->getTitle())),
1779
				'href' => "#widget-edit-$widget->guid",
1780
				'link_class' => "elgg-widget-edit-button",
1781
				'rel' => 'toggle',
1782
				'priority' => 800,
1783
			);
1784
			$return[] = \ElggMenuItem::factory($options);
1785
		}
1786
	}
1787
1788
	return $return;
1789
}
1790
1791
/*
1792
 * wet4_collections_page_handler
1793
 * Override page handler for wet4 theme - friend circles
1794
 */
1795
function wet4_collections_page_handler($page)
1796
{
1797
	$current_user = elgg_get_logged_in_user_entity();
1798
	if (!$current_user) {
1799
		register_error(elgg_echo('noaccess'));
1800
		elgg_get_session()->set('last_forward_from', current_page_url());
1801
		forward('');
1802
	}
1803
	elgg_set_context('friends');
1804
1805
	$base_dir = elgg_get_plugins_path() . 'wet4/pages/friends/collections';
1806
1807
	switch ($page[0]) {
1808
		case 'owner':
1809
			include("$base_dir/view.php");
1810
			break;
1811
		case 'add':
1812
			include("$base_dir/add.php");
1813
			break;
1814
		case 'edit':
1815
			include("$base_dir/edit.php");
1816
			break;
1817
		default:
1818
			return false;
1819
	}
1820
	return true;
1821
}
1822
1823
/*
1824
 * wet4_messages_page_handler
1825
 * Override page handler for wet4 theme - messages
1826
 */
1827 View Code Duplication
function wet4_messages_page_handler($page)
1828
{
1829
	$current_user = elgg_get_logged_in_user_entity();
1830
	if (!$current_user) {
1831
		register_error(elgg_echo('noaccess'));
1832
		elgg_get_session()->set('last_forward_from', current_page_url());
1833
		forward('');
1834
	}
1835
1836
	elgg_load_library('elgg:messages');
1837
1838
	elgg_push_breadcrumb(elgg_echo('messages'), 'messages/inbox/' . $current_user->username);
1839
1840
	if (!isset($page[0])) {
1841
		$page[0] = 'inbox';
1842
	}
1843
1844
	// Support the old inbox url /messages/<username>, but only if it matches the logged in user.
1845
	// Otherwise having a username like "read" on the system could confuse this function.
1846
	if ($current_user->username === $page[0]) {
1847
		$page[1] = $page[0];
1848
		$page[0] = 'inbox';
1849
	}
1850
1851
	if (!isset($page[1])) {
1852
		$page[1] = $current_user->username;
1853
	}
1854
1855
	$base_dir = elgg_get_plugins_path() . 'wet4/pages/messages';
1856
1857
	switch ($page[0]) {
1858
		case 'inbox':
1859
			set_input('username', $page[1]);
1860
			include("$base_dir/inbox.php");
1861
			break;
1862
		case 'notifications':
1863
			set_input('username', $page[1]);
1864
			include("$base_dir/notifications.php");
1865
			break;
1866
		case 'sent':
1867
			set_input('username', $page[1]);
1868
			include("$base_dir/sent.php");
1869
			break;
1870
		case 'read':
1871
			set_input('guid', $page[1]);
1872
			include("$base_dir/read.php");
1873
			break;
1874
		case 'compose':
1875
		case 'add':
1876
			include("$base_dir/send.php");
1877
			break;
1878
		default:
1879
			return false;
1880
	}
1881
	return true;
1882
}
1883
1884
/*
1885
 * enhanced_friendly_time_hook
1886
 *
1887
 * Friendly Time from GCconnex Codefest 2015 - 2016
1888
 *
1889
 * @author Nick
1890
 */
1891
function enhanced_friendly_time_hook($hook, $type, $return, $params)
1892
{
1893
	$diff = time() - ((int) $params['time']);
1894
	$newdate = date(  $params['time'] - 6 * 3600 );
1895
	//$timezone = get_input('new_timezone');
1896
	$user = elgg_get_logged_in_user_entity();
1897
		if ($user->new_timezone) {
1898
		$params['time'] = $newdate;
1899
		$timezone =$user->new_timezone;
1900
		$diff = time() - 6*3600 - ((int) $params['time']);
1901
	}
1902
	
1903
	$minute = 60;
1904
	$hour = $minute * 60;
1905
	$day = $hour * 24;
1906
1907
	if ($diff < $minute) {
1908
		$friendly_time = elgg_echo("friendlytime:justnow");
1909
	} elseif ($diff < $hour) {
1910
		$diff = round($diff / $minute);
1911
		if ($diff == 0) {
1912
			$diff = 1;
1913
		}
1914
1915
		if ($diff > 1) {
1916
			$friendly_time = elgg_echo("friendlytime:minutes", array($diff));
1917
		} else {
1918
			$friendly_time = elgg_echo("friendlytime:minutes:singular", array($diff));
1919
		}
1920
	} elseif ($diff < $day) {
1921
		$diff = round($diff / $hour);
1922
		if ($diff == 0) {
1923
			$diff = 1;
1924
		}
1925
1926
		if ($diff > 1) {
1927
			$friendly_time = elgg_echo("friendlytime:hours", array($diff));
1928
		} else {
1929
			$friendly_time = elgg_echo("friendlytime:hours:singular", array($diff));
1930
		}
1931
	} else {
1932
		$diff = round($diff / $day);
1933
		if ($diff == 0) {
1934
			$diff = 1;
1935
		}
1936
		//PHPlord let check for day, days, weeks and finally output date if too far away...
1937
		if ($diff == 1) {
1938
			$friendly_time = elgg_echo("friendlytime:days:singular", array($diff));
1939
		} elseif (6 >= $diff) {
1940
			$friendly_time = elgg_echo("friendlytime:days", array($diff));
1941
		} elseif (13 >= $diff) {
1942
			$friendly_time = elgg_echo("friendlytime:weeks:singular", array($diff));
1943
		} elseif ($diff == 14) {
1944
			$friendly_time = elgg_echo("friendlytime:weeks", array($diff));
1945
		} else {
1946
			$date_day = date('d', $params['time']);
1947
			$date_month = date('m', $params['time']);
1948
			$date_year = date('Y', $params['time']);
1949
			$date_hour = date('H', $params['time']);
1950
			$date_minute = date('i', $params['time']);
1951
			$friendly_time = $date_year . '-' . $date_month . '-' . $date_day . ' ' . $date_hour . ':' . $date_minute;
1952
		}
1953
	}
1954
1955
	$attributes = array();
1956
	$attributes['title'] = date(elgg_echo('friendlytime:date_format'), $params['time']);
1957
	$attributes['datetime'] = $timezone;
0 ignored issues
show
Bug introduced by
The variable $timezone 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...
1958
	
1959
	$attrs = elgg_format_attributes($attributes);
1960
1961
	return "<time $attrs>$friendly_time</time>";
1962
}
1963
1964
/**
1965
 * proper_subtypes
1966
 *
1967
 * Takes the subtypes and turns them into the plain language version of the subtype for menu items.
1968
 *
1969
 * @author Ethan Wallace
1970
 * @param string $type Entity subtype
1971
 * @return string Subtype
1972
 */
1973
function proper_subtypes($type)
1974
{
1975
	switch ($type) {
1976
		case 'page_top':
1977
		case 'page':
1978
			return elgg_echo('page');
1979
1980
		case 'thewire':
1981
			return elgg_echo('wire:post');
1982
1983
		case 'blog':
1984
			return elgg_echo('blog:blog');
1985
1986
		case 'comment':
1987
			return elgg_echo('comment');
1988
1989
		case 'groupforumtopic':
1990
			return elgg_echo('discussion');
1991
1992
		case 'discussion_reply':
1993
			return elgg_echo('group:replyitem');
1994
1995
		case 'file':
1996
			return elgg_echo('file:file');
1997
1998
		case 'folder':
1999
			return elgg_echo('item:object:folder');
2000
2001
		case 'event_calendar':
2002
			return elgg_echo('event_calendar:agenda:column:session');
2003
2004
		case 'bookmarks':
2005
			return elgg_echo('bookmark');
2006
2007
		case 'poll':
2008
			return elgg_echo('poll');
2009
2010
		case 'album':
2011
			return elgg_echo('album');
2012
2013
		case 'image':
2014
			return elgg_echo('image');
2015
2016
		case 'idea':
2017
			return elgg_echo('item:object:idea');
2018
2019
		case 'groups':
2020
			return elgg_echo('group:group');
2021
2022
		case 'question':
2023
			return elgg_echo('questions:edit:question:title');
2024
2025
		case 'answer':
2026
			return elgg_echo('questions:search:answer:title');
2027
	}
2028
2029
	return '';
2030
}
2031
2032
/**
2033
 * generate_hidden_text
2034
 *
2035
 * Takes the type and entity name to generate hidden text for entity/river menus
2036
 *
2037
 * @author Ethan Wallace
2038
 * @param string $type Entity subtype.
2039
 * @return array Contains different text for each menu item
2040
 */
2041
function generate_hidden_text($type, $name)
2042
{
2043
	$hiddenText = array();
2044
2045
	$lang = get_current_language();
2046
	$translated_name = gc_explode_translation($name, $lang);
2047
2048
	//create all unique menu items
2049
	switch ($type) {
2050
		case 'page_top':
2051
		case 'page':
2052
			$hiddenText['history'] = elgg_echo('entity:history:link:'.$type, array($translated_name));
2053
			break;
2054
2055
		case 'thewire':
2056
			$hiddenText['reply'] = elgg_echo('entity:reply:link:'.$type, array($translated_name));
2057
			break;
2058
2059
		case 'comment':
2060
			$hiddenText['comment'] = elgg_echo('entity:comment:link:'.$type, array($translated_name));
2061
			break;
2062
2063
		case 'groupforumtopic':
2064
			$hiddenText['lock'] = elgg_echo('entity:lock:link:'.$type, array($translated_nameame));
0 ignored issues
show
Bug introduced by
The variable $translated_nameame does not exist. Did you mean $translated_name?

This check looks for variables that are accessed but have not been defined. It raises an issue if it finds another variable that has a similar name.

The variable may have been renamed without also renaming all references.

Loading history...
2065
			$hiddenText['unlock'] = elgg_echo('entity:unlock:link:'.$type, array($translated_name));
2066
			break;
2067
2068
		case 'file':
2069
			$hiddenText['download'] = elgg_echo('entity:download:link:'.$type, array($translated_name));
2070
			break;
2071
2072
		case 'idea':
2073
			$hiddenText['upvote'] = elgg_echo('entity:upvote:link:'.$type, array($translated_name));
2074
			$hiddenText['downvote'] = elgg_echo('entity:downvote:link:'.$type, array($translated_name));
2075
			break;
2076
	}
2077
2078
	//default menus that ever item has
2079
	$hiddenText['like'] = elgg_echo('entity:like:link:'.$type, array($translated_name));
2080
	$hiddenText['unlike'] = elgg_echo('entity:unlike:link:'.$type, array($translated_name));
2081
	$hiddenText['edit'] = elgg_echo('entity:edit:link:'.$type, array($translated_name));
2082
	$hiddenText['delete'] = elgg_echo('entity:delete:link:'.$type, array($translated_name));
2083
	$hiddenText['share'] = elgg_echo('entity:share:link:'.$type, array($translated_name));
2084
	$hiddenText['subscribe'] = elgg_echo('entity:subscribe:link:'.$type, array($translated_name));
2085
2086
	return $hiddenText;
2087
}
2088
2089
/**
2090
 * embed_discussion_river
2091
 *
2092
 * Searches preview text of discussions to find video url to embed that video.
2093
 *
2094
 * @author Ethan Wallace
2095
 * @param string $desc Preview text from the discussion.
2096
 * @return string HTML to create embeded video
2097
 */
2098
function embed_discussion_river($desc)
2099
{
2100
	$patterns = array('#(((https://)?)|(^./))(((www.)?)|(^./))youtube\.com/watch[?]v=([^\[\]()<.,\s\n\t\r]+)#i'
2101
		,'#(((https://)?)|(^./))(((www.)?)|(^./))youtu\.be/([^\[\]()<.,\s\n\t\r]+)#i'
2102
		,'/(https:\/\/)?(www\.)?(vimeo\.com\/groups)(.*)(\/videos\/)([0-9]*)(\/)?/'
2103
		,'/(https:\/\/)(www\.)?(metacafe\.com\/watch\/)([0-9a-zA-Z_-]*)(\/[0-9a-zA-Z_-]*)(\/)/'
2104
		,'/(https:\/\/)?(www\.)?(vimeo.com\/)([^a-zA-Z][0-9]*)(\/)?/','/(https:\/\/)?(www\.)?(dailymotion.com\/video)([^a-zA-Z][0-9]*)(\/)?/'
2105
	);
2106
2107
	//Replace video providers with embebed content
2108
	foreach ($patterns as $pattern) {
2109
		if (preg_match_all($pattern, $desc, $matches)) {
2110
			$strAndPara = $matches[0];
2111
		}
2112
	}
2113
	return $strAndPara;
0 ignored issues
show
Bug introduced by
The variable $strAndPara 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...
2114
}
2115
2116
2117
/**
2118
 * Add a menu item to the topbar menu for logging out of an account
2119
 */
2120
function login_as_add_user_menu_link()
2121
{
2122
	$item = elgg_get_menu_item('topbar', 'login_as_return');
2123
2124
	if (isset($item)) {
2125
		$item->addLinkClass('no-style-link');
2126
		$item->addItemClass('login-as-out');
2127
		elgg_register_menu_item('user_menu', $item);
2128
	}
2129
}
2130
2131
/**
2132
 * Handles all question pages. Modified to add friends page
2133
 *
2134
 * @param array $segments
2135
 *
2136
 * @return bool
2137
 */
2138
function wet_questions_page_handler($segments)
2139
{
2140
	elgg_push_breadcrumb(elgg_echo('questions'), 'questions/all');
2141
2142
	$pages = 'mod/questions/pages/questions';
2143
	$new_page = 'mod/wet4/pages/questions';
2144 View Code Duplication
	switch ($segments[0]) {
2145
		case 'all':
2146
			include "$pages/all.php";
2147
			break;
2148
		case 'todo':
2149
			if (isset($segments[1]) && is_numeric($segments[1])) {
2150
				set_input('group_guid', $segments[1]);
2151
			}
2152
			include "$pages/todo.php";
2153
			break;
2154
		case 'owner':
2155
			if (isset($segments[1]) && is_numeric($segments[1])) {
2156
				elgg_set_page_owner_guid($segments[1]);
2157
			}
2158
			include "$pages/owner.php";
2159
			break;
2160
		case 'view':
2161
			set_input('guid', $segments[1]);
2162
			include "$new_page/view.php";
2163
			break;
2164
		case 'add':
2165
			elgg_gatekeeper();
2166
			include "$pages/add.php";
2167
			break;
2168
		case 'edit':
2169
			elgg_gatekeeper();
2170
			set_input('guid', $segments[1]);
2171
			include "$new_page/edit.php";
2172
			break;
2173
		case 'group':
2174
			elgg_group_gatekeeper();
2175
			include "$new_page/owner.php";
2176
			break;
2177
		case 'friends':
2178
			include "$new_page/friends.php";
2179
			break;
2180
		case 'experts':
2181
			if (isset($segments[1]) && is_numeric($segments[1])) {
2182
				elgg_set_page_owner_guid($segments[1]);
2183
			}
2184
			include "$pages/experts.php";
2185
			break;
2186
		default:
2187
			forward('questions/all');
2188
			return false;
2189
	}
2190
2191
	return true;
2192
}
2193
2194
/**
2195
 * Add menu items to the filter menu. Modified to remove filter menu from group context and add friends filter
2196
 *
2197
 * @param string         $hook   the name of the hook
2198
 * @param string         $type   the type of the hook
2199
 * @param ElggMenuItem[] $items  current return value
2200
 * @param array          $params supplied params
2201
 *
2202
 * @return void|ElggMenuItem[]
2203
 */
2204
function wet_questions_filter_menu_handler($hook, $type, $items, $params)
2205
{
2206
	if (empty($items) || !is_array($items) || !elgg_in_context('questions')) {
2207
		return;
2208
	}
2209
2210
	$page_owner = elgg_get_page_owner_entity();
2211
2212
	// change some menu items
2213
	foreach ($items as $key => $item) {
2214
		// add friends back into filter menu
2215
		if ($item->getName() == 'friend') {
2216
			$item->setHref("questions/friends");
2217
		}
2218
2219
		// in group context
2220
		if ($page_owner instanceof ElggGroup) {
2221
			// remove mine
2222
			if ($item->getName() == 'mine') {
2223
				unset($items[$key]);
2224
			}
2225
2226
			if ($item->getName() == 'friend') {
2227
				unset($items[$key]);
2228
			}
2229
2230
			// check if all is correct
2231
			if ($item->getName() === 'all') {
2232
				// remove filter menu in group context
2233
				unset($items[$key]);
2234
			}
2235
		}
2236
	}
2237
2238 View Code Duplication
	if (questions_is_expert()) {
2239
		$items[] = ElggMenuItem::factory([
2240
			'name' => 'todo',
2241
			'text' => elgg_echo('questions:menu:filter:todo'),
2242
			'href' => 'questions/todo',
2243
			'priority' => 700,
2244
		]);
2245
2246
		if ($page_owner instanceof ElggGroup) {
2247
			$items[] = ElggMenuItem::factory([
2248
				'name' => 'todo_group',
2249
				'text' => elgg_echo('questions:menu:filter:todo_group'),
2250
				'href' => "questions/todo/{$page_owner->getGUID()}",
2251
				'priority' => 710,
2252
			]);
2253
		}
2254
	}
2255
2256 View Code Duplication
	if (questions_experts_enabled()) {
2257
		$experts_href = 'questions/experts';
2258
		if ($page_owner instanceof ElggGroup) {
2259
			$experts_href .= "/{$page_owner->getGUID()}";
2260
		}
2261
2262
		$items[] = ElggMenuItem::factory([
2263
			'name' => 'experts',
2264
			'text' => elgg_echo('questions:menu:filter:experts'),
2265
			'href' => $experts_href,
2266
			'priority' => 800,
2267
		]);
2268
	}
2269
2270
	return $items;
2271
}
2272
2273
function wet_seo_friendly_urls($hook, $entity_type, $returnvalue, $params) {
2274
    $separator = "-";
2275
2276
    if ($entity_type == 'friendly:title') {
2277
        $title = $params['title'];
2278
2279
        // Pull in EN & FR titles
2280
        $title_en = gc_explode_translation($title, 'en');
2281
        $title_fr = gc_explode_translation($title, 'fr');
2282
2283
        // Combine EN & FR titles for URL (if exists)
2284
        if ($title_en !== "" && $title_fr !== "") {
2285
            if ($title_en !== $title_fr) {
2286
                $title = $title_en . $separator . $title_fr;
2287
            } else {
2288
                $title = $title_en;
2289
            }
2290
        } elseif ($title_en !== "") {
2291
            $title = $title_en;
2292
        } elseif ($title_fr !== "") {
2293
            $title = $title_fr;
2294
        }
2295
2296
        // Convert accented characters with regular equivalent
2297
        setlocale(LC_ALL, 'en_US.utf8');
2298
        $title = iconv('UTF-8', 'ASCII//TRANSLIT', $title);
2299
2300
        // Strip out special characters
2301
        $title = strip_tags($title);
2302
        $title = str_replace("'", "", $title);
2303
        $title = str_replace('"', "", $title);
2304
        $title = preg_replace('`\[.*\]`U', '', $title);
2305
        $title = preg_replace('`&(amp;)?#?[a-z0-9]+;`i', '', $title);
2306
2307
        // Add separator between words in URL string
2308
        $title = preg_replace(array("`[^a-z0-9]`i","`[-]+`") , $separator, $title);
2309
2310
        return trim(strtolower($title), $separator);
2311
    }
2312
}
2313