Exemplo n.º 1
0
 /**
  * Scanning of aliases for defining of current language
  *
  * @param array			$active_languages
  *
  * @return bool|string
  */
 protected function scan_aliases($active_languages)
 {
     if (!isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
         return false;
     }
     $Cache = Cache::instance();
     if (($aliases = $Cache->{'languages/aliases'}) === false) {
         $aliases = [];
         $aliases_list = _strtolower(get_files_list(LANGUAGES . '/aliases'));
         foreach ($aliases_list as $alias) {
             $aliases[$alias] = file_get_contents(LANGUAGES . "/aliases/{$alias}");
         }
         unset($aliases_list, $alias);
         $Cache->{'languages/aliases'} = $aliases;
     }
     $accept_languages = str_replace('-', '_', explode(',', strtolower($_SERVER['HTTP_ACCEPT_LANGUAGE'])));
     foreach (_strtolower($_SERVER) as $i => $v) {
         if (preg_match('/.*locale/i', $i)) {
             $accept_languages[] = strtolower($v);
         }
     }
     unset($i, $v);
     foreach ($accept_languages as $language) {
         $language = explode(';', $language, 2)[0];
         if (isset($aliases[$language]) && in_array($aliases[$language], $active_languages)) {
             return $aliases[$language];
         }
     }
     return false;
 }
Exemplo n.º 2
0
 public function test_cases()
 {
     $sentence = 'пользователь должен быть у Вас в друзьях а Вы у него';
     $this->assertEquals('ПОЛЬЗОВАТЕЛЬ ДОЛЖЕН БЫТЬ У ВАС В ДРУЗЬЯХ А ВЫ У НЕГО', trim(_strtoupper($sentence)));
     $this->assertEquals('пользователь должен быть у вас в друзьях а вы у него', trim(_strtolower($sentence)));
     $this->assertNotEquals(strtoupper($sentence), _strtoupper($sentence));
     $this->assertNotEquals(strtolower($sentence), _strtolower($sentence));
     $this->assertNotEquals(ucfirst($sentence), _ucfirst($sentence));
     $this->assertNotEquals(ucwords($sentence), _ucwords($sentence));
 }
Exemplo n.º 3
0
 /**
  */
 function prepare_str($string)
 {
     $patrn = "/([\\[\\}\\]\\{\\%\"\\'\\<\\>\\~\\!\\@\\#\$\\%\\&\\*\\(\\)\\s\\-\\_\\:\\;\\+\\=\\|\\?\\№\\.\\/\\^\\,])+/iu";
     $patrn2 = ["<", ">"];
     $string = str_replace($patrn2, "", $string);
     $string = _strtolower(trim($string));
     $string = preg_replace($patrn, ",", $string);
     $string = trim($string, ",");
     $str_search = explode(",", $string);
     $rezult = $this->search_fast($str_search);
     return $rezult;
 }
Exemplo n.º 4
0
 /**
  * AJAX-based method save current locale variable
  */
 function save_locale_var()
 {
     no_graphics(true);
     if (!DEBUG_MODE && !$_SESSION['locale_vars_edit']) {
         return print 'Access denied';
     }
     $SOURCE_VAR_NAME = str_replace('%20', ' ', trim($_POST['source_var']));
     $EDITED_VALUE = str_replace('%20', ' ', trim($_POST['edited_value']));
     $CUR_LOCALE = conf('language');
     // First we need to check if such var exists
     if (!strlen($SOURCE_VAR_NAME)) {
         return print 'Empty source var';
     }
     if (!strlen($EDITED_VALUE)) {
         return print 'Empty edited value';
     }
     if ($this->_parent->VARS_IGNORE_CASE) {
         $SOURCE_VAR_NAME = str_replace(' ', '_', _strtolower($SOURCE_VAR_NAME));
         $sql = "SELECT * FROM " . db('locale_vars') . " WHERE REPLACE(CONVERT(value USING utf8), ' ', '_') = '" . _es($SOURCE_VAR_NAME) . "'";
     } else {
         $sql = "SELECT * FROM " . db('locale_vars') . " WHERE value='" . _es($SOURCE_VAR_NAME) . "'";
     }
     $var_info = db()->query_fetch($sql);
     // Create variable record if not found
     if (empty($var_info['id'])) {
         $sql = ['value' => _es($SOURCE_VAR_NAME)];
         db()->INSERT('locale_vars', $sql);
         $var_info['id'] = db()->INSERT_ID();
     }
     $sql_data = ['var_id' => intval($var_info['id']), 'value' => _es($EDITED_VALUE), 'locale' => _es($CUR_LOCALE)];
     // Check if record is already exists
     $Q = db()->query('SELECT * FROM ' . db('locale_translate') . ' WHERE var_id=' . intval($var_info['id']));
     while ($A = db()->fetch_assoc($Q)) {
         $var_tr[$A['locale']] = $A['value'];
     }
     if (isset($var_tr[$CUR_LOCALE])) {
         db()->UPDATE('locale_translate', $sql_data, 'var_id=' . intval($var_info['id']) . " AND locale='" . _es($CUR_LOCALE) . "'");
     } else {
         db()->INSERT('locale_translate', $sql_data);
     }
     $sql = db()->UPDATE('locale_translate', $sql_data, 'var_id=' . intval($var_info['id']) . " AND locale='" . _es($CUR_LOCALE) . "'", true);
     db()->INSERT('revisions', ['user_id' => intval(MAIN_TYPE_USER ? main()->USER_ID : main()->ADMIN_ID), 'object_name' => _es('locale_var'), 'object_id' => _es($var_info['id']), 'old_text' => _es($var_tr[$CUR_LOCALE]), 'new_text' => _es($EDITED_VALUE), 'date' => time(), 'ip' => common()->get_ip(), 'comment' => _es('locale: ' . $CUR_LOCALE)]);
     cache_del('locale_translate_' . $CUR_LOCALE);
     return print 'Save OK';
 }
