Пример #1
0
 private function editOrSave($action)
 {
     $validations = array("exists" => array("Slug" => slug(POST("title", "clean")), "Year" => date("Y"), "Month" => date("m"), "Day" => date("d"), "Language" => POST("language")), "title" => "required", "content" => "required");
     $this->categories = POST("categories");
     $this->tags = POST("tags");
     $this->URL = PATH("blog/" . date("Y")) . "/" . date("m") . "/" . date("d") . "/" . slug(POST("title", "clean"));
     $this->muralExist = POST("mural_exist");
     $this->Files = $this->core("Files");
     $this->mural = FILES("mural");
     if ($this->mural["name"] !== "") {
         $dir = "www/lib/files/images/mural/";
         $this->mural = $this->Files->uploadImage($dir, "mural", "mural");
         if (is_array($this->mural)) {
             return $this->mural["alert"];
         }
     }
     $dir = "www/lib/files/images/blog/";
     $this->image = $this->Files->uploadImage($dir, "image", "resize", TRUE, TRUE, FALSE);
     $data = array("ID_User" => SESSION("ZanUserID"), "ID_URL" => 1, "Slug" => slug(POST("title", "clean")), "Content" => POST("content", "clean"), "Author" => SESSION("ZanUser"), "Year" => date("Y"), "Month" => date("m"), "Day" => date("d"), "Image_Small" => isset($this->image["small"]) ? $this->image["small"] : NULL, "Image_Medium" => isset($this->image["medium"]) ? $this->image["medium"] : NULL, "Pwd" => POST("pwd") ? POST("pwd", "encrypt") : NULL, "Start_Date" => now(4), "Text_Date" => now(2));
     $this->Data->ignore(array("categories", "tags", "mural_exists", "mural", "pwd", "category", "language_category", "application", "mural_exist"));
     $this->data = $this->Data->proccess($data, $validations);
     if (isset($this->data["error"])) {
         return $this->data["error"];
     }
 }
Пример #2
0
function add_definition($spart, $value)
{
    $w = $GLOBALS["word"];
    $d = DEFINITION(defaultDB(), NULL, $w);
    $d->set_lang("en");
    $d->set_value($value);
    $p = PATH($w, $spart);
    $d->set_path($p);
    $d = $w->add_definition($d);
}
Пример #3
0
 function __construct($db, $id, $word)
 {
     $this->_id = $id;
     $this->issql = ISSQLDB($db);
     $this->_word = $word !== NULL ? $word : NULL;
     if ($_fid = $this->_getpath()) {
         $this->_path = PATH($this->word(), $_fid);
     } elseif ($word !== NULL) {
         $this->_path = PATH($this->word());
     } else {
         $this->_path = NULL;
     }
     return $this;
 }
