Passed
Push — jobs_rebrand ( 53961b )
by
unknown
18:57
created

start.php ➔ remove_menu_item_handler()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 7
nc 3
nop 4
dl 0
loc 12
rs 9.4285
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
		//error_log('is registered? '.elgg_is_menu_item_registered('subSite','Forum'));
14
		//elgg_unregister_menu_item('subSite','Forum');
15
16
	/* cyu - global change to sidebars, display when it is not the crawler
17
	 * the following batch of elgg_extend_view overwrites the elements in the page
18
	 */
19
	elgg_extend_view('page/elements/sidebar', 'page/elements/gsa_view_start', 1);
20
	elgg_extend_view('page/elements/sidebar', 'page/elements/gsa_view_end', 1000);
21
22
	elgg_extend_view('page/elements/footer', 'page/elements/gsa_view_start', 1);
23
	elgg_extend_view('page/elements/footer', 'page/elements/gsa_view_end', 1000);
24
25
	elgg_extend_view('navigation/breadcrumbs', 'page/elements/gsa_view_start', 1);
26
	elgg_extend_view('navigation/breadcrumbs', 'page/elements/gsa_view_end', 1000);
27
28
	elgg_extend_view('object/widget/elements/content', 'page/elements/gsa_view_start', 1);
29
	elgg_extend_view('object/widget/elements/content', 'page/elements/gsa_view_end', 1000);
30
31
	// cyu - are we overriding the settings page handler? (note: the one in this plugin does nothing)
32
	elgg_unregister_page_handler('settings');
33
	elgg_register_page_handler('settings', '_elgg_wet_user_settings_page_handler');
34
35
36
	//reload groups library to have our sidebar changes
37
38
	elgg_register_library('GCconnex_logging', elgg_get_plugins_path() . 'wet4/lib/logging.php');
39
	elgg_register_library('GCconnex_display_in_language', elgg_get_plugins_path() . 'wet4/lib/translate_display.php');
40
	elgg_register_library('wet:custom_core', elgg_get_plugins_path() . 'wet4/lib/custom_core.php');
41
42
	elgg_load_library('GCconnex_logging');
43
	elgg_load_library('GCconnex_display_in_language');
44
	elgg_load_library('wet:custom_core');
45
	//get rid of reply icon on river menu
46
	elgg_unregister_plugin_hook_handler('register', 'menu:river', 'discussion_add_to_river_menu');
47
48
	//change icons for blog entity
49
	elgg_unregister_plugin_hook_handler("register", "menu:entity", array("\ColdTrick\BlogTools\EntityMenu", "register"));
50
	elgg_register_plugin_hook_handler("register", "menu:entity", 'wet4_blog_entity_menu');
51
	//Friendly Time - Nick
52
	elgg_register_plugin_hook_handler('format', 'friendly:time', 'enhanced_friendly_time_hook');
53
	elgg_register_event_handler('pagesetup', 'system', 'wet4_theme_pagesetup', 1000);
54
	elgg_register_event_handler('pagesetup', 'system', 'wet4_riverItem_remove');
55
	elgg_register_event_handler('pagesetup', 'system', 'messages_notifier');
56
57
	elgg_register_plugin_hook_handler('register', 'menu:entity', 'wet4_elgg_entity_menu_setup');
58
	elgg_register_plugin_hook_handler('register', 'menu:widget', 'wet4_widget_menu_setup');
59
	elgg_register_plugin_hook_handler('register', 'menu:page', 'wet4_elgg_page_menu_setup');
60
	elgg_register_plugin_hook_handler('register', 'menu:river', 'wet4_elgg_river_menu_setup');
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
		switch ($item->getName()){
260
			case 'mission_main':
261
				unset($menu[$key]);
262
				break;
263
		}
264
	}
265
	return $menu;
266
267
}
268
269
global $CONFIG;
270
$dbprefix = elgg_get_config('dbprefix');
271
// user default access if enabled
272
if ($CONFIG->remove_logged_in) {
273
	$query = "UPDATE {$dbprefix}entities SET access_id = 2 WHERE access_id = 1";//change access logged in to public
274
	update_data($query);
275
}
276
277
function department_page_handler()
278
{
279
	require_once elgg_get_plugins_path() . 'wet4/pages/department/activity.php';
280
	return true;
281
}
282
283
/*
284
 * groups_autocomplete
285
 * loads library for groups autocomplete in group creation form
286
 */
287
function groups_autocomplete()
288
{
289
	require_once elgg_get_plugins_path() . 'wet4/lib/groups_autocomplete.php';
290
	return true;
291
}
292
293
294
295
296
function _elgg_wet_user_settings_page_handler($page)
297
{
298
	global $CONFIG;
299
300
	if (!isset($page[0])) {
301
		$page[0] = 'user';
302
	}
303
304 View Code Duplication
	if (isset($page[1])) {
305
		$user = get_user_by_username($page[1]);
306
		elgg_set_page_owner_guid($user->guid);
307
	} else {
308
		$user = elgg_get_logged_in_user_entity();
309
		elgg_set_page_owner_guid($user->guid);
310
	}
311
312
	elgg_push_breadcrumb(elgg_echo('settings'), "settings/user/$user->username");
313
314
	switch ($page[0]) {
315
		case 'notifications':
316
			elgg_push_breadcrumb(elgg_echo('cp_notifications:name'));
317
			$path = elgg_get_plugins_path() . "/cp_notifications/" . "pages/cp_notifications/notification_setting.php";
318
			break;
319
		case 'statistics':
320
			elgg_push_breadcrumb(elgg_echo('usersettings:statistics:opt:linktext'));
321
			$path = $CONFIG->path . "pages/settings/statistics.php";
322
			break;
323
		case 'user':
324
			$path = $CONFIG->path . "pages/settings/account.php";
325
			break;
326
	}
327
328
	if (isset($path)) {
329
		require $path;
330
		return true;
331
	}
332
	return false;
333
}
334
335
336
337
338
/*
339
 * activity_page_handler
340
 * Override activity page handler
341
 */
342
function activity_page_handler($page)
343
{
344
	elgg_set_page_owner_guid(elgg_get_logged_in_user_guid());
345
346
	// make a URL segment available in page handler script
347
	$page_type = elgg_extract(0, $page, 'all');
348
	$page_type = preg_replace('[\W]', '', $page_type);
349 View Code Duplication
	if ($page_type == 'owner') {
350
		elgg_gatekeeper();
351
		$page_username = elgg_extract(1, $page, '');
352
		if ($page_username == elgg_get_logged_in_user_entity()->username) {
353
			$page_type = 'mine';
354
		} else {
355
			set_input('subject_username', $page_username);
356
		}
357
	}
358
	set_input('page_type', $page_type);
359
	@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...
360
	return true;
361
}
362
363
364
/*
365
 * _elgg_set_landing_page
366
 * Sets landing page from user settings
367
 */
368
function _elgg_set_landing_page()
369
{
370
	$page = strip_tags(get_input('landingpage'));
371
	$user_guid = get_input('guid');
372
373
	if ($user_guid) {
374
		$user = get_user($user_guid);
375
	} else {
376
		$user = elgg_get_logged_in_user_entity();
377
	}
378
379
	if ($user && $user->canEdit() && $page) {
380
		if ($page != $user->name) {
381
			$user->landingpage = $page;
382
			if ($user->save()) {
383
				return true;
384
			}
385
		} else {
386
			// no change
387
			return null;
388
		}
389
	}
390
	return false;
391
}
392
393
394
395
/*
396
 * wet4_theme_pagesetup
397
 * Overrides various menu items to add font awesome icons, reorder items and add accessabilty
398
 */
