containing the require of this routine, and create $r which can be queried by subsequent includes (usually item.tiles.widget.php)
tilespec
section 1 overrides the default tileCount of 12
section 2 overrides the default introLines count of 0
section 3 specifies the date format, if not specified then no date
1= M j, Y
2=
3=
section 4 specifies the tile footer format, if not specified, then no tile footer
1=
2=
3=
*/
// ********** DEFAULTS ******
$tileCode='tile_1';
$tileCount=12;
$itemIntroLines=0;
$getHeading=false;// this is an indicator to get a certain heading, rather than a given number of lines
$itemIntroLineLength=42;
$tileDateFormat=false;
$tileFooter=0;
if(!isset($clauses))$clauses=[];
$filter=[];
$createXDiv=false;
// ********** READ SPECS FROM x_ div ******
$interimHTML=ob_get_contents();
$div=explode('
= \''.date('Y-m-d H:i').'\')');
}
$fx=explode('fx_',$class);
if(count($fx)>1){
$fx=explode(' ',$fx[1])[0];
$fx=explode('_',$fx);
$fx=$fx[1]/$fx[0];
$fx*=100;
$fx=number_format($fx,2);
$fx=str_replace('.','d',$fx);
}else{
$fx=false;
}
$tile=explode('tile_',$class);
if(count($tile)>1){
$tileCode='tile_'.explode(' ',$tile)[0];
}
$a=explode('tilespec_',$class);
if(count($a)>1){
$tileSpec=explode(' ',$a[1])[0];
$a=explode('_',$tileSpec);
$count=count($a);
if($count>0){
$tileCount=$a[0];
if($count>1){
if($a[1][0]==='h'){
$getHeading=$a[1];
}else{
$itemIntroLines=$a[1];
}
}
if($count>2)$tileDateFormat=$a[2];
if($count>3)$tileFooter=$a[3];
}
}
//print_r($a);
//echo $itemIntroLines;flush();die;
/* ************************************************************************************************************************
************************************* get $tileCount items within published-expired dates *****************************
************************************************************************************************************************/
$webpage=ZDEF_RESOURCE_PATH_PAGENAME.'/';
// examine $webpage to determine if it has page in the page and if so, remove remove '/page/' and everything after it from the webpage lookup
$a=explode('/',$webpage);
$i = array_search('page',$a);
if($i!==false && isset($a[$i+1])) {
$requestedPage = +$a[$i+1];
}else{
$requestedPage = 1;
}
//echo PHP_EOL.'in item.tiles.count ';print_r($a);echo PHP_EOL.$i.' ';echo ' requested page '.$requestedPage;flush();die;
$orderClause = 'webpage_is_sticky DESC';
if(in_array('aexp',$clauses)){
$orderClause.=', webpage_expiry_datetime';// if we're looking at expired items we want to see the ones expiring first
}else if(in_array('start',$clauses)){
$orderClause .= ',webpage_start_datetime DESC';// AN OPTION FOR EVENTS AND CLASSES
}else{
$orderClause.=', webpage_publish_datetime DESC';// default
}
$sql='SELECT webpage_id,webpage_name,webpage_index_image,webpage_index_image_alt,webpage_publish_datetime,webpage_review_datetime,user_first_name,user_last_name'
.',user_blog_image_url,user_position_title FROM '.ZDEF_DATA_DB_NAME.'.webpage'
.' LEFT JOIN '.ZDEF_CONFIG_DB_NAME.'.user ON webpage_change_user_id = user_id';
$conditions=' WHERE webpage_saved_version = 0'.(SITE_TEST_MODE==1?'':' AND webpage_test_mode = 0').' AND webpage_active = 1'
.' AND ( (webpage_publish_datetime IS NULL OR NOW() >= webpage_publish_datetime OR webpage_is_sticky = 1) AND (webpage_expiry_datetime IS NULL OR NOW() <= webpage_expiry_datetime) )'
.' AND webpage$itemdef_id = ';
if(isset($INPAGE_ITEMDEF_ID) && is_numeric($INPAGE_ITEMDEF_ID)){ // the inpage itemdef id is a signal that the items are being inserted in a page other than their index page
$conditions.= $INPAGE_ITEMDEF_ID;
}else{
$conditions.= WEBPAGE_ITEMDEF_ID;
}
$conditions.=' AND webpage_is_item_index = 0 AND webpage$org_id = '.ORG_ID;
if(count($filter)>0)$conditions.= ' AND '.implode(' AND ',$filter);
if(WEBPAGE_IS_ITEM_INDEX!=1) $conditions.=' AND webpage.webpage_name <> \''.ZDEF_RESOURCE_PATH_PAGENAME.'/\''; // if we're not on the item index then we're on a detailed item don't display the item we're already on, and use the name to make sure we don't display the saved version of a published record
$sql=$sql.$conditions.' ORDER BY '.$orderClause.' LIMIT '.$tileCount.' OFFSET '.($requestedPage - 1) * $tileCount;
//echo $sql;flush();die;
$r=dbQry($db,$sql,'bglx4'.(SITE_TEST_MODE==1)?'item.tiles.count.widget':'');
$sql='SELECT COUNT(*) AS total_count FROM '.ZDEF_DATA_DB_NAME.'.webpage '.$conditions;
$rc=dbQry($db,$sql,'bglx5'.(SITE_TEST_MODE==1)?'item.tiles.count.widget':'');
$row=dbRN($rc);
$publishedUnexpiredActiveItems=$row['total_count'];
//echo PHP_EOL.'==>'.$publishedUnexpiredActiveItems.'<==';flush();die;
//echo $sql.' '.dbNR($r);flush();die;
if(WEBPAGE_IS_ITEM_INDEX==1 && dbNR($r)==0){ // !!!!!!!!!!!!!! WHAT IF YOU ARE CALLING THIS FROM A NON-INDEX PAGE, LIKE. SAY, INDEX page with latest news (blog) on it????????????????????
if($createXDiv)echo '
';
echo '
There are no published '.ITEMDEF_PLURAL_TITLE.'
';
if(1==2 && SITE_TEST_MODE==1)echo '
Test Mode Message: 4r5u9 widgets/item.tiles.widget '.$sql.'
';
if($createXDiv)echo '
';
}else{
foreach($r as $row){
$itemServerLocation=$row['webpage_name'];
$itemServerLocation=substr($itemServerLocation, 0, -1); // strip trailing slash from webpage name
ob_start();
$itemPageSharedFromOtherDomain=false;
if(defined('SITE_SHARES_PAGES') && SITE_SHARES_PAGES==1){
// if this site has shared pages and the ITEM page is shared from another domain, use the other domain path/page for creating the directory entry
$sql='SELECT webpage_shared_org_id FROM webpage WHERE webpage_name = \''.$row['webpage_name'].'\' AND webpage$org_id = '.ORG_ID;
$r=dbQry($db,$sql,'widg3284');
if(dbNR($r)>0){
$rowShared=dbRN($r);
//print_r($rowShared);flush();
$itemPageSharedFromOtherDomain=( $rowShared['webpage_shared_org_id'] !== 0 && !empty($rowShared['webpage_shared_org_id']) );
}else{
$response['jenisys_comms'] = ['ERROR: webpage record not found. '.$rowShared['webpage_name'].' item.tiles.widget'];
print_r($response);flush();die;
}
}
//echo 'requiring '.($itemPageSharedFromOtherDomain?SITE_SHARING_PATH_TO_SUBDOMAIN:ZDEF_PATH_TO_HUB_ROOT.ORG_HANDLE.'/').'source/published/'.$itemServerLocation.'.inc.php';
require ($itemPageSharedFromOtherDomain?SITE_SHARING_PATH_TO_SUBDOMAIN:ZDEF_PATH_TO_HUB_ROOT.ORG_HANDLE.'/').'source/published/'.$itemServerLocation.'.inc.php';
$itemHTML=ob_get_clean();
//echo PHP_EOL.$itemHTML.PHP_EOL;flush();
//print_r($row); echo ' '.ZDEF_PATH_TO_SUBDOMAIN.'published/'.$itemServerLocation.'.inc.php';die;
$doc = new DOMDocument();
libxml_use_internal_errors(true);// prevent html format errors from bubbling up to my error handler
$doc->loadHTML('' . $itemHTML); // DOMDocument will default to ISO-8859-1 unless you tell it utf8
$xpath = new DomXPath($doc);
if($createXDiv)echo '
';
echo '
';
$src=$row['webpage_index_image'];
if($src){
$alt=$row['webpage_index_image_alt'];
$dataMax=false;
$dataFocus=false;
}else{ // if there is no specific index image defined on webpage, then pull the first image from the webpage
$nodes = $xpath->query('//img[1]');
if ($nodes->length > 0) {
$node = $nodes->item(0);
$src = $node->getAttribute('src');
$alt = $node->getAttribute('alt');
$dataMax=$node->getAttribute('data-max');
$dataFocus=$node->getAttribute('data-focus');
$src = explode('?', $src)[0];// pull any query
}
}
if($src){
// DONT EVER REMOVE THE FOLLOWING. WE MUST SET ABSOLUTE REFERENCE HERE BECAUSE IT'S THE ONLY PLACE WE READ THE RESOURCE FILE AND DEAL WITH SHARED SITES
$src=($itemPageSharedFromOtherDomain?SITE_SHARING_URL:ORG_CDN_URL).$src;
echo '
';
}
echo '
';
if($tileDateFormat){
echo '
'.date('M j, Y',strtotime($row['webpage_update_datetime'])).'
';
}
if($getHeading){
$nodes=$xpath->query('//'.$getHeading);
$count=$nodes->length;
if($row['webpage_name'])echo '
'; // this is the webpage name of the item, not the calling webpage
if($count>0){
foreach ($nodes as $node) {
//echo PHP_EOL.$node->nodeValue;flush();die;
echo ''.mb_substr($node->nodeValue,0,$itemIntroLineLength).'
';
break;
}
}
if($row['webpage_name'])echo '';
}else{
// search: xml dom nodelist properties, xml dom nodelist methods
$nodes=$xpath->query('//h1 | //h2 | //h3 | //h4 | //p');
$count=$nodes->length;
$textContent=[];
$textLength=0;
$firstItem=true;
if($itemIntroLines>0 && $count>0){
foreach ($nodes as $node) {
$nodeValue=$node->nodeValue;
if(mb_strlen($nodeValue)>2 && $firstItem){
if($row['webpage_name'])echo '
'; // this is the webpage name of the item, not the calling webpage
echo ''.$nodeValue.'
';
if($row['webpage_name'])echo '';
$firstItem=false;
continue;
}else{
if(mb_strlen($nodeValue)>2){
$c=mb_substr(rtrim($nodeValue),-1);
if($c != '.' && $c != '!' && $c != '?')$nodeValue.='.';
}
$textContent[]=$nodeValue;
}
$textLength+=strlen($nodeValue);
if($textLength>$itemIntroLineLength * $itemIntroLines)break;
}
$textContent=implode(' ',$textContent);
$textContent=mb_substr($textContent,0,$itemIntroLineLength * $itemIntroLines);
// break to the last full word
if($itemIntroLines>1)$textContent=mb_substr($textContent,0,mb_strrpos(rtrim($textContent),' '));
if($textContent!='')echo '
'.$textContent.'…
';
}
}
/* foreach ($nodes as $node) {
echo '
'.$node->nodeValue.'
';
$node=$nodes.get[1];
if($node) echo '
'.$node.'
';
break;
}
*/
// !!!!!!!!!!!!!!!!!! These are the tile footers on the INDEX page !!!!!!!!!!!!!!!!!!!!
if($tileFooter==1){
if($row['webpage_update_datetime']){
$date = new DateTime($row['webpage_update_datetime']);
}else{
$date = new DateTime($row['webpage_publish_datetime']);
}
$date= $date->format('M d, Y');
echo '
';
echo '
';
echo '
'.HSC($row['user_first_name']).' '.HSC($row['user_last_name']).''.$date.'';
echo '
';
}
if($tileFooter==2){
}
if($tileFooter==3){
}
echo '
'; // end of the tile body div
echo '
';
if($createXDiv)echo '
';
}
$totalPages=ceil($publishedUnexpiredActiveItems/$tileCount);
//echo PHP_EOL.'Total Items '.$publishedUnexpiredActiveItems.' Tile Count '.$tileCount.PHP_EOL;flush();
//echo PHP_EOL.'Total Pages '.$totalPages.' This Page '.$requestedPage.PHP_EOL;flush();
if(!isset($INPAGE_ITEMDEF_ID)){ // if INPAGE_ITEMDEF_ID is defined then the items are being inserted into a page other than their index and don't need prev/next buttons
/* use this when you implement search $parms /*
if($parms>1){
$URL_PARMS_TO_RETURN_TO_CLIENT[]='search='.$requestedPage;
}
*/
if($totalPages > 1){?>
}
}
}
?>