Completed
Push — develop ( ff34f8...c5327c )
by Daniel
09:18
created

urls::get_mcp_url()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 16
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
dl 0
loc 16
ccs 0
cts 16
cp 0
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 8
nc 3
nop 2
crap 12
1
<?php
2
/**
3
 *
4
 * @package sitemaker
5
 * @copyright (c) 2016 Daniel A. (blitze)
6
 * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
7
 *
8
 */
9
10
namespace blitze\content\services;
11
12
abstract class urls
13
{
14
	/** @var \phpbb\auth\auth */
15
	protected $auth;
16
17
	/** @var \phpbb\config\db */
18
	protected $config;
19
20
	/** @var \phpbb\user */
21
	protected $user;
22
23
	/** @var string */
24
	protected $phpbb_root_path;
25
26
	/** @var string */
27
	protected $php_ext;
28
29
	/**
30
	 * Constructor
31
	 *
32
	 * @param \phpbb\auth\auth		$auth				Auth object
33
	 * @param \phpbb\config\db		$config				Config object
34
	 * @param \phpbb\user			$user				User object
35
	 * @param string				$phpbb_root_path	Path to the phpbb includes directory.
36
	 * @param string				$php_ext			php file extension
37
	*/
38
	public function __construct(\phpbb\auth\auth $auth, \phpbb\config\db $config, \phpbb\user $user, $phpbb_root_path, $php_ext)
39
	{
40
		$this->auth = $auth;
41
		$this->config = $config;
42
		$this->user = $user;
43
		$this->phpbb_root_path = $phpbb_root_path;
44
		$this->php_ext = $php_ext;
45
	}
46
47
	/**
48
	 * @param array $post_data
49
	 * @param array $topic_data
50
	 * @param string $cp_mode
51
	 * @return string
52
	 */
53
	public function get_edit_url(array $post_data, array $topic_data, $cp_mode = '')
54
	{
55
		$cp_param = $this->get_cp_param($post_data, $topic_data, $cp_mode);
56
		return ($this->edit_allowed($post_data, $topic_data)) ? append_sid("{$this->phpbb_root_path}posting.$this->php_ext", "mode=edit&amp;f={$topic_data['forum_id']}&amp;p={$post_data['post_id']}" . $cp_param) : '';
57
	}
58
59
	/**
60
	 * @param array $post_data
61
	 * @param array $topic_data
62
	 * @param string $cp_mode
63
	 * @return string
64
	 */
65
	public function get_delete_url(array $post_data, array $topic_data, $cp_mode = '')
66
	{
67
		$cp_param = $this->get_cp_param($post_data, $topic_data, $cp_mode);
68
		return ($this->delete_allowed($post_data, $topic_data)) ? append_sid("{$this->phpbb_root_path}posting.$this->php_ext", 'mode=' . (($this->softdelete_allowed($post_data)) ? 'soft_delete' : 'delete') . "&amp;f={$post_data['forum_id']}&amp;p={$post_data['post_id']}" . $cp_param) : '';
69
	}
70
71
	/**
72
	 * @param array $post_data
73
	 * @param array $topic_data
74
	 * @return string
75
	 */
76
	public function get_quote_url(array $post_data, array $topic_data)
77
	{
78
		return ($this->post_is_quotable($post_data, $topic_data) && $this->quote_allowed($topic_data)) ? append_sid("{$this->phpbb_root_path}posting.$this->php_ext", "mode=quote&amp;f={$topic_data['forum_id']}&amp;p={$post_data['post_id']}") : '';
79
	}
80
81
	/**
82
	 * @param array $topic_data
83
	 * @return string
84
	 */
85
	public function get_viewtopic_url(array $topic_data)
86
	{
87
		return append_sid("{$this->phpbb_root_path}viewtopic.$this->php_ext", "f={$topic_data['forum_id']}&amp;t={$topic_data['topic_id']}");
88
	}
89
90
	/**
91
	 * @param array $topic_data
92
	 * @return string
93
	 */
94
	public function get_print_topic_url(array $topic_data)
95
	{
96
		return ($this->auth->acl_get('f_print', $topic_data['forum_id'])) ? $topic_data['topic_url'] . '?view=print' : '';
97
	}
98
99
	/**
100
	 * @param array $topic_data
101
	 * @return string
102
	 */
103
	public function get_email_topic_url(array $topic_data)
104
	{
105
		return ($this->auth->acl_get('f_email', $topic_data['forum_id']) && $this->config['email_enable']) ? append_sid("{$this->phpbb_root_path}memberlist.{$this->php_ext}", 'mode=email&amp;t=' . $topic_data['topic_id']) : '';
106
	}
107
108
	/**
109
	 * @param int $forum_id
110
	 * @param string $username
111
	 * @return string
112
	 */
113
	public function get_search_users_posts_url($forum_id, $username)
114
	{
115
		return append_sid("{$this->phpbb_root_path}search.{$this->php_ext}", "author={$username}&amp;" . urlencode('fid[]') . "=$forum_id&amp;sc=0&amp;sf=titleonly&amp;sr=topics");
116
	}
117
118
	/**
119
	 * @param array $post_data
120
	 * @return string
121
	 */
122
	public function get_info_url(array $post_data)
123
	{
124
		$forum_id = $post_data['forum_id'];
125
		return ($this->auth->acl_get('m_info', $forum_id)) ? append_sid("{$this->phpbb_root_path}mcp.$this->php_ext", "i=main&amp;mode=post_details&amp;f=$forum_id&amp;p=" . $post_data['post_id'], true, $this->user->session_id) : '';
126
	}
127
128
	/**
129
	 * @param array $post_data
130
	 * @param string $viewtopic_url
131
	 * @return string
132
	 */
133
	public function get_approve_url(array $post_data, $viewtopic_url)
134
	{
135
		return append_sid("{$this->phpbb_root_path}mcp.$this->php_ext", "i=queue&amp;p={$post_data['post_id']}&amp;f={$post_data['forum_id']}&amp;redirect=" . urlencode(str_replace('&amp;', '&', $viewtopic_url . '&amp;p=' . $post_data['post_id'] . '#p' . $post_data['post_id'])));
136
	}
137
138
	/**
139
	 * @param array $post_data
140
	 * @param array $topic_data
141
	 * @return string
142
	 */
143
	public function get_mcp_edit_url(array $post_data, array $topic_data)
144
	{
145
		return append_sid("{$this->phpbb_root_path}posting.$this->php_ext", "mode=edit&amp;f={$topic_data['forum_id']}&amp;p={$post_data['post_id']}&amp;cp=mcp");
146
	}
147
148
	/**
149
	 * @param array $post_data
150
	 * @return string
151
	 *
152
	public function get_mcp_approve_url(array $post_data)
153
	{
154
		return append_sid("{$this->phpbb_root_path}mcp.$this->php_ext", 'i=queue&amp;mode=approve_details&amp;f=' . $post_data['forum_id'] . '&amp;p=' . $post_data['post_id'], true, $this->user->session_id);
155
	}
156
	*/
157
158
	/**
159
	 * @param array $post_data
160
	 * @return string
161
	 */
162
	public function get_mcp_report_url(array $post_data)
163
	{
164
		return ($this->auth->acl_get('m_report', $post_data['forum_id'])) ? append_sid("{$this->phpbb_root_path}mcp.$this->php_ext", 'i=reports&amp;mode=report_details&amp;f=' . $post_data['forum_id'] . '&amp;p=' . $post_data['post_id'], true, $this->user->session_id) : '';
165
	}
166
167
	/**
168
	 * @param array $post_data
169
	 * @param array $topic_data
170
	 * @return string
171
	 */
172
	public function get_mcp_restore_url(array $post_data, array $topic_data)
173
	{
174
		return ($this->auth->acl_get('m_approve', $post_data['forum_id'])) ? append_sid("{$this->phpbb_root_path}mcp.$this->php_ext", 'i=queue&amp;mode=' . (($topic_data['topic_visibility'] != ITEM_DELETED) ? 'deleted_posts' : 'deleted_topics') . '&amp;f=' . $post_data['forum_id'] . '&amp;p=' . $post_data['post_id'], true, $this->user->session_id) : '';
175
	}
176
177
	/**
178
	 * @param array $post_data
179
	 * @return string
180
	 */
181
	public function get_notes_url(array $post_data)
182
	{
183
		return ($this->auth->acl_getf_global('m_')) ? append_sid("{$this->phpbb_root_path}mcp.$this->php_ext", 'i=notes&amp;mode=user_notes&amp;u=' . $post_data['poster_id'], true, $this->user->session_id) : '';
184
	}
185
186
	/**
187
	 * @param array $post_data
188
	 * @return string
189
	 */
190
	public function get_warning_url(array $post_data)
191
	{
192
		return ($this->auth->acl_get('m_warn') && !$this->user_is_poster($post_data['poster_id']) && $post_data['poster_id'] != ANONYMOUS) ? append_sid("{$this->phpbb_root_path}mcp.$this->php_ext", 'i=warn&amp;mode=warn_post&amp;f=' . $post_data['forum_id'] . '&amp;p=' . $post_data['post_id'], true, $this->user->session_id) : '';
193
	}
194
195
	/**
196
	 * @param int $topic_id
197
	 * @return string
198
	 */
199
	public function get_mcp_queue_url($topic_id)
200
	{
201
		return append_sid("{$this->phpbb_root_path}mcp.$this->php_ext", "i=queue&amp;mode=unapproved_posts&amp;t=$topic_id", true, $this->user->session_id);
202
	}
203
204
	/**
205
	 * @param string $content_type
206
	 * @param int $topic_id
207
	 * @return string
208
	 */
209
	public function get_mcp_review_url($content_type, $topic_id)
210
	{
211
		return append_sid("{$this->phpbb_root_path}mcp.$this->php_ext", "i=-blitze-content-mcp-content_module&amp;mode=content&amp;do=view&amp;type=$content_type&amp;t=$topic_id");
212
	}
213
214
	/**
215
	 * @return string
216
	 */
217
	public function get_mcp_url($forum_id, $topic_id)
218
	{
219
		$u_mcp = '';
220
		if ($this->auth->acl_get('m_', $forum_id))
221
		{
222
			if ($topic_id)
223
			{
224
				$u_mcp = append_sid("{$this->phpbb_root_path}mcp.{$this->php_ext}", "i=mcp_main&amp;mode=topic_view&amp;f=$forum_id&amp;t=$topic_id", true, $this->user->session_id);
225
			}
226
			else
227
			{
228
				$u_mcp = append_sid("{$this->phpbb_root_path}mcp.$this->php_ext", 'i=-blitze-content-mcp-content_module&amp;mode=content', true, $this->user->session_id);
229
			}
230
		}
231
		return $u_mcp;
232
	}
233
234
	/**
235
	 * @param array $post_data
236
	 * @param array $topic_data
237
	 * @param string $cp_mode
238
	 * @return string
239
	 */
240
	protected function get_cp_param(array $post_data, array $topic_data, $cp_mode)
241
	{
242
		$cp_param = '';
243
		if ($topic_data['topic_first_post_id'] == $post_data['post_id'])
244
		{
245
			$cp_param = '&amp;cp=' . ((!$cp_mode) ? (($this->user_is_poster($post_data['poster_id'])) ? 'ucp' : 'mcp') : $cp_mode);
246
		}
247
		return $cp_param;
248
	}
249
}
250