Permalink
Browse files

Update Robot NoIndex Header Tag Module

* Show a list of files for the store owner to choose from (thanks to Jack (Jack_mcs) for the feedback and Laurent (foxp2) for the code sample)
* Change the robots meta content value to noindex,follow
  • Loading branch information...
1 parent 250462d commit 2c9216a07bfbde779a5527936e1f137464de24e4 @haraldpdl haraldpdl committed Jul 29, 2012
Showing with 63 additions and 6 deletions.
  1. +63 −6 catalog/includes/modules/header_tags/ht_robot_noindex.php
@@ -34,7 +34,7 @@ function execute() {
if (tep_not_null(MODULE_HEADER_TAGS_ROBOT_NOINDEX_PAGES)) {
$pages_array = array();
- foreach (explode("\n", MODULE_HEADER_TAGS_ROBOT_NOINDEX_PAGES) as $page) {
+ foreach (explode(';', MODULE_HEADER_TAGS_ROBOT_NOINDEX_PAGES) as $page) {
$page = trim($page);
if (!empty($page)) {
@@ -43,7 +43,7 @@ function execute() {
}
if (in_array(basename($PHP_SELF), $pages_array)) {
- $oscTemplate->addBlock('<meta name="robots" content="noindex" />' . "\n", $this->group);
+ $oscTemplate->addBlock('<meta name="robots" content="noindex,follow" />' . "\n", $this->group);
}
}
}
@@ -58,7 +58,7 @@ function check() {
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 Robot NoIndex Module', 'MODULE_HEADER_TAGS_ROBOT_NOINDEX_STATUS', 'True', 'Do you want to enable the Robot NoIndex module?', '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, use_function, set_function, date_added) values ('Pages', 'MODULE_HEADER_TAGS_ROBOT_NOINDEX_PAGES', '" . implode("\n", $this->get_default_pages()) . "', 'The pages to add the meta robot noindex tag to.', '6', '0', 'ht_robot_noindex_show_pages', 'ht_robot_noindex_edit_pages(', now())");
+ tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, use_function, set_function, date_added) values ('Pages', 'MODULE_HEADER_TAGS_ROBOT_NOINDEX_PAGES', '" . implode(';', $this->get_default_pages()) . "', 'The pages to add the meta robot noindex tag to.', '6', '0', 'ht_robot_noindex_show_pages', 'ht_robot_noindex_edit_pages(', 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_ROBOT_NOINDEX_SORT_ORDER', '0', 'Sort order of display. Lowest is displayed first.', '6', '0', now())");
}
@@ -102,10 +102,67 @@ function get_default_pages() {
}
function ht_robot_noindex_show_pages($text) {
- return nl2br($text);
+ return nl2br(implode("\n", explode(';', $text)));
}
- function ht_robot_noindex_edit_pages($text, $key) {
- return tep_draw_textarea_field('configuration[' . $key . ']', false, 35, 5, $text);
+ function ht_robot_noindex_edit_pages($values, $key) {
+ global $PHP_SELF;
+
+ $file_extension = substr($PHP_SELF, strrpos($PHP_SELF, '.'));
+ $files_array = array();
+ if ($dir = @dir(DIR_FS_CATALOG)) {
+ while ($file = $dir->read()) {
+ if (!is_dir(DIR_FS_CATALOG . $file)) {
+ if (substr($file, strrpos($file, '.')) == $file_extension) {
+ $files_array[] = $file;
+ }
+ }
+ }
+ sort($files_array);
+ $dir->close();
+ }
+
+ $values_array = explode(';', $values);
+
+ $output = '';
+ foreach ($files_array as $file) {
+ $output .= tep_draw_checkbox_field('ht_robot_noindex_file[]', $file, in_array($file, $values_array)) . '&nbsp;' . tep_output_string($file) . '<br />';
+ }
+
+ if (!empty($output)) {
+ $output = '<br />' . substr($output, 0, -6);
+ }
+
+ $output .= tep_draw_hidden_field('configuration[' . $key . ']', '', 'id="htrn_files"');
+
+ $output .= '<script type="text/javascript">
+ function htrn_update_cfg_value() {
+ var htrn_selected_files = \'\';
+
+ if ($(\'input[name="ht_robot_noindex_file[]"]\').length > 0) {
+ $(\'input[name="ht_robot_noindex_file[]"]:checked\').each(function() {
+ htrn_selected_files += $(this).attr(\'value\') + \';\';
+ });
+
+ if (htrn_selected_files.length > 0) {
+ htrn_selected_files = htrn_selected_files.substring(0, htrn_selected_files.length - 1);
+ }
+ }
+
+ $(\'#htrn_files\').val(htrn_selected_files);
+ }
+
+ $(function() {
+ htrn_update_cfg_value();
+
+ if ($(\'input[name="ht_robot_noindex_file[]"]\').length > 0) {
+ $(\'input[name="ht_robot_noindex_file[]"]\').change(function() {
+ htrn_update_cfg_value();
+ });
+ }
+ });
+ </script>';
+
+ return $output;
}
?>

0 comments on commit 2c9216a

Please sign in to comment.