Пример #4
0
function routePath()
{
    $flag = FALSE;
    $rsaquo = " ›› ";
    $path = path(whichApplication());
    if (segments() > 0) {
        for ($i = 0; $i <= segments() - 1; $i++) {
            if (!$flag) {
                if (segments() === 6) {
                    $flag = TRUE;
                    $HTML = a(__(_("Home")), PATH("cpanel")) . $rsaquo;
                    $HTML .= a(__(_(ucfirst(segment(2)))), $path . segment(2)) . $rsaquo;
                    $HTML .= a(__(_(ucfirst(segment(3)))), $path . segment(2) . _sh . segment(3)) . $rsaquo;
                    $HTML .= a(__(_(ucfirst(segment(4)))), $path . segment(2) . _sh . segment(3) . _sh . segment(4)) . $rsaquo;
                    $HTML .= a(__(_(ucfirst(segment(5)))), $path . segment(2) . _sh . segment(3) . _sh . segment(4) . _sh . segment(5));
                } elseif (segments() === 5) {
                    $flag = TRUE;
                    $HTML = a(__(_("Home"), path("cpanel"))) . $rsaquo;
                    $HTML .= a(__(_(ucfirst(segment(2)))), $path . segment(2)) . $rsaquo;
                    $HTML .= a(__(_(ucfirst(segment(3)))), $path . segment(2) . _sh . segment(3)) . $rsaquo;
                    $HTML .= a(__(_(ucfirst(segment(4)))), $path . segment(2) . _sh . segment(3) . _sh . segment(4));
                } elseif (segments() === 4) {
                    $flag = TRUE;
                    $HTML = a(__(_("Home")), path("cpanel")) . $rsaquo;
                    $HTML .= a(__(_(ucfirst(segment(1)))), $path . "cpanel") . $rsaquo;
                    $HTML .= a(__(_(ucfirst(segment(3)))), $path . segment(2) . _sh . segment(3));
                } elseif (segments() === 3) {
                    $flag = TRUE;
                    $HTML = a(__(_("Home")), path("cpanel")) . $rsaquo;
                    $HTML .= a(__(_(ucfirst(segment(1)))), $path . segment(3));
                } elseif (segments() === 2) {
                    $flag = TRUE;
                    $HTML = a(__(_("Home")), path("cpanel"));
                } else {
                    $HTML = a(__(_("Home")), path("cpanel"));
                }
            }
        }
    }
    return $HTML;
}
Пример #5
0
            $t = $t->only_with_attr(ATTR("template", "true"));
            $t = $t->all();
            //error_log(var_export(array_map(function($a){return$a->id();},$t),1));
            if (count($t) === 0) {
                exit("Could not find template with name: " . $template);
            } elseif (count($t) !== 1) {
                exit("Ambiguous template name (please remove duplicate template(s))");
            }
            if ($path === "common") {
                if (($s = run_template($w, PATH($w, "feminine"), $t[0], $forms, $ignore, $changes, FALSE)) === NULL) {
                    if (($s = run_template($w, PATH($w, "masculine"), $t[0], $forms, $ignore, $changes, FALSE)) === NULL) {
                        exit("success");
                    } else {
                        exit("Template did not run successfully: {$s}");
                    }
                } else {
                    exit("Template did not run successfully: {$s}");
                }
            } else {
                if (($s = run_template($w, PATH($w, $path), $t[0], $forms, $ignore, $changes, FALSE)) === NULL) {
                    exit("success");
                } else {
                    exit("Template did not run successfully: {$s}");
                }
            }
        }
        exit("Could not find word");
    } else {
        exit("Bad \$_GET");
    }
}
Пример #6
0
 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 {
Пример #7
0
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 
}
Пример #8
0
<?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');
if (!requireRank(3, FALSE)) {
    echo "Insufficient permissions";
} else {
    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"]);
        foreach ($w->paths() as $_) {
            if ((string) $_ === (string) $p) {
                $p = $_;
            }
        }
        if ($p->id() === NULL) {
            exit("Path {$p} did not exist");
        }
        if (!$p->valid()) {
            exit("Path {$p} was invalid");
        }
        $p->remove();
        exit("success");
    } else {
        exit("\$_GET was invalid");
    }
}
Пример #9
0
 function path_by_tag()
 {
     global $sql_stmts;
     $_id = NULL;
     $tag = func_get_args();
     $p = PATH($this, $tag);
     if ($this->issql) {
         $tag = (string) $p;
         sql_getone(sql_stmt("word_id,form_tag->form_id"), $_id, ["is", $this->_id, $tag]);
         if ($_id !== NULL) {
             return PATH($this, $_id);
         }
     }
     if ($p->exists()) {
         return $p;
     }
 }
