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

Force htmlcatalog.php to generate self-made templates

 
Reply
   X-Cart forums > X-Cart 4 > Dev Questions > Changing design
 
Thread Tools Search this Thread
  #1  
Old 03-30-2003, 07:02 PM
 
Alan Alan is offline
 

Advanced Member
  
Join Date: Feb 2003
Posts: 83
 

Default Force htmlcatalog.php to generate self-made templates

I've created a New Arrivals section for our store, using a modification of home.php, and I've named it newarrivals.php. Problem is in the admin/html_catalog.php, I have no idea what to add to the code, to make it crawl the page.

Apart from adding newarrivals.php to the array, what other sections in the script do I have to duplicate/modify to suit my changes?

*Edit-* Also, has anyone's help section not work, once in the HTML Catalog? Mine gives an invalid link error for some reason.

html_catalog.php:
Code:
# $Id: html_catalog.php,v 1.5.2.4 2003/02/11 07:10:02 svowl Exp $ # This script generates search engine friendly HTML catalog for X-cart set_time_limit(2700); require "../smarty.php"; require "../config.php"; require "./auth.php"; require "../include/security.php"; include "../include/categories.php"; $cat_dir = "../catalog"; $per_page = $config["General"]["products_per_page"]; $max_name_length = 64; $php_scripts = array("search.php","giftcert.php","help.php", "cart.php", "product.php","register.php", "home.php"); # # Generate filename for a category page # function category_filename($cat, $page = 1){ global $cat_names, $max_name_length; $cat_name = substr($cat_names[$cat], 0, $max_name_length); $cat_name =preg_replace("/[ \/]/", "_", $cat_name); $cat_name = preg_replace("/[^A-Za-z0-9_]+/", "", $cat_name); $cat_name = "category_".$cat."_".$cat_name."_page_".$page.".html"; return $cat_name; } # # Generate filename for a product page # function product_filename($productid){ global $max_name_length, $sql_tbl; $tmp = func_query_first("SELECT product FROM $sql_tbl[products] WHERE productid = '$productid'"); $prod_name = substr($tmp[product], 0, $max_name_length); $prod_name = preg_replace("/[ \/]/", "_", $prod_name); $prod_name = preg_replace("/[^A-Za-z0-9_]+/", "", $prod_name); $prod_name = "product_".$productid."_".$prod_name.".html"; return $prod_name; } # # Modify hyperlinksks to point to HTML pages of the catalogue # function process_page($page_src){ global $php_scripts; # Modify links to categories with page number while (preg_match("/<a[ ]+href[ ]*=[ ]*[\"']*home.php\?cat=[ ]*([0-9]+)&page=([0-9]+)[^\"^']*[\"']/", $page_src, $found)) $page_src = preg_replace("/<a[ ]+href[ ]*=[ ]*([\"']*)home.php\?cat=[ ]*".$found[1]."&page=".$found[2]."([^0-9]]*)/", "<a href=\\1".category_filename($found[1], $found[2])."\\2", $page_src); # Modify links to categories while (preg_match("/<a[ ]+href[ ]*=[ ]*[\"']*home.php\?cat=[ ]*([0-9]+)[^\"^']*[\"']/", $page_src, $found)) $page_src = preg_replace("/<a[ ]+href[ ]*=[ ]*([\"']*)home.php\?cat=[ ]*".$found[1]."([^0-9])/", "<a href=\\1".category_filename($found[1])."\\2", $page_src); # Modify links to products while (preg_match("/<a[ ]+href[ ]*=[ ]*[\"']*product.php\?productid=[ ]*([0-9]+)([^\"^']*)[\"']/", $page_src, $found)) $page_src = preg_replace("/<a[ ]+href[ ]*=[ ]*[\"']*product.php\?productid=[ ]*".$found[1]."([^0-9^\"^'^>]*)[\"']*/", "<a href=\"".product_filename($found[1])."\"", $page_src); # Modify links to PHP scripts $page_src = preg_replace("/<a[ ]+href[ ]*=[ ]*[\"']*(".implode("|", $php_scripts).")([^\"^']*)[\"']/", "<a href=\"../customer/\\1\\2\"", $page_src); # Modify action values in HTML forms $page_src = preg_replace("/action[ ]*=[ ]*[\"']*(".implode("|", $php_scripts).")([^\"^']*)[\"']/", "action=\"../customer/".$php_script."\\1\"", $page_src); # Strip all PHP transsids if any $page_src = preg_replace("/<a[ ]+href[ ]*=[ ]*[\"']*([^\"^']*)(\?XCARTSESSID=|&XCARTSESSID=)([^\"^']*)[\"']/", "<a href=\"\\1\"", $page_src); $page_src = preg_replace("/<input[ ]+type=\"hidden\"[ ]+name=\"XCARTSESSID\"[ ]+value=\"[a-zA-z0-9]*\"[ ]*\/>/", "", $page_src); return $page_src; } if($REQUEST_METHOD=="POST" && $mode=="catalog_gen") { include "./safe_mode.php"; echo "Generating catalog "; for($ii=0; $ii<256; $ii++) echo " "; flush(); if ($drop_pages == "on"){ echo "Deleting old catalog... "; flush(); $dir = opendir ($cat_dir); while ($file = readdir ($dir)) { if (($file == ".") or ($file == "..")) continue; if ((filetype ("$cat_dir/$file") != "dir")) { unlink ("$cat_dir/$file"); } } } echo "Preparing data... "; flush(); # Prepare array with the names of categories $tmp_array = func_query("SELECT categoryid, category FROM $sql_tbl[categories]"); foreach($tmp_array as $key=>$value) $cat_names[$value[categoryid]] = $value[category]; #Count number of products in each category foreach ($all_categories as $key=>$value) $all_categories[$key]["product_count"] = array_pop(func_query_first("SELECT COUNT(*) FROM $sql_tbl[products] WHERE (categoryid=$value[categoryid] OR categoryid1=$value[categoryid] OR categoryid2=$value[categoryid] OR categoryid3=$value[categoryid] AND avail>0)")); echo "Converting category pages to HTML "; # Dump X-cart home page to disk list($http_headers, $page_src) = func_http_get_request($xcart_http_host, $xcart_web_dir."/customer/home.php", ""); $page_src = process_page($page_src); $fp = fopen("$cat_dir/index.html", "w+"); if (!$fp) exit(); fwrite($fp, $page_src); # Traverse all categories and dump them on disk foreach ($all_categories as $key=>$value){ $pages = ceil($value[product_count] / $per_page); if ($pages == 0) $pages = 1; for($i = 1; $i <= $pages; $i++){ list($http_headers, $page_src) = func_http_get_request($xcart_http_host, $xcart_web_dir."/customer/home.php", "cat=$value[categoryid]&page=$i"); $page_src = process_page($page_src); $page_name = category_filename($value[categoryid], $i); $fp = fopen("$cat_dir/$page_name", "w+"); if (!$fp) exit(); fwrite($fp, $page_src); echo "."; flush(); } } echo " Converting product pages to HTML "; # Cycle through all products and dump them on disk $product_ids = func_query("select productid from $sql_tbl[products] where $sql_tbl[products].forsale='Y'"); foreach($product_ids as $key=>$value){ list($http_headers, $page_src) = func_http_get_request($xcart_http_host, $xcart_web_dir."/customer/product.php", "productid=$value[productid]"); $page_src = process_page($page_src); $page_name = product_filename($value["productid"]); $fp = fopen("$cat_dir/$page_name", "w+"); if (!$fp) exit(); fwrite($fp, $page_src); echo "."; flush(); } echo " HTML catalog successfuly created."; } else { # # Smarty display code goes here # $smarty->assign("main","html_catalog"); @include "../modules/gold_display.php"; $smarty->display("admin/home.tpl"); } ?>

