prettyurls works now with the new system; TODO: move the index eventually to bplustree

This commit is contained in:
real_nowhereman 2008-09-23 20:34:06 +00:00
parent b71facd9ec
commit bf51547230
2 changed files with 50 additions and 11 deletions

View File

@ -787,6 +787,8 @@
$id =& $couplet[0]; $id =& $couplet[0];
$entry =& $couplet[1]; $entry =& $couplet[1];
global $post; $post = $entry;
if (THEME_LEGACY_MODE) { if (THEME_LEGACY_MODE) {
$entry = theme_entry_filters($entry, $id); $entry = theme_entry_filters($entry, $id);
} }

View File

@ -12,7 +12,7 @@ Author URI: http://www.nowhereland.it
* Place where the index is stored * Place where the index is stored
*/ */
define('PRETTYURLS_TITLES', true); define('PRETTYURLS_TITLES', true);
define('PRETTYURLS_PATHINFO', false); define('PRETTYURLS_PATHINFO', true);
define('PRETTYURLS_CACHE', CACHE_DIR . '%%prettyurls-index.tmp'); define('PRETTYURLS_CACHE', CACHE_DIR . '%%prettyurls-index.tmp');
define('PRETTYURLS_CATS', CACHE_DIR . '%%prettyurls-cats.tmp'); define('PRETTYURLS_CATS', CACHE_DIR . '%%prettyurls-cats.tmp');
@ -133,17 +133,27 @@ class Plugin_PrettyURLs {
$this->index = array(); $this->index = array();
/*
$o =& entry_init(); $o =& entry_init();
$entries = $o->getList(); $entries = $o->getList();
*/
foreach ($entries as $id => $contents) { $o = new FPDB_Query(array('start'=>0,'count'=>-1,'fullparse'=>false), null);
#foreach ($entries as $id => $contents) {
while ($o->hasMore()) {
list($id, $contents) = $o->getEntry();
$date = date_from_id($id); $date = date_from_id($id);
echo $contents['subject'], "\n";
$md5 = md5(sanitize_title($contents['subject'])); $md5 = md5(sanitize_title($contents['subject']));
$this->index[$date['y']][$date['m']][$date['d']][$md5] = $id; $this->index[$date['y']][$date['m']][$date['d']][$md5] = $id;
} }
#}
$this->cache_save(); $this->cache_save();
io_write_file(PRETTYURLS_CACHE, 'dummy');
} }
@ -188,7 +198,9 @@ class Plugin_PrettyURLs {
function handle_entry($matches) { function handle_entry($matches) {
if (PRETTYURLS_TITLES) { if (PRETTYURLS_TITLES) {
if (isset($this->index[$this->fp_params['y']][$this->fp_params['m']][$this->fp_params['d']][md5($matches[1])])) {
#isset($this->index[
if ($this->cache_get($this->fp_params['y'],$this->fp_params['m'], $this->fp_params['d'], md5($matches[1]))) {
$this->fp_params['entry'] = $this->index[$this->fp_params['y']][$this->fp_params['m']][$this->fp_params['d']][md5($matches[1])]; $this->fp_params['entry'] = $this->index[$this->fp_params['y']][$this->fp_params['m']][$this->fp_params['d']][md5($matches[1])];
} else { } else {
// a bit hackish: we make up a fake url when there is no match, // a bit hackish: we make up a fake url when there is no match,
@ -241,10 +253,10 @@ class Plugin_PrettyURLs {
$this->baseurl = PRETTYURLS_PATHINFO? BLOG_BASEURL . 'index.php/' : BLOG_BASEURL; $this->baseurl = PRETTYURLS_PATHINFO? BLOG_BASEURL . 'index.php/' : BLOG_BASEURL;
if (PRETTYURLS_TITLES) { if (PRETTYURLS_TITLES) {
if ($f = io_load_file(PRETTYURLS_CACHE)) #if ($f = io_load_file(PRETTYURLS_CACHE))
$this->index = unserialize($f); $this->index = array(); #unserialize($f);
if (!$this->index) if (!file_exists(PRETTYURLS_CACHE))
$this->cache_create(); $this->cache_create();
@ -334,8 +346,8 @@ class Plugin_PrettyURLs {
function cache_delete_elem($id, $date) { function cache_delete_elem($id, $date) {
# is this a title change? # is this a title change?
if (isset($this->index[ $date['y'] ] [ $date['m'] ][ $date['d'] ])) if (false !== ($ids = $this->cache_get( $date['y'] , $date['m'] , $date['d'] )))
$hash = array_search($id, $this->index[ $date['y'] ] [ $date['m'] ][ $date['d'] ]); $hash = array_search($id, $ids);
else else
return; return;
@ -358,6 +370,8 @@ class Plugin_PrettyURLs {
} }
$this->cache_save();
} }
function cache_add($id, &$arr) { function cache_add($id, &$arr) {
@ -376,6 +390,24 @@ class Plugin_PrettyURLs {
} }
function cache_get($y,$m,$d=null,$h=null) {
if (!isset($this->index[$y][$m])) {
$s = @io_load_file(PRETTYURLS_CACHE.$y.$m);
$this->index[$y][$m] = $s? unserialize($s) : false;
}
if (is_null($d))
return $this->index[$y][$m];
if (is_null($h))
return ($this->index[$y][$m][$d]);
if (isset($this->index[$y][$m][$d]))
return isset($this->index[$y][$m][$d][$h]);
else
return false;
}
function cache_delete($id) { function cache_delete($id) {
$date = date_from_id($id); $date = date_from_id($id);
$this->cache_delete_elem($id, $date); $this->cache_delete_elem($id, $date);
@ -384,8 +416,13 @@ class Plugin_PrettyURLs {
} }
function cache_save() { function cache_save() {
if ($this->index) if ($this->index) {
return io_write_file(PRETTYURLS_CACHE, serialize($this->index)); foreach ($this->index as $year => $months) {
foreach ($months as $month => $days)
io_write_file(PRETTYURLS_CACHE.$year.$month, serialize($days));
}
}
return true; return true;