1
0
mirror of https://github.com/moparisthebest/wallabag synced 2024-11-23 17:42:15 -05:00

Merge branch 'dev'

This commit is contained in:
Nicolas Lœuillet 2013-07-31 17:19:50 +02:00
commit 85ebc80c7e
18 changed files with 1332 additions and 1102 deletions

View File

@ -25,7 +25,7 @@ You can :
## Requirements & installation ## Requirements & installation
You have to install [sqlite for php](http://www.php.net/manual/en/book.sqlite.php) on your server. You have to install [sqlite for php](http://www.php.net/manual/en/book.sqlite.php) on your server.
Get the [latest version](https://github.com/nicosomb/poche) of poche on github. Unzip it and upload it on your server. poche must have write access on assets, cache and db directories. Get the [latest version](https://github.com/inthepoche/poche) of poche on github. Unzip it and upload it on your server. poche must have write access on assets, cache and db directories.
That's all, **poche works** ! That's all, **poche works** !

0
img/messages/close.png Executable file → Normal file
View File

Before

Width:  |  Height:  |  Size: 662 B

After

Width:  |  Height:  |  Size: 662 B

0
img/messages/cross.png Executable file → Normal file
View File

Before

Width:  |  Height:  |  Size: 655 B

After

Width:  |  Height:  |  Size: 655 B

0
img/messages/help.png Executable file → Normal file
View File

Before

Width:  |  Height:  |  Size: 786 B

After

Width:  |  Height:  |  Size: 786 B

0
img/messages/tick.png Executable file → Normal file
View File

Before

Width:  |  Height:  |  Size: 537 B

After

Width:  |  Height:  |  Size: 537 B

0
img/messages/warning.png Executable file → Normal file
View File

Before

Width:  |  Height:  |  Size: 666 B

After

Width:  |  Height:  |  Size: 666 B

View File

@ -107,4 +107,3 @@ class JSLikeHTMLElement extends DOMElement
return '['.$this->tagName.']'; return '['.$this->tagName.']';
} }
} }
?>

File diff suppressed because it is too large Load Diff

View File

@ -93,7 +93,7 @@ class Session
// Force logout // Force logout
public static function logout() public static function logout()
{ {
unset($_SESSION['uid'],$_SESSION['info'],$_SESSION['expires_on'],$_SESSION['tokens']); unset($_SESSION['uid'],$_SESSION['info'],$_SESSION['expires_on'],$_SESSION['tokens'], $_SESSION['login'], $_SESSION['pass']);
} }
// Make sure user is logged in. // Make sure user is logged in.

View File

@ -14,9 +14,12 @@ if (!is_dir('db/')) {
@mkdir('db/',0705); @mkdir('db/',0705);
} }
define ('MODE_DEMO', FALSE);
define ('ABS_PATH', 'assets/'); define ('ABS_PATH', 'assets/');
define ('CONVERT_LINKS_FOOTNOTES', TRUE); define ('CONVERT_LINKS_FOOTNOTES', TRUE);
define ('REVERT_FORCED_PARAGRAPH_ELEMENTS',FALSE);
define ('DOWNLOAD_PICTURES', TRUE); define ('DOWNLOAD_PICTURES', TRUE);
define ('SALT', '464v54gLLw928uz4zUBqkRJeiPY68zCX');
$storage_type = 'sqlite'; # sqlite or file $storage_type = 'sqlite'; # sqlite or file
include 'functions.php'; include 'functions.php';
@ -32,9 +35,7 @@ require_once 'class.messages.php';
Session::init(); Session::init();
$store = new $storage_type(); $store = new $storage_type();
$msg = new Messages();
# initialisation de RainTPL # initialisation de RainTPL
raintpl::$tpl_dir = './tpl/'; raintpl::$tpl_dir = './tpl/';
raintpl::$cache_dir = './cache/'; raintpl::$cache_dir = './cache/';
@ -42,4 +43,24 @@ raintpl::$base_url = get_poche_url();
raintpl::configure('path_replace', false); raintpl::configure('path_replace', false);
raintpl::configure('debug', false); raintpl::configure('debug', false);
$tpl = new raintpl(); $tpl = new raintpl();
if(!$store->isInstalled())
{
logm('poche still not installed');
$tpl->draw('install');
if (isset($_GET['install'])) {
if (($_POST['password'] == $_POST['password_repeat'])
&& $_POST['password'] != "" && $_POST['login'] != "") {
$store->install($_POST['login'], encode_string($_POST['password'] . $_POST['login']));
Session::logout();
MyTool::redirect();
}
}
exit();
}
$_SESSION['login'] = (isset ($_SESSION['login'])) ? $_SESSION['login'] : $store->getLogin();
$_SESSION['pass'] = (isset ($_SESSION['pass'])) ? $_SESSION['pass'] : $store->getPassword();
$msg = new Messages();
$tpl->assign('msg', $msg); $tpl->assign('msg', $msg);

