10 Commits
0.4.0 ... 0.4.1

Author SHA1 Message Date
aff68e88cf Version upgrade (0.4.1) 2013-11-18 18:26:51 +01:00
bf0e40683c Removed TextHelper hacks 2013-11-18 15:41:16 +01:00
17bd7a7572 Added support for OpenGraph
- Linking to index and individual posts produces thumbs on sites like Facebook
- Thumbnails theoretically support custom sizes
2013-11-18 14:33:43 +01:00
a5d0a3f9ef HTML validation 2013-11-18 14:00:54 +01:00
5eb5e18b77 Fixes to Markdown parsing introduced in 7605177 2013-11-18 11:22:29 +01:00
19a8b90ca2 Added unique indexes 2013-11-18 10:31:04 +01:00
e7ec8ea49f Fixed user view tabs 2013-11-18 10:30:43 +01:00
0286e11c30 Fixed dangling postscore and crossref rows 2013-11-18 10:26:29 +01:00
7605177a6b Added strike through support to Markdown 2013-11-18 00:38:33 +01:00
52ceb8d962 Fixes to CLI scripts 2013-11-18 00:16:47 +01:00
15 changed files with 81 additions and 66 deletions

View File

@ -1,6 +1,6 @@
<?php
require_once 'src/core.php';
$config = configFactory();
$config = \Chibi\Registry::getConfig();
$fontsPath = $config->main->mediaPath . DS . 'fonts' . DS;
$libPath = $config->main->mediaPath . DS . 'lib' . DS;

View File

@ -41,6 +41,7 @@ class IndexController
$this->context->featuredPost = $featuredPost;
$this->context->featuredPostUser = $featuredPostUser;
$this->context->featuredPostDate = $featuredPostDate;
$this->context->pageThumb = \Chibi\UrlHelper::route('post', 'thumb', ['name' => $featuredPost->name]);
}
}

View File

