function display_inflection($w, $hidden = TRUE) { if ($c = $w->cached()) { if (($_ = json_decode($c, true)) === NULL) { echo $c; return; } else { $c = $_; } for ($i = 0; $i < count($c); $i++) { if ($i === 0) { echo $c[$i]; } else { echo format_word($c[$i]); } } return; } else { ob_start(); } $pronunciations = $w->pronunciations(); //error_log($pronunciations); $w->clear_connections(); $connections = $w->connections(); list($values0, $values1, $values2, $values3, $values4) = word_table_values($w); if (!$values0 and !$values1 and !$values3 and !$values4 and !$values2) { ?> <span id="word<?php echo $w->id(); ?> _forms">(No inflection for this word)</span><?php return; } ?> Inflection <?php display_icon("visibility", $hidden ? "Show" : "Hide", "toggle-forms" . $w->id()); if ($pronunciations) { ?> <span id="toggle-pronunciations<?php echo $w->id(); ?> _outer"> [<a href="javascript:void(0)" id="toggle-pronunciations<?php echo $w->id(); ?> ">show IPA</a>]<br><br> </span><?php } ?> <span id="toggle-quizzing<?php echo $w->id(); ?> _outer"> [<a href="javascript:void(0)" id="toggle-quizzing<?php echo $w->id(); ?> ">cover forms</a>]<br><br> </span><?php do_table($w, $values0, $values1, $values2, $values3, $values4, NULL, "format_value", function ($v, $p) use($w) { return format_word($p, $w->lang(), true); }, function ($p) use($connections) { $p = (string) $p; foreach ($connections as $connect) { if ($connect->type() === $p) { return $connect->to(); } } }, function ($p) use($pronunciations, $w) { $p = (string) $p; $made_div = FALSE; $last_type = NULL; $first = TRUE; foreach ($pronunciations as $pron) { if ((string) $pron->path() !== $p) { continue; } if ($pron->type() !== "IPA") { continue; } if (!$made_div) { ?> <span class="word<?php echo $w->id(); ?> _pronunciation"><?php $made_div = TRUE; } ?> <br><?php $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) { ?> </span><?php } }); ?> <script type="text/javascript"> $(function(){ var c = "<?php echo $w->id(); ?> "; var selector = $('#word'+c+'_forms, #toggle-pronunciations'+c+'_outer, #toggle-quizzing'+c+'_outer'); $('#toggle-forms'+c).click(function () { selector.toggle(); var vis = $('#word'+c+'_forms').is(':visible'); $('#toggle-forms'+c).attr('title', vis ? 'Hide' : 'Show'); if (!vis) $('.word'+c+'_pronunciation').hide(); }); <?php if (!$hidden) { ?> selector.hide(); <?php } ?> $('#toggle-forms'+c).trigger("click"); $('#toggle-pronunciations'+c).click(function () { $('.word'+c+'_pronunciation').toggle(); $('#toggle-pronunciations'+c).attr('title', $('.word'+c+'_pronunciation').is(':visible') ? 'hide IPA' : 'show IPA'); }); $('#toggle-quizzing'+c).click(function () { $('#word'+c+' td').addClass('hidden').on('click', function() {$(this).removeClass('hidden').off('click')}); }); $('.word'+c+'_pronunciation, #toggle-pronunciations').hide(); }); </script> <?php $w->set_cached(ob_get_contents()); ob_end_flush(); }
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; }