add('name', PLUGIN_EVENT_FILTER_ENTRIES_NAME);
$propbag->add('description', PLUGIN_EVENT_FILTER_ENTRIES_DESC);
$propbag->add('stackable', false);
$propbag->add('author', 'Garvin Hicking');
$propbag->add('version', '1.5');
$propbag->add('requirements', array(
'serendipity' => '0.8',
'smarty' => '2.6.7',
'php' => '4.1.0'
));
$propbag->add('event_hooks', array(
'external_plugin' => true,
'entries_footer' => true,
'frontend_configure' => true,
'frontend_fetchentries' => true
));
$propbag->add('groups', array('FRONTEND_VIEWS'));
}
function generate_content(&$title) {
$title = $this->title;
}
function event_hook($event, &$bag, &$eventData, $addData = null) {
global $serendipity;
$hooks = &$bag->get('event_hooks');
$links = array();
if (isset($hooks[$event])) {
$sort_order = array('timestamp' => DATE,
'isdraft' => PUBLISH . '/' . DRAFT,
'a.realname' => AUTHOR,
'category_name' => CATEGORY,
'last_modified' => LAST_UPDATED,
'title' => TITLE);
$per_page_max = 50;
$per_page = array('12', '16', '25', $per_page_max);
switch($event) {
case 'frontend_fetchentries':
if ($this->fetchLimit > 0) {
$serendipity['fetchLimit'] = $this->fetchLimit;
}
break;
case 'frontend_configure':
$_SERVER['REQUEST_URI'] = str_replace('%2Fplugin%2Ffilter%2F', '/plugin/filter/', $_SERVER['REQUEST_URI']);
break;
case 'entries_footer':
$link = $serendipity['baseURL'] . ($serendipity['rewrite'] == 'none' ? $serendipity['indexFile'] . '?/' : '') . 'plugin/filter/';
?>
$v){
if ($v[0] == 'P') { /* Page */
$page = substr($v, 1);
if (is_numeric($page)) {
$serendipity['GET']['page'] = $page;
unset($serendipity['uriArguments'][$k]);
}
}
}
switch($plugincode) {
case 'filter':
$perPage = (int)(!empty($_SESSION['sort']['perPage']) ? $_SESSION['sort']['perPage'] : $per_page[0]);
if ($perPage > $per_page_max) {
$perPage = $per_page_max;
}
$serendipity['fetchLimit'] = $perPage;
$this->fetchLimit = $perPage;
$page = (int)$serendipity['GET']['page'];
$offSet = $perPage*$page;
if (empty($_SESSION['sort']['ordermode']) || $_SESSION['sort']['ordermode'] != 'ASC') {
$_SESSION['sort']['ordermode'] = 'DESC';
}
if (!empty($_SESSION['sort']['order']) && !empty($sort_order[$_SESSION['sort']['order']])) {
$orderby = serendipity_db_escape_string($_SESSION['sort']['order'] . ' ' . $_SESSION['sort']['ordermode']);
} else {
$orderby = 'timestamp ' . serendipity_db_escape_string($_SESSION['sort']['ordermode']);
}
$filter = array();
if (!empty($_SESSION['filter']['author'])) {
$filter[] = "e.authorid = '" . serendipity_db_escape_string($_SESSION['filter']['author']) . "'";
}
if (!empty($_SESSION['filter']['category'])) {
$filter[] = "ec.categoryid = '" . serendipity_db_escape_string($_SESSION['filter']['category']) . "'";
}
if (!empty($_SESSION['filter']['body'])) {
if ($serendipity['dbType'] == 'mysql') {
$filter[] = "MATCH (title,body,extended) AGAINST ('" . serendipity_db_escape_string($_SESSION['filter']['body']) . "')";
$full = true;
}
}
$filter_sql = implode(' AND ', $filter);
// Fetch the entries
$entries = serendipity_fetchEntries(
false,
false,
serendipity_db_limit(
$offSet,
$perPage
),
true,
false,
$orderby,
$filter_sql
);
$serendipity['smarty_raw_mode'] = true;
include_once(S9Y_INCLUDE_PATH . 'include/genpage.inc.php');
serendipity_printEntries($entries);
$raw_data = ob_get_contents();
ob_end_clean();
$serendipity['smarty']->assign('CONTENT', $raw_data);
$serendipity['smarty']->assign('is_raw_mode', false);
serendipity_gzCompression();
$serendipity['smarty']->display(serendipity_getTemplateFile($serendipity['smarty_file'], 'serendipityPath'));
break;
}
return true;
break;
default:
return false;
break;
}
} else {
return false;
}
}
}
/* vim: set sts=4 ts=4 expandtab : */