lainchan/inc/display.php

262 lines
8.4 KiB
PHP
Raw Normal View History

2010-11-02 06:57:33 -04:00
<?php
/*
2010-11-04 01:58:43 -04:00
Stuff to help with the display.
2010-11-02 06:57:33 -04: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 07:41:52 -04:00
function commaize($n) {
$n = strval($n);
return (intval($n) < 1000) ? $n : commaize(substr($n, 0, -3)) . ',' . substr($n, -3);
}
2010-11-02 06:57:33 -04:00
function error($message) {
2010-11-30 03:59:35 -05:00
global $board;
2010-11-30 07:15:05 -05:00
if(function_exists('sql_close')) sql_close();
2010-11-04 07:41:52 -04:00
die(Element('page.html', Array(
'index'=>ROOT,
'title'=>'Error',
'subtitle'=>'An error has occured.',
'body'=>"<center>" .
"<h2>$message</h2>" .
2010-11-30 04:41:57 -05:00
(isset($board) ? "<p><a href=\"" . ROOT . $board['dir'] . FILE_INDEX . "\">Go back</a>.</p>" : '').
2010-11-04 07:41:52 -04:00
"</center>"
)));
2010-11-02 06:57:33 -04:00
}
2010-12-01 05:24:14 -05:00
function loginForm($error=false, $username=false) {
if(function_exists('sql_close')) sql_close();
die(Element('page.html', Array(
'index'=>ROOT,
'title'=>'Login',
'body'=>Element('login.html', Array(
'index'=>ROOT,
'error'=>$error,
'username'=>$username
)
)
)));
}
2010-11-02 06:57:33 -04:00
class Post {
public function __construct($id, $thread, $subject, $email, $name, $trip, $body, $time, $thumb, $thumbx, $thumby, $file, $filex, $filey, $filesize, $filename, $ip, $root=ROOT) {
2010-11-02 06:57:33 -04:00
$this->id = $id;
$this->thread = $thread;
$this->subject = utf8tohtml($subject);
2010-11-02 06:57:33 -04:00
$this->email = $email;
$this->name = utf8tohtml($name);
2010-11-02 06:57:33 -04:00
$this->trip = $trip;
$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->root = $root;
2010-11-02 06:57:33 -04:00
}
public function build($index=false) {
global $board, $mod;
2010-11-30 03:59:35 -05:00
$built = '<div class="post reply"' . (!$index?' id="reply_' . $this->id . '"':'') . '>' .
'<p class="intro"' . (!$index?' id="' . $this->id . '"':'') . '>';
// Subject
2010-11-05 13:47:12 -04: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">' . $this->name . '</span>'
// Trip
. (!empty($this->trip) ? ' <span class="trip">'.$this->trip.'</span>':'');
// IP Address
if($mod && $mod['type'] >= MOD_SHOW_IP) {
$built .= ' [<a style="margin:0;" href="?/IP/' . $this->ip . '">' . $this->ip . '</a>]';
}
// End email
if(!empty($this->email))
$built .= '</a>';
// Date/time
$built .= ' ' . date('m/d/y (D) H:i:s', $this->time);
$built .= ' <a class="post_no"' .
// JavaScript highlight
($index?'':' onclick="highlightReply(' . $this->id . ');"') .
' href="' . $this->root . $board['dir'] . DIR_RES . $this->thread . '.html' . '#' . $this->id . '">No.</a>' .
// JavaScript cite
'<a class="post_no"' . ($index?'':'onclick="citeReply(' . $this->id . ');"') . 'href="' . ($index?$this->root . $board['dir'] . DIR_RES . $this->thread . '.html' . '#q' . $this->id:'javascript:void(0);') . '">'.$this->id.'</a>' .
'</p>';
// File info
if(!empty($this->file)) {
2010-12-10 05:22:46 -05:00
$built .= '<p class="fileinfo">File: <a href="' . ROOT . $board['dir'] . DIR_IMG . $this->file .'">' . $this->file . '</a> <span class="unimportant">(' .
// Filesize
format_bytes($this->filesize) . ', ' .
// File dimensions
$this->filex . 'x' . $this->filey;
// Aspect Ratio
if(SHOW_RATIO) {
$fraction = fraction($this->filex, $this->filey, ':');
$built .= ', ' . $fraction;
}
// Filename
2010-12-12 10:44:43 -05:00
$built .= ', ' . $this->filename . ')</span></p>' .
// Thumbnail
2010-12-12 10:44:43 -05:00
'<a href="' . ROOT . $board['dir'] . DIR_IMG . $this->file.'"><img src="' . ROOT . $board['dir'] . DIR_THUMB . $this->thumb.'" style="width:'.$this->thumbx.'px;height:'.$this->thumby.'px;" /></a>';
}
if($mod) {
// Mod controls (on posts)
$built .= '<p style="float:right;margin:0;padding:0;font-size:80%;">';
// Delete
if($mod['type'] >= MOD_DELETE)
$built .= ' <a title="Delete" href="?/b/delete/' . $this->id . '">' . MOD_LINK_DELETE . '</a>';
// Delete all posts by IP
if($mod['type'] >= MOD_DELETEBYIP)
$built .= ' <a title="Delete all posts by IP" href="?/b/deletebyip/' . $this->id . '">' . MOD_LINK_DELETEBYIP . '</a>';
// Ban
if($mod['type'] >= MOD_BAN)
$built .= ' <a title="Ban" href="?/b/ban/' . $this->id . '">' . MOD_LINK_BAN . '</a>';
// Ban & Delete
if($mod['type'] >= MOD_BANDELETE)
$built .= ' <a title="Ban & Delete" href="?/b/ban&delete/' . $this->id . '">' . MOD_LINK_BANDELETE . '</a>';
// Delete file (keep post)
if($mod['type'] >= MOD_DELETEFILE)
$built .= ' <a title="Remove file" href="?/b/file/' . $this->id . '">' . MOD_LINK_DELETEFILE . '</a>';
$built .= '</p>';
}
// Body
$built .= '<p class="body">' . $this->body . '</p></div><br class="clear"/>';
2010-11-02 06:57:33 -04:00
return $built;
}
};
class Thread {
public $omitted = 0;
public function __construct($id, $subject, $email, $name, $trip, $body, $time, $thumb, $thumbx, $thumby, $file, $filex, $filey, $filesize, $filename, $ip, $root=ROOT) {
2010-11-02 06:57:33 -04:00
$this->id = $id;
$this->subject = utf8tohtml($subject);
2010-11-02 06:57:33 -04:00
$this->email = $email;
$this->name = utf8tohtml($name);
2010-11-02 06:57:33 -04:00
$this->trip = $trip;
$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;
$this->posts = Array();
$this->ip = $ip;
$this->root = $root;
2010-11-02 06:57:33 -04:00
}
public function add(Post $post) {
$this->posts[] = $post;
}
public function build($index=false) {
global $board, $mod;
2010-11-30 03:59:35 -05:00
2010-12-10 05:22:46 -05:00
$built = '<p class="fileinfo">File: <a href="' . ROOT . $board['dir'] . DIR_IMG . $this->file .'">' . $this->file . '</a> <span class="unimportant">(' .
2010-11-04 02:16:47 -04:00
// Filesize
format_bytes($this->filesize) . ', ' .
// File dimensions
$this->filex . 'x' . $this->filey;
// Aspect Ratio
if(SHOW_RATIO) {
$fraction = fraction($this->filex, $this->filey, ':');
$built .= ', ' . $fraction;
}
// Filename
$built .= ', ' . $this->filename . ')</span></p>' .
// Thumbnail
2010-12-10 05:22:46 -05:00
'<a href="' . ROOT . $board['dir'] . DIR_IMG . $this->file.'"><img src="' . ROOT . $board['dir'] . DIR_THUMB . $this->thumb.'" style="width:'.$this->thumbx.'px;height:'.$this->thumby.'px;" /></a>';
2010-11-04 02:16:47 -04:00
$built .= '<div class="post op"><p class="intro"' . (!$index?' id="' . $this->id . '"':'') . '>';
// Subject
2010-11-05 13:53:45 -04:00
if(!empty($this->subject))
$built .= '<span class="subject">' . $this->subject . '</span> ';
2010-11-04 02:16:47 -04: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>':'');
// IP Address
if($mod && $mod['type'] >= MOD_SHOW_IP) {
$built .= ' [<a style="margin:0;" href="?/IP/' . $this->ip . '">' . $this->ip . '</a>]';
}
2010-11-04 02:16:47 -04:00
// End email
if(!empty($this->email))
$built .= '</a>';
// Date/time
$built .= ' ' . date('m/d/y (D) H:i:s', $this->time);
$built .= ' <a class="post_no"' .
// JavaScript highlight
($index?'':' onclick="highlightReply(' . $this->id . ');"') .
' href="' . $this->root . $board['dir'] . DIR_RES . $this->id . '.html' . '#' . $this->id . '">No.</a>' .
2010-11-04 02:16:47 -04:00
// JavaScript cite
'<a class="post_no"' . ($index?'':'onclick="citeReply(' . $this->id . ');"') . 'href="' . ($index?$this->root . $board['dir'] . DIR_RES . $this->id . '.html' . '#q' . $this->id:'javascript:void(0);') . '">'.$this->id.'</a>' .
2010-11-04 02:16:47 -04:00
// [Reply]
($index ? '<a href="' . $this->root . $board['dir'] . DIR_RES . $this->id . '.html">[Reply]</a>' : '') .
2010-11-04 02:16:47 -04:00
'</p>';
// Body
$built .= $this->body .
// Omitted posts
($this->omitted ? '<span class="omitted">' . $this->omitted . ' post' . ($this->omitted==1?'':'s') . ' omitted. Click reply to view.</span>':'') .
// End
'</div>';
// Replies
2010-11-02 06:57:33 -04:00
foreach($this->posts as &$post) {
$built .= $post->build($index);
}
2010-11-04 02:16:47 -04:00
2010-11-02 06:57:33 -04:00
$built .= '<br class="clear"/><hr/>';
return $built;
}
};
?>