Exemplo n.º 5
0
 /**
  * Makes a UTF-8 string lowercase. This is a UTF8-aware version
  * of [strtolower](http://php.net/strtolower).
  *
  *     $str = UTF8::strtolower($str);
  *
  * @author  Andreas Gohr <*****@*****.**>
  * @param   string   mixed case string
  * @return  string
  * @uses    UTF8::$server_utf8
  */
 public static function strtolower($str)
 {
     if (UTF8::$server_utf8) {
         return mb_strtolower($str, Kohana::$charset);
     }
     if (!isset(self::$called[__FUNCTION__])) {
         require SYSPATH . 'utf8' . DIRECTORY_SEPARATOR . __FUNCTION__ . EXT;
         // Function has been called
         self::$called[__FUNCTION__] = TRUE;
     }
     return _strtolower($str);
 }
Exemplo n.º 6
0
/**
 * Takes all the relevant sql results and scores them to find the most likely match with the aiml
 *
 * @param array  $convoArr
 * @param array  $allrows
 * @param string $pattern
 * @internal param int $bot_parent_id
 * @internal param string $current_thatpattern
 * @internal param string $current_topic
 * @return array
 **/
function score_matches($convoArr, $allrows, $pattern)
{
    global $common_words_array;
    runDebug(__FILE__, __FUNCTION__, __LINE__, "Scoring the matches.", 4);
    # obtain some values to test
    $topic = get_topic($convoArr);
    $that = isset($convoArr['that'][1][1]) ? $convoArr['that'][1][1] : '';
    $default_pattern = $convoArr['conversation']['default_aiml_pattern'];
    $bot_parent_id = $convoArr['conversation']['bot_parent_id'];
    $bot_id = $convoArr['conversation']['bot_id'];
    # set the scores for each type of word or sentence to be used in this function
    # full pattern match scores:
    $this_bot_match = 250;
    $underscore_match = 100;
    $topic_underscore_match = 80;
    $topic_direct_match = 50;
    $topic_star_match = 10;
    $thatpattern_underscore_match = 45;
    $thatpattern_direct_match = 15;
    $thatpattern_star_match = 2;
    $direct_pattern_match = 10;
    $pattern_direct_match = 7;
    $pattern_star_match = 1;
    $default_pattern_match = 5;
    # individual word match scores:
    $uncommon_word_match = 8;
    $common_word_match = 1;
    $direct_word_match = 2;
    $underscore_word_match = 25;
    $star_word_match = 1;
    $rejected = -1000;
    # loop through all relevant results
    foreach ($allrows as $all => $subrow) {
        $category_bot_id = isset($subrow['bot_id']) ? $subrow['bot_id'] : 1;
        $category_topic = $subrow['topic'];
        $category_thatpattern = $subrow['thatpattern'];
        $category_pattern = $subrow['pattern'];
        $check_pattern_words = true;
        # make it all lower case, to make it easier to test, and do it using mbstring functions if possible
        $category_pattern_lc = _strtolower($category_pattern);
        $category_thatpattern_lc = _strtolower($category_thatpattern);
        $category_topic_lc = _strtolower($category_topic);
        $default_pattern_lc = _strtolower($default_pattern);
        $pattern_lc = _strtolower($pattern);
        $topic_lc = _strtolower($topic);
        $that_lc = _strtolower($that);
        // Start scoring here
        $current_score = 0;
        $track_matches = '';
        # 1.) Check for current bot, rather than parent
        if ($category_bot_id == $bot_id) {
            $current_score += $this_bot_match;
            $track_matches .= 'current bot, ';
        } elseif ($category_bot_id == $bot_parent_id) {
            $current_score += 0;
            $track_matches .= 'parent bot, ';
        } else {
            $current_score = $rejected;
            runDebug(__FILE__, __FUNCTION__, __LINE__, 'Found an error trying to identify the chatbot.', 1);
            unset($allrows[$all]);
            continue;
        }
        # 2.) test for a non-empty  current topic
        if (!empty($topic)) {
            # 2a.) test for a non-empty topic in the current category
            if (empty($category_topic) || $category_topic == '*') {
                // take no action, as we're not looking for a topic here
                $track_matches .= 'no topic to match, ';
            } else {
                # 2b.) create a RegEx to test for underscore matches
                if (strpos($category_topic, '_') !== false) {
                    $regEx = str_replace('_', '(.*)', $category_topic);
                    if ($regEx != $category_topic && preg_match("/{$regEx}/", $topic) === 1) {
                        $current_score += $topic_underscore_match;
                        $track_matches .= 'topic match with underscore, ';
                    }
                } elseif ($topic == $category_topic) {
                    $current_score += $topic_direct_match;
                    $track_matches .= 'direct topic match, ';
                } else {
                    $regEx = str_replace(array('*', '_'), '(.*)', $category_topic);
                    if (preg_match("/{$regEx}/", $topic)) {
                        $current_score += $topic_star_match;
                        $track_matches .= 'topic match with wildcards';
                    }
                }
            }
        }
        # end topic testing
        # 3.) test for a category thatpattern
        if (empty($category_thatpattern) || $category_thatpattern == '*') {
            $current_score += 1;
            $track_matches .= 'no thatpattern to match, ';
        } else {
            if (strpos($category_thatpattern, '_') !== false) {
                # 3a.) Create a RegEx to search for underscore wildcards
                $regEx = str_replace('_', '(.*)', $category_thatpattern);
                if ($regEx !== $category_thatpattern && preg_match("/{$regEx}/i", $that) === 1) {
                    $current_score += $thatpattern_underscore_match;
                    $track_matches .= 'thatpattern match with underscore, ';
                }
            } elseif ($that_lc == $category_thatpattern_lc) {
                $current_score += $thatpattern_direct_match;
                $track_matches .= 'direct thatpattern match, ';
            } elseif (strstr($category_thatpattern_lc, '*') !== false) {
                $regEx = str_replace(array('*', '_'), '(.*)', $category_thatpattern);
                if (preg_match("/{$regEx}/", $that)) {
                    $current_score += $thatpattern_star_match;
                    $track_matches .= 'thatpattern match with star, ';
                }
            } else {
                $current_score = $rejected;
                $track_matches .= 'no thatpattern match at all, ';
                runDebug(__FILE__, __FUNCTION__, __LINE__, "Matching '{$that_lc}' with '{$category_thatpattern_lc}' failed. Drat!'", 4);
            }
        }
        # end thatpattern testing
        # 4.) pattern testing
        # 4a.) Create a RegEx to search for underscore wildcards
        if (strpos($category_pattern, '_') !== false) {
            $regEx = str_replace('_', '(.*)', $category_pattern);
            //save_file(_LOG_PATH_ . 'regex.txt', "$regEx\n", true);
            if ($regEx != $category_pattern && preg_match("/{$regEx}/", $pattern) === 1) {
                $current_score += $underscore_match;
                $track_matches .= 'pattern match with underscore, ';
            }
        } elseif ($pattern == $category_pattern) {
            $current_score += $pattern_direct_match;
            $track_matches .= 'direct pattern match, ';
            //$check_pattern_words  = false;
        } else {
            $regEx = str_replace(array('*', '_'), '(.*?)', $category_pattern);
            if ($category_pattern == '*') {
                $current_score += $pattern_star_match;
                $track_matches .= 'pattern star match, ';
                $check_pattern_words = false;
            } elseif ($regEx != $category_pattern && ($category_pattern != '*' || $category_pattern != '_') && preg_match("/{$regEx}/", $pattern) != 0) {
            }
        }
        # end pattern testing
        # 4d.) See if the current category is the default category
        if ($category_pattern == $default_pattern_lc) {
            runDebug(__FILE__, __FUNCTION__, __LINE__, 'This category is the default pattern!', 4);
            $current_score += $default_pattern_match;
            $track_matches .= 'default pattern match, ';
            $check_pattern_words = false;
        }
        #5.) check to see if we need to score word by word
        if ($check_pattern_words && $category_pattern_lc != $default_pattern_lc) {
            # 5a.) first, a little setup
            $pattern_lc = _strtolower($pattern);
            $category_pattern_lc = _strtolower($category_pattern);
            $pattern_words = explode(" ", $pattern_lc);
            # 5b.) break the input pattern into an array of individual words and iterate through the array
            $category_pattern_words = explode(" ", $category_pattern_lc);
            foreach ($category_pattern_words as $word) {
                $word = trim($word);
                switch (true) {
                    case $word === '_':
                        $current_score += $underscore_word_match;
                        $track_matches .= 'underscore word match, ';
                        break;
                    case $word === '*':
                        $current_score += $star_word_match;
                        $track_matches .= 'star word match, ';
                        break;
                    case in_array($word, $pattern_words):
                        $current_score += $direct_word_match;
                        $track_matches .= "direct word match: {$word}, ";
                        break;
                    case in_array($word, $common_words_array):
                        $current_score += $common_word_match;
                        $track_matches .= "common word match: {$word}, ";
                        break;
                    default:
                        $current_score += $uncommon_word_match;
                        $track_matches .= "uncommon word match: {$word}, ";
                }
            }
        }
        $allrows[$all]['score'] += $current_score;
        $allrows[$all]['track_score'] = rtrim($track_matches, ', ');
    }
    //runDebug(__FILE__, __FUNCTION__, __LINE__, "Unsorted array \$allrows:\n" . print_r($allrows, true), 4);
    $allrows = sort2DArray("show top scoring aiml matches", $allrows, "score", 1, 10);
    runDebug(__FILE__, __FUNCTION__, __LINE__, "Sorted array \$allrows:\n" . print_r($allrows, true), 4);
    return $allrows;
}
Exemplo n.º 7
0
 public static function strtolower($str)
 {
     if (UTF8::$server_utf8) {
         return mb_strtolower($str, JsonApiApplication::$charset);
     }
     if (!isset(UTF8::$called[__FUNCTION__])) {
         require JsonApiApplication::find_file("utf8", __FUNCTION__);
         // Function has been called
         UTF8::$called[__FUNCTION__] = TRUE;
     }
     return _strtolower($str);
 }
