From 9bbe3feb1e5fe5f09e04305fd84928ee52d9f5a3 Mon Sep 17 00:00:00 2001 From: Frumph Date: Sun, 27 May 2012 01:42:13 -0700 Subject: [PATCH] Complete rewrite and release of Comic Easel, 05/27/2012 1:43am --- ceo-admin.php | 76 +- ceo-ajax-functions.php | 48 - ceo-config.php | 153 +- ceo-image-manager.php | 26 - comiceasel.php | 124 +- css/admin-editor.css | 6 + css/ceo-admin.css | 82 - css/comiceasel.css | 134 +- css/config.css | 233 ++ css/default.css | 10 - css/uploadify.css | 53 - functions/admin-meta.php | 82 +- functions/displaycomic.php | 372 +--- functions/easyphpthumbnail.class.php | 2029 ------------------ functions/filters.php | 47 + functions/injections.php | 206 +- functions/library.php | 57 + functions/navigation.php | 20 +- functions/redirects.php | 62 + functions/shortcodes.php | 198 ++ functions/uploader.php | 86 - images/easel_small.png | Bin 0 -> 5657 bytes js/fileuploader.js | 1018 --------- options/general.php | 58 + options/navigation.php | 84 + readme.txt | 121 +- screenshot-1.jpg | Bin 0 -> 133414 bytes scripts/check.php | 35 - scripts/expressInstall.swf | Bin 727 -> 0 bytes scripts/uploadify.php | 46 - scripts/uploadify.swf | Bin 23119 -> 0 bytes widgets/comic-archive-dropdown.php | 105 + widgets/{calendar.php => comic-calendar.php} | 15 +- widgets/recentcomics.php | 48 +- widgets/thumbnail.php | 38 +- 35 files changed, 1607 insertions(+), 4065 deletions(-) delete mode 100644 ceo-ajax-functions.php delete mode 100644 ceo-image-manager.php create mode 100644 css/admin-editor.css delete mode 100644 css/ceo-admin.css create mode 100644 css/config.css delete mode 100644 css/default.css delete mode 100644 css/uploadify.css delete mode 100644 functions/easyphpthumbnail.class.php create mode 100644 functions/filters.php create mode 100644 functions/library.php create mode 100644 functions/redirects.php create mode 100644 functions/shortcodes.php delete mode 100644 functions/uploader.php create mode 100644 images/easel_small.png delete mode 100644 js/fileuploader.js create mode 100644 options/general.php create mode 100644 options/navigation.php create mode 100644 screenshot-1.jpg delete mode 100644 scripts/check.php delete mode 100644 scripts/expressInstall.swf delete mode 100644 scripts/uploadify.php delete mode 100644 scripts/uploadify.swf create mode 100644 widgets/comic-archive-dropdown.php rename widgets/{calendar.php => comic-calendar.php} (97%) diff --git a/ceo-admin.php b/ceo-admin.php index ace104c..8d5a84d 100644 --- a/ceo-admin.php +++ b/ceo-admin.php @@ -1,6 +1,5 @@ + + 3, 'show_summary' => true)); + wp_widget_rss_output('http://frumph.net/?feed=rss2', array('items' => 3, 'show_summary' => true)); } function ceo_add_dashboard_widgets() { - wp_add_dashboard_widget('ceo_dashboard_widget', 'ComicPress.NET News', 'ceo_dashboard_feed_widget'); + wp_add_dashboard_widget('ceo_dashboard_widget', 'Frumph.NET News', 'ceo_dashboard_feed_widget'); } +function ceo_enqueue_admin_cpt_style( $cpt, $handle, $src = false, $deps = array(), $ver = false, $media = 'all' ) { + + /* Check the admin page we are on. */ + global $pagenow; + + /* Default to null to prevent enqueuing. */ + $enqueue = null; + + /* Enqueue style only if we are on the correct CPT editor page. */ + if ( isset($_GET['post_type']) && $_GET['post_type'] == $cpt && $pagenow == "post-new.php" ) { + $enqueue = true; + } + + /* Enqueue style only if we are on the correct CPT editor page. */ + if ( isset($_GET['post']) && $pagenow == "post.php" ) { + $post_id = $_GET['post']; + $post_obj = get_post( $post_id ); + if( $post_obj->post_type == $cpt ) + $enqueue = true; + } + + /* Only enqueue if editor page is the correct CPT. */ + if( $enqueue ) + wp_enqueue_style( $handle, $src, $deps, $ver, $media ); +} ?> \ No newline at end of file diff --git a/ceo-ajax-functions.php b/ceo-ajax-functions.php deleted file mode 100644 index e09e184..0000000 --- a/ceo-ajax-functions.php +++ /dev/null @@ -1,48 +0,0 @@ - \ No newline at end of file diff --git a/ceo-config.php b/ceo-config.php index b0f0cba..cf4bb73 100644 --- a/ceo-config.php +++ b/ceo-config.php @@ -1,15 +1,144 @@ -
+
+

- - - - - - - -
error
+

+
+ +

+ +

+ + +
+
+ __('General', 'comiceasel'), + 'navigation' => __('Navigation', 'comiceasel') + ); + if (empty($tab)) { $tab = array_shift(array_keys($tab_info)); } + + foreach($tab_info as $tab_id => $label) { ?> +
+ +
+ +
+ +
+
+
+ + + diff --git a/ceo-image-manager.php b/ceo-image-manager.php deleted file mode 100644 index d06d0ea..0000000 --- a/ceo-image-manager.php +++ /dev/null @@ -1,26 +0,0 @@ -
-

-
-
- - -
- - - diff --git a/comiceasel.php b/comiceasel.php index 1d42f92..d2236e0 100644 --- a/comiceasel.php +++ b/comiceasel.php @@ -2,12 +2,12 @@ /* Plugin Name: Comic Easel Plugin URI: http://comiceasel.com -Description: Manage a Comic with the Easel theme. -Version: 1.0 -Author: Philip M. Hofer (Frumph), Tyler Martin and Contributions from the ComicPress dev team. +Description: Comic Easel allows you to incorporate a WebComic using the WordPress Media Library functionality with Navigation into almost any WordPress theme. With just a few modifications of adding *injection* action locations into a theme, you can have the theme of your choice display a comic. +Version: 1.0.1 +Author: Philip M. Hofer (Frumph) Author URI: http://frumph.net/ -Copyright 2010 Philip M. Hofer (Frumph) (email : philip@frumph.net) +Copyright 2012 Philip M. Hofer (Frumph) (email : philip@frumph.net) 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 @@ -30,7 +30,7 @@ add_action('init', 'ceo_initialize_post_types'); function ceo_initialize_post_types() { $labels = array( - 'name' => __('Comic Easel', 'comiceasel'), + 'name' => __('Comics', 'comiceasel'), 'singular_name' => __('Comic', 'comiceasel'), 'add_new' => __('Add Comic', 'comiceasel'), 'add_new_item' => __('Add Comic', 'comiceasel'), @@ -58,9 +58,13 @@ function ceo_initialize_post_types() { 'rewrite' => array( 'slug' => 'comic', 'with_front' => true ), 'hierarchical' => false, 'can_export' => true, - 'menu_position' => 57, + 'show_in_menu' => true, + 'menu_position' => 5, + 'exclude_from_search' => false, + 'has_archive' => true, + 'query_var' => true, 'menu_icon' => ceo_pluginfo('plugin_url') . '/images/ceo-icon.png', - 'supports' => array( 'title', 'editor', 'excerpt', 'author', 'comments', 'thumbnail', 'custom-fields' ), + 'supports' => array( 'title', 'editor', 'excerpt', 'author', 'comments', 'thumbnail', 'custom-fields', 'revisions', 'trackbacks' ), 'description' => 'Post type for Comics' )); @@ -136,6 +140,7 @@ function ceo_initialize_post_types() { 'rewrite' => array( 'slug' => 'location' ), )); + register_taxonomy_for_object_type('post_tag', 'comic'); register_taxonomy_for_object_type('chapters', 'comic'); register_taxonomy_for_object_type('characters', 'comic'); register_taxonomy_for_object_type('locations', 'comic'); @@ -143,30 +148,18 @@ function ceo_initialize_post_types() { // THIS STUFF ONLY RUNS IN THE WP-ADMIN if (is_admin()) { - - // check if this is a easel theme, if not, dont execute. - // This will be removed since actions can be added to any theme. - if (strpos(get_template_directory(), 'easel') == false) { - if( substr( $_SERVER[ 'PHP_SELF' ], -19 ) != '/wp-admin/index.php' ) return; - - function ceo_no_ceo_theme() { - $output = '
'; - $output .= '

'.__('Comic Easel Error','comiceasel').'

'; - $output .= __('The current theme is not an Easel theme; Comic Easel will not load.','comiceasel').'
'; - $output .='
'; - $output .='
'; - echo $output; - } - - add_action( 'admin_notices', 'ceo_no_ceo_theme' ); - return; - } // only load the plugin code of we're in the administration part of WordPress. @require('ceo-admin.php'); @require('functions/admin-meta.php'); -} else { - // This style needs to be loaded on all the comic-easel pages inside ceo-core.php instead. - wp_enqueue_style('comiceasel-default-style', ceo_pluginfo('plugin_url').'/css/comiceasel.css'); +} + +add_action('wp_print_styles', 'ceo_run_css'); + +// This style needs to be loaded on all the comic-easel pages inside ceo-core.php instead. + +function ceo_run_css() { + wp_register_style('comiceasel-style', ceo_pluginfo('plugin_url').'/css/comiceasel.css'); + wp_enqueue_style('comiceasel-style'); } // Flush Rewrite Rules & create chapters @@ -178,40 +171,11 @@ function ceo_flush_rewrite() { $wp_rewrite->flush_rules(); } -// Checks chapters, creates them if needs be, checks directories, creates them if need be. -// This does not work yet, its purpose is to generate default chapters if no chapters exist. -function ceo_checkdefaults() { - $checkchapters = get_terms('chapters', 'orderby=count&hide_empty=0'); - if (empty($checkchapters)) { - $bookname = stripslashes(__('Book 1', 'comiceasel')); - $bookslug = sanitize_title($bookname); - // Should I check for .. the slug of term or name of term? - if (!term_exists($bookslug, 'chapters')) { - $args = array( - 'description' => stripslashes(__('The first book.', 'comiceasel')), - 'slug' => $bookslug - ); - $returned_book_info = wp_insert_term($bookname, 'chapters', $args); - $parent_term_id = 0; - // should I get term_taxonomy_id ? - // old: if (isset($returned_book_info['term_id'])) $parent_term_id = $returned_book_info['term_id']; - $parent_term = term_exists( $bookslug, 'chapters' ); // array is returned if taxonomy is given - $parent_term_id = $parent_term['term_id']; // get numeric term id - - if ($parent_term_id) { - $chaptername = stripslashes(__('Chapter 1', 'comiceasel')); - $chapterslug = sanitize_title($chaptername); - $args = array( - 'description' => stripslashes(__('First chapter of Book 1', 'comiceasel')), - 'slug' => $chapterslug, - 'parent' => $parent_term_id - ); - $returned_chapter_info = wp_insert_term($chaptername, 'chapters', $args); - } - } - } -} +// This file contains functions that is used elsewhere in the plugin +@require('functions/library.php'); +// Filters that change the behavior of WordPress +@require('functions/filters.php'); // This file handles navigation of the comic @require('functions/navigation.php'); @@ -222,6 +186,12 @@ function ceo_checkdefaults() { // This file contains the functions that are injected into the theme @require('functions/injections.php'); +// This file contains all the shortcodes for archives and cast pages +@require('functions/shortcodes.php'); + +// Redirects /?latest /?random etc. +@require('functions/redirects.php'); + /** * This is function ceo_clean_filename * @@ -252,12 +222,15 @@ function ceo_load_options($reset = false) { if (empty($ceo_config)) { delete_option('comiceasel-config'); foreach (array( - 'comic_folder' => 'webcomic', - 'comic_folder_medium' => 'webcomic-medium', - 'comic_folder_small' => 'webcomic-small', - 'medium_comic_width' => '360', - 'small_comic_width' => '200', - 'add_dashboard_frumph_feed_widget' => true + 'add_dashboard_frumph_feed_widget' => true, + 'disable_comic_on_home_page' => false, + 'disable_comic_blog_on_home_page' => false, + 'click_comic_next' => true, + 'navigate_only_chapters' => true, + 'enable_chapter_nav' => false, + 'enable_comments_nav' => true, + 'enable_random_nav' => true, + 'enable_embed_nav' => false ) as $field => $value) { $ceo_config[$field] = $value; } @@ -269,11 +242,11 @@ function ceo_load_options($reset = false) { function ceo_pluginfo($whichinfo = null) { global $ceo_pluginfo; - ceo_load_options('reset'); +// ceo_load_options('reset'); if (empty($ceo_pluginfo) || $whichinfo == 'reset') { // Important to assign pluginfo as an array to begin with. $ceo_pluginfo = array(); - $ceo_options = ceo_load_options('reset'); // TEMP: Reset is temporary + $ceo_options = ceo_load_options(); $ceo_coreinfo = wp_upload_dir(); $ceo_addinfo = array( // if wp_upload_dir reports an error, capture it @@ -289,16 +262,7 @@ function ceo_pluginfo($whichinfo = null) { 'style_path' => get_stylesheet_directory(), // comic-easel plugin directory/url 'plugin_url' => plugin_dir_url(dirname (__FILE__)) . 'comic-easel', - 'plugin_path' => trailingslashit(ABSPATH) . ceo_get_plugin_path(), - // Comic folders - 'comic_url' => trailingslashit($ceo_coreinfo['baseurl']) . $ceo_options['comic_folder'], - 'comic_path' => trailingslashit($ceo_coreinfo['basedir']) . $ceo_options['comic_folder'], - // Medium Thumbnail Folder - 'thumbnail_medium_url' => trailingslashit($ceo_coreinfo['baseurl']) . $ceo_options['comic_folder_medium'], - 'thumbnail_medium_path' => trailingslashit($ceo_coreinfo['basedir']) . $ceo_options['comic_folder_medium'], - // Small Thumbnail Folder - 'thumbnail_small_url' =>trailingslashit($ceo_coreinfo['baseurl']) . $ceo_options['comic_folder_small'], - 'thumbnail_small_path' => trailingslashit($ceo_coreinfo['basedir']) . $ceo_options['comic_folder_small'] + 'plugin_path' => trailingslashit(ABSPATH) . ceo_get_plugin_path() ); // Combine em. $ceo_pluginfo = array_merge($ceo_pluginfo, $ceo_addinfo); @@ -326,7 +290,7 @@ function ceo_test_information($vartodump) { ?> // Load all the widgets foreach (glob(ceo_pluginfo('plugin_path') . '/widgets/*.php') as $widgefile) { - @include($widgefile); + require_once($widgefile); } ?> diff --git a/css/admin-editor.css b/css/admin-editor.css new file mode 100644 index 0000000..0ef7322 --- /dev/null +++ b/css/admin-editor.css @@ -0,0 +1,6 @@ +/* runs in the post editor */ + +.admin-comicbox img { + max-width: 100%; +} + diff --git a/css/ceo-admin.css b/css/ceo-admin.css deleted file mode 100644 index b0b92cb..0000000 --- a/css/ceo-admin.css +++ /dev/null @@ -1,82 +0,0 @@ -.qq-uploader { - position: relative; - width: 100%; -} - -.qq-upload-button { - display: block; /* or inline-block */ - width: 105px; - padding: 7px 0; - text-align: center; - background: #000; - border-bottom: 1px solid #ddd; - color: #fff; -} -.qq-upload-button-hover { - background: #cc0000; -} -.qq-upload-button-focus { - outline: 1px dotted black; -} - -.qq-upload-drop-area { - position: absolute; - top: 0; - left: 0; - width: 100%; - height: 100%; - min-height: 70px; - z-index: 2; - background: #FF9797; - text-align: center; -} -.qq-upload-drop-area span { - display: block; - position: absolute; - top: 50%; - width: 100%; - margin-top: -8px; - font-size: 16px; -} -.qq-upload-drop-area-active { - background: #FF7171; -} - -.qq-upload-list { - margin: 15px 35px; - padding: 0; - list-style: disc; -} -.qq-upload-list li { - margin: 0; - padding: 0; - line-height: 15px; - font-size: 12px; -} -.qq-upload-file, .qq-upload-spinner, .qq-upload-size, .qq-upload-cancel, .qq-upload-failed-text { - margin-right: 7px; -} - -.qq-upload-file { -} -.qq-upload-spinner { - display: inline-block; - background: url("/wp-content/plugins/comic-easel/images/loading.gif"); - width: 15px; - height: 15px; - vertical-align: text-bottom; -} -.qq-upload-size, .qq-upload-cancel { - font-size: 11px; -} - -.qq-upload-failed-text { - display: none; -} -.qq-upload-fail .qq-upload-failed-text { - display: inline; -} - -#wpcontent #ceo_comic_in_post select { - height: auto; -} \ No newline at end of file diff --git a/css/comiceasel.css b/css/comiceasel.css index 3a0f2f5..76b5157 100644 --- a/css/comiceasel.css +++ b/css/comiceasel.css @@ -3,20 +3,41 @@ Comic Easel - Style.css Defaults for the Comic Easel Elements. */ -#default-nav-wrapper { - width: 100%; +table#comic-nav-wrapper { + background: none; + border: 0; + text-align: center; + border-collapse: collapse; + margin: 0 auto; + background: #333 !important; + margin: 6px auto; + border: solid 1px #000; + -moz-border-radius: 5px; + -khtml-border-radius: 5px; + -webkit-border-radius: 5px; + border-radius: 5px; + padding: 3px; + display: inline-block; } - .default-nav { - margin: 0 auto; - width: 300px; - } - - .default-nav-base { + td.comic-nav { + border: 0 !important; display: inline-block; padding: 0 10px; } + .comic-nav a:link, .comic-nav a:visited { + color: #fff; + } + + .comic-nav a:hover { + color: #fffc00; + } + + .comic-nav-embed { + width: 99%; + } + .infotext { font-size: 10px; color: gray; @@ -40,15 +61,106 @@ Defaults for the Comic Easel Elements. color: #ffcf00; } -.ceo_thumbnail_widget .widget-content { +#comic { text-align: center; } -#comic { - text-align: center; +#comic img { + margin: 0 auto; + padding: 0; + max-width: 100%; } #blogheader { border-bottom: solid 1px #fff; margin: 10px auto; +} + +/* cast archive shorttag */ + +.cast-box { + width: 520px; + padding: 2px; + margin: 10px auto; + border: solid 1px #ccc; + -moz-border-radius: 3px; + -khtml-border-radius: 3px; + -webkit-border-radius: 3px; + border-radius: 3px; + -moz-box-shadow: 2px 2px 2px #000; + -webkit-box-shadow: 2px 2px 2px #000; + -khtml-box-shadow: 2px 2px 2px #000; + box-shadow: 2px 2px 2px #000; +} + +.cast-pic { + float: left; + width: 150px; + height: 150px; + border: solid 1px #bff; +} + +.cast-info { + width: 358px; + float: left; + padding: 5px; +} + +.cast-comic-link { + text-align: right; +} + +/* Archive Shortcode */ + +.comic-archive-chapter-wrap { + width: 530px; + margin-bottom: 30px; +} + +.comic-archive-series-description { + padding: 20px; +} + +.comic-archive-chapter-description { + padding: 10px; +} + +h2.comic-archive-series-title { + text-align: center; +} + +.comic-archive-title { + margin-left: 10px; +} + +.comic-archive-date { + width: 88px; + display: inline-block; +} + +.comic-archive-thumbnail { + width: 150px; + float: left; + margin-right: 3px; + display: block; +} + +.comic-archive-list-wrap { + padding: 0; + list-style-type: none; + float: right; + width: 376px; +} + +.comic-list-alt { + background: #f7f7f7; +} + +.level-select { + font-weight: 700; + background: #eee; +} + +#comic-foot { + text-align: center; } \ No newline at end of file diff --git a/css/config.css b/css/config.css new file mode 100644 index 0000000..856efbe --- /dev/null +++ b/css/config.css @@ -0,0 +1,233 @@ +/* Admin Styles Here */ + +#ceoadmin-headericon { + height: 100px; + width: 100px; + margin: 14px 6px 0 0; + float: left; +} + +#ceoadmin { + font-family: 'Verdana', sans-serif; + font-size: 11px; + padding: 5px 0 0 0; + line-height: 5px; + margin: 0 0 1px 0; + overflow: hidden +} + +#ceoadmin div { + border-top-left-radius: 3px; + -moz-border-radius-topleft: 3px; + -webkit-border-top-left-radius: 3px; + -khtml-border-top-left-radius: 3px; + border-top-right-radius: 3px; + -moz-border-radius-topright: 3px; + -webkit-border-top-right-radius: 3px; + -khtml-border-top-right-radius: 3px; +} + +#ceoadmin div.off { + color: #999; + height: 23px; + margin: 0 0 0 5px; + line-height: 23px; + padding: 0 7px; + float: left; + background: #e9e9e9; + border-top: 1px solid #dfdfdf; + border-left: solid 1px #dfdfdf; + border-right: solid 1px #dfdfdf; + position: relative; + cursor: pointer; + z-index: 20; +} +#ceoadmin div.on { + color: #333; + padding: 0 7px; + margin: 0 0 0 5px; + float: left; + background: #fff; + border-top: 1px solid #dfdfdf; + border-left: 1px solid #dfdfdf; + border-right: 1px solid #dfdfdf; + border-bottom: 0px; + cursor: pointer; + height: 24px; + line-height: 23px; + position: relative; + z-index: 100; +} + +div.hide { + display: none; + width: 0; + overflow: hidden; +} + +div.show { + clear: left; + display: run-in; + position: relative; + z-index: 50; +} +div.show img { + float: left; + margin: 0 10px 10px 0; +} +.clear { + clear: both; +} + +.ceoadmin-footer { + padding: 10px; + margin: 10px 0 0 0; + color: #777; + text-align: center; + background: #fff; + border: 1px solid #dfdfdf; + font-family: 'Arial', sans-serif; + border-radius: 6px; + -moz-border-radius: 6px; + -webkit-border-radius: 6px; + -khtml-border-radius: 6px; +} +.ceoadmin-donate { + float: right; +} +.ceoadmin-footer a { + text-decoration: none; +} + +.comiceasel-options { + padding: 10px 10px 1px 10px; + background: #fff; + border-width: 1px 1px 1px 1px; + border-style: solid; + border-color: #dfdfdf; + margin-top: -2px; + font: 11px verdana, arial, sans-serif; + line-height: 18px; + border-top-left-radius: 6px; + -moz-border-radius-topleft: 6px; + -webkit-border-top-left-radius: 6px; + -khtml-border-top-left-radius: 6px; + border-top-right-radius: 6px; + -moz-border-radius-topright: 6px; + -webkit-border-top-right-radius: 6px; + -khtml-border-top-right-radius: 6px; +} + +.comiceasel-options-save { + margin-bottom: 15px; + border-width: 0 1px 1px 1px; + border-style: solid; + border-color: #dfdfdf; + border-bottom-left-radius: 6px; + -moz-border-radius-bottomleft: 6px; + -webkit-border-bottom-left-radius: 6px; + -khtml-border-bottom-left-radius: 6px; + border-bottom-right-radius: 6px; + -moz-border-radius-bottomright: 6px; + -webkit-border-bottom-right-radius: 6px; + -khtml-border-bottom-right-radius: 6px; +} + +.comiceasel-options table.widefat thead tr th { + font-size: 14px; +} + +.comiceasel-options table.widefat label { + display: block; + text-align: right; +} + +.comiceasel-options table.widefat label.inline-label { + display: inline; +} + +.comiceasel-options table.widefat select { + width: 100%; +} + +.comiceasel-options table.widefat { +/* margin-bottom: 10px; */ + border-bottom: none; +} + +#comiceasel-general .comiceasel-options table.widefat, #comiceasel-addons .comiceasel-options table.widefat { + margin-bottom: 10px; +} + +.comiceasel-options table.widefat th { + width: 200px; +} + +.comiceasel-options table.widefat th input{ +margin: 1px; +padding: 3px; +width: 100%; +} + +.comiceasel-options table.widefat th .radio input{ +margin: 0; +padding: 0; +width: auto; +} + +.comiceasel-options table.widefat th label { + color: #21759b; + text-align: left; +} + +.comiceasel-options table.widefat th label:hover { + color: #d54e21; +} + +.comiceasel-options table.widefat th, .comiceasel-options table.widefat td { + vertical-align: middle; +} +#comiceasel-version-title { + font-family: 'Georgia', serif; + font-size: 48px; + letter-spacing: -2px; + margin: 0; + padding: 30px 0 5px 0; + font-variant: small-caps; +} + + #easel-version-title a { + color: #333; + } + +#comiceasel-version-number { + font-family: monospace; + font-size: 16px; + letter-spacing: 8px; +} + +.comiceasel-options .radio { + padding-top: 5px; + text-align: right; +} + +div.show .ceoadmin-footer img{ + float: none; +} + +.comiceasel-major-publishing-actions { + padding: 6px; + clear: both; + border-top: none; + background: #eaf2fa; +} + +.comiceasel-major-publishing-actions input { + float: right; + min-width: 80px; + text-align: center; +} + +.alternate { + background: #eff; +} \ No newline at end of file diff --git a/css/default.css b/css/default.css deleted file mode 100644 index 2173d9e..0000000 --- a/css/default.css +++ /dev/null @@ -1,10 +0,0 @@ -body { - font: 12px/16px Arial, Helvetica, sans-serif; -} -#fileQueue { - width: 400px; - height: 300px; - overflow: auto; - border: 1px solid #E5E5E5; - margin-bottom: 10px; -} \ No newline at end of file diff --git a/css/uploadify.css b/css/uploadify.css deleted file mode 100644 index 754de06..0000000 --- a/css/uploadify.css +++ /dev/null @@ -1,53 +0,0 @@ -/* -Uploadify v2.1.0 -Release Date: August 24, 2009 - -Copyright (c) 2009 Ronnie Garcia, Travis Nickels - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. -*/ -.uploadifyQueueItem { - font: 11px Verdana, Geneva, sans-serif; - border: 2px solid #E5E5E5; - background-color: #F5F5F5; - margin-top: 5px; - padding: 10px; - width: 350px; -} -.uploadifyError { - border: 2px solid #FBCBBC !important; - background-color: #FDE5DD !important; -} -.uploadifyQueueItem .cancel { - float: right; -} -.uploadifyProgress { - background-color: #FFFFFF; - border-top: 1px solid #808080; - border-left: 1px solid #808080; - border-right: 1px solid #C5C5C5; - border-bottom: 1px solid #C5C5C5; - margin-top: 10px; - width: 100%; -} -.uploadifyProgressBar { - background-color: #0099FF; - width: 1px; - height: 3px; -} \ No newline at end of file diff --git a/functions/admin-meta.php b/functions/admin-meta.php index 11c6750..d416e6c 100644 --- a/functions/admin-meta.php +++ b/functions/admin-meta.php @@ -5,15 +5,14 @@ add_filter('manage_edit-comic_columns', 'ceo_add_new_comic_columns'); function ceo_add_new_comic_columns($comic_columns) { $new_columns['cb'] = ''; - $new_columns['title'] = _x('Comic Title Name', 'column name'); - - $new_columns['chapter'] = __('Chapter','easel'); - $new_columns['characters'] = __('Characters','easel'); - $new_columns['locations'] = __('Location','easel'); - $new_columns['tags'] = __('Tags', 'easel'); + $new_columns['title'] = __('Comic Title', 'comiceasel'); + $new_columns['chapter'] = __('Chapter','comiceasel'); + $new_columns['characters'] = __('Characters','comiceasel'); + $new_columns['locations'] = __('Location','comiceasel'); + $new_columns['tags'] = __('Tags', 'comiceasel'); $new_columns['date'] = _x('Date', 'column name'); - $new_columns['comicimages'] = _x('Comic', 'column name'); + $new_columns['comicimages'] = __('Thumbnail', 'comiceasel'); return $new_columns; } @@ -52,7 +51,7 @@ function ceo_manage_comic_columns($column_name, $id) { break; case 'comicimages': $post = &get_post($id); - $comicthumb = ceo_display_comic_thumbnail('small', $post, false, 100); + $comicthumb = ceo_display_comic_thumbnail('thumbnail', $post); if (!$comicthumb) { echo 'No Comic Found.'; } else { echo $comicthumb; } @@ -62,28 +61,20 @@ function ceo_manage_comic_columns($column_name, $id) { } // end switch } -function ceo_edit_comic_in_post($post) { -?> -
-
-
-
-
-
+function ceo_edit_comic_in_post($post) { ?> +
+
+
+
-
- - - -
- Alt Text (Hover) - This is text that is displayed when the mouse is over the comic.
-
-
+ The text placed here will appear when you mouse over the comic.
+ post_type ); + + /* Check if the current user has permission to edit the post. */ + if ( !current_user_can( $post_type->cap->edit_post, $post_id ) ) + return $post_id; + + /* Get the posted data and sanitize it for use as an HTML class. */ + $new_meta_value = ( isset( $_POST['comic-hovertext'] ) ? esc_textarea( $_POST['comic-hovertext'] ) : '' ); + + /* Get the meta key. */ + $meta_key = 'hovertext'; + + /* Get the meta value of the custom field key. */ + $meta_value = get_post_meta( $post_id, $meta_key, true ); + + /* If a new meta value was added and there was no previous value, add it. */ + if ( $new_meta_value && '' == $meta_value ) + add_post_meta( $post_id, $meta_key, $new_meta_value, true ); + + /* If the new meta value does not match the old value, update it. */ + elseif ( $new_meta_value && $new_meta_value != $meta_value ) + update_post_meta( $post_id, $meta_key, $new_meta_value ); + + /* If there is no new meta value but an old value exists, delete it. */ + elseif ( '' == $new_meta_value && $meta_value ) + delete_post_meta( $post_id, $meta_key, $meta_value ); } diff --git a/functions/displaycomic.php b/functions/displaycomic.php index 348a4d6..58a3279 100644 --- a/functions/displaycomic.php +++ b/functions/displaycomic.php @@ -1,79 +1,25 @@ ID); + if ($post_image_id) { + $thumbnail = wp_get_attachment_image_src( $post_image_id, $size, false); + $thumbnail = reset($thumbnail); + $hovertext = ceo_the_hovertext(); + $next_comic = ceo_get_next_comic_permalink(); + if (ceo_pluginfo('click_comic_next') && !empty($next_comic)) { + $output = ''; + } + $output .= ''.$hovertext.''; + if (ceo_pluginfo('click_comic_next') && !empty($next_comic)) { + $output .= ''; + } + return apply_filters('ceo_comics_display_comic', $output); + } else + return "No Comic (featured image) Found. Set One."; } -// If you want to run multiple comics on a single day, define your additional filters here. -// Example: you want to run an additional comic with the filename 2008-01-01-a-my-new-years-comic.jpg. -// Define an additional filter in the list below: -// -// $comic_filename_filters['secondary'] = "{date}-a*.*"; -// -// Then show the second comic on your page by calling the_comic with your filter name (PHP tags munged -// to maintain valid file syntax): -// -// -// Note that it's quite possible to slurp up the wrong file if your expressions are too broad. - -$comic_filename_filters = array(); -$comic_filename_filters['default'] = "{date}*.*"; - -// TODO: Change this to $output at some point. -function ceo_display_comic_navigation() { - global $post, $wp_query; - $first_comic = ceo_get_first_comic_permalink(); - $first_text = __('‹‹ First','comiceasel'); - $last_comic = ceo_get_last_comic_permalink(); - $last_text = __('Last ››','comiceasel'); - $next_comic = ceo_get_next_comic_permalink(); - $next_text = __('Next ›','comiceasel'); - $prev_comic = ceo_get_previous_comic_permalink(); - $prev_text = __('‹ Prev','comiceasel'); - ?> -
-
-
-
-
-
-
-
-
- ID, "fheight", true ); - $width = get_post_meta( $post->ID, "fwidth", true ); - if (empty($height)) $height = '300'; - if (empty($width)) $width = '100%'; - $output = "\r\n"; - $output .= " \r\n"; - $output .= "\r\n"; - $output .= "
\r\n"; - $output .= "

