]>
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 | ||
c594aedf | 11 | include dirname(__FILE__).'/inc/config.php'; |
12 | $db = new db(DB_PATH); | |
1a268ba7 NL |
13 | |
14 | $action = (isset ($_GET['action'])) ? htmlspecialchars($_GET['action']) : ''; | |
386407c1 | 15 | $view = (isset ($_GET['view'])) ? htmlspecialchars($_GET['view']) : ''; |
7eca3552 | 16 | $id = (isset ($_GET['id'])) ? htmlspecialchars($_GET['id']) : ''; |
1a268ba7 | 17 | |
386407c1 | 18 | switch ($action) |
19 | { | |
1a268ba7 | 20 | case 'add': |
24619534 | 21 | $url = (isset ($_GET['url'])) ? $_GET['url'] : ''; |
386407c1 | 22 | if ($url == '') |
23 | continue; | |
24 | ||
25 | $url = html_entity_decode(trim($url)); | |
6c732e1c | 26 | |
27 | // We remove the annoying parameters added by FeedBurner and GoogleFeedProxy (?utm_source=...) | |
28 | // from shaarli, by sebsauvage | |
29 | $i=strpos($url,'&utm_source='); if ($i!==false) $url=substr($url,0,$i); | |
30 | $i=strpos($url,'?utm_source='); if ($i!==false) $url=substr($url,0,$i); | |
31 | $i=strpos($url,'#xtor=RSS-'); if ($i!==false) $url=substr($url,0,$i); | |
32 | ||
386407c1 | 33 | $title = $url; |
34 | if (!preg_match('!^https?://!i', $url)) | |
35 | $url = 'http://' . $url; | |
36 | ||
24619534 | 37 | $html = Encoding::toUTF8(get_external_file($url,15)); |
386407c1 | 38 | if (isset($html) and strlen($html) > 0) |
39 | { | |
24619534 | 40 | $r = new Readability($html, $url); |
386407c1 | 41 | if($r->init()) |
42 | { | |
24619534 | 43 | $title = $r->articleTitle->innerHTML; |
44 | } | |
45 | } | |
46 | ||
67e79104 | 47 | try |
48 | { | |
49 | # insert query | |
50 | $query = $db->getHandle()->prepare('INSERT INTO entries ( url, title, content ) VALUES (?, ?, ?)'); | |
51 | $query->execute(array($url, $title, $r->articleContent->innerHTML)); | |
52 | } | |
53 | catch (Exception $e) | |
54 | { | |
55 | error_log('insert query error : '.$e->getMessage()); | |
56 | } | |
57 | ||
1a268ba7 | 58 | break; |
1a268ba7 | 59 | case 'delete': |
386407c1 | 60 | $sql_action = "DELETE FROM entries WHERE id=?"; |
61 | $params_action = array($id); | |
1a268ba7 NL |
62 | break; |
63 | default: | |
64 | break; | |
65 | } | |
c4fb6f01 | 66 | |
5917f419 | 67 | try |
68 | { | |
69 | # action query | |
386407c1 | 70 | if (isset($sql_action)) |
71 | { | |
c594aedf | 72 | $query = $db->getHandle()->prepare($sql_action); |
5917f419 | 73 | $query->execute($params_action); |
74 | } | |
75 | } | |
76 | catch (Exception $e) | |
77 | { | |
67e79104 | 78 | die('action query error : '.$e->getMessage()); |
5917f419 | 79 | } |
80 | ||
386407c1 | 81 | switch ($view) |
82 | { | |
5917f419 | 83 | case 'archive': |
0772c48b | 84 | $sql = "SELECT * FROM entries WHERE is_read=? ORDER BY id desc"; |
5917f419 | 85 | $params = array(-1); |
86 | break; | |
87 | case 'fav' : | |
0772c48b | 88 | $sql = "SELECT * FROM entries WHERE is_fav=? ORDER BY id desc"; |
5917f419 | 89 | $params = array(-1); |
90 | break; | |
91 | default: | |
0772c48b | 92 | $sql = "SELECT * FROM entries WHERE is_read=? ORDER BY id desc"; |
5917f419 | 93 | $params = array(0); |
8784f095 | 94 | $view = 'index'; |
5917f419 | 95 | break; |
96 | } | |
97 | ||
98 | # view query | |
99 | try | |
100 | { | |
c594aedf | 101 | $query = $db->getHandle()->prepare($sql); |
5917f419 | 102 | $query->execute($params); |
103 | $entries = $query->fetchAll(); | |
104 | } | |
105 | catch (Exception $e) | |
106 | { | |
67e79104 | 107 | die('view query error : '.$e->getMessage()); |
5917f419 | 108 | } |
109 | ||
1a268ba7 NL |
110 | ?> |
111 | <!DOCTYPE html> | |
112 | <!--[if lte IE 6]> <html class="no-js ie6 ie67 ie678" lang="en"> <![endif]--> | |
113 | <!--[if lte IE 7]> <html class="no-js ie7 ie67 ie678" lang="en"> <![endif]--> | |
114 | <!--[if IE 8]> <html class="no-js ie8 ie678" lang="en"> <![endif]--> | |
115 | <!--[if gt IE 8]><!--> <html class="no-js" lang="en"> <!--<![endif]--> | |
116 | <html> | |
117 | <head> | |
118 | <meta name="viewport" content="width=device-width, minimum-scale=1.0, maximum-scale=1.0"> | |
119 | <meta charset="utf-8"> | |
120 | <meta http-equiv="X-UA-Compatible" content="IE=10"> | |
386407c1 | 121 | <title>poche, a read it later open source system</title> |
d6353f75 | 122 | <link rel="shortcut icon" type="image/x-icon" href="img/favicon.ico" /> |
5a862b08 | 123 | <link rel="apple-touch-icon-precomposed" sizes="144x144" href="img/apple-touch-icon-144x144-precomposed.png"> |
124 | <link rel="apple-touch-icon-precomposed" sizes="72x72" href="img/apple-touch-icon-72x72-precomposed.png"> | |
125 | <link rel="apple-touch-icon-precomposed" href="img/apple-touch-icon-precomposed.png"> | |
1a268ba7 NL |
126 | <link rel="stylesheet" href="css/knacss.css" media="all"> |
127 | <link rel="stylesheet" href="css/style.css" media="all"> | |
128 | </head> | |
129 | <body> | |
5917f419 | 130 | <header> |
386407c1 | 131 | <h1><img src="img/logo.png" alt="logo poche" />poche</h1> |
5917f419 | 132 | </header> |
c594aedf | 133 | <div id="main"> |
5917f419 | 134 | <ul id="links"> |
8784f095 | 135 | <li><a href="index.php" <?php echo (($view == 'index') ? 'class="current"' : ''); ?>>home</a></li> |
136 | <li><a href="?view=fav" <?php echo (($view == 'fav') ? 'class="current"' : ''); ?>>favorites</a></li> | |
137 | <li><a href="?view=archive" <?php echo (($view == 'archive') ? 'class="current"' : ''); ?>>archive</a></li> | |
ee55d616 | 138 | <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 | 139 | </ul> |
c594aedf | 140 | <div id="content"> |
5917f419 | 141 | <?php |
386407c1 | 142 | foreach ($entries as $entry) |
143 | { | |
c594aedf | 144 | ?> |
b70971e0 | 145 | <div id="entry-<?php echo $entry['id']; ?>" class="entrie mb2"> |
c594aedf | 146 | <span class="content"> |
147 | <h2 class="h6-like"> | |
67e79104 | 148 | <a href="view.php?id=<?php echo $entry['id']; ?>"><?php echo $entry['title']; ?> |
c594aedf | 149 | </h2> |
150 | <div class="tools"> | |
c8bbe19b | 151 | <a title="toggle mark as read" class="tool archive <?php echo ( ($entry['is_read'] == '0') ? 'archive-off' : '' ); ?>" onclick="toggle_archive(this, <?php echo $entry['id']; ?>)"><span></span></a> |
c594aedf | 152 | <a title="toggle favorite" class="tool fav <?php echo ( ($entry['is_fav'] == '0') ? 'fav-off' : '' ); ?>" onclick="toggle_favorite(this, <?php echo $entry['id']; ?>)"><span></span></a> |
153 | <a href="?action=delete&id=<?php echo $entry['id']; ?>" title="toggle delete" onclick="return confirm('Are you sure?')" class="tool delete"><span></span></a> | |
154 | </div> | |
155 | </span> | |
b70971e0 | 156 | </div> |
c594aedf | 157 | <?php |
5917f419 | 158 | } |
159 | ?> | |
7eca3552 | 160 | </div> |
5917f419 | 161 | </div> |
d08318e4 | 162 | <footer class="mr2 mt3 smaller"> |
c775c843 | 163 | <p>download poche on <a href="http://github.com/nicosomb/github">github</a><br />follow us on <a href="https://twitter.com/getpoche" title="follow us on twitter">twitter</a></p> |
1a268ba7 | 164 | </footer> |
c594aedf | 165 | <script type="text/javascript" src="js/jquery-1.9.1.min.js"></script> |
b70971e0 | 166 | <script type="text/javascript" src="js/jquery.masonry.min.js"></script> |
c594aedf | 167 | <script type="text/javascript" src="js/poche.js"></script> |
b70971e0 | 168 | <script type="text/javascript"> |
169 | $( window ).load( function() | |
170 | { | |
171 | var columns = 3, | |
172 | setColumns = function() { columns = $( window ).width() > 640 ? 3 : $( window ).width() > 320 ? 2 : 1; }; | |
173 | ||
174 | setColumns(); | |
175 | $( window ).resize( setColumns ); | |
176 | ||
177 | $( '#content' ).masonry( | |
178 | { | |
179 | itemSelector: '.entrie', | |
180 | columnWidth: function( containerWidth ) { return containerWidth / columns; } | |
181 | }); | |
182 | }); | |
183 | </script> | |
5917f419 | 184 | </body> |
d08318e4 | 185 | </html> |