399
function wet4_theme_pagesetup()
400
{
401
	if (elgg_is_logged_in()) {
402
		elgg_register_menu_item('topbar', array(
403
			'name' => 'account',
404
			'text' => elgg_echo('account'),
405
			'href' => "#",
406
			'priority' => 100,
407
			'section' => 'alt',
408
			'link_class' => 'elgg-topbar-dropdown',
409
		));
410
411 View Code Duplication
		if (elgg_is_active_plugin('dashboard')) {
412
			$item = elgg_unregister_menu_item('topbar', 'dashboard');
413
			if ($item) {
414
				$item->setText(elgg_echo('dashboard'));
415
				$item->setSection('default');
416
				elgg_register_menu_item('site', $item);
417
			}
418
		}
419
420
		$item = elgg_get_menu_item('topbar', 'usersettings');
421
		if ($item) {
422
			$item->setParentName('account');
423
			$item->setText(elgg_echo('settings'));
424
			$item->setPriority(103);
425
		}
426
427
		$item = elgg_get_menu_item('topbar', 'logout');
428
		if ($item) {
429
			$item->setParentName('account');
430
			$item->setText(elgg_echo('logout'));
431
			$item->setPriority(104);
432
		}
433
434
		$item = elgg_get_menu_item('topbar', 'administration');
435
		if ($item) {
436
			$item->setParentName('account');
437
			$item->setText(elgg_echo('admin'));
438
			$item->setPriority(101);
439
		}
440
441
		if (elgg_is_active_plugin('site_notifications')) {
442
			$item = elgg_get_menu_item('topbar', 'site_notifications');
443
			if ($item) {
444
				$item->setParentName('account');
445
				$item->setText(elgg_echo('site_notifications:topbar'));
446
				$item->setPriority(102);
447
			}
448
		}
449
450 View Code Duplication
		if (elgg_is_active_plugin('reportedcontent')) {
451
			$item = elgg_unregister_menu_item('footer', 'report_this');
452
			if ($item) {
453
				$item->setText(elgg_view_icon('report-this'));
454
				$item->setPriority(500);
455
				$item->setSection('default');
456
				elgg_register_menu_item('extras', $item);
457
			}
458
		}
459
460
461
		//style colleague requests tab
462
		$context = elgg_get_context();
463
		$page_owner = elgg_get_page_owner_entity();
464
465
		if (elgg_is_logged_in()) {
466
			$user = elgg_get_logged_in_user_guid();
467
		}
468
469
		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...
470
			// Show menu link in the correct context
471
			if (in_array($context, array("friends", "friendsof", "collections"))) {
472
				$options = array(
473
					"type" => "user",
474
					"count" => true,
475
					"relationship" => "friendrequest",
476
					"relationship_guid" => $page_owner->getGUID(),
477
					"inverse_relationship" => true
478
				);
479
480
				$count = elgg_get_entities_from_relationship($options);
481
				$extra = "";
482
				if (!empty($count)) {
483
					$extra = '<span aria-hidden="true" class="notif-badge">' . $count . '</span>';
484
				}
485
486
				// add menu item
487
				$menu_item = array(
488
					"name" => "friend_request",
489
					"text" => elgg_echo("friend_request:menu") . $extra,
490
					"href" => "friend_request/" . $page_owner->username,
491
					"contexts" => array("friends", "friendsof", "collections")
492
				);
493
494
				elgg_register_menu_item("page", $menu_item);
495
			}
496
		}
497
498
		if (elgg_in_context('messages')) {
499
			elgg_unregister_menu_item("page", "friend_request");
500
		}
501
	}
502
503
504
	/*
505
	 *    Control colleague requests in topbar menu
506
	 *    taken from friend_request module
507
	 *    edited to place badge on colleagues instead of creating new icon
508
	 */
509
	$user = elgg_get_logged_in_user_entity();
510
511
	$params = array(
512
		"name" => "Colleagues",
513
		"href" => "friends/" . $user->username,
514
		"text" => '<i class="fa fa-users mrgn-rght-sm mrgn-tp-sm fa-lg"></i><span class="hidden-xs">' . elgg_echo("userMenu:colleagues") . '</span>',
515
		"title" => elgg_echo('userMenu:colleagues'),
516
		"class" => '',
517
		'item_class' => '',
518
		'priority' => '1'
519
	);
520
521
	elgg_register_menu_item("user_menu", $params);
522
523
524
	$context = elgg_get_context();
525
	$page_owner = elgg_get_page_owner_entity();
526
527
	// Remove link to friendsof
528
	elgg_unregister_menu_item("page", "friends:of");
529
530
	// Settings notifications tab in the User's setting page
531
	// cyu - allow site administrators to view user notification settings page
532
	elgg_unregister_menu_item('page', '2_a_user_notify');
533
	if ($page_owner instanceof ElggUser) {
534
		$params = array(
535
			"name" => "2_a_user_notify",
536
			"href" => "/settings/notifications/{$page_owner->username}",
537
			"text" => elgg_echo('notifications:subscriptions:changesettings'),
538
			'section' => 'configure',
539
			'priority' => '100',
540
			'context' => 'settings',
541
		);
542
	}
543
544
545
	elgg_register_menu_item("page", $params);
546
547
	if (!empty($user)) {
548
		$options = array(
549
			"type" => "user",
550
			"count" => true,
551
			"relationship" => "friendrequest",
552
			"relationship_guid" => $user->getGUID(),
553
			"inverse_relationship" => true
554
		);
555
556
		$count = elgg_get_entities_from_relationship($options);
557
		if (!empty($count)) {
558
			$countTitle = $count;
559
560
			//display 9+ instead of huge numbers in notif badge
561
			if ($count >= 10) {
562
				$count = '9+';
563
			}
564
565
			$params = array(
566
				"name" => "Colleagues",
567
				"href" => "friends/" . $user->username,
568
				"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>",
569
				"title" => elgg_echo('userMenu:colleagues') . ' - ' . $countTitle . ' ' . elgg_echo('friend_request') .'(s)',
570
				"class" => '',
571
				'item_class' => '',
572
				'priority' => '1'
573
			);
574
575
			elgg_register_menu_item("user_menu", $params);
576
577
			//topbar
578
579
			$params = array(
580
				"name" => "friends",
581
				"href" => "friends/" . $user->username,
582
				"text" => elgg_echo("friends") . "<span class='badge'>" . $count . "</span>",
583
				"title" => elgg_echo('friends') . ' - Requests(' . $count .')',
584
				"class" => 'friend-icon',
585
			);
586
587
			elgg_register_menu_item("topbar", $params);
588
		}
589
	}
590
591
592
593
	//likes and stuff yo
594
	$item = elgg_get_menu_item('entity', 'likes');
595
	if ($item) {
596
		$item->setText('likes');
597
		$item->setItemClass('msg-icon');
598
	}
599
600
	$item = elgg_get_menu_item('entity', 'delete');
601
	if ($item) {
602
		echo '<div> What that mean?</div>';
603
	}
604
605 View Code Duplication
	if (elgg_is_logged_in() && elgg_get_config('allow_registration')) {
606
		$params = array(
607
				'name' => 'invite',
608
				'text' => elgg_echo('friends:invite'),
609
				'href' => "invite/". $user->username,
610
				'contexts' => array('friends'),
611
				'priority' => 300,
612
			);
613
		elgg_register_menu_item('page', $params);
614
	}
615
616
617
	//new folder button for files
618
619 View Code Duplication
	if (elgg_is_logged_in()) {
620
		$user = elgg_get_logged_in_user_entity();
621
		if ($user->canEdit()) {
622
			$params = array(
623
				'name' => 'new_folder',
624
				'text' => elgg_echo("file_tools:new:title"),
625
				'href' => "#",
626
				"id" => "file_tools_list_new_folder_toggle",
627
				'item_class' => 'mrgn-lft-sm',
628
				'context' => 'file',
629
			);
630
			elgg_register_menu_item('title2', $params);
631
		}
632
	}
633
}
634
635
636
637
/**
638
 * Register items for the html head
639
 *
640
 * @param string $hook Hook name ('head')
641
 * @param string $type Hook type ('page')
642
 * @param array  $data Array of items for head
643
 * @return array
644
 */
645
function wet4_theme_setup_head($hook, $type, $data)
646
{
647
	$data['metas']['viewport'] = array(
648
		'name' => 'viewport',
649
		'content' => 'width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0',
650
	);
651
652
    if( file_exists('mod/wet4_theme/graphics/homescreen.png') ){
653
    	$data['links']['apple-touch-icon'] = array(
654
    		'rel' => 'apple-touch-icon',
655
    		'href' => elgg_normalize_url('mod/wet4_theme/graphics/homescreen.png'),
656
    	);
657
    }
658
659
	return $data;
660
}
661
662
/*
663
 * wet4_likes_entity_menu_setup
664
 * Override likes entity menu to include font awesome icons and add accessability
665
 */
666
function wet4_likes_entity_menu_setup($hook, $type, $return, $params)
667
{
668
	// make the widget view produce the same entity menu as the other objects
669
670
	$entity = $params['entity'];
671
	$lang = get_current_language();
672
	$entContext = $entity->getType();
673
674
	//check if entity is an object or group
675 View Code Duplication
	if ($entContext == 'object') {
676
677
		//find subtype
678
		$contentType = $entity->getSubtype();
679
		//convert subtype into plain language
680
		$entContext = proper_subtypes($contentType);//$entity->getSubtype();
681
682
		//check to see if entity is one f the entities with a title
683
		if (!in_array($entity->getSubtype(), array('comment', 'discussion_reply', 'thewire'))) {
684
			if ($entity->title3) {
685
				$entName = gc_explode_translation($entity->title3, $lang);
686
			} else {
687
				$entName = $entity->title;
688
			}
689
		} else { //if not get owner instead of name
690
691
			$entName = $entity->getOwnerEntity()->name;
692
		}
693
	} elseif ($entContext == 'group') {
694
		$contentType = 'group';
695
		$entContext = elgg_echo('group');
696
		if ($entity->title3) {
697
			$entName = gc_explode_translation($entity->title3, $lang);
698
		} else {
699
			$entName = $entity->name;
700
		}
701
	}
702
703
	if ($entity->canAnnotate(0, 'likes')) {
704
		$hasLiked = \Elgg\Likes\DataService::instance()->currentUserLikesEntity($entity->guid);
705
706
		//pass type and entiey/owner name to function to return array of text
707
		$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...
708
709
		// Always register both. That makes it super easy to toggle with javascript
710
		$return[] = ElggMenuItem::factory(array(
711
			'name' => 'likes',
712
			'href' => elgg_add_action_tokens_to_url("/action/likes/add?guid={$entity->guid}"),
713
			'text' => '<i class="fa fa-thumbs-up fa-lg icon-unsel"></i><span class="wb-inv">'.$hiddenText['like'].'</span>',
714
			'title' => elgg_echo('likes:likethis') . ' ' . $entContext,
715
			'item_class' => $hasLiked ? 'hidden' : '',
716
			'priority' => 998,
717
		));
718
		$return[] = ElggMenuItem::factory(array(
719
			'name' => 'unlike',
720
			'href' => elgg_add_action_tokens_to_url("/action/likes/delete?guid={$entity->guid}"),
721
			'text' => '<i class="fa fa-thumbs-up fa-lg icon-sel"></i><span class="wb-inv">'.$hiddenText['unlike'].'</span>',
722
			'title' => elgg_echo('likes:remove') . ' ' . $entContext,
723
			'item_class' => $hasLiked ? 'pad-rght-xs' : 'hidden',
724
			'priority' => 998,
725
		));
726
	}
727
728
	// likes count
729
	$count = elgg_view('likes/count', array('entity' => $entity));
730 View Code Duplication
	if ($count) {
731
		$options = array(
732
			'name' => 'likes_count',
733
			'text' => $count,
734
			'href' => false,
735
			'priority' => 999,
736
			'item_class' => 'entity-menu-bubble',
737
		);
738
		$return[] = ElggMenuItem::factory($options);
739
	}
740
741
	return $return;
742
}
743
744
745
/*
746
 * wet4_elgg_page_menu_setup
747
 * Override page menu on user settings page
748
 */
