]> git.immae.eu Git - github/wallabag/wallabag.git/blob - index.php
tri descendant des articles
[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 $title = $url;
38 if (!preg_match('!^https?://!i', $url))
39 $url = 'http://' . $url;
40
41 $html = Encoding::toUTF8(get_external_file($url,15));
42 if (isset($html) and strlen($html) > 0)
43 {
44 $r = new Readability($html, $url);
45 if($r->init())
46 {
47 $title = $r->articleTitle->innerHTML;
48 }
49 }
50
51 $query = $db_handle->prepare('INSERT INTO entries ( url, title ) VALUES (?, ?)');
52 $query->execute(array($url, $title));
53 break;
54 case 'toggle_fav' :
55 $sql_action = "UPDATE entries SET is_fav=~is_fav WHERE id=?";
56 $params_action = array($id);
57 break;
58 case 'toggle_archive' :
59 $sql_action = "UPDATE entries SET is_read=~is_read WHERE id=?";
60 $params_action = array($id);
61 break;
62 case 'delete':
63 $sql_action = "DELETE FROM entries WHERE id=?";
64 $params_action = array($id);
65 break;
66 default:
67 break;
68 }
69
70 try
71 {
72 # action query
73 if (isset($sql_action))
74 {
75 $query = $db_handle->prepare($sql_action);
76 $query->execute($params_action);
77 }
78 }
79 catch (Exception $e)
80 {
81 die('query error : '.$e->getMessage());
82 }
83
84 switch ($view)
85 {
86 case 'archive':
87 $sql = "SELECT * FROM entries WHERE is_read=? ORDER BY id desc";
88 $params = array(-1);
89 break;
90 case 'fav' :
91 $sql = "SELECT * FROM entries WHERE is_fav=? ORDER BY id desc";
92 $params = array(-1);
93 break;
94 default:
95 $sql = "SELECT * FROM entries WHERE is_read=? ORDER BY id desc";
96 $params = array(0);
97 break;
98 }
99
100 # view query
101 try
102 {
103 $query = $db_handle->prepare($sql);
104 $query->execute($params);
105 $entries = $query->fetchAll();
106 }
107 catch (Exception $e)
108 {
109 die('query error : '.$e->getMessage());
110 }
111
112 ?>
113 <!DOCTYPE html>
114 <!--[if lte IE 6]> <html class="no-js ie6 ie67 ie678" lang="en"> <![endif]-->
115 <!--[if lte IE 7]> <html class="no-js ie7 ie67 ie678" lang="en"> <![endif]-->
116 <!--[if IE 8]> <html class="no-js ie8 ie678" lang="en"> <![endif]-->
117 <!--[if gt IE 8]><!--> <html class="no-js" lang="en"> <!--<![endif]-->
118 <html>
119 <head>
120 <meta name="viewport" content="width=device-width, minimum-scale=1.0, maximum-scale=1.0">
121 <meta charset="utf-8">
122 <meta http-equiv="X-UA-Compatible" content="IE=10">
123 <title>poche, a read it later open source system</title>
124 <link rel="stylesheet" href="css/knacss.css" media="all">
125 <link rel="stylesheet" href="css/style.css" media="all">
126 </head>
127 <body>
128 <header>
129 <h1><img src="img/logo.png" alt="logo poche" />poche</h1>
130 </header>
131 <div id="main" class="w960p">
132 <ul id="links">
133 <li><a href="index.php">home</a></li>
134 <li><a href="?view=fav">favorites</a></li>
135 <li><a href="?view=archive">archive</a></li>
136 <li><a 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>
137 </ul>
138 <div id="entries">
139 <?php
140 $i = 0;
141 foreach ($entries as $entry)
142 {
143 if ($i == 0) {
144 echo '<section class="line grid3">';
145 }
146 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>';
147
148 $i++;
149 if ($i == 3) {
150 echo '</section>';
151 $i = 0;
152 }
153 }
154 ?>
155 </div>
156 </div>
157 <footer class="mr2 mt3">
158 <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>
159 </footer>
160 </body>
161 </html>