You are here

function forward_block in Forward 6

Same name and namespace in other branches
  1. 5 forward.module \forward_block()

Implementation of hook_block().

File

./forward.module, line 1257

Code

function forward_block($op = 'list', $delta = 0, $edit = array()) {
  switch ($op) {
    case 'list':
      $blocks[0]['info'] = t('Most Emailed');
      $blocks[0]['cache'] = BLOCK_NO_CACHE;
      $blocks[1]['info'] = t('Forward');
      $blocks[1]['cache'] = BLOCK_NO_CACHE;
      return $blocks;
    case 'configure':
      switch ($delta) {
        case 0:
          $block_options = array(
            /*'today' => t('Most Emailed Today'),
              'week' => t('Most Emailed This Week'),*/
            'allTime' => t('Most Emailed of All Time'),
            'recent' => t('Most Recently Emailed'),
          );
          $form['forward_block_type'] = array(
            '#type' => 'radios',
            '#title' => t('Block Type'),
            '#default_value' => variable_get('forward_block_type', ""),
            '#options' => $block_options,
            '#description' => t('Choose the block type'),
          );
          return $form;
        case 1:
          $form['forward_block_form'] = array(
            '#type' => 'radios',
            '#title' => t('Display form in block'),
            '#default_value' => variable_get('forward_block_form', variable_get('forward_form_type', 'link')),
            '#options' => array(
              'form' => 'form',
              'link' => 'link',
            ),
            '#description' => t('Choose whether to display the full form in the block or just an email this page link.'),
          );
          return $form;
      }
      break;
    case 'save':
      switch ($delta) {
        case 0:
          variable_set('forward_block_type', $edit['forward_block_type']);
          break;
        case 1:
          variable_set('forward_block_form', $edit['forward_block_form']);
          break;
      }
      break;
    case 'view':
      switch ($delta) {
        case 0:
          if (user_access('access content')) {
            switch (variable_get('forward_block_type', 'allTime')) {

              /*case 'today':
                  $pastday = time()-(24 * 60 * 60);
                  $query="SELECT n.nid, n.title, count(*) AS cnt FROM {forward_log} s LEFT JOIN {node} n ON s.nid = n.nid WHERE s.type='sent' AND n.status=1 AND timestamp > ". $pastday .' GROUP BY n.nid, n.title ORDER BY cnt DESC';
                  $block['subject'] = t("Today's Most Emailed");
                  $block['content'] = node_title_list(db_query_range($query, 0, 5));
                  break;
                case 'week':
                  $pastweek = time()-(7 * 24 * 60 * 60);
                  $query="SELECT n.nid, n.title, count(*) AS cnt FROM {forward_log} s LEFT JOIN {node} n ON s.nid = n.nid WHERE s.type='sent' AND n.status=1 AND timestamp > ". $pastweek .' GROUP BY n.nid, n.title ORDER BY cnt DESC';
                  $block['subject'] = t("This Week's Most Emailed");
                  $block['content'] = node_title_list(db_query_range($query, 0, 5));
                  break;*/
              case 'allTime':
                $query = "SELECT n.nid, n.title, f.* FROM {forward_statistics} f LEFT JOIN {node} n ON f.nid = n.nid WHERE forward_count > 0 ORDER BY f.forward_count DESC";
                $block['subject'] = t("Most Emailed");
                $block['content'] = node_title_list(db_query_range($query, 0, 5));
                break;
              case 'recent':
                $query = "SELECT n.nid, n.title, f.* FROM {forward_statistics} f LEFT JOIN {node} n ON f.nid = n.nid ORDER BY f.last_forward_timestamp DESC";
                $block['subject'] = t("Most Recently Emailed");
                $block['content'] = node_title_list(db_query_range($query, 0, 5));
                break;
            }
            return $block;
          }
          break;
        case 1:
          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', $img, $title, '', array(
                    'class' => 'forward-icon',
                  ));
                  $html = TRUE;
                  break;
                case 2:
                  $img = drupal_get_path('module', 'forward') . '/forward.gif';
                  $title = theme('image', $img, $title, '', array(
                    'class' => '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' => 'forward-page',
                ),
                'query' => 'path=' . $path,
              ));
            }
            else {
              $content = drupal_get_form('forward_form', $_GET['q'], $node->title);
            }
            return array(
              'subject' => t('Forward'),
              'content' => $content,
            );
          }
      }
  }
}