diff options
| -rw-r--r-- | inc/display.php | 28 | ||||
| -rw-r--r-- | mod.php | 17 |
2 files changed, 34 insertions, 11 deletions
diff --git a/inc/display.php b/inc/display.php index 465b0e1f..fb1a3379 100644 --- a/inc/display.php +++ b/inc/display.php @@ -131,20 +131,23 @@ return sprintf($config['capcode'], $cap); } - function truncate($body, $url) { + function truncate($body, $url, $max_lines = false, $max_chars = false) { global $config; - + if($max_lines === false) + $max_lines = $config['body_truncate']; + if($max_chars === false) + $max_chars = $config['body_truncate_char']; $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)) + if($lines > $max_lines) { + if(preg_match('/(((.*?)<br\/>){' . $max_lines . '})/', $body, $m)) $body = $m[0]; } - $body = substr($body, 0, $config['body_truncate_char']); + $body = substr($body, 0, $max_chars); if($body != $original_body) { // Remove any corrupt tags at the end @@ -347,8 +350,8 @@ // Thumbnail '<a href="' . $config['uri_img'] . $this->file.'"><img src="' . $config['uri_thumb'] . $this->thumb.'" style="width:'.$this->thumbx.'px;height:'.$this->thumby.'px;" alt="" /></a>'; - } elseif($this->file == 'deleted') { - $built .= '<img src="' . $config['image_deleted'] . '" alt="" />'; + } elseif($this->file == 'deleted') { + $built .= '<img src="' . $config['image_deleted'] . '" alt="" />'; } $built .= $this->postControls(); @@ -442,7 +445,11 @@ if($this->mod['type'] >= $config['mod']['bandelete']) $built .= ' <a title="Ban & Delete" href="?/' . $board['uri'] . '/ban&delete/' . $this->id . '">' . $config['mod']['link_bandelete'] . '</a>'; - // Stickies + // Delete file (keep post) + if(!empty($this->file) && $this->file != 'deleted' && $this->mod['type'] >= $config['mod']['deletefile']) + $built .= ' <a title="Remove file" href="?/' . $board['uri'] . '/deletefile/' . $this->id . '">' . $config['mod']['link_deletefile'] . '</a>'; + + // Sticky if($this->mod['type'] >= $config['mod']['sticky']) if($this->sticky) $built .= ' <a title="Make thread not sticky" href="?/' . $board['uri'] . '/unsticky/' . $this->id . '">' . $config['mod']['link_desticky'] . '</a>'; @@ -456,7 +463,6 @@ else $built .= ' <a title="Unlock thread" href="?/' . $board['uri'] . '/lock/' . $this->id . '">' . $config['mod']['link_lock'] . '</a>'; - $built .= '</span>'; } return $built; @@ -470,7 +476,7 @@ $built = // Actual embedding $this->embed; - } else { + } elseif(!empty($this->file) && $this->file != 'deleted') { // Image, not embedded shit $built = // File link @@ -490,6 +496,8 @@ $built .= ', ' . $this->filename . ')</span></p>' . // Thumbnail '<a href="' . $config['uri_img'] . $this->file.'"><img src="' . $config['uri_thumb'] . $this->thumb.'" style="width:'.$this->thumbx.'px;height:'.$this->thumby.'px;" alt="" /></a>'; + } elseif($this->file == 'deleted') { + $built = '<img src="' . $config['image_deleted'] . '" alt="" />'; } $built .= '<div class="post op"><p class="intro"' . (!$index?' id="' . $this->id . '"':'') . '>'; @@ -1172,7 +1172,7 @@ $po = new Post($post['id'], $post['thread'], $post['subject'], $post['email'], $post['name'], $post['trip'], $post['capcode'], $post['body'], $post['time'], $post['thumb'], $post['thumbwidth'], $post['thumbheight'], $post['file'], $post['filewidth'], $post['fileheight'], $post['filesize'], $post['filename'], $post['ip'], $post['embed'], '?/', $mod); } - $po->body .= + $append_html = '<div class="report">' . '<hr/>' . 'Board: <a href="?/' . $report['uri'] . '/' . $config['file_index'] . '">' . sprintf($config['board_abbreviation'], $report['uri']) . '</a><br/>' . @@ -1184,7 +1184,22 @@ ($mod['type'] >= $config['mod']['report_dismiss_ip'] ? '<a title="Discard all abuse reports by this user" href="?/reports/' . $report['id'] . '/dismiss/all">Dismiss+</a>' : '') . '</div>'; + + // Bug fix for https://github.com/savetheinternet/Tinyboard/issues/21 + $po->body = truncate($po->body, $po->link(), $config['body_truncate'] - substr_count($append_html, '<br/>')); + + if(strlen($po->body) + strlen($append_html) > $config['body_truncate_char']) { + // still too long. temporarily increase limit in the config + $__old_body_truncate_char = $config['body_truncate_char']; + $config['body_truncate_char'] = strlen($po->body) + strlen($append_html); + } + + $po->body .= $append_html; + $body .= $po->build(true) . '<hr/>'; + + if(isset($__old_body_truncate_char)) + $config['body_truncate_char'] = $__old_body_truncate_char; } $query = query("SELECT COUNT(`id`) AS `count` FROM `reports`") or error(db_error()); |
