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
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** !

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

@ -4,7 +4,7 @@
*
* This class extends PHP's DOMElement to allow
* users to get and set the innerHTML property of
* HTML elements in the same way it's done in
* HTML elements in the same way it's done in
* JavaScript.
*
* Example usage:
@ -15,16 +15,16 @@
* $doc->registerNodeClass('DOMElement', 'JSLikeHTMLElement');
* $doc->loadHTML('<div><p>Para 1</p><p>Para 2</p></div>');
* $elem = $doc->getElementsByTagName('div')->item(0);
*
*
* // print innerHTML
* echo $elem->innerHTML; // prints '<p>Para 1</p><p>Para 2</p>'
* echo "\n\n";
*
*
* // set innerHTML
* $elem->innerHTML = '<a href="http://fivefilters.org">FiveFilters.org</a>';
* echo $elem->innerHTML; // prints '<a href="http://fivefilters.org">FiveFilters.org</a>'
* echo "\n\n";
*
*
* // print document (with our changes)
* echo $doc->saveXML();
* @endcode
@ -59,7 +59,7 @@ class JSLikeHTMLElement extends DOMElement
$value = mb_convert_encoding($value, 'HTML-ENTITIES', 'UTF-8');
// Using <htmlfragment> will generate a warning, but so will bad HTML
// (and by this point, bad HTML is what we've got).
// We use it (and suppress the warning) because an HTML fragment will
// We use it (and suppress the warning) because an HTML fragment will
// be wrapped around <html><body> tags which we don't really want to keep.
// Note: despite the warning, if loadHTML succeeds it will return true.
$result = @$f->loadHTML('<htmlfragment>'.$value.'</htmlfragment>');
@ -86,7 +86,7 @@ class JSLikeHTMLElement extends DOMElement
* @code
* $string = $div->innerHTML;
* @endcode
*/
*/
public function __get($name)
{
if ($name == 'innerHTML') {
@ -106,5 +106,4 @@ class JSLikeHTMLElement extends DOMElement
{
return '['.$this->tagName.']';
}
}
?>
}

File diff suppressed because it is too large Load diff

View file

@ -93,7 +93,7 @@ class Session
// Force 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.

View file

@ -14,9 +14,12 @@ if (!is_dir('db/')) {
@mkdir('db/',0705);
}
define ('MODE_DEMO', FALSE);
define ('ABS_PATH', 'assets/');
define ('CONVERT_LINKS_FOOTNOTES', TRUE);
define ('REVERT_FORCED_PARAGRAPH_ELEMENTS',FALSE);
define ('DOWNLOAD_PICTURES', TRUE);
define ('SALT', '464v54gLLw928uz4zUBqkRJeiPY68zCX');
$storage_type = 'sqlite'; # sqlite or file
include 'functions.php';
@ -32,9 +35,7 @@ require_once 'class.messages.php';
Session::init();
$store = new $storage_type();
$msg = new Messages();
$store = new $storage_type();
# initialisation de RainTPL
raintpl::$tpl_dir = './tpl/';
raintpl::$cache_dir = './cache/';
@ -42,4 +43,24 @@ raintpl::$base_url = get_poche_url();
raintpl::configure('path_replace', false);
raintpl::configure('debug', false);
$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);

View file

