Getting SMF working again under the new setup
Jeremy D

Jeremy D commited on 2012-01-23 20:13:21
Showing 6 changed files, with 115 additions and 51 deletions.

... ...
@@ -1,32 +1,18 @@
1 1
 <?php
2 2
 
3
-// Show me the sauce.
4
-if (isset($_GET['sauce2']))
5
-{
6
-	echo '<!DOCTYPE html><html><head><title>PasteBin Source code</title></head><body>';
7
-
8
-	if (isset($_GET['f']) && $_GET['f'] == 'settings')
9
-		highlight_file(dirname(__FILE__) . '/settings.php');
10
-	elseif (isset($_GET['f']) && $_GET['f'] == 'language')
11
-		highlight_file(dirname(__FILE__) . '/languages/english.php');
12
-	else
13
-		highlight_file(__FILE__);
14
-
15
-	exit('</body></html>');
16
-}
3
+// Load the primary file.
4
+require_once(dirname(__FILE__) . '/settings.php');
17 5
 
18
-error_reporting(E_ALL);
19
-$_SERVER['REQUEST_URI'] = '/pastebin';
20
-require_once('../wp-ssi.php');
21
-$specialPage['noClear'] = true;
22
-$specialPage['class'] = 'post';
23
-$specialPage['contentClass'] = '';
24
-$specialPage['headerTitle'] = 'PasteBin';
25
-$specialPage['pageTitlePrefix'] = 'PasteBin';
6
+// Do a preload if needed.
7
+if (pBS::get('preload') != '' && file_exists(dirname(__FILE__) . '/' . pBS::get('preload')))
8
+	require_once(dirname(__FILE__) . '/' . pBS::get('preload'));
26 9
 
27 10
 // Start the PasteBin up.
28 11
 $pasteBin = new pB();
29 12
 
13
+// Show our recent section.
14
+$pasteBin->showRecent();
15
+
30 16
 // Modified for WordPress, but this handles the sidebar and css.
31 17
 if (defined('WPLANG'))
32 18
 {
... ...
@@ -48,6 +34,23 @@ else
48 34
 if (defined('WPLANG'))
49 35
 	$specialPage['title'] = $pasteBin->title;
50 36
 
37
+/*
38
+		// Added this for myself.
39
+		if (defined('WPLANG2'))
40
+			echo '
41
+			<br />
42
+			<ul>
43
+				<li class="widget">
44
+					<h2 class="widgettitle">See the Source</h2>
45
+					<ul>
46
+						<li><a href="./?sauce">Main Script</li>
47
+						<li><a href="./?sauce&f=settings">Settings</li>
48
+						<li><a href="./?sauce&f=language">Language</li>
49
+					</ul>
50
+				</li>
51
+			</ul>';
52
+*/
53
+
51 54
 /*
52 55
 * Main PasteBin class
53 56
 */
... ...
@@ -68,9 +71,6 @@ class pB
68 71
 	*/
69 72
 	public function __construct()
70 73
 	{
71
-		// Load the primary file.
72
-		require_once(dirname(__FILE__) . '/settings.php');
73
-
74 74
 		// Load up any settings that apply only to this pastebin.
75 75
 		if (file_exists(dirname(__FILE__) . '/settings-' . pathinfo(basename($_SERVER['SCRIPT_FILENAME']), PATHINFO_FILENAME) . '.php'))
76 76
 			require_once(dirname(__FILE__) . '/settings-' . pathinfo(basename($_SERVER['SCRIPT_FILENAME']), PATHINFO_FILENAME). '.php');
... ...
@@ -84,7 +84,9 @@ class pB
84 84
 			$class = 'pDB_' . pBS::get('db');
85 85
 			if (class_exists($class))
86 86
 				$this->db = new $class;
87
+			// @NOTE: NEEDS ERRORS HERE
87 88
 		}
89
+		// @NOTE: NEEDS ERRORS HERE
88 90
 
89 91
 		// Start up our User handler.
90 92
 		require_once(pBS::get('sources') . '/user.php');
... ...
@@ -95,7 +97,9 @@ class pB
95 97
 			$class = 'pUser_' . pBS::get('user');
96 98
 			if (class_exists($class))
97 99
 				$this->usr = new $class;
100
+			// @NOTE: NEEDS ERRORS HERE
98 101
 		}
102
+		// @NOTE: NEEDS ERRORS HERE
99 103
 
100 104
 		// Start up our User handler.
101 105
 		require_once(pBS::get('sources') . '/tpl.php');
