indvdum@0: $user->lang['ASCENDING'], 'd' => $user->lang['DESCENDING']); indvdum@0: indvdum@0: $sorts = array( indvdum@0: 'st' => array( indvdum@0: 'key' => 'sort_days', indvdum@0: 'default' => $def_st, indvdum@0: 'options' => $limit_days, indvdum@0: 'output' => &$s_limit_days, indvdum@0: ), indvdum@0: indvdum@0: 'sk' => array( indvdum@0: 'key' => 'sort_key', indvdum@0: 'default' => $def_sk, indvdum@0: 'options' => $sort_by_text, indvdum@0: 'output' => &$s_sort_key, indvdum@0: ), indvdum@0: indvdum@0: 'sd' => array( indvdum@0: 'key' => 'sort_dir', indvdum@0: 'default' => $def_sd, indvdum@0: 'options' => $sort_dir_text, indvdum@0: 'output' => &$s_sort_dir, indvdum@0: ), indvdum@0: ); indvdum@0: $u_sort_param = ''; indvdum@0: indvdum@0: foreach ($sorts as $name => $sort_ary) indvdum@0: { indvdum@0: $key = $sort_ary['key']; indvdum@0: $selected = $$sort_ary['key']; indvdum@0: indvdum@0: // Check if the key is selectable. If not, we reset to the default or first key found. indvdum@0: // This ensures the values are always valid. We also set $sort_dir/sort_key/etc. to the indvdum@0: // correct value, else the protection is void. ;) indvdum@0: if (!isset($sort_ary['options'][$selected])) indvdum@0: { indvdum@0: if ($sort_ary['default'] !== false) indvdum@0: { indvdum@0: $selected = $$key = $sort_ary['default']; indvdum@0: } indvdum@0: else indvdum@0: { indvdum@0: @reset($sort_ary['options']); indvdum@0: $selected = $$key = key($sort_ary['options']); indvdum@0: } indvdum@0: } indvdum@0: indvdum@0: $sort_ary['output'] = ''; indvdum@0: indvdum@0: $u_sort_param .= ($selected !== $sort_ary['default']) ? ((strlen($u_sort_param)) ? '&' : '') . "{$name}={$selected}" : ''; indvdum@0: } indvdum@0: indvdum@0: return; indvdum@0: } indvdum@0: indvdum@0: /** indvdum@0: * Generate Jumpbox indvdum@0: */ indvdum@0: function make_jumpbox($action, $forum_id = false, $select_all = false, $acl_list = false, $force_display = false) indvdum@0: { indvdum@0: global $config, $auth, $template, $user, $db; indvdum@0: indvdum@0: // We only return if the jumpbox is not forced to be displayed (in case it is needed for functionality) indvdum@0: if (!$config['load_jumpbox'] && $force_display === false) indvdum@0: { indvdum@0: return; indvdum@0: } indvdum@0: indvdum@0: $sql = 'SELECT forum_id, forum_name, parent_id, forum_type, left_id, right_id indvdum@0: FROM ' . FORUMS_TABLE . ' indvdum@0: ORDER BY left_id ASC'; indvdum@0: $result = $db->sql_query($sql, 600); indvdum@0: indvdum@0: $right = $padding = 0; indvdum@0: $padding_store = array('0' => 0); indvdum@0: $display_jumpbox = false; indvdum@0: $iteration = 0; indvdum@0: indvdum@0: // Sometimes it could happen that forums will be displayed here not be displayed within the index page indvdum@0: // This is the result of forums not displayed at index, having list permissions and a parent of a forum with no permissions. indvdum@0: // If this happens, the padding could be "broken" indvdum@0: indvdum@0: while ($row = $db->sql_fetchrow($result)) indvdum@0: { indvdum@0: if ($row['left_id'] < $right) indvdum@0: { indvdum@0: $padding++; indvdum@0: $padding_store[$row['parent_id']] = $padding; indvdum@0: } indvdum@0: else if ($row['left_id'] > $right + 1) indvdum@0: { indvdum@0: // Ok, if the $padding_store for this parent is empty there is something wrong. For now we will skip over it. indvdum@0: // @todo digging deep to find out "how" this can happen. indvdum@0: $padding = (isset($padding_store[$row['parent_id']])) ? $padding_store[$row['parent_id']] : $padding; indvdum@0: } indvdum@0: indvdum@0: $right = $row['right_id']; indvdum@0: indvdum@0: if ($row['forum_type'] == FORUM_CAT && ($row['left_id'] + 1 == $row['right_id'])) indvdum@0: { indvdum@0: // Non-postable forum with no subforums, don't display indvdum@0: continue; indvdum@0: } indvdum@0: indvdum@0: if (!$auth->acl_get('f_list', $row['forum_id'])) indvdum@0: { indvdum@0: // if the user does not have permissions to list this forum skip indvdum@0: continue; indvdum@0: } indvdum@0: indvdum@0: if ($acl_list && !$auth->acl_gets($acl_list, $row['forum_id'])) indvdum@0: { indvdum@0: continue; indvdum@0: } indvdum@0: indvdum@0: if (!$display_jumpbox) indvdum@0: { indvdum@0: $template->assign_block_vars('jumpbox_forums', array( indvdum@0: 'FORUM_ID' => ($select_all) ? 0 : -1, indvdum@0: 'FORUM_NAME' => ($select_all) ? $user->lang['ALL_FORUMS'] : $user->lang['SELECT_FORUM'], indvdum@0: 'S_FORUM_COUNT' => $iteration) indvdum@0: ); indvdum@0: indvdum@0: $iteration++; indvdum@0: $display_jumpbox = true; indvdum@0: } indvdum@0: indvdum@0: $template->assign_block_vars('jumpbox_forums', array( indvdum@0: 'FORUM_ID' => $row['forum_id'], indvdum@0: 'FORUM_NAME' => $row['forum_name'], indvdum@0: 'SELECTED' => ($row['forum_id'] == $forum_id) ? ' selected="selected"' : '', indvdum@0: 'S_FORUM_COUNT' => $iteration, indvdum@0: 'S_IS_CAT' => ($row['forum_type'] == FORUM_CAT) ? true : false, indvdum@0: 'S_IS_LINK' => ($row['forum_type'] == FORUM_LINK) ? true : false, indvdum@0: 'S_IS_POST' => ($row['forum_type'] == FORUM_POST) ? true : false) indvdum@0: ); indvdum@0: indvdum@0: for ($i = 0; $i < $padding; $i++) indvdum@0: { indvdum@0: $template->assign_block_vars('jumpbox_forums.level', array()); indvdum@0: } indvdum@0: $iteration++; indvdum@0: } indvdum@0: $db->sql_freeresult($result); indvdum@0: unset($padding_store); indvdum@0: indvdum@0: $template->assign_vars(array( indvdum@0: 'S_DISPLAY_JUMPBOX' => $display_jumpbox, indvdum@0: 'S_JUMPBOX_ACTION' => $action) indvdum@0: ); indvdum@0: indvdum@0: return; indvdum@0: } indvdum@0: indvdum@0: /** indvdum@0: * Bump Topic Check - used by posting and viewtopic indvdum@0: */ indvdum@0: function bump_topic_allowed($forum_id, $topic_bumped, $last_post_time, $topic_poster, $last_topic_poster) indvdum@0: { indvdum@0: global $config, $auth, $user; indvdum@0: indvdum@0: // Check permission and make sure the last post was not already bumped indvdum@0: if (!$auth->acl_get('f_bump', $forum_id) || $topic_bumped) indvdum@0: { indvdum@0: return false; indvdum@0: } indvdum@0: indvdum@0: // Check bump time range, is the user really allowed to bump the topic at this time? indvdum@0: $bump_time = ($config['bump_type'] == 'm') ? $config['bump_interval'] * 60 : (($config['bump_type'] == 'h') ? $config['bump_interval'] * 3600 : $config['bump_interval'] * 86400); indvdum@0: indvdum@0: // Check bump time indvdum@0: if ($last_post_time + $bump_time > time()) indvdum@0: { indvdum@0: return false; indvdum@0: } indvdum@0: indvdum@0: // Check bumper, only topic poster and last poster are allowed to bump indvdum@0: if ($topic_poster != $user->data['user_id'] && $last_topic_poster != $user->data['user_id']) indvdum@0: { indvdum@0: return false; indvdum@0: } indvdum@0: indvdum@0: // A bump time of 0 will completely disable the bump feature... not intended but might be useful. indvdum@0: return $bump_time; indvdum@0: } indvdum@0: indvdum@0: /** indvdum@0: * Generates a text with approx. the specified length which contains the specified words and their context indvdum@0: * indvdum@0: * @param string $text The full text from which context shall be extracted indvdum@0: * @param string $words An array of words which should be contained in the result, has to be a valid part of a PCRE pattern (escape with preg_quote!) indvdum@0: * @param int $length The desired length of the resulting text, however the result might be shorter or longer than this value indvdum@0: * indvdum@0: * @return string Context of the specified words separated by "..." indvdum@0: */ indvdum@0: function get_context($text, $words, $length = 400) indvdum@0: { indvdum@0: // first replace all whitespaces with single spaces indvdum@0: $text = preg_replace('/ +/', ' ', strtr($text, "\t\n\r\x0C ", ' ')); indvdum@0: indvdum@0: // we need to turn the entities back into their original form, to not cut the message in between them indvdum@0: $entities = array('<', '>', '[', ']', '.', ':', ':'); indvdum@0: $characters = array('<', '>', '[', ']', '.', ':', ':'); indvdum@0: $text = str_replace($entities, $characters, $text); indvdum@0: indvdum@0: $word_indizes = array(); indvdum@0: if (sizeof($words)) indvdum@0: { indvdum@0: $match = ''; indvdum@0: // find the starting indizes of all words indvdum@0: foreach ($words as $word) indvdum@0: { indvdum@0: if ($word) indvdum@0: { indvdum@0: if (preg_match('#(?:[^\w]|^)(' . $word . ')(?:[^\w]|$)#i', $text, $match)) indvdum@0: { indvdum@0: if (empty($match[1])) indvdum@0: { indvdum@0: continue; indvdum@0: } indvdum@0: indvdum@0: $pos = utf8_strpos($text, $match[1]); indvdum@0: if ($pos !== false) indvdum@0: { indvdum@0: $word_indizes[] = $pos; indvdum@0: } indvdum@0: } indvdum@0: } indvdum@0: } indvdum@0: unset($match); indvdum@0: indvdum@0: if (sizeof($word_indizes)) indvdum@0: { indvdum@0: $word_indizes = array_unique($word_indizes); indvdum@0: sort($word_indizes); indvdum@0: indvdum@0: $wordnum = sizeof($word_indizes); indvdum@0: // number of characters on the right and left side of each word indvdum@0: $sequence_length = (int) ($length / (2 * $wordnum)) - 2; indvdum@0: $final_text = ''; indvdum@0: $word = $j = 0; indvdum@0: $final_text_index = -1; indvdum@0: indvdum@0: // cycle through every character in the original text indvdum@0: for ($i = $word_indizes[$word], $n = utf8_strlen($text); $i < $n; $i++) indvdum@0: { indvdum@0: // if the current position is the start of one of the words then append $sequence_length characters to the final text indvdum@0: if (isset($word_indizes[$word]) && ($i == $word_indizes[$word])) indvdum@0: { indvdum@0: if ($final_text_index < $i - $sequence_length - 1) indvdum@0: { indvdum@0: $final_text .= '... ' . preg_replace('#^([^ ]*)#', '', utf8_substr($text, $i - $sequence_length, $sequence_length)); indvdum@0: } indvdum@0: else indvdum@0: { indvdum@0: // if the final text is already nearer to the current word than $sequence_length we only append the text indvdum@0: // from its current index on and distribute the unused length to all other sequenes indvdum@0: $sequence_length += (int) (($final_text_index - $i + $sequence_length + 1) / (2 * $wordnum)); indvdum@0: $final_text .= utf8_substr($text, $final_text_index + 1, $i - $final_text_index - 1); indvdum@0: } indvdum@0: $final_text_index = $i - 1; indvdum@0: indvdum@0: // add the following characters to the final text (see below) indvdum@0: $word++; indvdum@0: $j = 1; indvdum@0: } indvdum@0: indvdum@0: if ($j > 0) indvdum@0: { indvdum@0: // add the character to the final text and increment the sequence counter indvdum@0: $final_text .= utf8_substr($text, $i, 1); indvdum@0: $final_text_index++; indvdum@0: $j++; indvdum@0: indvdum@0: // if this is a whitespace then check whether we are done with this sequence indvdum@0: if (utf8_substr($text, $i, 1) == ' ') indvdum@0: { indvdum@0: // only check whether we have to exit the context generation completely if we haven't already reached the end anyway indvdum@0: if ($i + 4 < $n) indvdum@0: { indvdum@0: if (($j > $sequence_length && $word >= $wordnum) || utf8_strlen($final_text) > $length) indvdum@0: { indvdum@0: $final_text .= ' ...'; indvdum@0: break; indvdum@0: } indvdum@0: } indvdum@0: else indvdum@0: { indvdum@0: // make sure the text really reaches the end indvdum@0: $j -= 4; indvdum@0: } indvdum@0: indvdum@0: // stop context generation and wait for the next word indvdum@0: if ($j > $sequence_length) indvdum@0: { indvdum@0: $j = 0; indvdum@0: } indvdum@0: } indvdum@0: } indvdum@0: } indvdum@0: return str_replace($characters, $entities, $final_text); indvdum@0: } indvdum@0: } indvdum@0: indvdum@0: if (!sizeof($words) || !sizeof($word_indizes)) indvdum@0: { indvdum@0: return str_replace($characters, $entities, ((utf8_strlen($text) >= $length + 3) ? utf8_substr($text, 0, $length) . '...' : $text)); indvdum@0: } indvdum@0: } indvdum@0: indvdum@0: /** indvdum@0: * Decode text whereby text is coming from the db and expected to be pre-parsed content indvdum@0: * We are placing this outside of the message parser because we are often in need of it... indvdum@0: */ indvdum@0: function decode_message(&$message, $bbcode_uid = '') indvdum@0: { indvdum@0: global $config; indvdum@0: indvdum@0: if ($bbcode_uid) indvdum@0: { indvdum@0: $match = array('
', "[/*:m:$bbcode_uid]", ":u:$bbcode_uid", ":o:$bbcode_uid", ":$bbcode_uid"); indvdum@0: $replace = array("\n", '', '', '', ''); indvdum@0: } indvdum@0: else indvdum@0: { indvdum@0: $match = array('
'); indvdum@0: $replace = array("\n"); indvdum@0: } indvdum@0: indvdum@0: $message = str_replace($match, $replace, $message); indvdum@0: indvdum@0: $match = get_preg_expression('bbcode_htm'); indvdum@0: $replace = array('\1', '\1', '\2', '\1', '', ''); indvdum@0: indvdum@0: $message = preg_replace($match, $replace, $message); indvdum@0: } indvdum@0: indvdum@0: /** indvdum@0: * Strips all bbcode from a text and returns the plain content indvdum@0: */ indvdum@0: function strip_bbcode(&$text, $uid = '') indvdum@0: { indvdum@0: if (!$uid) indvdum@0: { indvdum@0: $uid = '[0-9a-z]{5,}'; indvdum@0: } indvdum@0: indvdum@0: $text = preg_replace("#\[\/?[a-z0-9\*\+\-]+(?:=(?:".*"|[^\]]*))?(?::[a-z])?(\:$uid)\]#", ' ', $text); indvdum@0: indvdum@0: $match = get_preg_expression('bbcode_htm'); indvdum@0: $replace = array('\1', '\1', '\2', '\1', '', ''); indvdum@0: indvdum@0: $text = preg_replace($match, $replace, $text); indvdum@0: } indvdum@0: indvdum@0: /** indvdum@0: * For display of custom parsed text on user-facing pages indvdum@0: * Expects $text to be the value directly from the database (stored value) indvdum@0: */ indvdum@0: function generate_text_for_display($text, $uid, $bitfield, $flags) indvdum@0: { indvdum@0: static $bbcode; indvdum@0: indvdum@0: if (!$text) indvdum@0: { indvdum@0: return ''; indvdum@0: } indvdum@0: indvdum@0: $text = censor_text($text); indvdum@0: indvdum@0: // Parse bbcode if bbcode uid stored and bbcode enabled indvdum@0: if ($uid && ($flags & OPTION_FLAG_BBCODE)) indvdum@0: { indvdum@0: if (!class_exists('bbcode')) indvdum@0: { indvdum@0: global $phpbb_root_path, $phpEx; indvdum@0: include($phpbb_root_path . 'includes/bbcode.' . $phpEx); indvdum@0: } indvdum@0: indvdum@0: if (empty($bbcode)) indvdum@0: { indvdum@0: $bbcode = new bbcode($bitfield); indvdum@0: } indvdum@0: else indvdum@0: { indvdum@0: $bbcode->bbcode($bitfield); indvdum@0: } indvdum@0: indvdum@0: $bbcode->bbcode_second_pass($text, $uid); indvdum@0: } indvdum@0: indvdum@0: $text = bbcode_nl2br($text); indvdum@0: $text = smiley_text($text, !($flags & OPTION_FLAG_SMILIES)); indvdum@0: indvdum@0: return $text; indvdum@0: } indvdum@0: indvdum@0: /** indvdum@0: * For parsing custom parsed text to be stored within the database. indvdum@0: * This function additionally returns the uid and bitfield that needs to be stored. indvdum@0: * Expects $text to be the value directly from request_var() and in it's non-parsed form indvdum@0: */ indvdum@0: function generate_text_for_storage(&$text, &$uid, &$bitfield, &$flags, $allow_bbcode = false, $allow_urls = false, $allow_smilies = false) indvdum@0: { indvdum@0: global $phpbb_root_path, $phpEx; indvdum@0: indvdum@0: $uid = $bitfield = ''; indvdum@0: $flags = (($allow_bbcode) ? OPTION_FLAG_BBCODE : 0) + (($allow_smilies) ? OPTION_FLAG_SMILIES : 0) + (($allow_urls) ? OPTION_FLAG_LINKS : 0); indvdum@0: indvdum@0: if (!$text) indvdum@0: { indvdum@0: return; indvdum@0: } indvdum@0: indvdum@0: if (!class_exists('parse_message')) indvdum@0: { indvdum@0: include($phpbb_root_path . 'includes/message_parser.' . $phpEx); indvdum@0: } indvdum@0: indvdum@0: $message_parser = new parse_message($text); indvdum@0: $message_parser->parse($allow_bbcode, $allow_urls, $allow_smilies); indvdum@0: indvdum@0: $text = $message_parser->message; indvdum@0: $uid = $message_parser->bbcode_uid; indvdum@0: indvdum@0: // If the bbcode_bitfield is empty, there is no need for the uid to be stored. indvdum@0: if (!$message_parser->bbcode_bitfield) indvdum@0: { indvdum@0: $uid = ''; indvdum@0: } indvdum@0: indvdum@0: $bitfield = $message_parser->bbcode_bitfield; indvdum@0: indvdum@0: return; indvdum@0: } indvdum@0: indvdum@0: /** indvdum@0: * For decoding custom parsed text for edits as well as extracting the flags indvdum@0: * Expects $text to be the value directly from the database (pre-parsed content) indvdum@0: */ indvdum@0: function generate_text_for_edit($text, $uid, $flags) indvdum@0: { indvdum@0: global $phpbb_root_path, $phpEx; indvdum@0: indvdum@0: decode_message($text, $uid); indvdum@0: indvdum@0: return array( indvdum@0: 'allow_bbcode' => ($flags & OPTION_FLAG_BBCODE) ? 1 : 0, indvdum@0: 'allow_smilies' => ($flags & OPTION_FLAG_SMILIES) ? 1 : 0, indvdum@0: 'allow_urls' => ($flags & OPTION_FLAG_LINKS) ? 1 : 0, indvdum@0: 'text' => $text indvdum@0: ); indvdum@0: } indvdum@0: indvdum@0: /** indvdum@0: * A subroutine of make_clickable used with preg_replace indvdum@0: * It places correct HTML around an url, shortens the displayed text indvdum@0: * and makes sure no entities are inside URLs indvdum@0: */ indvdum@0: function make_clickable_callback($type, $whitespace, $url, $relative_url, $class) indvdum@0: { indvdum@0: $orig_url = $url; indvdum@0: $orig_relative = $relative_url; indvdum@0: $append = ''; indvdum@0: $url = htmlspecialchars_decode($url); indvdum@0: $relative_url = htmlspecialchars_decode($relative_url); indvdum@0: indvdum@0: // make sure no HTML entities were matched indvdum@0: $chars = array('<', '>', '"'); indvdum@0: $split = false; indvdum@0: indvdum@0: foreach ($chars as $char) indvdum@0: { indvdum@0: $next_split = strpos($url, $char); indvdum@0: if ($next_split !== false) indvdum@0: { indvdum@0: $split = ($split !== false) ? min($split, $next_split) : $next_split; indvdum@0: } indvdum@0: } indvdum@0: indvdum@0: if ($split !== false) indvdum@0: { indvdum@0: // an HTML entity was found, so the URL has to end before it indvdum@0: $append = substr($url, $split) . $relative_url; indvdum@0: $url = substr($url, 0, $split); indvdum@0: $relative_url = ''; indvdum@0: } indvdum@0: else if ($relative_url) indvdum@0: { indvdum@0: // same for $relative_url indvdum@0: $split = false; indvdum@0: foreach ($chars as $char) indvdum@0: { indvdum@0: $next_split = strpos($relative_url, $char); indvdum@0: if ($next_split !== false) indvdum@0: { indvdum@0: $split = ($split !== false) ? min($split, $next_split) : $next_split; indvdum@0: } indvdum@0: } indvdum@0: indvdum@0: if ($split !== false) indvdum@0: { indvdum@0: $append = substr($relative_url, $split); indvdum@0: $relative_url = substr($relative_url, 0, $split); indvdum@0: } indvdum@0: } indvdum@0: indvdum@0: // if the last character of the url is a punctuation mark, exclude it from the url indvdum@0: $last_char = ($relative_url) ? $relative_url[strlen($relative_url) - 1] : $url[strlen($url) - 1]; indvdum@0: indvdum@0: switch ($last_char) indvdum@0: { indvdum@0: case '.': indvdum@0: case '?': indvdum@0: case '!': indvdum@0: case ':': indvdum@0: case ',': indvdum@0: $append = $last_char; indvdum@0: if ($relative_url) indvdum@0: { indvdum@0: $relative_url = substr($relative_url, 0, -1); indvdum@0: } indvdum@0: else indvdum@0: { indvdum@0: $url = substr($url, 0, -1); indvdum@0: } indvdum@0: break; indvdum@0: indvdum@0: // set last_char to empty here, so the variable can be used later to indvdum@0: // check whether a character was removed indvdum@0: default: indvdum@0: $last_char = ''; indvdum@0: break; indvdum@0: } indvdum@0: indvdum@0: $short_url = (strlen($url) > 55) ? substr($url, 0, 39) . ' ... ' . substr($url, -10) : $url; indvdum@0: indvdum@0: switch ($type) indvdum@0: { indvdum@0: case MAGIC_URL_LOCAL: indvdum@0: $tag = 'l'; indvdum@0: $relative_url = preg_replace('/[&?]sid=[0-9a-f]{32}$/', '', preg_replace('/([&?])sid=[0-9a-f]{32}&/', '$1', $relative_url)); indvdum@0: $url = $url . '/' . $relative_url; indvdum@0: $text = $relative_url; indvdum@0: indvdum@0: // this url goes to http://domain.tld/path/to/board/ which indvdum@0: // would result in an empty link if treated as local so indvdum@0: // don't touch it and let MAGIC_URL_FULL take care of it. indvdum@0: if (!$relative_url) indvdum@0: { indvdum@0: return $whitespace . $orig_url . '/' . $orig_relative; // slash is taken away by relative url pattern indvdum@0: } indvdum@0: break; indvdum@0: indvdum@0: case MAGIC_URL_FULL: indvdum@0: $tag = 'm'; indvdum@0: $text = $short_url; indvdum@0: break; indvdum@0: indvdum@0: case MAGIC_URL_WWW: indvdum@0: $tag = 'w'; indvdum@0: $url = 'http://' . $url; indvdum@0: $text = $short_url; indvdum@0: break; indvdum@0: indvdum@0: case MAGIC_URL_EMAIL: indvdum@0: $tag = 'e'; indvdum@0: $text = $short_url; indvdum@0: $url = 'mailto:' . $url; indvdum@0: break; indvdum@0: } indvdum@0: indvdum@0: $url = htmlspecialchars($url); indvdum@0: $text = htmlspecialchars($text); indvdum@0: $append = htmlspecialchars($append); indvdum@0: indvdum@0: $html = "$whitespace$text$append"; indvdum@0: indvdum@0: return $html; indvdum@0: } indvdum@0: indvdum@0: /** indvdum@0: * make_clickable function indvdum@0: * indvdum@0: * Replace magic urls of form http://xxx.xxx., www.xxx. and xxx@xxx.xxx. indvdum@0: * Cuts down displayed size of link if over 50 chars, turns absolute links indvdum@0: * into relative versions when the server/script path matches the link indvdum@0: */ indvdum@0: function make_clickable($text, $server_url = false, $class = 'postlink') indvdum@0: { indvdum@0: if ($server_url === false) indvdum@0: { indvdum@0: $server_url = generate_board_url(); indvdum@0: } indvdum@0: indvdum@0: static $magic_url_match; indvdum@0: static $magic_url_replace; indvdum@0: static $static_class; indvdum@0: indvdum@0: if (!is_array($magic_url_match) || $static_class != $class) indvdum@0: { indvdum@0: $static_class = $class; indvdum@0: $class = ($static_class) ? ' class="' . $static_class . '"' : ''; indvdum@0: $local_class = ($static_class) ? ' class="' . $static_class . '-local"' : ''; indvdum@0: indvdum@0: $magic_url_match = $magic_url_replace = array(); indvdum@0: // Be sure to not let the matches cross over. ;) indvdum@0: indvdum@0: // relative urls for this board indvdum@0: $magic_url_match[] = '#(^|[\n\t (>.])(' . preg_quote($server_url, '#') . ')/(' . get_preg_expression('relative_url_inline') . ')#ie'; indvdum@0: $magic_url_replace[] = "make_clickable_callback(MAGIC_URL_LOCAL, '\$1', '\$2', '\$3', '$local_class')"; indvdum@0: indvdum@0: // matches a xxxx://aaaaa.bbb.cccc. ... indvdum@0: $magic_url_match[] = '#(^|[\n\t (>.])(' . get_preg_expression('url_inline') . ')#ie'; indvdum@0: $magic_url_replace[] = "make_clickable_callback(MAGIC_URL_FULL, '\$1', '\$2', '', '$class')"; indvdum@0: indvdum@0: // matches a "www.xxxx.yyyy[/zzzz]" kinda lazy URL thing indvdum@0: $magic_url_match[] = '#(^|[\n\t (>])(' . get_preg_expression('www_url_inline') . ')#ie'; indvdum@0: $magic_url_replace[] = "make_clickable_callback(MAGIC_URL_WWW, '\$1', '\$2', '', '$class')"; indvdum@0: indvdum@0: // matches an email@domain type address at the start of a line, or after a space or after what might be a BBCode. indvdum@0: $magic_url_match[] = '/(^|[\n\t (>])(' . get_preg_expression('email') . ')/ie'; indvdum@0: $magic_url_replace[] = "make_clickable_callback(MAGIC_URL_EMAIL, '\$1', '\$2', '', '')"; indvdum@0: } indvdum@0: indvdum@0: return preg_replace($magic_url_match, $magic_url_replace, $text); indvdum@0: } indvdum@0: indvdum@0: /** indvdum@0: * Censoring indvdum@0: */ indvdum@0: function censor_text($text) indvdum@0: { indvdum@0: static $censors; indvdum@0: indvdum@0: // Nothing to do? indvdum@0: if ($text === '') indvdum@0: { indvdum@0: return ''; indvdum@0: } indvdum@0: indvdum@0: // We moved the word censor checks in here because we call this function quite often - and then only need to do the check once indvdum@0: if (!isset($censors) || !is_array($censors)) indvdum@0: { indvdum@0: global $config, $user, $auth, $cache; indvdum@0: indvdum@0: // We check here if the user is having viewing censors disabled (and also allowed to do so). indvdum@0: if (!$user->optionget('viewcensors') && $config['allow_nocensors'] && $auth->acl_get('u_chgcensors')) indvdum@0: { indvdum@0: $censors = array(); indvdum@0: } indvdum@0: else indvdum@0: { indvdum@0: $censors = $cache->obtain_word_list(); indvdum@0: } indvdum@0: } indvdum@0: indvdum@0: if (sizeof($censors)) indvdum@0: { indvdum@0: return preg_replace($censors['match'], $censors['replace'], $text); indvdum@0: } indvdum@0: indvdum@0: return $text; indvdum@0: } indvdum@0: indvdum@0: /** indvdum@0: * custom version of nl2br which takes custom BBCodes into account indvdum@0: */ indvdum@0: function bbcode_nl2br($text) indvdum@0: { indvdum@0: // custom BBCodes might contain carriage returns so they indvdum@0: // are not converted into
so now revert that indvdum@0: $text = str_replace(array("\n", "\r"), array('
', "\n"), $text); indvdum@0: return $text; indvdum@0: } indvdum@0: indvdum@0: /** indvdum@0: * Smiley processing indvdum@0: */ indvdum@0: function smiley_text($text, $force_option = false) indvdum@0: { indvdum@0: global $config, $user, $phpbb_root_path; indvdum@0: indvdum@0: if ($force_option || !$config['allow_smilies'] || !$user->optionget('viewsmilies')) indvdum@0: { indvdum@0: return preg_replace('##', ''; indvdum@0: } indvdum@0: } indvdum@0: indvdum@0: $filesize = get_formatted_filesize($attachment['filesize'], false); indvdum@0: indvdum@0: $comment = bbcode_nl2br(censor_text($attachment['attach_comment'])); indvdum@0: indvdum@0: $block_array += array( indvdum@0: 'UPLOAD_ICON' => $upload_icon, indvdum@0: 'FILESIZE' => $filesize['value'], indvdum@0: 'SIZE_LANG' => $filesize['unit'], indvdum@0: 'DOWNLOAD_NAME' => utf8_basename($attachment['real_filename']), indvdum@0: 'COMMENT' => $comment, indvdum@0: ); indvdum@0: indvdum@0: $denied = false; indvdum@0: indvdum@0: if (!extension_allowed($forum_id, $attachment['extension'], $extensions)) indvdum@0: { indvdum@0: $denied = true; indvdum@0: indvdum@0: $block_array += array( indvdum@0: 'S_DENIED' => true, indvdum@0: 'DENIED_MESSAGE' => sprintf($user->lang['EXTENSION_DISABLED_AFTER_POSTING'], $attachment['extension']) indvdum@0: ); indvdum@0: } indvdum@0: indvdum@0: if (!$denied) indvdum@0: { indvdum@0: $l_downloaded_viewed = $download_link = ''; indvdum@0: $display_cat = $extensions[$attachment['extension']]['display_cat']; indvdum@0: indvdum@0: if ($display_cat == ATTACHMENT_CATEGORY_IMAGE) indvdum@0: { indvdum@0: if ($attachment['thumbnail']) indvdum@0: { indvdum@0: $display_cat = ATTACHMENT_CATEGORY_THUMB; indvdum@0: } indvdum@0: else indvdum@0: { indvdum@0: if ($config['img_display_inlined']) indvdum@0: { indvdum@0: if ($config['img_link_width'] || $config['img_link_height']) indvdum@0: { indvdum@0: $dimension = @getimagesize($filename); indvdum@0: indvdum@0: // If the dimensions could not be determined or the image being 0x0 we display it as a link for safety purposes indvdum@0: if ($dimension === false || empty($dimension[0]) || empty($dimension[1])) indvdum@0: { indvdum@0: $display_cat = ATTACHMENT_CATEGORY_NONE; indvdum@0: } indvdum@0: else indvdum@0: { indvdum@0: $display_cat = ($dimension[0] <= $config['img_link_width'] && $dimension[1] <= $config['img_link_height']) ? ATTACHMENT_CATEGORY_IMAGE : ATTACHMENT_CATEGORY_NONE; indvdum@0: } indvdum@0: } indvdum@0: } indvdum@0: else indvdum@0: { indvdum@0: $display_cat = ATTACHMENT_CATEGORY_NONE; indvdum@0: } indvdum@0: } indvdum@0: } indvdum@0: indvdum@0: // Make some descisions based on user options being set. indvdum@0: if (($display_cat == ATTACHMENT_CATEGORY_IMAGE || $display_cat == ATTACHMENT_CATEGORY_THUMB) && !$user->optionget('viewimg')) indvdum@0: { indvdum@0: $display_cat = ATTACHMENT_CATEGORY_NONE; indvdum@0: } indvdum@0: indvdum@0: if ($display_cat == ATTACHMENT_CATEGORY_FLASH && !$user->optionget('viewflash')) indvdum@0: { indvdum@0: $display_cat = ATTACHMENT_CATEGORY_NONE; indvdum@0: } indvdum@0: indvdum@0: $download_link = append_sid("{$phpbb_root_path}download/file.$phpEx", 'id=' . $attachment['attach_id']); indvdum@0: indvdum@0: switch ($display_cat) indvdum@0: { indvdum@0: // Images indvdum@0: case ATTACHMENT_CATEGORY_IMAGE: indvdum@0: $l_downloaded_viewed = 'VIEWED_COUNT'; indvdum@0: $inline_link = append_sid("{$phpbb_root_path}download/file.$phpEx", 'id=' . $attachment['attach_id']); indvdum@0: $download_link .= '&mode=view'; indvdum@0: indvdum@0: $block_array += array( indvdum@0: 'S_IMAGE' => true, indvdum@0: 'U_INLINE_LINK' => $inline_link, indvdum@0: ); indvdum@0: indvdum@0: $update_count[] = $attachment['attach_id']; indvdum@0: break; indvdum@0: indvdum@0: // Images, but display Thumbnail indvdum@0: case ATTACHMENT_CATEGORY_THUMB: indvdum@0: $l_downloaded_viewed = 'VIEWED_COUNT'; indvdum@0: $thumbnail_link = append_sid("{$phpbb_root_path}download/file.$phpEx", 'id=' . $attachment['attach_id'] . '&t=1'); indvdum@0: $download_link .= '&mode=view'; indvdum@0: indvdum@0: $block_array += array( indvdum@0: 'S_THUMBNAIL' => true, indvdum@0: 'THUMB_IMAGE' => $thumbnail_link, indvdum@0: ); indvdum@0: indvdum@0: $update_count[] = $attachment['attach_id']; indvdum@0: break; indvdum@0: indvdum@0: // Windows Media Streams indvdum@0: case ATTACHMENT_CATEGORY_WM: indvdum@0: $l_downloaded_viewed = 'VIEWED_COUNT'; indvdum@0: indvdum@0: // Giving the filename directly because within the wm object all variables are in local context making it impossible indvdum@0: // to validate against a valid session (all params can differ) indvdum@0: // $download_link = $filename; indvdum@0: indvdum@0: $block_array += array( indvdum@0: 'U_FORUM' => generate_board_url(), indvdum@0: 'ATTACH_ID' => $attachment['attach_id'], indvdum@0: 'S_WM_FILE' => true, indvdum@0: ); indvdum@0: indvdum@0: // Viewed/Heared File ... update the download count indvdum@0: $update_count[] = $attachment['attach_id']; indvdum@0: break; indvdum@0: indvdum@0: // Real Media Streams indvdum@0: case ATTACHMENT_CATEGORY_RM: indvdum@0: case ATTACHMENT_CATEGORY_QUICKTIME: indvdum@0: $l_downloaded_viewed = 'VIEWED_COUNT'; indvdum@0: indvdum@0: $block_array += array( indvdum@0: 'S_RM_FILE' => ($display_cat == ATTACHMENT_CATEGORY_RM) ? true : false, indvdum@0: 'S_QUICKTIME_FILE' => ($display_cat == ATTACHMENT_CATEGORY_QUICKTIME) ? true : false, indvdum@0: 'U_FORUM' => generate_board_url(), indvdum@0: 'ATTACH_ID' => $attachment['attach_id'], indvdum@0: ); indvdum@0: indvdum@0: // Viewed/Heared File ... update the download count indvdum@0: $update_count[] = $attachment['attach_id']; indvdum@0: break; indvdum@0: indvdum@0: // Macromedia Flash Files indvdum@0: case ATTACHMENT_CATEGORY_FLASH: indvdum@0: list($width, $height) = @getimagesize($filename); indvdum@0: indvdum@0: $l_downloaded_viewed = 'VIEWED_COUNT'; indvdum@0: indvdum@0: $block_array += array( indvdum@0: 'S_FLASH_FILE' => true, indvdum@0: 'WIDTH' => $width, indvdum@0: 'HEIGHT' => $height, indvdum@0: 'U_VIEW_LINK' => $download_link . '&view=1', indvdum@0: ); indvdum@0: indvdum@0: // Viewed/Heared File ... update the download count indvdum@0: $update_count[] = $attachment['attach_id']; indvdum@0: break; indvdum@0: indvdum@0: default: indvdum@0: $l_downloaded_viewed = 'DOWNLOAD_COUNT'; indvdum@0: indvdum@0: $block_array += array( indvdum@0: 'S_FILE' => true, indvdum@0: ); indvdum@0: break; indvdum@0: } indvdum@0: indvdum@0: $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'])); indvdum@0: indvdum@0: $block_array += array( indvdum@0: 'U_DOWNLOAD_LINK' => $download_link, indvdum@0: 'L_DOWNLOAD_COUNT' => $l_download_count indvdum@0: ); indvdum@0: } indvdum@0: indvdum@0: $template->assign_block_vars('_file', $block_array); indvdum@0: indvdum@0: $compiled_attachments[] = $template->assign_display('attachment_tpl'); indvdum@0: } indvdum@0: indvdum@0: $attachments = $compiled_attachments; indvdum@0: unset($compiled_attachments); indvdum@0: indvdum@0: $tpl_size = sizeof($attachments); indvdum@0: indvdum@0: $unset_tpl = array(); indvdum@0: indvdum@0: preg_match_all('#(.*?)#', $message, $matches, PREG_PATTERN_ORDER); indvdum@0: indvdum@0: $replace = array(); indvdum@0: foreach ($matches[0] as $num => $capture) indvdum@0: { indvdum@0: // Flip index if we are displaying the reverse way indvdum@0: $index = ($config['display_order']) ? ($tpl_size-($matches[1][$num] + 1)) : $matches[1][$num]; indvdum@0: indvdum@0: $replace['from'][] = $matches[0][$num]; indvdum@0: $replace['to'][] = (isset($attachments[$index])) ? $attachments[$index] : sprintf($user->lang['MISSING_INLINE_ATTACHMENT'], $matches[2][array_search($index, $matches[1])]); indvdum@0: indvdum@0: $unset_tpl[] = $index; indvdum@0: } indvdum@0: indvdum@0: if (isset($replace['from'])) indvdum@0: { indvdum@0: $message = str_replace($replace['from'], $replace['to'], $message); indvdum@0: } indvdum@0: indvdum@0: $unset_tpl = array_unique($unset_tpl); indvdum@0: indvdum@0: // Needed to let not display the inlined attachments at the end of the post again indvdum@0: foreach ($unset_tpl as $index) indvdum@0: { indvdum@0: unset($attachments[$index]); indvdum@0: } indvdum@0: } indvdum@0: indvdum@0: /** indvdum@0: * Check if extension is allowed to be posted. indvdum@0: * indvdum@0: * @param mixed $forum_id The forum id to check or false if private message indvdum@0: * @param string $extension The extension to check, for example zip. indvdum@0: * @param array &$extensions The extension array holding the information from the cache (will be obtained if empty) indvdum@0: * indvdum@0: * @return bool False if the extension is not allowed to be posted, else true. indvdum@0: */ indvdum@0: function extension_allowed($forum_id, $extension, &$extensions) indvdum@0: { indvdum@0: if (empty($extensions)) indvdum@0: { indvdum@0: global $cache; indvdum@0: $extensions = $cache->obtain_attach_extensions($forum_id); indvdum@0: } indvdum@0: indvdum@0: return (!isset($extensions['_allowed_'][$extension])) ? false : true; indvdum@0: } indvdum@0: indvdum@0: /** indvdum@0: * Truncates string while retaining special characters if going over the max length indvdum@0: * The default max length is 60 at the moment indvdum@0: * The maximum storage length is there to fit the string within the given length. The string may be further truncated due to html entities. indvdum@0: * For example: string given is 'a "quote"' (length: 9), would be a stored as 'a "quote"' (length: 19) indvdum@0: * indvdum@0: * @param string $string The text to truncate to the given length. String is specialchared. indvdum@0: * @param int $max_length Maximum length of string (multibyte character count as 1 char / Html entity count as 1 char) indvdum@0: * @param int $max_store_length Maximum character length of string (multibyte character count as 1 char / Html entity count as entity chars). indvdum@0: * @param bool $allow_reply Allow Re: in front of string indvdum@0: * NOTE: This parameter can cause undesired behavior (returning strings longer than $max_store_length) and is deprecated. indvdum@0: * @param string $append String to be appended indvdum@0: */ indvdum@0: function truncate_string($string, $max_length = 60, $max_store_length = 255, $allow_reply = false, $append = '') indvdum@0: { indvdum@0: $chars = array(); indvdum@0: indvdum@0: $strip_reply = false; indvdum@0: $stripped = false; indvdum@0: if ($allow_reply && strpos($string, 'Re: ') === 0) indvdum@0: { indvdum@0: $strip_reply = true; indvdum@0: $string = substr($string, 4); indvdum@0: } indvdum@0: indvdum@0: $_chars = utf8_str_split(htmlspecialchars_decode($string)); indvdum@0: $chars = array_map('utf8_htmlspecialchars', $_chars); indvdum@0: indvdum@0: // Now check the length ;) indvdum@0: if (sizeof($chars) > $max_length) indvdum@0: { indvdum@0: // Cut off the last elements from the array indvdum@0: $string = implode('', array_slice($chars, 0, $max_length - utf8_strlen($append))); indvdum@0: $stripped = true; indvdum@0: } indvdum@0: indvdum@0: // Due to specialchars, we may not be able to store the string... indvdum@0: if (utf8_strlen($string) > $max_store_length) indvdum@0: { indvdum@0: // let's split again, we do not want half-baked strings where entities are split indvdum@0: $_chars = utf8_str_split(htmlspecialchars_decode($string)); indvdum@0: $chars = array_map('utf8_htmlspecialchars', $_chars); indvdum@0: indvdum@0: do indvdum@0: { indvdum@0: array_pop($chars); indvdum@0: $string = implode('', $chars); indvdum@0: } indvdum@0: while (!empty($chars) && utf8_strlen($string) > $max_store_length); indvdum@0: } indvdum@0: indvdum@0: if ($strip_reply) indvdum@0: { indvdum@0: $string = 'Re: ' . $string; indvdum@0: } indvdum@0: indvdum@0: if ($append != '' && $stripped) indvdum@0: { indvdum@0: $string = $string . $append; indvdum@0: } indvdum@0: indvdum@0: return $string; indvdum@0: } indvdum@0: indvdum@0: /** indvdum@0: * Get username details for placing into templates. indvdum@0: * This function caches all modes on first call, except for no_profile and anonymous user - determined by $user_id. indvdum@0: * indvdum@0: * @param string $mode Can be profile (for getting an url to the profile), username (for obtaining the username), colour (for obtaining the user colour), full (for obtaining a html string representing a coloured link to the users profile) or no_profile (the same as full but forcing no profile link) indvdum@0: * @param int $user_id The users id indvdum@0: * @param string $username The users name indvdum@0: * @param string $username_colour The users colour indvdum@0: * @param string $guest_username optional parameter to specify the guest username. It will be used in favor of the GUEST language variable then. indvdum@0: * @param string $custom_profile_url optional parameter to specify a profile url. The user id get appended to this url as &u={user_id} indvdum@0: * indvdum@0: * @return string A string consisting of what is wanted based on $mode. indvdum@0: * @author BartVB, Acyd Burn indvdum@0: */ indvdum@0: function get_username_string($mode, $user_id, $username, $username_colour = '', $guest_username = false, $custom_profile_url = false) indvdum@0: { indvdum@0: static $_profile_cache; indvdum@0: indvdum@0: // We cache some common variables we need within this function indvdum@0: if (empty($_profile_cache)) indvdum@0: { indvdum@0: global $phpbb_root_path, $phpEx; indvdum@0: indvdum@0: $_profile_cache['base_url'] = append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=viewprofile&u={USER_ID}'); indvdum@0: $_profile_cache['tpl_noprofile'] = '{USERNAME}'; indvdum@0: $_profile_cache['tpl_noprofile_colour'] = '{USERNAME}'; indvdum@0: $_profile_cache['tpl_profile'] = '{USERNAME}'; indvdum@0: $_profile_cache['tpl_profile_colour'] = '{USERNAME}'; indvdum@0: } indvdum@0: indvdum@0: global $user, $auth; indvdum@0: indvdum@0: // This switch makes sure we only run code required for the mode indvdum@0: switch ($mode) indvdum@0: { indvdum@0: case 'full': indvdum@0: case 'no_profile': indvdum@0: case 'colour': indvdum@0: indvdum@0: // Build correct username colour indvdum@0: $username_colour = ($username_colour) ? '#' . $username_colour : ''; indvdum@0: indvdum@0: // Return colour indvdum@0: if ($mode == 'colour') indvdum@0: { indvdum@0: return $username_colour; indvdum@0: } indvdum@0: indvdum@0: // no break; indvdum@0: indvdum@0: case 'username': indvdum@0: indvdum@0: // Build correct username indvdum@0: if ($guest_username === false) indvdum@0: { indvdum@0: $username = ($username) ? $username : $user->lang['GUEST']; indvdum@0: } indvdum@0: else indvdum@0: { indvdum@0: $username = ($user_id && $user_id != ANONYMOUS) ? $username : ((!empty($guest_username)) ? $guest_username : $user->lang['GUEST']); indvdum@0: } indvdum@0: indvdum@0: // Return username indvdum@0: if ($mode == 'username') indvdum@0: { indvdum@0: return $username; indvdum@0: } indvdum@0: indvdum@0: // no break; indvdum@0: indvdum@0: case 'profile': indvdum@0: indvdum@0: // Build correct profile url - only show if not anonymous and permission to view profile if registered user indvdum@0: // For anonymous the link leads to a login page. indvdum@0: if ($user_id && $user_id != ANONYMOUS && ($user->data['user_id'] == ANONYMOUS || $auth->acl_get('u_viewprofile'))) indvdum@0: { indvdum@0: $profile_url = ($custom_profile_url !== false) ? $custom_profile_url . '&u=' . (int) $user_id : str_replace(array('={USER_ID}', '=%7BUSER_ID%7D'), '=' . (int) $user_id, $_profile_cache['base_url']); indvdum@0: } indvdum@0: else indvdum@0: { indvdum@0: $profile_url = ''; indvdum@0: } indvdum@0: indvdum@0: // Return profile indvdum@0: if ($mode == 'profile') indvdum@0: { indvdum@0: return $profile_url; indvdum@0: } indvdum@0: indvdum@0: // no break; indvdum@0: } indvdum@0: indvdum@0: if (($mode == 'full' && !$profile_url) || $mode == 'no_profile') indvdum@0: { indvdum@0: return str_replace(array('{USERNAME_COLOUR}', '{USERNAME}'), array($username_colour, $username), (!$username_colour) ? $_profile_cache['tpl_noprofile'] : $_profile_cache['tpl_noprofile_colour']); indvdum@0: } indvdum@0: indvdum@0: return str_replace(array('{PROFILE_URL}', '{USERNAME_COLOUR}', '{USERNAME}'), array($profile_url, $username_colour, $username), (!$username_colour) ? $_profile_cache['tpl_profile'] : $_profile_cache['tpl_profile_colour']); indvdum@0: } indvdum@0: indvdum@0: /** indvdum@0: * @package phpBB3 indvdum@0: */ indvdum@0: class bitfield indvdum@0: { indvdum@0: var $data; indvdum@0: indvdum@0: function bitfield($bitfield = '') indvdum@0: { indvdum@0: $this->data = base64_decode($bitfield); indvdum@0: } indvdum@0: indvdum@0: /** indvdum@0: */ indvdum@0: function get($n) indvdum@0: { indvdum@0: // Get the ($n / 8)th char indvdum@0: $byte = $n >> 3; indvdum@0: indvdum@0: if (strlen($this->data) >= $byte + 1) indvdum@0: { indvdum@0: $c = $this->data[$byte]; indvdum@0: indvdum@0: // Lookup the ($n % 8)th bit of the byte indvdum@0: $bit = 7 - ($n & 7); indvdum@0: return (bool) (ord($c) & (1 << $bit)); indvdum@0: } indvdum@0: else indvdum@0: { indvdum@0: return false; indvdum@0: } indvdum@0: } indvdum@0: indvdum@0: function set($n) indvdum@0: { indvdum@0: $byte = $n >> 3; indvdum@0: $bit = 7 - ($n & 7); indvdum@0: indvdum@0: if (strlen($this->data) >= $byte + 1) indvdum@0: { indvdum@0: $this->data[$byte] = $this->data[$byte] | chr(1 << $bit); indvdum@0: } indvdum@0: else indvdum@0: { indvdum@0: $this->data .= str_repeat("\0", $byte - strlen($this->data)); indvdum@0: $this->data .= chr(1 << $bit); indvdum@0: } indvdum@0: } indvdum@0: indvdum@0: function clear($n) indvdum@0: { indvdum@0: $byte = $n >> 3; indvdum@0: indvdum@0: if (strlen($this->data) >= $byte + 1) indvdum@0: { indvdum@0: $bit = 7 - ($n & 7); indvdum@0: $this->data[$byte] = $this->data[$byte] &~ chr(1 << $bit); indvdum@0: } indvdum@0: } indvdum@0: indvdum@0: function get_blob() indvdum@0: { indvdum@0: return $this->data; indvdum@0: } indvdum@0: indvdum@0: function get_base64() indvdum@0: { indvdum@0: return base64_encode($this->data); indvdum@0: } indvdum@0: indvdum@0: function get_bin() indvdum@0: { indvdum@0: $bin = ''; indvdum@0: $len = strlen($this->data); indvdum@0: indvdum@0: for ($i = 0; $i < $len; ++$i) indvdum@0: { indvdum@0: $bin .= str_pad(decbin(ord($this->data[$i])), 8, '0', STR_PAD_LEFT); indvdum@0: } indvdum@0: indvdum@0: return $bin; indvdum@0: } indvdum@0: indvdum@0: function get_all_set() indvdum@0: { indvdum@0: return array_keys(array_filter(str_split($this->get_bin()))); indvdum@0: } indvdum@0: indvdum@0: function merge($bitfield) indvdum@0: { indvdum@0: $this->data = $this->data | $bitfield->get_blob(); indvdum@0: } indvdum@0: } indvdum@0: indvdum@0: ?>