1
0
mirror of https://github.com/vichan-devel/vichan.git synced 2024-11-25 07:50:23 +01:00

Merge vichan-devel

This commit is contained in:
8chan 2014-08-30 20:06:02 +00:00
commit 41be663ee9
11 changed files with 360 additions and 38 deletions

View File

@ -1526,6 +1526,11 @@
// Keep the Google Analytics cookies to one domain -- ga._setDomainName()
// $config['google_analytics_domain'] = 'www.example.org';
// Link imageboard to your Statcounter.com account to track users and provide traffic insights without the Google botnet.
// Extract these values from Statcounter's JS tracking code:
// $config['statcounter_project'] = '1234567';
// $config['statcounter_security'] = 'acbd1234';
// If you use Varnish, Squid, or any similar caching reverse-proxy in front of Tinyboard, you can
// configure Tinyboard to PURGE files when they're written to.
// $config['purge'] = array(

View File

@ -353,7 +353,7 @@ class Post {
$this->{$key} = $value;
}
if (isset($this->files))
if (isset($this->files) && $this->files)
$this->files = json_decode($this->files);
$this->subject = utf8tohtml($this->subject);

View File

@ -2325,6 +2325,7 @@ function shell_exec_error($command, $suppress_stdout = false) {
* added on. The result is displayed at the top of the post.
*/
function diceRoller($post) {
global $config;
if(strpos(strtolower($post->email), 'dice%20') === 0) {
$dicestr = str_split(substr($post->email, strlen('dice%20')));
@ -2372,7 +2373,7 @@ function diceRoller($post) {
// Prepend the result to the post body
$modifier = ($diceZ != 0) ? ((($diceZ < 0) ? ' - ' : ' + ') . abs($diceZ)) : '';
$dicesum = ($diceX > 1) ? ' = ' . $dicesum : '';
$post->body = 'Rolled ' . implode(', ', $dicerolls) . $modifier . $dicesum . '<br/>' . $post->body;
$post->body = '<table class="diceroll"><tr><td><img src="'.$config['dir']['static'].'d10.svg" alt="Dice roll" width="24"></td><td>Rolled ' . implode(', ', $dicerolls) . $modifier . $dicesum . '</td></tr></table><br/>' . $post->body;
}
}
}

View File

@ -20,8 +20,8 @@ $(document).ready(function(){
var do_expand = function() {
$(this)
.html($(this).text().replace(_("Click reply to view."), '<a href="javascript:void(0)">'+_("Click to expand")+'</a>.'))
.find('a').click(function() {
var thread = $(this).parent().parent().parent();
.find('a').click(window.expand_fun = function() {
var thread = $(this).parents('[id^="thread_"]');
var id = thread.attr('id').replace(/^thread_/, '');
$.ajax({
url: thread.find('p.intro a.post_no:first').attr('href'),
@ -43,12 +43,16 @@ $(document).ready(function(){
last_expanded = post_in_doc;
}
});
$('<span class="omitted"><a href="javascript:void(0)">' + _('Hide expanded replies') + '</a>.</span>')
.insertAfter(thread.find('span.omitted').css('display', 'none'))
thread.find("span.omitted").css('display', 'none');
$('<span class="omitted hide-expanded"><a href="javascript:void(0)">' + _('Hide expanded replies') + '</a>.</span>')
.insertAfter(thread.find('.op div.body, .op span.omitted').last())
.click(function() {
thread.find('.expanded').remove();
$(this).prev().css('display', '');
$(this).remove();
$(this).parent().find(".omitted:not(.hide-expanded)").css('display', '');
$(this).parent().find(".hide-expanded").remove();
});
}
});

View File

@ -36,7 +36,7 @@ $(document).ready(function(){
}
}
var fields_to_hide = 'div.post,div.video-container,video,img,p.fileinfo,a.hide-thread-link,br';
var fields_to_hide = 'div.post,div.video-container,video,img:not(.unanimated),canvas,p.fileinfo,a.hide-thread-link,div.new-posts,br';
var do_hide_threads = function() {
var id = $(this).children('p.intro').children('a.post_no:eq(1)').text();

105
js/live-index.js Normal file
View File

@ -0,0 +1,105 @@
/*
* live-index.js
* https://github.com/vichan-devel/Tinyboard/blob/master/js/live-index.js
*
* Released under the MIT license
* Copyright (c) 2014 Marcin Łabanowski <marcin@6irc.net>
*
* Usage:
* $config['api']['enabled'] = true;
* $config['additional_javascript'][] = 'js/jquery.min.js';
* $config['additional_javascript'][] = 'js/expand.js';
* $config['additional_javascript'][] = 'js/live-index.js';
*
*/
if (active_page == 'index' && (""+document.location).match(/\/(index\.html)?(\?|$|#)/))
+function() {
// Make jQuery respond to reverse()
$.fn.reverse = [].reverse;
var board_name = (""+document.location).match(/\/([^\/]+)\/[^/]*$/)[1];
var handle_one_thread = function() {
if ($(this).find(".new-posts").length <= 0) {
$(this).find("br.clear").before("<div class='new-posts'>"+_("No new posts.")+"</div>");
}
};
$(function() {
$("hr:first").before("<hr /><div class='new-threads'>"+_("No new threads.")+"</div>");
$('div[id^="thread_"]').each(handle_one_thread);
setInterval(function() {
$.getJSON(configRoot+board_name+"/0.json", function(j) {
var new_threads = 0;
j.threads.forEach(function(t) {
var s_thread = $("#thread_"+t.posts[0].no);
if (s_thread.length) {
var my_posts = s_thread.find(".post.reply").length;
var omitted_posts = s_thread.find(".omitted");
if (omitted_posts.length) {
omitted_posts = omitted_posts.html().match("^[^0-9]*([0-9]+)")[1]|0;
my_posts += omitted_posts;
}
my_posts -= t.posts[0].replies|0;
my_posts *= -1;
update_new_posts(my_posts, s_thread);
}
else {
new_threads++;
}
});
update_new_threads(new_threads);
});
}, 1000);
});
$(document).on("new_post", function(e, post) {
if (!$(post).hasClass("reply")) {
handle_one_thread.call(post);
}
});
var update_new_threads = function(i) {
var msg = i ?
(fmt(_("There are {0} new threads."), [i]) + " <a href='javascript:void(0)'>"+_("Click to expand")+"</a>.") :
_("No new threads.");
if ($(".new-threads").html() != msg) {
$(".new-threads").html(msg);
$(".new-threads a").click(fetch_new_threads);
}
};
var update_new_posts = function(i, th) {
var msg = (i>0) ?
(fmt(_("There are {0} new posts in this thread."), [i])+" <a href='javascript:void(0)'>"+_("Click to expand")+"</a>.") :
_("No new posts.");
if ($(th).find(".new-posts").html() != msg) {
$(th).find(".new-posts").html(msg);
$(th).find(".new-posts a").click(window.expand_fun);
}
};
var fetch_new_threads = function() {
$.get(""+document.location, function(data) {
$(data).find('div[id^="thread_"]').reverse().each(function() {
if ($("#"+$(this).attr("id")).length) {
// okay, the thread is there
}
else {
var thread = $(this).insertBefore('div[id^="thread_"]:first');
$(document).trigger("new_post", this);
}
});
});
};
}();

View File

@ -24,7 +24,7 @@ function unanimate_gif(e) {
draw_image();
}
$(e).hide();
$(e).addClass("unanimated").hide();
}
function no_animated_gif() {
@ -37,7 +37,7 @@ function no_animated_gif() {
function animated_gif() {
$('canvas.post-image').remove();
$('img.post-image').show();
$('img.post-image').removeClass("unanimated").show();
localStorage.no_animated_gif = false;
$('#no-animated-gif>a').text(_('Unanimate GIFs'));

View File

@ -152,12 +152,21 @@ $(function(){
};
var update_pinned = function() {
if (updating_suspended) return;
if (typeof update_title != "undefined") update_title();
var bl = $('.boardlist').first();
$('#watch-pinned, .watch-menu').remove();
var pinned = $('<div id="watch-pinned"></div>').appendTo(bl);
if (device_type == "desktop")
bl.off().on("mouseenter", function() {
updating_suspended = true;
}).on("mouseleave", function() {
updating_suspended = false;
});
var st = storage();
for (var i in st) {
if (is_pinned(st[i])) {
@ -198,7 +207,6 @@ $(function(){
if (device_type == "desktop")
link.off().mouseenter(function() {
updating_suspended = true;
$('.cb-menu').remove();
var board = $(this).attr("data-board");
@ -216,7 +224,6 @@ $(function(){
wl.find("a.cb-menuitem").each(init_hover);
}).mouseleave(function() {
updating_suspended = false;
$('.boardlist .cb-menu').remove();
});
}
@ -232,30 +239,45 @@ $(function(){
}
};
var fetch_jsons = function() {
if (updating_suspended) return;
if (window_active) check_scroll();
var st = storage();
var sched = 0;
var sched_diff = 300;
for (var i in st) {
if (st[i].watched) {
var r = $.getJSON(configRoot+i+"/threads.json", function(j, x, r) {
handle_board_json(r.board, j);
});
r.board = i;
(function(i) {
setTimeout(function() {
var r = $.getJSON(configRoot+i+"/threads.json", function(j, x, r) {
handle_board_json(r.board, j);
});
r.board = i;
}, sched);
sched += sched_diff;
})(i);
}
else if (st[i].threads) {
for (var j in st[i].threads) {
var r = $.getJSON(configRoot+i+"/res/"+j+".json", function(k, x, r) {
handle_thread_json(r.board, r.thread, k);
}).error(function(r) {
if(r.status == 404) handle_thread_404(r.board, r.thread);
});
r.board = i;
r.thread = j;
(function(i,j) {
setTimeout(function() {
var r = $.getJSON(configRoot+i+"/res/"+j+".json", function(k, x, r) {
handle_thread_json(r.board, r.thread, k);
}).error(function(r) {
if(r.status == 404) handle_thread_404(r.board, r.thread);
});
r.board = i;
r.thread = j;
}, sched);
})(i,j);
sched += sched_diff;
}
}
}
setTimeout(fetch_jsons, sched + sched_diff);
};
var handle_board_json = function(board, json) {
@ -293,31 +315,39 @@ $(function(){
status = status || {};
status[board] = status[board] || {};
status[board].last_thread = last_thread;
status[board].new_threads = new_threads;
update_pinned();
if (status[board].last_thread != last_thread || status[board].new_threads != new_threads) {
status[board].last_thread = last_thread;
status[board].new_threads = new_threads;
update_pinned();
}
};
var handle_thread_json = function(board, threadid, json) {
var new_posts = 0;
for (var i in json.posts) {
var post = json.posts[i];
var new_posts = 0;
if (post.time > storage()[board].threads[threadid] / 1000) {
new_posts++;
}
status = status || {};
status[board] = status[board] || {};
status[board].threads = status[board].threads || {};
}
status = status || {};
status[board] = status[board] || {};
status[board].threads = status[board].threads || {};
if (status[board].threads[threadid] != new_posts) {
status[board].threads[threadid] = new_posts;
update_pinned();
}
}
};
var handle_thread_404 = function(board, threadid) {
status = status || {};
status[board] = status[board] || {};
status[board].threads = status[board].threads || {};
status[board].threads[threadid] = -404; //notify 404
update_pinned();
if (status[board].threads[threadid] != -404) {
status[board].threads[threadid] = -404; //notify 404
update_pinned();
}
};
if (active_page == "thread") {
@ -386,7 +416,7 @@ $(function(){
$(window).scroll(function() {
var refresh = check_scroll();
if (refresh) {
fetch_jsons();
//fetch_jsons();
refresh = false;
}
});
@ -417,5 +447,4 @@ $(function(){
update_pinned();
fetch_jsons();
setInterval(fetch_jsons, 10000);
});

161
static/d10.svg Normal file

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 9.4 KiB

View File

@ -633,3 +633,12 @@ pre {
padding: 0;
margin: 5px 25px 5px 5px;
}
/* live-index.js */
.new-posts {
opacity: 0.6;
margin-top: 1em;
}
.new-threads {
text-align: center;
}

View File

@ -305,3 +305,11 @@ var max_images = {{ config.max_images }};
var _gaq = _gaq || [];_gaq.push(['_setAccount', '{% endraw %}{{ config.google_analytics }}{% raw %}']);{% endraw %}{% if config.google_analytics_domain %}{% raw %}_gaq.push(['_setDomainName', '{% endraw %}{{ config.google_analytics_domain }}{% raw %}']){% endraw %}{% endif %}{% if not config.google_analytics_domain %}{% raw %}_gaq.push(['_setDomainName', 'none']){% endraw %}{% endif %}{% raw %};_gaq.push(['_trackPageview']);(function() {var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;ga.src = ('https:' == document.location.protocol ? 'https://' : 'http://') + 'stats.g.doubleclick.net/dc.js';var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);})();{% endraw %}{% endif %}
{% if config.statcounter_project and config.statcounter_security %}
var sc = document.createElement('script');
sc.type = 'text/javascript';
sc.innerHTML = 'var sc_project={{ config.statcounter_project }};var sc_invisible=1;var sc_security="{{ config.statcounter_security }}";var scJsHost=(("https:" == document.location.protocol) ? "https://secure." : "http://www.");document.write("<sc"+"ript type=text/javascript src="+scJsHost+"statcounter.com/counter/counter.js></"+"script>");';
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(sc, s);
{% endif %}