1
0
mirror of https://github.com/vichan-devel/vichan.git synced 2024-11-30 18:24:29 +01:00
vichan/inc/display.php

643 lines
21 KiB
PHP
Raw Normal View History

2010-11-02 11:57:33 +01:00
<?php
2011-04-13 14:21:07 +02:00
if($_SERVER['SCRIPT_FILENAME'] == str_replace('\\', '/', __FILE__)) {
// You cannot request this file directly.
header('Location: ../', true, 302);
exit;
}
2010-11-02 11:57:33 +01:00
/*
2010-11-04 06:58:43 +01:00
Stuff to help with the display.
2010-11-02 11:57:33 +01:00
*/
/*
joaoptm78@gmail.com
http://www.php.net/manual/en/function.filesize.php#100097
*/
function format_bytes($size) {
$units = array(' B', ' KB', ' MB', ' GB', ' TB');
for ($i = 0; $size >= 1024 && $i < 4; $i++) $size /= 1024;
return round($size, 2).$units[$i];
}
2010-11-04 12:41:52 +01:00
function commaize($n) {
$n = strval($n);
return (intval($n) < 1000) ? $n : commaize(substr($n, 0, -3)) . ',' . substr($n, -3);
}
2011-02-19 10:16:13 +01:00
function doBoardListPart($list, $root) {
global $config;
$body = '';
foreach($list as $board) {
if(is_array($board))
$body .= ' [' . doBoardListPart($board, $root) . '] ';
else {
2011-03-17 13:49:28 +01:00
if(($key = array_search($board, $list)) && gettype($key) == 'string') {
$body .= ' <a href="' . $board . '">' . $key . '</a> /';
} else {
$body .= ' <a href="' . $root . $board . '/' . $config['file_index'] . '">' . $board . '</a> /';
}
2011-02-19 10:16:13 +01:00
}
}
$body = preg_replace('/\/$/', '', $body);
return $body;
}
function createBoardlist($mod=false) {
global $config;
if(!isset($config['boards'])) return Array('top'=>'','bottom'=>'');
2011-02-19 10:16:13 +01:00
$body = doBoardListPart($config['boards'], $mod?'?/':$config['root']);
if(!preg_match('/\] $/', $body))
$body = '[' . $body . ']';
2011-02-19 10:16:13 +01:00
$body = trim($body);
2011-02-20 02:39:56 +01:00
return Array(
'top' => '<div class="boardlist">' . $body . '</div>',
'bottom' => '<div class="boardlist bottom">' . $body . '</div>'
);
2011-02-19 10:16:13 +01:00
}
2010-11-04 12:41:52 +01:00
2010-11-02 11:57:33 +01:00
function error($message) {
2011-02-12 07:25:15 +01:00
global $board, $mod, $config;
2010-11-30 13:15:05 +01:00
if(defined('STDIN')) {
// Running from CLI
die('Error: ' . $message);
}
2010-11-04 12:41:52 +01:00
die(Element('page.html', Array(
'config'=>$config,
2010-11-04 12:41:52 +01:00
'title'=>'Error',
'subtitle'=>'An error has occured.',
'body'=>"<center>" .
"<h2>$message</h2>" .
(isset($board) ?
2011-02-12 07:25:15 +01:00
"<p><a href=\"" . $config['root'] .
($mod ? $config['file_mod'] . '?/' : '') .
$board['dir'] . $config['file_index'] . "\">Go back</a>.</p>" : '').
2010-11-04 12:41:52 +01:00
"</center>"
)));
2010-11-02 11:57:33 +01:00
}
function loginForm($error=false, $username=false, $redirect=false) {
2011-02-12 07:25:15 +01:00
global $config;
2010-12-01 11:24:14 +01:00
die(Element('page.html', Array(
2011-02-12 07:25:15 +01:00
'index'=>$config['root'],
2010-12-01 11:24:14 +01:00
'title'=>'Login',
2011-03-26 09:11:48 +01:00
'config'=>$config,
2010-12-01 11:24:14 +01:00
'body'=>Element('login.html', Array(
'config'=>$config,
2010-12-01 11:24:14 +01:00
'error'=>$error,
'username'=>$username,
'redirect'=>$redirect
2010-12-01 11:24:14 +01:00
)
)
)));
}
2011-04-14 20:59:04 +02:00
function pm_snippet($body, $len=null) {
2011-04-12 10:02:20 +02:00
global $config;
2011-04-14 20:59:04 +02:00
if(!isset($len))
2011-05-24 07:39:07 +02:00
$len = &$config['mod']['snippet_length'];
2011-04-14 20:59:04 +02:00
2011-04-12 10:02:20 +02:00
// Replace line breaks with some whitespace
$body = str_replace('<br/>', ' ', $body);
// Strip tags
$body = strip_tags($body);
// Unescape HTML characters, to avoid splitting them in half
$body = html_entity_decode_utf8($body);
2011-04-14 20:59:04 +02:00
$body = substr($body, 0, $len) . (strlen($body) > $len ? '…' : '');
2011-04-12 10:02:20 +02:00
// Re-escape the characters.
return '<em>' . utf8tohtml($body) . '</em>';
}
function capcode($cap) {
global $config;
if(isset($config['custom_capcode'][$cap])) {
if(is_array($config['custom_capcode'][$cap]))
return sprintf($config['custom_capcode'][$cap][0], $cap);
return sprintf($config['custom_capcode'][$cap], $cap);
}
return sprintf($config['capcode'], $cap);
}
function truncate($body, $url, $max_lines = false, $max_chars = false) {
2011-04-17 07:28:15 +02:00
global $config;
if($max_lines === false)
$max_lines = $config['body_truncate'];
if($max_chars === false)
$max_chars = $config['body_truncate_char'];
2011-04-17 07:28:15 +02:00
$original_body = $body;
$lines = substr_count($body, '<br/>');
// Limit line count
if($lines > $max_lines) {
if(preg_match('/(((.*?)<br\/>){' . $max_lines . '})/', $body, $m))
2011-04-17 07:28:15 +02:00
$body = $m[0];
}
$body = substr($body, 0, $max_chars);
2011-04-17 07:28:15 +02:00
if($body != $original_body) {
// Remove any corrupt tags at the end
$body = preg_replace('/<([\w]+)?([^>]*)?$/', '', $body);
// Open tags
if(preg_match_all('/<([\w]+)[^>]*>/', $body, $open_tags)) {
$tags = Array();
for($x=0;$x<count($open_tags[0]);$x++) {
if(!preg_match('/\/(\s+)?>$/', $open_tags[0][$x]))
$tags[] = $open_tags[1][$x];
}
// List successfully closed tags
if(preg_match_all('/(<\/([\w]+))>/', $body, $closed_tags)) {
for($x=0;$x<count($closed_tags[0]);$x++) {
unset($tags[array_search($closed_tags[1][$x], $tags)]);
}
}
// Close any open tags
foreach($tags as &$tag) {
$body .= "</{$tag}>";
}
}
$body .= '<span class="toolong">Post too long. Click <a href="' . $url . '">here</a> to view the full text.</span>';
}
return $body;
}
function confirmLink($text, $title, $confirm, $href) {
global $config, $mod;
if($config['mod']['server-side_confirm'])
return '<a onclick="if(confirm(\'' . htmlentities(addslashes($confirm)) . '\')) document.location=\'?/' . htmlentities(addslashes($href)) . '\';return false;" title="' . htmlentities($title) . '" href="?/confirm/' . $href . '">' . $text . '</a>';
else
return '<a onclick="return confirm(\'' . htmlentities(addslashes($confirm)) . '\')" title="' . htmlentities($title) . '" href="?/' . $href . '">' . $text . '</a>';
}
2010-11-02 11:57:33 +01:00
class Post {
2011-05-18 09:05:48 +02:00
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) {
2011-02-12 07:25:15 +01:00
global $config;
2011-05-24 07:39:07 +02:00
if(!isset($root)) $root = &$config['root'];
2011-02-12 07:25:15 +01:00
2010-11-02 11:57:33 +01:00
$this->id = $id;
$this->thread = $thread;
$this->subject = utf8tohtml($subject);
2010-11-02 11:57:33 +01:00
$this->email = $email;
$this->name = utf8tohtml($name);
2010-11-02 11:57:33 +01:00
$this->trip = $trip;
$this->capcode = $capcode;
2010-11-02 11:57:33 +01:00
$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;
2011-05-18 09:05:48 +02:00
$this->embed = $embed;
$this->root = $root;
$this->mod = $mod;
if($this->mod)
// Fix internal links
// Very complicated regex
$this->body = preg_replace(
2011-02-19 07:38:25 +01:00
'/<a((([a-zA-Z]+="[^"]+")|[a-zA-Z]+=[a-zA-Z]+|\s)*)href="' . preg_quote($config['root'], '/') . '(' . sprintf(preg_quote($config['board_path'], '/'), '\w+') . ')/',
'<a $1href="?/$4',
$this->body
);
2010-11-02 11:57:33 +01:00
}
2011-04-17 07:28:15 +02:00
public function link($pre = '') {
global $config, $board;
2011-05-20 14:44:11 +02:00
return $this->root . $board['dir'] . $config['dir']['res'] . sprintf($config['file_page'], $this->thread) . '#' . $pre . $this->id;
2011-04-17 07:28:15 +02:00
}
2010-12-16 16:20:16 +01:00
public function postControls() {
2011-02-12 07:25:15 +01:00
global $board, $config;
2011-01-18 06:48:39 +01:00
2010-12-16 16:20:16 +01:00
$built = '';
if($this->mod) {
2010-12-16 16:20:16 +01:00
// Mod controls (on posts)
// Delete
2011-07-03 15:05:14 +02:00
if(hasPermission($config['mod']['delete'], $board['uri'], $this->mod))
$built .= ' ' . confirmLink($config['mod']['link_delete'], 'Delete', 'Are you sure you want to delete this?', $board['uri'] . '/delete/' . $this->id);
2010-12-16 16:20:16 +01:00
// Delete all posts by IP
2011-07-03 15:05:14 +02:00
if(hasPermission($config['mod']['deletebyip'], $board['uri'], $this->mod))
$built .= ' ' . confirmLink($config['mod']['link_deletebyip'], 'Delete all posts by IP', 'Are you sure you want to delete all posts by IP?', $board['uri'] . '/deletebyip/' . $this->id);
2010-12-16 16:20:16 +01:00
// Ban
2011-07-03 15:05:14 +02:00
if(hasPermission($config['mod']['ban'], $board['uri'], $this->mod))
2011-02-12 07:25:15 +01:00
$built .= ' <a title="Ban" href="?/' . $board['uri'] . '/ban/' . $this->id . '">' . $config['mod']['link_ban'] . '</a>';
2010-12-16 16:20:16 +01:00
// Ban & Delete
2011-07-03 15:05:14 +02:00
if(hasPermission($config['mod']['bandelete'], $board['uri'], $this->mod))
2011-02-12 07:25:15 +01:00
$built .= ' <a title="Ban & Delete" href="?/' . $board['uri'] . '/ban&amp;delete/' . $this->id . '">' . $config['mod']['link_bandelete'] . '</a>';
2010-12-16 16:20:16 +01:00
// Delete file (keep post)
2011-07-03 15:05:14 +02:00
if(!empty($this->file) && hasPermission($config['mod']['deletefile'], $board['uri'], $this->mod))
2011-02-12 07:25:15 +01:00
$built .= ' <a title="Remove file" href="?/' . $board['uri'] . '/deletefile/' . $this->id . '">' . $config['mod']['link_deletefile'] . '</a>';
2010-12-16 16:20:16 +01:00
2011-07-03 15:05:14 +02:00
if(!empty($built))
$built = '<span class="controls">' . $built . '</span>';
2010-12-16 16:20:16 +01:00
}
return $built;
}
2010-11-02 11:57:33 +01:00
public function build($index=false) {
2011-05-25 12:15:47 +02:00
global $board, $config, $memcached, $debug;
2011-05-19 13:50:19 +02:00
if(!$this->mod && $config['memcached']['enabled']) {
2011-05-25 12:15:47 +02:00
if($built = $memcached->get($this->memcached_key($index))) {
if($config['debug']) {
$debug['memcached'][] = $this->memcached_key($index);
}
2011-05-19 13:50:19 +02:00
return $built;
2011-05-25 12:15:47 +02:00
}
2011-05-19 13:50:19 +02:00
}
2010-11-30 09:59:35 +01:00
$built = '<div class="post reply" id="reply_' . $this->id . '">' .
2011-01-21 03:14:55 +01:00
'<p class="intro"' . (!$index?' id="' . $this->id . '"':'') . '>' .
// Delete
'<input type="checkbox" class="delete" name="delete_' . $this->id . '" id="delete_' . $this->id . '" /><label for="delete_' . $this->id . '">';
// Subject
2010-11-05 18:47:12 +01:00
if(!empty($this->subject))
$built .= '<span class="subject">' . $this->subject . '</span> ';
// Email
if(!empty($this->email))
$built .= '<a class="email" href="mailto:' . $this->email . '">';
// Name
$built .= '<span class="name"' .
(!empty($this->capcode) && isset($config['custom_capcode'][$this->capcode][1]) ?
' style="' . $config['custom_capcode'][$this->capcode][1] . '"'
: '')
. '>' . $this->name . '</span>'
// Trip
. (!empty($this->trip) ? ' <span class="trip"' .
(!empty($this->capcode) && isset($config['custom_capcode'][$this->capcode][2]) ?
' style="' . $config['custom_capcode'][$this->capcode][2] . '"'
: '')
. '>'.$this->trip.'</span>':'')
// End email
. (!empty($this->email)? '</a>' : '')
// Capcode
. (!empty($this->capcode) ? capcode($this->capcode) : '');
// IP Address
2011-07-03 15:05:14 +02:00
if($this->mod && hasPermission($config['mod']['show_ip'], $board['uri'], $this->mod)) {
$built .= ' [<a style="margin:0;" href="?/IP/' . $this->ip . '">' . $this->ip . '</a>]';
}
// Date/time
2011-02-12 07:25:15 +01:00
$built .= ' ' . date($config['post_date'], $this->time);
2011-01-21 03:14:55 +01:00
// End delete
2011-04-13 12:02:58 +02:00
$built .= '</label>'
2011-01-21 03:14:55 +01:00
2011-04-13 12:02:58 +02:00
// Poster ID
. ($config['poster_ids'] ?
' ID: ' . poster_id($this->ip, $this->thread)
: '')
. ' <a class="post_no"' .
// JavaScript highlight
($index?'':' onclick="highlightReply(' . $this->id . ');"') .
2011-04-17 07:28:15 +02:00
' href="' . $this->link() . '">No.</a>' .
// JavaScript cite
2011-04-17 07:28:15 +02:00
'<a class="post_no"' . ($index?'':' onclick="citeReply(' . $this->id . ');"') . ' href="' . ($index ? $this->link('q') : 'javascript:void(0);') . '">'.$this->id.'</a>' .
'</p>';
2011-05-18 09:05:48 +02:00
if($this->embed) {
// Embedded video (or something else; doesn't have to be a video really)
$built .=
// Actual embedding
$this->embed;
} elseif(!empty($this->file) && $this->file != 'deleted') {
// File info
$built .= '<p class="fileinfo">' .
'File: <a href="' . $config['uri_img'] . $this->file . '">' . $this->file . '</a> ' .
'<span class="unimportant">(' .
2011-10-03 17:46:39 +02:00
($this->thumb == 'spoiler' ?
'Spoiler Image, '
: '') .
2011-05-18 09:05:48 +02:00
// Filesize
format_bytes($this->filesize) .
// File dimensions
($this->filex && $this->filey ?
', ' . $this->filex . 'x' . $this->filey
: '' );
// Aspect Ratio
if($config['show_ratio'] && $this->filex && $this->filey) {
$fraction = fraction($this->filex, $this->filey, ':');
$built .= ', ' . $fraction;
}
if($config['show_filename']) {
// Filename
2011-10-01 14:12:31 +02:00
$built .= ', ' .
(strlen($this->filename) > $config['max_filename_display'] ?
'<span title="' . $this->filename . '">' .
substr($this->filename, 0, $config['max_filename_display']) . '&hellip;' .
'</span>'
:
$this->filename
);
}
$built .= ')</span></p>' .
2011-05-18 09:05:48 +02:00
// Thumbnail
'<a href="' .
$config['uri_img'] .$this->file .
'" target="_blank"' .
($this->thumb == 'file' ? ' class="file"' : '') .
'><img src="' .
($this->thumb == 'file' ?
$config['file_thumb']
:
2011-10-03 17:46:39 +02:00
($this->thumb == 'spoiler' ?
$config['spoiler_image']
:
$config['uri_thumb'] . $this->thumb
)
) .
'" style="width:' . $this->thumbx . 'px;height:' . $this->thumby . 'px;" alt="" /></a>';
} elseif($this->file == 'deleted') {
$built .= '<img src="' . $config['image_deleted'] . '" alt="" />';
2010-12-12 16:44:43 +01:00
}
2010-12-16 16:20:16 +01:00
$built .= $this->postControls();
// Body
2011-07-06 21:22:33 +02:00
$built .= '<p class="body">' . ($index ? truncate($this->body, $this->link()) : $this->body) . '</p></div><br/>';
2011-05-19 13:50:19 +02:00
if(!$this->mod && $config['memcached']['enabled']) {
2011-05-19 13:59:25 +02:00
$memcached->set($this->memcached_key($index), $built, time() + $config['memcached']['timeout']);
2011-05-19 13:50:19 +02:00
}
2010-11-02 11:57:33 +01:00
return $built;
}
2011-05-19 13:59:25 +02:00
function memcached_key($index) {
global $board;
return 'post_' . md5($this->body) . '_' . ($this->file ? $this->file : '-') . '_' . ($index ? 'index_' : '') . $board['uri'] . '_' . $this->id;
}
2010-11-02 11:57:33 +01:00
};
class Thread {
2011-05-18 09:05:48 +02:00
public function __construct($id, $subject, $email, $name, $trip, $capcode, $body, $time, $thumb, $thumbx, $thumby, $file, $filex, $filey, $filesize, $filename, $ip, $sticky, $locked, $embed, $root=null, $mod=false, $hr=true) {
2011-02-12 07:25:15 +01:00
global $config;
2011-05-24 07:39:07 +02:00
if(!isset($root)) $root = &$config['root'];
2011-02-12 07:25:15 +01:00
2010-11-02 11:57:33 +01:00
$this->id = $id;
$this->subject = utf8tohtml($subject);
2010-11-02 11:57:33 +01:00
$this->email = $email;
$this->name = utf8tohtml($name);
2010-11-02 11:57:33 +01:00
$this->trip = $trip;
$this->capcode = $capcode;
2010-11-02 11:57:33 +01:00
$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->omitted = 0;
2011-02-17 07:07:36 +01:00
$this->omitted_images = 0;
2010-11-02 11:57:33 +01:00
$this->posts = Array();
$this->ip = $ip;
2010-12-16 13:08:52 +01:00
$this->sticky = $sticky;
2011-01-02 12:30:30 +01:00
$this->locked = $locked;
2011-05-18 09:05:48 +02:00
$this->embed = $embed;
$this->root = $root;
$this->mod = $mod;
2011-02-17 15:13:56 +01:00
$this->hr = $hr;
if($this->mod)
// Fix internal links
// Very complicated regex
$this->body = preg_replace(
2011-02-12 07:25:15 +01:00
'/<a(([a-zA-Z]+="[^"]+")|[a-zA-Z]+=[a-zA-Z]+|\s)*href="' . preg_quote($config['root'], '/') . '(' . sprintf(preg_quote($config['board_path'], '/'), '\w+') . ')/',
'<a href="?/$3',
$this->body
);
2010-11-02 11:57:33 +01:00
}
2011-04-17 07:28:15 +02:00
public function link($pre = '') {
global $config, $board;
2011-05-20 14:44:11 +02:00
return $this->root . $board['dir'] . $config['dir']['res'] . sprintf($config['file_page'], $this->id) . '#' . $pre . $this->id;
2011-04-17 07:28:15 +02:00
}
2010-11-02 11:57:33 +01:00
public function add(Post $post) {
$this->posts[] = $post;
}
2011-01-18 06:48:39 +01:00
public function postControls() {
2011-02-12 07:25:15 +01:00
global $board, $config;
2011-01-18 06:48:39 +01:00
2010-12-16 16:20:16 +01:00
$built = '';
if($this->mod) {
2010-12-16 16:20:16 +01:00
// Mod controls (on posts)
// Delete
2011-07-03 15:05:14 +02:00
if(hasPermission($config['mod']['delete'], $board['uri'], $this->mod))
$built .= ' ' . confirmLink($config['mod']['link_delete'], 'Delete', 'Are you sure you want to delete this?', $board['uri'] . '/delete/' . $this->id);
2010-12-16 16:20:16 +01:00
// Delete all posts by IP
2011-07-03 15:05:14 +02:00
if(hasPermission($config['mod']['deletebyip'], $board['uri'], $this->mod))
$built .= ' ' . confirmLink($config['mod']['link_deletebyip'], 'Delete all posts by IP', 'Are you sure you want to delete all posts by IP?', $board['uri'] . '/deletebyip/' . $this->id);
2010-12-16 16:20:16 +01:00
// Ban
2011-07-03 15:05:14 +02:00
if(hasPermission($config['mod']['ban'], $board['uri'], $this->mod))
2011-02-12 07:25:15 +01:00
$built .= ' <a title="Ban" href="?/' . $board['uri'] . '/ban/' . $this->id . '">' . $config['mod']['link_ban'] . '</a>';
2010-12-16 16:20:16 +01:00
// Ban & Delete
2011-07-03 15:05:14 +02:00
if(hasPermission($config['mod']['bandelete'], $board['uri'], $this->mod))
2011-02-12 07:25:15 +01:00
$built .= ' <a title="Ban & Delete" href="?/' . $board['uri'] . '/ban&amp;delete/' . $this->id . '">' . $config['mod']['link_bandelete'] . '</a>';
2010-12-16 16:20:16 +01:00
// Delete file (keep post)
2011-07-03 15:05:14 +02:00
if(!empty($this->file) && $this->file != 'deleted' && hasPermission($config['mod']['deletefile'], $board['uri'], $this->mod))
$built .= ' <a title="Remove file" href="?/' . $board['uri'] . '/deletefile/' . $this->id . '">' . $config['mod']['link_deletefile'] . '</a>';
// Sticky
2011-07-03 15:05:14 +02:00
if(hasPermission($config['mod']['sticky'], $board['uri'], $this->mod))
2010-12-16 16:20:16 +01:00
if($this->sticky)
2011-02-12 07:25:15 +01:00
$built .= ' <a title="Make thread not sticky" href="?/' . $board['uri'] . '/unsticky/' . $this->id . '">' . $config['mod']['link_desticky'] . '</a>';
2010-12-16 16:20:16 +01:00
else
2011-02-12 07:25:15 +01:00
$built .= ' <a title="Make thread sticky" href="?/' . $board['uri'] . '/sticky/' . $this->id . '">' . $config['mod']['link_sticky'] . '</a>';
2010-12-16 16:20:16 +01:00
2011-01-02 15:58:38 +01:00
// Lock
2011-07-03 15:05:14 +02:00
if(hasPermission($config['mod']['lock'], $board['uri'], $this->mod))
if($this->locked)
$built .= ' <a title="Unlock thread" href="?/' . $board['uri'] . '/unlock/' . $this->id . '">' . $config['mod']['link_unlock'] . '</a>';
2011-01-02 15:58:38 +01:00
else
$built .= ' <a title="Lock thread" href="?/' . $board['uri'] . '/lock/' . $this->id . '">' . $config['mod']['link_lock'] . '</a>';
2011-01-02 15:58:38 +01:00
2011-07-03 15:05:14 +02:00
if(!empty($built))
$built = '<span class="controls op">' . $built . '</span>';
2010-12-16 16:20:16 +01:00
}
return $built;
}
2010-11-02 11:57:33 +01:00
public function build($index=false) {
2011-02-12 07:25:15 +01:00
global $board, $config;
2010-11-30 09:59:35 +01:00
2011-05-18 09:05:48 +02:00
if($this->embed) {
// Embedded video (or something else; doesn't have to be a video really)
$built =
// Actual embedding
$this->embed;
} elseif(!empty($this->file) && $this->file != 'deleted') {
// File info
$built = '<p class="fileinfo">' .
'File: <a href="' . $config['uri_img'] . $this->file . '">' . $this->file . '</a> ' .
'<span class="unimportant">(' .
2011-10-03 17:46:39 +02:00
($this->thumb == 'spoiler' ?
'Spoiler Image, '
: '') .
2011-05-18 09:05:48 +02:00
// Filesize
format_bytes($this->filesize) .
// File dimensions
($this->filex && $this->filey ?
', ' . $this->filex . 'x' . $this->filey
: '' );
// Aspect Ratio
if($config['show_ratio'] && $this->filex && $this->filey) {
$fraction = fraction($this->filex, $this->filey, ':');
$built .= ', ' . $fraction;
}
if($config['show_filename']) {
// Filename
2011-10-01 14:12:31 +02:00
$built .= ', ' .
(strlen($this->filename) > $config['max_filename_display'] ?
'<span title="' . $this->filename . '">' .
substr($this->filename, 0, $config['max_filename_display']) . '&hellip;' .
'</span>'
:
$this->filename
);
}
$built .= ')</span></p>' .
2011-05-18 09:05:48 +02:00
// Thumbnail
'<a href="' .
$config['uri_img'] .$this->file .
'" target="_blank"' .
($this->thumb == 'file' ? ' class="file"' : '') .
'><img src="' .
($this->thumb == 'file' ?
$config['file_thumb']
:
2011-10-03 17:46:39 +02:00
($this->thumb == 'spoiler' ?
$config['spoiler_image']
:
$config['uri_thumb'] . $this->thumb
)
) .
'" style="width:' . $this->thumbx . 'px;height:' . $this->thumby . 'px;" alt="" /></a>';
} elseif($this->file == 'deleted') {
$built = '<img src="' . $config['image_deleted'] . '" alt="" />';
2010-11-04 07:16:47 +01:00
}
$built .= '<div class="post op"><p class="intro"' . (!$index?' id="' . $this->id . '"':'') . '>';
2011-01-21 03:14:55 +01:00
// Delete
$built .= '<input type="checkbox" class="delete" name="delete_' . $this->id . '" id="delete_' . $this->id . '" /><label for="delete_' . $this->id . '">';
2010-11-04 07:16:47 +01:00
// Subject
2010-11-05 18:53:45 +01:00
if(!empty($this->subject))
$built .= '<span class="subject">' . $this->subject . '</span> ';
2010-11-04 07:16:47 +01:00
// Email
if(!empty($this->email))
$built .= '<a class="email" href="mailto:' . $this->email . '">';
// Name
$built .= '<span class="name">' . $this->name . '</span>'
// Trip
. (!empty($this->trip) ? ' <span class="trip">'.$this->trip.'</span>':'')
// End email
. (!empty($this->email)? '</a>' : '')
// Capcode
. (!empty($this->capcode) ? capcode($this->capcode) : '');
2010-11-04 07:16:47 +01:00
// IP Address
2011-07-03 15:05:14 +02:00
if($this->mod && hasPermission($config['mod']['show_ip'], $board['uri'], $this->mod)) {
$built .= ' [<a style="margin:0;" href="?/IP/' . $this->ip . '">' . $this->ip . '</a>]';
}
2010-11-04 07:16:47 +01:00
// Date/time
2011-02-12 07:25:15 +01:00
$built .= ' ' . date($config['post_date'], $this->time);
2010-11-04 07:16:47 +01:00
2011-01-21 03:14:55 +01:00
// End delete
2011-04-13 12:02:58 +02:00
$built .= '</label>'
// Poster ID
. ($config['poster_ids'] ?
' ID: ' . poster_id($this->ip, $this->id)
: '')
2011-01-21 03:14:55 +01:00
2011-04-13 12:02:58 +02:00
. ' <a class="post_no"' .
2010-11-04 07:16:47 +01:00
// JavaScript highlight
($index?'':' onclick="highlightReply(' . $this->id . ');"') .
2011-04-17 07:28:15 +02:00
' href="' . $this->link() . '">No.</a>' .
2010-11-04 07:16:47 +01:00
// JavaScript cite
2011-04-17 07:28:15 +02:00
'<a class="post_no"' . ($index?'':' onclick="citeReply(' . $this->id . ');"') . ' href="' . ($index ? $this->link('q') : 'javascript:void(0);') . '">'.$this->id.'</a>' .
2010-12-16 13:08:52 +01:00
// Sticky
($this->sticky ? '<img class="icon" title="Sticky" src="' . $config['image_sticky'] . '" alt="Sticky" />' : '') .
2011-01-02 12:30:30 +01:00
// Locked
($this->locked ? '<img class="icon" title="Locked" src="' . $config['image_locked'] . '" alt="Locked" />' : '') .
2010-11-04 07:16:47 +01:00
// [Reply]
2011-05-20 14:44:11 +02:00
($index ? '<a href="' . $this->root . $board['dir'] . $config['dir']['res'] . sprintf($config['file_page'], $this->id) . '">[Reply]</a>' : '') .
2010-12-16 13:08:52 +01:00
2010-12-16 07:04:10 +01:00
// Mod controls
2010-12-16 16:20:16 +01:00
$this->postControls() .
2010-11-04 07:16:47 +01:00
'</p>';
2010-12-16 07:04:10 +01:00
2010-11-04 07:16:47 +01:00
// Body
2011-04-17 07:28:15 +02:00
$built .= '<p class="body">' . ($index ? truncate($this->body, $this->link()) : $this->body) . '</p>' .
2010-11-04 07:16:47 +01:00
// Omitted posts
2011-02-17 07:07:36 +01:00
($this->omitted || $this->omitted_images? '<span class="omitted">' .
($this->omitted ?
$this->omitted . ' post' . ($this->omitted==1?'':'s') .
($this->omitted_images ? ' and ' : '')
:'') .
($this->omitted_images ?
$this->omitted_images . ' image repl' . ($this->omitted_images==1?'y':'ies')
:'') .
' omitted. Click reply to view.</span>':'') .
2010-11-04 07:16:47 +01:00
// End
'</div>';
// Replies
2010-11-02 11:57:33 +01:00
foreach($this->posts as &$post) {
$built .= $post->build($index);
}
2010-11-04 07:16:47 +01:00
2011-02-17 15:13:56 +01:00
$built .= '<br class="clear"/>' . ($this->hr ? '<hr/>' : '');
2010-11-02 11:57:33 +01:00
return $built;
}
};
?>