Exemplo n.º 8
0
 /**
  * Makes a UTF-8 string lowercase.
  * @see http://php.net/strtolower
  *
  * @author  Andreas Gohr <*****@*****.**>
  *
  * @param   string   mixed case string
  * @return  string
  */
 public static function strtolower($str)
 {
     require_once dirname(__FILE__) . '/' . __FUNCTION__ . '.php';
     return _strtolower($str);
 }
Exemplo n.º 9
0
 /**
  * Translation of the given string
  *
  * Some common symbol codes in HTML:
  *	_ => '&#95;'
  *	' => '&prime;' or '&#39;'
  *	' => '&quot;'
  *	/ => '&frasl;'
  *	\ => '&#92;'
  *	[ => '&#91;'
  *	] => '&#93;'
  *	( => '&#40;'
  *	) => '&#41;'
  *	{ => '&#123;'
  *	} => '&#125;'
  *	? => '&#63;'
  *	! => '&#33;'
  *	| => '&#124;'
  *
  * @code
  *	$msg = t('You must log in below or <a href="%url">create a new account</a> before viewing the next page.',
  *			array('%url' => process_url('./?object=user&action=register')));
  * @endcode
  *
  * We have ability to use custom prefix for vars with same names in different places with different translations
  * ex. for var "welcome" we can have several vars with prefixes  "::forum::welcome"
  * Prefix syntax:	 "::[a-z_-]::text to tranlate here"
  *
  * @access	public
  * @param	$string string	Text to translate
  * @param	$args	array	Optional array of items to replace after translation
  * @return string Translation result
  */
 function translate_string($input_string, $args = 0, $lang = '')
 {
     if (DEBUG_MODE) {
         $_start_time = microtime(true);
     }
     $lang = strval($lang);
     if (!$lang) {
         $lang = $this->_get_current_lang();
     }
     if (!isset($this->_loaded[$lang])) {
         $this->_load_lang($lang);
     }
     if (!$lang || !$this->_loaded[$lang]) {
         return $input_string;
     }
     if (is_array($args) && isset($args[''])) {
         unset($args['']);
     }
     if (is_array($input_string)) {
         foreach ((array) $input_string as $k => $v) {
             $input_string[$k] = $this->translate_string($v, $args, $lang);
         }
         return $input_string;
     }
     if (!$input_string) {
         return $input_string;
     }
     $input_string = trim($input_string);
     DEBUG_MODE && $this->_calls[$input_string]++;
     if ($this->USE_TRANSLATE_CACHE && empty($args)) {
         $CACHE_NAME = $lang . '#____#' . $input_string;
         if (isset($this->_LOCALE_CACHE[$CACHE_NAME])) {
             return $this->_LOCALE_CACHE[$CACHE_NAME];
         }
     }
     $is_translated = false;
     $_source = $input_string;
     $output_string = $input_string;
     // Try to find prefix (starts with '::')
     $_prefix = '';
     $_prefix_length = 0;
     if ($input_string[0] == ':' && $input_string[1] == ':') {
         $_prefix = substr($input_string, 0, strpos($input_string, '::', 2) + 2);
         $_prefix_length = strlen($_prefix);
         $input_string = substr($input_string, $_prefix_length);
     }
     if ($this->TRANSLATE_ENABLED) {
         // Prepare for case ignore
         if ($this->VARS_IGNORE_CASE) {
             $first_input_string = $input_string;
             $input_string = strtolower($input_string);
             if ($this->REPLACE_UNDERSCORE) {
                 $input_string = str_replace('&nbsp;', ' ', $input_string);
                 $input_string = str_replace(' ', '_', $input_string);
             }
         }
         // Try to find prefix (starts with '::') again
         if (!strlen($_prefix) && isset($this->TR_VARS[$lang]['::' . $_GET['object'] . '::' . $input_string])) {
             $_prefix = '::' . $_GET['object'] . '::';
         }
         // First try to translate var with prefix
         if (strlen($_prefix) && isset($this->TR_VARS[$lang][$_prefix . $input_string])) {
             $output_string = $this->TR_VARS[$lang][$_prefix . $input_string];
             $is_translated = true;
             // Then common var
         } elseif (isset($this->TR_VARS[$lang][$input_string])) {
             $output_string = $this->TR_VARS[$lang][$input_string];
             $is_translated = true;
             // Then try _un_html_entities
         } elseif (($var_un_html = $this->_un_html_entities($input_string)) && isset($this->TR_VARS[$lang][$var_un_html])) {
             $output_string = $this->TR_VARS[$lang][$var_un_html];
             $is_translated = true;
             // Last - is untranslated
         } else {
             $output_string = $input_string;
             if (DEBUG_MODE) {
                 if (!isset($this->_NOT_TRANSLATED)) {
                     $this->_NOT_TRANSLATED = [];
                 }
                 if (!isset($this->_NOT_TRANSLATED[$lang])) {
                     $this->_NOT_TRANSLATED[$lang] = [];
                 }
                 if (!isset($this->_NOT_TRANSLATED[$lang][$input_string])) {
                     $this->_NOT_TRANSLATED[$lang][$input_string] = 0;
                 }
                 $this->_NOT_TRANSLATED[$lang][$input_string]++;
                 // Check if such variable exists
                 if ($this->AUTO_FIND_VARS && !isset($this->TR_ALL_VARS[$input_string])) {
                     $this->insert_var($input_string);
                 }
             }
         }
     }
     if ($this->REPLACE_UNDERSCORE && !$is_translated) {
         $output_string = str_replace('_', ' ', $_source);
         if ($_prefix_length) {
             $output_string = substr($output_string, $_prefix_length);
         }
     }
     if (!empty($args) && is_array($args)) {
         $output_string = $this->_process_sub_patterns($output_string, $args);
         $output_string = strtr($output_string, $args);
     }
     if ($this->TRACK_FIRST_LETTER_CASE && $is_translated) {
         $input = $this->VARS_IGNORE_CASE ? $first_input_string : $input_string;
         $first_s = substr($input, 0, 1);
         $first_t = _substr($output_string, 0, 1);
         $first_s_lower = strtolower($first_s) == $first_s;
         $first_t_lower = _strtolower($first_t) == $first_t;
         if (!$first_s_lower && $first_t_lower) {
             $output_string = _strtoupper($first_t) . _substr($output_string, 1);
         }
     }
     if (DEBUG_MODE) {
         if ($this->WRAP_VARS_FOR_INLINE_EDIT && false === strpos($output_string, 'class=localetr')) {
             $r = [' ' => '%20', '=' => '&equals;', '<' => '&lt;', '>' => '&gt;'];
             $svar = _prepare_html(str_replace(array_keys($r), array_values($r), $_source));
             $output_string = '<span class=localetr svar=' . $svar . '>' . $output_string . '</span>';
         }
         debug('i18n[]', ['name_orig' => $_source, 'name' => $input_string, 'out' => $output_string, 'lang' => $lang, 'args' => $args ?: '', 'translated' => (int) $is_translated, 'time' => round(microtime(true) - $_start_time, 5), 'trace' => main()->trace_string()]);
     }
     // Put to cache
     if ($this->USE_TRANSLATE_CACHE && empty($args)) {
         $this->_LOCALE_CACHE[$CACHE_NAME] = $output_string;
     }
     return $output_string;
 }
