Skip to content

Commit 988a526

Browse files
committed
Add name param in some topic urls
1 parent e92dcf0 commit 988a526

File tree

5 files changed

+36
-29
lines changed

5 files changed

+36
-29
lines changed

featherbb/Controller/Topic.php

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,15 +78,15 @@ public function display($req, $res, $args)
7878
}
7979

8080
$quickpost = $this->model->is_quickpost($cur_topic['post_replies'], $cur_topic['closed'], $is_admmod);
81-
$subscraction = $this->model->get_subscraction(($cur_topic['is_subscribed'] == User::get()->id), $args['id']);
81+
$subscraction = $this->model->get_subscraction(($cur_topic['is_subscribed'] == User::get()->id), $args['id'], $args['name']);
8282

83-
View::addAsset('canonical', Router::pathFor('Forum', ['id' => $args['id'], 'name' => $url_forum]));
83+
View::addAsset('canonical', Router::pathFor('Topic', ['id' => $args['id'], 'name' => $url_topic]));
8484
if ($num_pages > 1) {
8585
if ($p > 1) {
86-
View::addAsset('prev', Router::pathFor('ForumPaginate', ['id' => $args['id'], 'name' => $url_forum, 'page' => intval($p-1)]));
86+
View::addAsset('prev', Router::pathFor('Topic', ['id' => $args['id'], 'name' => $url_forum, 'page' => intval($p-1)]));
8787
}
8888
if ($p < $num_pages) {
89-
View::addAsset('next', Router::pathFor('ForumPaginate', ['id' => $args['id'], 'name' => $url_forum, 'page' => intval($p+1)]));
89+
View::addAsset('next', Router::pathFor('Topic', ['id' => $args['id'], 'name' => $url_forum, 'page' => intval($p+1)]));
9090
}
9191
}
9292

@@ -132,14 +132,17 @@ public function subscribe($req, $res, $args)
132132
{
133133
$args['id'] = Container::get('hooks')->fire('controller.topic.subscribe', $args['id']);
134134

135-
return $this->model->subscribe($args['id']);
135+
$this->model->subscribe($args['id']);
136+
return Router::redirect(Router::pathFor('Topic', ['id' => $args['id'], 'name' => $args['name']]), __('Subscribe redirect'));
136137
}
137138

138139
public function unsubscribe($req, $res, $args)
139140
{
140141
$args['id'] = Container::get('hooks')->fire('controller.topic.unsubscribe', $args['id']);
141142

142-
return $this->model->unsubscribe($args['id']);
143+
$this->model->unsubscribe($args['id']);
144+
145+
return Router::redirect(Router::pathFor('Topic', ['id' => $args['id'], 'name' => $args['name']]), __('Unsubscribe redirect'));
143146
}
144147

145148
public function close($req, $res, $args)

featherbb/Model/Api/Topic.php

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,8 @@ public function send_notifications_new_topic($post, $cur_posting, $new_tid)
349349
$cleaned_message = Container::get('email')->bbcode2email($post['message'], -1);
350350
}
351351

