<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>The eCartz Biz &#187; eCartz</title>
	<atom:link href="http://the.ecartz.biz/?feed=rss2&#038;cat=10" rel="self" type="application/rss+xml" />
	<link>http://the.ecartz.biz</link>
	<description>Making osCommerce Work for You</description>
	<lastBuildDate>Wed, 14 Oct 2009 20:02:22 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Overcoming magic_quotes_gpc</title>
		<link>http://the.ecartz.biz/overcoming-magic_quotes_gpc-b-165.html</link>
		<comments>http://the.ecartz.biz/overcoming-magic_quotes_gpc-b-165.html#comments</comments>
		<pubDate>Wed, 14 Oct 2009 20:02:22 +0000</pubDate>
		<dc:creator>eCartz</dc:creator>
				<category><![CDATA[osCommerce Coding]]></category>
		<category><![CDATA[magic_quotes_gpc]]></category>
		<category><![CDATA[osCommerce 3]]></category>

		<guid isPermaLink="false">http://the.ecartz.biz/-b-165.html</guid>
		<description><![CDATA[PHP offers a feature called magic_quotes_gpc.&#160; What this does is it takes all GET, POST, and COOKIE variables and applies a partial escaping to them.&#160; Unfortunately, the escaping that it does is not good enough to pass the result directly to MySQL.&#160; Further, when you run mysql_real_escape_string on the values, it will redo the escaping [...]]]></description>
			<content:encoded><![CDATA[<p>PHP offers a feature called magic_quotes_gpc.&nbsp; What this does is it takes all GET, POST, and COOKIE variables and applies a partial escaping to them.&nbsp; Unfortunately, the escaping that it does is not good enough to pass the result directly to MySQL.&nbsp; Further, when you run mysql_real_escape_string on the values, it will redo the escaping that magic_quotes_gpc did as well as the escaping that magic_quotes_gpc missed.&nbsp; For this reason, it is preferred for magic_quotes_gpc to be off. However, some hosts still use it, as it is on by default.&nbsp;</p>
<p>When magic_quotes_gpc is on with an osCommerce 3 installation, it can cause a weird looking error when editing a product with quotes or backslashes in the name or description.&nbsp; Each time you edit and save, it adds backslashes before all quotes and backslashes.&nbsp; Thus what starts as &#8221; becomes \&#8221; and then \\\&#8221;, \\\\\\\&#8221;, and so forth.&nbsp; This is covered in <a href="http://svn.oscommerce.com/jira/browse/OSC-1010">osCommerce bug report 1010</a>.&nbsp; I verified the issue and created a patch for it:&nbsp; </p><!--DEVFMTCODE--><div class="devcodeblock" title="PHP"><div class="devcodeoverflow"><ol><li>&nbsp;&nbsp;<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #009900;">&#40;</span> <a href="http://www.php.net/function_exists"><span style="color: #990000;">function_exists</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'get_magic_quotes_gpc'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <a href="http://www.php.net/get_magic_quotes_gpc"><span style="color: #990000;">get_magic_quotes_gpc</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #339933;">||</span> <span style="color: #009900;">&#40;</span> <a href="http://www.php.net/ini_get"><span style="color: #990000;">ini_get</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'magic_quotes_sybase'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #009900;">&#40;</span> <a href="http://www.php.net/strtolower"><span style="color: #990000;">strtolower</span></a><span style="color: #009900;">&#40;</span><a href="http://www.php.net/ini_get"><span style="color: #990000;">ini_get</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'magic_quotes_sybase'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">!=</span> <span style="color: #0000ff;">&quot;off&quot;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: #009900;">&#41;</span></li><li>&nbsp;&nbsp;<span style="color: #009900;">&#123;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #000000; font-weight: bold;">function</span> osc_stripslashes_callback<span style="color: #009900;">&#40;</span><span style="color: #339933;">&amp;</span><span style="color: #000088;">$value</span><span style="color: #339933;">,</span> <span style="color: #000088;">$key</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #000088;">$value</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/stripslashes"><span style="color: #990000;">stripslashes</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$value</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #009900;">&#125;</span></li><li>&nbsp;</li><li>&nbsp;&nbsp;&nbsp;&nbsp;<a href="http://www.php.net/array_walk_recursive"><span style="color: #990000;">array_walk_recursive</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_GET</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'osc_stripslashes_callback'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;<a href="http://www.php.net/array_walk_recursive"><span style="color: #990000;">array_walk_recursive</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'osc_stripslashes_callback'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;<a href="http://www.php.net/array_walk_recursive"><span style="color: #990000;">array_walk_recursive</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_COOKIE</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'osc_stripslashes_callback'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></li><li>&nbsp;&nbsp;<span style="color: #009900;">&#125;</span> </li></ol></div></div><!--END_DEVFMTCODE-->
<p>What this code does is it checks if get_magic_quotes_gpc is on and if it is, the code undoes it by running stripslashes on all the values in the GET, POST, and COOKIE superglobal arrays (the GPC in get_magic_quotes_gpc).&nbsp; The code uses array_walk_recursive so that if any of the values are arrays, those get handled as well.&nbsp; The osc_stripslashes_callback function is created because stripslashes does not have the correct method signature to be called from array_walk_recursive.&nbsp;</p>
<p>It&#8217;s possible that the code still does not handle magic_quotes_sybase correctly.&nbsp; It may be that stripslashes does not cover the sybase change.&nbsp; If so, then it should be relatively simple to change the code to properly cover the sybase case.&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Email templates for osCommerce 3</title>
		<link>http://the.ecartz.biz/email-templates-for-oscommerce-3-b-159.html</link>
		<comments>http://the.ecartz.biz/email-templates-for-oscommerce-3-b-159.html#comments</comments>
		<pubDate>Fri, 02 Oct 2009 19:55:52 +0000</pubDate>
		<dc:creator>eCartz</dc:creator>
				<category><![CDATA[osCommerce]]></category>
		<category><![CDATA[email templates]]></category>
		<category><![CDATA[osCommerce 3]]></category>

		<guid isPermaLink="false">http://the.ecartz.biz/-b-159.html</guid>
		<description><![CDATA[I was browsing the osCommerce issue tracker recently and came across a request for an email templating system.&#160; This is an interesting concept.&#160; I looked at it a bit, and noticed that there were two issues.&#160; The first issue is that the email layout is currently hard coded in includes/classes/order.php (as reported in that feature [...]]]></description>
			<content:encoded><![CDATA[<p>I was browsing the osCommerce issue tracker recently and came across a <a href="http://svn.oscommerce.com/jira/browse/OSC-945" target="_blank">request for an email templating system</a>.&nbsp; This is an interesting concept.&nbsp; I looked at it a bit, and noticed that there were two issues.&nbsp; The first issue is that the email layout is currently hard coded in includes/classes/order.php (as reported in that feature request).&nbsp; Thus, to change the layout requires editing a core file, which makes the layout changes fragile in the face of future changes that might be required to that file.&nbsp; It would be easy to either overwrite the layout changes or to miss a required change when updating the file.</p>
<p>A second problem is that the order information generation is hard coded into the layout.&nbsp; In other words, the layout and database access are intertwined.&nbsp; Further, the function unsets all the generated variables as it goes, so it would not be simple to refactor this to separate the data generation from the layout.&nbsp; It&#8217;s not impossible, but it would require a complete rewrite of the data generation &#8212; possibly even an interface to provide functions that can handle the looping efficiently.&nbsp;</p>
<p>Another option would be to generate something like an XML file with the order information.&nbsp; Then that could either be parsed to generate the email or transformed with XSLT into the email.&nbsp;</p>
<p>This issue is rampant throughout the osCommerce 3 codebase.&nbsp; There is still a great deal of content (e.g. HTML or email) embedded in code.&nbsp; The template system is better than what existed in the 2.2 series, but it still leaves a lot to be desired.&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Checkout Redux</title>
		<link>http://the.ecartz.biz/checkout-redux-b-155.html</link>
		<comments>http://the.ecartz.biz/checkout-redux-b-155.html#comments</comments>
		<pubDate>Thu, 17 Sep 2009 09:57:01 +0000</pubDate>
		<dc:creator>eCartz</dc:creator>
				<category><![CDATA[osCommerce Coding]]></category>
		<category><![CDATA[Checkout Redux]]></category>
		<category><![CDATA[osCommerce Addon]]></category>
		<category><![CDATA[osCommerce contribution]]></category>
		<category><![CDATA[payment processing]]></category>
		<category><![CDATA[Purchase before Account]]></category>

		<guid isPermaLink="false">http://the.ecartz.biz/-b-155.html</guid>
		<description><![CDATA[I&#8217;m releasing a new osCommerce add on, Checkout Redux.&#160; Checkout Redux is a play on the phrases &#8220;checkout redone&#8221; and &#8220;checkout reduced&#8221;.&#160; I started with the desire to do something that I meant to do five years ago, which is write a PayPal IPN contribution that worked for me.&#160; The problem that I have with [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m releasing a new osCommerce add on, <a title="Checkout Redux:  a shorter, faster, more robust checkout" href="http://addons.oscommerce.com/info/7019">Checkout Redux</a>.&nbsp; Checkout Redux is a play on the phrases &#8220;checkout redone&#8221; and &#8220;checkout reduced&#8221;.&nbsp; I started with the desire to do something that I meant to do five years ago, which is write a PayPal IPN contribution that worked for me.&nbsp;</p>
<p>The problem that I have with the PayPal Standard that comes with osCommerce is that it duplicates a lot of code that is included elsewhere.&nbsp; This produces difficulty whenever it is used with another contribution that modifies checkout, as the changes need to be put in both places.</p>
<p>Checkout Redux avoids this by refactoring checkout in such a way that it always inserts orders in the database before redirecting to an external processor (orders processed via curl and other backend methods still operate the same way as always).&nbsp; This eliminates the need for the PayPal module to insert the order in the database.&nbsp; In addition, Checkout Redux moves the insert order and order notification (email) code out of checkout process and into their own modules.</p>
<p>The result of this is that we can now call the checkout notification module from either checkout_process.php or a notification handler (e.g. standard_ipn.php).&nbsp; This way, when a contribution needs to change the emailing code, it can always do so in just one place.&nbsp; No need to modify multiple files to implement a single change.&nbsp;</p>
<p>The other major goal of this contribution is to shorten checkout.&nbsp; It does this by reducing the number of pages in the registration process and by skipping pages where no choice is made.&nbsp; Now, if the customer enters checkout without logging in, it immediately offers a chance to enter a shipping (or billing if only downloadable products are in the cart) address.&nbsp; When the customer submits the address, if there are no errors, it creates an account and sends the customer to the checkout_shipping page.&nbsp; This saves two clicks in the process (clicking to the register page and the create_account_success.php page).&nbsp;</p>
<p>More clicks are reduced by skipping pages where no choice is made.&nbsp; If a store only has one shipping method, then checkout_shipping is not needed.&nbsp; Forward to checkout_payment.&nbsp; Similarly, if there is only one option on checkout_payment, then it can be skipped.&nbsp; Onward to checkout_confirmation.&nbsp; As a result, the typical checkout for a new customer is reduced from seven clicks to three (checkout, submit address, and confirm).&nbsp;</p>
<p>The package includes a modified PayPal module (both the payment module and the IPN handler), a Google Analytics integration (to demonstrate the advantages of some of the checkout success changes), alternate files for use with the <a title="DHTML State Selection:  modifying osCommerce to consistently show a drop down for the zone" href="http://the.ecartz.biz/dhtml-state-selection-b-108.html">DHTML State Selection</a> add on, and an example of how to integrate another add on that changes the checkout_process.php file:&nbsp; the <a href="http://www.clubosc.com/update-on-clubosc-discount-coupon-system.html">Club osC Discount Coupon System</a>.&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Validating devformatter content</title>
		<link>http://the.ecartz.biz/validating-devformatter-content-b-145.html</link>
		<comments>http://the.ecartz.biz/validating-devformatter-content-b-145.html#comments</comments>
		<pubDate>Sat, 12 Sep 2009 10:11:42 +0000</pubDate>
		<dc:creator>eCartz</dc:creator>
				<category><![CDATA[eCartz]]></category>
		<category><![CDATA[Developer Formatter]]></category>
		<category><![CDATA[devformatter]]></category>
		<category><![CDATA[W3C HTML Validation]]></category>
		<category><![CDATA[Wordpress Plugin]]></category>
		<category><![CDATA[Zero Clipboard]]></category>

		<guid isPermaLink="false">http://the.ecartz.biz/-b-145.html</guid>
		<description><![CDATA[I use a WordPress plugin called the Developer Formatter to display code blocks. In general, it works well for me, but I recently went to check the W3C HTML Validator and was getting a large number of errors.&#160; Working through them, there were four things that the validator did not like about the plugin output:&#160; [...]]]></description>
			<content:encoded><![CDATA[<p>I use a WordPress plugin called the <a title="Developer Formatter:  a WordPress plugin that includes Geshi syntax highlighting for programming code" href="http://wordpress.org/extend/plugins/devformatter/" target="_blank">Developer Formatter</a> to display code blocks.  In general, it works well for me, but I recently went to check the <a title="The W3C Markup Validation Service" href="http://validator.w3.org/" target="_blank">W3C HTML Validator</a> and was getting a large number of errors.&nbsp; Working through them, there were four things that the validator did not like about the plugin output:&nbsp;</p>
<ol>
<li>The Javascript script tags used language=&#8221;Javascript&#8221; and did not include type=&#8221;text/javascript&#8221;.&nbsp;</li>
<li>The flash (for the clipboard) used embed, which is a Netscape proprietary extension.&nbsp;</li>
<li>WordPress automatically adds paragraph tags and either the code block was in a paragraph with other content or it was in its own paragraph.&nbsp; Unfortunately,<br />
&lt;pre&gt; is not a valid child of &lt;p&gt;, so the validator barfs.&nbsp;</li>
<li>Even if I strip the paragraph tags, the &lt;pre&gt; contains a &lt;table&gt;.&nbsp; Again, table is not a valid child of pre.&nbsp;</li>
</ol>
<p>The first problem was easy enough to fix.&nbsp; I just added the necessary type=&#8221;text/javascript&#8221; until the problem went away.&nbsp; The second was more complicated, but with the help of the <a title="Flash Satay: Embedding Flash While Supporting Standards" href="http://www.alistapart.com/articles/flashsatay" target="_blank">Flash Satay technique</a>, I was able to make a standards compliant version.&nbsp; I did not bother with creating the container flash, as the necessary flash is small enough to load completely.&nbsp; Streaming is not needed.&nbsp; The fourth was an easy fix.&nbsp; I just changed the pre to a div.&nbsp; This works fine in both IE and Firefox, so I&#8217;m happy.&nbsp;As you may have guessed, the third was not as simple a fix.&nbsp; I actually got it working pretty quickly by editing a WordPress function.&nbsp; However,&nbsp; I wanted to get it working by modifying the Developer Formatter plugin, as the solution has code specific to the plugin.&nbsp; That took longer, as the plugin does some wizardry that hides the code block while it is letting the WordPress content filters run.&nbsp; I originally tried to modify the wrong section of code and got no result, so I switched to adding a new filter that would run after the working WordPress filter.&nbsp; That failed.&nbsp; I finally worked out the proper place to change the Developer Formatter plugin and did so.&nbsp;The full set of code changes, starting with devinterface.php:</p>
<!--DEVFMTCODE--><div class="devcodeblock" title="PHP"><div class="devcodeoverflow"><ol><li>&nbsp;&nbsp;<span style="color: #000000; font-weight: bold;">function</span> devfmt_commonHeader<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #000000; font-weight: bold;">GLOBAL</span> <span style="color: #000088;">$DevFmt_Config</span><span style="color: #339933;">;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;script language=<span style="color: #000099; font-weight: bold;">\&quot;</span>JavaScript<span style="color: #000099; font-weight: bold;">\&quot;</span> type=<span style="color: #000099; font-weight: bold;">\&quot;</span>text/javascript<span style="color: #000099; font-weight: bold;">\&quot;</span>&gt;&lt;!--<span style="color: #000099; font-weight: bold;">\n</span> var DevFmtUrl='&quot;</span><span style="color: #339933;">.</span>DEVFMT_URL<span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;'; //--&gt;<span style="color: #000099; font-weight: bold;">\n</span>&lt;/script&gt;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;script type='text/javascript' src='&quot;</span><span style="color: #339933;">.</span>DEVFMT_URL<span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;devfmt_common.js?ver=&quot;</span><span style="color: #339933;">.</span>devfmt_Version<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;'&gt;&lt;/script&gt;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span></li><li>&nbsp;&nbsp;<span style="color: #009900;">&#125;</span></li></ol></div></div><!--END_DEVFMTCODE-->
<p>The type=&#8221;text/javascript&#8221; was added.&nbsp; This code would also validate under XHTML strict if the language=&#8221;JavaScript&#8221; was removed.&nbsp; However, for my purposes, XHTML Transitional is sufficient.&nbsp; Next, in the devfmt_ParseStructure function in devformatter.php:&nbsp;</p>
<!--DEVFMTCODE--><div class="devcodeblock" title="PHP"><div class="devcodeoverflow"><ol><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000ff;">'background-position:50% 50%;width:16px;height:16px;vertical-align:middle;&quot;&gt;'</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&lt;object id=&quot;ZeroClipboard'</span><span style="color: #339933;">.</span><span style="color: #000088;">$DevFmt_CodeIndex</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&quot;</span></li><li><span style="color: #0000ff;">type=&quot;application/x-shockwave-flash&quot; data=&quot;'</span><span style="color: #339933;">.</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;DEVFMT_URL<span style="color: #339933;">.</span><span style="color: #0000ff;">'_zclipboard.swf&quot; width=&quot;16&quot; height=&quot;16&quot; style=&quot;vertical-align:middle&quot;&gt;'</span><span style="color: #339933;">.</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000ff;">'&lt;param name=&quot;movie&quot; value=&quot;'</span><span style="color: #339933;">.</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;DEVFMT_URL<span style="color: #339933;">.</span><span style="color: #0000ff;">'_zclipboard.swf&quot; /&gt;'</span><span style="color: #339933;">.</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000ff;">'&lt;param name=&quot;FlashVars&quot; value=&quot;id='</span><span style="color: #339933;">.</span><span style="color: #000088;">$DevFmt_CodeIndex</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&amp;amp;width=16&amp;amp;height=16&quot; /&gt;'</span><span style="color: #339933;">.</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000ff;">'&lt;param name=&quot;wmode&quot; value=&quot;transparent&quot; /&gt;'</span><span style="color: #339933;">.</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000ff;">'&lt;param name=&quot;loop&quot; value=&quot;false&quot; /&gt;'</span><span style="color: #339933;">.</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000ff;">'&lt;param name=&quot;menu&quot; value=&quot;false&quot; /&gt;'</span><span style="color: #339933;">.</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000ff;">'&lt;param name=&quot;quality&quot; value=&quot;best&quot; /&gt;'</span><span style="color: #339933;">.</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000ff;">'&lt;param name=&quot;allowFullScreen&quot; value=&quot;false&quot; /&gt;'</span><span style="color: #339933;">.</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000ff;">'&lt;param name=&quot;allowScriptAccess&quot; value=&quot;always&quot; /&gt;'</span><span style="color: #339933;">.</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000ff;">'&lt;/object&gt;'</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&lt;/td&gt;'</span><span style="color: #339933;">.</span></li></ol></div></div><!--END_DEVFMTCODE-->
<p>replaced</p>
<!--DEVFMTCODE--><div class="devcodeblock" title="PHP"><div class="devcodeoverflow"><ol><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000ff;">'background-position:50% 50%;width:16px;height:16px;&quot;/&gt;&lt;embed id=&quot;ZeroClipboard'</span><span style="color: #339933;">.</span><span style="color: #000088;">$DevFmt_CodeIndex</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&quot; src=&quot;'</span><span style="color: #339933;">.</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;DEVFMT_URL<span style="color: #339933;">.</span><span style="color: #0000ff;">'_zclipboard.swf&quot; loop=&quot;false&quot; menu=&quot;false&quot; quality=&quot;best&quot; bgcolor=&quot;#ffffff&quot; width=&quot;16px&quot; height=&quot;16px&quot;'</span><span style="color: #339933;">.</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000ff;">' align=&quot;middle&quot; allowScriptAccess=&quot;always&quot; allowFullScreen=&quot;false&quot; type=&quot;application/x-shockwave-flash&quot;'</span><span style="color: #339933;">.</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000ff;">' pluginspage=&quot;http://www.macromedia.com/go/getflashplayer&quot; flashvars=&quot;id='</span><span style="color: #339933;">.</span><span style="color: #000088;">$DevFmt_CodeIndex</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&amp;amp;width=16&amp;amp;height=16&quot;'</span><span style="color: #339933;">.</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000ff;">' wmode=&quot;transparent&quot; /&gt;&lt;/td&gt;'</span><span style="color: #339933;">.</span></li></ol></div></div><!--END_DEVFMTCODE-->
<p>and to finish that function, change pre to div:&nbsp;</p>
<!--DEVFMTCODE--><div class="devcodeblock" title="PHP"><div class="devcodeoverflow"><ol><li>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #b1b100;">return</span> <span style="color: #000088;">$regionflag</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&lt;div class=&quot;devcodeblock&quot; title=&quot;'</span><span style="color: #339933;">.</span>devfmt_getLangTitle<span style="color: #009900;">&#40;</span><span style="color: #000088;">$ALang</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&quot;&gt;'</span><span style="color: #339933;">.</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #000088;">$Toolbar</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&lt;div class=&quot;devcodeoverflow&quot;'</span><span style="color: #339933;">.</span><span style="color: #000088;">$AStyle</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&gt;'</span><span style="color: #339933;">.</span><span style="color: #000088;">$ACode</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&lt;/div&gt;&lt;/div&gt;'</span><span style="color: #339933;">.</span><span style="color: #000088;">$regionflag</span><span style="color: #009900;">&#91;</span>1<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span></li></ol></div></div><!--END_DEVFMTCODE-->
<p>Later in the same file, in the devfmt_ContentFormat function, added</p>
<!--DEVFMTCODE--><div class="devcodeblock" title="PHP"><div class="devcodeoverflow"><ol><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #000088;">$AContent</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/str_replace"><span style="color: #990000;">str_replace</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'&lt;!--DEVFMTCODE--&gt;'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'&lt;/p&gt;&lt;!--DEVFMTCODE--&gt;'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$AContent</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #000088;">$AContent</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/str_replace"><span style="color: #990000;">str_replace</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'&lt;!--END_DEVFMTCODE--&gt;'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'&lt;!--END_DEVFMTCODE--&gt;&lt;p&gt;'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$AContent</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #000088;">$AContent</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/str_replace"><span style="color: #990000;">str_replace</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'&lt;p&gt;&lt;/p&gt;&lt;!--DEVFMTCODE--&gt;'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'&lt;!--DEVFMTCODE--&gt;'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$AContent</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #000088;">$AContent</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/str_replace"><span style="color: #990000;">str_replace</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'&lt;!--END_DEVFMTCODE--&gt;&lt;p&gt;&lt;/p&gt;'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'&lt;!--END_DEVFMTCODE--&gt;'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$AContent</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></li></ol></div></div><!--END_DEVFMTCODE-->
<p>These became the last three lines before the else and then the return.&nbsp; I.e. the effect was to make these the last statements that ran before the string was returned.&nbsp; Finally, to make the javascript work with the object replacing the embed for the flash, in devfmt_common.js, I changed</p>
<!--DEVFMTCODE--><div class="devcodeblock" title="PHP"><div class="devcodeoverflow"><ol><li>ZeroClipboard <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span></li><li> dispatch<span style="color: #339933;">:</span> <span style="color: #000000; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>id<span style="color: #339933;">,</span> eventName<span style="color: #339933;">,</span> args<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;EmbedObj <span style="color: #339933;">=</span> jQuery<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;embed#ZeroClipboard&quot;</span> <span style="color: #339933;">+</span> id<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#91;</span>0<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #b1b100;">switch</span><span style="color: #009900;">&#40;</span>eventName<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span></li></ol></div></div><!--END_DEVFMTCODE-->
<p>to </p><!--DEVFMTCODE--><div class="devcodeblock" title="PHP"><div class="devcodeoverflow"><ol><li>ZeroClipboard <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span></li><li> dispatch<span style="color: #339933;">:</span> <span style="color: #000000; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>id<span style="color: #339933;">,</span> eventName<span style="color: #339933;">,</span> args<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;EmbedObj <span style="color: #339933;">=</span> jQuery<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;object#ZeroClipboard&quot;</span> <span style="color: #339933;">+</span> id<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#91;</span>0<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #b1b100;">switch</span><span style="color: #009900;">&#40;</span>eventName<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span></li></ol></div></div><!--END_DEVFMTCODE-->
<p>Now, with these changes, <a title="[Valid] Markup Validation of http://the.ecartz.biz/preserve-image-ratio-in-oscommerce-b-127.html - W3C Markup Validator" href="http://validator.w3.org/check?uri=http%3A%2F%2Fthe.ecartz.biz%2Fpreserve-image-ratio-in-oscommerce-b-127.html;ss=1;outline=1" target="_blank">my site validates in XHTML Transitional</a>.&nbsp; It almost validates in XHTML Strict, but the aforementioned language=&#8221;JavaScript&#8221; and the use of target=&#8221;_blank&#8221; keep it from passing.&nbsp; I&#8217;m not willing to give up the open in a new window functionality, so I&#8217;ll stick with Transitional.&nbsp;</p>
<p>I&#8217;m going to see if I can talk the author into including these or equivalent changes into the next version of the Developer Formatter.&nbsp; It looks like the clipboard actually is a third party library called <a title="Zero Clipboard:  a Flash and Javascript library for making copy to clipboard buttons" href="http://code.google.com/p/zeroclipboard/" target="_blank">Zero Clipboard</a> by Joseph Huckaby.&nbsp; I&#8217;ll try to touch base with him as well.&nbsp;</p>
<p>Update:  <a title="[Plugin: Developer Formatter] W3C Validating pages with devformatter content" href="http://wordpress.org/support/topic/310289" target="_blank">report posted on WordPress forums</a>.</p>
<p>Update:&nbsp; <a title="Zero Clipboard Issue 22:  Test page not W3C valid" href="http://code.google.com/p/zeroclipboard/issues/detail?id=22" target="_blank">issue reported at the Zero Clipboard project page</a>.</p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Preserve Image Ratio in osCommerce</title>
		<link>http://the.ecartz.biz/preserve-image-ratio-in-oscommerce-b-127.html</link>
		<comments>http://the.ecartz.biz/preserve-image-ratio-in-oscommerce-b-127.html#comments</comments>
		<pubDate>Thu, 10 Sep 2009 04:31:52 +0000</pubDate>
		<dc:creator>eCartz</dc:creator>
				<category><![CDATA[osCommerce Coding]]></category>
		<category><![CDATA[image scaling]]></category>
		<category><![CDATA[osCommerce]]></category>

		<guid isPermaLink="false">http://the.ecartz.biz/-b-127.html</guid>
		<description><![CDATA[By default, if you configure osCommerce to use a particular image size in admin &#62;&#62; Configuration &#62;&#62; Images, it will rescale the image to fit that size.&#160; If the image had a different aspect ratio, it will then appear smushed or distorted.&#160; It&#8217;s possible to set up osCommerce such that this does not happen.&#160; You [...]]]></description>
			<content:encoded><![CDATA[<p>By default, if you configure osCommerce to use a particular image size in admin &gt;&gt; Configuration &gt;&gt; Images, it will rescale the image to fit that size.&nbsp; If the image had a different aspect ratio, it will then appear smushed or distorted.&nbsp; It&#8217;s possible to set up osCommerce such that this does not happen.&nbsp; You can do so by setting admin &gt;&gt; Configuration &gt;&gt; Images &gt;&gt; Calculate Image Size to true and then change the tep_image function in includes/functions/html_output.php<span id="more-127"></span> as so </p>
<!--DEVFMTCODE--><div class="devcodeblock" title="PHP"><div class="devcodeoverflow"><ol><li>&nbsp;&nbsp;<span style="color: #000000; font-weight: bold;">function</span> tep_image<span style="color: #009900;">&#40;</span><span style="color: #000088;">$src</span><span style="color: #339933;">,</span> <span style="color: #000088;">$alt</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">,</span> <span style="color: #000088;">$width</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">,</span> <span style="color: #000088;">$height</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">,</span> <span style="color: #000088;">$parameters</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">,</span> <span style="color: #000088;">$calculate_image_size</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #009900;">&#40;</span> <a href="http://www.php.net/empty"><span style="color: #990000;">empty</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$src</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span> <span style="color: #009900;">&#40;</span> <span style="color: #000088;">$src</span> <span style="color: #339933;">==</span> DIR_WS_IMAGES <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #009900;">&#40;</span> IMAGE_REQUIRED <span style="color: #339933;">==</span> <span style="color: #0000ff;">'false'</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #009900;">&#125;</span></li><li>&nbsp;</li><li><span style="color: #666666; font-style: italic;">// alt is added to the img tag even if it is null to prevent browsers from outputting</span></li><li><span style="color: #666666; font-style: italic;">// the image filename as default</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #000088;">$image</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'&lt;img src=&quot;'</span> <span style="color: #339933;">.</span> tep_output_string<span style="color: #009900;">&#40;</span><span style="color: #000088;">$src</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&quot; border=&quot;0&quot; alt=&quot;'</span> <span style="color: #339933;">.</span> tep_output_string<span style="color: #009900;">&#40;</span><span style="color: #000088;">$alt</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&quot;'</span><span style="color: #339933;">;</span></li><li>&nbsp;</li><li>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> tep_not_null<span style="color: #009900;">&#40;</span><span style="color: #000088;">$alt</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #000088;">$image</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">' title=&quot; '</span> <span style="color: #339933;">.</span> tep_output_string<span style="color: #009900;">&#40;</span><span style="color: #000088;">$alt</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">' &quot;'</span><span style="color: #339933;">;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #009900;">&#125;</span></li><li>&nbsp;</li><li>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #009900;">&#40;</span> CONFIG_CALCULATE_IMAGE_SIZE <span style="color: #339933;">==</span> <span style="color: #0000ff;">'true'</span> <span style="color: #009900;">&#41;</span>&nbsp;&nbsp;<span style="color: #339933;">&amp;&amp;</span> <span style="color: #009900;">&#40;</span> <span style="color: #000088;">$calculate_image_size</span> <span style="color: #339933;">==</span> <span style="color: #009900; font-weight: bold;">true</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$image_size</span> <span style="color: #339933;">=</span> <span style="color: #339933;">@</span><a href="http://www.php.net/getimagesize"><span style="color: #990000;">getimagesize</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$src</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><a href="http://www.php.net/empty"><span style="color: #990000;">empty</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$width</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> tep_not_null<span style="color: #009900;">&#40;</span><span style="color: #000088;">$height</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #000088;">$ratio</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$height</span> <span style="color: #339933;">/</span> <span style="color: #000088;">$image_size</span><span style="color: #009900;">&#91;</span>1<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #000088;">$width</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/intval"><span style="color: #990000;">intval</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$image_size</span><span style="color: #009900;">&#91;</span>0<span style="color: #009900;">&#93;</span> <span style="color: #339933;">*</span> <span style="color: #000088;">$ratio</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">elseif</span> <span style="color: #009900;">&#40;</span>tep_not_null<span style="color: #009900;">&#40;</span><span style="color: #000088;">$width</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <a href="http://www.php.net/empty"><span style="color: #990000;">empty</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$height</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #000088;">$ratio</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$width</span> <span style="color: #339933;">/</span> <span style="color: #000088;">$image_size</span><span style="color: #009900;">&#91;</span>0<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #000088;">$height</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/intval"><span style="color: #990000;">intval</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$image_size</span><span style="color: #009900;">&#91;</span>1<span style="color: #009900;">&#93;</span> <span style="color: #339933;">*</span> <span style="color: #000088;">$ratio</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">elseif</span> <span style="color: #009900;">&#40;</span><a href="http://www.php.net/empty"><span style="color: #990000;">empty</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$width</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <a href="http://www.php.net/empty"><span style="color: #990000;">empty</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$height</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #000088;">$width</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$image_size</span><span style="color: #009900;">&#91;</span>0<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #000088;">$height</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$image_size</span><span style="color: #009900;">&#91;</span>1<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">elseif</span> <span style="color: #009900;">&#40;</span> <span style="color: #000088;">$width</span> <span style="color: #339933;">*</span> <span style="color: #000088;">$image_size</span><span style="color: #009900;">&#91;</span>1<span style="color: #009900;">&#93;</span> <span style="color: #339933;">&lt;</span> <span style="color: #000088;">$height</span> <span style="color: #339933;">*</span> <span style="color: #000088;">$image_size</span><span style="color: #009900;">&#91;</span>0<span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #000088;">$height</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/intval"><span style="color: #990000;">intval</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$width</span> <span style="color: #339933;">*</span> <span style="color: #000088;">$image_size</span><span style="color: #009900;">&#91;</span>1<span style="color: #009900;">&#93;</span> <span style="color: #339933;">/</span> <span style="color: #000088;">$image_size</span><span style="color: #009900;">&#91;</span>0<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">elseif</span> <span style="color: #009900;">&#40;</span> <span style="color: #000088;">$width</span> <span style="color: #339933;">*</span> <span style="color: #000088;">$image_size</span><span style="color: #009900;">&#91;</span>1<span style="color: #009900;">&#93;</span> <span style="color: #339933;">&gt;</span> <span style="color: #000088;">$height</span> <span style="color: #339933;">*</span> <span style="color: #000088;">$image_size</span><span style="color: #009900;">&#91;</span>0<span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #000088;">$width</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/intval"><span style="color: #990000;">intval</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$height</span> <span style="color: #339933;">*</span> <span style="color: #000088;">$image_size</span><span style="color: #009900;">&#91;</span>0<span style="color: #009900;">&#93;</span> <span style="color: #339933;">/</span> <span style="color: #000088;">$image_size</span><span style="color: #009900;">&#91;</span>1<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #009900;">&#125;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">elseif</span> <span style="color: #009900;">&#40;</span>IMAGE_REQUIRED <span style="color: #339933;">==</span> <span style="color: #0000ff;">'false'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #009900;">&#125;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #009900;">&#125;</span></li></ol></div></div><!--END_DEVFMTCODE-->
<p>Two lines changed (75 and 88) and four lines added (99-102).&nbsp;</p>
<p>What this does is it makes the image fit within the selected size, preserving the image ratio.&nbsp; This takes the traditional advice (set Calculate Image Size to true and leave the width blank) and expands it for stores that have both narrow and wide images.&nbsp; The traditional advice could actually cause images that were tall and narrow to expand further in height, breaking out of the box for them.&nbsp; With this code, the image is always smaller than the box size (or the exact box size).&nbsp;</p>
<p>And make one change in tep_draw_separator, to keep this change from breaking tep_draw_separator: &nbsp;  </p>
<!--DEVFMTCODE--><div class="devcodeblock" title="PHP"><div class="devcodeoverflow"><ol><li>&nbsp;&nbsp;<span style="color: #000000; font-weight: bold;">function</span> tep_draw_separator<span style="color: #009900;">&#40;</span><span style="color: #000088;">$image</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'pixel_black.gif'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$width</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'100%'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$height</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'1'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #b1b100;">return</span> tep_image<span style="color: #009900;">&#40;</span>DIR_WS_IMAGES <span style="color: #339933;">.</span> <span style="color: #000088;">$image</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">' '</span><span style="color: #339933;">,</span> <span style="color: #000088;">$width</span><span style="color: #339933;">,</span> <span style="color: #000088;">$height</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></li><li>&nbsp;&nbsp;<span style="color: #009900;">&#125;</span></li></ol></div></div><!--END_DEVFMTCODE-->
<p>What this does is it keeps osCommerce from preserving the image ratio on the separators.  In that case, we want the single pixel image to appear in different ratios than the original.  </p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP/HTML Input Name Limit</title>
		<link>http://the.ecartz.biz/phphtml-input-name-limit-b-123.html</link>
		<comments>http://the.ecartz.biz/phphtml-input-name-limit-b-123.html#comments</comments>
		<pubDate>Sat, 05 Sep 2009 19:25:23 +0000</pubDate>
		<dc:creator>eCartz</dc:creator>
				<category><![CDATA[osCommerce Coding]]></category>
		<category><![CDATA[HTML input array]]></category>
		<category><![CDATA[osCommerce troubleshooting]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://the.ecartz.biz/-b-123.html</guid>
		<description><![CDATA[Worked through a weird bug the other day.&#160; A gaming computer store has products with lots of attributes &#8212; as many as fifty.&#160; Since osCommerce stores the attributes with the product ID, the result is to make the id array that holds the attributes on the shopping cart page have exceptionally large input names.&#160; If [...]]]></description>
			<content:encoded><![CDATA[<p>Worked through a weird bug the other day.&nbsp; A gaming computer store has products with lots of attributes &#8212; as many as fifty.&nbsp; Since osCommerce stores the attributes with the product ID, the result is to make the id array that holds the attributes on the shopping cart page have exceptionally large input names.&nbsp; If the name gets too large (I didn&#8217;t test it exactly, but more than two hundred characters was all right and three hundred some broke it), it gets silently dropped.&nbsp;<span id="more-123"></span></p>
<p>The behavior that this caused in osCommerce was to make the attributes disappear any time that the cart was updated (item removed or a quantity changed).&nbsp; The problem being that it was using the posted variables to determine the attributes.&nbsp; I&#8217;m not sure why it does this.&nbsp; It should have all the required information in the $cart variable stored in the session.&nbsp; Perhaps it is trying to mirror the product_info page behavior.&nbsp;</p>
<p>A surprisingly small change fixed this.&nbsp; I simply replaced the products ID string with the numerical placement in the list.&nbsp; I.e., for the first item, it&#8217;s ID became 0.&nbsp; The second item was 1 and so on.&nbsp; I changed it once in the shopping cart page and once in includes/application_top.php.&nbsp; This decreases the robustness somewhat (we are now relying on order being preserved through the POST), but it worked in my testing.&nbsp;</p>
<p>The includes/application_top.php change (only 354 changed; the others are just for context and to make the code highlighter offer a scroll bar):&nbsp; </p><!--DEVFMTCODE--><div class="devcodeblock" title="PHP"><div class="devcodeoverflow"><ol><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #000088;">$attributes</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$HTTP_POST_VARS</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'id'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> ? <span style="color: #000088;">$HTTP_POST_VARS</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'id'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">:</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #009900;">&#125;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #000088;">$cart</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">add_cart</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$HTTP_POST_VARS</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'products_id'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$HTTP_POST_VARS</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'cart_quantity'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$attributes</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></li></ol></div></div><!--END_DEVFMTCODE-->
<p>&nbsp;</p>
<p>The shopping_cart.php change (only 86 changed):&nbsp; </p><!--DEVFMTCODE--><div class="devcodeblock" title="PHP"><div class="devcodeoverflow"><ol><li>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #000088;">$products</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$cart</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">get_products</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span><span style="color: #339933;">=</span>0<span style="color: #339933;">,</span> <span style="color: #000088;">$n</span><span style="color: #339933;">=</span><a href="http://www.php.net/sizeof"><span style="color: #990000;">sizeof</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$products</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i</span><span style="color: #339933;">&lt;</span><span style="color: #000088;">$n</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i</span><span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span></li><li><span style="color: #666666; font-style: italic;">// Push all attributes information in an array</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><a href="http://www.php.net/isset"><span style="color: #990000;">isset</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$products</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'attributes'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <a href="http://www.php.net/is_array"><span style="color: #990000;">is_array</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$products</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'attributes'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span><a href="http://www.php.net/list"><span style="color: #990000;">list</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$option</span><span style="color: #339933;">,</span> <span style="color: #000088;">$value</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/each"><span style="color: #990000;">each</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$products</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'attributes'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #b1b100;">echo</span> tep_draw_hidden_field<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'id['</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$i</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">']['</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$option</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">']'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$value</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></li></ol></div></div><!--END_DEVFMTCODE-->
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Product Listing on Front Page</title>
		<link>http://the.ecartz.biz/product-listing-on-front-page-b-120.html</link>
		<comments>http://the.ecartz.biz/product-listing-on-front-page-b-120.html#comments</comments>
		<pubDate>Wed, 02 Sep 2009 18:41:15 +0000</pubDate>
		<dc:creator>eCartz</dc:creator>
				<category><![CDATA[osCommerce Coding]]></category>
		<category><![CDATA[front page]]></category>
		<category><![CDATA[osCommerce]]></category>
		<category><![CDATA[osCommerce contribution]]></category>
		<category><![CDATA[product listing]]></category>

		<guid isPermaLink="false">http://the.ecartz.biz/-b-120.html</guid>
		<description><![CDATA[I released a new osCommerce contribution yesterday:&#160; Product Listing on Front Page It&#8217;s just a small mod.&#160; I wouldn&#8217;t have released it (the forum thread seemed enough), but it was requested.&#160; This add-on adds a product listing to your front page.&#160; It is suitable for small stores, where the complete product list can fit on [...]]]></description>
			<content:encoded><![CDATA[<p>I released a new osCommerce contribution yesterday:&nbsp;  <a title="osCommerce contribution:  show a listing of all products on the front page" href="http://addons.oscommerce.com/info/6996">Product Listing on Front Page</a><br />
<span id="more-120"></span><br />
It&#8217;s just a small mod.&nbsp; I wouldn&#8217;t have released it (the forum thread seemed enough), but it was requested.&nbsp; This add-on adds a product listing to your front page.&nbsp; It is suitable for small stores, where the complete product list can fit on the front page. It shows all the products from all categories and manufacturers. It&#8217;s a small mod, only one edit to make in each of two files (one of which is a language file, so you may need to make the same change multiple times for a multi-lingual shop).&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Check Referrer Sessions Option</title>
		<link>http://the.ecartz.biz/check-referrer-sessions-option-b-113.html</link>
		<comments>http://the.ecartz.biz/check-referrer-sessions-option-b-113.html#comments</comments>
		<pubDate>Tue, 01 Sep 2009 00:16:36 +0000</pubDate>
		<dc:creator>eCartz</dc:creator>
				<category><![CDATA[osCommerce Coding]]></category>
		<category><![CDATA[osCommerce Community]]></category>
		<category><![CDATA[osCommerce]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[preventing shared sessions]]></category>
		<category><![CDATA[session handling]]></category>

		<guid isPermaLink="false">http://the.ecartz.biz/-b-113.html</guid>
		<description><![CDATA[A situation that was mentioned on the osCommerce forums recently started me thinking.&#160; Currently, if someone has cookies disabled, then the osCsid (the osCommerce session ID) appears in the URL.&#160; If such a person logs in and then emails a link to someone else, the osCsid will be included in that URL (unless they remove [...]]]></description>
			<content:encoded><![CDATA[<p>A situation that was mentioned on the osCommerce forums recently started me thinking.&nbsp; Currently, if someone has cookies disabled, then the osCsid (the osCommerce session ID) appears in the URL.&nbsp; If such a person logs in and then emails a link to someone else, the osCsid will be included in that URL (unless they remove it manually).&nbsp; If the recipient clicks on the link, they will get the sender&#8217;s session and be able to do things like view past orders, add new addresses, or checkout on their account.&nbsp;</p>
<p>One suggestion to resolve this was to set Recreate Sessions to true.&nbsp; While that is a good setting, it only helps if the user was not logged in at the time the link was sent or if the link is used after the login session has expired.&nbsp; Another suggestion is to check IP address, but that breaks people on proxies.&nbsp; Another suggestion is to check the user agent setting, but that won&#8217;t prevent the situation where both people use browsers that happen to pass the same user agent string.&nbsp;</p>
<p>I went back to the initial problem.&nbsp; If someone is logged in and browsing with a session ID in the URL, they will always have a referrer on the osCommerce site.&nbsp; If they leave the osCommerce site, then they will lose the session (which is one reason why cookies are preferable).&nbsp; Therefore, if their browser sends a referrer, the referrer will be on the osCommerce site.&nbsp; By contrast, the recipient of our hypothetical email will always have a blank referrer.&nbsp;</p>
<p>Can we simply check for blank referrers?&nbsp; Not really, it is possible to configure browsers not to send a referrer.&nbsp; If we block sessions for people without referrers, we will prevent login by anyone who has a blank referrer.&nbsp; Also, although we have been talking about email, there are other ways to share links, e.g. posting on a website or tweeting.&nbsp; In those cases, the link will have a referrer, it just won&#8217;t be osCommerce.&nbsp; So we need to check to see if the referrer is osCommerce and we need to allow for legitimate blank referrers.&nbsp;</p>
<p>My proposal is that if someone comes to the site with the referrer set, osCommerce will check to see if they have a session open.&nbsp; If so, osCommerce will see if they have a referrer set for the session.&nbsp; If not, then osCommerce will set the referrer.&nbsp; Now, if someone sends a request to osCommerce with a blank referrer, we can check to see if there is a referrer set in the session.&nbsp; If there is, then we can surmise that this is a new person, so we regenerate and clear the session.&nbsp; Further, if someone comes to osCommerce with a set referrer, the referrer is not osCommerce, and they have a session ID in the URL, we can regenerate and clear the session as well.&nbsp;</p>
<p>This covers:&nbsp;</p>
<ol>
<li>The case where a link is emailed with the session ID.</li>
<li>The case where a link is posted externally with the session ID.</li>
<li>The case where someone sends a blank referrer on every request.</li>
<li>The case where someone is browsing through the site normally and sending&nbsp; a referrer.</li>
</ol>
<p>We are left with an odd edge case, where someone who browses without a referrer emails a link to someone else with the session ID in it.&nbsp; In that case, the code would still fail, and they will share a session.&nbsp; You can slightly reduce this risk by checking the user agent.&nbsp;</p>
<p>Code:&nbsp; </p><!--DEVFMTCODE--><div class="devcodeblock" title="PHP"><div class="devcodeoverflow"><ol><li><span style="color: #666666; font-style: italic;">// only trust a session ID from the URL if refered </span></li><li><span style="color: #666666; font-style: italic;">// from this site</span></li><li>&nbsp;&nbsp;<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <a href="http://www.php.net/isset"><span style="color: #990000;">isset</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$HTTP_SERVER_VARS</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'HTTP_REFERER'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span> tep_session_is_registered<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'first_referred_by'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #000088;">$referrer</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/parse_url"><span style="color: #990000;">parse_url</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$HTTP_SERVER_VARS</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'HTTP_REFERER'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #009900;">&#40;</span> HTTP_COOKIE_DOMAIN <span style="color: #339933;">!=</span> <a href="http://www.php.net/substr"><span style="color: #990000;">substr</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'.'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$referrer</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'host'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #339933;">-</span>1 <span style="color: #339933;">*</span> <a href="http://www.php.net/strlen"><span style="color: #990000;">strlen</span></a><span style="color: #009900;">&#40;</span>HTTP_COOKIE_DOMAIN<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #339933;">&amp;&amp;</span> <span style="color: #009900;">&#40;</span> HTTPS_COOKIE_DOMAIN <span style="color: #339933;">!=</span>&nbsp;&nbsp;<a href="http://www.php.net/substr"><span style="color: #990000;">substr</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'.'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$referrer</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'host'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #339933;">-</span>1 <span style="color: #339933;">*</span> <a href="http://www.php.net/strlen"><span style="color: #990000;">strlen</span></a><span style="color: #009900;">&#40;</span>HTTPS_COOKIE_DOMAIN<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #339933;">&amp;&amp;</span> <span style="color: #009900;">&#40;</span> <span style="color: #000088;">$SID</span> <span style="color: #339933;">==</span> tep_session_name<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'='</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$HTTP_GET_VARS</span><span style="color: #009900;">&#91;</span>tep_session_name<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#41;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <a href="http://www.php.net/function_exists"><span style="color: #990000;">function_exists</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'session_regenerate_id'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="http://www.php.net/session_regenerate_id"><span style="color: #990000;">session_regenerate_id</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #000088;">$SID</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><a href="http://www.php.net/defined"><span style="color: #990000;">defined</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'SID'</span><span style="color: #009900;">&#41;</span> ? SID <span style="color: #339933;">:</span> <span style="color: #0000ff;">''</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <a href="http://www.php.net/isset"><span style="color: #990000;">isset</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$HTTP_GET_VARS</span><span style="color: #009900;">&#91;</span>tep_session_name<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <a href="http://www.php.net/unset"><span style="color: #990000;">unset</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$HTTP_GET_VARS</span><span style="color: #009900;">&#91;</span>tep_session_name<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #000088;">$_SESSION</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #009900;">&#125;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #009900;">&#125;</span></li><li>&nbsp;</li><li>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <a href="http://www.php.net/isset"><span style="color: #990000;">isset</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$HTTP_SERVER_VARS</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'HTTP_REFERER'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #339933;">!</span> tep_session_is_registered<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'first_referred_by'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;tep_session_register<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'first_referred_by'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #000088;">$first_referred_by</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$HTTP_SERVER_VARS</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'HTTP_REFERER'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #009900;">&#125;</span></li><li>&nbsp;&nbsp;<span style="color: #009900;">&#125;</span></li></ol></div></div><!--END_DEVFMTCODE-->
<p><a title="Regenerating the session when linked from an external source, Preventing shared sessions from shared links" href="http://forums.oscommerce.com/index.php?showtopic=343907" target="_blank">This has also been posted in the osCommerce Tips &amp; Tricks forum.</a></p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>DHTML State Selection</title>
		<link>http://the.ecartz.biz/dhtml-state-selection-b-108.html</link>
		<comments>http://the.ecartz.biz/dhtml-state-selection-b-108.html#comments</comments>
		<pubDate>Thu, 27 Aug 2009 19:15:17 +0000</pubDate>
		<dc:creator>eCartz</dc:creator>
				<category><![CDATA[osCommerce Coding]]></category>
		<category><![CDATA[osCommerce]]></category>
		<category><![CDATA[osCommerce Addon]]></category>
		<category><![CDATA[osCommerce contribution]]></category>

		<guid isPermaLink="false">http://the.ecartz.biz/-b-108.html</guid>
		<description><![CDATA[In response to a request on the osCommerce forums, I wrote up a method for changing automatically among drop downs for the various zones and the text input.&#160; The request was made to get it bundled into a contribution, and since there was unfinished work, I went ahead and did it.&#160; The DHTML State Selection [...]]]></description>
			<content:encoded><![CDATA[<p>In response to a request on the osCommerce forums, I wrote up <a href="http://forums.oscommerce.com/index.php?showtopic=85405&amp;view=findpost&amp;p=1432596">a method for changing automatically among drop downs for the various zones and the text input</a>.&nbsp; The request was made to get it bundled into a contribution, and since there was unfinished work, I went ahead and did it.&nbsp; The <a title="DHTML State Selection" href="http://addons.oscommerce.com/info/6975">DHTML State Selection Add on</a> is now available.&nbsp;&nbsp; Further looking, also revealed that there is at least one other contribution available for this, the AJAX based <a href="http://addons.oscommerce.com/info/2028">Country-State Selector</a>.&nbsp;</p>
<p>This brings up a point about the difference between DHTML and AJAX.&nbsp; AJAX is the new sexy term for fancy javascript and is often used to describe things that are really DHTML.&nbsp; AJAX stands for Asynchronous Javascript And XML.&nbsp; DHTML stands for Dynamic HTML.&nbsp; DHTML is taking the HTML that appears in the page and making changes to it with Javascript.&nbsp; AJAX is making a small web request to get an XML response.&nbsp; People often then use the AJAX information in DHTML changes that they make to the page.&nbsp; This has led to people calling DHTML widgets AJAX.&nbsp;</p>
<p>My add on is plain DHTML.&nbsp; It generates all the required drop downs on the server and hides them via a display:none CSS style.&nbsp; The Javascript that I wrote then turns on display of the appropriate menu when a country is selected from the countries menu.&nbsp; With all the zones installed, it&#8217;s a relatively heavy weight page.&nbsp; On the bright side, most of the page displays before it gets bogged down in creating the menus.&nbsp; Someone can enter name, street, zip, and city while waiting for the state and country to load.&nbsp;</p>
<p>The other add on apparently uses AJAX to load the menus.&nbsp; Presumably this makes the initial page load faster (fewer menus to send), but it also suggests that there will be a lag after the country is selected, while it loads the new menu.&nbsp; An interesting future project might be to do a performance comparison of the two contributions.&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>osCommerce Image Uploads</title>
		<link>http://the.ecartz.biz/oscommerce-image-uploads-b-100.html</link>
		<comments>http://the.ecartz.biz/oscommerce-image-uploads-b-100.html#comments</comments>
		<pubDate>Fri, 21 Aug 2009 20:16:24 +0000</pubDate>
		<dc:creator>eCartz</dc:creator>
				<category><![CDATA[osCommerce Coding]]></category>
		<category><![CDATA[images]]></category>
		<category><![CDATA[osCommerce]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[upload]]></category>

		<guid isPermaLink="false">http://the.ecartz.biz/-b-100.html</guid>
		<description><![CDATA[Recently, someone posted in the osCommerce forums looking for a way to upload product images into folders.&#160; I found a post that I made six years ago:&#160; Setting upload image destination in categories.php, Admin change.&#160; Surprisingly, the post was remarkably accurate with the more modern osCommerce RC2a, even the line numbers were only a couple [...]]]></description>
			<content:encoded><![CDATA[<p>Recently, someone posted in the <a href="http://forums.oscommerce.com/">osCommerce forums</a> looking for a way to upload product images into folders.&nbsp; I found a post that I made six years ago:&nbsp; <a title="osCommere forum post:  uploading images into folders" href="http://forums.oscommerce.com/index.php?showtopic=68910">Setting upload image destination in categories.php, Admin change</a>.&nbsp; Surprisingly, the post was remarkably accurate with the more modern osCommerce RC2a, even the line numbers were only a couple places off.&nbsp; The replacement code does not seem to need updating.&nbsp;</p>
<p>The way that this code works is that it adds a new text input next to the existing file input (for both product and category images).&nbsp; It then uses the functionality in the upload class that osCommerce provides to rename the image to whatever name is put in the text input.&nbsp; If the name includes a / and the directory structure exists, it will save the image into that directory.&nbsp;</p>
<p>When you upload a file with PHP, PHP/Apache stores the file in a temporary directory.&nbsp; So you then have to tell it to move the file from the temporary directory to the real directory.&nbsp; The parse method in the osCommerce upload class finds the temporary location.&nbsp; The save method then moves the file to its intended destination.&nbsp;</p>
<p>The added code has three main tasks:&nbsp; it adds the text input to the appropriate forms (three forms; one for products and two for categories); it changes the image saving to use the new image destination; and it modifies the database updates to use the image destination rather than the name of the uploaded file (if the image destination is present or if no file is uploaded).&nbsp;</p>
<p>The net result of this is that with the code, you can not upload a file and blank out the image destination (which defaults to the location of the previous image) to remove an image from a product (or category).&nbsp; In the regular code, there is no way to do this.&nbsp; Upload an image with a blank destination, which causes the image filename to be used and the image to be placed in the base images directory.&nbsp; Or you can upload an image with the destination set, which renames the image to the destination, which may be in a sub-folder of the images directory.&nbsp;</p>
<p>The one drawback to how this works is that it is currently necessary to create the directory separately (possibly via FTP).&nbsp; A reasonable enhancement might be to have it do a <a title="php function reference:  mkdir" href="http://us.php.net/manual/en/function.mkdir.php">mkdir</a> to create the directory on the fly.&nbsp; Not sure how that would work with safe mode though.&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