Exemplo n.º 10
0
 /**
  * Makes a UTF-8 string lowercase. This is a UTF8-aware version
  * of [strtolower](http://php.net/strtolower).
  *
  *     $str = UTF8::strtolower($str);
  *
  * @author  Andreas Gohr <*****@*****.**>
  * @param   string  $str mixed case string
  * @return  string
  * @uses    UTF8::$server_utf8
  * @uses    Kohana::$charset
  */
 public static function strtolower($str)
 {
     if (UTF8::$server_utf8) {
         return mb_strtolower($str, Kohana::$charset);
     }
     if (!isset(UTF8::$called[__FUNCTION__])) {
         require Kohana::find_file('utf8', __FUNCTION__);
         // Function has been called
         UTF8::$called[__FUNCTION__] = TRUE;
     }
     return _strtolower($str);
 }
Exemplo n.º 11
0
/**
 * 会员修改邮箱地址
 *
 * 编写人:陈雷
 * 编写日期:2009-6-16
 * 修改日期:
 * @param int $uid 用户uid
 * @param string $oldname 老邮箱地址
 * @param string $newname 新邮箱地址
 * @param string $password 原密码
 * @param string $validate_code 验证码
 * @param string $errorinfo 错误信息,引用
 * @return 1表示失败,0表示成功
 */
