From c5fe56f1b0a3428a8b96ef76c38fa25b3509998e Mon Sep 17 00:00:00 2001 From: "Hahn Axel (hahn)" <axel.hahn@unibe.ch> Date: Fri, 8 Sep 2023 13:20:53 +0200 Subject: [PATCH] add pageinclude class --- public_html/classes/pageinclude.class.php | 53 +++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 public_html/classes/pageinclude.class.php diff --git a/public_html/classes/pageinclude.class.php b/public_html/classes/pageinclude.class.php new file mode 100644 index 0000000..e5dc4c3 --- /dev/null +++ b/public_html/classes/pageinclude.class.php @@ -0,0 +1,53 @@ +<?php + + +class pageinclude{ + + protected $_request; + protected $_sPageFile; + protected $_sPagesDir; + + /** + * init + * @return bool + */ + public function __construct(){ + $this->_sPagesDir=__DIR__.'/../pages/'; + return true; + } + + protected function _detectPagefile(){ + $_request=$_SERVER['REQUEST_URI']; + $sPagefile=preg_replace('/\?.*$/', '', $_request); + if($sPagefile=="/"){ + $sPagefile="/index"; + } + return $sPagefile.=".php"; + } + + /** + * set another base dir for pages + * @param string $sDir path of the new pages dir + * @return bool + */ + public function setPagedir($sDir){ + if(is_dir($sDir)){ + $this->_sPagesDir=$sDir; + return true; + } + return false; + } + + public function getPage(){ + $this->_sPageFile=$this->_detectPagefile(); + ob_start(); + // echo "$this->_sPagesDir.$this->_sPageFile<br>"; + if (!@include($this->_sPagesDir.$this->_sPageFile)) { + echo "$this->_sPagesDir.$this->_sPageFile<br>"; + @include($this->_sPagesDir."error_404.php"); + } + $sPhpOut = ob_get_contents(); + ob_end_clean(); + return $sPhpOut; + } +} \ No newline at end of file -- GitLab