Zen Cart Logo
Forums / General Questions / Sidebox IDs are not unique for sideboxes in top level of includes/modules/sideboxes/.

Sidebox IDs are not unique for sideboxes in top level of includes/modules/sideboxes/.

Views: 824

Results 1 to 7 of 7
6 Mar 2013, 2:30 PM
#1
k9dug avatar

k9dug

New Zenner

Join Date:
Oct 2010
Location:
Glasgow, Scotland
Posts:
29
Plugin Contributions:
0

Sidebox IDs are not unique for sideboxes in top level of includes/modules/sideboxes/.

My pages are failing validator checks - reporting repeated use of id="Content".

The IDs are for sideboxes in the left column.

On investigation, I could see that the id of sideboxes is created in includes/modules/column_single.php, in the following codeblock:

if ( file_exists(DIR_WS_MODULES . 'sideboxes/' . $template_dir . '/' . $column_single_display->fields['layout_box_name']) ) {
	$box_id = zen_get_box_id($column_single_display->fields['layout_box_name']);
	require(DIR_WS_MODULES . 'sideboxes/' . $template_dir . '/' . $column_single_display->fields['layout_box_name']);
} else {
	$box_id = zen_get_box_id($column_single_display->fields['layout_box_name']);
	require(DIR_WS_MODULES . 'sideboxes/' . $column_single_display->fields['layout_box_name']);
}

The code to set the value of $box_id is the same in both halves of this block, but only returns a value if the if statement is satisfied. In other words, only if the sidebox file is present in includes/modules/sideboxes/my_template/ is $box_id set. Then the id will be, for example, "searchContent" (for the search.php sidebox).

Where the sidebox file resides directly in includes/modules/sideboxes/ (not in a template sub-directory of this), $box_id is not set, and the id will be, "Content" (for all sideboxes in this location).

My installation has a lot of custom code. I have tested and cannot see the problem on a fresh install, so I guess it may be a stray mod that's causing this.

Any suggestions where to look to solve this?

6 Mar 2013, 3:14 PM
#2
k9dug avatar

k9dug

New Zenner

Join Date:
Oct 2010
Location:
Glasgow, Scotland
Posts:
29
Plugin Contributions:
0

Re: Sidebox IDs are not unique for sideboxes in top level of includes/modules/sideboxes/.

OK, irrespective of the result of the if statement above, $box_id is being set from the same query:

