From 0abbcf9aba6a1e92393e60ab4169f7bca54ce1cd Mon Sep 17 00:00:00 2001
From: Savetheinternet
Date: Sun, 17 Apr 2011 15:28:15 +1000
Subject: [PATCH] truncate posts
---
inc/config.php | 4 +++
inc/display.php | 68 ++++++++++++++++++++++++++++++++++++++++++++-----
2 files changed, 66 insertions(+), 6 deletions(-)
diff --git a/inc/config.php b/inc/config.php
index 766d824f..131ac46c 100644
--- a/inc/config.php
+++ b/inc/config.php
@@ -80,6 +80,10 @@
// Max body length
$config['max_body'] = 1800;
+ // Amount of post lines to show on the index page
+ $config['body_truncate'] = 15;
+ // Amount of characters to show on the index page
+ $config['body_truncate_char'] = 2500;
$config['threads_per_page'] = 10;
$config['max_pages'] = 10;
diff --git a/inc/display.php b/inc/display.php
index 34be2dcc..2f0c15a2 100644
--- a/inc/display.php
+++ b/inc/display.php
@@ -131,6 +131,52 @@
return sprintf($config['capcode'], $cap);
}
+ function truncate($body, $url) {
+ global $config;
+
+ $original_body = $body;
+
+ $lines = substr_count($body, '
');
+
+ // Limit line count
+ if($lines > $config['body_truncate']) {
+ if(preg_match('/(((.*?)
){' . $config['body_truncate'] . '})/', $body, $m))
+ $body = $m[0];
+ }
+
+ $body = substr($body, 0, $config['body_truncate_char']);
+
+ if($body != $original_body) {
+ // Remove any corrupt tags at the end
+ $body = preg_replace('/<([\w]+)?([^>]*)?$/', '', $body);
+
+ // Open tags
+ if(preg_match_all('/<([\w]+)[^>]*>/', $body, $open_tags)) {
+
+ $tags = Array();
+ for($x=0;$x$/', $open_tags[0][$x]))
+ $tags[] = $open_tags[1][$x];
+ }
+
+ // List successfully closed tags
+ if(preg_match_all('/(<\/([\w]+))>/', $body, $closed_tags)) {
+ for($x=0;$xhere to view the full text.';
+ }
+
+ return $body;
+ }
+
function confirmLink($text, $title, $confirm, $href) {
global $config, $mod;
if($config['mod']['server-side_confirm'])
@@ -174,6 +220,11 @@
$this->body
);
}
+ public function link($pre = '') {
+ global $config, $board;
+
+ return $this->root . $board['dir'] . $config['dir']['res'] . $this->thread . '.html' . '#' . $pre . $this->id;
+ }
public function postControls() {
global $board, $config;
@@ -257,9 +308,9 @@
. ' No.' .
+ ' href="' . $this->link() . '">No.' .
// JavaScript cite
- ''.$this->id.'' .
+ ''.$this->id.'' .
'
';
// File info
@@ -288,7 +339,7 @@
$built .= $this->postControls();
// Body
- $built .= '' . $this->body . '
';
+ $built .= '' . ($index ? truncate($this->body, $this->link()) : $this->body) . '
';
return $built;
}
@@ -334,6 +385,11 @@
$this->body
);
}
+ public function link($pre = '') {
+ global $config, $board;
+
+ return $this->root . $board['dir'] . $config['dir']['res'] . $this->id . '.html' . '#' . $pre . $this->id;
+ }
public function add(Post $post) {
$this->posts[] = $post;
}
@@ -440,9 +496,9 @@
. ' No.' .
+ ' href="' . $this->link() . '">No.' .
// JavaScript cite
- ''.$this->id.'' .
+ ''.$this->id.'' .
// Sticky
($this->sticky ? '' : '') .
// Locked
@@ -455,7 +511,7 @@
'';
// Body
- $built .= '' . $this->body . '
' .
+ $built .= '' . ($index ? truncate($this->body, $this->link()) : $this->body) . '
' .
// Omitted posts
($this->omitted || $this->omitted_images? '' .