A few modifications:

1. Finally, clean up some of the crappy code in inc/display.php; no more extreme clutter. new Thread() and new Post() take an array as the first parameter now.

2. Poster country flags. Currently requires the "geoip" extension.

3. Give post images a classname. This was also long-overdue.
This commit is contained in:
Michael Foster 2013-08-16 21:08:01 +10:00
parent 88dff2a683
commit b666886416
8 changed files with 80 additions and 98 deletions

View File

@ -386,6 +386,11 @@
// When true, a blank password will be used for files (not usable for deletion).
$config['field_disable_password'] = false;
// Attach country flags to posts. Requires the PHP "geoip" extension to be installed:
// http://www.php.net/manual/en/intro.geoip.php. In the future, maybe I will find and include a proper
// pure-PHP geolocation library.
$config['country_flags'] = false;
// Require users to see the ban page at least once for a ban even if it has since expired.
$config['require_ban_view'] = true;
@ -727,6 +732,17 @@
// a link to an email address or IRC chat room to appeal the ban.
$config['ban_page_extra'] = '';
// Display flags (when available). This config option has no effect unless poster flags are enabled (see
// $config['country_flags']). Disable this if you want all previously-assigned flags to be hidden.
$config['display_flags'] = true;
// Location of post flags/icons (where "%s" is the flag name). Defaults to static/flags/%s.png.
// $config['uri_flags'] = 'http://static.example.org/flags/%s.png';
// Width and height of post flags:
$config['flag_width'] = 16;
$config['flag_height'] = 11;
/*
* ====================
* Javascript

View File

@ -270,36 +270,25 @@ function embed_html($link) {
}
class Post {
public function __construct($id, $thread, $subject, $email, $name, $trip, $capcode, $body, $time, $thumb, $thumbx, $thumby, $file, $filex, $filey, $filesize, $filename, $ip, $embed, $root=null, $mod=false) {
public function __construct($post, $root=null, $mod=false) {
global $config;
if (!isset($root))
$root = &$config['root'];
$this->id = $id;
$this->thread = $thread;
$this->subject = utf8tohtml($subject);
$this->email = $email;
$this->name = utf8tohtml($name);
$this->trip = $trip;
$this->capcode = $capcode;
$this->body = $body;
$this->time = $time;
$this->thumb = $thumb;
$this->thumbx = $thumbx;
$this->thumby = $thumby;
$this->file = $file;
$this->filex = $filex;
$this->filey = $filey;
$this->filesize = $filesize;
$this->filename = $filename;
$this->ip = $ip;
$this->embed = $embed;
$this->root = $root;
foreach ($post as $key => $value) {
$this->{$key} = $value;
}
$this->subject = utf8tohtml($this->subject);
$this->name = utf8tohtml($this->name);
$this->mod = $mod;
$this->root = $root;
if ($this->embed)
$this->embed = embed_html($this->embed);
$this->modifiers = extract_modifiers($this->body_nomarkup);
if ($this->mod)
// Fix internal links
// Very complicated regex
@ -367,42 +356,29 @@ class Post {
};
class Thread {
public function __construct($id, $subject, $email, $name, $trip, $capcode, $body, $time, $thumb, $thumbx, $thumby, $file, $filex, $filey, $filesize, $filename, $ip, $sticky, $locked, $bumplocked, $embed, $root=null, $mod=false, $hr=true) {
public function __construct($post, $root = null, $mod = false, $hr = true) {
global $config;
if (!isset($root))
$root = &$config['root'];
$this->id = $id;
$this->subject = utf8tohtml($subject);
$this->email = $email;
$this->name = utf8tohtml($name);
$this->trip = $trip;
$this->capcode = $capcode;
$this->body = $body;
$this->time = $time;
$this->thumb = $thumb;
$this->thumbx = $thumbx;
$this->thumby = $thumby;
$this->file = $file;
$this->filex = $filex;
$this->filey = $filey;
$this->filesize = $filesize;
$this->filename = $filename;
foreach ($post as $key => $value) {
$this->{$key} = $value;
}
$this->subject = utf8tohtml($this->subject);
$this->name = utf8tohtml($this->name);
$this->mod = $mod;
$this->root = $root;
$this->posts = array();
$this->omitted = 0;
$this->omitted_images = 0;
$this->posts = array();
$this->ip = $ip;
$this->sticky = $sticky;
$this->locked = $locked;
$this->bumplocked = $bumplocked;
$this->embed = $embed;
$this->root = $root;
$this->mod = $mod;
$this->hr = $hr;
if ($this->embed)
$this->embed = embed_html($this->embed);
$this->modifiers = extract_modifiers($this->body_nomarkup);
if ($this->mod)
// Fix internal links
// Very complicated regex
@ -462,7 +438,7 @@ class Thread {
$built .= ' <a title="'._('Make thread sticky').'" href="?/' . secure_link($board['dir'] . 'sticky/' . $this->id) . '">' . $config['mod']['link_sticky'] . '</a>';
if (hasPermission($config['mod']['bumplock'], $board['uri'], $this->mod))
if ($this->bumplocked)
if ($this->sage)
$built .= ' <a title="'._('Allow thread to be bumped').'" href="?/' . secure_link($board['dir'] . 'bumpunlock/' . $this->id) . '">' . $config['mod']['link_bumpunlock'] . '</a>';
else
$built .= ' <a title="'._('Prevent thread from being bumped').'" href="?/' . secure_link($board['dir'] . 'bumplock/' . $this->id) . '">' . $config['mod']['link_bumplock'] . '</a>';

View File

@ -149,6 +149,8 @@ function loadConfig() {
$config['url_javascript'] = $config['root'] . $config['file_script'];
if (!isset($config['additional_javascript_url']))
$config['additional_javascript_url'] = $config['root'];
if (!isset($config['uri_flags']))
$config['uri_flags'] = $config['root'] . 'static/flags/%s.png';
if ($config['root_file']) {
chdir($config['root_file']);
@ -1044,11 +1046,7 @@ function index($page, $mod=false) {
if ($query->rowCount() < 1 && $page > 1)
return false;
while ($th = $query->fetch(PDO::FETCH_ASSOC)) {
$thread = new Thread(
$th['id'], $th['subject'], $th['email'], $th['name'], $th['trip'], $th['capcode'], $th['body'], $th['time'], $th['thumb'],
$th['thumbwidth'], $th['thumbheight'], $th['file'], $th['filewidth'], $th['fileheight'], $th['filesize'], $th['filename'], $th['ip'],
$th['sticky'], $th['locked'], $th['sage'], $th['embed'], $mod ? '?/' : $config['root'], $mod
);
$thread = new Thread($th, $mod ? '?/' : $config['root'], $mod);
if ($config['cache']['enabled'] && $cached = cache::get("thread_index_{$board['uri']}_{$th['id']}")) {
$replies = $cached['replies'];
@ -1080,11 +1078,7 @@ function index($page, $mod=false) {
if ($po['file'])
$num_images++;
$thread->add(new Post(
$po['id'], $th['id'], $po['subject'], $po['email'], $po['name'], $po['trip'], $po['capcode'], $po['body'], $po['time'],
$po['thumb'], $po['thumbwidth'], $po['thumbheight'], $po['file'], $po['filewidth'], $po['fileheight'], $po['filesize'],
$po['filename'], $po['ip'], $po['embed'], $mod ? '?/' : $config['root'], $mod)
);
$thread->add(new Post($po, $mod ? '?/' : $config['root'], $mod));
}
if ($omitted) {
@ -1467,6 +1461,18 @@ function unicodify($body) {
return $body;
}
function extract_modifiers($body) {
$modifiers = array();
if (preg_match_all('@<tinyboard ([\w\s]+)>(.+?)</tinyboard>@um', $body, $matches, PREG_SET_ORDER)) {
foreach ($matches as $match) {
$modifiers[$match[1]] = $match[2];
}
}
return $modifiers;
}
function markup(&$body, $track_cites = false) {
global $board, $config, $markup_urls;
@ -1730,17 +1736,9 @@ function buildThread($id, $return = false, $mod = false) {
while ($post = $query->fetch(PDO::FETCH_ASSOC)) {
if (!isset($thread)) {
$thread = new Thread(
$post['id'], $post['subject'], $post['email'], $post['name'], $post['trip'], $post['capcode'], $post['body'], $post['time'],
$post['thumb'], $post['thumbwidth'], $post['thumbheight'], $post['file'], $post['filewidth'], $post['fileheight'], $post['filesize'],
$post['filename'], $post['ip'], $post['sticky'], $post['locked'], $post['sage'], $post['embed'], $mod ? '?/' : $config['root'], $mod
);
$thread = new Thread($post, $mod ? '?/' : $config['root'], $mod);
} else {
$thread->add(new Post(
$post['id'], $thread->id, $post['subject'], $post['email'], $post['name'], $post['trip'], $post['capcode'], $post['body'],
$post['time'], $post['thumb'], $post['thumbwidth'], $post['thumbheight'], $post['file'], $post['filewidth'], $post['fileheight'],
$post['filesize'], $post['filename'], $post['ip'], $post['embed'], $mod ? '?/' : $config['root'], $mod)
);
$thread->add(new Post($post, $mod ? '?/' : $config['root'], $mod));
}
}

View File

@ -780,19 +780,9 @@ function mod_page_ip($ip) {
while ($post = $query->fetch(PDO::FETCH_ASSOC)) {
if (!$post['thread']) {
// TODO: There is no reason why this should be such a fucking mess.
$po = new Thread(
$post['id'], $post['subject'], $post['email'], $post['name'], $post['trip'], $post['capcode'], $post['body'],
$post['time'], $post['thumb'], $post['thumbwidth'], $post['thumbheight'], $post['file'], $post['filewidth'],
$post['fileheight'], $post['filesize'], $post['filename'], $post['ip'], $post['sticky'], $post['locked'],
$post['sage'], $post['embed'], '?/', $mod, false
);
$po = new Thread($post, '?/', $mod, false);
} else {
$po = new Post(
$post['id'], $post['thread'], $post['subject'], $post['email'], $post['name'], $post['trip'], $post['capcode'],
$post['body'], $post['time'], $post['thumb'], $post['thumbwidth'], $post['thumbheight'], $post['file'], $post['filewidth'],
$post['fileheight'], $post['filesize'], $post['filename'], $post['ip'], $post['embed'], '?/', $mod
);
$po = new Post($post, '?/', $mod);
}
if (!isset($args['posts'][$board['uri']]))
@ -1907,19 +1897,9 @@ function mod_reports() {
if (!$post['thread']) {
// Still need to fix this:
$po = new Thread(
$post['id'], $post['subject'], $post['email'], $post['name'], $post['trip'],
$post['capcode'], $post['body'], $post['time'], $post['thumb'],
$post['thumbwidth'], $post['thumbheight'], $post['file'], $post['filewidth'],
$post['fileheight'], $post['filesize'], $post['filename'], $post['ip'], $post['sticky'],
$post['locked'], $post['sage'], $post['embed'], '?/', $mod, false
);
$po = new Thread($post, '?/', $mod, false);
} else {
$po = new Post(
$post['id'], $post['thread'], $post['subject'], $post['email'], $post['name'], $post['trip'], $post['capcode'],
$post['body'], $post['time'], $post['thumb'], $post['thumbwidth'], $post['thumbheight'], $post['file'], $post['filewidth'],
$post['fileheight'], $post['filesize'], $post['filename'], $post['ip'], $post['embed'], '?/', $mod
);
$po = new Post($post, '?/', $mod);
}
// a little messy and inefficient

View File

@ -421,6 +421,15 @@ if (isset($_POST['delete'])) {
wordfilters($post['body']);
$post['body'] = escape_markup_modifiers($post['body']);
if ($config['country_flags']) {
if (!geoip_db_avail(GEOIP_COUNTRY_EDITION)) {
error('GeoIP not available: ' . geoip_db_filename(GEOIP_COUNTRY_EDITION));
}
if ($country_code = @geoip_country_code_by_name('8.8.8.8')) {
$post['body'] .= '<tinyboard flag_country>' . strtolower($country_code) . '</tinyboard>';
}
}
if ($mod && isset($post['raw']) && $post['raw']) {
$post['body'] = '<tinyboard raw html>' . $post['body'] . '</tinyboard>';
}

View File

@ -129,13 +129,13 @@ img.banner {
border: 1px solid #a9a9a9;
margin: 12px auto 0 auto;
}
img {
img.post-image {
display: block;
float: left;
margin: 10px 20px;
border: none;
}
div.post img {
div.post img.post-image {
padding: 5px;
margin: 5px 20px 0 0;
}

View File

@ -28,6 +28,9 @@
{% if post.mod and post.mod|hasPermission(config.mod.show_ip, board.uri) %}
[<a style="margin:0;" href="?/IP/{{ post.ip }}">{{ post.ip }}</a>]
{% endif %}
{% if config.display_flags and post.modifiers.flag_country %}
<img class="flag" style="width:{{ config.flag_width }}px;height:{{ config.flag_height }}px" src="{{ config.uri_flags|sprintf(post.modifiers.flag_country) }}">
{% endif %}
<time datetime="{{ post.time|date('%Y-%m-%dT%H:%M:%S') }}{{ timezone() }}">{{ post.time|date(config.post_date) }}</time>
</label>
{% if config.poster_ids %}
@ -49,7 +52,7 @@
{% if post.embed %}
{{ post.embed }}
{% elseif post.file == 'deleted' %}
<img src="{{ config.image_deleted }}" alt="" />
<img class="post-image deleted" src="{{ config.image_deleted }}" alt="" />
{% elseif post.file and post.file %}
<p class="fileinfo">File: <a href="{{ config.uri_img }}{{ post.file }}">{{ post.file }}</a> <span class="unimportant">
(
@ -87,7 +90,7 @@
</span>
</p>
<a href="{{ config.uri_img }}{{ post.file }}" target="_blank"{% if post.thumb == 'file' %} class="file"{% endif %}>
<img src="
<img class="post-image" src="
{% if post.thumb == 'file' %}
{{ config.root }}
{% if config.file_icons[post.filename|extension] %}

View File

@ -6,7 +6,7 @@
{% if post.embed %}
{{ post.embed }}
{% elseif post.file == 'deleted' %}
<img src="{{ config.image_deleted }}" alt="" />
<img class="post-image deleted" src="{{ config.image_deleted }}" alt="" />
{% elseif post.file and post.file %}
<p class="fileinfo">{% trans %}File:{% endtrans %} <a href="{{ config.uri_img }}{{ post.file }}">{{ post.file }}</a> <span class="unimportant">
(
@ -42,7 +42,7 @@
)
</span></p>
<a href="{{ config.uri_img }}{{ post.file }}" target="_blank"{% if post.thumb == 'file' %} class="file"{% endif %}>
<img src="
<img class="post-image" src="
{% if post.thumb == 'file' %}
{{ config.root }}
{% if config.file_icons[post.filename|extension] %}