Completed
Push — develop ( 427889...5e581d )
by Daniel
12:10
created

helper::get_delete_url()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
dl 0
loc 5
ccs 0
cts 4
cp 0
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 3
nc 2
nop 3
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
class helper extends permissions
13
{
14
	/** @var string */
15
	protected $phpbb_root_path;
16
17
	/** @var string */
18
	protected $php_ext;
19
20
	/**
21
	 * Constructor
22
	 *
23
	 * @param \phpbb\auth\auth		$auth				Auth object
24
	 * @param \phpbb\config\db		$config				Config object
25
	 * @param \phpbb\user			$user				User object
26
	 * @param string				$phpbb_root_path	Path to the phpbb includes directory.
27
	 * @param string				$php_ext			php file extension
28
	*/
29
	public function __construct(\phpbb\auth\auth $auth, \phpbb\config\db $config, \phpbb\user $user, $phpbb_root_path, $php_ext)
30
	{
31
		parent::__construct($auth, $config, $user);
32
33
		$this->phpbb_root_path = $phpbb_root_path;
34
		$this->php_ext = $php_ext;
35
	}
36
37
	/**
38
	 * @param array $post_data
39
	 * @param array $topic_data
40
	 * @param string $cp_mode
41
	 * @return string
42
	 */
43
	public function get_edit_url(array $post_data, array $topic_data, $cp_mode = '')
44
	{
45
		$cp_param = $this->get_cp_param($post_data, $topic_data, $cp_mode);
46
		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) : '';
47
	}
48
49
	/**
50
	 * @param array $post_data
51
	 * @param array $topic_data
52
	 * @param string $cp_mode
53
	 * @return string
54
	 */
55
	public function get_delete_url(array $post_data, array $topic_data, $cp_mode = '')
56
	{
57
		$cp_param = $this->get_cp_param($post_data, $topic_data, $cp_mode);
58
		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) : '';
59
	}
60
61
	/**
62
	 * @param array $post_data
63
	 * @param array $topic_data
64
	 * @return string
65
	 */
66
	public function get_quote_url(array $post_data, array $topic_data)
67
	{
68
		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']}") : '';
69
	}
70
71
	/**
72
	 * @param array $topic_data
73
	 * @return string
74
	 */
75
	public function get_viewtopic_url(array $topic_data)
76
	{
77
		return append_sid("{$this->phpbb_root_path}viewtopic.$this->php_ext", "f={$topic_data['forum_id']}&amp;t={$topic_data['topic_id']}");
78
	}
79
80
	/**
81
	 * @param array $topic_data
82
	 * @return string
83
	 */
84
	public function get_print_topic_url(array $topic_data)
85
	{
86
		return ($this->auth->acl_get('f_print', $topic_data['forum_id'])) ? $topic_data['topic_url'] . '?view=print' : '';
87
	}
88
89
	/**
90
	 * @param array $topic_data
91
	 * @return string
92
	 */
93
	public function get_email_topic_url(array $topic_data)
94
	{
95
		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']) : '';
96
	}
97
98
	/**
99
	 * @param int $forum_id
100
	 * @param string $username
101
	 * @return string
102
	 */
103
	public function get_search_users_posts_url($forum_id, $username)
104
	{
105
		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");
106
	}
107
108
	/**
109
	 * @param array $post_data
110
	 * @return string
111
	 */
112
	public function get_info_url(array $post_data)
113
	{
114
		$forum_id = $post_data['forum_id'];
115
		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) : '';
116
	}
117
118
	/**
119
	 * @param array $post_data
120
	 * @param string $viewtopic_url
121
	 * @return string
122
	 */
123
	public function get_approve_url(array $post_data, $viewtopic_url)
124
	{
125
		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'])));
126
	}
127
128
	/**
129
	 * @param array $post_data
130
	 * @param array $topic_data
131
	 * @return string
132
	 */
133
	public function get_mcp_edit_url(array $post_data, array $topic_data)
134
	{
135
		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");
136
	}
137
138
	/**
139
	 * @param array $post_data
140
	 * @return string
141
	 */
142
	public function get_mcp_report_url(array $post_data)
143
	{
144
		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) : '';
145
	}
146
147
	/**
148
	 * @param array $post_data
149
	 * @param array $topic_data
150
	 * @return string
151
	 */
152
	public function get_mcp_restore_url(array $post_data, array $topic_data)
153
	{
154
		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) : '';
155
	}
156
157
	/**
158
	 * @param array $post_data
159
	 * @return string
160
	 */
161
	public function get_notes_url(array $post_data)
162
	{
163
		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) : '';
164
	}
165
166
	/**
167
	 * @param array $post_data
168
	 * @return string
169
	 */
170
	public function get_warning_url(array $post_data)
171
	{
172
		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) : '';
173
	}
174
175
	/**
176
	 * @param int $topic_id
177
	 * @return string
178
	 */
179
	public function get_mcp_queue_url($topic_id)
180
	{
181
		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);
182
	}
183
184
	/**
185
	 * @param string $content_type
186
	 * @param int $topic_id
187
	 * @return string
188
	 */
189
	public function get_mcp_review_url($content_type, $topic_id)
190
	{
191
		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");
192
	}
193
194
    /**
195
     * @param int $forum_id
196
     * @param int $topic_id
197
     * @return string
198
     */
199
	public function get_mcp_url($forum_id, $topic_id)
200
	{
201
		$u_mcp = '';
202
		if ($this->auth->acl_get('m_', $forum_id))
203
		{
204
			if ($topic_id)
205
			{
206
				$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);
207
			}
208
			else
209
			{
210
				$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);
211
			}
212
		}
213
		return $u_mcp;
214
	}
215
216
	/**
217
	 * @param array $post_data
218
	 * @param array $topic_data
219
	 * @param string $cp_mode
220
	 * @return string
221
	 */
222
	protected function get_cp_param(array $post_data, array $topic_data, $cp_mode)
223
	{
224
		$cp_param = '';
225
		if ($topic_data['topic_first_post_id'] == $post_data['post_id'])
226
		{
227
			$cp_param = '&amp;cp=' . ((!$cp_mode) ? (($this->user_is_poster($post_data['poster_id'])) ? 'ucp' : 'mcp') : $cp_mode);
228
		}
229
		return $cp_param;
230
	}
231
}
232