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