add: router.controller.svg (now manage svg recoloring)

This commit is contained in:
xdrm-brackets 2017-12-03 15:43:13 +01:00
parent 2653f896f2
commit c5fae9e7ce
2 changed files with 72 additions and 3 deletions

View File

@ -0,0 +1,60 @@
<?php
namespace router\controller;
class svg{
private $path;
private $color;
/* PRE-CALL
*
* @url<String> Calling URI
*
*/
public function __construct($url){
$this->path = $url['path'];
$this->color = substr($url['color'], 1);
}
/* Colorate svg
*
*/
public function color(){
header('Content-Type: image/svg+xml');
// On crée la partie ajoutée
$stylesheet = "\n<style type='text/css'>\n";
$stylesheet .= "\t#fill-edit{\n";
$stylesheet .= "\t\tfill: #".$this->color." !important;\n";
$stylesheet .= "\t\tfill-opacity: 1 !important;\n";
$stylesheet .= "\t}\n";
$stylesheet .= "\t#stroke-edit{\n";
$stylesheet .= "\t\tstroke: #".$this->color." !important;\n";
$stylesheet .= "\t\tstroke-opacity: 1 !important;\n";
$stylesheet .= "\t}\n";
$stylesheet .= "</style></svg>";
// On récupère le fichier
$file = file_get_contents(__PUBLIC__.'/'.$this->path);
// On ajoute le style
$file = str_replace('</svg>', $stylesheet, $file);
echo $file;
}
/* POST-CALL
*
*/
public function __destruct(){
}
}

View File

@ -5,10 +5,13 @@
"routes": { "routes": {
"/js/bundle.js": { "/{path}{color}": {
"methods": ["GET"], "methods": ["GET"],
"controller": "js:bundle", "controller": "svg:color",
"arguments": {} "arguments": {
"path": ".+\\.svg",
"color": "@[a-fA-F0-9]{6}"
}
}, },
"/js/_SERVER.js": { "/js/_SERVER.js": {
@ -17,6 +20,12 @@
"arguments": {} "arguments": {}
}, },
"/js/bundle.js": {
"methods": ["GET"],
"controller": "js:bundle",
"arguments": {}
},
"/{page}/": { "/{page}/": {
"methods": ["GET"], "methods": ["GET"],
"controller": "page:load", "controller": "page:load",