mirror of
https://github.com/vichan-devel/vichan.git
synced 2025-02-22 05:29:34 +01:00
Merge branch 'master' of github.com:vichan-devel/Tinyboard into beta
This commit is contained in:
commit
b86844c713
@ -19,6 +19,14 @@ class Cache {
|
|||||||
self::$cache = new Memcached();
|
self::$cache = new Memcached();
|
||||||
self::$cache->addServers($config['cache']['memcached']);
|
self::$cache->addServers($config['cache']['memcached']);
|
||||||
break;
|
break;
|
||||||
|
case 'redis':
|
||||||
|
self::$cache = new Redis();
|
||||||
|
self::$cache->connect($config['cache']['redis'][0], $config['cache']['redis'][1]);
|
||||||
|
if ($config['cache']['redis'][2]) {
|
||||||
|
self::$cache->auth($config['cache']['redis'][2]);
|
||||||
|
}
|
||||||
|
self::$cache->select($config['cache']['redis'][3]) or die('cache select failure');
|
||||||
|
break;
|
||||||
case 'php':
|
case 'php':
|
||||||
self::$cache = array();
|
self::$cache = array();
|
||||||
break;
|
break;
|
||||||
@ -45,6 +53,11 @@ class Cache {
|
|||||||
case 'php':
|
case 'php':
|
||||||
$data = isset(self::$cache[$key]) ? self::$cache[$key] : false;
|
$data = isset(self::$cache[$key]) ? self::$cache[$key] : false;
|
||||||
break;
|
break;
|
||||||
|
case 'redis':
|
||||||
|
if (!self::$cache)
|
||||||
|
self::init();
|
||||||
|
$data = json_decode(self::$cache->get($key), true);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// debug
|
// debug
|
||||||
@ -68,6 +81,11 @@ class Cache {
|
|||||||
self::init();
|
self::init();
|
||||||
self::$cache->set($key, $value, $expires);
|
self::$cache->set($key, $value, $expires);
|
||||||
break;
|
break;
|
||||||
|
case 'redis':
|
||||||
|
if (!self::$cache)
|
||||||
|
self::init();
|
||||||
|
self::$cache->setex($key, $expires, json_encode($value));
|
||||||
|
break;
|
||||||
case 'apc':
|
case 'apc':
|
||||||
apc_store($key, $value, $expires);
|
apc_store($key, $value, $expires);
|
||||||
break;
|
break;
|
||||||
@ -86,6 +104,7 @@ class Cache {
|
|||||||
|
|
||||||
switch ($config['cache']['enabled']) {
|
switch ($config['cache']['enabled']) {
|
||||||
case 'memcached':
|
case 'memcached':
|
||||||
|
case 'redis':
|
||||||
if (!self::$cache)
|
if (!self::$cache)
|
||||||
self::init();
|
self::init();
|
||||||
self::$cache->delete($key);
|
self::$cache->delete($key);
|
||||||
@ -114,6 +133,10 @@ class Cache {
|
|||||||
case 'php':
|
case 'php':
|
||||||
self::$cache[$key] = array();
|
self::$cache[$key] = array();
|
||||||
break;
|
break;
|
||||||
|
case 'redis':
|
||||||
|
if (!self::$cache)
|
||||||
|
self::init();
|
||||||
|
return self::$cache->flushDB();
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
@ -91,6 +91,7 @@
|
|||||||
|
|
||||||
$config['cache']['enabled'] = false;
|
$config['cache']['enabled'] = false;
|
||||||
// $config['cache']['enabled'] = 'memcached';
|
// $config['cache']['enabled'] = 'memcached';
|
||||||
|
// $config['cache']['enabled'] = 'redis';
|
||||||
// $config['cache']['enabled'] = 'apc';
|
// $config['cache']['enabled'] = 'apc';
|
||||||
// $config['cache']['enabled'] = 'xcache';
|
// $config['cache']['enabled'] = 'xcache';
|
||||||
|
|
||||||
@ -105,6 +106,11 @@
|
|||||||
array('localhost', 11211)
|
array('localhost', 11211)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Redis server to use. Location, port, password, database id.
|
||||||
|
// Note that Tinyboard may clear the database at times, so you may want to pick a
|
||||||
|
// database id just for Tinyboard to use.
|
||||||
|
$config['cache']['redis'] = array('localhost', 6379, '', 1);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* ====================
|
* ====================
|
||||||
* Cookie settings
|
* Cookie settings
|
||||||
|
@ -978,16 +978,33 @@ function index($page, $mod=false) {
|
|||||||
$th['sticky'], $th['locked'], $th['sage'], $th['embed'], $mod ? '?/' : $config['root'], $mod
|
$th['sticky'], $th['locked'], $th['sage'], $th['embed'], $mod ? '?/' : $config['root'], $mod
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!$config['cache']['enabled'] || !$replies = cache::get("thread_index_{$board['uri']}_{$th['id']}")) {
|
if ($config['cache']['enabled'] && $cached = cache::get("thread_index_{$board['uri']}_{$th['id']}")) {
|
||||||
|
$replies = $cached['replies'];
|
||||||
|
$omitted = $cached['omitted'];
|
||||||
|
} else {
|
||||||
$posts = prepare(sprintf("SELECT * FROM `posts_%s` WHERE `thread` = :id ORDER BY `id` DESC LIMIT :limit", $board['uri']));
|
$posts = prepare(sprintf("SELECT * FROM `posts_%s` WHERE `thread` = :id ORDER BY `id` DESC LIMIT :limit", $board['uri']));
|
||||||
$posts->bindValue(':id', $th['id']);
|
$posts->bindValue(':id', $th['id']);
|
||||||
$posts->bindValue(':limit', ($th['sticky'] ? $config['threads_preview_sticky'] : $config['threads_preview']), PDO::PARAM_INT);
|
$posts->bindValue(':limit', ($th['sticky'] ? $config['threads_preview_sticky'] : $config['threads_preview']), PDO::PARAM_INT);
|
||||||
$posts->execute() or error(db_error($posts));
|
$posts->execute() or error(db_error($posts));
|
||||||
|
|
||||||
$replies = $posts->fetchAll(PDO::FETCH_ASSOC);
|
$replies = array_reverse($posts->fetchAll(PDO::FETCH_ASSOC));
|
||||||
|
|
||||||
|
if (count($replies) == ($th['sticky'] ? $config['threads_preview_sticky'] : $config['threads_preview'])) {
|
||||||
|
$count = prepare(sprintf("SELECT COUNT(`id`) as `num` FROM `posts_%s` WHERE `thread` = :thread UNION ALL SELECT COUNT(`id`) FROM `posts_%s` WHERE `file` IS NOT NULL AND `thread` = :thread", $board['uri'], $board['uri']));
|
||||||
|
$count->bindValue(':thread', $th['id'], PDO::PARAM_INT);
|
||||||
|
$count->execute() or error(db_error($count));
|
||||||
|
$count = $count->fetchAll(PDO::FETCH_COLUMN);
|
||||||
|
|
||||||
|
$omitted = array('post_count' => $count[0], 'image_count' => $count[1]);
|
||||||
|
} else {
|
||||||
|
$omitted = false;
|
||||||
|
}
|
||||||
|
|
||||||
if ($config['cache']['enabled'])
|
if ($config['cache']['enabled'])
|
||||||
cache::set("thread_index_{$board['uri']}_{$th['id']}", $replies);
|
cache::set("thread_index_{$board['uri']}_{$th['id']}", array(
|
||||||
|
'replies' => $replies,
|
||||||
|
'omitted' => $omitted,
|
||||||
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
$num_images = 0;
|
$num_images = 0;
|
||||||
@ -1002,26 +1019,11 @@ function index($page, $mod=false) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
$post_count = count($replies); // $posts->rowCount()
|
if ($omitted) {
|
||||||
|
$thread->omitted = $omitted['post_count'] - ($th['sticky'] ? $config['threads_preview_sticky'] : $config['threads_preview']);
|
||||||
if ($post_count == ($th['sticky'] ? $config['threads_preview_sticky'] : $config['threads_preview'])) {
|
$thread->omitted_images = $omitted['image_count'] - $num_images;
|
||||||
// Yeah, using two cache objects for one thread seems a little inefficient. This code is messy and dumb; please clean it up if you can.
|
|
||||||
if (!$config['cache']['enabled'] || !$count = cache::get("thread_index_{$board['uri']}_{$th['id']}_omitted")) {
|
|
||||||
$count = prepare(sprintf("SELECT COUNT(`id`) as `num` FROM `posts_%s` WHERE `thread` = :thread UNION ALL SELECT COUNT(`id`) FROM `posts_%s` WHERE `file` IS NOT NULL AND `thread` = :thread", $board['uri'], $board['uri']));
|
|
||||||
$count->bindValue(':thread', $th['id'], PDO::PARAM_INT);
|
|
||||||
$count->execute() or error(db_error($count));
|
|
||||||
$count = $count->fetchAll(PDO::FETCH_COLUMN);
|
|
||||||
|
|
||||||
if ($config['cache']['enabled'])
|
|
||||||
cache::set("thread_index_{$board['uri']}_{$th['id']}_omitted", $count);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$thread->omitted = $count[0] - ($th['sticky'] ? $config['threads_preview_sticky'] : $config['threads_preview']);
|
|
||||||
$thread->omitted_images = $count[1] - $num_images;
|
|
||||||
}
|
|
||||||
|
|
||||||
$thread->posts = array_reverse($thread->posts);
|
|
||||||
|
|
||||||
$body .= $thread->build(true);
|
$body .= $thread->build(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1509,7 +1511,6 @@ function buildThread($id, $return=false, $mod=false) {
|
|||||||
if ($config['cache']['enabled'] && !$mod) {
|
if ($config['cache']['enabled'] && !$mod) {
|
||||||
// Clear cache
|
// Clear cache
|
||||||
cache::delete("thread_index_{$board['uri']}_{$id}");
|
cache::delete("thread_index_{$board['uri']}_{$id}");
|
||||||
cache::delete("thread_index_{$board['uri']}_{$id}_omitted");
|
|
||||||
cache::delete("thread_{$board['uri']}_{$id}");
|
cache::delete("thread_{$board['uri']}_{$id}");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -209,6 +209,8 @@ function mod_edit_board($boardName) {
|
|||||||
$query->bindValue(':title', $_POST['title']);
|
$query->bindValue(':title', $_POST['title']);
|
||||||
$query->bindValue(':subtitle', $_POST['subtitle']);
|
$query->bindValue(':subtitle', $_POST['subtitle']);
|
||||||
$query->execute() or error(db_error($query));
|
$query->execute() or error(db_error($query));
|
||||||
|
|
||||||
|
modLog('Edited board information for ' . sprintf($config['board_abbreviation'], $board['uri']), false);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($config['cache']['enabled']) {
|
if ($config['cache']['enabled']) {
|
||||||
@ -874,6 +876,8 @@ function mod_move($originBoard, $postID) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
modLog("Moved thread #${postID} to " . sprintf($config['board_abbreviation'], $targetBoard) . " (#${newID})", $originBoard);
|
||||||
|
|
||||||
// build new hread
|
// build new hread
|
||||||
buildThread($newID);
|
buildThread($newID);
|
||||||
buildIndex();
|
buildIndex();
|
||||||
@ -1029,8 +1033,12 @@ function mod_edit_post($board, $edit_raw_html, $postID) {
|
|||||||
$query->bindValue(':body', $_POST['body']);
|
$query->bindValue(':body', $_POST['body']);
|
||||||
$query->execute() or error(db_error($query));
|
$query->execute() or error(db_error($query));
|
||||||
|
|
||||||
if (!$edit_raw_html)
|
if ($edit_raw_html) {
|
||||||
|
modLog("Edited raw HTML of post #{$postID}");
|
||||||
|
} else {
|
||||||
|
modLog("Edited post #{$postID}");
|
||||||
rebuildPost($postID);
|
rebuildPost($postID);
|
||||||
|
}
|
||||||
|
|
||||||
buildIndex();
|
buildIndex();
|
||||||
|
|
||||||
|
63
js/toggle-locked-threads.js
Normal file
63
js/toggle-locked-threads.js
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
/*
|
||||||
|
* toggle-locked-threads.js
|
||||||
|
*
|
||||||
|
* Released under the MIT license
|
||||||
|
* Copyright (c) 2012 Michael Save <savetheinternet@tinyboard.org>
|
||||||
|
*
|
||||||
|
* Usage:
|
||||||
|
* $config['additional_javascript'][] = 'js/jquery.min.js';
|
||||||
|
* $config['additional_javascript'][] = 'js/toggle-locked-threads.js';
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
$(document).ready(function(){
|
||||||
|
if($('div.banner').length != 0)
|
||||||
|
return; // not index
|
||||||
|
|
||||||
|
var hide_locked_threads = localStorage['hidelockedthreads'] ? true : false;
|
||||||
|
|
||||||
|
$('<style type="text/css"> img.hidden{ opacity: 0.1; background: grey; border: 1px solid #000; } </style>').appendTo($('head'));
|
||||||
|
|
||||||
|
var hideLockedThread = function($thread) {
|
||||||
|
$thread
|
||||||
|
.hide()
|
||||||
|
.addClass('hidden');
|
||||||
|
};
|
||||||
|
|
||||||
|
var restoreLockedThread = function($thread) {
|
||||||
|
$thread
|
||||||
|
.show()
|
||||||
|
.removeClass('hidden');
|
||||||
|
};
|
||||||
|
|
||||||
|
var getThreadFromIcon = function($icon) {
|
||||||
|
return $icon.parent().parent().parent()
|
||||||
|
};
|
||||||
|
|
||||||
|
$('hr:first').before('<div id="toggle-locked-threads" style="text-align:right"><a class="unimportant" href="javascript:void(0)">-</a></div>');
|
||||||
|
$('div#toggle-locked-threads a')
|
||||||
|
.text((hide_locked_threads ? 'Show' : 'Hide') + ' locked threads')
|
||||||
|
.click(function() {
|
||||||
|
hide_locked_threads = !hide_locked_threads;
|
||||||
|
if (hide_locked_threads) {
|
||||||
|
$('img.icon[title="Locked"]').each(function() {
|
||||||
|
hideLockedThread(getThreadFromIcon($(this)));
|
||||||
|
});
|
||||||
|
localStorage.hidelockedthreads = true;
|
||||||
|
} else {
|
||||||
|
$('img.icon[title="Locked"]').each(function() {
|
||||||
|
restoreLockedThread(getThreadFromIcon($(this)));
|
||||||
|
});
|
||||||
|
delete localStorage.hidelockedthreads;
|
||||||
|
}
|
||||||
|
|
||||||
|
$(this).text((hide_locked_threads ? 'Show' : 'Hide') + ' locked threads')
|
||||||
|
});
|
||||||
|
|
||||||
|
if (hide_locked_threads) {
|
||||||
|
$('img.icon[title="Locked"]').each(function() {
|
||||||
|
hideLockedThread(getThreadFromIcon($(this)));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
@ -121,6 +121,10 @@
|
|||||||
<legend>{% trans 'Debug' %}</legend>
|
<legend>{% trans 'Debug' %}</legend>
|
||||||
<ul>
|
<ul>
|
||||||
<li><a href="?/debug/antispam">{% trans 'Anti-spam' %}</a></li>
|
<li><a href="?/debug/antispam">{% trans 'Anti-spam' %}</a></li>
|
||||||
|
<li><a href="?/debug/recent">{% trans 'Recent posts' %}</a></li>
|
||||||
|
{% if mod|hasPermission(config.mod.debug_sql) %}
|
||||||
|
<li><a href="?/debug/sql">{% trans 'SQL' %}</a></li>
|
||||||
|
{% endif %}
|
||||||
</ul>
|
</ul>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user