<?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>Karoshi Ethos &#187; PHP</title>
	<atom:link href="http://karoshiethos.com/tag/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://karoshiethos.com</link>
	<description>Navigating the treacherous waters of interactive technology</description>
	<lastBuildDate>Fri, 11 May 2012 20:46:35 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Smarty base href Modifier</title>
		<link>http://karoshiethos.com/2010/08/07/smarty-base-href-modifier/</link>
		<comments>http://karoshiethos.com/2010/08/07/smarty-base-href-modifier/#comments</comments>
		<pubDate>Sun, 08 Aug 2010 00:36:30 +0000</pubDate>
		<dc:creator>Rob Ruchte</dc:creator>
				<category><![CDATA[How To]]></category>
		<category><![CDATA[Things that are broken]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Smarty]]></category>

		<guid isPermaLink="false">http://karoshiethos.com/?p=536</guid>
		<description><![CDATA[It appears that Safari 5 will not respect the base href tag when used in a page served via https when the base href indicates a URL with the http protocol. There is probably more to this issue, but I ran across it while working on an Authorize.net integration using their SIM API. After a [...]]]></description>
			<content:encoded><![CDATA[<p>It appears that <a href="http://www.apple.com/safari/">Safari 5</a> will not respect the base href tag when used in a page served via https when the base href indicates a URL with the http protocol. There is probably more to this issue, but I ran across it while working on an <a href="http://authorize.net/">Authorize.net</a> integration using their <a href="http://developer.authorize.net/api/sim/">SIM API</a>. After a successful transaction, Authorize.net requests a URL of the developer's choosing, and proxies the response through their server to the user's browser. This allows developers to do callback processing of the successful transaction on their server, and display a custom "thank you" page. Brilliant. The problem is, if you have any included CSS, JavaScript, or images in the page, you either need to give them all fully qualified URLs, or use the base tag to specify a root URL to use for all relative link attributes in the page (href, src, action, etc.). I've done this same type of integration many times, going back about six years, and have never had a problem using the base href in this scenario. Now, Safari 5 will completely ignore the base href and display a big mess of un-styled markup when you reach the end of the Authorize.net transaction flow.</p>
<p>I do a lot of work with the <a href="http://www.smarty.net/">Smarty</a> template engine, and the site I'm working on now is large, complex, and has a fairly advanced layout with lots of CSS and <a href="http://jquery.com/">jQuery</a> goodies. Everything is so abstracted, it's just not practical to construct a single template for my Authorize.net relay pages, of which there are several. It's also not practical to change the templates to use fully qualified URLs for everything. So what I did was write a simple Smarty modifier that prepends a specified URL to all of the relative src, href, and action attributes within the supplied string. It also fixes background: url() inline CSS styles. On my relay templates, all I have to do is wrap the contents of the template in a {capture} function, assign the output to a variable, and run it through my modifier. Absolute paths for all. Here's the modifier code, hopefully it will save someone a few grey hairs.</p>
<pre class="syntax brush-php">&lt;?php
/**
 * Smarty plugin
 * @package Smarty
 * @subpackage plugins
 */

/**
 * Smarty base_href modifier plugin
 *
 * Type:     modifier&lt;br&gt;
 * Name:     base_href&lt;br&gt;
 * Purpose:  apply a base URL to all relative
 *				src, href, and background:url() attributes in a string
 * @author   Rob Ruchte &lt;rob care of thirdpartylabs com&gt;
 * @param string
 * @param string
 * @return string
 */
function smarty_modifier_base_href($string, $base_href)
{
	$base_href = (substr($base_href, -1)!='/') ? $base_href.'/':$base_href;

	$patterns = array();
	$patterns[] = '/href=\&quot;[^#]\/?([^\&quot;]*)\&quot;/i';
	$patterns[] = '/src=\&quot;\/?([^\&quot;]*)\&quot;/i';
	$patterns[] = '/action=\&quot;\/?([^\&quot;]*)\&quot;/i';
	$patterns[] = '/background: ?url\(\'?\/?([^\'|\)]*)\'?\)/i';
	$patterns[] = '/background-image: ?url\(\'?\/?([^\'|\)]*)\'?\)/i';

	$replacements = array();
	$replacements[] = 'href=&quot;'.$base_href.'$1&quot;';
	$replacements[] = 'src=&quot;'.$base_href.'$1&quot;';
	$replacements[] = 'action=&quot;'.$base_href.'$1&quot;';
	$replacements[] = 'background: url(\''.$base_href.'$1\')';
	$replacements[] = 'background-image: url(\''.$base_href.'$1\')';

    return preg_replace($patterns, $replacements, $string);
}

/* vim: set expandtab: */

?&gt;</pre>
<p>Usage:</p>
<pre class="syntax brush-html">{capture assign=output}
{include file=&quot;include/header.tpl&quot; title=&quot;Event Ticket Registration&quot;}
	&lt;div class=&quot;span-3&quot; id=&quot;leftbar&quot;&gt;
		[...]
	&lt;/div&gt;
	&lt;div class=&quot;span-11 last&quot; id=&quot;content&quot;&gt;
		&lt;div style=&quot;background: url(/images/feature.jpg);&quot;&gt;
			[...]
		&lt;/div&gt;
		&lt;div class=&quot;span-11 last&quot; id=&quot;copy&quot;&gt;
		&lt;div id=&quot;breadcrumbs&quot;&gt;
			{foreach from=$breadcrumbs item=currNav name=breadcrumbs}
				{if !$smarty.foreach.breadcrumbs.last}&lt;a href=&quot;{$currNav.path}&quot;&gt;{/if}
				{$currNav.title}
				{if !$smarty.foreach.breadcrumbs.last}&lt;/a&gt;&amp;nbsp;&amp;raquo;&amp;nbsp;{/if}
			{/foreach}
		&lt;/div&gt;
        &lt;h2&gt;Registration: {$event-&gt;getTitle()|escape}&lt;/h2&gt;
	    {$purchaseSuccess}
        &lt;/div&gt;
    &lt;/div&gt;
{include file=&quot;include/footer.tpl&quot;}
{/capture}
{$output|base_href:$smarty.const.BASE_URL}</pre>
]]></content:encoded>
			<wfw:commentRss>http://karoshiethos.com/2010/08/07/smarty-base-href-modifier/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Blogger Feed Displayed in Flash Crashing FireFox 3, With Fix</title>
		<link>http://karoshiethos.com/2009/07/25/blogger-feed-displayed-in-flash-crashing-firefox-3-with-fix/</link>
		<comments>http://karoshiethos.com/2009/07/25/blogger-feed-displayed-in-flash-crashing-firefox-3-with-fix/#comments</comments>
		<pubDate>Sun, 26 Jul 2009 03:47:07 +0000</pubDate>
		<dc:creator>Rob Ruchte</dc:creator>
				<category><![CDATA[How To]]></category>
		<category><![CDATA[Things that are broken]]></category>
		<category><![CDATA[Blogger]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://karoshiethos.com/?p=420</guid>
		<description><![CDATA[Recently, Blogger began appending a tracking gif to the content of each entry in their Atom feeds. The URL used in the image src uses https, most likely to avoid warnings when it's rendered in a https context. For some reason, when rendering the feed content containing the tracking image, the Flash player can crash, [...]]]></description>
			<content:encoded><![CDATA[<p>Recently, Blogger began appending a tracking gif to the content of each entry in their Atom feeds. The URL used in the image src uses https, most likely to avoid warnings when it's rendered in a https context. For some reason, when rendering the feed content containing the tracking image, the Flash player can crash, taking the browser with it on certain platform/browser combinations. We found the problem in FireFox 3.0 on OSX, but only on PPC Macs. Go figure.</p>
<p>In our case, we are proxying the Atom feed through a PHP script so we can display the feed contents to user agents without the Flash player. This made it fairly easy to  iterate through the entries, and with a simple bit of regex, strip out the offending markup from the contents.</p>
<p>Blogger is wrapping the image tag in a div with a very specific CSS class, which makes our job easy:</p>
<div class="code"><code><span style="color: rgb(0, 0, 0);"><span style="color: rgb(0, 119, 0);">foreach(</span><span style="color: rgb(0, 0, 187);">$feed</span><span style="color: rgb(0, 119, 0);">-&gt;</span><span style="color: rgb(0, 0, 187);">entries&nbsp;</span><span style="color: rgb(0, 119, 0);">as&nbsp;</span><span style="color: rgb(0, 0, 187);">$currEntry</span><span style="color: rgb(0, 119, 0);">)<br />
{<br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 187);">$currEntry</span><span style="color: rgb(0, 119, 0);">-&gt;</span><span style="color: rgb(0, 0, 187);">content&nbsp;</span><span style="color: rgb(0, 119, 0);">=&nbsp;</span><span style="color: rgb(0, 0, 187);">ereg_replace</span><span style="color: rgb(0, 119, 0);">(</span><span style="color: rgb(221, 0, 0);">'&lt;div&nbsp;class=\&quot;blogger-post-footer\&quot;&gt;.*&lt;/div&gt;'</span><span style="color: rgb(0, 119, 0);">,&nbsp;</span><span style="color: rgb(221, 0, 0);">''</span><span style="color: rgb(0, 119, 0);">,&nbsp;</span><span style="color: rgb(0, 0, 187);">$currEntry</span><span style="color: rgb(0, 119, 0);">-&gt;</span><span style="color: rgb(0, 0, 187);">content</span><span style="color: rgb(0, 119, 0);">);<br />
}</span></span></code></div>
<p>Depending on what you're using to parse the feed, you may or may not need to be concerned about decoding and encoding html entities during this process.</p>
]]></content:encoded>
			<wfw:commentRss>http://karoshiethos.com/2009/07/25/blogger-feed-displayed-in-flash-crashing-firefox-3-with-fix/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Smarty File Size Modifier</title>
		<link>http://karoshiethos.com/2009/05/02/smarty-file-size-modifier/</link>
		<comments>http://karoshiethos.com/2009/05/02/smarty-file-size-modifier/#comments</comments>
		<pubDate>Sun, 03 May 2009 02:30:59 +0000</pubDate>
		<dc:creator>Rob Ruchte</dc:creator>
				<category><![CDATA[How To]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Smarty]]></category>

		<guid isPermaLink="false">http://karoshiethos.com/?p=342</guid>
		<description><![CDATA[Here's a simple Smarty modifier that will format an integer that represents the number of bytes in a file as a human readable string. Usage: {$fileSizeInBytes&#124;file_size} Example: {assign var=fileSizeInBytes value=10485760} {$fileSizeInBytes&#124;file_size} {assign var=fileSizeInBytes value= 768000} {$fileSizeInBytes&#124;file_size} {assign var=fileSizeInBytes value=303} {$fileSizeInBytes&#124;file_size} Output: 10 MB 750 Kb 303 bytes &#60;?php /** * Smarty plugin * @package Smarty [...]]]></description>
			<content:encoded><![CDATA[<p>Here's a simple <a href="http://smarty.net/">Smarty</a> modifier that will format an integer that represents the number of bytes in a file as a human readable string.</p>
<p><strong>Usage:</strong><br />
{$fileSizeInBytes|file_size}</p>
<p><strong>Example:</strong><br />
{assign var=fileSizeInBytes value=10485760}<br />
{$fileSizeInBytes|file_size}</p>
<p>{assign var=fileSizeInBytes value= 768000}<br />
{$fileSizeInBytes|file_size}</p>
<p>{assign var=fileSizeInBytes value=303}<br />
{$fileSizeInBytes|file_size}</p>
<p><strong>Output:</strong><br />
10 MB<br />
750 Kb<br />
303 bytes</p>
<pre class="syntax brush-php">
&lt;?php
/**
 * Smarty plugin
 * @package Smarty
 * @subpackage plugins
 */

/**
 * Smarty file_size modifier plugin
 *
 * Type:     modifier&lt;br&gt;
 * Name:     file_size&lt;br&gt;
 * Purpose:  format file size represented in bytes into a human readable string&lt;br&gt;
 * Input:&lt;br&gt;
 *         - bytes: input bytes integer
 * @author   Rob Ruchte &lt;rob at thirdpartylabs dot com&gt;

 * @param integer
 * @return string
 */
function smarty_modifier_file_size($bytes=0)
{
    $mb = 1024*1024;

    if ($bytes &gt; $mb)
    {
        $output = sprintf (&quot;%01.2f&quot;,$bytes/$mb) . &quot; MB&quot;;
    }
    elseif ( $bytes &gt;= 1024 )
    {
        $output = sprintf (&quot;%01.0f&quot;,$bytes/1024) . &quot; Kb&quot;;
    }
    else
    {
        $output = $bytes . &quot; bytes&quot;;
    }

    return $output;
}

/* vim: set expandtab: */

?&gt;</pre>
]]></content:encoded>
			<wfw:commentRss>http://karoshiethos.com/2009/05/02/smarty-file-size-modifier/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Installing PDO_MYSQL on CentOS (the easy way)</title>
		<link>http://karoshiethos.com/2008/07/24/installing-pdo_mysql-on-centos/</link>
		<comments>http://karoshiethos.com/2008/07/24/installing-pdo_mysql-on-centos/#comments</comments>
		<pubDate>Thu, 24 Jul 2008 17:14:56 +0000</pubDate>
		<dc:creator>Rob Ruchte</dc:creator>
				<category><![CDATA[How To]]></category>
		<category><![CDATA[Carbon]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Zend Framework]]></category>

		<guid isPermaLink="false">http://karoshiethos.com/?p=37</guid>
		<description><![CDATA[When deploying LAMP projects, quite often we find ourselves being given access to a newly installed server with distribution-specific default configurations, which are usually very stripped down. Our Carbon Content Management Toolkit, which runs on top of the Zend Framework, uses the PDO_MYSQL driver for data access, along with a few other modules that are [...]]]></description>
			<content:encoded><![CDATA[<p>When deploying LAMP projects, quite often we find ourselves being given access to a newly installed server with distribution-specific default configurations, which are usually very stripped down. Our <a href="http://thirdpartylabs.com/services/cms">Carbon Content Management Toolkit</a>, which runs on top of the <a href="http://framework.zend.com/">Zend Framework</a>, uses the <a href="http://pecl.php.net/package/PDO_MYSQL">PDO_MYSQL</a> driver for data access, along with a few other modules that are typically present in commercial hosting environments, but not always included in an OS's default PHP build.</p>
<p>Getting <a href="http://pear.php.net/">PEAR</a>, <a href="http://pecl.php.net/">PECL</a>, and a build environment set up can be a time consuming process if you do it from scratch. Luckily most OSs these days come with easy to use package management systems that take care of downloading, building, and installing the packages you need, and their dependancies.</p>
<p>Check the <a href="http://en.wikipedia.org/wiki/Package_management_system">package management system</a> entry on Wikipedia if you're unsure about which package system your OS uses. Each one works a little bit differently, but the concepts are the same. You're going to need to set up your OS's version of the following packages in order to make your life easy:</p>
<p>php-devel<br />
php-pear<br />
mysql-devel<br />
httpd-devel</p>
<p>The package names will differ a bit for each system. The following example uses the <a href="http://wiki.centos.org/PackageManagement/Yum">Yum package manager</a> in <a href="http://centos.org/">CentOS</a>, and gets PDO_MYSQL up and running in just a few minutes.</p>
<p><code class="console"># yum install php-devel php-pear mysql-devel httpd-devel<br />
# pecl install pdo<br />
# PHP_PDO_SHARED=1 pecl install pdo_mysql</code></p>
<p>Add these lines to php.ini:</p>
<p><code class="console">extension=pdo.so<br />
extension=pdo_mysql.so</code></p>
<p>Now restart Apache, and you should see your PDO modules in phpinfo(), Robert's your father's brother.<br />
<code class="console"># apachectl restart</code></p>
<p>If you need to actually <a href="http://www.php.net/manual/en/install.unix.php">make a custom PHP build</a>, you should have everything you need to do that after installing the devel packages. You still may need to build any dependancies that your custom PHP build requires, but your package system should make that fairly easy.</p>
]]></content:encoded>
			<wfw:commentRss>http://karoshiethos.com/2008/07/24/installing-pdo_mysql-on-centos/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
	</channel>
</rss>

