App/lib/30_pages.php
2020-11-25 17:28:45 +01:00

67 lines
2.0 KiB
PHP

<?php #lib/30_pages.php
/********************************************************************************
* Content: Pages-Management *
* Author: Nils Otterpohl *
* Last modification: 24.06.2019 *
* Version: stable (complete, tested, uncommented) *
********************************************************************************/
function pgsCreatePage($label, $link, $class)
{
#Creates array with markers required for navigation
return array(
"###NAVLABEL###" => $label,
"###NAVHREF###" => $link,
"###NAVCLASS###" => $class
);
}
function pgsLoadPages($mysqli, $userID) {
/* userID unused for now, maybe will add page access control if neccessary */
$ret = array();
$dir = scandir("pgs");
foreach ($dir as $val) {
if ($val!="." && $val!="..") {
if (file_exists("pgs/".$val."/module.json")) {
$json = json_decode(file_get_contents("pgs/".$val."/module.json"), true);
if (lgnCheckRight($mysqli, $json["useRight"], $userID)) {
$key = $json["moduleName"];
$ret[$key]["ID"] = $json["moduleName"];
$ret[$key]["name"] = $json["title"];
$ret[$key]["path"] = $val;
$ret[$key]["tpl"] = pgsCreatePage($val, "", "");
}
}
}
}
return $ret;
}
function pgsIncPage($name)
{
#Checks if a mainpage exists, completes filename and returns valid page or default
$path = "pgs/".$name."/";
$possiblefiles = array("index.php", $name.".php");
foreach ($possiblefiles as $val)
{
if (file_exists($path.$val)) return $path.$val;
}
}
function pgsInclSub($name)
{ //
global $pages,$page;
$possibleexts = array("", ".php", ".htm", ".html", ".txt");
$file = "pgs/".$pages[$page["main"]]["path"]."/".$name;
foreach ($possibleexts as $val)
{
if (file_exists($file.$val)) return $file.$val;
}
addError("pgsInc", $name);
return false;
}
?>