forked from summerblue/phphub
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 224ba1a
Showing
142 changed files
with
12,693 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
* text=auto |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
.idea/* | ||
/bootstrap/compiled.php | ||
/vendor | ||
/node_modules | ||
composer.phar | ||
.env.*.php | ||
.env.php | ||
.DS_Store | ||
Thumbs.db | ||
|
||
tests/_output/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Contribution Guidelines | ||
|
||
Please submit all issues and pull requests to the [laravel/framework](http://github.com/laravel/framework) repository! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
var gulp = require('gulp'); | ||
var sass = require('gulp-sass'); | ||
var autoprefixer = require('gulp-autoprefixer'); | ||
|
||
gulp.task('css', function(){ | ||
gulp.src('app/assets/sass/main.scss') | ||
.pipe(sass()) | ||
.pipe(autoprefixer('last 10 version')) | ||
.pipe(gulp.dest('public/css')); | ||
}); | ||
|
||
gulp.task('watch', function(){ | ||
gulp.watch('app/assets/sass/**/*.scss', ['css']); | ||
}); | ||
|
||
gulp.task('default', ['watch']); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<?php namespace Phphub\Core; | ||
|
||
interface CreatorListener | ||
{ | ||
public function creatorFailed($errors); | ||
public function creatorSucceed($model); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?php namespace Phphub\Forms; | ||
|
||
use Laracasts\Validation\FormValidator; | ||
|
||
class ReplyCreationForm extends FormValidator | ||
{ | ||
protected $rules = [ | ||
'body' => 'required|min:2', | ||
'user_id' => 'required|numeric', | ||
'topic_id' => 'required|numeric', | ||
]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?php namespace Phphub\Forms; | ||
|
||
use Laracasts\Validation\FormValidator; | ||
|
||
class TopicCreationForm extends FormValidator | ||
{ | ||
protected $rules = [ | ||
'title' => 'required|min:5', | ||
'body' => 'required|min:10', | ||
'node_id' => 'required|numeric' | ||
]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?php namespace Phphub\Forms; | ||
|
||
use Laracasts\Validation\FormValidator; | ||
|
||
class UserSignupForm extends FormValidator | ||
{ | ||
|
||
protected $rules = [ | ||
'github_id' => 'required|unique:users', | ||
'name' => 'required', | ||
'email' => 'email' | ||
]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php namespace Phphub\Github; | ||
|
||
use User; | ||
|
||
/** | ||
* This class can call the following methods on the listener object: | ||
* | ||
* userFound($user) | ||
* userIsBanned($user) | ||
* userNotFound($githubData) | ||
*/ | ||
class GithubAuthenticator | ||
{ | ||
protected $userModel; | ||
|
||
public function __construct(User $userModel, GithubUserDataReader $reader) | ||
{ | ||
$this->userModel = $userModel; | ||
$this->reader = $reader; | ||
} | ||
|
||
public function authByCode(GithubAuthenticatorListener $listener, $code) | ||
{ | ||
$githubData = $this->reader->getDataFromCode($code); | ||
$user = $this->userModel->getByGithubId($githubData['id']); | ||
|
||
if ($user) { | ||
return $this->loginUser($listener, $user, $githubData); | ||
} | ||
|
||
return $listener->userNotFound($githubData); | ||
} | ||
|
||
private function loginUser($listener, $user, $githubData) | ||
{ | ||
if ($user->is_banned) { | ||
return $listener->userIsBanned($user); | ||
} | ||
|
||
$user->fill($githubData); | ||
$user->save(); | ||
|
||
return $listener->userFound($user); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?php namespace Phphub\Github; | ||
|
||
interface GithubAuthenticatorListener | ||
{ | ||
public function userFound($user); | ||
public function userIsBanned($user); | ||
public function userNotFound($githubData); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php namespace Phphub\Github; | ||
|
||
use OAuth; | ||
|
||
class GithubUserDataReader | ||
{ | ||
public function getDataFromCode($code) | ||
{ | ||
$data = $this->readFromGithub($code); | ||
return $this->formatData($data); | ||
} | ||
|
||
private function readFromGithub($code) | ||
{ | ||
$github = OAuth::consumer('GitHub'); | ||
$oauthTokenObject = $github->requestAccessToken($code); | ||
$githubData = json_decode($github->request('user'), true); | ||
$githubData['email'] = last(json_decode($github->request('user/emails'), true)); | ||
return $githubData; | ||
} | ||
|
||
private function formatData($data) | ||
{ | ||
return [ | ||
'id' => $data['id'], | ||
'name' => $data['login'], | ||
'email' => $data['email'], | ||
'github_id' => $data['id'], | ||
'github_url' => $data['html_url'], | ||
'image_url' => $data['avatar_url'], | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php namespace Phphub\Reply; | ||
|
||
use Phphub\Forms\ReplyCreationForm; | ||
use Phphub\Core\CreatorListener; | ||
use Reply, Auth; | ||
|
||
class ReplyCreator | ||
{ | ||
protected $replyModel; | ||
protected $form; | ||
|
||
public function __construct(Reply $replyModel, ReplyCreationForm $form) | ||
{ | ||
$this->userModel = $replyModel; | ||
$this->form = $form; | ||
} | ||
|
||
public function create(CreatorListener $observer, $data) | ||
{ | ||
$data['user_id'] = Auth::user()->id; | ||
|
||
// Validation | ||
$this->form->validate($data); | ||
|
||
$reply = Reply::create($data); | ||
if ( ! $reply) | ||
{ | ||
return $observer->creatorFailed($reply->getErrors()); | ||
} | ||
|
||
return $observer->creatorSucceed($reply); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php namespace Phphub\Topic; | ||
|
||
use Phphub\Forms\TopicCreationForm; | ||
use Phphub\Core\CreatorListener; | ||
use Topic, Auth; | ||
|
||
class TopicCreator | ||
{ | ||
protected $topicModel; | ||
protected $form; | ||
|
||
public function __construct(Topic $topicModel, TopicCreationForm $form) | ||
{ | ||
$this->userModel = $topicModel; | ||
$this->form = $form; | ||
} | ||
|
||
public function create(CreatorListener $observer, $data) | ||
{ | ||
$data['user_id'] = Auth::user()->id; | ||
|
||
// Validation | ||
$this->form->validate($data); | ||
|
||
$topic = Topic::create($data); | ||
if ( ! $topic) | ||
{ | ||
return $observer->creatorFailed($topic->getErrors()); | ||
} | ||
|
||
return $observer->creatorSucceed($topic); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php namespace Phphub\Topic; | ||
|
||
use Laracasts\Presenter\Presenter; | ||
use Input, URL; | ||
|
||
class TopicPresenter extends Presenter | ||
{ | ||
public function topicFilter($filter) | ||
{ | ||
$query_append = ''; | ||
if ( !empty(Input::except('filter')) ) | ||
{ | ||
$query_append = '&'.http_build_query(Input::except('filter')); | ||
} | ||
|
||
return URL::to('topics') . '?filter=' . $filter . $query_append; | ||
} | ||
|
||
public function getTopicFilter() | ||
{ | ||
$filters = ['noreply', 'vote', 'excellent','recent']; | ||
$request_filter = Input::get('filter'); | ||
if ( in_array($request_filter, $filters) ) | ||
{ | ||
return $request_filter; | ||
} | ||
return 'recent'; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php namespace Phphub\User; | ||
|
||
use Phphub\Forms\UserSignupForm; | ||
use User; | ||
|
||
/** | ||
* This class can call the following methods on the observer object: | ||
* | ||
* userValidationError($errors) | ||
* userCreated($user) | ||
*/ | ||
class UserCreator | ||
{ | ||
protected $userModel; | ||
protected $signupForm; | ||
|
||
public function __construct(User $userModel, UserSignupForm $signupForm) | ||
{ | ||
$this->userModel = $userModel; | ||
$this->signupForm = $signupForm; | ||
} | ||
|
||
public function create(UserCreatorListener $observer, $data) | ||
{ | ||
// Validation | ||
$this->signupForm->validate($data); | ||
|
||
return $this->createValidUserRecord($observer, $data); | ||
} | ||
|
||
private function createValidUserRecord($observer, $data) | ||
{ | ||
$user = User::create($data); | ||
if ( ! $user) | ||
{ | ||
return $observer->userValidationError($user->getErrors()); | ||
} | ||
|
||
return $observer->userCreated($user); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<?php namespace Phphub\User; | ||
|
||
interface UserCreatorListener | ||
{ | ||
public function userValidationError($errors); | ||
public function userCreated($user); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php namespace Phphub\User; | ||
|
||
use Laracasts\Presenter\Presenter; | ||
|
||
class UserPresenter extends Presenter | ||
{ | ||
/** | ||
* Present a link to the user gravatar | ||
* | ||
* @param int $size | ||
* @return string | ||
*/ | ||
public function gravatar($size = 30) | ||
{ | ||
$email = md5($this->email); | ||
|
||
return "//gravatar.com/avatar/{$email}?s={$size}"; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
html, | ||
body { | ||
height: 100%; | ||
/* The html and body elements cannot have any padding or margin. */ | ||
} | ||
|
||
#wrap { | ||
min-height: 100%; | ||
height: auto; | ||
/* Negative indent footer by its height */ | ||
margin: 0 auto -60px; | ||
/* Pad bottom by footer height */ | ||
padding: 0 0 60px; | ||
} | ||
|
||
#footer { | ||
height: 60px; | ||
background-color: #f5f5f5; | ||
} | ||
.footer { | ||
padding-top: 19px; | ||
color: #777; | ||
border-top: 1px dotted #e5e5e5; | ||
} | ||
|
||
embed { | ||
display:none; | ||
} |
Empty file.
Oops, something went wrong.