You are here

function forward_block_view in Forward 7

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

Implements hook_block_view().

File

./forward.module, line 1504

Code

function forward_block_view($delta) {
  switch ($delta) {
    case 'stats':
      if (user_access('access content')) {
        $block = array();
        $query = db_select('forward_statistics', 'f');
        $query
          ->leftJoin('node', 'n', 'f.nid = n.nid');
        $query
          ->fields('f');
        $query
          ->fields('n', array(
          'nid',
          'title',
        ));
        $query
          ->range(0, 5);
        $query
          ->addTag('node_access');
        switch (variable_get('forward_block_type', 'allTime')) {
          case 'allTime':
            $query
              ->condition('f.forward_count', 0, '>');
            $query
              ->orderBy('f.forward_count', 'DESC');
            $block['subject'] = t("Most Emailed");
            $block['content'] = node_title_list($query
              ->execute());
            break;
          case 'recent':
            $query
              ->orderBy('f.last_forward_timestamp', 'DESC');
            $block['subject'] = t("Most Recently Emailed");
            $block['content'] = node_title_list($query
              ->execute());
            break;
        }
        return $block;
      }
      break;
    case 'form':
      if (user_access('access forward')) {
        drupal_add_css(drupal_get_path('module', 'forward') . '/forward.css');
        if (variable_get('forward_block_form', 'link') == 'link') {
          $title = check_plain(t(variable_get('forward_link_title', 'Email this !type'), array(
            '!type' => t('page'),
          )));
          $html = FALSE;
          switch (variable_get('forward_link_style', 0)) {
            case 1:
              $img = drupal_get_path('module', 'forward') . '/forward.gif';
              $title = theme('image', array(
                'path' => $img,
                'alt' => $title,
                'title' => '',
                'attributes' => array(
                  'class' => array(
                    'forward-icon',
                  ),
                ),
              ));
              $html = TRUE;
              break;
            case 2:
              $img = drupal_get_path('module', 'forward') . '/forward.gif';
              $title = theme('image', array(
                'path' => $img,
                'alt' => $title,
                'title' => '',
                'attributes' => array(
                  'class' => array(
                    'forward-icon',
                    'forward-icon-margin',
                  ),
                ),
              )) . $title;
              $html = TRUE;
              break;
          }
          $path = $_GET['q'];
          $content = l($title, 'forward', array(
            'title' => $title,
            'html' => $html,
            'attributes' => array(
              'title' => t('Forward this page to a friend'),
              'class' => array(
                'forward-page',
              ),
            ),
            'query' => array(
              'path' => $path,
            ),
          ));
        }
        else {
          if (arg(0) == 'node' && is_numeric(arg(1)) && !arg(2)) {
            $node = node_load(arg(1));
            $content = drupal_get_form('forward_form', 'node/' . $node->nid, $node->title);
          }
          else {
            $content = drupal_get_form('forward_form', $_GET['q']);
          }
        }
        return array(
          'subject' => t('Forward'),
          'content' => $content,
        );
      }
  }
}