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:
10
.htaccess.dist
Normal file
10
.htaccess.dist
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
<IfModule mod_rewrite.c>
|
||||||
|
|
||||||
|
RewriteEngine on
|
||||||
|
RewriteBase /
|
||||||
|
|
||||||
|
RewriteCond %{REQUEST_FILENAME} !-f
|
||||||
|
RewriteCond %{REQUEST_FILENAME} !-d
|
||||||
|
RewriteRule ^(.*)$ index.php?l=$1
|
||||||
|
|
||||||
|
</IfModule>
|
||||||
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
?>
|
||||||
@@ -1,86 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
?><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<title>Current HandBrake Ripping Jobs</title>
|
|
||||||
<script lang="javascript">
|
|
||||||
|
|
||||||
</script>
|
|
||||||
<style>
|
|
||||||
body {
|
|
||||||
font-family: verdana, helvetica, sans-serif;
|
|
||||||
}
|
|
||||||
|
|
||||||
a {
|
|
||||||
color: gray;
|
|
||||||
}
|
|
||||||
|
|
||||||
label {
|
|
||||||
margin-left: 1em;
|
|
||||||
margin-right: 1em;
|
|
||||||
}
|
|
||||||
|
|
||||||
table {
|
|
||||||
border-collapse: collapse;
|
|
||||||
}
|
|
||||||
|
|
||||||
tr {
|
|
||||||
border: 1px dashed darkGray;
|
|
||||||
}
|
|
||||||
|
|
||||||
tr:hover {
|
|
||||||
background-color: lightBlue;
|
|
||||||
}
|
|
||||||
|
|
||||||
#errors {
|
|
||||||
border: 1px solid firebrick;
|
|
||||||
background: peachpuff;
|
|
||||||
color: darkred;
|
|
||||||
margin: 1em;
|
|
||||||
}
|
|
||||||
|
|
||||||
#messages {
|
|
||||||
border: 1px solid cornflowerblue;
|
|
||||||
background: lightcyan;
|
|
||||||
color: darkblue;
|
|
||||||
margin: 1em;
|
|
||||||
}
|
|
||||||
|
|
||||||
.default {
|
|
||||||
background: beige;
|
|
||||||
color: darkgray;
|
|
||||||
font-style: italic;
|
|
||||||
}
|
|
||||||
|
|
||||||
.icon {
|
|
||||||
height: 16px;
|
|
||||||
width: 16px;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<h1>Current HandBrake Ripping Jobs</h1>
|
|
||||||
|
|
||||||
<?php if ($errors) { ?>
|
|
||||||
<div id="errors">
|
|
||||||
<ul>
|
|
||||||
<?php foreach ($errors as $error) { ?>
|
|
||||||
<li><?php echo htmlspecialchars($error); ?></li>
|
|
||||||
<?php } ?>
|
|
||||||
</ul>
|
|
||||||
</div>
|
|
||||||
<?php } ?>
|
|
||||||
<?php if ($messages) { ?>
|
|
||||||
<div id="messages">
|
|
||||||
<ul>
|
|
||||||
<?php foreach ($messages as $message) { ?>
|
|
||||||
<li><?php echo htmlspecialchars($message); ?></li>
|
|
||||||
<?php } ?>
|
|
||||||
</ul>
|
|
||||||
</div>
|
|
||||||
<?php } ?>
|
|
||||||
|
|
||||||
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
14
index.php
Normal file
14
index.php
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
require 'HandBrakeCluster/Main.class.php';
|
||||||
|
$main = HandBrakeCluster_Main::instance();
|
||||||
|
$smarty = $main->smarty();
|
||||||
|
|
||||||
|
$page = new HandBrakeCluster_Page($smarty, $main->request());
|
||||||
|
$page->evaluate();
|
||||||
|
|
||||||
|
$smarty->assign('page_content', $smarty->fetch($page->template_filename()));
|
||||||
|
|
||||||
|
$smarty->display('index.tpl');
|
||||||
|
|
||||||
|
?>
|
||||||
11
pages/home.php
Normal file
11
pages/home.php
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
$running_jobs = array();
|
||||||
|
$completed_jobs = array();
|
||||||
|
|
||||||
|
$running_jobs[] = new HandBrakeCluster_Job();
|
||||||
|
|
||||||
|
$this->smarty->assign('running_jobs', $running_jobs);
|
||||||
|
$this->smarty->assign('completed_jobs;', $completed_jobs);
|
||||||
|
|
||||||
|
?>
|
||||||
0
pages/job-details.php
Normal file
0
pages/job-details.php
Normal file
0
pages/jobs.php
Normal file
0
pages/jobs.php
Normal file
0
pages/logs.php
Normal file
0
pages/logs.php
Normal file
116
styles/normal.css
Normal file
116
styles/normal.css
Normal file
@@ -0,0 +1,116 @@
|
|||||||
|
body {
|
||||||
|
margin: 0em;
|
||||||
|
padding: 0em;
|
||||||
|
background: #a7a09a;
|
||||||
|
font-family: verdana, helvetica, sans-serif;
|
||||||
|
}
|
||||||
|
|
||||||
|
a {
|
||||||
|
color: gray;
|
||||||
|
}
|
||||||
|
|
||||||
|
label {
|
||||||
|
margin-left: 1em;
|
||||||
|
margin-right: 1em;
|
||||||
|
}
|
||||||
|
|
||||||
|
table {
|
||||||
|
}
|
||||||
|
|
||||||
|
tr {
|
||||||
|
}
|
||||||
|
|
||||||
|
tr:hover {
|
||||||
|
background-color: lightBlue;
|
||||||
|
}
|
||||||
|
|
||||||
|
#container {
|
||||||
|
width: 75%;
|
||||||
|
min-width: 75em;
|
||||||
|
margin: auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
#banner {
|
||||||
|
margin: 0em;
|
||||||
|
padding: 0em;
|
||||||
|
background: #eeeeee;
|
||||||
|
}
|
||||||
|
|
||||||
|
#banner h1 {
|
||||||
|
padding: 0.5em;
|
||||||
|
}
|
||||||
|
|
||||||
|
#navigation {
|
||||||
|
background: #eeeeee;
|
||||||
|
margin-top: 0em;
|
||||||
|
margin-bottom: 1em;
|
||||||
|
padding: 0.2em;
|
||||||
|
}
|
||||||
|
|
||||||
|
#navigation ul {
|
||||||
|
margin: 0em;
|
||||||
|
padding: 0em 5em;;
|
||||||
|
list-style: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
#navigation li {
|
||||||
|
margin: 1em;
|
||||||
|
padding: 0em;
|
||||||
|
display: inline;
|
||||||
|
}
|
||||||
|
|
||||||
|
#page-container {
|
||||||
|
margin: 0em;
|
||||||
|
padding: 0em;
|
||||||
|
}
|
||||||
|
|
||||||
|
#sidebar {
|
||||||
|
float: left;
|
||||||
|
width: 20em;
|
||||||
|
margin-bottom: 1em;
|
||||||
|
|
||||||
|
background: #eeeeee;
|
||||||
|
}
|
||||||
|
|
||||||
|
#page {
|
||||||
|
margin-left: 21em;
|
||||||
|
margin-bottom: 1em;
|
||||||
|
padding: 0.5em;
|
||||||
|
|
||||||
|
background: #eeeeee;
|
||||||
|
}
|
||||||
|
|
||||||
|
#footer {
|
||||||
|
clear: both;
|
||||||
|
padding: 2em;
|
||||||
|
font-size: smaller;
|
||||||
|
font-style: italic;
|
||||||
|
|
||||||
|
background: #eeeeee;
|
||||||
|
color: #333333;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#errors {
|
||||||
|
background: peachpuff;
|
||||||
|
color: darkred;
|
||||||
|
margin: 1em;
|
||||||
|
}
|
||||||
|
|
||||||
|
#messages {
|
||||||
|
background: lightcyan;
|
||||||
|
color: darkblue;
|
||||||
|
margin: 1em;
|
||||||
|
}
|
||||||
|
|
||||||
|
.default {
|
||||||
|
background: beige;
|
||||||
|
color: darkgray;
|
||||||
|
font-style: italic;
|
||||||
|
}
|
||||||
|
|
||||||
|
.icon {
|
||||||
|
height: 16px;
|
||||||
|
width: 16px;
|
||||||
|
}
|
||||||
|
|
||||||
24
templates/home.tpl
Normal file
24
templates/home.tpl
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
<h2>Summary</h2>
|
||||||
|
|
||||||
|
<h3>Running Jobs</h3>
|
||||||
|
|
||||||
|
{if $running_jobs}
|
||||||
|
{foreach from=$running_jobs item=job}
|
||||||
|
<li><a href="{$base_uri}job-details/id/{$job->id()}" title="View job details">Job {$job->id()}</a></li>
|
||||||
|
{/foreach}
|
||||||
|
{else}
|
||||||
|
<em>There are no currently running jobs.</em>
|
||||||
|
{/if}
|
||||||
|
|
||||||
|
<h3>Completed Jobs</h3>
|
||||||
|
|
||||||
|
{if $completed_jobs}
|
||||||
|
<ul>
|
||||||
|
{foreach from=$completed_jobs item=job}
|
||||||
|
<li><a href="{$base_uri}job-details/id/{$job->id()}" title="View job details">Job {$job->id()}</a></li>
|
||||||
|
{/foreach}
|
||||||
|
</ul>
|
||||||
|
{else}
|
||||||
|
<em>There are no recently completed jobs.</em>
|
||||||
|
{/if}
|
||||||
|
|
||||||
50
templates/index.tpl
Normal file
50
templates/index.tpl
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>HandBrake Cluster WebUI</title>
|
||||||
|
<script lang="javascript">
|
||||||
|
</script>
|
||||||
|
<link rel="stylesheet" type="text/css" href="{$base_uri}styles/normal.css" />
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
|
||||||
|
<div id="container">
|
||||||
|
|
||||||
|
<div id="banner">
|
||||||
|
<h1>HandBrake Cluster WebUI</h1>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div id="navigation">
|
||||||
|
{include file=navigation.tpl}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div id="page-container">
|
||||||
|
|
||||||
|
<div id="sidebar">
|
||||||
|
{include file=sidebar.tpl}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div id="page">
|
||||||
|
|
||||||
|
{if $messages}
|
||||||
|
<div id="messages">
|
||||||
|
{foreach from=$messages item=message}
|
||||||
|
{$message}
|
||||||
|
{/foreach}
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
|
|
||||||
|
{$page_content}
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div id="footer">
|
||||||
|
Powered by HandBrakeCluster WebUI {$version}. Written by Ben Roberts.
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
1
templates/job-details.tpl
Normal file
1
templates/job-details.tpl
Normal file
@@ -0,0 +1 @@
|
|||||||
|
Job details...
|
||||||
1
templates/jobs.tpl
Normal file
1
templates/jobs.tpl
Normal file
@@ -0,0 +1 @@
|
|||||||
|
Jobs
|
||||||
1
templates/logs.tpl
Normal file
1
templates/logs.tpl
Normal file
@@ -0,0 +1 @@
|
|||||||
|
Logs...
|
||||||
5
templates/navigation.tpl
Normal file
5
templates/navigation.tpl
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
<ul>
|
||||||
|
<li><a href="{$base_uri}home/" title="Home">Home</a></li>
|
||||||
|
<li><a href="{$base_uri}jobs/" title="Jobs">Jobs</a></li>
|
||||||
|
<li><a href="{$base_uri}logs/" title="Logs">Logs</a></li>
|
||||||
|
</ul>
|
||||||
5
templates/sidebar.tpl
Normal file
5
templates/sidebar.tpl
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
<ul>
|
||||||
|
<li><a href="{$base_uri}home/" title="Home">Home</a></li>
|
||||||
|
<li><a href="{$base_uri}jobs/" title="Jobs">Jobs</a></li>
|
||||||
|
<li><a href="{$base_uri}logs/" title="Logs">Logs</a></li>
|
||||||
|
</ul>
|
||||||
0
tmp/cache/.gitignore
vendored
Normal file
0
tmp/cache/.gitignore
vendored
Normal file
0
tmp/templates/.gitignore
vendored
Normal file
0
tmp/templates/.gitignore
vendored
Normal file
Reference in New Issue
Block a user