Subversion Repositories svnkaklik

Rev

Details | Last modification | View Log

Rev Author Line No. Line
6 kaklik 1
<?php
2
/*************************
3
  Coppermine Photo Gallery
4
  ************************
5
  Copyright (c) 2003-2005 Coppermine Dev Team
6
  v1.1 originaly written by Gregory DEMAR
7
 
8
  This program is free software; you can redistribute it and/or modify
9
  it under the terms of the GNU General Public License as published by
10
  the Free Software Foundation; either version 2 of the License, or
11
  (at your option) any later version.
12
  ********************************************
13
  Coppermine version: 1.3.3
14
  $Source: /cvsroot/coppermine/stable/displayimage.php,v $
15
  $Revision: 1.11 $
16
  $Author: gaugau $
17
  $Date: 2005/04/19 03:17:10 $
18
**********************************************/
19
 
20
define('IN_COPPERMINE', true);
21
define('DISPLAYIMAGE_PHP', true);
22
define('INDEX_PHP', true);
23
//define('SMILIES_PHP', true);
24
 
25
require('include/init.inc.php');
26
 
27
if ($CONFIG['enable_smilies']) include("include/smilies.inc.php");
28
 
29
$breadcrumb = '';
30
$breadcrumb_text = '';
31
$cat_data = array();
32
 
33
if($CONFIG['read_exif_data'] ){
34
        include("include/exif_php.inc.php");
35
}
36
if($CONFIG['read_iptc_data'] ){
37
        include("include/iptc.inc.php");
38
}
39
 
40
 
41
/**
42
 * Local functions definition
43
 */
44
 