function change_email($uid, $oldname, $newname, $password, $validate_code, &$errorinfo)
{
    global $SDB, $DC, $SESSION, $MDB, $MDB_LY;
    $obj_user = $DC->get_user($uid);
    if ($obj_user->validate_email == 1) {
        $errorinfo = '您的邮箱已经通过验证,不能再次修改';
        $result = 0;
        return $result;
    }
    if (!strstr($newname, '@')) {
        $errorinfo = '新邮箱格式错误';
        $result = 0;
        return $result;
    }
    $validate_code = addslashes($validate_code);
    $code_hash = $_COOKIE['GFCH'];
    if (!verify_antispam_v2($code_hash, $validate_code)) {
        $errorinfo = '验证码错误';
        $result = 0;
        return $result;
    }
    $sql = "select uid from user where name = '{$newname}'";
    $temp_uid = $SDB->result($sql);
    if ($temp_uid > 0) {
        $errorinfo = '您要修改的新邮箱已经存在';
        $result = 0;
        return $result;
    }
    $raw_hash = 'Love21cn.com' . sha1(_strtolower($oldname)) . sha1($password);
    $login_hash = sha1($raw_hash);
    $user_obj = $DC->get_userlog_from_uidhash(md5($uid));
    if ($user_obj->login_hash == $login_hash) {
        $new_raw_hash = 'Love21cn.com' . sha1(_strtolower($newname)) . sha1($password);
        $new_login_hash = sha1($new_raw_hash);
        $arr = array('name' => $newname, 'login_hash' => $new_login_hash);
        $blogin = $DC->update_userlogin($uid, $arr);
        $buser = $DC->update_user($uid, $arr);
        v_send_email($newname, 1, $uid);
        $DC->set_cache('post_email_num_chenlei_' . $uid, 1, 3600 * 24);
        $errorinfo = '邮箱修改成功,验证邮件已发至新邮箱(' . $newname . ')请使用新邮箱地址重新登录世纪佳缘。';
        $result = 1;
        /**
         * 更新直邮推荐表
         */
        $sql = "update subscribe set email='" . $newname . "' where uid=" . $uid;
        $MDB_LY->query($sql);
        $USER = $SDB->result("SELECT * FROM user WHERE `uid`='" . $uid . "'");
        if (is_object($USER) && $USER->uid > 0) {
            write_session($USER, 0, 0, $new_login_hash);
        }
        $DC->set_cache('post_email_num_chenlei_' . $USER->uid, 0, 3600 * 24);
    } else {
        $errorinfo = '密码错误';
        $result = 0;
    }
    return $result;
}
Exemplo n.º 12
0
<?php

