diff options
| author | 2018-12-22 13:22:20 +0100 | |
|---|---|---|
| committer | 2018-12-22 13:22:20 +0100 | |
| commit | f0a359619fa2936d66a2b96dd086d4686e7405fa (patch) | |
| tree | ddad42a7f6813bd458f39d5203d083daad4cc1c5 /app/Models | |
| parent | e04804d0f67dd43fd3f072b9a127768ee7b7b56c (diff) | |
| parent | 4a1a852f457d52fa47191e3f7e3e9073e1324cd9 (diff) | |
Merge pull request #2186 from FreshRSS/dev1.13.0
FreshRSS 1.13.0
Diffstat (limited to 'app/Models')
| -rw-r--r-- | app/Models/Auth.php | 12 | ||||
| -rw-r--r-- | app/Models/BooleanSearch.php | 8 | ||||
| -rw-r--r-- | app/Models/ConfigurationSetter.php | 3 | ||||
| -rw-r--r-- | app/Models/EntryDAO.php | 13 | ||||
| -rw-r--r-- | app/Models/Feed.php | 21 | ||||
| -rw-r--r-- | app/Models/FeedDAO.php | 8 | ||||
| -rw-r--r-- | app/Models/Search.php | 8 | ||||
| -rw-r--r-- | app/Models/TagDAO.php | 2 |
8 files changed, 56 insertions, 19 deletions
diff --git a/app/Models/Auth.php b/app/Models/Auth.php index 8c711308c..9c3e31952 100644 --- a/app/Models/Auth.php +++ b/app/Models/Auth.php @@ -233,9 +233,11 @@ class FreshRSS_FormAuth { $token_file = DATA_PATH . '/tokens/' . $token . '.txt'; $mtime = @filemtime($token_file); - if ($mtime + 2629744 < time()) { - // Token has expired (> 1 month) or does not exist. - // TODO: 1 month -> use a configuration instead + $conf = Minz_Configuration::get('system'); + $limits = $conf->limits; + $cookie_duration = empty($limits['cookie_duration']) ? 2592000 : $limits['cookie_duration']; + if ($mtime + $cookie_duration < time()) { + // Token has expired (> cookie_duration) or does not exist. @unlink($token_file); return array(); } @@ -256,7 +258,7 @@ class FreshRSS_FormAuth { } $limits = $conf->limits; - $cookie_duration = empty($limits['cookie_duration']) ? 2629744 : $limits['cookie_duration']; + $cookie_duration = empty($limits['cookie_duration']) ? 2592000 : $limits['cookie_duration']; $expire = time() + $cookie_duration; Minz_Session::setLongTermCookie('FreshRSS_login', $token, $expire); return $token; @@ -277,7 +279,7 @@ class FreshRSS_FormAuth { public static function purgeTokens() { $conf = Minz_Configuration::get('system'); $limits = $conf->limits; - $cookie_duration = empty($limits['cookie_duration']) ? 2629744 : $limits['cookie_duration']; + $cookie_duration = empty($limits['cookie_duration']) ? 2592000 : $limits['cookie_duration']; $oldest = time() - $cookie_duration; foreach (new DirectoryIterator(DATA_PATH . '/tokens/') as $file_info) { // $extension = $file_info->getExtension(); doesn't work in PHP < 5.3.7 diff --git a/app/Models/BooleanSearch.php b/app/Models/BooleanSearch.php index 6e016f7e9..88eeea73c 100644 --- a/app/Models/BooleanSearch.php +++ b/app/Models/BooleanSearch.php @@ -45,6 +45,14 @@ class FreshRSS_BooleanSearch { return $this->searches; } + public function add($search) { + if ($search instanceof FreshRSS_Search) { + $this->searches[] = $search; + return $search; + } + return null; + } + public function __toString() { return $this->getRawInput(); } diff --git a/app/Models/ConfigurationSetter.php b/app/Models/ConfigurationSetter.php index ad703dfc5..ec6380df4 100644 --- a/app/Models/ConfigurationSetter.php +++ b/app/Models/ConfigurationSetter.php @@ -335,6 +335,9 @@ class FreshRSS_ConfigurationSetter { private function _limits(&$data, $values) { $max_small_int = 16384; $limits_keys = array( + 'cookie_duration' => array( + 'min' => 0, + ), 'cache_duration' => array( 'min' => 0, ), diff --git a/app/Models/EntryDAO.php b/app/Models/EntryDAO.php index a01c2227b..6d77a33cd 100644 --- a/app/Models/EntryDAO.php +++ b/app/Models/EntryDAO.php @@ -671,6 +671,15 @@ class FreshRSS_EntryDAO extends Minz_ModelPdo implements FreshRSS_Searchable { return isset($entries[0]) ? $entries[0] : null; } + public function searchIdByGuid($id_feed, $guid) { + $sql = 'SELECT id FROM `' . $this->prefix . 'entry` WHERE id_feed=? AND guid=?'; + $stm = $this->bd->prepare($sql); + $values = array($id_feed, $guid); + $stm->execute($values); + $res = $stm->fetchAll(PDO::FETCH_COLUMN, 0); + return isset($res[0]) ? $res[0] : null; + } + protected function sqlConcat($s1, $s2) { return 'CONCAT(' . $s1 . ',' . $s2 . ')'; //MySQL } @@ -912,8 +921,8 @@ class FreshRSS_EntryDAO extends Minz_ModelPdo implements FreshRSS_Searchable { return self::daoToEntries($stm->fetchAll(PDO::FETCH_ASSOC)); } - public function listIdsWhere($type = 'a', $id = '', $state = FreshRSS_Entry::STATE_ALL, $order = 'DESC', $limit = 1, $firstId = '', $filters = null, $date_min = 0) { //For API - list($values, $sql) = $this->sqlListWhere($type, $id, $state, $order, $limit, $firstId, $filters, $date_min); + public function listIdsWhere($type = 'a', $id = '', $state = FreshRSS_Entry::STATE_ALL, $order = 'DESC', $limit = 1, $firstId = '', $filters = null) { //For API + list($values, $sql) = $this->sqlListWhere($type, $id, $state, $order, $limit, $firstId, $filters); $stm = $this->bd->prepare($sql); $stm->execute($values); diff --git a/app/Models/Feed.php b/app/Models/Feed.php index e1dd2990d..b21a8bbbe 100644 --- a/app/Models/Feed.php +++ b/app/Models/Feed.php @@ -424,7 +424,7 @@ class FreshRSS_Feed extends Minz_Model { $author_names = ''; if (is_array($authors)) { foreach ($authors as $author) { - $author_names .= html_only_entity_decode(strip_tags($author->name == '' ? $author->email : $author->name)) . '; '; + $author_names .= escapeToUnicodeAlternative(strip_tags($author->name == '' ? $author->email : $author->name), true) . '; '; } } $author_names = substr($author_names, 0, -2); @@ -498,7 +498,7 @@ class FreshRSS_Feed extends Minz_Model { @unlink($this->lockPath); } - //<PubSubHubbub> + //<WebSub> public function pubSubHubbubEnabled() { $url = $this->selfUrl ? $this->selfUrl : $this->url; @@ -534,13 +534,13 @@ class FreshRSS_Feed extends Minz_Model { if ($hubFile = @file_get_contents($hubFilename)) { $hubJson = json_decode($hubFile, true); if (!$hubJson || empty($hubJson['key']) || !ctype_xdigit($hubJson['key'])) { - $text = 'Invalid JSON for PubSubHubbub: ' . $this->url; + $text = 'Invalid JSON for WebSub: ' . $this->url; Minz_Log::warning($text); Minz_Log::warning($text, PSHB_LOG); return false; } if ((!empty($hubJson['lease_end'])) && ($hubJson['lease_end'] < (time() + (3600 * 23)))) { //TODO: Make a better policy - $text = 'PubSubHubbub lease ends at ' + $text = 'WebSub lease ends at ' . date('c', empty($hubJson['lease_end']) ? time() : $hubJson['lease_end']) . ' and needs renewal: ' . $this->url; Minz_Log::warning($text); @@ -560,7 +560,7 @@ class FreshRSS_Feed extends Minz_Model { file_put_contents($hubFilename, json_encode($hubJson)); @mkdir(PSHB_PATH . '/keys/'); file_put_contents(PSHB_PATH . '/keys/' . $key . '.txt', base64url_encode($this->selfUrl)); - $text = 'PubSubHubbub prepared for ' . $this->url; + $text = 'WebSub prepared for ' . $this->url; Minz_Log::debug($text); Minz_Log::debug($text, PSHB_LOG); } @@ -579,17 +579,17 @@ class FreshRSS_Feed extends Minz_Model { $hubFilename = PSHB_PATH . '/feeds/' . base64url_encode($url) . '/!hub.json'; $hubFile = @file_get_contents($hubFilename); if ($hubFile === false) { - Minz_Log::warning('JSON not found for PubSubHubbub: ' . $this->url); + Minz_Log::warning('JSON not found for WebSub: ' . $this->url); return false; } $hubJson = json_decode($hubFile, true); if (!$hubJson || empty($hubJson['key']) || !ctype_xdigit($hubJson['key']) || empty($hubJson['hub'])) { - Minz_Log::warning('Invalid JSON for PubSubHubbub: ' . $this->url); + Minz_Log::warning('Invalid JSON for WebSub: ' . $this->url); return false; } $callbackUrl = checkUrl(Minz_Request::getBaseUrl() . '/api/pshb.php?k=' . $hubJson['key']); if ($callbackUrl == '') { - Minz_Log::warning('Invalid callback for PubSubHubbub: ' . $this->url); + Minz_Log::warning('Invalid callback for WebSub: ' . $this->url); return false; } if (!$state) { //unsubscribe @@ -618,7 +618,8 @@ class FreshRSS_Feed extends Minz_Model { $response = curl_exec($ch); $info = curl_getinfo($ch); - Minz_Log::warning('PubSubHubbub ' . ($state ? 'subscribe' : 'unsubscribe') . ' to ' . $url . + Minz_Log::warning('WebSub ' . ($state ? 'subscribe' : 'unsubscribe') . ' to ' . $url . + ' via hub ' . $hubJson['hub'] . ' with callback ' . $callbackUrl . ': ' . $info['http_code'] . ' ' . $response, PSHB_LOG); if (substr($info['http_code'], 0, 1) == '2') { @@ -633,5 +634,5 @@ class FreshRSS_Feed extends Minz_Model { return false; } - //</PubSubHubbub> + //</WebSub> } diff --git a/app/Models/FeedDAO.php b/app/Models/FeedDAO.php index e579f5881..7f00642f4 100644 --- a/app/Models/FeedDAO.php +++ b/app/Models/FeedDAO.php @@ -465,9 +465,15 @@ UPDATE `{$this->prefix}feed` SQL; $stm = $this->bd->prepare($sql); if (!($stm && $stm->execute(array(':new_value' => FreshRSS_Feed::TTL_DEFAULT, ':old_value' => -2)))) { + $info = $stm == null ? array(2 => 'syntax error') : $stm->errorInfo(); + Minz_Log::error('SQL warning updateTTL 1: ' . $info[2] . ' ' . $sql); + $sql2 = 'ALTER TABLE `' . $this->prefix . 'feed` ADD COLUMN ttl INT NOT NULL DEFAULT ' . FreshRSS_Feed::TTL_DEFAULT; //v0.7.3 $stm = $this->bd->prepare($sql2); - $stm->execute(); + if (!($stm && $stm->execute())) { + $info = $stm == null ? array(2 => 'syntax error') : $stm->errorInfo(); + Minz_Log::error('SQL error updateTTL 2: ' . $info[2] . ' ' . $sql2); + } } else { $stm->execute(array(':new_value' => -3600, ':old_value' => -1)); } diff --git a/app/Models/Search.php b/app/Models/Search.php index c52e391fa..f9cda7354 100644 --- a/app/Models/Search.php +++ b/app/Models/Search.php @@ -73,10 +73,18 @@ class FreshRSS_Search { return $this->min_date; } + public function setMinDate($value) { + return $this->min_date = $value; + } + public function getMaxDate() { return $this->max_date; } + public function setMaxDate($value) { + return $this->max_date = $value; + } + public function getMinPubdate() { return $this->min_pubdate; } diff --git a/app/Models/TagDAO.php b/app/Models/TagDAO.php index 1b59c8971..b55d2b35d 100644 --- a/app/Models/TagDAO.php +++ b/app/Models/TagDAO.php @@ -266,7 +266,7 @@ class FreshRSS_TagDAO extends Minz_ModelPdo implements FreshRSS_Searchable { if (is_array($entries) && count($entries) > 0) { $sql .= ' AND et.id_entry IN (' . str_repeat('?,', count($entries) - 1). '?)'; foreach ($entries as $entry) { - $values[] = $entry->id(); + $values[] = is_array($entry) ? $entry['id'] : $entry->id(); } } $stm = $this->bd->prepare($sql); |
