X-Cart: shopping cart software

X-Cart forums (https://forum.x-cart.com/index.php)
-   Changing design (https://forum.x-cart.com/forumdisplay.php?f=51)
-   -   Force htmlcatalog.php to generate self-made templates (https://forum.x-cart.com/showthread.php?t=2084)

Alan 03-30-2003 07:02 PM

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!

John7 03-31-2003 07:24 AM

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

funkydunk 03-31-2003 09:47 AM

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

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

B00MER 03-31-2003 12:29 PM

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

Alan 04-01-2003 01:09 AM

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


All times are GMT -8. The time now is 07:11 AM.

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