P.S. What is the difference between dropping and not dropping old HTML Catalog before creating new HTML Catalog?

TIA!
__________________
Best Regards!
Alan
Search is my friend
Reply With Quote
  #2  
Old 03-31-2003, 07:24 AM
 
John7 John7 is offline
 

Senior Member
  
Join Date: Jan 2003
Posts: 136
 

Default Eventually

Eventullay I was planning on asking a very similar question.

I'd also like to have it index the many extra pages I added to the home_main.tpl like aboutus.tpl dealer.tpl media.tpl etc etc

Is there an easy way to do this?

I know if this can be done FunkyDunk will be able to do it.

I've been reading and watching for a while now.
Usually any question I have is already asked in the forum.

Thanks for all your help everyone. This has been a great learning experience so far. Its a lot of fun learning new tricks and better ways to do things in x-cart.

Sincerely, John7
Reply With Quote
  #3  
Old 03-31-2003, 09:47 AM
 
funkydunk funkydunk is offline
 

X-Man
  
Join Date: Oct 2002
Location: Cambridge, UK
Posts: 2,210
 

Default

Thanks for the vote of confidence John... but the pressure....

What happens when you add the new page name to the array?

the diff between the dropping old catalog and not is if you have deleted a product, it will delete that page before building the new mini site.

hth
__________________
ex x-cart guru
Reply With Quote
  #4  
Old 03-31-2003, 12:29 PM
  B00MER's Avatar 
B00MER B00MER is offline
 

X-Guru
  
Join Date: Sep 2002
Location: Keller, TX (Cart-Lab.com)
Posts: 3,165
 

Default

Code:
$php_scripts = array("search.php","giftcert.php","help.php", "cart.php", "product.php","register.php", "home.php");

Adding to this array should make the regular expressions run over the contents of them and output html. You may have to make your own regular expressions if your doing some weird things.
__________________
Cart-Lab - 100+ Social Bookmarks for X-Cart.
Reply With Quote
  #5  
Old 04-01-2003, 01:09 AM
 
Alan Alan is offline
 

Advanced Member
  
Join Date: Feb 2003
Posts: 83
 

Default Damn

So I reckon that all the help.php links being converted to html works for all your pages?

In that case I'll have to contact x-cart to help me sort it out, as I didn't change my help.php and tpl files at all, and the html versions give me 401 errors.

The ones that work for me are:
home.php ------>home.html
product.php---->product.html
categories.php->categories.html

The ones that have html, but gets a 401 is:
help.php -->help.html

The ones that dont are:
search.php
giftcert.php
cart.php
register.php

And yes, the regular expressions part is killing me..it's been a while since I've gotten a good sleep, and the pressure is on from my boss too..T_T
__________________
Best Regards!
Alan
Search is my friend
Reply With Quote
Reply
   X-Cart forums > X-Cart 4 > Dev Questions > Changing design



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 10:17 PM.

   

 
X-Cart forums © 2001-2020