... ...
@@ -103,19 +107,16 @@ class pB
103 107
 		{
104 108
 			require_once(pBS::get('sources') . '/tpl-' . pBS::get('tpl') . '.php');
105 109
 
106
-			$class = 'pTPL_' . pBS::get('user');
110
+			$class = 'pTPL_' . pBS::get('tpl');
107 111
 			if (class_exists($class))
108 112
 				$this->tpl = new $class;
113
+			// @NOTE: NEEDS ERRORS HERE
109 114
 		}
115
+		// @NOTE: NEEDS ERRORS HERE
110 116
 
111 117
 		// Start getting things going.
112 118
 		$this->loadLanguage();
113 119
 		$this->loadGeshi();
114
-
115
-		// At this point we are ready to go.
116
-		if (pBS::get('smf_use_theme'))
117
-			echo '
118
-			<div id="paste_recent" class="alignright">', $this->showRecent(), '</div>';
119 120
 	}
120 121
 
121 122
 	/*
... ...
@@ -244,6 +245,9 @@ class pB
244 245
 	{
245 246
 		$this->title = pBL('index_title');
246 247
 
248
+		if (is_callable(array($this->tpl, 'htmlHead')))
249
+			$this->tpl->htmlHead($this->title);
250
+
247 251
 		// Trying to save this paste?
248 252
 		if (isset($_POST['save']))
249 253
 			$warnings = $this->makePaste(0);
... ...
@@ -253,6 +257,9 @@ class pB
253 257
 			echo '<div class="error_message">', implode('<br />', $warnings), '</div>';
254 258
 
255 259
 		$this->postForm((!empty($_POST['code']) ? $_POST['code'] : ''));
260
+
261
+		if (is_callable(array($this->tpl, 'htmlFooter')))
262
+			$this->tpl->htmlFooter();
256 263
 	}
257 264
 
258 265
 	/*
... ...
@@ -263,6 +270,9 @@ class pB
263 270
 	{
264 271
 		$this->title = pBL('view_title', $id);
265 272
 
273
+		if (is_callable(array($this->tpl, 'htmlHead')))
274
+			$this->tpl->htmlHead($this->title);
275
+
266 276
 		$paste = $this->showPaste($id);
267 277
 
268 278
 		if (!empty($paste['key']) && $this->usr->is_admin())
... ...
@@ -277,6 +287,9 @@ class pB
277 287
 			</div>';
278 288
 
279 289
 		$this->postForm($paste['body'], $id, $paste['use_geshi'], $paste['language']);
290
+
291
+		if (is_callable(array($this->tpl, 'htmlFooter')))
292
+			$this->tpl->htmlFooter();
280 293
 	}
281 294
 
282 295
 	/*
... ...
@@ -339,6 +352,10 @@ class pB
339 352
 		if ($recent_limit > 0)
340 353
 			$recent = $this->db->fetchRecent($recent_limit);
341 354
 
355
+		// Start to wrap it in a template if needed.
356
+		if (is_callable(array($this->tpl, 'recentTop')))
357
+			$this->tpl->recentTop();
358
+
342 359
 		// Output this.
343 360
 		echo '
344 361
 			<ul>		
... ...
@@ -356,20 +373,8 @@ class pB
356 373
 				</li>
357 374
 			</ul>';
358 375
 
359
-		// Added this for myself.
360
-		if (defined('WPLANG2'))
361
-			echo '
362
-			<br />
363
-			<ul>
364
-				<li class="widget">
365
-					<h2 class="widgettitle">See the Source</h2>
366
-					<ul>
367
-						<li><a href="./?sauce">Main Script</li>
368
-						<li><a href="./?sauce&f=settings">Settings</li>
369
-						<li><a href="./?sauce&f=language">Language</li>
370
-					</ul>
371
-				</li>
372
-			</ul>';
376
+		if (is_callable(array($this->tpl, 'recentBottom')))
377
+			$this->tpl->recentBottom();
373 378
 	}
374 379
 
375 380
 	/*
... ...
@@ -381,6 +386,9 @@ class pB
381 386
 	*/
382 387
 	public function postForm($code, $id = 0, $use_geshi = true, $geshi_language = 'php')
383 388
 	{
389
+		if (is_callable(array($this->tpl, 'postTop')))
390
+			$this->tpl->postTop();
391
+
384 392
 		echo '
385 393
 			<form method="post" action="', $this->URL('post'), '">
386 394
 				<div id="name_container">
... ...
@@ -414,9 +422,9 @@ class pB
414 422
 				</div>
415 423
 
416 424
 				<div id="code_container">
417
-					<div id="code_text" class="container"text">', pBL('code'), ':</div>
425
+					<div id="code_textf" class="container"text">', pBL('code'), ':</div>
418 426
 					<div id="code_value" class="container_value">
419
-						<textarea name="code" style="width: 100%;" rows="30">', $code, '</textarea>
427
+						<textarea name="code" rows="30">', $code, '</textarea>
420 428
 					</div>
421 429
 				</div>
422 430
 
... ...
@@ -459,6 +467,9 @@ class pB
459 467
 		echo '
460 468
 				<input id="submit" type="submit" name="submit" value="', pBL('submit'), '" />
461 469
 			</form>';
470
+
471
+		if (is_callable(array($this->tpl, 'postBottom')))
472
+			$this->tpl->postBottom();
462 473
 	}
