Subversion Repositories svnkaklik

Rev

Go to most recent revision | 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/include/functions.inc.php,v $
15
  $Revision: 1.24 $
16
  $Author: gaugau $
17
  $Date: 2005/04/19 03:17:11 $
18
**********************************************/
19
 
20
/**************************************************************************
21
   Function for managing cookie saved user profile
22
 **************************************************************************/
23
 
24
// Decode the user profile contained in a cookie
25
function user_get_profile()
26
{
27
        global $CONFIG, $USER, $HTTP_COOKIE_VARS;
28
 
29
        if (isset($HTTP_COOKIE_VARS[$CONFIG['cookie_name'].'_data'])) {
30
                $USER = @unserialize(@base64_decode($HTTP_COOKIE_VARS[$CONFIG['cookie_name'].'_data']));
31
        }
32
 
33
        if (!isset($USER['ID']) || strlen($USER['ID']) != 32) {
34
                list($usec, $sec) = explode(' ', microtime());
35
                $seed = (float) $sec + ((float) $usec * 100000);
36
                srand($seed);
37
                $USER=array('ID' => md5(uniqid(rand(),1)));
38
        } else {
39
                $USER['ID'] = addslashes($USER['ID']);
40
        }
41
 
42
        if (!isset($USER['am'])) $USER['am'] = 1;
43
}
44
 
45
// Save the user profile in a cookie
46
function user_save_profile()
47
{
48
        global $CONFIG, $USER, $HTTP_SERVER_VARS;
49
 
50
        $data = base64_encode(serialize($USER));
51
        setcookie($CONFIG['cookie_name'].'_data', $data, time()+86400*30, $CONFIG['cookie_path']);
52
}
53
 
54
/**************************************************************************
55
   Database functions
56
 **************************************************************************/
57
 
58
// Connect to the database
59
function cpg_db_connect()
60
{
61
        global $CONFIG;
62
        $result = @mysql_connect($CONFIG['dbserver'], $CONFIG['dbuser'], $CONFIG['dbpass']);
63
        if (!$result)
64
                return false;
65
        if (!mysql_select_db($CONFIG['dbname']))
66
                return false;
67
        return $result;
68
}
69
 
70
// Perform a database query
71
function db_query($query, $link_id = 0)
72
{
73
        global $CONFIG, $query_stats, $queries;
74
 
75
        $query_start = cpgGetMicroTime();
76
        if (($link_id)) {
77
            $result = mysql_query($query, $link_id);
78
        } else {
79
                $result = mysql_query($query);
80
        }
81
        $query_end = cpgGetMicroTime();
82
        if (isset($CONFIG['debug_mode']) && (($CONFIG['debug_mode']==1) || ($CONFIG['debug_mode']==2) )) {
83
                $query_stats[] = $query_end - $query_start;
84
                $queries[] = $query;
85
        }
86
        if (!$result) db_error("While executing query \"$query\" on $link_id");
87
 
88
        return $result;
89
}
90
 
91
// Error message if a query failed
92
function db_error($the_error)
93
{
94
        global $CONFIG;
95
 
96
        if (!$CONFIG['debug_mode']) {
97
            cpg_die(CRITICAL_ERROR, 'There was an error while processing a database query', __FILE__, __LINE__);
98
        } else {
99
 
100
                $the_error .= "\n\nmySQL error: ".mysql_error()."\n";
101
 
102
                $out = "<br />There was an error while processing a database query.<br /><br/>
103
                    <form name='mysql'><textarea rows=\"8\" cols=\"60\">".htmlspecialchars($the_error)."</textarea></form>";
104
 
105
            cpg_die(CRITICAL_ERROR, $out, __FILE__, __LINE__);
106
        }
107
}
108
 
109
// Fetch all rows in an array
110
function db_fetch_rowset($result)
111
{
112
        $rowset = array();
113
 
114
        while ($row = mysql_fetch_array($result)) $rowset[] = $row;
115
 
116
        return $rowset;
117
}
118
 
119
/**************************************************************************
120
   Utilities functions
121
 **************************************************************************/
122
 
123
//define ('LOC','YToyOntzOjE6ImwiO3M6OToie0dBTExFUll9IjtzOjE6InMiO3M6MTY5OiI8ZGl2IGNsYXNzPSJmb290ZXIiIGFsaWduPSJjZW50ZXIiIHN0eWxlPSJwYWRkaW5nLXRvcDogMTBweDsiPlBvd2VyZWQgYnkgPGEgaHJlZj0iaHR0cDovL3d3dy5jaGV6Z3JlZy5uZXQvY29wcGVybWluZS8iIHRhcmdldD0iX2JsYW5rIj5Db3BwZXJtaW5lIFBob3RvIEdhbGxlcnk8L2E+PC9kaXY+Ijt9');
124
 define ('LOC','YToyOntzOjE6ImwiO3M6OToie0dBTExFUll9IjtzOjE6InMiO3M6MTU5OiI8ZGl2IGNsYXNzPSJmb290ZXIiIGFsaWduPSJjZW50ZXIiIHN0eWxlPSJwYWRkaW5nLXRvcDogMTBweDsiPlBvd2VyZWQgYnkgPGEgaHJlZj0iaHR0cDovL2NvcHBlcm1pbmUuc2YubmV0LyIgdGFyZ2V0PSJfYmxhbmsiPkNvcHBlcm1pbmUgUGhvdG8gR2FsbGVyeTwvYT48L2Rpdj4iO30=');
125
// Replacement for the die function
126
function cpg_die($msg_code, $msg_text,  $error_file, $error_line, $output_buffer = false)
127
{
128
        global $CONFIG, $lang_cpg_die, $template_cpg_die;
129
 
130
        // Simple output if theme file is not loaded
131
        if(!function_exists('pageheader')){
132
                echo 'Fatal error :<br />'.$msg_text;
133
                exit;
134
        }
135
 
136
    $ob = ob_get_contents();
137
        if ($ob) ob_end_clean();
138
 
139
        if(!$CONFIG['debug_mode']) template_extract_block($template_cpg_die, 'file_line');
140
        if(!$output_buffer && !$CONFIG['debug_mode']) template_extract_block($template_cpg_die, 'output_buffer');
141
 
142
        $params = array(
143
                '{MESSAGE}' => $msg_text,
144
                '{FILE_TXT}' => $lang_cpg_die['file'],
145
                '{FILE}' => $error_file,
146
                '{LINE_TXT}' => $lang_cpg_die['line'],
147
                '{LINE}' => $error_line,
148
                '{OUTPUT_BUFFER}' => $ob,
149
        );
150
 
151
        pageheader($lang_cpg_die[$msg_code]);
152
        starttable(-1, $lang_cpg_die[$msg_code]);
153
        echo template_eval($template_cpg_die, $params);
154
        endtable();
155
        pagefooter();
156
        exit;
157
}
158
 
159
// Display a localised date
160
function localised_date($timestamp = -1, $datefmt)
161
{
162
    global $lang_month, $lang_day_of_week;
163
 
164
    if ($timestamp == -1) {
165
        $timestamp = time();
166
    }
167
 
168
    $date = ereg_replace('%[aA]', $lang_day_of_week[(int)strftime('%w', $timestamp)], $datefmt);
169
    $date = ereg_replace('%[bB]', $lang_month[(int)strftime('%m', $timestamp)-1], $date);
170
 
171
    return strftime($date, $timestamp);
172
}
173
 
174
// Function to create correct URLs for image name with space or exotic characters
175
function path2url($path)
176
{
177
        return str_replace("%2F","/",rawurlencode($path));
178
}
179
 
180
// Display a 'message box like' table
181
function msg_box($title, $msg_text, $button_text="", $button_link="", $width="-1")
182
{
183
        global $template_msg_box;
184
 
185
        if (!$button_text) {
186
            template_extract_block($template_msg_box, 'button');
187
        }
188
 
189
        $params = array(
190
                '{MESSAGE}' => $msg_text,
191
                '{LINK}' => $button_link,
192
                '{TEXT}' => $button_text
193
        );
194
 
195
        starttable($width, $title);
196
        echo template_eval($template_msg_box, $params);
197
        endtable();
198
}
199
 
200
function create_tabs($items, $curr_page, $total_pages, $template)
201
{
202
        global $CONFIG;
203
 
204
        if (function_exists('theme_create_tabs')) {
205
            theme_create_tabs($items, $curr_page, $total_pages, $template);
206
                return;
207
        }
208
 
209
        $maxTab = $CONFIG['max_tabs'];
210
 
211
        $tabs = sprintf($template['left_text'], $items, $total_pages);
212
        if (($total_pages == 1)) return $tabs;
213
 
214
        $tabs .= $template['tab_header'];
215
        if ($curr_page == 1) {
216
                $tabs .= sprintf($template['active_tab'], 1);
217
        } else {
218
                $tabs .= sprintf($template['inactive_tab'], 1, 1);
219
        }
220
        if ($total_pages > $maxTab){
221
                $start = max(2, $curr_page - floor(($maxTab -2)/2));
222
                $start = min($start, $total_pages - $maxTab +2);
223
                $end = $start + $maxTab -3;
224
        } else {
225
                $start = 2;
226
                $end = $total_pages-1;
227
        }
228
        for ($page = $start ; $page <= $end; $page++) {
229
                if ($page == $curr_page) {
230
                        $tabs .= sprintf($template['active_tab'], $page);
231
                } else {
232
                        $tabs .= sprintf($template['inactive_tab'], $page, $page);
233
                }
234
        }
235
        if ($total_pages > 1){
236
                if ($curr_page == $total_pages) {
237
                        $tabs .= sprintf($template['active_tab'], $total_pages);
238
                } else {
239
                        $tabs .= sprintf($template['inactive_tab'], $total_pages, $total_pages);
240
                }
241
        }
242
        return $tabs.$template['tab_trailer'];
243
}
244
 
245
/**
246
 * Rewritten by Nathan Codding - Feb 6, 2001. Taken from phpBB code
247
 * - Goes through the given string, and replaces xxxx://yyyy with an HTML <a> tag linking
248
 *         to that URL
249
 * - Goes through the given string, and replaces www.xxxx.yyyy[zzzz] with an HTML <a> tag linking
250
 *         to http://www.xxxx.yyyy[/zzzz]
251
 * - Goes through the given string, and replaces xxxx@yyyy with an HTML mailto: tag linking
252
 *                to that email address
253
 * - Only matches these 2 patterns either after a space, or at the beginning of a line
254
 *
255
 * Notes: the email one might get annoying - it's easy to make it more restrictive, though.. maybe
256
 * have it require something like xxxx@yyyy.zzzz or such. We'll see.
257
 */
258
function make_clickable($text)
259
{
260
        $ret = " " . $text;
261
        $ret = preg_replace("#([\n ])([a-z]+?)://([a-z0-9\-\.,\?!%\*_\#:;~\\&$@\/=\+]+)#i", "\\1<a href=\"\\2://\\3\" target=\"_blank\">\\2://\\3</a>", $ret);
262
        $ret = preg_replace("#([\n ])www\.([a-z0-9\-]+)\.([a-z0-9\-.\~]+)((?:/[a-z0-9\-\.,\?!%\*_\#:;~\\&$@\/=\+]*)?)#i", "\\1<a href=\"http://www.\\2.\\3\\4\" target=\"_blank\">www.\\2.\\3\\4</a>", $ret);
263
        $ret = preg_replace("#([\n ])([a-z0-9\-_.]+?)@([\w\-]+\.([\w\-\.]+\.)?[\w]+)#i", "\\1<a href=\"mailto:\\2@\\3\">\\2@\\3</a>", $ret);
264
        $ret = substr($ret, 1);
265
 
266
        return($ret);
267
}
268
 
