Merge branch 'dev'
@ -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
Before Width: | Height: | Size: 662 B After Width: | Height: | Size: 662 B |
0
img/messages/cross.png
Executable file → Normal file
Before Width: | Height: | Size: 655 B After Width: | Height: | Size: 655 B |
0
img/messages/help.png
Executable file → Normal file
Before Width: | Height: | Size: 786 B After Width: | Height: | Size: 786 B |
0
img/messages/tick.png
Executable file → Normal file
Before Width: | Height: | Size: 537 B After Width: | Height: | Size: 537 B |
0
img/messages/warning.png
Executable file → Normal file
Before Width: | Height: | Size: 666 B After Width: | Height: | Size: 666 B |
@ -107,4 +107,3 @@ class JSLikeHTMLElement extends DOMElement
|
||||
return '['.$this->tagName.']';
|
||||
}
|
||||
}
|
||||
?>
|
@ -2,6 +2,8 @@
|
||||
/**
|
||||
* Arc90's Readability ported to PHP for FiveFilters.org
|
||||
* Based on readability.js version 1.7.1 (without multi-page support)
|
||||
* Updated to allow HTML5 parsing with html5lib
|
||||
* Updated with lightClean mode to preserve more images and youtube/vimeo/viddler embeds
|
||||
* ------------------------------------------------------
|
||||
* Original URL: http://lab.arc90.com/experiments/readability/js/readability.js
|
||||
* Arc90's project URL: http://lab.arc90.com/experiments/readability/
|
||||
@ -10,7 +12,7 @@
|
||||
* More information: http://fivefilters.org/content-only/
|
||||
* License: Apache License, Version 2.0
|
||||
* Requires: PHP5
|
||||
* Date: 2011-07-22
|
||||
* Date: 2012-09-19
|
||||
*
|
||||
* Differences between the PHP port and the original
|
||||
* ------------------------------------------------------
|
||||
@ -62,14 +64,8 @@ $r->init();
|
||||
echo $r->articleContent->innerHTML;
|
||||
*/
|
||||
|
||||
|
||||
class Readability
|
||||
{
|
||||
/* constants */
|
||||
const FLAG_STRIP_UNLIKELYS = 1;
|
||||
const FLAG_WEIGHT_CLASSES = 2;
|
||||
const FLAG_CLEAN_CONDITIONALLY = 4;
|
||||
|
||||
public $version = '1.7.1-without-multi-page';
|
||||
public $convertLinksToFootnotes = false;
|
||||
public $revertForcedParagraphElements = true;
|
||||
@ -78,9 +74,10 @@ class Readability
|
||||
public $dom;
|
||||
public $url = null; // optional - URL where HTML was retrieved
|
||||
public $debug = false;
|
||||
public $lightClean = true; // preserves more content (experimental) added 2012-09-19
|
||||
protected $body = null; //
|
||||
protected $bodyCache = null; // Cache the body HTML in case we need to re-use it later
|
||||
protected $flags = self::FLAG_CLEAN_CONDITIONALLY; // 1 | 2 | 4; // Start with all flags set.
|
||||
protected $flags = 7; // 1 | 2 | 4; // Start with all flags set.
|
||||
protected $success = false; // indicates whether we were able to extract or not
|
||||
|
||||
/**
|
||||
@ -88,37 +85,47 @@ class Readability
|
||||
* Defined up here so we don't instantiate them repeatedly in loops.
|
||||
**/
|
||||
public $regexps = array(
|
||||
'unlikelyCandidates' => '/combx|comment|comments|community|disqus|extra|foot|header|menu|remark|rss|shoutbox|sidebar|sponsor|ad-break|agegate|pagination|pager|popup|tweet|twitter/i',
|
||||
'unlikelyCandidates' => '/combx|comment|community|disqus|extra|foot|header|menu|remark|rss|shoutbox|sidebar|sponsor|ad-break|agegate|pagination|pager|popup/i',
|
||||
'okMaybeItsACandidate' => '/and|article|body|column|main|shadow/i',
|
||||
'positive' => '/article|body|content|entry|hentry|main|page|pagination|post|text|blog|story/i',
|
||||
'negative' => '/combx|comment|comments|com-|contact|foot|footer|footnote|masthead|media|meta|outbrain|promo|related|scroll|shoutbox|sidebar|sponsor|shopping|tags|tool|widget/i',
|
||||
'divToPElements' => '/<(a|blockquote|dl|div|ol|p|pre|table|ul)/i',
|
||||
'positive' => '/article|body|content|entry|hentry|main|page|attachment|pagination|post|text|blog|story/i',
|
||||
'negative' => '/combx|comment|com-|contact|foot|footer|_nav|footnote|masthead|media|meta|outbrain|promo|related|scroll|shoutbox|sidebar|sponsor|shopping|tags|tool|widget/i',
|
||||
'divToPElements' => '/<(a|blockquote|dl|div|img|ol|p|pre|table|ul)/i',
|
||||
'replaceBrs' => '/(<br[^>]*>[ \n\r\t]*){2,}/i',
|
||||
'replaceFonts' => '/<(\/?)font[^>]*>/i',
|
||||
// 'trimRe' => '/^\s+|\s+$/g', // PHP has trim()
|
||||
'normalize' => '/\s{2,}/',
|
||||
'killBreaks' => '/(<br\s*\/?>(\s| ?)*){1,}/',
|
||||
'video' => '/http:\/\/(www\.)?(youtube|vimeo|dailymotion)\.com/i',
|
||||
'video' => '!//(player\.|www\.)?(youtube|vimeo|viddler)\.com!i',
|
||||
'skipFootnoteLink' => '/^\s*(\[?[a-z0-9]{1,2}\]?|^|edit|citation needed)\s*$/i'
|
||||
);
|
||||
|
||||
/* constants */
|
||||
const FLAG_STRIP_UNLIKELYS = 1;
|
||||
const FLAG_WEIGHT_CLASSES = 2;
|
||||
const FLAG_CLEAN_CONDITIONALLY = 4;
|
||||
|
||||
/**
|
||||
* Create instance of Readability
|
||||
* @param string UTF-8 encoded string
|
||||
* @param string (optional) URL associated with HTML (used for footnotes)
|
||||
* @param string which parser to use for turning raw HTML into a DOMDocument (either 'libxml' or 'html5lib')
|
||||
*/
|
||||
function __construct($html, $url=null)
|
||||
function __construct($html, $url=null, $parser='libxml')
|
||||
{
|
||||
$this->url = $url;
|
||||
/* Turn all double br's into p's */
|
||||
$html = preg_replace($this->regexps['replaceBrs'], '</p><p>', $html);
|
||||
$html = preg_replace($this->regexps['replaceFonts'], '<$1span>', $html);
|
||||
$html = mb_convert_encoding($html, 'HTML-ENTITIES', "UTF-8");
|
||||
if (trim($html) == '') $html = '<html></html>';
|
||||
if ($parser=='html5lib' && ($this->dom = HTML5_Parser::parse($html))) {
|
||||
// all good
|
||||
} else {
|
||||
$this->dom = new DOMDocument();
|
||||
$this->dom->preserveWhiteSpace = false;
|
||||
$this->dom->registerNodeClass('DOMElement', 'JSLikeHTMLElement');
|
||||
if (trim($html) == '') $html = '<html></html>';
|
||||
@$this->dom->loadHTML($html);
|
||||
$this->url = $url;
|
||||
}
|
||||
$this->dom->registerNodeClass('DOMElement', 'JSLikeHTMLElement');
|
||||
}
|
||||
|
||||
/**
|
||||
@ -214,7 +221,7 @@ class Readability
|
||||
* Debug
|
||||
*/
|
||||
protected function dbg($msg) {
|
||||
if ($this->debug) echo '* ',$msg, '<br />', "\n";
|
||||
if ($this->debug) echo '* ',$msg, "\n";
|
||||
}
|
||||
|
||||
/**
|
||||
@ -421,7 +428,7 @@ class Readability
|
||||
* If there is only one h2, they are probably using it
|
||||
* as a header and not a subheader, so remove it since we already have a header.
|
||||
***/
|
||||
if ($articleContent->getElementsByTagName('h2')->length == 1) {
|
||||
if (!$this->lightClean && ($articleContent->getElementsByTagName('h2')->length == 1)) {
|
||||
$this->clean($articleContent, 'h2');
|
||||
}
|
||||
$this->clean($articleContent, 'iframe');
|
||||
@ -440,8 +447,9 @@ class Readability
|
||||
$imgCount = $articleParagraphs->item($i)->getElementsByTagName('img')->length;
|
||||
$embedCount = $articleParagraphs->item($i)->getElementsByTagName('embed')->length;
|
||||
$objectCount = $articleParagraphs->item($i)->getElementsByTagName('object')->length;
|
||||
$iframeCount = $articleParagraphs->item($i)->getElementsByTagName('iframe')->length;
|
||||
|
||||
if ($imgCount === 0 && $embedCount === 0 && $objectCount === 0 && $this->getInnerText($articleParagraphs->item($i), false) == '')
|
||||
if ($imgCount === 0 && $embedCount === 0 && $objectCount === 0 && $iframeCount === 0 && $this->getInnerText($articleParagraphs->item($i), false) == '')
|
||||
{
|
||||
$articleParagraphs->item($i)->parentNode->removeChild($articleParagraphs->item($i));
|
||||
}
|
||||
@ -565,7 +573,7 @@ class Readability
|
||||
}
|
||||
else
|
||||
{
|
||||
// EXPERIMENTAL
|
||||
/* EXPERIMENTAL */
|
||||
// TODO: change these p elements back to text nodes after processing
|
||||
for ($i = 0, $il = $node->childNodes->length; $i < $il; $i++) {
|
||||
$childNode = $node->childNodes->item($i);
|
||||
@ -735,23 +743,6 @@ class Readability
|
||||
}
|
||||
}
|
||||
|
||||
/* Look for a special classname */
|
||||
if ($siblingNode->nodeType === XML_ELEMENT_NODE && $siblingNode->hasAttribute('class') && $siblingNode->getAttribute('class') != '')
|
||||
{
|
||||
if (preg_match($this->regexps['okMaybeItsACandidate'], $siblingNode->getAttribute('class'))) {
|
||||
$append = true;
|
||||
}
|
||||
}
|
||||
|
||||
/* Look for a special classname */
|
||||
if ($siblingNode->nodeType === XML_ELEMENT_NODE && $siblingNode->hasAttribute('id') && $siblingNode->getAttribute('id') != '')
|
||||
{
|
||||
if (preg_match($this->regexps['okMaybeItsACandidate'], $siblingNode->getAttribute('id'))) {
|
||||
$append = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if ($append)
|
||||
{
|
||||
$this->dbg('Appending node: ' . $siblingNode->nodeName);
|
||||
@ -964,13 +955,15 @@ class Readability
|
||||
* Clean a node of all elements of type "tag".
|
||||
* (Unless it's a youtube/vimeo video. People love movies.)
|
||||
*
|
||||
* Updated 2012-09-18 to preserve youtube/vimeo iframes
|
||||
*
|
||||
* @param DOMElement $e
|
||||
* @param string $tag
|
||||
* @return void
|
||||
*/
|
||||
public function clean($e, $tag) {
|
||||
$targetList = $e->getElementsByTagName($tag);
|
||||
$isEmbed = ($tag == 'object' || $tag == 'embed');
|
||||
$isEmbed = ($tag == 'iframe' || $tag == 'object' || $tag == 'embed');
|
||||
|
||||
for ($y=$targetList->length-1; $y >= 0; $y--) {
|
||||
/* Allow youtube and vimeo videos through as people usually want to see those. */
|
||||
@ -1035,6 +1028,7 @@ class Readability
|
||||
$img = $tagsList->item($i)->getElementsByTagName('img')->length;
|
||||
$li = $tagsList->item($i)->getElementsByTagName('li')->length-100;
|
||||
$input = $tagsList->item($i)->getElementsByTagName('input')->length;
|
||||
$a = $tagsList->item($i)->getElementsByTagName('a')->length;
|
||||
|
||||
$embedCount = 0;
|
||||
$embeds = $tagsList->item($i)->getElementsByTagName('embed');
|
||||
@ -1043,28 +1037,69 @@ class Readability
|
||||
$embedCount++;
|
||||
}
|
||||
}
|
||||
$embeds = $tagsList->item($i)->getElementsByTagName('iframe');
|
||||
for ($ei=0, $il=$embeds->length; $ei < $il; $ei++) {
|
||||
if (preg_match($this->regexps['video'], $embeds->item($ei)->getAttribute('src'))) {
|
||||
$embedCount++;
|
||||
}
|
||||
}
|
||||
|
||||
$linkDensity = $this->getLinkDensity($tagsList->item($i));
|
||||
$contentLength = strlen($this->getInnerText($tagsList->item($i)));
|
||||
$toRemove = false;
|
||||
|
||||
if ( $img > $p ) {
|
||||
if ($this->lightClean) {
|
||||
$this->dbg('Light clean...');
|
||||
if ( ($img > $p) && ($img > 4) ) {
|
||||
$this->dbg(' more than 4 images and more image elements than paragraph elements');
|
||||
$toRemove = true;
|
||||
} else if ($li > $p && $tag != 'ul' && $tag != 'ol') {
|
||||
$this->dbg(' too many <li> elements, and parent is not <ul> or <ol>');
|
||||
$toRemove = true;
|
||||
} else if ( $input > floor($p/3) ) {
|
||||
$this->dbg(' too many <input> elements');
|
||||
$toRemove = true;
|
||||
} else if ($contentLength < 25 && ($img === 0 || $img > 2) ) {
|
||||
} else if ($contentLength < 25 && ($embedCount === 0 && ($img === 0 || $img > 2))) {
|
||||
$this->dbg(' content length less than 25 chars, 0 embeds and either 0 images or more than 2 images');
|
||||
$toRemove = true;
|
||||
} else if($weight < 25 && $linkDensity > 0.2) {
|
||||
$this->dbg(' weight smaller than 25 and link density above 0.2');
|
||||
$toRemove = true;
|
||||
} else if($a > 2 && ($weight >= 25 && $linkDensity > 0.5)) {
|
||||
$this->dbg(' more than 2 links and weight above 25 but link density greater than 0.5');
|
||||
$toRemove = true;
|
||||
} else if($embedCount > 3) {
|
||||
$this->dbg(' more than 3 embeds');
|
||||
$toRemove = true;
|
||||
}
|
||||
} else {
|
||||
$this->dbg('Standard clean...');
|
||||
if ( $img > $p ) {
|
||||
$this->dbg(' more image elements than paragraph elements');
|
||||
$toRemove = true;
|
||||
} else if ($li > $p && $tag != 'ul' && $tag != 'ol') {
|
||||
$this->dbg(' too many <li> elements, and parent is not <ul> or <ol>');
|
||||
$toRemove = true;
|
||||
} else if ( $input > floor($p/3) ) {
|
||||
$this->dbg(' too many <input> elements');
|
||||
$toRemove = true;
|
||||
} else if ($contentLength < 25 && ($img === 0 || $img > 2) ) {
|
||||
$this->dbg(' content length less than 25 chars and 0 images, or more than 2 images');
|
||||
$toRemove = true;
|
||||
} else if($weight < 25 && $linkDensity > 0.2) {
|
||||
$this->dbg(' weight smaller than 25 and link density above 0.2');
|
||||
$toRemove = true;
|
||||
} else if($weight >= 25 && $linkDensity > 0.5) {
|
||||
$this->dbg(' weight above 25 but link density greater than 0.5');
|
||||
$toRemove = true;
|
||||
} else if(($embedCount == 1 && $contentLength < 75) || $embedCount > 1) {
|
||||
$this->dbg(' 1 embed and content length smaller than 75 chars, or more than one embed');
|
||||
$toRemove = true;
|
||||
}
|
||||
}
|
||||
|
||||
if ($toRemove) {
|
||||
//$this->dbg('Removing: '.$tagsList->item($i)->innerHTML);
|
||||
$tagsList->item($i)->parentNode->removeChild($tagsList->item($i));
|
||||
}
|
||||
}
|
||||
@ -1100,4 +1135,3 @@ class Readability
|
||||
$this->flags = $this->flags & ~$flag;
|
||||
}
|
||||
}
|
||||
?>
|
@ -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.
|
||||
|
@ -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';
|
||||
@ -33,8 +36,6 @@ require_once 'class.messages.php';
|
||||
Session::init();
|
||||
|
||||
$store = new $storage_type();
|
||||
$msg = new Messages();
|
||||
|
||||
# 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);
|
@ -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']);
|
||||
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');
|
||||
}
|
||||
else {
|
||||
$msg->add('e', 'error during insertion : the link wasn\'t added');
|
||||
}
|
||||
}
|
||||
else {
|
||||
$msg->add('e', 'the link has been added successfully');
|
||||
$msg->add('e', 'error during url preparation : the link wasn\'t added');
|
||||
logm('error during url preparation');
|
||||
}
|
||||
}
|
||||
else {
|
||||
$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':
|
||||
if ($store->deleteById($id)) {
|
||||
remove_directory(ABS_PATH . $id);
|
||||
$store->deleteById($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:
|
||||
|
@ -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) {
|
||||
|
@ -13,6 +13,14 @@ class Store {
|
||||
|
||||
}
|
||||
|
||||
public function getLogin() {
|
||||
|
||||
}
|
||||
|
||||
public function getPassword() {
|
||||
|
||||
}
|
||||
|
||||
public function add() {
|
||||
|
||||
}
|
||||
|
20
index.php
@ -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';
|
||||
|
@ -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
@ -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"}
|
@ -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}
|
||||
|