You are here

function _quotes_block_configure in Quotes 7

Same name and namespace in other branches
  1. 5 quotes.module \_quotes_block_configure()

Quotes block configuration.

Parameters

int $delta: The block ID that we are working with.

Return value

array returns the form data for further processing.

1 call to _quotes_block_configure()
quotes_block_configure in ./quotes.module
Implements hook_block_configure().

File

./quotes.module, line 1100
The quotes module allows users to maintain a list of quotes that can be displayed in any number of administrator-defined quote blocks.

Code

function _quotes_block_configure($delta) {
  global $_quotes_subs;
  drupal_add_js(drupal_get_path('module', 'quotes') . '/js/quotes.js');
  $none_opt = '- ' . t('none') . ' -';
  $block = db_query("SELECT qb.* FROM {quotes_blocks} qb WHERE bid = :bid", array(
    ':bid' => $delta,
  ))
    ->fetchObject();
  $any_filters = $block->nid_filter . $block->aid_filter . $block->rid_filter . $block->uid_filter . $block->tid_filter;
  $block->aid_filter = explode(',', $block->aid_filter);
  $block->rid_filter = explode(',', $block->rid_filter);
  $block->uid_filter = explode(',', $block->uid_filter);
  $block->tid_filter = explode(',', $block->tid_filter);

  // Get authors.
  $authors = quotes_get_authors(TRUE);

  // Get roles.
  $roles = user_roles(FALSE, 'create quotes');
  foreach (user_roles(FALSE, 'import quotes') as $rid => $role) {
    $roles[$rid] = $role;
  }
  foreach (user_roles(FALSE, 'edit own quotes') as $rid => $role) {
    $roles[$rid] = $role;
  }
  $roles[-1] = $none_opt;
  asort($roles);

  // Get users.
  $users = array(
    -1 => $none_opt,
  );
  $users[0] = variable_get('anonymous', t('Anonymous'));
  $result = db_query("SELECT DISTINCT u.uid, u.name FROM {users} u LEFT JOIN {users_roles} ur ON ur.uid = u.uid WHERE u.uid = 1 OR ur.rid IN (" . implode(',', count($roles) ? array_keys($roles) : array(
    0,
  )) . ")");
  foreach ($result as $row) {
    $users[$row->uid] = $row->uid ? $row->name : variable_get('anonymous', t('Anonymous'));
  }
  asort($users);
  $form = array();
  if ($delta) {
    $form['bid'] = array(
      '#type' => 'value',
      '#value' => $delta,
    );
  }
  $form['quotes'] = array(
    '#type' => 'fieldset',
    '#title' => 'Quotes specific settings',
    '#collapsible' => TRUE,
    '#collapsed' => FALSE,
    '#prefix' => '<div id="quotes-block-settings">',
    '#suffix' => '</div>',
  );
  $form['quotes']['block_type'] = array(
    '#type' => 'radios',
    '#title' => t('Type'),
    '#required' => TRUE,
    '#default_value' => $block->block_type == 1 ? 1 : 0,
    // Note the order of these options is important!
    '#options' => array(
      t('Random'),
      t('Most recent'),
      t('Unpublished'),
    ),
    '#description' => t('"Random" will choose a published quote at random. "Most recent" will display the most recently updated quotes. "Unpublished" will display quotes that are marked as not published (awaiting approval).'),
    '#prefix' => '<div class="quotes-radios">',
    '#suffix' => '</div>',
  );
  $_quotes_subs = array(
    '%' . t('interval') => NULL,
    '%' . t('bid') => NULL,
    '%' . t('title') => NULL,
    '%' . t('nid') => NULL,
    '%' . t('user') => NULL,
  );
  $sub_str = implode(', ', array_keys($_quotes_subs));
  $form['quotes']['name'] = array(
    '#type' => 'textfield',
    '#title' => t('Name'),
    '#required' => TRUE,
    '#default_value' => $block->name,
    '#description' => t("Enter a unique name for this block. This will identify the block on the !block administration page and be used for the default block title. The name may include any of: '%subs'.", array(
      '!block administration page' => l(t('block administration page'), 'admin/structure/block'),
      '%subs' => $sub_str,
    )),
  );
  $title_opts = array(
    0 => t('No title'),
    1 => t('Title linked to quote'),
    2 => t('Plain text'),
  );
  $form['quotes']['show_titles'] = array(
    '#type' => 'radios',
    '#options' => $title_opts,
    '#title' => t('Show titles'),
    '#required' => FALSE,
    '#default_value' => $block->show_titles,
    '#description' => t('If this option is selected, the titles of the quotes in this block will be shown.'),
    '#prefix' => '<div class="quotes-radios">',
    '#suffix' => '</div><div class="clear-block"></div>',
  );
  $form['quotes']['show_citation'] = array(
    '#type' => 'checkbox',
    '#title' => t('Show citation?'),
    '#default_value' => isset($block->show_citation) ? $block->show_citation : FALSE,
    '#description' => t('If this option is selected, the citation for the quote will be included in blocks.'),
  );
  $form['quotes']['max_length'] = array(
    '#type' => 'select',
    '#title' => t('Maximum quote length'),
    '#options' => drupal_map_assoc(array(
      0,
      10,
      20,
      30,
      40,
      50,
      60,
      70,
      80,
      90,
      128,
      192,
      256,
      320,
      384,
      448,
      512,
    )),
    '#default_value' => $block->max_length,
    '#description' => t('This will limit the length of a quote shown in the block. A value of zero (0) means no limit.'),
  );
  $form['quotes']['block_count'] = array(
    '#type' => 'select',
    '#options' => drupal_map_assoc(array(
      1,
      2,
      3,
      4,
      5,
      6,
      7,
      8,
      9,
      10,
      15,
      20,
      25,
      30,
      40,
      50,
      75,
      100,
    )),
    '#title' => t('Number of quotes in this block'),
    '#default_value' => $block->count,
    '#description' => t('This sets the maximum number of quotes that will be displayed in this block. It is suggested that no more than 5 quotes per block be used when the block type is set to "Random".'),
  );
  $form['quotes']['view_text'] = array(
    '#type' => 'textfield',
    '#title' => t('Block "View" link text'),
    '#maxlength' => 64,
    '#default_value' => $block->view_text,
    '#description' => t('The text of the link to view the quote from a block. Leaving this field blank disables the link.<br />This is only used when comments are enabled!'),
  );
  $form['quotes']['block_more'] = array(
    '#type' => 'textfield',
    '#title' => t('"More" link text'),
    '#maxlength' => 64,
    '#default_value' => $block->more_text,
    '#description' => t('This sets the text that will display on the "more" link at the bottom of the block. Leave it blank for no link. This is only available for a "Random" block.'),
  );
  $frequency = drupal_map_assoc(range(0, 100, 10));
  $form['quotes']['rand_freq'] = array(
    '#type' => 'select',
    '#title' => t('How often block will show'),
    '#options' => $frequency,
    '#default_value' => isset($block->rand_freq) ? $block->rand_freq : 100,
    '#description' => t('This sets the frequency with which the block will be shown. 100% is all the time; 0% is none of the time.'),
  );
  $form['quotes']['filters'] = array(
    '#type' => 'fieldset',
    '#title' => 'Quotes Filters',
    '#collapsible' => TRUE,
    '#collapsed' => empty($any_filters),
  );
  $form['quotes']['filters']['nid_filter'] = array(
    '#type' => 'textarea',
    '#title' => t('Node filter'),
    '#rows' => 2,
    '#default_value' => $block->nid_filter,
    '#description' => t('To restrict this block to display only certain quotes based on node IDs, enter the IDs here separated by commas, spaces, or returns.'),
  );
  if (count($authors)) {
    $form['quotes']['filters']['aid_filter'] = array(
      '#type' => 'select',
      '#title' => t('Author filter'),
      '#multiple' => TRUE,
      '#default_value' => $block->aid_filter,
      '#options' => $authors,
      '#description' => t('To restrict this block to display only quotes from certain authors, select the authors here.'),
    );
  }
  else {
    $form['quotes']['filters']['aid_filter'] = array(
      '#type' => 'item',
      '#title' => t('Author filter'),
      '#default_value' => $block->aid_filter ? $block->aid_filter : '',
      '#description' => t('There are no authors.  To filter by authors, there must be at least one quote with an attributed author'),
    );
  }
  if ($block->rid_filter == array(
    '',
  )) {
    $block->rid_filter = NULL;
  }
  if (count($roles)) {
    $form['quotes']['filters']['rid_filter'] = array(
      '#type' => 'select',
      '#title' => t('Role filter'),
      '#multiple' => TRUE,
      '#default_value' => $block->rid_filter,
      '#options' => $roles,
      '#description' => t('To restrict this block to display only quotes submitted by users in specific roles, select the roles here.'),
    );
  }
  else {
    $form['quotes']['filters']['rid_filter'] = array(
      '#type' => 'item',
      '#title' => t('Role filter'),
      '#default_value' => $block->rid_filter ? $block->rid_filter : '',
      '#description' => t('There are no roles configured with the %create quotes, %import quotes, or %edit own quotes permissions, so no roles are available. To filter by role, please assign this permission to at least one role on the !access control page.', array(
        '%create quotes' => t('create quotes'),
        '%import quotes' => t('import quotes'),
        '%edit own quotes' => t('edit own quotes'),
        '!access control page' => l(t('administer permissions page'), 'admin/user/permissions'),
      )),
    );
  }
  if ($block->uid_filter == array(
    '',
  )) {
    $block->uid_filter = NULL;
  }
  $form['quotes']['filters']['uid_filter'] = array(
    '#type' => 'select',
    '#title' => t('User filter'),
    '#multiple' => TRUE,
    '#default_value' => $block->uid_filter,
    '#options' => $users,
    '#description' => t('To restrict this block to display only quotes submitted by specific users, select the users here.'),
  );
  if ($block->tid_filter == array(
    '',
  )) {
    $block->tid_filter = NULL;
  }
  $taxo_opts = array();
  $taxo_opts = array(
    -1 => $none_opt,
  );

  // Get only the quotes module vocabulary.
  $names = db_query('SELECT vid FROM {taxonomy_vocabulary} WHERE name = :name', array(
    ':name' => 'quotes',
  ))
    ->fetchField();

  // If there isn't a vocabulary skip getting its terms.
  if ($names) {
    $terms = taxonomy_get_tree($names, $parent = 0, $max_depth = NULL, $load_entities = FALSE);
    foreach ($terms as $term) {
      $taxo_opts[$term->tid] = $term->name;
    }
    asort($taxo_opts);
    $form['quotes']['filters']['tid_filter'] = array(
      '#type' => 'select',
      '#title' => t('Category filter'),
      '#multiple' => TRUE,
      '#default_value' => $block->tid_filter,
      '#options' => $taxo_opts,
      '#description' => t('To restrict this block to display only quotes in specific categories, select the categories here.'),
    );
  }
  else {
    $form['quotes']['filters']['tid_filter'] = array(
      '#type' => 'item',
      '#title' => t('Category filter'),
      '#default_value' => $block->tid_filter ? $block->tid_filter : '',
      '#description' => t('The taxanomy vocabulary has not been set up. Please setup a vocabulary item at the !taxvocabadd&nbsp;
                           (it is necessay to set the machine_name to <em>quotes</em> for this vocabulary item.<br />
                           Once the vocabulaby has been created then add any terms (Categories) to your newly created vocabulary item.
                           These terms will then be available to select in the quotes block configuration area.', array(
        '!taxvocabadd' => l(t('taxonomy administration page'), 'admin/structure/taxonomy'),
      )),
    );
  }
  $form['quotes']['cron'] = array(
    '#type' => 'fieldset',
    '#title' => t('Update options'),
    '#collapsible' => TRUE,
    '#collapsed' => FALSE,
  );
  $form['quotes']['cron']['cron_interval'] = array(
    '#type' => 'textfield',
    '#size' => 4,
    '#maxlength' => 3,
    '#default_value' => $block->cron_interval ? $block->cron_interval : '',
    '#field_prefix' => t('Update every'),
    '#prefix' => '<div class="container-inline">',
  );
  $form['quotes']['cron']['cron_step'] = array(
    '#type' => 'select',
    '#default_value' => $block->cron_step,
    '#options' => array(
      1 => t('seconds'),
      60 => t('minutes'),
      3600 => t('hours'),
      86400 => t('days'),
      604800 => t('weeks'),
    ),
    '#suffix' => '</div>',
  );
  $form['quotes']['cron']['description'] = array(
    '#type' => 'item',
    '#description' => t('If set, the quote displayed in this block will get updated based on the interval specified (requires cron if page cache is enabled). Leave this value blank to have the quote updated every time the block is viewed.'),
    '#prefix' => '<div style="display: block;">',
    '#suffix' => '</div>',
  );
  return $form;
}