45
function html_picture_menu($id)
46
{
47
    global $lang_display_image_php;
48
 
49
    return <<<EOT
50
     <a href="#" onClick="return MM_openBrWindow('picEditor.php?id=$id','Crop_Picture','scrollbars=yes,toolbar=no,status=yes,resizable=yes')" class="admin_menu" >{$lang_display_image_php['crop_pic']}</a> <a href="editOnePic.php?id=$id&what=picture"  class="admin_menu">{$lang_display_image_php['edit_pic']}</a> <a href="delete.php?id=$id&what=picture"  class="admin_menu" onclick="return confirm('{$lang_display_image_php['confirm_del']}'); return false; ">{$lang_display_image_php['del_pic']}</a>
51
 
52
EOT;
53
}
54
// Prints the image-navigation menu
55
function html_img_nav_menu()
56
{
57
    global $CONFIG, $HTTP_SERVER_VARS, $HTTP_GET_VARS, $CURRENT_PIC_DATA, $PHP_SELF;
58
    global $album, $cat, $pos, $pic_count, $lang_img_nav_bar, $lang_text_dir, $template_img_navbar;
59
 
60
    $cat_link = is_numeric($album) ? '' : '&cat=' . $cat;
61
 
62
    $human_pos = $pos + 1;
63
    $page = ceil(($pos + 1) / ($CONFIG['thumbrows'] * $CONFIG['thumbcols']));
64
    $pid = $CURRENT_PIC_DATA['pid'];
65
 
66
    if ($pos > 0) {
67
        $prev = $pos - 1;
68
        $prev_tgt = "$PHP_SELF?album=$album$cat_link&pos=$prev";
69
        $prev_title = $lang_img_nav_bar['prev_title'];
70
    } else {
71
        $prev_tgt = "javascript:;";
72
        $prev_title = "";
73
    }
74
    if ($pos < ($pic_count -1)) {
75
        $next = $pos + 1;
76
        $next_tgt = "$PHP_SELF?album=$album$cat_link&pos=$next";
77
        $next_title = $lang_img_nav_bar['next_title'];
78
    } else {
79
        $next_tgt = "javascript:;";
80
        $next_title = "";
81
    }
82
 
83
    if (USER_CAN_SEND_ECARDS) {
84
        $ecard_tgt = "ecard.php?album=$album$cat_link&pid=$pid&pos=$pos";
85
        $ecard_title = $lang_img_nav_bar['ecard_title'];
86
    } else {
87
        $ecard_tgt = "javascript:alert('" . addslashes($lang_img_nav_bar['ecard_disabled_msg']) . "');";
88
        $ecard_title = $lang_img_nav_bar['ecard_disabled'];
89
    }
90
 
91
    $thumb_tgt = "thumbnails.php?album=$album$cat_link&page=$page";
92
 
93
    $slideshow_tgt = "$PHP_SELF?album=$album$cat_link&pid=$pid&slideshow=".$CONFIG['slideshow_interval'];
94
 
95
    $pic_pos = sprintf($lang_img_nav_bar['pic_pos'], $human_pos, $pic_count);
96
 
97
    $params = array('{THUMB_TGT}' => $thumb_tgt,
98
        '{THUMB_TITLE}' => $lang_img_nav_bar['thumb_title'],
99
        '{PIC_INFO_TITLE}' => $lang_img_nav_bar['pic_info_title'],
100
        '{SLIDESHOW_TGT}' => $slideshow_tgt,
101
        '{SLIDESHOW_TITLE}' => $lang_img_nav_bar['slideshow_title'],
102
        '{PIC_POS}' => $pic_pos,
103
        '{ECARD_TGT}' => $ecard_tgt,
104
        '{ECARD_TITLE}' => $ecard_title,
105
        '{PREV_TGT}' => $prev_tgt,
106
        '{PREV_TITLE}' => $prev_title,
107
        '{NEXT_TGT}' => $next_tgt,
108
        '{NEXT_TITLE}' => $next_title,
109
        '{PREV_IMAGE}' => ($lang_text_dir=='LTR') ? 'prev' : 'next',
110
        '{NEXT_IMAGE}' => ($lang_text_dir=='LTR') ? 'next' : 'prev',
111
        );
112
 
113
    return template_eval($template_img_navbar, $params);
114
}
115
// Displays a picture
116
function html_picture()
117
{
118
    global $CONFIG, $CURRENT_PIC_DATA, $CURRENT_ALBUM_DATA, $USER, $HTTP_COOKIE_VARS;
119
    global $album, $comment_date_fmt, $template_display_picture;
120
    global $lang_display_image_php, $lang_picinfo;
121
 
122
    $pid = $CURRENT_PIC_DATA['pid'];
123
 
124
    if (!isset($USER['liv']) || !is_array($USER['liv'])) {
125
        $USER['liv'] = array();
126
    }
127
    // Add 1 to hit counter
128
    if ($album != "lasthits" && !in_array($pid, $USER['liv']) && isset($HTTP_COOKIE_VARS[$CONFIG['cookie_name'] . '_data'])) {
129
        add_hit($pid);
130
        if (count($USER['liv']) > 4) array_shift($USER['liv']);
131
        array_push($USER['liv'], $pid);
132
    }
133
 
134
    if($CONFIG['thumb_use']=='ht' && $CURRENT_PIC_DATA['pheight'] > $CONFIG['picture_width'] ){ // The wierd comparision is because only picture_width is stored
135
      $condition = true;
136
    }elseif($CONFIG['thumb_use']=='wd' && $CURRENT_PIC_DATA['pwidth'] > $CONFIG['picture_width']){
137
      $condition = true;
138
    }elseif($CONFIG['thumb_use']=='any' && max($CURRENT_PIC_DATA['pwidth'], $CURRENT_PIC_DATA['pheight']) > $CONFIG['picture_width']){
139
      $condition = true;
140
    }else{
141
     $condition = false;
142
    }
143
 
144
 
145
 
146
    if ($CONFIG['make_intermediate'] && $condition ) {
147
        $picture_url = get_pic_url($CURRENT_PIC_DATA, 'normal');
148
    } else {
149
        $picture_url = get_pic_url($CURRENT_PIC_DATA, 'fullsize');
150
    }
151
    $pic_thumb_url = get_pic_url($CURRENT_PIC_DATA,'thumb');
152
 
153
    $picture_menu = ((USER_ADMIN_MODE && $CURRENT_ALBUM_DATA['category'] == FIRST_USER_CAT + USER_ID) || GALLERY_ADMIN_MODE) ? html_picture_menu($pid) : '';
154
 
155
    $image_size = compute_img_size($CURRENT_PIC_DATA['pwidth'], $CURRENT_PIC_DATA['pheight'], $CONFIG['picture_width']);
156
 
157
    $pic_title = '';
158
    $mime_content = get_type($CURRENT_PIC_DATA['filename']);
159
 
160
 
161
    if ($CURRENT_PIC_DATA['title'] != '') {
162
        $pic_title .= $CURRENT_PIC_DATA['title'] . "\n";
163
    }
164
    if ($CURRENT_PIC_DATA['caption'] != '') {
165
        $pic_title .= $CURRENT_PIC_DATA['caption'] . "\n";
166
    }
167
    if ($CURRENT_PIC_DATA['keywords'] != '') {
168
        $pic_title .= $lang_picinfo['Keywords'] . ": " . $CURRENT_PIC_DATA['keywords'];
169
    }
170
 
171
    if ($CURRENT_PIC_DATA['pwidth']==0 || $CURRENT_PIC_DATA['pheight']==0) {
172
        $image_size['geom']='';
173
        $image_size['whole'] = '';
174
    } elseif ($mime_content['content']=='movie' || $mime_content['content']=='audio') {
175
        $ctrl_offset['mov']=15;
176
        $ctrl_offset['wmv']=45;
177
        $ctrl_offset['swf']=0;
178
        $ctrl_offset['rm']=0;
179
        $ctrl_offset_default=45;
180
        $ctrl_height = (isset($ctrl_offset[$mime_content['extension']]))?($ctrl_offset[$mime_content['extension']]):$ctrl_offset_default;
181
        $image_size['whole']='width="'.$CURRENT_PIC_DATA['pwidth'].'" height="'.($CURRENT_PIC_DATA['pheight']+$ctrl_height).'"';
182
    }
183
 
184
    if ($mime_content['content']=='image') {
185
        if (isset($image_size['reduced'])) {
186
            $winsizeX = $CURRENT_PIC_DATA['pwidth'] + 16;
187
            $winsizeY = $CURRENT_PIC_DATA['pheight'] + 16;
188
            $pic_html = "<a href=\"javascript:;\" onClick=\"MM_openBrWindow('displayimage.php?pid=$pid&fullsize=1','" . uniqid(rand()) . "','scrollbars=yes,toolbar=yes,status=yes,resizable=yes,width=$winsizeX,height=$winsizeY')\">";
189
            $pic_title = $lang_display_image_php['view_fs'] . "\n==============\n" . $pic_title;
190
            $pic_html .= "<img src=\"" . $picture_url . "\" class=\"image\" border=\"0\" alt=\"{$lang_display_image_php['view_fs']}\" /><br />";
191
            $pic_html .= "</a>\n";
192
        } else {
193
            $pic_html = "<img src=\"" . $picture_url . "\" {$image_size['geom']} class=\"image\" border=\"0\" /><br />\n";
194
        }
195
    } elseif ($mime_content['content']=='document') {
196
        $pic_html = "<a href=\"{$picture_url}\" target=\"_blank\" class=\"document_link\"><img src=\"".$pic_thumb_url."\" border=\"0\" class=\"image\" /></a>\n<br />";
197
    } else {
198
            $pic_html = "<object {$image_size['whole']}><param name=\"autostart\" value=\"true\"><param name=\"src\" value=\"". $picture_url . "\"><embed {$image_size['whole']} src=\"". $picture_url . "\" autostart=\"true\"></embed></object><br />\n";
199
    }
200
 
201
    if (!$CURRENT_PIC_DATA['title'] && !$CURRENT_PIC_DATA['caption']) {
202
        template_extract_block($template_display_picture, 'img_desc');
203
    } else {
204
        if (!$CURRENT_PIC_DATA['title']) {
205
            template_extract_block($template_display_picture, 'title');
206
        }
207
        if (!$CURRENT_PIC_DATA['caption']) {
208
            template_extract_block($template_display_picture, 'caption');
209
        }
210
    }
211
 
212
    $params = array('{CELL_HEIGHT}' => '100',
213
        '{IMAGE}' => $pic_html,
214
        '{ADMIN_MENU}' => $picture_menu,
215
        '{TITLE}' => $CURRENT_PIC_DATA['title'],
216
        '{CAPTION}' => bb_decode($CURRENT_PIC_DATA['caption']),
217
        );
218
 
219
    return template_eval($template_display_picture, $params);
220
}
221
 
