Follow us on Twitter X-Cart on Facebook Wiki
Shopping cart software Solutions for online shops and malls

The template names in the source code
 
Reply
   X-Cart forums > X-Cart 4 > Changing and adding new features
 
Thread Tools Search this Thread
  #1  
Old 06-27-2007, 02:55 AM
  Ene's Avatar 
Ene Ene is offline
 

X-Cart team
  
Join Date: Aug 2004
Posts: 907
 

Smile The template names in the source code

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);

  } 
Attached Thumbnails
Click image for larger version

Name:	source_code.png
Views:	168
Size:	16.8 KB
ID:	442  
__________________
Eugene Kaznacheev,
Evangelist/Product Manager at Ecwid: http://www.ecwid.com/ (since Sept 2009)

ex-Head of X-Cart Tech Support Department
ex- X-Cart Hosting Manager - X-Cart hosting
ex-X-Cart Technical Support Engineer


Note: For the official guaranteed tech support services please turn to the Customers HelpDesk.
Reply With Quote
  #2  
Old 06-27-2007, 04:19 AM
 
Jerrad Jerrad is offline
 

X-Adept
  
Join Date: Nov 2004
Location: The Netherlands
Posts: 484
 

Default Re: The template names in the source code

I wish I had this mod a year ago...
Thanks anyway!
__________________
X-Cart 4.0.12
Heavy modified with paid, free and forum mods.
PHP 5.2.5 | MYSQL 5.0.51a
Reply With Quote
  #3  
Old 06-27-2007, 06:42 AM
 
carpeperdiem carpeperdiem is offline
 

X-Guru
  
Join Date: Jul 2006
Location: New York City, USA
Posts: 5,399
 

Default 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!
__________________
xcart 4.5.4 gold+ w/x-payments 1.0.6; xcart gold 4.4.4
Reply With Quote
  #4  
Old 06-28-2007, 11:32 PM
  Ene's Avatar 
Ene Ene is offline
 

X-Cart team
  
Join Date: Aug 2004
Posts: 907
 

Default 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.
__________________
Eugene Kaznacheev,
Evangelist/Product Manager at Ecwid: http://www.ecwid.com/ (since Sept 2009)

ex-Head of X-Cart Tech Support Department
ex- X-Cart Hosting Manager - X-Cart hosting
ex-X-Cart Technical Support Engineer


Note: For the official guaranteed tech support services please turn to the Customers HelpDesk.
Reply With Quote
  #5  
Old 06-29-2007, 04:20 AM
 
carpeperdiem carpeperdiem is offline
 

X-Guru
  
Join Date: Jul 2006
Location: New York City, USA
Posts: 5,399
 

Default 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...
__________________
xcart 4.5.4 gold+ w/x-payments 1.0.6; xcart gold 4.4.4
Reply With Quote
  #6  
Old 06-29-2007, 04:26 AM
  Ene's Avatar 
Ene Ene is offline
 

X-Cart team
  
Join Date: Aug 2004
Posts: 907
 

Default 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 : )
__________________
Eugene Kaznacheev,
Evangelist/Product Manager at Ecwid: http://www.ecwid.com/ (since Sept 2009)

ex-Head of X-Cart Tech Support Department
ex- X-Cart Hosting Manager - X-Cart hosting
ex-X-Cart Technical Support Engineer


Note: For the official guaranteed tech support services please turn to the Customers HelpDesk.
Reply With Quote
  #7  
Old 06-29-2007, 04:30 AM
 
carpeperdiem carpeperdiem is offline
 

X-Guru
  
Join Date: Jul 2006
Location: New York City, USA
Posts: 5,399
 

Default 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!
__________________
xcart 4.5.4 gold+ w/x-payments 1.0.6; xcart gold 4.4.4
Reply With Quote
  #8  
Old 06-29-2007, 05:11 AM
  Ene's Avatar 
Ene Ene is offline
 

X-Cart team
  
Join Date: Aug 2004
Posts: 907
 

Default 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";
}


: )
__________________
Eugene Kaznacheev,
Evangelist/Product Manager at Ecwid: http://www.ecwid.com/ (since Sept 2009)

ex-Head of X-Cart Tech Support Department
ex- X-Cart Hosting Manager - X-Cart hosting
ex-X-Cart Technical Support Engineer


Note: For the official guaranteed tech support services please turn to the Customers HelpDesk.
Reply With Quote
  #9  
Old 06-29-2007, 12:20 PM
 
carpeperdiem carpeperdiem is offline
 

X-Guru
  
Join Date: Jul 2006
Location: New York City, USA
Posts: 5,399
 

Default 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
__________________
xcart 4.5.4 gold+ w/x-payments 1.0.6; xcart gold 4.4.4
Reply With Quote
  #10  
Old 07-17-2007, 11:09 AM
  Ene's Avatar 
Ene Ene is offline
 

X-Cart team
  
Join Date: Aug 2004
Posts: 907
 

Default 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.
__________________
Eugene Kaznacheev,
Evangelist/Product Manager at Ecwid: http://www.ecwid.com/ (since Sept 2009)

ex-Head of X-Cart Tech Support Department
ex- X-Cart Hosting Manager - X-Cart hosting
ex-X-Cart Technical Support Engineer


Note: For the official guaranteed tech support services please turn to the Customers HelpDesk.
Reply With Quote
Reply
   X-Cart forums > X-Cart 4 > Changing and adding new features


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -8. The time now is 04:21 AM.

   

 
X-Cart forums © 2001-2018