Skip to content

Commit 3372385

Browse files
committed
Initial commit for forum package
0 parents  commit 3372385

File tree

85 files changed

+5470
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

85 files changed

+5470
-0
lines changed

.travis.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
language: php
2+
3+
php:
4+
- 5.3
5+
- 5.4
6+
- 5.5
7+
8+
before_script:
9+
- curl -s http://getcomposer.org/installer | php
10+
- php composer.phar install --dev
11+
12+
script: phpunit

composer.json

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
{
2+
"name": "syntax/forum",
3+
"description": "An upgrade to syntax/core to add forum functionality.",
4+
"license": "MIT",
5+
"authors": [
6+
{
7+
"name": "Stygian",
8+
"email": "[email protected]"
9+
},
10+
{
11+
"name": "Riddles",
12+
"email": "[email protected]"
13+
}
14+
],
15+
"require": {
16+
"php": ">=5.3.0",
17+
"syntax/core": ">=2"
18+
},
19+
"autoload": {
20+
"classmap": [
21+
"src/controllers",
22+
"src/models",
23+
"src/presenters",
24+
"src/services",
25+
"src/views"
26+
],
27+
"psr-0": {
28+
"Syntax\\Forum\\": "src/"
29+
}
30+
},
31+
"extra": {
32+
"branch-alias": {
33+
"dev-master": "1.0-dev"
34+
}
35+
}
36+
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
<?php namespace Syntax\Forum;
2+
3+
use Illuminate\Support\ServiceProvider;
4+
5+
class ForumServiceProvider extends ServiceProvider {
6+
7+
/**
8+
* Indicates if loading of the provider is deferred.
9+
*
10+
* @var bool
11+
*/
12+
protected $defer = false;
13+
14+
/**
15+
* Bootstrap the application events.
16+
*
17+
* @return void
18+
*/
19+
public function boot()
20+
{
21+
$this->package('syntax/forum');
22+
}
23+
24+
/**
25+
* Register the service provider.
26+
*
27+
* @return void
28+
*/
29+
public function register()
30+
{
31+
$this->shareWithApp();
32+
$this->registerViews();
33+
}
34+
35+
/**
36+
* Share the package with application
37+
*
38+
* @return void
39+
*/
40+
protected function shareWithApp()
41+
{
42+
$this->app['forum'] = $this->app->share(function($app)
43+
{
44+
return true;
45+
});
46+
}
47+
48+
/**
49+
* Register views
50+
*
51+
* @return void
52+
*/
53+
protected function registerViews()
54+
{
55+
$this->app['view']->addNamespace('forum', __DIR__.'/../../../views');
56+
}
57+
58+
/**
59+
* Get the services provided by the provider.
60+
*
61+
* @return array
62+
*/
63+
public function provides()
64+
{
65+
return array();
66+
}
67+
68+
}
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
<?php
2+
3+
class Core_ForumController extends BaseController {
4+
5+
public function getIndex()
6+
{
7+
// Get the categories
8+
$categories = Forum_Category::with(array('type', 'boards'))->orderBy('position', 'asc')->get();
9+
$statuses = Forum_Post_Status::all();
10+
11+
$openIssues = 0;
12+
$inProgressIssues = 0;
13+
$resolvedIssues = 0;
14+
foreach ($statuses as $status) {
15+
switch ($status->forum_support_status_id) {
16+
case Forum_Support_Status::TYPE_OPEN:
17+
$openIssues++;
18+
break;
19+
case Forum_Support_Status::TYPE_IN_PROGRESS:
20+
$inProgressIssues++;
21+
break;
22+
case Forum_Support_Status::TYPE_RESOLVED:
23+
$resolvedIssues++;
24+
break;
25+
}
26+
}
27+
28+
$forum = new Forum;
29+
$recentPosts = $forum->recentPosts();
30+
$recentSupportPosts = $forum->recentSupportPosts();
31+
32+
// Set the template
33+
$this->setViewData('categories', $categories);
34+
$this->setViewData('openIssues', $openIssues);
35+
$this->setViewData('inProgressIssues', $inProgressIssues);
36+
$this->setViewData('resolvedIssues', $resolvedIssues);
37+
$this->setViewData('recentPosts', $recentPosts);
38+
$this->setViewData('recentSupportPosts', $recentSupportPosts);
39+
}
40+
41+
public function getSearch()
42+
{
43+
$typesArray = [
44+
'all' => 'All types',
45+
'Forum_Post' => 'Post',
46+
'Forum_Reply' => 'Reply'
47+
];
48+
49+
$users = User::orderByNameAsc()->get()->toSelectArray('Select a user', 'id', 'username');
50+
$statuses = Forum_Support_Status::all()->toSelectArray('Select a status');
51+
52+
$this->setViewData('typesArray', $typesArray);
53+
$this->setViewData('users', $users);
54+
$this->setViewData('statuses', $statuses);
55+
}
56+
57+
public function postSearch()
58+
{
59+
$searchTerm = Input::get('keyword');
60+
61+
$posts = Forum_View::where('name', 'LIKE', '%'. $searchTerm .'%')->orWhere('content', 'LIKE', '%'. $searchTerm .'%')->paginate(20);
62+
63+
$typesArray = [
64+
'all' => 'All types',
65+
'Forum_Post' => 'Post',
66+
'Forum_Reply' => 'Reply'
67+
];
68+
69+
$users = User::orderByNameAsc()->get();
70+
$users = $this->arrayToSelect($users, 'id', 'username', 'Select a user');
71+
72+
$this->setViewData('typesArray', $typesArray);
73+
$this->setViewData('users', $users);
74+
$this->setViewData('posts', $posts);
75+
}
76+
77+
public function getSearchResults()
78+
{
79+
$searchTerm = Input::get('keyword');
80+
$type = Input::get('type');
81+
$user = Input::get('user');
82+
83+
$posts = Forum_View::orderBy('lastModified', 'desc');
84+
85+
if ($user != '0') {
86+
$posts->where('user_id', $user);
87+
}
88+
89+
if ($type != 'all') {
90+
$posts->where('type', $type);
91+
}
92+
93+
if ($searchTerm != '') {
94+
if ($user != '0' || $type != 'all') {
95+
$posts->where(function ($query) use ($searchTerm) {
96+
$query->where('name', 'LIKE', '%'. $searchTerm .'%');
97+
$query->orWhere('content', 'LIKE', '%'. $searchTerm .'%');
98+
});
99+
} else {
100+
$posts->where('name', 'LIKE', '%'. $searchTerm .'%')->orWhere('content', 'LIKE', '%'. $searchTerm .'%');
101+
}
102+
}
103+
104+
$posts = $posts->paginate(20);
105+
106+
$this->setViewData('posts', $posts);
107+
}
108+
109+
public function postPreview()
110+
{
111+
$this->skipView();
112+
$input = Input::all();
113+
return BBCode::parse(e($input['update']));
114+
}
115+
116+
public function getMarkAllRead()
117+
{
118+
$this->skipView();
119+
120+
$forum = new Forum;
121+
$forum->markAllReadByUser($this->activeUser->id);
122+
123+
$this->redirect('back', 'All posts marked read.');
124+
}
125+
}

0 commit comments

Comments
 (0)