749
function wet4_elgg_page_menu_setup($hook, $type, $return, $params)
750
{
751
	if (elgg_in_context('settings')) {
752
		$user = elgg_get_page_owner_entity();
753
754
		$dropdown = '<ul class="dropdown-menu pull-right subMenu">';
755
756
		$active_plugins = elgg_get_plugins();
757
758
		foreach ($active_plugins as $plugin) {
759
			$plugin_id = $plugin->getID();
760
			if (elgg_view_exists("usersettings/$plugin_id/edit") || elgg_view_exists("plugins/$plugin_id/usersettings")) {
761
				$params = array(
762
					'name' => $plugin_id,
763
					'text' => $plugin->getFriendlyName(),
764
					'href' => "settings/plugins/{$user->username}/$plugin_id",
765
				);
766
767
				$dropdown .= '<li><a href="' . elgg_get_site_url() . 'settings/plugins/' . $user->username . '/' . $plugin_id . '">' . $plugin->getFriendlyName() . '</a></li>';
768
			}
769
		}
770
771
		$dropdown .= '</ul>';
772
773
		return $return;
774
	}
775
}
776
777
/*
778
 * wet4_blog_entity_menu
779
 * Override blog entity menu to include font awesome icons and add accessability
780
 */
781
function wet4_blog_entity_menu($hook, $entity_type, $returnvalue, $params)
782
{
783
	if (empty($params) || !is_array($params)) {
784
		return $returnvalue;
785
	}
786
787
	$lang = get_current_language();
788
789
	$entity = elgg_extract("entity", $params);
790
	if (empty($entity) || !elgg_instanceof($entity, "object", "blog")) {
791
		return $returnvalue;
792
	}
793
794
	if ($entity->title3) {
795
		$entName = gc_explode_translation($entity->title3, $lang);
796
	} else {
797
		$entName = $entity->title;
798
	}
799
800
	// only published blogs
801
	if ($entity->status == "draft") {
802
		return $returnvalue;
803
	}
804
805 View Code Duplication
	if (!elgg_in_context("widgets") && elgg_is_admin_logged_in()) {
806
		$returnvalue[] = \ElggMenuItem::factory(array(
807
			"name" => "blog-feature",
808
			"text" => elgg_echo("blog_tools:toggle:feature"),
809
			"href" => "action/blog_tools/toggle_metadata?guid=" . $entity->getGUID() . "&metadata=featured",
810
			"item_class" => empty($entity->featured) ? "" : "hidden",
811
			"is_action" => true,
812
			"priority" => 175
813
		));
814
		$returnvalue[] = \ElggMenuItem::factory(array(
815
			"name" => "blog-unfeature",
816
			"text" => elgg_echo("blog_tools:toggle:unfeature"),
817
			"href" => "action/blog_tools/toggle_metadata?guid=" . $entity->getGUID() . "&metadata=featured",
818
			"item_class" => empty($entity->featured) ? "hidden" : "",
819
			"is_action" => true,
820
			"priority" => 176
821
		));
822
	}
823
824
	if ($entity->canComment()) {
825
		$returnvalue[] = \ElggMenuItem::factory(array(
826
			"name" => "comments",
827
			"text" => '<i class="fa fa-lg fa-comment icon-unsel"><span class="wb-inv">' . elgg_echo("entity:comment:link:blog", array($entName)) . '</span></i>',
828
			"title" => elgg_echo("comment:this"),
829
			"href" => $entity->getURL() . "#comments"
830
		));
831
	}
832
833
	return $returnvalue;
834
}
835
836
/*
837
 * my_owner_block_handler
838
 * Override owner_block menu to become tabs in profile
839
 */
