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