Dragonfly CMS logo Server sponsored and hosted by
DedicatedNOW
CVS logo  
.:: Home :: Dev. Resources :: Forums ::.
Dragonfly CMS CVS Repository
 Location: / cvs / html / includes / coppermine / functions.inc
This is a web interface to the Dragonfly CMS CVS tree. You can browse the file hierarchy by picking directories. If you pick a file, you will see the revision history for that file.
Selecting a revision number will show that revision of the file. There are links at each revision to display diffs, annotate and download.
Note: Info about CVS and our commits can be found at our CVS Info Forum
File name: html/includes/coppermine/functions.inc
Revision : 10.1 (3 years 5 months 1 weeks 3 days 22 hours 57 minutes 38 seconds ago) by djmaze
Changed : +88 -92 lines
Comment: cleanup using improved list_columns()


# Author Rev Line
1 djmaze 10.1 <?php
2 djmaze 10.1 /***************************************************************************
3 djmaze 1.1 Coppermine 1.3.1 for CPG-Dragonfly™
4 djmaze 1.1 **************************************************************************
5 djmaze 1.1 Port Copyright (c) 2004-2005 CPG Dev Team
6 djmaze 9.36 http://dragonflycms.org/
7 djmaze 1.1 **************************************************************************
8 djmaze 1.1 v1.1 (c) by Grégory Demar http://coppermine.sf.net/
9 djmaze 10.1 This program is free software; you can redistribute it and/or modify
10 djmaze 10.1 it under the terms of the GNU General Public License as published by
11 djmaze 10.1 the Free Software Foundation; either version 2 of the License, or
12 djmaze 10.1 (at your option) any later version.
13 djmaze 10.1 **************************************************************************
14 djmaze 1.1 Last modification notes:
15 djmaze 9.0 $Source: /cvs/html/includes/coppermine/functions.inc,v $
16 djmaze 10.1 $Revision: 10.0 $
17 djmaze 10.1 $Author: djmaze $
18 djmaze 10.1 $Date: 2010/11/05 01:03:18 $
19 djmaze 1.1 ****************************************************************************/
20 djmaze 1.1 global $THEME_DIR, $template, $block_name, $template_cpg_die, $template_msg_box;
21 djmaze 1.1  
22 nanocaio 9.43 function coppermine_block() {
23 nanocaio 9.43 global $module_name, $cpg_dir;
24 nanocaio 9.43 if ($module_name != $cpg_dir) return;
25 djmaze 9.6 global $db, $CONFIG;
26 djmaze 9.8 $cat = intval(isset($_GET['cat']) ? $_GET['cat'] : (isset($_POST['cat']) ? $_POST['cat'] : '0'));
27 nanocaio 9.43 $content = '<!-- coppermine user block -->';
28 nanocaio 9.43 $dot = '<b>&#8226;&nbsp;</b>';
29 djmaze 9.6 if (USER_CAN_CREATE_ALBUMS){
30 nanocaio 9.47 $content .= $dot.'<a href="'.URL::index('&amp;file=albmgr&amp;cat='.USER_GAL_CAT).'">' . ALBMGR_LNK . '</a><br />';
31 nanocaio 9.47 $content .= $dot.'<a href="'.URL::index('&amp;file=modifyalb').'">' . MODIFYALB_LNK . '</a><br />';
32 djmaze 9.6 }
33 nanocaio 9.47 $content .= $dot.'<a href="'.URL::index('&amp;file=profile').'">' . MY_PROF_LNK . '</a><br />';
34 djmaze 9.6 if (USER_CAN_CREATE_ALBUMS){
35 nanocaio 9.47 $content .= $dot.'<a href="'.URL::index("&amp;cat=".(FIRST_USER_CAT + USER_ID)).'" title="'.MY_GAL_TITLE.'">'.MY_GAL_LNK.'</a><br />';
36 djmaze 9.6 }
37 djmaze 9.6 if (USER_CAN_UPLOAD_PICTURES) {
38 nanocaio 9.47 $content .= $dot.'<a href="'.URL::index("&amp;file=upload").'" title="'.UPLOAD_PIC_TITLE.'">'.UPLOAD_PIC_LNK.'</a>';
39 djmaze 9.6 }
40 djmaze 9.6 if (GALLERY_ADMIN_MODE) {
41 djmaze 9.6 $content .= '<hr />';
42 djmaze 9.22 $num = $db->sql_count($CONFIG['TABLE_PICTURES'], "approved=0");
43 nanocaio 9.47 $content .= $dot.'<a href="'.URL::index('&amp;file=editpics&amp;mode=upload_approval').'">' . UPL_APP_LNK . '</a>: ' . $num[0] . '<br />' .
44 nanocaio 9.47 $dot.'<a href="'.URL::index('&amp;file=searchnew').'">' . SEARCHNEW_LNK . '</a><br />' .
45 nanocaio 9.47 $dot.'<a href="'.URL::index('&amp;file=reviewcom').'">' . COMMENTS_LNK . '</a><br />' .
46 nanocaio 9.47 $dot.'<a href="'.URL::index('&amp;file=groupmgr').'">' . GROUPS_LNK . '</a><br />' .
47 nanocaio 9.47 $dot.'<a href="'.URL::index('&amp;file=usermgr').'">' . USERS_LNK . '</a><br />' .
48 nanocaio 9.47 $dot.'<a href="'.URL::index('&amp;file=albmgr&amp;cat='.$cat).'">' . ALBUMS_LNK . '</a><br />' .
49 nanocaio 9.47 $dot.'<a href="'.URL::index('&amp;file=catmgr').'">' . CATEGORIES_LNK . '</a><br />';
50 djmaze 9.6 if (isset($_GET['album'])) {
51 nanocaio 9.47 $content .= $dot.'<a href="'.URL::index('&amp;file=editpics&amp;album='.$_GET['album']).'">' . EDIT_PICS . '</a><br />';
52 djmaze 9.6 }
53 djmaze 9.6 if (is_admin()) {
54 nanocaio 9.48 $content .= "$dot<a href=\"".URL::admin().'">' . CONFIG_LNK . "</a><br />";
55 djmaze 10.1 }
56 djmaze 9.6 }
57 nanocaio 9.43 return $content;
58 djmaze 1.1 }
59 djmaze 1.1  
60 djmaze 1.1 // Decode the user profile contained in a cookie
61 djmaze 1.1 function user_get_profile()
62 djmaze 1.1 {
63 djmaze 9.6 global $CONFIG, $USER, $SESS;
64 nanocaio 9.30 $chars = array(4=>'0-9a-f',5=>'0-9a-v',6=>'0-9a-zA-Z\-,');
65 nanocaio 9.30 $bits = (ini_get('session.hash_function')=='1')?160:128;
66 nanocaio 9.30 $size = $bits / 4;
67 nanocaio 9.30 $minsize = (int)ini_get('session.hash_bits_per_character');
68 nanocaio 9.30 if ($minsize < 4) $minsize = 4;
69 nanocaio 9.30 if ($minsize != 4) $size = ceil($bits/$minsize).",$size";
70 nanocaio 9.30 $chars = $chars[$minsize];
71 nanocaio 9.30  
72 djmaze 9.6 if (isset($_COOKIE[$CONFIG['cookie_name'] . '_data'])) {
73 djmaze 9.6 $USER = unserialize(base64_decode($_COOKIE[$CONFIG['cookie_name'] . '_data']));
74 djmaze 10.1 }
75 nanocaio 9.31 if (!isset($USER) || !is_array($USER)) { $USER = array(); }
76 nanocaio 9.30 if (!isset($USER['ID']) || preg_match("#^[$chars]{{$size}}$#", $USER['ID'])) {
77 djmaze 9.6 $USER['ID'] = $SESS->sess_id;
78 djmaze 9.6 }
79 djmaze 1.1 }
80 djmaze 1.1  
81 djmaze 1.1 // check if user is member of group
82 djmaze 1.1 function user_ingroup($group_id, &$usergroups) {
83 djmaze 9.6 if (!is_array($usergroups)) $usergroups = split(',', $usergroups);
84 djmaze 9.6 foreach($usergroups as $group) {
85 djmaze 9.6 if ($group == $group_id) return true;
86 djmaze 9.6 }
87 djmaze 9.6 return false;
88 djmaze 1.1 }
89 djmaze 1.1  
90 djmaze 1.1 /**
91 djmaze 1.1 * Database functions
92 djmaze 1.1 */
93 djmaze 1.1 // get a table count
94 djmaze 1.1 // cpg_tablecount("cpg_pictures", "count(*)")
95 djmaze 1.1 // cpg_tablecount("cpg_pictures", "sum(hits)")
96 djmaze 1.1 function cpg_tablecount($table, $type, $file='', $line='') {
97 djmaze 9.6 global $db;
98 djmaze 9.6 list($count) = $db->sql_ufetchrow("SELECT $type FROM $table",SQL_NUM,$file,$line);
99 djmaze 10.1 return $count;
100 djmaze 1.1 }
101 djmaze 1.1 /**
102 djmaze 1.1 * Utilities functions
103 djmaze 1.1 */
104 djmaze 1.1  
105 djmaze 1.1 // Replacement for the die function
106 djmaze 1.1 function cpg_die($msg_code, $msg_text, $error_file, $error_line, $output_buffer = false, $header=false)
107 djmaze 1.1 {
108 djmaze 9.6 global $CONFIG, $lang_cpg_die, $template_cpg_die,$CLASS;
109 djmaze 10.1 global $template;
110 djmaze 9.6 // Simple output if theme file is not loaded
111 djmaze 9.6 if (!function_exists('starttable')) {
112 djmaze 9.6 trigger_error('Fatal error :<br />' . $msg_text,E_USER_ERROR);
113 djmaze 9.6 exit;
114 djmaze 10.1 }
115 djmaze 9.6 $template_cpg_die = eval_tmplfile($template_cpg_die);
116 djmaze 9.6 //this shows error line numbers only to admin
117 djmaze 9.6 if (!USER_IS_ADMIN ||($CLASS['member']->demo)) template_extract_block($template_cpg_die, 'file_line');
118 djmaze 9.6 if (!$output_buffer && !$CONFIG['debug_mode']) template_extract_block($template_cpg_die, 'output_buffer');
119 djmaze 9.6  
120 djmaze 9.6 $params = array('{MESSAGE}' => $msg_text,
121 djmaze 9.6 '{FILE_TXT}' => FILE,
122 djmaze 9.6 '{FILE}' => $error_file,
123 djmaze 9.6 '{LINE_TXT}' => LINE,
124 djmaze 9.6 '{LINE}' => $error_line,
125 djmaze 9.6 '{OUTPUT_BUFFER}' => "",
126 djmaze 9.6 );
127 djmaze 9.6 if ($header) {
128 djmaze 9.6 pageheader($lang_cpg_die[$msg_code]);
129 djmaze 9.6 }
130 djmaze 9.6 global $CONFIG;
131 djmaze 9.6 global $template_header;
132 djmaze 9.6 require_once("header.php");
133 djmaze 9.6 // OpenTable();
134 djmaze 9.6 starttable(-1, $lang_cpg_die[$msg_code]);
135 djmaze 9.6 echo template_eval($template_cpg_die, $params);
136 djmaze 9.6 endtable();
137 djmaze 9.6 pagefooter();
138 djmaze 1.1 }
139 djmaze 1.1 // Function for writing a pageheader
140 djmaze 1.1 function pageheader($section, $meta='',$time=5)
141 djmaze 1.1 {
142 djmaze 9.6 global $CONFIG, $CPG_VERSION, $CPG_M_DIR, $template_header,$modheader;
143 djmaze 1.1  
144 djmaze 9.6 // header('P3P: CP="CAO DSP COR CURa ADMa DEVa OUR IND PHY ONL UNI COM NAV INT DEM PRE"');
145 djmaze 9.17 global $USER, $MAIN_CFG;
146 djmaze 9.6 $data = base64_encode(serialize($USER));
147 djmaze 9.17 setcookie($CONFIG['cookie_name'] . '_data', $data, time() + 86400 * 30, $MAIN_CFG['cookie']['path'], $MAIN_CFG['cookie']['domain']);
148 djmaze 10.1 $TMPCONFIG = $CONFIG;
149 djmaze 9.6 if ($meta != '') {
150 nanocaio 9.49 $modheader .= URL::refresh($meta,$time);
151 djmaze 9.6 }
152 djmaze 9.6 require_once("header.php");
153 djmaze 9.6 $CONFIG = $TMPCONFIG;
154 djmaze 9.6  
155 djmaze 9.6 OpenTable();
156 djmaze 9.6  
157 djmaze 9.6 $template_vars = array(
158 djmaze 9.6 '{LANG_DIR}' => _TEXT_DIR,
159 djmaze 9.6 '{TITLE}' => $CONFIG['gallery_name'].' - '.$section,
160 djmaze 9.6 '{CHARSET}' => $CONFIG['charset'] == 'language file' ? _CHARSET : $CONFIG['charset'],
161 djmaze 9.6 //'{META}' => $meta,
162 djmaze 9.6 '{GAL_NAME}' => $CONFIG['gallery_name'],
163 djmaze 9.6 '{GAL_DESCRIPTION}' => $CONFIG['gallery_description'],
164 djmaze 9.6 '{MAIN_MENU}' => ($meta == '' ? theme_main_menu():''),
165 djmaze 9.6 '{ADMIN_MENU}' => ''
166 djmaze 9.6 );
167 djmaze 9.6 //theme_admin_mode_menu()
168 djmaze 9.6 // coppercop added config var...
169 djmaze 9.6 //disabled temp
170 djmaze 9.6 echo template_eval($template_header, $template_vars);
171 djmaze 1.1 }
172 djmaze 1.1 // Function for writing a pagefooter
173 djmaze 1.1 function pagefooter()
174 djmaze 1.1 {
175 djmaze 9.6 global $template_footer,$CLASS;
176 djmaze 9.6 echo $template_footer;
177 djmaze 9.6 CloseTable();
178 djmaze 9.12 if (!$CLASS['member']->demo) { print_debug(); }
179 djmaze 9.6 require("footer.php");
180 djmaze 1.1 }
181 djmaze 1.1 // Display a localised date
182 djmaze 1.1 function localised_date($timestamp = -1, $datefmt)
183 djmaze 1.1 {
184 djmaze 9.6 return formatDateTime($timestamp, $datefmt);
185 djmaze 9.6 }
186 djmaze 1.1 // Function to create correct URLs for image name with space or exotic characters
187 djmaze 1.1 function path2url($path)
188 djmaze 1.1 {
189 djmaze 9.6 return str_replace("%2F", "/", rawurlencode($path));
190 djmaze 10.1 }
191 djmaze 1.1 // Display a 'message box like' table
192 djmaze 1.1 function msg_box($title, $msg_text, $button_text = "", $button_link = "", $width = "-1")
193 djmaze 1.1 {
194 djmaze 9.6 global $template_msg_box;
195 djmaze 1.1  
196 djmaze 9.6 if (!$button_text) {
197 djmaze 9.6 template_extract_block($template_msg_box, 'button');
198 djmaze 10.1 }
199 djmaze 9.6 $params = array('{MESSAGE}' => $msg_text,
200 djmaze 9.6 '{LINK}' => $button_link,
201 djmaze 9.6 '{TEXT}' => $button_text
202 djmaze 9.6 );
203 djmaze 9.6  
204 djmaze 9.6 starttable($width, $title);
205 djmaze 9.6 echo template_eval($template_msg_box, $params);
206 djmaze 9.6 endtable();
207 djmaze 10.1 }
208 djmaze 1.1 function create_tabs($items, $curr_page, $total_pages, $template)
209 djmaze 1.1 {
210 djmaze 9.6 global $CONFIG;
211 djmaze 1.1  
212 djmaze 9.6 if (function_exists('theme_create_tabs')) {
213 djmaze 9.6 theme_create_tabs($items, $curr_page, $total_pages, $template);
214 djmaze 9.6 return;
215 djmaze 10.1 }
216 djmaze 9.6 $maxTab = $CONFIG['max_tabs'];
217 djmaze 9.6 $tabs = sprintf($template['left_text'], $items, $total_pages);
218 djmaze 9.6 if (($total_pages == 1)) return $tabs;
219 djmaze 9.6 $tabs .= $template['tab_header'];
220 djmaze 9.6 if ($curr_page == 1) {
221 djmaze 9.6 $tabs .= sprintf($template['active_tab'], 1);
222 djmaze 9.6 } else {
223 djmaze 9.6 $tabs .= sprintf($template['inactive_tab'], 1, 1);
224 djmaze 10.1 }
225 djmaze 9.6 if ($total_pages > $maxTab) {
226 djmaze 9.6 $start = max(2, $curr_page - floor(($maxTab -2) / 2));
227 djmaze 9.6 $start = min($start, $total_pages - $maxTab + 2);
228 djmaze 9.6 $end = $start + $maxTab -3;
229 djmaze 9.6 } else {
230 djmaze 9.6 $start = 2;
231 djmaze 9.6 $end = $total_pages-1;
232 djmaze 10.1 }
233 djmaze 9.6 for ($page = $start ; $page <= $end; $page++) {
234 djmaze 9.6 if ($page == $curr_page) {
235 djmaze 9.6 $tabs .= sprintf($template['active_tab'], $page);
236 djmaze 9.6 } else {
237 djmaze 9.6 $tabs .= sprintf($template['inactive_tab'], $page, $page);
238 djmaze 10.1 }
239 djmaze 10.1 }
240 djmaze 9.6 if ($total_pages > 1) {
241 djmaze 9.6 if ($curr_page == $total_pages) {
242 djmaze 9.6 $tabs .= sprintf($template['active_tab'], $total_pages);
243 djmaze 9.6 } else {
244 djmaze 9.6 $tabs .= sprintf($template['inactive_tab'], $total_pages, $total_pages);
245 djmaze 10.1 }
246 djmaze 10.1 }
247 djmaze 9.6 return $tabs . $template['tab_trailer'];
248 djmaze 10.1 }
249 djmaze 1.1  
250 djmaze 1.1 // Allow the use of a limited set of phpBB bb codes in albums and image descriptions
251 djmaze 1.1 // Taken from phpBB code
252 djmaze 1.1 define ('LOC', 'YToyOntzOjE6ImwiO3M6OToie0dBTExFUll9IjtzOjE6InMiO3M6Mjk1OiI8ZGl2IGNsYXNzPSJmb290ZXIiIGFsaWduPSJjZW50ZXIiIHN0eWxlPSJwYWRkaW5nLXRvcDogMTBweDsiPlBvd2VyZWQgYnkgPGEgaHJlZj0iaHR0cDovL2NvcHBlcm1pbmUuc2YubmV0LyIgdGFyZ2V0PSJfYmxhbmsiPkNvcHBlcm1pbmUgUGhvdG8gR2FsbGVyeTwvYT4gdkNQR19WRVJTSU9OLU51a2U8YnI+Zm9yIHBocE51a2UgYW5kIHBvc3ROdWtlIGJ5IDxhIGhyZWY9Imh0dHA6Ly9jb3BwZXJtaW5lLmZpbmRoZXJlLm9yZy8iIHRhcmdldD0iX2JsYW5rIj5Db3BwZXJtaW5lIE51a2UgRGV2IFRlYW08L2E+PC9kaXY+Ijt9');
253 djmaze 1.1  
254 djmaze 1.1 // function added for blocks takes a string and shortens it for display
255 djmaze 1.1 // use: truncate_stringblocks($var,int)
256 djmaze 1.1 function truncate_stringblocks($str, $maxlength = 20)
257 djmaze 1.1 {
258 djmaze 9.6 if (strlen($str) > $maxlength) {
259 djmaze 9.6 return substr($str, 0, $maxlength) . " ...";
260 djmaze 9.6 } else {
261 djmaze 9.6 return $str;
262 djmaze 10.1 }
263 djmaze 10.1 }
264 djmaze 1.1 /**
265 djmaze 1.1 * Template functions
266 djmaze 1.1 */
267 djmaze 1.1 function eval_tmplfile($file, $load = true)
268 djmaze 1.1 {
269 djmaze 9.6 global $THEME_DIR, $CPG_M_DIR, $CPG_URL;
270 djmaze 9.6 if ($load)
271 djmaze 9.6 $thefile = implode("", file($THEME_DIR . '/' . $file));
272 djmaze 9.6 else
273 djmaze 9.6 $thefile = $file;
274 djmaze 9.6 $var = eval("return '" . preg_replace("/'/", "\'", $thefile) . "';");
275 djmaze 9.6 if (!$var) {
276 djmaze 9.6 cpg_error("There occured an error while processing $THEME_DIR/$file");
277 djmaze 9.6 }
278 djmaze 9.6 return $var;
279 djmaze 10.1 }
280 djmaze 1.1 // Load and parse the template.html file
281 djmaze 1.1 function load_template()
282 djmaze 1.1 {
283 djmaze 9.6 global $THEME_DIR, $CONFIG, $template_header, $template_footer, $CPG_VERSION;
284 djmaze 9.6 if (file_exists('template.html')) {
285 djmaze 9.6 $template_file = 'template.html';
286 djmaze 9.6 } elseif (file_exists($THEME_DIR . '/template.html')) {
287 djmaze 9.6 $template_file = $THEME_DIR . '/template.html';
288 djmaze 9.6 } if (!isset($template_file)) {
289 djmaze 9.6 trigger_error("<b>Coppermine critical error</b>:<br />Unable to load template file $THEME_DIR/template.html!</b>", E_USER_ERROR);
290 djmaze 9.6 }
291 djmaze 9.6 $template = eval_tmplfile('template.html');
292 djmaze 9.6 $pos = strpos($template, '{GALLERY}');
293 djmaze 9.6 $template_header = substr($template, 0, $pos);
294 djmaze 9.6 $template_footer = substr($template, $pos);
295 djmaze 9.6 $template_footer = str_replace('{GALLERY}', '', $template_footer);
296 djmaze 1.1 }
297 djmaze 1.1 // Eval a template (substitute vars with values)
298 djmaze 1.1 function template_eval(&$template, &$vars)
299 djmaze 1.1 {
300 djmaze 9.6 return strtr($template, $vars);
301 djmaze 10.1 }
302 djmaze 1.1 // Extract and return block '$block_name' from the template, the block is replaced by $subst
303 djmaze 1.1 function template_extract_block(&$template, $block_name, $subst = '')
304 djmaze 1.1 {
305 djmaze 9.6 global $THEME_DIR;
306 djmaze 9.6 $pattern = "#(<!-- BEGIN $block_name -->)(.*?)(<!-- END $block_name -->)#s";
307 djmaze 9.6 if (!preg_match($pattern, $template, $matches)) {
308 djmaze 9.6 die('<b>Theme:'.$THEME_DIR.' Template error<b><br />Failed to find block \'' . $block_name . '\'(' . htmlprepare($pattern) . ') in :<br /><pre>' . htmlprepare($template) . '</pre>');
309 djmaze 10.1 }
310 djmaze 9.6 $template = str_replace($matches[1] . $matches[2] . $matches[3], $subst, $template);
311 djmaze 9.6 return $matches[2];
312 djmaze 10.1 }
313 djmaze 1.1  
314 djmaze 1.1 /**
315 djmaze 1.1 * Functions for album/picture management
316 djmaze 1.1 */
317 djmaze 1.1 function get_cat_content(&$list, $cat, $title)
318 djmaze 1.1 {
319 djmaze 9.22 //if (!GALLERY_ADMIN_MODE) $upload = "AND uploads = 1";
320 djmaze 9.22 $upload = (!GALLERY_ADMIN_MODE) ? "AND uploads = 1" : '';
321 akamu 9.14 global $db, $CONFIG, $module_name;
322 djmaze 9.36 $albums = $db->sql_query("SELECT aid, title, visibility FROM {$CONFIG['TABLE_ALBUMS']} WHERE category = " . $cat . " $upload ORDER BY title");
323 akamu 9.14 $ug = USER_IN_GROUPS;
324 djmaze 9.6 while ($album = $db->sql_fetchrow($albums)) {
325 akamu 9.15 if(can_admin($module_name) || user_ingroup($album['visibility'], $ug) || ($album['visibility']=='0')){
326 akamu 9.14 $rowset['aid'] = $album['aid'];
327 akamu 9.14 $rowset['title'] = $title . $album['title'];
328 akamu 9.14 $list[] = $rowset;
329 akamu 9.14 }
330 djmaze 9.6 }
331 djmaze 9.6 $db->sql_freeresult($albums);
332 djmaze 9.6  
333 djmaze 9.36 $cats = $db->sql_query("SELECT cid, catname FROM {$CONFIG['TABLE_CATEGORIES']} WHERE parent=".$cat." ORDER BY catname");
334 djmaze 9.6 while ($subcat = $db->sql_fetchrow($cats)) {
335 djmaze 9.6 $tmptitle = $title . $subcat['catname'] . " > ";
336 djmaze 9.6 get_cat_content($list, $subcat['cid'], $tmptitle);
337 djmaze 9.6 }
338 djmaze 9.6 $db->sql_freeresult($cats);
339 djmaze 1.1 }
340 djmaze 1.1 // get a full list of albums to use
341 djmaze 1.1 function get_albumlist($user_id=0)
342 djmaze 1.1 {
343 djmaze 9.36 if (!GALLERY_ADMIN_MODE) $upload = 'AND uploads = 1';
344 djmaze 9.19 global $db, $CONFIG;
345 djmaze 1.1  
346 djmaze 9.6 $select = array();
347 djmaze 9.6 get_cat_content($select, 0, '');
348 djmaze 1.1  
349 akamu 9.14 if (GALLERY_ADMIN_MODE){
350 djmaze 9.36 $sql = "SELECT aid, CONCAT('(', username, ') ', title) AS title FROM {$CONFIG['TABLE_ALBUMS']} AS a "
351 djmaze 9.36 ."INNER JOIN {$CONFIG['TABLE_USERS']} AS u ON user_id = (category - " . FIRST_USER_CAT . ') '
352 djmaze 9.36 .'ORDER BY title';
353 akamu 9.25 } elseif (USER_CAN_CREATE_ALBUMS) {
354 djmaze 9.6 $sql = "SELECT aid, CONCAT('* ', title) AS title FROM {$CONFIG['TABLE_ALBUMS']} WHERE category='" . (FIRST_USER_CAT + $user_id) . "' ORDER BY title";
355 akamu 9.14 }
356 akamu 9.25 if (GALLERY_ADMIN_MODE || USER_CAN_CREATE_ALBUMS){
357 djmaze 9.36 $result = $db->sql_query($sql);
358 akamu 9.25 while ($row = $db->sql_fetchrow($result)) $select[] = $row;
359 akamu 9.25 $db->sql_freeresult($result);
360 akamu 9.25 }
361 djmaze 9.6 return $select;
362 djmaze 1.1 }
363 djmaze 1.1  
364 djmaze 1.1 // Retrieve the data for a picture or a set of picture
365 djmaze 1.1 function get_pic_data($meta, $album, &$count, &$album_name, $limit1 = -1, $limit2 = -1, $set_caption = true)
366 djmaze 1.1 {
367 djmaze 9.6 require_once("includes/nbbcode.php");
368 djmaze 9.6 global $USER, $CONFIG, $THEME_DIR, $FAVPICS;
369 nanocaio 9.38 global $thisalbum, $cat, $userinfo;
370 djmaze 9.6 global $lang_meta_album_names, $CPG_M_DIR, $CPG_PROFILE_URL;
371 djmaze 9.6 global $db;
372 djmaze 9.6 $sort_array = array('na' => 'filename ASC', 'nd' => 'filename DESC', 'ta' => 'title ASC', 'td' => 'title DESC', 'da' => 'pid ASC', 'dd' => 'pid DESC', 'ra' => 'pic_rating ASC', 'rd' => 'pic_rating DESC', 'sd' => 'max(pwidth,pheight) DESC', 'sa' => 'max(pwidth,pheight) ASC'); //'sa' => 'max(pwidth,pheight) DESC'
373 djmaze 9.6 $sort_code = isset($USER['sort'])? $USER['sort'] : $CONFIG['default_sort_order'];
374 djmaze 9.6 $sort_order = isset($sort_array[$sort_code]) ? $sort_array[$sort_code] : $sort_array[$CONFIG['default_sort_order']];
375 djmaze 9.6 $cat = (isset($_GET['cat']) && is_numeric($_GET['cat'])) ? $_GET['cat'] : 0;
376 nanocaio 9.37 $limit = ($limit1 >= 0) ? 'LIMIT '. intval($limit1) : '';
377 nanocaio 9.37 $limit .= (($limit1 >= 0) && ($limit2 > 0)) ? ','. intval($limit2) : '';
378 akamu 9.20 /*$limit1 = intval($limit1);
379 djmaze 9.6 $limit2 = intval($limit2);
380 djmaze 9.6 $limit = ($limit1 >= 0) ? ' LIMIT ' . $limit1 : '';
381 djmaze 9.6 $limit .= ($limit2 > 0) ? ' ,' . $limit2 : '';
382 akamu 9.20 */
383 djmaze 9.6 if ($limit2 == 1) {
384 nanocaio 9.51 $all = true;
385 nanocaio 9.51 $columns = $db->list_columns($CONFIG['TABLE_PICTURES']);
386 djmaze 10.1 $select_columns = 'p.'.implode(', p.',array_keys($columns));
387 djmaze 9.6 } else {
388 nanocaio 9.51 $all = false;
389 nanocaio 9.51 $select_columns = 'p.pid, p.filepath, p.filename, p.title, p.keywords, p.url_prefix, p.filesize, p.pwidth, p.pheight, p.ctime, p.aid';
390 djmaze 9.6 }
391 djmaze 9.6 // Regular albums
392 djmaze 9.6 if (is_numeric($album) && $meta == '') {
393 djmaze 9.6 $album_name = get_album_name($album);
394 djmaze 9.36 $result = $db->sql_query("SELECT COUNT(*) from {$CONFIG['TABLE_PICTURES']} as p INNER JOIN {$CONFIG['TABLE_ALBUMS']} AS a ON (a.aid = $album AND ".VIS_GROUPS.") WHERE p.aid='$album' AND approved=1");
395 djmaze 9.6 $nbEnr = $db->sql_fetchrow($result);
396 djmaze 9.6 $count = $nbEnr[0];
397 djmaze 9.6 $db->sql_freeresult($result);
398 nanocaio 9.51 if (!$all) {
399 nanocaio 9.51 $select_columns .= ', p.caption, p.hits, a.description';
400 djmaze 9.6 }
401 nanocaio 9.52 $result = $db->sql_query("SELECT $select_columns FROM {$CONFIG['TABLE_PICTURES']} as p INNER JOIN {$CONFIG['TABLE_ALBUMS']} AS a ON (a.aid = $album AND ".VIS_GROUPS.") WHERE p.aid='$album' AND approved=1 GROUP BY $select_columns ORDER BY $sort_order $limit");
402 djmaze 9.6 $rowset = $db->sql_fetchrowset($result);
403 djmaze 9.6 $db->sql_freeresult($result);
404 djmaze 9.6 // Set picture caption
405 djmaze 9.6 if ($set_caption) foreach ($rowset as $key => $row) {
406 djmaze 9.6 $caption = ($rowset[$key]['title'] || $rowset[$key]['hits']) ? "<span class=\"thumb_title\">" . $rowset[$key]['title'] . (($rowset[$key]['title'])?"-":"") . sprintf(N_VIEWS, $rowset[$key]['hits']) . "</span>" : '';
407 djmaze 9.6 if ($CONFIG['caption_in_thumbview']) {
408 djmaze 9.6 $caption .= $rowset[$key]['caption'] ? "<span class=\"thumb_caption\">" . decode_bbcode($rowset[$key]['caption']) . "</span>" : '';
409 djmaze 9.6 }
410 djmaze 9.6 if ($CONFIG['display_comment_count']) {
411 djmaze 9.6 $comments_nr = count_pic_comments($row['pid']);
412 djmaze 9.6 if ($comments_nr > 0) $caption .= "<span class=\"thumb_num_comments\">" . sprintf(N_COMMENTS, $comments_nr) . "</span>";
413 djmaze 9.6 }
414 djmaze 9.6 $rowset[$key]['caption_text'] = $caption;
415 djmaze 9.6 }
416 djmaze 9.6 return $rowset;
417 djmaze 9.6 }
418 djmaze 9.6 // Meta albums
419 djmaze 9.6 $album_name = $lang_meta_album_names[$meta];
420 djmaze 9.6 // Limits pictures to the amount shown
421 djmaze 9.6 switch ($meta) {
422 djmaze 9.6 // Last comments
423 djmaze 10.1 case 'lastcom':
424 nanocaio 9.51 list($count) = $db->sql_ufetchrow("SELECT COUNT(*) FROM {$CONFIG['TABLE_COMMENTS']} as c INNER JOIN {$CONFIG['TABLE_PICTURES']} AS p ON (p.pid = c.pid AND approved=1) INNER JOIN {$CONFIG['TABLE_ALBUMS']} as a ON (p.aid = a.aid AND ".VIS_GROUPS." AND $thisalbum)", SQL_NUM);
425 djmaze 9.6 if (!$count) return array();
426 nanocaio 9.51 if (!$all) {
427 nanocaio 9.52 $select_columns = 'c.msg_id, c.author_id, c.msg_author, c.msg_date, c.msg_body, ' . $select_columns;
428 djmaze 9.6 }
429 nanocaio 9.52 $rowset = $db->sql_ufetchrowset("SELECT $select_columns FROM {$CONFIG['TABLE_COMMENTS']} as c INNER JOIN {$CONFIG['TABLE_PICTURES']} AS p ON (p.pid = c.pid AND approved=1) INNER JOIN {$CONFIG['TABLE_ALBUMS']} as a ON (p.aid = a.aid AND ".VIS_GROUPS." AND $thisalbum) GROUP BY $select_columns ORDER BY msg_date DESC $limit", SQL_BOTH);
430 djmaze 9.6 if ($set_caption) foreach ($rowset as $key => $row) {
431 djmaze 9.6 // FIX PostNuke
432 djmaze 9.6 if ($row['author_id']) {
433 djmaze 9.9 $user_link = '<a href ="'.$CPG_PROFILE_URL.$row['author_id'].'">'.$row['msg_author'].'</a>';
434 djmaze 9.6 } else {
435 djmaze 9.6 $user_link = $row['msg_author'];
436 djmaze 10.1 }
437 djmaze 9.6 $msg_body = strlen($row['msg_body']) > 50 ? substr($row['msg_body'], 0, 50) . "...": $row['msg_body'];
438 djmaze 9.6 // if ($CONFIG['enable_smilies']) $msg_body = process_smilies($msg_body);
439 djmaze 9.6 $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>';
440 djmaze 9.6 $rowset[$key]['caption_text'] = $caption;
441 djmaze 10.1 }
442 djmaze 9.6 return $rowset;
443 djmaze 9.6  
444 djmaze 9.6 // Last comments by a specific user
445 djmaze 9.6 case 'lastcomby':
446 nanocaio 9.51 if (!$all) {
447 nanocaio 9.52 $select_columns = 'c.pid , c.msg_id, c.author_id, c.msg_author, c.msg_date, c.msg_body, ' . str_replace('p.pid', '', $select_columns);
448 nanocaio 9.51 }
449 nanocaio 9.51 list($count) = $db->sql_ufetchrow("SELECT COUNT(*) FROM {$CONFIG['TABLE_COMMENTS']} as c INNER JOIN {$CONFIG['TABLE_PICTURES']} AS p ON (p.pid = c.pid AND approved=1) INNER JOIN {$CONFIG['TABLE_ALBUMS']} as a ON (p.aid = a.aid AND ".VIS_GROUPS.") WHERE author_id = " .USER_ID. " GROUP BY c.pid", SQL_NUM);
450 djmaze 9.6 if (!$count) return array();
451 nanocaio 9.52 $rowset = $db->sql_ufetchrowset("SELECT $select_columns FROM {$CONFIG['TABLE_COMMENTS']} as c INNER JOIN {$CONFIG['TABLE_PICTURES']} AS p ON (p.pid = c.pid AND approved=1) INNER JOIN {$CONFIG['TABLE_ALBUMS']} as a ON (p.aid = a.aid AND ".VIS_GROUPS.") WHERE author_id = " .USER_ID. " GROUP BY $select_columns ORDER BY msg_date DESC $limit", SQL_BOTH);
452 djmaze 9.6 if ($set_caption) foreach ($rowset as $key => $row) {
453 djmaze 9.6 require_once("includes/nbbcode.php");
454 djmaze 9.6 $comment_body = make_clickable($row['msg_body']);
455 djmaze 9.6 $user_link = $row['msg_author'];
456 djmaze 9.6 $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">' . $comment_body . '</span>';
457 djmaze 9.6 $rowset[$key]['caption_text'] = $caption;
458 djmaze 10.1 }
459 djmaze 9.6 return $rowset;
460 djmaze 9.6  
461 djmaze 9.6 // Last uploads
462 djmaze 10.1 case 'lastup':
463 nanocaio 9.34 list($count) = $db->sql_ufetchrow("SELECT COUNT(*) FROM {$CONFIG['TABLE_PICTURES']} AS p INNER JOIN {$CONFIG['TABLE_ALBUMS']} AS a ON (p.aid = a.aid AND ".VIS_GROUPS." AND $thisalbum) WHERE approved=1 ORDER BY p.pid DESC", SQL_NUM);
464 djmaze 9.6 if (!$count) return array();
465 nanocaio 9.51 if (!$all) {
466 nanocaio 9.51 $select_columns = $select_columns . ', p.owner_id, p.owner_name';
467 djmaze 9.6 }
468 djmaze 9.36 $result = $db->sql_query("SELECT $select_columns FROM {$CONFIG['TABLE_PICTURES']} AS p INNER JOIN {$CONFIG['TABLE_ALBUMS']} AS a ON (p.aid = a.aid AND ".VIS_GROUPS." AND $thisalbum) WHERE approved=1 ORDER BY p.pid DESC $limit");
469 djmaze 9.6 $rowset = $db->sql_fetchrowset($result);
470 djmaze 9.6 $db->sql_freeresult($result);
471 djmaze 9.6 if ($set_caption) foreach ($rowset as $key => $row) {
472 djmaze 9.6 if ($row['owner_id'] && $row['owner_name']) {
473 djmaze 9.6 $user_link = '<span class="thumb_title"><a href="$CPG_PROFILE_URL">' . $row['msg_author'] . '</a></span>';
474 djmaze 9.6 } else {
475 djmaze 9.6 $user_link = '';
476 djmaze 10.1 }
477 djmaze 9.6 $caption = $user_link . '<span class="thumb_caption">' . localised_date($row['ctime'], LASTUP_DATE_FMT) . '</span>';
478 djmaze 9.6 $rowset[$key]['caption_text'] = $caption;
479 djmaze 10.1 }
480 djmaze 9.6 return $rowset;
481 djmaze 9.6  
482 djmaze 9.6 // Last uploads by a specific user
483 djmaze 9.6 case 'lastupby':
484 nanocaio 9.38 list($count) = $db->sql_ufetchrow("SELECT COUNT(*) FROM {$CONFIG['TABLE_PICTURES']} WHERE owner_id = '{$userinfo['user_id']}' AND approved=1 GROUP BY pid", SQL_NUM);
485 nanocaio 9.38 if (!$count) return array();
486 nanocaio 9.51 if (!$all) {
487 nanocaio 9.51 $select_columns .= ', p.owner_id, p.owner_name';
488 nanocaio 9.51 }
489 nanocaio 9.38 $result = $db->sql_query("SELECT $select_columns FROM {$CONFIG['TABLE_PICTURES']} AS p INNER JOIN {$CONFIG['TABLE_ALBUMS']} AS a ON (p.aid = a.aid AND ".VIS_GROUPS." AND $thisalbum) WHERE owner_id = '{$userinfo['user_id']}' AND approved=1 ORDER BY p.pid DESC $limit");
490 djmaze 9.6 $rowset = $db->sql_fetchrowset($result);
491 djmaze 9.6 $db->sql_freeresult($result);
492 djmaze 9.6 if ($set_caption) foreach ($rowset as $key => $row) {
493 djmaze 9.6 if ($row['owner_id'] && $row['owner_name']) {
494 djmaze 9.9 $user_link = '<span class="thumb_title"><a href ="$CPG_PROFILE_URL'.$row['owner_id'].'">'.$row['msg_author'].'</a></span>';
495 djmaze 9.6 } else {
496 djmaze 9.6 $user_link = '';
497 djmaze 10.1 }
498 djmaze 9.6 $caption = $user_link . '<span class="thumb_caption">' . localised_date($row['ctime'], LASTUP_DATE_FMT) . '</span>';
499 djmaze 9.6 $rowset[$key]['caption_text'] = $caption;
500 djmaze 10.1 }
501 djmaze 9.6 return $rowset;
502 djmaze 9.6  
503 djmaze 9.6 // Most viewed pictures
504 djmaze 9.6 case 'topn':
505 nanocaio 9.34 list($count) = $db->sql_ufetchrow("SELECT COUNT(*) from {$CONFIG['TABLE_PICTURES']} AS p INNER JOIN {$CONFIG['TABLE_ALBUMS']} AS a ON (p.aid = a.aid AND ".VIS_GROUPS." AND $thisalbum) WHERE approved=1 AND hits > 0", SQL_NUM);
506 djmaze 9.6 if (!$count) return array();
507 nanocaio 9.51 if (!$all) {
508 nanocaio 9.51 $select_columns .= ', p.hits';
509 djmaze 9.6 }
510 nanocaio 9.37 $result = $db->sql_query("SELECT $select_columns FROM {$CONFIG['TABLE_PICTURES']} AS p INNER JOIN {$CONFIG['TABLE_ALBUMS']} AS a ON (p.aid = a.aid AND ".VIS_GROUPS." AND $thisalbum) WHERE approved=1 AND p.hits > 0 ORDER BY p.hits DESC, p.filename ASC $limit");
511 djmaze 9.36 //$result2 = $db->sql_query("SELECT FOUND_ROWS()");
512 nanocaio 9.37 $rowset = $db->sql_fetchrowset($result, SQL_ASSOC);
513 djmaze 9.6 //$nbEnr = $db->sql_fetchrow($result2);
514 djmaze 9.6 //$count = $nbEnr[0];
515 djmaze 9.6 $db->sql_freeresult($result);
516 djmaze 9.6 if ($set_caption) foreach ($rowset as $key => $row) {
517 djmaze 9.6 $caption = "<span class=\"thumb_caption\">" . sprintf(N_VIEWS, $row['hits']) . '</span>';
518 djmaze 9.6 $rowset[$key]['caption_text'] = $caption;
519 djmaze 10.1 }
520 djmaze 9.6 return $rowset;
521 djmaze 9.6  
522 djmaze 9.6 // Top rated pictures
523 djmaze 9.6 case 'toprated':
524 nanocaio 9.51 list($count) = $db->sql_ufetchrow("SELECT COUNT(*) FROM {$CONFIG['TABLE_PICTURES']} AS p INNER JOIN {$CONFIG['TABLE_ALBUMS']} AS a ON (p.aid = a.aid AND ".VIS_GROUPS." AND $thisalbum) WHERE approved=1 AND p.votes >= {$CONFIG['min_votes_for_rating']}", SQL_NUM);
525 djmaze 9.6 if (!$count) return array();
526 nanocaio 9.51 if (!$all) {
527 nanocaio 9.51 $select_columns .= ', p.pic_rating, p.votes AS votes';
528 djmaze 9.6 }
529 phoenix 9.44 $result = $db->sql_query("SELECT $select_columns FROM {$CONFIG['TABLE_PICTURES']} AS p INNER JOIN {$CONFIG['TABLE_ALBUMS']} AS a ON (p.aid = a.aid AND ".VIS_GROUPS." AND $thisalbum) WHERE approved=1 AND p.votes >= '{$CONFIG['min_votes_for_rating']}' ORDER BY ROUND((pic_rating+1)/2000,2) DESC, p.votes DESC, filename $limit");
530 djmaze 9.6 $rowset = $db->sql_fetchrowset($result);
531 djmaze 9.6 $db->sql_freeresult($result);
532 djmaze 9.6 if ($set_caption) foreach ($rowset as $key => $row) {
533 djmaze 9.6 if (defined('THEME_HAS_RATING_GRAPHICS')) {
534 djmaze 9.6 $theme_prefix = "$CONFIG[theme]/";
535 djmaze 9.6 } else {
536 djmaze 9.6 $theme_prefix = '';
537 djmaze 10.1 }
538 djmaze 9.6 $caption = "<img src=\"" . $CPG_M_DIR . "/" . $theme_prefix . "images/rating" . round($row['pic_rating'] / 2000) . ".gif\" alt=\"".sprintf(RATING, round($row['pic_rating'] / 2000),$row['votes'])."\" border=\"0\" />" . "<br />" . round($row['pic_rating'] / 2000, 2) . "/5 ";
539 djmaze 9.6 $caption .= sprintf(N_VOTES, $row['votes']);
540 djmaze 9.6 $rowset[$key]['caption_text'] = $caption;
541 djmaze 10.1 }
542 djmaze 9.6 return $rowset;
543 djmaze 9.6  
544 djmaze 9.6 // Last viewed pictures
545 djmaze 9.6 case 'lasthits':
546 nanocaio 9.34 list($count) = $db->sql_ufetchrow("SELECT COUNT(*) from {$CONFIG['TABLE_PICTURES']} AS p INNER JOIN {$CONFIG['TABLE_ALBUMS']} AS a ON (p.aid = a.aid AND ".VIS_GROUPS." AND $thisalbum) WHERE approved=1 AND $thisalbum", SQL_NUM);
547 djmaze 9.6 if (!$count) return array();
548 djmaze 9.6 // count the number of pics to show
549 nanocaio 9.51 if (!$all) {
550 nanocaio 9.52 $select_columns .= ', p.mtime';
551 nanocaio 9.51 }
552 nanocaio 9.52 $result = $db->sql_query("SELECT $select_columns FROM {$CONFIG['TABLE_PICTURES']} AS p INNER JOIN {$CONFIG['TABLE_ALBUMS']} AS a ON (p.aid = a.aid AND ".VIS_GROUPS." AND $thisalbum) WHERE approved=1 AND $thisalbum GROUP BY $select_columns ORDER BY mtime DESC $limit");
553 djmaze 9.6 $rowset = $db->sql_fetchrowset($result);
554 djmaze 9.6 $db->sql_freeresult($result);
555 djmaze 9.6 if ($set_caption) foreach ($rowset as $key => $row) {
556 djmaze 9.6 $caption = "<span class=\"thumb_caption\">" . localised_date($row['mtime'], LASTHIT_DATE_FMT) . '</span>';
557 djmaze 9.6 $rowset[$key]['caption_text'] = $caption;
558 djmaze 10.1 }
559 djmaze 9.6 return $rowset;
560 djmaze 9.6  
561 djmaze 9.6 // Random pictures
562 djmaze 9.6 case 'random':
563 nanocaio 9.34 list($pic_count) = $db->sql_ufetchrow("SELECT COUNT(*) from {$CONFIG['TABLE_PICTURES']} AS p INNER JOIN {$CONFIG['TABLE_ALBUMS']} AS a ON (p.aid = a.aid AND ".VIS_GROUPS." AND $thisalbum) WHERE approved=1 GROUP BY p.pid", SQL_NUM);
564 djmaze 9.6 if (!$pic_count) return array();
565 djmaze 9.6 // count the number of pics to show
566 djmaze 9.6 // if we have more than 1000 pictures, we limit the number of picture returned
567 djmaze 9.6 // by the SELECT statement as ORDER BY RAND() is time consuming
568 djmaze 9.6 if ($pic_count > 1000) {
569 nanocaio 9.34 // $result = $db->sql_query("SELECT COUNT(*) from {$CONFIG['TABLE_PICTURES']} AS p INNER JOIN {$CONFIG['TABLE_ALBUMS']} AS a ON (p.aid = a.aid AND ".VIS_GROUPS." AND $thisalbum) WHERE approved=1 AND $thisalbum GROUP BY p.pid",false);
570 djmaze 9.6 // $nbEnr = $db->sql_fetchrow($result);
571 djmaze 9.6 $total_count = $nbEnr[0];
572 djmaze 9.6 $db->sql_freeresult($result);
573 djmaze 9.6 $granularity = floor($total_count / RANDPOS_MAX_PIC);
574 djmaze 9.6 $cor_gran = ceil($total_count / $pic_count);
575 djmaze 9.6 srand(time());
576 djmaze 9.6 for ($i = 1; $i <= $cor_gran; $i++) $random_num_set = rand(0, $granularity) . ', ';
577 djmaze 9.6 $random_num_set = substr($random_num_set, 0, -2);
578 nanocaio 9.52 $result = $db->sql_query("SELECT $select_columns FROM {$CONFIG['TABLE_PICTURES']} AS p INNER JOIN {$CONFIG['TABLE_ALBUMS']} ON (".VIS_GROUPS." AND $thisalbum) WHERE randpos IN ($random_num_set) AND approved = 1 GROUP BY $select_columns ORDER BY RAND() $limit");
579 djmaze 9.6 } else {
580 nanocaio 9.52 $result = $db->sql_query("SELECT $select_columns FROM {$CONFIG['TABLE_PICTURES']} AS p INNER JOIN {$CONFIG['TABLE_ALBUMS']} AS a ON (p.aid = a.aid AND ".VIS_GROUPS." AND $thisalbum) WHERE approved=1 GROUP BY $select_columns ORDER BY RAND() $limit");
581 djmaze 10.1 }
582 djmaze 9.6 $rowset = $db->sql_fetchrowset($result);
583 djmaze 9.6 /* $rowset = array();
584 djmaze 9.6 while ($row = $db->sql_fetchrow($result)) {
585 djmaze 9.6 $row['caption_text'] = '';
586 djmaze 9.6 $rowset[$row['pid']] = $row;
587 djmaze 9.6 }*/
588 djmaze 9.6 $db->sql_freeresult($result);
589 djmaze 9.6 return $rowset;
590 djmaze 9.6  
591 djmaze 9.6 //All pictures by member
592 djmaze 9.6 case 'allby':
593 djmaze 9.6 $m_id = (isset($_GET['member_id'])) ? intval($_GET['member_id']) : 1;
594 nanocaio 9.51 if (!$all) {
595 nanocaio 9.52 $select_columns .= ', p.owner_id, p.owner_name';
596 nanocaio 9.51 }
597 djmaze 10.1 $query = "{$CONFIG['TABLE_PICTURES']} AS p INNER JOIN {$CONFIG['TABLE_ALBUMS']} AS a ON (p.aid = a.aid AND ".VIS_GROUPS.") WHERE owner_id = '$m_id' AND approved=1 GROUP BY $select_columns ORDER BY p.pid DESC";
598 nanocaio 9.51 list($count) = $db->sql_ufetchrow("SELECT COUNT(*) FROM $query", SQL_NUM);
599 djmaze 9.6 if (!$count) return array();
600 djmaze 9.36 $result = $db->sql_query("SELECT $select_columns FROM $query $limit");
601 djmaze 9.6 $rowset = $db->sql_fetchrowset($result);
602 djmaze 9.6 $db->sql_freeresult($result);
603 djmaze 9.6 return $rowset;
604 djmaze 9.6  
605 djmaze 9.6 // Search results
606 djmaze 9.6 case 'search':
607 djmaze 9.6 if (isset($_GET['search'])) {
608 djmaze 9.6 $USER['search'] = Fix_Quotes($_GET['search']);
609 djmaze 9.6 if (isset($_GET['type']) && $_GET['type'] == 'full') {
610 djmaze 9.6 $USER['search'] = '###' . $USER['search'];
611 djmaze 10.1 }
612 djmaze 9.6 } elseif (isset($_POST['search'])) {
613 djmaze 9.6 $USER['search'] = Fix_Quotes($_POST['search']);
614 djmaze 9.6 if (isset($_POST['type']) && $_POST['type'] == 'full') {
615 djmaze 9.6 $USER['search'] = '###' . $USER['search'];
616 djmaze 9.6 }
617 djmaze 9.6 }
618 djmaze 9.6 if (isset($USER['search'])) {
619 djmaze 9.6 $search_string = Fix_Quotes($USER['search']);
620 djmaze 9.6 } else {
621 djmaze 9.6 cpg_die(_CRITICAL_ERROR, 'The searchstring is empty', __FILE__, __LINE__);
622 djmaze 9.6 $search_string = '';
623 djmaze 9.6 }
624 djmaze 9.6  
625 djmaze 9.6 if (substr($search_string, 0, 3) == '###') {
626 djmaze 9.6 $query_all = 1;
627 djmaze 9.6 $search_string = substr($search_string, 3);
628 djmaze 9.6 } else {
629 djmaze 9.6 $query_all = 0;
630 djmaze 10.1 }
631 djmaze 9.6 $album_name .= ' - "' . htmlprepare($search_string) . '"';
632 djmaze 9.6  
633 djmaze 9.11 require(CORE_PATH.'coppermine/search.inc');
634 nanocaio 9.46 $rowset = search_pics($search_string, $select_columns, $query_all, $limit, $pic_count, $set_caption);
635 nanocaio 9.46 $count = $pic_count;
636 djmaze 9.6 return $rowset;
637 djmaze 9.6  
638 djmaze 9.6 // Last albums to which uploads
639 djmaze 9.6 case 'lastalb':
640 nanocaio 9.46 list($count) = $db->sql_ufetchrow("SELECT COUNT(*) FROM {$CONFIG['TABLE_PICTURES']} AS p INNER JOIN {$CONFIG['TABLE_ALBUMS']} AS a ON (p.aid = a.aid AND ".VIS_GROUPS." AND $thisalbum) WHERE approved=1 AND $thisalbum", SQL_NUM);
641 djmaze 9.6 if (!$count) return array();
642 nanocaio 9.52 $result = $db->sql_query("SELECT $select_columns, a.title AS title, a.aid AS aid FROM {$CONFIG['TABLE_PICTURES']} AS p INNER JOIN {$CONFIG['TABLE_ALBUMS']} AS a ON (p.aid = a.aid AND ".VIS_GROUPS." AND $thisalbum) WHERE approved = 1 GROUP BY a.aid, a.title, $select_columns ORDER BY p.ctime DESC $limit");
643 djmaze 9.6 $rowset = $db->sql_fetchrowset($result);
644 djmaze 9.6 $db->sql_freeresult($result);
645 djmaze 9.6 if ($set_caption) foreach ($rowset as $key => $row) {
646 djmaze 9.6 $caption = "<span class=\"thumb_caption\">" . $row['title'] . " - " . localised_date($row['ctime'], LASTUP_DATE_FMT) . '</span>';
647 djmaze 9.6 $rowset[$key]['caption_text'] = $caption;
648 djmaze 10.1 }
649 djmaze 9.6 return $rowset;
650 djmaze 9.6  
651 djmaze 9.6 // Favourite Pictures
652 djmaze 9.6 case 'favpics':
653 djmaze 9.6 if (count($FAVPICS) > 0) {
654 nanocaio 9.51 $count = count($FAVPICS);
655 djmaze 9.6 $favs = implode(",", $FAVPICS);
656 nanocaio 9.52 $result = $db->sql_query("SELECT $select_columns FROM {$CONFIG['TABLE_PICTURES']} AS p WHERE approved = 1 AND pid IN ($favs) GROUP BY $select_columns $limit");
657 djmaze 9.6 $rowset = $db->sql_fetchrowset($result);
658 djmaze 9.6 $db->sql_freeresult($result);
659 djmaze 9.6 if ($set_caption) foreach ($rowset as $key => $row) {
660 djmaze 9.6 $caption = $rowset[$key]['title'] ? "<span class=\"thumb_caption\">" . ($rowset[$key]['title']) . "</span>" : '';
661 djmaze 9.6 $rowset[$key]['caption_text'] = $caption;
662 djmaze 10.1 }
663 djmaze 9.6 return $rowset;
664 djmaze 9.6 }
665 djmaze 9.6 else return null;
666 djmaze 9.6  
667 djmaze 9.6 // Invalid meta album
668 djmaze 9.6 default :
669 djmaze 9.6 cpg_die(_ERROR, NON_EXIST_AP.' '.$_GET['meta'].' '.$_POST['meta'].$meta, __FILE__, __LINE__);
670 djmaze 10.1 }
671 djmaze 1.1 } // End of get_pic_data
672 djmaze 1.1 // Get the name of an album
673 djmaze 1.1 function get_album_name($aid)
674 djmaze 1.1 {
675 djmaze 9.6 global $db,$CONFIG;
676 djmaze 9.6 //global $lang_errors;
677 djmaze 9.36 $result = $db->sql_query("SELECT title from {$CONFIG['TABLE_ALBUMS']} WHERE aid='$aid'");
678 djmaze 9.6 $count = $db->sql_numrows($result);
679 djmaze 9.6 if ($count > 0) {
680 djmaze 9.6 $row = $db->sql_fetchrow($result);
681 djmaze 9.6 return $row['title'];
682 djmaze 9.6 } else {
683 djmaze 9.6 cpg_die(_ERROR,NON_EXIST_AP.' '.$aid, __FILE__, __LINE__);
684 djmaze 10.1 }
685 djmaze 10.1 }
686 djmaze 1.1 // Return the name of a user
687 nanocaio 9.38 // obsolete function ?
688 djmaze 1.1 function get_username($uid)
689 djmaze 1.1 {
690 djmaze 9.6 $uid =intval($uid);
691 nanocaio 9.38 $data = getusrdata($uid);
692 nanocaio 9.38 //$data = getusrdata($uid, 'username');
693 nanocaio 9.38 return $data['username'];
694 djmaze 1.1 }
695 djmaze 1.1 // Return the total number of comments for a certain picture
696 djmaze 1.1 function count_pic_comments($pid, $skip = 0)
697 djmaze 1.1 {
698 djmaze 9.6 global $db, $CONFIG;
699 djmaze 9.36 $result = $db->sql_query("SELECT COUNT(*) FROM {$CONFIG['TABLE_COMMENTS']} WHERE pid=$pid and msg_id!=$skip");
700 djmaze 10.1 list($count) = $db->sql_fetchrow($result);
701 djmaze 9.6 $db->sql_freeresult($result);
702 djmaze 9.6 return $count;
703 djmaze 10.1 }
704 djmaze 1.1 // Add 1 everytime a picture is viewed.
705 djmaze 1.1 function add_hit($pid)
706 djmaze 1.1 {
707 djmaze 9.6 global $CONFIG,$db;
708 djmaze 9.36 $db->sql_query("UPDATE {$CONFIG['TABLE_PICTURES']} SET hits=hits+1 WHERE pid='$pid'");
709 djmaze 9.6 //$db->sql_freeresult($result);
710 djmaze 10.1 }
711 djmaze 1.1  
712 djmaze 1.1 // Build the breadcrumb array
713 djmaze 1.1 function set_breadcrumb($lasturl = 0)
714 djmaze 1.1 {
715 djmaze 9.19 global $db, $CONFIG, $CPG_M_URL, $album, $cat, $lang_meta_album_names,$pagetitle;
716 djmaze 9.6 $breadcrumb = array();
717 djmaze 9.6 $aid = $album;
718 djmaze 9.6 if ($cat < 0 && $cat != -$aid) {
719 djmaze 9.6 $aid = -$cat;
720 djmaze 9.6 $lasturl = 1;
721 djmaze 9.6 }
722 djmaze 9.6 if (is_numeric($aid) && $aid > 0) {
723 djmaze 9.36 $result = $db->sql_query("SELECT aid AS id, title, category AS parent FROM {$CONFIG['TABLE_ALBUMS']} WHERE aid = ".$aid);
724 djmaze 9.6 if ($db->sql_numrows($result)) {
725 djmaze 9.6 $row = $db->sql_fetchrow($result);
726 djmaze 9.6 $row['last'] = !$lasturl;
727 djmaze 9.6 $row['album'] = 1;
728 djmaze 9.6 $breadcrumb[] = $row;
729 djmaze 9.6 $db->sql_freeresult($result);
730 djmaze 9.6 }
731 djmaze 9.6 }
732 djmaze 9.6 else if (is_numeric($cat) && $cat > 0) {
733 djmaze 9.6 if ($cat > FIRST_USER_CAT) {
734 nanocaio 9.40 $row['title'] = getusrdata($cat - FIRST_USER_CAT, 'username');
735 nanocaio 9.40 $row['title'] = $row['title']['username'];
736 nanocaio 9.40 if (!empty($row['title'])) {
737 djmaze 9.6 $row['id'] = $cat;
738 djmaze 9.6 $row['parent'] = 1;
739 djmaze 9.6 $row['last'] = !$lasturl;
740 djmaze 9.6 $breadcrumb[] = $row;
741 nanocaio 9.40 } else {
742 nanocaio 9.40 unset($row['title']);
743 djmaze 9.6 }
744 djmaze 9.6 }
745 djmaze 9.6 else {
746 nanocaio 9.40 foreach (get_categories_data() as $row) {
747 nanocaio 9.40 if ($row['cid'] != $cat) continue;
748 nanocaio 9.40 $row['id'] = $cat;
749 nanocaio 9.40 $row['title'] = $row['catname'];
750 djmaze 9.6 $row['last'] = !$lasturl;
751 nanocaio 9.40 unset($row['cid'], $row['catname'], $row['description']);
752 djmaze 9.6 $breadcrumb[] = $row;
753 djmaze 9.6 }
754 djmaze 9.6 }
755 djmaze 9.6 }
756 djmaze 9.6 get_breadcrumb($breadcrumb);
757 nanocaio 9.47 $navigation = '<a class="statlink" id="statlink" href="'.URL::index("").'">' . $CONFIG['gallery_name'] . '</a> ';
758 djmaze 9.6 foreach($breadcrumb as $crumb) {
759 djmaze 9.6 if (isset($crumb['last'])) {
760 djmaze 9.6 $navigation .= ' '._BC_DELIM.' '.$crumb['title'];
761 djmaze 9.6 } elseif (isset($crumb['album'])) {
762 nanocaio 9.47 $navigation .= _BC_DELIM.' <a class="statlink" id="statlink" href="'.URL::index('&file=thumbnails&album='.$crumb['id']).'">'.$crumb['title'].'</a>';
763 djmaze 9.6 } else {
764 nanocaio 9.47 $navigation .= _BC_DELIM.' <a class="statlink" id="statlink" href="'.URL::index("&amp;cat=".$crumb['id']).'">'.$crumb['title'].'</a>';
765 djmaze 9.6 }
766 djmaze 9.6 }
767 djmaze 9.6 if (isset($_GET['meta']) && ($_GET['meta']!='')) {
768 djmaze 9.6 $navigation .= " "._BC_DELIM." ".$lang_meta_album_names[$_GET['meta']];
769 djmaze 9.6 }
770 djmaze 9.6 if ($navigation == "") $navigation = _BC_DELIM." Coppermine";
771 djmaze 9.6 $dummy = array();
772 djmaze 9.6 theme_display_breadcrumb($navigation, $dummy);
773 djmaze 1.1 }
774 djmaze 1.1  
775 djmaze 1.1 // Get the breadcrumb array
776 djmaze 1.1 function get_breadcrumb(&$breadcrumb)
777 djmaze 1.1 {
778 djmaze 9.19 global $db, $CONFIG;
779 djmaze 9.6 if (!$breadcrumb) return;
780 djmaze 9.6 $last = count($breadcrumb);
781 djmaze 9.6 if ($breadcrumb[0]['parent'] == 0 || !is_numeric($breadcrumb[0]['parent'])) return;
782 djmaze 9.6 if ($breadcrumb[$last-1]['parent'] > FIRST_USER_CAT) {
783 djmaze 9.6 $cat = $breadcrumb[$last-1]['parent'];
784 djmaze 9.36 $result = $db->sql_query("SELECT username AS title FROM {$CONFIG['TABLE_USERS']} WHERE user_id = " . ($cat - FIRST_USER_CAT));
785 djmaze 9.6 if ($db->sql_numrows($result)) {
786 djmaze 9.6 $row = $db->sql_fetchrow($result);
787 djmaze 9.6 $row['id'] = $cat;
788 djmaze 9.6 $row['parent'] = 1;
789 djmaze 9.6 $breadcrumb[] = $row;
790 djmaze 9.6 $db->sql_freeresult($result);
791 djmaze 9.6 get_breadcrumb($breadcrumb);
792 djmaze 9.6 }
793 djmaze 9.6 return;
794 djmaze 9.6 }
795 nanocaio 9.40 foreach (get_categories_data() as $row) {
796 nanocaio 9.40 if ($row['cid'] != $breadcrumb[$last-1]['parent']) continue;
797 nanocaio 9.40 $row['id'] = $row['cid'];
798 nanocaio 9.40 $row['title'] = $row['catname'];
799 nanocaio 9.40 unset($row['cid'], $row['catname'], $row['description']);
800 djmaze 9.6 $breadcrumb[] = $row;
801 djmaze 9.6 if ($row['parent'] > 0 && is_numeric($row['parent'])) get_breadcrumb($breadcrumb);
802 djmaze 9.6 else {
803 djmaze 9.6 $breadcrumb = array_reverse($breadcrumb);
804 djmaze 9.6 return;
805 djmaze 9.6 }
806 djmaze 9.6 }
807 djmaze 1.1 }
808 djmaze 1.1  
809 djmaze 1.1 // Compute image geometry based on max width / height
810 djmaze 1.1 function compute_img_size($width, $height, $max)
811 djmaze 1.1 {
812 djmaze 9.6 global $CONFIG;
813 djmaze 9.6 $thumb_use = $CONFIG['thumb_use'];
814 djmaze 9.6 if ($thumb_use == 'ht') {
815 djmaze 9.6 $ratio = $height / $max;
816 djmaze 9.6 } elseif ($thumb_use == 'wd') {
817 djmaze 9.6 $ratio = $width / $max;
818 djmaze 9.6 } else {
819 djmaze 9.6 $ratio = max($width, $height) / $max;
820 djmaze 10.1 }
821 djmaze 9.6 if ($ratio > 1.0) {
822 djmaze 9.6 $image_size['reduced'] = true;
823 djmaze 10.1 }
824 djmaze 9.6 $ratio = max($ratio, 1.0);
825 djmaze 9.6 $image_size['width'] = ceil($width / $ratio);
826 djmaze 9.6 $image_size['height'] = ceil($height / $ratio);
827 djmaze 9.6 $image_size['geom'] = 'width="' . $image_size['width'] . '" height="' . $image_size['height'] . '"';
828 djmaze 1.1  
829 djmaze 9.6 return $image_size;
830 djmaze 10.1 }
831 djmaze 1.1 function display_film_strip($meta, $album, $cat, $pos)
832 djmaze 1.1 {
833 djmaze 9.6 global $CONFIG, $AUTHORIZED;
834 djmaze 9.6 global $album_date_fmt, $lang_byte_units;
835 djmaze 10.1 $max_item = $CONFIG['max_film_strip_items'];
836 djmaze 9.6 $thumb_per_page = $max_item * 2;
837 djmaze 9.6 $l_limit = max(0, $pos - $CONFIG['max_film_strip_items']);
838 djmaze 9.6 $new_pos = max(0, $pos - $l_limit);
839 djmaze 9.6 $pic_data = get_pic_data($meta, $album, $thumb_count, $album_name, $l_limit, $thumb_per_page);
840 djmaze 9.6 if (count($pic_data) < $max_item) {
841 djmaze 9.6 $max_item = count($pic_data);
842 djmaze 10.1 }
843 djmaze 9.6 $lower_limit = 3;
844 djmaze 9.6 if (!isset($pic_data[$new_pos + 1])) {
845 djmaze 9.6 $lower_limit = $new_pos - $max_item + 1;
846 djmaze 9.6 } else if (!isset($pic_data[$new_pos + 2])) {
847 djmaze 9.6 $lower_limit = $new_pos - $max_item + 2;
848 djmaze 9.6 } else if (!isset($pic_data[$new_pos-1])) {
849 djmaze 9.6 $lower_limit = $new_pos;
850 djmaze 9.6 } else {
851 djmaze 9.6 $hf = $max_item / 2;
852 djmaze 9.6 $ihf = (int)($max_item / 2);
853 djmaze 9.6 if ($new_pos > $hf) {
854 djmaze 9.6 $lower_limit = $new_pos - $ihf;
855 djmaze 9.6 } elseif ($new_pos < $hf) {
856 djmaze 9.6 $lower_limit = 0;
857 djmaze 10.1 }
858 djmaze 10.1 }
859 djmaze 9.6 $pic_data = array_slice($pic_data, $lower_limit, $max_item);
860 djmaze 9.6 $i = $l_limit;
861 djmaze 9.6 if (count($pic_data) > 0) {
862 djmaze 9.6 $meta_link = ($meta != '') ? '&amp;meta='.$meta : '';
863 nanocaio 9.37 if (is_numeric($album) && $meta != 'random') {
864 djmaze 9.6 $alb_link = '&amp;album='.$album;
865 djmaze 9.6 } else {
866 djmaze 9.6 $alb_link = '&amp;cat='.(isset($cat) ? $cat : '0');
867 djmaze 9.6 }
868 djmaze 9.6 foreach ($pic_data as $key => $row) {
869 djmaze 9.6 $hi = (($pos == ($i + $lower_limit)) ? '1': '');
870 djmaze 9.6 $i++;
871 djmaze 9.6  
872 djmaze 9.6 $image_size = compute_img_size($row['pwidth'], $row['pheight'], $CONFIG['thumb_width']);
873 djmaze 9.6  
874 djmaze 9.6 if ($CONFIG['seo_alts'] == 0) {
875 djmaze 9.6 $pic_title = FILENAME . $row['filename'] . "\n" . FILESIZE . ($row['filesize'] >> 10) . $lang_byte_units[1] . "\n" . DIMENSIONS . $row['pwidth'] . "x" . $row['pheight'] . "\n" . DATE_ADDED . localised_date($row['ctime'], ALBUM_DATE_FMT);
876 djmaze 9.6 } else {
877 djmaze 9.6 if ($row['title'] != '') {
878 djmaze 9.6 $pic_title = $row['title'];
879 djmaze 9.6 if ($row['keywords'] != '') {
880 djmaze 9.6 $pic_title .= "\n";
881 djmaze 9.6 $pic_title .= $row['keywords'];
882 djmaze 10.1 }
883 djmaze 9.6 } elseif ($row['keywords'] != '') {
884 djmaze 9.6 $pic_title = $row['keywords'];
885 djmaze 9.6 } else {
886 djmaze 9.6 $pic_title = substr($row['filename'], 0, -4);
887 djmaze 10.1 }
888 djmaze 10.1 }
889 nanocaio 9.37 if ($meta == 'random') {
890 nanocaio 9.37 $thumb_list[$i]['pos'] = $row['pid'];
891 nanocaio 9.37 } else {
892 nanocaio 9.37 $p = $i - 1 + $lower_limit;
893 nanocaio 9.37 $p = ($p < 0 ? 0 : $p);
894 djmaze 10.1 $thumb_list[$i]['pos'] = $key < 0 ? $key : $p;
895 nanocaio 9.37 }
896 djmaze 9.6 if ($CONFIG['seo_alts'] == 0) {
897 djmaze 9.21 $thumb_list[$i]['image'] = "<img src=\"" . get_pic_url($row, 'thumb') . "\" class=\"image\" {$image_size['geom']} border=\"0\" alt=\"{$row['filename']}\" title=\"$pic_title\" />";
898 djmaze 9.6 } else {
899 djmaze 9.21 $thumb_list[$i]['image'] = "<img src=\"" . get_pic_url($row, 'thumb') . "\" class=\"image\" {$image_size['geom']} border=\"0\" alt=\"$pic_title\" title=\"$pic_title\" />";
900 djmaze 10.1 }
901 nanocaio 9.37 $thumb_list[$i]['caption'] = isset($row['caption_text']) ? $row['caption_text'] : '';
902 djmaze 9.6 $thumb_list[$i]['admin_menu'] = '';
903 nanocaio 9.47 $thumb_list[$i]['url'] = URL::index("&amp;file=displayimage$meta_link$alb_link&amp;pos=".$thumb_list[$i]['pos']);
904 djmaze 9.6 }
905 djmaze 9.6 return theme_display_film_strip($thumb_list);
906 djmaze 9.6 } else {
907 djmaze 9.6 //theme_no_img_to_display($album_name);
908 djmaze 9.6 trigger_error('film_strip '.NO_IMG_TO_DISPLAY.' '.$album_name,E_USER_WARNING);
909 djmaze 9.6 }
910 djmaze 1.1 } //end display filmstrip
911 djmaze 1.1  
912 djmaze 1.1 // Prints thumbnails of pictures in an album
913 djmaze 1.1 function display_thumbnails($meta, $album, $cat, $page, $thumbcols, $thumbrows, $display_tabs)
914 djmaze 1.1 {
915 djmaze 9.6 global $CONFIG, $AUTHORIZED;
916 djmaze 9.6 global $album_date_fmt, $lang_byte_units;
917 djmaze 9.6 $thumb_per_page = $thumbcols * $thumbrows;
918 djmaze 9.6 $lower_limit = ($page-1) * $thumb_per_page;
919 djmaze 9.6 $pic_data = get_pic_data($meta, $album, $thumb_count, $album_name, $lower_limit, $thumb_per_page);
920 djmaze 9.6 $total_pages = ceil($thumb_count / $thumb_per_page);
921 djmaze 9.6 $i = 0;
922 djmaze 9.6 if (count($pic_data) > 0) {
923 djmaze 9.6 $meta_link = ($meta != '') ? '&amp;meta='.$meta : '';
924 djmaze 9.6 if (is_numeric($album)) {
925 djmaze 9.6 $alb_link = '&amp;album='.$album;
926 djmaze 9.6 } else {
927 djmaze 9.6 $alb_link = '&amp;cat='.(isset($cat) ? $cat : '0');
928 djmaze 9.6 }
929 djmaze 9.6 $thissort = isset($_GET['sort']) ? "sort=".$_GET['sort'] : "sort=".$CONFIG['default_sort_order'];
930 nanocaio 9.47 $page_link = URL::index('&amp;file=thumbnails'.$alb_link.$meta_link."&amp;page=%d&amp;$thissort");
931 djmaze 9.6 foreach ($pic_data as $key => $row) {
932 djmaze 9.6 $i++;
933 djmaze 9.6 $image_size = compute_img_size($row['pwidth'], $row['pheight'], $CONFIG['thumb_width']);
934 djmaze 9.6 if ($CONFIG['seo_alts'] == 0) {
935 djmaze 9.6 $pic_title = FILENAME . $row['filename'] . "\n" . FILESIZE . ($row['filesize'] >> 10) . $lang_byte_units[1] . "\n" . DIMENSIONS . $row['pwidth'] . "x" . $row['pheight'] . "\n" . DATE_ADDED . localised_date($row['ctime'], $album_date_fmt);
936 djmaze 9.6 } else {
937 djmaze 9.6 if ($row['title'] != '') {
938 djmaze 9.6 $pic_title = $row['title'];
939 djmaze 9.6 if ($row['keywords'] != '') {
940 djmaze 9.6 $pic_title .= "\n";
941 djmaze 9.6 $pic_title .= $row['keywords'];
942 djmaze 10.1 }
943 djmaze 9.6 } elseif ($row['keywords'] != '') {
944 djmaze 9.6 $pic_title = $row['keywords'];
945 djmaze 9.6 } else {
946 djmaze 9.6 $pic_title = substr($row['filename'], 0, -4);
947 djmaze 10.1 }
948 djmaze 10.1 }
949 djmaze 9.6 if ($meta == 'random') {
950 djmaze 9.6 $thumb_list[$i]['pos'] = $row['pid'];
951 djmaze 9.6 } else {
952 djmaze 9.6 $thumb_list[$i]['pos'] = $key < 0 ? $key : $i - 1 + $lower_limit;
953 djmaze 9.6 }
954 djmaze 9.6 if ($CONFIG['seo_alts'] == 0) {
955 djmaze 9.6 $thumb_list[$i]['image'] = "<img src=\"" . get_pic_url($row, 'thumb') . "\" class=\"image\" {$image_size['geom']} border=\"0\" alt=\"{$row['filename']}\" title=\"$pic_title\" />";
956 djmaze 9.6 } else {
957 djmaze 9.6 $thumb_list[$i]['image'] = "<img src=\"" . get_pic_url($row, 'thumb') . "\" class=\"image\" {$image_size['geom']} border=\"0\" alt=\"$pic_title\" title=\"$pic_title\" />";
958 djmaze 10.1 }
959 djmaze 9.6 $thumb_list[$i]['caption'] = isset($row['caption_text']) ? $row['caption_text'] : '';
960 djmaze 9.6 $thumb_list[$i]['pid'] = $row['pid'];
961 djmaze 9.6 $thumb_list[$i]['admin_menu'] = '';
962 nanocaio 9.32 //$th_search = isset($_POST['search']) ? $_POST['search'] : '';
963 nanocaio 9.32 //$th_search = isset($_GET['search']) ? $_GET['search']: $th_search;
964 nanocaio 9.32 //$srh = isset($_GET['meta']) && $_GET['meta'] == 'search' ? "&amp;search=$th_search" : '';
965 djmaze 10.1  
966 nanocaio 9.47 $thumb_list[$i]['url'] = URL::index("&amp;file=displayimage$meta_link$alb_link&amp;pos=".$thumb_list[$i]['pos']/*.$srh*/);
967 akamu 9.25 }
968 djmaze 9.6 theme_display_thumbnails($thumb_list, $thumb_count, $album_name, $page_link, $page, $total_pages, is_numeric($album), $display_tabs);
969 djmaze 9.6 } else {
970 djmaze 9.6 if (isset($_GET['meta'])){
971 djmaze 9.6 theme_no_img_to_display($album_name);
972 djmaze 9.6 }else{
973 djmaze 9.6 trigger_error($album_name.' '.NO_IMG_TO_DISPLAY,E_USER_NOTICE);
974 djmaze 9.6 }
975 djmaze 9.6 }
976 djmaze 10.1 }
977 djmaze 1.1  
978 djmaze 1.1 // Return the url for a picture, allows to have pictures spreaded over multiple servers
979 djmaze 1.1 function get_pic_url(&$pic_row, $mode)
980 djmaze 1.1 {
981 djmaze 9.6 global $CONFIG;
982 djmaze 9.6 static $pic_prefix = array();
983 djmaze 9.6 static $url_prefix = array();
984 djmaze 9.6 if (!count($pic_prefix)) {
985 djmaze 9.6 $pic_prefix = array('thumb' => $CONFIG['thumb_pfx'],
986 djmaze 9.6 'normal' => $CONFIG['normal_pfx'],
987 djmaze 9.6 'fullsize' => ''
988 djmaze 9.6 );
989 djmaze 9.6 $url_prefix = array(0 => $CONFIG['fullpath']);
990 djmaze 10.1 }
991 djmaze 9.6 return path2url($pic_row['filepath'] . $pic_prefix[$mode] . $pic_row['filename']);
992 djmaze 10.1 }
993 djmaze 1.1  
994 djmaze 1.1 function print_debug()
995 djmaze 1.1 {
996 djmaze 9.9 global $CPG_URL, $CPG_M_DIR, $CPG_SESS;
997 djmaze 9.6 global $USER, $CONFIG, $first_install_M_DIR,$THEME_DIR,$CLASS;
998 djmaze 9.9 echo '<br />';
999 djmaze 9.6 if ($CONFIG['debug_mode'] AND USER_IS_ADMIN && (!$CLASS['member']->demo)) {
1000 djmaze 9.6 OpenTable();
1001 djmaze 9.18 echo '<table width="100%">
1002 djmaze 9.18 <caption>Debug Information</caption>
1003 djmaze 9.18 <tr><td class="tableh1" colspan="2"><span class="statlink"><b>Integration vars</b></span></td></tr>
1004 djmaze 9.18 <tr><td>Selected CMS Theme:</td><td>'.$CPG_SESS['theme'].'</td></tr>
1005 djmaze 9.18 <tr class="code"><td>Coppermine Theme:</td><td>'.$THEME_DIR.'</td></tr>
1006 djmaze 9.18 <tr><td>Module path</td><td>'.$CPG_M_DIR.'</td></tr>
1007 djmaze 9.18 <tr class="code"><td>Nukelink</td><td>'.$CPG_URL.'</td></tr>
1008 djmaze 9.18 <tr><td class="tableh1" colspan="2"><span class="statlink"><b>$_SERVER vars</b></span></td></tr>
1009 djmaze 9.18 <tr><td>DOCUMENT_ROOT:</td><td>'.$_SERVER['DOCUMENT_ROOT'].'</td></tr>
1010 djmaze 9.18 <tr class="code"><td>';
1011 djmaze 9.6 if (isset($_SERVER['HTTP_ACCEPT_CHARSET'])) {
1012 djmaze 9.18 echo 'HTTP_ACCEPT_CHARSET:</td><td>'.$_SERVER['HTTP_ACCEPT_CHARSET'].'</td></tr>
1013 djmaze 9.18 <tr><td>';
1014 djmaze 9.18 }
1015 djmaze 9.18 print 'HTTP_ACCEPT_LANGUAGE:</td><td>'.$_SERVER['HTTP_ACCEPT_LANGUAGE'].'</td></tr>
1016 djmaze 9.18 <tr class="code"><td>HTTP_USER_AGENT:</td><td>'.$_SERVER['HTTP_USER_AGENT'].'</td></tr>
1017 djmaze 9.18 <tr><td>SCRIPT_FILENAME:</td><td>'.$_SERVER['SCRIPT_FILENAME'].'</td></tr>
1018 djmaze 9.18 <tr class="code"><td></td></tr>
1019 djmaze 9.18 <tr><td>QUERY_STRING:</td><td>'.str_replace('&', '&amp;', $_SERVER['QUERY_STRING']).'</td></tr>
1020 djmaze 9.18 <tr class="code"><td>PHP_SELF:</td><td>'.$_SERVER['PHP_SELF'].'</td></tr>
1021 djmaze 9.18 <tr><td class="tableh1" colspan="2"><span class="statlink"><b>CPG Config</b></span></td></tr>
1022 djmaze 9.18 <tr><td>TABLE_PICTURES</td><td>'.$CONFIG['TABLE_PICTURES'].'</td></tr>
1023 djmaze 9.18 <tr class="code"><td>TABLE_ALBUMS</td><td>'.$CONFIG['TABLE_ALBUMS'].'</td></tr>
1024 djmaze 9.18 <tr><td>TABLE_COMMENTS</td><td>'.$CONFIG['TABLE_COMMENTS'].'</td></tr>
1025 djmaze 9.18 <tr class="code"><td>TABLE_CATEGORIES</td><td>'.$CONFIG['TABLE_CATEGORIES'].'</td></tr>
1026 djmaze 9.18 <tr><td>TABLE_CONFIG</td><td>'.$CONFIG['TABLE_CONFIG'].'</td></tr>
1027 djmaze 9.18 <tr class="code"><td>TABLE_USERGROUPS</td><td>'.$CONFIG['TABLE_USERGROUPS'].'</td></tr>
1028 djmaze 9.18 <tr><td>TABLE_VOTES</td><td>'.$CONFIG['TABLE_VOTES'].'</td></tr>
1029 djmaze 9.18 <tr class="code"><td>TABLE_USERS</td><td>' . $CONFIG['TABLE_USERS'].'</td></tr>
1030 djmaze 9.18 <tr><td>allow_private_albums</td><td>' . $CONFIG['allow_private_albums'].'</td></tr>
1031 djmaze 9.18 <tr class="code"><td>Site url (ecards_more_pic_target)</td><td>' . $CONFIG['ecards_more_pic_target'].'</td></tr>
1032 djmaze 9.18 <tr><td>fullpath</td><td>' . $CONFIG['fullpath'].'</td></tr>
1033 djmaze 9.18 <tr class="code"><td>USER_IN_GROUPS</td><td>' . USER_IN_GROUPS.'</td></tr>
1034 djmaze 9.18 <tr><td>Default Language</td><td>' . $CONFIG['lang'].'</td></tr>
1035 djmaze 9.18 <tr class="code"><td>Language Directory</td><td>' . $first_install_M_DIR.'</td></tr>
1036 djmaze 9.18 <tr><td class="tableh1" colspan="2"><span class="statlink"><b>Queries</b></span></td></tr>
1037 djmaze 9.18 <tr><td valign="top">GET</td><td><pre>'.var_export($_GET, true).'</pre></td></tr>
1038 djmaze 9.18 <tr class="code"><td valign="top">POST</td><td><pre>'.var_export($_POST, true).'</pre></td></tr>
1039 djmaze 9.18 </table>';
1040 djmaze 9.6 CloseTable();
1041 djmaze 9.6 }
1042 djmaze 10.1 }
1043 djmaze 1.1  
1044 djmaze 1.1 function speedup_pictures()
1045 djmaze 1.1 {
1046 djmaze 9.6 global $db, $CONFIG;
1047 djmaze 9.6 // Speed-up the random image query by 'keying' the image table
1048 djmaze 9.36 $result = $db->sql_query("SELECT count(*) FROM {$CONFIG['TABLE_PICTURES']}");
1049 djmaze 9.6 $nbEnr = $db->sql_fetchrow($result);
1050 djmaze 9.6 $db->sql_freeresult($result);
1051 djmaze 9.6 $pic_count = $nbEnr[0];
1052 djmaze 9.6 $granularity = floor($pic_count / RANDPOS_MAX_PIC);
1053 djmaze 9.6 if ($granularity != $CONFIG['randpos_interval'] && $pic_count > RANDPOS_MAX_PIC) {
1054 djmaze 9.36 $result = $db->sql_query("UPDATE {$CONFIG['TABLE_PICTURES']} SET randpos = ROUND(RAND()*$granularity)");
1055 djmaze 9.36 $result = $db->sql_query("UPDATE {$CONFIG['TABLE_CONFIG']} SET value = '$granularity' WHERE name = 'randpos_interval'");
1056 djmaze 9.6 }
1057 djmaze 1.1 }
1058 nanocaio 9.39 function init_cpg_count() {
1059 nanocaio 9.39 global $db, $CONFIG;
1060 nanocaio 9.39 static $data;
1061 nanocaio 9.39 if (!is_array($data)) {
1062 nanocaio 9.39 $result = $db->sql_ufetchrowset("
1063 djmaze 10.1 SELECT
1064 nanocaio 9.39 COUNT(*) as pic_count,
1065 nanocaio 9.39 a.aid,
1066 nanocaio 9.39 a.category,
1067 nanocaio 9.39 c.parent
1068 djmaze 10.1 FROM {$CONFIG['TABLE_PICTURES']} p
1069 djmaze 10.1 LEFT JOIN
1070 djmaze 10.1 {$CONFIG['TABLE_ALBUMS']} a
1071 nanocaio 9.39 ON (p.aid=a.aid)
1072 djmaze 10.1 LEFT JOIN
1073 nanocaio 9.39 {$CONFIG['TABLE_CATEGORIES']} c
1074 nanocaio 9.39 ON (c.cid=a.category)
1075 nanocaio 9.39 WHERE a.category < ".FIRST_USER_CAT."
1076 djmaze 10.1 GROUP by
1077 nanocaio 9.39 a.category,
1078 nanocaio 9.50 a.aid,
1079 nanocaio 9.50 c.parent", SQL_ASSOC);
1080 nanocaio 9.39  
1081 nanocaio 9.41 $stats = $data = array();
1082 nanocaio 9.41 if (count($result)) {
1083 nanocaio 9.41 foreach ($result as $row) {
1084 nanocaio 9.41 //assign parent 0 to albums assigned to the categery 0 (root)
1085 nanocaio 9.41 $stats[$row['category']]['parent'] = empty($row['parent']) ? 0 : $row['parent'];
1086 nanocaio 9.41 $stats[$row['category']]['category'] = $row['category'];
1087 nanocaio 9.41 //move pictures count from albums to their category
1088 nanocaio 9.41 $stats[$row['category']]['album_count'] = !empty($stats[$row['category']]['album_count']) ? $stats[$row['category']]['album_count'] + 1 : 1;
1089 nanocaio 9.41 $stats[$row['category']]['pic_count'] = isset($stats[$row['category']]['pic_count']) ? $stats[$row['category']]['pic_count'] + $row['pic_count'] : $row['pic_count'];
1090 nanocaio 9.41 }
1091 nanocaio 9.39 }
1092 nanocaio 9.41 if (count($stats)) foreach ($stats as $row) resolve_cpg_count($stats, $data, $row['pic_count'], $row['album_count'], $row['parent'], $row['category']);
1093 nanocaio 9.39 }
1094 nanocaio 9.39 return $data;
1095 nanocaio 9.39 }
1096 nanocaio 9.39  
1097 nanocaio 9.39 function resolve_cpg_count(&$stats, &$data, $pic_count=0, $album_count=0, $parent, $cat) {
1098 nanocaio 9.39 global $db, $CONFIG;
1099 nanocaio 9.39 $data[$cat]['parent'] = $parent;
1100 nanocaio 9.39 $data[$cat]['category'] = $cat;
1101 nanocaio 9.39 $data[$cat]['album_count'] = $album_count;
1102 nanocaio 9.39 $data[$cat]['pic_count'] = $pic_count;
1103 nanocaio 9.39 if ($parent) {
1104 nanocaio 9.39 // not passed from the loop yet
1105 nanocaio 9.39 if (!isset($data[$parent])) {
1106 nanocaio 9.40 // category doesn't contains albums but have sub-category will not be included in init_cpg_count()
1107 nanocaio 9.39 // then we build the category and its data
1108 nanocaio 9.39 if (!isset($stats[$parent])) {
1109 nanocaio 9.40 foreach (get_categories_data() as $row) {
1110 nanocaio 9.40 if ($row['cid'] != $parent) continue;
1111 nanocaio 9.40 $tmp_parent = $row['parent'];
1112 nanocaio 9.40 break;
1113 nanocaio 9.40 }
1114 nanocaio 9.39 $data[$parent]['parent'] = $stats[$parent]['parent'] = $tmp_parent;
1115 nanocaio 9.39 $data[$parent]['category'] = $stats[$parent]['category'] = $parent;
1116 nanocaio 9.39 $data[$parent]['album_count'] = $stats[$parent]['album_count'] = $data[$cat]['album_count'];
1117 nanocaio 9.39 $data[$parent]['pic_count'] = $stats[$parent]['pic_count'] = $data[$cat]['pic_count'];
1118 nanocaio 9.39 } else {
1119 nanocaio 9.39 // category data is available from the query
1120 nanocaio 9.39 $data[$parent]['parent'] = $stats[$parent]['parent'];
1121 nanocaio 9.39 $data[$parent]['category'] = $stats[$parent]['category'];
1122 nanocaio 9.39 $data[$parent]['album_count'] = $album_count;
1123 nanocaio 9.39 $data[$parent]['pic_count'] = $pic_count;
1124 nanocaio 9.39 }
1125 nanocaio 9.39 } else {
1126 nanocaio 9.39 $data[$parent]['album_count'] += $album_count;
1127 nanocaio 9.39 $data[$parent]['pic_count'] += $pic_count;
1128 nanocaio 9.39 }
1129 nanocaio 9.39 //move data to the parent
1130 nanocaio 9.39 resolve_cpg_count($stats, $data, $data[$parent]['pic_count'], $data[$parent]['album_count'], $stats[$parent]['parent'], $stats[$parent]['category']);
1131 nanocaio 9.39 }
1132 nanocaio 9.39 }
1133 nanocaio 9.39  
1134 nanocaio 9.39 function get_categories_data() {
1135 nanocaio 9.39 global $db, $CONFIG;
1136 nanocaio 9.39 static $categories_data;
1137 nanocaio 9.39 if (!is_array($categories_data)) {
1138 nanocaio 9.39 $result = $db->sql_query("SELECT cid, catname, description, parent FROM {$CONFIG['TABLE_CATEGORIES']} ORDER BY pos");
1139 nanocaio 9.39 $categories_data = $db->sql_fetchrowset($result, SQL_ASSOC);
1140 nanocaio 9.39 }
1141 nanocaio 9.39 return $categories_data;
1142 djmaze 10.1 }
1143 nanocaio 9.39  
1144 nanocaio 9.39 function get_albums_data() {
1145 nanocaio 9.39 global $db, $CONFIG;
1146 nanocaio 9.39 static $albums_data;
1147 nanocaio 9.39 if (!is_array($albums_data)) {
1148 nanocaio 9.40 $result = $db->sql_query("SELECT aid, category, visibility FROM {$CONFIG['TABLE_ALBUMS']}");
1149 nanocaio 9.39 $albums_data = $db->sql_fetchrowset($result, SQL_ASSOC);
1150 nanocaio 9.41 if (!count($albums_data)) $albums_data = array();
1151 nanocaio 9.39 }
1152 nanocaio 9.39 return $albums_data;
1153 djmaze 10.1 }


Code Credits - Privacy Policy