diff options
Diffstat (limited to 'index.php')
-rwxr-xr-x | index.php | 113 |
1 files changed, 78 insertions, 35 deletions
@@ -30,10 +30,12 @@ try | |||
30 | } | 30 | } |
31 | catch (Exception $e) | 31 | catch (Exception $e) |
32 | { | 32 | { |
33 | die('error : '.$e->getMessage()); | 33 | die('database error : '.$e->getMessage()); |
34 | } | 34 | } |
35 | 35 | ||
36 | $action = (isset ($_GET['action'])) ? htmlspecialchars($_GET['action']) : ''; | 36 | $action = (isset ($_GET['action'])) ? htmlspecialchars($_GET['action']) : ''; |
37 | $view = (isset ($_GET['view'])) ? htmlspecialchars($_GET['view']) : ''; | ||
38 | $id = (isset ($_GET['id'])) ? htmlspecialchars($_GET['id']) : ''; | ||
37 | 39 | ||
38 | switch ($action) { | 40 | switch ($action) { |
39 | case 'add': | 41 | case 'add': |
@@ -42,9 +44,13 @@ switch ($action) { | |||
42 | $query = $db_handle->prepare('INSERT INTO entries ( url, title ) VALUES (?, ?)'); | 44 | $query = $db_handle->prepare('INSERT INTO entries ( url, title ) VALUES (?, ?)'); |
43 | $query->execute(array($url, $title)); | 45 | $query->execute(array($url, $title)); |
44 | break; | 46 | break; |
45 | case 'archive': | 47 | case 'toggle_fav' : |
48 | $sql_action = "UPDATE entries SET is_fav=~is_fav WHERE id=?"; | ||
49 | $params_action = array($id); | ||
46 | break; | 50 | break; |
47 | case 'fav' : | 51 | case 'toggle_archive' : |
52 | $sql_action = "UPDATE entries SET is_read=~is_read WHERE id=?"; | ||
53 | $params_action = array($id); | ||
48 | break; | 54 | break; |
49 | case 'delete': | 55 | case 'delete': |
50 | break; | 56 | break; |
@@ -52,13 +58,55 @@ switch ($action) { | |||
52 | break; | 58 | break; |
53 | } | 59 | } |
54 | 60 | ||
55 | function url(){ | 61 | try |
56 | $protocol = "http"; | 62 | { |
57 | if(isset($_SERVER['HTTPS'])) | 63 | # action query |
58 | if($_SERVER['HTTPS'] != "off") | 64 | if (isset($sql_action)) { |
59 | $protocol = "https"; | 65 | $query = $db_handle->prepare($sql_action); |
60 | 66 | $query->execute($params_action); | |
61 | return $protocol . "://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; | 67 | } |
68 | } | ||
69 | catch (Exception $e) | ||
70 | { | ||
71 | die('query error : '.$e->getMessage()); | ||
72 | } | ||
73 | |||
74 | switch ($view) { | ||
75 | case 'archive': | ||
76 | $sql = "SELECT * FROM entries WHERE is_read=?"; | ||
77 | $params = array(-1); | ||
78 | break; | ||
79 | case 'fav' : | ||
80 | $sql = "SELECT * FROM entries WHERE is_fav=?"; | ||
81 | $params = array(-1); | ||
82 | break; | ||
83 | default: | ||
84 | $sql = "SELECT * FROM entries WHERE is_read=?"; | ||
85 | $params = array(0); | ||
86 | break; | ||
87 | } | ||
88 | |||
89 | # view query | ||
90 | try | ||
91 | { | ||
92 | $query = $db_handle->prepare($sql); | ||
93 | $query->execute($params); | ||
94 | $entries = $query->fetchAll(); | ||
95 | } | ||
96 | catch (Exception $e) | ||
97 | { | ||
98 | die('query error : '.$e->getMessage()); | ||
99 | } | ||
100 | |||
101 | function url() { | ||
102 | $protocol = "http"; | ||
103 | if(isset($_SERVER['HTTPS'])) { | ||
104 | if($_SERVER['HTTPS'] != "off") { | ||
105 | $protocol = "https"; | ||
106 | } | ||
107 | } | ||
108 | |||
109 | return $protocol . "://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; | ||
62 | } | 110 | } |
63 | ?> | 111 | ?> |
64 | <!DOCTYPE html> | 112 | <!DOCTYPE html> |
@@ -76,31 +124,26 @@ function url(){ | |||
76 | <link rel="stylesheet" href="css/style.css" media="all"> | 124 | <link rel="stylesheet" href="css/style.css" media="all"> |
77 | </head> | 125 | </head> |
78 | <body> | 126 | <body> |
79 | <header> | 127 | <header> |
80 | <h1>poche, a read it later open source system</h1> | 128 | <h1>poche, a read it later open source system</h1> |
81 | </header> | 129 | </header> |
82 | <div id="main" class="w800p"> | 130 | <div id="main" class="w800p"> |
83 | <ul id="links"> | 131 | <ul id="links"> |
84 | <li><a href="index.php">home</a></li> | 132 | <li><a href="index.php">home</a></li> |
85 | <li><a href="#">favorites</a></li> | 133 | <li><a href="?view=fav">favorites</a></li> |
86 | <li><a href="#">archive</a></li> | 134 | <li><a href="?view=archive">archive</a></li> |
87 | <li><a 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> | 135 | <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> |
88 | </ul> | 136 | </ul> |
89 | <?php | 137 | <ul id="entries"> |
90 | $query = $db_handle->prepare("SELECT * FROM entries WHERE read=?"); | 138 | <?php |
91 | $query->execute(array('FALSE')); | 139 | foreach ($entries as $entry) { |
92 | $entries = $query->fetchAll(); | 140 | echo '<li><a href="readityourself.php?url='.urlencode($entry['url']).'">' . $entry['title'] . '</a> <a href="?action=toggle_archive&id='.$entry['id'].'" title="toggle mark as read" class="tool">✓</a> <a href="?action=toggle_fav&id='.$entry['id'].'" title="toggle favorite" class="tool">'.(($entry['is_fav'] == 0) ? '☆' : '★' ).'</a> <a href="#" title="toggle delete" class="tool">⨯</a></li>'; |
93 | ?> | 141 | } |
94 | <ul id="entries"> | 142 | ?> |
95 | <?php | 143 | </ul> |
96 | foreach ($entries as $entry) { | 144 | </div> |
97 | echo '<li><a href="readityourself.php?url='.urlencode($entry['url']).'">' . $entry['title'] . '</a> <a href="#" title="toggle delete" class="tool">✓</a> <a href="#" title="toggle favorite" class="tool">☆</a> <a href="#" title="toggle mark as read" class="tool">⨯</a></li>'; | 145 | <footer class="mr2 mt3"> |
98 | } | ||
99 | ?> | ||
100 | </ul> | ||
101 | </div> | ||
102 | <footer class="mr2 mt3"> | ||
103 | <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>. poche is developed by <a href="http://nicolas.loeuillet.org">Nicolas LÅ“uillet</a> under the <a href="http://www.wtfpl.net/">Do What the Fuck You Want to Public License</a></p> | 146 | <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>. poche is developed by <a href="http://nicolas.loeuillet.org">Nicolas LÅ“uillet</a> under the <a href="http://www.wtfpl.net/">Do What the Fuck You Want to Public License</a></p> |
104 | </footer> | 147 | </footer> |
105 | </body> | 148 | </body> |
106 | </html> \ No newline at end of file | 149 | </html> \ No newline at end of file |