Empty sceleton
authorJoey Schulze <joey@infodrom.org>
Tue, 28 Feb 2017 21:51:41 +0000 (22:51 +0100)
committerJoey Schulze <joey@infodrom.org>
Sat, 24 Nov 2018 13:27:19 +0000 (14:27 +0100)
class/autoloader.class.php [new file with mode: 0644]
class/config.class.php [new file with mode: 0644]
class/template.class.php [new file with mode: 0644]
class/utilities.class.php [new file with mode: 0644]
html/favicon.ico [new file with mode: 0644]
html/index.php [new file with mode: 0644]
html/musiikki.css [new file with mode: 0644]
html/musiikki.js [new file with mode: 0644]

diff --git a/class/autoloader.class.php b/class/autoloader.class.php
new file mode 100644 (file)
index 0000000..5d080bc
--- /dev/null
@@ -0,0 +1,27 @@
+<?php
+
+class AutoLoader {
+  public static $loader = false;
+  protected static $classPath = __DIR__;
+
+  public static function init()
+  {
+    if (self::$loader === false)
+      self::$loader = new self();
+  }
+
+  public function __construct()
+  {
+    spl_autoload_register(array($this, 'autoload'));
+  }
+
+  protected function autoload($class)
+  {
+    $path = self::$classPath . '/' . strtolower($class) . '.class.php';
+
+    if (is_readable($path))
+      require_once($path);
+  }
+}
+
+AutoLoader::init();
diff --git a/class/config.class.php b/class/config.class.php
new file mode 100644 (file)
index 0000000..af29382
--- /dev/null
@@ -0,0 +1,51 @@
+<?php
+
+class Config {
+  const PATH = '/etc/musiikki.conf';
+
+  private static $main = false;
+
+  private $values = array();
+
+  public static function main()
+  {
+    if (self::$main === false)
+      self::$main = new Config(Config::PATH);
+
+    return self::$main;
+  }
+
+  private function __construct($path)
+  {
+    $this->loadValues($path);
+  }
+
+  private function loadValues($path)
+  {
+    if (!is_readable($path))
+      throw new Exception('Cannot open config file ' . $path);
+
+    $f = fopen($path, 'r');
+    if ($f === false)
+      throw new Exception('Cannot open config file ' . $path);
+
+    while (($line = fgets($f)) !== false) {
+      $line = trim($line);
+      if (substr($line,0,1) == '#') continue;
+      if (!strlen($line)) continue;
+
+      $parts = explode('=', $line, 2);
+      $this->values[$parts[0]] = $parts[1];
+    }
+
+    fclose($f);
+  }
+
+  public function get($name)
+  {
+    if (!array_key_exists($name, $this->values))
+      return NULL;
+
+    return $this->values[$name];
+  }
+}
diff --git a/class/template.class.php b/class/template.class.php
new file mode 100644 (file)
index 0000000..d8178ac
--- /dev/null
@@ -0,0 +1,36 @@
+<?php
+
+class Template {
+    const DIR = 'templates';
+
+    protected $template;
+    protected $templatePath;
+
+    public static function html($path, array $data=array())
+    {
+       $template = new Template($path);
+       return $template->render($data);
+    }
+
+    public function __construct($template)
+    {
+        $this->template = $template;
+        $this->templatePath = __DIR__ . '/../' . static::DIR . '/' . $this->template . '.phtml';
+
+        if (!is_readable($this->templatePath))
+            throw new Exception("Template {$this->template} not found");
+    }
+
+    public function render(array $data=array())
+    {
+        foreach ($data as $key => $value)
+            $$key = $value;
+
+        ob_start(); // Output Buffer einschalten
+        include($this->templatePath);
+        $renderedText = ob_get_contents();
+        ob_end_clean(); // Output Buffer beenden
+
+        return $renderedText;
+    }
+}
diff --git a/class/utilities.class.php b/class/utilities.class.php
new file mode 100644 (file)
index 0000000..1da847b
--- /dev/null
@@ -0,0 +1,39 @@
+<?php
+
+class Utilities {
+
+  public static function formatScript($path)
+  {
+    if (substr($path,-3) != '.js' || substr($path,-7) == '.min.js')
+      return sprintf('<script type="text/javascript" src="%s"></script>', $path);
+
+    $base = substr($path,0,-3);
+    $minfile = $base  . '.min.js';
+
+    if (!file_exists($minfile))
+      return sprintf('<script type="text/javascript" src="%s"></script>', $path);
+
+    if (filemtime($minfile) > filemtime($path))
+      return sprintf('<script type="text/javascript" src="%s"></script>', $minfile);
+
+    return sprintf('<script type="text/javascript" src="%s"></script>', $path);
+  }
+
+  public static function formatCSS($path)
+  {
+    if (substr($path,-4) != '.css' || substr($path,-8) == '.min.css')
+      return sprintf('<link rel="stylesheet" href="%s">', $path);
+
+    $base = substr($path,0,-4);
+    $minfile = $base  . '.min.css';
+
+    if (!file_exists($minfile))
+      return sprintf('<link rel="stylesheet" href="%s">', $path);
+
+    if (filemtime($minfile) > filemtime($path))
+      return sprintf('<link rel="stylesheet" href="%s">', $minfile);
+
+    return sprintf('<link rel="stylesheet" href="%s">', $path);
+  }
+
+}
diff --git a/html/favicon.ico b/html/favicon.ico
new file mode 100644 (file)
index 0000000..5e6f322
Binary files /dev/null and b/html/favicon.ico differ
diff --git a/html/index.php b/html/index.php
new file mode 100644 (file)
index 0000000..0b228f7
--- /dev/null
@@ -0,0 +1,5 @@
+<?php
+require_once(__DIR__.'/../class/autoloader.class.php');
+
+$template = new Template('index');
+echo $template->render([]);
diff --git a/html/musiikki.css b/html/musiikki.css
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/html/musiikki.js b/html/musiikki.js
new file mode 100644 (file)
index 0000000..e69de29