array(
* 'href' => $_SERVER['PHP_SELF'] . '?view=true',
* 'dynamic' => true,
* 'active' => !$this->isEditable,
* ),
* _t('_Edit') => array(
* 'href' => $_SERVER['PHP_SELF'] . '?edit=true',
* 'dynamicPopup' => true,
* 'active' => $this->isEditable,
* )
* )
* );
* }
* }
*
* $_page['name_index'] = 0; // choose your own index of template or leave if in doubt
* $_page['header'] = 'Example page';
* $_ni = $_page['name_index'];
*
* $oEPV = new BxExamplePageView();
* $_page_cont[$_ni]['page_main_code'] = $oEPV->getCode();
*
* PageCode();
*
* ?>
*
* 2. Insert into your sys_page_compose_pages table one line.
* Name - Unique identification name of the page. Used for association page with its blocks.
* We recommend use only latin symbols and digits. (In our example use "example")
* Title - Title of your page, it is shown in the Page Builder. ("Example page")
* Order - Just the order in list of pages in the Page Builder.
*
* 3. Insert into sys_page_compose lines for each block.
* ID - ID of the block. System field. Leave it by default (0). Will be passed to the function as first argument.
* Page - ID name of page which you inserted to sys_page_compose_pages ("example").
* PageWidth - System field. Leave it by default ("960px"). Customized later.
* Desc - Few words about this block. Description.
* Caption - Title of this block. ("Block One", "Block Two")
* Column - System field. Leave it by default (0). Customized later.
* Order - System field. Leave it by default (0). Customized later.
* Func - Name of function in your class (without prefix) which will be called to generate the block. ("BlockOne", "BlockTwo")
* Content - Optional argument. Rarely used. Passed as the second argument to the function.
* DesignBox - Number of Design Box (container). Leave it by default if in doubt (1).
* ColWidth - System field. Leave it by default (0). Customized later.
* Visible - System field. Leave it by default (0). Customized later.
* MinWidth - Minimum recommended width of the block.
*
* 4. Now go to the Page Builder, select your page in the list of pages and customize it (width, columns and blocks order).
Then customize every block (caption, visibility, etc.).
*
* 5. Open http://yoursite.com/example.php in your browser and you will see your new customized columned page.
*
*/
class BxDolPageView {
var $sPageName;
var $aPage; // cache of this page
var $sCode = '';
var $sWhoViews = 'non';
var $iMemberID = 0;
var $bAjaxMode = false;
var $aColumnsWidth = array ();
var $sTableName = 'sys_page_compose';
var $sCacheFile ;
var $oCacher = null;
var $_iProfileID;
var $_aProfile;
var $_aCouple;
var $bCouple;
var $_iCoupleID;
var $_aGenders;
var $_aMemLevels;
function BxDolPageView( $sPageName ) {
$this -> sCacheFile = 'sys_page_compose.inc';
$this -> sPageName = $sPageName;
$this -> _iProfileID = getLoggedId();
$this -> getProfileData();
$this -> getGenders();
$this -> getMemLevels();
if( !$this -> load() )
return false;
$this -> getViewerInfo();
$this -> checkAjaxMode();
}
function getProfileData() {
global $aUser;
$bUseCacheSystem = ( getParam('enable_cache_system') == 'on' ) ? true : false;
$oPDb = new BxDolProfileQuery();
$sProfileCache = BX_DIRECTORY_PATH_CACHE . 'user' . $this -> _iProfileID . '.php';
if( $bUseCacheSystem && file_exists( $sProfileCache ) && is_file( $sProfileCache ) ) {
require_once($sProfileCache);
$this -> _aProfile = $aUser[$this -> _iProfileID];
} else
$this -> _aProfile = $oPDb -> getProfileDataById( $this -> _iProfileID );
//get couple data
if( $this -> _aProfile['Couple'] ) {
$this -> bCouple = true;
$this -> _iCoupleID = $this -> _aProfile['Couple'];
$sProfileCache = BX_DIRECTORY_PATH_CACHE . 'user' . $this -> _iCoupleID . '.php';
if( $bUseCacheSystem && file_exists( $sProfileCache ) && is_file( $sProfileCache ) ) {
require_once($sProfileCache);
$this -> _aCouple = $aUser[$this -> _iCoupleID];
} else
$this -> _aCouple = $oPDb -> getProfileDataById( $this -> _iCoupleID );
}
return $this -> _aProfile;
}
function getGenders() {
$sQuery = "SELECT * FROM `sys_pre_values` WHERE `Key` = 'Sex' ORDER BY `Order`" ;
$aGenders = db_res($sQuery);
while($aRow = mysql_fetch_array($aGenders)) {
$this -> _aGenders[] = $aRow['Value'];
}
$this -> _aGenders[] = 'couple';
}
function getMemLevels() {
$sQuery = "SELECT * FROM `sys_acl_levels` WHERE `Active` = 'yes'" ;
$aMemLevels = db_res($sQuery);
while($aRow = mysql_fetch_array($aMemLevels)) {
$this -> _aMemLevels[] = $aRow['ID'];
}
}
function checkAjaxMode() {
if( isset( $_SERVER['HTTP_X_REQUESTED_WITH'] ) and $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest' )
$this -> bAjaxMode = true;
}
function createCache() {
if ($this->oCacher == null)
$this->oCacher = new BxDolPageViewCacher($this->sTableName, $this->sCacheFile);
return $this->oCacher->createCache();
}
function load() {
$oCache = $GLOBALS['MySQL']->getDbCacheObject();
$aCache = $oCache->getData($GLOBALS['MySQL']->genDbCacheKey($this->sCacheFile));
if (null === $aCache) {
if (!$this->createCache() ) {
echo '
Warning PageView cache not found';
return false;
}
$aCache = $oCache->getData($GLOBALS['MySQL']->genDbCacheKey($this->sCacheFile));
}
if( !$aCache ) {
echo '
Warning! PageView cache cannot be evaluated. Please recompile.';
return false;
}
if( !array_key_exists( $this -> sPageName, $aCache ) ) {
//echo '
Warning! The page not found in PageView cache.';
return false;
}
$this -> aPage = $aCache[ $this->sPageName ];
if (BxDolRequest::serviceExists('pageac', 'page_blocks_filter')) {
BxDolService::call('pageac', 'page_blocks_filter', array(&$this));
}
return true;
}
function isLoaded() {
return (isset($this->aPage) && !empty($this->aPage));
}
function getPageTitle() {
return $this->aPage['Title'];
}
function getViewerInfo() {
if (isMember()) {
$this -> sWhoViews = 'memb';
$this -> iMemberID = (int)$_COOKIE['memberID'];
}
}
function gen() {
global $_page_cont, $_ni, $_page, $oSysTemplate;
if( !$this -> aPage )
return false;
$this -> genColumnsHeader();
$oSysTemplate->setPageWidth($this -> aPage['Width']);
$oSysTemplate->addJs('view_edit.js');
if (isset($this -> aPage['Columns']) && !empty($this -> aPage['Columns'])){
foreach( array_keys( $this -> aPage['Columns'] ) as $iColumn )
$this -> genColumn( $iColumn );
} else {
$this->genPageEmpty();
}
$this -> genColumnsFooter();
}
function genPageEmpty() {
$this->genColumnsHeader();
$this->genColumnHeader(1, 100);
$this->sCode .= MsgBox(_t('_Empty'));
$this->genColumnFooter(1);
$this->genColumnsFooter();
}
function genOnlyBlock( $iBlockID, $sDynamicType = 'tab' ) {
if( !$iBlockID )
return false;
// search block
foreach( array_keys( $this -> aPage['Columns'] ) as $iColumn ) {
$aColumn = $this -> aPage['Columns'][ $iColumn ];
if( !$aColumn )
return false;
if (isset($aColumn['Blocks'][$iBlockID])) {
$this -> genBlock( $iBlockID, $aColumn['Blocks'][$iBlockID], false, $sDynamicType );
return true;
}
}
return false;
}
function getCode() {
if( !($this -> bAjaxMode and (int)$_REQUEST['pageBlock']) )
$this -> gen();
else {
$this -> genOnlyBlock( (int)$_REQUEST['pageBlock'], $_REQUEST['dynamic'] );
header( 'Content-type:text/html;charset=utf-8' );
echo $this -> sCode;
exit;
}
return $this -> sCode;
}
//for customizability
function genColumnsHeader() {
}
//for customizability
function genColumnsFooter() {
}
function genColumn( $iColumn ) {
$aColumn = $this -> aPage['Columns'][ $iColumn ];
if( !$aColumn )
return false;
$bShowDebugBlockInfo = !empty($_REQUEST['debug_mode']);
$this -> genColumnHeader( $iColumn, $aColumn['Width'] );
foreach( $aColumn['Blocks'] as $iBlockID => $aBlock ) {
if ($bShowDebugBlockInfo)
$iCurTime = getmicrotime();
$this -> genBlock( $iBlockID, $aBlock );
if ($bShowDebugBlockInfo) {
$iCurTime2 = getmicrotime();
$iGenTime = $iCurTime2 - $iCurTime;
$this -> sCode .= "";
}
}
$this -> genColumnFooter( $iColumn );
}
function getBlockCode_Topest($iColumn) {
return '';
}
function genColumnHeader( $iColumn, $fColumnWidth ) {
$iColumnsCount = count($this -> aPage['Columns']);
if(count($this -> aPage['Columns']) == 1)
$sAddClass = ' page_column_single';
else if($iColumn == 1)
$sAddClass = ' page_column_first';
else if($iColumn == $iColumnsCount)
$sAddClass = ' page_column_last';
else
$sAddClass = '';
switch (preg_replace('/\d+/', '', $this->aPage['Width'])) {
case 'px':
// calc width in pixels
if ('px' == $GLOBALS['oTemplConfig']->PageComposeColumnCalculation) {
/*if ($iColumn == $iColumnsCount) // sum of all columns must not be more/less than page width
$sColumnWidth = ($this -> aPage['Width'] - array_sum($this->aColumnsWidth)) . 'px';
else*/
$sColumnWidth = round(($fColumnWidth * $this -> aPage['Width']) / 100) . 'px';
$this->aColumnsWidth[$iColumn] = (int)$sColumnWidth;
break;
} // else calculate in percentages below
case '%':
$sColumnWidth = $fColumnWidth . '%';
break;
}
$this -> sCode .= '