Update of /cvsroot/php-blog/serendipity
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16871
Modified Files:
index.php serendipity_config.inc.php
Log Message:
* Allow pagination for searched entries
* Pretty URLs for search: http://blog/search/SEARCHTERM and
http://blog/search/SEARCHTERM/Pn.html for succeeding pages
- Requires version bump to work with mod_rewrite (not done yet, waiting
for Tom)
- Done in a BC compatible way
- Needed to adjust RegExp for parsing uriArguments variable, because
"%" and "+" signs need to be allowed to search for Umlauts etc.
Please check if that may break things (don't know of any)
Index: serendipity_config.inc.php
===================================================================
RCS file: /cvsroot/php-blog/serendipity/serendipity_config.inc.php,v
retrieving revision 1.129
retrieving revision 1.130
diff -u -d -r1.129 -r1.130
--- serendipity_config.inc.php 4 Jan 2005 10:18:06 -0000 1.129
+++ serendipity_config.inc.php 10 Jan 2005 13:12:53 -0000 1.130
@@ -113,6 +113,7 @@
@define('PATH_PLUGIN', 'plugin');
@define('PATH_ADMIN', 'admin');
@define('PATH_ENTRIES', 'entries');
+@define('PATH_SEARCH', 'search');
@define('PATH_SMARTY_COMPILE', 'templates_c'); // will be placed inside the template directory
@@ -140,6 +141,7 @@
@define('PAT_ARCHIVE', '@/'.PATH_ARCHIVE.'$@');
@define('PAT_CATEGORIES', '@/'.PATH_CATEGORIES.'/([0-9]+)@');
@define('PAT_PLUGIN', '@/' . PATH_PLUGIN . '/(.*)@');
+@define('PAT_SEARCH', '@/' . PATH_SEARCH . '/(.*)@');
@define('USERLEVEL_ADMIN', 255);
@define('USERLEVEL_CHIEF', 1);
Index: index.php
===================================================================
RCS file: /cvsroot/php-blog/serendipity/index.php,v
retrieving revision 1.70
retrieving revision 1.71
diff -u -d -r1.70 -r1.71
--- index.php 5 Jan 2005 13:08:44 -0000 1.70
+++ index.php 10 Jan 2005 13:12:52 -0000 1.71
@@ -29,7 +29,7 @@
$uri = $_SERVER['REQUEST_URI'];
/* Explode the path into sections, to later be able to check for arguments and add our own */
-preg_match('/^'. preg_quote($serendipity['serendipityHTTPPath'], '/') .'('. preg_quote($serendipity['indexFile'], '/') .'\?\/)?([a-z0-9\-*\/]+)/i', $uri, $_res);
+preg_match('/^'. preg_quote($serendipity['serendipityHTTPPath'], '/') .'('. preg_quote($serendipity['indexFile'], '/') .'\?\/)?([a-z0-9\-*\/%\+]+)/i', $uri, $_res);
if ( strlen($_res[2]) != 0 ) {
$serendipity['uriArguments'] = explode('/', $_res[2]);
} else {
@@ -256,7 +256,35 @@
include_once(S9Y_INCLUDE_PATH . 'include/genpage.inc.php');
} else if (preg_match('@/(index(\.php|\.html)?)|'. preg_quote($serendipity['indexFile']) .'@', $uri) ||
preg_match('@^/' . preg_quote(trim($serendipity['serendipityHTTPPath'], '/')) . '/?(\?.*)?$@', $uri)) {
- $serendipity['uriArguments'][] = PATH_ARCHIVES;
+
+ if ($serendipity['GET']['action'] == 'search') {
+ $serendipity['uriArguments'] = array(PATH_SEARCH, urlencode($serendipity['GET']['searchTerm']));
+ } else {
+ $serendipity['uriArguments'][] = PATH_ARCHIVES;
+ }
+
+ include_once(S9Y_INCLUDE_PATH . 'include/genpage.inc.php');
+} else if (preg_match(PAT_SEARCH, $uri, $matches)) {
+ $_args = $serendipity['uriArguments'];
+
+ /* Attempt to locate hidden variables within the URI */
+ $search = array();
+ foreach ($_args as $k => $v){
+ if ($v == PATH_SEARCH) {
+ continue;
+ }
+
+ if ($v{0} == 'P') { /* Page */
+ $serendipity['GET']['page'] = substr($v, 1);
+ unset($_args[$k]);
+ unset($serendipity['uriArguments'][$k]);
+ } else {
+ $search[] = $v;
+ }
+ }
+
+ $serendipity['GET']['action'] = 'search';
+ $serendipity['GET']['searchTerm'] = urldecode(htmlspecialchars(strip_tags(implode(' ', $search))));
include_once(S9Y_INCLUDE_PATH . 'include/genpage.inc.php');
} else {
header('HTTP/1.0 404 Not found');
|