function _sna_blocks_archivehtml in Simple Node Archive Blocks 6
Same name and namespace in other branches
- 7.2 theme/sna_blocks.theme.inc \_sna_blocks_archivehtml()
- 7 sna_blocks.module \_sna_blocks_archivehtml()
Theme the result set to HTML.
Parameters
array $results: Associate array in format Array([year(counter)] => Array([month(counter)] => Array([nid] => title)))
string $archive_items: Number node to be shown in expanded archive.
string $display_year: Which year to be shown in archive. A full numeric representation of a year, 4 digit.
string $display_month: Which month to be shown in arhive. Numeric representation of a month, with leading zeros.
Return value
string An HTML string.
2 calls to _sna_blocks_archivehtml()
- theme_sna_blocks_node in ./
sna_blocks.module - Returns a chronological archive block for node type.
- theme_sna_blocks_taxonomy in ./
sna_blocks.module - Returns a chronological archive block for node Vocabulary or Term.
File
- ./
sna_blocks.module, line 275 - Provide a simple node archive block
Code
function _sna_blocks_archivehtml($results, $archive_items, $display_year, $display_month, $values, $block_type) {
$output = t('No Content Posted.');
$view_taxo_arg = 'all';
$view_node_arg = 'all';
$use_jquerymenu = variable_get('sna_blocks_jquerymenu', 0);
if ($use_jquerymenu) {
$use_jquerymenu = $use_jquerymenu[1];
}
// Set taxonomy & node type argument for view.
if ($block_type == 'terms' && is_array($values)) {
if (count($values) == 1) {
$view_taxo_arg = key($values);
}
else {
$view_taxo_arg = implode('+', $values);
}
}
if ($block_type == 'node') {
$view_node_arg = $values;
}
// Need to find active block.
$arg = explode('/', $_GET['q']);
$active_block = FALSE;
if ($arg[0] == 'sna' && $block_type == 'node' && $arg[3] == $view_node_arg && $arg[4] == 'all') {
$active_block = TRUE;
}
$arg[4] = isset($arg[4]) ? str_replace(' ', '+', $arg[4]) : 0;
if ($arg[0] == 'sna' && $block_type == 'terms' && $arg[4] == $view_taxo_arg) {
$active_block = TRUE;
}
if ($node = menu_get_object()) {
$node_created = $node->created;
$display_year = date('Y', $node_created);
$display_month = date('F', $node_created);
if ($block_type == 'node') {
if ($values == 'all') {
$active_block = TRUE;
}
elseif ($values == 'custom') {
$node_types = variable_get('sna_blocks_custom_selection', array(
'page',
));
if (isset($node_types[$node->type]) && $node_types[$node->type] != '0') {
$active_block = TRUE;
}
}
elseif ($node->type == $values) {
$active_block = TRUE;
}
}
elseif ($block_type == 'terms') {
$terms = _sna_blocks_nodeterms($node->nid);
if (!empty($terms)) {
foreach ($terms as $key => $value) {
if (in_array($key, $values)) {
$active_block = TRUE;
}
}
}
}
}
$year_items = $trail = array();
// Build the HTML.
if (!empty($results)) {
$theme_arr = array();
// Loop through earch year.
foreach ($results as $year => $months) {
$year_value = explode(' ', $year);
// $year_value[0] contain year value and $year_value[1] conatian count.
$year_url = 'sna/' . $year_value[0] . '/00/' . $view_node_arg . '/' . $view_taxo_arg;
// Check for active year branch and block.
$expand_year = $display_year == $year_value[0] && $active_block ? TRUE : FALSE;
$children_months = array();
// If Using Jquery Menu.
if ($use_jquerymenu) {
unset($year_item);
unset($month_items);
$year_item['link']['href'] = $year_url;
$year_item['link']['title'] = t($year_value[0]) . ' ' . $year_value[1];
$year_item['link']['has_children'] = 1;
$year_item['link']['expanded'] = 0;
if ($expand_year) {
$trail[0] = $year_item['link']['href'];
}
$expand_year = TRUE;
}
if ($expand_year) {
// Loop through active year and show month.
foreach ($months as $month => $nodes) {
$month_value = explode(' ', $month);
// $month_value[0] contain month and $month_value[1] conatian count.
$month_url = 'sna/' . $year_value[0] . '/' . date('m', strtotime($month_value[0])) . '/' . $view_node_arg . '/' . $view_taxo_arg;
// Check for active month and block.
$expand_month = $display_year == $year_value[0] && $display_month == $month_value[0] && $active_block ? TRUE : FALSE;
$children_nodes = array();
// If Using Jquery Menu.
if ($use_jquerymenu) {
unset($month_item);
unset($node_items);
$month_item['link']['href'] = $month_url;
$month_item['link']['title'] = t($month_value[0]) . ' ' . $month_value[1];
$month_item['link']['has_children'] = 1;
$month_item['link']['expanded'] = 0;
if ($expand_month) {
$trail[0] = $year_item['link']['href'];
$trail[1] = $month_item['link']['href'];
}
$expand_month = TRUE;
}
if ($expand_month) {
$count = 1;
// Loop through acitive month and show node.
foreach ($nodes as $nid => $title) {
// If Using Jquery Menu.
if ($use_jquerymenu) {
unset($node_item);
}
// $archive_items number of nodes display in expanded archive.
if ($count <= $archive_items || $archive_items == 0) {
$children_nodes[] = l($title, 'node/' . $nid);
// If Using Jquery Menu.
if ($use_jquerymenu) {
$node_item['link']['href'] = 'node/' . $nid;
$node_item['link']['title'] = $title;
$node_item['link']['has_children'] = 0;
$node_item['link']['expanded'] = 0;
}
}
$count = $count != 0 ? $count + 1 : 0;
// If Using Jquery Menu.
if ($use_jquerymenu) {
$node_items[] = $node_item;
}
}
// If Using Jquery Menu.
if ($use_jquerymenu) {
$month_item['below'] = $node_items;
$month_items[] = $month_item;
}
}
$children_months[] = array(
'data' => l(t($month_value[0]), $month_url) . ' <span>' . $month_value[1] . '</span>',
'children' => $children_nodes,
);
}
// If Using Jquery Menu.
if ($use_jquerymenu) {
$year_item['below'] = $month_items;
$year_items[] = $year_item;
}
}
$theme_arr[] = array(
'data' => l(t($year_value[0]), $year_url) . ' <span>' . $year_value[1] . '</span>',
'children' => $children_months,
);
}
// If Using Jquery Menu.
if ($use_jquerymenu) {
$output = theme('menu_creation_by_array', $year_items, $trail);
}
else {
$output = theme('item_list', $theme_arr);
}
}
else {
// Term is not tagged with any node.
$output = t('No posts available');
}
return $output;
}