Updating my custom module to Drupal 7 I have updated a module from Drupal 6 to Drupal 7, but the following code doesn't work anymore. I have updated the .info file, but the module still doesn't work.

function header_image_block($op='list',$delta=0,$edit=array()) {
   if ($op=='list') {
     $blocks[0] = array(
       'info' =&gt; t('Header image'),
     );
     return $blocks;
   }

   elseif ($op == 'view') {
     $block = array(
       'subject' =&gt; 'Header Images',
       'content' =&gt; changeHeader(),
     );
     return $block;
   }
}

function changeHeader() {
  $output = '';
  $output = '&lt;img src = "' . base_path() . 'sites/all/themes/optimiza/images/imge-header.png" border = "0" /&gt;';
  if (arg(0) == 'node' &amp;&amp; is_numeric(arg(1))) {
    $nid = arg(1);
    $node = node_load($nid);
    $path = $node-&gt;field_head_img[0]['filepath'];
    if ($path != '') {
      $output = '&lt;img src = "' . base_path() . $path . '" border = "0" /&gt;';
    }
  }
  return $output;
}
In Drupal 7, instead of hook_block() there are more hooks:


hook_block_info()
hook_block_configure()
hook_block_save()
hook_block_view()


In short, you need to split the Drupal 6 code for hook_block() between those hooks.

As side notes:


Every function implemented from a module should be prefixed by the module short name
To load the node, you should use the following code.

if ($node = menu_get_object()) {
  // The page is a node page.
}  

To access the content of a field, you should use the following code.

$items = field_get_items('node', $node, 'field_head_img');
$path = $items[0]['filepath'];

To output an image, you should use theme('image'), or theme('image_style'). As you are outputting a field, you should use field_view_field(), as in the following code.

$output = field_view_field('node', $node, 'field_head_img');