'. preg_replace('!\s+!', ' ', htmlspecialchars($query)) .'
', '' => '') as $k => $v) { $p = 0; while (($p = strpos($text_l, $v, $p)) !== false) { if (($e = strpos($text_l, $k, $p)) === false) { $p += 5; continue; } $text_l = substr_replace($text_l, str_repeat(' ', $e - $p), $p, ($e - $p)); $p = $e; } } foreach ($SML_REPL as $k => $v) { $a = 0; $len = strlen($k); while (($a = strpos($text_l, $k, $a)) !== false) { if ((!$a || isset($GLOBALS['__SML_CHR_CHK__'][$text_l[$a - 1]])) && ((@$ch = $text_l[$a + $len]) == '' || isset($GLOBALS['__SML_CHR_CHK__'][$ch]))) { $text_l = substr_replace($text_l, $v, $a, $len); $text = substr_replace($text, $v, $a, $len); $a += strlen($v) - $len; } else { $a += $len; } } } return $text; } function post_to_smiley($text) { /* include once since draw_post_smiley_cntrl() may use it too */ include_once $GLOBALS['FORUM_SETTINGS_PATH'].'ps_cache'; if (isset($PS_SRC)) { $GLOBALS['PS_SRC'] = $PS_SRC; $GLOBALS['PS_DST'] = $PS_DST; } else { $PS_SRC = $GLOBALS['PS_SRC']; $PS_DST = $GLOBALS['PS_DST']; } /* check for emoticons */ foreach ($PS_SRC as $k => $v) { if (strpos($text, $v) === false) { unset($PS_SRC[$k], $PS_DST[$k]); } } return $PS_SRC ? str_replace($PS_SRC, $PS_DST, $text) : $text; } if (!($FUD_OPT_2 & 134217728)) { // PDF_ENABLED std_error('disabled'); } if ($FUD_OPT_2 & 16384) { // PHP_COMPRESSION_ENABLE ob_start('ob_gzhandler', (int)$PHP_COMPRESSION_LEVEL); } $forum = isset($_GET['frm']) ? (int)$_GET['frm'] : 0; $thread = isset($_GET['th']) ? (int)$_GET['th'] : 0; $msg = isset($_GET['msg']) ? (int)$_GET['msg'] : 0; $page = isset($_GET['page']) ? (int)$_GET['page'] : 0; $sel = isset($_GET['sel']) ? (array)$_GET['sel'] : array(); // Cleanup $sel foreach ($sel as $k => $v) { if ($v = (int)$v) { $sel[$k] = $v; } else { unset($sel[$k]); } } if ($forum) { if (!($FUD_OPT_2 & 268435456)) { // PDF_ALLOW_FULL std_error('disabled'); } if (!$page) { $page = 1; } if ($page) { if (!q_singleval('SELECT id FROM fud30_forum WHERE id='. $forum)) { invl_inp_err(); } $lwi = q_singleval(q_limit('SELECT seq FROM fud30_tv_'. $forum .' ORDER BY seq DESC', 1)); if ($lwi === NULL || $lwi === FALSE) { invl_inp_err(); } $join = 'FROM fud30_tv_'. $forum .' tv INNER JOIN fud30_thread t ON t.id=tv.thread_id INNER JOIN fud30_forum f ON f.id='. $forum .' INNER JOIN fud30_msg m ON m.thread_id=t.id LEFT JOIN fud30_users u ON m.poster_id=u.id LEFT JOIN fud30_poll p ON m.poll_id=p.id '; $lmt = ' AND tv.seq BETWEEN '. ($lwi - ($page * $THREADS_PER_PAGE) + 1) .' AND '. ($lwi - (($page - 1) * $THREADS_PER_PAGE)); } else { $join = 'FROM fud30_forum f INNER JOIN fud30_thread t ON t.forum_id=f.id INNER JOIN fud30_msg m ON m.thread_id=t.id LEFT JOIN fud30_users u ON m.poster_id=u.id LEFT JOIN fud30_poll p ON m.poll_id=p.id '; $lmt = ' AND f.id='. $forum; } } else if ($thread) { $join = 'FROM fud30_msg m INNER JOIN fud30_thread t ON t.id=m.thread_id INNER JOIN fud30_forum f ON f.id=t.forum_id LEFT JOIN fud30_users u ON m.poster_id=u.id LEFT JOIN fud30_poll p ON m.poll_id=p.id '; $lmt = ' AND m.thread_id='. $thread; } else if ($msg) { $lmt = ' AND m.id='. $msg; $join = 'FROM fud30_msg m INNER JOIN fud30_thread t ON t.id=m.thread_id INNER JOIN fud30_forum f ON f.id=t.forum_id LEFT JOIN fud30_users u ON m.poster_id=u.id LEFT JOIN fud30_poll p ON m.poll_id=p.id '; } else if ($sel) { /* PM handling. */ if (!q_singleval('SELECT count(*) FROM fud30_pmsg WHERE id IN('. implode(',', $sel) .') AND duser_id='. _uid)) { invl_inp_err(); } fud_use('private.inc'); } else { invl_inp_err(); } if (_uid) { if (!$is_a) { $join .= ' INNER JOIN fud30_group_cache g1 ON g1.user_id=2147483647 AND g1.resource_id=f.id LEFT JOIN fud30_group_cache g2 ON g2.user_id='. _uid .' AND g2.resource_id=f.id LEFT JOIN fud30_mod mm ON mm.forum_id=f.id AND mm.user_id='. _uid .' '; $lmt .= ' AND (mm.id IS NOT NULL OR '. q_bitand('COALESCE(g2.group_cache_opt, g1.group_cache_opt)', 2) .' > 0)'; } } else { $join .= ' INNER JOIN fud30_group_cache g1 ON g1.user_id=0 AND g1.resource_id=f.id '; $lmt .= ' AND '. q_bitand('g1.group_cache_opt', 2) .' > 0'; } if ($forum) { $subject = q_singleval('SELECT name FROM fud30_forum WHERE id='. $forum); } if (!$sel) { $c = q('SELECT m.id, m.thread_id, m.subject, m.post_stamp, m.attach_cnt, m.attach_cache, m.poll_cache, m.foff, m.length, m.file_id, u.id AS user_id, COALESCE(u.alias, \''. $ANON_NICK .'\') as alias, p.name AS poll_name, p.total_votes '. $join .' WHERE t.moved_to=0 AND m.apr=1 '. $lmt .' ORDER BY m.post_stamp, m.thread_id'); } else { $c = q('SELECT p.*, u.alias, p.duser_id AS user_id FROM fud30_pmsg p LEFT JOIN fud30_users u ON p.ouser_id=u.id WHERE p.id IN('. implode(',', $sel) .') AND p.duser_id='. _uid); } if (!($o = db_rowobj($c))) { invl_inp_err(); } if ($thread || $msg) { $subject = reverse_fmt($o->subject); } else if ($sel) { $subject = 'Private Message Archive'; } $fpdf = new fud_pdf('P', 'mm', $PDF_PAGE); $fpdf->SetAuthor('FUDforum '. $FORUM_VERSION); $fpdf->SetTitle(html_entity_decode($FORUM_TITLE)); $fpdf->SetSubject($subject); $fpdf->SetMargins($PDF_WMARGIN, $PDF_HMARGIN); $fpdf->AliasNbPages('{fnb}'); // Alias for total number of pages. $fpdf->begin_page($subject); do { /* Write message header. */ $fpdf->message_header(html_entity_decode($o->subject), array($o->user_id, html_entity_decode($o->alias)), $o->post_stamp, $o->id, (isset($o->thread_id) ? $o->thread_id : 0)); /* Write message body. */ if (!$sel) { $body = read_msg_body($o->foff, $o->length, $o->file_id); } else { $body = read_pmsg_body($o->foff, $o->length); } $fpdf->input_text(html_entity_decode(strip_tags(post_to_smiley($body)))); /* Handle attachments. */ if ($o->attach_cnt) { if (!empty($o->attach_cache) && ($a = unserialize($o->attach_cache))) { $attch = array(); foreach ($a as $i) { $attch[] = array('id' => $i[0], 'name' => $i[1], 'nd' => $i[3]); } $fpdf->add_attacments($attch); } else if ($sel) { $attch = array(); $c2 = uq('SELECT id, original_name, dlcount FROM fud30_attach WHERE message_id='. $o->id .' AND attach_opt=1'); while ($r2 = db_rowarr($c2)) { $attch[] = array('id' => $r2[0], 'name' => $r2[1], 'nd' => $r2[2]); } unset($c2); if ($attch) { $fpdf->add_attacments($attch, 1); } } } /* Handle polls. */ if (!empty($o->poll_name) && $o->poll_cache && ($pc = unserialize($o->poll_cache))) { $votes = array(); foreach ($pc as $opt) { $votes[] = array('name' => html_entity_decode(strip_tags(post_to_smiley($opt[0]))), 'votes' => $opt[1]); } $fpdf->add_poll(html_entity_decode($o->poll_name), $votes, $o->total_votes); } $fpdf->end_message(); } while (($o = db_rowobj($c))); unset($c); /* Output content to browser. */ $out = $fpdf->Output('FUDforum'. date('Ymd') .'.pdf', 'S'); header('Content-Type: application/pdf'); if ($_SERVER['SERVER_PORT'] == '443' && (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== false)) { header('Cache-Control: must-revalidate, post-check=0, pre-check=0', 1); header('Pragma: public', 1); } if (!($GLOBALS['FUD_OPT_2'] & 16384)) { header('Content-Length: '. strlen($out)); } header('Content-disposition: inline; filename=FUDforum'. date('Ymd') .'.pdf'); echo $out; ?>