@ -23,6 +23,11 @@ function get_poche_url()
return $protocol . "://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
}
function encode_string($string)
{
return sha1($string . SALT);
}
// function define to retrieve url content
function get_external_file($url)
{
@ -39,6 +44,10 @@ function get_external_file($url)
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
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...
curl_setopt($curl, CURL_HTTP_VERSION_1_1, true);
curl_setopt($curl, CURLOPT_ENCODING, "gzip, deflate");
@ -54,7 +63,15 @@ function get_external_file($url)
} else {
// 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
$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);
$title = $url;
if (!preg_match('!^https?://!i', $url))
$url = 'http://' . $url;
$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)
{
$r = new Readability($html, $url);
$r->convertLinksToFootnotes = CONVERT_LINKS_FOOTNOTES;
$r->revertForcedParagraphElements = REVERT_FORCED_PARAGRAPH_ELEMENTS;
if($r->init())
{
$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;
}
@ -263,7 +290,13 @@ function display_view($view, $id = 0, $full_head = 'yes')
$tpl->assign('id', $entry['id']);
$tpl->assign('url', $entry['url']);
$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_read', $entry['is_read']);
$tpl->assign('load_all_js', 0);
@ -311,35 +344,46 @@ function action_to_do($action, $url, $id = 0)
if (MyTool::isUrl($url)) {
if($parametres_url = prepare_url($url)) {
$store->add($url, $parametres_url['title'], $parametres_url['content']);
$last_id = $store->getLastId();
if (DOWNLOAD_PICTURES) {
$content = filtre_picture($parametres_url['content'], $url, $last_id);
if ($store->add($url, $parametres_url['title'], $parametres_url['content'])) {
$last_id = $store->getLastId();
if (DOWNLOAD_PICTURES) {
$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 {
$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('add link ' . $url);
break;
case 'delete':
remove_directory(ABS_PATH . $id);
$store->deleteById($id);
$msg->add('s', 'the link has been deleted successfully');
logm('delete link #' . $id);
if ($store->deleteById($id)) {
remove_directory(ABS_PATH . $id);
$msg->add('s', 'the link has been deleted successfully');
logm('delete link #' . $id);
}
else {
$msg->add('e', 'the link wasn\'t deleted');
logm('error : can\'t delete link #' . $id);
}
break;
case 'toggle_fav' :
$store->favoriteById($id);
$msg->add('s', 'the favorite toggle has been done successfully');
logm('mark as favorite link #' . $id);
break;
case 'toggle_archive' :
$store->archiveById($id);
$msg->add('s', 'the archive toggle has been done successfully');
logm('archive link #' . $id);
break;
default:
@ -351,4 +395,4 @@ function logm($message)
{
$t = strval(date('Y/m/d_H:i:s')).' - '.$_SERVER["REMOTE_ADDR"].' - '.strval($message)."\n";
file_put_contents('./log.txt',$t,FILE_APPEND);
}
}

View file

@ -17,7 +17,6 @@ class Sqlite extends Store {
parent::__construct();
$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);
}
@ -25,6 +24,63 @@ class Sqlite extends Store {
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) {
try
{
@ -107,6 +163,7 @@ class Sqlite extends Store {
$sql_action = 'INSERT INTO entries ( url, title, content ) VALUES (?, ?, ?)';
$params_action = array($url, $title, $content);
$query = $this->executeQuery($sql_action, $params_action);
return $query;
}
public function deleteById($id) {
@ -114,6 +171,7 @@ class Sqlite extends Store {
$sql_action = "DELETE FROM entries WHERE id=?";
$params_action = array($id);
$query = $this->executeQuery($sql_action, $params_action);
return $query;
}
public function favoriteById($id) {

View file

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

View file

@ -25,9 +25,9 @@ $ref = empty($_SERVER['HTTP_REFERER']) ? '' : $_SERVER['HTTP_REFERER'];
if (isset($_GET['login'])) {
// Login
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');
$msg->add('s', 'welcome in your pocket!');
$msg->add('s', 'welcome in your poche!');
if (!empty($_POST['longlastingsession'])) {
$_SESSION['longlastingsession'] = 31536000;
$_SESSION['expires_on'] = time() + $_SESSION['longlastingsession'];
@ -50,6 +50,22 @@ elseif (isset($_GET['logout'])) {
Session::logout();
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
$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>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>
<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>
<p><a href="?view=export" target="_blank">Click here</a> to export your poche datas.</p>
</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 />
</div>
<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">
</div>
<div class="row">

View file

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