diff -r 000000000000 -r 7caf561c50ee plugins/gallery/viewimage.php --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/plugins/gallery/viewimage.php Wed Jul 25 16:36:26 2007 -0400 @@ -0,0 +1,270 @@ +attachHook('page_not_found', 'gallery_namespace_handler($this);'); + +function gallery_namespace_handler(&$page) +{ + global $db, $session, $paths, $template, $plugins; // Common objects + + if ( $page->namespace != 'Gallery' ) + return false; + + if ( $page->page_id == 'Root' ) + { + page_Special_Gallery(); + return true; + } + + if ( preg_match('/^[0-9]+$/', $page->page_id) ) + { + $img_id = intval($page->page_id); + if ( !$img_id ) + return false; + $q = $db->sql_query('SELECT img_id, img_title, img_desc, print_sizes, img_time_upload, img_time_mod, folder_parent FROM '.table_prefix.'gallery WHERE img_id=' . $img_id . ';'); + if ( !$q ) + $db->_die(); + } + else + { + // Ech... he sent us a string... parse it and see what we get + if ( strstr($page->page_id, '/') ) + { + $folders = explode('/', $page->page_id); + } + else + { + $folders = array($page->page_id); + } + foreach ( $folders as $i => $_crap ) + { + $folder =& $folders[$i]; + $folder = dirtify_page_id($folder); + $folder = str_replace('_', ' ', $folder); + } + unset($folder); + + $folders = array_reverse($folders); + // This is one of the best MySQL tricks on the market. We're going to reverse-travel a folder path using LEFT JOIN and the incredible power of metacoded SQL + $sql = 'SELECT g0.img_id, g0.img_title, g0.img_desc, g0.print_sizes, g0.img_time_upload, g0.img_time_mod, g0.folder_parent FROM '.table_prefix.'gallery AS g0'; + $where = "\n " . 'WHERE g0.img_title=\'' . $db->escape($folders[0]) . '\''; + foreach ( $folders as $i => $folder ) + { + if ( $i == 0 ) + continue; + $i_dec = $i - 1; + $folder = $db->escape($folder); + $sql .= "\n LEFT JOIN ".table_prefix."gallery AS g{$i}\n ON ( g{$i}.img_id=g{$i_dec}.folder_parent AND g{$i}.img_title='$folder' )"; + $where .= "\n ".'AND g'.$i.'.img_id IS NOT NULL'; + } + $where .= "\n AND g{$i}.folder_parent IS NULL"; + $sql .= $where . ';'; + + if ( !$db->sql_query($sql) ) + { + $db->_die('The image metadata could not be loaded.'); + } + + // Now that the folder data is no longer needed, we can fool around with it a little + $folders = $page->page_id; + if ( !strstr($folders, '/') ) + { + $hier = '/'; + } + else + { + $hier = preg_replace('/\/([^\/]+)$/', '/', $folders); + $hier = sanitize_page_id($hier); + } + + } + if ( $db->numrows() < 1 ) + { + // Image not found - show custom error message + $template->header(); + echo '
You have requested an image that couldn\'t be looked up. Please check the URL and try again, or visit the Gallery index.
'; + $template->footer(); + return false; + } + $row = $db->fetchrow(); + + $db->free_result(); + + $img_id = $row['img_id']; + + if ( !$row['folder_parent'] ) + $row['folder_parent'] = ' IS NULL'; + else + $row['folder_parent'] = '=' . $row['folder_parent']; + + // Fetch image parent properties + $q = $db->sql_query('SELECT img_id, img_title FROM '.table_prefix.'gallery WHERE folder_parent' . $row['folder_parent'] . ' AND is_folder!=1 ORDER BY img_title ASC;'); + if ( !$q ) + $db->_die(); + + $folder_total = $db->numrows(); + $folder_this = 0; + $prev = false; + $next = false; + $next_title = ''; + $prev_title = ''; + + $i = 0; + + while ( $r = $db->fetchrow() ) + { + $i++; + if ( $i == $folder_total && $r['img_id'] == $img_id ) + { + $folder_this = $i; + $next = false; + } + else if ( $i < $folder_total && $r['img_id'] == $img_id ) + { + $folder_this = $i; + $next = true; + } + else + { + if ( $next ) + { + $next = $r['img_id']; + $next_title = $r['img_title']; + break; + } + $prev = $r['img_id']; + $prev_title = $r['img_title']; + } + } + + if ( $next ) + { + $next_sanitized = sanitize_page_id($next_title); + $next_url = ( isset($hier) ) ? makeUrlNS('Gallery', $hier . $next_sanitized ) : makeUrlNS('Gallery', $next); + } + if ( $prev ) + { + $prev_sanitized = sanitize_page_id($prev_title); + $prev_url = ( isset($hier) ) ? makeUrlNS('Gallery', $hier . $prev_sanitized ) : makeUrlNS('Gallery', $prev); + } + + $db->free_result(); + + $template->tpl_strings['PAGE_NAME'] = 'Gallery image: ' . htmlspecialchars($row['img_title']); + $title_spacey = strtolower(htmlspecialchars($row['img_title'])); + + $perms = $session->fetch_page_acl(strval($img_id), 'Gallery'); + + $template->header(); + + $img_id = intval($img_id); + $bc_folders = gallery_imgid_to_folder($img_id); + $bc_folders = array_reverse($bc_folders); + $bc_url = ''; + $breadcrumbs = array(); + $breadcrumbs[] = 'Gallery index'; + + foreach ( $bc_folders as $folder ) + { + $bc_url .= '/' . dirtify_page_id($folder); + $breadcrumbs[] = '' . htmlspecialchars($folder) . ''; + } + + $breadcrumbs[] = htmlspecialchars($row['img_title']); + + // From here, this breadcrumb stuff is a piece of... sourdough French bread :-) *smacks lips* + echo ''; + + // Prev button + if ( $prev ) + echo ''; + //echo ' | '; + // if ( $prev ) + // echo 'previous image'; + + echo ' | '; + + // Image title + echo $title_spacey; + + echo ' | '; + + // Next button + if ( $next ) + // echo 'next image'; + //echo ' | '; + if ( $next ) + echo ''; + + echo ' |
' . "image $folder_this of $folder_total" . ' |
Image details | |
---|---|
Uploaded: | ' . date('F d, Y h:i a', $row['img_time_upload']) . ' |
Last modified: | ' . date('F d, Y h:i a', $row['img_time_mod']) . ' |