]> git.immae.eu Git - github/wallabag/wallabag.git/blob - index.php
déplacement du fichier favicon + confirmation pour la suppression
[github/wallabag/wallabag.git] / index.php
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 require_once dirname(__FILE__).'/inc/Readability.php';
12 require_once dirname(__FILE__).'/inc/Encoding.php';
13 include dirname(__FILE__).'/inc/functions.php';
14
15 try
16 {
17 $db_handle = new PDO('sqlite:db/poche.sqlite');
18 $db_handle->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
19 }
20 catch (Exception $e)
21 {
22 die('database error : '.$e->getMessage());
23 }
24
25 $action = (isset ($_GET['action'])) ? htmlspecialchars($_GET['action']) : '';
26 $view = (isset ($_GET['view'])) ? htmlspecialchars($_GET['view']) : '';
27 $id = (isset ($_GET['id'])) ? htmlspecialchars($_GET['id']) : '';
28
29 switch ($action)
30 {
31 case 'add':
32 $url = (isset ($_GET['url'])) ? $_GET['url'] : '';
33 if ($url == '')
34 continue;
35
36 $url = html_entity_decode(trim($url));
37
38 // We remove the annoying parameters added by FeedBurner and GoogleFeedProxy (?utm_source=...)
39 // from shaarli, by sebsauvage
40 $i=strpos($url,'&utm_source='); if ($i!==false) $url=substr($url,0,$i);
41 $i=strpos($url,'?utm_source='); if ($i!==false) $url=substr($url,0,$i);
42 $i=strpos($url,'#xtor=RSS-'); if ($i!==false) $url=substr($url,0,$i);
43
44 $title = $url;
45 if (!preg_match('!^https?://!i', $url))
46 $url = 'http://' . $url;
47
48 $html = Encoding::toUTF8(get_external_file($url,15));
49 if (isset($html) and strlen($html) > 0)
50 {
51 $r = new Readability($html, $url);
52 if($r->init())
53 {
54 $title = $r->articleTitle->innerHTML;
55 }
56 }
57
58 $query = $db_handle->prepare('INSERT INTO entries ( url, title ) VALUES (?, ?)');
59 $query->execute(array($url, $title));
60 break;
61 case 'toggle_fav' :
62 $sql_action = "UPDATE entries SET is_fav=~is_fav WHERE id=?";
63 $params_action = array($id);
64 break;
65 case 'toggle_archive' :
66 $sql_action = "UPDATE entries SET is_read=~is_read WHERE id=?";
67 $params_action = array($id);
68 break;
69 case 'delete':
70 $sql_action = "DELETE FROM entries WHERE id=?";
71 $params_action = array($id);
72 break;
73 default:
74 break;
75 }
76
77 try
78 {
79 # action query
80 if (isset($sql_action))
81 {
82 $query = $db_handle->prepare($sql_action);
83 $query->execute($params_action);
84 }
85 }
86 catch (Exception $e)
87 {
88 die('query error : '.$e->getMessage());
89 }
90
91 switch ($view)
92 {
93 case 'archive':
94 $sql = "SELECT * FROM entries WHERE is_read=? ORDER BY id desc";
95 $params = array(-1);
96 break;
97 case 'fav' :
98 $sql = "SELECT * FROM entries WHERE is_fav=? ORDER BY id desc";
99 $params = array(-1);
100 break;
101 default:
102 $sql = "SELECT * FROM entries WHERE is_read=? ORDER BY id desc";
103 $params = array(0);
104 break;
105 }
106
107 # view query
108 try
109 {
110 $query = $db_handle->prepare($sql);
111 $query->execute($params);
112 $entries = $query->fetchAll();
113 }
114 catch (Exception $e)
115 {
116 die('query error : '.$e->getMessage());
117 }
118
119 ?>
120 <!DOCTYPE html>
121 <!--[if lte IE 6]> <html class="no-js ie6 ie67 ie678" lang="en"> <![endif]-->
122 <!--[if lte IE 7]> <html class="no-js ie7 ie67 ie678" lang="en"> <![endif]-->
123 <!--[if IE 8]> <html class="no-js ie8 ie678" lang="en"> <![endif]-->
124 <!--[if gt IE 8]><!--> <html class="no-js" lang="en"> <!--<![endif]-->
125 <html>
126 <head>
127 <meta name="viewport" content="width=device-width, minimum-scale=1.0, maximum-scale=1.0">
128 <meta charset="utf-8">
129 <meta http-equiv="X-UA-Compatible" content="IE=10">
130 <title>poche, a read it later open source system</title>
131 <link rel="shortcut icon" type="image/x-icon" href="img/favicon.ico" />
132 <link rel="apple-touch-icon-precomposed" sizes="144x144" href="img/apple-touch-icon-144x144-precomposed.png">
133 <link rel="apple-touch-icon-precomposed" sizes="72x72" href="img/apple-touch-icon-72x72-precomposed.png">
134 <link rel="apple-touch-icon-precomposed" href="img/apple-touch-icon-precomposed.png">
135 <link rel="stylesheet" href="css/knacss.css" media="all">
136 <link rel="stylesheet" href="css/style.css" media="all">
137 </head>
138 <body>
139 <header>
140 <h1><img src="img/logo.png" alt="logo poche" />poche</h1>
141 </header>
142 <div id="main" class="w960p">
143 <ul id="links">
144 <li><a href="index.php">home</a></li>
145 <li><a href="?view=fav">favorites</a></li>
146 <li><a href="?view=archive">archive</a></li>
147 <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>
148 </ul>
149 <div id="entries">
150 <?php
151 $i = 0;
152 foreach ($entries as $entry)
153 {
154 if ($i == 0) {
155 echo '<section class="line grid3">';
156 }
157 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">&#10003;</a> <a href="?action=toggle_fav&id='.$entry['id'].'" title="toggle favorite" class="tool">'.(($entry['is_fav'] == 0) ? '&#9734;' : '&#9733;' ).'</a> <a href="?action=delete&id='.$entry['id'].'" title="toggle delete" onclick="return confirm(\'Are you sure?\')" class="tool">&#10799;</a></div></aside>';
158
159 $i++;
160 if ($i == 3) {
161 echo '</section>';
162 $i = 0;
163 }
164 }
165 ?>
166 </div>
167 </div>
168 <footer class="mr2 mt3">
169 <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>
170 </footer>
171 </body>
172 </html>