View File

@ -23,6 +23,11 @@ function get_poche_url()
return $protocol . "://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; return $protocol . "://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
} }
function encode_string($string)
{
return sha1($string . SALT);
}
// function define to retrieve url content // function define to retrieve url content
function get_external_file($url) function get_external_file($url)
{ {
@ -39,6 +44,10 @@ function get_external_file($url)
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HEADER, false); curl_setopt($curl, CURLOPT_HEADER, false);
// FOR SSL do not verified certificate
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($curl, CURLOPT_AUTOREFERER, TRUE );
// FeedBurner requires a proper USER-AGENT... // FeedBurner requires a proper USER-AGENT...
curl_setopt($curl, CURL_HTTP_VERSION_1_1, true); curl_setopt($curl, CURL_HTTP_VERSION_1_1, true);
curl_setopt($curl, CURLOPT_ENCODING, "gzip, deflate"); curl_setopt($curl, CURLOPT_ENCODING, "gzip, deflate");
@ -54,7 +63,15 @@ function get_external_file($url)
} else { } else {
// create http context and add timeout and user-agent // create http context and add timeout and user-agent
$context = stream_context_create(array('http'=>array('timeout' => $timeout,'header'=> "User-Agent: ".$useragent,/*spoot Mozilla Firefox*/'follow_location' => true))); $context = stream_context_create(array(
'http'=>array('timeout' => $timeout,
'header'=> "User-Agent: ".$useragent, /*spoot Mozilla Firefox*/
'follow_location' => true),
// FOR SSL do not verified certificate
'ssl' => array('verify_peer' => false,
'allow_self_signed' => true)
)
);
// only download page lesser than 4MB // only download page lesser than 4MB
$data = @file_get_contents($url, false, $context, -1, 4000000); // We download at most 4 MB from source. $data = @file_get_contents($url, false, $context, -1, 4000000); // We download at most 4 MB from source.
@ -108,14 +125,26 @@ function prepare_url($url)
$i=strpos($url,'#xtor=RSS-'); if ($i!==false) $url=substr($url,0,$i); $i=strpos($url,'#xtor=RSS-'); if ($i!==false) $url=substr($url,0,$i);
$title = $url; $title = $url;
if (!preg_match('!^https?://!i', $url))
$url = 'http://' . $url;
$html = Encoding::toUTF8(get_external_file($url,15)); $html = Encoding::toUTF8(get_external_file($url,15));
// If get_external_file if not able to retrieve HTTPS content try the same URL with HTTP protocol
if (!preg_match('!^https?://!i', $url) && (!isset($html) || strlen($html) <= 0)) {
$url = 'http://' . $url;
$html = Encoding::toUTF8(get_external_file($url,15));
}
if (function_exists('tidy_parse_string')) {
$tidy = tidy_parse_string($html, array(), 'UTF8');
$tidy->cleanRepair();
$html = $tidy->value;
}
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 = CONVERT_LINKS_FOOTNOTES; $r->convertLinksToFootnotes = CONVERT_LINKS_FOOTNOTES;
$r->revertForcedParagraphElements = REVERT_FORCED_PARAGRAPH_ELEMENTS;
if($r->init()) if($r->init())
{ {
$content = $r->articleContent->innerHTML; $content = $r->articleContent->innerHTML;
@ -125,8 +154,6 @@ function prepare_url($url)
} }
} }
$msg->add('e', 'error during url preparation');
logm('error during url preparation');
return FALSE; return FALSE;
} }
@ -263,7 +290,13 @@ function display_view($view, $id = 0, $full_head = 'yes')
$tpl->assign('id', $entry['id']); $tpl->assign('id', $entry['id']);
$tpl->assign('url', $entry['url']); $tpl->assign('url', $entry['url']);
$tpl->assign('title', $entry['title']); $tpl->assign('title', $entry['title']);
$tpl->assign('content', $entry['content']); $content = $entry['content'];
if (function_exists('tidy_parse_string')) {
$tidy = tidy_parse_string($content, array('indent'=>true, 'show-body-only' => true), 'UTF8');
$tidy->cleanRepair();
$content = $tidy->value;
}
$tpl->assign('content', $content);
$tpl->assign('is_fav', $entry['is_fav']); $tpl->assign('is_fav', $entry['is_fav']);
$tpl->assign('is_read', $entry['is_read']); $tpl->assign('is_read', $entry['is_read']);
$tpl->assign('load_all_js', 0); $tpl->assign('load_all_js', 0);
@ -311,35 +344,46 @@ function action_to_do($action, $url, $id = 0)
if (MyTool::isUrl($url)) { if (MyTool::isUrl($url)) {
if($parametres_url = prepare_url($url)) { if($parametres_url = prepare_url($url)) {
$store->add($url, $parametres_url['title'], $parametres_url['content']); if ($store->add($url, $parametres_url['title'], $parametres_url['content'])) {
$last_id = $store->getLastId(); $last_id = $store->getLastId();
if (DOWNLOAD_PICTURES) { if (DOWNLOAD_PICTURES) {
$content = filtre_picture($parametres_url['content'], $url, $last_id); $content = filtre_picture($parametres_url['content'], $url, $last_id);
}
$msg->add('s', 'the link has been added successfully');
} }
$msg->add('s', 'the link has been added successfully'); else {
$msg->add('e', 'error during insertion : the link wasn\'t added');
}
}
else {
$msg->add('e', 'error during url preparation : the link wasn\'t added');
logm('error during url preparation');
} }
} }
else { else {
$msg->add('e', 'the link has been added successfully'); $msg->add('e', 'error during url preparation : the link is not valid');
logm($url . ' is not a valid url'); logm($url . ' is not a valid url');
} }
logm('add link ' . $url); logm('add link ' . $url);
break; break;
case 'delete': case 'delete':
remove_directory(ABS_PATH . $id); if ($store->deleteById($id)) {
$store->deleteById($id); remove_directory(ABS_PATH . $id);
$msg->add('s', 'the link has been deleted successfully'); $msg->add('s', 'the link has been deleted successfully');
logm('delete link #' . $id); logm('delete link #' . $id);
}
else {
$msg->add('e', 'the link wasn\'t deleted');
logm('error : can\'t delete link #' . $id);
}
break; break;
case 'toggle_fav' : case 'toggle_fav' :
$store->favoriteById($id); $store->favoriteById($id);
$msg->add('s', 'the favorite toggle has been done successfully');
logm('mark as favorite link #' . $id); logm('mark as favorite link #' . $id);
break; break;
case 'toggle_archive' : case 'toggle_archive' :
$store->archiveById($id); $store->archiveById($id);
$msg->add('s', 'the archive toggle has been done successfully');
logm('archive link #' . $id); logm('archive link #' . $id);
break; break;
default: default:

