From a4565e88edbc8e3bd092a475469769c86a4c350c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Fri, 2 Aug 2013 22:40:51 +0200 Subject: add Twig & refactor poche --- inc/poche/pocheCore.php | 257 ++++++++++++++++++++++++++++++++++++++++++ inc/poche/pochePictures.php | 114 +++++++++++++++++++ inc/poche/pocheTool.class.php | 124 ++++++++++++++++++++ 3 files changed, 495 insertions(+) create mode 100644 inc/poche/pocheCore.php create mode 100644 inc/poche/pochePictures.php create mode 100644 inc/poche/pocheTool.class.php (limited to 'inc/poche') diff --git a/inc/poche/pocheCore.php b/inc/poche/pocheCore.php new file mode 100644 index 00000000..52c603ac --- /dev/null +++ b/inc/poche/pocheCore.php @@ -0,0 +1,257 @@ + + * @copyright 2013 + * @license http://www.wtfpl.net/ see COPYING file + */ + +function encode_string($string) +{ + return sha1($string . SALT); +} + +function get_external_file($url) +{ + $timeout = 15; + $useragent = "Mozilla/5.0 (Windows NT 5.1; rv:18.0) Gecko/20100101 Firefox/18.0"; + + if (in_array ('curl', get_loaded_extensions())) { + # Fetch feed from URL + $curl = curl_init(); + curl_setopt($curl, CURLOPT_URL, $url); + curl_setopt($curl, CURLOPT_TIMEOUT, $timeout); + curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true); + 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"); + curl_setopt($curl, CURLOPT_USERAGENT, $useragent); + + $data = curl_exec($curl); + $httpcode = curl_getinfo($curl, CURLINFO_HTTP_CODE); + $httpcodeOK = isset($httpcode) and ($httpcode == 200 or $httpcode == 301); + curl_close($curl); + } else { + # create http context and add timeout and user-agent + $context = stream_context_create( + array( + 'http' => array( + 'timeout' => $timeout, + 'header' => "User-Agent: " . $useragent, + 'follow_location' => true + ), + 'ssl' => array( + 'verify_peer' => false, + 'allow_self_signed' => true + ) + ) + ); + + # only download page lesser than 4MB + $data = @file_get_contents($url, false, $context, -1, 4000000); + + if (isset($http_response_header) and isset($http_response_header[0])) { + $httpcodeOK = isset($http_response_header) and isset($http_response_header[0]) and ((strpos($http_response_header[0], '200 OK') !== FALSE) or (strpos($http_response_header[0], '301 Moved Permanently') !== FALSE)); + } + } + + # if response is not empty and response is OK + if (isset($data) and isset($httpcodeOK) and $httpcodeOK) { + + # take charset of page and get it + preg_match('##Usi', $data, $meta); + + # if meta tag is found + if (!empty($meta[0])) { + preg_match('#charset="?(.*)"#si', $meta[0], $encoding); + # if charset is found set it otherwise, set it to utf-8 + $html_charset = (!empty($encoding[1])) ? strtolower($encoding[1]) : 'utf-8'; + } else { + $html_charset = 'utf-8'; + $encoding[1] = ''; + } + + # replace charset of url to charset of page + $data = str_replace('charset=' . $encoding[1], 'charset=' . $html_charset, $data); + + return $data; + } + else { + return FALSE; + } +} + +function fetch_url_content($url) +{ + $url = base64_decode($url); + if (pocheTool::isUrl($url)) { + $url = pocheTool::cleanURL($url); + $html = Encoding::toUTF8(get_external_file($url)); + + # 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)); + } + + if (function_exists('tidy_parse_string')) { + $tidy = tidy_parse_string($html, array(), 'UTF8'); + $tidy->cleanRepair(); + $html = $tidy->value; + } + + $parameters = array(); + if (isset($html) and strlen($html) > 0) + { + $readability = new Readability($html, $url); + $readability->convertLinksToFootnotes = CONVERT_LINKS_FOOTNOTES; + $readability->revertForcedParagraphElements = REVERT_FORCED_PARAGRAPH_ELEMENTS; + + if($readability->init()) + { + $content = $readability->articleContent->innerHTML; + $parameters['title'] = $readability->articleTitle->innerHTML; + $parameters['content'] = $content; + + return $parameters; + } + } + } + else { + #$msg->add('e', _('error during url preparation : the link is not valid')); + pocheTool::logm($url . ' is not a valid url'); + } + + return FALSE; +} + +function display_view($view, $id = 0, $full_head = 'yes') +{ + global $tpl, $store, $msg; + + switch ($view) + { + case 'export': + $entries = $store->retrieveAll(); + $tpl->assign('export', pocheTool::renderJson($entries)); + $tpl->draw('export'); + pocheTool::logm('export view'); + break; + case 'config': + $tpl->assign('load_all_js', 0); + $tpl->draw('head'); + $tpl->draw('home'); + $tpl->draw('config'); + $tpl->draw('js'); + $tpl->draw('footer'); + pocheTool::logm('config view'); + break; + case 'view': + $entry = $store->retrieveOneById($id); + + if ($entry != NULL) { + $tpl->assign('id', $entry['id']); + $tpl->assign('url', $entry['url']); + $tpl->assign('title', $entry['title']); + $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); + $tpl->draw('view'); + } + else { + pocheTool::logm('error in view call : entry is NULL'); + } + + pocheTool::logm('view link #' . $id); + break; + default: # home view + $entries = $store->getEntriesByView($view); + + $tpl->assign('entries', $entries); + + if ($full_head == 'yes') { + $tpl->assign('load_all_js', 1); + $tpl->draw('head'); + $tpl->draw('home'); + } + + $tpl->draw('entries'); + + if ($full_head == 'yes') { + $tpl->draw('js'); + $tpl->draw('footer'); + } + break; + } +} + +/** + * Appel d'une action (mark as fav, archive, delete) + */ +function action_to_do($action, $url, $id = 0) +{ + global $store, $msg; + + switch ($action) + { + case 'add': + if($parametres_url = fetch_url_content($url)) { + if ($store->add($url, $parametres_url['title'], $parametres_url['content'])) { + pocheTool::logm('add link ' . $url); + $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')); + pocheTool::logm('error during insertion : the link wasn\'t added'); + } + } + else { + #$msg->add('e', _('error during url preparation : the link wasn\'t added')); + pocheTool::logm('error during content fetch'); + } + break; + case 'delete': + if ($store->deleteById($id)) { + if (DOWNLOAD_PICTURES) { + remove_directory(ABS_PATH . $id); + } + #$msg->add('s', _('the link has been deleted successfully')); + pocheTool::logm('delete link #' . $id); + } + else { + #$msg->add('e', _('the link wasn\'t deleted')); + pocheTool::logm('error : can\'t delete link #' . $id); + } + break; + case 'toggle_fav' : + $store->favoriteById($id); + pocheTool::logm('mark as favorite link #' . $id); + break; + case 'toggle_archive' : + $store->archiveById($id); + pocheTool::logm('archive link #' . $id); + break; + default: + break; + } +} diff --git a/inc/poche/pochePictures.php b/inc/poche/pochePictures.php new file mode 100644 index 00000000..bfc80657 --- /dev/null +++ b/inc/poche/pochePictures.php @@ -0,0 +1,114 @@ + + * @copyright 2013 + * @license http://www.wtfpl.net/ see COPYING file + */ + +/** + * On modifie les URLS des images dans le corps de l'article + */ +function filtre_picture($content, $url, $id) +{ + $matches = array(); + preg_match_all('#<\s*(img)[^>]+src="([^"]*)"[^>]*>#Si', $content, $matches, PREG_SET_ORDER); + foreach($matches as $i => $link) + { + $link[1] = trim($link[1]); + if (!preg_match('#^(([a-z]+://)|(\#))#', $link[1]) ) + { + $absolute_path = get_absolute_link($link[2],$url); + $filename = basename(parse_url($absolute_path, PHP_URL_PATH)); + $directory = create_assets_directory($id); + $fullpath = $directory . '/' . $filename; + download_pictures($absolute_path, $fullpath); + $content = str_replace($matches[$i][2], $fullpath, $content); + } + + } + + return $content; +} + +/** + * Retourne le lien absolu + */ +function get_absolute_link($relative_link, $url) +{ + /* return if already absolute URL */ + if (parse_url($relative_link, PHP_URL_SCHEME) != '') return $relative_link; + + /* queries and anchors */ + if ($relative_link[0]=='#' || $relative_link[0]=='?') return $url . $relative_link; + + /* parse base URL and convert to local variables: + $scheme, $host, $path */ + extract(parse_url($url)); + + /* remove non-directory element from path */ + $path = preg_replace('#/[^/]*$#', '', $path); + + /* destroy path if relative url points to root */ + if ($relative_link[0] == '/') $path = ''; + + /* dirty absolute URL */ + $abs = $host . $path . '/' . $relative_link; + + /* replace '//' or '/./' or '/foo/../' with '/' */ + $re = array('#(/\.?/)#', '#/(?!\.\.)[^/]+/\.\./#'); + for($n=1; $n>0; $abs=preg_replace($re, '/', $abs, -1, $n)) {} + + /* absolute URL is ready! */ + return $scheme.'://'.$abs; +} + +/** + * Téléchargement des images + */ + +function download_pictures($absolute_path, $fullpath) +{ + $rawdata = get_external_file($absolute_path); + + if(file_exists($fullpath)) { + unlink($fullpath); + } + $fp = fopen($fullpath, 'x'); + fwrite($fp, $rawdata); + fclose($fp); +} + +/** + * Crée un répertoire de médias pour l'article + */ +function create_assets_directory($id) +{ + $assets_path = ABS_PATH; + if(!is_dir($assets_path)) { + mkdir($assets_path, 0705); + } + + $article_directory = $assets_path . $id; + if(!is_dir($article_directory)) { + mkdir($article_directory, 0705); + } + + return $article_directory; +} + +/** + * Suppression du répertoire d'images + */ +function remove_directory($directory) +{ + if(is_dir($directory)) { + $files = array_diff(scandir($directory), array('.','..')); + foreach ($files as $file) { + (is_dir("$directory/$file")) ? remove_directory("$directory/$file") : unlink("$directory/$file"); + } + return rmdir($directory); + } +} diff --git a/inc/poche/pocheTool.class.php b/inc/poche/pocheTool.class.php new file mode 100644 index 00000000..cade115e --- /dev/null +++ b/inc/poche/pocheTool.class.php @@ -0,0 +1,124 @@ + + * @copyright 2013 + * @license http://www.wtfpl.net/ see COPYING file + */ + +class pocheTools +{ + public static function initPhp() + { + define('START_TIME', microtime(true)); + + if (phpversion() < 5) { + die(_('Oops, it seems you don\'t have PHP 5.')); + } + + error_reporting(E_ALL); + + function stripslashesDeep($value) { + return is_array($value) + ? array_map('stripslashesDeep', $value) + : stripslashes($value); + } + + if (get_magic_quotes_gpc()) { + $_POST = array_map('stripslashesDeep', $_POST); + $_GET = array_map('stripslashesDeep', $_GET); + $_COOKIE = array_map('stripslashesDeep', $_COOKIE); + } + + ob_start(); + register_shutdown_function('ob_end_flush'); + } + + public static function isUrl($url) + { + $pattern = '|^http(s)?://[a-z0-9-]+(.[a-z0-9-]+)*(:[0-9]+)?(/.*)?$|i'; + + return preg_match($pattern, $url); + } + + public static function getUrl() + { + $https = (!empty($_SERVER['HTTPS']) + && (strtolower($_SERVER['HTTPS']) == 'on')) + || (isset($_SERVER["SERVER_PORT"]) + && $_SERVER["SERVER_PORT"] == '443'); // HTTPS detection. + $serverport = (!isset($_SERVER["SERVER_PORT"]) + || $_SERVER["SERVER_PORT"] == '80' + || ($https && $_SERVER["SERVER_PORT"] == '443') + ? '' : ':' . $_SERVER["SERVER_PORT"]); + + $scriptname = str_replace('/index.php', '/', $_SERVER["SCRIPT_NAME"]); + + if (!isset($_SERVER["SERVER_NAME"])) { + return $scriptname; + } + + return 'http' . ($https ? 's' : '') . '://' + . $_SERVER["SERVER_NAME"] . $serverport . $scriptname; + } + + public static function redirect($url = '') + { + if ($url === '') { + $url = (empty($_SERVER['HTTP_REFERER'])?'?':$_SERVER['HTTP_REFERER']); + if (isset($_POST['returnurl'])) { + $url = $_POST['returnurl']; + } + } + + # prevent loop + if (empty($url) || parse_url($url, PHP_URL_QUERY) === $_SERVER['QUERY_STRING']) { + $url = pocheTool::getUrl(); + } + + if (substr($url, 0, 1) !== '?') { + $ref = pocheTool::getUrl(); + if (substr($url, 0, strlen($ref)) !== $ref) { + $url = $ref; + } + } + header('Location: '.$url); + exit(); + } + + public static function cleanURL($url) + { + + $url = html_entity_decode(trim($url)); + + $stuff = strpos($url,'&utm_source='); + if ($stuff !== FALSE) + $url = substr($url, 0, $stuff); + $stuff = strpos($url,'?utm_source='); + if ($stuff !== FALSE) + $url = substr($url, 0, $stuff); + $stuff = strpos($url,'#xtor=RSS-'); + if ($stuff !== FALSE) + $url = substr($url, 0, $stuff); + + return $url; + } + + public static function renderJson($data) + { + header('Cache-Control: no-cache, must-revalidate'); + header('Expires: Sat, 26 Jul 1997 05:00:00 GMT'); + header('Content-type: application/json; charset=UTF-8'); + + echo json_encode($data); + exit(); + } + + public static 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); + } +} \ No newline at end of file -- cgit v1.2.3 From 5ffe5cf541d0d1c7524537b034d0cde3da18f6e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Fri, 2 Aug 2013 23:00:57 +0200 Subject: rename pocheTool -> pocheTools --- inc/poche/pocheCore.php | 18 +++--- inc/poche/pochePictures.php | 12 ++-- inc/poche/pocheTool.class.php | 124 ---------------------------------------- inc/poche/pocheTools.class.php | 126 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 140 insertions(+), 140 deletions(-) delete mode 100644 inc/poche/pocheTool.class.php create mode 100644 inc/poche/pocheTools.class.php (limited to 'inc/poche') diff --git a/inc/poche/pocheCore.php b/inc/poche/pocheCore.php index 52c603ac..34c15d84 100644 --- a/inc/poche/pocheCore.php +++ b/inc/poche/pocheCore.php @@ -136,10 +136,16 @@ function fetch_url_content($url) function display_view($view, $id = 0, $full_head = 'yes') { - global $tpl, $store, $msg; + global $tpl, $store; switch ($view) { + case 'install': + pocheTool::logm('install mode'); + break; + case 'import'; + pocheTool::logm('import mode'); + break; case 'export': $entries = $store->retrieveAll(); $tpl->assign('export', pocheTool::renderJson($entries)); @@ -157,8 +163,8 @@ function display_view($view, $id = 0, $full_head = 'yes') break; case 'view': $entry = $store->retrieveOneById($id); - if ($entry != NULL) { + pocheTool::logm('view link #' . $id); $tpl->assign('id', $entry['id']); $tpl->assign('url', $entry['url']); $tpl->assign('title', $entry['title']); @@ -177,12 +183,9 @@ function display_view($view, $id = 0, $full_head = 'yes') else { pocheTool::logm('error in view call : entry is NULL'); } - - pocheTool::logm('view link #' . $id); break; default: # home view $entries = $store->getEntriesByView($view); - $tpl->assign('entries', $entries); if ($full_head == 'yes') { @@ -192,7 +195,6 @@ function display_view($view, $id = 0, $full_head = 'yes') } $tpl->draw('entries'); - if ($full_head == 'yes') { $tpl->draw('js'); $tpl->draw('footer'); @@ -202,11 +204,11 @@ function display_view($view, $id = 0, $full_head = 'yes') } /** - * Appel d'une action (mark as fav, archive, delete) + * Call action (mark as fav, archive, delete, etc.) */ function action_to_do($action, $url, $id = 0) { - global $store, $msg; + global $store; switch ($action) { diff --git a/inc/poche/pochePictures.php b/inc/poche/pochePictures.php index bfc80657..0d73a149 100644 --- a/inc/poche/pochePictures.php +++ b/inc/poche/pochePictures.php @@ -15,11 +15,9 @@ function filtre_picture($content, $url, $id) { $matches = array(); preg_match_all('#<\s*(img)[^>]+src="([^"]*)"[^>]*>#Si', $content, $matches, PREG_SET_ORDER); - foreach($matches as $i => $link) - { + foreach($matches as $i => $link) { $link[1] = trim($link[1]); - if (!preg_match('#^(([a-z]+://)|(\#))#', $link[1]) ) - { + if (!preg_match('#^(([a-z]+://)|(\#))#', $link[1])) { $absolute_path = get_absolute_link($link[2],$url); $filename = basename(parse_url($absolute_path, PHP_URL_PATH)); $directory = create_assets_directory($id); @@ -36,8 +34,7 @@ function filtre_picture($content, $url, $id) /** * Retourne le lien absolu */ -function get_absolute_link($relative_link, $url) -{ +function get_absolute_link($relative_link, $url) { /* return if already absolute URL */ if (parse_url($relative_link, PHP_URL_SCHEME) != '') return $relative_link; @@ -68,7 +65,6 @@ function get_absolute_link($relative_link, $url) /** * Téléchargement des images */ - function download_pictures($absolute_path, $fullpath) { $rawdata = get_external_file($absolute_path); @@ -111,4 +107,4 @@ function remove_directory($directory) } return rmdir($directory); } -} +} \ No newline at end of file diff --git a/inc/poche/pocheTool.class.php b/inc/poche/pocheTool.class.php deleted file mode 100644 index cade115e..00000000 --- a/inc/poche/pocheTool.class.php +++ /dev/null @@ -1,124 +0,0 @@ - - * @copyright 2013 - * @license http://www.wtfpl.net/ see COPYING file - */ - -class pocheTools -{ - public static function initPhp() - { - define('START_TIME', microtime(true)); - - if (phpversion() < 5) { - die(_('Oops, it seems you don\'t have PHP 5.')); - } - - error_reporting(E_ALL); - - function stripslashesDeep($value) { - return is_array($value) - ? array_map('stripslashesDeep', $value) - : stripslashes($value); - } - - if (get_magic_quotes_gpc()) { - $_POST = array_map('stripslashesDeep', $_POST); - $_GET = array_map('stripslashesDeep', $_GET); - $_COOKIE = array_map('stripslashesDeep', $_COOKIE); - } - - ob_start(); - register_shutdown_function('ob_end_flush'); - } - - public static function isUrl($url) - { - $pattern = '|^http(s)?://[a-z0-9-]+(.[a-z0-9-]+)*(:[0-9]+)?(/.*)?$|i'; - - return preg_match($pattern, $url); - } - - public static function getUrl() - { - $https = (!empty($_SERVER['HTTPS']) - && (strtolower($_SERVER['HTTPS']) == 'on')) - || (isset($_SERVER["SERVER_PORT"]) - && $_SERVER["SERVER_PORT"] == '443'); // HTTPS detection. - $serverport = (!isset($_SERVER["SERVER_PORT"]) - || $_SERVER["SERVER_PORT"] == '80' - || ($https && $_SERVER["SERVER_PORT"] == '443') - ? '' : ':' . $_SERVER["SERVER_PORT"]); - - $scriptname = str_replace('/index.php', '/', $_SERVER["SCRIPT_NAME"]); - - if (!isset($_SERVER["SERVER_NAME"])) { - return $scriptname; - } - - return 'http' . ($https ? 's' : '') . '://' - . $_SERVER["SERVER_NAME"] . $serverport . $scriptname; - } - - public static function redirect($url = '') - { - if ($url === '') { - $url = (empty($_SERVER['HTTP_REFERER'])?'?':$_SERVER['HTTP_REFERER']); - if (isset($_POST['returnurl'])) { - $url = $_POST['returnurl']; - } - } - - # prevent loop - if (empty($url) || parse_url($url, PHP_URL_QUERY) === $_SERVER['QUERY_STRING']) { - $url = pocheTool::getUrl(); - } - - if (substr($url, 0, 1) !== '?') { - $ref = pocheTool::getUrl(); - if (substr($url, 0, strlen($ref)) !== $ref) { - $url = $ref; - } - } - header('Location: '.$url); - exit(); - } - - public static function cleanURL($url) - { - - $url = html_entity_decode(trim($url)); - - $stuff = strpos($url,'&utm_source='); - if ($stuff !== FALSE) - $url = substr($url, 0, $stuff); - $stuff = strpos($url,'?utm_source='); - if ($stuff !== FALSE) - $url = substr($url, 0, $stuff); - $stuff = strpos($url,'#xtor=RSS-'); - if ($stuff !== FALSE) - $url = substr($url, 0, $stuff); - - return $url; - } - - public static function renderJson($data) - { - header('Cache-Control: no-cache, must-revalidate'); - header('Expires: Sat, 26 Jul 1997 05:00:00 GMT'); - header('Content-type: application/json; charset=UTF-8'); - - echo json_encode($data); - exit(); - } - - public static 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); - } -} \ No newline at end of file diff --git a/inc/poche/pocheTools.class.php b/inc/poche/pocheTools.class.php new file mode 100644 index 00000000..8907c18e --- /dev/null +++ b/inc/poche/pocheTools.class.php @@ -0,0 +1,126 @@ + + * @copyright 2013 + * @license http://www.wtfpl.net/ see COPYING file + */ + +class pocheTools +{ + public static function initPhp() + { + define('START_TIME', microtime(true)); + + if (phpversion() < 5) { + die(_('Oops, it seems you don\'t have PHP 5.')); + } + + error_reporting(E_ALL); + + function stripslashesDeep($value) { + return is_array($value) + ? array_map('stripslashesDeep', $value) + : stripslashes($value); + } + + if (get_magic_quotes_gpc()) { + $_POST = array_map('stripslashesDeep', $_POST); + $_GET = array_map('stripslashesDeep', $_GET); + $_COOKIE = array_map('stripslashesDeep', $_COOKIE); + } + + ob_start(); + register_shutdown_function('ob_end_flush'); + } + + public static function isUrl($url) + { + $pattern = '|^http(s)?://[a-z0-9-]+(.[a-z0-9-]+)*(:[0-9]+)?(/.*)?$|i'; + + return preg_match($pattern, $url); + } + + public static function getUrl() + { + $https = (!empty($_SERVER['HTTPS']) + && (strtolower($_SERVER['HTTPS']) == 'on')) + || (isset($_SERVER["SERVER_PORT"]) + && $_SERVER["SERVER_PORT"] == '443'); // HTTPS detection. + $serverport = (!isset($_SERVER["SERVER_PORT"]) + || $_SERVER["SERVER_PORT"] == '80' + || ($https && $_SERVER["SERVER_PORT"] == '443') + ? '' : ':' . $_SERVER["SERVER_PORT"]); + + $scriptname = str_replace('/index.php', '/', $_SERVER["SCRIPT_NAME"]); + + if (!isset($_SERVER["SERVER_NAME"])) { + return $scriptname; + } + + return 'http' . ($https ? 's' : '') . '://' + . $_SERVER["SERVER_NAME"] . $serverport . $scriptname; + } + + public static function redirect($url = '') + { + if ($url === '') { + $url = (empty($_SERVER['HTTP_REFERER'])?'?':$_SERVER['HTTP_REFERER']); + if (isset($_POST['returnurl'])) { + $url = $_POST['returnurl']; + } + } + + # prevent loop + if (empty($url) || parse_url($url, PHP_URL_QUERY) === $_SERVER['QUERY_STRING']) { + $url = pocheTool::getUrl(); + } + + if (substr($url, 0, 1) !== '?') { + $ref = pocheTool::getUrl(); + if (substr($url, 0, strlen($ref)) !== $ref) { + $url = $ref; + } + } + header('Location: '.$url); + exit(); + } + + public static function cleanURL($url) + { + + $url = html_entity_decode(trim($url)); + + $stuff = strpos($url,'&utm_source='); + if ($stuff !== FALSE) + $url = substr($url, 0, $stuff); + $stuff = strpos($url,'?utm_source='); + if ($stuff !== FALSE) + $url = substr($url, 0, $stuff); + $stuff = strpos($url,'#xtor=RSS-'); + if ($stuff !== FALSE) + $url = substr($url, 0, $stuff); + + return $url; + } + + public static function renderJson($data) + { + header('Cache-Control: no-cache, must-revalidate'); + header('Expires: Sat, 26 Jul 1997 05:00:00 GMT'); + header('Content-type: application/json; charset=UTF-8'); + + echo json_encode($data); + exit(); + } + + public static function logm($message) + { + if (DEBUG_POCHE) { + $t = strval(date('Y/m/d_H:i:s')) . ' - ' . $_SERVER["REMOTE_ADDR"] . ' - ' . strval($message) . "\n"; + file_put_contents('./log.txt', $t, FILE_APPEND); + } + } +} \ No newline at end of file -- cgit v1.2.3 From 161395d7098ec2bd86671d15d5b54f39148e2d5b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Fri, 2 Aug 2013 23:04:24 +0200 Subject: mv pochetool pochetools --- inc/poche/pocheCore.php | 34 +++++------ inc/poche/pocheTool.class.php | 126 +++++++++++++++++++++++++++++++++++++++++ inc/poche/pocheTools.class.php | 4 +- 3 files changed, 145 insertions(+), 19 deletions(-) create mode 100644 inc/poche/pocheTool.class.php (limited to 'inc/poche') diff --git a/inc/poche/pocheCore.php b/inc/poche/pocheCore.php index 34c15d84..e68696af 100644 --- a/inc/poche/pocheCore.php +++ b/inc/poche/pocheCore.php @@ -93,8 +93,8 @@ function get_external_file($url) function fetch_url_content($url) { $url = base64_decode($url); - if (pocheTool::isUrl($url)) { - $url = pocheTool::cleanURL($url); + if (pocheTools::isUrl($url)) { + $url = pocheTools::cleanURL($url); $html = Encoding::toUTF8(get_external_file($url)); # if get_external_file if not able to retrieve HTTPS content, try the same URL with HTTP protocol @@ -128,7 +128,7 @@ function fetch_url_content($url) } else { #$msg->add('e', _('error during url preparation : the link is not valid')); - pocheTool::logm($url . ' is not a valid url'); + pocheTools::logm($url . ' is not a valid url'); } return FALSE; @@ -141,16 +141,16 @@ function display_view($view, $id = 0, $full_head = 'yes') switch ($view) { case 'install': - pocheTool::logm('install mode'); + pocheTools::logm('install mode'); break; case 'import'; - pocheTool::logm('import mode'); + pocheTools::logm('import mode'); break; case 'export': $entries = $store->retrieveAll(); - $tpl->assign('export', pocheTool::renderJson($entries)); + $tpl->assign('export', pocheTools::renderJson($entries)); $tpl->draw('export'); - pocheTool::logm('export view'); + pocheTools::logm('export view'); break; case 'config': $tpl->assign('load_all_js', 0); @@ -159,12 +159,12 @@ function display_view($view, $id = 0, $full_head = 'yes') $tpl->draw('config'); $tpl->draw('js'); $tpl->draw('footer'); - pocheTool::logm('config view'); + pocheTools::logm('config view'); break; case 'view': $entry = $store->retrieveOneById($id); if ($entry != NULL) { - pocheTool::logm('view link #' . $id); + pocheTools::logm('view link #' . $id); $tpl->assign('id', $entry['id']); $tpl->assign('url', $entry['url']); $tpl->assign('title', $entry['title']); @@ -181,7 +181,7 @@ function display_view($view, $id = 0, $full_head = 'yes') $tpl->draw('view'); } else { - pocheTool::logm('error in view call : entry is NULL'); + pocheTools::logm('error in view call : entry is NULL'); } break; default: # home view @@ -215,7 +215,7 @@ function action_to_do($action, $url, $id = 0) case 'add': if($parametres_url = fetch_url_content($url)) { if ($store->add($url, $parametres_url['title'], $parametres_url['content'])) { - pocheTool::logm('add link ' . $url); + pocheTools::logm('add link ' . $url); $last_id = $store->getLastId(); if (DOWNLOAD_PICTURES) { $content = filtre_picture($parametres_url['content'], $url, $last_id); @@ -224,12 +224,12 @@ function action_to_do($action, $url, $id = 0) } else { #$msg->add('e', _('error during insertion : the link wasn\'t added')); - pocheTool::logm('error during insertion : the link wasn\'t added'); + pocheTools::logm('error during insertion : the link wasn\'t added'); } } else { #$msg->add('e', _('error during url preparation : the link wasn\'t added')); - pocheTool::logm('error during content fetch'); + pocheTools::logm('error during content fetch'); } break; case 'delete': @@ -238,20 +238,20 @@ function action_to_do($action, $url, $id = 0) remove_directory(ABS_PATH . $id); } #$msg->add('s', _('the link has been deleted successfully')); - pocheTool::logm('delete link #' . $id); + pocheTools::logm('delete link #' . $id); } else { #$msg->add('e', _('the link wasn\'t deleted')); - pocheTool::logm('error : can\'t delete link #' . $id); + pocheTools::logm('error : can\'t delete link #' . $id); } break; case 'toggle_fav' : $store->favoriteById($id); - pocheTool::logm('mark as favorite link #' . $id); + pocheTools::logm('mark as favorite link #' . $id); break; case 'toggle_archive' : $store->archiveById($id); - pocheTool::logm('archive link #' . $id); + pocheTools::logm('archive link #' . $id); break; default: break; diff --git a/inc/poche/pocheTool.class.php b/inc/poche/pocheTool.class.php new file mode 100644 index 00000000..8907c18e --- /dev/null +++ b/inc/poche/pocheTool.class.php @@ -0,0 +1,126 @@ + + * @copyright 2013 + * @license http://www.wtfpl.net/ see COPYING file + */ + +class pocheTools +{ + public static function initPhp() + { + define('START_TIME', microtime(true)); + + if (phpversion() < 5) { + die(_('Oops, it seems you don\'t have PHP 5.')); + } + + error_reporting(E_ALL); + + function stripslashesDeep($value) { + return is_array($value) + ? array_map('stripslashesDeep', $value) + : stripslashes($value); + } + + if (get_magic_quotes_gpc()) { + $_POST = array_map('stripslashesDeep', $_POST); + $_GET = array_map('stripslashesDeep', $_GET); + $_COOKIE = array_map('stripslashesDeep', $_COOKIE); + } + + ob_start(); + register_shutdown_function('ob_end_flush'); + } + + public static function isUrl($url) + { + $pattern = '|^http(s)?://[a-z0-9-]+(.[a-z0-9-]+)*(:[0-9]+)?(/.*)?$|i'; + + return preg_match($pattern, $url); + } + + public static function getUrl() + { + $https = (!empty($_SERVER['HTTPS']) + && (strtolower($_SERVER['HTTPS']) == 'on')) + || (isset($_SERVER["SERVER_PORT"]) + && $_SERVER["SERVER_PORT"] == '443'); // HTTPS detection. + $serverport = (!isset($_SERVER["SERVER_PORT"]) + || $_SERVER["SERVER_PORT"] == '80' + || ($https && $_SERVER["SERVER_PORT"] == '443') + ? '' : ':' . $_SERVER["SERVER_PORT"]); + + $scriptname = str_replace('/index.php', '/', $_SERVER["SCRIPT_NAME"]); + + if (!isset($_SERVER["SERVER_NAME"])) { + return $scriptname; + } + + return 'http' . ($https ? 's' : '') . '://' + . $_SERVER["SERVER_NAME"] . $serverport . $scriptname; + } + + public static function redirect($url = '') + { + if ($url === '') { + $url = (empty($_SERVER['HTTP_REFERER'])?'?':$_SERVER['HTTP_REFERER']); + if (isset($_POST['returnurl'])) { + $url = $_POST['returnurl']; + } + } + + # prevent loop + if (empty($url) || parse_url($url, PHP_URL_QUERY) === $_SERVER['QUERY_STRING']) { + $url = pocheTool::getUrl(); + } + + if (substr($url, 0, 1) !== '?') { + $ref = pocheTool::getUrl(); + if (substr($url, 0, strlen($ref)) !== $ref) { + $url = $ref; + } + } + header('Location: '.$url); + exit(); + } + + public static function cleanURL($url) + { + + $url = html_entity_decode(trim($url)); + + $stuff = strpos($url,'&utm_source='); + if ($stuff !== FALSE) + $url = substr($url, 0, $stuff); + $stuff = strpos($url,'?utm_source='); + if ($stuff !== FALSE) + $url = substr($url, 0, $stuff); + $stuff = strpos($url,'#xtor=RSS-'); + if ($stuff !== FALSE) + $url = substr($url, 0, $stuff); + + return $url; + } + + public static function renderJson($data) + { + header('Cache-Control: no-cache, must-revalidate'); + header('Expires: Sat, 26 Jul 1997 05:00:00 GMT'); + header('Content-type: application/json; charset=UTF-8'); + + echo json_encode($data); + exit(); + } + + public static function logm($message) + { + if (DEBUG_POCHE) { + $t = strval(date('Y/m/d_H:i:s')) . ' - ' . $_SERVER["REMOTE_ADDR"] . ' - ' . strval($message) . "\n"; + file_put_contents('./log.txt', $t, FILE_APPEND); + } + } +} \ No newline at end of file diff --git a/inc/poche/pocheTools.class.php b/inc/poche/pocheTools.class.php index 8907c18e..08c9dc8f 100644 --- a/inc/poche/pocheTools.class.php +++ b/inc/poche/pocheTools.class.php @@ -75,11 +75,11 @@ class pocheTools # prevent loop if (empty($url) || parse_url($url, PHP_URL_QUERY) === $_SERVER['QUERY_STRING']) { - $url = pocheTool::getUrl(); + $url = pocheTools::getUrl(); } if (substr($url, 0, 1) !== '?') { - $ref = pocheTool::getUrl(); + $ref = pocheTools::getUrl(); if (substr($url, 0, strlen($ref)) !== $ref) { $url = $ref; } -- cgit v1.2.3 From afe60d614b5c3c7700db93e51a991b0180887726 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Sat, 3 Aug 2013 08:05:02 +0200 Subject: remove file --- inc/poche/pocheTool.class.php | 126 ------------------------------------------ 1 file changed, 126 deletions(-) delete mode 100644 inc/poche/pocheTool.class.php (limited to 'inc/poche') diff --git a/inc/poche/pocheTool.class.php b/inc/poche/pocheTool.class.php deleted file mode 100644 index 8907c18e..00000000 --- a/inc/poche/pocheTool.class.php +++ /dev/null @@ -1,126 +0,0 @@ - - * @copyright 2013 - * @license http://www.wtfpl.net/ see COPYING file - */ - -class pocheTools -{ - public static function initPhp() - { - define('START_TIME', microtime(true)); - - if (phpversion() < 5) { - die(_('Oops, it seems you don\'t have PHP 5.')); - } - - error_reporting(E_ALL); - - function stripslashesDeep($value) { - return is_array($value) - ? array_map('stripslashesDeep', $value) - : stripslashes($value); - } - - if (get_magic_quotes_gpc()) { - $_POST = array_map('stripslashesDeep', $_POST); - $_GET = array_map('stripslashesDeep', $_GET); - $_COOKIE = array_map('stripslashesDeep', $_COOKIE); - } - - ob_start(); - register_shutdown_function('ob_end_flush'); - } - - public static function isUrl($url) - { - $pattern = '|^http(s)?://[a-z0-9-]+(.[a-z0-9-]+)*(:[0-9]+)?(/.*)?$|i'; - - return preg_match($pattern, $url); - } - - public static function getUrl() - { - $https = (!empty($_SERVER['HTTPS']) - && (strtolower($_SERVER['HTTPS']) == 'on')) - || (isset($_SERVER["SERVER_PORT"]) - && $_SERVER["SERVER_PORT"] == '443'); // HTTPS detection. - $serverport = (!isset($_SERVER["SERVER_PORT"]) - || $_SERVER["SERVER_PORT"] == '80' - || ($https && $_SERVER["SERVER_PORT"] == '443') - ? '' : ':' . $_SERVER["SERVER_PORT"]); - - $scriptname = str_replace('/index.php', '/', $_SERVER["SCRIPT_NAME"]); - - if (!isset($_SERVER["SERVER_NAME"])) { - return $scriptname; - } - - return 'http' . ($https ? 's' : '') . '://' - . $_SERVER["SERVER_NAME"] . $serverport . $scriptname; - } - - public static function redirect($url = '') - { - if ($url === '') { - $url = (empty($_SERVER['HTTP_REFERER'])?'?':$_SERVER['HTTP_REFERER']); - if (isset($_POST['returnurl'])) { - $url = $_POST['returnurl']; - } - } - - # prevent loop - if (empty($url) || parse_url($url, PHP_URL_QUERY) === $_SERVER['QUERY_STRING']) { - $url = pocheTool::getUrl(); - } - - if (substr($url, 0, 1) !== '?') { - $ref = pocheTool::getUrl(); - if (substr($url, 0, strlen($ref)) !== $ref) { - $url = $ref; - } - } - header('Location: '.$url); - exit(); - } - - public static function cleanURL($url) - { - - $url = html_entity_decode(trim($url)); - - $stuff = strpos($url,'&utm_source='); - if ($stuff !== FALSE) - $url = substr($url, 0, $stuff); - $stuff = strpos($url,'?utm_source='); - if ($stuff !== FALSE) - $url = substr($url, 0, $stuff); - $stuff = strpos($url,'#xtor=RSS-'); - if ($stuff !== FALSE) - $url = substr($url, 0, $stuff); - - return $url; - } - - public static function renderJson($data) - { - header('Cache-Control: no-cache, must-revalidate'); - header('Expires: Sat, 26 Jul 1997 05:00:00 GMT'); - header('Content-type: application/json; charset=UTF-8'); - - echo json_encode($data); - exit(); - } - - public static function logm($message) - { - if (DEBUG_POCHE) { - $t = strval(date('Y/m/d_H:i:s')) . ' - ' . $_SERVER["REMOTE_ADDR"] . ' - ' . strval($message) . "\n"; - file_put_contents('./log.txt', $t, FILE_APPEND); - } - } -} \ No newline at end of file -- cgit v1.2.3 From 8cbb2a88024969f7efd90f8053f3b0805fa2f8fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Sat, 3 Aug 2013 08:25:11 +0200 Subject: twig implementation --- inc/poche/pocheCore.php | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) (limited to 'inc/poche') diff --git a/inc/poche/pocheCore.php b/inc/poche/pocheCore.php index e68696af..3e32c4a8 100644 --- a/inc/poche/pocheCore.php +++ b/inc/poche/pocheCore.php @@ -134,10 +134,12 @@ function fetch_url_content($url) return FALSE; } -function display_view($view, $id = 0, $full_head = 'yes') +function display_view($view, $id = 0) { global $tpl, $store; + $tpl_vars = array(); + switch ($view) { case 'install': @@ -186,21 +188,25 @@ function display_view($view, $id = 0, $full_head = 'yes') break; default: # home view $entries = $store->getEntriesByView($view); - $tpl->assign('entries', $entries); + $tpl_vars = array( + 'entries' => $entries, + ); - if ($full_head == 'yes') { - $tpl->assign('load_all_js', 1); - $tpl->draw('head'); - $tpl->draw('home'); - } + // if ($full_head == 'yes') { + // $tpl->assign('load_all_js', 1); + // $tpl->draw('head'); + // $tpl->draw('home'); + // } - $tpl->draw('entries'); - if ($full_head == 'yes') { - $tpl->draw('js'); - $tpl->draw('footer'); - } + // $tpl->draw('entries'); + // if ($full_head == 'yes') { + // $tpl->draw('js'); + // $tpl->draw('footer'); + // } break; } + + return $tpl_vars; } /** -- cgit v1.2.3 From 2b840e0cfb63a453bea67a98541f3df9c273c5f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Sat, 3 Aug 2013 08:57:35 +0200 Subject: twig implementation --- inc/poche/pocheCore.php | 46 +++++++++++++++++++++++++++------------------- 1 file changed, 27 insertions(+), 19 deletions(-) (limited to 'inc/poche') diff --git a/inc/poche/pocheCore.php b/inc/poche/pocheCore.php index 3e32c4a8..9cbcc077 100644 --- a/inc/poche/pocheCore.php +++ b/inc/poche/pocheCore.php @@ -134,9 +134,35 @@ function fetch_url_content($url) return FALSE; } +function get_tpl_file($view) +{ + $tpl_file = 'home.twig'; + switch ($view) + { + case 'install': + $tpl_file = 'install.twig'; + break; + case 'import'; + $tpl_file = 'import.twig'; + break; + case 'export': + $tpl_file = 'export.twig'; + break; + case 'config': + $tpl_file = 'config.twig'; + break; + case 'view': + $tpl_file = 'view.twig'; + break; + default: + break; + } + return $tpl_file; +} + function display_view($view, $id = 0) { - global $tpl, $store; + global $store; $tpl_vars = array(); @@ -155,12 +181,6 @@ function display_view($view, $id = 0) pocheTools::logm('export view'); break; case 'config': - $tpl->assign('load_all_js', 0); - $tpl->draw('head'); - $tpl->draw('home'); - $tpl->draw('config'); - $tpl->draw('js'); - $tpl->draw('footer'); pocheTools::logm('config view'); break; case 'view': @@ -191,18 +211,6 @@ function display_view($view, $id = 0) $tpl_vars = array( 'entries' => $entries, ); - - // if ($full_head == 'yes') { - // $tpl->assign('load_all_js', 1); - // $tpl->draw('head'); - // $tpl->draw('home'); - // } - - // $tpl->draw('entries'); - // if ($full_head == 'yes') { - // $tpl->draw('js'); - // $tpl->draw('footer'); - // } break; } -- cgit v1.2.3 From 3ba5f81b7bc99d7ff954aa5b76aca93c9e157e67 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Sun, 4 Aug 2013 18:07:41 +0200 Subject: twig implementation --- inc/poche/pocheCore.php | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) (limited to 'inc/poche') diff --git a/inc/poche/pocheCore.php b/inc/poche/pocheCore.php index 9cbcc077..74b063e4 100644 --- a/inc/poche/pocheCore.php +++ b/inc/poche/pocheCore.php @@ -187,20 +187,16 @@ function display_view($view, $id = 0) $entry = $store->retrieveOneById($id); if ($entry != NULL) { pocheTools::logm('view link #' . $id); - $tpl->assign('id', $entry['id']); - $tpl->assign('url', $entry['url']); - $tpl->assign('title', $entry['title']); $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); - $tpl->draw('view'); + $tpl_vars = array( + 'entry' => $entry, + 'content' => $content, + ); } else { pocheTools::logm('error in view call : entry is NULL'); -- cgit v1.2.3 From eb1af592194e225bf887e4893e697f0ab8dd9a26 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Sun, 4 Aug 2013 20:58:31 +0200 Subject: refactoring --- inc/poche/Poche.class.php | 176 +++++++++++++++++++++++++++ inc/poche/Tools.class.php | 208 +++++++++++++++++++++++++++++++ inc/poche/Url.class.php | 94 ++++++++++++++ inc/poche/config.inc.php | 40 ++++++ inc/poche/pocheCore.php | 269 ----------------------------------------- inc/poche/pochePictures.php | 2 +- inc/poche/pocheTools.class.php | 126 ------------------- 7 files changed, 519 insertions(+), 396 deletions(-) create mode 100644 inc/poche/Poche.class.php create mode 100644 inc/poche/Tools.class.php create mode 100644 inc/poche/Url.class.php create mode 100644 inc/poche/config.inc.php delete mode 100644 inc/poche/pocheCore.php delete mode 100644 inc/poche/pocheTools.class.php (limited to 'inc/poche') diff --git a/inc/poche/Poche.class.php b/inc/poche/Poche.class.php new file mode 100644 index 00000000..973ae3e2 --- /dev/null +++ b/inc/poche/Poche.class.php @@ -0,0 +1,176 @@ + + * @copyright 2013 + * @license http://www.wtfpl.net/ see COPYING file + */ + +class Poche +{ + public $store; + public $tpl; + + function __construct($storage_type) + { + $this->store = new $storage_type(); + $this->init(); + + # installation + if(!$this->store->isInstalled()) + { + $this->install(); + } + + $this->saveUser(); + } + + private function init() + { + # l10n + putenv('LC_ALL=' . LANG); + setlocale(LC_ALL, LANG); + bindtextdomain(LANG, LOCALE); + textdomain(LANG); + + # template engine + $loader = new Twig_Loader_Filesystem(TPL); + $this->tpl = new Twig_Environment($loader, array( + 'cache' => CACHE, + )); + $this->tpl->addExtension(new Twig_Extensions_Extension_I18n()); + + Tools::initPhp(); + Session::init(); + } + + private function install() + { + Tools::logm('poche still not installed'); + echo $this->tpl->render('install.twig', array( + 'token' => Session::getToken(), + )); + if (isset($_GET['install'])) { + if (($_POST['password'] == $_POST['password_repeat']) + && $_POST['password'] != "" && $_POST['login'] != "") { + # let's rock, install poche baby ! + $this->store->install($_POST['login'], Tools::encodeString($_POST['password'] . $_POST['login'])); + Session::logout(); + Tools::redirect(); + } + } + exit(); + } + + private function saveUser() + { + $_SESSION['login'] = (isset ($_SESSION['login'])) ? $_SESSION['login'] : $this->store->getLogin(); + $_SESSION['pass'] = (isset ($_SESSION['pass'])) ? $_SESSION['pass'] : $this->store->getPassword(); + } + + /** + * Call action (mark as fav, archive, delete, etc.) + */ + public function action($action, Url $url, $id) + { + switch ($action) + { + case 'add': + if($parametres_url = $url->fetchContent()) { + if ($this->store->add($url->getUrl(), $parametres_url['title'], $parametres_url['content'])) { + Tools::logm('add link ' . $url->getUrl()); + $last_id = $this->store->getLastId(); + if (DOWNLOAD_PICTURES) { + $content = filtre_picture($parametres_url['content'], $url->getUrl(), $last_id); + } + #$msg->add('s', _('the link has been added successfully')); + } + else { + #$msg->add('e', _('error during insertion : the link wasn\'t added')); + Tools::logm('error during insertion : the link wasn\'t added'); + } + } + else { + #$msg->add('e', _('error during url preparation : the link wasn\'t added')); + Tools::logm('error during content fetch'); + } + break; + case 'delete': + if ($this->store->deleteById($id)) { + if (DOWNLOAD_PICTURES) { + remove_directory(ABS_PATH . $id); + } + #$msg->add('s', _('the link has been deleted successfully')); + Tools::logm('delete link #' . $id); + } + else { + #$msg->add('e', _('the link wasn\'t deleted')); + Tools::logm('error : can\'t delete link #' . $id); + } + break; + case 'toggle_fav' : + $this->store->favoriteById($id); + Tools::logm('mark as favorite link #' . $id); + break; + case 'toggle_archive' : + $this->store->archiveById($id); + Tools::logm('archive link #' . $id); + break; + default: + break; + } + } + + function displayView($view, $id = 0) + { + $tpl_vars = array(); + + switch ($view) + { + case 'install': + Tools::logm('install mode'); + break; + case 'import'; + Tools::logm('import mode'); + break; + case 'export': + $entries = $this->store->retrieveAll(); + // $tpl->assign('export', Tools::renderJson($entries)); + // $tpl->draw('export'); + Tools::logm('export view'); + break; + case 'config': + Tools::logm('config view'); + break; + case 'view': + $entry = $this->store->retrieveOneById($id); + if ($entry != NULL) { + Tools::logm('view link #' . $id); + $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_vars = array( + 'entry' => $entry, + 'content' => $content, + ); + } + else { + Tools::logm('error in view call : entry is NULL'); + } + break; + default: # home view + $entries = $this->store->getEntriesByView($view); + $tpl_vars = array( + 'entries' => $entries, + ); + break; + } + + return $tpl_vars; + } +} \ No newline at end of file diff --git a/inc/poche/Tools.class.php b/inc/poche/Tools.class.php new file mode 100644 index 00000000..c277035f --- /dev/null +++ b/inc/poche/Tools.class.php @@ -0,0 +1,208 @@ + + * @copyright 2013 + * @license http://www.wtfpl.net/ see COPYING file + */ + +class Tools +{ + public static function initPhp() + { + define('START_TIME', microtime(true)); + + if (phpversion() < 5) { + die(_('Oops, it seems you don\'t have PHP 5.')); + } + + error_reporting(E_ALL); + + function stripslashesDeep($value) { + return is_array($value) + ? array_map('stripslashesDeep', $value) + : stripslashes($value); + } + + if (get_magic_quotes_gpc()) { + $_POST = array_map('stripslashesDeep', $_POST); + $_GET = array_map('stripslashesDeep', $_GET); + $_COOKIE = array_map('stripslashesDeep', $_COOKIE); + } + + ob_start(); + register_shutdown_function('ob_end_flush'); + } + + public static function getPocheUrl() + { + $https = (!empty($_SERVER['HTTPS']) + && (strtolower($_SERVER['HTTPS']) == 'on')) + || (isset($_SERVER["SERVER_PORT"]) + && $_SERVER["SERVER_PORT"] == '443'); // HTTPS detection. + $serverport = (!isset($_SERVER["SERVER_PORT"]) + || $_SERVER["SERVER_PORT"] == '80' + || ($https && $_SERVER["SERVER_PORT"] == '443') + ? '' : ':' . $_SERVER["SERVER_PORT"]); + + $scriptname = str_replace('/index.php', '/', $_SERVER["SCRIPT_NAME"]); + + if (!isset($_SERVER["SERVER_NAME"])) { + return $scriptname; + } + + return 'http' . ($https ? 's' : '') . '://' + . $_SERVER["SERVER_NAME"] . $serverport . $scriptname; + } + + public static function redirect($url = '') + { + if ($url === '') { + $url = (empty($_SERVER['HTTP_REFERER'])?'?':$_SERVER['HTTP_REFERER']); + if (isset($_POST['returnurl'])) { + $url = $_POST['returnurl']; + } + } + + # prevent loop + if (empty($url) || parse_url($url, PHP_URL_QUERY) === $_SERVER['QUERY_STRING']) { + $url = Tools::getPocheUrl(); + } + + if (substr($url, 0, 1) !== '?') { + $ref = Tools::getPocheUrl(); + if (substr($url, 0, strlen($ref)) !== $ref) { + $url = $ref; + } + } + header('Location: '.$url); + exit(); + } + + public static function getTplFile($view) + { + $tpl_file = 'home.twig'; + switch ($view) + { + case 'install': + $tpl_file = 'install.twig'; + break; + case 'import'; + $tpl_file = 'import.twig'; + break; + case 'export': + $tpl_file = 'export.twig'; + break; + case 'config': + $tpl_file = 'config.twig'; + break; + case 'view': + $tpl_file = 'view.twig'; + break; + default: + break; + } + return $tpl_file; + } + + public static function getFile($url) + { + $timeout = 15; + $useragent = "Mozilla/5.0 (Windows NT 5.1; rv:18.0) Gecko/20100101 Firefox/18.0"; + + if (in_array ('curl', get_loaded_extensions())) { + # Fetch feed from URL + $curl = curl_init(); + curl_setopt($curl, CURLOPT_URL, $url); + curl_setopt($curl, CURLOPT_TIMEOUT, $timeout); + curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true); + 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"); + curl_setopt($curl, CURLOPT_USERAGENT, $useragent); + + $data = curl_exec($curl); + $httpcode = curl_getinfo($curl, CURLINFO_HTTP_CODE); + $httpcodeOK = isset($httpcode) and ($httpcode == 200 or $httpcode == 301); + curl_close($curl); + } else { + # create http context and add timeout and user-agent + $context = stream_context_create( + array( + 'http' => array( + 'timeout' => $timeout, + 'header' => "User-Agent: " . $useragent, + 'follow_location' => true + ), + 'ssl' => array( + 'verify_peer' => false, + 'allow_self_signed' => true + ) + ) + ); + + # only download page lesser than 4MB + $data = @file_get_contents($url, false, $context, -1, 4000000); + + if (isset($http_response_header) and isset($http_response_header[0])) { + $httpcodeOK = isset($http_response_header) and isset($http_response_header[0]) and ((strpos($http_response_header[0], '200 OK') !== FALSE) or (strpos($http_response_header[0], '301 Moved Permanently') !== FALSE)); + } + } + + # if response is not empty and response is OK + if (isset($data) and isset($httpcodeOK) and $httpcodeOK) { + + # take charset of page and get it + preg_match('##Usi', $data, $meta); + + # if meta tag is found + if (!empty($meta[0])) { + preg_match('#charset="?(.*)"#si', $meta[0], $encoding); + # if charset is found set it otherwise, set it to utf-8 + $html_charset = (!empty($encoding[1])) ? strtolower($encoding[1]) : 'utf-8'; + } else { + $html_charset = 'utf-8'; + $encoding[1] = ''; + } + + # replace charset of url to charset of page + $data = str_replace('charset=' . $encoding[1], 'charset=' . $html_charset, $data); + + return $data; + } + else { + return FALSE; + } + } + + public static function renderJson($data) + { + header('Cache-Control: no-cache, must-revalidate'); + header('Expires: Sat, 26 Jul 1997 05:00:00 GMT'); + header('Content-type: application/json; charset=UTF-8'); + echo json_encode($data); + exit(); + } + + public static function logm($message) + { + if (DEBUG_POCHE) { + $t = strval(date('Y/m/d_H:i:s')) . ' - ' . $_SERVER["REMOTE_ADDR"] . ' - ' . strval($message) . "\n"; + file_put_contents('./log.txt', $t, FILE_APPEND); + } + } + + public static function encodeString($string) + { + return sha1($string . SALT); + } +} \ No newline at end of file diff --git a/inc/poche/Url.class.php b/inc/poche/Url.class.php new file mode 100644 index 00000000..f4a8f99e --- /dev/null +++ b/inc/poche/Url.class.php @@ -0,0 +1,94 @@ + + * @copyright 2013 + * @license http://www.wtfpl.net/ see COPYING file + */ + +class Url +{ + public $url; + + function __construct($url) + { + $this->url = base64_decode($url); + } + + public function getUrl() { + return $this->url; + } + + public function setUrl($url) { + $this->url = $url; + } + + public function isCorrect() + { + $pattern = '|^http(s)?://[a-z0-9-]+(.[a-z0-9-]+)*(:[0-9]+)?(/.*)?$|i'; + + return preg_match($pattern, $this->url); + } + + public function clean() + { + $url = html_entity_decode(trim($this->url)); + + $stuff = strpos($url,'&utm_source='); + if ($stuff !== FALSE) + $url = substr($url, 0, $stuff); + $stuff = strpos($url,'?utm_source='); + if ($stuff !== FALSE) + $url = substr($url, 0, $stuff); + $stuff = strpos($url,'#xtor=RSS-'); + if ($stuff !== FALSE) + $url = substr($url, 0, $stuff); + + $this->url = $url; + } + + public function fetchContent() + { + if ($this->isCorrect()) { + $this->clean(); + $html = Encoding::toUTF8(Tools::getFile($this->getUrl())); + + # if Tools::getFile() if not able to retrieve HTTPS content, try the same URL with HTTP protocol + if (!preg_match('!^https?://!i', $this->getUrl()) && (!isset($html) || strlen($html) <= 0)) { + $this->setUrl('http://' . $this->getUrl()); + $html = Encoding::toUTF8(Tools::getFile($this->getUrl())); + } + + if (function_exists('tidy_parse_string')) { + $tidy = tidy_parse_string($html, array(), 'UTF8'); + $tidy->cleanRepair(); + $html = $tidy->value; + } + + $parameters = array(); + if (isset($html) and strlen($html) > 0) + { + $readability = new Readability($html, $this->getUrl()); + $readability->convertLinksToFootnotes = CONVERT_LINKS_FOOTNOTES; + $readability->revertForcedParagraphElements = REVERT_FORCED_PARAGRAPH_ELEMENTS; + + if($readability->init()) + { + $content = $readability->articleContent->innerHTML; + $parameters['title'] = $readability->articleTitle->innerHTML; + $parameters['content'] = $content; + + return $parameters; + } + } + } + else { + #$msg->add('e', _('error during url preparation : the link is not valid')); + Tools::logm($this->getUrl() . ' is not a valid url'); + } + + return FALSE; + } +} \ No newline at end of file diff --git a/inc/poche/config.inc.php b/inc/poche/config.inc.php new file mode 100644 index 00000000..81297e0c --- /dev/null +++ b/inc/poche/config.inc.php @@ -0,0 +1,40 @@ + + * @copyright 2013 + * @license http://www.wtfpl.net/ see COPYING file + */ + +define ('POCHE_VERSION', '0.4'); +define ('MODE_DEMO', FALSE); +define ('DEBUG_POCHE', FALSE); +define ('CONVERT_LINKS_FOOTNOTES', FALSE); +define ('REVERT_FORCED_PARAGRAPH_ELEMENTS', FALSE); +define ('DOWNLOAD_PICTURES', FALSE); +define ('SALT', '464v54gLLw928uz4zUBqkRJeiPY68zCX'); +define ('ABS_PATH', 'assets/'); +define ('TPL', './tpl'); +define ('LOCALE', './locale'); +define ('CACHE', './cache'); +define ('LANG', 'fr_FR.UTF8'); +$storage_type = 'sqlite'; # sqlite, file + +# /!\ Be careful if you change the lines below /!\ +require_once './inc/poche/Tools.class.php'; +require_once './inc/poche/Url.class.php'; +require_once './inc/poche/Poche.class.php'; +require_once './inc/3rdparty/Readability.php'; +require_once './inc/3rdparty/Encoding.php'; +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'; + +if (DOWNLOAD_PICTURES) { + require_once './inc/poche/pochePicture.php'; +} + +$poche = new Poche($storage_type); \ No newline at end of file diff --git a/inc/poche/pocheCore.php b/inc/poche/pocheCore.php deleted file mode 100644 index 74b063e4..00000000 --- a/inc/poche/pocheCore.php +++ /dev/null @@ -1,269 +0,0 @@ - - * @copyright 2013 - * @license http://www.wtfpl.net/ see COPYING file - */ - -function encode_string($string) -{ - return sha1($string . SALT); -} - -function get_external_file($url) -{ - $timeout = 15; - $useragent = "Mozilla/5.0 (Windows NT 5.1; rv:18.0) Gecko/20100101 Firefox/18.0"; - - if (in_array ('curl', get_loaded_extensions())) { - # Fetch feed from URL - $curl = curl_init(); - curl_setopt($curl, CURLOPT_URL, $url); - curl_setopt($curl, CURLOPT_TIMEOUT, $timeout); - curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true); - 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"); - curl_setopt($curl, CURLOPT_USERAGENT, $useragent); - - $data = curl_exec($curl); - $httpcode = curl_getinfo($curl, CURLINFO_HTTP_CODE); - $httpcodeOK = isset($httpcode) and ($httpcode == 200 or $httpcode == 301); - curl_close($curl); - } else { - # create http context and add timeout and user-agent - $context = stream_context_create( - array( - 'http' => array( - 'timeout' => $timeout, - 'header' => "User-Agent: " . $useragent, - 'follow_location' => true - ), - 'ssl' => array( - 'verify_peer' => false, - 'allow_self_signed' => true - ) - ) - ); - - # only download page lesser than 4MB - $data = @file_get_contents($url, false, $context, -1, 4000000); - - if (isset($http_response_header) and isset($http_response_header[0])) { - $httpcodeOK = isset($http_response_header) and isset($http_response_header[0]) and ((strpos($http_response_header[0], '200 OK') !== FALSE) or (strpos($http_response_header[0], '301 Moved Permanently') !== FALSE)); - } - } - - # if response is not empty and response is OK - if (isset($data) and isset($httpcodeOK) and $httpcodeOK) { - - # take charset of page and get it - preg_match('##Usi', $data, $meta); - - # if meta tag is found - if (!empty($meta[0])) { - preg_match('#charset="?(.*)"#si', $meta[0], $encoding); - # if charset is found set it otherwise, set it to utf-8 - $html_charset = (!empty($encoding[1])) ? strtolower($encoding[1]) : 'utf-8'; - } else { - $html_charset = 'utf-8'; - $encoding[1] = ''; - } - - # replace charset of url to charset of page - $data = str_replace('charset=' . $encoding[1], 'charset=' . $html_charset, $data); - - return $data; - } - else { - return FALSE; - } -} - -function fetch_url_content($url) -{ - $url = base64_decode($url); - if (pocheTools::isUrl($url)) { - $url = pocheTools::cleanURL($url); - $html = Encoding::toUTF8(get_external_file($url)); - - # 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)); - } - - if (function_exists('tidy_parse_string')) { - $tidy = tidy_parse_string($html, array(), 'UTF8'); - $tidy->cleanRepair(); - $html = $tidy->value; - } - - $parameters = array(); - if (isset($html) and strlen($html) > 0) - { - $readability = new Readability($html, $url); - $readability->convertLinksToFootnotes = CONVERT_LINKS_FOOTNOTES; - $readability->revertForcedParagraphElements = REVERT_FORCED_PARAGRAPH_ELEMENTS; - - if($readability->init()) - { - $content = $readability->articleContent->innerHTML; - $parameters['title'] = $readability->articleTitle->innerHTML; - $parameters['content'] = $content; - - return $parameters; - } - } - } - else { - #$msg->add('e', _('error during url preparation : the link is not valid')); - pocheTools::logm($url . ' is not a valid url'); - } - - return FALSE; -} - -function get_tpl_file($view) -{ - $tpl_file = 'home.twig'; - switch ($view) - { - case 'install': - $tpl_file = 'install.twig'; - break; - case 'import'; - $tpl_file = 'import.twig'; - break; - case 'export': - $tpl_file = 'export.twig'; - break; - case 'config': - $tpl_file = 'config.twig'; - break; - case 'view': - $tpl_file = 'view.twig'; - break; - default: - break; - } - return $tpl_file; -} - -function display_view($view, $id = 0) -{ - global $store; - - $tpl_vars = array(); - - switch ($view) - { - case 'install': - pocheTools::logm('install mode'); - break; - case 'import'; - pocheTools::logm('import mode'); - break; - case 'export': - $entries = $store->retrieveAll(); - $tpl->assign('export', pocheTools::renderJson($entries)); - $tpl->draw('export'); - pocheTools::logm('export view'); - break; - case 'config': - pocheTools::logm('config view'); - break; - case 'view': - $entry = $store->retrieveOneById($id); - if ($entry != NULL) { - pocheTools::logm('view link #' . $id); - $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_vars = array( - 'entry' => $entry, - 'content' => $content, - ); - } - else { - pocheTools::logm('error in view call : entry is NULL'); - } - break; - default: # home view - $entries = $store->getEntriesByView($view); - $tpl_vars = array( - 'entries' => $entries, - ); - break; - } - - return $tpl_vars; -} - -/** - * Call action (mark as fav, archive, delete, etc.) - */ -function action_to_do($action, $url, $id = 0) -{ - global $store; - - switch ($action) - { - case 'add': - if($parametres_url = fetch_url_content($url)) { - if ($store->add($url, $parametres_url['title'], $parametres_url['content'])) { - pocheTools::logm('add link ' . $url); - $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')); - pocheTools::logm('error during insertion : the link wasn\'t added'); - } - } - else { - #$msg->add('e', _('error during url preparation : the link wasn\'t added')); - pocheTools::logm('error during content fetch'); - } - break; - case 'delete': - if ($store->deleteById($id)) { - if (DOWNLOAD_PICTURES) { - remove_directory(ABS_PATH . $id); - } - #$msg->add('s', _('the link has been deleted successfully')); - pocheTools::logm('delete link #' . $id); - } - else { - #$msg->add('e', _('the link wasn\'t deleted')); - pocheTools::logm('error : can\'t delete link #' . $id); - } - break; - case 'toggle_fav' : - $store->favoriteById($id); - pocheTools::logm('mark as favorite link #' . $id); - break; - case 'toggle_archive' : - $store->archiveById($id); - pocheTools::logm('archive link #' . $id); - break; - default: - break; - } -} diff --git a/inc/poche/pochePictures.php b/inc/poche/pochePictures.php index 0d73a149..4e4a0b08 100644 --- a/inc/poche/pochePictures.php +++ b/inc/poche/pochePictures.php @@ -67,7 +67,7 @@ function get_absolute_link($relative_link, $url) { */ function download_pictures($absolute_path, $fullpath) { - $rawdata = get_external_file($absolute_path); + $rawdata = Tools::getFile($absolute_path); if(file_exists($fullpath)) { unlink($fullpath); diff --git a/inc/poche/pocheTools.class.php b/inc/poche/pocheTools.class.php deleted file mode 100644 index 08c9dc8f..00000000 --- a/inc/poche/pocheTools.class.php +++ /dev/null @@ -1,126 +0,0 @@ - - * @copyright 2013 - * @license http://www.wtfpl.net/ see COPYING file - */ - -class pocheTools -{ - public static function initPhp() - { - define('START_TIME', microtime(true)); - - if (phpversion() < 5) { - die(_('Oops, it seems you don\'t have PHP 5.')); - } - - error_reporting(E_ALL); - - function stripslashesDeep($value) { - return is_array($value) - ? array_map('stripslashesDeep', $value) - : stripslashes($value); - } - - if (get_magic_quotes_gpc()) { - $_POST = array_map('stripslashesDeep', $_POST); - $_GET = array_map('stripslashesDeep', $_GET); - $_COOKIE = array_map('stripslashesDeep', $_COOKIE); - } - - ob_start(); - register_shutdown_function('ob_end_flush'); - } - - public static function isUrl($url) - { - $pattern = '|^http(s)?://[a-z0-9-]+(.[a-z0-9-]+)*(:[0-9]+)?(/.*)?$|i'; - - return preg_match($pattern, $url); - } - - public static function getUrl() - { - $https = (!empty($_SERVER['HTTPS']) - && (strtolower($_SERVER['HTTPS']) == 'on')) - || (isset($_SERVER["SERVER_PORT"]) - && $_SERVER["SERVER_PORT"] == '443'); // HTTPS detection. - $serverport = (!isset($_SERVER["SERVER_PORT"]) - || $_SERVER["SERVER_PORT"] == '80' - || ($https && $_SERVER["SERVER_PORT"] == '443') - ? '' : ':' . $_SERVER["SERVER_PORT"]); - - $scriptname = str_replace('/index.php', '/', $_SERVER["SCRIPT_NAME"]); - - if (!isset($_SERVER["SERVER_NAME"])) { - return $scriptname; - } - - return 'http' . ($https ? 's' : '') . '://' - . $_SERVER["SERVER_NAME"] . $serverport . $scriptname; - } - - public static function redirect($url = '') - { - if ($url === '') { - $url = (empty($_SERVER['HTTP_REFERER'])?'?':$_SERVER['HTTP_REFERER']); - if (isset($_POST['returnurl'])) { - $url = $_POST['returnurl']; - } - } - - # prevent loop - if (empty($url) || parse_url($url, PHP_URL_QUERY) === $_SERVER['QUERY_STRING']) { - $url = pocheTools::getUrl(); - } - - if (substr($url, 0, 1) !== '?') { - $ref = pocheTools::getUrl(); - if (substr($url, 0, strlen($ref)) !== $ref) { - $url = $ref; - } - } - header('Location: '.$url); - exit(); - } - - public static function cleanURL($url) - { - - $url = html_entity_decode(trim($url)); - - $stuff = strpos($url,'&utm_source='); - if ($stuff !== FALSE) - $url = substr($url, 0, $stuff); - $stuff = strpos($url,'?utm_source='); - if ($stuff !== FALSE) - $url = substr($url, 0, $stuff); - $stuff = strpos($url,'#xtor=RSS-'); - if ($stuff !== FALSE) - $url = substr($url, 0, $stuff); - - return $url; - } - - public static function renderJson($data) - { - header('Cache-Control: no-cache, must-revalidate'); - header('Expires: Sat, 26 Jul 1997 05:00:00 GMT'); - header('Content-type: application/json; charset=UTF-8'); - - echo json_encode($data); - exit(); - } - - public static function logm($message) - { - if (DEBUG_POCHE) { - $t = strval(date('Y/m/d_H:i:s')) . ' - ' . $_SERVER["REMOTE_ADDR"] . ' - ' . strval($message) . "\n"; - file_put_contents('./log.txt', $t, FILE_APPEND); - } - } -} \ No newline at end of file -- cgit v1.2.3 From c765c3679fee3ed9e4bad9954a808116187a7e83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Sun, 4 Aug 2013 21:42:46 +0200 Subject: import in poche and not in an external file --- inc/poche/Poche.class.php | 108 +++++++++++++++++++++++++++++++++++++++++++++- inc/poche/config.inc.php | 1 + 2 files changed, 108 insertions(+), 1 deletion(-) (limited to 'inc/poche') diff --git a/inc/poche/Poche.class.php b/inc/poche/Poche.class.php index 973ae3e2..9e407d41 100644 --- a/inc/poche/Poche.class.php +++ b/inc/poche/Poche.class.php @@ -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
    + # 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() + { + + } } \ No newline at end of file diff --git a/inc/poche/config.inc.php b/inc/poche/config.inc.php index 81297e0c..98a9ee6b 100644 --- a/inc/poche/config.inc.php +++ b/inc/poche/config.inc.php @@ -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'; -- cgit v1.2.3 From 63c35580c7d60e2278ee6fe9ba2d4440ff0308d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Sun, 4 Aug 2013 22:35:08 +0200 Subject: twig implementation --- inc/poche/Poche.class.php | 115 ++++++++++++++++++++++++---------------------- inc/poche/Tools.class.php | 5 ++ 2 files changed, 66 insertions(+), 54 deletions(-) (limited to 'inc/poche') diff --git a/inc/poche/Poche.class.php b/inc/poche/Poche.class.php index 9e407d41..5c3eda80 100644 --- a/inc/poche/Poche.class.php +++ b/inc/poche/Poche.class.php @@ -118,8 +118,6 @@ class Poche $this->store->archiveById($id); Tools::logm('archive link #' . $id); break; - case 'import': - break; default: break; } @@ -131,18 +129,6 @@ class Poche switch ($view) { - case 'install': - Tools::logm('install mode'); - break; - case 'import'; - Tools::logm('import mode'); - break; - case 'export': - $entries = $this->store->retrieveAll(); - // $tpl->assign('export', Tools::renderJson($entries)); - // $tpl->draw('export'); - Tools::logm('export view'); - break; case 'config': Tools::logm('config view'); break; @@ -224,59 +210,80 @@ class Poche Tools::redirect(); } - public function import($from) + private function importFromInstapaper() { - if ($from == 'pocket') { - $html = new simple_html_dom(); - $html->load_file('./ril_export.html'); + Tools::logm('import from instapaper completed'); + Tools::redirect(); + } - $read = 0; - $errors = array(); - foreach($html->find('ul') as $ul) + private function importFromPocket() + { + $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) { - 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); - } + $a = $li->find('a'); + $url = new Url(base64_encode($a[0]->href)); + $this->action('add', $url); + if ($read == '1') { + $last_id = $this->store->getLastId(); + $this->store->archiveById($last_id); } - # Pocket génère un fichier HTML avec deux
      - # 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(); + # Pocket génère un fichier HTML avec deux
        + # Le premier concerne les éléments non lus + # Le second concerne les éléments archivés + $read = 1; } - else if ($from == 'readability') { - # TODO finaliser tout ça ici - $str_data = file_get_contents("readability"); - $data = json_decode($str_data,true); + Tools::logm('import from pocket completed'); + Tools::redirect(); + } - foreach ($data as $key => $value) { - $url = ''; - foreach ($value as $key2 => $value2) { - if ($key2 == 'article__url') { - $url = new Url($value2); - } + private function importFromReadability() + { + # TODO finaliser tout ça ici + # noms des variables + gestion des articles lus + $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(base64_encode($value2)); } - if ($url != '') - action_to_do('add', $url); } - logm('import from Readability completed'); - Tools::redirect(); + if ($url->isCorrect()) + $this->action('add', $url); } + Tools::logm('import from Readability completed'); + Tools::redirect(); } - public function export() + public function import($from) { + if ($from == 'pocket') { + $this->importFromPocket(); + } + else if ($from == 'readability') { + $this->importFromReadability(); + } + else if ($from == 'instapaper') { + $this->importFromInstapaper(); + } + } + public function export() + { + $entries = $this->store->retrieveAll(); + echo $this->tpl->render('export.twig', array( + 'export' => Tools::renderJson($entries), + )); + Tools::logm('export view'); } } \ No newline at end of file diff --git a/inc/poche/Tools.class.php b/inc/poche/Tools.class.php index c277035f..1ff4ba55 100644 --- a/inc/poche/Tools.class.php +++ b/inc/poche/Tools.class.php @@ -205,4 +205,9 @@ class Tools { return sha1($string . SALT); } + + public static function checkVar($var) + { + return ((isset ($_REQUEST["$var"])) ? htmlentities($_REQUEST["$var"]) : ''); + } } \ No newline at end of file -- cgit v1.2.3 From 3208d538a750866221fa231d4230082eef90ca69 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Mon, 5 Aug 2013 08:54:42 +0200 Subject: mysql support --- inc/poche/config.inc.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'inc/poche') diff --git a/inc/poche/config.inc.php b/inc/poche/config.inc.php index 98a9ee6b..67d0c887 100644 --- a/inc/poche/config.inc.php +++ b/inc/poche/config.inc.php @@ -20,7 +20,7 @@ define ('TPL', './tpl'); define ('LOCALE', './locale'); define ('CACHE', './cache'); define ('LANG', 'fr_FR.UTF8'); -$storage_type = 'sqlite'; # sqlite, file +$storage_type = 'sqlite'; # sqlite, mysql, (file, not yet) # /!\ Be careful if you change the lines below /!\ require_once './inc/poche/Tools.class.php'; -- cgit v1.2.3 From a62788c61ef80e6b0f1cf0b6304b2dfd2223aa38 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Mon, 5 Aug 2013 09:43:33 +0200 Subject: #100: welcome to you, instapaper users --- inc/poche/Poche.class.php | 22 ++++++++++++++++++++++ inc/poche/config.inc.php | 5 +++-- 2 files changed, 25 insertions(+), 2 deletions(-) (limited to 'inc/poche') diff --git a/inc/poche/Poche.class.php b/inc/poche/Poche.class.php index 5c3eda80..0d37e3c2 100644 --- a/inc/poche/Poche.class.php +++ b/inc/poche/Poche.class.php @@ -212,6 +212,28 @@ class Poche private function importFromInstapaper() { + $html = new simple_html_dom(); + $html->load_file('./instapaper-export.html'); + + $read = 0; + $errors = array(); + foreach($html->find('ol') as $ul) + { + foreach($ul->find('li') as $li) + { + $a = $li->find('a'); + $url = new Url(base64_encode($a[0]->href)); + $this->action('add', $url); + if ($read == '1') { + $last_id = $this->store->getLastId(); + $this->store->archiveById($last_id); + } + } + # Instapaper génère un fichier HTML avec deux
          + # Le premier concerne les éléments non lus + # Le second concerne les éléments archivés + $read = 1; + } Tools::logm('import from instapaper completed'); Tools::redirect(); } diff --git a/inc/poche/config.inc.php b/inc/poche/config.inc.php index 67d0c887..a16098d1 100644 --- a/inc/poche/config.inc.php +++ b/inc/poche/config.inc.php @@ -8,12 +8,13 @@ * @license http://www.wtfpl.net/ see COPYING file */ -define ('POCHE_VERSION', '0.4'); -define ('MODE_DEMO', FALSE); +define ('POCHE_VERSION', '1.0-alpha'); +define ('MODE_DEMO', TRUE); define ('DEBUG_POCHE', FALSE); define ('CONVERT_LINKS_FOOTNOTES', FALSE); define ('REVERT_FORCED_PARAGRAPH_ELEMENTS', FALSE); define ('DOWNLOAD_PICTURES', FALSE); +define ('SHARE_TWITTER', TRUE); define ('SALT', '464v54gLLw928uz4zUBqkRJeiPY68zCX'); define ('ABS_PATH', 'assets/'); define ('TPL', './tpl'); -- cgit v1.2.3 From a12832488d7da2fc7caffae3b5a6b06a02912c67 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Mon, 5 Aug 2013 10:03:59 +0200 Subject: update poche.sqlite --- inc/poche/config.inc.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'inc/poche') diff --git a/inc/poche/config.inc.php b/inc/poche/config.inc.php index a16098d1..eb0c1bb5 100644 --- a/inc/poche/config.inc.php +++ b/inc/poche/config.inc.php @@ -9,7 +9,7 @@ */ define ('POCHE_VERSION', '1.0-alpha'); -define ('MODE_DEMO', TRUE); +define ('MODE_DEMO', FALSE); define ('DEBUG_POCHE', FALSE); define ('CONVERT_LINKS_FOOTNOTES', FALSE); define ('REVERT_FORCED_PARAGRAPH_ELEMENTS', FALSE); -- cgit v1.2.3 From 7f959169b7220b4ed3e083cb2a545fe2c5400f9c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Mon, 5 Aug 2013 10:32:15 +0200 Subject: copy of poche.sqlite --- inc/poche/Poche.class.php | 29 ++++++++++++++++++----------- inc/poche/Tools.class.php | 4 ++-- 2 files changed, 20 insertions(+), 13 deletions(-) (limited to 'inc/poche') diff --git a/inc/poche/Poche.class.php b/inc/poche/Poche.class.php index 0d37e3c2..12cb1b42 100644 --- a/inc/poche/Poche.class.php +++ b/inc/poche/Poche.class.php @@ -212,6 +212,7 @@ class Poche private function importFromInstapaper() { + # TODO gestion des articles favs $html = new simple_html_dom(); $html->load_file('./instapaper-export.html'); @@ -229,9 +230,8 @@ class Poche $this->store->archiveById($last_id); } } - # Instapaper génère un fichier HTML avec deux
            - # Le premier concerne les éléments non lus - # Le second concerne les éléments archivés + + # the second
              is for read links $read = 1; } Tools::logm('import from instapaper completed'); @@ -240,6 +240,7 @@ class Poche private function importFromPocket() { + # TODO gestion des articles favs $html = new simple_html_dom(); $html->load_file('./ril_export.html'); @@ -257,9 +258,8 @@ class Poche $this->store->archiveById($last_id); } } - # Pocket génère un fichier HTML avec deux
                - # Le premier concerne les éléments non lus - # Le second concerne les éléments archivés + + # the second
                  is for read links $read = 1; } Tools::logm('import from pocket completed'); @@ -268,17 +268,24 @@ class Poche private function importFromReadability() { - # TODO finaliser tout ça ici - # noms des variables + gestion des articles lus + # TODO gestion des articles lus / favs $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(base64_encode($value2)); + foreach ($value as $attr => $attr_value) { + if ($attr == 'article__url') { + $url = new Url(base64_encode($attr_value)); } + // if ($attr_value == 'favorite' && $attr_value == 'true') { + // $last_id = $this->store->getLastId(); + // $this->store->favoriteById($last_id); + // } + // if ($attr_value == 'archive' && $attr_value == 'true') { + // $last_id = $this->store->getLastId(); + // $this->store->archiveById($last_id); + // } } if ($url->isCorrect()) $this->action('add', $url); diff --git a/inc/poche/Tools.class.php b/inc/poche/Tools.class.php index 1ff4ba55..834940ff 100644 --- a/inc/poche/Tools.class.php +++ b/inc/poche/Tools.class.php @@ -206,8 +206,8 @@ class Tools return sha1($string . SALT); } - public static function checkVar($var) + public static function checkVar($var, $default = '') { - return ((isset ($_REQUEST["$var"])) ? htmlentities($_REQUEST["$var"]) : ''); + return ((isset ($_REQUEST["$var"])) ? htmlentities($_REQUEST["$var"]) : $default); } } \ No newline at end of file -- cgit v1.2.3 From 32520785018e3ec3a2ce200689e863099e9646f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Mon, 5 Aug 2013 12:34:16 +0200 Subject: close #69: in the config page, you are notified of the release of a new version --- inc/poche/Poche.class.php | 22 ++++++++++++++++++++++ inc/poche/config.inc.php | 2 +- 2 files changed, 23 insertions(+), 1 deletion(-) (limited to 'inc/poche') diff --git a/inc/poche/Poche.class.php b/inc/poche/Poche.class.php index 12cb1b42..f9bcf85b 100644 --- a/inc/poche/Poche.class.php +++ b/inc/poche/Poche.class.php @@ -130,6 +130,16 @@ class Poche switch ($view) { case 'config': + $dev = $this->getPocheVersion('dev'); + $prod = $this->getPocheVersion('prod'); + $compare_dev = version_compare(POCHE_VERSION, $dev); + $compare_prod = version_compare(POCHE_VERSION, $prod); + $tpl_vars = array( + 'dev' => $dev, + 'prod' => $prod, + 'compare_dev' => $compare_dev, + 'compare_prod' => $compare_prod, + ); Tools::logm('config view'); break; case 'view': @@ -315,4 +325,16 @@ class Poche )); Tools::logm('export view'); } + + private function getPocheVersion($which = 'prod') + { + $cache_file = CACHE . '/' . $which; + if (file_exists($cache_file) && (filemtime($cache_file) > (time() - 86400 ))) { + $version = file_get_contents($cache_file); + } else { + $version = file_get_contents('http://www.inthepoche.com/' . $which); + file_put_contents($cache_file, $version, LOCK_EX); + } + return $version; + } } \ No newline at end of file diff --git a/inc/poche/config.inc.php b/inc/poche/config.inc.php index eb0c1bb5..27be1857 100644 --- a/inc/poche/config.inc.php +++ b/inc/poche/config.inc.php @@ -36,7 +36,7 @@ require_once './vendor/autoload.php'; require_once './inc/3rdparty/simple_html_dom.php'; if (DOWNLOAD_PICTURES) { - require_once './inc/poche/pochePicture.php'; + require_once './inc/poche/pochePictures.php'; } $poche = new Poche($storage_type); \ No newline at end of file -- cgit v1.2.3 From 55821e04c188997d258645975220828e195d0df4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Mon, 5 Aug 2013 15:54:37 +0200 Subject: share email +twitter / class messages --- inc/poche/Poche.class.php | 27 ++++++++++++++++++++++----- inc/poche/Tools.class.php | 11 +++++++++++ inc/poche/config.inc.php | 5 ++++- 3 files changed, 37 insertions(+), 6 deletions(-) (limited to 'inc/poche') diff --git a/inc/poche/Poche.class.php b/inc/poche/Poche.class.php index f9bcf85b..80bf6919 100644 --- a/inc/poche/Poche.class.php +++ b/inc/poche/Poche.class.php @@ -12,6 +12,7 @@ class Poche { public $store; public $tpl; + public $messages; function __construct($storage_type) { @@ -41,6 +42,9 @@ class Poche 'cache' => CACHE, )); $this->tpl->addExtension(new Twig_Extensions_Extension_I18n()); + # filter to display domain name of an url + $filter = new Twig_SimpleFilter('getDomain', 'Tools::getDomain'); + $this->tpl->addFilter($filter); Tools::initPhp(); Session::init(); @@ -113,10 +117,12 @@ class Poche case 'toggle_fav' : $this->store->favoriteById($id); Tools::logm('mark as favorite link #' . $id); + Tools::redirect(); break; case 'toggle_archive' : $this->store->archiveById($id); Tools::logm('archive link #' . $id); + Tools::redirect(); break; default: break; @@ -174,16 +180,21 @@ class Poche public function updatePassword() { - if (isset($_POST['password']) && isset($_POST['password_repeat'])) { - if ($_POST['password'] == $_POST['password_repeat'] && $_POST['password'] != "") { - if (!MODE_DEMO) { + if (MODE_DEMO) { + $this->messages->add('i', 'in demo mode, you can\'t update your password'); + Tools::logm('in demo mode, you can\'t do this'); + } + else { + if (isset($_POST['password']) && isset($_POST['password_repeat'])) { + if ($_POST['password'] == $_POST['password_repeat'] && $_POST['password'] != "") { Tools::logm('password updated'); + $this->messages->add('s', 'your password has been 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'); + $this->messages->add('e', 'the two fields have to be filled & the password must be the same in the two fields'); } } } @@ -194,7 +205,7 @@ class Poche 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'); - + $this->messages->add('s', 'login successful, welcome to your poche'); if (!empty($_POST['longlastingsession'])) { $_SESSION['longlastingsession'] = 31536000; $_SESSION['expires_on'] = time() + $_SESSION['longlastingsession']; @@ -205,9 +216,11 @@ class Poche session_regenerate_id(true); Tools::redirect($referer); } + $this->messages->add('e', 'login failed, bad login or password'); Tools::logm('login failed'); Tools::redirect(); } else { + $this->messages->add('e', 'login failed, you have to fill all fields'); Tools::logm('login failed'); Tools::redirect(); } @@ -215,6 +228,7 @@ class Poche public function logout() { + $this->messages->add('s', 'logout successful, see you soon!'); Tools::logm('logout'); Session::logout(); Tools::redirect(); @@ -244,6 +258,7 @@ class Poche # the second
                    is for read links $read = 1; } + $this->messages->add('s', 'import from instapaper completed'); Tools::logm('import from instapaper completed'); Tools::redirect(); } @@ -272,6 +287,7 @@ class Poche # the second
                      is for read links $read = 1; } + $this->messages->add('s', 'import from pocket completed'); Tools::logm('import from pocket completed'); Tools::redirect(); } @@ -300,6 +316,7 @@ class Poche if ($url->isCorrect()) $this->action('add', $url); } + $this->messages->add('s', 'import from Readability completed'); Tools::logm('import from Readability completed'); Tools::redirect(); } diff --git a/inc/poche/Tools.class.php b/inc/poche/Tools.class.php index 834940ff..7bc8830a 100644 --- a/inc/poche/Tools.class.php +++ b/inc/poche/Tools.class.php @@ -210,4 +210,15 @@ class Tools { return ((isset ($_REQUEST["$var"])) ? htmlentities($_REQUEST["$var"]) : $default); } + + public static function getDomain($url) + { + $pieces = parse_url($url); + $domain = isset($pieces['host']) ? $pieces['host'] : ''; + if (preg_match('/(?P[a-z0-9][a-z0-9\-]{1,63}\.[a-z\.]{2,6})$/i', $domain, $regs)) { + return $regs['domain']; + } + + return FALSE; + } } \ No newline at end of file diff --git a/inc/poche/config.inc.php b/inc/poche/config.inc.php index 27be1857..d49df190 100644 --- a/inc/poche/config.inc.php +++ b/inc/poche/config.inc.php @@ -15,6 +15,7 @@ define ('CONVERT_LINKS_FOOTNOTES', FALSE); define ('REVERT_FORCED_PARAGRAPH_ELEMENTS', FALSE); define ('DOWNLOAD_PICTURES', FALSE); define ('SHARE_TWITTER', TRUE); +define ('SHARE_MAIL', TRUE); define ('SALT', '464v54gLLw928uz4zUBqkRJeiPY68zCX'); define ('ABS_PATH', 'assets/'); define ('TPL', './tpl'); @@ -34,9 +35,11 @@ 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'; +require_once './inc/3rdparty/class.messages.php'; if (DOWNLOAD_PICTURES) { require_once './inc/poche/pochePictures.php'; } -$poche = new Poche($storage_type); \ No newline at end of file +$poche = new Poche($storage_type); +$poche->messages = new Messages(); \ No newline at end of file -- cgit v1.2.3 From 6a361945eaf86a978b82bd6fb3442fe64428d9df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Mon, 5 Aug 2013 21:56:32 +0200 Subject: new design, pagination & more --- inc/poche/Poche.class.php | 40 +++++++++++++++++++++++++++++----------- inc/poche/Tools.class.php | 2 +- inc/poche/config.inc.php | 12 +++++++----- 3 files changed, 37 insertions(+), 17 deletions(-) (limited to 'inc/poche') diff --git a/inc/poche/Poche.class.php b/inc/poche/Poche.class.php index 80bf6919..789d6647 100644 --- a/inc/poche/Poche.class.php +++ b/inc/poche/Poche.class.php @@ -13,11 +13,13 @@ class Poche public $store; public $tpl; public $messages; + public $pagination; function __construct($storage_type) { $this->store = new $storage_type(); $this->init(); + $this->messages = new Messages(); # installation if(!$this->store->isInstalled()) @@ -46,6 +48,8 @@ class Poche $filter = new Twig_SimpleFilter('getDomain', 'Tools::getDomain'); $this->tpl->addFilter($filter); + $this->pagination = new Paginator(PAGINATION, 'p'); + Tools::initPhp(); Session::init(); } @@ -54,7 +58,7 @@ class Poche { Tools::logm('poche still not installed'); echo $this->tpl->render('install.twig', array( - 'token' => Session::getToken(), + 'token' => Session::getToken() )); if (isset($_GET['install'])) { if (($_POST['password'] == $_POST['password_repeat']) @@ -62,6 +66,11 @@ class Poche # let's rock, install poche baby ! $this->store->install($_POST['login'], Tools::encodeString($_POST['password'] . $_POST['login'])); Session::logout(); + Tools::logm('poche is now installed'); + Tools::redirect(); + } + else { + Tools::logm('error during installation'); Tools::redirect(); } } @@ -89,30 +98,32 @@ class Poche if (DOWNLOAD_PICTURES) { $content = filtre_picture($parametres_url['content'], $url->getUrl(), $last_id); } - #$msg->add('s', _('the link has been added successfully')); + $this->messages->add('s', _('the link has been added successfully')); } else { - #$msg->add('e', _('error during insertion : the link wasn\'t added')); + $this->messages->add('e', _('error during insertion : the link wasn\'t added')); Tools::logm('error during insertion : the link wasn\'t added'); } } else { - #$msg->add('e', _('error during url preparation : the link wasn\'t added')); + $this->messages->add('e', _('error during fetching content : the link wasn\'t added')); Tools::logm('error during content fetch'); } + Tools::redirect(); break; case 'delete': if ($this->store->deleteById($id)) { if (DOWNLOAD_PICTURES) { remove_directory(ABS_PATH . $id); } - #$msg->add('s', _('the link has been deleted successfully')); + $this->messages->add('s', _('the link has been deleted successfully')); Tools::logm('delete link #' . $id); } else { - #$msg->add('e', _('the link wasn\'t deleted')); + $this->messages->add('e', _('the link wasn\'t deleted')); Tools::logm('error : can\'t delete link #' . $id); } + Tools::redirect(); break; case 'toggle_fav' : $this->store->favoriteById($id); @@ -169,9 +180,14 @@ class Poche break; default: # home view $entries = $this->store->getEntriesByView($view); + $this->pagination->set_total(count($entries)); + $page_links = $this->pagination->page_links('?view=' . $view . '&sort=' . $_SESSION['sort'] . '&'); + $datas = $this->store->getEntriesByView($view, $this->pagination->get_limit()); $tpl_vars = array( - 'entries' => $entries, + 'entries' => $datas, + 'page_links' => $page_links, ); + Tools::logm('display ' . $view . ' view'); break; } @@ -183,6 +199,7 @@ class Poche if (MODE_DEMO) { $this->messages->add('i', 'in demo mode, you can\'t update your password'); Tools::logm('in demo mode, you can\'t do this'); + Tools::redirect('?view=config'); } else { if (isset($_POST['password']) && isset($_POST['password_repeat'])) { @@ -195,6 +212,7 @@ class Poche } else { $this->messages->add('e', 'the two fields have to be filled & the password must be the same in the two fields'); + Tools::redirect('?view=config'); } } } @@ -205,7 +223,7 @@ class Poche 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'); - $this->messages->add('s', 'login successful, welcome to your poche'); + $this->messages->add('s', 'welcome to your poche'); if (!empty($_POST['longlastingsession'])) { $_SESSION['longlastingsession'] = 31536000; $_SESSION['expires_on'] = time() + $_SESSION['longlastingsession']; @@ -216,11 +234,11 @@ class Poche session_regenerate_id(true); Tools::redirect($referer); } - $this->messages->add('e', 'login failed, bad login or password'); + $this->messages->add('e', 'login failed: bad login or password'); Tools::logm('login failed'); Tools::redirect(); } else { - $this->messages->add('e', 'login failed, you have to fill all fields'); + $this->messages->add('e', 'login failed: you have to fill all fields'); Tools::logm('login failed'); Tools::redirect(); } @@ -228,7 +246,7 @@ class Poche public function logout() { - $this->messages->add('s', 'logout successful, see you soon!'); + $this->messages->add('s', 'see you soon!'); Tools::logm('logout'); Session::logout(); Tools::redirect(); diff --git a/inc/poche/Tools.class.php b/inc/poche/Tools.class.php index 7bc8830a..8b339ea5 100644 --- a/inc/poche/Tools.class.php +++ b/inc/poche/Tools.class.php @@ -197,7 +197,7 @@ class Tools { if (DEBUG_POCHE) { $t = strval(date('Y/m/d_H:i:s')) . ' - ' . $_SERVER["REMOTE_ADDR"] . ' - ' . strval($message) . "\n"; - file_put_contents('./log.txt', $t, FILE_APPEND); + file_put_contents(CACHE . '/log.txt', $t, FILE_APPEND); } } diff --git a/inc/poche/config.inc.php b/inc/poche/config.inc.php index d49df190..d91a44be 100644 --- a/inc/poche/config.inc.php +++ b/inc/poche/config.inc.php @@ -8,7 +8,7 @@ * @license http://www.wtfpl.net/ see COPYING file */ -define ('POCHE_VERSION', '1.0-alpha'); +define ('POCHE_VERSION', '1.0-beta'); define ('MODE_DEMO', FALSE); define ('DEBUG_POCHE', FALSE); define ('CONVERT_LINKS_FOOTNOTES', FALSE); @@ -22,24 +22,26 @@ define ('TPL', './tpl'); define ('LOCALE', './locale'); define ('CACHE', './cache'); define ('LANG', 'fr_FR.UTF8'); +define ('PAGINATION', '10'); +define ('THEME', 'light'); $storage_type = 'sqlite'; # sqlite, mysql, (file, not yet) # /!\ Be careful if you change the lines below /!\ require_once './inc/poche/Tools.class.php'; require_once './inc/poche/Url.class.php'; +require_once './inc/3rdparty/Session.class.php'; +require_once './inc/3rdparty/class.messages.php'; require_once './inc/poche/Poche.class.php'; require_once './inc/3rdparty/Readability.php'; require_once './inc/3rdparty/Encoding.php'; -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'; -require_once './inc/3rdparty/class.messages.php'; +require_once './inc/3rdparty/paginator.php'; if (DOWNLOAD_PICTURES) { require_once './inc/poche/pochePictures.php'; } -$poche = new Poche($storage_type); -$poche->messages = new Messages(); \ No newline at end of file +$poche = new Poche($storage_type); \ No newline at end of file -- cgit v1.2.3 From 6fb3a2a18591a4c79e91a90282d88cd84554f83c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Mon, 5 Aug 2013 22:50:00 +0200 Subject: move xsrf test --- inc/poche/config.inc.php | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'inc/poche') diff --git a/inc/poche/config.inc.php b/inc/poche/config.inc.php index d91a44be..ee0f6616 100644 --- a/inc/poche/config.inc.php +++ b/inc/poche/config.inc.php @@ -29,7 +29,6 @@ $storage_type = 'sqlite'; # sqlite, mysql, (file, not yet) # /!\ Be careful if you change the lines below /!\ require_once './inc/poche/Tools.class.php'; require_once './inc/poche/Url.class.php'; -require_once './inc/3rdparty/Session.class.php'; require_once './inc/3rdparty/class.messages.php'; require_once './inc/poche/Poche.class.php'; require_once './inc/3rdparty/Readability.php'; @@ -39,9 +38,18 @@ require_once './inc/store/' . $storage_type . '.class.php'; require_once './vendor/autoload.php'; require_once './inc/3rdparty/simple_html_dom.php'; require_once './inc/3rdparty/paginator.php'; +require_once './inc/3rdparty/Session.class.php'; if (DOWNLOAD_PICTURES) { require_once './inc/poche/pochePictures.php'; } -$poche = new Poche($storage_type); \ No newline at end of file +$poche = new Poche($storage_type); + +#XSRF protection with token +// if (!empty($_POST)) { +// if (!Session::isToken($_POST['token'])) { +// die(_('Wrong token')); +// } +// unset($_SESSION['tokens']); +// } \ No newline at end of file -- cgit v1.2.3 From 7ce7ec4c942e0a3567858ad0ec8e654000b49a3f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Tue, 6 Aug 2013 14:18:03 +0200 Subject: prepare to multi users --- inc/poche/Poche.class.php | 36 +++++++++++++++++++----------------- inc/poche/User.class.php | 33 +++++++++++++++++++++++++++++++++ inc/poche/config.inc.php | 3 ++- 3 files changed, 54 insertions(+), 18 deletions(-) create mode 100644 inc/poche/User.class.php (limited to 'inc/poche') diff --git a/inc/poche/Poche.class.php b/inc/poche/Poche.class.php index 789d6647..2c0c73f9 100644 --- a/inc/poche/Poche.class.php +++ b/inc/poche/Poche.class.php @@ -10,6 +10,7 @@ class Poche { + public $user; public $store; public $tpl; public $messages; @@ -26,17 +27,20 @@ class Poche { $this->install(); } - - $this->saveUser(); } private function init() { + Tools::initPhp(); + Session::init(); + $this->user = isset($_SESSION['poche_user']) ? $_SESSION['poche_user'] : array(); + # l10n - putenv('LC_ALL=' . LANG); - setlocale(LC_ALL, LANG); - bindtextdomain(LANG, LOCALE); - textdomain(LANG); + $language = ($this->user->getConfigValue('language')) ? $this->user->getConfigValue('language') : LANG; + putenv('LC_ALL=' . $language); + setlocale(LC_ALL, $language); + bindtextdomain($language, LOCALE); + textdomain($language); # template engine $loader = new Twig_Loader_Filesystem(TPL); @@ -48,10 +52,9 @@ class Poche $filter = new Twig_SimpleFilter('getDomain', 'Tools::getDomain'); $this->tpl->addFilter($filter); - $this->pagination = new Paginator(PAGINATION, 'p'); - - Tools::initPhp(); - Session::init(); + # Pagination + $pager = ($this->user->getConfigValue('pager')) ? $this->user->getConfigValue('pager') : PAGINATION; + $this->pagination = new Paginator($pager, 'p'); } private function install() @@ -77,12 +80,6 @@ class Poche exit(); } - private function saveUser() - { - $_SESSION['login'] = (isset ($_SESSION['login'])) ? $_SESSION['login'] : $this->store->getLogin(); - $_SESSION['pass'] = (isset ($_SESSION['pass'])) ? $_SESSION['pass'] : $this->store->getPassword(); - } - /** * Call action (mark as fav, archive, delete, etc.) */ @@ -221,7 +218,11 @@ class Poche 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']))) { + $user = $this->store->login($_POST['login'], Tools::encodeString($_POST['password'] . $_POST['login'])); + if ($user != array()) { + # Save login into Session + Session::login($user['username'], $user['password'], $_POST['login'], Tools::encodeString($_POST['password'] . $_POST['login']), array('poche_user' => new User($user))); + Tools::logm('login successful'); $this->messages->add('s', 'welcome to your poche'); if (!empty($_POST['longlastingsession'])) { @@ -248,6 +249,7 @@ class Poche { $this->messages->add('s', 'see you soon!'); Tools::logm('logout'); + $this->user = array(); Session::logout(); Tools::redirect(); } diff --git a/inc/poche/User.class.php b/inc/poche/User.class.php new file mode 100644 index 00000000..ef47730f --- /dev/null +++ b/inc/poche/User.class.php @@ -0,0 +1,33 @@ + + * @copyright 2013 + * @license http://www.wtfpl.net/ see COPYING file + */ + +class User +{ + public $id; + public $username; + public $name; + public $password; + public $email; + public $config; + + function __construct($user) + { + $this->id = $user['id']; + $this->username = $user['username']; + $this->name = $user['name']; + $this->password = $user['password']; + $this->email = $user['email']; + $this->config = $user['config']; + } + + function getConfigValue($name) { + return (isset($this->config[$name])) ? $this->config[$name] : FALSE; + } +} \ No newline at end of file diff --git a/inc/poche/config.inc.php b/inc/poche/config.inc.php index ee0f6616..d0c686f0 100644 --- a/inc/poche/config.inc.php +++ b/inc/poche/config.inc.php @@ -21,12 +21,13 @@ define ('ABS_PATH', 'assets/'); define ('TPL', './tpl'); define ('LOCALE', './locale'); define ('CACHE', './cache'); -define ('LANG', 'fr_FR.UTF8'); +define ('LANG', 'en_EN.UTF8'); define ('PAGINATION', '10'); define ('THEME', 'light'); $storage_type = 'sqlite'; # sqlite, mysql, (file, not yet) # /!\ Be careful if you change the lines below /!\ +require_once './inc/poche/User.class.php'; require_once './inc/poche/Tools.class.php'; require_once './inc/poche/Url.class.php'; require_once './inc/3rdparty/class.messages.php'; -- cgit v1.2.3 From 8d3275bee488d058c6ff0efe6e81d20a584d3709 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Tue, 6 Aug 2013 15:51:48 +0200 Subject: multi user --- inc/poche/Poche.class.php | 72 +++++++++++++++++++++++++++++------------------ inc/poche/User.class.php | 33 ++++++++++++++++------ inc/poche/config.inc.php | 2 +- 3 files changed, 70 insertions(+), 37 deletions(-) (limited to 'inc/poche') diff --git a/inc/poche/Poche.class.php b/inc/poche/Poche.class.php index 2c0c73f9..ce5bb54a 100644 --- a/inc/poche/Poche.class.php +++ b/inc/poche/Poche.class.php @@ -33,10 +33,18 @@ class Poche { Tools::initPhp(); Session::init(); - $this->user = isset($_SESSION['poche_user']) ? $_SESSION['poche_user'] : array(); + + if (isset($_SESSION['poche_user'])) { + $this->user = $_SESSION['poche_user']; + } + else { + # fake user, just for install & login screens + $this->user = new User(); + $this->user->setConfig($this->getDefaultConfig()); + } # l10n - $language = ($this->user->getConfigValue('language')) ? $this->user->getConfigValue('language') : LANG; + $language = $this->user->getConfigValue('language'); putenv('LC_ALL=' . $language); setlocale(LC_ALL, $language); bindtextdomain($language, LOCALE); @@ -53,8 +61,7 @@ class Poche $this->tpl->addFilter($filter); # Pagination - $pager = ($this->user->getConfigValue('pager')) ? $this->user->getConfigValue('pager') : PAGINATION; - $this->pagination = new Paginator($pager, 'p'); + $this->pagination = new Paginator($this->user->getConfigValue('pager'), 'p'); } private function install() @@ -80,6 +87,14 @@ class Poche exit(); } + public function getDefaultConfig() + { + return array( + 'pager' => PAGINATION, + 'language' => LANG, + ); + } + /** * Call action (mark as fav, archive, delete, etc.) */ @@ -89,7 +104,7 @@ class Poche { case 'add': if($parametres_url = $url->fetchContent()) { - if ($this->store->add($url->getUrl(), $parametres_url['title'], $parametres_url['content'])) { + if ($this->store->add($url->getUrl(), $parametres_url['title'], $parametres_url['content'], $this->user->getId())) { Tools::logm('add link ' . $url->getUrl()); $last_id = $this->store->getLastId(); if (DOWNLOAD_PICTURES) { @@ -109,7 +124,7 @@ class Poche Tools::redirect(); break; case 'delete': - if ($this->store->deleteById($id)) { + if ($this->store->deleteById($id, $this->user->getId())) { if (DOWNLOAD_PICTURES) { remove_directory(ABS_PATH . $id); } @@ -123,12 +138,12 @@ class Poche Tools::redirect(); break; case 'toggle_fav' : - $this->store->favoriteById($id); + $this->store->favoriteById($id, $this->user->getId()); Tools::logm('mark as favorite link #' . $id); Tools::redirect(); break; case 'toggle_archive' : - $this->store->archiveById($id); + $this->store->archiveById($id, $this->user->getId()); Tools::logm('archive link #' . $id); Tools::redirect(); break; @@ -157,7 +172,7 @@ class Poche Tools::logm('config view'); break; case 'view': - $entry = $this->store->retrieveOneById($id); + $entry = $this->store->retrieveOneById($id, $this->user->getId()); if ($entry != NULL) { Tools::logm('view link #' . $id); $content = $entry['content']; @@ -176,10 +191,10 @@ class Poche } break; default: # home view - $entries = $this->store->getEntriesByView($view); + $entries = $this->store->getEntriesByView($view, $this->user->getId()); $this->pagination->set_total(count($entries)); $page_links = $this->pagination->page_links('?view=' . $view . '&sort=' . $_SESSION['sort'] . '&'); - $datas = $this->store->getEntriesByView($view, $this->pagination->get_limit()); + $datas = $this->store->getEntriesByView($view, $this->user->getId(), $this->pagination->get_limit()); $tpl_vars = array( 'entries' => $datas, 'page_links' => $page_links, @@ -194,21 +209,21 @@ class Poche public function updatePassword() { if (MODE_DEMO) { - $this->messages->add('i', 'in demo mode, you can\'t update your password'); + $this->messages->add('i', _('in demo mode, you can\'t update your password')); Tools::logm('in demo mode, you can\'t do this'); Tools::redirect('?view=config'); } else { if (isset($_POST['password']) && isset($_POST['password_repeat'])) { if ($_POST['password'] == $_POST['password_repeat'] && $_POST['password'] != "") { - Tools::logm('password updated'); - $this->messages->add('s', 'your password has been updated'); - $this->store->updatePassword(Tools::encodeString($_POST['password'] . $_SESSION['login'])); + $this->messages->add('s', _('your password has been updated')); + $this->store->updatePassword($this->user->getId(), Tools::encodeString($_POST['password'] . $this->user->getUsername())); Session::logout(); + Tools::logm('password updated'); Tools::redirect(); } else { - $this->messages->add('e', 'the two fields have to be filled & the password must be the same in the two fields'); + $this->messages->add('e', _('the two fields have to be filled & the password must be the same in the two fields')); Tools::redirect('?view=config'); } } @@ -223,8 +238,7 @@ class Poche # Save login into Session Session::login($user['username'], $user['password'], $_POST['login'], Tools::encodeString($_POST['password'] . $_POST['login']), array('poche_user' => new User($user))); - Tools::logm('login successful'); - $this->messages->add('s', 'welcome to your poche'); + $this->messages->add('s', _('welcome to your poche')); if (!empty($_POST['longlastingsession'])) { $_SESSION['longlastingsession'] = 31536000; $_SESSION['expires_on'] = time() + $_SESSION['longlastingsession']; @@ -233,13 +247,14 @@ class Poche session_set_cookie_params(0); } session_regenerate_id(true); + Tools::logm('login successful'); Tools::redirect($referer); } - $this->messages->add('e', 'login failed: bad login or password'); + $this->messages->add('e', _('login failed: bad login or password')); Tools::logm('login failed'); Tools::redirect(); } else { - $this->messages->add('e', 'login failed: you have to fill all fields'); + $this->messages->add('e', _('login failed: you have to fill all fields')); Tools::logm('login failed'); Tools::redirect(); } @@ -247,7 +262,7 @@ class Poche public function logout() { - $this->messages->add('s', 'see you soon!'); + $this->messages->add('s', _('see you soon!')); Tools::logm('logout'); $this->user = array(); Session::logout(); @@ -271,14 +286,14 @@ class Poche $this->action('add', $url); if ($read == '1') { $last_id = $this->store->getLastId(); - $this->store->archiveById($last_id); + $this->action('toggle_archive', $url, $last_id); } } # the second
                        is for read links $read = 1; } - $this->messages->add('s', 'import from instapaper completed'); + $this->messages->add('s', _('import from instapaper completed')); Tools::logm('import from instapaper completed'); Tools::redirect(); } @@ -300,14 +315,14 @@ class Poche $this->action('add', $url); if ($read == '1') { $last_id = $this->store->getLastId(); - $this->store->archiveById($last_id); + $this->action('toggle_archive', $url, $last_id); } } # the second
                          is for read links $read = 1; } - $this->messages->add('s', 'import from pocket completed'); + $this->messages->add('s', _('import from pocket completed')); Tools::logm('import from pocket completed'); Tools::redirect(); } @@ -327,16 +342,17 @@ class Poche // if ($attr_value == 'favorite' && $attr_value == 'true') { // $last_id = $this->store->getLastId(); // $this->store->favoriteById($last_id); + // $this->action('toogle_fav', $url, $last_id); // } // if ($attr_value == 'archive' && $attr_value == 'true') { // $last_id = $this->store->getLastId(); - // $this->store->archiveById($last_id); + // $this->action('toggle_archive', $url, $last_id); // } } if ($url->isCorrect()) $this->action('add', $url); } - $this->messages->add('s', 'import from Readability completed'); + $this->messages->add('s', _('import from Readability completed')); Tools::logm('import from Readability completed'); Tools::redirect(); } @@ -356,7 +372,7 @@ class Poche public function export() { - $entries = $this->store->retrieveAll(); + $entries = $this->store->retrieveAll($this->user->getId()); echo $this->tpl->render('export.twig', array( 'export' => Tools::renderJson($entries), )); diff --git a/inc/poche/User.class.php b/inc/poche/User.class.php index ef47730f..6dac7839 100644 --- a/inc/poche/User.class.php +++ b/inc/poche/User.class.php @@ -17,17 +17,34 @@ class User public $email; public $config; - function __construct($user) + function __construct($user = array()) { - $this->id = $user['id']; - $this->username = $user['username']; - $this->name = $user['name']; - $this->password = $user['password']; - $this->email = $user['email']; - $this->config = $user['config']; + if ($user != array()) { + $this->id = $user['id']; + $this->username = $user['username']; + $this->name = $user['name']; + $this->password = $user['password']; + $this->email = $user['email']; + $this->config = $user['config']; + } } - function getConfigValue($name) { + public function getId() + { + return $this->id; + } + + public function getUsername() + { + return $this->username; + } + + public function setConfig($config) + { + $this->config = $config; + } + + public function getConfigValue($name) { return (isset($this->config[$name])) ? $this->config[$name] : FALSE; } } \ No newline at end of file diff --git a/inc/poche/config.inc.php b/inc/poche/config.inc.php index d0c686f0..a8a9c032 100644 --- a/inc/poche/config.inc.php +++ b/inc/poche/config.inc.php @@ -10,7 +10,7 @@ define ('POCHE_VERSION', '1.0-beta'); define ('MODE_DEMO', FALSE); -define ('DEBUG_POCHE', FALSE); +define ('DEBUG_POCHE', TRUE); define ('CONVERT_LINKS_FOOTNOTES', FALSE); define ('REVERT_FORCED_PARAGRAPH_ELEMENTS', FALSE); define ('DOWNLOAD_PICTURES', FALSE); -- cgit v1.2.3 From bc1ee8524e0769ad37e3c4c02cfe96d2f60e52f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Wed, 7 Aug 2013 14:24:07 +0200 Subject: postgres --- inc/poche/Database.class.php | 199 +++++++++++++++++++++++++++++++++++++++++++ inc/poche/Poche.class.php | 23 +++-- inc/poche/Tools.class.php | 2 + inc/poche/config.inc.php | 7 +- 4 files changed, 218 insertions(+), 13 deletions(-) create mode 100644 inc/poche/Database.class.php (limited to 'inc/poche') diff --git a/inc/poche/Database.class.php b/inc/poche/Database.class.php new file mode 100644 index 00000000..a226b31e --- /dev/null +++ b/inc/poche/Database.class.php @@ -0,0 +1,199 @@ + + * @copyright 2013 + * @license http://www.wtfpl.net/ see COPYING file + */ + +class Database { + + #postgresql + public static $db_path = 'pgsql:host=localhost;dbname=poche'; + public static $user = 'postgres'; + public static $password = 'postgres'; + #sqlite + // public static $db_path = 'sqlite:./db/poche.sqlite'; + // public static $user = ''; + // public static $password = ''; + #mysql + // public static $db_path = 'mysql:host=localhost;dbname=poche'; + // public static $user = 'root'; + // public static $password = 'root'; + + var $handle; + + function __construct() { + $this->handle = new PDO(self::$db_path, self::$user, self::$password); + $this->handle->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); + } + + private function getHandle() { + return $this->handle; + } + + public function isInstalled() { + $sql = "SELECT username FROM users WHERE id=?"; + $query = $this->executeQuery($sql, array('1')); + $hasAdmin = $query->fetchAll(); + + if (count($hasAdmin) == 0) + return FALSE; + + return TRUE; + } + + public function install($login, $password) { + $sql = 'INSERT INTO users ( username, password ) VALUES (?, ?)'; + $params = array($login, $password); + $query = $this->executeQuery($sql, $params); + + return TRUE; + } + + private function getConfigUser($id) { + $sql = "SELECT * FROM users_config WHERE user_id = ?"; + $query = $this->executeQuery($sql, array($id)); + $result = $query->fetchAll(); + $user_config = array(); + + foreach ($result as $key => $value) { + $user_config[$value['name']] = $value['value']; + } + + return $user_config; + } + + public function login($username, $password) { + $sql = "SELECT * FROM users WHERE username=? AND password=?"; + $query = $this->executeQuery($sql, array($username, $password)); + $login = $query->fetchAll(); + + $user = array(); + if (isset($login[0])) { + $user['id'] = $login[0]['id']; + $user['username'] = $login[0]['username']; + $user['password'] = $login[0]['password']; + $user['name'] = $login[0]['name']; + $user['email'] = $login[0]['email']; + $user['config'] = $this->getConfigUser($login[0]['id']); + } + + return $user; + } + + public function updatePassword($id, $password) + { + $sql_update = "UPDATE users SET password=? WHERE id=?"; + $params_update = array($password, $id); + $query = $this->executeQuery($sql_update, $params_update); + } + + private function executeQuery($sql, $params) { + try + { + $query = $this->getHandle()->prepare($sql); + $query->execute($params); + return $query; + } + catch (Exception $e) + { + Tools::logm('execute query error : '.$e->getMessage()); + return FALSE; + } + } + + public function retrieveAll($user_id) { + $sql = "SELECT * FROM entries WHERE user_id=? ORDER BY id"; + $query = $this->executeQuery($sql, array($user_id)); + $entries = $query->fetchAll(); + + return $entries; + } + + public function retrieveOneById($id, $user_id) { + $entry = NULL; + $sql = "SELECT * FROM entries WHERE id=? AND user_id=?"; + $params = array(intval($id), $user_id); + $query = $this->executeQuery($sql, $params); + $entry = $query->fetchAll(); + + return $entry[0]; + } + + public function getEntriesByView($view, $user_id, $limit = '') { + switch ($_SESSION['sort']) + { + case 'ia': + $order = 'ORDER BY id'; + break; + case 'id': + $order = 'ORDER BY id DESC'; + break; + case 'ta': + $order = 'ORDER BY lower(title)'; + break; + case 'td': + $order = 'ORDER BY lower(title) DESC'; + break; + default: + $order = 'ORDER BY id'; + break; + } + + switch ($view) + { + case 'archive': + $sql = "SELECT * FROM entries WHERE user_id=? AND is_read=? " . $order; + $params = array($user_id, 1); + break; + case 'fav' : + $sql = "SELECT * FROM entries WHERE user_id=? AND is_fav=? " . $order; + $params = array($user_id, 1); + break; + default: + $sql = "SELECT * FROM entries WHERE user_id=? AND is_read=? " . $order; + $params = array($user_id, 0); + break; + } + + $sql .= ' ' . $limit; + + $query = $this->executeQuery($sql, $params); + $entries = $query->fetchAll(); + + return $entries; + } + + public function add($url, $title, $content, $user_id) { + $sql_action = 'INSERT INTO entries ( url, title, content, user_id ) VALUES (?, ?, ?, ?)'; + $params_action = array($url, $title, $content, $user_id); + $query = $this->executeQuery($sql_action, $params_action); + return $query; + } + + public function deleteById($id, $user_id) { + $sql_action = "DELETE FROM entries WHERE id=? AND user_id=?"; + $params_action = array($id, $user_id); + $query = $this->executeQuery($sql_action, $params_action); + return $query; + } + + public function favoriteById($id, $user_id) { + $sql_action = "UPDATE entries SET is_fav=NOT is_fav WHERE id=? AND user_id=?"; + $params_action = array($id, $user_id); + $query = $this->executeQuery($sql_action, $params_action); + } + + public function archiveById($id, $user_id) { + $sql_action = "UPDATE entries SET is_read=NOT is_read WHERE id=? AND user_id=?"; + $params_action = array($id, $user_id); + $query = $this->executeQuery($sql_action, $params_action); + } + + public function getLastId() { + return $this->getHandle()->lastInsertId(); + } +} diff --git a/inc/poche/Poche.class.php b/inc/poche/Poche.class.php index ce5bb54a..0a43df71 100644 --- a/inc/poche/Poche.class.php +++ b/inc/poche/Poche.class.php @@ -16,9 +16,9 @@ class Poche public $messages; public $pagination; - function __construct($storage_type) + function __construct() { - $this->store = new $storage_type(); + $this->store = new Database(); $this->init(); $this->messages = new Messages(); @@ -52,9 +52,13 @@ class Poche # template engine $loader = new Twig_Loader_Filesystem(TPL); - $this->tpl = new Twig_Environment($loader, array( - 'cache' => CACHE, - )); + if (DEBUG_POCHE) { + $twig_params = array(); + } + else { + $twig_params = array('cache' => CACHE); + } + $this->tpl = new Twig_Environment($loader, $twig_params); $this->tpl->addExtension(new Twig_Extensions_Extension_I18n()); # filter to display domain name of an url $filter = new Twig_SimpleFilter('getDomain', 'Tools::getDomain'); @@ -124,18 +128,19 @@ class Poche Tools::redirect(); break; case 'delete': + $msg = 'delete link #' . $id; if ($this->store->deleteById($id, $this->user->getId())) { if (DOWNLOAD_PICTURES) { remove_directory(ABS_PATH . $id); } $this->messages->add('s', _('the link has been deleted successfully')); - Tools::logm('delete link #' . $id); } else { $this->messages->add('e', _('the link wasn\'t deleted')); - Tools::logm('error : can\'t delete link #' . $id); + $msg = 'error : can\'t delete link #' . $id; } - Tools::redirect(); + Tools::logm($msg); + Tools::redirect('?'); break; case 'toggle_fav' : $this->store->favoriteById($id, $this->user->getId()); @@ -385,7 +390,7 @@ class Poche if (file_exists($cache_file) && (filemtime($cache_file) > (time() - 86400 ))) { $version = file_get_contents($cache_file); } else { - $version = file_get_contents('http://www.inthepoche.com/' . $which); + $version = file_get_contents('http://static.inthepoche.com/versions/' . $which); file_put_contents($cache_file, $version, LOCK_EX); } return $version; diff --git a/inc/poche/Tools.class.php b/inc/poche/Tools.class.php index 8b339ea5..d0e43166 100644 --- a/inc/poche/Tools.class.php +++ b/inc/poche/Tools.class.php @@ -77,6 +77,7 @@ class Tools $url = $ref; } } + self::logm('redirect to ' . $url); header('Location: '.$url); exit(); } @@ -198,6 +199,7 @@ class Tools if (DEBUG_POCHE) { $t = strval(date('Y/m/d_H:i:s')) . ' - ' . $_SERVER["REMOTE_ADDR"] . ' - ' . strval($message) . "\n"; file_put_contents(CACHE . '/log.txt', $t, FILE_APPEND); + error_log('DEBUG POCHE : ' . $message); } } diff --git a/inc/poche/config.inc.php b/inc/poche/config.inc.php index a8a9c032..834b18ea 100644 --- a/inc/poche/config.inc.php +++ b/inc/poche/config.inc.php @@ -24,7 +24,7 @@ define ('CACHE', './cache'); define ('LANG', 'en_EN.UTF8'); define ('PAGINATION', '10'); define ('THEME', 'light'); -$storage_type = 'sqlite'; # sqlite, mysql, (file, not yet) +define ('STORAGE','postgres'); # postgres, mysql, sqlite # /!\ Be careful if you change the lines below /!\ require_once './inc/poche/User.class.php'; @@ -34,8 +34,7 @@ require_once './inc/3rdparty/class.messages.php'; require_once './inc/poche/Poche.class.php'; require_once './inc/3rdparty/Readability.php'; require_once './inc/3rdparty/Encoding.php'; -require_once './inc/store/store.class.php'; -require_once './inc/store/' . $storage_type . '.class.php'; +require_once './inc/poche/Database.class.php'; require_once './vendor/autoload.php'; require_once './inc/3rdparty/simple_html_dom.php'; require_once './inc/3rdparty/paginator.php'; @@ -45,7 +44,7 @@ if (DOWNLOAD_PICTURES) { require_once './inc/poche/pochePictures.php'; } -$poche = new Poche($storage_type); +$poche = new Poche(); #XSRF protection with token // if (!empty($_POST)) { -- cgit v1.2.3 From 68857cea8c08aab54c632d63f4526d0bb16f80d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Wed, 7 Aug 2013 14:38:58 +0200 Subject: setup of storage --- inc/poche/Database.class.php | 33 +++++++++++++++++---------------- inc/poche/config.inc.php | 9 ++++++++- 2 files changed, 25 insertions(+), 17 deletions(-) (limited to 'inc/poche') diff --git a/inc/poche/Database.class.php b/inc/poche/Database.class.php index a226b31e..034b1003 100644 --- a/inc/poche/Database.class.php +++ b/inc/poche/Database.class.php @@ -9,24 +9,25 @@ */ class Database { - - #postgresql - public static $db_path = 'pgsql:host=localhost;dbname=poche'; - public static $user = 'postgres'; - public static $password = 'postgres'; - #sqlite - // public static $db_path = 'sqlite:./db/poche.sqlite'; - // public static $user = ''; - // public static $password = ''; - #mysql - // public static $db_path = 'mysql:host=localhost;dbname=poche'; - // public static $user = 'root'; - // public static $password = 'root'; - var $handle; - function __construct() { - $this->handle = new PDO(self::$db_path, self::$user, self::$password); + function __construct() + { + switch (STORAGE) { + case 'sqlite': + $db_path = 'sqlite:' . STORAGE_SQLITE; + $this->handle = new PDO($db_path); + break; + case 'mysql': + $db_path = 'mysql:host=' . STORAGE_SERVER . ';dbname=' . STORAGE_DB; + $this->handle = new PDO($db_path, STORAGE_USER, STORAGE_PASSWORD); + break; + case 'postgres': + $db_path = 'pgsql:host=' . STORAGE_SERVER . ';dbname=' . STORAGE_DB; + $this->handle = new PDO($db_path, STORAGE_USER, STORAGE_PASSWORD); + break; + } + $this->handle->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); } diff --git a/inc/poche/config.inc.php b/inc/poche/config.inc.php index 834b18ea..ef2f699d 100644 --- a/inc/poche/config.inc.php +++ b/inc/poche/config.inc.php @@ -8,6 +8,14 @@ * @license http://www.wtfpl.net/ see COPYING file */ +# storage +define ('STORAGE','postgres'); # postgres, mysql, sqlite +define ('STORAGE_SERVER', 'localhost'); # leave blank for sqlite +define ('STORAGE_DB', 'poche'); # only for postgres & mysql +define ('STORAGE_SQLITE', './db/poche.sqlite'); +define ('STORAGE_USER', 'postgres'); # leave blank for sqlite +define ('STORAGE_PASSWORD', 'postgres'); # leave blank for sqlite + define ('POCHE_VERSION', '1.0-beta'); define ('MODE_DEMO', FALSE); define ('DEBUG_POCHE', TRUE); @@ -24,7 +32,6 @@ define ('CACHE', './cache'); define ('LANG', 'en_EN.UTF8'); define ('PAGINATION', '10'); define ('THEME', 'light'); -define ('STORAGE','postgres'); # postgres, mysql, sqlite # /!\ Be careful if you change the lines below /!\ require_once './inc/poche/User.class.php'; -- cgit v1.2.3 From 580d60b9416b3445300f37fc0ecc160254ed0676 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Wed, 7 Aug 2013 15:46:17 +0200 Subject: file to update from 0.x to 1.x \o/ --- inc/poche/Database.class.php | 1 + 1 file changed, 1 insertion(+) (limited to 'inc/poche') diff --git a/inc/poche/Database.class.php b/inc/poche/Database.class.php index 034b1003..8da7a994 100644 --- a/inc/poche/Database.class.php +++ b/inc/poche/Database.class.php @@ -29,6 +29,7 @@ class Database { } $this->handle->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); + Tools::logm('storage type ' . STORAGE); } private function getHandle() { -- cgit v1.2.3 From b916bcfccc5a8b1c1852c0bf39bb6f9837296a4e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Wed, 7 Aug 2013 19:14:28 +0200 Subject: fixes for 1.0-beta --- inc/poche/Database.class.php | 31 ++++++++++++----- inc/poche/Poche.class.php | 83 ++++++++++++++++++++++++++++++-------------- inc/poche/config.inc.php | 3 +- 3 files changed, 81 insertions(+), 36 deletions(-) (limited to 'inc/poche') diff --git a/inc/poche/Database.class.php b/inc/poche/Database.class.php index 8da7a994..cd5a9a31 100644 --- a/inc/poche/Database.class.php +++ b/inc/poche/Database.class.php @@ -37,19 +37,34 @@ class Database { } public function isInstalled() { - $sql = "SELECT username FROM users WHERE id=?"; - $query = $this->executeQuery($sql, array('1')); - $hasAdmin = $query->fetchAll(); + $sql = "SELECT username FROM users"; + $query = $this->executeQuery($sql, array()); + $hasAdmin = count($query->fetchAll()); - if (count($hasAdmin) == 0) + if ($hasAdmin == 0) return FALSE; return TRUE; } public function install($login, $password) { - $sql = 'INSERT INTO users ( username, password ) VALUES (?, ?)'; - $params = array($login, $password); + $sql = 'INSERT INTO users ( username, password, name, email) VALUES (?, ?, ?, ?)'; + $params = array($login, $password, $login, ' '); + $query = $this->executeQuery($sql, $params); + + $sequence = ''; + if (STORAGE == 'postgres') { + $sequence = 'users_id_seq'; + } + + $id_user = intval($this->getLastId($sequence)); + + $sql = 'INSERT INTO users_config ( user_id, name, value ) VALUES (?, ?, ?)'; + $params = array($id_user, 'pager', '10'); + $query = $this->executeQuery($sql, $params); + + $sql = 'INSERT INTO users_config ( user_id, name, value ) VALUES (?, ?, ?)'; + $params = array($id_user, 'language', 'en_EN.UTF8'); $query = $this->executeQuery($sql, $params); return TRUE; @@ -195,7 +210,7 @@ class Database { $query = $this->executeQuery($sql_action, $params_action); } - public function getLastId() { - return $this->getHandle()->lastInsertId(); + public function getLastId($column = '') { + return $this->getHandle()->lastInsertId($column); } } diff --git a/inc/poche/Poche.class.php b/inc/poche/Poche.class.php index 0a43df71..38b4a98e 100644 --- a/inc/poche/Poche.class.php +++ b/inc/poche/Poche.class.php @@ -34,7 +34,7 @@ class Poche Tools::initPhp(); Session::init(); - if (isset($_SESSION['poche_user'])) { + if (isset($_SESSION['poche_user']) && $_SESSION['poche_user'] != array()) { $this->user = $_SESSION['poche_user']; } else { @@ -102,7 +102,7 @@ class Poche /** * Call action (mark as fav, archive, delete, etc.) */ - public function action($action, Url $url, $id = 0) + public function action($action, Url $url, $id = 0, $import = FALSE) { switch ($action) { @@ -110,22 +110,34 @@ class Poche if($parametres_url = $url->fetchContent()) { if ($this->store->add($url->getUrl(), $parametres_url['title'], $parametres_url['content'], $this->user->getId())) { Tools::logm('add link ' . $url->getUrl()); - $last_id = $this->store->getLastId(); + $sequence = ''; + if (STORAGE == 'postgres') { + $sequence = 'entries_id_seq'; + } + $last_id = $this->store->getLastId($sequence); if (DOWNLOAD_PICTURES) { $content = filtre_picture($parametres_url['content'], $url->getUrl(), $last_id); } - $this->messages->add('s', _('the link has been added successfully')); + if (!$import) { + $this->messages->add('s', _('the link has been added successfully')); + } } else { - $this->messages->add('e', _('error during insertion : the link wasn\'t added')); - Tools::logm('error during insertion : the link wasn\'t added'); + if (!$import) { + $this->messages->add('e', _('error during insertion : the link wasn\'t added')); + Tools::logm('error during insertion : the link wasn\'t added ' . $url->getUrl()); + } } } else { - $this->messages->add('e', _('error during fetching content : the link wasn\'t added')); - Tools::logm('error during content fetch'); + if (!$import) { + $this->messages->add('e', _('error during fetching content : the link wasn\'t added')); + Tools::logm('error during content fetch ' . $url->getUrl()); + } + } + if (!$import) { + Tools::redirect(); } - Tools::redirect(); break; case 'delete': $msg = 'delete link #' . $id; @@ -145,12 +157,16 @@ class Poche case 'toggle_fav' : $this->store->favoriteById($id, $this->user->getId()); Tools::logm('mark as favorite link #' . $id); - Tools::redirect(); + if (!$import) { + Tools::redirect(); + } break; case 'toggle_archive' : $this->store->archiveById($id, $this->user->getId()); Tools::logm('archive link #' . $id); - Tools::redirect(); + if (!$import) { + Tools::redirect(); + } break; default: break; @@ -267,10 +283,10 @@ class Poche public function logout() { - $this->messages->add('s', _('see you soon!')); - Tools::logm('logout'); $this->user = array(); Session::logout(); + $this->messages->add('s', _('see you soon!')); + Tools::logm('logout'); Tools::redirect(); } @@ -279,6 +295,7 @@ class Poche # TODO gestion des articles favs $html = new simple_html_dom(); $html->load_file('./instapaper-export.html'); + Tools::logm('starting import from instapaper'); $read = 0; $errors = array(); @@ -288,10 +305,14 @@ class Poche { $a = $li->find('a'); $url = new Url(base64_encode($a[0]->href)); - $this->action('add', $url); + $this->action('add', $url, 0, TRUE); if ($read == '1') { - $last_id = $this->store->getLastId(); - $this->action('toggle_archive', $url, $last_id); + $sequence = ''; + if (STORAGE == 'postgres') { + $sequence = 'entries_id_seq'; + } + $last_id = $this->store->getLastId($sequence); + $this->action('toggle_archive', $url, $last_id, TRUE); } } @@ -308,6 +329,7 @@ class Poche # TODO gestion des articles favs $html = new simple_html_dom(); $html->load_file('./ril_export.html'); + Tools::logm('starting import from pocket'); $read = 0; $errors = array(); @@ -317,10 +339,14 @@ class Poche { $a = $li->find('a'); $url = new Url(base64_encode($a[0]->href)); - $this->action('add', $url); + $this->action('add', $url, 0, TRUE); if ($read == '1') { - $last_id = $this->store->getLastId(); - $this->action('toggle_archive', $url, $last_id); + $sequence = ''; + if (STORAGE == 'postgres') { + $sequence = 'entries_id_seq'; + } + $last_id = $this->store->getLastId($sequence); + $this->action('toggle_archive', $url, $last_id, TRUE); } } @@ -337,6 +363,7 @@ class Poche # TODO gestion des articles lus / favs $str_data = file_get_contents("./readability"); $data = json_decode($str_data,true); + Tools::logm('starting import from Readability'); foreach ($data as $key => $value) { $url = ''; @@ -344,18 +371,22 @@ class Poche if ($attr == 'article__url') { $url = new Url(base64_encode($attr_value)); } + $sequence = ''; + if (STORAGE == 'postgres') { + $sequence = 'entries_id_seq'; + } // if ($attr_value == 'favorite' && $attr_value == 'true') { - // $last_id = $this->store->getLastId(); + // $last_id = $this->store->getLastId($sequence); // $this->store->favoriteById($last_id); - // $this->action('toogle_fav', $url, $last_id); - // } - // if ($attr_value == 'archive' && $attr_value == 'true') { - // $last_id = $this->store->getLastId(); - // $this->action('toggle_archive', $url, $last_id); + // $this->action('toogle_fav', $url, $last_id, TRUE); // } + if ($attr_value == 'archive' && $attr_value == 'true') { + $last_id = $this->store->getLastId($sequence); + $this->action('toggle_archive', $url, $last_id, TRUE); + } } if ($url->isCorrect()) - $this->action('add', $url); + $this->action('add', $url, 0, TRUE); } $this->messages->add('s', _('import from Readability completed')); Tools::logm('import from Readability completed'); diff --git a/inc/poche/config.inc.php b/inc/poche/config.inc.php index ef2f699d..322f69d6 100644 --- a/inc/poche/config.inc.php +++ b/inc/poche/config.inc.php @@ -9,7 +9,7 @@ */ # storage -define ('STORAGE','postgres'); # postgres, mysql, sqlite +define ('STORAGE','sqlite'); # postgres, mysql, sqlite define ('STORAGE_SERVER', 'localhost'); # leave blank for sqlite define ('STORAGE_DB', 'poche'); # only for postgres & mysql define ('STORAGE_SQLITE', './db/poche.sqlite'); @@ -52,7 +52,6 @@ if (DOWNLOAD_PICTURES) { } $poche = new Poche(); - #XSRF protection with token // if (!empty($_POST)) { // if (!Session::isToken($_POST['token'])) { -- cgit v1.2.3 From c7ec97ce98576ab9da367315d1060e781c581df8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Wed, 7 Aug 2013 19:14:48 +0200 Subject: cache to FALSE --- inc/poche/config.inc.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'inc/poche') diff --git a/inc/poche/config.inc.php b/inc/poche/config.inc.php index 322f69d6..930b31e5 100644 --- a/inc/poche/config.inc.php +++ b/inc/poche/config.inc.php @@ -18,7 +18,7 @@ define ('STORAGE_PASSWORD', 'postgres'); # leave blank for sqlite define ('POCHE_VERSION', '1.0-beta'); define ('MODE_DEMO', FALSE); -define ('DEBUG_POCHE', TRUE); +define ('DEBUG_POCHE', FALSE); define ('CONVERT_LINKS_FOOTNOTES', FALSE); define ('REVERT_FORCED_PARAGRAPH_ELEMENTS', FALSE); define ('DOWNLOAD_PICTURES', FALSE); -- cgit v1.2.3