]> _ Git - cubist_cms-back.git/commitdiff
wip #2965 @0.5
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Thu, 29 Aug 2019 10:06:37 +0000 (12:06 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Thu, 29 Aug 2019 10:06:37 +0000 (12:06 +0200)
composer.json
src/app/Http/Controllers/CubistPWAController.php
src/app/Magic/Models/Settings.php
src/app/Magic/PageData.php
src/resources/views/favicon.blade.php
src/routes/cubist/backpack/pwa.php

index 80e86363458ab55e47dcbfb513324598c31e1180..3c49936523bbc0fbde34224b9c0576e2baece0ed 100644 (file)
@@ -42,7 +42,8 @@
         "barryvdh/laravel-debugbar": "^3.2",
         "league/commonmark-ext-autolink": "^1.0",
         "cviebrock/laravel-elasticsearch": "^3.6",
-        "spatie/laravel-honeypot": "^1.3"
+        "spatie/laravel-honeypot": "^1.3",
+        "chrisjean/php-ico": "^1.0"
 
     },
     "require-dev": {
index e943f4bc0863fee74e32c01ce6adad4d604ab1cf..fd46f644ad12f571f9992aac03d494c12def2760 100644 (file)
@@ -4,28 +4,49 @@
 namespace Cubist\Backpack\app\Http\Controllers;
 
 use Illuminate\Http\Request;
+use PHP_ICO;
 
 class CubistPWAController extends CubistFrontController
 {
     public static $androidSizes = [36, 48, 72, 96, 144, 192, 256, 512, 1024];
     public static $iosSizes = [57, 72, 76, 114, 120, 144, 152, 167, 182];
-    public static $faviconSizes = [16, 32,48,96,144, 192,256,384,512];
+    public static $faviconSizes = [16, 32, 48, 96, 144, 192, 256, 384, 512];
 
     public function manifest(Request $request)
     {
         $icons = [];
+        foreach (self::$androidSizes as $size) {
+            $icons[] = [
+                'sizes' => $size . 'x' . $size,
+                'type' => 'image/png',
+                'src' => $this->data['global']->getImageUrl('favicon_android', 'favicon_android_' . $size),
+                'density' => round($size / 48, 3),
+            ];
+        }
 
         $res = ['name' => $this->data['global']->pwa_name,
             'short_name' => $this->data['global']->pwa_short_name,
             'description' => '',
             'display' => 'standalone',
             'orientation' => 'any',
-            'background-color' => $this->data['global']->pwa_theme_color,
-            'theme-color' => $this->data['global']->pwa_theme_color,
+            'background_color' => $this->data['global']->pwa_theme_color,
+            'theme_color' => $this->data['global']->pwa_theme_color,
             'start_url' => '/',
             'scope' => '/',
             'icons' => $icons];
 
         return response(json_encode($res))->header('Content-Type', 'application/manifest+json');
     }
+
+    public function favicon()
+    {
+        $source = $this->data['global']->getImageFile('favicon_android', 'favicon_144');
+        $dest = storage_path('favicon.ico');
+        dd($dest);
+        if (!file_exists($dest) || filemtime($source) > filemtime($dest)) {
+            $ico_lib = new PHP_ICO($source, array(array(16, 16), array(32, 32), array(64, 64), array(128, 128)));
+            $ico_lib->save_ico($dest);
+        }
+        return response(file_get_contents($dest))->header('Content-Type','text/html');
+    }
 }
index 83cd9864da71764599007ddbd574396573c1f3d4..9e5e44673a09a32ce0fd2bc11b777366b5b12d40 100644 (file)
@@ -17,6 +17,8 @@ class Settings extends CubistMagicModel
 
     public function registerMediaConversions(Media $media = null)
     {
+        parent::registerMediaConversions($media);
+
         foreach (CubistPWAController::$androidSizes as $size) {
             $this->addMediaConversion('favicon_android_' . $size)
                 ->width($size)
index f148a6e820b5812ac8bef09bd4baf1f45a219549..8d534348f2549e283ad9a8c3060362eba3fb3c24 100644 (file)
@@ -240,6 +240,13 @@ class PageData implements \ArrayAccess
         return count($this->getMedia($offset)) > 0;
     }
 
+    public function getImageFile($offset, $conversionName = '')
+    {
+        /** @var Media $media */
+        $media = $this->getMedia($offset)->get(0);
+        return $media->getPath($conversionName);
+    }
+
     public function getMediaURL($offset, $default = null)
     {
         return $this->getImageURL($offset, '', $default);
index e14cdaf221d050c0658f64f6f1c191d70a10389a..6440f38744190b999def6ac99d15202a4bf12fcb 100644 (file)
@@ -2,5 +2,5 @@
     <link rel="icon" type="image/png" sizes="{{$size}}x{{$size}}" href="{{ $global->getImageUrl('favicon','favicon_'.$size) }}" />
 @endforeach
 @foreach(Cubist\Backpack\app\Http\Controllers\CubistPWAController::$iosSizes as $size)
-    <link rel="apple-touch-icon" sizes="{{$size}}x{{$size}}" href="{{ $global->getImageUrl('favicon_ios','favicon_ios_'.$size) }}" type="image/png" />
+    <link rel="apple-touch-icon" type="image/png" sizes="{{$size}}x{{$size}}" href="{{ $global->getImageUrl('favicon_ios','favicon_ios_'.$size) }}" />
 @endforeach
index b0228fe3fe429ff984d873907506b534ce34b343..4265a0cd417c8ec99fe17e026bbedc80f028d2cb 100644 (file)
@@ -1,2 +1,3 @@
 <?php
 Route::get('/manifest.webmanifest', '\Cubist\Backpack\app\Http\Controllers\CubistPWAController@manifest');
+Route::get('/favicon', '\Cubist\Backpack\app\Http\Controllers\CubistPWAController@favicon');