EntryDAO.php 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538
  1. <?php
  2. class FreshRSS_EntryDAO extends Minz_ModelPdo {
  3. public function addEntry ($valuesTmp) {
  4. $sql = 'INSERT INTO `' . $this->prefix . 'entry`(id, guid, title, author, content_bin, link, date, is_read, is_favorite, id_feed, tags) '
  5. . 'VALUES(?, ?, ?, ?, COMPRESS(?), ?, ?, ?, ?, ?, ?)';
  6. $stm = $this->bd->prepare ($sql);
  7. $values = array (
  8. $valuesTmp['id'],
  9. substr($valuesTmp['guid'], 0, 760),
  10. substr($valuesTmp['title'], 0, 255),
  11. substr($valuesTmp['author'], 0, 255),
  12. $valuesTmp['content'],
  13. substr($valuesTmp['link'], 0, 1023),
  14. $valuesTmp['date'],
  15. $valuesTmp['is_read'] ? 1 : 0,
  16. $valuesTmp['is_favorite'] ? 1 : 0,
  17. $valuesTmp['id_feed'],
  18. substr($valuesTmp['tags'], 0, 1023),
  19. );
  20. if ($stm && $stm->execute ($values)) {
  21. return $this->bd->lastInsertId();
  22. } else {
  23. $info = $stm->errorInfo();
  24. if ((int)($info[0] / 1000) !== 23) { //Filter out "SQLSTATE Class code 23: Constraint Violation" because of expected duplicate entries
  25. Minz_Log::record ('SQL error ' . $info[0] . ': ' . $info[1] . ' ' . $info[2]
  26. . ' while adding entry in feed ' . $valuesTmp['id_feed'] . ' with title: ' . $valuesTmp['title'], Minz_Log::ERROR);
  27. } /*else {
  28. Minz_Log::record ('SQL error ' . $info[0] . ': ' . $info[1] . ' ' . $info[2]
  29. . ' while adding entry in feed ' . $valuesTmp['id_feed'] . ' with title: ' . $valuesTmp['title'], Minz_Log::DEBUG);
  30. }*/
  31. return false;
  32. }
  33. }
  34. public function markFavorite ($id, $is_favorite = true) {
  35. $sql = 'UPDATE `' . $this->prefix . 'entry` e '
  36. . 'SET e.is_favorite = ? '
  37. . 'WHERE e.id=?';
  38. $values = array ($is_favorite ? 1 : 0, $id);
  39. $stm = $this->bd->prepare ($sql);
  40. if ($stm && $stm->execute ($values)) {
  41. return $stm->rowCount();
  42. } else {
  43. $info = $stm->errorInfo();
  44. Minz_Log::record ('SQL error : ' . $info[2], Minz_Log::ERROR);
  45. return false;
  46. }
  47. }
  48. public function markRead ($id, $is_read = true) {
  49. $sql = 'UPDATE `' . $this->prefix . 'entry` e INNER JOIN `' . $this->prefix . 'feed` f ON e.id_feed = f.id '
  50. . 'SET e.is_read = ?,'
  51. . 'f.cache_nbUnreads=f.cache_nbUnreads' . ($is_read ? '-' : '+') . '1 '
  52. . 'WHERE e.id=?';
  53. $values = array ($is_read ? 1 : 0, $id);
  54. $stm = $this->bd->prepare ($sql);
  55. if ($stm && $stm->execute ($values)) {
  56. return $stm->rowCount();
  57. } else {
  58. $info = $stm->errorInfo();
  59. Minz_Log::record ('SQL error : ' . $info[2], Minz_Log::ERROR);
  60. return false;
  61. }
  62. }
  63. public function markReadEntries ($idMax = 0, $onlyFavorites = false, $priorityMin = 0) {
  64. if ($idMax == 0) {
  65. $sql = 'UPDATE `' . $this->prefix . 'entry` e INNER JOIN `' . $this->prefix . 'feed` f ON e.id_feed = f.id '
  66. . 'SET e.is_read = 1, f.cache_nbUnreads=0 '
  67. . 'WHERE e.is_read = 0';
  68. if ($onlyFavorites) {
  69. $sql .= ' AND e.is_favorite = 1';
  70. } elseif ($priorityMin >= 0) {
  71. $sql .= ' AND f.priority > ' . intval($priorityMin);
  72. }
  73. $stm = $this->bd->prepare ($sql);
  74. if ($stm && $stm->execute ()) {
  75. return $stm->rowCount();
  76. } else {
  77. $info = $stm->errorInfo();
  78. Minz_Log::record ('SQL error : ' . $info[2], Minz_Log::ERROR);
  79. return false;
  80. }
  81. } else {
  82. $this->bd->beginTransaction ();
  83. $sql = 'UPDATE `' . $this->prefix . 'entry` e INNER JOIN `' . $this->prefix . 'feed` f ON e.id_feed = f.id '
  84. . 'SET e.is_read = 1 '
  85. . 'WHERE e.is_read = 0 AND e.id <= ?';
  86. if ($onlyFavorites) {
  87. $sql .= ' AND e.is_favorite = 1';
  88. } elseif ($priorityMin >= 0) {
  89. $sql .= ' AND f.priority > ' . intval($priorityMin);
  90. }
  91. $values = array ($idMax);
  92. $stm = $this->bd->prepare ($sql);
  93. if (!($stm && $stm->execute ($values))) {
  94. $info = $stm->errorInfo();
  95. Minz_Log::record ('SQL error : ' . $info[2], Minz_Log::ERROR);
  96. $this->bd->rollBack ();
  97. return false;
  98. }
  99. $affected = $stm->rowCount();
  100. if ($affected > 0) {
  101. $sql = 'UPDATE `' . $this->prefix . 'feed` f '
  102. . 'LEFT OUTER JOIN ('
  103. . 'SELECT e.id_feed, '
  104. . 'COUNT(*) AS nbUnreads '
  105. . 'FROM `' . $this->prefix . 'entry` e '
  106. . 'WHERE e.is_read = 0 '
  107. . 'GROUP BY e.id_feed'
  108. . ') x ON x.id_feed=f.id '
  109. . 'SET f.cache_nbUnreads=COALESCE(x.nbUnreads, 0)';
  110. $stm = $this->bd->prepare ($sql);
  111. if (!($stm && $stm->execute ())) {
  112. $info = $stm->errorInfo();
  113. Minz_Log::record ('SQL error : ' . $info[2], Minz_Log::ERROR);
  114. $this->bd->rollBack ();
  115. return false;
  116. }
  117. }
  118. $this->bd->commit ();
  119. return $affected;
  120. }
  121. }
  122. public function markReadCat ($id, $idMax = 0) {
  123. if ($idMax == 0) {
  124. $sql = 'UPDATE `' . $this->prefix . 'entry` e INNER JOIN `' . $this->prefix . 'feed` f ON e.id_feed = f.id '
  125. . 'SET e.is_read = 1, f.cache_nbUnreads=0 '
  126. . 'WHERE f.category = ? AND e.is_read = 0';
  127. $values = array ($id);
  128. $stm = $this->bd->prepare ($sql);
  129. if ($stm && $stm->execute ($values)) {
  130. return $stm->rowCount();
  131. } else {
  132. $info = $stm->errorInfo();
  133. Minz_Log::record ('SQL error : ' . $info[2], Minz_Log::ERROR);
  134. return false;
  135. }
  136. } else {
  137. $this->bd->beginTransaction ();
  138. $sql = 'UPDATE `' . $this->prefix . 'entry` e INNER JOIN `' . $this->prefix . 'feed` f ON e.id_feed = f.id '
  139. . 'SET e.is_read = 1 '
  140. . 'WHERE f.category = ? AND e.is_read = 0 AND e.id <= ?';
  141. $values = array ($id, $idMax);
  142. $stm = $this->bd->prepare ($sql);
  143. if (!($stm && $stm->execute ($values))) {
  144. $info = $stm->errorInfo();
  145. Minz_Log::record ('SQL error : ' . $info[2], Minz_Log::ERROR);
  146. $this->bd->rollBack ();
  147. return false;
  148. }
  149. $affected = $stm->rowCount();
  150. if ($affected > 0) {
  151. $sql = 'UPDATE `' . $this->prefix . 'feed` f '
  152. . 'LEFT OUTER JOIN ('
  153. . 'SELECT e.id_feed, '
  154. . 'COUNT(*) AS nbUnreads '
  155. . 'FROM `' . $this->prefix . 'entry` e '
  156. . 'WHERE e.is_read = 0 '
  157. . 'GROUP BY e.id_feed'
  158. . ') x ON x.id_feed=f.id '
  159. . 'SET f.cache_nbUnreads=COALESCE(x.nbUnreads, 0) '
  160. . 'WHERE f.category = ?';
  161. $values = array ($id);
  162. $stm = $this->bd->prepare ($sql);
  163. if (!($stm && $stm->execute ($values))) {
  164. $info = $stm->errorInfo();
  165. Minz_Log::record ('SQL error : ' . $info[2], Minz_Log::ERROR);
  166. $this->bd->rollBack ();
  167. return false;
  168. }
  169. }
  170. $this->bd->commit ();
  171. return $affected;
  172. }
  173. }
  174. public function markReadCatName($name, $idMax = 0) {
  175. if ($idMax == 0) {
  176. $sql = 'UPDATE `' . $this->prefix . 'entry` e '
  177. . 'INNER JOIN `' . $this->prefix . 'feed` f ON e.id_feed = f.id '
  178. . 'INNER JOIN `' . $this->prefix . 'category` c ON c.id = f.category '
  179. . 'SET e.is_read = 1, f.cache_nbUnreads=0 '
  180. . 'WHERE c.name = ?';
  181. $values = array($name);
  182. $stm = $this->bd->prepare($sql);
  183. if ($stm && $stm->execute($values)) {
  184. return $stm->rowCount();
  185. } else {
  186. $info = $stm->errorInfo();
  187. Minz_Log::record('SQL error : ' . $info[2], Minz_Log::ERROR);
  188. return false;
  189. }
  190. } else {
  191. $this->bd->beginTransaction();
  192. $sql = 'UPDATE `' . $this->prefix . 'entry` e '
  193. . 'INNER JOIN `' . $this->prefix . 'feed` f ON e.id_feed = f.id '
  194. . 'INNER JOIN `' . $this->prefix . 'category` c ON c.id = f.category '
  195. . 'SET e.is_read = 1 '
  196. . 'WHERE c.name = ? AND e.id <= ?';
  197. $values = array($name, $idMax);
  198. $stm = $this->bd->prepare($sql);
  199. if (!($stm && $stm->execute($values))) {
  200. $info = $stm->errorInfo();
  201. Minz_Log::record('SQL error : ' . $info[2], Minz_Log::ERROR);
  202. $this->bd->rollBack();
  203. return false;
  204. }
  205. $affected = $stm->rowCount();
  206. if ($affected > 0) {
  207. $sql = 'UPDATE `' . $this->prefix . 'feed` f '
  208. . 'LEFT OUTER JOIN ('
  209. . 'SELECT e.id_feed, '
  210. . 'COUNT(*) AS nbUnreads '
  211. . 'FROM `' . $this->prefix . 'entry` e '
  212. . 'WHERE e.is_read = 0 '
  213. . 'GROUP BY e.id_feed'
  214. . ') x ON x.id_feed=f.id '
  215. . 'INNER JOIN `' . $this->prefix . 'category` c ON c.id = f.category '
  216. . 'SET f.cache_nbUnreads=COALESCE(x.nbUnreads, 0) '
  217. . 'WHERE c.name = ?';
  218. $values = array($name);
  219. $stm = $this->bd->prepare($sql);
  220. if (!($stm && $stm->execute($values))) {
  221. $info = $stm->errorInfo();
  222. Minz_Log::record('SQL error : ' . $info[2], Minz_Log::ERROR);
  223. $this->bd->rollBack();
  224. return false;
  225. }
  226. }
  227. $this->bd->commit();
  228. return $affected;
  229. }
  230. }
  231. public function markReadFeed ($id, $idMax = 0) {
  232. if ($idMax == 0) {
  233. $sql = 'UPDATE `' . $this->prefix . 'entry` e INNER JOIN `' . $this->prefix . 'feed` f ON e.id_feed = f.id '
  234. . 'SET e.is_read = 1, f.cache_nbUnreads=0 '
  235. . 'WHERE f.id=? AND e.is_read = 0';
  236. $values = array ($id);
  237. $stm = $this->bd->prepare ($sql);
  238. if ($stm && $stm->execute ($values)) {
  239. return $stm->rowCount();
  240. } else {
  241. $info = $stm->errorInfo();
  242. Minz_Log::record ('SQL error : ' . $info[2], Minz_Log::ERROR);
  243. return false;
  244. }
  245. } else {
  246. $this->bd->beginTransaction ();
  247. $sql = 'UPDATE `' . $this->prefix . 'entry` e INNER JOIN `' . $this->prefix . 'feed` f ON e.id_feed = f.id '
  248. . 'SET e.is_read = 1 '
  249. . 'WHERE f.id=? AND e.is_read = 0 AND e.id <= ?';
  250. $values = array ($id, $idMax);
  251. $stm = $this->bd->prepare ($sql);
  252. if (!($stm && $stm->execute ($values))) {
  253. $info = $stm->errorInfo();
  254. Minz_Log::record ('SQL error : ' . $info[2], Minz_Log::ERROR);
  255. $this->bd->rollBack ();
  256. return false;
  257. }
  258. $affected = $stm->rowCount();
  259. if ($affected > 0) {
  260. $sql = 'UPDATE `' . $this->prefix . 'feed` f '
  261. . 'SET f.cache_nbUnreads=f.cache_nbUnreads-' . $affected
  262. . ' WHERE f.id=?';
  263. $values = array ($id);
  264. $stm = $this->bd->prepare ($sql);
  265. if (!($stm && $stm->execute ($values))) {
  266. $info = $stm->errorInfo();
  267. Minz_Log::record ('SQL error : ' . $info[2], Minz_Log::ERROR);
  268. $this->bd->rollBack ();
  269. return false;
  270. }
  271. }
  272. $this->bd->commit ();
  273. return $affected;
  274. }
  275. }
  276. public function searchByGuid ($feed_id, $id) {
  277. // un guid est unique pour un flux donné
  278. $sql = 'SELECT id, guid, title, author, UNCOMPRESS(content_bin) AS content, link, date, is_read, is_favorite, id_feed, tags '
  279. . 'FROM `' . $this->prefix . 'entry` WHERE id_feed=? AND guid=?';
  280. $stm = $this->bd->prepare ($sql);
  281. $values = array (
  282. $feed_id,
  283. $id
  284. );
  285. $stm->execute ($values);
  286. $res = $stm->fetchAll (PDO::FETCH_ASSOC);
  287. $entries = self::daoToEntry ($res);
  288. return isset ($entries[0]) ? $entries[0] : null;
  289. }
  290. public function searchById ($id) {
  291. $sql = 'SELECT id, guid, title, author, UNCOMPRESS(content_bin) AS content, link, date, is_read, is_favorite, id_feed, tags '
  292. . 'FROM `' . $this->prefix . 'entry` WHERE id=?';
  293. $stm = $this->bd->prepare ($sql);
  294. $values = array ($id);
  295. $stm->execute ($values);
  296. $res = $stm->fetchAll (PDO::FETCH_ASSOC);
  297. $entries = self::daoToEntry ($res);
  298. return isset ($entries[0]) ? $entries[0] : null;
  299. }
  300. public function listWhere($type = 'a', $id = '', $state = 'all', $order = 'DESC', $limit = 1, $firstId = '', $filter = '', $date_min = 0, $keepHistoryDefault = 0) {
  301. $where = '';
  302. $joinFeed = false;
  303. $values = array();
  304. switch ($type) {
  305. case 'a':
  306. $where .= 'f.priority > 0 ';
  307. $joinFeed = true;
  308. break;
  309. case 's':
  310. $where .= 'e1.is_favorite = 1 ';
  311. break;
  312. case 'c':
  313. $where .= 'f.category = ? ';
  314. $values[] = intval($id);
  315. $joinFeed = true;
  316. break;
  317. case 'f':
  318. $where .= 'e1.id_feed = ? ';
  319. $values[] = intval($id);
  320. break;
  321. case 'A':
  322. $where .= '1 ';
  323. break;
  324. default:
  325. throw new FreshRSS_EntriesGetter_Exception ('Bad type in Entry->listByType: [' . $type . ']!');
  326. }
  327. switch ($state) {
  328. case 'all':
  329. break;
  330. case 'not_read':
  331. $where .= 'AND e1.is_read = 0 ';
  332. break;
  333. case 'read':
  334. $where .= 'AND e1.is_read = 1 ';
  335. break;
  336. case 'favorite':
  337. $where .= 'AND e1.is_favorite = 1 ';
  338. break;
  339. default:
  340. throw new FreshRSS_EntriesGetter_Exception ('Bad state in Entry->listByType: [' . $state . ']!');
  341. }
  342. switch ($order) {
  343. case 'DESC':
  344. case 'ASC':
  345. break;
  346. default:
  347. throw new FreshRSS_EntriesGetter_Exception ('Bad order in Entry->listByType: [' . $order . ']!');
  348. }
  349. if ($firstId !== '') {
  350. $where .= 'AND e1.id ' . ($order === 'DESC' ? '<=' : '>=') . $firstId . ' ';
  351. }
  352. if (($date_min > 0) && ($type !== 's')) {
  353. $where .= 'AND (e1.id >= ' . $date_min . '000000 OR e1.is_read = 0 OR e1.is_favorite = 1 OR (f.keep_history <> 0';
  354. if (intval($keepHistoryDefault) === 0) {
  355. $where .= ' AND f.keep_history <> -2'; //default
  356. }
  357. $where .= ')) ';
  358. $joinFeed = true;
  359. }
  360. $search = '';
  361. if ($filter !== '') {
  362. $filter = trim($filter);
  363. $filter = addcslashes($filter, '\\%_');
  364. if (stripos($filter, 'intitle:') === 0) {
  365. $filter = substr($filter, strlen('intitle:'));
  366. $intitle = true;
  367. } else {
  368. $intitle = false;
  369. }
  370. if (stripos($filter, 'inurl:') === 0) {
  371. $filter = substr($filter, strlen('inurl:'));
  372. $inurl = true;
  373. } else {
  374. $inurl = false;
  375. }
  376. if (stripos($filter, 'author:') === 0) {
  377. $filter = substr($filter, strlen('author:'));
  378. $author = true;
  379. } else {
  380. $author = false;
  381. }
  382. $terms = array_unique(explode(' ', $filter));
  383. sort($terms); //Put #tags first
  384. foreach ($terms as $word) {
  385. $word = trim($word);
  386. if (strlen($word) > 0) {
  387. if ($intitle) {
  388. $search .= 'AND e1.title LIKE ? ';
  389. $values[] = '%' . $word .'%';
  390. } elseif ($inurl) {
  391. $search .= 'AND CONCAT(e1.link, e1.guid) LIKE ? ';
  392. $values[] = '%' . $word .'%';
  393. } elseif ($author) {
  394. $search .= 'AND e1.author LIKE ? ';
  395. $values[] = '%' . $word .'%';
  396. } else {
  397. if ($word[0] === '#' && isset($word[1])) {
  398. $search .= 'AND e1.tags LIKE ? ';
  399. $values[] = '%' . $word .'%';
  400. } else {
  401. $search .= 'AND CONCAT(e1.title, UNCOMPRESS(e1.content_bin)) LIKE ? ';
  402. $values[] = '%' . $word .'%';
  403. }
  404. }
  405. }
  406. }
  407. }
  408. $sql = 'SELECT e.id, e.guid, e.title, e.author, UNCOMPRESS(e.content_bin) AS content, e.link, e.date, e.is_read, e.is_favorite, e.id_feed, e.tags '
  409. . 'FROM `' . $this->prefix . 'entry` e '
  410. . 'INNER JOIN (SELECT e1.id FROM `' . $this->prefix . 'entry` e1 '
  411. . ($joinFeed ? 'INNER JOIN `' . $this->prefix . 'feed` f ON e1.id_feed = f.id ' : '')
  412. . 'WHERE ' . $where
  413. . $search
  414. . 'ORDER BY e1.id ' . $order
  415. . ($limit > 0 ? ' LIMIT ' . $limit : '') //TODO: See http://explainextended.com/2009/10/23/mysql-order-by-limit-performance-late-row-lookups/
  416. . ') e2 ON e2.id = e.id '
  417. . 'ORDER BY e.id ' . $order;
  418. $stm = $this->bd->prepare ($sql);
  419. $stm->execute ($values);
  420. return self::daoToEntry ($stm->fetchAll (PDO::FETCH_ASSOC));
  421. }
  422. public function listLastGuidsByFeed($id, $n) {
  423. $sql = 'SELECT guid FROM `' . $this->prefix . 'entry` WHERE id_feed=? ORDER BY id DESC LIMIT ' . intval($n);
  424. $stm = $this->bd->prepare ($sql);
  425. $values = array ($id);
  426. $stm->execute ($values);
  427. return $stm->fetchAll (PDO::FETCH_COLUMN, 0);
  428. }
  429. public function countUnreadRead () {
  430. $sql = 'SELECT COUNT(e.id) AS count FROM `' . $this->prefix . 'entry` e INNER JOIN `' . $this->prefix . 'feed` f ON e.id_feed = f.id WHERE priority > 0'
  431. . ' UNION SELECT COUNT(e.id) AS count FROM `' . $this->prefix . 'entry` e INNER JOIN `' . $this->prefix . 'feed` f ON e.id_feed = f.id WHERE priority > 0 AND is_read = 0';
  432. $stm = $this->bd->prepare ($sql);
  433. $stm->execute ();
  434. $res = $stm->fetchAll (PDO::FETCH_COLUMN, 0);
  435. $all = empty($res[0]) ? 0 : $res[0];
  436. $unread = empty($res[1]) ? 0 : $res[1];
  437. return array('all' => $all, 'unread' => $unread, 'read' => $all - $unread);
  438. }
  439. public function count ($minPriority = null) {
  440. $sql = 'SELECT COUNT(e.id) AS count FROM `' . $this->prefix . 'entry` e INNER JOIN `' . $this->prefix . 'feed` f ON e.id_feed = f.id';
  441. if ($minPriority !== null) {
  442. $sql = ' WHERE priority > ' . intval($minPriority);
  443. }
  444. $stm = $this->bd->prepare ($sql);
  445. $stm->execute ();
  446. $res = $stm->fetchAll (PDO::FETCH_COLUMN, 0);
  447. return $res[0];
  448. }
  449. public function countNotRead ($minPriority = null) {
  450. $sql = 'SELECT COUNT(e.id) AS count FROM `' . $this->prefix . 'entry` e INNER JOIN `' . $this->prefix . 'feed` f ON e.id_feed = f.id WHERE is_read = 0';
  451. if ($minPriority !== null) {
  452. $sql = ' AND priority > ' . intval($minPriority);
  453. }
  454. $stm = $this->bd->prepare ($sql);
  455. $stm->execute ();
  456. $res = $stm->fetchAll (PDO::FETCH_COLUMN, 0);
  457. return $res[0];
  458. }
  459. public function countUnreadReadFavorites () {
  460. $sql = 'SELECT COUNT(id) FROM `' . $this->prefix . 'entry` WHERE is_favorite=1'
  461. . ' UNION SELECT COUNT(id) FROM `' . $this->prefix . 'entry` WHERE is_favorite=1 AND is_read = 0';
  462. $stm = $this->bd->prepare ($sql);
  463. $stm->execute ();
  464. $res = $stm->fetchAll (PDO::FETCH_COLUMN, 0);
  465. $all = empty($res[0]) ? 0 : $res[0];
  466. $unread = empty($res[1]) ? 0 : $res[1];
  467. return array('all' => $all, 'unread' => $unread, 'read' => $all - $unread);
  468. }
  469. public function optimizeTable() {
  470. $sql = 'OPTIMIZE TABLE `' . $this->prefix . 'entry`';
  471. $stm = $this->bd->prepare ($sql);
  472. $stm->execute ();
  473. }
  474. public static function daoToEntry ($listDAO) {
  475. $list = array ();
  476. if (!is_array ($listDAO)) {
  477. $listDAO = array ($listDAO);
  478. }
  479. foreach ($listDAO as $key => $dao) {
  480. $entry = new FreshRSS_Entry (
  481. $dao['id_feed'],
  482. $dao['guid'],
  483. $dao['title'],
  484. $dao['author'],
  485. $dao['content'],
  486. $dao['link'],
  487. $dao['date'],
  488. $dao['is_read'],
  489. $dao['is_favorite'],
  490. $dao['tags']
  491. );
  492. if (isset ($dao['id'])) {
  493. $entry->_id ($dao['id']);
  494. }
  495. $list[] = $entry;
  496. }
  497. unset ($listDAO);
  498. return $list;
  499. }
  500. }