summaryrefslogtreecommitdiff
path: root/functions.php
diff options
context:
space:
mode:
authorAndrew Dolgov <[email protected]>2011-03-05 10:02:49 +0300
committerAndrew Dolgov <[email protected]>2011-03-05 10:02:49 +0300
commitab4b768ff9e8692eb5ef0d4755a0f05be58cd6a6 (patch)
tree14d9523618d1d58d6d8bcd5635822298d7040976 /functions.php
parenta089699c8915636ba4f158d77dba9b012bc93208 (diff)
allow searching for date using @keyword syntax
Diffstat (limited to 'functions.php')
-rw-r--r--functions.php75
1 files changed, 37 insertions, 38 deletions
diff --git a/functions.php b/functions.php
index 3d02d6c8b..33ac51d22 100644
--- a/functions.php
+++ b/functions.php
@@ -2145,6 +2145,24 @@
return $rv;
}
+ function convert_timestamp($timestamp, $source_tz, $dest_tz) {
+
+ try {
+ $source_tz = new DateTimeZone($source_tz);
+ } catch (Exception $e) {
+ $source_tz = new DateTimeZone('UTC');
+ }
+
+ try {
+ $dest_tz = new DateTimeZone($dest_tz);
+ } catch (Exception $e) {
+ $dest_tz = new DateTimeZone('UTC');
+ }
+
+ $dt = new DateTime(date('Y-m-d H:i:s', $timestamp), $source_tz);
+ return $dt->format('U') + $dest_tz->getOffset($dt);
+ }
+
function make_local_datetime($link, $timestamp, $long, $owner_uid = false,
$no_smart_dt = false) {
@@ -3220,54 +3238,35 @@
return $data;
}
- function getSearchSql($search, $match_on) {
+ function getSearchSql($link, $search, $match_on) {
$search_query_part = "";
$keywords = split(" ", $search);
$query_keywords = array();
- if ($match_on == "both") {
-
- foreach ($keywords as $k) {
- if (strpos($k, "-") === 0) {
- $k = substr($k, 1);
- $not = "NOT";
- } else {
- $not = "";
- }
-
- array_push($query_keywords, "(UPPER(ttrss_entries.title) $not LIKE UPPER('%$k%')
- OR UPPER(ttrss_entries.content) $not LIKE UPPER('%$k%'))");
+ foreach ($keywords as $k) {
+ if (strpos($k, "-") === 0) {
+ $k = substr($k, 1);
+ $not = "NOT";
+ } else {
+ $not = "";
}
- $search_query_part = implode("AND", $query_keywords) . " AND ";
+ if (strpos($k, "@") === 0) {
- } else if ($match_on == "title") {
-
- foreach ($keywords as $k) {
- if (strpos($k, "-") === 0) {
- $k = substr($k, 1);
- $not = "NOT";
- } else {
- $not = "";
- }
+ $user_tz_string = get_pref($link, 'USER_TIMEZONE', $_SESSION['uid']);
+ $orig_ts = strtotime(substr($k, 1));
+ $k = date("Y-m-d", convert_timestamp($orig_ts, $user_tz_string, 'UTC'));
+
+ array_push($query_keywords, "(".SUBSTRING_FOR_DATE."(updated,1,LENGTH('$k')) $not = '$k')");
+ } else if ($match_on == "both") {
+ array_push($query_keywords, "(UPPER(ttrss_entries.title) $not LIKE UPPER('%$k%')
+ OR UPPER(ttrss_entries.content) $not LIKE UPPER('%$k%'))");
+ } else if ($match_on == "title") {
array_push($query_keywords, "(UPPER(ttrss_entries.title) $not LIKE UPPER('%$k%'))");
- }
-
- $search_query_part = implode("AND", $query_keywords) . " AND ";
-
- } else if ($match_on == "content") {
-
- foreach ($keywords as $k) {
- if (strpos($k, "-") === 0) {
- $k = substr($k, 1);
- $not = "NOT";
- } else {
- $not = "";
- }
-
+ } else if ($match_on == "content") {
array_push($query_keywords, "(UPPER(ttrss_entries.content) $not LIKE UPPER('%$k%'))");
}
}
@@ -3294,7 +3293,7 @@
$search_query_part = "ref_id = -1 AND ";
} else {
- $search_query_part = getSearchSql($search, $match_on);
+ $search_query_part = getSearchSql($link, $search, $match_on);
$search_query_part .= " AND ";
}