function _sna_blocks_preprocess_sna_blocks in Simple Node Archive Blocks 7.2
@file The theme system, which controls the output of simple node archive.
Set archive variable for template.
1 call to _sna_blocks_preprocess_sna_blocks()
File
- theme/
sna_blocks.theme.inc, line 10 - The theme system, which controls the output of simple node archive.
Code
function _sna_blocks_preprocess_sna_blocks(&$vars) {
try {
$results = $vars['view']->result;
$archive_page = $vars['options']['sna_view_page_url'];
$arg = explode('/', $_GET['q']);
$use_jquerymenu = isset($vars['options']['sna_use_jquery']) && $vars['options']['sna_use_jquery'] ? $vars['options']['sna_use_jquery'] : 0;
$display_year = $display_month = '';
if (!empty($results)) {
// Check for node id, node title and date created.
if (!isset($vars['view']->result[0]->node_title)) {
drupal_set_message(t('Add node title'));
}
$field_name = isset($vars['options']['field_name']) ? $vars['options']['field_name'] : 'node_created';
$results = _sna_blocks_resultset($results, $field_name);
// Check for node view.
// Do the node exist in archive.
if ($node = menu_get_object()) {
$nid = $node->nid;
if ($field_name == 'node_created') {
$node_created = $node->created;
$display_year = date('Y', $node_created);
$display_month = date('F', $node_created);
}
else {
// Check for field archive type.
$date = new DateTime($node->{$field_name}[LANGUAGE_NONE][0]['value'], new DateTimeZone($node->{$field_name}[LANGUAGE_NONE][0]['timezone']));
$display_year = $date
->format('Y');
$display_month = $date
->format('F');
}
if (!isset($results[$display_year][$display_month][$nid])) {
$display_year = $display_month = '';
}
}
else {
$display_year = $arg[0] == $archive_page && isset($arg[1]) && $arg[1] != '' && is_numeric($arg[1]) ? $arg[1] : '';
$display_month = $arg[0] == $archive_page && isset($arg[2]) && $arg[2] != '00' && is_numeric($arg[2]) ? date('F', mktime(0, 0, 0, $arg[2], 10)) : '';
}
$results = _sna_blocks_resultset_add_count($results);
$vars['archive_block'] = _sna_blocks_archivehtml($results, $display_year, $display_month, $archive_page, $use_jquerymenu);
}
else {
$vars['archive_block'] = t('No Result found');
}
} catch (Exception $e) {
drupal_set_message($e
->getMessage());
}
}