return function () {
    $data = [];
    foreach ((array) db()->select('id, name')->from('static_pages')->where('active', '1')->get_2d() as $id => $name) {
        $name = _strtolower($name);
        if (strlen($name)) {
            $data[$name] = $name;
        }
    }
    return $data;
};
Exemplo n.º 13
0
 /**
  * Push user var into main traslation table
  */
 function user_var_push($FORCE_ID = false)
 {
     $_GET['id'] = intval($FORCE_ID ? $FORCE_ID : $_GET['id']);
     $A = db()->query_fetch('SELECT * FROM ' . db('locale_user_tr') . ' WHERE id=' . intval($_GET['id']));
     if (!$A) {
         return _e('No id');
     }
     $VAR_NAME = $A['name'];
     if ($this->VARS_IGNORE_CASE) {
         $VAR_NAME = str_replace(' ', '_', _strtolower($VAR_NAME));
     }
     if (!strlen($VAR_NAME)) {
         return _e('Empty var name');
     }
     $CUR_LOCALE = $A['locale'];
     if (!$CUR_LOCALE) {
         return _e('Empty var locale');
     }
     $EDITED_VALUE = $A['translation'];
     if (!strlen($EDITED_VALUE)) {
         return _e('Empty var translation');
     }
     // Get main translation var (if exists)
     $var_info = db()->query_fetch('SELECT * FROM ' . db('locale_vars') . ' WHERE value="' . _es($VAR_NAME) . '"');
     if (!$var_info) {
         $var_info = ['value' => _es($VAR_NAME), 'location' => ''];
         db()->INSERT('locale_vars', $var_info);
         $var_id = db()->INSERT_ID();
         if ($var_id) {
             $var_info['id'] = $var_id;
         }
     }
     if (!$var_info['id']) {
         return _e('No locale var id');
     }
     $sql_data = ['var_id' => intval($var_info['id']), 'value' => _es($EDITED_VALUE), 'locale' => _es($CUR_LOCALE)];
     // Get translation for the current locale
     $Q = db()->query('SELECT * FROM ' . db('locale_translate') . ' WHERE var_id=' . intval($var_info['id']));
     while ($A = db()->fetch_assoc($Q)) {
         $var_tr[$A['locale']] = $A['value'];
     }
     if (isset($var_tr[$CUR_LOCALE])) {
         db()->UPDATE('locale_translate', $sql_data, 'var_id=' . intval($var_info['id']) . ' AND locale="' . _es($CUR_LOCALE) . '"');
     } else {
         db()->INSERT('locale_translate', $sql_data);
     }
     return $FORCE_ID ? '' : js_redirect('./?object=' . $_GET['object'] . '&action=user_vars');
 }