$column_single_display = $db->Execute("select layout_box_name from " . TABLE_LAYOUT_BOXES . " 
                                       where (layout_box_location=0 or layout_box_location=1) 
                                       and layout_box_status_single=1 
                                       and layout_template ='" . $template_dir . "'" . ' 
                                       order by LPAD(layout_box_sort_order_single,11,"0")');

This returns the sidebox name (layout_box_name) only if that sidebox is listed in the db for the current template.

From my experience with other parts of zen cart, I would have thought that if the sidebox was not present in the template dir, that the default dir would be checked for presence of the file instead. In this case, it may make sense to change the template reference in the query, like so:

$column_single_display_default = $db->Execute("select layout_box_name from " . TABLE_LAYOUT_BOXES . " 
                                               where (layout_box_location=0 or layout_box_location=1) 
                                               and layout_box_status_single=1 
                                               and layout_template ='template_default'"
                                               order by LPAD(layout_box_sort_order_single,11,"0")');

and adapt the }else{ to something like:

 } else if ( file_exists(DIR_WS_MODULES . 'sideboxes/' . $column_single_display_default->fields['layout_box_name']) ) {

This should pull the default name for the sidebox from the db.
Let's try...

6 Mar 2013, 4:25 PM
#3
k9dug avatar

k9dug

New Zenner

Join Date:
Oct 2010
Location:
Glasgow, Scotland
Posts:
29
Plugin Contributions:
0

Re: Sidebox IDs are not unique for sideboxes in top level of includes/modules/sideboxes/.

Still can't get it to work.

Anyone out there with a better understanding of the way sideboxes are generated that can help me?

6 Mar 2013, 5:28 PM
#4
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,876
Plugin Contributions:
8

Re: Sidebox IDs are not unique for sideboxes in top level of includes/modules/sideboxes/.

The IDs are for sideboxes in the left column. First off, why are you using column_single.php for left column sideboxes?
I used a modified clone of column_single to handle sideboxes for the latest version of Editable Centerboxes in Plugins, and that gets appropriate ids, at least where any id is generated.```html

<!-- BOF Middlebox Group 9 --> <div id="navColumnMiddleWrapper9" class="navColumnMiddleWrapper"> <div class="middleboxContainer" id="middlebox_1"><!--// bof: ezpages //--> <div class="singleBoxContainer" id="ezpages"> <h3>Important Links</h3> <div class="middleboxContent"><div id="ezpagesContent" class="sideBoxContent"> <ul style="margin: 0; padding: 0; list-style-type: none;"> ``` It does give some "extra" class tags, mostly because I made minimal changes to stay as close as practical to existing code.

The featured sidebox when used in this container does not generate any *Content id at all. I did not touch the code for any individual sidebox for this; it is all handled uniformly by the global system.

7 Mar 2013, 10:54 AM
#5
k9dug avatar

k9dug

New Zenner

Join Date:
Oct 2010
Location:
Glasgow, Scotland
Posts:
29
Plugin Contributions:
0

Re: Sidebox IDs are not unique for sideboxes in top level of includes/modules/sideboxes/.

gjh42:

First off, why are you using column_single.php for left column sideboxes?

My mistake! I should have said column_left.php. I was looking at both. Apart from that, my question remains the same.

I have confirmed that the IDs for my left boxes are being generated (or should be) from column_left.php by inserting test strings:

  if ( file_exists(DIR_WS_MODULES . 'sideboxes/' . $template_dir . '/' . $column_left_display->fields['layout_box_name']) ) {
      //$box_id = zen_get_box_id($column_left_display->fields['layout_box_name']);
->    $box_id = "left1_";
      require(DIR_WS_MODULES . 'sideboxes/' . $template_dir . '/' . $column_left_display->fields['layout_box_name']);
  } else {
      //$box_id = zen_get_box_id($column_left_display->fields['layout_box_name']);
->    $box_id = "left2_";
      require(DIR_WS_MODULES . 'sideboxes/' . $column_left_display->fields['layout_box_name']);
  }

These result in my left sideboxes having IDs of "left2-Content".

So why are the IDs not being prefixed with the sidebox name?

Looking at the db query that is used for this it seems that only sideboxes which have been added to the database with the template name are being looked for:

$column_left_display= $db->Execute("select layout_box_name from " . TABLE_LAYOUT_BOXES . " 
                                    where layout_box_location = 0 
                                    and layout_box_status= '1' 
                                    and layout_template ='" . $template_dir . "'" . ' 
                                    order by layout_box_sort_order');

Looking in the database table zc_layout_boxes I see that every sidebox is listed four times, with the exception of a couple that are completely new and were added only to the template dir. Here is an extract from the table:

layout_id layout_template           layout_box_name layout_box_status ...
57        classic                   featured.php      0
9         default_template_settings featured.php      1
82        global                    featured.php      0
33        template_default          featured.php      1
100       global                    file_upload.php   1
58        classic                   information.php   0
10        default_template_settings information.php   1
83        global                    information.php   1
34        template_default          information.php   1

This raises the question for me:
Why does column_left.php not look first for the file registered against the template and then, if it doesn't find it, look for it against the default template? The names are there to be used for the sidebox IDs, they are just not being retrieved.

Or am I missing something?

7 Mar 2013, 2:08 PM
#6
k9dug avatar

k9dug

New Zenner

Join Date:
Oct 2010
Location:
Glasgow, Scotland
Posts:
29
Plugin Contributions:
0

Re: Sidebox IDs are not unique for sideboxes in top level of includes/modules/sideboxes/.

Aaaand at ease. It's working now. I removed all my debugging lines and hey presto it works.

No idea why.. Maybe this just proves the theory that just speaking to someone can answer your problem.

I only wish I knew why it didn't work, and why it works...

7 Mar 2013, 3:36 PM
#7
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,876
Plugin Contributions:
8

Re: Sidebox IDs are not unique for sideboxes in top level of includes/modules/sideboxes/.

Looking at the layout_boxes table, I see that every sidebox has an entry for every template installed; if an entry is missing for a template, that would give the result you described. The query should not look in template_default because the table is specifically for the current template box layout and you don't want to be using settings for another template. I suppose that if a new sidebox were added to only one template folder, it would appear only under that template in the table.
This also explains why you need to hit "reset" in the admin page when installing a new template; doing so must generate the template entries in this table, without which the template's sidebox layout cannot be read.