Category Archives: PHP

DX Image Box – Lighbox Croogo plugin

Today I released on github DX Image Box. It's a Fancybox wrapper that hooks in the Croogo plugin system so a developer could easily integrate lightbox integration with two lines of code. 

Last time I was doing Croogo work was in December, but recently I had to do some development on small Croogo-based projects and due to the chance that some of the features are going to be reused later, decided to do some plugin work. This is the first plugin released and I will consider contributing another one or two small thanks to Fahad's work on Croogo.

del.icio.us Digg DZone Facebook Google Google Reader Magnolia reddit SlashDot Technorati ReadMe.ru Dobavi.com Dao.bg Lubimi.com Ping.bg Pipe.bg Svejo.net Web-bg.com

Twitter using Drupal

Following Dries and Rob Douglas on Twitter I mentioned in the latest updates that Twitter started using Drupal for community site for the dev team. Dries has described in his blog http://buytaert.net/twitter-using-drupal that Twitter migrated to Drupal using one of their community platforms that I really enjoy. While WP has BuddyPress (and that could be ran separately as well) Drupal has few configurations for social platforms and seems like Twitter is using one of them.

There we are - https://dev.twitter.com/ . I would really like to see a feedback from the Twitter dev team for the usability of the platform. It's a well known fact that Drupal is a great platform for developers but has an non-intuitive interface for end clients which is one of the reasons WordPress is so popular right now. 

del.icio.us Digg DZone Facebook Google Google Reader Magnolia reddit SlashDot Technorati ReadMe.ru Dobavi.com Dao.bg Lubimi.com Ping.bg Pipe.bg Svejo.net Web-bg.com

ddsmoothmenu arrow dynamic paths

Working with ddsmoothmenu Smooth Navigation Menu by Dynamic Drive for a WordPress project I encountered a stupid lack of setting to provide image paths dynamically. This is a jQuery-based dropdown menu which seems and works fine but requires a static path to the images. Only two images though, for the arrows down and right, but it would be a serious issue when releasing a website or migrating to a new server.

So I decided to add a new setting configurable through the JavaScript call in your call-menu file where you could use php/java/python/whateva to retrieve the correct path dynamically and just pass it. I'm using v.1.5 and I did 2 corrections:

  1. in the ddsmoothmenu.js file replaced all smoothmenu.arrowimages strings with setting.arrowimages (just changing 'smoothmenu' to 'setting' in these three lines). There are 5 strings to be replaced at lines 75 to 77. What I do is add a new setting for them in the next section.
  2. Adding the paths to the images as a setting. So at the end my call includes the dynamic path to be used in the menus. Since I'm using WordPress, here there is my code for calling the menu:
  1.  
  2. ddsmoothmenu.init({
  3. mainmenuid: "header_top_menu",
  4. orientation: 'h',
  5. classname: 'ddsmoothmenu',
  6. arrowimages: {down:['downarrowclass', '<?php bloginfo("template_url"); ?>/img/down.gif', 23], right:['rightarrowclass', '<?php bloginfo("template_url"); ?>/img/right.gif']},
  7. contentsource: "markup"
  8. });
  9.  
del.icio.us Digg DZone Facebook Google Google Reader Magnolia reddit SlashDot Technorati ReadMe.ru Dobavi.com Dao.bg Lubimi.com Ping.bg Pipe.bg Svejo.net Web-bg.com

Subscribe to comments has to be integrated

WordPress is still number 1 platform for blogging. Top used blogging functionality is blog posting and commenting to blog threads. 

However, people that comment on a blog post normally have no way to get feedback eventually if anyone comments back in the same post. The post author (and administrator) receives notification for the comment but the comment author, on the other hand, has no natural way to be pinged back for a reply. This is a serious leak in the WP standard functionality. It is at least unethical not to inform someone for the reply (which might occur in a day, month, year even more).

WordPress comes with a standard feed for latest posts and feed for recent comments as well. However subscribing for all comments in a blog or finding a specific thread to subscribe for is not usable and not practical as well. The solution is the Subscribe To Comments plugin that adds a checkbox to the comment form which allows one to subscribe for further comments in the same thread. This is completely optional and up to ones preferences, but instead of breaking the whole conversation because of the 'echoing' this provides the instrumentation for a real communication.

WordPress.com uses Subscribe To Comments for 2 years or something, it's integrated in their web service. So why is it not included in the platform yet?

del.icio.us Digg DZone Facebook Google Google Reader Magnolia reddit SlashDot Technorati ReadMe.ru Dobavi.com Dao.bg Lubimi.com Ping.bg Pipe.bg Svejo.net Web-bg.com

Two students presented CodeIgniter research projects

Beyond the training and consulting business I am also part-time teacher for the Technology School Electronic Systems - Sofia and I do teach web technologies and WordPress. As the representer of the Web 2.0 world I took part in mentoring 2 teams for their diploma research assignments based on CodeIgniter.

One of the projects was a music web portal for artists, media, albums and more. Encyclopedia format for music addicts that could easily transform in a front-end manner using the same database structure. It was meant to start as a hard rock and metal project and later easily skinned and themed into other music categories as well. I really do hope to see it ready, as I already saw most pages and the database structure which extended the modeling structure that exists by default in CodeIgniter.