269
// Allow the use of a limited set of phpBB bb codes in albums and image descriptions
270
// Taken from phpBB code
271
function bb_decode($text)
272
{
273
        $text = nl2br($text);
274
 
275
        static $bbcode_tpl = array();
276
        static $patterns = array();
277
        static $replacements = array();
278
 
279
        // First: If there isn't a "[" and a "]" in the message, don't bother.
280
        if ((strpos($text, "[") === false || strpos($text, "]") === false))
281
        {
282
                return $text;
283
        }
284
 
285
        // [b] and [/b] for bolding text.
286
        $text = str_replace("[b]", '<b>', $text);
287
        $text = str_replace("[/b]", '</b>', $text);
288
 
289
        // [u] and [/u] for underlining text.
290
        $text = str_replace("[u]", '<u>', $text);
291
        $text = str_replace("[/u]", '</u>', $text);
292
 
293
        // [i] and [/i] for italicizing text.
294
        $text = str_replace("[i]", '<i>', $text);
295
        $text = str_replace("[/i]", '</i>', $text);
296
 
297
        // colours
298
        $text = preg_replace("/\[color=(\#[0-9A-F]{6}|[a-z]+)\]/", '<span style="color:$1">', $text);
299
        $text = str_replace("[/color]", '</span>', $text);
300
 
301
        // [i] and [/i] for italicizing text.
302
        //$text = str_replace("[i:$uid]", $bbcode_tpl['i_open'], $text);
303
        //$text = str_replace("[/i:$uid]", $bbcode_tpl['i_close'], $text);
304
 
305
        if (!count($bbcode_tpl)) {
306
                // We do URLs in several different ways..
307
                $bbcode_tpl['url']  = '<span class="bblink"><a href="{URL}" target="_blank">{DESCRIPTION}</a></span>';
308
                $bbcode_tpl['email']= '<span class="bblink"><a href="mailto:{EMAIL}">{EMAIL}</a></span>';
309
 
310
                $bbcode_tpl['url1'] = str_replace('{URL}', '\\1\\2', $bbcode_tpl['url']);
311
                $bbcode_tpl['url1'] = str_replace('{DESCRIPTION}', '\\1\\2', $bbcode_tpl['url1']);
312
 
313
                $bbcode_tpl['url2'] = str_replace('{URL}', 'http://\\1', $bbcode_tpl['url']);
314
                $bbcode_tpl['url2'] = str_replace('{DESCRIPTION}', '\\1', $bbcode_tpl['url2']);
315
 
316
                $bbcode_tpl['url3'] = str_replace('{URL}', '\\1\\2', $bbcode_tpl['url']);
317
                $bbcode_tpl['url3'] = str_replace('{DESCRIPTION}', '\\3', $bbcode_tpl['url3']);
318
 
319
                $bbcode_tpl['url4'] = str_replace('{URL}', 'http://\\1', $bbcode_tpl['url']);
320
                $bbcode_tpl['url4'] = str_replace('{DESCRIPTION}', '\\2', $bbcode_tpl['url4']);
321
 
322
                $bbcode_tpl['email'] = str_replace('{EMAIL}', '\\1', $bbcode_tpl['email']);
323
 
324
                // [url]xxxx://www.phpbb.com[/url] code..
325
                $patterns[1] = "#\[url\]([a-z]+?://){1}([a-z0-9\-\.,\?!%\*_\#:;~\\&$@\/=\+\(\)]+)\[/url\]#si";
326
                $replacements[1] = $bbcode_tpl['url1'];
327
 
328
                // [url]www.phpbb.com[/url] code.. (no xxxx:// prefix).
329
                $patterns[2] = "#\[url\]([a-z0-9\-\.,\?!%\*_\#:;~\\&$@\/=\+\(\)]+)\[/url\]#si";
330
                $replacements[2] = $bbcode_tpl['url2'];
331
 
332
                // [url=xxxx://www.phpbb.com]phpBB[/url] code..
333
                $patterns[3] = "#\[url=([a-z]+?://){1}([a-z0-9\-\.,\?!%\*_\#:;~\\&$@\/=\+\(\)]+)\](.*?)\[/url\]#si";
334
                $replacements[3] = $bbcode_tpl['url3'];
335
 
336
                // [url=www.phpbb.com]phpBB[/url] code.. (no xxxx:// prefix).
337
                $patterns[4] = "#\[url=([a-z0-9\-\.,\?!%\*_\#:;~\\&$@\/=\+\(\)]+)\](.*?)\[/url\]#si";
338
                $replacements[4] = $bbcode_tpl['url4'];
339
 
340
                // [email]user@domain.tld[/email] code..
341
                $patterns[5] = "#\[email\]([a-z0-9\-_.]+?@[\w\-]+\.([\w\-\.]+\.)?[\w]+)\[/email\]#si";
342
                $replacements[5] = $bbcode_tpl['email'];
343
 
344
                // [img]xxxx://www.phpbb.com[/img] code..
345
                $bbcode_tpl['img']  = '<img src="{URL}" >';
346
                $bbcode_tpl['img']  = str_replace('{URL}', '\\1\\2', $bbcode_tpl['img']);
347
 
348
                $patterns[6] = "#\[img\]([a-z]+?://){1}([a-z0-9\-\.,\?!%\*_\#:;~\\&$@\/=\+\(\)]+)\[/img\]#si";
349
                $replacements[6] = $bbcode_tpl['img'];
350
 
351
        }
352
 
353
        $text = preg_replace($patterns, $replacements, $text);
354
 
355
        return $text;
356
}
357
 
358
/**************************************************************************
359
   Template functions
360
 **************************************************************************/
361
 
362
// Load and parse the template.html file
363
function load_template()
364
{
365
        global $THEME_DIR, $CONFIG, $template_header, $template_footer;
366
 
367
        $tmpl_loc = array();
368
        $tmpl_loc = unserialize(base64_decode(LOC));
369
 
370
        if (file_exists(TEMPLATE_FILE)) {
371
            $template_file = TEMPLATE_FILE;
372
        } elseif (file_exists($THEME_DIR . TEMPLATE_FILE)) {
373
            $template_file = $THEME_DIR . TEMPLATE_FILE;
374
        } else die("<b>Coppermine critical error</b>:<br />Unable to load template file ".TEMPLATE_FILE."!</b>");
375
 
376
        $template = fread(fopen($template_file, 'r'), filesize($template_file));
377
        $gallery_pos = strpos($template, '{LANGUAGE_SELECT_FLAGS}');
378
        $template = str_replace('{LANGUAGE_SELECT_FLAGS}', languageSelect('flags') ,$template);
379
        $gallery_pos = strpos($template, '{LANGUAGE_SELECT_LIST}');
380
        $template = str_replace('{LANGUAGE_SELECT_LIST}', languageSelect('list') ,$template);
381
        $gallery_pos = strpos($template, '{THEME_DIR}');
382
        $template = str_replace('{THEME_DIR}', $THEME_DIR ,$template);
383
        $gallery_pos = strpos($template, '{THEME_SELECT_LIST}');
384
        $template = str_replace('{THEME_SELECT_LIST}', themeSelect('list') ,$template);
385
        $gallery_pos = strpos($template, $tmpl_loc['l']);
386
        $template = str_replace($tmpl_loc['l'], $tmpl_loc['s'] ,$template);
387
 
388
        $template_header = substr($template, 0, $gallery_pos);
389
        $template_footer = substr($template, $gallery_pos);
390
        $add_version_info = '<!--Coppermine Photo Gallery '.COPPERMINE_VERSION.'--></body>';
391
        $template_footer = ereg_replace("</body[^>]*>",$add_version_info,$template_footer);
392
}
393
 
394
// Eval a template (substitute vars with values)
395
function template_eval(&$template, &$vars)
396
{
397
        return strtr($template, $vars);
398
}
399
 
400
 
401
// Extract and return block '$block_name' from the template, the block is replaced by $subst
402
function template_extract_block(&$template, $block_name, $subst='')
403
{
404
        $pattern = "#(<!-- BEGIN $block_name -->)(.*?)(<!-- END $block_name -->)#s";
405
        if ( !preg_match($pattern, $template, $matches)){
406
                die('<b>Template error<b><br />Failed to find block \''.$block_name.'\'('.htmlspecialchars($pattern).') in :<br /><pre>'.htmlspecialchars($template).'</pre>');
407
        }
408
        $template = str_replace($matches[1].$matches[2].$matches[3], $subst, $template);
409
        return $matches[2];
410
}
411
 
412
/**************************************************************************
413
   Functions for album/picture management
414
 **************************************************************************/
415
 
416
// Get the list of albums that the current user can't see
417
function get_private_album_set()
418
{
419
        if (GALLERY_ADMIN_MODE) return;
420
        global $CONFIG, $ALBUM_SET, $USER_DATA, $FORBIDDEN_SET;
421
 
422
        if ($USER_DATA['can_see_all_albums']) return;
423
 
424
        $result = db_query("SELECT aid FROM {$CONFIG['TABLE_ALBUMS']} WHERE visibility != '0' AND visibility !='".(FIRST_USER_CAT + USER_ID)."' AND visibility NOT IN ".USER_GROUP_SET);
425
        if ((mysql_num_rows($result))) {
426
                $set ='';
427
            while($album=mysql_fetch_array($result)){
428
                    $set .= $album['aid'].',';
429
            } // while
430
                $FORBIDDEN_SET = "p.aid NOT IN (".substr($set, 0, -1).') ';
431
                $ALBUM_SET .= 'AND aid NOT IN ('.substr($set, 0, -1).') ';
432
        }
433
        mysql_free_result($result);
434
}
435
 