352+
$cleaned_subject = ForumSettings::get('o_censoring') == '1' ? $censored_subject : $post['subject']
353+
352354
// Loop through subscribed users and send emails
353355
foreach($result as $cur_subscriber) {
354356
// Is the subscription email for $cur_subscriber['language'] cached or not?
@@ -370,20 +372,20 @@ public function send_notifications_new_topic($post, $cur_posting, $new_tid)
370372
$mail_message_full = trim(substr($mail_tpl_full, $first_crlf));
371373

372374
$mail_subject = str_replace('<forum_name>', $cur_posting['forum_name'], $mail_subject);
373-
$mail_message = str_replace('<topic_subject>', ForumSettings::get('o_censoring') == '1' ? $censored_subject : $post['subject'], $mail_message);
375+
$mail_message = str_replace('<topic_subject>', $cleaned_subject, $mail_message);
374376
$mail_message = str_replace('<forum_name>', $cur_posting['forum_name'], $mail_message);
375377
$mail_message = str_replace('<poster>', $post['username'], $mail_message);
376-
$mail_message = str_replace('<topic_url>', Router::pathFor('Topic', ['id' => $new_tid]), $mail_message);
377-
$mail_message = str_replace('<unsubscribe_url>', Router::pathFor('unsubscribeTopic', ['id' => $cur_posting['id']]), $mail_message);
378+
$mail_message = str_replace('<topic_url>', Router::pathFor('Topic', ['id' => $new_tid, 'name' => Url::url_friendly($post['subject'])]), $mail_message);
379+
$mail_message = str_replace('<unsubscribe_url>', Router::pathFor('unsubscribeTopic', ['id' => $cur_posting['id'], 'name' => Url::url_friendly($post['subject'])]), $mail_message);
378380
$mail_message = str_replace('<board_mailer>', ForumSettings::get('o_board_title'), $mail_message);
379381

380382
$mail_subject_full = str_replace('<forum_name>', $cur_posting['forum_name'], $mail_subject_full);
381-
$mail_message_full = str_replace('<topic_subject>', ForumSettings::get('o_censoring') == '1' ? $censored_subject : $post['subject'], $mail_message_full);
383+
$mail_message_full = str_replace('<topic_subject>', $cleaned_subject, $mail_message_full);
382384
$mail_message_full = str_replace('<forum_name>', $cur_posting['forum_name'], $mail_message_full);
383385
$mail_message_full = str_replace('<poster>', $post['username'], $mail_message_full);
384386
$mail_message_full = str_replace('<message>', $cleaned_message, $mail_message_full);
385-
$mail_message_full = str_replace('<topic_url>', Router::pathFor('Topic', ['id' => $new_tid]), $mail_message_full);
386-
$mail_message_full = str_replace('<unsubscribe_url>', Router::pathFor('unsubscribeTopic', ['id' => $tid]), $mail_message_full);
387+
$mail_message_full = str_replace('<topic_url>', Router::pathFor('Topic', ['id' => $new_tid, 'name' => Url::url_friendly($post['subject'])]), $mail_message_full);
388+
$mail_message_full = str_replace('<unsubscribe_url>', Router::pathFor('unsubscribeTopic', ['id' => $tid, 'name' => Url::url_friendly($post['subject'])]), $mail_message_full);
387389
$mail_message_full = str_replace('<board_mailer>', ForumSettings::get('o_board_title'), $mail_message_full);
388390

389391
$notification_emails[$cur_subscriber['language']][0] = $mail_subject;
@@ -441,4 +443,4 @@ public function increment_post_count($post, $new_tid)
441443
$last_post = $last_post->save();
442444
}
443445
}
444-
}
446+
}

featherbb/Model/Post.php

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -844,7 +844,7 @@ public function send_notifications_reply($tid, $cur_posting, $new_pid, $post)
844844
$mail_message = str_replace('<topic_subject>', $cur_posting['subject'], $mail_message);
845845
$mail_message = str_replace('<replier>', $post['username'], $mail_message);
846846
$mail_message = str_replace('<post_url>', Router::pathFor('viewPost', ['id' => $tid, 'name' => Url::url_friendly($cur_posting['subject']), 'pid' => $new_pid]).'#p'.$new_pid, $mail_message);
847-
$mail_message = str_replace('<unsubscribe_url>', Router::pathFor('unsubscribeTopic', ['id' => $tid]), $mail_message);
847+
$mail_message = str_replace('<unsubscribe_url>', Router::pathFor('unsubscribeTopic', ['id' => $tid, 'name' => Url::url_friendly($cur_posting['subject'])]), $mail_message);
848848
$mail_message = str_replace('<board_mailer>', ForumSettings::get('o_board_title'), $mail_message);
849849
$mail_message = Container::get('hooks')->fire('model.post.send_notifications_reply_mail_message', $mail_message);
850850

@@ -853,7 +853,7 @@ public function send_notifications_reply($tid, $cur_posting, $new_pid, $post)
853853
$mail_message_full = str_replace('<replier>', $post['username'], $mail_message_full);
854854
$mail_message_full = str_replace('<message>', $cleaned_message, $mail_message_full);
855855
$mail_message_full = str_replace('<post_url>', Router::pathFor('viewPost', ['id' => $tid, 'name' => Url::url_friendly($cur_posting['subject']), 'pid' => $new_pid]).'#p'.$new_pid, $mail_message_full);
856-
$mail_message_full = str_replace('<unsubscribe_url>', Router::pathFor('unsubscribeTopic', ['id' => $tid]), $mail_message_full);
856+
$mail_message_full = str_replace('<unsubscribe_url>', Router::pathFor('unsubscribeTopic', ['id' => $tid, 'name' => Url::url_friendly($cur_posting['subject'])]), $mail_message_full);
857857
$mail_message_full = str_replace('<board_mailer>', ForumSettings::get('o_board_title'), $mail_message_full);
858858
$mail_message_full = Container::get('hooks')->fire('model.post.send_notifications_reply_mail_message_full', $mail_message_full);
859859

