]>
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 | ||
c594aedf | 47 | $query = $db->getHandle()->prepare('INSERT INTO entries ( url, title ) VALUES (?, ?)'); |
1a268ba7 NL |
48 | $query->execute(array($url, $title)); |
49 | break; | |
1a268ba7 | 50 | case 'delete': |
386407c1 | 51 | $sql_action = "DELETE FROM entries WHERE id=?"; |
52 | $params_action = array($id); | |
1a268ba7 NL |
53 | break; |
54 | default: | |
55 | break; | |
56 | } | |
c4fb6f01 | 57 | |
5917f419 | 58 | try |
59 | { | |
60 | # action query | |
386407c1 | 61 | if (isset($sql_action)) |
62 | { | |
c594aedf | 63 | $query = $db->getHandle()->prepare($sql_action); |
5917f419 | 64 | $query->execute($params_action); |
65 | } | |
66 | } | |
67 | catch (Exception $e) | |
68 | { | |
69 | die('query error : '.$e->getMessage()); | |
70 | } | |
71 | ||
386407c1 | 72 | switch ($view) |
73 | { | |
5917f419 | 74 | case 'archive': |
0772c48b | 75 | $sql = "SELECT * FROM entries WHERE is_read=? ORDER BY id desc"; |
5917f419 | 76 | $params = array(-1); |
77 | break; | |
78 | case 'fav' : | |
0772c48b | 79 | $sql = "SELECT * FROM entries WHERE is_fav=? ORDER BY id desc"; |
5917f419 | 80 | $params = array(-1); |
81 | break; | |
82 | default: | |
0772c48b | 83 | $sql = "SELECT * FROM entries WHERE is_read=? ORDER BY id desc"; |
5917f419 | 84 | $params = array(0); |
8784f095 | 85 | $view = 'index'; |
5917f419 | 86 | break; |
87 | } | |
88 | ||
89 | # view query | |
90 | try | |
91 | { | |
c594aedf | 92 | $query = $db->getHandle()->prepare($sql); |
5917f419 | 93 | $query->execute($params); |
94 | $entries = $query->fetchAll(); | |
95 | } | |
96 | catch (Exception $e) | |
97 | { | |
98 | die('query error : '.$e->getMessage()); | |
99 | } | |
100 | ||
1a268ba7 NL |
101 | ?> |
102 | <!DOCTYPE html> | |
103 | <!--[if lte IE 6]> <html class="no-js ie6 ie67 ie678" lang="en"> <![endif]--> | |
104 | <!--[if lte IE 7]> <html class="no-js ie7 ie67 ie678" lang="en"> <![endif]--> | |
105 | <!--[if IE 8]> <html class="no-js ie8 ie678" lang="en"> <![endif]--> | |
106 | <!--[if gt IE 8]><!--> <html class="no-js" lang="en"> <!--<![endif]--> | |
107 | <html> | |
108 | <head> | |
109 | <meta name="viewport" content="width=device-width, minimum-scale=1.0, maximum-scale=1.0"> | |
110 | <meta charset="utf-8"> | |
111 | <meta http-equiv="X-UA-Compatible" content="IE=10"> | |
386407c1 | 112 | <title>poche, a read it later open source system</title> |
d6353f75 | 113 | <link rel="shortcut icon" type="image/x-icon" href="img/favicon.ico" /> |
5a862b08 | 114 | <link rel="apple-touch-icon-precomposed" sizes="144x144" href="img/apple-touch-icon-144x144-precomposed.png"> |
115 | <link rel="apple-touch-icon-precomposed" sizes="72x72" href="img/apple-touch-icon-72x72-precomposed.png"> | |
116 | <link rel="apple-touch-icon-precomposed" href="img/apple-touch-icon-precomposed.png"> | |
1a268ba7 NL |
117 | <link rel="stylesheet" href="css/knacss.css" media="all"> |
118 | <link rel="stylesheet" href="css/style.css" media="all"> | |
119 | </head> | |
120 | <body> | |
5917f419 | 121 | <header> |
386407c1 | 122 | <h1><img src="img/logo.png" alt="logo poche" />poche</h1> |
5917f419 | 123 | </header> |
c594aedf | 124 | <div id="main"> |
5917f419 | 125 | <ul id="links"> |
8784f095 | 126 | <li><a href="index.php" <?php echo (($view == 'index') ? 'class="current"' : ''); ?>>home</a></li> |
127 | <li><a href="?view=fav" <?php echo (($view == 'fav') ? 'class="current"' : ''); ?>>favorites</a></li> | |
128 | <li><a href="?view=archive" <?php echo (($view == 'archive') ? 'class="current"' : ''); ?>>archive</a></li> | |
ee55d616 | 129 | <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 | 130 | </ul> |
c594aedf | 131 | <div id="content"> |
5917f419 | 132 | <?php |
386407c1 | 133 | foreach ($entries as $entry) |
134 | { | |
c594aedf | 135 | ?> |
b70971e0 | 136 | <div id="entry-<?php echo $entry['id']; ?>" class="entrie mb2"> |
c594aedf | 137 | <span class="content"> |
138 | <h2 class="h6-like"> | |
139 | <a href="readityourself.php?url=<?php echo urlencode($entry['url']); ?>"><?php echo $entry['title']; ?> | |
140 | </h2> | |
141 | <div class="tools"> | |
142 | <a title="toggle mark as read" class="tool archive <?php echo ( ($entry['is_read'] == '0') ? 'archive-off' : '' ); ?>" onclick="toggle_archive(<?php echo $entry['id']; ?>)"><span></span></a> | |
143 | <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> | |
144 | <a href="?action=delete&id=<?php echo $entry['id']; ?>" title="toggle delete" onclick="return confirm('Are you sure?')" class="tool delete"><span></span></a> | |
145 | </div> | |
146 | </span> | |
b70971e0 | 147 | </div> |
c594aedf | 148 | <?php |
5917f419 | 149 | } |
150 | ?> | |
7eca3552 | 151 | </div> |
5917f419 | 152 | </div> |
d08318e4 | 153 | <footer class="mr2 mt3 smaller"> |
c775c843 | 154 | <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 | 155 | </footer> |
c594aedf | 156 | <script type="text/javascript" src="js/jquery-1.9.1.min.js"></script> |
b70971e0 | 157 | <script type="text/javascript" src="js/jquery.masonry.min.js"></script> |
c594aedf | 158 | <script type="text/javascript" src="js/poche.js"></script> |
b70971e0 | 159 | <script type="text/javascript"> |
160 | $( window ).load( function() | |
161 | { | |
162 | var columns = 3, | |
163 | setColumns = function() { columns = $( window ).width() > 640 ? 3 : $( window ).width() > 320 ? 2 : 1; }; | |
164 | ||
165 | setColumns(); | |
166 | $( window ).resize( setColumns ); | |
167 | ||
168 | $( '#content' ).masonry( | |
169 | { | |
170 | itemSelector: '.entrie', | |
171 | columnWidth: function( containerWidth ) { return containerWidth / columns; } | |
172 | }); | |
173 | }); | |
174 | </script> | |
5917f419 | 175 | </body> |
d08318e4 | 176 | </html> |