Initial commit of HandBrakeCluster PHP framework
Replaced dodgy placeholder with a set of PHP classes for displaying a HandBrake webui. Current code uses Smarty as a templating engine, and includes an ugly but functional set of pages. The HandBrake classes are at present only placeholders, and offer no real functionality. Working class autoloader for the HandBrakeCluster_ hierarchy.
This commit is contained in:
13
HandBrakeCluster/Config.class.php
Normal file
13
HandBrakeCluster/Config.class.php
Normal file
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
class HandBrakeCluster_Config {
|
||||
|
||||
private $filename;
|
||||
|
||||
public function __construct($filename) {
|
||||
$this->filename = $filename;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
?>
|
||||
13
HandBrakeCluster/Database.class.php
Normal file
13
HandBrakeCluster/Database.class.php
Normal file
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
class HandBrakeCluster_Database {
|
||||
|
||||
private $config;
|
||||
|
||||
public function __construct(HandBrakeCluster_Config $config) {
|
||||
$this->config = $config;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
17
HandBrakeCluster/Job.class.php
Normal file
17
HandBrakeCluster/Job.class.php
Normal file
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
class HandBrakeCluster_Job {
|
||||
|
||||
private $id;
|
||||
|
||||
public function __construct() {
|
||||
$this->id = 42;
|
||||
}
|
||||
|
||||
public function id() {
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
?>
|
||||
15
HandBrakeCluster/Log.class.php
Normal file
15
HandBrakeCluster/Log.class.php
Normal file
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
class HandBrakeCluster_Log {
|
||||
|
||||
private $database;
|
||||
private $config;
|
||||
|
||||
public function __construct(HandBrakeCluster_Database $database, HandBrakeCluster_Config $config) {
|
||||
$this->database = $database;
|
||||
$this->config = $config;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
88
HandBrakeCluster/Main.class.php
Normal file
88
HandBrakeCluster/Main.class.php
Normal file
@@ -0,0 +1,88 @@
|
||||
<?php
|
||||
|
||||
require 'smarty/Smarty.class.php';
|
||||
|
||||
class HandBrakeCluster_Main {
|
||||
|
||||
private static $instance;
|
||||
|
||||
private $smarty;
|
||||
private $config;
|
||||
private $database;
|
||||
private $log;
|
||||
private $request;
|
||||
|
||||
private function __construct() {
|
||||
$this->smarty = new Smarty();
|
||||
|
||||
$this->smarty->template_dir = './templates';
|
||||
$this->smarty->compile_dir = './tmp/templates';
|
||||
$this->smarty->cache_dir = './tmp/cache';
|
||||
$this->smarty->config_fir = './config';
|
||||
|
||||
$this->smarty->assign('version', '0.1');
|
||||
$this->smarty->assign('base_uri', '/handbrake/');
|
||||
|
||||
$request_string = isset($_GET['l']) ? $_GET['l'] : '';
|
||||
$this->request = new HandBrakeCluster_RequestParser($request_string);
|
||||
}
|
||||
|
||||
public static function instance() {
|
||||
if (!self::$instance) {
|
||||
self::$instance = new HandBrakeCluster_Main();
|
||||
}
|
||||
|
||||
return self::$instance;
|
||||
}
|
||||
|
||||
public function smarty() {
|
||||
return $this->smarty;
|
||||
}
|
||||
|
||||
public function config() {
|
||||
return $this->config;
|
||||
}
|
||||
|
||||
public function database() {
|
||||
return $this->database;
|
||||
}
|
||||
|
||||
public function log() {
|
||||
return $this->log;
|
||||
}
|
||||
|
||||
public function request() {
|
||||
return $this->request;
|
||||
}
|
||||
|
||||
public static function initialise() {
|
||||
spl_autoload_register(array('HandBrakeCluster_Main','autoload'));
|
||||
}
|
||||
|
||||
public static function autoload($classname) {
|
||||
// Ensure the classname contains only valid class name characters
|
||||
if (!preg_match('/^[A-Z][a-zA-Z0-9_]*$/', $classname)) {
|
||||
throw new Exception('Illegal characters in classname'); // TODO Subclass this exception
|
||||
}
|
||||
|
||||
// Ensure the class to load begins with our prefix
|
||||
if (!preg_match('/^HandBrakeCluster_/', $classname)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Replace any underscores with directory separators
|
||||
$filename = preg_replace('/_/', '/', $classname);
|
||||
|
||||
// Tack on the class file suffix
|
||||
$filename .= '.class.php';
|
||||
|
||||
// If this file exists, load it
|
||||
if (file_exists($filename)) {
|
||||
require_once $filename;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
HandBrakeCluster_Main::initialise();
|
||||
|
||||
?>
|
||||
41
HandBrakeCluster/Page.class.php
Normal file
41
HandBrakeCluster/Page.class.php
Normal file
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
class HandBrakeCluster_Page {
|
||||
|
||||
private $smarty;
|
||||
private $request;
|
||||
|
||||
private $page;
|
||||
|
||||
public function __construct(Smarty $smarty, HandBrakeCluster_RequestParser $request) {
|
||||
$this->smarty = $smarty;
|
||||
$this->request = $request;
|
||||
$this->page = $request->page();
|
||||
}
|
||||
|
||||
public function page() {
|
||||
return $this->page;
|
||||
}
|
||||
|
||||
public function template_filename() {
|
||||
$template_filename = $this->page() . '.tpl';
|
||||
|
||||
if (!$this->smarty->template_exists($template_filename)) {
|
||||
$template_filename = 'home.tpl';
|
||||
}
|
||||
|
||||
return $template_filename;
|
||||
}
|
||||
|
||||
public function evaluate() {
|
||||
$code_filename = 'pages/' . $this->page() . '.php';
|
||||
if (!file_exists($code_filename)) {
|
||||
throw Exception('Template code file does not exist!');
|
||||
}
|
||||
eval("include '$code_filename';");
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
?>
|
||||
44
HandBrakeCluster/RequestParser.class.php
Normal file
44
HandBrakeCluster/RequestParser.class.php
Normal file
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
class HandBrakeCluster_RequestParser {
|
||||
|
||||
private $request_string;
|
||||
private $page = 'home';
|
||||
private $vars = array();
|
||||
|
||||
public function __construct($request_string) {
|
||||
$this->request_string = $request_string;
|
||||
|
||||
$this->parse();
|
||||
}
|
||||
|
||||
public function parse() {
|
||||
$components = explode('/', $this->request_string);
|
||||
|
||||
if (!$components) {
|
||||
return;
|
||||
}
|
||||
|
||||
// The first token is the page to execute
|
||||
$this->page = array_shift($components);
|
||||
|
||||
// The subsequent tokens are parameters for this page in key value pairs
|
||||
while ($components) {
|
||||
$this->vars[array_shift($components)] = $components ? array_shift($components) : null;
|
||||
}
|
||||
}
|
||||
|
||||
public function page() {
|
||||
return $this->page;
|
||||
}
|
||||
|
||||
public function get($key) {
|
||||
if (isset($this->vars[$key])) {
|
||||
return $this->vars[$key];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
?>
|
||||
Reference in New Issue
Block a user