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] [chibi]
prettyPrint=1 enableCache=1
[main] [main]
dbDriver = "sqlite" dbDriver = "sqlite"

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

View file

@ -3,24 +3,10 @@ class Bootstrap
{ {
public function render($callback = null) public function render($callback = null)
{ {
if ($callback === null) if ($callback !== null)
{
$callback = function()
{
(new \Chibi\View())->renderFile($this->context->layoutName);
};
}
if ($this->context->layoutName == 'layout-normal')
{
ob_start(['LayoutHelper', 'transformHtml']);
$callback(); $callback();
ob_end_flush();
}
else else
{ (new \Chibi\View())->renderFile($this->context->layoutName);
$callback();
}
} }
public function workWrapper($workCallback) public function workWrapper($workCallback)
@ -29,7 +15,7 @@ class Bootstrap
session_start(); session_start();
$this->context->handleExceptions = false; $this->context->handleExceptions = false;
LayoutHelper::setTitle($this->config->main->title); CustomAssetViewDecorator::setTitle($this->config->main->title);
$this->context->json = isset($_GET['json']); $this->context->json = isset($_GET['json']);
$this->context->layoutName = $this->context->json $this->context->layoutName = $this->context->json
@ -48,6 +34,8 @@ class Bootstrap
return; return;
} }
$this->context->viewDecorators []= new CustomAssetViewDecorator();
$this->context->viewDecorators []= new \Chibi\PrettyPrintViewDecorator();
try try
{ {
$this->render($workCallback); $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 <?php
LayoutHelper::setSubTitle('authentication form'); CustomAssetViewDecorator::setSubTitle('authentication form');
LayoutHelper::addStylesheet('auth.css'); CustomAssetViewDecorator::addStylesheet('auth.css');
?> ?>
<form action="<?php echo \Chibi\UrlHelper::route('auth', 'login') ?>" class="auth" method="post"> <form action="<?php echo \Chibi\UrlHelper::route('auth', 'login') ?>" class="auth" method="post">

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -1,13 +1,13 @@
<?php <?php
LayoutHelper::setSubTitle('logs (' . $name . ')'); CustomAssetViewDecorator::setSubTitle('logs (' . $name . ')');
?> ?>
<?php if (empty($this->context->transport->lines)): ?> <?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> <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 else: ?>
<?php <?php
LayoutHelper::addStylesheet('logs.css'); CustomAssetViewDecorator::addStylesheet('logs.css');
LayoutHelper::addScript('logs.js'); CustomAssetViewDecorator::addScript('logs.js');
?> ?>
<form action="<?php echo \Chibi\UrlHelper::route('log', 'view', ['name' => $this->context->transport->name]) ?>" method="get"> <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 if (!empty($pagesVisible)): ?>
<?php <?php
LayoutHelper::addStylesheet('paginator.css'); CustomAssetViewDecorator::addStylesheet('paginator.css');
if ($this->context->user->hasEnabledEndlessScrolling()) if ($this->context->user->hasEnabledEndlessScrolling())
LayoutHelper::addScript('paginator-endless.js'); CustomAssetViewDecorator::addScript('paginator-endless.js');
?> ?>
<nav class="paginator-wrapper"> <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 $post = $this->context->transport->post ?>
<?php if ($post->type == PostType::Image): ?> <?php if ($post->type == PostType::Image): ?>

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -2,7 +2,7 @@
<?php $this->renderFile('message') ?> <?php $this->renderFile('message') ?>
<?php else: ?> <?php else: ?>
<?php <?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"> <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 <?php
LayoutHelper::setSubTitle($this->context->transport->user->name); CustomAssetViewDecorator::setSubTitle($this->context->transport->user->name);
LayoutHelper::addStylesheet('user-view.css'); CustomAssetViewDecorator::addStylesheet('user-view.css');
?> ?>
<div id="sidebar"> <div id="sidebar">