function quotes_block_configure in Quotes 6
Same name and namespace in other branches
- 7 quotes.module \quotes_block_configure()
Quotes block configuration.
1 call to quotes_block_configure()
- quotes_block in ./
quotes.module - Implementation of hook_block().
File
- ./
quotes.module, line 789 - 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 = 0, $edit = array()) {
global $_quotes_subs;
drupal_add_js(drupal_get_path('module', 'quotes') . '/quotes.js');
$yesno = array(
t('No'),
t('Yes'),
);
$none_opt = '- ' . t('none') . ' -';
$block = db_fetch_object(db_query("SELECT qb.* FROM {quotes_blocks} qb WHERE bid = %d", $delta));
$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,
);
if ($roles[DRUPAL_ANONYMOUS_RID]) {
$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,
)) . ")");
while ($row = db_fetch_object($result)) {
$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'),
),
'#attributes' => array(
'class' => 'container-inline',
),
'#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).'),
);
$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/build/block'),
'%subs' => $sub_str,
)),
);
$title_opts = array(
0 => t('No title'),
1 => t('Title linked to quote'),
);
$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.'),
'#attributes' => array(
'class' => 'container-inline',
),
);
$form['quotes']['show_citation'] = array(
'#type' => 'radios',
'#options' => $yesno,
'#attributes' => array(
'class' => 'container-inline',
),
'#title' => t('Show citation'),
'#default_value' => $block->show_citation,
'#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. It will only be available on quotes that have comments read/write 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.'),
'#prefix' => '<div class="quotes_block_more">',
);
$frequency = array();
for ($i = 0; $i <= 100; $i += 10) {
$frequency[$i] = $i . '%';
}
$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. Most people will want this left at 100%.'),
// '#prefix' => '<div class="quotes_block_more">',
'#suffix' => '</div>',
);
$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'),
'#description' => t('There are no authors. To filter by authors, there must be at least one quote with an attributed author'),
);
}
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'),
'#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'),
)),
);
}
$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_merge(array(
-1 => '- ' . t('none') . ' -',
), taxonomy_form_all(TRUE));
if (function_exists('taxonomy_form_all')) {
$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.'),
);
}
$form['quotes']['cron'] = array(
'#type' => 'fieldset',
'#title' => t('Update options'),
'#description' => t('Note: Timed blocks will contain only one quote.'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
$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;
}