Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Index.php to reference html pages


rekhis

Recommended Posts

Hello,

 

I want my index.php to refer to some static html file so that in the main section, it displays my (say), my.html file. That way, if I need to change my main section, I will just have to change my.html file (which I am comfortable with) without modifying my index.php file. I have not used any php editor.

 

Is it possible?

 

Thanks in advance

rekhis

Link to comment
Share on other sites

I tried and got the following results -

 

define('TEXT_MAIN', '<object data="conditions.html">Server error: could not display conditions.html.</object>');

 

didn't give me anything.

 

define('TEXT_MAIN', '<iframe src="conditions.html" frameborder="0"></iframe>');

 

worked partly. I see my html page but it occupies only left half of the main screen. Because of that, it displays scroll bars, both vertical and horizontal. I tried pulling the box to occupy the whole width and length but its locked.

 

Is there any php directive to tell to use all main window?

 

rekhis

Link to comment
Share on other sites

Try this:

define('TEXT_MAIN', eval("include('test.html');"));

I just tested it on my development box (running PHP 4.3.3) and it seems to work just fine. If anyone has any reason why this is a bad idea please let me know.

 

Regards

Jim

See my profile for a list of my addons and ways to get support.

Link to comment
Share on other sites

Hi Jim,

 

I tried the code but its putting the included file on the top (top of the Shop, Contact, etc. tabs) and not in the main. I will look into php directive to see if some other directive helps.

 

Thanks

Link to comment
Share on other sites

I thought of this possibility after I posted that code. Your HTML file needs to contain only the tags that are allowed in the body of an HTML document. If you are using Dreamweaver (or any other WYSIWYG editor), it will put in the head and other tags to make a full HTML page. This full page then gets included inside the full page that index.php generates. The result is illegal HTML that confuses the browser.

 

You could strip out the extra tags by hand, but that defeats some of the purpose. The best solution would be to automatically strip the tags. I've come up with a bit of code that handles this.

 

However, we have also been trying to make that poor define do something that it was never intended for. A better solution is to put the code where it belongs -- in the main file. So here's how to do that:

 

Go to catalog/index.php and find this code (around line 390):

          <tr>
           <td class="main"><?php echo TEXT_MAIN; ?></td>
         </tr>

 

Now replace it with this code:

          <tr>
           <td class="main">
<?php
   $html_file = DIR_WS_LANGUAGES . $language . '/html/' . basename($PHP_SELF,".php") . '.html'; 
   $html = implode("", file($html_file));
   echo ereg_replace("(<!doctype([^>]+)>)|(<[/]?html>)|(<head>(.*)?</head>)|(<[/]?body([^>]+)?>)", '', $html);
?>
           </td>
         </tr>

 

This will find the file includes/languages/english/html/index.html, read the file in, strip off all the unwanted tags, and include the resulting fragment in index.php. It will work the same for whatever file you put it in, so it can also be used in all the Information Box files that need the same treatment. Just put your HTML files in the html directory (which must be created) in your english directory, and name the file the same as the file that you put the code in (with the .html extension instead of .php). You can include HTML files for the other languages that you use as well.

 

This solves a problem that has been bothering me for a while. I was worried about what would happen when I turned the store that I am developing over to my client. I would just about guarantee that they would try to edit that long text string in the define and bork it up. Now I have a way to give them a file that they can play with in Dreamweaver and not mess up the store. Thanks to everyone who contributed to this idea. Now I need to go change the rest of my files....

 

Regards

Jim

See my profile for a list of my addons and ways to get support.

Link to comment
Share on other sites

Jim,

 

Bull's Eye !! That works the way I was thinking! I was going nuts thinking - Am I the only one who needs this feature! Good to know there are are others as well !

 

Thanks for your hard work and thanks to those who helped you out. I tested the code with a test index.html file and it placed the file rightly in the main section. I did see some horizontal stretching of my page (right menu is half seen and needs to be scrolled) but it may be some tag definition of my index.html file (I use Namo Webeditor). Pls take a look at demo.rekhis.com to see what I mean.

 

I guess you can lock the size of your html file so that it doesn't take all the space, correct?

 

Thanks again

rekhis

Link to comment
Share on other sites

Hi rekhis

 

I just looked at your demo shop. The problem that you are seeing is in the code that your HTML editor is producing. The top of that included file is:

<table cellpadding="0" cellspacing="0" width="750">

which sets the width of the center section to 750 pixels. The fix for this is to change that line to:

<table cellpadding="0" cellspacing="0" width="100%">

which will fill the available space, no matter what the size. Unforunately I don't know how to do that in Namo Webeditor, or any other WYSIWYG editor. I'm an old HTML hacker that never learned how to use these modern tools. There should be some way to tell it to use relative size instead of fixed. If there is a forum for your editor they could probably answer that question.

 

