diff --git a/includes/admin-scripts.js b/includes/admin-scripts.js deleted file mode 100644 index a95c0cb..0000000 --- a/includes/admin-scripts.js +++ /dev/null @@ -1,22 +0,0 @@ -/** - * This document contains javascript necessary to enhance certain WebComic administrative functions. - * - * @package WebComic - * @since 2.1.0 - */ - -jQuery( document ) . ready( function( $ ) { - $( '.orphans' ) . change ( function() { - if ( $( this ) . attr( 'value' ) == 'comic_post' ) - $( '#orphan_post_controls' ) . show( 0 ); - else - $( '#orphan_post_controls' ) . hide( 0 ); - } ); - - $( '.comic' ) . change ( function() { - if ( $( this ) . attr( 'value' ) == 'publish' ) - $( '#comic_post_controls' ) . show( 0 ); - else - $( '#comic_post_controls' ) . hide( 0 ); - } ); -} ); \ No newline at end of file diff --git a/includes/jquery.cookie.js b/includes/jquery.cookie.js deleted file mode 100644 index 6df1fac..0000000 --- a/includes/jquery.cookie.js +++ /dev/null @@ -1,96 +0,0 @@ -/** - * Cookie plugin - * - * Copyright (c) 2006 Klaus Hartl (stilbuero.de) - * Dual licensed under the MIT and GPL licenses: - * http://www.opensource.org/licenses/mit-license.php - * http://www.gnu.org/licenses/gpl.html - * - */ - -/** - * Create a cookie with the given name and value and other optional parameters. - * - * @example $.cookie('the_cookie', 'the_value'); - * @desc Set the value of a cookie. - * @example $.cookie('the_cookie', 'the_value', { expires: 7, path: '/', domain: 'jquery.com', secure: true }); - * @desc Create a cookie with all available options. - * @example $.cookie('the_cookie', 'the_value'); - * @desc Create a session cookie. - * @example $.cookie('the_cookie', null); - * @desc Delete a cookie by passing null as value. Keep in mind that you have to use the same path and domain - * used when the cookie was set. - * - * @param String name The name of the cookie. - * @param String value The value of the cookie. - * @param Object options An object literal containing key/value pairs to provide optional cookie attributes. - * @option Number|Date expires Either an integer specifying the expiration date from now on in days or a Date object. - * If a negative value is specified (e.g. a date in the past), the cookie will be deleted. - * If set to null or omitted, the cookie will be a session cookie and will not be retained - * when the the browser exits. - * @option String path The value of the path atribute of the cookie (default: path of page that created the cookie). - * @option String domain The value of the domain attribute of the cookie (default: domain of page that created the cookie). - * @option Boolean secure If true, the secure attribute of the cookie will be set and the cookie transmission will - * require a secure protocol (like HTTPS). - * @type undefined - * - * @name $.cookie - * @cat Plugins/Cookie - * @author Klaus Hartl/klaus.hartl@stilbuero.de - */ - -/** - * Get the value of a cookie with the given name. - * - * @example $.cookie('the_cookie'); - * @desc Get the value of a cookie. - * - * @param String name The name of the cookie. - * @return The value of the cookie. - * @type String - * - * @name $.cookie - * @cat Plugins/Cookie - * @author Klaus Hartl/klaus.hartl@stilbuero.de - */ -jQuery.cookie = function(name, value, options) { - if (typeof value != 'undefined') { // name and value given, set cookie - options = options || {}; - if (value === null) { - value = ''; - options.expires = -1; - } - var expires = ''; - if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) { - var date; - if (typeof options.expires == 'number') { - date = new Date(); - date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000)); - } else { - date = options.expires; - } - expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE - } - // CAUTION: Needed to parenthesize options.path and options.domain - // in the following expressions, otherwise they evaluate to undefined - // in the packed version for some reason... - var path = options.path ? '; path=' + (options.path) : ''; - var domain = options.domain ? '; domain=' + (options.domain) : ''; - var secure = options.secure ? '; secure' : ''; - document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join(''); - } else { // only name given, get cookie - var cookieValue = null; - if (document.cookie && document.cookie != '') { - var cookies = document.cookie.split(';'); - for (var i = 0; i < cookies.length; i++) { - var cookie = jQuery.trim(cookies[i]); - // Does this cookie string begin with the name we want? - if (cookie.substring(0, name.length + 1) == (name + '=')) { - cookieValue = decodeURIComponent(cookie.substring(name.length + 1)); - break; - } - } - } - return cookieValue; - } -}; \ No newline at end of file diff --git a/includes/jquery.konami.js b/includes/jquery.konami.js deleted file mode 100644 index 27f40e7..0000000 --- a/includes/jquery.konami.js +++ /dev/null @@ -1,59 +0,0 @@ -/*! - * jQuery Konami code trigger v. 0.1 - * - * Copyright (c) 2009 Joe Mastey - * Dual licensed under the MIT and GPL licenses: - * http://www.opensource.org/licenses/mit-license.php - * http://www.gnu.org/licenses/gpl.html - * - * Usage: - * // konami code unlocks the tetris - * $('#tetris').konami(function(){ - * $(this).show(); - * }); - * - * - * // enable all weapons on 'idkfa'. - * // note that each weapon must be unlocked by its own code entry - * $('.weapon').konami(function(){ - * $(this).addClass('enabled'); - * }, {'code':[73, 68, 75, 70, 65]}); - * - * - * // listens on any element that can trigger a keyup event. - * // unlocks all weapons at once - * $(document).konami(function(){ - * $('.weapon').addClass('enabled'); - * }, {'code':[73, 68, 75, 70, 65]}); - * - * - */ -(function($){ - $.fn.konami = function( fn, params ) { - params = $.extend( {}, $.fn.konami.params, params ); - this.each(function(){ - var tgt = $(this); - tgt.bind( 'konami', fn ) - .bind( 'keyup', function(event) { $.fn.konami.checkCode( event, params, tgt ); } ); - }); - return this; - }; - - $.fn.konami.params = { - 'code' : [38, 38, 40, 40, 37, 39, 37, 39, 66, 65], - 'step' : 0 - }; - - $.fn.konami.checkCode = function( event, params, tgt ) { - if(event.keyCode == params.code[params.step]) { - params.step++; - } else { - params.step = 0; - } - - if(params.step == params.code.length) { - tgt.trigger('konami'); - params.step = 0; - } - }; -})(jQuery); \ No newline at end of file diff --git a/includes/scripts.js b/includes/scripts.js deleted file mode 100644 index 06228a5..0000000 --- a/includes/scripts.js +++ /dev/null @@ -1,61 +0,0 @@ -/** - * This document contains javascript necessary to enhance certain WebComic functions. - * - * @package WebComic - * @since 2.0.0 - */ - -jQuery( document ) . ready( function( $ ) { - /** Jump to the selected comic or chapter for dropdown_comics() */ - $( '.dropdown-comics' ) . change ( function() { if ( $( this ) . attr( 'value' ) != 0 ) window . location = $( this ) . attr( 'value' ); } ); - - /** Set, go to, or clear the comic bookmark using the links generated by bookmark_comic() */ - $( '.bookmark-comic .bookmark-this' ) . click( function() { var s = $( this ) . attr( 'rel' ); ; $.cookie( 'webcomic-bookmark' + s, window.location, { expires: 365, path: '/' } ); } ); - $( '.bookmark-comic .bookmark-goto' ) . click( function() { var s = $( this ) . attr( 'rel' ); if ( $.cookie( 'webcomic-bookmark' + s ) ) window.location = $.cookie( 'webcomic-bookmark' + s ); } ); - $( '.bookmark-comic .bookmark-clear' ) . click( function() { var s = $( this ) . attr( 'rel' ); $.cookie( 'webcomic-bookmark' + s, null, { path: '/' } ); } ); - - /** Automatic human validation for transcript.php */ - $( '#transcriptform textarea' ) . focus( function() { $( 'input[name=trans_human]' ) . val( '1' ); } ); - - /** AJAX-ify the submit transcript form for transcript.php */ - $( '#transcriptform' ) . ajaxForm( { target: '#transcript-response' } ); - $( '#transcriptform input[name=comic_transcript_submit]' ) . attr( 'value', '2' ); - - /** Keyboard Shotcuts */ - $.hotkeys.add( 'shift+down', { disableInInput: true }, function() { if ( $( '.random-comic-link.kbd-shortcut' ) . attr( 'href' ) ) window . location = $( '.random-comic-link' ) . attr( 'href' ); } ); - $.hotkeys.add( 'shift+left', { disableInInput: true }, function() { if ( $( '.first-comic-link.kbd-shortcut' ) . attr( 'href' ) ) window . location = $( '.first-comic-link' ) . attr( 'href' ); } ); - $.hotkeys.add( 'shift+right', { disableInInput: true }, function() { if ( $( '.last-comic-link.kbd-shortcut' ) . attr( 'href' ) ) window . location = $( '.last-comic-link' ) . attr( 'href' ); } ); - $.hotkeys.add( 'left', { disableInInput: true }, function() { if ( $( '.previous-comic-link.kbd-shortcut' ) . attr( 'href' ) ) window . location = $( '.previous-comic-link' ) . attr( 'href' ); } ); - $.hotkeys.add( 'right', { disableInInput: true }, function() { if ( $( '.next-comic-link.kbd-shortcut' ) . attr( 'href' ) ) window . location = $( '.next-comic-link' ) . attr( 'href' ); } ); - - /** Konami Code */ - $( document ) . konami( function() { - var i = Math . floor( Math . random() * 100 ); - - if ( i < 33 ) { - $.getScript( 'http://www.cornify.com/js/cornify.js', function() { - cornify_add(); - $( document ) . keydown( cornify_add ); - } ); - } else if ( i < 66 ) { - window . location = 'http://www.youtube.com/watch?v=icrNkmf9uyQ'; - } else if ( i < 99 ) { - i = Math . floor( Math . random() * 10 ); - - switch ( i ) { - case 0: window . location = 'http://byzemperors.com/'; - case 1: window . location = 'http://wiglafandmordred.com/'; - case 2: window . location = 'http://fesworks.com/'; - case 3: window . location = 'http://parasitepublishing.com/wordpress/'; - case 4: window . location = 'http://spiltinkstudios.com/'; - case 5: window . location = 'http://www.bloopcomic.com/'; - case 6: window . location = 'http://www.senshuu.com/'; - case 7: window . location = 'http://www.nattybumpercar.com/'; - case 8: window . location = 'http://www.goonpatrol.com/'; - case 9: window . location = 'http://www.connectedconcepts.net/'; - } - } else { - window . location = 'http://maikeruon.com/webcomic/special?=' . document . domain; - } - } ); -} ); \ No newline at end of file diff --git a/includes/transcript.php b/includes/transcript.php deleted file mode 100644 index 1fdc2aa..0000000 --- a/includes/transcript.php +++ /dev/null @@ -1,49 +0,0 @@ -' . __('This post is password protected. Enter the password to view the transcript.', 'webcomic' ) . '

'; - return; - } -?> - - - - - -

-
- - - -

-
- -

logged in to transcribe.', 'webcomic' ), get_option( 'siteurl' ) . '/wp-login.php?redirect_to=' . urlencode( get_permalink() ) ); ?>

- -
-
- -

%s', 'webcomic' ), get_option( 'siteurl' ) . '/wp-admin/profile.php', $user_identity ); ?>

- -

-

-

- -

- -

-
- -
- - \ No newline at end of file diff --git a/includes/wc-admin-chapters.php b/includes/wc-admin-chapters.php deleted file mode 100644 index 3c79ad6..0000000 --- a/includes/wc-admin-chapters.php +++ /dev/null @@ -1,320 +0,0 @@ - $chapter_name, 'slug' => $chapter_nicename, 'parent' => $chapter_parent, 'description' => $chapter_description ) ) ) ) - $updated = sprintf( __( 'Updated chapter “%s“', 'webcomic'), $chapter_name ); - elseif ( 1 == $update_error ) - $error = __( 'A chapter name must be provided.', 'webcomic' ); - elseif ( 2 == $update_error ) - $error = __( 'A chapter with that slug already exists.', 'webcomic' ); - else - $error = __( 'The chapter could not be updated.', 'webcomic' ); - } - - /** Attempt to create a new chapter */ - if ( 'chapter_add' == $_REQUEST[ 'action' ] ) { - check_admin_referer( 'chapter_add' ); - - $chapter_name = trim( $_REQUEST[ 'chapter_name' ] ); - $chapter_nicename = ( $_REQUEST[ 'chapter_nicename' ] ) ? sanitize_title( $_REQUEST[ 'chapter_nicename' ] ) : sanitize_title( $_REQUEST[ 'chapter_name' ] ); - $chapter_parent = ( $_REQUEST[ 'chapter_parent' ] ) ? $_REQUEST[ 'chapter_parent' ] : $series; - $chapter_description = $_REQUEST[ 'chapter_description' ]; - - if ( !$chapter_name ) { - $add_error = 1; - } elseif ( $_REQUEST[ 'chapter_nicename' ] && is_term( $chapter_nicename, 'chapter' ) ) { - $add_error = 2; - } else { - if ( !is_wp_error( wp_insert_term( $chapter_name, 'chapter', array( 'description' => $chapter_description, 'parent' => $chapter_parent, 'slug' => $chapter_nicename ) ) ) ) - $updated = sprintf( __( 'Added new chapter “%s“', 'webcomic' ), $chapter_name ); - else - $error = __( 'The chapter could not be added.', 'webcomic' ); - } - } - - /** Attempt to create a new chapter */ - if ( 'chapter_delete' == $_REQUEST[ 'action' ] ) { - check_admin_referer( 'chapter_delete' ); - - if ( $_REQUEST['is_volume'] ) { - $the_chapter = get_the_chapter( $_REQUEST[ 'chapter' ] ); - $children = get_term_children( $_REQUEST[ 'chapter' ], 'chapter' ); - $extra = __( ' and all the chapters it contained.', 'webcomic' ); - - foreach ( $children as $chapter ) { - $posts = get_objects_in_term( $chapter, 'chapter' ); - - foreach ( $posts as $_post ) - wp_delete_object_term_relationships( $_post, 'chapter' ); - - if ( $chapter == $current_chapters[ $the_series ] ) - $current_chapters[ $the_series ] = -1; - - wp_delete_term( $chapter,'chapter' ); - } - - update_option( 'comic_current_chapter', $current_chapters ); - wp_delete_term( $_REQUEST[ 'chapter' ], 'chapter' ); - } else { - $the_chapter = get_the_chapter( $_REQUEST[ 'chapter' ] ); - - $posts = get_objects_in_term( $_REQUEST[ 'chapter' ], 'chapter' ); - - foreach ( $posts as $_post ) - wp_delete_object_term_relationships( $_post, 'chapter' ); - - if ( $_REQUEST[ 'chapter' ] == $current_chapters[ $the_series ] ) { - $current_chapters[ $the_series ] = -1; - update_option( 'comic_current_chapter', $current_chapters ); - } - - wp_delete_term( $_REQUEST[ 'chapter' ], 'chapter' ); - } - - $updated =sprintf( __( 'Deleted “%1$s“%2$s', 'webcomic' ), $the_chapter->title, $extra ); - } - - //Display any messages - if ( $updated ) - echo '

' . $updated . '

'; - - if ( $error ) - echo '

' . $error . '

'; - - $collection = get_the_collection( 'hide_empty=0&depth=3&series=' . $series ); -?> -
-
icon
-

' . sprintf( __( 'This is a comic series. Changing the Chapter Slug will also rename the directory %s to match the new slug.', 'webcomic'), get_comic_directory( 'url', false, $category->term_id ), get_comic_directory( 'url', false, $category->term_id ) ) . '

'; -?> -

-
- - - - - - - - - - - - - - - - - - - - -

-

-
- -
- -
-
-

- - - - -

-
- -

-
-

- - - -

-
-
-
- - - - - - - - - - - - - - - - - - - - - - - - - $series->volumes ) { { foreach ( array_keys( get_object_vars( $collection->$series->volumes ) ) as $volume ) { $i++; ?> - > - - - - - - $series->volumes->$volume->chapters ) ) as $chapter ) { $i++; ?> - $series->volumes->$volume->chapters->$chapter->ID == $current_chapters[ $series ] ) echo ' style="background-color:#fdf9c6"'; ?>> - - - - - - - -
- $series->title ); ?>' class="row-title">$series->title; ?> -
-
$series->description; ?>$series->slug; ?>$series->count; ?>
- $series->volumes->$volume->title ); ?>" class="row-title">— $series->volumes->$volume->title; ?> - - $series->volumes->$volume->description; ?>$series->volumes->$volume->slug; ?>$series->volumes->$volume->count; ?>
- $series->volumes->$volume->chapters->$chapter->title ); ?>' class="row-title">— — $series->volumes->$volume->chapters->$chapter->title; ?> -
- - $series->volumes->$volume->chapters->$chapter->ID != $current_chapters[ $series ] ) { ?> - | - - | - - | $series->volumes->$volume->chapters->$chapter->title ) ); ?>')) { return true;}return false;"> -
-
$series->volumes->$volume->chapters->$chapter->description; ?>$series->volumes->$volume->chapters->$chapter->slug; ?>$series->volumes->$volume->chapters->$chapter->count; ?>
- $series->volumes ) ) ) { ?> -

»

- -
-
-
-
-
-

-
- -
> - - /> -

-
-

' . __( 'A chapter with that slug already exists. Chapter slugs must be unique across all series.', 'webcomic' ) . '

'; ?> -
> - - -

-
-
- - -

None to turn this chapter into a new volume that you can assign other chapters to.', 'webcomic' ); ?>

-
-
- - -

-
-

- - - -

- -
-
- - - - \ No newline at end of file diff --git a/includes/wc-admin-library.php b/includes/wc-admin-library.php deleted file mode 100644 index 5bec745..0000000 --- a/includes/wc-admin-library.php +++ /dev/null @@ -1,999 +0,0 @@ -ID, 'comic_library_view' ) ) - update_usermeta( $current_user->ID, 'comic_library_view', 'list' ); - if ( isset( $_REQUEST[ 'comic_library_view' ] ) ) - update_usermeta( $current_user->ID, 'comic_library_view', $_REQUEST[ 'comic_library_view' ] ); - - $lib_view = get_usermeta( $current_user->ID, 'comic_library_view' ); - - /** Set or update comics per page */ - if ( !get_usermeta( $current_user->ID, 'comics_per_page' ) ) - update_usermeta( $current_user->ID, 'comics_per_page', 20 ); - if ( isset( $_REQUEST[ 'comics_per_page' ] ) ) - update_usermeta( $current_user->ID, 'comics_per_page', $_REQUEST[ 'comics_per_page' ] ); - - $comics_per_page = get_usermeta( $current_user->ID, 'comics_per_page' ); - - /** Attempmt to update posts being matched with comics using the fallback method */ - if ( 'comic_fallback_update' == $_REQUEST[ 'action' ] ) { - $comics = comic_loop( -1, $series ); while ( $comics->have_posts() ) : $comics->the_post(); - $comic = get_the_comic(); - - if ( $comic->file && $comic->fallback ) { - if ( !add_post_meta( $comic->ID, 'comic_file', $comic->file_name, true ) ) - update_post_meta( $comic->ID, 'comic_file', $comic->file_name ); - - if ( $comic->large ) { - if ( !add_post_meta( $comic->ID, 'comic_large', $comic->large_name, true ) ) - update_post_meta( $comic->ID, 'comic_large', $comic->large_name ); - } - - if ( $comic->medium ) { - if ( !add_post_meta( $comic->ID, 'comic_medium', $comic->medium_name, true ) ) - update_post_meta( $comic->ID, 'comic_medium', $comic->medium_name ); - } - - if ( $comic->thumb ) { - if ( !add_post_meta( $comic->ID, 'comic_thumb', $comic->thumb_name, true ) ) - update_post_meta( $comic->ID, 'comic_thumb', $comic->thumb_name ); - } - - $i++; - } - endwhile; - - $updated = sprintf( __( '%d fallback comics updated.', 'webcomic' ), $i ); - - $i = 0; - } - - /** Attempt to upload the selected file, generate comic thumbnails, and create a post */ - if ( 'comic_upload' == $_REQUEST[ 'action' ] && 0 === $_FILES[ 'new_comic_file' ][ 'error' ] ) { - check_admin_referer( 'comic_upload' ); - - $file = pathinfo( $_FILES[ 'new_comic_file' ][ 'name' ] ); - - //Validate the file format. Files must be gif, jpg, jpeg, png, swf, or zip. - switch ( strtolower( $file[ 'extension' ] ) ) { - case 'gif': - case 'jpg': - case 'jpeg': - case 'png': - case 'swf': - case 'zip': break; - default: $invalid_format = true; - } - - if ( !$invalid_format && 'zip' == strtolower( $file[ 'extension' ] ) ) { - $zip = zip_open( $_FILES[ 'new_comic_file' ][ 'tmp_name' ] ); - - if ( is_resource( $zip ) ) { - while ( $zip_entry = zip_read( $zip ) ) { - $target_path = $file_path . zip_entry_name( $zip_entry ); - - if ( ( !is_file( $target_path ) || $_REQUEST[ 'new_comic_overwrite' ] ) && zip_entry_open( $zip, $zip_entry ) ) { - $zip_content = zip_entry_read( $zip_entry, zip_entry_filesize( $zip_entry ) ); - $zip_extension = substr( strrchr( zip_entry_name( $zip_entry ), '.' ), 1 ); - - if ( 'gif' == $zip_extension ) { - $new_comic = imagegif( imagecreatefromstring( $zip_content ), $target_path ); - } elseif ( 'jpg' == $zip_extension || 'jpeg' == $zip_extension ) { - $new_comic = imagejpeg( imagecreatefromstring( $zip_content ), $target_path ); - } elseif ( 'png' == $zip_extension ) { - $new_comic = imagepng( imagecreatefromstring( $zip_content ), $target_path ); - } elseif ( 'swf' == $zip_extension ) { //Flash comic - $new_comic = fopen( $target_path, 'w' ); - fwrite( $new_comic, $zip_content ); - fclose( $new_comic ); - } - - if ( $new_comic ) { - //Extraction counter - $i++; - - //Set the correct file permissions based on the server operating system - if ( strpos( PHP_OS, 'WIN' ) ) - chmod( $target_path, 0777 ); - else - chmod( $target_path, 0664 ); - - //Get the file information - $img_dim = getimagesize( $target_path ); - - //Attempt to create alternative sizes if this isn't an swf file - if ( 'application/x-shockwave-flash' != $img_dim[ 'mime' ] ) { - - //Get the specified alternative image dimensions for thumbnail generation - $img_lw = get_option( 'comic_large_size_w' ); - $img_lh = get_option( 'comic_large_size_h' ); - $img_mw = get_option( 'comic_medium_size_w' ); - $img_mh = get_option( 'comic_medium_size_h' ); - $img_tw = get_option( 'comic_thumb_size_w' ); - $img_th = get_option( 'comic_thumb_size_h' ); - $img_crop = get_option( 'comic_thumb_crop' ) ? true : false; - - //Generate a new large size image - if ( $img_dim[ 0 ] > $img_lw || $img_dim[ 1 ] > $img_lh ) - image_resize( $target_path, $img_lw, $img_lh, 0, 'large', $thumb_path ); - - //Generate a new medium size image - if ( $img_dim[ 0 ] > $img_mw || $img_dim[ 1 ] > $img_mh ) - image_resize( $target_path, $img_mw, $img_mh, 0, 'medium', $thumb_path ); - - //Generate a new thumbnail size image - if ( $img_dim[ 0 ] > $img_tw || $img_dim[ 1 ] > $img_th ) - image_resize( $target_path, $img_tw, $img_th, $img_crop, 'thumb', $thumb_path ); - } - } - - unset( $new_comic ); - zip_entry_close( $zip_entry ); - } - } - - if ( $i ) - $updated = sprintf( __( '%s comics successfully extracted from the archive.', 'webcomic' ), $i ); - else - $error = sprintf( __( 'No comics could be extracted from the archive.', 'webcomic' ), $i ); - } else { - switch ( $zip ) { - default: $error = __( 'An error occurred.', 'webcomic' ); - } - } - - zip_close( $zip ); - } elseif ( !$invalid_format ) { - //Set the filename key for older versions of PHP - if ( !$file[ 'filename' ] ) - $file[ 'filename' ] = substr( $file[ 'basename' ], 0, strlen( $file[ 'basename' ] ) - strlen( $file[ 'extension' ] ) - 1 ); - - //Generate a file hash if secure filenames are enabled - $hash = ( get_option( 'comic_secure_names' ) ) ? '-' . substr( md5( uniqid( rand() ) ), 0, 7) : ''; - - //Set the target path for the new file - $target_path = $file_path . $file[ 'filename' ] . $hash . '.' . $file[ 'extension' ]; - - //Attempt to move the uploaded file to the comic directory if a file with the new files filename doesn't already exist or overwrite is enabled - if ( ( !is_file( $target_path ) || $_REQUEST[ 'new_comic_overwrite' ] ) && move_uploaded_file( $_FILES[ 'new_comic_file' ][ 'tmp_name' ], $target_path ) ) { - //Set the correct file permissions based on the server operating system - if ( strpos( PHP_OS, 'WIN' ) ) - chmod( $target_path, 0777 ); - else - chmod( $target_path, 0664 ); - - //Get the file information - $img_dim = getimagesize( $target_path ); - - //Attempt to create alternative sizes if this isn't an swf file - if ( 'application/x-shockwave-flash' != $img_dim[ 'mime' ] ) { - //Get the specified alternative image dimensions - $img_lw = get_option( 'comic_large_size_w' ); - $img_lh = get_option( 'comic_large_size_h' ); - $img_mw = get_option( 'comic_medium_size_w' ); - $img_mh = get_option( 'comic_medium_size_h' ); - $img_tw = get_option( 'comic_thumb_size_w' ); - $img_th = get_option( 'comic_thumb_size_h' ); - $img_crop = get_option( 'comic_thumb_crop' ) ? true : false; - - //Generate a new large size image - if ( $img_dim[ 0 ] > $img_lw || $img_dim[ 1 ] > $img_lh ) - $file[ 'large' ] = basename( image_resize( $target_path, $img_lw, $img_lh, 0, 'large', $thumb_path ) ); - - //Generate a new medium size image - if ( $img_dim[ 0 ] > $img_mw || $img_dim[ 1 ] > $img_mh ) - $file[ 'medium' ] = basename( image_resize( $target_path, $img_mw, $img_mh, 0, 'medium', $thumb_path ) ); - - //Generate a new thumbnail size image - if ( $img_dim[ 0 ] > $img_tw || $img_dim[ 1 ] > $img_th ) - $file[ 'thumb' ] = basename( image_resize( $target_path, $img_tw, $img_th, $img_crop, 'thumb', $thumb_path ) ); - } - - //Attempt to automatically generate a post - if ( $_REQUEST[ 'comic_post_status' ] ) { - $post_date_std = $_REQUEST[ 'aa' ] . '-' . $_REQUEST[ 'mm' ] . '-' . $_REQUEST[ 'jj' ] . ' ' . $_REQUEST[ 'hh' ] . ':' . $_REQUEST[ 'mn' ] . ':' . $_REQUEST[ 'ss' ]; - $post_date_gmt = get_gmt_from_date( $post_date_std ); - $post_status = $_REQUEST[ 'comic_post_status' ]; - - $new_post = wp_insert_post( array( - 'post_content' => '…', - 'post_status' => $post_status, - 'post_category' => array( $series ), - 'post_date' => $post_date_std, - 'post_date_gmt' => $post_date_gmt, - 'post_title' => $file[ 'filename' ] - ) ); - - if ( $new_post ) { - add_post_meta( $new_post, 'comic_file', $file[ 'basename' ] ); - if ( $file[ 'large' ] ) - add_post_meta( $new_post, 'comic_large', $file[ 'large' ] ); - if ( $file[ 'medium' ] ) - add_post_meta( $new_post, 'comic_medium', $file[ 'medium' ] ); - if ( $file[ 'thumb' ] ) - add_post_meta( $new_post, 'comic_thumb', $file[ 'thumb' ] ); - } else { - $error = __( 'A post could not be automatically generated.', 'webcomic' ); - } - } - - $updated = __( 'New comic uploaded.', 'webcomic' ); - } else { - $error = __( 'A comic with that name already exists.', 'webcomic' ); - } - } else { - $error = __( 'Invalid file format. Comics must be gif, jpg, jpeg, png, or swf.', 'webcomic' ); - } - } elseif ( 'comic_upload' == $_REQUEST[ 'action' ] && 4 != $_FILES[ 'new_comic_file' ][ 'error' ] ) { - switch ( $_FILES[ 'new_comic_file' ][ 'error' ] ) { - case 1: //For simplicities sake we treat these as the same error. - case 2: $error = __( 'The file is too large to upload.', 'webcomic' ); break; - case 3: $error = __( 'The file was only partially uploaded.', 'webcomic' ); break; - case 6: $error = __( 'Your servers temporary directory could not be found.', 'webcomic' ); break; - case 7: $error = __( 'The file could not be saved properly after upload.', 'webcomic' ); break; - case 8: $error = __( 'The upload was halted by a PHP extensions.', 'webcomic'); break; - } - } - - /** Attempt to automatically generate posts for orphaned comics */ - if ( 'comic_bulk_actions' == $_REQUEST[ 'action' ] ) { - check_admin_referer( 'comic_bulk_actions' ); - - if ( $comics = $_REQUEST[ 'comics' ] ) { - - $action = ( $_REQUEST['Submit1'] ) ? $_REQUEST[ 'bulk_actions1' ] : $_REQUEST[ 'bulk_actions2' ]; - - if ( is_numeric( $action ) ) { //Attempt to assign selected comics to new storyline - foreach ( $comics as $comic ) - add_post_to_chapter( $comic, $action ); - - $updated = ( -1 == $action ) ? __( 'Selected comics removed from chapters.', 'webcomic' ) : __( 'Selected comics assigned to new chapter.', 'webcomic' ); - } elseif ( 'comic_regen_thumbs' == $action ) { //Attempt to regenerate thumbnails for selected files - $i = 0; - - foreach ( $comics as $comic ) { - if ( !get_post_meta( $comic, 'comic_file', true ) ) - continue; - - $img_dim = getimagesize( $file_path . get_post_meta( $comic, 'comic_file', true ) ); - - if ( 'application/x-shockwave-flash' != $img_dim[ 'mime' ] ) { - $file = pathinfo( $file_path . get_post_meta( $comic, 'comic_file', true ) ); - $thumbs = glob( $thumb_path . '*.*' ); - - if ( !$file[ 'filename' ] ) - $file[ 'filename' ] = substr( $file[ 'basename' ], 0, strlen( $file[ 'basename' ] ) - strlen( $file[ 'extension' ] ) - 1 ); - - foreach ( $thumbs as $thumb ) - if ( false !== strpos( $thumb, $file[ 'filename' ] ) ) - unlink( $thumb ); - - generate_comic_thumbnails( $comic, $file_path . $file[ 'basename' ], $img_dim ); - - $i++; - } - } - - if ( $i ) - $updated = sprintf( __ngettext( 'Thumbnails regenerated for %d file.', 'Thumbnails regenerated for %d files.', $i, 'webcomic' ), $i ); - else - $error = __( 'No thumbnails could be regenerated.', 'webcomic' ); - } elseif ( 'comic_delete' == $action || 'post_delete' == $action || 'comic_post_delete' == $action ) { //Attempt to delete files and/or posts - $fi = $pi = 0; - - foreach ( $comics as $comic ) { - if ( 'comic_delete' == $action || 'comic_post_delete' == $action ) { - $comic_file = ( $_REQUEST[ 'orphans' ] ) ? $comic : get_post_meta( $comic, 'comic_file', true ); - - if ( is_file( $file_path . $comic_file ) ) { - $file = pathinfo( $file_path . $comic_file ); - $thumbs = glob( $thumb_path . '*.*' ); - - if ( !$file[ 'filename' ] ) - $file[ 'filename' ] = substr( $file[ 'basename' ], 0, strlen( $file[ 'basename' ] ) - strlen( $file[ 'extension' ] ) - 1 ); - - unlink( $file_path . $comic_file ); - - foreach ( $thumbs as $thumb ) - if ( false !== strpos( $thumb, $file[ 'filename' ] ) ) - unlink( $thumb ); - if ( !$_REQUEST[ 'orphans' ] ) { - delete_post_meta( $comic, 'comic_file' ); - delete_post_meta( $comic, 'comic_large' ); - delete_post_meta( $comic, 'comic_medium' ); - delete_post_meta( $comic, 'comic_thumb' ); - } - - $fi++; - } - } - - if ( 'post_delete' == $action || 'comic_post_delete' == $action ) - if ( wp_delete_post( $comic ) ) - $pi++; - } - - if ( 'comic_delete' == $action ) { - if ( $fi ) - $updated = sprintf( __ngettext( '%d file deleted.', '%d files deleted.', $fi, 'webcomic' ), $fi ); - else - $error = __( 'None of the selected files could be deleted.', 'webcomic' ); - } elseif ( 'post_delete' == $action ) { - if ( $pi ) - $updated = sprintf( __ngettext( '%d post deleted.', '%d posts deleted.', $pi, 'webcomic' ), $pi ); - else - $error = __( 'None of the selected posts could be deleted.', 'webcomic' ); - } else { - if ( !$fi && !$pi ) - $error = __( 'None of the selected files or posts could be deleted.', 'webcomic' ); - else { - if ( $fi ) - $file_message = sprintf( __ngettext( '%d file', '%d files', $fi, 'webcomic' ), $fi ); - - if ( $pi ) - $post_message = sprintf( __ngettext( '%d post', '%d posts', $pi, 'webcomic' ), $pi ); - - if ( $fi && $pi ) - $updated = $file_message . __( ' and ', 'webcomic' ) . $post_message . __( ' deleted.', 'webcomic' ); - elseif( $fi ) - $updated = $file_message . __( ' deleted.', 'webcomic' ); - else - $updated = $post_message . __( ' deleted.', 'webcomic' ); - } - } - } elseif ( 'comic_rename' == $action ) { //Attemp to rename files - $i = 0; - - foreach ( $comics as $comic ) { - $hash = md5( $comic ); - - if ( is_file( $file_path . $_REQUEST[ 'comic_old_' . $hash ] . $_REQUEST[ 'comic_ext_' . $hash ] ) && !is_file( $file_path . $_REQUEST[ 'comic_name_' . $hash ] . $_REQUEST[ 'comic_ext_' . $hash ] ) ) { - rename( $file_path . $_REQUEST[ 'comic_old_' . $hash ] . $_REQUEST[ 'comic_ext_' . $hash ], $file_path . $_REQUEST[ 'comic_name_' . $hash ] . $_REQUEST[ 'comic_ext_' . $hash ] ); - - $thumbs = glob( $thumb_path . '*.*' ); - - foreach ( $thumbs as $thumb ) { - if ( false !== strpos( $thumb, $_REQUEST[ 'comic_old_' . $hash ] . '-large' ) ) - rename( $thumb, $thumb_path . $_REQUEST[ 'comic_name_' . $hash ] . '-large' . $_REQUEST[ 'comic_ext_' . $hash ] ); - - if ( false !== strpos( $thumb, $_REQUEST[ 'comic_old_' . $hash ] . '-medium' ) ) - rename( $thumb, $thumb_path . $_REQUEST[ 'comic_name_' . $hash ] . '-medium' . $_REQUEST[ 'comic_ext_' . $hash ] ); - - if ( false !== strpos( $thumb, $_REQUEST[ 'comic_old_' . $hash ] . '-thumb' ) ) - rename( $thumb, $thumb_path . $_REQUEST[ 'comic_name_' . $hash ] . '-thumb' . $_REQUEST[ 'comic_ext_' . $hash ] ); - } - - $i++; - } - } - - if ( $i ) - $updated = sprintf( __ngettext( '%d file renamed.', '%d files renamed.', $i, 'webcomic' ), $i ); - else - $error = __( 'None of the selected files could be renamed.', 'webcomic' ); - } elseif ( 'comic_post' == $action ) { - if ( 1 < count( $comics ) && !count( $_REQUEST[ 'days' ] ) ) { - $error = __( 'You must select at least one day to publish on when generating posts for multiple files.', 'webcomic' ); - } else { - $i = 0; - - $base_time = strtotime( $_REQUEST[ 'aa' ] . '-' . $_REQUEST[ 'mm' ] . '-' . $_REQUEST[ 'jj' ] ) + ( 60 * 60 * $_REQUEST[ 'hh' ] ) + ( 60 * $_REQUEST[ 'mn' ] ) + $_REQUEST[ 'ss' ]; - $base_day = date( 'l', $base_time ); - $start_day = date( 'w', $base_time ) + 1; - $num_days = count( $_REQUEST[ 'days' ] ); - - foreach ( $comics as $comic ) { - $file = pathinfo( $file_path . $comic ); - - if ( !$file[ 'filename' ] ) - $file[ 'filename' ] = substr( $file[ 'basename' ], 0, strlen( $file[ 'basename' ] ) - strlen( $file[ 'extension' ] ) - 1 ); - - $post_date_std = date( 'Y-m-d H:i:s', $base_time ); - $post_date_gmt = get_gmt_from_date( $post_date_std ); - $post_status = $_REQUEST[ 'comic_post_status' ]; - - $new_post = wp_insert_post( array( - 'post_content' => '…', - 'post_status' => $post_status, - 'post_category' => array( $series ), - 'post_date' => $post_date_std, - 'post_date_gmt' => $post_date_gmt, - 'post_title' => $file[ 'filename' ] - ) ); - - if ( $new_post ) { - add_post_meta( $new_post, 'comic_file', $file[ 'basename' ] ); - - if ( 'swf' != $file[ 'extension' ] ) { - $thumbs = glob( $thumb_path . '*.*' ); - - foreach ( $thumbs as $thumb ) { - if ( false !== strpos( $thumb, $file[ 'filename' ] . '-large' ) ) - add_post_meta( $new_post, 'comic_large', $file[ 'filename' ] . '-large.' . $file[ 'extension' ] ); - - if ( false !== strpos( $thumb, $file[ 'filename' ] . '-medium' ) ) - add_post_meta( $new_post, 'comic_medium', $file[ 'filename' ] . '-medium.' . $file[ 'extension' ] ); - - if ( false !== strpos( $thumb, $file[ 'filename' ] . '-thumb' ) ) - add_post_meta( $new_post, 'comic_thumb', $file[ 'filename' ] . '-thumb.' . $file[ 'extension' ] ); - } - } - - $i++; - } - - if ( 1 < count( $comics ) ) { - //Set the initial pointer position - if ( $start_day && 1 < $num_days ) { - if ( 7 == $start_day ) { - end( $_REQUEST[ 'days' ] ); - } elseif ( 1 != $start_day ) { - foreach ( $_REQUEST[ 'days' ] as $day ) { - if ( $day > $start_day ) - break; - } - } - - unset( $start_day ); - } - - if ( 1 == $num_days ) { - $weekday = 'next week'; - } elseif ( 7 == $num_days ) { - $weekday = 'tomorrow'; - } else { - if ( false === next( $_REQUEST[ 'days' ] ) ) - reset( $_REQUEST[ 'days' ] ); - - switch ( current( $_REQUEST[ 'days' ] ) ) { - case 1: $weekday = 'next sunday'; break; - case 2: $weekday = 'next monday'; break; - case 3: $weekday = 'next tuesday'; break; - case 4: $weekday = 'next wednesday'; break; - case 5: $weekday = 'next thursday'; break; - case 6: $weekday = 'next friday'; break; - case 7: $weekday = 'next saturday'; break; - } - } - - $base_time = strtotime( $weekday . ' +' . $_REQUEST[ 'hh' ] . ' hours +' . $_REQUEST[ 'mn' ] . ' minutes +' . $_REQUEST[ 'ss' ] . ' seconds', $base_time ); - } - } - - if ( $i ) - $updated = sprintf( __ngettext( '%d post automatically generated.', '%d posts automatically generated.', $i, 'webcomic' ), $i ); - else - $error = __( 'No posts could be automatically generated.', 'webcomic' ); - } - } - } else { - $error = __( 'Please select at least one comic.', 'webcomic' ); - } - } - - /** Attempt to regenerate an individual comics thumbnail files */ - if ( 'comic_thumb_regen' == $_REQUEST[ 'action' ] && is_file( $file_path . get_post_meta( $_REQUEST[ 'post' ], 'comic_file', true ) ) ) { - check_admin_referer( 'comic_thumb_regen' ); - - $img_dim = getimagesize( $file_path . get_post_meta( $_REQUEST[ 'post' ], 'comic_file', true ) ); - - if ( 'application/x-shockwave-flash' != $img_dim[ 'mime' ] ) { - $file = pathinfo( $file_path . get_post_meta( $_REQUEST[ 'post' ], 'comic_file', true ) ); - $thumbs = glob( $thumb_path . '*.*' ); - - if ( !$file[ 'filename' ] ) - $file[ 'filename' ] = substr( $file[ 'basename' ], 0, strlen( $file[ 'basename' ] ) - strlen( $file[ 'extension' ] ) - 1 ); - - foreach ( $thumbs as $thumb ) - if ( false !== strpos( $thumb, $file[ 'filename' ] ) ) - unlink( $thumb ); - - generate_comic_thumbnails( $_REQUEST[ 'post' ], $file_path . $file[ 'basename' ], $img_dim ); - - $updated = sprintf( __( '%s thumbnails regenerated.', 'webcomic' ), get_post_meta( $_REQUEST[ 'post' ], 'comic_file', true ) ); - } - } - - /** Attempt to delete a comic and it's associated thumbnail files */ - if ( 'comic_delete' == $_REQUEST[ 'action' ] ) { - check_admin_referer( 'comic_delete' ); - - if ( is_file( $file_path . $_REQUEST[ 'file' ] ) ) { - $file = pathinfo( $file_path . $_REQUEST[ 'file' ] ); - $thumbs = glob( $thumb_path . '*.*' ); - - if ( !$file[ 'filename' ] ) - $file[ 'filename' ] = substr( $file[ 'basename' ], 0, strlen( $file[ 'basename' ] ) - strlen( $file[ 'extension' ] ) - 1 ); - - unlink( $file_path . $_REQUEST[ 'file' ] ); - - foreach ( $thumbs as $thumb ) - if ( false !== strpos( $thumb, $file[ 'filename' ] ) ) - unlink( $thumb ); - - if ( $_REQUEST[ 'post' ] ) { - delete_post_meta( $_REQUEST[ 'post' ], 'comic_file' ); - delete_post_meta( $_REQUEST[ 'post' ], 'comic_large' ); - delete_post_meta( $_REQUEST[ 'post' ], 'comic_medium' ); - delete_post_meta( $_REQUEST[ 'post' ], 'comic_thumb' ); - } - - $updated = sprintf( __( 'Deleted %s', 'webcomic' ), $_REQUEST[ 'file' ] ); - } else { - $error = sprintf( __( '%s could not be deleted because it does not exist.', 'webcomic' ), $_REQUEST[ 'file' ] ); - } - } - - //Display update and error messages - if ( $updated ) - echo '

' . $updated . '

'; - - if ( $error ) - echo '

' . $error . '

'; - - - - // - // Begin Library Output - // - - //Get all the comic files - $comic_files = glob( $file_path . '*.*' ); - - if ( !is_array( $comic_files ) ) - $comic_files = array(); - - //Get just the comic files associated with a post - $comics = comic_loop( -1, $series ); - $comic_posts = array(); - - while ( $comics->have_posts() ) : $comics->the_post(); - $comic = get_the_comic(); - - if ( $comic->file ) { - array_push( $comic_posts, $file_path . $comic->file_name ); - $fallback_comics += ( $comic->fallback ) ? 1 : 0; - } else { - $orphan_posts += 1; - } - - $max_num_posts += 1; - endwhile; - - //Compare our lists to see if there are any orphaned files - $comic_orphans = array_diff( $comic_files, $comic_posts ); - natsort( $comic_orphans ); - - //Construct the library array - $library = array(); - $comics = comic_loop( $comics_per_page, $series, '&paged=' . $paged ); - - while ( $comics->have_posts() ) : $comics->the_post(); - $comic = get_the_comic(); - $chapter = get_the_chapter(); - $volume = get_the_chapter( 'volume' ); - $author = get_userdata( $post->post_author ); - $pending = get_pending_comments_num( $post->ID ); - - $data = new stdClass(); - $data->ID = $post->ID; - $data->link = get_permalink(); - $data->title = ( get_the_title() ) ? get_the_title() : '(no title)'; - $data->author = $author->display_name; - $data->author_id = $author->ID; - $data->file = $comic->file_name; - $data->comic = $comic->file; - $data->thumb = ( $comic->file ) ? get_comic_object( $comic, 'thumb' ) : false; - $data->volume = ( $volume ) ? $volume->title : '—'; - $data->chapter = ( $chapter ) ? $chapter->title . ' « ' : false; - $data->flash = ( $comic->flash ) ? true : false; - $data->fallback = ( $comic->fallback ) ? true : false; - $data->comments = "" . get_comments_number( $post->ID ) . ''; - - if ( $data->file ) { - $file = pathinfo( $file_path . $comic->file_name ); - - if ( !$file[ 'filename' ] ) - $file[ 'filename' ] = substr( $file[ 'basename' ], 0, strlen( $file[ 'basename' ] ) - strlen( $file[ 'extension' ] ) - 1 ); - - $data->name = $file[ 'filename' ]; - $data->ext = strtoupper( $file[ 'extension' ] ); - } - - if ( '0000-00-00 00:00:00' == $post->post_date ) { - $t_time = $h_time = __( 'Unpublished', 'webcomic' ); - } else { - $t_time = get_the_time( __( 'Y/m/d g:i:s A', 'webcomic' ) ); - $m_time = $post->post_date; - $time = get_post_time( 'G', true, $post ); - - $time_diff = time() - $time; - - if ( ( 'future' == $post->post_status ) ) { - if ( $time_diff <= 0 ) { - $h_time = sprintf( __( '%s from now', 'webcomic' ), human_time_diff( $time ) ); - } else { - $h_time = $t_time; - $missed = true; - } - } else { - - if ( $time_diff > 0 && $time_diff < 24 * 60 * 60 ) - $h_time = sprintf( __( '%s ago', 'webcomic' ), human_time_diff( $time ) ); - else - $h_time = mysql2date( __( 'Y/m/d', 'webcomic' ), $m_time); - } - } - - $data->date = '' . apply_filters( 'post_date_column_time', $h_time, $post, $column_name, 'list' ) . ''; - - if ( 'publish' == $post->post_status ) { - $data->status = __( 'Published', 'webcomic' ); - } elseif ( 'future' == $post->post_status ) { - if ( isset( $missed ) ) - $data->status = '' . __( 'Missed schedule', 'webcomic' ) . ''; - else - $data->status = __( 'Scheduled', 'webcomic' ); - } else { - $data->status = __( 'Last Modified', 'webcomic' ); - } - - if ( !empty( $post->post_password ) ) - $data->state[] = __( 'Password protected', 'webcomic' ); - elseif ( 'private' == $post->post_status ) - $data->state[] = __( 'Private', 'webcomic' ); - - if ( 'pending' == $post->post_status ) - $data->state[] = __( 'Pending', 'webcomic' ); - - if ( 'draft' == $post->post_status ) - $data->state[] = __( 'Draft', 'webcomic' ); - - $cur_num_posts += 1; - - array_push( $library, $data ); - endwhile; $max_num_pages = $comics->max_num_pages; - - //Determine the number of pages and build the paged navigation - if ( 1 < $max_num_pages ) { - $i = 1; - $prev = $paged - 1; - $next = $paged + 1; - - $to_num_post = ( ( $paged * $comics_per_page ) > $max_num_posts ) ? $max_num_posts : $paged * $comics_per_page; - $fro_num_post = ( $to_num_post == $max_num_posts ) ? $to_num_post - $cur_num_posts + 1 : $to_num_post - ($comics_per_page - 1); - - $paged_links = '
' . sprintf( __( 'Displaying %1$d – %2$d of %3$d', 'webcomic' ) , $fro_num_post, $to_num_post, $max_num_posts ) . ''; - - if ( 1 != $paged ) - $paged_links .= ' '; - - while ( $i <= $max_num_pages ) { - if ( ($i != 1 && $i < $paged - 2 ) || ( $i != $max_num_pages && $i > $paged + 2) ) { - if ( $i == 2 || $i == $max_num_pages - 1 ) - $paged_links .= '...'; - - $i++; - - continue; - } - - $paged_links .= ( $paged == $i ) ? '' . $i . ' ' : '' . $i . ' '; - - $i++; - } - - $i = 0; - - if ( $paged < $max_num_pages ) - $paged_links .= ''; - - $paged_links .= '
'; - } -?> -
-
icon
-

-

' . sprintf( __ngettext( '%d comic is being matched using the fallback method and should be updated.', '%d comics are being matched using the fallback method and should be updated.', $fallback_comics, 'webcomic' ), $fallback_comics, $view_link . '&action=comic_fallback_update' ) . '

'; - if ( $orphan_posts && current_user_can( 'edit_others_posts' ) ) - echo '

' . sprintf( __ngettext( '%d post is not linked to and cannot be matched with a comic.', '%d posts are not linked to and cannot be matched with a comic.', $orphan_posts, 'webcomic' ), $orphan_posts ) . '

'; - ?> -
-

- - - -

-
-
- -

- - - - - - - - - - - -

-
- -
- -
-
- - - count, 'webcomic' ), $buffer->count, $buffer->date, $buffer->time ); ?> -
- - -
- - - - - - - - - - - - - - - - - - - - - - comic && !( $i % 2 ) && !$item->fallback ) echo ' class="alt"'; elseif ( $item->fallback ) echo ' style="background:#fffbcc"'; elseif ( !$item->comic ) echo ' style="background:#fdd"'; ?>> - - - - - - - - -
comic && !$item->fallback && ( current_user_can( 'edit_others_posts' ) || $current_user->ID == $item->author_id ) ) { ?>thumb; ?> - file ) { ?> - ID == $item->author_id ) { ?>name; ?> ' . $item->name . ''; } ?>
- ext; ?> -

- ID == $item->author_id ) { ?> - - flash && !$item->fallback ) { ?> - | - - | file ) ); ?>')) {return true;}return false;" title=""> | - - -

- -
- ID == $item->author_id ) { ?>title; ?>' . $item->title . ''; } if ( $item->state ) echo ' - ' . implode( ', ', $item->state ) . ''; ?>
- author; ?> -

- ID == $item->author_id ) { ?> - - | title ) ); ?>')) {return true;}return false;"> | - - -

-
-
-
- - - - -
- - - - - -
-
- -

- -

-
- -
-
- - - - - - - - -
-
- - - - - - - - - $orphan ) { $orphan_info = pathinfo( $orphan ); if ( !$orphan_info[ 'filename' ] ) $orphan_info[ 'filename' ] = substr( $orphan_info[ 'basename' ], 0, strrpos( $orphan_info[ 'basename' ], '.' ) ); ?> - 0 && !( $x % 3 ) ) { $i++; ?> - - - > - - - - - > - - - - - - -
' . __( 'Select All', 'webcomic' ) . ''; else _e( 'File', 'webcomic' ); ?>
- - - - <?php echo $orphan_info[ 'basename' ]; ?> -
- - - - -
- - - - -
-
- - - - \ No newline at end of file diff --git a/includes/wc-admin-metabox.php b/includes/wc-admin-metabox.php deleted file mode 100644 index 94ba791..0000000 --- a/includes/wc-admin-metabox.php +++ /dev/null @@ -1,398 +0,0 @@ - - - - file ) { if ( $comic->fallback ) { ?> -

- -

- file ) { ?> -

- have_posts() ) : $comics->the_post(); - $the_comic = get_the_comic(); - - if ( $the_comic->file ) - array_push( $comic_posts, $file_path . $the_comic->file_name ); - endwhile; - - //Compare our lists to see if there are any orphaned files - $comic_orphans = array_diff( $comic_files, $comic_posts ); - natsort( $comic_orphans ); - - if ( $comic_orphans ) { - ?> -

-
- '; - } else { - $img = ( is_file( get_comic_directory( 'abs', true, $series ) . $orphan_info[ 'filename' ] . '-thumb.' . $orphan_info[ 'extension' ] ) ) ? get_comic_directory( 'url', true, $series ) . $orphan_info[ 'filename' ] . '-thumb.' . $orphan_info[ 'extension' ] : get_comic_directory( 'url', false, $series ) . $orphan_info[ 'filename' ] . '.' . $orphan_info[ 'extension' ]; - $preview = '' . $orphan_info[ 'basename' ] . ''; - } - - echo ''; - } - ?> -
- -

- - - - -

-

fallback ) _e( 'Any files currently associated with this post will be deleted when uploading a new file.', 'webcomic' ); ?>

-
- file && !$comic->fallback ) { $file = pathinfo( get_comic_directory( 'abs', false, $series ) . $comic->file_name ); ?> -

-
- - - -

- flash ) { ?> -

- large ) - _e( 'Large, Medium, and Thumbnail sizes available.', 'webcomic' ); - elseif ( $comic->medium ) - _e( 'Medium and Thumbnail sizes available.', 'webcomic' ); - elseif ( $comic->thumb ) - _e( 'Thumbnail size available.', 'webcomic' ); - else - _e( 'No additional sizes available.', 'webcomic' ); - ?> -

- -
- $series->volumes ) ) && current_user_can( 'manage_categories' ) ) { ?> -

-
- -

-

«


-

- - ID, 'comic_description', true ) ) { ?> - - - -

-


-

- - - - - -

- -

-
- -

- \ No newline at end of file diff --git a/includes/wc-admin-settings.php b/includes/wc-admin-settings.php deleted file mode 100644 index b24d1da..0000000 --- a/includes/wc-admin-settings.php +++ /dev/null @@ -1,188 +0,0 @@ -term_id ); - - /** Create any new series, if necessary */ - foreach ( $comic_cats as $comic_cat ) { - $series_key = array_search( $comic_cat, $comic_series ); - if ( false !== $series_key ) { - $new_series = get_term( $comic_series[ $series_key ], 'category' ); - wp_insert_term( $new_series->name, 'chapter' ); - $current_chapters[ $new_series->term_id ] = -1; - } - unset( $comic_series[ $series_key ] ); - } - - //Delete any old series, if necessary - if ( $comic_series ) { - foreach ( $comic_series as $the_series ) { - $s_parent = get_term( ( int ) $the_series, 'chapter' ); - $v_children = get_term_children( $the_series, 'chapter' ); - - foreach ( $v_children as $volume ) { - $c_children = get_term_children( $volume, 'chapter' ); - - foreach ( $c_children as $chapter ) - wp_delete_term( $chapter, 'chapter' ); - - wp_delete_term( $volume, 'chapter' ); - } - - unset( $current_chapters[ $the_series ] ); - wp_delete_term( $the_series, 'chapter' ); - } - } - - update_option( 'comic_current_chapter', $current_chapters ); - - //Generate comic directories if they don't already exist - foreach ( get_option( 'comic_category' ) as $comic_category ) - if ( !file_exists( get_comic_directory( 'abs', true, $comic_category ) ) ) - if ( !mkdir( get_comic_directory( 'abs', true, $comic_category ), 0775, true ) ) - $mkdir_error = true; - - //Disable the buffer alert if 0 is entered for days - if ( !get_option( 'comic_buffer_alert' ) ) - update_option( 'comic_buffer', '' ); - - echo '

' . __( 'Settings saved.', 'webcomic') . '

'; - - if ( $mkdir_error ) - echo '

' . __( 'Webcomic was not able to create necessary comic directories.', 'webcomic' ) . '

'; - } -?> -
-
icon
-

-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- -
-
- -

Ctrl or Command to select multiple categories.', 'webcomic' ); ?>

-
- -
-
- -
-
-
- -
/> -
- /> - -
- -
-

-

- - - - - - - - - - - - - -
-   -
- -
-   - -
-   - -
-

- Donate | Webcomic Version %s', 'webcomic' ), 'https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=5683100', get_option( 'webcomic_version' ) ); ?> - - -

-
-
- \ No newline at end of file diff --git a/includes/wc-admin.php b/includes/wc-admin.php deleted file mode 100644 index 89bd147..0000000 --- a/includes/wc-admin.php +++ /dev/null @@ -1,364 +0,0 @@ -' . __( 'Library Documentation', 'webcomic' ) . ''; - $help[1] = '' . __( 'Chapters Documentation', 'webcomic' ) . ''; - $help[2] = '' . __( 'Settings Documentation', 'webcomic' ) . ''; - - foreach ( $help as $key => $value ) - $help[ $key ] .= '
' . __( 'Webcomic Documentation', 'webcomic' ) . '
' . __( 'Webcomic Support Forum', 'webcomic' ) . ''; - - add_contextual_help( $library, $help[ 0 ] ); - add_contextual_help( $chapters, $help[ 1 ] ); - add_contextual_help( $settings, $help[ 2 ] ); - - register_column_headers( $library, array( 'collection' => __( 'Collection', 'webcomic' ), 'comments' => '
Comments
', 'date' => __( 'Date', 'webcomic' ) ) ); -} add_action( 'admin_menu', 'webcomic_admin_menu' ); - -/** - * Corrects the pagenow javascript variable for dynamically - * saving Library hidden column information. - * - * @package Webcomic - * @since 2.1.0 - */ -function webcomic_admin_enqueue_scripts( $suffix ) { - if ( false !== strpos( $suffix, 'comic-library' ) ) - echo ""; -} add_action( 'admin_enqueue_scripts', 'webcomic_admin_enqueue_scripts' ); - -/** - * Checks if the current column is hidden and outputs CSS as necessary. - * - * @package Webcomic - * @since 2.1.0 - * - * @param str $column Column ID - */ -function webcomic_hide_column( $column ) { - $hidden = get_hidden_columns( 'toplevel_page_comic-library' ); - - if ( in_array( $column, $hidden ) ) - echo ' style="display:none"'; -} - -function webcomic_print_cells( $item ) { - if ( !$item ) - return; - - $hidden = get_hidden_columns( 'toplevel_page_comic-library' ); - - if ( in_array( 'collection', $hidden ) ) - $hide_collection = ' style="display:none"'; - - if ( in_array( 'comments', $hidden ) ) - $hide_comments = ' style="display:none"'; - - if ( in_array( 'date', $hidden ) ) - $hide_date = ' style="display:none"'; - - echo '' . $item->chapter . $item->volume . '' . "\n"; - echo '
' . $item->comments . '
' . "\n"; - echo '' . $item->date . '
' . $item->status . '' . "\n"; -} - -/** - * Adds contextual help links to various administrative pages. - * - * @package Webcomic - * @since 2.0.0 - */ -function webcomic_contextual_help_list( $_wp_contextual_help ) { - $help = '

' . __( 'Using the Webcomic Metabox', 'webcomic' ) . '
' . __( 'Webcomic Documentation', 'webcomic' ) . '
' . __( 'Webcomic Support Forum', 'webcomic' ) . '

'; - - if ( $_wp_contextual_help[ 'post' ] ) - $_wp_contextual_help[ 'post' ] .= $help; - - if ( $_wp_contextual_help[ 'page' ] ) - $_wp_contextual_help[ 'page' ] .= $help; - - return $_wp_contextual_help; -} add_filter( 'contextual_help_list', 'webcomic_contextual_help_list' ); - -/** - * Registers plugin settings and ensures the correct javascript files are enqueued. - * - * @package Webcomic - * @since 1.0.0 - */ -function webcomic_admin_init() { - register_setting( 'webcomic_options', 'comic_category' ); - register_setting( 'webcomic_options', 'comic_directory' ); - register_setting( 'webcomic_options', 'comic_secure_paths' ); - register_setting( 'webcomic_options', 'comic_secure_names' ); - register_setting( 'webcomic_options', 'comic_post_draft' ); - register_setting( 'webcomic_options', 'comic_transcripts_allowed' ); - register_setting( 'webcomic_options', 'comic_transcripts_required' ); - register_setting( 'webcomic_options', 'comic_transcripts_loggedin' ); - register_setting( 'webcomic_options', 'comic_feed' ); - register_setting( 'webcomic_options', 'comic_feed_size' ); - register_setting( 'webcomic_options', 'comic_buffer' ); - register_setting( 'webcomic_options', 'comic_buffer_alert' ); - register_setting( 'webcomic_options', 'comic_keyboard_shortcuts' ); - register_setting( 'webcomic_options', 'comic_thumb_crop' ); - register_setting( 'webcomic_options', 'comic_thumb_size_w' ); - register_setting( 'webcomic_options', 'comic_thumb_size_h' ); - register_setting( 'webcomic_options', 'comic_medium_size_w' ); - register_setting( 'webcomic_options', 'comic_medium_size_h' ); - register_setting( 'webcomic_options', 'comic_large_size_w' ); - register_setting( 'webcomic_options', 'comic_large_size_h' ); -} add_action( 'admin_init', 'webcomic_admin_init' ); - -/** - * Adds a comic post to the specified chapter. - * - * This function adds a post to the specified chapter taxonomy. - * It first checks to see if the specified post is actually - * assigned to the defined comic category and, if so, assigns - * it to the specified chapter. - * - * @package Webcomic - * @since 1.0.0 - * - * @param int $id Post ID. - * @param int $chapter Chapter ID. - * @param bool $overwrite Overwrites a posts existing chapter, if any. - */ -function add_post_to_chapter( $id, $chapter, $overwrite = 1 ) { - if ( get_post_comic_category( $id ) ) { - $post_chapters = get_post_comic_chapters( $id ); - - if ( $post_chapters ) { - if ( $overwrite ) - remove_post_from_chapter( $id ); - else - return; - } - - if ( -1 == $chapter ) { - remove_post_from_chapter( $id ); - } else { - $the_chapter = get_term( $chapter, 'chapter' ); - $the_volume = get_term( $the_chapter->parent, 'chapter' ); - $the_series = get_term( $the_volume->parent, 'chapter' ); - - $new_tax = array(); - $new_tax[ 0 ] = $the_chapter->slug; - $new_tax[ 1 ] = $the_volume->slug; - $new_tax[ 2 ] = $the_series->slug; - - wp_set_object_terms( $id, $new_tax, 'chapter' ); - } - } -} - -/** - * Removes a comic post from a chapter. - * - * @package Webcomic - * @since 1.0.0 - * - * @param int $id Post ID. - */ -function remove_post_from_chapter( $id ){ - wp_delete_object_term_relationships( $id, 'chapter' ); -} -add_action( 'delete_post', 'remove_post_from_chapter' ); - -/** - * Adds new comic posts to the defined current chapter. - * - * This function adds any newly created comic posts to the defined - * current chapter for a given series. - * - * @package Webcomic - * @since 1.0.0 - * - * @param int $id Post ID. - */ -function add_post_to_current_chapter( $id ) { - $series = get_post_comic_category( $id ); - - if ( $series ) - $chapter = get_comic_current_chapter( $series ); - else - return; - - add_post_to_chapter( $id, $chapter, 0 ); -} add_action( 'save_post', 'add_post_to_current_chapter' ); - -/** - * Removes comic series information. - * - * This function automatically removes series information - * when a corresponding Category is deleted. - * - * @package Webcomic - * @since 2.0.0 - * - * @param int $id Category ID. - */ -function webcomic_category_delete( $id ) { - $categories = get_comic_category( true ); - - if ( $key = array_search( $id, $categories ) ) { - $s_parent = get_term( ( int ) $id, 'chapter' ); - $v_children = get_term_children( $id, 'chapter' ); - $current_chapters = get_comic_current_chapter( true ); - - foreach ( $v_children as $volume ) { - $c_children = get_term_children( $volume, 'chapter' ); - - foreach ( $c_children as $chapter ) - wp_delete_term( $chapter, 'chapter' ); - - wp_delete_term( $volume, 'chapter' ); - } - - unset( $current_chapters[ $id ] ); - unset( $categories[ $key ] ); - - update_option( 'comic_current_chapter', $current_chapters ); - update_option( 'comic_category', $categories ); - - wp_delete_term( $id, 'chapter' ); - } -} add_action( 'category_delete', 'webcomic_category_delete' ); - -/** - * Displays the slug warning for comic categories. - * - * This function adds a warning to the Edit Category page for comic - * categories, informing the user that changing the category slug - * will also require changing the categories associated comic - * directory to match the new slug name. - * - * @package Webcomic - * @since 2.0.0 - * - * @param obj $category The category object for the selected category. - */ -function webcomic_edit_category_form_pre( $category ) { - $categories = get_comic_category( true ); - - if ( false !== array_search( $category->term_id, $categories ) ) - echo '

' . sprintf( __( 'This is a comic category. Changing the Category Slug will also rename the directory %s to match the new slug.', 'webcomic'), get_comic_directory( 'url', false, $category->term_id ), get_comic_directory( 'url', false, $category->term_id ) ) . '

'; -} add_action( 'edit_category_form_pre', 'webcomic_edit_category_form_pre' ); - -/** - * Adds the 'comic_directory' hidden field to the Edit Category page. - * - * This function adds the 'comic_directory' hidden field to the Edit - * Category page. When detected, Webcomic copmares the existing directory - * path to the one in 'comic_directory' and renames comic subdirectories - * as necessary. - * - * @package Webcomic - * @since 2.0.0 - * - * @param obj $category The category object for the selected category. - */ -function webcomic_edit_category_form( $category ) { - $categories = get_comic_category( true ); - - if ( false !== array_search( $category->term_id, $categories ) ) - echo ''; -} add_action( 'edit_category_form', 'webcomic_edit_category_form' ); - -/** - * Renames comic subdirectories as necessary. - * - * This function compares the value of a unique hidden field - * to an existing comic subdirectory; if the two don't match, - * Webcomic renames the old directory using the new name. - * - * @package Webcomic - * @since 2.0.0 - * - * @param int $id Category ID. - */ -function webcomic_rename_subdirectory( $id ) { - if ( $_REQUEST[ 'webcomic_subdirectory' ] && $_REQUEST[ 'webcomic_subdirectory' ] != get_comic_directory( 'abs', false, $id ) ) - rename( $_REQUEST[ 'webcomic_subdirectory' ], get_comic_directory( 'abs', false, $id ) ); -} add_action( 'edited_category', 'webcomic_rename_subdirectory' ); add_action( 'edited_chapter', 'webcomic_rename_subdirectory' ); - -/** - * Generates comic thumbnails and associates them with the comic post. - * - * This is a utility function used to generate comic thumbnails from a - * source comic file and link them with the associated comic post. - * - * @package Webcomic - * @since 2.0.0 - * - * @param int $id Post ID. - * @param str $target_path Source file. - * @param arr $img_dim Source file information as generated by getimagesize(). - */ -function generate_comic_thumbnails( $id = false, $target_path = false, $img_dim = false ) { - if ( !$id || !$target_path || !$img_dim ) - return; - - $img_lw = get_option( 'comic_large_size_w' ); - $img_lh = get_option( 'comic_large_size_h' ); - $img_mw = get_option( 'comic_medium_size_w' ); - $img_mh = get_option( 'comic_medium_size_h' ); - $img_tw = get_option( 'comic_thumb_size_w' ); - $img_th = get_option( 'comic_thumb_size_h' ); - $img_crop = get_option( 'comic_thumb_crop' ) ? true : false; - $thumb_path = get_comic_directory( 'abs', true, get_post_comic_category( $id ) ); - - //Generate a new large size image and add or update the post custom field, or delete the post custom field - if ( $img_dim[ 0 ] > $img_lw || $img_dim[ 1 ] > $img_lh ) { - $comic_large = basename( image_resize( $target_path, $img_lw, $img_lh, 0, 'large', $thumb_path ) ); - - if ( !add_post_meta( $id, 'comic_large', $comic_large, true ) ) - update_post_meta( $id, 'comic_large', $comic_large ); - } elseif ( get_post_meta( $id, 'comic_large', true ) ) { - delete_post_meta( $id, 'comic_large' ); - } - - //Generate a new medium size image and add or update the post custom field, or delete the post custom field - if ( $img_dim[ 0 ] > $img_mw || $img_dim[ 1 ] > $img_mh ) { - $comic_medium = basename( image_resize( $target_path, $img_mw, $img_mh, 0, 'medium', $thumb_path ) ); - - if ( !add_post_meta( $id, 'comic_medium', $comic_medium, true ) ) - update_post_meta( $id, 'comic_medium', $comic_medium ); - } elseif ( get_post_meta( $id, 'comic_medium', true ) ) { - delete_post_meta( $id, 'comic_medium' ); - } - - //Generate a new thumbnail size image and add or update the post custom field, or delete the post custom field - if ( $img_dim[ 0 ] > $img_tw || $img_dim[ 1 ] > $img_th ) { - $comic_thumb = basename( image_resize( $target_path, $img_tw, $img_th, $img_crop, 'thumb', $thumb_path ) ); - - if ( !add_post_meta( $id, 'comic_thumb', $comic_thumb, true ) ) - update_post_meta( $id, 'comic_thumb', $comic_thumb ); - } elseif ( get_post_meta( $id, 'comic_thumb', true ) ) { - delete_post_meta( $id, 'comic_thumb' ); - } -} -?> \ No newline at end of file diff --git a/includes/wc-core.php b/includes/wc-core.php deleted file mode 100644 index 8f5461a..0000000 --- a/includes/wc-core.php +++ /dev/null @@ -1,2135 +0,0 @@ -query( 'posts_per_page=' . $number . '&cat=' . $include . $query ); - - return $comics; -} - -/** - * Removes the specified comic category from a standard loop. - * - * This function will remove the specified comic category (and all associated posts) - * from the regular WordPress loop. It can also generate an entirely new WP_Query - * object which ignores the specified comic category. If the $exclude parameter - * is unset, ignore_comics will remove all comic posts from the standard loop. If the - * $number parameter is set, ignore_comics returns a new WP_query Object. - * - * @package Webcomic - * @since 1.0.0 - * - * @param int $number The number of posts to return in a new WP_Query object. - * @param str $exclude Comma separated list of category ID's to exclude. - * @param str $query Appended to the query string used to generate the new WP_Query object. - * @return object New WordPress query object (only if $number has been set). - */ -function ignore_comics( $number = false, $exclude = false, $query = false ) { - global $paged; - - $exclude = ( $exclude ) ? $exclude : get_comic_category( true, 'exclude' ); - - if ( $number ) { - $new_query = new WP_Query; - $new_query->query( 'posts_per_page=' . $number . '&cat=' . $exclude . $query); - return $new_query; - } - - query_posts( 'cat=' . $exclude . '&paged=' . $paged . $query ); -} - -/** - * Checks if the current post is contained within a specified comic category. - * - * This function checks if the current post is contained in any defined - * comic category. The optional $id parameter allows checking for a specific - * comic category. Must be used within The Loop. - * - * @package Webcomic - * @since 1.8.0 - * - * @uses get_post_comic_category() - * - * @param int|str|array $category. Category ID, name or slug, or array of said. - * @param int|obj Post to check instead of the current post. - * @return bool True if the current post is in any of the given categories. - */ -function in_comic_category( $category = false, $_post = null ) { - $category = ( $category ) ? $category : get_comic_category( true ); - - if ( $_post ) - $_post = get_post( $_post ); - else - $_post =& $GLOBALS[ 'post' ]; - - if ( !$_post ) - return; - - $r = is_object_in_term( $_post->ID, 'category', $category ); - - if ( is_wp_error( $r ) ) - return; - - return $r; -} - -/** - * Checks if the current post is contained within a specified comic chapter. - * - * This function checks if the current post is contained in any defined - * comic chapter. The optional $id parameter allows checking for a specific - * comic chapter. Must be used within The Loop. - * - * @package Webcomic - * @since 1.8.0 - * - * @uses get_post_comic_category() - * - * @param int|str|array $category. Category ID, name or slug, or array of said. - * @param int|obj Post to check instead of the current post. - * @return bool True if the current post is in any of the given chapters. - */ -function in_comic_chapter( $chapter = false, $_post = null ) { - if ( empty( $chapter ) ) { - if ( get_post_comic_chapters() ) - return true; - else - return; - } - - if ( $_post ) - $_post = get_post( $_post ); - else - $_post =& $GLOBALS[ 'post' ]; - - if ( !$_post ) - return; - - $r = is_object_in_term( $_post->ID, 'chapter', $chapter ); - - if ( is_wp_error( $r ) ) - return; - - return $r; -} - - - -// -// Data Retrieval -// - -/** - * Returns comic information associated with the specified post. - * - * The $id parameter is optional when this funciton is used inside a WordPress Loop. - * If left unset, get_the_comic will attempt to retrieve comic information associated - * with the current post. - * - * The $limit parameter is only used when $id is one of 'first', 'previous', 'next', - * 'last', or 'random' and should be a valid category ID or one of 'chapter' or 'volume'. - * - * The $chapter parameter is only used when $limit is one of 'chapter' or 'volume' and - * should be a valid chapter ID. - * - * When used outside a WordPress Loop and $id is 'random' and no $limit is set get_the_comic - * will randomly select from the list of available comic categories. - * - * @package Webcomic - * @since 1.0.0 - * - * @param int|str $id Post ID or one of 'first', 'previous', 'next', 'last', or 'random'. - * @param int|str $limit Category ID or one of 'chapter', 'volume', or 'series'. - * @param int $chapter Chapter ID. - * @return object Object containing various comic information. - */ -function get_the_comic( $id = false, $limit = false, $chapter = false ) { - global $wp_query, $wpdb, $post; - - if ( $id ) { - $new_post = $id; - - switch ( $id ) { - case 'first': - $order = ' p.post_date ASC'; break; - case 'last': - $order = ' p.post_date DESC'; break; - case 'previous': - $order = ' p.post_date DESC LIMIT 1'; - $op = " p.post_date < '$post->post_date' AND"; break; - case 'next': - $order = ' p.post_date ASC LIMIT 1'; - $op = " p.post_date > '$post->post_date' AND"; break; - case 'random': - $order = ' RAND()'; break; - } - - if ( $order ) { - $taxonomy = ( $limit && is_string( $limit ) ) ? 'chapter' : 'category'; - - if ( 'chapter' == $taxonomy ) { - if ( $chapter ) - $tax_id = $chapter; - elseif ( in_comic_chapter() ) - $tax_id = get_post_comic_chapters()->$limit->term_id; - } - - if ( 'category' == $taxonomy || !$tax_id ) { - if ( $limit && is_numeric( $limit ) ) - $tax_id = $limit; - elseif ( 'random' == $id && !$wp_query->in_the_loop ) - $tax_id = get_comic_category( true, 'random' ); - elseif ( in_comic_category() ) - $tax_id = get_post_comic_category(); - else - return; //No taxonomy information could be found - } - - $join = " AND tt.taxonomy = '$taxonomy' AND tt.term_id IN ($tax_id)"; - - $new_post = $wpdb->get_var( "SELECT p.id FROM $wpdb->posts AS p INNER JOIN $wpdb->term_relationships AS tr ON p.ID = tr.object_id INNER JOIN $wpdb->term_taxonomy tt ON tr.term_taxonomy_id = tt.term_taxonomy_id $join WHERE $op p.post_type = 'post' AND p.post_status = 'publish' ORDER BY $order" ); - } - - $comic_post = &get_post( $new_post ); - } elseif ( in_comic_category() ) { - $comic_post =& $post; - } else { - return; //Not a comic post - } - - $comic_dir = ( $category ) ? $category : get_post_comic_category( $comic_post->ID ); - - $output = new stdClass(); - $output->ID = ( int ) $comic_post->ID; - $output->title = $comic_post->post_title; - $output->description = ( get_post_meta( $comic_post->ID, 'comic_description', true ) ) ? convert_chars( wptexturize( get_post_meta( $comic_post->ID, 'comic_description', true ) ) ) : $comic_post->post_title; - $output->link = get_permalink( $comic_post->ID ); - $output->class = 'comic-item comic-item-' . $output->ID; - - if ( get_post_meta( $comic_post->ID, 'comic_transcript', true ) ) { - $output->transcript = wpautop( convert_chars( wptexturize( get_post_meta( $comic_post->ID, 'comic_transcript', true ) ) ) ); - $output->transcript_status = 'publish'; - } elseif ( get_post_meta( $comic_post->ID, 'comic_transcript_pending', true ) ) { - $output->transcript = get_post_meta( $comic_post->ID, 'comic_transcript_pending', true ); - $output->transcript_status = 'pending'; - } elseif ( get_post_meta( $comic_post->ID, 'comic_transcript_draft', true ) ) { - $output->transcript = true; - $output->transcript_status = 'draft'; - } else { - $output->transcript = $output->transcript_status = false; - } - - if ( is_file( get_comic_directory( 'abs', false, $comic_dir ) . get_post_meta( $comic_post->ID, 'comic_file', true ) ) ) { - $output->file = ( get_option( 'comic_secure_paths' ) ) ? get_settings( 'home' ) . '?comic_object=' . $output->ID : get_comic_directory( 'url', false, $comic_dir ) . rawurlencode( get_post_meta( $comic_post->ID, 'comic_file', true ) ); - $output->file_name = get_post_meta( $comic_post->ID, 'comic_file', true ); - $output->file_data = getimagesize( get_comic_directory( 'abs', false, $comic_dir ) . $output->file_name ); - $output->flash = ( 'application/x-shockwave-flash' == $output->file_data[ 'mime' ] ) ? true : false; - - if ( is_file( get_comic_directory( 'abs', true, $comic_dir ) . get_post_meta( $comic_post->ID, 'comic_large', true ) ) ) { - $output->large = ( get_option( 'comic_secure_paths' ) ) ? get_settings( 'home' ) . '?comic_object=' . $output->ID . '/large' : get_comic_directory( 'url', true, $comic_dir ) . rawurlencode( get_post_meta( $comic_post->ID, 'comic_large', true ) ); - $output->large_name = get_post_meta( $comic_post->ID, 'comic_large', true ); - $output->large_data = getimagesize( get_comic_directory( 'abs', true, $comic_dir ) . $output->large_name ); - } - - if ( is_file( get_comic_directory( 'abs', true, $comic_dir ) . get_post_meta( $comic_post->ID, 'comic_medium', true ) ) ) { - $output->medium = ( get_option( 'comic_secure_paths' ) ) ? get_settings( 'home' ) . '?comic_object=' . $output->ID . '/medium' : get_comic_directory( 'url', true, $comic_dir ) . rawurlencode( get_post_meta( $comic_post->ID, 'comic_medium', true ) ); - $output->medium_name = get_post_meta( $comic_post->ID, 'comic_medium', true ); - $output->medium_data = getimagesize( get_comic_directory( 'abs', true, $comic_dir ) . $output->medium_name ); - } - - if ( is_file( get_comic_directory( 'abs', true, $comic_dir ) . get_post_meta( $comic_post->ID, 'comic_thumb', true ) ) ) { - $output->thumb = ( get_option( 'comic_secure_paths' ) ) ? get_settings( 'home' ) . '?comic_object=' . $output->ID . '/thumb' : get_comic_directory( 'url', true, $comic_dir ) . rawurlencode( get_post_meta( $comic_post->ID, 'comic_thumb', true ) ); - $output->thumb_name = get_post_meta( $comic_post->ID, 'comic_thumb', true ); - $output->thumb_data = getimagesize( get_comic_directory( 'abs', true, $comic_dir ) . $output->thumb_name ); - } - } elseif ( $comic_files = glob( get_comic_directory( 'abs', 0, $comic_dir ) . '*.*' ) ) { - if ( get_option( 'comic_name_format_date' ) ) - $date_format = get_option( 'comic_name_format_date' ); - elseif ( get_option( 'comicpress-manager-cpm-date-format' ) ) - $date_format = get_option( 'comicpress-manager-cpm-date-format' ); - elseif ( get_option( 'stripshow_date_format' ) ) - $date_format = get_option( 'stripshow_date_format' ); - else - $date_format = 'Y-m-d'; - - $date_id = mysql2date( $date_format, $comic_post->post_date ); - $slug_id = $comic_post->post_name; - $meta_id = get_post_meta( $comic_post->ID, 'comic_filename', true ); - - foreach( array_keys( $comic_files ) as $key ) { - if ( ( $date_id && false !== strpos( basename( $comic_files[ $key ] ), $date_id ) ) || ( $slug_id && false !== strpos( basename( $comic_files[ $key ] ), $slug_id ) ) || ( $meta_id && false !== strpos( basename( $comic_files[ $key ] ), $meta_id ) ) ) { - $output->file = ( get_option( 'comic_secure_paths' ) ) ? get_settings( 'home' ) . '?comic_object=' . $output->ID : get_comic_directory( 'url', 0, $comic_dir ) . rawurlencode( basename( $comic_files[ $key ] ) ); - $output->file_name = basename( $comic_files[ $key ] ); - $output->file_data = getimagesize( $comic_files[ $key ] ); - break; - } - } - - if ( $output->file ) { - $output->fallback = true; - - $output->flash = ( 'application/x-shockwave-flash' == $output->file_data[ 'mime' ] ) ? true : false; - - if ( $comic_thumb_files = glob( get_comic_directory( 'abs', true, $comic_dir ) . '*.*' ) ) { - $comic_thumbs = array(); - - foreach ( array_keys( $comic_thumb_files ) as $key ) - if ( ( $date_id && false !== strpos( basename( $comic_files[ $key ] ), $date_id ) ) || ( $slug_id && false !== strpos( basename( $comic_files[ $key ] ), $slug_id ) ) || ( $meta_id && false !== strpos( basename( $comic_files[ $key ] ), $meta_id ) ) ) - array_push( $comic_thumbs, basename( $comic_thumb_files[ $key ] ) ); - - foreach ( $comic_thumbs as $comic_thumb ) { - if ( strpos( $comic_thumb, 'large' ) && !$output->large ) { - $output->large = ( get_option( 'comic_secure_paths' ) ) ? get_settings( 'home' ) . '?comic_object=' . $output->ID . '/large' : get_comic_directory( 'url', true, $comic_dir ) . $comic_thumb; - $output->large_name = $comic_thumb; - $output->large_data = getimagesize( get_comic_directory( 'abs', true, $comic_dir ) . $comic_thumb ); - } - - if ( strpos( $comic_thumb, 'medium' ) && !$output->medium ) { - $output->medium = ( get_option( 'comic_secure_paths' ) ) ? get_settings( 'home' ) . '?comic_object=' . $output->ID . '/medium' : get_comic_directory( 'url', true, $comic_dir ) . $comic_thumb; - $output->medium_name = $comic_thumb; - $output->medium_data = getimagesize( get_comic_directory( 'abs', true, $comic_dir ) . $comic_thumb ); - } - - if ( strpos( $comic_thumb, 'thumb' ) && !$output->thumb ) { - $output->thumb = ( get_option( 'comic_secure_paths' ) ) ? get_settings( 'home' ) . '?comic_object=' . $output->ID . '/thumb' : get_comic_directory( 'url', true, $comic_dir ) . $comic_thumb; - $output->thumb_name = $comic_thumb; - $output->thumb_data = getimagesize( get_comic_directory( 'abs', true, $comic_dir ) . $comic_thumb ); - } - } - } - } else { - $output->file = false; - } - } - - return $output; -} - -/** - * Returns a properly formatted or comic element. - * - * This is a utility function designed to retrieve an appropriately - * formatted or element from a $comic object based on - * the specified size. - * - * If the specified size is not found for regular image comics, this - * function will attempt to retrieve the next smallest size. If no - * comic thumbnail can be retrieved (or no size is specified) the - * standard comic file is used. - * - * @package Webcomic - * @since 1.7.0 - * - * @param object $comic A comic object generated by get_the_comic. - * @param str $size The size of the comic image to return. - * @param bool $secure Use secure URL's regardless of the comic_secure_path setting - * @return str Properly formatted or element for use in HTML output. - */ -function get_comic_object( $comic = false, $size = false, $secure = false ) { - if ( !$comic || !is_object( $comic ) ) - return; //A $comic object with a file is required - - if ( !$comic->file ) - return $comic->title; //No comic file, return the post title instead - - $size = ( $size ) ? $size : 'full'; - - if ( $comic->flash ) { - if ( 'full' == $size ) - $dims = $comic->file_data[ 3 ]; - else - $dims = 'height="' . get_option( 'comic_' . $size . '_size_h' ) . '" width="' . get_option( 'comic_' . $size . '_size_w' ) . '"'; - - $output = ''; - } else { - if ( 'full' == $size ) { - $size = ( $secure ) ? get_option( 'home' ) . '?comic_object=' . $comic->ID : $comic->file; - $dims = $comic->file_data[ 3 ]; - } - - if ( 'large' == $size ) { - if ( $comic->large ) - $size = ( $secure ) ? get_option( 'home' ) . '?comic_object=' . $comic->ID . '/large' : $comic->large; - else - $size = 'medium'; - - $dims = ( $comic->large ) ? $comic->large_data[ 3 ] : ''; - } - - if ( 'medium' == $size ) { - if ( $comic->medium ) - $size = ( $secure ) ? get_option( 'home' ) . '?comic_object=' . $comic->ID . '/medium' : $comic->medium; - else - $size = 'thumb'; - - $dims = ( $comic->medium ) ? $comic->medium_data[ 3 ] : ''; - } - - if ( 'thumb' == $size ) { - if ( $comic->thumb ) - $size = ( $secure ) ? get_option( 'home' ) . '?comic_object=' . $comic->ID . '/thumb' : $comic->thumb; - else - $size = ( $secure ) ? get_option( 'home' ) . '?comic_object=' . $comic->ID : $comic->file; - - $dims = ( $comic->thumb ) ? $comic->thumb_data[ 3 ] : $comic->file_data[ 3 ]; - } - - $output = '' . $comic->title . ''; - } - - return $output; -} - -/** - * Returns buffer comic information. - * - * This function retrieves information related to "buffer" comics. - * For Webcomic's purposes a buffer comic is a post that is: - * - * 1. Scheduled to post some time in the future - * 2. Associated with a comic file - * - * @package Webcomic - * @since 2.1.0 - * - * @param int $series Category ID. - * @return obj An object containing buffer comic information. - */ -function get_comic_buffer( $series = false ) { - global $webcomic_series; - - $series = ( $series ) ? $series : $webcomic_series; - - if ( !$series ) - return; //No series defined; - - $posts = get_objects_in_term( $series, 'category' ); - - if ( !$posts ) - return; //No posts - - foreach ( array_keys( $posts ) as $key ) { - $_post = get_post( $posts[ $key ] ); - - if ( 'future' == $_post->post_status && 'post' == $_post->post_type && get_the_comic( $_post->ID )->file ) - $posts_sort[] = strtotime( $_post->post_date ); - } - - if ( !$posts_sort ) - return; //No scheduled posts - - natsort( $posts_sort ); - $last = array_reverse( $posts_sort ); - - $output = new stdClass(); - $output->count = ( int ) count( $last ); - $output->date = date( get_option( 'date_format' ), $last[ 0 ] ); - $output->time = date( get_option( 'time_format' ), $last[ 0 ] ); - $output->datetime = date( get_option( 'date_format' ), $last[ 0 ] ) . ' @ ' . date( get_option( 'time_format' ), $last[ 0 ] ); - $output->timestamp = $last[ 0 ]; - - return $output; -} - -/** - * Returns information associated with the specified chapter. - * - * This function retrieves information related to the specified chapter - * from Webcomic's "chapter" taxonomy. The taxonomy itself is split into - * chapters, volumes, and series. - * - * When used inside a WordPress Loop, this function returns the chapter - * information associated with the current post (if any). Posts can only - * be assigned to chapters, so setting the $chapter parameter to 'volume' - * or 'series' will let the function know that we want the volume or series - * the current post belongs to inestead of the chapter. - * - * @package Webcomic - * @since 1.0.0 - * - * @uses get_the_comic() - * @uses get_post_comic_chapters() - * - * @param int|str $chapter Chapter ID or one of 'chapter, 'volume', or 'series'. - * @return object An object containing chapter information. - */ -function get_the_chapter( $id = false ) { - global $post; - - $id = ( $id ) ? $id : 'chapter'; - - if ( is_numeric( $id ) ) { - $chapter = get_term( ( int ) $id, 'chapter' ); - - if ( !$chapter->parent ) - $css = 'series'; - elseif ( !get_term_children( $chapter->term_id, 'chapter' ) ) - $css = 'chapter'; - else - $css = 'volume'; - } else { - $chapters = get_post_comic_chapters( $post->ID ); - $chapter = $chapters->$id; - $css = $id; - } - - if ( !$chapter || is_wp_error( $chapter ) ) - return; //No chapter could be found - - $output = new stdClass(); - $output->ID = ( int ) $chapter->term_id; - $output->title = $chapter->name; - $output->slug = $chapter->slug; - $output->description = $chapter->description; - $output->count = ( int ) $chapter->count; - $output->parent = ( int ) $chapter->parent; - $output->class = 'comic-' . $css . '-item comic-' . $css . '-item-' . $chapter->term_id; - $output->link = get_term_link( ( int ) $chapter->term_id, 'chapter' ); - $output->feed = $output->link . 'feed/'; - $output->first = get_the_comic( 'first', $css, $chapter->term_id ); - $output->last = get_the_comic( 'last', $css, $chapter->term_id ); - - return $output; -} - -/** - * Returns all series, volume, chapter, and comic information for the entire site. - * - * This function returns a multidimensional, hiearchical object with four tiers. - * The first tier contains all of the comic series, each of which corresponds to - * a selected comic category. - * - * Each series contains a second teir (designated by the 'volumes' property) that - * contains all of the volume information for a given series. Each volume contains - * a third teir (designated by the 'chapters' property) that contains all of that - * volumes chapter information. - * - * Each chapter then contains a fourth tier (designated by the 'posts' property) - * that contains all of that chapters comic post information, as retrieved by - * get_the_comic(). - * - * Accepts a string or array of any arguments get_terms() will accept, as well as - * the additional parameters 'series', 'depth', and 'post_order'. - * - * series - Comma separated list of category ID's. Defaults to 0 (all). - * - * depth - How deep to function should iterate. Defaults to 4 (posts). - * - * post_order - What order posts should be returned in. Defaults to 'ASC'. - * - * @package Webcomic - * @since 1.4.0 - * - * @uses get_the_comic() - * @uses get_the_chapter() - * - * @param str|array $args An array or string of arguments (see above). - * @return object Multidimensional object containig series, volume, chapter, and comic information. - */ -function get_the_collection( $args = '' ) { - $defaults = array( - 'orderby' => 'id', - 'order' => 'ASC', - 'hide_empty' => 1, - 'series' => false, - 'depth' => 4, - 'post_order' => 'ASC' - ); - - $args = wp_parse_args( $args, $defaults ); - - if ( $args[ 'series' ] ) - $args[ 'series' ] = explode( ',', $args[ 'series' ] ); - - $collection = get_terms( 'chapter', $args ); - - if ( !$collection ) - return; //No collection could be found - - $series = new stdClass(); - - foreach ( array_keys( $collection ) as $key ) { - if ( !$collection[ $key ]->parent && ( !$args[ 'series' ] || false !== array_search( $collection[ $key ]->term_id, $args[ 'series' ] ) ) ) { - $series->{ $collection[ $key]->term_id } = get_the_chapter( $collection[ $key ]->term_id ); - $series->{ $collection[ $key]->term_id }->volumes = new stdClass(); - } else { - $chapters[ $collection[ $key ]->term_id ] = get_the_chapter( $collection[ $key ]->term_id ); - } - } - - if ( 1 < $args[ 'depth' ] && $chapters ) { - foreach ( array_keys( $chapters ) as $key ) { - if ( array_key_exists( $chapters[ $key ]->parent, get_object_vars( $series ) ) ) { - $chapters[ $key ]->chapters = new stdClass(); - $volumes[ $key ] = $chapters[ $key ]; - $series->{ $chapters[ $key ]->parent }->volumes->$key = $chapters[ $key ]; - unset( $chapters[ $key ] ); - } else { - $chapters[ $key ]->posts = new stdClass(); - } - } - } - - if ( 2 < $args[ 'depth' ] && $volumes && $chapters ) { - foreach ( array_keys( $chapters ) as $key) { - if ( array_key_exists( $chapters[ $key ]->parent, $volumes ) ) { - if ( 3 < $args[ 'depth' ] ) { - $chapter_posts = new stdClass(); - $posts_flat = get_objects_in_term( $key, 'chapter' ); - - if ( $posts_flat ) { - foreach ( array_keys( $posts_flat ) as $post_key ) { - $chapter_post = get_post( $posts_flat[ $post_key ] ); - - if ( 'publish' == $chapter_post->post_status && 'post' == $chapter_post->post_type ) - $posts_sort[ $chapter_post->ID ] = strtotime( $chapter_post->post_date ); - } - - natsort( $posts_sort ); - - $posts_order = ( 'DESC' == $args[ 'post_order' ] ) ? array_reverse( $posts_sort, true ) : $posts_sort; - - foreach( array_keys( $posts_order ) as $_post ) - $chapter_posts->$_post = get_the_comic( $_post ); - - $chapters[ $key ]->posts = $chapter_posts; - } - - unset( $posts_flat, $posts_sort, $posts_order, $chapter_posts ); - } - - $series->{ $volumes[ $chapters[ $key ]->parent ]->parent }->volumes->{ $chapters[ $key ]->parent }->chapters->$key = $chapters[ $key ]; - } - } - } - - unset( $collection, $volumes, $chapters ); - - return $series; -} - - - -// -// Comic Display -// - -/** - * Displays the comic associated with the current post. - * - * This is a shortcut function for displaying the comic associated with the - * current post. The comic may optionally be linked to an adjacent comic post - * if it is not a Flash comic. - * - * @package Webcomic - * @since 1.0.0 - * - * @uses get_the_comic() - * @uses get_comic_object() - * - * @param str $size The size of the comic image to return. - * @param str $link Make comic images clickable links, one of 'previous', 'next', or 'self'. - * @param str $limit Restrict the next/previous link, one of 'chapter', 'volume', or 'series'. - * @return bool False if not a comic post. - */ -function the_comic( $size = false, $link = false, $limit = false ) { - if ( !in_comic_category() ) - return; //Not a comic post - - $comic = get_the_comic(); - - if ( $link && !$comic->flash ) { - if ( 'self' == $link ) { - $before = ''; - } else { - $adj_comic = get_the_comic( $link, $limit ); - $before = ''; - } - - $after = ''; - } - - echo $before . get_comic_object( $comic, $size ) . $after; -} - -/** - * Displays the comic embed code associated with the current post. - * - * This function displays an input box with XHTML useful for sharing the - * current comic on other websites (embed code). It must be used within a - * WordPress Loop. - * - * @package Webcomic - * @since 1.0.0 - * - * @uses get_the_comic() - * @uses get_comic_object() - * - * @param str $size The size of the comic image the embed code will display, one of 'full', 'large', 'medium', or 'thumb'. - * @param str $format The markup to use for the display code, one of 'html' or 'bbcode'. - * @return bool False if not a comic post or $format = bbcode and the comic is a flash file. - */ -function the_comic_embed( $size = 'medium', $format = false ) { - if ( !in_comic_category() ) - return; //Not a comic post - - $comic = get_the_comic(); - $object = get_comic_object( $comic, $size, true ); - - switch ( $format ) { - case 'bbcode': if ( !$comic->flash ) $output = '[url=' . $comic->link . '][img]' . get_option( 'home' ) . '?comic_object=' . $comic->ID . '/' . $size . '[/img][/url]'; else return; break; - case 'html' : - default : $output = htmlspecialchars( '' ); break; - } - - echo ''; -} - -/** - * Displays buffer comic information. - * - * This function displays various comic buffer related information. - * - * @package Webcomic - * @since 2.1.0 - * - * @param str $type The information to return, one of 'count', 'date', 'time', 'datetime', or 'timestamp' - * @param int $series Category ID. - */ -function the_comic_buffer( $type = 'count', $series = false ) { - global $webcomic_series; - - $series = ( $series ) ? $series : $webcomic_series; - - if ( $buffer = get_comic_buffer( $series ) ) - echo $buffer->$type; -} - -/** - * Displays a comic series link for the current post. - * - * This function displays a category link for the comic category - * the current post belongs to. - * - * @package Webcomic - * @since 2.1.0 - * - * - * @param str $label The text to display for the link, or one of 'full', 'large', 'medium', or 'thumb'. - * @return bool False if not a comic post. - */ -function the_comic_series( $label = false ) { - if ( !in_comic_category() ) - return; //Not a comic post - - $term_id = get_post_comic_category(); - $series = get_term( $term_id, 'category' ); - - if ( 'thumb' == $label || 'medium' == $label || 'large' == $label || 'full' == $label ) { - if ( $comic->flash ) { - $image = get_comic_object( get_the_comic( 'random', $series->ID ), $label ) . '
'; - $link = $series->name; - } else { - $link = get_comic_object( get_the_comic( 'random', $series->ID ), $label ); - } - } elseif ( $label ) { - $link = $label; - } else { - $link = $series->name; - } - - echo '' . $link . ''; -} - - - -// -// Comic Transcripts -// - -/** - * Displays the comic transcript template. - * - * This function includes the 'transcript.php' file included with a - * theme and intended for use with Webcomic's comic transcripts. If - * no 'transcript.php' file exists in the current theme, the default - * template included with Webcomic is used. - * - * Themes should provide their own transcript.php template, using the - * transcript.php provided with Webcomic as a general guideline. - * - * @package Webcomic - * @since 2.0.0 - * - * @param str $file The template file to look for, defaults to '/transcript.php'. - * @return False if not a comic post. - */ -function transcript_template( $file = '/transcript.php' ) { - if ( !in_comic_category() ) - return; //Not a comic post - - global $user_identity, $transcript_status, $transcript_response; - - $req = get_option( 'comic_transcripts_required' ); - $comic = get_the_comic(); - $transcript = $comic->transcript; - $transcript_status = $comic->transcript_status; - - if ( $transcript_response ) - echo '
' . $transcript_response . '
'; - - if ( file_exists( TEMPLATEPATH . $file ) ) { - require( TEMPLATEPATH . $file ); - } else { - require( webcomic_include_url( 'transcript.php', 'abs' ) ); - } -} - -/** - * Checks the status of a transcript. - * - * This function checks the status of the transcript associated - * with the current post and should only be used in the transcript - * template file. - * - * @package Webcomic - * @since 2.1.0 - * - * @param str $status The transcript status, one of 'publish', 'pending', or 'draft' - * @return True if the $status equals $transcript_status - */ -function have_transcript( $status = false ) { - global $transcript_status; - - if ( $transcript_status == $status ) - return true; -} - -/** - * Displays the comic transcript form title. - * - * This function displays the correct form title based on whether - * no transcript exists (submitting a new transcript) or the author - * is requesting improvement of an existing transcript. - * - * @package Webcomic - * @since 2.0.0 - * - * @param str $new The text to use for "new transcript" forms. - * @param str $improve The text to use for "improve transcript" forms. - * @return Returns false if $comic is not an array. - */ -function transcript_form_title( $new = false, $improve = false ) { - global $transcript_status; - - if ( 'pending' == $transcript_status ) - echo ( $improve ) ? $improve : __( 'Improve Transcript', 'webcomic' ); - else - echo ( $new ) ? $new : __( 'Submit Transcript', 'webcomic' ); -} - -/** - * Displays additional necessary hidden fileds used when submitting a transcript. - * - * This function outputs additional hidden fields used by the submit - * transcript form handler, including the comic ID, comic title, the type of - * existing transcript, a javascript "human check" field to enable auto-captcha, - * and user information if the user is already logged in. - * - * It also providese a single parameter, $captcha, that is used as a human - * validation answer for an optional 'trans_captcha' field in the transcript form. - * If provided, transcript_id_fields hashes the answer and then compares the hash - * to the hash of the submitted trans_captcha field to validate human submissions. - * - * @package Webcomic - * @since 2.0.0 - * - * @param str $captcha The specified answer to a user-specified "captcha" question. - */ -function transcript_id_fields( $captcha = false ) { - global $post, $user_ID, $user_identity, $user_email, $transcript_status; - - $type = ( 'pending' == $transcript_status ) ? 2 : 1; - - if ( $user_ID ) - $userfields = ' - - - '; - elseif ( $captcha ) - $userfields = ' - - '; - else - $userfields = ' - '; - - echo $userfields . ' - - - - '; -} - - - -// -// Post Navigation -// - -/** - * Displays the standard set of comic navigation links. - * - * This is a shortcut function for displaying the standard set of comic - * navigation links (first, back, next, last). Must be used within a - * WordPress Loop. - * - * @package Webcomic - * @since 1.0.0 - * - * @uses first_comic_link() - * @uses next_comic_link() - * @uses previous_comic_link() - * @uses last_comic_link() - * - * @param str $limit Navigation link boundary, one of 'chapter or 'volume'. - * @param str $sep The text to display between each comic link. - * @param str $fstlabel The text to display for the first comic link. - * @param str $prelabel The text to display for the previous comic link. - * @param str $nxtlabel The text to display for the next comic link. - * @param str $lstlabel The text to display for the last comic link. - * @return bool False if not a comic post. - */ -function comics_nav_link( $args = '' ) { - if ( !in_comic_category() ) - return; //Not a comic post - - $defaults = array( - 'sep' => false, - 'limit' => false, - 'label' => false, - 'bookend' => false, - 'fstlabel' => false, - 'prelabel' => false, - 'nxtlabel' => false, - 'lstlabel' => false, - 'fstbookend' => false, - 'lstbookend' => false - ); - - $args = wp_parse_args( $args, $defaults ); - - if ( $args[ 'sep' ] ) - $sep = '' . $args[ 'sep' ] . ''; - - if ( $args[ 'bookend' ] ) - $args[ 'fstbookend' ] = $args[ 'lstbookend' ] = $args[ 'bookend' ]; - - if ( $args[ 'label' ] ) - $args[ 'fstlabel' ] = $args[ 'prelabel' ] = $args[ 'nxtlabel' ] = $args[ 'lstlabel' ] = $args[ 'label' ]; - - first_comic_link( $args[ 'fstlabel' ], $args[ 'limit' ], $args[ 'fstbookend' ] ); - echo $sep; - previous_comic_link( $args[ 'prelabel' ], $args[ 'limit' ], $args[ 'fstbookend' ] ); - echo $sep; - next_comic_link( $args[ 'nxtlabel' ], $args[ 'limit' ], $args[ 'lstbookend' ] ); - echo $sep; - last_comic_link( $args[ 'lstlabel' ], $args[ 'limit' ], $args[ 'lstbookend' ] ); -} - -/** - * Displays a link to the first comic. - * - * This is a shortcut function for displaying a link to the first comic in - * the current comic series, useful for building standard comic navigation. - * - * If the optional $limit parameter is set, the 'first' comic changes from first - * in the current comic series to first in the current volume or chapter. Must - * be used within a WordPress Loop. - * - * @package Webcomic - * @since 1.0.0 - * - * @uses get_the_comic() - * @uses get_comic_object() - * @uses get_the_chapter() - * - * @param str $label The text to display for the link, or one of 'full', 'large', 'medium', 'thumb', or 'title'. - * @param int|str $limit Category ID or one of 'chapter', 'volume', or 'series'. - * @param int $bookend Post or Page ID. - * @return bool False if not a comic post. - */ -function first_comic_link( $label = false, $limit = false, $bookend = false ) { - if ( !in_comic_category() ) - return; //Not a comic post - - load_webcomic_domain(); - - global $post; - - $comic = get_the_comic( 'first', $limit ); - $chapter = ( $limit ) ? get_the_chapter( $limit ) : false; - - if ( 'thumb' == $label || 'medium' == $label || 'large' == $label || 'full' == $label ) { - if ( $comic->flash ) { - $object = get_comic_object( $comic, $label ); - $link = $comic->title; - } else { - $link = get_comic_object( $comic, $label ); - } - } elseif ( 'title' == $label ) { - $link = $comic->title; - } else { - $link = ( $label ) ? $label : __( '« First', 'webcomic' ); - } - - $current = ( ( $limit && $post->ID == $chapter->first->ID ) || ( $post->ID == $comic->ID ) ) ? ' current-comic' : ''; - $shortcut = ( get_option( 'comic_keyboard_shortcuts' ) ) ? ' kbd-shortcut' : ''; - - if ( $current && $bookend && $permalink = get_permalink( $bookend ) ) { - $comic->link = $permalink; - $current = ''; - } - - $class = 'first-comic-link' . $current . $shortcut; - - echo $object . '' . $link . ''; -} - -/** - * Displays a link to the last comic. - * - * This is a shortcut function for displaying a link to the last comic in - * the current comic series, useful for building standard comic navigation. - * - * If the optional $limit parameter is set, the 'last' comic changes from last - * in the current comic series to last in the current volume or chapter. Must - * be used within a WordPress Loop. - * - * @package Webcomic - * @since 1.0.0 - * - * @uses get_the_comic() - * @uses get_comic_object() - * @uses get_the_chapter() - * - * @param str $label The text to display for the link, or one of 'full', 'large', 'medium', 'thumb', or 'title'. - * @param int|str $limit Category ID or one of 'chapter', 'volume', or 'series'. - * @param int $bookend Post or Page ID. - * @return bool False if not a comic post. - */ -function last_comic_link( $label = false, $limit = false, $bookend = false ) { - if ( !in_comic_category() ) - return; //Not a comic post - - load_webcomic_domain(); - - global $post; - - $comic = get_the_comic( 'last', $limit ); - $chapter = ( $limit ) ? get_the_chapter( $limit ) : false; - - if ( 'thumb' == $label || 'medium' == $label || 'large' == $label || 'full' == $label ) { - if ( $comic->flash ) { - $object = get_comic_object( $comic, $label ); - $link = $comic->title; - } else { - $link = get_comic_object( $comic, $label ); - } - } elseif ( 'title' == $label ) { - $link = $comic->title; - } else { - $link = ( $label ) ? $label : __( 'Last »', 'webcomic' ); - } - - $current = ( ( $limit && $post->ID == $chapter->last->ID ) || ( $post->ID == $comic->ID ) ) ? ' current-comic' : ''; - $shortcut = ( get_option( 'comic_keyboard_shortcuts' ) ) ? ' kbd-shortcut' : ''; - - if ( $current && $bookend && $permalink = get_permalink( $bookend ) ) { - $comic->link = $permalink; - $current = ''; - } - - $class = 'last-comic-link' . $current . $shortcut; - - echo $object . '' . $link . ''; -} - -/** - * Displays a link to the previous comic. - * - * This is a shortcut function for displaying a link to the previous comic - * which exists in chronological order from the current comic in the current - * comic series. - * - * If the optional $limit parameter is set, 'previous' is limited to the current - * volume or chapter. Must be used within a WordPress Loop. - * - * @package Webcomic - * @since 1.0.0 - * - * @uses get_the_comic() - * @uses get_comic_object() - * @uses get_the_chapter() - * - * @param str $label The text to display for the link, or one of 'full', 'large', 'medium', 'thumb', or 'title'. - * @param str $limit Navigation link boundary, one of 'chapter or 'volume' - * @param int $bookend Post or Page ID. - * @return bool False if not a comic post. - */ -function previous_comic_link( $label = false, $limit = false, $bookend = false ) { - if ( !in_comic_category() ) - return; //Not a comic post - - load_webcomic_domain(); - - global $post; - - $comic = get_the_comic( 'previous', $limit ); - $chapter = ( $limit ) ? get_the_chapter( $limit ) : false; - - if ( 'thumb' == $label || 'medium' == $label || 'large' == $label || 'full' == $label ) { - if ( $comic->flash ) { - $object = get_comic_object( $comic, $label ); - $link = $comic->title; - } else { - $link = get_comic_object( $comic, $label ); - } - } elseif ( 'title' == $label ) { - $link = $comic->title; - } else { - $link = ( $label ) ? $label : __( '‹ Previous', 'webcomic' ); - } - - $current = ( ( $limit && $post->ID == $chapter->first->ID ) || ( $post->ID == $comic->ID ) ) ? ' current-comic' : ''; - $shortcut = ( get_option( 'comic_keyboard_shortcuts' ) ) ? ' kbd-shortcut' : ''; - - if ( $current && $bookend && $permalink = get_permalink( $bookend ) ) { - $comic->link = $permalink; - $current = ''; - } - - $class = 'previous-comic-link' . $current . $shortcut; - - echo $object . '' . $link . ''; -} - -/** - * Displays a link to the next comic. - * - * This is a shortcut function for displaying a link to the next comic - * which exists in chronological order from the current comic in the current - * comic series. - * - * If the optional $limit parameter is set, 'next' is limited to the current - * volume or chapter. Must be used within a WordPress Loop. - * - * @package Webcomic - * @since 1.0.0 - * - * @uses get_the_comic() - * @uses get_comic_object() - * @uses get_the_chapter() - * - * @param str $label The text to display for the link, or one of 'full', 'large', 'medium', 'thumb', or 'title'. - * @param str $limit Navigation link boundary, one of 'chapter or 'volume'. - * @param int $bookend Post or Page ID. - * @return bool False if not a comic post. - */ -function next_comic_link( $label = false, $limit = false, $bookend = false ) { - if ( !in_comic_category() ) - return; //Not a comic post - - load_webcomic_domain(); - - global $post; - - $comic = get_the_comic( 'next', $limit ); - $chapter = ( $limit ) ? get_the_chapter( $limit ) : false; - - if ( 'thumb' == $label || 'medium' == $label || 'large' == $label || 'full' == $label ) { - if ( $comic->flash ) { - $object = get_comic_object( $comic, $label ); - $link = $comic->title; - } else { - $link = get_comic_object( $comic, $label ); - } - } elseif ( 'title' == $label ) { - $link = $comic->title; - } else { - $link = ( $label ) ? $label : __( 'Next ›', 'webcomic' ); - } - - $current = ( ( $limit && $post->ID == $chapter->last->ID ) || ( $post->ID == $comic->ID ) ) ? ' current-comic' : ''; - $shortcut = ( get_option( 'comic_keyboard_shortcuts' ) ) ? ' kbd-shortcut' : ''; - - if ( $current && $bookend && $permalink = get_permalink( $bookend ) ) { - $comic->link = $permalink; - $current = ''; - } - - $class = 'next-comic-link' . $current . $shortcut; - - echo $object . '' . $link . ''; -} - -/** - * Displays a link to a randomly selected comic in the specified format. - * - * This is a shortcut function for displaying a link to a randomly selected comic. - * If the optional $limit parameter is not set, random_comic_link will randomly - * select from the available comic series, or use the current comic series when - * used in the Loop. - * - * @package Webcomic - * @since 1.0.0 - * - * @uses get_the_comic() - * @uses get_comic_object() - * - * @param str $label The link text or image size, one of 'thumb', 'medium', 'large', or 'full'. - * @param int|str $limit Category ID or one of 'chapter', 'volume', or 'series'. - * @param int $chapter Chapter ID. Required when outside the loop and $limit is 'chapter' or 'volume'. - */ -function random_comic_link( $label = false, $limit = false, $chapter = false ) { - $comic = get_the_comic( 'random', $limit, $chapter ); - - if ( 'thumb' == $label || 'medium' == $label || 'large' == $label || 'full' == $label ) { - if ( $comic->flash ) { - $image = get_comic_object( $comic, $label ) . '
'; - $link = $comic->title; - } else { - $link = get_comic_object( $comic, $label ); - } - } elseif ( $label ) { - $link = $label; - } else { - $link = $comic->title; - } - - $shortcut = ( get_option( 'comic_keyboard_shortcuts' ) ) ? ' kbd-shortcut' : ''; - - echo $image . '' . $link . ''; -} - -/** - * Displays a set of comic bookmark links. - * - * This function displays a set of comic bookmark links, designed to - * allow users to save their place and then return to or clear it at - * a later date. The bookmark differentiates between different series - * by using the "rel" attribute and setting a unique cookie based - * on the current series. - * - * The javascrip that powers this function can be found in scripts.js. - * - * @package Webcomic - * @since 2.0.0 - * - * @uses get_series_by_path - * - * @param str $sep Text to display between each bookmark link. - * @param str $bookmark Text to display for the 'bookmark' link. - * @param str $return Text to display for the 'return' link. - * @param str $clear Text to display for the 'clear' link. - */ -function bookmark_comic( $sep = false, $bookmark = false, $return = false, $clear = false ) { - global $post; - - if ( is_home() || is_category( get_comic_category( true ) ) || ( is_page() && get_post_meta( $post->ID, 'comic_series', true ) ) || ( is_single() && in_comic_category() ) ) { - if ( $sep ) $sep = '' . $sep . ''; - - $bookmark = ( $bookmark ) ? $bookmark : __( 'Bookmark', 'webcomic' ); - $return = ( $return ) ? $return : __( 'Return', ' webcomic' ); - $clear = ( $clear ) ? $clear : __( 'Clear', 'webcomic' ); - $series = get_series_by_path(); - - if ( $series ) - $series = $series->term_id; - - echo ' -
- ' . $bookmark . '' . $sep . ' - ' . $return . '' . $sep . ' - ' . $clear . ' -
'; - } -} - - - -// -// Chapter Navigation -// - -/** - * Displays the standard set of chapter navigation links. - * - * This is a shortcut function for displaying the standard set of chapter - * navigation links (first, back, next, last). - * - * @package Webcomic - * @since 1.8.0 - * - * @uses first_chapter_link() - * @uses next_chapter_link() - * @uses previous_chapter_link() - * @uses last_chapter_link() - * - * @param str $volume Links point to series volumes instead of chapters. - * @param str $bound Where the links should point to, one of 'first','last', or 'page'. - * @param str $sep The text to display between each chapter link. - * @param str $fstlabel The text to display for the first chapter link. - * @param str $prelabel The text to display for the previous chapter link. - * @param str $nxtlabel The text to display for the next chapter link. - * @param str $lstlabel The text to display for the last chapter link. - */ -function chapters_nav_link( $args = '' ) { - if ( !in_comic_category() ) - return; //Not a comic post - - $defaults = array( - 'sep' => false, - 'type' => false, - 'label' => false, - 'bound' => false, - 'bookend' => false, - 'fstlabel' => false, - 'prelabel' => false, - 'nxtlabel' => false, - 'lstlabel' => false, - 'fstbookend' => false, - 'lstbookend' => false - ); - - $args = wp_parse_args( $args, $defaults ); - - if ( $args[ 'sep' ] ) { - $type = ( $args[ 'type' ] ) ? $args[ 'type' ] : 'chapter'; - $sep = '' . $args[ 'sep' ] . ''; - } - - if ( $args[ 'label' ] ) - $args[ 'fstlabel' ] = $args[ 'prelabel' ] = $args[ 'nxtlabel' ] = $args[ 'lstlabel' ] = $args[ 'label' ]; - - if ( $args[ 'bookend' ] ) - $args[ 'fstbookend' ] = $args[ 'lstbookend' ] = $args[ 'bookend' ]; - - first_chapter_link( $args[ 'fstlabel' ], $args[ 'type' ], $args[ 'bound' ], $args[ 'fstbookend' ] ); - echo $sep; - previous_chapter_link( $args[ 'prelabel' ], $args[ 'type' ], $args[ 'bound' ], $args[ 'fstbookend' ] ); - echo $sep; - next_chapter_link( $args[ 'nxtlabel' ], $args[ 'type' ], $args[ 'bound' ], $args[ 'lstbookend' ] ); - echo $sep; - last_chapter_link( $args[ 'lstlabel' ], $args[ 'type' ], $args[ 'bound' ], $args[ 'lstbookend' ] ); -} - -/** - * Displays a link to the first chapter of the current series. - * - * This function displays a link to the first volume or chapter of the - * current series. Like the_chapter_link(), the link itself can point - * to the beginning or end of the chapter or the chapter archive page - * and must be used within a WordPress Loop. - * - * @package Web Comic - * @since 1.8.0 - * - * @uses get_the_chapter() - * @uses get_comic_object() - * @uses get_post_comic_chapters() - * @uses get_post_comic_category() - * - * @param str $label The text to display for the link, or one of 'full', 'large', 'medium', 'thumb', or 'title'. - * @param str $type The chapter link to display, one of 'chapter' or 'volume'. - * @param str $bound Where the link should point to, one of 'first','last', or 'page'. - */ -function first_chapter_link( $label = false, $type = false, $bound = false, $bookend = false ) { - if ( in_comic_category() && $post_chapters = get_post_comic_chapters( $post->ID ) ) { - load_webcomic_domain(); - - global $wpdb, $post; - - $type = ( $type ) ? $type : 'chapter'; - $bound = ( $bound ) ? $bound : 'first'; - $preview = ( 'thumb' == $label || 'medium' == $label || 'large' == $label || 'full' == $label ) ? true : false; - $chapters = get_post_comic_chapters( $wpdb->get_var( "SELECT p.id FROM $wpdb->posts AS p INNER JOIN $wpdb->term_relationships AS tr ON p.ID = tr.object_id INNER JOIN $wpdb->term_taxonomy tt ON tr.term_taxonomy_id = tt.term_taxonomy_id AND tt.taxonomy = 'category' AND tt.term_id IN (" . get_post_comic_category( $post->ID ) . ") WHERE p.post_type = 'post' AND p.post_status = 'publish' ORDER BY p.post_date ASC" ) ); - $chapter = get_the_chapter( $chapters->$type->term_id ); - - if ( 'page' == $bound ) { - $url = $chapter->link; - $title = sprintf( __( 'Go to the %s archive', 'webcomic' ), $chapter->title ); - $comic = ( $preview ) ? get_comic_object( get_the_comic( 'random', $type, $chapter->ID ), $label ) : false; - } else { - $url = ( 'first' == $bound ) ? $chapter->first->link : $chapter->last->link; - $title = ( 'first' == $bound ) ? sprintf( __( 'Go to the beginning of %s', 'webcomic' ), $chapter->title ) : sprintf( __( 'Go to the end of %s', 'webcomic' ), $chapter->title ); - $comic = ( $preview ) ? get_comic_object( $chapter->$bound, $label ) : false; - } - - if ( false !== strpos( $comic, ''; - $link = $chapter->title; - } elseif ( $comic ) { - $link = $comic; - } elseif ( 'title' == $label ) { - $link = $chapter->title; - } else { - $link = ( $label ) ? $label : sprintf( __( '« First %s', 'webcomic' ), ucfirst( $type ) ); - } - - $current = ( $post_chapters->$type->term_id == $chapter->ID ) ? ' current-' . $type : ''; - - if ( $current && $bookend && $permalink = get_permalink( $bookend ) ) { - $url = $permalink; - $current = ''; - } - - $class = $chapter->class . ' first-' . $type . '-link' . $current; - - echo $object . '' . $link . ''; - } -} - -/** - * Displays a link to the last chapter of the current series. - * - * This function displays a link to the last volume or chapter of the - * current series. Like the_chapter_link(), the link itself can point - * to the beginning or end of the chapter or the chapter archive page - * and must be used within a WordPress Loop. - * - * @package Web Comic - * @since 1.8.0 - * - * @uses get_the_chapter() - * @uses get_comic_object() - * @uses get_post_comic_chapters() - * @uses get_post_comic_category() - * - * @param str $label The text to display for the link, or one of 'full', 'large', 'medium', 'thumb', or 'title'. - * @param str $type The chapter link to display, one of 'chapter' or 'volume'. - * @param str $bound Where the link should point to, one of 'first','last', or 'page'. - */ -function last_chapter_link( $label = false, $type = false, $bound = false, $bookend = false ) { - if ( in_comic_category() && $post_chapters = get_post_comic_chapters( $post->ID ) ) { - load_webcomic_domain(); - - global $wpdb, $post; - - $type = ( $type ) ? $type : 'chapter'; - $bound = ( $bound ) ? $bound : 'first'; - $preview = ( 'thumb' == $label || 'medium' == $label || 'large' == $label || 'full' == $label ) ? true : false; - $chapters = get_post_comic_chapters( $wpdb->get_var( "SELECT p.id FROM $wpdb->posts AS p INNER JOIN $wpdb->term_relationships AS tr ON p.ID = tr.object_id INNER JOIN $wpdb->term_taxonomy tt ON tr.term_taxonomy_id = tt.term_taxonomy_id AND tt.taxonomy = 'category' AND tt.term_id IN (" . get_post_comic_category( $post->ID ) . ") WHERE p.post_type = 'post' AND p.post_status = 'publish' ORDER BY p.post_date DESC" ) ); - $chapter = get_the_chapter( $chapters->$type->term_id ); - - if ( 'page' == $bound ) { - $url = $chapter->link; - $title = sprintf( __( 'Go to the %s archive', 'webcomic' ), $chapter->title ); - $comic = ( $preview ) ? get_comic_object( get_the_comic( 'random', $type, $chapter->ID ), $label ) : false; - } else { - $url = ( 'first' == $bound ) ? $chapter->first->link : $chapter->last->link; - $title = ( 'first' == $bound ) ? sprintf( __( 'Go to the beginning of %s', 'webcomic' ), $chapter->title ) : sprintf( __( 'Go to the end of %s', 'webcomic' ), $chapter->title ); - $comic = ( $preview ) ? get_comic_object( $chapter->$bound, $label ) : false; - } - - if ( false !== strpos( $comic, ''; - $link = $chapter->title; - } elseif ( $comic ) { - $link = $comic; - } elseif ( 'title' == $label ) { - $link = $chapter->title; - } else { - $link = ( $label ) ? $label : sprintf( __( 'Last %s »', 'webcomic' ), ucfirst( $type ) ); - } - - $current = ( $post_chapters->$type->term_id == $chapter->ID ) ? ' current-' . $type : ''; - - if ( $current && $bookend && $permalink = get_permalink( $bookend ) ) { - $url = $permalink; - $current = ''; - } - - $class = $chapter->class . ' last-' . $type . '-link' . $current; - - echo $object . '' . $link . ''; - } -} - -/** - * Displays a link to the previous chapter of the current series. - * - * This function displays a link to the previous volume or chapter of the - * current series. Like the_chapter_link(), the link itself can point - * to the beginning or end of the chapter or the chapter archive page - * and must be used within a WordPress Loop. - * - * @package Web Comic - * @since 1.8.0 - * - * @uses get_the_chapter() - * @uses get_comic_object() - * @uses get_post_comic_chapters() - * @uses get_post_comic_category() - * - * @param str $label The text to display for the link, or one of 'full', 'large', 'medium', 'thumb', or 'title'. - * @param str $type The chapter link to display, one of 'chapter' or 'volume'. - * @param str $bound Where the link should point to, one of 'first','last', or 'page'. - */ -function previous_chapter_link( $label = false, $type = false, $bound = false, $bookend = false ) { - if ( in_comic_category() && $post_chapters = get_post_comic_chapters( $post->ID ) ) { - load_webcomic_domain(); - - global $wpdb, $post; - - $type = ( $type ) ? $type : 'chapter'; - $bound = ( $bound ) ? $bound : 'first'; - $preview = ( 'thumb' == $label || 'medium' == $label || 'large' == $label || 'full' == $label ) ? true : false; - $_post = get_post( get_the_chapter( $post_chapters->$type->term_id )->first->ID ); - $chapters = get_post_comic_chapters( $wpdb->get_var( "SELECT p.id FROM $wpdb->posts AS p INNER JOIN $wpdb->term_relationships AS tr ON p.ID = tr.object_id INNER JOIN $wpdb->term_taxonomy tt ON tr.term_taxonomy_id = tt.term_taxonomy_id AND tt.taxonomy = 'category' AND tt.term_id IN (" . get_post_comic_category( $post->ID ) . ") WHERE p.post_date < '$_post->post_date' AND p.post_type = 'post' AND p.post_status = 'publish' ORDER BY p.post_date DESC LIMIT 1" ) ); - $chapter = get_the_chapter( $chapters->$type->term_id ); - - if ( 'page' == $bound ) { - $url = $chapter->link; - $title = sprintf( __( 'Go to the %s archive', 'webcomic' ), $chapter->title ); - $comic = ( $preview ) ? get_comic_object( get_the_comic( 'random', $type, $chapter->ID ), $label ) : false; - } else { - $url = ( 'first' == $bound ) ? $chapter->first->link : $chapter->last->link; - $title = ( 'first' == $bound ) ? sprintf( __( 'Go to the beginning of %s', 'webcomic' ), $chapter->title ) : sprintf( __( 'Go to the end of %s', 'webcomic' ), $chapter->title ); - $comic = ( $preview ) ? get_comic_object( $chapter->$bound, $label ) : false; - } - - if ( false !== strpos( $comic, ''; - $link = $chapter->title; - } elseif ( $comic ) { - $link = $comic; - } elseif ( 'title' == $label ) { - $link = $chapter->title; - } else { - $link = ( $label ) ? $label : sprintf( __( '‹ Previous %s', 'webcomic' ), ucfirst( $type ) ); - } - - $current = ( $post_chapters->$type->term_id == $chapter->ID ) ? ' current-' . $type : ''; - - if ( $current && $bookend && $permalink = get_permalink( $bookend ) ) { - $url = $permalink; - $current = ''; - } - - $class = $chapter->class . ' previous-' . $type . '-link' . $current; - - echo $object . '' . $link . ''; - } -} - -/** - * Displays a link to the next chapter of the current series. - * - * This function displays a link to the next volume or chapter of the - * current series. Like the_chapter_link(), the link itself can point - * to the beginning or end of the chapter or the chapter archive page - * and must be used within a WordPress Loop. - * - * @package Web Comic - * @since 1.8.0 - * - * @uses get_the_chapter() - * @uses get_comic_object() - * @uses get_post_comic_chapters() - * @uses get_post_comic_category() - * - * @param str $label The text to display for the link, or one of 'full', 'large', 'medium', 'thumb', or 'title'. - * @param str $type The chapter link to display, one of 'chapter' or 'volume'. - * @param str $bound Where the link should point to, one of 'first','last', or 'page'. - */ -function next_chapter_link( $label = false, $type = false, $bound = false, $bookend = false ) { - if ( in_comic_category() && $post_chapters = get_post_comic_chapters( $post->ID ) ) { - load_webcomic_domain(); - - global $wpdb, $post; - - $type = ( $type ) ? $type : 'chapter'; - $bound = ( $bound ) ? $bound : 'first'; - $preview = ( 'thumb' == $label || 'medium' == $label || 'large' == $label || 'full' == $label ) ? true : false; - $_post = get_post( get_the_chapter( $post_chapters->$type->term_id )->last->ID ); - $chapters = get_post_comic_chapters( $wpdb->get_var( "SELECT p.id FROM $wpdb->posts AS p INNER JOIN $wpdb->term_relationships AS tr ON p.ID = tr.object_id INNER JOIN $wpdb->term_taxonomy tt ON tr.term_taxonomy_id = tt.term_taxonomy_id AND tt.taxonomy = 'category' AND tt.term_id IN (" . get_post_comic_category( $post->ID ) . ") WHERE p.post_date > '$_post->post_date' AND p.post_type = 'post' AND p.post_status = 'publish' ORDER BY p.post_date ASC LIMIT 1" ) ); - $chapter = get_the_chapter( $chapters->$type->term_id ); - - if ( 'page' == $bound ) { - $url = $chapter->link; - $title = sprintf( __( 'Go to the %s archive', 'webcomic' ), $chapter->title ); - $comic = ( $preview ) ? get_comic_object( get_the_comic( 'random', $type, $chapter->ID ), $label ) : false; - } else { - $url = ( 'first' == $bound ) ? $chapter->first->link : $chapter->last->link; - $title = ( 'first' == $bound ) ? sprintf( __( 'Go to the beginning of %s', 'webcomic' ), $chapter->title ) : sprintf( __( 'Go to the end of %s', 'webcomic' ), $chapter->title ); - $comic = ( $preview ) ? get_comic_object( $chapter->$bound, $label ) : false; - } - - if ( false !== strpos( $comic, ''; - $link = $chapter->title; - } elseif ( $comic ) { - $link = $comic; - } elseif ( 'title' == $label ) { - $link = $chapter->title; - } else { - $link = ( $label ) ? $label : sprintf( __( 'Next %s ›', 'webcomic' ), ucfirst( $type ) ); - } - - $current = ( $post_chapters->$type->term_id == $chapter->ID ) ? ' current-' . $type : ''; - - if ( $current && $bookend && $permalink = get_permalink( $bookend ) ) { - $url = $permalink; - $current = ''; - } - - $class = $chapter->class . ' next-' . $type . '-link' . $current; - - echo $object . '' . $link . ''; - } -} - -/** - * Displays the chapter link associated with the current post. - * - * This is a shortcut function for displaying a link to the beginning, end, - * or archive page of the chapter, volume, or series associated with the - * current post and must be used within a WordPress Loop. - * - * @package Webcomic - * @since 1.0.0 - * - * @uses get_the_chapter() - * @uses get_comic_object() - * @uses get_post_comic_chapters() - * - * @param str $label The text to display for the link, or one of 'full', 'large', 'medium', 'thumb', or 'title'. - * @param str $type The chapter link to display, one of 'chapter' or 'volume'. - * @param str $bound Where the link should point to, one of 'first','last', or 'page'. - */ -function the_chapter_link( $label = false, $type = false, $bound = false ) { - if ( in_comic_category() && $chapter = get_the_chapter( $type ) ) { - load_webcomic_domain(); - - global $post; - - $type = ( $type ) ? $type : 'chapter'; - $bound = ( $bound ) ? $bound : 'first'; - $preview = ( 'thumb' == $label || 'medium' == $label || 'large' == $label || 'full' == $label ) ? true : false; - - if ( 'page' == $bound ) { - $url = $chapter->link; - $title = sprintf( __( 'Go to the %s archive', 'webcomic' ), $chapter->title ); - $comic = ( $preview ) ? get_comic_object( get_the_comic( 'random', $type, $chapter->ID ), $label ) : false; - } else { - $url = ( 'first' == $bound ) ? $chapter->first->link : $chapter->last->link; - $title = ( 'first' == $bound ) ? sprintf( __( 'Go to the beginning of %s', 'webcomic' ), $chapter->title ) : sprintf( __( 'Go to the end of %s', 'webcomic' ), $chapter->title ); - $comic = ( $preview ) ? get_comic_object( $chapter->$bound, $label ) : false; - } - - if ( false !== strpos( $comic, ''; - $link = $chapter->title; - } elseif ( $comic ) { - $link = $comic; - } else { - $link = ( $label ) ? $label : $chapter->title; - } - - $class = 'current-' . $type . '-link'; - - echo $object . '' . $link . ''; - } -} - - - -// -// Chapter Archives -// - -/** - * Displays the chapter title on chapter archive pages. - * - * This function displays the chapter title on chapter archive pages. Like - * single_cat_title() it accepts both $prefix and $display parameters. - * - * @package Webcomic - * @since 1.8.0 - * - * @param str $prefix Prefix to prepend to the chapter name. - * @param bool $display Returns the chapter title if set to false. - * @return str The chapter title, if $display is set to false. - */ -function single_chapter_title( $prefix = false, $display = true ) { - $chapter = get_term_by( 'slug', get_query_var( 'chapter' ), 'chapter' ); - - if ( $display ) - echo $prefix . $chapter->name; - else - return $chapter->name; -} - -/** - * Returns the specified chapter description. - * - * This function returns the specified chapter description. If used on - * a chapter archive page with no defined $chapter the current chapter - * description is returned. - * - * @package Webcomic - * @since 1.8.0 - * - * @param int $id Chapter ID. - * @return str The chapter description. - */ -function chapter_description( $id = false ) { - return term_description( $id, 'chapter' ); -} - - - -// -// Comic Archives -// - -/** - * Displays a list of recently posted comics. - * - * This is a shortcut function for displaying a list of recently posted comics - * using comic_loop() and get_the_comic(). - * - * @package Webcomic - * @since 1.0.0 - * - * @uses comic_loop() - * @uses get_the_comic() - * @uses get_comic_object() - * - * @param int $number The number of comics to display. - * @param str $label The image size, one of 'full', 'large', 'medium', or 'thumb'. - * @param str $limit Comma separated list of category ID's. - */ -function recent_comics( $number = 5, $label = false, $limit = false ) { - $comics = comic_loop( $number, $limit ); - - if ( $comics->have_posts() ) : while ( $comics->have_posts() ) : $comics->the_post(); - $comic = get_the_comic(); - - $link = ( $label ) ? get_comic_object( $comic, $label ) : $comic->title; - - if ( $comic->flash && $label ) { - $object = $link . '
'; - $link = $comic->title; - } - - $output .= '
  • ' . $object . '' . $link . '' . '
  • '; - endwhile; wp_reset_query(); endif; - - echo $output; -} - -/** - * Displays a form select control with comic posts or chapters. - * - * This function displays a form select control (dropdown box) listing comics - * or comic chapters. The javascrip that powers this function can be found in - * scripts.js. A number of arguments can be specified: - * - * label - The text displayed on the top first, neutral select value. defaults to - * 'Quick Archive'. - * - * post_order - The order of posts. Defaults to 'DESC'. - * - * number - Whether or not to prepend each post or chapter with a number. - * Defaults to 0 (false). - * - * groupby - Group posts by chapter, chapters, by volume, or volumes by series. One - * of 'chapter', 'volume', or 'series'. - * - * orderby - The field used to order chapters. Defaults to 'id'. - * - * order = The order to retrieve chapters in. Defaults to 'ASC'. - * - * series - Comma-separated list of series ID's to include. Defaults to false (all). - * - * bound - Where chapter options should point to. One of 'first' (default), - * 'last', or 'page' - * - * pages - Whether to append chapter titles with page counts. Defaults to false. - * - * @package Webcomic - * @since 1.0.0 - * - * @uses comic_loop() - * @uses get_the_collection() - * - * @param str|arr $args An array or string of arguments. - */ -function dropdown_comics( $args = '' ) { - load_webcomic_domain(); - - $defaults = array( - 'label' => __( 'Quick Archive', 'webcomic' ), - 'pages' => false, - 'order' => 'ASC', - 'bound' => 'first', - 'number' => false, - 'series' => false, - 'groupby' => false, - 'orderby' => 'id', - 'post_order' => 'DESC' - ); - - $args = wp_parse_args( $args, $defaults ); - - $output = ''; - - echo $output; -} - -/** - * Displays the comic archive in the specified format organized in the specified way. - * - * This is a very flexible function for display comic archives organized either by date - * or chapter (storyline). A number of arguments can be specified to control the output: - * - * groupby - Group posts by year, month, and day or series, volume, and chapter, one of 'date' or 'chapter'. - * - * format - How to display individual comic links. One of 'number' (display as a page number), - * 'full', 'large', 'medium', or 'thumb' (for images), or false (use the post title). - * - * series - Comma-separated list of series ID's to include. Defaults to 0 (all). - * - * post_order - The order of posts. Defaults to 'DESC'. - * - * orderby - The field used to order chapters. Defaults to 'id'. - * - * order - The order to retrieve chapters in. Defaults to 'ASC'. - * - * depth - Sets the depth parameter for storline archives. Defaults to 4. - * - * bound - Where series, volume, and chapter link should point to. One of - * 'first' (default), 'last', or 'page' - * - * descriptions - Whether to display series, volume, and chapter descriptions. - * Defaults to false. - * - * pages - Whether to display series, volume, and chapter page counts. - * Defaults to false. - * - * @package Webcomic - * @since 1.0.0 - * - * @uses comic_loop() - * @uses get_the_comic() - * @uses get_the_collection() - * - * @param str|arr $args An array or string of arguments. - */ -function comic_archive( $args = '' ) { - $defaults = array( - 'order' => 'ASC', - 'depth' => 4, - 'bound' => 'first', - 'pages' => false, - 'series' => false, - 'format' => false, - 'groupby' => 'date', - 'orderby' => 'id', - 'post_order' => 'DESC', - 'descriptions' => false - ); - - $args = wp_parse_args( $args, $defaults ); - - if ( 'date' == $args[ 'groupby' ] ) { - $comics = comic_loop( -1, $args[ 'series' ], '&order=' . $args[ 'post_order' ] ); - - if ( $comics->have_posts() ) : while( $comics->have_posts() ) : $comics->the_post(); - if ( $the_year != get_the_time( 'Y' ) ) { - $i = 0; - $the_month = 0; - - if ( $the_year ) - $output .= ( $args[ 'format' ] ) ? '' : ''; - - $the_year = get_the_time( 'Y' ); - $output .= '
    ' . $the_year . '
    '; - } - - $tr_class = ( !( $i % 2 ) ) ? ' class="alt"' : ''; - - if ( $args[ 'format' ] && 'number' != $args[ 'format' ]) { - if ( $the_month != get_the_time( 'm' ) ) { - if ( $the_month ) - $output .= ''; - - $output .= ' - - '; - - $i++; - } - endwhile; $output .= ( $args[ 'format' ] ) ? '
    ' . get_the_time( 'F' ) . ''; - - $the_month = get_the_time( 'm' ); - - $i++; - } - - $comic = get_the_comic(); - $link = get_comic_object( $comic, $args[ 'format' ] ); - - if ( $comic->flash ) { - $image = $link; - $link = $comic->title; - } - - $output .= $image . '' . $link . ''; - } else { - $output .= ' - - ' . get_the_time( 'F jS' ) . '' . the_title_attribute( 'echo=0' ) . '
    ' : ''; wp_reset_query(); endif; - } elseif ( 'chapter' == $args[ 'groupby' ] ) { - $collection = get_the_collection( 'order=' . $args[ 'order' ] . '&orderby=' . $args[ 'orderby' ] . '&series=' . $args[ 'series' ] . '&post_order=' . $args[ 'post_order' ] . '&depth=' . $args[ 'depth' ] ); - - if ( $collection ) { - $output = '
      '; - - foreach ( array_keys( get_object_vars( $collection ) ) as $series ) { - if ( 1 < count( $colleciton ) ) { - $description = ( $args[ 'descriptions' ] && $collection->$series->description ) ? '

      ' . $collection->$series->description . '

      ' :''; - $pages = ( $args[ 'pages' ] ) ? ' (' . $collection->$series->count . ')' : ''; - - switch( $args[ 'bound' ] ) { - case 'page': - $link = $collection->$series->link; - $title = sprintf( __( 'Go to the %s archive', 'webcomic' ), $collection->$series->title ); - break; - case 'last': - $link = $collection->$series->last->link; - $title = sprintf( __( 'Go to the end of %s', 'webcomic' ), $collection->$series->title ); - break; - default: - $link = $collection->$series->first->link; - $title = sprintf( __( 'Go to the beginning of %s', 'webcomic'), $collection->$series->title ); - } - - $output .= '
    1. ' . $collection->$series->title . $pages . '' . $description . '
        '; - } - - foreach ( array_keys( get_object_vars( $collection->$series->volumes ) ) as $volume ) { - $description = ( $args[ 'descriptions' ] && $collection->$series->volumes->$volume->description ) ? '

        ' . $collection->$series->volumes->$volume->description . '

        ' : ''; - $pages = ( $args[ 'pages' ] ) ? ' (' . $collection->$series->volumes->$volume->count . ')' : ''; - - switch( $args[ 'bound' ] ) { - case 'page': - $link = $collection->$series->volumes->$volume->link; - $title = sprintf( __( 'Go to the %s archive', 'webcomic' ), $collection->$series->volumes->$volume->title ); - break; - case 'last': - $link = $collection->$series->volumes->$volume->last->link; - $title = sprintf( __( 'Go to the end of %s', 'webcomic' ), $collection->$series->volumes->$volume->title ); - break; - default: - $link = $collection->$series->volumes->$volume->first->link; - $title = sprintf( __( 'Go to the beginning of %s', 'webcomic'), $collection->$series->volumes->$volume->title ); - } - - $output .= '
      1. ' . $collection->$series->volumes->$volume->title . $pages . '' . $description . '
          '; - - foreach ( array_keys( get_object_vars( $collection->$series->volumes->$volume->chapters ) ) as $chapter ) { - $description = ( $args[ 'descriptions' ] && $collection->$series->volumes->$volume->chapters->$chapter->description ) ? '

          ' . $collection->$series->volumes->$volume->chapters->$chapter->description . '

          ' : ''; - $pages = ( $args[ 'pages' ] ) ? ' (' . $collection->$series->volumes->$volume->chapters->$chapter->count . ')' : ''; - - if ( 'number' == $args[ 'format' ] ) - $num = ( 'ASC' == $args[ 'post_order' ] ) ? 1 : count( get_object_vars( $collection->$series->volumes->$volume->chapters->$chapter->posts ) ); - - switch( $args[ 'bound' ] ) { - case 'page': - $link = $collection->$series->volumes->$volume->chapters->$chapter->link; - $title = sprintf( __( 'Go to the %s archive', 'webcomic' ), $collection->$series->volumes->$volume->chapters->$chapter->title ); - break; - case 'last': - $link = $collection->$series->volumes->$volume->chapters->$chapter->last->link; - $title = sprintf( __( 'Go to the end of %s', 'webcomic' ), $collection->$series->volumes->$volume->chapters->$chapter->title ); - break; - default: - $link = $collection->$series->volumes->$volume->chapters->$chapter->first->link; - $title = sprintf( __( 'Go to the beginning of %s', 'webcomic'), $collection->$series->volumes->$volume->chapters->$chapter->title ); - } - - $output .= '
        1. ' . $collection->$series->volumes->$volume->chapters->$chapter->title . $pages . '' . $description . '
            '; - - foreach ( array_keys( get_object_vars( $collection->$series->volumes->$volume->chapters->$chapter->posts ) ) as $post ) { - if ( 'number' == $args[ 'format' ] ) { - $link = $num; - } elseif ( $args[ 'format' ] ) { - $link = get_comic_object( $collection->$series->volumes->$volume->chapters->$chapter->posts->$post, $args[ 'format' ] ); - - if ( $collection->$series->volumes->$volume->chapters->$chapter->posts->$post->flash ) { - $object = $link; - $link = $collection->$series->volumes->$volume->chapters->$chapter->posts->$post->title; - } - } else { - $link = $collection->$series->volumes->$volume->chapters->$chapter->posts->$post->title; - } - - $output .= '
          1. ' . $object . '' . $link . '
          2. '; - - if ( 'number' == $args[ 'format' ] ) - $num = ( 'ASC' == $args[ 'post_order' ] ) ? $num + 1 : $num - 1; - } - - $output .= '
        2. '; - } - - $output .= '
      2. '; - } - - if ( 1 < count( $colleciton ) ) - $output .= '
    2. '; - } - - $output .= '
    '; - } - - unset( $collection ); - } - - echo $output; -} -?> \ No newline at end of file diff --git a/includes/wc-widgets.php b/includes/wc-widgets.php deleted file mode 100644 index d2204af..0000000 --- a/includes/wc-widgets.php +++ /dev/null @@ -1,632 +0,0 @@ - __( 'Displays comic bookmark links that allow readers to save their place and return later', 'webcomic' ) ); - $this->WP_Widget( 'bookmark-comic', __( 'Bookmark Comic', 'webcomic' ), $widget_ops ); - } - - //display - function widget( $args, $instance ) { - echo $before_widget; - bookmark_comic(); - echo $after_widget; - } -} - -/** - * Initializes, manages, and displays the Comic Buffer widget. - * - * @package @ebComic - * @since 2.1.0 - * - * @uses the_comic_buffer() - */ -class WP_Widget_Comic_Buffer extends WP_Widget { - //constructor - function WP_Widget_Comic_Buffer() { - $widget_ops = array( 'description' => __( 'Displays buffer comic information', 'webcomic' ) ); - $this->WP_Widget( 'comic-buffer', __( 'Comic Buffer', 'webcomic' ), $widget_ops ); - } - - //display - function widget( $args, $instance ) { - extract( $args ); - - echo $before_widget; - if ( !empty( $instance[ 'title' ] ) ) echo $before_title . $instance[ 'title' ] . $after_title; - the_comic_buffer( $instance[ 'type' ], $instance[ 'series' ] ); - echo $after_widget; - } - - //update - function update( $new, $old ) { - if ( !isset( $new[ 'submit' ] ) ) - return; - - $instance = $old; - $instance[ 'title' ] = strip_tags( stripslashes( $new[ 'title' ] ) ); - $instance[ 'type' ] = $new[ 'type' ]; - $instance[ 'series' ] = $new[ 'series' ]; - - return $instance; - } - - //form - function form( $instance ) { - load_webcomic_domain(); - - $instance = wp_parse_args( ( array ) $instance, array( 'title' => __( 'Buffer Comics', 'webcomic'), 'type' => 'count', 'series' => 0 ) ); - - $title = htmlspecialchars( $instance[ 'title' ], ENT_QUOTES ); - $type = $instance[ 'type' ]; - $series = $instance[ 'series' ]; - ?> -

    -

    - -

    -

    - -

    - - __( 'Displays a link to a single, randomly selected comic', 'webcomic' ) ); - $this->WP_Widget( 'random-comic', __( 'Random Comic', 'webcomic' ), $widget_ops ); - } - - //display - function widget( $args, $instance ) { - extract( $args ); - - echo $before_widget; - if ( !empty( $instance[ 'title' ] ) ) echo $before_title . $instance[ 'title' ] . $after_title; - random_comic_link( $instance[ 'label' ], $instance[ 'limit' ] ); - echo $after_widget; - } - - //update - function update( $new, $old ) { - if ( !isset( $new[ 'submit' ] ) ) - return; - - $instance = $old; - $instance[ 'title' ] = strip_tags( stripslashes( $new[ 'title' ] ) ); - $instance[ 'label' ] = $new[ 'label' ]; - $instance[ 'limit' ] = $new[ 'limit' ]; - - return $instance; - } - - //form - function form( $instance ) { - load_webcomic_domain(); - - $instance = wp_parse_args( ( array ) $instance, array( 'title' => __( 'Random Comic', 'webcomic'), 'label' => '', 'limit' => 0 ) ); - - $title = htmlspecialchars( $instance[ 'title' ], ENT_QUOTES ); - $label = $instance[ 'label' ]; - $limit = $instance[ 'limit' ]; - ?> -

    -

    - -

    -

    - -

    - - __( 'Displays a list of recently posted comics', 'webcomic' ) ); - $this->WP_Widget( 'recent-comics', __( 'Recent Comics', 'webcomic' ), $widget_ops ); - } - - //display - function widget( $args, $instance ) { - extract( $args ); - - echo $before_widget; - if ( !empty( $instance[ 'title' ] ) ) echo $before_title . $instance[ 'title' ] . $after_title; - echo '
      '; - recent_comics( $instance[ 'number' ], $instance[ 'label' ], $instance[ 'limit' ] ); - echo '
    ' . $after_widget; - } - - //update - function update( $new, $old ) { - if ( !isset( $new[ 'submit' ] ) ) - return; - - $instance = $old; - $instance[ 'title' ] = strip_tags( stripslashes( $new[ 'title' ] ) ); - $instance[ 'number' ] = ( int ) $new[ 'number' ]; - $instance[ 'label' ] = $new[ 'label' ]; - $instance[ 'limit' ] = $new[ 'limit' ]; - - return $instance; - } - - //form - function form( $instance ) { - load_webcomic_domain(); - - $instance = wp_parse_args( ( array ) $instance, array( 'title' => __( 'Recent Comics', 'webcomic' ), 'number' => 5, 'label' => '', 'limit' => 0 ) ); - - $title = htmlspecialchars( $instance[ 'title' ], ENT_QUOTES ); - $number = $instance[ 'number' ]; - $label = $instance[ 'label' ]; - $limit = $instance[ 'limit' ]; - ?> -

    -

    -

    - -

    -

    - -

    - - __( 'Displays a dropdown list of comic posts', 'webcomic' ) ); - $this->WP_Widget( 'dropdown-comics', __( 'Dropdown Comics', 'webcomic' ), $widget_ops ); - } - - //display - function widget( $args, $instance ) { - load_webcomic_domain(); - - extract( $args ); - - $args = ( $instance[ 'label' ] ) ? 'label=' . $instance[ 'label' ] : 'label=' . __( 'Quick Archive', 'webcomic' ); - $args .= ( $instance[ 'post_order' ] ) ? '&post_order=ASC' : ''; - $args .= '&number=' . $instance[ 'number' ]; - $args .= '&series=' . $instance[ 'series' ]; - $args .= '&groupby=' . $instance[ 'groupby' ]; - $args .= '&orderby=' . $instance[ 'orderby' ]; - $args .= ( $instance[ 'order' ] ) ? '&order=DESC' : ''; - $args .= '&bound=' . $instance[ 'bound' ]; - $args .= '&pages=' . $instance[ 'pages' ]; - - echo $before_widget; - if ( !empty( $instance[ 'title' ] ) ) echo $before_title . $instance[ 'title' ] . $after_title; - dropdown_comics( $args ); - echo $after_widget; - } - - //update - function update( $new, $old ) { - if ( !isset( $new[ 'submit' ] ) ) - return; - - $instance = $old; - $instance[ 'title' ] = strip_tags( stripslashes( $new[ 'title' ] ) ); - $instance[ 'label' ] = strip_tags( stripslashes ($new[ 'label' ] ) ); - $instance[ 'post_order' ] = $new[ 'post_order' ]; - $instance[ 'number' ] = $new[ 'number' ]; - $instance[ 'series' ] = $new[ 'series' ]; - $instance[ 'groupby' ] = $new[ 'groupby' ]; - $instance[ 'orderby' ] = $new[ 'orderby' ]; - $instance[ 'bound' ] = $new[ 'bound' ]; - $instance[ 'order' ] = $new[ 'order' ]; - $instance[ 'pages' ] = $new[ 'pages' ]; - - return $instance; - } - - //form - function form( $instance ) { - load_webcomic_domain(); - - $instance = wp_parse_args( ( array ) $instance, array( 'title' => __( 'Dropdown Comics', 'webcomic'), 'label' => __( 'Quick Archive', 'webcomic' ) ) ); - - $title = htmlspecialchars( $instance[ 'title' ], ENT_QUOTES ); - $label = $instance[ 'label' ]; - $post_order = $instance[ 'post_order' ]; - $number = $instance[ 'number' ]; - $series = $instance[ 'series' ]; - $groupby = $instance[ 'groupby' ]; - $orderby = $instance[ 'orderby' ]; - $order = $instance[ 'order' ]; - $bound = $instance[ 'bound' ]; - $pages = $instance[ 'pages' ]; - ?> -

    -

    -

    - -

    -

    - -

    -

    - -

    -

    - -

    -

    -

    -

    -

    - - __( 'Displays an archive of your comics', 'webcomic' ) ); - $this->WP_Widget( 'comic-archive', __( 'Comic Archive', 'webcomic' ), $widget_ops ); - } - - //display - function widget( $args, $instance ) { - extract( $args ); - - $args = 'groupby=' . $instance[ 'groupby' ]; - $args .= '&format=' . $instance[ 'format' ]; - $args .= ( $instance[ 'post_order' ] ) ? '&post_order=ASC' : ''; - $args .= '&series=' . $instance[ 'series' ]; - $args .= '&orderby=' . $instance[ 'orderby' ]; - $args .= ( $instance[ 'order' ] ) ? '&order=DESC' : ''; - $args .= '&bound=' . $instance[ 'bound' ]; - $args .= '&descriptions=' . $instance[ 'descriptions' ]; - $args .= '&pages=' . $instance[ 'pages' ]; - - echo $before_widget; - if ( !empty( $instance[ 'title' ] ) ) echo $before_title . $instance[ 'title' ] . $after_title; - comic_archive( $args ); - echo $after_widget; - } - - //update - function update( $new, $old ) { - if ( !isset( $new[ 'submit' ] ) ) - return; - - $instance = $old; - $instance[ 'title' ] = strip_tags( stripslashes( $new[ 'title' ] ) ); - $instance[ 'groupby' ] = $new[ 'groupby' ]; - $instance[ 'format' ] = $new[ 'format' ]; - $instance[ 'post_order' ] = $new[ 'post_order' ]; - $instance[ 'series' ] = $new[ 'series' ]; - $instance[ 'orderby' ] = $new[ 'orderby' ]; - $instance[ 'order' ] = $new[ 'order' ]; - $instance[ 'bound' ] = $new[ 'bound' ]; - $instance[ 'descriptions' ] = $new[ 'descriptions' ]; - $instance[ 'pages' ] = $new[ 'pages' ]; - - return $instance; - } - - //form - function form( $instance ) { - load_webcomic_domain(); - - $instance = wp_parse_args( ( array ) $instance, array( 'title' => __( 'Comic Archive', 'webcomic') ) ); - - $title = htmlspecialchars( $instance[ 'title' ], ENT_QUOTES ); - $groupby = $instance[ 'groupby' ]; - $format = $instance[ 'format' ]; - $post_order = $instance[ 'post_order' ]; - $series = $instance[ 'series' ]; - $orderby = $instance[ 'orderby' ]; - $order = $instance[ 'order' ]; - $bound = $instance[ 'bound' ]; - $descriptions = $instance[ 'descriptions' ]; - $pages = $instance[ 'pages' ]; - ?> -

    -

    - -

    -

    - -

    -

    - -

    -

    - -

    -

    - -

    -

    -

    -

    -

    - - __( 'The most recent posts on your blog (ignores comic posts)', 'webcomic' ) ); - $this->WP_Widget( 'recent-posts', __( 'Recent Posts', 'webcomic' ), $widget_ops ); - } - - //display - function widget( $args, $instance ) { - extract( $args ); - - $posts = ignore_comics( $instance[ 'number' ] ); - - echo $before_widget; - if ( !empty( $instance[ 'title' ] ) ) echo $before_title . $instance[ 'title' ] . $after_title; - if ( $posts->have_posts() ) : - echo ''; - endif; - echo $after_widget; - } - - //update - function update( $new, $old ) { - if ( !isset( $new[ 'submit' ] ) ) - return; - - $instance = $old; - $instance[ 'title' ] = strip_tags( stripslashes( $new[ 'title' ] ) ); - $instance[ 'number' ] = ( int ) $new[ 'number' ]; - - return $instance; - } - - //form - function form( $instance ) { - load_webcomic_domain(); - - $instance = wp_parse_args( ( array ) $instance, array( 'title' => __( 'Recent Posts', 'webcomic'), 'number' => 5 ) ); - - $title = $instance[ 'title' ]; - $number = $instance[ 'number' ]; - ?> -

    -

    - - \ No newline at end of file diff --git a/includes/webcomic-small.png b/includes/webcomic-small.png deleted file mode 100644 index 0b3044f..0000000 Binary files a/includes/webcomic-small.png and /dev/null differ diff --git a/includes/webcomic.png b/includes/webcomic.png deleted file mode 100644 index 12e2f14..0000000 Binary files a/includes/webcomic.png and /dev/null differ diff --git a/readme.txt b/readme.txt index 2db8d68..9faa56d 100644 --- a/readme.txt +++ b/readme.txt @@ -1,278 +1,43 @@ === Webcomic === Contributors: mgsisk -Donate link: http://maikeruon.com/webcomic/ -Tags: webcomic, comic, multiple comics, inkblot, archimedes, hydrogen, silkscreen, storylines, chapters, library, management, themes, posts, publish -Requires at least: 2.8 -Tested up to: 2.8.4 -Stable tag: 2.1.1 +Donate link: http://webcomicms.net/ +Tags: webcomic, comic, multiple comics, storylines, chapters, library, management, themes, posts, publish, custom post type, custom taxonomy, template tags, widgets +Requires at least: 3.0 +Tested up to: 3.0 +Stable tag: 3 -Webcomic adds a collection of new features to WordPress designed specifically for publishing webcomics. +Comic publishing power for WordPress. == Description == -Webcomic adds a collection of new features to WordPress designed specifically for publishing webcomics, developing webcomic themes, and managing webcomic sites. +Please see the [official Webcomic site](http://webcomicms.net/) for the users manual, video tutorials, support forum, bug reports, andfeature requests. -**Inkblot Users** - Remember to download the most recent version of Inkblot from the new [Google Code site](http://code.google.com/p/webcomic/downloads/list) and update your theme files before installing Webcomic 2.1 += Upgrading? = -= 2.1.1 Updates = +**Back up everything.** WordPress has a really handy export tool you can use to backup your data that we highly suggest you use before you attempt to upgrade. You should also take note of the order of your chapters and anything else you'd really, really hate to lose, and watch this video: -- Fixed "arrar" error -- Fixed "This is a comic category" message showing up for non-comic categories on the Edit Category page. -- *New* Thanks to improvements in WordPress core and the removal of some now-unnecessary validations Chapter names no longer have to be unique across all series. You can now have chapters and volumes with the same names in the same series or different series. +[vimeo http://vimeo.com/12500716] -= New in 2.1 = +Webcomic adds a number of features related to creating, managing, and sharing webcomics. Key features include: -- **Buffer Comics:** New template tags and widgets allow you to display buffer comic information for each of your comic series. Enable Buffer Alerts and Webcomic will send an e-mail to you before any buffers run out, reminding you to get back to work. -- **Transcript Backups:** Expanding on Webcomics already robust integrated transcription system are transcript backups. Whenever an "improved" transcript is submitted the previous version is saved and can be easily restored if the new transcript is anything but improved. -- **Orphan Files:** Orphan files have received a complete overhaul. Delete, rename, or generate posts individually or en masse using the new Bulk Actions dropdown, view orphans in a more functional thumbnail grid, and easily assign an orphan file to a comic post using the new orphan file selector in the Webcomic metabox. -- **Screen Options:** Take advantage of new Library screen options to adjust the comic list columns and comics per page just like other WordPress list pages. -- **Widget Upgrades:** Besides a new Buffer Comic widget all Webcomic widgets have been upgraded to use the new WP_Widget class so that they can be used any number of times throughout the site. -- **Transparent Fallback:** Dates or slugs? It doesn't matter anymore; Webcomic now intelligently and transparently matches comic files with comic posts that aren't already linked to a comic file. -- **Much More:** For a complete overview of all the changes in Webcomic 2.1 please see the changelog. - -= Feature Highlights = - -- **Comic Publishing Power:** Stop hacking WordPress and start using it. Webcomic's simple configuration, library management, chapter organization and new template tags for WordPress themes give you the power to take control of your comic and your site to make it exactly what you want. -- **Multi-Comic Support:** One comic not enough? Webcomic can manage any number of webcomics on a single WordPress site; just select two or more Comic Categories and Webcomic takes care of the rest. And if that weren't enough, you can load entirely separate WordPress themes for different comic series. -- **Integrated Transcribing:** Say goodbye to [ohnorobot](http://ohnorobot.com/). Webcomic's fully-integrated transcription system provides automatic indexing of published transcripts for site searches, the ability to request improvement of transcripts from users, and allow users to submit new transcripts. -- **Chapter Organization:** Take control of your storylines. Webcomic's Chapter system utilizes the WordPress Taxonomy API to provide an entirely new, independent method of organizing comic posts that doesn't interfere with post categories and tags. Use all three to create infinitely complext storylines. -- **Library Management:** Config files? Dates in filenames? Not here. Webcomic provides a simple configuration page and robust but easy-to-use comic management right through WordPress. Name your comics whatever you want, automatically generate posts for orphaned comics, and more. -- **Internationalization Support:** The world is a big place, and Webcomic understands that. It might even speak your lanuage. If it doesn't, though, that's alright. Webcomic utilizes WordPress' I18n functions for localization, allowing it to be fully translated into a language near you. -- **Much More:** For a complete overview of all the features Webcomic provides please see the [documentation](http://code.google.com/p/webcomic/wiki/Requirements). +- **Integration:** Turn any WordPress theme into a Webcomic site with the flip of a switch. Webcomic 3's new integration option makes getting up and running easier than ever. +- **Management:** Manage webcomic posts, files, storylines, characters, print selling options, collection access, age restrictions, transcribing, buffers, and more. +- **Multiplicity:** Manage any number of collections on a single WordPress site or a network of sites. +- **Internationalization:** If Webcomic isn't already available in your language you can translate it into any language you speak using WordPress' own internationalization functions. +- **Extensibility:** Build your own Webcomic-powered WordPress themes using a collection of new template tags, or modify the way Webcomic works using action and filter hooks. == Installation == -1. Upload the `webcomic` directory to the `/wp-content/plugins/` directory -1. Activate the plugin through the 'Plugins' menu in WordPress -1. Start using Webcomic! - -To take full advantage of Webcomic, you'll need: - -- Some knowledge of creating WordPress themes and working with Template Tags, or -- A WordPress theme designed to use the new Template Tags Webcomic provides - -If building themes isn't your thing, check out [the official plugin website](http://maikeruon.com/webcomic/) for a collection of WordPress themes that are specifically designed to fully utilize Webcomic. - -== Frequently Asked Questions == - -= Where can I get help with this? = - -Please see [the Webcomic project page](http://code.google.com/p/webcomic/) at Google Code for complete documentation or the [Webcomic Google Group](http://groups.google.com/group/webcomic-discuss) for more direct assistance. - -= Wouldn't it be great if...? = - -All feature suggestions are taken seriously; Webcomic owes most of it's features to helpful users that have pointed out shortomings, suggested improvements, or hacked together features that eventually found their way into an official release. That doesn't mean *every* feature suggested will end up in Webcomic, but a suggestion never hurt. Feature suggestions can be posted on the [Google Group](http://groups.google.com/group/webcomic-discuss) or more formal enhancment issues can be filed at the [Google Code project page](http://code.google.com/p/webcomic/). - -= Can I use Webcomic for a comic/manga/graphic novel hosting site? = - -You can certainly try, but the Webcomic developer does not in any way endorse the illegal distrubution of licensed, published works and no support will be provided for such uses. - -== Screenshots == - -1. Settings -2. Library -3. Chapters -4. Metabox - -== Changelog == - -= 2.1 (July 17, 2009) = - -- Settings page updates: - - **New** Buffer Alert. When enabled, Webcomic will send an e-mail reminder the specified number of days prior to any comic buffer running out. - - **New** Keyboard Shortcuts. When enabled, users can quickly browser a comic series using the left and right arrow keys to see the previous or next comic. The key combinations shift+left, shift+right, and shift+down take users to the first, last, or a random comic in the series, respectively. - - A small donate link has been added next to the Webcomic version information. - - Slight reorganization for easier use. Save posts as drafts, Fallback Matching, and ComicPress Compatibility options have been removed. -- Library page updates: - - **New** Screen Options. Users can now toggle displaying the collection, comments, and date columns, as well as set the number of comics listed per page. - - **New** Grid View for Orphan Files. When Thumbnail view is selected orphaned files are now displayed in a more practical grid view. - - **New** Bulk Actions for Orphan Files. Delete, Rename, and Generate Post functions have been merged into a new Bulk Actions dropdown for orphan files. - - Post options now provide a Publish dropdown that allows you to save posts as drafts on a case-by-case basis. Date and time options are now hidden unless an appropriate publish option is selected. - - Slight reorganization for easier use. Author information has been merged into the Post column and replaced with a Comments column. -- Chapters page updates: - - "How to Use Chapters" instructions have been replaced with a link to the Chapters documentation. -- Metabox updates: - - **New** Orphan File Selector. The metabox now provides a list of orphan files that can be easily assigned to a comic post without any associated comic file. -- Core updates: - - **New** Embed Formats. A new 'format' parameter on the\_comic\_embed() allows you to specify whether embed code should be output in standard html or bbcode. - - **New** Navigation Bookends. A new 'bookend' parameter on the comic navigation template tags allows you to define a beginning and ending static page (or post) that users will be setnt to when the click first/previous on the first comic or next/last on the last comic. - - **New** Transcript Backups. Webcomic now saves a transcript backup when an "improved" transcript is submitted by a user that can be restored if the original transcript is preferred. - - **New** Template tags: get\_comic\_buffer, the\_comic\_buffer, the\_comic\_series. the\_comic\_embed has a new format option which allows you to specify HTML or BBCode output. The parameter order of the chapter navigation template tags has changed, and the shortcut nav functions now accept only a single $args parameter. get\_the\_comic() no longer returns false when a comic file can't be found, but the 'file' property is set to false. - - **New** Comic Buffer Widget. Allows you to display the total number of buffer comics for a particular series, or the date or date and time the buffer for a series will run out. - - **New** Widget Updates. All widgets have been updated to use the WP\_Widgets class, enabling multi-widget use on all Webcomic widgets. - - **New** CSS Filters. Webcomic now adds comic-specific CSS classes to both the body\_class and post\_class template tags. - - Webcomic now automatically performs Fallback Matching based on post dates, slugs, and custom fields as necessary. Custom date formats have been removed; the format is always YYYY-MM-DD unless an alternate format can be found from a previous version of Webcomic, ComicPress Manager, or stripShow. - - Internal 1.x to 2.0 upgrade functions have been removed. Users may still be able to upgrade directly from Webcomic 1.x to 2.1, though certain settings will be reset to their defaults. - - Contextual help links now point to the new documentation at Google Code. - - Various other feature enhancementsa nd bug fixes. -- Includes all point release updates: - - 2.0.1: Includes bug fix to address a Comic Archive widget bug that prevented comics from being organized by chapters. - - 2.0.1: Includes bug fix to address an array keys errror in wc-core.php. - - 2.0.2: Includes bug fixes for the Webcomic Add Post metabox which should address upload errors in 2.0.0 and 2.0.1 - - 2.0.3: Includes bug fixes that prevented random\_comic\_link() from functioning properly on certain pages - - 2.0.3: Includes fixes for the "Property name must be a string" error - - 2.0.4: Includes a fix that should address the Secure URL's broken image issue some useres experienced. - - 2.0.5: Includes minor fixes to the Library page related to automatic post generation and variable names. - - 2.0.6: Includes minor fixes for upload functions related to getting the correct filename in older versions of PHP. - - 2.0.7: Includes minor fixes to various Library and Core functions. - - 2.0.8: Includes a minor fix to the Library related to Fallback comics. - - 2.0.9: Includes a fix for the category.php error experienced by some users after upgrading to WordPress 2.8 - - 2.0.10: Includes "\" fix. - -= 2.0 (May 25, 2009) = - -- Completely rewritten for the 2.0 release to add new features, address bugs, and optimize performance. -- Settings page updates: - - Reorganized structure for easier configuration. - - Automatic post generation options have been removed. - - **New** Secure URL’s option. When enabled, the URL for comic images is obscured to hide both the name and location of comic files. - - **New** Post Drafting option. When enabled, Webcomic will save automatically generated posts as drafts instead of publishing them. - - **New** Transcript options. You can now enable or disable user-submitted transcripts, as well as require a name and e-mail address for user submitted transcripts. - - **New** Fallback Matching options. These options are actually the old method Webcomic used to match comic files with posts, remaining as a fallback option when a comic isn’t already linked to a post. A new ID option is available. - - **New** ComicPress Compatibility. A new option for ComicPress users testing Webcomic & InkBlot on their existing WordPress site that addresses incompatibilities between the directory structures of Webcomic 2 and ComicPress. Most users can permanently disable this option. -- Library page updates: - - Reorganized structure for easier use. - - Thumbnail view now works with the Orphan Comics list. - - The Publish On options are now always visible. - - Regenerate All Thumbnails has been removed. - - The Edit Comic page has been removed in favor of the Webcomic post metabox. - - **New** Fallback update option. The Library now recognizes comics being matched with a post using the Fallback Method and will update them for you. - - **New** Bulk Actions. This replaces the Update Collection dropdown and provides actions for regenerating thumbnails, deleting comics, posts, or comics and posts, and reassigning chapters for selected comics. - - **New** Orphan Post Generator options. The Orphan Post Generator has been completely reworked to handle almost any update schedule. - - **New** Single Post Generator. These options allow you to generate a post for only one orphaned comic instead of doing it en masse. -- Chapters page updates: - - Reorganized structure for easier use. - - The Using Chapters instructions have been updated. -- Core updates: - - Webcomic now always stores comics in subdirectories of the root comic directory, named after comic category slugs. - - Webcomic now links comic files to their associated post, eliminating the need to scan comic directories for comic files. The old matching methods remain as the Fallback Matching options. - - Numerous changes have been made to various Webcomic template tags to add new features, address bugs, and optimize performance. - - **New** Multi-Comic Themes. Webcomic can now load entirely new WordPress themes based on the current comic series a user is viewing. - - **New** Bookmark Comic widget. Allows users to save their place for a particular comic series. Supports multiple comics on the same site, using a unique ID to differentiate series to allow users to save one bookmark for each series running on your site. This widget uses the new bookmark\_comic() template tag - - **New** jQuery functions. Webcomic now includes the javascrpt necessary for certain functions–particularly dropdown\_comics()–to function properly. - - **New** WordPress MU fixes. Webcomic has been updated with numerous fixes and should now properly support WordPress MU. - - **New** Contextual Help. The contextual help menu on Webcomic pages now includes links to Webcomic documentation. - - **New** Code Breaker. All Webcomic powered sites can now enable a super secret feature by entering a special code on their website. - -= 1.9 (April 8, 2009) = - -- Includes a critical bug fix that caused Series to be set as their own parent when editing them from the Chapter’s page, resulting in numerous Chapter-related problems. -- Includes numerous fixes related to I18n functions (internationalization support) to correct strings that could not be correctly translated. -- random\_comic() has been deprecated and will be removed in the next release. Use random\_comic\_link() instead. -- Various minor bug fixes and feature enhancements. - -= 1.8 (March 19, 2009) = - -- Includes Multi-Comic support. Webcomic can now manage any number of webcomics on a single WordPress installation, each with it’s own Library and Chapter hierarchy. All Webcomic features and functions have been upgraded to fully support multiple webcomics. -- Includes User-Submittable Transcripts. Webcomic has a new option (transcript e-mail) that, when provided, allows users to submit individual comic transcripts to the e-mail address you provide. -- Includes Enhanced Chapter System. Chapters now take full advantage of the WordPress Taxonomy API, allowing for Chapter archive pages and chapter feeds. -- Includes Enhanced Template Tags. All core Webcomic template tags have been upgraded to enhance performance and enable multi-comic support. -- Includes Enhanced Navigation Options. Webcomic can now make comic images clickable next or previous comic links, limit first/back/next/last comic navigation to the current storyline (chapter or volume), and more. -- Includes new template tags: in\_comic\_category(), get\_post\_comic\_category(), get\_post\_chapters(), single\_chapter\_title(), chapter\_description(), chapters\_nav\_link(), first\_chapter\_link(), previous\_chapter\_link(), next\_chapter\_link(), last\_chapter\_link(), the\_chapter\_link() (replases the\_chapter() and the\_volume()). - -= 1.7 (February 6, 2009) = - -- Includes the Edit Comic option. You can now rename comics that are already associated with a post from the Library, as well as get a quick overview of what files comprise a single comic (the master file and any related thumbnail images). -- All core functions have been rewritten to improve performance and add new features. Please check the Webcomic Codex for fully updated documentation. - - get\_the\_comic() now returns an array of comic related information instead of specifically formatted output (similar to get\_the\_chapter()). - - get\_the\_chapter() can now provide both chapter and volume information (get\_the\_volume() has been removed; use get\_the\_chapter(’volume’) instead). - - get\_the\_collection() now accepts an array argument which takes any key/value pairs that the WordPress function get\_terms() will accept (see wp-includes/taxonomy.php). -- Includes new template tags get\_comic\_image(), the\_current\_chapter(), and the\_current\_volume(). -- All plugin files now include inline documentation. -- Additional bug fixes and feature enhancements. - -= 1.6 (January 7, 2009) = - -- Includes Meta Box. Webcomic now adds a new meta box to the add/edit post pages, which allows you to upload a comic directly from the add/edit post page and add custom descriptions, transcripts, and filenames more easily. Many thanks to Andrew Naylor for inspiring this addition with his original modifications. -- Inclueds new permission scheme. Webcomic permissions have been updated to check for specific user capabilities instead of limiting all plugin access to site administrators. WordPress Author’s now have access to a limited Comic Library and WordPress Editor’s now have access to the full Comic Library and Comic Chapters. -- Includes enhanced comic library. The Comic Library now offers the option to regenerate individual comic thumbnails, delete comic posts, and now compares filenames during upload to prevent accidental overwrites (with a new option to force overwriting an existing file). -- Includes enhanced auto post. Automatic post creation is now compatible with all file name options. When enabled, new options to set (or override for the “Date” naming option) the publish datetime for the generated comic post are available. -- Includes enhanced orphan post generation. Orphaned post generation is now compatible with all file name options. New options to set (or override for the “Date” naming option) the publish datetime and interval (”Post every week starting January 1, 2009?, for example) for the generated comic posts are now available. -- Includes internationalization support. Webcomic now makes full use of WordPress’s I18n features to allow for localization. -- The library view option is now set per-user instead of globally. If you’re using the thumbnail view when you upgrade your view will initially be reset to the list view. -- Corrected a flaw in the search functions that prevented transcripts and custom descriptions from being found when searching for more than one term. -- Additional minor bug fixes and feature enhancements - -= 1.5 (December 30, 2008) = - -- Added Search Integration. Comic transcripts and custom descriptions are now seamlessly integrated into the WordPress search function and will be included in searches. -- Added custom column to the Media Library. This will display the custom field value of comic\_filename (if custom filenames are being used). -- Minor bug fixes and feature enhancements. - -= 1.4 (December 24, 2008) = - -- Added Thumbnail Options. Webcomic now has an independent set of media options for generating comic thumbnails. -- Added Feed Options. You can now select the size of the comic image that appears in site feeds. -- Includes new template tag: get\_the\_collection. -- Most of the code base has been rewritten to improve performance, add features, and fix bugs. - -= 1.3 (December 21, 2008) = - -- Corrected secure filenames bug that prevented thumbnails from being retrieved. -- Corrected comic\_archive() and dropdown\_comics() bug that displayed post revisions, autosaves, etc. -- Added code to correctly set the total page count for Volumes. - -= 1.2 (December 19, 2008) = - -- Includes Automatic Post Creation. When enabled, Webcomic will attempt to create a new comic post during upload. This option is only available when using the Date name format, and comics must only have date information in their filename. -- Added Generate Missing Posts option to the Library page. Webcomic will attempt to create comic posts for orphaned comics when activated. This option is only available when using the Date name format, and comics must only have date information in their filename. -- Added a validation check to custom date names. Webcomic now checks to make sure you have (at least) a year, month, and day or week PHP date string identifier and resets to the default date format if one or more of these is missing. -- Rewrote most of the Webcomic functions to add features and improve performance. -- Includes new template tags: get\_the\_chapter and get\_the\_volume. - -= 1.1 (December 11, 2008) = - -- Includes Secure option for filenames. When enabled, Webcomic appends a secure hash to comic filenames during upload to prevent read-ahead and archive scraping. -- Corrected the Markdown plugin error that prevented WordPress from automatically activating Webcomic. - -= 1.0 (December 4, 2008) = - -- Initial stable, feature-complete public release. -- Includes Settings page: - - Set the comic category. - - Define the comic directory. The comic directory and the thumbs subdirectory (for storying comic thumbnails generated by Webcomic) are automatically created if they do not exist. - - Set the current chapter. If set, new comic posts will be automatically assigned to the current chapter. - - Add or remove comic images from site feeds. - - Select Date, Title, or Custom name formats for comic filenames. -- Includes Library page: - - See all comics with related post information. - - Easily see which posts don’t have a comic and which comics don’t have a post. - - Upload, rename, and delete comics. Webcomic will automatically generate comic thumbnails based your WordPress media settings - - Regenerate all comic thumbnails if your media settings change. - - Quickly assign multiple comics to volumes and chapters. - - Choose between list or thumbnail view. -- Includes Chapters page: - - Create, modify, and delete volunmes and chapters to organize your comic library. - - Add unique titles and descriptions volumes and chapters. - - See a total page count for volumes and a running page count for chapters. -- Includes new template tags for WordPress themes: comics\_nav\_link, comic\_archive, comic\_loop, dropdown\_comics, first\_comic\_link, get\_the\_comic, ignore\_comics, last\_comic\_link, next\_comic\_link, previous\_comic\_link, random\_comic, recent\_comics, the\_chapter, the\_comic, the\_comic\_embed, the\_comic\_transcript, and the\_volume. -- Includes new widgets for WordPress themes: Random Comic, Recent Comics, Dropdown Comics, Comic Archive, and Recent Posts (modified to ignore comic posts). - -== Additional Requirements == - -Webcomic requires PHP 5. +Once you've confirmed with your web host that you're working with PHP 5 and have the latest version of WordPress up and running you can install Webcomic from the *Install Plugins* page. Just do a search for "webcomic" and the first result should be the one you're looking for. -== Special Thanks == += Manual Installation = -To everyone that's given Webcomic a chance. I'd especially like to thank the following donors: +If you can't use the *Install Plugins* page for whatever reason, follow these steps to manually install Webcomic: -- shassinger -- greyliliy -- fesworks -- parasite publishing -- duncebot -- bloop -- senshuu -- nbumpercar -- lordmitz -- connected concepts +1. Download and extract Webcomic from the [WordPress plugin directory](http://wordpress.org/extend/plugins/webcomic). +2. Upload the `webcomic` directory to the `/wp-content/plugins` directory. To install Webcomic as a special multisite plugin upload the contents of the `webcomic` directory to the `/wp-content/mu-plugins` directory. +3. Activate the plugin through the *Manage Plugins* page in WordPress (not required if you've installed Webcomic in the `wp-content/mu-plugins` directory). -And the Webcomic & InkBlot 2 beta testers: += Using Webcomic = -- greyliliy -- ravenswood -- autodmc -- gemnoc -- kez -- senshuu -- mirz \ No newline at end of file +Webcomic's *Integrate* feature allows it to be used with any WordPress theme right out of the box, but to get the most out of Webcomic you may want to check out one of the [official Webcomic themes](http://webcomicms.net/support/manual/themes) or build your own theme using Webcomic's extensive selection of widgets, template tags, actions, and filters. \ No newline at end of file diff --git a/webcomic-includes/admin-walker.php b/webcomic-includes/admin-walker.php new file mode 100644 index 0000000..a114696 --- /dev/null +++ b/webcomic-includes/admin-walker.php @@ -0,0 +1,282 @@ + 'post_parent', 'id' => 'ID' ); + + function start_el( &$output, $obj, $depth, $args ) { + global $current_user, $webcomic; + static $i = 0; + + $webcomic->domain(); + + $post = get_post( $obj->ID ); + $files = $webcomic->retrieve( $post->ID, 'post', $args[ 'src' ], true ); + $alt = ( !( $i % 2 ) ) ? ' class="alt"' : ''; + $thide = ( in_array( 'thumbnails', $args[ 'hidden' ] ) ) ? ' style="display:none"' : ''; + $phide = ( in_array( 'post', $args[ 'hidden' ] ) ) ? ' style="display:none"' : ''; + $shide = ( in_array( 'storylines', $args[ 'hidden' ] ) ) ? ' style="display:none"' : ''; + $chide = ( in_array( 'characters', $args[ 'hidden' ] ) ) ? ' style="display:none"' : ''; + $mhide = ( in_array( 'comments', $args[ 'hidden' ] ) ) ? ' style="display:none"' : ''; + $dhide = ( in_array( 'date', $args[ 'hidden' ] ) ) ? ' style="display:none"' : ''; + $flist = $img = ''; + + if ( !empty( $files ) ) { + $post_meta = current( get_post_meta( $post->ID, 'webcomic' ) ); + $wc = current( wp_get_object_terms( $post->ID, 'webcomic_collection' ) ); + + foreach ( $files[ 'full' ] as $k => $v ) { + $faction = ''; + + if ( !empty( $files[ 'small' ][ $k ] ) ) + $file = $files[ 'small' ][ $k ]; + elseif ( !empty( $files[ 'medium' ][ $k ] ) ) + $file = $files[ 'medium' ][ $k ]; + elseif ( !empty( $files[ 'large' ][ $k ] ) ) + $file = $files[ 'large' ][ $k ]; + else + $file = $v; + + $reg = ( in_array( $files[ 'full' ][ $k ][ 'mime' ], array( 'image/jpeg', 'image/gif', 'image/png' ) ) ) ? '| ' . __( 'Regenerate Thumbnails', 'webcomic' ) . ' | ' : ''; + $bind = ( empty( $post_meta[ 'files' ] ) ) ? '' . __( 'Bind', 'webcomic' ) . ' | ' : '' . __( 'Unbind', 'webcomic' ) . ' | '; + $faction = ( current_user_can( 'edit_others_posts' ) || $current_user->ID == $post->post_author ) ? '' . __( 'Edit', 'webcomic' ) . '' . $reg . $bind . '' . __( 'Delete', 'webcomic' ) . ' | ' . __( 'View', 'webcomic' ) . '' : '' . __( 'View', 'webcomic' ) . ''; + $flist .= '' . $files[ 'full' ][ $k ][ 'filename' ] . '
    ' . $files[ 'full' ][ $k ][ 'mime' ] . '

    ' . $faction . '

    '; + $img .= ( 'application/x-shockwave-flash' == $file[ 'mime' ] ) ? '

    ' . $file[ 'full' ][ $k ][ 'filename' ] . '


    ' : '' . $files[ 'full' ][ $k ][ 'basename' ] . '
    '; + } + } + + $title = ( 'trash' != $post->post_status && ( current_user_can( 'edit_others_posts' ) || $current_user->ID == $post->post_author ) ) ? '' . $post->post_title . '' : '' . $post->post_title . ''; + $author = get_userdata( $post->post_author ); + $state = $cterms = $sterms = array(); + $cbox = ( current_user_can( 'edit_others_posts' ) || $current_user->ID == $post->post_author ) ? '' : ''; + + if ( 'trash' == $post->post_status ) + $paction = ( current_user_can( 'delete_others_posts' ) || $current_user->ID == $post->post_author ) ? '' . __( 'Restore', 'webcomic' ) . ' | ' . __( 'Delete Permanently', 'webcomic' ) . '' : ''; + else + $paction = ( current_user_can( 'edit_others_posts' ) || $current_user->ID == $post->post_author ) ? '' . __( 'Edit', 'webcomic' ) . ' | ' . __( 'Trash', 'webcomic' ) . ' | ' . __( 'View', 'webcomic' ) . '' : '' . __( 'View', 'webcomic' ) . ''; + + if ( !empty( $post->post_password ) ) + $state[] = __( 'Password Protected', 'webcomic' ); + elseif ( 'private' == $post->post_status ) + $state[] = __( 'Private', 'webcomic' ); + + if ( 'pending' == $post->post_status ) + $state[] = __( 'Pending', 'webcomic' ); + + if ( 'draft' == $post->post_status ) + $state[] = __( 'Draft', 'webcomic' ); + + if ( is_sticky( $post->ID ) ) + $state[] = __( 'Sticky', 'webcomic' ); + + $state = ( !empty( $state ) ) ? ' - ' . implode( ', ', $state ) . '' : ''; + + $storylines = wp_get_object_terms( $post->ID, 'webcomic_storyline' ); + + if ( !empty( $storylines ) && !is_wp_error( $storylines ) ) { + foreach ( $storylines as $storyline ) + $sterms[] = '' . $storyline->name . ''; + } else + $sterms = array( __( 'No Storylines', 'webcomic' ) ); + + $characters = wp_get_object_terms( $post->ID, 'webcomic_character' ); + + if ( !empty( $characters ) && !is_wp_error( $characters ) ) { + foreach ( $characters as $character ) + $cterms[] = '' . $character->name . ''; + } else + $cterms = array( __( 'No Characters', 'webcomic' ) ); + + if ( '0000-00-00 00:00:00' == $post->post_date ) + $t_time = $h_time = __( 'Unpublished', 'webcomic' ); + else { + $t_time = get_the_time( __( 'Y/m/d g:i:s A', 'webcomic' ), $post->ID ); + $m_time = $post->post_date; + $time = get_post_time( 'G', true, $post ); + $d_time = time() - $time; + + if ( ( 'future' == $post->post_status ) ) + $h_time = ( $d_time <= 0 ) ? sprintf( __( '%s from now', 'webcomic' ), human_time_diff( $time ) ) : $t_time; + elseif( $d_time > 0 && $d_time < 86400 ) + $h_time = sprintf( __( '%s ago', 'webcomic' ), human_time_diff( $time ) ); + else + $h_time = mysql2date( __( 'Y/m/d', 'webcomic' ), $m_time); + + $missed = ( $h_time == $t_time ) ? true : false; + } + + if ( 'publish' == $post->post_status ) + $status = __( 'Published', 'webcomic' ); + elseif ( 'future' == $post->post_status && $missed ) + $status = '' . __( 'Missed Schedule', 'webcomic' ) . ''; + elseif ( 'future' == $post->post_status ) + $status = __( 'Scheduled', 'webcomic' ); + else + $status = __( 'Last Modified', 'webcomic' ); + + $output .= ' + ' . $cbox . ' + ' . $img . ' + ' . $title . $state . '
    ' . $author->display_name . '

    ' . $paction . '

    + ' . $flist . ' + ' . implode( ', ', $sterms ) . ' + ' . implode( ', ', $cterms ) . ' + ' . $post->comment_count . ' + ' . $h_time . '
    ' . $status . ' + '; + + $i++; + } +} + +/** + * Returns the term list for a given collection. + * + * @package webcomic + * @since 3 + */ +class webcomic_Walker_AdminTermList extends Walker { + var $tree_type = 'webcomic_term'; + var $db_fields = array( 'parent' => 'parent', 'id' => 'term_id' ); + + function start_el( &$output, $term, $depth, $args ) { + global $webcomic; + + static $i = 0; + + $webcomic->domain(); + + $alt = ( !( $i % 2 ) ) ? ' class="alt"' : ''; + $chide = ( in_array( 'cover', $args[ 'hidden' ] ) ) ? ' style="display:none"' : ''; + $shide = ( in_array( 'slug', $args[ 'hidden' ] ) ) ? ' style="display:none"' : ''; + $hhide = ( in_array( 'characters', $args[ 'hidden' ] ) ) ? ';display:none' : ''; + $thide = ( in_array( 'storylines', $args[ 'hidden' ] ) ) ? ';display:none' : ''; + $phide = ( in_array( 'posts', $args[ 'hidden' ] ) ) ? ' style="display:none"' : ''; + $img = $default = $delete = ''; + + if ( $term->webcomic_default ) { + $style = ' style="background:#fffeeb"'; + $label = ( 'webcomic_collection' == $args[ 'page' ] ) ? __( 'Remove as Default', 'webcomic' ) : __( 'Remove from Defaults', 'webcomic' ); + $switch = 'off'; + } else { + $style = ''; + $label = ( 'webcomic_collection' == $args[ 'page' ] ) ? __( 'Set as Default', 'webcomic' ) : __( 'Add to Defaults', 'webcomic' ); + $switch = 'on'; + } + + if ( !empty( $term->webcomic_files ) ) { + if ( $term->webcomic_files[ 'small' ] ) + $file = $term->webcomic_files[ 'small' ]; + elseif ( $term->webcomic_files[ 'medium' ] ) + $file = $term->webcomic_files[ 'medium' ]; + elseif ( $term->webcomic_files[ 'large' ] ) + $file = $term->webcomic_files[ 'large' ]; + else + $file = $term->webcomic_files[ 'full' ]; + + foreach ( $file as $f ) + $img .= ( isset( $file[ 'mime' ] ) && 'application/x-shockwave-flash' == $file[ 'mime' ] ) ? '

    ' . $term->name . '


    ' : '' . $term->name . '
    '; + } + + $move = ( 'webcomic_storyline' == $args[ 'page' ] ) ? ' ' : ''; + $coll = ( 'webcomic_collection' != $args[ 'page' ] ) ? '&webcomic_collection=' . $term->term_group : ''; + $char = ( 'webcomic_collection' == $args[ 'page' ] ) ? '' . get_terms( 'webcomic_character', 'hide_empty=0&fields=count&term_group=' . $term->term_id ) . '' : ''; + $stor = ( 'webcomic_collection' == $args[ 'page' ] ) ? '' . get_terms( 'webcomic_storyline', 'hide_empty=0&fields=count&term_group=' . $term->term_id ) . '' : ''; + + if ( !( 'webcomic_collection' == $args[ 'page' ] && $term->webcomic_default ) ) { + $default = ' | ' . $label . ''; + $delete = ' | name ) ) . '\')){return true;}return false;">' . __( 'Delete', 'webcomic' ) . ''; + } + + $output .= ' + + ' . $img . ' + ' . str_repeat( '— ', $depth ) . $term->name . '
    ' . $move . '' . __( 'Edit', 'webcomic' ) . '' . $default . $delete . '
    + ' . $term->slug . '' . $char . $stor . ' + ' . $term->count . ' + '; + + $i++; + } +} + +/** + * Returns the dropdown term list for a given collection. + * + * @package webcomic + * @since 3 + */ +class webcomic_Walker_AdminTermDropdown extends Walker { + var $tree_type = 'webcomic_collection'; + var $db_fields = array( 'parent' => 'parent', 'id' => 'term_id' ); + + function start_el( &$output, $term, $depth, $args ) { + $output .= ''; + } +} + +/** + * Returns the dropdown parent term list for a given collection. + * + * @package webcomic + * @since 3 + */ +class webcomic_Walker_AdminTermParent extends Walker { + var $tree_type = 'webcomic_term'; + var $db_fields = array( 'parent' => 'parent', 'id' => 'term_id' ); + + function start_el( &$output, $term, $depth, $args ) { + $output .= ''; + } +} + +/** + * Returns term meta with normalized orders. + * + * @package webcomic + * @since 3 + */ +class webcomic_Walker_AdminTermNormalize extends Walker { + var $tree_type = 'webcomic_term'; + var $db_fields = array( 'parent' => 'parent', 'id' => 'term_id' ); + + function start_el( &$output, $term, $depth, $args ) { + global $webcomic; + + static $x = array(); + + if ( empty( $output ) ) + $output = $args[ 'term_meta' ]; + + if ( empty( $x[ $term->parent . '_' . $depth ] ) ) + $x[ $term->parent . '_' . $depth ] = 1; + + $output[ 'storyline' ][ $term->term_id ][ 'order' ] = $x[ $term->parent . '_' . $depth ]; + + $x[ $term->parent . '_' . $depth ]++; + } +} +?> \ No newline at end of file diff --git a/webcomic-includes/admin.php b/webcomic-includes/admin.php new file mode 100644 index 0000000..8ac5957 --- /dev/null +++ b/webcomic-includes/admin.php @@ -0,0 +1,4231 @@ +domain(); + + $e = array(); + $errors = sprintf( __( 'Step %d error:', 'webcomic' ), $step ); + $update = sprintf( __( 'Step %d complete!', 'webcomic' ), $step ); + + if ( 1 == $step ) { + if ( get_option( 'comic_transcripts_loggedin' ) ) + $transcribe_restrict = 'login'; + elseif ( get_option( 'comic_transcripts_required' ) ) + $transcribe_restrict = 'selfid'; + else + $transcribe_restrict = 'anyone'; + + if ( 'thumb' == get_option( 'comic_feed_size' ) ) + $feed_size = 'small'; + elseif ( get_option( 'comic_feed_size' ) ) + $feed_size = get_option( 'comic_feed_size' ); + else + $feed_size = $this->option( 'feed_size' ); + + $new = array(); + $new[ 'secure_toggle' ] = ( get_option( 'comic_secure_names' ) || get_option( 'comic_secure_paths' ) ) ? true : false; + $new[ 'transcribe_toggle' ] = ( get_option( 'comic_transcripts_allowed' ) ) ? true : false; + $new[ 'transcribe_restrict' ] = $transcribe_restrict; + $new[ 'feed_toggle' ] = ( get_option( 'comic_feed' ) ) ? true : false; + $new[ 'feed_size' ] = $feed_size; + $new[ 'buffer_toggle' ] = ( get_option( 'comic_buffer' ) ) ? true : false; + $new[ 'buffer_size' ] = intval( get_option( 'comic_buffer_alert' ) ); + $new[ 'shortcut_toggle' ] = ( get_option( 'comic_keyboard_shortcuts' ) ) ? true : false; + $new[ 'large_h' ] = intval( get_option( 'comic_large_size_h' ) ); + $new[ 'large_w' ] = intval( get_option( 'comic_large_size_w' ) ); + $new[ 'medium_h' ] = intval( get_option( 'comic_medium_size_h' ) ); + $new[ 'medium_w' ] = intval( get_option( 'comic_medium_size_h' ) ); + $new[ 'small_h' ] = intval( get_option( 'comic_thumb_size_h' ) ); + $new[ 'small_w' ] = intval( get_option( 'comic_thumb_size_w' ) ); + $new[ 'version' ] = $this->version; + $new[ 'default_collection' ] = $this->option( 'default_collection' ); + $new[ 'integrate_toggle' ] = $this->option( 'integrate_toggle' ); + $new[ 'transcribe_language' ] = $this->option( 'transcribe_language' ); + $new[ 'transcribe_default' ] = $this->option( 'transcribe_default' ); + $new[ 'age_toggle' ] = $this->option( 'age_toggle' ); + $new[ 'age_size' ] = $this->option( 'age_size' ); + $new[ 'paypal_business' ] = $this->option( 'paypal_business' ); + $new[ 'paypal_currency' ] = $this->option( 'paypal_currency' ); + $new[ 'paypal_log' ] = $this->option( 'paypal_log' ); + $new[ 'paypal_prints' ] = $this->option( 'paypal_prints' ); + $new[ 'paypal_method' ] = $this->option( 'paypal_method' ); + $new[ 'paypal_price_d' ] = $this->option( 'paypal_price_d' ); + $new[ 'paypal_price_i' ] = $this->option( 'paypal_price_i' ); + $new[ 'paypal_price_o' ] = $this->option( 'paypal_price_o' ); + $new[ 'paypal_shipping_d' ] = $this->option( 'paypal_shipping_d' ); + $new[ 'paypal_shipping_i' ] = $this->option( 'paypal_shipping_i' ); + $new[ 'paypal_shipping_o' ] = $this->option( 'paypal_shipping_o' ); + $new[ 'paypal_donation' ] = $this->option( 'paypal_donation' ); + $new[ 'term_meta' ] = $this->option( 'term_meta' ); + + $this->option( $new ); + + $this->update[ 'legacy_settings' ] = sprintf( __( '%s Settings have been transferred successfully.', 'webcomic' ), $update ); + } elseif ( 2 == $step ) { + global $wpdb; + + $i = 0; + $comic_cats = get_option( 'comic_category' ); + $cdir = get_option( 'comic_directory' ) . '/'; + $path = ( !defined( 'BLOGUPLOADDIR' ) ) ? ABSPATH : BLOGUPLOADDIR; + $lang = $this->option( 'transcribe_default' ); + $lkey = current( array_keys( $lang ) ); + $trans_toggle = ( $this->option( 'transcribe_toggle' ) ) ? true : false; + $paypal_toggle = ( $this->option( 'paypal_prints' ) ) ? true : false; + + foreach ( $comic_cats as $cat_id ) { + $cat = get_term( $cat_id, 'category' ); + + if ( $files = glob( $path . $cdir . $cat->slug . '/thumbs/*-thumb.*' ) ) + foreach ( $files as $file ) + rename( $file, substr_replace( $file, '-small.', strrpos( $file, '-thumb.' ), 7 ) ); + + if ( $posts = get_objects_in_term( $cat_id, 'category' ) ) { + $wpdb->query( "UPDATE $wpdb->posts SET post_type = 'webcomic_post' WHERE ID IN (" . implode( ',', $posts ) . ")" ); + + foreach ( $posts as $p ) { + if ( get_post_meta( $p, 'comic_transcript', true ) ) { + $status = 'publish'; + $text = get_post_meta( $p, 'comic_transcript', true ); + } elseif ( get_post_meta( $p, 'comic_transcript_pending', true ) ) { + $status = 'pending'; + $text = get_post_meta( $p, 'comic_transcript_pending', true ); + } elseif ( get_post_meta( $p, 'comic_transcript_draft', true ) ) { + $status = 'draft'; + $text = get_post_meta( $p, 'comic_transcript_draft', true ); + } + + if ( !( 'publish' == $status || 'pending' == $status ) && get_post_meta( $p, 'comic_transcript_backup', true ) ) + $backup = get_post_meta( $p, 'comic_transcript_backup', true ); + + $meta = array( + 'files' => array( 'full' => array( get_post_meta( $p, 'comic_file', true ) ), 'large' => array( get_post_meta( $p, 'comic_large', true ) ), 'medium' => array( get_post_meta( $p, 'comic_medium', true ) ), 'small' => array( str_replace( '-thumb.', '-small.', get_post_meta( $p, 'comic_thumb', true ) ) ) ), + 'alternate' => array(), + 'description' => array( get_post_meta( $p, 'comic_description', true ) ), + 'transcripts' => array( $lkey => array( 'language' => $lang[ $lkey ], 'status' => $status, 'text' => $text ) ), + 'transcribe_toggle' => $trans_toggle, + 'paypal' => array( 'prints' => $paypal_toggle ) + ); + + if ( $backup ) + $meta[ 'transcripts' ][ $lkey ][ 'backup' ] = $backup; + + if ( empty( $meta[ 'files' ][ 'full' ] ) ) + $meta[ 'files' ] = array(); + else { + if ( empty( $meta[ 'files' ][ 'large' ] ) ) + unset( $meta[ 'files' ][ 'large' ] ); + if ( empty( $meta[ 'files' ][ 'medium' ] ) ) + unset( $meta[ 'files' ][ 'medium' ] ); + if ( empty( $meta[ 'files' ][ 'small' ] ) ) + unset( $meta[ 'files' ][ 'small' ] ); + } + + update_post_meta( $p, 'webcomic', $meta ); + + unset( $status, $text, $backup ); + + $i++; + } + } + } + + if ( $i ) + $this->update[ 'legacy_posts' ] = sprintf( __( '%s "Comic posts" converted to webcomics successfully.', 'webcomic' ), $update ); + else + $this->errors[ 'no_legacy_posts' ] = sprintf( __( '%s No "comic posts" could be found.', 'webcomic' ), $error ); + } elseif ( 3 == $step ) { + $comic_cats = get_option( 'comic_category' ); + $terms = get_terms( 'chapter', 'get=all&orderby=' ); + $series = $volumes = $chapters = $collections = array(); + + if ( get_option( 'webcomic_temp_collections' ) ) + $collections = get_option( 'webcomic_temp_collections' ); + + if ( get_option( 'webcomic_temp_volumes' ) ) + $volumes = get_option( 'webcomic_temp_volumes' ); + + if ( get_option( 'webcomic_temp_chapters' ) ) + $chapters = get_option( 'webcomic_temp_chapters' ); + + foreach ( $terms as $term ) { + if ( !$term->parent ) + array_push( $series, $term ); + elseif ( in_array( $term->parent, $comic_cats ) ) + array_push( $volumes, $term ); + else + array_push( $chapters, $term ); + } + + update_option( 'webcomic_temp_volumes', $volumes ); + update_option( 'webcomic_temp_chapters', $chapters ); + + foreach ( $series as $k => $v ) { + $posts = get_objects_in_term( $v->term_id, 'category' ); + + if ( is_wp_error( $new = wp_insert_term( $v->name, 'webcomic_collection', array( 'slug' => $v->slug, 'description' => $v->description ) ) ) ) { + $e[] = $v; + continue; + } + + wp_delete_term( $v->term_id, 'chapter' ); + + if ( $posts ) + foreach ( $posts as $p ) + wp_set_object_terms( $p, ( int ) $new[ 'term_id' ], 'webcomic_collection', false ); + + $collections[ $v->term_id ] = $new[ 'term_id' ]; + } + + update_option( 'webcomic_temp_collections', $collections ); + + if ( $e ) { + $l = ''; + + foreach ( $e as $v ) + $l .= $v->name . '
    '; + + $this->errors[ 'legacy_chapters' ] = sprintf( __( "%s The following series' could not be converted to collections: $l", "webcomic" ), $errors ); + } else + $this->update[ 'legacy_chapters' ] = sprintf( __( "%s Series' converted to collections successfully.", "webcomic" ), $update ); + } elseif ( 4 == $step ) { + $volumes = get_option( 'webcomic_temp_volumes' ); + $collections = get_option( 'webcomic_temp_collections' ); + $parents = ( get_option( 'webcomic_temp_parents' ) ) ? get_option( 'webcomic_temp_parents' ) : array(); + + foreach ( $volumes as $k => $v ) { + if ( !$collections[ $v->parent ] ) + continue; + + $posts = get_objects_in_term( $v->term_id, 'chapter' ); + + $_REQUEST[ 'webcomic_collection' ] = $collections[ $v->parent ]; + $_REQUEST[ 'webcomic_parent' ] = 0; + + if ( is_wp_error( $new = wp_insert_term( $v->name, 'webcomic_storyline', array( 'slug' => $v->slug, 'description' => $v->description ) ) ) ) { + $e[] = $v; + continue; + } + + wp_delete_term( $v->term_id, 'chapter' ); + + if ( $posts ) + foreach ( $posts as $p ) + wp_set_object_terms( $p, ( int ) $new[ 'term_id' ], 'webcomic_storyline', true ); + + $collections[ $v->term_id ] = $collections[ $v->parent ]; + $parents[ $v->term_id ] = $new[ 'term_id' ]; + } + + update_option( 'webcomic_temp_collections', $collections ); + update_option( 'webcomic_temp_parents', $parents ); + + if ( $e ) { + $l = ''; + + foreach ( $e as $v ) + $l .= $v->name . '
    '; + + $this->errors[ 'legacy_chapters' ] = sprintf( __( "%s The following volumes could not be converted to storylines: $l", "webcomic" ), $errors ); + } else + $this->update[ 'legacy_chapters' ] = sprintf( __( '%s Volumes converted to storylines successfully.', 'webcomic' ), $update ); + } elseif ( 5 == $step ) { + $parents = get_option( 'webcomic_temp_parents' ); + $chapters = get_option( 'webcomic_temp_chapters' ); + $collections = get_option( 'webcomic_temp_collections' ); + + foreach ( $chapters as $k => $v ) { + if ( !$parents[ $v->parent ] || !$collections[ $v->parent ] ) + continue; + + $posts = get_objects_in_term( $v->term_id, 'chapter' ); + + $_REQUEST[ 'webcomic_collection' ] = $collections[ $v->parent ]; + $_REQUEST[ 'webcomic_parent' ] = $parents[ $v->parent ]; + + if ( is_wp_error( $new = wp_insert_term( $v->name, 'webcomic_storyline', array( 'slug' => $v->slug, 'parent' => $parents[ $v->parent ], 'description' => $v->description ) ) ) ) { + $e[] = $v; + continue; + } + + wp_delete_term( $v->term_id, 'chapter' ); + + if ( $posts ) + foreach ( $posts as $p ) + wp_set_object_terms( $p, ( int ) $new[ 'term_id' ], 'webcomic_storyline', true ); + } + + if ( $e ) { + $l = ''; + + foreach ( $e as $v ) + $l .= $v->name . '
    '; + + $this->errors[ 'legacy_chapters' ] = sprintf( __( "%s The following chapters could not be converted to storylines: $l", "webcomic" ), $errors ); + } else + $this->update[ 'legacy_chapters' ] = sprintf( __( '%s Chapters converted to storylines successfully.', 'webcomic' ), $update ); + } elseif ( 6 == $step ) { + global $wpdb; + + clean_term_cache( array(), array( 'webcomic_storyline' ) ); + + $term_meta = $this->option( 'term_meta' ); + + $w = new webcomic_Walker_AdminTermNormalize(); + + $term_meta = $w->walk( get_terms( 'webcomic_storyline', 'get=all' ), 0, array( 'term_meta' => $term_meta ) ); + + $this->option( 'term_meta', $term_meta ); + + $wpdb->query( "DELETE FROM $wpdb->postmeta WHERE meta_key IN ( 'comic_file', 'comic_large', 'comic_medium', 'comic_thumb', 'comic_description', 'comic_transcript', 'comic_transcript_pending', 'comic_transcript_draft', 'comic_transcript_backup' )" ); + + if ( $terms = get_terms( 'chapter', 'get=all' ) ) + foreach ( $terms as $term ) + wp_delete_term( $term->term_id, 'chapter' ); + + wp_clear_scheduled_hook( 'webcomic_buffer_alert' ); + + wp_schedule_event( time(), 'daily', 'webcomic_buffer_alert' ); + + delete_option( 'comic_category' ); + delete_option( 'comic_directory' ); + delete_option( 'comic_current_chapter' ); + delete_option( 'comic_secure_paths' ); + delete_option( 'comic_secure_names' ); + delete_option( 'comic_transcripts_allowed' ); + delete_option( 'comic_transcripts_required' ); + delete_option( 'comic_transcripts_loggedin' ); + delete_option( 'comic_feed' ); + delete_option( 'comic_feed_size' ); + delete_option( 'comic_buffer' ); + delete_option( 'comic_buffer_alert' ); + delete_option( 'comic_keyboard_shortcuts' ); + delete_option( 'comic_thumb_crop' ); + delete_option( 'comic_large_size_w' ); + delete_option( 'comic_large_size_h' ); + delete_option( 'comic_medium_size_w' ); + delete_option( 'comic_medium_size_h' ); + delete_option( 'comic_thumb_size_w' ); + delete_option( 'comic_thumb_size_h' ); + delete_option( 'webcomic_temp_volumes' ); + delete_option( 'webcomic_temp_chapters' ); + delete_option( 'webcomic_temp_collections' ); + delete_option( 'webcomic_temp_parents' ); + delete_option( 'webcomic_version' ); + + $this->update[ 'legacy_cleanup' ] = sprintf( __( "%s Congratulations, you're almost ready to roll.", "webcomic" ), $update ); + } else + return false; + } + + /** + * 'right_now_content_table_end' hook. + * + * @package webcomic + * @since 3 + */ + function hook_right_now_content_table_end() { + $np = wp_count_posts( 'webcomic_post' ); + $num = number_format_i18n( $np->publish ); + $text = _n( __( 'Webcomic', 'webcomic' ), __( 'Webcomics', 'webcomic' ), intval( $np->publish ) ); + + if ( current_user_can( 'upload_files' ) ) { + $num = "$num"; + $text = "$text"; + } + + echo '' . $num . '' . $text . ''; + } + + /** + * 'favorite_actions' hook. + * + * @package webcomic + * @since 3 + */ + function hook_favorite_actions( $actions ) { + global $post_type_object, $post; + + $this->domain(); + + foreach ( $actions as $k => $v ) + if ( false !== strpos( $k, 'webcomic_post' ) ) + unset( $actions[ $k ] ); + + $wc = ( !empty( $_REQUEST[ 'webcomic_collection' ] ) ) ? '&webcomic_collection=' . $_REQUEST[ 'webcomic_collection' ] : ''; + + if ( $post && !$wc && is_object_in_term( $post->ID, 'webcomic_collection' ) && $id = current( wp_get_object_terms( $post->ID, 'webcomic_collection', array( 'fields' => 'ids' ) ) ) ) + $wc = '&webcomic_collection=' . $id; + + $na = array(); + + if ( isset( $post_type_object ) && $wc ) + $na[ "admin.php?page=webcomic_files$wc" ] = array( __( 'Edit Webcomics', 'webcomic' ), 'upload_files' ); + + $na[ "post-new.php?post_type=webcomic_post$wc" ] = array( __( 'New Webcomic', 'webcomic' ), 'upload_files' ); + + $actions = $na + $actions; + + return $actions; + } + + /** + * 'admin_menu' hook. + * + * @package webcomic + * @since 3 + */ + function hook_admin_menu() { + $this->domain(); + + if ( !$this->option( 'uninstall' ) ) { + add_menu_page( __( 'Webcomic', 'webcomic' ), __( 'Webcomic', 'webcomic' ), 'upload_files', 'webcomic_files', array( &$this, 'admin_files' ), $this->url . 'webcomic-includes/icon-small.png', 3 ); + $pages[ 'webcomics' ] = add_submenu_page( 'webcomic_files', __( 'Webcomic Files', 'webcomic' ), __( 'Webcomics', 'webcomic' ), 'upload_files', 'webcomic_files', array( &$this, 'admin_files' ) ); + $pages[ 'storylines' ] = add_submenu_page( 'webcomic_files', __( 'Webcomic Storylines', 'webcomic' ), __( 'Storylines', 'webcomic' ), 'manage_categories', 'webcomic_storyline', array( &$this, 'admin_terms' ) ); + $pages[ 'characters' ] = add_submenu_page( 'webcomic_files', __( 'Webcomic Characters', 'webcomic' ), __( 'Characters', 'webcomic' ), 'manage_categories', 'webcomic_character', array( &$this, 'admin_terms' ) ); + $pages[ 'collections' ] = add_submenu_page( 'webcomic_files', __( 'Webcomic Collections', 'webcomic' ), __( 'Collections', 'webcomic' ), 'upload_files', 'webcomic_collection', array( &$this, 'admin_terms' ) ); + } else + add_menu_page( __( 'Webcomic', 'webcomic' ), __( 'Webcomic', 'webcomic' ), 'manage_options', 'webcomic_tools', array( &$this, 'admin_tools' ), $this->url . 'webcomic-includes/icon-small.png', 3 ); + + $pages[ 'tools' ] = add_submenu_page( 'webcomic_files', __( 'Webcomic Tools', 'webcomic' ), __( 'Tools', 'webcomic' ), 'manage_options', 'webcomic_tools', array( &$this, 'admin_tools' ) ); + + if ( !$this->option( 'uninstall' ) ) + $pages[ 'settings' ] = add_submenu_page( 'webcomic_files', __( 'Webcomic Settings', 'webcomic' ), __( 'Settings', 'webcomic' ), 'manage_options', 'webcomic_settings', array( &$this, 'admin_settings' ) ); + + if ( !$this->option( 'uninstall' ) ) { + if ( !empty( $pages[ 'webcomics' ] ) ) register_column_headers( $pages[ 'webcomics' ], array( 'thumbnails' => __( 'Thumbnails', 'webcomic' ), 'post' => __( 'Post', 'webcomic' ), 'name' => __( 'Files', 'webcomic' ), 'storylines' => __( 'Storylines', 'webcomic' ), 'characters' => __( 'Characters', 'webcomic' ), 'comments' => '
    Comments
    ', 'date' => __( 'Date', 'webcomic' ) ) ); + if ( !empty( $pages[ 'storylines' ] ) ) register_column_headers( $pages[ 'storylines' ], array( 'cover' => __( 'Cover', 'webcomic' ), 'name' => __( 'Name', 'webcomic' ), 'slug' => __( 'Slug', 'webcomic' ), 'posts' => __( 'Webcomics', 'webcomic' ) ) ); + if ( !empty( $pages[ 'characters' ] ) ) register_column_headers( $pages[ 'characters' ], array( 'cover' => __( 'Avatar', 'webcomic' ), 'name' => __( 'Name', 'webcomic' ), 'slug' => __( 'Slug', 'webcomic' ), 'posts' => __( 'Webcomics', 'webcomic' ) ) ); + if ( !empty( $pages[ 'collections' ] ) ) register_column_headers( $pages[ 'collections' ], array( 'cover' => __( 'Cover', 'webcomic' ), 'name' => __( 'Name', 'webcomic' ), 'slug' => __( 'Slug', 'webcomic' ), 'characters' => __( 'Characters', 'webcomic' ), 'storylines' => __( 'Storylines', 'webcomic' ), 'posts' => __( 'Webcomics', 'webcomic' ) ) ); + + add_meta_box( 'webcomic', __( 'Webcomic', 'webcomic' ), array( &$this, 'admin_metabox' ), 'webcomic_post', 'normal', 'high' ); + } + + $help = '' . __( 'Webcomic Help', 'webcomic' ) . ''; + + foreach ( $pages as $page ) + if ( !empty( $page ) ) + add_contextual_help( $page, $help ); + } + + /** + * 'admin_notices' hook. + * + * @package webcomic + * @since 3 + */ + function hook_admin_notices() { + echo ''; + if ( $this->update ) { ?>

    ', $this->update ); ?>

    errors ) { ?>

    ', $this->errors ); ?>

    true ), 'object' ); + + if ( !$taxonomies ) + return $tax; + + foreach ( $taxonomies as $t ) { + if ( !( 'webcomic_collection' == $t->name || 'webcomic_storyline' == $t->name || 'webcomic_character' == $t->name ) ) + continue; + + $id = $t->name; + add_meta_box( "add-{$id}", $t->label, 'wp_nav_menu_item_taxonomy_meta_box', 'nav-menus', 'side', 'default', $t ); + } + + return $tax; + } + + /** + * 'admin_init' hook. + * + * @package webcomic + * @since 3 + */ + function hook_admin_init() { + $this->admin_ajax(); + $this->domain(); + + add_action( 'admin_footer-post.php', array( $this, 'admin_footer_files' ) ); + add_action( 'admin_footer-post-new.php', array( $this, 'admin_footer_files' ) ); + + if ( !current_user_can( 'manage_categories' ) && ( ( isset( $_REQUEST[ 'subpage' ] ) && ( 'edit_webcomic_collection' == $_REQUEST[ 'subpage' ] ) ) || ( !empty( $_REQUEST[ 'bulk' ] ) && ( $action = ( !empty( $_REQUEST[ 'submit-1' ] ) ) ? $_REQUEST[ 'action-1' ] : $_REQUEST[ 'action-2' ] ) && 'batch_file' == $action ) ) ) + wp_die( __( 'You do not have sufficient permissions to access this page.', 'webcomic' ) ); + + if ( isset( $_REQUEST[ 'post_type' ], $_REQUEST[ 'trashed' ] ) && 'webcomic_post' == $_REQUEST[ 'post_type' ] ) { + $wc = current( wp_get_object_terms( $_REQUEST[ 'ids' ], 'webcomic_collection', array( 'fields' => 'ids' ) ) ); + wp_redirect( admin_url( 'admin.php?page=webcomic_files&webcomic_post_trashed=1&webcomic_collection=' . $wc ) ); + die(); + } + + if ( isset( $_REQUEST[ 'webcomic_post_trashed' ] ) ) + $this->update[ 'deleted_post' ] = __( 'Post moved to the trash', 'webcomic' ); + + if ( empty( $_REQUEST[ 'action' ] ) ) + return false; + + if ( 'add_webcomic_term' == $_REQUEST[ 'action' ] ) { + check_admin_referer( 'add_webcomic_term' ); + + $args = array( 'slug' => $_REQUEST[ 'webcomic_nicename' ], 'parent' => $_REQUEST[ 'webcomic_parent' ], 'description' => $_REQUEST[ 'webcomic_description' ] ); + + if ( 'webcomic_collection' == $_REQUEST[ 'page' ] ) + unset( $args[ 'parent' ] ); + + if ( is_wp_error( $new_term = wp_insert_term( trim( $_REQUEST[ 'webcomic_name' ] ), $_REQUEST[ 'page' ], $args ) ) ) + $this->errors = $new_term->get_error_messages(); + else + $this->update[ 'added_term' ] = sprintf( __( 'Added %s', 'webcomic' ), trim( $_REQUEST[ 'webcomic_name' ] ) ); + } + + if ( 'update_webcomic_term' == $_REQUEST[ 'action' ] ) { + check_admin_referer( 'update_webcomic_term' ); + + $args = array( 'name' => trim( $_REQUEST[ 'webcomic_name' ] ), 'slug' => $_REQUEST[ 'webcomic_nicename' ], 'description' => $_REQUEST[ 'webcomic_description' ] ); + + if ( 'webcomic_collection' != $_REQUEST[ 'page' ] ) + $args[ 'parent' ] = $_REQUEST[ 'webcomic_parent' ]; + else + $args[ 'term_group' ] = $_REQUEST[ 'webcomic_group' ]; + + if ( is_wp_error( $update_term = wp_update_term( $_REQUEST[ 'webcomic_term' ], $_REQUEST[ 'page' ], $args ) ) ) + $this->errors = $update_term->get_error_messages(); + else + $this->update[ 'updated_term' ] = sprintf( __( 'Updated %s', 'webcomic' ), trim( $_REQUEST[ 'webcomic_name' ] ) ); + } + + if ( 'delete_webcomic_term' == $_REQUEST[ 'action' ] && $old_term = get_term( $_REQUEST[ 'webcomic_term' ], $_REQUEST[ 'page' ] ) ) { + check_admin_referer( 'delete_webcomic_term' ); + + global $wpdb; + + if ( 'webcomic_collection' == $old_term->taxonomy ) { + if ( $old_term->webcomic_default ) { + $this->errors[ 'default_term' ] = __( 'You cannot delete the default collection.', 'webcomic' ); + return false; + } + + $posts = get_objects_in_term( $old_term->term_id, 'webcomic_collection' ); + } + + if ( is_wp_error( $deleted = wp_delete_term( $_REQUEST[ 'webcomic_term' ], $_REQUEST[ 'page' ] ) ) ) + $this->errors = $deleted->get_error_messages(); + else { + if ( !empty( $posts ) ) { + $cat = ( int ) get_option( 'default_category' ); + $wpdb->query( "UPDATE $wpdb->posts SET post_type = 'post' WHERE ID IN (" . implode( ',', $posts ) . ")" ); + $wpdb->query( "DELETE FROM $wpdb->postmeta WHERE post_id IN (" . implode( ',', $posts ) . ") AND meta_key IN ( 'webcomic' ) " ); + + foreach ( $posts as $p ) + wp_set_object_terms( $p, $cat, 'category' ); + } + + $this->update[ 'deleted_term' ] = sprintf( __( 'Deleted %s', 'webcomic' ), $old_term->name ); + } + } + + if ( 'default_webcomic_term' == $_REQUEST[ 'action' ] && ( 'on' == $_REQUEST[ 'switch' ] || 'off' == $_REQUEST[ 'switch' ] ) && $term = get_term( $_REQUEST[ 'webcomic_term' ], $_REQUEST[ 'page' ] ) ) { + check_admin_referer( 'default_webcomic_term' ); + + $type = end( explode( '_', $_REQUEST[ 'page' ] ) ); + + if ( 'collection' == $type ) { + $a = __( 'set as default', 'webcomic' ); + + $this->option( 'default_collection', $_REQUEST[ 'webcomic_term' ] ); + } else { + $a = ( 'on' == $_REQUEST[ 'switch' ] ) ? __( 'added to defaults', 'webcomic' ) : __( 'removed from defaults', 'webcomic' ); + + $term_meta = $this->option( 'term_meta' ); + $term_meta[ $type ][ $_REQUEST[ 'webcomic_term' ] ][ 'default' ] = ( 'on' == $_REQUEST[ 'switch' ] ) ? true : false; + + $this->option( 'term_meta', $term_meta ); + } + + $this->update[ 'default_term' ] = sprintf( __( '%s %s', 'webcomic' ), $term->name, $a ); + } + + if ( 'move_webcomic_term' == $_REQUEST[ 'action' ] && ( 'up' == $_REQUEST[ 'direction' ] || 'dn' == $_REQUEST[ 'direction' ] ) ) { + check_admin_referer( 'move_webcomic_term' ); + + $term = get_term( $_REQUEST[ 'webcomic_term' ], $_REQUEST[ 'page' ] ); + $sibs = get_terms( $_REQUEST[ 'page' ], 'hide_empty=0&webcomic_order=1&parent=' . $term->parent ); // . '&term_group=' . $wc->term_id + $last = end( $sibs ); + $first = reset( $sibs ); + + if ( ( 'up' == $_REQUEST[ 'direction' ] && $term->term_id == $first->term_id ) || ( 'dn' == $_REQUEST[ 'direction' ] && $term->term_id == $last->term_id ) ) { + $d = ( 'up' == $_REQUEST[ 'direction' ] ) ? __( 'first', 'webcomic' ) : __( 'last', 'webcomic' ); + $this->errors[ 'bad_move' ] = sprintf( __( '“%s” is already %s in this storyline.', 'webcomic' ), $term->name, $d ); + } elseif ( $new_order = ( 'up' == $_REQUEST[ 'direction' ] ) ? $term->webcomic_order - 1 : $term->webcomic_order + 1 ) { + $type = end( explode( '_', $_REQUEST[ 'page' ] ) ); + $term_meta = $this->option( 'term_meta' ); + + foreach ( $sibs as $sib ) { + if ( $new_order == $sib->webcomic_order ) { + $term_meta[ $type ][ $sib->term_id ][ 'order' ] = ( 'up' == $_REQUEST[ 'direction' ] ) ? $sib->webcomic_order + 1 : $sib->webcomic_order - 1; + $term_meta[ $type ][ $term->term_id ][ 'order' ] = $new_order; + break; + } + } + + $this->option( 'term_meta', $term_meta ); + + $a = ( 'up' == $_REQUEST[ 'direction' ] ) ? __( 'up', 'webcomic' ) : __( 'down', 'webcomic' ); + + $this->update[ 'moved_term' ] = sprintf( __( '%s moved %s', 'webcomic' ), $term->name, $a ); + } + } + + if ( 'bulk_webcomic_term' == $_REQUEST[ 'action' ] ) { + check_admin_referer( 'bulk_webcomic_term' ); + + if ( $_REQUEST[ 'bulk' ] && $action = ( !empty( $_REQUEST[ 'submit-1' ] ) ) ? $_REQUEST[ 'action-1' ] : $_REQUEST[ 'action-2' ] ) { + $type = end( explode( '_', $_REQUEST[ 'page' ] ) ); + + if ( 'regen' == $action ) { + $i = 0; + $wc = get_term( $_REQUEST[ 'webcomic_collection' ], 'webcomic_collection' ); + + foreach ( $_REQUEST[ 'bulk' ] as $bulk ) + if ( $this->regen( $bulk, $type, $wc->slug ) ) + $i++; + + if ( $i ) + $this->update[ 'regen_thumbs' ] = sprintf( _n( 'Thumbnails for %d file regenerated', 'Thumbnails for %d files regenerated', $i, 'webcomic' ), $i ); + } elseif ( 'add_default' == $action || 'remove_default' == $action ) { + $i = 0; + $a = ( 'add_default' == $action ) ? __( 'added to', 'webcomic' ) : __( 'removed from', 'webcomic' ); + $term_meta = $this->option( 'term_meta' ); + + foreach ( $_REQUEST[ 'bulk' ] as $bulk ) { + if ( ( 'add_default' == $action && !$term_meta[ $type ][ $bulk ][ 'default' ] ) || ( 'remove_default' == $action && $term_meta[ $type ][ $bulk ][ 'default' ] ) ) + $i++; + + $term_meta[ $type ][ $bulk ][ 'default' ] = ( 'add_default' == $action ) ? true : false; + } + + $this->option( 'term_meta', $term_meta ); + + if ( $i ) + $this->update[ 'default_term' ] = sprintf( _n( '%d term %s defaults', '%d terms %s defaults', $i, 'webcomic' ), $i, $a ); + } elseif ( 'delete' == $action ) { + $i = 0; + + foreach ( $_REQUEST[ 'bulk' ] as $bulk ) + if ( $old_term = get_term( $bulk, $type ) ) + if ( !is_wp_error( $deleted = wp_delete_term( $bulk, $_REQUEST[ 'page' ] ) ) ) + $i++; + + if ( $i ) + $this->update[ 'deleted_term' ] = sprintf( _n( '%d term deleted', '%d terms deleted', $i, 'webcomic' ), $i ); + else + $this->errors[ 'no_terms' ] = sprintf( __( 'None of the selected terms could be deleted', 'webcomic' ) ); + } + } + } + + if ( 'bind_webcomic_file' == $_REQUEST[ 'action' ] || ( 'unbind_webcomic_file' == $_REQUEST[ 'action' ] && isset( $_REQUEST[ 'webcomic_key' ] ) ) ) { + check_admin_referer( 'bind_webcomic_file' ); + + $a = ( 'bind_webcomic_file' == $_REQUEST[ 'action' ] ) ? __( 'bound to', 'webcomic' ) : __( 'unbound from', 'webcomic' ); + $m = ( 'bind_webcomic_file' == $_REQUEST[ 'action' ] ) ? true : false; + $wc = get_term( $_REQUEST[ 'webcomic_collection' ], 'webcomic_collection' ); + + if ( !( $files = $this->fetch( $_REQUEST[ 'post' ], 'post', $wc->slug, $m ) ) ) + return false; + + if ( 'unbind_webcomic_file' == $_REQUEST[ 'action' ] ) + foreach ( $files as $s => $f ) + foreach ( $f as $k => $v ) + if ( $k == $_REQUEST[ 'webcomic_key' ] ) + unset( $files[ $s ][ $k ] ); + + if ( $this->bind( $_REQUEST[ 'post' ], 'post', $files ) ) + $this->update[ 'bound_file' ] = sprintf( __( 'Files %s %s', 'webcomic' ), $a, get_the_title( $_REQUEST[ 'post' ] ) ); + } + + if ( 'regen_webcomic_file' == $_REQUEST[ 'action' ] && isset( $_REQUEST[ 'webcomic_key' ] ) ) { + check_admin_referer( 'regen_webcomic_file' ); + + $wc = ( $_REQUEST[ 'webcomic_collection' ] ) ? get_term( $_REQUEST[ 'webcomic_collection' ], 'webcomic_collection' ) : get_term( $_REQUEST[ 'webcomic_term' ], 'webcomic_collection' ); + + if ( $_REQUEST[ 'post' ] ) { + $id = $_REQUEST[ 'post' ]; + $type = 'post'; + $match = true; + } elseif ( $_REQUEST[ 'orphan' ] ) { + $id = $_REQUEST[ 'orphan' ]; + $type = 'orphan'; + } + + if ( $files = $this->regen( $id, $type, $wc->slug, $_REQUEST[ 'webcomic_key' ] ) ) + $this->update[ 'regen_thumbs' ] = sprintf( __( 'Thumbnails regenerated for %s', 'webcomic' ), implode( ', ', $files ) ); + } + + if ( 'delete_webcomic_file' == $_REQUEST[ 'action' ] && isset( $_REQUEST[ 'webcomic_key' ] ) ) { + check_admin_referer( 'delete_webcomic_file' ); + + $wc = ( $_REQUEST[ 'webcomic_collection' ] ) ? get_term( $_REQUEST[ 'webcomic_collection' ], 'webcomic_collection' ) : get_term( $_REQUEST[ 'webcomic_term' ], 'webcomic_collection' ); + + if ( $_REQUEST[ 'post' ] ) { + $id = $_REQUEST[ 'post' ]; + $type = 'post'; + } elseif ( $_REQUEST[ 'orphan' ] ) { + $id = $_REQUEST[ 'orphan' ]; + $type = 'orphan'; + } + + if ( is_array( $files = $this->delete( $id, $type, $wc->slug, $_REQUEST[ 'webcomic_key' ] ) ) ) + $this->errors[ "no_delete" ] = sprintf( __( 'The following files could not be deleted:

    %s', 'webcomic' ), implode( '
    ', $files ) ); + else + $this->update[ 'deleted_file' ] = sprintf( __( 'Deleted %s', 'webcomic' ), $files ); + } + + if ( 'delete_webcomic_post' == $_REQUEST[ 'action' ] ) { + check_admin_referer( 'delete_webcomic_post' ); + + $s = get_post_status( $_REQUEST[ 'post' ] ); + $a = ( 'trash' == $s ) ? __( 'permanently deleted', 'webcomic' ) : __( 'moved to the trash', 'webcomic' ); + + if ( 'trash' == $s && wp_delete_post( $_REQUEST[ 'post' ] ) ) + $this->update[ 'deleted_post' ] = __( 'Post permanently deleted', 'webcomic' ); + elseif ( wp_trash_post( $_REQUEST[ 'post' ] ) ) + $this->update[ 'deleted_post' ] = __( 'Post moved to the trash', 'webcomic' ); + else + $this->errors[ 'no_delete' ] = sprintf( __( 'The post could not be %a', 'webcomic' ), $a ); + } + + if ( 'undelete_webcomic_post' == $_REQUEST[ 'action' ] ) { + check_admin_referer( 'undelete_webcomic_post' ); + + if ( wp_untrash_post( $_REQUEST[ 'post' ] ) ) + $this->update[ 'restored_post' ] = __( 'Post restored', 'webcomic' ); + else + $this->errors[ 'no_undelete' ] = __( 'The post could not be restored', 'webcomic' ); + } + + if ( 'bulk_webcomic_file' == $_REQUEST[ 'action' ] ) { + check_admin_referer( 'bulk_webcomic_file' ); + + $type = $_REQUEST[ 'webcomic_type' ]; + + if ( !empty( $_REQUEST[ 'bulk' ] ) && $action = ( !empty( $_REQUEST[ 'submit-1' ] ) ) ? $_REQUEST[ 'action-1' ] : $_REQUEST[ 'action-2' ] ) { + if ( 'regen' == $action ) { + $i = 0; + $wc = get_term( $_REQUEST[ 'webcomic_collection' ], 'webcomic_collection' ); + + foreach ( $_REQUEST[ 'bulk' ] as $bulk ) + if ( $files = $this->regen( $bulk, $type, $wc->slug ) ) + $i += count( $files ); + + if ( $i ) + $this->update[ 'regen_thumbs' ] = sprintf( _n( 'Thumbnails for %d file regenerated', 'Thumbnails for %d files regenerated', $i, 'webcomic' ), $i ); + } elseif ( 'bind' == $action || 'unbind' == $action ) { + $i = 0; + $a = ( 'bind' == $action ) ? __( 'bound to' ) : __( 'unbound from' ); + $wc = get_term( $_REQUEST[ 'webcomic_collection' ], 'webcomic_collection' ); + + foreach ( $_REQUEST[ 'bulk' ] as $bulk ) { + $files = ( 'bind' == $action ) ? $this->fetch( $bulk, 'post', $wc->slug, true ) : array(); + + if ( $this->bind( $bulk, $type, $files ) ) + $i++; + } + + if ( $i ) + $this->update[ 'bound_file' ] = sprintf( _n( 'Files %s %d post', 'Files %s %d posts', $i, 'webcomic' ), $a, $i ); + } elseif ( 'delete_file' == $action || 'delete_post' == $action || 'delete_filepost' == $action ) { + $i = $x = 0; + $a = ( 'trash' == get_post_status( current( $_REQUEST[ 'bulk' ] ) ) ) ? __( 'permanently deleted', 'webcomic' ) : __( 'moved to the trash', 'webcomic' ); + $wc = get_term( $_REQUEST[ 'webcomic_collection' ], 'webcomic_collection' ); + $no_delete = array(); + + foreach ( $_REQUEST[ 'bulk' ] as $bulk ) { + if ( 'delete_file' == $action || 'delete_filepost' == $action ) { + if ( is_array( $files = $this->delete( $bulk, $type, $wc->slug ) ) ) + foreach ( $files as $file ) + array_push( $no_delete, $file ); + elseif ( $files ) + $i += count( explode( ',', $files ) ); + } + + if ( 'delete_post' == $action || 'delete_filepost' == $action ) { + if ( 'trash' == get_post_status( $bulk ) ) { + if ( wp_delete_post( $bulk ) ) + $x++; + } elseif ( wp_trash_post( $bulk ) ) + $x++; + } + } + + $output = array(); + $output[ 'files' ] = ( $i ) ? sprintf( _n( '%d file deleted', '%d files deleted', $i, 'webcomic' ), $i ) : sprintf( __( 'No files deleted', 'webcomic' ) ); + $output[ 'posts' ] = ( $x ) ? sprintf( _n( '%d post %s', '%d posts %s', $x, 'webcomic' ), $x, $a ) : $output[ 'posts' ] = sprintf( __( 'no posts %s', 'webcomic' ), $a ); + + if ( 'delete_file' == $action && $i ) + $this->update[ 'deleted_files' ] = $output[ 'files' ]; + elseif ( 'delete_file' == $action ) + $this->errors[ 'no_files' ] = $output[ 'files' ]; + elseif ( 'delete_post' == $action && $x ) + $this->update[ 'deleted_posts' ] = $output[ 'posts' ]; + elseif ( 'delete_post' == $action ) + $this->errors[ 'no_posts' ] = ucfirst( $output[ 'posts' ] ); + elseif ( !$i && !$x ) + $this->errors[ 'no_filepost' ] = implode( ' and ', $output ); + else + $this->update[ 'deteled_fileposts' ] = implode( ' and ', $output ); + } elseif ( 'undelete' == $action ) { + $i = 0; + + foreach ( $_REQUEST[ 'bulk' ] as $bulk ) + if ( wp_untrash_post( $bulk ) ) + $i++; + + if ( $i ) + $this->update[ 'restored_posts' ] = sprintf( _n( '%d post restored', '%d posts restored', $i, 'webcomic' ), $i ); + else + $this->errors[ 'no_posts' ] = sprintf( __( 'No posts restored', 'webcomic' ) ); + } + } elseif ( 'orphan' == $type ) { + $i = 0; + $wc = get_term( $_REQUEST[ 'webcomic_collection' ], 'webcomic_collection' ); + $no_rename = array(); + + foreach ( $_REQUEST[ 'webcomic_filename' ] as $k => $v ) { + if ( !$v || $v == $_REQUEST[ 'webcomic_oldname' ][ $k ] ) + continue; + + if ( is_array( $names = $this->rename( $_REQUEST[ 'webcomic_oldname' ][ $k ] . $_REQUEST[ 'webcomic_extension' ][ $k ], $type, $wc->slug, $v, 0 ) ) ) + foreach ( $names as $name ) + array_push( $no_rename, $name ); + else + $i++; + } + + if ( $i ) + $this->update[ 'renamed_files' ] = sprintf( _n( '%d file renamed', '%d files renamed', $i, 'webcomic' ), $i ); + + if ( !empty( $no_rename ) ) + $this->errors[ "no_rename" ] = sprintf( __( 'The following files could not be renamed:

    %s', 'webcomic' ), implode( '
    ', $no_rename ) ); + } + + if ( isset( $_REQUEST[ 'delete_all' ] ) && 'Empty Trash' == $_REQUEST[ 'delete_all' ] ) { + global $wpdb; + + $p = $wpdb->get_col( "SELECT * FROM $wpdb->posts AS p WHERE p.post_type = 'webcomic_post' AND p.post_status = 'trash'" ); + + foreach ( $p as $k ) + wp_delete_post( $k ); + + $this->update[ 'empty_trash' ] = sprintf( _n( '%d post permanently deleted', '%d posts permanently deleted', count( $p ), 'webcomic' ), count( $p ) ); + } + } + + if ( !empty( $_REQUEST[ 'bulk' ] ) && 'batch_webcomic_posts' == $_REQUEST[ 'action' ] ) { + check_admin_referer( 'batch_webcomic_posts' ); + + global $wpdb; + + $i = 0; + $st = ( 'add' == $_REQUEST[ 'webcomic_post_storylines_action' ] ) ? true : false; + $ct = ( 'add' == $_REQUEST[ 'webcomic_post_characters_action' ] ) ? true : false; + $ps = ( 'publish' == $_REQUEST[ 'webcomic_post_status' ] || 'private' == $_REQUEST[ 'webcomic_post_status' ] || 'pending' == $_REQUEST[ 'webcomic_post_status' ] || 'draft' == $_REQUEST[ 'webcomic_post_status' ] ) ? $_REQUEST[ 'webcomic_post_status' ] : false; + $ss = ( 'on' == $_REQUEST[ 'webcomic_post_sticky' ] || 'off' == $_REQUEST[ 'webcomic_post_sticky' ] ) ? $_REQUEST[ 'webcomic_post_sticky' ] : false; + $cs = ( 'open' == $_REQUEST[ 'webcomic_post_comments' ] || 'closed' == $_REQUEST[ 'webcomic_post_comments' ] ) ? $_REQUEST[ 'webcomic_post_comments' ] : false; + $gs = ( 'open' == $_REQUEST[ 'webcomic_post_pings' ] || 'closed' == $_REQUEST[ 'webcomic_post_pings' ] ) ? $_REQUEST[ 'webcomic_post_pings' ] : false; + $ts = ( 'open' == $_REQUEST[ 'webcomic_post_transcripts' ] || 'closed' == $_REQUEST[ 'webcomic_post_transcripts' ] ) ? $_REQUEST[ 'webcomic_post_transcripts' ] : false; + $xs = ( 'open' == $_REQUEST[ 'webcomic_post_prints' ] || 'closed' == $_REQUEST[ 'webcomic_post_prints' ] ) ? $_REQUEST[ 'webcomic_post_prints' ] : false; + $os = ( 'open' == $_REQUEST[ 'webcomic_post_originals' ] || 'closed' == $_REQUEST[ 'webcomic_post_originals' ] ) ? $_REQUEST[ 'webcomic_post_originals' ] : false; + + if ( !empty( $_REQUEST[ 'webcomic_post_storylines' ] ) ) + foreach ( ( array ) $_REQUEST[ 'webcomic_post_storylines' ] as $k => $v ) + $_REQUEST[ 'webcomic_post_storylines' ][ $k ] = ( int ) $v; + + if ( !empty( $_REQUEST[ 'webcomic_post_characters' ] ) ) + foreach ( ( array ) $_REQUEST[ 'webcomic_post_characters' ] as $k => $v ) + $_REQUEST[ 'webcomic_post_characters' ][ $k ] = ( int ) $v; + + foreach ( $_REQUEST[ 'bulk' ] as $bulk ) { + $i++; + + if ( $ss ) { + if ( 'on' == $ss ) + stick_post( $bulk ); + else + unstick_post( $bulk ); + } + + if ( $ps ) $wpdb->update( $wpdb->posts, array( 'post_status' => $ps ), array( 'ID' => $bulk ) ); + if ( $cs ) $wpdb->update( $wpdb->posts, array( 'comment_status' => $cs ), array( 'ID' => $bulk ) ); + if ( $gs ) $wpdb->update( $wpdb->posts, array( 'ping_status' => $gs ), array( 'ID' => $bulk ) ); + + if ( $ts || $xs || $os ) { + $post_meta = current( get_post_meta( $bulk, 'webcomic' ) ); + + if ( $ts ) + $post_meta[ 'transcribe_toggle' ] = ( 'open' == $_REQUEST[ 'webcomic_post_transcripts' ] ) ? true : false; + + if ( $xs ) + $post_meta[ 'paypal' ][ 'prints' ] = ( 'open' == $_REQUEST[ 'webcomic_post_prints' ] ) ? true : false; + + if ( $os ) + $post_meta[ 'paypal' ][ 'original' ] = ( 'open' == $_REQUEST[ 'webcomic_post_originals' ] ) ? true : false; + + update_post_meta( $bulk, 'webcomic', $post_meta ); + } + + $storylines = wp_get_object_terms( $bulk, 'webcomic_storyline', array( 'fields' => 'ids' ) ); + $characters = wp_get_object_terms( $bulk, 'webcomic_character', array( 'fields' => 'ids' ) ); + + wp_update_term_count( $storylines, 'webcomic_storyline' ); + wp_update_term_count( $characters, 'webcomic_character' ); + + if ( $_REQUEST[ 'webcomic_collection' ] != $_REQUEST[ 'webcomic_post_collection' ] ) { + $this->bind( $bulk, 'post' ); + wp_delete_object_term_relationships( $bulk, array( 'webcomic_collection', 'webcomic_storyline', 'webcomic_character' ) ); + wp_set_object_terms( $bulk, ( int ) $_REQUEST[ 'webcomic_post_collection' ], 'webcomic_collection', false ); + } + + if ( !empty( $_REQUEST[ 'webcomic_post_storylines' ] ) ) + wp_set_object_terms( $bulk, $_REQUEST[ 'webcomic_post_storylines' ], 'webcomic_storyline', $st ); + elseif ( !$st ) + wp_delete_object_term_relationships( $bulk, array( 'webcomic_storyline' ) ); + + if ( !empty( $_REQUEST[ 'webcomic_post_characters' ] ) ) + wp_set_object_terms( $bulk, $_REQUEST[ 'webcomic_post_characters' ], 'webcomic_character', $ct ); + elseif ( !$ct ) + wp_delete_object_term_relationships( $bulk, array( 'webcomic_character' ) ); + } + + if ( $i ) + $this->update[ 'batched_posts' ] = sprintf( _n( '%d post updated', '%d posts updated', $i, 'webcomic' ), $i ); + } + + if ( 'batch_webcomic_files' == $_REQUEST[ 'action' ] && !empty( $_REQUEST[ 'bulk' ] ) ) { + check_admin_referer( 'batch_webcomic_files' ); + + $i = 0; + $wc = get_term( $_REQUEST[ 'webcomic_collection' ], 'webcomic_collection' ); + $week = array( 1 => 'Monday', 2 => 'Tuesday', 3 => 'Wednesday', 4 => 'Thursday', 5 => 'Friday', 6 => 'Saturday', 7 => 'Sunday' ); + $start = $now = ( !empty( $_REQUEST[ 'webcomic_file_auto' ] ) ) ? false : strtotime( $_REQUEST[ 'aa' ] . '-' . $_REQUEST[ 'mm' ] . '-' . $_REQUEST[ 'jj' ] ); + $status = ( !empty( $_REQUEST[ 'webcomic_file_draft' ] ) ) ? 'draft' : 'publish'; + + if ( $start ) { + $today = date( 'N', $start ); + + switch ( $_REQUEST[ 'webcomic_file_interval' ] ) { + case 'day' : $days = array( 1 => 'Monday', 2 => 'Tuesday', 3 => 'Wednesday', 4 => 'Thursday', 5 => 'Friday', 6 => 'Saturday', 7 => 'Sunday' ); break; + case 'bus' : $days = array( 1 => 'Monday', 2 => 'Tuesday', 3 => 'Wednesday', 4 => 'Thursday', 5 => 'Friday' ); break; + case 'end' : $days = array( 6 => 'Saturday', 7 => 'Sunday' ); break; + case 'mwf' : $days = array( 1 => 'Monday', 3 => 'Wednesday', 5 => 'Friday' ); break; + case 'trd' : $days = array( 2 => 'Tuesday', 4 => 'Thursday' ); break; + case 'week': + if ( $_REQUEST[ 'days' ] ) { + foreach ( $_REQUEST[ 'days' ] as $d ) { + $a = explode( '/', $d ); + $days[ $a[ 0 ] ] = $a[ 1 ]; + } + } else + $days[ $today ] = $week[ $today ]; + break; + } + } + + foreach ( $_REQUEST[ 'bulk' ] as $bulk ) { + $info = pathinfo( stripslashes( $bulk ) ); + + if ( $start ) { + $date = date( 'Y-m-d H:i:s', $now ); + $gmt = get_gmt_from_date( $date ); + $today++; + + while ( $today < 9 ) { + $today = ( 8 == $today ) ? 1 : $today; + + if ( isset( $days[ $today ] ) ) { + $key = $today; + break; + } + + $today++; + } + + $now = strtotime( 'next ' . $days[ $key ], $now ); + } else { + $match = array(); + + preg_match( '#(\d\d\d\d)[- /.](0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])#', $info[ 'filename' ], $match ); + + if ( empty( $match ) ) + continue; + + $date = date( 'Y-m-d H:i:s', strtotime( $match[ 0 ] ) ); + $gmt = get_gmt_from_date( $date ); + } + + if ( !is_wp_error( $new_post = wp_insert_post( array( 'post_type' => 'webcomic_post', 'post_title' => $info[ 'filename' ], 'post_content' => '…', 'post_status' => $status, 'post_date' => $date, 'post_date_gmt' => $gmt ) ) ) ) { + $files = $this->fetch( $bulk, 'orphan', $wc->slug ); + + wp_set_object_terms( $new_post, ( int ) $wc->term_id, 'webcomic_collection', false ); + + $this->bind( $new_post, 'post', $files ); + + $post_meta = current( get_post_meta( $new_post, 'webcomic' ) ); + $post_meta[ 'alternate' ] = array(); + $post_meta[ 'description' ] = array(); + $post_meta[ 'transcripts' ] = array(); + $post_meta[ 'transcribe_toggle' ] = $this->option( 'transcribe_toggle' ); + $post_meta[ 'paypal' ] = array( + 'prints' => $wc->webcomic_paypal, + 'original' => true, + 'price_d' => 0, + 'price_i' => 0, + 'price_o' => 0, + 'shipping_d' => 0, + 'shipping_i' => 0, + 'shipping_o' => 0 + ); + + update_post_meta( $new_post, 'webcomic', $post_meta ); + + $i++; + } + } + + if ( $i ) + $this->update[ 'batched_files' ] = sprintf( _n( 'Post generated for %d file', 'Posts generated for %d files', $i, 'webcomic' ), $i ); + elseif ( !$t && !$i ) + $this->errors[ 'no_publish' ] = __( 'No files could be automatically published', 'webcomic' ); + } + + if ( 'bulk_webcomic_upload' == $_REQUEST[ 'action' ] ) { + check_admin_referer( 'bulk_webcomic_upload' ); + + $wc = get_term( $_REQUEST[ 'webcomic_collection' ], 'webcomic_collection' ); + + if ( is_array( $files = $this->upload( $wc->slug, 'bulk' ) ) ) { + $this->update[ 'upload_success' ] = sprintf( _n( '%d file uploaded to %s', '%d files uploaded to %s', count( $files[ 'full' ] ), 'webcomic' ), count( $files[ 'full' ] ), $wc->name ); + $_REQUEST[ 'uploaded_webcomic_files' ] = $files[ 'full' ]; + } + } + + if ( 'edit_webcomic_files' == $_REQUEST[ 'action' ] ) { + check_admin_referer( 'edit_webcomic_files' ); + + if ( !empty( $_REQUEST[ 'webcomic_delete' ] ) ) { + foreach ( $_REQUEST[ 'webcomic_delete' ] as $k => $v ) { + if ( 'full' == $k ) + continue; + + if ( is_array( $files = $this->delete( $_REQUEST[ 'id' ], $_REQUEST[ 'type' ], $_REQUEST[ 'src' ], $_REQUEST[ 'key' ], $k ) ) ) + $this->errors[ "no_delete_$k" ] = sprintf( __( 'The following files could not be deleted:

    %s', 'webcomic' ), implode( '
    ', $files ) ); + else + $this->update[ "delete_$k" ] = sprintf( __( 'Deleted %s size', 'webcomic' ), $k ); + } + } + + if ( is_array( $files = $this->upload( $_REQUEST[ 'src' ], 'singular' ) ) ) + $this->bind( $_REQUEST[ 'id' ], $_REQUEST[ 'type' ], $files, true ); + + $this->update[ 'edit_files' ] = sprintf( __( 'If you uploaded any new files you may need to go back and manually refresh the page to see them.', 'webcomic' ), $_REQUEST[ 'referer' ] ); + } + + if ( 'upgrade_legacy_webcomic' == $_REQUEST[ 'action' ] ) { + check_admin_referer( 'upgrade_legacy_webcomic' ); + + $this->upgrade_legacy( ( int ) $_REQUEST[ 'step' ] ); + } + + if ( 'uninstall_webcomic' == $_REQUEST[ 'action' ] ) { + check_admin_referer( 'uninstall_webcomic' ); + + $this->uninstall(); + } + + if ( 'webcomic_settings' == $_REQUEST[ 'action' ] ) { + check_admin_referer( 'webcomic_settings' ); + + $a = explode( '/', $_REQUEST[ 'transcribe_default' ] ); + $def_language = array( $a[ 0 ] => $a[ 1 ] ); + $new_languages = array(); + + if ( !empty( $_REQUEST[ 'transcribe_language' ] ) ) { + foreach ( $_REQUEST[ 'transcribe_language' ] as $l ) { + $a = explode( '/', $l ); + $new_languages[ $a[ 0 ] ] = $a[ 1 ]; + } + } + + $new_languages = array_merge( $new_languages, $def_language ); + natcasesort( $new_languages ); + + $new[ 'version' ] = $this->version; + $new[ 'default_collection' ] = $this->option( 'default_collection' ); + $new[ 'integrate_toggle' ] = ( isset( $_POST[ 'integrate_toggle' ] ) ) ? true : false; + $new[ 'secure_toggle' ] = ( isset( $_POST[ 'secure_toggle' ] ) ) ? true : false; + $new[ 'transcribe_toggle' ] = ( isset( $_POST[ 'transcribe_toggle' ] ) ) ? true : false; + $new[ 'transcribe_restrict' ] = $_POST[ 'transcribe_restrict' ]; + $new[ 'transcribe_language' ] = $new_languages; + $new[ 'transcribe_default' ] = $def_language; + $new[ 'feed_toggle' ] = ( isset( $_POST[ 'feed_toggle' ] ) ) ? true : false; + $new[ 'feed_size' ] = $_POST[ 'feed_size' ]; + $new[ 'buffer_toggle' ] = ( isset( $_POST[ 'buffer_toggle' ]) ) ? true : false; + $new[ 'buffer_size' ] = abs( intval( $_POST[ 'buffer_size' ] ) ); + $new[ 'age_toggle' ] = ( isset( $_POST[ 'age_toggle' ] ) ) ? true : false; + $new[ 'age_size' ] = abs( intval( $_POST[ 'age_size' ] ) ); + $new[ 'shortcut_toggle' ] = ( isset( $_POST[ 'shortcut_toggle' ] ) ) ? true : false; + $new[ 'paypal_business' ] = $_POST[ 'paypal_business' ]; + $new[ 'paypal_currency' ] = $_POST[ 'paypal_currency' ]; + $new[ 'paypal_log' ] = ( isset( $_POST[ 'paypal_log' ] ) ) ? true : false; + $new[ 'paypal_prints' ] = ( isset( $_POST[ 'paypal_prints' ] ) ) ? true : false; + $new[ 'paypal_method' ] = $_POST[ 'paypal_method' ]; + $new[ 'paypal_price_d' ] = round( abs( floatval( $_POST[ 'paypal_price_d' ] ) ), 2 ); + $new[ 'paypal_price_i' ] = round( abs( floatval( $_POST[ 'paypal_price_i' ] ) ), 2 ); + $new[ 'paypal_price_o' ] = round( abs( floatval( $_POST[ 'paypal_price_o' ] ) ), 2 ); + $new[ 'paypal_shipping_d' ] = round( abs( floatval( $_POST[ 'paypal_shipping_d' ] ) ), 2 ); + $new[ 'paypal_shipping_i' ] = round( abs( floatval( $_POST[ 'paypal_shipping_i' ] ) ), 2 ); + $new[ 'paypal_shipping_o' ] = round( abs( floatval( $_POST[ 'paypal_shipping_o' ] ) ), 2 ); + $new[ 'paypal_donation' ] = round( abs( floatval( $_POST[ 'paypal_donation' ] ) ), 2 ); + $new[ 'large_h' ] = abs( intval( $_POST[ 'large_h' ] ) ); + $new[ 'large_w' ] = abs( intval( $_POST[ 'large_w' ] ) ); + $new[ 'medium_h' ] = abs( intval( $_POST[ 'medium_h' ] ) ); + $new[ 'medium_w' ] = abs( intval( $_POST[ 'medium_w' ] ) ); + $new[ 'small_h' ] = abs( intval( $_POST[ 'small_h' ] ) ); + $new[ 'small_w' ] = abs( intval( $_POST[ 'small_w' ] ) ); + $new[ 'term_meta' ] = $this->option( 'term_meta' ); + + $this->option( $new ); + $this->update[ 'settings' ] = __( 'Settings saved', 'webcomic' ); + } + } + + /** + * 'profile_update' hook. + * + * @package webcomic + * @since 3 + */ + function hook_profile_update( $id ) { + $user_meta = ( current( get_user_meta( $id, 'webcomic' ) ) ) ? current( get_user_meta( $id, 'webcomic' ) ) : array(); + + $user_meta[ 'birthday' ] = ( $_REQUEST[ 'webcomic_birth_year' ] && $_REQUEST[ 'webcomic_birth_month' ] && $_REQUEST[ 'webcomic_birth_day' ] ) ? strtotime( $_REQUEST[ 'webcomic_birth_year' ] . '/' . $_REQUEST[ 'webcomic_birth_month' ] . '/' . $_REQUEST[ 'webcomic_birth_day' ] ) : ''; + + update_user_meta( $id, 'webcomic', $user_meta ); + } + + /** + * 'user_profile' hook. + * + * @package webcomic + * @since 3 + */ + function hook_show_user_profile( $user ) { + $this->domain(); + + $user_meta = current( get_user_meta( $user->ID, 'webcomic' ) ); + $birthday = ( $time = $user_meta[ 'birthday' ] ) ? explode( ' ', date( 'Y n j', $time ) ) : array(); + ?> +

    + + + + + +
    + + + + +
    + $v ) + $_REQUEST[ 'webcomic_storyline' ][ $k ] = ( int ) $v; + + if ( !empty( $_REQUEST[ 'webcomic_character' ] ) ) + foreach ( ( array ) $_REQUEST[ 'webcomic_character' ] as $k => $v ) + $_REQUEST[ 'webcomic_character' ][ $k ] = ( int ) $v; + + wp_set_object_terms( $id, ( int ) $_REQUEST[ 'webcomic_collection' ], 'webcomic_collection', false ); + wp_set_object_terms( $id, $_REQUEST[ 'webcomic_storyline' ], 'webcomic_storyline', false ); + wp_set_object_terms( $id, $_REQUEST[ 'webcomic_character' ], 'webcomic_character', false ); + + $wc = get_term( $_REQUEST[ 'webcomic_collection' ], 'webcomic_collection' ); + $p = ( $_REQUEST[ 'webcomic_paypal_prints' ] ) ? true : false; + $o = ( $_REQUEST[ 'webcomic_paypal_original' ] ) ? false : true; + $a = ( 'sub' == $_REQUEST[ 'webcomic_paypal_price_type_d' ] ) ? intval( 0 - $_REQUEST[ 'webcomic_paypal_price_d' ] ) : intval( $_REQUEST[ 'webcomic_paypal_price_d' ] ); + $b = ( 'sub' == $_REQUEST[ 'webcomic_paypal_price_type_i' ] ) ? intval( 0 - $_REQUEST[ 'webcomic_paypal_price_i' ] ) : intval( $_REQUEST[ 'webcomic_paypal_price_i' ] ); + $c = ( 'sub' == $_REQUEST[ 'webcomic_paypal_price_type_o' ] ) ? intval( 0 - $_REQUEST[ 'webcomic_paypal_price_o' ] ) : intval( $_REQUEST[ 'webcomic_paypal_price_o' ] ); + $d = ( 'sub' == $_REQUEST[ 'webcomic_paypal_shipping_type_d' ] ) ? intval( 0 - $_REQUEST[ 'webcomic_paypal_shipping_d' ] ) : intval( $_REQUEST[ 'webcomic_paypal_shipping_d' ] ); + $e = ( 'sub' == $_REQUEST[ 'webcomic_paypal_shipping_type_i' ] ) ? intval( 0 - $_REQUEST[ 'webcomic_paypal_shipping_i' ] ) : intval( $_REQUEST[ 'webcomic_paypal_shipping_i' ] ); + $f = ( 'sub' == $_REQUEST[ 'webcomic_paypal_shipping_type_o' ] ) ? intval( 0 - $_REQUEST[ 'webcomic_paypal_shipping_o' ] ) : intval( $_REQUEST[ 'webcomic_paypal_shipping_o' ] ); + + $post_meta = current( get_post_meta( $id, 'webcomic' ) ); + $post_meta[ 'files' ] = ( $_REQUEST[ 'current_webcomic_collection' ] == $_REQUEST[ 'webcomic_collection' ] ) ? $post_meta[ 'files' ] : array(); + $post_meta[ 'alternate' ] = ( $_REQUEST[ 'current_webcomic_collection' ] == $_REQUEST[ 'webcomic_collection' ] ) ? $post_meta[ 'alternate' ] : array(); + $post_meta[ 'description' ] = ( $_REQUEST[ 'current_webcomic_collection' ] == $_REQUEST[ 'webcomic_collection' ] ) ? $post_meta[ 'description' ] : array(); + $post_meta[ 'transcripts' ] = array(); + $post_meta[ 'transcribe_toggle' ] = ( $_REQUEST[ 'webcomic_transcribe_toggle' ] ) ? true : false; + $post_meta[ 'paypal' ] = array( + 'prints' => $p, + 'original' => $o, + 'price_d' => $a, + 'price_i' => $b, + 'price_o' => $c, + 'shipping_d' => $d, + 'shipping_i' => $e, + 'shipping_o' => $f + ); + + if ( $_REQUEST[ 'webcomic_alternate' ] ) + foreach ( $_REQUEST[ 'webcomic_alternate' ] as $k => $v ) + $post_meta[ 'alternate' ][ $k ] = $v; + + if ( $_REQUEST[ 'webcomic_description' ] ) + foreach ( $_REQUEST[ 'webcomic_description' ] as $k => $v ) + $post_meta[ 'description' ][ $k ] = $v; + + $languages = $this->option( 'transcribe_language' ); + + foreach ( $languages as $k => $v ) { + if ( 'delete' == $_REQUEST[ 'webcomic_transcript_action' ][ $k ] || !$_REQUEST[ 'webcomic_transcript' ][ $k ] ) + continue; + + $post_meta[ 'transcripts' ][ $k ][ 'language_code' ] = $k; + $post_meta[ 'transcripts' ][ $k ][ 'language' ] = $v; + $post_meta[ 'transcripts' ][ $k ][ 'status' ] = ( 'restore' == $_REQUEST[ 'webcomic_transcript_action' ][ $k ] ) ? 'draft' : $_REQUEST[ 'webcomic_transcript_action' ][ $k ]; + $post_meta[ 'transcripts' ][ $k ][ 'author' ] = ( 'restore' == $_REQUEST[ 'webcomic_transcript_action' ][ $k ] ) ? $_REQUEST[ 'webcomic_transcript_backup_author' ][ $k ] : $_REQUEST[ 'webcomic_transcript_author' ][ $k ]; + $post_meta[ 'transcripts' ][ $k ][ 'time' ] = ( 'restore' == $_REQUEST[ 'webcomic_transcript_action' ][ $k ] ) ? $_REQUEST[ 'webcomic_transcript_backup_time' ][ $k ] : $_REQUEST[ 'webcomic_transcript_time' ][ $k ]; + $post_meta[ 'transcripts' ][ $k ][ 'text' ] = ( 'restore' == $_REQUEST[ 'webcomic_transcript_action' ][ $k ] ) ? $_REQUEST[ 'webcomic_transcript_backup' ][ $k ] : $_REQUEST[ 'webcomic_transcript' ][ $k ]; + + if ( $current_user->data->rich_editing ) + $post_meta[ 'transcripts' ][ $k ][ 'text' ] = wpautop( $post_meta[ 'transcripts' ][ $k ][ 'text' ] ); + + if ( 'draft' == $_REQUEST[ 'webcomic_transcript_action' ][ $k ] && $_REQUEST[ 'webcomic_transcript_backup' ][ $k ] ) { + $post_meta[ 'transcripts' ][ $k ][ 'backup' ] = $_REQUEST[ 'webcomic_transcript_backup' ][ $k ]; + $post_meta[ 'transcripts' ][ $k ][ 'backup_time' ] = $_REQUEST[ 'webcomic_transcript_backup_time' ][ $k ]; + $post_meta[ 'transcripts' ][ $k ][ 'backup_author' ] = $_REQUEST[ 'webcomic_transcript_backup_author' ][ $k ]; + } + } + + $files = ( $_REQUEST[ 'current_webcomic_collection' ] == $_REQUEST[ 'webcomic_collection' ] ) ? $this->fetch( $id, 'post', $wc->slug, true ) : array(); + + if ( $_REQUEST[ 'webcomic_orphan' ] ) { + $tabs = $this->directory( 'abs', $wc->slug . '/thumbs' ); + + foreach ( $_REQUEST[ 'webcomic_orphan' ] as $orphan ) { + $info = pathinfo( stripslashes( $orphan ) ); + $files[ 'full' ][] = $info[ 'basename' ]; + + if ( is_file( $tabs . $info[ 'filename' ] . '-small.' . $info[ 'extension' ] ) ) + $files[ 'small' ][] = $info[ 'filename' ] . '-small.' . $info[ 'extension' ]; + if ( is_file( $tabs . $info[ 'filename' ] . '-medium.' . $info[ 'extension' ] ) ) + $files[ 'medium' ][] = $info[ 'filename' ] . '-medium.' . $info[ 'extension' ]; + if ( is_file( $tabs . $info[ 'filename' ] . '-large.' . $info[ 'extension' ] ) ) + $files[ 'large' ][] = $info[ 'filename' ] . '-large.' . $info[ 'extension' ]; + } + + natcasesort( $files[ 'full' ] ); + + $post_meta[ 'files' ] = $files; + } + + update_post_meta( $id, 'webcomic', $post_meta ); + + if ( is_array( $files = $this->upload( $wc->slug, 'bulk' ) ) ) + $this->bind( $id, 'post', $files, false ); + elseif ( !empty( $files ) && !$_REQUEST[ 'webcomic_orphan' ] ) { + if ( isset( $_REQUEST[ 'webcomic_filename' ] ) ) + foreach ( $_REQUEST[ 'webcomic_filename' ] as $k => $v ) + if ( $v && $files[ 'full' ][ $k ] != $v . $_REQUEST[ 'webcomic_extension' ][ $k ] && is_array( $names = $this->rename( $id, 'post', $wc->slug, $v, $k ) ) ) + $this->errors[ "no_rename_$k" ] = sprintf( __( 'The following files could not be renamed:

    %s', 'webcomic' ), implode( '
    ', $names ) ); + + if ( !empty( $_REQUEST[ 'webcomic_action' ] ) ) { + foreach ( $_REQUEST[ 'webcomic_action' ] as $k => $v ) { + $files = $this->fetch( $id, 'post', $wc->slug, true ); + + if ( 'regen' == $v ) + $this->regen( $id, 'post', $wc->slug, $k ); + elseif ( 'bind' == $v ) + $this->bind( $id, 'post', $files ); + elseif ( 'unbind' == $v ) { + foreach ( $files as $s => $f ) + unset( $files[ $s ][ $k ] ); + + $this->bind( $id, 'post', $files ); + } elseif ( 'delete' == $v && is_array( $files = $this->delete( $id, 'post', $wc->slug, $k ) ) ) + $this->errors[ "no_delete_$k" ] = sprintf( __( 'The following files could not be deleted:

    %s', 'webcomic' ), implode( '
    ', $files ) ); + } + } + } + } else { + wp_delete_object_term_relationships( $id, array( 'webcomic_collection', 'webcomic_storyline', 'webcomic_character' ) ); + delete_post_meta( $id, 'webcomic' ); + } + } + + + + //// + // Hooks - Taxonomy + // + // These functions hook into various WordPress + // taxonomy actions and should never be called + // directly. + //// + + /** + * 'created_webcomic_collection' hook. + * + * @package webcomic + * @since 3 + */ + function hook_created_webcomic_collection( $term_id, $tt_id ) { + $this->domain(); + + $term_meta = $this->option( 'term_meta' ); + $term = get_term( $term_id, 'webcomic_collection' ); + $tabs = $this->directory( 'abs', $term->slug . '/thumbs' ); + + if ( !@mkdir( $tabs, 0755, true ) ) + $this->errors[ 'no_directory' ] = sprintf( __( 'The collection directory could not be created. You will need to create the following directory (if it does not already exist) before you can manage webcomics for this collection: %s', 'webcomic' ), $tabs ); + + $term_meta[ 'collection' ][ $term_id ] = array( + 'files' => array(), + 'slug' => $term->slug, + 'restrict' => false, + 'bookend' => array( + 'first' => false, + 'last' => false + ), + 'paypal' => array( + 'prints' => $this->option( 'paypal_prints' ), + 'price_d' => 0, + 'price_i' => 0, + 'price_o' => 0, + 'shipping_d' => 0, + 'shipping_i' => 0, + 'shipping_o' => 0 + ) + ); $this->option( 'term_meta', $term_meta ); + } + + /** + * 'created_webcomic_storyline' hook. + * + * @package webcomic + * @since 3 + */ + function hook_created_webcomic_storyline( $term_id, $tt_id ) { + $term_meta = $this->option( 'term_meta' ); + $term_meta[ 'storyline' ][ $term_id ] = array( + 'files' => array(), + 'order' => count( get_terms( 'webcomic_storyline', 'hide_empty=0&webcomic_order=1&parent=' . $_REQUEST[ 'webcomic_parent' ] . '&term_group=' . $_REQUEST[ 'webcomic_collection' ] ) ) + 1, + 'parent' => $_REQUEST[ 'webcomic_parent' ], + 'group' => $_REQUEST[ 'webcomic_collection' ], + 'default' => false + ); $this->option( 'term_meta', $term_meta ); + + wp_update_term( $term_id, 'webcomic_storyline', array( 'term_group' => $_REQUEST[ 'webcomic_collection' ] ) ); + } + + /** + * 'created_webcomic_character' hook. + * + * @package webcomic + * @since 3 + */ + function hook_created_webcomic_character( $term_id, $tt_id ) { + $term_meta = $this->option( 'term_meta' ); + $term_meta[ 'character' ][ $term_id ] = array( + 'files' => array(), + 'group' => $_REQUEST[ 'webcomic_collection' ], + 'default' => false + ); $this->option( 'term_meta', $term_meta ); + + wp_update_term( $term_id, 'webcomic_character', array( 'term_group' => $_REQUEST[ 'webcomic_collection' ] ) ); + } + + /** + * 'edited_term' hook. + * + * @package webcomic + * @since 3 + */ + function hook_edited_term( $term_id, $tt_id, $taxonomy ) { + $this->domain(); + + if ( 'webcomic_collection' == $taxonomy || 'webcomic_storyline' == $taxonomy || 'webcomic_character' == $taxonomy ) { + $term_meta = $this->option( 'term_meta' ); + $term = get_term( $term_id, $taxonomy ); + $type = end( explode( '_', $taxonomy ) ); + $key = ( 'collection' == $type ) ? $term->term_id : $term->term_group; + + if ( !empty( $term_meta[ $type ][ $term_id ][ 'files' ] ) ) { + foreach ( $_REQUEST[ 'webcomic_filename' ] as $k => $v ) + if ( $v && $term_meta[ $type ][ $term_id ][ 'files' ][ 'full' ][ $k ] != $v . $_REQUEST[ 'webcomic_extension' ][ $k ] && is_array( $names = $this->rename( $term_id, $type, $term_meta[ 'collection' ][ $key ][ 'slug' ], $v, $k ) ) ) + $this->errors[ "no_rename_$k" ] = sprintf( __( 'The following files could not be renamed:

    %s', 'webcomic' ), implode( '
    ', $names ) ); + + foreach ( $_REQUEST[ 'webcomic_action' ] as $k => $v ) { + if ( 'regen' == $v ) + $this->regen( $term_id, $type, $term_meta[ 'collection' ][ $key ][ 'slug' ], $k ); + elseif ( 'delete' == $v && is_array( $files = $this->delete( $term_id, $type, $term_meta[ 'collection' ][ $key ][ 'slug' ], $k ) ) ) + $this->errors[ "no_delete_$k" ] = sprintf( __( 'The following files could not be deleted:

    %s', 'webcomic' ), implode( '
    ', $files ) ); + } + } + + if ( is_array( $files = $this->upload( $term_meta[ 'collection' ][ $key ][ 'slug' ] ) ) ) + $this->bind( $term_id, $type, $files, false ); + } + } + + /** + * 'edited_webcomic_collection' hook. + * + * @package webcomic + * @since 3 + */ + function hook_edited_webcomic_collection( $term_id, $tt_id ) { + $this->domain(); + + $term_meta = $this->option( 'term_meta' ); + $term = get_term( $term_id, 'webcomic_collection' ); + $nabs = $this->directory( 'abs', $term->slug ); + $oabs = $this->directory( 'abs', $term_meta[ 'collection' ][ $term_id ][ 'slug' ] ); + + if ( $nabs != $oabs ) + if ( !rename( $oabs, $nabs ) ) + $this->errors[ 'no_rename' ] = sprintf( __( 'The directory for this collection could not be renamed. You will need to rename %s to %s', 'webcomic' ), $oabs, $nabs ); + + $p = ( !empty( $_REQUEST[ 'webcomic_paypal_prints' ] ) ) ? true : false; + $a = ( 'sub' == $_REQUEST[ 'webcomic_paypal_price_type_d' ] ) ? intval( 0 - $_REQUEST[ 'webcomic_paypal_price_d' ] ) : intval( $_REQUEST[ 'webcomic_paypal_price_d' ] ); + $b = ( 'sub' == $_REQUEST[ 'webcomic_paypal_price_type_i' ] ) ? intval( 0 - $_REQUEST[ 'webcomic_paypal_price_i' ] ) : intval( $_REQUEST[ 'webcomic_paypal_price_i' ] ); + $c = ( 'sub' == $_REQUEST[ 'webcomic_paypal_price_type_o' ] ) ? intval( 0 - $_REQUEST[ 'webcomic_paypal_price_o' ] ) : intval( $_REQUEST[ 'webcomic_paypal_price_o' ] ); + $d = ( 'sub' == $_REQUEST[ 'webcomic_paypal_shipping_type_d' ] ) ? intval( 0 - $_REQUEST[ 'webcomic_paypal_shipping_d' ] ) : intval( $_REQUEST[ 'webcomic_paypal_shipping_d' ] ); + $e = ( 'sub' == $_REQUEST[ 'webcomic_paypal_shipping_type_i' ] ) ? intval( 0 - $_REQUEST[ 'webcomic_paypal_shipping_i' ] ) : intval( $_REQUEST[ 'webcomic_paypal_shipping_i' ] ); + $f = ( 'sub' == $_REQUEST[ 'webcomic_paypal_shipping_type_o' ] ) ? intval( 0 - $_REQUEST[ 'webcomic_paypal_shipping_o' ] ) : intval( $_REQUEST[ 'webcomic_paypal_shipping_o' ] ); + + $term_meta[ 'collection' ][ $term_id ][ 'slug' ] = $term->slug; + $term_meta[ 'collection' ][ $term_id ][ 'restrict' ] = ( isset( $_REQUEST[ 'webcomic_restrict' ] ) ) ? true : false; + $term_meta[ 'collection' ][ $term_id ][ 'bookend' ] = array( + 'first' => $_REQUEST[ 'webcomic_bookend_first' ], + 'last' => $_REQUEST[ 'webcomic_bookend_last' ] + ); + $term_meta[ 'collection' ][ $term_id ][ 'paypal' ] = array( + 'prints' => $p, + 'price_d' => $a, + 'price_i' => $b, + 'price_o' => $c, + 'shipping_d' => $d, + 'shipping_i' => $e, + 'shipping_o' => $f + ); + + $this->option( 'term_meta', $term_meta ); + } + + /** + * 'edited_webcomic_storyline' hook. + * + * @package webcomic + * @since 3 + */ + function hook_edited_webcomic_storyline( $term_id, $tt_id ) { + $term_meta = $this->option( 'term_meta' ); + $term = get_term( $term_id, 'webcomic_storyline' ); + + if ( $term->parent != $term_meta[ 'storyline' ][ $term_id ][ 'parent' ] ) { + $i = 1; + + if ( $old_sibs = get_terms( 'webcomic_storyline', 'hide_empty=0&webcomic_order=1&parent=' . $term_meta[ 'storyline' ][ $term_id ][ 'parent' ] . '&term_group=' . $term->term_group ) ) { + foreach ( $old_sibs as $sib ) { + $term_meta[ 'storyline' ][ $sib->term_id ][ 'order' ] = $i; + $i++; + } + + $i = 1; + } + + if ( $new_sibs = get_terms( 'webcomic_storyline', 'hide_empty=0&webcomic_order=1&parent=' . $term->parent . '&term_group=' . $term->term_group ) ) { + foreach ( $new_sibs as $sib ) { + if ( $sib->term_id == $term_id ) + continue; + + $term_meta[ 'storyline' ][ $sib->term_id ][ 'order' ] = $i; + $i++; + } + + $term_meta[ 'storyline' ][ $term_id ][ 'order' ] = $i; + } + + $term_meta[ 'storyline' ][ $term_id ][ 'parent' ] = $term->parent; + $this->option( 'term_meta', $term_meta ); + } + } + + /** + * 'delete_webcomic_collection' hook. + * + * @package webcomic + * @since 3 + */ + function hook_delete_webcomic_collection( $term_id, $tt_id ) { + $this->domain(); + + global $wpdb; + + $term_meta = $this->option( 'term_meta' ); + $abs = $this->directory( 'abs', $term_meta[ 'collection' ][ $term_id ][ 'slug' ] ); + $tabs = $abs . 'thumbs/'; + $terms = get_terms( array( 'webcomic_storyline', 'webcomic_character' ), 'hide_empty=0&term_group=' . $term_id ); + + if ( $terms ) + foreach ( $terms as $term ) + wp_delete_term( $term->term_id, $term->taxonomy ); + + if ( is_array( $files = $this->delete( $term_id, 'collection', $term_meta[ 'collection' ][ $term_id ][ 'slug' ] ) ) ) + $this->errors[ "no_delete_$term_id" ] = sprintf( __( 'The following files could not be deleted:

    %s', 'webcomic' ), implode( '
    ', $files ) ); + + unset( $term_meta[ 'collection' ][ $term_id ] ); + $this->option( 'term_meta', $term_meta ); + } + + /** + * 'delete_webcomic_storyline' hook. + * + * @package webcomic + * @since 3 + */ + function hook_delete_webcomic_storyline( $term_id, $tt_id ) { + $this->domain(); + + $term_meta = $this->option( 'term_meta' ); + $term_group = $term_meta[ 'storyline' ][ $term_id ][ 'group' ]; + + if ( is_array( $files = $this->delete( $term_id, 'storyline', $term_meta[ 'collection' ][ $term_group ][ 'slug' ] ) ) ) + $this->errors[ "no_delete_$term_id" ] = sprintf( __( 'The following files could not be deleted:

    %s', 'webcomic' ), implode( '
    ', $files ) ); + + $i = 1; + if ( $sibs = get_terms( 'webcomic_storyline', 'hide_empty=0&webcomic_order=1&parent=' . $term_meta[ 'storyline' ][ $term_id ][ 'parent' ] . '&term_group=' . $term_group ) ) { + foreach ( $sibs as $sib ) { + $term_meta[ 'storyline' ][ $sib->term_id ][ 'order' ] = $i; + $i++; + } + } + + unset( $term_meta[ 'storyline' ][ $term_id ] ); + $this->option( 'term_meta', $term_meta ); + } + + /** + * 'delete_webcomic_character' hook. + * + * @package webcomic + * @since 3 + */ + function hook_delete_webcomic_character( $term_id, $tt_id ) { + $this->domain(); + + $term_meta = $this->option( 'term_meta' ); + $term_group = $term_meta[ 'character' ][ $term_id ][ 'group' ]; + + if ( is_array( $files = $this->delete( $term_id, 'character', $term_meta[ 'collection' ][ $term_group ][ 'slug' ] ) ) ) + $this->errors[ "no_delete_$term_id" ] = sprintf( __( 'The following files could not be deleted:

    %s', 'webcomic' ), implode( '
    ', $files ) ); + + unset( $term_meta[ 'character' ][ $term_id ] ); + $this->option( 'term_meta', $term_meta ); + } + + + + //// + // Utilities + // + // These functions are designed for internal use + // and should never be called directly. + //// + + /** + * Uploads one or more files to the specified directory. + * + * @package webcomic + * @since 3 + * + * @param str $src The directory to upload files to. + * @param bool $method How to handle the uploaded file. + * @return arr|bool An array of filenames, or false on error. + */ + function upload( $src, $method = false ) { + $uploads = array(); + + if ( empty( $_FILES[ 'webcomic_file' ] ) ) + return true; + + foreach ( $_FILES[ 'webcomic_file' ] as $a => $r ) + foreach ( $r as $k => $v ) + $uploads[ $k ][ $a ] = $v; + + $this->domain(); + + $match = ( isset( $_REQUEST[ 'type' ] ) && 'post' == $_REQUEST[ 'type' ] ) ? true : false; + $files = ( 'singular' == $method ) ? $this->fetch( $_REQUEST[ 'id' ], $_REQUEST[ 'type' ], $src, $match ) : array(); + $abs = $this->directory( 'abs', $src ); + $url = $this->directory( 'url', $src ); + $tabs = $abs . 'thumbs/'; + $lw = $this->option( 'large_w' ); + $lh = $this->option( 'large_h' ); + $mw = $this->option( 'medium_w' ); + $mh = $this->option( 'medium_h' ); + $sw = $this->option( 'small_w' ); + $sh = $this->option( 'small_h' ); + $i = $x = $z = 0; + + foreach ( $uploads as $key => $upload ) { + if ( 0 === $upload[ 'error' ] ) { + if ( 'singular' == $method ) { + $z = true; + $info = pathinfo( $upload[ 'name' ] ); + $name = stripslashes( $_REQUEST[ 'webcomic_filename' ] ) . '-' . $key . '.' . $info[ 'extension' ]; + $file = $tabs . $name; + + if ( @move_uploaded_file( $upload[ 'tmp_name' ], $file ) ) + $files[ $key ][ $_REQUEST[ 'key' ] ] = $name; + } elseif ( is_array( $size = @getimagesize( $upload[ 'tmp_name' ] ) ) ) { + $z = true; + $info = pathinfo( $upload[ 'name' ] ); + $hash = ( $this->option( 'secure_toggle' ) ) ? '-' . substr( hash( 'md5', uniqid( rand() ) ), 0, 7 ) : ''; + $name = $info[ 'filename' ] . $hash . '.' . $info[ 'extension' ]; + $file = $abs . $name; + + if ( !$name || 0 === strpos( $name, '.' ) ) + continue; + + if ( ( !is_file( $file ) || !empty( $_REQUEST[ 'webcomic_overwrite' ] ) ) && @move_uploaded_file( $upload[ 'tmp_name' ], $file ) ) { + $stat = stat( dirname( $file ) ); + $perm = $stat[ 'mode' ] & 0000666; + chmod( $file, $perm ); + + $files[ 'full' ][ $x ] = $name; + + if ( 'image/jpeg' == $size[ 'mime' ] || 'image/gif' == $size[ 'mime' ] || 'image/png' == $size[ 'mime' ] ) { + if ( $size[ 0 ] > $lw || $size[ 1 ] > $lh ) + if ( $large = $this->resize( $file, $lw, $lh, 0, 'large', $tabs ) ) + $files[ 'large' ][ $x ] = basename( $large ); + + if ( $size[ 0 ] > $mw || $size[ 1 ] > $mh ) + if ( $medium = $this->resize( $file, $mw, $mh, 0, 'medium', $tabs ) ) + $files[ 'medium' ][ $x ] = basename( $medium ); + + if ( $size[ 0 ] > $sw || $size[ 1 ] > $sh ) + if ( $small = $this->resize( $file, $sw, $sh, 0, 'small', $tabs ) ) + $files[ 'small' ][ $x ] = basename( $small ); + } + } elseif ( is_file( $file ) ) + $this->errors[ "file_exists_$x" ] = sprintf( __( 'A file named %s already exists.', 'webcomic' ), $url . $upload[ 'name' ], $upload[ 'name' ] ); + else + $this->errors[ "no_move_$x" ] = sprintf( __( '%s could not be moved to the correct directory.', 'webcomic' ), $upload[ 'name' ] ); + } elseif ( is_resource( $data = @zip_open( $upload[ 'tmp_name' ] ) ) && 'bulk' == $method ) { + if ( $z ) + continue; + + while ( $entry = zip_read( $data ) ) { + $base = basename( zip_entry_name( $entry ) ); + $extn = substr( strrchr( $base, '.'), 0 ); + $hash = ( $this->option( 'secure_toggle' ) ) ? '-' . substr( hash( 'md5', uniqid( rand() ) ), 0, 7 ) : ''; + $name = substr( $base, 0, -strlen( $extn ) ) . $hash . $extn; + $file = $abs . $name; + + if ( !$name || 0 === strpos( $name, '.' ) ) + continue; + + if ( ( !is_file( $file ) || !empty( $_REQUEST[ 'webcomic_overwrite' ] ) ) && zip_entry_open( $data, $entry ) ) { + $content = zip_entry_read( $entry, zip_entry_filesize( $entry ) ); + + $newfile = fopen( $file, 'w' ); + + if ( !is_resource( $newfile ) ) + continue; + + fwrite( $newfile, $content ); + fclose( $newfile ); + + if ( is_array( $size = @getimagesize( $file ) ) ) { + $i++; + + $stat = stat( dirname( $file ) ); + $perm = $stat[ 'mode' ] & 0000666; + chmod( $file, $perm ); + + $files[ 'full' ][ $i ] = basename( $file ); + + if ( 'image/jpeg' == $size[ 'mime' ] || 'image/gif' == $size[ 'mime' ] || 'image/png' == $size[ 'mime' ] ) { + if ( $size[ 0 ] > $lw || $size[ 1 ] > $lh ) + if ( $large = $this->resize( $file, $lw, $lh, 0, 'large', $tabs ) ) + $files[ 'large' ][ $i ] = basename( $large ); + + if ( $size[ 0 ] > $mw || $size[ 1 ] > $mh ) + if ( $medium = $this->resize( $file, $mw, $mh, 0, 'medium', $tabs ) ) + $files[ 'medium' ][ $i ] = basename( $medium ); + + if ( $size[ 0 ] > $sw || $size[ 1 ] > $sh ) + if ( $small = $this->resize( $file, $sw, $sh, 0, 'small', $tabs ) ) + $files[ 'small' ][ $i ] = basename( $small ); + } + } else + unlink( $file ); + + zip_entry_close( $entry ); + } + } + + zip_close( $data ); + + if ( $i ) + $this->update[ "upload_archive_$x" ] = sprintf( _n( '%d file extracted from %s', '%d files extracted from %s', $i, 'webcomic' ), $i, $upload[ 'name' ] ); + else + $this->errors[ "no_archive_$x" ] = sprintf( __( 'No files could be extracted from %s', 'webcomic' ), $upload[ 'name' ] ); + + break; + } else + $this->errors[ "bad_type_$x" ] = sprintf( __( '%s is an invalid file type', 'webcomic' ), $upload[ 'name' ] ); + } else { + switch ( $upload[ 'error' ] ) { + case 1: + case 2: $this->errors[ "too_big_$x" ] = sprintf( __( 'The file is larger than the maximum upload size of %s', 'webcomic' ), ini_get( 'upload_max_filesize' ) ); break; + case 3: $this->errors[ "partial_file_$x" ] = __( 'The file was only partially uploaded', 'webcomic' ); break; + case 4: continue; + case 6: $this->errors[ "no_temp_$x" ] = __( 'The server temporary directory could not be found', 'webcomic' ); break; + case 7: $this->errors[ "no_save_$x" ] = __( 'The file could not be saved after upload', 'webcomic' ); break; + case 8: $this->errors[ "file_halt_$x" ] = __( 'The upload was halted by a PHP extension', 'webcomic'); break; + } + } + + $x++; + } + + if ( empty( $files ) ) + return true; + elseif ( !empty( $files[ 'full' ] ) ) + natcasesort( $files[ 'full' ] ); + else + return false; + + return $files; + } + + /** + * Resizes the specified file. + * + * @package webcomic + * @since 3 + * + * @param str $file The file to be resized. + * @param int $width The new maximum width. + * @param int $height The new maximum height. + * @param bool $crop Wehter to crop the resized image to the exact dimensions specified. + * @param str $suffix A suffix to append to the end of the filename. + * @param str $directory The directory to save the resized file to. + * @return str|bool The name of the resized file, or false on error. + */ + function resize( $file, $width, $height, $crop, $suffix, $directory ) { + if ( !is_file( $file ) || !is_resource( $image = imagecreatefromstring( file_get_contents( $file ) ) ) || !( $size = getimagesize( $file ) ) || ( $width <= 0 && $height <= 0 ) ) + return false; + + if ( $size[ 0 ] <= 0 || $size[ 1 ] <= 0 ) + return false; + + if ( $crop ) { + $ar = $size[ 0 ] / $size[ 1 ]; + $nw = min( $width, $size[ 0 ] ); + $nh = min( $height, $size[ 1 ] ); + + if ( !$nw ) + $nw = intval( $nh * $ar ); + + if ( !$nh ) + $nh = intval( $nw / $ar ); + + $sr = max( $nw / $size[ 0 ], $nh / $size[ 1 ] ); + $cw = round( $nw / $sr ); + $ch = round( $nh / $sr ); + $sx = floor( ( $size[ 0 ] - $cw) / 2 ); + $sy = floor( ( $size[ 1 ] - $ch) / 2 ); + } else { + $cw = $size[ 0 ]; + $ch = $size[ 1 ]; + $sx = $sy = 0; + $wr = $hr = 1.0; + + if ( $width > 0 && $size[ 0 ] > 0 && $size[ 0 ] > $width ) + $wr = $width / $size[ 0 ]; + + if ( $height > 0 && $size[ 1 ] > 0 && $size[ 1 ] > $height ) + $hr = $height / $size[ 1 ]; + + $r = min( $wr, $hr ); + $nw = intval( $size[ 0 ] * $r ); + $nh = intval( $size[ 1 ] * $r ); + } + + if ( $nw >= $size[ 0 ] && $nh >= $size[ 1 ] ) + return false; + + if ( is_resource( $newimg = imagecreatetruecolor( $nw, $nh ) ) ) { + imagealphablending( $newimg, false ); + imagesavealpha( $newimg, true ); + } else + return false; + + imagecopyresampled( $newimg, $image, 0, 0, $sx, $sy, $nw, $nh, $cw, $ch ); + + if ( ( 'image/png' == $size[ 'mime' ] || 'image/gif' == $size[ 'mime' ] ) && !imageistruecolor( $image ) ) { + imagetruecolortopalette( $newimg, true, imagecolorstotal( $image ) ); + + if ( false !== ( $trans = imagecolortransparent( $image ) ) ) { + $color = ( $trans >= 0 ) ? imagecolorsforindex( $image, imagecolortransparent( $image ) ) : array( 'red' => 255, 'green' => 255, 'blue' => 255 ); + $trans = imagecolorallocate( $newimg, $color[ 'red' ], $color[ 'green' ], $color[ 'blue' ] ); + imagefill( $newimg, 0, 0, $trans ); + imagecolortransparent( $newimg, $trans ); + } + } + + imagedestroy( $image ); + + if ( $suffix ) + $suffix = '-' . $suffix; + + $info = pathinfo( $file ); + + if ( !is_null( $directory ) && $path = realpath( $directory ) ) + $dir = $path; + + $filename = $dir . '/' . $info[ 'filename' ] . $suffix . '.' . $info[ 'extension' ]; + + if ( 'image/jpeg' == $size[ 'mime' ] ) { + if ( !imagejpeg( $newimg, $filename, 100 ) ) + return false; + } elseif ( 'image/gif' == $size[ 'mime' ] ) { + if ( !imagegif( $newimg, $filename ) ) + return false; + } elseif ( 'image/png' == $size[ 'mime' ] ) { + if ( !imagepng( $newimg, $filename ) ) + return false; + } else + return false; + + imagedestroy( $newimg ); + + $stat = stat( dirname( $filename ) ); + $perm = $stat[ 'mode' ] & 0000666; + chmod( $filename, $perm ); + + return $filename; + } + + /** + * Binds a set of files to the specified object. + * + * @package webcomic + * @since 3 + * + * @param int $id ID of the object files will be bound to. + * @param str $type The type of object, one of 'collection', 'storyline', 'character', or 'post'. + * @param arr $files An array of files to bind. + * @param bool $altdes Maintain alternative and descripttive text associations if true. + * @return bool False if a non-standard type is specified, true otherwise. + */ + function bind( $id, $type, $files = array(), $altdes = true ) { + $files = ( empty( $files[ 'full' ] ) ) ? array() : $files; + + if ( !empty( $files ) ) + foreach ( $files as $s => $f ) + foreach ( $f as $k => $v ) + $files[ $s ][ $k ] = stripslashes( $v ); + + if ( 'collection' == $type || 'storyline' == $type || 'character' == $type ) { + $term_meta = $this->option( 'term_meta' ); + + $term_meta[ $type ][ $id ][ 'files' ] = $files; + + $this->option( 'term_meta', $term_meta ); + } elseif ( 'post' == $type ) { + $post_meta = current( get_post_meta( $id, 'webcomic' ) ); + + if ( empty( $files ) || !$altdes ) { + $post_meta[ 'alternate' ] = array(); + $post_meta[ 'description' ] = array(); + } elseif ( ( !empty( $post_meta[ 'alternate' ] ) || !empty( $post_meta[ 'description' ] ) ) && ( $a = array_diff( array_keys( ( array ) $post_meta[ 'alternate' ] ), array_keys( $files[ 'full' ] ) ) ) ) { + foreach ( $a as $k ) { + unset( $post_meta[ 'alternate' ][ $k ] ); + unset( $post_meta[ 'description' ][ $k ] ); + } + } + + $post_meta[ 'files' ] = $files; + + update_post_meta( $id, 'webcomic', $post_meta ); + } else + return false; + + return true; + } + + /** + * Renames the files associated with an object. + * + * @package webcomic + * @since 3 + * + * @param int $id ID of the object to fetch files from. + * @param str $type The type of object to fetch for. Must be one of 'collection', 'storyline', 'character', 'post', or 'orphan'. + * @param str $src The directory to search when fetch files for 'orphan' type objects. + * @param str $filename The new filename to use. + * @param int $key The key that points to the file associated with the specified object. + * @return bool|arr True on success, false if no files can be found. Array of files that could not be renamed on error. + */ + function rename( $id, $type, $src, $filename, $key = false ) { + if ( false === $key ) + return false; + + $match = ( 'post' == $type || 'orphan' == $type ) ? true : false; + $abs = $this->directory( 'abs', $src ); + $tabs = $abs . 'thumbs/'; + $hash = ( $this->option( 'secure_toggle' ) ) ? '-' . substr( hash( 'md5', uniqid( rand() ) ), 0, 7 ) : ''; + $output = $bind = array(); + $filename = stripslashes( $filename ); + + if ( !( $files = $this->fetch( $id, $type, $src, $match ) ) ) + return false; + + foreach ( $files as $s => $f ) { + foreach ( $f as $k => $v ) { + if ( $key == $k ) { + $extension = '.' . end( explode( '.', $v ) ); + + if ( !@rename( $abs . $v, $abs . $filename . $hash . $extension ) ) { + if ( !@rename( $tabs . $v, $tabs . $filename . $hash . '-' . $s . $extension ) ) + $output[ $k ] = $v; + else + $files[ $s ][ $k ] = $filename . $hash . '-' . $s . $extension; + } else + $files[ $s ][ $k ] = $filename . $hash . $extension; + } + } + } + + natcasesort( $files[ 'full' ] ); + + $this->bind( $id, $type, $files ); + + if ( $output ) + return $output; + else + return true; + } + + /** + * Regenerates the thumbnails associated with an object. + * + * @package webcomic + * @since 3 + * + * @param int $id ID of the object to fetch files from. + * @param str $type The type of object to fetch for. Must be one of 'collection', 'storyline', 'character', 'post', or 'orphan'. + * @param str $src The directory to search when fetch files for 'orphan' type objects. + * @param int $key The key that points to the file associated with the specified object. If not specified, all file thumbnails are regenerated. + * @return bool|arr True on success, false if no files can be found. Array of files that could not be regenerated on error. + */ + function regen( $id, $type, $src, $key = false ) { + $match = ( 'post' == $type || 'orphan' == $type ) ? true : false; + + if ( !( $files = $this->fetch( $id, $type, $src, $match ) ) ) + return false; + + $i = 0; + $abs = $this->directory( 'abs', $src ); + $tabs = $abs . 'thumbs/'; + $lw = $this->option( 'large_w' ); + $lh = $this->option( 'large_h' ); + $mw = $this->option( 'medium_w' ); + $mh = $this->option( 'medium_h' ); + $sw = $this->option( 'small_w' ); + $sh = $this->option( 'small_h' ); + + foreach ( $files as $s => $f ) { + foreach ( $f as $k => $v ) { + if ( false !== $key && $key != $k ) + continue; + + if ( @unlink( $tabs . $v ) ) + unset( $files[ $s ][ $k ] ); + } + } + + foreach ( $files[ 'full' ] as $k => $v ) { + if ( ( false !== $key && $key != $k ) || !is_array( $data = @getimagesize( $abs . $v ) ) || !( 'image/jpeg' == $data[ 'mime' ] || 'image/gif' == $data[ 'mime' ] || 'image/png' == $data[ 'mime' ] ) ) + continue; + + $i++; + + if ( $data[ 0 ] > $lw || $data[ 1 ] > $lh ) + if ( $large = $this->resize( $abs . $v, $lw, $lh, 0, 'large', $tabs ) ) + $files[ 'large' ][ $k ] = basename( $large ); + + if ( $data[ 0 ] > $mw || $data[ 1 ] > $mh ) + if ( $medium = $this->resize( $abs . $v, $mw, $mh, 0, 'medium', $tabs ) ) + $files[ 'medium' ][ $k ] = basename( $medium ); + + if ( $data[ 0 ] > $sw || $data[ 1 ] > $sh ) + if ( $small = $this->resize( $abs . $v, $sw, $sh, 0, 'small', $tabs ) ) + $files[ 'small' ][ $k ] = basename( $small ); + } + + $this->bind( $id, $type, $files ); + + if ( $i && $key ) + return array( $files[ 'full' ][ $key ] ); + elseif ( $i ) + return $files[ 'full' ]; + else + return false; + } + + /** + * Deletes the files associated with an object. + * + * @package webcomic + * @since 3 + * + * @param int $id ID of the object to fetch files from. + * @param str $type The type of object to fetch for. Must be one of 'collection', 'storyline', 'character', 'post', or 'orphan'. + * @param str $src The directory to search when fetch files for 'orphan' type objects. + * @param int $key The key that points to the file associated with the specified object. If not specified, all files are deleted. + * @param str $size The size of the file to be deleted. Can be combined with $key to target a singular file in the files array. + * @return str|bool|arr String of comma-separated filenames on success, false if no files can be found. An array of filenames that could not be deleted on error. + */ + function delete( $id, $type, $src, $key = false, $size = false ) { + $match = ( 'post' == $type || 'orphan' == $type ) ? true : false; + + if ( !( $files = $this->fetch( $id, $type, $src, $match ) ) ) + return false; + + $abs = $this->directory( 'abs', $src ); + $tabs = $abs . 'thumbs/'; + $names = array(); + $output = array(); + + foreach ( $files as $s => $f ) { + if ( false !== $size && $size != $s ) + continue; + + foreach ( $f as $k => $v ) { + if ( false !== $key && $key != $k ) + continue; + + if ( !@unlink( $abs . $v ) ) { + if ( !@unlink( $tabs . $v ) ) + array_push( $output, $file ); + else + unset( $files[ $s ][ $k ] ); + } else { + array_push( $names, $files[ $s ][ $k ] ); + unset( $files[ $s ][ $k ] ); + } + } + + if ( empty( $files[ $s ] ) ) + unset( $files[ $s ] ); + } + + $this->bind( $id, $type, $files ); + + if ( $output ) + return $output; + else + return implode( ', ', $names ); + } + + + + //// + // Administration Pages + // + // These functions display the various Webcomic + // related administrative pages and should never + // be called directly. + //// + + /** + * Displays the post and file management pages. + * + * @package webcomic + * @since 3 + */ + function admin_files() { + $this->domain(); + + global $current_user, $wpdb; + + $wc = ( !empty( $_REQUEST[ 'webcomic_collection' ] ) ) ? get_term( $_REQUEST[ 'webcomic_collection' ], 'webcomic_collection' ) : get_term( ( int ) $this->option( 'default_collection' ), 'webcomic_collection' ); + $wcs = ( !empty( $_REQUEST[ 'webcomic_storyline' ] ) ) ? '&webcomic_storyline=' . $_REQUEST[ 'webcomic_storyline' ] : ''; + $wcc = ( !empty( $_REQUEST[ 'webcomic_character' ] ) ) ? '&webcomic_character=' . $_REQUEST[ 'webcomic_character' ] : ''; + $sub = ( !empty( $_REQUEST[ 'subpage' ] ) ) ? '&subpage=' . $_REQUEST[ 'subpage' ] : ''; + $page = $_REQUEST[ 'page' ]; + $pagenum = ( !empty( $_REQUEST[ 'pagenum' ] ) ) ? $_REQUEST[ 'pagenum' ] : 1; + $hidden = get_hidden_columns( 'toplevel_page_webcomic_files' ); + $find = ( !empty( $_REQUEST[ 's' ] ) ) ? '&s=' . $_REQUEST[ 's' ] : ''; + $view = '?page=' . $page . '&webcomic_collection=' . $wc->term_id . $wcs . $wcc . $sub . $find; + + if ( 'webcomic_collection' != $page && ( !$wc || is_wp_error( $wc ) ) ) { + ?> +
    +
    icon
    +

    +

    create a collection before you go any further.", 'webcomic' ), admin_url( 'admin.php?page=webcomic_collection' ) ); ?>

    +
    + + +
    +
    icon
    +

    name ); ?>

    +
    + +
    + +
    +
    +

    + + + + + + + + + + + + + + + + > + + + + + +
    + retrieve( $this->directory( 'abs', $wc->slug ) . $f, 'orphan', $wc->slug ); + + if ( $new[ 'small' ] ) + echo $new[ 'small' ][ 0 ][ 'html' ]; + elseif ( $new[ 'medium' ] ) + echo $new[ 'medium' ][ 0 ][ 'html' ]; + elseif ( $new[ 'large' ] ) + echo $new[ 'large' ][ 0 ][ 'html' ]; + else + echo $new[ 'full' ][ 0 ][ 'html' ]; + ?> + +
    + +
    +
    +
    + +
    +
    +
    +
    +

    +

    + Add More.', 'webcomic' ), $z ); ?>

    +
    +

    + + + + +

    +
    +
    +
    +
    +
    +
    + + + +
    +
    icon
    +

    name ); ?>

    +
    + +
    +
    +
    + + + + + + + + + + + + + + + + + + + + > + + + + + + + +
    + name; + } else + $sterms = array( __( 'No Storylines', 'webcomic' ) ); + + echo implode( ', ', $sterms ); + ?> + + name; + } else + $cterms = array( __( 'No Characters', 'webcomic' ) ); + + echo implode( ', ', $cterms ); + ?> +
    +
    +
    +
    +
    +
    +
    + + +

    +
    +
    +
    + + + +

    CTRL or Command to select multiple storylines.', 'webcomic' ); ?>

    +
    +
    + + + +

    CTRL or Command to select multiple characters.', 'webcomic' ); ?>

    +
    +
    +
    + + +
    +
    + + +
    +
    + + +
    +
    + + +
    +
    + + +
    +
    + + +
    +
    + + +
    +

    + + + + +

    +
    +
    +
    +
    + +
    +
    + + + +
    +
    icon
    +

    name ); ?>

    +
    + +
    +
    +
    + + + + + + + + + + + + + + + + + + > + + + + + + +
    + retrieve( $bulk, 'orphan', $wc->slug ); + + if ( $orphan[ 'small' ] ) + echo $orphan[ 'small' ][ 0 ][ 'html' ]; + elseif ( $orphan[ 'medium' ] ) + echo $orphan[ 'medium' ][ 0 ][ 'html' ]; + elseif ( $orphan[ 'large' ] ) + echo $orphan[ 'large' ][ 0 ][ 'html' ]; + else + echo $orphan[ 'full' ][ 0 ][ 'html' ]; + ?> + +
    + +
    +
    +
    +
    +
    +
    +
    + + + , + +

    +
    +
    + + + +

    +
    +
    + +

    +
    +
    + +

    Start on… and Publish every… settings will be ignored.', 'webcomic' ); ?>

    +
    +

    + + + + +

    +
    +
    +
    +
    + +
    +
    + + ID, 'webcomic' ) ); + + if ( empty( $user_meta[ 'files_per_page' ] ) ) { + $user_meta[ 'files_per_page' ] = 20; + update_user_meta( $current_user->ID, 'webcomic', $user_meta ); + } elseif ( !empty( $_REQUEST[ 'webcomic_files_per_page' ] ) ) { + $user_meta[ 'files_per_page' ] = intval( $_REQUEST[ 'webcomic_files_per_page' ] ); + update_user_meta( $current_user->ID, 'webcomic', $user_meta ); + } + + $fpp = $user_meta[ 'files_per_page' ]; + + $abs = $this->directory( 'abs', $wc->slug ); + $url = $this->directory( 'url', $wc->slug ); + $tabs = $abs . 'thumbs/'; + $turl = $url . 'thumbs/'; + $files = glob( $abs . '*.*' ); + $posts = get_objects_in_term( $wc->term_id, 'webcomic_collection' ); + $orphans = $matched = $count = array(); + $term_meta = $this->option( 'term_meta' ); + $post_object = get_post_type_object( 'webcomic_post' ); + + $count[ 'all' ] = $count[ 'future' ] = $count[ 'publish' ] = $count[ 'private' ] = $count[ 'pending' ] = $count[ 'draft' ] = $count[ 'trash' ] = $count[ 'orphaned' ] = $count[ 'matched' ] = 0; + + foreach ( $term_meta as $taxonomy ) + foreach ( $taxonomy as $term ) + if ( !empty( $term[ 'files' ] ) ) + foreach ( $term[ 'files' ][ 'full' ] as $k => $v ) + if ( false !== ( $key = array_search( $abs . $term[ 'files' ][ 'full' ][ $k ], $files ) ) ) + unset( $files[ $key ] ); + + foreach ( $posts as $k => $v ) { + if ( 'webcomic_post' != get_post_type( $v ) ) + continue; + + $status = get_post_status( $v ); + + if ( 'trash' != $status ) + $count[ 'all' ]++; + + switch( $status ) { + case 'future' : $count[ 'future' ]++; break; + case 'publish': $count[ 'publish' ]++; break; + case 'private': $count[ 'private' ]++; break; + case 'pending': $count[ 'pending' ]++; break; + case 'draft' : $count[ 'draft' ]++; break; + case 'trash' : $count[ 'trash' ]++; break; + } + + $post_meta = current( get_post_meta( $v, 'webcomic' ) ); + $post_files = $this->fetch( $v, 'post', $wc->slug, true ); + + if ( empty( $post_files ) && 'trash' != $status ) { + array_push( $orphans, $v ); + $count[ 'orphaned' ]++; + } elseif ( !empty( $post_files ) ) { + if ( empty( $post_meta[ 'files' ] ) && 'trash' != $status ) { + array_push( $matched, $v ); + $count[ 'matched' ]++; + } + + foreach ( $post_files[ 'full' ] as $f ) { + $fk = array_search( $abs . $f, $files ); + unset( $files[ $fk ] ); + } + } + } + + if ( !empty( $_REQUEST[ 'webcomic_storyline' ] ) ) { + $a = get_objects_in_term( $_REQUEST[ 'webcomic_storyline' ], 'webcomic_storyline' ); + $posts = array_intersect( $posts, $a ); + } + + if ( !empty( $_REQUEST[ 'webcomic_character' ] ) ) { + $a = get_objects_in_term( $_REQUEST[ 'webcomic_character' ], 'webcomic_character' ); + $posts = array_intersect( $posts, $a ); + } + + $status = ( !empty( $_REQUEST[ 'subpage' ] ) && 'orphaned' != $_REQUEST[ 'subpage' ] && 'matched' != $_REQUEST[ 'subpage' ] ) ? "p.post_status = '" . $_REQUEST[ 'subpage' ] . "'" : "p.post_status != 'trash'"; + $search = ( !empty( $_REQUEST[ 's' ] ) ) ? "AND ( ( p.post_title LIKE '%" . $wpdb->escape( $_REQUEST[ 's' ] ) . "%' ) OR ( p.post_content LIKE '%" . $wpdb->escape( $_REQUEST[ 's' ] ) . "%' ) OR ( p.post_excerpt LIKE '%" . $wpdb->escape( $_REQUEST[ 's' ] ) . "%' ) OR ( pm.meta_value LIKE '%" . $wpdb->escape( $_REQUEST[ 's' ] ) . "%' ) )" : ''; + $join = ( $search ) ? " LEFT JOIN $wpdb->postmeta AS pm ON p.ID = pm.post_id AND pm.meta_key = 'webcomic' " : ''; + + if ( isset( $_REQUEST[ 'subpage' ] ) && 'orphaned' == $_REQUEST[ 'subpage' ] ) + $posts = $orphans; + elseif ( isset( $_REQUEST[ 'subpage' ] ) && 'matched' == $_REQUEST[ 'subpage' ] ) + $posts = $matched; + + $author_posts = ( empty( $posts ) ) ? array() : $wpdb->get_col( "SELECT * FROM $wpdb->posts AS p $join WHERE p.ID IN (" . implode( ',', $posts ) . ") AND p.post_type = 'webcomic_post' AND p.post_status != 'trash' AND p.post_author = " . $current_user->ID . " $search ORDER BY post_date DESC" ); + + $count[ 'mine' ] = count( $author_posts ); + + $posts = ( ( isset( $_REQUEST[ 'subpage' ] ) && 'mine' == $_REQUEST[ 'subpage' ] ) || empty( $posts ) ) ? $author_posts : $wpdb->get_col( "SELECT * FROM $wpdb->posts AS p $join WHERE p.ID IN (" . implode( ',', $posts ) . ") AND p.post_type = 'webcomic_post' AND $status $search ORDER BY post_date DESC" ); + + foreach ( $posts as $k => $v ) + $posts[ $k ] = ( object ) array( 'ID' => $v, 'post_parent' => 0 ); + + $max_post = ( count( $posts ) < ( $pagenum * $fpp ) ) ? count( $posts ) : $pagenum * $fpp; + ?> + +
    +
    icon
    +

    labels->name, $wc->name ); ?> labels->add_new; ?>

    +
    + +
    +
    + + + +
    +
    $fpp ) printf( __( 'Displaying %1$d – %2$d of %3$d', 'webcomic' ) , ( ( $pagenum - 1 ) * $fpp + 1 ), $max_post, count( $posts ) ); ?> 'admin.php' . $view . '%_%', 'format' => '&pagenum=%#%', 'prev_text' => __( '«', 'webcomic' ), 'next_text' => __( '»', 'webcomic' ), 'total' => ceil ( count( $posts ) / $fpp ), 'current' => $pagenum ) ); ?>
    +
    + + + + + + +
    +
    + + + + + paged_walk( $posts, 0, $pagenum, $fpp, array( 'hidden' => $hidden, 'view' => $view, 'src' => $wc->slug ) ); + ?> + +
    +
    +
    $fpp ) printf( __( 'Displaying %1$d – %2$d of %3$d', 'webcomic' ) , ( ( $pagenum - 1 ) * $fpp + 1 ), $max_post, count( $posts ) ); ?> 'admin.php' . $view . '%_%', 'format' => '&pagenum=%#%', 'prev_text' => __( '«', 'webcomic' ), 'next_text' => __( '»', 'webcomic' ), 'total' => ceil ( count( $posts ) / $fpp ), 'current' => $pagenum ) ); ?>
    +
    + + + + + + +
    +
    + +
    +


    +
    + +
    +
    +
    + + + + + +
    +
    + + $cols ) { + ?> + + $file ) { + $class = array( 'available-theme' ); + + if ( $row == 1 ) $class[] = 'top'; + if ( $row == $rows ) $class[] = 'bottom'; + if ( $col == 1 ) $class[] = 'left'; + if ( $col == 3 ) $class[] = 'right'; + if ( !$term ) { echo ''; continue; } + ?> + + + + +
    + + +
    + + + +
    + | + ')){return true;}return false;"> | + + +
    +
    + +
    +

    labels->not_found_in_trash : $post_object->labels->not_found; ?>

    + +
    + + domain(); + + global $current_user; + + $wc = ( !empty( $_REQUEST[ 'webcomic_collection' ] ) ) ? get_term( $_REQUEST[ 'webcomic_collection' ], 'webcomic_collection' ) : get_term( ( int ) $this->option( 'default_collection' ), 'webcomic_collection' ); + $page = $_REQUEST[ 'page' ]; + $pagenum = ( !empty( $_REQUEST[ 'pagenum' ] ) ) ? $_REQUEST[ 'pagenum' ] : 1; + $hidden = get_hidden_columns( 'webcomic_page_' . $page ); + $find = ( !empty( $_REQUEST[ 's' ] ) ) ? '&s=' . $_REQUEST[ 's' ] : ''; + $view = ( 'webcomic_collection' == $page ) ? '?page=' . $page : '?page=' . $page . '&webcomic_collection=' . $wc->term_id . $find; + $img_field = ( 'webcomic_character' == $page ) ? __( 'avatar', 'webcomic' ) : __( 'cover', 'webcomic' ); + $taxonomy = get_taxonomy( $page ); + + $user_meta = current( get_user_meta( $current_user->ID, 'webcomic' ) ); + + if ( empty( $user_meta[ $page . '_per_page' ] ) ) { + $user_meta[ $page . '_per_page' ] = 20; + update_user_meta( $current_user->ID, 'webcomic', $user_meta ); + } elseif ( !empty( $_REQUEST[ $page . '_per_page' ] ) ) { + $user_meta[ $page . '_per_page' ] = intval( $_REQUEST[ $page . '_per_page' ] ); + update_user_meta( $current_user->ID, 'webcomic', $user_meta ); + } + + $tpp = $user_meta[ $page . '_per_page' ]; + + if ( $current_user->data->rich_editing ) { + $tinymce_width = ( !empty( $_REQUEST[ 'subpage' ] ) ) ? '460px' : '100%'; + wp_tiny_mce( false, array( 'editor_selector' => 'webcomic_tinymce', 'width' => $tinymce_width, 'theme_advanced_buttons1' => implode( ',', array( 'bold', 'italic', '|', 'bullist', 'numlist', 'blockquote', '|', 'link', 'unlink', '|', 'charmap', 'spellchecker', 'fullscreen', 'wp_adv' ) ), 'theme_advanced_buttons2' => implode( ',', array( 'formatselect', '|', 'justifyleft', 'justifycenter', 'justifyright', 'justifyfull', '|', 'sub', 'sup', '|', 'removeformat', 'code' ) ) ) ); + } + + if ( 'webcomic_collection' != $page && ( !$wc || is_wp_error( $wc ) ) ) { + ?> +
    +
    icon
    +

    +

    create a collection before you go any further.", 'webcomic' ), admin_url( 'admin.php?page=webcomic_collection' ) ); ?>

    +
    + + +
    +
    icon
    +

    labels->edit_item; ?>

    +
    + +
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    + + +

    + webcomic_files ) ) { foreach ( $term->webcomic_files[ 'full' ] as $k => $v ) { ?> + + +
    + webcomic_files[ 'large' ][ $k ] ) ) + $s[] = __( 'large', 'webcomic' ); + if ( isset( $term->webcomic_files[ 'medium' ][ $k ] ) ) + $s[] = __( 'medium', 'webcomic' ); + if ( isset( $term->webcomic_files[ 'small' ][ $k ] ) ) + $s[] = __( 'small', 'webcomic' ); + + if ( 1 < count( $s ) ) + printf( __( '%s sizes available', 'webcomic' ), ucfirst( substr_replace( implode( ', ', $s ), __( ' and', 'webcomic' ), strrpos( implode( ', ', $s ), ',' ), 1 ) ) ); + elseif ( !empty( $s ) ) + printf( __( '%s size available', 'webcomic' ), ucfirst( current( $s ) ) ); + else + _e( 'No thumbnail sizes available', 'webcomic' ); + + echo ' | ' . __( 'Edit', 'webcomic' ) . ''; + } } + ?> +
    +
    + labels->singular_name ) ); ?> +
    +
    + +
    +
    + labels->singular_name ) ); ?> +
    + +
    + +
    + labels->singular_name ) ); ?> +
    +
    + labels->name, strtolower( $taxonomy->labels->singular_name ), strtolower( $taxonomy->labels->name ) ); ?> +
    +
    + labels->singular_name ) ); ?> +
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    + option( 'paypal_price_d' ) ); ?> + + % = + price( $this->option( 'paypal_price_d' ), array( $term->webcomic_paypal[ 'price_d' ] ) ), $this->option( 'paypal_currency' ) ); ?> + + option( 'paypal_shipping_d' ) ); ?> + + % = + price( $this->option( 'paypal_shipping_d' ), array( $term->webcomic_paypal[ 'shipping_d' ] ) ), $this->option( 'paypal_currency' ) ); ?> +
    + option( 'paypal_price_i' ) ); ?> + + % = + price( $this->option( 'paypal_price_i' ), array( $term->webcomic_paypal[ 'price_i' ] ) ), $this->option( 'paypal_currency' ) ); ?> + + option( 'paypal_shipping_i' ) ); ?> + + % = + price( $this->option( 'paypal_shipping_i' ), array( $term->webcomic_paypal[ 'shipping_i' ] ) ), $this->option( 'paypal_currency' ) ); ?> +
    + option( 'paypal_price_o' ) ); ?> + + % = + price( $this->option( 'paypal_price_o' ), array( $term->webcomic_paypal[ 'price_o' ] ) ), $this->option( 'paypal_currency' ) ); ?> + + option( 'paypal_shipping_o' ) ); ?> + + % = + price( $this->option( 'paypal_shipping_o' ), array( $term->webcomic_paypal[ 'shipping_o' ] ) ), $this->option( 'paypal_currency' ) ); ?> +
    + labels->singular_name ) ); ?> + +
    +
    +

    + + + + + + +

    +
    +
    + term_id : ''; $terms = get_terms( $page, 'hide_empty=0&webcomic_order=' . $wco . $tg . $search ); $num_term = count( get_terms( $page, 'hide_empty=0&parent=0&term_group=' . $wc->term_id ) ); $max_term = ( $num_term < ( $pagenum * $tpp ) ) ? $num_term : $pagenum * $tpp; ?> + +
    +
    icon
    +

    + labels->name; + else + printf( __( '%s in %s', 'webcomic' ), $taxonomy->labels->name, $wc->name ); + ?> +

    +
    + +
    +
    +
    +
    + +

    name, strtolower( $taxonomy->labels->name ) ); ?>

    + +

    + +
    + +
    +
    'admin.php' . $view . '%_%', 'format' => '&pagenum=%#%', 'prev_text' => __( '«', 'webcomic' ), 'next_text' => __( '»', 'webcomic' ), 'total' => ceil ( $num_term / $tpp ), 'current' => $pagenum ) ); ?>
    +
    + + +
    +
    + + + + + paged_walk( $terms, 0, $pagenum, $tpp, array( 'hidden' => $hidden, 'view' => $view, 'page' => $page ) ); + ?> + +
    +
    +
    $tpp ) printf( __( 'Displaying %1$d – %2$d of %3$d', 'webcomic' ) , ( ( $pagenum - 1 ) * $tpp + 1 ), $max_term, $num_term ); ?> 'admin.php' . $view . '%_%', 'format' => '&pagenum=%#%', 'prev_text' => __( '«', 'webcomic' ), 'next_text' => __( '»', 'webcomic' ), 'total' => ceil ( $num_term / $tpp ), 'current' => $pagenum ) ); ?>
    +
    + + + + +
    +
    +
    + +
    +
    +
    +
    +
    +

    +
    + +
    + + +

    +
    +
    + + +

    labels->singular_name ) ); ?>

    +
    +
    + + +

    +
    + +
    + + +

    labels->name, strtolower( $taxonomy->labels->singular_name ), strtolower( $taxonomy->labels->name ) ); ?>

    +
    + + + +
    + + +

    labels->singular_name ) ); ?>

    +
    +

    + + + +

    +
    +
    +
    +
    +
    +
    + + domain(); + + $page = $_REQUEST[ 'page' ]; + $subpage = ( !empty( $_REQUEST[ 'subpage' ] ) ) ? $_REQUEST[ 'subpage' ] : ''; + $subview = ( $subpage ) ? '&subpage=' . $subpage : ''; + $view = '?page=' . $page . $subview; + + if ( $subpage && 'edit_files' == $_REQUEST[ 'subpage' ] ) { + $match = ( 'post' == $_REQUEST[ 'type' ] ) ? true : false; + $files = $this->retrieve( $_REQUEST[ 'id' ], $_REQUEST[ 'type' ], $_REQUEST[ 'src' ], $match ); + $referer = ( !empty( $_REQUEST[ 'referer' ] ) ) ? $_REQUEST[ 'referer' ] : $_SERVER[ 'HTTP_REFERER' ]; + + if ( $files ) { + $file = array(); + $file[ 'full' ] = ( !empty( $files[ 'full' ][ $_REQUEST[ 'key' ] ] ) ) ? $files[ 'full' ][ $_REQUEST[ 'key' ] ] : array(); + $file[ 'large' ] = ( !empty( $files[ 'large' ][ $_REQUEST[ 'key' ] ] ) ) ? $files[ 'large' ][ $_REQUEST[ 'key' ] ] : array(); + $file[ 'medium' ] = ( !empty( $files[ 'medium' ][ $_REQUEST[ 'key' ] ] ) ) ? $files[ 'medium' ][ $_REQUEST[ 'key' ] ] : array(); + $file[ 'small' ] = ( !empty( $files[ 'small' ][ $_REQUEST[ 'key' ] ] ) ) ? $files[ 'small' ][ $_REQUEST[ 'key' ] ] : array(); + ?> +
    +
    icon
    +

    +
    + + + + $v ) { + if ( 'full' == $k ) + $s = __( 'full', 'webcomic' ); + if ( 'large' == $k ) + $s = __( 'large', 'webcomic' ); + if ( 'medium' == $k ) + $s = __( 'medium', 'webcomic' ); + if ( 'small' == $k ) + $s = __( 'small', 'webcomic' ); + ?> + + + + + + +
    + + + +

    + +

    + + +

    + +

    +

    + + + +

    + +
    +
    + +
    +
    icon
    +

    +
    +
    +
    + +

    version ); ?>

    +

    +
      + 0 ) echo ' style="color:#008000;text-decoration:line-through";'; ?>> + 1 ) echo ' style="color:#008000;text-decoration:line-through";'; ?>> + 2 ) echo ' style="color:#008000;text-decoration:line-through";'; ?>> + 3 ) echo ' style="color:#008000;text-decoration:line-through";'; ?>> + 4 ) echo ' style="color:#008000;text-decoration:line-through";'; ?>> +
    1. +
    +

    +
      +
    1. %s', 'webcomic' ), $this->directory( 'url' ), $this->directory( 'url' ) ); ?>
    2. +
    3. official Webcomic-ready themes", "webcomic" ), $this->version, 'http://webcomicms.net/support/manual/themes/' ); ?>
    4. +
    +

    +

    backup all of your data before proceeding.', 'webcomic' ), admin_url( 'export.php' ) ); ?>

    +

    + + + + + + version ); else printf( __( 'Continue with Step %d »', 'webcomic' ), $_REQUEST[ 'step' ] ); ?> +

    + +

    +
      +
    1. %s', 'webcomic' ), $this->directory( 'url' ), $this->directory( 'url' ) ); ?>
    2. +
    3. official Webcomic-ready themes", "webcomic" ), $this->version, 'http://webcomicms.net/support/manual/themes/' ); ?>
    4. +
    +

    + +
    +
    +
    +
    + option( 'uninstall' ) ) { ?> +
    +
    icon
    +

    +
    +
    +
    + option( 'uninstall' ) ) { ?> +

    +
      +
    1. +
    2. +
    3. +
    4. +
    5. +
    +

    %s.', 'webcomic' ), $this->directory( 'url' ), $this->directory( 'url' ) ); ?>

    +

    +

    + + +

    + +

    +

    deactivate the plugin and delete the Webcomic directory at %s to complete the uninstallation.', 'webcomic' ), admin_url( 'plugins.php' ), $this->directory( 'url' ), $this->directory( 'url' ) ); ?>

    + +
    +
    +
    +
    + +
    +
    icon
    +

    + + + + + + + option( 'uninstall' ) ) { ?> + > + + + + +
    +
    + domain(); + + $languages = array( 'aa' => __( 'Afar', 'webcomic' ), 'ab' => __( 'Abkhazian', 'webcomic' ), 'ae' => __( 'Avestan', 'webcomic' ), 'af' => __( 'Afrikaans', 'webcomic' ), 'ak' => __( 'Akan', 'webcomic' ), 'am' => __( 'Amharic', 'webcomic' ), 'an' => __( 'Aragonese', 'webcomic' ), 'ar' => __( 'Arabic', 'webcomic' ), 'as' => __( 'Assamese', 'webcomic' ), 'av' => __( 'Avaric', 'webcomic' ), 'ay' => __( 'Aymara', 'webcomic' ), 'az' => __( 'Azerbaijani', 'webcomic' ), 'ba' => __( 'Bashkir', 'webcomic' ), 'be' => __( 'Belarusian', 'webcomic' ), 'bg' => __( 'Bulgarian', 'webcomic' ), 'bh' => __( 'Bihari', 'webcomic' ), 'bi' => __( 'Bislama', 'webcomic' ), 'bm' => __( 'Bambara', 'webcomic' ), 'bn' => __( 'Bengali', 'webcomic' ), 'bo' => __( 'Tibetan', 'webcomic' ), 'br' => __( 'Breton', 'webcomic' ), 'bs' => __( 'Bosnian', 'webcomic' ), 'ca' => __( 'Catalan', 'webcomic' ), 'ce' => __( 'Chechen', 'webcomic' ), 'ch' => __( 'Chamorro', 'webcomic' ), 'co' => __( 'Corsican', 'webcomic' ), 'cr' => __( 'Cree', 'webcomic' ), 'cs' => __( 'Czech', 'webcomic' ), 'cu' => __( 'Church Slavic', 'webcomic' ), 'cv' => __( 'Chuvash', 'webcomic' ), 'cy' => __( 'Welsh', 'webcomic' ), 'da' => __( 'Danish', 'webcomic' ), 'de' => __( 'German', 'webcomic' ), 'dv' => __( 'Divehi', 'webcomic' ), 'dz' => __( 'Dzongkha', 'webcomic' ), 'ee' => __( 'Ewe', 'webcomic' ), 'el' => __( 'Greek', 'webcomic' ), 'en' => __( 'English', 'webcomic' ), 'eo' => __( 'Esperanto', 'webcomic' ), 'es' => __( 'Spanish', 'webcomic' ), 'et' => __( 'Estonian', 'webcomic' ), 'eu' => __( 'Basque', 'webcomic' ), 'fa' => __( 'Persian', 'webcomic' ), 'ff' => __( 'Fulah', 'webcomic' ), 'fi' => __( 'Finnish', 'webcomic' ), 'fj' => __( 'Fijian', 'webcomic' ), 'fo' => __( 'Faroese', 'webcomic' ), 'fr' => __( 'French', 'webcomic' ), 'fy' => __( 'Western Frisian', 'webcomic' ), 'ga' => __( 'Irish', 'webcomic' ), 'gd' => __( 'Scottish Gaelic', 'webcomic' ), 'gl' => __( 'Galician', 'webcomic' ), 'gn' => __( 'Guarani', 'webcomic' ), 'gu' => __( 'Gujarati', 'webcomic' ), 'gv' => __( 'Manx', 'webcomic' ), 'ha' => __( 'Hausa', 'webcomic' ), 'he' => __( 'Hebrew', 'webcomic' ), 'hi' => __( 'Hindi', 'webcomic' ), 'ho' => __( 'Hiri Motu', 'webcomic' ), 'hr' => __( 'Croatian', 'webcomic' ), 'ht' => __( 'Haitian', 'webcomic' ), 'hu' => __( 'Hungarian', 'webcomic' ), 'hy' => __( 'Armenian', 'webcomic' ), 'hz' => __( 'Herero', 'webcomic' ), 'ia' => __( 'Interlingua', 'webcomic' ), 'id' => __( 'Indonesian', 'webcomic' ), 'ie' => __( 'Interlingue', 'webcomic' ), 'ig' => __( 'Igbo', 'webcomic' ), 'ii' => __( 'Sichuan Yi', 'webcomic' ), 'ik' => __( 'Inupiaq', 'webcomic' ), 'io' => __( 'Ido', 'webcomic' ), 'is' => __( 'Icelandic', 'webcomic' ), 'it' => __( 'Italian', 'webcomic' ), 'iu' => __( 'Inuktitut', 'webcomic' ), 'ja' => __( 'Japanese', 'webcomic' ), 'jv' => __( 'Javanese', 'webcomic' ), 'ka' => __( 'Georgian', 'webcomic' ), 'kg' => __( 'Kongo', 'webcomic' ), 'ki' => __( 'Kikuyu', 'webcomic' ), 'kj' => __( 'Kwanyama', 'webcomic' ), 'kk' => __( 'Kazakh', 'webcomic' ), 'kl' => __( 'Kalaallisut', 'webcomic' ), 'km' => __( 'Khmer', 'webcomic' ), 'kn' => __( 'Kannada', 'webcomic' ), 'ko' => __( 'Korean', 'webcomic' ), 'kr' => __( 'Kanuri', 'webcomic' ), 'ks' => __( 'Kashmiri', 'webcomic' ), 'ku' => __( 'Kurdish', 'webcomic' ), 'kv' => __( 'Komi', 'webcomic' ), 'kw' => __( 'Cornish', 'webcomic' ), 'ky' => __( 'Kirghiz', 'webcomic' ), 'la' => __( 'Latin', 'webcomic' ), 'lb' => __( 'Luxembourgish', 'webcomic' ), 'lg' => __( 'Ganda', 'webcomic' ), 'li' => __( 'Limburgish', 'webcomic' ), 'ln' => __( 'Lingala', 'webcomic' ), 'lo' => __( 'Lao', 'webcomic' ), 'lt' => __( 'Lithuanian', 'webcomic' ), 'lu' => __( 'Luba-Katanga', 'webcomic' ), 'lv' => __( 'Latvian', 'webcomic' ), 'mg' => __( 'Malagasy', 'webcomic' ), 'mh' => __( 'Marshallese', 'webcomic' ), 'mi' => __( 'Maori', 'webcomic' ), 'mk' => __( 'Macedonian', 'webcomic' ), 'ml' => __( 'Malayalam', 'webcomic' ), 'mn' => __( 'Mongolian', 'webcomic' ), 'mr' => __( 'Marathi', 'webcomic' ), 'ms' => __( 'Malay', 'webcomic' ), 'mt' => __( 'Maltese', 'webcomic' ), 'my' => __( 'Burmese', 'webcomic' ), 'na' => __( 'Nauru', 'webcomic' ), 'nb' => __( 'Norwegian Bokmal', 'webcomic' ), 'nd' => __( 'North Ndebele', 'webcomic' ), 'ne' => __( 'Nepali', 'webcomic' ), 'ng' => __( 'Ndonga', 'webcomic' ), 'nl' => __( 'Dutch', 'webcomic' ), 'nn' => __( 'Norwegian Nynorsk', 'webcomic' ), 'no' => __( 'Norwegian', 'webcomic' ), 'nr' => __( 'South Ndebele', 'webcomic' ), 'nv' => __( 'Navajo', 'webcomic' ), 'ny' => __( 'Chichewa', 'webcomic' ), 'oc' => __( 'Occitan', 'webcomic' ), 'oj' => __( 'Ojibwa', 'webcomic' ), 'om' => __( 'Oromo', 'webcomic' ), 'or' => __( 'Oriya', 'webcomic' ), 'os' => __( 'Ossetian', 'webcomic' ), 'pa' => __( 'Panjabi', 'webcomic' ), 'pi' => __( 'Pali', 'webcomic' ), 'pl' => __( 'Polish', 'webcomic' ), 'ps' => __( 'Pashto', 'webcomic' ), 'pt' => __( 'Portuguese', 'webcomic' ), 'qu' => __( 'Quechua', 'webcomic' ), 'rm' => __( 'Raeto-Romance', 'webcomic' ), 'rn' => __( 'Kirundi', 'webcomic' ), 'ro' => __( 'Romanian', 'webcomic' ), 'ru' => __( 'Russian', 'webcomic' ), 'rw' => __( 'Kinyarwanda', 'webcomic' ), 'sa' => __( 'Sanskrit', 'webcomic' ), 'sc' => __( 'Sardinian', 'webcomic' ), 'sd' => __( 'Sindhi', 'webcomic' ), 'se' => __( 'Northern Sami', 'webcomic' ), 'sg' => __( 'Sango', 'webcomic' ), 'si' => __( 'Sinhala', 'webcomic' ), 'sk' => __( 'Slovak', 'webcomic' ), 'sl' => __( 'Slovenian', 'webcomic' ), 'sm' => __( 'Samoan', 'webcomic' ), 'sn' => __( 'Shona', 'webcomic' ), 'so' => __( 'Somali', 'webcomic' ), 'sq' => __( 'Albanian', 'webcomic' ), 'sr' => __( 'Serbian', 'webcomic' ), 'ss' => __( 'Swati', 'webcomic' ), 'st' => __( 'Southern Sotho', 'webcomic' ), 'su' => __( 'Sundanese', 'webcomic' ), 'sv' => __( 'Swedish', 'webcomic' ), 'sw' => __( 'Swahili', 'webcomic' ), 'ta' => __( 'Tamil', 'webcomic' ), 'te' => __( 'Telugu', 'webcomic' ), 'tg' => __( 'Tajik', 'webcomic' ), 'th' => __( 'Thai', 'webcomic' ), 'ti' => __( 'Tigrinya', 'webcomic' ), 'tk' => __( 'Turkmen', 'webcomic' ), 'tl' => __( 'Tagalog', 'webcomic' ), 'tn' => __( 'Tswana', 'webcomic' ), 'to' => __( 'Tonga', 'webcomic' ), 'tr' => __( 'Turkish', 'webcomic' ), 'ts' => __( 'Tsonga', 'webcomic' ), 'tt' => __( 'Tatar', 'webcomic' ), 'tw' => __( 'Twi', 'webcomic' ), 'ty' => __( 'Tahitian', 'webcomic' ), 'ug' => __( 'Uighur', 'webcomic' ), 'uk' => __( 'Ukrainian', 'webcomic' ), 'ur' => __( 'Urdu', 'webcomic' ), 'uz' => __( 'Uzbek', 'webcomic' ), 've' => __( 'Venda', 'webcomic' ), 'vi' => __( 'Vietnamese', 'webcomic' ), 'vo' => __( 'Volapuk', 'webcomic' ), 'wa' => __( 'Walloon', 'webcomic' ), 'wo' => __( 'Wolof', 'webcomic' ), 'xh' => __( 'Xhosa', 'webcomic' ), 'yi' => __( 'Yiddish', 'webcomic' ), 'yo' => __( 'Yoruba', 'webcomic' ), 'za' => __( 'Zhuang', 'webcomic' ), 'zh' => __( 'Chinese', 'webcomic' ), 'zu' => __( 'Zulu', 'webcomic' ) ); + + natcasesort( $languages ); + ?> +
    +
    icon
    +

    +
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    option( 'age_toggle' ) ) echo ' checked'; ?>>
    option( 'buffer_toggle' ) ) echo ' checked'; ?>>
    option( 'feed_toggle' ) ) echo ' checked'; ?>> +
    +

    +

    Ctrl or Command to select multiple languages.', 'webcomic' ); ?>

    +
    option( 'transcribe_toggle' ) ) echo ' checked'; ?>> +

    + + +

    +
    +

    +

    + + + + + + + + + + + + + +
    ×
    ×
    ×
    +

    +

    + + + + + + + + + + + + + +
    + + Get a PayPal Account', 'webcomic' ), 'http://paypal.com/' ); ?>
    + +
    +

    + + + + + + + + + + + + + +
    + option( 'paypal_prints' ) ) echo ' checked'; ?>> + +
    +   +   + +
    +   +   + +
    +

    + + + + + +
    + +
    +

    + Donate | Webcomic %s', 'webcomic' ), 'https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=R6SH66UF6F9DG', $this->option( 'version' ) ); ?> + +

    +
    +
    + domain(); + + global $current_user; + + $wc = $ids = $post_meta = false; + + if ( is_object_in_term( $post->ID, 'webcomic_collection' ) ) { + $ids = true; + $wc = current( wp_get_object_terms( $post->ID, 'webcomic_collection' ) ); + $post_meta = current( get_post_meta( $post->ID, 'webcomic' ) ); + } elseif ( !empty( $_REQUEST[ 'webcomic_collection' ] ) ) + $wc = get_term( $_REQUEST[ 'webcomic_collection' ], 'webcomic_collection' ); + ?> + +
    + + + + + + + + +
    +
    + ' . __( 'Select a collection to make this a webcomic post.', 'webcomic' ) . '

    '; + else + echo '

    ' . __( 'Hold Ctrl or Command to select multiple storylines and characters.', 'webcomic' ) . '

    '; + ?> +
    + +
    + + +
    + +
    + + +
    + +
    + directory( 'abs', $wc->slug ); + $url = $this->directory( 'url', $wc->slug ); + $tabs = $abs . 'thumbs/'; + $turl = $url . 'thumbs/'; + $files = glob( $abs . '*.*' ); + $posts = get_objects_in_term( $wc->term_id, 'webcomic_collection' ); + $term_meta = $this->option( 'term_meta' ); + + foreach ( $term_meta as $taxonomy ) + foreach ( $taxonomy as $term ) + if ( !empty( $term[ 'files' ] ) ) + foreach ( $term[ 'files' ][ 'full' ] as $k => $v ) + if ( false !== ( $key = array_search( $abs . $term[ 'files' ][ 'full' ][ $k ], $files ) ) ) + unset( $files[ $key ] ); + + foreach ( $posts as $k => $v ) { + if ( 'webcomic_post' != get_post_type( $v ) ) + continue; + + $status = get_post_status( $v ); + + $post_files = $this->fetch( $v, 'post', $wc->slug, true ); + + if ( !empty( $post_files ) ) + foreach ( $post_files[ 'full' ] as $f ) { + $fk = array_search( $abs . $f, $files ); + unset( $files[ $fk ] ); + } + } + + if ( $files ) { + ?> +

    + + $cols ) { + ?> + + $file ) { + $class = array( 'available-theme' ); + + if ( $row == 1 ) $class[] = 'top'; + if ( $row == $rows ) $class[] = 'bottom'; + if ( $col == 1 ) $class[] = 'left'; + if ( $col == 3 ) $class[] = 'right'; + if ( !$term ) { echo ''; continue; } + ?> + + + + +
    + + +
    + + +
    + retrieve( $post->ID, 'post', $wc->slug, true ); ?> +
    + + + + + + + + + + $v ) { ?> + + + + + + + + + + + + + + + + + +
    +

    +
    + + Add More.', 'webcomic' ), $z ); ?> +

    +

    + + + + +
    + '; + + if ( 1 < count( $s ) ) + printf( __( '%s sizes available', 'webcomic' ), ucfirst( substr_replace( implode( ', ', $s ), __( ' and', 'webcomic' ), strrpos( implode( ', ', $s ), ',' ), 1 ) ) ); + elseif ( !empty( $s ) ) + printf( __( '%s size available', 'webcomic' ), ucfirst( current( $s ) ) ); + else + _e( 'No thumbnail sizes available', 'webcomic' ); + + echo ' | ' . __( 'Edit', 'webcomic' ) . '

    '; + ?> +
    +
    +
    + +

    + + $v ) { + ?> + + + +
    + + + + + + + + +
    +
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    + price( $this->option( 'paypal_price_d' ), array( $wc->webcomic_paypal[ 'price_d' ] ) ) ); ?> + + % = + price( $this->option( 'paypal_price_d' ), array( $wc->webcomic_paypal[ 'price_d' ], $price_d ) ), $this->option( 'paypal_currency' ) ); ?> + + price( $this->option( 'paypal_shipping_d' ), array( $wc->webcomic_paypal[ 'shipping_d' ] ) ) ); ?> + + % = + price( $this->option( 'paypal_shipping_d' ), array( $wc->webcomic_paypal[ 'shipping_d' ], $shipping_d ) ), $this->option( 'paypal_currency' ) ); ?> +
    + price( $this->option( 'paypal_price_i' ), array( $wc->webcomic_paypal[ 'price_i' ] ) ) ); ?> + + % = + price( $this->option( 'paypal_price_i' ), array( $wc->webcomic_paypal[ 'price_i' ], $price_i ) ), $this->option( 'paypal_currency' ) ); ?> + + price( $this->option( 'paypal_shipping_i' ), array( $wc->webcomic_paypal[ 'shipping_i' ] ) ) ); ?> + + % = + price( $this->option( 'paypal_shipping_i' ), array( $wc->webcomic_paypal[ 'shipping_i' ], $shipping_i ) ), $this->option( 'paypal_currency' ) ); ?> +

    + price( $this->option( 'paypal_price_o' ), array( $wc->webcomic_paypal[ 'price_o' ] ) ) ); ?> + + % = + price( $this->option( 'paypal_price_o' ), array( $wc->webcomic_paypal[ 'price_o' ], $price_o ) ), $this->option( 'paypal_currency' ) ); ?> + + price( $this->option( 'paypal_shipping_o' ), array( $wc->webcomic_paypal[ 'shipping_o' ] ) ) ); ?> + + % = + price( $this->option( 'paypal_shipping_o' ), array( $wc->webcomic_paypal[ 'shipping_o' ], $shipping_o ) ), $this->option( 'paypal_currency' ) ); ?> +
    +
    +
    + + + + domain(); + + if ( empty( $_REQUEST[ 'webcomic_ajax' ] ) ) + return false; + elseif ( 'collection' == $_REQUEST[ 'webcomic_ajax' ] ) { + global $post; + + $wc = ( $_REQUEST[ 'webcomic_collection' ] ) ? get_term( $_REQUEST[ 'webcomic_collection' ], 'webcomic_collection' ) : false; + $ids = ( $_REQUEST[ 'post_ID' ] && is_object_in_term( $_REQUEST[ 'post_ID' ], 'webcomic_collection', $wc->term_id ) ) ? true : false; + ?> + +
    + Select a collection to make this a webcomic %s.

    ', 'webcomic' ), $_REQUEST[ 'post_type' ] ); + else + echo '

    ' . __( 'Hold Ctrl or Command to select multiple storylines and characters.', 'webcomic' ) . '

    '; + ?> + + + +
    + + + + + +
    + + + + + directory( 'abs', $wc->slug ); + $url = $this->directory( 'url', $wc->slug ); + $tabs = $abs . 'thumbs/'; + $turl = $url . 'thumbs/'; + $files = glob( $abs . '*.*' ); + $posts = get_objects_in_term( $wc->term_id, 'webcomic_collection' ); + $term_meta = $this->option( 'term_meta' ); + + foreach ( $term_meta as $taxonomy ) + foreach ( $taxonomy as $term ) + if ( !empty( $term[ 'files' ] ) ) + foreach ( $term[ 'files' ][ 'full' ] as $k => $v ) + if ( false !== ( $key = array_search( $abs . $term[ 'files' ][ 'full' ][ $k ], $files ) ) ) + unset( $files[ $key ] ); + + foreach ( $posts as $k => $v ) { + if ( 'webcomic_post' != get_post_type( $v ) ) + continue; + + $status = get_post_status( $v ); + + $post_files = $this->fetch( $v, 'post', $wc->slug, true ); + + if ( !empty( $post_files ) ) + foreach ( $post_files[ 'full' ] as $f ) { + $fk = array_search( $abs . $f, $files ); + unset( $files[ $fk ] ); + } + } + + if ( $files ) { + ?> +

    + + $cols ) { + ?> + + $file ) { + $class = array( 'available-theme' ); + + if ( $row == 1 ) $class[] = 'top'; + if ( $row == $rows ) $class[] = 'bottom'; + if ( $col == 1 ) $class[] = 'left'; + if ( $col == 3 ) $class[] = 'right'; + if ( !$term ) { echo ''; continue; } + ?> + + + + +
    + + +
    + + +
    + +
    + + + +

    CTRL or Command to select multiple storylines. Remove posts from all storylines by selecting “Replace” with no storylines selected.', 'webcomic' ); ?>

    +
    +
    + + + +

    CTRL or Command to select multiple characters. Remove posts from all characters by selecting “Replace” with no characters selected.', 'webcomic' ); ?>

    +
    + post_type && $current_user->data->rich_editing ) { + $mce_locale = ( '' == get_locale() ) ? 'en' : strtolower( substr( get_locale(), 0, 2 ) ); + ?> + + \ No newline at end of file diff --git a/webcomic-includes/icon-small.png b/webcomic-includes/icon-small.png new file mode 100644 index 0000000..0c54514 Binary files /dev/null and b/webcomic-includes/icon-small.png differ diff --git a/webcomic-includes/icon.png b/webcomic-includes/icon.png new file mode 100644 index 0000000..52d694d Binary files /dev/null and b/webcomic-includes/icon.png differ diff --git a/webcomic-includes/mgs-core.php b/webcomic-includes/mgs-core.php new file mode 100644 index 0000000..6165615 --- /dev/null +++ b/webcomic-includes/mgs-core.php @@ -0,0 +1,205 @@ +name ) $this->name = 'mgs_core'; + if ( !$this->version ) $this->version = 1; + if ( !$this->file ) $this->file = __FILE__; + if ( !$this->type ) $this->type = 'plugin'; + + $this->base = ( 'plugin' == $this->type ) ? plugin_basename( $this->file ) : dirname( $this->file ); + $this->cdir = ( is_multisite() ) ? trailingslashit( BLOGUPLOADDIR ) : trailingslashit( WP_CONTENT_DIR ); + $this->curl = ( is_multisite() ) ? trailingslashit( trailingslashit( get_bloginfo( 'url' ) ) . 'files' ) : trailingslashit( WP_CONTENT_URL ); + $this->update = array(); + $this->errors = array(); + $this->options = $this->option(); + + if ( 'plugin' == $this->type ) { + $this->dir = ( realpath( dirname( $this->file ) ) !== realpath( WPMU_PLUGIN_DIR ) ) ? trailingslashit( trailingslashit( WP_PLUGIN_DIR ) . dirname( $this->base ) ) : trailingslashit( trailingslashit( WPMU_PLUGIN_DIR ) ); + $this->url = ( realpath( dirname( $this->file ) ) !== realpath( WPMU_PLUGIN_DIR ) ) ? trailingslashit( trailingslashit( WP_PLUGIN_URL ) . str_replace( basename( $this->file ), '', $this->base ) ) : trailingslashit( trailingslashit( WPMU_PLUGIN_URL ) . str_replace( basename( $this->file ), '', $this->base ) ); + } else { + $this->dir = trailingslashit( TEMPLATEPATH ); + $this->url = trailingslashit( get_template_directory_uri() ); + } + + $class = new ReflectionClass( get_class( $this ) ); + $methods = $class->getMethods(); + + foreach ( $methods as $method ) { + if ( 0 === strpos( $method->name, 'hook_' ) ) { + $hook = substr( $method->name, 5 ); + $prio = array_pop( explode( '_', $hook ) ); + + if ( is_numeric( $prio ) ) + $hook = substr( $hook, 0, - ( strlen( '_' . $prio ) ) ); + else + $prio = 10; + + add_filter( $hook, array( &$this, $method->name ), $prio, $method->getNumberOfParameters() ); + } elseif ( 0 === strpos( $method->name, 'short_' ) ) { + $short = substr( $method->name, 6 ); + add_shortcode( $short, array( &$this, $method->name ) ); + } + } unset( $class, $methods, $hook, $prio ); + + if ( empty( $this->options ) ) + add_filter( 'init', array( &$this, 'install' ) ); + elseif ( $this->options[ 'version' ] != $this->version ) + add_filter( 'init', array( &$this, 'upgrade' ) ); + elseif ( !empty( $this->options[ 'uninstall' ] ) && 'plugin' == $this->type ) + register_deactivation_hook( $this->file, array( &$this, 'deactivate' ) ); + } + + /** + * Deactivation function for plugins. + * + * Deletes plugin options when the plugin is deactivated. + * The uninstall function (which classes using the + * framework must define) should remove any additional + * information, as well as add the 'uninstall' option + * which triggers the deactivation hook. + * + * @package mgs_core + * @since 1 + */ + final function deactivate( $t = false ) { + $this->option( null ); + } + + /** + * Load text domain for translations. + * + * Plugins need to call this function anytime + * strings can be translated in a function. Themes + * should usually call this function once in a + * hook_after_setup_theme() function. + * + * @package mgs_core + * @since 1 + */ + final function domain() { + if ( 'plugin' == $this->type && realpath( dirname( $this->file ) ) !== realpath( WPMU_PLUGIN_DIR ) ) + load_muplugin_textdomain( $this->name, $this->dir . $this->name . '-includes/languages' ); + elseif ( 'plugin' == $this->type ) + load_plugin_textdomain( $this->name, $this->dir . $this->name . '-includes/languages', dirname( $this->base ) ); + elseif ( 'theme' == $this->type ) { + load_theme_textdomain( $this->name, $this->dir . 'languages' ); + + $l = get_locale(); + $lf = $this->dir . "languages/$l.php"; + + if ( is_readable( $lf ) ) require_once( $lf ); + } else + return false; + } + + /** + * Add, retrieve, update, or delete an option or options. + * + * Options are stored in a single database entry as an array + * and loaded into the framework $options variable during + * initialization. + * + * @package mgs_core + * @since 1 + * + * @param str|arr|null The name of the option to return, an array of new options to save, or null (deletes all existing options). + * @param str|null The new value for the option specified in $o, or null to delete the option. + * @return Return all options, the specified options, true when updating options, or false on error. + */ + final function option( $o = false, $v = false ) { + if ( false === $o ) { + return get_option( $this->name . '_options', array() ); + } elseif ( null === $o ) { + $this->options = $o; + return delete_option( $this->name . '_options' ); + } elseif ( is_array( $o ) ) { + $this->options = $o; + return update_option( $this->name . '_options', $o ); + } elseif ( array_key_exists( $o, $this->options ) ) { + if ( false === $v ) + return $this->options[ $o ]; + elseif ( null === $v ) + unset ( $this->options[ $o ] ); + else + $this->options[ $o ] = $v; + + return update_option( $this->name . '_options', $this->options ); + } + + return false; + } + + /** + * Abstract functions that must be defined. + * + * These abstract functions must be defined in any class + * extending the framework, even if they're unused: + * + * Install is a run-once function that should, at the very least, + * set plugin or theme options with a 'version' key. + * + * Upgrade is run any time there's a mismatch between the class $version + * and the version stored in the plugin or theme options. + * + * Uninstall must be called by another class method and should, at the + * very least, set the 'uninstall' option to true. + * + * @package mgs_core + * @since 1 + */ + abstract function install(); + abstract function upgrade(); + abstract function uninstall(); +} +?> \ No newline at end of file diff --git a/webcomic-includes/scripts.js b/webcomic-includes/scripts.js new file mode 100644 index 0000000..7e313d6 --- /dev/null +++ b/webcomic-includes/scripts.js @@ -0,0 +1,32 @@ +/** + * This document contains javascript necessary to enhance certain Webcomic functions. + * + * @package webcomic + * @since 3 + */ +jQuery( document ) . ready( function( $ ) { + /** Load transcripts for improvement */ + $( 'select[name=webcomic_transcript_language]' ) . change( + function() { + $( this ) . parents( 'form' ) . find( 'input[name=webcomic_ajax]' ) . val( 1 ); + var params = $( this ) . parents( 'form' ) . serialize(); + $( this ) . parents( 'form' ) . find( 'textarea[name=webcomic_transcript_text]' ) . load( window.location.pathname, params ); + $( this ) . parents( 'form' ) . find( 'input[name=webcomic_ajax]' ) . val( 0 ); + } + ) . change(); + + /** Enable keyboard shortcuts */ + $( '.webcomic-kbd-shortcut' ) . click( function() { if ( $( this ) . attr( 'href' ) ) window . location = $( this ) . attr( 'href' ); } ); + $.hotkeys.add( 'right', { disableInInput: true }, function() { $( '.next-webcomic-link.webcomic-kbd-shortcut' ) . click(); } ); + $.hotkeys.add( 'left', { disableInInput: true }, function() { $( '.previous-webcomic-link.webcomic-kbd-shortcut' ) . click(); } ); + $.hotkeys.add( 'shift+left', { disableInInput: true }, function() { $( '.first-webcomic-link.webcomic-kbd-shortcut' ) . click(); } ); + $.hotkeys.add( 'shift+right', { disableInInput: true }, function() { $( '.last-webcomic-link.webcomic-kbd-shortcut' ) . click(); } ); + $.hotkeys.add( 'shift+up', { disableInInput: true }, function() { $( '.purchase-webcomic-link.webcomic-kbd-shortcut' ) . click(); } ); + $.hotkeys.add( 'shift+down', { disableInInput: true }, function() { $( '.random-webcomic-link.webcomic-kbd-shortcut' ) . click(); } ); + $.hotkeys.add( 'ctrl+shift+up', { disableInInput: true }, function() { $( '.remove-webcomic-link.webcomic-kbd-shortcut' ) . click(); } ); + $.hotkeys.add( 'ctrl+shift+left', { disableInInput: true }, function() { $( '.return-webcomic-link.webcomic-kbd-shortcut' ) . click(); } ); + $.hotkeys.add( 'ctrl+shift+down', { disableInInput: true }, function() { $( '.bookmark-webcomic-link.webcomic-kbd-shortcut' ) . click(); } ); + + /** Jump to the selected url */ + $( '.webcomic-posts,.related-webcomic-posts,.webcomic-post-terms,.webcomic-terms,.webcomic-archive' ) . change ( function() { if ( $( this ) . attr( 'value' ) != 0 ) window . location = $( this ) . attr( 'value' ); } ); +} ); \ No newline at end of file diff --git a/webcomic-includes/tags-legacy.php b/webcomic-includes/tags-legacy.php new file mode 100644 index 0000000..f67d2ec --- /dev/null +++ b/webcomic-includes/tags-legacy.php @@ -0,0 +1,48 @@ +in_webcomic_term( 'webcomic_collection', $terms, $id ); } +function in_comic_chapter( $terms = false, $id = false ) { global $webcomic; return $webcomic->in_webcomic_term( 'webcomic_storyline', $terms, $id ); } +function get_the_comic( $id = false, $dep1 = false, $dep2 = false ) { global $webcomic; return $webocmic->get_webcomic_post( $id ); } +function get_the_chapter( $id ) { return get_term( $id, 'webcomic_storyline' ); } +function get_comic_object( $id = false, $size = false, $dep1 = false ) { global $webcomic; $size = ( 'thumb' == $size ) ? 'small' : $size; return $webcomic->get_webcomic_object( $size, 'post', false, $id ); } +function get_comic_buffer( $term = false ) { global $webcomic; return $webcomic->get_webcomic_buffer( $term ); } +function the_comic( $size = 'full', $link = false, $terms = false ) { global $webcomic; $size = ( 'thumb' == $size ) ? 'small' : $size; $taxonomy = ( $terms ) ? 'webcomic_storyline' : false; echo $webcomic->get_the_webcomic_object( $size, $link, $taxonomy, $terms, false, false ); } +function the_comic_embed( $size = 'small', $format = 'shtml' ) { global $webcomic; echo $webcomic->get_the_webcomic_embed( $format, $size ); } +function the_comic_series( $label = false ) { global $webcomic; if ( 'full' == $label || 'large' == $label || 'medium' == $label || 'small' == $label || 'thumb' == $label ) { $label = ( 'thumb' == $label ) ? 'small' : $label; $image = '&image=' . $label; } echo $webcomic->get_the_webcomic_post_terms( 'webcomic_collection', 'separator=, ' . $image ); } +function transcript_template( $file = false ) { global $webcomic; $webcomic->webcomic_transcripts_template( $file ); } +function transcript_id_fields( $captcha = false ) { global $webcomic; echo $webcomic->get_webcomic_transcribe_form_fields(); } +function have_transcript( $status = false ) { global $webcomic; return $webcomic->have_webcomic_transcripts( $status ); } +function comics_nav_link( $args = false ) { global $webcomic; $defaults = array( 'sep' => false, 'label' => '%label', 'fstlabel' => '%label', 'prelabel' => '%label', 'nxtlabel' => '%label', 'lstlabel' => '%label' ); $args = wp_parse_args( $args, $defaults ); if ( $args[ 'label' ] ) $args[ 'fstlabel' ] = $args[ 'prelabel' ] = $args[ 'nxtlabel' ] = $args[ 'lstlabel' ] = $args[ 'label' ]; extract( $args ); $sep = ( $sep ) ? $sep : ''; echo $webcomic->get_relative_webcomic_link( 'first', '%link', $fstlabel ) . $sep . $webcomic->get_relative_webcomic_link( 'previous', '%link', $prelabel ) . $sep . $webcomic->get_relative_webcomic_link( 'next', '%link', $nxtlabel ) . $sep . $webcomic->get_relative_webcomic_link( 'last', '%link', $lstlabel ); } +function first_comic_link( $link = '%label', $dep1 = false, $dep2 = false ) { global $webcomic; if ( 'title' == $link || 'full' == $link || 'large' == $link || 'medium' == $link || 'small' == $link || 'thumb' == $link ) { $link = ( 'thumb' == $link ) ? 'small' : $link; $link = ( 'title' == $link ) ? '%'. $link : '%thumb-' . $link; } echo $webcomic->get_relative_webcomic_link( 'first', '%link', $link, false, false ); } +function last_comic_link( $link = '%label', $dep1 = false, $dep2 = false ) { global $webcomic; if ( 'title' == $link || 'full' == $link || 'large' == $link || 'medium' == $link || 'small' == $link || 'thumb' == $link ) { $link = ( 'thumb' == $link ) ? 'small' : $link; $link = ( 'title' == $link ) ? '%'. $link : '%thumb-' . $link; } echo $webcomic->get_relative_webcomic_link( 'last', '%link', $link, false, false ); } +function previous_comic_link( $link = '%label', $dep1 = false, $dep2 = false ) { global $webcomic; if ( 'title' == $link || 'full' == $link || 'large' == $link || 'medium' == $link || 'small' == $link || 'thumb' == $link ) { $link = ( 'thumb' == $link ) ? 'small' : $link; $link = ( 'title' == $link ) ? '%'. $link : '%thumb-' . $link; } echo $webcomic->get_relative_webcomic_link( 'previous', '%link', $link, false, false ); } +function next_comic_link( $link = '%label', $dep1 = false, $dep2 = false ) { global $webcomic; if ( 'title' == $link || 'full' == $link || 'large' == $link || 'medium' == $link || 'small' == $link || 'thumb' == $link ) { $link = ( 'thumb' == $link ) ? 'small' : $link; $link = ( 'title' == $link ) ? '%'. $link : '%thumb-' . $link; } echo $webcomic->get_relative_webcomic_link( 'next', '%link', $link, false, false ); } +function random_comic_link( $link = '%label', $dep1 = false, $dep2 = false ) { global $webcomic; if ( 'title' == $link || 'full' == $link || 'large' == $link || 'medium' == $link || 'small' == $link || 'thumb' == $link ) { $link = ( 'thumb' == $link ) ? 'small' : $link; $link = ( 'title' == $link ) ? '%'. $link : '%thumb-' . $link; } echo $webcomic->get_relative_webcomic_link( 'random', '%link', $link, false, false ); } +function bookmark_comic( $sep = false, $bookmark = false, $return = false, $clear = false ) { global $webcomic; $sep = ( $sep ) ? '' . $sep . '' : ''; echo '
    ' . $webcomic->get_bookmark_webcomic_link( 'bookmark', '%link', $bookmark ) . $sep . $webcomic->get_bookmark_webcomic_link( 'return', '%link', $return ) . $sep . $webcomic->get_bookmark_webcomic_link( 'remove', '%link', $clear ) . '
    '; } +function chapters_nav_link( $args = false ) { global $webcomic; $defaults = array( 'sep' => false, 'label' => false, 'fstlabel' => false, 'prelabel' => false, 'nxtlabel' => false, 'lstlabel' => false ); $args = wp_parse_args( $args, $defaults ); if ( $args[ 'label' ] ) $args[ 'fstlabel' ] = $args[ 'prelabel' ] = $args[ 'nxtlabel' ] = $args[ 'lstlabel' ] = $args[ 'label' ]; extract( $args ); echo $webcomic->get_relative_webcomic_term_link( 'first', 'webcomic_storyline', '%link', $fstlabel, false, false ) . $sep . $webcomic->get_relative_webcomic_term_link( 'previous', 'webcomic_storyline', '%link', $prelabel, false, false ) . $sep . $webcomic->get_relative_webcomic_term_link( 'next', 'webcomic_storyline', '%link', $nxtlabel, false, false ) . $sep . $webcomic->get_relative_webcomic_term_link( 'last', 'webcomic_storyline', '%link', $lstlabel, false, false ); } +function first_chapter_link( $link = '%label', $dep1 = false, $dep2 = false, $dep3 = false ) { global $webcomic; if ( 'title' == $link || 'full' == $link || 'large' == $link || 'medium' == $link || 'small' == $link || 'thumb' == $link ) { $link = ( 'thumb' == $link ) ? 'small' : $link; $link = ( 'title' == $link ) ? '%'. $link : '%thumb-' . $link; } echo $webcomic->get_relative_webcomic_term_link( 'first', 'webcomic_storyline', '%link', $link, false, false ); } +function last_chapter_link( $link = '%label', $dep1 = false, $dep2 = false, $dep3 = false ) { global $webcomic; if ( 'title' == $link || 'full' == $link || 'large' == $link || 'medium' == $link || 'small' == $link || 'thumb' == $link ) { $link = ( 'thumb' == $link ) ? 'small' : $link; $link = ( 'title' == $link ) ? '%'. $link : '%thumb-' . $link; } echo $webcomic->get_relative_webcomic_term_link( 'last', 'webcomic_storyline', '%link', $link, false, false ); } +function previous_chapter_link( $link = '%label', $dep1 = false, $dep2 = false, $dep3 = false ) { global $webcomic; if ( 'title' == $link || 'full' == $link || 'large' == $link || 'medium' == $link || 'small' == $link || 'thumb' == $link ) { $link = ( 'thumb' == $link ) ? 'small' : $link; $link = ( 'title' == $link ) ? '%'. $link : '%thumb-' . $link; } echo $webcomic->get_relative_webcomic_term_link( 'previous', 'webcomic_storyline', '%link', $link, false, false ); } +function next_chapter_link( $link = '%label', $dep1 = false, $dep2 = false, $dep3 = false ) { global $webcomic; if ( 'title' == $link || 'full' == $link || 'large' == $link || 'medium' == $link || 'small' == $link || 'thumb' == $link ) { $link = ( 'thumb' == $link ) ? 'small' : $link; $link = ( 'title' == $link ) ? '%'. $link : '%thumb-' . $link; } echo $webcomic->get_relative_webcomic_term_link( 'next', 'webcomic_storyline', '%link', $link, false, false ); } +function the_chapter_link( $label = false, $dep1 = false, $dep2 = false ) { global $webcomic; if ( 'full' == $label || 'large' == $label || 'medium' == $label || 'small' == $label || 'thumb' == $label ) { $label = ( 'thumb' == $label ) ? 'small' : $label; $image = '&image=' . $label; } echo $webcomic->get_the_webcomic_post_terms( 'webcomic_storyline', 'separator=, ' . $image ); } +function single_chapter_title( $dep1 = false, $display = true ) { global $webcomic; if ( $display ) echo $webcomic->get_webcomic_term_info( 'name', 'webcomic_storyline' ); else return $webcomic->get_webcomic_term_info( 'name', 'webcomic_storyline' ); } +function chapter_description( $term = false ) { global $webcomic; return $webcomic->get_webcomic_term_info( 'description', 'webcomic_storyline', $term ); } +function recent_comics( $number = 5, $label = false, $limit = false ) { global $webcomic; if ( 'full' == $label || 'large' == $label || 'medium' == $label || 'small' == $label || 'thumb' == $label ) { $label = ( 'thumb' == $label ) ? 'small' : $label; $image = '&image=' . $label; } $limit = ( $limit ) ? '&term_group=' . current( explode( ',', $limit ) ) : ''; echo $webcomic->get_the_webcomic_archive( 'limit=' . $number . $image . $limit ); } +function dropdown_comics( $args = false ) { global $webcomic; $defaults = array( 'format' => 'dropdown' ); $args = wp_parse_args( $args, $defaults ); $args[ 'order' ] = $args[ 'post_order' ]; $args[ 'group' ] = ( $args[ 'groupby' ] ) ? 'storyline' : false; echo $webcomic->get_the_webcomic_archive( $args ); } +function comic_archive( $args = false ) { global $webcomic; $defaults = array( 'format' => 'grid', 'last_only' => true ); $args = wp_parse_args( $args, $defaults ); if ( 'chapter' == $args[ 'groupby' ] ) $args[ 'format' ] = 'olist'; $args[ 'order' ] = $args[ 'post_order' ]; $args[ 'group_order' ] = $args[ 'order' ]; $args[ 'show_description' ] = $args[ 'descriptions' ]; $args[ 'show_count' ] = $args[ 'pages' ]; echo $webcomic->get_the_webcomic_archive( $args ); } + +/* These functions have no direct equivalent in Webcomic 3 */ +function get_comic_category() { return false; } +function get_the_collection( $args = false ) { return arrray(); } +function the_comic_buffer( $i = false, $terms = false ) { return false; } +function transcript_form_title( $new = false, $improve =false ) { return false; } +?> \ No newline at end of file diff --git a/webcomic-includes/tags.php b/webcomic-includes/tags.php new file mode 100644 index 0000000..32d4165 --- /dev/null +++ b/webcomic-includes/tags.php @@ -0,0 +1,105 @@ +get_webcomic_post( $id ); } +function get_webcomic_object( $size = 'full', $type = false, $key = false, $id = false, $format = false ) { global $webcomic; return $webcomic->get_webcomic_object( $size, $type, $key, $id, $format ); } +function the_webcomic_object( $size = 'full', $link = false, $taxonomy = false, $terms = false, $key = false, $id = false ) { global $webcomic; echo $webcomic->get_the_webcomic_object( $size, $link, $taxonomy, $terms, $key, $id ); } +function get_webcomic_embed( $format = 'shtml', $size = 'small', $key = false, $id = false ) { global $webcomic; return $webocmic->get_webcomic_embed( $format, $size, $key, $id ); } +function the_webcomic_embed( $format = 'shtml', $size = 'small', $key = false, $id = false ) { global $webcomic; echo $webcomic->get_the_webcomic_embed( $format, $size, $key, $id ); } +function random_webcomic_url( $taxonomy = false, $terms = false, $id = false, $global = false ) { global $webcomic; echo $webcomic->get_relative_webcomic_url( 'random', $taxonomy, $terms, $id, $global ); } +function first_webcomic_url( $taxonomy = false, $terms = false, $id = false, $global = false ) { global $webcomic; echo $webcomic->get_relative_webcomic_url( 'first', $taxonomy, $terms, $id, $global ); } +function last_webcomic_url( $taxonomy = false, $terms = false, $id = false, $global = false ) { global $webcomic; echo $webcomic->get_relative_webcomic_url( 'last', $taxonomy, $terms, $id, $global ); } +function previous_webcomic_url( $taxonomy = false, $terms = false, $id = false, $global = false ) { global $webcomic; echo $webcomic->get_relative_webcomic_url( 'previous', $taxonomy, $terms, $id, $global ); } +function next_webcomic_url( $taxonomy = false, $terms = false, $id = false, $global = false ) { global $webcomic; echo $webcomic->get_relative_webcomic_url( 'next', $taxonomy, $terms, $id, $global ); } +function purchase_webcomic_url( $id = false ) { global $webcomic; echo $webcomic->get_purchase_webcomic_url( $id ); } +function bookmark_webcomic_url( $id = false ) { global $webcomic; echo $webcomic->get_bookmark_webcomic_url( 'bookmark', $id ); } +function return_webcomic_url( $id = false ) { global $webcomic; echo $webcomic->get_bookmark_webcomic_url( 'return', $id ); } +function remove_webcomic_url( $id = false ) { global $webcomic; echo $webcomic->get_bookmark_webcomic_url( 'remove', $id ); } +function random_webcomic_link( $format = '%link', $link = '%label', $taxonomy = false, $terms = false, $id = false, $global = false ) { global $webcomic; echo $webcomic->get_relative_webcomic_link( 'random', $format, $link, $taxonomy, $terms, $id, $global ); } +function first_webcomic_link( $format = '%link', $link = '%label', $taxonomy = false, $terms = false, $id = false, $global = false ) { global $webcomic; echo $webcomic->get_relative_webcomic_link( 'first', $format, $link, $taxonomy, $terms, $id, $global ); } +function last_webcomic_link( $format = '%link', $link = '%label', $taxonomy = false, $terms = false, $id = false, $global = false ) { global $webcomic; echo $webcomic->get_relative_webcomic_link( 'last', $format, $link, $taxonomy, $terms, $id, $global ); } +function previous_webcomic_link( $format = '%link', $link = '%label', $taxonomy = false, $terms = false, $id = false, $global = false ) { global $webcomic; echo $webcomic->get_relative_webcomic_link( 'previous', $format, $link, $taxonomy, $terms, $id, $global ); } +function next_webcomic_link( $format = '%link', $link = '%label', $taxonomy = false, $terms = false, $id = false, $global = false ) { global $webcomic; echo $webcomic->get_relative_webcomic_link( 'next', $format, $link, $taxonomy, $terms, $id, $global ); } +function purchase_webcomic_link( $format = '%link', $link = '%label', $id = false ) { global $webcomic; echo $webcomic->get_purchase_webcomic_link( $format, $link, $id ); } +function boookmark_webcomic_link( $format = '%link', $link = '%label', $id = false ) { global $webcomic; echo $webcomic->get_bookmark_webcomic_link( 'bookmark', $format, $link, $id ); } +function return_webcomic_link( $format = '%link', $link = '%label', $id = false ) { global $webcomic; echo $webcomic->get_bookmark_webcomic_link( 'return', $format, $link, $id ); } +function remove_webcomic_link( $format = '%link', $link = '%label', $id = false ) { global $webcomic; echo $webcomic->get_bookmark_webcomic_link( 'remove', $format, $link, $id ); } +function get_related_webcomics( $storylines = true, $characters = true, $id = false ) { global $webcomic; return $webcomic->get_related_webcomics( Sstorylines, $characters, $id ); } +function get_the_related_webcomics( $args = false ) { global $webcomic; echo $webcomic->get_the_related_webcomics( $args ); } +function get_buffer_webcomics( $terms = false, $taxonomy = false ) { global $webcomic; return $webcomic->get_buffer_webcomics( $terms, $taxonomy ); } +function the_buffer_webcomics( $args = false ) { global $webcomic; echo $webcomic->get_the_buffer_webcomics( $args ); } +function webcomic_verify( $type = false, $id = false ) { global $webcomic; return $webcomic->verify( $type, $id ); } +function webcomic_verify_form( $label = false ) { global $webcomic; echo $webcomic->get_webcomic_verify_form( $label ); } +function webcomic_verify_age( $id = false ) { global $webcomic; echo $webcomic->get_webcomic_verify_age( $id ); } +function the_webcomic_donation_amount( $dec = false, $sep = false ) { global $webcomic; echo $webcomic->get_the_webcomic_donation_amount( $dec, $sep ); } +function webcomic_donation_fields() { global $webcomic; echo $webcomic->get_webcomic_donation_fields(); } +function webcomic_donation_form( $label = false ) { global $webcomic; echo $webcomic->get_webcomic_donation_form( $label ); } +function webcomic_prints_open( $id = false, $original = false ) { global $webcomic; return $webcomic->webcomic_prints_open( $id, $original ); } +function get_purchase_webcomic_cost( $cost = 'price', $type = 'domestic', $id = false ) { global $webcomic; return $webcomic->get_purchase_webcomic_cost( $cost, $type, $id ); } +function the_purchase_webcomic_cost( $cost = 'price', $type = 'domestic', $dec = false, $sep = false, $id = false ) { global $webcomic; echo $webcomic->get_the_purchase_webcomic_cost( $cost, $type, $dec, $sep, $id ); } +function get_purchase_webcomic_adjustment( $adjustment = 'collection', $type = 'domestic', $id = false ) { global $webcomic; return $webcomic->get_purchase_webcomic_adjustment( $adjustment, $type, $id ); } +function the_purchase_webcomic_adjustment( $adjustment = 'collection', $type = 'domestic', $dec = false, $sep = false, $id = false ) { global $webcomic; echo $webcomic->get_the_purchase_webcomic_adjustment( $adjustment, $type, $dec, $sep, $id ); } +function purchase_webcomic_fields( $type = 'domestic', $id = false ) { global $webcomic; echo $webcomic->get_purchase_webcomic_fields( $type, $id ); } +function purchase_webcomic_form( $type = 'dmoestic', $label = false, $id = false ) { global $webcomic; echo $webcomic->get_purchase_webcomic_form( $type, $label, $id ); } +function webcomic_transcripts_template( $file = false ) { global $webcomic; $webcomic->webcomic_transcripts_template( $file ); } +function have_webcomic_transcripts( $status = false ) { global $webcomic; return $webcomic->have_webcomic_transcripts( $status ); } +function list_webcomic_transcripts( $args = false ) { global $webcomic; $webcomic->list_webcomic_transcripts( $args ); } +function webcomic_transcripts_open() { global $webcomic; return $webcomic->webcomic_transcripts_open(); } +function webcomic_transcribe_form( $args = false ) { global $webcomic; $webcomic->webcomic_transcribe_form( $args ); } +function webcomic_transcribe_form_fields() { global $webcomic; echo $webcomic->get_webcomic_transcribe_form_fields(); } +function webcomic_transcribe_form_languages() { global $webcomic; echo $webcomic->get_webcomic_transcribe_form_languages(); } +function webcomic_transcript_info( $i = false ) { global $webcomic; echo $webcomic->get_webcomic_transcript_info( $i ); } +function webcomic_transcript_class( $class = false ) { global $webcomic; echo $webcomic->get_webcomic_transcript_class( $class ); } +function in_webcomic_collection( $terms = false, $id = false ) { global $webcomic; return $webcomic->in_webcomic_term( 'webcomic_collection', $terms, $id ); } +function get_webcomic_post_collections( $id = false ) { global $webcomic; return $webcomic->get_webcomic_post_terms( 'webcomic_collection', $id ); } +function the_webcomic_post_collections( $args = false ) { global $webcomic; echo $webcomic->get_the_webcomic_post_terms( 'webcomic_collection', $args ); } +function get_webcomic_collection_info( $i = false, $term = false ) { global $webcomic; echo $webcomic->get_webcomic_term_info( $i, 'webcomic_collection', $term ); } +function the_webcomic_collections( $args = false ) { global $webcomic; echo $webcomic->get_the_webcomic_terms( 'webcomic_collection', $args ); } +function random_webcomic_collection_url( $term = false, $orderby = false, $hide_empty = true ) { global $webcomic; echo $webcomic->get_relative_webcomic_term_url( 'random', 'webcomic_collection', $term, $orderby, $hide_empty ); } +function first_webcomic_collection_url( $term = false, $orderby = false, $hide_empty = true ) { global $webcomic; echo $webcomic->get_relative_webcomic_term_url( 'first', 'webcomic_collection', $term, $orderby, $hide_empty ); } +function last_webcomic_collection_url( $term = false, $orderby = false, $hide_empty = true ) { global $webcomic; echo $webcomic->get_relative_webcomic_term_url( 'last', 'webcomic_collection', $term, $orderby, $hide_empty ); } +function previous_webcomic_collection_url( $term = false, $orderby = false, $hide_empty = true ) { global $webcomic; echo $webcomic->get_relative_webcomic_term_url( 'previous', 'webcomic_collection', $term, $orderby, $hide_empty ); } +function next_webcomic_collection_url( $term = false, $orderby = false, $hide_empty = true ) { global $webcomic; echo $webcomic->get_relative_webcomic_term_url( 'next', 'webcomic_collection', $term, $orderby, $hide_empty ); } +function random_webcomic_collection_link( $format = '%link', $link = '%label', $term = false, $orderby = false, $hide_empty = true ) { global $webcomic; echo $webcomic->get_relative_webcomic_term_link( 'random', 'webcomic_collection', $format, $link, $term, $orderby, $hide_empty ); } +function first_webcomic_collection_link( $format = '%link', $link = '%label', $term = false, $orderby = false, $hide_empty = true ) { global $webcomic; echo $webcomic->get_relative_webcomic_term_link( 'first', 'webcomic_collection', $format, $link, $term, $orderby, $hide_empty ); } +function last_webcomic_collection_link( $format = '%link', $link = '%label', $term = false, $orderby = false, $hide_empty = true ) { global $webcomic; echo $webcomic->get_relative_webcomic_term_link( 'last', 'webcomic_collection', $format, $link, $term, $orderby, $hide_empty ); } +function previous_webcomic_collection_link( $format = '%link', $link = '%label', $term = false, $orderby = false, $hide_empty = true ) { global $webcomic; echo $webcomic->get_relative_webcomic_term_link( 'previous', 'webcomic_collection', $format, $link, $term, $orderby, $hide_empty ); } +function next_webcomic_collection_link( $format = '%link', $link = '%label', $term = false, $orderby = false, $hide_empty = true ) { global $webcomic; echo $webcomic->get_relative_webcomic_term_link( 'next', 'webcomic_collection', $format, $link, $term, $orderby, $hide_empty ); } +function in_webcomic_storyline( $terms = false, $id = false ) { global $webcomic; return $webcomic->in_webcomic_term( 'webcomic_storyline', $terms, $id ); } +function get_webcomic_post_storylines( $id = false ) { global $webcomic; return $webcomic->get_webcomic_post_terms( 'webcomic_storyline', $id ); } +function the_webcomic_post_storylines( $args = false ) { global $webcomic; echo $webcomic->get_the_webcomic_post_terms( 'webcomic_storyline', $args ); } +function get_webcomic_storyline_info( $i = false, $term = false ) { global $webcomic; echo $webcomic->get_webcomic_term_info( $i, 'webcomic_storyline', $term ); } +function the_webcomic_storylines( $args = false ) { global $webcomic; echo $webcomic->get_the_webcomic_terms( 'webcomic_storyline', $args ); } +function random_webcomic_storyline_url( $term = false, $orderby = false, $hide_empty = true ) { global $webcomic; echo $webcomic->get_relative_webcomic_term_url( 'random', 'webcomic_storyline', $term, $orderby, $hide_empty ); } +function first_webcomic_storyline_url( $term = false, $orderby = false, $hide_empty = true ) { global $webcomic; echo $webcomic->get_relative_webcomic_term_url( 'first', 'webcomic_storyline', $term, $orderby, $hide_empty ); } +function last_webcomic_storyline_url( $term = false, $orderby = false, $hide_empty = true ) { global $webcomic; echo $webcomic->get_relative_webcomic_term_url( 'last', 'webcomic_storyline', $term, $orderby, $hide_empty ); } +function previous_webcomic_storyline_url( $term = false, $orderby = false, $hide_empty = true ) { global $webcomic; echo $webcomic->get_relative_webcomic_term_url( 'previous', 'webcomic_storyline', $term, $orderby, $hide_empty ); } +function next_webcomic_storyline_url( $term = false, $orderby = false, $hide_empty = true ) { global $webcomic; echo $webcomic->get_relative_webcomic_term_url( 'next', 'webcomic_storyline', $term, $orderby, $hide_empty ); } +function random_webcomic_storyline_link( $format = '%link', $link = '%label', $term = false, $orderby = false, $hide_empty = true ) { global $webcomic; echo $webcomic->get_relative_webcomic_term_link( 'random', 'webcomic_storyline', $format, $link, $term, $orderby, $hide_empty ); } +function first_webcomic_storyline_link( $format = '%link', $link = '%label', $term = false, $orderby = false, $hide_empty = true ) { global $webcomic; echo $webcomic->get_relative_webcomic_term_link( 'first', 'webcomic_storyline', $format, $link, $term, $orderby, $hide_empty ); } +function last_webcomic_storyline_link( $format = '%link', $link = '%label', $term = false, $orderby = false, $hide_empty = true ) { global $webcomic; echo $webcomic->get_relative_webcomic_term_link( 'last', 'webcomic_storyline', $format, $link, $term, $orderby, $hide_empty ); } +function previous_webcomic_storyline_link( $format = '%link', $link = '%label', $term = false, $orderby = false, $hide_empty = true ) { global $webcomic; echo $webcomic->get_relative_webcomic_term_link( 'previous', 'webcomic_storyline', $format, $link, $term, $orderby, $hide_empty ); } +function next_webcomic_storyline_link( $format = '%link', $link = '%label', $term = false, $orderby = false, $hide_empty = true ) { global $webcomic; echo $webcomic->get_relative_webcomic_term_link( 'next', 'webcomic_storyline', $format, $link, $term, $orderby, $hide_empty ); } +function in_webcomic_character( $terms = false, $id = false ) { global $webcomic; return $webcomic->in_webcomic_term( 'webcomic_character', $terms, $id ); } +function get_webcomic_post_characters( $id = false ) { global $webcomic; return $webcomic->get_webcomic_post_terms( 'webcomic_character', $id ); } +function the_webcomic_post_characters( $args = false ) { global $webcomic; echo $webcomic->get_the_webcomic_post_terms( 'webcomic_character', $args ); } +function webcomic_character_info( $i = false, $term = false ) { global $webcomic; echo $webcomic->get_webcomic_term_info( $i, 'webcomic_character', $term ); } +function the_webcomic_characters( $args = false ) { global $webcomic; echo $webcomic->get_the_webcomic_terms( 'webcomic_character', $args ); } +function random_webcomic_character_url( $term = false, $orderby = false, $hide_empty = true ) { global $webcomic; echo $webcomic->get_relative_webcomic_term_url( 'random', 'webcomic_character', $term, $orderby, $hide_empty ); } +function first_webcomic_character_url( $term = false, $orderby = false, $hide_empty = true ) { global $webcomic; echo $webcomic->get_relative_webcomic_term_url( 'first', 'webcomic_character', $term, $orderby, $hide_empty ); } +function last_webcomic_character_url( $term = false, $orderby = false, $hide_empty = true ) { global $webcomic; echo $webcomic->get_relative_webcomic_term_url( 'last', 'webcomic_character', $term, $orderby, $hide_empty ); } +function previous_webcomic_character_url( $term = false, $orderby = false, $hide_empty = true ) { global $webcomic; echo $webcomic->get_relative_webcomic_term_url( 'previous', 'webcomic_character', $term, $orderby, $hide_empty ); } +function next_webcomic_character_url( $term = false, $orderby = false, $hide_empty = true ) { global $webcomic; echo $webcomic->get_relative_webcomic_term_url( 'next', 'webcomic_character', $term, $orderby, $hide_empty ); } +function random_webcomic_character_link( $format = '%link', $link = '%label', $term = false, $orderby = false, $hide_empty = true ) { global $webcomic; echo $webcomic->get_relative_webcomic_term_link( 'random', 'webcomic_character', $format, $link, $term, $orderby, $hide_empty ); } +function first_webcomic_character_link( $format = '%link', $link = '%label', $term = false, $orderby = false, $hide_empty = true ) { global $webcomic; echo $webcomic->get_relative_webcomic_term_link( 'first', 'webcomic_character', $format, $link, $term, $orderby, $hide_empty ); } +function last_webcomic_character_link( $format = '%link', $link = '%label', $term = false, $orderby = false, $hide_empty = true ) { global $webcomic; echo $webcomic->get_relative_webcomic_term_link( 'last', 'webcomic_character', $format, $link, $term, $orderby, $hide_empty ); } +function previous_webcomic_character_link( $format = '%link', $link = '%label', $term = false, $orderby = false, $hide_empty = true ) { global $webcomic; echo $webcomic->get_relative_webcomic_term_link( 'previous', 'webcomic_character', $format, $link, $term, $orderby, $hide_empty ); } +function next_webcomic_character_link( $format = '%link', $link = '%label', $term = false, $orderby = false, $hide_empty = true ) { global $webcomic; echo $webcomic->get_relative_webcomic_term_link( 'next', 'webcomic_character', $format, $link, $term, $orderby, $hide_empty ); } +function webcomic_archive( $args = false ) { global $webcomic; echo $webcomic->get_the_webcomic_archive( $args ); } +?> \ No newline at end of file diff --git a/webcomic-includes/template-purchase-print.php b/webcomic-includes/template-purchase-print.php new file mode 100644 index 0000000..83092df --- /dev/null +++ b/webcomic-includes/template-purchase-print.php @@ -0,0 +1,77 @@ +domain(); +?> + + + +
    +
    +
    > +

    + +
    +
    + + + + '' ) ); ?> +
    + +
    +
    + +
    +
    +

    + + +
    +
    + +
    + permalink. Follow any comments here with the RSS feed for this post.', 'webcomic' ); + else + $utility_text = __( 'This entry was posted in %1$s. Bookmark the permalink. Follow any comments here with the RSS feed for this post.', 'webcomic' ); + + printf( + $utility_text, + get_the_category_list( ', ' ), + $tag_list, + get_permalink(), + the_title_attribute( 'echo=0' ), + get_post_comments_feed_link() + ); + + edit_post_link( __( 'Edit', 'webcomic' ), '', '' ); + ?> +
    +
    + +
    +
    + + \ No newline at end of file diff --git a/webcomic-includes/template-transcripts.php b/webcomic-includes/template-transcripts.php new file mode 100644 index 0000000..be02252 --- /dev/null +++ b/webcomic-includes/template-transcripts.php @@ -0,0 +1,35 @@ +domain(); +?> + +
    + +
    +
    + + have_webcomic_transcripts() ) { ?> +

    + list_webcomic_transcripts(); ?> + + webcomic_transcripts_open() ) { //If transcribing is enabled, but there are no transcripts ?> + + + + + webcomic_transcribe_form(); ?> + \ No newline at end of file diff --git a/webcomic-includes/template-verify-age.php b/webcomic-includes/template-verify-age.php new file mode 100644 index 0000000..34f981a --- /dev/null +++ b/webcomic-includes/template-verify-age.php @@ -0,0 +1,33 @@ +domain(); +?> + + + +
    +
    +
    +

    +
    +

    + get_webcomic_verify_form(); ?> +
    +
    +
    +
    + + \ No newline at end of file diff --git a/webcomic-includes/template-verify-fail.php b/webcomic-includes/template-verify-fail.php new file mode 100644 index 0000000..b463bba --- /dev/null +++ b/webcomic-includes/template-verify-fail.php @@ -0,0 +1,31 @@ +domain(); +?> + + + +
    +
    +
    +

    +
    +

    +
    +
    +
    +
    + + \ No newline at end of file diff --git a/webcomic-includes/walker.php b/webcomic-includes/walker.php new file mode 100644 index 0000000..2fc80e2 --- /dev/null +++ b/webcomic-includes/walker.php @@ -0,0 +1,271 @@ + 'parent', 'id' => 'term_id' ); + + function start_lvl( &$output, $depth, $args ) { + if ( !$args[ 'separator' ] ) + $output .= '<' . $args[ 'x' ] . 'l class="children">'; + } + + function end_lvl( &$output, $depth, $args ) { + if ( !$args[ 'separator' ] ) + $output .= ''; + } + + function end_el( &$output, $page, $depth, $args ) { + if ( $args[ 'separator' ] ) + $output .= $args[ 'separator' ]; + else + $output .= ''; + } + + function start_el( &$output, $term, $depth, $args ) { + global $webcomic; + + $webcomic->domain(); + + $term_name = esc_attr( $term->name ); + + $link = '' : '>'; + + if ( $args[ 'image' ] && !empty( $term->webcomic_files[ $args[ 'image' ] ] ) ) { + foreach ( $term->webcomic_files[ $args[ 'image' ] ] as $v ) + $link .= ( $webcomic->option( 'secure_toggle' ) ) ? $v[ 'shtml' ] : $v[ 'html' ]; + } else + $link .= '' . $term_name . ''; + + $link .= ''; + + if ( ( !empty( $args[ 'feed_image' ] ) ) || ( !empty( $args[ 'feed' ] ) ) ) { + $link .= ( empty( $args[ 'feed_image' ] ) ) ? ' (' : ' '; + $link .= ''; + + if ( empty( $args[ 'feed' ] ) ) + $alt = ' alt="' . sprintf( __( 'Feed for all %s webcomics', 'webcomic' ), $term_name ) . '"'; + else { + $title = ' title="' . $args[ 'feed' ] . '"'; + $alt = ' alt="' . $args[ 'feed' ] . '"'; + $name = $args[ 'feed' ]; + $link .= $title; + } + + $link .= ( empty( $args[ 'feed_image' ] ) ) ? $name . ')' : ''; + } + + if ( $args[ 'show_count' ] ) + $link .= ' (' . intval( $term->count ) . ')'; + + $_term = ( isset( $args[ 'selected' ] ) && $args[ 'selected' ] ) ? get_term( $args[ 'selected' ], $args[ 'taxonomy' ] ) : false; + + if ( !$args[ 'separator' ] ) { + $class = 'webcomic-term-item ' . $args[ 'taxonomy' ] . '-item ' . $args[ 'taxonomy' ] . '-item-' . $term->term_id; + + if ( $args[ 'selected' ] && ( $term->term_id == $args[ 'selected' ] ) ) + $class .= 'current-webcomic-term current-' . $args[ 'taxonomy' ]; + elseif ( $_term && ( $term->term_id == $_term->parent ) ) + $class .= 'current-webcomic-term-parent current-' . $args[ 'taxonomy' ] . '-parent'; + + $output .= '
  • ' . $link; + } else + $output .= $link; + } +} + +/** + * Returns a formatted select element of webcomic terms. + * + * @package webcomic + * @since 3 + */ +class webcomic_Walker_TermDropdown extends Walker { + var $tree_type = 'webcomic_term'; + var $db_fields = array ( 'parent' => 'parent', 'id' => 'term_id' ); + + function start_el( &$output, $term, $depth, $args ) { + $term_name = esc_attr( $term->name ); + + $output .= '' : ''; + } +} + +/** + * Returns a formatted list of webcomic posts. + * + * @package webcomic + * @since 3 + */ +class webcomic_Walker_ArchiveList extends Walker { + var $tree_type = 'webcomic_term'; + var $db_fields = array ( 'parent' => 'parent', 'id' => 'term_id' ); + + function start_lvl( &$output, $depth, $args ) { + if ( !$args[ 'separator' ] || ( 'collection' == $args[ 'group' ] || 'storyline' == $args[ 'group' ] || 'character' == $args[ 'group' ] ) ) + $output .= '<' . $args[ 'x' ] . 'l class="children">'; + } + + function end_lvl( &$output, $depth, $args ) { + if ( !$args[ 'separator' ] || ( 'collection' == $args[ 'group' ] || 'storyline' == $args[ 'group' ] || 'character' == $args[ 'group' ] ) ) + $output .= ''; + } + + function end_el( &$output, $page, $depth, $args ) { + if ( $args['separator'] && !( 'collection' == $args[ 'group' ] || 'storyline' == $args[ 'group' ] || 'character' == $args[ 'group' ] ) ) + $output .= $args[ 'separator' ]; + else + $output .= '
  • '; + } + + function start_el( &$output, $term, $depth, $args ) { + global $webcomic; + + $webcomic->domain(); + + if ( $args[ 'group_image' ] ) { + $link = $img = false; + + $wc = ( 'collection' == $args[ 'group' ] ) ? get_term( $term->term_id, 'webcomic_collection' ) : get_term( $term->term_group, 'webcomic_collection' ); + + if ( $img = $webcomic->retrieve( $term->term_id, $args[ 'group' ], $wc->slug, true ) ) + foreach ( $img[ $args[ 'group_image' ] ] as $v ) + $link .= ( $webcomic->option( 'secure_toggle' ) ) ? $v[ 'shtml' ] : $v[ 'html' ]; + } else + $link = $term->name; + + $output .= '
  • ' . $link; + $output .= ( $args[ 'show_count' ] ) ? ' (' . $term->count . ')' : ''; + $output .= ( $args[ 'show_description' ] ) ? $term->description : ''; + $children = ( $args[ 'last_only' ] ) ? get_term_children( $term->term_id, $term->taxonomy ) : array(); + + if ( ( !empty( $args[ 'last_only' ] ) && empty( $children ) ) || empty( $args[ 'last_only' ] ) ) { + if ( ( $posts = get_objects_in_term( $term->term_id, "webcomic_$args[group]" ) ) ) { + usort( $posts, array( $webcomic, 'usort_term_objects_by_date' ) ); + + if ( !empty( $args[ 'limit' ] ) ) + $posts = array_slice( $posts, 0, $args[ 'limit' ] ); + + if ( $args[ 'separator' ] ) { + $format = false; + $output .= ''; + } else { + $format = true; + $output .= '<' . $args[ 'x' ] . 'l class="webcomic-archive-items">'; + } + + foreach ( $posts as $p ) { + if ( get_post_status( $p ) != 'publish' ) + continue; + + $wc = ( isset( $wc ) ) ? $wc : current( wp_get_object_terms( $p, 'webcomic_collection' ) ); + + if ( $args[ 'image' ] ) { + $link = $img = false; + + if ( $img = $webcomic->retrieve( $p, 'post', $wc->slug, true ) ) + foreach ( $img[ $args[ 'image' ] ] as $v ) + $link .= ( $webcomic->option( 'secure_toggle' ) ) ? $v[ 'shtml' ] : $v[ 'html' ]; + } else + $link = get_the_title( $p ); + + $output .= ( $format ) ? '
  • ' . $link . '
  • ' : '' . $link . '' . $args[ 'separator' ]; + } + + + $output .= ( $format ) ? '' : ''; + + if ( !$format ) + $output = substr( $output, 0, strrpos( $output, $args[ 'separator' ] ) ); + } + } + } +} + +/** + * Return a formatted dropdown of webcomics. + * + * @package webcomic + * @since 3 + */ +class webcomic_Walker_ArchiveDropdown extends Walker { + var $tree_type = 'webcomic_term'; + var $db_fields = array ( 'parent' => 'parent', 'id' => 'term_id' ); + + function start_el( &$output, $term, $depth, $args ) { + global $webcomic; + + $term_name = esc_attr( $term->name ); + + $output .= '' : ''; + $children = ( $args[ 'last_only' ] ) ? get_term_children( $term->term_id, $term->taxonomy ) : array(); + + if ( ( !empty( $args[ 'last_only' ] ) && empty( $children ) ) || empty( $args[ 'last_only' ] ) ) { + if ( $posts = get_objects_in_term( $term->term_id, $term->taxonomy ) ) { + usort( $posts, array( $webcomic, 'usort_term_objects_by_date' ) ); + + if ( 'DESC' == $args[ 'order' ] ) + $posts = array_reverse( $posts ); + + foreach ( $posts as $p ) + $output .= ''; + } + } + } +} + +/** + * Displays one or more transcripts associated with a webcommic post. + * + * @package webcomic + * @since 3 + */ +class webcomic_Walker_Transcripts extends Walker { + var $tree_type = 'webcomic_transcripts'; + var $db_fields = array ( 'parent' => 'language', 'id' => 'language_code' ); + + function start_el( &$output, $transcript, $depth, $args ) { + global $webcomic, $post, $webcomic_transcript; + + $webcomic_transcript = $transcript; + + if ( !empty( $args[ 'callback' ] ) ) { + call_user_func( $args[ 'callback' ], $transcript, $args, $depth ); + return false; + } + + extract( $args, EXTR_SKIP ); + ?> +
    get_webcomic_transcript_class(); ?> id="webcomic-transcript-get_webcomic_transcript_info( 'id' ) ?>" lang="get_webcomic_transcript_info( 'language_code' ); ?>"> + get_webcomic_transcript_info( 'text' ) ?> +
    + %s @ %s', 'webcomic' ), + $webcomic->get_webcomic_transcript_info( 'language' ), + $webcomic->get_webcomic_transcript_info( 'author' ), + $webcomic->get_webcomic_transcript_info( 'the_date' ), + $webcomic->get_webcomic_transcript_info( 'the_time' ) ); + ?> +
    +
    + \ No newline at end of file diff --git a/webcomic-includes/widgets.php b/webcomic-includes/widgets.php new file mode 100644 index 0000000..d7d6c00 --- /dev/null +++ b/webcomic-includes/widgets.php @@ -0,0 +1,738 @@ +domain(); + + $o = array( 'description' => __( 'Allow users to support your webcomic through donations.', 'webcomic' ) ); + $this->WP_Widget( 'webcomic-donation' , __( 'Webcomic Donation', 'webcomic' ), $o ); + } + + function widget( $args, $instance ) { + global $webcomic; + + extract( $args ); + + echo $before_widget; + + if ( !empty( $instance[ 'title' ] ) ) + echo $before_title . $instance[ 'title' ] . $after_title; + + echo $webcomic->get_webcomic_donation_form( $instance[ 'label' ] ); + + if ( !empty( $instance[ 'text' ] ) ) { + if ( !empty( $instance[ 'format' ] ) ) + echo wpautop( $instance[ 'text' ] ); + else + echo $instance[ 'text' ]; + } + + echo $after_widget; + } + + function update( $new, $old ) { + if ( !isset( $new[ 'submit' ] ) ) + return false; + + $instance = $old; + $instance[ 'title' ] = strip_tags( stripslashes( $new[ 'title' ] ) ); + $instance[ 'label' ] = strip_tags( stripslashes( $new[ 'label' ] ) ); + $instance[ 'text' ] = stripslashes( $new[ 'text' ] ); + $instance[ 'format' ] = ( $new[ 'format' ] ) ? true : false; + + return $instance; + } + + function form( $instance ) { + global $webcomic; + + $webcomic->domain(); + + $instance = wp_parse_args( ( array ) $instance, array( + 'title' => __( 'Donate', 'webcomic' ), + 'text' => '' + ) ); extract( $instance ); + + $title = htmlspecialchars( $instance[ 'title' ], ENT_QUOTES ); + $label = htmlspecialchars( $instance[ 'label' ], ENT_QUOTES ); + $text = htmlspecialchars( $instance[ 'text' ], ENT_QUOTES ); + ?> +

    +

    + +

    + + domain(); + + $o = array( 'description' => __( 'Link to the first, last, or a random webcomic.', 'webcomic' ) ); + $this->WP_Widget( 'relative-webcomic', __( 'Relative Webcomic', 'webcomic' ), $o ); + } + + function widget( $args, $instance ) { + global $webcomic; + + extract( $args ); + + $before_widget = ( !empty( $instance[ 'title' ] ) ) ? $before_widget . $before_title . $instance[ 'title' ] . $after_title : $before_widget; + + echo $webcomic->get_relative_webcomic_link( $instance[ 'key' ], $before_widget . '%link' . $after_widget, $instance[ 'format' ], $instance[ 'taxonomy' ], $instance[ 'term' ], false, true ); + } + + function update( $new, $old ) { + if ( !isset( $new[ 'submit' ] ) ) + return false; + + $instance = $old; + $instance[ 'title' ] = strip_tags( stripslashes( $new[ 'title' ] ) ); + $instance[ 'key' ] = $new[ 'key' ]; + $instance[ 'format' ] = $new[ 'format' ]; + $instance[ 'term' ] = $new[ 'term' ]; + $instance[ 'taxonomy' ] = ( $new[ 'term' ] ) ? 'webcomic_collection' : ''; + + return $instance; + } + + function form( $instance ) { + global $webcomic; + + $webcomic->domain(); + + $instance = wp_parse_args( ( array ) $instance, array( + 'title' => __( 'Random Webcomic', 'webcomic' ), + 'key' => 'random', + 'format' => '%label', + 'term' => false, + 'taxonomy' => false + ) ); extract( $instance ); + + $title = htmlspecialchars( $title, ENT_QUOTES ); + ?> +

    +

    +

    + +

    +

    + +

    + + domain(); + + $o = array( 'description' => __( 'A list of scheduled webcomics.', 'webcomic' ) ); + $this->WP_Widget( 'buffer-webcomics', __( 'Webcomic Buffer', 'webcomic' ), $o ); + } + + function widget( $args, $instance ) { + global $webcomic; + + extract( $args ); + + $instance[ 'before' ] = ( !empty( $instance[ 'title' ] ) ) ? $before_widget . $before_title . $instance[ 'title' ] . $after_title : $before_widget; + $instance[ 'after' ] = $after_widget; + + echo $webcomic->get_the_buffer_webcomics( $instance ); + } + + function update( $new, $old ) { + if ( !isset( $new[ 'submit' ] ) ) + return false; + + $instance = $old; + $instance[ 'title' ] = strip_tags( stripslashes( $new[ 'title' ] ) ); + $instance[ 'number' ] = $new[ 'number' ]; + $instance[ 'image' ] = $new[ 'image' ]; + $instance[ 'terms' ] = $new[ 'terms' ]; + $instance[ 'taxonomy' ] = ( $new[ 'terms' ] ) ? 'webcomic_collection' : ''; + $instance[ 'order' ] = ( $new[ 'order' ] ) ? 'DESC' : 'ASC'; + + return $instance; + } + + function form( $instance ) { + global $webcomic; + + $webcomic->domain(); + + $instance = wp_parse_args( ( array ) $instance, array( + 'title' => __( 'Scheduled Webcomics', 'webcomic' ), + 'number' => 1, + 'image' => false, + 'terms' => false, + 'taxonomy' => false, + 'order' => 'DESC' + ) ); extract( $instance ); + + $title = htmlspecialchars( $title, ENT_QUOTES ); + ?> +

    +

    +

    + +

    +

    + +

    +

    + + domain(); + + $o = array( 'description' => __( 'Links that allow users to save their place while reading.', 'webcomic' ) ); + $this->WP_Widget( 'bookmark-webcomic', __( 'Webcomic Bookmark', 'webcomic' ), $o ); + } + + function widget( $args, $instance ) { + global $webcomic; + + extract( $args ); + + echo $before_widget; + + if ( !empty( $instance[ 'title' ] ) ) + $before_title . $instance[ 'title' ] . $after_title; + + echo $webcomic->get_bookmark_webcomic_link( 'bookmark', '%link', $instance[ 'format1' ] ); + echo $webcomic->get_bookmark_webcomic_link( 'return', '%link', $instance[ 'format2' ] ); + echo $webcomic->get_bookmark_webcomic_link( 'remove', '%link', $instance[ 'format3' ] ); + + echo $after_widget; + } + + function update( $new, $old ) { + if ( !isset( $new[ 'submit' ] ) ) + return false; + + $instance = $old; + $instance[ 'title' ] = strip_tags( stripslashes( $new[ 'title' ] ) ); + $instance[ 'format1' ] = $new[ 'format1' ]; + $instance[ 'format2' ] = $new[ 'format2' ]; + $instance[ 'format3' ] = $new[ 'format3' ]; + + return $instance; + } + + function form( $instance ) { + global $webcomic; + + $webcomic->domain(); + + $instance = wp_parse_args( ( array ) $instance, array( + 'title' => __( 'Bookmark Webcomic', 'webcomic' ), + 'format1' => '%label', + 'format2' => '%label', + 'format3' => '%label' + ) ); extract( $instance ); + + $title = htmlspecialchars( $title, ENT_QUOTES ); + ?> +

    +

    +

    +

    + + domain(); + + $o = array( 'description' => __( 'A list, dropdown, or cloud of webcomic collections.', 'webcomic' ) ); + $this->WP_Widget( 'webcomic-collections', __( 'Webcomic Collections', 'webcomic' ), $o ); + } + + function widget( $args, $instance ) { + global $webcomic; + + extract( $args ); + + $instance[ 'before' ] = ( !empty( $instance[ 'title' ] ) ) ? $before_widget . $before_title . $instance[ 'title' ] . $after_title : $before_widget; + $instance[ 'after' ] = $after_widget; + + echo $webcomic->get_the_webcomic_terms( 'webcomic_collection', $instance ); + } + + function update( $new, $old ) { + if ( !isset( $new[ 'submit' ] ) ) + return false; + + $instance = $old; + $instance[ 'title' ] = strip_tags( stripslashes( $new[ 'title' ] ) ); + $instance[ 'label' ] = strip_tags( stripslashes( $new[ 'label' ] ) ); + $instance[ 'format' ] = $new[ 'format' ]; + $instance[ 'image' ] = ( 'dropdown' == $new[ 'format' ] ) ? '' : $new[ 'image' ]; + $instance[ 'hide_empty' ] = ( $new[ 'hide_empty' ] ) ? false : true; + + return $instance; + } + + function form( $instance ) { + global $webcomic; + + $webcomic->domain(); + + $instance = wp_parse_args( ( array ) $instance, array( + 'title' => __( 'Collections', 'webcomic' ), + 'label' => '', + 'format' => 'ulist', + 'image' => false, + 'hide_empty' => true + ) ); extract( $instance ); + + $title = htmlspecialchars( $title, ENT_QUOTES ); + ?> +

    +

    +

    + +

    +

    + +

    +

    + + domain(); + + $o = array( 'description' => __( 'A list, dropdown, or cloud of webcomic storylines.', 'webcomic' ) ); + $this->WP_Widget( 'webcomic-storylines', __( 'Webcomic Storylines', 'webcomic' ), $o ); + } + + function widget( $args, $instance ) { + global $webcomic; + + extract( $args ); + + $instance[ 'before' ] = ( !empty( $instance[ 'title' ] ) ) ? $before_widget . $before_title . $instance[ 'title' ] . $after_title : $before_widget; + $instance[ 'after' ] = $after_widget; + + echo $webcomic->get_the_webcomic_terms( 'webcomic_storyline', $instance ); + } + + function update( $new, $old ) { + if ( !isset( $new[ 'submit' ] ) ) + return false; + + $instance = $old; + $instance[ 'title' ] = strip_tags( stripslashes( $new[ 'title' ] ) ); + $instance[ 'label' ] = strip_tags( stripslashes( $new[ 'label' ] ) ); + $instance[ 'format' ] = $new[ 'format' ]; + $instance[ 'image' ] = ( 'dropdown' == $new[ 'format' ] ) ? '' : $new[ 'image' ]; + $instance[ 'term_group' ] = $new[ 'term_group' ]; + $instance[ 'hide_empty' ] = ( $new[ 'hide_empty' ] ) ? false : true; + + return $instance; + } + + function form( $instance ) { + global $webcomic; + + $webcomic->domain(); + + $instance = wp_parse_args( ( array ) $instance, array( + 'title' => __( 'Storylines', 'webcomic' ), + 'label' => '', + 'format' => 'ulist', + 'image' => false, + 'term_group' => false, + 'hide_empty' => true + ) ); extract( $instance ); + + $title = htmlspecialchars( $title, ENT_QUOTES ); + ?> +

    +

    +

    + +

    +

    + +

    +

    + +

    +

    + + domain(); + + $o = array( 'description' => __( 'A list, dropdown, or cloud of webcomic characters.', 'webcomic' ) ); + $this->WP_Widget( 'webcomic-characters', __( 'Webcomic Characters', 'webcomic' ), $o ); + } + + function widget( $args, $instance ) { + global $webcomic; + + extract( $args ); + + $instance[ 'before' ] = ( !empty( $instance[ 'title' ] ) ) ? $before_widget . $before_title . $instance[ 'title' ] . $after_title : $before_widget; + $instance[ 'after' ] = $after_widget; + + echo $webcomic->get_the_webcomic_terms( 'webcomic_character', $instance ); + } + + function update( $new, $old ) { + if ( !isset( $new[ 'submit' ] ) ) + return false; + + $instance = $old; + $instance[ 'title' ] = strip_tags( stripslashes( $new[ 'title' ] ) ); + $instance[ 'label' ] = strip_tags( stripslashes( $new[ 'label' ] ) ); + $instance[ 'format' ] = $new[ 'format' ]; + $instance[ 'image' ] = ( 'dropdown' == $new[ 'format' ] ) ? '' : $new[ 'image' ]; + $instance[ 'term_group' ] = $new[ 'term_group' ]; + $instance[ 'hide_empty' ] = ( $new[ 'hide_empty' ] ) ? false : true; + + return $instance; + } + + function form( $instance ) { + global $webcomic; + + $webcomic->domain(); + + $instance = wp_parse_args( ( array ) $instance, array( + 'title' => __( 'Characters', 'webcomic' ), + 'label' => '', + 'format' => 'ulist', + 'image' => false, + 'term_group' => false, + 'hide_empty' => true + ) ); extract( $instance ); + + $title = htmlspecialchars( $title, ENT_QUOTES ); + ?> +

    +

    +

    + +

    +

    + +

    +

    + +

    +

    + + domain(); + + $o = array( 'description' => __( 'Display webcomics in various ways.', 'webcomic' ) ); + $this->WP_Widget( 'webcomic-archive', __( 'Webcomic Archive', 'webcomic' ), $o ); + } + + function widget( $args, $instance ) { + global $webcomic; + + extract( $args ); + + $instance[ 'before' ] = ( !empty( $instance[ 'title' ] ) ) ? $before_widget . $before_title . $instance[ 'title' ] . $after_title : $before_widget; + $instance[ 'after' ] = $after_widget; + + echo $webcomic->get_the_webcomic_archive( $instance ); + } + + function update( $new, $old ) { + if ( !isset( $new[ 'submit' ] ) ) + return false; + + $instance = $old; + $instance[ 'title' ] = strip_tags( stripslashes( $new[ 'title' ] ) ); + $instance[ 'label' ] = strip_tags( stripslashes( $new[ 'label' ] ) ); + $instance[ 'format' ] = $new[ 'format' ]; + $instance[ 'image' ] = ( 'dropdown' == $new[ 'format' ] ) ? '' : $new[ 'image' ]; + $instance[ 'group' ] = $new[ 'group' ]; + $instance[ 'term_group' ] = $new[ 'term_group' ]; + $instance[ 'limit' ] = intval( $new[ 'limit' ] ); + $instance[ 'order' ] = ( $new[ 'order' ] ) ? false : true; + + return $instance; + } + + function form( $instance ) { + global $webcomic; + + $webcomic->domain(); + + $instance = wp_parse_args( ( array ) $instance, array( + 'title' => __( 'Archive', 'webcomic' ), + 'label' => '', + 'format' => 'ulist', + 'image' => false, + 'group' => false, + 'term_group' => false, + 'limit' => 0, + 'order' => true + ) ); extract( $instance ); + + $title = htmlspecialchars( $title, ENT_QUOTES ); + ?> +

    +

    +

    + +

    +

    + +

    +

    + +

    +

    + +

    +

    +

    + + \ No newline at end of file diff --git a/webcomic.php b/webcomic.php index 5b6f87b..668f5f0 100644 --- a/webcomic.php +++ b/webcomic.php @@ -2,13 +2,13 @@ /* Text Domain: webcomic Plugin Name: Webcomic -Plugin URI: http://maikeruon.com/webcomic/ -Description: Webcomic adds a collection of new features to WordPress designed specifically for publishing webcomics, developing webcomic themes, and managing webcomic sites. -Version: 2.1.1 +Plugin URI: http://webcomicms.net/ +Description: Comic publishing power for WordPress. Create, manage, and share your webcomics like never before. +Version: 3 Author: Michael Sisk Author URI: http://maikeruon.com/ -Copyright 2008 - 2009 Michael Sisk (email: mike@maikeruon.com) +Copyright 2008 Michael Sisk (email: mike@maikeruon.com) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -17,687 +17,3897 @@ This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software -Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ -// -// Base Loaders -// -/** - * Loads the webcomic domain for translations. - * - * @package Webcomic - * @since 1.6.0 - */ -function load_webcomic_domain() { load_plugin_textdomain( 'webcomic', PLUGINDIR . '/' . dirname( plugin_basename( __FILE__ ) ), dirname( plugin_basename( __FILE__ ) ) ); } + +/** Load the core */ +if ( !class_exists( 'mgs_core' ) ) require_once( 'webcomic-includes/mgs-core.php' ); /** - * Creates the default Webcomic settings. + * Defines all Webcomic plugin functionality, + * extending mgs_core. For administrative + * functions and filters, see the webcomic_admin + * class in webcomic-includes/admin.php * - * This funciton should only run when the plugin is first activated. - * It will attempt to create all of the default Webcomic settings and - * standard comic directories, and upgrade older features as necessary. - * - * @package Webcomic - * @since 1.0.0 + * @package webcomic + * @since 3 */ -if ( !get_option( 'webcomic_version' ) || '2.1.1' != get_option( 'webcomic_version' ) ) { - function webcomic_install() { - load_webcomic_domain(); - - $default_category = get_option( 'default_category' ); - - /** Make sure all of our default options have a value. */ - add_option( 'comic_category', array( $default_category ) ); - add_option( 'comic_directory', 'comics' ); - add_option( 'comic_current_chapter', array( $default_category => '-1' ) ); - add_option( 'comic_secure_paths', '' ); - add_option( 'comic_secure_names', '' ); - add_option( 'comic_transcripts_allowed', '' ); - add_option( 'comic_transcripts_required', '' ); - add_option( 'comic_transcripts_loggedin', '' ); - add_option( 'comic_feed', '1' ); - add_option( 'comic_feed_size', 'full' ); - add_option( 'comic_buffer', '1' ); - add_option( 'comic_buffer_alert', '7' ); - add_option( 'comic_keyboard_shortcuts', '' ); - add_option( 'comic_thumb_crop', '' ); - add_option( 'comic_large_size_w', get_option( 'large_size_w' ) ); - add_option( 'comic_large_size_h', get_option( 'large_size_h' ) ); - add_option( 'comic_medium_size_w', get_option( 'medium_size_w' ) ); - add_option( 'comic_medium_size_h', get_option( 'medium_size_h' ) ); - add_option( 'comic_thumb_size_w', get_option( 'thumbnail_size_w' ) ); - add_option( 'comic_thumb_size_h', get_option( 'thumbnail_size_h' ) ); - - /** Make sure our default comic directories exist. */ - if ( file_exists( ABSPATH . 'wpmu-settings.php' ) && !file_exists( BLOGUPLOADDIR ) ) //WPMU Check - mkdir( BLOGUPLOADDIR, 0775, true ); - - if ( !file_exists( get_comic_directory( 'abs', true ) ) ) - if ( !mkdir( get_comic_directory( 'abs', true ), 0775, true ) ) - $mkdir_error = sprintf( __( 'Webcomic was not able to create the default comic directories. If this problem persists after update your settings you will need to create them yourself.', 'webcomic' ), 'admin.php?page=comic-settings' ); - - /** Add or update the 'webcomic_version' setting and create the first series as necessary */ - if ( get_option( 'webcomic_version' ) ) { - update_option( 'webcomic_version', '2.1.1' ); +class webcomic extends mgs_core { + /** Override mgs_core variables */ + protected $name = 'webcomic'; + protected $version = '3'; + protected $file = __FILE__; + protected $type = 'plugin'; + + //// + // Core + // + // These functions define critical features + // and should never be called directly. + //// + + /** + * Run-once installation. + * + * @package webcomic + * @since 3 + */ + function install() { + $this->domain(); + + $this->option( array( + 'version' => $this->version, + 'default_collection' => false, + 'integrate_toggle' => false, + 'secure_toggle' => false, + 'transcribe_toggle' => true, + 'transcribe_restrict' => 'anyone', + 'transcribe_language' => array( 'en' => __( 'English', 'webcomic' ) ), + 'transcribe_default' => array( 'en' => __( 'English', 'webcomic' ) ), + 'feed_toggle' => true, + 'feed_size' => 'full', + 'buffer_toggle' => true, + 'buffer_size' => 7, + 'age_toggle' => true, + 'age_size' => 18, + 'shortcut_toggle' => true, + 'paypal_business' => '', + 'paypal_currency' => 'USD', + 'paypal_log' => false, + 'paypal_prints' => false, + 'paypal_method' => '_xclick', + 'paypal_price_d' => 8, + 'paypal_price_i' => 11, + 'paypal_price_o' => 14, + 'paypal_shipping_d' => 2, + 'paypal_shipping_i' => 4, + 'paypal_shipping_o' => 6, + 'paypal_donation' => 0, + 'large_h' => get_option( 'large_size_h' ), + 'large_w' => get_option( 'large_size_w' ), + 'medium_h' => get_option( 'medium_size_h' ), + 'medium_w' => get_option( 'medium_size_w' ), + 'small_h' => get_option( 'thumbnail_size_h' ), + 'small_w' => get_option( 'thumbnail_size_w' ), + 'term_meta' => array( + 'collection' => array(), + 'storyline' => array(), + 'character' => array() + ) + ) ); + + $default = wp_insert_term( __( 'Untitled', 'webcomic' ), 'webcomic_collection' ); + + $this->option( 'default_collection', $default[ 'term_id' ] ); + + wp_schedule_event( time(), 'daily', 'webcomic_buffer_alert' ); + + $a = ( get_option( 'webcomic_version' ) ) ? sprintf( __( "If you're upgrading from a previous version please visit the Upgrade Webcomic page now.", "webcomic" ), admin_url( 'admin.php?page=webcomic_tools&subpage=upgrade_webcomic' ) ) : sprintf( __( 'You may want to adjust some settings, or you can go to the Library to start publishing webcomics.', 'webcomic' ), admin_url( 'admin.php?page=webcomic_settings' ), admin_url( 'admin.php?page=webcomic_collection' ) ); + + $this->update[ 'installed' ] = sprintf( __( 'Thanks for choosing Webcomic! %s', 'webcomic' ), $a ); + } + + /** + * Upgrades older versions. + * + * @package webcomic + * @since 3 + */ + function upgrade() { + $this->domain(); + + $this->option( 'version', $this->version ); + + $this->update[ 'upgraded' ] = sprintf( __( 'Thanks again for choosing Webcomic! Your support is much appreciated.', 'webcomic' ), 'https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=R6SH66UF6F9DG' ); + } + + /** + * Uninstalls the plugin + * + * @package webcomic + * @since 3 + */ + function uninstall() { + global $wpdb; + + $this->domain(); + + $cat = ( int ) get_option( 'default_category' ); + + if ( $collections = get_terms( 'webcomic_collection', 'get=all&fields=ids' ) ) + foreach ( $collections as $collection ) + wp_delete_term( $collection, 'webcomic_collection' ); + + if ( $storylines = get_terms( 'webcomic_storyline', 'get=all&fields=ids' ) ) + foreach ( $storylines as $storyline ) + wp_delete_term( $storyline, 'webcomic_storyline' ); + + if ( $characters = get_terms( 'webcomic_character', 'get=all&fields=ids' ) ) + foreach ( $characters as $character ) + wp_delete_term( $character, 'webcomic_character' ); + + $posts = $wpdb->get_col( "SELECT ID FROM $wpdb->posts WHERE post_type = 'webcomic_post'" ); + $wpdb->query( "UPDATE $wpdb->posts SET post_type = 'post' WHERE post_type = 'webcomic_post'" ); + $wpdb->query( "DELETE FROM $wpdb->postmeta WHERE meta_key IN ( 'webcomic' )" ); + + foreach ( $posts as $p ) + wp_set_object_terms( $p, $cat, 'category' ); + + $wp_user_search = new WP_User_Search( null, null, null ); + + foreach ( $wp_user_search->get_results() as $userid ) + delete_user_meta( $userid, 'webcomic' ); + + $this->option( array( + 'version' => $this->version, + 'uninstall' => true + ) ); + + $this->update[ 'uninstalled' ] = __( 'Information, files, and settings related to Webcomic have been removed.', 'webcomic' ); + } + + + + //// + // Template Tags + // + // These functions define new template tags + // to be used when designing WordPress themes. + //// + + /** + * Shortcut function for retrieving a single webcomic. + * + * Since WordPress doesn't have a get_post filter that can + * be used to automatically add webcomic metadata to the + * post object we're using get_posts with suppress_filters + * disabled and 'any' for post_status as a work around. + * Hopefully we can trash this later in favor of a hook. + * + * @package webcomic + * @since 3 + * + * @param int $id The post ID. + * @return A post object with Webcomic metadata, or false on error. + */ + function get_webcomic_post( $id ) { + return current( get_posts( array( 'p' => $id, 'post_type' => 'webcomic_post', 'post_status' => 'any', 'suppress_filters' => false ) ) ); + } + + /** + * Retrieves a properly formatted webcomic object for the a specified post or term. + * + * @package webcoomic + * @since 3 + * + * @param str $size The size of the object. Must be one of 'full', 'large', 'medium', or 'small'. + * @param str $type The type of item to retrieve objects for. Must be one of 'post', 'collection', 'storyline', or 'character'. + * @param int $key The file index to return. If specified, only that part of the object will be returned. + * @param int $id The post or term ID to retrieve objects for. Only required when $type is one of 'collection', 'storyline', or 'character'. + * @param str $format The format webcomic objects should be retrieved in. May be one of 'html', 'shtml', 'bbcode', or 'sbbcode'. + * @return A properly formatted webcomic object string, or false on error. + */ + function get_webcomic_object( $size, $type, $key = false, $id = false, $format = false ) { + global $wpdb, $post; + + if ( !( 'full' == $size || 'large' == $size || 'medium' == $size || 'small' == $size ) || ( !$id && ( 'collection' == $type || 'storyline' == $type || 'character' == $type ) ) || ( !$id && !$post ) || !$this->verify() ) + return false; + + $r = array(); + + if ( 'post' == $type ) + $obj = ( $id && $post->ID != $id ) ? $this->get_webcomic_post( $id ) : $post; + else + $obj = get_term( $id, "webcomic_$type" ); + + $secure = $this->option( 'secure_toggle' ); + + if ( ( $files = $obj->webcomic_files[ $size ] ) ) { + foreach ( $files as $k => $f ) { + if ( false !== $key && $key != $k ) + continue; + + if ( $format ) + $r[] = $f[ $format ]; + else + $r[] = ( $secure ) ? $f[ 'shtml' ] : $f[ 'html' ]; + } + } + + return apply_filters( 'webcomic_get_object', implode( '', $r ), $size, $type, $key, $id, $format ); + } + + // Display + + /** + * Retrieves a properly formatted webcomic object. + * + * @package webcomic + * @since 3 + * + * @param str $size The size of the object. Must be one of 'full', 'large', 'medium', or 'small'. + * @param str $link How to link the returned object. May be one of 'random', 'first', 'previous', 'next', 'last', or 'self'. + * @param str $taxonomy A taxonomy to limit the linked webcomics to if $link is not false. + * @param int|arr $terms A term ID or array of term ID's. Required if $taxonomy is not false. + * @param int $key The file index to return. If specified, only that part of the object will be returned. + * @param int $id The post ID to retrieve objects for. Only required when used outside of a WordPress loop. + * @return The webcomic object, or false on error. + */ + function get_the_webcomic_object( $size, $link = false, $taxonomy = false, $terms = false, $key = false, $id = false ) { + global $post; + + $id = ( intval( $id ) > 0 ) ? $id : $post->ID; + + if ( !( $obj = $this->get_webcomic_object( $size, 'post', $key, $id ) ) ) + return false; + + $kbd = ( $this->option( 'shortcut_toggle' ) ) ? ' webcomic-kbd-shortcut' : ''; + + if ( ( 'random' == $link || 'first' == $link || 'previous' == $link || 'next' == $link || 'last' == $link ) && ( $ids = $this->get_relative_webcomics( $taxonomy, $terms, $id ) ) ) + $r = '' . $obj . ''; + elseif ( 'self' == $link ) + $r = '' . $obj . '
    ' . get_bloginfo( 'name' ) . '' ) : "[url=" . get_permalink( $id ) . "]" . $obj . "[/url]\n\n[url=" . get_bloginfo( 'url' ) . "]" . get_bloginfo( 'name' ) . "[/url]"; + + return apply_filters( 'webcomic_get_embed', $r, $format, $size, $key, $id ); + } + + /** + * Retrieves embed code form field for sharing the specified webcomic. + * + * @package webcomic + * @since 3 + * + * @param str $format The format webcomic objects should be retrieved in. Must be one of 'html', 'shtml', 'bbcode', or 'sbbcode'. + * @param str $size The size of the object. Must be one of 'full', 'large', 'medium', or 'small'. + * @param int $key The file index to return. If specified, only that part of the object will be returned. + * @param int $id The post ID to retrieve objects for. Only required when used outside of a WordPress loop. + * @return Embed webcomic code in input field for sharing, or false on error. + */ + function get_the_webcomic_embed( $format, $size, $key = false, $id = false ) { + global $post; + + $id = ( intval( $id ) > 0 ) ? $id : $post->ID; + + if ( !( $code = $this->get_webcomic_embed( $format, $size, $key, $id ) ) ) + return false; + + $r = ''; + + return apply_filters( 'webcomic_get_the_embed', $r, $code, $format, $size, $key, $id ); + } + + // Navigation + + /** + * Retrieves webcomic ID's relative to the specified webcomic. + * + * This function can also be used outside of the loop + * to retrieve first, last, and random webcomics. + * + * @package webcomic + * @since 3 + * + * @param str $taxonomy A taxonomy to limit the returned ID's to. + * @param int|arr $terms A term ID or array of term ID's. Required if $taxonomy is not false. + * @param int $id Webcomic ID that returned ID's will be relative to. + * @return An array of webcomic ID's, or false on error. + */ + function get_relative_webcomics( $taxonomy = false, $terms = false, $id = false, $global = false ) { + global $wpdb, $post; + + if ( !$this->verify() ) + return false; + + $id = ( !$id && !empty( $post ) ) ? $post->ID : $id; + $ck = $id . '_' . hash( 'md5', $taxonomy . implode( ( array ) $terms, '' ) . $global ); + + if ( $r = wp_cache_get( $ck, 'get_relative_webcomics' ) ) + return $r; + + if ( $terms && $taxonomy && ( 'webcomic_collection' == $taxonomy || 'webcomic_storyline' == $taxonomy || 'webcomic_character' == $taxonomy ) ) { + $terms = ( array ) $terms; + + foreach ( $terms as $k => $v ) + $terms[ $k ] = ( int ) $v; + } + + $join = ( $terms ) ? "INNER JOIN $wpdb->term_relationships AS tr ON p.ID = tr.object_id INNER JOIN $wpdb->term_taxonomy tt ON tr.term_taxonomy_id = tt.term_taxonomy_id AND tt.taxonomy = '$taxonomy' AND tt.term_id IN ( '" . implode( "', '", $terms ) . "' )" : ''; + + if ( !$global && !$join ) { + $wc = current( wp_get_object_terms( $id, 'webcomic_collection' ) ); + $join = "INNER JOIN $wpdb->term_relationships AS tr ON p.ID = tr.object_id INNER JOIN $wpdb->term_taxonomy tt ON tr.term_taxonomy_id = tt.term_taxonomy_id AND tt.taxonomy = 'webcomic_collection' AND tt.term_id = '$wc->term_id'"; + } + + $query = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM $wpdb->posts AS p $join WHERE p.post_type = 'webcomic_post' AND p.post_status IN ( 'publish', 'private' ) ORDER BY p.post_date ASC" ) ); + $r = array(); + + if ( !empty( $query ) ) { + $r[ 'random' ] = ( int ) $query[ array_rand( $query, 1 ) ]; + $r[ 'last' ] = ( int ) end( $query ); + $r[ 'first' ] = ( int ) reset( $query ); + + if ( false !== ( $key = array_search( $id, $query ) ) ) { + $r[ 'previous' ] = ( int ) ( ( $key - 1 ) > -1 && isset( $query[ $key - 1 ] ) ) ? $query[ $key - 1 ] : $id; + $r[ 'next' ] = ( int ) ( ( $key + 1 ) < count( $query ) && isset( $query[ $key + 1 ] ) ) ? $query[ $key + 1 ] : $id; + $r[ 'first-bookend' ] = $r[ 'previous-bookend' ] = ( int ) ( $wc->webcomic_bookend[ 'first' ] ) ? $wc->webcomic_bookend[ 'first' ] : $id; + $r[ 'last-bookend' ] = $r[ 'next-bookend' ] = ( int ) ( $wc->webcomic_bookend[ 'last' ] ) ? $wc->webcomic_bookend[ 'last' ] : $id; + } + } + + wp_cache_add( $ck, $r, 'get_relative_webcomics' ); + + return apply_filters( 'webcomic_get_relative', $r, $id, $taxonomy, $terms ); + } + + /** + * Retrieves webcomic permalink URL relative to the current webcomic. + * + * @package webcomic + * @since 3 + * + * @param str $key The releative key ID. Must be one of 'first', 'previous', 'next', 'last', or 'random'. + * @param str $taxonomy A taxonomy to limit the returned ID's to. + * @param int|arr $terms A term ID or array of term ID's. Required if $taxonomy is not false. + * @param int $id Webcomic ID that returned ID's will be relative to. + * @param bool $global Uses URL parameters instead of regular permalink if true. + * @return The permalink URL, or false on error. + */ + function get_relative_webcomic_url( $key, $taxonomy = false, $terms = false, $id = false, $global = false ) { + if ( !( $ids = $this->get_relative_webcomics( $taxonomy, $terms, $id, $global ) ) || !$ids[ $key ] ) + return false; + + global $post; + + $end = ( 'random' == $key ) ? $ids[ $key ] : $ids[ $key . '-bookend' ]; + + if ( $global ) + $url = get_bloginfo( 'url' ) . '?relative_webcomic=' . implode( '/', array( $key, $taxonomy, implode( ',', ( array ) $terms ), $id ) ); + else + $url = ( !$id && $post->ID == $ids[ $key ] ) ? get_permalink( $end ) : get_permalink( $ids[ $key ] ); + + return apply_filters( 'webcomic_get_relative_url', $url, $key, $taxonomy, $terms ); + } + + /** + * Retrieves a properly formatted webcomic link relative to the current webcomic. + * + * @package webcomic + * @since 3 + * + * @param str $key The releative key ID. Must be one of 'first', 'previous', 'next', 'last', or 'random'. + * @param str $format The format of the returned link. Should contain %link token. + * @param str $link What to display for the link text. May contain the %label, %title, %date, %thumb-small,-# %thumb-medium-#, %thumb-large-#, and %thumb-full-# tokens. + * @param str $taxonomy A taxonomy to limit the returned ID's to. + * @param int|arr $terms A term ID or array of term ID's. Required if $taxonomy is not false. + * @param int $id Webcomic ID that returned ID's will be relative to. + * @param bool $global Uses URL parameters instead of regular permalink if true. + * @return Formatted webcomic link, or false on error. + */ + function get_relative_webcomic_link( $key, $format, $link, $taxonomy = false, $terms = false, $id = false, $global = false ) { + if ( !( $ids = $this->get_relative_webcomics( $taxonomy, $terms, $id, $global ) ) || !$ids[ $key ] ) + return false; + + global $post; + + $this->domain(); + + switch ( $key ) { + case 'random' : $label = '' . __( '∞ Random ∞', 'webcomic' ) . ''; break; + case 'first' : + case 'first-bookend': $label = '' . __( '« First', 'webcomic' ) . ''; break; + case 'last' : + case 'last-bookend' : $label = '' . __( 'Last »', 'webcomic' ) . ''; break; + case 'previous' : $label = '' . __( '‹ Previous', 'webcomic' ) . ''; break; + case 'next' : $label = '' . __( 'Next ›', 'webcomic' ) . ''; break; + default: return false; + } + + $current = ( !$id && !$global && $post->ID == $ids[ $key ] && 'random' != $key ) ? ' current-webcomic' : ''; + $kbd = ( $this->option( 'shortcut_toggle' ) ) ? ' webcomic-kbd-shortcut' : ''; + $date = get_the_time( get_option( 'date_format' ), $ids[ $key ] ); + $title = get_the_title( $ids[ $key ] ); + $match = false; + + if ( preg_match( '/\%thumb-(full|large|medium|small)(?:-(\d+))?/', $link, $match ) ) + $link = preg_replace( "/$match[0]/", $this->get_webcomic_object( $match[ 1 ], 'post', $match[ 2 ], $ids[ $key ] ), $link ); + + $link = str_replace( '%label', $label, $link ); + $link = str_replace( '%title', $title, $link ); + $link = str_replace( '%date', $date, $link ); + $link = '' . $link . ''; + $format = str_replace( '%link', $link, $format ); + + return apply_filters( 'webcomic_get_relative_link', $format, $link, $key, $taxonomy, $terms ); + } + + /** + * Retrieves the appropriate URL to the purchase webcomic print template for the specified webcomic. + * + * A simple URL parameter redirects to the purchase webcomic print + * template for any webcomic post, but this function determines + * whether permalinks are being used and appends it to the post + * permalink as necessary. + * + * @package webcomic + * @since 3 + * + * @param int $id Webcomic ID to retrieve the purchase print URL for. + * @return The purchase URL, or false on error. + */ + function get_purchase_webcomic_url( $id = false ) { + global $wp_rewrite, $post; + + if ( ( !$post && !$id ) || !$this->option( 'paypal_business' ) || !$this->verify() ) + return false; + + $id = ( intval( $id ) > 0 ) ? $id : $post->ID; + $url = get_permalink( $id ); + + $r = ( is_object( $wp_rewrite ) && $wp_rewrite->using_permalinks() ) ? $url . '?purchase_webcomic_print=' . $id : $url . '&purchase_webcomic_print=' . $id; + + return apply_filters( 'webcomic_get_purchase_url', $r, $id ); + } + + /** + * Retrieves a properly formatted purchase webcomic print link for the specified webcomic. + * + * @package webcomic + * @since 3 + * + * @param str $format The format of the returned link. Should contain %link token. + * @param str $link What to display for the link text. May contain the %label, %title, %date, %thumb-small-#, %thumb-medium-#, %thumb-large-#, and %thumb-full-# tokens. + * @param int $id Webcomic ID to retrieve the purchase print URL for. + * @return Formatted purchase webcomic link, or false on error. + */ + function get_purchase_webcomic_link( $format, $link, $id = false ) { + global $post; + + $this->domain(); + + if ( !$post && !$id ) + return false; + + $id = ( intval( $id ) > 0 ) ? $id : $post->ID; + + if ( !( $url = $this->get_purchase_webcomic_url( $id ) ) ) + return false; + + $kbd = ( $this->option( 'shortcut_toggle' ) ) ? ' webcomic-kbd-shortcut' : ''; + $date = get_the_time( get_option( 'date_format' ), $id ); + $title = get_the_title( $id ); + $label = '' . __( 'Purchase Webcomic', 'webcomic' ) . ''; + $closed = ( $this->webcomic_prints_open() ) ? '' : ' purchase-webcomic-link-closed'; + $match = false; + + if ( preg_match( '/\%thumb-(full|large|medium|small)(?:-(\d+))?/', $link, $match ) ) + $link = preg_replace( "/$match[0]/", $this->get_webcomic_object( $match[ 1 ], 'post', $match[ 2 ], $id ), $link ); + + $link = str_replace( '%label', $label, $link ); + $link = str_replace( '%title', $title, $link ); + $link = str_replace( '%date', $date, $link ); + $link = '' . $link . ''; + $format = str_replace( '%link', $link, $format ); + + return apply_filters( 'webcomic_get_purchase_link', $format, $link, $id ); + } + + /** + * Retrieves the appropriate URL to the purchase webcomic print template for the specified webcomic. + * + * A simple URL parameter calls the bookmark webcomic function + * for any webcomic post, but this function determines + * whether permalinks are being used and appends it to the post + * permalink as necessary. + * + * @package webcomic + * @since 3 + * + * @param str $key The type of bookmark link, one of 'bookmark', 'return', or 'remove' + * @param int $id Webcomic ID to retrieve the purchase print URL for. + * @return The purchase URL, or false on error. + */ + function get_bookmark_webcomic_url( $key, $id = false ) { + global $wp_rewrite, $post; + + if ( ( !$post && !$id ) || !$this->verify() ) + return false; + + $id = ( intval( $id ) > 0 ) ? $id : $post->ID; + $wc = current( wp_get_object_terms( $id, 'webcomic_collection' ) ); + $url = get_permalink( $id ); + + $r = ( is_object( $wp_rewrite ) && $wp_rewrite->using_permalinks() ) ? $url . '?bookmark_webcomic=' . $id . '/' . $key . '/' . $wc->term_id : $url . '&purchase_webcomic_print=' . $id . '/' . $key . '/' . $wc->term_id; + + return apply_filters( 'webcomic_get_bookmark_url', $r, $key, $id ); + } + + /** + * Retrieves a properly formatted bookmark webcomic link for the specified webcomic. + * + * @package webcomic + * @since 3 + * + * @param str $key The type of bookmark link, one of 'bookmark', 'return', or 'remove'. + * @param str $format The format of the returned link. Should contain %link token. + * @param str $link What to display for the link text. May contain the %label, %title, %date, %thumb-small-#, %thumb-medium-#, %thumb-large-#, and %thumb-full-# tokens. + * @param int $id Webcomic ID to retrieve the bookmark URL for. + * @return Formatted bookmark webcomic link, or false on error. + */ + function get_bookmark_webcomic_link( $key, $format, $link, $id = false ) { + global $wp_rewrite, $post; + + $wc = current( wp_get_object_terms( $post->ID, 'webcomic_collection' ) ); + + if ( ( !$post && !$id ) || empty( $wc ) || is_wp_error( $wc ) || !is_singular() || 'webcomic_post' != $post->post_type ) + return false; + + $this->domain(); + + $id = ( intval( $id ) > 0 ) ? $id : $post->ID; + + if ( !( $url = $this->get_bookmark_webcomic_url( $key, $id ) ) ) + return false; + + switch ( $key ) { + case 'bookmark': $label = '' . __( 'Bookmark', 'webcomic' ) . ''; break; + case 'return' : $label = '' . __( 'Return', 'webcomic' ) . ''; break; + case 'remove' : $label = '' . __( 'Remove', 'webcomic' ) . ''; break; + default: return false; + } + + $kbd = ( $this->option( 'shortcut_toggle' ) ) ? ' webcomic-kbd-shortcut' : ''; + $date = get_the_time( get_option( 'date_format' ), $post->ID ); + $title = get_the_title( $post->ID ); + $match = false; + + if ( preg_match( '/\%thumb-(full|large|medium|small)(?:-(\d+))?/', $link, $match ) ) + $link = preg_replace( "/$match[0]/", $this->get_webcomic_object( $match[ 1 ], 'post', $match[ 2 ], $id ), $link ); + + $link = str_replace( '%label', $label, $link ); + $link = str_replace( '%title', $title, $link ); + $link = str_replace( '%date', $date, $link ); + $link = '' . $link . ''; + $format = str_replace( '%link', $link, $format ); + + return apply_filters( 'webcomic_get_bookmark_link', $format, $link, $key ); + } + + // Related + + /** + * Retrieves webcomic ID's related to the specified post by storylines and/or characters. + * + * @package webcomic + * @since 3 + * + * @param bool $storylines Match based on storylines. + * @param bool $characters Match based on characters. + * @param int $id Webcomic ID to reference. + * @return arr Related Webcomic ID's, or false on error. + */ + function get_related_webcomics( $storylines = true, $characters = true, $id = false ) { + global $post; + + if ( ( !$post && !$id ) || !$this->verify() ) + return false; + + $id = ( intval( $id ) > 0 ) ? $id : $post->ID; + $storylines = ( $storylines ) ? wp_get_object_terms( $id, 'webcomic_storyline', array( 'fields' => 'ids' ) ) : array(); + $characters = ( $characters ) ? wp_get_object_terms( $id, 'webcomic_character', array( 'fields' => 'ids' ) ) : array(); + + if ( !empty( $storylines ) && !is_wp_error( $storylines ) ) + $story_posts = get_objects_in_term( $storylines[ array_rand( $storylines ) ], 'webcomic_storyline' ); + + if ( !empty( $characters ) && !is_wp_error( $characters ) ) + $character_posts = get_objects_in_term( $characters[ array_rand( $characters ) ], 'webcomic_character' ); + + if ( $story_posts && $character_posts ) + $posts = array_intersect( $story_posts, $character_posts ); + elseif ( !$story_posts && !$character_posts ) + return false; + else + $posts = ( !empty( $story_posts ) ) ? $story_posts : $character_posts; + + if ( empty( $posts ) || is_wp_error( $posts ) ) + return false; + + if ( false !== ( $key = array_search( $id, $posts ) ) ) + unset( $posts[ $key ] ); + + return apply_filters( 'webcomic_get_related', $posts, $storylines, $characters, $id ); + } + + /** + * Retrieves a formatted list of related webcomics. + * + * @package webcomic + * @since 3 + * + * @param arr|str $args An array or string of arguments (see below for full details). + * @return Formatted list of related webcomics, or false on error. + */ + function get_the_related_webcomics( $args = false ) { + $defaults = array( + 'format' => false, //str Format to display the terms in. Must be one of 'ulist', 'olist', or 'dropdown' + 'separator' => false, //str Text string to place between posts when 'format' is false. + 'before' => false, //str Text string to place before the generated output. + 'after' => false, //str Text string to place after the generated output. + 'number' => 5, //int The number of related posts to return. + 'order' => 'ASC', //str The order to return posts in, either ASC (oldest first) or DESC (newest first). Sorts by post ID. + 'image' => false, //str Displays images for post links instead of titles if non-false and 'format' is not 'dropdown'. If set, should be one of 'full', 'large', 'medium', or 'small'. + 'imagekey' => false, //int The file index to use when 'image' is non-false. If specified, only that part of the image object will be returned. + 'label' => false, //str Text string to display for the first null option when 'format' is 'dropdown'. + 'storylines' => true, //bool Match posts based on storylines + 'characters' => true, //bool Match posts based on characters + 'id' => false //int ID of the object to retrieve related posts for. + ); $args = wp_parse_args( $args, $defaults ); extract( $args ); + + if ( !( $posts = $this->get_related_webcomics( $storylines, $characters, $id ) ) ) + return false; + + if ( 'DESC' == $order ) + $posts = array_reverse( $posts ); + + if ( $number > 0 ) + $posts = array_slice( $posts, 0, $number ); + + if ( $separator ) + $format = false; + elseif ( !$format ) + $format = 'ulist'; + + foreach ( $posts as $p ) { + $t = ( 'dropdown' != $format && ( 'full' == $image || 'large' == $image || 'medium' == $image || 'small' == $image ) ) ? $this->get_webcomic_object( $image, 'post', $imagekey, $p ) : get_the_title( $p ); + $u = get_permalink( $p ); + + if ( 'ulist' == $format || 'olist' == $format ) { + $s1 = ''; + } elseif ( 'dropdown' == $format ) { + $s1 = ''; + } else { + $s1 = false; + $s2 = $separator; + } + + $l[] = $s1 . '' . $t . '' . $s2; + } + + if ( 'ulist' == $format ) { + $p1 = ''; + } elseif ( 'olist' == $format ) { + $p1 = ''; + } elseif ( 'dropdown' == $format ) { + $p1 = ''; + } + + $l = implode( '', $l ); + $l = ( $separator ) ? substr( $l, 0, strrpos( $l, $separator ) ) : $l; + + $r = $before . $p1 . $l . $p2 . $after; + + return apply_filters( 'webcomic_get_the_related', $r, $args ); + } + + // Buffers + + /** + * Retrieves webcomic ID's for webcomics schedules to publish in the future. + * + * @package webcomic + * @since 3 + * + * @param arr|int $terms An array of term ID's to limit the search for buffer webcomics by. + * @param str $taxonomy The taxonomy the term ID's belong to. Required. + * @return An array of webcomic ID's, or false on error. + */ + function get_buffer_webcomics( $terms = false, $taxonomy = false ) { + if ( !$this->verify() ) + return false; + + $ck = 'webcomic_buffer_' . hash( 'md5', implode( ( array ) $terms, '' ) . $taxonomy ); + + if ( $r = wp_cache_get( $ck, 'get_buffer_webcomics' ) ) + return $r; + + global $wpdb; + + $r = array(); + + if ( $terms && $taxonomy && ( 'webcomic_collection' == $taxonomy || 'webcomic_storyline' == $taxonomy || 'webcomic_character' == $taxonomy ) ) { + $terms = ( array ) $terms; + + foreach ( $terms as $k => $v ) + $terms[ $k ] = ( int ) $v; + } + + $join = ( $terms ) ? "INNER JOIN $wpdb->term_relationships AS tr ON p.ID = tr.object_id INNER JOIN $wpdb->term_taxonomy tt ON tr.term_taxonomy_id = tt.term_taxonomy_id AND tt.taxonomy = '$taxonomy' AND tt.term_id IN ( '" . implode( "', '", $terms ) . "' )" : ""; + $query = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM $wpdb->posts AS p $join WHERE p.post_type = 'webcomic_post' AND p.post_status = 'future' ORDER BY p.post_date DESC" ) ); + + if ( empty( $query ) ) + return false; + + wp_cache_add( $ck, $query, 'get_buffer_webcomics' ); + + return apply_filters( 'webcomic_get_buffer', $query, $term, $taxonomy ); + } + + /** + * Retrieves a formatted list of buffer webcomics. + * + * @package webcomic + * @since 3 + * + * @param arr|str $args An array or string of arguments (see below for full details). + * @return Formatted list of related webcomics, or false on error. + */ + function get_the_buffer_webcomics( $args = false ) { + $defaults = array( + 'format' => false, //str Format to display the terms in. Must be one of 'ulist' or 'olist' + 'separator' => false, //str Text string to place between posts when 'format' is false. + 'before' => false, //str Text string to place before the generated output. + 'after' => false, //str Text string to place after the generated output. + 'number' => 1, //int The number of buffer posts to return. + 'order' => 'DESC', //str The order to return posts in, either ASC (oldest first) or DESC (newest first). Sorts by post date. + 'image' => false, //str Displays images for post links instead of titles if non-false. If set, should be one of 'full', 'large', 'medium', or 'small'. + 'imagekey' => false, //int The file index to use when 'image' is non-false. If specified, only that part of the image object will be returned. + 'terms' => false, //arr An array of term ID's to limit the search for buffer webcomics to. + 'taxonomy' => false //str The taxonomy 'terms' belong to. Required if 'terms' is non-false. + ); $args = wp_parse_args( $args, $defaults ); extract( $args ); + + if ( !( $posts = $this->get_buffer_webcomics( $terms, $taxonomy ) ) ) + return false; + + if ( 'ASC' == $order ) + $posts = array_reverse( $posts ); + + if ( $number > 0 ) + $posts = array_slice( $posts, 0, $number ); + + if ( $separator ) + $format = false; + elseif ( !$format ) + $format = 'ulist'; + + foreach ( $posts as $p ) { + $t = ( 'full' == $image || 'large' == $image || 'medium' == $image || 'small' == $image ) ? preg_replace( '/title="*."/', 'title="' . the_title_attribute( 'echo=0' ) . ' (' . get_the_time( get_option( 'date_format' ), $p ) . ' @ ' . get_the_time( get_option( 'time_format' ), $p ) . ')"', $this->get_webcomic_object( $image, 'post', $imagekey, $p ) ) : '' . get_the_title( $p ) . ''; + + if ( 'ulist' == $format || 'olist' == $format ) { + $s1 = '
  • '; + $s2 = '
  • '; + } else { + $s1 = false; + $s2 = $separator; + } + + $l[] = $s1 . $t . $s2; + } + + if ( 'ulist' == $format ) { + $p1 = '
      '; + $p2 = '
    '; + } elseif ( 'olist' == $format ) { + $p1 = '
      '; + $p2 = '
    '; + } + + $l = implode( '', $l ); + $l = ( $separator ) ? substr( $l, 0, strrpos( $l, $separator ) ) : $l; + + $r = $before . $p1 . $l . $p2 . $after; + + return apply_filters( 'webcomic_get_the_buffer', $r, $args ); + } + + // Verification + + /** + * Retrieves a fully formatted age verification form. + * + * @package webcomic + * @since 3 + * + * @param str $label String label to use for the submit button. + * @return Formatted HTML form, or false on error. + */ + function get_webcomic_verify_form( $label = false ) { + global $post; + + $this->domain(); + + $i = 1; + $day = $year = false; + + while ( $i < 32 ) { + $day .= ''; + $i++; + } $i = $x = intval( date( 'Y' ) ); + + while ( $i >= $x - 80 ) { + $year .= ''; + $i--; + } unset( $i, $x ); + + $r = '
    ' . wp_nonce_field( 'verify_webcomic_age', '_wpnonce', true, false ) . ' + + + + + + +
    + '; + + return apply_filters( 'webcomic_get_verify_form', $r, $label ); + } + + /** + * Retrieves the minimum age required to access the specified content. + * + * @package webcomic + * @since 3 + * + * @param + */ + function get_webcomic_verify_age( $id = false ) { + global $post; + + $id = ( intval( $id ) > 0 ) ? $id : $post->ID; + $wc = current( wp_get_object_terms( $id, 'webcomic_collection' ) ); + + if ( empty( $wc ) || is_wp_error( $wc ) ) + return false; + + return apply_filters( 'webcomic_get_verify_age', $wc->term_group, $id ); + } + + // Donations + + /** + * Retrieves a formatted donation amount for display. + * + * This function formats the donation amount for display purposes. + * It should not be used where precise values are required. + * + * @param str $dec The character to use as a decimal. Defaults to '.'. + * @param str $sep The character to use to separate thousands. Defaults to ','. + * @return Formatted donation amount string, or false on error. + */ + function get_the_webcomic_donation_amount( $dec = false, $sep = false ) { + if ( !( $cost = $this->option( 'paypal_donation' ) ) ) + return false; + + $dec = ( $dec ) ? $dec : '.'; + $sep = ( $sep ) ? $decimal : ','; + + $r = number_format( $cost, 2, $dec, $sep ) . ' ' . $this->option( 'paypal_currency' ); + + return apply_filters( 'webcomic_get_the_donation_amount', $r, $dec, $sep ); + } + + /** + * Retrieves necessary form fields for donations. + * + * @package webcomic + * @since 3 + * + * @return Necessary hidden form fields, or false on error. + */ + function get_webcomic_donation_fields() { + if ( !$this->option( 'paypal_business' ) ) + return false; + + $r = ' + + ' . ( ( $this->option( 'paypal_donation' ) ) ? '' : '' ) . ' + + + + + '; + + return apply_filters( 'webcomic_get_donation_fields', $r ); + } + + /** + * Retrieves a complete webcomic donation form. + * For testing, use https://www.sandbox.paypal.com/cgi-bin/webscr + * + * @package webcomic + * @since 3 + * + * @param str $label The label to display for the submit button. Defaults to 'Buy Now' for single-item method and 'Add to Cart' for shopping cart method. + * @param int $id Webcomic ID to reference for form data. + * @return The complete HTML form, or false on error. + */ + function get_webcomic_donation_form( $label = false ) { + if ( !$this->option( 'paypal_business' ) ) + return false; + + $label = ( $label ) ? $label : __( 'Donate', 'webcomic' ); + $r = '
    ' . $this->get_webcomic_donation_fields() . '
    '; + + return apply_filters( 'webcomic_get_donation_form', $r, $label ); + } + + // Prints + + /** + * Checks to see if prints are being sold for the specified post. + * + * @packgae webcomic + * @since 3 + * + * @param int $id Webcomic ID to check print status for. + * @param bool $original If true, checks to see if the original is still for sale. + * @return True if prints are being sold, false otherwise. + */ + function webcomic_prints_open( $id = false, $original = false ) { + global $post; + + if ( !$post && !$id ) + return false; + + $id = ( intval( $id ) > 0 ) ? $id : $post->ID; + $post_meta = current( get_post_meta( $id, 'webcomic' ) ); + + if ( $original ) + return $post_meta[ 'paypal' ][ 'original' ]; + else + return $post_meta[ 'paypal' ][ 'prints' ]; + } + + /** + * Retrieves the specified cost value for a webcomic print. + * + * @package webcomic + * @since 3 + * + * @param str $cost The value to return. Must be one of 'price', 'collection-price', 'base-price', 'shipping', 'collection-shipping', or 'base-shipping'. + * @param str $type The type of value to return. Must be one of 'domestic', 'international', or 'original'. + * @param int $id Webcomic ID to retrieve cost for. + * @return float The specified cost, or false on error. + */ + function get_purchase_webcomic_cost( $cost, $type, $id = false ) { + global $post; + + if ( !$post && !$id ) + return false; + + $x = ( 'domestic' == $type ) ? 'd' : 'i'; + $x = ( 'original' == $type ) ? 'o' : $x; + $id = ( intval( $id ) > 0 ) ? $id : $post->ID; + $t = end( explode( '-', $cost ) ); + $wc = current( wp_get_object_terms( $id, 'webcomic_collection' ) ); + $base = $this->option( 'paypal_' . $t . '_' . $x ); + + if ( empty( $wc ) || is_wp_error( $wc ) ) + return false; + + $post_meta = current( get_post_meta( $id, 'webcomic' ) ); + $amount = array( $wc->webcomic_paypal[ $t . '_' . $x ], $post_meta[ 'paypal' ][ $t . '_' . $x ] ); + + if ( 'base-price' == $cost || 'base-shipping' == $cost || 'collection-price' == $cost || 'collection-shipping' == $cost ) + unset( $amount[ 1 ] ); + + if ( 'base-price' == $cost || 'base-shipping' == $cost ) + unset( $amount[ 0 ] ); + + $r = $this->price( $base, $amount ); + + return apply_filters( 'webcomic_get_purchase_cost', $r, $cost, $type, $id ); + } + + /** + * Retrieves a formatted cost value for display. + * + * This function formats the cost value of a webcomic print + * for display purposes. It should not be used where precise + * values are required. + * + * @param str $cost The value to return. Must be one of 'price', 'collection-price', 'base-price', 'shipping', 'collection-shipping', or 'base-shipping'. + * @param str $type The type of value to return. Must be one of 'domestic', 'international', or 'original'. + * @param str $dec The character to use as a decimal. Defaults to '.'. + * @param str $sep The character to use to separate thousands. Defaults to ','. + * @param int $id Webcomic ID to retrieve cost for. + * @return Formatted cost string, or false on error. + */ + function get_the_purchase_webcomic_cost( $cost, $type, $dec = false, $sep = false, $id = false ) { + if ( !is_float( $cost = $this->get_purchase_webcomic_cost( $cost, $type, $id ) ) ) + return false; + + $dec = ( $dec ) ? $dec : '.'; + $sep = ( $sep ) ? $sep : ','; + + $r = number_format( $cost, 2, $dec, $sep ) . ' ' . $this->option( 'paypal_currency' ); + + return apply_filters( 'webcomic_get_the_purchase_cost', $r, $cost, $type, $dec, $sep, $id ); + } + + /** + * Returns information about the specified adjustment. + * + * @package webcomic + * @since 3 + * + * @param str $adjustment The adjustment to return, one of 'collection-price', 'collection-shipping', 'post-price', or 'post-shipping'. + * @param str $type The type of value to return. Must be one of 'domestic', 'international', or 'original'. + * @return arr Array containing adjustment information, or false on error. + */ + function get_purchase_webcomic_adjustment( $adjustment, $type, $id = false ) { + global $post; + + if ( !$post && !$id ) + return false; + + $id = ( intval( $id ) > 0 ) ? $id : $post->ID; + + if ( false !== strpos( $adjustment, 'post' ) ) { + $post_meta = current( get_post_meta( $id, 'webcomic' ) ); + $paypal = $post_meta[ 'paypal' ]; } else { - add_option( 'webcomic_version', '2.1.1' ); + $wc = current( wp_get_object_terms( $id, 'webcomic_collection' ) ); + $paypal = $wc->webcomic_paypal; + } + + if ( !$paypal ) + return false; + + $r = array(); + $x = ( 'domestic' == $type ) ? 'd' : 'i'; + $x = ( 'original' == $type ) ? 'o' : $x; + $t = end( explode( '-', $adjustment ) ); + + $r = $paypal[ $t . '_' . $x ]; + + if ( !$r[ 'amount' ] ) + return false; + + return apply_filters( 'webcomic_get_purchase_adjustment', $r, $adjustment, $type, $id ); + } + + /** + * Retrieves a formatted adjustment value for display. + * + * This function formats the adjustment value of a webcomic print + * for display purposes. It should not be used where precise + * values are required. + * + * @param str $adjustment The adjustment to return, one of 'collection-price', 'collection-shipping', 'post-price', or 'post-shipping'. + * @param str $type The type of value to return. Must be one of 'domestic', 'international', or 'original'. + * @param str $dec The character to use as a decimal. Defaults to '.'. + * @param str $sep The character to use to separate thousands. Defaults to ','. + * @param int $id Webcomic ID to retrieve cost for. + * @return Formatted adjustment string, or false on error. + */ + function get_the_purchase_webcomic_adjustment( $adjustment, $type, $dec = false, $sep = false, $id = false ) { + if ( !( $a = $this->get_purchase_webcomic_adjustment( $adjustment, $type, $id ) ) ) + return false; + + $dec = ( $dec ) ? $dec : '.'; + $sep = ( $sep ) ? $sep : ','; + $adj = ( $a > 0 ) ? '+ ' : '- '; + + $r = $adj . number_format( $a, 0, $dec, $sep ) . '%'; + + return apply_filters( 'webcomic_get_the_purchase_adjustment', $r, $cost, $type, $dec, $sep, $id ); + } + + /** + * Retrieves necessary form fields for the specified type of print form. + * + * @package webcomic + * @since 3 + * + * @param str $type The type of form, one of 'domestic', 'international', or 'original'. + * @param bool $cart If true, displays the cart (does not add item) when paypal_method is _cart. + * @param int $id Webcomic ID to reference for form data. + * @return Necessary hidden form fields, or false on error. + */ + function get_purchase_webcomic_fields( $type, $cart = false, $id = false ) { + global $post; + + if ( ( !$post && !$id ) || !$this->option( 'paypal_business' ) || !$this->verify() ) + return false; + + $id = ( intval( $id ) > 0 ) ? $id : $post->ID; + + if ( !$this->webcomic_prints_open( $id ) || ( 'original' == $type && !$this->webcomic_prints_open( $id, true ) ) ) + return false; + + $bn = ( '_cart' == $this->option( 'paypal_method' ) && 'original' != $type ) ? 'ShoppingCart' : 'BuyNow'; + $cart = ( $cart ) ? '' : ''; + $method = ( 'original' == $type ) ? '_xclick' : $this->option( 'paypal_method' ); + + $r = ' + + + + + + + + + + '; + + if ( 'original' != $type ) + $r .= ''; + + if ( '_cart' == $method ) + $r .= '' . $cart; + + return apply_filters( 'webcomic_get_purchase_fields', $r, $type, $id ); + } + + /** + * Retrieves a complete purchase webcomic form of the specified type. + * + * @package webcomic + * @since 3 + * + * @param str $type The type of form, one of 'domestic', 'international', or 'original'. + * @param str $label The label to display for the submit button. Defaults to 'Buy Now' for single-item method and 'Add to Cart' for shopping cart method. + * @param bool $cart Displays the cart contents for shopping cart method when true. + * @param int $id Webcomic ID to reference for form data. + * @return The complete HTML form, or false on error. + */ + function get_purchase_webcomic_form( $type, $label = false, $cart = false, $id = false ) { + global $post; + + if ( ( !$post && !$id ) || !$this->option( 'paypal_business' ) || !( $fields = $this->get_purchase_webcomic_fields( $type, $id ) ) ) + return false; + + $id = ( intval( $id ) > 0 ) ? $id : $post->ID; + + if ( !$label && '_cart' == $this->option( 'paypal_method' ) && $cart && 'original' != $type ) + $label = __( 'View Cart', 'webcomic' ); + elseif ( !$label && '_cart' == $this->option( 'paypal_method' ) && 'original' != $type ) + $label = __( 'Add to Cart', 'webcomic' ); + elseif ( !$label ) + $label = __( 'Buy Now', 'webcomic' ); + + $r = '
    ' . $fields . '
    '; //https://www.sandbox.paypal.com/cgi-bin/webscr + + return apply_filters( 'webcomic_get_purchase_form', $r, $type, $label, $id ); + } + + // Transcripts + + /** + * Includes the transcripts template. + * + * @package webcomic + * @since 3 + * + * @param str $file The filename to retrieve. + * @return False on error. + */ + function webcomic_transcripts_template( $file = false ) { + global $with_webcomic_transcripts, $webcomic_transcript, $post, $wpdb, $user_login, $user_ID, $user_identity; + + if ( !( is_single() || is_page() || $with_webcomic_transcripts ) || !$post || !$this->verify() ) + return false; + + $file = ( $file ) ? $file : 'webcomic_transcripts.php'; + $form = locate_template( array( $file ) ) ? locate_template( array( $file ) ) : $this->dir . 'webcomic-includes/template-transcripts.php'; + + require_once( $form ); + } + + /** + * Checks to see if any published transcripts exist. + * + * @package webcomic + * @since 3 + * + * @param str $status The status to check for. Must be one of 'draft', 'pending', or 'publish'. + * @return True or the number of transcripts, false otherwise. + */ + function have_webcomic_transcripts( $status = false ) { + global $post; + + if ( !$post ) + return false; + + $post_meta = current( get_post_meta( $post->ID, 'webcomic' ) ); + + $x = 0; + $r = ( empty( $post_meta[ 'transcripts' ] ) ) ? false : true; + $s = ( $status ) ? $status : 'publish'; + + if ( $r ) { + foreach ( $post_meta[ 'transcripts' ] as $t ) + if ( $s == $t[ 'status' ] ) + $x++; + + $r = ( $x ) ? $x : false; + } + + return $r; + } + + /** + * Checks to see if transcribing is allowed for the specified post. + * + * @packgae webcomic + * @since 3 + * + * @return True if transcribing is allowed, false otherwise. + */ + function webcomic_transcripts_open() { + global $post; + + if ( !$post ) + return false; + + $i = 0; + $post_meta = current( get_post_meta( $post->ID, 'webcomic' ) ); + $languages = $this->option( 'transcribe_language' ); + + foreach ( $languages as $k => $v ) + if ( empty( $post_meta[ 'transcripts' ][ $k ][ 'status' ] ) || ( 'publish' != $post_meta[ 'transcripts' ][ $k ][ 'status' ] && 'draft' != $post_meta[ 'transcripts' ][ $k ][ 'status' ] ) ) + $i++; + + return ( $i && $post_meta[ 'transcribe_toggle' ] ); + } + + /** + * Displays a properly formatted transcribing form. + * + * @package webcomic + * @since 3 + * + * @param arr|str $args Arguments for the generated form (see below). + * @param int $id Webcomic ID to display transcribe form for. + * @return False if no Webcomic ID can be found. + */ + function webcomic_transcribe_form( $args = false ) { + if ( !$this->webcomic_transcripts_open() ) { + do_action( 'webcomic_transcribe_form_closed' ); + return false; + } + + global $user_identity, $post, $id; + + if ( !$post && !$id ) + return false; + + $id = ( intval( $id ) > 0 ) ? $id : $post->ID; + + $transcriber = wp_get_current_commenter(); + + $req = ( 'selfid' == $this->option( 'transcribe_restrict' ) ); + + $defaults = array( + 'fields' => apply_filters( + 'webcomic_transcribe_default_fields', + array( + 'author' => ' +

    + ' . + ( $req ? '*' : '' ) . + ' +

    ', + 'email' => ' +

    ' . + ' ' . + ( $req ? '*' : '' ) . + ' +

    ' + ), $args, $req + ), + 'language' => ' +

    + ' . + $this->get_webcomic_transcribe_form_languages() . + '

    ', + 'transcript' => ' +

    + + +

    ', + 'submit' => ' +

    + ' . + $this->get_webcomic_transcribe_form_fields() . + '

    ', + 'transcribe_form_title' => '

    ' . __( 'Transcribe', 'webcomic' ) . '

    ', + 'transcript_submitted' => '', + 'must_log_in' => '', + 'logged_in_as' => '

    ' . sprintf( __( 'Logged in as %s. Log out?

    ', 'webcomic' ), admin_url( 'profile.php' ), $user_identity, wp_logout_url( get_permalink( $id ) ) ), + 'transcribe_notes_before' => '

    ' . __( 'Your email is never published nor shared.', 'webcomic' ) . ( $req ? __( ' Required fields are marked *', 'webcomic' ) : '' ) . '

    ', + 'transcribe_notes_after' => '

    ' . __( 'You may use these HTML tags and attributes: ', 'webcomic' ) . '' . allowed_tags() . '

    ' + ); $args = wp_parse_args( $args, apply_filters( 'webcomic_transcribe_defaults', $defaults, $req ) ); extract( $args ); + + if ( 'login' == $this->option( 'transcribe_restrict' ) && !is_user_logged_in() ) { + echo apply_filters( 'webcomic_transcribe_form_must_log_in', $must_log_in ); + + do_action( 'webcomic_transcribe_form_must_log_in_after' ); + } else { + do_action( 'webcomic_transcribe_form_before' ); + ?> +
    + $field ) + echo apply_filters( "webcomic_transcribe_form_field_{$name}", $field ); + + do_action( 'webcomic_transcribe_form_fields_after' ); + } + + echo apply_filters( 'webcomic_transcribe_form_field_language', $language ); + echo apply_filters( 'webcomic_transcribe_form_field_transcript', $transcript ); + echo apply_filters( 'webcomic_transcribe_form_notes_after', $transcribe_notes_after ); + echo apply_filters( 'webcomic_transcribe_form_field_submit', $submit ); + + do_action( 'webcomic_transcribe_form', $id ); + ?> +
    + ID ) . '" style="display:none"> + + + + '; + + if ( is_user_logged_in() ) $r .= ' + + + '; + + return apply_filters( 'webcomic_get_transcribe_form_fields', $r ); + } + + /** + * Returns language select field for transcribe form. + * + * @package webcomic + * @since 3 + */ + function get_webcomic_transcribe_form_languages() { + global $post; + + $post_meta = current( get_post_meta( $post->ID, 'webcomic' ) ); + $default = $this->option( 'transcribe_default' ); + $languages = $this->option( 'transcribe_language' ); + + $r = ''; + + return apply_filters( 'webcomic_get_transcribe_form_languages', $r, $languages, $default ); + } + + /** + * Displays the transcripts associated with a post. + * + * @package webcomic + * @since 3 + * + * @param arr|str $args An array or string of arguments (see below for full details). + * @return False if no webcomic ID can be found. + */ + function list_webcomic_transcripts( $args = array() ) { + global $post, $in_webcomic_transcript_loop; + + if ( !$post ) + return false; + + $in_webcomic_transcript_loop = true; + + $defaults = array( + 'walker' => null, //obj The walker class to use for iterating transcripts. + 'callback' => null //str Name of the function that displays each transcript + ); $args = wp_parse_args( $args, $defaults ); extract( $args ); + + if ( !$walker ) + $walker = new webcomic_Walker_Transcripts; + + $post_meta = current( get_post_meta( $post->ID, 'webcomic' ) ); + $transcripts = array(); + + foreach ( $post_meta[ 'transcripts' ] as $t ) + if ( 'publish' == $t[ 'status' ] ) + array_push( $transcripts, ( object ) $t ); + + if ( !$transcripts ) + return false; + + $walker->walk( $transcripts, 0, $args ); + + $in_webcomic_transcript_loop = false; + } + + /** + * Retrieves information related to the current transcript. + * + * @package webcomic + * @since 3 + * + * @param str $i The information to return. One of 'text', 'time', 'the_time', 'the_date', 'language', 'language_code', 'author', or 'id' + * @return The specified information, or false on error. + */ + function get_webcomic_transcript_info( $i ) { + global $post, $webcomic_transcript, $in_webcomic_transcript_loop; + + if ( !$in_webcomic_transcript_loop ) + return false; + + if ( isset( $webcomic_transcript->$i ) ) + $r = $webcomic_transcript->$i; + elseif ( 'id' == $i ) + $r = $post->ID . '-' . $webcomic_transcript->language_code; + elseif ( 'the_date' == $i ) + $r = date( get_option( 'date_format' ), $webcomic_transcript->time ); + elseif ( 'the_time' == $i ) + $r = date( get_option( 'time_format' ), $webcomic_transcript->time ); + else + $r = false; + + return apply_filters( 'webcomic_get_transcript_info', $r, $i, $webcomic_transcript ); + } + + /** + * Retrieves the webcomic transcript classes. + * + * @package webcomic + * @since 3 + * + * @param arr|str $class Additional CSS classes. + */ + function get_webcomic_transcript_class( $class = false ) { + global $post, $webcomic_transcript, $in_webcomic_transcript_loop; + + if ( !$in_webcomic_transcript_loop ) + return false; + + $user_data = get_userdata( $post->post_author ); + $classes[] = 'webcomic-transcript'; + $classes[] = 'webcomic-transcript-' . $post->ID; + $classes[] = 'webcomic-transcript-' . $webcomic_transcript->language_code; + $classes[] = 'webcomic-transcript-' . $post->ID . '-' . $webcomic_transcript->language_code; + + if ( $user_data->display_name == $webcomic_transcript->author ) + $classes[] = 'webcomic-transcript-author'; + + if ( $class ) + foreach ( ( array ) $class as $c ) + $classes[] = $c; + + $r = 'class="' . implode( ' ', $classes ). '"'; + + return apply_filters( 'webcomic_get_transcript_class', $r, $classes, $class ); + } + + // Terms + + /** + * Check if the current post is in specified taxonomy. + * + * Shortcut function for WordPress' own is_object_in_term. + * Though technically generic, we always return false if the + * specified taxonomy is not a Webcomic taxonomy. + * + * @package webcomic + * @since 3 + */ + function in_webcomic_term( $taxonomy, $terms = false, $id = false ) { + if ( !( 'webcomic_collection' == $taxonomy || 'webcomic_storyline' == $taxonomy || 'webcomic_character' == $taxonomy ) ) + return false; + + if ( $id ) + $_post = get_post( $id ); + else + $_post =& $GLOBALS[ 'post' ]; + + if ( !$_post ) + return false; + + $r = is_object_in_term( $_post->ID, $taxonomy, $terms ); + + if ( is_wp_error( $r ) ) + return false; + + return $r; + } + + /** + * Returns term information based on taxonomy. + * + * @package webcomic + * @since 3 + * + * @param str $i The information to return. + * @parram str $taxonomy The taxonomy to check. + * @param str Slug of the term to retrive. Optional; if no slug is provided, will attempt to use query_var. + * @return The requested information in it's original format, or false on error. + */ + function get_webcomic_term_info( $i, $taxonomy, $term = false ) { + $term = ( $term ) ? $term : get_query_var( $taxonomy ); + $r = false; + + if ( $t = get_term_by( 'slug', $term, $taxonomy ) ) { + if ( isset( $t->{ $i } ) ) + $r = $t->{ $i }; + elseif ( 'link' == $i ) + $r = get_term_link( ( int ) $t->term_id, $taxonomy ); + elseif ( 'feed' == $i ) + $r = get_term_feed_link( ( int ) $t->term_id, $taxonomy ); + elseif ( 'thumb-small' == $i || 'thumb-medium' == $i || 'thumb-large' == $i || 'thumb-full' == $i ) { + $s = end( explode( '-', $i ) ); + $x = end( explode( '_', $taxonomy ) ); + $r = $this->get_webcomic_object( $s, $x, false, $t->term_id ); + } + } + + return apply_filters( 'webcomic_get_term_info', $r, $i, $taxonomy, $term ); + } + + /** + * Returns terms related to the specified post in the specified taxonomy. + * + * Although technically generic, we alway return false + * if the specified taxonomy is not a Webcomic taxonomy. + * + * @package webcomic + * @since 3 + */ + function get_webcomic_post_terms( $taxonomy, $id = false ) { + if ( !( 'webcomic_collection' == $taxonomy || 'webcomic_storyline' == $taxonomy || 'webcomic_character' == $taxonomy ) ) + return false; + + global $post; + + $id = ( intval( $id ) > 0 ) ? $id : $post->ID; + $terms = get_object_term_cache( $id, $taxonomy ); + + if ( false === $terms ) { + $terms = wp_get_object_terms( $id, $taxonomy ); + wp_cache_add( $id, $terms, $taxonomy . '_post_relationships' ); + } + + if ( !empty( $terms ) ) { + if ( 'webcomic_storyline' == $taxonomy ) + usort( $terms, array( &$this, 'usort_storylines' ) ); + else + usort( $terms, '_usort_terms_by_name' ); + } else + $terms = array(); + + return apply_filters( 'webcomic_get_post_terms', $terms, $taxonomy, $id ); + } + + /** + * Returns a formatted list of terms related to the specified object in the specified taxonomy. + * + * @package webcomic + * @since 3 + * + * @uses get_webcomic_post_terms + * + * @param str $taxonomy The taxonomy the retrieved terms belong to. Must be one of 'webcomic_collection', 'webcomic_storyline', or 'webcomic_character'. + * @param arr|str $args A string or array of arguments. + * @return Formatted list of terms, or false on error. + */ + function get_the_webcomic_post_terms( $taxonomy, $args = false ) { + $defaults = array( + 'format' => false, //str Format to display the terms in. Must be one of 'ulist', 'olist', 'dropdown', 'cloud', 'grid', or false. + 'separator' => false, //str Text string to place between terms when 'format' is false. + 'before' => false, //str Text string to place before the generated output. + 'after' => false, //str Text string to place after the generated output. + 'image' => false, //str Displays covers/avatars for term links instead of names if non-false and 'format' is not 'dropdown'. If set, should be one of 'full', 'large', 'medium', or 'small'. + 'label' => false, //str Text string to display for the first null option when 'format' is 'dropdown'. + 'smallest' => 8, //int Smallest size for term clouds. Should be between 1 and 99 when using image clouds. + 'largest' => 22, //int Largest for term clouds. Automatically set to 100 for image clouds. + 'unit' => 'pt', //str The unit to use for cloud sizes. Automaticaly set to % for image clouds. + 'show_count' => false, //str Displays the total post count for each term. + 'id' => false //int ID of the object to retrieve terms for. + ); $args = wp_parse_args( $args, $defaults ); extract( $args ); + + $terms = $this->get_webcomic_post_terms( $taxonomy, $id ); + + if ( empty( $terms ) || !$this->verify() ) + return false; + + $this->domain(); + + if ( $separator ) + $format = false; + elseif ( !$format ) + $format = 'ulist'; + + if ( !$format || 'ulist' == $format || 'olist' == $format ) { + $walker = ( 'dropdown' == $format ) ? new webcomic_Walker_TermDropdown() : new webcomic_Walker_TermList(); + + if ( 'ulist' == $format || 'olist' == $format ) { + $x = ( 'ulist' == $format ) ? 'u' : 'o'; + $p1 = '<' . $x . 'l class="webcomic-post-terms ' . $taxonomy . '-post-terms">'; + $p2 = ''; + } elseif ( 'dropdown' == $format ) { + $x = false; + $p1 = ''; + } else + $x = $p1 = $p2 = false; + + $args[ 'x' ] = $x; + $args[ 'taxonomy' ] = $taxonomy; + + $l = $walker->walk( $terms, 0, $args ); + $l = ( !$format ) ? substr( $l, 0, strrpos( $l, $separator ) ) : $l; + } elseif ( 'cloud' == $format ) { + $largest = ( $largest ) ? $largest : 22; + $smallest = ( $smallest ) ? $smallest : 8; + $counts = array(); + + foreach ( ( array ) $terms as $k => $v ) + $counts[ $k ] = $v->count; + + $a = array(); + + if ( $image ) { + $largest = 100; + $smallest = ceil( $smallest ); + + $min_count = min( $counts ); + + if ( ( $spread = max( $counts ) - $min_count ) <= 0 ) + $spread = 1; + + if ( ( $dim_spread = $largest - $smalles ) < 0 ) + $dim_spread = 1; + + $dim_step = $dim_spread / $spread; + + foreach ( $terms as $k => $v ) { + $count = $counts[ $k ]; + $size = ( $smallest + ( ( $count - $min_count ) * $dim_step ) ); + $term_name = $v->name; + + if ( $v->webcomic_files[ $image ] ) { + $term_name = ''; + + foreach ( $v->webcomic_files[ $image ] as $file ) { + $f = ( $this->option( 'secure_toggle' ) ) ? $file[ 'shtml' ] : $file[ 'html' ]; + $new = 'width="' . ceil( ( $size / 100 ) * $file[ 0 ] ) . '" height="' . ceil( ( $size / 100 ) * $file[ 1 ] ) . '"'; + $term_name .= preg_replace( '/(width="\d+" height="\d+")/', $new, $f ); + } + } + + $a[] = '' . $term_name . ''; + } + + $l = implode( ' ', $a ); + } else { + $min_count = min( $counts ); + + if ( ( $spread = max( $counts ) - $min_count ) <= 0 ) + $spread = 1; + + if ( ( $font_spread = $largest - $smallest ) < 0 ) + $font_spread = 1; + + $font_step = $font_spread / $spread; + + foreach ( $terms as $k => $v ) + $a[] = '' . $v->name . ''; + + $l = implode( ' ', $a ); + } + } + + $r = $before . $p1 . $l . $p2 . $after; + + return apply_filters( 'webcomic_get_the_post_terms', $r, $terms, $taxonomy, $args ); + } + + // Term Navigation + + /** + * Retrieves term ID's relative to the specified term. + * + * @package webcomic + * @since 3 + * + * @param str $taxonomy The taxonomy terms belong to. + * @param str|int $term The term slug or ID that acts as an anchor. + * @param str $orderby How to order the retrieved terms. Defaults to 'name' for characters and collections and 'custom' for storylines. + * @param bool $hide_empty Wether to exclude empty terms. Defaults to true. + * @return arr An array of webcomic ID's, or false on error. + */ + function get_relative_webcomic_terms( $taxonomy, $term = false, $orderby = false , $hide_empty = true) { + if ( !( $term = ( $term ) ? $term : get_query_var( $taxonomy ) ) || !$this->verify() ) + return false; + + $ck = $taxonomy . '_' . hash( 'md5', implode( ( array ) $term, '' ) . $orderby . $hide_empty ); + + if ( $r = wp_cache_get( $ck, 'get_relative_webcomic_terms' ) ) + return $r; + + if ( intval( $term ) ) + $term = get_term( $term, $taxonomy ); + else + $term = get_term_by( 'slug', $term, $taxonomy ); + + if ( 'webcomic_storyline' == $taxonomy ) + $orderby = ( $orderby ) ? 'orderby=' . $orderby : 'webcomic_order=1'; + else + $orderby = ( $orderby ) ? 'orderby=' . $orderby : 'orderby=name'; + + $hide_empty = ( $hide_empty ) ? '' : '&hide_empty=0'; + + $r = array(); + + if ( !is_wp_error( $terms = get_terms( $taxonomy, $orderby . '&term_group=' . $term->term_group . $hide_empty ) ) && $terms ) { + foreach ( array_keys( $terms ) as $k ) { + if ( $terms[ $k ]->term_id == $term->term_id ) { + $key = $k; + break; + } + } + + if ( false !== $key ) { + $r[ 'random' ] = ( int ) $terms[ array_rand( $terms, 1 ) ]->term_id; + $r[ 'last' ] = ( int ) end( $terms )->term_id; + $r[ 'first' ] = ( int ) reset( $terms )->term_id; + $r[ 'previous' ] = ( int ) ( ( $key - 1 ) > -1 && isset( $terms[ $key - 1 ] ) ) ? $terms[ $key - 1 ]->term_id : $term->term_id; + $r[ 'next' ] = ( int ) ( ( $key + 1 ) < count( $terms ) && isset( $terms[ $key + 1 ] ) ) ? $terms[ $key + 1 ]->term_id : $term->term_id; + } + } + + wp_cache_add( $ck, $r, 'get_relative_webcomic_terms' ); + + return apply_filters( 'webcomic_get_relative_terms', $r, $taxonomy, $term, $orderby ); + } + + /** + * Retrieves term permalink URL's relative to the current term. + * + * @package webcomic + * @since 3 + * + * @param str $key The releative key ID. Must be one of 'first', 'previous', 'next', 'last', or 'random'. + * @param str $taxonomy The taxonomy terms belong to. + * @param str $term The term ID or slug that acts as an anchor. + * @param str $orderby How to order the terms. May be one of 'name', 'count', 'term_group', 'slug', or 'term_group_name'. Defaults to 'name' for webcomic_character and custom for webcomic_storyline. + * @param bool $hide_empty Wether to exclude empty terms. Defaults to true. + * @return The permalink URL, or false on error. + */ + function get_relative_webcomic_term_url( $key, $taxonomy, $term = false, $orderby = false, $hide_empty = true ) { + if ( !( $ids = $this->get_relative_webcomic_terms( $taxonomy, $terms, $orderby, $hide_empty ) ) || !$ids[ $key ] ) + return false; + + global $post; + + $url = get_term_link( $ids[ $key ], $taxonomy ); + + return apply_filters( 'webcomic_get_relative_term_url', $url, $key, $taxonomy, $terms ); + } + + /** + * Retrieves a properly formatted term link relative to the current term. + * + * @package webcomic + * @since 3 + * + * @param str $key The releative key ID. Must be one of 'first', 'previous', 'next', 'last', or 'random'. + * @param str $taxonomy The taxonomy terms belong to. + * @param str $format The format of the returned link. Should contain %link token. + * @param str $link What to display for the link text. May contain the %label, %name, %thumb-small, %thumb-medium, %thumb-large, and %thumb-full tokens. + * @param str $term A term ID or array of term ID's. Required if $taxonomy is not false. + * @param str $orderby How to order the terms. May be one of 'name', 'count', 'term_group', 'slug', or 'term_group_name'. Defaults to 'name' for webcomic_character and custom for webcomic_storyline. + * @param bool $hide_empty Wether to exclude empty terms. Defaults to true. + * @return Formatted term link, or false on error. + */ + function get_relative_webcomic_term_link( $key, $taxonomy, $format, $link, $term = false, $orderby = false, $hide_empty = true ) { + if ( !( $term = ( $term ) ? $term : get_query_var( $taxonomy ) ) || !( $ids = $this->get_relative_webcomic_terms( $taxonomy, $term, $orderby, $hide_empty ) ) || !$ids[ $key ] ) + return false; + + $this->domain(); + + if ( 'webcomic_storyline' == $taxonomy ) + $l = __( 'Storyline', 'webcomic' ); + elseif ( 'webcomic_character' == $taxonomy ) + $l = __( 'Character', 'webcomic' ); + elseif ( 'webcomic_collection' == $taxonomy ) + $l = __( 'Collection', 'webcomic' ); + else + return false; + + switch ( $key ) { + case 'random' : $label = '' . sprintf( __( 'Random %s', 'webcomic' ), $l ) . ''; break; + case 'first' : $label = '' . sprintf( __( '« First %s', 'webcomic' ), $l ) . ''; break; + case 'last' : $label = '' . sprintf( __( 'Last %s »', 'webcomic' ), $l ) . ''; break; + case 'previous': $label = '' . sprintf( __( '‹ Previous %s', 'webcomic' ), $l ) . ''; break; + case 'next' : $label = '' . sprintf( __( 'Next %s ›', 'webcomic' ), $l ) . ''; break; + } + + $type = end( explode( '_', $taxonomy ) ); + $term = get_term_by( 'slug', $term, $taxonomy ); + $adj_term = get_term( $ids[ $key ], $taxonomy ); + $current = ( $term->term_id == $ids[ $key ] ) ? ' current-' . $type : ''; + $kbd = ( $this->option( 'shortcut_toggle' ) ) ? ' webcomic-kbd-shortcut' : ''; + $match = false; + + if ( preg_match( '/\%thumb-(full|large|medium|small)(?:-(\d+))?/', $link, $match ) ) + $link = preg_replace( "/$match[0]/", $this->get_webcomic_object( $match[ 1 ], $type, $match[ 2 ], $ids[ $key ] ), $link ); + + $link = str_replace( '%label', $label, $link ); + $link = str_replace( '%name', $adj_term->name, $link ); + $link = '' . $link . ''; + $format = str_replace( '%link', $link, $format ); + + return apply_filters( 'webcomic_get_relative_term_link', $format, $link, $key, $taxonomy, $term ); + } + + /** + * Returns a formatted list of terms. + * + * @package webcomic + * @since 3 + * + * @param str $taxonomy The taxonomy the retrieved terms belong to. Must be one of 'webcomic_collection', 'webcomic_storyline', or 'webcomic_character'. + * @param arr|str $args A string or array of arguments. + * @return Formatted list of terms, or false on error. + */ + function get_the_webcomic_terms( $taxonomy, $args = false ) { + $defaults = array( + 'format' => false, //str Format to display the terms in. Must be one of 'ulist', 'olist', 'dropdown', 'cloud', 'grid', or false. + 'separator' => false, //str Text string to place between terms when 'format' is false. + 'before' => false, //str Text string to place before the generated output. + 'after' => false, //str Text string to place after the generated output. + 'image' => false, //str Displays covers/avatars for term links instead of names if non-false and 'format' is not 'dropdown'. If set, should be one of 'full', 'large', 'medium', or 'small'. + 'label' => false, //str Text string to display for the first null option when 'format' is 'dropdown'. + 'smallest' => 8, //int Smallest size for term clouds. Should be between 1 and 99 when using image clouds. + 'largest' => 22, //int Largest for term clouds. Automatically set to 100 for image clouds. + 'unit' => 'pt', //str The unit to use for cloud sizes. Automaticaly set to % for image clouds. + 'show_count' => false, //bool Show the term post count. + 'selected' => false, //int ID of the currently selected term + 'hierarchical' => true, //bool Display terms hierarchically. + 'hide_empty' => true, //bool Hide terms with no assigned posts. + 'order' => 'ASC', //str Order to return terms in, one of 'ASC' or 'DESC'. + 'term_group' => false //int Term group the returned terms must belong to; necessary for limiting storylines and characters to a specific collection. + ); $args = wp_parse_args( $args, $defaults ); extract( $args ); + + if ( empty( $args[ 'orderby' ] ) ) { + $args[ 'orderby' ] = ( 'webcomic_collection' == $taxonomy || 'webcomic_character' == $taxonomy ) ? 'name' : ''; + + if ( 'webcomic_storyline' == $taxonomy ) + $args[ 'webcomic_order' ] = true; + } + + if ( !$args[ 'selected' ] && $slug = get_query_var( $taxonomy ) ) { + $term = get_term_by( 'slug', $slug, $taxonomy ); + + $args[ 'selected' ] = ( $term && !is_wp_error( $term ) ) ? $term->term_id : false; + } + + $terms = get_terms( $taxonomy, $args ); + + if ( empty( $terms ) ) + return false; + + $this->domain(); + + if ( $separator ) + $format = false; + elseif ( !$format ) + $format = 'ulist'; + + if ( !$format || 'ulist' == $format || 'olist' == $format ) { + $walker = ( 'dropdown' == $format ) ? new webcomic_Walker_TermDropdown() : new webcomic_Walker_TermList(); + + if ( 'ulist' == $format || 'olist' == $format ) { + $x = ( 'ulist' == $format ) ? 'u' : 'o'; + $p1 = '<' . $x . 'l class="webcomic-terms ' . $taxonomy . '-terms">'; + $p2 = ''; + } elseif ( 'dropdown' == $format ) { + $x = false; + $p1 = ''; + } else + $x = $p1 = $p2 = false; + + $args[ 'x' ] = $x; + $args[ 'taxonomy' ] = $taxonomy; + + $l = $walker->walk( $terms, 0, $args ); + $l = ( !$format ) ? substr( $l, 0, strrpos( $l, $separator ) ) : $l; + } elseif ( 'cloud' == $format ) { + $largest = ( $largest ) ? $largest : 22; + $smallest = ( $smallest ) ? $smallest : 8; + $counts = array(); + + foreach ( ( array ) $terms as $k => $v ) + $counts[ $k ] = $v->count; + + $a = array(); + + if ( $image ) { + $largest = 100; + $smallest = ceil( $smallest ); + + $min_count = min( $counts ); + + if ( ( $spread = max( $counts ) - $min_count ) <= 0 ) + $spread = 1; + + if ( ( $dim_spread = $largest - $smalles ) < 0 ) + $dim_spread = 1; + + $dim_step = $dim_spread / $spread; + + foreach ( $terms as $k => $v ) { + $count = $counts[ $k ]; + $size = ( $smallest + ( ( $count - $min_count ) * $dim_step ) ); + $term_name = $v->name; + + if ( $v->webcomic_files[ $image ] ) { + $term_name = ''; + + foreach ( $v->webcomic_files[ $image ] as $file ) { + $f = ( $this->option( 'secure_toggle' ) ) ? $file[ 'shtml' ] : $file[ 'html' ]; + $new = 'width="' . ceil( ( $size / 100 ) * $file[ 0 ] ) . '" height="' . ceil( ( $size / 100 ) * $file[ 1 ] ) . '"'; + $term_name .= preg_replace( '/(width="\d+" height="\d+")/', $new, $f ); + } + } + + $a[] = '' . $term_name . ''; + } + + $l = implode( ' ', $a ); + } else { + $min_count = min( $counts ); + + if ( ( $spread = max( $counts ) - $min_count ) <= 0 ) + $spread = 1; + + if ( ( $font_spread = $largest - $smallest ) < 0 ) + $font_spread = 1; + + $font_step = $font_spread / $spread; + + foreach ( $terms as $k => $v ) + $a[] = '' . $v->name . ''; + + $l = implode( ' ', $a ); + } + } elseif ( false !== strpos( $format, 'grid' ) ) { + $i = 0; + $cols = ( is_numeric( end( explode( '-', $format ) ) ) ) ? intval( end( explode( '-', $format ) ) ) : 3; + + $rows = ceil ( count( $terms ) / $cols ); + $table = array(); + + for ( $row = 1; $row <= $rows; $row++ ) + for ( $col = 1; $col <= $cols; $col++ ) + $table[ $row ][ $col ] = array_shift( $terms ); + + $l = ''; + + foreach ( $table as $row => $cols ) { + $a = ( !( $i % 2 ) ) ? ' class="alt"' : ''; + $l .= ''; + + foreach ( $cols as $col => $term ) { + if ( !$term ) { + $l .= ''; + continue; + } + + $term_name = $term->name; + + if ( $term->webcomic_files[ $image ] ) { + $term_name = ''; + + foreach ( $term->webcomic_files[ $image ] as $file ) + $term_name .= ( $this->option( 'secure_toggle' ) ) ? $file[ 'shtml' ] : $file[ 'html' ]; + } + + $l .= ''; + } + + $l .= ''; + $i++; + } + + $l .= '
    ' . $term_name . '
    '; + } + + $r = $before . $p1 . $l . $p2 . $after; + + return apply_filters( 'webcomic_get_the_terms', $r, $terms, $taxonomy, $args ); + } + + /** + * Displays webcomic posts in the specified format. + * + * While this function is relatively flexible, users are + * encouraged to expierment with their own archive layouts + * and not rely on the ones provided by this template tag. + * + * @package webcomic + * @since 3 + * + * @param arr|str $args A string or array of arguments. + * @return Formatted archive of webcomic posts, or false on error. + */ + function get_the_webcomic_archive( $args = false ) { + $defaults = array( + 'format' => false, //str Format to display the terms in. Must be one of 'ulist', 'olist', 'dropdown', 'grid' (when group is not 'collection', 'storyline', or 'character'), or false. + 'group' => false, //str How to group the webcomics. May be one of 'day', 'month, 'year', 'collection', 'storyline', or 'character'. + 'separator' => false, //str Text string to place between terms when 'format' is false. + 'before' => false, //str Text string to place before the generated output. + 'after' => false, //str Text string to place after the generated output. + 'image' => false, //str Displays thumbnails for post links instead of names if non-false and 'format' is not 'dropdown'. If set, should be one of 'full', 'large', 'medium', or 'small'. + 'group_image' => false, //str Displays thumbnails for term links instead of names if non-false and 'format' is not 'dropdown'. If set, should be one of 'full', 'large', 'medium', or 'small'. + 'label' => false, //str Text string to display for the first null option when 'format' is 'dropdown'. + 'limit' => false, //int Limits the number of returned webcomics (total or for each term when groups by 'collection', 'storyline', or 'character'). + 'group_limit' => false, //int Limits the number of returned terms. + 'show_count' => false, //bool Show the term post count. + 'show_description' => false, //bool Show term descriptions. + 'hierarchical' => true, //bool Display terms hierarchically. + 'hide_empty' => true, //bool Hide terms with no assigned posts. + 'order' => 'ASC', //str Order to return posts in, one of 'ASC' or 'DESC'. + 'group_order' => 'ASC', //str Order to return terms in, one of 'ASC' or 'DESC'. + 'term_group' => false, //int Term group the returned terms must belong to; necessary for limiting storylines and characters to a specific collection. + 'last_only' => false //bool Display posts for the last (bottom-most) terms in the hierarchy. + ); $args = wp_parse_args( $args, $defaults ); extract( $args ); + + global $wpdb; + + $before = $p1 = $l = $p2 = $after = false; + + if ( 'collection' == $group || 'storyline' == $group || 'character' == $group ) { + if ( 'storyline' == $group ) + $args[ 'webcomic_order' ] = 1; + + $a = ( 'collection' == $group || $term_group ) ? get_terms( "webcomic_$group", $args ) : get_terms( 'webcomic_collection', $args ); + $wc = ( 'collection' == $group || $term_group ) ? false : true; + + if ( 'DESC' == $group_order ) + $a = array_reverse( $a ); + + if ( !empty( $group_limit ) ) + $a = array_slice( $a, 0, $group_limit ); + + if ( false === strpos( $format, 'grid' ) ) { + if ( 'ulist' == $format || 'olist' == $format ) { + $x = ( 'ulist' == $format ) ? 'u' : 'o'; + $p1 = '<' . $x . 'l class="webcomic-archive webcomic-archive-' . $group . 's">'; + $p2 = ''; + } elseif ( 'dropdown' == $format ) { + $x = false; + $p1 = ''; + } else + $x = $p1 = $p2 = false; + + $args[ 'x' ] = $x; + $args[ 'taxonomy' ] = "webcomic_$group"; + + if ( $wc ) { + foreach ( $a as $v ) { + $args[ 'wc' ] = $v; + + if ( 'ulist' == $format || 'olist' == $format ) + $l .= '
  • ' . $v->name . '<' . $x . 'l class="webcomic-archive-'. $group .'">'; + elseif ( 'dropdown' == $format ) + $l .= ''; + + $b = get_terms( "webcomic_$group", $args ); + + if ( 'DESC' == $group_order ) + $b = array_reverse( $b ); + + if ( !empty( $group_limit ) ) + $b = array_slice( $b, 0, $group_limit ); + + $w = ( 'dropdown' == $format ) ? new webcomic_Walker_ArchiveDropdown() : new webcomic_Walker_ArchiveList(); + $l .= $w->walk( $b, 0, $args ); + + if ( !$format ) + $l .= substr( $l, 0, strrpos( $l, $separator ) ); + else + $l .= ( 'dropdown' == $format ) ? '' : '
  • '; + } + } else { + $w = ( 'dropdown' == $format ) ? new webcomic_Walker_ArchiveDropdown() : new webcomic_Walker_ArchiveList(); + $l = $w->walk( $a, 0, $args ); + $l = ( !$format ) ? substr( $l, 0, strrpos( $l, $separator ) ) : $l; + } + } + } else { + $order = ( 'ASC' == $order ) ? $order : 'DESC'; + $limit = ( $limit ) ? 'LIMIT ' . intval( $limit ) : ''; + $join = ( $term_group ) ? $wpdb->prepare( "INNER JOIN $wpdb->term_relationships AS tr ON p.ID = tr.object_id INNER JOIN $wpdb->term_taxonomy tt ON tr.term_taxonomy_id = tt.term_taxonomy_id AND tt.taxonomy = 'webcomic_collection' AND tt.term_id IN (%s)", $term_group ) : ''; + $ids = $wpdb->get_col( "SELECT ID FROM $wpdb->posts AS p $join WHERE post_type = 'webcomic_post' AND post_status IN ('publish','private') ORDER BY post_date $order $limit" ); + $d = false; + + if ( !$ids ) + return false; + + if ( $separator ) + $format = false; + elseif ( !$format ) + $format = 'ulist'; + + if ( 'year' == $group ) + $f = apply_filters( 'webcomic_archive_year', 'Y' ); + elseif ( 'month' == $group ) + $f = apply_filters( 'webcomic_archive_month', 'F Y' ); + elseif ( 'day' == $group ) + $f = apply_filters( 'webcomic_archive_day', get_option( 'date_format' ) ); + else + $f = false; + + if ( 'ulist' == $format || 'olist' == $format ) { + $x = ( 'ulist' == $format ) ? 'u' : 'o'; + $l = '<' . $x . 'l class="webcomic-archive webcomic-archive-' . $group . '">'; + + foreach ( $ids as $id ) { + if ( $f && $d && ( $d != get_the_time( $f, $id ) ) ) + $l .= ''; + + if ( $f && ( $d != get_the_time( $f, $id ) ) ) { + if ( 'year' == $group ) + $u = get_year_link( get_the_time( 'Y', $id ) ); + elseif ( 'month' == $group ) + $u = get_month_link( get_the_time( 'Y', $id ), get_the_time( 'n', $id ) ); + else + $u = get_day_link( get_the_time( 'Y', $id ), get_the_time( 'n', $id ), get_the_time( 'j', $id ) ); + + $l .= '
  • ' . get_the_time( $f, $id ) . '<' . $x . 'l class="webcomic-archive-items">'; + $d = get_the_time( $f, $id ); + } else + $l .= '
  • '; + + if ( $image ) { + $link = $wc = $img = false; + $wc = current( wp_get_object_terms( $id, 'webcomic_collection' ) ); + + if ( is_object( $wc ) && ( $img = $this->retrieve( $id, 'post', $wc->slug, true ) ) ) + if ( !empty( $img[ $image ] ) ) + foreach ( $img[ $image ] as $v ) + $link .= ( $this->option( 'secure_toggle' ) ) ? $v[ 'shtml' ] : $v[ 'html' ]; + } else + $link = get_the_title( $id ); + + $l .= '
  • ' . $link . '
  • '; + } + + $l .= ( $d ) ? '' : ''; + } elseif ( 'dropdown' == $format ) { + $c = ( $group ) ? ' webcomic-archive-' . $group : ''; + $l = '' : ''; + } elseif ( false !== strpos( $format, 'grid' ) ) { + $i = $x = 0; + $c = $cols = ( is_numeric( end( explode( '-', $format ) ) ) ) ? intval( end( explode( '-', $format ) ) ) : 3; + + if ( !$group ) { + $rows = ceil ( count( $ids ) / $cols ); + $table = array(); + + for ( $row = 1; $row <= $rows; $row++ ) + for ( $col = 1; $col <= $cols; $col++ ) + $table[ $row ][ $col ] = array_shift( $ids ); + } else { + $date = false; + $dates = array(); + + foreach ( $ids as $id ) { + if ( $date != get_the_time( $f, $id ) ) { + $dates[ get_the_time( $f, $id ) ][] = $id; + $date = get_the_time( $f, $id ); + } else + $dates[ $date ][] = $id; + } + + $table = array(); + + foreach ( $dates as $k => $v ) { + $rows = ceil ( count( $v ) / $cols ); + + $table[] = current( $v ); + + $i++; + + for( $row = 1; $row <= $rows; $row++ ) + for ( $col = 1; $col <= $cols; $col++ ) + $table[ $k . ' ' . $row ][ $col ] = array_shift( $v ); + } + } + + $class = ( $group ) ? ' webcomic-archive-' . $group : ''; + + $i = $x = 0; + $l = ''; + + foreach ( $table as $row => $cols ) { + $a = ( !( $i % 2 ) ) ? ' alt' : ''; + $l .= ''; + + if ( 'year' == $group ) + $u = get_year_link( get_the_time( 'Y', $cols ) ); + elseif ( 'month' == $group ) + $u = get_month_link( get_the_time( 'Y', $cols ), get_the_time( 'n', $cols ) ); + else + $u = get_day_link( get_the_time( 'Y', $cols ), get_the_time( 'n', $cols ), get_the_time( 'j', $cols ) ); + + $l .= ''; + $d = get_the_time( $f, $cols ); + } else { + $l .= 'webcomic-archive-items' . $a . '">'; + + foreach ( $cols as $col => $id ) { + if ( !$id ) { + $l .= ''; + continue; + } + + if ( $image ) { + $link = $wc = $img = false; + $wc = current( wp_get_object_terms( $id, 'webcomic_collection' ) ); + + if ( $img = $this->retrieve( $id, 'post', $wc->slug, true ) ) + foreach ( $img[ $image ] as $v ) + $link .= ( $this->option( 'secure_toggle' ) ) ? $v[ 'shtml' ] : $v[ 'html' ]; + } else + $link = get_the_title( $id ); + + $l .= ''; + } + } + + $l .= ''; + $i++; + } + + $l .= '
    ' . get_the_time( $f, $cols ) . '' . $link . '
    '; + } else { + $l = array(); + + foreach ( $ids as $id ) { + if ( $image ) { + $link = $wc = $img = false; + $wc = current( wp_get_object_terms( $id, 'webcomic_collection' ) ); + + if ( $img = $this->retrieve( $id, 'post', $wc->slug, true ) ) + foreach ( $img[ $image ] as $v ) + $link .= ( $this->option( 'secure_toggle' ) ) ? $v[ 'shtml' ] : $v[ 'html' ]; + } else + $link = get_the_title( $id ); + + $l[] = '' . $link . ''; + } + + $l = implode( $separator, $l ); + } + } + + + $r = $before . $p1 . $l . $p2 . $after; + + return apply_filters( 'webcomic_get_the_archive', $r, $args ); + } + + + + //// + // Shortcodes + // + // These functions define WordPress shortcodes + // to be used in post content. + //// + + /** + * Displays the webcomic related to the current post. + * + * @package webcomic + * @since 3 + */ + function short_webcomic( $atts, $content = false ) { + extract( shortcode_atts( array( + 'size' => 'full', + 'link' => false, + 'taxonomy' => false, + 'terms' => false, + 'key' => false + ), $atts ) ); + + return $this->get_the_webcomic_object( $size, $link, $taxonomy, $terms, $key ); + } + + /** + * Displays a link to a random webcomic in the current collection. + * + * @package webcomic + * @since 3 + */ + function short_random_webcomic_link( $atts, $content = false ) { + extract( shortcode_atts( array( + 'link' => '%link', + 'format' => '%label', + 'taxonomy' => false, + 'terms' => false + ), $atts ) ); + + return $this->get_relative_webcomic_link( 'random', $link, $format, $taxonomy, $terms ); + } + /** + * Displays a link to the first webcomic in the current collection. + * + * @package webcomic + * @since 3 + */ + function short_first_webcomic_link( $atts, $content = false ) { + extract( shortcode_atts( array( + 'link' => '%link', + 'format' => '%label', + 'taxonomy' => false, + 'terms' => false + ), $atts ) ); + + return $this->get_relative_webcomic_link( 'first', $link, $format, $taxonomy, $terms ); + } + + /** + * Displays a link to the previous webcomic in the current collection. + * + * @package webcomic + * @since 3 + */ + function short_previous_webcomic_link( $atts, $content = false ) { + extract( shortcode_atts( array( + 'link' => '%link', + 'format' => '%label', + 'taxonomy' => false, + 'terms' => false + ), $atts ) ); + + return $this->get_relative_webcomic_link( 'previous', $link, $format, $taxonomy, $terms ); + } + + /** + * Displays a link to the next webcomic in the current collection. + * + * @package webcomic + * @since 3 + */ + function short_next_webcomic_link( $atts, $content = false ) { + extract( shortcode_atts( array( + 'link' => '%link', + 'format' => '%label', + 'taxonomy' => false, + 'terms' => false + ), $atts ) ); + + return $this->get_relative_webcomic_link( 'next', $link, $format, $taxonomy, $terms ); + } + + /** + * Displays a link to the last webcomic in the current collection. + * + * @package webcomic + * @since 3 + */ + function short_last_webcomic_link( $atts, $content = false ) { + extract( shortcode_atts( array( + 'link' => '%link', + 'format' => '%label', + 'taxonomy' => false, + 'terms' => false + ), $atts ) ); + + return $this->get_relative_webcomic_link( 'last', $link, $format, $taxonomy, $terms ); + } + + /** + * Displays a link to purchase a print of the current webcomic. + * + * @package webcomic + * @since 3 + */ + function short_purchase_webcomic_link( $atts, $content = false ) { + extract( shortcode_atts( array( + 'link' => '%link', + 'format' => '%label', + 'id' => false + ), $atts ) ); + + return $this->get_purchase_webcomic_link( $link, $format, $id ); + } + + /** + * Displays a formatted list of webcomics related to the current webcomic. + * + * @package webcomic + * @since 3 + */ + function short_get_related_webcomics( $atts, $content = false ) { + extract( shortcode_atts( array( + 'format' => false, + 'separator' => false, + 'before' => false, + 'after' => false, + 'number' => 5, + 'order' => 'ASC', + 'image' => false, + 'imagekey' => false, + 'label' => false, + 'storylines' => true, + 'characters' => true + ), $atts ) ); + + return $this->get_the_related_webcomics( array( + 'format' => $format, + 'separator' => $separator, + 'before' => $before, + 'after' => $after, + 'number' => 5, + 'order' => 'ASC', + 'image' => $image, + 'imagekey' => $imagekey, + 'label' => $label, + 'storylines' => $storylines, + 'characters' => $characters + ) ); + } + + /** + * Displays a formatted list of collections related to the current webcomic. + * + * @package webcomic + * @since 3 + */ + function short_webcomic_collections( $atts, $content = false ) { + extract( shortcode_atts( array( + 'format' => false, + 'separator' => false, + 'before' => false, + 'after' => false, + 'image' => false, + 'label' => false, + 'smallest' => 8, + 'largest' => 22, + 'unit' => 'pt' + ), $atts ) ); + + return $this->get_the_webcomic_post_terms( 'webcomic_collection', array( + 'format' => $format, + 'separator' => $separator, + 'before' => $before, + 'after' => $after, + 'image' => $image, + 'label' => $label, + 'smallest' => $smallest, + 'largest' => $largest, + 'unit' => $unit + ) ); + } + + /** + * Displays a formatted list of storylines related to the current webcomic. + * + * @package webcomic + * @since 3 + */ + function short_webcomic_storylines( $atts, $content = false ) { + extract( shortcode_atts( array( + 'format' => false, + 'separator' => false, + 'before' => false, + 'after' => false, + 'image' => false, + 'label' => false, + 'smallest' => 8, + 'largest' => 22, + 'unit' => 'pt' + ), $atts ) ); + + return $this->get_the_webcomic_post_terms( 'webcomic_storyline', array( + 'format' => $format, + 'separator' => $separator, + 'before' => $before, + 'after' => $after, + 'image' => $image, + 'label' => $label, + 'smallest' => $smallest, + 'largest' => $largest, + 'unit' => $unit + ) ); + } + + /** + * Displays a formatted list of characters related to the current webcomic. + * + * @package webcomic + * @since 3 + */ + function short_webcomic_characters( $atts, $content = false ) { + extract( shortcode_atts( array( + 'format' => false, + 'separator' => false, + 'before' => false, + 'after' => false, + 'image' => false, + 'label' => false, + 'smallest' => 8, + 'largest' => 22, + 'unit' => 'pt' + ), $atts ) ); + + return $this->get_the_webcomic_post_terms( 'webcomic_character', array( + 'format' => $format, + 'separator' => $separator, + 'before' => $before, + 'after' => $after, + 'image' => $image, + 'label' => $label, + 'smallest' => $smallest, + 'largest' => $largest, + 'unit' => $unit + ) ); + } + + + + //// + // Hooks - Initialization + // + // These functions hook into various WordPress + // initialization actions and should never be + // called directly. + //// + + /** + * 'init' hook. + * + * @package webcomic + * @since 3 + */ + function hook_init() { + global $wp_rewrite; + + $this->domain(); + + $rewrite = array(); + + if ( is_object( $wp_rewrite ) && $wp_rewrite->using_permalinks() ) { + $rewrite[ 'webcomic' ] = array( 'slug' => apply_filters( 'webcomic_post_slug', 'archive' ) ); + $rewrite[ 'collection' ] = array( 'slug' => apply_filters( 'webcomic_collection_slug', 'collection' ) ); + $rewrite[ 'storyline' ] = array( 'slug' => apply_filters( 'webcomic_storyline_slug', 'storyline' ) ); + $rewrite[ 'character' ] = array( 'slug' => apply_filters( 'webcomic_character_slug', 'character' ) ); + } else + $rewrite[ 'webcomic' ] = $rewrite[ 'collection' ] = $rewrite[ 'storyline' ] = $rewrite[ 'character' ] = false; + + register_post_type( 'webcomic_post', array( 'labels' => array( 'name' => __( 'Webcomics', 'webcomic' ), 'singular_name' => __( 'Webcomic', 'webcomic' ), 'add_new_item' => __( 'Add New Webcomic', 'webcomic' ), 'edit_item' => __( 'Edit Webcomic', 'webcomic' ), 'new_item' => __( 'New Webcomic', 'webcomic' ), 'view_item' => __( 'View Webcomic', 'webcomic' ), 'search_items' => __( 'Search Webcomics', 'webcomic' ), 'not_found' => __( 'No webcomics found', 'webcomic' ), 'not_found_in_trash' => __( 'No webcomics found in trash', 'webcomic' ) ), 'public' => true, 'show_ui' => true, 'rewrite' => $rewrite[ 'webcomic' ], 'query_var' => 'webcomic_post', 'taxonomies' => array( 'category', 'post_tag' ), 'menu_position' => 5, 'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'trackbacks', 'custom-fields', 'comments', 'revisions' ) ) ); + register_taxonomy( 'webcomic_collection', array( 'webcomic_post' ), array( 'labels' => array( 'name' => __( 'Collections', 'webcomic' ), 'singular_name' => __( 'Collection', 'webcomic' ), 'search_items' => __( 'Search Collections', 'webcomic' ), 'popular_items' => __( 'Popular Collections', 'webcomic' ), 'all_items' => __( 'All Collections', 'webcomic' ), 'parent_item' => __( 'Parent Collection', 'webcomic' ), 'parent_item_colon' => __( 'Parent Collection:', 'webcomic' ), 'edit_item' => __( 'Edit Collection', 'webcomic' ), 'update_item' => __( 'Update Collection', 'webcomic' ), 'add_new_item' => __( 'Add New Collection', 'webcomic' ), 'new_item_name' => __( 'New Collection Name', 'webcomic' ) ), 'hierarchical' => true, 'public' => true, 'show_ui' => false, 'rewrite' => $rewrite[ 'collection' ], 'query_var' => 'webcomic_collection', 'update_count_callback' => '_update_post_term_count' ) ); + register_taxonomy( 'webcomic_storyline', array( 'webcomic_post' ), array( 'labels' => array( 'name' => __( 'Storylines', 'webcomic' ), 'singular_name' => __( 'Storyline', 'webcomic' ), 'search_items' => __( 'Search Storylines', 'webcomic' ), 'popular_items' => __( 'Popular Storylines', 'webcomic' ), 'all_items' => __( 'Al Storylines', 'webcomic' ), 'parent_item' => __( 'Parent Storyline', 'webcomic' ), 'parent_item_colon' => __( 'Parent Storyline:', 'webcomic' ), 'edit_item' => __( 'Edit Storyline', 'webcomic' ), 'update_item' => __( 'Update Storyline', 'webcomic' ), 'add_new_item' => __( 'Add New Storyline', 'webcomic' ), 'new_item_name' => __( 'New Storyline Name', 'webcomic' ) ), 'hierarchical' => true, 'public' => true, 'show_ui' => false, 'rewrite' => $rewrite[ 'storyline' ], 'query_var' => 'webcomic_storyline', 'update_count_callback' => '_update_post_term_count' ) ); + register_taxonomy( 'webcomic_character', array( 'webcomic_post' ), array( 'labels' => array( 'name' => __( 'Characters', 'webcomic' ), 'singular_name' => __( 'Character', 'webcomic' ), 'search_items' => __( 'Search Characters', 'webcomic' ), 'popular_items' => __( 'Popular Characters', 'webcomic' ), 'all_items' => __( 'All Characters', 'webcomic' ), 'parent_item' => __( 'Parent Character', 'webcomic' ), 'parent_item_colon' => __( 'Parent Character:', 'webcomic' ), 'edit_item' => __( 'Edit Character', 'webcomic' ), 'update_item' => __( 'Update Character', 'webcomic' ), 'add_new_item' => __( 'Add New Character', 'webcomic' ), 'new_item_name' => __( 'New Character Name', 'webcomic' ) ), 'hierarchical' => true, 'public' => true, 'show_ui' => false, 'rewrite' => $rewrite[ 'character' ], 'query_var' => 'webcomic_character', 'update_count_callback' => '_update_post_term_count' ) ); + + if ( get_option( 'webcomic_version' ) ) + register_taxonomy( 'chapter', array( 'post', 'webcomic_post' ), array( 'label' => __( 'Chapter', 'webcomic' ), 'hierarchical' => true, 'public' => true, 'show_ui' => false, 'update_count_callback' => '_update_post_term_count' ) ); + + flush_rewrite_rules(); + + wp_enqueue_script( 'swfobject', '', '', '', true ); + + remove_filter( 'pre_term_description', 'wp_filter_kses' ); + + if ( !empty( $_REQUEST[ 'webcomic_paypal_ipn' ] ) ) { + global $wpdb; + + $id = ( $wpdb->blog_id ) ? $wpdb->blog_id : 0; + $text = ''; + $pass = true; + $type = $_REQUEST[ 'webcomic_paypal_ipn' ]; + $req = 'cmd=_notify-validate'; + $log = ( $this->option( 'paypal_log' ) ) ? fopen( $this->dir . 'webcomic-includes/ipnlog-' . $id . '.txt', 'a' ) : false; + + foreach ( $_POST as $key => $value ) { + $value = urlencode( stripslashes( $value ) ); + $req .= "&$key=$value"; + } + + $header .= "POST /cgi-bin/webscr HTTP/1.0\r\n"; + $header .= "Content-Type: application/x-www-form-urlencoded\r\n"; + $header .= "Content-Length: " . strlen( $req ) . "\r\n\r\n"; + $fp = fsockopen( 'ssl://www.paypal.com', 443, $errno, $errstr, 30 ); //ssl://www.sandbox.paypal.com + + $txn_id = $_POST[ 'txn_id' ]; + $item_number = ( $_POST[ 'num_cart_items' ] ) ? $_POST[ 'num_cart_items' ] . 'SC' : $_POST[ 'item_number' ]; + $payer_email = $_POST[ 'payer_email' ]; + $receiver_email = $_POST[ 'receiver_email' ]; + $payment_status = $_POST[ 'payment_status' ]; + $payment_currency = $_POST[ 'mc_currency' ]; + + $text = sprintf( "%s %s IPN %s: ", ucfirst( $type ), $item_number, $txn_id ); + + if ( !$fp ) + $text .= __( "HTTP Error\n", "webcomic" ); + else { + fputs( $fp, $header . $req ); + + while ( !feof( $fp ) ) { + $res = fgets ( $fp, 1024 ); + $file = file_get_contents( $this->dir . 'webcomic-includes/ipnlog-' . $id . '.txt' ); + + if ( 0 == strcmp( $res, "VERIFIED" ) ) { + if ( 'Completed' != $payment_status ) { + $text .= __( "Incomplete\n", "webcomic" ); + $pass = false; + } + + if ( false !== strpos( $file, $txn_id ) ) { + $text .= __( "Already processed\n", "webcomic" ); + $pass = false; + } + + if ( strtolower( urldecode( $receiver_email ) ) != $this->option( 'paypal_business' ) ) { + $text .= sprintf( __( "Bad Email: %s != %s \n", "webcomic" ), strtolower( urldecode( $receiver_email ) ), $this->option( 'paypal_business' ) ); + $pass = false; + } + + if ( $payment_currency != $this->option( 'paypal_currency' ) ) { + $text .= sprintf( __( "Bad Currency: %s != %s\n", "webcomic" ), $payment_currency, $this->option( 'paypal_currency' ) ); + $pass = false; + } + + if ( $pass ) { + $text .= sprintf( __( "Completed on %s\n", "webcomic" ), date( get_option( 'date_format' ) . ' @ ' . get_option( 'time_format' ) ) ); + + if ( 'original' == $type ) { + $post_meta = current( get_post_meta( ( int ) $item_number, 'webcomic' ) ); + $post_meta[ 'paypal' ][ 'original' ] = false; + update_post_meta( ( int ) $item_number, 'webcomic', $post_meta ); + } + } + } elseif ( 0 == strcmp ( $res, "INVALID" ) ) + $text .= __( "Invalid\n", "webcomic" ); + } + + if ( $log ) { + fwrite( $log, $text ); + fclose( $fp ); + } + + fclose( $log ); + } + } + + if ( !empty( $_GET[ 'webcomic_object' ] ) ) { + do_action( 'webcomic_secure_object' ); + + $info = explode( '/', $_GET[ 'webcomic_object' ] ); + $match = ( 'post' == $info[ 0 ] ) ? true : false; + $headers = ( function_exists( 'getallheaders' ) ) ? getallheaders() : false; + + if ( 'post' == $info[ 0 ] ) { + $id = current( wp_get_object_terms( $info[ 1 ], 'webcomic_collection' ) ); + $wc = get_term( $id, 'webcomic_collection' ); + } elseif ( 'collection' == $info[ 0 ] ) + $wc = get_term( $info[ 1 ], 'webcomic_collection' ); + else { + $term = get_term( $info[ 1 ], 'webcomic_' . $info[ 0 ] ); + $wc = get_term( $term->term_group, 'webcomic_collection' ); + } + + if ( $files = $this->retrieve( $info[ 1 ], $info[ 0 ], $wc->slug, $match ) ) { + if ( !$files[ $info[ 2 ] ][ $info[ 3 ] ] ) + return false; + + $img = $files[ $info[ 2 ] ][ $info[ 3 ] ][ 'dirname' ] .'/' . $files[ $info[ 2 ] ][ $info[ 3 ] ][ 'basename' ]; + + if ( $headers && isset( $headers[ 'If-Modified-Since' ] ) && ( strtotime( $headers[ 'If-Modified-Since' ] ) == filemtime( $img ) ) ) + header( 'Last-Modified: ' . gmdate( 'D, d M Y H:i:s', filemtime( $img ) ) . ' GMT', true, 304 ); + else { + header( 'Last-Modified: ' . gmdate( 'D, d M Y H:i:s', filemtime( $img ) ) . ' GMT', true, 200 ); + header( 'Content-Length: ' . filesize( $img ) ); + header( 'Content-Type: ' . $files[ $info[ 2 ] ][ $info[ 3 ] ][ 'mime' ] ); + } + + die( readfile( $img ) ); + } + } + + if ( isset( $_REQUEST[ 'action' ] ) && 'verify_webcomic_age' == $_REQUEST[ 'action' ] ) { + check_admin_referer( 'verify_webcomic_age' ); + + do_action( 'webcomic_verify_age' ); + + global $current_user; + + if ( $_REQUEST[ 'webcomic_birth_year' ] && $_REQUEST[ 'webcomic_birth_month' ] && $_REQUEST[ 'webcomic_birth_day' ] ) { + $bday = strtotime( $_REQUEST[ 'webcomic_birth_year' ] . '/' . $_REQUEST[ 'webcomic_birth_month' ] . '/' . $_REQUEST[ 'webcomic_birth_day' ] ); + + if ( $current_user->ID ) { + $user_meta = current( get_user_meta( $current_user->ID, 'webcomic' ) ); + $user_meta[ 'birthday' ] = $bday; + update_user_meta( $current_user->ID, 'webcomic', $user_meta ); + } else { + $time = apply_filters( 'webcomic_verify_lifetime', 30000000 ); + setcookie( 'webcomic_birthday_' . COOKIEHASH, $bday, time() + $time, COOKIEPATH, COOKIE_DOMAIN ); + } + } + } + + if ( isset( $_REQUEST[ 'action' ] ) && 'submit_webcomic_transcript' == $_REQUEST[ 'action' ] ) { + check_admin_referer( 'submit_webcomic_transcript' ); + + do_action( 'webcomic_submit_transcript' ); + + if ( !$_REQUEST[ hash( 'md5', 'webcomic_transcript_' . $_REQUEST[ 'webcomic_transcript_post' ] ) ] ) { + $post_meta = current( get_post_meta( $_REQUEST[ 'webcomic_transcript_post' ], 'webcomic' ) ); + + if ( !empty( $_REQUEST[ 'webcomic_ajax' ] ) ) { + echo ( isset( $post_meta[ 'transcripts' ][ $_REQUEST[ 'webcomic_transcript_language' ] ][ 'text' ] ) ) ? wp_filter_kses( $post_meta[ 'transcripts' ][ $_REQUEST[ 'webcomic_transcript_language' ] ][ 'text' ] ) : ''; + + die(); + } + + if ( isset( $post_meta[ 'transcripts' ][ $_REQUEST[ 'webcomic_transcript_language' ] ][ 'status' ] ) && ( 'publish' == $post_meta[ 'transcripts' ][ $_REQUEST[ 'webcomic_transcript_language' ] ][ 'status' ] || 'draft' == $post_meta[ 'transcripts' ][ $_REQUEST[ 'webcomic_transcript_language' ] ][ 'status' ] ) ) + wp_die( __( 'Error: no transcripts are being accepted for this webcomic right now.', 'webcomic' ) ); + elseif ( !$_REQUEST[ 'webcomic_transcript_text' ] ) + wp_die( __( 'Error: please type a transcript.', 'webcomic' ) ); + elseif ( 'selfid' == $this->option( 'transcribe_restrict' ) && !( $_REQUEST[ 'webcomic_transcript_author' ] || $_REQUEST[ 'webcomic_transcript_email' ] ) ) + wp_die( __( 'Error: all fields are required.', 'webcomic' ) ); + elseif ( 'selfid' == $this->option( 'transcribe_restrict' ) && !filter_var( $_REQUEST[ 'webcomic_transcript_email' ], FILTER_VALIDATE_EMAIL ) ) + wp_die( __( 'Error: a valid e-mail address is required.', 'webcomic' ) ); + else { + $_REQUEST[ 'webcomic_transcript_status' ] = true; + + $languages = $this->option( 'transcribe_language' ); + $default = array_keys( $this->option( 'transcribe_default' ) ); + $lkey = ( $_REQUEST[ 'webcomic_transcript_language' ] ) ? $_REQUEST[ 'webcomic_transcript_language' ] : $default[ 0 ]; + $author = ( $_REQUEST[ 'webcomic_transcript_author' ] ) ? stripslashes( $_REQUEST[ 'webcomic_transcript_author' ] ) : __( 'Anonymous', 'webcomc' ); + $email = ( $_REQUEST[ 'webcomic_transcript_email' ] ) ? $_REQUEST[ 'webcomic_transcript_email' ] : ''; + $title = '' . get_the_title( $_REQUEST[ 'webcomic_transcript_post' ] ) . ''; + $transcript = "\n\n" . wpautop( wp_filter_kses( $_REQUEST[ 'webcomic_transcript_text' ] ) ) . "\n\n"; + $message = sprintf( __( '%s has submitted a new transcript for %s in %s.%sYou can approve, edit, or delete this transcript by visiting: %s', 'webcomic' ), $author . ' (' . $email . ')', $title, $languages[ $lkey ], $transcript, admin_url( 'post.php?action=edit&post=' . $_REQUEST[ 'webcomic_transcript_post' ] ) ); + + if ( !empty( $post_meta[ 'transcripts' ][ $lkey ][ 'text' ] ) ) { + $post_meta[ 'transcripts' ][ $lkey ][ 'backup' ] = $post_meta[ 'transcripts' ][ $lkey ][ 'text' ]; + $post_meta[ 'transcripts' ][ $lkey ][ 'backup_time' ] = $post_meta[ 'transcripts' ][ $lkey ][ 'author' ]; + $post_meta[ 'transcripts' ][ $lkey ][ 'backup_author' ] = $post_meta[ 'transcripts' ][ $lkey ][ 'time' ]; + } + + $post_meta[ 'transcripts' ][ $lkey ][ 'language_code' ] = $lkey; + $post_meta[ 'transcripts' ][ $lkey ][ 'language' ] = $languages[ $lkey ]; + $post_meta[ 'transcripts' ][ $lkey ][ 'status' ] = 'draft'; + $post_meta[ 'transcripts' ][ $lkey ][ 'author' ] = $author; + $post_meta[ 'transcripts' ][ $lkey ][ 'time' ] = time(); + $post_meta[ 'transcripts' ][ $lkey ][ 'text' ] = rtrim( $transcript ); + + update_post_meta( $_REQUEST[ 'webcomic_transcript_post' ], 'webcomic', $post_meta ); + + @wp_mail( get_option( 'admin_email' ), sprintf( __( '[%s] Transcript Submitted for %s', 'webcomic' ), html_entity_decode( get_option( 'blogname' ) ), html_entity_decode( $title ) ), $message ); + } + } + } + } + + /** + * 'widgets_init' hook. + * + * All widgets are defined in the + * /webcomic-includes/widgets.php file. + * + * @package webcomic + * @since 3 + */ + function hook_widgets_init() { + register_widget( 'webcomic_Widget_Buffer' ); + register_widget( 'webcomic_Widget_Donation' ); + register_widget( 'webcomic_Widget_Relative' ); + register_widget( 'webcomic_Widget_Bookmark' ); + register_widget( 'webcomic_Widget_Characters' ); + register_widget( 'webcomic_Widget_Storylines' ); + register_widget( 'webcomic_Widget_Collections' ); + register_widget( 'webcomic_Widget_Archive' ); + } + + /** + * 'template_redirect' hook. + * + * @package webcomic + * @since 3 + */ + function hook_template_redirect() { + global $post; + + wp_enqueue_script( 'webcomic-scripts', $this->url . 'webcomic-includes/scripts.js', array( 'jquery', 'jquery-hotkeys' ), '', true ); + + if ( !$this->verify( 'restrict' ) ) + auth_redirect(); + + if ( !$this->verify( 'age' ) ) { + if ( isset( $_REQUEST[ 'action' ] ) && 'verify_webcomic_age' == $_REQUEST[ 'action' ] && $_REQUEST[ 'redirect' ] ) { + unset( $_REQUEST[ 'action' ] ); + wp_redirect( $_REQUEST[ 'redirect' ] ); + } + + $v = apply_filters( 'webcomic_verify_age_template', 'webcomic_verifyage.php' ); + $f = apply_filters( 'webcomic_verify_fail_template', 'webcomic_verifyfail.php' ); + + $form = ( locate_template( array( $v ) ) ) ? locate_template( array( $v ) ) : $this->dir . 'webcomic-includes/template-verify-age.php'; + $fail = ( locate_template( array( $f ) ) ) ? locate_template( array( $f ) ) : $this->dir . 'webcomic-includes/template-verify-fail.php'; + + if ( !$this->age() ) { + require_once( $form ); + die(); + } elseif ( !$this->verify( 'age' ) ) { + require_once( $fail ); + die(); + } + } + + if ( $this->option( 'paypal_business' ) && !empty( $_REQUEST[ 'purchase_webcomic_print' ] ) ) { + $v = apply_filters( 'webcomic_purchase_print_template', 'webcomic_purchaseprint.php' ); + + if ( locate_template( array( $v ) ) ) + $p = locate_template( array( $v ) ); + else + $p = $this->dir . 'webcomic-includes/template-purchase-print.php'; + + require_once( $p ); + die(); + } + + if ( !empty( $_REQUEST[ 'relative_webcomic' ] ) ) { + global $wpdb; + + $a = explode( '/', $_REQUEST[ 'relative_webcomic' ] ); + + if ( $url = $this->get_relative_webcomic_url( $a[ 0 ], $a[ 1 ], explode( ',', $a[ 2 ] ), $a[ 3 ] ) ) + wp_redirect( $url ); + } + + if ( !empty( $_REQUEST[ 'bookmark_webcomic' ] ) ) { + $a = explode( '/', $_REQUEST[ 'bookmark_webcomic' ] ); + $time = ( 'bookmark' == $a[ 1 ] ) ? apply_filters( 'webcomic_bookmark_lifetime', 30000000 ) : -1; + + if ( 'bookmark' == $a[ 1 ] ) + setcookie( 'webcomic_bookmark_' . $a[ 2 ], get_permalink( $a[ 0 ] ), time() + $time, COOKIEPATH, COOKIE_DOMAIN ); + elseif ( 'remove' == $a[ 1 ] ) + setcookie( 'webcomic_bookmark_' . $a[ 2 ], get_permalink( $a[ 0 ] ), time() + $time, COOKIEPATH, COOKIE_DOMAIN ); + elseif ( isset( $_COOKIE[ 'webcomic_bookmark_' . $a[ 2 ] ] ) ) + wp_redirect( $_COOKIE[ 'webcomic_bookmark_' . $a[ 2 ] ] ); + else + return false; + } + } + + + + //// + // Hooks - Posts + // + // These functions hook into various WordPress + // post actions and should never be called + // directly. + //// + + /** + * 'body_class' hook. + * + * @package webcomic + * @since 3 + */ + function hook_body_class( $classes, $class ) { + global $post; + + if ( is_tax( 'webcomic_collection' ) ) + $classes[] = 'webcomic_collection webcomic_collection-' . get_query_var( 'webcomic_collection' ); + + if ( is_tax( 'webcomic_storyline' ) ) + $classes[] = 'webcomic_storyline webcomic_storyline-' . get_query_var( 'webcomic_storyline' ); + + if ( is_tax( 'webcomic_character' ) ) + $classes[] = 'webcomic_character webcomic_character-' . get_query_var( 'webcomic_character' ); + + if ( ( is_singular( 'webcomic_post' ) || is_page() ) && $wc = current( wp_get_object_terms( $post->ID, 'webcomic_collection' ) ) ) { + if ( !is_tax( 'webcomic_collection' ) ) + $classes[] = 'webcomic_collection-' . sanitize_html_class( $wc->slug, $wc->term_id ); + + if ( isset( $_REQUEST[ 'purchase_webcomic_print' ] ) ) + $classes[] = 'webcomic-purchase'; + + if ( !$this->verify( 'age' ) ) + $classes[] = ( $this->age() ) ? 'webcomic-verify-fail' : 'webcomic-verify-age'; + + if ( !$this->verify( 'restrict' ) ) + $classes[] = 'webcomic-restricted'; + } + + return $classes; + } + + /** + * 'post_class' hook. + * + * @package webcomic + * @since 3 + */ + function hook_post_class( $classes, $class, $id ) { + if ( in_array( 'type-webcomic_post', $classes ) && ( $wc = current( wp_get_object_terms( $id, 'webcomic_collection' ) ) ) ) { + $classes[] = 'webcomic_collection-' . sanitize_html_class( $wc->slug, $wc->term_id ); + + if ( $storylines = wp_get_object_terms( $id, 'webcomic_storyline' ) ) + foreach ( $storylines as $storyline ) + $classes[] = 'webcomic_storyline-' . sanitize_html_class( $storyline->slug, $storyline->term_id ); + + if ( $characters = wp_get_object_terms( $id, 'webcomic_character' ) ) + foreach ( $characters as $character ) + $classes[] = 'webcomic_character-' . sanitize_html_class( $character->slug, $character->term_id ); + + if ( !$this->verify( 'age' ) ) + $classes[] = ( $this->age() ) ? 'webcomic-verify-fail' : 'webcomic-verify-age'; + + if ( !$this->verify( 'restrict' ) ) + $classes[] = 'webcomic-restricted'; + } + + return $classes; + } + + /** + * 'the_post' hook. + * + * @package webcomic + * @since 3 + */ + function hook_the_post( $post ) { + if ( !$post || 'webcomic_post' != $post->post_type ) + return $post; + + $wc = current( wp_get_object_terms( $post->ID, 'webcomic_collection' ) ); + $post_meta = current( get_post_meta( $post->ID, 'webcomic' ) ); + + $post->webcomic_files = ( is_object( $wc ) ) ? $this->retrieve( $post->ID, 'post', $wc->slug, true ) : NULL; + $post->webcomic_alternate = ( isset( $post_meta[ 'alternate' ] ) ) ? $post_meta[ 'alternate' ] : NULL; + $post->webcomic_description = ( isset( $post_meta[ 'description' ] ) ) ? $post_meta[ 'description' ] : NULL; + $post->webcomic_transcribe_toggle = ( isset( $post_meta[ 'transcribe_toggle' ] ) ) ? $post_meta[ 'transcribe_toggle' ] : NULL; + $post->webcomic_transcripts = ( isset( $post_meta[ 'transcripts' ] ) ) ? $post_meta[ 'transcripts' ] : NULL; + $post->webcomic_paypal = ( isset( $post_meta[ 'paypal' ] ) ) ? $post_meta[ 'paypal' ] : NULL; + + return $post; + } + + /** + * 'the_posts' hook. + * + * @package webcomic + * @since 3 + */ + function hook_the_posts( $posts ) { + foreach ( $posts as $post ) { + if ( 'webcomic_post' != $post->post_type ) + continue; + + $wc = current( wp_get_object_terms( $post->ID, 'webcomic_collection' ) ); + $post_meta = current( get_post_meta( $post->ID, 'webcomic' ) ); + + $post->webcomic_files = ( is_object( $wc ) ) ? $this->retrieve( $post->ID, 'post', $wc->slug, true ) : NULL; + $post->webcomic_alternate = ( isset( $post_meta[ 'alternate' ] ) ) ? $post_meta[ 'alternate' ] : NULL; + $post->webcomic_description = ( isset( $post_meta[ 'description' ] ) ) ? $post_meta[ 'description' ] : NULL; + $post->webcomic_transcribe_toggle = ( isset( $post_meta[ 'transcribe_toggle' ] ) ) ? $post_meta[ 'transcribe_toggle' ] : NULL; + $post->webcomic_transcripts = ( isset( $post_meta[ 'transcripts' ] ) ) ? $post_meta[ 'transcripts' ] : NULL; + $post->webcomic_paypal = ( isset( $post_meta[ 'paypal' ] ) ) ? $post_meta[ 'paypal' ] : NULL; + } + + return $posts; + } + + /** + * 'loop_start' hook. + * + * @package webcomic + * @since 3 + */ + function hook_loop_start() { + if ( !$this->option( 'integrate_toggle' ) ) + return false; + + global $post; + + if ( is_home() || is_front_page() ) { + $webcomics = new WP_Query( 'post_type=webcomic_post&posts_per_page=1' ); if ( $webcomics->posts ) { $_post = $post; foreach ( $webcomics->posts as $p ) { + $post = $p; + ?> +
    > +

    + + +
    + →', 'webcomic' ) ); ?> + '' ) ); ?> +
    + +
    + get_the_webcomic_terms( 'webcomic_collection', array( 'before' => __( 'From ', 'webcomic' ), 'separator' => ', ', 'after' => ' | ' ) ); ?> + get_the_webcomic_terms( 'webcomic_storyline', array( 'before' => __( 'Part of ', 'webcomic' ), 'separator' => ', ', 'after' => ' | ' ) ); ?> + get_the_webcomic_terms( 'webcomic_character', array( 'before' => __( 'Featuring ', 'webcomic' ), 'separator' => ', ', 'after' => ' | ' ) ); ?> + + | + ' . __( 'Tagged ', 'webcomic' ) . '', ', ', ' | ' ); ?> + + | ', '' ); ?> +
    +

    + domain(); + + global $post; + + if ( 'webcomic_post' == get_post_type( $post ) ) { + $wc = current( wp_get_object_terms( $post->ID, 'webcomic_collection' ) ); + $ok = true; + + if ( !$this->verify( 'restrict' ) ) { + $content = apply_filters( 'webcomic_content_restrict', sprintf( __( 'Please login to view this webcomic.', 'webcomic' ), get_permalink( $post->ID ) ), $post, $wc ); + $ok = false; + } elseif ( !$this->verify( 'age' ) ) { + if ( !$this->age() ) { + $content = apply_filters( 'webcomic_content_verify', sprintf( __( 'Please verify your age to view this webcomic.', 'webcomic' ), get_permalink( $post->ID ) ), $post, $wc ); + $ok = false; + } else { + $content = apply_filters( 'webcomic_content_verify_fail', sprintf( __( 'You must be at least %d years old to view this webcomic.', 'webcomic' ), $wc->term_group ), $post, $wc ); + $ok = false; + } + } - if ( !get_the_collection( 'hide_empty=0&depth=1' ) ) { - $first_series = get_term( $default_category, 'category' ); - wp_insert_term( $first_series->name, 'chapter' ); + if ( $this->option( 'feed_toggle' ) && is_feed() && $ok ) { + $sz = $this->option( 'feed_size' ); + + if ( $files = $this->retrieve( $post->ID, 'post', $wc->slug, true ) ) { + foreach ( $files[ 'full' ] as $k => $v ) { + $file = ( isset( $files[ $sz ][ $k ] ) ) ? $files[ $sz ][ $k ] : $v; + $img .= ( $this->option( 'secure_toggle' ) ) ? $file[ 'html' ] : $file[ 'shtml' ]; + } + + $content = '

    ' . $img . '

    ' . $content; + } + } elseif ( $this->option( 'integrate_toggle' ) && !is_feed() && !is_trackback() && !is_admin() && $this->in_webcomic_term( 'webcomic_collection' ) && $ok ) { + if ( is_home() || is_front_page() || ( is_single() && $this->in_webcomic_term( 'webcomic_collection' ) ) ) { + ?> + + get_the_webcomic_object( 'full' ); ?> + + post_content; + } elseif ( is_archive() && $this->in_webcomic_term( 'webcomic_collection' ) ) { + echo $this->get_the_webcomic_object( 'small' ); + } } } - /** Setup our buffer alert scheduled task hook */ - if ( !wp_next_scheduled( 'webcomic_buffer_alert' ) ) - wp_schedule_event( 0, 'daily', 'webcomic_buffer_alert' ); - - echo '

    ' . sprintf( __( 'Thanks for choosing Webcomic! Please update your settings.', 'webcomic' ), 'admin.php?page=comic-settings' ) . '

    '; + return $content; + } + + /** + *'request' hook. + * + * @package webcomic + * @since 3 + */ + function hook_request( $q ) { + if ( isset( $q[ 'feed' ] ) && !isset( $q[ 'post_type' ] ) ) + $q[ 'post_type' ] = array( 'post', 'webcomic_post' ); - if ( $mkdir_error ) - echo '

    ' . $mkdir_error . '

    '; - } add_action( 'admin_notices', 'webcomic_install' ); -} - - - -// -// Data Retrieval -// - -/** - * Returns the appropriate include URL. - * - * This is an internal utility function for determining the correct - * path (absolute path, relative path, or url path) to a file in - * Webcomic's "includes" directory based on it's installed location: - * either a regular plugins folder or WordPress MU's special "mu-plugins" folder. - * - * @package Webcomic - * @since 2.0.0 - * - * @param str $file The file to include (required). - * @param str $type The type of URL to return, one of 'abs', 'url', or 'rel'. - */ -function webcomic_include_url( $file = false, $type = false ) { - if ( !file ) - return; //Must specify a file + return $q; + } - $mu_check = pathinfo( __FILE__ ); + /** + * 'posts_request' hook. + * + * @package webcomic + * @since 3 + */ + function hook_posts_request( $query ) { + global $wp_query; + + if ( $wp_query->is_search && false === strpos( $query, 'DISTINCT' ) ) + $query = str_replace( 'SELECT', 'SELECT DISTINCT', $query ); + + return $query; + } - if ( strstr( $mu_check[ 'dirname' ], 'mu-plugins' ) ) { - switch ( $type ) { - case 'abs' : return WP_CONTENT_DIR . '/mu-plugins/includes/' . $file; - case 'rel' : return 'includes/' . $file; - case 'url' : - default : return WP_CONTENT_URL . '/mu-plugins/includes/' . $file; - } - } else { - switch ( $type ) { - case 'abs' : return WP_PLUGIN_DIR . '/webcomic/includes/' . $file; - case 'rel' : return 'webcomic/includes/' . $file; - case 'url' : - default : return plugins_url( 'webcomic/includes/' . $file ); - } + /** + * 'posts_join' hook. + * + * @package webcomic + * @since 3 + */ + function hook_posts_join( $join ) { + global $wp_query, $wpdb; + + if ( $wp_query->is_search ) + $join .= " LEFT JOIN $wpdb->postmeta ON $wpdb->posts.ID = $wpdb->postmeta.post_id "; + + return $join; } -} - -/** - * Returns the specified comic category. - * - * This is a utility funciton for retrieving a comic category. If no - * 'id' is specified, the first comic category is returned. An array - * containing all comic categories is returned if 'id' is set to 'all'. - * - * @package Webcomic - * @since 1.0.0 - * - * @param bool $all Return all comic categories as an array. - * @param str $format The format multiple categories should be returned in. - * @return int|arr ID of the first comic category or an array of all comic categories. - */ -function get_comic_category( $all = false, $format = false ) { - $category = get_option( 'comic_category' ); - - if ( $all ) { - if ( 'include' == $format ) { - return implode( ',', $category ); - } elseif ( 'exclude' == $format) { - return '-' . implode( ',-', $category ); - } elseif ( 'random' == $format ) { - $key = array_rand( $category ); - return $category[ $key ]; - } elseif ( 'post_link_exclude' == $format ) { - return implode( ' and ', $category ); - } else { - return $category; + + /** + * 'posts_where' hook. + * + * @package webcomic + * @since 3 + */ + function hook_posts_where( $where ) { + global $wp_query, $wpdb; + + if ( $wp_query->is_archive ) + $where = str_replace( "post_type = 'post'", "post_type IN ('post','webcomic_post')", $where ); + + if ( $wp_query->is_search ) { + $query_terms = explode( ' ', $wp_query->query_vars[ 's' ] ); + + $i = 0; + $or = '('; + + foreach ( $query_terms as $query_term ) { + if ( $query_term !== '' ) { + $or .= "(($wpdb->posts.post_title LIKE '%" . $wpdb->escape( $query_term ) . "%') OR ($wpdb->posts.post_content LIKE '%" . $wpdb->escape( $query_term ) . "%') OR (($wpdb->postmeta.meta_key = 'webcomic') AND $wpdb->postmeta.meta_value LIKE '%" . $wpdb->escape( $query_term ) . "%')) OR "; + $i++; + } + } + + if ( $i > 1 ) + $or .= "(($wpdb->posts.post_title LIKE '" . $wpdb->escape( $wp_query->query_vars[ 's' ] ) . "') OR ($wpdb->posts.post_content LIKE '" . $wpdb->escape( $wp_query->query_vars[ 's' ] ) . "') OR (($wpdb->postmeta.meta_key = 'webcomic') AND $wpdb->postmeta.meta_value LIKE '%" . $wpdb->escape( $wp_query->query_vars[ 's' ] ) . "%')))"; + else + $or = rtrim( $or, ' OR ') . ')'; + + $where = preg_replace( "/\(\(\(.*\)\)/i", $or, $where, 1 ); } - } else { - return ( int ) $category[ 0 ]; + + return $where; } -} - -/** - * Returns the the specified comic directory. - * - * This is a utility funciton for retrieving the specified comic - * directory. This function can return either the absolute or url - * path to the comic root or 'thumbs' directory. - * - * @package Webcomic - * @since 1.0.0 - * - * @param str $type The type of path to return, 'abs' or 'url'. - * @param bool $thumbs Return the comic thumbnail directory. - * @param int $category ID of a specified comic category. - * @return str Path to the comic root or thumbnail directory. - */ -function get_comic_directory( $type = 'abs', $thumbs = false, $category = false ) { - if ( 'root' == $type ) - return get_settings( 'siteurl' ) . '/' . get_option( 'comic_directory' ) . '/'; - - $prepend = ( 'abs' == $type ) ? ABSPATH : get_settings( 'siteurl' ) . '/'; - if ( file_exists( ABSPATH . 'wpmu-settings.php' ) ) //WPMU Check - $prepend = ( 'abs' == $type ) ? BLOGUPLOADDIR : get_settings( 'siteurl' ) . '/files/'; - $catid = ( $category ) ? $category : get_comic_category(); - $cat = &get_category( $catid ); - $catdir = '/' . $cat->slug; - - if ( $thumbs ) - return $prepend . get_option( 'comic_directory' ) . $catdir . '/thumbs/'; - - return $prepend . get_option( 'comic_directory' ) . $catdir . '/'; -} - -/** - * Returns the the current comic chapter for the specified series. - * - * This is a utility funciton for retrieving the current chapter for the - * specified comic series, or all current chapters if $series is set - * to 'all'. - * - * @package Webcomic - * @since 1.0.0 - * - * @param int|str $series ID of a specific comic category or -1. - * @return int|array ID of the slected current comic chapter or all comic chapters. - */ -function get_comic_current_chapter( $series = false ) { - $current_chapters = get_option( 'comic_current_chapter' ); - - if ( !$series ) - return array_shift( array_values( $current_chapters ) ); - elseif ( true === $series ) - return $current_chapters; - else - return $current_chapters[ $series ]; -} - -/** - * Retrieves the comic category for a given post. - * - * This is a utility function to determine which (if any) comic category - * a given post belongs to. If a match is found, the comic category ID - * is returned immediately. - * - * @package Webcomic - * @since 1.8.0 - * - * @param int $id Post ID. - * @return int Category ID. - */ -function get_post_comic_category( $id = false ) { - global $post; + //// + // Hooks - Taxonomy + // + // These functions hook into various WordPress + // taxonomy actions and should never be called + // directly. + //// - $id = ( $id ) ? ( int ) $id : $post->ID; + /** + * 'list_terms_exclusions' hook. + * + * @package webcomic + * @since 3 + */ + function hook_list_terms_exclusions( $exclusions, $args ) { + global $wpdb; + + if ( !empty( $args[ 'term_group' ] ) ) { + + if ( !empty( $args[ 'require_group' ] ) ) { + $term_groups = "'" . implode( "','", preg_split( '/[\s,]+/', $args[ 'term_group' ] ) ) . "'"; + $exclusions .= " AND t.term_group IN ($term_groups) "; + } else { + $term_groups = preg_split( '/[\s,]+/', $args[ 'term_group' ] ); + + foreach ( ( array ) $term_groups as $term_group ) { + if ( $term_groups[ 0 ] == $term_group ) + $exclusions .= " AND (t.term_group = $term_group"; + else + $exclusions .= " OR t.term_group = $term_group"; + } + + $exclusions .= ') '; + } + } + + $taxonomies = array(); + + if ( !empty( $args[ 'webcomic_storyline' ] ) ) $taxonomies[] = 'webcomic_storyline'; + if ( !empty( $args[ 'webcomic_character' ] ) ) $taxonomies[] = 'webcomic_character'; + + if ( !empty( $taxonomies ) ) { + foreach ( $taxonomies as $taxonomy ) { + $terms = preg_split( '/[\s,]+/', $args[ $taxonomy ] ); + $include = $exclude = array(); + + foreach ( ( array ) $terms as $term ) { + if ( $term > 0 ) + $include[] = $term; + else + $exclude[] = abs( $term ); + } + + if ( $args[ 'webcomic_require' ] ) { + if ( $include ) { + $terms = "'" . implode( "','", $include ) . "'"; + $exclusions .= " AND t.term_id IN (SELECT tr.object_id FROM $wpdb->term_relationships AS tr INNER JOIN $wpdb->term_taxonomy AS tt ON tr.term_taxonomy_id = tt.term_taxonomy_id WHERE tt.taxonomy IN ('$taxonomy') AND tt.term_id IN ($terms)) "; + } if ( $exclude ) { + $terms = "'" . implode( "','", $exclude ) . "'"; + $exclusions .= " AND t.term_id NOT IN (SELECT tr.object_id FROM $wpdb->term_relationships AS tr INNER JOIN $wpdb->term_taxonomy AS tt ON tr.term_taxonomy_id = tt.term_taxonomy_id WHERE tt.taxonomy IN ('$taxonomy') AND tt.term_id IN ($terms)) "; + } + } else { + if ( $include ) { + $exclusions .= " AND (t.term_id IN (SELECT tr.object_id FROM $wpdb->term_relationships AS tr INNER JOIN $wpdb->term_taxonomy AS tt ON tr.term_taxonomy_id = tt.term_taxonomy_id WHERE tt.taxonomy IN ('$taxonomy')"; + + foreach ( $include as $term ) { + if ( $include[ 0 ] == $term ) + $exclusions .= " AND tt.term_id = $term"; + else + $exclusions .= " OR tt.term_id = $term"; + } + + $exclusions .= ')) '; + } if ( $exclude ) { + $exclusions .= " AND (t.term_id NOT IN (SELECT tr.object_id FROM $wpdb->term_relationships AS tr INNER JOIN $wpdb->term_taxonomy AS tt ON tr.term_taxonomy_id = tt.term_taxonomy_id WHERE tt.taxonomy IN ('$taxonomy')"; + + foreach ( ( array ) $exclude as $term ) { + if ( $exclude[ 0 ] == $term ) + $exclusions .= " AND tt.term_id = $term"; + else + $exclusions .= " OR tt.term_id = $term"; + } + + $exclusions .= ')) '; + } + } + } + } + + return $exclusions; + } - $post_cats = wp_get_object_terms( $id, 'category', array( 'fields' => 'ids' ) ); - $comic_cats = get_comic_category( true ); + /** + * 'get_terms_orderby' hook. + * + * @package webcomic + * @since 3 + */ + function hook_get_terms_orderby( $orderby, $args ) { + $orderby = ( 'term_group_name' == $args[ 'orderby' ] ) ? 't.term_group,t.name' : $orderby; + return $orderby; + } - if ( $comic_cats ) - foreach ( $post_cats as $post_cat ) - foreach ( $comic_cats as $comic_cat ) - if ( $post_cat == $comic_cat ) - return ( int ) $comic_cat; -} - -/** - * Retrieves the chapter objects for a given post. - * - * This is a utility function used to generate an object of taxonomy - * objects for the specified or current posts chapter, volume, and series. - * - * @package Webcomic - * @since 1.8.0 - * - * @param int $id A valid post ID. - * @return obj Object containg chapter taxonomy objects. - */ -function get_post_comic_chapters( $id = false ) { - global $post; + /** + * 'get_term' hook. + * + * @package webcomic + * @since 3 + */ + function hook_get_term( $term, $taxonomy ) { + if ( 'webcomic_collection' == $taxonomy || 'webcomic_storyline' == $taxonomy || 'webcomic_character' == $taxonomy ) { + $term_meta = $this->option( 'term_meta' ); + $type = end( explode( '_', $taxonomy ) ); + $key = ( 'collection' == $type ) ? $term->term_id : $term->term_group; + + if ( isset( $term_meta[ 'collection' ][ $key ] ) ) + $term->webcomic_files = $this->retrieve( $term->term_id, $type, $term_meta[ 'collection' ][ $key ][ 'slug' ] ); + + if ( 'webcomic_collection' == $taxonomy ) + $term->webcomic_default = ( $term->term_id == $this->option( 'default_collection' ) ) ? true : false; + else + $term->webcomic_default = $term_meta[ $type ][ $term->term_id ][ 'default' ]; + + if ( 'collection' == $type ) { + $term->webcomic_bookend = ( isset( $term_meta[ $type ][ $term->term_id ][ 'bookend' ] ) ) ? $term_meta[ $type ][ $term->term_id ][ 'bookend' ] : NULL; + $term->webcomic_restrict = ( isset( $term_meta[ $type ][ $term->term_id ][ 'restrict' ] ) ) ? $term_meta[ $type ][ $term->term_id ][ 'restrict' ] : NULL; + $term->webcomic_paypal = ( isset( $term_meta[ $type ][ $term->term_id ][ 'paypal' ] ) ) ? $term_meta[ $type ][ $term->term_id ][ 'paypal' ] : NULL; + } elseif ( 'storyline' == $type ) + $term->webcomic_order = $term_meta[ $type ][ $term->term_id ][ 'order' ]; + } + + return $term; + } - $id = ( $id ) ? ( int ) $id : $post->ID; + /** + * 'get_terms' hook. + * + * @package webcomic + * @since 3 + */ + function hook_get_terms( $terms, $taxonomies, $args ) { + if ( in_array( 'webcomic_collection', $taxonomies ) || in_array( 'webcomic_storyline', $taxonomies ) || in_array( 'webcomic_character', $taxonomies ) ) { + $term_meta = $this->option( 'term_meta' ); + + foreach ( $terms as $term ) { + if ( !is_object( $term ) || !( 'webcomic_collection' == $term->taxonomy || 'webcomic_storyline' == $term->taxonomy || 'webcomic_character' == $term->taxonomy ) ) + continue; + + $type = end( explode( '_', $term->taxonomy ) ); + $key = ( 'collection' == $type ) ? $term->term_id : $term->term_group; + + $term->webcomic_files = $this->retrieve( $term->term_id, $type, $term_meta[ 'collection' ][ $key ][ 'slug' ] ); + + if ( 'webcomic_collection' == $term->taxonomy ) + $term->webcomic_default = ( $term->term_id == $this->option( 'default_collection' ) ) ? true : false; + else + $term->webcomic_default = $term_meta[ $type ][ $term->term_id ][ 'default' ]; + + if ( 'collection' == $type ) { + $term->webcomic_bookend = $term_meta[ $type ][ $term->term_id ][ 'bookend' ]; + $term->webcomic_restrict = $term_meta[ $type ][ $term->term_id ][ 'restrict' ]; + $term->webcomic_paypal = $term_meta[ $type ][ $term->term_id ][ 'paypal' ]; + } elseif ( 'storyline' == $type ) + $term->webcomic_order = $term_meta[ 'storyline' ][ $term->term_id ][ 'order' ]; + } + + if ( in_array( 'webcomic_storyline', $taxonomies ) && !empty( $args[ 'webcomic_order' ] ) ) + usort( $terms, array( &$this, 'usort_storylines' ) ); + } + + return $terms; + } - $chapters = wp_get_object_terms( $id, 'chapter' ); + /** + * 'wp_get_object_terms' hook. + * + * @package webcomic + * @since 3 + */ + function hook_wp_get_object_terms( $terms, $object_ids, $taxonomies, $args ) { + if ( 'all' == $args[ 'fields' ] || 'all_with_object_id' == $args[ 'fields' ] ) { + $term_meta = $this->option( 'term_meta' ); + + foreach ( $terms as $term ) { + if ( !( 'webcomic_collection' == $term->taxonomy || 'webcomic_storyline' == $term->taxonomy || 'webcomic_character' == $term->taxonomy ) ) + continue; + + $type = end( explode( '_', $term->taxonomy ) ); + $key = ( 'collection' == $type ) ? $term->term_id : $term->term_group; + + $term->webcomic_files = $this->retrieve( $term->term_id, $type, $term_meta[ 'collection' ][ $key ][ 'slug' ] ); + + if ( 'webcomic_collection' == $term->taxonomy ) + $term->webcomic_default = ( $term->term_id == $this->option( 'default_collection' ) ) ? true : false; + else + $term->webcomic_default = $term_meta[ $type ][ $term->term_id ][ 'default' ]; + + if ( 'collection' == $type ) { + $term->webcomic_bookend = $term_meta[ $type ][ $term->term_id ][ 'bookend' ]; + $term->webcomic_restrict = $term_meta[ $type ][ $term->term_id ][ 'restrict' ]; + $term->webcomic_paypal = $term_meta[ $type ][ $term->term_id ][ 'paypal' ]; + } elseif ( 'storyline' == $type ) + $term->webcomic_order = $term_meta[ 'storyline' ][ $term->term_id ][ 'order' ]; + } + } + + return $terms; + } - if ( !$chapters ) - return; //The post does not beling to any chapters - $post_chapters = new stdClass(); - foreach ( $chapters as $value ) { - if ( !$value->parent ) - $post_chapters->series = $value; - elseif ( !get_term_children( $value->term_id, 'chapter' ) ) - $post_chapters->chapter = $value; - else - $post_chapters->volume = $value; - } + //// + // Hooks - Webcomic + // + // These functions hook into special Webcomic + // defined actions and should never be called + // directly. + //// - return $post_chapters; -} - -/** - * Returns the current webcomic series ID based on the requested path. - * - * This funciton checks the requrested URL for various parameters - * in an attempt to find what comic series, if any, the requested - * pages is associated with. If the page is associated witha comic - * series the series ID is returned. - * - * @package Webcomic - * @since 2.0.0 - * - * @return Category ID. - */ -function get_series_by_path() { - if ( get_option( 'permalink_structure' ) ) { - if ( $_SERVER[ 'HTTPS' ] ) - $s = ( 'on' == $_SERVER[ 'HTTPS' ] ) ? 's' : ''; - - $port = ( '80' == $_SERVER[ 'SERVER_PORT' ] ) ? '' : ':' . $_SERVER[ 'SERVER_PORT' ]; - $url = "http$s://" . $_SERVER[ 'SERVER_NAME' ] . $port . $_SERVER[ 'REQUEST_URI' ]; - list( $url ) = explode( '?', $url ); - - $pid = url_to_postid( $url ); - - list( $url ) = explode( '/page/', $url ); + /** + * 'webcomic_buffer_alert' hook. + * + * @package webcomic + * @since 3 + */ + function hook_webcomic_buffer_alert() { + if ( !$this->option( 'buffer_toggle' ) ) + return false; - $cid = get_category_by_path( $url, false ); - $cid = $cid->cat_ID; + $this->domain(); - $url = rawurlencode( urldecode( $url ) ); - $url = str_replace( '%2F', '/', $url ); - $url = str_replace( '%20', ' ', $url ); - $urls = '/' . trim( $url, '/' ); - $slug = sanitize_title( basename( $urls ) ); + global $wpdb; - $chapter = get_term_by( 'slug', $slug, 'chapter' ); + $now = time(); + $terms = get_terms( 'webcomic_collection', 'get=all' ); - if ( $chapter ) { - if ( $chapter->parent ) { - $chapter = get_term( $chapter->parent, 'chapter' ); + foreach ( $terms as $term ) { + $ids = get_objects_in_term( $term->term_id, 'webcomic_collection' ); + + if ( $ids && !is_wp_error( $ids ) && $post = $wpdb->get_var( "SELECT post_date FROM $wpdb->posts WHERE post_status = 'future' AND ID IN (" . implode( ',', $ids ) . ") ORDER BY post_date DESC" ) ) { + $eta = floor( ( strtotime( $post ) - $now ) / 86400 ); - if ( $chapter->parent ) - $chapter = get_term( $chapter->parent, 'chapter' ); + if ( $eta && $eta <= $this->option( 'buffer_size' ) ) + wp_mail( get_option( 'admin_email' ), sprintf( _n( '[%s] Buffer Alert for %s - Only %d Day Left', '[%s] Buffer Alert for %s - Only %d Days Left', $eta, 'webcomic' ), html_entity_decode( get_option( 'blogname' ) ), html_entity_decode( $term->name ), $eta ), sprintf( __( "This is an automated reminder that your buffer for %s will run out on %s ($d days from now).\n\nYou can disable these automatic reminders from the Webcomic Settings page.", "webcomic" ), html_entity_decode( $term->name ), get_the_time( 'j F y', strtotime( $post ) ), $eta, admin_url( 'admin.php?page=webcomic_settings' ) ) ); } - - $sid = $chapter->term_id; } - } else { - $pid = ( $_GET[ 'p' ] ) ? $_GET[ 'p' ] : $_GET[ 'page_id' ]; - $cid = $_GET[ 'cat' ]; } - if ( get_post_meta( $pid, 'comic_series', true ) ) - $pid = get_post_meta( $pid, 'comic_series', true ); - else - $pid = get_post_comic_category( $pid ); - - if ( $pid ) - return get_category( $pid ); - elseif ( $cid ) - return get_category( $cid ); - elseif ( $sid ) - return get_category( $sid ); -} - - - -// -// Search Unification -// - -/** - * Removes duplicates from search results. - * - * @package Webcomic - * @since 1.5.0 - */ -function webcomic_post_request( $query ) { - global $wp_query; - - if ( $wp_query->is_search && false === strpos( $where, 'DISTINCT' ) ) - $query = str_replace( 'SELECT', 'SELECT DISTINCT', $query ); - return $query; -} add_filter( 'posts_request', 'webcomic_post_request' ); - -/** - * Adds post meta data to the search query. - * - * @package Webcomic - * @since 1.5.0 - */ -function webcomic_posts_join( $join ) { - global $wp_query, $wpdb; - if ( $wp_query->is_search ) - $join .= " LEFT JOIN $wpdb->postmeta ON $wpdb->posts.ID = $wpdb->postmeta.post_id "; + ////OK + // Utilities + // + // These functions are designed for internal use + // and should never be called directly. + //// - return $join; -} add_filter( 'posts_join', 'webcomic_posts_join' ); - -/** - * Adds specific checks for finding content based on the 'comic_description' - * and 'comic_transcript' custom field matches. - * - * @package Webcomic - * @since 1.5.0 - */ -function webcomic_posts_where( $where ) { - global $wp_query, $wpdb; + /** + * Sorts storylines by the user-defined order. + * + * @package webcomic + * @since 3 + */ + function usort_storylines( $a, $b ) { + if ( $a->webcomic_order > $b->webcomic_order ) + return 1; + elseif ( $a->webcomic_order < $b->webcomic_order ) + return -1; + else + return 0; + } - $query_terms = explode( ' ', $wp_query->query_vars[ 's' ] ); + /** + * Sorts terms by term_group. + * + * @package webcomic + * @since 3 + */ + function usort_terms_by_collection( $a, $b ) { + if ( $a->term_group > $b->term_group ) + return 1; + elseif ( $a->term_group < $b->term_group ) + return -1; + else + return 0; + } - $or = '('; + /** + * Sorts term object ID's by date. + * + * @package webcomic + * @since 3 + */ + function usort_term_objects_by_date( $a, $b ) { + $a = get_the_time( 'U', $a ); + $b = get_the_time( 'U', $b ); + + if ( $a > $b ) + return 1; + elseif ( $a < $b ) + return -1; + else + return 0; + } - foreach ( $query_terms as $query_term ) { - if ( $Query_term !== '' ) { - $or .= "(($wpdb->posts.post_title LIKE '%" . $wpdb->escape( $query_term ) . "%') OR ($wpdb->posts.post_content LIKE '%" . $wpdb->escape( $query_term ) . "%') OR (($wpdb->postmeta.meta_key = 'comic_transcript' OR $wpdb->postmeta.meta_key = 'comic_description') AND $wpdb->postmeta.meta_value LIKE '%" . $wpdb->escape( $query_term ) . "%')) OR "; - $i++; + /** + * Retrieves path or URI to the specified file directory. + * + * @package webcomic + * @since 3 + * + * @param str $type One of 'abs' or 'url'. + * @param str $sub Name of the subdirectory to retrieve. + */ + function directory( $type = null, $sub = null ) { + switch ( $type ) { + case 'abs': if ( $sub ) return $this->cdir . 'webcomic/' . $sub . '/'; else return $this->cdir . 'webcomic/'; + case 'url': if ( $sub ) return $this->curl . 'webcomic/' . $sub . '/'; else return $this->curl . 'webcomic/'; + default: return false; } } - if ( $i > 1 ) - $or .= "(($wpdb->posts.post_title LIKE '" . $wpdb->escape( $wp_query->query_vars[ 's' ] ) . "') OR ($wpdb->posts.post_content LIKE '" . $wpdb->escape( $wp_query->query_vars[ 's' ] ) . "') OR (($wpdb->postmeta.meta_key = 'comic_transcript' OR $wpdb->postmeta.meta_key = 'comic_description') AND $wpdb->postmeta.meta_value LIKE '%" . $wpdb->escape( $wp_query->query_vars[ 's' ] ) . "%')))"; - else - $or = rtrim( $or, ' OR ') . ')'; - - $where = preg_replace( "/\(\(\(.*\)\)/i", $or, $where, 1 ); - - return $where; -} add_filter( 'posts_where', 'webcomic_posts_where' ); - - - -// -// Comic Templates -// - -/** - * Loads a comic-specific template and sets the $webcomic_series global. - * - * This function checks the requested url to see if the - * requested page is either directly related to a specific - * comic category or has the 'comic_series' custom field set. - * If either is true, it will check if a template exists in - * "webcomic-cat-slug" and load that template instead, if one exists. - * - * @package Webcomic - * @since 2.0.0 - * - * @param str $template The current template string. - * @return str New theme directory or $template - */ -function webcomic_series_template() { - global $webcomic_series; - - $webcomic_series = get_series_by_path(); - - if ( $webcomic_series && is_dir( get_theme_root() . '/webcomic-' . $webcomic_series->slug ) ) { - function load_series_template() { - global $webcomic_series; - - return 'webcomic-' . $webcomic_series->slug; - } add_filter( 'stylesheet', 'load_series_template' ); + /** + * Determines the age (in years) of the current user. + * + * @package webcomic + * @since 3 + */ + function age() { + global $current_user; + + $user_meta = ( is_array( $a = get_user_meta( $current_user->ID, 'webcomic' ) ) ) ? current( $a ) : array(); + + if ( isset( $user_meta[ 'birthday' ] ) ) + return ( time() - $user_meta[ 'birthday' ] ) / 31556926; + elseif ( isset( $_COOKIE[ 'webcomic_birthday_' . COOKIEHASH ] ) ) + return ( time() - $_COOKIE[ 'webcomic_birthday_' . COOKIEHASH ] ) / 31556926; + else + return false; } -} add_action( 'template_redirect', 'webcomic_series_template' ); - - - -// -// Other Stuff -// - -/** - * Registers the 'chapter' taxonomy. - * - * @package Webcomic - * @since 2.0.0 - */ -function webcomic_init() { - register_taxonomy( 'chapter', 'post', array( 'hierarchical' => true, 'update_count_callback' => '_update_post_term_count', 'label' => 'Chapter' ) ); -} add_action( 'init', 'webcomic_init' ); - -/** - * Displays the comic in the site feed. - * - * @package Webcomic - * @since 1.0.0 - */ -if ( get_option( 'comic_feed' ) ) { - function webcomic_feed( $content ) { - if ( is_feed() ) $prepend = ( in_comic_category() ) ? '

    ' . get_comic_object( get_the_comic(), get_option( 'comic_feed_size' ) ) . '

    ' : ''; + /** + * Verifies that the current user can access webcomic content. + * + * @package webcomic + * @since 3 + * + * @param str $type One of 'age' or 'restrict'. + * @param str $id The post ID to get verification info from. + * @return True if the user is verified, false otherwise. + */ + function verify( $type = false, $id = false ) { + global $post; - return $prepend . $content; - } add_filter( 'the_content', 'webcomic_feed' ); -} - -/** - * Sends buffer comic notifications on a daily basis. - * - * @package Webcomic - * @since 2.1.0 - */ -if ( get_option( 'comic_buffer' ) ) { - function webcomic_buffer_alert() { - $cats = get_comic_category( true ); - $now = time(); + $collection = $storyline = $character = false; - foreach ( $cats as $cat ) { - $buffer = get_comic_buffer( $cat ); - $info = get_term( $cat, 'category' ); - $eta = floor( ( $buffer->timestamp - $now ) / 86400 ); - - if ( $buffer && $eta == get_option( 'comic_buffer_alert' ) ) - @wp_mail( get_option( 'admin_email' ), sprintf( __( '[%s] Buffer Alert for %s', 'webcomic' ), html_entity_decode( get_option( 'blogname' ) ), html_entity_decode( $info->name ) ), sprintf( __( 'This is an automated reminder that your buffer for %s will run out on %s ($d days away).', 'webcomic' ), html_entity_decode( $info->name ), $buffer->datetime, get_option( 'comic_buffer_alert' ) - $eta ) ); - } - } add_action( 'webcomic_buffer_alert', 'webcomic_buffer_alert' ); -} - -/** - * Handles secure URL's, transcript.php form requests, and enqueue's necessary javascript. - * - * @package Webcomic - * @since 2.0.0 - */ -function webcomic_template_redirect() { - //Display the specified comic object from a secured URL - if ( $_GET[ 'comic_object' ] ) { - $info = explode( '/', $_GET[ 'comic_object' ] ); - $comic = get_the_comic( $info[ 0 ] ); - - $headers = ( function_exists( 'getallheaders' ) ) ? getallheaders() : false; - $size = ( $info[ 1 ] ) ? $info[ 1 ] : 'full'; - $dir = get_post_comic_category( $comic->ID ); - $fpath = get_comic_directory( 'abs', false, $dir ); - $tpath = get_comic_directory( 'abs', true, $dir ); + if ( !$post && !$id && !( ( $collection = get_query_var( 'webcomic_collection' ) ) || !( $storyline = get_query_var( 'webcomic_storyline' ) ) || !( $character = get_query_var( 'webcomic_character' ) ) ) || ( 'age' == $type && !$this->option( 'age_toggle' ) ) || ( 'restrict' == $type && is_user_logged_in() ) ) + return true; + + if ( $id ) + $wc = current( wp_get_object_terms( $id, 'webcomic_collection' ) ); + elseif ( $post ) + $wc = current( wp_get_object_terms( $post->ID, 'webcomic_collection' ) ); + elseif ( $collection ) + $wc = get_term_by( 'slug', $collection, 'webcomic_collection' ); + elseif ( $storyline && ( $t = get_term_by( 'slug', $collection, 'webcomic_storyline' ) ) ) + $wc = get_term( $t->term_group, 'webcomic_collection' ); + elseif ( $character && ( $t = get_term_by( 'slug', $collection, 'webcomic_character' ) ) ) + $wc = get_term( $t->term_group, 'webcomic_collection' ); + else + return true; - if ( 'full' == $size || $comic->flash ) - $size = $fpath . $comic->file_name; + if ( empty( $wc ) ) + return true; - if ( 'large' == $size ) - $size = ( $comic->large ) ? $tpath . $comic->large_name : 'medium'; + $age = ( !$this->option( 'age_toggle' ) || $wc->term_group < $this->option( 'age_size' ) || $this->age() > $wc->term_group ) ? true : false; + $restrict = ( $wc->webcomic_restrict && !is_user_logged_in() ) ? false : true; - if ( 'medium' == $size ) - $size = ( $comic->medium ) ? $tpath . $comic->medium_name : 'thumb'; + if ( 'age' == $type ) + return $age; + elseif ( 'restrict' == $type ) + return $restrict; + elseif ( $age && $restrict ) + return true; + else + return false; + } + + /** + * Calculates a price based on input. + * + * Given a $base, this function iterates through specified + * amounts and adds or subtracts their value (based on $rate + * and $type). Discount amounts that would reduce the final + * price to zero or less are ignored. + * + * @package webcomic + * @since 3 + * + * @param float $base The starting amount. Cannot be negative or zero. + * @param arr $amount An array of float amounts that will adjust the $base. + * @param arr $rate An array of str rates, one for each amount. Must be 'fixed' or 'percent'. + * @return float|bool The final price, rounded to two decimal places, or false on error. + */ + function price( $base, $amount, $rate = false ) { + $output = abs( floatval( $base ) ); + $m = $c = 0; - if ( 'thumb' == $size ) - $size = ( $comic->thumb ) ? $tpath . $comic->thumb_name : $fpath . $comic->file_name; + if ( !$output ) + return false; - if ( $headers && isset( $headers[ 'If-Modified-Since' ] ) && ( strtotime( $headers[ 'If-Modified-Since' ] ) == filemtime( $size ) ) ) { - header( 'Last-Modified: ' . gmdate( 'D, d M Y H:i:s', filemtime( $size ) ) . ' GMT', true, 304 ); - } else { - header( 'Last-Modified: ' . gmdate( 'D, d M Y H:i:s', filemtime( $size ) ) . ' GMT', true, 200 ); - header( 'Content-Length: ' . filesize( $size ) ); - header( 'Content-Type: ' . $comic->file_data[ 'mime' ] ); + foreach ( $amount as $k => $v ) { + if ( !$v ) + continue; - die( readfile( $size ) ); + $r = ( isset( $rate[ $k ] ) ) ? $rate[ $k ] : 'percent'; + $m = ( 'fixed' == $r ) ? abs( $v ) : $output * ( abs( $v ) / 100 ); + $c = ( $v < 0 ) ? $output - $m : $output + $m; + + if ( $c <= .01 ) + continue; + else + $output = $c; } + + return round( $output, 2 ); } - //Enqueue javascript required for various Webcomic features - wp_enqueue_script( 'jquery-cookie', webcomic_include_url( 'jquery.cookie.js' ), array( 'jquery' ) ); - wp_enqueue_script( 'jquery-konami', webcomic_include_url( 'jquery.konami.js' ), array( 'jquery' ) ); - wp_enqueue_script( 'webcomic-scripts', webcomic_include_url( 'scripts.js' ), array( 'jquery', 'jquery-hotkeys', 'jquery-form', 'jquery-cookie' ) ); + /** + * Fetches the filenames associated with an object. + * + * @package webcomic + * @since 3 + * + * @param int $id ID of the object to fetch files from. + * @param str $type The type of object to fetch for. Must be one of 'collection', 'storyline', 'character', 'post', or 'orphan'. + * @param str $src The directory to search when fetch files for 'orphan' type objects. + * @param bool $match Attempt to match the object with posts if no posts are associated with it. + * @return arr Array of filenames, or false on error. + */ + function fetch( $id, $type, $src, $match = false ) { + $abs = $this->directory( 'abs', $src ); + $tabs = $abs . 'thumbs/'; + + if ( 'collection' == $type || 'storyline' == $type || 'character' == $type ) { + $term_meta = $this->option( 'term_meta' ); + $files = $term_meta[ $type ][ $id ][ 'files' ]; + } elseif( 'post' == $type ) { + $post_meta = current( ( array ) get_post_meta( $id, 'webcomic' ) ); + $files = ( empty( $post_meta[ 'files' ] ) && $match ) ? $this->match( $id, $src ) : $post_meta[ 'files' ]; + } elseif ( 'orphan' == $type ) { + $info = pathinfo( $abs . stripslashes( $id ) ); + $files[ 'full' ] = array( $info[ 'basename' ] ); + + if ( is_file( $tabs . $info[ 'filename' ] . '-small.' . $info[ 'extension' ] ) ) + $files[ 'small' ] = array( $info[ 'filename' ] . '-small.' . $info[ 'extension' ] ); + if ( is_file( $tabs . $info[ 'filename' ] . '-medium.' . $info[ 'extension' ] ) ) + $files[ 'medium' ] = array( $info[ 'filename' ] . '-medium.' . $info[ 'extension' ] ); + if ( is_file( $tabs . $info[ 'filename' ] . '-large.' . $info[ 'extension' ] ) ) + $files[ 'large' ] = array( $info[ 'filename' ] . '-large.' . $info[ 'extension' ] ); + } else + return false; + + return $files; + } - //Handle transcript.php form requests - if ( $_POST[ 'comic_transcript_submit' ] ) { - global $transcript_response; + /** + * Retrives detailed information for the files associated with an object. + * + * @package webcomic + * @since 3 + * + * @param int $id ID of the object to fetch files from. + * @param str $type The type of object to fetch for. Must be one of 'collection', 'storyline', 'character', 'post', or 'orphan'. + * @param str $src The directory to search when fetch files for 'orphan' type objects. + * @param bool $match Attempt to match the object with posts if no posts are associated with it. + * @return arr Array of file data, or false on error. + */ + function retrieve( $id, $type, $src, $match = false ) { + if ( !( $files = $this->fetch( $id, $type, $src, $match ) ) ) + return false; - $before = ''; - $after = ''; - $captcha = ( $_POST[ 'trans_checksum' ] ) ? md5( $_POST[ 'trans_captcha' ] ) == $_POST[ 'trans_checksum' ] : true; - $human = ( 1 < $_POST[ 'comic_transcript_submit' ] ) ? $_POST[ 'trans_human' ] : true; + global $wpdb; - if ( !get_post_meta( $_POST[ 'trans_id' ], 'comic_transcript_draft', true ) && !get_post_meta( $_POST[ 'trans_id' ], 'comic_transcript', true ) && ( $human && $captcha ) ) { - if ( !$_POST[ 'transcript' ] || ( get_option( 'comic_transcripts_required' ) && ( !$_POST[ 'trans_author' ] || !$_POST[ 'trans_email' ] ) ) ) { - $error = 1; - $message = ( get_option( 'comic_transcripts_required' ) && ( !$_POST[ 'trans_author' ] || !$_POST[ 'trans_email' ] ) ) ? __( 'Error: all fields are required.', 'webcomic' ) : __( 'Error: please type a transcript.', 'webcomic' ) ; - } elseif ( get_option( 'comic_transcripts_required' ) && !filter_var( $_POST[ 'trans_email' ], FILTER_VALIDATE_EMAIL ) ) { - $error = 1; - $message = __( 'Error: invalid e-mail address.', 'webcomic' ); - } else { - $email = ( $_POST[ 'trans_email' ] ) ? ' (' . $_POST[ 'trans_email' ] . ')' : ''; - $from = ( $_POST[ 'trans_author' ] ) ? stripslashes( $_POST[ 'trans_author' ] ) . $email : __( 'Anonymous', 'webcomc' ); - $title = stripslashes( $_POST[ 'trans_title' ] ); - $transcript = "\n\n" . wp_filter_kses( $_POST[ 'transcript' ] ) . "\n\n"; - $message = sprintf( __( '%1$s has submitted a new transcript for %2$s.%3$sYou can approve, edit, or delete this transcript by visiting: %4$s', 'webcomic' ), $from, $title, $transcript, admin_url( 'post.php?action=edit&post=' . $_POST[ 'trans_id' ] ) ); - $postmeta = sprintf( __( '{ Submitted by %1$s on %2$s }', 'webcomic' ), $from, date( get_option( 'date_format' ) . ' ' . get_option( 'time_format' ) ) ) . rtrim( $transcript ); - - add_post_meta( $_POST[ 'trans_id' ], 'comic_transcript_draft', $postmeta, true ); - - if ( 1 < $_POST[ 'trans_type' ] ) { - add_post_meta( $_POST[ 'trans_id' ], 'comic_transcript_backup', get_post_meta( $_POST[ 'trans_id' ], 'comic_transcript_pending', true ), true ); - delete_post_meta( $_POST[ 'trans_id' ], 'comic_transcript_pending' ); - } + $output = array(); + $abs = $this->directory( 'abs', $src ); + $url = $this->directory( 'url', $src ); + $tabs = $abs . 'thumbs/'; + $turl = $url . 'thumbs/'; + $size = array( 'full', 'large', 'medium', 'small' ); + $image = apply_filters( 'webcomic_retrieve_image', '%alt', $id, $type ); + $flash = apply_filters( 'webcomic_retrieve_flash', '%alt' ); + $post_meta = ( 'post' == $type ) ? current( get_post_meta( $id, 'webcomic' ) ) : false; + + foreach ( array_keys( $files[ 'full' ] ) as $k ) { + if ( 'post' == $type ) { + $alt = ( isset( $post_meta[ 'alternate' ][ $k ] ) ) ? $post_meta[ 'alternate' ][ $k ] : ''; + $des = ( isset( $post_meta[ 'description' ][ $k ] ) ) ? $post_meta[ 'description' ][ $k ] : ''; + } else + $alt = $des = ( 'collection' == $type || 'storyline' == $type || 'character' == $type ) ? '' : $files[ 'full' ][ $k ]; + + foreach ( $size as $s ) { + if ( empty( $files[ $s ][ $k ] ) ) + continue; - @wp_mail( get_option( 'admin_email' ), sprintf( __( '[%s] New Transcript for "%s"', 'webcomic' ), html_entity_decode( get_option( 'blogname' ) ), html_entity_decode( $title ) ), $message ); + $output[ $s ][ $k ] = array_merge( getimagesize( ( ( 'full' == $s ) ? $abs : $tabs ) . $files[ $s ][ $k ] ), pathinfo( ( ( 'full' == $s ) ? $abs : $tabs ) . $files[ $s ][ $k ] ) ); + $output[ $s ][ $k ][ 'url' ] = ( ( 'full' == $s ) ? $url : $turl ) . $files[ $s ][ $k ]; + $output[ $s ][ $k ][ 'surl' ] = get_bloginfo( 'url' ) . '/?webcomic_object=' . $type . '/' . $id . '/' . $s . '/' . $k; - $before = ''; - $message = __( 'Thanks! Your transcript has been submitted for approval.', 'webcomic' ); + $obj = ( 'application/x-shockwave-flash' == $output[ $s ][ $k ][ 'mime' ] ) ? str_replace( '%des', $des, str_replace( '%alt', $alt, str_replace( '%size', $s, str_replace( '%width', $output[ $s ][ $k ][ 0 ], str_replace( '%height', $output[ $s ][ $k ][ 1 ], str_replace( '%uid', hash( 'md5', $output[ $s ][ $k ][ 'url' ] ), $flash ) ) ) ) ) ) : str_replace( '%des', $des, str_replace( '%alt', $alt, str_replace( '%size', $s, str_replace( '%heightwidth', $output[ $s ][ $k ][ 3 ], str_replace( '%uid', hash( 'md5', $output[ $s ][ $k ][ 'url' ] ), $image ) ) ) )); + + $output[ $s ][ $k ][ 'html' ] = str_replace( '%url', $output[ $s ][ $k ][ 'url' ], $obj ); + $output[ $s ][ $k ][ 'shtml' ] = str_replace( '%url', $output[ $s ][ $k ][ 'surl' ], $obj ); + $output[ $s ][ $k ][ 'bbcode' ] = ( 'application/x-shockwave-flash' == $output[ $s ][ $k ][ 'mime' ] ) ? '' : '[img]' . $output[ $s ][ $k ][ 'url' ] . '[/img]'; + $output[ $s ][ $k ][ 'sbbcode' ] = ( 'application/x-shockwave-flash' == $output[ $s ][ $k ][ 'mime' ] ) ? '' : '[img]' . $output[ $s ][ $k ][ 'surl' ] . '[/img]'; } - } elseif ( $_POST[ 'trans_human' ] && md5( $_POST[ 'trans_captcha' ] ) == $_POST[ 'trans_checksum' ] ) { - $error = 1; - $message = ( get_post_meta( $_POST[ 'trans_id' ], 'comic_transcript', true ) ) ? __( 'Error: a transcript has already been approved.', 'webcomic' ) : __( 'Error: a transcript is already awaiting approval.', 'webcomic' ); - } else { - $error = 1; - $message = __( 'Error: human check failed, please try again.', 'webcomic' ); + + unset( $alt, $des, $obj ); } - - if ( 1 < $_POST[ 'comic_transcript_submit' ] ) - die( $before . $message . $after ); - elseif ( $error ) - wp_die( $before . $message . $after ); - else - $transcript_response = $before . $message . $after; - } -} add_action( 'template_redirect', 'webcomic_template_redirect' ); - -/** - * Add webcomic-specific CSS classes to body element. - * - * @package Webcomic - * @since 2.1.0 - * - * @param arr $classes Body class array. - * @return arr The updated $classes array. - */ -function webcomic_body_class( $classes ) { - global $webcomic_series; - - //Must be a Webcomic powered site - $classes[] = 'webcomic'; - - //Add the webcomic series class - if ( $webcomic_series ) $classes[] = 'webcomic-' . $webcomic_series->slug; - - return $classes; -} add_filter( 'body_class', 'webcomic_body_class' ); - -/** - * Add webcomic-specific CSS classes to post elements. - * - * @package Webcomic - * @since 2.1.0 - * - * @param arr $classes Post class array. - * @return arr The updated $classes array. - */ -function webcomic_post_class( $classes ) { - global $post; - - //Change the post type for comics - if ( in_comic_category() ) { - $classes[ 0 ] = 'comic-' . $post->ID; - $classes[ 1 ] = 'comic'; + + return apply_filters( 'webcomic_retrieve_files', $output, $id, $type, $src, $match ); } - //Add chapter calsses for comic posts assigned to a chapter - if ( $chapters = get_post_comic_chapters() ) { - $classes[] = 'series-' . $chapters->series->slug; - $classes[] = 'volume-' . $chapters->volume->slug; - $classes[] = 'chapter-' . $chapters->chapter->slug; + /** + * Matches a post with an existing file. + * + * Attempts to match a specified post with an + * existing file. Uses the post date by default, + * but the 'webcomic_match_key' filter can be used + * to change the format or replace the date with any + * post-specific criteria for matching. + * + * @package webcomic + * @since 3 + * + * @param int $id ID of the post to be matched. + * @param str $src The directory to search for matching files. + * @return arr An array of files, or false if no match can be found. + */ + function match( $id, $src ) { + $key = apply_filters( 'webcomic_match_key', get_the_time( 'Y-m-d', $id ), $id, get_term_by( 'slug', $src, 'webcomic_collection' ) ); + $abs = $this->directory( 'abs', $src ); + $tabs = $abs . 'thumbs/'; + $output = array(); + + if ( !( $files = glob( $abs . '*.*' ) ) ) + return false; + + foreach ( $files as $file ) { + if ( false !== strpos( $file, $key ) ) { + $output[ 'full' ] = array( basename( $file ) ); + break; + } + } + + if ( empty( $output ) ) + return false; + + $thumbs = glob( $tabs . '*.*' ); + + foreach ( $thumbs as $thumb ) { + if ( false !== strpos( $thumb, $key ) && false !== strpos( $thumb, '-large.' ) ) + $output[ 'large' ] = array( basename( $thumb ) ); + + if ( false !== strpos( $thumb, $key ) && false !== strpos( $thumb, '-medium.' ) ) + $output[ 'medium' ] = array( basename( $thumb ) ); + + if ( false !== strpos( $thumb, $key ) && false !== strpos( $thumb, '-small.' ) ) + $output[ 'small' ] = array( basename( $thumb ) ); + } + + return $output; } - - return $classes; -} add_filter( 'post_class', 'webcomic_post_class' ); - +} global $webcomic; -/** - * Enqueue's necessary javascript for administrative pages. - */ -function webcomic_admin_print_scripts() { - wp_enqueue_script( 'webcomic-admin-scripts', webcomic_include_url( 'admin-scripts.js' ), array( 'jquery' ) ); -} add_action( 'admin_print_scripts', 'webcomic_admin_print_scripts' ); +include_once( 'webcomic-includes/tags-legacy.php' ); +include_once( 'webcomic-includes/widgets.php' ); -/** - * wc-core.php contains all of the new template tags. - * wc-widgets.php contains all of the new widgets. - * wc-admin.php initializes core administrative functions. - * wc-admin-settings.php contains all Settings page functionality. - * wc-admin-library.php contains all Library page functionality. - * wc-admin-chapters.php contains all Chapters page functionality. - * wc-admin-metabox.php contains all Metabox functionality. - */ -require_once( 'includes/wc-core.php' ); -require_once( 'includes/wc-widgets.php' ); if ( is_admin() ) { - require_once( 'includes/wc-admin.php' ); - require_once( 'includes/wc-admin-library.php' ); - require_once( 'includes/wc-admin-chapters.php' ); - require_once( 'includes/wc-admin-settings.php' ); - require_once( 'includes/wc-admin-metabox.php' ); + include_once( 'webcomic-includes/admin.php' ); + include_once( 'webcomic-includes/admin-walker.php' ); +} else { + include_once( 'webcomic-includes/tags.php' ); + include_once( 'webcomic-includes/walker.php' ); } + +$instance = apply_filters( 'webcomic_initialize_class', 'webcomic' ); +$webcomic = new $instance; ?> \ No newline at end of file