/** * Make a string lower case * * @param string $str String * * @return string */ public static function strtolower($str) { return self::$instance->strtolower($str); }
/** * Filter some text cutting out all non words and stop words * * @param string $input text to filter * * @return string */ public function clean($input) { $words = explode(' ', ereg_replace('[[:punct:][:space:]]+', ' ', $input)); $stop_words = $this->getByLang(null, true); $retval = array(); foreach ($words as $word) { $word = PMF_String::strtolower($word); if (!is_numeric($word) && 1 < PMF_String::strlen($word) && !in_array($word, $stop_words) && !in_array($word, $retval)) { $retval[] = $word; } } return $retval; }
/** * This function checks the content against a bad word list if the banned * word spam protection has been activated from the general phpMyFAQ * configuration. * * @param string $content * * @return bool */ public function checkBannedWord($content) { // Sanity checks $content = PMF_String::strtolower(trim($content)); if ('' === $content || !$this->_config->get('spam.checkBannedWords')) { return true; } // Check if we check more than one word $checkWords = explode(' ', $content); if (1 === count($checkWords)) { $checkWords = array($content); } $bannedWords = $this->getBannedWords(); // We just search a match of, at least, one banned word into $content if (is_array($bannedWords)) { foreach ($bannedWords as $bannedWord) { foreach ($checkWords as $word) { if (PMF_String::strtolower($word) === PMF_String::strtolower($bannedWord)) { return false; } } } } return true; }
/** * This function checks the content against a dab word list * if the banned word spam protection has been activated from the general PMF configuration. * * @param string $content * @return bool * @access public * @author Katherine A. Bouton * @author Thorsten Rinne <*****@*****.**> * @author Matteo Scaramuccia <*****@*****.**> * @author Peter Beauvain <*****@*****.**> */ function checkBannedWord($content) { // Sanity checks $content = trim($content); if ('' == $content && !PMF_Configuration::getInstance()->get('spam.checkBannedWords')) { return true; } $bannedWords = getBannedWords(); // We just search a match of, at least, one banned word into $content $content = PMF_String::strtolower($content); if (is_array($bannedWords)) { foreach ($bannedWords as $bannedWord) { if (PMF_String::strpos($content, PMF_String::strtolower($bannedWord)) !== false) { return false; } } } return true; }
/** * Returns a search engine optimized title * * @param string $title * * @return string */ public function getSEOItemTitle($title = '') { if ('' === $title) { $title = $this->itemTitle; } $itemTitle = trim($title); // Lower the case (aesthetic) $itemTitle = PMF_String::strtolower($itemTitle); // Use '_' for some other characters for: // 1. avoiding regexp match break; // 2. improving the reading. $itemTitle = str_replace(array('-', "'", '/', '''), '_', $itemTitle); // 1. Remove any CR LF sequence // 2. Use a '-' for the words separation $itemTitle = PMF_String::preg_replace('/\\s/m', '-', $itemTitle); // Hack: remove some chars for having a better readable title $itemTitle = str_replace(array('+', ',', ';', ':', '.', '?', '!', '"', '(', ')', '[', ']', '{', '}', '<', '>'), '', $itemTitle); // Hack: move some chars to "similar" but plain ASCII chars $itemTitle = str_replace(array('à', 'è', 'é', 'ì', 'ò', 'ù', 'ä', 'ö', 'ü', 'ß', 'Ä', 'Ö', 'Ü', 'č', 'ę', 'ė', 'į', 'š', 'ų', 'ū', 'ž'), array('a', 'e', 'e', 'i', 'o', 'u', 'ae', 'oe', 'ue', 'ss', 'Ae', 'Oe', 'Ue', 'c', 'e', 'e', 'i', 's', 'u', 'u', 'z'), $itemTitle); // Clean up $itemTitle = PMF_String::preg_replace('/-[\\-]+/m', '-', $itemTitle); return rawurlencode($itemTitle); }
/** * Saves all tags from a FAQ record * * @param integer $record_id Record ID * @param array $tags Array of tags */ public function saveTags($record_id, $tags) { if (!is_array($tags)) { return false; } $current_tags = $this->getAllTags(); // Delete all tag references for the faq record if (count($tags) > 0) { $this->deleteTagsFromRecordId($record_id); } // Store tags and references for the faq record foreach ($tags as $tagging_name) { $tagging_name = trim($tagging_name); if (PMF_String::strlen($tagging_name) > 0) { if (!in_array(PMF_String::strtolower($tagging_name), array_map(array('PMF_String', 'strtolower'), $current_tags))) { // Create the new tag $new_tagging_id = $this->db->nextID(SQLPREFIX . 'faqtags', 'tagging_id'); $query = sprintf("\n INSERT INTO\n %sfaqtags\n (tagging_id, tagging_name)\n VALUES\n (%d, '%s')", SQLPREFIX, $new_tagging_id, $tagging_name); $this->db->query($query); // Add the tag reference for the faq record $query = sprintf("\n INSERT INTO\n %sfaqdata_tags\n (record_id, tagging_id)\n VALUES\n (%d, %d)", SQLPREFIX, $record_id, $new_tagging_id); $this->db->query($query); } else { // Add the tag reference for the faq record $query = sprintf("\n INSERT INTO\n %sfaqdata_tags\n (record_id, tagging_id)\n VALUES\n (%d, %d)", SQLPREFIX, $record_id, array_search(PMF_String::strtolower($tagging_name), array_map(array('PMF_String', 'strtolower'), $current_tags))); $this->db->query($query); } } } return true; }
/** * Decode a given ACE domain name * @param string Domain name (ACE string) * [@param string Desired output encoding, see {@link set_parameter}] * @return string Decoded Domain name (UTF-8 or UCS-4) */ public function decode($input, $one_time_encoding = false) { // Optionally set if ($one_time_encoding) { switch ($one_time_encoding) { case 'utf8': case 'ucs4_string': case 'ucs4_array': break; default: $this->_error('Unknown encoding ' . $one_time_encoding); return false; } } // Make sure to drop any newline characters around $input = trim($input); // Negotiate input and try to determine, whether it is a plain string, // an email address or something like a complete URL if (PMF_String::strpos($input, '@')) { // Maybe it is an email address // No no in strict mode if ($this->_strict_mode) { $this->_error('Only simple domain name parts can be handled in strict mode'); return false; } list($email_pref, $input) = explode('@', $input, 2); $arr = explode('.', $input); foreach ($arr as $k => $v) { if (PMF_String::preg_match('!^' . preg_quote($this->_punycode_prefix, '!') . '!', $v)) { $conv = $this->_decode($v); if ($conv) { $arr[$k] = $conv; } } } $input = join('.', $arr); $arr = explode('.', $email_pref); foreach ($arr as $k => $v) { if (PMF_String::preg_match('!^' . preg_quote($this->_punycode_prefix, '!') . '!', $v)) { $conv = $this->_decode($v); if ($conv) { $arr[$k] = $conv; } } } $email_pref = join('.', $arr); $return = $email_pref . '@' . $input; } elseif (PMF_String::preg_match('![:\\./]!', $input)) { // Or a complete domain name (with or without paths / parameters) // No no in strict mode if ($this->_strict_mode) { $this->_error('Only simple domain name parts can be handled in strict mode'); return false; } $parsed = parse_url($input); if (isset($parsed['host'])) { $arr = explode('.', $parsed['host']); foreach ($arr as $k => $v) { $conv = $this->_decode($v); if ($conv) { $arr[$k] = $conv; } } $parsed['host'] = join('.', $arr); $return = (empty($parsed['scheme']) ? '' : $parsed['scheme'] . (PMF_String::strtolower($parsed['scheme']) == 'mailto' ? ':' : '://')) . (empty($parsed['user']) ? '' : $parsed['user'] . (empty($parsed['pass']) ? '' : ':' . $parsed['pass']) . '@') . $parsed['host'] . (empty($parsed['port']) ? '' : ':' . $parsed['port']) . (empty($parsed['path']) ? '' : $parsed['path']) . (empty($parsed['query']) ? '' : '?' . $parsed['query']) . (empty($parsed['fragment']) ? '' : '#' . $parsed['fragment']); } else { // parse_url seems to have failed, try without it $arr = explode('.', $input); foreach ($arr as $k => $v) { $conv = $this->_decode($v); $arr[$k] = $conv ? $conv : $v; } $return = join('.', $arr); } } else { // Otherwise we consider it being a pure domain name string $return = $this->_decode($input); if (!$return) { $return = $input; } } // The output is UTF-8 by default, other output formats need conversion here // If one time encoding is given, use this, else the objects property switch ($one_time_encoding ? $one_time_encoding : $this->_api_encoding) { case 'utf8': return $return; break; case 'ucs4_string': return $this->_ucs4_to_ucs4_string($this->_utf8_to_ucs4($return)); break; case 'ucs4_array': return $this->_utf8_to_ucs4($return); break; default: $this->_error('Unsupported output format'); return false; } }