Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bind Theme in service provider #96

Merged
merged 18 commits into from
Dec 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 8 additions & 27 deletions .github/workflows/github-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,57 +20,38 @@ jobs:

test:
runs-on: ubuntu-latest
env:
DB_HOST: localhost
DB_CONNECTION: mysql
DB_DATABASE: horizontlaravel
DB_USERNAME: root
DB_PASSWORD: password
LOG_CHANNEL: stderr
services:
mysql:
image: mysql:latest
env:
MYSQL_ALLOW_EMPTY_PASSWORD: false
MYSQL_ROOT_PASSWORD: password
MYSQL_DATABASE: horizontlaravel
ports:
- 3306/tcp
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3
steps:
- uses: actions/checkout@v3
- uses: php-actions/composer@v6
with:
args: --ignore-platform-reqs
- name: Set up before tests
run: |
php artisan migrate --no-interaction --force
php artisan db:seed --no-interaction --force
- name: Force installed variable
run: export INSTALLED=YES
- name: Run unit tests
run: INSTALLED=YES XDEBUG_MODE=coverage vendor/bin/phpunit --testsuite Unit,Integration --coverage-clover reports/coverage.xml
- name: After test steps
run: XDEBUG_MODE=coverage vendor/bin/phpunit --testsuite Unit,Integration --coverage-clover reports/coverage.xml
# - name: Upload coverage
# run: |
# if [ -f "reports/coverage.xml" ]; then vendor/bin/codacycoverage clover reports/coverage.xml; fi
- name: Show versions
run: |
if [ -f "reports/coverage.xml" ]; then vendor/bin/codacycoverage clover reports/coverage.xml; fi
php artisan --version
php artisan hcms:version
strategy:
fail-fast: false
matrix:
php-versions: ['8.1', '8.2']
php-versions: ['8.1', '8.2', '8.3']

docker_image:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Log in to Docker Hub
uses: docker/login-action@v2
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Build and push Docker image
uses: docker/build-push-action@v4
uses: docker/build-push-action@v6
with:
context: .
push: true
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<h1 align="center">HorizontCMS</h1>

