News:

You may pay someone to create your store, or you visit our seminar and become a professional yourself with the silver certification

Main Menu

Bug in template.class.php

Started by doorknob, April 17, 2009, 00:02:55 AM

Previous topic - Next topic

doorknob

The fetch() method tests whether the template file exists using the php function file_exists(). This function returns true whether the 'file' is a file or a directory. If the fetch() function is called with an empty string as the template file name, file_exists() is used to validate the default path. Because this is a valid directory, a value of true is returned. The fetch() function then executes the include() without a proper file name which generates an error. Lines 212 to 216 should be changed from
if( file_exists( $this->path . $file ) ) {
include($this->path . $file);  // Include the file
} elseif( file_exists( $this->default_path . $file ) ) {
include( $this->default_path . $file );
}

to
if( is_file( $this->path . $file ) ) {
include($this->path . $file);  // Include the file
} elseif( is_file( $this->default_path . $file ) ) {
include( $this->default_path . $file );
}


Regards
Phil
J1.5.10 VM 1.1.3


doorknob

The error occurs if the fetch() method is called with an empty argument (template file name). I have adapted a commercial module for product presentation so that it calls template files and uses separate templates for different components of the presentation. The name of each template file is provided by a series of module parameters. Not all of the components are used for every instance of the module. When fetch() is called with an empty parameter because the corresponding component is not used, it crashes. The code is intended to protect against this situation but doesn't because file_exists() returns true even if the file name is missing, so long as the path is a valid directory. When I changed the test function to is_file(), it worked as I had expected and now my module works correctly. As an example, the centre column of this page http://www.eyeforabargain.co.uk/ shows two instances of the module. This first has a single product with a header and a horizontal divider but no need for a vertical divider. The second has no header but uses both the horizontal and vertical dividers to present multiple products two per row. By having the facility for the components to be optional, I have created the illusion of a single module with a composite presentation style.
Regards
phil