tidy up php api script

This commit is contained in:
Ben Harris 2017-12-27 15:11:24 -05:00
parent 326dd8f5f1
commit 588da48b29
2 changed files with 4031 additions and 9 deletions

View File

@ -1,17 +1,30 @@
<?php
$tags = file("/home/ben/taglines.txt");
$tags = file("taglines.txt");
$fonts = __DIR__."/fonts/";
if (isset($_GET["count"])) echo count($tags);
if (isset($_GET["count"])) { // get number of taglines
echo count($tags);
}
elseif (isset($_GET["key"])) echo $tags[$_GET["key"]];
elseif (isset($_GET["key"])) { // get specified tagline (with bounds checking)
echo $tags[$_GET["key"] >= count($tags) ? array_rand($tags) : intval($_GET["key"])];
}
elseif (isset($_GET["fonts"]))
echo json_encode(array_map(function($f){ return basename($f, ".flf"); }, glob("$fonts*.flf")));
elseif (isset($_GET["fonts"])) { // get list of fonts
echo json_encode(array_map(function ($f) {
return basename($f, ".flf");
}, glob("$fonts*.flf")));
}
elseif (isset($_GET["text"]))
echo shell_exec("/usr/bin/figlet -d $fonts -w 158 -f " . ($_GET["font"] ?? "standard") . " " . escapeshellarg($_GET["text"]));
else echo $tags[array_rand($tags)];
elseif (isset($_GET["text"])) { // run figlet
echo shell_exec(
"/usr/bin/figlet -d $fonts -w 140 -f " .
escapeshellarg($_GET["font"] ?? "standard") . " " .
escapeshellarg($_GET["text"])
);
}
else { // get a random tagline
echo $tags[array_rand($tags)];
}

4009
api/taglines.txt Normal file

File diff suppressed because it is too large Load Diff