Skip to content

Commit d832d75

Browse files
committed
fixed comment urls
1 parent 556afed commit d832d75

File tree

5 files changed

+35
-11
lines changed

5 files changed

+35
-11
lines changed

app/controllers/ForumController.php

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public function getIndex()
2828
public function getThread()
2929
{
3030
$thread = App::make('slugModel');
31-
$comments = $this->comments->getThreadCommentsPaginated($thread, 5);
31+
$comments = $this->comments->getThreadCommentsPaginated($thread, Comment::PER_PAGE);
3232

3333
$this->view('forum.thread', compact('thread', 'comments'));
3434
}
@@ -167,4 +167,21 @@ public function postEditComment($commentId)
167167

168168
return $this->redirectAction('ForumController@getThread', [$comment->parent->slug->slug]);
169169
}
170+
171+
public function getComment($thread, $commentId)
172+
{
173+
// Holy shit worst code ever made..
174+
// LYLAS!
175+
176+
$perPage = Comment::PER_PAGE;
177+
$comment = Comment::find($commentId);
178+
$before = Comment::where('parent_id', '=', $comment->parent_id)->where('created_at', '<', $comment->created_at)->count();
179+
180+
$page = round($before / $perPage, 0, PHP_ROUND_HALF_DOWN) + 1;
181+
182+
$url = action('ForumController@getThread', [$thread]);
183+
184+
return Redirect::to($url . '?page=' . $page . '#comment-' . $commentId);
185+
186+
}
170187
}

app/domain/Lio/Comments/Comment.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ class Comment extends EloquentBaseModel implements SlugInterface
2222
const TYPE_PASTE = 1;
2323
const TYPE_ARTICLE = 2;
2424

25+
const PER_PAGE = 5;
26+
2527
public function owner()
2628
{
2729
return $this->morphTo('owner');
@@ -88,6 +90,7 @@ public function getSlugString()
8890
return $this->getForumPostSlugString();
8991
}
9092
}
93+
9194
//
9295

9396
private function getForumPostSlugString()

app/domain/Lio/Comments/CommentPresenter.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,8 @@ public function commentUrl()
2121

2222
if ( ! $slug) return '';
2323

24-
if( Input::has('page')) {
25-
$pagination = '?page=' . Input::get('page');
26-
}
27-
28-
$url = action('ForumController@getThread', [$slug->slug]);
29-
return $url . $pagination . "#comment-{$this->id}";
24+
$url = action('ForumController@getComment', [$slug->slug, $this->id]);
25+
return $url;
3026
}
3127

3228
public function child_count_label()

app/routes.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@
3636

3737
// forum
3838
Route::get('forum', 'ForumController@getIndex');
39+
Route::get('forum/{slug}/comment/{commentId}', 'ForumController@getComment');
40+
3941
Route::get('forum/create-thread', ['before' => 'auth', 'uses' => 'ForumController@getCreateThread']);
4042
Route::post('forum/create-thread', ['before' => 'auth', 'uses' => 'ForumController@postCreateThread']);
4143
Route::get('forum/edit-thread/{threadId}', ['before' => 'auth', 'uses' => 'ForumController@getEditThread']);
@@ -45,6 +47,8 @@
4547
Route::get('forum/{slug}', ['before' => 'handle_slug', 'uses' => 'ForumController@getThread']);
4648
Route::post('forum/{slug}', ['before' => 'auth|handle_slug', 'uses' => 'ForumController@postThread']);
4749

50+
51+
4852
// admin
4953
Route::group(['before' => 'auth', 'prefix' => 'admin'], function() {
5054

public/javascripts/forums.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,16 @@ function limitTagCheckboxes()
88

99
function moveSidebar()
1010
{
11-
$( "window" ).bind( "resize", function() {
12-
if (document.width < '800') {
13-
$('.sidebar').insertAfter('section.content');
11+
$( window ).bind( "resize", function() {
12+
if (document.width < 800) {
13+
$('.sidebar').insertAfter('.content');
1414
}
1515
});
16+
17+
if (document.width < 800) {
18+
$('.sidebar').insertAfter('.content');
19+
}
1620
}
1721

1822
limitTagCheckboxes();
19-
moveSidebar();
23+
// moveSidebar();

0 commit comments

Comments
 (0)