New exciting experimental feature: EXCLUDE queries.

append exclude:ID to your URL query string to exclude a category from the listing. e.g. ?x=cat:10;exclude:5 to list all the entries which belongs to cat-id 10 AND NOT to cat-id 5
This commit is contained in:
real_nowhereman 2009-11-21 16:06:57 +00:00
parent 53bf2ca321
commit 42f944fabc

View File

@ -10,6 +10,7 @@
var $count = -1; var $count = -1;
var $random = 0; var $random = 0;
var $category = 0; var $category = 0;
var $exclude = null;
var $page = 1; var $page = 1;
var $fullparse = false; var $fullparse = false;
var $comments = false; var $comments = false;
@ -119,6 +120,10 @@
$this->comments = true; $this->comments = true;
} }
if (isset($params['exclude'])) {
$this->not = intval($params['exclude']);
}
} }
function parse_string($str) { function parse_string($str) {
@ -142,6 +147,9 @@
var $nextid = ''; var $nextid = '';
var $previd = ''; var $previd = '';
var $currentid = ''; var $currentid = '';
var $main_idx = null;
var $secondary_idx = null;
var $walker = null;
function FPDB_Query($params, $ID) { function FPDB_Query($params, $ID) {
@ -166,7 +174,8 @@
$fpdb->init(); $fpdb->init();
$entry_index =& $fpdb->get_index($this->params->category); $this->main_idx =& $fpdb->get_index($this->params->category);
$entry_index =& $this->main_idx;
$this->counter++; $this->counter++;
@ -184,8 +193,17 @@
$this->_prepare_single($entry_index); $this->_prepare_single($entry_index);
} else { } else {
$this->_prepare_list($entry_index); $this->_prepare_list($entry_index);
if ($this->params->exclude) {
$o =& $fpdb->get_index($this->params->exclude);
if ($o !== false)
$this->secondary_idx =& $o;
}
} }
// force first entry to be loaded: updates count, pointer
$this->peekEntry();
} }
@ -285,22 +303,6 @@
$index_count = $qp->start = $qp->count = 0; $index_count = $qp->start = $qp->count = 0;
} }
#$this->pointer = $qp->start;
// fills array
/*
stuff for cats, have a look
$this->local_list =& $tmp;
if ($qp->start + $qp->count > $i) {
$qp->count = $i - $qp->start;
}
*/
} }
// not so great implementation... doesn't work well // not so great implementation... doesn't work well
@ -328,24 +330,28 @@
function hasMore() { function hasMore() {
$GLOBALS['current_query'] =& $this; $GLOBALS['current_query'] =& $this;
// if system init has not been done (filling pointer variable etc.)
if ($this->counter < 0) // call prepare()
if ($this->counter < 0) {
$this->prepare(); $this->prepare();
}
return $this->pointer < $this->params->start + $this->params->count; // hasMore() returns false either if pointer exceeded the count
// or peekEntry returns false
return ((bool) $this->peekEntry()
&& $this->pointer < $this->params->start + $this->params->count );
} }
function &peekEntry() { function &peekEntry() {
global $post; global $post;
if (!$this->hasMore()) { /*if (!$this->hasMore()) {
$false = array(false, false); $false = array(false, false);
return $false; return $false;
} }*/
$qp =& $this->params; $qp =& $this->params;
@ -353,24 +359,46 @@
if ($this->counter < 0) if ($this->counter < 0)
$this->prepare(); $this->prepare();
if (!$this->walker) {
$false = array(false, false);
return $false;
}
#$this->_fillPrevId();
#$this->_fillNextId();
#$id = $this->_fillCurrentId();
// search first eligible post
while ($this->walker->valid && $this->pointer<$qp->start) { while ($this->walker->valid && $this->pointer<$qp->start) {
$this->previd = $this->currentid;
$id = $this->currentid = entry_keytoid($this->walker->current_key());
if ($this->single) $this->preventry = array('subject' => $this->walker->current_value()); $this->previd = $this->currentid;
$key = $this->walker->current_key();
$id = $this->currentid = entry_keytoid($key);
if ($this->single)
$this->preventry = array('subject' => $this->walker->current_value());
$this->walker->next(); $this->walker->next();
$this->pointer++; $this->pointer++;
} }
// if there is a secondary (not) idx
if ($this->secondary_idx) {
// skips posts until we find one which is not in the secondary idx
while ( $this->walker->valid
&& ($key = $this->walker->current_key())
&& $this->secondary_idx->has_key($key)) {
$this->walker->next();
$qp->count--;
}
}
if (!$this->walker->valid) {
$cont = false; return $cont;
}
// pointer == start // pointer == start
$prevcurr = $this->currentid; $prevcurr = $this->currentid;
@ -639,6 +667,8 @@
* m (string) two digit month (06 means June); 'y' must be set * m (string) two digit month (06 means June); 'y' must be set
* d (string) two digit for day; 'y' and 'm' must be set * d (string) two digit for day; 'y' and 'm' must be set
* *
* exclude (int) experimental: excludes category ID given as argument from listing
*
* *
* fullparse (bool) non-full-parsed entries get their values * fullparse (bool) non-full-parsed entries get their values
* right from the indexed list (or <em>cache</em>). * right from the indexed list (or <em>cache</em>).