aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWojciech Polak <polak@gnu.org>2008-03-16 17:13:15 +0000
committerWojciech Polak <polak@gnu.org>2008-03-16 17:13:15 +0000
commit9a2ce594f9ad8f40d77f8228856d673efc426b17 (patch)
treebce3c6818efbf378b282787bcc1b2073732cbbbf
parent96fbd05231bf012c840b3699dec25d5b7173e4a7 (diff)
downloadblogright-9a2ce594f9ad8f40d77f8228856d673efc426b17.tar.gz
blogright-9a2ce594f9ad8f40d77f8228856d673efc426b17.tar.bz2
version 2.2
-rw-r--r--blog.php360
-rw-r--r--config.php67
2 files changed, 238 insertions, 189 deletions
diff --git a/blog.php b/blog.php
index 23c22fb..367773b 100644
--- a/blog.php
+++ b/blog.php
@@ -1,43 +1,47 @@
1<?php 1<?php
2 2
3// blogRight! version 2.1 (2006-03-24) 3// blogRight! version 2.2 (2008-03-16)
4// Copyright (C) 2004, 2005, 2006 Wojciech Polak. 4// Copyright (C) 2004, 2005, 2006, 2007, 2008 Wojciech Polak.
5// 5//
6// This program is free software; you can redistribute it and/or modify 6// This program is free software; you can redistribute it and/or modify it
7// it under the terms of the GNU General Public License as published by 7// under the terms of the GNU General Public License as published by the
8// the Free Software Foundation; either version 2, or (at your option) 8// Free Software Foundation; either version 3 of the License, or (at your
9// any later version. 9// option) any later version.
10// 10//
11// This program is distributed in the hope that it will be useful, 11// This program is distributed in the hope that it will be useful,
12// but WITHOUT ANY WARRANTY; without even the implied warranty of 12// but WITHOUT ANY WARRANTY; without even the implied warranty of
13// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14// GNU General Public License for more details. 14// GNU General Public License for more details.
15// 15//
16// You should have received a copy of the GNU General Public License 16// You should have received a copy of the GNU General Public License along
17// along with this program; if not, write to the Free Software Foundation, 17// with this program. If not, see <http://www.gnu.org/licenses/>.
18// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18
19if (!ereg ("^apache2", @php_sapi_name ()))
20 ob_start ('ob_gzhandler');
19 21
20require 'config.php'; 22require 'config.php';
21 23
22if (!isset ($header_file)) 24if (!isset ($CONF)) exit;
23 $header_file = 'inc/header.html'; 25
26if (!isset ($CONF['path.header_file']))
27 $CONF['path.header_file'] = 'inc/header.html';
24 28
25if (!isset ($footer_file)) 29if (!isset ($CONF['path.footer_file']))
26 $footer_file = 'inc/footer.html'; 30 $CONF['path.footer_file'] = 'inc/footer.html';
27 31
28if (!isset ($charsetEncoding)) 32if (!isset ($CONF['charsetEncoding']))
29 $charsetEncoding = 'UTF-8'; 33 $CONF['charsetEncoding'] = 'UTF-8';
30 34
31///////////////////////////// 35/////////////////////////////
32 36
33$start_time = microtime (); 37$start_time = microtime ();
34 38
35if (isset ($_REQUEST['q'])) 39if (isset ($_GET['q']))
36{ 40{
37 $q = $_REQUEST['q']; 41 $q = $_GET['q'];
38 $result = array (); 42 $result = array ();
39 ereg ('([0-9]{4})?[-/]?([0-1][0-9])?[-/]?([0-3][0-9])?', $q, $result); 43 ereg ('([0-9]{4})?[-/]?([0-1][0-9])?[-/]?([0-3][0-9])?', $q, $result);
40 44
41 if (isset ($result[1]) && $result[1] != '') 45 if (isset ($result[1]) && $result[1] != '')
42 { 46 {
43 $search_y = $result[1]; 47 $search_y = $result[1];
@@ -48,31 +52,32 @@ if (isset ($_REQUEST['q']))
48 if (isset ($result[3]) && $result[3] != '') 52 if (isset ($result[3]) && $result[3] != '')
49 $search_d = $result[3] <= 31 ? $result[3] > 0 ? $result[3] : 1 : 31; 53 $search_d = $result[3] <= 31 ? $result[3] > 0 ? $result[3] : 1 : 31;
50 } 54 }
51 else 55 else
52 { 56 {
53 if (eregi ('^all$', $q)) 57 if (eregi ('^all$', $q))
54 unset ($recent); 58 unset ($CONF['recent']);
55 } 59 }
56} 60}
57 61
58///////////////////////////// 62/////////////////////////////
59 63
60if (isset ($datadir) && $datadir != '') 64if (isset ($CONF['path.data']) && $CONF['path.data'] != '')
61{ 65{
62 $cwd = $datadir; 66 $cwd = $CONF['path.data'];
63} 67}
64else 68else
65{ 69{
66 $datadir = ''; 70 $CONF['path.data'] = '';
67 $cwd = getcwd (); 71 $cwd = getcwd ();
68} 72}
69 73
70if (file_exists ($datadir.$orderfile)) 74if (isset ($CONF['orderfile']) &&
75 file_exists ($CONF['path.data'].$CONF['orderfile']))
71{ 76{
72 $lines = file ($datadir.$orderfile); 77 $lines = file ($CONF['path.data'].$CONF['orderfile']);
73 foreach ($lines as $line) 78 foreach ($lines as $line)
74 $searchdirs[] = chop ($line); 79 $searchdirs[] = chop ($line);
75 $searchdirs = array_unique ($searchdirs); 80 $searchdirs = array_unique ($searchdirs);
76} 81}
77else if (isset ($search_y)) 82else if (isset ($search_y))
78{ 83{
@@ -88,31 +93,32 @@ else // scan the directory
88 if (is_numeric ($name)) 93 if (is_numeric ($name))
89 $searchdirs[] = $name; 94 $searchdirs[] = $name;
90 } 95 }
91 closedir ($dp); 96 closedir ($dp);
92 sort ($searchdirs); 97 sort ($searchdirs);
93 98
94 if ($sortorder == 'desc') 99 if (isset ($CONF['sortorder']) &&
100 $CONF['sortorder'] == 'desc')
95 $searchdirs = array_reverse ($searchdirs); 101 $searchdirs = array_reverse ($searchdirs);
96} 102}
97 103
98///////////////////////////// 104/////////////////////////////
99 105
100$include_files = array (); 106$include_files = array ();
101 107
102foreach ($searchdirs as $dir) 108foreach ($searchdirs as $dir)
103{ 109{
104 $path = $datadir.$dir; 110 $path = $CONF['path.data'].$dir;
105 $dirlist = array (); 111 $dirlist = array ();
106 112
107 // ignore hidden files/dirs. 113 // ignore hidden files/dirs.
108 if ($dir[0] != '.' && $dir[0] != '' && is_dir ($path)) 114 if ($dir[0] != '.' && $dir[0] != '' && is_dir ($path))
109 { 115 {
110 if (file_exists ($path.'/'.$orderfile)) 116 if (file_exists ($path.'/'.$CONF['orderfile']))
111 { 117 {
112 $lines = file ($path.'/'.$orderfile); 118 $lines = file ($path.'/'.$CONF['orderfile']);
113 foreach ($lines as $line) 119 foreach ($lines as $line)
114 $dirlist[] = $path.'/'.chop ($line); 120 $dirlist[] = $path.'/'.chop ($line);
115 } 121 }
116 else // scan the directory 122 else // scan the directory
117 { 123 {
118 if (!($dp = opendir ($path))) 124 if (!($dp = opendir ($path)))
@@ -127,20 +133,20 @@ foreach ($searchdirs as $dir)
127 $dirlist[filemtime ($path.'/'.$name) . $i] = $path.'/'.$name; 133 $dirlist[filemtime ($path.'/'.$name) . $i] = $path.'/'.$name;
128 $i++; 134 $i++;
129 } 135 }
130 } 136 }
131 closedir ($dp); 137 closedir ($dp);
132 138
133 if ($sortby == 'timestamp') 139 if ($CONF['sortby'] == 'timestamp')
134 ksort ($dirlist); 140 ksort ($dirlist);
135 else // sort by name 141 else // sort by name
136 sort ($dirlist); 142 sort ($dirlist);
137 } 143 }
138 } 144 }
139 145
140 if ($sortorder == 'desc' && !isset ($search_y)) 146 if ($CONF['sortorder'] == 'desc' && !isset ($search_y))
141 $dirlist = array_reverse ($dirlist); 147 $dirlist = array_reverse ($dirlist);
142 148
143 $include_files = array_merge ($include_files, $dirlist); 149 $include_files = array_merge ($include_files, $dirlist);
144 } 150 }
145} 151}
146 152
@@ -148,43 +154,49 @@ foreach ($searchdirs as $dir)
148 154
149$cur_y = date ('Y'); 155$cur_y = date ('Y');
150$cur_m = date ('m'); 156$cur_m = date ('m');
151 157
152function cmonth ($var) 158function cmonth ($var)
153{ 159{
154 global $cur_y, $cur_m, $suffix; 160 global $cur_y, $cur_m;
155 if (ereg ("$cur_y/$cur_m-.*$suffix\$", $var)) 161 if (ereg ("$cur_y/$cur_m-.*\.html\$", $var))
156 return true; 162 return true;
157 else 163 else
158 return false; 164 return false;
159} 165}
160 166
161if (isset ($ATOM) || isset ($_REQUEST['atom']) || 167if (isset ($_GET['format'])) {
162 isset ($RSS) || isset ($_REQUEST['rss'])) { 168 if ($_GET['format'] == 'atom')
163 $recent = $feedRecent; 169 $ATOM = true;
170 else if ($_GET['format'] == 'rss')
171 $RSS = true;
172}
173
174if (isset ($ATOM) || isset ($RSS)) {
175 $CONF['recent'] = $CONF['feed.recent'];
164} 176}
165 177
166// show only N recent entries or current month 178// show only N recent entries or current month
167if (!isset ($search_y) && isset ($recent)) 179if (!isset ($search_y) && isset ($CONF['recent']))
168{ 180{
169 if (is_numeric ($recent)) 181 if (is_numeric ($CONF['recent']))
170 { 182 {
171 $include_files = array_slice ($include_files, 0, $recent); 183 $include_files = array_slice ($include_files, 0, $CONF['recent']);
172 } 184 }
173<