Newest chibi-core

This commit is contained in:
Marcin Kurczewski 2014-02-27 15:04:36 +01:00
parent 06cdebaccb
commit 82b0d9a63a
27 changed files with 105 additions and 143 deletions

View file

@ -1,5 +1,5 @@
[chibi]
prettyPrint=1
enableCache=1
[main]
dbDriver = "sqlite"

@ -1 +1 @@
Subproject commit 9653960e235c2c932bce404d3fe8ff4ea3990e08
Subproject commit 4628a3d8dde54b411294be6c07b62a163cd9c774

View file

@ -3,24 +3,10 @@ class Bootstrap
{
public function render($callback = null)
{
if ($callback === null)
{
$callback = function()
{
(new \Chibi\View())->renderFile($this->context->layoutName);
};
}
if ($this->context->layoutName == 'layout-normal')
{
ob_start(['LayoutHelper', 'transformHtml']);
if ($callback !== null)
$callback();
ob_end_flush();
}
else
{
$callback();
}
(new \Chibi\View())->renderFile($this->context->layoutName);
}
public function workWrapper($workCallback)
@ -29,7 +15,7 @@ class Bootstrap
session_start();
$this->context->handleExceptions = false;
LayoutHelper::setTitle($this->config->main->title);
CustomAssetViewDecorator::setTitle($this->config->main->title);
$this->context->json = isset($_GET['json']);
$this->context->layoutName = $this->context->json
@ -48,6 +34,8 @@ class Bootstrap
return;
}
$this->context->viewDecorators []= new CustomAssetViewDecorator();
$this->context->viewDecorators []= new \Chibi\PrettyPrintViewDecorator();
try
{
$this->render($workCallback);

View file

@ -0,0 +1,40 @@
<?php
class CustomAssetViewDecorator extends \Chibi\AssetViewDecorator
{
private static $pageThumb = null;
private static $subTitle = null;
public static function setSubTitle($text)
{
self::$subTitle = $text;
}
public static function setPageThumb($path)
{
self::$pageThumb = $path;
}
public function transformHtml($html)
{
self::$title = isset(self::$subTitle)
? sprintf('%s&nbsp;&ndash;&nbsp;%s', self::$title, self::$subTitle)
: self::$title;
$html = parent::transformHtml($html);
$headSnippet = '<meta property="og:title" content="' . self::$title . '"/>';
$headSnippet .= '<meta property="og:url" content="' . \Chibi\UrlHelper::currentUrl() . '"/>';
if (!empty(self::$pageThumb))
$headSnippet .= '<meta property="og:image" content="' . self::$pageThumb . '"/>';
$bodySnippet = '<script type="text/javascript">';
$bodySnippet .= '$(function() {';
$bodySnippet .= '$(\'body\').trigger(\'dom-update\');';
$bodySnippet .= '});';
$bodySnippet .= '</script>';
$html = str_replace('</head>', $headSnippet . '</head>', $html);
$html = str_replace('</body>', $bodySnippet . '</body>', $html);
return $html;
}
}

View file

@ -1,66 +0,0 @@
<?php
class LayoutHelper
{
private static $stylesheets = [];
private static $scripts = [];
private static $title = null;
private static $pageThumb = null;
private static $subTitle = null;
public static function setTitle($text)
{
self::$title = $text;
}
public static function setSubTitle($text)
{
self::$subTitle = $text;
}
public static function setPageThumb($path)
{
self::$pageThumb = $path;
}
public static function addStylesheet($css)
{
self::$stylesheets []= $css;
}
public static function addScript($js)
{
self::$scripts []= $js;
}
public static function transformHtml($html)
{
$bodySnippet = '';
$headSnippet = '';
$title = isset(self::$subTitle)
? sprintf('%s&nbsp;&ndash;&nbsp;%s', self::$title, self::$subTitle)
: self::$title;
$headSnippet .= '<title>' . $title . '</title>';
$headSnippet .= '<meta property="og:title" content="' . $title . '"/>';
$headSnippet .= '<meta property="og:url" content="' . \Chibi\UrlHelper::currentUrl() . '"/>';
if (!empty(self::$pageThumb))
$headSnippet .= '<meta property="og:image" content="' . self::$pageThumb . '"/>';
foreach (array_unique(self::$stylesheets) as $name)
$headSnippet .= '<link rel="stylesheet" type="text/css" href="' . \Chibi\UrlHelper::absoluteUrl('/media/css/' . $name) . '"/>';
foreach (array_unique(self::$scripts) as $name)
$bodySnippet .= '<script type="text/javascript" src="' . \Chibi\UrlHelper::absoluteUrl('/media/js/' . $name) . '"></script>';
$bodySnippet .= '<script type="text/javascript">';
$bodySnippet .= '$(function() {';
$bodySnippet .= '$(\'body\').trigger(\'dom-update\');';
$bodySnippet .= '});';
$bodySnippet .= '</script>';
$html = str_replace('</head>', $headSnippet . '</head>', $html);
$html = str_replace('</body>', $bodySnippet . '</body>', $html);
return $html;
}
}

View file

@ -1,6 +1,6 @@
<?php
LayoutHelper::setSubTitle('authentication form');
LayoutHelper::addStylesheet('auth.css');
CustomAssetViewDecorator::setSubTitle('authentication form');
CustomAssetViewDecorator::addStylesheet('auth.css');
?>
<form action="<?php echo \Chibi\UrlHelper::route('auth', 'login') ?>" class="auth" method="post">

View file

@ -1,6 +1,6 @@
<?php
LayoutHelper::addStylesheet('comment-edit.css');
LayoutHelper::addScript('comment-edit.js');
CustomAssetViewDecorator::addStylesheet('comment-edit.css');
CustomAssetViewDecorator::addScript('comment-edit.js');
?>
<form action="<?php echo \Chibi\UrlHelper::route('comment', 'add', ['postId' => $this->context->transport->post->id]) ?>" method="post" class="add-comment">

View file

@ -1,6 +1,6 @@
<?php
LayoutHelper::addStylesheet('comment-edit.css');
LayoutHelper::addScript('comment-edit.js');
CustomAssetViewDecorator::addStylesheet('comment-edit.css');
CustomAssetViewDecorator::addScript('comment-edit.js');
?>
<form action="<?php echo \Chibi\UrlHelper::route('comment', 'edit', ['id' => $this->context->transport->comment->id]) ?>" method="post" class="edit-comment">

View file

@ -1,15 +1,15 @@
<?php
LayoutHelper::setSubTitle('comments');
CustomAssetViewDecorator::setSubTitle('comments');
?>
<?php if (empty($this->context->transport->posts)): ?>
<p class="alert alert-warning">No comments to show.</p>
<?php else: ?>
<?php
LayoutHelper::addStylesheet('comment-list.css');
LayoutHelper::addStylesheet('comment-small.css');
LayoutHelper::addStylesheet('comment-edit.css');
LayoutHelper::addScript('comment-edit.js');
CustomAssetViewDecorator::addStylesheet('comment-list.css');
CustomAssetViewDecorator::addStylesheet('comment-small.css');
CustomAssetViewDecorator::addStylesheet('comment-edit.css');
CustomAssetViewDecorator::addScript('comment-edit.js');
?>
<div class="comments-wrapper">

View file

@ -1,7 +1,7 @@
<?php
LayoutHelper::addStylesheet('comment-small.css');
LayoutHelper::addStylesheet('comment-edit.css');
LayoutHelper::addScript('comment-edit.js');
CustomAssetViewDecorator::addStylesheet('comment-small.css');
CustomAssetViewDecorator::addStylesheet('comment-edit.css');
CustomAssetViewDecorator::addScript('comment-edit.js');
?>
<div class="comment">

View file

@ -1,4 +1,4 @@
<?php LayoutHelper::addStylesheet('debug.css') ?>
<?php CustomAssetViewDecorator::addStylesheet('debug.css') ?>
<div class="main-wrapper">
<?php foreach (Database::getLogs() as $log): ?>
<div class="debug">

View file

@ -1,6 +1,6 @@
<?php
LayoutHelper::setSubtitle('help');
LayoutHelper::addStylesheet('index-help.css');
CustomAssetViewDecorator::setSubtitle('help');
CustomAssetViewDecorator::addStylesheet('index-help.css');
$tabs = $this->config->help->subTitles;
$firstTab = !empty($tabs) ? array_keys($tabs)[0] : null;

View file

@ -1,6 +1,6 @@
<?php
LayoutHelper::setSubtitle('home');
LayoutHelper::addStylesheet('index-index.css');
CustomAssetViewDecorator::setSubtitle('home');
CustomAssetViewDecorator::addStylesheet('index-index.css');
?>
<div id="welcome">

View file

@ -1,10 +1,10 @@
<?php
LayoutHelper::addStylesheet('../lib/jquery-ui/jquery-ui.css');
LayoutHelper::addStylesheet('core.css');
LayoutHelper::addScript('../lib/jquery/jquery.min.js');
LayoutHelper::addScript('../lib/jquery-ui/jquery-ui.min.js');
LayoutHelper::addScript('../lib/mousetrap/mousetrap.min.js');
LayoutHelper::addScript('core.js');
CustomAssetViewDecorator::addStylesheet('../lib/jquery-ui/jquery-ui.css');
CustomAssetViewDecorator::addStylesheet('core.css');
CustomAssetViewDecorator::addScript('../lib/jquery/jquery.min.js');
CustomAssetViewDecorator::addScript('../lib/jquery-ui/jquery-ui.min.js');
CustomAssetViewDecorator::addScript('../lib/mousetrap/mousetrap.min.js');
CustomAssetViewDecorator::addScript('core.js');
?>
<!DOCTYPE html>

View file

@ -1,13 +1,13 @@
<?php
LayoutHelper::setSubTitle('logs (' . $name . ')');
CustomAssetViewDecorator::setSubTitle('logs (' . $name . ')');
?>
<?php if (empty($this->context->transport->lines)): ?>
<p class="alert alert-warning">This log is empty. <a href="<?php echo \Chibi\UrlHelper::route('log', 'list') ?>">Go back</a></p>
<?php else: ?>
<?php
LayoutHelper::addStylesheet('logs.css');
LayoutHelper::addScript('logs.js');
CustomAssetViewDecorator::addStylesheet('logs.css');
CustomAssetViewDecorator::addScript('logs.js');
?>
<form action="<?php echo \Chibi\UrlHelper::route('log', 'view', ['name' => $this->context->transport->name]) ?>" method="get">

View file

@ -42,9 +42,9 @@ if (!function_exists('pageUrl'))
<?php if (!empty($pagesVisible)): ?>
<?php
LayoutHelper::addStylesheet('paginator.css');
CustomAssetViewDecorator::addStylesheet('paginator.css');
if ($this->context->user->hasEnabledEndlessScrolling())
LayoutHelper::addScript('paginator-endless.js');
CustomAssetViewDecorator::addScript('paginator-endless.js');
?>
<nav class="paginator-wrapper">

View file

@ -1,4 +1,4 @@
<?php LayoutHelper::setPageThumb(\Chibi\UrlHelper::route('post', 'thumb', ['name' => $this->context->transport->post->name])) ?>
<?php CustomAssetViewDecorator::setPageThumb(\Chibi\UrlHelper::route('post', 'thumb', ['name' => $this->context->transport->post->name])) ?>
<?php $post = $this->context->transport->post ?>
<?php if ($post->type == PostType::Image): ?>

View file

@ -1,5 +1,5 @@
<?php
LayoutHelper::setSubTitle('posts');
CustomAssetViewDecorator::setSubTitle('posts');
$tabs = [];
if (PrivilegesHelper::confirm(Privilege::ListPosts))

View file

@ -1,6 +1,6 @@
<?php
LayoutHelper::addStylesheet('post-list.css');
LayoutHelper::addScript('post-list.js');
CustomAssetViewDecorator::addStylesheet('post-list.css');
CustomAssetViewDecorator::addScript('post-list.js');
?>
<?php if (isset($this->context->source) and $this->context->source == 'mass-tag' and PrivilegesHelper::confirm(Privilege::MassTag)): ?>

View file

@ -1,5 +1,5 @@
<?php
LayoutHelper::addStylesheet('post-small.css');
CustomAssetViewDecorator::addStylesheet('post-small.css');
$classNames =
[

View file

@ -1,9 +1,9 @@
<?php
LayoutHelper::setSubTitle('upload');
LayoutHelper::addStylesheet('post-upload.css');
LayoutHelper::addScript('post-upload.js');
LayoutHelper::addStylesheet('../lib/tagit/jquery.tagit.css');
LayoutHelper::addScript('../lib/tagit/jquery.tagit.js');
CustomAssetViewDecorator::setSubTitle('upload');
CustomAssetViewDecorator::addStylesheet('post-upload.css');
CustomAssetViewDecorator::addScript('post-upload.js');
CustomAssetViewDecorator::addStylesheet('../lib/tagit/jquery.tagit.css');
CustomAssetViewDecorator::addScript('../lib/tagit/jquery.tagit.js');
?>
<div id="sidebar">

View file

@ -1,9 +1,9 @@
<?php
LayoutHelper::setSubTitle('showing ' . TextHelper::reprPost($this->context->transport->post) . ' &ndash; ' . TextHelper::reprTags($this->context->transport->post->getTags()));
LayoutHelper::addStylesheet('post-view.css');
LayoutHelper::addScript('post-view.js');
LayoutHelper::addStylesheet('../lib/tagit/jquery.tagit.css');
LayoutHelper::addScript('../lib/tagit/jquery.tagit.js');
CustomAssetViewDecorator::setSubTitle('showing ' . TextHelper::reprPost($this->context->transport->post) . ' &ndash; ' . TextHelper::reprTags($this->context->transport->post->getTags()));
CustomAssetViewDecorator::addStylesheet('post-view.css');
CustomAssetViewDecorator::addScript('post-view.js');
CustomAssetViewDecorator::addStylesheet('../lib/tagit/jquery.tagit.css');
CustomAssetViewDecorator::addScript('../lib/tagit/jquery.tagit.js');
$editPostPrivileges = [
Privilege::EditPostSafety,
@ -318,8 +318,8 @@ $canEditAnything = count(array_filter($editPostPrivileges)) > 0;
</div>
<?php
LayoutHelper::addStylesheet('comment-list.css');
LayoutHelper::addStylesheet('comment-small.css');
CustomAssetViewDecorator::addStylesheet('comment-list.css');
CustomAssetViewDecorator::addStylesheet('comment-small.css');
?>
<div class="comments-wrapper">
<?php if (!empty($this->context->transport->post->getComments())): ?>

View file

@ -1,6 +1,6 @@
<?php
LayoutHelper::setSubTitle('tags');
LayoutHelper::addStylesheet('tag-list.css');
CustomAssetViewDecorator::setSubTitle('tags');
CustomAssetViewDecorator::addStylesheet('tag-list.css');
$tabs = [];
if (PrivilegesHelper::confirm(Privilege::ListTags)) $tabs['list'] = 'List';

View file

@ -1,9 +1,9 @@
<?php
LayoutHelper::setSubTitle('users');
LayoutHelper::addStylesheet('user-list.css');
LayoutHelper::addStylesheet('paginator.css');
CustomAssetViewDecorator::setSubTitle('users');
CustomAssetViewDecorator::addStylesheet('user-list.css');
CustomAssetViewDecorator::addStylesheet('paginator.css');
if ($this->context->user->hasEnabledEndlessScrolling())
LayoutHelper::addScript('paginator-endless.js');
CustomAssetViewDecorator::addScript('paginator-endless.js');
?>
<nav class="sort-styles">

View file

@ -1,12 +1,12 @@
<?php
LayoutHelper::setSubTitle('registration form');
CustomAssetViewDecorator::setSubTitle('registration form');
?>
<?php if ($this->context->transport->success === true): ?>
<?php $this->renderFile('message') ?>
<?php else: ?>
<?php
LayoutHelper::addStylesheet('auth.css');
CustomAssetViewDecorator::addStylesheet('auth.css');
?>
<form action="<?php echo \Chibi\UrlHelper::route('auth', 'register') ?>" class="auth" method="post">

View file

@ -2,7 +2,7 @@
<?php $this->renderFile('message') ?>
<?php else: ?>
<?php
LayoutHelper::addStylesheet('auth.css');
CustomAssetViewDecorator::addStylesheet('auth.css');
?>
<form action="<?php echo \Chibi\UrlHelper::route($this->context->route->simpleControllerName, $this->context->route->simpleActionName) ?>" method="post" class="auth" autocomplete="off">

View file

@ -1,6 +1,6 @@
<?php
LayoutHelper::setSubTitle($this->context->transport->user->name);
LayoutHelper::addStylesheet('user-view.css');
CustomAssetViewDecorator::setSubTitle($this->context->transport->user->name);
CustomAssetViewDecorator::addStylesheet('user-view.css');
?>
<div id="sidebar">