You are here

function freelinking_block in Freelinking 6

Same name and namespace in other branches
  1. 5 freelinking.module \freelinking_block()
  2. 6.2 freelinking.module \freelinking_block()

File

./freelinking.module, line 178

Code

function freelinking_block($op = 'list', $delta = 0) {
  switch ($op) {
    case 'list':
      $blocks[0]['info'] = t('Freelink targets that need to be created');
      $blocks[0]['cache'] = BLOCK_NO_CACHE;
      return $blocks;
      break;
    case 'configure':
      $form['freelinking_block_options'] = array(
        '#type' => 'fieldset',
        '#title' => t('Freelinking Block Options'),
      );
      for ($i = 5; $i <= 30; $i = $i + 5) {
        $options[$i] = $i;
      }
      $form['freelinking_block_options']['freelinking_blocknum'] = array(
        '#title' => t('Number of non-existing link phrases to show'),
        '#type' => 'select',
        '#options' => $options,
        '#default_value' => variable_get('freelinking_blocknum', '10'),
        '#description' => t('Number of phrases to show in the block.'),
      );
      return $form;
      break;
    case 'view':
      switch ($delta) {
        case 0:
          $query = 'SELECT * FROM {freelinking} WHERE path LIKE "node/add%" ORDER BY RAND()';
          $result = db_query($query);
          $i = 0;
          $content = '';
          while ($freelink = db_fetch_object($result)) {
            if ($i == variable_get('freelinking_blocknum', 10)) {

              // we're done
              break;
            }
            $items[] = l(urldecode($freelink->phrase), $freelink->path, array(), $freelink->args);
            $i++;
          }

          // endwhile looping through flpairs
          $block['subject'] = t('Create This Content');
          $block['content'] = theme('item_list', $items);
          return $block;
        default:
          break;
      }

    // endswitch $delta
    default:
      break;
  }

  // endswitch $op
}