changeset 68:941d3be57d7b

Get rid of mgeneric.inc.php dependency, as we don't need much from there .. for now.
author Matti Hamalainen <ccr@tnsp.org>
date Wed, 14 Sep 2016 15:47:48 +0300
parents fc4900455610
children 7777887bc515
files mgallery.php
diffstat 1 files changed, 116 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- 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
+    "  <link rel=\"stylesheet\" href=\"".$filename.
+    "\" type=\"text/css\" ".($media !== FALSE ? "media=\"".$media."\"": "")." />\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
+  "<!DOCTYPE html>\n".
+  "<html>\n".
+  "<head>\n".
+  "  <meta charset=\"".$pageCharset."\">\n".
+  "  <meta http-equiv=\"Content-type\" content=\"text/html;charset=".$pageCharset."\">\n".
+  "  <title>".strip_tags($pageTitle)."</title>\n".
+  $pageExtra;
+
+  if (is_array($pageCSS))
+  {
+    foreach ($pageCSS as $uri => $media)
+      mgPrintCSSLine($uri, $media);
+  }
+  else
+  {
+    mgPrintCSSLine($pageCSS, FALSE);
+  }
+
+  echo
+  "</head>\n".
+  "<body>\n";
+
+/*
+  if (isset($pageUrchin) && file_exists($pageUrchin))
+    require_once $pageUrchin;
+  else
+  if (file_exists("urchin.inc.php"))
+    require_once "urchin.inc.php";
+*/
+
+  echo "<div id=\"messageBox\"></div>\n";
+
+  if ($useContents)
+    echo "<div id=\"contents\">\n";
+}
+
+
+function mgPrintPageFooter($useContents = TRUE)
+{
+  if ($useContents)
+    echo "</div>\n";
+
+  echo "</body>\n</html>\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
     "<h1>Gallery error</h1>\n".
@@ -406,7 +510,7 @@
   //echo "<p>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().
     "<div id=\"imageLarge\"><img src=\"".
@@ -566,7 +670,7 @@
   // - Javascript stuff for picture data updates
   //
   $pageTitle = $galTitlePrefix.mgGetArr($galData, "caption", " - %1", "", "chentities");
-  cmPrintPageHeader($pageTitle);
+  mgPrintPageHeader($pageTitle);
   echo
     mgGetLanguageSelector().
     "<h1>".$pageTitle."</h1>\n";
@@ -602,5 +706,5 @@
 }
 
 mgPrintPageInfoFooter();
-cmPrintPageFooter(TRUE);
+mgPrintPageFooter(TRUE);
 ?>
\ No newline at end of file