<?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>Always Right &#187; development</title> <atom:link href="http://www.stefanoforenza.com/category/development/feed/" rel="self" type="application/rss+xml" /><link>http://www.stefanoforenza.com</link> <description>Stefano Forenza - Personal Blog</description> <lastBuildDate>Tue, 31 Jan 2012 01:39:06 +0000</lastBuildDate> <language>en</language> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <generator>http://wordpress.org/?v=3.3.1</generator> <item><title>How to create Private (and moderated) Forums BuddyPress and BBPress</title><link>http://www.stefanoforenza.com/how-to-create-private-and-moderated-forums-buddypress-and-bbpress/</link> <comments>http://www.stefanoforenza.com/how-to-create-private-and-moderated-forums-buddypress-and-bbpress/#comments</comments> <pubDate>Wed, 04 Feb 2009 04:57:16 +0000</pubDate> <dc:creator>Stefano Forenza</dc:creator> <category><![CDATA[development]]></category> <category><![CDATA[php]]></category> <category><![CDATA[bbpress]]></category> <category><![CDATA[buddypress]]></category> <category><![CDATA[wordpress]]></category> <category><![CDATA[wordpress mu]]></category> <category><![CDATA[[HOW TO] get the damn thing working]]></category> <guid
isPermaLink="false">http://www.stefanoforenza.com/?p=290</guid> <description><![CDATA[If you develop on BuddyPress, you&#8217;re likely to get stuck while trying to get per-forum permissions. Indeed, it seems there&#8217;s not yet a way to make BBPress read the BuddyPress groups and hide the froums belonging to private  groups I had to develop a way myself. Furthermore, I needed to give forum moderation rights to [...]]]></description> <content:encoded><![CDATA[<p>If you develop on BuddyPress, you&#8217;re likely to get stuck while trying to get per-forum permissions.</p><p>Indeed, it seems there&#8217;s not yet a way to make BBPress read the BuddyPress groups and hide the froums belonging to private  groups I had to develop a way myself.</p><p>Furthermore, I needed to give forum moderation rights to the moderators of each group in BuddyPress on a per-forum basis.</p><p>This is a quick and dirty tutorial for future reference. Keep in mind I am using the bleeding edge (svn) versions of WordPress Mu, BuddyPress and BBPress.</p><p>At the end of this tutorial <strong>your BBpress will hide any forum associated with a non-public user group, and group moderators will have the needed  privileges in BBPress as well</strong> (without manual intervention).</p><p><strong>Note: </strong>I assume you <strong>already work</strong> with those three softwares and <strong>you know how</strong> to install them, install plugins, etc.</p><p><strong>First</strong>: install WordPress Mu 2.7 (it&#8217;s not stable yet, so you&#8217;ll have to get it somewhere from svn)</p><p><strong>Second:</strong> Install BuddyPress bleeding edge version on top of WordPress.</p><p><strong>Third:</strong> Download the svn version of BBPress and decompress it in a sub folder.</p><p><a
href="http://bbpress.org/forums/topic/wordpress-and-bbpress-integration-101">Be sure to properly integrate BBPress with WordPress</a>. (<a
href="http://jimgroom.org/bavawiki/index.php?title=Integrating_WPMu%2C_BuddyPress%2C_and_bbPress">further reading here</a>)</p><p>When you get everything working, download the <a
href="http://bbpress.org/plugins/topic/hidden-forums/">Hidden Forums plugin</a> and install it in BBPress.</p><p>Now, open the <em>hidden-forums/hidden-forums.php</em> file and replace everything from the top to the &#8220;<em>/*    stop  editing  here    */</em>&#8221; mark with:</p><pre>require_once( 'bp_integration.php' );</pre><p>When you&#8217;re done, create a new file named &#8220;<em>bp_integration.php</em>&#8221; in the same folder and copy paste the following code. Save everything, activate, and you&#8217;re done <img
src='http://www.stefanoforenza.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> .</p><pre>&lt;?php
//settings
global $bp;
$bp['groups']['table_name_groupmeta'] = 'wp_bp_groups_groupmeta';
$bp['groups']['table_name'] = 'wp_bp_groups';
$bp['groups']['table_name_members'] = 'wp_bp_groups_members';
$bp_integration_privileges = array(); //ids of forums the logged user can moderate
function bp_integration_apply_user_permissions()
{
    global $hidden_forums, $bb_current_user;
    global $bbdb, $bp;
    global $bp_integration_privileges;
    $query = "
    SELECT group.id as id, group.enable_forum as enable_forum, meta.meta_value as forum_id FROM `{$bp['groups']['table_name']}` as `group`
    INNER JOIN `{$bp['groups']['table_name_groupmeta']}` as meta
        ON group.id = meta.group_id AND meta.meta_key = 'forum_id' AND group.status != 'public'
    ";
    $private_groups = $bbdb-&gt;get_results( $query );
    $user_id=(!empty($bb_current_user)) ? intval($bb_current_user-&gt;ID) : 0;
    // hide these forums, list by comma seperated number
    $hidden_forums['hidden_forums']=array();
    foreach ( $private_groups as $group )
    {
        $hidden_forums['hidden_forums'][] = $group-&gt;forum_id;
    }
    $allowed_group = bp_integration_allowed_forums($user_id);
    $moderator_in = bp_integration_user_privileges($user_id);
    foreach ( $allowed_group as $allowed )
    {
        foreach ( $private_groups as $group )
        {
            if ( $group-&gt;id == $allowed-&gt;group_id &amp;&amp; $group-&gt;enable_forum )
            {
                $hidden_forums['allow_users'][$group-&gt;forum_id][] = $user_id;
            }
        }
    }
    foreach ( $moderator_in as $moderated )
    {
        foreach ( $private_groups as $group )
        {
            if ( $group-&gt;id == $moderated-&gt;group_id &amp;&amp; $group-&gt;enable_forum )
            {
                $bp_integration_privileges[] = $group-&gt;forum_id;
            }
        }
    }
    $hidden_forums['allow_roles']['all_forums']=array('keymaster');
    $hidden_forums['allow_users']['all_forums'] = array();
}
add_action('bb_init','bp_integration_apply_user_permissions',199);
function bp_integration_user_privileges ( $user_id, $limit = false, $page = false, $get_total = true, $as_col = false )
{
    global $bbdb, $bp;
    if ( $limit &amp;&amp; $page )
        $pag_sql = $bbdb-&gt;prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) );
			$group_sql = $bbdb-&gt;prepare( "
SELECT DISTINCT group_id
FROM " . $bp['groups']['table_name_members'] . "
WHERE user_id = %d AND inviter_id = 0 AND is_banned = 0
AND ( is_admin = 1 OR is_mod = 1 )
{$pag_sql}
", $user_id );
    return $paged_groups = $bbdb-&gt;get_results( $group_sql );
}
function bp_integration_allowed_forums( $user_id, $limit = false, $page = false, $get_total = true, $as_col = false ) {
		global $bbdb, $bp;
		if ( $limit &amp;&amp; $page )
			$pag_sql = $bbdb-&gt;prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) );
			$group_sql = $bbdb-&gt;prepare( "SELECT DISTINCT group_id FROM " . $bp['groups']['table_name_members'] . " WHERE user_id = %d AND inviter_id = 0 AND is_banned = 0{$pag_sql}", $user_id );
		return $paged_groups = $bbdb-&gt;get_results( $group_sql );
	}
