summaryrefslogtreecommitdiffabout
authorWojciech Polak <polak@gnu.org>2008-03-16 17:13:15 (GMT)
committer Wojciech Polak <polak@gnu.org>2008-03-16 17:13:15 (GMT)
commit9a2ce594f9ad8f40d77f8228856d673efc426b17 (patch) (side-by-side diff)
treebce3c6818efbf378b282787bcc1b2073732cbbbf
parent96fbd05231bf012c840b3699dec25d5b7173e4a7 (diff)
downloadblogright-9a2ce594f9ad8f40d77f8228856d673efc426b17.tar.gz
blogright-9a2ce594f9ad8f40d77f8228856d673efc426b17.tar.bz2
version 2.2
Diffstat (more/less context) (ignore whitespace changes)
-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 @@
<?php
-// blogRight! version 2.1 (2006-03-24)
-// Copyright (C) 2004, 2005, 2006 Wojciech Polak.
+// blogRight! version 2.2 (2008-03-16)
+// Copyright (C) 2004, 2005, 2006, 2007, 2008 Wojciech Polak.
//
-// This program is free software; you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation; either version 2, or (at your option)
-// any later version.
+// This program is free software; you can redistribute it and/or modify it
+// under the terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3 of the License, or (at your
+// option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
-// You should have received a copy of the GNU General Public License
-// along with this program; if not, write to the Free Software Foundation,
-// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+// You should have received a copy of the GNU General Public License along
+// with this program. If not, see <http://www.gnu.org/licenses/>.
+
+if (!ereg ("^apache2", @php_sapi_name ()))
+ ob_start ('ob_gzhandler');
require 'config.php';
-if (!isset ($header_file))
- $header_file = 'inc/header.html';
+if (!isset ($CONF)) exit;
+
+if (!isset ($CONF['path.header_file']))
+ $CONF['path.header_file'] = 'inc/header.html';
-if (!isset ($footer_file))
- $footer_file = 'inc/footer.html';
+if (!isset ($CONF['path.footer_file']))
+ $CONF['path.footer_file'] = 'inc/footer.html';
-if (!isset ($charsetEncoding))
- $charsetEncoding = 'UTF-8';
+if (!isset ($CONF['charsetEncoding']))
+ $CONF['charsetEncoding'] = 'UTF-8';
/////////////////////////////
$start_time = microtime ();
-if (isset ($_REQUEST['q']))
+if (isset ($_GET['q']))
{
- $q = $_REQUEST['q'];
+ $q = $_GET['q'];
$result = array ();
ereg ('([0-9]{4})?[-/]?([0-1][0-9])?[-/]?([0-3][0-9])?', $q, $result);
if (isset ($result[1]) && $result[1] != '')
{
$search_y = $result[1];
@@ -48,31 +52,32 @@ if (isset ($_REQUEST['q']))
if (isset ($result[3]) && $result[3] != '')
$search_d = $result[3] <= 31 ? $result[3] > 0 ? $result[3] : 1 : 31;
}
else
{
if (eregi ('^all$', $q))
- unset ($recent);
+ unset ($CONF['recent']);
}
}
/////////////////////////////
-if (isset ($datadir) && $datadir != '')
+if (isset ($CONF['path.data']) && $CONF['path.data'] != '')
{
- $cwd = $datadir;
+ $cwd = $CONF['path.data'];
}
else
{
- $datadir = '';
+ $CONF['path.data'] = '';
$cwd = getcwd ();
}
-if (file_exists ($datadir.$orderfile))
+if (isset ($CONF['orderfile']) &&
+ file_exists ($CONF['path.data'].$CONF['orderfile']))
{
- $lines = file ($datadir.$orderfile);
+ $lines = file ($CONF['path.data'].$CONF['orderfile']);
foreach ($lines as $line)
$searchdirs[] = chop ($line);
$searchdirs = array_unique ($searchdirs);
}
else if (isset ($search_y))
{
@@ -88,31 +93,32 @@ else // scan the directory
if (is_numeric ($name))
$searchdirs[] = $name;
}
closedir ($dp);
sort ($searchdirs);
- if ($sortorder == 'desc')
+ if (isset ($CONF['sortorder']) &&
+ $CONF['sortorder'] == 'desc')
$searchdirs = array_reverse ($searchdirs);
}
/////////////////////////////
$include_files = array ();
foreach ($searchdirs as $dir)
{
- $path = $datadir.$dir;
+ $path = $CONF['path.data'].$dir;
$dirlist = array ();
// ignore hidden files/dirs.
if ($dir[0] != '.' && $dir[0] != '' && is_dir ($path))
{
- if (file_exists ($path.'/'.$orderfile))
+ if (file_exists ($path.'/'.$CONF['orderfile']))
{
- $lines = file ($path.'/'.$orderfile);
+ $lines = file ($path.'/'.$CONF['orderfile']);
foreach ($lines as $line)
$dirlist[] = $path.'/'.chop ($line);
}
else // scan the directory
{
if (!($dp = opendir ($path)))
@@ -127,20 +133,20 @@ foreach ($searchdirs as $dir)
$dirlist[filemtime ($path.'/'.$name) . $i] = $path.'/'.$name;
$i++;
}
}
closedir ($dp);
- if ($sortby == 'timestamp')
+ if ($CONF['sortby'] == 'timestamp')
ksort ($dirlist);
else // sort by name
sort ($dirlist);
}
}
- if ($sortorder == 'desc' && !isset ($search_y))
+ if ($CONF['sortorder'] == 'desc' && !isset ($search_y))
$dirlist = array_reverse ($dirlist);
$include_files = array_merge ($include_files, $dirlist);
}
}
@@ -148,43 +154,49 @@ foreach ($searchdirs as $dir)
$cur_y = date ('Y');
$cur_m = date ('m');
function cmonth ($var)
{
- global $cur_y, $cur_m, $suffix;
- if (ereg ("$cur_y/$cur_m-.*$suffix\$", $var))
+ global $cur_y, $cur_m;
+ if (ereg ("$cur_y/$cur_m-.*\.html\$", $var))
return true;
else
return false;
}
-if (isset ($ATOM) || isset ($_REQUEST['atom']) ||
- isset ($RSS) || isset ($_REQUEST['rss'])) {
- $recent = $feedRecent;
+if (isset ($_GET['format'])) {
+ if ($_GET['format'] == 'atom')
+ $ATOM = true;
+ else if ($_GET['format'] == 'rss')
+ $RSS = true;
+}
+
+if (isset ($ATOM) || isset ($RSS)) {
+ $CONF['recent'] = $CONF['feed.recent'];
}
// show only N recent entries or current month
-if (!isset ($search_y) && isset ($recent))
+if (!isset ($search_y) && isset ($CONF['recent']))
{
- if (is_numeric ($recent))
+ if (is_numeric ($CONF['recent']))
{
- $include_files = array_slice ($include_files, 0, $recent);
+ $include_files = array_slice ($include_files, 0, $CONF['recent']);
}
- else if ($recent == 'month')
+ else if ($CONF['recent'] == 'month')
{
$month_files = array_filter ($include_files, 'cmonth');
while (!count ($month_files))
{
$cur_m = sprintf ('%02d', $cur_m - 1);
if ($cur_m == '00')
{
$cur_m = 12;
$cur_y -= 1;
- if ($cur_y < 1983) // set your minimal value ;)
+ if ($cur_y < 1983)
break; // fatal error; anti-loop protection
}
$month_files = array_filter ($include_files, 'cmonth');
}
$include_files = array ();
@@ -194,15 +206,15 @@ if (!isset ($search_y) && isset ($recent))
}
/////////////////////////////
$year_array = array (); // Array of years for copyright purposes
-if (isset ($RSS) || isset ($_REQUEST['rss']))
+if (isset ($RSS))
{
- $pubDate = date ("D, d M Y H:i:s O", filemtime ($include_files[0]));
+ $pubDate = gmdate ("D, d M Y H:i:s O", filemtime ($include_files[0]));
$lastModified = gmdate ("D, d M Y H:i:s T", filemtime ($include_files[0]));
$ETag = '"'.md5 ($lastModified).'"';
$headers = getallheaders ();
if (array_key_exists ('If-Modified-Since', $headers) &&
array_key_exists ('If-None-Match', $headers))
@@ -211,34 +223,32 @@ if (isset ($RSS) || isset ($_REQUEST['rss']))
$headers['If-None-Match'] == $ETag)
{
header ('HTTP/1.1 304 Not Modified');
exit ();
}
}
- header ("Content-Type: text/xml; charset=$charsetEncoding");
+ header ("Content-Type: text/xml; charset=".$CONF['charsetEncoding']);
header ("Last-Modified: $lastModified");
header ("ETag: $ETag");
- echo '<?xml version="1.0" encoding="'.$charsetEncoding.'"?>'."\n";
- if ($feedStylesheet)
- echo "<?xml-stylesheet href=\"$site/$weblogdir/css/rss.css\" type=\"text/css\"?>\n";
+ echo '<?xml version="1.0" encoding="'.$CONF['charsetEncoding'].'"?>'."\n";
echo '<rss version="2.0">'."\n";
echo " <channel>\n";
- echo " <title>$feedTitle</title>\n";
- echo " <description>$feedDescription</description>\n";
- echo " <link>$site/$weblogdir/</link>\n";
- echo " <copyright>$feedCopyright</copyright>\n";
- echo " <language>$feedLanguage</language>\n";
+ echo " <title>".$CONF['feed.title']."</title>\n";
+ echo " <description>".$CONF['feed.description']."</description>\n";
+ echo " <link>".$CONF['url.site']."/</link>\n";
+ echo " <copyright>".$CONF['feed.copyright']."</copyright>\n";
+ echo " <language>".$CONF['feed.language']."</language>\n";
echo " <pubDate>$pubDate</pubDate>\n";
echo " <docs>http://blogs.law.harvard.edu/tech/rss</docs>\n";
echo " <generator>blogRight!</generator>\n";
- echo " <managingEditor>$feedEditor</managingEditor>\n";
+ echo " <managingEditor>".$CONF['feed.editor']."</managingEditor>\n";
foreach ($include_files as $inc)
{
- if (ereg (".*$suffix\$", basename ($inc)))
+ if (ereg (".*\.html\$", basename ($inc)))
{
$cdd = basename (dirname ($inc)); // current data dir
if (is_numeric ($cdd))
{
ereg ('^(.*)-(.*)\.', basename ($inc), $res);
$year = $cdd; // let's assume that...
@@ -254,42 +264,45 @@ if (isset ($RSS) || isset ($_REQUEST['rss']))
else {
$fmtime = filemtime ($inc);
}
$pubDate = date ("D, d M Y H:i:s O", $fmtime);
$itemTitle = date ('d M Y', $fmtime);
- $permaLink = date ('Ymd', $fmtime);
+ $permaLink = date ($CONF['permalinkFmt'], $fmtime);
echo " <item>\n";
echo " <title>$itemTitle</title>\n";
- echo " <link>$site/$weblogdir/?q=$permaLink</link>\n";
+ echo " <link>".$CONF['url.site']."/".
+ $CONF['qpattern'].$permaLink."</link>\n";
- if ($feedCDATA) {
+ if ($CONF['feed.CDATA']) {
echo " <description><![CDATA[\n";
- indent_include (9, $inc, $feedCDATA);
+ indent_include (9, $inc, $CONF['feed.CDATA']);
echo " ]]></description>\n";
}
else {
echo " <description>\n";
- indent_include (9, $inc, $feedCDATA);
+ indent_include (9, $inc, $CONF['feed.CDATA']);
echo " </description>\n";
}
- echo " <guid isPermaLink=\"true\">$site/$weblogdir/?q=$permaLink</guid>\n";
+ echo " <guid isPermaLink=\"true\">".
+ $CONF['url.site']."/".$CONF['qpattern'].
+ $permaLink."</guid>\n";
echo " <pubDate>$pubDate</pubDate>\n";
echo " </item>\n";
}
}
echo " </channel>\n";
echo "</rss>\n";
}
-else if (isset ($ATOM) || isset ($_REQUEST['atom'])) {
-
- $pubDate = date ('Y-m-d\TH:i:s\Z', filemtime ($include_files[0]));
- $lastModified = date ('Y-m-d\TH:i:s\Z', filemtime ($include_files[0]));
+else if (isset ($ATOM))
+{
+ $pubDate = gmdate ('Y-m-d\TH:i:s\Z', filemtime ($include_files[0]));
+ $lastModified = gmdate ("D, d M Y H:i:s T", filemtime ($include_files[0]));
$ETag = '"'.md5 ($lastModified).'"';
$headers = getallheaders ();
if (array_key_exists ('If-Modified-Since', $headers) &&
array_key_exists ('If-None-Match', $headers))
{
@@ -297,38 +310,37 @@ else if (isset ($ATOM) || isset ($_REQUEST['atom'])) {
$headers['If-None-Match'] == $ETag)
{
header ('HTTP/1.1 304 Not Modified');
exit ();
}
}
- header ("Content-Type: text/xml; charset=$charsetEncoding");
+ header ("Content-Type: text/xml; charset=".$CONF['charsetEncoding']);
header ("Last-Modified: $lastModified");
header ("ETag: $ETag");
- $tagUri = "tag:$feedAuthorEmail,2004:blog";
-
- echo '<?xml version="1.0" encoding="'.$charsetEncoding.'"?>'."\n";
- if ($feedStylesheet)
- echo "<?xml-stylesheet href=\"$site/$weblogdir/css/atom.css\" type=\"text/css\"?>\n";
- echo '<feed xmlns="http://www.w3.org/2005/Atom">'."\n";
- echo " <title>$feedTitle</title>\n";
- echo " <subtitle>$feedDescription</subtitle>\n";
+ echo '<?xml version="1.0" encoding="'.$CONF['charsetEncoding'].'"?>'."\n";
+ echo '<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="'.
+ $CONF['feed.language'].'">'."\n";
+ echo " <title>".$CONF['feed.title']."</title>\n";
+ echo " <subtitle>".$CONF['feed.description']."</subtitle>\n";
echo " <updated>$pubDate</updated>\n";
echo " <author>\n";
- echo " <name>$feedAuthorName</name>\n";
- echo " <email>$feedAuthorEmail</email>\n";
+ echo " <name>".$CONF['feed.authorName']."</name>\n";
+ echo " <email>".$CONF['feed.authorEmail']."</email>\n";
echo " </author>\n";
- echo " <rights>$feedCopyright</rights>\n";
+ echo " <rights>".$CONF['feed.copyright']."</rights>\n";
echo " <generator>blogRight!</generator>\n";
- echo " <id>$tagUri</id>\n";
- echo " <link rel=\"self\" type=\"application/atom+xml\" href=\"$site/$weblogdir/atom/\"/>\n";
- echo " <link rel=\"alternate\" type=\"text/html\" href=\"$site/$weblogdir/\"/>\n";
+ echo " <id>".$CONF['feed.tagUri']."</id>\n";
+ echo " <link rel=\"self\" type=\"application/atom+xml\" href=\"".
+ $CONF['url.site']."/atom/\"/>\n";
+ echo " <link rel=\"alternate\" type=\"text/html\" href=\"".
+ $CONF['url.site']."/\"/>\n";
foreach ($include_files as $inc)
{
- if (ereg (".*$suffix\$", basename ($inc)))
+ if (ereg (".*\.html\$", basename ($inc)))
{
$cdd = basename (dirname ($inc)); // current data dir
if (is_numeric ($cdd))
{
ereg ('^(.*)-(.*)\.', basename ($inc), $res);
$year = $cdd;
@@ -344,66 +356,78 @@ else if (isset ($ATOM) || isset ($_REQUEST['atom'])) {
else {
$fmtime = filemtime ($inc);
}
$pubDate = date ('Y-m-d\TH:i:s\Z', $fmtime);
$itemTitle = date ('d M Y', $fmtime);
- $permaLink = date ('Ymd', $fmtime);
+ $permaLink = date ($CONF['permalinkFmt'], $fmtime);
echo " <entry>\n";
- echo " <id>$tagUri/$permaLink</id>\n";
+ echo " <id>".$CONF['feed.tagUri']."/$permaLink</id>\n";
echo " <updated>$pubDate</updated>\n";
echo " <title>$itemTitle</title>\n";
- echo " <link rel=\"alternate\" type=\"text/html\" href=\"$site/$weblogdir/?q=$permaLink\"/>\n";
+ echo " <link rel=\"alternate\" type=\"text/html\" href=\"".
+ $CONF['url.site']."/".$CONF['qpattern'].$permaLink."\"/>\n";
- if ($feedXHTML) {
+ if ($CONF['feed.XHTML']) {
echo " <content type=\"xhtml\" xml:space=\"preserve\">\n";
echo " <div xmlns=\"http://www.w3.org/1999/xhtml\">\n";
- indent_include (6, $inc, $feedXHTML);
+ indent_include (6, $inc, $CONF['feed.XHTML']);
echo " </div>\n";
echo " </content>\n";
}
- else if ($feedCDATA) {
+ else if ($CONF['feed.CDATA']) {
echo " <content type=\"html\" xml:space=\"preserve\"><![CDATA[\n";
- indent_include (6, $inc, $feedCDATA);
+ indent_include (6, $inc, $CONF['feed.CDATA']);
echo " ]]></content>\n";
}
else {
echo " <content type=\"html\" xml:space=\"preserve\">\n";
- indent_include (6, $inc, $feedCDATA);
+ indent_include (6, $inc, $CONF['feed.CDATA']);
echo " </content>\n";
}
echo " </entry>\n";
}
}
echo '</feed>'."\n";
}
else // HTML
{
- header ("Content-Type: text/html; charset=$charsetEncoding");
- echo '<?xml version="1.0" encoding="'.$charsetEncoding.'"?>'."\n";
- @include ($datadir.$header_file);
+ echo '<?xml version="1.0" encoding="'.$CONF['charsetEncoding'].'"?>'."\n";
+
+ $title = '';
+ if (isset ($search_y)) {
+ $title = $search_y;
+ if (isset ($search_m))
+ $title .= '-'.$search_m;
+ if (isset ($search_d))
+ $title .= '-'.$search_d;
+ }
+
+ @include ($CONF['path.header_file']);
+
+ echo "\n<div id=\"content\" class=\"hfeed\">\n\n";
foreach ($include_files as $inc)
{
// the query engine...
if (isset ($search_m))
{
if (isset ($search_d))
{
- if (ereg ("^$search_m-$search_d.*$suffix\$", basename ($inc)))
+ if (ereg ("^$search_m-$search_d.*\.html\$", basename ($inc)))
include_file ($inc);
}
else
- if (ereg ("^$search_m-.*$suffix\$", basename ($inc)))
+ if (ereg ("^$search_m-.*\.html\$", basename ($inc)))
include_file ($inc);
}
else
- if (ereg (".*$suffix\$", basename ($inc)))
+ if (ereg (".*\.html\$", basename ($inc)))
include_file ($inc);
}
// Calculate a copyright footnote.
$copyrightYear = '';
if (count ($year_array))
@@ -414,13 +438,15 @@ else // HTML
$copyrightYear .= "$y, ";
$copyrightYear = substr ($copyrightYear, 0, -2);
}
else
$copyrightYear = date ('Y');
- @include ($datadir.$footer_file);
+ echo "</div>\n\n"; /* /hfeed */
+
+ @include ($CONF['path.footer_file']);
$duration = microtime_diff ($start_time, microtime ());
$duration = sprintf ("%0.6f", $duration);
echo "\n<!-- processing took $duration seconds -->";
echo "\n<!-- powered by blogRight! -->\n";
}
@@ -433,53 +459,51 @@ $global_fn = 0; // Global number of the next footnote. This is unique
// within a html page and is used for creating unique
// anchors.
// Return full url of the script
function script_url ()
{
- global $site, $weblogdir;
- if (isset($_REQUEST['q']))
- return $site.'/'.$weblogdir.'?q='.$_REQUEST['q'];
- return $site.'/'.$weblogdir.'/';
+ global $CONF;
+ if ($CONF['qpattern'] != '' && isset ($_GET['q']))
+ return $CONF['url.site'].'/'.$CONF['qpattern'].$_GET['q'];
+ return $CONF['url.site'].'/';
}
// Save away the collected footnote text and replace it by an appropriate
// link.
function footnote_handler ($matches)
{
- global $site,$global_fn,$local_fn,$footnotes;
+ global $global_fn, $local_fn, $footnotes;
$footnotes[$local_fn++] = $matches[1];
$global_fn++;
- return '<a href="'.script_url().'#footnote'.$global_fn.'" name="FNRET'.$global_fn.'"><sup>'.$local_fn.')</sup></a> ';
+ return '<a href="'.script_url ().'#footnote'.$global_fn.'" name="FNRET'.
+ $global_fn.'"><sup>'.$local_fn.')</sup></a> ';
}
// Process a single input line from the file being included.
// Returns processed line, if it is ready for output. Otherwise,
// tucks the line to the global variable $collect and returns false.
// Make sure you unset $collect before the *first* invocation of process_line()
// for the given input file.
function process_line ($line)
{
- global $site, $photodir, $imagedir, $search_d;
- global $gscript, $defaultGallery, $thumbnailPrefix;
- global $local_fn, $global_fn, $footnotes;
- global $collect;
+ global $CONF, $search_d, $local_fn, $global_fn;
+ global $footnotes, $collect;
if (isset ($collect))
{
$collect = $collect . ' ' . rtrim ($line);
if (!preg_match ('^</footnote>^', $line))
return false;
$line = $collect . "\n";
unset ($GLOBALS['collect']);
}
$line = preg_replace_callback ('^<footnote>(.*)</footnote>^',
- "footnote_handler",
- $line);
+ "footnote_handler", $line);
if (preg_match ('^<footnote>^', $line))
{
$collect = rtrim ($line);
return false;
}
@@ -487,50 +511,64 @@ function process_line ($line)
if (!preg_match ('/="(https?|ftp|mailto):\/\/.*?"/i', $line)) // a local path
{
$res = array ();
if (preg_match ('/<img src="(.*?)"(.*?)>/i', $line, $res))
{
- $line = preg_replace ('/<img src="(.*?)"(.*?)>/i',
- '<img src="'.$site.'/'.$imagedir.'/$1" alt="[image]"$2 />', $line);
+ $line = str_replace ('\"', '"',
+ preg_replace ('/<img src="(.*?)"(.*?)>/ie',
+ "str_replace(array('%IMAGE','%PARAMS'),array('\\1','\\2'),'".
+ $CONF['patternURL.img']."')", $line));
}
- else if (preg_match ('/<photo album="(.*?)" src="(.*?)"(.*?)>/i', $line, $res))
+ else if (preg_match ('/<photo album="(.*?)" src="(.*?)"(.*?)>/i',
+ $line, $res))
{
if ($res[1] == 'default')
- $res[1] = $defaultGallery;
+ $res[1] = $CONF['defaultGallery'];
$prefix = dirname (trim ($res[2]));
if ($prefix[0] == '.')
- $prefix = $thumbnailPrefix[$res[1]];
+ $prefix = $CONF['thumbnailPrefix'][$res[1]];
$photo = basename (trim ($res[2]));
+ $thumbnail = $prefix . $photo;
+ $photo = str_replace ('.jpg', '', $photo);
- $line = '<p class="photo"><a href="'.$photodir.'/'.$gscript.'?q='.$res[1].'&amp;photo='.$photo.'">'
- .'<img src="'.$site.'/'.$photodir.'/'.$prefix.$photo.'" alt="[photo]"'.$res[3].' /></a></p>';
+ $line = '<p class="photo">'.
+ str_replace (array ('%ALBUM', '%PHOTO', '%THUMBNAIL', '%PARAMS'),
+ array ($res[1], $photo, $thumbnail, $res[3]),
+ $CONF['patternURL.photos']).'</p>';
}
else if (preg_match ('/<photo src="(.*?)"(.*?)>/i', $line, $res))
{
- $line = '<p class="photo"><a href="'.$photodir.'/photo.php?q='.$res[1].'"><img src="'
- .$site.'/'.$photodir.'/'
- .$thumbnailPrefix['default'].$res[1].'" alt="[photo]"'.$res[2].' /></a></p>';
+ $line = '<p class="photo">'.
+ str_replace (array ('%PHOTO', '%THUMBNAIL', '%PARAMS'),
+ array ($res[1],
+ $CONF['thumbnailPrefix']['default'].$res[1],
+ $res[2]),
+ $CONF['patternURL.photo']).'</p>';
}
- else if (preg_match ('/<gallery album="(.*?)" img="(.*?)"(.*?)>/i', $line, $res))
+ else if (preg_match ('/<gallery album="(.*?)" img="(.*?)"(.*?)>/i',
+ $line, $res))
{
$pdir = dirname (trim ($res[2]));
if ($pdir[0] == '.')
$pdir = '';
$pbase = basename (trim ($res[2]));
-
- $line = '<p class="gallery"><a href="'.$photodir.'/'.$gscript.'?q='.$res[1].'">'
- .'<img src="'.$site.'/'.$photodir;
- if ($pdir)
- $line .= '/'.$pdir;
- $line .= '/'.$thumbnailPrefix['default'].$pbase.'" alt="[gallery]"'
- .$res[3]." /><br />&raquo;</a></p>\n";
+ $thumbnail = '';
+ if ($pdir) $thumbnail .= $pdir.'/';
+ $thumbnail .= $CONF['thumbnailPrefix']['default'].$pbase;
+
+ $line = '<p class="gallery">'.
+ str_replace (array ('%ALBUM', '%THUMBNAIL', '%PARAMS'),
+ array ($res[1], $thumbnail, $res[3]),
+ $CONF['patternURL.gallery'])."</p>\n";
}
-
- $line = preg_replace ('/<a href="(.*?)">/i', '<a href="'.$site.'/$1">', $line);
+ $line = str_replace ('\"', '"',
+ preg_replace ('/<a href="(.*?)">/ie',
+ "str_replace(array('%URI'),array('\\1'),'".
+ $CONF['patternURL.link']."')", $line));
}
return $line;
}
// Process the footnotes collected for the entry.
// Arguments:
@@ -545,13 +583,14 @@ function process_footnotes ($out, $data)
if ($local_fn > 0)
{
$out ($data, '<div class="footnote">');
for ($i = 0; $i < $local_fn; $i++)
{
$n = $global_fn-$local_fn+$i+1;
- $out ($data, '<p><a href="'.script_url().'#FNRET'.$n.'" name="footnote'.$n.'"><sup>'.($i+1).')</sup></a> ');
+ $out ($data, '<p><a href="'.script_url().'#FNRET'.
+ $n.'" name="footnote'.$n.'"><sup>'.($i+1).')</sup></a> ');
$out ($data, $footnotes[$i]);
$out ($data, '</p>');
}
$out ($data, '</div>');
}
}
@@ -564,15 +603,13 @@ function printer ($data, $string)
/////////////////////////////
// HTML output
function include_file ($file)
{
- global $site, $photodir, $imagedir, $search_d;
- global $local_fn;
- global $year_array;
+ global $CONF, $search_d, $local_fn, $year_array;
$res = array ();
$cdd = basename (dirname ($file)); // current data dir
$local_fn = 0;
if (is_numeric ($cdd))
{
@@ -585,44 +622,51 @@ function include_file ($file)
{
$month = $res[1];
$day = $res[2];
}
$entryDate = mktime (0, 0, 0, $month, $day, $year);
- $permaLink = date ('Ymd', $entryDate);
+ $permaLink = date ($CONF['permalinkFmt'], $entryDate);
+ $pubDate = date ('Y-m-d\TH:i:s\Z', $entryDate);
$entryDate = date ('d M Y', $entryDate);
}
else
{
- $permaLink = date ('Ymd', filemtime ($file));
- $entryDate = date ('d M Y', filemtime ($file));
+ $mt = filemtime ($file);
+ $permaLink = date ($CONF['permalinkFmt'], $mt);
+ $pubDate = gmdate ('Y-m-d\TH:i:s\Z', $mt);
+ $entryDate = date ('d M Y', $mt);
}
$fd = file ($file);
if ($fd)
{
- echo '<div id="e'.$permaLink.'" class="entry">'."\n";
- echo '<div class="entryTitle">';
- echo '<a href="?q='.$permaLink
+ echo '<div id="e'.str_replace ( '/','',$permaLink).'" class="hentry">'."\n";
+ echo '<div class="entry-title">';
+ echo '<a href="./'.$CONF['qpattern'].$permaLink
.'" rel="bookmark" title="'.$entryDate.'">'.$entryDate.'</a>';
echo '</div>'."\n";
- echo '<div class="entryBody">'."\n";
+ echo '<div class="entry-content">'."\n";
unset ($GLOBALS['collect']);
foreach ($fd as $line)
{
$line = process_line ($line);
if ($line)
echo ($line);
}
process_footnotes ('printer', 0);
echo '</div>'."\n";
- echo '<div class="entryFooter">'."\n";
- echo '<a href="?q='.$permaLink.'" rel="bookmark" title="'.$entryDate.
- '" class="permalink">'.$entryDate.'</a>'."\n";
+ echo '<div class="entry-footer">'."\n";
+ echo '<a href="./'.$CONF['qpattern'].
+ $permaLink.'" rel="bookmark" title="'.$entryDate.
+ '"><abbr class="published" title="'.
+ $pubDate.'">'.$entryDate.'</abbr></a>'."\n";
+ echo '<address class="vcard"><span class="fn">'.
+ $CONF['feed.authorName'].'</span></address>';
echo '</div>'."\n";
echo '</div>'."\n\n";
}
}
function printer_html ($level, $string)
@@ -632,21 +676,21 @@ function printer_html ($level, $string)
echo (htmlentities ($string) . "\n");
}
// Atom/RSS 2.0 output
function indent_include ($level, $file, $unescaped)
{
- global $site, $imagedir, $photodir, $weblogdir, $local_fn;
+ global $local_fn;
$local_fn = 0;
$cdd = basename (dirname ($file)); // current data dir
$fd = file ($file);
if ($fd)
{
+ unset ($GLOBALS['collect']);
foreach ($fd as $line)
{
- unset ($GLOBALS['collect']);
$line = process_line ($line);
if ($line)
{
for ($i = 0; $i < $level; $i++)
echo ' ';
if ($unescaped)
@@ -659,22 +703,21 @@ function indent_include ($level, $file, $unescaped)
process_footnotes ('printer_html', $level);
}
}
function printCalendar ()
{
- global $calendarEmptyMonths, $calendarVertical;
- global $cwd, $cur_y, $cur_m;
+ global $CONF, $cwd, $cur_y, $cur_m;
echo "<!-- BEGIN CALENDAR -->\n\n";
- if (!isset ($calendarEmptyMonths))
- $calendarEmptyMonths = true;
+ if (!isset ($CONF['calendar.emptyMonths']))
+ $CONF['calendar.emptyMonths'] = true;
- if (!isset ($calendarVertical))
- $calendarVertical = false;
+ if (!isset ($CONF['calendar.vertical']))
+ $CONF['calendar.vertical'] = false;
$searchdirs = array ();
if (!($dp = opendir ($cwd)))
die ("Can't open data directory.");
while ($name = readdir ($dp))
{
@@ -682,29 +725,30 @@ function printCalendar ()
$searchdirs[] = $cwd.'/'.$name;
}
closedir ($dp);
sort ($searchdirs);
echo "<div id=\"calendar\">\n";
- echo "<table class=\"calendarTable\"><tr>\n";
+ echo "<table class=\"calendar-table\"><tr>\n";
foreach ($searchdirs as $dir)
{
if (!($dp = opendir ($dir)))
continue;
$dir = basename ($dir);
echo "\n <!-- $dir -->\n";
- echo " <td><div class=\"calendarYear\"><a href=\"?q=$dir\">$dir</a></div>\n";
- echo " <table class=\"calendarMonths\">\n\n";
+ echo " <td><div class=\"calendar-year\"><a href=\"./".
+ $CONF['qpattern'].$dir."/\">$dir</a></div>\n";
+ echo " <table class=\"calendar-months\">\n\n";
$mtab = array ();
while ($name = readdir ($dp))
{
- if (ereg ("^(.*)-(.*)$suffix\$", $name, $res))
+ if (ereg ("^(.*)-(.*)\.html\$", $name, $res))
{
if (!($dir >= $cur_y && $res[1] > $cur_m))
$mtab[0 + $res[1]]++;
}
}
closedir ($dp);
@@ -714,31 +758,33 @@ function printCalendar ()
echo " <tr>\n";
for ($col = 0; $col < 3; $col++, $month++)
{
echo " <td>";
if ($mtab[$month])
{
- printf (" <a href=\"?q=%4d%02d\">", $dir, $month);
+ printf (" <a href=\"./".
+ $CONF['qpattern']."%4d/%02d/\">",
+ $dir, $month);
echo strftime ("%b", strtotime ("$dir-$month-1"));
echo "</a> ";
}
else
{
- if ($calendarEmptyMonths)
+ if ($CONF['calendar.emptyMonths'])
echo strftime ("%b", strtotime ("$dir-$month-1"));
else
echo ' &nbsp; ';
}
echo "</td>\n";
}
echo " </tr>\n\n";
}
echo " </table></td>\n";
- if ($calendarVertical)
+ if ($CONF['calendar.vertical'])
echo " </tr><tr>\n";
}
echo "\n</tr>\n</table>\n";
echo "</div>\n";
echo "\n<!-- END CALENDAR -->\n\n";
@@ -746,15 +792,17 @@ function printCalendar ()
function htmlentities2 ($htmlcode) {
static $htmlEntities;
static $entitiesDecoded;
static $utf8Entities;
if (!isset ($htmlEntities))
- $htmlEntities = array_values (get_html_translation_table (HTML_ENTITIES, ENT_QUOTES));
+ $htmlEntities = array_values (get_html_translation_table (HTML_ENTITIES,
+ ENT_QUOTES));
if (!isset ($entitiesDecoded))
- $entitiesDecoded = array_keys (get_html_translation_table (HTML_ENTITIES, ENT_QUOTES));
+ $entitiesDecoded = array_keys (get_html_translation_table (HTML_ENTITIES,
+ ENT_QUOTES));
if (!isset ($utf8Entities)) {
$num = count ($entitiesDecoded);
for ($u = 0; $u < $num; $u++)
$utf8Entities[$u] = '&#'.ord ($entitiesDecoded[$u]).';';
}
return str_replace ($htmlEntities, $utf8Entities, $htmlcode);
diff --git a/config.php b/config.php
index 5b25ec7..7d18740 100644
--- a/config.php
+++ b/config.php
@@ -1,47 +1,48 @@
<?php
-// blogRight! version 2.1
+// blogRight! version 2.2
// BEGIN CONFIG
-$site = 'http://your.site.name';
-$weblogdir = 'blogright';
-$imagedir = 'blogright/graphics';
-$photodir = 'blogright/photos';
-
-$charsetEncoding = 'UTF-8';
-
-$suffix = '.html'; // entries' file extension
-$recent = 'month'; // number of entries shown by default
-$sortby = 'name'; // sort by: 'name', 'timestamp'
-$sortorder = 'desc'; // sorting order: 'asc', 'desc'
-$orderfile = '.order'; // [optional] order file name
-
-$header_file = 'templates/header.html';
-$footer_file = 'templates/footer.html';
+$CONF['url.site'] = 'http://your.site.name/blog';
+$CONF['path.data'] = '/filesystem/path/blog/data/';
+$CONF['path.header_file'] = 'templates/header.html';
+$CONF['path.footer_file'] = 'templates/footer.html';
+$CONF['charsetEncoding'] = 'UTF-8';
+$CONF['recent'] = 'month'; // number of entries shown by default
+$CONF['sortby'] = 'name'; // sort by: 'name', 'timestamp'
+$CONF['sortorder'] = 'desc'; // sorting order: 'asc', 'desc'
+$CONF['orderfile'] = '.order'; // an optional order file name
+$CONF['permalinkFmt'] = 'Y/m/d';
+$CONF['qpattern'] = ''; // empty for PrettyURI, otherwise '?q='
// Webxiangpianbu
-$gscript = ''; // empty means index.(html|php)
-$defaultGallery = 'photoblog';
-$thumbnailPrefix['default'] = 'small/small-';
-$thumbnailPrefix['photoblog'] = 'photoblog/small/small-';
+$CONF['defaultGallery'] = 'photoblog';
+$CONF['thumbnailPrefix'] = array ('default' => 'small/small-',
+ 'photoblog' => 'photoblog/small/small-');
+
+$CONF['patternURL.img'] = '<img src="http://your.site.name/images/%IMAGE" alt="[image]"%PARAMS />';
+$CONF['patternURL.link'] = '<a href="http://your.site.name/%URI">';
+$CONF['patternURL.photo'] = '<a href="photos/%PHOTO"><img src="http://your.site.name/photos/data/%THUMBNAIL" alt="[photo]"%PARAMS /></a>';
+$CONF['patternURL.photos'] = '<a href="photos/%ALBUM/%PHOTO"><img src="http://your.site.name/photos/data/%THUMBNAIL" alt="[photo]"%PARAMS /></a>';
+$CONF['patternURL.gallery'] = '<a href="photos/%ALBUM/"><img src="http://your.site.name/photos/data/%THUMBNAIL" alt="[gallery]"%PARAMS /><br />&#187;</a>';
// RSS/Atom
-$feedStylesheet = true; // $site/$weblogdir/css/(atom|rss).css
-$feedTitle = 'title';
-$feedDescription = "description";
-$feedCopyright = 'Copyright (C) Your Name';
-$feedAuthorName = 'Your Name';
-$feedAuthorEmail = 'Your e-mail address';
-$feedEditor = "$feedAuthorEmail ($feedAuthorName)";
-$feedLanguage = 'en'; // Two-letter language code as per ISO 639
-$feedRecent = '10';
-$feedXHTML = true;
-$feedCDATA = true;
+$CONF['feed.title'] = 'title';
+$CONF['feed.description'] = "description";
+$CONF['feed.copyright'] = 'Copyright (C) Your Name';
+$CONF['feed.authorName'] = 'Your Name';
+$CONF['feed.authorEmail'] = 'Your e-mail address';
+$CONF['feed.editor'] = "Your e-mail address (Your Name)";
+$CONF['feed.tagUri'] = 'tag:EMAIL,YEAR:NAME';
+$CONF['feed.language'] = 'en'; // Two-letter language code as per ISO 639
+$CONF['feed.recent'] = '10';
+$CONF['feed.XHTML'] = true;
+$CONF['feed.CDATA'] = true;
// Calendar
-$calendarEmptyMonths = false;
-$calendarVertical = false;
+$CONF['calendar.emptyMonths'] = false;
+$CONF['calendar.vertical'] = false;
// END CONFIG
?>

Return to:

Send suggestions and report system problems to the System administrator.