| @@ -1,8 +1,8 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | /* |
| 3 | 3 | Plugin Name: Image Source Control |
| 4 | - Version: 1.2 | |
| 4 | + Version: 1.3.2 | |
| 5 | 5 | Plugin URI: http://webgilde.com/en/image-source-control/ |
| 6 | 6 | Description: The Image Source Control saves the source of an image, lists them and warns if it is missing. |
| 7 | 7 | Author: Thomas Maier |
| 8 | 8 | Author URI: http://www.webgilde.com/ |
| @@ -37,9 +37,9 @@ | ||
| 37 | 37 | header('HTTP/1.1 403 Forbidden'); |
| 38 | 38 | exit(); |
| 39 | 39 | } |
| 40 | 40 | |
| 41 | -define('ISCVERSION', '1.2'); | |
| 41 | +define('ISCVERSION', '1.3.2'); | |
| 42 | 42 | define('ISCNAME', 'Image Source Control'); |
| 43 | 43 | define('ISCTEXTDOMAIN', 'isc'); |
| 44 | 44 | define('ISCDIR', basename(dirname(__FILE__))); |
| 45 | 45 | define('ISCPATH', plugin_dir_path(__FILE__)); |
| @@ -69,8 +69,13 @@ | ||
| 69 | 69 | ) |
| 70 | 70 | ); |
| 71 | 71 | |
| 72 | 72 | /** |
| 73 | + * Commonly used text elements | |
| 74 | + */ | |
| 75 | + protected $_common_texts = array(); | |
| 76 | + | |
| 77 | + /** | |
| 73 | 78 | * allowed image file types/extensions |
| 74 | 79 | * @since 1.1 |
| 75 | 80 | */ |
| 76 | 81 | protected $_allowedExtensions = array( |
| @@ -76,14 +81,11 @@ | ||
| 76 | 81 | protected $_allowedExtensions = array( |
| 77 | 82 | 'jpg', 'png', 'gif' |
| 78 | 83 | ); |
| 79 | 84 | |
| 80 | - protected $_upgrade_step = array( | |
| 81 | - '1.2' | |
| 82 | - ); | |
| 83 | - | |
| 84 | 85 | /** |
| 85 | 86 | * Thumbnail size in list of all images. |
| 87 | + * @since 1.2 | |
| 86 | 88 | */ |
| 87 | 89 | protected $_thumbnail_size = array('thumbnail', 'medium', 'large', 'custom'); |
| 88 | 90 | |
| 89 | 91 | /** |
| @@ -90,23 +92,38 @@ | ||
| 90 | 92 | * options saved in the db |
| 91 | 93 | * @since 1.2 |
| 92 | 94 | */ |
| 93 | 95 | protected $_options = array(); |
| 94 | - | |
| 96 | + | |
| 95 | 97 | /** |
| 98 | + * Position of image's caption | |
| 99 | + */ | |
| 100 | + protected $_caption_position = array( | |
| 101 | + 'top-left', | |
| 102 | + 'top-center', | |
| 103 | + 'top-right', | |
| 104 | + 'center', | |
| 105 | + 'bottom-left', | |
| 106 | + 'bottom-center', | |
| 107 | + 'bottom-right' | |
| 108 | + ); | |
| 109 | + | |
| 110 | + /** | |
| 96 | 111 | * Setup registers filterts and actions. |
| 97 | 112 | */ |
| 98 | 113 | public function __construct() |
| 99 | - { | |
| 100 | - | |
| 114 | + { | |
| 101 | 115 | // load all plugin options |
| 102 | 116 | $this->_options = get_option('isc_options'); |
| 117 | + $this->_common_texts['not_available'] = __('Not available', ISCTEXTDOMAIN); | |
| 103 | 118 | |
| 104 | 119 | // insert all function for the frontend here |
| 105 | 120 | |
| 106 | 121 | add_shortcode('isc_list', array($this, 'list_post_attachments_with_sources_shortcode')); |
| 107 | 122 | add_shortcode('isc_list_all', array($this, 'list_all_post_attachments_sources_shortcode')); |
| 108 | - | |
| 123 | + add_action('wp_enqueue_scripts', array($this, 'front_scripts')); | |
| 124 | + add_action('wp_head', array($this, 'front_head')); | |
| 125 | + add_action('the_content', array($this, 'content_filter')); | |
| 109 | 126 | // insert all backend functions below this check |
| 110 | 127 | if (!current_user_can('upload_files')) { |
| 111 | 128 | return false; |
| 112 | 129 | } |
| @@ -112,22 +129,103 @@ | ||
| 112 | 129 | } |
| 113 | 130 | |
| 114 | 131 | register_activation_hook(ISCPATH . '/isc.php', array($this, 'activation')); |
| 115 | 132 | |
| 133 | + add_action('add_attachment', array($this, 'attachment_added'), 10, 2); | |
| 116 | 134 | add_filter('attachment_fields_to_edit', array($this, 'add_isc_fields'), 10, 2); |
| 117 | 135 | add_filter('attachment_fields_to_save', array($this, 'isc_fields_save'), 10, 2); |
| 118 | 136 | |
| 137 | + add_action('admin_notices', array($this, 'admin_notices')); | |
| 138 | + | |
| 119 | 139 | add_action('admin_menu', array($this, 'create_menu')); |
| 120 | 140 | add_action('admin_init', array($this, 'SAPI_init')); |
| 121 | 141 | |
| 122 | 142 | add_action('admin_enqueue_scripts', array($this, 'add_admin_scripts')); |
| 143 | + add_action( 'admin_print_scripts', array($this, 'admin_headjs') ); | |
| 123 | 144 | |
| 124 | - // ajax function; 'add_meta_fields' is the action defined in isc.js as the action to be called via ajax | |
| 125 | - add_action('wp_ajax_add_meta_fields', array($this, 'add_meta_values_to_attachments')); | |
| 126 | - | |
| 127 | 145 | // save image information in meta field when a post is saved |
| 128 | 146 | add_action('save_post', array($this, 'save_image_information_on_post_save')); |
| 129 | 147 | } |
| 148 | + | |
| 149 | + public function get_source_by_url($url) | |
| 150 | + { | |
| 151 | + $id = $this->get_image_by_url($url); | |
| 152 | + $metadata['source'] = get_post_meta($id, 'isc_image_source', true); | |
| 153 | + $metadata['own'] = get_post_meta($id, 'isc_image_source_own', true); | |
| 154 | + | |
| 155 | + $source = $this->_common_texts['not_available']; | |
| 156 | + | |
| 157 | + $att_post = get_post($id); | |
| 158 | + | |
| 159 | + if ('' != $metadata['own']) { | |
| 160 | + if ($this->_options['use_authorname']) { | |
| 161 | + if (!empty($att_post)) { | |
| 162 | + $source = get_the_author_meta('display_name', $att_post->post_author); | |
| 163 | + } | |
| 164 | + } else { | |
| 165 | + $source = $this->options['by_author_text']; | |
| 166 | + } | |
| 167 | + } else { | |
| 168 | + if ('' != $metadata['source']) { | |
| 169 | + $source = $metadata['source']; | |
| 170 | + } | |
| 171 | + } | |
| 172 | + return $source; | |
| 173 | + } | |
| 174 | + | |
| 175 | + public function content_filter($content) | |
| 176 | + { | |
| 177 | + $options = $this->get_isc_options(); | |
| 178 | + if ($options['source_on_image']) { | |
| 179 | + $pattern = '#(\[caption.*align="(.+)"[^\]*]{0,}\])? *(<a [^>]+>)? *(<img .*class=".*(align\d{4,})?.*wp-image-(\d+)\D*".*src="(.+)".*/?>).*(?(3)(?:</a>)|.*).*(?(1)(?:\[/caption\])|.*)#isU'; | |
| 180 | + $count = preg_match_all($pattern, $content, $matches); | |
| 181 | + if (false !== $count) { | |
| 182 | + for ($i=0; $i < $count; $i++) { | |
| 183 | + $id = $matches[6][$i]; | |
| 184 | + $src = $matches[7][$i]; | |
| 185 | + $source = '<p class="isc-source-text">' . $options['source_pretext'] . ' ' . $this->get_source_by_url($src) . '</p>'; | |
| 186 | + $old_content = $matches[0][$i]; | |
| 187 | + $new_content = str_replace('wp-image-' . $id, 'wp-image-' . $id . ' with-source', $old_content); | |
| 188 | + $alignment = (!empty($matches[1][$i]))? $matches[2][$i] : $matches[5][$i]; | |
| 189 | + | |
| 190 | + $content = str_replace($old_content, '<div id="isc_attachment_' . $id . '" class="isc-source ' . $alignment . '"> ' . $new_content . $source . '</div>', $content); | |
| 191 | + } | |
| 192 | + } | |
| 193 | + } | |
| 194 | + return $content; | |
| 195 | + } | |
| 196 | + | |
| 197 | + public function attachment_added($att_id) | |
| 198 | + { | |
| 199 | + foreach ($this->_fields as $field) { | |
| 200 | + update_post_meta($att_id, $field['id'], $field['default']); | |
| 201 | + } | |
| 202 | + } | |
| 203 | + | |
| 204 | + /** | |
| 205 | + * Front-end scripts in <head /> section. | |
| 206 | + */ | |
| 207 | + public function front_head() | |
| 208 | + { | |
| 209 | + $options = $this->get_isc_options(); | |
| 210 | + ?> | |
| 211 | + <script type="text/javascript"> | |
| 212 | + /* <![CDATA[ */ | |
| 213 | + var isc_front_data = | |
| 214 | + { | |
| 215 | + caption_position : '<?php echo $options['caption_position']; ?>', | |
| 216 | + } | |
| 217 | + /* ]]> */ | |
| 218 | + </script> | |
| 219 | + <?php | |
| 220 | + } | |
| 221 | + | |
| 222 | + /** | |
| 223 | + * Enqueue scripts for the front-end. | |
| 224 | + */ | |
| 225 | + public function front_scripts() { | |
| 226 | + wp_enqueue_script('isc_front_js', plugins_url('/js/front-js.js', __FILE__), array('jquery'), ISCVERSION); | |
| 227 | + } | |
| 130 | 228 | |
| 131 | 229 | /** |
| 132 | 230 | * create the menu pages for isc |
| 133 | 231 | */ |
| @@ -153,16 +251,17 @@ | ||
| 153 | 251 | */ |
| 154 | 252 | public function add_admin_scripts($hook) |
| 155 | 253 | { |
| 156 | 254 | global $isc_setting; |
| 157 | - if ($hook != $isc_setting) { | |
| 158 | - return; | |
| 255 | + if ('post.php' == $hook) { | |
| 256 | + wp_enqueue_script('isc_postphp_script', plugins_url('/js/post.php.js', __FILE__), array('jquery'), ISCVERSION); | |
| 159 | 257 | } |
| 160 | - wp_enqueue_script('isc_script', plugins_url('/js/isc.js', __FILE__), false, ISCVERSION); | |
| 161 | - // this is to define ajaxurl to be able to use this in its own js script | |
| 162 | - // wp_localize_script( 'isc_script', 'IscAjax', array( 'ajaxurl' => admin_url( 'admin-ajax.php' ) ) ); | |
| 258 | + if ($hook == $isc_setting) { | |
| 259 | + wp_enqueue_script('isc_script', plugins_url('/js/isc.js', __FILE__), false, ISCVERSION); | |
| 260 | + wp_enqueue_style('isc_image_settings_css', plugins_url('/css/image-settings.css', __FILE__), false, ISCVERSION); | |
| 261 | + } | |
| 163 | 262 | } |
| 164 | - | |
| 263 | + | |
| 165 | 264 | /** |
| 166 | 265 | * add custom field to attachment |
| 167 | 266 | * @param arr $form_fields |
| 168 | 267 | * @param object $post |
| @@ -201,9 +300,8 @@ | ||
| 201 | 300 | { |
| 202 | 301 | if (isset($attachment['isc_image_source'])) { |
| 203 | 302 | update_post_meta($post['ID'], 'isc_image_source', $attachment['isc_image_source']); |
| 204 | 303 | } |
| 205 | - | |
| 206 | 304 | update_post_meta($post['ID'], 'isc_image_source_own', $attachment['isc_image_source_own']); |
| 207 | 305 | return $post; |
| 208 | 306 | } |
| 209 | 307 | |
| @@ -233,13 +331,9 @@ | ||
| 233 | 331 | $this->update_image_posts_meta($post_id, $post->post_content); |
| 234 | 332 | |
| 235 | 333 | $attachments = get_post_meta($post_id, 'isc_post_images', true); |
| 236 | 334 | } |
| 237 | - | |
| 238 | - $authorname = ''; | |
| 239 | - if (!empty($post->post_author)) | |
| 240 | - $authorname = get_the_author_meta('display_name', $post->post_author); | |
| 241 | - | |
| 335 | + | |
| 242 | 336 | $return = ''; |
| 243 | 337 | if (!empty($attachments)) { |
| 244 | 338 | $atts = array(); |
| 245 | 339 | foreach ($attachments as $attachment_id => $attachment_array) { |
| @@ -251,9 +345,14 @@ | ||
| 251 | 345 | // remove if no information set |
| 252 | 346 | unset($atts[$attachment_id]); |
| 253 | 347 | continue; |
| 254 | 348 | } elseif ($own != '') { |
| 255 | - if ($this->_options['use_authorname'] && !empty($authorname)) { | |
| 349 | + if ($this->_options['use_authorname']) { | |
| 350 | + $authorname = ''; | |
| 351 | + $att_post = get_post($attachment_id); | |
| 352 | + if (null !== $att_post) { | |
| 353 | + $authorname = get_the_author_meta('display_name', $att_post->post_author); | |
| 354 | + } | |
| 256 | 355 | $atts[$attachment_id ]['source'] = $authorname; |
| 257 | 356 | } else { |
| 258 | 357 | $atts[$attachment_id ]['source'] = $this->_options['by_author_text']; |
| 259 | 358 | } |
| @@ -276,13 +375,28 @@ | ||
| 276 | 375 | // don't display anything, if no image sources displayed |
| 277 | 376 | if ($attachments == array()) { |
| 278 | 377 | return ; |
| 279 | 378 | } |
| 379 | + | |
| 380 | + $options = $this->get_isc_options(); | |
| 381 | + $show_text = __('Show the list', ISCTEXTDOMAIN); | |
| 382 | + $hide_text = __('Hide the list', ISCTEXTDOMAIN); | |
| 383 | + | |
| 280 | 384 | ob_start(); |
| 281 | - | |
| 282 | 385 | $headline = $this->_options['image_list_headline']; |
| 283 | - printf('<p class="isc_image_list_title">%s</p>', $headline); ?> | |
| 284 | - <ul class="isc_image_list"><?php | |
| 386 | + $hide_style = ($options['hide_list'])? 'style="height: 0px; overflow: hidden;"': 'style="height: 100%; overflow: hidden;"'; | |
| 387 | + $hide_class = ($options['hide_list'])? ' isc-list-up': ' isc-list-down'; | |
| 388 | + $hide_title = ($options['hide_list'])? $show_text : $hide_text; | |
| 389 | + printf('<p class="isc_image_list_title" title="%2$s" style="cursor: pointer;">%1$s</p>', $headline, $hide_title); ?> | |
| 390 | + <script type="text/javascript"> | |
| 391 | + /* <!--[CDATA[ */ | |
| 392 | + isc_jstext = { | |
| 393 | + show_list: "<?php echo esc_attr($show_text); ?>", | |
| 394 | + hide_list: "<?php echo esc_attr($hide_text); ?>" | |
| 395 | + } | |
| 396 | + /* ]]--> */ | |
| 397 | + </script> | |
| 398 | + <ul class="isc_image_list <?php echo $hide_class; ?>"<?php echo $hide_style; ?>><?php | |
| 285 | 399 | |
| 286 | 400 | foreach ($attachments as $atts_id => $atts_array) { |
| 287 | 401 | if (empty($atts_array['source'])) { |
| 288 | 402 | continue; |
| @@ -385,8 +499,29 @@ | ||
| 385 | 499 | } |
| 386 | 500 | } |
| 387 | 501 | |
| 388 | 502 | /** |
| 503 | + * Display scripts in <head></head> section of admin page. Useful for creating js variables in the js global namespace. | |
| 504 | + */ | |
| 505 | + public function admin_headjs() | |
| 506 | + { | |
| 507 | + global $pagenow; | |
| 508 | + $options = $this->get_isc_options(); | |
| 509 | + if ('post.php' == $pagenow) { | |
| 510 | + ?> | |
| 511 | + <script type="text/javascript"> | |
| 512 | + /* <![CDATA[ */ | |
| 513 | + isc_data = { | |
| 514 | + warning_nosource : <?php echo (($options['warning_nosource'])? 'true' : 'false'); ?>, | |
| 515 | + block_form_message : '<?php _e('Please specify the image source', ISCTEXTDOMAIN); ?>' | |
| 516 | + } | |
| 517 | + /* ]]> */ | |
| 518 | + </script> | |
| 519 | + <?php | |
| 520 | + } | |
| 521 | + } | |
| 522 | + | |
| 523 | + /** | |
| 389 | 524 | * show the loading image from wp-admin/images/loading.gif |
| 390 | 525 | * @param bool $display should this be displayed directly or hidden? via inline css |
| 391 | 526 | */ |
| 392 | 527 | public function show_loading_image($display = true) |
| @@ -543,8 +678,12 @@ | ||
| 543 | 678 | $image_urls = $this->_filter_src_attributes($content); |
| 544 | 679 | $image_ids = array(); |
| 545 | 680 | $added_images = array(); |
| 546 | 681 | $removed_images = array(); |
| 682 | + | |
| 683 | + // add thumbnail information | |
| 684 | + $thumb_id = get_post_thumbnail_id($post_id); | |
| 685 | + if ( !empty( $thumb_id )) { $image_urls[] = wp_get_attachment_url($thumb_id); } | |
| 547 | 686 | |
| 548 | 687 | $isc_post_images = get_post_meta($post_id, 'isc_post_images', true); |
| 549 | 688 | |
| 550 | 689 | foreach ($image_urls as $url) { |
| @@ -661,28 +800,27 @@ | ||
| 661 | 800 | $connected_atts[$_attachment->ID]['own'] = get_post_meta($_attachment->ID, 'isc_image_source_own', true); |
| 662 | 801 | $connected_atts[$_attachment->ID]['title'] = $_attachment->post_title; |
| 663 | 802 | $connected_atts[$_attachment->ID]['author_name'] = ''; |
| 664 | 803 | if ('' != $connected_atts[$_attachment->ID]['own']) { |
| 665 | - $parent = get_post($_attachment->post_parent); | |
| 666 | - $connected_atts[$_attachment->ID]['author_name'] = get_the_author_meta('display_name', $parent->post_author); | |
| 804 | + $connected_atts[$_attachment->ID]['author_name'] = get_the_author_meta('display_name', $_attachment->post_author); | |
| 667 | 805 | } |
| 668 | 806 | |
| 669 | 807 | $metadata = get_post_meta($_attachment->ID, 'isc_image_posts', true); |
| 670 | - $parents_data = ''; | |
| 808 | + $usage_data = ''; | |
| 671 | 809 | |
| 672 | 810 | if (is_array($metadata) && array() != $metadata) { |
| 673 | - $parents_data .= "<ul style='margin: 0;'>"; | |
| 811 | + $usage_data .= "<ul style='margin: 0;'>"; | |
| 674 | 812 | foreach($metadata as $data) { |
| 675 | - $parents_data .= sprintf(__('<li><a href="%1$s" title="View %2$s">%3$s</a></li>', ISCTEXTDOMAIN), | |
| 813 | + $usage_data .= sprintf(__('<li><a href="%1$s" title="View %2$s">%3$s</a></li>', ISCTEXTDOMAIN), | |
| 676 | 814 | esc_url(get_permalink($data)), |
| 677 | 815 | esc_attr(get_the_title($data)), |
| 678 | 816 | esc_html(get_the_title($data)) |
| 679 | 817 | ); |
| 680 | 818 | } |
| 681 | - $parents_data .= "</ul>"; | |
| 819 | + $usage_data .= "</ul>"; | |
| 682 | 820 | } |
| 683 | 821 | |
| 684 | - $connected_atts[$_attachment->ID]['posts'] = $parents_data; | |
| 822 | + $connected_atts[$_attachment->ID]['posts'] = $usage_data; | |
| 685 | 823 | } |
| 686 | 824 | |
| 687 | 825 | $total = count($connected_atts); |
| 688 | 826 | |
| @@ -730,11 +868,8 @@ | ||
| 730 | 868 | { |
| 731 | 869 | if (!is_array($atts) || $atts == array()) |
| 732 | 870 | return; |
| 733 | 871 | $options = $this->get_isc_options(); |
| 734 | - if (!isset($options['thumbnail_size'])) { | |
| 735 | - $options = $options + $this->default_options(); | |
| 736 | - } | |
| 737 | 872 | ?> |
| 738 | 873 | <table> |
| 739 | 874 | <thead> |
| 740 | 875 | <?php if ($options['thumbnail_in_list']) : ?> |
| @@ -746,11 +881,10 @@ | ||
| 746 | 881 | <th><?php _e('Source', ISCTEXTDOMAIN); ?></th> |
| 747 | 882 | </thead> |
| 748 | 883 | <tbody> |
| 749 | 884 | <?php foreach ($atts as $id => $data) : ?> |
| 750 | - <?php | |
| 751 | - /** @todo ment for later: this text was used above already; find a place to but it so it is defined only once and used where needed */ | |
| 752 | - $source = __('Not available', ISCTEXTDOMAIN); | |
| 885 | + <?php | |
| 886 | + $source = $this->_common_texts['not_available']; | |
| 753 | 887 | if ('' != $data['own']) { |
| 754 | 888 | /** @todo ment for later: this text was used above already; find a place to but it so it is defined only once and used where needed */ |
| 755 | 889 | if ($this->_options['use_authorname']) { |
| 756 | 890 | $source = $data['author_name']; |
| @@ -927,10 +1061,10 @@ | ||
| 927 | 1061 | } |
| 928 | 1062 | $options = $this->get_isc_options(); |
| 929 | 1063 | if (!$options['installed']) { |
| 930 | 1064 | /** |
| 931 | - * Here, all jobs to perform during first installation, especially options and custom fields. | |
| 932 | - * Important: No add_action('something', 'somefunction'). | |
| 1065 | + * Here, all jobs to perform during first activation, especially options and custom fields. | |
| 1066 | + * Important: NO add_action('something', 'somefunction') here. | |
| 933 | 1067 | */ |
| 934 | 1068 | |
| 935 | 1069 | // adds meta fields for attachments |
| 936 | 1070 | $this->add_meta_values_to_attachments(); |
| @@ -951,14 +1085,20 @@ | ||
| 951 | 1085 | $default['image_list_headline'] = __('image sources', ISCTEXTDOMAIN); |
| 952 | 1086 | $default['use_authorname'] = true; |
| 953 | 1087 | $default['by_author_text'] = __('Owned by the author', ISCTEXTDOMAIN); |
| 954 | 1088 | $default['installed'] = false; |
| 955 | - $default['version'] = '1.2'; | |
| 1089 | + $default['version'] = ISCVERSION; | |
| 956 | 1090 | $default['webgilde'] = false; |
| 957 | 1091 | $default['thumbnail_in_list'] = false; |
| 958 | 1092 | $default['thumbnail_size'] = 'thumbnail'; |
| 959 | 1093 | $default['thumbnail_width'] = 150; |
| 960 | 1094 | $default['thumbnail_height'] = 150; |
| 1095 | + $default['warning_nosource'] = true; | |
| 1096 | + $default['warning_onesource_missing'] = true; | |
| 1097 | + $default['hide_list'] = false; | |
| 1098 | + $default['caption_position'] = 'top-left'; | |
| 1099 | + $default['source_on_image'] = false; | |
| 1100 | + $default['source_pretext'] = __('Source:', ISCTEXTDOMAIN); | |
| 961 | 1101 | return $default; |
| 962 | 1102 | } |
| 963 | 1103 | |
| 964 | 1104 | /** |
| @@ -968,15 +1108,38 @@ | ||
| 968 | 1108 | { |
| 969 | 1109 | $this->upgrade_management(); |
| 970 | 1110 | register_setting('isc_options_group', 'isc_options', array($this, 'settings_validation')); |
| 971 | 1111 | add_settings_section('isc_settings_section', '', '__return_false', 'isc_settings_page'); |
| 1112 | + | |
| 1113 | + // Starts Page/Post settings group | |
| 972 | 1114 | add_settings_field('image_list_headline', __('Image list headline', ISCTEXTDOMAIN), array($this, 'renderfield_list_headline'), 'isc_settings_page', 'isc_settings_section'); |
| 1115 | + /** | |
| 1116 | + * All new setting in Page/Post group Here! | |
| 1117 | + */ | |
| 1118 | + add_settings_field('hide_list', __('Hide the image list', ISCTEXTDOMAIN), array($this, 'renderfield_hide_list'), 'isc_settings_page', 'isc_settings_section'); | |
| 1119 | + // Ends Page/Post settings group | |
| 1120 | + | |
| 1121 | + // Starts Full images list group | |
| 1122 | + add_settings_field('use_thumbnail', __("Use thumbnails in images list", ISCTEXTDOMAIN), array($this, 'renderfield_use_thumbnail'), 'isc_settings_page', 'isc_settings_section'); | |
| 1123 | + /** | |
| 1124 | + * All new setting in Full images list group Here! | |
| 1125 | + */ | |
| 1126 | + add_settings_field('thumbnail_width', __("Thumbnails max-width", ISCTEXTDOMAIN), array($this, 'renderfield_thumbnail_width'), 'isc_settings_page', 'isc_settings_section'); | |
| 1127 | + add_settings_field('thumbnail_height', __("Thumbnails max-height", ISCTEXTDOMAIN), array($this, 'renderfield_thumbnail_height'), 'isc_settings_page', 'isc_settings_section'); | |
| 1128 | + // Ends Full images list group | |
| 1129 | + | |
| 1130 | + // Starts Misc settings group | |
| 973 | 1131 | add_settings_field('use_authorname', __('Use authors names', ISCTEXTDOMAIN), array($this, 'renderfield_use_authorname'), 'isc_settings_page', 'isc_settings_section'); |
| 974 | 1132 | add_settings_field('by_author_text', __('Custom text for owned images', ISCTEXTDOMAIN), array($this, 'renderfield_byauthor_text'), 'isc_settings_page', 'isc_settings_section'); |
| 975 | 1133 | add_settings_field('webgilde_backlink', __("Link to webgilde's website", ISCTEXTDOMAIN), array($this, 'renderfield_webgile'), 'isc_settings_page', 'isc_settings_section'); |
| 976 | - add_settings_field('use_thumbnail', __("Use thumbnails in images list", ISCTEXTDOMAIN), array($this, 'renderfield_use_thumbnail'), 'isc_settings_page', 'isc_settings_section'); | |
| 977 | - add_settings_field('thumbnail_width', __("Thumbnails max-width", ISCTEXTDOMAIN), array($this, 'renderfield_thumbnail_width'), 'isc_settings_page', 'isc_settings_section'); | |
| 978 | - add_settings_field('thumbnail_height', __("Thumbnails max-height", ISCTEXTDOMAIN), array($this, 'renderfield_thumbnail_height'), 'isc_settings_page', 'isc_settings_section'); | |
| 1134 | + /** | |
| 1135 | + * All new setting in Misc settings group Here! | |
| 1136 | + */ | |
| 1137 | + add_settings_field('source_caption', __("Source as caption on image", ISCTEXTDOMAIN), array($this, 'renderfield_source_caption'), 'isc_settings_page', 'isc_settings_section'); | |
| 1138 | + add_settings_field('caption_position', __("Caption position", ISCTEXTDOMAIN), array($this, 'renderfield_caption_pos'), 'isc_settings_page', 'isc_settings_section'); | |
| 1139 | + add_settings_field('warning_one_source', __("Warning when there is at least one missing source", ISCTEXTDOMAIN), array($this, 'renderfield_warning_onesource_misisng'), 'isc_settings_page', 'isc_settings_section'); | |
| 1140 | + add_settings_field('warning_nosource', __("Warnings when source not available", ISCTEXTDOMAIN), array($this, 'renderfield_warning_nosource'), 'isc_settings_page', 'isc_settings_section'); | |
| 1141 | + // Ends Misc settings group | |
| 979 | 1142 | } |
| 980 | 1143 | |
| 981 | 1144 | /** |
| 982 | 1145 | * manage data structure upgrading of outdated versions |
| @@ -981,38 +1144,28 @@ | ||
| 981 | 1144 | /** |
| 982 | 1145 | * manage data structure upgrading of outdated versions |
| 983 | 1146 | */ |
| 984 | 1147 | public function upgrade_management() { |
| 985 | - /** | |
| 986 | - * Since the activation hook is not executed on plugin upgrade, this function checks options in database | |
| 987 | - * during the admin_init hook to handle plugin's upgrade. | |
| 988 | - */ | |
| 1148 | + | |
| 1149 | + /* | |
| 1150 | + * Since the activation hook is not executed on plugin upgrade, this function checks options in database | |
| 1151 | + * during the admin_init hook to handle plugin's upgrade. | |
| 1152 | + */ | |
| 1153 | + | |
| 1154 | + $options = get_option('isc_options'); | |
| 989 | 1155 | |
| 990 | - $options = get_option( 'isc_options' ); | |
| 991 | - | |
| 992 | - $max_step = count($this->_upgrade_step); | |
| 993 | - $step_count = 0; | |
| 994 | - | |
| 995 | - if (!is_array($options) || !isset($options['version'])){ // versions prior to 1.2 | |
| 996 | - | |
| 997 | - $default = $this->default_options(); | |
| 998 | - $options = $options + $default; | |
| 1156 | + if (!is_array($options)) { | |
| 1157 | + // special case for version prior to 1.2 (which don't have options) | |
| 1158 | + $options = $this->default_options(); | |
| 999 | 1159 | $this->init_image_posts_metafield(); |
| 1000 | 1160 | $options['installed'] = true; |
| 1001 | - | |
| 1002 | 1161 | update_option('isc_options', $options); |
| 1003 | - $step_count++; | |
| 1004 | - | |
| 1005 | - } elseif(ISCVERSION != $options['version']) { | |
| 1162 | + } | |
| 1006 | 1163 | |
| 1007 | - while (ISCVERSION != $options['version'] && $step_count <= $max_step) { | |
| 1008 | - switch ($options['version']) { | |
| 1009 | - /** | |
| 1010 | - * Here, the incremental upgrade process depending on the currently installed version. | |
| 1011 | - */ | |
| 1012 | - } | |
| 1013 | - } | |
| 1014 | - | |
| 1164 | + if (ISCVERSION != $options['version']) { | |
| 1165 | + $options = $options + $this->default_options(); | |
| 1166 | + $options['version'] = ISCVERSION; | |
| 1167 | + update_option('isc_options', $options); | |
| 1015 | 1168 | } |
| 1016 | 1169 | } |
| 1017 | 1170 | |
| 1018 | 1171 | /** |
| @@ -1022,16 +1175,23 @@ | ||
| 1022 | 1175 | { |
| 1023 | 1176 | ?> |
| 1024 | 1177 | <div id="icon-options-general" class="icon32"><br></div> |
| 1025 | 1178 | <h2><?php _e('Images control settings', ISCTEXTDOMAIN); ?></h2> |
| 1026 | - <form id="image-control-form" method="post" action="options.php"> | |
| 1179 | + <div id="isc-admin-wrap"> | |
| 1180 | + <form id="image-control-form" method="post" action="options.php"> | |
| 1181 | + <div class="postbox isc-setting-group"><?php // Open the div for the first settings group ?> | |
| 1182 | + <h3 class="setting-group-head"><?php _e('Post / Page images list', ISCTEXTDOMAIN); ?></h3> | |
| 1183 | + <?php | |
| 1184 | + settings_fields( 'isc_options_group' ); | |
| 1185 | + do_settings_sections( 'isc_settings_page' ); | |
| 1186 | + ?> | |
| 1187 | + </div><?php //Close the last settings group div ?> | |
| 1188 | + <p class="submit"> | |
| 1189 | + <input type="submit" name="submit" id="submit" class="button button-primary" value="Save Changes"> | |
| 1190 | + </p> | |
| 1191 | + </form> | |
| 1192 | + </div><!-- #isc-admin-wrap --> | |
| 1027 | 1193 | <?php |
| 1028 | - settings_fields( 'isc_options_group' ); | |
| 1029 | - do_settings_sections( 'isc_settings_page' ); | |
| 1030 | - submit_button(); | |
| 1031 | - ?> | |
| 1032 | - </form> | |
| 1033 | - <?php | |
| 1034 | 1194 | } |
| 1035 | 1195 | |
| 1036 | 1196 | /** |
| 1037 | 1197 | * image_list field callbacks |
| @@ -1048,15 +1208,34 @@ | ||
| 1048 | 1208 | </div> |
| 1049 | 1209 | <?php |
| 1050 | 1210 | } |
| 1051 | 1211 | |
| 1212 | + public function renderfield_hide_list() | |
| 1213 | + { | |
| 1214 | + $options = $this->get_isc_options(); | |
| 1215 | + $description = __("Hide the list when the post is loaded. A simple click on the list headline will show the list content.", ISCTEXTDOMAIN); | |
| 1216 | + ?> | |
| 1217 | + <div id="hide-list-block"> | |
| 1218 | + <label for="hide-list"><?php _e('Hide the image list of a post', ISCTEXTDOMAIN) ?></label> | |
| 1219 | + <input type="checkbox" name="isc_options[hide_list]" id="hide-list" <?php checked($options['hide_list']); ?> /> | |
| 1220 | + <p><em><?php echo $description; ?></em></p> | |
| 1221 | + </div> | |
| 1222 | + </td></tr></tbody></table> | |
| 1223 | + </div><!-- .postbox --> | |
| 1224 | + <div class="postbox isc-setting-group"> | |
| 1225 | + <h3 class="setting-group-head"><?php _e('Full images list', ISCTEXTDOMAIN) ?></h3> | |
| 1226 | + <table class="form-table"><tbody><tr><td> | |
| 1227 | + <?php | |
| 1228 | + } | |
| 1229 | + | |
| 1052 | 1230 | public function renderfield_use_authorname() |
| 1053 | 1231 | { |
| 1054 | 1232 | $options = $this->get_isc_options(); |
| 1055 | - $description = __("Display the author's public name as source when the image is owned by the author. Uncheck to use a custom text instead.", ISCTEXTDOMAIN); | |
| 1233 | + $description = __("Display the author's public name as source when the image is owned by the author (the uploader of the image, not necessarily the author of the post the image is displayed on). Uncheck to use a custom text instead.", ISCTEXTDOMAIN); | |
| 1234 | + | |
| 1056 | 1235 | ?> |
| 1057 | 1236 | <div id="use-authorname-block"> |
| 1058 | - <label for="use_authorname"><?php _e('Use author name') ?></label> | |
| 1237 | + <label for="use_authorname"><?php _e('Use author name', ISCTEXTDOMAIN) ?></label> | |
| 1059 | 1238 | <input type="checkbox" name="isc_options[use_authorname_ckbox]" id="use_authorname" <?php checked($options['use_authorname']); ?> /> |
| 1060 | 1239 | <p><em><?php echo $description; ?></em></p> |
| 1061 | 1240 | </div> |
| 1062 | 1241 | <?php |
| @@ -1076,15 +1255,8 @@ | ||
| 1076 | 1255 | |
| 1077 | 1256 | public function renderfield_webgile() |
| 1078 | 1257 | { |
| 1079 | 1258 | $options = $this->get_isc_options(); |
| 1080 | - /** | |
| 1081 | - * Avoid warning notices because of the absence of webgilde field in isc_options throughout development steps. | |
| 1082 | - * This 'if' block can be removed for the next release. | |
| 1083 | - */ | |
| 1084 | - if (!isset($options['webgilde'])) { | |
| 1085 | - $options = $options + $this->default_options(); | |
| 1086 | - } | |
| 1087 | 1259 | $description = sprintf(__('Display a link to <a href="%s">Image Source Control plugin's website</a> below the list of all images in the blog?', ISCTEXTDOMAIN), WEBGILDE); |
| 1088 | 1260 | ?> |
| 1089 | 1261 | <div id="webgilde-block"> |
| 1090 | 1262 | <input type="checkbox" id="webgilde-link" name="isc_options[webgilde_field]" <?php checked($options['webgilde']); ?> /> |
| @@ -1095,15 +1267,12 @@ | ||
| 1095 | 1267 | |
| 1096 | 1268 | public function renderfield_use_thumbnail() |
| 1097 | 1269 | { |
| 1098 | 1270 | $options = $this->get_isc_options(); |
| 1099 | - if (!isset($options['thumbnail_size'])) { | |
| 1100 | - $options = $options + $this->default_options(); | |
| 1101 | - } | |
| 1102 | 1271 | $description = __('Display thumbnails on the list of all images in the blog.' ,ISCTEXTDOMAIN); |
| 1103 | 1272 | ?> |
| 1104 | 1273 | <div id="use-thumbnail-block"> |
| 1105 | - <input type="checkbox" id="use-thumbnail" name="isc_options[use_thumbnail]" <?php checked($options['thumbnail_in_list']); ?> /> | |
| 1274 | + <input type="checkbox" id="use-thumbnail" name="isc_options[use_thumbnail]" value="1" <?php checked($options['thumbnail_in_list']); ?> /> | |
| 1106 | 1275 | <select id="thumbnail-size-select" name="isc_options[size_select]" <?php disabled(!$options['thumbnail_in_list']) ?>> |
| 1107 | 1276 | <?php foreach ($this->_thumbnail_size as $size) : ?> |
| 1108 | 1277 | <option value="<?php echo $size; ?>" <?php selected($size, $options['thumbnail_size']);?>><?php echo $size; ?></option> |
| 1109 | 1278 | <?php endforeach; ?> |
| @@ -1115,11 +1284,8 @@ | ||
| 1115 | 1284 | |
| 1116 | 1285 | public function renderfield_thumbnail_width() |
| 1117 | 1286 | { |
| 1118 | 1287 | $options = $this->get_isc_options(); |
| 1119 | - if (!isset($options['thumbnail_size'])) { | |
| 1120 | - $options = $options + $this->default_options(); | |
| 1121 | - } | |
| 1122 | 1288 | $description = __('Custom value of the maximum allowed width for thumbnail.' ,ISCTEXTDOMAIN); |
| 1123 | 1289 | ?> |
| 1124 | 1290 | <div id="thumbnail-custom-width"> |
| 1125 | 1291 | <input type="text" id="custom-width" name="isc_options[thumbnail_width]" class="small-text" value="<?php echo $options['thumbnail_width'] ?>" /> px |
| @@ -1130,11 +1296,8 @@ | ||
| 1130 | 1296 | |
| 1131 | 1297 | public function renderfield_thumbnail_height() |
| 1132 | 1298 | { |
| 1133 | 1299 | $options = $this->get_isc_options(); |
| 1134 | - if (!isset($options['thumbnail_size'])) { | |
| 1135 | - $options = $options + $this->default_options(); | |
| 1136 | - } | |
| 1137 | 1300 | $description = __('Custom value of the maximum allowed height for thumbnail.' ,ISCTEXTDOMAIN); |
| 1138 | 1301 | ?> |
| 1139 | 1302 | <div id="thumbnail-custom-height"> |
| 1140 | 1303 | <input type="text" id="custom-height" name="isc_options[thumbnail_height]" class="small-text" value="<?php echo $options['thumbnail_height'] ?>"/> px |
| @@ -1139,11 +1302,71 @@ | ||
| 1139 | 1302 | <div id="thumbnail-custom-height"> |
| 1140 | 1303 | <input type="text" id="custom-height" name="isc_options[thumbnail_height]" class="small-text" value="<?php echo $options['thumbnail_height'] ?>"/> px |
| 1141 | 1304 | <p><em><?php echo $description; ?></em></p> |
| 1142 | 1305 | </div> |
| 1306 | + </td></tr></tbody></table> | |
| 1307 | + </div><!-- .postbox --> | |
| 1308 | + <div class="postbox isc-setting-group"> | |
| 1309 | + <h3 class="setting-group-head"><?php _e('Miscellaneous settings', ISCTEXTDOMAIN); ?></h3> | |
| 1310 | + <table class="form-table"><tbody><tr><td> | |
| 1143 | 1311 | <?php |
| 1144 | 1312 | } |
| 1145 | 1313 | |
| 1314 | + public function renderfield_warning_nosource() | |
| 1315 | + { | |
| 1316 | + $options = $this->get_isc_options(); | |
| 1317 | + $description = __('Warn and prevent data to be saved when an attachment is edited and the source has not been specified.' ,ISCTEXTDOMAIN); | |
| 1318 | + ?> | |
| 1319 | + <div id="no-source-block"> | |
| 1320 | + <input type="checkbox" id="no-source" name="isc_options[no_source]"value="1" <?php checked($options['warning_nosource']); ?>/> | |
| 1321 | + <p><em><?php echo $description; ?></em></p> | |
| 1322 | + </div> | |
| 1323 | + <?php | |
| 1324 | + } | |
| 1325 | + | |
| 1326 | + public function renderfield_warning_onesource_misisng() | |
| 1327 | + { | |
| 1328 | + $options = $this->get_isc_options(); | |
| 1329 | + $description = __('Display an admin notice in admin pages when one or more image sources are missing.' ,ISCTEXTDOMAIN); | |
| 1330 | + ?> | |
| 1331 | + <div id="one-source-block"> | |
| 1332 | + <input type="checkbox" id="one-source" name="isc_options[one_source]"value="1" <?php checked($options['warning_onesource_missing']); ?>/> | |
| 1333 | + <p><em><?php echo $description; ?></em></p> | |
| 1334 | + </div> | |
| 1335 | + <?php | |
| 1336 | + } | |
| 1337 | + | |
| 1338 | + public function renderfield_caption_pos() | |
| 1339 | + { | |
| 1340 | + $options = $this->get_isc_options(); | |
| 1341 | + $description = __('Position of captions into images' ,ISCTEXTDOMAIN); | |
| 1342 | + ?> | |
| 1343 | + <div id="caption-position-block"> | |
| 1344 | + <select id="caption-pos" name="isc_options[cap_pos]"> | |
| 1345 | + <?php foreach ($this->_caption_position as $pos) : ?> | |
| 1346 | + <option value="<?php echo $pos; ?>" <?php selected($pos, $options['caption_position']); ?>><?php echo $pos; ?></option> | |
| 1347 | + <?php endforeach; ?> | |
| 1348 | + </select> | |
| 1349 | + <p><em><?php echo $description; ?></em></p> | |
| 1350 | + </div> | |
| 1351 | + <?php | |
| 1352 | + } | |
| 1353 | + | |
| 1354 | + public function renderfield_source_caption() | |
| 1355 | + { | |
| 1356 | + $options = $this->get_isc_options(); | |
| 1357 | + $description_checkbox = __('Tick to display source onto each image.' ,ISCTEXTDOMAIN); | |
| 1358 | + $description_textfield = __('The text preceding the source on each image.' ,ISCTEXTDOMAIN); | |
| 1359 | + ?> | |
| 1360 | + <div id="caption-block"> | |
| 1361 | + <input type="checkbox" id="source-on-image" value="1" name="isc_options[source_on_image]" <?php checked($options['source_on_image']); ?> /> | |
| 1362 | + <p><em><?php echo $description_checkbox; ?></em></p> | |
| 1363 | + <input type="text" id='source-pretext' name="isc_options[source_pretext]" value="<?php echo $options['source_pretext']; ?>" /> | |
| 1364 | + <p><em><?php echo $description_textfield; ?></em></p> | |
| 1365 | + </div> | |
| 1366 | + <?php | |
| 1367 | + } | |
| 1368 | + | |
| 1146 | 1369 | /** |
| 1147 | 1370 | * Returns isc_options if it exists, returns the default options otherwise. |
| 1148 | 1371 | */ |
| 1149 | 1372 | public function get_isc_options() { |
| @@ -1186,8 +1409,31 @@ | ||
| 1186 | 1409 | } |
| 1187 | 1410 | } else { |
| 1188 | 1411 | $output['thumbnail_in_list'] = false; |
| 1189 | 1412 | } |
| 1413 | + if (isset($input['no_source'])) { | |
| 1414 | + $output['warning_nosource'] = true; | |
| 1415 | + } else { | |
| 1416 | + $output['warning_nosource'] = false; | |
| 1417 | + } | |
| 1418 | + if (isset($input['one_source'])) { | |
| 1419 | + $output['warning_onesource_missing'] = true; | |
| 1420 | + } else { | |
| 1421 | + $output['warning_onesource_missing'] = false; | |
| 1422 | + } | |
| 1423 | + if (isset($input['hide_list'])){ | |
| 1424 | + $output['hide_list'] = true; | |
| 1425 | + } else { | |
| 1426 | + $output['hide_list'] = false; | |
| 1427 | + } | |
| 1428 | + if (in_array($input['cap_pos'], $this->_caption_position)) | |
| 1429 | + $output['caption_position'] = $input['cap_pos']; | |
| 1430 | + if (isset($input['source_on_image'])) { | |
| 1431 | + $output['source_on_image'] = true; | |
| 1432 | + $output['source_pretext'] = $input['source_pretext']; | |
| 1433 | + } else { | |
| 1434 | + $output['source_on_image'] = false; | |
| 1435 | + } | |
| 1190 | 1436 | return $output; |
| 1191 | 1437 | } |
| 1192 | 1438 | |
| 1193 | 1439 | /** |
| @@ -1221,8 +1467,41 @@ | ||
| 1221 | 1467 | } |
| 1222 | 1468 | } |
| 1223 | 1469 | } |
| 1224 | 1470 | } |
| 1471 | + } | |
| 1472 | + | |
| 1473 | + /** | |
| 1474 | + * | |
| 1475 | + */ | |
| 1476 | + public function admin_notices() | |
| 1477 | + { | |
| 1478 | + $args = array( | |
| 1479 | + 'post_type' => 'attachment', | |
| 1480 | + 'numberposts' => -1, | |
| 1481 | + 'post_status' => null, | |
| 1482 | + 'post_parent' => null, | |
| 1483 | + 'meta_query' => array( | |
| 1484 | + array( | |
| 1485 | + 'key' => 'isc_image_source', | |
| 1486 | + 'value' => '', | |
| 1487 | + 'compare' => '=' | |
| 1488 | + ), | |
| 1489 | + array( | |
| 1490 | + 'key' => 'isc_image_source_own', | |
| 1491 | + 'value' => '', | |
| 1492 | + 'compare' => '' | |
| 1493 | + ) | |
| 1494 | + ) | |
| 1495 | + ); | |
| 1496 | + $attachments = get_posts($args); | |
| 1497 | + $options = $this->get_isc_options(); | |
| 1498 | + if (!empty($attachments) && $options['warning_onesource_missing'] ) { | |
| 1499 | + $missing_src = esc_url(admin_url('upload.php?page=image-source-control-isc/templates/missing_sources.php')); | |
| 1500 | + ?> | |
| 1501 | + <div class="updated"><p><?php printf(__('One or more attachments still have no source. See the <a href="%s">missing sources</a> list', ISCTEXTDOMAIN), $missing_src);?></p></div> | |
| 1502 | + <?php | |
| 1503 | + } | |
| 1225 | 1504 | } |
| 1226 | 1505 | |
| 1227 | 1506 | }// end of class |
| 1228 | 1507 | |