-
Notifications
You must be signed in to change notification settings - Fork 21
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
1 parent
668e310
commit 817d183
Showing
458 changed files
with
284,027 additions
and
1,422 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,20 @@ | ||
<?php | ||
|
||
namespace App; | ||
|
||
use Illuminate\Database\Eloquent\Model; | ||
|
||
class Blog extends Model | ||
{ | ||
// | ||
|
||
public function user() | ||
{ | ||
return $this->belongsTo('App\User'); | ||
} | ||
|
||
public function posts() | ||
{ | ||
return $this->hasMany('App\Post'); | ||
} | ||
} |
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,175 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers\Admin; | ||
|
||
use Illuminate\Http\Request; | ||
|
||
use App\Http\Requests; | ||
use App\Http\Controllers\Controller; | ||
use App\Blog; | ||
use Auth; | ||
|
||
class BlogsController extends Controller | ||
{ | ||
|
||
public function __construct() | ||
{ | ||
# Check permissions | ||
if(!Auth::user()->has('admin.blogs.access')) { | ||
return redirect('/admin')->with('warning', "You are not allowed to perform this action")->send(); | ||
} | ||
} | ||
|
||
public function index() { | ||
# Get all blogs | ||
$blogs = Blog::all(); | ||
|
||
# Return the view | ||
return view('admin/blogs/index', ['blogs' => $blogs]); | ||
} | ||
|
||
public function create() | ||
{ | ||
# Check permissions | ||
if(!Auth::user()->has('admin.blogs.create')) { | ||
return redirect('/admin')->with('warning', "You are not allowed to perform this action")->send(); | ||
} | ||
|
||
# Get all the data | ||
$data_index = 'blogs'; | ||
require('Data/Create/Get.php'); | ||
|
||
# Return the view | ||
return view('admin/blogs/create', [ | ||
'fields' => $fields, | ||
'confirmed' => $confirmed, | ||
'encrypted' => $encrypted, | ||
'hashed' => $hashed, | ||
'masked' => $masked, | ||
'table' => $table, | ||
'code' => $code, | ||
'wysiwyg' => $wysiwyg, | ||
]); | ||
} | ||
|
||
public function store(Request $request) | ||
{ | ||
# Check permissions | ||
if(!Auth::user()->has('admin.blogs.create')) { | ||
return redirect('/admin')->with('warning', "You are not allowed to perform this action")->send(); | ||
} | ||
|
||
# create the user | ||
$row = new Blog; | ||
|
||
# Save the data | ||
$data_index = 'blogs'; | ||
require('Data/Create/Save.php'); | ||
|
||
$row->user_id = Auth::user()->id; | ||
$row->save(); | ||
|
||
# Return the admin to the blogs page with a success message | ||
return redirect('/admin/blogs')->with('success', "The blog has been created"); | ||
} | ||
|
||
public function posts($id) | ||
{ | ||
# Check permissions | ||
if(!Auth::user()->has('admin.blogs.posts')) { | ||
return redirect('/admin')->with('warning', "You are not allowed to perform this action")->send(); | ||
} | ||
|
||
# Find the blog | ||
$blog = Blog::findOrFail($id); | ||
|
||
# Get the blog posts | ||
$posts = $blog->posts; | ||
|
||
# Return the view | ||
return view('admin/blogs/posts', ['posts' => $posts, 'blog' => $blog]); | ||
} | ||
|
||
public function edit($id) | ||
{ | ||
# Check permissions | ||
if(!Auth::user()->has('admin.blogs.edit')) { | ||
return redirect('/admin')->with('warning', "You are not allowed to perform this action")->send(); | ||
} | ||
|
||
# Find the blog | ||
$row = Blog::findOrFail($id); | ||
|
||
# Get all the data | ||
$data_index = 'blogs'; | ||
require('Data/Edit/Get.php'); | ||
|
||
# Return the edit form | ||
return view('admin/blogs/edit', [ | ||
'row' => $row, | ||
'fields' => $fields, | ||
'confirmed' => $confirmed, | ||
'empty' => $empty, | ||
'encrypted' => $encrypted, | ||
'hashed' => $hashed, | ||
'masked' => $masked, | ||
'table' => $table, | ||
'code' => $code, | ||
'wysiwyg' => $wysiwyg, | ||
]); | ||
} | ||
|
||
public function update($id, Request $request) | ||
{ | ||
# Check permissions | ||
if(!Auth::user()->has('admin.blogs.edit')) { | ||
return redirect('/admin')->with('warning', "You are not allowed to perform this action")->send(); | ||
} | ||
|
||
# Find the blog | ||
$row = Blog::findOrFail($id); | ||
|
||
if($row->user_id == Auth::user()->id or Auth::user()->su) { | ||
# The user who's trying to modify the post is able to do such because it's the owner or it's su | ||
|
||
# Save the data | ||
$data_index = 'blogs'; | ||
require('Data/Edit/Save.php'); | ||
|
||
# Return the admin to the blogs page with a success message | ||
return redirect('/admin/blogs')->with('success', "The blog has been edited"); | ||
} else { | ||
#The user is not allowed to delete the blog | ||
return redirect('admin/blogs')->with('warning', "You are not allowed to perform this action"); | ||
} | ||
} | ||
|
||
public function destroy($id) | ||
{ | ||
# Check permissions | ||
if(!Auth::user()->has('admin.blogs.delete')) { | ||
return redirect('/admin')->with('warning', "You are not allowed to perform this action")->send(); | ||
} | ||
|
||
# Find The Blog | ||
$blog = Blog::findOrFail($id); | ||
|
||
if($blog->user_id == Auth::user()->id or Auth::user()->su) { | ||
# The user who's trying to delete the post is able to do such because it's the owner or it's su | ||
|
||
# Delete posts | ||
foreach($blog->posts as $post) { | ||
$post->delete(); | ||
} | ||
|
||
# Delete blog | ||
$blog->delete(); | ||
|
||
# Return a redirect | ||
return redirect('admin/blogs')->with('success', "The blog has been deleted"); | ||
} else { | ||
#The user is not allowed to delete the blog | ||
return redirect('admin/blogs')->with('warning', "You are not allowed to perform this action"); | ||
} | ||
} | ||
} |
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,54 @@ | ||
<?php | ||
|
||
/* | ||
+---------------------------------------------------------------------------+ | ||
| Laralum Data Fetcher | | ||
+---------------------------------------------------------------------------+ | ||
| | | ||
| * Requires: | | ||
| | | ||
| $row - The row information | | ||
| | | ||
| * Available variables: | | ||
| | | ||
| $data - The table settings | | ||
| $table - The table name +-------------+ | ||
| $hidden: Columns that will not be displayed in the edit form, and they won't be updated +----------------------------+ | ||
| $empty: Columns that will not have their current value when editing them (eg: password field is hidden in the model) | | ||
| $confirmed: fields that will need to be confirmed twice +-+ | ||
| $encrypted: Fields that will be encrypted using: Crypt::encrypt(); when they are saved and decrypted when editing them +---------------------------+ | ||
| $hashed: Fields that will be hashed when they are saved in the database, will be empty on editing, and if saved as empty they will not be modified | | ||
| $masked: Fields that will be displayed as a type='password', so their content when beeing modified won't be visible +------------------------------+ | ||
| $default_random: Fields that if no data is set, they will be randomly generated (10 characters) +-------------------+ | ||
| $su_hidden: Columns that will be added to the hidden array if the user is su +------------------+ | ||
| $columns: the row columns +--+ | ||
| $fields: get the available fields | | ||
| | | ||
+---------------------------------------------------------------------------+ | ||
| | | ||
| This file creates the variables nessesary to make | | ||
| the dynamic field edition avialable to all the controllers | | ||
| regardless of it's differences. | | ||
| | | ||
+---------------------------------------------------------------------------+ | ||
*/ | ||
|
||
include('SimpleGet.php'); | ||
|
||
# Get the row table columns | ||
$columns = Schema::getColumnListing($table); | ||
|
||
# Gets the fields available to edit / update | ||
$final_columns = []; | ||
foreach($columns as $column) { | ||
$add = true; | ||
foreach($hidden as $hide) { | ||
if($column == $hide) { | ||
$add = false; | ||
} | ||
} | ||
if($add) { | ||
array_push($final_columns, $column); | ||
} | ||
} | ||
$fields = $final_columns; |
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,86 @@ | ||
<?php | ||
|
||
/* | ||
+---------------------------------------------------------------------------+ | ||
| Laralum Data Saver | | ||
+---------------------------------------------------------------------------+ | ||
| | | ||
| * Requires: | | ||
| | | ||
| $row - The row information | | ||
| $request - The form requrest information | | ||
| | | ||
+---------------------------------------------------------------------------+ | ||
| | | ||
| This files saves the new information to the database | | | ||
| | | ||
+---------------------------------------------------------------------------+ | ||
*/ | ||
|
||
include('Get.php'); | ||
|
||
# Validate The Request | ||
$this->validate($request, $validator); | ||
|
||
# Update the row | ||
foreach($fields as $field) { | ||
|
||
$save = true; | ||
|
||
# Check the field type | ||
$type = Schema::getColumnType($table, $field); | ||
|
||
# Get the value | ||
$value = $request->input($field); | ||
|
||
if($type == 'string' or $type == 'integer') { | ||
|
||
# Check if it's a default_random field | ||
foreach($default_random as $random) { | ||
if($random == $field) { | ||
if(!$value) { | ||
$value = str_random(10); | ||
} | ||
} | ||
} | ||
|
||
# Check if it's a hashed field | ||
foreach($hashed as $hash) { | ||
if($hash == $field) { | ||
if($value) { | ||
$value = Hash::make($value); | ||
} else { | ||
$save = false; | ||
} | ||
} | ||
} | ||
|
||
# Check if it's an encrypted field | ||
foreach($encrypted as $encrypt) { | ||
if($encrypt == $field) { | ||
$value = Crypt::encrypt($value); | ||
} | ||
} | ||
|
||
# Save it | ||
if($save) { | ||
$row->$field = $value; | ||
} | ||
|
||
} elseif($type == 'boolean') { | ||
|
||
# Save it | ||
if($value) { | ||
$row->$field = true; | ||
} else { | ||
$row->$field = false; | ||
} | ||
|
||
} else { | ||
# Save it | ||
$row->$field = $value; | ||
} | ||
} | ||
|
||
# Save the row | ||
$row->save(); |
Oops, something went wrong.