840
function wet4_elgg_entity_menu_setup($hook, $type, $return, $params)
841
{
842
	//Have widgets show the same entity menu
843
844
	$entity = $params['entity'];
845
	$lang = get_current_language();
846
	/* @var \ElggEntity $entity */
847
	$handler = elgg_extract('handler', $params, false);
848
849
	//Nick -Remove empty comment and reply links from river menu
850
	foreach ($return as $key => $item) {
851
		if ($item->getName() == 'access') {
852
			unset($return[$key]);
853
		}
854
	}
855
856
	$entContext = $entity->getType();
857
858
	//check if entity is an object or group
859 View Code Duplication
	if ($entContext == 'object') {
860
861
		//find subtype
862
		$contentType = $entity->getSubtype();
863
		//convert subtype into plain language
864
		$entContext = proper_subtypes($contentType);
865
866
		//check to see if entity is one f the entities with a title
867
		if (!in_array($entity->getSubtype(), array('comment', 'discussion_reply', 'thewire', 'answer'))) {
868
			if ($entity->title3) {
869
				$entName = gc_explode_translation($entity->title3, $lang);
870
			} else {
871
				$entName = $entity->title;
872
			}
873
		} else { //if not get owner instead of name
874
875
			$entName = $entity->getOwnerEntity()->name;
876
		}
877
	} elseif ($entContext == 'group') {
878
		$contentType = 'group';
879
		$entContext = elgg_echo('group');
880
		if ($entity->title3) {
881
			$entName = gc_explode_translation($entity->title3, $lang);
882
		} else {
883
			$entName = $entity->name;
884
		}
885
	}
886
887
	//pass type and entiey/owner name to function to return array of text
888
	$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...
889
890
891
	$blocked_subtypes = array('comment', 'discussion_reply');
892
	if (in_array($entity->getSubtype(), $blocked_subtypes) || elgg_instanceof($entity, 'user')) {
0 ignored issues
show
Unused Code introduced by
This if statement is empty and can be removed.

This check looks for the bodies of if statements that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.

These if bodies can be removed. If you have an empty if but statements in the else branch, consider inverting the condition.

if (rand(1, 6) > 3) {
//print "Check failed";
} else {
    print "Check succeeded";
}

could be turned into

if (rand(1, 6) <= 3) {
    print "Check succeeded";
}

This is much more concise to read.

Loading history...
893
		//do not let comments or discussion replies to be reshared on the wire
894
	} else {
895
		// check is this item was shared on thewire
896
		$count = $entity->getEntitiesFromRelationship(array(
897
			'type' => 'object',
898
			'subtype' => 'thewire',
899
			'relationship' => 'reshare',
900
			'inverse_relationship' => true,
901
			'count' => true
902
		));
903
904
		if ($count) {
905
			if ($count >=2) {
906
				$share = elgg_echo('thewire:shares');
907
			} else {
908
				$share = elgg_echo('thewire:share');
909
			}
910
911
			// show counter
912
			$return[] = \ElggMenuItem::factory(array(
913
				'name' => 'thewire_tools_reshare_count',
914
				'text' => $count . $share,
915
				'title' => elgg_echo('thewire_tools:reshare:count'),
916
				'href' => 'ajax/view/thewire_tools/reshare_list?entity_guid=' . $entity->getGUID(),
917
				'link_class' => 'elgg-lightbox',
918
				'item_class' => ' entity-menu-bubble',
919
				'is_trusted' => true,
920
				'priority' => 501,
921
				'data-colorbox-opts' => json_encode(array(
922
					'maxHeight' => '85%'
923
				))
924
			));
925
		}
926
927
928
		if (elgg_is_logged_in()) {
929
			//reshare on the wire
930
			$options = array(
931
				'name' => 'thewire_tools_reshare',
932
				'text' => '<i class="fa fa-share-alt fa-lg icon-unsel"><span class="wb-inv">'.$hiddenText['share'].'</span></i>',
933
				'title' => elgg_echo('thewire_tools:reshare'),
934
				'href' => 'ajax/view/thewire_tools/reshare?reshare_guid=' . $entity->getGUID(),
935
				'link_class' => 'elgg-lightbox',
936
				'item_class' => '',
937
				'is_trusted' => true,
938
				'priority' => 500
939
			);
940
			$return[] = \ElggMenuItem::factory($options);
941
		} else {
942
			$options = array(
943
				'name' => 'thewire_tools_reshare',
944
				'text' => '',
945
				'item_class' => 'removeMe',
946
			);
947
			$return[] = \ElggMenuItem::factory($options);
948
		}
949
	}
950
951
	//only show reply on the wire with logged in user
952
	if ($entity->getSubtype() == 'thewire' && elgg_is_logged_in()) {
953
		$options = array(
954
			'name' => 'reply',
955
			'text' => '<i class="fa fa-reply fa-lg icon-unsel"><span class="wb-inv">'.$hiddenText['reply'].'</span></i>',
956
			'title' => elgg_echo('reply'),
957
			'href' => 'ajax/view/thewire_tools/reply?guid=' . $entity->getGUID(),
958
			'link_class' => 'elgg-lightbox',
959
			'is_trusted' => true,
960
			'priority' => 100
961
		);
962
		$return[] = \ElggMenuItem::factory($options);
963
	}
964
965
	if (($entity->countEntitiesFromRelationship("parent") || $entity->countEntitiesFromRelationship("parent", true))) {
966
                $options = array(
967
                    'name' => 'thread',
968
                    'text' => elgg_echo('thewire:thread'),
969
                    'href' => 'ajax/view/thewire_tools/thread?thread_id=' . $entity->wire_thread,
970
                    'link_class' => 'elgg-lightbox',
971
                    'is_trusted' => true,
972
                    'priority' => 170,
973
                );
974
                $return[] = ElggMenuItem::factory($options);
975
            }
976
  
977
	if ($entity->canEdit() && $handler) {
978
        //checks so the edit icon is not placed on incorrect entities
979
      if($handler != 'group_operators'){
980
            if($entity->getSubtype() != 'thewire' && $entity->getSubtype() != 'discussion_reply'){
981
                $options = array(
982
                    'name' => 'edit',
983
                    'text' => '<i class="fa fa-edit fa-lg icon-unsel"><span class="wb-inv">'.$hiddenText['edit'].'</span></i>',
984
                    'title' => elgg_echo('edit:this') . ' ' . $entContext,
985
                    'href' => "$handler/edit/{$entity->getGUID()}",
986
                    'priority' => 299,
987
                );
988
                $return[] = \ElggMenuItem::factory($options);
989
            }
990
		// delete link
991
992
            if (elgg_is_logged_in() && $entity->getSubtype() != 'discussion_reply'){
993
            		$options = array(
994
            			'name' => 'delete',
995
            			'text' => '<i class="fa fa-trash-o fa-lg icon-unsel"><span class="wb-inv">'.$hiddenText['delete'].'</span></i>',
996
            			'title' => elgg_echo('delete:this') . ' ' . $entContext,
997
            			'href' => "action/$handler/delete?guid={$entity->getGUID()}",
998
            			'confirm' => elgg_echo('deleteconfirm'),
999
            			'priority' => 300,
1000
            		);
1001
            		$return[] = \ElggMenuItem::factory($options);
1002
                    }
1003
1004
            if (elgg_is_logged_in()){
1005
                $user = elgg_get_logged_in_user_entity();
1006
                $page_owner = elgg_get_page_owner_entity();
1007
                if($entity->getSubtype() == 'discussion_reply' ){
1008
                    if($entity->owner_guid == $user['guid'] || elgg_is_admin_logged_in() || ($page_owner instanceof ElggGroup && $page_owner->getOwnerGUID() == $user['guid']) || $page_owner->canEdit()){
1009
                    $options = array(
1010
                    'name' => 'edit',
1011
                    'text' => '<i class="fa fa-edit fa-lg icon-unsel"><span class="wb-inv">'.$hiddenText['edit'].'</span></i>',
1012
                    'title' => elgg_echo('edit:this') . ' ' . $entContext,
1013
                    'href' => "$handler/edit/{$entity->getGUID()}",
1014
                    'priority' => 299,
1015
                );
1016
                $return[] = \ElggMenuItem::factory($options);
1017
1018
                    $options = array(
1019
                        'name' => 'delete',
1020
                        'text' => '<i class="fa fa-trash-o fa-lg icon-unsel"><span class="wb-inv">'.$hiddenText['delete'].'</span></i>',
1021
                        'title' => elgg_echo('delete:this') . ' ' . $entContext,
1022
                        'href' => "action/$handler/delete?guid={$entity->getGUID()}",
1023
                        'confirm' => elgg_echo('deleteconfirm'),
1024
                        'priority' => 300,
1025
                    );
1026
                    $return[] = \ElggMenuItem::factory($options);
1027
                    }
1028
                }
1029
            }
1030
        }
1031
    }
1032
1033 View Code Duplication
    if($entity->getSubType() == 'file'){
1034
        // download link
1035
		$options = array(
1036
			'name' => 'download',
1037
			'text' => '<i class="fa fa-download fa-lg icon-unsel"><span class="wb-inv">'.$hiddenText['download'].'</span></i>',
1038
			'title' => 'Download File',
1039
			'href' => "file/download/{$entity->getGUID()}",
1040
			'priority' => 300,
1041
		);
1042
		$return[] = \ElggMenuItem::factory($options);
1043
	}
1044
1045
1046 View Code Duplication
	if ($entity->getSubType() == 'page_top') {
1047
		//history icon
1048
		$options = array(
1049
			'name' => 'history',
1050
			'text' => '<i class="fa fa-history fa-lg icon-unsel"><span class="wb-inv">' . $hiddenText['history'] . '</span></i>',
1051
			'title'=> elgg_echo('pages:history'),
1052
			'href' => "pages/history/$entity->guid",
1053
			'priority' => 150,
1054
		);
1055
		$return[] = \ElggMenuItem::factory($options);
1056
	}
1057
1058
	//opening and close dicussions
1059
	if (elgg_instanceof($entity, "object", "groupforumtopic") && $entity->canEdit() && elgg_is_active_plugin('group_tools')) {
1060
		$return[] = ElggMenuItem::factory(array(
1061
			"name" => "status_change_open",
1062
			"text" => '<i class="fa fa-lock fa-lg icon-unsel"><span class="wb-inv">'.$hiddenText['unlock'].'</span></i>',
1063
			"confirm" => elgg_echo("group_tools:discussion:confirm:open"),
1064
			"href" => "action/discussion/toggle_status?guid=" . $entity->getGUID(),
1065
			"is_trusted" => true,
1066
			"title" => "Open the topic",
1067
			"priority" => 200,
1068
			"item_class" => ($entity->status == "closed") ? "" : "hidden"
1069
		));
1070
		$return[] = ElggMenuItem::factory(array(
1071
			"name" => "status_change_close",
1072
			"text" => '<i class="fa fa-unlock fa-lg icon-unsel"><span class="wb-inv">'.$hiddenText['lock'].'</span></i>',
1073
			"confirm" => elgg_echo("group_tools:discussion:confirm:close"),
1074
			"href" => "action/discussion/toggle_status?guid=" . $entity->getGUID(),
1075
			"is_trusted" => true,
1076
			"title" => "Close the topic",
1077
			"priority" => 201,
1078
			"item_class" => ($entity->status == "closed") ? "hidden" : ""
1079
		));
1080
	}
1081
1082
	//style comment for Questions mod and switch to FA icon
1083
	if ($entity->canComment()) {
1084
		if (elgg_extract('full_view', $params, false) || ($entity instanceof ElggAnswer)) {
1085
			$options = array(
1086
				'name' => 'comments',
1087
				"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>',
1088
				"title" => elgg_echo("comment:this") . ' ' . $entContext,
1089
				'href' => "#comments-add-{$entity->getGUID()}",
1090
				'priority' => 288,
1091
				'rel' => 'toggle'
1092
			);
1093
			$return[] = \ElggMenuItem::factory($options);
1094
		}
1095
	}
1096
1097
	return $return;
1098
}
1099
1100
/*
1101
 * _wet4_friends_page_handler
1102
 * Override friends page handler to use wet4 pages
1103
 */
1104
function _wet4_friends_page_handler($page, $handler)
1105
{
1106
	//change the page handler for friends to user our own pages. This increases the limit of friends for data table parsing and such :)
1107
	elgg_set_context('friends');
1108
1109 View Code Duplication
	if (isset($page[0]) && $user = get_user_by_username($page[0])) {
1110
		elgg_set_page_owner_guid($user->getGUID());
1111
	}
1112
1113
	if (!elgg_get_page_owner_guid()) {
1114
		return false;
1115
	}
1116
	$plugin_path = elgg_get_plugins_path();
1117
	switch ($handler) {
1118
		case 'friends':
1119
			//use the pages in our theme instead of the core pages
1120
			require($plugin_path ."wet4/pages/friends/index.php");
1121
			break;
1122
		case 'friendsof':
1123
			require($plugin_path ."wet4/pages/friends/of.php");
1124
			break;
1125
		default:
1126
			return false;
1127
	}
1128
	return true;
1129
}
1130
1131
/*
1132
 * wet4_riverItem_remove
1133
 * Remove unwanted river items
1134
 */
1135
function wet4_riverItem_remove()
1136
{
1137
	elgg_unregister_menu_item('river', 'comment');
1138
	elgg_unregister_menu_item('river', 'reply');
1139
}
1140
1141
/*
1142
 * wet4_elgg_river_menu_setup
1143
 * Override river menu to use font awesome icons + add accessability
1144
 */