436
// Retrieve the data for a picture or a set of picture
437
function get_pic_data($album, &$count, &$album_name, $limit1=-1, $limit2=-1, $set_caption = true)
438
{
439
        global $USER, $CONFIG, $ALBUM_SET, $CURRENT_CAT_NAME, $CURRENT_ALBUM_KEYWORD, $HTTP_GET_VARS, $HTML_SUBST, $THEME_DIR, $FAVPICS;
440
        global $album_date_fmt, $lastcom_date_fmt, $lastup_date_fmt, $lasthit_date_fmt;
441
        global $lang_get_pic_data, $lang_meta_album_names, $lang_errors;
442
 
443
        $sort_array = array('na' => 'filename ASC', 'nd' => 'filename DESC', 'ta'=>'title ASC', 'td'=>'title DESC', 'da' => 'pid ASC', 'dd' => 'pid DESC');
444
        $sort_code = isset($USER['sort'])? $USER['sort'] : $CONFIG['default_sort_order'];
445
        $sort_order = isset($sort_array[$sort_code]) ? $sort_array[$sort_code] : $sort_array[$CONFIG['default_sort_order']];
446
        $limit = ($limit1 != -1) ? ' LIMIT '. $limit1 : '';
447
        $limit .= ($limit2 != -1) ? ' ,'. $limit2 : '';
448
 
449
        if ($limit2 == 1) {
450
            $select_columns = '*';
451
        } else {
452
            $select_columns = 'pid, filepath, filename, url_prefix, filesize, pwidth, pheight, ctime, aid';
453
        }
454
 
455
        // Keyword
456
        if (!empty($CURRENT_ALBUM_KEYWORD)){
457
                $keyword = "OR keywords like '%$CURRENT_ALBUM_KEYWORD%'";
458
        } else $keyword = '';
459
 
460
        // Regular albums
461
        if ((is_numeric($album))) {
462
                $album_name_keyword = get_album_name($album);
463
                $album_name = $album_name_keyword['title'];
464
                $album_keyword = $album_name_keyword['keyword'];
465
 
466
                if (!empty($album_keyword)){
467
                        $keyword = "OR keywords like '%$album_keyword%'";
468
                }
469
 
470
                $approved = GALLERY_ADMIN_MODE ? '' : 'AND approved=\'YES\'';
471
 
472
                $result = db_query("SELECT COUNT(*) from {$CONFIG['TABLE_PICTURES']} WHERE aid='$album' $keyword $approved $ALBUM_SET");
473
                $nbEnr = mysql_fetch_array($result);
474
                $count = $nbEnr[0];
475
                mysql_free_result($result);
476
 
477
                if($select_columns != '*') $select_columns .= ', title, caption,hits,owner_id,owner_name';
478
 
479
                $result = db_query("SELECT $select_columns from {$CONFIG['TABLE_PICTURES']} WHERE aid='$album' $keyword $approved $ALBUM_SET ORDER BY $sort_order $limit");
480
                $rowset = db_fetch_rowset($result);
481
                mysql_free_result($result);
482
                // Set picture caption
483
                if ($set_caption) foreach ($rowset as $key => $row){
484
 
485
                        $caption = "<span class=\"thumb_title\">";
486
                        $caption .= ($rowset[$key]['title']||$rowset[$key]['hits']) ? $rowset[$key]['title'] : '';
487
 
488
            if ($CONFIG['views_in_thumbview']){
489
               if ($rowset[$key]['title']){$caption .= "&nbsp;&ndash;&nbsp;";}
490
            $caption .= sprintf($lang_get_pic_data['n_views'], $rowset[$key]['hits']);
491
            }
492
                 $caption .= "</span>";
493
 
494
 
495
                        if ($CONFIG['caption_in_thumbview']){
496
                           $caption .= $rowset[$key]['caption'] ? "<span class=\"thumb_caption\">".bb_decode(($rowset[$key]['caption']))."</span>" : '';
497
                        }
498
                        if ($CONFIG['display_comment_count']) {
499
                                $comments_nr = count_pic_comments($row['pid']);
500
                                if ($comments_nr > 0) $caption .= "<span class=\"thumb_num_comments\">".sprintf($lang_get_pic_data['n_comments'], $comments_nr )."</span>";
501
                        }
502
 
503
                        if ($CONFIG['display_uploader']){
504
                                $caption .= '<span class="thumb_title"><a href ="profile.php?uid='.$rowset[$key]['owner_id'].'">'.$rowset[$key]['owner_name'].'</a></span>';
505
                        }
506
 
507
                        $rowset[$key]['caption_text'] = $caption;
508
 
509
                }
510
 
511
                return $rowset;
512
        }
513
 
514
 
515
        // Meta albums
516
        switch($album){
517
        case 'lastcom': // Last comments
518
                if ($ALBUM_SET && $CURRENT_CAT_NAME) {
519
                        $album_name = $album_name = $lang_meta_album_names['lastcom'].' - '. $CURRENT_CAT_NAME;
520
                } else {
521
                        $album_name = $lang_meta_album_names['lastcom'];
522
                }
523
                $query = "SELECT COUNT(*) from {$CONFIG['TABLE_COMMENTS']}, {$CONFIG['TABLE_PICTURES']}  WHERE approved = 'YES' AND {$CONFIG['TABLE_COMMENTS']}.pid = {$CONFIG['TABLE_PICTURES']}.pid $keyword $ALBUM_SET";
524
                $result = db_query($query);
525
 
526
                $nbEnr = mysql_fetch_array($result);
527
                $count = $nbEnr[0];
528
                mysql_free_result($result);
529
 
530
                if($select_columns == '*'){
531
                        $select_columns = 'p.*';
532
                } else {
533
                        $select_columns = str_replace('pid', 'c.pid', $select_columns).', msg_id, author_id, msg_author, UNIX_TIMESTAMP(msg_date) as msg_date, msg_body, aid';
534
                }
535
 
536
                $TMP_SET = str_replace($CONFIG['TABLE_PICTURES'],'p',$ALBUM_SET);
537
                $result = db_query("SELECT $select_columns FROM {$CONFIG['TABLE_COMMENTS']} as c, {$CONFIG['TABLE_PICTURES']} as p WHERE approved = 'YES' AND c.pid = p.pid $keyword $TMP_SET ORDER by msg_id DESC $limit");
538
 
539
 
540
                $rowset = db_fetch_rowset($result);
541
                mysql_free_result($result);
542
 
543
                if ($set_caption) foreach ($rowset as $key => $row){
544
                        if ($row['author_id']) {
545
                            $user_link = '<a href ="profile.php?uid='.$row['author_id'].'">'.$row['msg_author'].'</a>';
546
                        } else {
547
                                $user_link = $row['msg_author'];
548
                        }
549
                        $msg_body = strlen($row['msg_body']) > 50 ? @substr($row['msg_body'],0,50)."...": $row['msg_body'];
550
                        if ($CONFIG['enable_smilies']) $msg_body = process_smilies($msg_body);
551
                        $caption = '<span class="thumb_title">'.$user_link.'</span>'.'<span class="thumb_caption">'.localised_date($row['msg_date'], $lastcom_date_fmt).'</span>'.'<span class="thumb_caption">'.$msg_body.'</span>';
552
                        $rowset[$key]['caption_text'] = $caption;
553
                }
554
                return $rowset;
555
                break;
556
 
557
        case 'lastcomby': // Last comments by a specific user
558
                if (isset($USER['uid'])) {
559
                        $uid = (int)$USER['uid'];
560
                } else {
561
                        $uid = -1;
562
                }
563
 
564
                $user_name = get_username($uid);
565
                if ($ALBUM_SET && $CURRENT_CAT_NAME) {
566
                        $album_name = $album_name = $lang_meta_album_names['lastcom'].' - '. $CURRENT_CAT_NAME .' - '. $user_name;
567
                } else {
568
                        $album_name = $lang_meta_album_names['lastcom'].' - '. $user_name;
569
                }
570
                $result = db_query("SELECT COUNT(*) from {$CONFIG['TABLE_COMMENTS']}, {$CONFIG['TABLE_PICTURES']}  WHERE approved = 'YES' AND author_id = '$uid' AND {$CONFIG['TABLE_COMMENTS']}.pid = {$CONFIG['TABLE_PICTURES']}.pid $ALBUM_SET");
571
                $nbEnr = mysql_fetch_array($result);
572
                $count = $nbEnr[0];
573
                mysql_free_result($result);
574
 
575
                if($select_columns == '*'){
576
                        $select_columns = 'p.*';
577
                } else {
578
                        $select_columns = str_replace('pid', 'c.pid', $select_columns).', msg_id, author_id, msg_author, UNIX_TIMESTAMP(msg_date) as msg_date, msg_body, aid';
579
                }
580
 
581
                $result = db_query("SELECT $select_columns FROM {$CONFIG['TABLE_COMMENTS']} as c, {$CONFIG['TABLE_PICTURES']} as p WHERE approved = 'YES' AND author_id = '$uid' AND c.pid = p.pid $ALBUM_SET ORDER by msg_id DESC $limit");
582
                $rowset = db_fetch_rowset($result);
583
                mysql_free_result($result);
584
 
585
                if ($set_caption) foreach ($rowset as $key => $row){
586
                        if ($row['author_id']) {
587
                            $user_link = '<a href ="profile.php?uid='.$row['author_id'].'">'.$row['msg_author'].'</a>';
588
                        } else {
589
                                $user_link = $row['msg_author'];
590
                        }
591
 
592
                        $caption = '<span class="thumb_title">'.$user_link.'</span>'.'<span class="thumb_caption">'.localised_date($row['msg_date'], $lastcom_date_fmt).'</span>'.'<span class="thumb_caption">'.$row['msg_body'].'</span>';
593
                        $rowset[$key]['caption_text'] = $caption;
594
                }
595
                return $rowset;
596
                break;
597
 
598
        case 'lastup': // Last uploads
599
                if ($ALBUM_SET && $CURRENT_CAT_NAME) {
600
                        $album_name = $lang_meta_album_names['lastup'].' - '. $CURRENT_CAT_NAME;
601
                } else {
602
                        $album_name = $lang_meta_album_names['lastup'];
603
                }
604
 
605
                $result = db_query("SELECT COUNT(*) from {$CONFIG['TABLE_PICTURES']} WHERE approved = 'YES' $ALBUM_SET");
606
                $nbEnr = mysql_fetch_array($result);
607
                $count = $nbEnr[0];
608
                mysql_free_result($result);
609
 
610
                if($select_columns != '*' ) $select_columns .= ',title, caption, owner_id, owner_name, aid';
611
 
612
                $result = db_query("SELECT $select_columns FROM {$CONFIG['TABLE_PICTURES']} WHERE approved = 'YES' $ALBUM_SET ORDER BY pid DESC $limit");
613
 
614
                $rowset = db_fetch_rowset($result);
615
                mysql_free_result($result);
616
 
617
                if ($set_caption) foreach ($rowset as $key => $row){
618
                        $user_link = ($CONFIG['display_uploader'] && $row['owner_id'] && $row['owner_name']) ? '<span class="thumb_title"><a href ="profile.php?uid='.$row['owner_id'].'">'.$row['owner_name'].'</a></span>' : '';
619
                        $caption = $user_link.'<span class="thumb_caption">'.localised_date($row['ctime'], $lastup_date_fmt).'</span>';
620
                        $rowset[$key]['caption_text'] = $caption;
621
                }
622
                return $rowset;
623
                break;
624
 
625
        case 'lastupby': // Last uploads by a specific user
626
                if (isset($USER['uid'])) {
627
                        $uid = (int)$USER['uid'];
628
                } else {
629
                        $uid = -1;
630
                }
631
 
632
                $user_name = get_username($uid);
633
                if ($ALBUM_SET && $CURRENT_CAT_NAME) {
634
                        $album_name = $lang_meta_album_names['lastup'].' - '. $CURRENT_CAT_NAME .' - '. $user_name;
635
                } else {
636
                        $album_name = $lang_meta_album_names['lastup'] .' - '. $user_name;
637
                }
638
 
639
                $result = db_query("SELECT COUNT(*) from {$CONFIG['TABLE_PICTURES']} WHERE approved = 'YES' AND owner_id = '$uid' $ALBUM_SET");
640
                $nbEnr = mysql_fetch_array($result);
641
                $count = $nbEnr[0];
642
                mysql_free_result($result);
643
 
644
                if($select_columns != '*' ) $select_columns .= ', owner_id, owner_name, aid';
645
 
646
                $result = db_query("SELECT $select_columns FROM {$CONFIG['TABLE_PICTURES']} WHERE approved = 'YES' AND owner_id = '$uid' $ALBUM_SET ORDER BY pid DESC $limit");
647
 
648
                $rowset = db_fetch_rowset($result);
649
                mysql_free_result($result);
650
 
651
                if ($set_caption) foreach ($rowset as $key => $row){
652
                        if ($row['owner_id'] && $row['owner_name']) {
653
                            $user_link = '<span class="thumb_title"><a href ="profile.php?uid='.$row['owner_id'].'">'.$row['owner_name'].'</a></span>';
654
                        } else {
655
                                $user_link = '';
656
                        }
657
                        $caption = $user_link.'<span class="thumb_caption">'.localised_date($row['ctime'], $lastup_date_fmt).'</span>';
658
                        $rowset[$key]['caption_text'] = $caption;
659
                }
660
                return $rowset;
661
                break;
662
 
663
        case 'topn': // Most viewed pictures
664
                if ($ALBUM_SET && $CURRENT_CAT_NAME) {
665
                        $album_name = $lang_meta_album_names['topn'].' - '. $CURRENT_CAT_NAME;
666
                } else {
667
                        $album_name = $lang_meta_album_names['topn'];
668
                }
669
                $query ="SELECT COUNT(*) from {$CONFIG['TABLE_PICTURES']} WHERE approved = 'YES' AND hits > 0  $ALBUM_SET $keyword";
670
 
671
                $result = db_query($query);
672
                $nbEnr = mysql_fetch_array($result);
673
                $count = $nbEnr[0];
674
                mysql_free_result($result);
675
 
676
                if($select_columns != '*') $select_columns .= ', hits, aid, filename';
677
 
678
                $result = db_query("SELECT $select_columns FROM {$CONFIG['TABLE_PICTURES']} WHERE approved = 'YES'AND hits > 0 $ALBUM_SET $keyword ORDER BY hits DESC, filename  $limit");
679
 
680
                $rowset = db_fetch_rowset($result);
681
                mysql_free_result($result);
682
 
683
                if ($set_caption) foreach ($rowset as $key => $row){
684
                        $caption = "<span class=\"thumb_caption\">".sprintf($lang_get_pic_data['n_views'], $row['hits']).'</span>';
685
                        $rowset[$key]['caption_text'] = $caption;
686
                }
687
                return $rowset;
688
                break;
689
 
690
        case 'toprated': // Top rated pictures
691
                if ($ALBUM_SET && $CURRENT_CAT_NAME) {
692
                        $album_name = $lang_meta_album_names['toprated'].' - '. $CURRENT_CAT_NAME;
693
                } else {
694
                        $album_name = $lang_meta_album_names['toprated'];
695
                }
696
                $result = db_query("SELECT COUNT(*) from {$CONFIG['TABLE_PICTURES']} WHERE approved = 'YES' AND votes >= '{$CONFIG['min_votes_for_rating']}' $ALBUM_SET");
697
                $nbEnr = mysql_fetch_array($result);
698
                $count = $nbEnr[0];
699
                mysql_free_result($result);
700
 
701
                if($select_columns != '*') $select_columns .= ', pic_rating, votes, aid';
702
 
703
                $result = db_query("SELECT $select_columns FROM {$CONFIG['TABLE_PICTURES']} WHERE approved = 'YES' AND votes >= '{$CONFIG['min_votes_for_rating']}' $ALBUM_SET ORDER BY ROUND((pic_rating+1)/2000) DESC, votes DESC, filename $limit");
704
                $rowset = db_fetch_rowset($result);
705
                mysql_free_result($result);
706
 
707
                if ($set_caption) foreach ($rowset as $key => $row){
708
                        if (defined('THEME_HAS_RATING_GRAPHICS')) {
709
                            $prefix= $THEME_DIR;
710
                        } else {
711
                            $prefix= '';
712
                        }
713
                        $caption = "<span class=\"thumb_caption\">".'<img src="'.$prefix.'images/rating'.round($row['pic_rating']/2000).'.gif" align="absmiddle"/>'.'<br />'.sprintf($lang_get_pic_data['n_votes'], $row['votes']).'</span>';
714
                        $rowset[$key]['caption_text'] = $caption;
715
                }
716
                return $rowset;
717
                break;
718
 
719
        case 'lasthits': // Last viewed pictures
720
                if ($ALBUM_SET && $CURRENT_CAT_NAME) {
721
                        $album_name = $lang_meta_album_names['lasthits'].' - '. $CURRENT_CAT_NAME;
722
                } else {
723
                        $album_name = $lang_meta_album_names['lasthits'];
724
                }
725
                $result = db_query("SELECT COUNT(*) from {$CONFIG['TABLE_PICTURES']} WHERE approved = 'YES' $ALBUM_SET");
726
                $nbEnr = mysql_fetch_array($result);
727
                $count = $nbEnr[0];
728
                mysql_free_result($result);
729
 
730
                if($select_columns != '*') $select_columns .= ', UNIX_TIMESTAMP(mtime) as mtime, aid';
731
 
732
                $result = db_query("SELECT $select_columns FROM {$CONFIG['TABLE_PICTURES']} WHERE approved = 'YES' $ALBUM_SET ORDER BY mtime DESC $limit");
733
                $rowset = db_fetch_rowset($result);
734
                mysql_free_result($result);
735
 
736
                if ($set_caption) foreach ($rowset as $key => $row){
737
                        $caption = "<span class=\"thumb_caption\">".localised_date($row['mtime'], $lasthit_date_fmt).'</span>';
738
                        $rowset[$key]['caption_text'] = $caption;
739
                }
740
                return $rowset;
741
                break;
742
 
743
        case 'random': // Random pictures
744
                if ($ALBUM_SET && $CURRENT_CAT_NAME) {
745
                        $album_name = $lang_meta_album_names['random'].' - '. $CURRENT_CAT_NAME;
746
                } else {
747
                        $album_name = $lang_meta_album_names['random'];
748
                }
749
                $result = db_query("SELECT COUNT(*) from {$CONFIG['TABLE_PICTURES']} WHERE approved = 'YES' $ALBUM_SET");
750
                $nbEnr = mysql_fetch_array($result);
751
                $pic_count = $nbEnr[0];
752
                mysql_free_result($result);
753
 
754
                if($select_columns != '*') $select_columns .= ', aid';
755
 
756
                // if we have more than 1000 pictures, we limit the number of picture returned
757
                // by the SELECT statement as ORDER BY RAND() is time consuming
758
                                /* Commented out due to image not found bug
759
                if ($pic_count > 1000) {
760
                    $result = db_query("SELECT COUNT(*) from {$CONFIG['TABLE_PICTURES']} WHERE approved = 'YES'");
761
                        $nbEnr = mysql_fetch_array($result);
762
                        $total_count = $nbEnr[0];
763
                        mysql_free_result($result);
764
 
765
                        $granularity = floor($total_count / RANDPOS_MAX_PIC);
766
                        $cor_gran = ceil($total_count / $pic_count);
767
                        srand(time());
768
                        for ($i=1; $i<= $cor_gran; $i++) $random_num_set =rand(0, $granularity).', ';
769
                        $random_num_set = substr($random_num_set,0, -2);
770
                        $result = db_query("SELECT $select_columns FROM {$CONFIG['TABLE_PICTURES']} WHERE  randpos IN ($random_num_set) AND approved = 'YES' $ALBUM_SET ORDER BY RAND() LIMIT $limit2");
771
                } else {
772
                                */
773
                $sql = "SELECT $select_columns FROM {$CONFIG['TABLE_PICTURES']} WHERE approved = 'YES' $ALBUM_SET ORDER BY RAND() LIMIT $limit2";
774
                $result = db_query($sql);
775
 
776
                $rowset = array();
777
                while($row = mysql_fetch_array($result)){
778
                        $row['caption_text'] = '';
779
                        $rowset[-$row['pid']] = $row;
780
                }
781
                mysql_free_result($result);
782
 
783
                return $rowset;
784
                break;
785
 
786
        case 'search': // Search results
787
                if (isset($USER['search'])) {
788
                        $search_string = $USER['search'];
789
                } else {
790
                        $search_string = '';
791
                }
792
 
793
                if (substr($search_string, 0, 3) == '###') {
794
                    $query_all = 1;
795
                        $search_string = substr($search_string, 3);
796
                } else {
797
                    $query_all = 0;
798
                }
799
 
800
                if ($ALBUM_SET && $CURRENT_CAT_NAME) {
801
                        $album_name = $lang_meta_album_names['search'].' - '. $CURRENT_CAT_NAME;
802
                } else {
803
                        $album_name = $lang_meta_album_names['search'].' - "'. strtr($search_string, $HTML_SUBST) . '"';
804
                }
805
 
806
                include 'include/search.inc.php';
807
                return $rowset;
808
                break;
809
 
810
        case 'lastalb': // Last albums to which uploads
811
                if ($ALBUM_SET && $CURRENT_CAT_NAME) {
812
                        $album_name = $lang_meta_album_names['lastalb'].' - '. $CURRENT_CAT_NAME;
813
                } else {
814
                        $album_name = $lang_meta_album_names['lastalb'];
815
                }
816
 
817
 
818
                $ALBUM_SET = str_replace( "aid", $CONFIG['TABLE_PICTURES'].".aid" , $ALBUM_SET );
819
 
820
                $result = db_query("SELECT COUNT(*) from {$CONFIG['TABLE_PICTURES']} WHERE approved = 'YES' $ALBUM_SET");
821
                $nbEnr = mysql_fetch_array($result);
822
                $count = $nbEnr[0];
823
                mysql_free_result($result);
824
 
825
                $result = db_query("SELECT *,{$CONFIG['TABLE_ALBUMS']}.title AS title,{$CONFIG['TABLE_ALBUMS']}.aid AS aid  FROM {$CONFIG['TABLE_PICTURES']},{$CONFIG['TABLE_ALBUMS']} WHERE {$CONFIG['TABLE_PICTURES']}.aid = {$CONFIG['TABLE_ALBUMS']}.aid AND approved = 'YES' $ALBUM_SET GROUP  BY {$CONFIG['TABLE_PICTURES']}.aid ORDER BY {$CONFIG['TABLE_PICTURES']}.ctime DESC $limit");
826
                $rowset = db_fetch_rowset($result);
827
                mysql_free_result($result);
828
 
829
                if ($set_caption) foreach ($rowset as $key => $row){
830
                        $caption = "<span class=\"thumb_caption\">".$row['title']." - ".localised_date($row['ctime'], $lastup_date_fmt).'</span>';
831
                        $rowset[$key]['caption_text'] = $caption;
832
                }
833
                return $rowset;
834
                break;
835
 
836
        case 'favpics': // Favourite Pictures
837
 
838
                $album_name = $lang_meta_album_names['favpics'];
839
                                $rowset = array();
840
                if (count($FAVPICS)>0){
841
                        $favs = implode(",",$FAVPICS);
842
                        $result = db_query("SELECT COUNT(*) from {$CONFIG['TABLE_PICTURES']} WHERE approved = 'YES' AND pid IN ($favs)");
843
                        $nbEnr = mysql_fetch_array($result);
844
                        $count = $nbEnr[0];
845
                        mysql_free_result($result);
846
 
847
                        $select_columns = '*';
848
 
849
                        $result = db_query("SELECT $select_columns FROM {$CONFIG['TABLE_PICTURES']} WHERE approved = 'YES'AND pid IN ($favs) $limit");
850
                        $rowset = db_fetch_rowset($result);
851
 
852
                        mysql_free_result($result);
853
 
854
                        if ($set_caption) foreach ($rowset as $key => $row){
855
                                $caption = $rowset[$key]['title'] ? "<span class=\"thumb_caption\">".($rowset[$key]['title'])."</span>" : '';
856
                                $rowset[$key]['caption_text'] = $caption;
857
                        }
858
                }
859
                return $rowset;
860
                break;
861
 
862
        default : // Invalid meta album
863
        cpg_die(ERROR, $lang_errors['non_exist_ap'], __FILE__, __LINE__);
864
        }
865
} // End of get_pic_data
866
 
