aboutsummaryrefslogtreecommitdiffhomepage
path: root/inc
diff options
context:
space:
mode:
authornicosomb <nicolas@loeuillet.org>2013-04-18 10:15:46 +0200
committernicosomb <nicolas@loeuillet.org>2013-04-18 10:15:46 +0200
commitd06f30ef931402a1e56aab841ce852b3b81a9697 (patch)
treec6250f8b0b2d2eb369f396bc31f6842a08d54c88 /inc
parent64458521c36de87d10f1c726667faeaaa5126840 (diff)
downloadwallabag-d06f30ef931402a1e56aab841ce852b3b81a9697.tar.gz
wallabag-d06f30ef931402a1e56aab841ce852b3b81a9697.tar.zst
wallabag-d06f30ef931402a1e56aab841ce852b3b81a9697.zip
Fixed #54 - récupération de l'id améliorée et utilisation de action_to_do() pour l'insertion dans l'import pocket
Diffstat (limited to 'inc')
-rw-r--r--inc/config.php3
-rw-r--r--inc/functions.php30
2 files changed, 19 insertions, 14 deletions
diff --git a/inc/config.php b/inc/config.php
index 4db3cf40..386fd036 100644
--- a/inc/config.php
+++ b/inc/config.php
@@ -14,6 +14,7 @@ if (!is_dir('db/')) {
14 14
15define ('DB_PATH', 'sqlite:./db/poche.sqlite'); 15define ('DB_PATH', 'sqlite:./db/poche.sqlite');
16define ('ABS_PATH', 'assets/'); 16define ('ABS_PATH', 'assets/');
17define ('CONVERT_LINKS_FOOTNOTES', TRUE);
17define ('DOWNLOAD_PICTURES', TRUE); 18define ('DOWNLOAD_PICTURES', TRUE);
18 19
19include 'db.php'; 20include 'db.php';
@@ -50,5 +51,5 @@ $url = (isset ($_GET['url'])) ? $_GET['url'] : '';
50$token = (isset ($_REQUEST['token'])) ? $_REQUEST['token'] : ''; 51$token = (isset ($_REQUEST['token'])) ? $_REQUEST['token'] : '';
51 52
52if ($action != '') { 53if ($action != '') {
53 action_to_do($action, $id, $url, $token); 54 action_to_do($action, $url, $token, $id);
54} 55}
diff --git a/inc/functions.php b/inc/functions.php
index f572d983..936ec6ea 100644
--- a/inc/functions.php
+++ b/inc/functions.php
@@ -88,7 +88,7 @@ function get_external_file($url)
88/** 88/**
89 * Préparation de l'URL avec récupération du contenu avant insertion en base 89 * Préparation de l'URL avec récupération du contenu avant insertion en base
90 */ 90 */
91function prepare_url($url, $id) 91function prepare_url($url)
92{ 92{
93 $parametres = array(); 93 $parametres = array();
94 $url = html_entity_decode(trim($url)); 94 $url = html_entity_decode(trim($url));
@@ -107,14 +107,11 @@ function prepare_url($url, $id)
107 if (isset($html) and strlen($html) > 0) 107 if (isset($html) and strlen($html) > 0)
108 { 108 {
109 $r = new Readability($html, $url); 109 $r = new Readability($html, $url);
110 $r->convertLinksToFootnotes = TRUE; 110 $r->convertLinksToFootnotes = CONVERT_LINKS_FOOTNOTES;
111 if($r->init()) 111 if($r->init())
112 { 112 {
113 $content = $r->articleContent->innerHTML; 113 $content = $r->articleContent->innerHTML;
114 $parametres['title'] = $r->articleTitle->innerHTML; 114 $parametres['title'] = $r->articleTitle->innerHTML;
115 if (DOWNLOAD_PICTURES) {
116 $content = filtre_picture($content, $url, $id);
117 }
118 $parametres['content'] = $content; 115 $parametres['content'] = $content;
119 return $parametres; 116 return $parametres;
120 } 117 }
@@ -233,7 +230,7 @@ function remove_directory($directory)
233 * Appel d'une action (mark as fav, archive, delete) 230 * Appel d'une action (mark as fav, archive, delete)
234 */ 231 */
235 232
236function action_to_do($action, $id, $url, $token) 233function action_to_do($action, $url, $token, $id = 0)
237{ 234{
238 global $db; 235 global $db;
239 236
@@ -243,13 +240,9 @@ function action_to_do($action, $id, $url, $token)
243 if ($url == '') 240 if ($url == '')
244 continue; 241 continue;
245 242
246 # FIXME corriger cette génération d'ID 243 if($parametres_url = prepare_url($url)) {
247 $req = $db->getHandle()->query("SELECT id FROM entries ORDER BY id DESC"); 244 $sql_action = 'INSERT INTO entries ( url, title, content ) VALUES (?, ?, ?)';
248 $id = $req->fetchColumn()+1; 245 $params_action = array($url, $parametres_url['title'], $parametres_url['content']);
249
250 if($parametres_url = prepare_url($url, $id)) {
251 $sql_action = 'INSERT INTO entries ( id, url, title, content ) VALUES (?,?, ?, ?)';
252 $params_action = array($id,$url, $parametres_url['title'], $parametres_url['content']);
253 } 246 }
254 247
255 logm('add link ' . $url); 248 logm('add link ' . $url);
@@ -290,6 +283,17 @@ function action_to_do($action, $id, $url, $token)
290 { 283 {
291 $query = $db->getHandle()->prepare($sql_action); 284 $query = $db->getHandle()->prepare($sql_action);
292 $query->execute($params_action); 285 $query->execute($params_action);
286 # if we add a link, we have to download pictures
287 if ($action == 'add') {
288 $last_id = $db->getHandle()->lastInsertId();
289 if (DOWNLOAD_PICTURES) {
290 $content = filtre_picture($parametres_url['content'], $url, $last_id);
291 $sql_update = "UPDATE entries SET content=? WHERE id=?";
292 $params_update = array($content, $last_id);
293 $query_update = $db->getHandle()->prepare($sql_update);
294 $query_update->execute($params_update);
295 }
296 }
293 } 297 }
294 } 298 }
295 catch (Exception $e) 299 catch (Exception $e)