/
navigation.php
235 lines (198 loc) · 6.78 KB
/
navigation.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
<?php
function comicpress_get_first_comic() {
return comicpress_get_terminal_post_in_category(comicpress_all_comic_categories_string(), true);
}
function comicpress_get_last_comic() {
return comicpress_get_terminal_post_in_category(comicpress_all_comic_categories_string(), false);
}
function comicpress_get_previous_comic($in_same_category = false, $category = null) { return comicpress_get_adjacent_comic($category, true, $in_same_category); }
function comicpress_get_next_comic($in_same_category = false, $category = null) { return comicpress_get_adjacent_comic($category, false, $in_same_category); }
/**
* Get the hyperlink to the first comic post in the database.
* @return string The hyperlink to the first comic post, or false.
*/
function comicpress_get_first_comic_permalink() {
$terminal = comicpress_get_first_comic();
if (!empty($terminal))
return !empty($terminal) ? apply_filters('comicpress_get_first_comic_permalink',get_permalink($terminal->ID)) : false;
}
/**
* Get the hyperlink to the last comic post in the database.
* @return string The hyperlink to the first comic post, or false.
*/
function comicpress_get_last_comic_permalink() {
$terminal = comicpress_get_last_comic();
return !empty($terminal) ? apply_filters('comicpress_get_last_comic_permalink',get_permalink($terminal->ID)) : false;
}
/**
* Get the link to the previous comic from the current one.
*/
function comicpress_previous_comic_link($format, $link) {
previous_post_link($format, $link, false, comicpress_all_blog_categories_array_and());
}
/**
* Get the link to the next comic from the current one.
*/
function comicpress_next_comic_link($format, $link) {
next_post_link($format, $link, false, comicpress_all_blog_categories_array_and());
}
/**
* This is function comicpress_get_next_comic_permalink
*
* @return mixed false if no next comic permalink, else return the permalink
*
*/
function comicpress_get_next_comic_permalink($in_same_category = false) {
$next_comic = comicpress_get_next_comic($in_same_category);
if (is_object($next_comic)) {
if (isset($next_comic->ID)) {
return apply_filters('comicpress_get_next_comic_permalink',get_permalink($next_comic->ID));
}
}
return false;
}
/**
* This is function comicpress_get_previous_comic_permalink
*
* @return mixed false if there is no permalink or next previous comic
*
*/
function comicpress_get_previous_comic_permalink($in_same_category = false) {
$prev_comic = comicpress_get_previous_comic($in_same_category);
if (is_object($prev_comic)) {
if (isset($prev_comic->ID)) {
return apply_filters('comicpress_get_previous_comic_permalink',get_permalink($prev_comic->ID));
}
}
return false;
}
/**
* Get the adjacent comic from the current one.
* @param int $category The category to use.
* @param boolean $previous True if the previous chronological comic should be retrieved.
* @return array The WordPress post object for the comic post.
*/
function comicpress_get_adjacent_comic($category, $previous = false, $in_same_category = false) {
if (!empty($category)) {
$categories_to_exclude = comicpress_get_string_to_exclude_all_but_provided_categories($category);
} else {
$categories_to_exclude = comicpress_all_blog_categories_array_and();
}
return get_adjacent_post($in_same_category, $categories_to_exclude, $previous);
}
/**
* Find the terminal post in a specific category.
*/
function comicpress_get_terminal_post_in_category($categoryID, $first = true, $storyline = false) {
global $post;
if (empty($categoryID)) $categoryID = comicpress_themeinfo('comiccat');
$excluded_cats = array();
if ($storyline) {
// echo "CAT ID: ".$categoryID."<br />";
$excluded_catlist = get_categories(array('child_of' => $categoryID));
foreach ($excluded_catlist as $catlist) {
$excluded_cats[] = $catlist->cat_ID;
}
}
$sortOrder = $first ? "asc" : "desc";
$categoryID = explode(',', $categoryID);
if (!empty($excluded_cats)) {
$args = array(
'category__in' => $categoryID,
'category__not_in' => $excluded_cats,
'order' => $sortOrder,
'posts_per_page' => 1
);
} else {;
$args = array(
'category__in' => $categoryID,
'order' => $sortOrder,
'posts_per_page' => 1
);
}
$terminalComicQuery = new WP_Query($args);
$terminalPost = false;
if ($terminalComicQuery->have_posts()) {
$terminalPost = reset($terminalComicQuery->posts);
}
return $terminalPost;
}
/**
* Find the first post in the storyline prior to the current one.
*/
function comicpress_get_previous_storyline_start() {
global $post;
if (($category_id = comicpress_get_adjacent_storyline_category_id(false)) !== false) {
$terminal_post = comicpress_get_terminal_post_in_category($category_id, true, true);
if ($post->ID == $terminal_post->ID) return false;
$category = get_the_category($post->ID);
$current_terminal_post = comicpress_get_terminal_post_in_category($category[0]->cat_ID);
if ($current_terminal_post->ID == $post->ID) {
return $terminal_post;
} else {
return $current_terminal_post;
}
}
return false;
}
function comicpress_get_previous_storyline_start_permalink() {
$prev_story = comicpress_get_previous_storyline_start();
if (is_object($prev_story)) {
if (isset($prev_story->ID)) {
return get_permalink($prev_story->ID);
}
}
return false;
}
/**
* Find the first post in the storyline following to the current one.
*/
function comicpress_get_next_storyline_start() {
if (($category_id = comicpress_get_adjacent_storyline_category_id(true)) !== false) {
return comicpress_get_terminal_post_in_category($category_id, true, true);
}
return false;
}
function comicpress_get_next_storyline_start_permalink() {
$next_story = comicpress_get_next_storyline_start();
if (is_object($next_story)) {
if (isset($next_story->ID)) {
return get_permalink($next_story->ID);
}
}
return false;
}
function comicpress_get_adjacent_storyline_category_id($next = false) {
global $post, $category_tree;
$categories = get_the_category($post->ID);
if (is_array($categories)) {
$category_id = $categories[0]->cat_ID;
for ($i = 0, $il = count($category_tree); $i < $il; ++$i) {
$storyline_category_id = end(explode("/", $category_tree[$i]));
if ($storyline_category_id == $category_id) {
$target_index = false;
if ($next) {
$target_index = $i + 1;
} else {
$target_index = $i - 1;
}
if (isset($category_tree[$target_index])) {
return end(explode('/', $category_tree[$target_index]));
}
}
}
}
return false;
}
function comicpress_get_terminal_post_of_chapter_permalink($first = true) {
global $post;
$category = get_the_category($post->ID);
$term_post = comicpress_get_terminal_post_in_category($category[0]->cat_ID, $first, false);
if (is_object($term_post)) {
if (isset($term_post->ID)) {
return get_permalink($term_post->ID);
}
}
return false;
}
?>