sro('/Includes/functions.php'); sro('/PHP5/lib/PHPLang/make_example.php'); sro('/PHP5/lib/PHPLang/display.php'); sro('/PHP5/lib/PHPLang/db.php'); sro('/PHP5/lib/PHPLang/misc.php'); sro('/PHP5/lib/PHPLang/templates.php'); if (!array_key_exists("lang", $_GET) or !($langs = vec_norm(explode(",", $_GET["lang"]), "trim"))) { $langs = ['la']; } if (!array_key_exists("name", $_GET) or !($names = vec_norm(explode(",", $_GET["name"]), "trim"))) { $names = NULL; } if (!array_key_exists("spart", $_GET) or !($sparts = vec_norm(explode(",", $_GET["spart"]), "trim"))) { $sparts = NULL; } if (!array_key_exists("attr", $_GET) or !($attrs = vec_norm(explode(",", $_GET["attr"]), "trim"))) { $attrs = []; } $definitions = safe_get("definitions", $_GET); $connections = safe_get("connections", $_GET); $forms = safe_get("forms", $_GET); if ($langs and count($langs) == 1 and $names and count($names) == 1 and $sparts and count($sparts) == 1) { $w = defaultDB()->searcher()->name($names[0])->spart($sparts[0])->lang($langs[0])->all(); if (count($w)) { exit("present"); } else { exit("absent"); } } else { exit("Bad \$_GET"); }
} $ret = do_pick($answer, NULL, $selections, $reason); if ($ret === NULL) { $stop = TRUE; } else { return $ret; } }, $choices[1], array_keys($choices[1])); if ($stop) { return $try(); } $cquiz_answers["answer{$n}"] = [implode("\n", array_map("format_word", $answers))]; if ($shuffle) { shuffle($answers); } if (count($answers) !== count(vec_norm(array_unique($answers)))) { $reason = "results were not unique (" . implode(",", $results) . ")"; return $try(); } foreach ($answers as &$r) { $r = format_word($r, $lang); } $result_json[] = ["matching", "answer{$n}", $quiz->get_other("matching{$n}-tooltip"), $left, $answers]; $n += 1; } elseif ($word === $OP_USER_INPUT || $word === $OP_USER_PARAGRAPH) { $refresh(1); $stop = FALSE; $answers = $quiz->get_other("answer{$n}"); $lang = safe_get("answer{$n}-language", $quiz->get_others()); if (is_callable($answers)) { $answers = $answers($selections, defaultDB());
function process($dopick, &$reason) { $this->answers = []; $this->correct = []; foreach ($dopick($this->init, FALSE) as $k => $v) { $r = $dopick($v, TRUE); if ($r === NULL) { return; } $r = $this->format_word($r); $this->answers[] = $r; if ($k === "correct" or is_array($v) and array_key_exists("correct", $v) and !!$dopick($v["correct"], FALSE)) { $this->correct[] = $r; } } if (count($this->answers) !== count(vec_norm(array_unique($this->answers)))) { $reason = "answers were not unique (" . implode(",", $this->answers) . ")"; return; } return $this; }
function _def_parse($def) { $def_exists = "EXISTS (SELECT 1 FROM definitions WHERE definitions.word_id = words.word_id AND "; $expr = ["def_value LIKE CONCAT('%',?,'%')", "def_value REGEXP CONCAT('[[:<:]]',?,'[[:>:]]')", "def_value REGEXP CONCAT('(^|,|;|\\n)\\W*',?,'\\W*(\$|,|;|\\n)')"]; $type = endswith($def, ",") ? 2 : (endswith($def, "~") ? 0 : 1); if (!$type) { $def = substr($def, 0, strlen($def) - 1); } $def = vec_norm(explode(",", $def), "trim"); $this->stmt .= "("; $op = ""; foreach ($def as $d) { $this->stmt .= $op . $def_exists . $expr[$type] . ")"; $this->args[0] .= "s"; $this->args[] = $type ? preg_quote($d) : $d; $op = " AND "; } $this->stmt .= ")"; return $expr[$type]; }
if ($reverse = substr($attr, 0, 1) === "!") { $attr = substr($attr, 1); } if (strpos($attr, "=") === FALSE) { $a = ATTR($attr); } else { list($name, $value) = explode("=", $attr, 2); $a = ATTR($name, $value); } if ($a !== NULL) { if (!$reverse) { $searcher = $searcher->only_with_attr($a); } else { $searcher = $searcher->only_without_attr($a); } } } $list = $searcher->all(); } else { $list = []; foreach ($ids as $id) { $list[] = WORD(defaultDB(), intval($id)); } } $res = vec_norm(array_map(function ($e) { if (no_format($e)) { return ["data" => $e->name(), "value" => $e->id() . "", "display" => $e->info()]; } return ["data" => $e->name(), "value" => $e->id() . "", "display" => format_word($e->info())]; }, $list)); echo json_encode($res);
function lexify_punctuation($str) { $OPS = array_map(function ($o) { return $GLOBALS["OP_{$o}"]; }, ["PERIOD", "COMMA", "COLON", "APOS", "QUEST", "EXCL", "MDASH", "NDASH", "LPAREN", "RPAREN", "LQUOTE", "RQUOTE"]); $result = [""]; $i = 0; $lens = strlen($str); while ($i < $lens) { $match = NULL; foreach ($OPS as $op) { if (startswith($str, $op->text, $i)) { $match = $op; break; } } if ($match !== NULL) { $result[] = $match; $i += strlen($match->text); } else { if (!is_string($result[count($result) - 1])) { $result[] = ""; } $result[count($result) - 1] .= $str[$i]; $i += 1; } } $result = vec_norm(array_map(function ($o) { if (is_string($o)) { return trim($o); } return $o; }, $result)); return $result; }
<?php require_once '/var/www/config.php'; sro('/Includes/mysql.php'); sro('/Includes/session.php'); sro('/Includes/functions.php'); sro('/PHP5/lib/PHPLang/make_example.php'); sro('/PHP5/lib/PHPLang/display.php'); if (!requireRank(3, FALSE)) { echo "Insufficient permissions"; } else { if (array_key_exists("id", $_GET) and array_key_exists("attr", $_GET) and is_numeric($_GET["id"])) { $w = WORD(defaultDB(), intval($_GET["id"])); $attrs = vec_norm(explode(",", $_GET["attr"]), "trim"); foreach ($attrs as $attr) { if (!$attr) { continue; } $a = NULL; if ($reverse = substr($attr, 0, 1) === "!") { $attr = substr($attr, 1); } if (strpos($attr, "=") === FALSE) { if (!$reverse) { exit("invalid format: {$attr}"); } $a = ATTR($attr); } else { if ($reverse) { exit("invalid format: !{$attr}"); }
}, $ids)); } else { if (!array_key_exists("lang", $_GET) or !($langs = vec_norm(explode(",", $_GET["lang"]), "trim"))) { $langs = ['la']; } } if ($ids or !array_key_exists("name", $_GET) or !($names = vec_norm(explode(",", $_GET["name"]), "trim"))) { $names = NULL; } if ($ids or !array_key_exists("spart", $_GET) or !($sparts = vec_norm(explode(",", $_GET["spart"]), "trim"))) { $sparts = NULL; } if ($ids or !array_key_exists("attr", $_GET) or !($attrs = vec_norm(explode(",", $_GET["attr"]), "trim"))) { $attrs = []; } if ($ids or !array_key_exists("def", $_GET) or !($defs = vec_norm(explode(",", $_GET["def"]), "trim"))) { $defs = []; } } else { $langs = ["la"]; $names = $sparts = $ids = []; } $start = intval(safe_get("start", $_GET)); $limit = intval(safe_get("limit", $_GET)); if ($limit <= 0) { $limit = 5; } if ($limit > 50) { $limit = 50; } ?>
if ($forms) { //$searcher = $searcher->form_includes($forms); $op = " AND ("; foreach ($forms as $f) { $stmt .= $op . "form_value LIKE CONCAT('%',?,'%')"; $searcher->args[0] .= "s"; $searcher->args[] .= $f; $op = " OR "; } if ($op === " OR ") { $stmt .= ")"; } } $value = $stmt; error_log($value); $stmt = $mysqli->prepare($stmt); if (!$stmt) { echo "Prepare failed: (" . $mysqli->errno . ") " . $mysqli->error; echo "\nStatement was: " . var_export($value, 1); } $_start = microtime(true); $list = sql_getmany($stmt, $searcher->map, $searcher->args); error_log("-- Took " . (microtime(true) - $_start) . "s"); $stmt->close(); } else { $list = []; } $res = vec_norm(array_map(function ($e) { return ["data" => $e, "value" => $e, "display" => format_word($e)]; }, $list)); echo json_encode($res);
function search_GET($limit = 50, &$max_size = NULL) { $db = defaultDB(); if (!array_key_exists("lang", $_GET) or !($langs = vec_norm(explode(",", $_GET["lang"]), "trim"))) { $langs = ['la']; } if (!array_key_exists("name", $_GET) or !($names = vec_norm(explode(",", $_GET["name"]), "trim"))) { $names = NULL; } if (!array_key_exists("form", $_GET) or !($forms = vec_norm(explode(",", $_GET["form"]), "trim"))) { $forms = NULL; } if (!array_key_exists("spart", $_GET) or !($sparts = vec_norm(explode(",", $_GET["spart"]), "trim"))) { $sparts = NULL; } if (!array_key_exists("attr", $_GET) or !($attrs = vec_norm(explode(",", $_GET["attr"]), "trim"))) { $attrs = []; } if (!array_key_exists("def", $_GET) or !($defs = vec_norm(explode(";", $_GET["def"]), "trim"))) { $defs = []; } if (!array_key_exists("id", $_GET) or !($ids = vec_norm(explode(",", $_GET["id"]), "trim"))) { $ids = NULL; } $no_definitions = safe_get("no_definitions", $_GET) === "true"; $no_templates = !(safe_get("show_templates", $_GET) === "true"); $start = intval(safe_get("start", $_GET)); $_ = $limit; $limit = intval(safe_get("limit", $_GET)); if ($limit <= 0) { $limit = 5; } if ($limit > $_) { $limit = $_; } if ($ids === NULL) { $searcher = $db->searcher(); if ($names) { $searcher = $searcher->name($names); } if ($forms) { $searcher = $searcher->form($forms); } if ($langs) { $searcher = $searcher->lang($langs); } if ($sparts) { $searcher = $searcher->spart($sparts); } if ($defs) { $searcher = $searcher->definition_parse($defs); } else { if ($no_definitions) { $searcher = $searcher->no_definitions(); } } if ($no_templates) { $attrs[] = "!template"; } foreach ($attrs as $attr) { if (!$attr) { continue; } $a = NULL; if ($reverse = substr($attr, 0, 1) === "!") { $attr = substr($attr, 1); } if (strpos($attr, "=") === FALSE) { $a = ATTR($attr); } else { list($name, $value) = explode("=", $attr, 2); $a = ATTR($name, $value); } if ($a !== NULL) { if (!$reverse) { $searcher = $searcher->only_with_attr($a); } else { $searcher = $searcher->only_without_attr($a); } } } $max_size = $searcher->max_size(); $list = $searcher->limit($start, $limit)->all("name"); if (count($list) === $max_size) { $max_size = NULL; } } else { $max_size = NULL; $list = []; foreach ($ids as $id) { $list[] = WORD(defaultDB(), intval($id)); } } return $list; }