forked from gbishop/TarHeelGameplay
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfind.php
More file actions
97 lines (87 loc) · 2.38 KB
/
find.php
File metadata and controls
97 lines (87 loc) · 2.38 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
92
93
94
95
96
97
<?php
/*
Template Name: FindBooks
GET: Return a list of books that match the query
*/
?>
<?php
$count = 24;
$cp1 = $count + 1;
$mq = array(
'relation' => 'AND',
array(
'key' => 'language',
'value' => THR('language'))
);
if (THR('audience'))
$mq[] = array(
'key' => 'audience',
'value' => THR('audience'));
if (THR('skill') > 0) {
$skill = THR('skill');
$mq[] = array(
'key' => 'dof',
'value' => $skill,
'compare' => ($skill < 2) ? '=' : '>=');
}
$args = array(
's' => THR('search'),
'posts_per_page' => $cp1,
'offset' => (THR('page') - 1) * $count,
'category_name' => 'Gameplays',
'tag' => THR('category'),
'meta_query' => $mq,
'orderby' => 'date',
'order' => 'DESC',
'post_type' => 'post',
'post_status' => 'publish'
);
$posts = get_posts($args);
$nrows = count($posts);
$json = getParam('json', 0, '/\d+/');
$result = posts_to_find_results($posts, $nrows, $count);
//print_r($result);
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();
}
// construct the searchForm view object
$searchFormData = $Templates['searchForm'];
foreach( $searchFormData['controls'] as &$control) {
if (!array_key_exists('name', $control)) {
continue;
}
if ($control['name'] == 'category') {
$control['options'] = array_merge($control['options'], $Templates['categories']);
} elseif ($control['name'] == 'language') {
$control['options'] = $Templates['languages'];
}
}
$searchFormData = setFormFromState($searchFormData);
setTHR('findAnotherLink', find_url()); // set the return to link to come back to this state
?>
<?php thr_header('find-page', array('settings'=>true, 'chooseFavorites'=>true)); ?>
<!-- find.php -->
<?php
$view = array();
$view['searchForm'] = template_render('form', $searchFormData);
$view['bookList'] = template_render('bookList', $result);
if ($page > 1) {
$view['backLink'] = find_url($page-1);
}
if ($result['more']) {
$view['nextLink'] = find_url($page+1);
}
echo template_render('find', $view);
thr_footer();
?>