You are here

function forward_block_view in Forward 7.3

Same name and namespace in other branches
  1. 7 forward.module \forward_block_view()
  2. 7.2 forward.module \forward_block_view()

Implements hook_block_view().

File

./forward.module, line 1378
Allows forwarding of entities by email, and provides a record of how often each has been forwarded.

Code

function forward_block_view($delta) {
  switch ($delta) {
    case 'stats':
      if (user_access('access content')) {
        $block = array();
        $entity_type = variable_get('forward_block_entity_type', 'node');
        $query = new EntityFieldQuery();
        $query = $query
          ->entityCondition('entity_type', $entity_type);
        $query = $query
          ->range(0, 5);

        // Limit to published nodes or active users
        if ($entity_type == 'node' || $entity_type == 'user') {
          $query = $query
            ->propertyCondition('status', 1);
        }
        switch (variable_get('forward_block_type', 'allTime')) {
          case 'allTime':
            $query = $query
              ->addTag('stats_alltime');
            $block['subject'] = t('Most Emailed of All Time');
            $block['content'] = _forward_entity_title_list($query
              ->execute());
            break;
          case 'recent':
            $query = $query
              ->addTag('stats_recent');
            $block['subject'] = t('Most Recently Emailed');
            $block['content'] = _forward_entity_title_list($query
              ->execute());
            break;
        }
        return $block;
      }
      break;
    case 'form':
      if (user_access('access forward')) {
        $path = $_GET['q'];
        $id = _forward_entity_from_path($path, $entity_type, $entity, $bundle);
        if (!$id || _forward_show_on_entity($entity_type, $entity, $bundle)) {
          if (variable_get('forward_block_form', 'link') == 'link') {
            $content = theme('forward_link', array(
              'entity_type' => $entity_type,
              'entity' => $entity,
              'path' => $path,
              'block' => TRUE,
            ));
          }
          else {
            if ($id) {
              $entity_wrapper = entity_metadata_wrapper($entity_type, $entity);
              $content = drupal_get_form('forward_form', NULL, $entity_wrapper);
            }
            else {
              $content = drupal_get_form('forward_form', $path);
            }
          }
          return array(
            'subject' => t('Forward'),
            'content' => $content,
          );
        }
      }
  }
}