CMSMS Shop Skin Helper for osCommerce and Zen Cart + others

Have a question or a suggestion about a 3rd party addon module or plugin?
Let us know here.
User avatar
Owens
Forum Members
Forum Members
Posts: 97
Joined: Thu Dec 27, 2007 11:29 pm

CMSMS Shop Skin Helper for osCommerce and Zen Cart + others

Post by Owens »

Latest Version: 1.2
Download: http://www.studio-owens.com/code/cmsms-shop-skin-helper.htm

About CMSMS Shop Skin Helper:
I've been contacted via email a great deal lately in regards to how I "integrated" CMS Made Simple with osCommerce / Zen Cart. I didn't integrate them, just skinned them.

I skin all the osCommerce / Zen Cart projects with cached skin files, which are generated from a CMS Made Simple page using some predefined HTML comments placed in the template.

I am releasing the basic code I use to do this under the GNU GPL so others can modify and share as desired. The code to generate the skin files is very simple, and every line is commented to make it easy for someone to adapt to their needs. I use variations of this code to create skin files for a variety of PHP apps, not just osCommerce and Zen Cart. I have even used it in conjunction with existing caching systems.

This tool removes that headache of trying to maintain a similarly themed eCommerce package. When a new page is added, or the design changes in CMS Made Simple, the CMSMS Shop Skin Helper does the work of updating the skin files for osCommerce / Zen Cart. The code creates three files from the CMS Made Simple page and uses those files to sandwich the eCommerce pages. This allows the CMS Made Simple menus to be easily updated on a time schedule and/or with a manual call to the CMSMS Shop Skin Helper code.

Manually skinning an osCommerce or Zen Cart installation with a template similar to the CMS Made Simple template is a pain. As multiple template files have to be updated each time something changed with your site's design or a new page is added to the menu. Yuck.

How To Skin osCommerce / Zen Cart:
I provide an example in the download for skinning an osCommerce and Zen Cart installation.

Support:
This thread will be the support page for the CMSMS Shop Skin Helper. Post your questions here and maybe I, or someone else in the community, can help you out.

File Create Functions:
Some servers have disabled allow_url_include for better security. Two create file functions exist: create_file() requires allow_url_include to be turned on; create_file_curl() uses CURL to create the files.
Last edited by Anonymous on Fri Nov 13, 2009 3:37 pm, edited 1 time in total.
Simon66
Power Poster
Power Poster
Posts: 250
Joined: Wed Aug 29, 2007 4:36 am

Re: CMSMS Shop Skin Helper for osCommerce and Zen Cart

Post by Simon66 »

Very impressive!
I'll test this out on one of my own ideas. If it works out I'll add it to my list of 'offerings'.
I'm getting more and more enquiries about e-commerce.
This looks like a great solution.
Thanks

Simon66
A common mistake that people make when trying to design something completely foolproof is to underestimate the ingenuity of complete fools.

This must be Thursday. I never could get the hang of Thursdays.

Douglas Adams - The only sane person in the asylum.
User avatar
Owens
Forum Members
Forum Members
Posts: 97
Joined: Thu Dec 27, 2007 11:29 pm

Re: CMSMS Shop Skin Helper for osCommerce and Zen Cart + others

Post by Owens »

Let me know how you end up using it, or if the instructions included in the download need changed.
User avatar
Owens
Forum Members
Forum Members
Posts: 97
Joined: Thu Dec 27, 2007 11:29 pm

Update v1.1: CMSMS Shop Skin Helper

Post by Owens »

CMSMS Shop Skin Helper - Update v1.1

Some servers have allow_url_include disabled for better security. Starting with PHP 5.2.X allow_url_include is disabled by default. As an alternative method of creating files I have included a second create file function that uses cURL.

If allow_url_include is disabled PHP will throw an error like:
Warning: require() [function.require]: URL file-access is disabled in the server configuration in /catalog/cmsms_shop_skin_helper.php on line 100
In this case use the function: create_file_curl()

The the original function requires allow_url_include to be enabled: create_file()

The first post of this thread has the download link.
Last edited by Anonymous on Tue Aug 18, 2009 3:04 pm, edited 1 time in total.
Connie

Re: CMSMS Shop Skin Helper for osCommerce and Zen Cart + others

