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