示例#1
0
 function get_mgrW($w)
 {
     if (!ISWORD($w)) {
         $w = WORD($this, $w);
     }
     return $this->get_mgr($w->lang(), $w->speechpart());
 }
示例#2
0
 function &resolve_hash(&$hash)
 {
     if (ISWORD($hash)) {
         return $hash->path_storage;
     }
     if ($hash === NULL and $this->word() !== NULL) {
         if ($this->word()->path_storage !== NULL) {
             return $this->word()->path_storage;
         }
         #elseif ($this->word()->db() !== NULL)
         #	return $this->word()->db();
     }
     return $hash;
 }
function do_table($w, $values0, $values1, $values2, $values3, $values4, $ignore, $format_value, $format_word, $get_link = NULL, $extras = NULL, $optimization = 0)
{
    ?>
<div class="scrollable"><?php 
    if ($values1 and !$values2 and !$values3 and !$values4 and !$values0) {
        ?>
<table class="text-center inflection inflection-small" id="word<?php 
        echo $w->id();
        ?>
_forms"><?php 
        foreach ($values1[false] as $_1) {
            ?>
<tr><th><?php 
            echo format_value($_1);
            ?>
</th></tr><tr><td><?php 
            echo format_word(PATH($w, $_1)->get(), $w->lang(), true);
            ?>
</td></tr><?php 
        }
    } else {
        ?>
<table class="text-left inflection" id="word<?php 
        echo $w->id();
        ?>
_forms"><?php 
        $first0 = $last0 = NULL;
        _get_first_last($values0, $first0, $last0);
        if (!$values0) {
            $values0 = [FALSE];
            $values1 = [$values1, "_" => $values1];
            $values2 = [$values2, "_" => $values2];
            $values3 = [$values3, "_" => $values3];
            $values4 = [$values4, "_" => $values4];
        }
        foreach ($values0 as $_key => $_0) {
            $name0 = $_0;
            // FIXME
            if ($name0 === " ") {
                $name0 = FALSE;
            }
            if (!$values1[$_0]) {
                $values1[$_0] = [FALSE];
            }
            if (!$values2[$_0]) {
                $values2[$_0] = [FALSE];
            }
            if (!$values3[$_0]) {
                $values3[$_0] = [FALSE];
            }
            if (!$values4[$_0]) {
                $values4[$_0] = [FALSE];
            }
            $path = PATH($w, $_0);
            if ($_0 !== $first0) {
                // Blank row to separate sub-tables based on $values0
                ?>
<tr><th>&nbsp;</th></tr><?php 
            }
            // values0 : table name
            // values1 : major vertical
            // values2 : minor vertical
            // values3 : major horizontal
            // values4 : minor horizontal
            $_1 = (count($values1[$_0]) > 1 or $values1[$_0][0] !== FALSE);
            ?>
<tr><?php 
            $hspan1 = $_1 !== FALSE ? 2 : 1;
            if ($name0 === FALSE) {
                ?>
<th colspan="<?php 
                echo $hspan1;
                ?>
">&nbsp;</th><?php 
            } else {
                ?>
<th colspan="<?php 
                echo $hspan1;
                ?>
" class="greatest"><?php 
                echo $format_value($name0);
                ?>
</th><?php 
            }
            if ($values3[$_0]) {
                foreach ($values3[$_0] as $_3) {
                    ?>
<th colspan="<?php 
                    echo count($values4[$_0][$_3]);
                    ?>
" class="major"><?php 
                    echo $format_value($_3);
                    ?>
</th><?php 
                }
            }
            ?>
</tr><?php 
            if (!array_key_exists("_", $values4[$_0])) {
                $values4[$_0]["_"] = [];
            }
            if ($values4[$_0]["_"] and $values4[$_0]["_"][0] !== FALSE) {
                ?>
<tr><th colspan="<?php 
                echo $hspan1;
                ?>
">&nbsp;</th><?php 
                foreach ($values3[$_0] as $_3) {
                    if ($values4[$_0][$_3]) {
                        foreach ($values4[$_0][$_3] as $_4) {
                            ?>
<th class="minor"><?php 
                            echo $format_value($_4);
                            ?>
</th><?php 
                        }
                    }
                }
                ?>
</tr><?php 
                $hspan4 = 1;
            } elseif ($values4[$_0]["_"]) {
                $hspan4 = count($values4[$_0]["_"]);
                foreach ($values4[$_0] as &$v) {
                    $v = [""];
                }
            } else {
                $hspan4 = 1;
            }
            foreach ($values1[$_0] as $_1) {
                if ($_1 !== FALSE) {
                    ?>
<tr><?php 
                    ?>
<th colspan="2" class="major"><?php 
                    echo $format_value($_1);
                    ?>
</th><?php 
                    ?>
</tr><?php 
                }
                // Previous row (directly above)
                $p_2 = NULL;
                foreach ($values2[$_0][$_1] as $_2) {
                    ?>
<tr><?php 
                    if ($_1 !== FALSE) {
                        ?>
<th>&nbsp;&nbsp;&nbsp;</th><?php 
                    }
                    ?>
<th class="minor"><?php 
                    echo $format_value($_2);
                    ?>
</th><?php 
                    $row = [];
                    $last = NULL;
                    foreach ($values3[$_0] as $_3) {
                        $acc = [];
                        $i = -1;
                        foreach ($values4[$_0][$_3] as $_4) {
                            $p = PATH($w, $_0, $_1, $_3, $_4, $_2);
                            if ($i < 0 or $p->get() != $last or !$last) {
                                $acc[] = [];
                                $last = $p->get();
                                $i += 1;
                            }
                            $acc[$i][] = [$p, 2 => $_3, $_4];
                        }
                        if (!($optimization & 2) or count($acc) != 1 and count($acc) != count($values4)) {
                            $acc = [];
                            foreach ($values4[$_0][$_3] as $_4) {
                                $p = PATH($w, $_0, $_1, $_3, $_4, $_2);
                                $acc[] = [[$p, 2 => $_3, $_4]];
                            }
                        }
                        $row = array_merge($row, $acc);
                    }
                    $first1 = $last1 = NULL;
                    _get_first_last($values1[$_0], $first1, $last1);
                    $first2 = $last2 = NULL;
                    _get_first_last($values2[$_0][$_1], $first2, $last2);
                    $first3 = $last3 = NULL;
                    _get_first_last($values3[$_0], $first3, $last3);
                    $first4 = $last4 = NULL;
                    _get_first_last($values4[$_0][$_3], $first4, $last4);
                    foreach ($row as $val_group) {
                        $p = $val_group[0][0];
                        $_ = count($val_group) - 1;
                        $_30 = $val_group[0][2];
                        $_40 = $val_group[0][3];
                        $_31 = $val_group[$_][2];
                        $_41 = $val_group[$_][3];
                        if ($_ === 0) {
                            $_3 = $_30;
                            $_4 = $_40;
                            $ditto = ($p_2 and $p->get() and PATH($w, $_0, $_1, $_3, $_4, $p_2)->get() == $p->get());
                        } else {
                            $_3 = $_4 = NULL;
                            $ditto = FALSE;
                        }
                        ?>
<td colspan="<?php 
                        echo $hspan4 * count($val_group);
                        ?>
" <?php 
                        $classes = "";
                        if (!$first4 or $_40 === $first4) {
                            $classes .= " leftline";
                        }
                        if (!$last4 or $_41 === $last4) {
                            $classes .= " rightline";
                        }
                        if (!$first2 or $_2 === $first2) {
                            $classes .= " topline";
                        }
                        if (!$last2 or $_2 === $last2) {
                            $classes .= " bottomline";
                        }
                        if ((!$first4 or $_40 === $first4) and $_30 !== $first3) {
                            $classes .= " leftline";
                        }
                        echo " class='{$classes}' ";
                        if (count($val_group) > 1) {
                            echo " style='text-align: center;'";
                        }
                        ?>
><?php 
                        if ($get_link !== NULL) {
                            $link = $get_link($p);
                        } else {
                            $link = NULL;
                        }
                        if (ISWORD($link)) {
                            $link = "dictionary.php?id=" . $link->id();
                        }
                        if ($link) {
                            ?>
<a class="word-ref" href="<?php 
                            echo $link;
                            ?>
"><?php 
                        }
                        if (!_in_ignore($p, $ignore) or !$p->hasvalue()) {
                            $val = $format_word($p->get(), $p);
                        } else {
                            $val = '<abbr class="symbolic" title="You\'ve not learned this yet">—</abbr>';
                        }
                        if (count($val_group) > 1) {
                            $val = "" . "<span style='float: right;'>→</span>" . "<span style='float: left;'>←</span>" . $val;
                        } elseif ($ditto and $optimization & 1) {
                            $val = "&nbsp;&nbsp;&nbsp;&nbsp;&#8243;";
                            # ditto mark
                            $val = "&nbsp;&#x2044;&nbsp;&#x2044;";
                            #echo "↓";
                        }
                        echo $val;
                        if ($link) {
                            ?>
</a><?php 
                        }
                        if ($extras !== NULL) {
                            $extras($p);
                        }
                        ?>
</td><?php 
                    }
                    ?>
</tr><?php 
                    $p_2 = $_2;
                }
            }
        }
    }
    ?>
</table></div><?php 
}
示例#4
0
function DEPATH($init = NULL, $aliases = NULL, $name = NULL)
{
    if (function_exists("ISWORD") and ISWORD($init)) {
        return $init->mgr();
    } else {
        return new _DEPATH($init, $aliases, $name);
    }
}
示例#5
0
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;
    }
}
示例#6
0
function display_lang($lang)
{
    if (ISWORD($lang)) {
        $lang = $lang->lang();
    }
    ?>
<sup>[<?php 
    echo $lang;
    ?>
]</sup><?php 
}