<?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>Query7 &#187; Prakash Mohanty</title>
	<atom:link href="http://query7.com/author/prakash/feed" rel="self" type="application/rss+xml" />
	<link>http://query7.com</link>
	<description>PHP, Javascript, Python and Web Development</description>
	<lastBuildDate>Sat, 25 Jun 2011 21:29:51 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.4</generator>
		<item>
		<title>Internationalization and Partial Rendering in the CodeIgniter Framework</title>
		<link>http://query7.com/internationalization-and-partial-rendering-in-the-codeigniter-framework</link>
		<comments>http://query7.com/internationalization-and-partial-rendering-in-the-codeigniter-framework#comments</comments>
		<pubDate>Mon, 06 Sep 2010 16:59:10 +0000</pubDate>
		<dc:creator>Prakash Mohanty</dc:creator>
				<category><![CDATA[Code Igniter]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[Zend]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[codeigniter]]></category>
		<category><![CDATA[localization]]></category>
		<category><![CDATA[multi-language]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[Zend Framework]]></category>

		<guid isPermaLink="false">http://www.webdevelopmentbits.com/?p=678</guid>
		<description><![CDATA[As experienced Web developers, it won’t shock you to find literally thousands of comparisons between CodeIgniter and the other popular frameworks you may be considering for your site. Each framework has its good and, ummm… less good points, but]]></description>
			<content:encoded><![CDATA[<p>As experienced Web developers, it won’t shock you to find literally thousands of comparisons between <a href="http://codeigniter.com/">CodeIgniter</a> and the other popular frameworks you may be considering for your site. Each framework has its good and, ummm… <em>less good </em>points, but let’s say you’re wedded to CodeIgniter for whatever reason, and you’ve got a few languages you’re tasked with supporting so you’re getting set to work on internationalization. So you go back and refresh your memory of just how to do that, and you begin coming across certain sites saying that CodeIgniter doesn&#8217;t support internationalization. So you begin to ponder ditching CodeIgniter, since you’re aces in a couple other frameworks, but that would be a mistake. CodeIgniter is a genius framework, and well optimized for so many other tasks that it’s worth sticking with. Plus, we have a nifty solution to your CodeIgniter internationalization issues.</p>
<p>If you’re going to be developing a multi-language site, then when you’re setting up your CMS, from the beginning be sure to go for a CodeIgniter CMS like CI-CMS or Pyro CMS in order to minimize languages issues down the road. {The <a href="http://www.zend.com/en/">Zend</a> framework, with its strong partial rendering, may seem like a better option in a pinch, but CodeIgniter trumps Zend in other crucial areas, so it’s worth sticking with.}</p>
<p>With CodeIgniter it makes great sense to build in modular separation (you can find the library <a href="http://maestric.com/doc/php/codeigniter_i18n">here</a>), though at first glace I’ll agree it looks like a tough implementation.</p>
<p>As you scan the library article, the lines to put most emphasis on will naturally deal with switching languages.</p>
<p>For example, you’ll find in the Notes section of the above library site:</p>
<pre>&lt;?php

anchor($this-&gt;lang-&gt;switch_uri('fr'),'Display current page in French');
$lang['about.gender'] = "Je suis un homme";

?&gt;</pre>
<p>Plug the lines below into your route.php and config.php files.</p>
<p>In config/route.php :</p>
<pre>&lt;?php

$route['^fr/(.+)$'] = "$1";

$route['^en/(.+)$'] = "$1";

// '/en' and '/fr' URIs -&gt; use default controller

$route['^fr$'] = $route['default_controller'];

$route['^en$'] = $route['default_controller'];

?&gt;</pre>
<p>In config/config.php,</p>
<p>$config['base_url']  must correspond to your configuration. For example,</p>
<pre>&lt;?php

$config['index_page'] = "";

?&gt;</pre>
<p>Creating the language file in system/application/language/english/about_lang.php was already clear to you.</p>
<pre>&lt;?php

$lang['about.gender'] = "I'm a man";
$lang['about.gender'] = "Je suis un homme";

?&gt;</pre>
<p>The controller part at</p>
<p>system/application/controllers/about.php should also be clear to you.</p>
<p>In the index function</p>
<pre>&lt;?php

$this-&gt;load-&gt;helper('language');

$this-&gt;load-&gt;helper('url');

// load language file‚

$this-&gt;lang-&gt;load('about');

$this-&gt;load-&gt;view('about');

?&gt;</pre>
<p>Once you&#8217;re done with these, browse to the welcome module on your local machine at http://localhost/ci/fr/welcome/test.<br />
You should find the language lines show up as expected.</p>
<p>Be sure to hit the CodeIgniter <a href="http://codeigniter.com/wiki/Language_Translation/">resource site</a> for some really useful, ready made down loadable translation files in zip format. This’ll save you heaps of time and work. Once you’ve extracted these zip archives, you’ll find files named as in the <em>about_lang.php </em>as above.</p>
<p>Next, while looking into partial rendering, we come across <a href="http://codeigniter.com/wiki/View_Object_PHP5/">this site</a>, which brings us more clarity.</p>
<pre>&lt;?php

$this-&gt;view-&gt;layout = 'master_layout_file'; // or leave this empty to render partials only

//Add a partial file and (optional) $data‚

$header = $this-&gt;view-&gt;load('header','header_file',$data);

// subheader‚

$header-&gt;load('sub_header','sub_header_file',$data);

$header-&gt;set($data);

$this-&gt;view-&gt;render();

?&gt;</pre>
<p>Now let’s render the partials in our master template:</p>
<pre>&lt;?php $header-&gt;render();?&gt;;</pre>
<p>And that&#8217;s about it. Pretty simple, right?</p>
<p>Before closing, just a brief note: PyroCMS is a multilingual CodeIgniter CMS with built-in language configuration options you can tailor to your site. You can find language settings inside the admin panel, and while the implementation will be similar to the approach we’ve outlined above it may not be an exact match.</p>
<p>Well, that&#8217;s it!  Thanks for reading, and I hope this helps.  If you have any questions about this specific tutorial or any other issues re: web development with CodeIgniter, Zend, or whatever else, drop us a line any time from our contact page!</p>
<p>Prakash R. Mohanty</p>
<p>Senior Software Engineer<br />
Sourcebits Technologies</p>
]]></content:encoded>
			<wfw:commentRss>http://query7.com/internationalization-and-partial-rendering-in-the-codeigniter-framework/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>HTML Email Compatibility Across Mail Clients</title>
		<link>http://query7.com/html-email-compatibility-across-mail-clients</link>
		<comments>http://query7.com/html-email-compatibility-across-mail-clients#comments</comments>
		<pubDate>Mon, 17 May 2010 00:29:25 +0000</pubDate>
		<dc:creator>Prakash Mohanty</dc:creator>
				<category><![CDATA[Best Practices]]></category>
		<category><![CDATA[Design]]></category>
		<category><![CDATA[Mail]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[CSS Table]]></category>
		<category><![CDATA[HTML mail]]></category>
		<category><![CDATA[Web Design]]></category>

		<guid isPermaLink="false">http://www.webdevelopmentbits.com/?p=573</guid>
		<description><![CDATA[<p style="text-align: center;"><a href="http://query7.com/wp-content/uploads/Screen-shot-2010-05-17-at-9.20.44-PM.png"><img class="size-full wp-image-578  aligncenter" title="Screen shot 2010-05-17 at 9.20.44 PM" src="http://query7.com/wp-content/uploads/Screen-shot-2010-05-17-at-9.20.44-PM.png" alt="" width="530" height="181" /></a></p>
<p>Lots of compatibility issues occur when HTML developers deal with HTML-formatted emails generated using server side languages like PHP, PERL, JAVA, etc. in their projects.</p>
<p>From time to time you’ll find the odd gobbledygooked message in your Web-based email app, but generally speaking HTML-formatted messages render flawlessly on the Web.  On the other hand, desktop mail clients such as Outlook on Windows, Mail.app on OS X, and the rainbow flavors of desktop Linux (Ubuntu, Centos, and so on) routinely have rendering issues with HTML-based email.</p>
<p>Despite the incredible advances in modern software, why does this continue to happen?</p>
<p>The answer is quite simple: certain mail clients ignore certain HTML tags.  Now there’s no universal rule as to which ignores what, but the more you code the more you’ll learn, so for now let’s take a look at one case with Outlook.</p>
<p>For many users, email ‘stationery’ conjures up late 90s memories of <a href="http://www.incredimail.com/english/splash.aspx">Incredimail</a> and a general, unsavory n00bishness.  But for marketing purposes a well-designed mail template, consisting of a stylish background image, thoughtful font selection, layout and copy equates to sales.  Perhaps thousands of people – from prospective clients to the media – will view mail&#8230;</p>]]></description>
			<content:encoded><![CDATA[<p style="text-align: center;"><a href="http://query7.com/wp-content/uploads/Screen-shot-2010-05-17-at-9.20.44-PM.png"><img class="size-full wp-image-578  aligncenter" title="Screen shot 2010-05-17 at 9.20.44 PM" src="http://query7.com/wp-content/uploads/Screen-shot-2010-05-17-at-9.20.44-PM.png" alt="" width="530" height="181" /></a></p>
<p>Lots of compatibility issues occur when HTML developers deal with HTML-formatted emails generated using server side languages like PHP, PERL, JAVA, etc. in their projects.</p>
<p>From time to time you’ll find the odd gobbledygooked message in your Web-based email app, but generally speaking HTML-formatted messages render flawlessly on the Web.  On the other hand, desktop mail clients such as Outlook on Windows, Mail.app on OS X, and the rainbow flavors of desktop Linux (Ubuntu, Centos, and so on) routinely have rendering issues with HTML-based email.</p>
<p>Despite the incredible advances in modern software, why does this continue to happen?</p>
<p>The answer is quite simple: certain mail clients ignore certain HTML tags.  Now there’s no universal rule as to which ignores what, but the more you code the more you’ll learn, so for now let’s take a look at one case with Outlook.</p>
<p>For many users, email ‘stationery’ conjures up late 90s memories of <a href="http://www.incredimail.com/english/splash.aspx">Incredimail</a> and a general, unsavory n00bishness.  But for marketing purposes a well-designed mail template, consisting of a stylish background image, thoughtful font selection, layout and copy equates to sales.  Perhaps thousands of people – from prospective clients to the media – will view mail on this template and associate it with your corporate brand, so perfection is key.</p>
<p style="text-align: center;"><img class="size-medium wp-image-579   aligncenter" title="Ye Gods!!  Incredimail!!! " src="http://www.webdevelopmentbits.com/wp-content/uploads/2010/05/back1-300x240.gif" alt="" width="248" height="199" /></p>
<p style="text-align: left;">Now let’s focus on the background image.  Many HTML developers will begin by putting CSS styles in the header of the HTML email directly, or when that fails try working around the problem using div tags and inline CSS.  But either way the results are borked.  Why?  Because Outlook ignores the CSS property “background-image”.</p>
<p style="text-align: left;">After so much trial and error, the solution we finally decided on was a pure table-based layout with inline CSS – with the CSS being restricted to each individual table cell since Outlook does not ignore those.  We’ve found this not only renders properly in Outlook, but all the other major desktop and Web clients, too.</p>
<p>And here&#8217;s how good it can look.</p>
<p style="text-align: center;"><a href="http://query7.com/wp-content/uploads/Image-xbox.png"><img class="size-full wp-image-580  aligncenter" title="Image-xbox" src="http://query7.com/wp-content/uploads/Image-xbox.png" alt="" width="539" height="746" /></a></p>
<p>For your reference, here are few examples of HTML tags that are compatible with almost all desktop and Web-based mail clients.</p>
<pre>&lt;table cellspacing="0" cellpadding="0" bgcolor="#6b6f7a"&gt;
    &lt;tr&gt;
        &lt;td width="55" height="53" valign="top"&gt;
            &lt;img src="http://domainname/media/mail/header_01.jpg" alt="" width="78" height="53" /&gt;
        &lt;/td&gt;
        &lt;td style="font-family: Arial,sans-serif;" width="546" bgcolor="#ffffff"&gt;&lt;/td&gt;
        &lt;td style="border-bottom: 1px solid #ffffff; padding: 0pt 15px; background-color: #b6d354; color: #ffffff; text-transform: uppercase; height: 43px; vertical-align: middle; font-size: 12px;"&gt;&lt;/td&gt;
    &lt;/tr&gt;
&lt;/table&gt;</pre>
<p>CSS style property -</p>
<pre>word-wrap: break-all;</pre>
<p>With the absence of a background tag, images can be used inside the</p>
<pre>&lt;table&gt;</pre>
<p>and</p>
<pre>&lt;td&gt;</pre>
<p>tags.</p>
<p>Happy HTML email  coding!!</p>
]]></content:encoded>
			<wfw:commentRss>http://query7.com/html-email-compatibility-across-mail-clients/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Using the keyword &quot;this&quot; in PHP</title>
		<link>http://query7.com/using-this-in-php</link>
		<comments>http://query7.com/using-this-in-php#comments</comments>
		<pubDate>Thu, 08 Jan 2009 16:09:39 +0000</pubDate>
		<dc:creator>Prakash Mohanty</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[object-oriented basics]]></category>

		<guid isPermaLink="false">http://www.webdevelopmentbits.com/?p=345</guid>
		<description><![CDATA[You may come across number of functions, variables inside a class, you
call each one them as object of the class.

The keyword “this” is used in a class in php , to call and use these objects as
shown in the example below.]]></description>
			<content:encoded><![CDATA[<p>You may have come across number of functions and variables inside a class and perhaps you don&#8217;t even know how they&#8217;re called or invoked. These functions and variables that belong to a class are called as properties and methods, or simply members, of this class.</p>
<p>In PHP, the keyword &#8220;<code>$this</code>&#8221; is used as a self reference of a class and you can use it for calling and using these properties and methods as shown in the example bellow.</p>
<p>Create a file ClassOne.php with code bellow:<br />
<code>&lt;?php</code></p>
<pre>
class ClassOne
{
    // this is a property of this class
    public $propertyOne;

    // When the ClassOne is instantiated, the first method called is
    // its constructor, which also is a method of the class
    public function __construct($argumentOne)
    {
        // this key word used here to assign
        // the argument to the class
        $this->propertyOne = $argumentOne;
    }

    // this is a method of the class
    function methodOne()
    {
        //this keyword also used here to use  the value of variable $var1
        return 'Method one print value for its '
             . ' property $propertyOne: ' . $this->propertyOne;
    }
}
</pre>
<p>In this class, we are also using the visibility declarations (public), which means whether the members are accessible on a subclass &#8211; we will discuss it later &#8211; or instance.<br />
Another thing you must be curious about is the use of &#8216;->&#8217;. This is an object pointer and, on PHP, it&#8217;s used for accessing members inside an object.</p>
<p>Now, let&#8217;s test your class! Create another file, called use.php with the following code:<br />
<code>&lt;?php</code></p>
<pre>
// include your class file
require_once 'ClassOne.php';

// Create an instance of your class
$classOneInstance = new ClassOne('Hello');

// And test it
print $classOneInstance->propertyOne . '&lt;br /&gt;';
print $classOneInstance->methodOne();
</pre>
<p>- Note that in both files we&#8217;re not using the enclosing PHP tags (?&gt;). Once they have only PHP code, it&#8217;s not needed and it&#8217;s also a good practice to avoid them on pure PHP files.</p>
]]></content:encoded>
			<wfw:commentRss>http://query7.com/using-this-in-php/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>HTTP Request without CURL</title>
		<link>http://query7.com/http-request-without-curl</link>
		<comments>http://query7.com/http-request-without-curl#comments</comments>
		<pubDate>Thu, 08 Jan 2009 09:46:37 +0000</pubDate>
		<dc:creator>Prakash Mohanty</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[HTTP Request]]></category>
		<category><![CDATA[no CURL]]></category>

		<guid isPermaLink="false">http://www.webdevelopmentbits.com/?p=340</guid>
		<description><![CDATA[<p>A short tutorial on how to make a simple object for HTTP request without the need of using CURL.<br />
The way to accomplish that is using the function <code>stream_context_create</code> to prepare the string, and then you use <code>fopen</code> and <code>stream_get_contents</code> to get the response.</p>
<p><code>&#60;?php</code></p>
<pre>
class Custom_Http_Request
{
    private $_url;
    private $_body;
    private $_method = 'POST';
    private $_headers = array();
    private $_response;
    private $_stream;

    public function __construct($url, $body)
    {
        if (empty($url) &#124;&#124; empty($body)) {
            throw new Exception('Both URL and BODY are required '
                              . 'for fetching the request.');
        }

        $this->_url  = $url;
        $this->_body = $body;
    }

    public function setMethod($method)
    {
        if ('POST' == $method &#124;&#124; 'GET' == $method) {
            $this->_method = $method;
            return $this;
        }

        throw new Exception('Invalid method set.');
    }

    public function addHeader(array $header)
    {
        if (!empty($header)) {
            $this->_headers[] = $header;
            return $this;
        }

        throw new Exception('The headers are empty.');
    }

    public function getMethod()
    {
        return $this->_method;
    }

    public function getBody()
    {
        return $this->_body;
    }

    public function getHeaders()
    {
        return $this->_headers;
    }

    public function getResponse()
    {
        if (is_null($this->_stream)) {
            $this->_openStream();
        }

        if (is_null($this->_response)) {
            $this->_response = @stream_get_contents($this->_stream);

            if (false === $this->_response) {
                throw new Exception('It is not possible to '
                                  . 'read from the response.');
            }
        }</pre><p>&#8230;</p>]]></description>
			<content:encoded><![CDATA[<p>A short tutorial on how to make a simple object for HTTP request without the need of using CURL.<br />
The way to accomplish that is using the function <code>stream_context_create</code> to prepare the string, and then you use <code>fopen</code> and <code>stream_get_contents</code> to get the response.</p>
<p><code>&lt;?php</code></p>
<pre>
class Custom_Http_Request
{
    private $_url;
    private $_body;
    private $_method = 'POST';
    private $_headers = array();
    private $_response;
    private $_stream;

    public function __construct($url, $body)
    {
        if (empty($url) || empty($body)) {
            throw new Exception('Both URL and BODY are required '
                              . 'for fetching the request.');
        }

        $this->_url  = $url;
        $this->_body = $body;
    }

    public function setMethod($method)
    {
        if ('POST' == $method || 'GET' == $method) {
            $this->_method = $method;
            return $this;
        }

        throw new Exception('Invalid method set.');
    }

    public function addHeader(array $header)
    {
        if (!empty($header)) {
            $this->_headers[] = $header;
            return $this;
        }

        throw new Exception('The headers are empty.');
    }

    public function getMethod()
    {
        return $this->_method;
    }

    public function getBody()
    {
        return $this->_body;
    }

    public function getHeaders()
    {
        return $this->_headers;
    }

    public function getResponse()
    {
        if (is_null($this->_stream)) {
            $this->_openStream();
        }

        if (is_null($this->_response)) {
            $this->_response = @stream_get_contents($this->_stream);

            if (false === $this->_response) {
                throw new Exception('It is not possible to '
                                  . 'read from the response.');
            }
        }

        return $this->_response;
    }

    private function _assemble()
    {
        $params = array(
        	'http' => array(
        		'method'  => $this->_method,
        		'content' => $this->_body
            )
        );

        if (!empty($this->_headers)) {
            $params['http']['header'] = $this->_headers;
        }

        return stream_context_create($params);
    }

    private function _openStream()
    {
        $this->_stream = <code>@fopen</code>($this->_url, 'rb', false, $this->_assemble());

        if (!$this->_stream) {
            throw new Exception('It was not possible to '
                              . "connect to {$this->_url}.");
        }
    }
}
</pre>
<p>More on this in my next post.</p>
]]></content:encoded>
			<wfw:commentRss>http://query7.com/http-request-without-curl/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

