<?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>Peter Törnstrand &#187; php</title>
	<atom:link href="http://www.tornstrand.com/category/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.tornstrand.com</link>
	<description>Drupal, PHP and web developing</description>
	<lastBuildDate>Fri, 16 Apr 2010 07:04:56 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>The Drupal module jungle</title>
		<link>http://www.tornstrand.com/2009/08/19/the-drupal-module-jungle/</link>
		<comments>http://www.tornstrand.com/2009/08/19/the-drupal-module-jungle/#comments</comments>
		<pubDate>Wed, 19 Aug 2009 13:00:14 +0000</pubDate>
		<dc:creator>peter</dc:creator>
				<category><![CDATA[cms]]></category>
		<category><![CDATA[drupal]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[modules]]></category>

		<guid isPermaLink="false">http://www.tornstrand.com/2009/08/19/the-drupal-module-jungle/</guid>
		<description><![CDATA[Drupal is a great CMS, during the time I have spent working with it I have come to love it. However, for an emerging Drupal developer the abundance of different modules can be a real hassel. Sometimes you need third party modules to perform simple tasks, such as getting the breadcrumb trail to work properly [...]]]></description>
			<content:encoded><![CDATA[<p>Drupal is a great CMS, during the time I have spent working with it I have come to love it. However, for an emerging Drupal developer the abundance of different modules can be a real hassel. Sometimes you need third party modules to perform simple tasks, such as getting the breadcrumb trail to work properly or to display a simple menu. Below you will find a list of modules I find indespensable when developing a Drupal web site. I have left out the modules <span style="font-style: italic">Views</span> and <span style="font-style: italic">CCK</span> since they are so vital to developing a Drupal site you are probably already using them.<span id="more-30"></span></p>
<h2>Administration</h2>
<p><a href="http://drupal.org/project/admin"><strong>Admin</strong></a><br />
Perhapse the mose confusing part when first starting to work with Drupal is the lack of a proper administration section. The &#8220;back end&#8221; of the web site in Drupal is an integrated part of the site itself. This probably has to do with Drupals history as a community system where all users were able to create content. This is however not the case, for the most parts, when I develop sites.</p>
<p>The module simply named <em>Admin</em> solves this problem and does it beautifully. <em>Admin</em> is developed as part of the new administration interface in Drupal 7. The module rearranges the default Drupal navigation menu and makes it more logical for administrators and also ships with a custom administation theme that makes the admin section of your web site look beautiful as well.</p>
<p><a href="http://drupal.org/project/admin_theme"><strong>Administration theme</strong></a><em><br />
Administration theme</em> is a module allowing you to use your selected administration theme on any page. Good for among other things to get the batch processing pages to display with the administration theme.</p>
<p><a href="http://drupal.org/project/better_formats"><strong>Better formats</strong></a><em><br />
Better formats</em> adds more flexibility to Drupal&#8217;s core input format system. It allows you to set default formats for different user roles and is pretty much a must have if you have more then one administrator/editor on your site.</p>
<p><a href="http://drupal.org/project/trash"><strong>Trash</strong></a><br />
This module adds a <em>trashcan</em> for nodes. Nodes can be moved to the trash instead of being deleted and thus can be restored or permanently deleted later on.</p>
<h2>Menus, breadcrumbs and taxonomy</h2>
<p><a href="http://drupal.org/project/menu_block"><strong>Menu block</strong></a><em><br />
Menu block</em> if a module for creating blocks displaying only parts of a specific menu. Say you want to display a menu only containing level 2+, then this module is for you.</p>
<p><a href="http://drupal.org/project/menu_breadcrumb"><strong>Menu breadcrumbs</strong></a><br />
By default, Drupal 6 will use the built in Navigation menu for the breadcrumb. This module allows you to use the menu the current page belongs to for the breadcrumb.</p>
<p><a href="http://drupal.org/project/taxonomy_breadcrumb"><strong>Taxonomy breadcrumb</strong></a><br />
The <em>Taxonomy breadcrumb</em> module generates taxonomy based breadcrumbs on node pages and taxonomy/term pages.</p>
<p><a href="http://drupal.org/project/taxonomy_forceall"><strong>Taxonomy force all</strong></a><br />
This module forces the paramter <var>all</var> to the taxonomy listing pages. This corrects the problem of empty pages when using hierarchical taxonomy terms.</p>
<h2>Editing and file management</h2>
<p><a href="http://drupal.org/project/wysiwyg"><strong>Wysiwyg</strong><strong> API</strong></a><em><br />
Wysiwyg API</em> module allows you to use client-side editors (a.k.a. WYSIWYG editors) to edit content in Drupal. It integrates your editor of choice (well, almost) with Drupal. Personally I almost always use <a href="http://tinymce.moxiecode.com/">TinyMCE</a>, a free editor by Moxiecode.</p>
<p><a href="http://drupal.org/project/imce"><strong>IMCE</strong></a><br />
IMCE is an image/file uploader and browser that supports personal directories and quota. It&#8217;s not the prettiest module out there but it gets the job done. This module can also be integrated with client-side editors to allow for a more intuitive image selection tool when creating or editing HTML content.</p>
<p>I use this module as a file manager and with a bit of tweaking you can get this module to integrate visually with the <em>Admin</em> module.</p>
<p><a href="http://drupal.org/project/imagecache"><strong>ImageCache</strong></a><em><br />
ImageCache</em> allows you to setup presets for image processing. If an <em>ImageCache</em> derivative doesn&#8217;t exist the web server&#8217;s rewrite rules will pass the request to Drupal which in turn hands it off to <em>ImageCache</em> to dynamically generate the file.</p>
<p>This is a must have module if you are using a lot of images in your content. It takes one image uploaded by the content creator and transforms it to exactly fit the desired dimensions.</p>
<h2>Utility</h2>
<p><a href="http://drupal.org/project/google_analytics"><strong>Google Analytics</strong></a><br />
Adds the Google Analytics web statistics tracking system to your website. Supports tracking of logged in users and outgoing links.</p>
<p><a href="http://drupal.org/project/backup_migrate"><strong>Backup and Migrate</strong></a><br />
Backup and Migrate simplifies the task of backing up and restoring your Drupal database or copying your database from one Drupal site to another. It supports gzip, bzip and zip compression as well as automatic scheduled backups.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.tornstrand.com/2009/08/19/the-drupal-module-jungle/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Reading a XML processing instruction with PHP</title>
		<link>http://www.tornstrand.com/2008/10/21/reading-a-xml-processing-instruction-with-php/</link>
		<comments>http://www.tornstrand.com/2008/10/21/reading-a-xml-processing-instruction-with-php/#comments</comments>
		<pubDate>Tue, 21 Oct 2008 15:56:36 +0000</pubDate>
		<dc:creator>peter</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[processing instruction]]></category>
		<category><![CDATA[xml]]></category>
		<category><![CDATA[xpath]]></category>
		<category><![CDATA[xsl]]></category>

		<guid isPermaLink="false">http://www.tornstrand.com/2008/10/21/reading-a-xml-processing-instruction-with-php/</guid>
		<description><![CDATA[I&#8217;m doing some XSL transformations in a project I&#8217;m involved in right now. The XML documents that are beeing transformed all include a xml-stylesheet processing instruction that I need to read in order to know what stylesheet to use for a specfic document. To my surprise, reading processing instructions from a DOMDocument in PHP was [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m doing some XSL transformations in a project I&#8217;m involved in right now. The XML documents that are beeing transformed all include a xml-stylesheet processing instruction that I need to read in order to know what stylesheet to use for a specfic document. To my surprise, reading processing instructions from a DOMDocument in PHP was not so easy as one might assume.</p>
<p><span id="more-29"></span>I wont go into details and tell you about all the hair (of which I have very little) I lost during my search for a way to get ahold of those processing instructions. In the end I used a XPath expression to select the PI. Below you&#8217;ll find the code I used.</p>
<p><code>$doc = new DOMDocument;<br />
$doc-&gt;load("document.xml");<br />
$xpath = new DOMXpath($doc);<br />
$nodes = $xpath-&gt;evaluate("/child::processing-instruction('xml-stylesheet')");<br />
if(!empty($nodes))<br />
$pi = $nodes-&gt;item(0);<br />
print $pi-&gt;target;<br />
print $pi-&gt;data;</code></p>
]]></content:encoded>
			<wfw:commentRss>http://www.tornstrand.com/2008/10/21/reading-a-xml-processing-instruction-with-php/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Zend_Form custom/localized error messages</title>
		<link>http://www.tornstrand.com/2008/06/27/zend_form-customlocalized-error-messages/</link>
		<comments>http://www.tornstrand.com/2008/06/27/zend_form-customlocalized-error-messages/#comments</comments>
		<pubDate>Fri, 27 Jun 2008 19:45:25 +0000</pubDate>
		<dc:creator>peter</dc:creator>
				<category><![CDATA[localization]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[zend framework]]></category>
		<category><![CDATA[zend_form]]></category>

		<guid isPermaLink="false">http://www.tornstrand.com/2008/06/27/zend_form-customlocalized-error-messages/</guid>
		<description><![CDATA[I&#8217;ve been playing around with Zend_Form and Zend Framework 1.5 these last couple of days. Like most people I hade some trouble getting used to the decorator part of the form API. Decorators are used to style form elements for rendering in the browser, adding tags before, after and wrapping the form element itself. After [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been playing around with <a href="http://framework.zend.com/manual/en/zend.form.html">Zend_Form</a> and <a href="http://framework.zend.com/">Zend Framework</a> 1.5 these last couple of days. Like most people I hade some trouble getting used to the decorator part of the form API. Decorators are used to style form elements for rendering in the browser, adding tags before, after and wrapping the form element itself. After much swearing I finally found <a href="http://devzone.zend.com/article/3450-Decorators-with-Zend_Form">this article</a> in the Zend Developer forums that did a pretty good job explaining it.</p>
<p>The next problem I ran into was customizing the form error messages, not just customizing the messages but also localizing them. The framework has default error messages defined for all validators you can use with your form elements but they are kind of stiff and I doubt anyone really want&#8217;s to use them. It turns out the solution is really simple.</p>
<p>To attach a validator to a form element you normally write something like this:</p>
<p><code>$textField = new Zend_Form_Element_Text("myField");<br />
$textField-&gt;addValidator(new Zend_Validate_NotEmpty());</code></p>
<p>If you want to customize the message and maybe even localize it you simply init a validator and manuelly set the message via the <em>setMessage</em> method, like this:</p>
<p><code>$notEmpty = new Zend_Validate_NotEmpty();<br />
$notEmpty-&gt;setMessage("You have to enter a value");<br />
$textField = new Zend_Form_Element_Text("myField");<br />
$textField-&gt;addValidator($notEmpty);</code></p>
<p>If you like to localize the error message, replace the setMessage call with:</p>
<p><code>$notEmpty-&gt;setMessage($this-&gt;getView()-&gt;translate("You have to enter a value"));</code></p>
<p>It&#8217;s just that simple <img src='http://www.tornstrand.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.tornstrand.com/2008/06/27/zend_form-customlocalized-error-messages/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>String localization with gettext and Zend Framework</title>
		<link>http://www.tornstrand.com/2008/03/29/string-localization-with-gettext-and-zend-framework/</link>
		<comments>http://www.tornstrand.com/2008/03/29/string-localization-with-gettext-and-zend-framework/#comments</comments>
		<pubDate>Sat, 29 Mar 2008 12:57:48 +0000</pubDate>
		<dc:creator>peter</dc:creator>
				<category><![CDATA[localization]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[gettext]]></category>
		<category><![CDATA[zend framework]]></category>

		<guid isPermaLink="false">http://www.tornstrand.com/2008/03/29/string-localization-with-gettext-and-zend-framework/</guid>
		<description><![CDATA[There&#8217;s a lot more to localizing a web site then just replacing strings with diffrent languages (for an exelent introduction read the ZF documentation on Zend_Locale). But in this post I will talk about string localization, and especially string localization using gettext and .mo-files with Zend Framework. The Zend Framework offers many ways for you [...]]]></description>
			<content:encoded><![CDATA[<p>There&#8217;s a lot more to localizing a web site then just replacing strings with diffrent languages (for an exelent introduction read the <a href="http://framework.zend.com/manual/en/zend.locale.html">ZF documentation on Zend_Locale</a>). But in this post I will talk about string localization, and especially string localization using <a href="http://www.gnu.org/software/gettext/">gettext</a> and .mo-files with <a href="http://framework.zend.com/">Zend Framework</a>.<span id="more-12"></span></p>
<p>The Zend Framework offers many ways for you to store your translated strings. It could be an array, a CSV or XML file or you could use gettext which we will be using in the examples below.</p>
<p>First you need an example application, it doesn&#8217;t need to be more complicated than a clean installation of ZF with a IndexController and a matching view, and of course the bootstrap.</p>
<p>Ok, so the first thing we will do is to load the <a href="http://framework.zend.com/manual/en/zend.translate.html">Zend_Translate</a> class in our bootstrap, load the language files, and save the object in the registry using <a href="http://framework.zend.com/manual/en/zend.registry.html">Zend_Registry</a>.</p>
<p><code>Zend_Loader::loadClass('Zend_Translate');<br />
Zend_Loader::loadClass('Zend_Registry');<br />
$translate = new Zend_Translate('gettext', './languages');<br />
$registry = Zend_Registry::getInstance();<br />
$registry-&gt;set('Zend_Translate', $translate);</code></p>
<p>Ok, so what we did here was to first load the classes that we need, the Zend_Translate and Zend_Registry classes. Next we create the Zend_Translate object and pass in the directory containing all of our different languages we will support in our application, in this case we will be supporting swedish and english language. Don&#8217;t worry about the language files, I will explain how you create those later on. Finally we save our Zend_Translate object to the registry so we don&#8217;t need to create our object over and over again in our application.</p>
<p>The next step is to dive into our applications views to identify the strings we want translated. In our example we only have one view, the index view of our IndexController. So let&#8217;s open that up and have a look at it.</p>
<p><code>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"&gt;<br />
&lt;html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"&gt;<br />
&lt;head&gt;<br />
&lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&gt;<br />
&lt;title&gt;Zend_Translate example&lt;/title&gt;<br />
&lt;/head&gt;<br />
&lt;body&gt;<br />
&lt;h1&gt;Hello World!&lt;/h1&gt;<br />
&lt;p&gt;This is a Zend_Translate demonstration&lt;/p&gt;<br />
&lt;/body&gt;<br />
&lt;/html&gt;<br />
</code></p>
<p>Here we have two strings that needs to be localized, so we wrap these strings in a call to the translate object.</p>
<p><code>&lt;h1&gt;&lt;?php echo $this-&gt;translate("Hello World!"); ?&gt;&lt;/h1&gt;<br />
&lt;p&gt;&lt;?php echo $this-&gt;translate("This is a Zend_Translate demonstration"); ?&gt;&lt;/p&gt;</code></p>
<p>Zend Framwork 1.5 ships with the Zend_View_Helper_Translate which makes translating strings easy, before you were forced to translate the strings in the controller or write your own translation view helper.</p>
<p>Now we have made all the modifications to our application that needs to be done to support string localization. Now it&#8217;s time to create our translation files, the  .mo-files. First thing you want to do is to download <a href="http://www.poedit.net/">Poedit</a>. Poedit is an application that helps you gather all the strings that should be translated from your application and presents them in a interface for you to translate. The program is open source and exists in versions for all major operating systems.</p>
<p>Lets fire up Poedit and try to import the strings. Click File -&gt; New catalogue and a settings windows should appear.</p>
<p><a href="http://www.tornstrand.com/wp-content/uploads/2008/03/poedit_settings.png" title="Poedit - Settings form"></a></p>
<p style="text-align: center"><a href="http://www.tornstrand.com/wp-content/uploads/2008/03/poedit_settings.png" title="Poedit - Settings form"><img src="http://www.tornstrand.com/wp-content/uploads/2008/03/poedit_settings.png" alt="Poedit - Settings form" /></a></p>
<p>Fill in the settings so it looks something like the above image. Then click the Paths tab.</p>
<p><a href="http://www.tornstrand.com/wp-content/uploads/2008/03/poedit_paths.png" title="Poedit - Paths"></a></p>
<p style="text-align: center"><a href="http://www.tornstrand.com/wp-content/uploads/2008/03/poedit_paths.png" title="Poedit - Paths"><img src="http://www.tornstrand.com/wp-content/uploads/2008/03/poedit_paths.png" alt="Poedit - Paths" /></a></p>
<p>Here you first enter the base path to your application and then you add the directories in your application that contains the files with the strings to be translated (your views). When your done click the Keywords tab.</p>
<p><a href="http://www.tornstrand.com/wp-content/uploads/2008/03/poedit_keywords.png" title="Poedit - Keywords"></a></p>
<p style="text-align: center"><a href="http://www.tornstrand.com/wp-content/uploads/2008/03/poedit_keywords.png" title="Poedit - Keywords"><img src="http://www.tornstrand.com/wp-content/uploads/2008/03/poedit_keywords.png" alt="Poedit - Keywords" /></a></p>
<p>Here you enter the name of the function you are calling to translate a string, in Zend Framework the function name is translate ($this-&gt;<strong>translate</strong>(&#8220;String&#8221;)).</p>
<p>When you&#8217;re done click OK. If your setup is anything like mine you will now encounter a error saying the catalogue update failed.</p>
<p><a href="http://www.tornstrand.com/wp-content/uploads/2008/03/poedit_error.png" title="Poedit - Error"></a></p>
<p style="text-align: center"><a href="http://www.tornstrand.com/wp-content/uploads/2008/03/poedit_error.png" title="Poedit - Error"><img src="http://www.tornstrand.com/wp-content/uploads/2008/03/poedit_error.png" alt="Poedit - Error" /></a></p>
<p>This was expected and happens because Poedit don&#8217;t know to look for strings in .phtml files that are used by Zend Framework. Click File -&gt; Preferences and click the tab Code readers. Select the PHP item and click Edit.</p>
<p><a href="http://www.tornstrand.com/wp-content/uploads/2008/03/poedit_php.png" title="Poedit - PHP settings"></a></p>
<p style="text-align: center"><a href="http://www.tornstrand.com/wp-content/uploads/2008/03/poedit_php.png" title="Poedit - PHP settings"><img src="http://www.tornstrand.com/wp-content/uploads/2008/03/poedit_php.png" alt="Poedit - PHP settings" /></a></p>
<p>Edit the settings so they reflect the settings in the picture above.</p>
<p>Now when you click update the strings that we wrapped in the translate function call should appear in Poedit in a list with the original strings to the left and the translations to the right. Get to work translating your strings and then save the catalogue. I&#8217;m keeping all my language files in a directory called languages in the web application root next to the library and application directories.</p>
<p>The application will automatically detects locale based on the HTTP_ACCEPT_LANGUAGE header sent by browsers. It will try to match the available languages to the users preffered language and if no match is made it will use the default language (the strings in your view files). You can customize this to use other methods but that&#8217;s out of the scope for this post.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.tornstrand.com/2008/03/29/string-localization-with-gettext-and-zend-framework/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>Garbeled data using PDO and MySQL</title>
		<link>http://www.tornstrand.com/2008/01/20/garbeled-data-using-pdo-and-mysql/</link>
		<comments>http://www.tornstrand.com/2008/01/20/garbeled-data-using-pdo-and-mysql/#comments</comments>
		<pubDate>Sun, 20 Jan 2008 15:00:43 +0000</pubDate>
		<dc:creator>peter</dc:creator>
				<category><![CDATA[databases]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[pdo]]></category>

		<guid isPermaLink="false">http://www.tornstrand.com/index.php/2008/01/20/garbeled-data-using-pdo-and-mysql/</guid>
		<description><![CDATA[Ran into some trouble the other day while emigrating a PHP solution from our development server to the production server. The application was working fine on the development server but once moved to the production server it started to behave strangely. Data returned from the datebase via stored procedures was contaning lots of garbeled data [...]]]></description>
			<content:encoded><![CDATA[<p>Ran into some trouble the other day while emigrating a PHP solution from our development server to the production server. The application was working fine on the development server but once moved to the production server it started to behave strangely.<span id="more-4"></span></p>
<p>Data returned from the datebase via stored procedures was contaning lots of garbeled data and results from previous select statments. So i turned to Google to find the answer to this strange behavior. Turns out this problem appears when executing a stored procedure contaning a <a href="http://dev.mysql.com/doc/refman/5.0/en/sqlps.html">PREPARE</a> statement. Why would one do this you might ask, well it has to do with MySQL inability to handle variables in the LIMIT clause. The only way to do paging with a stored procedure in MySQL is to use a PREPARE statement inside the procedure.</p>
<pre>DELIMITER $$
CREATE PROCEDURE paging (IN pageSize INT, IN position INT)
BEGIN
	PREPARE stmt FROM CONCAT("SELECT * FROM table LIMIT ", position ,", ", pageSize);
	EXECUTE stmt;
END $$
DELIMITER ;</pre>
<p>Since this problem only occured on the production server the solution was pretty clear, simply update MySQL and PHP to the latest stable releases and you&#8217;re fine.</p>
<p>Related links: <a href="http://bugs.mysql.com/bug.php?id=19008">Bug report on php.net</a>, <a href="http://bugs.mysql.com/bug.php?id=19008">Bug report on Mysql.com</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.tornstrand.com/2008/01/20/garbeled-data-using-pdo-and-mysql/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