867
 
868
// Get the name of an album
869
function get_album_name($aid)
870
{
871
        global $CONFIG;
872
        global $lang_errors;
873
 
874
        $result = db_query("SELECT title,keyword from {$CONFIG['TABLE_ALBUMS']} WHERE aid='$aid'");
875
        $count = mysql_num_rows($result);
876
        if ($count > 0) {
877
                $row = mysql_fetch_array($result);
878
                return $row;
879
        } else {
880
                cpg_die(ERROR, $lang_errors['non_exist_ap'], __FILE__, __LINE__);
881
        }
882
}
883
 
884
// Return the name of a user
885
function get_username($uid)
886
{
887
        global $CONFIG;
888
 
889
        $uid = (int)$uid;
890
 
891
        if (!$uid) {
892
            return 'Anonymous';
893
        } elseif (defined('UDB_INTEGRATION')) {
894
           return udb_get_user_name($uid);
895
        } else {
896
                $result = db_query("SELECT user_name FROM {$CONFIG['TABLE_USERS']} WHERE user_id = '".$uid."'");
897
                if (mysql_num_rows($result) == 0) return '';
898
                $row = mysql_fetch_array($result);
899
                mysql_free_result($result);
900
                return $row['user_name'];
901
        }
902
}
903
 
904
// Return the ID of a user
905
function get_userid($username)
906
{
907
        global $CONFIG;
908
 
909
        $username = addslashes($username);
910
 
911
        if (!$username) {
912
            return 0;
913
        } elseif (defined('UDB_INTEGRATION')) { // (Altered to fix banning w/ bb integration - Nibbler)
914
           return udb_get_user_id($username);
915
        } else {
916
                $result = db_query("SELECT user_id FROM {$CONFIG['TABLE_USERS']} WHERE user_name = '".$username."'");
917
                if (mysql_num_rows($result) == 0) return 0;
918
                $row = mysql_fetch_array($result);
919
                mysql_free_result($result);
920
                return $row['user_id'];
921
        }
922
}
923
 