@@ -1027,6 +1027,8 @@ public function send_notifications_new_topic($post, $cur_posting, $new_tid)
10271027
$cleaned_message = Container::get('email')->bbcode2email($post['message'], -1);
10281028
}
10291029

1030+
$cleaned_subject = ForumSettings::get('o_censoring') == '1' ? $censored_subject : $post['subject']
1031+
10301032
// Loop through subscribed users and send emails
10311033
foreach($result as $cur_subscriber) {
10321034
// Is the subscription email for $cur_subscriber['language'] cached or not?
@@ -1049,21 +1051,21 @@ public function send_notifications_new_topic($post, $cur_posting, $new_tid)
10491051
$mail_message_full = trim(substr($mail_tpl_full, $first_crlf));
10501052

10511053
$mail_subject = str_replace('<forum_name>', $cur_posting['forum_name'], $mail_subject);
1052-
$mail_message = str_replace('<topic_subject>', ForumSettings::get('o_censoring') == '1' ? $censored_subject : $post['subject'], $mail_message);
1054+
$mail_message = str_replace('<topic_subject>', $cleaned_subject, $mail_message);
10531055
$mail_message = str_replace('<forum_name>', $cur_posting['forum_name'], $mail_message);
10541056
$mail_message = str_replace('<poster>', $post['username'], $mail_message);
1055-
$mail_message = str_replace('<topic_url>', Router::pathFor('Topic', ['id' => $new_tid]), $mail_message);
1056-
$mail_message = str_replace('<unsubscribe_url>', Router::pathFor('unsubscribeTopic', ['id' => $cur_posting['id']]), $mail_message);
1057+
$mail_message = str_replace('<topic_url>', Router::pathFor('Topic', ['id' => $new_tid, 'name' => Url::url_friendly($post['subject'])]), $mail_message);
1058+
$mail_message = str_replace('<unsubscribe_url>', Router::pathFor('unsubscribeTopic', ['id' => $cur_posting['id'], 'name' => Url::url_friendly($post['subject'])]), $mail_message);
10571059
$mail_message = str_replace('<board_mailer>', ForumSettings::get('o_board_title'), $mail_message);
10581060
$mail_message = Container::get('hooks')->fire('model.post.send_notifications_new_topic_mail_message', $mail_message);
10591061

10601062
$mail_subject_full = str_replace('<forum_name>', $cur_posting['forum_name'], $mail_subject_full);
1061-
$mail_message_full = str_replace('<topic_subject>', ForumSettings::get('o_censoring') == '1' ? $censored_subject : $post['subject'], $mail_message_full);
1063+
$mail_message_full = str_replace('<topic_subject>', $cleaned_subject, $mail_message_full);
10621064
$mail_message_full = str_replace('<forum_name>', $cur_posting['forum_name'], $mail_message_full);
10631065
$mail_message_full = str_replace('<poster>', $post['username'], $mail_message_full);
10641066
$mail_message_full = str_replace('<message>', $cleaned_message, $mail_message_full);
1065-
$mail_message_full = str_replace('<topic_url>', Router::pathFor('Topic', ['id' => $new_tid]), $mail_message_full);
1066-
$mail_message_full = str_replace('<unsubscribe_url>', Router::pathFor('unsubscribeTopic', ['id' => $tid]), $mail_message_full);
1067+
$mail_message_full = str_replace('<topic_url>', Router::pathFor('Topic', ['id' => $new_tid, 'name' => Url::url_friendly($post['subject'])]), $mail_message_full);
1068+
$mail_message_full = str_replace('<unsubscribe_url>', Router::pathFor('unsubscribeTopic', ['id' => $tid, 'name' => Url::url_friendly($post['subject'])]), $mail_message_full);
10671069
$mail_message_full = str_replace('<board_mailer>', ForumSettings::get('o_board_title'), $mail_message_full);
10681070
$mail_message_full = Container::get('hooks')->fire('model.post.send_notifications_new_topic_mail_message_full', $mail_message_full);
10691071

featherbb/Model/Topic.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ public function subscribe($topic_id)
260260
$subscription = Container::get('hooks')->fireDB('model.topic.subscribe_topic_query', $subscription);
261261
$subscription = $subscription->save();
262262

263-
return Router::redirect(Router::pathFor('Topic', ['id' => $topic_id]), __('Subscribe redirect'));
263+
return $subscription;
264264
}
265265

266266
public function unsubscribe($topic_id)
@@ -288,24 +288,24 @@ public function unsubscribe($topic_id)
288288
$delete = Container::get('hooks')->fireDB('model.topic.unsubscribe_topic_query', $delete);
289289
$delete = $delete->delete_many();
290290

