Gravatar Zend Framework View Helper

I have worked on a Zend Framework these past couple of days and needed the ability to display a users avatar. This is easy by using Automattic’s gravatar project. The easiest way to add a users avatar is to use a (this) view helper. Basically in your view you just pass the user’s email address and a desired size and your all set. Make sure in the view helper you specify the default image if the user doesn’t have an avatar to display.

You can download the source here. Comments and improvements are always welcome.

<?php
/**
 *
 * @author Shaun Farrell
 * @version 1.0
 */
require_once 'Zend/View/Interface.php';

/**
 * Gravatar helper
 *
 * @uses viewHelper Zend_View_Helper
 */
class Zend_View_Helper_Gravatar {

	/**
	 * @var Zend_View_Interface
	 */
	public $view;
	/**
	 *
	 * @var unknown_type
	 */
	protected $_gravatarUrl = "http://www.gravatar.com/avatar.php?";
	/**
	 *
	 * @var unknown_type
	 */
	protected $_defaultImage = "http://everquest.allakhazam.com/pgfx/item_576.png";

	/**
	 *
	 * @param $emailAddress
	 * @param $size
	 * @param $imgAlt
	 */
	public function gravatar($emailAddress, $size = "40", $imgAlt = "")
	{
		$gravatarId = "gravatar_id=" . md5(strtolower(trim($emailAddress)));
		$url = $this->_gravatarUrl . $gravatarId . "&default=" . urlencode($this->_defaultImage) .
			"&size=" . $size;

		echo "<img src=\"$url\" alt=\"$imgAlt\" />";
		return null;
	}

	/**
	 * Sets the view field
	 * @param $view Zend_View_Interface
	 */
	public function setView(Zend_View_Interface $view) {
		$this->view = $view;
	}
}

After the Deadline (AtD)

Yesterday I had the great opportunity to here Raphael Mudge the creator of AtD present After the Deadline at DC PHP.  Below is a recording of the talk.  I hope to write some more about AtD after I play around with it more.

Recovery.gov | SharePoint, Blogging, and Photo Uploads!

This will never happen with recovery.gov but it’s in the second contract modification document from Smartronix.

Synteractive is a strategy and business solutions consulting firm specializing in
leveraging the power of information to radically improve the efficiency and effectiveness
of complex organizations. Synteractive has a proven record of using Microsoft Office
SharePoint Server (MOSS) technology to aid in business transformation efforts of both
federal government agencies and private companies. They will leverage their unrivaled
expertise in Web 2.0 technology implementation to transform Recovery.gov from a mere
information dissemination website into an interactive platform where Americans can
swap stories about stimulus projects in their areas, upload pictures illustrating the
effects of the projects, blog about their experiences, and ultimately engaged as a
meaningful member of the Recovery community.

First off, why build a transparent application in Sharepoint! Secondly, have you seen any government sites that allow users to blog and upload pictures? Can’t wait to see this in action!

Oh yeah, hopefully Smartronix isn’t letting Syneractive design the website, it looks really bad!

Contract Documents for Recovery.gov can be found at http://www.recovery.gov/?q=node/765 <– where are the pretty urls?
PDF that shows above quote Page 5 Section 2.2 on this document http://www.recovery.gov/sites/default/files/508%20Second%20Modification%20Managment%20Proposal.pdf

Zend_Db Firebug Profiler via .ini File

So a couple of days ago I posted a way to get the DB profiler working via your bootstrap but an easier way to get things working is via your configuration .ini file.

Once again you need Firefox, FireBug, and FirePHP. Then in your .ini file add the following lines;

resources.db.isdefaulttableadapter = true
resources.db.params.profiler.enabled = true
resources.db.params.profiler.class = Zend_Db_Profiler_Firebug

The best part about this is that you can add this code only to load based on the environment set in your .htaccess or index.php file in your public folder.

Getting Zend_Db Firebug Profiler Working with Zend_Application

When developing web applications I normally run into some SQL problems and want to see what the SQL code is doing on the backend. To do this one would normally just print the SQL statement to the screen during execution. However, if you use Zend Framework you are in luck. You can profile your database calls with Firebug and it’s really easy. Here is what you will need to start.

  1. Running Zend Framework (1.8.4 or above using Zend_Application)
  2. Mozilla Firefox Browser – You should be using this anyways!
  3. The latest version of Firebug – http://getfirebug.com/
  4. The lastest version of FirePHP – http://www.firephp.org/

Once those firefox add-ons have been installed your ready to add in some code.

In your bootstrap.php file add

    /**
     * Setup the database profiling
     */
    protected function _initDbProfiler()
    {
        $this->bootstrap('db');
        $profiler = new Zend_Db_Profiler_Firebug('All DB Queries');
        $profiler->setEnabled(true);
        $this->getPluginResource('db')->getDbAdapter()
             ->setProfiler($profiler);
    }

With this code added all your SQL statements that are executed will show up in the console window of FireBug. If it’s not working make sure that you have the net console enabled! profiling will not work if net is not enabled.

More information about Zend_Db_Profiler can be found at http://framework.zend.com/manual/en/zend.db.profiler.html