1145
function wet4_elgg_river_menu_setup($hook, $type, $return, $params)
1146
{
1147
	if (elgg_is_logged_in()) {
1148
		$item = $params['item'];
1149
		$object = $item->getObjectEntity();
1150
		$lang = get_current_language();
1151
		// add comment link but annotations cannot be commented on
1152
1153
		if (!$object || !$object->canAnnotate(0, 'likes')) {
1154
			return;
1155
		}
1156
		//Nick -Remove empty comment and reply links from river menu
1157
		foreach ($return as $key => $item) {
1158
			switch ($item->getName()) {
1159
				case 'comment':
1160
				case 'reply':
1161
					unset($return[$key]);
1162
					break;
1163
			}
1164
		}
1165
1166
		$entContext = $object->getType();
1167
		//check if entity is an object or group
1168 View Code Duplication
		if ($entContext == 'object') {
1169
1170
			//find subtype
1171
			$contentType = $object->getSubtype();
1172
			//convert subtype into plain language
1173
			$entContext = proper_subtypes($contentType);
1174
1175
			//check to see if entity is one f the entities with a title
1176
			if (!in_array($object->getSubtype(), array('comment', 'discussion_reply', 'thewire', 'answer'))) {
1177
				if ($object->title3) {
1178
					$entName = gc_explode_translation($object->title3, $lang);
1179
				} else {
1180
					$entName = $object->title;
1181
				}
1182
			} else { //if not get owner instead of name
1183
				$entName = $object->getOwnerEntity()->name;
1184
			}
1185
		} elseif ($entContext == 'group') {
1186
			$contentType = 'group';
1187
			$entContext = elgg_echo('group');
1188
			if ($object->title3) {
1189
				$entName = gc_explode_translation($object->title3, $lang);
1190
			} else {
1191
				$entName = $object->name;
1192
			}
1193
		}
1194
1195
		//pass type and entiey/owner name to function to return array of text
1196
		$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...
1197
1198
		if ($entContext != 'user') {
1199
			$hasLiked = \Elgg\Likes\DataService::instance()->currentUserLikesEntity($object->guid);
1200
1201
			// Always register both. That makes it super easy to toggle with javascript
1202
			$return[] = ElggMenuItem::factory(array(
1203
				'name' => 'likes',
1204
				'href' => elgg_add_action_tokens_to_url("/action/likes/add?guid={$object->guid}"),
1205
				'text' => '<i class="fa fa-thumbs-up fa-lg icon-unsel"></i><span class="wb-inv">'.$hiddenText['like'].'</span>',
1206
				'title' => elgg_echo('likes:likethis') . ' ' . $entContext,
1207
				'item_class' => $hasLiked ? 'hidden' : '',
1208
				'priority' => 100,
1209
			));
1210
			$return[] = ElggMenuItem::factory(array(
1211
				'name' => 'unlike',
1212
				'href' => elgg_add_action_tokens_to_url("/action/likes/delete?guid={$object->guid}"),
1213
				'text' => '<i class="fa fa-thumbs-up fa-lg icon-sel"></i><span class="wb-inv">'.$hiddenText['unlike'].'</span>',
1214
				'title' => elgg_echo('likes:remove') . ' ' . $entContext,
1215
				'item_class' => $hasLiked ? '' : 'hidden',
1216
				'priority' => 100,
1217
			));
1218
1219
			// likes count
1220
			$count = elgg_view('likes/count', array('entity' => $object));
1221 View Code Duplication
			if ($count) {
1222
				$return[] = ElggMenuItem::factory(array(
1223
					'name' => 'likes_count',
1224
					'text' => $count,
1225
					'href' => false,
1226
					'priority' => 101,
1227
				));
1228
			}
1229
		}
1230
1231
		$blocked_subtypes = array('comment', 'discussion_reply');
1232 View Code Duplication
		if (in_array($object->getSubtype(), $blocked_subtypes) || elgg_instanceof($object, 'user')) {
0 ignored issues
show
Unused Code introduced by
This if statement is empty and can be removed.

This check looks for the bodies of if statements that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.

These if bodies can be removed. If you have an empty if but statements in the else branch, consider inverting the condition.

if (rand(1, 6) > 3) {
//print "Check failed";
} else {
    print "Check succeeded";
}

could be turned into

if (rand(1, 6) <= 3) {
    print "Check succeeded";
}

This is much more concise to read.

Loading history...
1233
			//do not let comments or discussion replies to be reshared on the wire
1234
		} else {
1235
			$return[]= ElggMenuItem::factory(array(
1236
				'name' => 'thewire_tools_reshare',
1237
				'text' => '<i class="fa fa-share-alt fa-lg icon-unsel"><span class="wb-inv">'.$hiddenText['share'].'</span></i>',
1238
				'title' => elgg_echo('thewire_tools:reshare'),
1239
				'href' => 'ajax/view/thewire_tools/reshare?reshare_guid=' . $object->getGUID(),
1240
				'link_class' => 'elgg-lightbox',
1241
				'item_class' => '',
1242
				'is_trusted' => true,
1243
				'priority' => 500
1244
			));
1245
		}
1246
1247
		if (elgg_is_admin_logged_in()) {
1248
			$options = array(
1249
				'name' => 'delete',
1250
				'href' => elgg_add_action_tokens_to_url("action/river/delete?id=$item->id"),
1251
				'text' => '<i class="fa fa-trash-o fa-lg icon-unsel"><span class="wb-inv">Delete This</span></i>',
1252
				'title' => elgg_echo('river:delete'),
1253
				'confirm' => elgg_echo('deleteconfirm'),
1254
				'priority' => 200,
1255
			);
1256
			$return[] = \ElggMenuItem::factory($options);
1257
		}
1258
	}
1259
1260
	return $return;
1261
}
1262
1263
/*
1264
 * my_filter_menu_handler
1265
 * Rearrange filter menu for The Wire
1266
 */
1267
function my_filter_menu_handler($hook, $type, $menu, $params)
1268
{
1269
	foreach ($menu as $key => $item) {
1270
		if (elgg_in_context('thewire')) {
1271
			switch ($item->getName()) {
1272
				case 'all':
1273
					$item->setPriority('1');
1274
					break;
1275
				case 'friend':
1276
					$item->setPriority('2');
1277
					break;
1278
				case 'mention':
1279
					$item->setText(elgg_echo('search'));
1280
					$item->setPriority('4');
1281
					break;
1282
				case 'mine':
1283
					$item->setPriority('3');
1284
					break;
1285
			}
1286
		}
1287
	}
1288
}
1289
1290
/*
1291
 * my_site_menu_handler
1292
 * Set href of groups link depending if a logged in user is using site
1293
 */
1294
function my_site_menu_handler($hook, $type, $menu, $params)
1295
{
1296
	if (!is_array($menu)) {
1297
		return;
1298
	}
1299
1300
	foreach ($menu as $key => $item) {
1301
		if ($item->getName() === 'groups') {
1302
			(elgg_is_logged_in()) ? $item->setHref(elgg_get_site_url().'groups/all?filter=yours') : $item->setHref(elgg_get_site_url().'groups/all?filter=popular');
1303
		}
1304
	}
1305
}
1306
1307
/*
1308
 * my_title_menu_handler
1309
 * Add styles to phot album title menu
1310
 */
1311
function my_title_menu_handler($hook, $type, $menu, $params)
1312
{
1313
	if (!is_array($menu)) {
1314
		return;
1315
	}
1316
1317
	foreach ($menu as $key => $item) {
1318
		if ($item->getName() === 'slideshow') {
1319
			$item->setText(elgg_echo('album:slideshow'));
1320
		} elseif ($item->getName() === 'addphotos') {
1321
			$item->setItemClass('mrgn-rght-sm');
1322
		}
1323
	}
1324
}
1325
1326
/*
1327
 * my_owner_block_handler
1328
 * Override owner_block menu to become tabs in profile
1329
 */
