forked from RomanSixty/Feed-on-Feeds
-
Notifications
You must be signed in to change notification settings - Fork 3
/
sidebar.php
executable file
·393 lines (322 loc) · 12.8 KB
/
sidebar.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
<?php
/*
* This file is part of FEED ON FEEDS - http://feedonfeeds.com/
*
* sidebar.php - sidebar for all pages
*
*
* Copyright (C) 2004-2007 Stephen Minutillo
* steve@minutillo.com - http://minutillo.com/steve/
*
* Distributed under the GPL - see LICENSE
*
*/
include_once 'fof-main.php';
fof_set_content_type();
/* quell warnings */
function fof_sidebar_get_key_($array, $key, $default = NULL) {
if (!empty($array[$key])) {
return $array[$key];
}
return $default;
}
$sidebar_style = $fof_prefs_obj->get('sidebar_style');
/* honor old pref, if user hasn't saved new-style yet */
if (empty($sidebar_style) && $fof_prefs_obj->get('simple_sidebar')) {
$sidebar_style = 'simple';
}
?>
<img id="throbber" src="<?php echo $fof_asset['throbber_image']; ?>" align="left" style="display: none;" />
<?php
$welcomecontent = '<span>Welcome, <span class="userid">' . $fof_user_name . '</span>!</span>';
$welcomecontent .= '<span class="hide-on-mobile"> | <a href="prefs.php">prefs</a>';
if (!defined('FOF_AUTH_EXTERNAL')) {
$welcomecontent .= ' | <a href="logout.php">log out</a>';
}
echo '<div id="welcome" class="banner ontop">' . $welcomecontent . "</div>\n";
echo '<div id="welcome-spacer" class="banner">' . $welcomecontent . "</div>\n";
echo '<div id="feed-actions" class="hide-on-mobile"><a href="add.php"><b>Add Feeds</b></a> / ';
if ($sidebar_style == 'fancy') {
echo '<a href="#" class="hide-on-mobile" title="Update all subscribed feeds" onclick="sb_update_subscribed_sources()"><b>Update Feeds</b></a>';
} else {
echo '<a href="update.php"><b>Update Feeds</b></a>';
}
echo '</div>' . "\n";
?>
<ul id="nav">
<?php
$order = $fof_prefs_obj->get('feed_order');
$direction = $fof_prefs_obj->get('feed_direction');
$sharing = $fof_prefs_obj->get('sharing');
/* these parameters control highlighting of the active view */
$what = fof_sidebar_get_key_($_GET, 'what', 'unread');
$what_a = explode(' ', $what);
$when = fof_sidebar_get_key_($_GET, 'when');
$search = fof_sidebar_get_key_($_GET, 'search');
$feed = fof_sidebar_get_key_($_GET, 'feed');
$feeds = fof_get_feeds(fof_current_user(), $order, $direction);
$unread = 0;
$starred = 0;
$total = 0;
$n = 0;
foreach ($feeds as $row) {
$n++;
$unread += fof_sidebar_get_key_($row, 'feed_unread', 0);
$starred += fof_sidebar_get_key_($row, 'feed_starred', 0);
$total += fof_sidebar_get_key_($row, 'feed_items', 0);
}
$page_title_js = 'Feed on Feeds';
if (!empty($unread)) {
$page_title_js .= " ($unread)";
}
?>
<script>
document.title=<?php echo json_encode($page_title_js); ?>;
what=<?php echo json_encode($what); ?>;
when=<?php echo json_encode($when); ?>;
search=<?php echo json_encode($search); ?>;
feed=<?php echo json_encode($feed); ?>;
starred=<?php echo json_encode($starred); ?>;
</script>
<?php
echo ' <li' . (empty($feed) && $what == 'unread' ? " class='current-view'" : '') . '>';
echo '📖 <a href="' . fof_url('.', array('what' => 'unread', 'how' => 'paged')) . '"><span style="color:red"><b>Unread' . ($unread ? " ($unread)" : '') . '</b></span></a>';
echo '<span class="hide-on-mobile"> [<a href="' . fof_url('.', array('what' => 'unread', 'how' => 'unpaged')) . '">unpaged</a>]</span>';
echo "</li>\n";
echo ' <li' . (empty($feed) && $what == 'star' ? " class='current-view'" : '') . '>';
echo '<span class="starred-small"></span> <a href="' . fof_url('.', array('what' => 'star', 'how' => 'paged')) . '">Starred <span id="starredcount">' . ($starred ? "($starred)" : '') . '</span></a>';
echo '<span class="hide-on-mobile"> [<a href="' . fof_url('.', array('what' => 'star', 'how' => 'unpaged')) . '">unpaged</a>]</span>';
echo "</li>\n";
echo ' <li' . (empty($feed) && $what == 'all' && isset($when) ? " class='current-view'" : '') . '>';
echo '📆 <a href="' . fof_url('.', array('what' => 'all', 'when' => 'today')) . '">Today</a>';
echo "</li>\n";
echo ' <li' . (empty($feed) && $what == 'all' && empty($when) ? " class='current-view'" : '') . '>';
echo '📓 <a href="' . fof_url('.', array('what' => 'all', 'how' => 'paged')) . '">All Items ' . ($total ? "($total)" : '') . "</a>";
echo "</li>\n";
echo ' <li' . (!empty($search) ? ' class="current-view"' : '') . '>';
echo '🔎 <a href="#" onclick="document.getElementById(\'search\').classList.toggle(\'hide\');document.getElementById(\'searchfield\').focus();return false;">Search</a>' . "\n";
echo ' <form action="." id="search"' . (empty($search) ? ' class="hide"' : '') . ">\n";
echo ' <input type="hidden" name="how" value="paged">' . "\n";
echo ' <input type="hidden" name="what" value="' . (empty($what) || $what == 'unread' ? 'all' : htmlentities($what, ENT_QUOTES)) . "\">\n";
if (!empty($when)) {
echo ' <input type="hidden" name="when" value="' . htmlentities($when, ENT_QUOTES) . "\">\n";
}
echo ' <input id="searchfield" name="search" value="' . htmlentities($search ?? '', ENT_QUOTES) . "\" placeholder=\"search term\">\n";
echo " </form>\n";
echo " </li>\n";
?>
</ul>
<!--nav end-->
<?php
function fof_sidebar_tags_fancy() {
global $fof_asset;
global $sharing;
global $what_a;
$taglines = array();
$n = 0;
foreach (fof_get_tags(fof_current_user()) as $tag) {
if (in_array($tag['tag_name'], array('unread', 'star', 'folded'))) {
continue;
}
$tag_name_html = htmlentities($tag['tag_name']);
$tag_name_json = htmlentities(json_encode($tag['tag_name']), ENT_QUOTES);
$tag_view_unread_url = fof_url('.', array('what' => implode(' ', array($tag['tag_name'], 'unread')), 'how' => 'paged'));
$tag_view_all_url = fof_url('.', array('what' => $tag['tag_name'], 'how' => 'paged'));
$tagline = ' <tr class="tag' . (++$n % 2 ? ' odd-row' : '') . (in_array($tag['tag_name'], $what_a) ? ' current-view' : '') . '" id="tagid_' . $tag['tag_id'] . '">';
$tagline .= '<td class="source hide-on-mobile"><img src="' . (empty($tag['tag_icon']) ? $fof_asset['tag_icon'] : $tag['tag_icon']) . '" class="feed-icon" /></td>';
$tagline .= '<td class="unread"><span class="unread">';
if ($tag['unread']) {
$tagline .= '<a class="unread" href="' . $tag_view_unread_url . '" title="' . $tag['unread'] . ' unread items">' . $tag['unread'] . '</a>';
}
$tagline .= '</span></td>';
$tagline .= '<td class="title"><a href="' . ($tag['unread'] ? $tag_view_unread_url : $tag_view_all_url) . '" title="' . ($tag['unread'] ? ($tag['unread'] . ' new of ') : '') . $tag['count'] . ' total items">' . $tag['tag_name'] . '</a></td>';
$tagline .= '<td class="controls hide-on-mobile">';
$tagline .= '<ul class="feedmenu"><li>';
$tagline .= '<a href="#" title="tag controls">≡</a>';
$tagline .= '<ul>';
$tagline .= '<li><a href="' . $tag_view_all_url . '" title="' . $tag['count'] . ' total items">View all items</a></li>';
$tagline .= '<li><a href="#" title="update all source feeds" onclick="return sb_update_tag_sources(' . $tag_name_json . ');">Update contributing feeds</a></li>';
$tagline .= '<li><a href="#" title="mark all read" onclick="return sb_mark_tag_read(' . $tag_name_json . ')">Mark all items as read</a></li>';
$tagline .= '<li><a href="#" title="untag all items" onclick="return sb_del_tag_conf(' . $tag_name_json . ');">Delete tag from all items</a></li>';
$tagline .= '</ul>';
$tagline .= '</li></ul>';
$tagline .= '</td>';
if ($sharing == 'all_tagged') {
$tagline .= '<td class="sharing"><a href="' . fof_url('./shared.php', array('user' => fof_current_user(), 'which' => $tag_name_html, 'how' => 'paged')) . '">' . $tag['tag_name'] . '</a></td>';
}
$tagline .= '</tr>';
$taglines[] = $tagline;
}
/* headers */
if (!empty($taglines)) {
echo "<div id=\"tags\">\n";
echo "<table cellspacing=\"0\" cellpadding=\"1\" border=\"0\" class=\"taglist\">\n";
echo "<thead class=\"hide-on-mobile\">\n";
echo ' <tr class="heading">';
echo '<th class="source"></th>';
echo '<th class="unread"><span class="unread">#</span></th>';
echo '<th class="title">tag name</th>';
echo '<th class="controls"><span></span></th>';
if ($sharing == 'all_tagged') {
echo '<th class="sharing">shared page</th>';
}
echo "</tr>\n";
echo "</thead>\n";
echo "<tbody>\n";
echo implode("\n", $taglines);
echo "\n</tbody>\n</table>\n</div>\n<!--tags end-->\n\n\n";
}
}
function fof_sidebar_tags_default() {
global $sharing;
global $what_a;
$unread_id = fof_db_get_tag_by_name('unread');
$star_id = fof_db_get_tag_by_name('star');
$folded_id = fof_db_get_tag_by_name('folded');
$tags = fof_get_tags(fof_current_user());
$taglines = array();
$n = 0;
foreach ($tags as $tag) {
$tag_id = $tag['tag_id'];
if ($tag_id == $unread_id
|| $tag_id == $star_id
|| $tag_id == $folded_id) {
continue;
}
$tagline = '';
$tag_name = $tag['tag_name'];
$tag_name_html = htmlentities($tag_name);
$tag_name_json = htmlentities(json_encode($tag_name), ENT_QUOTES);
$count = $tag['count'];
$unread = $tag['unread'];
$tag_classes = array();
if (++$n % 2) {
$tag_classes[] = 'odd-row';
}
if (in_array($tag_name, $what_a)) {
$tag_classes[] = 'current-view';
}
$tag_classes = implode(' ', $tag_classes);
if (!empty($tag_classes)) {
$tag_classes = ' class="' . $tag_classes . '"';
}
$tagline .= ' <tr' . $tag_classes . '>';
$tagline .= '<td class="unread">';
if ($unread) {
$tagline .= '<a class="unread" href="' . fof_url('.', array('what' => "$tag_name unread", 'how' => 'paged')) . "\">$unread</a>/";
}
$tagline .= '<a href="' . fof_url('.', array('what' => $tag_name, 'how' => 'paged')) . "\">$count</a>";
$tagline .= '</td>';
$tagline .= '<td class="title"><b><a href="' . fof_url('.', array('what' => $tag_name, 'how' => 'paged')) . '">' . $tag_name_html . '</a></b></td>';
$tagline .= '<td class="controls"><a href="#" title="untag all items" onclick="return sb_del_tag_conf(' . $tag_name_json . ');">[x]</a></td>';
if ($sharing == 'all_tagged') {
$tagline .= '<td class="sharing"><a href="' . fof_url('./shared.php', array('user' => $fof_user_id, 'which' => $tag_name, 'how' => 'paged')) . '">[' . $tag_name_html . ']</a>';
}
$tagline .= '</tr>';
$taglines[] = $tagline;
}
if (!empty($taglines)) {
?>
<div id="tags">
<table cellspacing="0" cellpadding="1" border="0" id="taglist">
<tr class="heading"><td><span class="unread">#</span></td><td class="title">tag name</td><td class="controls">untag</td><?php if ($sharing == 'all_tagged') {
echo '<td class="sharing">shared page</td>';
}
?></tr>
<?php
echo implode("\n", $taglines);
?>
</table>
</div>
<!--tags end-->
<?php
}
?>
<?php
}
if (function_exists('fof_sidebar_tags_' . $sidebar_style)) {
call_user_func('fof_sidebar_tags_' . $sidebar_style);
} else {
fof_sidebar_tags_default();
}
?>
<div id="feeds">
<table cellspacing="0" cellpadding="1" border="0">
<thead class="hide-on-mobile">
<tr class="heading">
<?php
/* all possible columns */
$title = array('feed_age' => 'sort by last update time',
'max_date' => 'sort by last new item',
'feed_unread' => 'sort by number of unread items',
'feed_url' => 'sort by feed URL',
'feed_title' => 'sort by feed title',
'null' => '',
);
$name = array('feed_age' => 'age',
'max_date' => 'latest',
'feed_unread' => '<span class="unread">#</span>',
'feed_url' => 'feed',
'feed_title' => 'title',
'null' => '',
);
$column_class = array('feed_age' => 'update',
'max_date' => 'latest',
'feed_unread' => 'unread',
'feed_url' => 'source',
'feed_title' => 'title',
);
switch ($sidebar_style) {
case 'simple':
$columns = array('feed_url', 'feed_unread', 'feed_title');
break;
case 'fancy':
$columns = array('null', 'max_date', 'feed_unread', 'feed_title');
break;
default:
$columns = array('feed_age', 'max_date', 'feed_unread', 'feed_url', 'feed_title');
}
foreach ($columns as $col) {
if ($col == $order) {
$feed_order_toggle = $direction == 'asc' ? 'desc' : 'asc';
} else {
$feed_order_toggle = 'asc';
}
$onclick = "return change_feed_order('$col', '$feed_order_toggle')";
echo ' <th';
if (!empty($column_class[$col])) {
echo ' class="' . $column_class[$col] . '"';
}
echo '>';
echo '<span class="nowrap"><a href="#" title="' . $title[$col] . '" onclick="' . $onclick . '">';
echo $name[$col];
if ($col == $order) {
echo $direction == 'asc' ? '↓' : '↑';
}
echo "</a></span></th>\n";
}
?>
<th class="controls hide-on-mobile"></th>
</tr>
</thead>
<tbody>
<?php
$what_id = array_map('fof_db_get_tag_by_name', $what_a);
$t = 0;
foreach ($feeds as $row) {
$view_contrib = array_intersect($what_id, $row['subscription_prefs']['tags']);
$view_feed = (!empty($_GET['feed']) && $_GET['feed'] == $row['feed_id']);
echo '<tr id="f' . $row['feed_id'] . '" class="feed' . (++$t % 2 ? ' odd-row' : '') . ((count($view_contrib) || $view_feed) ? ' current-view' : '') . "\">\n";
echo fof_render_feed_row($row);
echo "</tr>\n";
}
?>
</tbody>
</table>
</div>
<!--sidebar end-->
<?php
/* ??? */
$order = fof_sidebar_get_key_($_GET, 'order', 'title');
$direction = fof_sidebar_get_key_($_GET, 'direction', 'asc');
?>