Get Flash!

\r\n"; - $output .= "

\"Get

\r\n"; - $output .= "
\r\n"; - $output .= "
\r\n"; - add_action('wp_footer', 'ceo_init_comic_swf'); - return apply_filters('ceo_display_comic_swf',$output); -} - -/** -* Display text when image (comic) is hovered -* Text is taken from a custom field named "hovertext" -*/ function ceo_the_hovertext($override_post = null) { global $post; $post_to_use = !is_null($override_post) ? $override_post : $post; @@ -81,274 +27,38 @@ function ceo_the_hovertext($override_post = null) { return (empty($hovertext)) ? get_the_title($post_to_use->ID) : $hovertext; } -function ceo_init_comic_swf() { - wp_enqueue_script('swfobject'); -} - -// This function will let authors who want to use comicpress as a way to output their books/text in a comic area as a page. -function ceo_display_comic_text($comic) { - if (file_exists(ceo_pluginfo('base_path') . $comic)) { - $output = nl2br(file_get_contents(ceo_pluginfo('base_path') . $comic)); +// We use this type of query so that $post is set, it's already set with is_single - but needs to be set on the home page +function ceo_display_comic_area() { + global $wp_query, $post; + if (is_single()) { + ceo_display_comic_wrapper(); + } else { + if (is_home() && !is_paged() && ceo_pluginfo('display_comic_on_home')) { + ceo_Protect(); + $comic_args = array( + 'posts_per_page' => 1, + 'post_type' => 'comic' + ); + $wp_query->in_the_loop = true; $comicFrontpage = new WP_Query(); $comicFrontpage->query($comic_args); + while ($comicFrontpage->have_posts()) : $comicFrontpage->the_post(); + ceo_display_comic_wrapper(); + endwhile; + ceo_UnProtect(); + } } - return apply_filters('ceo_display_comic_text', $output); } - // Do the thumbnail display functions here. -function ceo_display_comic_thumbnail($type = 'small', $override_post = null, $use_post_image = false, $setwidth = 0) { +function ceo_display_comic_thumbnail($thumbnail_size = 'thumbnail', $override_post = null) { global $post; $thumbnail = ''; $post_to_use = !empty($override_post) ? $override_post : $post; - // use_post_image if its set to true - if ($use_post_image) { - $post_image_id = get_post_thumbnail_id($post_to_use->ID); - if ($post_image_id) { - $thumbnail = wp_get_attachment_image_src( $post_image_id, 'post-thumbnail', false); - if ($thumbnail) (string)$thumbnail = $thumbnail[0]; - } - } - - if (empty($thumbnail)) { - if (count($thumb_found = get_comic_path($type, $post_to_use)) > 0) { - // adjust the thumbnail directories of all of them not just one, time to stop outputting them singularly and do array - $thumbnail = array(); - if (!empty($thumb_found)) { - foreach ($thumb_found as $thumb) { - $thumbnail[] = ceo_pluginfo('base_url') . ceo_clean_filename($thumb); - } - } - } - } - - if (empty($thumbnail)) { - // TODO: Need to determine the filename's extension at this point and mark it as such for those who don't have thumbnails. - return false; - } - - $output = ''; - if (is_array($thumbnail)) { - foreach ($thumbnail as $thumb) { - if ($setwidth) { - $output .= ''.get_the_title($post_to_use).''."\r\n"; - } else { - $output .= ''.get_the_title($post_to_use).''."\r\n"; - } - } + if ( has_post_thumbnail($post_to_use->ID) ) { + $output = ''.get_the_post_thumbnail($post_to_use->ID, $thumbnail_size).''."\r\n"; } else { - if ($setwidth) { - $output = ''.get_the_title($post_to_use).''."\r\n"; - } else { - $output = ''.get_the_title($post_to_use).''."\r\n"; - } +// $output = "No Thumbnail Found."; } -// if ($count > 1) $output = $count.' comics attached.
'.$output; - - return apply_filters('ceo_display_comic_thumbnail', $output); + return apply_filters('easel_display_comic_thumbnail', $output); } - -// TODO: Add the hovertext - rascal code and click to next INSIDE this. -function ceo_display_comic_image($post, $comic) { - $file_url = ceo_pluginfo('base_url') . ceo_clean_filename($comic); - if (ceo_pluginfo('rascal_says')) { - $alt_text = get_the_title($post); - } else { - $alt_text = ceo_the_hovertext($post); - } - $output = ''.$alt_text.''; - return apply_filters('ceo_display_comic_image',$output); -} - -// jquery code image swap by @brianarn -function ceo_display_comic() { - global $post; - $comics = get_comic_path('comic', $post); - if (is_array($comics)) { - $count = 1; - $outputlist = ''; $output = ''; - foreach ($comics as $comic) { - $comicsplit = explode(".", $comic); - switch (strtolower($comicsplit[1])) { - case 'swf': - $output .= '
'; - $output .= ceo_display_comic_swf($post, $comic); - $output .= "
\r\n"; - $outputlist .= "\r\n"; - $count += 1; - break; - case 'txt': - case 'inc': - case 'htm': - $output .= '
'; - $output .= ceo_display_comic_text($comic); - $output .= "
\r\n"; - $outputlist .= "\r\n"; - $count += 1; - break; - case 'png': - case 'gif': - case 'jpg': - case 'jpeg': - case 'tif': - case 'tiff': - case 'bmp': - default: - $output .= '
'; - $output .= ceo_display_comic_image($post, $comic); - $output .= "
\r\n"; - $outputlist .= "\r\n"; - $count += 1; - } - } - if ($count > 2 && ceo_pluginfo('enable_multicomic_jquery')) { - // Add the script stuff before the rest here. - $output = $outputscript . $output; - } - } - return $output; -} - -function ceo_comic_clicks_next($output) { - global $post, $wp_query; - if (is_search() || is_archive() || is_feed()) return $output; - $hovertext = ceo_the_hovertext($post); - $next_comic = ceo_get_next_comic_permalink(); - if (empty($next_comic)) $next_comic = '#'; - $class = ''; - if (ceo_pluginfo('rascal_says')) { - $the_title = get_the_title($post); - $class='class="tt"'; - } else { - $the_title = ceo_the_hovertext($post); - } - $output = "{$output}\r\n"; - return $output; -} - -function ceo_rascal_says($output) { - global $post, $wp_query; - if (is_search() || is_archive() || is_feed()) return $output; - $hovertext = get_post_meta( $post->ID, "hovertext", true ); - $href_to_use = "#"; - if (!empty($hovertext)) { - $output = preg_replace('#title="([^*]*)"#', '', $output); - $output = " {$hovertext} {$output}\r\n"; - } - if (ceo_pluginfo('comic_clicks_next')) { - $href_to_use = ceo_get_next_comic_permalink(); - if (empty($href_to_use)) $href_to_use = "#"; - $output = "post_title."\">{$output}"; - } else { - $output = "post_title."\">{$output}"; - } - return apply_filters('ceo_rascal_says',$output); -} - -if (ceo_pluginfo('rascal_says')) { - add_filter('ceo_display_comic_image', 'ceo_rascal_says'); -} - -if (ceo_pluginfo('comic_clicks_next') && !ceo_pluginfo('rascal_says')) { - add_filter('ceo_display_comic_image', 'ceo_comic_clicks_next'); -} - -/** -* Find a comic file in the filesystem. -* @param string $folder The folder name to search. -* @param string $override_post A WP Post object to use in place of global $post. -* @param string $filter The $comic_filename_filters to use. -* @return string The relative path to the comic file, or false if not found. -*/ - -function get_comic_path($folder = 'comic', $override_post = null, $filter = 'default') { - global $post, $comic_filename_filters, $comic_pathfinding_errors; - - $post_to_use = !empty($override_post) ? $override_post : $post; - - $meta_name = 'comic'; - - if (function_exists('xlanguage_current_language_code')) - $meta_name .= '-'.xlanguage_current_language_code(); - - $comicfile = get_post_meta( $post_to_use->ID, $meta_name, false ); - -// Backswards compatibility here - - switch ($folder) { - case "medium": $subfolder_to_use = ceo_pluginfo('comic_folder_medium'); break; - case "small": $subfolder_to_use = ceo_pluginfo('comic_folder_small'); break; - case "comic": default: $subfolder_to_use = ceo_pluginfo('comic_folder'); break; - } - - $folder_to_use = ceo_pluginfo('base_path') . $subfolder_to_use; - -/* if (!is_dir($folder_to_use . '/' . $comicfile) && $folder !== 'comic') - $folder_to_use = ceo_pluginfo('base_path') . '/' . ceo_pluginfo('comic_folder'); */ - - if (!empty($comicfile)) { - // return this as an array if we want to include in the future multiple comics found type thing, keeping it compatible. - $newresults = array(); - foreach ($comicfile as $comic) { - if (!file_exists($folder_to_use . '/' . $comic) && $folder !== 'comic') - $subfolder_to_use = ceo_pluginfo('comic_folder'); - $newresults[] = $subfolder_to_use .'/' .$comic; - } - return $newresults; - - } else { - // backwards compatibility - if (isset($comic_filename_filters[$filter])) { - $filter_to_use = $comic_filename_filters[$filter]; - } else { - $filter_to_use = '{date}*.*'; - } - $post_date = mysql2date(CP_DATE_FORMAT, $post_to_use->post_date); - $filter_with_date = str_replace('{date}', $post_date, $filter_to_use); - - $results = array(); - if (count($results = glob("${folder_to_use}/${filter_with_date}")) > 0) { - $newresults = array(); - foreach ($results as $result) { - // Strip the base directory off. - $newresults[] = str_replace(ceo_pluginfo('base_path'), '', $result); - } - return $newresults; - - } - // fallback to the comics directory ^ if nothing returned above. - $folder_to_use = ceo_pluginfo('base_path') . ceo_pluginfo('comic_folder'); - if (count($results = glob("${folder_to_use}/${filter_with_date}")) > 0) { - $newresults = array(); - foreach ($results as $result) { - // Strip the base directory off. - $newresults[] = str_replace(ceo_pluginfo('base_path'), '', $result); - } - return $newresults; - } - } - - $comic_pathfinding_errors[] = sprintf(__("Unable to find the file in the %s folder that matched the pattern %s. Check your WordPress and ComicPress settings.", 'comicpress'), $folder_to_use, $filter_with_date); - return false; -} - - -/** -* Find a comic file in the filesystem and return an absolute URL to that file. -* @param string $folder The folder name to search. -* @param string $override_post A WP Post object to use in place of global $post. -* @param string $filter The $comic_filename_filters to use. -* @return string The absolute URL to the comic file, or false if not found. -*/ -function get_comic_url($folder = 'comic', $override_post = null, $filter = 'default') { - if (($results = get_comic_path($folder, $override_post, $filter)) !== false) { - $newresults = array(); - foreach ($results as $result) { - $newresults[] = ceo_pluginfo('base_url') . $result; - } - return $newresults; - } - return false; -} - - ?> \ No newline at end of file diff --git a/functions/easyphpthumbnail.class.php b/functions/easyphpthumbnail.class.php deleted file mode 100644 index 18a4186..0000000 --- a/functions/easyphpthumbnail.class.php +++ /dev/null @@ -1,2029 +0,0 @@ - -Visit http://www.mywebmymail.com for more information - -Permission to use, copy, modify, and/or distribute this software for any -purpose without fee is hereby granted, provided that the above -copyright notice and this permission notice appear in all copies. - -THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES -WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF -MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR -ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF -OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - -*/ - -class easyphpthumbnail { - - /** - * The size of the thumbnail in px - * Autoscale landscape or portrait - * - * @var int - */ - public $Thumbsize; - /** - * The height of the thumbnail in px - * Forces all thumbnails to the same height - * - * @var int - */ - public $Thumbheight; - /** - * The width of the thumbnail in px - * Forces all thumbnails to the same width - * - * @var int - */ - public $Thumbwidth; - /** - * Set dimensions to percentage instead of px - * - * @var boolean - */ - public $Percentage; - /** - * Allow image enlargement - * - * @var boolean - */ - public $Inflate; - /** - * Quality of JPEG images 0 - 100 - * - * @var int - */ - public $Quality; - /** - * The frame width in px around the image - * - * @var int - */ - public $Framewidth; - /** - * Frame color in web format: '#00FF00' - * - * @var string - */ - public $Framecolor; - /** - * Background color in web format: '#00FF00' - * - * @var string - */ - public $Backgroundcolor; - /** - * Add shadow - * - * @var boolean - */ - public $Shadow; - /** - * Show binder rings - * - * @var boolean - */ - public $Binder; - /** - * Binder ring spacing in px - * - * @var int - */ - public $Binderspacing; - /** - * Path to PNG watermark image - * - * @var string - */ - public $Watermarkpng; - /** - * Position of watermark image, bottom right corner: '100% 100%' - * - * @var string - */ - public $Watermarkposition; - /** - * Transparency level of watermark image 0 - 100 - * - * @var int - */ - public $Watermarktransparency; - /** - * CHMOD level of saved thumbnails: '0755' - * - * @var string - */ - public $Chmodlevel; - /** - * Path to location for thumbnails - * - * @var string - */ - public $Thumblocation; - /** - * Filetype conversion for saving thumbnail - * - * @var string - */ - public $Thumbsaveas; - /** - * Prefix for saving thumbnails - * - * @var string - */ - public $Thumbprefix; - /** - * Clip corners; array with 7 values - * [0]: 0=disable 1=straight 2=rounded - * [1]: Percentage of clipping - * [2]: Clip randomly 0=disable 1=enable - * [3]: Clip top left 0=disable 1=enable - * [4]: Clip bottom left 0=disable 1=enable - * [5]: Clip top right 0=disable 1=enable - * [6]: Clip bottom right 0=disable 1=enable - * - * @var array - */ - public $Clipcorner; - /** - * Age image; array with 3 values - * [0]: Boolean 0=disable 1=enable - * [1]: Add noise 0-100, 0=disable - * [2]: Sephia depth 0-100, 0=disable (greyscale) - * - * @var array - */ - public $Ageimage; - /** - * Crop image; array with 6 values - * [0]: 0=disable 1=enable free crop 2=enable center crop 3=enable square crop - * [1]: 0=percentage 1=pixels - * [2]: Crop left - * [3]: Crop right - * [4]: Crop top - * [5]: Crop bottom - * - * @var array - */ - public $Cropimage; - /** - * Path to PNG border image - * - * @var string - */ - public $Borderpng; - /** - * Copyright text - * - * @var string - */ - public $Copyrighttext; - /** - * Position for Copyrighttext text, bottom right corner: '100% 100%' - * - * @var string - */ - public $Copyrightposition; - /** - * Path to TTF Fonttype - * If no TTF font is specified, system font will be used - * - * @var string - */ - public $Copyrightfonttype; - /** - * Fontsize for Copyrighttext text - * - * @var string - */ - public $Copyrightfontsize; - /** - * Copyrighttext text color in web format: '#000000' - * No color specified will auto-determine black or white - * - * @var string - */ - public $Copyrighttextcolor; - /** - * Rotate image in degrees - * - * @var int - */ - public $Rotate; - /** - * Flip the image horizontally - * - * @var boolean - */ - public $Fliphorizontal; - /** - * Flip the image vertically - * - * @var boolean - */ - public $Flipvertical; - /** - * Create square canvas thumbs - * - * @var boolean - */ - public $Square; - /** - * Apply a filter to the image - * - * @var boolean - */ - public $Applyfilter; - /** - * Apply a 3x3 filter matrix to the image; array with 9 values - * [0]: a1,1 - * [1]: a1,2 - * [2]: a1,3 - * [3]: a2,1 - * [4]: a2,2 - * [5]: a2,3 - * [6]: a3,1 - * [7]: a3,2 - * [8]: a3,3 - * - * @var array - */ - public $Filter; - /** - * Divisor for filter - * - * @var int - */ - public $Divisor; - /** - * Offset for filter - * - * @var int - */ - public $Offset; - /** - * Blur filter - * - * @var boolean - */ - public $Blur; - /** - * Sharpen filter - * - * @var boolean - */ - public $Sharpen; - /** - * Edge filter - * - * @var boolean - */ - public $Edge; - /** - * Emboss filter - * - * @var boolean - */ - public $Emboss; - /** - * Mean filter - * - * @var boolean - */ - public $Mean; - /** - * Rotate and crop the image - * - * @var boolean - */ - public $Croprotate; - /** - * Apply perspective to the image; array with 3 values - * [0]: 0=disable 1=enable - * [1]: Direction 0=left 1=right 2=top 3=bottom - * [2]: Perspective strength 0 - 100 - * - * @var array - */ - public $Perspective; - /** - * Apply perspective to the thumbnail; array with 3 values - * [0]: 0=disable 1=enable - * [1]: Direction 0=left 1=right 2=top 3=bottom - * [2]: Perspective strength 0 - 100 - * - * @var array - */ - public $Perspectivethumb; - /** - * Apply shading gradient to the image; array with 4 values - * [0]: 0=disable 1=enable - * [1]: Shading strength 0 - 100 - * [2]: Shading area 0 - 100 - * [3]: Shading direction 0=right 1=left 2=top 3=bottom - * - * @var array - */ - public $Shading; - /** - * Shading gradient color in web format: '#00FF00' - * - * @var string - */ - public $Shadingcolor; - /** - * Apply a mirror effect to the thumbnail; array with 4 values - * [0]: 0=disable 1=enable - * [1]: Mirror transparency gradient starting strength 0 - 100 - * [2]: Mirror transparency gradient ending strength 0 - 100 - * [3]: Mirror area 0 - 100 - * [4]: Mirror 'gap' between original image and reflection in px - * - * @var array - */ - public $Mirror; - /** - * Mirror gradient color in web format: '#00FF00' - * - * @var string - */ - public $Mirrorcolor; - /** - * Create image negative - * - * @var boolean - */ - public $Negative; - /** - * Replace a color in the image; array with 4 values - * [0]: 0=disable 1=enable - * [1]: Color to replace in web format: '#00FF00' - * [2]: Replacement color in web format: '#FF0000' - * [3]: RGB tolerance 0 - 100 - * - * @var array - */ - public $Colorreplace; - /** - * Scramble pixels; array with 3 values - * [0]: 0=disable 1=enable - * [1]: Pixel range - * [2]: Repeats (use with care!) - * - * @var array - */ - public $Pixelscramble; - /** - * Convert image to greyscale - * - * @var boolean - */ - public $Greyscale; - /** - * Change brightness of the image; array with 2 values - * [0]: 0=disable 1=enable - * [1]: Brightness -100 to 100 - * - * @var array - */ - public $Brightness; - /** - * Change contrast of the image; array with 2 values - * [0]: 0=disable 1=enable - * [1]: Contrast -100 to 100 - * - * @var array - */ - public $Contrast; - /** - * Change gamma of the image; array with 2 values - * [0]: 0=disable 1=enable - * [1]: Gamma correction factor - * - * @var array - */ - public $Gamma; - /** - * Reduce palette of the image; array with 2 values - * [0]: 0=disable 1=enable - * [1]: Amount of colors for palette - * - * @var array - */ - public $Palette; - /** - * Merge a color in the image; array with 5 values - * [0]: 0=disable 1=enable - * [1]: Red component 0 - 255 - * [2]: Green component 0 - 255 - * [3]: Blue component 0 - 255 - * [4]: Opacity level 0 - 127 - * - * @var array - */ - public $Colorize; - /** - * Pixelate the image; array with 2 values - * [0]: 0=disable 1=enable - * [1]: Block size in px - * - * @var array - */ - public $Pixelate; - /** - * Apply a median filter to remove noise - * - * @var boolean - */ - public $Medianfilter; - /** - * Deform the image with twirl effect; array with 3 values - * [0]: 0=disable 1=enable - * [1]: Effect strength 0 to 100 - * [2]: Direction of twirl 0=clockwise 1=anti-clockwise - * - * @var array - */ - public $Twirlfx; - /** - * Deform the image with ripple effect; array with 2 values - * [0]: 0=disable 1=enable - * [1]: Amount of horizontal waves - * [2]: Amplitude of horizontal waves in px - * [3]: Amount of vertical waves - * [4]: Amplitude of vertical waves in px - * - * @var array - */ - public $Ripplefx; - /** - * Deform the image with perspective ripple or 'lake' effect; array with 3 values - * [0]: 0=disable 1=enable - * [1]: Density of the waves - * [2]: Lake area measured from bottom 0 - 100 - * - * @var array - */ - public $Lakefx; - /** - * Deform the image with a circular waterdrop effect; array with 4 values - * [0]: 0=disable 1=enable - * [1]: Amplitude in px - * [2]: Radius in px - * [3]: Wavelength in px - * - * @var array - */ - public $Waterdropfx; - /** - * Create transparent image; array with 4 values - * [0]: 0=disable 1=enable - * [1]: 0=PNG 1=GIF - * [2]: Replacement color in web format: '#FF0000' - * [3]: RGB tolerance 0 - 100 - * - * @var array - */ - public $Maketransparent; - /** - * Filename for saving thumbnails - * - * @var string - */ - public $Thumbfilename; - /** - * The image filename or array with filenames - * - * @var string / array - */ - private $image; - /** - * Original image - * - * @var image - */ - private $im; - /** - * Thumbnail image - * - * @var image - */ - private $thumb; - /** - * Temporary image - * - * @var image - */ - private $newimage; - /** - * Dimensions of original image; array with 3 values - * [0]: Width - * [1]: Height - * [2]: Filetype - * - * @var array - */ - private $size; - /** - * Offset in px for binder - * - * @var int - */ - private $bind_offset; - /** - * Offset in px for shadow - * - * @var int - */ - private $shadow_offset; - /** - * Offset in px for frame - * - * @var int - */ - private $frame_offset; - /** - * Thumb width in px - * - * @var int - */ - private $thumbx; - /** - * Thumb height in px - * - * @var int - */ - private $thumby; - - /** - * Class constructor - * - */ - public function __construct() { - - $this->Thumbsize = 160; - $this->Thumbheight = 0; - $this->Thumbwidth = 0; - $this->Percentage = false; - $this->Framewidth = 0; - $this->Inflate = false; - $this->Shadow = false; - $this->Binder = false; - $this->Binderspacing = 8; - $this->Backgroundcolor = '#FFFFFF'; - $this->Framecolor = '#FFFFFF'; - $this->Watermarkpng = ''; - $this->Watermarkposition = '100% 100%'; - $this->Watermarktransparency = '70'; - $this->Quality = '90'; - $this->Chmodlevel = ''; - $this->Thumblocation = ''; - $this->Thumbsaveas = ''; - $this->Thumbprefix = 'thumbnail_'; - $this->Clipcorner = array(0,15,0,1,1,1,0); - $this->Ageimage = array(0,10,80); - $this->Cropimage = array(0,0,20,20,20,20); - $this->Borderpng = ''; - $this->Copyrighttext = ''; - $this->Copyrightposition = '0% 95%'; - $this->Copyrightfonttype = ''; - $this->Copyrightfontsize = 2; - $this->Copyrighttextcolor = ''; - $this->Rotate = 0; - $this->Fliphorizontal = false; - $this->Flipvertical = false; - $this->Square = false; - $this->Applyfilter = false; - $this->Filter = array(0,0,0,0,1,0,0,0,0); - $this->Divisor = 1; - $this->Offset = 0; - $this->Blur = false; - $this->Sharpen = false; - $this->Edge = false; - $this->Emboss = false; - $this->Mean = false; - $this->Croprotate = false; - $this->Perspective = array(0,0,30); - $this->Perspectivethumb = array(0,1,20); - $this->Shading = array(0,70,65,0); - $this->Shadingcolor = '#000000'; - $this->Mirror = array(0,20,100,40,2); - $this->Mirrorcolor = '#FFFFFF'; - $this->Negative = false; - $this->Colorreplace = array(0,'#000000','#FFFFFF',30); - $this->Pixelscramble = array(0,3,1); - $this->Greyscale = false; - $this->Brightness = array(0,30); - $this->Contrast = array(0,30); - $this->Gamma = array(0,1.5); - $this->Palette = array(0,6); - $this->Colorize = array(0,100,0,0,0); - $this->Pixelate = array(0,3); - $this->Medianfilter = false; - $this->Twirlfx = array(0,20,0); - $this->Ripplefx = array(0,5,15,5,5); - $this->Lakefx = array(0,15,80); - $this->Waterdropfx = array(0,1.2,400,40); - $this->Maketransparent = array(0,0,'#FFFFFF',30); - $this->Thumbfilename = ''; - - } - - /** - * Class destructor - * - */ - public function __destruct() { - if(is_resource($this->im)) imagedestroy($this->im); - if(is_resource($this->thumb)) imagedestroy($this->thumb); - if(is_resource($this->newimage)) imagedestroy($this->newimage); - } - - /** - * Creates and outputs thumbnail - * - * @param string/array $filename - * @param string $output - */ - public function Createthumb($filename="unknown",$output="screen") { - - if (is_array($filename) && $output=="file") { - foreach ($filename as $name) { - $this->image=$name; - $this->thumbmaker(); - $this->savethumb(); - } - } else { - $this->image=$filename; - $this->thumbmaker(); - if ($output=="file") {$this->savethumb();} else {$this->displaythumb();} - } - - } - - /** - * Apply all modifications to the image - * - */ - private function thumbmaker() { - - if($this->loadimage()) { - // Modifications to the original sized image - if ($this->Cropimage[0]>0) {$this->cropimage();} - if ($this->Medianfilter) {$this->medianfilter();} - if ($this->Greyscale) {$this->greyscale();} - if ($this->Brightness[0]==1) {$this->brightness();} - if ($this->Contrast[0]==1) {$this->contrast();} - if ($this->Gamma[0]==1) {$this->gamma();} - if ($this->Palette[0]==1) {$this->palette();} - if ($this->Colorize[0]==1) {$this->colorize();} - if ($this->Colorreplace[0]==1) {$this->colorreplace();} - if ($this->Pixelscramble[0]==1) {$this->pixelscramble();} - if ($this->Pixelate[0]==1) {$this->pixelate();} - if ($this->Ageimage[0]==1) {$this->ageimage();} - if ($this->Fliphorizontal) {$this->rotateorflip(0,1);} - if ($this->Flipvertical) {$this->rotateorflip(0,-1);} - if ($this->Watermarkpng!='') {$this->addpngwatermark();} - if ($this->Clipcorner[0]==1) {$this->clipcornersstraight();} - if ($this->Clipcorner[0]==2) {$this->clipcornersround();} - if (intval($this->Rotate)<>0 && !$this->Croprotate) { - switch(intval($this->Rotate)) { - case -90: - case 270: - $this->rotateorflip(1,0); - break; - case -270: - case 90: - $this->rotateorflip(1,0); - break; - case -180: - case 180: - $this->rotateorflip(1,0); - $this->rotateorflip(1,0); - break; - default: - $this->freerotate(); - } - } - if ($this->Croprotate) {$this->croprotate();} - if ($this->Sharpen) {$this->sharpen();} - if ($this->Blur) {$this->blur();} - if ($this->Edge) {$this->edge();} - if ($this->Emboss) {$this->emboss();} - if ($this->Mean) {$this->mean();} - if ($this->Applyfilter) {$this->filter();} - if ($this->Twirlfx[0]==1) {$this->twirlfx();} - if ($this->Ripplefx[0]==1) {$this->ripplefx();} - if ($this->Lakefx[0]==1) {$this->lakefx();} - if ($this->Waterdropfx[0]==1) {$this->waterdropfx();} - if ($this->Negative) {$this->negative();} - if ($this->Shading[0]==1) {$this->shading();} - if ($this->Perspective[0]==1) {$this->perspective();} - // Prepare the thumbnail (new canvas) and add modifications to the resized image (thumbnail) - $this->createemptythumbnail(); - if ($this->Binder) {$this->addbinder();} - if ($this->Shadow) {$this->addshadow();} - imagecopyresampled($this->thumb,$this->im,$this->Framewidth*($this->frame_offset-1),$this->Framewidth,0,0,$this->thumbx-($this->frame_offset*$this->Framewidth)-$this->shadow_offset,$this->thumby-2*$this->Framewidth-$this->shadow_offset,imagesx($this->im),imagesy($this->im)); - if ($this->Borderpng!='') {$this->addpngborder();} - if ($this->Copyrighttext!='') {$this->addcopyright();} - if ($this->Square) {$this->square();} - if ($this->Mirror[0]==1) {$this->mirror();} - if ($this->Perspectivethumb[0]==1) {$this->perspectivethumb();} - if ($this->Maketransparent[0]==1) {$this->maketransparent();} - } - - } - - /** - * Load image in memory - * - */ - private function loadimage() { - - if (file_exists($this->image)) { - $this->size=GetImageSize($this->image); - switch($this->size[2]) { - case 1: - if (imagetypes() & IMG_GIF) {$this->im=imagecreatefromgif($this->image);return true;} else {$this->invalidimage('No GIF support');return false;} - break; - case 2: - if (imagetypes() & IMG_JPG) {$this->im=imagecreatefromjpeg($this->image);return true;} else {$this->invalidimage('No JPG support');return false;} - break; - case 3: - if (imagetypes() & IMG_PNG) {$this->im=imagecreatefrompng($this->image);return true;} else {$this->invalidimage('No PNG support');return false;} - break; - default: - $this->invalidimage('Filetype ?????'); - return false; - } - } else { - $this->invalidimage('File not found'); - return false; - } - - } - - /** - * Creates error image - * - * @param string $message - */ - private function invalidimage($message) { - - $this->thumb=imagecreate(80,75); - $black=imagecolorallocate($this->thumb,0,0,0);$yellow=imagecolorallocate($this->thumb,255,255,0); - imagefilledrectangle($this->thumb,0,0,80,75,imagecolorallocate($this->thumb,255,0,0)); - imagerectangle($this->thumb,0,0,79,74,$black);imageline($this->thumb,0,20,80,20,$black); - imagefilledrectangle($this->thumb,1,1,78,19,$yellow);imagefilledrectangle($this->thumb,27,35,52,60,$yellow); - imagerectangle($this->thumb,26,34,53,61,$black); - imageline($this->thumb,27,35,52,60,$black);imageline($this->thumb,52,35,27,60,$black); - imagestring($this->thumb,1,5,5,$message,$black); - - } - - /** - * Add watermark to image - * - */ - private function addpngwatermark() { - - if (file_exists($this->Watermarkpng)) { - $this->newimage=imagecreatefrompng($this->Watermarkpng); - $wpos=explode(' ',str_replace('%','',$this->Watermarkposition)); - imagecopymerge($this->im,$this->newimage,min(max(imagesx($this->im)*($wpos[0]/100)-0.5*imagesx($this->newimage),0),imagesx($this->im)-imagesx($this->newimage)),min(max(imagesy($this->im)*($wpos[1]/100)-0.5*imagesy($this->newimage),0),imagesy($this->im)-imagesy($this->newimage)),0,0,imagesx($this->newimage),imagesy($this->newimage),intval($this->Watermarktransparency)); - imagedestroy($this->newimage); - } - - } - - /** - * Create empty thumbnail - * - */ - private function createemptythumbnail() { - - $thumbsize=$this->Thumbsize;$thumbwidth=$this->Thumbwidth;$thumbheight=$this->Thumbheight; - if ($thumbsize==0) {$thumbsize=9999;$thumbwidth=0;$thumbheight=0;} - if ($this->Percentage) { - if ($thumbwidth>0) {$thumbwidth=floor(($thumbwidth/100)*$this->size[0]);} - if ($thumbheight>0) {$thumbheight=floor(($thumbheight/100)*$this->size[1]);} - if ($this->size[0]>$this->size[1]) - $thumbsize=floor(($thumbsize/100)*$this->size[0]); - else - $thumbsize=floor(($thumbsize/100)*$this->size[1]); - } - if (!$this->Inflate) { - if ($thumbsize>$this->size[0] && $thumbsize>$this->size[1]) {$thumbsize=max($this->size[0],$this->size[1]);} - if ($thumbheight>$this->size[1]) {$thumbheight=$this->size[1];} - if ($thumbwidth>$this->size[0]) {$thumbwidth=$this->size[0];} - } - if ($this->Binder) {$this->frame_offset=3;$this->bind_offset=4;} else {$this->frame_offset=2;$this->bind_offset=0;} - if ($this->Shadow) {$this->shadow_offset=3;} else {$this->shadow_offset=0;} - if ($thumbheight>0 && $thumbwidth>0) { - $this->thumb=imagecreatetruecolor($this->Framewidth*$this->frame_offset+$thumbwidth+$this->shadow_offset,$this->Framewidth*2+$thumbheight+$this->shadow_offset); - } else if ($thumbheight>0) { - $this->thumb=imagecreatetruecolor($this->Framewidth*$this->frame_offset+ceil($this->size[0]/($this->size[1]/$thumbheight))+$this->shadow_offset,$this->Framewidth*2+$thumbheight+$this->shadow_offset); - } else if ($thumbwidth>0) { - $this->thumb=imagecreatetruecolor($this->Framewidth*$this->frame_offset+$thumbwidth+$this->shadow_offset,$this->Framewidth*2+ceil($this->size[1]/($this->size[0]/$thumbwidth))+$this->shadow_offset); - } else { - $x1=$this->Framewidth*$this->frame_offset+$thumbsize+$this->shadow_offset; - $x2=$this->Framewidth*$this->frame_offset+ceil($this->size[0]/($this->size[1]/$thumbsize))+$this->shadow_offset; - $y1=$this->Framewidth*2+ceil($this->size[1]/($this->size[0]/$thumbsize))+$this->shadow_offset; - $y2=$this->Framewidth*2+$thumbsize+$this->shadow_offset; - if ($this->size[0]>$this->size[1]) {$this->thumb=imagecreatetruecolor($x1,$y1);} else {$this->thumb=imagecreatetruecolor($x2,$y2);} - } - $this->thumbx=imagesx($this->thumb);$this->thumby=imagesy($this->thumb); - imagefilledrectangle($this->thumb,0,0,$this->thumbx,$this->thumby,imagecolorallocate($this->thumb,hexdec(substr($this->Backgroundcolor,1,2)),hexdec(substr($this->Backgroundcolor,3,2)),hexdec(substr($this->Backgroundcolor,5,2)))); - imagefilledrectangle($this->thumb,$this->bind_offset,0,$this->thumbx-$this->shadow_offset,$this->thumby-$this->shadow_offset,imagecolorallocate($this->thumb,hexdec(substr($this->Framecolor,1,2)),hexdec(substr($this->Framecolor,3,2)),hexdec(substr($this->Framecolor,5,2)))); - - } - - /** - * Drop shadow on thumbnail - * - */ - private function addshadow() { - - $gray=imagecolorallocate($this->thumb,192,192,192); - $middlegray=imagecolorallocate($this->thumb,158,158,158); - $darkgray=imagecolorallocate($this->thumb,128,128,128); - imagerectangle($this->thumb,$this->bind_offset,0,$this->thumbx-4,$this->thumby-4,$gray); - imageline($this->thumb,$this->bind_offset,$this->thumby-3,$this->thumbx,$this->thumby-3,$darkgray); - imageline($this->thumb,$this->thumbx-3,0,$this->thumbx-3,$this->thumby,$darkgray); - imageline($this->thumb,$this->bind_offset+2,$this->thumby-2,$this->thumbx,$this->thumby-2,$middlegray); - imageline($this->thumb,$this->thumbx-2,2,$this->thumbx-2,$this->thumby,$middlegray); - imageline($this->thumb,$this->bind_offset+2,$this->thumby-1,$this->thumbx,$this->thumby-1,$gray); - imageline($this->thumb,$this->thumbx-1,2,$this->thumbx-1,$this->thumby,$gray); - - } - - /** - * Clip corners original image - * - */ - private function clipcornersstraight() { - - $clipsize=$this->Clipcorner[1]; - if ($this->size[0]>$this->size[1]) - $clipsize=floor($this->size[0]*(intval($clipsize)/100)); - else - $clipsize=floor($this->size[1]*(intval($clipsize)/100)); - if (intval($clipsize)>0) { - $bgcolor=imagecolorallocate($this->im,hexdec(substr($this->Backgroundcolor,1,2)),hexdec(substr($this->Backgroundcolor,3,2)),hexdec(substr($this->Backgroundcolor,5,2))); - if ($this->Clipcorner[2]) {$random1=rand(0,1);$random2=rand(0,1);$random3=rand(0,1);$random4=rand(0,1);} else {$random1=1;$random2=1;$random3=1;$random4=1;} - for ($i=0;$i<$clipsize;$i++) { - if ($this->Clipcorner[3] && $random1) {imageline($this->im,0,$i,$clipsize-$i,$i,$bgcolor);} - if ($this->Clipcorner[4] && $random2) {imageline($this->im,0,$this->size[1]-$i-1,$clipsize-$i,$this->size[1]-$i-1,$bgcolor);} - if ($this->Clipcorner[5] && $random3) {imageline($this->im,$this->size[0]-$clipsize+$i,$i,$this->size[0]+$clipsize-$i,$i,$bgcolor);} - if ($this->Clipcorner[6] && $random4) {imageline($this->im,$this->size[0]-$clipsize+$i,$this->size[1]-$i-1,$this->size[0]+$clipsize-$i,$this->size[1]-$i-1,$bgcolor);} - } - } - - } - - /** - * Clip round corners original image - * - */ - private function clipcornersround() { - - $clipsize=floor($this->size[0]*($this->Clipcorner[1]/100)); - $clip_degrees=90/max($clipsize,1); - $points_tl=array(0,0); - $points_br=array($this->size[0],$this->size[1]); - $points_tr=array($this->size[0],0); - $points_bl=array(0,$this->size[1]); - $bgcolor=imagecolorallocate($this->im,hexdec(substr($this->Backgroundcolor,1,2)),hexdec(substr($this->Backgroundcolor,3,2)),hexdec(substr($this->Backgroundcolor,5,2))); - for ($i=0;$i<$clipsize;$i++) { - $x=$clipsize*cos(deg2rad($i*$clip_degrees)); - $y=$clipsize*sin(deg2rad($i*$clip_degrees)); - array_push($points_tl,$clipsize-$x); - array_push($points_tl,$clipsize-$y); - array_push($points_tr,$this->size[0]-$clipsize+$x); - array_push($points_tr,$clipsize-$y); - array_push($points_br,$this->size[0]-$clipsize+$x); - array_push($points_br,$this->size[1]-$clipsize+$y); - array_push($points_bl,$clipsize-$x); - array_push($points_bl,$this->size[1]-$clipsize+$y); - } - array_push($points_tl,$clipsize,0); - array_push($points_br,$this->size[0]-$clipsize,$this->size[1]); - array_push($points_tr,$this->size[0]-$clipsize,0); - array_push($points_bl,$clipsize,$this->size[1]); - if ($this->Clipcorner[2]) {$random1=rand(0,1);$random2=rand(0,1);$random3=rand(0,1);$random4=rand(0,1);} else {$random1=1;$random2=1;$random3=1;$random4=1;} - if ($this->Clipcorner[3] && $random1) {imagefilledpolygon($this->im,$points_tl,count($points_tl)/2,$bgcolor);} - if ($this->Clipcorner[4] && $random2) {imagefilledpolygon($this->im,$points_bl,count($points_bl)/2,$bgcolor);} - if ($this->Clipcorner[5] && $random3) {imagefilledpolygon($this->im,$points_tr,count($points_tr)/2,$bgcolor);} - if ($this->Clipcorner[6] && $random4) {imagefilledpolygon($this->im,$points_br,count($points_br)/2,$bgcolor);} - imagerectangle($this->im,0,0,$this->size[0]-1,$this->size[1]-1,$bgcolor); - - } - - /** - * Convert original image to greyscale and/or apply noise and sephia effect - * - */ - private function ageimage() { - - imagetruecolortopalette($this->im,1,256); - for ($c=0;$c<256;$c++) { - $col=imagecolorsforindex($this->im,$c); - $new_col=floor($col['red']*0.2125+$col['green']*0.7154+$col['blue']*0.0721); - $noise=rand(-$this->Ageimage[1],$this->Ageimage[1]); - if ($this->Ageimage[2]>0) { - $r=$new_col+$this->Ageimage[2]+$noise; - $g=floor($new_col+$this->Ageimage[2]/1.86+$noise); - $b=floor($new_col+$this->Ageimage[2]/-3.48+$noise); - } else { - $r=$new_col+$noise; - $g=$new_col+$noise; - $b=$new_col+$noise; - } - imagecolorset($this->im,$c,max(0,min(255,$r)),max(0,min(255,$g)),max(0,min(255,$b))); - } - - } - - /** - * Add border to thumbnail - * - */ - private function addpngborder() { - - if (file_exists($this->Borderpng)) { - $borderim=imagecreatefrompng($this->Borderpng); - imagecopyresampled($this->thumb,$borderim,$this->bind_offset,0,0,0,$this->thumbx-$this->shadow_offset-$this->bind_offset,$this->thumby-$this->shadow_offset,imagesx($borderim),imagesy($borderim)); - imagedestroy($borderim); - } - - } - - /** - * Add binder effect to thumbnail - * - */ - private function addbinder() { - - if (intval($this->Binderspacing)<4) {$this->Binderspacing=4;} - $spacing=floor($this->thumby/$this->Binderspacing)-2; - $offset=floor(($this->thumby-($spacing*$this->Binderspacing))/2); - $gray=imagecolorallocate($this->thumb,192,192,192); - $middlegray=imagecolorallocate($this->thumb,158,158,158); - $darkgray=imagecolorallocate($this->thumb,128,128,128); - $black=imagecolorallocate($this->thumb,0,0,0); - $white=imagecolorallocate($this->thumb,255,255,255); - for ($i=$offset;$i<=$offset+$spacing*$this->Binderspacing;$i+=$this->Binderspacing) { - imagefilledrectangle($this->thumb,8,$i-2,10,$i+2,$black); - imageline($this->thumb,11,$i-1,11,$i+1,$darkgray); - imageline($this->thumb,8,$i-2,10,$i-2,$darkgray); - imageline($this->thumb,8,$i+2,10,$i+2,$darkgray); - imagefilledrectangle($this->thumb,0,$i-1,8,$i+1,$gray); - imageline($this->thumb,0,$i,8,$i,$white); - imageline($this->thumb,0,$i-1,0,$i+1,$gray); - imagesetpixel($this->thumb,0,$i,$darkgray); - } - - } - - /** - * Add Copyright text to thumbnail - * - */ - private function addcopyright() { - - if ($this->Copyrightfonttype=='') { - $widthx=imagefontwidth($this->Copyrightfontsize)*strlen($this->Copyrighttext); - $heighty=imagefontheight($this->Copyrightfontsize); - $fontwidth=imagefontwidth($this->Copyrightfontsize); - } else { - $dimensions=imagettfbbox($this->Copyrightfontsize,0,$this->Copyrightfonttype,$this->Copyrighttext); - $widthx=$dimensions[2];$heighty=$dimensions[5]; - $dimensions=imagettfbbox($this->Copyrightfontsize,0,$this->Copyrightfonttype,'W'); - $fontwidth=$dimensions[2]; - } - $cpos=explode(' ',str_replace('%','',$this->Copyrightposition)); - if (count($cpos)>1) { - $cposx=floor(min(max($this->thumbx*($cpos[0]/100)-0.5*$widthx,$fontwidth),$this->thumbx-$widthx-0.5*$fontwidth)); - $cposy=floor(min(max($this->thumby*($cpos[1]/100)-0.5*$heighty,$heighty),$this->thumby-$heighty*1.5)); - } else { - $cposx=$fontwidth; - $cposy=$this->thumby-10; - } - if ($this->Copyrighttextcolor=='') { - $colors=array(); - for ($i=$cposx;$i<($cposx+$widthx);$i++) { - $indexis=ImageColorAt($this->thumb,$i,$cposy+0.5*$heighty); - $rgbarray=ImageColorsForIndex($this->thumb,$indexis); - array_push($colors,$rgbarray['red'],$rgbarray['green'],$rgbarray['blue']); - } - if (array_sum($colors)/count($colors)>180) { - if ($this->Copyrightfonttype=='') - imagestring($this->thumb,$this->Copyrightfontsize,$cposx,$cposy,$this->Copyrighttext,imagecolorallocate($this->thumb,0,0,0)); - else - imagettftext($this->thumb,$this->Copyrightfontsize,0,$cposx,$cposy,imagecolorallocate($this->thumb,0,0,0),$this->Copyrightfonttype,$this->Copyrighttext); - } else { - if ($this->Copyrightfonttype=='') - imagestring($this->thumb,$this->Copyrightfontsize,$cposx,$cposy,$this->Copyrighttext,imagecolorallocate($this->thumb,255,255,255)); - else - imagettftext($this->thumb,$this->Copyrightfontsize,0,$cposx,$cposy,imagecolorallocate($this->thumb,255,255,255),$this->Copyrightfonttype,$this->Copyrighttext); - } - } else { - if ($this->Copyrightfonttype=='') - imagestring($this->thumb,$this->Copyrightfontsize,$cposx,$cposy,$this->Copyrighttext,imagecolorallocate($this->thumb,hexdec(substr($this->Copyrighttextcolor,1,2)),hexdec(substr($this->Copyrighttextcolor,3,2)),hexdec(substr($this->Copyrighttextcolor,5,2)))); - else - imagettftext($this->thumb,$this->Copyrightfontsize,0,$cposx,$cposy,imagecolorallocate($this->thumb,hexdec(substr($this->Copyrighttextcolor,1,2)),hexdec(substr($this->Copyrighttextcolor,3,2)),hexdec(substr($this->Copyrighttextcolor,5,2))),$this->Copyrightfonttype,$this->Copyrighttext); - } - - } - - /** - * Rotate the image at any angle - * Image is not scaled down - * - */ - private function freerotate() { - - $angle=$this->Rotate; - if ($angle<>0) { - $centerx=floor($this->size[0]/2); - $centery=floor($this->size[1]/2); - $maxsizex=ceil(abs(cos(deg2rad($angle))*$this->size[0])+abs(sin(deg2rad($angle))*$this->size[1])); - $maxsizey=ceil(abs(sin(deg2rad($angle))*$this->size[0])+abs(cos(deg2rad($angle))*$this->size[1])); - if ($maxsizex & 1) {$maxsizex+=3;} else {$maxsizex+=2;} - if ($maxsizey & 1) {$maxsizey+=3;} else {$maxsizey+=2;} - $this->newimage=imagecreatetruecolor($maxsizex,$maxsizey); - imagefilledrectangle($this->newimage,0,0,$maxsizex,$maxsizey,imagecolorallocate($this->newimage,hexdec(substr($this->Backgroundcolor,1,2)),hexdec(substr($this->Backgroundcolor,3,2)),hexdec(substr($this->Backgroundcolor,5,2)))); - $newcenterx=imagesx($this->newimage)/2; - $newcentery=imagesy($this->newimage)/2; - $angle+=180; - for ($px=0;$pxnewimage);$px++) { - for ($py=0;$pynewimage);$py++) { - $vectorx=floor(($newcenterx-$px)*cos(deg2rad($angle))+($newcentery-$py)*sin(deg2rad($angle))); - $vectory=floor(($newcentery-$py)*cos(deg2rad($angle))-($newcenterx-$px)*sin(deg2rad($angle))); - if (($centerx+$vectorx)>-1 && ($centerx+$vectorx)<($centerx*2) && ($centery+$vectory)>-1 && ($centery+$vectory)<($centery*2)) - imagecopy($this->newimage,$this->im,$px,$py,$centerx+$vectorx,$centery+$vectory,1,1); - } - } - imagedestroy($this->im); - $this->im=imagecreatetruecolor(imagesx($this->newimage),imagesy($this->newimage)); - imagecopy($this->im,$this->newimage,0,0,0,0,imagesx($this->newimage),imagesy($this->newimage)); - imagedestroy($this->newimage); - $this->size[0]=imagesx($this->im); - $this->size[1]=imagesy($this->im); - } - - } - - /** - * Rotate the image at any angle - * Image is scaled down - * - */ - private function croprotate() { - - $this->im=imagerotate($this->im,-$this->Rotate,imagecolorallocate($this->im,hexdec(substr($this->Backgroundcolor,1,2)),hexdec(substr($this->Backgroundcolor,3,2)),hexdec(substr($this->Backgroundcolor,5,2)))); - - } - - /** - * Rotate the image +90, -90 or 180 degrees - * Flip the image over horizontal or vertical axis - * - * @param $rotate - * @param $flip - */ - private function rotateorflip($rotate,$flip) { - - if ($rotate) { - $this->newimage=imagecreatetruecolor($this->size[1],$this->size[0]); - } else { - $this->newimage=imagecreatetruecolor($this->size[0],$this->size[1]); - } - if (intval($this->Rotate)>0 || $flip>0) { - for ($px=0;$px<$this->size[0];$px++) { - if ($rotate) { - for ($py=0;$py<$this->size[1];$py++) {imagecopy($this->newimage,$this->im,$this->size[1]-$py-1,$px,$px,$py,1,1);} - } else { - for ($py=0;$py<$this->size[1];$py++) {imagecopy($this->newimage,$this->im,$this->size[0]-$px-1,$py,$px,$py,1,1);} - } - } - } else { - for ($px=0;$px<$this->size[0];$px++) { - if ($rotate) { - for ($py=0;$py<$this->size[1];$py++) {imagecopy($this->newimage,$this->im,$py,$this->size[0]-$px-1,$px,$py,1,1);} - } else { - for ($py=0;$py<$this->size[1];$py++) {imagecopy($this->newimage,$this->im,$px,$this->size[1]-$py-1,$px,$py,1,1);} - } - } - } - imagedestroy($this->im); - $this->im=imagecreatetruecolor(imagesx($this->newimage),imagesy($this->newimage)); - imagecopy($this->im,$this->newimage,0,0,0,0,imagesx($this->newimage),imagesy($this->newimage)); - imagedestroy($this->newimage); - $this->size[0]=imagesx($this->im); - $this->size[1]=imagesy($this->im); - - } - - /** - * Crop image in percentage or pixels - * Crop from sides or from center - * Negative value for bottom crop will enlarge the canvas - * - */ - private function cropimage() { - - if ($this->Cropimage[1]==0) { - $crop2=floor($this->size[0]*($this->Cropimage[2]/100)); - $crop3=floor($this->size[0]*($this->Cropimage[3]/100)); - $crop4=floor($this->size[1]*($this->Cropimage[4]/100)); - $crop5=floor($this->size[1]*($this->Cropimage[5]/100)); - } - if ($this->Cropimage[1]==1) { - $crop2=$this->Cropimage[2]; - $crop3=$this->Cropimage[3]; - $crop4=$this->Cropimage[4]; - $crop5=$this->Cropimage[5]; - } - if ($this->Cropimage[0]==2) { - $crop2=floor($this->size[0]/2)-$crop2; - $crop3=floor($this->size[0]/2)-$crop3; - $crop4=floor($this->size[1]/2)-$crop4; - $crop5=floor($this->size[1]/2)-$crop5; - } - if ($this->Cropimage[0]==3) { - if ($this->size[0]>$this->size[1]) { - $crop2=$crop3=floor(($this->size[0]-$this->size[1])/2); - $crop4=$crop5=0; - } else { - $crop4=$crop5=floor(($this->size[1]-$this->size[0])/2); - $crop2=$crop3=0; - } - } - $this->newimage=imagecreatetruecolor($this->size[0]-$crop2-$crop3,$this->size[1]-$crop4-$crop5); - if ($crop5<0) {$crop5=0;imagefilledrectangle($this->newimage,0,0,imagesx($this->newimage),imagesy($this->newimage),imagecolorallocate($this->newimage,hexdec(substr($this->Polaroidframecolor,1,2)),hexdec(substr($this->Polaroidframecolor,3,2)),hexdec(substr($this->Polaroidframecolor,5,2))));} - imagecopy($this->newimage,$this->im,0,0,$crop2,$crop4,$this->size[0]-$crop2-$crop3,$this->size[1]-$crop4-$crop5); - imagedestroy($this->im); - $this->im=imagecreatetruecolor(imagesx($this->newimage),imagesy($this->newimage)); - imagecopy($this->im,$this->newimage,0,0,0,0,imagesx($this->newimage),imagesy($this->newimage)); - imagedestroy($this->newimage); - $this->size[0]=imagesx($this->im); - $this->size[1]=imagesy($this->im); - - } - - /** - * Enlarge the canvas to be same width and height - * - */ - private function square() { - - $squaresize=max($this->thumbx,$this->thumby); - $this->newimage=imagecreatetruecolor($squaresize,$squaresize); - imagefilledrectangle($this->newimage,0,0,$squaresize,$squaresize,imagecolorallocate($this->newimage,hexdec(substr($this->Backgroundcolor,1,2)),hexdec(substr($this->Backgroundcolor,3,2)),hexdec(substr($this->Backgroundcolor,5,2)))); - $centerx=floor(($squaresize-$this->thumbx)/2); - $centery=floor(($squaresize-$this->thumby)/2); - imagecopy($this->newimage,$this->thumb,$centerx,$centery,0,0,$this->thumbx,$this->thumby); - imagedestroy($this->thumb); - $this->thumb=imagecreatetruecolor($squaresize,$squaresize); - imagecopy($this->thumb,$this->newimage,0,0,0,0,$squaresize,$squaresize); - imagedestroy($this->newimage); - - } - - /** - * Apply a 3x3 filter matrix to the image - * - */ - private function filter() { - - if (function_exists('imageconvolution')) { - imageconvolution($this->im,array(array($this->Filter[0],$this->Filter[1],$this->Filter[2]), array($this->Filter[3],$this->Filter[4],$this->Filter[5]),array($this->Filter[6],$this->Filter[7],$this->Filter[8])),$this->Divisor,$this->Offset); - } else { - $newpixel=array(); - $this->newimage=imagecreatetruecolor($this->size[0],$this->size[1]); - for ($y=0;$y<$this->size[1];$y++) { - for ($x=0;$x<$this->size[0];$x++) { - $newpixel[0]=0;$newpixel[1]=0;$newpixel[2]=0; - $a11=$this->rgbpixel($x-1,$y-1);$a12=$this->rgbpixel($x,$y-1);$a13=$this->rgbpixel($x+1,$y-1); - $a21=$this->rgbpixel($x-1,$y);$a22=$this->rgbpixel($x,$y);$a23=$this->rgbpixel($x+1,$y); - $a31=$this->rgbpixel($x-1,$y+1);$a32=$this->rgbpixel($x,$y+1);$a33=$this->rgbpixel($x+1,$y+1); - $newpixel[0]+=$a11['red']*$this->Filter[0]+$a12['red']*$this->Filter[1]+$a13['red']*$this->Filter[2]; - $newpixel[1]+=$a11['green']*$this->Filter[0]+$a12['green']*$this->Filter[1]+$a13['green']*$this->Filter[2]; - $newpixel[2]+=$a11['blue']*$this->Filter[0]+$a12['blue']*$this->Filter[1]+$a13['blue']*$this->Filter[2]; - $newpixel[0]+=$a21['red']*$this->Filter[3]+$a22['red']*$this->Filter[4]+$a23['red']*$this->Filter[5]; - $newpixel[1]+=$a21['green']*$this->Filter[3]+$a22['green']*$this->Filter[4]+$a23['green']*$this->Filter[5]; - $newpixel[2]+=$a21['blue']*$this->Filter[3]+$a22['blue']*$this->Filter[4]+$a23['blue']*$this->Filter[5]; - $newpixel[0]+=$a31['red']*$this->Filter[6]+$a32['red']*$this->Filter[7]+$a33['red']*$this->Filter[8]; - $newpixel[1]+=$a31['green']*$this->Filter[6]+$a32['green']*$this->Filter[7]+$a33['green']*$this->Filter[8]; - $newpixel[2]+=$a31['blue']*$this->Filter[6]+$a32['blue']*$this->Filter[7]+$a33['blue']*$this->Filter[8]; - $newpixel[0]=max(0,min(255,intval($newpixel[0]/$this->Divisor)+$this->Offset)); - $newpixel[1]=max(0,min(255,intval($newpixel[1]/$this->Divisor)+$this->Offset)); - $newpixel[2]=max(0,min(255,intval($newpixel[2]/$this->Divisor)+$this->Offset)); - imagesetpixel($this->newimage,$x,$y,imagecolorallocatealpha($this->newimage,$newpixel[0],$newpixel[1],$newpixel[2],$a11['alpha'])); - } - } - imagecopy($this->im,$this->newimage,0,0,0,0,$this->size[0],$this->size[1]); - imagedestroy($this->newimage); - } - - } - - /** - * Apply a median filter matrix to the image to remove noise - * - */ - private function medianfilter() { - - $this->newimage=imagecreatetruecolor($this->size[0],$this->size[1]); - for ($y=0;$y<$this->size[1];$y++) { - for ($x=0;$x<$this->size[0];$x++) { - $newred=array();$newgreen=array();$newblue=array(); - $a11=$this->rgbpixel($x-1,$y-1);$a12=$this->rgbpixel($x,$y-1);$a13=$this->rgbpixel($x+1,$y-1); - $a21=$this->rgbpixel($x-1,$y);$a22=$this->rgbpixel($x,$y);$a23=$this->rgbpixel($x+1,$y); - $a31=$this->rgbpixel($x-1,$y+1);$a32=$this->rgbpixel($x,$y+1);$a33=$this->rgbpixel($x+1,$y+1); - $newred[]=$a11['red'];$newgreen[]=$a11['green'];$newblue[]=$a11['blue']; - $newred[]=$a12['red'];$newgreen[]=$a12['green'];$newblue[]=$a12['blue']; - $newred[]=$a13['red'];$newgreen[]=$a13['green'];$newblue[]=$a13['blue']; - $newred[]=$a21['red'];$newgreen[]=$a21['green'];$newblue[]=$a21['blue']; - $newred[]=$a22['red'];$newgreen[]=$a22['green'];$newblue[]=$a22['blue']; - $newred[]=$a23['red'];$newgreen[]=$a23['green'];$newblue[]=$a23['blue']; - $newred[]=$a31['red'];$newgreen[]=$a31['green'];$newblue[]=$a31['blue']; - $newred[]=$a32['red'];$newgreen[]=$a32['green'];$newblue[]=$a32['blue']; - $newred[]=$a33['red'];$newgreen[]=$a33['green'];$newblue[]=$a33['blue']; - sort($newred,SORT_NUMERIC);sort($newgreen,SORT_NUMERIC);sort($newblue,SORT_NUMERIC); - imagesetpixel($this->newimage,$x,$y,imagecolorallocatealpha($this->newimage,$newred[4],$newgreen[4],$newblue[4],$a22['alpha'])); - } - } - imagecopy($this->im,$this->newimage,0,0,0,0,$this->size[0],$this->size[1]); - imagedestroy($this->newimage); - - } - - /** - * Return RGB values from pixel - * - */ - private function rgbpixel($x,$y) { - - if ($x<0) {$x=0;} - if ($x>=$this->size[0]) {$x=$this->size[0]-1;} - if ($y<0) {$y=0;} - if ($y>=$this->size[1]) {$y=$this->size[1]-1;} - $pixel=ImageColorAt($this->im,$x,$y); - return array('red' => ($pixel >> 16 & 0xFF),'green' => ($pixel >> 8 & 0xFF),'blue' => ($pixel & 0xFF),'alpha' => ($pixel >>24 & 0xFF)); - - } - - /** - * Gaussian Blur Filter - * - */ - private function blur() { - - $oldfilter=$this->Filter;$olddivisor=$this->Divisor;$oldoffset=$this->Offset; - $this->Filter = array(1,2,1,2,4,2,1,2,1); - $this->Divisor = 16; - $this->Offset = 0; - $this->filter(); - $this->Filter = $oldfilter; - $this->Divisor = $olddivisor; - $this->Offset = $oldoffset; - - } - - /** - * Sharpen Filter - * - */ - private function sharpen() { - - $oldfilter=$this->Filter;$olddivisor=$this->Divisor;$oldoffset=$this->Offset; - $this->Filter = array(-1,-1,-1,-1,16,-1,-1,-1,-1); - $this->Divisor = 8; - $this->Offset = 0; - $this->filter(); - $this->Filter = $oldfilter; - $this->Divisor = $olddivisor; - $this->Offset = $oldoffset; - - } - - /** - * Edge Filter - * - */ - private function edge() { - - $oldfilter=$this->Filter;$olddivisor=$this->Divisor;$oldoffset=$this->Offset; - $this->Filter = array(-1,-1,-1,-1,8,-1,-1,-1,-1); - $this->Divisor = 1; - $this->Offset = 127; - $this->filter(); - $this->Filter = $oldfilter; - $this->Divisor = $olddivisor; - $this->Offset = $oldoffset; - - } - - /** - * Emboss Filter - * - */ - private function emboss() { - - $oldfilter=$this->Filter;$olddivisor=$this->Divisor;$oldoffset=$this->Offset; - $this->Filter = array(2,0,0,0,-1,0,0,0,-1); - $this->Divisor = 1; - $this->Offset = 127; - $this->filter(); - $this->Filter = $oldfilter; - $this->Divisor = $olddivisor; - $this->Offset = $oldoffset; - - } - - /** - * Mean Filter - * - */ - private function mean() { - - $oldfilter=$this->Filter;$olddivisor=$this->Divisor;$oldoffset=$this->Offset; - $this->Filter = array(1,1,1,1,1,1,1,1,1); - $this->Divisor = 9; - $this->Offset = 0; - $this->filter(); - $this->Filter = $oldfilter; - $this->Divisor = $olddivisor; - $this->Offset = $oldoffset; - - } - - /** - * Apply perspective to the image - * - */ - private function perspective() { - - $this->newimage=imagecreatetruecolor($this->size[0],$this->size[1]); - imagefilledrectangle($this->newimage,0,0,$this->size[0],$this->size[1],imagecolorallocate($this->newimage,hexdec(substr($this->Backgroundcolor,1,2)),hexdec(substr($this->Backgroundcolor,3,2)),hexdec(substr($this->Backgroundcolor,5,2)))); - if ($this->Perspective[1]==0 || $this->Perspective[1]==1) { - $gradient=($this->size[1]-($this->size[1]*(max(100-$this->Perspective[2],1)/100)))/$this->size[0]; - for ($c=0;$c<$this->size[0];$c++) { - if ($this->Perspective[1]==0) { - $length=$this->size[1]-(floor($gradient*$c)); - } else { - $length=$this->size[1]-(floor($gradient*($this->size[0]-$c))); - } - imagecopyresampled($this->newimage,$this->im,$c,floor(($this->size[1]-$length)/2),$c,0,1,$length,1,$this->size[1]); - } - } else { - $gradient=($this->size[0]-($this->size[0]*(max(100-$this->Perspective[2],1)/100)))/$this->size[1]; - for ($c=0;$c<$this->size[1];$c++) { - if ($this->Perspective[1]==2) { - $length=$this->size[0]-(floor($gradient*$c)); - } else { - $length=$this->size[0]-(floor($gradient*($this->size[1]-$c))); - } - imagecopyresampled($this->newimage,$this->im,floor(($this->size[0]-$length)/2),$c,0,$c,$length,1,$this->size[0],1); - } - } - imagecopy($this->im,$this->newimage,0,0,0,0,$this->size[0],$this->size[1]); - imagedestroy($this->newimage); - - } - - /** - * Apply perspective to the thumbnail - * - */ - private function perspectivethumb() { - - $this->newimage=imagecreatetruecolor($this->thumbx,$this->thumby); - imagefilledrectangle($this->newimage,0,0,$this->thumbx,$this->thumby,imagecolorallocate($this->newimage,hexdec(substr($this->Backgroundcolor,1,2)),hexdec(substr($this->Backgroundcolor,3,2)),hexdec(substr($this->Backgroundcolor,5,2)))); - if ($this->Perspectivethumb[1]==0 || $this->Perspectivethumb[1]==1) { - $gradient=($this->thumby-($this->thumby*(max(100-$this->Perspectivethumb[2],1)/100)))/$this->thumbx; - for ($c=0;$c<$this->thumbx;$c++) { - if ($this->Perspectivethumb[1]==0) { - $length=$this->thumby-(floor($gradient*$c)); - } else { - $length=$this->thumby-(floor($gradient*($this->thumbx-$c))); - } - imagecopyresampled($this->newimage,$this->thumb,$c,floor(($this->thumby-$length)/2),$c,0,1,$length,1,$this->thumby); - } - } else { - $gradient=($this->thumbx-($this->thumbx*(max(100-$this->Perspectivethumb[2],1)/100)))/$this->thumby; - for ($c=0;$c<$this->thumby;$c++) { - if ($this->Perspectivethumb[1]==2) { - $length=$this->thumbx-(floor($gradient*$c)); - } else { - $length=$this->thumbx-(floor($gradient*($this->thumby-$c))); - } - imagecopyresampled($this->newimage,$this->thumb,floor(($this->thumbx-$length)/2),$c,0,$c,$length,1,$this->thumbx,1); - } - } - imagecopy($this->thumb,$this->newimage,0,0,0,0,$this->thumbx,$this->thumby); - imagedestroy($this->newimage); - - } - - /** - * Apply gradient shading to image - * - */ - private function shading() { - - if ($this->Shading[3]==0 || $this->Shading[3]==1) { - $this->newimage=imagecreatetruecolor(1,$this->size[1]); - imagefilledrectangle($this->newimage,0,0,1,$this->size[1],imagecolorallocate($this->newimage,hexdec(substr($this->Shadingcolor,1,2)),hexdec(substr($this->Shadingcolor,3,2)),hexdec(substr($this->Shadingcolor,5,2)))); - } else { - $this->newimage=imagecreatetruecolor($this->size[0],1); - imagefilledrectangle($this->newimage,0,0,$this->size[0],1,imagecolorallocate($this->newimage,hexdec(substr($this->Shadingcolor,1,2)),hexdec(substr($this->Shadingcolor,3,2)),hexdec(substr($this->Shadingcolor,5,2)))); - } - if ($this->Shading[3]==0) { - $shadingstrength=$this->Shading[1]/($this->size[0]*($this->Shading[2]/100)); - for ($c=$this->size[0]-floor(($this->size[0]*($this->Shading[2]/100)));$c<$this->size[0];$c++) { - $opacity=floor($shadingstrength*($c-($this->size[0]-floor(($this->size[0]*($this->Shading[2]/100)))))); - imagecopymerge($this->im,$this->newimage,$c,0,0,0,1,$this->size[1],max(min($opacity,100),0)); - } - } else if ($this->Shading[3]==1) { - $shadingstrength=$this->Shading[1]/($this->size[0]*($this->Shading[2]/100)); - for ($c=0;$csize[0]*($this->Shading[2]/100));$c++) { - $opacity=floor($this->Shading[1]-($c*$shadingstrength)); - imagecopymerge($this->im,$this->newimage,$c,0,0,0,1,$this->size[1],max(min($opacity,100),0)); - } - } else if ($this->Shading[3]==2) { - $shadingstrength=$this->Shading[1]/($this->size[1]*($this->Shading[2]/100)); - for ($c=0;$csize[1]*($this->Shading[2]/100));$c++) { - $opacity=floor($this->Shading[1]-($c*$shadingstrength)); - imagecopymerge($this->im,$this->newimage,0,$c,0,0,$this->size[0],1,max(min($opacity,100),0)); - } - } else { - $shadingstrength=$this->Shading[1]/($this->size[1]*($this->Shading[2]/100)); - for ($c=$this->size[1]-floor(($this->size[1]*($this->Shading[2]/100)));$c<$this->size[1];$c++) { - $opacity=floor($shadingstrength*($c-($this->size[1]-floor(($this->size[1]*($this->Shading[2]/100)))))); - imagecopymerge($this->im,$this->newimage,0,$c,0,0,$this->size[0],1,max(min($opacity,100),0)); - } - } - imagedestroy($this->newimage); - - } - - /** - * Apply mirror effect to the thumbnail with gradient - * - */ - private function mirror() { - - $bottom=floor(($this->Mirror[3]/100)*$this->thumby)+$this->Mirror[4]; - $this->newimage=imagecreatetruecolor($this->thumbx,$this->thumby+$bottom); - imagefilledrectangle($this->newimage,0,0,$this->thumbx,$this->thumby+$bottom,imagecolorallocate($this->newimage,hexdec(substr($this->Backgroundcolor,1,2)),hexdec(substr($this->Backgroundcolor,3,2)),hexdec(substr($this->Backgroundcolor,5,2)))); - imagecopy($this->newimage,$this->thumb,0,0,0,0,$this->thumbx,$this->thumby); - imagedestroy($this->thumb);$this->thumb=imagecreatetruecolor($this->thumbx,$this->thumby+$bottom); - imagecopy($this->thumb,$this->newimage,0,0,0,0,$this->thumbx,$this->thumby+$bottom); - imagedestroy($this->newimage);$this->thumbx=imagesx($this->thumb);$this->thumby=imagesy($this->thumb); - for ($px=0;$px<$this->thumbx;$px++) { - for ($py=$this->thumby-($bottom*2)+$this->Mirror[4];$py<($this->thumby-$bottom);$py++) {imagecopy($this->thumb,$this->thumb,$px,$this->thumby-($py-($this->thumby-($bottom*2)))-1+$this->Mirror[4],$px,$py,1,1);} - } - $this->newimage=imagecreatetruecolor($this->thumbx,1); - imagefilledrectangle($this->newimage,0,0,$this->thumbx,1,imagecolorallocate($this->newimage,hexdec(substr($this->Mirrorcolor,1,2)),hexdec(substr($this->Mirrorcolor,3,2)),hexdec(substr($this->Mirrorcolor,5,2)))); - $shadingstrength=($this->Mirror[2]-$this->Mirror[1])/$bottom; - for ($c=$this->thumby-$bottom;$c<$this->thumby;$c++) { - $opacity=$this->Mirror[1]+floor(($bottom-($this->thumby-$c))*$shadingstrength); - imagecopymerge($this->thumb,$this->newimage,0,$c,0,0,$this->thumbx,1,max(min($opacity,100),0)); - } - imagedestroy($this->newimage); - - } - - /** - * Create a negative - * - */ - private function negative() { - - if (function_exists('imagefilter')) { - imagefilter($this->im,IMG_FILTER_NEGATE); - } else { - for ($y=0;$y<$this->size[1];$y++) { - for ($x=0;$x<$this->size[0];$x++) { - $pixel=ImageColorAt($this->im,$x,$y); - imagesetpixel($this->im,$x,$y,imagecolorallocatealpha($this->im,255-($pixel >> 16 & 0xFF),255-($pixel >> 8 & 0xFF),255-($pixel & 0xFF),$pixel >> 24 & 0xFF)); - } - } - } - - } - - /** - * Replace a color - * Eucledian color vector distance - * - */ - private function colorreplace() { - - $red=hexdec(substr($this->Colorreplace[1],1,2));$green=hexdec(substr($this->Colorreplace[1],3,2));$blue=hexdec(substr($this->Colorreplace[1],5,2)); - $rednew=hexdec(substr($this->Colorreplace[2],1,2));$greennew=hexdec(substr($this->Colorreplace[2],3,2));$bluenew=hexdec(substr($this->Colorreplace[2],5,2)); - $tolerance=sqrt(pow($this->Colorreplace[3],2)+pow($this->Colorreplace[3],2)+pow($this->Colorreplace[3],2)); - for ($y=0;$y<$this->size[1];$y++) { - for ($x=0;$x<$this->size[0];$x++) { - $pixel=ImageColorAt($this->im,$x,$y); - $redpix=($pixel >> 16 & 0xFF);$greenpix=($pixel >> 8 & 0xFF);$bluepix=($pixel & 0xFF); - if (sqrt(pow($redpix-$red,2)+pow($greenpix-$green,2)+pow($bluepix-$blue,2))<$tolerance) - imagesetpixel($this->im,$x,$y,imagecolorallocatealpha($this->im,$rednew,$greennew,$bluenew,$pixel >> 24 & 0xFF)); - } - } - - } - - /** - * Randomly reposition pixels - * - */ - private function pixelscramble() { - - for ($i=0;$i<$this->Pixelscramble[2];$i++) { - $this->newimage=imagecreatetruecolor($this->size[0],$this->size[1]); - for ($y=0;$y<$this->size[1];$y++) { - for ($x=0;$x<$this->size[0];$x++) { - $newx=$x+rand(-$this->Pixelscramble[1],$this->Pixelscramble[1]); - $newy=$y+rand(-$this->Pixelscramble[1],$this->Pixelscramble[1]); - if ($newx<0 && $newx>=$this->size[0]) {$newx=$x;} - if ($newy<0 && $newy>=$this->size[1]) {$newy=$y;} - imagecopy($this->newimage,$this->im,$newx,$newy,$x,$y,1,1); - imagecopy($this->newimage,$this->im,$x,$y,$newx,$newy,1,1); - } - } - imagecopy($this->im,$this->newimage,0,0,0,0,$this->size[0],$this->size[1]); - imagedestroy($this->newimage); - } - - } - - /** - * Convert to greyscale - * - */ - private function greyscale() { - - if (function_exists('imagefilter')) { - imagefilter($this->im,IMG_FILTER_GRAYSCALE); - } else { - for ($y=0;$y<$this->size[1];$y++) { - for ($x=0;$x<$this->size[0];$x++) { - $pixel=ImageColorAt($this->im,$x,$y); - $grey=floor(($pixel >> 16 & 0xFF)*0.299 + ($pixel >> 8 & 0xFF)*0.587 + ($pixel & 0xFF)*0.114); - imagesetpixel($this->im,$x,$y,imagecolorallocatealpha($this->im,$grey,$grey,$grey,$pixel >> 24 & 0xFF)); - } - } - } - - } - - /** - * Change brightness - * - */ - private function brightness() { - - if (function_exists('imagefilter')) { - imagefilter($this->im,IMG_FILTER_BRIGHTNESS,$this->Brightness[1]); - } else { - for ($y=0;$y<$this->size[1];$y++) { - for ($x=0;$x<$this->size[0];$x++) { - $pixel=ImageColorAt($this->im,$x,$y); - $redpix=max(0,min(255,($pixel >> 16 & 0xFF)+($this->Brightness[1]/100)*255)); - $greenpix=max(0,min(255,($pixel >> 8 & 0xFF)+($this->Brightness[1]/100)*255)); - $bluepix=max(0,min(255,($pixel & 0xFF)+($this->Brightness[1]/100)*255)); - imagesetpixel($this->im,$x,$y,imagecolorallocatealpha($this->im,$redpix,$greenpix,$bluepix,$pixel >> 24 & 0xFF)); - } - } - } - - } - - /** - * Change contrast - * - */ - private function contrast() { - - if (function_exists('imagefilter')) { - imagefilter($this->im,IMG_FILTER_CONTRAST,-$this->Contrast[1]); - } else { - for ($y=0;$y<$this->size[1];$y++) { - for ($x=0;$x<$this->size[0];$x++) { - $pixel=ImageColorAt($this->im,$x,$y); - $redpix=max(0,min(255,(((($pixel >> 16 & 0xFF)/255)-0.5)*($this->Contrast[1]/100+1)+0.5)*255)); - $greenpix=max(0,min(255,(((($pixel >> 8 & 0xFF)/255)-0.5)*($this->Contrast[1]/100+1)+0.5)*255)); - $bluepix=max(0,min(255,(((($pixel & 0xFF)/255)-0.5)*($this->Contrast[1]/100+1)+0.5)*255)); - imagesetpixel($this->im,$x,$y,imagecolorallocatealpha($this->im,$redpix,$greenpix,$bluepix,$pixel >> 24 & 0xFF)); - } - } - } - - } - - /** - * Change gamma - * - */ - private function gamma() { - - imagegammacorrect($this->im,1,$this->Gamma[1]); - - } - - /** - * Reduce palette - * - */ - private function palette() { - - imagetruecolortopalette($this->im,false,$this->Palette[1]); - - } - - /** - * Merge a color in the image - * - */ - private function colorize() { - - if (function_exists('imagefilter')) { - imagefilter($this->im,IMG_FILTER_COLORIZE,$this->Colorize[1],$this->Colorize[2],$this->Colorize[3],$this->Colorize[4]); - } else { - for ($y=0;$y<$this->size[1];$y++) { - for ($x=0;$x<$this->size[0];$x++) { - $pixel=ImageColorAt($this->im,$x,$y); - $redpix=max(0,min(255,($pixel >> 16 & 0xFF)+$this->Colorize[1])); - $greenpix=max(0,min(255,($pixel >> 8 & 0xFF)+$this->Colorize[2])); - $bluepix=max(0,min(255,($pixel & 0xFF)+$this->Colorize[3])); - $alpha =max(0,min(127,($pixel >> 24 & 0xFF)+$this->Colorize[4])); - imagesetpixel($this->im,$x,$y,imagecolorallocatealpha($this->im,$redpix,$greenpix,$bluepix,$alpha)); - } - } - } - - } - - /** - * Pixelate the image - * - */ - private function pixelate() { - - if (function_exists('imagefilter')) { - imagefilter($this->im,IMG_FILTER_PIXELATE,$this->Pixelate[1],true); - } else { - for ($y=0;$y<$this->size[1];$y+=$this->Pixelate[1]) { - for ($x=0;$x<$this->size[0];$x+=$this->Pixelate[1]) { - $pixel=ImageColorAt($this->im,$x,$y); - imagefilledrectangle($this->im,$x,$y,$x+$this->Pixelate[1]-1,$y+$this->Pixelate[1]-1,$pixel); - } - } - } - - } - - /** - * Bilinear interpolation - * - */ - private function bilinear($xnew,$ynew) { - - $xf=floor($xnew);$xc=$xf+1;$fracx=$xnew-$xf;$fracx1=1-$fracx; - $yf=floor($ynew);$yc=$yf+1;$fracy=$ynew-$yf;$fracy1=1-$fracy; - $ff=$this->rgbpixel($xf,$yf);$cf=$this->rgbpixel($xc,$yf); - $fc=$this->rgbpixel($xf,$yc);$cc=$this->rgbpixel($xc,$yc); - $red=floor($fracy1*($fracx1*$ff['red']+$fracx*$cf['red'])+$fracy*($fracx1*$fc['red']+$fracx*$cc['red'])); - $green=floor($fracy1*($fracx1*$ff['green']+$fracx*$cf['green'])+$fracy*($fracx1*$fc['green']+$fracx*$cc['green'])); - $blue=floor($fracy1*($fracx1*$ff['blue']+$fracx*$cf['blue'])+$fracy*($fracx1*$fc['blue']+$fracx*$cc['blue'])); - return array('red' => $red,'green' => $green,'blue' => $blue,'alpha' => $cc['alpha']); - - } - - /** - * Apply twirl FX to image - * - */ - private function twirlfx() { - - $rotationamount=$this->Twirlfx[1]/1000; - $centerx=floor($this->size[0]/2);$centery=floor($this->size[1]/2); - $this->newimage=imagecreatetruecolor($this->size[0],$this->size[1]); - for ($y=0;$y<$this->size[1];$y++) { - for ($x=0;$x<$this->size[0];$x++) { - $truex=$x-$centerx;$truey=$y-$centery; - $theta=atan2(($truey),($truex)); - $radius=sqrt($truex*$truex+$truey*$truey); - if ($this->Twirlfx[2]==0) { - $newx=$centerx+($radius*cos($theta+$rotationamount*$radius)); - $newy=$centery+($radius*sin($theta+$rotationamount*$radius)); - } else { - $newx=$centerx-($radius*cos($theta+$rotationamount*$radius)); - $newy=$centery-($radius*sin($theta+$rotationamount*$radius)); - } - $newpix=$this->bilinear($newx,$newy); - imagesetpixel($this->newimage,$x,$y,imagecolorallocatealpha($this->newimage,$newpix['red'],$newpix['green'],$newpix['blue'],$newpix['alpha'])); - } - } - imagecopy($this->im,$this->newimage,0,0,0,0,$this->size[0],$this->size[1]); - imagedestroy($this->newimage); - - } - - /** - * Apply ripple FX to image - * - */ - private function ripplefx() { - - $wavex=((2*pi())/$this->size[0])*$this->Ripplefx[1]; - $wavey=((2*pi())/$this->size[1])*$this->Ripplefx[3]; - $this->newimage=imagecreatetruecolor($this->size[0],$this->size[1]); - for ($y=0;$y<$this->size[1];$y++) { - for ($x=0;$x<$this->size[0];$x++) { - $newx=$x+$this->Ripplefx[4]*sin($y*$wavey); - $newy=$y+$this->Ripplefx[2]*sin($x*$wavex); - $newpix=$this->bilinear($newx,$newy); - imagesetpixel($this->newimage,$x,$y,imagecolorallocatealpha($this->newimage,$newpix['red'],$newpix['green'],$newpix['blue'],$newpix['alpha'])); - } - } - imagecopy($this->im,$this->newimage,0,0,0,0,$this->size[0],$this->size[1]); - imagedestroy($this->newimage); - - } - - /** - * Apply lake FX to image - * - */ - private function lakefx() { - - $this->newimage=imagecreatetruecolor($this->size[0],$this->size[1]); - $ystart=max($this->size[1]-floor($this->size[1]*($this->Lakefx[2]/100)),0); - if ($ystart>0) { - imagecopy($this->newimage,$this->im,0,0,0,0,$this->size[0],$this->size[1]); - } - for ($y=$ystart;$y<$this->size[1];$y++) { - for ($x=0;$x<$this->size[0];$x++) { - $newy=$y+3*pi()*(1/$this->size[1])*$y*sin(($this->size[1]*($this->Lakefx[1]/100)*($this->size[1]-$y))/$y); - $newpix=$this->bilinear($x,$newy); - imagesetpixel($this->newimage,$x,$y,imagecolorallocatealpha($this->newimage,$newpix['red'],$newpix['green'],$newpix['blue'],$newpix['alpha'])); - } - } - imagecopy($this->im,$this->newimage,0,0,0,0,$this->size[0],$this->size[1]); - imagedestroy($this->newimage); - - } - - /** - * Apply waterdrop FX to image - * - */ - private function waterdropfx() { - - $centerx=floor($this->size[0]/2);$centery=floor($this->size[1]/2); - $this->newimage=imagecreatetruecolor($this->size[0],$this->size[1]); - for ($y=0;$y<$this->size[1];$y++) { - for ($x=0;$x<$this->size[0];$x++) { - $truex=$x-$centerx;$truey=$y-$centery; - $distance=sqrt($truex*$truex+$truey*$truey); - $amount=$this->Waterdropfx[1]*sin($distance/$this->Waterdropfx[3]*2*pi()); - $amount=$amount*($this->Waterdropfx[2]-$distance)/$this->Waterdropfx[2]; - if ($distance!=0) {$amount=$amount*$this->Waterdropfx[3]/$distance;} - $newx=$x+$truex*$amount; - $newy=$y+$truey*$amount; - $newpix=$this->bilinear($newx,$newy); - imagesetpixel($this->newimage,$x,$y,imagecolorallocatealpha($this->newimage,$newpix['red'],$newpix['green'],$newpix['blue'],$newpix['alpha'])); - } - } - imagecopy($this->im,$this->newimage,0,0,0,0,$this->size[0],$this->size[1]); - imagedestroy($this->newimage); - - } - - /** - * Create a transparent image - * - */ - private function maketransparent() { - - imagetruecolortopalette($this->thumb,false,254); - $red=hexdec(substr($this->Maketransparent[2],1,2));$green=hexdec(substr($this->Maketransparent[2],3,2));$blue=hexdec(substr($this->Maketransparent[2],5,2)); - $transparentcolor=imagecolorallocate($this->thumb,$red,$green,$blue); - $tolerance=sqrt(pow($this->Maketransparent[3],2)+pow($this->Maketransparent[3],2)+pow($this->Maketransparent[3],2)); - for ($y=0;$y<$this->thumby;$y++) { - for ($x=0;$x<$this->thumbx;$x++) { - $pixel=ImageColorAt($this->thumb,$x,$y); - $redpix=($pixel >> 16 & 0xFF);$greenpix=($pixel >> 8 & 0xFF);$bluepix=($pixel & 0xFF); - if (sqrt(pow($redpix-$red,2)+pow($greenpix-$green,2)+pow($bluepix-$blue,2))<$tolerance) - imagesetpixel($this->thumb,$x,$y,$transparentcolor); - } - } - imagecolortransparent($this->thumb,$transparentcolor); - if ($this->Maketransparent[1]==0) {$this->size[2]=3;} else {$this->size[2]=1;} - - } - - /** - * Create a animated PNG image - * - * @param array $frames - * @param string $output - * @param string $delay - */ - public function Create_apng($frames, $outputFilename, $delay) { - - $imageData = array(); - $IHDR = array(); - $sequenceNumber = 0; - foreach ($frames as $frame) { - if (file_exists($frame)) { - $fh = fopen($frame,'rb'); - $chunkData = fread($fh, 8); - $header = unpack("C1highbit/"."A3signature/". "C2lineendings/"."C1eof/"."C1eol", $chunkData); - if (is_array($header) && $header['highbit'] == 0x89 && $header['signature'] == "PNG") { - $IDAT=''; - while (!feof($fh)) { - $chunkData = fread($fh, 8); - $chunkDataHeader = unpack ("N1length/A4type", $chunkData); - switch ($chunkDataHeader['type']) { - case 'IHDR': - if (count($IHDR) == 0) { - $chunkData = fread($fh, $chunkDataHeader['length']); - $IHDR = unpack("N1width/"."N1height/". "C1bits/"."C1color/"."C1compression/"."C1prefilter/"."C1interlacing", $chunkData); - fseek($fh, 4, SEEK_CUR); - } else { - fseek($fh, $chunkDataHeader['length'] + 4, SEEK_CUR); - } - break; - case 'IDAT': - $IDAT .= fread($fh, $chunkDataHeader['length']); - fseek($fh, 4, SEEK_CUR); - break; - case 'IEND'; - break 2; - default: - fseek($fh, $chunkDataHeader['length'] + 4, SEEK_CUR); - break; - } - } - fclose($fh); - $imageData[] = $IDAT; - } else { - fclose($fh); - } - } - } - $pngHeader = "\x89\x50\x4E\x47\x0D\x0A\x1A\x0A"; - $IHDR_chunk = $this->create_chunk('IHDR', pack('NNCCCCC', $IHDR['width'], $IHDR['height'], $IHDR['bits'], $IHDR['color'], $IHDR['compression'], $IHDR['prefilter'], $IHDR['interlacing'])); - $acTL_chunk = $this->create_chunk('acTL', pack("NN", count($imageData), 0)); - $data = $this->create_fcTL($sequenceNumber, $IHDR['width'], $IHDR['height'], $delay); - $fcTL_chunk = $this->create_chunk('fcTL', $data); - $sequenceNumber += 1; - if (count($imageData) == 1) {$acTL_chunk = $fcTL_chunk = '';} - $fh = fopen($outputFilename, 'w'); - foreach ($imageData as $key => $image) { - if ($key == 0) { - $firstFrame = $this->create_chunk('IDAT', $image); - fwrite($fh, $pngHeader . $IHDR_chunk . $acTL_chunk . $fcTL_chunk . $firstFrame); - } else { - $data = $this->create_fcTL($sequenceNumber, $IHDR['width'], $IHDR['height'], $delay); - $fcTL_chunk = $this->create_chunk('fcTL', $data); - $sequenceNumber += 1; - $data = pack("N", $sequenceNumber); - $data .= $image; - $fdAT_chunk = $this->create_chunk('fdAT', $data); - $sequenceNumber += 1; - fwrite($fh, $fcTL_chunk . $fdAT_chunk); - } - } - fwrite($fh, $this->create_chunk('IEND')); - fclose($fh); - - } - - /** - * Create a PNG binary chunk - * - * @param array $type - * @param string $data - */ - private function create_chunk($type, $data = '') { - - $chunk = pack("N", strlen($data)) . $type . $data . pack("N", crc32($type . $data)); - return $chunk; - - } - - /** - * Create a PNG fcTL binary chunk - * - * @param array $frameNumber - * @param string $width - * @param string $height - * @param string $delay - */ - private function create_fcTL($frameNumber, $width, $height, $delay) { - - $fcTL = array(); - $fcTL['sequence_number'] = $frameNumber; - $fcTL['width'] = $width; - $fcTL['height'] = $height; - $fcTL['x_offset'] = 0; - $fcTL['y_offset'] = 0; - $fcTL['delay_num'] = $delay; - $fcTL['delay_den'] = 1000; - $fcTL['dispose_op'] = 0; - $fcTL['blend_op'] = 0; - $data = pack("NNNNN", $fcTL['sequence_number'], $fcTL['width'], $fcTL['height'], $fcTL['x_offset'], $fcTL['y_offset']); - $data .= pack("nn", $fcTL['delay_num'], $fcTL['delay_den']); - $data .= pack("cc", $fcTL['dispose_op'], $fcTL['blend_op']); - return $data; - - } - - /** - * Save thumbnail to file - * - */ - private function savethumb() { - - if ($this->Thumbsaveas!='') { - switch (strtolower($this->Thumbsaveas)) { - case "gif": - $this->image=substr($this->image,0,strrpos($this->image,'.')).".gif"; - $this->size[2]=1; - break; - case "jpg": - $this->image=substr($this->image,0,strrpos($this->image,'.')).".jpg"; - $this->size[2]=2; - break; - case "jpeg": - $this->image=substr($this->image,0,strrpos($this->image,'.')).".jpeg"; - $this->size[2]=2; - break; - case "png": - $this->image=substr($this->image,0,strrpos($this->image,'.')).".png"; - $this->size[2]=3; - break; - } - } - if ($this->Thumbfilename!='') { - $this->image=$this->Thumbfilename; - } - switch($this->size[2]) { - case 1: - imagegif($this->thumb,$this->Thumblocation.$this->Thumbprefix.basename($this->image)); - break; - case 2: - imagejpeg($this->thumb,$this->Thumblocation.$this->Thumbprefix.basename($this->image),$this->Quality); - break; - case 3: - imagepng($this->thumb,$this->Thumblocation.$this->Thumbprefix.basename($this->image)); - break; - } - if ($this->Chmodlevel!='') {chmod($this->Thumblocation.$this->Thumbprefix.basename($this->image),octdec($this->Chmodlevel));} - imagedestroy($this->im); - imagedestroy($this->thumb); - - } - - /** - * Display thumbnail on screen - * - */ - private function displaythumb() { - - switch($this->size[2]) { - case 1: - header("Content-type: image/gif");imagegif($this->thumb); - break; - case 2: - header("Content-type: image/jpeg");imagejpeg($this->thumb,'',$this->Quality); - break; - case 3: - header("Content-type: image/png");imagepng($this->thumb); - break; - } - imagedestroy($this->im); - imagedestroy($this->thumb); - exit; - - } - -} - -?> diff --git a/functions/filters.php b/functions/filters.php new file mode 100644 index 0000000..4584449 --- /dev/null +++ b/functions/filters.php @@ -0,0 +1,47 @@ +post_type == 'comic') { + $content = '

