source: trunk/plogger.php @ 612

Revision 612, 5.9 KB checked in by sidtheduck, 7 months ago (diff)
  • Fix for auto-truncation forcing default view on valid (yet emtpy) collections or albums.
RevLine 
[550]1<?php
[602]2global $config, $thumbnail_config;
[550]3
[590]4include_once(dirname(__FILE__).'/plog-load-config.php');
[550]5
6if (!empty($_POST['comment_post_ID'])) {
[591]7        // Backward compatibility for SVN themes
[590]8        include_once(PLOGGER_DIR.'plog-comment.php');
9        exit();
[550]10}
11
[591]12// Process path here - is set if mod_rewrite is in use
[550]13if (!empty($_REQUEST['path'])) {
14        // The following line calculates the path in the album and excludes any subdirectories if
15        // Plogger is installed in one
[602]16        $path = join('/', array_diff_assoc(explode('/', $_SERVER['REQUEST_URI']), explode('/', $_SERVER['PHP_SELF'])));
17        if ($path{ strlen($path)-1} == '/') {
18                $path = substr($path, 0, -1);;
19        }
[550]20        $resolved_path = resolve_path($path);
21        if (is_array($resolved_path)) {
22                if (isset($resolved_path['level'])) {
23                        $_GET['level'] = $resolved_path['level'];
24                }
25                if (isset($resolved_path['id'])) {
26                        $_GET['id'] = $resolved_path['id'];
27                }
[563]28                if (isset($resolved_path['plog_page'])) {
29                        $_GET['plog_page'] = $resolved_path['plog_page'];
30                }
[550]31                if (isset($resolved_path['mode'])) {
32                        $_GET['mode'] = $resolved_path['mode'];
33                }
[596]34                if (isset($resolved_path['searchterms'])) {
35                        $_REQUEST['searchterms'] = $resolved_path['searchterms'];
36                }
[550]37
[591]38                // Get the path for RSS links (maybe should rework this)
[550]39                $parts = parse_url($_SERVER['REQUEST_URI']);
40                $path = $parts['path'];
41        }
42} else {
[591]43        // Check for additional $_GET query arguments (non-Plogger)
[550]44        $query_args = array();
45        $query_parts = array();
46        $parts = parse_url($_SERVER['REQUEST_URI']);
47        if (isset($parts['query'])) {
[590]48                parse_str($parts['query'], $query_parts);
[550]49        }
[590]50        $plogger_args = array('level', 'id', 'mode', 'plog_page', 'searchterms', 'sortby', 'sortdir');
[550]51        $url_args = array_keys($query_parts);
52        $diff_args = array_diff($url_args, $plogger_args);
[590]53        foreach ($diff_args as $diff) {
54                $query_args[] = $diff.'='.$query_parts[$diff];
[550]55        }
[590]56        if (!empty($query_args)) {
57                $config['query_args'] = implode('&amp;', $query_args);
[550]58        }
59}
60
61// Set sorting session variables if they are passed
62if (isset($_GET['sortby'])) {
63        $_SESSION['plogger_sortby'] = $_GET['sortby'];
64}
65
66if (isset($_GET['sortdir'])) {
67        $_SESSION['plogger_sortdir'] = $_GET['sortdir'];
68}
69
70// The three GET parameters that it accepts are
[590]71// $level = 'collection', 'album', or 'picture'
[550]72// $id = id number of collection, album, or picture
73// $n = starting element (for pagination) go from n to n + max_thumbs (in global config)
74
[591]75// Use Plogger-specific variables to avoid name clashes if Plogger is embedded
[550]76
[612]77$GLOBALS['plogger_level'] = isset($_GET['level']) ? $_GET['level'] : 'collections';
[559]78$GLOBALS['plogger_id'] = isset($_GET['id']) ? intval($_GET['id']) : 0;
79$GLOBALS['plogger_mode'] = isset($_GET['mode']) ? $_GET['mode'] : '';
[550]80
[612]81$allowed_levels = array('collections', 'collection', 'album', 'picture', 'search', '404');
82if (!in_array($GLOBALS['plogger_level'], $allowed_levels)) {
83        $GLOBALS['plogger_level'] = 'collections';
84}
[559]85
[612]86$config['truncate_breadcrumb'] = false;
87// If not at search level, check to see if we need to auto-truncate
88if ($GLOBALS['plogger_level'] != 'search') {
89        // Count collections and albums with pictures in them
90        $active = get_active_collections_albums();
91        // If only 1 active album, truncate the 'collection' & 'collections' portion of Plogger
92        if (count($active['albums']) == 1) {
93                if (!($GLOBALS['plogger_level'] == 'album' && $GLOBALS['plogger_id'] != $active['albums'][0])) {
94                        $config['truncate_breadcrumb'] = 'album';
95                }
96                if ($GLOBALS['plogger_level'] == 'collections' || $GLOBALS['plogger_level'] == 'collection') {
[590]97                        $GLOBALS['plogger_level'] = 'album';
[612]98                        $GLOBALS['plogger_id'] = $active['albums'][0];
[559]99                }
[612]100        // If only 1 active collection, truncate the 'collections' portion of Plogger
101        } else if (count($active['collections']) == 1) {
102                if (!($GLOBALS['plogger_level'] == 'collection' && $GLOBALS['plogger_id'] != $active['collections'][0])) {
103                        $config['truncate_breadcrumb'] = 'collection';
104                }
105                if ($GLOBALS['plogger_level'] == 'collections') {
[590]106                        $GLOBALS['plogger_level'] = 'collection';
[612]107                        $GLOBALS['plogger_id'] = $active['collections'][0];
[559]108                }
109        }
110}
111
[550]112define('THEME_DIR', PLOGGER_DIR.'plog-content/themes/'.$config['theme_dir']);
113define('THEME_URL', $config['theme_url']);
114
[591]115// Initialize Plogger
[568]116plogger_init();
117
[591]118// Throw 404 headers if a 404 error has occurred
[590]119if ($GLOBALS['plogger_level'] == '404' && !headers_sent()) {
120        header( 'Status: 404 Not Found' );
121        header($_SERVER['SERVER_PROTOCOL'].' 404 Not Found');
[568]122}
123
[573]124function the_plogger_head() {
[550]125        plogger_head();
126
127        $use_file = 'head.php';
[590]128        if (file_exists(THEME_DIR.'/'.$use_file)) {
129                include(THEME_DIR.'/'.$use_file);
[550]130        } else {
131                include(PLOGGER_DIR.'plog-content/themes/default/'.$use_file);
132        }
133}
134
[588]135function the_plogger_gallery() {
[591]136        // Collections mode (show all albums within a collection) it's the default
[590]137        $use_file = 'collections.php';
138        if ($GLOBALS['plogger_level'] == 'picture') {
[550]139                $use_file = 'picture.php';
[590]140        } elseif ($GLOBALS['plogger_level'] == 'search') {
141                if ($GLOBALS['plogger_mode'] == 'slideshow') {
[550]142                        $use_file = 'slideshow.php';
143                } else {
144                        $use_file = 'search.php';
145                }
[590]146        } elseif ($GLOBALS['plogger_level'] == 'album') {
[550]147                // Album level display mode (display all pictures within album)
[590]148                if ($GLOBALS['plogger_mode'] == 'slideshow') {
[550]149                        $use_file = 'slideshow.php';
150                } else {
151                        $use_file = 'album.php';
152                }
[590]153        } else if ($GLOBALS['plogger_level'] == 'collection') {
[550]154                $use_file = 'collection.php';
[590]155        } else if ($GLOBALS['plogger_level'] == '404') {
[568]156                $use_file = '404.php';
[550]157        }
158
[591]159        // If the theme does not have the requested file, then use the one from the default template
[590]160        if (file_exists(THEME_DIR.'/'.$use_file)) {
161                include(THEME_DIR.'/'.$use_file);
[550]162        } else {
163                include(PLOGGER_DIR.'/plog-content/themes/default/'.$use_file);
164        }
[591]165
166        // Close the connections
[590]167        close_db();
168        if (function_exists('close_ftp')) {
169                close_ftp();
170        }
[591]171
172        // Debug dump at bottom
[590]173        if (defined('PLOGGER_DEBUG') && PLOGGER_DEBUG == '1') {
174                trace('Queries: '.$GLOBALS['query_count']);
175                foreach ($GLOBALS['queries'] as $q) {
176                        trace($q);
177                }
178                trace(plog_timer('end'));
179        }
[550]180}
[591]181
[555]182?>
Note: See TracBrowser for help on using the repository browser.