diff options
Diffstat (limited to 'BitThemes.php')
| -rw-r--r-- | BitThemes.php | 104 |
1 files changed, 104 insertions, 0 deletions
diff --git a/BitThemes.php b/BitThemes.php index 9967361..422bc6b 100644 --- a/BitThemes.php +++ b/BitThemes.php @@ -51,10 +51,12 @@ class BitThemes extends BitSingleton { * @return void */ function __construct() { + global $gBitSmarty; parent::__construct(); // start up caching engine $this->mThemeCache = new BitCache( 'themes', TRUE ); + $gBitSmarty->verifyCompileDir(); } @@ -452,6 +454,108 @@ class BitThemes extends BitSingleton { } } + function displayLayoutColumn( $pColumn ) { + global $gBitSmarty; + if( !empty( $this->mLayout[$pColumn] ) ) { + for ($i = 0; $i < count( $this->mLayout[$pColumn] ); $i++) { + $r = &$this->mLayout[$pColumn][$i]; + if( !empty( $r['visible'] )) { + // @TODO MODULE UPGRADE under new module organization this is not reliable as tpls are in sub dir in modules/ change this when upgrade is complete + list( $package, $template ) = explode( '/', $r['module_rsrc'] ); + // deal with custom modules + if( $package == '_custom:custom' ) { + global $gBitLanguage; + + // We're gonna run our own cache mechanism for user_modules + // the cache is here to avoid calls to consumming queries, + // each module is different for each language because of the strings + $cacheDir = TEMP_PKG_PATH.'modules/cache/'; + if( !is_dir( $cacheDir )) { + mkdir_p( $cacheDir ); + } + $cachefile = $cacheDir.'_custom.'.$gBitLanguage->mLanguage.'.'.$template.'.tpl.cache'; + + if( !empty( $r["cache_time"] ) && file_exists( $cachefile ) && !(( $gBitSystem->getUTCTime() - filemtime( $cachefile )) > $r["cache_time"] )) { + $fp = fopen( $cachefile, "r" ); + $data = fread( $fp, filesize( $cachefile )); + fclose( $fp ); + $r["data"] = $data; + } else { + if( $moduleParams = $this->getCustomModule( $template )) { + $moduleParams = array_merge( $r, $moduleParams ); + $gBitSmarty->assign_by_ref( 'moduleParams', $moduleParams ); + $gBitSmarty->display( 'bitpackage:themes/custom_module.tpl' ); + + if( !empty( $r["cache_time"] ) ) { + // write to chache file + $fp = fopen( $cachefile, "w+" ); + fwrite( $fp, $data, strlen( $data )); + fclose( $fp ); + } + $r["data"] = $data; + } + } + unset( $data ); + } else { + $explosion = explode( '/', $r['module_rsrc'] ); + $template = array_pop( $explosion ); + + // using $module_rows, $module_params and $module_title is deprecated. please use $moduleParams hash instead + global $module_rows, $module_params, $module_title, $gBitLanguage; + + $cacheDir = TEMP_PKG_PATH.'modules/cache/'; + if( !is_dir( $cacheDir )) { + mkdir_p( $cacheDir ); + } + + // include tpl name and module id to uniquely identify + $cachefile = $cacheDir.'_module_'.$r['module_id'].'.'.$gBitLanguage->mLanguage.'.'.$template.'.cache'; + + // if the time is right get the cache else get it fresh + if( !empty( $r["cache_time"] ) && file_exists( $cachefile ) && filesize( $cachefile ) && !(( $gBitSystem->getUTCTime() - filemtime( $cachefile )) > $r["cache_time"] ) ) { + $fp = fopen( $cachefile, "r" ); + $data = fread( $fp, filesize( $cachefile )); + fclose( $fp ); + $r["data"] = $data; + } else { + $module_params = $r['module_params']; // backwards compatability + + if( !$r['module_rows'] ) { + $r['module_rows'] = 10; + } + + // if there's no custom title, get one from file name + if( !$r['title'] = ( isset( $r['title'] ) ? tra( $r['title'] ) : NULL )) { + $pattern[0] = "/.*\/mod_(.*)\.tpl/"; + $replace[0] = "$1"; + $pattern[1] = "/_/"; + $replace[1] = " "; + $r['title'] = ( !empty( $r['title'] ) ? tra( $r['title'] ) : tra( ucfirst( preg_replace( $pattern, $replace, $r['module_rsrc'] )))); + } + + // moduleParams are extracted in BitSmarty::getSiblingAttachments() and passed on the the module php file + $moduleParams = $r; + $gBitSmarty->assign_by_ref( 'moduleParams', $moduleParams ); + // assign the custom module title + $gBitSmarty->assign_by_ref( 'moduleTitle', $r['title'] ); + $gBitSmarty->display( $r['module_rsrc'] ); + + if( !empty( $r["cache_time"] ) ) { + // write to chache file + $fp = fopen( $cachefile, "w+" ); + fwrite( $fp, $data, strlen( $data )); + fclose( $fp ); + } + $r["data"] = $data; + } + + unset( $moduleParams ); + } + } + } + } + } + /** * get the current layout from the database, layouts are fetched in this order in this order until one is successfully loaded: 'layout', 'fallback_layout', ACTIVE_PACKGE, DEFAULT_PACKAGE" * |
