Sunday, June 12, 2011

Function ereg() is deprecated

I have been working with my Drupal site for slightly over a month now, and I have seen various warnings appear on different screens.  These warnings did not affect the site so I did not dedicate much time to resolving these issues.  Today I finally felt the urge to resolve these issues.  The number of messages that Drupal must process and display on the page greatly increased the time required to display the page.  I can reproduce the issue by going to logging in as administrator and going to Administer, then Site Building, and then Modules.

I decided to focus on the warning Function ereg() is deprecated in /var/www/site/includes/ on line 895 because this particular warning appeared more times than any other.  A page dedicated to this warning can be found on Drupal's site.  The comments on this page suggest many possible resolutions.  One solution suggested modifying line 895 of file/var/www/site/includes/ (the offending line mentioned by the error message).

The solution suggested adding an '@' before the function call ereg() (the function call mentioned by the error message.  I had never heard of this operator before, so I did a little research.  I finally found the this page on which explains that when an '@' symbol is "prepended to an expression in PHP, any error messages that might be generated by that expression will be ignored."  I made the required modification and the warning disappeared.

I wouldn't really call this a fix because this does not solve the underlying issue; it is a band-aid.  So what is the underlying issue?  The function ereg() is deprecated in php 5.3 according to this page on, and the function preg_match(), which is faster and uses a Perl-compatible regular expression syntax, should be used instead.

According to a comment by VM on Drupal's site, Drupal 6 does not support PHP 5.3 until Drupal version 6.14.  The ideal solution to this problem (and probably every other warning I see) is to upgrade from Drupal version 6.9 to 6.14 (or higher).  I read an article on Drupal's site on upgrading which involved backing up my site and it sounded like quite a bit of work.  I felt this would be a good article for another post on another day.  So I decided to go the route of adding '@' before the function call to suppress the error messages.

Thanks for reading.

Tuesday, June 7, 2011

Introduction to Views

Let's say that you wanted to display a list of the last five page nodes created on your site.  The site administrator could keep track of this manually, but this may occupy much of the administrator's time and energy.  The author of the page could remember to update a list, but this may lead to mistakes which may taint the list.  Fortunately we can simply install the Views module for this functionality.

I downloaded the Views module here.  After copying the files to my site's /module/ directory, I enabled the Views module as well as Views exporter and Views UI.  After enabling the module, the Views area link appeared under the Administer and Site Building area.  From here I can administer views for the entire site.

 I clicked the Add button to add a new view to my site.  I entered the name "view_pages" and selected "Node" for a view type.  The view type determines which arguments, fields, sort criteria, and filters can be used to customize the view. 

A view consists of one or more Displays and the default settings.  The different display types include the following:
  • Attachment
  • Block
  • Date Browser
  • Feed
  • Page
There may be more display types available depending on which modules you have installed.  For my purpose, I chose to create two displays:  newest_additions and latest_updates.  The newest_additions displays the newest content nodes created while latest_updates displays the content nodes that have been most recently updated. 

Essentially, these two displays are the same except for the name, fields, and sort criteria.  For newest_additions I clicked on the name to change it to something meaningful.  I then added some fields for the Title of the node, the post date of the node, and a link to view the node.  Finally, I added the post date as sort critera and chose to sort in descending.

I added the latest_updates display in the same way as I added the newest_additions display.  I simply used the node updated date instead of the node post date.  I also used the node updated date as the sort criteria instead of the note post date.

I became a bit confused when my views did not look correct on my site.  They did not look correct because each of my displays used the default settings instead of the display's overridden settings.  To override the settings, I clicked the Override button when editing that settings.  

I then clicked the Save button and my view was ready to be added to a site.  Because my displays were added as Blocks, I could go to the Blocks administration screen (Administer->Site Building->Block) and drag my two blocks to the right sidebar and Voila:  I could see my Latest Updates and Newest Additions views on the right sidebar.

So that is my introduction to views.  I have other ideas for views and I will write another post about them when I have implemented them.

Until then thanks for reading!