diff --git a/app/Http/Controllers/Laralum/APIController.php b/app/Http/Controllers/Laralum/APIController.php new file mode 100644 index 0000000..8a436c3 --- /dev/null +++ b/app/Http/Controllers/Laralum/APIController.php @@ -0,0 +1,83 @@ + trans('api.api_disabled')]; + } + + $columns = Schema::getColumnListing($table); + + if($accessor){ + + if($accessor == 'latest') { + $rows = DB::table($table)->orderBy('id', 'desc')->limit(1)->get(); + } elseif($accessor == 'latests'){ + if(!$data){ + $data = 5; + } + $rows = DB::table($table)->orderBy('id', 'desc')->limit($data)->get(); + } else { + if(!Schema::hasColumn($table, $accessor)){ + abort(404); + } + $rows = DB::table($table)->where($accessor, $data)->get(); + } + + } else { + $rows = DB::table($table)->get(); + } + + $final_columns = []; + + foreach($columns as $column){ + if(in_array($column, $api[$table]['show'])){ + array_push($final_columns, $column); + } + } + + $final_rows = []; + foreach($rows as $row){ + $final_row = []; + foreach($final_columns as $column){ + $final_row[$column] = $row->$column; + } + array_push($final_rows, $final_row); + } + + return $final_rows; + } +} diff --git a/app/Http/Controllers/Laralum/Data/API.php b/app/Http/Controllers/Laralum/Data/API.php new file mode 100644 index 0000000..eb84439 --- /dev/null +++ b/app/Http/Controllers/Laralum/Data/API.php @@ -0,0 +1,58 @@ + [ + 'show' => [ + 'id', 'name', 'email', 'active', 'banned', 'country_code', 'created_at', 'updated_at' + ], + 'enabled' => true, + ], + 'users_settings' => [ + 'show' => [ + 'default_role', 'location', 'register_enabled', 'default_active', 'welcome_email' + ], + 'enabled' => true, + ], + 'roles' => [ + 'show' => [ + 'id', 'name', 'color', 'assignable', 'allow_editing', 'created_at', 'updated_at' + ], + 'enabled' => true, + ], + 'permissions' => [ + 'show' => [ + 'id', 'slug', 'color', 'assignable', 'created_at', 'updated_at' + ], + 'enabled' => true, + ], + 'blogs' => [ + 'show' => [ + 'id', 'name', 'views_location', 'user_id', 'created_at', 'updated_at' + ], + 'enabled' => true, + ], + 'posts' => [ + 'show' => [ + 'id', 'image', 'title', 'description', 'body', 'user_id', 'blog_id', 'edited_by', 'created_at', 'updated_at' + ], + 'enabled' => true, + ], + 'post_comments' => [ + 'show' => [ + 'id', 'user_id', 'post_id', 'name', 'email', 'content', 'created_at', 'updated_at' + ], + 'enabled' => true, + ], + 'documents' => [ + 'show' => [ + 'id', 'user_id', 'name', 'slug', 'disabled', 'download_timer', 'downloads', 'created_at', 'updated_at' + ], + 'enabled' => true, + ], + 'settings' => [ + 'show' => [ + 'laralum_version', 'website_title', 'logo' + ], + 'enabled' => true, + ], +]; diff --git a/app/Http/Controllers/Laralum/Laralum.php b/app/Http/Controllers/Laralum/Laralum.php index 4b2bf23..e373553 100644 --- a/app/Http/Controllers/Laralum/Laralum.php +++ b/app/Http/Controllers/Laralum/Laralum.php @@ -1053,5 +1053,13 @@ public static function dataPath() return app_path() . '/Http/Controllers/Laralum/Data'; } + public static function apiData() + { + require('Data/API.php'); + if($api){ + return $api; + } + } + } diff --git a/app/User.php b/app/User.php index 6fff3b1..6b0a421 100644 --- a/app/User.php +++ b/app/User.php @@ -28,12 +28,10 @@ class User extends Authenticatable * @var array */ protected $hidden = [ - 'password', 'remember_token', + 'password', 'remember_token', 'activation_key', ]; /** - * setNameAttribute - * * Mutator to capitalize the name * * @param mixed $value @@ -43,8 +41,6 @@ public function setNameAttribute($value){ } /** - * roles - * * Returns all the roles from the user * */ @@ -54,8 +50,6 @@ public function roles() } /** - * isAdmin - * * Returns true if the user has access to laralum * */ @@ -65,8 +59,6 @@ public function isAdmin() } /** - * hasPermission - * * Returns true if the user has the permission slug * * @param string $slug @@ -84,8 +76,6 @@ public function hasPermission($slug) } /** - * hasRole - * * Returns true if the user has the role * * @param string $name @@ -101,8 +91,6 @@ public function hasRole($name) } /** - * blogs - * * Returns all the blogs owned by the user * */ @@ -112,8 +100,6 @@ public function blogs() } /** - * has_blog - * * Returns true if the user has blog access * * @param number $id @@ -131,8 +117,6 @@ public function has_blog($id) } /** - * owns_blog - * * Returns true if the user owns the blog * * @param number $id @@ -147,8 +131,6 @@ public function owns_blog($id) } /** - * posts - * * Returns all the posts from the user * */ @@ -158,8 +140,6 @@ public function posts() } /** - * owns_post - * * Returns true if the users owns the post * * @param number $id @@ -174,8 +154,6 @@ public function owns_post($id) } /** - * avatar - * * Returns the user avatar from Gavatar * * @param number $size @@ -189,8 +167,6 @@ public function avatar($size = null){ } /** - * documents - * * Returns all the documents from the user * */ @@ -200,8 +176,6 @@ public function documents() } /** - * sendWelcomeEmail - * * Sends the welcome email notification to the user * */ @@ -211,8 +185,6 @@ public function sendWelcomeEmail() } /** - * sendActivationEmail - * * Sends the activation email notification to the user * */ diff --git a/database/migrations/2016_06_11_160205_create_settings.php b/database/migrations/2016_06_11_160205_create_settings.php index a1dda88..2072b76 100644 --- a/database/migrations/2016_06_11_160205_create_settings.php +++ b/database/migrations/2016_06_11_160205_create_settings.php @@ -28,7 +28,7 @@ public function up() }); $settings = new Settings; - $settings->laralum_version = "2.0.6"; + $settings->laralum_version = "2.1"; $settings->website_title = env('APP_NAME', 'My Application'); $settings->logo = ''; //Default logo will load $settings->button_color = "blue"; diff --git a/resources/lang/ca/api.php b/resources/lang/ca/api.php new file mode 100644 index 0000000..2b827db --- /dev/null +++ b/resources/lang/ca/api.php @@ -0,0 +1,16 @@ + "Aquesta API està desactivada", + +]; diff --git a/resources/lang/ca/laralum.php b/resources/lang/ca/laralum.php index 0e0b055..0542a02 100644 --- a/resources/lang/ca/laralum.php +++ b/resources/lang/ca/laralum.php @@ -298,9 +298,9 @@ 'security_description_title' => "Què és aquesta pàgina?", 'security_description' => "Aquesta pàgina és una pàgina de confirmació per evitar - coses que és possible que no vulguis fer, o simplement - per fer-li saber que aquesta acció no es pot desfer i - és per això que requereix quelcom més que un sol clic + coses que és possible que no vulguis fer, o simplement + per fer-li saber que aquesta acció no es pot desfer i + és per això que requereix quelcom més que un sol clic per a ser executada.", /* @@ -543,4 +543,14 @@ 'activation_not_valid' => "El codi d'activació no és vàlid", 'activation_account' => "Activació de compte", 'activation_key' => "Clau d'activació", + + /* + |-------------------------------------------------------------------------- + | VERSION 2.1.X + |-------------------------------------------------------------------------- + */ + 'laralum_API' => "API de Laralum", + 'API_subtitle' => "API pública de Laralum (Tindrà codis d'API aviat)", + 'API_url' => "URL de l'API", + 'API_show' => "Columnes que es mostraran", ]; diff --git a/resources/lang/en/api.php b/resources/lang/en/api.php new file mode 100644 index 0000000..f9d6f68 --- /dev/null +++ b/resources/lang/en/api.php @@ -0,0 +1,16 @@ + "The current API is disabled", + +]; diff --git a/resources/lang/en/laralum.php b/resources/lang/en/laralum.php index 736bf40..1579933 100644 --- a/resources/lang/en/laralum.php +++ b/resources/lang/en/laralum.php @@ -543,4 +543,14 @@ 'activation_not_valid' => "The activation code is not valid", 'activation_account' => "Account Activation", 'activation_key' => "Activation Key", + + /* + |-------------------------------------------------------------------------- + | VERSION 2.1.X + |-------------------------------------------------------------------------- + */ + 'laralum_API' => "Laralum API", + 'API_subtitle' => "Laralum Public API (Will soon have API keys)", + 'API_url' => "API URL", + 'API_show' => "Columns that will be shown", ]; diff --git a/resources/lang/es/api.php b/resources/lang/es/api.php new file mode 100644 index 0000000..00f6326 --- /dev/null +++ b/resources/lang/es/api.php @@ -0,0 +1,16 @@ + "Esta API está desactivada", + +]; diff --git a/resources/lang/es/laralum.php b/resources/lang/es/laralum.php index 6886646..dbba604 100644 --- a/resources/lang/es/laralum.php +++ b/resources/lang/es/laralum.php @@ -300,7 +300,7 @@ 'security_description' => "Esta página es una página de confirmación para evitar cosas que no quieras hacer, o simplemente para hacerle saber que esta acción no se puede deshacer y es por ello - que requiere algo mas que un solo click para ser + que requiere algo mas que un solo click para ser ejecutada.", /* @@ -543,4 +543,14 @@ 'activation_not_valid' => "El código de activación no és válido", 'activation_account' => "Activación de cuenta", 'activation_key' => "Clave de activación", + + /* + |-------------------------------------------------------------------------- + | VERSION 2.1.X + |-------------------------------------------------------------------------- + */ + 'laralum_API' => "API de Laralum", + 'API_subtitle' => "API pública de Laralum (Tendrá códigos de API en breves)", + 'API_url' => "URL de la API", + 'API_show' => "Columnas que se mostraran", ]; diff --git a/resources/views/laralum/API/index.blade.php b/resources/views/laralum/API/index.blade.php new file mode 100644 index 0000000..e9ba29f --- /dev/null +++ b/resources/views/laralum/API/index.blade.php @@ -0,0 +1,78 @@ +@extends('layouts.admin.panel') +@section('breadcrumb') + +@endsection +@section('title', trans('laralum.laralum_API')) +@section('icon', "exchange") +@section('subtitle', trans('laralum.API_subtitle')) +@section('content') +
+
+
+ + + + + + + + + + @foreach($api as $a => $data) + + + + + + + + + + + + + @endforeach + +
{{ trans('laralum.API_url') }}{{ trans('laralum.API_show') }}
+ @if($data['enabled']) + + @else + + @endif + /{{ $a }}/{accessor?}/{data?} + + @foreach($data['show'] as $d) +
{{ $d }}
+ @endforeach +
+ @if($data['enabled']) + + @else + + @endif + /{{ $a }}/latest + + @foreach($data['show'] as $d) +
{{ $d }}
+ @endforeach +
+ @if($data['enabled']) + + @else + + @endif + /{{ $a }}/latests/{number?} + + @foreach($data['show'] as $d) +
{{ $d }}
+ @endforeach +
+
+
+
+
+@endsection diff --git a/resources/views/layouts/admin/panel.blade.php b/resources/views/layouts/admin/panel.blade.php index 03d278b..5f47187 100644 --- a/resources/views/layouts/admin/panel.blade.php +++ b/resources/views/layouts/admin/panel.blade.php @@ -132,6 +132,9 @@ +
{{ trans('laralum.settings') }}
diff --git a/routes/api.php b/routes/api.php index 6b907f3..221a23d 100644 --- a/routes/api.php +++ b/routes/api.php @@ -13,6 +13,6 @@ | */ -Route::get('/user', function (Request $request) { - return $request->user(); -})->middleware('auth:api'); +Route::group(['namespace' => 'Laralum', 'as' => 'API::'], function () { + Route::get('/{table}/{accessor?}/{data?}', 'APIController@show')->name('show'); +}); diff --git a/routes/web.php b/routes/web.php index 24b030f..b8b19e2 100644 --- a/routes/web.php +++ b/routes/web.php @@ -90,14 +90,14 @@ }); -Route::group(['middleware' => ['laralum.base'], 'as' => 'Laralum::'], function () { +Route::group(['middleware' => ['laralum.base'], 'namespace' => 'Laralum', 'as' => 'Laralum::'], function () { # Public document downloads - Route::get('/document/{slug}', 'Laralum\DownloadsController@downloader')->name('document_downloader'); - Route::post('/document/{slug}', 'Laralum\DownloadsController@download'); + Route::get('/document/{slug}', 'DownloadsController@downloader')->name('document_downloader'); + Route::post('/document/{slug}', 'DownloadsController@download'); # Public language changer - Route::get('/locale/{locale}', 'Laralum\LocaleController@set')->name('locale'); + Route::get('/locale/{locale}', 'LocaleController@set')->name('locale'); }); @@ -222,6 +222,9 @@ Route::get('/CRUD/{table}/{id}/delete', 'SecurityController@confirm')->name('CRUD_delete'); Route::post('/CRUD/{table}/{id}/delete', 'CRUDController@deleteRow'); + # API + Route::get('/API', 'APIController@index')->name('API'); + # File Manager Route::get('/files', 'FilesController@files')->name('files');