home *** CD-ROM | disk | FTP | other *** search
/ Cricao de Sites - 650 Layouts Prontos / WebMasters.iso / CMS / xoops-2.0.18.1.exe / xoops-2.0.18.1 / htdocs / class / theme_blocks.php < prev    next >
Encoding:
PHP Script  |  2007-09-09  |  4.9 KB  |  150 lines

  1. <?php
  2. /**
  3.  * xos_logos_PageBuilder component class file
  4.  *
  5.  * @copyright    The XOOPS project http://www.xoops.org/
  6.  * @license      http://www.fsf.org/copyleft/gpl.html GNU public license
  7.  * @package      xos_logos
  8.  * @subpackage   xos_logos_PageBuilder
  9.  * @version        $Id: theme_blocks.php 1029 2007-09-09 03:49:25Z phppp $
  10.  * @author       Skalpa Keo <skalpa@xoops.org>
  11.  * @since        2.3.0
  12.  */
  13. /**
  14.  * This file cannot be requested directly
  15.  */
  16. if ( !defined( 'XOOPS_ROOT_PATH' ) )    exit();
  17.  
  18. include_once XOOPS_ROOT_PATH . '/class/xoopsblock.php';
  19. include_once XOOPS_ROOT_PATH . '/class/template.php';
  20.  
  21. /**
  22.  * xos_logos_PageBuilder main class
  23.  *
  24.  * @package     xos_logos
  25.  * @subpackage  xos_logos_PageBuilder
  26.  * @author         Skalpa Keo
  27.  * @since       2.3.0
  28.  */
  29. class xos_logos_PageBuilder {
  30.     
  31.     var $theme = false;
  32.     
  33.     var $blocks = array();    
  34.  
  35.     function xoInit( $options = array() ) {
  36.         $this->retrieveBlocks();
  37.         if ( $this->theme ) {
  38.             $this->theme->template->assign_by_ref( 'xoBlocks', $this->blocks );
  39.         }
  40.         return true;
  41.     }
  42.     
  43.     /**
  44.      * Called before a specific zone is rendered
  45.      */
  46.     function preRender( $zone = '' ) {
  47.     }
  48.     /**
  49.      * Called after a specific zone is rendered
  50.      */
  51.     function postRender( $zone = '' ) {
  52.     }    
  53.     
  54.     function retrieveBlocks() {
  55.         global $xoopsUser, $xoopsModule, $xoopsConfig;
  56.  
  57.         $startMod = ( $xoopsConfig['startpage'] == '--' ) ? 'system' : $xoopsConfig['startpage'];
  58.         if ( @is_object( $xoopsModule ) ) {
  59.             list( $mid, $dirname ) = array( $xoopsModule->getVar('mid'), $xoopsModule->getVar('dirname') );
  60.             $isStart = ( substr( $_SERVER['PHP_SELF'], -9 ) == 'index.php' && $xoopsConfig['startpage'] == $dirname );
  61.         } else {
  62.             list( $mid, $dirname ) = array( 0, 'system' );
  63.             $isStart = !@empty( $GLOBALS['xoopsOption']['show_cblock'] );
  64.         }
  65.         
  66.         $groups = @is_object( $xoopsUser ) ? $xoopsUser->getGroups() : array( XOOPS_GROUP_ANONYMOUS );
  67.         
  68.         $oldzones = array(
  69.             XOOPS_SIDEBLOCK_LEFT                => 'canvas_left',
  70.             XOOPS_SIDEBLOCK_RIGHT                => 'canvas_right',
  71.             XOOPS_CENTERBLOCK_LEFT                => 'page_topleft',
  72.             XOOPS_CENTERBLOCK_CENTER            => 'page_topcenter',
  73.             XOOPS_CENTERBLOCK_RIGHT                => 'page_topright',
  74.             XOOPS_CENTERBLOCK_BOTTOMLEFT        => 'page_bottomleft',
  75.             XOOPS_CENTERBLOCK_BOTTOM            => 'page_bottomcenter',
  76.             XOOPS_CENTERBLOCK_BOTTOMRIGHT        => 'page_bottomright',
  77.         );
  78.         foreach ( $oldzones as $zone ) {
  79.             $this->blocks[$zone] = array();
  80.         }
  81.         if ( $this->theme ) {
  82.             $template =& $this->theme->template;
  83.             $backup = array( $template->caching, $template->cache_lifetime );
  84.         } else {
  85.             $template =& new XoopsTpl();
  86.         }
  87.         $xoopsblock = new XoopsBlock();
  88.         $block_arr = array();
  89.         $block_arr = $xoopsblock->getAllByGroupModule( $groups, $mid, $isStart, XOOPS_BLOCK_VISIBLE);
  90.         foreach ( $block_arr as $block ) {
  91.             $side = $oldzones[ $block->getVar('side') ];
  92.             if ( $var = $this->buildBlock( $block, $template ) ) {
  93.                 $this->blocks[$side][$var["id"]] = $var;
  94.             }
  95.         }
  96.         if ( $this->theme ) {
  97.             list( $template->caching, $template->cache_lifetime ) = $backup;
  98.         }
  99.     }
  100.  
  101.     function generateCacheId($cache_id) {
  102.         if ($this->theme) {
  103.             $cache_id = $this->theme->generateCacheId($cache_id);
  104.         }
  105.         return $cache_id;
  106.     }
  107.     
  108.     function buildBlock( $xobject, &$template ) {
  109.         // The lame type workaround will change
  110.         // bid is added temporarily as workaround for specific block manipulation
  111.         $block = array(
  112.             'id'        => $xobject->getVar( 'bid' ),
  113.             'module'    => $xobject->getVar( 'dirname' ),
  114.             'title'        => $xobject->getVar( 'title' ),
  115.             //'name'        => strtolower( preg_replace( '/[^0-9a-zA-Z_]/', '', str_replace( ' ', '_', $xobject->getVar( 'name' ) ) ) ),
  116.             'weight'    => $xobject->getVar( 'weight' ),
  117.             'lastmod'    => $xobject->getVar( 'last_modified' ),
  118.         );
  119.  
  120.         //global $xoopsLogger;
  121.         
  122.         $xoopsLogger =& XoopsLogger::instance();
  123.         
  124.         $bcachetime = intval( $xobject->getVar('bcachetime') );
  125.         //$template =& new XoopsTpl();
  126.         if (empty($bcachetime)) {
  127.             $template->caching = 0;
  128.         } else {
  129.             $template->caching = 2;
  130.             $template->cache_lifetime = $bcachetime;
  131.         }
  132.         $tplName = ( $tplName = $xobject->getVar('template') ) ? "db:$tplName" : "db:system_block_dummy.html";
  133.         $cacheid = $this->generateCacheId( 'blk_' . $xobject->getVar( 'dirname', 'n' ) . '_' . $xobject->getVar('bid')/*, $xobject->getVar( 'show_func', 'n' )*/ );
  134.  
  135.         if ( !$bcachetime || !$template->is_cached( $tplName, $cacheid ) ) {
  136.             $xoopsLogger->addBlock( $xobject->getVar('name') );
  137.             if ( ! ( $bresult = $xobject->buildBlock() ) ) {
  138.                 return false;
  139.             }
  140.             $template->assign( 'block', $bresult );
  141.             $block['content'] = $template->fetch( $tplName, $cacheid );
  142.         } else {
  143.             $xoopsLogger->addBlock( $xobject->getVar('name'), true, $bcachetime );
  144.             $block['content'] = $template->fetch( $tplName, $cacheid );
  145.         }
  146.         return $block;
  147.     }
  148.     
  149.     
  150. }