Drupal Planet

Selection of postings suitable for Drupal Planet feeds.

Module/theme namespacing issues

Here's a lovely function defined in a module offered for contribution...

  1. function myTruncate($string, $limit, $break=".", $pad="...") {
  2.   // return with no change if string is shorter than $limit  
  3.   if(strlen<($string) <= $limit) return $string;
  4.   // is $break present between $limit and the end of the string?  
  5.   if(false !== ($breakpoint = strpos<($string, $break, $limit))) {
  6.     if($breakpoint < strlen<($string) - 1) {
  7.       $string = substr<($string, 0, $breakpoint) . $pad;
  8.     }
  9.   }
  10.   return $string;
  11. }



Sod input formats, it's ok for me

Today this arrived on my desk...

  1. $node->format = 2; // Allow for HTML in Node

This snippet was from code that was about to create a new node. The body of this node came in via an external XML/RSS feed.

OK buddy, you may trust this source but can you expect everyone you are going to share your module with should inherit your implict trust?

In fact, I saw this in two CVS applications today. Both declined (for more than just this).



Problems with DB abstraction

In a previous post< we have described in some detail various aspects of selecting nodes and terms ensuring that Drupal's node access system is respected. However, new and exciting examples continue to arrive at the CVS review doorstep.

Here's some more fopars we deal with on a regular basis...

  1. $sql = "SELECT nid FROM {node} WHERE type = '%s' AND title = '%s' LIMIT 1";
  2. $duplicate = db_result(db_query($sql, 'story', $item->title));  



Syndicate content