I'm glad to know that this little mod works for you. I've got it going on the front page and all of the Information Box pages on my test site. Now I can let my client edit things without having to constantly go fix code errors.

 

While I was looking at your store, I checked to see where you are located. You might want to add that to your contact page -- it makes customers a lot more comfortable if they know your address. You can see what I did to my client's contact page here.

 

Hmmm, Indian food. Yummy. Please post a link when you get your store up and running.

 

Regards

Jim

See my profile for a list of my addons and ways to get support.

Link to comment
Share on other sites

Go to catalog/index.php and find this code (around line 390):

 ? ? ? ? ?<tr>
? ? ? ? ? ?<td class="main"><?php echo TEXT_MAIN; ?></td>
? ? ? ? ?</tr>

 

Now replace it with this code:

 ? ? ? ? ?<tr>
? ? ? ? ? ?<td class="main">
<?php
? ?$html_file = DIR_WS_LANGUAGES . $language . '/html/' . basename($PHP_SELF,".php") . '.html'; 
? ?$html = implode("", file($html_file));
? ?echo ereg_replace("(<!doctype([^>]+)>)|(<[/]?html>)|(<head>(.*)?</head>)|(<[/]?body([^>]+)?>)", '', $html);
?>
? ? ? ? ? ?</td>
? ? ? ? ?</tr>

Actually, this is at Line 308-309, not 390

 

(Using Crimson Editor)

Link to comment
Share on other sites

Jim, when I added your code to "catalog/index.php", I received this error:

 

Warning: file(includes/languages/english/html/default.html): failed to open stream: No such file or directory in /home/ocbn/public_html/catalog/default.php on line 311

 

Warning: implode(): Bad arguments. in /home/ocbn/public_html/catalog/default.php on line 311

:huh:

 

Here is what I am trying to do:

1) Retitle the main table (on the catalog/default.php page) "New Products For October" to read "4 Easy Ways To Shop",

2) Eliminate the existing content (product images, text and the links) contained within the table

