aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorNicolas Lœuillet <nicolas@loeuillet.org>2014-07-12 16:39:31 +0200
committerNicolas Lœuillet <nicolas@loeuillet.org>2014-07-12 16:39:31 +0200
commit26b77483ee7545c0e4f8eeb205a5743bf3589adb (patch)
tree4a1da42493bcf2f16ef6373d7955dad5ff5eda45
parentb3cda72e93fff3a4c3476e9e7e78ef2b2a3f02b9 (diff)
downloadwallabag-26b77483ee7545c0e4f8eeb205a5743bf3589adb.tar.gz
wallabag-26b77483ee7545c0e4f8eeb205a5743bf3589adb.tar.zst
wallabag-26b77483ee7545c0e4f8eeb205a5743bf3589adb.zip
remove PicoFarad
I’ll implement it an other day.
-rw-r--r--inc/3rdparty/PicoFarad/Request.php78
-rw-r--r--inc/3rdparty/PicoFarad/Response.php156
-rw-r--r--inc/3rdparty/PicoFarad/Router.php157
-rw-r--r--inc/3rdparty/PicoFarad/Session.php57
-rw-r--r--inc/3rdparty/PicoFarad/Template.php36
-rw-r--r--inc/poche/Routing.class.php8
-rwxr-xr-xinc/poche/global.inc.php13
-rwxr-xr-xindex.php57
8 files changed, 9 insertions, 553 deletions
diff --git a/inc/3rdparty/PicoFarad/Request.php b/inc/3rdparty/PicoFarad/Request.php
deleted file mode 100644
index 46c82bca..00000000
--- a/inc/3rdparty/PicoFarad/Request.php
+++ /dev/null
@@ -1,78 +0,0 @@
1<?php
2
3namespace PicoFarad\Request;
4
5
6function param($name, $default_value = null)
7{
8 return isset($_GET[$name]) ? $_GET[$name] : $default_value;
9}
10
11
12function int_param($name, $default_value = 0)
13{
14 return isset($_GET[$name]) && ctype_digit($_GET[$name]) ? (int) $_GET[$name] : $default_value;
15}
16
17
18function value($name)
19{
20 $values = values();
21 return isset($values[$name]) ? $values[$name] : null;
22}
23
24
25function values()
26{
27 if (! empty($_POST)) {
28
29 return $_POST;
30 }
31
32 $result = json_decode(body(), true);
33
34 if ($result) {
35 return $result;
36 }
37
38 return array();
39}
40
41
42function body()
43{
44 return file_get_contents('php://input');
45}
46
47
48function file_content($field)
49{
50 if (isset($_FILES[$field])) {
51 return file_get_contents($_FILES[$field]['tmp_name']);
52 }
53
54 return '';
55}
56
57
58function file_info($field)
59{
60 if (isset($_FILES[$field])) {
61 return array(
62 'name' => $_FILES[$field]['name'],
63 'mimetype' => $_FILES[$field]['type'],
64 'size' => $_FILES[$field]['size'],
65 );
66 }
67
68 return false;
69}
70
71
72function file_move($field, $destination)
73{
74 if (isset($_FILES[$field]) && ! file_exists($destination)) {
75 @mkdir(dirname($destination), 0777, true);
76 move_uploaded_file($_FILES[$field]['tmp_name'], $destination);
77 }
78} \ No newline at end of file
diff --git a/inc/3rdparty/PicoFarad/Response.php b/inc/3rdparty/PicoFarad/Response.php
deleted file mode 100644
index 9114fde0..00000000
--- a/inc/3rdparty/PicoFarad/Response.php
+++ /dev/null
@@ -1,156 +0,0 @@
1<?php
2
3namespace PicoFarad\Response;
4
5
6function force_download($filename)
7{
8 header('Content-Disposition: attachment; filename="'.$filename.'"');
9}
10
11
12function content_type($mimetype)
13{
14 header('Content-Type: '.$mimetype);
15}
16
17
18function status($status_code)
19{
20 $sapi_name = php_sapi_name();
21
22 if (strpos($sapi_name, 'apache') !== false || $sapi_name === 'cli-server') {
23 header('HTTP/1.0 '.$status_code);
24 }
25 else {
26 header('Status: '.$status_code);
27 }
28}
29
30
31function redirect($url)
32{
33 header('Location: '.$url);
34 exit;
35}
36
37
38function json(array $data, $status_code = 200)
39{
40 status($status_code);
41
42 header('Content-Type: application/json');
43 echo json_encode($data);
44
45 exit;
46}
47
48
49function text($data, $status_code = 200)
50{
51 status($status_code);
52
53 header('Content-Type: text/plain; charset=utf-8');
54 echo $data;
55
56 exit;
57}
58
59
60function html($data, $status_code = 200)
61{
62 status($status_code);
63
64 header('Content-Type: text/html; charset=utf-8');
65 echo $data;
66
67 exit;
68}
69
70
71function xml($data, $status_code = 200)
72{
73 status($status_code);
74
75 header('Content-Type: text/xml; charset=utf-8');
76 echo $data;
77
78 exit;
79}
80
81
82function js($data, $status_code = 200)
83{
84 status($status_code);
85
86 header('Content-Type: text/javascript; charset=utf-8');
87 echo $data;
88
89 exit;
90}
91
92
93function binary($data, $status_code = 200)
94{
95 status($status_code);
96
97 header('Content-Transfer-Encoding: binary');
98 header('Content-Type: application/octet-stream');
99 echo $data;
100
101 exit;
102}
103
104
105function csp(array $policies = array())
106{
107 $policies['default-src'] = "'self'";
108 $values = '';
109
110 foreach ($policies as $policy => $hosts) {
111
112 if (is_array($hosts)) {
113
114 $acl = '';
115
116 foreach ($hosts as &$host) {
117
118 if ($host === '*' || $host === 'self' || strpos($host, 'http') === 0) {
119 $acl .= $host.' ';
120 }
121 }
122 }
123 else {
124
125 $acl = $hosts;
126 }
127
128 $values .= $policy.' '.trim($acl).'; ';
129 }
130
131 header('Content-Security-Policy: '.$values);
132}
133
134
135function nosniff()
136{
137 header('X-Content-Type-Options: nosniff');
138}
139
140
141function xss()
142{
143 header('X-XSS-Protection: 1; mode=block');
144}
145
146
147function hsts()
148{
149 header('Strict-Transport-Security: max-age=31536000');
150}
151
152
153function xframe($mode = 'DENY', array $urls = array())
154{
155 header('X-Frame-Options: '.$mode.' '.implode(' ', $urls));
156} \ No newline at end of file
diff --git a/inc/3rdparty/PicoFarad/Router.php b/inc/3rdparty/PicoFarad/Router.php
deleted file mode 100644
index b62b8e2d..00000000
--- a/inc/3rdparty/PicoFarad/Router.php
+++ /dev/null
@@ -1,157 +0,0 @@
1<?php
2
3namespace PicoFarad\Router;
4
5// Load controllers: bootstrap('controllers', 'controller1', 'controller2')
6function bootstrap()
7{
8 $files = \func_get_args();
9 $base_path = array_shift($files);
10
11 foreach ($files as $file) {
12 require $base_path.'/'.$file.'.php';
13 }
14}
15
16// Execute a callback before each action
17function before($value = null)
18{
19 static $before_callback = null;
20
21 if (is_callable($value)) {
22 $before_callback = $value;
23 }
24 else if (is_callable($before_callback)) {
25 $before_callback($value);
26 }
27}
28
29// Execute a callback before a specific action
30function before_action($name, $value = null)
31{
32 static $callbacks = array();
33
34 if (is_callable($value)) {
35 $callbacks[$name] = $value;
36 }
37 else if (isset($callbacks[$name]) && is_callable($callbacks[$name])) {
38 $callbacks[$name]($value);
39 }
40}
41
42// Execute an action
43function action($name, \Closure $callback)
44{
45 $handler = isset($_GET['action']) ? $_GET['action'] : 'default';
46
47 if ($handler === $name) {
48 before($name);
49 before_action($name);
50 $callback();
51 }
52}
53
54// Execute an action only for POST requests
55function post_action($name, \Closure $callback)
56{
57 if ($_SERVER['REQUEST_METHOD'] === 'POST') {
58 action($name, $callback);
59 }
60}
61
62// Execute an action only for GET requests
63function get_action($name, \Closure $callback)
64{
65 if ($_SERVER['REQUEST_METHOD'] === 'GET') {
66 action($name, $callback);
67 }
68}
69
70// Run when no action have been executed before
71function notfound(\Closure $callback)
72{
73 before('notfound');
74 before_action('notfound');
75 $callback();
76}
77
78// Match a request like this one: GET /myhandler
79function get($url, \Closure $callback)
80{
81 find_route('GET', $url, $callback);
82}
83
84// Match a request like this one: POST /myhandler
85function post($url, \Closure $callback)
86{
87 find_route('POST', $url, $callback);
88}
89
90// Match a request like this one: PUT /myhandler
91function put($url, \Closure $callback)
92{
93 find_route('PUT', $url, $callback);
94}
95
96// Match a request like this one: DELETE /myhandler
97function delete($url, \Closure $callback)
98{
99 find_route('DELETE', $url, $callback);
100}
101
102// Define which callback to execute according to the URL and the HTTP verb
103function find_route($method, $route, \Closure $callback)
104{
105 if ($_SERVER['REQUEST_METHOD'] === $method) {
106
107 if (! empty($_SERVER['QUERY_STRING'])) {
108 $url = substr($_SERVER['REQUEST_URI'], 0, -(strlen($_SERVER['QUERY_STRING']) + 1));
109 }
110 else {
111 $url = $_SERVER['REQUEST_URI'];
112 }
113
114 $params = array();
115
116 if (url_match($route, $url, $params)) {
117
118 before($route);
119 \call_user_func_array($callback, $params);
120 exit;
121 }
122 }
123}
124
125// Parse url and find matches
126function url_match($route_uri, $request_uri, array &$params)
127{
128 if ($request_uri === $route_uri) return true;
129 if ($route_uri === '/' || $request_uri === '/') return false;
130
131 $route_uri = trim($route_uri, '/');
132 $request_uri = trim($request_uri, '/');
133
134 $route_items = explode('/', $route_uri);
135 $request_items = explode('/', $request_uri);
136 $nb_route_items = count($route_items);
137
138 if ($nb_route_items === count($request_items)) {
139
140 for ($i = 0; $i < $nb_route_items; ++$i) {
141
142 if ($route_items[$i][0] === ':') {
143
144 $params[substr($route_items[$i], 1)] = $request_items[$i];
145 }
146 else if ($route_items[$i] !== $request_items[$i]) {
147
148 $params = array();
149 return false;
150 }
151 }
152
153 return true;
154 }
155
156 return false;
157}
diff --git a/inc/3rdparty/PicoFarad/Session.php b/inc/3rdparty/PicoFarad/Session.php
deleted file mode 100644
index ee7b415a..00000000
--- a/inc/3rdparty/PicoFarad/Session.php
+++ /dev/null
@@ -1,57 +0,0 @@
1<?php
2
3namespace PicoFarad\Session;
4
5const SESSION_LIFETIME = 2678400;
6
7
8function open($base_path = '/', $save_path = '')
9{
10 if ($save_path !== '') session_save_path($save_path);
11
12 // HttpOnly and secure flags for session cookie
13 session_set_cookie_params(
14 SESSION_LIFETIME,
15 $base_path ?: '/',
16 null,
17 isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on',
18 true
19 );
20
21 // Avoid session id in the URL
22 ini_set('session.use_only_cookies', true);
23
24 // Ensure session ID integrity
25 ini_set('session.entropy_file', '/dev/urandom');
26 ini_set('session.entropy_length', '32');
27 ini_set('session.hash_bits_per_character', 6);
28
29 // Custom session name
30 session_name('__$');
31
32 session_start();
33
34 // Regenerate the session id to avoid session fixation issue
35 if (empty($_SESSION['__validated'])) {
36 session_regenerate_id(true);
37 $_SESSION['__validated'] = 1;
38 }
39}
40
41
42function close()
43{
44 session_destroy();
45}
46
47
48function flash($message)
49{
50 $_SESSION['flash_message'] = $message;
51}
52
53
54function flash_error($message)
55{
56 $_SESSION['flash_error_message'] = $message;
57} \ No newline at end of file
diff --git a/inc/3rdparty/PicoFarad/Template.php b/inc/3rdparty/PicoFarad/Template.php
deleted file mode 100644
index c32be309..00000000
--- a/inc/3rdparty/PicoFarad/Template.php
+++ /dev/null
@@ -1,36 +0,0 @@
1<?php
2
3namespace PicoFarad\Template;
4
5const PATH = 'templates/';
6
7// Template\load('template_name', ['bla' => 'value']);
8function load()
9{
10 if (func_num_args() < 1 || func_num_args() > 2) {
11 die('Invalid template arguments');
12 }
13
14 if (! file_exists(PATH.func_get_arg(0).'.php')) {
15 die('Unable to load the template: "'.func_get_arg(0).'"');
16 }
17
18 if (func_num_args() === 2) {
19
20 if (! is_array(func_get_arg(1))) {
21 die('Template variables must be an array');
22 }
23
24 extract(func_get_arg(1));
25 }
26
27 ob_start();
28 include PATH.func_get_arg(0).'.php';
29 return ob_get_clean();
30}
31
32
33function layout($template_name, array $template_args = array(), $layout_name = 'layout')
34{
35 return load($layout_name, $template_args + array('content_for_layout' => load($template_name, $template_args)));
36}
diff --git a/inc/poche/Routing.class.php b/inc/poche/Routing.class.php
index 6e2c046b..8c2f38e3 100644
--- a/inc/poche/Routing.class.php
+++ b/inc/poche/Routing.class.php
@@ -11,8 +11,8 @@
11class Routing 11class Routing
12{ 12{
13 protected $wallabag; 13 protected $wallabag;
14 public $referer; 14 protected $referer;
15 public $view; 15 protected $view;
16 protected $action; 16 protected $action;
17 protected $id; 17 protected $id;
18 protected $url; 18 protected $url;
@@ -55,7 +55,7 @@ class Routing
55 # because messages can be added in $poche->action(), we have to add this entry now (we can add it before) 55 # because messages can be added in $poche->action(), we have to add this entry now (we can add it before)
56 $this->vars = array_merge($this->vars, array('messages' => $this->wallabag->messages->display('all', FALSE))); 56 $this->vars = array_merge($this->vars, array('messages' => $this->wallabag->messages->display('all', FALSE)));
57 57
58 $this->render($this->file, $this->vars); 58 $this->_render($this->file, $this->vars);
59 } 59 }
60 60
61 private function _defineTplInformation() 61 private function _defineTplInformation()
@@ -142,7 +142,7 @@ class Routing
142 } 142 }
143 } 143 }
144 144
145 public function render($file, $vars) 145 public function _render($file, $vars)
146 { 146 {
147 echo $this->wallabag->tpl->render($file, $vars); 147 echo $this->wallabag->tpl->render($file, $vars);
148 } 148 }
diff --git a/inc/poche/global.inc.php b/inc/poche/global.inc.php
index 9d710b6c..3eb64df0 100755
--- a/inc/poche/global.inc.php
+++ b/inc/poche/global.inc.php
@@ -40,12 +40,6 @@ require_once INCLUDES . '/3rdparty/libraries/PHPePub/Logger.php';
40require_once INCLUDES . '/3rdparty/libraries/PHPePub/EPub.php'; 40require_once INCLUDES . '/3rdparty/libraries/PHPePub/EPub.php';
41require_once INCLUDES . '/3rdparty/libraries/PHPePub/EPubChapterSplitter.php'; 41require_once INCLUDES . '/3rdparty/libraries/PHPePub/EPubChapterSplitter.php';
42 42
43require_once INCLUDES . '/3rdparty/PicoFarad/Request.php';
44require_once INCLUDES . '/3rdparty/PicoFarad/Response.php';
45require_once INCLUDES . '/3rdparty/PicoFarad/Router.php';
46require_once INCLUDES . '/3rdparty/PicoFarad/Session.php';
47require_once INCLUDES . '/3rdparty/PicoFarad/Template.php';
48
49# system configuration; database credentials et caetera 43# system configuration; database credentials et caetera
50require_once INCLUDES . '/poche/config.inc.php'; 44require_once INCLUDES . '/poche/config.inc.php';
51require_once INCLUDES . '/poche/config.inc.default.php'; 45require_once INCLUDES . '/poche/config.inc.default.php';
@@ -61,10 +55,3 @@ if (!ini_get('date.timezone') || !@date_default_timezone_set(ini_get('date.timez
61if (defined('ERROR_REPORTING')) { 55if (defined('ERROR_REPORTING')) {
62 error_reporting(ERROR_REPORTING); 56 error_reporting(ERROR_REPORTING);
63} 57}
64
65// Start session
66Session::$sessionName = 'wallabag';
67Session::init();
68
69// Let's rock !
70$wallabag = new Poche();
diff --git a/index.php b/index.php
index 6f190518..e199956c 100755
--- a/index.php
+++ b/index.php
@@ -12,56 +12,9 @@ define ('POCHE', '1.8.0');
12require 'check_setup.php'; 12require 'check_setup.php';
13require_once 'inc/poche/global.inc.php'; 13require_once 'inc/poche/global.inc.php';
14 14
15// Start session
16Session::$sessionName = 'wallabag';
17Session::init();
15 18
16use PicoFarad\Router; 19// Let's rock !
17use PicoFarad\Response; 20$wallabag = new Poche();
18use PicoFarad\Request;
19use PicoFarad\Session;
20
21// Called before each action
22Router\before(function($action) {
23
24 // Open a session only for the specified directory
25 Session\open(dirname($_SERVER['PHP_SELF']));
26
27 // HTTP secure headers
28 Response\csp();
29 Response\xframe();
30 Response\xss();
31 Response\nosniff();
32});
33
34// Show help
35Router\get_action('unread', function() use ($wallabag) {
36 $view = 'home';
37 $id = 0;
38
39 $tpl_vars = array(
40 'referer' => $wallabag->routing->referer,
41 'view' => $wallabag->routing->view,
42 'poche_url' => Tools::getPocheUrl(),
43 'title' => _('wallabag, a read it later open source system'),
44 'token' => \Session::getToken(),
45 'theme' => $wallabag->tpl->getTheme(),
46 'entries' => '',
47 'page_links' => '',
48 'nb_results' => '',
49 'listmode' => (isset($_COOKIE['listmode']) ? true : false),
50 );
51
52 $count = $wallabag->store->getEntriesByViewCount($view, $wallabag->user->getId(), $id);
53
54 if ($count > 0) {
55 $wallabag->pagination->set_total($count);
56 $page_links = str_replace(array('previous', 'next'), array(_('previous'), _('next')),
57 $wallabag->pagination->page_links('?view=' . $view . '&sort=' . $_SESSION['sort'] . (($id)?'&id='.$id:'') . '&' ));
58 $tpl_vars['entries'] = $wallabag->store->getEntriesByView($view, $wallabag->user->getId(), $wallabag->pagination->get_limit(), $id);
59 $tpl_vars['page_links'] = $page_links;
60 $tpl_vars['nb_results'] = $count;
61 }
62
63 $wallabag->routing->render('home.twig', $tpl_vars);
64
65 Tools::logm('display ' . $view . ' view');
66
67});