1330
function my_owner_block_handler($hook, $type, $menu, $params){
1331
1332
    /*
1333
     *
1334
     * If new tool has been added to group tools
1335
     * Make sure the priority is less then 100
1336
     *
1337
     */
1338
1339
1340
        //rearrange menu items
1341 View Code Duplication
    if(elgg_get_context() == 'profile'){
1342
1343
        elgg_unregister_menu_item('owner_block', 'activity');
1344
1345
        //turn owner_block  menu into tabs
1346
        foreach ($menu as $key => $item){
1347
1348
            switch ($item->getName()) {
1349
                case 'discussion':
1350
                    $item->setText(elgg_echo('gprofile:discussion'));
1351
1352
                    $item->setPriority('1');
1353
                    break;
1354
                case 'file':
1355
                    $item->setText(elgg_echo('gprofile:files'));
1356
                    $item->setHref('#file');
1357
                    $item->setPriority('2');
1358
                    break;
1359
                case 'blog':
1360
                    $item->setText(elgg_echo('gprofile:blogs'));
1361
                    $item->setHref('#blog');
1362
                    $item->setPriority('3');
1363
                    break;
1364
                case 'event_calendar':
1365
                    $item->setText(elgg_echo('gprofile:events'));
1366
                    $item->setHref('#events');
1367
                    $item->setPriority('6');
1368
                    break;
1369
                case 'pages':
1370
                    $item->setText(elgg_echo('gprofile:pages'));
1371
                    $item->setHref('#page_top');
1372
                    $item->setPriority('7');
1373
                    break;
1374
                case 'bookmarks':
1375
                    $item->setText(elgg_echo('gprofile:bookmarks'));
1376
                    $item->setHref('#bookmarks');
1377
                    $item->setPriority('8');
1378
                    break;
1379
                case 'polls':
1380
                    $item->setText(elgg_echo('gprofile:polls'));
1381
                    $item->setHref('#poll');
1382
                    $item->setPriority('9');
1383
                    break;
1384
                case 'tasks':
1385
                    $item->setText(elgg_echo('gprofile:tasks'));
1386
                    $item->setHref('#task_top');
1387
                    $item->setPriority('10');
1388
                    break;
1389
                case 'photos':
1390
                    $item->setText(elgg_echo('gprofile:photos'));
1391
                    $item->addItemClass('removeMe');
1392
                    $item->setPriority('11');
1393
                    break;
1394
                case 'photo_albums':
1395
                    $item->setText(elgg_echo('gprofile:albumsCatch'));
1396
                    $item->setHref('#album');
1397
                    $item->setPriority('12');
1398
                    break;
1399
                case 'ideas':
1400
                    $item->setText(elgg_echo('gprofile:ideas'));
1401
                    $item->addItemClass('removeMe');
1402
                    $item->setPriority('12');
1403
                    break;
1404
1405
                case 'orgs':
1406
                    $item->setPriority('13');
1407
                    break;
1408
                case 'thewire':
1409
                    //$item->setText(elgg_echo('The Wire'));
1410
                    $item->setHref('#thewire');
1411
                    $item->setPriority('5');
1412
                    break;
1413
                case 'activity':
1414
                    $item->setText(elgg_echo('activity'));
1415
1416
                    $item->setPriority('13');
1417
                    $item->addItemClass('removeMe');
1418
                    break;
1419
                case 'user_invite_from_profile':
1420
                    $item->setPriority('13');
1421
                    break;
1422
								case 'questions':
1423
			              $item->setText(elgg_echo('widget:questions:title'));
1424
			              $item->setHref('#question');
1425
			              $item->setPriority('8');
1426
		                break;
1427
            }
1428
1429
        }
1430
1431
1432
1433
    }
1434
1435
1436
	//rearrange menu items
1437 View Code Duplication
	if (elgg_get_context() == 'profile') {
1438
		elgg_unregister_menu_item('owner_block', 'activity');
1439
1440
		//turn owner_block menu into tabs
1441
		foreach ($menu as $key => $item) {
1442
			switch ($item->getName()) {
1443
				case 'discussion':
1444
					$item->setText(elgg_echo('gprofile:discussion'));
1445
					$item->setPriority('1');
1446
					break;
1447
				case 'file':
1448
					$item->setText(elgg_echo('gprofile:files'));
1449
					$item->setHref('#file');
1450
					$item->setPriority('2');
1451
					break;
1452
				case 'blog':
1453
					$item->setText(elgg_echo('gprofile:blogs'));
1454
					$item->setHref('#blog');
1455
					$item->setPriority('3');
1456
					break;
1457
				case 'thewire':
1458
					$item->setHref('#thewire');
1459
					$item->setPriority('5');
1460
					break;
1461
				case 'event_calendar':
1462
					$item->setText(elgg_echo('gprofile:events'));
1463
					$item->setHref('#events');
1464
					$item->setPriority('6');
1465
					break;
1466
				case 'pages':
1467
					$item->setText(elgg_echo('gprofile:pages'));
1468
					$item->setHref('#page_top');
1469
					$item->setPriority('7');
1470
					break;
1471
				case 'bookmarks':
1472
					$item->setText(elgg_echo('gprofile:bookmarks'));
1473
					$item->setHref('#bookmarks');
1474
					$item->setPriority('8');
1475
					break;
1476
				case 'questions':
1477
					$item->setText(elgg_echo('widget:questions:title'));
1478
					$item->setHref('#question');
1479
					$item->setPriority('8');
1480
					break;
1481
				case 'polls':
1482
					$item->setText(elgg_echo('gprofile:polls'));
1483
					$item->setHref('#poll');
1484
					$item->setPriority('9');
1485
					break;
1486
				case 'tasks':
1487
					$item->setText(elgg_echo('gprofile:tasks'));
1488
					$item->setHref('#task_top');
1489
					$item->setPriority('10');
1490
					break;
1491
				case 'photos':
1492
					$item->setText(elgg_echo('gprofile:photos'));
1493
					$item->addItemClass('removeMe');
1494
					$item->setPriority('11');
1495
					break;
1496
				case 'photo_albums':
1497
					$item->setText(elgg_echo('gprofile:albumsCatch'));
1498
					$item->setHref('#album');
1499
					$item->setPriority('12');
1500
					break;
1501
				case 'ideas':
1502
					$item->setText(elgg_echo('gprofile:ideas'));
1503
					$item->addItemClass('removeMe');
1504
					$item->setPriority('12');
1505
					break;
1506
				case 'activity':
1507
					$item->setText('Activity');
1508
					$item->setPriority('13');
1509
					$item->addItemClass('removeMe');
1510
					break;
1511
				case 'user_invite_from_profile':
1512
				case 'orgs':
1513
					$item->setPriority('13');
1514
					break;
1515
			}
1516
		}
1517
	}
1518
}
1519
1520
/*
1521
 * river_handler
1522
 * Remove comment menu item
1523
 */
1524
function river_handler($hook, $type, $menu, $params)
1525
{
1526
}
1527
1528
/*
1529
 * wet4_dashboard_page_handler
1530
 * Override page handler for wet4 theme - dashboard
1531
 */
1532 View Code Duplication
function wet4_dashboard_page_handler()
1533
{
1534
	// Ensure that only logged-in users can see this page
1535
	elgg_gatekeeper();
1536
1537
	// Set context and title
1538
	elgg_set_context('dashboard');
1539
	elgg_set_page_owner_guid(elgg_get_logged_in_user_guid());
1540
	$title = elgg_echo('dashboard');
1541
1542
	// wrap intro message in a div
1543
	$intro_message = elgg_view('dashboard/blurb', array());
1544
1545
	$params = array(
1546
		'content' => $intro_message,
1547
		'num_columns' => 2,
1548
		'show_access' => false,
1549
	);
1550
	//use our own layouts for dashboard and stuff
1551
	$widgets = elgg_view_layout('db_widgets', $params);
1552
1553
	$body = elgg_view_layout('dashboard', array(
1554
		'title' => false,
1555
		'content' => $widgets
1556
	));
1557
1558
	echo elgg_view_page($title, $body);
1559
	return true;
1560
}
1561
1562
/*
1563
 * wet4_widget_menu_setup
1564
 * Override widget menu to use font awesome icons + add accessability
1565
 */
1566
function wet4_widget_menu_setup($hook, $type, $return, $params)
1567
{
1568
	$widget = $params['entity'];
1569
	$show_edit = elgg_extract('show_edit', $params, true);
1570
1571
	$options = array(
1572
		'name' => 'collapse',
1573
		'text' => '<i class="fa fa-lg icon-unsel"><span class="wb-inv">'. elgg_echo('wet:collapseWidget', array($widget->getTitle())).'</span></i> ',
1574
		'title' => elgg_echo('wet:collapseWidget', array($widget->getTitle())),
1575
		'href' => "#elgg-widget-content-$widget->guid",
1576
		'link_class' => 'elgg-widget-collapse-button ',
1577
		'rel' => 'toggle',
1578
		'priority' => 1,
1579
	);
1580
1581
	$return[] = \ElggMenuItem::factory($options);
1582
	if ($widget->canEdit()) {
1583
		$options = array(
1584
			'name' => 'delete',
1585
			'text' => '<i class="fa fa-trash-o fa-lg icon-unsel"><span class="wb-inv">'.elgg_echo('widget:delete', array($widget->getTitle())).'</span></i>',
1586
			'title' => elgg_echo('widget:delete', array($widget->getTitle())),
1587
			'href' => "action/widgets/delete?widget_guid=$widget->guid&context=" . $widget->getContainerGUID(),
1588
			'is_action' => true,
1589
			'link_class' => 'elgg-widget-delete-button',
1590
			'id' => "elgg-widget-delete-button-$widget->guid",
1591
			'data-elgg-widget-type' => $widget->handler,
1592
			'priority' => 900,
1593
		);
1594
		$return[] = \ElggMenuItem::factory($options);
1595
		// This is to maybe have a move button on widgets to move them with the keyboard.
1596
1597
		if ($show_edit) {
1598
			$options = array(
1599
				'name' => 'settings',
1600
				'text' => '<i class="fa fa-cog fa-lg icon-unsel"><span class="wb-inv">'.elgg_echo('widget:edit', array($widget->getTitle())).'</span></i>',
1601
				'title' => elgg_echo('widget:edit', array($widget->getTitle())),
1602
				'href' => "#widget-edit-$widget->guid",
1603
				'link_class' => "elgg-widget-edit-button",
1604
				'rel' => 'toggle',
1605
				'priority' => 800,
1606
			);
1607
			$return[] = \ElggMenuItem::factory($options);
1608
		}
1609
	}
1610
1611
	return $return;
1612
}
1613
1614
/*
1615
 * wet4_collections_page_handler
1616
 * Override page handler for wet4 theme - friend circles
1617
 */
