Skip to content
Browse files

Generalize header tags oscTemplate class methods to support groups of…

… modules interact with the template layout
  • Loading branch information...
1 parent 426e9a4 commit c2066d29b4f89e83ebc4fddd3041fb53cdf4b224 @haraldpdl haraldpdl committed Nov 5, 2010
View
22 catalog/admin/modules.php
@@ -22,41 +22,47 @@
$module_language_directory = DIR_FS_CATALOG_LANGUAGES;
$module_key = 'MODULE_SHIPPING_INSTALLED';
define('HEADING_TITLE', HEADING_TITLE_MODULES_SHIPPING);
+ $template_integration = false;
break;
case 'ordertotal':
$module_type = 'order_total';
$module_directory = DIR_FS_CATALOG_MODULES . 'order_total/';
$module_language_directory = DIR_FS_CATALOG_LANGUAGES;
$module_key = 'MODULE_ORDER_TOTAL_INSTALLED';
define('HEADING_TITLE', HEADING_TITLE_MODULES_ORDER_TOTAL);
+ $template_integration = false;
break;
case 'actionrecorder':
$module_type = 'action_recorder';
$module_directory = DIR_FS_CATALOG_MODULES . 'action_recorder/';
$module_language_directory = DIR_FS_CATALOG_LANGUAGES;
$module_key = 'MODULE_ACTION_RECORDER_INSTALLED';
define('HEADING_TITLE', HEADING_TITLE_MODULES_ACTION_RECORDER);
+ $template_integration = false;
break;
case 'social_bookmarks':
$module_type = 'social_bookmarks';
$module_directory = DIR_FS_CATALOG_MODULES . 'social_bookmarks/';
$module_language_directory = DIR_FS_CATALOG_LANGUAGES;
$module_key = 'MODULE_SOCIAL_BOOKMARKS_INSTALLED';
define('HEADING_TITLE', HEADING_TITLE_MODULES_SOCIAL_BOOKMARKS);
+ $template_integration = false;
break;
case 'header_tags':
$module_type = 'header_tags';
$module_directory = DIR_FS_CATALOG_MODULES . 'header_tags/';
$module_language_directory = DIR_FS_CATALOG_LANGUAGES;
$module_key = 'MODULE_HEADER_TAGS_INSTALLED';
define('HEADING_TITLE', HEADING_TITLE_MODULES_HEADER_TAGS);
+ $template_integration = true;
break;
case 'dashboard':
$module_type = 'dashboard';
$module_directory = DIR_FS_ADMIN . 'includes/modules/dashboard/';
$module_language_directory = DIR_FS_ADMIN . 'includes/languages/';
$module_key = 'MODULE_ADMIN_DASHBOARD_INSTALLED';
define('HEADING_TITLE', HEADING_TITLE_MODULES_ADMIN_DASHBOARD);
+ $template_integration = false;
break;
case 'payment':
default:
@@ -65,6 +71,7 @@
$module_language_directory = DIR_FS_CATALOG_LANGUAGES;
$module_key = 'MODULE_PAYMENT_INSTALLED';
define('HEADING_TITLE', HEADING_TITLE_MODULES_PAYMENT);
+ $template_integration = false;
break;
}
}
@@ -235,6 +242,21 @@
} else {
tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Installed Modules', '" . $module_key . "', '" . implode(';', $installed_modules) . "', 'This is automatically updated. No need to edit.', '6', '0', now())");
}
+
+ if ($template_integration == true) {
+ $check_query = tep_db_query("select configuration_value from " . TABLE_CONFIGURATION . " where configuration_key = 'TEMPLATE_BLOCK_GROUPS'");
+ if (tep_db_num_rows($check_query)) {
+ $check = tep_db_fetch_array($check_query);
+ $tbgroups_array = explode(';', $check['configuration_value']);
+ if (!in_array($module_type, $tbgroups_array)) {
+ $tbgroups_array[] = $module_type;
+ sort($tbgroups_array);
+ tep_db_query("update " . TABLE_CONFIGURATION . " set configuration_value = '" . implode(';', $tbgroups_array) . "', last_modified = now() where configuration_key = 'TEMPLATE_BLOCK_GROUPS'");
+ }
+ } else {
+ tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Installed Template Block Groups', 'TEMPLATE_BLOCK_GROUPS', '" . $module_type . "', 'This is automatically updated. No need to edit.', '6', '0', now())");
+ }
+ }
}
?>
<tr>
View
48 catalog/includes/classes/osc_template.php
@@ -12,7 +12,7 @@
class oscTemplate {
var $_title;
- var $_header_tags = array();
+ var $_blocks = array();
function oscTemplate() {
$this->_title = TITLE;
@@ -26,34 +26,46 @@ function getTitle() {
return $this->_title;
}
- function addHeaderTag($tag) {
- $this->_header_tags[] = $tag;
+ function addBlock($block, $group) {
+ $this->_blocks[$group][] = $block;
}
- function getHeaderTags() {
- if (!empty($this->_header_tags)) {
- return implode("\n", $this->_header_tags);
+ function hasBlocks($group) {
+ return (isset($this->_blocks[$group]) && !empty($this->_blocks[$group]));
+ }
+
+ function getBlocks($group) {
+ if ($this->hasBlocks($group)) {
+ return implode("\n", $this->_blocks[$group]);
}
}
- function buildHeaderTags() {
+ function buildBlocks() {
global $language;
- if ( defined('MODULE_HEADER_TAGS_INSTALLED') && tep_not_null(MODULE_HEADER_TAGS_INSTALLED) ) {
- $htm_array = explode(';', MODULE_HEADER_TAGS_INSTALLED);
+ if ( defined('TEMPLATE_BLOCK_GROUPS') && tep_not_null(TEMPLATE_BLOCK_GROUPS) ) {
+ $tbgroups_array = explode(';', TEMPLATE_BLOCK_GROUPS);
- foreach ( $htm_array as $htm ) {
- $class = substr($htm, 0, strrpos($htm, '.'));
+ foreach ($tbgroups_array as $group) {
+ $module_key = 'MODULE_' . strtoupper($group) . '_INSTALLED';
- if ( !class_exists($class) ) {
- include(DIR_WS_LANGUAGES . $language . '/modules/header_tags/' . $htm);
- include(DIR_WS_MODULES . 'header_tags/' . $class . '.php');
- }
+ if ( defined($module_key) && tep_not_null($module_key) ) {
+ $modules_array = explode(';', constant($module_key));
+
+ foreach ( $modules_array as $module ) {
+ $class = substr($module, 0, strrpos($module, '.'));
+
+ if ( !class_exists($class) ) {
+ include(DIR_WS_LANGUAGES . $language . '/modules/' . $group . '/' . $module);
+ include(DIR_WS_MODULES . $group . '/' . $class . '.php');
+ }
- $ht = new $class();
+ $mb = new $class();
- if ( $ht->isEnabled() ) {
- $ht->execute();
+ if ( $mb->isEnabled() ) {
+ $mb->execute();
+ }
+ }
}
}
}
View
1 catalog/includes/modules/header_tags/ht_category_title.php
@@ -12,6 +12,7 @@
class ht_category_title {
var $code = 'ht_category_title';
+ var $group = 'header_tags';
var $title;
var $description;
var $sort_order;
View
10 catalog/includes/modules/header_tags/ht_google_analytics.php
@@ -12,6 +12,7 @@
class ht_google_analytics {
var $code = 'ht_google_analytics';
+ var $group = 'header_tags';
var $title;
var $description;
var $sort_order;
@@ -31,6 +32,10 @@ function execute() {
global $PHP_SELF, $oscTemplate, $customer_id;
if (tep_not_null(MODULE_HEADER_TAGS_GOOGLE_ANALYTICS_ID)) {
+ if (MODULE_HEADER_TAGS_GOOGLE_ANALYTICS_JS_PLACEMENT != 'Header') {
+ $this->group = 'footer_scripts';
+ }
+
$header = '<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push([\'_setAccount\', \'' . tep_output_string(MODULE_HEADER_TAGS_GOOGLE_ANALYTICS_ID) . '\']);
@@ -86,7 +91,7 @@ function execute() {
})();
</script>' . "\n";
- $oscTemplate->addHeaderTag($header);
+ $oscTemplate->addBlock($header, $this->group);
}
}
@@ -116,6 +121,7 @@ function install() {
tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Enable Google Analytics Module', 'MODULE_HEADER_TAGS_GOOGLE_ANALYTICS_STATUS', 'True', 'Do you want to add Google Analytics to your shop?', '6', '1', 'tep_cfg_select_option(array(\'True\', \'False\'), ', now())");
tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Google Analytics ID', 'MODULE_HEADER_TAGS_GOOGLE_ANALYTICS_ID', '', 'The Google Analytics profile ID to track.', '6', '0', now())");
tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('E-Commerce Tracking', 'MODULE_HEADER_TAGS_GOOGLE_ANALYTICS_EC_TRACKING', 'True', 'Do you want to enable e-commerce tracking? (E-Commerce tracking must also be enabled in your Google Analytics profile settings)', '6', '1', 'tep_cfg_select_option(array(\'True\', \'False\'), ', now())");
+ tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Javascript Placement', 'MODULE_HEADER_TAGS_GOOGLE_ANALYTICS_JS_PLACEMENT', 'Header', 'Should the Google Analytics javascript be loaded in the header or footer?', '6', '1', 'tep_cfg_select_option(array(\'Header\', \'Footer\'), ', now())");
tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Sort Order', 'MODULE_HEADER_TAGS_GOOGLE_ANALYTICS_SORT_ORDER', '0', 'Sort order of display. Lowest is displayed first.', '6', '0', now())");
}
@@ -124,7 +130,7 @@ function remove() {
}
function keys() {
- return array('MODULE_HEADER_TAGS_GOOGLE_ANALYTICS_STATUS', 'MODULE_HEADER_TAGS_GOOGLE_ANALYTICS_ID', 'MODULE_HEADER_TAGS_GOOGLE_ANALYTICS_EC_TRACKING', 'MODULE_HEADER_TAGS_GOOGLE_ANALYTICS_SORT_ORDER');
+ return array('MODULE_HEADER_TAGS_GOOGLE_ANALYTICS_STATUS', 'MODULE_HEADER_TAGS_GOOGLE_ANALYTICS_ID', 'MODULE_HEADER_TAGS_GOOGLE_ANALYTICS_EC_TRACKING', 'MODULE_HEADER_TAGS_GOOGLE_ANALYTICS_JS_PLACEMENT', 'MODULE_HEADER_TAGS_GOOGLE_ANALYTICS_SORT_ORDER');
}
}
?>
View
1 catalog/includes/modules/header_tags/ht_manufacturer_title.php
@@ -12,6 +12,7 @@
class ht_manufacturer_title {
var $code = 'ht_manufacturer_title';
+ var $group = 'header_tags';
var $title;
var $description;
var $sort_order;
View
3 catalog/includes/modules/header_tags/ht_opensearch.php
@@ -12,6 +12,7 @@
class ht_opensearch {
var $code = 'ht_opensearch';
+ var $group = 'header_tags';
var $title;
var $description;
var $sort_order;
@@ -30,7 +31,7 @@ function ht_opensearch() {
function execute() {
global $oscTemplate;
- $oscTemplate->addHeaderTag('<link rel="search" type="application/opensearchdescription+xml" href="' . tep_href_link('opensearch.php', '', 'NONSSL', false) . '" title="' . tep_output_string(STORE_NAME) . '" />');
+ $oscTemplate->addBlock('<link rel="search" type="application/opensearchdescription+xml" href="' . tep_href_link('opensearch.php', '', 'NONSSL', false) . '" title="' . tep_output_string(STORE_NAME) . '" />', $this->group);
}
function isEnabled() {
View
1 catalog/includes/modules/header_tags/ht_product_title.php
@@ -12,6 +12,7 @@
class ht_product_title {
var $code = 'ht_product_title';
+ var $group = 'header_tags';
var $title;
var $description;
var $sort_order;
View
2 catalog/includes/template_bottom.php
@@ -21,5 +21,7 @@
</div> <!-- bodyWrapper //-->
+<?php echo $oscTemplate->getBlocks('footer_scripts'); ?>
+
</body>
</html>
View
4 catalog/includes/template_top.php
@@ -10,7 +10,7 @@
Released under the GNU General Public License
*/
- $oscTemplate->buildHeaderTags();
+ $oscTemplate->buildBlocks();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html <?php echo HTML_PARAMS; ?>>
@@ -26,7 +26,7 @@
<script type="text/javascript" src="ext/jquery/fancybox/jquery.fancybox-1.3.1.pack.js"></script>
<link rel="stylesheet" type="text/css" href="ext/960gs/<?php echo ((stripos(HTML_PARAMS, 'dir="rtl"') !== false) ? 'rtl_' : ''); ?>960_24_col.css" />
<link rel="stylesheet" type="text/css" href="stylesheet.css" />
-<?php echo $oscTemplate->getHeaderTags(); ?>
+<?php echo $oscTemplate->getBlocks('header_tags'); ?>
</head>
<body>

0 comments on commit c2066d2

Please sign in to comment.
Something went wrong with that request. Please try again.