Initial commit.

This is to be the new HashRU website based on the Aaronweb.net/Kabuki CMS.
This commit is contained in:
2016-09-01 23:13:23 +02:00
commit ab0e4efbcb
68 changed files with 8054 additions and 0 deletions

36
templates/AdminBar.php Normal file
View File

@@ -0,0 +1,36 @@
<?php
/*****************************************************************************
* AdminBar.php
* Defines the AdminBar class.
*
* Kabuki CMS (C) 2013-2015, Aaron van Geffen
*****************************************************************************/
class AdminBar extends SubTemplate
{
private $extra_items = [];
protected function html_content()
{
echo '
<div id="admin_bar">
<ul>
<li><a href="', BASEURL, '/managetags/">Tags</a></li>
<li><a href="', BASEURL, '/manageusers/">Users</a></li>
<li><a href="', BASEURL, '/manageerrors/">Errors [', ErrorLog::getCount(), ']</a></li>';
foreach ($this->extra_items as $item)
echo '
<li><a href="', $item[0], '">', $item[1], '</a></li>';
echo '
<li><a href="', BASEURL, '/logout/">Log out [', Registry::get('user')->getFullName(), ']</a></li>
</ul>
</div>';
}
public function appendItem($url, $caption)
{
$this->extra_items[] = [$url, $caption];
}
}

71
templates/AlbumIndex.php Normal file
View File

@@ -0,0 +1,71 @@
<?php
/*****************************************************************************
* AlbumIndex.php
* Contains the album index template.
*
* Kabuki CMS (C) 2013-2015, Aaron van Geffen
*****************************************************************************/
class AlbumIndex extends SubTemplate
{
protected $albums;
protected $show_edit_buttons;
protected $show_labels;
protected $row_limit = 1000;
const TILE_WIDTH = 400;
const TILE_HEIGHT = 267;
public function __construct(array $albums, $show_edit_buttons = false, $show_labels = true)
{
$this->albums = $albums;
$this->show_edit_buttons = $show_edit_buttons;
$this->show_labels = $show_labels;
}
protected function html_content()
{
echo '
<div class="tiled_grid">';
foreach (array_chunk($this->albums, 3) as $photos)
{
echo '
<div class="tiled_row">';
foreach ($photos as $album)
{
echo '
<div class="landscape">';
if ($this->show_edit_buttons)
echo '
<a class="edit" href="#">Edit</a>';
echo '
<a href="', $album['link'], '">';
if (isset($album['thumbnail']))
echo '
<img src="', $album['thumbnail']->getThumbnailUrl(static::TILE_WIDTH, static::TILE_HEIGHT, true, true), '" alt="">';
else
echo '
<img src="', BASEURL, '/images/nothumb.png" alt="">';
if ($this->show_labels)
echo '
<h4>', $album['caption'], '</h4>';
echo '
</a>
</div>';
}
echo '
</div>';
}
echo '
</div>';
}
}

31
templates/DummyBox.php Normal file
View File

@@ -0,0 +1,31 @@
<?php
/*****************************************************************************
* DummyBox.php
* Defines the key template DummyBox.
*
* Kabuki CMS (C) 2013-2015, Aaron van Geffen
*****************************************************************************/
class DummyBox extends SubTemplate
{
public function __construct($title = '', $content = '', $class = '')
{
$this->_title = $title;
$this->_content = $content;
$this->_class = $class;
}
protected function html_content()
{
echo '
<div class="boxed_content', $this->_class ? ' ' . $this->_class : '', '">', $this->_title ? '
<h2>' . $this->_title . '</h2>' : '', '
', $this->_content;
foreach ($this->_subtemplates as $template)
$template->html_main();
echo '
</div>';
}
}

292
templates/EditAssetForm.php Normal file
View File

