get_block('mbSpecials')) != null) { array_splice($block->data, $position-1, 0, array('most_commented' => array( 'URL' => make_index_url(array('section' => 'most_commented')), 'TITLE' => l10n('displays most commented pictures'), 'NAME' => l10n('Most commented') ) ) ); } } function section_init_mostcommented() { global $tokens, $page, $conf; if (!in_array('most_commented', $tokens)) { return; } $page['section'] = 'most_commented'; $page['title'] = '' . l10n('Most commented') . ''; $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 img.id, COUNT(*) AS count FROM ' . IMAGES_TABLE . ' AS img INNER JOIN ' . COMMENTS_TABLE . ' AS com ON com.image_id = img.id WHERE img.id IN (' . implode(',', $img) . ') AND com.validated = "true" GROUP BY img.id ORDER BY count DESC, img.hit DESC LIMIT ' . $conf['top_number'] . ' ;'; $page['items'] = query2array($query, null, 'id'); } add_event_handler('loc_end_index_thumbnails', 'add_nb_comments_mostcommented'); } function add_nb_comments_mostcommented($tpl_thumbnails_var) { global $template, $user, $selection; // unsed sort order $template->clear_assign('image_orders'); // display nb comments if hidden by user if (!$user['show_nb_comments']) { $query = ' SELECT image_id, COUNT(*) AS nb_comments FROM '.COMMENTS_TABLE.' WHERE validated = \'true\' AND image_id IN ('.implode(',', $selection).') GROUP BY image_id ;'; $nb_comments_of = query2array($query, 'image_id', 'nb_comments'); foreach ($tpl_thumbnails_var as &$row) { $row['NB_COMMENTS'] = $nb_comments_of[$row['id']]; } unset($row); } return $tpl_thumbnails_var; }