The other project is a social network for places. A mix of the foursquare listing of categories and places and the Golden Pages catalogue, but with better interaction for users, taking advantage of the localization browser services and latest HTML 5 fine tunes. It has a pretty neat design and more than 30 DB tables at the moment and is going to be ready soon. Users in the site could interact to each other and follow the new places being added with their comments. The basic idea is filling in a database of places with location (easy to find in a Google Map) with comments, ratings and more that is built on the CodeIgniter framework. This is a great profiler that helps the PR managers of a company or a restaurant to improve the quality and social skills and keeps the good rating online.

I'm glad to see the enthusiasm of the development process and the improving code quality and feature set. Both teams work hard and would probably take part in competitions with their projects.

del.icio.us Digg DZone Facebook Google Google Reader Magnolia reddit SlashDot Technorati ReadMe.ru Dobavi.com Dao.bg Lubimi.com Ping.bg Pipe.bg Svejo.net Web-bg.com

Access beforeFilter set variable in controller (CakePHP)

In a CakePHP application we could define an intermediate abstraction of a controller called AppController. The concept is having a Controller class defined by Cake core, writing controllers for our project and defining app_controller.php file for our common functions repeated in every controller.

In this case we usually use beforeFilter or beforeRender method in AppController in order to define some data to be transferred automatically in every controller. More about app_controller and callback functions.

When a variable is set in beforeFilter, it could be used with it's name later in CakePHP views. For example:

 

  1.  
  2. $this->set('products', array('P1' => 'Pizza', 'P2' => 'Water'));

 

Any view later:

 

  1.  
  2. <?php echo $products['P1']; ?>
  3.  

But that variable could not be accessed directly in a controller function. In this case we could use viewVars array in order to access beforeFilter set variable in other controller method, which solves our problem: 

 

  1.  
  2. function test() {
  3. $products = $this->viewVars['products'];
  4. $product_1 = $products['P1'];
  5. }
  6.  

 

 

del.icio.us Digg DZone Facebook Google Google Reader Magnolia reddit SlashDot Technorati ReadMe.ru Dobavi.com Dao.bg Lubimi.com Ping.bg Pipe.bg Svejo.net Web-bg.com

Easy AJAX calls in CakePHP

 CakePHP is a great framework for rapid development of web based applications that serves well the principles of DRY (Do not Repeat Yourself). However unlike other web frameworks, CakePHP is not (and probably will not) fully AJAX based (for instance, you could check the list of PHP Ajax frameworks or try some Java/Python implementations such as Google Web Toolkit and Pyjamas). 

In no way the statement above means that you cannot do some flexible and dynamic client-side calls into your CakePHP site. You could freely use plain Javascript in your views, use the JS helper of CakePHP or add some prototype/jQuery library and take advantage of its features. Beyond all that possibilities you could use one more helper of Cake - the AJAX helper. The AJAX helper provides an intuitive interface for maintaining some standard task with only few lines of code.

Some of the methods that you can use with the Ajax helper:

  • link
  • remoteFunction
  • form
  • observeField
  • autoComplete
  • drag & drop

and few more that you could find in the link above. 

The standard 1.2 implementation expects prototype and scriptaculous in order to run properly. However you could easily replace them with jQuery (and jQuery UI) libraries. Some examples on that: http://www.cakephp.bee.pl/

 

del.icio.us Digg DZone Facebook Google Google Reader Magnolia reddit SlashDot Technorati ReadMe.ru Dobavi.com Dao.bg Lubimi.com Ping.bg Pipe.bg Svejo.net Web-bg.com

How to hide load time comment for AJAX calls in CakePHP

 CakePHP puts some debug info after page load including the load time of the page. Even though it is an HTML comment line, it does affect returned data for AJAX calls (and not only). 

If we do return JSON, we could set the returned type for json-like and then json_encode the data using the $this->autoRender = false; clause. However, if we expect some specific data (like a boolean yes/no result), we would have problems with the debug feature of CakePHP.

So we could disable the debugging feature of Cake only for AJAX calls adding this statement to the beforeFIlter() action of the app_controller.php:

 

  1. if ( $this->RequestHandler->isAjax() ) {
  2. Configure::write('debug',0);
  3. }

del.icio.us Digg DZone Facebook Google Google Reader Magnolia reddit SlashDot Technorati ReadMe.ru Dobavi.com Dao.bg Lubimi.com Ping.bg Pipe.bg Svejo.net Web-bg.com

Motoclub.BG – our new moto project

 

We delivered Motoclub.BG and now it's available and accessible. The web portal is an online version of a magazine for motorcycle sports and vehicles, ATVs and others. As the bikers' favourite music is rock/metal, breaking news on concerts and live events in clubs are posted there as well.

The portal has few interesting sections for magazine online overview. You could find news and specialised articles, moto calendar with coming events, catalogue with specifications for different brands and so on. Filters and archives provide searching via keywords or month/year ranges. RSS feed on latest news is staying in the left column, next to the invitation to the Facebook group of the website.

The project is CakePHP based with MySQL database behind. I've implemented a few custom solutions on user management and RSS aggregation which I'm going to describe later.

del.icio.us Digg DZone Facebook Google Google Reader Magnolia reddit SlashDot Technorati ReadMe.ru Dobavi.com Dao.bg Lubimi.com Ping.bg Pipe.bg Svejo.net Web-bg.com