222
function html_rating_box()
223
{
224
    global $CONFIG, $CURRENT_PIC_DATA, $CURRENT_ALBUM_DATA;
225
    global $template_image_rating, $lang_rate_pic;
226
 
227
    if (!(USER_CAN_RATE_PICTURES && $CURRENT_ALBUM_DATA['votes'] == 'YES')) return '';
228
 
229
    $votes = $CURRENT_PIC_DATA['votes'] ? sprintf($lang_rate_pic['rating'], round($CURRENT_PIC_DATA['pic_rating'] / 2000, 1), $CURRENT_PIC_DATA['votes']) : $lang_rate_pic['no_votes'];
230
    $pid = $CURRENT_PIC_DATA['pid'];
231
 
232
    $params = array('{TITLE}' => $lang_rate_pic['rate_this_pic'],
233
        '{VOTES}' => $votes,
234
        '{RATE0}' => "ratepic.php?pic=$pid&rate=0",
235
        '{RATE1}' => "ratepic.php?pic=$pid&rate=1",
236
        '{RATE2}' => "ratepic.php?pic=$pid&rate=2",
237
        '{RATE3}' => "ratepic.php?pic=$pid&rate=3",
238
        '{RATE4}' => "ratepic.php?pic=$pid&rate=4",
239
        '{RATE5}' => "ratepic.php?pic=$pid&rate=5",
240
        '{RUBBISH}' => $lang_rate_pic['rubbish'],
241
        '{POOR}' => $lang_rate_pic['poor'],
242
        '{FAIR}' => $lang_rate_pic['fair'],
243
        '{GOOD}' => $lang_rate_pic['good'],
244
        '{EXCELLENT}' => $lang_rate_pic['excellent'],
245
        '{GREAT}' => $lang_rate_pic['great'],
246
        );
247
 
248
    return template_eval($template_image_rating, $params);
249
}
250
// Display picture information
251
function html_picinfo()
252
{
253
    global $CONFIG, $CURRENT_PIC_DATA, $CURRENT_ALBUM_DATA, $THEME_DIR, $FAVPICS;
254
    global $album, $lang_picinfo, $lang_display_image_php, $lang_byte_units;
255
 
256
    if ($CURRENT_PIC_DATA['owner_id'] && $CURRENT_PIC_DATA['owner_name']) {
257
        $owner_link = '<a href ="profile.php?uid=' . $CURRENT_PIC_DATA['owner_id'] . '">' . $CURRENT_PIC_DATA['owner_name'] . '</a> ';
258
    } else {
259
        $owner_link = '';
260
    }
261
 
262
    if (GALLERY_ADMIN_MODE && $CURRENT_PIC_DATA['pic_raw_ip']) {
263
        if ($CURRENT_PIC_DATA['pic_hdr_ip']) {
264
            $ipinfo = ' (' . $CURRENT_PIC_DATA['pic_hdr_ip'] . '[' . $CURRENT_PIC_DATA['pic_raw_ip'] . ']) / ';
265
        } else {
266
            $ipinfo = ' (' . $CURRENT_PIC_DATA['pic_raw_ip'] . ') / ';
267
        }
268
    } else {
269
        if ($owner_link) {
270
            $ipinfo = '/ ';
271
        } else {
272
            $ipinfo = '';
273
        }
274
    }
275
 
276
    $info[$lang_picinfo['Filename']] = htmlspecialchars($CURRENT_PIC_DATA['filename']);
277
    $info[$lang_picinfo['Album name']] = '<span class="alblink">' . $owner_link . $ipinfo . '<a href="thumbnails.php?album=' . $CURRENT_PIC_DATA['aid'] . '">' . $CURRENT_ALBUM_DATA['title'] . '</a></span>';
278
 
279
    if ($CURRENT_PIC_DATA['votes'] > 0) {
280
        if (defined('THEME_HAS_RATING_GRAPHICS')) {
281
            $prefix = $THEME_DIR;
282
        } else {
283
            $prefix = '';
284
        }
285
        $info[sprintf($lang_picinfo['Rating'], $CURRENT_PIC_DATA['votes'])] = '<img src="' . $prefix . 'images/rating' . round($CURRENT_PIC_DATA['pic_rating'] / 2000) . '.gif" align="absmiddle"/>';
286
    }
287
 
288
    if ($CURRENT_PIC_DATA['keywords'] != "") {
289
        $info[$lang_picinfo['Keywords']] = '<span class="alblink">' . preg_replace("/(\S+)/", "<a href=\"thumbnails.php?album=search&search=\\1\">\\1</a>" , $CURRENT_PIC_DATA['keywords']) . '</span>';
290
    }
291
 
292
    for ($i = 1; $i <= 4; $i++) {
293
        if ($CONFIG['user_field' . $i . '_name']) {
294
            if ($CURRENT_PIC_DATA['user' . $i] != "") {
295
                $info[$CONFIG['user_field' . $i . '_name']] = make_clickable($CURRENT_PIC_DATA['user' . $i]);
296
            }
297
        }
298
    }
299
 
300
    $info[$lang_picinfo['File Size']] = ($CURRENT_PIC_DATA['filesize'] > 10240 ? ($CURRENT_PIC_DATA['filesize'] >> 10) . '&nbsp;' . $lang_byte_units[1] : $CURRENT_PIC_DATA['filesize'] . '&nbsp;' . $lang_byte_units[0]);
301
    $info[$lang_picinfo['File Size']] = '<span dir="LTR">' . $info[$lang_picinfo['File Size']] . '</span>';
302
    $info[$lang_picinfo['Dimensions']] = sprintf($lang_display_image_php['size'], $CURRENT_PIC_DATA['pwidth'], $CURRENT_PIC_DATA['pheight']);
303
    $info[$lang_picinfo['Displayed']] = sprintf($lang_display_image_php['views'], $CURRENT_PIC_DATA['hits']);
304
 
305
    $path_to_pic = $CONFIG['fullpath'] . $CURRENT_PIC_DATA['filepath'] . $CURRENT_PIC_DATA['filename'];
306
 
307
    if ($CONFIG['read_exif_data']) $exif = exif_parse_file($path_to_pic);
308
 
309
    if (isset($exif) && is_array($exif)) {
310
        if (isset($exif['Camera'])) $info[$lang_picinfo['Camera']] = $exif['Camera'];
311
        if (isset($exif['DateTaken'])) $info[$lang_picinfo['Date taken']] = $exif['DateTaken'];
312
        if (isset($exif['Aperture'])) $info[$lang_picinfo['Aperture']] = $exif['Aperture'];
313
        if (isset($exif['ISO'])) $info[$lang_picinfo['ISO']] = $exif['ISO'];
314
        if (isset($exif['ExposureTime'])) $info[$lang_picinfo['Exposure time']] = $exif['ExposureTime'];
315
        if (isset($exif['FocalLength'])) $info[$lang_picinfo['Focal length']] = $exif['FocalLength'];
316
        if (@strlen(trim($exif['Comment'])) > 0 ) {
317
                $info[$lang_picinfo['Comment']] = trim($exif['Comment']);
318
        }
319
    }
320
 
321
    if ($CONFIG['read_iptc_data']) $iptc = get_IPTC($path_to_pic);
322
 
323
    if (isset($iptc) && is_array($iptc)) {
324
        if (isset($iptc['Title'])) $info[$lang_picinfo['iptcTitle']] = trim($iptc['Title']);
325
        if (isset($iptc['Copyright'])) $info[$lang_picinfo['iptcCopyright']] = trim($iptc['Copyright']);
326
        if (isset($iptc['Keywords'])) $info[$lang_picinfo['iptcKeywords']] = trim(implode(" ",$iptc['Keywords']));
327
        if (isset($iptc['Category'])) $info[$lang_picinfo['iptcCategory']] = trim($iptc['Category']);
328
        if (isset($iptc['SubCategories'])) $info[$lang_picinfo['iptcSubCategories']] = trim(implode(" ",$iptc['SubCategories']));
329
    }
330
    // Create the absolute URL for display in info
331
    $info['URL'] = '<a href="' . $CONFIG["ecards_more_pic_target"] . (substr($CONFIG["ecards_more_pic_target"], -1) == '/' ? '' : '/') .basename($_SERVER['PHP_SELF']) . "?pos=-$CURRENT_PIC_DATA[pid]" . '" >' . $CONFIG["ecards_more_pic_target"] . (substr($CONFIG["ecards_more_pic_target"], -1) == '/' ? '' : '/') . basename($_SERVER['PHP_SELF']) . "?pos=-$CURRENT_PIC_DATA[pid]" . '</a>';
332
    // with subdomains the variable is $_SERVER["SERVER_NAME"] does not return the right value instead of using a new config variable I reused $CONFIG["ecards_more_pic_target"] no trailing slash in the configure
333
    // Create the add to fav link
334
    if (!in_array($CURRENT_PIC_DATA['pid'], $FAVPICS)) {
335
        $info[$lang_picinfo['addFavPhrase']] = "<a href=\"addfav.php?pid=" . $CURRENT_PIC_DATA['pid'] . "\">" . $lang_picinfo['addFav'] . '</a>';
336
    } else {
337
        $info[$lang_picinfo['addFavPhrase']] = "<a href=\"addfav.php?pid=" . $CURRENT_PIC_DATA['pid'] . "\">" . $lang_picinfo['remFav'] . '</a>';
338
    }
339
 
340
    return theme_html_picinfo($info);
341
}
342
// Displays comments for a specific picture
343
function html_comments($pid)
344
{
345
    global $CONFIG, $USER, $CURRENT_ALBUM_DATA, $comment_date_fmt, $HTML_SUBST;
346
    global $template_image_comments, $template_add_your_comment, $lang_display_comments;
347
 
348
    $html = '';
349
 
350
    if (!$CONFIG['enable_smilies']) {
351
        $tmpl_comment_edit_box = template_extract_block($template_image_comments, 'edit_box_no_smilies', '{EDIT}');
352
        template_extract_block($template_image_comments, 'edit_box_smilies');
353
        template_extract_block($template_add_your_comment, 'input_box_smilies');
354
    } else {
355
        $tmpl_comment_edit_box = template_extract_block($template_image_comments, 'edit_box_smilies', '{EDIT}');
356
        template_extract_block($template_image_comments, 'edit_box_no_smilies');
357
        template_extract_block($template_add_your_comment, 'input_box_no_smilies');
358
    }
359
 
360
    $tmpl_comments_buttons = template_extract_block($template_image_comments, 'buttons', '{BUTTONS}');
361
    $tmpl_comments_ipinfo = template_extract_block($template_image_comments, 'ipinfo', '{IPINFO}');
362
 
363
    $result = db_query("SELECT msg_id, msg_author, msg_body, UNIX_TIMESTAMP(msg_date) AS msg_date, author_id, author_md5_id, msg_raw_ip, msg_hdr_ip FROM {$CONFIG['TABLE_COMMENTS']} WHERE pid='$pid' ORDER BY msg_id ASC");
364
 
365
    while ($row = mysql_fetch_array($result)) {
366
        $user_can_edit = (GALLERY_ADMIN_MODE) || (USER_ID && USER_ID == $row['author_id'] && USER_CAN_POST_COMMENTS) || (!USER_ID && USER_CAN_POST_COMMENTS && ($USER['ID'] == $row['author_md5_id']));
367
        $comment_buttons = $user_can_edit ? $tmpl_comments_buttons : '';
368
        $comment_edit_box = $user_can_edit ? $tmpl_comment_edit_box : '';
369
        $comment_ipinfo = ($row['msg_raw_ip'] && GALLERY_ADMIN_MODE)?$tmpl_comments_ipinfo : '';
370
 
371
        if ($CONFIG['enable_smilies']) {
372
            $comment_body = process_smilies(make_clickable($row['msg_body']));
373
            $smilies = generate_smilies("f{$row['msg_id']}", 'msg_body');
374
        } else {
375
            $comment_body = make_clickable($row['msg_body']);
376
            $smilies = '';
377
        }
378
 
379
        $params = array('{EDIT}' => &$comment_edit_box,
380
            '{BUTTONS}' => &$comment_buttons,
381
            '{IPINFO}' => &$comment_ipinfo
382
            );
383
 
384
        $template = template_eval($template_image_comments, $params);
385
 
386
        $params = array('{MSG_AUTHOR}' => $row['msg_author'],
387
            '{MSG_ID}' => $row['msg_id'],
388
            '{EDIT_TITLE}' => &$lang_display_comments['edit_title'],
389
            '{CONFIRM_DELETE}' => &$lang_display_comments['confirm_delete'],
390
            '{MSG_DATE}' => localised_date($row['msg_date'], $comment_date_fmt),
391
            '{MSG_BODY}' => &$comment_body,
392
            '{MSG_BODY_RAW}' => $row['msg_body'],
393
            '{OK}' => &$lang_display_comments['OK'],
394
            '{SMILIES}' => $smilies,
395
            '{HDR_IP}' => $row['msg_hdr_ip'],
396
            '{RAW_IP}' => $row['msg_raw_ip'],
397
            );
398
 
399
        $html .= template_eval($template, $params);
400
    }
401
 
402
    if (USER_CAN_POST_COMMENTS && $CURRENT_ALBUM_DATA['comments'] == 'YES') {
403
        if (USER_ID) {
404
            $user_name_input = '<input type="hidden" name="msg_author" value="' . USER_NAME . '">';
405
            template_extract_block($template_add_your_comment, 'user_name_input', $user_name_input);
406
            $user_name = '';
407
        } else {
408
            $user_name = isset($USER['name']) ? '"' . strtr($USER['name'], $HTML_SUBST) . '"' : '"' . $lang_display_comments['your_name'] . '" onClick="javascript:this.value=\'\';"';
409
        }
410
 
411
        $params = array('{ADD_YOUR_COMMENT}' => $lang_display_comments['add_your_comment'],
412
            // Modified Name and comment field
413
            '{NAME}' => $lang_display_comments['name'],
414
            '{COMMENT}' => $lang_display_comments['comment'],
415
            '{PIC_ID}' => $pid,
416
            '{USER_NAME}' => $user_name,
417
            '{MAX_COM_LENGTH}' => $CONFIG['max_com_size'],
418
            '{OK}' => $lang_display_comments['OK'],
419
            '{SMILIES}' => '',
420
            );
421
 
422
        if ($CONFIG['enable_smilies']) $params['{SMILIES}'] = generate_smilies();
423
 
424
        $html .= template_eval($template_add_your_comment, $params);
425
    }
426
 
427
    return $html;
428
}
429
// Display the full size image
430
function display_fullsize_pic()
431
{
432
    global $CONFIG, $HTTP_GET_VARS, $THEME_DIR, $ALBUM_SET;
433
    global $lang_errors, $lang_fullsize_popup, $lang_charset;
434
 
435
    if (function_exists('theme_display_fullsize_pic')) {
436
        theme_display_fullsize_pic();
437
        return;
438
    }
439
 
440
    ?>
441
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
442
<html>
443
<head>
444
<title><?php echo $CONFIG['gallery_name'] ?>: <?php echo $lang_fullsize_popup['click_to_close'];
445
    ?></title>
446
<meta http-equiv="content-type" content="text/html; charset=<?php echo $CONFIG['charset'] == 'language file' ? $lang_charset : $CONFIG['charset'] ?>" />
447
<link rel="stylesheet" href="<?php echo $THEME_DIR ?>style.css" />
448
<script type="text/javascript" src="scripts.js"></script>
449
</head>
450
<body scroll="auto" marginwidth="0" marginheight="0">
451
<script language="JavaScript" type="text/JavaScript">
452
adjust_popup();
453
</script>
454
 
455
<table width="100%" height="100%" border="0" cellpadding="0" cellspacing="2">
456
 <td align="center" valign="middle">
457
  <table cellspacing="2" cellpadding="0" style="border: 1px solid #000000; background-color: #FFFFFF;">
458
   <td>
459
<?php
460
    if (isset($HTTP_GET_VARS['picfile'])) {
461
        if (!GALLERY_ADMIN_MODE) cpg_die(ERROR, $lang_errors['access_denied'], __FILE__, __LINE__);
462
 
463
        $picfile = $HTTP_GET_VARS['picfile'];
464
        $picname = $CONFIG['fullpath'] . $picfile;
465
        $imagesize = @getimagesize($picname);
466
        echo "<a href=\"javascript: window.close()\"><img src=\"" . path2url($picname) . "\" $imagesize[3] class=\"image\" border=\"0\" alt=\"\" title=\"$picfile\n" . $lang_fullsize_popup['click_to_close'] . "\"/></a><br />\n";
467
    } elseif (isset($HTTP_GET_VARS['pid'])) {
468
        $pid = (int)$HTTP_GET_VARS['pid'];
469
        $sql = "SELECT * " . "FROM {$CONFIG['TABLE_PICTURES']} " . "WHERE pid='$pid' $ALBUM_SET";
470
        $result = db_query($sql);
471
 
472
        if (!mysql_num_rows($result)) cpg_die(ERROR, $lang_errors['non_exist_ap'], __FILE__, __LINE__);
473
 
474
        $row = mysql_fetch_array($result);
475
        $pic_url = get_pic_url($row, 'fullsize');
476
        $geom = 'width="' . $row['pwidth'] . '" height="' . $row['pheight'] . '"';
477
        echo "<a href=\"javascript: window.close()\"><img src=\"" . $pic_url . "\" $geom class=\"image\" border=\"0\" alt=\"\" title=\"" . htmlspecialchars($row['filename']) . "\n" . $lang_fullsize_popup['click_to_close'] . "\"></a><br />\n";
478
    }
479
 
480
    ?>
481
   </td>
482
  </table>
483
 </td>
484
</table>
485
</body>
486
</html>
487
<?php
488
}
489
 
