diff options
Diffstat (limited to 'index.php')
-rwxr-xr-x | index.php | 74 |
1 files changed, 34 insertions, 40 deletions
@@ -8,20 +8,6 @@ | |||
8 | * @license http://www.wtfpl.net/ see COPYING file | 8 | * @license http://www.wtfpl.net/ see COPYING file |
9 | */ | 9 | */ |
10 | 10 | ||
11 | /** | ||
12 | * TODO | ||
13 | * gestion des erreurs sqlite (duplicate tout ça) | ||
14 | * gérer si url vide | ||
15 | * traiter les variables passées en get | ||
16 | * récupérer le titre de la page pochée (cf readityourself.php) | ||
17 | * actions archive, fav et delete à traiter | ||
18 | * bookmarklet | ||
19 | * améliorer présentation des liens | ||
20 | * améliorer présentation d'un article | ||
21 | * aligner verticalement les icones d'action | ||
22 | * afficher liens mis en favoris et archivés | ||
23 | * tri des liens | ||
24 | */ | ||
25 | require_once dirname(__FILE__).'/inc/Readability.php'; | 11 | require_once dirname(__FILE__).'/inc/Readability.php'; |
26 | require_once dirname(__FILE__).'/inc/Encoding.php'; | 12 | require_once dirname(__FILE__).'/inc/Encoding.php'; |
27 | include dirname(__FILE__).'/inc/functions.php'; | 13 | include dirname(__FILE__).'/inc/functions.php'; |
@@ -37,22 +23,27 @@ catch (Exception $e) | |||
37 | } | 23 | } |
38 | 24 | ||
39 | $action = (isset ($_GET['action'])) ? htmlspecialchars($_GET['action']) : ''; | 25 | $action = (isset ($_GET['action'])) ? htmlspecialchars($_GET['action']) : ''; |
40 | $view = (isset ($_GET['view'])) ? htmlspecialchars($_GET['view']) : ''; | 26 | $view = (isset ($_GET['view'])) ? htmlspecialchars($_GET['view']) : ''; |
41 | $id = (isset ($_GET['id'])) ? htmlspecialchars($_GET['id']) : ''; | 27 | $in = (isset ($_GET['id'])) ? htmlspecialchars($_GET['id']) : ''; |
42 | 28 | ||
43 | switch ($action) { | 29 | switch ($action) |
30 | { | ||
44 | case 'add': | 31 | case 'add': |
45 | $url = (isset ($_GET['url'])) ? $_GET['url'] : ''; | 32 | $url = (isset ($_GET['url'])) ? $_GET['url'] : ''; |
46 | $url = html_entity_decode(trim($url)); | 33 | if ($url == '') |
47 | $title = $url; | 34 | continue; |
48 | // if url use https protocol change it to http | 35 | |
49 | if (!preg_match('!^https?://!i', $url)) $url = 'http://'.$url; | 36 | $url = html_entity_decode(trim($url)); |
50 | // convert page to utf-8 | 37 | $title = $url; |
38 | if (!preg_match('!^https?://!i', $url)) | ||
39 | $url = 'http://' . $url; | ||
40 | |||
51 | $html = Encoding::toUTF8(get_external_file($url,15)); | 41 | $html = Encoding::toUTF8(get_external_file($url,15)); |
52 | if(isset($html) and strlen($html) > 0) { | 42 | if (isset($html) and strlen($html) > 0) |
53 | // send result to readability library | 43 | { |
54 | $r = new Readability($html, $url); | 44 | $r = new Readability($html, $url); |
55 | if($r->init()) { | 45 | if($r->init()) |
46 | { | ||
56 | $title = $r->articleTitle->innerHTML; | 47 | $title = $r->articleTitle->innerHTML; |
57 | } | 48 | } |
58 | } | 49 | } |
@@ -61,16 +52,16 @@ switch ($action) { | |||
61 | $query->execute(array($url, $title)); | 52 | $query->execute(array($url, $title)); |
62 | break; | 53 | break; |
63 | case 'toggle_fav' : | 54 | case 'toggle_fav' : |
64 | $sql_action = "UPDATE entries SET is_fav=~is_fav WHERE id=?"; | 55 | $sql_action = "UPDATE entries SET is_fav=~is_fav WHERE id=?"; |
65 | $params_action = array($id); | 56 | $params_action = array($id); |
66 | break; | 57 | break; |
67 | case 'toggle_archive' : | 58 | case 'toggle_archive' : |
68 | $sql_action = "UPDATE entries SET is_read=~is_read WHERE id=?"; | 59 | $sql_action = "UPDATE entries SET is_read=~is_read WHERE id=?"; |
69 | $params_action = array($id); | 60 | $params_action = array($id); |
70 | break; | 61 | break; |
71 | case 'delete': | 62 | case 'delete': |
72 | $sql_action = "DELETE FROM entries WHERE id=?"; | 63 | $sql_action = "DELETE FROM entries WHERE id=?"; |
73 | $params_action = array($id); | 64 | $params_action = array($id); |
74 | break; | 65 | break; |
75 | default: | 66 | default: |
76 | break; | 67 | break; |
@@ -79,7 +70,8 @@ switch ($action) { | |||
79 | try | 70 | try |
80 | { | 71 | { |
81 | # action query | 72 | # action query |
82 | if (isset($sql_action)) { | 73 | if (isset($sql_action)) |
74 | { | ||
83 | $query = $db_handle->prepare($sql_action); | 75 | $query = $db_handle->prepare($sql_action); |
84 | $query->execute($params_action); | 76 | $query->execute($params_action); |
85 | } | 77 | } |
@@ -89,17 +81,18 @@ catch (Exception $e) | |||
89 | die('query error : '.$e->getMessage()); | 81 | die('query error : '.$e->getMessage()); |
90 | } | 82 | } |
91 | 83 | ||
92 | switch ($view) { | 84 | switch ($view) |
85 | { | ||
93 | case 'archive': | 86 | case 'archive': |
94 | $sql = "SELECT * FROM entries WHERE is_read=?"; | 87 | $sql = "SELECT * FROM entries WHERE is_read=?"; |
95 | $params = array(-1); | 88 | $params = array(-1); |
96 | break; | 89 | break; |
97 | case 'fav' : | 90 | case 'fav' : |
98 | $sql = "SELECT * FROM entries WHERE is_fav=?"; | 91 | $sql = "SELECT * FROM entries WHERE is_fav=?"; |
99 | $params = array(-1); | 92 | $params = array(-1); |
100 | break; | 93 | break; |
101 | default: | 94 | default: |
102 | $sql = "SELECT * FROM entries WHERE is_read=?"; | 95 | $sql = "SELECT * FROM entries WHERE is_read=?"; |
103 | $params = array(0); | 96 | $params = array(0); |
104 | break; | 97 | break; |
105 | } | 98 | } |
@@ -107,7 +100,7 @@ switch ($view) { | |||
107 | # view query | 100 | # view query |
108 | try | 101 | try |
109 | { | 102 | { |
110 | $query = $db_handle->prepare($sql); | 103 | $query = $db_handle->prepare($sql); |
111 | $query->execute($params); | 104 | $query->execute($params); |
112 | $entries = $query->fetchAll(); | 105 | $entries = $query->fetchAll(); |
113 | } | 106 | } |
@@ -127,13 +120,13 @@ catch (Exception $e) | |||
127 | <meta name="viewport" content="width=device-width, minimum-scale=1.0, maximum-scale=1.0"> | 120 | <meta name="viewport" content="width=device-width, minimum-scale=1.0, maximum-scale=1.0"> |
128 | <meta charset="utf-8"> | 121 | <meta charset="utf-8"> |
129 | <meta http-equiv="X-UA-Compatible" content="IE=10"> | 122 | <meta http-equiv="X-UA-Compatible" content="IE=10"> |
130 | <title>poche : queue</title> | 123 | <title>poche, a read it later open source system</title> |
131 | <link rel="stylesheet" href="css/knacss.css" media="all"> | 124 | <link rel="stylesheet" href="css/knacss.css" media="all"> |
132 | <link rel="stylesheet" href="css/style.css" media="all"> | 125 | <link rel="stylesheet" href="css/style.css" media="all"> |
133 | </head> | 126 | </head> |
134 | <body> | 127 | <body> |
135 | <header> | 128 | <header> |
136 | <h1><img src="img/logo.png" alt="logo poche" />poche, a read it later open source system</h1> | 129 | <h1><img src="img/logo.png" alt="logo poche" />poche</h1> |
137 | </header> | 130 | </header> |
138 | <div id="main" class="w800p"> | 131 | <div id="main" class="w800p"> |
139 | <ul id="links"> | 132 | <ul id="links"> |
@@ -144,7 +137,8 @@ catch (Exception $e) | |||
144 | </ul> | 137 | </ul> |
145 | <ul id="entries"> | 138 | <ul id="entries"> |
146 | <?php | 139 | <?php |
147 | foreach ($entries as $entry) { | 140 | foreach ($entries as $entry) |
141 | { | ||
148 | echo '<li><a href="readityourself.php?url='.urlencode($entry['url']).'">' . $entry['title'] . '</a> <a href="?action=toggle_archive&id='.$entry['id'].'" title="toggle mark as read" class="tool">✓</a> <a href="?action=toggle_fav&id='.$entry['id'].'" title="toggle favorite" class="tool">'.(($entry['is_fav'] == 0) ? '☆' : '★' ).'</a> <a href="?action=delete&id='.$entry['id'].'" title="toggle delete" class="tool">⨯</a></li>'; | 142 | echo '<li><a href="readityourself.php?url='.urlencode($entry['url']).'">' . $entry['title'] . '</a> <a href="?action=toggle_archive&id='.$entry['id'].'" title="toggle mark as read" class="tool">✓</a> <a href="?action=toggle_fav&id='.$entry['id'].'" title="toggle favorite" class="tool">'.(($entry['is_fav'] == 0) ? '☆' : '★' ).'</a> <a href="?action=delete&id='.$entry['id'].'" title="toggle delete" class="tool">⨯</a></li>'; |
149 | } | 143 | } |
150 | ?> | 144 | ?> |