Skip to content

Commit

Permalink
refactor: Laravel Pint changes
Browse files Browse the repository at this point in the history
  • Loading branch information
secondnetwork committed Feb 20, 2024
1 parent c9ab54b commit 8fdb5d4
Show file tree
Hide file tree
Showing 8 changed files with 76 additions and 82 deletions.
29 changes: 15 additions & 14 deletions src/BladeDirectives.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@ class BladeDirectives
{
public static function kompassCss()
{
$url = 'http://localhost:5088:' . env('VITE_PORT_KOMPASS', '5088') . '/resources/js/main.js';
$url = 'http://localhost:5088:'.env('VITE_PORT_KOMPASS', '5088').'/resources/js/main.js';
$url200 = @get_headers($url);
if (!$url200) {
if (! $url200) {
// $content = (public_path('vendor/kompass/assets/manifest.json'));
if(file_exists(public_path('vendor/kompass/assets/manifest.json'))) {
if (file_exists(public_path('vendor/kompass/assets/manifest.json'))) {
$content = file_get_contents(asset('vendor/kompass/assets/manifest.json'));
}else{
} else {
$content = '';
}

// $manifest = json_decode($content, true);
// if (Storage::exists(asset('vendor/kompass/assets/manifest.json')))
// dump('ja');
Expand All @@ -32,12 +32,13 @@ public static function kompassCss()

$entry = 'resources/js/main.js';

if (!empty($manifest[$entry]['css'])) {
if (! empty($manifest[$entry]['css'])) {
foreach ($manifest[$entry]['css'] as $file) {
$urls[] = $file;
// $tags .= "<link rel=\"stylesheet\" href=\"$url\">";
}
return '<link rel="stylesheet" href="' . asset('vendor/kompass/assets/' . $urls[0]) . '"><style>[x-cloak] { display: none !important; }</style>';

return '<link rel="stylesheet" href="'.asset('vendor/kompass/assets/'.$urls[0]).'"><style>[x-cloak] { display: none !important; }</style>';
}
} else {
return '';
Expand All @@ -46,22 +47,22 @@ public static function kompassCss()

public static function kompassJs()
{
$url = 'http://localhost:' . env('VITE_PORT_KOMPASS', '5088') . '/resources/js/main.js';
$url = 'http://localhost:'.env('VITE_PORT_KOMPASS', '5088').'/resources/js/main.js';
$url200 = @get_headers($url);
if (!$url200) {
if(file_exists(public_path('vendor/kompass/assets/manifest.json'))) {
if (! $url200) {
if (file_exists(public_path('vendor/kompass/assets/manifest.json'))) {
$content = file_get_contents(asset('vendor/kompass/assets/manifest.json'));
}else{
} else {
$content = '';
}
$manifest = json_decode($content, true);
$entry = 'resources/js/main.js';
if ($content) {
return '<script type="module" defer src="' . asset('vendor/kompass/assets/' . $manifest[$entry]['file']) . '"></script>';
return '<script type="module" defer src="'.asset('vendor/kompass/assets/'.$manifest[$entry]['file']).'"></script>';
}

} else {
return '<script type="module" defer src="' . $url . '"></script>';
return '<script type="module" defer src="'.$url.'"></script>';
}
}

Expand Down
2 changes: 0 additions & 2 deletions src/Commands/FaviconGeneratorCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
use Illuminate\Console\Command;
use Secondnetwork\Kompass\FaviconGenerator;



class FaviconGeneratorCommand extends Command
{
public $signature = 'kompass:favicon-generator';
Expand Down
60 changes: 26 additions & 34 deletions src/FaviconGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,38 @@

namespace Secondnetwork\Kompass;

use Intervention\Image\ImageManager;
use Intervention\Image\Drivers\Gd\Driver;
use Intervention\Image\ImageManager;

class FaviconGenerator
{

protected String $distPath;
protected string $distPath;

public function __construct(
protected String $filePath,
protected String $publicPath = 'favicon',
)
{
if(!file_exists(public_path($this->publicPath))) {
protected string $filePath,
protected string $publicPath = 'favicon',
) {
if (! file_exists(public_path($this->publicPath))) {
mkdir(public_path($this->publicPath), 0755, true);
}
$this->distPath = public_path($this->publicPath);
}

public function generateFaviconsFromImagePath() {
public function generateFaviconsFromImagePath()
{
$manager = new ImageManager(new Driver());
// create an image manager instance with imagick driver
// Image::configure(['driver' => 'imagick']);

$image = $manager->read($this->filePath);

$image->resize(192, 192)->save($this->distPath . "/android-chrome-192x192.png", 100, 'png');
$image->resize(512, 512)->save($this->distPath . "/android-chrome-512x512.png", 100, 'png');
$image->resize(180, 180)->save($this->distPath . "/apple-touch-icon.png", 100, 'png');
$image->resize(16, 16)->save($this->distPath . "/favicon-16x16.png", 100, 'png');
$image->resize(32, 32)->save($this->distPath . "/favicon-32x32.png", 100, 'png');
$image->resize(32, 32)->save($this->distPath . "/favicon.ico", 100, 'ico');
$image->resize(150, 150)->save($this->distPath . "/mstile-150x150.png", 100, 'png');
$image->resize(192, 192)->save($this->distPath.'/android-chrome-192x192.png', 100, 'png');
$image->resize(512, 512)->save($this->distPath.'/android-chrome-512x512.png', 100, 'png');
$image->resize(180, 180)->save($this->distPath.'/apple-touch-icon.png', 100, 'png');
$image->resize(16, 16)->save($this->distPath.'/favicon-16x16.png', 100, 'png');
$image->resize(32, 32)->save($this->distPath.'/favicon-32x32.png', 100, 'png');
$image->resize(32, 32)->save($this->distPath.'/favicon.ico', 100, 'ico');
$image->resize(150, 150)->save($this->distPath.'/mstile-150x150.png', 100, 'png');

// // favicon.ico
// $icon = new \Imagick();
Expand All @@ -59,8 +58,7 @@ public function saveBrowserConfigXml(): void
</msapplication>
</browserconfig>';


$xmlFile = fopen("{$this->distPath}/browserconfig.xml", "w") or die("Unable to open file!");
$xmlFile = fopen("{$this->distPath}/browserconfig.xml", 'w') or exit('Unable to open file!');
fwrite($xmlFile, $xml);
fclose($xmlFile);
}
Expand All @@ -72,12 +70,12 @@ public function saveSiteWebManifest(): void
"short_name": "",
"icons": [
{
"src": "/' . $this->publicPath . '/android-chrome-192x192.png",
"src": "/'.$this->publicPath.'/android-chrome-192x192.png",
"sizes": "192x192",
"type": "image/png"
},
{
"src": "/' . $this->publicPath . '/android-chrome-512x512.png",
"src": "/'.$this->publicPath.'/android-chrome-512x512.png",
"sizes": "512x512",
"type": "image/png"
}
Expand All @@ -87,28 +85,22 @@ public function saveSiteWebManifest(): void
"display": "standalone"
}';


$jsonFile = fopen("{$this->distPath}/site.webmanifest", "w") or die("Unable to open file!");
$jsonFile = fopen("{$this->distPath}/site.webmanifest", 'w') or exit('Unable to open file!');
fwrite($jsonFile, $json);
fclose($jsonFile);
}

/**
* @param String $publicPath
* @return string
*/
public static function generateHtmlMetaIcons(String $publicPath = 'favicons'): string
public static function generateHtmlMetaIcons(string $publicPath = 'favicons'): string
{
$html = '
<link rel="apple-touch-icon" sizes="180x180" href=" ' . $publicPath . '/apple-touch-icon.png">
<link rel="icon" type="image/png" sizes="32x32" href=" ' . $publicPath . '/favicon-32x32.png">
<link rel="icon" type="image/png" sizes="16x16" href=" ' . $publicPath . '/favicon-16x16.png">
<link rel="manifest" href=" ' . $publicPath . '/site.webmanifest">
<link rel="mask-icon" href=" ' . $publicPath . '/safari-pinned-tab.svg" color="#5bbad5">
<link rel="apple-touch-icon" sizes="180x180" href=" '.$publicPath.'/apple-touch-icon.png">
<link rel="icon" type="image/png" sizes="32x32" href=" '.$publicPath.'/favicon-32x32.png">
<link rel="icon" type="image/png" sizes="16x16" href=" '.$publicPath.'/favicon-16x16.png">
<link rel="manifest" href=" '.$publicPath.'/site.webmanifest">
<link rel="mask-icon" href=" '.$publicPath.'/safari-pinned-tab.svg" color="#5bbad5">
<meta name="msapplication-TileColor" content="#da532c">
<meta name="theme-color" content="#ffffff">';

return $html;
}

}
14 changes: 8 additions & 6 deletions src/Helpers/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ function get_thumbnails($id_media, $class = null, $size = null)
if (! function_exists('get_field')) {
function get_field($type, $data, $class = null, $size = null)
{

foreach ($data as $value) {
if ($value->type == $type) {

Expand Down Expand Up @@ -87,7 +87,7 @@ function get_field($type, $data, $class = null, $size = null)
}

if ($value->type == 'gallery' && $value->data != null) {

$file = files::where('id', $value->data)->first();
if ($file) {
if ($size) {
Expand Down Expand Up @@ -229,13 +229,15 @@ function setting($key = null, $default = null)

return $data->data;
}
// return Arr::get(config('settings'), $data );
// return Arr::get(config('settings'), $data );
} else {
$data = Arr::get(app('settings'), $data);
if (Schema::hasTable('settings')) {
$data = Arr::get(app('settings'), $data);

if (! empty($data->group) == $keydata[0]) {
if (! empty($data->group) == $keydata[0]) {

return $data->data;
return $data->data;
}
}
}

Expand Down
17 changes: 9 additions & 8 deletions src/KompassServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
use Illuminate\View\Compilers\BladeCompiler;
use Illuminate\View\ComponentAttributeBag;
use Livewire\Livewire;
use Secondnetwork\Kompass\Commands\KompassCommand;
use Secondnetwork\Kompass\Commands\FaviconGeneratorCommand;
use Secondnetwork\Kompass\Commands\KompassCommand;
use Secondnetwork\Kompass\Http\Middleware\RoleMiddleware;
use Secondnetwork\Kompass\Models\Page;
use Secondnetwork\Kompass\Models\Post;
Expand Down Expand Up @@ -71,9 +71,9 @@ public function boot(): void

$this->commands([
KompassCommand::class,
FaviconGeneratorCommand::class
FaviconGeneratorCommand::class,
]);

}
Gate::define('role', function ($user, ...$roles) {
return $user->hasRole($roles);
Expand Down Expand Up @@ -186,12 +186,13 @@ public function register(): void
$this->app->singleton('kompassVite', function () {
return new KompassVite;
});

$this->app->singleton('settings', function ($app) {
return $app['cache']->remember('settings', 10, function () {
return Setting::pluck('data', 'key', 'group')->toArray();
if (Schema::hasTable('settings')) {
$this->app->singleton('settings', function ($app) {
return $app['cache']->remember('settings', 10, function () {
return Setting::pluck('data', 'key', 'group')->toArray();
});
});
});
}
}

protected function loadHelpers()
Expand Down
19 changes: 9 additions & 10 deletions src/Livewire/Frontend/Pageview.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\Storage;
use Livewire\Component;
use RalphJSmit\Laravel\SEO\Support\SEOData;
use Secondnetwork\Kompass\Models\Block;
use Secondnetwork\Kompass\Models\Datafield;
use Secondnetwork\Kompass\Models\File;
Expand Down Expand Up @@ -34,17 +33,17 @@ public function mount($slug = null)
if (! empty($this->page->new_url)) {
return redirect($this->page->new_url, $this->page->status_code);
}

$this->blocks = Cache::rememberForever('kompass_block_'.$slug, function () {
return Block::where('blockable_type', 'page')
->where('blockable_id', $this->page->id)
->where('status', 'published')
->orderBy('order', 'asc')
->where('subgroup', null)
->with(['children' => function ($query) {
$query->where('status', 'published');
}])
->with(['datafield','meta'])->get();
->where('blockable_id', $this->page->id)
->where('status', 'published')
->orderBy('order', 'asc')
->where('subgroup', null)
->with(['children' => function ($query) {
$query->where('status', 'published');
}])
->with(['datafield', 'meta'])->get();
});
// //blockable_type
// $this->blocks = Cache::rememberForever('kompass_block_'.$slug, function () {
Expand Down
6 changes: 3 additions & 3 deletions src/Livewire/Medialibrary.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,10 +158,10 @@ public function selectItem($itemId, $action)
$this->description = $model->description;
$this->type = $model->type;
if ($model->path) {
$this->file = 'storage/'. $model->path.'/'.$model->slug.'.'.$model->extension;
}else {
$this->file = 'storage/'.$model->path.'/'.$model->slug.'.'.$model->extension;
} else {
$this->file = 'storage/'.$model->slug.'.'.$model->extension;
}
}

$this->updated_at = $model->updated_at;
$this->FormEdit = true;
Expand Down
11 changes: 6 additions & 5 deletions src/Livewire/PagesData.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public function saveEditorState($editorJsonData, $id)
public function mount($id)
{
$this->page = Page::findOrFail($id);

$this->blocks = Block::where('blockable_type', 'page')->where('blockable_id', $id)->orderBy('order', 'asc')->where('subgroup', null)->with('children')->with('datafield')->get();

$this->blocktemplates = Blocktemplates::orderBy('order', 'asc')->get()->all();
Expand Down Expand Up @@ -198,7 +198,7 @@ public function addBlock($blocktemplatesID, $name, $type, $iconclass = null)
'alignment' => 'align-left',
]);
break;

default:
$blockmeta->saveMeta([
'layout' => 'popout',
Expand Down Expand Up @@ -293,7 +293,7 @@ public function updateGrid($id, $grid)
public function classname($id)
{
if ($this->newName != null) {
$setblock = Block::find($id);
$setblock = Block::find($id);

$setblock->deleteMeta('css-classname');
$setblock->saveMeta([
Expand All @@ -302,11 +302,12 @@ public function classname($id)
}
$this->resetPageComponent();
}

public function idanchor($id)
{
if ($this->newName != null) {
$setblock = Block::find($id);
$setblock->deleteMeta('idanchor');
$setblock = Block::find($id);
$setblock->deleteMeta('idanchor');
$setblock->deleteMeta('id-anchor');
$setblock->saveMeta([
'id-anchor' => $this->newName,
Expand Down

0 comments on commit 8fdb5d4

Please sign in to comment.