dev_endboard/opt/display.php

1104 lines
36 KiB
PHP

<?php
/*
* This is the endboard software, version beta 0.80
* It is a textboard written for the use in the darknets.
*
* This file holds all the functions used to display and format posts.
* It can be included without side effects.
*
* The writing of this code started some time ago with another software
* called smolBBS. Although there is almost no original code left now,
* I still regard endboard as a fork of smolBBS.
* The author of smolBBS has required that the following text be
* distributed with any redistribution, so here it goes.
* The license and other conditions apply to endboard as well.
*
* IRC: *dulm @ irc.rizon.net
*
* Copyright (C) 2020 sandlind
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* (1) Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* (2) Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* (3)The name of the author may not be used to
* endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
// Translate simple bbcode to html, and highlight quotes, like so:
// [b bold],[i italic],[u underlined],[s strikethrough]
// [h headline],[sp spoiler],[li list element],[url link],>>quote\r\n
function bbcode_to_html($text, $settings, $sub)
{
if ( ($settings['enable_bbcode'] == FALSE) ) {
return $text;
}
$search = array (
'/(\[b\ )(.*)(\])/',
'/(\[i\ )(.*)(\])/',
'/(\[u\ )(.*)(\])/',
'/(\[s\ )(.*)(\])/',
'/(\[h\ )(.*)(\])/',
'/(\[sp\ )(.*)(\])/',
'/(\[li\ )(.*)(\])/',
'/(\[url\ )(.*)(\])/',
'/ s\/(.+)\/([0-9]+)/',
'/>> ([0-9]+)\r\n/',
'/>>(.*)\r\n/'
);
$replace = array (
'<strong>$2</strong>',
'<em>$2</em>',
'<u>$2</u>',
'<s>$2</s>',
'<h2>$2</h2>',
'<spoiler>$2</spoiler>',
'<li>$2</li>',
'<a href="$2" target="_blank">$2</a>',
' <a href="/r/$1/$2">s/$1/$2</a>',
"<quote><a href=\"#$1_$sub\">>$1$2</a></quote><br>",
'<quote>>>$1$2</quote><br>'
);
return preg_replace($search, $replace, $text);
}
// Break text according to config.php, also transform \r\n to <br>
function break_text($text, $settings)
{
$post_text = wordwrap($text, $settings['line_break'], "\n", TRUE);
$post_text = nl2br($post_text, FALSE);
return $post_text;
}
// Do some magic number trickery (easteregg)
function make_id_text($post_id)
{
switch($post_id) {
case 1:
$id_text = 'first post - yeah';
break;
case 42:
$id_text = '...and thanks for all the fish...';
break;
case 69:
$id_text = "$post_id 😏";
break;
case 104:
$id_text = '10-4 affirmative';
break;
case 143:
$id_text = "$post_id 💌";
break;
case 404:
$id_text = 'content not found';
break;
case 420:
$id_text = '🌿🌿🌿';
break;
case 666:
$id_text = '👿👿👿 ';
break;
case 911:
$id_text = 'How can I help you ?';
break;
case 1312:
$id_text = 'all cats are beautiful';
break;
default:
$id_text = $post_id;
}
return $id_text;
}
// Show each post in a thread
function print_thread($db, $sub, $css, $settings, $org_id, $link_to_reply)
{
$html_string = '<div class=\'postcontainer\'>';
if ( $link_to_reply != '' ) {
$html_string .= "<a href=\"#$link_to_reply" . "_" . "$sub\""
. ">Jump to post $link_to_reply </a>";
}
$statement = $db->prepare("SELECT post_id, org_id, sub, text, timestamp,
name, tripcode, move_message,
edit_message
FROM threads WHERE sub = '$sub'
AND org_id = '$org_id'
AND shadow = 'no'
ORDER BY post_id DESC");
$result = $statement->execute();
while ($row = $result->fetchArray(SQLITE3_NUM)) {
$post_id = "{$row[0]}";
$org_id = "{$row[1]}";
$post_text = "{$row[3]}";
$post_text = break_text(bbcode_to_html($post_text, $settings, $sub),
$settings);
$id_text = make_id_text($post_id);
$timestamp = "{$row[4]}";
$name = "{$row[5]}";
$tripcode = "{$row[6]}";
$move_message = "{$row[7]}";
$edit_message = "{$row[8]}";
$html_string .= "<div><p id=\"$post_id" . "_" . "$sub\"></p>"
. "<div class='post'>#$id_text";
if ( !empty($timestamp) &&
$settings['enable_timestamps'] ) {
$html_string .= "<small>:$timestamp</small>";
}
// $html_string .= "<br><br><code>$post_text</code><br><br>";
$html_string .= "<br><br>$post_text<br><br>";
if ( !empty($name) &&
$settings['enable_edit']) {
$html_string .= "<a href='/e/$sub/$post_id/css=$css'>edit</a> ";
}
if ( !empty($name) &&
$settings['enable_tripcodes']) {
$name_string = $name;
$link_string_4 = "/u/$name_string/css=$css";
$html_string .= "<a href='$link_string_4'>$name_string</a>";
}
if ( !empty($move_message) ) {
$html_string .= "<br><small>|$move_message|</small>";
}
if ( !empty($edit_message) ) {
$html_string .= "<br><small>|$edit_message|</small>";
}
$html_string .= '</div>';
}
echo "$html_string";
}
// Show each post of the overboard (so all original posts in their
// sequence, including bumps, except for the subs that are excluded)
function print_overboard($db, $css, $settings, $page)
{
$out = '';
$pagination = $settings['pagination'];
if ( (!empty($settings['no_overboard'])) ) {
$last = array_pop($settings['no_overboard']);
foreach($settings['no_overboard'] as $no_overboard) {
$str = "'" . $no_overboard . "', ";
$out .= $str;
}
$out .= "'" . $last . "'";
}
if ($page == 'all') {
$statement = $db->prepare("SELECT post_id, org_id,
sub, text, timestamp, name,
tripcode, move_message,
edit_message
FROM threads
WHERE org_id = original
AND shadow = 'no'
AND sub NOT IN ($out)
ORDER BY ROWID DESC");
} elseif ($page > 0) {
// if the page is defined
$page_start = ($page - 1) * $settings['pagination'];
$statement = $db->prepare("SELECT post_id, org_id,
sub, text, timestamp, name,
tripcode, move_message,
edit_message
FROM threads
WHERE org_id = original
AND shadow = 'no'
AND sub NOT IN ($out)
ORDER BY ROWID DESC
LIMIT '$page_start', '$pagination'");
} else {
$statement = $db->prepare("SELECT post_id, org_id,
sub, text, timestamp, name,
tripcode, move_message,
edit_message
FROM threads
WHERE org_id = original
AND shadow = 'no'
AND sub NOT IN ($out)
ORDER BY ROWID DESC
LIMIT '$pagination'");
}
$result = $statement->execute();
while ($row = $result->fetchArray(SQLITE3_NUM)) {
$html_string = '';
$post_id = "{$row[0]}";
$org_id = "{$row[1]}";
$sub = "{$row[2]}";
$text = "{$row[3]}";
$post_text = break_text(bbcode_to_html($text, $settings, $sub),
$settings);
$timestamp = "{$row[4]}";
$name = "{$row[5]}";
$tripcode = "{$row[6]}";
$move_message = "{$row[7]}";
$edit_message = "{$row[8]}";
$link_string_1 = "/r/$sub/$org_id/op/css=$css";
$link_string_2 = "/r/$sub/$org_id/css=$css";
$link_string_3 = "/s/$sub/css=$css";
$html_string .= "<div class='post'>"
. "<p id=\"$post_id\"></p>"
. "<a href='$link_string_3'>$sub</a>:"
. "<a href='$link_string_1'>#$post_id</a>";
if ( !empty($timestamp) &&
$settings['enable_timestamps'] ) {
$html_string .= "<small>:$timestamp</small>";
}
$html_string .= "<br><br>$post_text<br><br>"
. "<a href='$link_string_2'>reply</a> ";
if ( !empty($name) &&
$settings['enable_edit']) {
$html_string .= "<a href='/e/$sub/$post_id/css=$css'>edit</a> ";
}
if ( !empty($name) &&
$settings['enable_tripcodes']) {
$name_string = $name;
$link_string_4 = "/u/$name_string/css=$css";
$html_string .= "<a href='$link_string_4'>$name_string</a>";
}
if ( !empty($move_message) ) {
$html_string .= "<br><small>|$move_message|</small>";
}
if ( !empty($edit_message) ) {
$html_string .= "<br><small>|$edit_message|</small>";
}
$html_string .= '</div>';
echo "$html_string";
if ($page == 'all') {
print_replies($db, $sub, $post_id, $org_id,
$settings, $css, 'open');
} else {
print_replies($db, $sub, $post_id, $org_id,
$settings, $css, 'closed');
}
echo "<br></div><br>";
}
}
// Show each post of an individual feed
function print_individual_feed($db, $css, $settings, $ex_subs, $in_subs)
{
$counter = 0;
if ( (!empty($ex_subs)) ) {
$out = '';
$last = array_pop($ex_subs);
foreach($ex_subs as $ex_sub) {
$str = "'" . $ex_sub . "', ";
$out .= $str;
}
$out .= "'" . $last . "'";
$statement = $db->prepare("SELECT post_id, org_id, sub, text,
timestamp, name, tripcode,
move_message, edit_message
FROM threads
WHERE org_id = original
AND shadow = 'no'
AND sub NOT IN ($out)
ORDER BY ROWID DESC");
} elseif ( (!empty($in_subs)) ) {
$in = '';
$last = array_pop($in_subs);
foreach($in_subs as $in_sub) {
$str = "'" . $in_sub . "', ";
$in .= $str;
}
$in .= "'" . $last . "'";
$statement = $db->prepare("SELECT post_id, org_id, sub, text,
timestamp, name, tripcode,
move_message, edit_message
FROM threads
WHERE org_id = original
AND shadow = 'no'
AND sub IN ($in)
ORDER BY ROWID DESC");
}
$result = $statement->execute();
while ($row = $result->fetchArray(SQLITE3_NUM)) {
$html_string = '';
$counter++;
$post_id = "{$row[0]}";
$org_id = "{$row[1]}";
$sub = "{$row[2]}";
$text = "{$row[3]}";
$post_text = break_text(bbcode_to_html($text, $settings, $sub),
$settings);
$timestamp = "{$row[4]}";
$name = "{$row[5]}";
$tripcode = "{$row[6]}";
$move_message = "{$row[7]}";
$edit_message = "{$row[8]}";
$link_string_1 = "/r/$sub/$org_id/op/css=$css";
$link_string_2 = "/r/$sub/$org_id/css=$css";
$link_string_3 = "/s/$sub/css=$css";
$html_string .= "<div class='post'>"
. "<p id=\"$post_id\"></p>"
. "<a href='$link_string_3'>$sub</a>:"
. "<a href='$link_string_1'>#$post_id</a>";
if ( !empty($timestamp) &&
$settings['enable_timestamps'] ) {
$html_string .= "<small>:$timestamp</small>";
}
// $html_string .= "<br><br><code>$post_text</code><br><br>"
$html_string .= "<br><br>$post_text<br><br>"
. "<a href='$link_string_2'>reply</a> ";
if ( !empty($name) &&
$settings['enable_edit']) {
$html_string .= "<a href='/e/$sub/$post_id/css=$css'>edit</a> ";
}
if ( !empty($name) &&
$settings['enable_tripcodes']) {
$name_string = $name;
$link_string_4 = "/u/$name_string/css=$css";
$html_string .= "<a href='$link_string_4'>$name_string</a>";
}
if ( !empty($move_message) ) {
$html_string .= "<br><small>|$move_message|</small>";
}
if ( !empty($edit_message) ) {
$html_string .= "<br><small>|$edit_message|</small>";
}
$html_string .= '</div>';
echo "$html_string";
print_replies($db, $sub, $post_id, $org_id, $settings, $css, 'closed');
echo "<br></div><br>";
}
return $counter;
}
// Print the footer for the admin
function print_footer_admin($css, $settings, $token)
{
$link_string_1 = "/lo/all/css=$css/$token";
$link_string_2 = "/lo/auth/css=$css/$token";
$link_string_3 = "/lo/bot/css=$css/$token";
$link_string_4 = "/lo/del/css=$css/$token";
$link_string_5 = "/lo/sys/css=$css/$token";
$link_string_6 = "/lo/user/css=$css/$token";
$link_string_7 = "/lo/import/css=$css/$token";
$left_section = "<a href='$link_string_1'>all logs</a>"
. "|<a href='$link_string_2'>auth</a>"
. "|<a href='$link_string_6'>user</a>"
. "|<a href='$link_string_3'>bot</a>"
. "|<a href='$link_string_4'>del</a>"
. "|<a href='$link_string_7'>import</a>"
. "|<a href='$link_string_5'>sys</a>";
$mid_section = "<a href='/dt/$token'>log out</a>"
. "|<a href='/sh/$token'>"
. "show shadowed posts and subs</a>";
$right_section = "<a href='/df/css=$css/$token'>dump</a>"
. "|<a href='/im/css=$css/$token'>import</a>"
. "|<a href='/cm/css=$css/$token'>view mods</a>";
print_footer($left_section, $mid_section, $right_section);
}
// Print the footer for the landing page
function print_footer_landing($db, $settings)
{
if ($settings['enable_admin_panel'] == TRUE) {
$left_section = "<a href='/aa'>Admin login</a>";
} else {
$left_section = "**********";
}
if ($settings['enable_mod_panel'] == TRUE) {
$mid_section = "<a href='/am'>Mod login</a>";
} else {
$mid_section = "**********";
}
if ( ($settings['enable_admin_panel'] == TRUE)
&& (!check_admin($db, $settings)) ) {
$right_section = "<a href='/pa'>set admin password</a>";
} elseif ($settings['take_applications'] == TRUE) {
$right_section = "<a href='/ap'>apply for mod account</a>";
} else {
$right_section = "**********";
}
print_footer($left_section, $mid_section, $right_section);
}
// Print the footer for the mod
function print_footer_mod($css, $settings, $token, $sub)
{
$left_section = "***************";
$mid_section = "<a href='/dt/$token'>log out</a>";
$right_section = "***************";
print_footer($left_section, $mid_section, $right_section);
}
// Print the footer for multifeeds
function print_footer_multifeeds($subs_string, $total_posts, $css, $settings)
{
$left_section = $subs_string . '|' . $total_posts . " posts total";
$mid_section = "<a href='/s/overboard/css=$css'>overboard</a>|"
. "<a href='/su/css=$css'>show subs</a>";
$right_section = "<a href='/iv/$subs_string/css=$css'"
. ">get link for multifeed</a>";
print_footer($left_section, $mid_section, $right_section);
}
// Print footer, with the total messages and some links, for the subs
function print_footer_sub($sub, $total_posts, $css, $page, $settings)
{
if ( ($total_posts > $settings['pagination']) && ($page != 'all') ) {
$number_first_message = ($page - 1) * $settings['pagination'] + 1;
$number_last_message =
$number_first_message + $settings['pagination'] - 1;
if ($number_last_message > $total_posts) {
$number_last_message = $total_posts;
}
$next_page = $page + 1;
$prev_page = $page - 1;
$pages_total = ceil($total_posts / $settings['pagination']);
$show_string_1 = "page:$page/$pages_total|posts:"
. "$number_first_message"
. "-$number_last_message/$total_posts|";
$link_string_1 = "/s/$sub/$next_page/css=$css";
$link_string_2 = "/s/$sub/$prev_page/css=$css";
$link_string_3 = "/s/$sub/all/css=$css";
if ( ($number_first_message > 1)
&& ($number_last_message < $total_posts) ) {
$left_section = "$show_string_1<a href='$link_string_1'"
. ">older</a>|<a href='$link_string_2'"
. ">newer</a>|<a href='$link_string_3'>all";
} elseif ($number_last_message == $total_posts) {
$left_section = "$show_string_1<a href='$link_string_2'"
. ">newer</a>|<a href='$link_string_3'>all";
} else {
$left_section = "$show_string_1<a href='$link_string_1'"
. ">older</a>|<a href='$link_string_3'>all";
}
} else {
$left_section = "$total_posts posts total";
}
$mid_section = '';
$right_section = '';
if ($sub == 'main') {
$mid_section = "<a href='/s/overboard/1/css=$css'>overboard</a>|"
. "<a href='/su/css=$css'>show subs</a>";
$right_section = "<a href='/d/$sub'>save main</a>";
} elseif ( ($sub == 'overboard') ) {
$mid_section = "<a href='/s/main/1/css=$css'>main</a>|"
. "<a href='/su/css=$css'>show subs</a>";
$right_section = "<a href='/d/overboard'>save overboard</a>";
} else {
$mid_section = "<a href='/s/main/1/css=$css'>main</a>|"
. "<a href='/s/overboard/1/css=$css'>overboard</a>|"
. "<a href='/su/css=$css'>show subs</a>";
$right_section = "<a href='/d/$sub'>save $sub</a>";
}
print_footer($left_section, $mid_section, $right_section);
}
// Print the footer for replies
function print_footer_reply($sub, $total_posts, $css, $msg, $org_id, $settings)
{
$left_section = $msg;
$mid_section = "<a href='/s/$sub/css=$css'>back to $sub</a>|"
. "<a href='/s/overboard/css=$css'>overboard</a>";
$right_section = "<a href='/d/$sub/$org_id'>save $msg</a>";
print_footer($left_section, $mid_section, $right_section);
}
// prints the footer
function print_footer($left_section, $mid_section, $right_section)
{
$html_string = "<br><div id=\"footer\">"
. "<div class=alignleft>$left_section</div>"
. "<div class=aligncenter>$mid_section</div>"
. "<div class=alignright>$right_section</div>"
. "<div id=\"interlaced\"></div>"
. "<div id=\"glare\"></div>"
. "</div></html>";
echo "$html_string";
}
// Give all the http-headers to the client, mostly for opsec reasons.
// After, print the html header to open the document for the browser.
function print_header($css)
{
// header( 'Content-Type: text/html; charset=utf-8');
// header( 'X-Frame-Options: DENY', FALSE);
// header( 'HTTP Cross-Origin-Opener-Policy: same-origin', FALSE);
// header( 'Cross-Origin-Resource-Policy: same-site', FALSE);
// header( 'Permissions-Policy: geolocation=(), camera=(), microphone=()',
// FALSE);
// header( 'Permissions-Policy: interest-cohort=()', FALSE);
// header( 'Server: webserver', FALSE);
// header( 'X-DNS-Prefetch-Control: off', FALSE);
// header( 'Cache-Control: no-cache', FALSE);
// header( 'Pragma: no-cache', FALSE);
// nginx throws an error with those, and gives back 502 - bad gateway
// does not happen with other versions
$html_string = "<!DOCTYPE html><html lang=\"en\"><head>"
. "<link rel=\"stylesheet\" type=\"text/css\" "
. "href=\"/css/$css.css\"></head><body>";
echo "$html_string";
}
// Show all replies to a given post
function print_replies($db, $sub, $post_id, $org_id, $settings, $css, $state)
{
$sub_statement = $db->prepare("SELECT post_id, org_id,
sub, text, timestamp,
name, tripcode, move_message,
edit_message
FROM threads
WHERE sub = '$sub'
AND org_id = '$org_id'
AND org_id != original
AND shadow = 'no'");
$sub_result = $sub_statement->execute();
$answers = array();
$counter = 0;
while ($row = $sub_result->fetchArray(SQLITE3_NUM)) {
$sub_post_id = "{$row[0]}";
$sub_org_id = "{$row[1]}";
$sub_text = "{$row[3]}";
$sub_timestamp = "{$row[4]}";
$sub_name = "{$row[5]}";
$sub_tripcode = "{$row[6]}";
$sub_move_message = "{$row[7]}";
$sub_edit_message = "{$row[8]}";
if ($sub_post_id != $sub_org_id) {
$counter++;
$post = array();
$sub_post_text = break_text(bbcode_to_html
($sub_text, $settings, $sub),
$settings);
array_push($post, $sub_post_id);
array_push($post, $sub_org_id);
array_push($post, $sub_post_text);
array_push($post, $sub_timestamp);
array_push($post, $sub_name);
array_push($post, $sub_tripcode);
array_push($post, $sub_move_message);
array_push($post, $sub_edit_message);
array_push($answers, $post);
}
}
$display_number = $counter - 1;
if ($counter == 0) {
// no replies exist for this message
return;
}
$last_answer = array_pop($answers);
$last_post_id = $last_answer[0];
$last_post_text = $last_answer[2];
$last_post_timestamp = $last_answer[3];
$last_post_name = $last_answer[4];
$last_post_tripcode = $last_answer[5];
$last_post_move_message = $last_answer[6];
$last_post_edit_message = $last_answer[7];
$html_string = '';
if ($counter > 1) {
// we have at least one reply
if ($state == 'open') {
$html_string .= "<details open>";
} else {
$html_string .= "<details>";
}
$html_string .= "<summary>Show $display_number more replies</summary>";
foreach ($answers as $display_msg) {
$answer_post_id = $display_msg[0];
$answer_post_text = $display_msg[2];
$answer_post_timestamp = $display_msg[3];
$answer_post_name = $display_msg[4];
$answer_post_tripcode = $display_msg[5];
$answer_post_move_message = $display_msg[6];
$answer_post_edit_message = $display_msg[7];
$link_string_1 = "/r/$sub/$org_id/$answer_post_id/css=$css";
$html_string .= "<div class='postreply'>"
. "<p id=\"$answer_post_id" . "_" . "$sub\"></p>"
. "<a href='$link_string_1'>#$answer_post_id</a>";
if ( !empty($answer_post_timestamp) &&
$settings['enable_timestamps'] ) {
$html_string .= "<small>:$answer_post_timestamp</small>";
}
$html_string .= "<br><br>$answer_post_text<br><br>";
if ( !empty($answer_post_name) &&
$settings['enable_edit']) {
$html_string .= "<a href='/e/$sub/$answer_post_id/css=$css'"
. ">edit</a> ";
}
if ( !empty($answer_post_name) &&
$settings['enable_tripcodes']) {
$name_string = $answer_post_name;
$link_string_4 = "/u/$name_string/css=$css";
$html_string .= "<a href='$link_string_4'>$name_string</a>";
}
if ( !empty($answer_post_move_message) ) {
$html_string .= "<br><small>|$answer_post_move_message|"
. "</small>";
}
if ( !empty($answer_post_edit_message) ) {
$html_string .= "<br><small>|$answer_post_edit_message|"
. "</small>";
}
$html_string .= '</div>';
}
$html_string .= "</details>";
}
$link_string_1 = "/r/$sub/$org_id/$last_post_id/css=$css";
$html_string .= "<div class='postreply2'>"
. "<p id=\"$last_post_id" . "_" . "$sub\"></p>"
. "<a href='$link_string_1'>#$last_post_id</a>";
if ( !empty($last_post_timestamp) &&
$settings['enable_timestamps'] ) {
$html_string .= "<small>:$last_post_timestamp</small>";
}
$html_string .= "<br><br>$last_post_text<br><br>";
if ( !empty($last_post_name) &&
$settings['enable_edit']) {
$html_string .= "<a href='/e/$sub/$last_post_id/css=$css'>edit</a> ";
}
if ( !empty($last_post_name) &&
$settings['enable_tripcodes']) {
$name_string = $last_post_name;
$link_string_4 = "/u/$name_string/css=$css";
$html_string .= "<a href='$link_string_4'>$name_string</a>";
}
if ( !empty($last_post_move_message) ) {
$html_string .= "<br><small>|$last_post_move_message|</small>";
}
if ( !empty($last_post_edit_message) ) {
$html_string .= "<br><small>|$last_post_edit_message|</small>";
}
$html_string .= '</div>';
echo "$html_string";
}
// Send a rss feed
function print_rss_all($db, $settings, $page)
{
$page_start = ($page - 1) * $settings['pagination'];
$pagination = $settings['pagination'];
$title = $settings['title'];
$address = $settings['web_address'];
$description = $settings['RSS_message'];
$name = $settings['site_name'];
$out = '';
if ( (!empty($settings['no_overboard'])) ) {
$last = array_pop($settings['no_overboard']);
foreach($settings['no_overboard'] as $no_overboard) {
$str = "'" . $no_overboard . "', ";
$out .= $str;
}
$out .= "'" . $last . "'";
}
$statement = $db->prepare("SELECT post_id, org_id,
sub, text, timestamp, name,
move_message, edit_message
FROM threads
WHERE shadow = 'no'
AND sub NOT IN ($out)
ORDER BY ROWID DESC
LIMIT '$page_start', '$pagination'");
$result = $statement->execute();
header( "Content-type: text/xml" );
$rss_string = "<?xml version='1.0' encoding='UTF-8'?><rss version='2.0'>"
. "<x xmlns:$name='$address'>"
. "<channel><title>$title</title>"
. "<link>$address</link>"
. "<description>$description</description>"
. "<language>en-us</language>";
while ($row = $result->fetchArray(SQLITE3_NUM)) {
$post_id = "{$row[0]}";
$org_id = "{$row[1]}";
$sub = "{$row[2]}";
$text = "{$row[3]}";
$text = htmlspecialchars($text);
$timestamp = "{$row[4]}";
$user_name = "{$row[5]}";
$move_message = "{$row[6]}";
$edit_message = "{$row[7]}";
$rss_string .= "<item>"
. "<$name:sub>$sub</$name:sub>";
if ( $post_id != $org_id ) {
$rss_string .= "<$name:answer>answer to $org_id</$name:answer>";
}
if ( !empty($timestamp) &&
$settings['enable_timestamps'] ) {
$rss_string .= "<$name:timestamp>$timestamp</$name:timestamp>";
}
if ( empty($user_name) ) {
$user_name = "anonymous";
}
$rss_string .= "<$name:author>$user_name</$name:author>";
if ( !empty($move_message) ) {
$rss_string .= "<$name:moved>$move_message</$name:moved>";
}
if ( !empty($edit_message) ) {
$rss_string .= "<$name:edited>$edit_message</$name:edited>";
}
$rss_string .= "<description>$text</description>"
. "<link>$address/r/$sub/$org_id</link></item>";
}
$rss_string .= "</channel></x></rss>";
echo $rss_string;
}
// Show each post in a sub
function print_sub($db, $sub, $css, $settings, $page)
{
echo "<div class='postcontainer'>";
$pagination = $settings['pagination'];
if ($page == 'all') {
$statement = $db->prepare("SELECT post_id, org_id,
sub, text, timestamp,
name, tripcode, move_message,
edit_message
FROM threads
WHERE sub = '$sub'
AND shadow = 'no'
AND original = org_id
ORDER BY ROWID DESC");
} elseif ($page > 0) {
// if the page is defined
$page_start = ($page - 1) * $settings['pagination'];
$statement = $db->prepare("SELECT post_id, org_id,
sub, text, timestamp,
name, tripcode, move_message,
edit_message
FROM threads
WHERE sub = '$sub'
AND shadow = 'no'
AND original = org_id
ORDER BY ROWID DESC
LIMIT '$page_start', '$pagination'");
} else {
$statement = $db->prepare("SELECT post_id, org_id,
sub, text, timestamp,
name, tripcode, move_message,
edit_message
FROM threads
WHERE sub = '$sub'
AND shadow = 'no'
AND original = org_id
ORDER BY ROWID DESC
LIMIT '$pagination'");
}
$result = $statement->execute();
while ($row = $result->fetchArray(SQLITE3_NUM)) {
$html_string = '';
$post_id = "{$row[0]}";
$org_id = "{$row[1]}";
$text = "{$row[3]}";
$timestamp = "{$row[4]}";
$name = "{$row[5]}";
$tripcode = "{$row[6]}";
$move_message = "{$row[7]}";
$edit_message = "{$row[8]}";
$post_text = break_text(bbcode_to_html($text, $settings, $sub),
$settings);
$html_string .= "<div>";
$id_text = make_id_text($post_id);
$link_string_1 = "/r/$sub/$org_id/op/css=$css";
$link_string_2 = "/r/$sub/$org_id/css=$css";
$html_string .= "<div class='post'>"
. "<p id=\"$post_id\"></p>"
. "<a href='$link_string_1'>#$id_text</a>";
if ( !empty($timestamp) &&
$settings['enable_timestamps'] ) {
$html_string .= "<small>:$timestamp</small>";
}
// $html_string .= "<br><br><code>$post_text</code><br><br>"
$html_string .= "<br><br>$post_text<br><br>"
. "<a href='$link_string_2'>reply</a> ";
if ( !empty($name) &&
$settings['enable_edit']) {
$html_string .= "<a href='/e/$sub/$post_id/css=$css'>edit</a> ";
}
if ( !empty($name) &&
$settings['enable_tripcodes']) {
$name_string = $name;
$link_string_4 = "/u/$name_string/css=$css";
$html_string .= "<a href='$link_string_4'>$name_string</a>";
}
if ( !empty($move_message) ) {
$html_string .= "<br><small>|$move_message|</small>";
}
if ( !empty($edit_message) ) {
$html_string .= "<br><small>|$edit_message|</small>";
}
$html_string .= '</div>';
echo "$html_string";
if ($page == 'all') {
print_replies($db, $sub, $post_id, $org_id,
$settings, $css, 'open');
} else {
print_replies($db, $sub, $post_id, $org_id,
$settings, $css, 'closed');
}
echo "<br></div><br>";
}
echo "</div>";
}
// prints the fixed topheader with some text
function print_top_header($text)
{
echo "<div class=\"header id=\"topheader\"><h1>$text</h1></div>";
}
// Show each post by a user
function print_user($db, $name, $css, $settings)
{
echo "<div class='postcontainer'>";
$statement = $db->prepare("SELECT post_id, org_id,
sub, text, timestamp,
name, tripcode
FROM threads
WHERE name = '$name'
AND shadow = 'no'
ORDER BY ROWID DESC");
$result = $statement->execute();
while ($row = $result->fetchArray(SQLITE3_NUM)) {
$html_string = '';
$post_id = "{$row[0]}";
$org_id = "{$row[1]}";
$sub = "{$row[2]}";
$text = "{$row[3]}";
$timestamp = "{$row[4]}";
$name = "{$row[5]}";
$tripcode = "{$row[6]}";
$post_text = break_text(bbcode_to_html($text, $settings, $sub),
$settings);
$html_string .= "<div>";
$id_text = make_id_text($post_id);
$link_string_1 = "/r/$sub/$org_id/$post_id/css=$css";
$link_string_2 = "/r/$sub/$org_id/css=$css";
$html_string .= "<div class='post'>"
. "<p id=\"$post_id\"></p>"
. "<a href='$link_string_1'>#$id_text</a>";
if ( !empty($timestamp) &&
$settings['enable_timestamps'] ) {
$html_string .= "<small>:$timestamp</small>";
}
// $html_string .= "<br><br><code>$post_text</code><br><br>"
$html_string .= "<br><br>$post_text<br><br>"
. "<a href='$link_string_2'>reply</a> ";
if ( !empty($name) &&
$settings['enable_edit']) {
$html_string .= "<a href='/e/$sub/$post_id/css=$css'>edit</a> ";
}
$html_string .= '</div><br></div><br>';
echo "$html_string";
}
echo "</div>";
}
// EOF