aboutsummaryrefslogtreecommitdiff
path: root/app/class/modelfont.php
diff options
context:
space:
mode:
Diffstat (limited to 'app/class/modelfont.php')
-rw-r--r--app/class/modelfont.php57
1 files changed, 49 insertions, 8 deletions
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;
+ }
+}