diff options
Diffstat (limited to 'app/class/modelfont.php')
-rw-r--r-- | app/class/modelfont.php | 53 |
1 files changed, 51 insertions, 2 deletions
diff --git a/app/class/modelfont.php b/app/class/modelfont.php index 11ce6dd..09f2ddd 100644 --- a/app/class/modelfont.php +++ b/app/class/modelfont.php @@ -2,10 +2,27 @@ class Modelfont extends Model { + + const FONT_TYPES = ['woff2', 'woff', 'otf', 'ttf', 'eot', 'svg']; + + + public function getfontlist() + { + return $this->fontlist($this->list()); + } + + public function renderfontface() + { + $list = $this->list(); + $fontlist = $this->fontlist($list); + $fontface = $this->fontface($fontlist); + $this->write($fontface); + } + + public function list() { - var_dump(Model::fontpath()); - if ($handle = opendir(Model::fontpath())) { + if ($handle = opendir(Model::FONT_DIR)) { $list = []; while (false !== ($entry = readdir($handle))) { if ($entry != "." && $entry != "..") { @@ -19,6 +36,38 @@ class Modelfont extends Model return $list; } + + public function fontlist(array $list) + { + $fontlist = []; + $fonttypes = implode('|', $this::FONT_TYPES); + $regex = '#(.+)\.('.$fonttypes.')#'; + foreach ($list as $font) { + if(preg_match($regex, $font, $out)) { + $fontlist[] = ['id' => $out[1], 'ext' =>$out[2]]; + } + } + + return $fontlist; + } + + public function fontface(array $fontlist) + { + $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; + } + return $fontface; + } + + + public function write(string $fontface) + { + $write = file_put_contents(Model::GLOBAL_DIR.'fonts.css', $fontface); + if($write !== false) { + + } + } } |