require 'example_functions.php'; ?> <!doctype html> <html> <head> <link rel="stylesheet" type="text/css" href="css/bootstrap.min.css"> <link rel="stylesheet" type="text/css" href="css/style.css"> <link href='http://fonts.googleapis.com/css?family=Source+Code+Pro' rel='stylesheet' type='text/css'> </head> <body> <nav class="navbar navbar-inverse"> <div class="container"> <div class="navbar-header"> <span class="navbar-brand">JREAM\array_key_depth()</span> </div> </div> </nav> <div class="container"> <?php echo definition('array_key_depth'); run('Simple', 'not_here', $simple); run('Named', 'frontend', $named); run('Nested', 'supervisor', $nested); ?> </div><!-- /container --> </body> </html><?php
function haxe($str) { $lines = explode("\n", $str); $str = ''; foreach ($lines as $ln) { $ln = preg_replace('/(\\!\\=|\\>\\=|\\<\\=|\\|\\||\\=\\=|\\&\\&)/', '<span class="operator">\\1</span>', $ln); if (preg_match('/^\\s*(class )|(interface )/', $ln)) { $ln = classDef($ln); } elseif (preg_match('/(var )|(function )/U', preg_replace('/(\\/\\/.*$)/U', '', $ln))) { $ln = definition($ln); } else { $ln = preg_replace('/\\@(dispatch|param|result|return|author|throws|throw|exception)/', '<span class="tag \\1">@\\1</span>', $ln) . "\n"; # @tags } $ln = preg_replace('/^(\\s*(\\*|\\/\\*).*)$/', '<i>\\1</i>', $ln); $ln = preg_replace('/^(\\s*\\*\\/)/', '<i>\\1</i>', $ln); $ln = preg_replace('/(?<!\\:)(\\/\\/.*)$/', '<i>\\1</i>', $ln); $ln = preg_replace('/(\\s|\\()(([a-z0-9_]+\\.)+[A-Z][a-zA-Z0-9_]*)/', '\\1<type>\\2</type>', $ln); $ln = preg_replace('/(\\s+)(!([.a-zA-Z0-9_]+))([^=.a-zA-Z0-9_])/', '\\1\\3\\4', $ln); $ln = preg_replace('/([^a-zA-Z0-9_])(this|super)([^a-zA-Z0-9_])/', '\\1<span class="\\2">\\2</span>\\3', $ln); $ln = preg_replace('/([^a-zA-Z0-9_])(package|cast|null|false|true|return)([^a-zA-Z0-9_])/', '\\1<span class="\\2">\\2</span>\\3', $ln); $ln = preg_replace('/([^a-zA-Z-0-9_])if(\\s*)\\(/', '\\1<span class="if">if</span>\\3(', $ln); $str .= $ln; } return "<div class=\"haxe\">\n" . imports($str) . "</div>"; }
$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"); $res1 = NULL; sql_getmany($query, $res1, ["is", $word->id(), definition($db, $res0[0])->value()]); $query->close(); if (!$res1) { exit('An error occurred'); } #$res1 = choose_n_unique($res1, 4); $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">
function main() { // Load globals global $errorPrefix; global $classMapFilename; global $generateMarkdown; global $lang; global $idRanges; global $autoIncrement; // Set up our paths and file handler $scriptPath = realpath(dirname(__FILE__)); $classMapPath = join(DIRECTORY_SEPARATOR, [$scriptPath, 'data', $classMapFilename]); touch($classMapPath . '.txt'); // Make sure the file exists $classMap = file($classMapPath . '.txt', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES); /* * Get any existing ID maps [ 'type' => [ [ 'classname' => 'SomeClass', 'namespace' => '\IPS\appname', 'id' => [ 199, NULL ], 'path' => 'sources/SomeClass/SomeClass.php' ], [ 'classname' => 'SubClass', 'namespace' => '\IPS\appname\SomeClass', 'id' => [ 100, ord( 'B' ) ], 'path' => 'sources/SomeClass/SubClass.php' ] ] ] */ $maps = []; $mappedPaths = []; $curType = NULL; $index = 0; foreach ($classMap as $line) { // Type definition? if ($def = definition($line, strtoupper($lang['type']))) { $curType = strtolower($def); if (!isset($maps[$curType])) { $maps[$curType][$index] = []; } } // Classname definition? if ($def = definition($line, strtoupper($lang['classname']))) { $maps[$curType][$index]['classname'] = $def; } // Namespace definition? if ($def = definition($line, strtoupper($lang['namespace']))) { $maps[$curType][$index]['namespace'] = $def; } // ID definition? if ($def = definition($line, strtoupper($lang['id']))) { $suffix = NULL; if (!is_numeric($def)) { $suffix = substr($def, -1); $def = substr($def, 0, -1); $suffix = ord($suffix); } $maps[$curType][$index]['id'] = [$def, $suffix]; } // Path definition? if ($def = definition($line, strtoupper($lang['path']))) { $maps[$curType][$index]['path'] = $def; $mappedPaths[] = $def; ++$index; } } // Get a list of files $types = ['sources', 'modules', 'extensions', 'hooks', 'widgets', 'tasks', 'interface', 'setup', 'misc']; $filePaths = []; foreach ($types as $type) { // Ignore misc if ($type == 'misc') { continue; } $path = join(DIRECTORY_SEPARATOR, [$scriptPath, $type]); // Skip it if the directory does not exist try { $iter = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path, RecursiveDirectoryIterator::SKIP_DOTS), RecursiveIteratorIterator::SELF_FIRST, RecursiveIteratorIterator::CATCH_GET_CHILD); } catch (UnexpectedValueException $e) { continue; } $filePaths[$type] = []; foreach ($iter as $path => $file) { if ($file->isFile() and $file->getExtension() == 'php') { $filePaths[$type][] = $path; } } } // Set our starting point for auto-incrementing ID's foreach ($types as $type) { // Ignore misc if ($type == 'misc') { continue; } list($min, $max) = $idRanges[$type]; $autoIncrement[$type] = [$min, NULL]; if ($maps and !empty($maps[$type])) { foreach ($maps[$type] as $map) { // ID Suffix if ($map['id'][1]) { if ($map['id'][1] > (int) $autoIncrement[$type][1]) { $autoIncrement[$type] = $map['id']; } } // ID Number if ($map['id'][0] > (int) $autoIncrement[$type][0]) { $autoIncrement[$type] = $map['id']; } } } } // Iterate over our files foreach ($types as $type) { // Ignore misc if ($type == 'misc') { continue; } // Skip empty types if (empty($filePaths[$type])) { continue; } foreach ($filePaths[$type] as $fp) { $lines = file($fp, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES); // Attempt to match our ClassName and Namespace $className = NULL; $namespace = NULL; foreach ($lines as $line) { // All done? if ($className and $namespace) { break; } // Namespace? if (preg_match('/namespace\\s+([^;]+);/', $line, $namespaceMatch)) { $namespace = $namespaceMatch[1]; continue; } // Class name? $preg = in_array($type, ['hooks', 'interface', 'setup']) ? '/class ([a-zA-Z_\\x7f-\\xff][a-zA-Z0-9_\\x7f-\\xff]*).*/' : '/class _([a-zA-Z0-9_\\x7f-\\xff]*).*/'; if (preg_match($preg, $line, $classNameMatch)) { $className = $classNameMatch[1]; continue; } } if ($className and $namespace) { $path = array_pop(explode($type . DIRECTORY_SEPARATOR, $fp)); if (in_array($path, $mappedPaths)) { continue; } $mappedPaths[] = $fp; $idSet = popId($type); $maps[$type][] = ['classname' => $className, 'namespace' => $namespace, 'id' => $idSet, 'path' => $path]; $id = (string) $idSet[0]; if ($idSet[1]) { $id = $id . chr($idSet[1]); } print "ID {$id} assigned to class {$namespace}\\{$className}" . PHP_EOL; } } } // Write our output $classMap = fopen($classMapPath . '.txt', 'w+'); foreach ($maps as $type => $map) { foreach ($map as $subMap) { $id = (string) $subMap['id'][0]; if ($subMap['id'][1]) { $id = $id . chr($id[1]); } fwrite($classMap, strtoupper($lang['type']) . ': ' . ucfirst($type)); fwrite($classMap, PHP_EOL); fwrite($classMap, strtoupper($lang['classname']) . ': ' . $subMap['classname']); fwrite($classMap, PHP_EOL); fwrite($classMap, strtoupper($lang['namespace']) . ': ' . $subMap['namespace']); fwrite($classMap, PHP_EOL); fwrite($classMap, strtoupper($lang['id']) . ': ' . $id); fwrite($classMap, PHP_EOL); fwrite($classMap, strtoupper($lang['path']) . ': ' . $subMap['path']); fwrite($classMap, PHP_EOL); fwrite($classMap, PHP_EOL); } } fclose($classMap); // Generate a markdown document if ($generateMarkdown) { $classMap = fopen($classMapPath . '.md', 'w+'); foreach ($maps as $type => $map) { fwrite($classMap, '# ' . ucfirst($type)); fwrite($classMap, PHP_EOL); foreach ($map as $subMap) { $id = (string) $subMap['id'][0]; if ($subMap['id'][1]) { $id = $id . chr($id[1]); } fwrite($classMap, "{$lang['key']} | {$lang['value']}"); fwrite($classMap, PHP_EOL); fwrite($classMap, str_repeat('-', strlen($lang['key'])) . ' | ' . str_repeat('-', strlen($lang['value']))); fwrite($classMap, PHP_EOL); fwrite($classMap, strtoupper($lang['type']) . ' | ' . ucfirst($type)); fwrite($classMap, PHP_EOL); fwrite($classMap, strtoupper($lang['classname']) . ' | ' . $subMap['classname']); fwrite($classMap, PHP_EOL); fwrite($classMap, strtoupper($lang['namespace']) . ' | ' . $subMap['namespace']); fwrite($classMap, PHP_EOL); fwrite($classMap, strtoupper($lang['id']) . ' | ' . $id); fwrite($classMap, PHP_EOL); fwrite($classMap, strtoupper($lang['path']) . ' | ' . $subMap['path']); fwrite($classMap, PHP_EOL); fwrite($classMap, PHP_EOL); } } fclose($classMap); } }
} foreach ($res as &$r) { $r = ["correct" => $r->word()->id() === $pick_db["word"]->id(), "value" => ((string) $r->path() ? "(" . $r->path() . ") " : "") . str_replace("\n", ", ", $r->value())]; } return $res; }, "choices0-tooltip" => "Pick correct definition"]]], "random-definitions-stage28-29-fr" => ["name" => "Stage 28–29 Vocabulary (FR)", "category" => "Vocabulary", "lang" => "la", "options" => [["help" => "Choose a correct definition for the given word", "selections" => ["word" => function ($_, $db, $path) { $s = $db->searcher(); $s->stmt .= "\n\t\t\t\t\t\tWHERE word_id IN (\n\t\t\t\t\t\t\tSELECT word_id FROM definitions\n\t\t\t\t\t\t\tWHERE def_lang = 'en'\n\t\t\t\t\t\t\tAND def_type IS NULL\n\t\t\t\t\t\t)\n\t\t\t\t\t\tAND word_lang = 'la'\n\t\t\t\t\t\tAND word_id NOT IN (\n\t\t\t\t\t\t\tSELECT word_id FROM attributes\n\t\t\t\t\t\t\tWHERE attr_tag = 'template' OR attr_tag = 'hidden'\n\t\t\t\t\t\t)\n\t\t\t\t\t\tAND (\n\t\t\t\t\t\t\tSELECT attr_value FROM attributes\n\t\t\t\t\t\t\tWHERE word_id = words.word_id\n\t\t\t\t\t\t\tAND attr_tag = 'clc-stage' \n\t\t\t\t\t\t) IN (28,29)"; $s->args = []; return $s->rand(); }], "sentence" => [$OP_LQUOTE, function ($pick_db) { return format_word($pick_db["word"]->name()); }, $OP_RQUOTE, $OP_COLON, $OP_USER_INPUT], "answer0-language" => "en", "answer0" => function ($pick_db, $db) { global $mysqli; $query = $mysqli->prepare("\n\t\t\t\t\tSELECT DISTINCT def_id FROM definitions\n\t\t\t\t\tWHERE def_lang = 'en'\n\t\t\t\t\tAND def_type IS NULL\n\t\t\t\t\tAND word_id = (?)\n\t\t\t\t"); $res = NULL; sql_getmany($query, $res, ["i", $pick_db["word"]->id()]); $query->close(); if (!$res) { return NULL; } $ret = []; $ret2 = []; foreach ($res as $r) { $ret = array_merge($ret, explode("\n", definition(defaultDB(), $r)->value())); } foreach ($ret as $r) { $ret2 = array_merge($ret2, array_map("trim", explode(",", $r))); } return ["correct" => explode(",", $ret[0]), "acceptable" => $ret2]; }, "answer0-tooltip" => "Type correct definition"]]], "009" => ["name" => "Synonyms", "lang" => "la", "category" => "Vocabulary", "n_questions" => "auto", "options" => [make_matching(["cædō" => "interficiō", "exeō" => "discēdō", "pulsō" => "verberō", "volō" => "cupiō"]), make_matching(["turba" => "multitūdō", "mīles" => "arma", "imperātor" => "rēx"])]]]);