Пример #10
0
function run_template($w, $p, $t, $arg, $ignore, $change, $overwrite = FALSE)
{
    $t->read_paths();
    error_log("Template size: " . count($t->path_storage));
    $w->read_paths();
    foreach ($t->paths() as $path) {
        // Path: create from $w
        $p2 = PATH($w);
        // Merge $p and $path into $p2
        $p2->add2((string) $p, (string) $path);
        // Don't overwrite existing values
        if (!$overwrite and $p2->hasvalue()) {
            continue;
        }
        // Don't do if matches an ignore field
        $cont = FALSE;
        foreach ($ignore as $ig) {
            foreach ($ig as $value) {
                if (!in_array($value, $p2->map)) {
                    $cont = FALSE;
                    break;
                } else {
                    $cont = TRUE;
                }
            }
            if ($cont) {
                break;
            }
        }
        #error_log($cont ? "TRUE: $p2" : "FALSE: $p2");
        if ($cont) {
            continue;
        }
        // Modify path based on changes
        foreach ($p2->map as $value) {
            if (array_key_exists($value, $change)) {
                $p2->add($change[$value]);
            }
        }
        // Make template
        $l = TEMPLATE($path->get());
        // Evaluate the template
        $value = $l($arg);
        if ($value === NULL) {
            return "Missing variable";
        }
        if (!$p2->hasvalue()) {
            #error_log($p2 . $value);
            #error_log(var_export($w->path_storage,1));
            $p2->set($value);
            #error_log(var_export($w->path_storage,1));
            #error_log(var_export($p2->get(),1));
            $p2 = $w->add_path($p2);
            #error_log(var_export($p2->id(),1));
        } else {
            $p2 = $w->get_path($p2);
            $p2->set_value($value);
            $p2->set($value);
        }
    }
    return NULL;
}
Пример #11
0
 function iterate($k, $hash = NULL)
 {
     $h =& $this->resolve_hash($hash);
     #echo "\$hash:";
     #var_dump($hash);
     $vals = $this->_calculate_valid_values();
     $ret = $vals[$k];
     /*if (!$ret) {
     			echo "\$vals ($k, $this, ".$this->word()->id()."):";
     			var_dump($vals);
     			var_dump($this->word()->id());
     			die($this->word()->id()." was not valid");
     		}/**/
     if (FLAT_STORAGE) {
         if ($h !== NULL) {
             foreach ($vals[$k] as $i => $k) {
                 $found = FALSE;
                 foreach (array_keys($h) as $_) {
                     if (!PATH($this->_mgr, $_)->issub($this)) {
                         continue;
                     }
                     foreach (explode("/", $_) as $__) {
                         if ($__ === $k) {
                             $found = TRUE;
                             break;
                         }
                     }
                     if ($found) {
                         break;
                     }
                 }
                 if (!$found) {
                     //error_log("$k does not exist under ".$this);
                     unset($ret[$i]);
                 }
                 //else error_log("$k exists under ".$this);
             }
         }
         return array_values($ret);
     }
     if ($h !== NULL) {
         foreach (array_values($ret) as $i => $k) {
             if (!array_key_exists_r($k, $h)) {
                 unset($ret[$i]);
             }
         }
     }
     #echo "\$ret:";
     #var_dump($ret);
     return array_values($ret);
 }