463 474
 
464 475
 	/*
... ...
@@ -16,3 +16,14 @@ pre div
16 16
 {
17 17
 	display: inline !important;
18 18
 }
19
+
20
+#code_value textarea
21
+{
22
+	width: 100%;
23
+}
24
+
25
+/* For when in SMF */
26
+#content_section #code_value textarea
27
+{
28
+	width: 80%;
29
+}
... ...
@@ -20,6 +20,9 @@ class pBS
20 20
 	// Template Handler.
21 21
 	private static $tpl = 'smf';
22 22
 
23
+	// Any preloader file needed?
24
+	private static $preload = ''; //'__integrate.php';
25
+
23 26
 	// Language files location and default.
24 27
 	private static $languages = './languages';
25 28
 	private static $default_language = 'english';
... ...
@@ -29,7 +32,7 @@ class pBS
29 32
 	private static $smf_paste_board = 4;
30 33
 	private static $smf_increase_postcout = true;
31 34
 	private static $smf_post_approval = false;
32
-	private static $smf_use_theme = false	;
35
+	private static $smf_use_theme = true;
33 36
 	private static $smf_theme_id = 1;
34 37
 
35 38
 	// The URLs
... ...
@@ -28,6 +28,10 @@ class pDB_smf extends pDB
28 28
 		{
29 29
 			$ssi_theme = pBS::get('smf_theme_id');
30 30
 			$ssi_layers = array('html', 'body');
31
+
32
+			// Since SSI is loading the theme, we can't do this later.
33
+			$context['html_headers'] = '
34
+	<link rel="stylesheet" type="text/css" href="' . pBS::get('css')  . '" />';
31 35
 		}
32 36
 
33 37
 		require_once(pBS::get('smf_dir') . '/SSI.php');
... ...
@@ -95,7 +99,7 @@ class pDB_smf extends pDB
95 99
 		// This is how the data should return.
96 100
 		return array(
97 101
 			'id' => $topic['id_topic'],
98
-			'key' => $Paste['p'],
102
+			'key' => isset($Paste['p']) ? $Paste['p'] : '',
99 103
 			'board_id' => $topic['board_id'],
100 104
 			'approved' => $topic['approved'],
101 105
 			'use_geshi' => $Paste['use_geshi'],
... ...
@@ -10,13 +10,21 @@ class pTPL_smf extends pTPL
10 10
 	*/
11 11
 	public function __construct()
12 12
 	{
13
+		// SMF isn't started yet.
14
+		if (!defined('SMF'))
15
+		{
16
+			require_once(dirname(__FILE__) . '/db-smf.php');
17
+
18
+			$discard = new pDB_smf;
19
+			unset($discard);
20
+		}
13 21
 	}
14 22
 
15 23
 	/*
16 24
 	* Do the header
17 25
 	* @Note: Because we used ssi earlier to star the SMF theme, we have nothing to do here
18 26
 	*/
19
-	public function html_head($title)
27
+	public function htmlHead($title)
20 28
 	{
21 29
 		global $context;
22 30
 
... ...
@@ -26,8 +34,26 @@ class pTPL_smf extends pTPL
26 34
 	/*
27 35
 	* The very last thing before we close up shop.
28 36
 	*/
29
-	public function html_footer()
37
+	public function htmlFooter()
30 38
 	{
31 39
 		ssi_shutdown();
32 40
 	}
41
+
42
+	/*
43
+	* Custom code before the top part of recent.
44
+	*/
45
+	public function recentTop()
46
+	{
47
+		echo '
48
+			<div id="paste_recent" class="floatright">';
49
+	}
50
+
51
+	/*
52
+	* Custom code before the bottom part of recent.
53
+	*/
54
+	public function recentBottom()
55
+	{
56
+		echo '
57
+			</div>';
58
+	}
33 59
 }
34 60
\ No newline at end of file
... ...
@@ -15,6 +15,15 @@ class pUser_smf extends pUser
15 15
 	*/
16 16
 	public function __construct()
17 17
 	{
18
+		// SMF isn't started yet.
19
+		if (!defined('SMF'))
20
+		{
21
+			require_once(dirname(__FILE__) . '/db-smf.php');
22
+
23
+			$discard = new pDB_smf;
24
+			unset($discard);
25
+		}
26
+
18 27
 		$this->usr = userInfo::_();
19 28
 	}
20 29
 
21 30