Skip to content

Commit

Permalink
Merge pull request #45 from AlexStack/alex_dev
Browse files Browse the repository at this point in the history
Version 1.4
  • Loading branch information
AlexStack authored Jan 12, 2020
2 parents c33b5c3 + 46d82ae commit 8807491
Show file tree
Hide file tree
Showing 47 changed files with 1,752 additions and 483 deletions.
34 changes: 34 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"env": {
"browser": true,
"node": true,
"es6": true
},
"parser": "babel-eslint",
"extends": ["eslint:recommended", "plugin:react/recommended", "plugin:prettier/recommended"],
"globals": {
"Atomics": "readonly",
"SharedArrayBuffer": "readonly"
},
"parserOptions": {
"ecmaFeatures": {
"jsx": true
},
"ecmaVersion": 2018,
"sourceType": "module"
},
"plugins": [
"react",
"prettier"
],
"rules": {
"strict": 0,
"valid-jsdoc": 2,
"react/jsx-uses-react": 2,
"react/jsx-uses-vars": 2,
"react/react-in-jsx-scope": 2,
"react/jsx-filename-extension": [1, {
"extensions": [".js", ".jsx"]
}]
}
}
2 changes: 0 additions & 2 deletions .styleci.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
preset: laravel
risky: false
enabled:
- alpha_ordered_imports
- align_double_arrow
- align_equals
disabled:
- length_ordered_imports
- unused_use
- unalign_equals
finder:
Expand Down
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"endforelse",
"endphp",
"forelse",
"persistor",
"tabpanel"
]
}
79 changes: 43 additions & 36 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
[![image](docs/images/min/styleci.svg)](https://github.com/AlexStack/Laravel-CMS/releases)
[![Latest Stable Version](https://poser.pugx.org/alexstack/laravel-cms/v/stable)](https://github.com/AlexStack/Laravel-CMS/releases)

- Free, open source Simple Bootstrap Laravel CMS for any EXISTING Laravel 5.x or new Laravel 6 website.
- Only add a few database tables with prefix, not effect your existing database tables.
- You can easy custom the database table names, the page URL path(route) and the template(theme)
- Free, open-source Simple Bootstrap Laravel CMS for any EXISTING Laravel 5.x or new Laravel 6 website.
- Only add a few database tables with a prefix, not effect your existing database tables.
- You can easily custom the database table names, the page URL path(route) and the template(theme)
- Website is ready after install. Easy to use, simple enough but flexible.
- Basic Laravel 5.x /Laravel 6.x syntax and blade template, no need to learn a new "language"

Expand Down Expand Up @@ -38,7 +38,7 @@ php artisan laravelcms --action=uninstall

![image](docs/images/min/artisan-install-command-min.png)

## Screenshot of the output of uninstall command
## Screenshot of the output of uninstalling command

![image](docs/images/min/artisan-uninstall-command-min.png)

Expand All @@ -64,16 +64,16 @@ php artisan make:auth && php artisan migrate
composer require laravel/ui && php artisan ui vue --auth
```

## How to log into the backend /cmsadmin/ ?
## How to log into the backend /cmsadmin/?

- Amila CMS use your existing Laravel user system
- You need to login with the FIRST USER of your site (user_id = 1)
- You need to log in with the FIRST USER of your site (user_id = 1)
- You can add more admin users by change the admin_ary in config/laravel-cms.php
- If you don't have any existing user, then register a new one via http://your-domain/register

## Why the uploaded image can not display (404 error)

- You can fix it by create a storage public link
- You can fix it by creating a storage public link
- **php artisan storage:link**
- eg. The public/storage should link to ../storage/app/public, if the public/storage is a real folder, you should remove/rename it and run "php artisan storage:link" to set up the link.

Expand All @@ -82,13 +82,13 @@ composer require laravel/ui && php artisan ui vue --auth
- **homepage_route**: This is the frontend homepage. By default it is /cms-home, you can change it to / then remove the existing / route in the routes/web.php

```php
# Change homepage_route to / in config/laravel-cms.php
'homepage_route' => env('LARAVEL_CMS_HOMEPAGE_ROUTE', '/'),
# Change homepage_route to /  in config/laravel-cms.php
'homepage_route'    => env('LARAVEL_CMS_HOMEPAGE_ROUTE', '/'),

# Remove the existing / route in the routes/web.php

// Route::get('/', function () {
// return view('welcome');
//     return view('welcome');
// });
```

Expand All @@ -98,13 +98,13 @@ composer require laravel/ui && php artisan ui vue --auth
'page_route_prefix' => env('LARAVEL_CMS_PAGE_PREFIX', '/Article-'),
```

- **admin_route**: This is the backend admin page route, By default it is /cmsadmin
- **admin_route**: This is the backend admin page route, By default, it is /cmsadmin

```php
'admin_route' => env('LARAVEL_CMS_BACKEND_ROUTE', '/admin2019'),
'admin_route'       => env('LARAVEL_CMS_BACKEND_ROUTE', '/admin2019'),
```

- **After change the route, you will need to run below commands:**
- **After changing the route, you will need to run below commands:**

```php
php artisan laravelcms --action=clear
Expand All @@ -116,15 +116,15 @@ php artisan laravelcms --action=clear

```php
@if ( isset($file_data->main_image) )
<img src="{{$helper->imageUrl($file_data->main_image, '1000') }}" class="img-fluid" />
    <img src="{{$helper->imageUrl($file_data->main_image, '1000') }}" class="img-fluid" />

<img src="{{$helper->imageUrl($file_data->main_image, '500') }}" class="img-fluid" />
    <img src="{{$helper->imageUrl($file_data->main_image, '500') }}" class="img-fluid" />

<img src="{{$helper->imageUrl($file_data->main_image, 'w', '150') }}" class="img-fluid" />
    <img src="{{$helper->imageUrl($file_data->main_image, 'w', '150') }}" class="img-fluid" />

<img src="{{$helper->imageUrl($file_data->main_image, '100', '100') }}" class="img-fluid" />
    <img src="{{$helper->imageUrl($file_data->main_image, '100', '100') }}" class="img-fluid" />

<img src="{{$helper->imageUrl($file_data->main_image, 'original', 'original') }}" class="img-fluid" />
    <img src="{{$helper->imageUrl($file_data->main_image, 'original', 'original') }}" class="img-fluid" />

@endif

Expand All @@ -145,7 +145,7 @@ php artisan laravelcms --action=clear
<script src="{{ $helper->assetUrl('js/bottom.js') }}"></script>
```

- The default template file will load css and js asset with last_modify_time parameter to avoid cache from browser
- The default template file will load CSS and js asset with last_modify_time parameter to avoid cache from the browser

## How to set up a different template theme from the default?

Expand All @@ -154,12 +154,12 @@ php artisan laravelcms --action=clear
- Default value in config/laravel-cms.php

```php
'template' => [
'frontend_dir' => 'frontend',
'backend_dir' => 'backend',
'backend_language' => 'en',
'frontend_language' => 'en',
]
    'template' => [
        'frontend_dir'      => 'frontend',
        'backend_dir'       => 'backend',
        'backend_language'  => 'en',
        'frontend_language' => 'en',
    ]
```

- run **php artisan config:cache** to load new config file
Expand All @@ -173,11 +173,16 @@ php artisan laravelcms --action=clear
- 'slug_suffix' can be anything you want, empty means no suffix

```php
'slug_format' => 'from_title',
'slug_suffix' => '.html',
'slug_separate' => '-',
    'slug_format'   => 'from_title',
    'slug_suffix'   => '.html',
    'slug_separate' => '-',
```

## Use your own PHP class / How to integrate your PHP code into the CMS

- One simple option is to implement a method from your own PHP controller/class by adding it into a cms page. [Tutorial for it.](https://www.laravelcms.tech/Laravel-Advanced-Override-the-page-content-by-your-PHP-Class-method-function.html "Use your PHP class in a Laravel CMS page")
- Another option is to create a CMS plugin for your own project and use it for all pages. [A tutorial is here.](https://www.laravelcms.tech/Laravel-Create-your-own-plugin.html "How to create a Laravel CMS Plugin") You can also publish the plugin if the feature can be used by other websites.

## How to set up a brand new Laravel 6.x website & install our CMS

- It's good for a local test
Expand All @@ -186,24 +191,24 @@ php artisan laravelcms --action=clear
// Install Laravel 6.x & the CMS package
composer create-project --prefer-dist laravel/laravel cms && cd cms && composer require alexstack/laravel-cms

// Then you need to change the database settings in the .env, after that initialize CMS
// Then you need to change the database settings in the .env after that initialize CMS
cd cms & vi .env
php artisan laravelcms

// Or initialize the CMS with silent mode
php artisan laravelcms --action=initialize --locale=en --table_prefix=cms_ --silent=yes
php artisan laravelcms --action=initialize --locale=en --table_prefix=cms_  --silent=yes

// Enable auth system for Laravel 6.x
composer require laravel/ui && php artisan ui vue --auth && php artisan migrate

// Config the document root to point to the cms/public then you can access the backend
// Tips: You will need register a new user, the first user will be the admin user
// Tips: You will need to register a new user, the first user will be the admin user
```

## How to upgrade the CMS?

- Run below command in your Laravel project folder
- It will ask whether you want to copy the new view,asset and language files to your project
- It will ask whether you want to copy the new view, asset and language files to your project

```php
composer require alexstack/laravel-cms && php artisan laravelcms --action=upgrade
Expand All @@ -213,10 +218,12 @@ composer require alexstack/laravel-cms && php artisan laravelcms --action=upgrad

![image](docs/images/min/laravel-cms-upgrade-min.png)

## License
## ReactJS for backend All Pages list

- The Amila Laravel CMS is open-source software licensed under the MIT license.
- Laravel CMS use ReactJS for backend All Pages list, [the ReactJS source code can be found here](https://github.com/AlexStack/Laravel-CMS/tree/alex_dev/src/resources/reactJs)
- The compiled js file is here: /public/laravel-cms/backend/js/reactLaravelCmsBackend.js
- It can be switch to normal Laravel blade page by change the "react_js": true to false in the setting system.all_pages

```
## License

```
- The Amila Laravel CMS is open-source software licensed under the MIT license.
13 changes: 10 additions & 3 deletions src/Helpers/LaravelCmsPluginInquiry.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,20 @@ public function getFormSettings($page_id)
{
$settings = LaravelCmsInquirySetting::where('page_id', $page_id)->first();

if (! isset($settings->form_enabled) || ! $settings->form_enabled) {
if (isset($settings->form_enabled) && ! $settings->form_enabled) {
return null;
}
$default_setting_id = $settings->default_setting_id ?? $this->helper->s('inquiry.default_setting_id');
$default_setting_id = isset($settings->default_setting_id) ? $settings->default_setting_id : $this->helper->s('inquiry.default_setting_id');
if ($default_setting_id) {
$default_settings = LaravelCmsInquirySetting::where('id', $default_setting_id)->first();
if (! $default_settings) {
return null;
} elseif (! $settings) {
// in case there is no record in the inquires table
$settings = $default_settings;
}
}
// dd($settings);
$new_settings = clone $settings;
foreach ($settings->toArray() as $key => $value) {
if (null === $new_settings[$key]) {
Expand Down Expand Up @@ -290,7 +297,7 @@ public function show($id)
'page' => $setting->page_id,
'switch_nav_tab' => 'inquiry',
'show_advanced_settings'=> 'yes',
]);
]);
}
}
}
34 changes: 30 additions & 4 deletions src/Http/Controllers/LaravelCmsPageAdminController.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,36 @@ public function checkUser()
public function index()
{
$this->checkUser();

$data = $this->repo->index();

return view($this->helper->bladePath('page-list', 'b'), $data);
if ('json' == request()->response_type) {
$data = $this->repo->index();

unset($data['helper']);
unset($data['plugins']);

foreach ($data['all_pages'] as $key => $page) {
$data['all_pages'][$key]->url = $this->helper->url($page);
//remove some unused ReactJS api data for speed, it can save around 24% bandwidth transfer
unset($data['all_pages'][$key]->redirect_url);
unset($data['all_pages'][$key]->slug);
unset($data['all_pages'][$key]->status);
unset($data['all_pages'][$key]->parent_id);
unset($data['all_pages'][$key]->sort_value);
// $data['all_pages'][$key]->menu_enabled = (int) $data['all_pages'][$key]->menu_enabled;
}

// JSON_UNESCAPED_UNICODE can save around another 20% bandwidth transfer if it is Chinese site
$rs = response()->json($data['all_pages'])->setEncodingOptions(JSON_UNESCAPED_UNICODE);

return $rs;
} elseif (0 === $this->helper->s('system.all_pages.react_js')) {
$data = $this->repo->index();

return view($this->helper->bladePath('page-list', 'b'), $data);
} else {
$data['helper'] = $this->helper;

return view($this->helper->bladePath('page-list-react-js', 'b'), $data);
}
}

public function create()
Expand Down
5 changes: 5 additions & 0 deletions src/Models/LaravelCmsPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,11 @@ public function children()
return $this->hasMany(\AlexStack\LaravelCms\Models\LaravelCmsPage::class, 'parent_id', 'id')->with('children')->orderBy('sort_value', 'desc')->orderBy('id', 'desc');
}

public function children4list()
{
return $this->hasMany(\AlexStack\LaravelCms\Models\LaravelCmsPage::class, 'parent_id', 'id')->with('children4list:title,menu_title,id,parent_id,slug,redirect_url,menu_enabled')->orderBy('sort_value', 'desc')->orderBy('id', 'desc');
}

public function menus()
{
return $this->hasMany(\AlexStack\LaravelCms\Models\LaravelCmsPage::class, 'parent_id', 'id')->where('menu_enabled', 1)->with('menus:title,menu_title,id,parent_id,slug,redirect_url,menu_enabled')->orderBy('sort_value', 'desc')->orderBy('id', 'desc');
Expand Down
10 changes: 5 additions & 5 deletions src/Repositories/LaravelCmsPageAdminRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function index()
{
//$data['all_pages'] = LaravelCmsPage::orderBy('id','desc')->get();

$all_page_ary = $this->flattenArray($this->parentPages('all')->toArray());
$all_page_ary = $this->flattenArray($this->parentPages('all')->toArray(), 'children4list');

$data['all_pages'] = json_decode(json_encode($all_page_ary), false);

Expand Down Expand Up @@ -287,17 +287,17 @@ public function flattenArray($elements, $name = 'children', $depth = 0)

public function parentPages($action = 'get_select_options')
{
$data['children'] = LaravelCmsPage::with('children:title,menu_title,id,parent_id,menu_enabled,slug,redirect_url,sort_value,status')
$data['children'] = LaravelCmsPage::with('children4list:title,menu_title,id,parent_id,menu_enabled,slug,redirect_url,sort_value,status')
->whereNull('parent_id')
->orderBy('sort_value', 'desc')
->orderBy('id', 'desc')
->get();
->get(['title', 'menu_title', 'id', 'parent_id', 'menu_enabled', 'slug', 'redirect_url', 'sort_value', 'status']);

//var_dump($data['children']->toArray());

if ('get_select_options' == $action) {
$options = [null => 'Top Level'];
$flat_ary = $this->flattenArray($data['children']->toArray());
$options = [null => $this->helper->t('top_level')];
$flat_ary = $this->flattenArray($data['children']->toArray(), 'children4list');

//var_dump($flat_ary);

Expand Down
Loading

0 comments on commit 8807491

Please sign in to comment.