]>
Commit | Line | Data |
---|---|---|
1a268ba7 NL |
1 | <?php |
2 | /** | |
3 | * poche, a read it later open source system | |
4 | * | |
5 | * @category poche | |
6 | * @author Nicolas Lœuillet <nicolas@loeuillet.org> | |
7 | * @copyright 2013 | |
8 | * @license http://www.wtfpl.net/ see COPYING file | |
9 | */ | |
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 | ||
26 | try | |
27 | { | |
a590ea55 | 28 | $db_handle = new PDO('sqlite:db/poche.sqlite'); |
1a268ba7 NL |
29 | $db_handle->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); |
30 | } | |
31 | catch (Exception $e) | |
32 | { | |
5917f419 | 33 | die('database error : '.$e->getMessage()); |
1a268ba7 NL |
34 | } |
35 | ||
36 | $action = (isset ($_GET['action'])) ? htmlspecialchars($_GET['action']) : ''; | |
5917f419 | 37 | $view = (isset ($_GET['view'])) ? htmlspecialchars($_GET['view']) : ''; |
38 | $id = (isset ($_GET['id'])) ? htmlspecialchars($_GET['id']) : ''; | |
1a268ba7 NL |
39 | |
40 | switch ($action) { | |
41 | case 'add': | |
42 | $url = (isset ($_GET['url'])) ? htmlspecialchars($_GET['url']) : ''; | |
43 | $title = $url; | |
44 | $query = $db_handle->prepare('INSERT INTO entries ( url, title ) VALUES (?, ?)'); | |
45 | $query->execute(array($url, $title)); | |
46 | break; | |
5917f419 | 47 | case 'toggle_fav' : |
48 | $sql_action = "UPDATE entries SET is_fav=~is_fav WHERE id=?"; | |
49 | $params_action = array($id); | |
1a268ba7 | 50 | break; |
5917f419 | 51 | case 'toggle_archive' : |
52 | $sql_action = "UPDATE entries SET is_read=~is_read WHERE id=?"; | |
53 | $params_action = array($id); | |
1a268ba7 NL |
54 | break; |
55 | case 'delete': | |
56 | break; | |
57 | default: | |
58 | break; | |
59 | } | |
c4fb6f01 | 60 | |
5917f419 | 61 | try |
62 | { | |
63 | # action query | |
64 | if (isset($sql_action)) { | |
65 | $query = $db_handle->prepare($sql_action); | |
66 | $query->execute($params_action); | |
67 | } | |
68 | } | |
69 | catch (Exception $e) | |
70 | { | |
71 | die('query error : '.$e->getMessage()); | |
72 | } | |
73 | ||
74 | switch ($view) { | |
75 | case 'archive': | |
76 | $sql = "SELECT * FROM entries WHERE is_read=?"; | |
77 | $params = array(-1); | |
78 | break; | |
79 | case 'fav' : | |
80 | $sql = "SELECT * FROM entries WHERE is_fav=?"; | |
81 | $params = array(-1); | |
82 | break; | |
83 | default: | |
84 | $sql = "SELECT * FROM entries WHERE is_read=?"; | |
85 | $params = array(0); | |
86 | break; | |
87 | } | |
88 | ||
89 | # view query | |
90 | try | |
91 | { | |
92 | $query = $db_handle->prepare($sql); | |
93 | $query->execute($params); | |
94 | $entries = $query->fetchAll(); | |
95 | } | |
96 | catch (Exception $e) | |
97 | { | |
98 | die('query error : '.$e->getMessage()); | |
99 | } | |
100 | ||
101 | function url() { | |
102 | $protocol = "http"; | |
103 | if(isset($_SERVER['HTTPS'])) { | |
104 | if($_SERVER['HTTPS'] != "off") { | |
105 | $protocol = "https"; | |
106 | } | |
107 | } | |
108 | ||
109 | return $protocol . "://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; | |
c4fb6f01 | 110 | } |
1a268ba7 NL |
111 | ?> |
112 | <!DOCTYPE html> | |
113 | <!--[if lte IE 6]> <html class="no-js ie6 ie67 ie678" lang="en"> <![endif]--> | |
114 | <!--[if lte IE 7]> <html class="no-js ie7 ie67 ie678" lang="en"> <![endif]--> | |
115 | <!--[if IE 8]> <html class="no-js ie8 ie678" lang="en"> <![endif]--> | |
116 | <!--[if gt IE 8]><!--> <html class="no-js" lang="en"> <!--<![endif]--> | |
117 | <html> | |
118 | <head> | |
119 | <meta name="viewport" content="width=device-width, minimum-scale=1.0, maximum-scale=1.0"> | |
120 | <meta charset="utf-8"> | |
121 | <meta http-equiv="X-UA-Compatible" content="IE=10"> | |
122 | <title>poche : queue</title> | |
123 | <link rel="stylesheet" href="css/knacss.css" media="all"> | |
124 | <link rel="stylesheet" href="css/style.css" media="all"> | |
125 | </head> | |
126 | <body> | |
5917f419 | 127 | <header> |
128 | <h1>poche, a read it later open source system</h1> | |
129 | </header> | |
130 | <div id="main" class="w800p"> | |
131 | <ul id="links"> | |
132 | <li><a href="index.php">home</a></li> | |
133 | <li><a href="?view=fav">favorites</a></li> | |
134 | <li><a href="?view=archive">archive</a></li> | |
135 | <li><a title="i am a bookmarklet, use me !" href="javascript:(function(){var%20url%20=%20location.href;var%20title%20=%20document.title%20||%20url;window.open('<?php echo url()?>?action=add&url='%20+%20encodeURIComponent(url),'_self');})();">poche it !</a></li> | |
136 | </ul> | |
137 | <ul id="entries"> | |
138 | <?php | |
139 | foreach ($entries as $entry) { | |
140 | 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="#" title="toggle delete" class="tool">⨯</a></li>'; | |
141 | } | |
142 | ?> | |
143 | </ul> | |
144 | </div> | |
145 | <footer class="mr2 mt3"> | |
c4fb6f01 | 146 | <p class="smaller"><a href="http://github.com/nicosomb/poche">poche</a> is a read it later open source system, based on <a href="http://www.memiks.fr/readityourself/">ReadItYourself</a>. poche is developed by <a href="http://nicolas.loeuillet.org">Nicolas Lœuillet</a> under the <a href="http://www.wtfpl.net/">Do What the Fuck You Want to Public License</a></p> |
1a268ba7 | 147 | </footer> |
5917f419 | 148 | </body> |
1a268ba7 | 149 | </html> |