forked from gbishop/TarHeelGameplay
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfavorites.php
More file actions
91 lines (81 loc) · 2.25 KB
/
favorites.php
File metadata and controls
91 lines (81 loc) · 2.25 KB
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
<?php
/*
Template Name: Favorites
GET: Return a list of books that match the query
*/
?>
<?php
// redirect on an empty URL so the page is bookmarkable
if (! array_key_exists('favorites', $_GET) && ! array_key_exists('collection', $_GET) && THR('favorites')) {
$loc = favorites_url();
header('Location: ' . $loc);
die();
}
// redirect on A or R URLs so the resulting URL reflects the state
if (array_key_exists('favorites', $_GET) && preg_match('/^[AR]/', $_GET['favorites'])) {
$loc = favorites_url();
header('Location: ' . $loc);
die();
}
$favorites = THR('favorites');
$fav_array = explode(',', $favorites);
$count = 24;
$cp1 = $count + 1; // ask for one more to determine if there are more
$page = THR('fpage');
$offset = ($page - 1) * $count;
$args = array(
'post__in' => $fav_array,
'posts_per_page' => $cp1,
'offset' => $offset,
'category' => '',
'category_name' => 'Gameplays',
'orderby' => 'date',
'order' => 'DESC',
'include' => '',
'exclude' => '',
'meta_key' => '',
'meta_value' => '',
'post_type' => 'post',
'post_mime_type' => '',
'post_parent' => '',
'author' => '',
'post_status' => 'publish'
);
$posts = get_posts($args);
$json = array_key_exists('json', $_GET) && $_GET['json'] == 1;
$nrows = count($posts);
$result = posts_to_find_results($posts, $nrows, $count);
if (0) { // force an error for testing
header("HTTP/1.0 500 Internal Error");
die();
}
if (0) { // delay for testing
sleep(3);
}
if ($json) {
$output = json_encode($result);
header('Content-Type: application/json');
header('Content-Size: ' . strlen($output));
echo $output;
die();
}
setTHR('findAnotherLink', '/favorites/');
?>
<?php
thr_header('favorites-page', array('settings'=>true, 'chooseFavorites'=>true));
?>
<!-- favorites.php -->
<?php
$view = array();
$view['searchForm'] = '';
$result['favorites'] = true;
$view['bookList'] = template_render('bookList', $result);
if ($page > 1) {
$view['backLink'] = favorites_url($page-1);
}
if ($result['more']) {
$view['nextLink'] = favorites_url($page+1);
}
echo template_render('find', $view);
thr_footer();
?>