API abuse

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));  



Sod translators, abuse t()

Not all CVS application reviews result in a decline of the application. Many get through even though it contains some "bugs". Here's an example that is in some sense classic.

Lets look at a snippet...

  1. $warning = variable_get('foo_warning', NULL);
  2.  
  3. $tokens = array(
  4.   '%user' => $account->name,
  5.   '!edit_url' => url('user/'.$account->uid.'/edit',array('absolute'=>TRUE)),
  6.   '%expiry_date' => date("F j, Y", $expiry_date),
  7.   '%days_left' => round(($expiry_date - $today[0]) / 86400),
  8. );
  9.  
  10. // ... and then
  11.  
  12. drupal_set_message(t($warning, $tokens), 'warning');



Syndicate content