3) Insert my own content (I have created a page called "main.html; See -http://sdscrubs.com/main.html)

 

 

I read the post at "Using file include in define('TEXT_INFORMATION', '')" but it wasn't that helpful.

 

NOTE - Earlier, I was able to add a single line of text by editing lines 274-76 in the english.php file,

but when I tried to insert the below code (copied from main.html - removing <html><head><body> tags), this screwed up all the tables on the default.php page.

 

Here is the code (copied from my "main.html") I want to insert into the main area of the opening Catalog Page:

 

<TABLE cellSpacing=0 cellPadding=0 width="100%" border=0 height="175">
             <TR>
               <TD class=main height="145">
               <blockquote>
                 <p style="line-height: 150%; margin-top: 0; margin-bottom: 0">
                 <font color="#336699" size="2"><b>4 Easy Ways To Shop!</b></font></p>
                 <p style="line-height: 150%; margin-top: 0; margin-bottom: 0">
                 <font color="#336699" size="2"><b>Just Click & Choose your Preferred 
                 Method!</b></font></p>
                 <hr color="#7B9EBD" size="1">
                 <ol>
                   <li>
                   <p style="line-height: 150%; margin-top: 0; margin-bottom: 0">
                   <b>
                   <a href="http://sdscrubs.com/catalog/default.php">
                   <font color="#336699"><u>Browse Our 
                   Online Catalog & Shop Online Securely!</u></font></a></b></li>
                   <li>
                   <p style="line-height: 150%; margin-top: 0; margin-bottom: 0">
                   Or, You can
                   Send in your Order By Fax: <b>(661) 274-9747</b></li>
                   <li>
                   <p style="line-height: 150%; margin-top: 0; margin-bottom: 0">
                   Or, You can
                   Phone In Your Order <b>Toll-Free: (866) 274-9799</b></li>
                   <li>
                   <p style="line-height: 150%; margin-top: 0; margin-bottom: 0">
                   Or,
                   Send Your Order by Snail-Mail (Postal)</li>
                 </ol>
                 <p style="line-height: 150%; margin-top: 0; margin-bottom: 0">
                 NOTE -
                 To make the above 2nd, 3rd and 4th Ordering Options more convenient:</p>
                 <hr color="#7B9EBD" size="1">
                 <ol>
                   <li>
                 <p style="line-height: 150%; margin-top: 0; margin-bottom: 0">
                 Go ahead and Shop using our "<b><a href="http://sdscrubs.com/catalog/default.php"><u><font color="#336699">Online 
                 Catalog</font></u></a></b>", </p>
                   </li>
                   <li>
                 <p style="line-height: 150%; margin-top: 0; margin-bottom: 0">
                 Click to Add items to your Shopping Cart, </p>
                   </li>
                   <li>
                 <p style="line-height: 150%; margin-top: 0; margin-bottom: 0">
                 Then go to "<b><a target="_blank" href="http://sdscrubs.com/catalog/shopping_cart.php"><u><font color="#336699">Cart 
                 Contents</font></u></a></b>" and print out that page (using 
                 your browser's printer button), </p>
                   </li>
                   <li>
                 <p style="line-height: 150%; margin-top: 0; margin-bottom: 0">
                 Finally, continue to "<b><a target="_blank" href="http://sdscrubs.com/catalog/checkout_payment.php"><u><font color="#336699">Checkout</font></u></a></b>", 
                 fill out that form and print it out. </p>
                   </li>
                 </ol>
               </blockquote>
               <p> </TD></TR>
             <TR>
               <TD height="30">    <p align="center"><b><font face="Verdana" size="2">
   CALL (866) 274-9799 or 
               <a href="catalog-request.htm"><font color="#336699">
   <u>CLICK HERE TO ORDER OUR 
   FULL COLOR CATALOG!</u></font></a></font></b></p>
                   </TD></TR></TABLE>

 

________________________________________

I know there is a simple solution. Once I can find it, understand it and implement it, I will be more than happy to write a technical "DIY-HowTo" paper for this topic. If there is already such a document out there, I have failed to find it (has anyone seen my glasses?).

 

Any help in this area would greatly be appreciated........

Link to comment
Share on other sites

Hi Jim,

 

Again, you're right on your money! I had copied the index.html from one of my site's files (which has themes, custom colors, etc.) which caused getting lots of extraneous code in it. I created a new file with same text and its getting displayed just fine!

 

I need to study more to put my contact info under 'Contact Us' tab. Right now, its sitting under 'Help'. Not an obvious place, I know, but I will see if I can put it under 'Contact' tab as well. I saw your site and feel that is the way mine also should be.

 

I will sure post the link once I am up. As of now, I plan to use this site as demo-site only.

 

To [email protected] -

 

I was also getting same (or similar) error before. I had named my file as demo.html whereas (as I understand), system was expecting index.html. Once I renamed my file, things started working just fine. In your case, you need to put default.html file under ...../english/html directory. If your filename is main.html, rename it to default.html and give it a try.

 

Jim, pls correct me if my understanding is wrong. And thanks once more!

 

rekhis

Link to comment
Share on other sites

Actually, this is at Line 308-309, not 390

I don't doubt it. My pages have a lot of modifications, so the line numbers are often quite different. I was too lazy to go look this up in an unmodified copy of osC. Sorry! :rolleyes:

 

rekhis, your understanding is perfectly correct. The file has to be named the same as the file it is being inserted into, just with the .html extension, and it has to be placed in includes/languages/english/html/. That error message is exactly what will happen if the file is not found where the code expects it to be and with exactly the correct name. It's not very forgiving at all.

 

[email protected]: This mod was intended to replace the text in the index page, not the contents of the New Products box. That box is generated by a separate module if I remember correctly. However, this should be possible to do. Let me go take a look at that box a bit. I'll post back here when I find out.

 

And there isn't any reference "how-to" document for this because we're inventing it on the fly. :ph34r: Feel free to document it if you wish....

 

Regards

Jim

See my profile for a list of my addons and ways to get support.

Link to comment
Share on other sites

OK, that was a bit more work than I thought it would be -- I had to go learn something about how those boxes are generated. The solution is really simple, though -- take this code:

<?php
/*
 $Id: new_products.php, html mod 2003/10/04 Jim Keebaugh Exp $

 osCommerce, Open Source E-Commerce Solutions
 http://www.oscommerce.com

 Copyright (c) 2003 osCommerce

 Released under the GNU General Public License
*   
*   NOTE: This is not the original new_products file.
*         This file was modified from the original
*         information.php by hpdl.
*/
?>
<!-- new_products //-->
<?php
 $info_box_contents = array();
 $info_box_contents[] = array('text' => TABLE_HEADING_NEW_PRODUCTS);

 new infoBoxHeading($info_box_contents, false, false);


 $html_file = DIR_WS_LANGUAGES . $language . '/html/' . basename($PHP_SELF,".php") . '_box.html'; 
 $html = implode("", file($html_file));
 $output = ereg_replace("(<!doctype([^>]+)>)|(<[/]?html>)|(<head>(.*)?</head>)|(<[/]?body([^>]+)?>)", '', $html);

 $info_box_contents = array();
 $info_box_contents[] = array('text' => $output);

 new infoBox($info_box_contents);

?>
<!-- new_products_eof //-->

and put it into a brand new file. Name your new file new_products.php. Now backup your existing copy of catalog/includes/modules/new_products.php and replace it with this one.

 

This code will look for a file named index_box.html located in catalog/includes/languages/english/html/. That's probably not the most elegant file name possible, but I'm out of inspiration right now. It's easily changed if you wish. Anyway, the contents of that file will be inserted into the "New Products" box at the bottom of the index page.

 

This will still work if you do the mod I suggested earlier for the text in the top part of the page. That mod looks for a file named index.html and this one looks for index_box.html. Hopefully that will keep them in line.

 

Oh, and the title of the New Products box is in catalog/includes/languages/english/index.php and looks like this:

define('TABLE_HEADING_NEW_PRODUCTS', 'New Products For %s');

Just change that to:

define('TABLE_HEADING_NEW_PRODUCTS', 'How to Order');

or whatever you want it to say.

 

I just tested this on my development system so it should work. Please post back here if you are having problems and I'll try to help.

 

Regards

Jim

See my profile for a list of my addons and ways to get support.

Link to comment
Share on other sites

rekhis: If you want the code for the contact_us box just let me know and I'll post it or PM it to you. It's just the standard box with a few mods. I'm not really fond of the extra email fields, so I'd be happy to remove them for you. :D

 

Regards

Jim

See my profile for a list of my addons and ways to get support.

Link to comment
Share on other sites

Thanks for the prompt reply Jim, and I will try it in a little while (my butt is getting sore).

 

I am sure there are a lot of others that would want to change the content in the "New Products For October" box / table, as I wish to.

 

I figured out the changing the text of "New....." a little while ago. I also figured out adding a <font color> attribute (am I cheating?) to give the text more contrast inside the box heading.

 

Quick Question - Do I use the stylesheet to set the BOX_HEADING's text color attributes? Wouldn't that be easier????

 

I'll give everyone the heads up on the "default.php" main body content change. I see the potential of the page becoming overwhelmed as I add all my products within the next few days.....

Link to comment
Share on other sites

Jim, you're the Man!

 

That was so easy to do......now I can debunk the index pages in my root directory, create a simple FLASH page and redirect them to my catalog.

 

Hats off to ya! And thanks........

Link to comment
Share on other sites

It would definitely be better to change the colors in the stylesheet. Adding a <font color> attribute to a tag that already has a style color defined could cause unpredictable results. Besides, it's a lot easier to change the color in the stylesheet than hunting all over for all of the places you've used that color.

 

Glad you could use this little mod. I suspect that there are other people out there who could benefit from it as well. I'll see if I can put it into a contribution or a Tips & Tricks topic as soon as I have some time.

 

Regards

Jim

See my profile for a list of my addons and ways to get support.

Link to comment
Share on other sites

Hi Jim,

 

Putting in trips & tricks will be really great. I had seen at least one more such request in the recent past and can extrapolate that there would be many such requests in the past as (you initially indicated), it will be easier for the users/clients to modify a single plain html file leaving index.php untouched.

 

I have pm-ed you for the code of contact_us box.

 

Rgds

rekhis

Link to comment
Share on other sites

This topic has now spawned a real contribution. I've added another text box option, complete modified files, and copious installation notes. Support for this new contribution will be in this thread.

 

Thanks again to everyone who posted to this thread for all of the kind words, corrections, and enthusiasm. You are what makes the Open Source community work.

 

Regards

Jim

See my profile for a list of my addons and ways to get support.

Link to comment
Share on other sites

Awesome contribution - And timely too!

 

One problem - The "readme" file is blank!

 

One thing I did find out though (maybe it's just my config), but I had to create 2 pages indentical to each other for the catalog/includes/languages/english/html/ folder.

 

These pages I had to name default.html & index.html respectively.

 

It seems that as you go deeper into the site and are redirected back to the catalog home page, it is looking for one or the other. Chances are that is in the coding somewhere, but I am not sure. So I just login to my site with Frontpage 2002, browse (using folder view) to the /html folder, open both files simultaneously, edit one page, go to html view, copy the code, then paste it into the other page's code, then save both files to the server. Kind of a pain (I would rather just edit one page only).

 

BUT, it is so much better than populating the entire opening page with a bunch of graphics, slowing the page down if you have a dialup connect :angry: (DSL here :D .

 

Thanks a bunch and if you're curious, you can check out the site (although it's still under development) at SD Scrubs Online.....

 

Any suggestions would also be more than welcome!

 

Robert

Link to comment
Share on other sites

Ouch! Something ate the readme file, including the original on my computer. Before I had it backed up. Looks like I'll be rewriting it.

 

On looking at your site, I see that you have both an index.php and a default.php in your /catalog/ folder. That's the reason for having two HTML files, since they have to match. You should get rid of one of these; it's bad practice to have two such pages in the same folder. It could have worse effects than just the duplication in HTML files.

 

Regards

Jim

See my profile for a list of my addons and ways to get support.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...