, <%2%> etc that the elements are piled. These will generally be menus // and the three column configuration - although there will be others. Different templates may be specified for different pages. // // the config file exists only for sitewide variables that are pre-db. ie: the db info and the names of the config/message table. The message table holds all messages // multiple languages can be supported. // // db file exists for security and db connection information //------------------------------------------------------------------------------------------------------------------------------------------------------------------- ini_set("memory_limit", "256M"); set_time_limit(10); //in secs ini_set('session.use_trans_sid', false); // ini_set('mbstring.internal_encoding','UTF-8'); //mbstring deprecated in PHP 5.6 but default charset in any case, in 5.6, is UTF-8 error_reporting(E_ALL ^ E_WARNING); //$backstage=1; $backstage=0; if ($backstage==1){ $uid=1; $cID=1943; $id=1; // bigger number for editing releases: eg 4429 or 4430 for latest Joan Shentons } else { $uid=1; $cID=1; $id=1; $pageID=1; $standardGroupID=1; $emailPwd=1; $msg=1; $template=1; $trys=1; $redirectPageID=1; $firstLoginPageID=1; $logOff=1; $userName=''; $userPassword=''; } include('classLib.php'); include('config.php'); include('db.php'); // now that we have all the config stuff, call the db and security stuff //set some variables for PHP 7.3 rules $pgeTitle=""; $mainfeedname=""; $groupID=0; $str_sql=""; $isEditable=""; $tags=""; // Nick's mods (some loops) to upgrade from PHP4 to PHP5 foreach ($_GET as $key=>$value){$$key = $value;} foreach ($_POST as $key=>$value){$$key = $value;} foreach ($_SESSION as $key=>$value){$$key = $value;} if (isset($_POST['userName'])) { $GLOBALS['userName']=$_POST['userName']; } if (isset($_POST['userPassword'])) { $GLOBALS['userPassword']=$_POST['userPassword']; } //echo "
userName=".$userName; //echo "
top uid=".$uid; // echo "
uid=".$uid; if ($backstage==1) { $isDeveloper=1; } else { $isDeveloper=$db->getFieldVal('DB_011_USER',$uid,15,0)==1?1:0; } $isDeveloper=1; // echo "
isDev:".$isDeveloper; // is this an admin page or not ? $pageDefaults[5]=$backstage==1?1:''; if ($pageDefaults[5]) { $isAdmin='y'; // echo "
isadmin"; $css=$adminCss; $moduleDir=$adminModuleDir; $defaultTemplateID=$mainAdminTemplateID; $str_sql="select * from DB_005_PAGEFUNCTIONS where (DB_001_PAGE_ID=".$pageID." or DB_001_PAGE_ID=-1)"; /*}elseif ($pageDefaults[2]) { echo "Page defaults here: $pageDefaults[5]
\n\n"; $isAdmin=''; $css=$mainCss; $defaultTemplateID=$mainTemplateID; $str_sql="select * from DB_005_PAGEFUNCTIONS where (DB_001_PAGE_ID=".$pageID." or DB_001_PAGE_ID=-1)"; */ }else{ /* echo "Page defaults[0] (ID): $pageDefaults[0]
\n"; echo "Page defaults[1] (Name): $pageDefaults[1]
\n"; echo "Page defaults[2] (Access level): $pageDefaults[2]
\n"; echo "Page defaults[3] (Title): $pageDefaults[3]
\n"; echo "Page defaults[4] (Template ID): $pageDefaults[4]
\n"; echo "
Page defaults[5] (Admin?): $pageDefaults[5]
\n"; echo "Page defaults[6] (Menulink): $pageDefaults[6]
\n"; echo "Page defaults[7] (Vdir): $pageDefaults[7]
\n"; echo "Page defaults[8] (Description): $pageDefaults[8]
\n"; echo "Page defaults[9] (Keywords): $pageDefaults[9]
\n"; */ $pagename=$pageDefaults[1]; // echo "
isnotadmin"; $isAdmin=''; $css=$mainCss; $defaultTemplateID=$mainTemplateID; $str_sql="select * from DB_005_PAGEFUNCTIONS where (DB_001_PAGE_ID=".$pageID." or DB_001_PAGE_ID=0)"; } $str_sql.=" and DB_005_ENABLED=1"; $str_sql.=" order by DB_005_ORDER"; $mainTemplate=$pageDefaults[4]?$db->getFieldVal('DB_014_TEMPLATES',$pageDefaults[4],2,0):$db->getFieldVal('DB_014_TEMPLATES',$defaultTemplateID,2,0); //echo "