490
function slideshow()
491
{
492
    global $CONFIG, $HTTP_GET_VARS, $lang_display_image_php, $template_display_picture;
493
 
494
    if (function_exists('theme_slideshow')) {
495
        theme_slideshow();
496
        return;
497
    }
498
 
499
    pageheader($lang_display_image_php['slideshow']);
500
 
501
    include "include/slideshow.inc.php";
502
 
503
    $start_slideshow = '<script language="JavaScript" type="text/JavaScript">runSlideShow()</script>';
504
    template_extract_block($template_display_picture, 'img_desc', $start_slideshow);
505
 
506
    $params = array('{CELL_HEIGHT}' => $CONFIG['picture_width'] + 100,
507
        '{IMAGE}' => '<img src="' . $start_img . '" name="SlideShow" class="image" /><br />',
508
        '{ADMIN_MENU}' => '',
509
        );
510
 
511
    starttable();
512
    echo template_eval($template_display_picture, $params);
513
    endtable();
514
    starttable();
515
    echo <<<EOT
516
        <tr>
517
                <td align="center" class="navmenu" style="white-space: nowrap;">
518
                        <a href="javascript:endSlideShow()" class="navmenu">{$lang_display_image_php['stop_slideshow']}</a>
519
                </td>
520
        </tr>
521
 
522
EOT;
523
    endtable();
524
    pagefooter();
525
}
526
 