Post by Connie »

I run into a funny result  ???

The website where I am testing the functionality is password-protected (because in state of development, non-public)
Now the 3 generated files contain this content:

Code: Select all

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<__html><head>
<title>401 Authorization Required</title>
</head></__body>
<h1>Authorization Required</h1>
<p>This server could not verify that you
are authorized to access the document
requested.  Either you supplied the wrong
credentials (e.g., bad password), or your
browser doesn't understand how to supply
the credentials required.</p>
<__body></__html>
What to do? I do not want to disable the auth-directive in the .htaccess ;=)
Connie

Re: CMSMS Shop Skin Helper for osCommerce and Zen Cart + others

Post by Connie »

And I have a second question, which I want to post separately:

How does the script react to changes in the menue (in example new pages are added or deleted), I understand that the script must run to write these into the 3 files

so what do you suggest:

1) run the script using a cron-job

2) include the script in the application (in my case it is a database-related script which outputs some text) and invoke it everytime the script is called?

Thanks in advance, Connie
Connie

Re: CMSMS Shop Skin Helper for osCommerce and Zen Cart + others

Post by Connie »

I used it on a "non-secured" local installation and I am totally impressed! It is exactly what I need!

I ran it manually and was missing some info that the script succeeded.

Would it be too much asked to print some success-message on screen?
User avatar
Owens
Forum Members
Forum Members
Posts: 97
Joined: Thu Dec 27, 2007 11:29 pm

Re: CMSMS Shop Skin Helper for osCommerce and Zen Cart + others

Post by Owens »

Hello Connie,

Output Messages
I added the $debug variable back into the code. Download v1.2 of the CMSMS Shop Skin Helper from my website, and set the debug variable to true (this is found in the source code around line 56). This will output a success or fail messages to the screen on each step.
http://www.studio-owens.com/code/cmsms-shop-skin-helper.htm



Automatic Script Running
Connie wrote: How does the script react to changes in the menue (in example new pages are added or deleted), I understand that the script must run to write these into the 3 files
The script doesn't react to changes in the menu, as it is very generic and can be used for any PHP application and not just CMSMS. That being said, you could integrate it into core so each time the menu is updated, the script fires and creates the new skins. However, this change would need to be made each time you updated the code, and it would negate your ability to receive technical support on the core. Therefore, it is easiest to use one of the three following methods to update the menus.


Method One - Setup a Cron Job
Connie wrote: 1) run the script using a cron-job
1) A Cron Job will work fine. Since the Cron Job runs on a set schedule there will be a delay between when the pages are updated and the script fires.

Setting the debug variable to true would be great for running this script as a cron, as it would then send you the success or fail output messages when it runs.


Method Two - Include the File in the Site's Home Page
Connie wrote: 2) include the script in the application (in my case it is a database-related script which outputs some text) and invoke it everytime the script is called?
2) timeToLive
You asked about this on my site, and I personally use this method for some of my clients. The timeToLive variable, and comments on its use, are found directly in the source code.

Open the file: cmsms_shop_skin_helper.php file and look around line 48:

Code: Select all

