X-Cart: shopping cart software

X-Cart forums (https://forum.x-cart.com/index.php)
-   Dev Questions (https://forum.x-cart.com/forumdisplay.php?f=20)
-   -   The template names in the source code (https://forum.x-cart.com/showthread.php?t=32118)

Ene 06-27-2007 02:55 AM

The template names in the source code
 
1 Attachment(s)
Disclaimer: This mod is provided on an "as-is" basis without warranty of any kind. Feel free to use and improve it, but please do not sell it.

Description: This mod is for those X-Cart masters who are not familiar with the templates structure yet. Install this mod, refresh any dynamic X-Cart page and check the HTML source. You'll see that X-Cart prints the templates names where the '{include}' Smarty tags are used. So you'll be able to find the required template easily, just check the source and find the template name near the necessary HTML code.

How to install:

0. This mod was created for X-Cart 4.1.7. If you use other X-Cart versions, you may need to alter the code.

1. Edit the '<xcart_dir>/include/func/func.core.php' file and add the following code before the last '>?' line:

PHP Code:

function func_show_as_comment($string$end=false) {
    
$templates = array (
       
"buttons/go_image_menu.tpl",
       
"modules/Special_Offers/customer/cart_checkout_buttons.tpl",
       
"main/title_selector.tpl",
       
"modules/QuickBooks/orders.tpl",
       
"modules/UPS_OnLine_Tools/ups_currency.tpl",
       
"buttons/go_image.tpl",
       
"buttons/go_image_menu.tpl",
       
"main/image_property.tpl",
       
"main/include_js.tpl"
   
);
if (!
in_array($string$templates) ) {

echo 
"\n\n<!--";
if (
$end) echo " / ";
echo 
"$string -->\n\n";
}




2. Edit the '<xcart_dir>/Smarty-2.6.12/Smarty.class.php' file, replace:

PHP Code:

function fetch($resource_name$cache_id null$compile_id null$display false)
  {
      static 
$_cache_info = array(); 


with

PHP Code:

function fetch($resource_name$cache_id null$compile_id null$display false)
  {
      static 
$_cache_info = array();
     
func_show_as_comment($resource_name); 


then replace:

PHP Code:

ob_start();
          if (
$this->_is_compiled($resource_name$_smarty_compile_path)
                  || 
$this->_compile_resource($resource_name$_smarty_compile_path))
          {
              include(
$_smarty_compile_path);
          }

          
$_smarty_results ob_get_contents();
          
ob_end_clean(); 


with

PHP Code:

ob_start();
          if (
$this->_is_compiled($resource_name$_smarty_compile_path)
                  || 
$this->_compile_resource($resource_name$_smarty_compile_path))
          {
              include(
$_smarty_compile_path);
          }
     
func_show_as_comment($resource_nametrue);

          
$_smarty_results ob_get_contents();
          
ob_end_clean(); 


3. Again edit the '<xcart_dir>/Smarty-2.6.12/Smarty.class.php' file, replace:

PHP Code:

function _smarty_include($params)

  {
       if (
$this->debugging) { 


with

PHP Code:

function _smarty_include($params)

  {
      
func_show_as_comment($params[smarty_include_tpl_file]);
      if (
$this->debugging) { 


and replace:

PHP Code:

$this->_smarty_debug_info[$included_tpls_idx]['exec_time'] = smarty_core_get_microtime($_params$this) - $debug_start_time;
      }

      if (
$this->caching) {
          
$this->_cache_info['template'][$params['smarty_include_tpl_file']] = true;
      }
  } 


with

PHP Code:

$this->_smarty_debug_info[$included_tpls_idx]['exec_time'] = smarty_core_get_microtime($_params$this) - $debug_start_time;
      }

      if (
$this->caching) {
          
$this->_cache_info['template'][$params['smarty_include_tpl_file']] = true;
      }
      
func_show_as_comment($params[smarty_include_tpl_file], true);

  } 


Jerrad 06-27-2007 04:19 AM

Re: The template names in the source code
 
I wish I had this mod a year ago...
Thanks anyway! :D

carpeperdiem 06-27-2007 06:42 AM

Re: The template names in the source code
 
:-)

very cool.

this should be stock... HOWEVER, there should be a "disable" switch so a visitor can't see or try to exploit this info.

I don't need visitors knowing paths and template names.

BUT - this is a great idea for newbies and stores in development.

Thanks for posting this!

Ene 06-28-2007 11:32 PM

Re: The template names in the source code
 
Quote:

Originally Posted by carpeperdiem
:-)

very cool.

this should be stock... HOWEVER, there should be a "disable" switch so a visitor can't see or try to exploit this info.

I don't need visitors knowing paths and template names.

BUT - this is a great idea for newbies and stores in development.

Thanks for posting this!


Use the following code:

PHP Code:

function func_show_as_comment($string$end=false) { 
global 
$show_template_names;

    
$templates = array ( 
       
"buttons/go_image_menu.tpl"
       
"modules/Special_Offers/customer/cart_checkout_buttons.tpl"
       
"main/title_selector.tpl"
       
"modules/QuickBooks/orders.tpl"
       
"modules/UPS_OnLine_Tools/ups_currency.tpl"
       
"buttons/go_image.tpl"
       
"buttons/go_image_menu.tpl"
       
"main/image_property.tpl"
       
"main/include_js.tpl" 
   
); 
if (!
in_array($string$templates) && $show_template_names) { 

echo 
"\n\n<!--"
if (
$end) echo " / "
echo 
"$string -->\n\n"




X-Cart will show the template names only for the URLs like 'home.php?cat=111&show_template_names=Y', i.e. with 'show_template_names' parameter.

carpeperdiem 06-29-2007 04:20 AM

Re: The template names in the source code
 
Eugene,

Thanks... that's great, but for those of us with cdseo, this will not work, since our URLS look like, "domain.com/category/product.html

But thank you for the idea...

Ene 06-29-2007 04:26 AM

Re: The template names in the source code
 
Quote:

Originally Posted by carpeperdiem
Eugene,

Thanks... that's great, but for those of us with cdseo, this will not work, since our URLS look like, "domain.com/category/product.html

But thank you for the idea...



The 'func_show_as_comment()' function can check that administrator is logged in, so X-Cart will show the template names in such cases only. (i.e. you log in as administrator and open the customer area)
If you need this code, I can create it : )

carpeperdiem 06-29-2007 04:30 AM

Re: The template names in the source code
 
Quote:

The 'func_show_as_comment()' function can check that administrator is logged in, so X-Cart will show the template names in such cases only. (i.e. you log in as administrator and open the customer area)
If you need this code, I can create it : )

Well that's a grea idea! So only a logged in admin (on the customer side) will see the code? Now that's brilliant.

Is there a performance hit asociated with this?

Thanks for contributing this!

Ene 06-29-2007 05:11 AM

Re: The template names in the source code
 
Quote:

Is there a performance hit asociated with this?

No.

Quote:

Now that's brilliant.

Use this code:

PHP Code:

function func_show_as_comment($string$end=false) {
global 
$identifiers;
     
$templates = array (
        
"buttons/go_image_menu.tpl",
        
"modules/Special_Offers/customer/cart_checkout_buttons.tpl",
        
"main/title_selector.tpl",
        
"modules/QuickBooks/orders.tpl",
        
"modules/UPS_OnLine_Tools/ups_currency.tpl",
        
"buttons/go_image.tpl",
        
"buttons/go_image_menu.tpl",
        
"main/image_property.tpl",
        
"main/include_js.tpl"
    
);
if (!
in_array($string$templates) && (array_key_exists("P"$identifiers) || array_key_exists("A"$identifiers))) {

echo 
"\n\n<!--";
if (
$end) echo " / ";
echo 
"$string -->\n\n";
}



: )

carpeperdiem 06-29-2007 12:20 PM

Re: The template names in the source code
 
Eugene,

I found a slight problem with this new mod:

In Windows IE6 and IE7, WHILE LOGGED IN as admin, it disrupts the css style sheet, to the point where a "centered" container no longer centers, category menus
distort and basically the site looks like doo. A simple logout by the admin and everything is back to normal. if the admin logs in, then it looks like doo again (that is, CSS is not recognized or used).

This problem does not show itself in Firefox (win or mac) or any mac browser. I did not test in Safari/windows.

Basically, whatever is going on here disrupts the CSS code in MSIE 6 and 7 (win XP pro SP2 -- tested on 2 different machines) - ONLY when logged in as admin.

For now, I have reverted to what I had, and I can re-visit this another time...

Thanks

Jeremy

Ene 07-17-2007 11:09 AM

Re: The template names in the source code
 
Quote:

I found a slight problem with this new mod:


I've checked this mod on the default X-Cart installation and haven't found any errors.

Do you use any custom templates?
If yes, you need to add their names to the '$templates' array, so the 'func_show_as_comment' function will not process them.


All times are GMT -8. The time now is 03:02 PM.

Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.