1618
function wet4_collections_page_handler($page)
1619
{
1620
	$current_user = elgg_get_logged_in_user_entity();
1621
	if (!$current_user) {
1622
		register_error(elgg_echo('noaccess'));
1623
		elgg_get_session()->set('last_forward_from', current_page_url());
1624
		forward('');
1625
	}
1626
	elgg_set_context('friends');
1627
1628
	$base_dir = elgg_get_plugins_path() . 'wet4/pages/friends/collections';
1629
1630
	switch ($page[0]) {
1631
		case 'owner':
1632
			include("$base_dir/view.php");
1633
			break;
1634
		case 'add':
1635
			include("$base_dir/add.php");
1636
			break;
1637
		case 'edit':
1638
			include("$base_dir/edit.php");
1639
			break;
1640
		default:
1641
			return false;
1642
	}
1643
	return true;
1644
}
1645
1646
/*
1647
 * wet4_messages_page_handler
1648
 * Override page handler for wet4 theme - messages
1649
 */
1650 View Code Duplication
function wet4_messages_page_handler($page)
1651
{
1652
	$current_user = elgg_get_logged_in_user_entity();
1653
	if (!$current_user) {
1654
		register_error(elgg_echo('noaccess'));
1655
		elgg_get_session()->set('last_forward_from', current_page_url());
1656
		forward('');
1657
	}
1658
1659
	elgg_load_library('elgg:messages');
1660
1661
	elgg_push_breadcrumb(elgg_echo('messages'), 'messages/inbox/' . $current_user->username);
1662
1663
	if (!isset($page[0])) {
1664
		$page[0] = 'inbox';
1665
	}
1666
1667
	// Support the old inbox url /messages/<username>, but only if it matches the logged in user.
1668
	// Otherwise having a username like "read" on the system could confuse this function.
1669
	if ($current_user->username === $page[0]) {
1670
		$page[1] = $page[0];
1671
		$page[0] = 'inbox';
1672
	}
1673
1674
	if (!isset($page[1])) {
1675
		$page[1] = $current_user->username;
1676
	}
1677
1678
	$base_dir = elgg_get_plugins_path() . 'wet4/pages/messages';
1679
1680
	switch ($page[0]) {
1681
		case 'inbox':
1682
			set_input('username', $page[1]);
1683
			include("$base_dir/inbox.php");
1684
			break;
1685
		case 'notifications':
1686
			set_input('username', $page[1]);
1687
			include("$base_dir/notifications.php");
1688
			break;
1689
		case 'sent':
1690
			set_input('username', $page[1]);
1691
			include("$base_dir/sent.php");
1692
			break;
1693
		case 'read':
1694
			set_input('guid', $page[1]);
1695
			include("$base_dir/read.php");
1696
			break;
1697
		case 'compose':
1698
		case 'add':
1699
			include("$base_dir/send.php");
1700
			break;
1701
		default:
1702
			return false;
1703
	}
1704
	return true;
1705
}
1706
1707
/*
1708
 * enhanced_friendly_time_hook
1709
 *
1710
 * Friendly Time from GCconnex Codefest 2015 - 2016
1711
 *
1712
 * @author Nick
1713
 */
1714
function enhanced_friendly_time_hook($hook, $type, $return, $params)
1715
{
1716
	$diff = time() - ((int) $params['time']);
1717
1718
	$minute = 60;
1719
	$hour = $minute * 60;
1720
	$day = $hour * 24;
1721
1722
	if ($diff < $minute) {
1723
		$friendly_time = elgg_echo("friendlytime:justnow");
1724
	} elseif ($diff < $hour) {
1725
		$diff = round($diff / $minute);
1726
		if ($diff == 0) {
1727
			$diff = 1;
1728
		}
1729
1730
		if ($diff > 1) {
1731
			$friendly_time = elgg_echo("friendlytime:minutes", array($diff));
1732
		} else {
1733
			$friendly_time = elgg_echo("friendlytime:minutes:singular", array($diff));
1734
		}
1735
	} elseif ($diff < $day) {
1736
		$diff = round($diff / $hour);
1737
		if ($diff == 0) {
1738
			$diff = 1;
1739
		}
1740
1741
		if ($diff > 1) {
1742
			$friendly_time = elgg_echo("friendlytime:hours", array($diff));
1743
		} else {
1744
			$friendly_time = elgg_echo("friendlytime:hours:singular", array($diff));
1745
		}
1746
	} else {
1747
		$diff = round($diff / $day);
1748
		if ($diff == 0) {
1749
			$diff = 1;
1750
		}
1751
		//PHPlord let check for day, days, weeks and finally output date if too far away...
1752
		if ($diff == 1) {
1753
			$friendly_time = elgg_echo("friendlytime:days:singular", array($diff));
1754
		} elseif (6 >= $diff) {
1755
			$friendly_time = elgg_echo("friendlytime:days", array($diff));
1756
		} elseif (13 >= $diff) {
1757
			$friendly_time = elgg_echo("friendlytime:weeks:singular", array($diff));
1758
		} elseif ($diff == 14) {
1759
			$friendly_time = elgg_echo("friendlytime:weeks", array($diff));
1760
		} else {
1761
			$date_day = date('d', $params['time']);
1762
			$date_month = date('m', $params['time']);
1763
			$date_year = date('Y', $params['time']);
1764
			$date_hour = date('H', $params['time']);
1765
			$date_minute = date('i', $params['time']);
1766
			$friendly_time = $date_year . '-' . $date_month . '-' . $date_day . ' ' . $date_hour . ':' . $date_minute;
1767
		}
1768
	}
1769
1770
	$attributes = array();
1771
	$attributes['title'] = date(elgg_echo('friendlytime:date_format'), $params['time']);
1772
	$attributes['datetime'] = date('c', $params['time']);
1773
	$attrs = elgg_format_attributes($attributes);
1774
1775
	return "<time $attrs>$friendly_time</time>";
1776
}
1777
1778
/**
1779
 * proper_subtypes
1780
 *
1781
 * Takes the subtypes and turns them into the plain language version of the subtype for menu items.
1782
 *
1783
 * @author Ethan Wallace
1784
 * @param string $type Entity subtype
1785
 * @return string Subtype
1786
 */
1787
function proper_subtypes($type)
1788
{
1789
	switch ($type) {
1790
		case 'page_top':
1791
		case 'page':
1792
			return elgg_echo('page');
1793
1794
		case 'thewire':
1795
			return elgg_echo('wire:post');
1796
1797
		case 'blog':
1798
			return elgg_echo('blog:blog');
1799
1800
		case 'comment':
1801
			return elgg_echo('comment');
1802
1803
		case 'groupforumtopic':
1804
			return elgg_echo('discussion');
1805
1806
		case 'discussion_reply':
1807
			return elgg_echo('group:replyitem');
1808
1809
		case 'file':
1810
			return elgg_echo('file:file');
1811
1812
		case 'folder':
1813
			return elgg_echo('item:object:folder');
1814
1815
		case 'event_calendar':
1816
			return elgg_echo('event_calendar:agenda:column:session');
1817
1818
		case 'bookmarks':
1819
			return elgg_echo('bookmark');
1820
1821
		case 'poll':
1822
			return elgg_echo('poll');
1823
1824
		case 'album':
1825
			return elgg_echo('album');
1826
1827
		case 'image':
1828
			return elgg_echo('image');
1829
1830
		case 'idea':
1831
			return elgg_echo('item:object:idea');
1832
1833
		case 'groups':
1834
			return elgg_echo('group:group');
1835
1836
		case 'question':
1837
			return elgg_echo('questions:edit:question:title');
1838
1839
		case 'answer':
1840
			return elgg_echo('questions:search:answer:title');
1841
	}
1842
1843
	return '';
1844
}
1845
1846
/**
1847
 * generate_hidden_text
1848
 *
1849
 * Takes the type and entity name to generate hidden text for entity/river menus
1850
 *
1851
 * @author Ethan Wallace
1852
 * @param string $type Entity subtype.
1853
 * @return array Contains different text for each menu item
1854
 */
1855
function generate_hidden_text($type, $name)
1856
{
1857
	$hiddenText = array();
1858
1859
	//create all unique menu items
1860
	switch ($type) {
1861
		case 'page_top':
1862
		case 'page':
1863
			$hiddenText['history'] = elgg_echo('entity:history:link:'.$type, array($name));
1864
			break;
1865
1866
		case 'thewire':
1867
			$hiddenText['reply'] = elgg_echo('entity:reply:link:'.$type, array($name));
1868
			break;
1869
1870
		case 'comment':
1871
			$hiddenText['comment'] = elgg_echo('entity:comment:link:'.$type, array($name));
1872
			break;
1873
1874
		case 'groupforumtopic':
1875
			$hiddenText['lock'] = elgg_echo('entity:lock:link:'.$type, array($name));
1876
			$hiddenText['unlock'] = elgg_echo('entity:unlock:link:'.$type, array($name));
1877
			break;
1878
1879
		case 'file':
1880
			$hiddenText['download'] = elgg_echo('entity:download:link:'.$type, array($name));
1881
			break;
1882
1883
		case 'idea':
1884
			$hiddenText['upvote'] = elgg_echo('entity:upvote:link:'.$type, array($name));
1885
			$hiddenText['downvote'] = elgg_echo('entity:downvote:link:'.$type, array($name));
1886
			break;
1887
	}
1888
1889
	//default menus that ever item has
1890
	$hiddenText['like'] = elgg_echo('entity:like:link:'.$type, array($name));
1891
	$hiddenText['unlike'] = elgg_echo('entity:unlike:link:'.$type, array($name));
1892
	$hiddenText['edit'] = elgg_echo('entity:edit:link:'.$type, array($name));
1893
	$hiddenText['delete'] = elgg_echo('entity:delete:link:'.$type, array($name));
1894
	$hiddenText['share'] = elgg_echo('entity:share:link:'.$type, array($name));
1895
	$hiddenText['subscribe'] = elgg_echo('entity:subscribe:link:'.$type, array($name));
1896
1897
	return $hiddenText;
1898
}
1899
1900
/**
1901
 * embed_discussion_river
1902
 *
1903
 * Searches preview text of discussions to find video url to embed that video.
1904
 *
1905
 * @author Ethan Wallace
1906
 * @param string $desc Preview text from the discussion.
1907
 * @return string HTML to create embeded video
1908
 */
