diff --git a/inc/config.php b/inc/config.php index 2634f719..5e215fca 100644 --- a/inc/config.php +++ b/inc/config.php @@ -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; @@ -726,6 +731,17 @@ // Optional HTML to append to "You are banned" pages. For example, you could include instructions and/or // 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; /* * ==================== diff --git a/inc/display.php b/inc/display.php index af0ee89f..ee600ed3 100644 --- a/inc/display.php +++ b/inc/display.php @@ -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 .= ' ' . $config['mod']['link_sticky'] . ''; if (hasPermission($config['mod']['bumplock'], $board['uri'], $this->mod)) - if ($this->bumplocked) + if ($this->sage) $built .= ' ' . $config['mod']['link_bumpunlock'] . ''; else $built .= ' ' . $config['mod']['link_bumplock'] . ''; diff --git a/inc/functions.php b/inc/functions.php index 085d911f..c6751a91 100644 --- a/inc/functions.php +++ b/inc/functions.php @@ -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('@(.+?)@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)); } } diff --git a/inc/mod/pages.php b/inc/mod/pages.php index 932b2ed6..9f8fcc5c 100644 --- a/inc/mod/pages.php +++ b/inc/mod/pages.php @@ -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 diff --git a/post.php b/post.php index 8a8487e8..11792379 100644 --- a/post.php +++ b/post.php @@ -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'] .= '' . strtolower($country_code) . ''; + } + } + if ($mod && isset($post['raw']) && $post['raw']) { $post['body'] = '' . $post['body'] . ''; } diff --git a/stylesheets/style.css b/stylesheets/style.css index c0430b7c..16f99e9a 100644 --- a/stylesheets/style.css +++ b/stylesheets/style.css @@ -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; } diff --git a/templates/post_reply.html b/templates/post_reply.html index b0391f19..56832710 100644 --- a/templates/post_reply.html +++ b/templates/post_reply.html @@ -27,6 +27,9 @@ {% endif %} {% if post.mod and post.mod|hasPermission(config.mod.show_ip, board.uri) %} [{{ post.ip }}] + {% endif %} + {% if config.display_flags and post.modifiers.flag_country %} + {% endif %} @@ -49,7 +52,7 @@ {% if post.embed %} {{ post.embed }} {% elseif post.file == 'deleted' %} - + {% elseif post.file and post.file %}

File: {{ post.file }} ( @@ -87,7 +90,7 @@

- + {% elseif post.file and post.file %}

{% trans %}File:{% endtrans %} {{ post.file }} ( @@ -42,7 +42,7 @@ )

-