diff options
author | vincent-peugnet <v.peugnet@free.fr> | 2018-11-29 01:53:17 +0100 |
---|---|---|
committer | vincent-peugnet <v.peugnet@free.fr> | 2018-11-29 01:53:17 +0100 |
commit | d0ef17169701f90a9dab5f50e3eb61954653cae2 (patch) | |
tree | 03efa5a4e6eb1d2727b4c075b16a3627b1ad4591 /app | |
parent | 6e3ad2f1355e5f474cc02ab3b9eebe881dbb04ee (diff) | |
download | wcms-d0ef17169701f90a9dab5f50e3eb61954653cae2.tar.gz wcms-d0ef17169701f90a9dab5f50e3eb61954653cae2.zip |
font upload
Diffstat (limited to 'app')
-rw-r--r-- | app/class/controllerart.php | 2 | ||||
-rw-r--r-- | app/class/controllerconnect.php | 4 | ||||
-rw-r--r-- | app/class/controllerfont.php | 19 | ||||
-rw-r--r-- | app/class/modelfont.php | 57 | ||||
-rw-r--r-- | app/class/routes.php | 3 | ||||
-rw-r--r-- | app/view/templates/edittopbar.php | 2 | ||||
-rw-r--r-- | app/view/templates/font.php | 47 | ||||
-rw-r--r-- | app/view/templates/navart.php | 2 |
8 files changed, 119 insertions, 17 deletions
diff --git a/app/class/controllerart.php b/app/class/controllerart.php index 6740f9c..67ec280 100644 --- a/app/class/controllerart.php +++ b/app/class/controllerart.php @@ -174,7 +174,7 @@ class Controllerart extends Controller $this->artmanager->delete($this->art); } - $this->routedirect('backrouter'); + $this->routedirect('home'); } public function update($id) diff --git a/app/class/controllerconnect.php b/app/class/controllerconnect.php index b8dea88..dd06933 100644 --- a/app/class/controllerconnect.php +++ b/app/class/controllerconnect.php @@ -39,7 +39,7 @@ class Controllerconnect extends Controller if (!empty($id)) { $this->routedirect('artread/', ['art' => $id]); } else { - $this->routedirect('backrouter'); + $this->routedirect('home'); } } @@ -50,7 +50,7 @@ class Controllerconnect extends Controller if (!empty($id)) { $this->routedirect('artread/', ['art' => $id]); } else { - $this->routedirect('backrouter'); + $this->routedirect('home'); } } diff --git a/app/class/controllerfont.php b/app/class/controllerfont.php index 29064d2..d85e60e 100644 --- a/app/class/controllerfont.php +++ b/app/class/controllerfont.php @@ -14,7 +14,14 @@ class Controllerfont extends Controller public function desktop() { - var_dump($this->fontmanager->getfontlist()); + if($this->user->isadmin()) { + + $fontlist = $this->fontmanager->getfontlist(); + + $this->showtemplate('font', ['fontlist' => $fontlist, 'fonttypes' => $this->fontmanager->getfonttypes(), 'fontfile' => Model::globalpath().'fonts.css']); + } else { + $this->routedirect('home'); + } } public function render() @@ -23,9 +30,15 @@ class Controllerfont extends Controller $this->routedirect('font'); } - public function addfont() + public function add() { - + var_dump($_FILES); + if(isset($_POST['fontname'])) { + $fontname = $_POST['fontname']; + } else { + $fontname = ''; + } + var_dump($this->fontmanager->upload($_FILES, 2 ** 16, $fontname)); } } diff --git a/app/class/modelfont.php b/app/class/modelfont.php index 09f2ddd..4059096 100644 --- a/app/class/modelfont.php +++ b/app/class/modelfont.php @@ -11,6 +11,14 @@ class Modelfont extends Model return $this->fontlist($this->list()); } + public function getfonttypes() + { + $fonttypes = array_map(function ($ext) { + return '.' . $ext; + }, $this::FONT_TYPES); + return implode(', ', $fonttypes); + } + public function renderfontface() { $list = $this->list(); @@ -41,13 +49,12 @@ class Modelfont extends Model { $fontlist = []; $fonttypes = implode('|', $this::FONT_TYPES); - $regex = '#(.+)\.('.$fonttypes.')#'; + $regex = '#(.+)\.(' . $fonttypes . ')#'; foreach ($list as $font) { - if(preg_match($regex, $font, $out)) { - $fontlist[] = ['id' => $out[1], 'ext' =>$out[2]]; + if (preg_match($regex, $font, $out)) { + $fontlist[] = ['id' => $out[1], 'ext' => $out[2], 'size' => filesize(Model::FONT_DIR . $font)]; } } - return $fontlist; } @@ -55,7 +62,7 @@ class Modelfont extends Model { $fontface = ''; foreach ($fontlist as $font) { - $fontface .= '@font-face {' . PHP_EOL . 'font-family: ' . $font['id'] . ';' . PHP_EOL . ' src: url( ' . Model::fontpath() . $font['id'] .'.'. $font['ext'] . ');' . PHP_EOL . '}' . PHP_EOL . PHP_EOL; + $fontface .= '@font-face {' . PHP_EOL . 'font-family: ' . $font['id'] . ';' . PHP_EOL . ' src: url( ' . Model::fontpath() . $font['id'] . '.' . $font['ext'] . ');' . PHP_EOL . '}' . PHP_EOL . PHP_EOL; } return $fontface; } @@ -63,17 +70,51 @@ class Modelfont extends Model public function write(string $fontface) { - $write = file_put_contents(Model::GLOBAL_DIR.'fonts.css', $fontface); - if($write !== false) { + $write = file_put_contents(Model::GLOBAL_DIR . 'fonts.css', $fontface); + if ($write !== false) { } } -} + public function upload(array $file, $maxsize = 2 ** 24, $id = null) + { + $message = 'runing'; + if (isset($file) and $file['font']['error'] == 0 and $file['font']['size'] < $maxsize) { + $infosfichier = pathinfo($file['font']['name']); + $extension_upload = $infosfichier['extension']; + $extensions_autorisees = $this::FONT_TYPES; + if (in_array($extension_upload, $extensions_autorisees)) { + if (!empty($id)) { + $id = strtolower(strip_tags($id)); + $id = str_replace(' ', '_', $id); + } else { + $id = $infosfichier['filename']; + } + if (!file_exists($this::FONT_DIR . $id . '.' . $extension_upload)) { + + $extension_upload = strtolower($extension_upload); + $uploadok = move_uploaded_file($file['font']['tmp_name'], $this::FONT_DIR . $id . '.' . $extension_upload); + if ($uploadok) { + $message = 'uploadok'; + } else { + $message = 'uploaderror'; + } + } else { + $message = 'filealreadyexist'; + + } + } + } else { + $message = 'filetoobig'; + + } + return $message; + } +} diff --git a/app/class/routes.php b/app/class/routes.php index e5175aa..5edfa81 100644 --- a/app/class/routes.php +++ b/app/class/routes.php @@ -14,12 +14,13 @@ class Routes } $router->addMatchTypes(array('cid' => '[a-zA-Z0-9-_+,\'!%@&.$€=\(\|\)]+')); $router->addRoutes([ - ['GET|POST', '/', 'Backrouter#run', 'backrouter'], + ['GET|POST', '/', 'Controllerhome#desktop', 'home'], ['POST', '/!co', 'Controllerconnect#log', 'log'], ['GET', '/!co', 'Controllerconnect#connect', 'connect'], ['GET', '/!m', 'Controllermedia#desktop', 'media'], ['GET', '/!font', 'Controllerfont#desktop', 'font'], ['GET', '/!font/render', 'Controllerfont#render', 'fontrender'], + ['POST', '/!font/add', 'Controllerfont#add', 'fontadd'], ['GET', '/[cid:art]/', 'Controllerart#read', 'artread/'], ['GET', '/[cid:art]', 'Controllerart#read', 'artread'], ['GET', '/[cid:art]/add', 'Controllerart#add', 'artadd'], diff --git a/app/view/templates/edittopbar.php b/app/view/templates/edittopbar.php index 5090081..6d90932 100644 --- a/app/view/templates/edittopbar.php +++ b/app/view/templates/edittopbar.php @@ -3,7 +3,7 @@ <form action="<?= $this->uart('artupdate', $art->id()) ?>" method="post" id="update"> <span> - <a href="<?= $this->url('backrouter') ?>" class="icon" >⏏</a> + <a href="<?= $this->url('home') ?>" class="icon" >⏏</a> </span> <span> <input type="submit" value="update" accesskey="x" form="update"> diff --git a/app/view/templates/font.php b/app/view/templates/font.php new file mode 100644 index 0000000..e294031 --- /dev/null +++ b/app/view/templates/font.php @@ -0,0 +1,47 @@ +<?php $this->layout('layout', ['title' => 'font', 'css' => $css . 'font.css']) ?> + + +<?php $this->start('page') ?> + +<body> +<section class="font"> + + +<a href="<?= $this->url('fontrender') ?>">⚡ Render</a> +<a href="<?= $fontfile ?>" target="_blank">👓 View font CSS file</a> + + +<form action="<?= $this->url('fontadd') ?>" method="post" enctype="multipart/form-data"> +<label for="font">Font file <i>(<?= $fonttypes ?>)</i></label> +<input type="file" name="font" id="font" accept="<?= $fonttypes ?>"> +<label for="fontname">Rename font <i>(optionnal)</i></label> +<input type="text" name="fontname" id="fontname"> +<input type="submit" value="upload font(s)"> +</form> + + +<table id="fontlist"> +<tr> +<th>font</th> +<th>type</th> +<th>size</th> +</tr> +<?php + +foreach ($fontlist as $font ) { + ?> + <tr> + <td><?= $font['id'] ?></td> + <td><?= $font['ext'] ?></td> + <td><?= readablesize($font['size']) ?></td> + </tr> + <?php +} + +?> +</table> + +</section> +</body> + +<?php $this->stop('page') ?>
\ No newline at end of file diff --git a/app/view/templates/navart.php b/app/view/templates/navart.php index 45e9cda..8e7c40b 100644 --- a/app/view/templates/navart.php +++ b/app/view/templates/navart.php @@ -63,7 +63,7 @@ <span class="button" style="font-family: monospace; background-color: #7b97b9;" >User lvl : <?= $user->level() ?></span> </li> <li class="drop"> - <a class="button" href="<?= $this->url('backrouter') ?>">home</a> + <a class="button" href="<?= $this->url('home') ?>">home</a> </li> |