]> git.wh0rd.org - tt-rss.git/commitdiff
allow searching for date using @keyword syntax
authorAndrew Dolgov <fox@madoka.volgo-balt.ru>
Sat, 5 Mar 2011 07:02:49 +0000 (10:02 +0300)
committerAndrew Dolgov <fox@madoka.volgo-balt.ru>
Sat, 5 Mar 2011 07:02:49 +0000 (10:02 +0300)
functions.php

index 3d02d6c8b1945cfec1aa11f7156ca38ba6a1ce0b..33ac51d22a5b91512fcc5f00436179744dff6e96 100644 (file)
                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) {
 
                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%'))");
                        }
                }
                                                $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 ";
                                }