From 6cecff762cdb9f1390b68fbece6464c82b11f2de Mon Sep 17 00:00:00 2001 From: Matt Fletcher Date: Mon, 11 Jan 2021 21:04:10 +0000 Subject: [PATCH 01/42] Fix canonical header tag to work with new category tree The most important change is from buildBreadcrumb to find_path. That alone will fix the bug where it crashes. Also updated the module to latest standards. --- includes/modules/header_tags/ht_canonical.php | 98 ++++++++----------- 1 file changed, 40 insertions(+), 58 deletions(-) diff --git a/includes/modules/header_tags/ht_canonical.php b/includes/modules/header_tags/ht_canonical.php index 096a1d8e9..cd9282044 100644 --- a/includes/modules/header_tags/ht_canonical.php +++ b/includes/modules/header_tags/ht_canonical.php @@ -10,77 +10,59 @@ Released under the GNU General Public License */ - class ht_canonical { - var $code = 'ht_canonical'; - var $group = 'header_tags'; - var $title; - var $description; - var $sort_order; - var $enabled = false; - - function __construct() { - $this->title = MODULE_HEADER_TAGS_CANONICAL_TITLE; - $this->description = MODULE_HEADER_TAGS_CANONICAL_DESCRIPTION; - - if ( defined('MODULE_HEADER_TAGS_CANONICAL_STATUS') ) { - $this->sort_order = MODULE_HEADER_TAGS_CANONICAL_SORT_ORDER; - $this->enabled = (MODULE_HEADER_TAGS_CANONICAL_STATUS == 'True'); - } + class ht_canonical extends abstract_executable_module { + + const CONFIG_KEY_BASE = 'MODULE_HEADER_TAGS_CANONICAL_'; + + public function __construct() { + parent::__construct(__FILE__); } - function execute() { - global $PHP_SELF, $cPath, $oscTemplate, $category_depth; - global $current_category_id, $OSCOM_category; - + public function build_link() { + global $PHP_SELF, $cPath, $current_category_id; + switch (basename($PHP_SELF)) { case 'index.php': - if (isset($cPath) && tep_not_null($cPath) && ($current_category_id > 0) && ($category_depth != 'top')) { - $canonical = $OSCOM_category->buildBreadcrumb($current_category_id); - - $oscTemplate->addBlock('' . PHP_EOL, $this->group); - } - elseif (isset($_GET['manufacturers_id']) && tep_not_null($_GET['manufacturers_id'])) { - $oscTemplate->addBlock('' . PHP_EOL, $this->group); - } - else { - $oscTemplate->addBlock('' . PHP_EOL, $this->group); + if (isset($cPath) && tep_not_null($cPath) && ($current_category_id > 0) && ($GLOBALS['category_depth'] != 'top')) { + $canonical = Guarantor::ensure_global('category_tree')->find_path($current_category_id); + + return tep_href_link('index.php', 'view=all&cPath=' . $canonical, 'SSL', false); + } elseif (isset($_GET['manufacturers_id']) && tep_not_null($_GET['manufacturers_id'])) { + return tep_href_link('index.php', 'view=all&manufacturers_id=' . (int)$_GET['manufacturers_id'], 'SSL', false); } - break; - + + return tep_href_link('index.php', '', 'SSL', false); + case 'product_info.php': - $oscTemplate->addBlock('' . PHP_EOL, $this->group); - break; - + return tep_href_link('product_info.php', 'products_id=' . (int)$_GET['products_id'], 'SSL', false); + case 'products_new.php': case 'specials.php': - $oscTemplate->addBlock('' . PHP_EOL, $this->group); - break; - - default: - $oscTemplate->addBlock('' . PHP_EOL, $this->group); - break; - } - } + return tep_href_link($PHP_SELF, 'view=all', 'SSL', false); - function isEnabled() { - return $this->enabled; - } - - function check() { - return defined('MODULE_HEADER_TAGS_CANONICAL_STATUS'); + default: + return tep_href_link($PHP_SELF, '', 'SSL', false); + } } - function install() { - tep_db_query("insert into configuration (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Enable Canonical Module', 'MODULE_HEADER_TAGS_CANONICAL_STATUS', 'True', 'Do you want to enable the Canonical module?', '6', '1', 'tep_cfg_select_option(array(\'True\', \'False\'), ', now())"); - tep_db_query("insert into configuration (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Sort Order', 'MODULE_HEADER_TAGS_CANONICAL_SORT_ORDER', '0', 'Sort order of display. Lowest is displayed first.', '6', '0', now())"); + public function execute() { + $GLOBALS['oscTemplate']->addBlock('' . PHP_EOL, $this->group); } - function remove() { - tep_db_query("delete from configuration where configuration_key in ('" . implode("', '", $this->keys()) . "')"); + protected function get_parameters() { + return [ + 'MODULE_HEADER_TAGS_CANONICAL_STATUS' => [ + 'title' => 'Enable Canonical Module', + 'value' => 'True', + 'desc' => 'Do you want to enable the Canonical module?', + 'set_func' => "tep_cfg_select_option(['True', 'False'], ", + ], + 'MODULE_HEADER_TAGS_CANONICAL_SORT_ORDER' => [ + 'title' => 'Sort Order', + 'value' => '0', + 'desc' => 'Sort order of display. Lowest is displayed first.', + ], + ]; } - function keys() { - return array('MODULE_HEADER_TAGS_CANONICAL_STATUS', 'MODULE_HEADER_TAGS_CANONICAL_SORT_ORDER'); - } } - \ No newline at end of file From 1e127bea6ac125d982d2421ef8a44d3d71d4cf74 Mon Sep 17 00:00:00 2001 From: Matt Fletcher Date: Tue, 12 Jan 2021 10:29:23 +0000 Subject: [PATCH 02/42] Convert null to '' The new Text::is_empty does stricter type checking, which is often helpful. But in this case, we were relying on PHP type juggling to convert the nulls to empty strings, which then broke the alt text parameter. Converting nulls to '' in the source rather than relying on PHP to do it for us. Same endpoint, only under stricter typing rules. Note that some of these parameters still follow paths that work. E.g. height and width. However, these are likely to be "fixed" later. So going ahead and changing them now rather than waiting until they break. At worst this may be unnecessary. --- includes/modules/boxes/bm_languages.php | 10 +++++----- .../product_info/templates/tpl_cm_pi_gallery.php | 10 +++++----- includes/modules/navbar/templates/tpl_nb_languages.php | 2 +- includes/modules/pi/product_info/pi_gallery.php | 10 +++++----- templates/default/includes/components/product_card.php | 4 ++-- 5 files changed, 18 insertions(+), 18 deletions(-) diff --git a/includes/modules/boxes/bm_languages.php b/includes/modules/boxes/bm_languages.php index 6c7d5a782..315ef3655 100644 --- a/includes/modules/boxes/bm_languages.php +++ b/includes/modules/boxes/bm_languages.php @@ -15,9 +15,9 @@ class bm_languages extends abstract_block_module { const CONFIG_KEY_BASE = 'MODULE_BOXES_LANGUAGES_'; public function execute() { - global $PHP_SELF, $lng, $request_type; + global $PHP_SELF, $lng; - if (substr(basename($PHP_SELF), 0, 8) !== 'checkout') { + if (Text::is_prefixed_by($PHP_SELF, 'checkout')) { if (!isset($lng) || !($lng instanceof language)) { $lng = new language(); } @@ -25,9 +25,9 @@ public function execute() { if (count($lng->catalog_languages) > 1) { $languages_string = ''; $parameters = tep_get_all_get_params(['language', 'currency']) . 'language='; - foreach($lng->catalog_languages as $key => $value) { - $languages_string .= ' ' - . tep_image('includes/languages/' . $value['directory'] . '/images/' . $value['image'], htmlspecialchars($value['name']), null, null, null, false) + foreach ($lng->catalog_languages as $key => $value) { + $languages_string .= ' ' + . tep_image('includes/languages/' . $value['directory'] . '/images/' . $value['image'], htmlspecialchars($value['name']), '', '', '', false) . ' '; } diff --git a/includes/modules/content/product_info/templates/tpl_cm_pi_gallery.php b/includes/modules/content/product_info/templates/tpl_cm_pi_gallery.php index 892120562..154128547 100644 --- a/includes/modules/content/product_info/templates/tpl_cm_pi_gallery.php +++ b/includes/modules/content/product_info/templates/tpl_cm_pi_gallery.php @@ -1,12 +1,12 @@ '; - $other_img_indicator = $other_img = null; + $other_img_indicator = $other_img = ''; foreach ($other_images as $k => $v) { $n = $k+1; $other_img_indicator .= '
  • '; $other_img .= '