/
displaycomic.php
407 lines (358 loc) · 15.2 KB
/
displaycomic.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
394
395
396
397
398
399
400
401
402
403
404
405
406
407
<?php
// If any errors occur while searching for a comic file, the error messages will be pushed into here.
$comic_pathfinding_errors = array();
// If ComicPress Manager is installed, use the date format defined there. If not, default to
// Y-m-d.. It's best to use CPM's date definition for improved operability between theme and plugin.
if (defined("CPM_DATE_FORMAT")) {
define("CP_DATE_FORMAT", CPM_DATE_FORMAT);
} else {
define("CP_DATE_FORMAT", "Y-m-d");
}
// If you want to run multiple comics on a single day, define your additional filters here.
// Example: you want to run an additional comic with the filename 2008-01-01-a-my-new-years-comic.jpg.
// Define an additional filter in the list below:
//
// $comic_filename_filters['secondary'] = "{date}-a*.*";
//
// Then show the second comic on your page by calling the_comic with your filter name (PHP tags munged
// to maintain valid file syntax):
//
// < ?php the_comic('secondary'); ? >
//
// Note that it's quite possible to slurp up the wrong file if your expressions are too broad.
$comic_filename_filters = array();
$comic_filename_filters['default'] = "{date}*.*";
if (!function_exists('comicpress_display_comic_area')) {
function comicpress_display_comic_area() {
global $post; ?>
<div id="comic-wrap" class="comic-id-<?php echo $post->ID; ?>">
<div id="comic-head"><?php if (is_active_sidebar('over-comic')) get_sidebar('over'); ?></div>
<div class="clear"></div>
<?php if (is_active_sidebar('left-of-comic')) get_sidebar('comicleft'); ?>
<div id="comic">
<?php echo comicpress_display_comic(); ?>
</div>
<?php if (is_active_sidebar('right-of-comic')) get_sidebar('comicright'); ?>
<div class="clear"></div>
<div id="comic-foot"><?php if (is_active_sidebar('under-comic')) get_sidebar('under'); ?></div>
</div>
<?php }
}
function comicpress_display_comic_swf($post, $comic) {
$file_url = comicpress_themeinfo('baseurl') . comicpress_clean_filename($comic);
$height = get_post_meta( $post->ID, "fheight", true );
$width = get_post_meta( $post->ID, "fwidth", true );
if (empty($height)) $height = '300';
if (empty($width)) $width = '100%';
$output = "<object id=\"myId\" classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" width=\"{$width}\" height=\"{$height}\">\r\n";
$output .= " <param name=\"movie\" value=\"".$file_url."\" />\r\n";
$output .= "<!--[if !IE]>--><object type=\"application/x-shockwave-flash\" data=\"".$file_url."\" width=\"{$width}\" height=\"{$height}\"><!--<![endif]-->\r\n";
$output .= " <div>\r\n";
$output .= " <h1>Get Flash!</h1>\r\n";
$output .= " <p><a href=\"http://www.adobe.com/go/getflashplayer\"><img src=\"http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif\" alt=\"Get Adobe Flash player\" /></a></p>\r\n";
$output .= " </div>\r\n";
$output .= "<!--[if !IE]>--></object><!--<![endif]--></object>\r\n";
add_action('wp_footer', 'comicpress_init_comic_swf');
return apply_filters('comicpress_display_comic_swf',$output);
}
/**
* Display text when image (comic) is hovered
* Text is taken from a custom field named "hovertext"
*/
function comicpress_the_hovertext($override_post = null) {
global $post;
$post_to_use = !is_null($override_post) ? $override_post : $post;
$hovertext = get_post_meta( $post_to_use->ID, "hovertext", true );
return (empty($hovertext)) ? get_the_title($post_to_use->ID) : $hovertext;
}
function comicpress_init_comic_swf() {
wp_enqueue_script('swfobject', '', array(), false, true);
}
// This function will let authors who want to use comicpress as a way to output their books/text in a comic area as a page.
function comicpress_display_comic_text($comic) {
if (file_exists(comicpress_themeinfo('basedir') . '/' .$comic)) {
$output = file_get_contents(comicpress_themeinfo('basedir') . '/' .$comic);
}
return apply_filters('comicpress_display_comic_text', $output);
}
// Do the thumbnail display functions here.
function comicpress_display_comic_thumbnail($type = 'mini', $override_post = null, $use_post_image = false, $setwidth = 0, $multi = false) {
global $post;
$post_to_use = !empty($override_post) ? $override_post : $post;
// use_post_image if its set to true
if ($use_post_image) {
$post_image_id = get_post_thumbnail_id($post_to_use->ID);
if ($post_image_id) {
$thumbnail = wp_get_attachment_image_src( $post_image_id, 'post-thumbnail', false);
if ($thumbnail) (string)$thumbnail = $thumbnail[0];
}
}
if (empty($thumbnail)) {
$thumb_found = get_comic_path($type, $post_to_use);
$count = count($thumb_found);
// adjust the thumbnail directories of all of them not just one, time to stop outputting them singularly and do array
$thumbnail = array();
if (!empty($thumb_found)) {
foreach ($thumb_found as $thumb) {
$thumbnail[] = comicpress_themeinfo('baseurl') . comicpress_clean_filename($thumb);
}
}
}
if (empty($thumbnail)) {
// Catchall non-thumbnails and display the notfound.
$thumbnail = array();
$thumbnail[] = $thumbnail[] = get_template_directory_uri() . '/images/notfound.png';
}
$output = '';
$alttext = comicpress_the_hovertext($post_to_use);
if (is_array($thumbnail)) {
if ($multi) {
foreach ($thumbnail as $thumb) {
if ($setwidth) {
$output .= '<img src="'.$thumb.'" alt="'.$alttext.'" style="max-width:'.$setwidth.'px" class="comicthumbnail" title="'.$alttext.'" />'."\r\n";
} else {
$output .= '<img src="'.$thumb.'" alt="'.$alttext.'" class="comicthumbnail" title="'.$alttext.'" />'."\r\n";
}
}
} else {
$thumb = $thumbnail[0];
if ($setwidth) {
$output .= '<img src="'.$thumb.'" alt="'.$alttext.'" style="max-width:'.$setwidth.'px" class="comicthumbnail" title="'.$alttext.'" />'."\r\n";
} else {
$output .= '<img src="'.$thumb.'" alt="'.$alttext.'" class="comicthumbnail" title="'.$alttext.'" />'."\r\n";
}
}
} else {
if ($setwidth) {
$output = '<img src="'.$thumbnail.'" alt="'.$alttext.'" style="max-width:'.$setwidth.'px" class="comicthumbnail" title="'.$alttext.'" />'."\r\n";
} else {
$output = '<img src="'.$thumbnail.'" alt="'.$alttext.'" class="comicthumbnail" title="'.$alttext.'" />'."\r\n";
}
}
// if ($count > 1) $output = $count.' comics attached.<br />'.$output;
return apply_filters('comicpress_display_comic_thumbnail', $output);
}
// TODO: Add the hovertext - rascal code and click to next INSIDE this.
if (!function_exists('comicpress_display_comic_image')) {
function comicpress_display_comic_image($post, $comic) {
global $wp_query;
$file_url = comicpress_themeinfo('baseurl') . comicpress_clean_filename($comic);
$alt_text = comicpress_the_hovertext($post);
if (!is_search() && !is_archive() && !is_feed()) {
$ok = $oktoo = true;;
$href_to_use = $before_output = $add_href = $after_output = $add_tt_class = '';
if (comicpress_themeinfo('enable_comic_lightbox')) {
$tags = wp_get_post_tags($post->ID);
$tagsarray = array();
if (is_array($tags) && !empty($tags)) {
foreach ($tags as $tag) {
$tagsarray[] = $tag->slug;
}
if (in_array('fullpage', $tagsarray)) {
$add_href = '<a href="'.$file_url.'" title="'.$alt_text.'" rel="lightbox">';
$after_output = '</a>';
$ok = false;
}
}
}
if (comicpress_themeinfo('rascal_says') && !empty($alt_text) && $ok) {
$hovertext = get_post_meta( $post->ID, "hovertext", true );
$href_to_use = "#";
if (!empty($hovertext)) {
$before_output = '<span class="tooltip"><span class="top"> </span><span class="middle">'.$alt_text.'</span><span class="bottom"> </span></span>';
$add_href = '<a href="'.$href_to_use.'" class="tt" title="'.$post->post_title.'">';
$add_tt_class = ' class="tt"';
$after_output = '</a>';
$oktoo = false;
}
}
if (comicpress_themeinfo('comic_clicks_next') && $ok) {
$href_to_use = comicpress_get_next_comic_permalink();
$add_href = '<a href="'.$href_to_use.'" title="'.$alt_text.'"'.$add_tt_class.'>';
$after_output = '</a>';
}
}
$output = $add_href . $before_output . '<img src="'.$file_url.'" alt="'.$alt_text.'" title="'.$alt_text.'"/>' . $after_output;
return apply_filters('comicpress_display_comic_image', $output);
}
}
// jquery code image swap by @brianarn
function comicpress_display_comic() {
global $post;
$comics = get_comic_path('comic', $post);
$output = '';
if (is_array($comics)) {
$count = 1;
$outputlist = '';
$outputscript = '';
foreach ($comics as $comic) {
$comicsplit = explode(".", $comic);
switch (strtolower($comicsplit[1])) {
case 'swf':
$output .= '<div id="comic-'.$count.'" class="comicpane">';
$output .= comicpress_display_comic_swf($post, $comic);
$output .= "</div>\r\n";
$outputlist .= "<button id=\"show-".$count."\" type=\"button\">".$count."</button>\r\n";
$count += 1;
break;
case 'txt':
case 'inc':
case 'htm':
$output .= '<div id="comic-'.$count.'" class="comicpane">';
$output .= comicpress_display_comic_text($comic);
$output .= "</div>\r\n";
$outputlist .= "<button id=\"show-".$count."\" type=\"button\">".$count."</button>\r\n";
$count += 1;
break;
case 'png':
case 'gif':
case 'jpg':
case 'jpeg':
case 'tif':
case 'tiff':
case 'bmp':
default:
$output .= '<div id="comic-'.$count.'" class="comicpane">';
$output .= comicpress_display_comic_image($post, $comic);
$output .= "</div>\r\n";
$outputlist .= "<button id=\"show-".$count."\" type=\"button\">".$count."</button>\r\n";
$count += 1;
}
}
if ($count > 2 && comicpress_themeinfo('enable_multicomic_jquery')) {
// Add the script stuff before the rest here.
$output = $outputscript . $output;
}
}
return $output;
}
if (!function_exists('comicpress_comic_clicks_next')) {
function comicpress_comic_clicks_next($output) {
global $post, $wp_query;
if (is_search() || is_archive() || is_feed()) return $output;
$hovertext = comicpress_the_hovertext($post);
$next_comic = comicpress_get_next_comic_permalink();
$class = '';
if (comicpress_themeinfo('rascal_says')) {
$the_title = get_the_title($post);
$class='class="tt"';
} else {
$the_title = comicpress_the_hovertext($post);
}
$output = "<a {$class} href=\"{$next_comic}\" title=\"{$the_title}\">{$output}</a>\r\n";
return $output;
}
}
function comicpress_rascal_says($output) {
global $post, $wp_query;
if (is_search() || is_archive() || is_feed()) return $output;
$hovertext = get_post_meta( $post->ID, "hovertext", true );
$href_to_use = "#";
if (!empty($hovertext)) {
$output = preg_replace('#title="([^*]*)"#', '', $output);
$output = "<span class=\"tooltip\"><span class=\"top\"> </span><span class=\"middle\">{$hovertext}</span><span class=\"bottom\"> </span></span>{$output}\r\n";
}
if (comicpress_themeinfo('comic_clicks_next')) {
$href_to_use = comicpress_get_next_comic_permalink();
if (empty($href_to_use)) $href_to_use = "#";
$output = "<a href=\"{$href_to_use}\" class=\"tt\" title=\"".$post->post_title."\">{$output}</a>";
} else {
$output = "<a class=\"tt\" href=\"{$href_to_use}\" title=\"".$post->post_title."\">{$output}</a>";
}
return apply_filters('comicpress_rascal_says',$output);
}
/*
Old Method
if (comicpress_themeinfo('rascal_says')) {
add_filter('comicpress_display_comic_image', 'comicpress_rascal_says');
}
if (comicpress_themeinfo('comic_clicks_next') && !comicpress_themeinfo('rascal_says')) {
add_filter('comicpress_display_comic_image', 'comicpress_comic_clicks_next');
}
*/
/**
* Find a comic file in the filesystem.
* @param string $folder The folder name to search.
* @param string $override_post A WP Post object to use in place of global $post.
* @param string $filter The $comic_filename_filters to use.
* @return string The relative path to the comic file, or false if not found.
*/
function get_comic_path($folder = 'comic', $override_post = null, $filter = 'default') {
global $post, $comic_filename_filters, $comic_pathfinding_errors;
$post_to_use = !empty($override_post) ? $override_post : $post;
$meta_name = 'comic';
$comicfile = '';
if (function_exists('xlanguage_current_language_code'))
$meta_name .= '-'.xlanguage_current_language_code();
$comicfile = get_post_meta( $post_to_use->ID, $meta_name, false );
// Backswards compatibility here
switch ($folder) {
case "rss": $subfolder_to_use = comicpress_themeinfo('rss_comic_folder'); break;
case "archive": $subfolder_to_use = comicpress_themeinfo('archive_comic_folder'); break;
case "mini": $subfolder_to_use = comicpress_themeinfo('mini_comic_folder'); break;
case "comic": default: $subfolder_to_use = comicpress_themeinfo('comic_folder'); break;
}
$folder_to_use = comicpress_themeinfo('basedir') . $subfolder_to_use;
// if (!file_exists($folder_to_use . '/' . $comicfile) && $folder !== 'comic')
// $subfolder_to_use = comicpress_themeinfo('comic_folder');
if (!empty($comicfile)) {
// return this as an array if we want to include in the future multiple comics found type thing, keeping it compatible.
$newresults = array();
foreach ($comicfile as $comic) {
if (!file_exists($folder_to_use . '/' . $comic) && $folder !== 'comic')
$subfolder_to_use = comicpress_themeinfo('comic_folder');
$newresults[] = trailingslashit($subfolder_to_use) . trailingslashit($comic);
}
return $newresults;
} else {
// backwards compatibility
if (isset($comic_filename_filters[$filter])) {
$filter_to_use = $comic_filename_filters[$filter];
} else {
$filter_to_use = '{date}*.*';
}
$post_date = mysql2date(CP_DATE_FORMAT, $post_to_use->post_date);
$filter_with_date = str_replace('{date}', $post_date, $filter_to_use);
$results = array();
if (count($results = glob("${folder_to_use}/${filter_with_date}")) > 0) {
$newresults = array();
foreach ($results as $result) {
// Strip the base directory off.
$newresults[] = str_replace(comicpress_themeinfo('basedir'), '', $result);
}
return $newresults;
} else {
// fallback to the comics directory
$folder_to_use = trailingslashit(comicpress_themeinfo('basedir')) . comicpress_themeinfo('comic_folder');
if (count($results = glob("${folder_to_use}/${filter_with_date}")) > 0) {
$newresults = array();
foreach ($results as $result) {
// Strip the base directory off.
$newresults[] = str_replace(untrailingslashit(comicpress_themeinfo('basedir')), '', $result);
}
return $newresults;
}
}
}
$comic_pathfinding_errors[] = sprintf(__("Unable to find the file in the <strong>%s</strong> folder that matched the pattern <strong>%s</strong>. Check your WordPress and ComicPress settings.", 'comicpress'), $folder_to_use, $filter_with_date);
return false;
}
/**
* Find a comic file in the filesystem and return an absolute URL to that file.
* @param string $folder The folder name to search.
* @param string $override_post A WP Post object to use in place of global $post.
* @param string $filter The $comic_filename_filters to use.
* @return string The absolute URL to the comic file, or false if not found.
*/
function get_comic_url($folder = 'comic', $override_post = null, $filter = 'default') {
if (($results = get_comic_path($folder, $override_post, $filter)) !== false) {
$newresults = array();
foreach ($results as $result) {
ltrim($result, '/');
$newresults[] = trailingslashit( comicpress_themeinfo('baseurl') ) . $result;
}
return $newresults;
}
return false;
}
?>