diff options
| author | 2020-01-18 11:58:46 +0100 | |
|---|---|---|
| committer | 2020-01-18 11:58:46 +0100 | |
| commit | 01576e6317a9125133d7352f95bd9011083e0c2d (patch) | |
| tree | 6d6c8bc6a3201c737d702639b23d47abe69f571f | |
| parent | 8eabc068c900c96cb06c2403414c3e0bf9387f34 (diff) | |
[API, extension] Use 'dateAdded()' to forge 'crawlTimeMsec' & 'timestampUsec' field in greader API. (#2773)
- Add the ability to customize 'dateAdded()', so an extension can change it if needed.
| -rw-r--r-- | app/Models/Entry.php | 21 | ||||
| -rw-r--r-- | p/api/greader.php | 4 |
2 files changed, 20 insertions, 5 deletions
diff --git a/app/Models/Entry.php b/app/Models/Entry.php index 2aa99baa9..b8422832b 100644 --- a/app/Models/Entry.php +++ b/app/Models/Entry.php @@ -14,6 +14,7 @@ class FreshRSS_Entry extends Minz_Model { private $content; private $link; private $date; + private $date_added = 0; //In microseconds private $hash = null; private $is_read; //Nullable boolean private $is_favorite; @@ -68,11 +69,15 @@ class FreshRSS_Entry extends Minz_Model { return timestamptodate($this->date); } } - public function dateAdded($raw = false) { - $date = intval(substr($this->id, 0, -6)); + public function dateAdded($raw = false, $microsecond = false) { if ($raw) { - return $date; + if ($microsecond) { + return $this->date_added; + } else { + return intval(substr($this->id, 0, -6)); + } } else { + $date = intval(substr($this->id, 0, -6)); return timestamptodate($date); } } @@ -119,6 +124,9 @@ class FreshRSS_Entry extends Minz_Model { public function _id($value) { $this->id = $value; + if ($this->date_added == 0) { + $this->date_added = $value; + } } public function _guid($value) { if ($value == '') { @@ -161,6 +169,13 @@ class FreshRSS_Entry extends Minz_Model { $value = intval($value); $this->date = $value > 1 ? $value : time(); } + public function _dateAdded($value, $microsecond = false) { + if ($microsecond) { + $this->date_added = $value; + } else { + $this->date_added = $value * 1000000; + } + } public function _isRead($value) { $this->is_read = $value === null ? null : (bool)$value; } diff --git a/p/api/greader.php b/p/api/greader.php index 159ee1941..c63ed12fa 100644 --- a/p/api/greader.php +++ b/p/api/greader.php @@ -496,8 +496,8 @@ function entriesToArray($entries) { } $item = array( 'id' => 'tag:google.com,2005:reader/item/' . dec2hex($entry->id()), //64-bit hexa http://code.google.com/p/google-reader-api/wiki/ItemId - 'crawlTimeMsec' => substr($entry->id(), 0, -3), - 'timestampUsec' => '' . $entry->id(), //EasyRSS + 'crawlTimeMsec' => substr($entry->dateAdded(true, true), 0, -3), + 'timestampUsec' => '' . $entry->dateAdded(true, true), //EasyRSS & Reeder 'published' => $entry->date(true), 'title' => escapeToUnicodeAlternative($entry->title(), false), 'summary' => array('content' => $entry->content()), |
