/* lib v15 */
function generateHTML($db){
// Generates everything in wpg
// need $db in case webapage php does lookups
//error_reporting(E_ALL);
//error_reporting(E_ALL & ~E_WARNING & ~E_NOTICE);
//ini_set('display_errors',1);ini_set('log_errors',1);ini_set('error_log',ZDEF_PATH_TO_WEHUB_ACCOUNT.'error-logs/php-error.log');
// the breadcrumbs and section header/footer are generated inside of and they are evaluated, and php inserts done as required
require_once ZDEF_PATH_TO_LIBRARY . 'org.global.functions.inc.php';
ob_start();
if(defined('FORCE_FULL_GENERATE_FOR_CDN') || !ZDEF_XHR_GET_PAGE){ ?>
/* this allows us to autofocus this field without actaully making it a part of the list of elements that can be tabbed into */?>
if(!WEBPAGE_IS_LANDING_PAGE && ! JENISYS_PARM_IS_APP && FLAG_NOIMGS!==1){ // JENISYS_PARM_IS_APP means we want the -app version of the webpage
/* FLAG_NOIMGS is a flag used when resizing browser to get coerced .img_ sizes so we don't need images and we don't need a header because headers have no coerced images */
include (WEBPAGE_SERVE_FROM_SHARED_DOMAIN?ZDEF_PATH_TO_HUB_ROOT.ORG_HANDLE.'/':ZDEF_PATH_TO_SUBDOMAIN).'source/gbl/head.inc.php'; // if WEBPAGE_SERVE_FROM_SHARED_DOMAIN then ZDEF_PATH_TO_SUBDOMAIN is the sharing domain. Head always comes from the current domain
}?>
if(JENISYS_PARM_IS_APP){ // JENISYS_PARM_IS_APP means we want the -app version of the webpage. We get this on FORCE_FULL_GENERATE_FOR_CDN. This will be false if ZDEF_XHR_GET_PAGE is true.
include ZDEF_PATH_TO_SUBDOMAIN.'source/gbl/head.app.inc.php';/* include the smaller app version of the header */
}?>
}
// ====================== Build Jenisys panel, logic if just passed login authorization =============================
if((defined('PASSED_LOGIN_AUTH') && JENISYS==1) || defined('FORCE_FULL_GENERATE_FOR_CDN')){
echo '
';
dbSel($db,ZDEF_DATA_DB_NAME,'ssv21a');// select the 'data' data base
require ZDEF_PATH_TO_LIBRARY.'jenisys/jenisys.controls.php';
require ZDEF_PATH_TO_LIBRARY.'jenisys/jenisys.message.center.php';
require ZDEF_PATH_TO_LIBRARY.'jenisys/resource.panel.php';
if(SITE_HAS_OUTAGE_MAPS==1){
require ZDEF_PATH_TO_LIBRARY.'outage.maps/outage.panel.php';
}
echo '
';
}
// ============== Define which webpage fn we will load
$webpage=ZDEF_PATH_TO_WEBPAGE_SOURCE;
$a=explode('/',$webpage);
// === get rid of any page and page number
$i = array_search('page',$a);
if($i!==false) {
$a=array_slice($a, 0, $i);
$webpage=implode('/',$a).'.inc.php';
}
if(!file_exists($webpage)){
if(SITE_TEST_MODE==1 || FLAG_FORCEVARS===SITE_TEST_FLAG_PW){
echo getcwd();
echo ' (from generateHTML) body path was '.$webpage.' ';
echo PHP_EOL . 'ZDEF_PATH_TO_WEBPAGE_SOURCE '.ZDEF_PATH_TO_WEBPAGE_SOURCE;
echo PHP_EOL . 'ZDEF_HUB_HANDLE '.ZDEF_HUB_HANDLE.' ORG_HANDLE '.ORG_HANDLE;
echo PHP_EOL . str_repeat('ERR ',2000);ob_flush();flush();die;
}
if(!defined('WEBPAGE_NOT_FOUND'))define('WEBPAGE_NOT_FOUND',1);
}
require_once 'jenisys/insert.PHP.markers.inc.php';
// ==================================================================================================================================
// ================ Produce webpage HTML ======================
// generate breadcrumbs if required
$breadcrumbs='';
if(ORG_SHOW_BREADCRUMBS && JENISYS_PARM_IS_APP != 1){// no breadcrumbs needed in app versions
if(ZDEF_ON_HOME_PAGE==1){
$breadcrumbs.= '';
}else{
$breadcrumbs.= '';
}
}
// get the item section header code if a section exists
$sectionHeader='';
if(WEBPAGE_ITEMDEF_ID!=0){// get the item section header code if a section exists and we're not on the item directory
$fn=ZDEF_PATH_TO_SUBDOMAIN.'published/'.WEBPAGE_ITEM_TYPE.'/~~'.WEBPAGE_ITEM_TYPE.'.header.inc.php';
if(file_exists($fn)){
$sectionHeader = getParsedHTML($db,$fn);
}
}
// get webpage contents and strip tags
$webpageHTML=getParsedHTML($db,$webpage);
$start=strpos($webpageHTML, '');
if($end < $start){
echo('generateHTML 23809fj: Webpage Contents HTML malformed, contains tag or php before ',$mainContent)[0];
// get section footer if it exists
$sectionFooter='';
if(WEBPAGE_ITEMDEF_ID!=0){// get the item section header code if a section exists and we're not on the item directory
$fn=ZDEF_PATH_TO_SUBDOMAIN.'published/'.WEBPAGE_ITEM_TYPE.'/~~'.WEBPAGE_ITEM_TYPE.'.footer.inc.php';
if(file_exists($fn)){
$sectionFooter = getParsedHTML($db,$fn);
}
}
// assemble html in
$webpageHTML=$openingMainTag.$breadcrumbs.$sectionHeader.$mainContent.$sectionFooter.''; // This contains all html in INCLUDING breadcrumbs, section header, page content, section footer
$fn=ZDEF_PATH_TO_HUB.'tmp/temp.html';
file_put_contents($fn,$webpageHTML);
require $fn; // (do not use require_once) // writing and requiring HTML is safer than eval()
unlink($fn);
if(defined('FORCE_FULL_GENERATE_FOR_CDN') || !ZDEF_XHR_GET_PAGE){
if( !WEBPAGE_IS_LANDING_PAGE && !JENISYS_PARM_IS_APP ){
$foot = (WEBPAGE_SERVE_FROM_SHARED_DOMAIN?ZDEF_PATH_TO_HUB_ROOT.ORG_HANDLE.'/':ZDEF_PATH_TO_SUBDOMAIN).'source/gbl/foot.inc.php'; // if WEBPAGE_SERVE_FROM_SHARED_DOMAIN then ZDEF_PATH_TO_SUBDOMAIN is the sharing domain. Footer always comes from the current domain
if(!file_exists($foot))STErr(' Footer not Found: '.$foot);
include $foot;
if(ORG_PRIVACY_POPUP!=='')require ZDEF_PATH_TO_SUBDOMAIN.'published/'.ORG_PRIVACY_POPUP;
}
echo '
';
echo '
';/* closes wpg */
}
$output=ob_get_clean();
/* *********** Modify all imgs. Change src by replacing with blank base 64 image and storing the img src in data-src so we can use javascript to send requests for the correct image size*/
//preg_match_all('/]*class="[^"]*img_[^"]*"[^>]*>\s*]+>\s*<\/picture>/i', $output, $matches);
preg_match_all('/(]*>)/i', $output, $matches);
if(!defined('DATAIMG')){ // on a publish generateHTML is required twice
define('DATAIMG','data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP8/wcAAwAB/0PdR6kAAAAASUVORK5CYII=');
}
foreach ($matches[0] as $imgTag) {
preg_match('/src="([^"]+)"/i', $imgTag, $srcMatch);
if (isset($srcMatch[1])) {
$src = $srcMatch[1];
if( (strpos($src,"https://".ORG_CDN_ORIGINALS_URL) === 0 || strpos($src,"https://") === false ) ) { // on domain image (OFF DOMAIN IMAGES NOT ALLOWED)
$newImgTag = defined('FORCE_FULL_GENERATE_FOR_CDN') && FORCE_FULL_GENERATE_FOR_CDN ? $imgTag :str_replace($srcMatch[0], 'src= "'.DATAIMG.'" data-src="'.$src.'"', $imgTag);
$row=[];
// create image data-max using the dimensions of the ORIGINAL image from the resource table. Data-max is needed for publish to CDN and that script removes it
$sql='SELECT resource_extension, resource_image_width, resource_image_height, resource_focus FROM resource WHERE resource_active = 1 AND resource_server_name = \''.dbEsc($db,$src).'\' AND resource$org_id = '.ORG_ID;
$r=dbQry($db,$sql,'genh3894');
if(dbNR($r)>0){
$row=dbRN($r);
if(strtolower($row['resource_extension']) != 'svg'){
// create a data-max tag from resource_image_width, resource_image_height, using 10000x10000 for svg which doesn't have either
$imgWidth = !empty($row['resource_image_width']) ? (string) round((float) $row['resource_image_width']) : '10000';
$imgHeight = !empty($row['resource_image_height']) ? (string) round((float) $row['resource_image_height']) : '10000';
$newImgTag = preg_replace(['/\\s*data-max="[^"]*"/', '/ tags
preg_match_all('/.*?<\/video>/is', $output, $matches);
foreach ($matches[0] as $match) {
$dom = new DOMDocument();
libxml_use_internal_errors(true);
// Wrap match with a generic root element
$dom->loadHTML('
' . $match . '
', LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD);
libxml_clear_errors();
$videoElements = $dom->getElementsByTagName('video');
if($videoElements->length == 0){
continue; // something wrong with the parsing
}
foreach ($videoElements as $videoElement) {
foreach ($videoElement->getElementsByTagName('source') as $sourceElement) {
if ($sourceElement->hasAttribute('src')) {
$srcValue = $sourceElement->getAttribute('src');
$sourceElement->setAttribute('data-src', $srcValue);
$sourceElement->setAttribute('src', ''); // Clear original src
}
}
$modifiedVideoHtml = $dom->saveHTML($videoElement);
$output = str_replace($match, $modifiedVideoHtml, $output);
}
}
return $output;
}
function getParsedHTML($db, $fn){
// get the content of a file without executing its php, add php markers to content as required, write and require the content to execute the php, return the resulting content
//$db is passed because it may be needed in required code
$contents = file_get_contents($fn);
if (strpos($contents, '