towards-a-new-leftypol
3 years ago
1 changed files with 361 additions and 361 deletions
@ -5,419 +5,419 @@ |
|||||
*/ |
*/ |
||||
|
|
||||
if (realpath($_SERVER['SCRIPT_FILENAME']) == str_replace('\\', '/', __FILE__)) { |
if (realpath($_SERVER['SCRIPT_FILENAME']) == str_replace('\\', '/', __FILE__)) { |
||||
// You cannot request this file directly. |
// You cannot request this file directly. |
||||
exit; |
exit; |
||||
} |
} |
||||
|
|
||||
/* |
/* |
||||
[email protected] |
[email protected] |
||||
http://www.php.net/manual/en/function.filesize.php#100097 |
http://www.php.net/manual/en/function.filesize.php#100097 |
||||
*/ |
*/ |
||||
function format_bytes($size) { |
function format_bytes($size) { |
||||
$units = array(' B', ' KB', ' MB', ' GB', ' TB'); |
$units = array(' B', ' KB', ' MB', ' GB', ' TB'); |
||||
for ($i = 0; $size >= 1024 && $i < 4; $i++) $size /= 1024; |
for ($i = 0; $size >= 1024 && $i < 4; $i++) $size /= 1024; |
||||
return round($size, 2).$units[$i]; |
return round($size, 2).$units[$i]; |
||||
} |
} |
||||
|
|
||||
function doBoardListPart($list, $root, &$boards) { |
function doBoardListPart($list, $root, &$boards) { |
||||
global $config; |
global $config; |
||||
|
|
||||
$body = ''; |
|
||||
foreach ($list as $key => $board) { |
|
||||
if (is_array($board)) |
|
||||
$body .= ' <span class="sub" data-description="' . $key . '">[' . doBoardListPart($board, $root, $boards) . ']</span> '; |
|
||||
else { |
|
||||
if (gettype($key) == 'string') { |
|
||||
$body .= ' <a href="' . $board . '">' . $key . '</a> /'; |
|
||||
} else { |
|
||||
$title = ''; |
|
||||
if (array_key_exists($board,$config['boards_alias'])){ |
|
||||
$actual_board = $config['boards_alias'][$board]; |
|
||||
if (isset ($boards[$actual_board])) { |
|
||||
$title = ' title="'.$boards[$actual_board].'"'; |
|
||||
} |
|
||||
|
|
||||
$body .= ' <a href="' . $root . $actual_board . '/' . $config['file_index'] . '"'.$title.'>' . $board . '</a> /'; |
$body = ''; |
||||
} |
foreach ($list as $key => $board) { |
||||
else |
if (is_array($board)) |
||||
{ |
$body .= ' <span class="sub" data-description="' . $key . '">[' . doBoardListPart($board, $root, $boards) . ']</span> '; |
||||
if (isset ($boards[$board])) { |
else { |
||||
$title = ' title="'.$boards[$board].'"'; |
if (gettype($key) == 'string') { |
||||
} |
$body .= ' <a href="' . $board . '">' . $key . '</a> /'; |
||||
|
} else { |
||||
|
$title = ''; |
||||
|
if (array_key_exists($board,$config['boards_alias'])){ |
||||
|
$actual_board = $config['boards_alias'][$board]; |
||||
|
if (isset ($boards[$actual_board])) { |
||||
|
$title = ' title="'.$boards[$actual_board].'"'; |
||||
|
} |
||||
|
|
||||
$body .= ' <a href="' . $root . $board . '/' . $config['file_index'] . '"'.$title.'>' . $board . '</a> /'; |
$body .= ' <a href="' . $root . $actual_board . '/' . $config['file_index'] . '"'.$title.'>' . $board . '</a> /'; |
||||
} |
} |
||||
} |
else |
||||
} |
{ |
||||
} |
if (isset ($boards[$board])) { |
||||
$body = preg_replace('/\/$/', '', $body); |
$title = ' title="'.$boards[$board].'"'; |
||||
|
} |
||||
return $body; |
|
||||
|
$body .= ' <a href="' . $root . $board . '/' . $config['file_index'] . '"'.$title.'>' . $board . '</a> /'; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
$body = preg_replace('/\/$/', '', $body); |
||||
|
|
||||
|
return $body; |
||||
} |
} |
||||
|
|
||||
function createBoardlist($mod=false) { |
function createBoardlist($mod=false) { |
||||
global $config; |
global $config; |
||||
|
|
||||
if (!isset($config['boards'])) return array('top'=>'','bottom'=>''); |
if (!isset($config['boards'])) return array('top'=>'','bottom'=>''); |
||||
|
|
||||
$xboards = listBoards(); |
$xboards = listBoards(); |
||||
$boards = array(); |
$boards = array(); |
||||
foreach ($xboards as $val) { |
foreach ($xboards as $val) { |
||||
$boards[$val['uri']] = $val['title']; |
$boards[$val['uri']] = $val['title']; |
||||
} |
} |
||||
|
|
||||
$body = doBoardListPart($config['boards'], $mod?'?/':$config['root'], $boards); |
$body = doBoardListPart($config['boards'], $mod?'?/':$config['root'], $boards); |
||||
|
|
||||
if ($config['boardlist_wrap_bracket'] && !preg_match('/\] $/', $body)) |
if ($config['boardlist_wrap_bracket'] && !preg_match('/\] $/', $body)) |
||||
$body = '[' . $body . ']'; |
$body = '[' . $body . ']'; |
||||
|
|
||||
$body = trim($body); |
$body = trim($body); |
||||
|
|
||||
// Message compact-boardlist.js faster, so that page looks less ugly during loading |
// Message compact-boardlist.js faster, so that page looks less ugly during loading |
||||
$top = "<script type='text/javascript'>if (typeof do_boardlist != 'undefined') do_boardlist();</script>"; |
$top = "<script type='text/javascript'>if (typeof do_boardlist != 'undefined') do_boardlist();</script>"; |
||||
|
|
||||
return array( |
return array( |
||||
'top' => '<div class="boardlist">' . $body . '</div>' . $top, |
'top' => '<div class="boardlist">' . $body . '</div>' . $top, |
||||
'bottom' => '<div class="boardlist bottom">' . $body . '</div>' |
'bottom' => '<div class="boardlist bottom">' . $body . '</div>' |
||||
); |
); |
||||
} |
} |
||||
|
|
||||
|
|
||||
function loginForm($error=false, $username=false, $redirect=false) { |
function loginForm($error=false, $username=false, $redirect=false) { |
||||
global $config; |
global $config; |
||||
|
|
||||
die(Element('page.html', array( |
die(Element('page.html', array( |
||||
'index' => $config['root'], |
'index' => $config['root'], |
||||
'title' => _('Login'), |
'title' => _('Login'), |
||||
'config' => $config, |
'config' => $config, |
||||
'body' => Element('login.html', array( |
'body' => Element('login.html', array( |
||||
'config'=>$config, |
'config'=>$config, |
||||
'error'=>$error, |
'error'=>$error, |
||||
'username'=>utf8tohtml($username), |
'username'=>utf8tohtml($username), |
||||
'redirect'=>$redirect |
'redirect'=>$redirect |
||||
) |
) |
||||
) |
) |
||||
))); |
))); |
||||
} |
} |
||||
|
|
||||
function pm_snippet($body, $len=null) { |
function pm_snippet($body, $len=null) { |
||||
global $config; |
global $config; |
||||
|
|
||||
if (!isset($len)) |
if (!isset($len)) |
||||
$len = &$config['mod']['snippet_length']; |
$len = &$config['mod']['snippet_length']; |
||||
|
|
||||
// Replace line breaks with some whitespace |
// Replace line breaks with some whitespace |
||||
$body = preg_replace('@<br/?>@i', ' ', $body); |
$body = preg_replace('@<br/?>@i', ' ', $body); |
||||
|
|
||||
// Strip tags but leave span tags which contain spoiler |
// Strip tags but leave span tags which contain spoiler |
||||
$body_with_spoiler_tags = strip_tags($body,'<span>'); |
$body_with_spoiler_tags = strip_tags($body,'<span>'); |
||||
|
|
||||
// Check for spoiler tags |
// Check for spoiler tags |
||||
$spoiler = preg_match("/spoiler/", $body_with_spoiler_tags); |
$spoiler = preg_match("/spoiler/", $body_with_spoiler_tags); |
||||
|
|
||||
// Strip tags |
// Strip tags |
||||
$body = strip_tags($body); |
$body = strip_tags($body); |
||||
|
|
||||
// Unescape HTML characters, to avoid splitting them in half |
// Unescape HTML characters, to avoid splitting them in half |
||||
$body = html_entity_decode($body, ENT_COMPAT, 'UTF-8'); |
$body = html_entity_decode($body, ENT_COMPAT, 'UTF-8'); |
||||
|
|
||||
// calculate strlen() so we can add "..." after if needed |
// calculate strlen() so we can add "..." after if needed |
||||
$strlen = mb_strlen($body); |
$strlen = mb_strlen($body); |
||||
|
|
||||
$body = mb_substr($body, 0, $len); |
$body = mb_substr($body, 0, $len); |
||||
|
|
||||
if ($spoiler){ |
if ($spoiler){ |
||||
$value = "<span class=\"spoiler\">" . utf8tohtml($body) . "</span>"; |
$value = "<span class=\"spoiler\">" . utf8tohtml($body) . "</span>"; |
||||
} |
} |
||||
else { |
else { |
||||
$value = utf8tohtml($body); |
$value = utf8tohtml($body); |
||||
} |
} |
||||
|
|
||||
// Re-escape the characters. |
// Re-escape the characters. |
||||
return '<em>' . utf8tohtml($body) . ($strlen > $len ? '…' : '') . '</em>'; |
return '<em>' . utf8tohtml($body) . ($strlen > $len ? '…' : '') . '</em>'; |
||||
} |
} |
||||
|
|
||||
function capcode($cap) { |
function capcode($cap) { |
||||
global $config; |
global $config; |
||||
|
|
||||
if (!$cap) |
if (!$cap) |
||||
return false; |
return false; |
||||
|
|
||||
$capcode = array(); |
$capcode = array(); |
||||
if (isset($config['custom_capcode'][$cap])) { |
if (isset($config['custom_capcode'][$cap])) { |
||||
if (is_array($config['custom_capcode'][$cap])) { |
if (is_array($config['custom_capcode'][$cap])) { |
||||
$capcode['cap'] = sprintf($config['custom_capcode'][$cap][0], $cap); |
$capcode['cap'] = sprintf($config['custom_capcode'][$cap][0], $cap); |
||||
if (isset($config['custom_capcode'][$cap][1])) |
if (isset($config['custom_capcode'][$cap][1])) |
||||
$capcode['name'] = $config['custom_capcode'][$cap][1]; |
$capcode['name'] = $config['custom_capcode'][$cap][1]; |
||||
if (isset($config['custom_capcode'][$cap][2])) |
if (isset($config['custom_capcode'][$cap][2])) |
||||
$capcode['trip'] = $config['custom_capcode'][$cap][2]; |
$capcode['trip'] = $config['custom_capcode'][$cap][2]; |
||||
} else { |
} else { |
||||
$capcode['cap'] = sprintf($config['custom_capcode'][$cap], $cap); |
$capcode['cap'] = sprintf($config['custom_capcode'][$cap], $cap); |
||||
} |
} |
||||
} else { |
} else { |
||||
$capcode['cap'] = sprintf($config['capcode'], $cap); |
$capcode['cap'] = sprintf($config['capcode'], $cap); |
||||
} |
} |
||||
|
|
||||
return $capcode; |
return $capcode; |
||||
} |
} |
||||
|
|
||||
function truncate($body, $url, $max_lines = false, $max_chars = false) { |
function truncate($body, $url, $max_lines = false, $max_chars = false) { |
||||
global $config; |
global $config; |
||||
|
|
||||
if ($max_lines === false) |
if ($max_lines === false) |
||||
$max_lines = $config['body_truncate']; |
$max_lines = $config['body_truncate']; |
||||
if ($max_chars === false) |
if ($max_chars === false) |
||||
$max_chars = $config['body_truncate_char']; |
$max_chars = $config['body_truncate_char']; |
||||
|
|
||||
// We don't want to risk truncating in the middle of an HTML comment. |
// We don't want to risk truncating in the middle of an HTML comment. |
||||
// It's easiest just to remove them all first. |
// It's easiest just to remove them all first. |
||||
$body = preg_replace('/<!--.*?-->/s', '', $body); |
$body = preg_replace('/<!--.*?-->/s', '', $body); |
||||
|
|
||||
$original_body = $body; |
$original_body = $body; |
||||
|
|
||||
$lines = substr_count($body, '<br/>'); |
$lines = substr_count($body, '<br/>'); |
||||
|
|
||||
// Limit line count |
// Limit line count |
||||
if ($lines > $max_lines) { |
if ($lines > $max_lines) { |
||||
if (preg_match('/(((.*?)<br\/>){' . $max_lines . '})/', $body, $m)) |
if (preg_match('/(((.*?)<br\/>){' . $max_lines . '})/', $body, $m)) |
||||
$body = $m[0]; |
$body = $m[0]; |
||||
} |
} |
||||
|
|
||||
$body = mb_substr($body, 0, $max_chars); |
$body = mb_substr($body, 0, $max_chars); |
||||
|
|
||||
if ($body != $original_body) { |
if ($body != $original_body) { |
||||
// Remove any corrupt tags at the end |
// Remove any corrupt tags at the end |
||||
$body = preg_replace('/<([\w]+)?([^>]*)?$/', '', $body); |
$body = preg_replace('/<([\w]+)?([^>]*)?$/', '', $body); |
||||
|
|
||||
// Open tags |
// Open tags |
||||
if (preg_match_all('/<([\w]+)[^>]*>/', $body, $open_tags)) { |
if (preg_match_all('/<([\w]+)[^>]*>/', $body, $open_tags)) { |
||||
|
|
||||
$tags = array(); |
$tags = array(); |
||||
for ($x=0;$x<count($open_tags[0]);$x++) { |
for ($x=0;$x<count($open_tags[0]);$x++) { |
||||
if (!preg_match('/\/(\s+)?>$/', $open_tags[0][$x])) |
if (!preg_match('/\/(\s+)?>$/', $open_tags[0][$x])) |
||||
$tags[] = $open_tags[1][$x]; |
$tags[] = $open_tags[1][$x]; |
||||
} |
} |
||||
|
|
||||
// List successfully closed tags |
// List successfully closed tags |
||||
if (preg_match_all('/(<\/([\w]+))>/', $body, $closed_tags)) { |
if (preg_match_all('/(<\/([\w]+))>/', $body, $closed_tags)) { |
||||
for ($x=0;$x<count($closed_tags[0]);$x++) { |
for ($x=0;$x<count($closed_tags[0]);$x++) { |
||||
unset($tags[array_search($closed_tags[2][$x], $tags)]); |
unset($tags[array_search($closed_tags[2][$x], $tags)]); |
||||
} |
} |
||||
} |
} |
||||
|
|
||||
// remove broken HTML entity at the end (if existent) |
// remove broken HTML entity at the end (if existent) |
||||
$body = preg_replace('/&[^;]+$/', '', $body); |
$body = preg_replace('/&[^;]+$/', '', $body); |
||||
|
|
||||
$tags_no_close_needed = array("colgroup", "dd", "dt", "li", "optgroup", "option", "p", "tbody", "td", "tfoot", "th", "thead", "tr", "br", "img"); |
$tags_no_close_needed = array("colgroup", "dd", "dt", "li", "optgroup", "option", "p", "tbody", "td", "tfoot", "th", "thead", "tr", "br", "img"); |
||||
|
|
||||
// Close any open tags |
// Close any open tags |
||||
foreach ($tags as &$tag) { |
foreach ($tags as &$tag) { |
||||
if (!in_array($tag, $tags_no_close_needed)) |
if (!in_array($tag, $tags_no_close_needed)) |
||||
$body .= "</{$tag}>"; |
$body .= "</{$tag}>"; |
||||
} |
} |
||||
} else { |
} else { |
||||
// remove broken HTML entity at the end (if existent) |
// remove broken HTML entity at the end (if existent) |
||||
$body = preg_replace('/&[^;]*$/', '', $body); |
$body = preg_replace('/&[^;]*$/', '', $body); |
||||
} |
} |
||||
|
|
||||
$body .= '<span class="toolong">'.sprintf(_('Post too long. Click <a href="%s">here</a> to view the full text.'), $url).'</span>'; |
$body .= '<span class="toolong">'.sprintf(_('Post too long. Click <a href="%s">here</a> to view the full text.'), $url).'</span>'; |
||||
} |
} |
||||
|
|
||||
return $body; |
return $body; |
||||
} |
} |
||||
|
|
||||
function bidi_cleanup($data) { |
function bidi_cleanup($data) { |
||||
// Closes all embedded RTL and LTR unicode formatting blocks in a string so that |
// Closes all embedded RTL and LTR unicode formatting blocks in a string so that |
||||
// it can be used inside another without controlling its direction. |
// it can be used inside another without controlling its direction. |
||||
|
|
||||
$explicits = '\xE2\x80\xAA|\xE2\x80\xAB|\xE2\x80\xAD|\xE2\x80\xAE'; |
$explicits = '\xE2\x80\xAA|\xE2\x80\xAB|\xE2\x80\xAD|\xE2\x80\xAE'; |
||||
$pdf = '\xE2\x80\xAC'; |
$pdf = '\xE2\x80\xAC'; |
||||
|
|
||||
preg_match_all("!$explicits!", $data, $m1, PREG_OFFSET_CAPTURE | PREG_SET_ORDER); |
preg_match_all("!$explicits!", $data, $m1, PREG_OFFSET_CAPTURE | PREG_SET_ORDER); |
||||
preg_match_all("!$pdf!", $data, $m2, PREG_OFFSET_CAPTURE | PREG_SET_ORDER); |
preg_match_all("!$pdf!", $data, $m2, PREG_OFFSET_CAPTURE | PREG_SET_ORDER); |
||||
|
|
||||
if (count($m1) || count($m2)){ |
if (count($m1) || count($m2)){ |
||||
|
|
||||
$p = array(); |
$p = array(); |
||||
foreach ($m1 as $m){ $p[$m[0][1]] = 'push'; } |
foreach ($m1 as $m){ $p[$m[0][1]] = 'push'; } |
||||
foreach ($m2 as $m){ $p[$m[0][1]] = 'pop'; } |
foreach ($m2 as $m){ $p[$m[0][1]] = 'pop'; } |
||||
ksort($p); |
ksort($p); |
||||
|
|
||||
$offset = 0; |
$offset = 0; |
||||
$stack = 0; |
$stack = 0; |
||||
foreach ($p as $pos => $type){ |
foreach ($p as $pos => $type){ |
||||
|
|
||||
if ($type == 'push'){ |
if ($type == 'push'){ |
||||
$stack++; |
$stack++; |
||||
}else{ |
}else{ |
||||
if ($stack){ |
if ($stack){ |
||||
$stack--; |
$stack--; |
||||
}else{ |
}else{ |
||||
# we have a pop without a push - remove it |
# we have a pop without a push - remove it |
||||
$data = substr($data, 0, $pos-$offset) |
$data = substr($data, 0, $pos-$offset) |
||||
.substr($data, $pos+3-$offset); |
.substr($data, $pos+3-$offset); |
||||
$offset += 3; |
$offset += 3; |
||||
} |
} |
||||
} |
} |
||||
} |
} |
||||
|
|
||||
# now add some pops if your stack is bigger than 0 |
# now add some pops if your stack is bigger than 0 |
||||
for ($i=0; $i<$stack; $i++){ |
for ($i=0; $i<$stack; $i++){ |
||||
$data .= "\xE2\x80\xAC"; |
$data .= "\xE2\x80\xAC"; |
||||
} |
} |
||||
|
|
||||
return $data; |
return $data; |
||||
} |
} |
||||
|
|
||||
return $data; |
return $data; |
||||
} |
} |
||||
|
|
||||
function secure_link_confirm($text, $title, $confirm_message, $href) { |
function secure_link_confirm($text, $title, $confirm_message, $href) { |
||||
global $config; |
global $config; |
||||
|
|
||||
return '<a onclick="if (event.which==2) return true;if (confirm(\'' . htmlentities(addslashes($confirm_message)) . '\')) document.location=\'?/' . htmlspecialchars(addslashes($href . '/' . make_secure_link_token($href))) . '\';return false;" title="' . htmlentities($title) . '" href="?/' . $href . '">' . $text . '</a>'; |
return '<a onclick="if (event.which==2) return true;if (confirm(\'' . htmlentities(addslashes($confirm_message)) . '\')) document.location=\'?/' . htmlspecialchars(addslashes($href . '/' . make_secure_link_token($href))) . '\';return false;" title="' . htmlentities($title) . '" href="?/' . $href . '">' . $text . '</a>'; |
||||
} |
} |
||||
function secure_link($href) { |
function secure_link($href) { |
||||
return $href . '/' . make_secure_link_token($href); |
return $href . '/' . make_secure_link_token($href); |
||||
} |
} |
||||
|
|
||||
function embed_html($link) { |
function embed_html($link) { |
||||
global $config; |
global $config; |
||||
|
|
||||
foreach ($config['embedding'] as $embed) { |
foreach ($config['embedding'] as $embed) { |
||||
if ($html = preg_replace($embed[0], $embed[1], $link)) { |
if ($html = preg_replace($embed[0], $embed[1], $link)) { |
||||
if ($html == $link) |
if ($html == $link) |
||||
continue; // Nope |
continue; // Nope |
||||
|
|
||||
$html = str_replace('%%tb_width%%', $config['embed_width'], $html); |
$html = str_replace('%%tb_width%%', $config['embed_width'], $html); |
||||
$html = str_replace('%%tb_height%%', $config['embed_height'], $html); |
$html = str_replace('%%tb_height%%', $config['embed_height'], $html); |
||||
|
|
||||
return $html; |
return $html; |
||||
} |
} |
||||
} |
} |
||||
|
|
||||
if ($link[0] == '<') { |
if ($link[0] == '<') { |
||||
// Prior to v0.9.6-dev-8, HTML code for embedding was stored in the database instead of the link. |
// Prior to v0.9.6-dev-8, HTML code for embedding was stored in the database instead of the link. |
||||
return $link; |
return $link; |
||||
} |
} |
||||
|
|
||||
return 'Embedding error.'; |
return 'Embedding error.'; |
||||
} |
} |
||||
|
|
||||
class Post { |
class Post { |
||||
public function __construct($post, $root=null, $mod=false) { |
public function __construct($post, $root=null, $mod=false) { |
||||
global $config; |
global $config; |
||||
if (!isset($root)) |
if (!isset($root)) |
||||
$root = &$config['root']; |
$root = &$config['root']; |
||||
|
|
||||
foreach ($post as $key => $value) { |
foreach ($post as $key => $value) { |
||||
$this->{$key} = $value; |
$this->{$key} = $value; |
||||
} |
} |
||||
|
|
||||
if (isset($this->files) && $this->files) |
if (isset($this->files) && $this->files) |
||||
$this->files = @json_decode($this->files); |
$this->files = @json_decode($this->files); |
||||
|
|
||||
$this->subject = utf8tohtml($this->subject); |
$this->subject = utf8tohtml($this->subject); |
||||
$this->name = utf8tohtml($this->name); |
$this->name = utf8tohtml($this->name); |
||||
$this->mod = $mod; |
$this->mod = $mod; |
||||
$this->root = $root; |
$this->root = $root; |
||||
|
|
||||
if ($this->embed) |
if ($this->embed) |
||||
$this->embed = embed_html($this->embed); |
$this->embed = embed_html($this->embed); |
||||
|
|
||||
$this->modifiers = extract_modifiers($this->body_nomarkup); |
$this->modifiers = extract_modifiers($this->body_nomarkup); |
||||
|
|
||||
if ($config['always_regenerate_markup']) { |
if ($config['always_regenerate_markup']) { |
||||
$this->body = $this->body_nomarkup; |
$this->body = $this->body_nomarkup; |
||||
markup($this->body); |
markup($this->body); |
||||
} |
} |
||||
|
|
||||
if ($this->mod) |
if ($this->mod) |
||||
// Fix internal links |
// Fix internal links |
||||
// Very complicated regex |
// Very complicated regex |
||||
$this->body = preg_replace( |
$this->body = preg_replace( |
||||
'/<a((([a-zA-Z]+="[^"]+")|[a-zA-Z]+=[a-zA-Z]+|\s)*)href="' . preg_quote($config['root'], '/') . '(' . sprintf(preg_quote($config['board_path'], '/'), $config['board_regex']) . ')/u', |
'/<a((([a-zA-Z]+="[^"]+")|[a-zA-Z]+=[a-zA-Z]+|\s)*)href="' . preg_quote($config['root'], '/') . '(' . sprintf(preg_quote($config['board_path'], '/'), $config['board_regex']) . ')/u', |
||||
'<a $1href="?/$4', |
'<a $1href="?/$4', |
||||
$this->body |
$this->body |
||||
); |
); |
||||
} |
} |
||||
public function link($pre = '', $page = false) { |
public function link($pre = '', $page = false) { |
||||
global $config, $board; |
global $config, $board; |
||||
|
|
||||
return $this->root . $board['dir'] . $config['dir']['res'] . link_for((array)$this, $page == '50') . '#' . $pre . $this->id; |
return $this->root . $board['dir'] . $config['dir']['res'] . link_for((array)$this, $page == '50') . '#' . $pre . $this->id; |
||||
} |
} |
||||
|
|
||||
public function build($index=false) { |
public function build($index=false) { |
||||
global $board, $config; |
global $board, $config; |
||||
|
|
||||
return Element('post_reply.html', array('config' => $config, 'board' => $board, 'post' => &$this, 'index' => $index, 'mod' => $this->mod)); |
return Element('post_reply.html', array('config' => $config, 'board' => $board, 'post' => &$this, 'index' => $index, 'mod' => $this->mod)); |
||||
} |
} |
||||
}; |
}; |
||||
|
|
||||
class Thread { |
class Thread { |
||||
public function __construct($post, $root = null, $mod = false, $hr = true) { |
public function __construct($post, $root = null, $mod = false, $hr = true) { |
||||
global $config; |
global $config; |
||||
if (!isset($root)) |
if (!isset($root)) |
||||
$root = &$config['root']; |
$root = &$config['root']; |
||||
|
|
||||
foreach ($post as $key => $value) { |
foreach ($post as $key => $value) { |
||||
$this->{$key} = $value; |
$this->{$key} = $value; |
||||
} |
} |
||||
|
|
||||
if (isset($this->files)) |
if (isset($this->files)) |
||||
$this->files = @json_decode($this->files); |
$this->files = @json_decode($this->files); |
||||
|
|
||||
$this->subject = utf8tohtml($this->subject); |
$this->subject = utf8tohtml($this->subject); |
||||
$this->name = utf8tohtml($this->name); |
$this->name = utf8tohtml($this->name); |
||||
$this->mod = $mod; |
$this->mod = $mod; |
||||
$this->root = $root; |
$this->root = $root; |
||||
$this->hr = $hr; |
$this->hr = $hr; |
||||
|
|
||||
$this->posts = array(); |
$this->posts = array(); |
||||
$this->omitted = 0; |
$this->omitted = 0; |
||||
$this->omitted_images = 0; |
$this->omitted_images = 0; |
||||
|
|
||||
if ($this->embed) |
if ($this->embed) |
||||
$this->embed = embed_html($this->embed); |
$this->embed = embed_html($this->embed); |
||||
|
|
||||
$this->modifiers = extract_modifiers($this->body_nomarkup); |
$this->modifiers = extract_modifiers($this->body_nomarkup); |
||||
|
|
||||
if ($config['always_regenerate_markup']) { |
if ($config['always_regenerate_markup']) { |
||||
$this->body = $this->body_nomarkup; |
$this->body = $this->body_nomarkup; |
||||
markup($this->body); |
markup($this->body); |
||||
} |
} |
||||
|
|
||||
if ($this->mod) |
if ($this->mod) |
||||
// Fix internal links |
// Fix internal links |
||||
// Very complicated regex |
// Very complicated regex |
||||
$this->body = preg_replace( |
$this->body = preg_replace( |
||||
'/<a((([a-zA-Z]+="[^"]+")|[a-zA-Z]+=[a-zA-Z]+|\s)*)href="' . preg_quote($config['root'], '/') . '(' . sprintf(preg_quote($config['board_path'], '/'), $config['board_regex']) . ')/u', |
'/<a((([a-zA-Z]+="[^"]+")|[a-zA-Z]+=[a-zA-Z]+|\s)*)href="' . preg_quote($config['root'], '/') . '(' . sprintf(preg_quote($config['board_path'], '/'), $config['board_regex']) . ')/u', |
||||
'<a $1href="?/$4', |
'<a $1href="?/$4', |
||||
$this->body |
$this->body |
||||
); |
); |
||||
} |
} |
||||
public function link($pre = '', $page = false) { |
public function link($pre = '', $page = false) { |
||||
global $config, $board; |
global $config, $board; |
||||
|
|
||||
return $this->root . $board['dir'] . $config['dir']['res'] . link_for((array)$this, $page == '50') . '#' . $pre . $this->id; |
return $this->root . $board['dir'] . $config['dir']['res'] . link_for((array)$this, $page == '50') . '#' . $pre . $this->id; |
||||
} |
} |
||||
public function add(Post $post) { |
public function add(Post $post) { |
||||
$this->posts[] = $post; |
$this->posts[] = $post; |
||||
} |
} |
||||
public function postCount() { |
public function postCount() { |
||||
return count($this->posts) + $this->omitted; |
return count($this->posts) + $this->omitted; |
||||
} |
} |
||||
public function build($index=false, $isnoko50=false) { |
public function build($index=false, $isnoko50=false) { |
||||
global $board, $config, $debug; |
global $board, $config, $debug; |
||||
|
|
||||
$hasnoko50 = $this->postCount() >= $config['noko50_min']; |
$hasnoko50 = $this->postCount() >= $config['noko50_min']; |
||||
|
|
||||
event('show-thread', $this); |
event('show-thread', $this); |
||||
|
|
||||
$file = ($index && $config['file_board']) ? 'post_thread_fileboard.html' : 'post_thread.html'; |
$file = ($index && $config['file_board']) ? 'post_thread_fileboard.html' : 'post_thread.html'; |
||||
$built = Element($file, array('config' => $config, 'board' => $board, 'post' => &$this, 'index' => $index, 'hasnoko50' => $hasnoko50, 'isnoko50' => $isnoko50, 'mod' => $this->mod)); |
$built = Element($file, array('config' => $config, 'board' => $board, 'post' => &$this, 'index' => $index, 'hasnoko50' => $hasnoko50, 'isnoko50' => $isnoko50, 'mod' => $this->mod)); |
||||
|
|
||||
return $built; |
return $built; |
||||
} |
} |
||||
}; |
}; |
||||
|
|
||||
|
Loading…
Reference in new issue