mirror of
https://github.com/moparisthebest/wallabag
synced 2024-11-27 11:22:17 -05:00
import in poche and not in an external file
This commit is contained in:
parent
eb1af59219
commit
c765c3679f
73
import.php
73
import.php
@ -1,73 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* poche, a read it later open source system
|
||||
*
|
||||
* @category poche
|
||||
* @author Nicolas Lœuillet <support@inthepoche.com>
|
||||
* @copyright 2013
|
||||
* @license http://www.wtfpl.net/ see COPYING file
|
||||
*/
|
||||
|
||||
set_time_limit(0);
|
||||
|
||||
include dirname(__FILE__).'/inc/config.php';
|
||||
include dirname(__FILE__).'/inc/simple_html_dom.php';
|
||||
|
||||
if (!isset($_GET['start'])) {
|
||||
echo _('Please execute the import script locally, it can take a very long time.') . '<br /><br />' . _('Please choose between Pocket & Readabilty :') . '<br /><a href="import.php?start=pocket">' . _('Bye bye Pocket, let\'s go !') . '</a><br /><a href="import.php?start=readability">' . _('Bye bye Readability, let\'s go !') . '</a>';
|
||||
}
|
||||
else {
|
||||
if ($_GET['start'] == 'pocket') {
|
||||
$html = new simple_html_dom();
|
||||
$html->load_file('ril_export.html');
|
||||
|
||||
$read = 0;
|
||||
$errors = array();
|
||||
foreach($html->find('ul') as $ul)
|
||||
{
|
||||
foreach($ul->find('li') as $li)
|
||||
{
|
||||
$a = $li->find('a');
|
||||
$url = $a[0]->href;
|
||||
|
||||
action_to_do('add', $url);
|
||||
if ($read == '1') {
|
||||
$last_id = $db->getHandle()->lastInsertId();
|
||||
$sql_update = "UPDATE entries SET is_read=~is_read WHERE id=?";
|
||||
$params_update = array($last_id);
|
||||
$query_update = $db->getHandle()->prepare($sql_update);
|
||||
$query_update->execute($params_update);
|
||||
}
|
||||
}
|
||||
# Pocket génère un fichier HTML avec deux <ul>
|
||||
# Le premier concerne les éléments non lus
|
||||
# Le second concerne les éléments archivés
|
||||
$read = 1;
|
||||
}
|
||||
|
||||
echo _('Import from Pocket completed.') . '<a href="index.php">' . _('Welcome to poche !') .'</a>';
|
||||
logm('import from pocket completed');
|
||||
}
|
||||
else if ($_GET['start'] == 'readability') {
|
||||
$str_data = file_get_contents("readability");
|
||||
$data = json_decode($str_data,true);
|
||||
|
||||
foreach ($data as $key => $value) {
|
||||
$url = '';
|
||||
foreach ($value as $key2 => $value2) {
|
||||
if ($key2 == 'article__url') {
|
||||
$url = $value2;
|
||||
}
|
||||
}
|
||||
if ($url != '')
|
||||
action_to_do('add', $url);
|
||||
}
|
||||
|
||||
echo _('Import from Readability completed.') . '<a href="index.php">' . _('Welcome to poche !') . '</a>';
|
||||
logm('import from Readability completed');
|
||||
}
|
||||
else {
|
||||
echo _('Error with the import.') . '<a href="index.php">' . _('Back to poche'). '</a>';
|
||||
logm('error with the import');
|
||||
}
|
||||
}
|
@ -73,7 +73,7 @@ class Poche
|
||||
/**
|
||||
* Call action (mark as fav, archive, delete, etc.)
|
||||
*/
|
||||
public function action($action, Url $url, $id)
|
||||
public function action($action, Url $url, $id = 0)
|
||||
{
|
||||
switch ($action)
|
||||
{
|
||||
@ -118,6 +118,8 @@ class Poche
|
||||
$this->store->archiveById($id);
|
||||
Tools::logm('archive link #' . $id);
|
||||
break;
|
||||
case 'import':
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@ -173,4 +175,108 @@ class Poche
|
||||
|
||||
return $tpl_vars;
|
||||
}
|
||||
|
||||
public function updatePassword()
|
||||
{
|
||||
if (isset($_POST['password']) && isset($_POST['password_repeat'])) {
|
||||
if ($_POST['password'] == $_POST['password_repeat'] && $_POST['password'] != "") {
|
||||
if (!MODE_DEMO) {
|
||||
Tools::logm('password updated');
|
||||
$this->store->updatePassword(Tools::encodeString($_POST['password'] . $_SESSION['login']));
|
||||
Session::logout();
|
||||
Tools::redirect();
|
||||
}
|
||||
else {
|
||||
Tools::logm('in demo mode, you can\'t do this');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function login($referer)
|
||||
{
|
||||
if (!empty($_POST['login']) && !empty($_POST['password'])) {
|
||||
if (Session::login($_SESSION['login'], $_SESSION['pass'], $_POST['login'], Tools::encodeString($_POST['password'] . $_POST['login']))) {
|
||||
Tools::logm('login successful');
|
||||
|
||||
if (!empty($_POST['longlastingsession'])) {
|
||||
$_SESSION['longlastingsession'] = 31536000;
|
||||
$_SESSION['expires_on'] = time() + $_SESSION['longlastingsession'];
|
||||
session_set_cookie_params($_SESSION['longlastingsession']);
|
||||
} else {
|
||||
session_set_cookie_params(0);
|
||||
}
|
||||
session_regenerate_id(true);
|
||||
Tools::redirect($referer);
|
||||
}
|
||||
Tools::logm('login failed');
|
||||
Tools::redirect();
|
||||
} else {
|
||||
Tools::logm('login failed');
|
||||
Tools::redirect();
|
||||
}
|
||||
}
|
||||
|
||||
public function logout()
|
||||
{
|
||||
Tools::logm('logout');
|
||||
Session::logout();
|
||||
Tools::redirect();
|
||||
}
|
||||
|
||||
public function import($from)
|
||||
{
|
||||
if ($from == 'pocket') {
|
||||
$html = new simple_html_dom();
|
||||
$html->load_file('./ril_export.html');
|
||||
|
||||
$read = 0;
|
||||
$errors = array();
|
||||
foreach($html->find('ul') as $ul)
|
||||
{
|
||||
foreach($ul->find('li') as $li)
|
||||
{
|
||||
$a = $li->find('a');
|
||||
$url = new Url($a[0]->href);
|
||||
$this->action('add', $url);
|
||||
if ($read == '1') {
|
||||
$last_id = $this->store->lastInsertId();
|
||||
$sql_update = "UPDATE entries SET is_read=~is_read WHERE id=?";
|
||||
$params_update = array($last_id);
|
||||
$query_update = $this->store->prepare($sql_update);
|
||||
$query_update->execute($params_update);
|
||||
}
|
||||
}
|
||||
# Pocket génère un fichier HTML avec deux <ul>
|
||||
# Le premier concerne les éléments non lus
|
||||
# Le second concerne les éléments archivés
|
||||
$read = 1;
|
||||
}
|
||||
logm('import from pocket completed');
|
||||
Tools::redirect();
|
||||
}
|
||||
else if ($from == 'readability') {
|
||||
# TODO finaliser tout ça ici
|
||||
$str_data = file_get_contents("readability");
|
||||
$data = json_decode($str_data,true);
|
||||
|
||||
foreach ($data as $key => $value) {
|
||||
$url = '';
|
||||
foreach ($value as $key2 => $value2) {
|
||||
if ($key2 == 'article__url') {
|
||||
$url = new Url($value2);
|
||||
}
|
||||
}
|
||||
if ($url != '')
|
||||
action_to_do('add', $url);
|
||||
}
|
||||
logm('import from Readability completed');
|
||||
Tools::redirect();
|
||||
}
|
||||
}
|
||||
|
||||
public function export()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
@ -32,6 +32,7 @@ require_once './inc/3rdparty/Session.class.php';
|
||||
require_once './inc/store/store.class.php';
|
||||
require_once './inc/store/' . $storage_type . '.class.php';
|
||||
require_once './vendor/autoload.php';
|
||||
require_once './inc/3rdparty/simple_html_dom.php';
|
||||
|
||||
if (DOWNLOAD_PICTURES) {
|
||||
require_once './inc/poche/pochePicture.php';
|
||||
|
45
index.php
45
index.php
@ -10,8 +10,6 @@
|
||||
|
||||
include dirname(__FILE__).'/inc/poche/config.inc.php';
|
||||
|
||||
$notices = array();
|
||||
|
||||
# XSRF protection with token
|
||||
// if (!empty($_POST)) {
|
||||
// if (!Session::isToken($_POST['token'])) {
|
||||
@ -25,50 +23,18 @@ $referer = empty($_SERVER['HTTP_REFERER']) ? '' : $_SERVER['HTTP_REFERER'];
|
||||
|
||||
if (isset($_GET['login'])) {
|
||||
# hello you
|
||||
if (!empty($_POST['login']) && !empty($_POST['password'])) {
|
||||
if (Session::login($_SESSION['login'], $_SESSION['pass'], $_POST['login'], Tools::encodeString($_POST['password'] . $_POST['login']))) {
|
||||
Tools::logm('login successful');
|
||||
$notices['value'] = _('login successful');
|
||||
|
||||
if (!empty($_POST['longlastingsession'])) {
|
||||
$_SESSION['longlastingsession'] = 31536000;
|
||||
$_SESSION['expires_on'] = time() + $_SESSION['longlastingsession'];
|
||||
session_set_cookie_params($_SESSION['longlastingsession']);
|
||||
} else {
|
||||
session_set_cookie_params(0);
|
||||
}
|
||||
session_regenerate_id(true);
|
||||
Tools::redirect($referer);
|
||||
}
|
||||
Tools::logm('login failed');
|
||||
$notices['value'] = _('Login failed !');
|
||||
Tools::redirect();
|
||||
} else {
|
||||
Tools::logm('login failed');
|
||||
Tools::redirect();
|
||||
}
|
||||
$poche->login($referer);
|
||||
}
|
||||
elseif (isset($_GET['logout'])) {
|
||||
# see you soon !
|
||||
Tools::logm('logout');
|
||||
Session::logout();
|
||||
Tools::redirect();
|
||||
$poche->logout();
|
||||
}
|
||||
elseif (isset($_GET['config'])) {
|
||||
# Update password
|
||||
if (isset($_POST['password']) && isset($_POST['password_repeat'])) {
|
||||
if ($_POST['password'] == $_POST['password_repeat'] && $_POST['password'] != "") {
|
||||
if (!MODE_DEMO) {
|
||||
Tools::logm('password updated');
|
||||
$poche->store->updatePassword(Tools::encodeString($_POST['password'] . $_SESSION['login']));
|
||||
Session::logout();
|
||||
Tools::redirect();
|
||||
}
|
||||
else {
|
||||
Tools::logm('in demo mode, you can\'t do this');
|
||||
}
|
||||
}
|
||||
$poche->updatePassword();
|
||||
}
|
||||
elseif (isset($_GET['import'])) {
|
||||
$poche->import($_GET['from']);
|
||||
}
|
||||
|
||||
# Aaaaaaand action !
|
||||
@ -87,7 +53,6 @@ $tpl_vars = array(
|
||||
'demo' => MODE_DEMO,
|
||||
'title' => _('poche, a read it later open source system'),
|
||||
'token' => Session::getToken(),
|
||||
'notices' => $notices,
|
||||
);
|
||||
|
||||
if (Session::isLogged()) {
|
||||
|
@ -13,7 +13,7 @@
|
||||
{% block content %}
|
||||
<div id="content">
|
||||
<h2>{% trans "Bookmarklet" %}</h2>
|
||||
<p>{% trans "Thanks to the bookmarklet, you will be able to easily add a link to your poche." %} {% trans "Have a look to this documentation:" %} <a href="http://inthepoche.com/?pages/Documentation" target="_blank">http://inthepoche.com/?pages/Documentation</a>.</p>
|
||||
<p>{% trans "Thanks to the bookmarklet, you will be able to easily add a link to your poche." %} {% trans "Have a look to this documentation:" %} <a href="http://inthepoche.com/?pages/Documentation">inthepoche.com</a>.</p>
|
||||
<p>{% trans "Drag & drop this link to your bookmarks bar and have fun with poche." %}</p>
|
||||
<p><a ondragend="this.click();" style="cursor: move; border: 1px dashed grey; background: white;" title="i am a bookmarklet, use me !" href="javascript:if(top['bookmarklet-url@inthepoche.com']){top['bookmarklet-url@inthepoche.com'];}else{(function(){var%20url%20=%20location.href%20||%20url;window.open('{{ poche_url }}?action=add&url='%20+%20btoa(url),'_self');})();void(0);}">{% trans "poche it!" %}</a></p>
|
||||
|
||||
@ -35,6 +35,15 @@
|
||||
<input type="hidden" name="returnurl" value="{{ referer }}">
|
||||
<input type="hidden" name="token" value="{{ token }}">
|
||||
</form>
|
||||
|
||||
<h2>{% trans "Import" %}</h2>
|
||||
<p>{% trans "Please execute the import script locally, it can take a very long time." %}</p>
|
||||
<p>{% trans "More infos in the official doc:" %} <a href="http://inthepoche.com/?pages/Documentation">inthepoche.com</a></p>
|
||||
<p><ul>
|
||||
<li><a href="/?import&from=pocket">{% trans "import from Pocket" %}</a> (you must have a "ril_export.html" file on your server)</li>
|
||||
<li><a href="/?import&from=readability">{% trans "import from Readability" %}</a> (you must have a "readability" file on your server)</li>
|
||||
</ul></p>
|
||||
|
||||
<h2>{% trans "Export your poche datas" %}</h2>
|
||||
<p><a href="?view=export" target="_blank">{% trans "Click here" %}</a> {% trans "to export your poche datas." %}</p>
|
||||
</div>
|
||||
|
@ -15,15 +15,6 @@
|
||||
<li><img src="./tpl/img/up.png" onclick="sort_links('{{ view }}', 'ta');" title="{% trans "by title asc" %}" /> {% trans "by title" %} <img src="./tpl/img/down.png" onclick="sort_links('{{ view }}', 'td');" title="{% trans "by title desc" %}" /></li>
|
||||
</ul>
|
||||
{% endblock %}
|
||||
{% block notices %}
|
||||
<div class="messages">
|
||||
<ul>
|
||||
{% for notice in notices %}
|
||||
<li>{{ notice.value|e }}</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</div>
|
||||
{% endblock %}
|
||||
{% block content %}
|
||||
<div id="content">
|
||||
{% for entry in entries %}
|
||||
|
@ -17,7 +17,6 @@
|
||||
<div id="main">
|
||||
{% block menu %}{% endblock %}
|
||||
{% block precontent %}{% endblock %}
|
||||
{% block messages %}{% endblock %}
|
||||
{% block content %}{% endblock %}
|
||||
{% block js %}{% endblock %}
|
||||
</div>
|
||||
|
@ -1,15 +1,6 @@
|
||||
{% extends "layout.twig" %}
|
||||
|
||||
{% block title %}{% trans "login to your poche" %}{% endblock %}
|
||||
{% block notices %}
|
||||
<div class="messages">
|
||||
<ul>
|
||||
{% for notice in notices %}
|
||||
<li>{{ notice.value|e }}</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</div>
|
||||
{% endblock %}
|
||||
{% block content %}
|
||||
<form method="post" action="?login" name="loginform">
|
||||
<fieldset class="w500p center">
|
||||
|
Loading…
Reference in New Issue
Block a user