'. ceo_display_comic_thumbnail('full', $post) . '

' . $content; + } + return apply_filters('ceo_insert_comic_into_feed', $content); +} + +function ceo_insert_comic_into_archive($content) { + global $wp_query, $post; + if (is_archive() || is_search() && ($post->post-type == 'comic') && !is_single() && !is_feed()) { + $content = '

'.ceo_display_comic_thumbnail('medium', $post) . '

' . $content; + } + return apply_filters('ceo_insert_comic_into_archive', $content); +} + +function ceo_change_prev_rel_link_two($object) { + global $post, $wp_query; + if ($post->post_type=='comic' || is_home()) $link=''."\r\n"; + return $link; +} + +function ceo_change_next_rel_link_two($object) { + global $post; + if ($post->post_type=='comic') $link=''."\r\n"; + return $link; +} + + diff --git a/functions/injections.php b/functions/injections.php index 9e80148..bfb35cd 100644 --- a/functions/injections.php +++ b/functions/injections.php @@ -1,7 +1,7 @@ post_type == 'comic') { - $before = '
Chapter: '; + $before = '
Story: '; $sep = ', '; $after = '
'; $post_category = get_the_term_list( $post->ID, 'chapters', $before, $sep, $after ); } - return apply_filters('ceo_display_comic_chapters', $post_category); + echo apply_filters('ceo_display_comic_chapters', $post_category); } -add_action('easel-content-area', 'ceo_display_comic_area'); +// var_dump(ceo_pluginfo('disable_comic_on_home_page')); -function ceo_display_comic_area() { - global $wp_query, $post; - if (is_single()) { - ceo_display_comic_wrapper(); - } /* else { - if (is_home() && !is_paged()) { - Protect(); - $comic_args = array( - 'posts_per_page' => 1, - 'post_type' => 'comic' - ); - $wp_query->in_the_loop = true; $comicFrontpage = new WP_Query(); $comicFrontpage->query($comic_args); - while ($comicFrontpage->have_posts()) : $comicFrontpage->the_post(); - ceo_display_comic_wrapper(); - endwhile; - UnProtect(); - } - } */ + +add_action('comic-area', 'ceo_display_comic_area'); + +if (!function_exists('ceo_display_comic_navigation')) { + function ceo_display_comic_navigation() { + global $post, $wp_query; + + $first_comic = ceo_get_first_comic_permalink(); + $first_text = __('‹‹ First','easel'); + $last_comic = ceo_get_last_comic_permalink(); + $last_text = __('Last ››','easel'); + $next_comic = ceo_get_next_comic_permalink(); + $next_text = __('Next ›','easel'); + $prev_comic = ceo_get_previous_comic_permalink(); + $prev_text = __('‹ Prev','easel'); + ?> + + + + + + + + + + + + + + + + + + + + + +
()
+ ID); + $thumbnail = wp_get_attachment_image_src( $post_image_id, 'full', false); + if (is_array($thumbnail)) { + $thumbnail = reset($thumbnail); + echo $thumbnail; + } + ?> +
+ post_type == 'comic') { ?>
-
+
+ +
+
+
+
@@ -63,26 +102,7 @@ function ceo_display_comic_wrapper() { in_the_loop = true; $comicFrontpage = new WP_Query(); $comicFrontpage->query('post_type=comic&showposts=1'); - while ($comicFrontpage->have_posts()) : $comicFrontpage->the_post(); - easel_display_post(); - endwhile; - } - if (is_home()) { ?> -
- post_type == 'comic')) - $post_thumbnail = '

