diff options
| author | wjames5 <will@tekimaki.com> | 2009-11-12 05:09:05 +0000 |
|---|---|---|
| committer | wjames5 <will@tekimaki.com> | 2009-11-12 05:09:05 +0000 |
| commit | e2a98da57304b5779a96cc0b6dd30a7f496ed8fe (patch) | |
| tree | e7252178d0138b54a06c7e139262d761a09347a6 | |
| parent | f7b9ef447f5581b997f7f7edf0711e12138211eb (diff) | |
| download | themes-e2a98da57304b5779a96cc0b6dd30a7f496ed8fe.tar.gz themes-e2a98da57304b5779a96cc0b6dd30a7f496ed8fe.tar.bz2 themes-e2a98da57304b5779a96cc0b6dd30a7f496ed8fe.zip | |
Begin module upgrade - read in modules from both old and new locations and process config files during layout editing. Add an upgrade method for packages which upgrade their modules to call to assist people updating their site. Make some use of the new config data to demonstrate possibilities in layout menu. Include one module update in blog pkg to sketch out how configuration file might look.
| -rw-r--r-- | BitThemes.php | 75 | ||||
| -rw-r--r-- | admin/admin_layout_inc.php | 4 | ||||
| -rw-r--r-- | modules_inc.php | 5 | ||||
| -rw-r--r-- | templates/admin_layout.tpl | 41 | ||||
| -rw-r--r-- | templates/admin_layout_inc.tpl | 4 |
5 files changed, 117 insertions, 12 deletions
diff --git a/BitThemes.php b/BitThemes.php index dc9dbc4..f9074dc 100644 --- a/BitThemes.php +++ b/BitThemes.php @@ -1,6 +1,6 @@ <?php /** - * @version $Header: /cvsroot/bitweaver/_bit_themes/BitThemes.php,v 1.101 2009/09/15 13:54:56 wjames5 Exp $ + * @version $Header: /cvsroot/bitweaver/_bit_themes/BitThemes.php,v 1.102 2009/11/12 05:09:05 wjames5 Exp $ * @package themes */ @@ -42,6 +42,9 @@ class BitThemes extends BitBase { // Display Mode var $mDisplayMode; + // When all modules are loaded they are loaded here + var $mModules = array(); + /** * Initiate class @@ -914,11 +917,15 @@ class BitThemes extends BitBase { */ function getAllModules( $pDir='modules', $pPrefix='mod_' ) { global $gBitSystem; - $all_modules = array(); + // @TODO MODULE UPGRADE + // hash for carrying references to modules: + // $this->mModules[$pDir][$pPrefix] + // this is ugly but is to smooth the transition until all modules are upgraded to directory and registration structure + // it will be unncessary once all packages are caught up if(( $modules = $this->getCustomModuleList() ) && $pPrefix == 'mod_' ) { foreach( $modules as $m ) { - $all_modules[tra( 'Custom Modules' )]['_custom:custom/'.$m["name"]] = $m["name"]; + $this->mModules[$pDir][$pPrefix][tra( 'Custom Modules' )]['_custom:custom/'.$m["name"]] = $m["name"]; } } @@ -930,8 +937,20 @@ class BitThemes extends BitBase { $h = opendir( $loc ); if( $h ) { while (($file = readdir($h)) !== false) { + // match on legacy module files which require a prefix if ( preg_match( "/^$pPrefix(.*)\.tpl$/", $file, $match )) { - $all_modules[ucfirst( $key )]['bitpackage:'.$key.'/'.$file] = str_replace( '_', ' ', $match[1] ); + $this->mModules[$pDir][$pPrefix][ucfirst( $key )]['bitpackage:'.$key.'/'.$file] = array( 'title' => str_replace( '_', ' ', $match[1] ), + 'template' => $file, + ); + } + // loop over nested directories which contain modern modules + // these modules are only accessible from gBitThemes + elseif ( !in_array( $file, array('.','..','CVS') ) && @is_dir( $loc.'/'.$file ) ){ + $conf_file = $loc.'/'.$file.'/config_inc.php'; + // we expect a configuration file + if( @is_file( $conf_file ) ){ + require_once( $conf_file ); + } } } closedir ($h); @@ -945,7 +964,9 @@ class BitThemes extends BitBase { if( $h ) { while (($file = readdir($h)) !== false) { if ( preg_match( "/^$pPrefix(.*)\.tpl$/", $file, $match )) { - $all_modules[ucfirst( $key )]['bitpackage:temp/'.$key.'/'.$file] = str_replace( '_', ' ', $match[1] ); + $this->mModules[$pDir][$pPrefix][ucfirst( $key )]['bitpackage:temp/'.$key.'/'.$file] = array( 'title' => str_replace( '_', ' ', $match[1] ), + 'template' => $file, + ); } } closedir ($h); @@ -954,8 +975,50 @@ class BitThemes extends BitBase { } } } + return $this->mModules[$pDir][$pPrefix]; + } + + function registerModule( $pMixed ){ + $pkg = $pMixed['package']; + $dir = $pMixed['directory']; + $tpl = $pMixed['template']; + $legacy_dir = $pMixed['legacy_dir']; + $legacy_prefix = $pMixed['legacy_prefix']; + $this->mModules[$legacy_dir][$legacy_prefix][ucfirst( $pkg )]['bitpackage:'.$pkg.'/'.$dir.'/'.$tpl] = $pMixed; + } + + // utility function for other packages when they upgrade their modules to the new module system + // see themes/admin/upgrades/3.0.0.php for an example of usages + function upgradeModulesPaths(){ + $this->getAllModules(); + $legacy_mods = array(); + $upgrade_mods = array(); + + foreach( $this->mModules['modules']['mod_'] as $pkg => $modules ){ + foreach( $modules as $modulepath => $module ){ + $parts = explode( "/", $modulepath ); + if( count( $parts ) > 2 ){ + $upgrade_mods[array_pop( $parts )] = $modulepath; + } + } + } + + $sql1 = "SELECT DISTINCT `module_rsrc` FROM `".BIT_DB_PREFIX."themes_layouts`"; + $legacy_mods = $this->mDb->getArray( $sql1 ); + + // fix everything + // transaction will save us if something goes bad + $this->mDb->StartTrans(); + + foreach( $legacy_mods as $old ){ + $key = array_pop( explode( "/", $old['module_rsrc'] ) ); + if( in_array( $key, array_keys($upgrade_mods) ) && $old['module_rsrc'] != $upgrade_mods[$key]){ + $storeHash = array( 'module_rsrc' => $upgrade_mods[$key] ); + $this->mDb->associateUpdate( BIT_DB_PREFIX."themes_layouts", $storeHash, array( 'module_rsrc' => $old['module_rsrc'] )); + } + } - return $all_modules; + $this->mDb->CompleteTrans(); } /** diff --git a/admin/admin_layout_inc.php b/admin/admin_layout_inc.php index a544e6d..2e5c884 100644 --- a/admin/admin_layout_inc.php +++ b/admin/admin_layout_inc.php @@ -1,5 +1,5 @@ <?php -// $Header: /cvsroot/bitweaver/_bit_themes/admin/admin_layout_inc.php,v 1.9 2009/09/15 18:50:42 tylerbello Exp $ +// $Header: /cvsroot/bitweaver/_bit_themes/admin/admin_layout_inc.php,v 1.10 2009/11/12 05:09:05 wjames5 Exp $ // Initialization require_once( '../../bit_setup_inc.php' ); @@ -130,4 +130,6 @@ $gBitSmarty->assign_by_ref( "groups", $groups ); // we need gBitThemes as well $gBitSmarty->assign_by_ref( "gBitThemes", $gBitThemes ); + +$gBitThemes->loadJavascript( THEMES_PKG_PATH.'scripts/BitThemes.js', TRUE ); ?> diff --git a/modules_inc.php b/modules_inc.php index 77d7239..f6539bf 100644 --- a/modules_inc.php +++ b/modules_inc.php @@ -1,6 +1,6 @@ <?php /** - * @version $Header: /cvsroot/bitweaver/_bit_themes/modules_inc.php,v 1.11 2009/06/18 06:44:46 lsces Exp $ + * @version $Header: /cvsroot/bitweaver/_bit_themes/modules_inc.php,v 1.12 2009/11/12 05:09:05 wjames5 Exp $ * @package themes * @subpackage functions */ @@ -19,6 +19,7 @@ if( $gBitThemes->mLayout && empty( $gHideModules )) { for ($i = 0; $i < count( $gBitThemes->mLayout[$column] ); $i++) { $r = &$gBitThemes->mLayout[$column][$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' ) { @@ -55,6 +56,8 @@ if( $gBitThemes->mLayout && empty( $gHideModules )) { } unset( $data ); } else { + $template = array_pop( explode( '/', $r['module_rsrc'] ) ); + // using $module_rows, $module_params and $module_title is deprecated. please use $moduleParams hash instead global $module_rows, $module_params, $module_title, $gBitLanguage; diff --git a/templates/admin_layout.tpl b/templates/admin_layout.tpl index 4de36e4..b28d3cf 100644 --- a/templates/admin_layout.tpl +++ b/templates/admin_layout.tpl @@ -112,7 +112,16 @@ <div class="row"> {formlabel label="Module" for="module_rsrc"} {forminput} - {html_options name="fAssign[module_rsrc]" id="module_rsrc" options=$allModules selected=`$fAssign.name`} + {*html_options name="fAssign[module_rsrc]" id="module_rsrc" options=$allModules selected=`$fAssign.name` *} + <select name="fAssign[module_rsrc]" id="module_rsrc" onchange="javascript:BitThemes.viewModuleParamsHelp( this.options[this.selectedIndex].value )"> + {foreach key=pkg item=modules from=$allModules} + <optgroup label="{$pkg}"> + {foreach key=value item=module from=$modules} + <option value="{$value}" {if $fAssign.name eq $value}selected="selected"{/if}>{$module.title}</option> + {/foreach} + </optgroup> + {/foreach} + </select> {formhelp note="Extended help can be found at the end of this page."} {/forminput} </div> @@ -176,6 +185,25 @@ {forminput} <input type="text" size="48" name="fAssign[params]" id="params" value="{$fAssign.params|escape}" /> {formhelp note="Here you can enter any additional parameters the module might need. Use the http query string form, e.g. foo=123&bar=ABC (optional)"} + {foreach key=pkg item=modules from=$allModules} + {foreach key=value item=module from=$modules} + {if $module.params} + <table id="themes_params_help_{$value}" class="themes_params_help" style="display:none"> + <tr> + <th colspan=2 style="text-align:left">Options for {$module.title}</th> + </tr> + {foreach key=param item=data from=$module.params} + {if $data.help} + <tr> + <td style="font-weight:bold; padding-right:4px">{$param}</td> + <td>{$data.help}</td> + </tr> + {/if} + {/foreach} + </table> + {/if} + {/foreach} + {/foreach} {/forminput} </div> @@ -225,7 +253,16 @@ {if $fEdit && $fAssign.name} <input type="hidden" name="fAssign[module]" value="{$fAssign.module}" id="module" />{$fAssign.module} {else} - {html_options name="fAssign[module_rsrc]" id="module" values=$allCenters options=$allCenters selected=`$mod`} + {* html_options name="fAssign[module_rsrc]" id="module" values=$allCenters options=$allCenters selected=`$mod` *} + <select name="fAssign[module_rsrc]" id="module" {*onchange="javascript:BitThemes.viewModuleParamsHelp( this.options[this.selectedIndex].value )"*}> + {foreach key=pkg item=modules from=$allCenters} + <optgroup label="{$pkg}"> + {foreach key=value item=module from=$modules} + <option value="{$value}" {if $mod eq $value}selected="selected"{/if}>{$module.title}</option> + {/foreach} + </optgroup> + {/foreach} + </select> {/if} {formhelp note="Pick the center bit you want to display when accessing this package."} {/forminput} diff --git a/templates/admin_layout_inc.tpl b/templates/admin_layout_inc.tpl index 3bfaf82..0e42092 100644 --- a/templates/admin_layout_inc.tpl +++ b/templates/admin_layout_inc.tpl @@ -46,8 +46,8 @@ {foreach from=$allModulesHelp key=package item=help} <h2><a href="javascript:flip('id{$package}')">{$package}</a></h2> <div class="modulehelp" id="id{$package}" {if !$smarty.request.expand_all}style="display:none;"{/if}> - {foreach from=$help key=file item=title} - <h3>{$title|capitalize}</h3> + {foreach from=$help key=file item=module} + <h3>{$module.title|capitalize}</h3> {include file=$file} {/foreach} <hr /> |
