<?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>George Papayiannis &#187; Open Source</title>
	<atom:link href="http://www.sematopia.com/category/software-open-source/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.sematopia.com</link>
	<description></description>
	<lastBuildDate>Mon, 21 Nov 2011 23:18:07 +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>Apache: Stripping/Remove the www from URLS</title>
		<link>http://www.sematopia.com/2009/08/apache-strippingremove-the-www-from-urls/</link>
		<comments>http://www.sematopia.com/2009/08/apache-strippingremove-the-www-from-urls/#comments</comments>
		<pubDate>Wed, 19 Aug 2009 23:26:23 +0000</pubDate>
		<dc:creator>George A. Papayiannis</dc:creator>
				<category><![CDATA[Open Source]]></category>
		<category><![CDATA[PHP/MySQL]]></category>

		<guid isPermaLink="false">http://www.sematopia.com/?p=457</guid>
		<description><![CDATA[For reasons I won&#8217;t go into, I wanted to force Apache to strip the www from the URLs. So if someone typed in http://www.abc.com, Apache would automatically send them to http://abc.com. First thing to do is make sure ModRewrite is enabled, once that&#8217;s done simply put the following in your VirtualHost configuration or in the [...]]]></description>
			<content:encoded><![CDATA[<p>For reasons I won&#8217;t go into, I wanted to force Apache to strip the www from the URLs.  So if someone typed in http://www.abc.com, Apache would automatically send them to http://abc.com.  First thing to do is make sure ModRewrite is enabled, once that&#8217;s done simply put the following in your VirtualHost configuration or in the associated .htaccess file:</p>
<div class='code_parent'>
<div class='code_title'>Code:</div>
<div class='code_child'><code>
<div class='pre_container'>
<pre>RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.(.+)$
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]</pre>
</div>
<p></code></div>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.sematopia.com/2009/08/apache-strippingremove-the-www-from-urls/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>o&#8217;reilly: The GPL and Software as a Service</title>
		<link>http://www.sematopia.com/2007/08/oreilly-the-gpl-and-software-as-a-service/</link>
		<comments>http://www.sematopia.com/2007/08/oreilly-the-gpl-and-software-as-a-service/#comments</comments>
		<pubDate>Wed, 08 Aug 2007 17:33:43 +0000</pubDate>
		<dc:creator>George A. Papayiannis</dc:creator>
				<category><![CDATA[Open Source]]></category>

		<guid isPermaLink="false">http://www.sematopia.com/?p=201</guid>
		<description><![CDATA[I&#8217;ve never been a big fan of GPL. The license is too ambiguous and in certain cases may be open to interpretation. I was reading up on Sphinx and what it can do when it struck me: This license says nothing about using software as a service. A quick Google search confirmed my thought via [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve never been a big fan of GPL.  The license is too ambiguous and in certain cases may be open to interpretation.  I was reading up on <a href="http://www.sphinxsearch.com">Sphinx</a> and what it can do when it struck me: This license says nothing about using software as a service.  A quick Google search confirmed my thought via a <a href="http://radar.oreilly.com/archives/2007/07/the_gpl_and_sof_1.html">blog post by O&#8217;Reilly</a>:</p>
<blockquote><p>
..that free software license requirements to release source code are all triggered by the act of distribution, and that web applications, which are not actually &#8220;distributed,&#8221; are therefore not bound by these licenses..
</p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://www.sematopia.com/2007/08/oreilly-the-gpl-and-software-as-a-service/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Tech Talk: Dojo JavaScript Toolkit slides</title>
		<link>http://www.sematopia.com/2007/03/tech-talk-dojo-javascript-toolkit-slides/</link>
		<comments>http://www.sematopia.com/2007/03/tech-talk-dojo-javascript-toolkit-slides/#comments</comments>
		<pubDate>Thu, 01 Mar 2007 16:42:48 +0000</pubDate>
		<dc:creator>George A. Papayiannis</dc:creator>
				<category><![CDATA[Device UI]]></category>
		<category><![CDATA[IBM]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://www.sematopia.com/?p=175</guid>
		<description><![CDATA[I&#8217;m giving a tech talk today at work on a JavaScript Toolkit called Dojo. I made the slides based off of the dojo.book documentation. I uploaded the slides to Zoho, you can see them below. Hit the button in the bottom corner to maximize the presentation.]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m giving a tech talk today at work on a <a href="http://dojotoolkit.org/">JavaScript Toolkit called Dojo</a>.  I made the slides based off of the <a href="http://manual.dojotoolkit.org/WikiHome/DojoDotBook/BookIntroduction">dojo.book documentation</a>.  I uploaded the slides to Zoho, you can see them below.  Hit the button in the bottom corner to maximize the presentation.</p>
<p><iframe src="http://show.zoho.com/ViewURL.sas?USER=papayiya&#038;DOC=dojo-tech-talk-ppt&#038;IFRAME=yes" height='370' width='480' name="dojo-tech-talk-ppt" scrolling=no frameBorder='0' ></iframe></p>
]]></content:encoded>
			<wfw:commentRss>http://www.sematopia.com/2007/03/tech-talk-dojo-javascript-toolkit-slides/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>YUI: Blog, Library, Patterns, Theater</title>
		<link>http://www.sematopia.com/2007/02/yui-blog-library-patterns-theater/</link>
		<comments>http://www.sematopia.com/2007/02/yui-blog-library-patterns-theater/#comments</comments>
		<pubDate>Tue, 27 Feb 2007 21:24:47 +0000</pubDate>
		<dc:creator>George A. Papayiannis</dc:creator>
				<category><![CDATA[Corporate]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://www.sematopia.com/?p=171</guid>
		<description><![CDATA[I&#8217;m blown away at how &#8220;right&#8221; Yahoo is doing it. All too often I see corporation doing Open Source, but releasing some early, un-commented, buggy piece of crap to the public, while keeping the corporate version under wraps. Yahoo released their next version of the YUI Library the other day, this says it all: YUI [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m blown away at how &#8220;right&#8221; Yahoo is doing it.  All too often I see corporation doing Open Source, but releasing some early, un-commented, buggy piece of crap to the public, while keeping the corporate version under wraps.  Yahoo released their next version of the YUI Library <a href="http://yuiblog.com/blog/2007/02/20/yui-220-released/">the other day</a>, this says it all:</p>
<blockquote><p>
YUI was released internally at Yahoo! about six months before it was released for public use under a BSD license in February 2006. Although the internal and external versions of the library were identical, the way we built and distributed them was different and we managed those differences with separate versioning tracks. Today we’re merging the internal and external project versioning and reaffirming that the YUI you can download here is exactly the same YUI Library used all across Yahoo!. Hence, we’re retiring the old public version series (which had reached 0.12.2) and we’re unifying the versioning of this release at v2.2.0.</p></blockquote>
<p>Aside from the <a href="YUI Library">YUI Library</a> and <a href="Design Patterns">Patterns</a>, theirs great video tutorials from industry folks (<a href="YUI Theater">YUI Theater</a>), including a total of 10 videos by <a href="http://www.crockford.com/">Douglas Crockford</a> covering all aspects of JavaScript.</p>
<p><a href="http://yuiblog.com/">YUI Blog</a><br />
<a href="http://developer.yahoo.net/yui">YUI Library</a><br />
<a href="http://developer.yahoo.net/ypatterns">YUI Design Patterns</a><br />
<a href="http://developer.yahoo.com/yui/theater/">YUI Theater</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.sematopia.com/2007/02/yui-blog-library-patterns-theater/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Friday wrap-up #2</title>
		<link>http://www.sematopia.com/2006/10/friday-wrap-up-2/</link>
		<comments>http://www.sematopia.com/2006/10/friday-wrap-up-2/#comments</comments>
		<pubDate>Sat, 21 Oct 2006 02:58:08 +0000</pubDate>
		<dc:creator>George A. Papayiannis</dc:creator>
				<category><![CDATA[Friday]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[PHP/MySQL]]></category>

		<guid isPermaLink="false">http://www.sematopia.com/?p=154</guid>
		<description><![CDATA[CASCON was running this week from Monday to Thursday. I didn’t realize this was a free conference for everyone, including people outside IBM. I saw a bunch of professors from McMaster also, some were giving talks. I went to the Ruby on Rails workshop and it was going OK until one of the presenters starting [...]]]></description>
			<content:encoded><![CDATA[<p>CASCON was running this week from Monday to Thursday.  I didn’t realize this was a free conference for everyone, including people outside IBM.  I saw a bunch of professors from McMaster also, some were giving talks.</p>
<p>I went to the Ruby on Rails workshop and it was going OK until one of the presenters starting comparing Ruby on Rails (RoR) to PHP.  People need to get something straight: Ruby is the programming language and Rails is a framework.  Comparing RoR to PHP isn’t fair, since PHP is the programming language with no framework.  If you’re going to compare them, make sure your using some type of template engine like Smarty, etc. </p>
<p>Tuesday, Wednesday and Thursday I had a display at the Technology Showcase from 11:30am to 1:30pm, presenting <a href="http://www.sematopia.com/?p=151">WDSC and JWL</a>.  The experience was good, I met a lot of great people really interested in AJAX and JSF. </p>
<p>Doug Crockford is a smart guy, he&#8217;s a JavaScript guru and the creator of JSON.  Earlier this year he wrote a paper <a href="http://json.org/JSONRequest.html">describing JSONRequest</a>, here&#8217;s the abstract:</p>
<blockquote><p>XMLHttpRequest has a security model which is inadequate for supporting the next generation of web applications. JSONRequest is proposed as a new browser service that allows for two-way data exchange with any JSON data server without exposing users or organization to harm. It exchanges data between scripts on pages with JSON servers in the web. It is hoped that browser makers will build this feature into their products in order to enable the next advance in web application development.
</p></blockquote>
<p>It&#8217;s a good read and not a bad idea (though received a lot of criticism).  There has also been heavy discussion about this on the Dojo mailing list.  Doug&#8217;s <a href="http://javascript.crockford.com/">personal website</a> is filled with great JavaScript articles and resources &#8211; especially <a href="http://javascript.crockford.com/private.html">this article</a> on objects in JavaScript.</p>
<p>I read <a href="http://www.ics.uci.edu/~fielding/pubs/dissertation/rest_arch_style.htm">Chapter 5</a> of Roy Fielding&#8217;s dissertation, which introduced REST or Representational State Transfer.  REST is a lot like the Relational Database, conceptually its easy, but has the potential to revolutionize how we do certain things.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.sematopia.com/2006/10/friday-wrap-up-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How To: Making a PHP REST client to call REST resources</title>
		<link>http://www.sematopia.com/2006/10/how-to-making-a-php-rest-client-to-call-rest-resources/</link>
		<comments>http://www.sematopia.com/2006/10/how-to-making-a-php-rest-client-to-call-rest-resources/#comments</comments>
		<pubDate>Fri, 20 Oct 2006 21:36:27 +0000</pubDate>
		<dc:creator>George A. Papayiannis</dc:creator>
				<category><![CDATA[Open Source]]></category>
		<category><![CDATA[PHP/MySQL]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://www.sematopia.com/?p=153</guid>
		<description><![CDATA[A lot of companies these days (including Amazon and Yahoo!) are exposing their web services in the form of REST resources. At a high level REST is pretty easy to understand, all you&#8217;re doing is exposing a web service in the form of a URL. Users can then query this URL, through HTTP methods like [...]]]></description>
			<content:encoded><![CDATA[<p>A lot of companies these days (including <a href="http://aws.amazon.com">Amazon</a> and <a href="http://developer.yahoo.com/maps/rest/V1/geocode.html">Yahoo!</a>) are exposing their web services in the form of <a href="http://en.wikipedia.org/wiki/Representational_State_Transfer">REST resources</a>.  At a high level REST is pretty easy to understand, all you&#8217;re doing is exposing a web service in the form of a URL.  Users can then query this URL, through HTTP methods like GET and POST.  REST calls generally return some type of XML or Object Encoding like JSON.</p>
<p>An example would be <a href="http://developer.yahoo.com/maps/rest/V1/geocode.html">Yahoo!&#8217;s Geocoding API</a>, with the following URL:</p>
<div class='code_parent'>
<div class='code_title'>Code:</div>
<div class='code_child'><code>
<div class='pre_container'>
<pre>http://api.local.yahoo.com/MapsService/V1/geocode?appid=YahooDemo&#038;street=701+First+Street&#038;city=Sunnyvale&#038;state=CA</pre>
</div>
<p></code></div>
</div>
<p>I would get:</p>
<div class='code_parent'>
<div class='code_title'>Code:</div>
<div class='code_child'><code>
<div class='pre_container'>
<pre>&#60;Result precision="address">
   &#60;Latitude>37.416384&#60;/Latitude>
   &#60;Longitude>-122.024853&#60;/Longitude>
   &#60;Address>701 FIRST AVE&#60;/Address>
   &#60;City>SUNNYVALE&#60;/City>
   &#60;State>CA&#60;/State>
   &#60;Zip>94089-1019&#60;/Zip>
   &#60;Country>US&#60;/Country>
&#60;/Result></pre>
</div>
<p></code></div>
</div>
<p>So Yahoo! exposes the Geocode URL and allows you to query this resource using URL parameters like <strong>appid</strong> and <strong>street</strong>.  Dynamically building your URL to query a given resource is OK, generally that&#8217;s what people do, like the following:</p>
<div class='code_parent'>
<div class='code_title'>Code:</div>
<div class='code_child'><code>
<div class='pre_container'>
<pre>$base = 'http://xml.amazon.com/onca/xml3';
$query_string = "";

$params = array( 'ManufacturerSearch' => "O'Reilly",
    'mode'  => 'books',
    'sort'  => '+salesrank',
    'page'  => 1,
    'type'  => 'lite',
    'f'     => 'xml',
    't'     => 'trachtenberg-20' ,
    'dev-t' => 'XXXXXXXXXXXXXX' ,
);

foreach ($params as $key => $value) {
    $query_string .= "$key=" . urlencode($value) . "&#038;";
}

$url = "$base?$query_string";
$output = file_get_contents($url);</pre>
</div>
<p></code></div>
</div>
<p>The problem here, is that REST is meant to take advantage of HTTP methods GET, POST, PUT, DELETE, etc.. When people are showing examples which dynamically build queries and call file_get_contents, the average user doesn&#8217;t appreciate (understand) what type of request is being made.  Do they care?  Should they care?  We’ll that’s another story.  Eventually though, more intense REST resources will become widely available, and it will be critical the user (developer) understands if their making a POST or PUT request.</p>
<p>I came across a great PEAR package the other day called <a href="http://pear.php.net/package/HTTP_Request/">HTTP_REQUEST</a>, which among many things supports GET/POST/HEAD/TRACE/PUT/DELETE, basic authentication, proxy, proxy authentication, SSL, file uploads and more.  Using this package, I got started on a simple wrapper class called RESTclient, which gives intuitive support for making REST resource calls.</p>
<p>So if I was going to use RESTclient to call the Geocode API above, it would look like this:</p>
<div class='code_parent'>
<div class='code_title'>Code:</div>
<div class='code_child'><code>
<div class='pre_container'>
<pre>&#60;?php

require_once "RESTclient.php";

$rest = new RESTclient();

$inputs = array();
$inputs["appid"] = "YahooDemo";
$inputs["street"] = "701 First Street";
$inputs["city"] = "Sunnyvale";
$inputs["state"] = "CA";

$url = "http://api.local.yahoo.com/MapsService/V1/geocode/"
$rest->createRequest("$url","POST",$inputs);
$rest->sendRequest();
$output = $rest->getResponse();
echo $output;

?></pre>
</div>
<p></code></div>
</div>
<p>At this point, you might be thinking, who cares &#8212; what’s the difference between using a loop to dynamically generate the URL or RESTclient.  There are lots of reasons, first off, I can easily call the Geocode resource again using another address just by changing:</p>
<div class='code_parent'>
<div class='code_title'>Code:</div>
<div class='code_child'><code>
<div class='pre_container'>
<pre>$inputs["street"] = "1600 Amphitheatre Parkway";
$inputs["city"] = "Mountain View";</pre>
</div>
<p></code></div>
</div>
<p>There was no need to re-generate the URL.  Furthermore, I&#8217;m explicitly specifying a POST request.  Just as easily I can make a PUT, DELETE, etc. request on a given resource by changing the <strong>createRequest</strong> method parameters.</p>
<p>The class below is RESTclient.  Note, I put this together to prove a point, it still needs some work if you plan on using it.</p>
<div class='code_parent'>
<div class='code_title'>Code:</div>
<div class='code_child'><code>
<div class='pre_container'>
<pre>&#60;?php

require_once "HTTP/Request.php";

class RESTClient {

    private $root_url = "";
    private $curr_url = "";
    private $user_name = "";
    private $password = "";
    private $response = "";
    private $responseBody = "";
    private $req = null;

    public function __construct($root_url = "", $user_name = "", $password = "") {
        $this->root_url = $this->curr_url = $root_url;
        $this->user_name = $user_name;
        $this->password = $password;
        if ($root_url != "") {
            $this->createRequest("GET");
            $this->sendRequest();
        }
        return true;
    }

    public function createRequest($url, $method, $arr = null) {
        $this->curr_url = $url;
        $this->req =&#038; new HTTP_Request($url);
        if ($this->user_name != "" &#038;&#038; $this->password != "") {
           $this->req->setBasicAuth($this->user_name, $this->password);
        }        

        switch($method) {
            case "GET":
                $this->req->setMethod(HTTP_REQUEST_METHOD_GET);
                break;
            case "POST":
                $this->req->setMethod(HTTP_REQUEST_METHOD_POST);
                $this->addPostData($arr);
                break;
            case "PUT":
                $this->req->setMethod(HTTP_REQUEST_METHOD_PUT);
                // to-do
                break;
            case "DELETE":
                $this->req->setMethod(HTTP_REQUEST_METHOD_DELETE);
                // to-do
                break;
        }
    }

    private function addPostData($arr) {
        if ($arr != null) {
            foreach ($arr as $key => $value) {
                $this->req->addPostData($key, $value);
            }
        }
    }

    public function sendRequest() {
        $this->response = $this->req->sendRequest();

        if (PEAR::isError($this->response)) {
            echo $this->response->getMessage();
            die();
        } else {
            $this->responseBody = $this->req->getResponseBody();
        }
    }

    public function getResponse() {
        return $this->responseBody;
    }

}
?></pre>
</div>
<p></code></div>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.sematopia.com/2006/10/how-to-making-a-php-rest-client-to-call-rest-resources/feed/</wfw:commentRss>
		<slash:comments>35</slash:comments>
		</item>
		<item>
		<title>How to: Building dynamic PHP objects and URL decoding example</title>
		<link>http://www.sematopia.com/2006/10/how-to-building-dynamic-php-objects-and-url-decoding-example/</link>
		<comments>http://www.sematopia.com/2006/10/how-to-building-dynamic-php-objects-and-url-decoding-example/#comments</comments>
		<pubDate>Sat, 07 Oct 2006 04:10:54 +0000</pubDate>
		<dc:creator>George A. Papayiannis</dc:creator>
				<category><![CDATA[Open Source]]></category>
		<category><![CDATA[PHP/MySQL]]></category>
		<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://www.sematopia.com/?p=150</guid>
		<description><![CDATA[PHP is a powerful programming language; with every release I’m amazed with the new power and functionality. The ability to build dynamic objects (the way I’ll describe) I believe was introduced as of PHP 5. In any case, this is good stuff. There are lots of reasons why you would want to create a dynamic [...]]]></description>
			<content:encoded><![CDATA[<p>PHP is a powerful programming language; with every release I’m amazed with the new power and functionality.  The ability to build dynamic objects (the way I’ll describe) I believe was introduced as of PHP 5.  In any case, this is good stuff.  There are lots of reasons why you would want to create a dynamic object, in my example below; you’ll see how to create a dynamic object of the URL query parameters.</p>
<p>At the heart of building dynamic PHP objects are the PHP Magic Methods.  From the <a href="http://www.php.net/manual/en/language.oop5.magic.php">PHP manual</a>:</p>
<blockquote><p>The function names __construct, __destruct  (see Constructors and Destructors), __call, __get, __set, __isset, __unset  (see Overloading), __sleep, __wakeup, __toString, __set_state, __clone and __autoload  are magical in PHP classes. You cannot have functions with these names in any of your classes unless you want the magic functionality associated with them.</p></blockquote>
<p>Magic methods get called automatically through the parser when certain events occur.  For example, just before you transition pages all objects you’ve created will call their respective __sleep methods.  Most likely you wouldn’t have this method defined, so nothing would happen.</p>
<p>So now lets look at what happens when a certain method (or variable) of a given PHP object is called.  Take the following code as an example:</p>
<div class='code_parent'>
<div class='code_title'>Code:</div>
<div class='code_child'><code>
<div class='pre_container'>
<pre>$x = new obj();
$x->method1();
$x->var1;</pre>
</div>
<p></code></div>
</div>
<p>When a method of a given object is called (like method1) the first thing the parser does is look for the associated name in the instance of the object.  If the method is found, then the parser gives control to the method.  If the method is not found, then the __call function is called with the function name and input values as a parameter.  If this function returns true, then the object will return successfully.  If a __call function does not exist, the parser will check the parent class (if exists) and so forth.</p>
<p>Similarly, if a variable of an object is requested (like var1) the parser looks in the object for a variable with that name.  If a variable does not exist, the __get method is called with the name of the variable as a parameter, and so forth.</p>
<p>You should be able to see how we can now simulate (fake) the existence of methods and variables by using these magic methods.  The code below shows the parent class G_Dynamic.  This class would be the parent to specific subclasses that would require dynamic method/variable access.</p>
<div class='code_parent'>
<div class='code_title'>Code:</div>
<div class='code_child'><code>
<div class='pre_container'>
<pre>&#60;?php

/*  */

/**
 *
 * PHP versions 5.1.4
 *
 * George A. Papayiannis
 *
 * This class provides the magic functions needed to create
 * a dynamic object.  Subclasses would extend this object
 * and call the constructor with a parsed array.  See
 * g_url_decode.class.php for an example of creating a
 * dynamic object from the URL query string.
 *
 */

/**
 * Class definition
 */

class G_Dynamic {

    private $param = array();

    public function __construct($init) {
        $this->param = $init;
    }

    private function __get($name) {
        if (isset($this->param[$name])) {
            $res = $this->param[$name];
        } else {
            $res = false;
        }
        return $res;
    }

    private function __set($name, $val) {
        if (isset($this->param[$name])) {
            $this->param[$name] = $val;
            $res = true;
        } else {
            $res = false;
        }
        return $res;
    }

    private function __isset($name) {
        return isset($this->param[$name]);
    }

    private function __unset($name) {
        unset($this->param[$name]);
    }

    private function __call($name, $var) {
        // add code to simulate function call
        // return TRUE for success
    }

}

?></pre>
</div>
<p></code></div>
</div>
<p>As an example, I created a subclass to G_Dynamic called G_URL_Decode.  This class takes the URL query string as input, parses it into an array and calls the parents (G_Dynamic) constructor.  The code for G_URL_Decode is below:</p>
<div class='code_parent'>
<div class='code_title'>Code:</div>
<div class='code_child'><code>
<div class='pre_container'>
<pre>&#60;?php

/*  */

/**
 *
 * PHP versions 5.1.4
 *
 * George A. Papayiannis
 *
 * This class extends the G_Dynamic class to create a
 * dynamic object of the URL query string.  In another
 * file, you would have:
 *
 * require_once "g_url_decode.class.php";
 * $x = new G_URL_Decode($_SERVER['QUERY_STRING']);
 *
 * then you could have $x->(url param name) to access
 *
 */

require_once "g_dynamic.class.php";

/**
 * Class definition
 */

class G_URL_Decode extends G_Dynamic {

    private $queryParam = array();

    public function __construct($qs) {
         parent::__construct($this->parseURL($qs));
    }

    public function getQueryParam() {
        return $this->queryParam;
    }

    private function parseURL($qs) {
        $this->queryParam = array();
        $qs_parsed = explode("&#038;", $qs);
		foreach ($qs_parsed as $value) {
			$paramVal = explode("=",$value);
			if (array_key_exists(1,$paramVal)) {
				$this->queryParam[htmlspecialchars(urldecode($paramVal[0]))] = htmlspecialchars(urldecode($paramVal[1]));
			}
		}
		return $this->queryParam;
    }
}

?></pre>
</div>
<p></code></div>
</div>
<p>Once the URL query string is successfully parsed, you can access the parameter names through the object.  The code to bring it all together is below.</p>
<div class='code_parent'>
<div class='code_title'>Code:</div>
<div class='code_child'><code>
<div class='pre_container'>
<pre>&#60;?php

require_once "g_url_decode.class.php";
$x = new G_URL_Decode($_SERVER['QUERY_STRING']);
echo $x->var1;

?></pre>
</div>
<p></code></div>
</div>
<p>Using this as a base, you should be able to build some pretty cool dynamic objects.<br />
<a href="http://www.sematopia.com/upload/dynamic.rar">Click here</a> to download the source.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.sematopia.com/2006/10/how-to-building-dynamic-php-objects-and-url-decoding-example/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>SemCodeFix: A plugin to display preformatted code in WordPress</title>
		<link>http://www.sematopia.com/2006/09/semcodefix-a-plugin-to-display-preformatted-code-in-wordpress/</link>
		<comments>http://www.sematopia.com/2006/09/semcodefix-a-plugin-to-display-preformatted-code-in-wordpress/#comments</comments>
		<pubDate>Sun, 17 Sep 2006 02:44:34 +0000</pubDate>
		<dc:creator>George A. Papayiannis</dc:creator>
				<category><![CDATA[Open Source]]></category>
		<category><![CDATA[PHP/MySQL]]></category>

		<guid isPermaLink="false">http://www.sematopia.com/?p=138</guid>
		<description><![CDATA[SemCodeFix is a WordPress plugin I made to display preformatted code correctly. This plugin can display any type of code, html, text, scripts, etc. Using the plugin is easy, just wrap your text in a code tag from within the WordPress editor. Here&#8217;s an example of what it would look like. The code below is [...]]]></description>
			<content:encoded><![CDATA[<p>SemCodeFix is a WordPress plugin I made to display preformatted code correctly.  This plugin can display any type of code, html, text, scripts, etc.  Using the plugin is easy, just wrap your text in a code tag from within the WordPress editor.  Here&#8217;s an example of what it would look like.  The code below is Python, its a solution to the <a href="http://en.wikipedia.org/wiki/Eight_queens_puzzle">Eight queens puzzle</a>.</p>
<div class='code_parent'>
<div class='code_title'>Code:</div>
<div class='code_child'><code>
<div class='pre_container'>
<pre>
def n_queens(n, width):
    if n == 0:
        return [[]] # one solution, the empty list
    else:
        return add_queen(n-1, width, n_queens(n-1, width))

def add_queen(new_row, width, previous_solutions):
    solutions = []
    for sol in previous_solutions:
        for new_col in range(width):
            if safe_queen(new_row, new_col, sol):
                solutions.append(sol + [new_col])
    return solutions

def safe_queen(new_row, new_col, sol):
    for row in range(new_row):
        if (sol[row] == new_col or  # same column clash
            sol[row] + row == new_col + new_row or  # diagonal clash
            sol[row] - row == new_col - new_row):   # other diagonal
                return 0
    return 1

for sol in n_queens(8, 8):
   print sol
</pre>
</div>
<p></code></div>
</div>
<p>To activate/use this plugin, do the following:</p>
<p>1. Place the plugin file in the plugin directory of your WordPress installation and activate it.<br />
2. Copy and paste the CSS into your local.css file of your theme&#8217;s directory.<br />
3. Depending on your theme, your might want to change the <em><strong>width</strong></em> value in the <em><strong>div.code_child</strong></em> css style.<br />
4. Any code you have, just wrap it in a <em><strong>code</strong></em> tag from within the editor.</p>
<p>When installed, the plugin will override the native code styles of your theme and display output as above.<br />
Download the <a href="http://www.sematopia.com/wp-content/uploads/2006/09/sem-code-fix.php.txt">plugin file</a><br />
Download the <a href="http://www.sematopia.com/wp-content/uploads/2006/09/sem-code-fix.css.txt">CSS file</a></p>
<p>Good luck</p>
]]></content:encoded>
			<wfw:commentRss>http://www.sematopia.com/2006/09/semcodefix-a-plugin-to-display-preformatted-code-in-wordpress/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>Comet: Life after AJAX</title>
		<link>http://www.sematopia.com/2006/08/comet-life-after-ajax/</link>
		<comments>http://www.sematopia.com/2006/08/comet-life-after-ajax/#comments</comments>
		<pubDate>Tue, 08 Aug 2006 20:13:49 +0000</pubDate>
		<dc:creator>George A. Papayiannis</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://www.sematopia.com/?p=118</guid>
		<description><![CDATA[There is no doubt that AJAX is a brilliant idea, which has pushed web development to a new level. That said, the framework has many limitations, and a lot of big time names in the open source industry (Alex Russel being one of them) have taken notice. People that don&#8217;t understand Comet call it &#8220;disgruntled [...]]]></description>
			<content:encoded><![CDATA[<p>There is no doubt that AJAX is a brilliant idea, which has <em>pushed</em> web development to a new level.  That said, the framework has many limitations, and a lot of big time names in the open source industry (<a href="http://alex.dojotoolkit.org/?p=545">Alex Russel</a> being one of them) have taken notice.  People that don&#8217;t understand Comet call it &#8220;disgruntled AJAX developers who went off on their own&#8221;.  The reality is, that a server-side event driven model for web development is needed.  The catch?  A long-lived static connection from the client-side (browser) to the server is needed.  For example, this event driven server-side model, means that the server can now tell the client to refresh a panel on demand (without the client making a request).</p>
<p>On Sunday, the Dojo Foundation <a href="http://blog.dojotoolkit.org/2006/08/06/cometd-new-dojo-project">announced</a> <a href="http://www.cometd.com/">Cometd</a> as a new Dojo project.</p>
<blockquote><p>Cometd is a scalable HTTP-based event routing bus that uses a push technology pattern known as Comet.</p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://www.sematopia.com/2006/08/comet-life-after-ajax/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Dojo: A glimpse into the future of web development</title>
		<link>http://www.sematopia.com/2006/08/dojo-a-glimpse-into-the-future-of-web-development/</link>
		<comments>http://www.sematopia.com/2006/08/dojo-a-glimpse-into-the-future-of-web-development/#comments</comments>
		<pubDate>Thu, 03 Aug 2006 19:11:52 +0000</pubDate>
		<dc:creator>George A. Papayiannis</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://www.sematopia.com/?p=117</guid>
		<description><![CDATA[Update (Aug. 17 2006): The more I use Dojo, the more impressed I am with what is being done. The entire project has so much attention to detail. I just spent a little while looking at dojo.io.* and am blown away at this easy to use, transparent approach to AJAX. That’s a powerful title, will [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Update</strong> (Aug. 17 2006): The more I use Dojo, the more impressed I am with what is being done.  The entire project has so much attention to detail.  I just spent a little while looking at dojo.io.* and am blown away at this easy to use, transparent approach to AJAX.</p>
<p>That’s a powerful title, will it come true?  Who knows.  At this moment and time, at version 0.3, Dojo is insanely impressive.<br />
So the first question that most people will have is: What is Dojo?</p>
<blockquote><p>Dojo is the Open Source Javascript toolkit that makes professional web development better, easier, and faster</p></blockquote>
<p>A little more detail:</p>
<blockquote><p>Dojo is an Open Source DHTML toolkit written in JavaScript. It builds on several contributed code bases (nWidgets, Burstlib, f(m)), which is why we refer to it sometimes as a &#8220;unified&#8221; toolkit. Dojo aims to solve some long-standing historical problems with DHTML which prevented mass adoption of dynamic web application development.</p>
<p>Dojo allows you to easily build dynamic capabilities into web pages and any other environment that supports JavaScript sanely. You can use the components that Dojo provides to make your web sites more useable, responsive, and functional. With Dojo you can build degradeable user interfaces more easily, prototype interactive widgets quickly, and animate transitions. You can use the lower-level APIs and compatibility layers from Dojo to write portable JavaScript and simplify complex scripts. Dojo&#8217;s event system, I/O APIs, and generic language enhancement form the basis of a powerful programming environment</p></blockquote>
<p>I hear people say &#8220;Dojo, that’s the AJAX framework&#8221;.  Sure, Dojo is about asynchronous interaction, but that’s only a part of the story.  The problem with JavaScript is that it blew up way too fast.  It’s a powerful programming language, but lacks the subtleties, which would make it easy to develop large-scale JavaScript applications.  I doubt in the mid 90s Netscape envisioned JavaScript the way its used today.  In 2002, Doug Crockford got fed up and made JSLint:</p>
<blockquote><p>When C was a young programming language, there were several common programming errors that were not caught by the primitive compilers, so an accessory program called lint  was developed which would scan a source file, looking for problems.  As the language matured, the definition of the language was strengthened to eliminate some insecurities, and compilers got better at issuing warnings. lint is no longer needed.</p>
<p>JavaScript is a young language. It was originally intended to do small tasks in webpages, tasks for which Java was too heavy and clumsy. But JavaScript is a very capable language, and it is now being used in larger projects. Many of the features that were intended to make the language easy to use are troublesome for larger projects. A lint for JavaScript is needed: JSLint, a JavaScript syntax checker and validator.
</p></blockquote>
<p>The good folks at Dojo have taken this a massive step further, put very gently:</p>
<blockquote><p>dojo.lang.* contains wrappers for common idioms. It doesn&#8217;t provide replacements for language constructs. We only provide functions that provide value-added above the standard javascript routines, or functions that mask browser incompatibilites, etc.</p></blockquote>
<p>The reality is, an amazing, transparent, useful framework has been (is being) developed, which will give the Web developer power they’ve only dreamt of.  Were talking proper class constructs, inheritance, the ability to override methods, and much more.</p>
<p>In total there is the Dojo Infrastructure (fundamental behaviors), General purpose libraries (String manip., DOM manip., etc…), Data Structures (Dictionary, ArrayList, Queue, etc..), Web I/O (RPC, JSON, etc.), Visual Web (animations, graphics, etc.), Math and Cryptogrpahy (speaks for itself.. clientside Crypto, like Meebo) and a great Widget library.</p>
<p>What kind of widgets are we looking at?  Here is a taste of what you can expect:</p>
<p><a href="http://www.sematopia.com/dojo/demos/widget/Fisheye.html">FisheyeList</a> – hover over the menu at the top…<br />
<a href="http://www.sematopia.com/dojo/tests/widget/test_Dialog3.html">Popup Dialogs</a> – click the links on the top left…<br />
<a href="http://www.sematopia.com/dojo/tests/widget/test_FloatingPane.html">Floating Pane</a> – drag them, close them.. the world is your oyster<br />
<a href="http://www.sematopia.com/dojo/tests/widget/test_InlineEditBox.html">Inline Edit Box</a> – just like Flikr, click the title and text…</p>
<p>All this, and their only in version 0.3.  Give it a try: <a href="http://www.dojotoolkit.com">dojotoolkit.com</a> &#8212; be warned documentation to the specifics of the API is sparse.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.sematopia.com/2006/08/dojo-a-glimpse-into-the-future-of-web-development/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

