function sna_blocks_block in Simple Node Archive Blocks 6
Implements of hook_block().
File
- ./
sna_blocks.module, line 52 - Provide a simple node archive block
Code
function sna_blocks_block($op = 'list', $delta = 0) {
$block = array();
switch ($op) {
case 'list':
// Node archive.
$block_types = variable_get('sna_blocks_block_types', array(
'page',
));
foreach ($block_types as $type => $value) {
// Check the selected block types.
if ($value != '0') {
$block['sna-node-' . $value] = array(
'info' => t('Simple Node Archive - Node : @name', array(
'@name' => $value,
)),
);
}
}
// Taxonomy archive.
$taxonomy_options = variable_get('sna_blocks_taxonomy_options', array());
$taxonomy_archive = variable_get('sna_blocks_taxonomy_items', array());
foreach ($taxonomy_archive as $type => $value) {
// Check the selected block types.
if ($value != '0') {
$block['sna-taxo-' . $value] = array(
'info' => t('Simple Node Archive - Taxonomy : @name', array(
'@name' => $taxonomy_options[$value],
)),
);
}
}
return $block;
case 'view':
$archive_items = variable_get('sna_blocks_items', 0);
$arg = explode('/', $_GET['q']);
$year = $arg[0] == 'sna' && $arg[1] != '' && is_numeric($arg[1]) ? $arg[1] : '';
$month = $arg[0] == 'sna' && $arg[2] != '00' && is_numeric($arg[2]) ? date('F', mktime(0, 0, 0, $arg[2])) : '';
// Node archive.
$block_types = variable_get('sna_blocks_block_types', array(
'page',
));
foreach ($block_types as $type => $value) {
if ($delta == 'sna-node-' . $value) {
$block['subject'] = t('SNA Node type @name', array(
'@name' => $value,
));
$block['content'] = theme('sna_blocks_node', array(
'value' => $value,
'archive_items' => $archive_items,
'year' => $year,
'month' => $month,
));
}
}
// Taxonomy Archive.
$taxonomy_options = variable_get('sna_blocks_taxonomy_options', array());
$taxonomy_archive = variable_get('sna_blocks_taxonomy_items', array());
foreach ($taxonomy_archive as $type => $value) {
if ($delta == 'sna-taxo-' . $value) {
$block['subject'] = t('SNA Taxonomy type @name', array(
'@name' => $taxonomy_options[$value],
));
$block['content'] = theme('sna_blocks_taxonomy', array(
'value' => $value,
'archive_items' => $archive_items,
'year' => $year,
'month' => $month,
));
}
}
return $block;
}
}