[![Laravel 9](https://img.shields.io/badge/Laravel-9-orange.svg)](http://laravel.com)
[![Laravel 10](https://img.shields.io/badge/Laravel-10-orange.svg)](http://laravel.com)
[![Bootstrap 5.3](https://img.shields.io/badge/Bootstrap-5.3-563d7c.svg)](http://getbootstrap.com)
[![VueJs 2.6](https://img.shields.io/badge/VueJs-2.6-green.svg)](http://vuejs.org)
[![Codacy Badge](https://api.codacy.com/project/badge/Grade/d645b6be9b6a42a8b6189cc32ea8f546)](https://www.codacy.com/app/ttimot24/HorizontCMS?utm_source=github.com&amp;utm_medium=referral&amp;utm_content=ttimot24/HorizontCMS&amp;utm_campaign=Badge_Grade)
Expand All @@ -12,7 +12,7 @@
This lightweight CMS platform is not just about functionality—it's about empowerment. Whether you're a seasoned developer or a novice user, HorizontCMS provides intuitive tools and a seamless interface to extend and build your online presence with ease. With just one click, you can unlock endless possibilities and unleash your creativity.


### Latest version: [v1.1.0](https://github.com/ttimot24/HorizontCMS/releases/tag/v1.1.0)
### Latest version: [v1.2.0](https://github.com/ttimot24/HorizontCMS/releases/tag/v1.2.0)

### Try out

Expand Down
7 changes: 2 additions & 5 deletions app/Controllers/WebsiteController.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,9 @@ class WebsiteController extends Controller

private $theme;

public function __construct(Request $request){

public function __construct(Request $request, \App\Libs\Theme $theme){
$this->request = $request;

$this->theme = new \App\Libs\Theme(\Settings::get('theme'));

$this->theme = $theme;
}

/**
Expand Down
4 changes: 2 additions & 2 deletions app/HorizontCMS.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ public function __construct($basePath = null)

public static function isInstalled()
{
return file_exists(base_path(".env")) || env("INSTALLED", false);
return file_exists(base_path(".env")) || config('horizontcms.installed', false);
}

public function publicPath()
public function publicPath($path = '')
{
return $this->basePath . DIRECTORY_SEPARATOR;
}
Expand Down
9 changes: 4 additions & 5 deletions app/Http/Middleware/AdminMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,12 @@ class AdminMiddleware {
* @return mixed
*/
public function handle($request, Closure $next){

if(!$request->user()->isAdmin() || !$request->user()->isActive()){

\Auth::logout();
return redirect()->back();
if($request->user()->isAdmin() && $request->user()->isActive()){
return $next($request);
}

return $next($request);
\Auth::logout();
return redirect()->back();
}
}
4 changes: 4 additions & 0 deletions app/Http/RouteResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ public function __construct(){
$this->resetNamespace();
}

public function getNamespace(){
return $this->namespace;
}

public function resetNamespace(){
$this->namespace = $this->defaultNamespace;
}
Expand Down
2 changes: 1 addition & 1 deletion app/Model/Blogpost.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class Blogpost extends Model
* @var array
*/
protected $fillable = [
'title', 'summary', 'text', 'category_id', 'comments_enabled', 'active',
'title','slug', 'summary', 'text', 'category_id', 'comments_enabled', 'active',
];

public static $rules = [
Expand Down
2 changes: 1 addition & 1 deletion app/Model/Page.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class Page extends Model {
* @var array
*/
protected $fillable = [
'name', 'url' ,'visibility', 'parent_id', 'language' , 'queue', 'page', 'active',
'name','slug', 'url' ,'visibility', 'parent_id', 'language' , 'queue', 'page', 'active',
];

public static $rules = [
Expand Down
3 changes: 2 additions & 1 deletion app/Model/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,12 @@ public static function has($setting){

public static function getAll(){

$array = [];

foreach(self::all() as $each){
$array[$each->setting] = $each->value;
}


return $array;
}

Expand Down
10 changes: 3 additions & 7 deletions app/Model/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public function blogposts(){
*/
public function role(){

if(\App\Model\UserRole::find($this->role_id)==NULL){
if(\App\Model\UserRole::find($this->role_id)==null){
$this->role_id = 1;
}

Expand All @@ -98,13 +98,9 @@ public function comments(){
}


public function hasPermission($permission){
public function hasPermission(string $permission): bool {

if(!isset($this->role->rights) || $this->role->rights==NULL || $this->role->rights==""){
return false;
}

return in_array($permission, $this->role->rights);
return empty($this->role->rights)? false : in_array($permission, $this->role->rights);
}

/**
Expand Down
3 changes: 1 addition & 2 deletions app/Model/UserRole.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,14 @@ class UserRole extends Model {
* @var array
*/
protected $fillable = [
'name',
'name', 'rights'
];


public function users(){
return $this->hasMany(\App\Model\User::class,'role_id','id');
}


/**
* Accessor for rights
*/
Expand Down
2 changes: 0 additions & 2 deletions app/Providers/AppServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ public function boot()
dd($queries);
});
}

$this->app->register(\Laravel\Dusk\DuskServiceProvider::class);
}


Expand Down
18 changes: 13 additions & 5 deletions app/Providers/ThemeServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,16 @@ class ThemeServiceProvider extends ServiceProvider
*/
public function boot()
{
if (!app()->runningInConsole() && app()->isInstalled()) {
if (app()->isInstalled()) {

$theme = new Theme(\App\Model\Settings::get('theme'));

// For website
if (!\Request::is(\Config::get('horizontcms.backend_prefix') . "/*")) {
$this->loadJsonTranslationsFrom(base_path($theme->getPath() . "resources/lang"));
}
$this->app->singleton(Theme::class, function ($app) use($theme) {
return $theme;
});


$this->registerTranslations($theme);

$this->registerThemeViews($theme);

Expand All @@ -31,6 +33,12 @@ public function boot()
}
}

protected function registerTranslations(Theme $theme){
if (!\Request::is(\Config::get('horizontcms.backend_prefix') . "/*")) {
$this->loadJsonTranslationsFrom(base_path($theme->getPath() . "resources/lang"));
}
}

protected function registerThemeViews(Theme $theme){
\View::addNamespace('theme', [
$theme->getPath() . "app" . DIRECTORY_SEPARATOR . "View",
Expand Down
17 changes: 4 additions & 13 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
{
"name": "ttimot24/horizont-cms",
"version": "1.1.0",
"version": "1.2.0",
"description": "The CMS that fits exactly to your needs",
"keywords": ["hcms", "laravel","vuejs","bootstrap","website"],
"license": "MIT",
"type": "project",
"require": {
"php": "^8.0",
"laravel/framework": "9.*",
"php": "^8.1",
"laravel/framework": "^10.0",
"lavary/laravel-menu": "1.8.*",
"composer/semver": "*",
"visualappeal/php-auto-update" : "1.0.2",
"madnest/madzipper" : "*",
"jackiedo/log-reader": "*",
"intervention/image": "*",
Expand All @@ -22,9 +21,8 @@
"nunomaduro/collision": "^6.1"
},
"require-dev": {
"phpunit/phpunit" : "^9.0",
"phpunit/phpunit" : "^10.0",
"mockery/mockery": "1.4.*",
"laravel/dusk": "6.*",
"filp/whoops" : "~2.0",
"bamarni/composer-bin-plugin": "^1.8"
},
Expand Down Expand Up @@ -70,12 +68,5 @@
"bamarni/composer-bin-plugin": true,
"phpstan/extension-installer": true
}
},
"extra": {
"laravel": {
"dont-discover": [
"laravel/dusk"
]
}
}
}
Loading
Loading