get_block('mbSpecials')) != null){
array_splice($block->data, $position-1, 0, array('most_downloaded' =>
array(
'URL' => make_index_url(array('section' => 'most_downloaded')),
'TITLE' => l10n('displays most downloaded Photos'),
'NAME' => l10n('Most downloaded')
)
)
);
}
}
function section_init_most_downloaded()
{
global $tokens, $page, $conf;
if (!in_array('most_downloaded', $tokens))
{
return;
}
$page['section'] = 'most_downloaded';
$page['title'] = '' . l10n('Most downloaded') . '';
$page['section_title'] = '' . l10n('Home') . ''
. $conf['level_separator'] . $page['title'];
$query = '
SELECT DISTINCT image_id
FROM ' . IMAGE_CATEGORY_TABLE . '
WHERE ' .
get_sql_condition_FandF(
array(
'forbidden_categories' => 'category_id',
'visible_categories' => 'category_id',
'visible_images' => 'image_id',
),
'', true
)
. '
;';
$img = query2array($query, null, 'image_id');
if (empty($img))
{
$page['items'] = array();
}
else
{
$query = 'SELECT id, download_counter FROM ' . IMAGES_TABLE . ' AS img WHERE img.id IN (' . implode(',', $img) . ') and download_counter > 0 ORDER BY download_counter DESC, img.hit DESC LIMIT ' . $conf['top_number'] . ';';
$page['items'] = query2array($query, null, 'id');
add_event_handler('loc_end_index_thumbnails', 'add_nb_most_downloaded');
}
function add_nb_most_downloaded($tpl_thumbnails_var){
global $template, $user, $selection;
// unsed sort order
$template->clear_assign('image_orders');
$query = 'SELECT id, download_counter FROM '.IMAGES_TABLE.' WHERE id IN ('.implode(',', $selection).');';
$nb_download = query2array($query, 'id', 'download_counter');
foreach ($tpl_thumbnails_var as &$row)
{
$row['download_counter'] = $nb_download[$row['id']];
}
unset($row);
return $tpl_thumbnails_var;
}
}
}