global $quiz_types; global $df_exclude; $challenge = function ($spart, $lang = 'la') { return function () use($spart, $lang) { global $OP_USER_INPUT; return [["help" => function (&$pick_db, $db) { $word = $pick_db["word"]; $paths = $pick_db["word"]->read_paths(); $paths = array_filter($paths, function ($p) { return $p->get(); }); $path = $pick_db["path"] = choose_one($paths); error_log(var_export($path->get(), 1)); $pick_db["form"] = $path->get(); $path = implode(" ", array_map("format_path", array_reverse(explode("/", (string) $path)))); $word_name = display_word_name($word); return "What is the {$path} for {$word_name}."; }, "selections" => ["word" => function ($_, $db, $path) use($spart, $lang) { $s = $db->searcher()->spart($spart)->lang($lang)->only_without_attr(ATTR("irregular"))->only_without_attr(ATTR("hidden"))->only_without_attr(ATTR("template")); $s->stmt .= " AND EXISTS (SELECT 1 FROM forms WHERE forms.word_id = words.word_id AND form_tag != '' AND form_value != '')"; return $s->rand(); }], "sentence" => [$OP_USER_INPUT], "answer0" => function ($pick_db) { $map = function ($w) use($pick_db) { return word_link2($pick_db["word"], $w, true, true); }; return array_map($map, explode("\n", $pick_db["form"])); }, "answer0-tooltip" => "Enter form"]]; }; }; $quiz_types = array_merge($quiz_types, ["random-verb-forms1" => ["name" => "Random verb forms", "category" => "Challenge", "lang" => "la", "options" => $challenge("verb")], "random-noun-forms1" => ["name" => "Random noun forms", "category" => "Challenge", "lang" => "la", "options" => $challenge("noun")]]);
function __construct($word, $translation = FALSE) { $this->word = $word; $this->translation = $translation; $this->others = NULL; $this->hints = ["Principal Parts" => display_word_name($word), "Definition" => implode(", ", explode("\n", $word->definitions()[0]->value()))]; $this->selections = ["voice" => PICK(["active", "passive"]), "mood-tense" => PICK(["indicative/present", "indicative/imperfect", "indicative/future", "indicative/perfect", "indicative/pluperfect", "indicative/future-perfect", "subjunctive/imperfect", "subjunctive/pluperfect"])]; }
function display_word_info($w, $can_edit = FALSE) { $id = $w->id(); $lang = $w->lang(); $spart = $w->speechpart(); $common = false; $w->clear_connections(); $connections = $w->connections(); $w->read_paths(); $w->read_attrs(); display_lang($w); ?> <span class="word-name" id="word<?php echo $w->id(); ?> _name"><?php echo display_word_name($w, $common); ?> </span> <?php if ($common) { echo format_abbr("c.", "Common Gender") . " "; } elseif ($lang === "la" and $spart === "noun" and $genders = $w->path()->iterate("gender")) { foreach ($genders as $g) { echo format_abbr($g[0] . ".", capitalize($g)); } echo " "; } $infos = []; /* $stem = $w->path(); if ($stem->hasvalue()) $infos[] = format_word(str_replace("\n", ", ", $stem->get())); */ $infos[] = $spart; foreach ($w->read_attrs() as $attr) { if ($attr->tag()[0] != "-") { $infos[] = format_attr($attr->tag(), $attr->value()); } } ?> (<?php echo implode("; ", $infos); ?> )<?php if ($can_edit !== NULL and $can_edit) { $slug = slugify($w, $lang); $class = "word{$id}_toolbox"; ?> <?php display_icon("tools", "Tools", "word{$id}_tools", NULL, "hider hiding2"); ?> <script type="text/javascript"> $(function() { var id = <?php echo $id; ?> ; var state = -1; $('#word'+id+'_tools').on('mousedown', function(e) { if (state === -1) { $(this).removeClass('hiding2'); state = 0; } e.preventDefault(); return false; }).on('mouseup', function(e) { if (state === 0) state = 1; else if (state === 1) { $(this).addClass('hiding2'); state = -1; } e.preventDefault(); return false; }).on('click', function(e){e.preventDefault();return false;}); }); </script> <span class="<?php echo $class; ?> "> <?php display_icon("hardlink", "Link by ID", NULL, "dictionary.php?id={$id}"); ?> <?php display_icon("del", "Delete", "word{$id}_delete"); ?> <script type="text/javascript"> $(function() { var id = <?php echo $id; ?> ; $('#word'+id+'_delete').on("click", function() { dict.word_delete(id); }); }); </script> <?php display_icon("rename", "Rename", "word{$id}_rename"); ?> <script type="text/javascript"> $(function() { var id = <?php echo $id; ?> ; $('#word'+id+'_rename').on("mouseup.rename", function() { dict.word_rename(id, "<?php echo $w->name(); ?> "); }); }); </script> <?php display_icon("refresh", "Refresh", "word{$id}_refresh"); ?> <script type="text/javascript"> $(function() { var id = <?php echo $id; ?> ; $('#word'+id+'_refresh').on("mouseup.refresh", function() { dict.word_refresh(id); }); }); </script> <?php display_icon("change POS", "Change Part of Speech", "word{$id}_change_POS"); ?> <script type="text/javascript"> $(function() { var id = <?php echo $id; ?> ; $('#word'+id+'_change_POS').on('mouseup', function() { var pos = prompt('What part of speech?', '<?php echo $spart; ?> '); if (pos) dict.word_change_POS(id, pos); }); }); </script> </span> (size: <?php echo count($w->paths()); ?> ) <div class="<?php echo $class; ?> "> <a href="http://en.wiktionary.org/wiki/<?php echo $slug; ?> #<?php echo format_lang($w); ?> " target="_blank">Wiktionary</a> <?php if ($w->lang() === "la") { ?> – <a href="http://www.perseus.tufts.edu/hopper/text?doc=Perseus:text:1999.04.0059:entry=<?php echo $slug; ?> " target="_blank">Lewis & Short</a> <?php } ?> <br> Pronunciation: <input id="word<?php echo $id; ?> _pronunciation_tool"> <span></span> </div> <script> $(function() { var transform = la_ipa.transforms["IPA transcription"]; $('#word<?php echo $id; ?> _pronunciation_tool').on('keyup', function() { var $this=$(this); $this.next().text(transform($this.val())); }); }); </script> <?php } $made_div = FALSE; $first = TRUE; $last_type = NULL; $using = []; $from = []; $sep = ""; foreach ($connections as $c) { if (!$made_div) { ?> <div class="word-more-info"><?php $made_div = TRUE; } if ($c->type() === "prefix") { $using[] = $c->to(); } elseif ($c->type() === "etymon") { $from[] = $c->to(); } } if ($from) { if (!$made_div) { ?> <div class="word-more-info"><?php $made_div = TRUE; } echo "From "; foreach ($using as $u) { word_link($u, $u->lang() === $w->lang()); echo " + "; } $sep = ""; foreach ($from as $u) { word_link($u, $u->lang() === $w->lang()); echo $sep; $sep = ", from "; } ?> <br><?php } if ($sep === ", from ") { ?> <br><?php } foreach ($w->pronunciations() as $pron) { if ((string) $pron->path()) { continue; } if (!$pron->value()) { continue; } if (!$made_div) { ?> <div class="word-more-info"><?php $made_div = TRUE; } if (!$first and $pron->type() === $last_type) { ?> ; <?php } else { if (!$first) { ?> <br><?php } echo $pron->type() . ": "; } $last_type = $pron->type(); if ($pron->sublang()) { ?> <sup>[<?php echo $pron->sublang(); ?> ]</sup><?php } ?> [<?php echo format_pron($pron->value()); ?> ]<?php $first = FALSE; } if ($made_div) { ?> </div><?php } if ($can_edit) { ?> <div> <input id="word<?php echo $id; ?> _value_attr" type="text" placeholder="[!]attr[=value]; ..." required> <button id="word<?php echo $id; ?> _button_enter_attr" onclick="dict.word_add_attr(<?php echo $id; ?> )">Add</button> <button id="word<?php echo $id; ?> _button_clear_attr" onclick="$('#word<?php echo $id; ?> _value_attr').val('')">Clear</button> </div> <script type="text/javascript"> $(function() { var id = <?php echo $id; ?> ; $('#word'+id+'_value_attr').keypress(function(e){if (e.which == 13)dict.word_add_attr(<?php echo $id; ?> )}); var lock=false; var splitter = /,\s*/; var last1 = $('#enter-names').val().split(splitter); var last2 = $('#enter-attrs').val().split(splitter); function getcheckbox(name) { var ret=[]; $('input:checkbox[name="'+name+'"]:checked:visible').each(function() { ret.push($(this).val()); }); return ret.join(); } $('#word'+id+'_value_attr').autocomplete(autocompletions['word-attributes'](id,'<?php echo $lang; ?> ','<?php echo $spart; ?> ')); }); </script> <?php } }
$res = array_merge($res0, $res1); $options = []; foreach ($res as &$r) { $options[] = str_replace("\n", ", ", definition($db, $r)->value()); } $correct = $options[0]; shuffle($options); $indices = array_keys($options); shuffle($indices); $correct_index = array_values(array_filter($indices, function ($i) use($options, $correct) { return $options[$i] == $correct; }))[0]; ?> <div id="pantheumsmallquiz"> <h3 style="margin-top:0px;margin-bottom:0.2em;"><?php echo display_word_name($word); ?> <span data-i18n="can_mean">can mean</span>...</h3> <div style="margin-bottom:0.2em;font-size:90%;" id="pantheumsmallquiz-time"> <a href="javascript:void(0)"> <span> </span> </a> </div> <span id="pantheumsmallquiz-answer" class="select select-bordered reverse-indent-label"> <label><input name="pantheumsmallquiz" class="inputlabel" type="radio" value="<?php echo $indices[0]; ?> " required><?php echo $options[$indices[0]]; ?> </label><br>
function make_chart2($w, $w2, $values = NULL, $ignore = NULL, $legend = "this chart", $add = NULL, $basepath = NULL) { ob_start(); if ($values === NULL) { $values = word_table_values($w, $ignore); list($values0, $values1, $values2, $values3, $values4) = $values; } else { list($values0, $values1, $values2, $values3, $values4) = $values; $values0 = _do_ignore($values0, $ignore); if (is_fillable($values1)) { $values1 = _fill($values1, $values0); } if (is_fillable($values2)) { $values2 = _fill($values2, $values0); } if (is_fillable($values3)) { $values3 = _fill($values3, $values0); } if (is_fillable($values4)) { $values4 = _fill($values4, $values0); } _filter_ignore2($values1, $ignore, PATH($w), $values0); _filter_ignore2($values2, $ignore, PATH($w), $values0, $values1); _filter_ignore2($values3, $ignore, PATH($w), $values0); _filter_ignore2($values4, $ignore, PATH($w), $values0, $values3); } global $OP_USER_INPUT; $w->read_paths(); $w->read_attrs(); $w2->read_paths(); $w2->read_attrs(); if ($add) { $add = ", {$add}"; } $ret = ["help" => "Fill in {$legend} for “" . display_word_name($w) . "” and “" . display_word_name($w2) . "”{$add}.", "selections" => [], "sentence" => []]; $i = 0; $get_question = function ($form, $path) use(&$i, $w2, &$ret, $basepath) { $ret["answer{$i}-hidden"] = TRUE; $ret["answer{$i}"] = ["correct" => [], "acceptable" => []]; $form2 = PATH($w2, $path, $basepath); $form2 = $form2->get(); foreach (explode("\n", $form) as $f) { foreach (explode("\n", $form2) as $f2) { $ret["answer{$i}"]["correct"][] = $f . " " . $f2; $ret["answer{$i}"]["acceptable"][] = $f . " " . $f2; $ret["answer{$i}"]["acceptable"][] = $f2 . " " . $f; } } $ret["answer{$i}-tooltip"] = "Enter form"; $i++; return '<input>'; }; do_table($w, $values0, $values1, $values2, $values3, $values4, $ignore, "format_value", $get_question, NULL, NULL, 0); $table = explode("<input>", ob_get_contents()); ob_clean(); $i = count($table) - 1; foreach ($table as $r) { $ret["sentence"][] = HTML($r); if ($i) { $ret["sentence"][] = $OP_USER_INPUT; } $i -= 1; } return $ret; }