function la_en($path, $only_one = false) { global $OP_APOS; global $sudata; $arch = safe_get("archtrans", json_decode($sudata, true)) == "true"; $o = $only_one; $decide = function ($archaic, $modern, $extra = NULL) use($o, $arch) { if ($o) { return $arch ? $archaic : $modern; } return $extra ? "({$archaic}|{$modern}|{$extra})" : "({$archaic}|{$modern})"; }; $word = $path->word(); $spart = $word->speechpart(); $definitions = get_definitions($path); $verb = $spart === "verb"; $noun = $spart === "noun"; if ($verb) { $mood = $path->key_value("mood"); $tense = $path->key_value("tense"); $voice = $path->key_value("voice"); $person = $path->key_value("person"); $number = $path->key_value("number"); $psv = $voice === "passive"; // passive voice $_p = $person[strlen($person) - 1]; // person {1,2,3} $pl = $number === "singular" ? 0 : 1; // plural number $st = ($_p == 2 and !$pl) ? "st" : NULL; // singular/person-2 $eth = ($_p == 3 and !$pl) ? "eth" : NULL; // singular/person-3 if (!$o and $st) { $st = "[st]"; } } $d0 = []; // present $d1 = []; // preterite $d2 = []; // past participle $d3 = []; // present participle $d4 = []; // 3s present / 2s present $d5 = []; // 2s perfect (archaic) $be = []; foreach ($definitions as $def) { if ($o and $d0) { break; } $matches = []; if (preg_match("/^be(?:\\s+|\$)/", $def)) { if ($o and $be) { continue; } $be[] = preg_replace("/^be(?:\\s+|\$)/", "", $def) ?: " "; continue; } if (preg_match("/^([a-zA-Z-]+)((?:[^a-zA-Z-].*)?)\$/", $def, $matches)) { $a = $matches[1]; $b = $matches[2]; $d0[] = $def; if ($noun) { $d1[] = _make_expr(InflectN::pluralize($a)) . $b; } if (!$verb) { continue; } $d1[] = _make_expr(InflectV::preterite($a, $o)) . $b; $d2[] = _make_expr(InflectV::pastparticiple($a, $o)) . $b; $d3[] = _make_expr(InflectV::presentparticiple($a, $o)) . $b; if (!$pl and $_p != 1) { if ($_p == 2) { $d4[] = _make_expr(InflectV::secondsingular($a, $o)) . $b; } else { $d4[] = _make_expr(InflectV::thirdsingular($a, $o)) . $b; } } else { $d4[] = $def; } $d5[] = _make_expr(InflectV::secondsingular(InflectV::preterite($a, $o), $o)) . $b; } } if ($o) { if ($d0) { $d0 = $d0[0]; } if ($d1) { $d1 = $d1[0]; } if ($d2) { $d2 = $d2[0]; } if ($d3) { $d3 = $d3[0]; } if ($d4) { $d4 = $d4[0]; } } $d0 = make_expr($d0) ?: " "; $d1 = make_expr($d1) ?: " "; $d2 = make_expr($d2) ?: " "; $d3 = make_expr($d3) ?: " "; $d4 = make_expr($d4) ?: " "; $d5 = make_expr($d5) ?: " "; $be = make_expr($be); $d = $d0; $D = $d3; if ($spart === "verb") { $t = $v = $p = $b = $m = NULL; if ($mood === "infinitive") { if ($tense === "future") { $t = "be about to"; } elseif ($tense === "perfect") { $t = "have"; $d = $d2; } if ($voice === "passive") { if ($tense === "perfect") { $v = "been"; } else { $v = "be"; } $d = $d2; } if ($be and (!$o or !trim($d)) and !$psv) { $eb = [$d0 => "be ", $d2 => "been "]; $BE = safe_get($d, $eb) . $be; if (!trim($d) or $o) { $d = $BE; } else { $d = "(" . trim($d) . "|{$BE})"; } } return "to {$t} {$v} {$d}"; } elseif ($mood === "participle") { $d = $d3; if ($tense === "future") { $t = $o ? "about to" : "(about|going) to"; $d = $d0; } elseif ($tense === "perfect") { $t = "having"; $d = $d1; } if ($voice === "passive") { if ($tense === "perfect") { $v = "been"; } else { $v = "be"; } $d = $d2; } if ($be and (!$o or !trim($d)) and !$psv) { $eb = [$d0 => "be ", $d1 => "have been ", $d2 => "been ", $d3 => " "]; $BE = safe_get($d, $eb) . $be; if (!trim($d) or $o) { $d = $BE; } else { $d = "(" . trim($d) . "|{$BE})"; } } return "{$t} {$v} {$d}"; } elseif ($mood === "indicative" || $mood === "subjunctive") { $subj = $mood === "subjunctive"; $M = ""; $p = ["I", "we", $o ? "thou" : "(you|thou) [\\(sg.\\)]", $o ? "you" : "[all] (you|ye|y{$OP_APOS}all) [\\(pl.\\)]", $o ? "She/he/it" : "(he|she|it)", "they"]; $p = safe_get(2 * ($_p - 1) + $pl, $p); // ignore errors if person isn't provided // am are is ... $is = [$o ? "am" : "(am|{$OP_APOS}m)", $decide($subj ? "beest" : "art", "are", "{$OP_APOS}rt|{$OP_APOS}re|" . ($subj ? "art" : "beest")), $o ? "is" : "(is|{$OP_APOS}s)"]; if ($pl) { $is = "are"; } else { $is = safe_get($_p - 1, $is); } if ($subj and (!$o or $arch and !$st)) { $is = $o ? "be" : "({$is}|be)"; } // was were wast ... $was = [($o and $subj) ? "were" : "was", $decide($subj ? "wert" : "wast", "were", $subj ? "wast" : "wert"), ($o and $subj) ? "were" : "was"]; if ($pl) { $was = "were"; } else { $was = safe_get($_p - 1, $was); } if ($subj and (!$o or $arch and !$st)) { $was = $o ? "were" : "({$was}|were)"; } // shall will wilt ... $will = $o ? "will" : "(will|{$OP_APOS}ll)"; if ($_p == 1) { $will = $o ? "shall" : "(shall|will|{$OP_APOS}ll)"; } elseif ($_p == 2 and !$pl) { $will = $decide("wilt", "will", "shall|{$OP_APOS}ll"); } if (!$o) { $will = "({$will}|{$is} (going|about) to)"; } // has have hast ... $has = "have"; if ($eth) { $has = $decide("hath", "has"); } elseif ($_p == 2 and !$pl) { $has = $decide("hast", "have", "havest"); } if ($psv) { $d = $D = $d2; } if ($tense === "present") { $b = $is; if ($psv) { list($m, $b) = [$b, $b . " being"]; } else { $m = " "; } if (!$psv and $_p != 1 and !$pl) { if ($_p == 3) { $d = $d4; } elseif ($o) { $d = $arch ? $d4 : $d; } else { $d = "({$d}|{$d4})"; } } } elseif ($tense === "imperfect") { $b = $was; if ($psv) { list($m, $b) = [$b, $b . " being"]; } } elseif ($tense === "future") { $m = $will; if ($psv) { $m .= " be"; } else { $b = "{$m} be"; } } else { $d = $d2; $D = $d2; if ($tense === "perfect") { if ($psv) { list($b, $m) = [$was, "{$has} been"]; } else { if ($st) { $d1 = $decide($d5, $d1); } list($b, $m, $d) = [$has, " ", $d1]; } } elseif ($tense === "pluperfect") { $m = "had" . (($o and !$arch) ? "" : $st) . ($psv ? " been" : ""); } elseif ($tense === "future-perfect") { $m = $will . " have" . ($psv ? " been" : ""); } } if ($be and (!$o or !trim($d) or !trim($D)) and !$psv) { $eb = [$d1 => "have been ", $d2 => "been ", $d3 => " ", $d4 => $is . " ", $d5 => "hast been "]; if (!in_array($D, $eb)) { error_log(json_encode($D)); } if (!in_array($d, $eb)) { error_log(json_encode($d)); } $BE = safe_get($D, $eb) . $be; if (!trim($D) or $o) { $D = $BE; } else { $D = "(" . trim($D) . "|{$BE})"; } $BE = safe_get($d, $eb) . $be; if (!trim($d) or $o) { $d = $BE; } else { $d = "(" . trim($d) . "|{$BE})"; } } else { $be = NULL; } if (!$d and !$D) { return NULL; } if (!$D) { $b = NULL; } if (!$d) { $m = NULL; } if ($b and (!$o or $m === NULL or $be !== NULL)) { if ($o or $m === NULL) { return "{$p} {$b} {$D}"; } else { return "{$p} ({$m} {$M} {$d}|{$b} {$D})"; } } elseif ($d) { return "{$p} {$m} {$M} {$d}"; } return NULL; } } else { if ($noun) { if ($path->key_value("number") == "plural") { $d = $d1; } $t = $o ? "the" : "(a|an|the|some)"; $c = [0 => "", "vocative" => "", "nominative" => "", "accusative" => "", "ablative" => $o ? "from/by" : "(from|by)", "dative" => $o ? "to/for" : "(to|for)", "genitive" => "of", "locative" => "at"]; $c = $c[$path->key_value("case")]; return "{$c} {$t} {$d}"; } else { if ($spart === "adjective" || $spart === "adverb") { $c = [0 => "", "positive" => "", "comparative" => $o ? "quite/more" : "(quite|rather|more)", "superlative" => $o ? "very/most" : "(very|most)"]; $c = $c[$path->key_value("degree")]; return "{$c} {$d}"; } } } return $d; }
if (array_key_exists("change", $_GET)) { $_change = explode(";", $_GET["change"]); foreach ($_change as $str) { list($key, $value) = explode(",", $str); $change[$key] = $value; } } if (array_key_exists("overwrite", $_GET)) { $overwrite = TRUE; } else { $overwrite = FALSE; } // Word as passed by id $w = WORD(defaultDB(), intval($_GET["id"])); // Path as passed as string $p = PATH($w, safe_get("path", $_GET)); // Template: passed by name, spart from word, attr template=true $t = defaultDB()->searcher(); $t = $t->spart($w->speechpart()); $t = $t->name($_GET["template"]); $t = $t->only_with_attr(ATTR("template", "true")); $t = $t->all(); if (count($t) === 0) { echo "Could not find template with name: " . $_GET["template"]; } elseif (count($t) !== 1) { echo "Ambiguous template name (please remove duplicate template(s))"; } else { $t = $t[0]; if (($s = run_template($w, $p, $t, $arg, $ignore, $change, $overwrite)) === NULL) { exit("success"); } else {
<?php require_once '/var/www/config.php'; sro('/Includes/mysql.php'); sro('/Includes/session.php'); sro('/Includes/functions.php'); sro('/PHP5/lib/PHPLang/misc.php'); sro('/PHP5/lib/PHPLang/make_example.php'); sro('/PHP5/lib/PHPLang/db.php'); sro('/PHP5/lib/PHPLang/display.php'); $dir = "/var/www/Data/"; $sentences_data = json_decode(file_get_contents("{$dir}/la/sentences.json"), true); $keys = array_keys($sentences_data); $_ = $keys; if ($a = safe_get("sentence", $_GET)) { foreach ($_ as $i => $k) { if (strpos($k, $a) === false) { unset($keys[$i]); } } } echo json_encode(array_values($keys));
if (!is_array($v) or !array_key_exists("name", $v)) { continue; } ?> <label><input name="quiz-types" type="radio" value="<?php echo $k; ?> " <?php if ($predicate($k)) { echo "checked"; } $first = FALSE; ?> <?php if (safe_get("n_questions", $v)) { $n = $v["n_questions"]; if ($n === "auto") { if (is_callable($v["options"])) { error_log("Warning: n_questions=auto does not work with deferred options (key {$k})"); } else { $n = count($v["options"]); } } $onclick = 'var prev_val = $("#quiz-number").val();$("#quiz-number").val(Math.abs(' . $n . ')).attr("disabled",' . $n . ' > 0)'; } else { $onclick = 'if ($("#quiz-number").attr("disabled"))$("#quiz-number").removeAttr("disabled").val(prev_val);else prev_val = $("#quiz-number").val()'; } $onclick .= ';$("#selections").toggle(!!$("#selections ul").hide().filter("#' . $k . '-selections").show().length);'; echo "onclick='{$onclick}'"; ?>
$id = NULL; if (is_string($element)) { $name = $element; $id = get_id($name, $sentence); } elseif (is_int($element)) { $id = $element; $name = $sentence[$id]["value"]; } elseif (is_string($key)) { $name = $key; $id = get_id($name, $sentence); } elseif ($key !== NULL) { $id = $key; $name = $sentence[$id]["value"]; } if ($name !== NULL and $id !== NULL) { $phrase = safe_get($id, safe_get($id, $phrases_others)); if ($phrase !== NULL) { $phrase = " phrase{$phrase}"; } if (array_key_exists("link", $sentence[$id])) { $name = "<a href='{$sentence[$id]['link']}'>{$name}</a>"; } if (array_key_exists("role", $sentence[$id])) { $div = '<div class="role' . $phrase . '">(' . $sentence[$id]["role"] . ')</div>'; } else { $div = NULL; } echo $div; ?> <span class="word" id="tree-<?php echo $id;
function get_template($conj) { return safe_get(0, defaultDB()->searcher()->spart("verb")->name($conj)->only_with_attr(ATTR("template", "true"))->all()); }
function merge_selections($selections) { $this->tense = safe_get("selected-mood-tense", $selections); if (!$this->tense) { $this->tense = "person-3"; } if ($this->tense === "random") { $this->tense = PICK(self::$tenses); } }
<?php require_once '/var/www/config.php'; sro('/Includes/mysql.php'); sro('/Includes/session.php'); sro('/Includes/functions.php'); sro('/PHP5/lib/PHPLang/common.php'); sro('/PHP5/lib/PHPLang/db.php'); sro('/PHP5/lib/PHPLang/translation.php'); if (array_key_exists("id", $_GET) and array_key_exists("path", $_GET) and is_numeric($_GET["id"])) { $w = WORD(defaultDB(), intval($_GET["id"])); $w->read_paths(); $p = PATH($w, $_GET["path"]); echo la_en($p, !safe_get("all_forms", $_GET)); } else { exit("\$_GET was invalid"); }
if (!$options) { continue; } ?> <ul id="<?php echo $id; ?> -selections"><?php foreach ($options as $optionid => $option) { $name = safe_get("name", $option); $default = safe_get("default", $option); if (!$name) { $name = $optionid; } echo "<li>" . $name . ": "; $opts = safe_get("values", $option); if ($opts) { ?> <select data-selection="<?php echo $optionid; ?> "><?php foreach ($opts as $optid => $opt) { if (is_integer($optid)) { $optid = $opt; } $tag = $optid === $default ? "selected" : ""; ?> <option value="<?php echo $optid; ?>
function do_pick($t, $db, &$pick_db, &$reason) { if ($db === NULL) { $db = defaultDB(); } if ($t === NULL) { $reason = "pick was null"; return $t; } elseif (ISOP($t) or ISHTML($t)) { return $t; } elseif (ISPICK($t)) { return $t->rand($db); } elseif (is_string($t)) { return $t; } elseif (is_callable($t)) { $t = _process_value($t, $pick_db, $db); if ($t === NULL) { $reason = "custom function returned NULL"; return $t; } else { return do_pick($t, $db, $pick_db, $reason); } } elseif (array_key_exists("condition", $t) and !$t["condition"]($pick_db, $db, null)) { return FALSE; } elseif (array_key_exists("value", $t)) { return _process_value($t["value"], $pick_db, $db); } if (!($word = safe_get("word", $t))) { $searcher = $db->searcher(); #var_dump(array_keys($searcher->master)); if (array_key_exists("name", $t)) { $searcher = $searcher->name(_process_value($t["name"], $pick_db, $db)); } if (array_key_exists("language", $t)) { $searcher = $searcher->lang(_process_value($t["language"], $pick_db, $db)); } elseif (array_key_exists("lang", $t)) { $searcher = $searcher->lang(_process_value($t["lang"], $pick_db, $db)); } if (array_key_exists("speechpart", $t)) { $searcher = $searcher->partofspeech(_process_value($t["speechpart"], $pick_db, $db)); } elseif (array_key_exists("spart", $t)) { $searcher = $searcher->partofspeech(_process_value($t["spart"], $pick_db, $db)); } if (array_key_exists("attr", $t)) { foreach ($t["attr"] as $k => $v) { $v = _process_value($v, $pick_db, $db); if ($reverse = substr($k, 0, 1) === "!") { $k = substr($k, 1); $m = "only_without_attr"; } else { $m = "only_with_attr"; } $searcher = $searcher->{$m}($v !== NULL ? ATTR($k, $v) : ATTR($k)); } } $word = $searcher->rand(); } if (!ISWORD($word)) { $reason = "could not find a word with name " . var_export($t["name"], 1) . " and attrs " . var_export(safe_get("attr", $t), 1); return; } if (array_key_exists("store_word", $t)) { $pick_db[$t["store_word"]] = $word; } $word->read_paths(); $path = PATH($word); if (array_key_exists("path", $t)) { $p = $t["path"]; if (!is_array($p)) { $p = _process_value($p, $pick_db, $db, $path); } foreach ($p as $k => $_) { $path->add2([$k => _process_value($_, $pick_db, $db, $path)]); } } if (array_key_exists("verb-gender", $t)) { $g = $t["verb-gender"]; $g = _process_value($g, $pick_db, $db, $path); if ($g !== NULL and $path->exists()) { $path->add($g); if (!$path->hasvalue()) { $path->take("gender"); } } } if ($path->hasvalue() || !(string) $path) { $ret = $path->hasvalue() ? $path->get() : $word->name(); if (array_key_exists("store", $t)) { $pick_db[$t["store"]] = $ret; } if (array_key_exists("store_path", $t)) { $pick_db[$t["store_path"]] = $path; } return format_word($ret, $word->lang()); } else { $reason = "path '{$path}' didn't exist in word with id <a target='_blank' href='dictionary.php?id=" . $word->id() . "'>" . $word->id() . "</a> or was NULL"; return; } }
$id = get_id($name, $sentence); } elseif (is_int($element)) { $id = $element; $name = $sentence[$id]["value"]; } elseif (is_string($key)) { $name = $key; $id = get_id($name, $sentence); } elseif ($key !== NULL) { $id = $key; $name = $sentence[$id]["value"]; } if ($name !== NULL and $id !== NULL) { $dataphrase = ""; $phrase = safe_get($id, safe_get($id, $phrases_others)); if ($parent !== NULL and is_array(safe_get("role", $sentence[$id]))) { $phrase = safe_get($parent, safe_get($parent, $phrases_others)); } /**/ if ($phrase !== NULL) { $dataphrase = " data-phrase='{$phrase}'"; $phrase = " phrase{$phrase}"; } if (array_key_exists("link", $sentence[$id])) { $name = "<a href='{$sentence[$id]['link']}'>{$name}</a>"; } if (array_key_exists("role", $sentence[$id])) { $role = $sentence[$id]["role"]; if (is_array($role)) { $role = array_shift($sentence[$id]["role"]); } $div = '<div class="role' . $phrase . '">(' . $role . ')</div>';
function display_word_name($w, &$common = false) { $lang = $w->lang(); $spart = $w->speechpart(); $name = NULL; if ($lang === "la") { if ($spart === "noun") { if ($genders = $w->path()->iterate("gender")) { $name = []; $common = true; if ($name !== NULL and in_array($g = "masculine", $genders)) { $key = PATH($w, "nominative/singular/{$g}"); if (!$key->hasvalue()) { $name = NULL; } else { $name[] = $key->get(); $key = PATH($w, "genitive/singular/{$g}"); if (!$key->hasvalue()) { $name = NULL; } else { $name[] = $key->get(); } } } else { $common = false; } if ($name !== NULL and in_array($g = "feminine", $genders)) { $key = PATH($w, "nominative/singular/{$g}"); if (!$key->hasvalue()) { $name = NULL; } else { $name[] = $key->get(); $key = PATH($w, "genitive/singular/{$g}"); if (!$key->hasvalue()) { $name = NULL; } else { $name[] = $key->get(); } } } else { $common = false; } if ($name !== NULL and in_array($g = "neuter", $genders)) { $key = PATH($w, "nominative/singular/{$g}"); if (!$key->hasvalue()) { $name = NULL; } else { $name[] = $key->get(); $key = PATH($w, "genitive/singular/{$g}"); if (!$key->hasvalue()) { $name = NULL; } else { $name[] = $key->get(); } } $common = false; } if ($common and count($name) === 4 and $name[0] == $name[2] and $name[1] == $name[3]) { $name = [$name[0], $name[1]]; } else { $common = false; } } } elseif ($spart === "pronoun") { if ($genders = $w->path()->iterate("gender")) { $name = []; if ($name !== NULL and in_array($g = "masculine", $genders)) { $key = PATH($w, "nominative/singular/{$g}"); if (!$key->hasvalue()) { $name = NULL; } else { $name[] = $key->get(); } } if ($name !== NULL and in_array($g = "feminine", $genders)) { $key = PATH($w, "nominative/singular/{$g}"); if (!$key->hasvalue()) { $name = NULL; } else { $name[] = $key->get(); } } if ($name !== NULL and in_array($g = "neuter", $genders)) { $key = PATH($w, "nominative/singular/{$g}"); if (!$key->hasvalue()) { $name = NULL; } else { $name[] = $key->get(); } } if (count($name) == 2 and $name[0] === $name[1] or count($name) == 3 and $name[0] === $name[1] and $name[1] === $name[2]) { $name = [$name[0]]; $key = PATH($w, "nominative/plural"); if ($key->hasvalue()) { $name[] = $key->get(); } } } } elseif ($spart === "adjective") { $name = []; $number = safe_get(0, PATH($w, "positive")->iterate("number")); $keys = ["" => ["positive/nominative/{$number}/masculine", "positive/nominative/{$number}/feminine", "positive/nominative/{$number}/neuter"], "adjective-12" => ["positive/nominative/{$number}/masculine", "positive/nominative/{$number}/feminine", "positive/nominative/{$number}/neuter"], "adjective-3" => ["positive/nominative/{$number}/masculine", "positive/nominative/{$number}/neuter", "positive/genitive/{$number}/masculine"], "adjective-3-3" => ["positive/nominative/{$number}/masculine", "positive/nominative/{$number}/feminine", "positive/nominative/{$number}/neuter"]]; $keys = $keys[ATTR($w, "declension")->get()]; foreach ($keys as $_ => $key) { $key = PATH($w, $key); if (!$key->hasvalue()) { $name = NULL; break; } $name[] = $key->get(); } } elseif ($spart === "verb") { $name = []; foreach (["indicative/active/present/person-1/singular", "infinitive/active/present", "indicative/active/perfect/person-1/singular", "participle/perfect/passive"] as $_ => $key) { $key = PATH($w, $key); if (!$key->hasvalue()) { if ($_ <= 1) { $name = NULL; break; } elseif ($_ == 3) { $key = PATH($w, "supine/accusative"); if (!$key->hasvalue()) { continue; } } else { continue; } } $name[] = $key->get(); } } } if ($name === NULL) { $name = $w->name(); } else { $name = implode(", ", array_map("modify_options", $name)); } if (no_format($w)) { $name = $w->name(); } else { $name = format_word($name, $w->lang()); } return $name; }
function which3($lang, $spart, $key, $N = NULL, $given = NULL, $rand = NULL, $name = NULL) { global $OP_MULTIPLE_CHOICE; global $OP_PARAGRAPH; global $OP_LPAREN; global $OP_RPAREN; global $OP_LQUOTE; global $OP_RQUOTE; $selections = []; $path = []; $mgr = defaultDB()->get_mgr($lang, $spart); $given = PATH($mgr, $given); $_gender = null; if ($N === NULL) { $N = count($mgr->key2values[$key]); } $selections["answers"] = PICK($N, $key, safe_get($key, $rand))->l($lang); $recurse = function ($mgr) use(&$_gender, $spart, $given, &$recurse, &$path, $rand, &$selections, $lang) { foreach ($mgr->simple_keys as $k) { if ($given->key_exists($k)) { $path[] = $given->key_value($k); } else { if ($k === "gender" and $spart === "verb") { $_gender = make_pick(PICK($k, safe_get($k, $rand))->l($lang), $k); } else { $path[] = make_pick(PICK($k, safe_get($k, $rand))->l($lang), $k); } } } foreach ($mgr->recursive_keys as $k) { if ($given->key_exists($k)) { $path[] = $given->key_value($k); $recurse($mgr->level[$k][$given->key_value($k)]); } } }; $recurse($mgr); $answers = []; $selections[$key] = function ($pick_db) { error_log(var_export($pick_db, 1)); return $pick_db["answers"][0]; }; for ($v = 0; $v < $N; $v++) { $answers[] = ["correct" => function ($pick_db) use($v) { return safe_get($pick_db["answers"][$v], $pick_db); }, "value" => function ($pick_db) use($v) { return $pick_db["answers"][$v]; }]; } $ret = ["help" => "What {$key} is this word?", "selections" => $selections, "sentence" => [["lang" => $lang, "speechpart" => $spart, "path" => $path, "attr" => ["!template" => NULL, "!hidden" => NULL], "store_word" => "word", "store" => "result"], function (&$pick_db) use($key) { global $mysqli; $query = $mysqli->prepare("\n\t\t\t\t\tSELECT form_tag FROM forms\n\t\t\t\t\tWHERE word_id = (?)\n\t\t\t\t\tAND form_value = (?)\n\t\t\t\t"); $res = NULL; sql_getmany($query, $res, ["is", $pick_db["word"]->id(), $pick_db["result"]]); $query->close(); foreach ($res as $tag) { $p = PATH($pick_db["word"], $tag); $v = $p->key_value($key); $pick_db[$v] = TRUE; } return FALSE; // No word }, $OP_PARAGRAPH, $OP_MULTIPLE_CHOICE], "choices0" => $answers, "choices0-tooltip" => "What {$key}?", "choices0-language" => "en"]; if ($name !== null) { $ret["sentence"][0]["name"] = $name; } if ($_gender !== null) { $ret["sentence"][0]["verb-gender"] = $_gender; } return $ret; }
<br><span data-i18n="dictionary.parts_of_speech">Part(s) of speech</span>: <select id="enter-sparts" style="width: 300px;"></select> <br><span data-i18n="dictionary.definitions">Definition(s)</span>: <input id="enter-defs" type="text" value="<?php echo safe_get('def', $_GET); ?> " placeholder="definition_part; definition1, definition2,; ..."> <br><span data-i18n="dictionary.attributes">Attribute(s)</span>: <input id="enter-attrs" type="text" value="<?php echo safe_get('attr', $_GET); ?> " placeholder="[!]attr[=value], ..."> <br> ID: <input id="enter-ids" style="width: 100px;" type="text" value="<?php echo safe_get('id', $_GET); ?> " placeholder="id, ..."> <button onclick="dict.refreshEntries();" data-i18n="ui.search">Search</button> <?php if ($editor) { ?> <button onclick="dict.addEntry(function(){dict.refreshEntries();});" data-i18n="ui.add">Add</button> <?php } ?> <button onclick="$('#enter-attrs,#enter-ids,#enter-names,#enter-forms,#enter-langs,#enter-sparts').val('').change();" data-i18n="ui.clear_fields">Clear fields</button> <div class="navigation"> <span data-i18n="dictionary.show">Show</span> <select id="limit"> <?php
<?php require_once '/var/www/config.php'; sro('/Includes/mysql.php'); sro('/Includes/session.php'); sro('/Includes/functions.php'); sro('/PHP5/lib/PHPLang/common.php'); sro('/PHP5/lib/PHPLang/display.php'); sro('/PHP5/lib/PHPLang/string.php'); sro('/PHP5/lib/PHPLang/misc.php'); $input = $_GET["input"]; $syntax = $_GET["syntax"]; $dict = nano_dfdict(); global $DEBUG_STRING_PHP; $expression = nanomacro($syntax, $dict, 4); $DEBUG_STRING_PHP = safe_get("debug", $_GET) === "true"; $permutation = permute_syntax($expression); ob_start(); $result = compare_syntax3($syntax, $input, $dict, !!safe_get("matchall", $_GET), safe_get("dist", $_GET)); $log = ob_get_contents(); ob_end_clean(); echo json_encode(["expression" => $expression, "result" => $result, "log" => $log, "permutation" => $permutation]);
function compare_syntax($ss, $i, $flags, &$others = NULL, $dist = 0) { global $DEBUG_STRING_PHP; if (safe_get("unescaped", $flags)) { $ss = swap3($ss, ["(", ")", "[", "]", "{", "}", "|"]); } /**/ $matchall = !!safe_get("matchall", $flags); unset($flags["matchall"]); if ($DEBUG_STRING_PHP) { echo "compare_syntax '{$ss}' and '{$i}'<ol>"; } //echo " -> '$ss'"; $flags["unescaped"] = false; if (safe_get("max_distance", $flags) == NULL) { $flags["max_distance"] = 0; } $i = no_specials2($i); if (strpos($ss, "\\") === false) { $m = match($i, $ss, $flags, $dist); if ($DEBUG_STRING_PHP) { echo "</ol>"; } if ($m === null or $matchall and strlen($m) + $dist > $flags["max_distance"]) { return null; } else { return $ss; } } //var_dump(split1($ss)); $rr = null; foreach (split1($ss) as $s) { $r = compare_part($s, $i, $flags); if ($r !== null and $others !== null and !in_array($r, $others)) { $others[] = $r; } if ($r !== null and ($rr === null or strlen($r) > strlen($rr))) { $rr = $r; } if ($DEBUG_STRING_PHP) { echo "<hr>"; } } if ($others !== null) { $others = array_values(array_diff($others, [$rr])); } // remove "correct" match if ($DEBUG_STRING_PHP) { var_dump($rr); } if ($DEBUG_STRING_PHP) { echo "</ol>"; } if ($matchall) { $d = 0; $m = match($i, $rr, $flags, $d, true); if ($DEBUG_STRING_PHP) { var_dump($d, $m, $i, $rr); } //if ($d !== $dist) die("internal error 2"); $dist = $d; $r = strlen($m) + $dist <= $flags["max_distance"]; if ($DEBUG_STRING_PHP) { echo $r ? "{$rr} ≈ {$i}" : "{$rr} !≈ {$i}"; } if (!$r) { return NULL; } } return $rr; }
$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 = []; } 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"); if ($ids === NULL) { $searcher = defaultDB()->searcher(); if ($names) { $searcher = $searcher->name_includes($names); } if ($langs) { $searcher = $searcher->lang($langs); } if ($sparts) { $searcher = $searcher->spart($sparts); } if ($no_definitions) { $searcher = $searcher->no_definitions(); } if ($no_templates) {
<?php require_once '/var/www/config.php'; sro('/Includes/mysql.php'); sro('/Includes/session.php'); sro('/Includes/functions.php'); sro('/PHP5/lib/PHPLang/db.php'); sro('/PHP5/lib/PHPLang/display.php'); sro('/PHP5/lib/PHPLang/string.php'); if (!headers_sent()) { header("access-control-allow-origin: *"); } global $mysqli; $actual_link = "https://latin.cipherboy.com/PHP5/quiz/smallquiz.php?{$_SERVER['QUERY_STRING']}"; $la = safe_get("lang", $_GET); if (!$la) { $la = "la"; } $db = defaultDB(); $s = $db->searcher(); $s->stmt .= "\n\tWHERE word_id IN (\n\t\tSELECT word_id FROM definitions\n\t\tWHERE def_lang = 'en'\n\t\tAND def_type IS NULL\n\t)\n\tAND word_lang = '{$la}'\n\tAND word_id NOT IN (\n\t\tSELECT word_id FROM attributes\n\t\tWHERE attr_tag = 'template' OR attr_tag = 'hidden'\n\t)\n\tORDER BY RAND() LIMIT 1"; $s->args = []; $word = $s->rand(); $query = $mysqli->prepare("\n\tSELECT DISTINCT def_id FROM definitions\n\tWHERE def_lang = 'en'\n\tAND def_type IS NULL\n\tAND word_id = (?)\n\tORDER BY rand()\n\tLIMIT 1\n"); $res0 = NULL; sql_getmany($query, $res0, ["i", $word->id()]); $query->close(); if (!$res0) { exit('An error occurred'); } $query = $mysqli->prepare("\n\tSELECT DISTINCT def_id FROM definitions\n\tWHERE def_lang = 'en'\n\tAND def_type IS NULL\n\tAND word_id != (?)\n\tAND def_value != ''\n\tAND def_value != (?)\n\tAND word_id in (\n\t\tSELECT word_id FROM words WHERE word_lang = '{$la}'\n\t)\n\tAND word_id NOT IN (\n\t\tSELECT word_id FROM attributes\n\t\tWHERE attr_tag = 'template' OR attr_tag = 'hidden'\n\t)\n\tORDER BY RAND() LIMIT 4\n");
require_once '/var/www/config.php'; sro('/Includes/mysql.php'); sro('/Includes/session.php'); sro('/Includes/functions.php'); sro('/PHP5/lib/PHPLang/db.php'); if (!requireRank(3, FALSE)) { echo "Insufficient permissions"; } else { if (array_key_exists("id", $_GET) and array_key_exists("val", $_GET) and array_key_exists("path", $_GET) and is_numeric($_GET["id"])) { $w = WORD(defaultDB(), intval($_GET["id"])); $d = DEFINITION(defaultDB(), NULL, $w); if (safe_get("lang", $_GET)) { $d->set_lang($_GET["lang"]); } else { $d->set_lang("en"); } if (safe_get("type", $_GET)) { $d->set_type($_GET["type"]); } $d->set_value($_GET["val"]); if (safe_get("path", $_GET)) { $p = PATH($w, $_GET["path"]); $d->set_path($p); } $d = $w->add_definition($d); exit("success"); } else { exit("\$_GET was invalid (" . var_export($_GET, 1) . ")"); } }
sro('/PHP5/lib/PHPLang/make_example.php'); sro('/PHP5/lib/PHPLang/display.php'); include_once 'quiz_types.php'; global $quiz_types; $type = array_key_exists("type", $_POST) ? $_POST["type"] : NULL; $last = array_key_exists("last", $_POST) ? $_POST["last"] : NULL; $mode = array_key_exists("mode", $_POST) ? $_POST["mode"] : 'page'; if ($type !== NULL and $last and array_key_exists($type, $quiz_types) and is_array($quiz_types[$type]) and array_key_exists("options", $quiz_types[$type]) and safe_get("name", $quiz_types[$type])) { $quiz = $quiz_types[$type]; if (safe_get("modes", $quiz) and !in_array($mode, $quiz["modes"])) { exit("Please select a mode valid for the quiz"); } $selections = []; if (safe_get("user_selections", $quiz)) { foreach ($quiz["user_selections"] as $k => $desc) { $v = safe_get("selected-{$k}", $_POST); // TODO: validate $selections["selected-{$k}"] = $v; } } $q = NEWQUIZ($type, $last, $mode, $selections); if ($q !== NULL) { if ($q->id()) { exit("" . $q->id()); } else { exit("success"); } } else { exit("no-credit"); } } else {
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()); } if (!is_array($answers)) { $reason = "answers were not in an array"; return $try(); } $process = function ($answer) use($dopick, &$stop, &$correct, $lang) { if ($stop) { return; } $ret = $dopick($answer, TRUE); if ($ret === NULL) { $stop = TRUE; } else {
echo "<a href=index.php?cmd=ticket_reason_up&id={$r['0']}>上移<a/> "; echo "<a href=index.php?cmd=ticket_reason_down&id={$r['0']}>下移<a/> "; echo " </td>"; } echo "</tr>\n"; } echo "</table>"; ?> <?php exit(0); } // end cmd==sysinfo // USER_PREF if ($cmd == "user_pref_tdm") { $tdm = safe_get("tdm"); $user = $_SESSION["user"]; if ($tdm != "1") { $tdm = "0"; } $q = "replace into userpref values('{$user}','ticketdisplaymode','{$tdm}')"; mysql_query($q); $cmd = "user_pref"; } if ($cmd == "user_pref") { echo $_SESSION["truename"]; echo " From: "; echo $_SERVER["REMOTE_ADDR"]; echo "<p>"; echo "个人偏好设置<p>"; $tdm = getticketdisplaymode();
static function use_hint($n) { $all_hints = self::all_hints(); $hints =& $all_hints[count($all_hints) - 1]; if (!safe_get($n, $hints[0])) { return; } // hint does not exist $hints[1] &= 1 << $n; if (gmp_popcount(gmp_init($hints[1])) > $hints[2]) { return; } // hint already used self::set_hints($all_hints); return $hints[0][$n]; }
$subscore = 0; $out_of = 0; $cquiz = CURRENTQUIZ(); if (!$cquiz) { exit("session timed out"); } if ($cquiz->mode() != "question") { exit("Checking answers is not allowed for this quiz (mode: " . $cquiz->mode() . ")"); } $flags = ["unescaped" => TRUE, "matchall" => TRUE]; $name = safe_get("name", $_POST); if (!$name) { exit("no key name supplied"); } $values = $cquiz->answers()[$name]; $answer = safe_get("answer", $_POST); if (!$answer) { exit("no answer supplied"); } if (array_key_exists("correct", $values) and is_array($values["correct"]) and array_key_exists("expr", $values) and is_string($values["expr"])) { $value = compare_syntax3($values["expr"], $answer, nano_dfdict(), true); if ($value === null) { echo "false"; } else { echo "true"; } } else { if (array_key_exists("correct", $values) and array_key_exists("acceptable", $values) and is_array($values["correct"]) and is_array($values["acceptable"])) { $also = $values["correct"]; $correct = $values["correct"]; $values = $values["acceptable"];
<?php require_once '/var/www/config.php'; sro('/Includes/mysql.php'); sro('/Includes/session.php'); global $suid; if (!$suid) { sro('/Pages/restricted/logged-out.php'); die; } sro('/Includes/functions.php'); sro('/PHP5/quiz/common.php'); sro('/PHP5/quiz/quiz_types.php'); $master = safe_get("master", $_GET) == "true" and quiz_auth(); ?> <header> <h1>My Quizzes <?php if (!$master and quiz_auth()) { echo "<a href='?master=true'>master</a>"; } ?> </h1> </header> <article id="quiz"> <table style="border-spacing: 8px 2px;"> <tr><th>Select</th> <?php if ($master) { echo "<th>UserName</th>"; } ?>
<?php require_once '/var/www/config.php'; sro('/Includes/mysql.php'); sro('/Includes/session.php'); sro('/Includes/functions.php'); sro('/PHP5/lib/PHPLang/common.php'); sro('/PHP5/lib/PHPLang/db.php'); sro('/PHP5/lib/PHPLang/display.php'); global $sql_stmts; $db = defaultDB(); if (safe_get("lang", $_GET)) { $langs = [$_GET["lang"]]; } else { $langs = ['la']; } ?> <select><?php foreach ($db->langs() as $l) { $name = $l; sql_getone(sql_stmt("lang_id->#words"), $words, ["s", $l]); $c = count($words); if ($words < 10) { continue; } sql_getone(sql_stmt("lang_id->lang_dispname"), $name, ["s", $l]); ?> <option <?php if (in_array($l, $langs)) { ?> selected<?php
function __construct($old) { $options = $old["options"]; if (is_callable($options)) { $options = $options(); } foreach ($options as $opt) { if (is_callable($opt)) { $opt = $opt(); } if (!array_key_exists("condition", $opt) || $opt["condition"]()) { $this->options[] = $opt; } } $this->no_shuffle = safe_get("no_shuffle", $old); }
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'); sro('/PHP5/dictionary/search.php'); $_start_t = microtime(true); $editor = requireRank(3, FALSE); $id2vals = "{"; # for JS $dependencies = "{"; $inflection = !(safe_get("no_inflections", $_GET) === "true"); $start = intval(safe_get("start", $_GET)); $limit = intval(safe_get("limit", $_GET)); if ($limit <= 0) { $limit = 5; } if ($limit > 50) { $limit = 50; } if (count($_GET)) { $max_size = NULL; $list = search_GET($limit, $max_size); foreach ($list as $w) { $id = $w->id(); ?> <hr><section id="word<?php echo $id; ?>
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"); }
$stmt = "SELECT DISTINCT {$get} FROM attributes"; $op = " WHERE word_id in (SELECT word_id FROM words WHERE "; if (safe_get("lang", $_GET)) { $stmt .= "{$op} ("; $_ = ""; foreach (explode(",", $_GET["lang"]) as $l) { if (!preg_match("/^[a-zA-Z0-9]+\$/", $l)) { continue; } $stmt .= "{$_} word_lang = '{$l}'"; $_ = " OR "; } $stmt .= ")"; $op = " AND "; } if (safe_get("spart", $_GET)) { $stmt .= "{$op} ("; $_ = ""; foreach (explode(",", $_GET["spart"]) as $l) { if (!preg_match("/^[a-zA-Z0-9]+\$/", $l)) { continue; } $stmt .= "{$_} word_spart = '{$l}'"; $_ = " OR "; } $stmt .= ")"; $op = " AND "; } if ($op === " AND ") { $stmt .= ")"; } else {