[3609] | 1 | <?php |
---|
| 2 | |
---|
| 3 | if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); |
---|
| 4 | |
---|
| 5 | global $page, $user, $conf, $template; |
---|
| 6 | |
---|
| 7 | if (script_basename() == 'picture' |
---|
| 8 | or ($datas['cat_display'] == 'wo_thumb' and !empty($page['items'])) |
---|
| 9 | or ($datas['cat_display'] == 'w_thumb' and empty($page['items']) and isset($page['category'])) |
---|
| 10 | or ($datas['cat_display'] == 'selected_cats' and isset($page['category']) and !in_array($page['category']['id'], $datas['cat_selection']))) |
---|
| 11 | { |
---|
| 12 | return false; |
---|
| 13 | } |
---|
| 14 | |
---|
| 15 | $forbidden = get_sql_condition_FandF |
---|
| 16 | ( |
---|
| 17 | array |
---|
| 18 | ( |
---|
| 19 | 'forbidden_categories' => 'ic.category_id', |
---|
| 20 | 'visible_categories' => 'ic.category_id', |
---|
| 21 | 'visible_images' => 'i.id' |
---|
| 22 | ), |
---|
| 23 | 'AND' |
---|
| 24 | ); |
---|
| 25 | |
---|
| 26 | $query =' |
---|
| 27 | SELECT DISTINCT(i.id) |
---|
| 28 | FROM '.IMAGES_TABLE.' AS i |
---|
| 29 | INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS ic ON i.id = ic.image_id |
---|
| 30 | INNER JOIN '.CATEGORIES_TABLE.' AS c ON ic.category_id = c.id |
---|
| 31 | WHERE i.date_available >= SUBDATE( |
---|
| 32 | CURRENT_DATE,INTERVAL '.$user['recent_period'].' DAY)'; |
---|
| 33 | |
---|
| 34 | if (isset($page['category'])) |
---|
| 35 | { |
---|
| 36 | $query .= ' |
---|
| 37 | AND ( c.uppercats LIKE \''.$page['category']['uppercats'].',%\' OR c.id = '.$page['category']['id'].' ) |
---|
| 38 | '; |
---|
| 39 | } |
---|
| 40 | |
---|
| 41 | $query .= ' |
---|
| 42 | '.$forbidden.' |
---|
[8625] | 43 | ORDER BY i.id DESC |
---|
[3609] | 44 | LIMIT 0, '.$datas['nb_images'].' |
---|
| 45 | ;'; |
---|
| 46 | |
---|
| 47 | $pictures = array(); |
---|
| 48 | $selection = array_from_query($query, 'id'); |
---|
| 49 | |
---|
| 50 | if (count($selection) > 0) |
---|
| 51 | { |
---|
| 52 | $query = ' |
---|
| 53 | SELECT * |
---|
| 54 | FROM '.IMAGES_TABLE.' |
---|
| 55 | WHERE id IN ('.implode(',', $selection).') |
---|
[8625] | 56 | ORDER BY id DESC |
---|
[3609] | 57 | ;'; |
---|
| 58 | $result = pwg_query($query); |
---|
| 59 | while ($row = mysql_fetch_assoc($result)) |
---|
| 60 | { |
---|
| 61 | array_push($pictures, $row); |
---|
| 62 | } |
---|
| 63 | } |
---|
| 64 | |
---|
| 65 | if (count($pictures) > 0) |
---|
| 66 | { |
---|
| 67 | if ($user['show_nb_comments']) |
---|
| 68 | { |
---|
| 69 | $query = ' |
---|
| 70 | SELECT image_id, COUNT(*) AS nb_comments |
---|
| 71 | FROM '.COMMENTS_TABLE.' |
---|
| 72 | WHERE validated = \'true\' |
---|
| 73 | AND image_id IN ('.implode(',', $selection).') |
---|
| 74 | GROUP BY image_id |
---|
| 75 | ;'; |
---|
| 76 | $nb_comments_of = simple_hash_from_query($query, 'image_id', 'nb_comments'); |
---|
| 77 | } |
---|
| 78 | |
---|
| 79 | // template thumbnail initialization |
---|
| 80 | trigger_action('loc_begin_index_thumbnails', $pictures); |
---|
[9581] | 81 | $block['thumbnails'] = array(); |
---|
[3609] | 82 | |
---|
| 83 | foreach ($pictures as $row) |
---|
| 84 | { |
---|
| 85 | // link on picture.php page |
---|
| 86 | $url = duplicate_picture_url( |
---|
| 87 | array( |
---|
| 88 | 'image_id' => $row['id'], |
---|
| 89 | 'image_file' => $row['file'] |
---|
| 90 | ), |
---|
| 91 | array('start') |
---|
| 92 | ); |
---|
| 93 | $url = add_url_params($url, array('pwgs_re' => implode(',',$selection))); |
---|
| 94 | |
---|
| 95 | $tpl_var = |
---|
| 96 | array( |
---|
| 97 | 'ID' => $row['id'], |
---|
| 98 | 'TN_SRC' => get_thumbnail_url($row), |
---|
| 99 | 'TN_ALT' => $row['file'], |
---|
| 100 | 'TN_TITLE' => get_thumbnail_title($row), |
---|
| 101 | 'ICON_TS' => get_icon($row['date_available']), |
---|
| 102 | 'URL' => $url, |
---|
| 103 | |
---|
| 104 | /* Fields for template-extension usage */ |
---|
| 105 | 'FILE_PATH' => $row['path'], |
---|
| 106 | 'FILE_POSTED' => $row['date_available'], |
---|
| 107 | 'FILE_CREATED' => $row['date_creation'], |
---|
| 108 | 'FILE_DESC' => $row['comment'], |
---|
| 109 | 'FILE_AUTHOR' => $row['author'], |
---|
| 110 | 'FILE_HIT' => $row['hit'], |
---|
| 111 | 'FILE_SIZE' => $row['filesize'], |
---|
| 112 | 'FILE_WIDTH' => $row['width'], |
---|
| 113 | 'FILE_HEIGHT' => $row['height'], |
---|
| 114 | 'FILE_METADATE' => $row['date_metadata_update'], |
---|
| 115 | 'FILE_HAS_HD' => ($row['has_high'] and $user['enabled_high']=='true') ? |
---|
| 116 | true:false, /* lack of include/functions_picture.inc.php */ |
---|
| 117 | ); |
---|
| 118 | |
---|
| 119 | if ($user['show_nb_hits']) |
---|
| 120 | { |
---|
| 121 | $tpl_var['NB_HITS'] = $row['hit']; |
---|
| 122 | } |
---|
| 123 | |
---|
| 124 | if ($conf['show_thumbnail_caption']) |
---|
| 125 | {// name of the picture |
---|
| 126 | if (isset($row['name']) and $row['name'] != '') |
---|
| 127 | { |
---|
| 128 | $name = $row['name']; |
---|
| 129 | } |
---|
| 130 | else |
---|
| 131 | { |
---|
| 132 | $name = str_replace('_', ' ', get_filename_wo_extension($row['file'])); |
---|
| 133 | } |
---|
| 134 | |
---|
| 135 | $tpl_var['NAME'] = $name; |
---|
| 136 | } |
---|
| 137 | |
---|
| 138 | if ( isset($nb_comments_of) ) |
---|
| 139 | { |
---|
| 140 | $tpl_var['NB_COMMENTS'] = (int)@$nb_comments_of[$row['id']]; |
---|
| 141 | } |
---|
| 142 | |
---|
[9581] | 143 | $block['thumbnails'][] = $tpl_var; |
---|
[3609] | 144 | } |
---|
| 145 | |
---|
[9581] | 146 | $block['thumbnails'] = trigger_event('loc_end_index_thumbnails', $block['thumbnails'], $pictures); |
---|
[3609] | 147 | |
---|
[9581] | 148 | $block['TEMPLATE'] = 'stuffs_thumbnails.tpl'; |
---|
[3609] | 149 | } |
---|
| 150 | |
---|
[3300] | 151 | ?> |
---|