# HG changeset patch # User Matti Hamalainen # Date 1473857268 -10800 # Node ID 941d3be57d7b708c83915740fbb81773084f5952 # Parent fc49004556103f4ca0ca1525b03754a186c2f04f Get rid of mgeneric.inc.php dependency, as we don't need much from there .. for now. diff -r fc4900455610 -r 941d3be57d7b mgallery.php --- a/mgallery.php Wed Sep 14 15:35:53 2016 +0300 +++ b/mgallery.php Wed Sep 14 15:47:48 2016 +0300 @@ -3,7 +3,6 @@ // Yet Another Image Gallery // (C) Copyright 2015-2016 Tecnic Software productions (TNSP) // -require "mgeneric.inc.php"; require "mgallery.inc.php"; $pageLang = "fi"; @@ -17,6 +16,111 @@ // // Various utility functions // +function mgTrimIfString($val) +{ + if (is_string($val)) + return trim($val); + else + return $val; +} + + +function mgGetRequestItem($name, $default = "", $allowGet = FALSE) +{ + if ($allowGet) + return isset($_REQUEST[$name]) ? mgTrimIfString($_REQUEST[$name]) : $default; + else + return isset($_POST[$name]) ? mgTrimIfString($_POST[$name]) : $default; +} + + +function chentities($str) +{ + return htmlentities($str, ENT_NOQUOTES, "UTF-8"); +} + + +function mgPrintCSSLine($filename, $media = FALSE) +{ + echo + " \n"; +} + + +function mgPrintPageHeader($pageTitle, $pageExtra = "", $useContents = TRUE) +{ + global $pageCSS, $pageCSSIndex, $pageCharset, $pageAuthor, $pageCSSData, $pageUrchin; + + if (!isset($pageCSS)) + { + if (!isset($pageCSSData)) + { + $pageCSSData = array( + "cookie" => "docscss", + "prefix" => "/css/docs", + ); + } + + if (isset($_GET["css"])) + { + $pageCSSIndex = intval($_GET["css"]); + setcookie($pageCSSData["cookie"], $pageCSSIndex, time() + 365*24*60*60, "/"); // expire in a year + } + else + { + $pageCSSIndex = isset($_COOKIE[$pageCSSData["cookie"]]) ? intval($_COOKIE[$pageCSSData["cookie"]]) : 1; + } + $pageCSS = $pageCSSData["prefix"].$pageCSSIndex.".css"; + } + + echo + "\n". + "\n". + "\n". + " \n". + " \n". + " ".strip_tags($pageTitle)."\n". + $pageExtra; + + if (is_array($pageCSS)) + { + foreach ($pageCSS as $uri => $media) + mgPrintCSSLine($uri, $media); + } + else + { + mgPrintCSSLine($pageCSS, FALSE); + } + + echo + "\n". + "\n"; + +/* + if (isset($pageUrchin) && file_exists($pageUrchin)) + require_once $pageUrchin; + else + if (file_exists("urchin.inc.php")) + require_once "urchin.inc.php"; +*/ + + echo "
\n"; + + if ($useContents) + echo "
\n"; +} + + +function mgPrintPageFooter($useContents = TRUE) +{ + if ($useContents) + echo "
\n"; + + echo "\n\n"; +} + + function mgGetImageTitleStr($filename, &$data) { return @@ -318,7 +422,7 @@ // // Check language // -if (($tmp = stGetRequestItem("lang", FALSE, TRUE)) !== FALSE) +if (($tmp = mgGetRequestItem("lang", FALSE, TRUE)) !== FALSE) { $tmp = strtolower($tmp); if (array_key_exists($tmp, $pageLanguages)) @@ -339,7 +443,7 @@ // // Check for "from" redirection // -if (($from = stGetRequestItem("from", FALSE, TRUE)) !== FALSE && +if (($from = mgGetRequestItem("from", FALSE, TRUE)) !== FALSE && preg_match("@^[a-z0-9/_.]+\$@i", $from)) { header("Location: ".$from); @@ -368,10 +472,10 @@ $galTitlePrefix = mgGetSetting("title_prefix"); $galTitleSep = mgGetSetting("title_sep"); -$galMode = stGetRequestItem("mode", "view", TRUE); -$galPath = stGetRequestItem("path", ".", TRUE); -$galPageIndex = intval(stGetRequestItem("index", 0, TRUE)); -$galImage = stGetRequestItem("image", FALSE, TRUE); +$galMode = mgGetRequestItem("mode", "view", TRUE); +$galPath = mgGetRequestItem("path", ".", TRUE); +$galPageIndex = intval(mgGetRequestItem("index", 0, TRUE)); +$galImage = mgGetRequestItem("image", FALSE, TRUE); if (is_string($galImage)) $galImage = basename($galImage); @@ -397,7 +501,7 @@ if (!isset($galData) || !isset($galEntries) || !isset($galAlbumsIndex) || !isset($galImagesIndex)) { - cmPrintPageHeader(mgGetVal(["title_prefix", "title_sep"], "%1%2")."ERROR!"); + mgPrintPageHeader(mgGetVal(["title_prefix", "title_sep"], "%1%2")."ERROR!"); echo "

Gallery error

\n". @@ -406,7 +510,7 @@ //echo "

filename=: '".$filename."', X: galData=".intval(isset($galData)).", galEntries=".intval(isset($galEntries))."\n"; mgPrintPageInfoFooter(); - cmPrintPageFooter(TRUE); + mgPrintPageFooter(TRUE); exit; } @@ -433,7 +537,7 @@ ]; $pageTitle = $galTitlePrefix.$galTitleSep.mgGetTrans($galData["caption"])." - ".$galImage; - cmPrintPageHeader($pageTitle); + mgPrintPageHeader($pageTitle); echo mgGetLanguageSelector(). "

".$pageTitle."\n"; @@ -602,5 +706,5 @@ } mgPrintPageInfoFooter(); -cmPrintPageFooter(TRUE); +mgPrintPageFooter(TRUE); ?> \ No newline at end of file