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