Exemplo n.º 14
0
 /**
  */
 function _get_page_from_db($id = null)
 {
     $id = $id ?: $_GET['id'];
     if (empty($id)) {
         return [];
     }
     $cache_name = $id . '|' . $lang;
     $a = $this->_cache[$cache_name];
     if (!is_null($a)) {
         return $a;
     }
     $q = db()->from(self::table)->where('active', '1');
     if (is_numeric($id)) {
         $q->where('id', (int) $id);
     } else {
         $q->where('name', _strtolower($id));
     }
     $lang = conf('language');
     $q->where('locale', $lang);
     $a = $q->get();
     $this->_cache[$cache_name] = $a;
     return $a;
 }
Exemplo n.º 15
0
 /**
  * Makes a UTF-8 string lowercase. This is a UTF8-aware version
  * of [strtolower](http://php.net/strtolower).
  *
  *     $str = UTF8::strtolower($str);
  *
  * @author  Andreas Gohr <*****@*****.**>
  * @param   string  $str mixed case string
  * @return  string
  * @uses    UTF8::$server_utf8
  * @uses    Phalcana\Phalcana::$charset
  */
 public static function strtolower($str)
 {
     if (UTF8::$server_utf8) {
         return mb_strtolower($str, Phalcana::$charset);
     }
     if (!isset(UTF8::$called[__FUNCTION__])) {
         require Phalcana::$di->get('fs')->findFile('utf8', __FUNCTION__);
         // Function has been called
         UTF8::$called[__FUNCTION__] = true;
     }
     return _strtolower($str);
 }
Exemplo n.º 16
0
 /**
  */
 function _get_info($id = null)
 {
     $id = isset($id) ? $id : $_GET['id'];
     return db()->from(self::table)->where('title', _strtolower(urldecode($id)))->or_where('id', (int) $id)->get();
 }
Exemplo n.º 17
0
/**
 * Подготовка URL
 *
 * @param string $st
 * @return string
 */
function prepare_url($url)
{
    $new_url = strip_tags($url);
    $table = array('«' => '', '»' => '', '—' => '', '–' => '', '“' => '', '”' => '');
    $new_url = str_replace(array_keys($table), array_values($table), $new_url);
    if (defined('TRANSLIT_URL') && TRANSLIT_URL) {
        $new_url = translit_string(trim(_strtolower($new_url)));
    }
    $new_url = preg_replace(array('/^[\\/-]+|[\\/-]+$|^[\\/_]+|[\\/_]+$|[^\\.a-zа-яеёA-ZА-ЯЕЁ0-9\\/_-]/u', '/--+/', '/-*\\/+-*/', '/\\/\\/+/'), array('-', '-', '/', '/'), $new_url);
    $new_url = trim($new_url, '-');
    if (substr(URL_SUFF, 0, 1) != '/' && substr($url, -1) == '/') {
        $new_url = $new_url . "/";
    }
    return mb_strtolower(rtrim($new_url, '.'), 'UTF-8');
}
Exemplo n.º 18
0
 /**
  */
 function add_var()
 {
     if (is_post()) {
         $_POST['var_name'] = _strtolower(str_replace(' ', '_', $_POST['var_name']));
         $var_info = db()->get('SELECT * FROM ' . db('locale_vars') . ' WHERE LOWER(REPLACE(CONVERT(value USING utf8), " ", "_")) = "' . _es($_POST['var_name']) . '"');
         if (!empty($_POST['var_name']) && empty($var_info)) {
             db()->insert_safe('locale_vars', ['value' => $_POST['var_name']]);
             $INSERT_ID = db()->insert_id();
             common()->admin_wall_add(['locale var added: ' . $_POST['var_name'], $INSERT_ID]);
         }
         if (empty($INSERT_ID) && !empty($var_info)) {
             $INSERT_ID = $var_info['id'];
         }
         if (!_ee()) {
             $sql = [];
             $cnames = [];
             foreach ((array) $this->_cur_langs_array as $info) {
                 $tr_name = 'var_tr__' . $info['locale'];
                 if (!isset($_POST[$tr_name])) {
                     continue;
                 }
                 $sql[] = _es(['var_id' => (int) $INSERT_ID, 'value' => $_POST[$tr_name], 'locale' => $info['locale']]);
                 $cnames[] = 'locale_translate_' . $info['locale'];
             }
             if ($sql && $INSERT_ID) {
                 db()->insert('locale_translate', $sql);
                 cache_del($cnames);
             }
             common()->admin_wall_add(['locale var added: ' . $_POST['var_name']]);
             return js_redirect($INSERT_ID ? url('/@object/edit_var/' . intval($INSERT_ID)) : url('/@object/show_vars'));
         }
     }
     $r = (array) $_POST + ['back_link' => url('/@object/show_vars')];
     $form = form($r)->text('var_name');
     foreach ((array) $this->_cur_langs_array as $info) {
         $form->textarea('var_tr__' . $info['locale'], $info['name']);
     }
     return $form->save_and_back();
 }
