Update of /cvsroot/php-blog/serendipity
In directory sc8-pr-cvs1:/tmp/cvs-serv5942
Modified Files:
index.php search.php serendipity_admin.php
serendipity_config.inc.php serendipity_functions.inc.php
serendipity_sidebar_items.php
Log Message:
+++ATTENTION+++
This one's a troublemaker for those who already use serendipity. The link-rewriting has been changed. An entry is now accessed like this:
/archives/id_title_of_entry.html (used to be /archives/e_id.html)
Timeranges are now accessed like this:
/archives/200203.html (used to be /archives/d_200203.html)
This is more reader friendly and the search engines will be able to find pages better (title is contained in filename). Of course, all your "old" link to serendipity blogs are now broken. Since I don't want to have two ways of accessing an entry (old way AND new way), you'll have to go through your entries and fix the links.
Since I'm the only one with 200+ entries, I'm probably the one who'll come up with a script that goes through your db and fixes the links. Eventually.
Also, the pregeneration is now broken, but can be easily fixed (look for "fixme", there's an unlink($filename."*.html") that's supposed to delete a file - since this function doesnt (need to) know the title of the entry, it must delete id_*.html instead of id_title_of_entry.html). Easy fiX.
Does the rest work for you?
Index: index.php
===================================================================
RCS file: /cvsroot/php-blog/serendipity/index.php,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- index.php 3 May 2003 13:28:19 -0000 1.8
+++ index.php 25 May 2003 16:36:33 -0000 1.9
@@ -1,18 +1,16 @@
<?php
// We need to set this to return a 200 since we use .htaccess ErrorDocument
-// rules to handle archives.
+// rules to handle archives.
header("HTTP/1.0 200\r\n");
-session_start();
include_once("serendipity_config.inc.php");
$track_referer = true;
$uri = $_SERVER['REQUEST_URI'];
-if (preg_match('@/archives/@', $uri)) {
- if (preg_match('@/(d_(\d+)\.html)@', $uri, $matches)) {
- $range = $matches[2];
+if (preg_match('@/archives/(\d+)\.html@', $uri, $matches)) {
+ $range = $matches[1];
$_GET['serendipity']['action'] = "read";
$_GET['serendipity']['range'] = $range;
-
+
if (strlen($range) == 6) {
$date = date("m/Y", mktime(0,0,0, substr($range, 4, 6), 2, substr($range, 0, 4)));
@@ -31,36 +29,37 @@
fwrite($fp, $data);
fclose($fp);
}
-
+
echo $data;
- } else if (preg_match('@/(e_(\d+)\.html)@', $uri, $matches)) {
- $id = $matches[2];
-
- serendipity_track_referrer($id);
- $track_referer = false;
+}
- $_GET['serendipity']['action'] = 'read';
- $_GET['serendipity']['id'] = $id;
+else if (preg_match('@/(\d+)_\w+\.html@i', $uri, $matches)) {
+ $id = $matches[1];
- $title = serendipity_db_query("SELECT title FROM {$serendipity['dbPrefix']}entries " .
+ serendipity_track_referrer($id);
+ $track_referer = false;
+
+ $_GET['serendipity']['action'] = 'read';
+ $_GET['serendipity']['id'] = $id;
+
+ $title = serendipity_db_query("SELECT title FROM {$serendipity['dbPrefix']}entries " .
'WHERE id=' . serendipity_db_escape_string($id), true);
- $title = $title[0];
-
- $serendipity['blogSubTitle'] = htmlspecialchars($title);
+ $title = $title[0];
- ob_start();
- include_once("serendipity_genpage.inc.php");
- $data = ob_get_contents();
- ob_end_clean();
+ $serendipity['blogSubTitle'] = htmlspecialchars($title);
- if ($serendipity['pregenerate']) {
- $fp = fopen("./archives/{$matches[1]}", "w");
- fwrite($fp, $data);
- fclose($fp);
- }
+ ob_start();
+ include_once("serendipity_genpage.inc.php");
+ $data = ob_get_contents();
+ ob_end_clean();
+
+ if ($serendipity['pregenerate']) {
+ $fp = fopen("./archives/{$matches[1]}", "w");
+ fwrite($fp, $data);
+ fclose($fp);
+ }
+ print $data;
- print $data;
- }
} else if (preg_match('@/feeds/@', $uri)) {
if (preg_match('@/index.(rss|rdf|rss2)$@', $uri, $matches)) {
switch ($matches[1]) {
@@ -84,7 +83,7 @@
fwrite($fp, $data);
fclose($fp);
}
-
+
print $data;
}
} else if (preg_match('@/admin$@', $uri)) {
Index: search.php
===================================================================
RCS file: /cvsroot/php-blog/serendipity/search.php,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- search.php 29 Mar 2003 16:44:46 -0000 1.2
+++ search.php 25 May 2003 16:36:33 -0000 1.3
@@ -1,5 +1,5 @@
<?php
-session_start();
+
include_once("serendipity_config.inc.php");
include_once("serendipity_genpage.inc.php");
?>
Index: serendipity_admin.php
===================================================================
RCS file: /cvsroot/php-blog/serendipity/serendipity_admin.php,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- serendipity_admin.php 21 May 2003 15:49:50 -0000 1.8
+++ serendipity_admin.php 25 May 2003 16:36:33 -0000 1.9
@@ -1,4 +1,5 @@
<?php
+ini_set("session.use_trans_sid",1);
session_start();
if (file_exists("./serendipity_config_local.inc.php")) {
include("serendipity_config.inc.php");
Index: serendipity_config.inc.php
===================================================================
RCS file: /cvsroot/php-blog/serendipity/serendipity_config.inc.php,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -d -r1.10 -r1.11
--- serendipity_config.inc.php 24 May 2003 01:51:52 -0000 1.10
+++ serendipity_config.inc.php 25 May 2003 16:36:33 -0000 1.11
@@ -1,7 +1,7 @@
<?php
define('IN_serendipity', true);
include_once('compat.php');
-
+ini_set("session.use_trans_sid",0);
$serendipity['production'] = 1;
if (!isset($serendipity['serendipityPath'])) {
$serendipity['serendipityPath'] = './';
Index: serendipity_functions.inc.php
===================================================================
RCS file: /cvsroot/php-blog/serendipity/serendipity_functions.inc.php,v
retrieving revision 1.51
retrieving revision 1.52
diff -u -d -r1.51 -r1.52
--- serendipity_functions.inc.php 24 May 2003 22:04:22 -0000 1.51
+++ serendipity_functions.inc.php 25 May 2003 16:36:33 -0000 1.52
@@ -110,7 +110,7 @@
<TD COLSPAN='5' ALIGN='center' VALIGN='bottom' CLASS='serendipity_calendarHeader'><B><nobr>
<?php
if ($serendipity["rewrite"]==true) {
- $link = $serendipity["serendipityHTTPPath"]."archives/d_".$year.sprintf("%02d",$month).".html";
+ $link = $serendipity["serendipityHTTPPath"]."archives/".$year.sprintf("%02d",$month).".html";
}
else {
$link = "fixme";
@@ -152,7 +152,7 @@
// Print day
if ($serendipity["rewrite"]==true)
- $link = $serendipity["serendipityHTTPPath"]."archives/d_".date("Ymd", mktime(0,0,0, $month, $currDay, $year)).".html";
+ $link = $serendipity["serendipityHTTPPath"]."archives/".date("Ymd", mktime(0,0,0, $month, $currDay, $year)).".html";
else
$link = "fixme!";
if (date("m") == $month && date("Y") == $year && $currDay == date("j")) echo "<I>";
@@ -257,6 +257,12 @@
return serendipity_db_query($querystring);
}
+/**
+* Creates a filename that consists of [a-zA-z0-9_] (with some custom adjustments (space -> _, ä -> ae and such)
+**/
+function serendipity_makeFilename($str) {
+ return preg_replace('#[^\w]#', '', str_replace(" ", "_" , $str));
+}
/**
* Prints the entries you fetched with serendipity_fetchEntries/searchEntries in HTML.
@@ -296,16 +302,16 @@
if ($entry['exflag'] && !$extended) {
echo "<br><div class='serendipity_time'><a href=\""
. $serendipity['serendipityHTTPPath']
- . "archives/e_"
+ . "archives/"
. $entry['id']
- . ".html#extended\">View Extended Entry</a></div><br>";
+ . "_".serendipity_makeFilename($entry['title']).".html#extended\">View Extended Entry</a></div><br>";
}
echo "<div class='serendipity_time'><br><a href=\""
. $serendipity['serendipityHTTPPath']
- . "archives/e_"
+ . "archives/"
. $entry['id']
- . ".html\">".POSTED_BY." "
+ . "_".serendipity_makeFilename($entry['title']).".html\">".POSTED_BY." "
. htmlentities($entry['username'])
. ($entry['category_name']?(" in ${entry['category_name']}"):"")
." at "
@@ -335,7 +341,7 @@
echo " rdf:about=\"{$serendipity['baseURL']}feeds/ei_{$entry['id']}.rdf\"\n";
echo " trackback:ping=\"{$serendipity['baseURL']}comment.php?type=trackback&entry_id={$entry['id']}\"\n";
echo " dc:title=\"{$entry['title']}\"\n";
- echo " dc:identifier=\"{$serendipity['baseURL']}archives/e_{$entry['id']}.html\" />\n";
+ echo " dc:identifier=\"{$serendipity['baseURL']}archives/{$entry['id']}_".serendipity_makeFilename($entry['title']).".html\" />\n";
echo "</rdf:RDF>\n";
echo "-->\n";
@@ -562,7 +568,7 @@
foreach ($entries as $entry) {
echo "<item>\n";
echo "<title>{$entry['title']}</title>\n";
- echo "<link>{$serendipity['baseURL']}archives/e_{$entry['id']}.html</link>\n";
+ echo "<link>{$serendipity['baseURL']}archives/{$entry['id']}_".serendipity_makeFilename($entry['title']).".html</link>\n";
if ($version == '2.0') {
// extract author information
$query = "select email from {$serendipity['dbPrefix']}authors where username='{$entry['username']}'";
@@ -572,7 +578,7 @@
echo utf8_encode(htmlspecialchars(serendipity_emoticate(serendipity_markup_text($entry['body']))));
echo "\n</content:encoded>\n";
echo '<pubDate>' . date("r", $entry['timestamp']) . "</pubDate>\n";
- echo "<guid>{$serendipity['baseURL']}e_{$entry['id']}.html</guid>\n";
+ echo "<guid>{$serendipity['baseURL']}archives/{$entry['id']}_".serendipity_makeFilename($entry['title']).".html</guid>\n";
} else {
echo "<description>\n" . utf8_encode(htmlspecialchars($entry['body'])) . "\n</description>\n";
}
@@ -681,10 +687,11 @@
$dated = date("Ymd", $timestamp);
$datem = date("Ym", $timestamp);
- @unlink("{$serendipity['serendipityPath']}/archives/d_{$dated}.html");
- @unlink("{$serendipity['serendipityPath']}/archives/d_{$datem}.html");
+ @unlink("{$serendipity['serendipityPath']}/archives/{$dated}.html");
+ @unlink("{$serendipity['serendipityPath']}/archives/{$datem}.html");
}
- @unlink("{$serendipity['serendipityPath']}/archives/e_{$id}.html");
+ // Fixme (the _* part) !
+ @unlink("{$serendipity['serendipityPath']}/archives/{$id}_*.html");
@unlink("{$serendipity['serendipityPath']}/feeds/index.rss");
@unlink("{$serendipity['serendipityPath']}/feeds/index.rss2");
@unlink("{$serendipity['serendipityPath']}/index.html");
@@ -1727,7 +1734,7 @@
for($x=1; $x<13; $x++) {
$entries = serendipity_postAmount($currYear, $x);
if ($entries>0) {
- $a = "<a href='{$serendipity['serendipityHTTPPath']}archives/d_$currYear".sprintf("%02s",$x).".html'>";
+ $a = "<a href='{$serendipity['serendipityHTTPPath']}archives/$currYear".sprintf("%02s",$x).".html'>";
$b = "($entries entries)</a>";
}
else {
Index: serendipity_sidebar_items.php
===================================================================
RCS file: /cvsroot/php-blog/serendipity/serendipity_sidebar_items.php,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -d -r1.12 -r1.13
--- serendipity_sidebar_items.php 24 May 2003 10:23:06 -0000 1.12
+++ serendipity_sidebar_items.php 25 May 2003 16:36:33 -0000 1.13
@@ -64,7 +64,7 @@
for($x=0; $x<3; $x++) {
$ts-=1;
if ($serendipity["rewrite"] === true)
- $link = $serendipity["serendipityHTTPPath"]."archives/d_".date("Ym", $ts).".html";
+ $link = $serendipity["serendipityHTTPPath"]."archives/".date("Ym", $ts).".html";
else
$link = "fixme";
echo "<a href='$link'>".$serendipity["months"][date("n", $ts)]." ".date("Y", $ts)."</a><br />";
|