getTrace();
//position 0 would be the line that called this function so we ignore it
$last_call = $trace[1];
print_r($last_call);
}
function getBool($val) {
if ($val) return "true";
else return "false";
}
function printDebug($msg) {
if (DEBUGOUT) {
echo "picosite DEBUG: " . $msg . "\n";
file_put_contents("debug.log", $msg . "\n", FILE_APPEND | LOCK_EX);
echo "
";
}
}
function printDebugArray($msg, $array) {
printDebug($msg);
foreach ($array as $key => $value) printDebug($key . " = " . $value);
}
function transSecureSysName($string) {
//dumb method name
$newstring = preg_replace("/[^A-Za-z0-9.-]/","",$string);
return $newstring;
}
function transStart($instring, $substring) {
$length = strlen($substring);
return (substr($instring, 0, $length) === $substring);
}
function transEnd($instring, $substring) {
$length = strlen($substring);
return $length === 0 || (substr($instring, -$length) === $substring);
}
function transStripNode($nodes) {
$stripped = [];
foreach ($nodes as $key => $node) {
$nodesplit = explode('/', $node);
$snode = $nodesplit[1];
$snodesplit = explode('.', $snode);
$node = $snodesplit[0];
$stripped[$key] = $node;
}
return $stripped;
}
function getLinkMain() {
// this method makes a 'back to main page' link
// and preserves the selected language
$link = "/page.php";
if (isset($_GET['l'])) $link = $link + "?l=" . $_GET['l'];
return $link;
}
function getPageTitles($files, $subpage = "[NONE]") {
$newFiles = [];
foreach ($files as $file) {
$paths = explode("/", $file);
if (count($paths) == 2) {
$file = $paths[1];
$dir = $paths[0];
}
$lang = NULL;
$inslang = "";
$fn = NULL;
$parts = explode('.', $file);
$title = $parts[0];
if ((transEnd($file, ".blog.page") && $dir === "blogs") ||
(transEnd($file, ".guide.page") && $dir === "guides") ||
(transEnd($file, ".sub.page") && $dir === $subpage)) {
if (count($parts) == 3) {
$type = $parts[1];
} elseif ( count($parts) == 5) {
$type = $parts[3];
}
} elseif (transEnd($file, ".page") && $dir === ".") {
$type = "page";
}
if (($subpage === "[NONE]") && $type === "sub") {
continue;
}
if (!is_null($_GET['l'])) {
$lang = $_GET['l'];
$inslang = "." . $lang . ".trans";
}
if ($type === "blog") $fn = "blogs/" . $title . $inslang . ".blog.page";
if ($type === "guide") $fn = "guides/" . $title . $inslang . ".guide.page";
if ($type === "sub") $fn = $subpage . "/" . $title . $inslang . ".sub.page";
if ((($type === "page") && transEnd($file, ".page")))
$fn = $title . $inslang . ".page";
if (!is_null($fn)) {
array_push($newFiles, $fn);
}
}
$files = $newFiles;
$titledRefs = [];
foreach ($files as $file) {
$hastitle = false;
$ispub = true;
$filesplit = explode(".", $file);
$node = $filesplit[0];
$nodesplit = explode("/", $node);
if (count($nodesplit) == 2) {
$node = $nodesplit[1];
}
if (!file_exists($file)) {
$titledRefs[$node] = "Missing File";
continue;
}
$page = file_get_contents($file);
$lines = explode("\n", $page);
#find if page requires publish picocode
foreach ($lines as $line) {
if (transStart($line, "%%##holdpub")) {
$ispub = false;
}
}
#find the page title
foreach ($lines as $line) {
if (transStart($line, "%%##title=")) {
$sides = explode("=", $line);
$title = $sides[1];
$titledRefs[$node] = $title;
$hastitle = true;
}
}
printDebug("getPageTitles(): \$ispub = " . getBool($ispub));
if (!$hastitle) $titledRefs[$node] = "Untitled Page";
if (!$ispub) $titledRefs[$node] = "%%HIDE%%";
}
return $titledRefs;
}
function getPriceBitcoin() {
$datadir = CURRENCY_DAT;
if (!transEnd($datadir,"/")) $datadir = $datadir . "/";
return (float) file_get_contents($datadir . "btc-price");
}
function getPriceMonero() {
$datadir = CURRENCY_DAT;
if (!transEnd($datadir,"/")) $datadir = $datadir . "/";
return (float) file_get_contents($datadir . "xmr-price");
}
function getItemList() {
$items = [];
$data = file_get_contents("itemlist.txt");
$lines = explode("\n", $data);
foreach ($lines as $line) {
$split = explode(',', $line);
$name = $split[0];
$price = $split[1];
if ($name !== "") $items[$name] = $price;
}
return $items;
}
function getItemListOld() {
$items = [];
if (file_exists("itemlist-old.txt") === false) {
$items['NOFILE'] = true;
return $items;
}
$data = file_get_contents("itemlist-old.txt");
$lines = explode("\n", $data);
foreach ($lines as $line) {
$split = explode(',', $line);
$name = $split[0];
$price = $split[1];
if ($name !== "") $items[$name] = $price;
}
return $items;
}
function getPageSubpage($file) {
$subname = "[NOFILE]";
if (file_exists($file)) {
$subname = "[NOSUB]";
$content = file_get_contents($file);
$lines = explode("\n", $content);
foreach ($lines as $line) {
if (transStart($line, "%%##subpg=")) {
$exploded = explode("=", $line);
$subname = $exploded[1];
break;
}
}
}
return $subname;
}
function getPageFile($subpagedir = "[NONE]") {
$fn = "";
$inslang = "";
if (is_null($_GET['q']) || $_GET['q'] === "") $_GET['q'] = 'main';
if (!is_null($_GET['l'])) $inslang = "." . $_GET['l'] . ".trans";
if (is_null($_GET['g']) && is_null($_GET['b']) && is_null($_GET['sp']))
$fn = $_GET["q"] . $inslang . ".page";
if (!is_null($_GET['g']) && is_null($_GET['b']) && is_null($_GET['sp'])) {
$fn = "guides/" . $_GET['g'] . $inslang . ".guide.page";
}
if (is_null($_GET['g']) && !is_null($_GET['b']) && is_null($_GET['sp'])) {
$fn = "blogs/" . $_GET['b'] . $inslang . ".blog.page";
}
if (is_null($_GET['g']) && is_null($_GET['b']) && !is_null($_GET['sp'])) {
if ($subpagedir === "[NONE]") {
$subname = getPageSubpage($_GET['q'] . ".page");
if ($subname === "[NOFILE]") {
$fn = $_GET['q'] . ".page"; //if this looks odd it does a 404
} else if ($subname === "[NOSUB]") {
return $subname;
} else {
$subpagedir = $subname;
}
}
$fn = $subpagedir . "/" . $_GET['sp'] . $inslang . ".sub.page";
}
return $fn;
}
function printDomains($msg) {
if (file_exists("domainlist.txt")) {
printDebug("printDomians() domain list exists");
$domains = file_get_contents("domainlist.txt");
$domains = explode("\n", $domains);
} else {
return;
}
echo "$msg";
foreach ($domains as $domain) {
if ($_SERVER['HTTP_HOST'] === $domain) continue;
echo '' . $domain . " ";
}
echo "\n";
}
function printCoreOut($text) {
debugMethodName();
if (is_string($text)) {
if (preg_match('/\n/', $text)) {
$text = explode('\n', $text);
} else {
echo "$text";
}
}
if (is_array($text)) {
foreach ($text as $line) {
echo "$line\n";
}
}
}
function printPrice($itemname, $usdprice, $oldprice) {
$oldmode = true;
if ($oldprice === "NOFILE") {
$oldmode = false;
}
$btc = getPriceBitcoin();
$xmr = getPriceMonero();
$btcp = number_format($usdprice / $btc, 6);
$xmrp = number_format($usdprice / $xmr, 6);
$sym = CURRENCY_SYM;
if ($oldmode) {
echo "
LTC " . date("G:i:s d/m/Y", $timebtc) . ": $" . getPriceBitcoin() . "
\n";
echo "XMR " . date("G:i:s d/m/Y", $timexmr) . ": $" . getPriceMonero() . "\n";
echo "
Name of Item | Old price | Price | Litecoin cost | Monero cost |
Name of Item | Price | Litecoin cost | Monero cost |
' . date("G:i:s d/m/Y", $time) . ' | '; if ($justone) echo "' . $thetitle . " |
Back to Guides'; } } function printSubpage($groupname) { $groupname = transSecureSysName($groupname); //this stops injection $lang = transSecureSysName($_GET['l']); $subpages = []; if (!file_exists($groupname . '/')) { http_response_code(404); print "
Back to ' . $grouptitle . ''; } } function printFile($file) { global $HIDEPAGE; if ($HIDEPAGE) { echo "The following page is currently hidden from view, and is probably a work in progress."; http_response_code(404); return; } if (file_exists($file)) { debugMethodName(); $content = file_get_contents($file); $lines = explode("\n", $content); foreach ($lines as $line) { if (substr($line, 0, 4) !== "%%##") { printCoreOut($line); echo "\n"; } else { // eventually this will be a function of // similar things but for now it just has // icnlude, which includes a file if (transStart($line, "%%##incld=")) { $exploded = explode("=", $line); $incl = $exploded[1]; printFile($incl); } if (transStart($line, "%%##subpg=")) { $exploded = explode("=", $line); $subpage = $exploded[1]; printSubpage($subpage); } if (transStart($line, "%%##guide")) { printGuide(); } if (transStart($line, "%%##blogs")) { printBlog(); } if (transStart($line, "%%##price")) { if (transStart($line, "%%##price=all")) { printDebug("printFile: we are calling printItemList()"); printItemListing(); } } } } } else { http_response_code(404); print("