]> git.immae.eu Git - github/wallabag/wallabag.git/blame - index.php
background sur le menu pour savoir sur quelle page on se trouve
[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);
8784f095 104 $view = 'index';
5917f419 105 break;
106}
107
108# view query
109try
110{
386407c1 111 $query = $db_handle->prepare($sql);
5917f419 112 $query->execute($params);
113 $entries = $query->fetchAll();
114}
115catch (Exception $e)
116{
117 die('query error : '.$e->getMessage());
118}
119
1a268ba7
NL
120?>
121<!DOCTYPE html>
122<!--[if lte IE 6]> <html class="no-js ie6 ie67 ie678" lang="en"> <![endif]-->
123<!--[if lte IE 7]> <html class="no-js ie7 ie67 ie678" lang="en"> <![endif]-->
124<!--[if IE 8]> <html class="no-js ie8 ie678" lang="en"> <![endif]-->
125<!--[if gt IE 8]><!--> <html class="no-js" lang="en"> <!--<![endif]-->
126<html>
127 <head>
128 <meta name="viewport" content="width=device-width, minimum-scale=1.0, maximum-scale=1.0">
129 <meta charset="utf-8">
130 <meta http-equiv="X-UA-Compatible" content="IE=10">
386407c1 131 <title>poche, a read it later open source system</title>
d6353f75 132 <link rel="shortcut icon" type="image/x-icon" href="img/favicon.ico" />
5a862b08 133 <link rel="apple-touch-icon-precomposed" sizes="144x144" href="img/apple-touch-icon-144x144-precomposed.png">
134 <link rel="apple-touch-icon-precomposed" sizes="72x72" href="img/apple-touch-icon-72x72-precomposed.png">
135 <link rel="apple-touch-icon-precomposed" href="img/apple-touch-icon-precomposed.png">
1a268ba7
NL
136 <link rel="stylesheet" href="css/knacss.css" media="all">
137 <link rel="stylesheet" href="css/style.css" media="all">
138 </head>
139 <body>
5917f419 140 <header>
386407c1 141 <h1><img src="img/logo.png" alt="logo poche" />poche</h1>
5917f419 142 </header>
7eca3552 143 <div id="main" class="w960p">
5917f419 144 <ul id="links">
8784f095 145 <li><a href="index.php" <?php echo (($view == 'index') ? 'class="current"' : ''); ?>>home</a></li>
146 <li><a href="?view=fav" <?php echo (($view == 'fav') ? 'class="current"' : ''); ?>>favorites</a></li>
147 <li><a href="?view=archive" <?php echo (($view == 'archive') ? 'class="current"' : ''); ?>>archive</a></li>
ee55d616 148 <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 149 </ul>
7eca3552 150 <div id="entries">
5917f419 151 <?php
7eca3552 152 $i = 0;
386407c1 153 foreach ($entries as $entry)
154 {
7eca3552 155 if ($i == 0) {
156 echo '<section class="line grid3">';
157 }
d6353f75 158 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>';
7eca3552 159
160 $i++;
161 if ($i == 3) {
162 echo '</section>';
163 $i = 0;
164 }
5917f419 165 }
166 ?>
7eca3552 167 </div>
5917f419 168 </div>
d08318e4 169 <footer class="mr2 mt3 smaller">
170 <p><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>.<br />
171 Follow us on <a href="https://twitter.com/getpoche" title="follow us on twitter">@getpoche</a>.</<br />
172 Logo by <a href="http://www.iconfinder.com/icondetails/43256/128/jeans_monotone_pocket_icon">Brightmix</a>.<br />
173 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 174 </footer>
5917f419 175 </body>
d08318e4 176</html>