| <?php |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| if (!defined('IN_PHPBB')) |
| { |
| exit; |
| } |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| function gen_sort_selects(&$limit_days, &$sort_by_text, &$sort_days, &$sort_key, &$sort_dir, &$s_limit_days, &$s_sort_key, &$s_sort_dir, &$u_sort_param, $def_st = false, $def_sk = false, $def_sd = false) |
| { |
| global $user; |
| |
| $sort_dir_text = array('a' => $user->lang['ASCENDING'], 'd' => $user->lang['DESCENDING']); |
| |
| $sorts = array( |
| 'st' => array( |
| 'key' => 'sort_days', |
| 'default' => $def_st, |
| 'options' => $limit_days, |
| 'output' => &$s_limit_days, |
| ), |
| |
| 'sk' => array( |
| 'key' => 'sort_key', |
| 'default' => $def_sk, |
| 'options' => $sort_by_text, |
| 'output' => &$s_sort_key, |
| ), |
| |
| 'sd' => array( |
| 'key' => 'sort_dir', |
| 'default' => $def_sd, |
| 'options' => $sort_dir_text, |
| 'output' => &$s_sort_dir, |
| ), |
| ); |
| $u_sort_param = ''; |
| |
| foreach ($sorts as $name => $sort_ary) |
| { |
| $key = $sort_ary['key']; |
| $selected = $$sort_ary['key']; |
| |
| |
| |
| |
| if (!isset($sort_ary['options'][$selected])) |
| { |
| if ($sort_ary['default'] !== false) |
| { |
| $selected = $$key = $sort_ary['default']; |
| } |
| else |
| { |
| @reset($sort_ary['options']); |
| $selected = $$key = key($sort_ary['options']); |
| } |
| } |
| |
| $sort_ary['output'] = '<select name="' . $name . '" id="' . $name . '">'; |
| foreach ($sort_ary['options'] as $option => $text) |
| { |
| $sort_ary['output'] .= '<option value="' . $option . '"' . (($selected == $option) ? ' selected="selected"' : '') . '>' . $text . '</option>'; |
| } |
| $sort_ary['output'] .= '</select>'; |
| |
| $u_sort_param .= ($selected !== $sort_ary['default']) ? ((strlen($u_sort_param)) ? '&' : '') . "{$name}={$selected}" : ''; |
| } |
| |
| return; |
| } |
| |
| |
| |
| |
| function make_jumpbox($action, $forum_id = false, $select_all = false, $acl_list = false, $force_display = false) |
| { |
| global $config, $auth, $template, $user, $db; |
| |
| |
| if (!$config['load_jumpbox'] && $force_display === false) |
| { |
| return; |
| } |
| |
| $sql = 'SELECT forum_id, forum_name, parent_id, forum_type, left_id, right_id |
| FROM ' . FORUMS_TABLE . ' |
| ORDER BY left_id ASC'; |
| $result = $db->sql_query($sql, 600); |
| |
| $right = $padding = 0; |
| $padding_store = array('0' => 0); |
| $display_jumpbox = false; |
| $iteration = 0; |
| |
| |
| |
| |
| |
| while ($row = $db->sql_fetchrow($result)) |
| { |
| if ($row['left_id'] < $right) |
| { |
| $padding++; |
| $padding_store[$row['parent_id']] = $padding; |
| } |
| else if ($row['left_id'] > $right + 1) |
| { |
| |
| |
| $padding = (isset($padding_store[$row['parent_id']])) ? $padding_store[$row['parent_id']] : $padding; |
| } |
| |
| $right = $row['right_id']; |
| |
| if ($row['forum_type'] == FORUM_CAT && ($row['left_id'] + 1 == $row['right_id'])) |
| { |
| |
| continue; |
| } |
| |
| if (!$auth->acl_get('f_list', $row['forum_id'])) |
| { |
| |
| continue; |
| } |
| |
| if ($acl_list && !$auth->acl_gets($acl_list, $row['forum_id'])) |
| { |
| continue; |
| } |
| |
| if (!$display_jumpbox) |
| { |
| $template->assign_block_vars('jumpbox_forums', array( |
| 'FORUM_ID' => ($select_all) ? 0 : -1, |
| 'FORUM_NAME' => ($select_all) ? $user->lang['ALL_FORUMS'] : $user->lang['SELECT_FORUM'], |
| 'S_FORUM_COUNT' => $iteration) |
| ); |
| |
| $iteration++; |
| $display_jumpbox = true; |
| } |
| |
| $template->assign_block_vars('jumpbox_forums', array( |
| 'FORUM_ID' => $row['forum_id'], |
| 'FORUM_NAME' => $row['forum_name'], |
| 'SELECTED' => ($row['forum_id'] == $forum_id) ? ' selected="selected"' : '', |
| 'S_FORUM_COUNT' => $iteration, |
| 'S_IS_CAT' => ($row['forum_type'] == FORUM_CAT) ? true : false, |
| 'S_IS_LINK' => ($row['forum_type'] == FORUM_LINK) ? true : false, |
| 'S_IS_POST' => ($row['forum_type'] == FORUM_POST) ? true : false) |
| ); |
| |
| for ($i = 0; $i < $padding; $i++) |
| { |
| $template->assign_block_vars('jumpbox_forums.level', array()); |
| } |
| $iteration++; |
| } |
| $db->sql_freeresult($result); |
| unset($padding_store); |
| |
| $template->assign_vars(array( |
| 'S_DISPLAY_JUMPBOX' => $display_jumpbox, |
| 'S_JUMPBOX_ACTION' => $action) |
| ); |
| |
| return; |
| } |
| |
| |
| |
| |
| function bump_topic_allowed($forum_id, $topic_bumped, $last_post_time, $topic_poster, $last_topic_poster) |
| { |
| global $config, $auth, $user; |
| |
| |
| if (!$auth->acl_get('f_bump', $forum_id) || $topic_bumped) |
| { |
| return false; |
| } |
| |
| |
| $bump_time = ($config['bump_type'] == 'm') ? $config['bump_interval'] * 60 : (($config['bump_type'] == 'h') ? $config['bump_interval'] * 3600 : $config['bump_interval'] * 86400); |
| |
| |
| if ($last_post_time + $bump_time > time()) |
| { |
| return false; |
| } |
| |
| |
| if ($topic_poster != $user->data['user_id'] && $last_topic_poster != $user->data['user_id']) |
| { |
| return false; |
| } |
| |
| |
| return $bump_time; |
| } |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| function get_context($text, $words, $length = 400) |
| { |
| |
| $text = preg_replace('/ +/', ' ', strtr($text, "\t\n\r\x0C ", ' ')); |
| |
| $word_indizes = array(); |
| if (sizeof($words)) |
| { |
| $match = ''; |
| |
| foreach ($words as $word) |
| { |
| if ($word) |
| { |
| if (preg_match('#(?:[^\w]|^)(' . $word . ')(?:[^\w]|$)#i', $text, $match)) |
| { |
| $pos = utf8_strpos($text, $match[1]); |
| if ($pos !== false) |
| { |
| $word_indizes[] = $pos; |
| } |
| } |
| } |
| } |
| unset($match); |
| |
| if (sizeof($word_indizes)) |
| { |
| $word_indizes = array_unique($word_indizes); |
| sort($word_indizes); |
| |
| $wordnum = sizeof($word_indizes); |
| |
| $sequence_length = (int) ($length / (2 * $wordnum)) - 2; |
| $final_text = ''; |
| $word = $j = 0; |
| $final_text_index = -1; |
| |
| |
| for ($i = $word_indizes[$word], $n = utf8_strlen($text); $i < $n; $i++) |
| { |
| |
| if (isset($word_indizes[$word]) && ($i == $word_indizes[$word])) |
| { |
| if ($final_text_index < $i - $sequence_length - 1) |
| { |
| $final_text .= '... ' . preg_replace('#^([^ ]*)#', '', utf8_substr($text, $i - $sequence_length, $sequence_length)); |
| } |
| else |
| { |
| |
| |
| $sequence_length += (int) (($final_text_index - $i + $sequence_length + 1) / (2 * $wordnum)); |
| $final_text .= utf8_substr($text, $final_text_index + 1, $i - $final_text_index - 1); |
| } |
| $final_text_index = $i - 1; |
| |
| |
| $word++; |
| $j = 1; |
| } |
| |
| if ($j > 0) |
| { |
| |
| $final_text .= utf8_substr($text, $i, 1); |
| $final_text_index++; |
| $j++; |
| |
| |
| if (utf8_substr($text, $i, 1) == ' ') |
| { |
| |
| if ($i + 4 < $n) |
| { |
| if (($j > $sequence_length && $word >= $wordnum) || utf8_strlen($final_text) > $length) |
| { |
| $final_text .= ' ...'; |
| break; |
| } |
| } |
| else |
| { |
| |
| $j -= 4; |
| } |
| |
| |
| if ($j > $sequence_length) |
| { |
| $j = 0; |
| } |
| } |
| } |
| } |
| return $final_text; |
| } |
| } |
| |
| if (!sizeof($words) || !sizeof($word_indizes)) |
| { |
| return (utf8_strlen($text) >= $length + 3) ? utf8_substr($text, 0, $length) . '...' : $text; |
| } |
| } |
| |
| |
| |
| |
| |
| function decode_message(&$message, $bbcode_uid = '') |
| { |
| global $config; |
| |
| if ($bbcode_uid) |
| { |
| $match = array('<br />', "[/*:m:$bbcode_uid]", ":u:$bbcode_uid", ":o:$bbcode_uid", ":$bbcode_uid"); |
| $replace = array("\n", '', '', '', ''); |
| } |
| else |
| { |
| $match = array('<br />'); |
| $replace = array("\n"); |
| } |
| |
| $message = str_replace($match, $replace, $message); |
| |
| $match = get_preg_expression('bbcode_htm'); |
| $replace = array('\1', '\1', '\2', '\1', '', ''); |
| |
| $message = preg_replace($match, $replace, $message); |
| } |
| |
| |
| |
| |
| function strip_bbcode(&$text, $uid = '') |
| { |
| if (!$uid) |
| { |
| $uid = '[0-9a-z]{5,}'; |
| } |
| |
| $text = preg_replace("#\[\/?[a-z0-9\*\+\-]+(?:=(?:".*"|[^\]]*))?(?::[a-z])?(\:$uid)\]#", ' ', $text); |
| |
| $match = get_preg_expression('bbcode_htm'); |
| $replace = array('\1', '\1', '\2', '\1', '', ''); |
| |
| $text = preg_replace($match, $replace, $text); |
| } |
| |
| |
| |
| |
| |
| function generate_text_for_display($text, $uid, $bitfield, $flags) |
| { |
| static $bbcode; |
| |
| if (!$text) |
| { |
| return ''; |
| } |
| |
| $text = censor_text($text); |
| |
| |
| if ($uid && ($flags & OPTION_FLAG_BBCODE)) |
| { |
| if (!class_exists('bbcode')) |
| { |
| global $phpbb_root_path, $phpEx; |
| include($phpbb_root_path . 'includes/bbcode.' . $phpEx); |
| } |
| |
| if (empty($bbcode)) |
| { |
| $bbcode = new bbcode($bitfield); |
| } |
| else |
| { |
| $bbcode->bbcode($bitfield); |
| } |
| |
| $bbcode->bbcode_second_pass($text, $uid); |
| } |
| |
| $text = bbcode_nl2br($text); |
| $text = smiley_text($text, !($flags & OPTION_FLAG_SMILIES)); |
| |
| return $text; |
| } |
| |
| |
| |
| |
| |
| |
| function generate_text_for_storage(&$text, &$uid, &$bitfield, &$flags, $allow_bbcode = false, $allow_urls = false, $allow_smilies = false) |
| { |
| global $phpbb_root_path, $phpEx; |
| |
| $uid = $bitfield = ''; |
| $flags = (($allow_bbcode) ? OPTION_FLAG_BBCODE : 0) + (($allow_smilies) ? OPTION_FLAG_SMILIES : 0) + (($allow_urls) ? OPTION_FLAG_LINKS : 0); |
| |
| if (!$text) |
| { |
| return; |
| } |
| |
| if (!class_exists('parse_message')) |
| { |
| include($phpbb_root_path . 'includes/message_parser.' . $phpEx); |
| } |
| |
| $message_parser = new parse_message($text); |
| $message_parser->parse($allow_bbcode, $allow_urls, $allow_smilies); |
| |
| $text = $message_parser->message; |
| $uid = $message_parser->bbcode_uid; |
| |
| |
| if (!$message_parser->bbcode_bitfield) |
| { |
| $uid = ''; |
| } |
| |
| $bitfield = $message_parser->bbcode_bitfield; |
| |
| return; |
| } |
| |
| |
| |
| |
| |
| function generate_text_for_edit($text, $uid, $flags) |
| { |
| global $phpbb_root_path, $phpEx; |
| |
| decode_message($text, $uid); |
| |
| return array( |
| 'allow_bbcode' => ($flags & OPTION_FLAG_BBCODE) ? 1 : 0, |
| 'allow_smilies' => ($flags & OPTION_FLAG_SMILIES) ? 1 : 0, |
| 'allow_urls' => ($flags & OPTION_FLAG_LINKS) ? 1 : 0, |
| 'text' => $text |
| ); |
| } |
| |
| |
| |
| |
| |
| |
| function make_clickable_callback($type, $whitespace, $url, $relative_url, $class) |
| { |
| $orig_url = $url; |
| $orig_relative = $relative_url; |
| $append = ''; |
| $url = htmlspecialchars_decode($url); |
| $relative_url = htmlspecialchars_decode($relative_url); |
| |
| |
| $chars = array('<', '>', '"'); |
| $split = false; |
| |
| foreach ($chars as $char) |
| { |
| $next_split = strpos($url, $char); |
| if ($next_split !== false) |
| { |
| $split = ($split !== false) ? min($split, $next_split) : $next_split; |
| } |
| } |
| |
| if ($split !== false) |
| { |
| |
| $append = substr($url, $split) . $relative_url; |
| $url = substr($url, 0, $split); |
| $relative_url = ''; |
| } |
| else if ($relative_url) |
| { |
| |
| $split = false; |
| foreach ($chars as $char) |
| { |
| $next_split = strpos($relative_url, $char); |
| if ($next_split !== false) |
| { |
| $split = ($split !== false) ? min($split, $next_split) : $next_split; |
| } |
| } |
| |
| if ($split !== false) |
| { |
| $append = substr($relative_url, $split); |
| $relative_url = substr($relative_url, 0, $split); |
| } |
| } |
| |
| |
| $last_char = ($relative_url) ? $relative_url[strlen($relative_url) - 1] : $url[strlen($url) - 1]; |
| |
| switch ($last_char) |
| { |
| case '.': |
| case '?': |
| case '!': |
| case ':': |
| case ',': |
| $append = $last_char; |
| if ($relative_url) |
| { |
| $relative_url = substr($relative_url, 0, -1); |
| } |
| else |
| { |
| $url = substr($url, 0, -1); |
| } |
| break; |
| |
| |
| |
| default: |
| $last_char = ''; |
| break; |
| } |
| |
| $short_url = (strlen($url) > 55) ? substr($url, 0, 39) . ' ... ' . substr($url, -10) : $url; |
| |
| switch ($type) |
| { |
| case MAGIC_URL_LOCAL: |
| $tag = 'l'; |
| $relative_url = preg_replace('/[&?]sid=[0-9a-f]{32}$/', '', preg_replace('/([&?])sid=[0-9a-f]{32}&/', '$1', $relative_url)); |
| $url = $url . '/' . $relative_url; |
| $text = $relative_url; |
| |
| |
| |
| |
| if (!$relative_url) |
| { |
| return $whitespace . $orig_url . '/' . $orig_relative; |
| } |
| break; |
| |
| case MAGIC_URL_FULL: |
| $tag = 'm'; |
| $text = $short_url; |
| break; |
| |
| case MAGIC_URL_WWW: |
| $tag = 'w'; |
| $url = 'http://' . $url; |
| $text = $short_url; |
| break; |
| |
| case MAGIC_URL_EMAIL: |
| $tag = 'e'; |
| $text = $short_url; |
| $url = 'mailto:' . $url; |
| break; |
| } |
| |
| $url = htmlspecialchars($url); |
| $text = htmlspecialchars($text); |
| $append = htmlspecialchars($append); |
| |
| $html = "$whitespace<!-- $tag --><a$class href=\"$url\">$text</a><!-- $tag -->$append"; |
| |
| return $html; |
| } |
| |
| |
| |
| |
| |
| |
| |
| |
| function make_clickable($text, $server_url = false, $class = 'postlink') |
| { |
| if ($server_url === false) |
| { |
| $server_url = generate_board_url(); |
| } |
| |
| static $magic_url_match; |
| static $magic_url_replace; |
| static $static_class; |
| |
| if (!is_array($magic_url_match) || $static_class != $class) |
| { |
| $static_class = $class; |
| $class = ($static_class) ? ' class="' . $static_class . '"' : ''; |
| $local_class = ($static_class) ? ' class="' . $static_class . '-local"' : ''; |
| |
| $magic_url_match = $magic_url_replace = array(); |
| |
| |
| |
| $magic_url_match[] = '#(^|[\n\t (>.])(' . preg_quote($server_url, '#') . ')/(' . get_preg_expression('relative_url_inline') . ')#ie'; |
| $magic_url_replace[] = "make_clickable_callback(MAGIC_URL_LOCAL, '\$1', '\$2', '\$3', '$local_class')"; |
| |
| |
| $magic_url_match[] = '#(^|[\n\t (>.])(' . get_preg_expression('url_inline') . ')#ie'; |
| $magic_url_replace[] = "make_clickable_callback(MAGIC_URL_FULL, '\$1', '\$2', '', '$class')"; |
| |
| |
| $magic_url_match[] = '#(^|[\n\t (>])(' . get_preg_expression('www_url_inline') . ')#ie'; |
| $magic_url_replace[] = "make_clickable_callback(MAGIC_URL_WWW, '\$1', '\$2', '', '$class')"; |
| |
| |
| $magic_url_match[] = '/(^|[\n\t (>])(' . get_preg_expression('email') . ')/ie'; |
| $magic_url_replace[] = "make_clickable_callback(MAGIC_URL_EMAIL, '\$1', '\$2', '', '')"; |
| } |
| |
| return preg_replace($magic_url_match, $magic_url_replace, $text); |
| } |
| |
| |
| |
| |
| function censor_text($text) |
| { |
| static $censors; |
| |
| |
| if (!isset($censors) || !is_array($censors)) |
| { |
| global $config, $user, $auth, $cache; |
| |
| |
| if (!$user->optionget('viewcensors') && $config['allow_nocensors'] && $auth->acl_get('u_chgcensors')) |
| { |
| $censors = array(); |
| } |
| else |
| { |
| $censors = $cache->obtain_word_list(); |
| } |
| } |
| |
| if (sizeof($censors)) |
| { |
| return preg_replace($censors['match'], $censors['replace'], $text); |
| } |
| |
| return $text; |
| } |
| |
| |
| |
| |
| function bbcode_nl2br($text) |
| { |
| |
| |
| $text = str_replace(array("\n", "\r"), array('<br />', "\n"), $text); |
| return $text; |
| } |
| |
| |
| |
| |
| function smiley_text($text, $force_option = false) |
| { |
| global $config, $user, $phpbb_root_path; |
| |
| if ($force_option || !$config['allow_smilies'] || !$user->optionget('viewsmilies')) |
| { |
| return preg_replace('#<!\-\- s(.*?) \-\-><img src="\{SMILIES_PATH\}\/.*? \/><!\-\- s\1 \-\->#', '\1', $text); |
| } |
| else |
| { |
| return preg_replace('#<!\-\- s(.*?) \-\-><img src="\{SMILIES_PATH\}\/(.*?) \/><!\-\- s\1 \-\->#', '<img src="' . $phpbb_root_path . $config['smilies_path'] . '/\2 />', $text); |
| } |
| } |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| function parse_attachments($forum_id, &$message, &$attachments, &$update_count, $preview = false) |
| { |
| if (!sizeof($attachments)) |
| { |
| return; |
| } |
| |
| global $template, $cache, $user; |
| global $extensions, $config, $phpbb_root_path, $phpEx; |
| |
| |
| $compiled_attachments = array(); |
| |
| if (!isset($template->filename['attachment_tpl'])) |
| { |
| $template->set_filenames(array( |
| 'attachment_tpl' => 'attachment.html') |
| ); |
| } |
| |
| if (empty($extensions) || !is_array($extensions)) |
| { |
| $extensions = $cache->obtain_attach_extensions($forum_id); |
| } |
| |
| |
| $attach_ids = array(); |
| foreach ($attachments as $pos => $attachment) |
| { |
| |
| if (!isset($attachment['extension']) && !isset($attachment['physical_filename'])) |
| { |
| $attach_ids[(int) $attachment['attach_id']] = $pos; |
| } |
| } |
| |
| |
| if (sizeof($attach_ids)) |
| { |
| global $db; |
| |
| $new_attachment_data = array(); |
| |
| $sql = 'SELECT * |
| FROM ' . ATTACHMENTS_TABLE . ' |
| WHERE ' . $db->sql_in_set('attach_id', array_keys($attach_ids)); |
| $result = $db->sql_query($sql); |
| |
| while ($row = $db->sql_fetchrow($result)) |
| { |
| if (!isset($attach_ids[$row['attach_id']])) |
| { |
| continue; |
| } |
| |
| |
| if ($preview) |
| { |
| $row['attach_comment'] = $attachments[$attach_ids[$row['attach_id']]]['attach_comment']; |
| } |
| |
| $new_attachment_data[$attach_ids[$row['attach_id']]] = $row; |
| } |
| $db->sql_freeresult($result); |
| |
| $attachments = $new_attachment_data; |
| unset($new_attachment_data); |
| } |
| |
| |
| if ($config['display_order']) |
| { |
| |
| krsort($attachments); |
| } |
| else |
| { |
| |
| ksort($attachments); |
| } |
| |
| foreach ($attachments as $attachment) |
| { |
| if (!sizeof($attachment)) |
| { |
| continue; |
| } |
| |
| |
| $template->destroy_block_vars('_file'); |
| |
| $block_array = array(); |
| |
| |
| $attachment['extension'] = strtolower(trim($attachment['extension'])); |
| $filename = $phpbb_root_path . $config['upload_path'] . '/' . basename($attachment['physical_filename']); |
| $thumbnail_filename = $phpbb_root_path . $config['upload_path'] . '/thumb_' . basename($attachment['physical_filename']); |
| |
| $upload_icon = ''; |
| |
| if (isset($extensions[$attachment['extension']])) |
| { |
| if ($user->img('icon_topic_attach', '') && !$extensions[$attachment['extension']]['upload_icon']) |
| { |
| $upload_icon = $user->img('icon_topic_attach', ''); |
| } |
| else if ($extensions[$attachment['extension']]['upload_icon']) |
| { |
| $upload_icon = '<img src="' . $phpbb_root_path . $config['upload_icons_path'] . '/' . trim($extensions[$attachment['extension']]['upload_icon']) . '" alt="" />'; |
| } |
| } |
| |
| $filesize = $attachment['filesize']; |
| $size_lang = ($filesize >= 1048576) ? $user->lang['MIB'] : (($filesize >= 1024) ? $user->lang['KIB'] : $user->lang['BYTES']); |
| $filesize = get_formatted_filesize($filesize, false); |
| |
| $comment = bbcode_nl2br(censor_text($attachment['attach_comment'])); |
| |
| $block_array += array( |
| 'UPLOAD_ICON' => $upload_icon, |
| 'FILESIZE' => $filesize, |
| 'SIZE_LANG' => $size_lang, |
| 'DOWNLOAD_NAME' => basename($attachment['real_filename']), |
| 'COMMENT' => $comment, |
| ); |
| |
| $denied = false; |
| |
| if (!extension_allowed($forum_id, $attachment['extension'], $extensions)) |
| { |
| $denied = true; |
| |
| $block_array += array( |
| 'S_DENIED' => true, |
| 'DENIED_MESSAGE' => sprintf($user->lang['EXTENSION_DISABLED_AFTER_POSTING'], $attachment['extension']) |
| ); |
| } |
| |
| if (!$denied) |
| { |
| $l_downloaded_viewed = $download_link = ''; |
| $display_cat = $extensions[$attachment['extension']]['display_cat']; |
| |
| if ($display_cat == ATTACHMENT_CATEGORY_IMAGE) |
| { |
| if ($attachment['thumbnail']) |
| { |
| $display_cat = ATTACHMENT_CATEGORY_THUMB; |
| } |
| else |
| { |
| if ($config['img_display_inlined']) |
| { |
| if ($config['img_link_width'] || $config['img_link_height']) |
| { |
| $dimension = @getimagesize($filename); |
| |
| |
| if ($dimension === false || empty($dimension[0]) || empty($dimension[1])) |
| { |
| $display_cat = ATTACHMENT_CATEGORY_NONE; |
| } |
| else |
| { |
| $display_cat = ($dimension[0] <= $config['img_link_width'] && $dimension[1] <= $config['img_link_height']) ? ATTACHMENT_CATEGORY_IMAGE : ATTACHMENT_CATEGORY_NONE; |
| } |
| } |
| } |
| else |
| { |
| $display_cat = ATTACHMENT_CATEGORY_NONE; |
| } |
| } |
| } |
| |
| |
| if (($display_cat == ATTACHMENT_CATEGORY_IMAGE || $display_cat == ATTACHMENT_CATEGORY_THUMB) && !$user->optionget('viewimg')) |
| { |
| $display_cat = ATTACHMENT_CATEGORY_NONE; |
| } |
| |
| if ($display_cat == ATTACHMENT_CATEGORY_FLASH && !$user->optionget('viewflash')) |
| { |
| $display_cat = ATTACHMENT_CATEGORY_NONE; |
| } |
| |
| $download_link = append_sid("{$phpbb_root_path}download/file.$phpEx", 'id=' . $attachment['attach_id']); |
| |
| switch ($display_cat) |
| { |
| |
| case ATTACHMENT_CATEGORY_IMAGE: |
| $l_downloaded_viewed = 'VIEWED_COUNT'; |
| $inline_link = append_sid("{$phpbb_root_path}download/file.$phpEx", 'id=' . $attachment['attach_id']); |
| $download_link .= '&mode=view'; |
| |
| $block_array += array( |
| 'S_IMAGE' => true, |
| 'U_INLINE_LINK' => $inline_link, |
| ); |
| |
| $update_count[] = $attachment['attach_id']; |
| break; |
| |
| |
| case ATTACHMENT_CATEGORY_THUMB: |
| $l_downloaded_viewed = 'VIEWED_COUNT'; |
| $thumbnail_link = append_sid("{$phpbb_root_path}download/file.$phpEx", 'id=' . $attachment['attach_id'] . '&t=1'); |
| $download_link .= '&mode=view'; |
| |
| $block_array += array( |
| 'S_THUMBNAIL' => true, |
| 'THUMB_IMAGE' => $thumbnail_link, |
| ); |
| break; |
| |
| |
| case ATTACHMENT_CATEGORY_WM: |
| $l_downloaded_viewed = 'VIEWED_COUNT'; |
| |
| |
| |
| |
| |
| $block_array += array( |
| 'U_FORUM' => generate_board_url(), |
| 'ATTACH_ID' => $attachment['attach_id'], |
| 'S_WM_FILE' => true, |
| ); |
| |
| |
| $update_count[] = $attachment['attach_id']; |
| break; |
| |
| |
| case ATTACHMENT_CATEGORY_RM: |
| case ATTACHMENT_CATEGORY_QUICKTIME: |
| $l_downloaded_viewed = 'VIEWED_COUNT'; |
| |
| $block_array += array( |
| 'S_RM_FILE' => ($display_cat == ATTACHMENT_CATEGORY_RM) ? true : false, |
| 'S_QUICKTIME_FILE' => ($display_cat == ATTACHMENT_CATEGORY_QUICKTIME) ? true : false, |
| 'U_FORUM' => generate_board_url(), |
| 'ATTACH_ID' => $attachment['attach_id'], |
| ); |
| |
| |
| $update_count[] = $attachment['attach_id']; |
| break; |
| |
| |
| case ATTACHMENT_CATEGORY_FLASH: |
| list($width, $height) = @getimagesize($filename); |
| |
| $l_downloaded_viewed = 'VIEWED_COUNT'; |
| |
| $block_array += array( |
| 'S_FLASH_FILE' => true, |
| 'WIDTH' => $width, |
| 'HEIGHT' => $height, |
| ); |
| |
| |
| $update_count[] = $attachment['attach_id']; |
| break; |
| |
| default: |
| $l_downloaded_viewed = 'DOWNLOAD_COUNT'; |
| |
| $block_array += array( |
| 'S_FILE' => true, |
| ); |
| break; |
| } |
| |
| $l_download_count = (!isset($attachment['download_count']) || $attachment['download_count'] == 0) ? $user->lang[$l_downloaded_viewed . '_NONE'] : (($attachment['download_count'] == 1) ? sprintf($user->lang[$l_downloaded_viewed], $attachment['download_count']) : sprintf($user->lang[$l_downloaded_viewed . 'S'], $attachment['download_count'])); |
| |
| $block_array += array( |
| 'U_DOWNLOAD_LINK' => $download_link, |
| 'L_DOWNLOAD_COUNT' => $l_download_count |
| ); |
| } |
| |
| $template->assign_block_vars('_file', $block_array); |
| |
| $compiled_attachments[] = $template->assign_display('attachment_tpl'); |
| } |
| |
| $attachments = $compiled_attachments; |
| unset($compiled_attachments); |
| |
| $tpl_size = sizeof($attachments); |
| |
| $unset_tpl = array(); |
| |
| preg_match_all('#<!\-\- ia([0-9]+) \-\->(.*?)<!\-\- ia\1 \-\->#', $message, $matches, PREG_PATTERN_ORDER); |
| |
| $replace = array(); |
| foreach ($matches[0] as $num => $capture) |
| { |
| |
| $index = ($config['display_order']) ? ($tpl_size-($matches[1][$num] + 1)) : $matches[1][$num]; |
| |
| $replace['from'][] = $matches[0][$num]; |
| $replace['to'][] = (isset($attachments[$index])) ? $attachments[$index] : sprintf($user->lang['MISSING_INLINE_ATTACHMENT'], $matches[2][array_search($index, $matches[1])]); |
| |
| $unset_tpl[] = $index; |
| } |
| |
| if (isset($replace['from'])) |
| { |
| $message = str_replace($replace['from'], $replace['to'], $message); |
| } |
| |
| $unset_tpl = array_unique($unset_tpl); |
| |
| |
| foreach ($unset_tpl as $index) |
| { |
| unset($attachments[$index]); |
| } |
| } |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| function extension_allowed($forum_id, $extension, &$extensions) |
| { |
| if (empty($extensions)) |
| { |
| global $cache; |
| $extensions = $cache->obtain_attach_extensions($forum_id); |
| } |
| |
| return (!isset($extensions['_allowed_'][$extension])) ? false : true; |
| } |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| function truncate_string($string, $max_length = 60, $max_store_length = 255, $allow_reply = true, $append = '') |
| { |
| $chars = array(); |
| |
| $strip_reply = false; |
| $stripped = false; |
| if ($allow_reply && strpos($string, 'Re: ') === 0) |
| { |
| $strip_reply = true; |
| $string = substr($string, 4); |
| } |
| |
| $_chars = utf8_str_split(htmlspecialchars_decode($string)); |
| $chars = array_map('utf8_htmlspecialchars', $_chars); |
| |
| |
| if (sizeof($chars) > $max_length) |
| { |
| |
| $string = implode('', array_slice($chars, 0, $max_length - utf8_strlen($append))); |
| $stripped = true; |
| } |
| |
| |
| if (utf8_strlen($string) > $max_store_length) |
| { |
| |
| $_chars = utf8_str_split(htmlspecialchars_decode($string)); |
| $chars = array_map('utf8_htmlspecialchars', $_chars); |
| |
| do |
| { |
| array_pop($chars); |
| $string = implode('', $chars); |
| } |
| while (utf8_strlen($string) > $max_store_length || !sizeof($chars)); |
| } |
| |
| if ($strip_reply) |
| { |
| $string = 'Re: ' . $string; |
| } |
| |
| if ($append != '' && $stripped) |
| { |
| $string = $string . $append; |
| } |
| |
| return $string; |
| } |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| function get_username_string($mode, $user_id, $username, $username_colour = '', $guest_username = false, $custom_profile_url = false) |
| { |
| static $_profile_cache; |
| static $_base_profile_url; |
| |
| $cache_key = $user_id; |
| |
| |
| if ($user_id && $user_id != ANONYMOUS && isset($_profile_cache[$cache_key][$mode])) |
| { |
| |
| if ($mode == 'no_profile') |
| { |
| $tpl = (!$_profile_cache[$cache_key]['colour']) ? '{USERNAME}' : '<span style="color: {USERNAME_COLOUR};" class="username-coloured">{USERNAME}</span>'; |
| return str_replace(array('{USERNAME_COLOUR}', '{USERNAME}'), array($_profile_cache[$cache_key]['colour'], $_profile_cache[$cache_key]['username']), $tpl); |
| } |
| |
| return $_profile_cache[$cache_key][$mode]; |
| } |
| |
| global $phpbb_root_path, $phpEx, $user, $auth; |
| |
| $username_colour = ($username_colour) ? '#' . $username_colour : ''; |
| |
| if ($guest_username === false) |
| { |
| $username = ($username) ? $username : $user->lang['GUEST']; |
| } |
| else |
| { |
| $username = ($user_id && $user_id != ANONYMOUS) ? $username : ((!empty($guest_username)) ? $guest_username : $user->lang['GUEST']); |
| } |
| |
| |
| $_profile_cache[$cache_key]['colour'] = $username_colour; |
| $_profile_cache[$cache_key]['username'] = $username; |
| $_profile_cache[$cache_key]['no_profile'] = true; |
| |
| |
| |
| if ($user_id && $user_id != ANONYMOUS && ($user->data['user_id'] == ANONYMOUS || $auth->acl_get('u_viewprofile'))) |
| { |
| if (empty($_base_profile_url)) |
| { |
| $_base_profile_url = append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=viewprofile&u={USER_ID}'); |
| } |
| |
| $profile_url = ($custom_profile_url !== false) ? $custom_profile_url . '&u=' . (int) $user_id : str_replace('={USER_ID}', '=' . (int) $user_id, $_base_profile_url); |
| $tpl = (!$username_colour) ? '<a href="{PROFILE_URL}">{USERNAME}</a>' : '<a href="{PROFILE_URL}" style="color: {USERNAME_COLOUR};" class="username-coloured">{USERNAME}</a>'; |
| $_profile_cache[$cache_key]['full'] = str_replace(array('{PROFILE_URL}', '{USERNAME_COLOUR}', '{USERNAME}'), array($profile_url, $username_colour, $username), $tpl); |
| } |
| else |
| { |
| $tpl = (!$username_colour) ? '{USERNAME}' : '<span style="color: {USERNAME_COLOUR};" class="username-coloured">{USERNAME}</span>'; |
| $_profile_cache[$cache_key]['full'] = str_replace(array('{USERNAME_COLOUR}', '{USERNAME}'), array($username_colour, $username), $tpl); |
| $profile_url = ''; |
| } |
| |
| |
| $_profile_cache[$cache_key]['profile'] = $profile_url; |
| |
| |
| if ($mode == 'no_profile') |
| { |
| $tpl = (!$_profile_cache[$cache_key]['colour']) ? '{USERNAME}' : '<span style="color: {USERNAME_COLOUR};" class="username-coloured">{USERNAME}</span>'; |
| return str_replace(array('{USERNAME_COLOUR}', '{USERNAME}'), array($_profile_cache[$cache_key]['colour'], $_profile_cache[$cache_key]['username']), $tpl); |
| } |
| |
| return $_profile_cache[$cache_key][$mode]; |
| } |
| |
| |
| |
| |
| class bitfield |
| { |
| var $data; |
| |
| function bitfield($bitfield = '') |
| { |
| $this->data = base64_decode($bitfield); |
| } |
| |
| |
| |
| function get($n) |
| { |
| |
| $byte = $n >> 3; |
| |
| if (strlen($this->data) >= $byte + 1) |
| { |
| $c = $this->data[$byte]; |
| |
| |
| $bit = 7 - ($n & 7); |
| return (bool) (ord($c) & (1 << $bit)); |
| } |
| else |
| { |
| return false; |
| } |
| } |
| |
| function set($n) |
| { |
| $byte = $n >> 3; |
| $bit = 7 - ($n & 7); |
| |
| if (strlen($this->data) >= $byte + 1) |
| { |
| $this->data[$byte] = $this->data[$byte] | chr(1 << $bit); |
| } |
| else |
| { |
| $this->data .= str_repeat("\0", $byte - strlen($this->data)); |
| $this->data .= chr(1 << $bit); |
| } |
| } |
| |
| function clear($n) |
| { |
| $byte = $n >> 3; |
| |
| if (strlen($this->data) >= $byte + 1) |
| { |
| $bit = 7 - ($n & 7); |
| $this->data[$byte] = $this->data[$byte] &~ chr(1 << $bit); |
| } |
| } |
| |
| function get_blob() |
| { |
| return $this->data; |
| } |
| |
| function get_base64() |
| { |
| return base64_encode($this->data); |
| } |
| |
| function get_bin() |
| { |
| $bin = ''; |
| $len = strlen($this->data); |
| |
| for ($i = 0; $i < $len; ++$i) |
| { |
| $bin .= str_pad(decbin(ord($this->data[$i])), 8, '0', STR_PAD_LEFT); |
| } |
| |
| return $bin; |
| } |
| |
| function get_all_set() |
| { |
| return array_keys(array_filter(str_split($this->get_bin()))); |
| } |
| |
| function merge($bitfield) |
| { |
| $this->data = $this->data | $bitfield->get_blob(); |
| } |
| } |
| |
| ?> |