]> git.immae.eu Git - github/wallabag/wallabag.git/blame - index.php
typo pour le hover sur le lien de retour à la home
[github/wallabag/wallabag.git] / index.php
CommitLineData
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 11require_once dirname(__FILE__).'/inc/Readability.php';
12require_once dirname(__FILE__).'/inc/Encoding.php';
13include dirname(__FILE__).'/inc/functions.php';
1a268ba7
NL
14
15try
16{
a590ea55 17 $db_handle = new PDO('sqlite:db/poche.sqlite');
1a268ba7
NL
18 $db_handle->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
19}
20catch (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 29switch ($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));
6c732e1c 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
386407c1 44 $title = $url;
45 if (!preg_match('!^https?://!i', $url))
46 $url = 'http://' . $url;
47
24619534 48 $html = Encoding::toUTF8(get_external_file($url,15));
386407c1 49 if (isset($html) and strlen($html) > 0)
50 {
24619534 51 $r = new Readability($html, $url);
386407c1 52 if($r->init())
53 {
24619534 54 $title = $r->articleTitle->innerHTML;
55 }
56 }
57
1a268ba7
NL
58 $query = $db_handle->prepare('INSERT INTO entries ( url, title ) VALUES (?, ?)');
59 $query->execute(array($url, $title));
60 break;
5917f419 61 case 'toggle_fav' :
386407c1 62 $sql_action = "UPDATE entries SET is_fav=~is_fav WHERE id=?";
63 $params_action = array($id);
1a268ba7 64 break;
5917f419 65 case 'toggle_archive' :
386407c1 66 $sql_action = "UPDATE entries SET is_read=~is_read WHERE id=?";
67 $params_action = array($id);
1a268ba7
NL
68 break;
69 case 'delete':
386407c1 70 $sql_action = "DELETE FROM entries WHERE id=?";
71 $params_action = array($id);
1a268ba7
NL
72 break;
73 default:
74 break;
75}
c4fb6f01 76
5917f419 77try
78{
79 # action query
386407c1 80 if (isset($sql_action))
81 {
5917f419 82 $query = $db_handle->prepare($sql_action);
83 $query->execute($params_action);
84 }
85}
86catch (Exception $e)
87{
88 die('query error : '.$e->getMessage());
89}
90
386407c1 91switch ($view)
92{
5917f419 93 case 'archive':
0772c48b 94 $sql = "SELECT * FROM entries WHERE is_read=? ORDER BY id desc";
5917f419 95 $params = array(-1);
96 break;
97 case 'fav' :
0772c48b 98 $sql = "SELECT * FROM entries WHERE is_fav=? ORDER BY id desc";
5917f419 99 $params = array(-1);
100 break;
101 default:
0772c48b 102 $sql = "SELECT * FROM entries WHERE is_read=? ORDER BY id desc";
5917f419 103 $params = array(0);
104 break;
105}
106
107# view query
108try
109{
386407c1 110 $query = $db_handle->prepare($sql);
5917f419 111 $query->execute($params);
112 $entries = $query->fetchAll();
113}
114catch (Exception $e)
115{
116 die('query error : '.$e->getMessage());
117}
118
1a268ba7
NL
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">
386407c1 130 <title>poche, a read it later open source system</title>
ee55d616 131 <link rel="shortcut icon" type="image/x-icon" href="favicon.ico" />
5a862b08 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">
1a268ba7
NL
135 <link rel="stylesheet" href="css/knacss.css" media="all">
136 <link rel="stylesheet" href="css/style.css" media="all">
137 </head>
138 <body>
5917f419 139 <header>
386407c1 140 <h1><img src="img/logo.png" alt="logo poche" />poche</h1>
5917f419 141 </header>
7eca3552 142 <div id="main" class="w960p">
5917f419 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>
ee55d616 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>
5917f419 148 </ul>
7eca3552 149 <div id="entries">
5917f419 150 <?php
7eca3552 151 $i = 0;
386407c1 152 foreach ($entries as $entry)
153 {
7eca3552 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" class="tool">&#10799;</a></div></aside>';
158
159 $i++;
160 if ($i == 3) {
161 echo '</section>';
162 $i = 0;
163 }
5917f419 164 }
165 ?>
7eca3552 166 </div>
5917f419 167 </div>
168 <footer class="mr2 mt3">
644ba9a9 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>
1a268ba7 170 </footer>
5917f419 171 </body>
1a268ba7 172</html>