@ -80,12 +80,12 @@ class PostController
$this->context->transport->searchQuery = $formQuery;
if (strpos($formQuery, '/') !== false)
throw new SimpleException('Search query contains invalid characters');
$url = \Chibi\UrlHelper::route('post', 'list', ['source' => $source, 'additionalInfo' => $additionalInfo, 'query' => urlencode($formQuery)]);
$url = \Chibi\UrlHelper::route('post', 'list', ['source' => $source, 'additionalInfo' => $additionalInfo, 'query' => $formQuery]);
\Chibi\UrlHelper::forward($url);
return;
}
$query = trim(urldecode($query));
$query = trim($query);
$page = intval($page);
$postsPerPage = intval($this->config->browsing->postsPerPage);
$this->context->subTitle = 'posts';
@ -552,6 +552,8 @@ class PostController
if (InputHelper::get('submit'))
{
//remove stuff from auxiliary tables
R::trashAll(R::find('postscore', 'post_id = ?', [$post->id]));
R::trashAll(R::find('crossref', 'post_id = ? OR post2_id = ?', [$post->id, $post->id]));
foreach ($post->ownComment as $comment)
{
$comment->post = null;
@ -731,6 +733,7 @@ class PostController
$flagged = in_array(TextHelper::reprPost($post), SessionHelper::get('flagged', []));
$this->context->pageThumb = \Chibi\UrlHelper::route('post', 'thumb', ['name' => $post->name]);
$this->context->stylesheets []= 'post-view.css';
$this->context->stylesheets []= 'comment-small.css';
$this->context->scripts []= 'post-view.js';
@ -750,13 +753,18 @@ class PostController
* Action that renders the thumbnail of the requested file and sends it to user.
* @route /post/{name}/thumb
*/
public function thumbAction($name)
public function thumbAction($name, $width = null, $height = null)
{
$dstWidth = $width === null ? $this->config->browsing->thumbWidth : $width;
$dstHeight = $height === null ? $this->config->browsing->thumbHeight : $height;
$dstWidth = min(1000, max(1, $dstWidth));
$dstHeight = min(1000, max(1, $dstHeight));
$this->context->layoutName = 'layout-file';
$path = $this->config->main->thumbsPath . DS . $name . '.custom';
if (!file_exists($path))
$path = $this->config->main->thumbsPath . DS . $name . '.default';
$path = $this->config->main->thumbsPath . DS . $name . '-' . $dstWidth . 'x' . $dstHeight . '.default';
if (!file_exists($path))
{
$post = Model_Post::locate($name);
@ -764,8 +772,6 @@ class PostController
PrivilegesHelper::confirmWithException(Privilege::ListPosts);
PrivilegesHelper::confirmWithException(Privilege::ListPosts, PostSafety::toString($post->safety));
$srcPath = $this->config->main->filesPath . DS . $post->name;
$dstWidth = $this->config->browsing->thumbWidth;
$dstHeight = $this->config->browsing->thumbHeight;
if ($post->type == PostType::Youtube)
{

View File

@ -126,7 +126,7 @@ class TagController
$suppliedQuery = ' ';
$suppliedTag = InputHelper::get('tag');
$suppliedTag = Model_Tag::validateTag($suppliedTag);
\Chibi\UrlHelper::forward(\Chibi\UrlHelper::route('post', 'list', ['source' => 'mass-tag', 'query' => urlencode($suppliedQuery), 'additionalInfo' => $suppliedTag]));
\Chibi\UrlHelper::forward(\Chibi\UrlHelper::route('post', 'list', ['source' => 'mass-tag', 'query' => $suppliedQuery, 'additionalInfo' => $suppliedTag]));
}
}
}

View File

@ -1,6 +1,18 @@
<?php
class UserController
{
private function loadUserView($user)
{
$flagged = in_array(TextHelper::reprUser($user), SessionHelper::get('flagged', []));
$this->context->flagged = $flagged;
$this->context->transport->user = $user;
$this->context->handleExceptions = true;
$this->context->viewName = 'user-view';
$this->context->stylesheets []= 'tabs.css';
$this->context->stylesheets []= 'user-view.css';
$this->context->subTitle = $user->name;
}
private static function sendTokenizedEmail(
$user,
$body,
@ -8,7 +20,7 @@ class UserController
$senderName,
$senderEmail,
$recipientEmail,
$tokens)
$linkActionName)
{
//prepare unique user token
do
@ -24,8 +36,11 @@ class UserController
R::store($token);
\Chibi\Registry::getContext()->mailSent = true;
$tokens = [];
$tokens['host'] = $_SERVER['HTTP_HOST'];
$tokens['token'] = $tokenText;
if ($linkActionName !== null)
$tokens['link'] = \Chibi\UrlHelper::route('user', $linkActionName, ['token' => $tokenText]);
$body = wordwrap(TextHelper::replaceTokens($body, $tokens), 70);
$subject = TextHelper::replaceTokens($subject, $tokens);
@ -63,9 +78,6 @@ class UserController
return;
}
$tokens = [];
$tokens['link'] = \Chibi\UrlHelper::route('user', 'activation', ['token' => '{token}']);
return self::sendTokenizedEmail(
$user,
$regConfig->confirmationEmailBody,
@ -73,16 +85,13 @@ class UserController
$regConfig->confirmationEmailSenderName,
$regConfig->confirmationEmailSenderEmail,
$user->email_unconfirmed,
$tokens);
'activation');
}
private static function sendPasswordResetConfirmation($user)
{
$regConfig = \Chibi\Registry::getConfig()->registration;
$tokens = [];
$tokens['link'] = \Chibi\UrlHelper::route('user', 'password-reset', ['token' => '{token}']);
return self::sendTokenizedEmail(
$user,
$regConfig->passwordResetEmailBody,
@ -90,7 +99,7 @@ class UserController
$regConfig->passwordResetEmailSenderName,
$regConfig->passwordResetEmailSenderEmail,
$user->email_confirmed,
$tokens);
'password-reset');
}
@ -234,13 +243,8 @@ class UserController
PrivilegesHelper::confirmWithException(Privilege::ViewUser, PrivilegesHelper::getIdentitySubPrivilege($user));
PrivilegesHelper::confirmWithException(Privilege::DeleteUser, PrivilegesHelper::getIdentitySubPrivilege($user));
$this->context->handleExceptions = true;
$this->context->transport->user = $user;
$this->loadUserView($user);
$this->context->transport->tab = 'delete';
$this->context->viewName = 'user-view';
$this->context->stylesheets []= 'tabs.css';
$this->context->stylesheets []= 'user-view.css';
$this->context->subTitle = $name;
$this->context->suppliedCurrentPassword = $suppliedCurrentPassword = InputHelper::get('current-password');
@ -253,6 +257,7 @@ class UserController
if ($suppliedPasswordHash != $user->pass_hash)
throw new SimpleException('Must supply valid password');
}
R::trashAll(R::find('postscore', 'user_id = ?', [$user->id]));
foreach ($user->alias('commenter')->ownComment as $comment)
{
$comment->commenter = null;
@ -287,13 +292,8 @@ class UserController
PrivilegesHelper::confirmWithException(Privilege::ViewUser, PrivilegesHelper::getIdentitySubPrivilege($user));
PrivilegesHelper::confirmWithException(Privilege::ChangeUserSettings, PrivilegesHelper::getIdentitySubPrivilege($user));
$this->context->handleExceptions = true;
$this->context->transport->user = $user;
$this->loadUserView($user);
$this->context->transport->tab = 'settings';
$this->context->viewName = 'user-view';
$this->context->stylesheets []= 'tabs.css';
$this->context->stylesheets []= 'user-view.css';
$this->context->subTitle = $name;
if (InputHelper::get('submit'))
{
@ -326,13 +326,8 @@ class UserController
$user = Model_User::locate($name);
PrivilegesHelper::confirmWithException(Privilege::ViewUser, PrivilegesHelper::getIdentitySubPrivilege($user));
$this->context->handleExceptions = true;
$this->context->transport->user = $user;
$this->loadUserView($user);
$this->context->transport->tab = 'edit';
$this->context->viewName = 'user-view';
$this->context->stylesheets []= 'tabs.css';
$this->context->stylesheets []= 'user-view.css';
$this->context->subTitle = $name;
$this->context->suppliedCurrentPassword = $suppliedCurrentPassword = InputHelper::get('current-password');
$this->context->suppliedName = $suppliedName = InputHelper::get('name');
@ -437,14 +432,12 @@ class UserController
$page = 1;
PrivilegesHelper::confirmWithException(Privilege::ViewUser, PrivilegesHelper::getIdentitySubPrivilege($user));
$this->context->stylesheets []= 'tabs.css';
$this->context->stylesheets []= 'user-view.css';
$this->loadUserView($user);
$this->context->stylesheets []= 'post-list.css';
$this->context->stylesheets []= 'post-small.css';
$this->context->stylesheets []= 'paginator.css';
if ($this->context->user->hasEnabledEndlessScrolling())
$this->context->scripts []= 'paginator-endless.js';
$this->context->subTitle = $name;
$query = '';
if ($tab == 'uploads')
@ -459,10 +452,6 @@ class UserController
$page = max(1, min($pageCount, $page));
$posts = Model_Post::getEntities($query, $postsPerPage, $page);
$flagged = in_array(TextHelper::reprUser($user), SessionHelper::get('flagged', []));
$this->context->flagged = $flagged;
$this->context->transport->user = $user;
$this->context->transport->tab = $tab;
$this->context->transport->paginator = new StdClass;
$this->context->transport->paginator->page = $page;

View File

@ -5,6 +5,7 @@ class CustomMarkdown extends \Michelf\Markdown
{
$this->no_markup = true;
$this->span_gamut += ['doSpoilers' => 71];
$this->span_gamut += ['doStrike' => 6];
$this->span_gamut += ['doUsers' => 7];
$this->span_gamut += ['doPosts' => 8];
$this->span_gamut += ['doTags' => 9];
@ -45,6 +46,14 @@ class CustomMarkdown extends \Michelf\Markdown
return preg_replace_callback('/\n/', [&$this, '_doHardBreaks_callback'], $text);
}
protected function doStrike($text)
{
return preg_replace_callback('{(~~|---)([^~]+)\1}', function($x)
{
return $this->hashPart('<del>') . $x[2] . $this->hashPart('</del>');
}, $text);
}
protected function doSpoilers($text)
{
if (is_array($text))

View File

@ -0,0 +1,3 @@
CREATE UNIQUE INDEX idx_uq_postscore_post_id_user_id ON postscore(post_id, user_id);
CREATE UNIQUE INDEX idx_uq_crossref_post_id_post2_id ON crossref(post_id, post2_id);

View File

@ -13,7 +13,7 @@
</div>
<div class="footer">
<span class="left">
<div class="left">
Tags:&nbsp;
<ul class="tags">
<?php foreach ($this->context->featuredPost->sharedTag as $tag): ?>
@ -24,9 +24,9 @@
</li>
<?php endforeach ?>
</ul>
</span>
</div>
<span class="right">
<div class="right">
Featured&#32;
<?php if ($this->context->featuredPostUser): ?>
by <a href="<?php echo \Chibi\UrlHelper::route('user', 'view', ['name' => $this->context->featuredPostUser->name]) ?>"><?php echo $this->context->featuredPostUser->name ?></a>,&#32;
@ -39,7 +39,7 @@
<?php else: ?>
<?php printf('%d days ago', $x) ?>
<?php endif ?>
</span>
</div>
<div class="clear"></div>
</div>

View File

@ -2,18 +2,25 @@
<html>
<head>
<meta charset="utf-8"/>
<?php if (isset($this->context->subTitle)): ?>
<title><?php printf('%s&nbsp;&ndash;&nbsp;%s', $this->context->title, $this->context->subTitle) ?></title>
<?php else: ?>
<title><?php echo $this->context->title ?></title>
<?php endif ?>
<?php
$title = isset($this->context->subTitle)
? sprintf('%s&nbsp;&ndash;&nbsp;%s', $this->context->title, $this->context->subTitle)
: $this->context->title
?>
<title><?php echo $title ?></title>
<?php foreach (array_unique($this->context->stylesheets) as $name): ?>
<link rel="stylesheet" type="text/css" href="<?php echo \Chibi\UrlHelper::absoluteUrl('/media/css/' . $name) ?>"/>
<?php endforeach ?>
<?php foreach (array_unique($this->context->scripts) as $name): ?>
<script type="text/javascript" src="<?php echo \Chibi\UrlHelper::absoluteUrl('/media/js/' . $name) ?>"></script>
<?php endforeach ?>
<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1">
<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1"/>
<meta property="og:title" content="<?php echo $title ?>"/>
<meta property="og:url" content="<?php echo \Chibi\UrlHelper::currentUrl() ?>"/>
<?php if (!empty($this->context->pageThumb)): ?>
<meta property="og:image" content="<?php echo $this->context->pageThumb ?>"/>
<?php endif ?>
</head>
<body>
@ -103,7 +110,7 @@
<?php endif ?>
<span><a href="<?php echo SZURU_LINK ?>">szurubooru v<?php echo SZURU_VERSION ?></a></span>
<?php if (PrivilegesHelper::confirm(Privilege::ListLogs)): ?>
<span><a href="<?php echo \Chibi\UrlHelper::route('log', 'list') ?>">Logs</span>
<span><a href="<?php echo \Chibi\UrlHelper::route('log', 'list') ?>">Logs</a></span>
<?php endif ?>
</div>
</footer>

View File

@ -77,12 +77,12 @@
<?php if (PrivilegesHelper::confirm(Privilege::ScorePost)): ?>
&nbsp;[
<?php $scoreLink = \Chibi\UrlHelper::route('post', 'score', ['id' => $this->context->transport->post->id, 'score' => '{score}']) ?>
<?php $scoreLink = function($score) { return \Chibi\UrlHelper::route('post', 'score', ['id' => $this->context->transport->post->id, 'score' => $score]); } ?>
<?php if ($this->context->score === 1): ?>
<a class="simple-action selected" href="<?php echo TextHelper::replaceTokens($scoreLink, ['score' => 0]) ?>">
<a class="simple-action selected" href="<?php echo $scoreLink(0) ?>">
<?php else: ?>
<a class="simple-action" href="<?php echo TextHelper::replaceTokens($scoreLink, ['score' => 1]) ?>">
<a class="simple-action" href="<?php echo $scoreLink(1) ?>">
<?php endif ?>
vote up
</a>
@ -90,9 +90,9 @@
,&nbsp;
<?php if ($this->context->score === -1): ?>
<a class="simple-action selected" href="<?php echo TextHelper::replaceTokens($scoreLink, ['score' => 0]) ?>">
<a class="simple-action selected" href="<?php echo $scoreLink(0) ?>">
<?php else: ?>
<a class="simple-action" href="<?php echo TextHelper::replaceTokens($scoreLink, ['score' => -1]) ?>">
<a class="simple-action" href="<?php echo $scoreLink(-1) ?>">
<?php endif ?>
down
</a>]

View File

@ -1,14 +1,14 @@
<?php $max = max([0]+array_map(function($x) { return $x['post_count']; }, $this->context->transport->tags)); ?>
<?php $add = 0.25 ?>
<?php $mul = 0.75 / max(1, log(max(1, $max))) ?>
<?php $url = \Chibi\UrlHelper::route('post', 'list', ['query' => '{query}']) ?>
<?php $url = \Chibi\UrlHelper::route('post', 'list', ['query' => '_query_']) ?>
<div class="tags">
<ul>
<?php foreach ($this->context->transport->tags as $tag): ?>
<?php $name = $tag['name'] ?>
<?php $count = $tag['post_count'] ?>
<li class="tag" title="<?php echo $name ?> (<?php echo $count ?>)">
<a href="<?php echo TextHelper::replaceTokens($url, ['query' => $name]) ?>" style="opacity: <?php printf('%.02f', $add + $mul * log($count)) ?>">
<a href="<?php echo str_replace('_query_', $name, $url) ?>" style="opacity: <?php printf('%.02f', $add + $mul * log($count)) ?>">
<?php echo $name . ' (' . $count . ')' ?>
</a>
</li>

View File

@ -1,6 +1,6 @@
<form action="<?php echo \Chibi\UrlHelper::route('user', 'settings', ['name' => $this->context->transport->user->name]) ?>" method="post" class="settings aligned">
<div class="safety">
<label class="left" for="name">Safety:</label>
<label class="left">Safety:</label>
<div class="input-wrapper">
<?php foreach (PostSafety::getAll() as $safety): ?>
<?php if (PrivilegesHelper::confirm(Privilege::ListPosts, PostSafety::toString($safety))): ?>
@ -12,10 +12,10 @@
</div>
<div class="endless-scrolling">
<label class="left" for="name">Endless scrolling:</label>
<label class="left" for="endless-scrolling">Endless scrolling:</label>
<div class="input-wrapper">
<label>
<input type="checkbox" name="endless-scrolling" <?php if ($this->context->transport->user->hasEnabledEndlessScrolling()) echo ' checked="checked"' ?>/>
<input type="checkbox" id="endless-scrolling" name="endless-scrolling" <?php if ($this->context->transport->user->hasEnabledEndlessScrolling()) echo ' checked="checked"' ?>/>
Enabled
</label>
</div>

View File

@ -1,5 +1,5 @@
<?php
define('SZURU_VERSION', '0.4.0');
define('SZURU_VERSION', '0.4.1');
define('SZURU_LINK', 'http://github.com/rr-/szurubooru');
define('DS', DIRECTORY_SEPARATOR);

View File

@ -1,6 +1,6 @@
<?php
require_once 'src/core.php';
$config = configFactory();
$config = \Chibi\Registry::getConfig();
$dbVersion = Model_Property::get('db-version');
printf('DB version = %d' . PHP_EOL, $dbVersion);