root/trunk/plog-load-config.php

Revision 588, 5.9 KB (checked in by kimparsell, 3 weeks ago)

+ Minor markup changes for install/upgrade process.
+ Minor admin section changes to make action notices consistent.
+ Miscellaneous cleanup.

  • Property svn:keywords set to LastChangedDate LastChangedRevision Author Id HeadURL
Line 
1<?php
2
3/*
4
5This file will load all the configuration elements from the database
6and place them into a global associative array called $config
7
8SVN keyword tags:
9$LastChangedDate$ (Date)
10$LastChangedRevision$ (Revision)
11$LastChangedBy$ (Author)
12$HeadURL$ (URL)
13$Id$
14
15Note that SVN keywords are only propset enabled for plog-load-config.php!
16Variables enabled: LastChangedDate LastChangedRevision LastChangedBy HeadURL Id
17*/
18
19$config = array();
20$thumbnail_config = array();
21
22require_once(dirname(__FILE__)."/plog-globals.php");
23if (is_file(PLOGGER_DIR."plog-config.php")){
24    require_once(PLOGGER_DIR."plog-config.php");
25} else if (is_file(PLOGGER_DIR."plog-config-sample.php")) {
26    require_once(PLOGGER_DIR."plog-config-sample.php");
27} else {
28    die("Could not find any config file!");
29}
30require_once(PLOGGER_DIR."plog-includes/plog-functions.php");
31
32if (defined('PLOGGER_DEBUG') && PLOGGER_DEBUG == '1') {
33    $GLOBALS['query_count'] = 0;
34    $GLOBALS['queries'] = array();
35    $plog_start_time = plog_timer();
36}
37
38connect_db();
39
40$query = "SELECT * FROM `".TABLE_PREFIX."config`";
41$result = run_query($query);
42
43if (mysql_num_rows($result) == 0){
44    die("No config information in the database.");
45}
46
47$config = mysql_fetch_assoc($result);
48
49$config['basedir'] = PLOGGER_DIR;
50
51$url_parts = parse_url($_SERVER['REQUEST_URI']);
52$config['baseurl'] = "http://".$_SERVER['HTTP_HOST'].$url_parts['path'];
53
54// Try to figure out whether we are embedded (for example running from Wordpress)
55// Using $_SERVER['SCRIPT_FILENAME'] should produce the same result as __FILE__ if inclusion script in same location as Plogger
56// in some environments (virtual hosts) $_SERVER['SCRIPT_FILENAME'] is not the correct absolute path, but realpath() seems to clear it up
57if (!defined('PLOGGER_EMBEDDED') || PLOGGER_EMBEDDED=='') {
58    if (dirname(__FILE__) != dirname(realpath($_SERVER['SCRIPT_FILENAME'])) && strpos($_SERVER['SCRIPT_FILENAME'],"plog-admin") === false) {
59        $config['embedded'] = 1;
60        // disable our own cruft-free urls, because the URL has already been processed by WordPress
61        $config['use_mod_rewrite'] = 0;
62        trace('Plogger is embedded');
63        trace('dirname: ' . dirname(__FILE__));
64        trace('$_SERVER[\'SCRIPT_FILENAME\']' .': '. $_SERVER['SCRIPT_FILENAME']);
65        trace('realpath($_SERVER[\'SCRIPT_FILENAME\'])' .': '. realpath($_SERVER['SCRIPT_FILENAME']));
66    } else {
67        $config['embedded'] = 0;
68        // if mod_rewrite is on, make sure to remove the file basename
69        if ($config['use_mod_rewrite'] == 1) {
70            $config['baseurl'] = "http://".$_SERVER['HTTP_HOST']. substr($_SERVER['PHP_SELF'],0,strrpos($_SERVER['PHP_SELF'],"/")) . "/";
71        }
72    }
73} else{
74    // Set PLOGGER_EMBEDDED to 1 in config file to overrule automatic test
75    if (PLOGGER_EMBEDDED == '1') {
76        $config['embedded'] = 1;
77        $config['use_mod_rewrite'] = 0;
78        trace('Plogger is embedded');
79        // Set PLOGGER_EMBEDDED to 0 in case Plogger inclusion in different folder location, but does not already use mod_rewrite paths
80    } else {
81        $config['embedded'] = 0;
82        // if mod_rewrite is on, make sure to remove the file basename
83        if ($config['use_mod_rewrite'] == 1) {
84            $config['baseurl'] = "http://".$_SERVER['HTTP_HOST']. substr($_SERVER['PHP_SELF'],0,strrpos($_SERVER['PHP_SELF'],"/")) . "/";
85        }
86    }
87}
88
89// remove plog-admin/ from the end, if present .. is there a better way to determine the full url?
90// had to update this for new use of links without mod_rewrite turned on (only affects the View gallery greybox in Admin)
91if (strpos($config['baseurl'], 'plog-admin/')) {
92    $config['baseurl'] = substr($config['baseurl'], 0, strpos($config['baseurl'], 'plog-admin/'));
93}
94
95$config['theme_url'] = $config['gallery_url']."plog-content/themes/".basename($config['theme_dir'])."/";
96$config['charset'] = 'utf-8';
97
98// Fill $revision with latest changeset number from SVN
99$revision = '$LastChangedRevision$'; // This string is automatically changed by SVN version control
100$revision = substr($revision, strpos($revision, ' ')+1, strrpos($revision, ' ')-strpos($revision, ' ')-1);
101
102$config['version'] = 'Version 1.0Beta3, Rev ' . $revision;
103
104// charset set with HTTP headers has higher priority than that set in HTML head section
105// since some servers set their own charset for PHP files, this should take care of it
106// and hopefully doesn't break anything
107
108if (!headers_sent()){
109    header('Content-Type: text/html; charset=' . $config['charset']);
110}
111
112$query = "SELECT * FROM `".TABLE_PREFIX."thumbnail_config`";
113$result = run_query($query);
114
115if (mysql_num_rows($result) == 0){
116    die("No thumbnail config information in the database.");
117}
118
119$prefix_arr = array(1 => '', 2 => 'lrg-', 3 => 'rss-', 4 => 'tn-');
120
121while($row = mysql_fetch_assoc($result)) {
122    $thumbnail_config[$row['id']] = array(
123    'filename_prefix' => $prefix_arr[$row['id']],
124    'size' => $row['max_size'],
125    'timestamp' => $row['update_timestamp'],
126    'disabled' => $row['disabled']);
127}
128
129// need to add the new theme preview thumbnail array
130$thumbnail_config[5] = array(
131    'filename_prefix' => 'theme-',
132    'size' => 150,
133    'timestamp' => 0,
134    'disabled' => 0);
135
136// debugging functions
137function display_uservariables() {
138    foreach ($config as $keys => $values) {
139        echo "$keys = $values<br />";
140    }
141}
142
143function trace($output, $echo = true) {
144    if (defined('PLOGGER_DEBUG')) {
145        if (PLOGGER_DEBUG == '1') {
146            //echo('*'.vname($output).':'.$output.'*');
147            if ($echo === false) {
148                return '*'.$output.'*<br />';
149            } else {
150                echo '*'.$output.'*<br />';
151            }
152        }
153    }
154}
155
156function vname(&$var, $scope=false, $prefix='unique', $suffix='value') {
157    if ($scope) $vals = $scope;
158    else $vals = $GLOBALS;
159    $old = $var;
160    $var = $new = $prefix.rand().$suffix;
161    $vname = FALSE;
162    foreach($vals as $key => $val) {
163        if($val === $new) $vname = $key;
164    }
165    $var = $old;
166    return $vname;
167}
168
169if (!isset($_SESSION['plogger_sortby'])){
170    $_SESSION['plogger_sortby'] = $config['default_sortby'];
171}
172
173if (!isset($_SESSION['plogger_sortdir'])){
174    $_SESSION['plogger_sortdir'] = $config['default_sortdir'];
175}
176
177if (!isset($_SESSION['plogger_details'])){
178    $_SESSION['plogger_details'] = 0;
179
180}
181
182?>
Note: See TracBrowser for help on using the browser.