Beispiel #1
0
function qa_handles_to_userids($handles, $exactonly = false)
{
    require_once QA_INCLUDE_DIR . 'util/string.php';
    if (QA_FINAL_EXTERNAL_USERS) {
        $rawhandleuserids = qa_get_userids_from_public($handles);
    } else {
        require_once QA_INCLUDE_DIR . 'db/users.php';
        $rawhandleuserids = qa_db_user_get_handle_userids($handles);
    }
    $gothandleuserids = array();
    if ($exactonly) {
        // only take the exact matches
        foreach ($handles as $handle) {
            $gothandleuserids[$handle] = @$rawhandleuserids[$handle];
        }
    } else {
        // normalize to lowercase without accents, and then find matches
        $normhandleuserids = array();
        foreach ($rawhandleuserids as $handle => $userid) {
            $normhandleuserids[qa_string_remove_accents(qa_strtolower($handle))] = $userid;
        }
        foreach ($handles as $handle) {
            $gothandleuserids[$handle] = @$normhandleuserids[qa_string_remove_accents(qa_strtolower($handle))];
        }
    }
    return $gothandleuserids;
}
 public function test__qa_string_remove_accents()
 {
     $test = qa_string_remove_accents($this->strAccents);
     $expected = 'The quicK ssroWn Fot jUOIps OVEr THE LAEzy Dog';
     $this->assertEquals($expected, $test);
 }
Beispiel #3
0
function qa_q_request($questionid, $title)
{
    if (qa_to_override(__FUNCTION__)) {
        $args = func_get_args();
        return qa_call_override(__FUNCTION__, $args);
    }
    require_once QA_INCLUDE_DIR . 'qa-app-options.php';
    require_once QA_INCLUDE_DIR . 'qa-util-string.php';
    $title = qa_block_words_replace($title, qa_get_block_words_preg());
    $words = qa_string_to_words($title, true, false, false);
    $wordlength = array();
    foreach ($words as $index => $word) {
        $wordlength[$index] = qa_strlen($word);
    }
    $remaining = qa_opt('q_urls_title_length');
    if (array_sum($wordlength) > $remaining) {
        arsort($wordlength, SORT_NUMERIC);
        // sort with longest words first
        foreach ($wordlength as $index => $length) {
            if ($remaining > 0) {
                $remaining -= $length;
            } else {
                unset($words[$index]);
            }
        }
    }
    $title = implode('-', $words);
    if (qa_opt('q_urls_remove_accents')) {
        $title = qa_string_remove_accents($title);
    }
    return (int) $questionid . '/' . $title;
}
Beispiel #4
0
function qa_q_request($questionid, $title)
{
    require_once QA_INCLUDE_DIR . 'qa-util-string.php';
    $words = qa_string_to_words($title, true, false, false);
    $wordlength = array();
    foreach ($words as $index => $word) {
        $wordlength[$index] = qa_strlen($word);
    }
    $remaining = qa_opt('q_urls_title_length');
    if (array_sum($wordlength) > $remaining) {
        arsort($wordlength, SORT_NUMERIC);
        // sort with longest words first
        foreach ($wordlength as $index => $length) {
            if ($remaining > 0) {
                $remaining -= $length;
            } else {
                unset($words[$index]);
            }
        }
    }
    $title = implode('-', $words);
    if (qa_opt('q_urls_remove_accents')) {
        $title = qa_string_remove_accents($title);
    }
    return (int) $questionid . '/' . $title;
}