From d06f30ef931402a1e56aab841ce852b3b81a9697 Mon Sep 17 00:00:00 2001 From: nicosomb Date: Thu, 18 Apr 2013 10:15:46 +0200 Subject: =?UTF-8?q?Fixed=20#54=20-=20r=C3=A9cup=C3=A9ration=20de=20l'id=20?= =?UTF-8?q?am=C3=A9lior=C3=A9e=20et=20utilisation=20de=20action=5Fto=5Fdo(?= =?UTF-8?q?)=20pour=20l'insertion=20dans=20l'import=20pocket?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- inc/config.php | 3 ++- inc/functions.php | 30 +++++++++++++++++------------- 2 files changed, 19 insertions(+), 14 deletions(-) (limited to 'inc') 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/')) { define ('DB_PATH', 'sqlite:./db/poche.sqlite'); define ('ABS_PATH', 'assets/'); +define ('CONVERT_LINKS_FOOTNOTES', TRUE); define ('DOWNLOAD_PICTURES', TRUE); include 'db.php'; @@ -50,5 +51,5 @@ $url = (isset ($_GET['url'])) ? $_GET['url'] : ''; $token = (isset ($_REQUEST['token'])) ? $_REQUEST['token'] : ''; if ($action != '') { - action_to_do($action, $id, $url, $token); + action_to_do($action, $url, $token, $id); } 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) /** * Préparation de l'URL avec récupération du contenu avant insertion en base */ -function prepare_url($url, $id) +function prepare_url($url) { $parametres = array(); $url = html_entity_decode(trim($url)); @@ -107,14 +107,11 @@ function prepare_url($url, $id) if (isset($html) and strlen($html) > 0) { $r = new Readability($html, $url); - $r->convertLinksToFootnotes = TRUE; + $r->convertLinksToFootnotes = CONVERT_LINKS_FOOTNOTES; if($r->init()) { $content = $r->articleContent->innerHTML; $parametres['title'] = $r->articleTitle->innerHTML; - if (DOWNLOAD_PICTURES) { - $content = filtre_picture($content, $url, $id); - } $parametres['content'] = $content; return $parametres; } @@ -233,7 +230,7 @@ function remove_directory($directory) * Appel d'une action (mark as fav, archive, delete) */ -function action_to_do($action, $id, $url, $token) +function action_to_do($action, $url, $token, $id = 0) { global $db; @@ -243,13 +240,9 @@ function action_to_do($action, $id, $url, $token) if ($url == '') continue; - # FIXME corriger cette génération d'ID - $req = $db->getHandle()->query("SELECT id FROM entries ORDER BY id DESC"); - $id = $req->fetchColumn()+1; - - if($parametres_url = prepare_url($url, $id)) { - $sql_action = 'INSERT INTO entries ( id, url, title, content ) VALUES (?,?, ?, ?)'; - $params_action = array($id,$url, $parametres_url['title'], $parametres_url['content']); + if($parametres_url = prepare_url($url)) { + $sql_action = 'INSERT INTO entries ( url, title, content ) VALUES (?, ?, ?)'; + $params_action = array($url, $parametres_url['title'], $parametres_url['content']); } logm('add link ' . $url); @@ -290,6 +283,17 @@ function action_to_do($action, $id, $url, $token) { $query = $db->getHandle()->prepare($sql_action); $query->execute($params_action); + # if we add a link, we have to download pictures + if ($action == 'add') { + $last_id = $db->getHandle()->lastInsertId(); + if (DOWNLOAD_PICTURES) { + $content = filtre_picture($parametres_url['content'], $url, $last_id); + $sql_update = "UPDATE entries SET content=? WHERE id=?"; + $params_update = array($content, $last_id); + $query_update = $db->getHandle()->prepare($sql_update); + $query_update->execute($params_update); + } + } } } catch (Exception $e) -- cgit v1.2.3