MainTplID=".$mainTemplateID; //echo "."; $pageFunctions=$db->get2dArray($str_sql); $outputHtml=new templateBuilder($mainTemplate); $switchTags=array("<%pageTitle%>","<%keywords%>","<%description%>","<%css%>","<%pagename%>","<%mainfeedname%>","<%mainfeedurl%>"); if (!isset($pgeTitle)) { $switchVals=array(($pageDefaults[3]?$pageDefaults[3]:$siteTitle),($pageDefaults[9]?$pageDefaults[9]:$keywords),($pageDefaults[8]?$pageDefaults[8]:$description),$css,$pagename,$mainfeedname,$mainfeedurl); }else{ $switchVals=array($pgeTitle,$keywords,$description,''); } // firstly we need to parse the template and get all the <%stackn%> tags. $tagStart=count($switchTags)-1; $stacks=$outputHtml->getStacks(); for ($i=0;$i- there is a problem with the config.php file"; exit(); } // get all the modules $dir=dir($moduleDir); while ($file=$dir->read()) { if (preg_match("~.php~", $file)) {$moduleFiles[]=$file;} /* //----------------MAILBOX------------------- if($file='formEdit.php') { $mailtox="rob2@pressdispensary.co.uk(Robert)"; $mailfromx="rob@pressdispensary.co.uk(Rob)"; $subjectx="from Index.php 2"; $stringx="Hello. ID=".$id." and TYPE=".$type." and table name=".$tableName."\n\nand time=".date('H-i-s, Y-m-d')."\n\n and File=".$file; // mail($mailtox,$subjectx, $stringx, "From : <".$mailfromx.">"); } //--------------end MAILBOX----------------- */ } // now we create stacks for the stacktags. for ($i=0;$iget2dArray($str_sql); for ($variablesCounter=0;$variablesCountergetFieldVal('DB_014_TEMPLATES',$variables[2][$variablesCounter],2,0); }else{ eval("$".$variables[3][$variablesCounter].'="'.$variables[2][$variablesCounter].'";'); } } } include($moduleDir.$pageFunctions[2][$i]); // this always produces a $str; $switchVals[$pageFunctions[5][$i]+$tagStart].=$str; //offset by the number of tags that already exist } }else{ $switchVals[]="The requested module '".$pageFunctions[2][$i]."' module is not in the '".$moduleDir."' Directory
- there is a problem with the config.php file"; } } } // Go do it !!!! - the data to be passed to the template class. $outputHtml->simpleTemplate($switchTags, $switchVals); $str=$outputHtml->getTemplateStr(); // for www3 stupidity $str=str_replace("&id=",'&id=',$str); $str=str_replace("T&C",'T&C',$str); $str=str_replace("I&C",'I&C',$str); if ($uid and !$noEditor) { $str.=editorButtons($pageAdminPageID,$pageID,$isAdmin,$uid,$groupID); } // rewriteRule if ($rewriteRule and !$isAdmin) { $str=rewriteUrl2($str,$pageID); } if (!$pageDefaults[5]) { // logging - only for non-admin pages $l=new logs($thisSite); $l->logit(); $str=stripTags($str); } // $str=detectDevice($str); //calls function (lower down in index.php) to detect device. Started 27.10.12 - switched off 13Jul15 print $str; mysqli_close($conn); // this makes editor buttons depending on accesslevel // ------------------------------------------------------------------------------------------------------------------------------------------------- function editorButtons($pageAdminPageID,$pageID,$isAdmin,$uid,$groupID){ $db=new db; if ($groupID==1) { $str.="\"edit"; // turn buttons on and off $str.="