924
// Return the total number of comments for a certain picture
925
function count_pic_comments($pid, $skip=0)
926
{
927
        global $CONFIG;
928
        $result = db_query("SELECT count(*) from {$CONFIG['TABLE_COMMENTS']} where pid=$pid and msg_id!=$skip");
929
        $nbEnr = mysql_fetch_array($result);
930
        $count = $nbEnr[0];
931
        mysql_free_result($result);
932
 
933
        return $count;
934
}
935
 
936
// Add 1 everytime a picture is viewed.
937
function add_hit($pid)
938
{
939
        global $CONFIG;
940
 
941
        db_query("UPDATE {$CONFIG['TABLE_PICTURES']} SET hits=hits+1 WHERE pid='$pid'");
942
}
943
 
944
 
945
// Build the breadcrumb
946
function breadcrumb($cat, &$breadcrumb, &$BREADCRUMB_TEXT)
947
{
948
        global $album, $lang_errors, $lang_list_categories;
949
        global $CONFIG,$CURRENT_ALBUM_DATA, $CURRENT_CAT_NAME;
950
        if ($cat != 0) { //Categories other than 0 need to be selected
951
                $breadcrumb_array = array();
952
                if ($cat >= FIRST_USER_CAT) {
953
                        $user_name = get_username($cat - FIRST_USER_CAT);
954
                        if (!$user_name) $user_name = 'Mr. X';
955
 
956
                        $breadcrumb_array[] = array($cat, $user_name);
957
                        $CURRENT_CAT_NAME = sprintf($lang_list_categories['xx_s_gallery'], $user_name);
958
                        $row['parent'] = 1;
959
                } else {
960
                    $result = db_query("SELECT name, parent FROM {$CONFIG['TABLE_CATEGORIES']} WHERE cid = '$cat'");
961
                        if (mysql_num_rows($result) == 0) cpg_die(CRITICAL_ERROR, $lang_errors['non_exist_cat'], __FILE__, __LINE__);
962
                        $row = mysql_fetch_array($result);
963
 
964
                        $breadcrumb_array[] = array($cat, $row['name']);
965
                        $CURRENT_CAT_NAME = $row['name'];
966
                        mysql_free_result($result);
967
                }
968
 
969
                while($row['parent'] != 0){
970
                    $result = db_query("SELECT cid, name, parent FROM {$CONFIG['TABLE_CATEGORIES']} WHERE cid = '{$row['parent']}'");
971
                        if (mysql_num_rows($result) == 0) cpg_die(CRITICAL_ERROR, $lang_errors['orphan_cat'], __FILE__, __LINE__);
972
                        $row = mysql_fetch_array($result);
973
 
974
                        $breadcrumb_array[] = array($row['cid'], $row['name']);
975
                        mysql_free_result($result);
976
                } // while
977
 
978
                $breadcrumb_array = array_reverse($breadcrumb_array);
979
                $breadcrumb = '<a href="index.php">'.$lang_list_categories['home'].'</a>';
980
                $BREADCRUMB_TEXT = $lang_list_categories['home'];
981
 
982
                foreach ($breadcrumb_array as $category){
983
                        $link = "<a href=\"index.php?cat={$category[0]}\">{$category[1]}</a>";
984
                        $breadcrumb .= ' > ' . $link;
985
                        $BREADCRUMB_TEXT .= ' > ' . $category[1];
986
                }
987
 
988
        }else{ //Dont bother just add the Home link  to breadcrumb
989
                $breadcrumb = '<a href="index.php">'.$lang_list_categories['home'].'</a>';
990
                $BREADCRUMB_TEXT = $lang_list_categories['home'];
991
        }
992
        //Add Link for album if aid is set
993
        if (isset($CURRENT_ALBUM_DATA['aid'])){
994
                $link = "<a href=\"thumbnails.php?album=".$CURRENT_ALBUM_DATA['aid']."\">".$CURRENT_ALBUM_DATA['title']."</a>";
995
                $breadcrumb .= ' > ' . $link;
996
                $BREADCRUMB_TEXT .= ' > ' . $CURRENT_ALBUM_DATA['title'];
997
        }
998
}
999
 
1000
 
1001
 
1002
 
1003
 
1004
/**************************************************************************
1005
 
1006
 **************************************************************************/
1007
 
1008
// Compute image geometry based on max width / height
1009
function compute_img_size($width, $height, $max)
1010
{
1011
         global $CONFIG;
1012
        $thumb_use=$CONFIG['thumb_use'];
1013
        if($thumb_use=='ht') {
1014
          $ratio = $height / $max;
1015
        } elseif($thumb_use=='wd') {
1016
          $ratio = $width / $max;
1017
        } else {
1018
          $ratio = max($width, $height) / $max;
1019
        }
1020
        if ($ratio > 1.0) {
1021
                $image_size['reduced'] = true;
1022
        }
1023
        $ratio = max($ratio, 1.0);
1024
        $image_size['width'] = ceil($width / $ratio);
1025
        $image_size['height'] = ceil($height / $ratio);
1026
        $image_size['whole'] = 'width="'.$image_size['width'].'" height="'.$image_size['height'].'"';
1027
        if($thumb_use=='ht') {
1028
          $image_size['geom'] = ' height="'.$image_size['height'].'"';
1029
        } elseif($thumb_use=='wd') {
1030
          $image_size['geom'] = 'width="'.$image_size['width'].'"';
1031
        } else {
1032
          $image_size['geom'] = 'width="'.$image_size['width'].'" height="'.$image_size['height'].'"';
1033
        }
1034
 
1035
 
1036
 
1037
        return $image_size;
1038
}
1039
 
1040
// Prints thumbnails of pictures in an album
1041
function display_thumbnails($album, $cat, $page, $thumbcols, $thumbrows, $display_tabs)
1042
{
1043
        global $CONFIG, $AUTHORIZED, $HTTP_GET_VARS;
1044
        global $album_date_fmt, $lang_display_thumbnails, $lang_errors, $lang_byte_units;
1045
 
1046
        $thumb_per_page = $thumbcols * $thumbrows;
1047
        $lower_limit = ($page-1) * $thumb_per_page;
1048
 
1049
        $pic_data = get_pic_data($album, $thumb_count, $album_name, $lower_limit, $thumb_per_page);
1050
 
1051
        $total_pages = ceil($thumb_count / $thumb_per_page);
1052
 
1053
        $i = 0;
1054
        if (count($pic_data) > 0) {
1055
                foreach ($pic_data as $key => $row) {
1056
                        $i++;
1057
 
1058
                        $pic_title =$lang_display_thumbnails['filename'].$row['filename']."\n".
1059
                                $lang_display_thumbnails['filesize'].($row['filesize'] >> 10).$lang_byte_units[1]."\n".
1060
                                $lang_display_thumbnails['dimensions'].$row['pwidth']."x".$row['pheight']."\n".
1061
                                $lang_display_thumbnails['date_added'].localised_date($row['ctime'], $album_date_fmt);
1062
 
1063
                        $pic_url =  get_pic_url($row, 'thumb');
1064
                        if (!is_image($row['filename'])) {
1065
                                $image_info = getimagesize($pic_url);
1066
                                $row['pwidth'] = $image_info[0];
1067
                                $row['pheight'] = $image_info[1];
1068
                        }
1069
 
1070
                        $image_size = compute_img_size($row['pwidth'], $row['pheight'], $CONFIG['thumb_width']);
1071
 
1072
                        $thumb_list[$i]['pos'] = $key < 0 ? $key : $i - 1 + $lower_limit;
1073
                        $thumb_list[$i]['image'] = "<img src=\"" . $pic_url . "\" class=\"image\" {$image_size['geom']} border=\"0\" alt=\"{$row['filename']}\" title=\"$pic_title\">";
1074
                        $thumb_list[$i]['caption'] = $row['caption_text'];
1075
                        $thumb_list[$i]['admin_menu'] = '';
1076
                        $thumb_list[$i]['aid'] = $row['aid'];
1077
                }
1078
                theme_display_thumbnails($thumb_list, $thumb_count, $album_name, $album, $cat, $page, $total_pages, is_numeric($album), $display_tabs);
1079
        } else {
1080
                theme_no_img_to_display($album_name);
1081
        }
1082
}
1083
 
1084
/**
1085
 * Return an array containing the system thumbs in a directory
1086
 */
