Completed
Push — master ( 95b9d3...1cdd25 )
by
unknown
07:56
created

start.php ➔ wet4_group_entity_menu_setup()   B

Complexity

Conditions 10
Paths 7

Size

Total Lines 29

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 10
nc 7
nop 4
dl 0
loc 29
rs 7.6666
c 0
b 0
f 0

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