@@ -0,0 +1,292 @@
<?php
/*****************************************************************************
* EditAssetForm.php
* Contains the edit asset template.
*
* Kabuki CMS (C) 2013-2015, Aaron van Geffen
*****************************************************************************/
class EditAssetForm extends SubTemplate
{
private $asset;
private $thumbs;
public function __construct(Asset $asset, array $thumbs = [])
{
$this->asset = $asset;
$this->thumbs = $thumbs;
}
protected function html_content()
{
echo '
<form id="asset_form" action="" method="post" enctype="multipart/form-data">
<div class="boxed_content" style="margin-bottom: 2%">
<div style="float: right">
<a class="btn btn-red" href="', BASEURL, '/editasset/?id=', $this->asset->getId(), '&delete">Delete asset</a>
<input type="submit" value="Save asset data">
</div>
<h2>Edit asset \'', $this->asset->getTitle(), '\' (', $this->asset->getFilename(), ')</h2>
</div>';
$this->section_replace();
echo '
<div style="float: left; width: 60%; margin-right: 2%">';
$this->section_key_info();
$this->section_asset_meta();
echo '
</div>
<div style="float: left; width: 38%;">';
if (!empty($this->thumbs))
$this->section_thumbnails();
$this->section_linked_tags();
echo '
</div>';
$this->section_crop_editor();
echo '
</form>';
}
protected function section_key_info()
{
$date_captured = $this->asset->getDateCaptured();
echo '
<div class="widget key_info">
<h3>Key info</h3>
<dl>
<dt>Title</dt>
<dd><input type="text" name="title" maxlength="255" size="70" value="', $this->asset->getTitle(), '">
<dt>Date captured</dt>
<dd><input type="text" name="date_captured" size="30" value="',
$date_captured ? $date_captured->format('Y-m-d H:i:s') : '', '" placeholder="Y-m-d H:i:s">
<dt>Display priority</dt>
<dd><input type="number" name="priority" min="0" max="100" step="1" value="', $this->asset->getPriority(), '">
</dl>
</div>';
}
protected function section_linked_tags()
{
echo '
<div class="widget linked_tags" style="margin-top: 2%">
<h3>Linked tags</h3>
<ul id="tag_list">';
foreach ($this->asset->getTags() as $tag)
echo '
<li>
<input class="tag_check" type="checkbox" name="tag[', $tag->id_tag, ']" id="linked_tag_', $tag->id_tag, '" title="Uncheck to delete" checked>
', $tag->tag, '
</li>';
echo '
<li id="new_tag_container"><input type="text" id="new_tag" placeholder="Type to link a new tag"></li>
</ul>
</div>
<script type="text/javascript" src="', BASEURL, '/js/ajax.js"></script>
<script type="text/javascript" src="', BASEURL, '/js/autosuggest.js"></script>
<script type="text/javascript">
setTimeout(function() {
var tag_autosuggest = new TagAutoSuggest({
inputElement: "new_tag",
listElement: "tag_list",
baseUrl: "', BASEURL, '",
appendCallback: function(item) {
if (document.getElementById("linked_tag_" + item.id_tag)) {
return;
}
var newCheck = document.createElement("input");
newCheck.type = "checkbox";
newCheck.name = "tag[" + item.id_tag + "]";
newCheck.id = "linked_tag_" + item.id_tag;
newCheck.title = "Uncheck to delete";
newCheck.checked = "checked";
var newNode = document.createElement("li");
newNode.appendChild(newCheck);
var newLabel = document.createTextNode(item.label);
newNode.appendChild(newLabel);
var list = document.getElementById("tag_list");
var input = document.getElementById("new_tag_container");
list.insertBefore(newNode, input);
}
});
}, 100);
</script>';
}
protected function section_thumbnails()
{
echo '
<div class="widget linked_thumbs">
<h3>Thumbnails</h3>
View: <select id="thumbnail_src">';
foreach ($this->thumbs as $thumb)
{
if (!$thumb['status'])
continue;
echo '
<option data-url="', $thumb['url'], '" data-crop_width="', $thumb['dimensions'][0], '" data-crop_height="', $thumb['dimensions'][1], '"',
isset($thumb['crop_method']) ? ' data-crop_method="' . $thumb['crop_method'] . '"' : '',
isset($thumb['crop_region']) ? ' data-crop_region="' . $thumb['crop_region'] . '"' : '', '>
', implode('x', $thumb['dimensions']);
if ($thumb['cropped'])
{
echo ' (';
switch ($thumb['crop_method'])
{
case 'b': echo 'bottom'; break;
case 'e': echo 'exact'; break;
case 's': echo 'slice'; break;
case 't': echo 'top'; break;
default: echo 'centre'; break;
}
echo ' crop)';
}
elseif ($thumb['custom_image'])
echo ' (custom)';
echo '
</option>';
}
echo '
</select>
<a id="thumbnail_link" href="', $this->thumbs[0]['url'], '" target="_blank">
<img id="thumbnail" src="', $this->thumbs[0]['url'], '" alt="Thumbnail" style="width: 100%; height: auto;">
</a>
</div>
<script type="text/javascript">
setTimeout(function() {
document.getElementById("thumbnail_src").addEventListener("change", function(event) {
var selection = event.target.options[event.target.selectedIndex];
document.getElementById("thumbnail_link").href = selection.dataset.url;
document.getElementById("thumbnail").src = selection.dataset.url;
});
}, 100);
</script>';
}
protected function section_crop_editor()
{
if (!$this->asset->isImage())
return;
echo '
<script type="text/javascript" src="', BASEURL, '/js/crop_editor.js"></script>
<script type="text/javascript">
setTimeout(function() {
var editor = new CropEditor({
original_image_src: "', $this->asset->getUrl(), '",
editor_container_parent_id: "asset_form",
thumbnail_select_id: "thumbnail_src",
drag_target: "drag_target",
asset_id: ', $this->asset->getId(), ',
after_save: function(data) {
// Update thumbnail
document.getElementById("thumbnail").src = data.url + "?" + (new Date()).getTime();
// Update select
var src = document.getElementById("thumbnail_src");
src.options[src.selectedIndex].dataset.crop_region = data.value;
// TODO: update meta
}
});
}, 100);
</script>';
}
protected function section_asset_meta()
{
echo '
<div class="widget asset_meta" style="margin-top: 2%">
<h3>Asset meta data</h3>
<ul>';
$i = -1;
foreach ($this->asset->getMeta() as $key => $meta)
{
$i++;
echo '
<li>
<input type="text" name="meta_key[', $i, ']" value="', htmlentities($key), '">
<input type="text" name="meta_value[', $i, ']" value="', htmlentities($meta), '">
</li>';
}
echo '
<li>
<input type="text" name="meta_key[', $i + 1, ']" value="">
<input type="text" name="meta_value[', $i + 1, ']" value="">
</li>
</ul>
<p><input type="submit" value="Save metadata"></p>
</div>';
}
protected function section_replace()
{
echo '
<div class="widget replace_asset" style="margin-bottom: 2%; display: block">
<h3>Replace asset</h3>
File: <input type="file" name="replacement">
Target: <select name="replacement_target">
<option value="full">master file</option>';
foreach ($this->thumbs as $thumb)
{
if (!$thumb['status'])
continue;
echo '
<option value="thumb_', implode('x', $thumb['dimensions']);
if ($thumb['cropped'])
echo $thumb['crop_method'] === 'c' ? '_c' : '_c' . $thumb['crop_method'];
echo '">
thumbnail (', implode('x', $thumb['dimensions']);
if ($thumb['cropped'])
{
echo ', ';
switch ($thumb['crop_method'])
{
case 'b': echo 'bottom'; break;
case 'e': echo 'exact'; break;
case 's': echo 'slice'; break;
case 't': echo 'top'; break;
default: echo 'centre'; break;
}
echo ' crop';
}
elseif ($thumb['custom_image'])
echo ' (custom)';
echo ')
</option>';
}
echo '
</select>
<input type="submit" value="Save asset">
</div>';
}
}

161
templates/FormView.php Normal file
View File

@@ -0,0 +1,161 @@
<?php
/*****************************************************************************
* FormView.php
* Contains the form template.
*
* Kabuki CMS (C) 2013-2015, Aaron van Geffen
*****************************************************************************/
class FormView extends SubTemplate
{
public function __construct(Form $form, $title = '')
{
$this->title = $title;
$this->request_url = $form->request_url;
$this->request_method = $form->request_method;
$this->fields = $form->getFields();
$this->missing = $form->getMissing();
$this->data = $form->getData();
$this->content_above = $form->content_above;
$this->content_below = $form->content_below;
}
protected function html_content($exclude = [], $include = [])
{
if (!empty($this->title))
echo '
<div id="journal_title">
<h3>', $this->title, '</h3>
</div>
<div id="inner">';
foreach ($this->_subtemplates as $template)
$template->html_main();
echo '
<form action="', $this->request_url, '" method="', $this->request_method, '" enctype="multipart/form-data">';
if (isset($this->content_above))
echo $this->content_above;
echo '
<dl>';
foreach ($this->fields as $field_id => $field)
{
// Either we have a blacklist
if (!empty($exclude) && in_array($field_id, $exclude))
continue;
// ... or a whitelist
elseif (!empty($include) && !in_array($field_id, $include))
continue;
// ... or neither (ha)
$this->renderField($field_id, $field);
}
echo '
</dl>
<input type="hidden" name="', Session::getSessionTokenKey(), '" value="', Session::getSessionToken(), '">
<div style="clear: both">
<button type="submit" class="btn btn-primary">Save information</button>';
if (isset($this->content_below))
echo '
', $this->content_below;
echo '
</div>
</form>';
if (!empty($this->title))
echo '
</div>';
}
protected function renderField($field_id, $field)
{
if (isset($field['before_html']))
echo '</dl>
', $field['before_html'], '
<dl>';
if ($field['type'] != 'checkbox' && isset($field['label']))
echo '
<dt class="cont_', $field_id, isset($field['tab_class']) ? ' target target-' . $field['tab_class'] : '', '"', in_array($field_id, $this->missing) ? ' style="color: red"' : '', '>', $field['label'], '</dt>';
elseif ($field['type'] == 'checkbox' && isset($field['header']))
echo '
<dt class="cont_', $field_id, isset($field['tab_class']) ? ' target target-' . $field['tab_class'] : '', '"', in_array($field_id, $this->missing) ? ' style="color: red"' : '', '>', $field['header'], '</dt>';
echo '
<dd class="cont_', $field_id, isset($field['dd_class']) ? ' ' . $field['dd_class'] : '', isset($field['tab_class']) ? ' target target-' . $field['tab_class'] : '', '">';
if (isset($field['before']))
echo $field['before'];
switch ($field['type'])
{
case 'select':
echo '
<select name="', $field_id, '" id="', $field_id, '"', !empty($field['disabled']) ? ' disabled' : '', '>';
if (isset($field['placeholder']))
echo '
<option value="">', $field['placeholder'], '</option>';
foreach ($field['options'] as $value => $option)
echo '
<option value="', $value, '"', $this->data[$field_id] == $value ? ' selected' : '', '>', htmlentities($option), '</option>';
echo '
</select>';
break;
case 'radio':
foreach ($field['options'] as $value => $option)
echo '
<input type="radio" name="', $field_id, '" value="', $value, '"', $this->data[$field_id] == $value ? ' checked' : '', !empty($field['disabled']) ? ' disabled' : '', '> ', htmlentities($option);
break;
case 'checkbox':
echo '
<label><input type="checkbox"', $this->data[$field_id] ? ' checked' : '', !empty($field['disabled']) ? ' disabled' : '', ' name="', $field_id, '"> ', htmlentities($field['label']), '</label>';
break;
case 'textarea':
echo '
<textarea name="', $field_id, '" id="', $field_id, '" cols="', isset($field['columns']) ? $field['columns'] : 40, '" rows="', isset($field['rows']) ? $field['rows'] : 4, '"', !empty($field['disabled']) ? ' disabled' : '', '>', $this->data[$field_id], '</textarea>';
break;
case 'color':
echo '
<input type="color" name="', $field_id, '" id="', $field_id, '" value="', htmlentities($this->data[$field_id]), '"', !empty($field['disabled']) ? ' disabled' : '', '>';
break;
case 'numeric':
echo '
<input type="number"', isset($field['step']) ? ' step="' . $field['step'] . '"' : '', '" min="', isset($field['min_value']) ? $field['min_value'] : '0', '" max="', isset($field['max_value']) ? $field['max_value'] : '9999', '" name="', $field_id, '" id="', $field_id, '"', isset($field['size']) ? ' size="' . $field['size'] . '"' : '', isset($field['maxlength']) ? ' maxlength="' . $field['maxlength'] . '"' : '', ' value="', htmlentities($this->data[$field_id]), '"', !empty($field['disabled']) ? ' disabled' : '', '>';
break;
case 'file':
if (!empty($this->data[$field_id]))
echo '<img src="', $this->data[$field_id], '" alt=""><br>';
echo '
<input type="file" name="', $field_id, '" id="', $field_id, '"', !empty($field['disabled']) ? ' disabled' : '', '>';
break;
case 'text':
case 'password':
default:
echo '
<input type="', $field['type'], '" name="', $field_id, '" id="', $field_id, '"', isset($field['size']) ? ' size="' . $field['size'] . '"' : '', isset($field['maxlength']) ? ' maxlength="' . $field['maxlength'] . '"' : '', ' value="', htmlentities($this->data[$field_id]), '"', !empty($field['disabled']) ? ' disabled' : '', isset($field['trigger']) ? ' class="trigger-' . $field['trigger'] . '"' : '', '>';
}
if (isset($field['after']))
echo ' ', $field['after'];
echo '
</dd>';
}
}

60
templates/LogInForm.php Normal file
View File

@@ -0,0 +1,60 @@
<?php
/*****************************************************************************
* LogInForm.php
* Contains the login form template.
*
* Kabuki CMS (C) 2013-2015, Aaron van Geffen
*****************************************************************************/
class LogInForm extends SubTemplate
{
private $error_message = '';
private $redirect_url = '';
private $emailaddress = '';
public function setErrorMessage($message)
{
$this->error_message = $message;
}
public function setRedirectUrl($url)
{
$_SESSION['login_url'] = $url;
$this->redirect_url = $url;
}
public function setEmail($addr)
{
$this->emailaddress = htmlentities($addr);
}
protected function html_content()
{
echo '
<form action="', BASEURL, '/login/" method="post" id="login">
<h3>Admin login</h3>';
// Invalid login? Show a message.
if (!empty($this->error_message))
echo '
<p style="color: red">', $this->error_message, '</p>';
echo '
<dl>
<dt><label for="field_emailaddress">E-mail address:</label></dt>
<dd><input type="text" id="field_emailaddress" name="emailaddress" tabindex="1" value="', $this->emailaddress, '" autofocus></dd>
<dt><label for="field_password">Password:</label></dt>
<dd><input type="password" id="field_password" name="password" tabindex="2"></dd>
</dl>';
// Throw in a redirect url if asked for.
if (!empty($this->redirect_url))
echo '
<input type="hidden" name="redirect_url" value="', base64_encode($this->redirect_url), '">';
echo '
<div><button type="submit" class="btn btn-primary" id="field_login" name="login" tabindex="3">Log in</button></div>
</form>';
}
}

115
templates/MainTemplate.php Normal file
View File

@@ -0,0 +1,115 @@
<?php
/*****************************************************************************
* MainTemplate.php
* Defines the key template MainTemplate.
*
* Kabuki CMS (C) 2013-2015, Aaron van Geffen
*****************************************************************************/
class MainTemplate extends Template
{
private $title = '';
private $classes = [];
private $area;
private $css = '';
private $header_html = '';
private $canonical_url = '';
public function __construct($title = '')
{
$this->title = $title;
}
public function html_main()
{
echo '<!DOCTYPE html>
<html lang="en">
<head>
<title>', $this->title, '</title>', !empty($this->canonical_url) ? '
<link rel="canonical" href="' . $this->canonical_url . '">' : '', '
<link type="text/css" rel="stylesheet" href="', BASEURL, '/css/default.css">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">', !empty($this->css) ? '
<style type="text/css">' . $this->css . '
</style>' : '', $this->header_html, '
</head>
<body', !empty($this->classes) ? ' class="' . implode(' ', $this->classes) . '"' : '', '>
<header>
<h1 id="logo"><a href="', BASEURL, '/">#pics</a></h1>
<ul id="nav">
<li><a href="', BASEURL, '/">albums</a></li>
<li><a href="', BASEURL, '/people/">people</a></li>
<li><a href="', BASEURL, '/timeline/">timeline</a></li>
</ul>
</header>
<div id="wrapper">';
foreach ($this->_subtemplates as $template)
$template->html_main();
echo '
<footer>';
if (Registry::has('user') && Registry::get('user')->isAdmin())
{
if (class_exists('Cache'))
echo '
<span class="cache-info">Cache info: ', Cache::$hits, ' hits, ', Cache::$misses, ' misses, ', Cache::$puts, ' puts, ', Cache::$removals, ' removals</span>';
if (Registry::has('start'))
echo '<br>
<span class="creation-time">Page creation time: ', sprintf('%1.4f', microtime(true) - Registry::get('start')), ' seconds</span>';
if (Registry::has('db'))
echo '<br>
<span class="query-count">Database interaction: ', Registry::get('db')->getQueryCount(), ' queries</span>';
}
else
echo '
<span class="vanity">Powered by <a href="https://aaronweb.net/projects/kabuki/">Kabuki CMS</a> | <a href="', BASEURL, '/login/">Admin</a></span>';
echo '
</footer>
</div>';
if (Registry::has('db') && defined("DB_LOG_QUERIES") && DB_LOG_QUERIES)
foreach (Registry::get('db')->getLoggedQueries() as $query)
echo '<pre>', strtr($query, "\t", " "), '</pre>';
echo '
</body>
</html>';
}
public function appendCss($css)
{
$this->css .= $css;
}
public function appendHeaderHtml($html)
{
$this->header_html .= "\n\t\t" . $html;
}
public function appendStylesheet($uri)
{
$this->appendHeaderHtml('<link text="text/css" rel="stylesheet" href="'. $uri . '">');
}
public function setCanonicalUrl($url)
{
$this->canonical_url = $url;
}
public function addClass($class)
{
if (!in_array($class, $this->classes))
$this->classes[] = $class;
}
public function removeClass($class)
{
if ($key = array_search($class, $this->classes) !== false)
unset($this->classes[$key]);
}
}

View File

@@ -0,0 +1,77 @@
<?php
/*****************************************************************************
* MediaUploader.php
* Contains the media uploading template.
*
* Kabuki CMS (C) 2013-2015, Aaron van Geffen
*****************************************************************************/
class MediaUploader extends SubTemplate
{
protected function html_content()
{
echo '
<form action="" class="admin_box" method="post" enctype="multipart/form-data">
<h2>Upload new media</h2>
<div>
<h3>Select files</h3>
<ul>
<li>
<input type="file" name="new_asset[0]"><br>
<input type="text" name="title[0]" placeholder="Custom title (optional)" size="50">
</li>
<li>
<input type="file" name="new_asset[1]"><br>
<input type="text" name="title[1]" placeholder="Custom title (optional)" size="50">
</li>
<li>
<input type="file" name="new_asset[2]"><br>
<input type="text" name="title[2]" placeholder="Custom title (optional)" size="50">
</li>
</ul>
</div>
<div>
<h3>Link tags</h3>
<ul id="tag_list">
<li id="new_tag_container"><input type="text" id="new_tag" placeholder="Type to link a new tag"></li>
</ul>
</div>
<script type="text/javascript" src="', BASEURL, '/js/ajax.js"></script>
<script type="text/javascript" src="', BASEURL, '/js/autosuggest.js"></script>
<script type="text/javascript">
setTimeout(function() {
var tag_autosuggest = new TagAutoSuggest({
inputElement: "new_tag",
listElement: "tag_list",
baseUrl: "', BASEURL, '",
appendCallback: function(item) {
if (document.getElementById("linked_tag_" + item.id_tag)) {
return;
}
var newCheck = document.createElement("input");
newCheck.type = "checkbox";
newCheck.name = "tag[" + item.id_tag + "]";
newCheck.id = "linked_tag_" + item.id_tag;
newCheck.title = "Uncheck to delete";
newCheck.checked = "checked";
var newNode = document.createElement("li");
newNode.appendChild(newCheck);
var newLabel = document.createTextNode(item.label);
newNode.appendChild(newLabel);
var list = document.getElementById("tag_list");
var input = document.getElementById("new_tag_container");
list.insertBefore(newNode, input);
}
});
}, 100);
</script>
<div>
<input name="save" type="submit" value="Upload the lot">
</div>
</form>';
}
}

44
templates/Pagination.php Normal file
View File

@@ -0,0 +1,44 @@
<?php
/*****************************************************************************
* Pagination.php
* Contains the pagination template.
*
* Kabuki CMS (C) 2013-2015, Aaron van Geffen
*****************************************************************************/
class Pagination extends SubTemplate
{
private $index;
public function __construct(PageIndex $index)
{
$this->index = $index->getPageIndex();
$this->class = $index->getPageIndexClass();
}
protected function html_content()
{
echo '
<div class="table_pagination', !empty($this->class) ? ' ' . $this->class : '', '">
<ul>
<li class="first"><', !empty($this->index['previous']) ? 'a href="' . $this->index['previous']['href'] . '"' : 'span', '>&laquo; previous</', !empty($this->index['previous']) ? 'a' : 'span', '></li>';
foreach ($this->index as $key => $page)
{
if (!is_numeric($key))
continue;
if (!is_array($page))
echo '
<li class="page-padding"><span>...</span></li>';
else
echo '
<li class="page-number', $page['is_selected'] ? ' active' : '', '"><a href="', $page['href'], '">', $page['index'], '</a></li>';
}
echo '
<li class="last"><', !empty($this->index['next']) ? 'a href="' . $this->index['next']['href'] . '"' : 'span', '>next &raquo;</', !empty($this->index['next']) ? 'a' : 'span', '></li>
</ul>
</div>';
}
}

244
templates/PhotosIndex.php Normal file
View File

@@ -0,0 +1,244 @@
<?php
/*****************************************************************************
* PhotosIndex.php
* Contains the project index template.
*
* Kabuki CMS (C) 2013-2015, Aaron van Geffen
*****************************************************************************/
class PhotosIndex extends SubTemplate
{
protected $mosaic;
protected $show_edit_buttons;
protected $show_labels;
protected $row_limit = 1000;
protected $previous_header = '';
const PANORAMA_WIDTH = 1280;
const PANORAMA_HEIGHT = null;
const PORTRAIT_WIDTH = 400;
const PORTRAIT_HEIGHT = 640;
const LANDSCAPE_WIDTH = 850;
const LANDSCAPE_HEIGHT = 640;
const DUO_WIDTH = 618;
const DUO_HEIGHT = 412;
const SINGLE_WIDTH = 618;
const SINGLE_HEIGHT = 412;
const TILE_WIDTH = 400;
const TILE_HEIGHT = 267;
public function __construct(PhotoMosaic $mosaic, $show_edit_buttons = false, $show_labels = true, $show_headers = true)
{
$this->mosaic = $mosaic;
$this->show_edit_buttons = $show_edit_buttons;
$this->show_headers = $show_headers;
$this->show_labels = $show_labels;
}
protected function html_content()
{
echo '
<div class="tiled_grid">';
for ($i = $this->row_limit; $i > 0 && $row = $this->mosaic->getRow(); $i--)
{
list($photos, $what) = $row;
$this->header($photos);
$this->$what($photos);
}
echo '
</div>';
}
protected function header($photos)
{
if (!$this->show_headers)
return;
$date = $photos[0]->getDateCaptured();
if (!$date)
return;
$header = $date->format('F Y');
if ($header === $this->previous_header)
return;
$name = str_replace(' ', '', strtolower($header));
echo '
<div class="tiled_header" id="', $name, '">
<a href="#', $name, '">', $header, '</a>
</div>';
$this->previous_header = $header;
}
protected function color(Image $image)
{
$color = $image->bestColor();
if ($color == 'FFFFFF')
$color = 'ccc';
return $color;
}
protected function photo(Image $image, $width, $height, $crop = true, $fit = true)
{
if ($this->show_edit_buttons)
echo '
<a class="edit" href="', BASEURL, '/editasset/?id=', $image->getId(), '">Edit</a>';
echo '
<a href="', $image->getUrl(), '">
<img src="', $image->getThumbnailUrl($width, $height, $crop, $fit), '" alt="" title="', $image->getTitle(), '">';
if ($this->show_labels)
echo '
<h4>', $image->getTitle(), '</h4>';
echo '
</a>';
}
protected function panorama(array $photos)
{
foreach ($photos as $image)
{
echo '
<div style="border-color: #', $this->color($image), '" class="panorama">';
$this->photo($image, static::PANORAMA_WIDTH, static::PANORAMA_HEIGHT, false, false);
echo '
</div>';
}
}
protected function portrait(array $photos)
{
$image = array_shift($photos);
echo '
<div class="tiled_row">
<div class="column_portrait">
<div style="border-color: #', $this->color($image), '" class="portrait">';
$this->photo($image, static::PORTRAIT_WIDTH, static::PORTRAIT_HEIGHT, 'top');
echo '
</div>
</div>
<div class="column_tiles_four">';
foreach ($photos as $image)
{
$color = $image->bestColor();
if ($color == 'FFFFFF')
$color = 'ccc';
echo '
<div style="border-color: #', $color, '" class="landscape">';
$this->photo($image, static::TILE_WIDTH, static::TILE_HEIGHT, 'top');
echo '
</div>';
}
echo '
</div>
</div>';
}
protected function landscape(array $photos)
{
$image = array_shift($photos);
echo '
<div class="tiled_row">
<div class="column_landscape">
<div style="border-color: #', $this->color($image), '" class="landscape">';
$this->photo($image, static::LANDSCAPE_WIDTH, static::LANDSCAPE_HEIGHT, 'top');
echo '
</div>
</div>
<div class="column_tiles_two">';
foreach ($photos as $image)
{
echo '
<div style="border-color: #', $this->color($image), '" class="landscape">';
$this->photo($image, static::TILE_WIDTH, static::TILE_HEIGHT, 'top');
echo '
</div>';
}
echo '
</div>
</div>';
}
protected function duo(array $photos)
{
echo '
<div class="tiled_row">';
foreach ($photos as $image)
{
echo '
<div style="border-color: #', $this->color($image), '" class="duo">';
$this->photo($image, static::DUO_WIDTH, static::DUO_HEIGHT, true);
echo '
</div>';
}
echo '
</div>';
}
protected function single(array $photos)
{
$image = array_shift($photos);
echo '
<div class="tiled_row">
<div style="border-color: #', $this->color($image), '" class="single">';
$this->photo($image, static::SINGLE_WIDTH, static::SINGLE_HEIGHT, 'top');
echo '
</div>
</div>';
}
protected function row(array $photos)
{
echo '
<div class="tiled_row">';
foreach ($photos as $image)
{
echo '
<div style="border-color: #', $this->color($image), '" class="landscape">';
$this->photo($image, static::TILE_WIDTH, static::TILE_HEIGHT, true);
echo '
</div>';
}
echo '
</div>';
}
}

17
templates/SubTemplate.php Normal file
View File

@@ -0,0 +1,17 @@
<?php
/*****************************************************************************
* SubTemplate.php
* Defines the key template SubTemplate.
*
* Kabuki CMS (C) 2013-2015, Aaron van Geffen
*****************************************************************************/
abstract class SubTemplate extends Template
{
public function html_main()
{
echo $this->html_content();
}
abstract protected function html_content();
}

114
templates/TabularData.php Normal file
View File

@@ -0,0 +1,114 @@
<?php
/*****************************************************************************
* TabularData.php
* Contains the template that displays tabular data.
*
* Kabuki CMS (C) 2013-2015, Aaron van Geffen
*****************************************************************************/
class TabularData extends Pagination
{
public function __construct(GenericTable $table)
{
$this->_t = $table;
parent::__construct($table);
}
protected function html_content()
{
echo '
<div class="admin_box">';
$title = $this->_t->getTitle();
if (!empty($title))
echo '
<h2>', $title, '</h2>';
// Showing a page index?
parent::html_content();
// Maybe even a small form?
if (isset($this->_t->form_above))
$this->showForm($this->_t->form_above);
// Build the table!
echo '
<table class="table table-striped">
<thead>
<tr>';
// Show the table's headers.
foreach ($this->_t->getHeader() as $th)
{
echo '
<th', (!empty($th['width']) ? ' width="' . $th['width'] . '"' : ''), (!empty($th['class']) ? ' class="' . $th['class'] . '"' : ''), ($th['colspan'] > 1 ? ' colspan="' . $th['colspan'] . '"' : ''), ' scope="', $th['scope'], '">',
$th['href'] ? '<a href="' . $th['href'] . '">' . $th['label'] . '</a>' : $th['label'];
if ($th['sort_mode'] )
echo ' ', $th['sort_mode'] == 'up' ? '&uarr;' : '&darr;';
echo '</th>';
}
echo '
</tr>
</thead>
<tbody>';
// Show the table's body.
$body = $this->_t->getBody();
if (is_array($body))
{
foreach ($body as $tr)
{
echo '
<tr', (!empty($tr['class']) ? ' class="' . $tr['class'] . '"' : ''), '>';
foreach ($tr['cells'] as $td)
echo '
<td', (!empty($td['width']) ? ' width="' . $td['width'] . '"' : ''), '>', $td['value'], '</td>';
echo '
</tr>';
}
}
else
echo '
<tr>
<td colspan="', count($this->_t->getHeader()), '">', $body, '</td>
</tr>';
echo '
</tbody>
</table>';
// Maybe another small form?
if (isset($this->_t->form_below))
$this->showForm($this->_t->form_below);
// Showing a page index?
parent::html_content();
echo '
</div>';
}
protected function showForm($form)
{
echo '
<form action="', $form['action'], '" method="', $form['method'], '" class="table_form ', $form['class'], '">';
if (!empty($form['fields']))
foreach ($form['fields'] as $name => $field)
echo '
<input name="', $name, '" type="', $field['type'], '" placeholder="', $field['placeholder'], '"', isset($field['class']) ? ' class="' . $field['class'] . '"' : '', isset($field['value']) ? ' value="' . $field['value'] . '"' : '', '>';
if (!empty($form['buttons']))
foreach ($form['buttons'] as $name => $button)
echo '
<input name="', $name, '" type="', $button['type'], '" value="', $button['caption'], '" class="btn', isset($button['class']) ? ' ' . $button['class'] . '' : '', '">';
echo '
</form>';
}
}

34
templates/Template.php Normal file
View File

@@ -0,0 +1,34 @@
<?php
/*****************************************************************************
* Template.php
* Contains key Template interface.
*
* Kabuki CMS (C) 2013-2015, Aaron van Geffen
*****************************************************************************/
abstract class Template
{
protected $_subtemplates = array();
abstract public function html_main();
public function adopt(Template $template, $position = 'end')
{
// By default, we append it.
if ($position == 'end')
$this->_subtemplates[] = $template;
// We can also add it to the beginning of the list, though.
else
array_unshift($this->_subtemplates, $template);
}
public function clear()
{
$this->_subtemplates = [];
}
public function pass($id, $data)
{
$this->{$id} = $data;
}
}