Recent posts functionality
Conflicts: inc/config.php inc/mod/pages.php mod.php
This commit is contained in:
parent
eac7d10ee0
commit
fb2b66e2dd
@ -1376,6 +1376,8 @@
|
|||||||
$config['mod']['view_ban_appeals'] = MOD;
|
$config['mod']['view_ban_appeals'] = MOD;
|
||||||
// Accept and deny ban appeals
|
// Accept and deny ban appeals
|
||||||
$config['mod']['ban_appeals'] = MOD;
|
$config['mod']['ban_appeals'] = MOD;
|
||||||
|
// View the recent posts page
|
||||||
|
$config['mod']['recent'] = MOD;
|
||||||
|
|
||||||
// Config editor permissions
|
// Config editor permissions
|
||||||
$config['mod']['config'] = array();
|
$config['mod']['config'] = array();
|
||||||
|
@ -2213,6 +2213,72 @@ function mod_report_dismiss($id, $all = false) {
|
|||||||
header('Location: ?/reports', true, $config['redirect_http']);
|
header('Location: ?/reports', true, $config['redirect_http']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function mod_recent_posts($lim) {
|
||||||
|
global $config, $mod, $pdo;
|
||||||
|
|
||||||
|
if (!hasPermission($config['mod']['recent']))
|
||||||
|
error($config['error']['noaccess']);
|
||||||
|
|
||||||
|
$limit = (is_numeric($lim))? $lim : 25;
|
||||||
|
|
||||||
|
$mod_boards = array();
|
||||||
|
$boards = listBoards();
|
||||||
|
|
||||||
|
//if not all boards
|
||||||
|
if ($mod['boards'][0]!='*') {
|
||||||
|
foreach ($boards as $board) {
|
||||||
|
if (in_array($board['uri'], $mod['boards']))
|
||||||
|
$mod_boards[] = $board;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$mod_boards = $boards;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Manually build an SQL query
|
||||||
|
$query = 'SELECT * FROM (';
|
||||||
|
foreach ($mod_boards as $board) {
|
||||||
|
$query .= sprintf('SELECT *, %s AS `board` FROM ``posts_%s`` UNION ALL ', $pdo->quote($board['uri']), $board['uri']);
|
||||||
|
}
|
||||||
|
// Remove the last "UNION ALL" seperator and complete the query
|
||||||
|
$query = preg_replace('/UNION ALL $/', ') AS `all_posts` ORDER BY `time` DESC LIMIT ' . $limit, $query);
|
||||||
|
$query = query($query) or error(db_error());
|
||||||
|
$posts = $query->fetchAll(PDO::FETCH_ASSOC);
|
||||||
|
|
||||||
|
$body = '<h4>Viewing last '.$limit.' posts</h4>
|
||||||
|
<p>View <a href="?/recent/25"> 25 </a>|<a href="?/recent/50"> 50 </a>|<a href="?/recent/100"> 100 </a></p>
|
||||||
|
<a href="javascript:void(0)" id="erase-local-data" style="float:right; clear:both">Erase local data</a></div>';
|
||||||
|
foreach ($posts as $post) {
|
||||||
|
openBoard($post['board']);
|
||||||
|
if (!$post['thread']) {
|
||||||
|
// Still need to fix this:
|
||||||
|
$po = new Thread($post, '?/', $mod, false);
|
||||||
|
$string = $po->build(true);
|
||||||
|
$replacement = str_replace('<p class="fileinfo">',
|
||||||
|
'<div class="post-wrapper" data-board="'.$post['board'].'"><a class="eita-link" id="eita-'.$post['board'].'-'.$post['id'].'" href="?/'.$post['board'].'/res/'.$post['id'].'.html#'.$post['id'].'">/'.$post['board'].'/'.$post['id'].'</a><br><p class="fileinfo">',
|
||||||
|
$string);
|
||||||
|
} else {
|
||||||
|
$po = new Post($post, '?/', $mod);
|
||||||
|
$string = $po->build(true);
|
||||||
|
$replacement = str_replace('<div class="post reply"',
|
||||||
|
'<div class="post-wrapper" data-board="'.$post['board'].'"><a class="eita-link" id="eita-'.$post['board'].'-'.$post['id'].'" href="?/'.$post['board'].'/res/'.$post['thread'].'.html#'.$post['id'].'">/'.$post['board'].'/'.$post['id'].'</a><br><div class="post reply"',
|
||||||
|
$string);
|
||||||
|
}
|
||||||
|
$body .= $replacement . '</div>';
|
||||||
|
}
|
||||||
|
|
||||||
|
echo Element('modpage.html', array(
|
||||||
|
'config' => $config,
|
||||||
|
'mod' => $mod,
|
||||||
|
'hide_dashboard_link' => true,
|
||||||
|
'title' => _('Recent posts'),
|
||||||
|
'subtitle' => '',
|
||||||
|
'nojavascript' => false,
|
||||||
|
'is_recent_posts' => true,
|
||||||
|
'body' => $body
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
function mod_config($board_config = false) {
|
function mod_config($board_config = false) {
|
||||||
global $config, $mod, $board;
|
global $config, $mod, $board;
|
||||||
|
73
js/recent-posts.js
Normal file
73
js/recent-posts.js
Normal file
@ -0,0 +1,73 @@
|
|||||||
|
/*
|
||||||
|
* recent-posts.js
|
||||||
|
*
|
||||||
|
* Recent posts controlling script
|
||||||
|
*
|
||||||
|
* Released under the WTFPL license
|
||||||
|
* Copyright (c) 2014 sinuca <#55ch@rizon.net>
|
||||||
|
*
|
||||||
|
* Requires jquery
|
||||||
|
* incomplete
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
$(document).ready(function(){
|
||||||
|
|
||||||
|
if (!localStorage.hiddenrecentposts)
|
||||||
|
localStorage.hiddenrecentposts = '{}';
|
||||||
|
|
||||||
|
if (!localStorage.recentpostscount)
|
||||||
|
localStorage.recentpostscount = 25;
|
||||||
|
|
||||||
|
// Load data from HTML5 localStorage
|
||||||
|
var hidden_data = JSON.parse(localStorage.hiddenrecentposts);
|
||||||
|
|
||||||
|
var store_data_posts = function() {
|
||||||
|
localStorage.hiddenrecentposts = JSON.stringify(hidden_data);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Delete old hidden posts (7+ days old)
|
||||||
|
for (var key in hidden_data) {
|
||||||
|
for (var id in hidden_data[key]) {
|
||||||
|
if (hidden_data[key][id] < Math.round(Date.now() / 1000) - 60 * 60 * 24 * 7) {
|
||||||
|
delete hidden_data[key][id];
|
||||||
|
store_data_posts();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var do_hide_posts = function() {
|
||||||
|
var data = $(this).attr('id');
|
||||||
|
var splitted = data.split('-');
|
||||||
|
var id = splitted[2];
|
||||||
|
var post_container = $(this).parent();
|
||||||
|
|
||||||
|
var board = post_container.data("board");
|
||||||
|
|
||||||
|
if (!hidden_data[board]) {
|
||||||
|
hidden_data[board] = {};
|
||||||
|
}
|
||||||
|
|
||||||
|
$('<a class="hide-post-link" href="javascript:void(0)"> Dismiss </a>')
|
||||||
|
.insertBefore(post_container.find('a.eita-link:first'))
|
||||||
|
.click(function(){
|
||||||
|
hidden_data[board][id] = Math.round(Date.now() / 1000);
|
||||||
|
store_data_posts();
|
||||||
|
|
||||||
|
post_container.closest('hr').hide();
|
||||||
|
post_container.children().hide();
|
||||||
|
});
|
||||||
|
if(hidden_data[board][id])
|
||||||
|
post_container.find('a.hide-post-link').click();
|
||||||
|
}
|
||||||
|
|
||||||
|
$('a.eita-link').each(do_hide_posts);
|
||||||
|
|
||||||
|
$('#erase-local-data').click(function(){
|
||||||
|
hidden_data = {};
|
||||||
|
store_data_posts();
|
||||||
|
$(this).html('Loading...');
|
||||||
|
location.reload();
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
2
mod.php
2
mod.php
@ -65,6 +65,8 @@ $pages = array(
|
|||||||
'/bans/(\d+)' => 'secure_POST bans', // ban list
|
'/bans/(\d+)' => 'secure_POST bans', // ban list
|
||||||
'/ban-appeals' => 'secure_POST ban_appeals', // view ban appeals
|
'/ban-appeals' => 'secure_POST ban_appeals', // view ban appeals
|
||||||
|
|
||||||
|
'/recent/(\d+)' => 'recent_posts', // view recent posts
|
||||||
|
|
||||||
'/search' => 'search_redirect', // search
|
'/search' => 'search_redirect', // search
|
||||||
'/search/(posts|IP_notes|bans|log)/(.+)/(\d+)' => 'search', // search
|
'/search/(posts|IP_notes|bans|log)/(.+)/(\d+)' => 'search', // search
|
||||||
'/search/(posts|IP_notes|bans|log)/(.+)' => 'search', // search
|
'/search/(posts|IP_notes|bans|log)/(.+)' => 'search', // search
|
||||||
|
5
templates/mod/recent_posts.html
Normal file
5
templates/mod/recent_posts.html
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
{% if posts|count %}
|
||||||
|
<p style="text-align:center" class="unimportant">({% trans 'There are no active posts.' %})</p>
|
||||||
|
{% else %}
|
||||||
|
|
||||||
|
{% endif %}
|
Loading…
Reference in New Issue
Block a user