tilde/api/index.php

35 lines
903 B
PHP

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