527
function get_subcat_data($parent, $level)
528
{
529
    global $CONFIG, $ALBUM_SET_ARRAY;
530
 
531
    $result = db_query("SELECT cid, name, description FROM {$CONFIG['TABLE_CATEGORIES']} WHERE parent = '$parent'");
532
    if (mysql_num_rows($result) > 0) {
533
        $rowset = db_fetch_rowset($result);
534
        foreach ($rowset as $subcat) {
535
            $result = db_query("SELECT aid FROM {$CONFIG['TABLE_ALBUMS']} WHERE category = {$subcat['cid']}");
536
            $album_count = mysql_num_rows($result);
537
            while ($row = mysql_fetch_array($result)) {
538
                $ALBUM_SET_ARRAY[] = $row['aid'];
539
            } // while
540
        }
541
        if ($level > 1) get_subcat_data($subcat['cid'], $level -1);
542
    }
543
}
544
 
545
/**
546
 * Main code
547
 */
548
 
549
$pos = isset($HTTP_GET_VARS['pos']) ? (int)$HTTP_GET_VARS['pos'] : 0;
550
$cat = isset($HTTP_GET_VARS['cat']) ? (int)$HTTP_GET_VARS['cat'] : 0;
551
$album = isset($HTTP_GET_VARS['album']) ? $HTTP_GET_VARS['album'] : '';
552
// Build the album set if required
553
if (!is_numeric($album) && $cat) { // Meta albums, we need to restrict the albums to the current category
554
    if ($cat < 0) {
555
        $ALBUM_SET .= 'AND aid IN (' . (- $cat) . ') ';
556
    } else {
557
        $ALBUM_SET_ARRAY = array();
558
        if ($cat == USER_GAL_CAT)
559
            $where = 'category > ' . FIRST_USER_CAT;
560
        else
561
            $where = "category = '$cat'";
562
 
563
        $result = db_query("SELECT aid FROM {$CONFIG['TABLE_ALBUMS']} WHERE $where");
564
        while ($row = mysql_fetch_array($result)) {
565
            $ALBUM_SET_ARRAY[] = $row['aid'];
566
        } // while
567
        get_subcat_data($cat, $CONFIG['subcat_level']);
568
        // Treat the album set
569
        if (count($ALBUM_SET_ARRAY)) {
570
            $set = '';
571
            foreach ($ALBUM_SET_ARRAY as $album_id) $set .= ($set == '') ? $album_id : ',' . $album_id;
572
            $ALBUM_SET .= "AND aid IN ($set) ";
573
        }
574
    }
575
}
576
// Retrieve data for the current picture
577
if ($pos < 0) {
578
    $pid = - $pos;
579
    $result = db_query("SELECT aid from {$CONFIG['TABLE_PICTURES']} WHERE pid='$pid' $ALBUM_SET LIMIT 1");
580
    if (mysql_num_rows($result) == 0) cpg_die(ERROR, $lang_errors['non_exist_ap'], __FILE__, __LINE__);
581
    $row = mysql_fetch_array($result);
582
    $album = $row['aid'];
583
    $pic_data = get_pic_data($album, $pic_count, $album_name, -1, -1, false);
584
    for($pos = 0; $pic_data[$pos]['pid'] != $pid && $pos < $pic_count; $pos++);
585
    $pic_data = get_pic_data($album, $pic_count, $album_name, $pos, 1, false);
586
    $CURRENT_PIC_DATA = $pic_data[0];
587
} elseif (isset($HTTP_GET_VARS['pos'])) {
588
    $pic_data = get_pic_data($album, $pic_count, $album_name, $pos, 1, false);
589
    if ($pic_count == 0) {
590
        cpg_die(INFORMATION, $lang_errors['no_img_to_display'], __FILE__, __LINE__);
591
    } elseif (count($pic_data) == 0 && $pos >= $pic_count) {
592
        $pos = $pic_count - 1;
593
        $human_pos = $pos + 1;
594
        $pic_data = get_pic_data($album, $pic_count, $album_name, $pos, 1, false);
595
    }
596
    $CURRENT_PIC_DATA = $pic_data[0];
597
}
598
// Retrieve data for the current album
599
if (isset($CURRENT_PIC_DATA)) {
600
    $result = db_query("SELECT title, comments, votes, category, aid FROM {$CONFIG['TABLE_ALBUMS']} WHERE aid='{$CURRENT_PIC_DATA['aid']}' LIMIT 1");
601
    if (!mysql_num_rows($result)) cpg_die(CRITICAL_ERROR, sprintf($lang_errors['pic_in_invalid_album'], $CURRENT_PIC_DATA['aid']), __FILE__, __LINE__);
602
    $CURRENT_ALBUM_DATA = mysql_fetch_array($result);
603
 
604
    if (is_numeric($album)) {
605
        $cat = - $album;
606
        $actual_cat = $CURRENT_ALBUM_DATA['category'];
607
        breadcrumb($actual_cat, $breadcrumb, $breadcrumb_text);
608
        $cat = - $album;
609
    } else {
610
        $actual_cat = $CURRENT_ALBUM_DATA['category'];
611
        breadcrumb($actual_cat, $breadcrumb, $breadcrumb_text);
612
    }
613
}
614
 
