1
0
mirror of https://github.com/moparisthebest/wallabag synced 2024-11-30 04:42:19 -05:00

Fixed #54 - récupération de l'id améliorée et utilisation de action_to_do() pour l'insertion dans l'import pocket

This commit is contained in:
nicosomb 2013-04-18 10:15:46 +02:00
parent 64458521c3
commit d06f30ef93
3 changed files with 20 additions and 33 deletions

View File

@ -29,26 +29,8 @@ else {
$a = $li->find('a'); $a = $li->find('a');
$url = $a[0]->href; $url = $a[0]->href;
# FIXME corriger cette génération d'ID
$req = $db->getHandle()->query("SELECT id FROM entries ORDER BY id DESC");
$id = $req->fetchColumn()+1;
$parametres_url = prepare_url($url, $id); action_to_do('add', $url, $token);
$sql_action = 'INSERT INTO entries ( url, title, content, is_read ) VALUES (?, ?, ?, ?)';
$params_action = array($url, $parametres_url['title'], $parametres_url['content'], $read);
try
{
# action query
if (isset($sql_action))
{
$query = $db->getHandle()->prepare($sql_action);
$query->execute($params_action);
}
}
catch (Exception $e)
{
logm('error during pocket import : ' . $e->getMessage());
}
} }
# Pocket génère un fichier HTML avec deux <ul> # Pocket génère un fichier HTML avec deux <ul>
# Le premier concerne les éléments non lus # Le premier concerne les éléments non lus

View File

@ -14,6 +14,7 @@ if (!is_dir('db/')) {
define ('DB_PATH', 'sqlite:./db/poche.sqlite'); define ('DB_PATH', 'sqlite:./db/poche.sqlite');
define ('ABS_PATH', 'assets/'); define ('ABS_PATH', 'assets/');
define ('CONVERT_LINKS_FOOTNOTES', TRUE);
define ('DOWNLOAD_PICTURES', TRUE); define ('DOWNLOAD_PICTURES', TRUE);
include 'db.php'; include 'db.php';
@ -50,5 +51,5 @@ $url = (isset ($_GET['url'])) ? $_GET['url'] : '';
$token = (isset ($_REQUEST['token'])) ? $_REQUEST['token'] : ''; $token = (isset ($_REQUEST['token'])) ? $_REQUEST['token'] : '';
if ($action != '') { if ($action != '') {
action_to_do($action, $id, $url, $token); action_to_do($action, $url, $token, $id);
} }

View File

@ -88,7 +88,7 @@ function get_external_file($url)
/** /**
* Préparation de l'URL avec récupération du contenu avant insertion en base * 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(); $parametres = array();
$url = html_entity_decode(trim($url)); $url = html_entity_decode(trim($url));
@ -107,14 +107,11 @@ function prepare_url($url, $id)
if (isset($html) and strlen($html) > 0) if (isset($html) and strlen($html) > 0)
{ {
$r = new Readability($html, $url); $r = new Readability($html, $url);
$r->convertLinksToFootnotes = TRUE; $r->convertLinksToFootnotes = CONVERT_LINKS_FOOTNOTES;
if($r->init()) if($r->init())
{ {
$content = $r->articleContent->innerHTML; $content = $r->articleContent->innerHTML;
$parametres['title'] = $r->articleTitle->innerHTML; $parametres['title'] = $r->articleTitle->innerHTML;
if (DOWNLOAD_PICTURES) {
$content = filtre_picture($content, $url, $id);
}
$parametres['content'] = $content; $parametres['content'] = $content;
return $parametres; return $parametres;
} }
@ -233,7 +230,7 @@ function remove_directory($directory)
* Appel d'une action (mark as fav, archive, delete) * 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; global $db;
@ -243,13 +240,9 @@ function action_to_do($action, $id, $url, $token)
if ($url == '') if ($url == '')
continue; continue;
# FIXME corriger cette génération d'ID if($parametres_url = prepare_url($url)) {
$req = $db->getHandle()->query("SELECT id FROM entries ORDER BY id DESC"); $sql_action = 'INSERT INTO entries ( url, title, content ) VALUES (?, ?, ?)';
$id = $req->fetchColumn()+1; $params_action = array($url, $parametres_url['title'], $parametres_url['content']);
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']);
} }
logm('add link ' . $url); logm('add link ' . $url);
@ -290,6 +283,17 @@ function action_to_do($action, $id, $url, $token)
{ {
$query = $db->getHandle()->prepare($sql_action); $query = $db->getHandle()->prepare($sql_action);
$query->execute($params_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) catch (Exception $e)