Passed
Push — collab-accessibility ( 37b996...9f3d34 )
by
unknown
34:02 queued 12:44
created

start.php ➔ consistent_menu_styler_alt()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

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