615
if (isset($HTTP_GET_VARS['fullsize'])) {
616
    display_fullsize_pic();
617
    ob_end_flush();
618
} elseif (isset($HTTP_GET_VARS['slideshow'])) {
619
    slideshow();
620
    ob_end_flush();
621
} else {
622
    if (!isset($HTTP_GET_VARS['pos'])) cpg_die(ERROR, $lang_errors['non_exist_ap'], __FILE__, __LINE__);
623
    $picture_title = $CURRENT_PIC_DATA['title'] ? $CURRENT_PIC_DATA['title'] : strtr(preg_replace("/(.+)\..*?\Z/", "\\1", htmlspecialchars($CURRENT_PIC_DATA['filename'])), "_", " ");
624
 
625
    $nav_menu = html_img_nav_menu();
626
    $picture = html_picture();
627
    $votes = html_rating_box();
628
    $pic_info = html_picinfo();
629
    $comments = html_comments($CURRENT_PIC_DATA['pid']);
630
    if ($CURRENT_PIC_DATA['keywords']) { $meta_keywords = "<meta name=\"keywords\" content=\"".$CURRENT_PIC_DATA['keywords']."\">"; }
631
 
632
    pageheader($album_name . '/' . $picture_title, $meta_keywords, false);
633
    // Display Breadcrumbs
634
    if ($breadcrumb && !(strpos($CONFIG['main_page_layout'],"breadcrumb")===false)) {
635
        theme_display_breadcrumb($breadcrumb, $cat_data);
636
    }
637
    // Display Filmstrip if the album is not search
638
    if ($album != 'search') {
639
        $film_strip = display_film_strip($album, (isset($cat) ? $cat : 0), $pos, true);
640
    }
641
    theme_display_image($nav_menu, $picture, $votes, $pic_info, $comments, $film_strip);
642
    pagefooter();
643
    ob_end_flush();
644
}
645
 
646
?>