Comments Off on PHP and RIA

For our presentation on PHP and RIA (PowerPoint Slides) Stas and I improved the chat application originally written by Padraic Brady and featured in the Ajax Chat Tutorial. We added a number of capabilities to show some of the more advanced concepts in the Zend Framework. You can download the application by clicking this link, Improved Ajax Chat.

The modifications are as follows:

  1. The data handling is separated into distinct model class – model/ChatData.php
  2. The chat application now has log capability, meaning it preserves everything that was said and the log can be viewed later.
  3. The log page supports searching.
  4. The log supports webservice integrations with following services:
    • Yahoo content analyzer – allows to find “interesting” words in the text
    • Flickr image search – allows to display images that relate to specific keywords
    • Amazon book search – allows to get list of books that relate to the keywords

In order to see this additional functions, do the following:

  1. Start chat as usual, chat for a bit (try to use long meaningful sentences so that chances of finding “interesting” keywords would be bigger)
  2. Click on the “chat log” link
  3. On the log page, click on the “Analyze” button. The keywords will be highlighted.
  4. Choose “Flickr” or “Amazon” radio button
  5. Click on a keyword and see window with service results
  6. Close window and repeat with different service and keywords.

The application features three action controllers – IndexController for the main chat, LogController for the log window and ServiceController implementing the conntection to services.

The data model, it uses SimpleXML to operate the chat data file, and Zend_Search_Lucene to index and search the log.

In this application, following components were used:

The application also uses Zend_Json::fromXML function, which is part of the xml2json proposal and was recently added to the core. It’s planned to be part of ZF 1.1 release, before that you will need Zend_Json from the incubator or SVN.

You will need Apache server to run the application. Unpack it into chat/ subdirectory in your document root, and allow .htaccess to work there (AllowOverride All). You will also need Zend Framework library to be in include_path. chat/data subdirectory should be writable by the Apache user.