Disqus and Zend Framework - The Ossigeno Blog - Powered by Ossigeno 3.0_rc1

Posted by giorgio
On Jun 3, 2009 9:40:19 PM
Disqus is an application that hosts commenting service for your blog. Or your Zend Framework application, since you can place a comment box anywhere: here's a small view helper.
Disqus, pronounced "discuss", is a service and tool for web comments and discussions. The Disqus comment system can be plugged into any website, blog, or application. Disqus makes commenting easier and more interactive, while connecting websites and commenters across a thriving discussion community.
-- From the Disqus wiki

Really, it is very easier to integrate. Many blogs have substitute their comment system with the one provided by Disqus, and there are many plugin for the mahor blogging platforms. If it spreads, you won't ever need to register on a blog to comment it; another beautiful feature is the possibility of claiming all comments made with an e-mail address on the internet at registration time: I found old comments, which I couldn't keep track of, on blogs that integrate Disqus, simply because I signed them with my gmail.
To integrate Disqus comment system in a Zend Framework application I have written a view helper myself in five minutes:

 * @copyright  2008, Giorgio Sironi
 * @license    http://www.gnu.org/licenses/gpl-2.0.html GNU Public License
 * @version    $Id$
 * @link       http://sf.net/projects/ossigeno

class Otk_View_Helper_Disqus extends Zend_View_Helper_Abstract
     * @param  string $disqusUnixName
     * @return string html
    public function disqus($disqusUnixName)
        return "<div id=\"disqus_thread\"></div>
        <script type=\"text/javascript\" src=\"http://disqus.com/forums/{$disqusUnixName}/embed.js\"></script>
        <noscript><a href=\"http://{$disqusUnixName}.disqus.com/?url=ref\">
        View the discussion thread.
        <a href=\"http://disqus.com\" class=\"dsq-brlink\">blog comments powered by <span class=\"logo-disqus\">Disqus</span></a>

That's all, since the only thing to do is to print the needed javascript and degradable links in case our visitor is a user without javascript or, more likely, a spider from a search engine.
Usage of this view helper is simple:
    echo $this->disqus('thenameofmydisqusregistration');
The only argument is the unix name given to your registration to disqus. It is also called short name. I'll start use Disqus in this blog on the next upgrade of Ossigeno, that will contain the Disqus view helper.
Feel free to suggest improvements - it's a small code snippet that I wrote this evening. And if you are a blogger, try Disqus: outsourcing is a big trend nowadays and comments are tipically difficult to manage, with captcha, registrations and so on. So let someone else bear the burden. :)