291-
return Router::redirect(Router::pathFor('Topic', ['id' => $topic_id]), __('Unsubscribe redirect'));
291+
return $delete;
292292
}
293293

294294
// Subscraction link
295-
public function get_subscraction($is_subscribed, $topic_id)
295+
public function get_subscraction($is_subscribed, $topic_id, $topic_subject)
296296
{
297297
if (!User::get()->is_guest && ForumSettings::get('o_topic_subscriptions') == '1') {
298298
if ($is_subscribed) {
299299
// I apologize for the variable naming here. It's a mix of subscription and action I guess :-)
300-
$subscraction = "\t\t".'<p class="subscribelink clearb"><span>'.__('Is subscribed').' - </span><a href="proxy.php?url=https%3A%2F%2Fgithub.com%2F%3C%2Fspan%3E".Router::pathFor('unsubscribeTopic', ['id' => $topic_id]).'">'.__('Unsubscribe').'</a></p>'."\n";
300+
$subscraction = "\t\t".'<p class="subscribelink clearb"><span>'.__('Is subscribed').' - </span><a href="proxy.php?url=https%3A%2F%2Fgithub.com%2F%3C%2Fspan%3E".Router::pathFor('unsubscribeTopic', ['id' => $topic_id, 'name' => $topic_subject]).'">'.__('Unsubscribe').'</a></p>'."\n";
301301
} else {
302-
$subscraction = "\t\t".'<p class="subscribelink clearb"><a href="proxy.php?url=https%3A%2F%2Fgithub.com%2F%3C%2Fspan%3E".Router::pathFor('subscribeTopic', ['id' => $topic_id]).'">'.__('Subscribe').'</a></p>'."\n";
302+
$subscraction = "\t\t".'<p class="subscribelink clearb"><a href="proxy.php?url=https%3A%2F%2Fgithub.com%2F%3C%2Fspan%3E".Router::pathFor('subscribeTopic', ['id' => $topic_id, 'name' => $topic_subject]).'">'.__('Subscribe').'</a></p>'."\n";
303303
}
304304
} else {
305305
$subscraction = '';
306306
}
307307

308-
$subscraction = Container::get('hooks')->fire('model.topic.get_subscraction', $subscraction, $is_subscribed, $topic_id);
308+
$subscraction = Container::get('hooks')->fire('model.topic.get_subscraction', $subscraction, $is_subscribed, $topic_id, $topic_subject);
309309

310310
return $subscraction;
311311
}

featherbb/routes.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@
3838
Route::get('/{id:[0-9]+}/{name:[\w\-]+}/page/{page:[0-9]+}', '\FeatherBB\Controller\Topic:display')->setName('TopicPaginate');
3939
Route::get('/{id:[0-9]+}/{name:[\w\-]+}/post/{pid:[0-9]+}', '\FeatherBB\Controller\Topic:viewpost')->setName('viewPost');
4040
Route::get('/{id:[0-9]+}/{name:[\w\-]+}/action/{action:[\w\-]+}', '\FeatherBB\Controller\Topic:action')->setName('topicAction');
41-
Route::get('/subscribe/{id:[0-9]+}[/{name:[\w\-]+}]', '\FeatherBB\Controller\Topic:subscribe')->add(new IsLogged)->setName('subscribeTopic');
42-
Route::get('/unsubscribe/{id:[0-9]+}[/{name:[\w\-]+}]', '\FeatherBB\Controller\Topic:unsubscribe')->add(new IsLogged)->setName('unsubscribeTopic');
41+
Route::get('/subscribe/{id:[0-9]+}/{name:[\w\-]+}', '\FeatherBB\Controller\Topic:subscribe')->add(new IsLogged)->setName('subscribeTopic');
42+
Route::get('/unsubscribe/{id:[0-9]+}/{name:[\w\-]+}', '\FeatherBB\Controller\Topic:unsubscribe')->add(new IsLogged)->setName('unsubscribeTopic');
4343
Route::get('/close/{id:[0-9]+}[/{name:[\w\-]+}]', '\FeatherBB\Controller\Topic:close')->add(new IsAdmMod)->setName('closeTopic');
4444
Route::get('/open/{id:[0-9]+}[/{name:[\w\-]+}]', '\FeatherBB\Controller\Topic:open')->add(new IsAdmMod)->setName('openTopic');
4545
Route::get('/stick/{id:[0-9]+}[/{name:[\w\-]+}]', '\FeatherBB\Controller\Topic:stick')->add(new IsAdmMod)->setName('stickTopic');

0 commit comments

Comments
 (0)