948 | $is_auth_ary = auth(AUTH_READ, AUTH_LIST_ALL, $userdata); | 955 | $is_auth_ary = auth(AUTH_READ, AUTH_LIST_ALL, $userdata); |
949 | $is_download_auth_ary = auth(AUTH_DOWNLOAD, AUTH_LIST_ALL, $userdata); | 956 | $is_download_auth_ary = auth(AUTH_DOWNLOAD, AUTH_LIST_ALL, $userdata); |
950 | $attachment_details = get_attachment_details($params['id']); | 957 | $attachment_details = get_attachment_details($params['id']); |
| | 3793 | * Undo HTML special chars |
| | 3794 | */ |
| | 3795 | function undo_htmlspecialchars($input, $full_undo = false) |
| | 3796 | { |
| | 3797 | if($full_undo) |
| | 3798 | { |
| | 3799 | $input = str_replace(' ', '', $input); |
| | 3800 | } |
| | 3801 | $input = preg_replace("/>/i", ">", $input); |
| | 3802 | $input = preg_replace("/</i", "<", $input); |
| | 3803 | $input = preg_replace("/"/i", "\"", $input); |
| | 3804 | $input = preg_replace("/&/i", "&", $input); |
| | 3805 | |
| | 3806 | if($full_undo) |
| | 3807 | { |
| | 3808 | if(preg_match_all('/&\#([0-9]+);/', $input, $matches) && sizeof($matches)) |
| | 3809 | { |
| | 3810 | $list = array(); |
| | 3811 | for($i = 0; $i < sizeof($matches[1]); $i++) |
| | 3812 | { |
| | 3813 | $list[$matches[1][$i]] = true; |
| | 3814 | } |
| | 3815 | $search = array(); |
| | 3816 | $replace = array(); |
| | 3817 | foreach($list as $var => $value) |
| | 3818 | { |
| | 3819 | $search[] = '&#' . $var . ';'; |
| | 3820 | $replace[] = chr($var); |
| | 3821 | } |
| | 3822 | $input = str_replace($search, $replace, $input); |
| | 3823 | } |
| | 3824 | } |
| | 3825 | |
| | 3826 | return $input; |
| | 3827 | } |
| | 3828 | |
| | 3829 | /* |
4003 | } | 4051 | // Autolinks - BEGIN |
4004 | | 4052 | // |
4005 | $bbcode = new bbcode(); | 4053 | // Obtain list of autolink words and build preg style replacement arrays for use by the calling script, note that the vars are passed as references this just makes it easier to return both sets of arrays |
4006 | | 4054 | // |
4007 | if (defined('SMILIES_TABLE')) | 4055 | function obtain_autolinks_list($forum_id) |
4008 | { | | |
4009 | $bbcode->allowed_smilies = array(); | | |
4010 | $bbcode->allowed_smilies = $cache->obtain_smileys(false); | | |
4011 | } | | |
4012 | | | |
4013 | // Need to initialize the random numbers only ONCE | | |
4014 | mt_srand((double) microtime() * 1000000); | | |
4015 | | | |
4016 | /** | | |
4017 | * For display of custom parsed text on user-facing pages | | |
4018 | * Expects $text to be the value directly from the database (stored value) | | |
4019 | */ | | |
4020 | function generate_text_for_display($text, $only_smileys = false, $censor = true, $acro_autolinks = false, $forum_id = '999999') | | |
4021 | { | | |
4022 | global $bbcode, $config, $userdata; | | |
4023 | | | |
4024 | if (empty($text)) | | |
4044 | $userdata['user_allowhtml'] = $config['allow_html'] ? true : false; | 4066 | // Munge word boundaries to stop autolinks from linking to |
4045 | $userdata['user_allowbbcode'] = $config['allow_bbcode'] ? true : false; | 4067 | // themselves or other autolinks in step 2 in the function below. |
4046 | $userdata['user_allowsmile'] = $config['allow_smilies'] ? true : false; | 4068 | $row['link_url'] = preg_replace('/(\b)/', '\\1ALSPACEHOLDER', $row['link_url']); |
4047 | } | 4069 | $row['link_comment'] = preg_replace('/(\b)/', '\\1ALSPACEHOLDER', $row['link_comment']); |
4048 | $bbcode->allow_html = ($userdata['user_allowhtml'] && $config['allow_html']) ? true : false; | | |
4049 | $bbcode->allow_bbcode = ($userdata['user_allowbbcode'] && $config['allow_bbcode']) ? true : false; | | |
4050 | $bbcode->allow_smilies = ($userdata['user_allowsmile'] && $config['allow_smilies']) ? true : false; | | |
4051 | } | | |
4053 | if ($only_smileys) | 4071 | if($row['link_style']) |
4054 | { | | |
4055 | $text = $bbcode->parse_only_smilies($text); | | |
4056 | } | | |
4057 | else | | |
4058 | { | | |
4059 | $text = $bbcode->parse($text); | | |
4060 | if (defined('IS_ICYPHOENIX') && $acro_autolinks) | | |
4061 | { | | |
4062 | $text = $bbcode->acronym_pass($text); | | |
4063 | $text = autolink_text($text, $forum_id); | | |
4064 | } | | |
4065 | } | | |
4066 | | | |
4067 | return $text; | | |
4068 | } | | |
4069 | | | |
4070 | /* | | |
4071 | * Generate bbcode uid | | |
4072 | */ | | |
4073 | function make_bbcode_uid() | | |
4074 | { | | |
4075 | // Unique ID for this message.. | | |
4076 | $uid = unique_id(); | | |
4077 | $uid = substr($uid, 0, BBCODE_UID_LEN); | | |
4078 | return $uid; | | |
4079 | } | | |
4080 | | | |
4081 | /* | | |
4082 | * Generate a single row of smileys | | |
4083 | * Moved here from functions_post to optimize viewtopic and remove the full include of functions_post | | |
4084 | */ | | |
4085 | if (defined('SMILIES_TABLE')) | | |
4086 | { | | |
4087 | function generate_smilies_row() | | |
4088 | { | | |
4089 | global $db, $cache, $config, $template; | | |
4090 | if (defined('IN_PA_POSTING')) | | |
4091 | { | | |
4092 | global $pafiledb_template; | | |
4093 | } | | |
4094 | | | |
4095 | $max_smilies = (!empty($config['smilie_single_row']) ? intval($config['smilie_single_row']) : 20); | | |
4096 | | | |
4097 | $sql = "SELECT emoticon, code, smile_url FROM " . SMILIES_TABLE . " GROUP BY smile_url ORDER BY smilies_order LIMIT " . $max_smilies; | | |
4098 | $result = $db->sql_query($sql, 0, 'smileys_'); | | |
4099 | | | |
4100 | $host = extract_current_hostname(); | | |
4101 | | | |
4102 | $orig = array(); | | |
4103 | $repl = array(); | | |
4104 | while ($row = $db->sql_fetchrow($result)) | | |
4105 | { | | |
4106 | $parsing_template = array( | | |
4107 | 'CODE' => $row['code'], | | |
4108 | 'URL' => 'http://' . $host . $config['script_path'] . $config['smilies_path'] . '/' . $row['smile_url'], | | |
4109 | 'DESC' => htmlspecialchars($row['emoticon']) | | |
4110 | ); | | |
4111 | if (defined('IN_PA_POSTING')) | | |
4119 | } | 4080 | $autolinks['match'][] = '/(?<![\/\w@\.:-])(?!\.\w)(' . phpbb_preg_quote($row['link_keyword'], '/'). ')(?![\/\w@:-])(?!\.\w)/i'; |
4120 | $db->sql_freeresult($result); | 4081 | if($row['link_int']) |
4121 | } | | |
4122 | } | | |
4123 | | | |
4124 | /* | | |
4125 | * Undo HTML special chars | | |
4126 | */ | | |
4127 | function undo_htmlspecialchars($input, $full_undo = false) | | |
4128 | { | | |
4129 | if($full_undo) | | |
4130 | { | | |
4131 | $input = str_replace(' ', '', $input); | | |
4132 | } | | |
4133 | $input = preg_replace("/>/i", ">", $input); | | |
4134 | $input = preg_replace("/</i", "<", $input); | | |
4135 | $input = preg_replace("/"/i", "\"", $input); | | |
4136 | $input = preg_replace("/&/i", "&", $input); | | |
4137 | | | |
4138 | if($full_undo) | | |
4139 | { | | |
4140 | if(preg_match_all('/&\#([0-9]+);/', $input, $matches) && sizeof($matches)) | | |
4141 | { | | |
4142 | $list = array(); | | |
4143 | for($i = 0; $i < sizeof($matches[1]); $i++) | | |
4158 | return $input; | 4095 | /** |
4159 | } | 4096 | * Autolinks |
4160 | | 4097 | * Original Author - Jim McDonald - Edited by Mighty Gorgon |
4161 | /* | 4098 | */ |
4162 | * Make a link clickable | 4099 | function autolink_text($text, $forum_id = '') |
4163 | */ | | |
4164 | function make_clickable($text) | | |
4165 | { | | |
4166 | $text = preg_replace('#(script|about|applet|activex|chrome):#is', "\\1:", $text); | | |
4167 | $text = preg_replace('#(script|about|applet|activex|chrome):#is', "\\1:", $text); | | |
4168 | | | |
4169 | // pad it with a space so we can match things at the start of the 1st line. | | |
4170 | $ret = ' ' . $text; | | |
4171 | | | |
4172 | // matches an "xxxx://yyyy" URL at the start of a line, or after a space. | | |
4173 | // xxxx can only be alpha characters. | | |
4174 | // yyyy is anything up to the first space, newline, comma, double quote or < | | |
4175 | $ret = preg_replace("#(^|[\n ])([\w]+?://[\w\#$%&~/.\-;:=,?@\[\]+]*)#is", "\\1<a href=\"\\2\" target=\"_blank\">\\2</a>", $ret); | | |
4176 | | | |
4177 | // matches a "www|ftp.xxxx.yyyy[/zzzz]" kinda lazy URL thing | | |
4178 | // Must contain at least 2 dots. xxxx contains either alphanum, or "-" | | |
4179 | // zzzz is optional.. will contain everything up to the first space, newline, | | |
4180 | // comma, double quote or <. | | |
4181 | $ret = preg_replace("#(^|[\n ])((www|ftp)\.[\w\#$%&~/.\-;:=,?@\[\]+]*)#is", "\\1<a href=\"http://\\2\" target=\"_blank\">\\2</a>", $ret); | | |
4182 | | | |
4183 | | | |
4184 | // matches an email@domain type address at the start of a line, or after a space. | | |
4185 | // Note: Only the followed chars are valid; alphanums, "-", "_" and or ".". | | |
4186 | $ret = preg_replace("#(^|[\n ])([a-z0-9&\-_.]+?)@([\w\-]+\.([\w\-\.]+\.)*[\w]+)#i", "\\1<a href=\"mailto:\\2@\\3\">\\2@\\3</a>", $ret); | | |
4187 | | | |
4188 | // Remove our padding.. | | |
4189 | $ret = substr($ret, 1); | | |
4190 | | | |
4191 | return($ret); | | |
4192 | } | | |
4193 | | | |
4194 | // Autolinks - BEGIN | | |
4195 | // | | |
4196 | // Obtain list of autolink words and build preg style replacement arrays for use by the calling script, note that the vars are passed as references this just makes it easier to return both sets of arrays | | |
4197 | // | | |
4198 | function obtain_autolinks_list($forum_id) | | |
4199 | { | | |
4200 | global $db; | | |
4201 | | | |
4202 | $where = ($forum_id) ? ' WHERE link_forum = 0 OR link_forum IN (' . $forum_id . ')' : ' WHERE link_forum = -1'; | | |
4203 | $sql = "SELECT * FROM " . AUTOLINKS . $where; | | |
4204 | $result = $db->sql_query($sql, 0, 'autolinks_', TOPICS_CACHE_FOLDER); | | |
4205 | | | |
4206 | $autolinks = array(); | | |
4207 | while($row = $db->sql_fetchrow($result)) | | |
4226 | $autolinks['replace'][] = '<a href="' . append_sid(htmlspecialchars($row['link_url'])) . '" target="_self"' . $style . 'title="' . htmlspecialchars($row['link_comment']) . '">' . htmlspecialchars($row['link_title']) . '</a>'; | 4115 | global $config; |
4227 | } | 4116 | // Step 1 - move all tags out of the text and replace them with placeholders |
4228 | else | 4117 | preg_match_all('/(<a\s+.*?\/a>|<[^>]+>)/i', $text, $matches); |
4229 | { | 4118 | $matchnum = sizeof($matches[1]); |
4230 | $autolinks['replace'][] = '<a href="' . htmlspecialchars($row['link_url']) . '" target="_blank"' . $style . 'title="' . htmlspecialchars($row['link_comment']) . '">' . htmlspecialchars($row['link_title']) . '</a>'; | 4119 | for($i = 0; $i < $matchnum; $i++) |
4231 | } | 4120 | { |
4232 | } | 4121 | $text = preg_replace('/' . preg_quote($matches[1][$i], '/') . '/', "ALPLACEHOLDER{$i}PH", $text, 1); |
4233 | $db->sql_freeresult($result); | 4122 | } |
4258 | global $config; | 4164 | $text = preg_replace('#(script|about|applet|activex|chrome):#is', "\\1:", $text); |
4259 | // Step 1 - move all tags out of the text and replace them with placeholders | 4165 | $text = preg_replace('#(script|about|applet|activex|chrome):#is', "\\1:", $text); |
4260 | preg_match_all('/(<a\s+.*?\/a>|<[^>]+>)/i', $text, $matches); | | |
4261 | $matchnum = sizeof($matches[1]); | | |
4262 | for($i = 0; $i < $matchnum; $i++) | | |
4263 | { | | |
4264 | $text = preg_replace('/' . preg_quote($matches[1][$i], '/') . '/', "ALPLACEHOLDER{$i}PH", $text, 1); | | |
4265 | } | | |
4277 | // Step 3 - replace the spaces we munged in step 1 | 4170 | // matches an "xxxx://yyyy" URL at the start of a line, or after a space. |
4278 | $text = preg_replace('/ALSPACEHOLDER/', '', $text); | 4171 | // xxxx can only be alpha characters. |
| | 4172 | // yyyy is anything up to the first space, newline, comma, double quote or < |
| | 4173 | $ret = preg_replace("#(^|[\n ])([\w]+?://[\w\#$%&~/.\-;:=,?@\[\]+]*)#is", "\\1<a href=\"\\2\" target=\"_blank\">\\2</a>", $ret); |
4280 | // Step 4 - replace the HTML tags that we removed in step 1 | 4175 | // matches a "www|ftp.xxxx.yyyy[/zzzz]" kinda lazy URL thing |
4281 | for($i = 0; $i < $matchnum; $i++) | 4176 | // Must contain at least 2 dots. xxxx contains either alphanum, or "-" |
4282 | { | 4177 | // zzzz is optional.. will contain everything up to the first space, newline, |
4283 | $text = preg_replace("/ALPLACEHOLDER{$i}PH/", $matches[1][$i], $text, 1); | 4178 | // comma, double quote or <. |
4284 | } | 4179 | $ret = preg_replace("#(^|[\n ])((www|ftp)\.[\w\#$%&~/.\-;:=,?@\[\]+]*)#is", "\\1<a href=\"http://\\2\" target=\"_blank\">\\2</a>", $ret); |
4285 | } | | |
4291 | /* | 4182 | // matches an email@domain type address at the start of a line, or after a space. |
4292 | * Get attachment details | 4183 | // Note: Only the followed chars are valid; alphanums, "-", "_" and or ".". |
4293 | */ | 4184 | $ret = preg_replace("#(^|[\n ])([a-z0-9&\-_.]+?)@([\w\-]+\.([\w\-\.]+\.)*[\w]+)#i", "\\1<a href=\"mailto:\\2@\\3\">\\2@\\3</a>", $ret); |
4294 | function get_attachment_details($attach_id) | | |
4295 | { | | |
4296 | global $db; | | |
4297 | $sql = "SELECT a.*, d.*, s.*, p.forum_id | | |
4298 | FROM " . ATTACHMENTS_TABLE . " a, " . ATTACHMENTS_DESC_TABLE . " d, " . ATTACHMENTS_STATS_TABLE . " s, " . POSTS_TABLE . " p | | |
4299 | WHERE a.attach_id = " . $attach_id . " | | |
4300 | AND d.attach_id = a.attach_id | | |
4301 | AND s.attach_id = a.attach_id | | |
4302 | AND a.post_id > 0 | | |
4303 | AND p.post_id = a.post_id | | |
4304 | LIMIT 1"; | | |
4305 | $db->sql_return_on_error(true); | | |
4306 | $result = $db->sql_query($sql); | | |
4307 | $db->sql_return_on_error(false); | | |
4320 | /* | 4189 | return($ret); |
4321 | * Get download details | | |
4322 | */ | | |
4323 | function get_download_details($file_id) | | |
4324 | { | | |
4325 | global $db, $userdata; | | |
4326 | $sql = "SELECT f.*, c.* | | |
4327 | FROM " . PA_FILES_TABLE . " f, " . PA_CATEGORY_TABLE . " c | | |
4328 | WHERE file_id = " . $file_id . " | | |
4329 | AND file_approved = '1' | | |
4330 | AND c.cat_id = f.file_catid | | |
4331 | LIMIT 1"; | | |
4332 | $db->sql_return_on_error(true); | | |
4333 | $result = $db->sql_query($sql); | | |
4334 | $db->sql_return_on_error(false); | | |
4335 | | | |
4336 | if ($row = $db->sql_fetchrow($result)) | | |
4337 | { | | |
4338 | $db->sql_freeresult($result); | | |
4339 | $allowed = false; | | |
4340 | if (($row['auth_view_file'] == AUTH_ALL) || ($userdata['user_level'] == ADMIN)) | | |
4341 | { | | |
4342 | $allowed = true; | | |
4343 | } | | |
4344 | elseif (($row['auth_view_file'] == AUTH_REG) && $userdata['session_logged_in']) | | |
4345 | { | | |
4346 | $allowed = true; | | |
4347 | } | | |
4348 | return ($allowed ? $row : false); | | |
4356 | /* | | |
4357 | * This function turns HTML into text... strips tags, comments spanning multiple lines including CDATA, and anything else that gets in it's way. | | |
4358 | */ | | |
4359 | function html2txt($document) | | |
4360 | { | | |
4361 | $search = array( | | |
4362 | '@<script[^>]*?>.*?</script>@si', // Strip out javascript | | |
4363 | '@<[\/\!]*?[^<>]*?>@si', // Strip out HTML tags | | |
4364 | '@<style[^>]*?>.*?</style>@siU', // Strip style tags properly | | |
4365 | '@<![\s\S]*?--[ \t\n\r]*>@' // Strip multi-line comments including CDATA | | |
4366 | ); | | |
4367 | $text = preg_replace($search, '', $document); | | |
4368 | return $text; | | |
4402 | /* | | |
4403 | * Convert BR to newline | | |
4404 | */ | | |
4405 | function br2nl($text, $remove_linebreaks = false) | | |
4406 | { | | |
4407 | if ($remove_linebreaks) | | |
4408 | { | | |
4409 | $text = preg_replace("/(\r\n|\n|\r)/", "", $text); | | |
4410 | } | | |
4411 | return preg_replace("=<br */?>=i", "\n", $text); | | |
4412 | } | | |
4413 | | | |
4414 | /* | | |
4415 | * Convert newline to BR | | |
4416 | */ | | |
4417 | function nl2br_mg($text) | | |
4418 | { | | |
4419 | /* | | |
4420 | $text = preg_replace("/\r\n/", "\n", $text); | | |
4421 | $text = str_replace('<br />', "\n", $text); | | |
4422 | */ | | |
4423 | $text = preg_replace(array("/<br \/>\r\n/", "/<br>\r\n/", "/(\r\n|\n|\r)/"), array("\r\n", "\r\n", "<br />\r\n"), $text); | | |
4424 | return $text; | | |
4425 | } | | |
4426 | | | |