Beispiel #1
0
<?php

require_once "../phplib/util.php";
define('TYPE_SHOW_ONLY_VERBS', 'conjugare');
define('TYPE_SHOW_NO_VERBS', 'declinare');
$cuv = util_getRequestParameter('cuv');
$lexemId = util_getRequestParameter('lexemId');
$ajax = util_getRequestParameter('ajax');
$type = util_getRequestParameter('type');
$searchType = SEARCH_INFLECTED;
$arr = StringUtil::analyzeQuery($cuv);
$hasDiacritics = session_user_prefers(Preferences::FORCE_DIACRITICS) || $arr[0];
// LexemId search
if ($lexemId) {
    $searchType = SEARCH_LEXEM_ID;
    SmartyWrap::assign('lexemId', $lexemId);
    if (!StringUtil::validateAlphabet($lexemId, '0123456789')) {
        $lexemId = '';
    }
    $lexem = Lexem::get_by_id($lexemId);
    if ($lexem) {
        $lexems = array($lexem);
        $cuv = $lexem->formNoAccent;
    } else {
        $lexems = array();
        $cuv = NULL;
    }
}
if ($lexemId) {
    SmartyWrap::assign('paradigmLink', util_getWwwRoot() . "lexem/{$cuv}/{$lexemId}/paradigma");
} else {
util_assertNotMirror();
$form = util_getRequestParameter('form');
$sourceId = util_getRequestParameter('source');
$loc = util_getRequestParameter('loc');
$paradigm = util_getRequestParameter('paradigm');
$structStatus = util_getRequestParameter('structStatus');
$nick = util_getRequestParameter('nick');
$searchButton = util_getRequestParameter('searchButton');
if (!$searchButton) {
    util_redirect('index.php');
}
$where = array();
$joins = array();
// Process the $form argument
$form = StringUtil::cleanupQuery($form);
list($hasDiacritics, $hasRegexp, $ignored) = StringUtil::analyzeQuery($form);
$field = $hasDiacritics ? 'formNoAccent' : 'formUtf8General';
if ($hasRegexp) {
    $fieldValue = StringUtil::dexRegexpToMysqlRegexp($form);
} else {
    $fieldValue = "= '{$form}'";
}
$where[] = "{$field} {$fieldValue}";
// Process the $sourceId argument
if ($sourceId) {
    $joins['definition'] = true;
    $where[] = "sourceId = {$sourceId}";
}
// Process the $loc argument
switch ($loc) {
    case 0:
$status = util_getRequestIntParameter('status');
$nick = util_getRequestParameter('nick');
$sourceId = util_getRequestIntParameter('source');
$yr1 = util_getRequestIntParameter('yr1');
$mo1 = util_getRequestIntParameter('mo1');
$da1 = util_getRequestIntParameter('da1');
$yr2 = util_getRequestIntParameter('yr2');
$mo2 = util_getRequestIntParameter('mo2');
$da2 = util_getRequestIntParameter('da2');
$searchButton = util_getRequestParameter('searchButton');
$ip = $_SERVER['REMOTE_ADDR'];
// Execute query and display results
// Convert wildcards to mysql format
if ($searchButton) {
    $name = StringUtil::cleanupQuery($name);
    $arr = StringUtil::analyzeQuery($name);
    $hasDiacritics = $arr[0];
    $hasRegexp = $arr[1];
    $isAllDigits = $arr[2];
    $field = $hasDiacritics ? 'formNoAccent' : 'formUtf8General';
    $userId = '';
    if ($nick) {
        $user = User::get_by_nick($nick);
        if ($user) {
            $userId = $user->id;
        }
    }
    $beginTime = mktime(0, 0, 0, $mo1, $da1, $yr1);
    $endTime = mktime(23, 59, 59, $mo2, $da2, $yr2);
    // Query the database and output the results
    $defs = Definition::searchModerator($name, $hasDiacritics, $sourceId, $status, $userId, $beginTime, $endTime);
Beispiel #4
0
assertEquals('mamă', AdminStringUtil::extractLexicon($def));
assert(StringUtil::hasRegexp('asd[0-9]'));
assert(!StringUtil::hasRegexp('ăâîșț'));
assert(StringUtil::hasRegexp('cop?l'));
assertEquals("like 'cop%l'", StringUtil::dexRegexpToMysqlRegexp('cop*l'));
assertEquals("like 'cop_l'", StringUtil::dexRegexpToMysqlRegexp('cop?l'));
assertEquals("rlike '^(cop[a-z]l)\$'", StringUtil::dexRegexpToMysqlRegexp('cop[a-z]l'));
assertEquals("rlike '^(cop[^a-z]l)\$'", StringUtil::dexRegexpToMysqlRegexp('cop[^a-z]l'));
assertEquals("rlike '^(cop[â-z]l)\$'", StringUtil::dexRegexpToMysqlRegexp('cop[â-z]l'));
assertEquals("rlike '^(cop[â-z]l.*)\$'", StringUtil::dexRegexpToMysqlRegexp('cop[â-z]l*'));
assertEqualArrays(array(0, 0, 0), StringUtil::analyzeQuery('mama'));
assertEqualArrays(array(1, 0, 0), StringUtil::analyzeQuery('mamă'));
assertEqualArrays(array(0, 1, 0), StringUtil::analyzeQuery('cop?l'));
assertEqualArrays(array(0, 1, 0), StringUtil::analyzeQuery('cop[c-g]l'));
assertEqualArrays(array(1, 1, 0), StringUtil::analyzeQuery('căț[c-g]l'));
assertEqualArrays(array(0, 0, 1), StringUtil::analyzeQuery('1234567'));
assertEquals('&#x25;&#x7e;&#x24;&#x40;&#x27;', AdminStringUtil::xmlizeRequired('\\%\\~\\$\\@\\\''));
assertEquals('&lt;&gt;&amp;', AdminStringUtil::xmlizeRequired('<>&'));
$t = FlexStringUtil::extractTransforms('arde', 'arzând', 0);
assertEquals(4, count($t));
assertEquals('d', $t[0]->transfFrom);
assertEquals('z', $t[0]->transfTo);
assertEquals('e', $t[1]->transfFrom);
assertEquals('', $t[1]->transfTo);
assertEquals('', $t[2]->transfFrom);
assertEquals('ând', $t[2]->transfTo);
assertEquals(UNKNOWN_ACCENT_SHIFT, $t[3]);
$t = FlexStringUtil::extractTransforms('frumos', 'frumoasă', 0);
assertEquals(3, count($t));
assertEquals('o', $t[0]->transfFrom);
assertEquals('oa', $t[0]->transfTo);
Beispiel #5
0
function lookup($sourceId, $cuv, $fd)
{
    if (!source_exists($sourceId)) {
        socket_write($fd, "550 invalid database, use SHOW DB for a list\r\n");
        return;
    }
    if ($sourceId == '*' || $sourceId == '!') {
        $sourceId = 0;
    }
    $cuv = StringUtil::cleanupQuery($cuv);
    $arr = StringUtil::analyzeQuery($cuv);
    $field = $arr[0] ? 'formNoAccent' : 'formUtf8General';
    $lexems = db_find(new Lexem(), "{$field} = '{$cuv}' order by formNoAccent");
    $definitions = Definition::loadForLexems($lexems, $sourceId, $cuv);
    $searchResults = SearchResult::mapDefinitionArray($definitions);
    if (!count($definitions)) {
        socket_write($fd, "552 no match\r\n");
        return;
    }
    socket_write($fd, "150 " . count($definitions) . " definition(s) found\r\n");
    foreach ($searchResults as $sr) {
        $def = pretty_print($sr->definition->internalRep);
        socket_write($fd, "151 \"" . $cuv . "\" " . $sr->source->id . " \"" . $sr->source->name . "\"\r\n");
        socket_write($fd, "{$cuv}\r\n{$def}");
        socket_write($fd, ".\r\n");
    }
    socket_write($fd, "250 ok\r\n");
}
<?php

require_once "../phplib/util.php";
header("Content-Type: application/json");
$acEnable = Config::get("search.acEnable");
$acMinChars = Config::get("search.acMinChars");
$acLimit = Config::get("search.acLimit");
$search = $_REQUEST["term"];
if (!$acEnable || strlen($search) < $acMinChars) {
    return print json_encode(array());
}
$arr = StringUtil::analyzeQuery($search);
$hasDiacritics = session_user_prefers(Preferences::FORCE_DIACRITICS) || $arr[0];
$sql_like = sprintf("%s%%", $search);
$search_results = Lexem::searchLike($sql_like, $hasDiacritics, true, $acLimit);
$clean_results = array_map(function ($lexem) use($hasDiacritics) {
    if ($hasDiacritics) {
        return $lexem->formNoAccent;
    } else {
        return $lexem->formUtf8General;
    }
}, $search_results);
return print json_encode($clean_results);
?>