Completed
Pull Request — gcconnex (#1568)
by Nick
17:08
created

start.php ➔ generate_hidden_text()   C

Complexity

Conditions 8
Paths 8

Size

Total Lines 44
Code Lines 31

Duplication

Lines 0
Ratio 0 %

Importance

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