Permalink
Browse files

Don't integrate content modules into the template (cfgm_content->temp…

…late_integration) so content modules are only loaded on demand. Add content functions to the template class to separate the content (on demand) from blocks (global).
  • Loading branch information...
1 parent 3cfef9f commit 615e2c42292b42b24864ac95b534d388ef89d68c @haraldpdl committed Oct 20, 2013
View
@@ -35,7 +35,7 @@
<div class="contentContainer">
<?php
- echo $oscTemplate->getBlocks('account');
+ echo $oscTemplate->getContent('account');
?>
</div>
@@ -16,7 +16,7 @@ class cfgm_content {
var $language_directory = DIR_FS_CATALOG_LANGUAGES;
var $key = 'MODULE_CONTENT_INSTALLED';
var $title;
- var $template_integration = true;
+ var $template_integration = false;
function cfgm_content() {
$this->directory = DIR_FS_CATALOG_MODULES . 'content/';
@@ -106,7 +106,7 @@
?>
<?php
- echo $oscTemplate->getBlocks('checkout_success');
+ echo $oscTemplate->getContent('checkout_success');
?>
<div class="buttonSet">
@@ -5,17 +5,19 @@
osCommerce, Open Source E-Commerce Solutions
http://www.oscommerce.com
- Copyright (c) 2010 osCommerce
+ Copyright (c) 2013 osCommerce
Released under the GNU General Public License
*/
class oscTemplate {
var $_title;
var $_blocks = array();
+ var $_content = array();
var $_grid_container_width = 24;
var $_grid_content_width = 16;
var $_grid_column_width = 4;
+ var $_data = array();
function oscTemplate() {
$this->_title = TITLE;
@@ -62,25 +64,6 @@ function hasBlocks($group) {
}
function getBlocks($group) {
- if ( !class_exists('tp_' . $group) && file_exists(DIR_WS_MODULES . 'pages/tp_' . $group . '.php') ) {
- include(DIR_WS_MODULES . 'pages/tp_' . $group . '.php');
-
- $template_page_class = 'tp_' . $group;
-
- $template_page = new $template_page_class();
- $template_page->prepare();
- }
-
- if ( class_exists('tp_' . $group) ) {
- if ( !isset($template_page) ) {
- $template_page_class = 'tp_' . $group;
-
- $template_page = new $template_page_class();
- }
-
- $template_page->build();
- }
-
if ($this->hasBlocks($group)) {
return implode("\n", $this->_blocks[$group]);
}
@@ -115,15 +98,6 @@ function buildBlocks() {
$mb = new $class();
if ( $mb->isEnabled() ) {
- if ( !class_exists('tp_' . $mb->group) && file_exists(DIR_WS_MODULES . 'pages/tp_' . $mb->group . '.php') ) {
- include(DIR_WS_MODULES . 'pages/tp_' . $mb->group . '.php');
-
- $template_page_class = 'tp_' . $mb->group;
-
- $template_page = new $template_page_class();
- $template_page->prepare();
- }
-
$mb->execute();
}
}
@@ -132,5 +106,69 @@ function buildBlocks() {
}
}
}
+
+ function addContent($content, $group) {
+ $this->_content[$group][] = $content;
+ }
+
+ function hasContent($group) {
+ return (isset($this->_content[$group]) && !empty($this->_content[$group]));
+ }
+
+ function getContent($group) {
+ global $language;
+
+ if ( !class_exists('tp_' . $group) && file_exists(DIR_WS_MODULES . 'pages/tp_' . $group . '.php') ) {
+ include(DIR_WS_MODULES . 'pages/tp_' . $group . '.php');
+ }
+
+ if ( class_exists('tp_' . $group) ) {
+ $template_page_class = 'tp_' . $group;
+ $template_page = new $template_page_class();
+ $template_page->prepare();
+ }
+
+ foreach ( $this->getContentModules($group) as $module ) {
+ $class = substr($module, 0, strrpos($module, '.'));
+
+ if ( !class_exists($class) ) {
+ if ( file_exists(DIR_WS_MODULES . 'content/' . $module) ) {
+ if ( file_exists(DIR_WS_LANGUAGES . $language . '/modules/content/' . $module) ) {
+ include(DIR_WS_LANGUAGES . $language . '/modules/content/' . $module);
+ }
+
+ include(DIR_WS_MODULES . 'content/' . $module);
+ }
+ }
+
+ if ( class_exists($class) ) {
+ $mb = new $class();
+
+ if ( $mb->isEnabled() ) {
+ $mb->execute();
+ }
+ }
+ }
+
+ if ( class_exists('tp_' . $group) ) {
+ $template_page->build();
+ }
+
+ if ($this->hasContent($group)) {
+ return implode("\n", $this->_content[$group]);
+ }
+ }
+
+ function getContentModules($group) {
+ $result = array();
+
+ foreach ( explode(';', MODULE_CONTENT_INSTALLED) as $file ) {
+ if ( substr($file, 0, strlen('cm_' . $group . '_')) == 'cm_' . $group . '_' ) {
+ $result[] = $file;
+ }
+ }
+
+ return $result;
+ }
}
?>
@@ -19,19 +19,13 @@ class cm_account_test {
var $enabled = false;
function cm_account_test() {
- global $PHP_SELF, $oscTemplate;
-
$this->title = MODULE_CONTENT_TEST_TITLE . ' (' . $this->group . ')';
$this->description = MODULE_CONTENT_TEST_DESCRIPTION;
if ( defined('MODULE_CONTENT_TEST_STATUS') ) {
$this->sort_order = MODULE_CONTENT_TEST_SORT_ORDER;
$this->enabled = (MODULE_CONTENT_TEST_STATUS == 'True');
}
-
- if ( !isset($oscTemplate) || ($PHP_SELF != FILENAME_ACCOUNT) ) {
- $this->enabled = false;
- }
}
function execute() {
@@ -17,19 +17,13 @@ class cm_checkout_success_downloads {
var $enabled = false;
function cm_checkout_success_downloads() {
- global $PHP_SELF, $oscTemplate;
-
$this->title = MODULE_CHECKOUT_SUCCESS_DOWNLOADS_TITLE . ' (' . $this->group . ')';
$this->description = MODULE_CHECKOUT_SUCCESS_DOWNLOADS_DESCRIPTION;
if (defined('MODULE_CHECKOUT_SUCCESS_DOWNLOADS_STATUS')) {
$this->sort_order = MODULE_CHECKOUT_SUCCESS_DOWNLOADS_SORT_ORDER;
$this->enabled = (MODULE_CHECKOUT_SUCCESS_DOWNLOADS_STATUS == 'True');
}
-
- if ( !isset($oscTemplate) || ($PHP_SELF != FILENAME_CHECKOUT_SUCCESS) ) {
- $this->enabled = false;
- }
}
function execute() {
@@ -78,7 +72,7 @@ function execute() {
$cs_data .= ' </table>' . PHP_EOL;
$cs_data .= '</div>' . PHP_EOL;
- $oscTemplate->addBlock($cs_data, $this->group);
+ $oscTemplate->addContent($cs_data, $this->group);
}
}
@@ -17,19 +17,13 @@ class cm_checkout_success_previous_orders {
var $enabled = false;
function cm_checkout_success_previous_orders() {
- global $PHP_SELF, $oscTemplate;
-
$this->title = MODULE_CHECKOUT_SUCCESS_PREVIOUS_ORDERS_TITLE . ' (' . $this->group . ')';
$this->description = MODULE_CHECKOUT_SUCCESS_PREVIOUS_ORDERS_DESCRIPTION;
if ( defined('MODULE_CHECKOUT_SUCCESS_PREVIOUS_ORDERS_STATUS') ) {
$this->sort_order = MODULE_CHECKOUT_SUCCESS_PREVIOUS_ORDERS_SORT_ORDER;
$this->enabled = (MODULE_CHECKOUT_SUCCESS_PREVIOUS_ORDERS_STATUS == 'True');
}
-
- if ( !isset($oscTemplate) || ($PHP_SELF != FILENAME_CHECKOUT_SUCCESS) ) {
- $this->enabled = false;
- }
}
function execute() {
@@ -68,7 +62,7 @@ function execute() {
' <div class="ui-widget-content infoBoxContents">' . $customer_orders_string . '</div>' .
'</div>';
- $oscTemplate->addBlock($cs_data, $this->group);
+ $oscTemplate->addContent($cs_data, $this->group);
}
}
}
@@ -17,19 +17,13 @@ class cm_checkout_success_product_notifications {
var $enabled = false;
function cm_checkout_success_product_notifications() {
- global $PHP_SELF, $oscTemplate;
-
$this->title = MODULE_CHECKOUT_SUCCESS_PRODUCT_NOTIFICATIONS_TITLE . ' (' . $this->group . ')';
$this->description = MODULE_CHECKOUT_SUCCESS_PRODUCT_NOTIFICATIONS_DESCRIPTION;
if (defined('MODULE_CHECKOUT_SUCCESS_PRODUCT_NOTIFICATIONS_STATUS')) {
$this->sort_order = MODULE_CHECKOUT_SUCCESS_PRODUCT_NOTIFICATIONS_SORT_ORDER;
$this->enabled = (MODULE_CHECKOUT_SUCCESS_PRODUCT_NOTIFICATIONS_STATUS == 'True');
}
-
- if ( !isset($oscTemplate) || ($PHP_SELF != FILENAME_CHECKOUT_SUCCESS) ) {
- $this->enabled = false;
- }
}
function execute() {
@@ -106,7 +100,7 @@ function execute() {
' </div>' .
'</form>' . PHP_EOL;
- $oscTemplate->addBlock($cs_data, $this->group);
+ $oscTemplate->addContent($cs_data, $this->group);
}
}
}
@@ -17,19 +17,13 @@ class cm_checkout_success_thank_you {
var $enabled = false;
function cm_checkout_success_thank_you() {
- global $PHP_SELF, $oscTemplate;
-
$this->title = MODULE_CHECKOUT_SUCCESS_THANK_YOU_TITLE . ' (' . $this->group . ')';
$this->description = MODULE_CHECKOUT_SUCCESS_THANK_YOU_DESCRIPTION;
if ( defined('MODULE_CHECKOUT_SUCCESS_THANK_YOU_STATUS') ) {
$this->sort_order = MODULE_CHECKOUT_SUCCESS_THANK_YOU_SORT_ORDER;
$this->enabled = (MODULE_CHECKOUT_SUCCESS_THANK_YOU_STATUS == 'True');
}
-
- if ( !isset($oscTemplate) || ($PHP_SELF != FILENAME_CHECKOUT_SUCCESS) ) {
- $this->enabled = false;
- }
}
function execute() {
@@ -44,7 +38,7 @@ function execute() {
' </p></div>' .
'</div>';
- $oscTemplate->addBlock($cs_data, $this->group);
+ $oscTemplate->addContent($cs_data, $this->group);
}
function isEnabled() {
@@ -44,7 +44,7 @@ function build() {
$output = '';
- foreach ( $oscTemplate->_data['account'] as $group ) {
+ foreach ( $oscTemplate->_data[$this->group] as $group ) {
$output .= '<h2>' . $group['title'] . '</h2>' .
'<div class="contentText">' .
' <ul class="accountLinkList">';
@@ -63,7 +63,7 @@ function build() {
'</div>';
}
- $oscTemplate->addBlock($output, $this->group);
+ $oscTemplate->addContent($output, $this->group);
}
}
?>

0 comments on commit 615e2c4

Please sign in to comment.