Site maintenance: Sun 15 Nov, from 12:00 UTC, about 4–6 hours. Details

This cutover relies on some testing that is still incomplete so may be cancelled at short notice

Forums / Templates, Stylesheets, Page Layout / Sorting EZ-Pages Into Sideboxes

Sorting EZ-Pages Into Sideboxes

Started by ojhernandez on 14 May 2011, 4:24 PM · Views: 2,185

Results 21 to 31 of 31
17 May 2011, 7:51 PM
#21
gjh42 avatar

gjh42

Black Belt

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

Sorting EZ-Pages Into Sideboxes

Okay, zen_href_link(FILENAME_EZPAGES, is required because this doesn't refer to the sidebox at all, but to the ez-page main_page name in the URL.

define('BOX_HEADING_EZPAGES2','Box 2 Heading'); was something I expected to be already defined correctly, but didn't know you hadn't done.

I wouldn't think the $page_query would be a problem any more than the $page_query_list_sidebox, as they are both assigned from scratch in each sidebox and should wipe out any previous content, but maybe something from the first box execution carries over in spite of that. I'll have to test that.

There is one possible failure mode for the display test as is: if there are no actual ez-pages set to display in one of the sideboxes, it will still execute and show an empty box. That can be avoided by moving the filter to an earlier point, in the SQL query. This fetches all sidebox links regardless of which box they are intended to display in:```php
$page_query = $db->Execute("select * from " . TABLE_EZPAGES . " where status_sidebox = 1 and sidebox_sort_order > 0 order by sidebox_sort_order, pages_title");
if ($page_query->RecordCount()>0) {


I had been thinking that this would make a good tutorial to highlight various gotchas that might need to be dealt with when cloning a sidebox; with the additional ones you have uncovered, it would definitely save a lot of grief to also have it in packaged mod form. I'll work on that, with the SQL adaptation I mentioned.
17 May 2011, 11:25 PM
#22
ojhernandez avatar

ojhernandez

New Zenner

Join Date:
May 2010
Posts:
67
Plugin Contributions:
0

Re: Sorting EZ-Pages Into Sideboxes

hairydog:

I had to make a few more changes to get it to work. On line 53 of ezpages2.php it should say

zen_href_link(FILENAME_EZPAGES, 'id='

> 
> The page_query that decides which EZ Page goes into which box wasn't working, because they both had the same name, so I renamed the second to $page_query2
> 
> And I had to add 
> 
> define('BOX_HEADING_EZPAGES2','Box 2 Heading');
> 
> to ez_pages_definitions.php
> 
> And now it works a treat!
> 
> Would it be worth making it a contrib?

I was actually coming to this thread to say that everything works on my end but.....I didn't modify "ezpages2.php" in that way. I also didn't define anything.

Does this mean there is some underlying issue here?

Thanks!,

ojhernandez
18 May 2011, 1:48 AM
#23
gjh42 avatar

gjh42

Black Belt

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

Re: Sorting EZ-Pages Into Sideboxes

If it works, it works. This is not an ambiguous function, so I don't expect surprises if you have it doing what it is supposed to do. I actually didn't notice that it wasn't you who posted those additional changes.

The BOX_HEADING_EZPAGES2, if undefined, will be used as its literal name, and your sidebox would be titled BOX_HEADING_EZPAGES2.

The zen_href_link(FILENAME_EZPAGES, will only be active if the link is to an ez-page; internal or external links will bypass that function and work regardless.

I'm not sure that you actually need to edit $page_query.

18 May 2011, 6:18 AM
#24
gjh42 avatar

gjh42

Black Belt

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

Re: Sorting EZ-Pages Into Sideboxes

For the improved filter, remove the two lines described above in post 6.
Add to the SQL query
and pages_id in (" . EZPAGES_SIDEBOX_FILTER . ")
or
and pages_id in (" . EZPAGES2_SIDEBOX_FILTER . ")
to get```php
$page_query = $db->Execute("select * from " . TABLE_EZPAGES . " where status_sidebox = 1 and sidebox_sort_order > 0 and pages_id in (" . EZPAGES_SIDEBOX_FILTER . ") order by sidebox_sort_order, pages_title");
if ($page_query->RecordCount()>0) {

Make a new file /includes/datafiles/extra_datafiles/ezpages_sidebox_filters.php, with content```php
define('EZPAGES_SIDEBOX_FILTER', '1,3,5,7,11');
define('EZPAGES2_SIDEBOX_FILTER', '2,4,6,8,9,10');  
22 May 2011, 9:02 PM
#25
ojhernandez avatar

ojhernandez

New Zenner

Join Date:
May 2010
Posts:
67
Plugin Contributions:
0

Re: Sorting EZ-Pages Into Sideboxes

gjh42:

For the improved filter, remove the two lines described above in post 6.
Add to the SQL query
and pages_id in (" . EZPAGES_SIDEBOX_FILTER . ")
or
and pages_id in (" . EZPAGES2_SIDEBOX_FILTER . ")
to get```php
$page_query = $db->Execute("select * from " . TABLE_EZPAGES . " where status_sidebox = 1 and sidebox_sort_order > 0 and pages_id in (" . EZPAGES_SIDEBOX_FILTER . ") order by sidebox_sort_order, pages_title");
if ($page_query->RecordCount()>0) {

> Make a new file /includes/datafiles/extra_datafiles/ezpages_sidebox_filters.php, with content```php
define('EZPAGES_SIDEBOX_FILTER', '1,3,5,7,11');
define('EZPAGES2_SIDEBOX_FILTER', '2,4,6,8,9,10');  

Hello again!

I know it has been around 4 days since my last reply but this weekend has been a very busy one!

What do you mean by "add to the SQL query"?

Thanks!

ojhernandez

23 May 2011, 12:28 PM
#26
gjh42 avatar

gjh42

Black Belt

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

Re: Sorting EZ-Pages Into Sideboxes

Find the line in /includes/modules/sideboxes/your_template/ezpages.php and ezpages2.php that starts with $page_query, and add the bit shown to end up as shown in the PHP Code box.

Also make the new file described.

24 May 2011, 10:52 PM
#27
ojhernandez avatar

ojhernandez

New Zenner

Join Date:
May 2010
Posts:
67
Plugin Contributions:
0

Re: Sorting EZ-Pages Into Sideboxes

gjh42:

Find the line in /includes/modules/sideboxes/your_template/ezpages.php and ezpages2.php that starts with $page_query, and add the bit shown to end up as shown in the PHP Code box.

Also make the new file described.

Hello,

I made the file that you described (I had to create the "datafiles" directory.)

Although now I get an error in that sidebox column.

It reads:

Error:

1054 Unknown column 'EZPAGES_SIDEBOX_FILTER' in 'where clause'
in:
[select * from ezpages where status_sidebox = 1 and sidebox_sort_order > 0 and pages_id in (EZPAGES_SIDEBOX_FILTER) order by sidebox_sort_order, pages_title]

I looked at my php files and I can't find anything wrong though, although I'm sure I made a silly mistake.

ezpages.php:

<?php
/**
 * ezpages sidebox - used to display links to EZ-Pages content
 *
 * @package templateSystem
 * @copyright Copyright 2003-2007 Zen Cart Development Team
 * @copyright Portions Copyright 2003 osCommerce
 * @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0
 * @version $Id: ezpages.php 6021 2007-03-17 16:34:19Z ajeh $
 */

  $zco_notifier->notify('NOTIFY_START_EZPAGES_SIDEBOX');

  // test if sidebox should display
  if (EZPAGES_STATUS_SIDEBOX == '1' or (EZPAGES_STATUS_SIDEBOX== '2' and (strstr(EXCLUDE_ADMIN_IP_FOR_MAINTENANCE, $_SERVER['REMOTE_ADDR'])))) {
    if (isset($var_linksList)) {
      unset($var_linksList);
    }
    $page_query = $db->Execute("select * from " . TABLE_EZPAGES . " where status_sidebox = 1 and sidebox_sort_order > 0 and pages_id in (" . EZPAGES_SIDEBOX_FILTER . ") order by sidebox_sort_order, pages_title");
    if ($page_query->RecordCount()>0) {
      $title =  BOX_HEADING_EZPAGES;
      $box_id =  'ezpages';
      $rows = 0;
      while (!$page_query->EOF) {

	

        $rows++;
        $page_query_list_sidebox[$rows]['id'] = $page_query->fields['pages_id'];
        $page_query_list_sidebox[$rows]['name'] = $page_query->fields['pages_title'];
        $page_query_list_sidebox[$rows]['altURL']  = "";
        switch (true) {
          // external link new window or same window
          case ($page_query->fields['alt_url_external'] != ''):
          $page_query_list_sidebox[$rows]['altURL']  = $page_query->fields['alt_url_external'];
          break;
          // internal link new window
          case ($page_query->fields['alt_url'] != '' and $page_query->fields['page_open_new_window'] == '1'):
          $page_query_list_sidebox[$rows]['altURL']  = (substr($page_query->fields['alt_url'],0,4) == 'http') ?
          $page_query->fields['alt_url'] :
          ($page_query->fields['alt_url']=='' ? '' : zen_href_link($page_query->fields['alt_url'], '', ($page_query->fields['page_is_ssl']=='0' ? 'NONSSL' : 'SSL'), true, true, true));
          break;
          // internal link same window
          case ($page_query->fields['alt_url'] != '' and $page_query->fields['page_open_new_window'] == '0'):
          $page_query_list_sidebox[$rows]['altURL']  = (substr($page_query->fields['alt_url'],0,4) == 'http') ?
          $page_query->fields['alt_url'] :
          ($page_query->fields['alt_url']=='' ? '' : zen_href_link($page_query->fields['alt_url'], '', ($page_query->fields['page_is_ssl']=='0' ? 'NONSSL' : 'SSL'), true, true, true));
          break;
        }

        // if altURL is specified, use it; otherwise, use EZPage ID to create link
        $page_query_list_sidebox[$rows]['link'] = ($page_query_list_sidebox[$rows]['altURL'] =='') ?
        zen_href_link(FILENAME_EZPAGES, 'id=' . $page_query->fields['pages_id'] . ($page_query->fields['toc_chapter'] > 0 ? '&chapter=' . $page_query->fields['toc_chapter'] : ''), ($page_query->fields['page_is_ssl']=='0' ? 'NONSSL' : 'SSL')) :
        $page_query_list_sidebox[$rows]['altURL'];
        $page_query_list_sidebox[$rows]['link'] .= ($page_query->fields['page_open_new_window'] == '1' ? '" target="_blank' : '');

	       

	$page_query->MoveNext();
      }

      $title_link = false;

      $var_linksList = $page_query_list_sidebox;

      require($template->get_template_dir('tpl_ezpages.php',DIR_WS_TEMPLATE, $current_page_base,'sideboxes'). '/tpl_ezpages.php');

      $zco_notifier->notify('NOTIFY_END_EZPAGES_SIDEBOX');
      require($template->get_template_dir($column_box_default, DIR_WS_TEMPLATE, $current_page_base,'common') . '/' . $column_box_default);
    }
  } // test for display

  $zco_notifier->notify('NOTIFY_END_EZPAGES_SIDEBOX');
?>

ezpages2.php

<?php
/**
 * ezpages sidebox - used to display links to EZ-Pages content
 *
 * @package templateSystem
 * @copyright Copyright 2003-2007 Zen Cart Development Team
 * @copyright Portions Copyright 2003 osCommerce
 * @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0
 * @version $Id: ezpages.php 6021 2007-03-17 16:34:19Z ajeh $
 */

  $zco_notifier->notify('NOTIFY_START_EZPAGES2_SIDEBOX');

  // test if sidebox should display
  if (EZPAGES_STATUS_SIDEBOX == '1' or (EZPAGES_STATUS_SIDEBOX== '2' and (strstr(EXCLUDE_ADMIN_IP_FOR_MAINTENANCE, $_SERVER['REMOTE_ADDR'])))) {
    if (isset($var_linksList)) {
      unset($var_linksList);
    }
    $page_query = $db->Execute("select * from " . TABLE_EZPAGES . " where status_sidebox = 1 and sidebox_sort_order > 0 and pages_id in (" . EZPAGES2_SIDEBOX_FILTER . ") order by sidebox_sort_order, pages_title");
    if ($page_query->RecordCount()>0) {
      $title =  BOX_HEADING_EZPAGES2;
      $box_id =  'ezpages2';
      $rows = 0;
      while (!$page_query->EOF) {
		

         
        $rows++;
        $page_query_list_sidebox[$rows]['id'] = $page_query->fields['pages_id'];
        $page_query_list_sidebox[$rows]['name'] = $page_query->fields['pages_title'];
        $page_query_list_sidebox[$rows]['altURL']  = "";
        switch (true) {
          // external link new window or same window
          case ($page_query->fields['alt_url_external'] != ''):
          $page_query_list_sidebox[$rows]['altURL']  = $page_query->fields['alt_url_external'];
          break;
          // internal link new window
          case ($page_query->fields['alt_url'] != '' and $page_query->fields['page_open_new_window'] == '1'):
          $page_query_list_sidebox[$rows]['altURL']  = (substr($page_query->fields['alt_url'],0,4) == 'http') ?
          $page_query->fields['alt_url'] :
          ($page_query->fields['alt_url']=='' ? '' : zen_href_link($page_query->fields['alt_url'], '', ($page_query->fields['page_is_ssl']=='0' ? 'NONSSL' : 'SSL'), true, true, true));
          break;
          // internal link same window
          case ($page_query->fields['alt_url'] != '' and $page_query->fields['page_open_new_window'] == '0'):
          $page_query_list_sidebox[$rows]['altURL']  = (substr($page_query->fields['alt_url'],0,4) == 'http') ?
          $page_query->fields['alt_url'] :
          ($page_query->fields['alt_url']=='' ? '' : zen_href_link($page_query->fields['alt_url'], '', ($page_query->fields['page_is_ssl']=='0' ? 'NONSSL' : 'SSL'), true, true, true));
          break;
        }

        // if altURL is specified, use it; otherwise, use EZPage ID to create link
        $page_query_list_sidebox[$rows]['link'] = ($page_query_list_sidebox[$rows]['altURL'] =='') ?
        zen_href_link(FILENAME_EZPAGES2, 'id=' . $page_query->fields['pages_id'] . ($page_query->fields['toc_chapter'] > 0 ? '&chapter=' . $page_query->fields['toc_chapter'] : ''), ($page_query->fields['page_is_ssl']=='0' ? 'NONSSL' : 'SSL')) :
        $page_query_list_sidebox[$rows]['altURL'];
        $page_query_list_sidebox[$rows]['link'] .= ($page_query->fields['page_open_new_window'] == '1' ? '" target="_blank' : '');

	 $page_query->MoveNext();
      }

      $title_link = false;

      $var_linksList = $page_query_list_sidebox;

      require($template->get_template_dir('tpl_ezpages2.php',DIR_WS_TEMPLATE, $current_page_base,'sideboxes'). '/tpl_ezpages2.php');

      $zco_notifier->notify('NOTIFY_END_EZPAGES2_SIDEBOX');
      require($template->get_template_dir($column_box_default, DIR_WS_TEMPLATE, $current_page_base,'common') . '/' . $column_box_default);
    }
  } // test for display

  $zco_notifier->notify('NOTIFY_END_EZPAGES2_SIDEBOX');
?>

ezpages_sidebox_filters:

define('EZPAGES_SIDEBOX_FILTER', '1,3,5,7,11'); 
define('EZPAGES2_SIDEBOX_FILTER', '2,4,6,8,9,10');

Thanks in Advance!

ojhernandez

25 May 2011, 4:42 AM
#28
gjh42 avatar

gjh42

Black Belt

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

Re: Sorting EZ-Pages Into Sideboxes

The SQL error message indicates that the constant definition is not being processed before the file with the SQL runs. I made an error in the folder names - it should be just /includes/extra_datafiles/ezpages_sidebox_filters.php - no /datafiles/ folder. Sorry about that.

26 May 2011, 2:13 AM
#29
ojhernandez avatar

ojhernandez

New Zenner

Join Date:
May 2010
Posts:
67
Plugin Contributions:
0

Re: Sorting EZ-Pages Into Sideboxes

gjh42:

The SQL error message indicates that the constant definition is not being processed before the file with the SQL runs. I made an error in the folder names - it should be just /includes/extra_datafiles/ezpages_sidebox_filters.php - no /datafiles/ folder. Sorry about that.

I fixed the folder issue but now there is new unwanted behavior.

The same error displays in the sidebox:

Error:

1054 Unknown column 'EZPAGES_SIDEBOX_FILTER' in 'where clause'
in:
[select * from ezpages where status_sidebox = 1 and sidebox_sort_order > 0 and pages_id in (EZPAGES_SIDEBOX_FILTER) order by sidebox_sort_order, pages_title]

But now, it displays "define('EZPAGES_SIDEBOX_FILTER', '1,3,5,7,11'); define('EZPAGES2_SIDEBOX_FILTER', '2,4,6,8,9,10');" at the top of my page.

Did I overlook something?

Thanks in Advance!

ojhernandez

27 May 2011, 5:56 PM
#30
ojhernandez avatar

ojhernandez

New Zenner

Join Date:
May 2010
Posts:
67
Plugin Contributions:
0

Re: Sorting EZ-Pages Into Sideboxes

I've decided to go ahead with the method that you described in post 6 since it was working for me.

Although I have one question regarding it,

where is BOX_HEADING_EZPAGES2 defined so I can change the text that it displays for the heading on the sidebox?

Thanks in Advance!

ojhernandez

27 May 2011, 6:15 PM
#31
ojhernandez avatar

ojhernandez

New Zenner

Join Date:
May 2010
Posts:
67
Plugin Contributions:
0

Re: Sorting EZ-Pages Into Sideboxes

ojhernandez:

I've decided to go ahead with the method that you described in post 6 since it was working for me.

Although I have one question regarding it,

where is BOX_HEADING_EZPAGES2 defined so I can change the text that it displays for the heading on the sidebox?

Thanks in Advance!

ojhernandez

I have found the answer to my question. I have posted it here so that it may help anyone else who sees this post and has the same question. :)

http://www.zen-cart.com/forum/showthread.php?t=78008

RuFuS:

includes/languages/english/extra_definitions/yourtemplate/ez_pages_definitions.php

Your looking for define('BOX_HEADING_EZPAGES','Important Links');

or actually in your case

define('BOX_HEADING_EZPAGES','Useful_Articles');

I wasn't sure if you had already found it or you are using a template :blink:

ojhernandez