Completed
Push — solid-gold-duct-tape ( 649033 )
by
unknown
14:15
created

start.php ➔ wet4_group_entity_menu_setup()   B

Complexity

Conditions 8
Paths 7

Size

Total Lines 29

Duplication

Lines 0
Ratio 0 %

Importance

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