[440] | 1 | <?php |
---|
| 2 | // +-----------------------------------------------------------------------+ |
---|
[2297] | 3 | // | Piwigo - a PHP based picture gallery | |
---|
| 4 | // +-----------------------------------------------------------------------+ |
---|
| 5 | // | Copyright(C) 2008 Piwigo Team http://piwigo.org | |
---|
| 6 | // | Copyright(C) 2003-2008 PhpWebGallery Team http://phpwebgallery.net | |
---|
| 7 | // | Copyright(C) 2002-2003 Pierrick LE GALL http://le-gall.net/pierrick | |
---|
| 8 | // +-----------------------------------------------------------------------+ |
---|
| 9 | // | This program is free software; you can redistribute it and/or modify | |
---|
| 10 | // | it under the terms of the GNU General Public License as published by | |
---|
| 11 | // | the Free Software Foundation | |
---|
| 12 | // | | |
---|
| 13 | // | This program is distributed in the hope that it will be useful, but | |
---|
| 14 | // | WITHOUT ANY WARRANTY; without even the implied warranty of | |
---|
| 15 | // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
---|
| 16 | // | General Public License for more details. | |
---|
| 17 | // | | |
---|
| 18 | // | You should have received a copy of the GNU General Public License | |
---|
| 19 | // | along with this program; if not, write to the Free Software | |
---|
| 20 | // | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, | |
---|
| 21 | // | USA. | |
---|
| 22 | // +-----------------------------------------------------------------------+ |
---|
[440] | 23 | |
---|
| 24 | /** |
---|
[1082] | 25 | * This file is included by the main page to show thumbnails for the default |
---|
[440] | 26 | * case |
---|
[1090] | 27 | * |
---|
[440] | 28 | */ |
---|
| 29 | |
---|
[1036] | 30 | $page['rank_of'] = array_flip($page['items']); |
---|
| 31 | |
---|
| 32 | $pictures = array(); |
---|
| 33 | |
---|
| 34 | $selection = array_slice( |
---|
| 35 | $page['items'], |
---|
| 36 | $page['start'], |
---|
| 37 | $page['nb_image_page'] |
---|
| 38 | ); |
---|
| 39 | |
---|
| 40 | if (count($selection) > 0) |
---|
| 41 | { |
---|
| 42 | $query = ' |
---|
| 43 | SELECT * |
---|
| 44 | FROM '.IMAGES_TABLE.' |
---|
[1677] | 45 | WHERE id IN ('.implode(',', $selection).') |
---|
| 46 | ;'; |
---|
[1036] | 47 | $result = pwg_query($query); |
---|
[1596] | 48 | while ($row = mysql_fetch_assoc($result)) |
---|
[1036] | 49 | { |
---|
| 50 | $row['rank'] = $page['rank_of'][ $row['id'] ]; |
---|
[1090] | 51 | |
---|
[1036] | 52 | array_push($pictures, $row); |
---|
| 53 | } |
---|
[440] | 54 | |
---|
[1036] | 55 | usort($pictures, 'rank_compare'); |
---|
| 56 | } |
---|
| 57 | |
---|
| 58 | if (count($pictures) > 0) |
---|
[440] | 59 | { |
---|
[2218] | 60 | // define category slideshow url |
---|
| 61 | $row = reset($pictures); |
---|
| 62 | $page['cat_slideshow_url'] = |
---|
| 63 | add_url_params( |
---|
| 64 | duplicate_picture_url( |
---|
| 65 | array( |
---|
| 66 | 'image_id' => $row['id'], |
---|
| 67 | 'image_file' => $row['file'] |
---|
| 68 | ), |
---|
| 69 | array('start') |
---|
| 70 | ), |
---|
| 71 | array('slideshow' => |
---|
| 72 | (isset($_GET['slideshow']) ? $_GET['slideshow'] |
---|
| 73 | : '' )) |
---|
| 74 | ); |
---|
[2234] | 75 | |
---|
[2274] | 76 | if ($user['show_nb_comments']) |
---|
| 77 | { |
---|
| 78 | $query = ' |
---|
| 79 | SELECT image_id, COUNT(*) AS nb_comments |
---|
| 80 | FROM '.COMMENTS_TABLE.' |
---|
| 81 | WHERE validated = \'true\' |
---|
| 82 | AND image_id IN ('.implode(',', $selection).') |
---|
| 83 | GROUP BY image_id |
---|
| 84 | ;'; |
---|
| 85 | $nb_comments_of = simple_hash_from_query($query, 'image_id', 'nb_comments'); |
---|
| 86 | } |
---|
[440] | 87 | } |
---|
| 88 | |
---|
[2274] | 89 | // template thumbnail initialization |
---|
| 90 | $template->set_filenames( array( 'index_thumbnails' => 'thumbnails.tpl',)); |
---|
| 91 | |
---|
[1596] | 92 | trigger_action('loc_begin_index_thumbnails', $pictures); |
---|
| 93 | |
---|
[1036] | 94 | foreach ($pictures as $row) |
---|
[440] | 95 | { |
---|
[1596] | 96 | $thumbnail_url = get_thumbnail_url($row); |
---|
[1090] | 97 | |
---|
| 98 | // link on picture.php page |
---|
| 99 | $url = duplicate_picture_url( |
---|
| 100 | array( |
---|
| 101 | 'image_id' => $row['id'], |
---|
| 102 | 'image_file' => $row['file'] |
---|
[1094] | 103 | ), |
---|
| 104 | array('start') |
---|
[1090] | 105 | ); |
---|
| 106 | |
---|
[2234] | 107 | $tpl_var = |
---|
[440] | 108 | array( |
---|
[2274] | 109 | 'ID' => $row['id'], |
---|
[2515] | 110 | 'TN_SRC' => $thumbnail_url, |
---|
| 111 | 'TN_ALT' => $row['file'], |
---|
| 112 | 'TN_TITLE' => get_thumbnail_title($row), |
---|
| 113 | 'ICON_TS' => get_icon($row['date_available']), |
---|
| 114 | 'URL' => $url, |
---|
[2841] | 115 | |
---|
| 116 | /* Fields for template-extension usage */ |
---|
| 117 | 'FILE_PATH' => $row['path'], |
---|
| 118 | 'FILE_POSTED' => format_date($row['date_available'], 'mysql_datetime'), |
---|
| 119 | 'FILE_CREATED' => (empty($row['date_creation'])) ? |
---|
[2856] | 120 | '-': format_date($row['date_creation'], 'mysql_date'), |
---|
[2841] | 121 | 'FILE_DESC' => (empty($row['comment'])) ? '-' : $row['comment'], |
---|
| 122 | 'FILE_AUTHOR' => (empty($row['author'])) ? '-' : $row['author'], |
---|
| 123 | 'FILE_HIT' => $row['hit'], |
---|
| 124 | 'FILE_SIZE' => (empty($row['filesize'])) ? '-' : $row['filesize'], |
---|
| 125 | 'FILE_WIDTH' => (empty($row['width'])) ? '-' : $row['width'], |
---|
| 126 | 'FILE_HEIGHT' => (empty($row['height'])) ? '-' : $row['height'], |
---|
| 127 | 'FILE_METADATE' => (empty($row['date_metadata_update'])) ? |
---|
[2856] | 128 | '-': format_date($row['date_metadata_update'], 'mysql_date'), |
---|
[2841] | 129 | 'FILE_RATE' => (empty($row['rate'])) ? '-' : $row['rate'], |
---|
| 130 | 'FILE_HAS_HD' => ($row['has_high'] and $user['enabled_high']=='true') ? |
---|
| 131 | true:false, /* lack of include/functions_picture.inc.php */ |
---|
[440] | 132 | ); |
---|
[2234] | 133 | |
---|
[1864] | 134 | if ($user['show_nb_hits']) |
---|
[1763] | 135 | { |
---|
[2274] | 136 | $tpl_var['NB_HITS'] = $row['hit']; |
---|
[1763] | 137 | } |
---|
[803] | 138 | |
---|
| 139 | if ($conf['show_thumbnail_caption']) |
---|
| 140 | { |
---|
| 141 | // name of the picture |
---|
| 142 | if (isset($row['name']) and $row['name'] != '') |
---|
| 143 | { |
---|
| 144 | $name = $row['name']; |
---|
| 145 | } |
---|
| 146 | else |
---|
| 147 | { |
---|
| 148 | $name = str_replace('_', ' ', get_filename_wo_extension($row['file'])); |
---|
| 149 | } |
---|
[1082] | 150 | |
---|
| 151 | switch ($page['section']) |
---|
[803] | 152 | { |
---|
[1082] | 153 | case 'best_rated' : |
---|
[1056] | 154 | { |
---|
| 155 | $name = '('.$row['average_rate'].') '.$name; |
---|
[1082] | 156 | break; |
---|
[1056] | 157 | } |
---|
[1082] | 158 | case 'most_visited' : |
---|
[1056] | 159 | { |
---|
[2081] | 160 | if ( !$user['show_nb_hits']) { |
---|
| 161 | $name = '('.$row['hit'].') '.$name; |
---|
| 162 | } |
---|
[1082] | 163 | break; |
---|
[1056] | 164 | } |
---|
[803] | 165 | } |
---|
[1090] | 166 | |
---|
[2515] | 167 | $tpl_var['NAME'] = $name; |
---|
[803] | 168 | } |
---|
[1090] | 169 | |
---|
[2274] | 170 | if ( isset($nb_comments_of) ) |
---|
[440] | 171 | { |
---|
[2274] | 172 | $row['nb_comments'] = isset($nb_comments_of[$row['id']]) |
---|
| 173 | ? (int)$nb_comments_of[$row['id']] : 0; |
---|
| 174 | $tpl_var['NB_COMMENTS'] = $row['nb_comments']; |
---|
[440] | 175 | } |
---|
| 176 | |
---|
[2274] | 177 | //plugins need to add/modify sth in this loop ? |
---|
| 178 | $tpl_var = trigger_event('loc_index_thumbnail', $tpl_var, $row); |
---|
| 179 | |
---|
[2234] | 180 | $template->append('thumbnails', $tpl_var); |
---|
[440] | 181 | } |
---|
[1596] | 182 | |
---|
| 183 | trigger_action('loc_end_index_thumbnails', $pictures); |
---|
[2274] | 184 | $template->assign_var_from_handle('THUMBNAILS', 'index_thumbnails'); |
---|
[1036] | 185 | |
---|
| 186 | pwg_debug('end include/category_default.inc.php'); |
---|
[1098] | 187 | ?> |
---|