/* timeToLive can be useed for automated updating of the skin files; not used in the example 
install instructions; if you include this file at the top of your eCommerece home page then 
timeToLive will cause the skin files to be re-generated every # of seconds; set timeToLive to a low 
time if doing many CMSMS template changes; seconds to keep the skin files for; 
600 = 10 minutes; 43200 = 12 hours */
$timeToLive = 10;
Set this variable higher to keep the cached skin files longer. The reason to cache the skins is a reduced load time. I had an old method (the old method can be found on my site's blog) that didn't cache the skins from CMSMS and it took way to much time to process.

After you set the timeToLive variable in the source code, include the skin helper file at the top of your site's home page, or in the PHP Application (for example, I typically choose the main page of osCommerce). Your PHP include would look something like this:

Code: Select all

<?php include('cmsms_shop_skin_helper.php'); ?>
Make sure you set the debug variable to false if you are going to use the timeToLive feature. You wouldn't want messages output to the visitor each time the script fires.


Method Three - Manually Call the File
This by far the easiest method. Simply call the file after you make all your page changes. I sometimes create a shortcut in CMSMS for the client to use. http://wiki.cmsmadesimple.org/index.php/User_Handbook/Admin_Panel/Site_Admin/Manage_Shortcuts


Secured Directory
Hum... haven't run into this problem myself. I will ask some of the other developers that are using this script if they have run into this problem.
Last edited by Anonymous on Fri Nov 13, 2009 3:39 pm, edited 1 time in total.
Connie

Re: CMSMS Shop Skin Helper for osCommerce and Zen Cart + others

Post by Connie »

Owen,

it is great. Thank you for your answers and suggestions.

I think I will include into the application script without debug-messages when the inplementation will be set productive ..

I think as I have to integrate some "old" application because it is a relaunch of a 12 year old very active website, I will have need of more than one $cmsmsURL, so maybe I will rename that script or add the $cmsmsURL as variable, would you mind about that?

Thanks again, this is a great tool!

Connie
User avatar
Owens
Forum Members
Forum Members
Posts: 97
Joined: Thu Dec 27, 2007 11:29 pm

Re: CMSMS Shop Skin Helper for osCommerce and Zen Cart + others

Post by Owens »

Connie wrote: I will have need of more than one $cmsmsURL, so maybe I will rename that script or add the $cmsmsURL as variable, would you mind about that?
You can do what you want with it as long as you keep the copyright and GNU GPL license intact. More details here: http://www.studio-owens.com/code.htm

This code is distributed under the GNU General Public License, which is a Free Software license. It grants to you the four following freedoms: (1) The freedom to run the program for any purpose; (2) The freedom to study how the program works and adapt it to your needs; (3) The freedom to redistribute copies so you can help your neighbor; (4) The freedom to improve the program and release your improvements to the public, so that the whole community benefits.
User avatar
Owens
Forum Members
Forum Members
Posts: 97
Joined: Thu Dec 27, 2007 11:29 pm

Re: CMSMS Shop Skin Helper for ZenCart from Carol

Post by Owens »

Carol wrote:Hi Stephen, I've gone thru the about.pdf and followed the instructions for zencart. My installation for cmsms and zencart are vanilla other than shop being in a different folder. The cmsms_shop_skin_helper.php ran and created 3 files in the shopskin folder. But I have no skin for cmsms or zencart. Any ideas where I should look next? I've double checked every instruction to make sure I didn't miss anything. Thanks. Carol
Not sure exactly what you mean by "I have no skin for cmsms or zencart" so my best guess is that
(a) the CMSMS page (that is set in STEP 3 of the About.pdf) is not using the modified template (created in STEP 2 of the About.pdf);
(b) your active ZenCart template isn't setup properly to use the skin files created by this code (as described in STEP 4 on page 5 of the About.pdf).

Those are my best guesses based upon the info provided.

In order to provide more assistance via this thread, I will need some more information from you:
1. The URL for the page you are using in "STEP 3: Modify the settings in cmsms_shop_skin_helper.php for your site." part 1.
2. The source code for the CMSMS template that you are using.
3. The source code for the ZenCart template you are using.
4. URL to the directory with the 3 skin files that are being created by the Shop Skin Helper.
Last edited by Owens on Fri Feb 21, 2014 12:59 pm, edited 1 time in total.
User avatar
rotezecke
Power Poster
Power Poster
Posts: 411
Joined: Fri Apr 18, 2008 9:34 pm

Re: CMSMS Shop Skin Helper for osCommerce and Zen Cart + oth

Post by rotezecke »

Hi there
I installed the skin maker in combination with os commerce and all is good.
only the navigation that points from cmsms at os commerce pages:

/catalog/somelink.php

are rendered to
/catalog/catalog/somelink.php

an absolute link fixes that problem
http://myURL.com/catalog/somelink.php

however, that makes the site less portable.
does anyone know a way to include {smary} in the url field in content->pages?
or is there another way? a redirect or something?

cheers, mario


cheers
User avatar
Owens
Forum Members
Forum Members
Posts: 97
Joined: Thu Dec 27, 2007 11:29 pm

Re: CMSMS Shop Skin Helper for osCommerce and Zen Cart + oth

Post by Owens »

rotezecke wrote:...

only the navigation that points from cmsms at os commerce pages:

/catalog/somelink.php

are rendered to
/catalog/catalog/somelink.php

...
Mario,
Attached is a relative URL fix. I didn't upload this file as an official release to my website yet, as it is untested. So let me know if this works for you. However it should work fine.

I added a function that performs a RegEx and removes catalog/ from href links.

If you need something different let me know. I code for money.
Attachments
relative_url_fix_untested.zip
Does not contain the entire package. Only contains a modified version of cmsms_shop_skin_helper.php
(2.88 KiB) Downloaded 404 times
User avatar
rotezecke
Power Poster
Power Poster
Posts: 411
Joined: Fri Apr 18, 2008 9:34 pm

Re: CMSMS Shop Skin Helper for osCommerce and Zen Cart + oth

Post by rotezecke »

Thanks. the fix didn't quite work as is.
was:

Code: Select all

function relative_href_fix($string, $debug) {
  $dirRemove = 'catalog';
  $pattern = '/(href)\s*=\s*"('.$catalog.'\/)([^:"]*)(?:")/is';
  $replace = 'href="$3"';
  $string = preg_replace($pattern, $replace, $string);
  if ($debug == true) echo '<p>File Modified with relative href fix: <strong>'.$fileName.'</strong></p>';
  return $string;
}
is now:

Code: Select all

function relative_href_fix($string, $debug) {
  $dirRemove = 'catalog';
  $pattern = '/(href)\s*=\s*"('.$dirRemove.'\/)/';
  $replace = 'href="';
  $string = preg_replace($pattern, $replace, $string);
  if ($debug == true) echo '<p>File Modified with relative href fix: <strong>'.$fileName.'</strong></p>';
  return $string;
}
this part:
([^:"]*)(?:")/is
regular expressions give me a headache; all i know it didnt work. hence the simplified version.

oh, and the line where the function is called needs a semi-colon.

thanks again.
User avatar
Owens
Forum Members
Forum Members
Posts: 97
Joined: Thu Dec 27, 2007 11:29 pm

Re: CMSMS Shop Skin Helper for osCommerce and Zen Cart + oth

Post by Owens »

Glad it was helpful. Yep the pattern had $catalog instead of $dirRemove, and should have been:

Code: Select all

$pattern = '/(href)\s*=\s*"('.$dirRemove.'\/)([^:"]*)(?:")/is';
rotezecke wrote:this part:
([^:"]*)(?:")/is
regular expressions give me a headache
I'll try to break it down... knowledge is power.

The Regex parts found in the above statement
[ ]
matches any single character within the brackets; so [a-z] would match alpha lowercase character

[^ ]
the caret here means to match any single character that is NOT within the brackets; example [^0-9] would match any character that is NOT a number

*
repeats the previous item zero or more times

( )
create a capturing group; backreferences allow you to reuse this part of the regex match

(?: )
create passive group; the question mark and the colon after the opening round bracket mean this group is NOT captured for backreference

So the three things found in the Regex you have questions about are:
([^:"]*)
Here I was looking for anything that could be found within the double quotes of a href. I am matching anything that is NOT : (colon) or " (quotation mark) as a quotation mark would denote the end of the href=" " attribute.

(?:")
This is matching the closing quotation mark, but I didn't need a backreference for my purpose.

/is
The closing forward slash. The /i makes the regex case insensitive. The /s enables single-line mode, to handle the href if it was split across multiple lines for whatever reason.

A sample PHP script to help illustrate the above matches and resulting replacement...

Code: Select all

<?php 
$dirRemove = 'catalog';
$string = '<p>Here comes a catalog/ directory link <a href="catalog/mypage.php">catalog/mypage.php</a> to be fixed.</p>';
$pattern = '/(href)\s*=\s*"('.$dirRemove.'\/)([^:"]*)(?:")/i';
$replace = 'href="$3"';

echo '<p>HTML BEFORE:</p><p style="color:red;">'.htmlspecialchars($string).'</p>';
echo '<hr/>';

echo '<p>REGEX MATCHES:</p>';
preg_match($pattern, $string, $matches);
echo '<p style="color:red;">';
print_r($matches);
echo '</p>';
echo '<hr/>';

$string = preg_replace($pattern, $replace, $string);

echo '<p>HTML AFTER:</p><p style="color:red;">'.htmlspecialchars($string).'</p>';
echo '<hr/>';
?>
Post Reply

Return to “Modules/Add-Ons”