[geeklog-cvs] geeklog: Consolidated common date comparison into search API, fu...
geeklog-cvs at lists.geeklog.net
geeklog-cvs at lists.geeklog.net
Wed Sep 30 19:10:19 EDT 2009
details: http://project.geeklog.net/cgi-bin/hgweb.cgi/rev/187ee0efcee2
changeset: 7342:187ee0efcee2
user: Sami Barakat
date: Thu Oct 01 00:07:25 2009 +0100
description:
Consolidated common date comparison into search API, functionally the same
diffstat:
plugins/calendar/functions.inc | 17 +++++------------
plugins/links/functions.inc | 15 +++------------
plugins/staticpages/functions.inc | 15 +++------------
system/classes/search.class.php | 30 ++++++------------------------
system/classes/searchcriteria.class.php | 18 ++++++++++++++++++
5 files changed, 35 insertions(+), 60 deletions(-)
diffs (201 lines):
diff -r db4c6eb6e843 -r 187ee0efcee2 plugins/calendar/functions.inc
--- a/plugins/calendar/functions.inc Sun Sep 27 21:26:06 2009 +0200
+++ b/plugins/calendar/functions.inc Thu Oct 01 00:07:25 2009 +0100
@@ -1634,26 +1634,17 @@
$sql = COM_getPermSQL('AND') . ' ';
- if (!empty($datestart) && !empty($dateend))
- {
- $delim = substr($datestart, 4, 1);
- if (!empty($delim))
- {
- $DS = explode($delim, $datestart);
- $DE = explode($delim, $dateend);
- $startdate = mktime(0,0,0,$DS[1],$DS[2],$DS[0]);
- $enddate = mktime(23,59,59,$DE[1],$DE[2],$DE[0]);
- $sql .= "AND (UNIX_TIMESTAMP(datestart) BETWEEN '$startdate' AND '$enddate') ";
- }
- }
if (!empty ($author)) {
$sql .= "AND (owner_id = '$author') ";
}
// Search the public events
$search_e = new SearchCriteria('calendar', array($LANG_CAL_1[16],$LANG_CAL_1[24]));
+
$columns = array('title' => 'title', 'location', 'description');
+ $sql .= $search_e->getDateRangeSQL('AND', 'datestart', $datestart, $dateend);
list($sql_tmp,$ftsql_tmp) = $search_e->buildSearchSQL($keyType, $query, $columns, $sql_e . $sql);
+
$search_e->setSQL($sql_tmp);
$search_e->setFTSQL($ftsql_tmp);
$search_e->setRank(2);
@@ -1664,8 +1655,10 @@
// Search personal events
$search_p = new SearchCriteria('calendar', array($LANG_CAL_1[16],$LANG_CAL_1[23]));
+
$columns = array('title' => 'title', 'location', 'description');
list($sql_tmp,$ftsql_tmp) = $search_p->buildSearchSQL($keyType, $query, $columns, $sql_p . $sql);
+
$search_p->setSQL($sql_tmp);
$search_p->setFTSQL($ftsql_tmp);
$search_p->setRank(2);
diff -r db4c6eb6e843 -r 187ee0efcee2 plugins/links/functions.inc
--- a/plugins/links/functions.inc Sun Sep 27 21:26:06 2009 +0200
+++ b/plugins/links/functions.inc Thu Oct 01 00:07:25 2009 +0100
@@ -368,25 +368,16 @@
$sql .= "FROM {$_TABLES['links']} WHERE date <> 1 ";
$sql .= COM_getPermSQL('AND') . ' ';
- if (!empty($datestart) && !empty($dateend))
- {
- $delim = substr($datestart, 4, 1);
- if (!empty($delim))
- {
- $DS = explode($delim, $datestart);
- $DE = explode($delim, $dateend);
- $startdate = mktime(0,0,0,$DS[1],$DS[2],$DS[0]);
- $enddate = mktime(23,59,59,$DE[1],$DE[2],$DE[0]);
- $sql .= "AND (UNIX_TIMESTAMP(date) BETWEEN '$startdate' AND '$enddate') ";
- }
- }
if (!empty ($author)) {
$sql .= "AND (owner_id = '$author') ";
}
$search = new SearchCriteria('links', $LANG_LINKS[14]);
+
$columns = array('title' => 'title', 'description');
+ $sql .= $search->getDateRangeSQL('AND', 'date', $datestart, $dateend);
list($sql,$ftsql) = $search->buildSearchSQL($keyType, $query, $columns, $sql);
+
$search->setSQL($sql);
$search->setFTSQL($ftsql);
$search->setRank(3);
diff -r db4c6eb6e843 -r 187ee0efcee2 plugins/staticpages/functions.inc
--- a/plugins/staticpages/functions.inc Sun Sep 27 21:26:06 2009 +0200
+++ b/plugins/staticpages/functions.inc Thu Oct 01 00:07:25 2009 +0100
@@ -610,25 +610,16 @@
$sql .= "WHERE (sp.sp_uid = u.uid) AND (sp_php <> 1) ";
$sql .= COM_getPermSQL('AND') . COM_getLangSQL('sp_id', 'AND', 'sp') . ' ';
- if (!empty($datestart) && !empty($dateend))
- {
- $delim = substr($datestart, 4, 1);
- if (!empty($delim))
- {
- $DS = explode($delim, $datestart);
- $DE = explode($delim, $dateend);
- $startdate = mktime(0,0,0,$DS[1],$DS[2],$DS[0]);
- $enddate = mktime(23,59,59,$DE[1],$DE[2],$DE[0]);
- $sql .= "AND (UNIX_TIMESTAMP(sp_date) BETWEEN '$startdate' AND '$enddate') ";
- }
- }
if (!empty ($author)) {
$sql .= "AND (sp_uid = '$author') ";
}
$search = new SearchCriteria('staticpages', $LANG_STATIC['staticpages']);
+
$columns = array('title' => 'sp_title', 'sp_content');
+ $sql .= $search->getDateRangeSQL('AND', 'sp_date', $datestart, $dateend);
list($sql,$ftsql) = $search->buildSearchSQL($keyType, $query, $columns, $sql);
+
$search->setSQL($sql);
$search->setFTSQL($ftsql);
$search->setRank(3);
diff -r db4c6eb6e843 -r 187ee0efcee2 system/classes/search.class.php
--- a/system/classes/search.class.php Sun Sep 27 21:26:06 2009 +0200
+++ b/system/classes/search.class.php Thu Oct 01 00:07:25 2009 +0100
@@ -362,18 +362,6 @@
$sql .= "WHERE (draft_flag = 0) AND (date <= NOW()) AND (u.uid = s.uid) ";
$sql .= COM_getPermSQL('AND') . COM_getTopicSQL('AND') . COM_getLangSQL('sid', 'AND') . ' ';
- if (!empty($this->_dateStart) && !empty($this->_dateEnd))
- {
- $delim = substr($this->_dateStart, 4, 1);
- if (!empty($delim))
- {
- $DS = explode($delim, $this->_dateStart);
- $DE = explode($delim, $this->_dateEnd);
- $startdate = mktime(0,0,0,$DS[1],$DS[2],$DS[0]);
- $enddate = mktime(23,59,59,$DE[1],$DE[2],$DE[0]);
- $sql .= "AND (UNIX_TIMESTAMP(date) BETWEEN '$startdate' AND '$enddate') ";
- }
- }
if (!empty($this->_topic)) {
$sql .= "AND (s.tid = '$this->_topic') ";
}
@@ -382,8 +370,11 @@
}
$search_s = new SearchCriteria('stories', $LANG09[65]);
+
$columns = array('title' => 'title', 'introtext', 'bodytext');
+ $sql .= $search_s->getDateRangeSQL('AND', 'date', $this->_dateStart, $this->_dateEnd);
list($sql, $ftsql) = $search_s->buildSearchSQL($this->_keyType, $query, $columns, $sql);
+
$search_s->setSQL($sql);
$search_s->setFTSQL($ftsql);
$search_s->setRank(5);
@@ -405,18 +396,6 @@
$sql .= COM_getPermSQL('AND',0,2,'s') . COM_getTopicSQL('AND',0,'s') . COM_getLangSQL('sid','AND','s') . ") ";
$sql .= "WHERE (u.uid = c.uid) AND (s.draft_flag = 0) AND (s.commentcode >= 0) AND (s.date <= NOW()) ";
- if (!empty($this->_dateStart) && !empty($this->_dateEnd))
- {
- $delim = substr($this->_dateStart, 4, 1);
- if (!empty($delim))
- {
- $DS = explode($delim, $this->_dateStart);
- $DE = explode($delim, $this->_dateEnd);
- $startdate = mktime(0,0,0,$DS[1],$DS[2],$DS[0]);
- $enddate = mktime(23,59,59,$DE[1],$DE[2],$DE[0]);
- $sql .= "AND (UNIX_TIMESTAMP(c.date) BETWEEN '$startdate' AND '$enddate') ";
- }
- }
if (!empty($this->_topic)) {
$sql .= "AND (s.tid = '$this->_topic') ";
}
@@ -425,8 +404,11 @@
}
$search_c = new SearchCriteria('comments', array($LANG09[65],$LANG09[66]));
+
$columns = array('title' => 'c.title', 'comment');
+ $sql .= $search_c->getDateRangeSQL('AND', 'c.date', $this->_dateStart, $this->_dateEnd);
list($sql, $ftsql) = $search_c->buildSearchSQL($this->_keyType, $query, $columns, $sql);
+
$search_c->setSQL($sql);
$search_c->setFTSQL($ftsql);
$search_c->setRank(2);
diff -r db4c6eb6e843 -r 187ee0efcee2 system/classes/searchcriteria.class.php
--- a/system/classes/searchcriteria.class.php Sun Sep 27 21:26:06 2009 +0200
+++ b/system/classes/searchcriteria.class.php Thu Oct 01 00:07:25 2009 +0100
@@ -204,6 +204,24 @@
return array($sql,$ftsql);
}
+
+ function getDateRangeSQL( $type = 'WHERE', $column, $datestart, $dateend )
+ {
+ if (!empty($datestart) && !empty($dateend))
+ {
+ $delim = substr($datestart, 4, 1);
+ if (!empty($delim))
+ {
+ $DS = explode($delim, $datestart);
+ $DE = explode($delim, $dateend);
+ $startdate = mktime(0,0,0,$DS[1],$DS[2],$DS[0]);
+ $enddate = mktime(23,59,59,$DE[1],$DE[2],$DE[0]);
+ return " $type (UNIX_TIMESTAMP($column) BETWEEN '$startdate' AND '$enddate') ";
+ }
+ }
+
+ return "";
+ }
}
?>
More information about the geeklog-cvs
mailing list