1087
function cpg_get_system_thumb_list($search_folder = 'images/')
1088
{
1089
        global $CONFIG;
1090
        static $thumbs = array();
1091
 
1092
        $folder = 'images/';
1093
 
1094
        $thumb_pfx =& $CONFIG['thumb_pfx'];
1095
        // If thumb array is empty get list from coppermine 'images' folder
1096
        if ((count($thumbs) == 0) && ($folder == $search_folder)) {
1097
                $dir = opendir($folder);
1098
                while (($file = readdir($dir))!==false) {
1099
                        if (is_file($folder . $file) && strpos($file,$thumb_pfx) === 0) {
1100
                                // Store filenames in an array
1101
                                $thumbs[] = array('filename' => $file);
1102
                        }
1103
                }
1104
                closedir($dir);
1105
                return $thumbs;
1106
        } elseif ($folder == $search_folder) {
1107
                // Search folder is the same as coppermine images folder; just return the array
1108
                return $thumbs;
1109
        } else {
1110
                // Search folder is the different; check for files in the given folder
1111
                $results = array();
1112
                foreach ($thumbs as $thumb) {
1113
                        if (is_file($search_folder.$thumb['filename'])) {
1114
                                $results[] = array('filename' => $thumb['filename']);
1115
                        }
1116
                }
1117
                return $results;
1118
        }
1119
}
1120
 
1121
// Prints thumbnails of pictures in an album
1122
function display_film_strip($album, $cat, $pos)
1123
{
1124
        global $CONFIG, $AUTHORIZED, $HTTP_GET_VARS;
1125
        global $album_date_fmt, $lang_display_thumbnails, $lang_errors, $lang_byte_units;
1126
        $max_item=$CONFIG['max_film_strip_items'];
1127
        //$thumb_per_page = $pos+$CONFIG['max_film_strip_items'];
1128
        $thumb_per_page = $max_item*2;
1129
        $l_limit = max(0,$pos-$CONFIG['max_film_strip_items']);
1130
        $new_pos=max(0,$pos-$l_limit);
1131
 
1132
        $pic_data = get_pic_data($album, $thumb_count, $album_name, $l_limit, $thumb_per_page);
1133
 
1134
        if (count($pic_data) < $max_item ){
1135
                $max_item = count($pic_data);
1136
        }
1137
        $lower_limit=3;
1138
 
1139
        if(!isset($pic_data[$new_pos+1])) {
1140
           $lower_limit=$new_pos-$max_item+1;
1141
        } else if(!isset($pic_data[$new_pos+2])) {
1142
           $lower_limit=$new_pos-$max_item+2;
1143
        } else if(!isset($pic_data[$new_pos-1])) {
1144
           $lower_limit=$new_pos;
1145
        } else {
1146
          $hf=$max_item/2;
1147
          $ihf=(int)($max_item/2);
1148
          if($new_pos > $hf ) {
1149
             //if($max_item%2==0) {
1150
               //$lower_limit=
1151
             //} else {
1152
             {
1153
               $lower_limit=$new_pos-$ihf;
1154
             }
1155
          }
1156
          elseif($new_pos < $hf ) { $lower_limit=0; }
1157
        }
1158
 
1159
        $pic_data=array_slice($pic_data,$lower_limit,$max_item);
1160
        $i=$l_limit;
1161
        if (count($pic_data) > 0) {
1162
                foreach ($pic_data as $key => $row) {
1163
                        $hi =(($pos==($i + $lower_limit)) ? '1': '');
1164
                        $i++;
1165
 
1166
                        $pic_title =$lang_display_thumbnails['filename'].$row['filename']."\n".
1167
                                $lang_display_thumbnails['filesize'].($row['filesize'] >> 10).$lang_byte_units[1]."\n".
1168
                                $lang_display_thumbnails['dimensions'].$row['pwidth']."x".$row['pheight']."\n".
1169
                                $lang_display_thumbnails['date_added'].localised_date($row['ctime'], $album_date_fmt);
1170
 
1171
                        $pic_url =  get_pic_url($row, 'thumb');
1172
                        if (!is_image($row['filename'])) {
1173
                                $image_info = getimagesize($pic_url);
1174
                                $row['pwidth'] = $image_info[0];
1175
                                $row['pheight'] = $image_info[1];
1176
                        }
1177
 
1178
                        $image_size = compute_img_size($row['pwidth'], $row['pheight'], $CONFIG['thumb_width']);
1179
 
1180
                        $p=$i - 1 + $lower_limit;
1181
                        $p=($p < 0 ? 0 : $p);
1182
                        $thumb_list[$i]['pos'] = $key < 0 ? $key : $p;
1183
                        $thumb_list[$i]['image'] = "<img src=\"" . $pic_url . "\" class=\"image\" {$image_size['geom']} border=\"0\" alt=\"{$row['filename']}\" title=\"$pic_title\">";
1184
                        $thumb_list[$i]['caption'] = $row['caption_text'];
1185
                        $thumb_list[$i]['admin_menu'] = '';
1186
 
1187
                }
1188
                return theme_display_film_strip($thumb_list, $thumb_count, $album_name, $album, $cat, $pos, is_numeric($album));
1189
        } else {
1190
                theme_no_img_to_display($album_name);
1191
        }
1192
}
1193
 
1194
// Return the url for a picture, allows to have pictures spreaded over multiple servers
1195
function get_pic_url(&$pic_row, $mode)
1196
{
1197
        global $CONFIG,$THEME_DIR;
1198
 
1199
        static $pic_prefix = array();
1200
        static $url_prefix = array();
1201
 
1202
        if (!count($pic_prefix)) {
1203
                $pic_prefix = array(
1204
                        'thumb' => $CONFIG['thumb_pfx'],
1205
                        'normal' => $CONFIG['normal_pfx'],
1206
                        'fullsize' => ''
1207
                );
1208
 
1209
                $url_prefix = array(
1210
 
1211
                );
1212
        }
1213
 
1214
        $mime_content = get_type($pic_row['filename']);
1215
        $filepathname = null;
1216
 
1217
        // Code to handle custom thumbnails
1218
        // If fullsize or normal mode use regular file
1219
        if ($mime_content['content'] != 'image' && $mode!= 'thumb') {
1220
                $mode = 'fullsize';
1221
        } elseif ($mime_content['content'] != 'image' && $mode == 'thumb') {
1222
                $thumb_extensions = Array('.gif','.png','.jpg');
1223
                // Check for user-level custom thumbnails
1224
                // Create custom thumb path and erase extension using filename; Erase filename's extension
1225
                $custom_thumb_path = $url_prefix[$pic_row['url_prefix']].$pic_row['filepath'].$pic_prefix[$mode];
1226
                $file_base_name = str_replace('.'.$mime_content['extension'],'',basename($pic_row['filename']));
1227
                // Check for file-specific thumbs
1228
                foreach ($thumb_extensions as $extension) {
1229
                        if (file_exists($custom_thumb_path.$file_base_name.$extension)) {
1230
                                $filepathname = $custom_thumb_path.$file_base_name.$extension;
1231
                                break;
1232
                        }
1233
                }
1234
                // Check for extension-specific thumbs
1235
                if (is_null($filepathname)) {
1236
                        foreach ($thumb_extensions as $extension) {
1237
                                if (file_exists($custom_thumb_path.$mime_content['extension'].$extension)) {
1238
                                        $filepathname = $custom_thumb_path.$mime_content['extension'].$extension;
1239
                                        break;
1240
                                }
1241
                        }
1242
                }
1243
                // Check for content-specific thumbs
1244
                if (is_null($filepathname)) {
1245
                        foreach ($thumb_extensions as $extension) {
1246
                                if (file_exists($custom_thumb_path.$mime_content['content'].$extension)) {
1247
                                        $filepathname = $custom_thumb_path.$mime_content['content'].$extension;
1248
                                        break;
1249
                                }
1250
                        }
1251
                }
1252
                // Use default thumbs
1253
                if (is_null($filepathname)) {
1254
                               // Check for default theme- and global-level thumbs
1255
                               $thumb_paths[] = $THEME_DIR.'/images/';                 // Used for custom theme thumbs
1256
                               $thumb_paths[] = 'images/';                             // Default Coppermine thumbs
1257
                               foreach ($thumb_paths as $default_thumb_path) {
1258
                                       if (is_dir($default_thumb_path)) {
1259
                                               foreach ($thumb_extensions as $extension) {
1260
                                                       // Check for extension-specific thumbs
1261
                                                       if (file_exists($default_thumb_path.$CONFIG['thumb_pfx'].$mime_content['extension'].$extension)) {
1262
                                                               $filepathname = $default_thumb_path.$CONFIG['thumb_pfx'].$mime_content['extension'].$extension;
1263
                                                               break 2;
1264
                                                       }
1265
                                        }
1266
                                               foreach ($thumb_extensions as $extension) {
1267
                                                       // Check for media-specific thumbs (movie,document,audio)
1268
                                                       if (file_exists($default_thumb_path.$CONFIG['thumb_pfx'].$mime_content['content'].$extension)) {
1269
                                                               $filepathname = $default_thumb_path.$CONFIG['thumb_pfx'].$mime_content['content'].$extension;
1270
                                                               break 2;
1271
                                                       }
1272
                                               }
1273
                                       }
1274
                               }
1275
                }
1276
                return path2url($filepathname);
1277
        }
1278
 
1279
        return $url_prefix[$pic_row['url_prefix']]. path2url($pic_row['filepath']. $pic_prefix[$mode]. $pic_row['filename']);
1280
}
1281
 
1282
// Return a variable from the default language file
1283
function& cpg_get_default_lang_var($language_var_name,$overide_language = null) {
1284
        global $CONFIG;
1285
        if (is_null($overide_language)) {
1286
                if (isset($CONFIG['default_lang'])) {
1287
                        $language = $CONFIG['default_lang'];
1288
                } else {
1289
                               $language = $CONFIG['lang'];
1290
                }
1291
        } else {
1292
                       $language = $overide_language;
1293
        }
1294
        include('lang/'.$language.'.php');
1295
        return $$language_var_name;
1296
}
1297
 
1298
// Returns a variable from the current language file
1299
// If variable doesn't exists gets value from english lang file
1300
function& cpg_lang_var($varname,$index=null) {
1301
        global $$varname;
1302
 
1303
        $lang_var =& $$varname;
1304
 
1305
        if (isset($lang_var)) {
1306
                if (!is_null($index) && !isset($lang_var[$index])) {
1307
                        include('lang/english.php');
1308
                        return $lang_var[$index];
1309
                } elseif (is_null($index)) {
1310
                        return $lang_var;
1311
                } else {
1312
                               return $lang_var[$index];
1313
                }
1314
        } else {
1315
                       include('lang/english.php');
1316
                       return $lang_var;
1317
        }
1318
}
1319
 
1320
//defined new debug_output function here in functions.inc.php instead of theme.php with different function names to avoid incompatibilities with users not updating their themes as required. Advanced info is only output if (GALLERY_ADMIN_MODE == TRUE)  - GauGau 2003-11-23
1321
 
