The version of vichan running on lainchan.org
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

312 lines
10KB

  1. <?php
  2. /*
  3. Stuff to help with the display.
  4. */
  5. /*
  6. joaoptm78@gmail.com
  7. http://www.php.net/manual/en/function.filesize.php#100097
  8. */
  9. function format_bytes($size) {
  10. $units = array(' B', ' KB', ' MB', ' GB', ' TB');
  11. for ($i = 0; $size >= 1024 && $i < 4; $i++) $size /= 1024;
  12. return round($size, 2).$units[$i];
  13. }
  14. function commaize($n) {
  15. $n = strval($n);
  16. return (intval($n) < 1000) ? $n : commaize(substr($n, 0, -3)) . ',' . substr($n, -3);
  17. }
  18. function error($message) {
  19. global $board;
  20. if(function_exists('sql_close')) sql_close();
  21. die(Element('page.html', Array(
  22. 'index'=>ROOT,
  23. 'title'=>'Error',
  24. 'subtitle'=>'An error has occured.',
  25. 'body'=>"<center>" .
  26. "<h2>$message</h2>" .
  27. (isset($board) ? "<p><a href=\"" . ROOT . $board['dir'] . FILE_INDEX . "\">Go back</a>.</p>" : '').
  28. "</center>"
  29. )));
  30. }
  31. function loginForm($error=false, $username=false) {
  32. if(function_exists('sql_close')) sql_close();
  33. die(Element('page.html', Array(
  34. 'index'=>ROOT,
  35. 'title'=>'Login',
  36. 'body'=>Element('login.html', Array(
  37. 'index'=>ROOT,
  38. 'error'=>$error,
  39. 'username'=>$username
  40. )
  41. )
  42. )));
  43. }
  44. class Post {
  45. public function __construct($id, $thread, $subject, $email, $name, $trip, $body, $time, $thumb, $thumbx, $thumby, $file, $filex, $filey, $filesize, $filename, $ip, $root=ROOT, $mod=false) {
  46. $this->id = $id;
  47. $this->thread = $thread;
  48. $this->subject = utf8tohtml($subject);
  49. $this->email = $email;
  50. $this->name = utf8tohtml($name);
  51. $this->trip = $trip;
  52. $this->body = $body;
  53. $this->time = $time;
  54. $this->thumb = $thumb;
  55. $this->thumbx = $thumbx;
  56. $this->thumby = $thumby;
  57. $this->file = $file;
  58. $this->filex = $filex;
  59. $this->filey = $filey;
  60. $this->filesize = $filesize;
  61. $this->filename = $filename;
  62. $this->ip = $ip;
  63. $this->root = $root;
  64. $this->mod = $mod;
  65. }
  66. public function postControls() {
  67. $built = '';
  68. if($this->mod) {
  69. // Mod controls (on posts)
  70. $built .= '<span class="controls">';
  71. // Delete
  72. if($this->mod['type'] >= MOD_DELETE)
  73. $built .= ' <a title="Delete" href="?/b/delete/' . $this->id . '">' . MOD_LINK_DELETE . '</a>';
  74. // Delete all posts by IP
  75. if($this->mod['type'] >= MOD_DELETEBYIP)
  76. $built .= ' <a title="Delete all posts by IP" href="?/b/deletebyip/' . $this->id . '">' . MOD_LINK_DELETEBYIP . '</a>';
  77. // Ban
  78. if($this->mod['type'] >= MOD_BAN)
  79. $built .= ' <a title="Ban" href="?/b/ban/' . $this->id . '">' . MOD_LINK_BAN . '</a>';
  80. // Ban & Delete
  81. if($this->mod['type'] >= MOD_BANDELETE)
  82. $built .= ' <a title="Ban & Delete" href="?/b/ban&amp;delete/' . $this->id . '">' . MOD_LINK_BANDELETE . '</a>';
  83. // Delete file (keep post)
  84. if(!empty($this->file) && $this->mod['type'] >= MOD_DELETEFILE)
  85. $built .= ' <a title="Remove file" href="?/b/deletefile/' . $this->id . '">' . MOD_LINK_DELETEFILE . '</a>';
  86. $built .= '</span>';
  87. }
  88. return $built;
  89. }
  90. public function build($index=false) {
  91. global $board;
  92. $built = '<div class="post reply"' . (!$index?' id="reply_' . $this->id . '"':'') . '>' .
  93. '<p class="intro"' . (!$index?' id="' . $this->id . '"':'') . '>';
  94. // Subject
  95. if(!empty($this->subject))
  96. $built .= '<span class="subject">' . $this->subject . '</span> ';
  97. // Email
  98. if(!empty($this->email))
  99. $built .= '<a class="email" href="mailto:' . $this->email . '">';
  100. // Name
  101. $built .= '<span class="name">' . $this->name . '</span>'
  102. // Trip
  103. . (!empty($this->trip) ? ' <span class="trip">'.$this->trip.'</span>':'');
  104. // IP Address
  105. if($this->mod && $this->mod['type'] >= MOD_SHOW_IP) {
  106. $built .= ' [<a style="margin:0;" href="?/IP/' . $this->ip . '">' . $this->ip . '</a>]';
  107. }
  108. // End email
  109. if(!empty($this->email))
  110. $built .= '</a>';
  111. // Date/time
  112. $built .= ' ' . date(POST_DATE, $this->time);
  113. $built .= ' <a class="post_no"' .
  114. // JavaScript highlight
  115. ($index?'':' onclick="highlightReply(' . $this->id . ');"') .
  116. ' href="' . $this->root . $board['dir'] . DIR_RES . $this->thread . '.html' . '#' . $this->id . '">No.</a>' .
  117. // JavaScript cite
  118. '<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>' .
  119. '</p>';
  120. // File info
  121. if(!empty($this->file) && $this->file != 'deleted') {
  122. $built .= '<p class="fileinfo">File: <a href="' . ROOT . $board['dir'] . DIR_IMG . $this->file .'">' . $this->file . '</a> <span class="unimportant">(' .
  123. // Filesize
  124. format_bytes($this->filesize) . ', ' .
  125. // File dimensions
  126. $this->filex . 'x' . $this->filey;
  127. // Aspect Ratio
  128. if(SHOW_RATIO) {
  129. $fraction = fraction($this->filex, $this->filey, ':');
  130. $built .= ', ' . $fraction;
  131. }
  132. // Filename
  133. $built .= ', ' . $this->filename . ')</span></p>' .
  134. // Thumbnail
  135. '<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>';
  136. } elseif($this->file == 'deleted') {
  137. $built .= '<img src="' . DELETED_IMAGE . '" />';
  138. }
  139. $built .= $this->postControls();
  140. // Body
  141. $built .= '<p class="body">' . $this->body . '</p></div><br class="clear"/>';
  142. return $built;
  143. }
  144. };
  145. class Thread {
  146. public $omitted = 0;
  147. public function __construct($id, $subject, $email, $name, $trip, $body, $time, $thumb, $thumbx, $thumby, $file, $filex, $filey, $filesize, $filename, $ip, $sticky, $locked, $root=ROOT, $mod=false) {
  148. $this->id = $id;
  149. $this->subject = utf8tohtml($subject);
  150. $this->email = $email;
  151. $this->name = utf8tohtml($name);
  152. $this->trip = $trip;
  153. $this->body = $body;
  154. $this->time = $time;
  155. $this->thumb = $thumb;
  156. $this->thumbx = $thumbx;
  157. $this->thumby = $thumby;
  158. $this->file = $file;
  159. $this->filex = $filex;
  160. $this->filey = $filey;
  161. $this->filesize = $filesize;
  162. $this->filename = $filename;
  163. $this->omitted = 0;
  164. $this->posts = Array();
  165. $this->ip = $ip;
  166. $this->sticky = $sticky;
  167. $this->locked = $locked;
  168. $this->root = $root;
  169. $this->mod = $mod;
  170. }
  171. public function add(Post $post) {
  172. $this->posts[] = $post;
  173. }
  174. public function postControls() {
  175. $built = '';
  176. if($this->mod) {
  177. // Mod controls (on posts)
  178. $built .= '<span class="controls op">';
  179. // Delete
  180. if($this->mod['type'] >= MOD_DELETE)
  181. $built .= ' <a title="Delete" href="?/b/delete/' . $this->id . '">' . MOD_LINK_DELETE . '</a>';
  182. // Delete all posts by IP
  183. if($this->mod['type'] >= MOD_DELETEBYIP)
  184. $built .= ' <a title="Delete all posts by IP" href="?/b/deletebyip/' . $this->id . '">' . MOD_LINK_DELETEBYIP . '</a>';
  185. // Ban
  186. if($this->mod['type'] >= MOD_BAN)
  187. $built .= ' <a title="Ban" href="?/b/ban/' . $this->id . '">' . MOD_LINK_BAN . '</a>';
  188. // Ban & Delete
  189. if($this->mod['type'] >= MOD_BANDELETE)
  190. $built .= ' <a title="Ban & Delete" href="?/b/ban&amp;delete/' . $this->id . '">' . MOD_LINK_BANDELETE . '</a>';
  191. // Delete file (keep post)
  192. if($this->mod['type'] >= MOD_STICKY)
  193. if($this->sticky)
  194. $built .= ' <a title="Make thread not sticky" href="?/b/unsticky/' . $this->id . '">' . MOD_LINK_DESTICKY . '</a>';
  195. else
  196. $built .= ' <a title="Make thread sticky" href="?/b/sticky/' . $this->id . '">' . MOD_LINK_STICKY . '</a>';
  197. $built .= '</span>';
  198. }
  199. return $built;
  200. }
  201. public function build($index=false) {
  202. global $board;
  203. $built = '<p class="fileinfo">File: <a href="' . ROOT . $board['dir'] . DIR_IMG . $this->file .'">' . $this->file . '</a> <span class="unimportant">(' .
  204. // Filesize
  205. format_bytes($this->filesize) . ', ' .
  206. // File dimensions
  207. $this->filex . 'x' . $this->filey;
  208. // Aspect Ratio
  209. if(SHOW_RATIO) {
  210. $fraction = fraction($this->filex, $this->filey, ':');
  211. $built .= ', ' . $fraction;
  212. }
  213. // Filename
  214. $built .= ', ' . $this->filename . ')</span></p>' .
  215. // Thumbnail
  216. '<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>';
  217. $built .= '<div class="post op"><p class="intro"' . (!$index?' id="' . $this->id . '"':'') . '>';
  218. // Subject
  219. if(!empty($this->subject))
  220. $built .= '<span class="subject">' . $this->subject . '</span> ';
  221. // Email
  222. if(!empty($this->email))
  223. $built .= '<a class="email" href="mailto:' . $this->email . '">';
  224. // Name
  225. $built .= '<span class="name">' . $this->name . '</span>'
  226. // Trip
  227. . (!empty($this->trip) ? ' <span class="trip">'.$this->trip.'</span>':'');
  228. // IP Address
  229. if($this->mod && $this->mod['type'] >= MOD_SHOW_IP) {
  230. $built .= ' [<a style="margin:0;" href="?/IP/' . $this->ip . '">' . $this->ip . '</a>]';
  231. }
  232. // End email
  233. if(!empty($this->email))
  234. $built .= '</a>';
  235. // Date/time
  236. $built .= ' ' . date(POST_DATE, $this->time);
  237. $built .= ' <a class="post_no"' .
  238. // JavaScript highlight
  239. ($index?'':' onclick="highlightReply(' . $this->id . ');"') .
  240. ' href="' . $this->root . $board['dir'] . DIR_RES . $this->id . '.html' . '#' . $this->id . '">No.</a>' .
  241. // JavaScript cite
  242. '<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>' .
  243. // Sticky
  244. ($this->sticky ? '<img class="icon" title="Sticky" src="' . IMAGE_STICKY . '" />' : '') .
  245. // Locked
  246. ($this->locked ? '<img class="icon" title="Locked" src="' . IMAGE_LOCKED . '" />' : '') .
  247. // [Reply]
  248. ($index ? '<a href="' . $this->root . $board['dir'] . DIR_RES . $this->id . '.html">[Reply]</a>' : '') .
  249. // Mod controls
  250. $this->postControls() .
  251. '</p>';
  252. // Body
  253. $built .= $this->body .
  254. // Omitted posts
  255. ($this->omitted ? '<span class="omitted">' . $this->omitted . ' post' . ($this->omitted==1?'':'s') . ' omitted. Click reply to view.</span>':'') .
  256. // End
  257. '</div>';
  258. // Replies
  259. foreach($this->posts as &$post) {
  260. $built .= $post->build($index);
  261. }
  262. $built .= '<br class="clear"/><hr/>';
  263. return $built;
  264. }
  265. };
  266. ?>