Completed
Pull Request — master (#2104)
by Ilia
13:32 queued 05:12
created

start.php ➔ wet4_group_entity_menu_setup()   B

Complexity

Conditions 10
Paths 7

Size

Total Lines 29

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 10
nc 7
nop 4
dl 0
loc 29
rs 7.6666
c 0
b 0
f 0

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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