Code Duplication    Length = 56-56 lines in 2 locations

mod/messages/start.php 1 location

@@ 80-135 (lines=56) @@
77
 * @param array $page Array of URL components for routing
78
 * @return bool
79
 */
80
function messages_page_handler($page) {
81
82
	$current_user = elgg_get_logged_in_user_entity();
83
	if (!$current_user) {
84
		register_error(elgg_echo('noaccess'));
85
		elgg_get_session()->set('last_forward_from', current_page_url());
86
		forward('');
87
	}
88
89
	elgg_load_library('elgg:messages');
90
91
	elgg_push_breadcrumb(elgg_echo('messages'), 'messages/inbox/' . $current_user->username);
92
93
	if (!isset($page[0])) {
94
		$page[0] = 'inbox';
95
	}
96
97
	// Support the old inbox url /messages/<username>, but only if it matches the logged in user.
98
	// Otherwise having a username like "read" on the system could confuse this function.
99
	if ($current_user->username === $page[0]) {
100
		$page[1] = $page[0];
101
		$page[0] = 'inbox';
102
	}
103
104
	if (!isset($page[1])) {
105
		$page[1] = $current_user->username;
106
	}
107
108
	$base_dir = elgg_get_plugins_path() . 'messages/pages/messages';
109
110
	switch ($page[0]) {
111
		case 'inbox':
112
			set_input('username', $page[1]);
113
			include("$base_dir/inbox.php");
114
			break;
115
		case 'notifications':
116
			set_input('username', $page[1]);
117
			include("$base_dir/notifications.php");
118
			break;
119
		case 'sent':
120
			set_input('username', $page[1]);
121
			include("$base_dir/sent.php");
122
			break;
123
		case 'read':
124
			set_input('guid', $page[1]);
125
			include("$base_dir/read.php");
126
			break;
127
		case 'compose':
128
		case 'add':
129
			include("$base_dir/send.php");
130
			break;
131
		default:
132
			return false;
133
	}
134
	return true;
135
}
136
137
/**
138
 * Display notification of new messages in topbar

mod/wet4/start.php 1 location

@@ 1727-1782 (lines=56) @@
1724
 * wet4_messages_page_handler
1725
 * Override page handler for wet4 theme - messages
1726
 */
1727
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