summaryrefslogtreecommitdiff
path: root/inc/display.php
blob: 20e8b16d119eab5c111ba6634375c1f199ada880 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
<?php
	/*
		Shit to help with the display.
	*/
	
	
	/* 
		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];
	}
	
	function error($message) {
		die(Element('page.html', Array('index' => ROOT, 'title'=>'Error', 'subtitle'=>'An error has occured.', 'body'=>"<h1>$message</h1><p style=\"text-align:center;\"><a href=\"" . ROOT . FILE_INDEX . "\">Go back</a>.</p>")));
	}
	
	class Post {
		public function __construct($id, $thread, $subject, $email, $name, $trip, $body, $time, $thumb, $thumbx, $thumby, $file, $filex, $filey, $filesize, $filename) {
			$this->id = $id;
			$this->thread = $thread;
			$this->subject = utf8tohtml($subject);
			$this->email = $email;
			$this->name = utf8tohtml($name);
			$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;
		}
		public function build($index=false) {
			$built =	'<div class="post reply"' . (!$index?' id="reply_' . $this->id . '"':'') . '>' . 
						'<p class="intro"' . (!$index?' id="' . $this->id . '"':'') . '>';
			
			// 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>':'');
			
			// 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="' . ROOT . DIR_RES . $this->thread . '.html' . '#' . $this->id . '">No.</a>' . 
			// JavaScript cite
				'<a class="post_no"' . ($index?'':'onclick="citeReply(' . $this->id . ');"') . 'href="' . ($index?ROOT . DIR_RES . $this->thread . '.html' . '#q' . $this->id:'javascript:void(0);') . '">'.$this->id.'</a>' . 
			'</p>';
		
			// File info
			if(!empty($this->file)) {
				$built .= '<p class="fileinfo">File: <a href="'	. ROOT . $this->file .'">' . basename($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
				$built .= ', ' . $this->filename . ')</span></p>' . 
			// Thumbnail
					'<a href="' . ROOT . $this->file.'"><img src="' . ROOT . $this->thumb.'" style="width:'.$this->thumbx.'px;height:'.$this->thumby.'px;" /></a>';
			}
			
			// Body
			$built .= '<p class="body">' . $this->body . '</p></div><br class="clear"/>';
			
			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) {
			$this->id = $id;
			$this->subject = utf8tohtml($subject);
			$this->email = $email;
			$this->name = utf8tohtml($name);
			$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();
		}
		public function add(Post $post) {
			$this->posts[] = $post;
		}
		
		
		public function build($index=false) {
			$built = '<p class="fileinfo">
		File: <a href="' . ROOT . $this->file.'">'.basename($this->file).'</a> <span class="unimportant">('.format_bytes($this->filesize).', '.$this->filex.'x'.$this->filey.', '.$this->filename.')</span>
	</p>
	<a href="' . ROOT . $this->file.'"><img src="' . ROOT . $this->thumb.'" style="width:'.$this->thumbx.'px;height:'.$this->thumby.'px;" /></a>
	<div class="post op">
		<p class="intro">
			<span class="subject">
				'.$this->subject.'
			</span>
			' . ( !empty($this->email) ? '<a class="email" href="mailto:' . $this->email . '">':'') .
			'<span class="name">'
				. $this->name . 
			'</span>' . (!empty($this->trip) ? ' <span class="trip">'.$this->trip.'</span>':'')
			. ( !empty($this->email) ? '</a>':'')
			. ' ' . date('m/d/y (D) H:i:s', $this->time). '
			<a class="post_no"' . ($index?'':' onclick="highlightReply(' . $this->id . ');"') . ' href="' . ROOT . DIR_RES . $this->id . '.html' . '#' . $this->id . '">No.</a><a class="post_no"' . ($index?'':'onclick="citeReply(' . $this->id . ');"') . 'href="' . ($index?ROOT . DIR_RES . $this->id . '.html' . '#q' . $this->id:'javascript:void(0);') . '">'.$this->id.'</a>' . ($index ? '<a href="' . ROOT . DIR_RES . $this->id . '.html">[Reply]</a>' : '') . 
		'</p>'
		.$this->body.'
		' . ($this->omitted ? '<span class="omitted">' . $this->omitted . ' post' . ($this->omitted==1?'':'s') . ' omitted. Click reply to view.</span>':'') . '
	</div>';
			foreach($this->posts as &$post) {
				$built .= $post->build($index);
			}
			$built .= '<br class="clear"/><hr/>';
			return $built;
		}
	};
?>