Exemplo n.º 19
0
 /**
  * Makes a UTF-8 string lowercase
  *
  * This is a UTF8-aware version of [strtolower](http://php.net/strtolower).
  *
  * Example:
  * ~~~
  * $str = UTF8::strtolower($str);
  * ~~~
  *
  * @author  Andreas Gohr <*****@*****.**>
  *
  * @param   string  $str  Mixed case string
  *
  * @return  string
  *
  * @uses    UTF8::$server_utf8
  * @uses    Kohana::$charset
  * @uses    Kohana::find_file
  */
 public static function strtolower($str)
 {
     if (self::$server_utf8) {
         return mb_strtolower($str, Kohana::$charset);
     }
     UTF8::_load(__FUNCTION__);
     return _strtolower($str);
 }
Exemplo n.º 20
0
 /**
  */
 function _fix_page_name($in = null)
 {
     if (!strlen($in)) {
         return '';
     }
     // Detect non-latin characters
     if (strlen($in) !== _strlen($in)) {
         $in = common()->make_translit(_strtolower($in));
     }
     $in = preg_replace('/[^a-z0-9\\_\\-]/i', '_', strtolower($in));
     $in = trim(str_replace(['__', '___'], '_', $in), '_');
     return $in;
 }
Exemplo n.º 21
0
 /**
  * Analyze text, find top keywords and return string ready for use inside 'MATCH ... AGAINST ...'
  */
 function _get_keywords_from_text($text = '')
 {
     $num_to_ret = $this->NUM_KEYWORDS;
     $wordlist = preg_split($this->_PATTERN_KWORDS, _strtolower(strip_tags($text)));
     // Build an array of the unique words and number of times they occur.
     $a = array_count_values($wordlist);
     // Remove the stop words from the list.
     foreach ((array) $this->STOP_WORDS as $_word) {
         unset($a[$_word]);
     }
     // Remove short words from the list.
     foreach ((array) $a as $k => $v) {
         if (_strlen($k) < 4) {
             unset($a[$k]);
         }
     }
     arsort($a, SORT_NUMERIC);
     $num_words = count($a);
     $num_to_ret = $num_words > $this->num_to_ret ? $num_to_ret : $num_words;
     $outwords = array_slice($a, 0, $num_to_ret);
     $result = implode(' ', array_keys($outwords));
     return $result;
 }
Exemplo n.º 22
0
 /**
  * Makes a UTF-8 string lowercase.
  * @see http://php.net/strtolower
  *
  * @author  Andreas Gohr <*****@*****.**>
  *
  * @param   string   mixed case string
  * @return  string
  */
 public static function strtolower($str)
 {
     if (!isset(self::$called[__FUNCTION__])) {
         require SYSPATH . 'core/utf8/' . __FUNCTION__ . EXT;
         // Function has been called
         self::$called[__FUNCTION__] = TRUE;
     }
     return _strtolower($str);
 }
Exemplo n.º 23
0
 /**
  */
 function _get_info($id = null, $lang = null)
 {
     $id = isset($id) ? $id : $_GET['id'];
     $lang = isset($lang) ? $lang : $_GET['page'];
     $a = db()->from(self::table)->where('locale', $lang ? strtolower($lang) : '')->where('name', _strtolower(urldecode($id)))->or_where('id', (int) $id)->get();
     if ($a) {
         return $a;
     } elseif ($lang) {
         $all_langs = main()->get_data('locale_langs');
         if (!isset($all_langs[$lang])) {
             return false;
         }
         // Try with first lang as fallback
         $a = db()->from(self::table)->where('name', _strtolower(urldecode($id)))->or_where('id', (int) $id)->get();
         // Create missing page
         if ($a && $a['locale'] && $lang !== $locale) {
             $new = $a;
             unset($new['id']);
             $new['active'] = 0;
             $new['parent_id'] = 0;
             $new['locale'] = $lang;
             db()->insert_safe(self::table, $new);
             $new['id'] = db()->insert_id();
             return $new;
         }
         return $a;
     }
     return false;
 }