function _init_search_query_object() { $request = request::instance(); if ($search_query = utf8_trim($request->get_attribute('search_query'))) { $this->query_object->add(search_text_normalizer::process($search_query)); } }
public function getMessageText($inputName, XenForo_Input $input, $htmlCharacterLimit = -1) { $messageText = parent::getMessageText($inputName, $input, $htmlCharacterLimit); if (utf8_trim($messageText) === 'lipsum') { $lipsum = @file_get_contents('http://www.lipsum.com/feed/json'); if (!empty($lipsum)) { $lipsum = @json_decode($lipsum, true); if (!empty($lipsum['feed']['lipsum'])) { $messageText = sprintf("%s\n\nBy [URL=%s]%s[/URL]", $lipsum['feed']['lipsum'], $lipsum['feed']['creditlink'], $lipsum['feed']['creditname']); } } } return $messageText; }
function get_search_query_object() { if ($this->query_object) { return $this->query_object; } $request = request::instance(); if (!($search_query = utf8_trim($request->get_attribute('search_query')))) { return null; } $this->query_object = new search_query(); $search_query = search_text_normalizer::process($search_query); $words = explode(' ', $search_query); foreach ($words as $word) { $this->query_object->add($word); } return $this->query_object; }
/** * Parses a var file into a data structure. Used in conjunction with an * Importtag */ function parse_var_file($filename) { $result = array(); $raw_lines = file($filename); while (list(, $line) = each($raw_lines)) { $equal_pos = utf8_strpos($line, '='); if ($equal_pos === false) { $result[utf8_trim($line)] = null; } else { $key = utf8_trim(utf8_substr($line, 0, $equal_pos)); if (utf8_strlen($key) > 0) { $result[$key] = utf8_trim(utf8_substr($line, $equal_pos + 1)); } } } return $result; }
/** * 双字节字符截取 * * @param string $content * @param int $length * @return string */ function substrs($content, $length) { if (!defined('CFG_CHARSET')) { define('CFG_CHARSET', 'utf-8'); } if ($length && strlen($content) > $length) { if (CFG_CHARSET != 'utf-8') { $retstr = ''; for ($i = 0; $i < $length - 2; $i++) { $retstr .= ord($content[$i]) > 127 ? $content[$i] . $content[++$i] : $content[$i]; } return $retstr . ' ..'; } else { return utf8_trim(substr($content, 0, $length * 3)); } } return $content; }
/** * Returns filename component of path * * @author Lars Knickrehm <*****@*****.**> * @category Library * @copyright Copyright © 2009 Lars Knickrehm * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License * @link http://php.net/manual/function.basename.php * @package UTF-8 * @param string $path A path. Both slash (/) and backslash (\) are used as directory separator character. * @param string $suffix If the filename ends in suffix this will also be cut off. * @return string Base name of the given path * @since Version 0.5.0 * @version 0.5.0 */ function utf8_basename($path, $suffix = '') { // Change backslash (\) to slash (/) $path = utf8_trim(strtr($path, array('\\' => '/')), '/'); // Get basename $i = utf8_strrpos($path, '/'); if ($i !== false) { $path = utf8_substr($path, $i + 1); } // Handle suffix if ($suffix !== '') { $position = utf8_strrpos($path, $suffix); if ($position !== false) { $path = utf8_substr($path, 0, $position); } } return $path; }
function process($content) { $content = utf8_strtolower($content); $content = utf8_str_replace("\n", ' ', $content); $content = utf8_str_replace("\t", ' ', $content); $content = utf8_str_replace("\r", ' ', $content); $search = array("'<script[^>]*?>.*?</script>'si", "'<[\\/\\!]*?[^<>]*?>'si", "'([\r\n])[\\s]+'"); $replace = array('', ' ', ' '); $content = preg_replace($search, $replace, $content); $content = preg_replace("#(\\.){2,}#", ' ', $content); $content = preg_replace("#^\\.#", ' ', $content); $content = preg_replace("#\\s\\.#", ' ', $content); $content = preg_replace("#\\.\\s#", ' ', $content); $content = preg_replace("#\\.\$#", ' ', $content); //non utf8 chars(�,�) $content = preg_replace("#(\\s|^)(\"|'|`|�|�)(\\w)#", '\\1\\3', $content); $content = preg_replace("#(\\w)(\"|'|`|�|�)(\\s|\$)#u", '\\1\\3', $content); $content = utf8_str_replace(" ", ' ', $content); $content = utf8_str_replace(":", ' ', $content); $content = utf8_str_replace(",", ' ', $content); $content = utf8_str_replace(";", ' ', $content); $content = utf8_str_replace("(", ' ', $content); $content = utf8_str_replace(")", ' ', $content); $content = utf8_str_replace("-", ' ', $content); $content = utf8_str_replace("+", ' ', $content); $content = utf8_str_replace("/", ' ', $content); $content = utf8_str_replace("!", ' ', $content); $content = utf8_str_replace("?", ' ', $content); $content = utf8_str_replace("[", ' ', $content); $content = utf8_str_replace("]", ' ', $content); $content = utf8_str_replace("\$", ' ', $content); $content = utf8_str_replace("\\", ' ', $content); $content = utf8_str_replace("<", ' ', $content); $content = utf8_str_replace(">", ' ', $content); $content = utf8_str_replace("*", ' ', $content); $content = utf8_trim(preg_replace("~\\s+~u", ' ', $content)); return $content; }
function pun_trim($str, $charlist = false) { return is_string($str) ? utf8_trim($str, $charlist) : ''; }
/** * Assign user to organization AND Try to create new organization if it doesn't exist yet * * @param object User * @param string Organization name * @param string Organization role */ function userorg_update_by_name(&$User, $org_name, $org_role = '') { $org_name = utf8_trim($org_name); if (empty($org_name)) { // Don't update an user organization with empty name: return; } if (is_null($this->userorgs)) { // Initialize array to keep what organizations should be assigned to the user: $this->userorgs = array(); } // Get organization ID by name AND save it in array to update after user insertion: $org_ID = $this->userorg_get_by_name($org_name); $this->userorgs[$org_ID] = $org_role; }
if ($is_logged_in) { if ($User->ID == $current_User->ID && !$User->has_avatar()) { // If user hasn't an avatar, add a link to go for uploading of avatar $avatar_imgtag = '<a href="' . get_user_avatar_url() . '">' . $avatar_imgtag . '</a>'; } } echo $params['profile_avatar_before'] . $avatar_imgtag . $params['profile_avatar_after']; // First Last Names: $first_last_name = ''; if ($Settings->get('firstname_editing') != 'hidden' && $User->get('firstname') != '') { $first_last_name .= $User->get('firstname'); } if ($Settings->get('lastname_editing') != 'hidden' && $User->get('lastname') != '') { $first_last_name .= ' ' . $User->get('lastname'); } $first_last_name = utf8_trim($first_last_name); if (!empty($first_last_name)) { // Display first last name of it is not empty echo '<h1>' . $first_last_name . '</h1>'; } // Nickname: if ($Settings->get('nickname_editing') != 'hidden' && $User->get('nickname') != '') { echo '<h2>' . $User->get('nickname') . '</h2>'; } // Login: echo '<h2 class="text-muted">' . $User->get('login') . '</h2>'; echo '<hr class="profile_separator" />' . "\n"; // Gender & age group: $gender_age_group = $User->get_gender(); if (!empty($User->age_min) || !empty($User->age_max)) { if (!empty($gender_age_group)) {
/** * UTF-8 aware replacement for trim() * * Strip whitespace (or other characters) from the beginning and end of a string. You only need to use this if you are supplying the charlist * optional arg and it contains UTF-8 characters. Otherwise trim will work normally on a UTF-8 string * * @param string $str The string to be trimmed * @param string $charlist The optional charlist of additional characters to trim * * @return string The trimmed string * * @see http://www.php.net/trim * @since 1.3.0 */ public static function trim($str, $charlist = false) { if (empty($charlist) && $charlist !== false) { return $str; } if ($charlist === false) { return utf8_trim($str); } return utf8_trim($str, $charlist); }
public static function getNormalizedTagText($tagText) { $tagText = utf8_trim($tagText); $tagText = utf8_strtolower($tagText); return $tagText; }
function processEditProjectForm() { global $manager; $id = $_POST['id']; $title = $_POST['title']; $slug = empty($_POST['slug']) ? $manager->clerk->simple_name($title) : $_POST['slug']; $oldSlug = $_POST['oldslug']; $now = getdate(); $date = mktime($now["hours"], $now["minutes"], $now["seconds"], $_POST["date_month"], $_POST["date_day"], $_POST["date_year"]); $tags = $_POST['tags']; $publish = $_POST['publish']; $paths = $manager->getSetting("projects_path"); $paths = array('path' => $paths['data1'], 'url' => $paths['data2']); if ($_POST['submit'] == "save") { if ($manager->clerk->query_countRows("projects", "WHERE slug= '{$slug}' AND id != '{$id}'") >= 1) { $manager->message(0, false, 'A project with the simple name/slug <em>"' . $slug . '"</em> already exists! Please choose a new one.'); return false; } if ($manager->clerk->query_edit("projects", "title= '{$title}', slug= '{$slug}', date= '{$date}', publish= '{$publish}'", "WHERE id= '{$id}'")) { $manager->message(1, false, "Project <em>{$title}</em> saved!"); // Handle tags... if (!empty($tags)) { $tags = explode(",", $tags); $total = count($tags); $manager->clerk->query_delete("projects_to_tags", "WHERE projectid= '{$id}'"); $count = 0; foreach ($tags as $c) { $count++; $query .= "('" . utf8_trim($c) . "', '{$id}')"; $query .= $count == $total ? "" : ", "; } $manager->clerk->query_insert("projects_to_tags", "tag, projectid", $query, true); } else { $manager->clerk->query_delete("projects_to_tags", "WHERE projectid= '{$id}'"); } // Handle renaming if ($slug != $oldSlug) { rename($paths['path'] . $oldSlug, $paths['path'] . $slug); } } else { $manager->message(0, true, "This project could not be saved!"); } } }
/** * @param string $string * @param int $maxLength * @param array $options * * @return string */ public static function snippet($string, $maxLength = 0, array $options = array()) { $options = array_merge(array('previewBreakBbCode' => 'prbreak', 'ellipsis' => '…'), $options); if (!empty($options['previewBreakBbCode']) && preg_match(sprintf('#\\[%1$s\\](?<preview>.*)\\[/%1$s\\]#', preg_quote($options['previewBreakBbCode'], '#')), $string, $matches, PREG_OFFSET_CAPTURE)) { // preview break bbcode found if (!empty($matches['preview'][0])) { // preview text specified, use it directly $string = $matches['preview'][0]; $maxLength = 0; } else { // use content before the found bbcode to continue $string = substr($string, 0, $matches[0][1]); $maxLength = 0; } } $snippet = XenForo_Template_Helper_Core::callHelper('snippet', array($string, $maxLength, $options)); // TODO: find better way to avoid having to call this $snippet = htmlspecialchars_decode($snippet); if ($maxLength == 0 || $maxLength > utf8_strlen($string)) { return $snippet; } $offset = 0; $stack = array(); while (true) { $startPos = utf8_strpos($snippet, '<', $offset); if ($startPos !== false) { $endPos = utf8_strpos($snippet, '>', $startPos); if ($endPos === false) { // we found a partial open tag, best to delete the whole thing $snippet = utf8_substr($snippet, 0, $startPos) . $options['ellipsis']; break; } $foundLength = $endPos - $startPos - 1; $found = utf8_substr($snippet, $startPos + 1, $foundLength); $offset = $endPos; if (preg_match('#^(?<closing>/?)(?<tag>\\w+)#', $found, $matches)) { $tag = $matches['tag']; $isClosing = !empty($matches['closing']); $isSelfClosing = !$isClosing && utf8_substr($found, $foundLength - 1, 1) === '/'; if ($isClosing) { $lastInStack = null; if (count($stack) > 0) { $lastInStack = array_pop($stack); } if ($lastInStack !== $tag) { // found tag does not match the one in stack $replacement = ''; // first we have to close the one in stack if ($lastInStack !== null) { $replacement .= sprintf('</%s>', $tag); } // then we have to self close the found tag $replacement .= utf8_substr($snippet, $startPos, $endPos - $startPos - 1); $replacement .= '/>'; // do the replacement $snippet = utf8_substr_replace($snippet, $replacement, $startPos, $endPos - $startPos); $offset = $startPos + utf8_strlen($snippet); } } elseif ($isSelfClosing) { // do nothing } else { // is opening tag $stack[] = $tag; } } } else { break; } } while (!empty($stack)) { $snippet .= sprintf('</%s>', array_pop($stack)); } $snippet = utf8_trim($snippet); if ($snippet === '') { // this is bad... // happens if the $maxLength is too low and for some reason the very first tag cannot finish $snippet = utf8_trim(strip_tags($string)); if ($snippet !== '') { $snippet = XenForo_Template_Helper_Core::callHelper('snippet', array($snippet, $maxLength, $options)); } else { // this is super bad... // the string is one big html tag and it is too damn long $snippet = $options['ellipsis']; } } return $snippet; }
/** * Return a search score for the given text and search keywords * * @param string Text to score * @param string The search keywords to score by * @param integer Score multiplier * @return integer Result score */ function score_tags($tag_name, $search_term, $score_weight = 4) { $score = 0.0; $scores_map = array(); if ($tag_name == utf8_trim($search_term)) { // We use only EXACT match for post tags: $score = $score_weight; $scores_map['tags'] = $score; } return array('score' => $score, 'score_weight' => $score_weight, 'map' => $scores_map); }
function substrs($content, $length, $add = 'Y') { if (strlen($content) > $length) { if ($GLOBALS['db_charset'] != 'utf-8') { $retstr = ''; for ($i = 0; $i < $length - 2; $i++) { $retstr .= ord($content[$i]) > 127 ? $content[$i] . $content[++$i] : $content[$i]; } return $retstr . ($add == 'Y' ? ' ..' : ''); } return utf8_trim(substr($content, 0, $length)) . ($add == 'Y' ? ' ..' : ''); } return $content; }
function mul_excerpt($excerpt) { $myexcerpt = substr($excerpt, 0, 255); return utf8_trim($myexcerpt) . '... '; }
function _parse_string(&$contents) { $lines =& preg_split("#\r\n|\r|\n#u", $contents); unset($contents); if ($lines === false) { debug::write_error("'{$this->file_path}' is empty", __FILE__ . ' : ' . __LINE__ . ' : ' . __FUNCTION__); return false; } $current_group = 'default'; if (count($lines) == 0) { return false; } // check for charset if (preg_match("/#charset[^=]*=(.+)/u", $lines[0], $match)) { $this->charset = utf8_trim($match[1]); } foreach ($lines as $line) { if (($line = utf8_trim($line)) == '') { continue; } // removing comments after #, not after # inside "" $line = preg_replace('/([^"#]+|"(.*?)")|(#[^#]*)/u', "\\1", $line); // check for new group if (preg_match("#^\\[(.+)\\]\\s*\$#u", $line, $new_group_name_array)) { $new_group_name = utf8_trim($new_group_name_array[1]); $current_group = $new_group_name; $this->group_values[$current_group] = array(); continue; } // check for variable if (preg_match("#^([a-zA-Z0-9_-]+)(\\[([a-zA-Z0-9_-]*)\\]){0,1}(\\s*)=(.*)\$#u", $line, $value_array)) { $var_name = utf8_trim($value_array[1]); $var_value = utf8_trim($value_array[5]); if (preg_match('/^"(.*)"$/u', $var_value, $m)) { $var_value = $m[1]; } if ($value_array[2]) { if ($value_array[3]) { $key_name = $value_array[3]; if (isset($this->group_values[$current_group][$var_name]) && is_array($this->group_values[$current_group][$var_name])) { $this->group_values[$current_group][$var_name][$key_name] = $var_value; } else { $this->group_values[$current_group][$var_name] = array($key_name => $var_value); } } else { if (isset($this->group_values[$current_group][$var_name]) && is_array($this->group_values[$current_group][$var_name])) { $this->group_values[$current_group][$var_name][] = $var_value; } else { $this->group_values[$current_group][$var_name] = array($var_value); } } } else { $this->group_values[$current_group][$var_name] = $var_value; } } } }
/** * UTF-8 aware replacement for trim() * Strip whitespace (or other characters) from the beginning and end of a string * Note: you only need to use this if you are supplying the charlist * optional arg and it contains UTF-8 characters. Otherwise trim will * work normally on a UTF-8 string * * @param string $str The string to be trimmed * @param string $charlist The optional charlist of additional characters to trim * * @return string The trimmed string * * @see http://www.php.net/trim * @since 2.0 */ public static function trim($str, $charlist = null) { if (empty($charlist) && $charlist !== null) { return $str; } if (!function_exists('utf8_trim')) { require_once __DIR__ . '/phputf8/trim.php'; } if ($charlist === null) { return utf8_trim($str); } return utf8_trim($str, $charlist); }
/** * 作用: 精确处理中文excerpt * 来源: 综合WP CN Excerpt和中文工具箱 * URL: http://yan.me/dia, http://weibo.com/joychaocc */ function apip_excerpt($text) { global $apip_options; //erase short codes $text = get_the_content(); $text = strip_shortcodes($text); $text = str_replace(']]>', ']]>', $text); $text = strip_tags($text); //return and spaces $search = array('/<br\\s*\\/?>/' => "\n", '/\\n\\n/' => "\n", '/ /i' => ''); $text = preg_replace(array_keys($search), $search, $text); if ($apip_options['excerpt_length'] > 0) { $len = $apip_options['excerpt_length']; } else { $len = 180; } $text = mb_substr($text, 0, $len, 'utf-8'); $text = utf8_trim($text) . $apip_options['excerpt_ellipsis']; return $text; }
/** * Restrict with keywords * * @param string Keyword search string * @param string Search for entire phrase or for individual words: 'OR', 'AND', 'sentence'(or '1') * @param string Require exact match of title or contents — does NOT apply to tags which are always an EXACT match * @param string Scope of keyword search string: 'title', 'content' */ function where_keywords($keywords, $phrase, $exact, $keyword_scope = 'title,content') { global $DB; $this->keywords = utf8_trim($keywords); $this->keyword_scope = $keyword_scope; $this->phrase = $phrase; $this->exact = $exact; if (empty($keywords)) { // Nothing to search, Exit here: return; } $search_sql = array(); // Determine what fields should be used in search: $search_fields = array(); $keyword_scopes = explode(',', $keyword_scope); foreach ($keyword_scopes as $keyword_scope) { switch ($keyword_scope) { case 'title': $search_fields[] = $this->dbprefix . 'title'; break; case 'content': $search_fields[] = $this->dbprefix . 'content'; break; case 'tags': $this->FROM_add('LEFT JOIN T_items__itemtag ON post_ID = itag_itm_ID'); $this->FROM_add('LEFT JOIN T_items__tag ON itag_tag_ID = tag_ID'); $this->GROUP_BY('post_ID'); // Tags are always an EXACT match: $search_sql[] = 'tag_name = ' . $DB->quote($keywords); break; // TODO: add more. } } if (empty($search_fields) && empty($search_sql)) { // No correct fields to search, Exit here: return; } // Set sql operator depending on parameter: if (in_array(strtolower($phrase), array('or', '1', 'sentence'))) { $operator_sql = 'OR'; } else { $operator_sql = 'AND'; } if (!empty($search_fields)) { // Do search if at least one field is requested: if ($exact) { // We want exact match of each search field: $mask = ''; } else { // The words/sentence are/is to be included in the each search field: $mask = '%'; } if ($phrase == '1' || $phrase == 'sentence') { // Sentence search: foreach ($search_fields as $search_field) { $search_sql[] = $search_field . ' LIKE ' . $DB->quote($mask . $keywords . $mask); } } else { // Word search: // Put spaces instead of commas: $keywords = preg_replace('/, +/', ',', $keywords); $keywords = utf8_trim(str_replace(array(',', '"'), ' ', $keywords)); // Split by each word: $keywords = preg_split('/\\s+/', $keywords); foreach ($keywords as $keyword) { $search_field_sql = array(); foreach ($search_fields as $search_field) { $search_field_sql[] = $search_field . ' LIKE ' . $DB->quote($mask . $keyword . $mask); } $search_sql[] = '( ' . implode(' OR ', $search_field_sql) . ' )'; } } } // Concat the searches: $search_sql = '( ' . implode(' ' . $operator_sql . ' ', $search_sql) . ' )'; $this->WHERE_and($search_sql); }
public function filterString($string, array $rendererStates) { $isString = true; if (is_array($string)) { // array is our way of marking tag originals prepend/append text $isString = false; $string = reset($string); } if ($isString) { // checks if the string is an URI of some kind $isString = !Zend_Uri::check($string); } if ($isString) { // checks if the parent tag has some strange requirements $tagDataStack = $rendererStates['tagDataStack']; $lastTagDataStack = array_pop($tagDataStack); if ($lastTagDataStack['tag'] === 'hashtag') { // well, this is a hashtag already... $isString = false; } else { $parentTagInfo = $this->_parent__getTagRule($lastTagDataStack['tag']); if (!empty($parentTagInfo['plainChildren'])) { // parent tag asks for plain children, we should do nothing $isString = false; } elseif (!empty($parentTagInfo['stopSmilies']) or !empty($parentTagInfo['stopLineBreakConversion'])) { // parent tag asks for some functionalities disabled, we should disable ourself // too $isString = false; } } } if ($isString) { $offset = 0; while (true) { $pos = utf8_strpos($string, '#', $offset); if ($pos === false) { break; } $offset = $pos + 1; if ($pos > 0) { $beforeTagText = utf8_substr($string, $pos - 1, 1); if (!preg_match(Tinhte_XenTag_Integration::REGEX_VALID_CHARACTER_AROUND, $beforeTagText)) { // the before character of tag text is not a valid character, dismiss the found // tag text continue; } } $stringForPregMatch = utf8_substr($string, $pos + 1); if (preg_match('/[^a-zA-Z0-9]/', $stringForPregMatch, $matches, PREG_OFFSET_CAPTURE)) { $nonTagTextPos = $matches[0][1]; } else { // get all of the remaining characters $nonTagTextPos = utf8_strlen($stringForPregMatch); } $nonTagTextPos += $pos + 1; $tagText = utf8_trim(utf8_substr($string, $pos + 1, $nonTagTextPos - 1 - $pos)); if (utf8_strlen($tagText) < Tinhte_XenTag_Option::get('tagMinLength')) { // too short continue; } $afterTagText = utf8_substr($string, $nonTagTextPos, 1); if (!empty($afterTagText)) { if (!preg_match(Tinhte_XenTag_Integration::REGEX_VALID_CHARACTER_AROUND, $afterTagText)) { // the after character of tag text is not a valid character, dismiss the found // tag text $tagText = ''; } } if (!empty($tagText)) { $this->_Tinhte_XenTag_autoHashtagTexts[Tinhte_XenTag_Helper::getSafeTagTextForSearch($tagText)] = $tagText; // add bb code wrapping $replacement = sprintf('[HASHTAG]#%s[/HASHTAG]', $tagText); $string = utf8_substr_replace($string, $replacement, $pos, $nonTagTextPos - $pos); $pos += utf8_strlen($replacement) - 1; } $offset = $pos + 1; } } return parent::filterString($string, $rendererStates); }
/** * UTF-8 aware replacement for trim() * Strip whitespace (or other characters) from the beginning and end of a string * Note: you only need to use this if you are supplying the charlist * optional arg and it contains UTF-8 characters. Otherwise trim will * work normally on a UTF-8 string * * @static * @access public * @param string the string to be trimmed * @param string the optional charlist of additional characters to trim * @return string the trimmed string * @see http://www.php.net/trim */ public static function trim($str, $charlist = FALSE) { jimport('phputf8.trim'); if ($charlist === FALSE) { return utf8_trim($str); } else { return utf8_trim($str, $charlist); } }
function pun_trim($str, $charlist = false) { return utf8_trim($str, $charlist); }
function forum_trim($str, $charlist = " \t\n\r\v ") { return utf8_trim(trim($str), $charlist); }
/** * UTF-8 aware replacement for trim() * Strip whitespace (or other characters) from the beginning and end of a string * Note: you only need to use this if you are supplying the charlist * optional arg and it contains UTF-8 characters. Otherwise trim will * work normally on a UTF-8 string * * @param string $str The string to be trimmed * @param string $charlist The optional charlist of additional characters to trim * * @return string The trimmed string * * @see http://www.php.net/trim * @since 1.0 */ public static function trim($str, $charlist = false) { if (empty($charlist) && $charlist !== false) { return $str; } require_once __DIR__ . '/phputf8/trim.php'; if ($charlist === false) { return utf8_trim($str); } return utf8_trim($str, $charlist); }
/** * UTF-8 aware replacement for trim() * Strip whitespace (or other characters) from the beginning and end of a string * Note: you only need to use this if you are supplying the charlist * optional arg and it contains UTF-8 characters. Otherwise trim will * work normally on a UTF-8 string * * @param string $str The string to be trimmed * @param string $charlist The optional charlist of additional characters to trim * * @return string The trimmed string * * @see http://www.php.net/trim * @since 11.1 */ public static function trim($str, $charlist = false) { if (empty($charlist) && $charlist !== false) { return $str; } jimport('phputf8.trim'); if ($charlist === false) { return utf8_trim($str); } else { return utf8_trim($str, $charlist); } }
function handle($match, $state, $pos, &$handler) { $result = array('entry' => '', 'data' => array($this->util->getIsaKey(false) => array(), $this->util->getTitleKey(false) => array())); // allow for preprocessing by a subclass $match = $this->preprocess($match, $state, $pos, $handler, $result); $lines = explode("\n", $match); $header = trim(array_shift($lines)); $footer = trim(array_pop($lines)); // allow subclasses to mangle header $header = $this->handleHeader($header, $result); // extract header, and match it to get classes and fragment preg_match('/^( +[^#>]+)?(?: *#([^>]*?))?$/', $header, $header); // process the classes into triples foreach (preg_split('/\\s+/', trim($header[1])) as $class) { if ($class == '') { continue; } $result['data'][$this->util->getIsaKey(false)][] = array('value' => $class, 'type' => 'text', 'hint' => null); } // process the fragment if necessary $result['entry'] = $header[2]; $result['position'] = $pos; if ($result['entry'] != '') { $result['title candidate'] = array('value' => $result['entry'], 'type' => 'text', 'hint' => null); } // parse tree $tree = $this->syntax->constructTree($lines, 'data entry'); // allow subclasses first pick in the tree $this->handleBody($tree, $result); // fetch all lines $lines = $this->syntax->extractText($tree); // sanity check if (count($tree['cs'])) { msg(sprintf($this->syntax->getLang('error_entry_block'), $tree['cs'][0]['tag'] ? sprintf($this->syntax->getLang('named_group'), utf8_tohtml(hsc($tree['cs'][0]['tag']))) : $this->syntax->getLang('unnamed_group'), utf8_tohtml(hsc($result['entry']))), -1); return array(); } $p = $this->syntax->getPatterns(); // now handle all lines foreach ($lines as $line) { $line = $line['text']; // match a "property_type(hint)*: value" pattern // (the * is only used to indicate that the value is actually a comma-seperated list) // [grammar] ENTRY := PREDICATE TYPE? '*'? ':' ANY if (preg_match("/^({$p->predicate})\\s*({$p->type})?\\s*(\\*)?\\s*:\\s*({$p->any}?)\$/", $line, $parts)) { // assign useful names list(, $property, $ptype, $multi, $values) = $parts; list($type, $hint) = $p->type($ptype); // trim property so we don't get accidental 'name ' keys $property = utf8_trim($property); // lazy create key bucket if (!isset($result['data'][$property])) { $result['data'][$property] = array(); } // determine values, splitting on commas if necessary $values = $multi == '*' ? explode(',', $values) : array($values); // generate triples from the values foreach ($values as $v) { $v = utf8_trim($v); if ($v == '') { continue; } // replace the [[]] quasi-magic token with the empty string if ($v == '[[]]') { $v = ''; } if (!isset($type) || $type == '') { list($type, $hint) = $this->util->getDefaultType(); } $result['data'][$property][] = array('value' => $v, 'type' => $type, 'hint' => $hint ?: null); } } else { msg(sprintf($this->syntax->getLang('error_entry_line'), utf8_tohtml(hsc($line))), -1); } } // normalize data: // - Normalize all values $buckets = $result['data']; $result['data'] = array(); foreach ($buckets as $property => &$bucket) { // normalize the predicate $property = $this->util->normalizePredicate($property); // process all triples foreach ($bucket as &$triple) { // normalize the value $type = $this->util->loadType($triple['type']); $triple['value'] = $type->normalize($triple['value'], $triple['hint']); // lazy create property bucket if (!isset($result['data'][$property])) { $result['data'][$property] = array(); } $result['data'][$property][] = $triple; } } // normalize title candidate if (!empty($result['title candidate'])) { $type = $this->util->loadType($result['title candidate']['type']); $result['title candidate']['value'] = $type->normalize($result['title candidate']['value'], $result['title candidate']['hint']); } $footer = $this->handleFooter($footer, $result); return $result; }
public static function trim($str, $charlist = false) { return is_string($str) ? utf8_trim($str, $charlist) : ''; }
public function renderWidgetsFor($templateName, array $params, XenForo_Template_Abstract $template, array &$containerData) { if ($this->_isIgnoredTemplate($templateName, $params)) { return false; } $originalHtml = isset($containerData['sidebar']) ? $containerData['sidebar'] : ''; $html = $this->_renderWidgetsFor($templateName, array_merge($params, array(self::PARAM_POSITION_CODE => $templateName)), $template, $originalHtml); if (defined(self::NO_VISITOR_PANEL_FLAG)) { // the flag is used to avoid string searching as much as possible // the string search is also required to confirm the noVisitorPanel request $count = 0; $html = str_replace(self::NO_VISITOR_PANEL_MARKUP, '', $html, $count); if ($count > 0) { $containerData['noVisitorPanel'] = true; } } if ($html != $originalHtml) { $containerData['sidebar'] = utf8_trim($html); if (!empty($containerData['sidebar']) and self::debugMode()) { $containerData['sidebar'] .= sprintf('<div>Widget Framework is in debug mode<br/>Renderers: %d<br/>Widgets: %d<br/></div>', count($this->_renderers), $this->_widgetCount); } } return true; }