commit f78a4fd0b7128828fea7458dbcb43eadf1ec6293 Author: Michel Date: Sun Jun 24 15:51:50 2018 +0200 First commit diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..f2b28c1 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,17 @@ +# For more information about the properties used in this file, +# please see the EditorConfig documentation: +# http://editorconfig.org + +[*] +charset = utf-8 +end_of_line = lf +indent_size = 4 +indent_style = space +insert_final_newline = true +trim_trailing_whitespace = true + +[{*.yml,package.json,*.scss,*.js}] +indent_size = 2 + +# The indent size used in the package.json file cannot be changed: +# https://github.com/npm/npm/pull/3180#issuecomment-16336516 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..1ad0b69 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +/node_modules/ +/**/*.js.map +/**/*.css.map diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..9da8689 --- /dev/null +++ b/LICENSE @@ -0,0 +1,28 @@ +Copyright (c) 2017, The Webmen +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +* Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + +* Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +* Neither the name of the {organization} nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + diff --git a/README.md b/README.md new file mode 100644 index 0000000..9174b56 --- /dev/null +++ b/README.md @@ -0,0 +1,12 @@ +# SilverStripe Progressive Web App + +Tools to add progressive web app functionality to your silverstripe website + +## Installation +``` +composer require pixelspin/silverstripe-progressivewebapp +``` + +## Usage +Install the module, run dev/build and fill in the settings in the siteconfig +Place the link to the manifest file () in the head of your pages \ No newline at end of file diff --git a/_config/config.yml b/_config/config.yml new file mode 100644 index 0000000..00b9baf --- /dev/null +++ b/_config/config.yml @@ -0,0 +1,11 @@ +--- +Name: progressivewebapp +--- + +SilverStripe\Control\Director: + rules: + 'manifest.json': 'Pixelspin\ProgressiveWebApp\Controllers\ProgressiveWebAppController' + +SilverStripe\SiteConfig\SiteConfig: + extensions: + - Pixelspin\ProgressiveWebApp\Extensions\ProgressiveWebAppSiteConfigExtension \ No newline at end of file diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..96759c9 --- /dev/null +++ b/composer.json @@ -0,0 +1,37 @@ +{ + "name": "pixelspin/silverstripe-progressivewebapp", + "description": "Tools to add progressive web app functionality to your silverstripe website", + "type": "silverstripe-vendormodule", + "keywords": [ + "silverstripe", + "progressive", + "app" + ], + "license": "BSD-3-Clause", + "authors": [{ + "name": "Michel van der Steege", + "email": "michelsteege@hotmail.com" + }], + "minimum-stability": "dev", + "prefer-stable": true, + "require": { + "silverstripe/cms": "^4.0@dev", + "silverstripe/vendor-plugin": "^1.0", + "silverware/colorpicker": "^1.0" + }, + "require-dev": { + "phpunit/phpunit": "^5.7", + "squizlabs/php_codesniffer": "^3.0" + }, + "extra": { + "installer-name": "silverstripe-progressivewebapp", + "branch-alias": { + "dev-master": "2.x-dev" + } + }, + "autoload": { + "psr-4": { + "Pixelspin\\ProgressiveWebApp\\": "src/" + } + } +} diff --git a/src/Controllers/ProgressiveWebAppController.php b/src/Controllers/ProgressiveWebAppController.php new file mode 100644 index 0000000..81e7ff1 --- /dev/null +++ b/src/Controllers/ProgressiveWebAppController.php @@ -0,0 +1,90 @@ +ManifestName){ + $manifestContent['name'] = $config->ManifestName; + } + if($config->ManifestShortName){ + $manifestContent['short_name'] = $config->ManifestShortName; + } + if($config->ManifestDescription){ + $manifestContent['description'] = $config->ManifestDescription; + } + if($config->ManifestColor){ + $manifestContent['background_color'] = $config->ManifestColor; + $manifestContent['theme_color'] = $config->ManifestColor; + } + if($config->ManifestOrientation){ + $manifestContent['orientation'] = $config->ManifestOrientation; + } + if($config->ManifestDisplay){ + $manifestContent['display'] = $config->ManifestDisplay; + } + + $logo = $config->ManifestLogo(); + if($logo && $logo->exists()){ + $mime = $logo->getMimeType(); + $manifestContent['icons'] = [ + [ + 'src' => $logo->Fill(48,48)->Link(), + 'sizes' => '48x48', + 'type' => $mime + ], + [ + 'src' => $logo->Fill(72,72)->Link(), + 'sizes' => '72x72', + 'type' => $mime + ], + [ + 'src' => $logo->Fill(96,96)->Link(), + 'sizes' => '96x96', + 'type' => $mime + ], + [ + 'src' => $logo->Fill(144,144)->Link(), + 'sizes' => '144x144', + 'type' => $mime + ], + [ + 'src' => $logo->Fill(168,168)->Link(), + 'sizes' => '168x168', + 'type' => $mime + ], + [ + 'src' => $logo->Fill(192,192)->Link(), + 'sizes' => '192x192', + 'type' => $mime + ] + ]; + } + + $this->getResponse()->addHeader('Content-Type', 'application/manifest+json; charset="utf-8"'); + return json_encode($manifestContent); + + } + +} \ No newline at end of file diff --git a/src/Extensions/ProgressiveWebAppSiteConfigExtension.php b/src/Extensions/ProgressiveWebAppSiteConfigExtension.php new file mode 100644 index 0000000..3025d68 --- /dev/null +++ b/src/Extensions/ProgressiveWebAppSiteConfigExtension.php @@ -0,0 +1,68 @@ + 'Varchar', + 'ManifestShortName' => 'Varchar', + 'ManifestDescription' => 'Varchar(255)', + 'ManifestColor' => DBColor::class, + 'ManifestOrientation' => 'Varchar', + 'ManifestDisplay' => 'Varchar' + ]; + + private static $displays = [ + 'fullscreen', + 'standalone', + 'minimal-ui', + 'browser' + ]; + + private static $orientations = [ + 'any', + 'natural', + 'landscape', + 'landscape-primary', + 'landscape-secondary', + 'portrait', + 'portrait-primary', + 'portrait-secondary' + ]; + + private static $has_one = [ + 'ManifestLogo' => Image::class + ]; + + public function onAfterWrite() { + parent::onAfterWrite(); + $manifestLogo = $this->owner->ManifestLogo(); + if ($manifestLogo && $manifestLogo->exists()) { + $manifestLogo->doPublish(); + } + } + + public function updateCMSFields(FieldList $fields) { + + $fields->addFieldToTab('Root.ProgressiveWebApp', TextField::create('ManifestName', 'Name')->setDescription('Application name')); + $fields->addFieldToTab('Root.ProgressiveWebApp', TextField::create('ManifestShortName', 'Short name')->setDescription('Short human-readable name for the application')); + $fields->addFieldToTab('Root.ProgressiveWebApp', TextField::create('ManifestDescription', 'Description')->setDescription('Short description about the app')); + $fields->addFieldToTab('Root.ProgressiveWebApp', ColorField::create('ManifestColor', 'Color')->setDescription('Color used for the splash screen and/or icon')); + $fields->addFieldToTab('Root.ProgressiveWebApp', DropdownField::create('ManifestOrientation', 'Orientation', array_combine(self::$orientations, self::$orientations))->setDescription('App orientation')); + $fields->addFieldToTab('Root.ProgressiveWebApp', DropdownField::create('ManifestDisplay', 'Display', array_combine(self::$displays, self::$displays))->setDescription('Display mode of the app')); + $fields->addFieldToTab('Root.ProgressiveWebApp', UploadField::create('ManifestLogo', 'Logo')->setDescription('This image must be square and at least 512x512px')); + + } + + +}