<?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>Notes Log &#187; Fixing</title>
	<atom:link href="http://noteslog.com/category/fixing/feed/" rel="self" type="application/rss+xml" />
	<link>http://noteslog.com</link>
	<description></description>
	<lastBuildDate>Sat, 15 May 2010 13:31:55 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>How to add events to a PHP project</title>
		<link>http://noteslog.com/post/how-to-add-events-to-a-php-project/</link>
		<comments>http://noteslog.com/post/how-to-add-events-to-a-php-project/#comments</comments>
		<pubDate>Sun, 28 Jun 2009 21:20:09 +0000</pubDate>
		<dc:creator>Andrea Ercolino</dc:creator>
				<category><![CDATA[Fixing]]></category>

		<guid isPermaLink="false">http://noteslog.com/?p=383</guid>
		<description><![CDATA[Here is a short class that will let you add events to a PHP project. The class EventManager defines a singleton, which you access with the EventManager::getInstance() expression. Here is the logic: bind a handler to an event: EventManager::getInstance()-&#62;bind( &#8216;event&#8217;, &#8216;handler&#8217; ) An event can be a string or a PHP regular expression. A handler must be a [...]]]></description>
			<content:encoded><![CDATA[<p>Here is a short class that will let you add events to a PHP project.</p>
<p>The class EventManager defines a singleton, which you access with the EventManager::getInstance() expression.</p>
<p><span id="more-383"></span>Here is the logic:</p>
<ol>
<li>bind a handler to an event: EventManager::getInstance()-&gt;bind( &#8216;event&#8217;, &#8216;handler&#8217; )<br />
An event can be a string or a PHP regular expression. A handler must be a PHP callable expression.</li>
<li>trigger an event: EventManager::getInstance()-&gt;trigger( &#8216;event&#8217; )<br />
A triggered event should be  a string. That string is going to be matched against all the bound events. Whenever a match is found, all the handlers bound to the matching events will be called. All the arguments passed to trigger will be passed along to the handlers. If a handler returns a false value, all other handlers won&#8217;t be called.</li>
</ol>
<p><pre><code class="php">class EventManager {
    
    /**
     * Singleton setup
     */
	static protected $_instance = null;
	protected function __construct() {}
	protected function __clone() {}
	static public function getInstance() {
		if (is_null( self::$_instance )) {
		    $class = __CLASS__;
			self::$_instance = new $class();
		}
		return self::$_instance;
	}
	
	
	/**
	 * Stores bindings between events and their handlers
	 *
	 * @var array
	 */
	protected $_bindings = array();
	
	
	/**
	 * Returns the id of the given $handler
	 *
	 * @param $handler a callable expression
	 * @return string
	 */
	protected function getId( $handler ) {
	    if (! is_callable( $handler )) {
	        throw new Exception('Expected a callable expression');
	    }
	    if (is_string( $handler )) {
	        $id = &quot;function: $handler&quot;;
	    } else {
	        $container = $hadler[0];
	        $method = $handler[1];
	        if (is_string( $container )) {
	            $class = $container;
	            $id = &quot;class: $class, method: $method&quot;;
	        } else {
	            $class = get_class( $container );
	            $object = spl_object_hash( $container );
	            $id = &quot;class: $class, object: $object, method: $method&quot;;
	        }
	    }
	    return $id;
	}
	
	
	/**
	 * Returns TRUE if the given $expression is a regular expression in PHP
	 * TODO improve EventManager::isRegExp by allowing matching delimiters (), [], {}, &lt;&gt;
	 *
	 * @param $regex
	 * @return boolean
	 */
	protected function isRegExp( $expression ) {
	    if (is_string( $expression ) &amp;&amp; preg_match( '/([^\w \\])[^\1\\\r\n]*(?:\\.[^\1\\\r\n]*)*\1/', $expression )) {
	        return true;
	    }
	    return false;
	}
	
	
	/**
	 * Binds a $handler to an $event
	 *
	 * @param string $event
	 * @param callable $handler
	 * @return EventManager
	 */
	public function bind( $event, $handler ) {
	    $id = $this-&gt;getId( $handler );
	    $this-&gt;_bindings[ $event ][ $id ] = $handler;
		return $this;
	}
	
	
	/**
	 * Unbinds a $handler from an $event
	 *
	 * @param string $event
	 * @param callable $handler
	 * @return EventManager
	 */
	public function unbind( $event, $handler = null ) {
		if (is_null( $handler )) {
			unset( $this-&gt;_bindings[ $event ] );
		} else {
		    $id = $this-&gt;getId( $handler );
    	    unset( $this-&gt;_bindings[ $event ][ $id ] );
		}
		return $this;
	}
	
	
	/**
	 * Dispatches a $triggered event to all its matching handlers
	 *
	 * @param string $triggered
	 * @return EventManager
	 */
	public function trigger( $triggered ) {
	    $result = true;
	    $args = func_get_args();
	    foreach ($this-&gt;_bindings as $event =&gt; $handlers) {
	        if ($this-&gt;isRegExp( $event )) {
    	        if (! preg_match( $event, $triggered )) {
    	            continue;
    	        }
	        } else {
	            if ($event != $triggered) {
	                continue;
	            }
	        }
    	    if (is_array( $handlers )) {
    			foreach ($handlers as $handler) {
    			    if (is_callable( $handler )) {
    			        $result = call_user_func_array( $handler, $args );
        				if (false === $result) {
        					break;
        				}
    			    }
    			}
    		}
    		if (false === $result) {
				break;
			}
	    }
		return $this;
	}
	
}</code></pre></p>
]]></content:encoded>
			<wfw:commentRss>http://noteslog.com/post/how-to-add-events-to-a-php-project/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>null is null or is not an object</title>
		<link>http://noteslog.com/post/null-is-null-or-is-not-an-object/</link>
		<comments>http://noteslog.com/post/null-is-null-or-is-not-an-object/#comments</comments>
		<pubDate>Wed, 29 Apr 2009 19:11:11 +0000</pubDate>
		<dc:creator>Andrea Ercolino</dc:creator>
				<category><![CDATA[Fixing]]></category>

		<guid isPermaLink="false">http://noteslog.com/?p=233</guid>
		<description><![CDATA[I stumbled upon this javascript error in IE7 today. Shouldn&#8217;t it be null is null and is not an object ?]]></description>
			<content:encoded><![CDATA[<p>I stumbled upon this javascript error in IE7 today.</p>
<p>Shouldn&#8217;t it be <strong>null is null and is not an object</strong> ?</p>
]]></content:encoded>
			<wfw:commentRss>http://noteslog.com/post/null-is-null-or-is-not-an-object/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>How to show a slow loading page</title>
		<link>http://noteslog.com/post/how-to-show-a-slow-loading-page/</link>
		<comments>http://noteslog.com/post/how-to-show-a-slow-loading-page/#comments</comments>
		<pubDate>Sun, 05 Apr 2009 22:52:59 +0000</pubDate>
		<dc:creator>Andrea Ercolino</dc:creator>
				<category><![CDATA[Fixing]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://noteslog.com/?p=343</guid>
		<description><![CDATA[Problem &#8211; Slow loading pages are frustrating, for web users and developers too. Of course there are many possible tweaks you can use to speed them up, but sometimes you cannot optimize a page any further. UPDATED 2009-10-11 Solution &#8211; If you can&#8217;t beat them, join them. You can show a progress indicator to let your [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Problem</strong> &#8211; Slow loading pages are frustrating, for web users and developers too. Of course there are many possible tweaks you can use to speed them up, but sometimes you cannot optimize a page any further.</p>
<ul>
<li>UPDATED 2009-10-11</li>
</ul>
<p><span id="more-343"></span></p>
<p><strong>Solution</strong> &#8211; If you can&#8217;t beat them, join them. You can show a progress indicator to let your web users know that your server is thinking hard the answer to their request, but how do you do that?</p>
<p><strong>Requirement 1</strong> &#8211; You cannot put the progress indicator on the leaving page, because you don&#8217;t want to modify every single reference to a slow page. It doesn&#8217;t make sense either: a slow page is slow by itself! You really don&#8217;t need that coupling.</p>
<p><strong>Requirement 2</strong> - You cannot put the progress indicator on the landing page, the slow one, because the browser needs it before the slow page has arrived. If they arrive together, the progress indicator is useless!</p>
<p>There is a <a href="http://www.aspnetpro.com/NewsletterArticle/2003/08/asp200308bm_l/asp200308bm_l.asp" target="_blank">good article</a> about this issue but it fails at implementing the first requirement. Anyway that was the idea I worked on when starting this project.</p>
<p>Here is the waiting page that get&#8217;s loaded while loading the slow page. For browsers other than IE, the trick is to change the document.location.href property after loading the <a href="http://ajaxload.info/" target="_blank">progress indicator</a> image. In IE we change the document.location.href and then add the image.</p>
<p>I used jQuery to make it simple.</p>
<p><strong>waiting.php</strong></p>
<p><pre class="chili-all"><code class="html">&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot; &quot;DTD/xhtml1-transitional.dtd&quot;&gt;

&lt;html xml:lang=&quot;en&quot; lang=&quot;en&quot; xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&gt;&lt;head&gt;

&lt;title&gt;Loading Page...&lt;/title&gt;

&lt;script type=&quot;text/javascript&quot; src=&quot;http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot;&gt;</code><code class="javascript">
jQuery( function( $ ) {
	function redirect() {
		$('form').submit();
	}
	
	if($.browser.msie) {
		redirect();
		$('img').appendTo('body').attr('src', 'loading-page.gif');
	} else {
		$('#loading').bind('load', function() {
	        redirect();
	    }).attr('src', 'loading-page.gif');
	}
} );
</code><code class="html">&lt;/script&gt;

&lt;/head&gt;&lt;body&gt;

&lt;h1&gt;Loading Page...&lt;/h1&gt;
&lt;img id=&quot;loading&quot; /&gt;
&lt;form method=&quot;&lt;?php </code><code class="php">echo $method </code><code class="html">?&gt;&quot; action=&quot;&lt;?php </code><code class="php">echo $url </code><code class="html">?&gt;&quot;&gt;
 &lt;input type=&quot;hidden&quot; name=&quot;waiting&quot; value=&quot;&lt;?php </code><code class="php">echo $waiting </code><code class="html">?&gt;&quot; /&gt;
&lt;/form&gt;

&lt;/body&gt;&lt;/html&gt;</code></pre>


</p>
<p>And here is the slow page.</p>
<p><strong>slow-page.php</strong></p>
<p><pre class="chili-all"><code class="html">&lt;?php
</code><code class="php">
if ( ! isset($_REQUEST['waiting']) ) {
    $url = htmlspecialchars( $_SERVER['REQUEST_URI'] );
	$method = $_SERVER['REQUEST_METHOD'];
	$waiting = time();
	include &quot;waiting.php&quot;;
    return;
}

sleep(10); //simulate a slow task

</code><code class="html">?&gt;

&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot; &quot;DTD/xhtml1-transitional.dtd&quot;&gt;

&lt;html xml:lang=&quot;en&quot; lang=&quot;en&quot; xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&gt;&lt;head&gt;
 &lt;title&gt;Slow Page&lt;/title&gt;
&lt;/head&gt;&lt;body&gt;
 &lt;h1&gt;Hello World!&lt;/h1&gt;
&lt;/body&gt;&lt;/html&gt;</code></pre>


</p>
<p>You can test it <a href="http://noteslog.com/personal/projects/page-loading/3/slow-page.php" target="_blank">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://noteslog.com/post/how-to-show-a-slow-loading-page/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Your PHP MySQL library version 5.0.51a differs from your MySQL server version 5.1.30</title>
		<link>http://noteslog.com/post/your-php-mysql-library-version/</link>
		<comments>http://noteslog.com/post/your-php-mysql-library-version/#comments</comments>
		<pubDate>Sat, 07 Feb 2009 21:31:30 +0000</pubDate>
		<dc:creator>Andrea Ercolino</dc:creator>
				<category><![CDATA[Fixing]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[WampServer]]></category>

		<guid isPermaLink="false">http://noteslog.com/?p=332</guid>
		<description><![CDATA[After installing WampServer 2.0f, the also installed phpMyAdmin 3.1.1 displays a notice at the bottom of the main page, saying: &#8220;Your PHP MySQL library version 5.0.51a differs from your MySQL server version 5.1.30&#8243;. I was experimenting some issues with Toad for MySQL, totally unrelated by the way and still to be solved, so I was [...]]]></description>
			<content:encoded><![CDATA[<p>After installing WampServer 2.0f, the also installed phpMyAdmin 3.1.1 displays a notice at the bottom of the main page, saying: &#8220;Your PHP MySQL library version 5.0.51a differs from your MySQL server version 5.1.30&#8243;.</p>
<p><span id="more-332"></span></p>
<p>I was experimenting some issues with Toad for MySQL, totally unrelated by the way and still to be solved, so I was sensitive to malfunctions, and decided to go through it.</p>
<p>The problem is that WampServer 2.0f installs MySQL 5.1.30 and PHP 5.2.8, which only supports MySQL 5.0.51a. So the only available solution, if you  want to stay with the last stable PHP version, is to downgrade MySQL to version 5.0.51a.</p>
<p>You can download and install a <a href="http://www.wampserver.com/en/addons_mysql.php" target="_blank">MySQL add on</a>, by using the menu option WampServer/MySQL/Version/Get more&#8230; Unfortunately, the installation does not end when the installer finishes. In fact you&#8217;ll need to manually configure your new database server.</p>
<p>Switch to it by using the menu option WampServer/MySQL/Version/5.0.51a, wait for the WampServer status icon to get back to white, and reload phpMyAdmin. Works? Mine didn&#8217;t. The problem is that the new MySQL server is still not configured and very empty.</p>
<ul>
<li>Switch back to the first server (5.1.30) and  export all your databases (don&#8217;t export information_schema nor mysql). Then switch to the second server (5.0.51a) for the last time.</li>
<li>Edit the file wamp/apps/phpmyadmin3.1.1/config.inc.php and remove the password.</li>
<li>Delete cookies and cache of the browser. This should be enough for allowing phpMyAdmin to load again.</li>
<li>Go to the Priviliges tab, and remove the users rows with production.mysql.com in them: they are garbage of this MySQL version.</li>
<li>Edit the user root/localhost and set a password.</li>
<li>Reload phpMyAdmin and check that it fails.</li>
<li>Edit again the file wamp/apps/phpmyadmin3.1.1/config.inc.php and insert the password.</li>
<li>Reload phpMyAdmin and check that it doesn&#8217;t fail.</li>
<li>Add new users/databases as needed.</li>
<li>Select each database and import its schema and data, from your previous exports.</li>
</ul>
<p>Done.</p>
]]></content:encoded>
			<wfw:commentRss>http://noteslog.com/post/your-php-mysql-library-version/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>How to cause a view refresh in jQuery</title>
		<link>http://noteslog.com/post/how-to-cause-a-view-refresh-in-jquery/</link>
		<comments>http://noteslog.com/post/how-to-cause-a-view-refresh-in-jquery/#comments</comments>
		<pubDate>Sat, 05 Jul 2008 13:05:57 +0000</pubDate>
		<dc:creator>Andrea Ercolino</dc:creator>
				<category><![CDATA[Fixing]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://noteslog.com/?p=216</guid>
		<description><![CDATA[$('body').width( $('body').width() - 1 ).width( $('body').width() + 1 );]]></description>
			<content:encoded><![CDATA[<p><pre><code class="javascript">$('body').width( $('body').width() - 1 ).width( $('body').width() + 1 );</code></pre></p>
]]></content:encoded>
			<wfw:commentRss>http://noteslog.com/post/how-to-cause-a-view-refresh-in-jquery/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to write a fast catch-all RegExp</title>
		<link>http://noteslog.com/post/how-to-write-a-fast-catch-all-regexp/</link>
		<comments>http://noteslog.com/post/how-to-write-a-fast-catch-all-regexp/#comments</comments>
		<pubDate>Sat, 17 May 2008 17:55:36 +0000</pubDate>
		<dc:creator>Andrea Ercolino</dc:creator>
				<category><![CDATA[Fixing]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[regular expression]]></category>

		<guid isPermaLink="false">http://noteslog.com/?p=208</guid>
		<description><![CDATA[In How to write a safe catch-all RegExp I suggested to use (?:\w&#124;\W)* for matching any character in a regular expression. It&#8217;s certainly true and safe, and the same stands for its siblings (?:\s&#124;\S)* and (?:\d&#124;\D)*. If you want to match a large text, these expressions are not the best. I&#8217;ve prepared a simple test [...]]]></description>
			<content:encoded><![CDATA[<p>In <a href="http://noteslog.com/post/how-to-write-a-safe-catch-all-regexp/" target="_self">How to write a safe catch-all RegExp</a> I suggested to use <strong><span style="color: #333399;">(?:\w|\W)*</span></strong> for matching any character in a regular expression. It&#8217;s certainly true and safe, and the same stands for its siblings <strong><span style="color: #333399;">(?:\s|\S)*</span></strong> and <strong><span style="color: #333399;">(?:\d|\D)*</span></strong>.</p>
<p>If you want to match a large text, these expressions are not the best. I&#8217;ve prepared a simple <a href="http://noteslog.com/personal/projects/regexp/test.html">test page</a> where the GeSHi&#8217;s engine file, which is almost 120KB, is going to be matched by the regular expression you input.</p>
<p>In Firefox 2 the performance is quite good, about 100 ms on my PC, but in Internet Explorer 7 it takes more than 7 minutes !!!</p>
<p>The best catch-all regular expression is <strong><span style="color: #333399;">[\w\W]*</span></strong>, which employs about 50 ms in FF2, and 0 ms in IE7 !!! (yes, zero milliseconds)</p>
]]></content:encoded>
			<wfw:commentRss>http://noteslog.com/post/how-to-write-a-fast-catch-all-regexp/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>WordPress Rendering Troubles</title>
		<link>http://noteslog.com/post/wordpress-rendering-troubles/</link>
		<comments>http://noteslog.com/post/wordpress-rendering-troubles/#comments</comments>
		<pubDate>Sat, 24 Nov 2007 22:41:59 +0000</pubDate>
		<dc:creator>Andrea Ercolino</dc:creator>
				<category><![CDATA[Fixing]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://noteslog.com/post/wordpress-rendering-troubles/</guid>
		<description><![CDATA[WordPress has many helpers that allow authors to write down some text and have it nicely formatted for their readers, without having to care about HTML issues. It&#8217;s a great job, but sometimes it doesn&#8217;t do the right thing. This bug affects content and custom fields, which means that it&#8217;s more of a conceptual bug [...]]]></description>
			<content:encoded><![CDATA[<p>WordPress has many helpers that allow authors to write down some text and have it nicely formatted for their readers, without having to care about HTML issues. It&#8217;s a great job, but sometimes it doesn&#8217;t do the right thing.</p>
<p>This bug affects content and custom fields, which means that it&#8217;s more of a conceptual bug than a coding bug. I wrote an <a href="http://noteslog.com/post/entity-enzyme-or-the-pacman-effect-strikes-back/">article</a> with a workaround for the content. Now, let&#8217;s see a simple fix for custom fields.</p>
<p>I&#8217;ll describe both problems I detected and give a solution based on changing some WordPress code. I know it&#8217;s not a perfect solution, but it works and it&#8217;s also relatively easy. In the snippets you&#8217;ll see the code as it&#8217;s supposed to get changed to. (with 3 lines of context before and after changed lines, each preceded by a <span style="text-decoration: underline;">//noteslog.com</span> comment)</p>
<p>WordPress Version: 2.3.1</p>
<h4>Problem: HTML Entities Conversion</h4>
<p>Custom fields that have HTML entities in their key or value are treated by WordPress weirdly. <a href="http://images.google.com/images?q=frustration&amp;hl=en&amp;rls=com.microsoft:en:IE-SearchBox&amp;rlz=1I7GGLJ&amp;um=1&amp;ie=UTF-8&amp;sa=X&amp;oi=images&amp;ct=title" target="_blank">Frustration</a> will appear soon after realizing that WordPress won&#8217;t return what you put in before.</p>
<p>If I write <span style="text-decoration: underline;">&amp;para;</span> inside the visual editor of a post, WordPress should assume that I want to visualize <span style="text-decoration: underline;">&amp;para;</span>. In fact it will pretend to do the right thing the first time I save the post. All subsequent times it will show a <span style="text-decoration: underline;">&para;</span> where I put a <span style="text-decoration: underline;">&amp;para;</span>.</p>
<p>If I write <span style="text-decoration: underline;">&amp;para;</span> inside the code editor of a post, WordPress should assume that I want to visualize <span style="text-decoration: underline;">&para;</span>, and it does the right thing (sort of, because I now have a <span style="text-decoration: underline;">&para;</span> inside the code too).</p>
<p>If I write <span style="text-decoration: underline;">&amp;para;</span> inside a custom field&#8217;s key or value, WordPress should assume that I want to visualize <span style="text-decoration: underline;">&para;</span> for my readers, and <span style="text-decoration: underline;">&amp;para;</span> for myself when I&#8217;m authoring the custom field. In fact WordPress does the wrong thing here again, because it&#8217;ll immediately convert <span style="text-decoration: underline;">&amp;para;</span> to <span style="text-decoration: underline;">&para;</span>.</p>
<h5>Solution</h5>
<p>This fix requires changing four lines in two files. We&#8217;ll use the PHP function <a href="http://php.net/manual/en/function.htmlspecialchars.php" target="_blank">htmlspecialchars</a> in place of the WordPress function <span style="text-decoration: underline;">attribute_escape</span>. After the fix, filters for <span style="text-decoration: underline;">&#8220;attribute_escape&#8221;</span> won&#8217;t get applied to custom fields keys and values. (this shouldn&#8217;t be a problem)</p>
<p><strong>Open</strong>: wp-admin/admin-ajax.php<br />
<strong>Search:</strong> function wp_ajax_meta_row<br />
<pre class="chili-all"><code class="php">add_action( 'shutdown', 'get_out_now', -1 );

function wp_ajax_meta_row( $pid, $mid, $key, $value ) {
//noteslog.com
	$value = htmlspecialchars( $value ); //attribute_escape($value);
	$key_js = addslashes(wp_specialchars($key, 'double'));
//noteslog.com
	$key = htmlspecialchars( $key ); //attribute_escape($key);
	$r .= &quot;&lt;tr id='meta-$mid'&gt;&lt;td valign='top'&gt;&quot;;
	$r .= &quot;&lt;input name='meta[$mid][key]' tabindex='6' onkeypress='return killSubmit(\&quot;theList.ajaxUpdater(&amp;#039;meta&amp;#039;,&amp;#039;meta-$mid&amp;#039;);\&quot;,event);' type='text' size='20' value='$key' /&gt;&quot;;
	$r .= &quot;&lt;/td&gt;&lt;td&gt;&lt;textarea name='meta[$mid][value]' tabindex='6' rows='2' cols='30'&gt;$value&lt;/textarea&gt;&lt;/td&gt;&lt;td align='center'&gt;&quot;;</code></pre></p>
<p><strong>Open</strong>: wp-admin/includes/template.php<br />
<strong>Search: </strong>function list_meta<br />
<pre class="chili-all"><code class="php">}

		$key_js = js_escape( $entry['meta_key'] );
//noteslog.com
		$entry['meta_key']   = htmlspecialchars($entry['meta_key']);//attribute_escape($entry['meta_key']);
//noteslog.com
		$entry['meta_value'] = htmlspecialchars($entry['meta_value']);//attribute_escape($entry['meta_value']);
		$entry['meta_id'] = (int) $entry['meta_id'];
		$r .= &quot;\n\t&lt;tr id='meta-{$entry['meta_id']}' class='$style'&gt;&quot;;
		$r .= &quot;\n\t\t&lt;td valign='top'&gt;&lt;input name='meta[{$entry['meta_id']}][key]' tabindex='6' type='text' size='20' value='{$entry['meta_key']}' /&gt;&lt;/td&gt;&quot;;</code></pre></p>
<h4>Problem: White Space Trimming</h4>
<p>Custom fields that begin or end with white space in their key or value are trimmed. I can undestand that a key is more easily dealt with if it is trimmed before saving it into the database. But values should definitely retain all their white space AS IS.</p>
<h5>Solution</h5>
<p>This fix requires changing four lines in three files. We&#8217;ll add a <span style="text-decoration: underline;">$trim</span> parameter to the wordpress function <span style="text-decoration: underline;">maybe_serialize</span>, by default set to <span style="text-decoration: underline;">true</span>. Wherever we do not want a <span style="text-decoration: underline;">$data</span> value trimmed, we&#8217;ll call <span style="text-decoration: underline;">maybe_serialize</span> with a <span style="text-decoration: underline;">false</span> second argument.</p>
<p><strong>Open</strong>: wp-includes/functions.php<br />
<strong>Search</strong>: function maybe_serialize<br />
<pre class="chili-all"><code class="php">return true;
}

//noteslog.com
function maybe_serialize($data, $trim=true) { //($data)
//noteslog.com
	if ( $trim &amp;&amp; is_string($data) ) //( is_string($data) )
		$data = trim($data);
	elseif ( is_array($data) || is_object($data) )
		return serialize($data);</code></pre></p>
<p><strong>Open</strong>: wp-admin/includes/post.php<br />
<strong>Search</strong>: function add_meta<br />
<pre class="chili-all"><code class="php">$metakeyselect = $wpdb-&gt;escape( stripslashes( trim( $_POST['metakeyselect'] ) ) );
	$metakeyinput = $wpdb-&gt;escape( stripslashes( trim( $_POST['metakeyinput'] ) ) );
//noteslog.com
	$metavalue = maybe_serialize( stripslashes( ( $_POST['metavalue'] ) ), false ); //( stripslashes( trim( $_POST['metavalue'] ) ) );
	$metavalue = $wpdb-&gt;escape( $metavalue );

	if ( ('0' === $metavalue || !empty ( $metavalue ) ) &amp;&amp; ((('#NONE#' != $metakeyselect) &amp;&amp; !empty ( $metakeyselect) ) || !empty ( $metakeyinput) ) ) {
		// We have a key/value pair. If both the select and the</code></pre></p>
<p><strong>Open</strong>: wp-admin/includes/post.php<br />
<strong>Search</strong>: function update_meta<br />
<pre class="chili-all"><code class="php">if ( in_array($mkey, $protected) )
		return false;

//noteslog.com
	$mvalue = maybe_serialize( stripslashes( $mvalue ), false ); //( stripslashes( $mvalue ) );
	$mvalue = $wpdb-&gt;escape( $mvalue );
	$mid = (int) $mid;
	return $wpdb-&gt;query( &quot;UPDATE $wpdb-&gt;postmeta SET meta_key = '$mkey', meta_value = '$mvalue' WHERE meta_id = '$mid'&quot; );</code></pre></p>
]]></content:encoded>
			<wfw:commentRss>http://noteslog.com/post/wordpress-rendering-troubles/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>How to fix the resize event in IE</title>
		<link>http://noteslog.com/post/how-to-fix-the-resize-event-in-ie/</link>
		<comments>http://noteslog.com/post/how-to-fix-the-resize-event-in-ie/#comments</comments>
		<pubDate>Sun, 23 Sep 2007 21:45:46 +0000</pubDate>
		<dc:creator>Andrea Ercolino</dc:creator>
				<category><![CDATA[Fixing]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://noteslog.com/post/how-to-fix-the-resize-event-in-ie/</guid>
		<description><![CDATA[In IE the window resize event is fired multiple times per actual resize: it is a well known issue for IE6 and IE7, but they misbehave along different patterns. Actually it seems that IE6 is worse than IE7. After quite a long session of R&#38;D, I&#8217;ve got to a pretty good solution, in the form [...]]]></description>
			<content:encoded><![CDATA[<p>In IE the window resize event is fired multiple times per actual resize: it is a well known issue for IE6 and IE7, but they misbehave along different patterns. Actually it seems that IE6 is worse than IE7.</p>
<p>After quite a long session of R&amp;D, I&#8217;ve got to a pretty good solution, in the form of a jQuery plugin: <a href="http://noteslog.com/personal/projects/wresize/1.1/jquery.wresize.js" target="_blank">jquery.wresize.js</a></p>
<p>/*  
===============================================================================
WResize is the jQuery plugin for fixing the IE window resize bug
...............................................................................
                                               Copyright 2007 / Andrea Ercolino
-------------------------------------------------------------------------------
LICENSE: http://www.opensource.org/licenses/mit-license.php
WEBSITE: http://noteslog.com/
===============================================================================
*/

( function( $ ) 
{
	$.fn.wresize = function( f ) 
	{
		version = '1.1';
		wresize = {fired: false, width: 0};

		function resizeOnce() 
		{
			if ( $.browser.msie )
			{
				if ( ! wresize.fired )
				{
					wresize.fired = true;
				}
				else 
				{
					var version = parseInt( $.browser.version, 10 );
					wresize.fired = false;
					if ( version < 7 )
					{
						return false;
					}
					else if ( version == 7 )
					{
						//a vertical resize is fired once, an horizontal resize twice
						var width = $( window ).width();
						if ( width != wresize.width )
						{
							wresize.width = width;
							return false;
						}
					}
				}
			}

			return true;
		}

		function handleWResize( e ) 
		{
			if ( resizeOnce() )
			{
				return f.apply(this, [e]);
			}
		}

		this.each( function() 
		{
			if ( this == window )
			{
				$( this ).resize( handleWResize );
			}
			else
			{
				$( this ).resize( f );
			}
		} );

		return this;
	};

} ) ( jQuery );</p>
<p>If you want to try it, here is a <a href="http://noteslog.com/personal/projects/wresize/1.1/test-wresize.html" target="_blank">test page</a>, where a div is automatically resized when the window is resized.</p>
<p><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" style="overflow:hidden;">
 <head>
  <title> test window resize </title>

<script type="text/javascript" src="http://jquery.com/src/jquery-latest.pack.js"></script>
<script type="text/javascript" src="jquery.wresize.js"></script>


<script type="text/javascript">
jQuery( function( $ ) 
{
	function content_resize() 
	{
		var w = $( window );
		var H = w.height();
		var W = w.width();
		$( '#content' ).css( {width: W-20, height: H-20} );
	}

	$( window ).wresize( content_resize );

	content_resize();
} );
</script>

 </head>

 <body>
 
<div id="content" style="border: 1px dashed silver; position:absolute; overflow:auto;">
test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test 
</div>

 </body>
</html></p>
<p>References:</p>
<blockquote><p><a href="http://dev.jquery.com/ticket/1625" target="_blank">http://dev.jquery.com</a><br />
<a href="http://snook.ca/archives/javascript/ie6_fires_onresize/" target="_blank"> http://snook.ca</a><br />
<a href="http://ecmascript.stchur.com/2006/08/20/beating-the-ie-resize-bug/" target="_blank"> http://ecmascript.stchur.com</a></p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://noteslog.com/post/how-to-fix-the-resize-event-in-ie/feed/</wfw:commentRss>
		<slash:comments>34</slash:comments>
		</item>
		<item>
		<title>How to write a safe RegExp for Opera</title>
		<link>http://noteslog.com/post/how-to-write-a-safe-regexp-for-opera/</link>
		<comments>http://noteslog.com/post/how-to-write-a-safe-regexp-for-opera/#comments</comments>
		<pubDate>Sat, 24 Feb 2007 11:01:04 +0000</pubDate>
		<dc:creator>Andrea Ercolino</dc:creator>
				<category><![CDATA[Fixing]]></category>
		<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://noteslog.com/?p=149</guid>
		<description><![CDATA[The PHP recipe for Chili contains a big regular expression (32862 chars) to account for the thousands of PHP functions. Internet Explorer and Firefox accept such a giant, but Opera does not. No way. It&#8217;s a problem at the core level. So the only solution, very simple though, is not to use a literal expression: [...]]]></description>
			<content:encoded><![CDATA[<p>The PHP recipe for Chili contains a big regular expression (32862 chars) to account for the thousands of PHP functions.</p>
<p>Internet Explorer and Firefox accept such a giant, but Opera does not. No way. It&#8217;s a problem at the core level. So the only solution, very simple though, is not to use a literal expression: use <code class="javascript">new RegExp( "..." );</code> instead of <code class="javascript">/.../</code>.</p>
<p>Remember to escape the expression for strings: for my recipe it was very simple because the step only contains a long list of words, between two word boundaries, which need an extra backslash.</p>
]]></content:encoded>
			<wfw:commentRss>http://noteslog.com/post/how-to-write-a-safe-regexp-for-opera/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Found the Culprit of the Pacman&#8217;s Effect</title>
		<link>http://noteslog.com/post/found-the-culprit-of-the-pacmans-effect/</link>
		<comments>http://noteslog.com/post/found-the-culprit-of-the-pacmans-effect/#comments</comments>
		<pubDate>Thu, 22 Feb 2007 12:22:50 +0000</pubDate>
		<dc:creator>Andrea Ercolino</dc:creator>
				<category><![CDATA[Fixing]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://noteslog.com/?p=147</guid>
		<description><![CDATA[Some time ago I wrote Entity enzyme, or The pacman effect strikes back. It was an article about the pacman effect of the ampersand in WordPress and how to try to solve it with a simple enzyme. Recently I&#8217;ve discovered that it&#8217;s an escaping / unescaping issue still unresolved in WordPress 2.1, and it&#8217;s somewhat [...]]]></description>
			<content:encoded><![CDATA[<p>Some time ago I wrote <a title="Permanent Link: Entity enzyme, or The pacman effect strikes back" rel="bookmark" href="http://noteslog.com/?p=83">Entity enzyme, or The pacman effect strikes back</a>. It was an article about the pacman effect of the ampersand in WordPress and how to try to solve it with a simple enzyme. Recently I&#8217;ve discovered that it&#8217;s an escaping / unescaping issue still unresolved in WordPress 2.1, and it&#8217;s somewhat nastier than I initially thought.</p>
<p>If you want to write HTML entity codes in a post, and you need to represent that of an ampersand for example (it&#8217;s <span style="text-decoration: underline;">&amp;amp;</span>), then there is no way to get it right. In fact, WordPress will always resolve an entity code.</p>
<p>Thus, if you write <span style="text-decoration: underline;">&amp;amp;</span>, you&#8217;ll get <span style="text-decoration: underline;">&amp;</span> after the first save roundtrip, and if you try to escape the <span style="text-decoration: underline;">&amp;</span> into <span style="text-decoration: underline;">&amp;amp;</span> with <span style="text-decoration: underline;">&amp;amp;</span>, obtaining <span style="text-decoration: underline;">&amp;amp;amp;</span> (this looks weird but it&#8217;s the way to do it in plain HTML), then the first time you save the post you get <span style="text-decoration: underline;">&amp;amp;</span> back, and the second time you save the post you get <span style="text-decoration: underline;">&amp;</span> back.</p>
<p>In general if you write <span style="text-decoration: underline;">&amp;</span> followed by any number of <span style="text-decoration: underline;">amp;</span> (like <span style="text-decoration: underline;">&amp;amp;amp;amp;amp;amp;amp;amp;</span>) then WordPress will make the <span style="text-decoration: underline;">&amp;</span> eat up an <span style="text-decoration: underline;">amp;</span> at each saving roundtrip, hence the pacman effect.</p>
<p>But the title of my previous post about this issue was &#8220;the pacman effect <span style="text-decoration: underline;">strikes back.</span>&#8221; In fact it&#8217;s not only a problem of the post content but also of the custom fields, thus corrupting the last resort we WordPress bloggers have for content AS IS. And this is where I get really upset.</p>
<p>Last tuesday I found the culprit and asked the wp-hackers list wether they considered it a bug or not. I&#8217;m still waiting for an answer, so I hope this post will help me to broaden the question and understand if I need to submit it to WordPress Trac or go in for a hack myself.</p>
<p></p>
]]></content:encoded>
			<wfw:commentRss>http://noteslog.com/post/found-the-culprit-of-the-pacmans-effect/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
