templateData = $tempData; }else{ // ok the data is not there. We have // to query the database then store // the data in cace $dbSlinger = new dbSlinger(); $sql = 'SELECT * FROM ' . DB_NAME . '.templates'; $DBQ = $dbSlinger->db_query($sql,"MYFETCHASC"); if($DBQ[0]){ $this->templateData = $DBQ[1]; apc_store(md5('templateData'),$DBQ[1],300); }else{ // error with getting template data. $this->p_error(0,"Error with getting template data for publisher. Check DBLOG"); } } }else{ // cache is disabled. $dbSlinger = new dbSlinger(); $sql = 'SELECT * FROM ' . DB_NAME . '.templates'; $DBQ = $dbSlinger->db_query($sql,"MYFETCHASC"); if($DBQ[0]){ $this->templateData = $DBQ[1]; }else{ // error with getting template data. $this->p_error(0,"Error with getting template data for publisher. Check DBLOG"); } } } function publishSite(){ /* --------------------------------------- Function to publish the whole site for all the pages inside each section. -------------------------------------*/ // first have to get our sectionID's $errs = array(); $dbSlinger = new dbSlinger(); $sql = 'SELECT groupID FROM ' . DB_NAME . '.site_sections'; $DBQ = $dbSlinger->db_query($sql,"MYFETCHASC"); if($DBQ[0]){ $secIDs = $DBQ[1]; for($i=0;$isetSection($secIDs[$i]['groupID']); $pubSec = $this->publishSection(); if(!$pubSec[0]){ $errs[] = 'Error with publishing sectionID:' . $secIDs[$i]['groupID']; } } if(empty($errs)){ return array(1,"Published site succesfully"); }else{ for($i=0;$ip_error($errs[$i]); } return array(0,"Error with publishing site, check logs"); } }else{ $this->p_error(0,"Error could not get section IDs. SQL:" . $sql); return array(0,"Error could not get section ID's"); } } function publishSection(){ /* --------------------------------------- Function to publish all the pages in a section. We will set the section ID outside of the current scope. -------------------------------------*/ $errs = array(); $dbSlinger = new dbSlinger(); $sql = 'SELECT * FROM ' . DB_NAME . '.page WHERE parentID = \'' . $this->sectionID . '\''; $DBQ = $dbSlinger->db_query($sql,"MYFETCHASC"); if($DBQ[0]){ $this->isSec = 1; $this->pages = $DBQ[1]; for($i=0;$ipages);$i++){ $this->curPage = $this->pages[$i]; $packIt = $this->package(); if(!$packIt[0]){ $errs[] = 'Error with publishing page on sectionID:' . $this->sectionID . 'Error:' . $packIt[1]; } } if(empty($errs)){ return array(1,"Published page succesfully"); }else{ $this->p_error(0,'Error with publishing page on sectionID:'); return array(0,"Error with publshing section, check logs"); } }else{ return array(0,"Error with publshing section, check logs"); } } function publishPages($pages2publish){ $errs = array(); if(!empty($pages2publish)){ for($i=0;$ipageID = $pages2publish[$i]; $packIt = $this->package(); if(!$packIt[0]){ $errs[] = 'Error with publishing page ID:' . $pages2publish[$i] . ' secID:' . $this->sectionID . 'Error:' . $packIt[1]; } } if(empty($errs)){ return array(1,"Published pages successfully!"); }else{ $this->p_error(0,"Error with publishing pages..."); for($i=0;$ip_error(0,$errs[$i]); } return array(0,'Error with publishing the pages, please check logs'); } }else{ return array(0,"Error no IDs were suplied for publisher->publishPages"); } } function package(){ /* --------------------------------------- Function to get all our data togehter from the database, build our template up and send off for deilivery -------------------------------------*/ // first get our page data if($this->isSec){ $pageData = $this->curPage; $this->pageID = $this->curPage['id']; }else{ $dbSlinger = new dbSlinger(); $sql = 'SELECT * FROM ' . DB_NAME . '.page WHERE id = \'' . $this->pageID . '\' && parentID = \'' . $this->sectionID . '\''; $DBQ = $dbSlinger->db_query($sql,"MYFETCHASC"); if($DBQ[0]){ // ok we now have our page data $pageData = $DBQ[1][0]; }else{ // error with getting page data form the database; $this->p_error(0,"Error with getting page data from database"); return array(0,"Error with getting page data"); } } if($pageData){ // we now have our page data we need to get the // section config data to see how to layoout the // page. $configData = $this->getConfigData(); if($configData[0]){ // ok we now have our config data $configData = $configData[1]; // now we set up our page data // we first grab our template ID // pull the template and get the // template data and insert // our page data. $appDir = $this->appPath(); $appDir = $appDir[1]; $templateID = $pageData['templateID']; $template = ''; $secDirName = $configData['dir_name']; $secName = $this->sectionName; for($i=0;$itemplateData);$i++){ if($this->templateData[$i]['id'] == $templateID){ $template = $this->templateData[$i]['template']; } } if($template){ // ok we now have our template time to // open it and get our data ready $err = ''; $template = ROOT_SITE_DIR . 'templates/' . $template; $fp = @fopen($template,'r'); if($fp){ flock($fp,LOCK_EX); $tContent = @fread($fp,filesize($template)); if(!$tContent){ // error with reading template file $err = 'Error with reading template file: ' . $template; } fclose($fp); }else{ // error with opening template file $err = 'Error with opening template file:' . $template; } }else{ // error with getting the template $err = 'Error with getting the template from templateData'; } if(!$err){ // ok we now hove our template preped time to go // trough our config data and insert the data we need. if($configData['allow_code']){ $code = $pageData['code']; $tContent = str_replace("[CODE]",$code,$tContent); } if($configData['allow_images']){ // come back to this. } if($configData['allow_comments']){ $comID = $pageData['commentID']; $getComments = $this->processCOM($comID); if($getComments[0]){ $tContent = str_replace("[COMMENTS]",$getComments[1],$tContent); }else{ // error with getting comment data $err = 'Error with processing comment data'; } } if($configData['allow_cat']){ $catID = $pageData['catID']; if($catID){ if(!$dbSlinger){ $dbSlinger = new dbSlinger(); } $sql = 'SELECT cat_name,dir_name FROM ' . DB_NAME . '.page_cats WHERE groupID = \'' . $catID . '\' && parentID = \'' . $this->sectionID . '\''; $DBQ = $dbSlinger->db_query($sql,"MYFETCHASC"); if($DBQ[0]){ $catName = $DBQ[1][0]['cat_name']; $catDirName = $DBQ[1][0]['dir_name']; $catDisplay = ''; $tContent = str_replace("[CATEGORY]",$catDisplay,$tContent); }else{ // error with getting cat name $err = 'Error with getting category name'; } }else{ $catDisplay = ''; $tContent = str_replace("[CATEGORY]",$catDisplay,$tContent); } }else{ $catDisplay = ''; $tContent = str_replace("[CATEGORY]",$catDisplay,$tContent); } if($configData['allow_files']){ //$fileIDs = preg_split('/:/',$pageData['fileIDs'],-1,PREG_SPLIT_NO_EMPTY); $fileIDs = $pageData['fileIDs']; if($fileIDs){ $pFiles = $this->processFiles($fileIDs); if($pFiles[0]){ $tContent = str_replace("[FILES]",$pFiles[1],$tContent); }else{ // error with processing files $err = 'Error with processing file information'; } } } // ok we now have all our config set data set // time to go trough the basics and replace them. if(!empty($pageData['iCSS'])){ // ok there is some internal css on this page // we will go ahead and insert it $css = ''; // replace our string $tContent = str_replace("[CSS]",$css,$tContent); }else if(empty($pageData['iCSS'])){ // get rid of our scrap $tContent = str_replace("[CSS]",'',$tContent); } if(!empty($pageData['iJS'])){ // ok there is some internal JS on this page // we will go ahead and insert it $js = ''; // replace our string $tContent = str_replace("[JS]",$js,$tContent); }else if(empty($pageData['iJS'])){ // get rid of our scrap $tContent = str_replace("[JS]",'',$tContent); } $tContent = str_replace("[PAGE_TITLE]",$pageData['pageTitle'],$tContent); $tContent = str_replace("[TITLE]",$pageData['title'],$tContent); $tContent = str_replace("[CONTENT]",html_entity_decode($pageData['text']),$tContent); $tContent = str_replace("[PAGE_DESC]",$pageData['page_desc'],$tContent); $tContent = str_replace("[PAGE_KEYWORDS]",$pageData['page_keyword'],$tContent); $tContent = str_replace("[AUTHOR]",$auth,$tContent); $tContent = str_replace("[PARENTID]",$this->sectionID,$tContent); $tContent = str_replace("[APPPATH]",$appDir,$tContent); $navData = $this->generateNav(); $tContent = str_replace("[NAV]",$navData,$tContent); if($pageData['pageIndex']){ $fileName = "index.php"; }else{ $fileName = $pageData['fileName'] . '.php'; } if($pageData['catID']){ // ok this page belongs to a sub-category // we have to get the sub-cat directory name $fPath = $appDir . $secDirName . '/' . $catDirName . '/'; }else{ $fPath = $appDir . $secDirName . '/'; } $publish = $this->deliver($fPath . $fileName,$tContent); if($publish[0]){ //echo "SecID:" . $this->sectionID; $dbSlinger = new dbSlinger(); $sql = 'UPDATE ' . DB_NAME . '.page SET published = \'1\' WHERE parentID = \'' . $this->sectionID . '\' AND id = \'' . $this->pageID . '\''; $DBQ = $dbSlinger->db_query($sql); return array(1,"Published Page Succesfully"); }else{ return array(0,$publish[1]); } }else{ // ok there was an error with the template $this->p_error(0,"Error with opening template to publish page"); return array(0,"Error with opening template to publish page"); } }else{ // ok there was an errror getting our config data $this->p_error(0,"Error with getting config data for sectionID:" . $this->sectionID); return array(0,"Error with getting config data"); } }else{ return array(0,"Error with getting page data"); } } function deliver($file,$data){ /* --------------------------------------- This will take the suplied data and publish the page. -------------------------------------*/ // first have to check and make sure // suplied data is not blank if(!empty($file) || !empty($data)){ $fp = fopen($file,'w'); if($fp){ $fw = fwrite($fp,$data); if($fw){ return array(1,"Published page succesfully"); }else{ return array(0,"Error with publishing page, could not right data to page"); } }else{ return array(0,"Error with creating new page, could not create the page"); } }else{ return array(0,"Supplied data was empty"); } } function processFiles($fileIDs){ /* --------------------------------------- This function will genereate the way file information is displayed trhough a template handler. -------------------------------------*/ $fileIDs = preg_split('/:/',$fileIDs,-1,PREG_SPLIT_NO_EMPTY); if(count($fileIDs) == 1){ // ok we just have a single file download // no reason to list them in a UL. $dbSlinger = new dbSlinger(); $sql = 'SELECT * FROM ' . DB_NAME . '.files WHERE id = \'' . $fileIDs[0] . '\''; $DBQ = $dbSlinger->db_query($sql,"MYFETCHASC"); if($DBQ[0]){ // ok we have our file data // time to open our template and replace // the data. $fileData = $DBQ[1][0]; $appDir = $this->appPath(); $appDir = $appDir[1]; $adminDir = $this->getAdminDir(); $adminDir = $adminDir[1]; $tOpen = fopen($appDir . $adminDir . "/includes/fileCode.php","r"); if(!$tOpen){ $err = 'Error with opening fileCode template'; }else{ flock($tOpen,LOCK_EX); $fileTemp = fread($tOpen,filesize($appDir . $adminDir . "/includes/fileCode.php")); if(!$fileTemp){ $err = 'Error with reading template file'; } } fclose($tOpen); if(!$err){ // begin our parseing $pStart = preg_split('/\[SINGLE-FILE\]/i',$fileTemp); if($pStart){ $pEnd = preg_split('/\[END-SINGLE-FILE\]/i',$pStart[1]); if($pEnd){ $strTemp = $pEnd[0]; }else{ // error with finding our end point // for single files $err = 'Error with finding end point in the fileCode template'; } }else{ // error with finding our starting point // for single files $err = 'Error with finding our starting point in the fileCode template'; } } }else{ $err = 'Error with getting file data for ID: ' . $fileIDs[0]; } if(!$err){ // ok we now have our string template ready // just have to swap out the data and return $rFile = str_replace('[URL]',SITE_URL . 'download.php?id=' . $fileData['id'],$strTemp); $rFile = str_replace('[TITLE]',$fileData['title'],$rFile); $rFile = str_replace('[ID]',$fileData['id'],$rFile); $rFile = str_replace('[DESC]',$fileData['fileDesc'],$rFile); $rFile = str_replace('[HITS]',$fileData['hits'],$rFile); return array(1,$rFile); }else{ $this->p_error(0,$err); return array(0,$err); } }else{ for($i=0;$idb_query($sql,"MYFETCHASC"); if($DBQ[0]){ $files = $DBQ[1]; $appDir = $this->appPath(); $appDir = $appDir[1]; $adminDir = $this->getAdminDir(); $adminDir = $adminDir[1]; $tOpen = fopen($appDir . $adminDir . "/includes/fileCode.php","r"); if(!$tOpen){ // error with opening up file template synthax $err = 'Error with opening fileCode template'; }else{ flock($tOpen,LOCK_EX); $fileTemp = fread($tOpen,filesize($appDir . $adminDir . "/includes/fileCode.php")); if(!$fileTemp){ // error with reading file template synthax } } fclose($tOpen); if(!$err){ // begin our parseing $pStart = preg_split('/\[MULTI-FILES\]/i',$fileTemp); if($pStart){ $pStr = preg_split('/\[dataStart\]/i',$pStart[1]); if($pStr){ $strStart = $pStr[0]; $pLoop = preg_split('/\[dataEnd\]/i',$pStr[1]); if($pLoop){ $strLoop = $pLoop[0]; $pEnd = preg_split('/\[END-MULTI-FILES\]/i',$pLoop[1]); if($pEnd){ $strEnd = $pEnd[0]; }else{ // error with finding our end point // for multi-files $err = 'Error with finding our end point in the fileCode template'; } }else{ // error with finding our loop string // for multi-files $err = 'Error with finding our loop string in the fileCode template'; } }else{ // error with finding our start point for data // for multi files $err = 'Error with finding end point in the fileCode template'; } }else{ // error with finding our starting point // for multi-files $err = 'Error with finding our starting point in the fileCode template'; } } if(!$err){ // ok we have our template ready to be inserted with our data. $rFiles = $strStart; for($i=0;$ip_error("Error with getting file data in processFiles"); return array(0,"Error with getting file data in processFiles. SQL:" . $sql); echo 'err sql'; } }else{ // no ids were suplied return array(0,"Error no IDs were suplied to processFiles"); echo 'err no ids'; } } } function processCOM($comID){ // this function will genereate // the php coding needed to pull up the comments // we will have the php coding in an external file // for easy access for future upgrades or changes. $appPath = $this->appPath(); $adminPath = $this->getAdminDir(); $path = $appPath[1] . $adminPath[1] . '/includes/comCode.php'; $cOpen = @fopen($path,"r"); if(!$cOpen){ // error with opening up file for comment code }else{ flock($cOpen,LOCK_EX); $codeCont = @fread($cOpen,filesize($appPath[1] . $adminPath[1] . '/includes/comCode.php')); if(!$codeCont){ // error with reading file for comment code return array(0,$err); }else{ // ok we have our code content // we now need to replace the commentID $codeCont = str_replace("[COMID]",$comID,$codeCont); $codeCont = str_replace("[PARENTID]",$this->sectionID,$codeCont); $codeCont = str_replace("[APPPATH]",$appPath[1] . $adminPath[1],$codeCont); return array(1,$codeCont); } } } } ?>