<?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>SqUe &#187; dev</title>
	<atom:link href="http://blogs.kmfa.net/sque/tag/dev/feed/" rel="self" type="application/rss+xml" />
	<link>http://blogs.kmfa.net/sque</link>
	<description>&#34;Think free speech, not free beer&#34;</description>
	<lastBuildDate>Fri, 02 Apr 2010 01:37:10 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Code quality measurement</title>
		<link>http://blogs.kmfa.net/sque/2010/02/code-quality-measurement/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=code-quality-measurement</link>
		<comments>http://blogs.kmfa.net/sque/2010/02/code-quality-measurement/#comments</comments>
		<pubDate>Sun, 21 Feb 2010 16:41:49 +0000</pubDate>
		<dc:creator>sque</dc:creator>
				<category><![CDATA[Geeking]]></category>
		<category><![CDATA[dev]]></category>
		<category><![CDATA[funny]]></category>

		<guid isPermaLink="false">http://blogs.kmfa.net/sque/?p=158</guid>
		<description><![CDATA[I was looking for the best way to measure code quality and I found it. Here is the scientific presentation of the formula. I think many coders out there will agree that this is definitely a good way!]]></description>
			<content:encoded><![CDATA[<p style="text-align: left">I was looking for the best way to measure code quality and I <a href="http://phpkitchen.com/2009/04/how-to-measure-code-quality/">found it</a>. Here is the scientific presentation of the formula.</p>
<p style="text-align: center"><img class="aligncenter size-full wp-image-159" title="WTFs/Minute" src="http://blogs.kmfa.net/sque/files/2010/02/wtfspermin1.jpg" alt="" width="500" height="471" /></p>
<p style="text-align: center">
<p style="text-align: left">I think many coders out there will agree that this is definitely a good way!</p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.kmfa.net/sque/2010/02/code-quality-measurement/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Tinkering with Tags</title>
		<link>http://blogs.kmfa.net/sque/2009/12/tinkering-with-tags/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=tinkering-with-tags</link>
		<comments>http://blogs.kmfa.net/sque/2009/12/tinkering-with-tags/#comments</comments>
		<pubDate>Fri, 18 Dec 2009 17:22:20 +0000</pubDate>
		<dc:creator>sque</dc:creator>
				<category><![CDATA[PHPLibs]]></category>
		<category><![CDATA[dev]]></category>
		<category><![CDATA[htmltag]]></category>
		<category><![CDATA[phplibs]]></category>

		<guid isPermaLink="false">http://blogs.kmfa.net/sque/?p=43</guid>
		<description><![CDATA[PHPLibs has an HTML module which contains the HTMLTag and HTMLDoc class. Those two classes have many commons with DOM&#8217;s element and document specification, but they are actually complete different and dont try to use it for DOM parsing and manipulation. PHPLib&#8217;s html module was designed to generate html source and not parse one. It [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://phplibs.kmfa.net">PHPLibs</a> has an HTML module which contains the <a href="http://phplibs.kmfa.net/api/HTMLTag">HTMLTag</a> and <a href="http://phplibs.kmfa.net/api/HTMLDoc">HTMLDoc</a> class. Those two classes have many commons with DOM&#8217;s element and document specification, but they are actually complete different and dont try to use it for DOM parsing and manipulation.</p>
<p>PHPLib&#8217;s html module was designed to generate html source and not parse one. It is the opposite of php&#8217;s native DOM usage, where most of the times is used to parse xhtml/html source. This is because creating elements using the DOM specification could be very painfull and you will probably loose hours of writing while you could just dump static html code or generate dynamic code using a home-made string concatenation function like &#8220;my_html_tag&#8221;.</p>
<p><span id="more-43"></span></p>
<h3>The birth of HTML module</h3>
<pre class="brush: php; title: ; notranslate">
$dom = new DOMDocument('1.0', 'iso-8859-1');
$element = $dom-&gt;appendChild(new DOMElement('root'));
$element_ns = new DOMElement('pr:node1', 'thisvalue', 'http://xyz');
$element-&gt;appendChild($element_ns);
echo $dom-&gt;saveXML(); /* &lt;?xml version=&quot;1.0&quot; encoding=&quot;iso-8859-1&quot;?&gt;
&lt;root&gt;&lt;pr:node1 xmlns:pr=&quot;http://xyz&quot;&gt;thisvalue&lt;/pr:node1&gt;&lt;/root&gt; */
</pre>
<p>Imagine using the above format to create numerous nested elements&#8230; like nightmare. The first time I wanted to create dynamic html I realized that there were only two ways for me, either template engine or string crafting in source. However we know very well that as web is evolving we are heading towards micro-formats and CSS for styling, and using template engines nowadays is like using rock to cut a potato.</p>
<p>So for me the only was to start echo this and concat that to create html code. Instantly, the door bell rings and some old friends came to visit me. Mr. Mess, Mrs Insecurity with their ugly kids which I still haven&#8217;t learned their names. I realized that this is dead-end for me, I slammed the door and started thinking how on heck can I have simple dynamic html, in a secure, easy, portable, html version independant and fast way to use.</p>
<p>This was the start of HTMLTag, which is still missing many many things, but it is usable, safe and quite fast. Lets see how can this module help us to ease our path to successful programming. HTMLTag has almost the same usage like DOMElement, you have to create it by instantiating the class and append it to parent element, so to create a 2&#215;2 table you have to do something like this:</p>
<pre class="brush: php; title: ; notranslate">
// A 2x2 table creation
 $table = new HTMLTag('table',
     new HTMLTag('tr',
         new HTMLTag('td', 'row 1 col 1'),
         new HTMLTag('td', 'row 1 col 2')
     ),
     new HTMLTag('tr',
         new HTMLTag('td', 'row 2 col 1'),
         new HTMLTag('td', 'row 2 col 2')
     )
 );</pre>
<p>You will start thinking that I am idiot to create something that has the same disadvantages of what I am whining for. Well object instantiation process is not the best and there are some plans to improve it, but there is a faster way to do the same by using shortcut functions like <strong>tag()</strong>.</p>
<pre class="brush: php; title: ; notranslate">
// A 2x2 table using tag() shortcut
 $table = tag('table,
     tag('tr',
         tag('td', 'row 1 col 1'),
         tag('td', 'row 1 col 2')
     ),
     tag('tr',
         tag('td', 'row 2 col 1'),
         tag('td', 'row 2 col 2')
     )
 );
</pre>
<p>The above example showed how to created nested tags. It was done in the same and less number of characters that you would need to write html, so we are on the right direction. Apart from this, <strong>all</strong> the data are <strong>implicitly</strong> escaped preventing any script injections techniques or unwanted disformation of the output. There is off course an easy way to explicitly inject html code.</p>
<h3>Show me some magic</h3>
<p>You are probably expecting to see a miracle or something, but you will not find one here. However there are some tricks that should be mentioned. In the next paragraphs I will show you what HTMLTag is capable to do at the moment and how it can help you in development.</p>
<h4>Automatic rendering</h4>
<p>HTMLTag supports automatic rendering of tags by casting them to strings. When php demands the string format of the object it will render itself and all childs and return the html code.</p>
<p>Continuing with the above example, the following code will echo the html.</p>
<pre class="brush: php; title: ; notranslate">echo $table; // $table will call render() automatically and return html code</pre>
<p>There is also another shortcut function named <strong>etag()</strong> which is a shortcut of &#8220;<strong>echo tag()</strong>&#8221; so if you wanted to create the table and sent it to output buffer you could do:</p>
<pre class="brush: php; title: ; notranslate">etag('table,
     tag('tr',
         tag('td', 'row 1 col 1'),
         tag('td', 'row 1 col 2')
     ),
     tag('tr',
         tag('td', 'row 2 col 1'),
         tag('td', 'row 2 col 2')
     )
 );</pre>
<h4>Render in HTML or XHTML</h4>
<p>HTMLTag is capable to render HTML and XHTML compliant code depending on what it will be asked to do. Rendering mode can be controlled globally or per tag. By default HTMLTag renders in html mode, this can be changed by changing the <em>static</em> property <a href="http://phplibs.kmfa.net/api/HTMLTag/$default_render_mode">$default_render_mode</a> to &#8220;xhtml&#8221;.</p>
<p>So if you wanted to render table in xhtml it can be done like this</p>
<pre class="brush: php; title: ; notranslate">HTMLTag::$default_render_mode = 'xhtml';
echo $table;</pre>
<p>You will probably decide your rendering mode in one place and this must be done before any rendering occurs. You could even use different output modes depending on the agent that client is using.</p>
<p>Note that HTMLDoc is also checking HTMLTag::$default_render_mode for selecting document type.</p>
<h4>Automatic appending &#8211; <em>looking for better name</em> -</h4>
<p>HTMLTag supports a way to automatic append new tags without explicit telling them to append to a parent. This is controlled through a stack where you can push and pop parents and by using <strong>etag</strong> the tag is appended in the last pushed parent. The concept and api are simple, but can help a lot when creating dynamic number of elements.</p>
<p>So let&#8217;s see how can this be help full when creating a table of something</p>
<pre class="brush: php; title: ; notranslate">
tag('table')-&amp;gt;push_parent(); // This make tag table the active parent

foreach($products as $product)
{   etag('tr')-&amp;gt;push_parent();  // We use etag to append it to current
                                // parent and then push this to make it active parent
    etag('td', $product-&amp;gt;id);
    etag('td', $product-&amp;gt;name);
    etag('td', $product-&amp;gt;price);
    HTMLTag::pop_parent();      // Pop tr parent
}
echo HTMLTag::pop_parent();  // Pop table and echo it
</pre>
<p>This can be very helpful when creating nested formats, permitting to change parent or child structure without need to rewrite code of the affected ones. The source is also much cleaner and smaller than moving around variables and using append() for each tag.</p>
<h3>I have a dream&#8230;</h3>
<p>HTMLTag is more useful for me than the other solutions, but it is not what I really want and there is a lot of work before it is complete. What I am still missing is DOM features, although HTMLTag is DOM-like it misses all the good stuff like XPath etc. There is also a project named <a href="http://code.google.com/p/phpquery/">phpquery</a> which can work on DOM trees to select nodes using CSS3 rules, very much like jQuery, this however can&#8217;t work with HTMLTag unless it is converted to really DOMElement objects.</p>
<p>There are also sometimes that you want pure static html but it needs to interact with dynamic html like appending it to a object. The only way to do it is by creating static html using HTMLTag objects element by element, and this is an overkill. There should be a way to parse small chunks of html or even complete documents, like DOM does.</p>
<p>What I am thinking is make HTMLTag a wrapper arround DOMElement so that can have all features of HTMLTag and all features of DOMElement. This can be improved by implementing a way for even simpler dynamic object creation something like</p>
<pre class="brush: php; title: ; notranslate">$.TABLE(
     $.TR(
         $.TD('row 1 col 1'),
         $.TD(td', 'row 1 col 2')
     ),
     $.TR(
         $.TD('row 2 col 1'),
         $.TD('row 2 col 2')
     )
 );</pre>
<p>I am dreaming for HTML module that is a complete output device, injecting data directly from output buffer to html elements, or even directly parsing output buffer and creating trees. Searching replacing and modifying should be really trivial.</p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.kmfa.net/sque/2009/12/tinkering-with-tags/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Honly.gr is here!</title>
		<link>http://blogs.kmfa.net/sque/2009/12/honly-gr-is-here/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=honly-gr-is-here</link>
		<comments>http://blogs.kmfa.net/sque/2009/12/honly-gr-is-here/#comments</comments>
		<pubDate>Mon, 07 Dec 2009 12:40:19 +0000</pubDate>
		<dc:creator>sque</dc:creator>
				<category><![CDATA[Web Implementations]]></category>
		<category><![CDATA[dev]]></category>
		<category><![CDATA[portfolio]]></category>

		<guid isPermaLink="false">http://blogs.kmfa.net/sque/?p=21</guid>
		<description><![CDATA[The past two weeks we started a rapid development on HONLY, a place for greek players of Heroes of Newerth game. The initial goal was to design a site from the scratch, create a user database and integrate SimpleMachines forums in it. Well we did it, in record time! Dewfall did a great job designing [...]]]></description>
			<content:encoded><![CDATA[<p>The past two weeks we started a rapid development on <a href="http://www.honly.gr">HONLY</a>, a place for greek players of <a href="http://www.heroesofnewerth.com/">Heroes of Newerth</a> game. The initial goal was to design a site from the scratch, create a user database and integrate SimpleMachines forums in it. Well we did it, in record time!</p>
<div id="attachment_26" class="wp-caption alignleft" style="width: 236px"><img class="size-medium wp-image-26" src="http://blogs.kmfa.net/sque/files/2009/12/honly1-226x300.png" alt="Screenshot from the honly.gr website" width="226" height="300" /><p class="wp-caption-text">Screenshot from the honly.gr website</p></div>
<p><em>Dewfall</em> did a great job designing a gamish style that reminds a lot of HoN but still has its own personality. The style is based on dark colors which suits more for this game.</p>
<p>This was the first time I was focusing only on translating raster image to CSS properties, without worrying about style itself. I must admit that it was a lot easier and I had all the time that I needed to tweak more CSS files, and not bother trying to figure which colors fits better using my untalented mind.</p>
<p>Apart from design there is a big part of development. <a href="http://www.honly.gr">HONLY</a> will not be just a forum but it will be a set of applications that will help players, like the ladder, mods repository, signature etc. At first I though to implement everything with <a href="http://phplibs.kmfa.net">PHPLibs</a> but then it seemed an overkill to create a forum from the scratch. So I grabbed the latest SimpleMachines forum (2.0 RC2) and started working on integrating it.</p>
<p>There were many issues to solve, like url routing, authentication realm, search, theme etc. Although not all of them were implemented, it is now clear to me how to set up them. The first thing I did was to solve url routing and with phplibs <a href="http://phplibs.kmfa.net/api/@0.2/Stupid">Stupid system</a> it was like one line of code. Next I had to figure out how would be the UI consistent in forum and in the rest of the site, and this was the hard part for me. I search around on internet and nothing helped me, so I made a copy of the default &#8220;Curve&#8221; SMF Theme and starting playing with it.</p>
<p>SMF has a very simple template system, no mysterious markup language or files with unknown format, it was straight forward PHP, which for me was easy to read and change. I started from changing the CSS files and after changing over 150 rules the site started looking in proper colors. Then I focused on rewriting the header from the scratch, I reimplemented a much richer but more minimal login form, powered by jquery for some simple effects. The final website was exactly what <em>Dewfall</em> had designed and this made us happy with this work.</p>
<p><em>Bite</em> is the domain name inventor and will be the main moderator of the forum too. He has already started creating groups, boards , and testing any side of the forum. Friends of us have registered their self on the site and the user base started growing.</p>
<p>We hope greek HoN players to love it and use it.</p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.kmfa.net/sque/2009/12/honly-gr-is-here/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

