start.php ➔ wet4_elgg_entity_menu_setup()   F
last analyzed

Complexity

Conditions 50
Paths > 20000

Size

Total Lines 287

Duplication

Lines 49
Ratio 17.07 %

Importance

Changes 0
Metric Value
cc 50
nc 1524096
nop 4
dl 49
loc 287
rs 0
c 0
b 0
f 0

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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