1322
function cpg_debug_output()
1323
{
1324
    global $HTTP_GET_VARS, $HTTP_POST_VARS, $HTTP_SERVER_VARS;
1325
    global $USER, $USER_DATA, $ALBUM_SET, $CONFIG, $time_start, $query_stats, $queries, $lang_cpg_debug_output;
1326
        $time_end = cpgGetMicroTime();
1327
        $time = round($time_end - $time_start, 3);
1328
 
1329
        $query_count = count($query_stats);
1330
        $query_times = '';
1331
        $total_query_time = 0;
1332
        foreach ($query_stats as $qtime) {
1333
            $query_times .= round($qtime, 3) . "s ";
1334
            $total_query_time += $qtime;
1335
        }
1336
        $total_query_time = round($total_query_time, 3);
1337
        $debug_underline = '&#0010;------------------&#0010;';
1338
        $debug_separate = '&#0010;==========================&#0010;';
1339
        echo '<form name="debug">';
1340
        starttable('100%', $lang_cpg_debug_output['debug_info'],2);
1341
        echo '<tr><td align="center" valign="middle" class="tableh2">';
1342
        echo '<script language="Javascript">
1343
<!--
1344
 
1345
function HighlightAll(theField) {
1346
var tempval=eval("document."+theField)
1347
tempval.focus()
1348
tempval.select()
1349
}
1350
//-->
1351
</script>';
1352
        echo '
1353
        <div class="admin_menu"><a href="javascript:HighlightAll(\'debug.debugtext\')" class="adm_menu">' . $lang_cpg_debug_output['select_all'] . '</a></div>';
1354
        echo '</td><td align="left" valign="middle" class="tableh2">';
1355
        if (GALLERY_ADMIN_MODE){echo '<span class="album_stat">('.$lang_cpg_debug_output['copy_and_paste_instructions'].')</span>';}
1356
        echo '</td></tr>';
1357
        echo '<tr><td class="tableb" colspan="2">';
1358
        echo '<textarea  rows="10" class="debug_text" name="debugtext">';
1359
        echo "USER: ";
1360
        echo $debug_underline;
1361
        print_r($USER);
1362
        echo $debug_separate;
1363
        echo "USER DATA:";
1364
        echo $debug_underline;
1365
        print_r($USER_DATA);
1366
        echo $debug_separate;
1367
        echo "Queries:";
1368
        echo $debug_underline;
1369
        print_r($queries);
1370
        echo $debug_separate;
1371
        echo "GET :";
1372
        echo $debug_underline;
1373
        print_r($HTTP_GET_VARS);
1374
        echo $debug_separate;
1375
        echo "POST :";
1376
        echo $debug_underline;
1377
        print_r($HTTP_POST_VARS);
1378
        echo $debug_separate;
1379
        if (GALLERY_ADMIN_MODE){
1380
        echo "VERSION INFO :";
1381
        echo $debug_underline;
1382
        $version_comment = ' - OK';
1383
        if (strcmp('4.0.0', phpversion()) == 1) {$version_comment = ' - your PHP version isn\'t good enough! Minimum requirements: 4.x';}
1384
        echo 'PHP version: ' . phpversion().$version_comment;
1385
        echo $debug_underline;
1386
        $version_comment = '';
1387
        $mySqlVersion = cpg_phpinfo_mysql_version();
1388
        if (strcmp('3.23.23', $mySqlVersion) == 1) {$version_comment = ' - your mySQL version isn\'t good enough! Minimum requirements: 3.23.23';}
1389
        echo 'mySQL version: ' . $mySqlVersion . $version_comment;
1390
        echo $debug_underline;
1391
        echo 'Coppermine version: ';
1392
        echo COPPERMINE_VERSION;
1393
        echo $debug_separate;
1394
        error_reporting  (E_ERROR | E_WARNING | E_PARSE);
1395
        echo cpg_phpinfo_mod_output('gd','text');
1396
        echo cpg_phpinfo_mod_output('mysql','text');
1397
        echo cpg_phpinfo_mod_output('zlib','text');
1398
        echo 'Server restrictions (safe mode)?';
1399
        echo $debug_underline;
1400
        echo 'Directive | Local Value | Master Value';
1401
        echo cpg_phpinfo_conf_output("safe_mode");
1402
        echo cpg_phpinfo_conf_output("safe_mode_exec_dir");
1403
        echo cpg_phpinfo_conf_output("safe_mode_gid");
1404
        echo cpg_phpinfo_conf_output("safe_mode_include_dir");
1405
        echo cpg_phpinfo_conf_output("safe_mode_exec_dir");
1406
        echo cpg_phpinfo_conf_output("sql.safe_mode");
1407
        echo cpg_phpinfo_conf_output("disable_functions");
1408
        echo cpg_phpinfo_conf_output("file_uploads");
1409
        echo cpg_phpinfo_conf_output("include_path");
1410
        echo cpg_phpinfo_conf_output("open_basedir");
1411
        echo $debug_separate;
1412
        echo 'email';
1413
        echo $debug_underline;
1414
        echo 'Directive | Local Value | Master Value';
1415
        echo cpg_phpinfo_conf_output("sendmail_from");
1416
        echo cpg_phpinfo_conf_output("sendmail_path");
1417
        echo cpg_phpinfo_conf_output("SMTP");
1418
        echo cpg_phpinfo_conf_output("smtp_port");
1419
        echo $debug_separate;
1420
        echo 'Size and Time';
1421
        echo $debug_underline;
1422
        echo 'Directive | Local Value | Master Value';
1423
        echo cpg_phpinfo_conf_output("max_execution_time");
1424
        echo cpg_phpinfo_conf_output("max_input_time");
1425
        echo cpg_phpinfo_conf_output("upload_max_filesize");
1426
        echo cpg_phpinfo_conf_output("post_max_size");
1427
        echo $debug_separate;
1428
        }
1429
 
1430
        echo <<<EOT
1431
Page generated in $time seconds - $query_count queries in $total_query_time seconds - Album set : $ALBUM_SET
1432
EOT;
1433
        echo "</textarea>";
1434
        echo "</td>";
1435
        echo "</tr>";
1436
        if (GALLERY_ADMIN_MODE){
1437
          echo "<tr><td class=\"tableb\" colspan=\"2\">";
1438
          echo "<a href=\"phpinfo.php\">".$lang_cpg_debug_output['phpinfo']."</a>";
1439
          error_reporting  (E_ERROR | E_WARNING | E_PARSE);
1440
          echo "</td></tr>";
1441
        }
1442
        endtable();
1443
        echo "</form>";
1444
}
1445
 
1446
//phpinfo-related functions:
1447
function cpg_phpinfo_mod($search)
1448
{
1449
    // this could be done much better with regexpr - anyone who wants to change it: go ahead
1450
    ob_start();
1451
    phpinfo(INFO_MODULES);
1452
    $string = ob_get_contents();
1453
    $module = $string;
1454
    $delimiter = '#cpgdelimiter#';
1455
    ob_end_clean();
1456
    // find out the first occurence of "<h2" and throw the superfluos stuff away
1457
    $string = strstr($string, 'module_' . $search);
1458
    $string = eregi_replace('</table>(.*)', '', $string);
1459
    $string = strstr($string, '<tr>');
1460
    $string = str_replace('</td>', '|', $string);
1461
    $string = str_replace('</tr>', $delimiter, $string);
1462
    $string = chop(strip_tags($string));
1463
    $pieces = explode($delimiter, $string);
1464
    foreach($pieces as $key => $val) {
1465
        $bits[$key] = explode("|", $val);
1466
    }
1467
    return $bits;
1468
}
1469
 
1470
function cpg_phpinfo_mod_output($search,$output_type)
1471
{
1472
// first parameter is the module name, second parameter is the way you want your output to look like: table or text
1473
    $pieces = cpg_phpinfo_mod($search);
1474
    $summ = '';
1475
    $return = '';
1476
    $debug_underline = '&#0010;------------------&#0010;';
1477
    $debug_separate = '&#0010;==========================&#0010;';
1478
 
1479
    if ($output_type == 'table')
1480
    {
1481
    ob_start();
1482
    starttable('100%', 'Module: '.$search, 2);
1483
    $return.= ob_get_contents();
1484
    ob_end_clean();
1485
    }
1486
    else
1487
    {
1488
    $return.= 'Module: '.$search.$debug_underline;
1489
    }
1490
    foreach($pieces as $val) {
1491
        if ($output_type == 'table') {$return.= '<tr><td>';}
1492
        $return.= $val[0];
1493
        if ($output_type == 'table') {$return.= '</td><td>';}
1494
        $return.= $val[1];
1495
        if ($output_type == 'table') {$return.= '</td></tr>';}
1496
        $summ .= $val[0];
1497
    }
1498
    if (!$summ) {
1499
        if ($output_type == 'table') {$return.= '<tr><td colspan="2">';}
1500
        $return.= 'module doesn\'t exist';
1501
        if ($output_type == 'table') {$return.= '</td></tr>';}
1502
    }
1503
    if ($output_type == 'table')
1504
    {
1505
    ob_start();
1506
    endtable();
1507
    $return.= ob_get_contents();
1508
    ob_end_clean();
1509
    }
1510
    else
1511
    {
1512
    $return.= $debug_separate;
1513
    }
1514
    return $return;
1515
}
1516
 
1517
function cpg_phpinfo_mysql_version()
1518
{
1519
    $result = db_query("SELECT VERSION() as version");
1520
    $row = mysql_fetch_row($result);
1521
    return $row[0];
1522
}
1523
 
1524
function cpg_phpinfo_conf($search)
1525
{
1526
    // this could be done much better with regexpr - anyone who wants to change it: go ahead
1527
    $string ='';
1528
    $pieces = '';
1529
    $delimiter = '#cpgdelimiter#';
1530
    $bits = '';
1531
 
1532
    ob_start();
1533
    phpinfo(INFO_CONFIGURATION);
1534
    $string = ob_get_contents();
1535
    ob_end_clean();
1536
    // find out the first occurence of "</tr" and throw the superfluos stuff in front of it away
1537
    $string = strchr($string, '</tr>');
1538
    $string = str_replace('</td>', '|', $string);
1539
    $string = str_replace('</tr>', $delimiter, $string);
1540
    $string = chop(strip_tags($string));
1541
    $pieces = explode($delimiter, $string);
1542
    foreach($pieces as $val) {
1543
        $bits = explode("|", $val);
1544
        if (strchr($bits[0], $search)) {
1545
            return $bits;
1546
        }
1547
    }
1548
}
1549
 
1550
function cpg_phpinfo_conf_output($search)
1551
{
1552
$pieces = cpg_phpinfo_conf($search);
1553
        $return= $pieces[0] . ' | ' . $pieces[1] . ' | ' . $pieces[2];
1554
        return $return;
1555
}
1556
 
