Last active
March 9, 2018 21:03
-
-
Save flashwave/a08c5cbb81c8a567b43adc4fb6ccd362 to your computer and use it in GitHub Desktop.
old code from long ago
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
* Satoko Image Board Engine | |
* (c)Flashwave (flashii) 2014 | |
* http://flashii.net/ | |
*/ | |
// Include Language and Configuration file | |
require('config.php'); | |
include('lang/'.$satoko['language'].'.php'); | |
// Turn error reporting on or off depending on what's set in config | |
if($satoko['exposeErrors']) { | |
error_reporting(E_ALL); | |
} else { | |
error_reporting(0); | |
} | |
function error($text) { | |
return '<html> | |
<head> | |
<title>Satoko '.L_ERROR.'</title> | |
<link rel="stylesheet" type="text/css" title="switch" href="css/yotsuba.css" /> | |
</head> | |
<body style="margin-top: 20%; text-align: center;"> | |
<h1 style="font-size:36pt;">'.$text.'</h1> | |
</body> | |
</html>'; | |
} | |
// Check dependencies | |
if(version_compare(phpversion(), '5.3.0', '<')) { // PHP 5.3 or higher | |
print(error(L_PHP_OUTDATED)); | |
exit; | |
} | |
if(!extension_loaded('PDO')) { // PHP Data Objects | |
print(error(L_SQL_FUNCTION)); | |
exit; | |
} | |
/// Database Connection | |
try { | |
$sql = new PDO($pdoData['connect'], $pdoData['user'], $pdoData['pass']); // Connect to SQL server using PDO | |
} catch(PDOException $e) { | |
print(error(L_SQL_CONNECT_FAIL).$e->getMessage()); // Exit and display error message on failure | |
exit; | |
} | |
// Page generation assets | |
$boardData = array(); // Declare array | |
if($satoko['folderName']) { // Add directory title to URL if set in config | |
$boardData['title'] = "/".basename(__DIR__)."/ - ".$satoko['title']; | |
} else { | |
$boardData['title'] = $satoko['title']; | |
} | |
if($satoko['subtitleEnable']) { // Add subtitle to board name if set in config | |
$boardData['subtitle'] = $satoko['subtitle']; | |
} else { | |
$boardData['subtitle'] = null; | |
} | |
// Functions | |
function getByteSymbol($bytes) { | |
$symbols = array('B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'); | |
$exp = floor(log($bytes)/log(1024)); | |
return @sprintf("%.2f ".$symbols[$exp], ($bytes/pow(1024, floor($exp)))); | |
} | |
function desBoardHeader(&$data, $catalog = false) { | |
global $boardData, $satoko; | |
$catalogTitle = $catalog ? ' - Catalog' : ''; | |
$data .= '<!DOCTYPE html><html><head> | |
<meta http-equiv="Content-type" content="text/html; charset=UTF-8"> | |
<title>'.$boardData['title'].$catalogTitle.'</title>'; | |
foreach($satoko['styles'] as $styleUrl => $styleName) { | |
reset($satoko['styles']); | |
$mainStyle = key($satoko['styles']); | |
$alternateStyle = ($styleUrl == $mainStyle) ? '' : 'alternate '; | |
$catalogStyleMode = $catalog ? 'catalog.' : ''; | |
if(!$satoko['styleSwitching'] && $styleUrl == $mainStyle) { | |
$data .= '<link rel="'.$alternateStyle.'stylesheet" type="text/css" title="'.$styleName.'" href="'.$satoko['stylesDir'].$catalogStyleMode.$styleUrl.'" />'; | |
} elseif($satoko['styleSwitching']) { | |
$data .= '<link rel="'.$alternateStyle.'stylesheet" type="text/css" title="'.$styleName.'" href="'.$satoko['stylesDir'].$catalogStyleMode.$styleUrl.'" />'; | |
} | |
} | |
$data .= '<script type="text/javascript" charset="UTF-8" src="'.$satoko['satokojs'].'"></script> | |
<meta name="description" content="'.$satoko['description'].'" /> | |
<meta http-equiv="cache-control" content="max-age=0" /> | |
<meta http-equiv="cache-control" content="no-cache" /> | |
<meta http-equiv="expires" content="0" /> | |
<meta http-equiv="expires" content="Tue, 01 Jan 1980 1:00:00 GMT" /> | |
<meta http-equiv="pragma" content="no-cache" /> | |
</head> | |
<body> | |
<div id="top"></div> | |
<div id="boardNavDesktop">'; | |
foreach($satoko['boardNav'] as $boardNavList){ | |
$data .= '['; | |
foreach($boardNavList as $boardNavListSub) { | |
if(current($boardNavList)==1){ | |
$data .= '['; | |
} | |
$data .= '<a href="/'.$boardNavListSub.'/index.html">'.$boardNavListSub.'</a>'; | |
if(count($boardNavList >= 1)&&$boardNavListSub != end($boardNavList)){ | |
$data .= ' / '; | |
} | |
} | |
$data .= '] '; | |
} | |
$data .= '<span id="navtopright">'; | |
if($satoko['exposeManage']) { | |
$data .= '[<a href="manage.php" target="_top">'.L_MANAGE.'</a>] '; | |
} | |
$data .= '[<a href="../">'.L_HOME.'</a>] | |
</span> | |
</div> | |
<div class="boardBanner">'; | |
if($satoko['headerimgEnable']){ | |
$data .= '<img class="title" alt="'.$satoko['title'].'" src="'.$satoko['headerimg'].'" />'; | |
} | |
$data .= '<div class="boardTitle">'.$boardData['title'].'</div> | |
<div class="boardSubtitle">'.$boardData['subtitle'].'</div> | |
</div>'; | |
} | |
function desBoardFooter(&$data) { | |
global $satoko; | |
$data .= '<div id="absbot" class="absBotText"> | |
<span class="absBotDisclaimer"> | |
- <a rel="nofollow" target="_top" href="http://satoko.flashii.net/">satoko</a> + alpha -<br /> | |
'; | |
if($satoko['disclaimerEnable']){ | |
$data .= $satoko['disclaimer']; | |
} | |
$data .= '</span> | |
</div> | |
<div id="bottom"></div> | |
</body> | |
</html>'; | |
} | |
function desPostForm(&$data) { | |
global $satoko; | |
$data .= '<hr class="abovePostForm" /> | |
<div class="navLinks">'; | |
if($satoko['catalogEnable']) { | |
$data .= '[<a href="catalog.html">'.L_CATALOG.'</a>] '; | |
} | |
$data .= '[<a href="'.$satoko['phpself'].'">'.L_REFRESH.'</a>]'; | |
if($satoko['showGenerationTime']) { | |
$data .= ' ['.L_GENERATED.': '.date($satoko['dateFormat'], time()).']'; | |
} | |
$data .= '</div> | |
<form enctype="multipart/form-data" method="post" action="'.$satoko['phpself'].'" name="post"> | |
<table id="postForm" class="postForm"> | |
<tbody> | |
<tr><td>'.L_NAME.'</td><td><input name="name" type="text" /></td></tr> | |
<tr><td>'.L_EMAIL.'</td><td><input name="email" type="text" /></td></tr> | |
<tr><td>'.L_SUBJECT.'</td><td><input name="sub" type="text" /><input value="'.L_SUBMIT.'" type="submit" name="submit" /></td></tr> | |
<tr><td>'.L_COMMENT.'</td><td><textarea name="com" cols="48" rows="4" wrap="soft"></textarea></td></tr> | |
<!--<tr><td>'.L_VERIFICATION.'</td><td><img src="http://puu.sh/7EDKt.jpg" /></td></tr>--> | |
<tr><td>'.L_FILE.'</td><td><input id="postFile" name="upfile" type="file" /><div>[<label><input name="spoiler" value="on" type="checkbox">'.L_SPOILERIMG.'</label>]</div></td></tr> | |
<tr><td>'.L_PASSWORD.'</td><td><input id="postPassword" name="pwd" type="password" /> <span class="password">'.L_PASSWORDSUB.'</span></td></tr> | |
<tr class="rules"> | |
<td colspan="2"> | |
<ul class="rules">'; | |
foreach($satoko['rules'] as $rule) { | |
$data .= '<li>'.$rule.'</li>'; | |
} | |
$data .= ' </ul> | |
</td> | |
</tr> | |
</tbody> | |
</table> | |
</form>'; | |
if($satoko['announcementDisplay']){ | |
$data .= '<hr /> | |
<div class="globalMessage">'.$satoko['announcement'].'</div>'; | |
} | |
$data .= '<hr />'; | |
} | |
function desStyleSwitcher(&$data) { | |
global $satoko; | |
$data .= ' | |
<div class="stylechanger">'.L_STYLE.' <select id="styleSelector" onchange="styleChange(getSelectedStyle());">'; | |
foreach($satoko['styles'] as $styleUrl => $styleName) { | |
reset($satoko['styles']); | |
$mainStyle = key($satoko['styles']); | |
$data .= '<option value="'.$styleName.'" '; | |
if($styleUrl == $mainStyle){ | |
$data .= 'selected'; | |
} | |
$data .= '>'.$styleName.'</option>'; | |
} | |
$data .= '</select></div>'; | |
} | |
function buildBoardPage(&$data, $currentPage) { | |
global $boardData, $satoko, $sql, $pdoData; | |
$startid = $currentPage * $satoko['threadsPerPage']; | |
$data .= '<form name="delform" id="delform" action="'.$satoko['phpself'].'" method="post"> | |
<div class="board">'; | |
$boardPage = $sql->query("SELECT * FROM `".$pdoData['poststable']."` GROUP BY `thread_id` ORDER BY `dateTime` LIMIT ".$startid.",".($satoko['threadsPerPage']+$startid)); | |
while($row = $boardPage->fetch(PDO::FETCH_ASSOC)) { | |
$data .= '<div class="thread" id="t'.$row['id'].'">'; | |
$boardThread = $sql->query("SELECT * FROM `".$pdoData['poststable']."` WHERE `thread_id`='".$row['thread_id']."' LIMIT ".($satoko['threadsPostsPreview'] + 1)); | |
$tempCount=0; | |
while($row = $boardThread->fetch(PDO::FETCH_ASSOC)) { | |
$data .= '<div id="pc'.$row['id'].'" class="postContainer '; | |
if($tempCount == 0) { | |
$data .= 'opContainer">'; | |
} else { | |
$data .= 'replyContainer">'; | |
} | |
if($tempCount != 0) { | |
$data .= '<div class="sideArrows" id="sa'.$row['id'].'">>></div>'; | |
} | |
$data .= '<div id="p'.$row['id'].'" class="post '; | |
if($tempCount == 0) { | |
$data .= 'op">'; | |
} else { | |
$data .= 'reply">'; | |
} | |
if(!empty($row['file_url'])){ | |
$data .= '<div id="f'.$row['id'].'" class="file"><div id="fT'.$row['id'].'" class="fileText"> | |
'.L_FILE.': <a target="_blank" href="'.$row['file_url'].'">'.$row['file_url'].'</a>-('.getByteSymbol($row['file_size']).', '.$row['image_width'].'x'.$row['image_height'].', '.$row['file_name'].') | |
</div> | |
<a target="_blank" class="fileThumb" href="'.$row['file_url'].'"> | |
<img src="'.$row['file_url'].'" alt="'.getByteSymbol($row['file_size']).'" /> | |
</a> | |
</div>'; | |
} | |
$data .= '<div id="pi'.$row['id'].'" class="postInfo"> | |
<input type="checkbox" value="delete" name="'.$row['id'].'" /> | |
<span class="subject">'.$row['subject'].'</span> | |
<span class="nameBlock">'; | |
if(!empty($row['name'])){$data .= '<span class="name">'.$row['name'].'</span> ';}else{$data .= '<span class="name">'.$satoko['anonName'].'</span> ';} | |
if(!empty($row['trip'])){$data .= '<span class="postertrip">!'.$row['trip'].'</span> ';} | |
$data .= '</span> | |
<span class="dateTime">'.date($satoko['dateFormat'], $row['dateTime']).'</span> | |
<span class="postNum"> | |
<a href="#" title="'.L_HIGHLIGHT.'">No.</a><a href="#" title="'.L_QUOTE.'">'.$row['id'].'</a>'; | |
if($tempCount == 0) { | |
$data .= ' <span>[<a class="replylink" href="#">'.L_REPLY.'</a>]</span>'; | |
} | |
$data .= '</span> | |
</div> | |
<blockquote id="m'.$row['id'].'" class="postMessage">'.nl2br($row['comment']).'</blockquote> | |
</div></div>'; | |
++$tempCount; | |
} | |
$data .= '</div><hr />'; | |
} | |
$data .= '</div> | |
<div class="bottomCtrl"> | |
<div class="deleteform"> | |
<input name="mode" value="usrdel" type="hidden">'.L_DELETE_POST.' [<input name="onlyimgdel" value="on" type="checkbox">'.L_FILE_ONLY.'] '.L_PASSWORD.' <input id="delPassword" name="pwd" type="password"> | |
<input value="'.L_DELETE.'" type="submit"><input id="bottomReportBtn" value="'.L_REPORT.'" type="button"> | |
</div>'; | |
if($satoko['styleSwitching']) { | |
desStyleSwitcher($data); | |
} | |
$data .= ' | |
</div> | |
</form> | |
<div class="pagelist"> | |
<div class="prev"><form class="pageSwitcherForm" action="1"><input value="'.L_PREV.'" accesskey="x" type="submit"></form></div> | |
<div class="pages">'; | |
$boardPages = $sql->query("SELECT COUNT(*) FROM `".$pdoData['poststable']."` WHERE `id`==`thread_id` ORDER BY `id` DESC"); | |
if(!$boardPages){ | |
$pageCount = 0; | |
} else { | |
$pageCount = ($boardPages / $satoko['threadsPerPage']); | |
} | |
for ($pages = 0; $pages <= $satoko['boardMaxPages']; $pages++) { | |
if($pages - $pageCount!=0){ | |
$data .= '['.$pages.'] '; | |
} else { | |
if($pages == $currentPage) { | |
$data .= '[<a href="'.$pageCount.'.html"><strong>'.$pages.'</strong></a>] '; | |
} else { | |
$data .= '[<a href="'.$pageCount.'.html">'.$pages.'</a>] '; | |
} | |
} | |
} | |
$data .= '</div> | |
<div class="next"><form class="pageSwitcherForm" action="1"><input value="'.L_NEXT.'" accesskey="x" type="submit"></form></div>'; | |
if($satoko['catalogEnable']) { | |
$data .= '<div class="pages cataloglink"><a href="catalog.html">'.L_CATALOG.'</a></div>'; | |
} | |
$data .= '</div>'; | |
} | |
function buildCatalog(&$data) { | |
global $satoko, $sql, $pdoData; | |
$boardPage = $sql->query("SELECT * FROM `".$pdoData['poststable']."` GROUP BY `thread_id` ORDER BY `dateTime`"); | |
$data .= '<div class="catalog">'; | |
while($row = $boardPage->fetch(PDO::FETCH_ASSOC)) { | |
$data .= '<div class="thread" id="t'.$row['id'].'">'; | |
$boardThread = $sql->query("SELECT * FROM `".$pdoData['poststable']."` WHERE `thread_id`='".$row['thread_id']."' LIMIT ".$satoko['threadsPostsPreview']); | |
$tempCount=0; | |
while($row = $boardThread->fetch(PDO::FETCH_ASSOC)) { | |
++$tempCount; | |
$data .= '<div id="pc'.$row['id'].'" class="postContainer '; | |
if($tempCount==1){$data .= 'opContainer">';}else{$data .= 'replyContainer">';} | |
if($tempCount!=1){$data .= '<div class="sideArrows" id="sa'.$row['id'].'">>></div>';} | |
$data .= '<div id="p'.$row['id'].'" class="post '; | |
if($tempCount==1){$data .= 'op">';}else{$data .= 'reply">';} | |
if(!empty($row['file_url'])){ | |
$data .= '<div id="f'.$row['id'].'" class="file"><div id="fT'.$row['id'].'" class="fileText"> | |
'.L_FILE.': <a target="_blank" href="'.$row['file_url'].'">'.$row['file_url'].'</a>-('.getByteSymbol($row['file_size']).', '.$row['image_width'].'x'.$row['image_height'].', '.$row['file_name'].') | |
</div> | |
<a target="_blank" class="fileThumb" href="'.$row['file_url'].'"> | |
<img src="'.$row['file_url'].'" alt="'.getByteSymbol($row['file_size']).'" /> | |
</a> | |
</div>'; | |
} | |
$data .= '<div id="pi'.$row['id'].'" class="postInfo"> | |
<input type="checkbox" value="delete" name="'.$row['id'].'" /> | |
<span class="subject">'.$row['subject'].'</span> | |
<span class="nameBlock">'; | |
if(!empty($row['name'])){$data .= '<span class="name">'.$row['name'].'</span> ';}else{$data .= '<span class="name">'.$satoko['anonName'].'</span> ';} | |
if(!empty($row['trip'])){$data .= '<span class="postertrip">!'.$row['trip'].'</span> ';} | |
$data .= '</span> | |
<span class="dateTime">'.date($satoko['dateFormat'], $row['dateTime']).'</span> | |
<span class="postNum"> | |
<a href="#" title="'.L_HIGHLIGHT.'">No.</a><a href="#" title="'.L_QUOTE.'">'.$row['id'].'</a>'; | |
if($tempCount==1){$data .= ' <span>[<a class="replylink" href="#">'.L_REPLY.'</a>]</span>';} | |
$data .= '</span> | |
</div> | |
<blockquote id="m'.$row['id'].'" class="postMessage">'.nl2br($row['comment']).'</blockquote> | |
</div></div>'; | |
} | |
$data .= '</div><hr />'; | |
} | |
$data .= ' | |
</div> | |
<div class="bottomCtrl">'; | |
if($satoko['styleSwitching']) { | |
desStyleSwitcher($data); | |
} | |
$data .= '</div>'; | |
} | |
function writeBoard() { | |
global $satoko; | |
desBoardHeader($board); | |
desPostForm($board); | |
buildBoardPage($board, 0); | |
desBoardFooter($board); | |
file_put_contents($satoko['indexFile'], $board); | |
} | |
function writeCatalog() { | |
global $satoko; | |
desBoardHeader($catalog, true); | |
buildCatalog($catalog); | |
desBoardFooter($catalog); | |
file_put_contents($satoko['catalogFile'], $catalog); | |
} | |
writeBoard(); | |
if($satoko['catalogEnable']) { | |
writeCatalog(); | |
} else { | |
if(file_exists($satoko['catalogFile'])) { | |
unlink($satoko['catalogFile']); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment