function add(&$site_object)
 {
     $indexer =& indexer::instance();
     $indexer->remove($site_object);
     $index_array = array();
     $index_array_only_words = array();
     $attributes =& $site_object->export_attributes();
     $keys = array_keys($attributes);
     foreach ($keys as $attribute_name) {
         $definition = $site_object->get_attribute_definition($attribute_name);
         if (!isset($definition['search']) || !$definition['search']) {
             continue;
         }
         $text =& indexer::normalize_string($attributes[$attribute_name]);
         $words_array =& utf8_explode(' ', $text);
         for ($i = 0, $j = 1, $max_count = 1000; $i < sizeof($words_array); $i++) {
             if (!($word = utf8_trim($words_array[$i]))) {
                 continue;
             }
             $index_array_only_words[] = $word;
             if ($i > $j * $max_count || $i == sizeof($words_array) - 1) {
                 $index_array_only_words =& array_values(array_unique($index_array_only_words));
                 $indexer->_update_db($site_object, $index_array_only_words, $attribute_name);
                 $j++;
                 $index_array = array();
                 $index_array_only_words = array();
             }
         }
     }
 }
function add_url_query_items($url, $items = array())
{
    $str_params = '';
    $request = request::instance();
    if (($node_id = $request->get_attribute('node_id')) && !isset($items['node_id'])) {
        $items['node_id'] = $node_id;
    }
    if (utf8_strpos($url, '?') === false) {
        $url .= '?';
    }
    foreach ($items as $key => $val) {
        $url = preg_replace("/&*{$key}=[^&]*/u", '', $url);
        $str_params .= "&{$key}={$val}";
    }
    $items = utf8_explode('#', $url);
    $url = $items[0];
    $fragment = isset($items[1]) ? '#' . $items[1] : '';
    return $url . $str_params . $fragment;
}
/**
 * This is an Unicode aware replacement for strpos
 *
 * Uses mb_string extension if available
 *
 * @author Harry Fuecks <*****@*****.**>
 * @see    strpos()
 */
function utf8_strpos($haystack, $needle, $offset = 0)
{
    if (!defined('UTF8_NOMBSTRING') && function_exists('mb_strpos')) {
        return mb_strpos($haystack, $needle, $offset, 'utf-8');
    }
    if (!$offset) {
        $ar = utf8_explode($needle, $str);
        if (count($ar) > 1) {
            return utf8_strlen($ar[0]);
        }
        return false;
    } else {
        if (!is_int($offset)) {
            trigger_error('Offset must be an integer', E_USER_WARNING);
            return false;
        }
        $str = utf8_substr($str, $offset);
        if (false !== ($pos = utf8_strpos($str, $needle))) {
            return $pos + $offset;
        }
        return false;
    }
}
 function get_line_number()
 {
     static $lineno = 0;
     static $index = 0;
     static $text = null;
     static $lines;
     if (is_null($text)) {
         $text = utf8_explode("\n", $this->rawtext);
         $lines = count($text);
     }
     for (; $lineno < $lines; $lineno++) {
         $index += utf8_strlen($text[$lineno]);
         if ($index > $this->cur_byte_index) {
             return $lineno + 1;
         }
     }
     return $lineno;
 }
示例#5
0
 function clean_path($path, $to_type = DIR_SEPARATOR_LOCAL)
 {
     $path = fs::convert_separators($path, $to_type);
     $separator = fs::separator($to_type);
     $path = fs::_normalize_separators($path, $separator);
     $path_elements = utf8_explode($separator, $path);
     $newpath_elements = array();
     foreach ($path_elements as $path_element) {
         if ($path_element == '.') {
             continue;
         }
         if ($path_element == '..' && count($newpath_elements) > 0) {
             array_pop($newpath_elements);
         } else {
             $newpath_elements[] = $path_element;
         }
     }
     if (count($newpath_elements) == 0) {
         $newpath_elements[] = '.';
     }
     $path = implode($separator, $newpath_elements);
     return $path;
 }
 function utf8_explode($sep, $str)
 {
     return utf8_explode($sep, $str);
 }