source: trunk/plogger.php @ 612

Revision 612, 5.9 KB checked in by sidtheduck, 6 months ago (diff)
  • Fix for auto-truncation forcing default view on valid (yet emtpy) collections or albums.
Line 
1<?php
2global $config, $thumbnail_config;
3
4include_once(dirname(__FILE__).'/plog-load-config.php');
5
6if (!empty($_POST['comment_post_ID'])) {
7        // Backward compatibility for SVN themes
8        include_once(PLOGGER_DIR.'plog-comment.php');
9        exit();
10}
11
12// Process path here - is set if mod_rewrite is in use
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
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        }
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                }
28                if (isset($resolved_path['plog_page'])) {
29                        $_GET['plog_page'] = $resolved_path['plog_page'];
30                }
31                if (isset($resolved_path['mode'])) {
32                        $_GET['mode'] = $resolved_path['mode'];
33                }
34                if (isset($resolved_path['searchterms'])) {
35                        $_REQUEST['searchterms'] = $resolved_path['searchterms'];
36                }
37
38                // Get the path for RSS links (maybe should rework this)
39                $parts = parse_url($_SERVER['REQUEST_URI']);
40                $path = $parts['path'];
41        }
42} else {
43        // Check for additional $_GET query arguments (non-Plogger)
44        $query_args = array();
45        $query_parts = array();
46        $parts = parse_url($_SERVER['REQUEST_URI']);
47        if (isset($parts['query'])) {
48                parse_str($parts['query'], $query_parts);
49        }
50        $plogger_args = array('level', 'id', 'mode', 'plog_page', 'searchterms', 'sortby', 'sortdir');
51        $url_args = array_keys($query_parts);
52        $diff_args = array_diff($url_args, $plogger_args);
53        foreach ($diff_args as $diff) {
54                $query_args[] = $diff.'='.$query_parts[$diff];
55        }
56        if (!empty($query_args)) {
57                $config['query_args'] = implode('&amp;', $query_args);
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
71// $level = 'collection', 'album', or 'picture'
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
75// Use Plogger-specific variables to avoid name clashes if Plogger is embedded
76
77$GLOBALS['plogger_level'] = isset($_GET['level']) ? $_GET['level'] : 'collections';
78$GLOBALS['plogger_id'] = isset($_GET['id']) ? intval($_GET['id']) : 0;
79$GLOBALS['plogger_mode'] = isset($_GET['mode']) ? $_GET['mode'] : '';
80
81$allowed_levels = array('collections', 'collection', 'album', 'picture', 'search', '404');
82if (!in_array($GLOBALS['plogger_level'], $allowed_levels)) {
83        $GLOBALS['plogger_level'] = 'collections';
84}
85
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') {
97                        $GLOBALS['plogger_level'] = 'album';
98                        $GLOBALS['plogger_id'] = $active['albums'][0];
99                }
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') {
106                        $GLOBALS['plogger_level'] = 'collection';
107                        $GLOBALS['plogger_id'] = $active['collections'][0];
108                }
109        }
110}
111
112define('THEME_DIR', PLOGGER_DIR.'plog-content/themes/'.$config['theme_dir']);
113define('THEME_URL', $config['theme_url']);
114
115// Initialize Plogger
116plogger_init();
117
118// Throw 404 headers if a 404 error has occurred
119if ($GLOBALS['plogger_level'] == '404' && !headers_sent()) {
120        header( 'Status: 404 Not Found' );
121        header($_SERVER['SERVER_PROTOCOL'].' 404 Not Found');
122}
123
124function the_plogger_head() {
125        plogger_head();
126
127        $use_file = 'head.php';
128        if (file_exists(THEME_DIR.'/'.$use_file)) {
129                include(THEME_DIR.'/'.$use_file);
130        } else {
131                include(PLOGGER_DIR.'plog-content/themes/default/'.$use_file);
132        }
133}
134
135function the_plogger_gallery() {
136        // Collections mode (show all albums within a collection) it's the default
137        $use_file = 'collections.php';
138        if ($GLOBALS['plogger_level'] == 'picture') {
139                $use_file = 'picture.php';
140        } elseif ($GLOBALS['plogger_level'] == 'search') {
141                if ($GLOBALS['plogger_mode'] == 'slideshow') {
142                        $use_file = 'slideshow.php';
143                } else {
144                        $use_file = 'search.php';
145                }
146        } elseif ($GLOBALS['plogger_level'] == 'album') {
147                // Album level display mode (display all pictures within album)
148                if ($GLOBALS['plogger_mode'] == 'slideshow') {
149                        $use_file = 'slideshow.php';
150                } else {
151                        $use_file = 'album.php';
152                }
153        } else if ($GLOBALS['plogger_level'] == 'collection') {
154                $use_file = 'collection.php';
155        } else if ($GLOBALS['plogger_level'] == '404') {
156                $use_file = '404.php';
157        }
158
159        // If the theme does not have the requested file, then use the one from the default template
160        if (file_exists(THEME_DIR.'/'.$use_file)) {
161                include(THEME_DIR.'/'.$use_file);
162        } else {
163                include(PLOGGER_DIR.'/plog-content/themes/default/'.$use_file);
164        }
165
166        // Close the connections
167        close_db();
168        if (function_exists('close_ftp')) {
169                close_ftp();
170        }
171
172        // Debug dump at bottom
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        }
180}
181
182?>
Note: See TracBrowser for help on using the repository browser.