function bp_integration_moderators_privileges ()
{
    global $bb_current_user, $forum,$topic_id;
    global $bp_integration_privileges;
    $args = func_get_args();
     $moderator_skills = array(
		'moderate' =&gt; true,
		'participate' =&gt; true,
		'manage_tags' =&gt; true,			//+
        /* ??!?! seems not work
		'delete_topics' =&gt; true,		//+
		'close_topics' =&gt; true,			//+
		'stick_topics' =&gt; true,			//+
		'move_topics' =&gt; false,			//+
         */
        /* ??!?! seems to work */
        'delete_topic' =&gt; true,		//+
		'close_topic' =&gt; true,			//+
		'stick_topic' =&gt; true,			//+
		'move_topic' =&gt; false,
		'view_by_ip' =&gt; false,			//+
		'edit_closed' =&gt; true,			//+
		'edit_deleted' =&gt; true,			//+
		'browse_deleted' =&gt; true,		//+
		'edit_others_tags' =&gt; true,		//+
		'edit_others_topics' =&gt; true,	//+
		'delete_posts' =&gt; true,			//+
		'throttle' =&gt; true,				//+
		'ignore_edit_lock' =&gt; true,		//+
		'edit_others_posts' =&gt; true,	//+
		'edit_favorites' =&gt; true,
		'edit_tags' =&gt; true,
		'edit_topics' =&gt; true,
		'edit_posts' =&gt; true,
		'edit_profile' =&gt; true,
		'write_topics' =&gt; true,
		'write_posts' =&gt; true,
		'change_password' =&gt; true,
		'read' =&gt; true
	);
    if ( ! in_array($args[1], array_keys($moderator_skills)) )
    {
        //echo '&lt;pre&gt;';var_dump( $args[1] );echo '&lt;/pre&gt;';
        return $args[0];
    }
    if (!$bb_current_user || in_array('keymaster',$bb_current_user-&gt;roles) || in_array('administrator',$bb_current_user-&gt;roles))
    {
		return $args[0];
    }
    //--------&gt; OK, LET'S GO !
    // prevents forum moderators to stick a topic to the forum's front page
    if ( $args[1] == 'stick_topic' )
    {
        global $super;
        $super = 0;
    }
	if (empty($forum)) {
		$topic = get_topic($topic_id);
		$forum_id = $topic-&gt;forum_id;
	} else {
        $forum_id = $forum-&gt;forum_id;
    }
    if ( !$forum_id ) return $args[0];
    if ( in_array( $forum_id, $bp_integration_privileges ))
    {
        $args[0] = $moderator_skills[ $args[1] ];
    }
    return $args[0];
}
add_filter('bb_current_user_can','bp_integration_moderators_privileges',10,25);
?&gt;</pre>]]></content:encoded> <wfw:commentRss>http://www.stefanoforenza.com/how-to-create-private-and-moderated-forums-buddypress-and-bbpress/feed/</wfw:commentRss> <slash:comments>1</slash:comments> </item> <item><title>Mozilla gets on WordPress MU. How does it feels guys?</title><link>http://www.stefanoforenza.com/mozilla-gets-on-wordpress-mu-how-does-it-feels-guys/</link> <comments>http://www.stefanoforenza.com/mozilla-gets-on-wordpress-mu-how-does-it-feels-guys/#comments</comments> <pubDate>Sat, 30 Jun 2007 22:22:08 +0000</pubDate> <dc:creator>Stefano Forenza</dc:creator> <category><![CDATA[development]]></category> <category><![CDATA[wordpress]]></category> <guid
isPermaLink="false">http://www.stefanoforenza.com/blog/mozzilla-gets-on-wordpress-mu-how-does-it-feels-guys/</guid> <description><![CDATA[( as I am still working on adapting WordPress MU to the site I&#8217;m developing, this post is work-in-progress and will be updated every now and then. Be sure to check it back in a few days if the argument interests you) I am always impressed when even large techy organizations like Mozilla adopt popular [...]]]></description> <content:encoded><![CDATA[<p><em>( as I am still working on adapting WordPress MU to the site I&#8217;m developing, this post is work-in-progress and will be updated every now and then. Be sure to check it back in a few days if the argument interests you)</em></p><p>I am always impressed when even large techy organizations like <strong>Mozilla</strong> adopt popular tools get their stuff done.</p><p><a
href="http://blog.mozilla.com/blog/2007/06/05/welcome-to-the-new-mozilla-blog/">Mozilla recently released their new blog</a>, based on <a
href="http://mu.wordpress.org/">WordPress MU</a>. I would like very much to know if they like it just because I am recently porting the front end of a personal project onto <em>wordpress mu.</em></p><p>How do they deal with security holes (I find <em>wordpress design</em> quite likely to create holes as development progresses)?</p><p><span
id="more-23"></span></p><p>I am asking, just because <strike>I am still wondering if adopting a blog-app for a custom site (a network of them, to be precise) can be a good choice</strike> I just adopted WPMU as well.</p><h2>Why did I choose WMU</h2><ul><li>Enourmous and gorgeous community. Lot&#8217;s of stuff available</li><li>Centralized backend.</li><li>Wonderful theme system. Simple, PHPish, fast, customizable.</li><li>I spent too much time on the frontend when I should have focused more on backend procedures.</li><li>Good for SEO. Even better with plugins.</li></ul><h2>Caveats I got around</h2><ul><li>multiple blogs with one backend. <strong>done</strong> <em>( adopting wordpress MU instead of the mainstream&#8217;s )</em></li><li>post bulk import. <strong>done</strong> <em><strike>( using an <a
href="http://phpxmlrpc.sourceforge.net/">xmlrpc PHP library</a> on the client side ).</strike></em> As importing a thousand of posts per day is a little too much slow I am actually ftping a serialized PHP array and save on db using hand-made queries (I could use WordPress built-in functions, but I had to add one field more to the posts-table so I am forced to use custom queries)</li></ul><h2>Solved Problems</h2><h3>WordPress MU hates WWW.</h3><p>WordPress MU definitely wants to have a base domain. As cheap hostings sometime force you to use www I was getting infinite redirections errors. WordPress MU detects www and redirects me to http://domain.com. My hosting then detects the absence of www and redirects the browser back to http://www.domain.com. None of the two seems willing to give up <img
src='http://www.stefanoforenza.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> . A little hack in <strong>wpmu-settings.php </strong>did the trick. Another hack to add to the <strong>upgrading-todos list of pain</strong>.</p><p>Sadly, the login had a similar problem, wordpress wasn&#8217;t gonna allow me log on other domains apart the www.  After some google-struggling I came up with YAH (yet another hack) to add to my <strong>bloody upgrading list of pain</strong>. You have to change some more code in<strong> wpmu-settings.php</strong>.</p><p>Around line 261 change:</p><p><code>if ( !defined('COOKIE_DOMAIN') )<br
/> define('COOKIE_DOMAIN', '.' . $_SERVER['HTTP_HOST'</code>]</p><p>Into</p><p><code>if ( !defined('COOKIE_DOMAIN') )<br
/> define('COOKIE_DOMAIN', '.' . $_SERVER['HTTP_HOST'] );</code></p><p><a
href="http://mu.wordpress.org/forums/topic.php?id=4251#post-27709">Thankyou raimond</a> !</p><h2>To be resolved yet</h2><h3>Altering the post table structure</h3><p>I need to add a single link (url) reference to each post that get imported into wordpress. In the source database, the link is a unique key, meaning that you can't have two record with the same link at the same time. This is needed in order to avoid duplication.</p><ul><li><strong>custom fields</strong> is not a choice, since records will grow very fast (nearly 200 new posts per day) that would yield to a very large <em>meta table. </em></li><li>I need a way to pass the link via <em>xmlrpc</em>. Saving a duplicate-url-record should lead to a silent failure of the record import only.</li><li>at 99% /xmlrpc.php will need to be tweaked. This is a pain in the ass when it comes to upgrading. And upgrading is needed because the <em>security-not-in-mind architecture</em> of <strong>wordpress</strong>.</li></ul><h3>Setting up a ready 4 live empty blog.</h3><p>This is something WMU does but I doubt it's possible to set up every tweak. The best would be having the choice to reply an already configured empty blog. Anyone got around this ?</p><h3>Disabling blog creation</h3><p>Maybe because <em>WordPress MU</em> is designed to allow subscribers to create their own blog, it does not allow disabling the blog creation in the front end. Again, you can just delete the subscription-file. But, <strong>again</strong>, upgrading becomes a pain.</p><p>As a side note the following lines in README.txt are to be found:</p><blockquote><p>4. If you want to restrict blog signups, set the restrict domain email setting in the admin.</p></blockquote><p>This obviously doesn't apply, cause it affects the whole user signups, not only the blogger wannabees.</p><h2>WPMU Gotchas</h2><p>Here's the things I don't plan to resolve.</p><h3>Bad error handling</h3><p>WordPress MU throws an unhealty dose of notices. That's not serious, come on! When you're the founder of a (hopefully) successful blog community you want be notified of each and every problems in the code. If the software throws notices when everything is allright, how can you expect no notice new errors in the (already polluted) logs ?</p><p>I am serious, and I am not talking about plugins, I could understand that. I am talking about core code, what the hell is that ? How do they develop in house ?</p><p>For example:</p><pre>if (! unserialize($value) )
$value = stripslashes( $value );</pre><p>It's obvious to anyone with more than 1 year programming that this will throw a notice, when unserialize fails. Putting a @ before <em>unserialize</em> won't prevent the problem to show in the logs but could at least save your screen when developing on your box. A small <em>regexp</em> or on <em>$value</em>, or a bunch of <em>strpos</em> are likely to save your ass (and the logs) the 90% of times.</p><h2>Conclusion</h2><p><strike>Will I ever get online ?</strike> WordPress MU can be a good choice, although, if you're gonna use it for something which is not a blog, you should think twice. It can be good, anyway, only be sure to consider all the low-downs.</p> ]]></content:encoded> <wfw:commentRss>http://www.stefanoforenza.com/mozilla-gets-on-wordpress-mu-how-does-it-feels-guys/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>How to build an absolute url in php</title><link>http://www.stefanoforenza.com/how-to-build-an-absolute-url-in-php/</link> <comments>http://www.stefanoforenza.com/how-to-build-an-absolute-url-in-php/#comments</comments> <pubDate>Mon, 30 Apr 2007 16:50:06 +0000</pubDate> <dc:creator>Stefano Forenza</dc:creator> <category><![CDATA[development]]></category> <category><![CDATA[php]]></category> <guid
isPermaLink="false">http://devnull.dreamhosters.com/2007/04/30/how-to-build-an-absolute-url-in-php/</guid> <description><![CDATA[Today, I was looking for a way to make an url absolute. Ok, it’s easy. Guess I should think some good excuse for not being to able to do it in 5 minutes. The sad reality is I ended digging on google (again). I am posting what I found, for (main, and) your reference. A [...]]]></description> <content:encoded><![CDATA[<p><a
title="how-to-build-an-absolute-url-in-php" name="how-to-build-an-absolute-url-in-php" id="how-to-build-an-absolute-url-in-php"></a> Today, I was looking for a <strong>way to make an url absolute</strong>.</p><p
class="level1"> Ok, it’s easy. Guess I should think some good excuse for not being to able to do it in 5 minutes. The sad reality is I ended digging on google (again).</p><p>I am posting what I found, for (main, and) your reference.<span
id="more-11"></span></p><h2><a
title="a-working-one" name="a-working-one" id="a-working-one"></a>A working one</h2><p
class="level2"> <strong>Update</strong>: the function I found didn’t pass my testcases. I had to craft one myself. A raw one, but this should work (really).</p><p>I apologize for ugly code, I just wanted to get something fast.</p><pre class="code php"><span class="kw2">function</span> absolutizeUrl <span class="br0">(</span> <span class="re0">$u</span>, <span class="re0">$p</span> <span class="br0">)</span>
<span class="br0">{</span>
	<span class="re0">$url</span> = <a href="http://www.php.net/parse_url"><span class="kw3">parse_url</span></a><span class="br0">(</span> <span class="re0">$u</span> <span class="br0">)</span>;
	<span class="re0">$page</span> = <a href="http://www.php.net/parse_url"><span class="kw3">parse_url</span></a><span class="br0">(</span> <span class="re0">$p</span> <span class="br0">)</span>;
	<span class="kw1">if</span> <span class="br0">(</span> <a href="http://www.php.net/strpos"><span class="kw3">strpos</span></a><span class="br0">(</span> <span class="re0">$u</span> , <span class="st0">'/'</span> <span class="br0">)</span> === <span class="nu0">0</span> <span class="br0">)</span>
	<span class="br0">{</span>
		<span class="co1">//already absolute		</span>
	<span class="br0">}</span> <span class="kw1">else</span> <span class="br0">{</span>
		<span class="re0">$basePath</span> = <span class="st0">''</span>;
		<span class="kw1">if</span> <span class="br0">(</span>
			<a href="http://www.php.net/isset"><span class="kw3">isset</span></a><span class="br0">(</span> <span class="re0">$page</span><span class="br0">[</span> <span class="st0">'path'</span> <span class="br0">]</span> <span class="br0">)</span>
			&amp;&amp; <a href="http://www.php.net/strpos"><span class="kw3">strpos</span></a><span class="br0">(</span> <a href="http://www.php.net/ltrim"><span class="kw3">ltrim</span></a><span class="br0">(</span> <span class="re0">$page</span><span class="br0">[</span> <span class="st0">'path'</span> <span class="br0">]</span>, <span class="st0">'/'</span> <span class="br0">)</span>, <span class="st0">'/'</span> <span class="br0">)</span>
		<span class="br0">)</span>
		<span class="br0">{</span>
			<span class="re0">$baseTokens</span> = <a href="http://www.php.net/explode"><span class="kw3">explode</span></a><span class="br0">(</span> <span class="st0">'/'</span>, <span class="re0">$page</span><span class="br0">[</span> <span class="st0">'path'</span> <span class="br0">]</span> <span class="br0">)</span>;
			<a href="http://www.php.net/array_pop"><span class="kw3">array_pop</span></a><span class="br0">(</span> <span class="re0">$baseTokens</span> <span class="br0">)</span>; <span class="co1">// strip basename			</span>
			<span class="re0">$baseTokens</span><span class="br0">[</span><span class="br0">]</span> = <span class="re0">$u</span>;
			<span class="re0">$u</span> = <a href="http://www.php.net/join"><span class="kw3">join</span></a><span class="br0">(</span> <span class="st0">'/'</span>, <span class="re0">$baseTokens</span> <span class="br0">)</span>;
		<span class="br0">}</span>
	<span class="br0">}</span>
	<span class="kw1">if</span> <span class="br0">(</span> ! <a href="http://www.php.net/isset"><span class="kw3">isset</span></a><span class="br0">(</span> <span class="re0">$url</span><span class="br0">[</span> <span class="st0">'host'</span> <span class="br0">]</span><span class="br0">)</span><span class="br0">)</span>
	<span class="br0">{</span>
		<span class="re0">$u</span> = <span class="st0">'http://'</span>.<span class="re0">$page</span><span class="br0">[</span> <span class="st0">'host'</span> <span class="br0">]</span>.<span class="st0">'/'</span>.<a href="http://www.php.net/ltrim"><span class="kw3">ltrim</span></a><span class="br0">(</span> <span class="re0">$u</span>, <span class="st0">'/'</span> <span class="br0">)</span>;
	<span class="br0">}</span>
	<span class="kw1">return</span> <span class="re0">$u</span>;
<span class="br0">}</span></pre><h2><a
title="the-bad-one-i-found" name="the-bad-one-i-found" id="the-bad-one-i-found"></a>The bad one I found</h2><p><strong>Note:</strong> this is <strong>not</strong> <em>error_reporting( E_ALL )</em> safe. You may have to edit (I had) to avoid stupid notices on the screen.</p><pre class="code php"><span class="kw2">function</span> absolutizeUrl<span class="br0">(</span> <span class="re0">$relative</span>, <span class="re0">$absolute</span> <span class="br0">)</span>
<span class="br0">{</span>
	<a href="http://www.php.net/extract"><span class="kw3">extract</span></a><span class="br0">(</span><a href="http://www.php.net/parse_url"><span class="kw3">parse_url</span></a><span class="br0">(</span><span class="re0">$absolute</span><span class="br0">)</span><span class="br0">)</span>;
	<span class="kw1">if</span><span class="br0">(</span><span class="re0">$relative</span><span class="br0">{</span><span class="nu0">0</span><span class="br0">}</span> == <span class="st0">'/'</span><span class="br0">)</span> <span class="br0">{</span>
		<span class="re0">$cparts</span> = <a href="http://www.php.net/array_filter"><span class="kw3">array_filter</span></a><span class="br0">(</span><a href="http://www.php.net/explode"><span class="kw3">explode</span></a><span class="br0">(</span><span class="st0">"/"</span>, <span class="re0">$relative</span><span class="br0">)</span><span class="br0">)</span>;
	<span class="br0">}</span>
	<span class="kw1">else</span>
	<span class="br0">{</span>
		<span class="re0">$aparts</span> = <a href="http://www.php.net/array_filter"><span class="kw3">array_filter</span></a><span class="br0">(</span><a href="http://www.php.net/explode"><span class="kw3">explode</span></a><span class="br0">(</span><span class="st0">"/"</span>, <span class="re0">$path</span><span class="br0">)</span><span class="br0">)</span>;
		<span class="re0">$rparts</span> = <a href="http://www.php.net/array_filter"><span class="kw3">array_filter</span></a><span class="br0">(</span><a href="http://www.php.net/explode"><span class="kw3">explode</span></a><span class="br0">(</span><span class="st0">"/"</span>, <span class="re0">$relative</span><span class="br0">)</span><span class="br0">)</span>;
		<span class="re0">$cparts</span> = <a href="http://www.php.net/array_merge"><span class="kw3">array_merge</span></a><span class="br0">(</span><span class="re0">$aparts</span>, <span class="re0">$rparts</span><span class="br0">)</span>;
		<span class="kw1">foreach</span><span class="br0">(</span><span class="re0">$cparts</span> <span class="kw1">as</span> <span class="re0">$i</span> =&gt; <span class="re0">$part</span><span class="br0">)</span>
		<span class="br0">{</span>
			<span class="kw1">if</span><span class="br0">(</span><span class="re0">$part</span> == <span class="st0">'.'</span><span class="br0">)</span>
			<span class="br0">{</span>
				<span class="re0">$cparts</span><span class="br0">[</span><span class="re0">$i</span><span class="br0">]</span> = <span class="kw2">null</span>;
			<span class="br0">}</span>
			<span class="kw1">if</span><span class="br0">(</span><span class="re0">$part</span> == <span class="st0">'..'</span><span class="br0">)</span>
			<span class="br0">{</span>
				<span class="re0">$cparts</span><span class="br0">[</span><span class="re0">$i</span> - <span class="nu0">1</span><span class="br0">]</span> = <span class="kw2">null</span>;
				<span class="re0">$cparts</span><span class="br0">[</span><span class="re0">$i</span><span class="br0">]</span> = <span class="kw2">null</span>;
			<span class="br0">}</span>
		<span class="br0">}</span>
		<span class="re0">$cparts</span> = <a href="http://www.php.net/array_filter"><span class="kw3">array_filter</span></a><span class="br0">(</span><span class="re0">$cparts</span><span class="br0">)</span>;
	<span class="br0">}</span>
	<span class="re0">$path</span> = <a href="http://www.php.net/implode"><span class="kw3">implode</span></a><span class="br0">(</span><span class="st0">"/"</span>, <span class="re0">$cparts</span><span class="br0">)</span>;
	<span class="re0">$url</span> = <span class="st0">""</span>;
	<span class="kw1">if</span><span class="br0">(</span><span class="re0">$scheme</span><span class="br0">)</span>
	<span class="br0">{</span>
		<span class="re0">$url</span> = <span class="st0">"$scheme://"</span>;
	<span class="br0">}</span>
	<span class="kw1">if</span><span class="br0">(</span><span class="re0">$user</span><span class="br0">)</span>
	<span class="br0">{</span>
		<span class="re0">$url</span> .= <span class="st0">"$user"</span>;
		<span class="kw1">if</span><span class="br0">(</span><span class="re0">$pass</span><span class="br0">)</span>
		<span class="br0">{</span>
		<span class="re0">$url</span> .= <span class="st0">":$pass"</span>;
		<span class="br0">}</span>
		<span class="re0">$url</span> .= <span class="st0">"@"</span>;
	<span class="br0">}</span>
	<span class="kw1">if</span><span class="br0">(</span><span class="re0">$host</span><span class="br0">)</span>
	<span class="br0">{</span>
		<span class="re0">$url</span> .= <span class="st0">"$host/"</span>;
	<span class="br0">}</span>
	<span class="re0">$url</span> .= <span class="re0">$path</span>;
	<span class="kw1">return</span> <span class="re0">$url</span>;
<span class="br0">}</span></pre><p><a
href="http://www.thescripts.com/forum/thread3648.html" class="urlextern" title="http://www.thescripts.com/forum/thread3648.html">Found it here</a>.</p> ]]></content:encoded> <wfw:commentRss>http://www.stefanoforenza.com/how-to-build-an-absolute-url-in-php/feed/</wfw:commentRss> <slash:comments>5</slash:comments> </item> <item><title>Firebug: avoid errors in other browsers</title><link>http://www.stefanoforenza.com/firebug-avoid-errors-in-other-browsers/</link> <comments>http://www.stefanoforenza.com/firebug-avoid-errors-in-other-browsers/#comments</comments> <pubDate>Thu, 19 Apr 2007 17:10:49 +0000</pubDate> <dc:creator>Stefano Forenza</dc:creator> <category><![CDATA[development]]></category> <category><![CDATA[javascript]]></category> <guid
isPermaLink="false">http://devnull.dreamhosters.com/2007/06/23/firebug-avoid-errors-in-other-browsers/</guid> <description><![CDATA[Small snippets or full-featured libraries &#8211; if you develop in Javascript and don’t have Firefox and Firebug installed &#8211; you’d better get them now. Firebug is a Firefox extension which brings several top-notch inspection/debugging features. You can inspect DOM, change CSS run-time and so on. Aside DOM, CSS and Net capabilities Firebug features a very [...]]]></description> <content:encoded><![CDATA[<p><a
title="firebugavoid-errors-in-other-browsers" name="firebugavoid-errors-in-other-browsers" id="firebugavoid-errors-in-other-browsers"></a> Small snippets or full-featured libraries  &#8211; if you develop in <a
href="http://developer.mozilla.org/en/docs/JavaScript" class="urlextern" title="http://developer.mozilla.org/en/docs/JavaScript">Javascript</a> and don’t have <a
href="http://getfirefox.com/" class="urlextern" title="http://getfirefox.com/">Firefox</a> and <a
href="http://getfirebug.com/" class="urlextern" title="http://getfirebug.com/">Firebug</a></p><p
class="level1"> installed &#8211; you’d better get them now.</p><p>Firebug is a Firefox extension which brings several top-notch inspection/debugging features. You can inspect <acronym
title="Document Object Model">DOM</acronym>, change <acronym
title="Cascading Style Sheets">CSS</acronym> run-time and so on.</p><p>Aside <acronym
title="Document Object Model">DOM</acronym>, <acronym
title="Cascading Style Sheets">CSS</acronym> and Net capabilities Firebug features a <em>very good debugger</em> and some very useful <em>logging capabilities</em>. For example in your scripts you could write:</p><pre class="code javascript">console.<span class="me1">log</span> <span class="br0">(</span> <span class="st0">"result is:"</span>, <span class="kw2">var</span> <span class="br0">)</span>;</pre><p>and get the javascript variable “var” dumped into Firebug console.<span
id="more-14"></span></p><h2><a
title="browsers-issue" name="browsers-issue" id="browsers-issue"></a>Browsers Issue</h2><p>Sadly, firebug as an extension is only available to Firefox. This means that any of your script will fail while running inside other browsers.</p><p>I wrote a little script to fix the problem:</p><pre class="code javascript"><span class="kw1">if</span> <span class="br0">(</span> <span class="kw1">typeof</span><span class="br0">(</span> console<span class="br0">)</span> == <span class="st0">"undefined"</span> <span class="br0">)</span> <span class="kw2">var</span> console = <span class="br0">{</span><span class="br0">}</span>;
console.<span class="me1">turnOff</span> = <span class="kw2">function</span> <span class="br0">(</span><span class="br0">)</span>
<span class="br0">{</span>
	<span class="kw2">var</span> api = <span class="br0">[</span> <span class="st0">'log'</span>, <span class="st0">'debug'</span>, <span class="st0">'info'</span>, <span class="st0">'warn'</span>, <span class="st0">'error'</span>, <span class="st0">'assert'</span>, <span class="st0">'dir'</span>, <span class="st0">'dirxml'</span>, <span class="st0">'trace'</span>, <span class="st0">'group'</span>, <span class="st0">'groupEnd'</span>, <span class="st0">'time'</span>, <span class="st0">'timeEnd'</span>, <span class="st0">'profile'</span>, <span class="st0">'profileEnd'</span>, <span class="st0">'count'</span> <span class="br0">]</span>;
	<span class="kw1">for</span> <span class="br0">(</span> <span class="kw2">var</span> i = <span class="nu0">0</span>; i &lt; api.<span class="me1">length</span>; i++ <span class="br0">)</span> console<span class="br0">[</span> api<span class="br0">[</span>i<span class="br0">]</span> <span class="br0">]</span> = <span class="kw2">function</span> <span class="br0">(</span><span class="br0">)</span><span class="br0">{</span><span class="br0">}</span>;
	console.<span class="me1">firebug</span> = <span class="st0">"0.00"</span>;
<span class="br0">}</span>
<span class="kw1">if</span> <span class="br0">(</span> <span class="kw1">typeof</span><span class="br0">(</span> console.<span class="me1">firebug</span><span class="br0">)</span> == <span class="st0">"undefined"</span>  <span class="br0">)</span> console.<span class="me1">turnOff</span><span class="br0">(</span><span class="br0">)</span>;</pre><p>Needless to say, I became aware afterwards a quite identical solution was available from the Firebug official site’s as well. Here’s is the official solution:</p><pre class="code javascript"><span class="kw1">if</span> <span class="br0">(</span>!window.<span class="me1">console</span> || !console.<span class="me1">firebug</span><span class="br0">)</span>
<span class="br0">{</span>
    <span class="kw2">var</span> names = <span class="br0">[</span><span class="st0">"log"</span>, <span class="st0">"debug"</span>, <span class="st0">"info"</span>, <span class="st0">"warn"</span>, <span class="st0">"error"</span>, <span class="st0">"assert"</span>, <span class="st0">"dir"</span>, <span class="st0">"dirxml"</span>,
    <span class="st0">"group"</span>, <span class="st0">"groupEnd"</span>, <span class="st0">"time"</span>, <span class="st0">"timeEnd"</span>, <span class="st0">"count"</span>, <span class="st0">"trace"</span>, <span class="st0">"profile"</span>, <span class="st0">"profileEnd"</span><span class="br0">]</span>;
    window.<span class="me1">console</span> = <span class="br0">{</span><span class="br0">}</span>;
    <span class="kw1">for</span> <span class="br0">(</span><span class="kw2">var</span> i = <span class="nu0">0</span>; i &lt; names.<span class="me1">length</span>; ++i<span class="br0">)</span>
        window.<span class="me1">console</span><span class="br0">[</span>names<span class="br0">[</span>i<span class="br0">]</span><span class="br0">]</span> = <span class="kw2">function</span><span class="br0">(</span><span class="br0">)</span> <span class="br0">{</span><span class="br0">}</span>
<span class="br0">}</span></pre><p>The only difference is mine provides a <em>console.turnOff()</em> function which disables firebug logging even in firefox (when called explicitly form your script).</p><pre class="code javascript">console.<span class="me1">turnOff</span><span class="br0">(</span><span class="br0">)</span>;
console.<span class="me1">debug</span><span class="br0">(</span> <span class="st0">'Hello world'</span> <span class="br0">)</span>; <span class="co1">//won't output anything</span></pre><p><span> </span></p> ]]></content:encoded> <wfw:commentRss>http://www.stefanoforenza.com/firebug-avoid-errors-in-other-browsers/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>A brief look into REST</title><link>http://www.stefanoforenza.com/a-brief-look-into-rest/</link> <comments>http://www.stefanoforenza.com/a-brief-look-into-rest/#comments</comments> <pubDate>Sat, 03 Mar 2007 16:49:00 +0000</pubDate> <dc:creator>Stefano Forenza</dc:creator> <category><![CDATA[development]]></category> <category><![CDATA[http]]></category> <guid
isPermaLink="false">http://devnull.dreamhosters.com/2007/03/03/a-brief-look-into-rest/</guid> <description><![CDATA[With the explosion of Rails like Mvc frameworks, URI well-formness whas brought more and more to the attention of web developers. In php we see often great misuse of HTTP request method, with lots of parameters following the “?”, overuse of POST method and so on. Lack of proper browsers support for PUT/DELETE methods does [...]]]></description> <content:encoded><![CDATA[<p><a
title="a-brief-look-into-rest" name="a-brief-look-into-rest" id="a-brief-look-into-rest"></a> With the explosion of Rails like Mvc frameworks, <acronym
title="Uniform Resource Identifier">URI</acronym> well-formness whas brought more and more to the attention of web developers.</p><p
class="level1"> In php we see often great misuse of <acronym
title="Hyper Text Transfer Protocol">HTTP</acronym> request method, with lots of parameters following the “?”, overuse of POST method and so on. Lack of proper browsers support for PUT/DELETE methods does not help to make situation better.<span
id="more-10"></span></p><p>Beside this, a good understanding of <acronym
title="Hyper Text Transfer Protocol">HTTP</acronym> architecture can be useful to developer, as cited frameworks tends to use a lot URIs even in their inner-workings side. It’s good to see that someone is already trying to learn something from the past/present experiences with <acronym
title="Hyper Text Transfer Protocol">HTTP</acronym> implementation. (<a
href="http://konstrukt.dk/" class="urlextern" title="http://konstrukt.dk/">Konstruct</a> for instance).</p><p>Here’s 2 resources you SHOULD really read (especially if you are working on a MVC framework).</p><ul><li
class="level1"><p
class="li"> <a
href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html#sec9" class="urlextern" title="http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html#sec9">HTTP 1.1 Section 9 &#8211; Methods Definitions</a> (brief explaining of http’s methods meaning)</p></li><li
class="level1"><p
class="li"> <a
href="http://www.prescod.net/rest/mistakes/" class="urlextern" title="http://www.prescod.net/rest/mistakes/">Common Rest Mistakes</a></p></li></ul><p></p> ]]></content:encoded> <wfw:commentRss>http://www.stefanoforenza.com/a-brief-look-into-rest/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>Know what you are gonna do !</title><link>http://www.stefanoforenza.com/know-what-you-are-gonna-do/</link> <comments>http://www.stefanoforenza.com/know-what-you-are-gonna-do/#comments</comments> <pubDate>Sat, 03 Mar 2007 16:43:57 +0000</pubDate> <dc:creator>Stefano Forenza</dc:creator> <category><![CDATA[development]]></category> <category><![CDATA[fun]]></category> <guid
isPermaLink="false">http://devnull.dreamhosters.com/2007/02/03/know-what-you-are-gonna-do/</guid> <description><![CDATA[A little IM conversation I had with one friend. &#160; (me) che features vuoi avere per la primissima versione ? Felice: non credo che la rilascio pubblica&#8230; (me) vabbè. che features deve avere ? (me) non lo sai, briccone.. Felice: no.. Translation (me): what feature do you plan to include in the very first version [...]]]></description> <content:encoded><![CDATA[<p><a
title="know-what-you-are-gonna-do" name="know-what-you-are-gonna-do" id="know-what-you-are-gonna-do"></a> A little IM conversation I had with one friend.</p><p
class="level1">&nbsp;</p><ul><li
class="level1"><p
class="li"> (me) che features vuoi avere per la primissima versione ?</p></li><li
class="level1"><p
class="li"> Felice: non credo che la rilascio pubblica&#8230;</p></li><li
class="level1"><p
class="li"> (me) vabbè. che features deve avere ?</p></li><li
class="level1"><p
class="li"> (me) non lo sai, briccone..</p></li><li
class="level1"><p
class="li"> Felice: no..</p></li></ul><p><strong> Translation</strong></p><ul><li
class="level1"><p
class="li"> (me): what feature do you plan to include in the very first version ?</p></li><li
class="level1"><p
class="li"> Felice: I guess I won’t make a public release for the alpha.</p></li><li
class="level1"><p
class="li"> (me): ok, but what features do you want in it ?</p></li><li
class="level1"><p
class="li"> (me): you don’t know, right ?</p></li><li
class="level1"><p
class="li"> Felice: right..</p></li></ul><p><strong>Try to always know what you want !</strong></p> ]]></content:encoded> <wfw:commentRss>http://www.stefanoforenza.com/know-what-you-are-gonna-do/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>Xdump: a little piece of my story as developer</title><link>http://www.stefanoforenza.com/xdump-a-little-piece-of-my-story-as-developer/</link> <comments>http://www.stefanoforenza.com/xdump-a-little-piece-of-my-story-as-developer/#comments</comments> <pubDate>Mon, 19 Feb 2007 16:56:37 +0000</pubDate> <dc:creator>Stefano Forenza</dc:creator> <category><![CDATA[development]]></category> <category><![CDATA[php]]></category> <category><![CDATA[projects]]></category> <guid
isPermaLink="false">http://devnull.dreamhosters.com/2007/02/19/xdump-a-little-piece-of-my-story-as-developer/</guid> <description><![CDATA[I am slowly beginning to pull online docs and samples for Xdump. Xdump was one debugging tool I had to develop for the reason that in some situations var_dump() simply is not enough. Here’s the overview of xdump. Of course one could say that as good programmer you should never ever findy yourself in such [...]]]></description> <content:encoded><![CDATA[<p><a
title="xdumpa-little-piece-of-my-story-as-developer" name="xdumpa-little-piece-of-my-story-as-developer" id="xdumpa-little-piece-of-my-story-as-developer"></a> I am slowly beginning to pull online docs and samples for <strong>Xdump</strong>.</p><p
class="level1"> Xdump was one debugging tool I had to develop for the reason that in some situations <a
href="http://php.net/var_dump" class="urlextern" title="http://php.net/var_dump">var_dump()</a> simply is not enough.</p><h2><a
title="section" name="section" id="section"></a></h2><p
class="level2"> Here’s the <a
href="/2007/01/23/xdump/">overview of xdump</a>.</p><p>Of course one could say that as good programmer you should never ever findy yourself in such a situation which requires something more powerful than <a
href="http://php.net/var_dump" class="urlextern" title="http://php.net/var_dump">var_dump()</a> or <a
href="http://php.net/print_r" class="urlextern" title="http://php.net/print_r">print_r()</a>. I can understand this kind of point-of-view, but I found that real world not always is like that.</p><p>Today at work, for example, I had to add some functionality to a <a
href="http://www.zen-cart.com/" class="urlextern" title="http://www.zen-cart.com/">zen-cart</a> installation. <a
href="http://www.stefanoforenza.com/xdump/zen-cart-example" class="wikilink1" title="xdump:zen-cart-example">This is something var_dump simply cannot manage</a> (without driving you crazy, I mean).<span
id="more-12"></span></p><h2><a
title="download" name="download" id="download"></a>Download</h2><p><del>I will try to make download available as soon as I can.</del></p><p><a
href="http://xdump.googlecode.com/files/xdump%2020070220.zip" class="urlextern" title="http://xdump.googlecode.com/files/xdump%2020070220.zip">Download available on google code</a></p> ]]></content:encoded> <wfw:commentRss>http://www.stefanoforenza.com/xdump-a-little-piece-of-my-story-as-developer/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>Need for Cache</title><link>http://www.stefanoforenza.com/need-for-cache/</link> <comments>http://www.stefanoforenza.com/need-for-cache/#comments</comments> <pubDate>Fri, 16 Feb 2007 10:04:36 +0000</pubDate> <dc:creator>Stefano Forenza</dc:creator> <category><![CDATA[development]]></category> <category><![CDATA[php]]></category> <category><![CDATA[projects]]></category> <guid
isPermaLink="false">http://devnull.dreamhosters.com/2007/06/23/need-for-cache/</guid> <description><![CDATA[After going through PhpThumb hell, I decided to develop one serious decent caching library for caching dynamically generated images. Download &#160; Download zipped source from Google Code Or browse svn repository Download source from svn using: svn checkout http://xdump.googlecode.com/svn/trunk/ xdump Brief story One of our previous sites (about 50k page-views per day) was using a [...]]]></description> <content:encoded><![CDATA[<p>After going through <a
href="http://phpthumb.sourceforge.net/" class="urlextern" title="http://phpthumb.sourceforge.net/">PhpThumb</a> hell, I decided to develop one <del>serious</del> decent <a
href="http://code.google.com/p/cache-on-request/" class="urlextern" title="http://code.google.com/p/cache-on-request/">caching library</a> for caching dynamically generated images.<span
id="more-6"></span></p><h2><a
title="download" name="download" id="download"></a>Download</h2><p
class="level2">&nbsp;</p><blockquote><p
class="no"> Download zipped source from <a
href="http://cache-on-request.googlecode.com/files/cache-on-request-veryalpha.zip" class="urlextern" title="http://cache-on-request.googlecode.com/files/cache-on-request-veryalpha.zip">Google Code</a></p><p>Or <a
href="http://cache-on-request.googlecode.com/svn/trunk/" class="urlextern" title="http://cache-on-request.googlecode.com/svn/trunk/">browse svn repository</a></p><p>Download source from svn using: <em>svn checkout <a
href="http://xdump.googlecode.com/svn/trunk/" class="urlextern" title="http://xdump.googlecode.com/svn/trunk/">http://xdump.googlecode.com/svn/trunk/</a> xdump</em></p></blockquote><h2><a
title="brief-story" name="brief-story" id="brief-story"></a>Brief story</h2><p
class="level2"> One of our previous sites (about 50k page-views per day) was using a little php script for resizing dinamically images to thumbnail size. Since we didn’t knew in advance the size we was gonna need, resize was made at run-time.</p><p>With site’s restyling the number of resized images on every page increased sensibly. As it’s easy to guess server load went sky-high. We tried to replace the package with <a
href="http://phpthumb.sourceforge.net/" class="urlextern" title="http://phpthumb.sourceforge.net/">PhpThumb</a> but the situation got even worse (yes, worse was possible).</p><h2><a
title="what-s-wrong-with-phpthumb" name="what-s-wrong-with-phpthumb" id="what-s-wrong-with-phpthumb"></a>What&#8217;s wrong with PhpThumb</h2><p
class="level2"> I have some problems with <a
href="http://phpthumb.sourceforge.net/" class="urlextern" title="http://phpthumb.sourceforge.net/">PhpThumb</a>. Oh yes, I do.</p><ul><li
class="level1"><p
class="li"> <strong>It’s bloated</strong>. Even if PhpThumb is a class, the caching routines are written in a procedural file who reads $_GET superglobal to decide what to do. This means I had to simulate <acronym
title="Hyper Text Transfer Protocol">HTTP</acronym> request by emptying manually $_GET and putting there only values PhpThumb needs. You don’t pass through that file.. you don’t cache.</p></li></ul><ul><li
class="level1"><p
class="li"> <strong>Cache working</strong>.</p><ul><li
class="level2"><p
class="li"> Does it work? I couldn’t verify, the only thing I know is that the cache directory kept becoming bigger, with apparently no limit. Actually, it became so big to cause server load by itself.</p></li><li
class="level2"><p
class="li"> I tried disabling cache in the config. Guess what? It kept caching, yes it did! I had to <em>physically delete</em> the cache path to block caching.</p></li><li
class="level2"><p
class="li"> Cached file retrieving. It’s made using <a
href="http://php.net/readfile" class="urlextern" title="http://php.net/readfile">readfile()</a> or <a
href="http://php.net/header" class="urlextern" title="http://php.net/header">header</a> redirects. While that’s better than nothing I think we can <a
href="http://meta.wikimedia.org/wiki/404_handler_caching" class="urlextern" title="http://meta.wikimedia.org/wiki/404_handler_caching">do better</a>, much better.</p></li></ul></li></ul><h2><a
title="strategy" name="strategy" id="strategy"></a>Strategy</h2><p
class="level2"> The solution I choose is what some call <strong>generate on request</strong>. This trick consists in creating a dynamic script, making it the default <strong>Apache’s ErrorDocument</strong> for the current directory and let it handle the content generation.</p><p>The flow:</p><ol><li
class="level1"><p
class="li"> Assume we store all downloadable wallpapers on our site are stored into /image/wallpapers directory.</p></li><li
class="level1"><p
class="li"> The website’s page will contain a non existant image path. Say something like: <em> <a
href="http://example.com/dynamic/40x30/images/wallpapers/britney.jpg" class="urlextern" title="http://example.com/dynamic/40x30/images/wallpapers/britney.jpg">http://example.com/dynamic/40&#215;30/images/wallpapers/britney.jpg</a> </em></p></li><li
class="level1"><p
class="li"> At the time of the first visit to the page the resized image will not be there yet.</p></li><li
class="level1"><p
class="li"> When the image requests hits Apache, it will be redirected to our custom ErrorDocument (<em>front_controller.php</em>).</p></li><li
class="level1"><p
class="li"> <em>front_controller.php</em> will take care to read <em>/images/wallpapers/britney.jpg</em> generate our 40×30 nice thumbnail at <em>/dynamic/40×30/images/wallpapers/britney.jpg</em> path.</p></li><li
class="level1"><p
class="li"> Afterwars the user browser will be redirected to the generated image,  making it appear on the page.</p></li><li
class="level1"><p
class="li"> Every other request to the page will find the image already at the path requested, without needing <acronym
title="Hypertext Preprocessor">PHP</acronym> to do anything.</p></li></ol><h2><a
title="the-code" name="the-code" id="the-code"></a>The Code</h2><p
class="level2"> Here’s some code boxes to let you know how code looks like.</p><h3><a
title="htaccess" name="htaccess" id="htaccess"></a>.htaccess</h3><p
class="level3"> The only purpose of .htaccess here is to instruct to consider our <strong>Front Controller</strong> the default error page for the generated images path.</p><p>The first time an image is requested the Front Controller manages to create it at the requested path, and to redirect the user to it.</p><p>The following requests will find the image already waiting for them. This means the file will be served by Apache itself with no php intermediation. This can lead to performance improvement around the order of magnitude.</p><pre class="code apache"><span class="kw1">ErrorDocument</span> <span class="nu0">404</span> /dynamic/front_controller.php</pre><h3><a
title="front-controller" name="front-controller" id="front-controller"></a>Front Controller</h3><p
class="level3"> The purpouse of this file is to include libs, instantiate main class, decide which drivers are to be used and make thing run.</p><pre class="code php"><span class="kw1">include</span> <span class="br0">(</span> <span class="st0">'_libs/logger.php'</span> <span class="br0">)</span>;
<span class="kw1">include</span> <span class="br0">(</span> <span class="st0">'_libs/cache_on_request.php'</span> <span class="br0">)</span>;
<span class="re0">$FrontController</span> = <span class="kw2">new</span> GenerateOnRequest<span class="br0">(</span><span class="br0">)</span>;
<span class="co1">//decomment the following 2 lines only for debug purpouse</span>
<span class="re0">$FrontController</span>-&gt;<span class="me1">configuration</span><span class="br0">[</span><span class="st0">'debug'</span><span class="br0">]</span>=<span class="kw2">true</span>; <span class="co1">//prints logs (and hinibits header final)</span>
<span class="co1">//$FrontController-&gt;configuration['stopGeneration']=true; //checked by drivers, hinibits concrete file generation</span>
<span class="co1">//attacching drivers</span>
<span class="re0">$FrontController</span>-&gt;<span class="me1">attachDriver</span><span class="br0">(</span> <span class="kw2">new</span> ResetController <span class="br0">)</span>;
<span class="re0">$FrontController</span>-&gt;<span class="me1">attachDriver</span><span class="br0">(</span> <span class="kw2">new</span> GdImageResizer <span class="br0">)</span>;
<span class="re0">$FrontController</span>-&gt;<span class="me1">run</span><span class="br0">(</span> <span class="re0">$_SERVER</span><span class="br0">[</span> <span class="st0">'REQUEST_URI'</span> <span class="br0">]</span>, <a href="http://www.php.net/dirname"><span class="kw3">dirname</span></a><span class="br0">(</span><span class="kw2">__FILE__</span> <span class="br0">)</span> <span class="br0">)</span>;</pre><p
class="tags"><span> <a
href="http://www.stefanoforenza.com/tags/php" class="wikilink2" title="tags:php" rel="tag">php</a>, <a
href="http://www.stefanoforenza.com/tags/lib-dev" class="wikilink2" title="tags:lib-dev" rel="tag">lib-dev</a> </span></p> ]]></content:encoded> <wfw:commentRss>http://www.stefanoforenza.com/need-for-cache/feed/</wfw:commentRss> <slash:comments>1</slash:comments> </item> <item><title>Xdump</title><link>http://www.stefanoforenza.com/xdump/</link> <comments>http://www.stefanoforenza.com/xdump/#comments</comments> <pubDate>Tue, 23 Jan 2007 16:58:38 +0000</pubDate> <dc:creator>Stefano Forenza</dc:creator> <category><![CDATA[development]]></category> <category><![CDATA[php]]></category> <category><![CDATA[projects]]></category> <guid
isPermaLink="false">http://devnull.dreamhosters.com/2007/01/23/xdump/</guid> <description><![CDATA[When working with large arrays/objects,with complex references beetween variables or (again) php’s built-in var_dump() e debug_backtrace() shows their limits. Have you ever tried to var_dump $GLOBALS ? Even if when I started this lib there were already some classes which provided nice html formatted dump, in the moment I needed one, I couldn’t (my fault) [...]]]></description> <content:encoded><![CDATA[<p><a
title="x-dump" name="x-dump" id="x-dump"></a> When working with large arrays/objects,with complex references beetween variables or (again) php’s built-in <a
href="http://php.net/var_dump" class="urlextern" title="http://php.net/var_dump">var_dump()</a> e <a
href="http://php.net/debug_backtrace" class="urlextern" title="http://php.net/debug_backtrace">debug_backtrace()</a> shows their limits.</p><p
class="level1"> Have you ever tried to var_dump $GLOBALS ?</p><p>Even if when I started this lib there were already some classes which provided nice html formatted dump, in the moment I needed one, I couldn’t (my fault) find one.<span
id="more-13"></span></p><p><strong>Xdump</strong> started as a bunch of procedural lines of code and slowly evolved in a object-oriented library which can provide <em>nice collapsable html dumps and backtraces</em>, <em>spoof references</em> (to avoid dump bloat and recursions) and <em>show source code lines</em> where dump was invoked as well as display on screen <em>source code lines for every backtrace jump</em>.</p><h2><a
title="download" name="download" id="download"></a>Download</h2><p
class="level2">&nbsp;</p><blockquote><p
class="no"> <a
href="http://code.google.com/p/xdump/downloads/list" class="urlextern" title="http://code.google.com/p/xdump/downloads/list">Xdump Download Page</a></p></blockquote><h2><a
title="overview" name="overview" id="overview"></a>Overview</h2><p
class="level2"> Xdump let’s you display php vars nicely on the screen.</p><ul><li
class="level1"><p
class="li"> Jump to examples</p></li><li
class="level2"><p
class="li"> Test cases are provided (requires SimpleTest)</p></li></ul><h2><a
title="usage" name="usage" id="usage"></a>Usage</h2><p
class="level2">&nbsp;</p><ol><li
class="level1"><p
class="li"> Include “xdump/xdump.php” in your main include file.</p></li><li
class="level1"><p
class="li"> Use following code:</p></li></ol><pre class="code php"><a href="http://www.php.net/echo"><span class="kw3">echo</span></a> xdump::<span class="me2">dump</span><span class="br0">(</span><span class="re0">$var</span><span class="br0">)</span>;</pre><ol><li
class="level1"><p
class="li"> To show a backtrace instead type:</p></li></ol><pre class="code php"><a href="http://www.php.net/echo"><span class="kw3">echo</span></a> xdump::<span class="me2">backtrace</span><span class="br0">(</span><span class="br0">)</span>;</pre><h2><a
title="samples" name="samples" id="samples"></a>Samples</h2><p
class="level2"> <a
href="http://www.stefanoforenza.com/xdump/zen-cart-example" class="wikilink1" title="xdump:zen-cart-example">Dumping get_defined_vars() inside a Zen-Cart template</a></p><h2><a
title="licence-and-contact" name="licence-and-contact" id="licence-and-contact"></a>Licence and contact</h2><p
class="level2">&nbsp;</p><ul><li
class="level1"><p
class="li"> Xdump is <acronym
title="Massachusetts Institute of Technology">MIT</acronym> Licensed.</p></li><li
class="level2"><p
class="li"> Info, suggestions and stuff to: stefano@stefanoforenza.com</p></li></ul><h2><a
title="features" name="features" id="features"></a>Features</h2><p
class="level2"> <strong>General</strong></p><ul><li
class="level1"><p
class="li"> Displays php dumps more nicely</p></li><li
class="level2"><p
class="li"> Dumps are javascript contractible. They occupy little space on the page and open when clicked.</p></li><li
class="level2"><p
class="li"> Display nicely without styles and javascript as well (if you work with them disabled)</p></li><li
class="level2">Shows file, line number and source lines around the dump invocation (no more digging around to remove debugging code). Shows source lines for every backtrace jump as well (neat! try it).</li><li
class="level2"><p
class="li"> (almost) Plug &amp; Play</p></li></ul><p><strong>Technical</strong></p><ul><li
class="level1"><p
class="li"> Handles reference recursions inside objects and arrays (no endless loop). Will signal visually nested references (the parent referenced element will blink orange).</li><li
class="level2"><p
class="li"> PHP5 Overloading aware (doesn’t touch <em
class="u">get, </em>set etc)</p></li><li
class="level2"><p
class="li"> PHP4 Compatible</p></li><li
class="level2"><p
class="li"> Shows you backtrace info and the chunk of the code that invoked the dump</p></li><li
class="level2">Some little effort to limit the size of markup inside the dump. Keep in mind that the dump will anyway be bigger than a vardump</li></ul> ]]></content:encoded> <wfw:commentRss>http://www.stefanoforenza.com/xdump/feed/</wfw:commentRss> <slash:comments>2</slash:comments> </item> </channel> </rss>
