diff options
author | Nicolas Lœuillet <nicolas.loeuillet@gmail.com> | 2013-08-07 14:24:07 +0200 |
---|---|---|
committer | Nicolas Lœuillet <nicolas.loeuillet@gmail.com> | 2013-08-07 14:24:07 +0200 |
commit | bc1ee8524e0769ad37e3c4c02cfe96d2f60e52f6 (patch) | |
tree | 5ea9d0f0560e84c07ab84c86b9e5fd4dd6ebb039 | |
parent | 8d3275bee488d058c6ff0efe6e81d20a584d3709 (diff) | |
download | wallabag-bc1ee8524e0769ad37e3c4c02cfe96d2f60e52f6.tar.gz wallabag-bc1ee8524e0769ad37e3c4c02cfe96d2f60e52f6.tar.zst wallabag-bc1ee8524e0769ad37e3c4c02cfe96d2f60e52f6.zip |
postgres
-rw-r--r-- | inc/3rdparty/paginator.php | 354 | ||||
-rw-r--r-- | inc/poche/Database.class.php (renamed from inc/store/sqlite.class.php) | 38 | ||||
-rw-r--r-- | inc/poche/Poche.class.php | 23 | ||||
-rw-r--r-- | inc/poche/Tools.class.php | 2 | ||||
-rw-r--r-- | inc/poche/config.inc.php | 7 | ||||
-rw-r--r-- | inc/store/file.class.php | 47 | ||||
-rw-r--r-- | inc/store/mysql.class.php | 195 | ||||
-rw-r--r-- | inc/store/store.class.php | 55 | ||||
-rw-r--r-- | tpl/_footer.twig | 1 |
9 files changed, 219 insertions, 503 deletions
diff --git a/inc/3rdparty/paginator.php b/inc/3rdparty/paginator.php index e8801555..306756c0 100644 --- a/inc/3rdparty/paginator.php +++ b/inc/3rdparty/paginator.php | |||
@@ -9,99 +9,103 @@ | |||
9 | class Paginator{ | 9 | class Paginator{ |
10 | 10 | ||
11 | /** | 11 | /** |
12 | * set the number of items per page. | 12 | * set the number of items per page. |
13 | * | 13 | * |
14 | * @var numeric | 14 | * @var numeric |
15 | */ | 15 | */ |
16 | private $_perPage; | 16 | private $_perPage; |
17 | 17 | ||
18 | /** | 18 | /** |
19 | * set get parameter for fetching the page number | 19 | * set get parameter for fetching the page number |
20 | * | 20 | * |
21 | * @var string | 21 | * @var string |
22 | */ | 22 | */ |
23 | private $_instance; | 23 | private $_instance; |
24 | 24 | ||
25 | /** | 25 | /** |
26 | * sets the page number. | 26 | * sets the page number. |
27 | * | 27 | * |
28 | * @var numeric | 28 | * @var numeric |
29 | */ | 29 | */ |
30 | private $_page; | 30 | private $_page; |
31 | 31 | ||
32 | /** | 32 | /** |
33 | * set the limit for the data source | 33 | * set the limit for the data source |
34 | * | 34 | * |
35 | * @var string | 35 | * @var string |
36 | */ | 36 | */ |
37 | private $_limit; | 37 | private $_limit; |
38 | 38 | ||
39 | /** | 39 | /** |
40 | * set the total number of records/items. | 40 | * set the total number of records/items. |
41 | * | 41 | * |
42 | * @var numeric | 42 | * @var numeric |
43 | */ | 43 | */ |
44 | private $_totalRows = 0; | 44 | private $_totalRows = 0; |
45 | 45 | ||
46 | 46 | ||
47 | 47 | ||
48 | /** | 48 | /** |
49 | * __construct | 49 | * __construct |
50 | * | 50 | * |
51 | * pass values when class is istantiated | 51 | * pass values when class is istantiated |
52 | * | 52 | * |
53 | * @param numeric $_perPage sets the number of iteems per page | 53 | * @param numeric $_perPage sets the number of iteems per page |
54 | * @param numeric $_instance sets the instance for the GET parameter | 54 | * @param numeric $_instance sets the instance for the GET parameter |
55 | */ | 55 | */ |
56 | public function __construct($perPage,$instance){ | 56 | public function __construct($perPage,$instance){ |
57 | $this->_instance = $instance; | 57 | $this->_instance = $instance; |
58 | $this->_perPage = $perPage; | 58 | $this->_perPage = $perPage; |
59 | $this->set_instance(); | 59 | $this->set_instance(); |
60 | } | 60 | } |
61 | 61 | ||
62 | /** | 62 | /** |
63 | * get_start | 63 | * get_start |
64 | * | 64 | * |
65 | * creates the starting point for limiting the dataset | 65 | * creates the starting point for limiting the dataset |
66 | * @return numeric | 66 | * @return numeric |
67 | */ | 67 | */ |
68 | private function get_start(){ | 68 | private function get_start(){ |
69 | return ($this->_page * $this->_perPage) - $this->_perPage; | 69 | return ($this->_page * $this->_perPage) - $this->_perPage; |
70 | } | 70 | } |
71 | 71 | ||
72 | /** | 72 | /** |
73 | * set_instance | 73 | * set_instance |
74 | * | 74 | * |
75 | * sets the instance parameter, if numeric value is 0 then set to 1 | 75 | * sets the instance parameter, if numeric value is 0 then set to 1 |
76 | * | 76 | * |
77 | * @var numeric | 77 | * @var numeric |
78 | */ | 78 | */ |
79 | private function set_instance(){ | 79 | private function set_instance(){ |
80 | $this->_page = (int) (!isset($_GET[$this->_instance]) ? 1 : $_GET[$this->_instance]); | 80 | $this->_page = (int) (!isset($_GET[$this->_instance]) ? 1 : $_GET[$this->_instance]); |
81 | $this->_page = ($this->_page == 0 ? 1 : $this->_page); | 81 | $this->_page = ($this->_page == 0 ? 1 : $this->_page); |
82 | } | 82 | } |
83 | 83 | ||
84 | /** | 84 | /** |
85 | * set_total | 85 | * set_total |
86 | * | 86 | * |
87 | * collect a numberic value and assigns it to the totalRows | 87 | * collect a numberic value and assigns it to the totalRows |
88 | * | 88 | * |
89 | * @var numeric | 89 | * @var numeric |
90 | */ | 90 | */ |
91 | public function set_total($_totalRows){ | 91 | public function set_total($_totalRows){ |
92 | $this->_totalRows = $_totalRows; | 92 | $this->_totalRows = $_totalRows; |
93 | } | 93 | } |
94 | 94 | ||
95 | /** | 95 | /** |
96 | * get_limit | 96 | * get_limit |
97 | * | 97 | * |
98 | * returns the limit for the data source, calling the get_start method and passing in the number of items perp page | 98 | * returns the limit for the data source, calling the get_start method and passing in the number of items perp page |
99 | * | 99 | * |
100 | * @return string | 100 | * @return string |
101 | */ | 101 | */ |
102 | public function get_limit(){ | 102 | public function get_limit(){ |
103 | return "LIMIT ".$this->get_start().",$this->_perPage"; | 103 | if (STORAGE == 'postgres') { |
104 | return "LIMIT ".$this->_perPage." OFFSET ".$this->get_start(); | ||
105 | } else { | ||
106 | return "LIMIT ".$this->get_start().",".$this->_perPage; | ||
104 | } | 107 | } |
108 | } | ||
105 | 109 | ||
106 | /** | 110 | /** |
107 | * page_links | 111 | * page_links |
@@ -112,87 +116,87 @@ class Paginator{ | |||
112 | * @var sting $ext optionally pass in extra parameters to the GET | 116 | * @var sting $ext optionally pass in extra parameters to the GET |
113 | * @return string returns the html menu | 117 | * @return string returns the html menu |
114 | */ | 118 | */ |
115 | public function page_links($path='?',$ext=null) | 119 | public function page_links($path='?',$ext=null) |
116 | { | 120 | { |
117 | $adjacents = "2"; | 121 | $adjacents = "2"; |
118 | $prev = $this->_page - 1; | 122 | $prev = $this->_page - 1; |
119 | $next = $this->_page + 1; | 123 | $next = $this->_page + 1; |
120 | $lastpage = ceil($this->_totalRows/$this->_perPage); | 124 | $lastpage = ceil($this->_totalRows/$this->_perPage); |
121 | $lpm1 = $lastpage - 1; | 125 | $lpm1 = $lastpage - 1; |
122 | 126 | ||
123 | $pagination = ""; | 127 | $pagination = ""; |
124 | if($lastpage > 1) | 128 | if($lastpage > 1) |
125 | { | 129 | { |
126 | $pagination .= "<div class='pagination'>"; | 130 | $pagination .= "<div class='pagination'>"; |
127 | if ($this->_page > 1) | 131 | if ($this->_page > 1) |
128 | $pagination.= "<a href='".$path."$this->_instance=$prev"."$ext'>« previous</a>"; | 132 | $pagination.= "<a href='".$path."$this->_instance=$prev"."$ext'>« previous</a>"; |
129 | else | 133 | else |
130 | $pagination.= "<span class='disabled'>« previous</span>"; | 134 | $pagination.= "<span class='disabled'>« previous</span>"; |
131 | 135 | ||
132 | if ($lastpage < 7 + ($adjacents * 2)) | 136 | if ($lastpage < 7 + ($adjacents * 2)) |
133 | { | 137 | { |
134 | for ($counter = 1; $counter <= $lastpage; $counter++) | 138 | for ($counter = 1; $counter <= $lastpage; $counter++) |
135 | { | 139 | { |
136 | if ($counter == $this->_page) | 140 | if ($counter == $this->_page) |
137 | $pagination.= "<span class='current'>$counter</span>"; | 141 | $pagination.= "<span class='current'>$counter</span>"; |
138 | else | 142 | else |
139 | $pagination.= "<a href='".$path."$this->_instance=$counter"."$ext'>$counter</a>"; | 143 | $pagination.= "<a href='".$path."$this->_instance=$counter"."$ext'>$counter</a>"; |
140 | } | 144 | } |
141 | } | 145 | } |
142 | elseif($lastpage > 5 + ($adjacents * 2)) | 146 | elseif($lastpage > 5 + ($adjacents * 2)) |
143 | { | 147 | { |
144 | if($this->_page < 1 + ($adjacents * 2)) | 148 | if($this->_page < 1 + ($adjacents * 2)) |
145 | { | 149 | { |
146 | for ($counter = 1; $counter < 4 + ($adjacents * 2); $counter++) | 150 | for ($counter = 1; $counter < 4 + ($adjacents * 2); $counter++) |
147 | { | 151 | { |
148 | if ($counter == $this->_page) | 152 | if ($counter == $this->_page) |
149 | $pagination.= "<span class='current'>$counter</span>"; | 153 | $pagination.= "<span class='current'>$counter</span>"; |
150 | else | 154 | else |
151 | $pagination.= "<a href='".$path."$this->_instance=$counter"."$ext'>$counter</a>"; | 155 | $pagination.= "<a href='".$path."$this->_instance=$counter"."$ext'>$counter</a>"; |
152 | } | 156 | } |
153 | $pagination.= "..."; | 157 | $pagination.= "..."; |
154 | $pagination.= "<a href='".$path."$this->_instance=$lpm1"."$ext'>$lpm1</a>"; | 158 | $pagination.= "<a href='".$path."$this->_instance=$lpm1"."$ext'>$lpm1</a>"; |
155 | $pagination.= "<a href='".$path."$this->_instance=$lastpage"."$ext'>$lastpage</a>"; | 159 | $pagination.= "<a href='".$path."$this->_instance=$lastpage"."$ext'>$lastpage</a>"; |
156 | } | 160 | } |
157 | elseif($lastpage - ($adjacents * 2) > $this->_page && $this->_page > ($adjacents * 2)) | 161 | elseif($lastpage - ($adjacents * 2) > $this->_page && $this->_page > ($adjacents * 2)) |
158 | { | 162 | { |
159 | $pagination.= "<a href='".$path."$this->_instance=1"."$ext'>1</a>"; | 163 | $pagination.= "<a href='".$path."$this->_instance=1"."$ext'>1</a>"; |
160 | $pagination.= "<a href='".$path."$this->_instance=2"."$ext'>2</a>"; | 164 | $pagination.= "<a href='".$path."$this->_instance=2"."$ext'>2</a>"; |
161 | $pagination.= "..."; | 165 | $pagination.= "..."; |
162 | for ($counter = $this->_page - $adjacents; $counter <= $this->_page + $adjacents; $counter++) | 166 | for ($counter = $this->_page - $adjacents; $counter <= $this->_page + $adjacents; $counter++) |
163 | { | 167 | { |
164 | if ($counter == $this->_page) | 168 | if ($counter == $this->_page) |
165 | $pagination.= "<span class='current'>$counter</span>"; | 169 | $pagination.= "<span class='current'>$counter</span>"; |
166 | else | 170 | else |
167 | $pagination.= "<a href='".$path."$this->_instance=$counter"."$ext'>$counter</a>"; | 171 | $pagination.= "<a href='".$path."$this->_instance=$counter"."$ext'>$counter</a>"; |
168 | } | 172 | } |
169 | $pagination.= ".."; | 173 | $pagination.= ".."; |
170 | $pagination.= "<a href='".$path."$this->_instance=$lpm1"."$ext'>$lpm1</a>"; | 174 | $pagination.= "<a href='".$path."$this->_instance=$lpm1"."$ext'>$lpm1</a>"; |
171 | $pagination.= "<a href='".$path."$this->_instance=$lastpage"."$ext'>$lastpage</a>"; | 175 | $pagination.= "<a href='".$path."$this->_instance=$lastpage"."$ext'>$lastpage</a>"; |
172 | } | 176 | } |
173 | else | 177 | else |
174 | { | 178 | { |
175 | $pagination.= "<a href='".$path."$this->_instance=1"."$ext'>1</a>"; | 179 | $pagination.= "<a href='".$path."$this->_instance=1"."$ext'>1</a>"; |
176 | $pagination.= "<a href='".$path."$this->_instance=2"."$ext'>2</a>"; | 180 | $pagination.= "<a href='".$path."$this->_instance=2"."$ext'>2</a>"; |
177 | $pagination.= ".."; | 181 | $pagination.= ".."; |
178 | for ($counter = $lastpage - (2 + ($adjacents * 2)); $counter <= $lastpage; $counter++) | 182 | for ($counter = $lastpage - (2 + ($adjacents * 2)); $counter <= $lastpage; $counter++) |
179 | { | 183 | { |
180 | if ($counter == $this->_page) | 184 | if ($counter == $this->_page) |
181 | $pagination.= "<span class='current'>$counter</span>"; | 185 | $pagination.= "<span class='current'>$counter</span>"; |
182 | else | 186 | else |
183 | $pagination.= "<a href='".$path."$this->_instance=$counter"."$ext'>$counter</a>"; | 187 | $pagination.= "<a href='".$path."$this->_instance=$counter"."$ext'>$counter</a>"; |
184 | } | 188 | } |
185 | } | 189 | } |
186 | } | 190 | } |
187 | 191 | ||
188 | if ($this->_page < $counter - 1) | 192 | if ($this->_page < $counter - 1) |
189 | $pagination.= "<a href='".$path."$this->_instance=$next"."$ext'>next »</a>"; | 193 | $pagination.= "<a href='".$path."$this->_instance=$next"."$ext'>next »</a>"; |
190 | else | 194 | else |
191 | $pagination.= "<span class='disabled'>next »</span>"; | 195 | $pagination.= "<span class='disabled'>next »</span>"; |
192 | $pagination.= "</div>\n"; | 196 | $pagination.= "</div>\n"; |
193 | } | 197 | } |
194 | 198 | ||
195 | 199 | ||
196 | return $pagination; | 200 | return $pagination; |
197 | } | 201 | } |
198 | } | 202 | } |
diff --git a/inc/store/sqlite.class.php b/inc/poche/Database.class.php index 4c628dc1..a226b31e 100644 --- a/inc/store/sqlite.class.php +++ b/inc/poche/Database.class.php | |||
@@ -8,15 +8,25 @@ | |||
8 | * @license http://www.wtfpl.net/ see COPYING file | 8 | * @license http://www.wtfpl.net/ see COPYING file |
9 | */ | 9 | */ |
10 | 10 | ||
11 | class Sqlite extends Store { | 11 | class Database { |
12 | |||
13 | #postgresql | ||
14 | public static $db_path = 'pgsql:host=localhost;dbname=poche'; | ||
15 | public static $user = 'postgres'; | ||
16 | public static $password = 'postgres'; | ||
17 | #sqlite | ||
18 | // public static $db_path = 'sqlite:./db/poche.sqlite'; | ||
19 | // public static $user = ''; | ||
20 | // public static $password = ''; | ||
21 | #mysql | ||
22 | // public static $db_path = 'mysql:host=localhost;dbname=poche'; | ||
23 | // public static $user = 'root'; | ||
24 | // public static $password = 'root'; | ||
12 | 25 | ||
13 | public static $db_path = 'sqlite:./db/poche.sqlite'; | ||
14 | var $handle; | 26 | var $handle; |
15 | 27 | ||
16 | function __construct() { | 28 | function __construct() { |
17 | parent::__construct(); | 29 | $this->handle = new PDO(self::$db_path, self::$user, self::$password); |
18 | |||
19 | $this->handle = new PDO(self::$db_path); | ||
20 | $this->handle->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); | 30 | $this->handle->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); |
21 | } | 31 | } |
22 | 32 | ||
@@ -91,6 +101,7 @@ class Sqlite extends Store { | |||
91 | catch (Exception $e) | 101 | catch (Exception $e) |
92 | { | 102 | { |
93 | Tools::logm('execute query error : '.$e->getMessage()); | 103 | Tools::logm('execute query error : '.$e->getMessage()); |
104 | return FALSE; | ||
94 | } | 105 | } |
95 | } | 106 | } |
96 | 107 | ||
@@ -103,8 +114,6 @@ class Sqlite extends Store { | |||
103 | } | 114 | } |
104 | 115 | ||
105 | public function retrieveOneById($id, $user_id) { | 116 | public function retrieveOneById($id, $user_id) { |
106 | parent::__construct(); | ||
107 | |||
108 | $entry = NULL; | 117 | $entry = NULL; |
109 | $sql = "SELECT * FROM entries WHERE id=? AND user_id=?"; | 118 | $sql = "SELECT * FROM entries WHERE id=? AND user_id=?"; |
110 | $params = array(intval($id), $user_id); | 119 | $params = array(intval($id), $user_id); |
@@ -115,8 +124,6 @@ class Sqlite extends Store { | |||
115 | } | 124 | } |
116 | 125 | ||
117 | public function getEntriesByView($view, $user_id, $limit = '') { | 126 | public function getEntriesByView($view, $user_id, $limit = '') { |
118 | parent::__construct(); | ||
119 | |||
120 | switch ($_SESSION['sort']) | 127 | switch ($_SESSION['sort']) |
121 | { | 128 | { |
122 | case 'ia': | 129 | case 'ia': |
@@ -140,11 +147,11 @@ class Sqlite extends Store { | |||
140 | { | 147 | { |
141 | case 'archive': | 148 | case 'archive': |
142 | $sql = "SELECT * FROM entries WHERE user_id=? AND is_read=? " . $order; | 149 | $sql = "SELECT * FROM entries WHERE user_id=? AND is_read=? " . $order; |
143 | $params = array($user_id, -1); | 150 | $params = array($user_id, 1); |
144 | break; | 151 | break; |
145 | case 'fav' : | 152 | case 'fav' : |
146 | $sql = "SELECT * FROM entries WHERE user_id=? AND is_fav=? " . $order; | 153 | $sql = "SELECT * FROM entries WHERE user_id=? AND is_fav=? " . $order; |
147 | $params = array($user_id, -1); | 154 | $params = array($user_id, 1); |
148 | break; | 155 | break; |
149 | default: | 156 | default: |
150 | $sql = "SELECT * FROM entries WHERE user_id=? AND is_read=? " . $order; | 157 | $sql = "SELECT * FROM entries WHERE user_id=? AND is_read=? " . $order; |
@@ -161,7 +168,6 @@ class Sqlite extends Store { | |||
161 | } | 168 | } |
162 | 169 | ||
163 | public function add($url, $title, $content, $user_id) { | 170 | public function add($url, $title, $content, $user_id) { |
164 | parent::__construct(); | ||
165 | $sql_action = 'INSERT INTO entries ( url, title, content, user_id ) VALUES (?, ?, ?, ?)'; | 171 | $sql_action = 'INSERT INTO entries ( url, title, content, user_id ) VALUES (?, ?, ?, ?)'; |
166 | $params_action = array($url, $title, $content, $user_id); | 172 | $params_action = array($url, $title, $content, $user_id); |
167 | $query = $this->executeQuery($sql_action, $params_action); | 173 | $query = $this->executeQuery($sql_action, $params_action); |
@@ -169,7 +175,6 @@ class Sqlite extends Store { | |||
169 | } | 175 | } |
170 | 176 | ||
171 | public function deleteById($id, $user_id) { | 177 | public function deleteById($id, $user_id) { |
172 | parent::__construct(); | ||
173 | $sql_action = "DELETE FROM entries WHERE id=? AND user_id=?"; | 178 | $sql_action = "DELETE FROM entries WHERE id=? AND user_id=?"; |
174 | $params_action = array($id, $user_id); | 179 | $params_action = array($id, $user_id); |
175 | $query = $this->executeQuery($sql_action, $params_action); | 180 | $query = $this->executeQuery($sql_action, $params_action); |
@@ -177,21 +182,18 @@ class Sqlite extends Store { | |||
177 | } | 182 | } |
178 | 183 | ||
179 | public function favoriteById($id, $user_id) { | 184 | public function favoriteById($id, $user_id) { |
180 | parent::__construct(); | 185 | $sql_action = "UPDATE entries SET is_fav=NOT is_fav WHERE id=? AND user_id=?"; |
181 | $sql_action = "UPDATE entries SET is_fav=~is_fav WHERE id=? AND user_id=?"; | ||
182 | $params_action = array($id, $user_id); | 186 | $params_action = array($id, $user_id); |
183 | $query = $this->executeQuery($sql_action, $params_action); | 187 | $query = $this->executeQuery($sql_action, $params_action); |
184 | } | 188 | } |
185 | 189 | ||
186 | public function archiveById($id, $user_id) { | 190 | public function archiveById($id, $user_id) { |
187 | parent::__construct(); | 191 | $sql_action = "UPDATE entries SET is_read=NOT is_read WHERE id=? AND user_id=?"; |
188 | $sql_action = "UPDATE entries SET is_read=~is_read WHERE id=? AND user_id=?"; | ||
189 | $params_action = array($id, $user_id); | 192 | $params_action = array($id, $user_id); |
190 | $query = $this->executeQuery($sql_action, $params_action); | 193 | $query = $this->executeQuery($sql_action, $params_action); |
191 | } | 194 | } |
192 | 195 | ||
193 | public function getLastId() { | 196 | public function getLastId() { |
194 | parent::__construct(); | ||
195 | return $this->getHandle()->lastInsertId(); | 197 | return $this->getHandle()->lastInsertId(); |
196 | } | 198 | } |
197 | } | 199 | } |
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 | |||
16 | public $messages; | 16 | public $messages; |
17 | public $pagination; | 17 | public $pagination; |
18 | 18 | ||
19 | function __construct($storage_type) | 19 | function __construct() |
20 | { | 20 | { |
21 | $this->store = new $storage_type(); | 21 | $this->store = new Database(); |
22 | $this->init(); | 22 | $this->init(); |
23 | $this->messages = new Messages(); | 23 | $this->messages = new Messages(); |
24 | 24 | ||
@@ -52,9 +52,13 @@ class Poche | |||
52 | 52 | ||
53 | # template engine | 53 | # template engine |
54 | $loader = new Twig_Loader_Filesystem(TPL); | 54 | $loader = new Twig_Loader_Filesystem(TPL); |
55 | $this->tpl = new Twig_Environment($loader, array( | 55 | if (DEBUG_POCHE) { |
56 | 'cache' => CACHE, | 56 | $twig_params = array(); |
57 | )); | 57 | } |
58 | else { | ||
59 | $twig_params = array('cache' => CACHE); | ||
60 | } | ||
61 | $this->tpl = new Twig_Environment($loader, $twig_params); | ||
58 | $this->tpl->addExtension(new Twig_Extensions_Extension_I18n()); | 62 | $this->tpl->addExtension(new Twig_Extensions_Extension_I18n()); |
59 | # filter to display domain name of an url | 63 | # filter to display domain name of an url |
60 | $filter = new Twig_SimpleFilter('getDomain', 'Tools::getDomain'); | 64 | $filter = new Twig_SimpleFilter('getDomain', 'Tools::getDomain'); |
@@ -124,18 +128,19 @@ class Poche | |||
124 | Tools::redirect(); | 128 | Tools::redirect(); |
125 | break; | 129 | break; |
126 | case 'delete': | 130 | case 'delete': |
131 | $msg = 'delete link #' . $id; | ||
127 | if ($this->store->deleteById($id, $this->user->getId())) { | 132 | if ($this->store->deleteById($id, $this->user->getId())) { |
128 | if (DOWNLOAD_PICTURES) { | 133 | if (DOWNLOAD_PICTURES) { |
129 | remove_directory(ABS_PATH . $id); | 134 | remove_directory(ABS_PATH . $id); |
130 | } | 135 | } |
131 | $this->messages->add('s', _('the link has been deleted successfully')); | 136 | $this->messages->add('s', _('the link has been deleted successfully')); |
132 | Tools::logm('delete link #' . $id); | ||
133 | } | 137 | } |
134 | else { | 138 | else { |
135 | $this->messages->add('e', _('the link wasn\'t deleted')); | 139 | $this->messages->add('e', _('the link wasn\'t deleted')); |
136 | Tools::logm('error : can\'t delete link #' . $id); | 140 | $msg = 'error : can\'t delete link #' . $id; |
137 | } | 141 | } |
138 | Tools::redirect(); | 142 | Tools::logm($msg); |
143 | Tools::redirect('?'); | ||
139 | break; | 144 | break; |
140 | case 'toggle_fav' : | 145 | case 'toggle_fav' : |
141 | $this->store->favoriteById($id, $this->user->getId()); | 146 | $this->store->favoriteById($id, $this->user->getId()); |
@@ -385,7 +390,7 @@ class Poche | |||
385 | if (file_exists($cache_file) && (filemtime($cache_file) > (time() - 86400 ))) { | 390 | if (file_exists($cache_file) && (filemtime($cache_file) > (time() - 86400 ))) { |
386 | $version = file_get_contents($cache_file); | 391 | $version = file_get_contents($cache_file); |
387 | } else { | 392 | } else { |
388 | $version = file_get_contents('http://www.inthepoche.com/' . $which); | 393 | $version = file_get_contents('http://static.inthepoche.com/versions/' . $which); |
389 | file_put_contents($cache_file, $version, LOCK_EX); | 394 | file_put_contents($cache_file, $version, LOCK_EX); |
390 | } | 395 | } |
391 | return $version; | 396 | 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 | |||
77 | $url = $ref; | 77 | $url = $ref; |
78 | } | 78 | } |
79 | } | 79 | } |
80 | self::logm('redirect to ' . $url); | ||
80 | header('Location: '.$url); | 81 | header('Location: '.$url); |
81 | exit(); | 82 | exit(); |
82 | } | 83 | } |
@@ -198,6 +199,7 @@ class Tools | |||
198 | if (DEBUG_POCHE) { | 199 | if (DEBUG_POCHE) { |
199 | $t = strval(date('Y/m/d_H:i:s')) . ' - ' . $_SERVER["REMOTE_ADDR"] . ' - ' . strval($message) . "\n"; | 200 | $t = strval(date('Y/m/d_H:i:s')) . ' - ' . $_SERVER["REMOTE_ADDR"] . ' - ' . strval($message) . "\n"; |
200 | file_put_contents(CACHE . '/log.txt', $t, FILE_APPEND); | 201 | file_put_contents(CACHE . '/log.txt', $t, FILE_APPEND); |
202 | error_log('DEBUG POCHE : ' . $message); | ||
201 | } | 203 | } |
202 | } | 204 | } |
203 | 205 | ||
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'); | |||
24 | define ('LANG', 'en_EN.UTF8'); | 24 | define ('LANG', 'en_EN.UTF8'); |
25 | define ('PAGINATION', '10'); | 25 | define ('PAGINATION', '10'); |
26 | define ('THEME', 'light'); | 26 | define ('THEME', 'light'); |
27 | $storage_type = 'sqlite'; # sqlite, mysql, (file, not yet) | 27 | define ('STORAGE','postgres'); # postgres, mysql, sqlite |
28 | 28 | ||
29 | # /!\ Be careful if you change the lines below /!\ | 29 | # /!\ Be careful if you change the lines below /!\ |
30 | require_once './inc/poche/User.class.php'; | 30 | require_once './inc/poche/User.class.php'; |
@@ -34,8 +34,7 @@ require_once './inc/3rdparty/class.messages.php'; | |||
34 | require_once './inc/poche/Poche.class.php'; | 34 | require_once './inc/poche/Poche.class.php'; |
35 | require_once './inc/3rdparty/Readability.php'; | 35 | require_once './inc/3rdparty/Readability.php'; |
36 | require_once './inc/3rdparty/Encoding.php'; | 36 | require_once './inc/3rdparty/Encoding.php'; |
37 | require_once './inc/store/store.class.php'; | 37 | require_once './inc/poche/Database.class.php'; |
38 | require_once './inc/store/' . $storage_type . '.class.php'; | ||
39 | require_once './vendor/autoload.php'; | 38 | require_once './vendor/autoload.php'; |
40 | require_once './inc/3rdparty/simple_html_dom.php'; | 39 | require_once './inc/3rdparty/simple_html_dom.php'; |
41 | require_once './inc/3rdparty/paginator.php'; | 40 | require_once './inc/3rdparty/paginator.php'; |
@@ -45,7 +44,7 @@ if (DOWNLOAD_PICTURES) { | |||
45 | require_once './inc/poche/pochePictures.php'; | 44 | require_once './inc/poche/pochePictures.php'; |
46 | } | 45 | } |
47 | 46 | ||
48 | $poche = new Poche($storage_type); | 47 | $poche = new Poche(); |
49 | 48 | ||
50 | #XSRF protection with token | 49 | #XSRF protection with token |
51 | // if (!empty($_POST)) { | 50 | // if (!empty($_POST)) { |
diff --git a/inc/store/file.class.php b/inc/store/file.class.php deleted file mode 100644 index c9d85dcc..00000000 --- a/inc/store/file.class.php +++ /dev/null | |||
@@ -1,47 +0,0 @@ | |||
1 | <?php | ||
2 | /** | ||
3 | * poche, a read it later open source system | ||
4 | * | ||
5 | * @category poche | ||
6 | * @author Nicolas Lœuillet <support@inthepoche.com> | ||
7 | * @copyright 2013 | ||
8 | * @license http://www.wtfpl.net/ see COPYING file | ||
9 | */ | ||
10 | |||
11 | class File extends Store { | ||
12 | function __construct() { | ||
13 | |||
14 | } | ||
15 | |||
16 | public function add() { | ||
17 | |||
18 | } | ||
19 | |||
20 | public function retrieveOneById($id) { | ||
21 | |||
22 | } | ||
23 | |||
24 | public function retrieveOneByURL($url) { | ||
25 | |||
26 | } | ||
27 | |||
28 | public function deleteById($id) { | ||
29 | |||
30 | } | ||
31 | |||
32 | public function favoriteById($id) { | ||
33 | |||
34 | } | ||
35 | |||
36 | public function archiveById($id) { | ||
37 | |||
38 | } | ||
39 | |||
40 | public function getEntriesByView($view) { | ||
41 | |||
42 | } | ||
43 | |||
44 | public function getLastId() { | ||
45 | |||
46 | } | ||
47 | } | ||
diff --git a/inc/store/mysql.class.php b/inc/store/mysql.class.php deleted file mode 100644 index 8b7f83da..00000000 --- a/inc/store/mysql.class.php +++ /dev/null | |||
@@ -1,195 +0,0 @@ | |||
1 | <?php | ||
2 | /** | ||
3 | * poche, a read it later open source system | ||
4 | * | ||
5 | * @category poche | ||
6 | * @author Nicolas Lœuillet <support@inthepoche.com> | ||
7 | * @copyright 2013 | ||
8 | * @license http://www.wtfpl.net/ see COPYING file | ||
9 | */ | ||
10 | |||
11 | class Mysql extends Store { | ||
12 | |||
13 | public static $db_path = 'mysql:host=localhost;dbname=poche'; | ||
14 | public static $user = 'root'; | ||
15 | public static $password = 'root'; | ||
16 | var $handle; | ||
17 | |||
18 | function __construct() { | ||
19 | parent::__construct(); | ||
20 | |||
21 | $this->handle = new PDO(self::$db_path, self::$user, self::$password); | ||
22 | $this->handle->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); | ||
23 | } | ||
24 | |||
25 | private function getHandle() { | ||
26 | return $this->handle; | ||
27 | } | ||
28 | |||
29 | public function isInstalled() { | ||
30 | // $sql = "SELECT name FROM sqlite_sequence WHERE name=?"; | ||
31 | // $query = $this->executeQuery($sql, array('config')); | ||
32 | // $hasConfig = $query->fetchAll(); | ||
33 | |||
34 | // if (count($hasConfig) == 0) | ||
35 | // return FALSE; | ||
36 | |||
37 | // if (!$this->getLogin() || !$this->getPassword()) | ||
38 | // return FALSE; | ||
39 | |||
40 | return TRUE; | ||
41 | } | ||
42 | |||
43 | public function install($login, $password) { | ||
44 | $this->getHandle()->exec('CREATE TABLE IF NOT EXISTS "config" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL UNIQUE , "name" VARCHAR UNIQUE, "value" BLOB)'); | ||
45 | |||
46 | $this->handle->exec('CREATE TABLE IF NOT EXISTS "entries" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL UNIQUE , "title" VARCHAR, "url" VARCHAR UNIQUE , "is_read" INTEGER DEFAULT 0, "is_fav" INTEGER DEFAULT 0, "content" BLOB)'); | ||
47 | |||
48 | if (!$this->getLogin()) { | ||
49 | $sql_login = 'INSERT INTO config ( name, value ) VALUES (?, ?)'; | ||
50 | $params_login = array('login', $login); | ||
51 | $query = $this->executeQuery($sql_login, $params_login); | ||
52 | } | ||
53 | |||
54 | if (!$this->getPassword()) { | ||
55 | $sql_pass = 'INSERT INTO config ( name, value ) VALUES (?, ?)'; | ||
56 | $params_pass = array('password', $password); | ||
57 | $query = $this->executeQuery($sql_pass, $params_pass); | ||
58 | } | ||
59 | |||
60 | return TRUE; | ||
61 | } | ||
62 | |||
63 | public function getLogin() { | ||
64 | $sql = "SELECT value FROM config WHERE name=?"; | ||
65 | $query = $this->executeQuery($sql, array('login')); | ||
66 | $login = $query->fetchAll(); | ||
67 | |||
68 | return isset($login[0]['value']) ? $login[0]['value'] : FALSE; | ||
69 | } | ||
70 | |||
71 | public function getPassword() { | ||
72 | $sql = "SELECT value FROM config WHERE name=?"; | ||
73 | $query = $this->executeQuery($sql, array('password')); | ||
74 | $pass = $query->fetchAll(); | ||
75 | |||
76 | return isset($pass[0]['value']) ? $pass[0]['value'] : FALSE; | ||
77 | } | ||
78 | |||
79 | public function updatePassword($password) | ||
80 | { | ||
81 | $sql_update = "UPDATE config SET value=? WHERE name='password'"; | ||
82 | $params_update = array($password); | ||
83 | $query = $this->executeQuery($sql_update, $params_update); | ||
84 | } | ||
85 | |||
86 | private function executeQuery($sql, $params) { | ||
87 | try | ||
88 | { | ||
89 | $query = $this->getHandle()->prepare($sql); | ||
90 | $query->execute($params); | ||
91 | return $query; | ||
92 | } | ||
93 | catch (Exception $e) | ||
94 | { | ||
95 | Tools::logm('execute query error : '.$e->getMessage()); | ||
96 | } | ||
97 | } | ||
98 | |||
99 | public function retrieveAll() { | ||
100 | $sql = "SELECT * FROM entries ORDER BY id"; | ||
101 | $query = $this->executeQuery($sql, array()); | ||
102 | $entries = $query->fetchAll(); | ||
103 | |||
104 | return $entries; | ||
105 | } | ||
106 | |||
107 | public function retrieveOneById($id) { | ||
108 | parent::__construct(); | ||
109 | |||
110 | $entry = NULL; | ||
111 | $sql = "SELECT * FROM entries WHERE id=?"; | ||
112 | $params = array(intval($id)); | ||
113 | $query = $this->executeQuery($sql, $params); | ||
114 | $entry = $query->fetchAll(); | ||
115 | |||
116 | return $entry[0]; | ||
117 | } | ||
118 | |||
119 | public function getEntriesByView($view) { | ||
120 | parent::__construct(); | ||
121 | |||
122 | switch ($_SESSION['sort']) | ||
123 | { | ||
124 | case 'ia': | ||
125 | $order = 'ORDER BY id'; | ||
126 | break; | ||
127 | case 'id': | ||
128 | $order = 'ORDER BY id DESC'; | ||
129 | break; | ||
130 | case 'ta': | ||
131 | $order = 'ORDER BY lower(title)'; | ||
132 | break; | ||
133 | case 'td': | ||
134 | $order = 'ORDER BY lower(title) DESC'; | ||
135 | break; | ||
136 | default: | ||
137 | $order = 'ORDER BY id'; | ||
138 | break; | ||
139 | } | ||
140 | |||
141 | switch ($view) | ||
142 | { | ||
143 | case 'archive': | ||
144 | $sql = "SELECT * FROM entries WHERE is_read=? " . $order; | ||
145 | $params = array(1); | ||
146 | break; | ||
147 | case 'fav' : | ||
148 | $sql = "SELECT * FROM entries WHERE is_fav=? " . $order; | ||
149 | $params = array(1); | ||
150 | break; | ||
151 | default: | ||
152 | $sql = "SELECT * FROM entries WHERE is_read=? " . $order; | ||
153 | $params = array(0); | ||
154 | break; | ||
155 | } | ||
156 | |||
157 | $query = $this->executeQuery($sql, $params); | ||
158 | $entries = $query->fetchAll(); | ||
159 | |||
160 | return $entries; | ||
161 | } | ||
162 | |||
163 | public function add($url, $title, $content) { | ||
164 | parent::__construct(); | ||
165 | $sql_action = 'INSERT INTO entries ( url, title, content ) VALUES (?, ?, ?)'; | ||
166 | $params_action = array($url, $title, $content); | ||
167 | $query = $this->executeQuery($sql_action, $params_action); | ||
168 | return $query; | ||
169 | } | ||
170 | |||
171 | public function deleteById($id) { | ||
172 | parent::__construct(); | ||
173 | $sql_action = "DELETE FROM entries WHERE id=?"; | ||
174 | $params_action = array($id); | ||
175 | $query = $this->executeQuery($sql_action, $params_action); | ||
176 | return $query; | ||
177 | } | ||
178 | |||
179 | public function favoriteById($id) { | ||
180 | parent::__construct(); | ||
181 | $sql_action = "UPDATE entries SET is_fav = IF (is_fav, 0, 1)"; | ||
182 | $query = $this->executeQuery($sql_action, array()); | ||
183 | } | ||
184 | |||
185 | public function archiveById($id) { | ||
186 | parent::__construct(); | ||
187 | $sql_action = "UPDATE entries SET is_read = IF (is_read, 0, 1)"; | ||
188 | $query = $this->executeQuery($sql_action, array()); | ||
189 | } | ||
190 | |||
191 | public function getLastId() { | ||
192 | parent::__construct(); | ||
193 | return $this->getHandle()->lastInsertId(); | ||
194 | } | ||
195 | } | ||
diff --git a/inc/store/store.class.php b/inc/store/store.class.php deleted file mode 100644 index d6e63014..00000000 --- a/inc/store/store.class.php +++ /dev/null | |||
@@ -1,55 +0,0 @@ | |||
1 | <?php | ||
2 | /** | ||
3 | * poche, a read it later open source system | ||
4 | * | ||
5 | * @category poche | ||
6 | * @author Nicolas Lœuillet <support@inthepoche.com> | ||
7 | * @copyright 2013 | ||
8 | * @license http://www.wtfpl.net/ see COPYING file | ||
9 | */ | ||
10 | |||
11 | class Store { | ||
12 | function __construct() { | ||
13 | |||
14 | } | ||
15 | |||
16 | public function login() { | ||
17 | |||
18 | } | ||
19 | |||
20 | public function add() { | ||
21 | |||
22 | } | ||
23 | |||
24 | public function retrieveAll() { | ||
25 | |||
26 | } | ||
27 | |||
28 | public function retrieveOneById($id) { | ||
29 | |||
30 | } | ||
31 | |||
32 | public function retrieveOneByURL($url) { | ||
33 | |||
34 | } | ||
35 | |||
36 | public function deleteById($id) { | ||
37 | |||
38 | } | ||
39 | |||
40 | public function favoriteById($id) { | ||
41 | |||
42 | } | ||
43 | |||
44 | public function archiveById($id) { | ||
45 | |||
46 | } | ||
47 | |||
48 | public function getEntriesByView($view) { | ||
49 | |||
50 | } | ||
51 | |||
52 | public function getLastId() { | ||
53 | |||
54 | } | ||
55 | } | ||
diff --git a/tpl/_footer.twig b/tpl/_footer.twig index a541e6ee..b74d9079 100644 --- a/tpl/_footer.twig +++ b/tpl/_footer.twig | |||
@@ -1,3 +1,4 @@ | |||
1 | <footer class="w600p center mt3 smaller txtright"> | 1 | <footer class="w600p center mt3 smaller txtright"> |
2 | <p>{% trans "powered by" %} <a href="http://inthepoche.com">poche</a></p> | 2 | <p>{% trans "powered by" %} <a href="http://inthepoche.com">poche</a></p> |
3 | {% if constant('DEBUG_POCHE') == 1 %}<p><strong>{% trans "debug mode is on so cache is off." %} {% trans "your poche version:" %}{{constant('POCHE_VERSION')}}</strong></p>{% endif %} | ||
3 | </footer> \ No newline at end of file | 4 | </footer> \ No newline at end of file |