summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSavetheinternet <savetheinternet@n0v4.com>2011-04-17 15:28:15 +1000
committerSavetheinternet <savetheinternet@n0v4.com>2011-04-17 15:28:15 +1000
commit2babc137e982e0191144ca51ef89759923c33002 (patch)
treee4befbef39708c2c44fbb52cd9395b040ddfcf41
parente47279b3f078b133a1ddb132264c401ed713357e (diff)
truncate posts
-rw-r--r--inc/config.php4
-rw-r--r--inc/display.php68
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, '<br/>');
+
+ // Limit line count
+ if($lines > $config['body_truncate']) {
+ if(preg_match('/(((.*?)<br\/>){' . $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<count($open_tags[0]);$x++) {
+ if(!preg_match('/\/(\s+)?>$/', $open_tags[0][$x]))
+ $tags[] = $open_tags[1][$x];
+ }
+
+ // List successfully closed tags
+ if(preg_match_all('/(<\/([\w]+))>/', $body, $closed_tags)) {
+ for($x=0;$x<count($closed_tags[0]);$x++) {
+ unset($tags[array_search($closed_tags[1][$x], $tags)]);
+ }
+ }
+
+ // Close any open tags
+ foreach($tags as &$tag) {
+ $body .= "</{$tag}>";
+ }
+ }
+ $body .= '<span class="toolong">Post too long. Click <a href="' . $url . '">here</a> to view the full text.</span>';
+ }
+
+ 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 @@
. ' <a class="post_no"' .
// JavaScript highlight
($index?'':' onclick="highlightReply(' . $this->id . ');"') .
- ' href="' . $this->root . $board['dir'] . $config['dir']['res'] . $this->thread . '.html' . '#' . $this->id . '">No.</a>' .
+ ' href="' . $this->link() . '">No.</a>' .
// JavaScript cite
- '<a class="post_no"' . ($index?'':' onclick="citeReply(' . $this->id . ');"') . ' href="' . ($index?$this->root . $board['dir'] . $config['dir']['res'] . $this->thread . '.html' . '#q' . $this->id:'javascript:void(0);') . '">'.$this->id.'</a>' .
+ '<a class="post_no"' . ($index?'':' onclick="citeReply(' . $this->id . ');"') . ' href="' . ($index ? $this->link('q') : 'javascript:void(0);') . '">'.$this->id.'</a>' .
'</p>';
// File info
@@ -288,7 +339,7 @@
$built .= $this->postControls();
// Body
- $built .= '<p class="body">' . $this->body . '</p></div><br class="clear"/>';
+ $built .= '<p class="body">' . ($index ? truncate($this->body, $this->link()) : $this->body) . '</p></div><br class="clear"/>';
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 @@
. ' <a class="post_no"' .
// JavaScript highlight
($index?'':' onclick="highlightReply(' . $this->id . ');"') .
- ' href="' . $this->root . $board['dir'] . $config['dir']['res'] . $this->id . '.html' . '#' . $this->id . '">No.</a>' .
+ ' href="' . $this->link() . '">No.</a>' .
// JavaScript cite
- '<a class="post_no"' . ($index?'':' onclick="citeReply(' . $this->id . ');"') . ' href="' . ($index?$this->root . $board['dir'] . $config['dir']['res'] . $this->id . '.html' . '#q' . $this->id:'javascript:void(0);') . '">'.$this->id.'</a>' .
+ '<a class="post_no"' . ($index?'':' onclick="citeReply(' . $this->id . ');"') . ' href="' . ($index ? $this->link('q') : 'javascript:void(0);') . '">'.$this->id.'</a>' .
// Sticky
($this->sticky ? '<img class="icon" title="Sticky" src="' . $config['image_sticky'] . '" />' : '') .
// Locked
@@ -455,7 +511,7 @@
'</p>';
// Body
- $built .= '<p class="body">' . $this->body . '</p>' .
+ $built .= '<p class="body">' . ($index ? truncate($this->body, $this->link()) : $this->body) . '</p>' .
// Omitted posts
($this->omitted || $this->omitted_images? '<span class="omitted">' .