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

helper::get_viewtopic_url()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 4
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 2
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 urls
13
{
14
	/**
15
	 * @param array $post_data
16
	 * @return bool
17
	 */
18
	public function display_attachments_notice(array $post_data)
19
	{
20
		return (!$this->auth->acl_get('f_download', $post_data['forum_id']) && $post_data['post_attachment']);
21
	}
22
23
	/**
24
	 * @param array $post_data
25
	 * @return bool
26
	 */
27
	public function permanent_delete_allowed(array $post_data)
28
	{
29
		return ($this->auth->acl_get('m_delete', $post_data['forum_id']) ||
30
		($this->auth->acl_get('f_delete', $post_data['forum_id']) && $this->user->data['user_id'] == $post_data['poster_id']));
31
	}
32
33
	/**
34
	 * @param int $poster_id
35
	 * @return bool
36
	 */
37
	public function user_is_poster($poster_id)
38
	{
39
		return ($poster_id == $this->user->data['user_id']);
40
	}
41
42
	/**
43
	 * @param int $forum_id
44
	 * @return bool
45
	 */
46
	public function can_report_post($forum_id)
47
	{
48
		return ($this->auth->acl_get('f_report', $forum_id));
49
	}
50
51
	/**
52
	 * @param array $topic_data
53
	 * @return bool
54
	 */
55
	public function topic_has_unapproved_posts(array $topic_data)
56
	{
57
		return ($topic_data['topic_visibility'] == ITEM_APPROVED && $topic_data['topic_posts_unapproved'] && $this->auth->acl_get('m_approve', $topic_data['forum_id']));
58
	}
59
60
	/**
61
	 * @param array $topic_data
62
	 * @return bool
63
	 */
64
	public function topic_is_reported(array $topic_data)
65
	{
66
		return ($topic_data['topic_reported'] && !$topic_data['topic_moved_id'] && $this->auth->acl_get('m_report', $topic_data['forum_id'])) ? true : false;
67
	}
68
69
	/**
70
	 * @param array $topic_data
71
	 * @return bool
72
	 */
73
	public function topic_is_locked(array $topic_data)
74
	{
75
		return ($topic_data['topic_status'] == ITEM_UNLOCKED && $topic_data['forum_status'] == ITEM_UNLOCKED) ? false : true;
76
	}
77
78
	/**
79
	 * @param array $post_data
80
	 * @return bool
81
	 */
82
	public function post_is_unapproved(array $post_data)
83
	{
84
		return (($post_data['post_visibility'] == ITEM_UNAPPROVED || $post_data['post_visibility'] == ITEM_REAPPROVE) && $this->auth->acl_get('m_approve', $post_data['forum_id'])) ? true : false;
85
	}
86
87
	/**
88
	 * @param array $post_data
89
	 * @param array $topic_data
90
	 * @return bool
91
	 */
92
	protected function edit_allowed(array $post_data, array $topic_data)
93
	{
94
		return ($this->user->data['is_registered'] && ($this->auth->acl_get('m_edit', $post_data['forum_id']) || (
95
			!$this->cannot_edit($post_data) &&
96
			!$this->cannot_edit_time($post_data) &&
97
			!$this->cannot_edit_locked($post_data, $topic_data)
98
		)));
99
	}
100
101
	/**
102
	 * @param array $topic_data
103
	 * @return bool
104
	 */
105
	protected function quote_allowed(array $topic_data)
106
	{
107
		return $this->auth->acl_get('m_edit', $topic_data['forum_id']) || ($topic_data['topic_status'] != ITEM_LOCKED &&
108
			($this->user->data['user_id'] == ANONYMOUS || $this->auth->acl_get('f_reply', $topic_data['forum_id']))
109
		);
110
	}
111
112
	/**
113
	 * @param array $post_data
114
	 * @param array $topic_data
115
	 * @return bool
116
	 */
117
	protected function post_is_quotable(array $post_data, array $topic_data)
118
	{
119
		return ($post_data['post_visibility'] == ITEM_APPROVED && $topic_data['topic_first_post_id'] != $post_data['post_id']);
120
	}
121
122
	/**
123
	 * @param array $post_data
124
	 * @param array $topic_data
125
	 * @return bool
126
	 */
127
	protected function delete_allowed(array $post_data, array $topic_data)
128
	{
129
		return ($this->user->data['is_registered'] && (($this->auth->acl_get('m_delete', $post_data['forum_id']) || ($this->auth->acl_get('m_softdelete', $post_data['forum_id']) && $post_data['post_visibility'] != ITEM_DELETED)) || (
130
			!$this->cannot_delete($post_data) &&
131
			!$this->cannot_delete_lastpost($post_data, $topic_data) &&
132
			!$this->cannot_delete_time($post_data) &&
133
			!$this->cannot_delete_locked($post_data, $topic_data)
134
		)));
135
	}
136
137
	/**
138
	 * @param array $post_data
139
	 * @return bool
140
	 */
141
	protected function softdelete_allowed(array $post_data)
142
	{
143
		return ($this->auth->acl_get('m_softdelete', $post_data['forum_id']) ||
144
			($this->auth->acl_get('f_softdelete', $post_data['forum_id']) && $this->user->data['user_id'] == $post_data['poster_id'])) && ($post_data['post_visibility'] != ITEM_DELETED);
145
	}
146
147
	/**
148
	 * @param array $post_data
149
	 * @return bool
150
	 */
151
	protected function cannot_edit(array $post_data)
152
	{
153
		return (!$this->auth->acl_get('f_edit', $post_data['forum_id']) || $this->user->data['user_id'] != $post_data['poster_id']);
154
	}
155
156
	/**
157
	 * @param array $post_data
158
	 * @return bool
159
	 */
160
	protected function cannot_edit_time(array $post_data)
161
	{
162
		return ($this->config['edit_time'] && $post_data['post_time'] <= time() - ($this->config['edit_time'] * 60));
163
	}
164
165
	/**
166
	 * @param array $post_data
167
	 * @param array $topic_data
168
	 * @return bool
169
	 */
170
	protected function cannot_edit_locked(array $post_data, array $topic_data)
171
	{
172
		return ($topic_data['topic_status'] == ITEM_LOCKED || $post_data['post_edit_locked']);
173
	}
174
175
	/**
176
	 * @param array $post_data
177
	 * @return bool
178
	 */
179
	protected function cannot_delete(array $post_data)
180
	{
181
		return $this->user->data['user_id'] != $post_data['poster_id'] || (
182
			!$this->auth->acl_get('f_delete', $post_data['forum_id']) &&
183
			(!$this->auth->acl_get('f_softdelete', $post_data['forum_id']) || $post_data['post_visibility'] == ITEM_DELETED)
184
		);
185
	}
186
187
	/**
188
	 * @param array $post_data
189
	 * @param array $topic_data
190
	 * @return bool
191
	 */
192
	protected function cannot_delete_lastpost(array $post_data, array $topic_data)
193
	{
194
		return $topic_data['topic_last_post_id'] != $post_data['post_id'];
195
	}
196
197
	/**
198
	 * @param array $post_data
199
	 * @return bool
200
	 */
201
	protected function cannot_delete_time(array $post_data)
202
	{
203
		return $this->config['delete_time'] && $post_data['post_time'] <= time() - ($this->config['delete_time'] * 60);
204
	}
205
206
	/**
207
	 * we do not want to allow removal of the last post if a moderator locked it!
208
	 * @param array $post_data
209
	 * @param array $topic_data
210
	 * @return bool
211
	 */
212
	protected function cannot_delete_locked(array $post_data, array $topic_data)
213
	{
214
		return $topic_data['topic_status'] == ITEM_LOCKED || $post_data['post_edit_locked'];
215
	}
216
}
217