1909
function embed_discussion_river($desc)
1910
{
1911
	$patterns = array('#(((https://)?)|(^./))(((www.)?)|(^./))youtube\.com/watch[?]v=([^\[\]()<.,\s\n\t\r]+)#i'
1912
		,'#(((https://)?)|(^./))(((www.)?)|(^./))youtu\.be/([^\[\]()<.,\s\n\t\r]+)#i'
1913
		,'/(https:\/\/)?(www\.)?(vimeo\.com\/groups)(.*)(\/videos\/)([0-9]*)(\/)?/'
1914
		,'/(https:\/\/)(www\.)?(metacafe\.com\/watch\/)([0-9a-zA-Z_-]*)(\/[0-9a-zA-Z_-]*)(\/)/'
1915
		,'/(https:\/\/)?(www\.)?(vimeo.com\/)([^a-zA-Z][0-9]*)(\/)?/','/(https:\/\/)?(www\.)?(dailymotion.com\/video)([^a-zA-Z][0-9]*)(\/)?/'
1916
	);
1917
1918
	//Replace video providers with embebed content
1919
	foreach ($patterns as $pattern) {
1920
		if (preg_match_all($pattern, $desc, $matches)) {
1921
			$strAndPara = $matches[0];
1922
		}
1923
	}
1924
	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...
1925
}
1926
1927
1928
/**
1929
 * Add a menu item to the topbar menu for logging out of an account
1930
 */
1931
function login_as_add_user_menu_link()
1932
{
1933
	$item = elgg_get_menu_item('topbar', 'login_as_return');
1934
1935
	if (isset($item)) {
1936
		$item->addLinkClass('no-style-link');
1937
		$item->addItemClass('login-as-out');
1938
		elgg_register_menu_item('user_menu', $item);
1939
	}
1940
}
1941
1942
/**
1943
 * Handles all question pages. Modified to add friends page
1944
 *
1945
 * @param array $segments
1946
 *
1947
 * @return bool
1948
 */
1949
function wet_questions_page_handler($segments)
1950
{
1951
	elgg_push_breadcrumb(elgg_echo('questions'), 'questions/all');
1952
1953
	$pages = 'mod/questions/pages/questions';
1954
	$new_page = 'mod/wet4/pages/questions';
1955 View Code Duplication
	switch ($segments[0]) {
1956
		case 'all':
1957
			include "$pages/all.php";
1958
			break;
1959
		case 'todo':
1960
			if (isset($segments[1]) && is_numeric($segments[1])) {
1961
				set_input('group_guid', $segments[1]);
1962
			}
1963
			include "$pages/todo.php";
1964
			break;
1965
		case 'owner':
1966
			if (isset($segments[1]) && is_numeric($segments[1])) {
1967
				elgg_set_page_owner_guid($segments[1]);
1968
			}
1969
			include "$pages/owner.php";
1970
			break;
1971
		case 'view':
1972
			set_input('guid', $segments[1]);
1973
			include "$new_page/view.php";
1974
			break;
1975
		case 'add':
1976
			elgg_gatekeeper();
1977
			include "$pages/add.php";
1978
			break;
1979
		case 'edit':
1980
			elgg_gatekeeper();
1981
			set_input('guid', $segments[1]);
1982
			include "$new_page/edit.php";
1983
			break;
1984
		case 'group':
1985
			elgg_group_gatekeeper();
1986
			include "$new_page/owner.php";
1987
			break;
1988
		case 'friends':
1989
			include "$new_page/friends.php";
1990
			break;
1991
		case 'experts':
1992
			if (isset($segments[1]) && is_numeric($segments[1])) {
1993
				elgg_set_page_owner_guid($segments[1]);
1994
			}
1995
			include "$pages/experts.php";
1996
			break;
1997
		default:
1998
			forward('questions/all');
1999
			return false;
2000
	}
2001
2002
	return true;
2003
}
2004
2005
/**
2006
 * Add menu items to the filter menu. Modified to remove filter menu from group context and add friends filter
2007
 *
2008
 * @param string         $hook   the name of the hook
2009
 * @param string         $type   the type of the hook
2010
 * @param ElggMenuItem[] $items  current return value
2011
 * @param array          $params supplied params
2012
 *
2013
 * @return void|ElggMenuItem[]
2014
 */
2015
function wet_questions_filter_menu_handler($hook, $type, $items, $params)
2016
{
2017
	if (empty($items) || !is_array($items) || !elgg_in_context('questions')) {
2018
		return;
2019
	}
2020
2021
	$page_owner = elgg_get_page_owner_entity();
2022
2023
	// change some menu items
2024
	foreach ($items as $key => $item) {
2025
		// add friends back into filter menu
2026
		if ($item->getName() == 'friend') {
2027
			$item->setHref("questions/friends");
2028
		}
2029
2030
		// in group context
2031
		if ($page_owner instanceof ElggGroup) {
2032
			// remove mine
2033
			if ($item->getName() == 'mine') {
2034
				unset($items[$key]);
2035
			}
2036
2037
			if ($item->getName() == 'friend') {
2038
				unset($items[$key]);
2039
			}
2040
2041
			// check if all is correct
2042
			if ($item->getName() === 'all') {
2043
				// remove filter menu in group context
2044
				unset($items[$key]);
2045
			}
2046
		}
2047
	}
2048
2049 View Code Duplication
	if (questions_is_expert()) {
2050
		$items[] = ElggMenuItem::factory([
2051
			'name' => 'todo',
2052
			'text' => elgg_echo('questions:menu:filter:todo'),
2053
			'href' => 'questions/todo',
2054
			'priority' => 700,
2055
		]);
2056
2057
		if ($page_owner instanceof ElggGroup) {
2058
			$items[] = ElggMenuItem::factory([
2059
				'name' => 'todo_group',
2060
				'text' => elgg_echo('questions:menu:filter:todo_group'),
2061
				'href' => "questions/todo/{$page_owner->getGUID()}",
2062
				'priority' => 710,
2063
			]);
2064
		}
2065
	}
2066
2067 View Code Duplication
	if (questions_experts_enabled()) {
2068
		$experts_href = 'questions/experts';
2069
		if ($page_owner instanceof ElggGroup) {
2070
			$experts_href .= "/{$page_owner->getGUID()}";
2071
		}
2072
2073
		$items[] = ElggMenuItem::factory([
2074
			'name' => 'experts',
2075
			'text' => elgg_echo('questions:menu:filter:experts'),
2076
			'href' => $experts_href,
2077
			'priority' => 800,
2078
		]);
2079
	}
2080
2081
	return $items;
2082
}
2083
2084
function wet_seo_friendly_urls($hook, $entity_type, $returnvalue, $params) {
2085
    $separator = "-";
2086
2087
    if ($entity_type == 'friendly:title') {
2088
        $title = $params['title'];
2089
2090
        // Pull in EN & FR titles
2091
        $title_en = gc_explode_translation($title, 'en');
2092
        $title_fr = gc_explode_translation($title, 'fr');
2093
2094
        // Combine EN & FR titles for URL (if exists)
2095
        if ($title_en !== "" && $title_fr !== "") {
2096
            if ($title_en !== $title_fr) {
2097
                $title = $title_en . $separator . $title_fr;
2098
            } else {
2099
                $title = $title_en;
2100
            }
2101
        } elseif ($title_en !== "") {
2102
            $title = $title_en;
2103
        } elseif ($title_fr !== "") {
2104
            $title = $title_fr;
2105
        }
2106
2107
        // Convert accented characters with regular equivalent
2108
        setlocale(LC_ALL, 'en_US.utf8');
2109
        $title = iconv('UTF-8', 'ASCII//TRANSLIT', $title);
2110
2111
        // Strip out special characters
2112
        $title = strip_tags($title);
2113
        $title = str_replace("'", "", $title);
2114
        $title = str_replace('"', "", $title);
2115
        $title = preg_replace('`\[.*\]`U', '', $title);
2116
        $title = preg_replace('`&(amp;)?#?[a-z0-9]+;`i', '', $title);
2117
2118
        // Add separator between words in URL string
2119
        $title = preg_replace(array("`[^a-z0-9]`i","`[-]+`") , $separator, $title);
2120
2121
        return trim(strtolower($title), $separator);
2122
    }
2123
}
2124