\"Edit\"
"; // dropdown of shared modules $str.="
\"show
"; // shared moduleList $str.=sharedModules($pageID,$isAdmin); }else{ // here we need to figure out if a punter has access to anything on the page. // currently this only caters to textblocks. $str_sql=" select distinct DB_021_VALUE from DB_021_PAGEFUNCTIONVARIABLE, DB_005_PAGEFUNCTIONS "; $str_sql.=" where DB_005_MODULE_ID=DB_005_ID "; $str_sql.=" and DB_005_PAGEFUNCTIONS.DB_001_PAGE_ID='".$pageID."' "; $str_sql.=" and DB_021_VBLENAME='textBlockID'"; $vals=$db->get2dArray($str_sql); for ($i=0;$i\"Edit\""; } } return $str; } // function editorButtons(){} ends // ------------------------------------------------------------------------------------------------------------------------------------------------- function rewriteUrl2($str,$pageID){ $db=new db; $dir=str_replace(" ","_",$db->getFieldVal('DB_001_PAGE',$pageID,7,0)); $adminPages=$db->get2dArray("select * from DB_001_PAGE where DB_001_ADMIN=1"); $s=explode("href=",$str); // parse all the links for ($i=1;$i"," ",$s[$i]); $s[$i]=str_replace("&"," ",$s[$i]); $s[$i]=str_replace($dir,"../",$s[$i]); list($link,$idPart)=explode(" ",$s[$i]); // link is the full - path link this will be swapped later. $link=str_replace('"',"",$link); $logoffArray=explode("?",$link); if (in_array('logOff=1',$logoffArray)) { $logoffLink=str_replace('?logOff','&logOff',$link); /* //----------------MAILBOX------------------- $mailto="rob2@pressdispensary.co.uk(Robert)"; $mailfrom="no-reply@pressdispensary.co.uk"; $namefrom="PD System - no reply"; $subject="logoffLink is ".$logoffLink; $string=$subject; mail($mailto,$subject, $string, "From : <".$mailfrom.">(".$namefrom.")"); //------------------------------------------ */ } list($pageNum)=explode("&",$link); $pageNum=str_replace('index.php?pageID=',"",$pageNum); // this is the page number if ($pageNum) { $oldLink[]=$link; if ($logoffLink) { $newLink[]=$logoffLink; } else if (!in_array($pageNum,$adminPages[0])) { $pageNum=str_replace("'","",$pageNum); $thisDir=str_replace(" ","_",$db->getFieldVal('DB_001_PAGE',$pageNum,7,0)); // this is the virtual directory. if ($thisDir) { // $newLink[]=($dir?"../":"").$thisDir."/page".$pageNum.".php"; // $newLink[]=($dir?"../":"")."99".$pageNum."/".$thisDir.".php"; //makes thisDir null and rewrite rule reads number system $newLink[]=($dir?"/":"").$thisDir.".php"; //requires rewrite rule for every page in httpd.conf }else{ // $newLink[]=($dir?"../":"")."page".$pageNum.".php"; $newLink[]=($dir?"../":"")."index.php"; } }else{ $newLink[]=($dir?"/":"").$link; //experimentally by Rob from 10Sep15 to remove subdirectories (eg 'releases/') from internal links and make them default to root. Originally was: $newLink[]=($dir?"../":"").$link; } } } } if (count($newLink)) { $str=str_replace($oldLink,$newLink,$str); } // hack for images & pdfs if ($dir) { $str=str_replace("/images/","%%images%%",$str); $str=str_replace("images/","/images/",$str); $str=str_replace("%%images%%","/images/",$str); $str=str_replace("i/","/i/",$str); // for the images folder /i $str=str_replace("/h/i/","/hi/",$str); // crude hack to stop above str_replace affecting '/hi/', common in BBC URLs $str=str_replace("wik/i/","wiki/",$str); // crude hack to stop above str_replace affecting the word 'wiki' $str=str_replace("Ouf/i/","Oufi/",$str); // crude hack to stop above str_replace affecting the word 'Oufi' - REALLY NEED TO SORT! $str=str_replace("/do/i/","/doi/",$str); // crude hack to stop above str_replace affecting '/doi/', common in Wiley medical URLs $str=str_replace("pdf/","/pdf/",$str); $str=str_replace("cssjs/","/cssjs/",$str); } // unhack hard-coded line breaks that used '[%nn%]' (a horrible hack itself), used in plugin.nl2br_url to inject javascript into emails $str=str_replace('[%nn%]',PHP_EOL,$str); return $str; } // function rewriteUrl(){} ends //----------------------------------------------------------------------------------------------------------------------------------------------- function stripTags($str){ $s=explode('<%',$str); $str=$s[0]; for ($i=1;$i",$s[$i]); if (strlen($tag)<20) { $str.=$body; }else{ $str.=$s[$i]; } } return $str; } // function stripTags() ends //----------------------------------------------------------------------------------------------------------------------------------------------- function sharedModules($pageID,$isAdmin){ $db=new db; // handle the input if ($GLOBALS['updateModules']) { // first do functions unique to this page $str_sql="select * from DB_005_PAGEFUNCTIONS where DB_001_PAGE_ID='".$pageID."'"; $vals=$db->get2dArray($str_sql); for ($i=0;$iget2dArray($str_sql); for ($i=0;$iget2dArray("select * from DB_017_PAGEFUNCTION_X_PAGE where DB_001_PAGE_ID='".$pageID."' and DB_005_PAGEFUNCTION_ID='".$vals[0][$i]."'"); if (!$isThere[0]) { $valArray=array('',$vals[0][$i],$pageID,''); $db->genericTableUpdate('add', $valArray,'DB_017_PAGEFUNCTION_X_PAGE','',''); } }else{ $db->qry("delete from DB_017_PAGEFUNCTION_X_PAGE where DB_001_PAGE_ID='".$pageID."' and DB_005_PAGEFUNCTION_ID='".$vals[0][$i]."'"); } } header("location: index.php?pageID=".$pageID."&id=".$GLOBALS['id']."&src=".$GLOBALS['src'].' Content-Type: text/html; charset=utf-8'); } $str_sql="select * from DB_005_PAGEFUNCTIONS where DB_001_PAGE_ID='".$pageID."' or DB_001_PAGE_ID=".($isAdmin?"-1":"0")." order by DB_001_PAGE_ID desc, DB_005_CELLNAME, DB_005_ORDER"; $vals=$db->get2dArray($str_sql); // inline css so doesn't effect the main css file $str.="
"; $str.=""; $str.=""; $str.="
"; $str.="
"; for ($i=0;$i".$vals[1][$i]."":$vals[1][$i]; $name=$vals[3][$i]<1?"defaultModuleEnabled":"moduleEnabled"; if ($vals[3][$i]<1) { $str_sql="select * from DB_017_PAGEFUNCTION_X_PAGE where DB_005_PAGEFUNCTION_ID=".$vals[0][$i]." and DB_001_PAGE_ID=".$pageID; $temp=$db->get1dArray($str_sql); $checked=(count($temp)?" checked":""); }else{ $checked=($vals[7][$i]?" checked":""); } $str.="".$displayVal."
\n"; } $str.="
"; return $str; } // function sharedModules() ends //----------------------------------------- function detectDevice($str) { $detect = new Mobile_Detect(); if($detect->isiOS()){ // Code to run for the Apple's iOS platform. // echo "hello iOS"; $str=str_replace('',''.PHP_EOL.'',$str); } /* if($detect->isAndroidOS()){ // Code to run for the Google's Android platform. } */ return $str; } ?>