Explorar o código

ajout export au format Uniflux

Marien Fressinaud %!s(int64=13) %!d(string=hai) anos
pai
achega
f528d2c315

+ 7 - 0
app/configuration/routes.php

@@ -44,6 +44,13 @@ return array (
 		'action'     => 'main'
 		'action'     => 'main'
 	),
 	),
 	
 	
+	// API
+	array (
+		'route'      => '/api/get_favorites',
+		'controller' => 'api',
+		'action'     => 'getFavorites'
+	),
+	
 	// Entry
 	// Entry
 	array (
 	array (
 		'route'      => '/articles/marquer.php\?id=([\w\d\-_]{6})&lu=([\d]{1})',
 		'route'      => '/articles/marquer.php\?id=([\w\d\-_]{6})&lu=([\d]{1})',

+ 38 - 0
app/controllers/apiController.php

@@ -0,0 +1,38 @@
+<?php
+  
+class apiController extends ActionController {
+	public function getFavoritesAction () {
+		header('Content-type: application/json');
+
+		$this->view->_useLayout (false);
+
+		$entryDAO = new EntryDAO ();
+		$entryDAO->_nbItemsPerPage (-1);
+
+		$entries_tmp = $entryDAO->listFavorites ('all', 'low_to_high');
+
+		$entries = array ();
+		
+		foreach ($entries_tmp as $e) {
+			$author = $e->author ();
+			$feed = $e->feed (true);
+			$content = 'Article publié initialement sur <a href="' . $feed->website () . '">' . $feed->name () . '</a>';
+			if($author != '') {
+				$content .= ' par ' . $author;
+			}
+			$content .= ', mis en favoris dans <a href="https://github.com/marienfressinaud/FreshRSS">FreshRSS</a>';
+
+			$id = $e->id ();
+			$entries[$id] = array ();
+			$entries[$id]['title'] = $e->title ();
+			$entries[$id]['content'] = $content;
+			$entries[$id]['date'] = $e->date (true);
+			$entries[$id]['lastUpdate'] = $e->date (true);
+			$entries[$id]['tags'] = array ();
+			$entries[$id]['url'] = $e->link ();
+			$entries[$id]['type'] = 'url';
+		}
+		
+		$this->view->entries = $entries;
+	}
+}

+ 10 - 5
app/models/Entry.php

@@ -250,12 +250,17 @@ class EntryDAO extends Model_pdo {
 		$res = $stm->fetchAll (PDO::FETCH_ASSOC);
 		$res = $stm->fetchAll (PDO::FETCH_ASSOC);
 		$this->nbItems = $res[0]['count'];
 		$this->nbItems = $res[0]['count'];
 		
 		
-		$deb = ($this->currentPage - 1) * $this->nbItemsPerPage;
-		$fin = $this->nbItemsPerPage;
+		if($this->nbItemsPerPage < 0) {
+			$sql = 'SELECT * FROM entry' . $where
+			     . ' ORDER BY date' . $order;
+		} else {
+			$deb = ($this->currentPage - 1) * $this->nbItemsPerPage;
+			$fin = $this->nbItemsPerPage;
 		
 		
-		$sql = 'SELECT * FROM entry' . $where
-		     . ' ORDER BY date' . $order
-		     . ' LIMIT ' . $deb . ', ' . $fin;
+			$sql = 'SELECT * FROM entry' . $where
+			     . ' ORDER BY date' . $order
+			     . ' LIMIT ' . $deb . ', ' . $fin;
+		}
 		$stm = $this->bd->prepare ($sql);
 		$stm = $this->bd->prepare ($sql);
 		
 		
 		$stm->execute ();
 		$stm->execute ();

+ 3 - 0
app/views/api/getFavorites.phtml

@@ -0,0 +1,3 @@
+<?php
+echo json_encode ($this->entries);
+?>