forked from gbishop/TarHeelReaderTheme
-
Notifications
You must be signed in to change notification settings - Fork 0
/
single-book.php
81 lines (78 loc) · 3.39 KB
/
single-book.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
<?php if (have_posts()):
while (have_posts()):
the_post();
$book = ParseBookPost($post);
$pages = $book['pages'];
$Npages = count($pages);
$link = $book['link'];
$preview = substr($link, 0, 4) == '/?p=';
$findLink = THR('findAnotherLink');
$mp3 = null;
if (has_speech($book['language'])) {
$voice = THR('voice');
if ($voice != 'silent') {
$v = $voice[0];
$id = $book['ID'];
$folder = substr($id, -2) . '/' . $id;
$bust = $book['bust'];
$mp3 = "/cache/speech/$folder/$page-$v.mp3?bust=$bust";
echo "<!-- $mp3 -->";
}
}
$pageNumber = $page;
// setup page classes
$addClass = '';
if ($pageNumber == 1) {
$addClass = ' front-page';
} elseif ($pageNumber > $Npages) {
$addClass = ' choice-page';
}
$hview = array();
$hview['noTitle'] = true;
if ($pageNumber == 1) {
$hview['isFavorite'] = preg_match('/(^|,)' . $id . '(,|$)/', THR('favorites'));
$hview['ID'] = $book['ID']; // book ID for download/settings links in the menu
$hview['settings'] = true;
}
thr_header('thr-book-page thr-colors' . $addClass, $hview);
$view = array();
$view['frontPage'] = $pageNumber == 1;
$view['title'] = $book['title'];
$view['textColor'] = THR('textColor');
$view['pageColor'] = THR('pageColor');
$view['ID'] = $book['ID'];
$N = count($book['pages']);
if ($pageNumber <= $N) {
$view['author'] = $book['author'];
$view['pageNumber'] = $pageNumber;
$view['backto'] = urlencode($link);
$view['image'] = $book['pages'][max(1, $pageNumber-1)];
$view['caption'] = $view['image']['text'];
if ($pageNumber == 1) {
$view['backLink'] = $findLink;
$view['nextLink'] = pageLink($link, 2);
} else {
$view['backLink'] = pageLink($link, $pageNumber-1);
$view['nextLink'] = pageLink($link, $pageNumber+1);
}
setImageSizes($view['image']);
if ($mp3) $view['audio'] = audio($mp3);
echo template_render('bookPage', $view);
} else {
$view['nextLink'] = pageLink($link, $pageNumber+1);
$view['link'] = $link;
$view['findLink'] = $findLink;
$view['what'] = $pageNumber == $N+1;
$view['rate'] = $pageNumber == $N+2;
$view['thanks'] = $pageNumber >= $N+3;
$rating = getParam('rating', '', '/[123]/');
if ($rating && $view['thanks']) {
$rating = intval($rating, 10);
$view['rating'] = rating_info(update_book_rating($post->ID, $rating));
} else {
$view['rating'] = rating_info($book['rating_value']);
}
echo template_render('choicePage', $view);
}
endwhile; endif;
thr_footer(); ?>