Пример #12
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;
    }
}
Пример #13
0
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;
}
Пример #14
0
    if (!$def_expr) {
        $def_expr = make_expr($defs);
    }
    $correct = [capitalize(implode(" ", [$pron[0], $be[0], "in (the)", $defs[0]]))];
    $expr = "{*" . implode("} {", array_map("make_expr", [$pron, $be])) . "} {(in|at) " . make_expr($art) . " {$def_expr}}";
    error_log($expr);
    return ["correct" => $correct, "expr" => $expr];
}, "answer0-tooltip" => "English translation", "answer0-language" => "en"], ["help" => "Translate this into English.", "selections" => ["number" => PICK("number")->l("la"), "gender" => PICK("gender")->l("la"), "word" => NULL], "sentence" => [["spart" => "verb", "language" => "la", "name" => "sum", "path" => ["indicative/present/active/person-3", get_pick("number")]], ["spart" => "noun", "language" => "la", "attr" => $df_exclude, "store_word" => "word", "path" => ["nominative", PICK("gender"), get_pick("number")]], $OP_COLON, $OP_PARAGRAPH, $OP_USER_INPUT], "answer0" => function ($pick_db, $db) {
    $number = $pick_db["number"];
    $gender = $pick_db["gender"];
    $word = $pick_db["word"];
    $pron = ["singular" => ["there", "it", "he", "she"], "plural" => ["there", "they"]];
    $pron = $pron[$number];
    $be = ["singular" => ["is"], "plural" => ["are"]];
    $be = $be[$number];
    $path = PATH($word, "nominative/{$gender}/{$number}");
    $defs = [];
    $def_expr = NULL;
    foreach ($word->definitions() as $def) {
        if ($def->lang() !== "en") {
            continue;
        }
        $_path = $def->path();
        if ($_path and !$path->issub($_path, TRUE)) {
            continue;
        }
        if ($def->type() === "expr") {
            $def_expr = $def->value();
        } else {
            $defs = array_merge($defs, explode("\n", $def->value()));
        }
Пример #15
0
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;
}
Пример #16
0
        $_[10] = [$quae, $qui, $quod];
    } else {
        $_[10] = [$quod, $qui, $quae];
    }
    return $_[10][0];
}, get_pick(10, 1), get_pick(10, 2), ["name" => "qui", "lang" => "la", "spart" => "pronoun", "path" => [get_pick(0, 0), get_pick(1, 1), get_pick(2, 0)]], ["name" => "qui", "lang" => "la", "spart" => "pronoun", "path" => [get_pick(0, 1), get_pick(1, 0), get_pick(2, 1)]]], "choices0-tooltip" => ""], ["help" => "Choose the pronoun that correctly \n\t\t\t           fills in the blank.\n\t\t\t           ", "selections" => [0 => NULL, 1 => NULL, 2 => PICK(2, ["dative", "genitive", "ablative"])->l("la")], "sentence" => [["spart" => "noun", "lang" => "la", "attr" => $df_exclude, "path" => [make_picks(PICK(2, "number")->l("la"), 1, 0, 0), make_picks(PICK(2, "gender")->l("la"), 1, 1, 0), "nominative"]], $OP_COMMA, $OP_USER_INPUT, ["spart" => "verb", "lang" => "la", "attr" => array_merge($df_exclude, ["transitive" => "true"]), "path" => ["indicative/active/person-3", PICK("tense")->l("la"), get_pick(0, 0)], "verb-gender" => get_pick(1, 0)], $OP_COMMA, ["name" => "sum", "lang" => "la", "spart" => "verb", "path" => [get_pick(0, 0), "person-3/indicative/active", PICK("tense")->l("la")]], ["spart" => "adjective", "lang" => "la", "attr" => $df_exclude, "path" => [get_pick(0, 0), get_pick(1, 0), "nominative/positive"]]], "answer0" => ["name" => "qui", "lang" => "la", "spart" => "pronoun", "path" => [get_pick(0, 0), get_pick(1, 0), "nominative"]], "answer0-tooltip" => "relative pronoun form"]]], "007" => ["name" => "Noun–verb agreement", "category" => "Grammar", "lang" => "la", "options" => [["help" => "Choose the pronoun that correctly \n\t\t\t           restates the subject of the verb.\n\t\t\t           (Note: for third-person pronouns,\n\t\t\t           assume both options are of the same\n\t\t\t           gender and thus only differ in number.)", "selections" => [0 => "true", 1 => PICK(3, "person")->l("la"), 2 => PICK(2, "number")->l("la"), 3 => PICK("gender")->l("la"), 4 => NULL, 5 => "active", 6 => NULL, "+adj" => FALSE], "sentence" => [$OP_MULTIPLE_CHOICE, " ", ["condition" => eq_pick("+adj", TRUE), "lang" => "la", "attr" => $df_exclude, "speechpart" => "adjective", "path" => ["nominative", "positive", get_pick(2, 0), get_pick(3)]], ["condition" => fn_and(eq_pick(0, "true"), eq_pick(5, "active")), "lang" => "la", "attr" => $df_exclude, "speechpart" => "noun", "path" => ["accusative", PICK("number")->l("la"), PICK("gender")->l("la")]], ["lang" => "la", "speechpart" => "verb", "attr" => ["transitive" => get_pick(0), "!template" => NULL, "!hidden" => NULL, "!irregular" => NULL], "path" => ["indicative", get_pick(1, 0), get_pick(2, 0), make_pick(PICK(["present", "imperfect", "perfect"]), 4), get_pick(5)], "verb-gender" => get_pick(3)]], "choices0" => ["correct" => ["lang" => "la", "speechpart" => "pronoun", "attr" => ["person" => get_pick(1, 0)], "path" => ["number" => get_pick(2, 0), "nominative", get_pick(3)]], ["lang" => "la", "speechpart" => "pronoun", "attr" => ["person" => get_pick(1, 1)], "path" => ["number" => get_pick(2, 0), "nominative", get_pick(3)]], ["lang" => "la", "speechpart" => "pronoun", "attr" => ["person" => get_pick(1, 2)], "path" => ["number" => get_pick(2, 0), "nominative", get_pick(3)]], ["lang" => "la", "speechpart" => "pronoun", "attr" => ["person" => get_pick(1, 0)], "path" => ["number" => get_pick(2, 1), "nominative", get_pick(3)]], ["lang" => "la", "speechpart" => "pronoun", "attr" => ["person" => get_pick(1, 1)], "path" => ["number" => get_pick(2, 1), "nominative", get_pick(3)]], ["lang" => "la", "speechpart" => "pronoun", "attr" => ["person" => get_pick(1, 2)], "path" => ["number" => get_pick(2, 1), "nominative", get_pick(3)]]], "choices0-tooltip" => "Quis/qui"]]], "subj01" => ["name" => "Subjunctive or Indicative?", "category" => "Grammar", "lang" => "la", "options" => [["help" => "What is the mood of this verb?", "selections" => ["path" => PICK([["indicative", "present", "singular", "person-3", "active"], ["indicative", "imperfect", "singular", "person-3", "active"], ["indicative", "pluperfect", "singular", "person-3", "active"], ["indicative", "perfect", "singular", "person-3", "active"], ["subjunctive", "imperfect", "singular", "person-3", "active"], ["subjunctive", "pluperfect", "singular", "person-3", "active"], ["subjunctive", "imperfect", "singular", "person-3", "active"], ["subjunctive", "pluperfect", "singular", "person-3", "active"]])], "sentence" => [["spart" => "verb", "attr" => $df_exclude, "lang" => "la", "path" => get_pick("path")], $OP_MULTIPLE_CHOICE], "choices0" => ["correct" => get_pick("path", 0), function ($pick_db) {
    if ($pick_db["path"][0] == "indicative") {
        return "subjunctive";
    }
    return "indicative";
}], "choices0-tooltip" => "Which mood?", "choices0-language" => "en"]]], "subjunctive-infinitives" => ["name" => "Subjunctive practice", "category" => "Grammar", "lang" => "la", "stage" => 24, "options" => function () {
    global $OP_USER_INPUT;
    return [["help" => function (&$pick_db, $db) {
        $word = $pick_db["word"];
        $pick_db["word"]->read_paths();
        $path = $pick_db["path"] = PATH($word);
        foreach ($pick_db as $k => $v) {
            if ($k === "word" or $k === "path") {
                continue;
            }
            #error_log("$k = $v".var_export($v,true));
            $path->add2($v);
        }
        #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) {
        $s = $db->searcher()->spart("verb")->only_without_attr(ATTR("irregular"))->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 != '') AND NOT EXISTS (SELECT 1 FROM attributes WHERE attr_tag = 'conjugation' AND attr_value like '%deponent%' AND word_id = words.word_id)";