'. ceo_display_comic_thumbnail('medium', $post, true) . '

'; - return $post_thumbnail; -} - -add_action('easel-display-the-content-archive-before', 'ceo_inject_thumbnail_into_archive_posts'); +// add_action('easel-display-the-content-archive-before', 'ceo_inject_thumbnail_into_archive_posts'); // add_action('easel-display-the-content-before', 'ceo_inject_thumbnail_into_archive_posts'); - function ceo_inject_thumbnail_into_archive_posts() { global $post; if ($post->post_type == 'comic') { @@ -132,20 +140,23 @@ function ceo_inject_thumbnail_into_archive_posts() { // Inject into the menubar some mini navigation -add_action('easel-menubar-mini-navigation', 'ceo_inject_mini_navigation'); +add_action('comic-mini-navigation', 'ceo_inject_mini_navigation'); function ceo_inject_mini_navigation() { global $post; $next_comic = $prev_comic = ''; + if (is_home() && !is_paged()) { $wp_query->in_the_loop = true; $comicFrontpage = new WP_Query(); $comicFrontpage->query('post_type=comic&showposts=1'); while ($comicFrontpage->have_posts()) : $comicFrontpage->the_post(); $next_comic = ceo_get_next_comic_permalink(); $prev_comic = ceo_get_previous_comic_permalink(); endwhile; - } elseif ($post->post_type == 'comic') { - $next_comic = ceo_get_next_comic_permalink(); - $prev_comic = ceo_get_previous_comic_permalink(); + } else { + if ($post->post_type == 'comic') { + $next_comic = ceo_get_next_comic_permalink(); + $prev_comic = ceo_get_previous_comic_permalink(); + } } if (!empty($next_comic) || !empty($prev_comic)) { $next_text = __('›','comiceasel'); @@ -161,4 +172,73 @@ function ceo_inject_mini_navigation() { } } +add_action('comic-blog-area', 'ceo_display_comic_post_home'); + +function ceo_display_comic_post_home() { + global $wp_query; + if (is_home() && !ceo_pluginfo('disable_comic_blog_on_home_page')) { + if (!is_paged()) { + $wp_query->in_the_loop = true; $comicFrontpage = new WP_Query(); $comicFrontpage->query('post_type=comic&showposts=1'); + while ($comicFrontpage->have_posts()) : $comicFrontpage->the_post(); + if (function_exists('comicpress_display_post')) { + comicpress_display_post(); + } elseif (function_exists('easel_display_post')) { + easel_display_post(); + } else ceo_display_comic_post(); + endwhile; + if (ceo_pluginfo('enable_comments_on_homepage')) { + $withcomments = 1; + comments_template('', true); + } + wp_reset_query(); + } + } +} + +function ceo_display_comic_post() { +global $post, $wp_query; ?> +
> +
+
+
+