1557
// theme and language selection
1558
function languageSelect($parameter)
1559
{
1560
global $CONFIG,$lang_language_selection;
1561
$return= '';
1562
$lineBreak = "\n";
1563
 
1564
//check if language display is enabled
1565
if ($CONFIG['language_list'] == 0 && $parameter == 'list'){
1566
    return;
1567
}
1568
if ($CONFIG['language_flags'] == 0 && $parameter == 'flags'){
1569
    return;
1570
}
1571
 
1572
 
1573
 
1574
 
1575
// get the current language
1576
 //use the default language of the gallery
1577
 $cpgCurrentLanguage = $CONFIG['lang'];
1578
 
1579
 // is a user logged in?
1580
 //has the user already chosen another language for himself?
1581
 //if($USER['lang']!=""){
1582
 //   $cpgCurrentLanguage = $USER['lang'];
1583
 //   }
1584
 //has the language been set to something else on the previous page?
1585
 if (isset($_GET['lang'])){
1586
    $cpgCurrentLanguage = $_GET['lang'];
1587
    }
1588
 //get the url and all vars except $lang
1589
 $cpgChangeUrl = $_SERVER["SCRIPT_NAME"]."?";
1590
 foreach ($_GET as $key => $value) {
1591
    if ($key!="lang"){$cpgChangeUrl.= $key . "=" . $value . "&";}
1592
 }
1593
 $cpgChangeUrl.= 'lang=';
1594
 
1595
 
1596
// get an array of english and native language names and flags
1597
// for now, use a static array definition here - this could later be made into a true database query
1598
$lang_language_data['arabic'] = array('Arabic','&#1575;&#1604;&#1593;&#1585;&#1576;&#1610;&#1577;','sa');
1599
$lang_language_data['basque'] = array('Basque','Euskera','baq');
1600
$lang_language_data['bosnian'] = array('Bosnian','Bosanski','ba');
1601
$lang_language_data['brazilian_portuguese'] = array('Portuguese [Brazilian]','Portugu&ecirc;s Brasileiro','br');
1602
$lang_language_data['bulgarian'] = array('Bulgarian','&#1041;&#1098;&#1083;&#1075;&#1072;&#1088;&#1089;&#1082;&#1080;','bg');
1603
$lang_language_data['catalan'] = array('Catalan','Catal&agrave;','ct');
1604
$lang_language_data['chinese_big5'] = array('Chinese-Big5','&#21488;&#28771;','tw');
1605
$lang_language_data['chinese_gb'] = array('Chinese-GB2312','&#20013;&#22269;','cn');
1606
$lang_language_data['croatian'] = array('Croatian','Hrvatski','hr');
1607
$lang_language_data['czech'] = array('Czech','&#x010C;esky','cz');
1608
$lang_language_data['danish'] = array('Danish','Dansk','dk');
1609
$lang_language_data['dutch'] = array('Dutch','Nederlands','nl');
1610
$lang_language_data['english'] = array('English','English','gb');
1611
$lang_language_data['estonian'] = array('Estonian','Eesti','ee');
1612
$lang_language_data['finnish'] = array('Finnish','Suomea','fi');
1613
$lang_language_data['french'] = array('French','Fran&ccedil;ais','fr');
1614
$lang_language_data['german'] = array('German','Deutsch','de');
1615
$lang_language_data['greek'] = array('Greek','&#917;&#955;&#955;&#951;&#957;&#953;&#954;&#940;','gr');
1616
$lang_language_data['hebrew'] = array('Hebrew','&#1506;&#1489;&#1512;&#1497;&#1514;','il');
1617
$lang_language_data['hungarian'] = array('Hungarian','Magyarul','hu');
1618
$lang_language_data['indonesian'] = array('Indonesian','Bahasa Indonesia','id');
1619
$lang_language_data['italian'] = array('Italian','Italiano','it');
1620
$lang_language_data['japanese'] = array('Japanese','&#26085;&#26412;&#35486;','jp');
1621
$lang_language_data['korean'] = array('Korean','&#54620;&#44397;&#50612;','kr');
1622
$lang_language_data['kurdish'] = array('Kurdish','&#1603;&#1608;&#1585;&#1583;&#1740;','ku');
1623
$lang_language_data['latvian'] = array('Latvian','Latvian','lv');
1624
$lang_language_data['malay'] = array('Malay','Bahasa Melayu','my');
1625
$lang_language_data['norwegian'] = array('Norwegian','Norsk','no');
1626
$lang_language_data['polish'] = array('Polish','Polski','pl');
1627
$lang_language_data['portuguese'] = array('Portuguese [Portugal]','Portugu&ecirc;s','pt');
1628
$lang_language_data['romanian'] = array('Romanian','Rom&acirc;n&atilde;','ro');
1629
$lang_language_data['russian'] = array('Russian','&#1056;&#1091;&#1089;&#1089;&#1082;&#1080;&#1081;','ru');
1630
$lang_language_data['slovak'] = array('Slovak','Slovensky','sl');
1631
$lang_language_data['slovenian'] = array('Slovenian','Slovensko','si');
1632
$lang_language_data['spanish'] = array('Spanish','Espa&ntilde;ol','es');
1633
$lang_language_data['swedish'] = array('Swedish','Svenska','se');
1634
$lang_language_data['thai'] = array('Thai','&#3652;&#3607;&#3618;','th');
1635
$lang_language_data['turkish'] = array('Turkish','T&uuml;rk&ccedil;e','tr');
1636
$lang_language_data['uighur'] = array('Uighur','Uighur','cn-xj');
1637
$lang_language_data['vietnamese'] = array('Vietnamese','Tieng Viet','vn');
1638
$lang_language_data['welsh'] = array('Welsh','Cymraeg','gb-cm');
1639
 
1640
// get list of available languages
1641
  $value = strtolower($CONFIG['lang']);
1642
  // is utf-8 selected?
1643
 if ($CONFIG['charset'] == 'utf-8') {
1644
     $cpg_charset = 'utf-8';
1645
 } else {
1646
     $cpg_charset = '';
1647
 }
1648
  $lang_dir = 'lang/';
1649
  $dir = opendir($lang_dir);
1650
  while ($file = readdir($dir)) {
1651
      if (is_file($lang_dir . $file) && strtolower(substr($file, -4)) == '.php') {
1652
          if (($cpg_charset != 'utf-8' && strstr($file,'utf-8') == false) || ($cpg_charset == 'utf-8' && strstr($file,'utf-8') == true)) {
1653
              $lang_array[] = strtolower(substr($file, 0 , -4));
1654
          }
1655
      }
1656
  }
1657
  closedir($dir);
1658
  natcasesort($lang_array);
1659
 
1660
//start the output
1661
switch ($parameter) {
1662
   case 'flags':
1663
       if ($CONFIG['language_flags'] == 2){
1664
           $return.= $lang_language_selection['choose_language'].': ';
1665
       }
1666
       foreach ($lang_array as $language) {
1667
       $cpg_language_name = str_replace('-utf-8','', $language);
1668
              if (array_key_exists($cpg_language_name, $lang_language_data)){
1669
              $return.= $lineBreak .  '<a href="' .$cpgChangeUrl. $language . '"><img src="images/flags/' . $lang_language_data[$cpg_language_name][2] . '.gif" border="0" width="16" height="10" alt="" title="';
1670
              $return.= $lang_language_data[$language][0];
1671
              if ($lang_language_data[$language][1] != $lang_language_data[$language][0]){
1672
                  $return.= ' (' . $lang_language_data[$language][1] . ')';
1673
                  }
1674
              $return.= '" /></a>&nbsp;' . $lineBreak;
1675
              }
1676
              }
1677
          if ($CONFIG['language_reset'] == 1){
1678
              $return.=  '<a href="' .$cpgChangeUrl. 'xxx"><img src="images/flags/reset.gif" border="0" width="16" height="11" alt="" title="';
1679
              $return.=  $lang_language_selection['reset_language'] . '" /></a>' . $lineBreak;
1680
          }
1681
       break;
1682
   case 'table':
1683
       $return = 'not yet implemented';
1684
       break;
1685
   default:
1686
       $return.= $lineBreak . '<form name="cpgChooseLanguage" action="' . $cpgChangeUrl . '" method="get" style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;display:inline">' . $lineBreak;
1687
       $return.= '<select name="cpgLanguageSelect" class="listbox_lang" onchange="if (this.options[this.selectedIndex].value) window.location.href=\'' . $cpgChangeUrl . '\' + this.options[this.selectedIndex].value;">' . $lineBreak;
1688
       $return.='<option selected="selected">' . $lang_language_selection['choose_language'] . '</option>' . $lineBreak;
1689
       foreach ($lang_array as $language) {
1690
          $return.=  '<option value="' . $language  . '" >';
1691
              if (array_key_exists($language, $lang_language_data)){
1692
              $return.= $lang_language_data[$language][0];
1693
              if ($lang_language_data[$language][1] != $lang_language_data[$language][0]){
1694
                  $return.= ' (' . $lang_language_data[$language][1] . ')';
1695
                  }
1696
              }
1697
              else{
1698
                  $return.= ucfirst($language);
1699
                  }
1700
              $return.= ($value == $language ? '*' : '');
1701
              $return.= '</option>' . $lineBreak;
1702
              }
1703
          if ($CONFIG['language_reset'] == 1){
1704
              $return.=  '<option value="xxx">' . $lang_language_selection['reset_language'] . '</option>' . $lineBreak;
1705
          }
1706
          $return.=  '</select>' . $lineBreak;
1707
          $return.=  '</form>' . $lineBreak;
1708
   }
1709
 
1710
return $return;
1711
}
1712
 
1713
function themeSelect($parameter)
1714
{
1715
global $CONFIG,$lang_theme_selection;
1716
$return= '';
1717
$lineBreak = "\n";
1718
 
1719
if ($CONFIG['theme_list'] == 0){
1720
    return;
1721
}
1722
 
1723
// get the current theme
1724
//get the url and all vars except $theme
1725
$cpgCurrentTheme = $_SERVER["SCRIPT_NAME"]."?";
1726
foreach ($_GET as $key => $value) {
1727
    if ($key!="theme"){$cpgCurrentTheme.= $key . "=" . $value . "&";}
1728
}
1729
$cpgCurrentTheme.="theme=";
1730
 
1731
// get list of available languages
1732
    $value = $CONFIG['theme'];
1733
    $theme_dir = 'themes/';
1734
 
1735
    $dir = opendir($theme_dir);
1736
    while ($file = readdir($dir)) {
1737
        if (is_dir($theme_dir . $file) && $file != "." && $file != "..") {
1738
            $theme_array[] = $file;
1739
        }
1740
    }
1741
    closedir($dir);
1742
 
1743
    natcasesort($theme_array);
1744
 
1745
//start the output
1746
switch ($parameter) {
1747
   case 'table':
1748
       $return = 'not yet implemented';
1749
       break;
1750
   default:
1751
       $return.= $lineBreak . '<form name="cpgChooseTheme" action="' . $cpgCurrentTheme . '" method="get" style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;display:inline">' . $lineBreak;
1752
       $return.= '<select name="cpgThemeSelect" class="listbox_lang" onchange="if (this.options[this.selectedIndex].value) window.location.href=\'' . $cpgCurrentTheme . '\' + this.options[this.selectedIndex].value;">' . $lineBreak;
1753
       $return.='<option selected="selected">' . $lang_theme_selection['choose_theme'] . '</option>';
1754
       foreach ($theme_array as $theme) {
1755
           $return.= '<option value="' . $theme . '">' . strtr(ucfirst($theme), '_', ' ') . ($value == $theme ? '*' : ''). '</option>' . $lineBreak;
1756
       }
1757
          if ($CONFIG['theme_reset'] == 1){
1758
              $return.=  '<option value="xxx">' . $lang_theme_selection['reset_theme'] . '</option>' . $lineBreak;
1759
          }
1760
          $return.=  '</select>' . $lineBreak;
1761
          $return.=  '</form>' . $lineBreak;
1762
   }
1763
 
1764
return $return;
1765
}
1766
 
1767
 
1768
 
1769
 
1770
 
1771
?>