View File

@ -17,7 +17,6 @@ class Sqlite extends Store {
parent::__construct(); parent::__construct();
$this->handle = new PDO(self::$db_path); $this->handle = new PDO(self::$db_path);
$this->handle->exec('CREATE TABLE IF NOT EXISTS "entries" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL UNIQUE , "title" VARCHAR, "url" VARCHAR UNIQUE , "is_read" INTEGER DEFAULT 0, "is_fav" INTEGER DEFAULT 0, "content" BLOB)');
$this->handle->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $this->handle->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} }
@ -25,6 +24,63 @@ class Sqlite extends Store {
return $this->handle; return $this->handle;
} }
public function isInstalled() {
$sql = "SELECT name FROM sqlite_sequence WHERE name=?";
$query = $this->executeQuery($sql, array('config'));
$hasConfig = $query->fetchAll();
if (count($hasConfig) == 0)
return FALSE;
if (!$this->getLogin() || !$this->getPassword())
return FALSE;
return TRUE;
}
public function install($login, $password) {
$this->getHandle()->exec('CREATE TABLE IF NOT EXISTS "config" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL UNIQUE , "name" VARCHAR UNIQUE, "value" BLOB)');
$this->handle->exec('CREATE TABLE IF NOT EXISTS "entries" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL UNIQUE , "title" VARCHAR, "url" VARCHAR UNIQUE , "is_read" INTEGER DEFAULT 0, "is_fav" INTEGER DEFAULT 0, "content" BLOB)');
if (!$this->getLogin()) {
$sql_login = 'INSERT INTO config ( name, value ) VALUES (?, ?)';
$params_login = array('login', $login);
$query = $this->executeQuery($sql_login, $params_login);
}
if (!$this->getPassword()) {
$sql_pass = 'INSERT INTO config ( name, value ) VALUES (?, ?)';
$params_pass = array('password', $password);
$query = $this->executeQuery($sql_pass, $params_pass);
}
return TRUE;
}
public function getLogin() {
$sql = "SELECT value FROM config WHERE name=?";
$query = $this->executeQuery($sql, array('login'));
$login = $query->fetchAll();
return isset($login[0]['value']) ? $login[0]['value'] : FALSE;
}
public function getPassword() {
$sql = "SELECT value FROM config WHERE name=?";
$query = $this->executeQuery($sql, array('password'));
$pass = $query->fetchAll();
return isset($pass[0]['value']) ? $pass[0]['value'] : FALSE;
}
public function updatePassword($password)
{
$sql_update = "UPDATE config SET value=? WHERE name='password'";
$params_update = array($password);
$query = $this->executeQuery($sql_update, $params_update);
}
private function executeQuery($sql, $params) { private function executeQuery($sql, $params) {
try try
{ {
@ -107,6 +163,7 @@ class Sqlite extends Store {
$sql_action = 'INSERT INTO entries ( url, title, content ) VALUES (?, ?, ?)'; $sql_action = 'INSERT INTO entries ( url, title, content ) VALUES (?, ?, ?)';
$params_action = array($url, $title, $content); $params_action = array($url, $title, $content);
$query = $this->executeQuery($sql_action, $params_action); $query = $this->executeQuery($sql_action, $params_action);
return $query;
} }
public function deleteById($id) { public function deleteById($id) {
@ -114,6 +171,7 @@ class Sqlite extends Store {
$sql_action = "DELETE FROM entries WHERE id=?"; $sql_action = "DELETE FROM entries WHERE id=?";
$params_action = array($id); $params_action = array($id);
$query = $this->executeQuery($sql_action, $params_action); $query = $this->executeQuery($sql_action, $params_action);
return $query;
} }
public function favoriteById($id) { public function favoriteById($id) {

View File

@ -13,6 +13,14 @@ class Store {
} }
public function getLogin() {
}
public function getPassword() {
}
public function add() { public function add() {
} }

View File

@ -25,9 +25,9 @@ $ref = empty($_SERVER['HTTP_REFERER']) ? '' : $_SERVER['HTTP_REFERER'];
if (isset($_GET['login'])) { if (isset($_GET['login'])) {
// Login // Login
if (!empty($_POST['login']) && !empty($_POST['password'])) { if (!empty($_POST['login']) && !empty($_POST['password'])) {
if (Session::login('poche', 'poche', $_POST['login'], $_POST['password'])) { if (Session::login($_SESSION['login'], $_SESSION['pass'], $_POST['login'], encode_string($_POST['password'] . $_POST['login']))) {
logm('login successful'); logm('login successful');
$msg->add('s', 'welcome in your pocket!'); $msg->add('s', 'welcome in your poche!');
if (!empty($_POST['longlastingsession'])) { if (!empty($_POST['longlastingsession'])) {
$_SESSION['longlastingsession'] = 31536000; $_SESSION['longlastingsession'] = 31536000;
$_SESSION['expires_on'] = time() + $_SESSION['longlastingsession']; $_SESSION['expires_on'] = time() + $_SESSION['longlastingsession'];
@ -50,6 +50,22 @@ elseif (isset($_GET['logout'])) {
Session::logout(); Session::logout();
MyTool::redirect(); MyTool::redirect();
} }
elseif (isset($_GET['config'])) {
if (isset($_POST['password']) && isset($_POST['password_repeat'])) {
if ($_POST['password'] == $_POST['password_repeat'] && $_POST['password'] != "") {
logm('password updated');
if (!DEMO) {
$store->updatePassword(encode_string($_POST['password'] . $_SESSION['login']));
$msg->add('s', 'your password has been updated');
}
else {
$msg->add('i', 'in demo mode, you can\'t update password');
}
}
else
$msg->add('e', 'your password can\'t be empty and you have to repeat it in the second field');
}
}
# Traitement des paramètres et déclenchement des actions # Traitement des paramètres et déclenchement des actions
$view = (isset ($_REQUEST['view'])) ? htmlentities($_REQUEST['view']) : 'index'; $view = (isset ($_REQUEST['view'])) ? htmlentities($_REQUEST['view']) : 'index';

View File

@ -3,6 +3,25 @@
<p>Thanks to the bookmarklet, you will be able to easily add a link to your poche. If you don't know how use a bookmarklet, <a href="http://support.mozilla.org/en-US/kb/bookmarklets-perform-common-web-page-tasks">have a look here</a>.</p> <p>Thanks to the bookmarklet, you will be able to easily add a link to your poche. If you don't know how use a bookmarklet, <a href="http://support.mozilla.org/en-US/kb/bookmarklets-perform-common-web-page-tasks">have a look here</a>.</p>
<p>Drag & drop this link to your bookmarks bar and have fun with poche.</p> <p>Drag & drop this link to your bookmarks bar and have fun with poche.</p>
<p><a style="cursor: move; border: 1px dashed grey; background: white;" title="i am a bookmarklet, use me !" href="javascript:(function(){var%20url%20=%20location.href%20||%20url;window.open('{$poche_url}?action=add&url='%20+%20encodeURIComponent(url),'_self');})();">poche it !</a></p> <p><a style="cursor: move; border: 1px dashed grey; background: white;" title="i am a bookmarklet, use me !" href="javascript:(function(){var%20url%20=%20location.href%20||%20url;window.open('{$poche_url}?action=add&url='%20+%20encodeURIComponent(url),'_self');})();">poche it !</a></p>
<h2>Password</h2>
<form method="post" action="?config" name="loginform">
<fieldset class="w500p">
<div class="row">
<label class="col w150p" for="password">New password</label>
<input class="col" type="password" id="password" name="password" placeholder="Password" tabindex="2">
</div>
<div class="row">
<label class="col w150p" for="password_repeat">Repeat your new password</label>
<input class="col" type="password" id="password_repeat" name="password_repeat" placeholder="Password" tabindex="3">
</div>
<div class="row mts txtcenter">
<button class="bouton" type="submit" tabindex="4">Update</button>
</div>
</fieldset>
<input type="hidden" name="returnurl" value="<?php echo htmlspecialchars($referer);?>">
<input type="hidden" name="token" value="<?php echo Session::getToken(); ?>">
</form>
<h2>Export</h2> <h2>Export</h2>
<p><a href="?view=export" target="_blank">Click here</a> to export your poche datas.</p> <p><a href="?view=export" target="_blank">Click here</a> to export your poche datas.</p>
</div> </div>

30
tpl/install.html Normal file
View File

@ -0,0 +1,30 @@
{include="head"}
<body class="light-style">
<header>
<h1><a href="index.php"><img src="./img/logo.png" alt="logo poche" /></a>poche</h1>
</header>
<div id="main">
<form method="post" action="?install" name="loginform">
<fieldset class="w500p center">
<h2 class="mbs txtcenter">install your poche</h2>
<div class="row">
<label class="col w150p" for="login">Login</label>
<input class="col" type="text" id="login" name="login" placeholder="Login" tabindex="1" autofocus />
</div>
<div class="row">
<label class="col w150p" for="password">Password</label>
<input class="col" type="password" id="password" name="password" placeholder="Password" tabindex="2">
</div>
<div class="row">
<label class="col w150p" for="password_repeat">Repeat your password</label>
<input class="col" type="password" id="password_repeat" name="password_repeat" placeholder="Password" tabindex="3">
</div>
<div class="row mts txtcenter">
<button class="bouton" type="submit" tabindex="4">Install</button>
</div>
</fieldset>
<input type="hidden" name="returnurl" value="<?php echo htmlspecialchars($referer);?>">
<input type="hidden" name="token" value="<?php echo Session::getToken(); ?>">
</form>
{include="footer"}

View File

@ -12,7 +12,7 @@
<input class="col" type="text" id="login" name="login" placeholder="Login" tabindex="1" autofocus /> <input class="col" type="text" id="login" name="login" placeholder="Login" tabindex="1" autofocus />
</div> </div>
<div class="row"> <div class="row">
<label class="col w150p" for="password" >Password</label> <label class="col w150p" for="password">Password</label>
<input class="col" type="password" id="password" name="password" placeholder="Password" tabindex="2"> <input class="col" type="password" id="password" name="password" placeholder="Password" tabindex="2">
</div> </div>
<div class="row"> <div class="row">

View File

@ -38,6 +38,7 @@
<h1><a href="{$url}">{$title}</a></h1> <h1><a href="{$url}">{$title}</a></h1>
<div class="vieworiginal txtright small"><a href="{$url}" target="_blank" title="original : {$title}">view original</a></div> <div class="vieworiginal txtright small"><a href="{$url}" target="_blank" title="original : {$title}">view original</a></div>
</header> </header>
{include="messages"}
<article> <article>
<div id="readityourselfcontent"> <div id="readityourselfcontent">
{$content} {$content}