+
+ +
+
+ +
+
+ '
Pages: ', 'after' => '
', 'next_or_number' => 'number')); ?> +
+
+ +
+
+
+
+
+query_vars['suppress_filters'] ) ) { + $post_type = get_query_var('post_type'); + if($post_type) : + $post_type = $post_type; + else: + $post_type = array('post','comic'); + $query->set('post_type',$post_type); + endif; + return $query; + } +} + ?> diff --git a/functions/library.php b/functions/library.php new file mode 100644 index 0000000..5b42eb7 --- /dev/null +++ b/functions/library.php @@ -0,0 +1,57 @@ + + + ID, 'chapters')); - if (empty($current_chapter) || is_null($current_chapter)) { - $current_chapter_id = 0; - } else { + $current_chapter = get_the_terms( $post->ID, 'chapters'); + $current_chapter_id = 0; + if (is_array($current_chapter) && ceo_pluginfo('navigate_only_chapters')) { + $current_chapter = reset($current_chapter); $current_chapter_id = $current_chapter->term_id; } return ceo_get_terminal_post_of_chapter($current_chapter_id, true); @@ -18,10 +18,10 @@ function ceo_get_first_comic_permalink() { function ceo_get_last_comic() { global $post; - $current_chapter = reset(get_the_terms( $post->ID, 'chapters')); - if (empty($current_chapter) || is_null($current_chapter)) { - $current_chapter_id = 0; - } else { + $current_chapter = get_the_terms( $post->ID, 'chapters'); + $current_chapter_id = 0; + if (is_array($current_chapter) && ceo_pluginfo('navigate_only_chapters')) { + $current_chapter = reset($current_chapter); $current_chapter_id = $current_chapter->term_id; } return ceo_get_terminal_post_of_chapter($current_chapter_id, false); @@ -33,7 +33,7 @@ function ceo_get_last_comic_permalink() { } function ceo_get_previous_comic() { - return ceo_get_adjacent_comic(true, true); + return ceo_get_adjacent_comic(true, ceo_pluginfo('navigate_only_chapters')); } function ceo_get_previous_comic_permalink() { @@ -47,7 +47,7 @@ function ceo_get_previous_comic_permalink() { } function ceo_get_next_comic() { - return ceo_get_adjacent_comic(false, true); + return ceo_get_adjacent_comic(false, ceo_pluginfo('navigate_only_chapters')); } function ceo_get_next_comic_permalink() { diff --git a/functions/redirects.php b/functions/redirects.php new file mode 100644 index 0000000..8478793 --- /dev/null +++ b/functions/redirects.php @@ -0,0 +1,62 @@ + 1, + 'post_type' => 'comic', + 'orderby' => 'post_date', + 'order' => 'DESC', + 'post_status' => 'publish', + 'chapters' => $this_chapter->slug + ); + $qposts = get_posts( $args ); + if (is_array($qposts)) { + $qposts = reset($qposts); + wp_redirect( get_permalink( $qposts->ID ) ); + } else { + wp_redirect( bloginfo('url') ); + } + } else { + $args = array( + 'numberposts' => 1, + 'post_type' => 'comic', + 'orderby' => 'post_date', + 'order' => 'DESC', + 'post_status' => 'publish' + ); + $qposts = get_posts( $args ); + if (is_array($qposts)) { + $qposts = reset($qposts); + wp_redirect( get_permalink( $qposts->ID ) ); + } + } + wp_reset_query(); + exit; +} + +function ceo_random_comic() { + $args = array( + 'numberposts' => 1, + 'post_type' => 'comic', + 'orderby' => 'rand', + 'post_status' => 'publish' + ); + $qposts = get_posts( $args ); + if (is_array($qposts)) { + $qposts = reset($qposts); + wp_redirect( get_permalink( $qposts->ID ) ); + } + exit; +} + +?> \ No newline at end of file diff --git a/functions/shortcodes.php b/functions/shortcodes.php new file mode 100644 index 0000000..86dad81 --- /dev/null +++ b/functions/shortcodes.php @@ -0,0 +1,198 @@ +'; + $cast_output .= '
'; + $cast_output .= '
'; + $cast_output .= '
'; + $cast_output .= '

'.$character->name.'

'; + $cast_output .= '

'; + $cast_output .= $character->description; + $cast_output .= '

'; + $cast_output .= '

'; + $cast_output .= ''.__('Comics:','comiceasel').' '.$character->count.'
'; + $args = array( + 'numberposts' => 1, + 'post_type' => 'comic', + 'orderby' => 'post_date', + 'order' => 'ASC', + 'post_status' => 'publish', + 'characters' => $character->slug, + ); + $qposts = get_posts( $args ); + if (!empty($qposts)) { + $first_seen = $qposts[0]->post_title; + $first_seen_id = $qposts[0]->ID; + $cast_output .= ''.__('First Appearance:','comiceasel').' '.$first_seen.'
'; + } + wp_reset_query(); + $cast_output .= '

'; + $cast_output .= '
'; + $cast_output .= '
'; + $cast_output .= '
'; + } + } else { + $cast_output = __('You do not have any characters yet.','comiceasel'); + } + return $cast_output; +} + +function ceo_comic_archive_multi( $atts, $content = null ) { +extract( shortcode_atts( array( + 'list' => 0, + 'style' => 0, + 'chapter' => 0, + 'thumbnail' => 0, + 'order' => 'ASC' + ), $atts ) ); + switch ($list) { + case 1: + ceo_archive_list_series($thumbnail); + break; + case 0: + default: + if ($chapter) { + ceo_archive_list_single($chapter, $order, $thumbnail); + } else { + ceo_archive_list_all($order, $thumbnail); + } + break; + } +} + +function ceo_archive_list_single($chapter = 0, $order = 'ASC', $thumbnail = 0) { + $output = ''; + // get chapter from ID# + $single_chapter = get_term_by('term_id', $chapter, 'chapters'); + if (is_null($single_chapter)) { echo "Invalid Chapter Specified"; return; } + $output .= '
'; + $output .= '

'.$single_chapter->name.'

'; + $output .= '
'; + $output .= '
'.$single_chapter->description.'
'; + $args = array( + 'numberposts' => -1, + 'post_type' => 'comic', + 'orderby' => 'post_date', + 'order' => $order, + 'post_status' => 'publish', + 'chapters' => $single_chapter->slug + ); + $qposts = get_posts( $args ); + $archive_count = 0; + if ($thumbnail) { + $output .= '
'.get_the_post_thumbnail($qposts[0]->ID, 'thumbnail').'
'; + } + $output .= '
'; + $css_alt = false; + foreach ($qposts as $qpost) { + $archive_count++; + if ($css_alt) { $alternate = ' comic-list-alt'; $css_alt = false; } else { $alternate = ''; $css_alt=true; } + $output .= '
'.get_the_time('M d, Y', $qpost->ID).''.$qpost->post_title.'
'; + } + $output .= '
'; + $output .= '
'; + wp_reset_query(); + echo apply_filters('ceo_archive_list_single', $output); +} + +function ceo_archive_list_all($order = 'ASC', $thumbnail = 0) { + $output = ''; + $all_chapters = get_terms('chapters'); + if (is_null($all_chapters)) { echo 'There are no chapters available.'; return; } + $output = ''; + foreach ($all_chapters as $chapter) { + if ($chapter->count) { + $output .= '
'; + $output .= '

'.$chapter->name.'

'; + $output .= '
'; + $output .= '
'.$chapter->description.'
'; + $args = array( + 'numberposts' => -1, + 'post_type' => 'comic', + 'orderby' => 'post_date', + 'order' => $order, + 'post_status' => 'publish', + 'chapters' => $chapter->slug + ); + $qposts = get_posts( $args ); + $archive_count = 0; + if ($thumbnail) { + $output .= '
'.get_the_post_thumbnail($qposts[0]->ID, 'thumbnail').'
'; + } + $output .= '
'; + $css_alt = false; + foreach ($qposts as $qpost) { + $archive_count++; + if ($css_alt) { $alternate = ' comic-list-alt'; $css_alt = false; } else { $alternate = ''; $css_alt=true; } + $output .= '
'.get_the_time('M d, Y', $qpost->ID).''.$qpost->post_title.'
'; + } + $output .= '
'; + $output .= '
'; + } + } + wp_reset_query(); + echo apply_filters('ceo_archive_list_all', $output); +} + +function ceo_archive_list_series($thumbnail = 0) { + $output = ''; + $archive_count = 0; + $args = array( + 'pad_counts' => 0, + 'orderby' => 'id', + 'order' => 'DESC', + 'hide_empty' => 0, + 'parent' => 0 + ); + $parent_chapters = get_terms( 'chapters', $args ); + if (is_array($parent_chapters)) { + foreach($parent_chapters as $parent_chapter) { + $output .= '

'.$parent_chapter->name.'

'; + $output .= '
'; + $output .= '
'.$parent_chapter->description.'
'; + $child_chapters = get_term_children( $parent_chapter->term_id, 'chapters' ); + foreach ($child_chapters as $child) { + $child_term = get_term_by( 'id', $child, 'chapters' ); + if ($child_term->count) { + $output .= '
'; + $output .= '

'.$child_term->name.'

'; + $output .= '
'; + $output .= '
'.$child_term->description.'
'; + $child_args = array( + 'numberposts' => -1, + 'post_type' => 'comic', + 'orderby' => 'post_date', + 'order' => 'ASC', + 'post_status' => 'publish', + 'chapters' => $child_term->slug + ); + $qcposts = get_posts( $child_args ); + if ($thumbnail) { + $output .= '
'.get_the_post_thumbnail($qcposts[0]->ID, 'thumbnail').'
'; + } + $output .= '
'; + $css_alt = false; + foreach ($qcposts as $qcpost) { + $archive_count++; + if ($css_alt) { $alternate = ' comic-list-alt'; $css_alt = false; } else { $alternate = ''; $css_alt=true; } + $output .= '
'.get_the_time('M d, Y', $qcpost->ID).''.$qcpost->post_title.'
'; + } + $output .= '
'; + $output .= '
'; + } + } + } + echo $output; + } +} + +?> \ No newline at end of file diff --git a/functions/uploader.php b/functions/uploader.php deleted file mode 100644 index 59a1194..0000000 --- a/functions/uploader.php +++ /dev/null @@ -1,86 +0,0 @@ -false); - } - - $size = $file->getSize(); - if ($size == 0){ - return array(success=>false, error=>"File is empty."); - } - if ($size > $maxFileSize){ - return array(success=>false, error=>"File is too large."); - } - - $pathinfo = pathinfo($file->getName()); - $filename = $pathinfo['filename']; - $ext = $pathinfo['extension']; - - // if you limit file extensions on the client side, - // you should check file extension here too - - while (file_exists(ceo_pluginfo('comic_path') .'/'. $filename . '.' . $ext)){ - $filename .= rand(10, 99); - } - - $file->save(ceo_pluginfo('comic_path') .'/'. $filename . '.' . $ext); - - if (preg_match("/jpg|jpeg|gif|png/i", $ext)){ - //generate medium comic image - $thumb = new easyphpthumbnail; - $thumb -> Thumbwidth = ceo_pluginfo('medium_comic_width'); - $thumb -> Thumblocation = ceo_pluginfo('thumbnail_medium_path') .'/'; - $thumb -> Thumbprefix = ''; - $thumb -> Createthumb(ceo_pluginfo('comic_path') .'/'. $filename . '.' . $ext,'file'); - - //generate small comic image - $thumb -> Thumbwidth = ceo_pluginfo('small_comic_width'); - $thumb -> Thumblocation = ceo_pluginfo('thumbnail_small_path') .'/'; - $thumb -> Thumbprefix = ''; - $thumb -> Createthumb(ceo_pluginfo('comic_path') .'/'. $filename . '.' . $ext,'file'); - } - add_post_meta($_GET[post_id], 'comic', $filename . '.' . $ext, false); - - return array(success=>true); -} - diff --git a/images/easel_small.png b/images/easel_small.png new file mode 100644 index 0000000000000000000000000000000000000000..01159b436dd72392950c65855e530bf13a6bff1f GIT binary patch literal 5657 zcmV+!7Ut=RP)TZbA#6PI=NBDc9MBuTCzFW& zNx#B<>%tcw z+4=L#6xDZL{Eu(^^RwT2{5j$yZc^mxv6jx3h51F8M>4E<0Ftw(sd62gVl~o)+$FMg z>XfG*eL%H$_aFI57)Wrw4|{X8^(xs4K~Z%Ho_) z(}dh5{DGj|z2F20hCn3b12{a8DiMK3Db2rWnP8~%e8<3SW||5XoNjO|IzgdP!1jjH zEw|`dG$FS~NXQ!shr=$18?KHTAr^^3vLXr6Q<85L|Bjq$>uqN;m>?GLVQO|BgI*Tw zYOGL8#e!WlA$I}0%QI)SIeesI8DfS}9fHSDc#^i+1#lo){Q2LP2gCm@Eqb z9v@T`WWuJ(!UyoWfF|Tl32}NX(lR<7M?NiVmNA z`^u#d5-5`hVRmjI{$)c&fe`&qGfl{y!)!2F4L)B0-2f8_2@{0~>1iq%i^)v8MY+hu zo@>WD2gk{8!D6!mc>S<0D+TJx))7r2qzSn*SZ6H@Mn4ildWhQ_h<~X~mT^S_-Ytb5 zMq8(ko$i=OQOS{uAk3rL;$nohYjb%m=`1uMcNl0nT%Oqg_6z}^i&3vHK8}){Bm#Mo zDCI-Sj-P7lJ0A#yK!N^4KW&MZ-Bwq^&C#hJqzSo0pq8)@)h!YUAP@)whFYLNLh#AY z{;;zBC=xsR^{_4{4J@eMLnsz=GquoETe9^-d=O2@&EWF*O&DqUB^d68QFTW#Y7&YC zpjF9|@$xN4phJssGI4q6>7W)+eUt;yr9rMFF#{Fl#SO$eqFK_WFHX4jbDtg3dY| zSKd06oR}QNhZP>s8;_ptxEd@paw;g=r?H&%6uPn}9(lXH)>}je>l}be0mtHW&k%33n9}^*~^~TUS zIXiC-M8jGE3x!8B4XLz!vs=64! z?IEKpP?(`4n&h*68^2>P&Ei_Q8H+< zN?>PU3FPHu0-Cb-Y*uAuWfnzI72$B0Cgesyn*;$2b3>u9&4vxHM1kjWqc{wQ@mz$8 zU79hDf={JVf!S<^vV!#HOidD8Z0m+GlO6OHFZ=Uf`qIB_+_Z@**-*;RXj4HcmmzUC zuCJ`DjG2*IJIlTI@ zF-vc6Z$c_7FE0lao1dh0$aVP2BRk(aXH!hL*gfcJZ*PYkJ9eyi-BPKP)Uy%mBlCzy zXhINMYl^S4>ug{|L$>j2{owL=K`dPP5P0+E%|x|VqH3oJA^717N8URRhoit@!C=LP zBG8YHKzUi&ir0@O3vzODY6k}gU!n;?bPbGu;BSp0$+b(uj*SlXF%m(DMx%k!($Y#K zgv@mG&`y0BJidTkqg4bf(|TAStD_Qt+S*#8+6(9?>jrRn{fjIX%P(R2VQR{dkUDE> zYUER*D4_}YL&OX-^Cm8f0tq_|24iCUNPT_1 zSfNlf(1hFoMzdA#^aMa7=fT)$V*Cgh{l#8Frk-+WLYBeq@=lu;9I?DKCCtxELM#Dw zve|4h`b*X)7SV((Lm(J3&CFWe87ax&w9SBd&X$mR%gf7^TrM}CCgcX8@3_Hi=gFmz zLz#%;Rcyh3;~xFthU7XkXtEltQWSQlO5S(_cQ(zTGACWDEw#5i`LP)L?6 zkYN-JP00J;21DUuo81j8g%oN_b79snPL_-$1RFPQ%x5qd6*M8&1w3U1nR!ey$JFHo zrC10)y9F$B)uMPX`UG$Hj<6h)?*k{4FFG$Dv&c~W6vP8!(VJ_tpl zz~^#7Efa#-Fb3fS`4J>U!{_rWX+jV>tuj4brvazOOHu&FQ)YnMKTV@ZQ^+OprEX5AC%!OLDHef(>xAKJL!e7t`J6IJ zrIIXtEAQ*;BX1Gi?|iN0^EjJRRdOwh#p0Oe7938GuLZx?uNgwp)bD4`AXywJ7E7Iz zrp^|N1R&yZz`Wpqbo>p;KB|=Rz&Jtv?@bB0x9aNZ`~wFLkYN;GMoRMM_H3=%y}7!$ zK)|LLB-?~YDu#c1{_yYd`tCJD$bqBh-aC&(J;gkk0`J62jw9@oaM>1yjsF4YRW*$jeS&@p}sco4s>u{e~y^ z)q{Y|g=v!&beSn68#nf3W_;B`K~A~``bLdQ$!IX#b@_r&l$i|e;~)Qf_C*XH&YwFASK7}3KWu}_JT;Uz zRD(>K1VJ>BZ0w~>J`X}ZKXhLihQn{Q&%D;sd2)Ds=D-VUm=IQWx+aT_PhkJ(6l7&+ z(S%Xp!(JjrpF$cfFEbTRUF`$YoDH-p#a&l8k3j<=qW97nP;ou*>9Q;+$}0mlmj|(M zBpz~elhBu07vaq5j_AQR-oAYLV*eq#%R^>~ulR`PY7-*M)~Pf6;cz_P2}$`!>@+c3 ze0(|`E)Nvsro><7y--|>9;E{%0D9p=1lf+v30m9++ z!O++YwDt_!51+hrrlVi~QZyPRo5ncStPWX*tfCxUrXL+TNjJ`5vEbUI2^%UM^3Z%) zt#&d!1S1?V7{*5dwtO@~h{){h>W22#7Vujqpg=2x9ourFx>ODJ1oYBmFca&XoH9Xs z-zXT-iTlxa?SJLes}s|6Pu&;7@OtpMoV?sjZIajHBWanyYIDTScMeR}m*po{7G#Qo z*mEEdhWu0|yfHWdzF-9S9M)}^B|BU=e*yY0x5oWL%{mQKG}eJ6DG9GKVkC7?45PiF zQDf}b*~=JK2N~%a1vJ;Lhq4WMFlI0pPE5Cu4Q8D86(Kr}Vm%RxCbKQRYfk6Tgs1n~ z)P4*%9})6-#U#hO3&~2+C?VX@4JMNbvNLX+{F*G}y*6?U-agj?#<2mAQ$E;Tk_n}S z8-T;*hw%q2peRPr=Vx8&90|X8ymk1s(;Y9Ht#q>6l7?XXy2nCP1Ax#NoG=78Uy@A3cU_=T=>9Ro+* zUjHGyLS}ah-aK>p!KXgexQ#;X6G0u+R9(y}$xq+iKVrDA2vHa3>I!%i6&GEBNCbL@ zCdmAs5tG&7j$zziQnn6U*pTPWc0p_V6;L~bu&aI~e<^P6KAPF=n__96Oa;qGSwvE^O)l^ zb5LEk0h(&oHzOe=rPIXyLP&0QhBlp_EQ7|4r7&$-gx;ZvJ`&L^I@}fu5;1sf3fit* z1CkHriGADQt$CJcu; z95xGV3r=vOM$ssx=%6#>8L*?lFhtPAQ79rA91dW2g3}lKV!wR#Oxu}DS6>K6BCnHR z>m%OU_Fp{v)nm;KrM!W`aoDqGGd%O7U(bK%xr3j;YgaxPK*ZK8A@5@Mw%YaI{F^U4 z)YOO$brPc;J?aqwMm!`6OI6D-+~trB#ZZ<|z$TlCAq)mH96r_VK5*phar8eVIoavE z5OJKHo63&9_~UOqaQ*~ zZWJ+5jBs4RU+f(Ty!=LM+qurc-v)xAmXCXEDG&;uJbdD!{vW^k+1xhleI!iVy}7Ik z38}$9&fX70Cj_DHzR_Vmld=2phqi(jbw}rw5%9*M5J3~w)jbSXh9?099Q^v|*%vVS z`YS9GT%miJJl=Bo#Mhp9FjpYt!OXM;w$^PBs^m#ca|@39h7iyjOs9YHe{VdzqoFjJ z$zrl&(J1TC@wXY%=&VI(#;Vrm#E0hFdagx~kl>2mi_v_ft!wBnsy5{D#;})csVjlH zvi!!^S~>;So2?bYYVD`Kd>9^&OguJm*wjvpwjSGBSJE?l;-|4d-@#aH^hhi^bSU;G z4>XXln7hJF!uw=X)v1}*{jsAz{o7b{@Risvp7}CK!Lcn7ZFa9rB_(+mC-G@*d5Z75sed-1ni?0a<-6}}vUiqR<(>~5|RVBHDX zEask>{k|L)tKCk7UN(wD@_s!o?R9E0Lw&`!?DhtNCtg2ud9n({VLH}-ZETt>OijqV zR_b0QWWnJwE;v1qo~Z@zqANbgs8A#cSWKpJ`9z78a3!xCZ#|NeqI}Zf@;d+Pr4z3& zINbkpUlX$E^q7p6g-98L!6Fmt$T*c+A>|7ATooCTUujIv%zf|6-+lhSVJU&Xc?Bc8 zKMs?He#BsynX`vHey};0CK4(nLbB~@N`h{|jt7}tVMr7i_cS30YdP2CQM+%Y@ib2TZWZ>sAH>;_uysd{9UwD!6XfFPe}9hQj(ulium|1Bc57 zUmyTnJ{MF937L5SgEg_QIVDNV>Kz~%AJx?G+hpTh>1 z*GJYb5OGL)ND58JDj*z*nCIs09v+VaZnBdbki8C*_!Nt&pb1$WmSsnQ7PWK!O!(OucXE+cv?YfQR`=R)+-%uFFb$nDcKr~R#+ud~?v-gkw}O<<. - */ - -var qq = qq || {}; - -/** - * Class that creates our multiple file upload widget - */ -qq.FileUploader = function(o){ - this._options = { - // container element DOM node (ex. $(selector)[0] for jQuery users) - element: null, - // url of the server-side upload script, should be on the same domain - action: '/server/upload', - // additional data to send, name-value pairs - params: {}, - // ex. ['jpg', 'jpeg', 'png', 'gif'] or [] - allowedExtensions: [], - // size limit in bytes, 0 - no limit - // this option isn't supported in all browsers - sizeLimit: 0, - onSubmit: function(id, fileName){}, - onComplete: function(id, fileName, responseJSON){}, - - // - // UI customizations - - template: '
' + - '
Drop files here to upload
' + - '
Upload a file
' + - '
    ' + - '
    ', - - // template for one item in file list - fileTemplate: '
  • ' + - '' + - '' + - '' + - 'Cancel' + - 'Failed' + - '
  • ', - - classes: { - // used to get elements from templates - button: 'qq-upload-button', - drop: 'qq-upload-drop-area', - dropActive: 'qq-upload-drop-area-active', - list: 'qq-upload-list', - - file: 'qq-upload-file', - spinner: 'qq-upload-spinner', - size: 'qq-upload-size', - cancel: 'qq-upload-cancel', - - // added to list item when upload completes - // used in css to hide progress spinner - success: 'qq-upload-success', - fail: 'qq-upload-fail' - }, - messages: { - //serverError: "Some files were not uploaded, please contact support and/or try again.", - typeError: "{file} has invalid extension. Only {extensions} are allowed.", - sizeError: "{file} is too large, maximum file size is {sizeLimit}.", - emptyError: "{file} is empty, please select files again without it." - }, - showMessage: function(message){ - alert(message); - } - }; - - qq.extend(this._options, o); - - this._element = this._options.element; - - if (this._element.nodeType != 1){ - throw new Error('element param of FileUploader should be dom node'); - } - - this._element.innerHTML = this._options.template; - - // number of files being uploaded - this._filesInProgress = 0; - - // easier access - this._classes = this._options.classes; - - this._handler = this._createUploadHandler(); - - this._bindCancelEvent(); - - var self = this; - this._button = new qq.UploadButton({ - element: this._getElement('button'), - //multiple: qq.UploadHandlerXhr.isSupported(), - onChange: function(input){ - self._onInputChange(input); - } - }); - - this._setupDragDrop(); -}; - -qq.FileUploader.prototype = { - setParams: function(params){ - this._options.params = params; - }, - /** - * Returns true if some files are being uploaded, false otherwise - */ - isUploading: function(){ - return !!this._filesInProgress; - }, - /** - * Gets one of the elements listed in this._options.classes - * - * First optional element is root for search, - * this._element is default value. - * - * Usage - * 1. this._getElement('button'); - * 2. this._getElement(item, 'file'); - **/ - _getElement: function(parent, type){ - if (typeof parent == 'string'){ - // parent was not passed - type = parent; - parent = this._element; - } - - var element = qq.getByClass(parent, this._options.classes[type])[0]; - - if (!element){ - throw new Error('element not found ' + type); - } - - return element; - }, - _error: function(code, fileName){ - var message = this._options.messages[code]; - message = message.replace('{file}', this._formatFileName(fileName)); - message = message.replace('{extensions}', this._options.allowedExtensions.join(', ')); - message = message.replace('{sizeLimit}', this._formatSize(this._options.sizeLimit)); - this._options.showMessage(message); - }, - _formatFileName: function(name){ - if (name.length > 33){ - name = name.slice(0, 19) + '...' + name.slice(-13); - } - return name; - }, - _isAllowedExtension: function(fileName){ - var ext = (-1 !== fileName.indexOf('.')) ? fileName.replace(/.*[.]/, '').toLowerCase() : ''; - var allowed = this._options.allowedExtensions; - - if (!allowed.length){return true;} - - for (var i=0; i -1; - - // dt.effectAllowed is none in Safari 5 - // dt.types.contains check is for firefox - return dt && dt.effectAllowed != 'none' && - (dt.files || (!isWebkit && dt.types.contains && dt.types.contains('Files'))); - } - - var self = this, - dropArea = this._getElement('drop'); - - dropArea.style.display = 'none'; - - var hideTimeout; - qq.attach(document, 'dragenter', function(e){ - e.preventDefault(); - }); - - qq.attach(document, 'dragover', function(e){ - if (isValidDrag(e)){ - - if (hideTimeout){ - clearTimeout(hideTimeout); - } - - if (dropArea == e.target || qq.contains(dropArea,e.target)){ - var effect = e.dataTransfer.effectAllowed; - if (effect == 'move' || effect == 'linkMove'){ - e.dataTransfer.dropEffect = 'move'; // for FF (only move allowed) - } else { - e.dataTransfer.dropEffect = 'copy'; // for Chrome - } - qq.addClass(dropArea, self._classes.dropActive); - e.stopPropagation(); - } else { - dropArea.style.display = 'block'; - e.dataTransfer.dropEffect = 'none'; - } - - e.preventDefault(); - } - }); - - qq.attach(document, 'dragleave', function(e){ - if (isValidDrag(e)){ - - if (dropArea == e.target || qq.contains(dropArea,e.target)){ - qq.removeClass(dropArea, self._classes.dropActive); - e.stopPropagation(); - } else { - - if (hideTimeout){ - clearTimeout(hideTimeout); - } - - hideTimeout = setTimeout(function(){ - dropArea.style.display = 'none'; - }, 77); - } - } - }); - - qq.attach(dropArea, 'drop', function(e){ - dropArea.style.display = 'none'; - self._uploadFileList(e.dataTransfer.files); - e.preventDefault(); - }); - }, - _createUploadHandler: function(){ - var self = this, - handlerClass; - - //if(qq.UploadHandlerXhr.isSupported()){ - // handlerClass = 'UploadHandlerXhr'; - //} else { - handlerClass = 'UploadHandlerForm'; - //} - - var handler = new qq[handlerClass]({ - action: this._options.action, - onProgress: function(id, fileName, loaded, total){ - // is only called for xhr upload - self._updateProgress(id, loaded, total); - }, - onComplete: function(id, fileName, result){ - self._filesInProgress--; - - // mark completed - var item = self._getItemByFileId(id); - qq.remove(self._getElement(item, 'cancel')); - qq.remove(self._getElement(item, 'spinner')); - - if (result.success){ - qq.addClass(item, self._classes.success); - } else { - qq.addClass(item, self._classes.fail); - - if (result.error){ - self._options.showMessage(result.error); - } - } - - self._options.onComplete(id, fileName, result); - } - }); - - return handler; - }, - _onInputChange: function(input){ - - //if (this._handler instanceof qq.UploadHandlerXhr){ - // - // this._uploadFileList(input.files); - // - //} else { - - if (this._validateFile(input)){ - this._uploadFile(input); - } - - //} - - this._button.reset(); - }, - _uploadFileList: function(files){ - var valid = true; - - var i = files.length; - while (i--){ - if (!this._validateFile(files[i])){ - valid = false; - break; - } - } - - if (valid){ - var i = files.length; - while (i--){ this._uploadFile(files[i]); } - } - }, - _uploadFile: function(fileContainer){ - var id = this._handler.add(fileContainer); - var name = this._handler.getName(id); - if (false == this._options.onSubmit(id, name)) - return false; - this._addToList(id, name); - this._handler.upload(id, this._options.params); - }, - _validateFile: function(file){ - var name,size; - - if (file.value){ - // it is a file input - // get input value and remove path to normalize - name = file.value.replace(/.*(\/|\\)/, ""); - } else { - // fix missing properties in Safari - name = file.fileName != null ? file.fileName : file.name; - size = file.fileSize != null ? file.fileSize : file.size; - } - - if (! this._isAllowedExtension(name)){ - this._error('typeError',name); - return false; - - } else if (size === 0){ - this._error('emptyError',name); - return false; - - } else if (size && this._options.sizeLimit && size > this._options.sizeLimit){ - this._error('sizeError',name); - return false; - } - - return true; - }, - _addToList: function(id, fileName){ - var item = qq.toElement(this._options.fileTemplate); - item.qqFileId = id; - - var fileElement = this._getElement(item, 'file'); - qq.setText(fileElement, this._formatFileName(fileName)); - this._getElement(item, 'size').style.display = 'none'; - - this._getElement('list').appendChild(item); - - this._filesInProgress++; - }, - _updateProgress: function(id, loaded, total){ - var item = this._getItemByFileId(id); - var size = this._getElement(item, 'size'); - size.style.display = 'inline'; - - var text; - if (loaded != total){ - text = Math.round(loaded / total * 100) + '% from ' + this._formatSize(total); - } else { - text = this._formatSize(total); - } - - qq.setText(size, text); - }, - _formatSize: function(bytes){ - var i = -1; - do { - bytes = bytes / 1024; - i++; - } while (bytes > 99); - - return Math.max(bytes, 0.1).toFixed(1) + ['kB', 'MB', 'GB', 'TB', 'PB', 'EB'][i]; - }, - _getItemByFileId: function(id){ - var item = this._getElement('list').firstChild; - - // there can't be text nodes in our dynamically created list - // because of that we can safely use nextSibling - while (item){ - if (item.qqFileId == id){ - return item; - } - - item = item.nextSibling; - } - }, - /** - * delegate click event for cancel link - **/ - _bindCancelEvent: function(){ - var self = this, - list = this._getElement('list'); - - qq.attach(list, 'click', function(e){ - e = e || window.event; - var target = e.target || e.srcElement; - - if (qq.hasClass(target, self._classes.cancel)){ - qq.preventDefault(e); - - var item = target.parentNode; - self._handler.cancel(item.qqFileId); - qq.remove(item); - } - }); - - } -}; - -qq.UploadButton = function(o){ - this._options = { - element: null, - // if set to true adds multiple attribute to file input - multiple: false, - // name attribute of file input - name: 'file', - onChange: function(input){}, - hoverClass: 'qq-upload-button-hover', - focusClass: 'qq-upload-button-focus' - }; - - qq.extend(this._options, o); - - this._element = this._options.element; - - // make button suitable container for input - qq.css(this._element, { - position: 'relative', - overflow: 'hidden', - // Make sure browse button is in the right side - // in Internet Explorer - direction: 'ltr' - }); - - this._input = this._createInput(); -}; - -qq.UploadButton.prototype = { - /* returns file input element */ - getInput: function(){ - return this._input; - }, - /* cleans/recreates the file input */ - reset: function(){ - if (this._input.parentNode){ - qq.remove(this._input); - } - - qq.removeClass(this._element, this._options.focusClass); - this._input = this._createInput(); - }, - _createInput: function(){ - var input = document.createElement("input"); - - if (this._options.multiple){ - input.setAttribute("multiple", "multiple"); - } - - input.setAttribute("type", "file"); - input.setAttribute("name", this._options.name); - - qq.css(input, { - position: 'absolute', - // in Opera only 'browse' button - // is clickable and it is located at - // the right side of the input - right: 0, - top: 0, - zIndex: 1, - fontSize: '460px', - margin: 0, - padding: 0, - cursor: 'pointer', - opacity: 0 - }); - - this._element.appendChild(input); - - var self = this; - qq.attach(input, 'change', function(){ - self._options.onChange(input); - }); - - qq.attach(input, 'mouseover', function(){ - qq.addClass(self._element, self._options.hoverClass); - }); - qq.attach(input, 'mouseout', function(){ - qq.removeClass(self._element, self._options.hoverClass); - }); - qq.attach(input, 'focus', function(){ - qq.addClass(self._element, self._options.focusClass); - }); - qq.attach(input, 'blur', function(){ - qq.removeClass(self._element, self._options.focusClass); - }); - - // IE and Opera, unfortunately have 2 tab stops on file input - // which is unacceptable in our case, disable keyboard access - if (window.attachEvent){ - // it is IE or Opera - input.setAttribute('tabIndex', "-1"); - } - - return input; - } -}; - -/** - * Class for uploading files using form and iframe - */ -qq.UploadHandlerForm = function(o){ - this._options = { - // URL of the server-side upload script, - // should be on the same domain to get response - action: '/upload', - // fires for each file, when iframe finishes loading - onComplete: function(id, fileName, response){} - }; - qq.extend(this._options, o); - - this._inputs = {}; -}; -qq.UploadHandlerForm.prototype = { - /** - * Adds file input to the queue - * Returns id to use with upload, cancel - **/ - add: function(fileInput){ - fileInput.setAttribute('name', 'qqfile'); - var id = 'qq-upload-handler-iframe' + qq.getUniqueId(); - - this._inputs[id] = fileInput; - - // remove file input from DOM - if (fileInput.parentNode){ - qq.remove(fileInput); - } - - return id; - }, - /** - * Sends the file identified by id and additional query params to the server - * @param {Object} params name-value string pairs - */ - upload: function(id, params){ - var input = this._inputs[id]; - - if (!input){ - throw new Error('file with passed id was not added, or already uploaded or cancelled'); - } - - var fileName = this.getName(id); - - var iframe = this._createIframe(id); - var form = this._createForm(iframe, params); - form.appendChild(input); - - var self = this; - this._attachLoadEvent(iframe, function(){ - self._options.onComplete(id, fileName, self._getIframeContentJSON(iframe)); - - delete self._inputs[id]; - // timeout added to fix busy state in FF3.6 - setTimeout(function(){ - qq.remove(iframe); - }, 1); - }); - - form.submit(); - qq.remove(form); - - return id; - }, - cancel: function(id){ - if (id in this._inputs){ - delete this._inputs[id]; - } - - var iframe = document.getElementById(id); - if (iframe){ - // to cancel request set src to something else - // we use src="javascript:false;" because it doesn't - // trigger ie6 prompt on https - iframe.setAttribute('src', 'javascript:false;'); - - qq.remove(iframe); - } - }, - getName: function(id){ - // get input value and remove path to normalize - return this._inputs[id].value.replace(/.*(\/|\\)/, ""); - }, - _attachLoadEvent: function(iframe, callback){ - qq.attach(iframe, 'load', function(){ - // when we remove iframe from dom - // the request stops, but in IE load - // event fires - if (!iframe.parentNode){ - return; - } - - // fixing Opera 10.53 - if (iframe.contentDocument && - iframe.contentDocument.body && - iframe.contentDocument.body.innerHTML == "false"){ - // In Opera event is fired second time - // when body.innerHTML changed from false - // to server response approx. after 1 sec - // when we upload file with iframe - return; - } - - callback(); - }); - }, - /** - * Returns json object received by iframe from server. - */ - _getIframeContentJSON: function(iframe){ - // iframe.contentWindow.document - for IE<7 - var doc = iframe.contentDocument ? iframe.contentDocument: iframe.contentWindow.document, - response; - - try{ - response = eval("(" + doc.body.innerHTML + ")"); - } catch(err){ - response = {}; - } - - return response; - }, - /** - * Creates iframe with unique name - */ - _createIframe: function(id){ - // We can't use following code as the name attribute - // won't be properly registered in IE6, and new window - // on form submit will open - // var iframe = document.createElement('iframe'); - // iframe.setAttribute('name', id); - - var iframe = qq.toElement('