| [ PHPXref.com ] | [ Generated: Sun Jul 20 20:57:59 2008 ] | [ vtiger Forums 1.1 ] |
| [ Index ] [ Variables ] [ Functions ] [ Classes ] [ Constants ] [ Statistics ] | ||
[Summary view] [Print] [Text view]
1 <?php 2 /*************************************************************************** 3 * slideshow.php 4 * ------------------- 5 * begin : Thu, Feb 13, 2003 6 * copyright : (C) 2003 Tom Davenport 7 * email : tomdav@yahoo.com 8 * 9 * $Id: slideshow.php,v 1.1 2005/03/31 12:32:28 isaac Exp $ 10 * 11 * 12 ***************************************************************************/ 13 14 /*************************************************************************** 15 * 16 * This program is free software; you can redistribute it and/or modify 17 * it under the terms of the GNU General Public License as published by 18 * the Free Software Foundation; either version 2 of the License, or 19 * (at your option) any later version. 20 * 21 ***************************************************************************/ 22 23 if ( !defined('IN_PHPBB') ) 24 { 25 die('Hacking attempt'); 26 exit; 27 } 28 29 while (!$thumbnail) 30 { 31 // 32 // Determine if they are viewing the slideshow, album, or random picture 33 // 34 $order = ''; 35 $ualbum = 0; 36 $malbum = 0; 37 $show_i = -1; 38 39 if ($download_id != -1) 40 { 41 $order = $HTTP_GET_VARS['order']; 42 } 43 else if ($HTTP_GET_VARS['u']) 44 { 45 $ualbum = $HTTP_GET_VARS['u']; 46 } 47 else if ($HTTP_GET_VARS['m']) 48 { 49 $malbum = $HTTP_GET_VARS['m']; 50 } 51 else 52 { 53 $show_i = -999; // none of the above so display random picture 54 } 55 56 // 57 // Ignore attachments posted in forums where user doesn't have view, read, and download status 58 // 59 $is_auth_ary = auth(AUTH_ALL, AUTH_LIST_ALL, $userdata); 60 $ignore = ''; 61 @reset($is_auth_ary); 62 while( list($key, $value) = each($is_auth_ary) ) 63 { 64 if ( !$value['auth_view'] || !$value['auth_read'] || !$value['auth_download'] ) 65 { 66 $ignore .= ( ( $ignore != '' ) ? ', ' : '' ) . $key; 67 } 68 } 69 70 if ( $ignore != '' ) 71 { 72 $ignore = "AND (t.forum_id NOT IN ($ignore)) "; 73 } 74 75 $order = ($order == 'user_id' || $ualbum) ? 'u.user_id,' : ''; 76 77 $sql = "SELECT d.width, d.height, d.border, d.attach_id, d.physical_filename, d.real_filename, d.download_count, d.comment, d.filesize, d.thumbnail, p.post_id, p.post_username, p.post_time, u.username, u.user_id, t.topic_title, t.forum_id 78 FROM " . ATTACHMENTS_TABLE . " a, " . ATTACHMENTS_DESC_TABLE . " d, " . POSTS_TABLE . " p, " . USERS_TABLE . " u, " . TOPICS_TABLE . " t 79 WHERE (d.attach_id = a.attach_id) AND (a.post_id = p.post_id) AND (p.poster_id = u.user_id) AND (p.topic_id = t.topic_id) AND (a.privmsgs_id = 0) AND (d.width > 0) $ignore 80 ORDER BY $order p.post_id, d.filetime " . ( ($attach_config['display_order'] == '0' ) ? 'DESC' : 'ASC' ); 81 82 if ( !($result = $db->sql_query($sql)) ) 83 { 84 message_die(GENERAL_ERROR, 'Could not query album or slideshow information', '', __LINE__, __FILE__, $sql); 85 } 86 87 $order = ($order != '') ? '&order=user_id' : ''; 88 89 $pics = $db->sql_fetchrowset($result); 90 $num_pics = $db->sql_numrows($result); 91 $db->sql_freeresult($result); 92 93 $next_album = $num_pics; 94 for ($i = 0; $i < $num_pics; $i++) 95 { 96 if (!$pics[$i]['comment']) 97 { 98 $pics[$i]['comment'] = $pics[$i]['real_filename']; 99 } 100 101 if ($download_id == $pics[$i]['attach_id']) 102 { 103 $show_i = $i; 104 } 105 106 $key = $pics[$i]['user_id'] + 1; 107 if (!$user[$key]) 108 { 109 $text = ($pics[$i]['user_id'] == -1) ? $lang['Guest'] : $pics[$i]['username']; 110 $user[$key] = strtolower($text) . $text; 111 if ($ualbum) 112 { 113 if ($pics[$i]['user_id'] == $ualbum) 114 { 115 $show_i = $i; 116 } 117 else if ($show_i > -1 && $next_album == $num_pics) 118 { 119 $next_album = $i; 120 } 121 } 122 } 123 124 $key = create_date('ny', $pics[$i]['post_time'], $board_config['board_timezone']); 125 if (!$month[$key]) 126 { 127 $month[$key] = create_date('ymM Y', $pics[$i]['post_time'], $board_config['board_timezone']); 128 if ($malbum) 129 { 130 if ($key == $malbum) 131 { 132 $show_i = $i; 133 } 134 else if ($show_i > -1 && $next_album == $num_pics) 135 { 136 $next_album = $i; 137 } 138 } 139 } 140 } 141 142 if ($num_pics == 0 || $show_i == -1) // no pics, not in slideshow or not a valid album so get outta here 143 { 144 break; 145 } 146 147 srand((double)microtime()*1000000); 148 149 if ($show_i == -999) // display random picture 150 { 151 $show_i = rand(1, $num_pics) - 1; 152 } 153 154 $this = $pics[$show_i]; 155 156 $rand_id = $pics[rand(1, $num_pics) - 1]['attach_id']; 157 158 $uoptions = ''; 159 $u = array( ($malbum) ? -999 : $this['user_id'] ); 160 asort ($user); 161 @reset ($user); 162 while (list($key, $text) = each($user)) 163 { 164 $key = $key - 1; 165 $u[] = $key; 166 $text = substr($text, strlen($text) / 2); 167 if ($key == $u[0]) 168 { 169 if ($ualbum) 170 { 171 $page_title = $text . ' ' . $lang['Pics']; 172 } 173 else 174 { 175 $text = $this['username']; 176 } 177 $key .= '" selected="selected'; $uselected = count($u) - 1; 178 } 179 $uoptions .= '<option value="' . $key . '">' . $text . '</option>'; 180 } 181 $u[0] = $u[count($u) - 1]; 182 $u[] = $u[1]; 183 if ($malbum) 184 { 185 $uoptions = '<option value="0" selected="selected">' . $lang['By_username'] . '</option>' . $uoptions; 186 } 187 188 $moptions = ''; 189 $m = array( ($ualbum) ? -999 : create_date('ny', $this['post_time'], $board_config['board_timezone']) ); 190 asort($month); 191 @reset($month); 192 while (list($key, $text) = each($month)) 193 { 194 $m[] = $key; 195 $text = substr($text, 4); 196 if ($key == $m[0]) 197 { 198 $page_title = ($malbum) ? $text . ' ' . $lang['Pics'] : $this['comment']; 199 $key .= '" selected="selected'; 200 $mselected = count($m) - 1; 201 } 202 $moptions .= '<option value="' . $key . '">' . $text . '</option>'; 203 } 204 $m[0] = $m[count($m) - 1]; 205 $m[] = $m[1]; 206 if ($ualbum) 207 { 208 $moptions .= '<option value="0" selected="selected">' . $lang['By_month'] . '</option>'; 209 } 210 211 $hidden_sid = (append_sid('')) ? '<input type="hidden" name="sid" value="' . $userdata['session_id'] . '" />' : ''; 212 213 if ($ualbum || $malbum) // display album 214 { 215 include($phpbb_root_path . 'includes/page_header.'.$phpEx); 216 217 $template->set_filenames(array( 218 'album_body' => 'album.tpl') 219 ); 220 221 $template->assign_vars(array( 222 'U_RAND_DOWNLOAD' => append_sid($phpbb_root_path . 'download.' . $phpEx . '?id=' . $rand_id), 223 'L_PICS' => $lang['Pics'], 224 'L_OR' => $lang['Or'], 225 'U_DOWNLOAD' => append_sid($phpbb_root_path . 'download.' . $phpEx), 226 'UOPTIONS' => $uoptions, 227 'MOPTIONS' => $moptions, 228 'HIDDEN_SID' => $hidden_sid, 229 'MINI_SEARCH_IMG' => $images['icon_mini_search'], 230 231 'U_PREV' => append_sid($phpbb_root_path . 'download.' . $phpEx . '?' . ( ($ualbum) ? 'u=' . $u[$uselected - 1] : 'm=' . $m[$mselected - 1] )), 232 'U_NEXT' => append_sid($phpbb_root_path . 'download.' . $phpEx . '?' . ( ($ualbum) ? 'u=' . $u[$uselected + 1] : 'm=' . $m[$mselected + 1] )), 233 'L_PREV' => $lang['Previous'], 234 'L_NEXT' => ( ($uselected) ? $lang['Next_user'] : $lang['Next_month'] ), 235 'U_POSTER_PROFILE' => append_sid($phpbb_root_path . 'profile.' . $phpEx . '?mode=viewprofile&' . POST_USERS_URL . '=' . $this['user_id']), 236 'L_VIEW_PROFILE' => $lang['View_profile'], 237 'L_KILOBYTE' => $lang['KB']) 238 ); 239 240 if ($ualbum && $this['user_id'] != -1) 241 { 242 $template->assign_block_vars('switch_poster_profile', array()); 243 } 244 245 for ($i = $show_i; $i < $next_album; $i++) 246 { 247 $this = $pics[$i]; 248 $this['thumbnail'] = $upload_dir . '/' . ( ($this['thumbnail']) ? THUMB_DIR . '/t_' : '' ) . $this['physical_filename']; 249 $size = get_img_size_format($this['width'], $this['height']); 250 $this['thumbnail'] = $this['thumbnail'] . '" width="' . $size[0] . '" height="' . $size[1]; 251 252 $template->assign_block_vars('thumb', array( 253 'POSTER_NAME' => $this['username'], 254 'TOPIC_TITLE' => str_replace('"', """, strip_tags($this['topic_title'])), 255 'COMMENT' => $this['comment'], 256 'FILESIZE' => round($this['filesize'] / 1024, 0), 257 'U_DOWNLOAD' => append_sid($phpbb_root_path . 'download.' . $phpEx . '?id=' . $this['attach_id'] . $order), 258 'U_THUMB' => $this['thumbnail']) 259 ); 260 } 261 262 $template->pparse('album_body'); 263 264 include($phpbb_root_path . 'includes/page_tail.'.$phpEx); 265 } 266 else // display picture 267 { 268 $prev = ($show_i == 0) ? $pics[$num_pics - 1] : $pics[$show_i - 1]; 269 $next = ($show_i + 1 == $num_pics) ? $pics[0] : $pics[$show_i + 1]; 270 while (($next['attach_id'] == $rand_id || $prev['attach_id'] == $rand_id || $this['attach_id'] == $rand_id) && $num_pics > 3) 271 { 272 $rand_id = $pics[rand(1, $num_pics) - 1]['attach_id']; 273 } 274 275 $prev_id_direction = $prev['attach_id'] . '-'; 276 $next_id_direction = $next['attach_id'] . '_'; 277 $rand_id_direction = $rand_id . '*'; 278 279 $slideshow_value = ''; 280 if ( $x = substr($HTTP_GET_VARS['id'], strlen($download_id)) ) 281 { 282 $secs = intval(substr($x, 1)); 283 if ($secs <= 0) 284 { 285 $x = ''; 286 } 287 else 288 { 289 $text = substr($x, 0, 1); // first character indicates direction 290 $text = (strpos($prev_id_direction, $text)) ? $prev_id_direction : ( (strpos($rand_id_direction, $text)) ? $rand_id_direction : $next_id_direction ); 291 $x = substr(stristr($x, 'x'), 0, 1); 292 $slideshow_value = substr($text, -1) . $secs . $x; 293 } 294 if ($x == 'X') // uppercase X => browser not javascript 1.2 enabled so use meta refresh 295 { 296 $template->assign_vars(array("META" => '<meta http-equiv="refresh" content="' . $secs . ';url=' . append_sid("download.$phpEx?id=" . $text . $secs . $x . $order) . '">')); 297 $slideshow_value = 'meta'; 298 } 299 } 300 301 // 302 // update the download count or border 303 // 304 $auth_edit = ( ($userdata['user_id'] == $this['user_id'] && $is_auth_ary[$this['forum_id']]['auth_edit'] ) || $is_auth_ary[$this['forum_id']]['auth_mod'] ); 305 if ($auth_edit && isset($HTTP_GET_VARS['b'])) 306 { 307 $this['border'] = intval($HTTP_GET_VARS['b']); 308 $sql = "UPDATE " . ATTACHMENTS_DESC_TABLE . " 309 SET border = " . $this['border'] . " 310 WHERE attach_id = " . $this['attach_id']; 311 if ( !($db->sql_query($sql)) ) 312 { 313 message_die(GENERAL_ERROR, 'Couldn\'t update attachment border', '', __LINE__, __FILE__, $sql); 314 } 315 } 316 else if (!strpos($HTTP_GET_VARS['id'], '_X')) // don't update count when stopping meta slideshow or modifying border 317 { 318 $this['download_count'] += 1; 319 $sql = "UPDATE " . ATTACHMENTS_DESC_TABLE . " 320 SET download_count = download_count + 1 321 WHERE attach_id = " . $this['attach_id']; 322 if ( !($db->sql_query($sql)) ) 323 { 324 message_die(GENERAL_ERROR, 'Couldn\'t update attachment download count', '', __LINE__, __FILE__, $sql); 325 } 326 } 327 328 // 329 // display option to edit post or modify border if authorized 330 // 331 if ($auth_edit) 332 { 333 $auth_edit = ' | <a class="slideshow" href="' . append_sid("download.$phpEx?id=" . $this['attach_id'] . $order) . '&b=' . abs($this['border'] - 1) . '">' . ( ($this['border'] == 1) ? $lang['Remove_border'] : $lang['Add_border'] ) . '</a>'; 334 $auth_edit .= ' | <a class="slideshow" href="' . append_sid("posting.$phpEx?mode=editpost&" . POST_POST_URL . "=" . $this['post_id']) . '">' . $lang['Edit_post'] . '</a>'; 335 } 336 337 // 338 // set thumbnails and image border 339 // 340 $prev['thumbnail'] = $upload_dir . '/' . ( ($prev['thumbnail']) ? THUMB_DIR . '/t_' : '' ) . $prev['physical_filename']; 341 $size = get_img_size_format($prev['width'], $prev['height']); 342 $prev['thumbnail'] = $prev['thumbnail'] . '" width="' . $size[0] . '" height="' . $size[1]; 343 344 $next['thumbnail'] = $upload_dir . '/' . ( ($next['thumbnail']) ? THUMB_DIR . '/t_' : '' ) . $next['physical_filename']; 345 $size = get_img_size_format($next['width'], $next['height']); 346 $next['thumbnail'] = $next['thumbnail'] . '" width="' . $size[0] . '" height="' . $size[1]; 347 348 $this['physical_filename'] = $upload_dir . '/' . $this['physical_filename']; 349 $this['physical_filename'] .= '" width="' . $this['width'] . '" height="' . $this['height'] . '" border="' . $this['border']; 350 351 // 352 // get post_text for post preview 353 // 354 $sql = "SELECT post_text, bbcode_uid FROM " . POSTS_TEXT_TABLE . " WHERE post_id = " . $this['post_id']; 355 if ( !($result = $db->sql_query($sql)) ) 356 { 357 message_die(GENERAL_ERROR, 'Could not query post information for slideshow', '', __LINE__, __FILE__, $sql); 358 } 359 $row = $db->sql_fetchrow($result); 360 361 // 362 // strip any html tags 363 // 364 $post_text = strip_tags($row['post_text']); 365 366 // 367 // convert url tag 368 // 369 while ($url = stristr($post_text, '[url')) 370 { 371 $text = stristr($url, '[/url]'); 372 $i = strpos($url, ']'); 373 if (!$text || $i > strlen($url) - strlen($text)) 374 { 375 break; 376 } 377 $post_text = substr($post_text, 0, -strlen($url)); 378 $url = substr($url, 0, -strlen($text)); 379 $text = substr($url, $i + 1) . '</a>' . substr($text, 6); 380 $url = ($i < 5) ? substr($url, $i + 1) : substr($url, 5, $i - 5); 381 $url = ( (strpos(substr($url, 0, 9), '://') < 3) ? 'http://' : '' ) . $url; 382 $post_text .= '<a class="slideshow" href="' . $url . '" target="_blank">' . $text; 383 } 384 385 // 386 // remove other bbcode tags 387 // 388 $post_text = preg_replace('/\[url\]|\[\/url\]/si', '', $post_text); 389 $post_text = preg_replace('/\[.*?:' . $row['bbcode_uid'] . ':?.*?\]/si', '', $post_text); 390 391 // 392 // limit preview to 2K (extend if necessary to avoid chopping link) 393 // 394 $i = 1024 * 2; 395 if (strlen($post_text) > $i) 396 { 397 $text = substr($post_text, $i); 398 if (strpos($text, '>') > strpos($text, '</a>')) 399 { 400 $i += strpos($text, '</a>') + 4; 401 } 402 $post_text = substr($post_text, 0, $i) . '... <a href="' . append_sid("viewtopic.$phpEx?" . POST_POST_URL . "=" . $this['post_id'] . "#" . $this['post_id']) . '">' . $lang['More'] . '</a>'; 403 } 404 $post_text = str_replace("\n", "<br />", $post_text); 405 406 $gen_simple_header = -1; // -1 to use slideshow_header.tpl 407 include($phpbb_root_path . 'includes/page_header.'.$phpEx); 408 409 $template->set_filenames(array( 410 'slideshow_body_and_footer' => 'slideshow.tpl') 411 ); 412 413 $template->assign_vars(array( 414 'COMMENT' => $this['comment'], 415 'L_TOPIC' => $lang['Topic'], 416 'U_POST' => append_sid("viewtopic.$phpEx?" . POST_POST_URL . "=" . $this['post_id'] . "#" . $this['post_id']), 417 'TOPIC_TITLE' => str_replace('"', """, strip_tags($this['topic_title'])), 418 'L_DOWNLOAD_COUNT' => sprintf($lang['Download_times'], $this['download_count']), 419 'FILESIZE' => round($this['filesize'] / 1024, 0), 420 'L_KILOBYTE' => $lang['KB'], 421 'U_DOWNLOAD' => append_sid("download.$phpEx"), 422 'UOPTIONS' => $uoptions, 423 'MOPTIONS' => $moptions, 424 'HIDDEN_SID' => $hidden_sid, 425 'MINI_SEARCH_IMG' => $images['icon_mini_search'], 426 427 'PREV_POSTER_NAME' => $prev['username'], 428 'PREV_TOPIC_TITLE' => str_replace('"', """, strip_tags($prev['topic_title'])),