Skip to content

Commit a1e7fa3

Browse files
committed
Add auto-unlock, and check for lock permissions.
Turning on "lock solved topics" option now still requires that the user either have "m_lock" permission or "f_user_lock" permission before the topic will be automatically locked. Otherwise the topic will only be marked as solved without locking. Additionally, unsolving a topic will only unlock it if the user is a moderator with "m_lock" permission, and will only do so if the "lock solved topics" option is enabled. Fixes #16, #17
1 parent 41d34e7 commit a1e7fa3

File tree

3 files changed

+81
-21
lines changed

3 files changed

+81
-21
lines changed

controller/main_controller.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,14 @@ public function mark($solve, $post_id)
5454

5555
$this->check_solve_conditions($solve, $topic_data);
5656

57-
$lock_topic = (bool) $topic_data['forum_lock_solved'];
58-
$solved_post_id = $solve == 'solved' ? $post_id : 0;
59-
$this->topicsolved->update_topic_solved(
60-
$topic_data['topic_id'], $solved_post_id, $lock_topic);
57+
if ($solve == 'solved')
58+
{
59+
$this->topicsolved->mark_solved($topic_data, $post_id);
60+
}
61+
else
62+
{
63+
$this->topicsolved->mark_unsolved($topic_data);
64+
}
6165

6266
$post_url = $this->topicsolved->get_link_to_post(
6367
$topic_data['forum_id'], $topic_data['topic_id'], $post_id);

readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ This is an update of the phpBB 3.0.x Topic Solved MOD, written by Jari Kanerva.
2222
* Custom text indicators can use custom colour.
2323
* Only topic author or moderator can solve topics.
2424
* Can be locked to only moderator access for solving topics.
25-
* Solving topics may be set to automatically lock the topic.
25+
* Solving topics may be set to automatically lock/unlock the topic.
2626
* All settings can be customized per-forum.
2727

2828
## Translations

topicsolved.php

Lines changed: 72 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public function user_can_solve_post($solved, $topic_data)
9494

9595
if (($topic_data[$forum_permission[$solved]] == topicsolved::TOPIC_SOLVED_MOD ||
9696
$topic_data[$forum_permission[$solved]] == topicsolved::TOPIC_SOLVED_YES) &&
97-
$this->auth->acl_get('m_'))
97+
$this->auth->acl_get('m_', $topic_data['forum_id']))
9898
{
9999
return true;
100100
}
@@ -140,26 +140,15 @@ public function get_topic_data($post_id)
140140
}
141141

142142
/**
143-
* Mark topic as solved with the given post.
143+
* Update topic with the given data.
144144
*
145-
* Post will only be locked if marking as solved, not when unsolving. This
146-
* method does not do any validation. Data should be validated first.
147-
*
148-
* @param int $topic_id Topic to be marked.
149-
* @param int $post_id Solved post or 0 for unsolved topic.
150-
* @param bool $lock Lock the topic after marking as solved.
145+
* @param int $topic_id Topic to update.
146+
* @param int $data Topic data to update.
151147
*
152148
* @return mixed true if successful
153149
*/
154-
public function update_topic_solved($topic_id, $post_id, $lock = false)
150+
public function update_topic($topic_id, $data)
155151
{
156-
$data = array('topic_solved' => $post_id);
157-
158-
if ($lock)
159-
{
160-
$data['topic_status'] = ITEM_LOCKED;
161-
}
162-
163152
$update_sql = $this->db->sql_build_array('UPDATE', $data);
164153
$result = $this->db->sql_query('
165154
UPDATE ' . TOPICS_TABLE . '
@@ -170,6 +159,73 @@ public function update_topic_solved($topic_id, $post_id, $lock = false)
170159
return $result;
171160
}
172161

162+
/**
163+
* Marks a topic as solved.
164+
*
165+
* @param array $topic_data Topic to be marked as solved.
166+
* @param int $post_id Post to mark as the solution.
167+
*/
168+
public function mark_solved($topic_data, $post_id)
169+
{
170+
// Database column values to set.
171+
$column_data = array('topic_solved' => $post_id);
172+
173+
if ($topic_data['forum_lock_solved'] &&
174+
$this->user_can_lock_post($topic_data['forum_id']))
175+
{
176+
$column_data['topic_status'] = ITEM_LOCKED;
177+
}
178+
179+
$this->update_topic($topic_data['topic_id'], $column_data);
180+
}
181+
182+
/**
183+
* Marks a topic as unsolved.
184+
*
185+
* @param array $topic_data Topic to be marked as unsolved.
186+
*/
187+
public function mark_unsolved($topic_data)
188+
{
189+
// Database column values to set.
190+
$column_data = array('topic_solved' => 0);
191+
192+
if ($topic_data['forum_lock_solved'] &&
193+
$this->auth->acl_get('m_lock', $topic_data['forum_id']))
194+
{
195+
$column_data['topic_status'] = ITEM_UNLOCKED;
196+
}
197+
198+
$this->update_topic($topic_data['topic_id'], $column_data);
199+
}
200+
201+
/**
202+
* Checks if the currently logged in user has permission to lock a post.
203+
*
204+
* Regular users won't have permission to solve any topics other than their
205+
* own, and moderator permissions are forum based, so we only need to know
206+
* the forum, not the post.
207+
*
208+
* @param int $forum_id Forum to check permissions on.
209+
*
210+
* @return bool true if user has permission to lock a post.
211+
*/
212+
public function user_can_lock_post($forum_id)
213+
{
214+
// Check if user is moderator with appropriate lock permission
215+
if ($this->auth->acl_get('m_lock', $forum_id))
216+
{
217+
return true;
218+
}
219+
220+
// Check if user has "lock own posts" permission
221+
if ($this->auth->acl_get('f_user_lock', $forum_id))
222+
{
223+
return true;
224+
}
225+
226+
return false;
227+
}
228+
173229
/**
174230
* Generate markup for the given solved indicator image.
175231
*

0 commit comments

Comments
 (0)