]>
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 | ||
24619534 | 11 | require_once dirname(__FILE__).'/inc/Readability.php'; |
12 | require_once dirname(__FILE__).'/inc/Encoding.php'; | |
13 | include dirname(__FILE__).'/inc/functions.php'; | |
1a268ba7 NL |
14 | |
15 | try | |
16 | { | |
a590ea55 | 17 | $db_handle = new PDO('sqlite:db/poche.sqlite'); |
1a268ba7 NL |
18 | $db_handle->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); |
19 | } | |
20 | catch (Exception $e) | |
21 | { | |
5917f419 | 22 | die('database error : '.$e->getMessage()); |
1a268ba7 NL |
23 | } |
24 | ||
25 | $action = (isset ($_GET['action'])) ? htmlspecialchars($_GET['action']) : ''; | |
386407c1 | 26 | $view = (isset ($_GET['view'])) ? htmlspecialchars($_GET['view']) : ''; |
7eca3552 | 27 | $id = (isset ($_GET['id'])) ? htmlspecialchars($_GET['id']) : ''; |
1a268ba7 | 28 | |
386407c1 | 29 | switch ($action) |
30 | { | |
1a268ba7 | 31 | case 'add': |
24619534 | 32 | $url = (isset ($_GET['url'])) ? $_GET['url'] : ''; |
386407c1 | 33 | if ($url == '') |
34 | continue; | |
35 | ||
36 | $url = html_entity_decode(trim($url)); | |
37 | $title = $url; | |
38 | if (!preg_match('!^https?://!i', $url)) | |
39 | $url = 'http://' . $url; | |
40 | ||
24619534 | 41 | $html = Encoding::toUTF8(get_external_file($url,15)); |
386407c1 | 42 | if (isset($html) and strlen($html) > 0) |
43 | { | |
24619534 | 44 | $r = new Readability($html, $url); |
386407c1 | 45 | if($r->init()) |
46 | { | |
24619534 | 47 | $title = $r->articleTitle->innerHTML; |
48 | } | |
49 | } | |
50 | ||
1a268ba7 NL |
51 | $query = $db_handle->prepare('INSERT INTO entries ( url, title ) VALUES (?, ?)'); |
52 | $query->execute(array($url, $title)); | |
53 | break; | |
5917f419 | 54 | case 'toggle_fav' : |
386407c1 | 55 | $sql_action = "UPDATE entries SET is_fav=~is_fav WHERE id=?"; |
56 | $params_action = array($id); | |
1a268ba7 | 57 | break; |
5917f419 | 58 | case 'toggle_archive' : |
386407c1 | 59 | $sql_action = "UPDATE entries SET is_read=~is_read WHERE id=?"; |
60 | $params_action = array($id); | |
1a268ba7 NL |
61 | break; |
62 | case 'delete': | |
386407c1 | 63 | $sql_action = "DELETE FROM entries WHERE id=?"; |
64 | $params_action = array($id); | |
1a268ba7 NL |
65 | break; |
66 | default: | |
67 | break; | |
68 | } | |
c4fb6f01 | 69 | |
5917f419 | 70 | try |
71 | { | |
72 | # action query | |
386407c1 | 73 | if (isset($sql_action)) |
74 | { | |
5917f419 | 75 | $query = $db_handle->prepare($sql_action); |
76 | $query->execute($params_action); | |
77 | } | |
78 | } | |
79 | catch (Exception $e) | |
80 | { | |
81 | die('query error : '.$e->getMessage()); | |
82 | } | |
83 | ||
386407c1 | 84 | switch ($view) |
85 | { | |
5917f419 | 86 | case 'archive': |
0772c48b | 87 | $sql = "SELECT * FROM entries WHERE is_read=? ORDER BY id desc"; |
5917f419 | 88 | $params = array(-1); |
89 | break; | |
90 | case 'fav' : | |
0772c48b | 91 | $sql = "SELECT * FROM entries WHERE is_fav=? ORDER BY id desc"; |
5917f419 | 92 | $params = array(-1); |
93 | break; | |
94 | default: | |
0772c48b | 95 | $sql = "SELECT * FROM entries WHERE is_read=? ORDER BY id desc"; |
5917f419 | 96 | $params = array(0); |
97 | break; | |
98 | } | |
99 | ||
100 | # view query | |
101 | try | |
102 | { | |
386407c1 | 103 | $query = $db_handle->prepare($sql); |
5917f419 | 104 | $query->execute($params); |
105 | $entries = $query->fetchAll(); | |
106 | } | |
107 | catch (Exception $e) | |
108 | { | |
109 | die('query error : '.$e->getMessage()); | |
110 | } | |
111 | ||
1a268ba7 NL |
112 | ?> |
113 | <!DOCTYPE html> | |
114 | <!--[if lte IE 6]> <html class="no-js ie6 ie67 ie678" lang="en"> <![endif]--> | |
115 | <!--[if lte IE 7]> <html class="no-js ie7 ie67 ie678" lang="en"> <![endif]--> | |
116 | <!--[if IE 8]> <html class="no-js ie8 ie678" lang="en"> <![endif]--> | |
117 | <!--[if gt IE 8]><!--> <html class="no-js" lang="en"> <!--<![endif]--> | |
118 | <html> | |
119 | <head> | |
120 | <meta name="viewport" content="width=device-width, minimum-scale=1.0, maximum-scale=1.0"> | |
121 | <meta charset="utf-8"> | |
122 | <meta http-equiv="X-UA-Compatible" content="IE=10"> | |
386407c1 | 123 | <title>poche, a read it later open source system</title> |
ee55d616 | 124 | <link rel="shortcut icon" type="image/x-icon" href="favicon.ico" /> |
125 | <link rel="apple-touch-icon-precomposed" sizes="144x144" href="apple-touch-icon-144x144-precomposed.png"> | |
126 | <link rel="apple-touch-icon-precomposed" sizes="72x72" href="apple-touch-icon-72x72-precomposed.png"> | |
127 | <link rel="apple-touch-icon-precomposed" href="apple-touch-icon-precomposed.png"> | |
1a268ba7 NL |
128 | <link rel="stylesheet" href="css/knacss.css" media="all"> |
129 | <link rel="stylesheet" href="css/style.css" media="all"> | |
130 | </head> | |
131 | <body> | |
5917f419 | 132 | <header> |
386407c1 | 133 | <h1><img src="img/logo.png" alt="logo poche" />poche</h1> |
5917f419 | 134 | </header> |
7eca3552 | 135 | <div id="main" class="w960p"> |
5917f419 | 136 | <ul id="links"> |
137 | <li><a href="index.php">home</a></li> | |
138 | <li><a href="?view=fav">favorites</a></li> | |
139 | <li><a href="?view=archive">archive</a></li> | |
ee55d616 | 140 | <li><a style="cursor: move" 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> |
5917f419 | 141 | </ul> |
7eca3552 | 142 | <div id="entries"> |
5917f419 | 143 | <?php |
7eca3552 | 144 | $i = 0; |
386407c1 | 145 | foreach ($entries as $entry) |
146 | { | |
7eca3552 | 147 | if ($i == 0) { |
148 | echo '<section class="line grid3">'; | |
149 | } | |
150 | echo '<aside class="mod entrie mb2"><h2 class="h6-like"><a href="readityourself.php?url='.urlencode($entry['url']).'">' . $entry['title'] . '</h2><div class="tools"><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></div></aside>'; | |
151 | ||
152 | $i++; | |
153 | if ($i == 3) { | |
154 | echo '</section>'; | |
155 | $i = 0; | |
156 | } | |
5917f419 | 157 | } |
158 | ?> | |
7eca3552 | 159 | </div> |
5917f419 | 160 | </div> |
161 | <footer class="mr2 mt3"> | |
644ba9a9 | 162 | <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>. <a href="https://twitter.com/getpoche" title="follow us on twitter">@getpoche</a>. Logo by <a href="http://www.iconfinder.com/icondetails/43256/128/jeans_monotone_pocket_icon">Brightmix</a>. poche is developed by <a href="http://nicolas.loeuillet.org">Nicolas Lœuillet</a> under the <a href="http://www.wtfpl.net/">WTFPL</a>.</p> |
1a268ba7 | 163 | </footer> |
5917f419 | 164 | </body> |
1a268ba7 | 165 | </html> |