Jeremy D commited on 2012-01-23 20:37:19
Showing 9 changed files, with 65 additions and 47 deletions.
... | ... |
@@ -27,7 +27,7 @@ else |
27 | 27 |
class pB |
28 | 28 |
{ |
29 | 29 |
/* |
30 |
- * Some basic stuff |
|
30 |
+ * Some basic stuff. |
|
31 | 31 |
*/ |
32 | 32 |
public $title = 'PasteBin'; |
33 | 33 |
private $action = 'index'; |
... | ... |
@@ -54,9 +54,11 @@ class pB |
54 | 54 |
$class = 'pDB_' . pBS::get('db'); |
55 | 55 |
if (class_exists($class)) |
56 | 56 |
$this->db = new $class; |
57 |
- // @NOTE: NEEDS ERRORS HERE |
|
57 |
+ else |
|
58 |
+ this->error('Database is defined but no such class exists.'); |
|
58 | 59 |
} |
59 |
- // @NOTE: NEEDS ERRORS HERE |
|
60 |
+ else |
|
61 |
+ this->error('No database handler is defined.'); |
|
60 | 62 |
|
61 | 63 |
// Start up our User handler. |
62 | 64 |
require_once(pBS::get('sources') . '/user.php'); |
... | ... |
@@ -67,11 +69,13 @@ class pB |
67 | 69 |
$class = 'pUser_' . pBS::get('user'); |
68 | 70 |
if (class_exists($class)) |
69 | 71 |
$this->usr = new $class; |
70 |
- // @NOTE: NEEDS ERRORS HERE |
|
72 |
+ else |
|
73 |
+ this->error('User is defined but no such class exists.'); |
|
71 | 74 |
} |
72 |
- // @NOTE: NEEDS ERRORS HERE |
|
75 |
+ else |
|
76 |
+ this->error('No user handler is defined.'); |
|
73 | 77 |
|
74 |
- // Start up our User handler. |
|
78 |
+ // Start up our Template handler. |
|
75 | 79 |
require_once(pBS::get('sources') . '/tpl.php'); |
76 | 80 |
if (file_exists(pBS::get('sources') . '/tpl-' . pBS::get('tpl') . '.php')) |
77 | 81 |
{ |
... | ... |
@@ -80,9 +84,11 @@ class pB |
80 | 84 |
$class = 'pTPL_' . pBS::get('tpl'); |
81 | 85 |
if (class_exists($class)) |
82 | 86 |
$this->tpl = new $class; |
83 |
- // @NOTE: NEEDS ERRORS HERE |
|
87 |
+ else |
|
88 |
+ this->error('Template is defined but no such class exists.'); |
|
84 | 89 |
} |
85 |
- // @NOTE: NEEDS ERRORS HERE |
|
90 |
+ else |
|
91 |
+ this->error('No template handler is defined.'); |
|
86 | 92 |
|
87 | 93 |
// Start getting things going. |
88 | 94 |
$this->loadLanguage(); |
... | ... |
@@ -114,7 +120,7 @@ class pB |
114 | 120 |
} |
115 | 121 |
|
116 | 122 |
/* |
117 |
- * Setup GeSHI |
|
123 |
+ * Setup GeSHI. |
|
118 | 124 |
*/ |
119 | 125 |
public function loadGeshi() |
120 | 126 |
{ |
... | ... |
@@ -138,21 +144,28 @@ class pB |
138 | 144 |
} |
139 | 145 |
|
140 | 146 |
/* |
141 |
- * Handle a fatal Error |
|
147 |
+ * Handle a fatal Error. |
|
148 |
+ * @param $msg String The error message to display. |
|
142 | 149 |
*/ |
143 | 150 |
public function error($msg) |
144 | 151 |
{ |
145 |
- // For now. |
|
152 |
+ // Debug this if we want to debug it. |
|
153 |
+ if (pBS::get('debug')) |
|
154 |
+ { |
|
155 |
+ echo '<pre>'; |
|
146 | 156 |
debug_print_backtrace(); |
157 |
+ echo '</pre>'; |
|
158 |
+ } |
|
159 |
+ |
|
147 | 160 |
exit($msg); |
148 | 161 |
} |
149 | 162 |
|
150 | 163 |
/* |
151 |
- * Format a URL |
|
152 |
- * @param $act string The action we want to use |
|
153 |
- * @param $sa string The value of the action |
|
164 |
+ * Format a URL for output. |
|
165 |
+ * @param $act string The action we want to use. |
|
166 |
+ * @param $sa string The value of the action. |
|
154 | 167 |
* @param $extras array An array of key => value containing extras to add to the url. |
155 |
- * @return string Return the url. |
|
168 |
+ * @return string The formated URL, ready for output in links. |
|
156 | 169 |
*/ |
157 | 170 |
public function URL($act, $sa = '', $extras = array()) |
158 | 171 |
{ |
... | ... |
@@ -174,6 +187,7 @@ class pB |
174 | 187 |
$url_prefix .= str_replace($_SERVER['DOCUMENT_ROOT'], '', __FILE__) . '?'; |
175 | 188 |
} |
176 | 189 |
|
190 |
+ // Special cases we do certain things to the url. |
|
177 | 191 |
if ($act == 'index' && $url_prefix{strlen($url_prefix) -1} == '?') |
178 | 192 |
return substr($url_prefix, 0, -1); |
179 | 193 |
elseif ($act == 'index') |
... | ... |
@@ -201,7 +215,7 @@ class pB |
201 | 215 |
} |
202 | 216 |
} |
203 | 217 |
|
204 |
- // This may happen with a portal.. |
|
218 |
+ // This may happen with a portal. |
|
205 | 219 |
if (pBS::get('use_portal')) |
206 | 220 |
$url = str_replace('?;', '?', $url); |
207 | 221 |
|
... | ... |
@@ -209,7 +223,7 @@ class pB |
209 | 223 |
} |
210 | 224 |
|
211 | 225 |
/* |
212 |
- * Show a new past form |
|
226 |
+ * Show a new past form. |
|
213 | 227 |
*/ |
214 | 228 |
public function action_index() |
215 | 229 |
{ |
... | ... |
@@ -222,7 +236,7 @@ class pB |
222 | 236 |
if (isset($_POST['save'])) |
223 | 237 |
$warnings = $this->makePaste(0); |
224 | 238 |
|
225 |
- // Show any errors |
|
239 |
+ // Show any errors. |
|
226 | 240 |
if (!empty($warnings)) |
227 | 241 |
echo '<div class="error_message">', implode('<br />', $warnings), '</div>'; |
228 | 242 |
|
... | ... |
@@ -233,8 +247,8 @@ class pB |
233 | 247 |
} |
234 | 248 |
|
235 | 249 |
/* |
236 |
- * Show a paste |
|
237 |
- * @param $id int The id of the paste |
|
250 |
+ * Show a paste. |
|
251 |
+ * @param $id int The id of the paste. |
|
238 | 252 |
*/ |
239 | 253 |
public function action_view($id) |
240 | 254 |
{ |
... | ... |
@@ -245,6 +259,7 @@ class pB |
245 | 259 |
|
246 | 260 |
$paste = $this->showPaste($id); |
247 | 261 |
|
262 |
+ // Give admins a hint what the key is. |
|
248 | 263 |
if (!empty($paste['key']) && $this->usr->is_admin()) |
249 | 264 |
echo ' |
250 | 265 |
<div class="information"><b>Key:</b> ', $paste['key'], '</div>'; |
... | ... |
@@ -301,7 +316,7 @@ class pB |
301 | 316 |
return false; |
302 | 317 |
} |
303 | 318 |
|
304 |
- // Valid Numbers only.. |
|
319 |
+ // Valid Numbers only. |
|
305 | 320 |
$result = $this->db->addPaste($data); |
306 | 321 |
|
307 | 322 |
// Send us there. |
... | ... |
@@ -312,7 +327,7 @@ class pB |
312 | 327 |
} |
313 | 328 |
|
314 | 329 |
/* |
315 |
- * Show some recent pastes |
|
330 |
+ * Show some recent pastes. |
|
316 | 331 |
*/ |
317 | 332 |
public function showRecent() |
318 | 333 |
{ |
... | ... |
@@ -343,16 +358,17 @@ class pB |
343 | 358 |
</li> |
344 | 359 |
</ul>'; |
345 | 360 |
|
361 |
+ // Close up the wrapper. |
|
346 | 362 |
if (is_callable(array($this->tpl, 'recentBottom'))) |
347 | 363 |
$this->tpl->recentBottom(); |
348 | 364 |
} |
349 | 365 |
|
350 | 366 |
/* |
351 |
- * Shows a form for making/editing a paste |
|
352 |
- * @param $code string A string containing the actual code for the code box |
|
353 |
- * @param $id (optiona) int The id of the paste |
|
367 |
+ * Shows a form for making/editing a paste. |
|
368 |
+ * @param $code string A string containing the actual code for the code box. |
|
369 |
+ * @param $id (optiona) int The id of the paste. |
|
354 | 370 |
* @param $use_geshi (optiona) bool Whether to use geshi or not. |
355 |
- * @param $geshi_language (optional) string The default language to use, ie php |
|
371 |
+ * @param $geshi_language (optional) string The default language to use, ie php. |
|
356 | 372 |
*/ |
357 | 373 |
public function postForm($code, $id = 0, $use_geshi = true, $geshi_language = 'php') |
358 | 374 |
{ |
... | ... |
@@ -365,6 +381,7 @@ class pB |
365 | 381 |
<span id="name_text" class="container_text">', pBL('user_name'), ':</span> |
366 | 382 |
<span id="name_value" class="container_value">'; |
367 | 383 |
|
384 |
+ // The user handler says you are a guest. |
|
368 | 385 |
if ($this->usr->is_guest()) |
369 | 386 |
echo ' |
370 | 387 |
<input type="text" name="name" value="', !empty($_POST['name']) ? htmlspecialchars($_POST['name']) : 'Guest', '" />'; |
... | ... |
@@ -380,6 +397,7 @@ class pB |
380 | 397 |
<span id="email_text" class="container_text">', pBL('email'), ':</span> |
381 | 398 |
<span id="email_value class="container_value">'; |
382 | 399 |
|
400 |
+ // Guests can enter their email, users get it auto filled. |
|
383 | 401 |
if ($this->usr->is_guest()) |
384 | 402 |
echo ' |
385 | 403 |
<input type="text" name="email" value="', !empty($_POST['email']) ? htmlspecialchars($_POST['email']) : 'your+name@domain.com', '" />'; |
... | ... |
@@ -443,7 +461,7 @@ class pB |
443 | 461 |
} |
444 | 462 |
|
445 | 463 |
/* |
446 |
- * Shows an existing paste |
|
464 |
+ * Shows an existing paste. |
|
447 | 465 |
* @param $id int The id of the paste to load up. |
448 | 466 |
*/ |
449 | 467 |
public function showPaste($id) |
... | ... |
@@ -27,14 +27,6 @@ class pBS |
27 | 27 |
private static $languages = './languages'; |
28 | 28 |
private static $default_language = 'english'; |
29 | 29 |
|
30 |
- // Where SMF is at. |
|
31 |
- private static $smf_dir = '../forum/'; |
|
32 |
- private static $smf_paste_board = 4; |
|
33 |
- private static $smf_increase_postcout = true; |
|
34 |
- private static $smf_post_approval = false; |
|
35 |
- private static $smf_use_theme = true; |
|
36 |
- private static $smf_theme_id = 1; |
|
37 |
- |
|
38 | 30 |
// The URLs |
39 | 31 |
private static $url_sef = true; |
40 | 32 |
private static $sef_base = '/pastebin'; |
... | ... |
@@ -58,6 +50,14 @@ class pBS |
58 | 50 |
private static $recent_limit = 10; |
59 | 51 |
private static $recent_limit_admin = 50; |
60 | 52 |
|
53 |
+ // When we are using SMF, we need to know where it is. |
|
54 |
+ private static $smf_dir = '../forum/'; |
|
55 |
+ private static $smf_paste_board = 4; |
|
56 |
+ private static $smf_increase_postcout = true; |
|
57 |
+ private static $smf_post_approval = false; |
|
58 |
+ private static $smf_use_theme = true; |
|
59 |
+ private static $smf_theme_id = 1; |
|
60 |
+ |
|
61 | 61 |
/* |
62 | 62 |
* DO NOT MODIFY THIS. |
63 | 63 |
* Allows applications to request settings without ability to change them. |
... | ... |
@@ -1,7 +1,7 @@ |
1 | 1 |
<?php |
2 | 2 |
|
3 | 3 |
/* |
4 |
-* Basic handler for database interaction |
|
4 |
+* SMF handler for database interaction. |
|
5 | 5 |
*/ |
6 | 6 |
class pDB_smf extends pDB |
7 | 7 |
{ |
... | ... |
@@ -65,7 +65,7 @@ class pDB_smf extends pDB |
65 | 65 |
|
66 | 66 |
/* |
67 | 67 |
* Fetches all the information abouta a paste. |
68 |
- * @param $id int The id of the paste |
|
68 |
+ * @param $id int The id of the paste. |
|
69 | 69 |
*/ |
70 | 70 |
public function fetchPaste($id) |
71 | 71 |
{ |
... | ... |
@@ -1,7 +1,7 @@ |
1 | 1 |
<?php |
2 | 2 |
|
3 | 3 |
/* |
4 |
-* Sets up the basic Theme handler for Pastebin |
|
4 |
+* SMF Theme handler for Pastebin. |
|
5 | 5 |
*/ |
6 | 6 |
class pTPL_smf extends pTPL |
7 | 7 |
{ |
... | ... |
@@ -21,8 +21,8 @@ class pTPL_smf extends pTPL |
21 | 21 |
} |
22 | 22 |
|
23 | 23 |
/* |
24 |
- * Do the header |
|
25 |
- * @Note: Because we used ssi earlier to star the SMF theme, we have nothing to do here |
|
24 |
+ * Do the header. |
|
25 |
+ * @Note: Because we used ssi earlier to star the SMF theme, we have nothing to do here. |
|
26 | 26 |
*/ |
27 | 27 |
public function htmlHead($title) |
28 | 28 |
{ |