You are here

function recipe_block in Recipe 6

Same name and namespace in other branches
  1. 5 recipe.module \recipe_block()

Implementation of hook_block().

File

./recipe.module, line 592
recipe.module - share recipes

Code

function recipe_block($op = 'list', $delta = 0, $edit = array()) {

  // The $op parameter determines what piece of information is being requested.
  switch ($op) {
    case 'list':

      // If $op is "list", we just need to return a list of block descriptions.
      // This is used to provide a list of possible blocks to the administrator,
      // end users will not see these descriptions.
      $blocks[RECIPE_BLOCK_RECENT]['info'] = t('Recipe: Newest recipes');
      if (variable_get('recipe_summary_location', 0) == 1) {
        $blocks[RECIPE_BLOCK_SUMMARY]['info'] = t('Recipe: Recipe summary');
      }
      return $blocks;
    case 'view':

      // If $op is "view", then we need to generate the block for display
      // purposes. The $delta parameter tells us which block is being requested.
      switch ($delta) {
        case RECIPE_BLOCK_RECENT:

          // The subject is displayed at the top of the block. Note that it
          // should be passed through t() for translation.
          $block['subject'] = t('Newest Recipes');

          // The content of the block is typically generated by calling a custom
          // function.
          $result = db_query_range(db_rewrite_sql("SELECT n.nid, n.title, n.uid, u.name FROM {node} n INNER JOIN {node_revisions} r ON n.vid = r.vid INNER JOIN {users} u ON n.uid = u.uid WHERE n.type='recipe' AND n.status =1 ORDER BY n.created DESC"), 0, 5);
          $block["content"] = node_title_list($result);
          break;
        case RECIPE_BLOCK_SUMMARY:
          if (variable_get('recipe_summary_location', 0) == 1) {
            if (user_access('access content')) {
              if (arg(0) == 'node' && is_numeric(arg(1)) && (arg(2) == '' || arg(2) == 'view')) {
                $node = node_load(arg(1));

                // Don't show the yield form, it doesn't fit.
                $node->yield_form_off = 1;
                if ($node->type == 'recipe') {
                  $block['subject'] = variable_get('recipe_summary_title', t('Summary'));
                  $block['content'] = theme('recipe_summary', $node, array(
                    'show_title' => FALSE,
                  ));
                  return $block;
                }
              }
            }
          }
          break;
      }
      return $block;
  }
}