<?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; How To</title>
	<atom:link href="http://karoshiethos.com/category/how-to/feed/" rel="self" type="application/rss+xml" />
	<link>http://karoshiethos.com</link>
	<description>Navigating the treacherous waters of interactive technology</description>
	<lastBuildDate>Sat, 06 Nov 2010 16:38:51 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1</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>Serving a Flash Socket Policy File From Processing</title>
		<link>http://karoshiethos.com/2010/03/26/serving-a-flash-socket-policy-file-from-processing-org/</link>
		<comments>http://karoshiethos.com/2010/03/26/serving-a-flash-socket-policy-file-from-processing-org/#comments</comments>
		<pubDate>Sat, 27 Mar 2010 03:52:53 +0000</pubDate>
		<dc:creator>Rob Ruchte</dc:creator>
				<category><![CDATA[How To]]></category>
		<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Kung-Foo]]></category>
		<category><![CDATA[Processing]]></category>

		<guid isPermaLink="false">http://karoshiethos.com/?p=500</guid>
		<description><![CDATA[Last night I spent way too long trying to get AS3 to communicate with a simple socket server I wrote in Processing. I've done this kind of thing before and seemed to recall that it was pretty simple. But in the meantime, Adobe, in an effort to be more secure, has changed the Flash player [...]]]></description>
			<content:encoded><![CDATA[<p>Last night I spent way too long trying to get AS3 to communicate with a simple socket server I wrote in <a href="http://processing.org/" target="_blank">Processing</a>. I've done this kind of thing before and seemed to recall that it was pretty simple. But in the meantime, Adobe, <a href="http://www.adobe.com/devnet/flashplayer/articles/flash_player9_security_update.html#socket_policy" target="_blank">in an effort to be more secure</a>, has changed the Flash player to require a "<a href="http://www.adobe.com/devnet/flashplayer/articles/fplayer9_security_04.html" target="_blank">socket policy file</a>". The socket policy file is very similar to the familiar crossdomain.xml file that defines security permissions for HTTP access. Unfortunately, the socket policy file must either be sent on demand from the sockets that the player is attempting to access, <a href="http://www.adobe.com/devnet/flashplayer/articles/socket_policy_files.html" target="_blank">or from port 843</a> on the host that the player is attempting to connect to. If all you want to do is run a quick and dirty socket server and have Flash clients connect to it, this is all a huge PITA.</p>
<p>Since <a href="http://e-articles.info/e/a/title/Privileged-Ports-of-a-UNIX-machine/" target="_blank">ports below 1024 require root permissions</a> in order for processes to use them on OS X, and I didn't want to run some other server process just to serve policy files, I needed to kludge a way to send the policy file from my nice, elegant socket server every time a client connected and requested a policy file. The example below is a simplified version, as it only listens on one port - the project I was working on was basically a proxy from one SWF to another, so I had two socket servers that needed to listen for the requests for a policy file and respond. In this example, the server listens for connections on port 5208, and simply echoes incoming data from the client to System.out, and has some visual feedback in the window. When the incoming message contains the string "policy-file-request" (the entire message from Flash will be
<policy-file-request/> terminated with a null char), we simply spit back the XML for a wide-open socket policy, followed by a null char (This is required, or the Flash player will not accept the policy file. This is what tied me in knots last night. RTFM!)</p>
<pre class="syntax brush-java">import processing.net.*;

int bgLevel = 0;
int port = 5208;
Server server;

String flashDomainPolicy = &quot;&lt;?xml version=\&quot;1.0\&quot;?&gt;&quot;
                              +&quot;&lt;cross-domain-policy xmlns:xsi=\&quot;http://www.w3.org/2001/XMLSchema-instance\&quot; xsi:noNamespaceSchemaLocation=\&quot;http://www.adobe.com/xml/schemas/PolicyFileSocket.xsd\&quot;&gt;&quot;
                              +&quot;&lt;allow-access-from domain=\&quot;*\&quot; to-ports=\&quot;*\&quot; secure=\&quot;false\&quot; /&gt;&quot;
                              +&quot;&lt;site-control permitted-cross-domain-policies=\&quot;all\&quot; /&gt;&quot;
                              +&quot;&lt;/cross-domain-policy&gt;&quot;;

void setup ()
{
  size(200, 200);
  server = new Server(this, port);
  background(bgLevel);
}

void draw ()
{
  Client client = server.available();

  if (client !=null)
  {
    String message = trim(client.readString());

    if (message != null)
    {
      if (match(message,&quot;policy-file-request&quot;) != null)
      {
        sendFlashPolicy(server);
      }
      else
      {
        server.write(message);
        System.out.println(message);

        // Change the background color to indicate message activity
        bgLevel = 255;
      }
    }
  }

  // Fade to black
  if (bgLevel&gt;1)
  {
    bgLevel-=2;
    background(bgLevel);
  }
}

void sendFlashPolicy(Server socketServer)
{
    socketServer.write(flashDomainPolicy+char(0));
    System.out.println(&quot;Sending Flash policy file&quot;);
}</pre>
<p>You can test this without a Flash client by firing up the sketch and telnetting to the port. Any strings you send will be echoed to System.out, unless you send the string "policy-file-request" in your message, which will result in the server sending the policy XML to you. You should be able to connect a Flash client to this server and start communicating right away.</p>
]]></content:encoded>
			<wfw:commentRss>http://karoshiethos.com/2010/03/26/serving-a-flash-socket-policy-file-from-processing-org/feed/</wfw:commentRss>
		<slash:comments>3</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>Automatic AMF class mapping in Zend (Part 2)</title>
		<link>http://karoshiethos.com/2009/06/11/automatic-amf-class-mapping-in-zend-part-2/</link>
		<comments>http://karoshiethos.com/2009/06/11/automatic-amf-class-mapping-in-zend-part-2/#comments</comments>
		<pubDate>Thu, 11 Jun 2009 19:35:42 +0000</pubDate>
		<dc:creator>jon</dc:creator>
				<category><![CDATA[How To]]></category>

		<guid isPermaLink="false">http://karoshiethos.com/?p=404</guid>
		<description><![CDATA[see Part 1 Polishing off automatic mapping of objects to the correct class from PHP (Zend) back to ActionScript turned out to be easier than I thought. In addition to the more commonly used $_explicitType class property, Zend also supports using a function called getASClassName. You can either paste this into each of your remote [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://karoshiethos.com/2009/06/11/automatic-amf-class-mapping-in-zend-part-1/">see Part 1</a></p>
<p>Polishing off automatic mapping of objects to the correct class from PHP (Zend) back to ActionScript turned out to be easier than I thought.</p>
<p>In addition to the more commonly used $_explicitType class property, Zend also supports using a function called getASClassName. You can either paste this into each of your remote class stubs, or modify the getClassName method in Serializer to do it automatically.</p>
<p><code class="php">public function getASClassName() <br />
{<br />
 return "&gt;" . str_replace("_", ".", get_class($this)); <br />
}</code></p>
<p>Clearly you'll need to avoid underscores appearing package and class names. That may be true regardless if you're planning to take advantage of Zend's automatic class loading.</p>
<p>On the Flash side, if you're not using the Flex compiler, you can use this to automatically register class aliases to the correct string.</p>
<p><code class="actionscript">function autoRegisterClassAlias (localClass:Class):void<br />
{<br />
registerClassAlias("&gt;" + flash.utils.describeType(localClass).@name.split("::").join("."), localClass)<br />
}</code></p>
<p>I've made it compatible with the Flex version. If the greater-than character is the cause of annoyance and confusion, feel free to remove it, but you'll need to do so on the PHP classes as well.</p>
<p>I'm sure this won't be our last post on this topic. If you've got lots of experience with AMF and Zend (I honestly don't) please post your thoughts in the comments.</p>
]]></content:encoded>
			<wfw:commentRss>http://karoshiethos.com/2009/06/11/automatic-amf-class-mapping-in-zend-part-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Automatic AMF class mapping in Zend (Part 1)</title>
		<link>http://karoshiethos.com/2009/06/11/automatic-amf-class-mapping-in-zend-part-1/</link>
		<comments>http://karoshiethos.com/2009/06/11/automatic-amf-class-mapping-in-zend-part-1/#comments</comments>
		<pubDate>Thu, 11 Jun 2009 17:33:38 +0000</pubDate>
		<dc:creator>jon</dc:creator>
				<category><![CDATA[How To]]></category>

		<guid isPermaLink="false">http://karoshiethos.com/?p=394</guid>
		<description><![CDATA[First off, much thanks to Lee Coltrane for figuring this out. He's a bit busy at the moment, so I'm writing this up without the benefit of his input which I'm sure will be extremely valuable once our schedules mesh up. A few caveats right off the bat. 1) We're still figuring out our best [...]]]></description>
			<content:encoded><![CDATA[<p>First off, much thanks to Lee Coltrane for figuring this out. He's a bit busy at the moment, so I'm writing this up without the benefit of his input which I'm sure will be extremely valuable once our schedules mesh up.</p>
<p>A few caveats right off the bat. 1) We're still figuring out our best practices. 2) This is Flex only (see below)  3) We haven't (yet) written any code to automatically populate the $_explicitType variable going back to Flash from PHP.</p>
<p>If you're reading this, you've more than likely come across a Flex metatag like the one below:</p>
<p><code class="actionscript">[RemoteClass(alias="com.domain.FooBar")]</code></p>
<p>Personally, I found it annoying to have to populate the alias manually. The compiler knows the package name and the class name. Don't make me type it again! And, in fact, the compiler will accept the metatag without it:</p>
<p><code class="actionscript">[RemoteClass]</code></p>
<p>The only problem is getting Zend (in our case) to map it to the correct remote class. The Adobe engineers saw fit to prepend a greater-than character to the outgoing classname when using this syntax. So, if you omit the alias, "&gt;com.domain.FooBar" will be sent instead.</p>
<p>To get ZendAmf to map this automatically, you'll need to make a slight modification to the Deserializer.php class. Mine is located in Zend/Amf/Parse/Amf3/Deserializer.php (Note: I haven't even looked at the Amf0 class yet, but my understanding is that custom class mapping isn't supported in AMF0) Insert the following code around line 315 in the readObject method after it has tried to determine the className but before it has assigned a return object.</p>
<p><code class="php">// Allow and map automatic aliases via RemoteClass metatag &amp; flex<br />
if (strpos ($className, '&gt;') === 0)<br />
{<br />
  $className = substr ($className, 1);<br />
}<br />
//translation: If the classname begins with '&gt;' use the rest of the string instead.<br />
</code></p>
<p>This addition will deal with <strong>incoming</strong> class mapping. If you want to remove the alias parameter from all of your ActionScript RemoteClass metatags, you'll need to format your $_explicitType entries like this:</p>
<p><code class="php">$_explicitType = "&gt;com.domain.FooBar";</code></p>
<p>...which is what we'll look at in Part 2! </p>
<p>NOTE: I said at the very beginning this is Flex only. Compiling with the Flash IDE does not support the RemoteClass metaTag, so you'll need to use registerRemoteClass as you've probably read about elsewhere. Perhaps in part 2 (or 3?) I'll write up an ActionScript class that can register classes against the correct package names automatically. Until then, I'll give you a hint: flash.utils.describeType.</p>
]]></content:encoded>
			<wfw:commentRss>http://karoshiethos.com/2009/06/11/automatic-amf-class-mapping-in-zend-part-1/feed/</wfw:commentRss>
		<slash:comments>1</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>SEO Presentation for NCSU Web Developer Group</title>
		<link>http://karoshiethos.com/2009/04/22/seo-presentation-for-ncsu-web-developer-group/</link>
		<comments>http://karoshiethos.com/2009/04/22/seo-presentation-for-ncsu-web-developer-group/#comments</comments>
		<pubDate>Wed, 22 Apr 2009 21:50:54 +0000</pubDate>
		<dc:creator>Rob Ruchte</dc:creator>
				<category><![CDATA[How To]]></category>

		<guid isPermaLink="false">http://karoshiethos.com/?p=325</guid>
		<description><![CDATA[Jon and I delivered a presentation about SEO to the NCSU Web Developer Group this afternoon. If you were in attendance, thanks very much for coming to see us, we hope you found it informative. We talked about a lot of useful online resources during the presentation, all of the links are in the slide deck that we've posted [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://karoshiethos.com/author/jon/">Jon</a> and <a href="http://karoshiethos.com/author/rob/">I</a> delivered a presentation about SEO to the <a href="http://ncsuwebdev.ning.com/">NCSU Web Developer Group</a> this afternoon. If you were in attendance, thanks very much for coming to see us, we hope you found it informative. We talked about a lot of useful online resources during the presentation, all of the links are in the slide deck that we've posted for your convenience. You can download <a title="Thirdparty Labs and Shovemedia SEO Presentation" href="http://karoshiethos.com/seo.pdf">a PDF of the slides here</a>, or <a href="http://www.slideshare.net/RobRuchte/seo-strategies-by-thirdparty-labs-and-shovemedia">view them on SlideShare</a>. </p>
<p>Please feel free to post comments and questions here.</p>
]]></content:encoded>
			<wfw:commentRss>http://karoshiethos.com/2009/04/22/seo-presentation-for-ncsu-web-developer-group/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>AS3 Class to Asset Linkage &#8211; something different?</title>
		<link>http://karoshiethos.com/2008/12/22/as3-class-to-asset-linkage-something-different/</link>
		<comments>http://karoshiethos.com/2008/12/22/as3-class-to-asset-linkage-something-different/#comments</comments>
		<pubDate>Tue, 23 Dec 2008 03:18:12 +0000</pubDate>
		<dc:creator>jon</dc:creator>
				<category><![CDATA[How To]]></category>
		<category><![CDATA[Things that are broken]]></category>

		<guid isPermaLink="false">http://karoshiethos.com/?p=157</guid>
		<description><![CDATA[I decided I'd try an FLA-less project using embedded library assets from swfs, but that proved contrary to my workflow. If I'm going to use the IDE for layout, then I've got a good handful of layers. Not just a graphic or three. I want several things to align, you know visually, so I used [...]]]></description>
			<content:encoded><![CDATA[<p>I decided I'd try an FLA-less project using embedded library assets from swfs, but that proved contrary to my workflow. If I'm going to use the IDE for layout, then I've got a good handful of layers. Not just a graphic or three. I want several things to align, you know visually, so I used a visual layout tool to configure my layout. Smart, huh? But you can't pull in an entire timeline worth of assets and then provide the class and still expect to get the whole thing wired up. Flex compiler's gotta be all one child asset at a time within the class.</p>
<p>Despite reading more than once that you could somehow:</p>
<p><code>[Embed (src="library.swf", symbol="layout"]<br />
public class layoutClass extends Sprite<br />
{<br />
//  rest of class here<br />
}<br />
</code></p>
<p>I never got it to work. I only got the directive to work for class property members, not the class definition itself.</p>
<p>You could use composition to pull an entire layout's worth of assets in. But then you've got this magic asset container property that's different from the local "this" context. No, I wanted all the assets linked to the class in one place, like I was used to with the IDE in the first place.</p>
<p>I decided it was worth it to reparent all the assets out of a temporary holder, and reconstruct the layer stack in the new parent.</p>
<p>I knew the code for this wasn't hard or long, but it isn't exactly obvious:</p>
<p><code>//Layout is a class that can be populated via<br />
//embed directive or by having a 'skin' swc in your classpath. <br />
<br/>var layout:Sprite = new Layout()<br />
<br/>var len = layout.numChildren<br />
for (var i=0; i&lt;len ; i++) {<br />
  //move the child into this<br />
  var c = addChild (layout.getChildAt(0))<br />
  //link the property name of the class to the asset<br />
  this[c.name] = c<br />
}<br />
</code></p>
<p>Merry WhateverDecemberweenNewYear.</p>
]]></content:encoded>
			<wfw:commentRss>http://karoshiethos.com/2008/12/22/as3-class-to-asset-linkage-something-different/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>PNG sequence to SWF</title>
		<link>http://karoshiethos.com/2008/09/03/png-sequence-to-swf/</link>
		<comments>http://karoshiethos.com/2008/09/03/png-sequence-to-swf/#comments</comments>
		<pubDate>Wed, 03 Sep 2008 19:59:18 +0000</pubDate>
		<dc:creator>jon</dc:creator>
				<category><![CDATA[How To]]></category>
		<category><![CDATA[PNG sequence SWF swftools batch]]></category>

		<guid isPermaLink="false">http://karoshiethos.com/?p=109</guid>
		<description><![CDATA[I needed to stitch a stack of PNG images into a SWF using a server process. There are quite a few tools and methods for doing this interactively, but it gets painful if you want an unattended process. I found SWFTools (includes PNG2SWF.EXE), which handles the awful, complex bit of ... building a SWF from [...]]]></description>
			<content:encoded><![CDATA[<p>I needed to stitch a stack of PNG images into a SWF using a server process. There are quite a few tools and methods for doing this interactively, but it gets painful if you want an unattended process.</p>
<p>I found <a href="http://swftools.org/">SWFTools</a> (includes PNG2SWF.EXE), which handles the awful, complex bit of ... building a SWF from a bunch of PNGs, but then I needed to figure out how to get it to auto-magically use all the PNGs in a specific folder. Essentially, I found a tool that does the hard part, but I needed to cobble together the actual command it should use. Wince if you want to, but I'm a masochist and I hacked together this batch file (like it's 1988, baby):</p>
<p><code>@echo OFF<br />
SET LIST=<br/><br />
REM Build a list of PNGs<br />
for /f "delims=" %%a in ('dir /b /a-d %1*.png 2^&gt;NUL') do call :process %%a %1<br/><br />
@echo ON<br />
REM now make a SWF!<br />
CALL png2swf -r 20 -o %2 %LIST%<br/><br />
SET LIST=<br />
goto :eof<br/><br />
:process<br />
REM append the next file to the LIST variable<br />
if not "%LIST%"=="" set LIST=%LIST%<br />
set LIST=%LIST%%~2%~1</code></p>
<p>example usage -- test.bat c:\path\pngFolder c:\path\resulting.swf</p>
<p>I'm sure this is dead easy in linux (you can get swftools in linux flavors too, including source), and I'll send cookies to whoever posts the first working script in the comments.</p>
<p>Note: I'm not sure why this is, but the resulting SWF can't be imported into Flash CS3 as one would expect. If you were going to do <em>that</em>, you could've imported the initial sequence in the first place.</p>
]]></content:encoded>
			<wfw:commentRss>http://karoshiethos.com/2008/09/03/png-sequence-to-swf/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Mangled Kerning Revisited—Now with Workaround!</title>
		<link>http://karoshiethos.com/2008/08/14/mangled-kerning-revisited%e2%80%94now-with-workaround/</link>
		<comments>http://karoshiethos.com/2008/08/14/mangled-kerning-revisited%e2%80%94now-with-workaround/#comments</comments>
		<pubDate>Thu, 14 Aug 2008 19:40:24 +0000</pubDate>
		<dc:creator>jon</dc:creator>
				<category><![CDATA[How To]]></category>
		<category><![CDATA[Things that are broken]]></category>

		<guid isPermaLink="false">http://karoshiethos.com/?p=91</guid>
		<description><![CDATA[(see the original Mangled Kerning post) We decided when we started this blog it wasn't going to be a bunch of whine, whine, whine such-and-such doesn't work. If we couldn't find a workaround of some sort, then we were just polluting the search space with more of the same "anyone else have an answer?" You [...]]]></description>
			<content:encoded><![CDATA[<p>(see the <a href="http://karoshiethos.com/2008/07/26/mangled-kerning-in-flash-html-text/">original Mangled Kerning</a> post)</p>
<p>We decided when we started this blog it wasn't going to be a bunch of whine, whine, whine such-and-such doesn't work. If we couldn't find a workaround of some sort, then we were just polluting the search space with more of the same "anyone else have an answer?" You may have dug through some of that to get here. There's value in seeing you're not the only one out there, but it's so limited we decided to avoid it if at all possible.</p>
<p>So. You've got an autosized textfield. You want to use Anti-alias for readability. But you've noticed strange spacing problems around HTML anchors. You've got a few options. I've come back to edit this post several times after seeing opportunities to achieve the same fix with less effort, but I'm preserving some of the more complex work-arounds because the bug is so quirky, someone might have need to try one of the uglier approaches.</p>
<p>1) After setting the htmlText, access the height property of the field, then it's safe to turn off autoSize which will allow correct kerning behavior:</p>
<pre>
var temp1 = (field.height)
field.autoSize = TextFieldAutoSize.NONE
</pre>
<p>You won't have to wait additional frames or anything like that. Just remember to turn autoSize back on before changing the text.</p>
<p>2) Set the antiAliasType property of the TextField to flash.text.AntiAliasType.ADVANCED <em><strong>after </strong>the field has already been on the stage for at least two (count 'em: 2) frames</em>. That's frame 3 if you're following along at home and your TextField was present on frame 1. Use the visible property to avoid epileptic seizures.</p>
<p>3) It would appear that only authoring-tool-placed TextFields require the extra 2 frames. Create a TextField from code, and you can set the antiAliasType property of the TextField to flash.text.AntiAliasType.ADVANCED in the <strong>next</strong> frame. Again, use the visible property to hide the layout jump:</p>
<pre>var field = new TextField( 20, 20, 500, 1)
addChild(field)

field.embedFonts = true
field.multiline = true
field.wordWrap = true
field.autoSize = TextFieldAutoSize.LEFT

var styles = new StyleSheet();
styles.setStyle("p", {fontFamily: "HelveticaNeueLT Std Med Cn", fontSize: "18", kerning: false, letterSpacing: 0, color: '#CCCCCC'})
styles.setStyle("a", {textDecoration: 'underline', kerning: false, letterSpacing: 0, color: '#FFFFFF'} );
field.styleSheet = styles

field.htmlText = "&lt;p&gt;This top line is necessary to push the content down because that matters somehow in this simple example of &lt;a href=\"http://nowhere.com\"&gt;Quirky&lt;/a&gt; text in Flash.&lt;/p&gt;"

//NEXT FRAME:
field.antiAliasType = flash.text.AntiAliasType.ADVANCED
</pre>
<p>4) If you must be a sadist, use a hybrid approach to replace authoring tool-placed TextFields with runtime-created TextFields while preserving position, dimensions, autoSizing, styles, etc. And after you've gone to all the trouble, don't forget to set the antiAliasType to advanced. If you're willing to let the original field handle the autoSizing, you can turn <strong>off</strong> autoSize on the dynamic field, size it according to the first field, and avoid having to wait a frame to set the antiAliasType as in #2. Just remember that if you need to change the field's contents, you'll have to turn autoSize back on. NOTE: Your mileage may vary, but I found that wordwrap was uneffected by this bug, so even though the kerning sometimes jumps around aggressively, I didn't find any changes in wordwrapping, thus no changes in sizing to worry about ... so far.</p>
]]></content:encoded>
			<wfw:commentRss>http://karoshiethos.com/2008/08/14/mangled-kerning-revisited%e2%80%94now-with-workaround/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>

