function faq_block in Frequently Asked Questions 5.2
Same name and namespace in other branches
- 5 faq.module \faq_block()
- 6 faq.module \faq_block()
Implementation of hook_block().
Create the code of the FAQ page providing three block types: FAQ Categories, Recent FAQs and Random FAQs.
File
- ./
faq.module, line 1093 - The FAQ module allows users to create a FAQ page, with questions and answers displayed in different styles, according to the settings.
Code
function faq_block($op = 'list', $delta = 0, $edit = array()) {
static $vocabularies, $terms;
switch ($op) {
case 'list':
$blocks[0]['info'] = t('FAQ Categories');
$blocks[1]['info'] = t('Recent FAQs');
$blocks[2]['info'] = t('Random FAQs');
return $blocks;
case 'view':
switch ($delta) {
case 0:
// FAQ Categories.
if (module_exists("taxonomy")) {
if (!isset($terms)) {
$terms = array();
$vocabularies = taxonomy_get_vocabularies('faq');
$vocab_omit = variable_get('faq_omit_vocabulary', array());
$vocabularies = array_diff_key($vocabularies, $vocab_omit);
foreach ($vocabularies as $vocab) {
foreach (taxonomy_get_tree($vocab->vid) as $term) {
if (taxonomy_term_count_nodes($term->tid, 'faq')) {
$terms[$term->name] = $term->tid;
}
}
}
}
if (count($terms) > 0) {
$block['subject'] = t('FAQ Categories');
$items = array();
foreach ($terms as $name => $tid) {
$items[] = l($name, 'faq/' . $tid);
}
$list_style = variable_get('faq_category_listing', 'ul');
$block['content'] = theme('item_list', $items, NULL, $list_style);
}
}
break;
case 1:
// Recent FAQs.
$block['subject'] = t('Recent FAQs');
$block['content'] = faq_highlights_block(variable_get('faq_block_recent_faq_count', 5));
break;
case 2:
// Random FAQs.
$block['subject'] = t('Random FAQs');
$block['content'] = faq_random_highlights_block(variable_get('faq_block_random_faq_count', 5));
break;
}
// End switch($delta).
return $block;
case 'configure':
switch ($delta) {
case 0:
break;
case 1:
// Recent FAQs.
$form['faq_block_recent_faq_count'] = array(
'#type' => 'textfield',
'#title' => t('Number of FAQs to show'),
'#description' => t("This controls the number of FAQs that appear in the 'Recent FAQs' block"),
'#default_value' => variable_get('faq_block_recent_faq_count', 5),
);
break;
case 2:
// Random FAQs.
$form['faq_block_random_faq_count'] = array(
'#type' => 'textfield',
'#title' => t('Number of FAQs to show'),
'#description' => t("This controls the number of FAQs that appear in the 'Random FAQs' block"),
'#default_value' => variable_get('faq_block_random_faq_count', 5),
);
break;
}
// End switch($delta).
return $form;
case 'save':
switch ($delta) {
case 0:
break;
case 1:
variable_set('faq_block_recent_faq_count', $edit['faq_block_recent_faq_count']);
break;
case 2:
variable_set('faq_block_random_faq_count', $edit['faq_block_random_faq_count']);
break;
}
// End switch($delta).
return;
}
// End switch($op).
}