PluginProbe
Image Source Control Lite – Show Image Credits and Captions / trunk
Image Source Control Lite – Show Image Credits and Captions vtrunk
3.12.0 3.11.0 trunk 1.1 1.1.1 1.1.2 1.1.2.1 1.1.3 1.10 1.10.1 1.10.2 1.10.3 1.10.4 1.10.5 1.2 1.2.0.1 1.2.0.2 1.2.0.3 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.4.1 1.3.5 All 110 releases
← All changes | admin/admin.php +130 -950 1.10trunk View file →
@@ -1,975 +1,155 @@
1 1 <?php
2 -//avoid direct calls to this file
3 -if (!function_exists('add_action')) {
4 - header('Status: 403 Forbidden');
5 - header('HTTP/1.1 403 Forbidden');
6 - exit();
7 -}
8 2
9 -if (!class_exists('ISC_Admin')) {
3 +namespace ISC;
10 4
11 - /**
12 - * handles all admin functionalities
13 - *
14 - * @since 1.7 - move a lot of functions here from general class
15 - */
16 - class ISC_Admin extends ISC_Class {
5 +use ISC\Image_Sources\Image_Sources_Admin_Scripts;
17 6
18 - /**
19 - * initiate admin functions
20 - *
21 - * @since 1.7
22 - */
23 - public function __construct() {
7 +/**
8 + * Initialize WP Admin
9 + */
10 +class Admin {
11 + /**
12 + * Initiate admin functions
13 + */
14 + public function __construct() {
15 + // load more admin-related classes
16 + add_action( 'init', [ $this, 'load_modules' ] );
24 17
25 - parent::__construct();
18 + // Remove existing admin notices and register our own
19 + add_action( 'in_admin_header', [ $this, 'unregister_admin_notices' ] );
26 20
27 - register_activation_hook(ISCPATH . '../isc.php', array($this, 'activation'));
21 + // ISC page header
22 + add_action( 'isc_admin_notices', [ $this, 'branded_admin_header' ] );
28 23
29 - // attachment field handling
30 - add_action('add_attachment', array($this, 'attachment_added'), 10, 2);
31 - add_filter('attachment_fields_to_edit', array($this, 'add_isc_fields'), 10, 2);
32 - add_filter('attachment_fields_to_save', array($this, 'isc_fields_save'), 10, 2);
24 + // hide the admin language switcher from WPML on our pages
25 + add_filter( 'wpml_show_admin_language_switcher', [ $this, 'disable_wpml_admin_lang_switcher' ] );
33 26
34 - // save image information in meta field after a post was saved
35 - add_action('wp_insert_post', array($this, 'save_image_information_on_post_save'));
27 + // add links to setting and source list to plugin page
28 + add_action( 'plugin_action_links_' . ISCBASE, [ $this, 'add_links_to_plugin_page' ] );
36 29
37 - // admin notices
38 - add_action('admin_notices', array($this, 'admin_notices'));
30 + // fire when an attachment is removed
31 + add_action( 'delete_attachment', [ $this, 'clear_unused_images_stats' ] );
39 32
40 - // settings page
41 - add_action('admin_menu', array($this, 'create_menu'));
42 - add_action('admin_init', array($this, 'SAPI_init'));
33 + new \ISC\Settings();
34 + }
43 35
44 - // scripts and styles
45 - add_action('admin_enqueue_scripts', array($this, 'add_admin_scripts'));
46 - add_action( 'admin_print_scripts', array($this, 'admin_headjs') );
36 + /**
37 + * Load additional admin classes and modules
38 + */
39 + public function load_modules() {
40 + new \ISC\Admin\Admin_Scripts();
41 + new \ISC\Admin\Admin_Ajax();
42 + new \ISC\Admin\Media_Library_Filter();
43 + new \ISC\Admin\Media_Library_Checks();
47 44
48 - // ajax calls
49 - add_action('wp_ajax_isc-post-image-relations', array($this, 'list_post_image_relations'));
50 - add_action('wp_ajax_isc-image-post-relations', array($this, 'list_image_post_relations'));
51 - }
45 + if ( Plugin::is_module_enabled( 'image_sources' ) ) {
46 + new \ISC\Image_Sources\Admin();
47 + }
52 48
53 - /**
54 - * Search for missing sources and display a warning if found some
55 - */
56 - public function admin_notices()
57 - {
49 + new \ISC\Feedback();
50 + }
58 51
59 - // only check, if check-option was enabled
60 - $options = $this->get_isc_options();
61 - if( empty( $options['warning_onesource_missing'] ) ){
62 - return;
63 - };
52 + /**
53 + * Unregister existing admin notices and register our own
54 + * This should help prevent unrelated notices on ISC specific pages
55 + */
56 + public function unregister_admin_notices() {
57 + if ( ! Admin_Utils::is_isc_page() ) {
58 + return;
59 + }
64 60
65 - $show_warning = get_transient( 'isc-show-missing-sources-warning' );
61 + // Remove all admin_notices hooks
62 + remove_all_actions( 'admin_notices' );
66 63
67 - // attachments without sources
68 - if( ! $show_warning ){
69 - $args = array(
70 - 'post_type' => 'attachment',
71 - 'numberposts' => 1,
72 - 'post_status' => null,
73 - 'post_parent' => null,
74 - 'meta_query' => array(
75 - array(
76 - 'key' => 'isc_image_source',
77 - 'value' => '',
78 - 'compare' => '='
79 - ),
80 - array(
81 - 'key' => 'isc_image_source_own',
82 - 'value' => '1',
83 - 'compare' => '!=',
84 - )
85 - )
86 - );
87 - $attachments = get_posts($args);
64 + // Trigger ISC-specific admin notices action
65 + do_action( 'isc_admin_notices' );
66 + }
88 67
89 - if( !empty( $attachments ) ){
90 - $show_warning = true;
91 - } else {
92 - // load unindexed attachments
93 - $args = array(
94 - 'post_type' => 'attachment',
95 - 'numberposts' => 1,
96 - 'post_status' => null,
97 - 'post_parent' => null,
98 - 'meta_query' => array(
99 - array(
100 - 'key' => 'isc_image_source',
101 - 'value' => 'any',
102 - 'compare' => 'NOT EXISTS'
103 - ),
104 - )
105 - );
106 - $attachments2 = get_posts($args);
107 - if( !empty( $attachments2 ) ){
108 - $show_warning = true;
109 - }
110 - }
111 - }
68 + /**
69 + * Add links to pages from plugins.php
70 + *
71 + * @param array $links existing plugin links.
72 + * @return array
73 + */
74 + public function add_links_to_plugin_page( $links ): array {
75 + // add link to premium.
76 + if ( ! Plugin::is_pro() ) {
77 + array_unshift( $links, Admin_Utils::get_pro_link( 'plugin-overview' ) );
78 + }
79 + // settings link
80 + $links[] = sprintf(
81 + '<a href="%s">%s</a>',
82 + esc_url( add_query_arg( 'page', 'isc-settings', get_admin_url() . 'options-general.php' ) ),
83 + __( 'Settings', 'image-source-control-isc' )
84 + );
112 85
113 - if ( $show_warning ){
114 - $missing_src = esc_url(admin_url('upload.php?page=isc_missing_sources_page'));
115 - ?><div class="error"><p><?php
116 - printf(__('One or more attachments still have no source. See the <a href="%s">missing sources</a> list', 'image-source-control-isc'), $missing_src);
117 - ?></p></div><?php
118 - }
86 + return $links;
87 + }
119 88
120 - // save result in transient and don’t check for 24 hours
121 - set_transient( 'isc-show-missing-sources-warning', $show_warning, DAY_IN_SECONDS );
122 - }
89 + /**
90 + * Disable the WPML language switcher on ISC pages
91 + *
92 + * @param bool $state current state.
93 + *
94 + * @return bool
95 + */
96 + public function disable_wpml_admin_lang_switcher( $state ): bool {
97 + // needs to run before plugins_loaded with prio 1, so our own `is_isc_page` function is not available here
98 + global $pagenow;
123 99
124 - /**
125 - * add scripts to admin pages
126 - * @since 1.0
127 - * @update 1.1.1
128 - */
129 - public function add_admin_scripts($hook)
130 - {
131 - global $isc_setting;
132 - if ('post.php' == $hook) {
133 - // 2013-12-11 (maik) quick fix for post.php.js to avoid access conflicts caused by other plugins due to by inconsistent naming
134 - wp_enqueue_script('isc_postphp_script', plugins_url('/assets/js/post.js', __FILE__), array('jquery'), ISCVERSION);
135 - }
136 - //if ($hook == $isc_setting) {
137 - wp_enqueue_script('isc_script', plugins_url('/assets/js/isc.js', __FILE__), false, ISCVERSION);
138 - wp_enqueue_style('isc_image_settings_css', plugins_url('/assets/css/image-settings.css', __FILE__), false, ISCVERSION);
139 - //}
140 - }
100 + // phpcs:ignore WordPress.Security.NonceVerification.Recommended
101 + if ( ! isset( $_GET['page'] ) ) {
102 + return $state;
103 + }
141 104
142 - /**
143 - * Display scripts in <head></head> section of admin page. Useful for creating js variables in the js global namespace.
144 - */
145 - public function admin_headjs()
146 - {
147 - global $pagenow;
148 - $options = $this->get_isc_options();
149 - if ('post.php' == $pagenow) {
150 - ?>
151 - <script type="text/javascript">
152 - /* <![CDATA[ */
153 - isc_data = {
154 - warning_nosource : <?php echo (($options['warning_nosource'])? 'true' : 'false'); ?>,
155 - block_form_message : '<?php _e('Please specify the image source', 'image-source-control-isc'); ?>'
156 - }
157 - /* ]]> */
158 - </script>
159 - <?php
160 - }
161 - }
105 + // settings page
106 + if (
107 + $pagenow === 'options-general.php'
108 + // phpcs:ignore WordPress.Security.NonceVerification.Recommended
109 + && in_array( $_GET['page'], [ 'isc-settings' ], true )
110 + ) {
111 + $state = false;
112 + }
162 113
163 - /**
164 - * add custom field to attachment
165 - *
166 - * @since 1.0
167 - * @updated 1.1
168 - * @updated 1.3.5 added field for license
169 - * @updated 1.5 added field for url
114 + // media pages
115 + if (
116 + $pagenow === 'upload.php'
117 + // phpcs:ignore WordPress.Security.NonceVerification.Recommended
118 + && in_array( $_GET['page'], [ 'isc-unused-images', 'isc-images' ], true )
119 + ) {
120 + $state = false;
121 + }
170 122
171 - * @param arr $form_fields
172 - * @param object $post
173 - * @return arr
174 - */
175 - public function add_isc_fields($form_fields, $post)
176 - {
177 - // add input field for source
178 - $form_fields['isc_image_source']['label'] = __('Image Source', 'image-source-control-isc');
179 - $form_fields['isc_image_source']['value'] = get_post_meta($post->ID, 'isc_image_source', true);
180 - $form_fields['isc_image_source']['helps'] = __('Include the image source here.', 'image-source-control-isc' );
123 + return $state;
124 + }
181 125
182 - // add checkbox to mark as your own image
183 - $form_fields['isc_image_source_own']['input'] = 'html';
184 - $form_fields['isc_image_source_own']['label'] = '';
185 - $form_fields['isc_image_source_own']['helps'] =
186 - __('Check this box if this is your own image and doesn\'t need a source.', 'image-source-control-isc');
187 - $form_fields['isc_image_source_own']['html'] =
188 - "<input type='checkbox' value='1' name='attachments[{$post->ID}][isc_image_source_own]' id='attachments[{$post->ID}][isc_image_source_own]' "
189 - . checked(get_post_meta($post->ID, 'isc_image_source_own', true), 1, false )
190 - . " style=\"width:14px\"/> "
191 - . __('This is my image', 'image-source-control-isc');
126 + /**
127 + * Add an ISC branded header to plugin pages
128 + */
129 + public static function branded_admin_header() {
130 + $screen = get_current_screen();
131 + $screen_id = $screen->id ?? null;
132 + if ( ! Admin_Utils::is_isc_page() ) {
133 + return;
134 + }
135 + switch ( $screen_id ) {
136 + case 'settings_page_isc-settings':
137 + $title = __( 'Settings', 'image-source-control-isc' );
138 + break;
139 + case 'media_page_isc-sources':
140 + $title = __( 'Tools', 'image-source-control-isc' );
141 + break;
142 + default:
143 + $title = get_admin_page_title();
144 + }
145 + include ISCPATH . 'admin/templates/header.php';
146 + }
192 147
193 - // add input field for source url
194 - $form_fields['isc_image_source_url']['label'] = __('Image Source URL', 'image-source-control-isc');
195 - $form_fields['isc_image_source_url']['value'] = get_post_meta($post->ID, 'isc_image_source_url', true);
196 - $form_fields['isc_image_source_url']['helps'] = __('URL to link the source text to.', 'image-source-control-isc');
197 -
198 - // add input field for source
199 - $options = $this->get_isc_options();
200 - if($options['enable_licences'] && $licences = $this->licences_text_to_array($options['licences'])) {
201 - $form_fields['isc_image_licence']['input'] = 'html';
202 - $form_fields['isc_image_licence']['label'] = __('Image License', 'image-source-control-isc');
203 - $form_fields['isc_image_licence']['helps'] = __('Choose the image license.', 'image-source-control-isc');
204 - $html = '<select name="attachments['.$post->ID.'][isc_image_licence]" id="attachments['.$post->ID.'][isc_image_licence]">';
205 - $html .= '<option value="">--</option>';
206 - foreach($licences as $_licence_name => $_licence_data) {
207 - $html .= '<option value="'.$_licence_name.'" '.selected(get_post_meta($post->ID, 'isc_image_licence', true), $_licence_name, false) .'>'.$_licence_name.'</option>';
208 - }
209 - $html .= '</select>';
210 - $form_fields['isc_image_licence']['html'] = $html;
211 - }
212 -
213 - return $form_fields;
214 - }
215 -
216 - /**
217 - * save image source to post_meta
218 - *
219 - * @updated 1.5 added field for url
220 - *
221 - * @param object $post
222 - * @param $attachment
223 - * @return object $post
224 - */
225 - public function isc_fields_save($post, $attachment)
226 - {
227 - if (isset($attachment['isc_image_source'])) {
228 - update_post_meta($post['ID'], 'isc_image_source', trim($attachment['isc_image_source']));
229 - }
230 - if (isset($attachment['isc_image_source_url'])) {
231 - $url = esc_url_raw($attachment['isc_image_source_url']);
232 - update_post_meta($post['ID'], 'isc_image_source_url', $url);
233 - }
234 - $own = (isset($attachment['isc_image_source_own'])) ? $attachment['isc_image_source_own'] : '';
235 - update_post_meta($post['ID'], 'isc_image_source_own', $own);
236 - if (isset($attachment['isc_image_licence'])) {
237 - update_post_meta($post['ID'], 'isc_image_licence', $attachment['isc_image_licence']);
238 - }
239 -
240 - // remove transient that shows the warning, if true, to re-check image source warning with next call to admin_notices()
241 - $options = $this->get_isc_options();
242 - if( isset( $options['warning_onesource_missing'] )
243 - && $options['warning_onesource_missing']
244 - && get_transient( 'isc-show-missing-sources-warning' ) ){
245 -
246 - delete_transient( 'isc-show-missing-sources-warning' );
247 - };
248 -
249 - return $post;
250 - }
251 -
252 - /**
253 - * this is an entry function to save image information to a post when it is saved
254 - * @since 1.1
255 - * @param type $post_id
256 - */
257 - public function save_image_information_on_post_save($post_id)
258 - {
259 - // return, if save_post is called more than one time
260 - if ( did_action('save_post') !== 1
261 - || ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
262 - || ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) {
263 - return;
264 - }
265 -
266 - /**
267 - * don’t save meta data for non-public post types, since those shouldn’t be visible in the frontend
268 - * ignore also attachment posts
269 - */
270 - if ( ! isset( $_POST['post_type'] )
271 - || ! in_array( $_POST['post_type'], get_post_types( array( 'public' => true ), 'names' ) ) // is the post type public
272 - || 'attachment' == $_POST['post_type']) {
273 - return;
274 - }
275 -
276 - // check if this is a revision and if so, use parent post id
277 - if ($_id = wp_is_post_revision($post_id)) {
278 - $post_id = $_id;
279 - }
280 -
281 - $_content = '';
282 - if ( !empty( $_POST['content']) ) {
283 - $_content = stripslashes($_POST['content']);
284 - } else { // retrieve content with Gutenberg, because no content included in $_POST object then
285 - $_post = get_post( $post_id );
286 - if( isset( $_post->post_content ) ){
287 - $_content = $_post->post_content;
288 - }
289 - }
290 -
291 - // Needs to be called before the 'isc_post_images' field is updated.
292 - $this->update_image_posts_meta($post_id, $_content);
293 - $this->save_image_information($post_id, $_content);
294 - }
295 -
296 -
297 - public function attachment_added($att_id)
298 - {
299 - foreach ($this->_fields as $field) {
300 - update_post_meta($att_id, $field['id'], $field['default']);
301 - }
302 - }
303 -
304 - /**
305 - * The activation function
306 - */
307 - public function activation()
308 - {
309 - if (!is_array(get_option('isc_options'))) {
310 - update_option( 'isc_options', $this->default_options() );
311 - }
312 - $options = $this->get_isc_options();
313 - if (!$options['installed']) {
314 - /**
315 - * Here, all jobs to perform during first activation, especially options and custom fields.
316 - * Important: NO add_action('something', 'somefunction') here.
317 - */
318 -
319 - /**
320 - * auto indexation removed in version 1.6
321 - * not needed due to NOT EXISTS for meta fields since WP 3.5
322 - *
323 - * @todo remove the functions completely
324 - */
325 -
326 - // adds meta fields for attachments
327 - // $this->add_meta_values_to_attachments();
328 -
329 - // set all isc_image_posts meta fields.
330 - // $this->init_image_posts_metafield();
331 -
332 - $options['installed'] = true;
333 - update_option('isc_options', $options);
334 - }
335 - }
336 -
337 - /**
338 - * create the menu pages for isc
339 - *
340 - * @since 1.0
341 - */
342 - public function create_menu()
343 - {
344 - global $isc_missing;
345 - global $isc_setting;
346 -
347 - // These pages should be available only for editors and higher
348 - $isc_missing = add_submenu_page('upload.php', 'missing image sources by Image Source Control Plugin', __('Missing Sources', 'image-source-control-isc'), 'edit_others_posts', 'isc_missing_sources_page', array($this, 'render_missing_sources_page'));
349 - $isc_setting = add_options_page(__('Image control - ISC plugin', 'image-source-control-isc'), __('Image Sources', 'image-source-control-isc'), 'edit_others_posts', 'isc_settings_page', array($this, 'render_isc_settings_page'));
350 - }
351 -
352 - /**
353 - * Settings API initialization
354 - *
355 - * @update 1.3.5 added settings for sources
356 - * @todo rewrite this and following functions to a more practical form (esp. shorter) or at least bundle field into more useful sections
357 - */
358 - public function SAPI_init()
359 - {
360 - $this->upgrade_management();
361 - register_setting('isc_options_group', 'isc_options', array($this, 'settings_validation'));
362 - add_settings_section('isc_settings_section', '', '__return_false', 'isc_settings_page');
363 -
364 - // handle type of source display
365 - add_settings_field('source_display_type', __('How to display sources', 'image-source-control-isc'), array($this, 'renderfield_sources_display_type'), 'isc_settings_page', 'isc_settings_section');
366 -
367 - // settings for archive pages
368 - add_settings_field('list_on_archives', __('Sources below full posts', 'image-source-control-isc'), array($this, 'renderfield_list_on_archives'), 'isc_settings_page', 'isc_settings_section');
369 - add_settings_field('list_on_excerpts', __('Sources below excerpts', 'image-source-control-isc'), array($this, 'renderfield_list_on_excerpts'), 'isc_settings_page', 'isc_settings_section');
370 -
371 - // settings for sources list below single pages
372 - add_settings_field('image_list_headline', __('Image list headline', 'image-source-control-isc'), array($this, 'renderfield_list_headline'), 'isc_settings_page', 'isc_settings_section');
373 -
374 - // source in caption
375 - add_settings_field('source_caption', __("Overlay pre-text", 'image-source-control-isc'), array($this, 'renderfield_overlay_text'), 'isc_settings_page', 'isc_settings_section');
376 - add_settings_field('caption_position', __("Overlay position", 'image-source-control-isc'), array($this, 'renderfield_overlay_position'), 'isc_settings_page', 'isc_settings_section');
377 -
378 - // full image sources list group
379 - add_settings_field('use_thumbnail', __("Use thumbnails in images list", 'image-source-control-isc'), array($this, 'renderfield_use_thumbnail'), 'isc_settings_page', 'isc_settings_section');
380 - add_settings_field('thumbnail_width', __("Thumbnails max-width", 'image-source-control-isc'), array($this, 'renderfield_thumbnail_width'), 'isc_settings_page', 'isc_settings_section');
381 - add_settings_field('thumbnail_height', __("Thumbnails max-height", 'image-source-control-isc'), array($this, 'renderfield_thumbnail_height'), 'isc_settings_page', 'isc_settings_section');
382 -
383 - // Licence settings group
384 - add_settings_field('enable_licences', __("Enable licenses", 'image-source-control-isc'), array($this, 'renderfield_enable_licences'), 'isc_settings_page', 'isc_settings_section');
385 - add_settings_field('licences', __('List of licenses', 'image-source-control-isc'), array($this, 'renderfield_licences'), 'isc_settings_page', 'isc_settings_section');
386 -
387 - // Misc settings group
388 - add_settings_field('exclude_own_images', __('Exclude own images', 'image-source-control-isc'), array($this, 'renderfield_exclude_own_images'), 'isc_settings_page', 'isc_settings_section');
389 - add_settings_field('use_authorname', __('Use authors names', 'image-source-control-isc'), array($this, 'renderfield_use_authorname'), 'isc_settings_page', 'isc_settings_section');
390 - add_settings_field('by_author_text', __('Custom text for owned images', 'image-source-control-isc'), array($this, 'renderfield_byauthor_text'), 'isc_settings_page', 'isc_settings_section');
391 - add_settings_field('webgilde_backlink', __("Link to webgilde's website", 'image-source-control-isc'), array($this, 'renderfield_webgile'), 'isc_settings_page', 'isc_settings_section');
392 - add_settings_field('warning_one_source', __("Warning when there is at least one missing source", 'image-source-control-isc'), array($this, 'renderfield_warning_onesource_misisng'), 'isc_settings_page', 'isc_settings_section');
393 - add_settings_field('warning_nosource', __("Warnings when source not available", 'image-source-control-isc'), array($this, 'renderfield_warning_nosource'), 'isc_settings_page', 'isc_settings_section');
394 - }
395 -
396 - /**
397 - * manage data structure upgrading of outdated versions
398 - */
399 - public function upgrade_management() {
400 -
401 - /*
402 - * Since the activation hook is not executed on plugin upgrade, this function checks options in database
403 - * during the admin_init hook to handle plugin's upgrade.
404 - */
405 -
406 - $options = get_option('isc_options');
407 -
408 - if (is_array($options)) {
409 - // version 1.7 and higher
410 - if(version_compare('1.7', $options['version'], '>')){
411 - // convert old into new settings
412 - if(isset($options['attach_list_to_post'])){
413 - $options['display_type'][] = 'list';
414 - }
415 - if(isset($options['source_on_image'])){
416 - $options['display_type'][] = 'overlay';
417 - }
418 - }
419 - } else {
420 - // special case for version prior to 1.2 (which don't have options)
421 - $options = $this->default_options();
422 - $this->init_image_posts_metafield();
423 - $options['installed'] = true;
424 - update_option('isc_options', $options);
425 - }
426 -
427 - if (ISCVERSION != $options['version']) {
428 - $options = $options + $this->default_options();
429 - $options['version'] = ISCVERSION;
430 - update_option('isc_options', $options);
431 - }
432 -
433 - }
434 -
435 - /**
436 - * Image_control's page callback
437 - */
438 - public function render_isc_settings_page()
439 - {
440 - ?>
441 - <div id="icon-options-general" class="icon32"><br></div>
442 - <h2><?php _e('Images control settings', 'image-source-control-isc'); ?></h2>
443 - <div id="isc-admin-wrap">
444 - <form id="image-control-form" method="post" action="options.php">
445 - <div id="isc-setting-group-type" class="postbox isc-setting-group"><?php // Open the div for the first settings group ?>
446 - <h3 class="setting-group-head"><?php _e('How to display source in Frontend', 'image-source-control-isc'); ?></h3>
447 - <?php
448 - settings_fields( 'isc_options_group' );
449 - do_settings_sections( 'isc_settings_page' );
450 - ?>
451 - </div><?php //Close the last settings group div ?>
452 - <p class="submit">
453 - <input type="submit" name="submit" id="submit" class="button button-primary" value="Save Changes">
454 - </p>
455 - </form>
456 - </div><!-- #isc-admin-wrap -->
457 - <?php
458 - }
459 -
460 - /**
461 - * Missing sources page callback
462 - */
463 - public function render_missing_sources_page()
464 - {
465 - require_once(ISCPATH . '/admin/templates/missing_sources.php');
466 - }
467 -
468 - /**
469 - * *******************************
470 - * WordPress Setting API Callbacks
471 - * *******************************
472 - */
473 - /**
474 - * choose type of sources display in the frontend
475 - *
476 - * @since 1.7
477 - */
478 - public function renderfield_sources_display_type()
479 - {
480 - $options = $this->get_isc_options();
481 - ?>
482 - <p class="description"><?php echo __('Choose where to display image sources in the frontend', 'image-source-control-isc'); ?></p><br/>
483 - <div id="display_types_block">
484 - <input type="hidden" name="isc_options[display_type]" value=""/>
485 -
486 - <input type="checkbox" name="isc_options[display_type][]" id="display-types-list" value="list" <?php checked(in_array('list', $options['display_type']), true); ?> />
487 - <label for="display-types-list"><?php echo __('list below content', 'image-source-control-isc');; ?></label>
488 - <p class="description"><?php echo __('Displays a list of image sources below singular pages.', 'image-source-control-isc'); ?></p>
489 -
490 - <input type="checkbox" name="isc_options[display_type][]" id="display-types-overlay" value="overlay" <?php checked(in_array('overlay', $options['display_type']), true); ?> />
491 - <label for="display-types-overlay"><?php echo __('overlay', 'image-source-control-isc');; ?></label>
492 - <p class="description"><?php echo __('Display image source as a simple overlay', 'image-source-control-isc');; ?></p>
493 -
494 - <p><?php echo __('If you don’t want to use any of these methods, you can still place the image source list manually as described <a href="http://webgilde.com/en/image-source-control/image-sources-frontend/" title="external link" target="_blank">here</a>', 'image-source-control-isc');; ?></p>
495 - </div>
496 - </td></tr></tbody></table>
497 - </div><!-- .postbox -->
498 - <div id="isc-setting-group-list" class="postbox isc-setting-group">
499 - <h3 class="setting-group-head"><?php _e('Archive Pages', 'image-source-control-isc'); ?></h3>
500 - <table class="form-table"><tbody>
501 - <?php
502 - }
503 -
504 - /**
505 - * select the option for sources on archive pages
506 - *
507 - * @since 1.8
508 - */
509 - public function renderfield_list_on_archives()
510 - {
511 - $options = $this->get_isc_options();
512 - ?>
513 - <div id="display_types_block">
514 - <input type="checkbox" name="isc_options[list_on_archives]" id="list-on-archives" value="1" <?php checked(1, $options['list_on_archives'], true); ?> />
515 - <label for="list-on-archives"><?php echo __('Display sources list below full posts', 'image-source-control-isc');; ?></label>
516 - <p class="description"><?php echo __('Choose this option if you want to display the sources list attached to posts on archive and category pages that display the full content.', 'image-source-control-isc'); ?></p>
517 - </div>
518 - <?php
519 - }
520 -
521 - /**
522 - * select the option for sources on archive pages
523 - *
524 - * @since 1.8
525 - */
526 - public function renderfield_list_on_excerpts()
527 - {
528 - $options = $this->get_isc_options();
529 - ?>
530 - <div id="display_types_block">
531 - <input type="checkbox" name="isc_options[list_on_excerpts]" id="list-on-excerpts" value="1" <?php checked(1, $options['list_on_excerpts'], true); ?> />
532 - <label for="list-on-excerpts"><?php echo __('Display sources list below excerpts', 'image-source-control-isc');; ?></label>
533 - <p class="description"><?php echo __('Choose this option if you want to display the source of the featured image below the post excerpt. The source will be attached to the excerpt and it might happen that you see it everywhere. If this happens you should display the source manually in your template.', 'image-source-control-isc'); ?></p>
534 - </div>
535 - </td></tr></tbody></table>
536 - </div><!-- .postbox -->
537 - <div id="isc-setting-group-list" class="postbox isc-setting-group">
538 - <h3 class="setting-group-head"><?php _e('List below content', 'image-source-control-isc'); ?></h3>
539 - <table class="form-table"><tbody>
540 - <?php
541 - }
542 -
543 - public function renderfield_list_headline()
544 - {
545 - $options = $this->get_isc_options();
546 - $description = __('The headline of the image list added via shortcode or function in your theme.', 'image-source-control-isc');
547 - ?>
548 - <div id="image-list-headline-block">
549 - <label for="list-head"><?php __('Image list headline', 'image-source-control-isc'); ?></label>
550 - <input type="text" name="isc_options[image_list_headline_field]" id="list-head" value="<?php echo $options['image_list_headline'] ?>" class="regular-text" />
551 - <p><em><?php echo $description; ?></em></p>
552 - </div>
553 - </td></tr></tbody></table>
554 - </div><!-- .postbox -->
555 - <div id="isc-setting-group-overlay" class="postbox isc-setting-group">
556 - <h3 class="setting-group-head"><?php _e('Overlay', 'image-source-control-isc') ?></h3>
557 - <table class="form-table"><tbody>
558 - <?php
559 - }
560 -
561 - public function renderfield_overlay_text()
562 - {
563 - $options = $this->get_isc_options();
564 - ?>
565 - <div id="overlay-block">
566 - <input type="text" id='source-pretext' name="isc_options[source_pretext]" value="<?php echo $options['source_pretext']; ?>" />
567 - <p><em><?php echo __('The text preceding the source.' ,'image-source-control-isc'); ?></em></p>
568 - </div>
569 - <?php
570 - }
571 -
572 - public function renderfield_overlay_position()
573 - {
574 - $options = $this->get_isc_options();
575 - $description = __('Position of overlay into images' ,'image-source-control-isc');
576 - ?>
577 - <div id="caption-position-block">
578 - <select id="caption-pos" name="isc_options[cap_pos]">
579 - <?php foreach ($this->_caption_position as $pos) : ?>
580 - <option value="<?php echo $pos; ?>" <?php selected($pos, $options['caption_position']); ?>><?php echo $pos; ?></option>
581 - <?php endforeach; ?>
582 - </select>
583 - <p><em><?php echo $description; ?></em></p>
584 - </div>
585 - </td></tr></tbody></table>
586 - </div><!-- .postbox -->
587 - <div class="postbox isc-setting-group">
588 - <h3 class="setting-group-head"><?php _e('Full images list', 'image-source-control-isc') ?></h3>
589 - <table class="form-table"><tbody>
590 - <?php
591 - }
592 -
593 - /**
594 - * render option to exclude image from lists if it is makes as "by the author"
595 - *
596 - * @since 1.3.7
597 - */
598 - public function renderfield_exclude_own_images()
599 - {
600 - $options = $this->get_isc_options();
601 - $description = __("Exclude images marked as 'own image' from image lists (post and full) and overlay in the frontend. You can still manage them in the dashboard.", 'image-source-control-isc');
602 -
603 - ?>
604 - <div id="use-authorname-block">
605 - <label for="exclude_own_images"><?php _e('Hide sources for own images', 'image-source-control-isc') ?></label>
606 - <input type="checkbox" name="isc_options[exclude_own_images]" id="exclude_own_images" <?php checked($options['exclude_own_images']); ?> />
607 - <p><em><?php echo $description; ?></em></p>
608 - </div>
609 - <?php
610 - }
611 -
612 - public function renderfield_use_authorname()
613 - {
614 - $options = $this->get_isc_options();
615 - $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.", 'image-source-control-isc');
616 -
617 - ?>
618 - <div id="use-authorname-block">
619 - <label for="use_authorname"><?php _e('Use author name', 'image-source-control-isc') ?></label>
620 - <input type="checkbox" name="isc_options[use_authorname_ckbox]" id="use_authorname" <?php checked($options['use_authorname']); ?> />
621 - <p><em><?php echo $description; ?></em></p>
622 - </div>
623 - <?php
624 - }
625 -
626 - public function renderfield_byauthor_text()
627 - {
628 - $options = $this->get_isc_options();
629 - $description = __("Enter the custom text to display if you do not want to use the author's public name.", 'image-source-control-isc');
630 - ?>
631 - <div id="by-author-text">
632 - <input type="text" id="byauthor" name="isc_options[by_author_text_field]" value="<?php echo $options['by_author_text']; ?>" <?php disabled($options['use_authorname']); ?> class="regular-text" />
633 - <p><em><?php echo $description; ?></em></p>
634 - </div>
635 - <?php
636 - }
637 -
638 - public function renderfield_enable_licences()
639 - {
640 - $options = $this->get_isc_options();
641 - $description = __("Enable this to be able to add and display copyright/copyleft licenses for your images and manage them in the field below.", 'image-source-control-isc');
642 -
643 - ?>
644 - <div id="enable-licences">
645 - <input type="checkbox" name="isc_options[enable_licences]" id="enable_licences" <?php checked($options['enable_licences']); ?> />
646 - <p><em><?php echo $description; ?></em></p>
647 - </div>
648 - <?php
649 - }
650 -
651 - public function renderfield_licences()
652 - {
653 - $options = $this->get_isc_options();
654 - $description = __('List of licenses the author can choose for an image. Enter a license per line and separate the name from the optional link with a pipe symbol (e.g. <em>CC BY 2.0|http://creativecommons.org/licenses/by/2.0/legalcode</em>).' ,'image-source-control-isc');
655 -
656 - // fall back to default if field is empty
657 - if( empty( $options['licences'] ) ){
658 - // retrieve default options
659 - $default = ISC_Class::get_instance()->default_options();
660 - if( !empty( $default['licences'] ) ){
661 - $options['licences'] = $default['licences'];
662 - }
663 - }
664 -
665 - ?>
666 - <div id="licences">
667 - <textarea name="isc_options[licences]"><?php echo $options['licences'] ?></textarea>
668 - <p><em><?php echo $description; ?></em></p>
669 - </div>
670 - </td></tr></tbody></table>
671 - </div><!-- .postbox -->
672 - <div class="postbox isc-setting-group">
673 - <h3 class="setting-group-head"><?php _e('Miscellaneous settings', 'image-source-control-isc'); ?></h3>
674 - <table class="form-table"><tbody><tr>
675 - <?php
676 - }
677 -
678 - public function renderfield_webgile()
679 - {
680 - $options = $this->get_isc_options();
681 - $description = sprintf(__('Display a link to <a href="%s">Image Source Control plugin&#39;s website</a> below the list of all images in the blog?', 'image-source-control-isc'), WEBGILDE);
682 - ?>
683 - <div id="webgilde-block">
684 - <input type="checkbox" id="webgilde-link" name="isc_options[webgilde_field]" <?php checked($options['webgilde']); ?> />
685 - <p><em><?php echo $description; ?></em></p>
686 - </div>
687 - <?php
688 - }
689 -
690 - public function renderfield_use_thumbnail()
691 - {
692 - $options = $this->get_isc_options();
693 - $description = __('Display thumbnails on the list of all images in the blog.' ,'image-source-control-isc');
694 - ?>
695 - <div id="use-thumbnail-block">
696 - <input type="checkbox" id="use-thumbnail" name="isc_options[use_thumbnail]" value="1" <?php checked($options['thumbnail_in_list']); ?> />
697 - <select id="thumbnail-size-select" name="isc_options[size_select]" <?php disabled(!$options['thumbnail_in_list']) ?>>
698 - <?php foreach ($this->_thumbnail_size as $size) : ?>
699 - <option value="<?php echo $size; ?>" <?php selected($size, $options['thumbnail_size']);?>><?php echo $size; ?></option>
700 - <?php endforeach; ?>
701 - </select>
702 - <p><em><?php echo $description; ?></em></p>
703 - </div>
704 - <?php
705 - }
706 -
707 - public function renderfield_thumbnail_width()
708 - {
709 - $options = $this->get_isc_options();
710 - $description = __('Custom value of the maximum allowed width for thumbnail.' ,'image-source-control-isc');
711 - ?>
712 - <div id="thumbnail-custom-width">
713 - <input type="text" id="custom-width" name="isc_options[thumbnail_width]" class="small-text" value="<?php echo $options['thumbnail_width'] ?>" /> px
714 - <p><em><?php echo $description; ?></em></p>
715 - </div>
716 - <?php
717 - }
718 -
719 - public function renderfield_thumbnail_height()
720 - {
721 - $options = $this->get_isc_options();
722 - $description = __('Custom value of the maximum allowed height for thumbnail.' ,'image-source-control-isc');
723 - ?>
724 - <div id="thumbnail-custom-height">
725 - <input type="text" id="custom-height" name="isc_options[thumbnail_height]" class="small-text" value="<?php echo $options['thumbnail_height'] ?>"/> px
726 - <p><em><?php echo $description; ?></em></p>
727 - </div>
728 - </td></tr></tbody></table>
729 - </div><!-- .postbox -->
730 - <div class="postbox isc-setting-group">
731 - <h3 class="setting-group-head"><?php _e('Licenses settings', 'image-source-control-isc'); ?></h3>
732 - <table class="form-table"><tbody><tr>
733 - <?php
734 - }
735 -
736 - public function renderfield_warning_nosource()
737 - {
738 - $options = $this->get_isc_options();
739 - $description = __('Warn and prevent data to be saved when an attachment is edited and the source has not been specified.' ,'image-source-control-isc');
740 - ?>
741 - <div id="no-source-block">
742 - <input type="checkbox" id="no-source" name="isc_options[no_source]"value="1" <?php checked($options['warning_nosource']); ?>/>
743 - <p><em><?php echo $description; ?></em></p>
744 - </div>
745 - <?php
746 - }
747 -
748 - public function renderfield_warning_onesource_misisng()
749 - {
750 - $options = $this->get_isc_options();
751 - $description = __('Display an admin notice in admin pages when one or more image sources are missing.' ,'image-source-control-isc');
752 - ?>
753 - <div id="one-source-block">
754 - <input type="checkbox" id="one-source" name="isc_options[one_source]"value="1" <?php checked($options['warning_onesource_missing']); ?>/>
755 - <p><em><?php echo $description; ?></em></p>
756 - </div>
757 - <?php
758 - }
759 -
760 - /**
761 - * ****************************
762 - * End of Setting API Callbacks
763 - * ****************************
764 - */
765 -
766 - /**
767 - * get all attachments with empty sources string
768 - */
769 - public function get_attachments_with_empty_sources()
770 - {
771 - $args = array(
772 - 'post_type' => 'attachment',
773 - 'numberposts' => -1,
774 - 'post_status' => null,
775 - 'post_parent' => null,
776 - 'meta_query' => array(
777 - // image source is empty
778 - array(
779 - 'key' => 'isc_image_source',
780 - 'value' => '',
781 - 'compare' => '=',
782 - ),
783 - // and does not belong to an author
784 - array(
785 - 'key' => 'isc_image_source_own',
786 - 'value' => '1',
787 - 'compare' => '!=',
788 - ),
789 - )
790 - );
791 -
792 - $attachments = get_posts($args);
793 - if (!empty($attachments)) {
794 - return $attachments;
795 - }
796 - }
797 -
798 - /**
799 - * get all attachments without the proper meta values (needed mostly after installing the plugin for unindexed images)
800 - *
801 - * @since 1.6
802 - */
803 - public function get_attachments_without_sources()
804 - {
805 - $args = array(
806 - 'post_type' => 'attachment',
807 - 'numberposts' => -1,
808 - 'post_status' => null,
809 - 'post_parent' => null,
810 - 'meta_query' => array(
811 - // image source is empty
812 - array(
813 - 'key' => 'isc_image_source',
814 - 'value' => 'any', /* any string; needed prior to WP 3.9 */
815 - 'compare' => 'NOT EXISTS',
816 - ),
817 - )
818 - );
819 -
820 - $attachments = get_posts($args);
821 - if (!empty($attachments)) {
822 - return $attachments;
823 - }
824 - }
825 -
826 -
827 - /**
828 - * list image post relations (called with ajax)
829 - *
830 - * @since 1.6.1
831 - */
832 - public function list_post_image_relations(){
833 - // get all meta fields
834 - $args = array(
835 - 'posts_per_page' => -1,
836 - 'post_status' => null,
837 - 'post_parent' => null,
838 - 'meta_query' => array(
839 - array(
840 - 'key' => 'isc_post_images',
841 - ),
842 - )
843 - );
844 - $posts_with_images = new WP_Query($args);
845 -
846 - if($posts_with_images->have_posts()){
847 - require_once(ISCPATH . '/admin/templates/post_images_list.php');
848 - }
849 -
850 - wp_reset_postdata();
851 -
852 - die();
853 - }
854 -
855 - /**
856 - * list post image relations (called with ajax)
857 - *
858 - * @since 1.6.1
859 - */
860 - public function list_image_post_relations(){
861 - // get all images
862 - $args = array(
863 - 'post_type' => 'attachment',
864 - 'posts_per_page' => -1,
865 - 'post_status' => 'inherit',
866 - 'meta_query' => array(
867 - array(
868 - 'key' => 'isc_image_posts',
869 - ),
870 - )
871 - );
872 - $images_with_posts = new WP_Query($args);
873 -
874 - if($images_with_posts->have_posts()){
875 - require_once(ISCPATH . '/admin/templates/image_posts_list.php');
876 - }
877 -
878 - wp_reset_postdata();
879 -
880 - die();
881 - }
882 -
883 - /**
884 - * Input validation function.
885 - * @param array $input values from the admin panel
886 - * @updated 1.3.5 added licenses fields
887 - */
888 - public function settings_validation($input)
889 - {
890 - $output = $this->get_isc_options();
891 - if(!is_array($input['display_type'])){
892 - $output['display_type'] = array();
893 - } else {
894 - $output['display_type'] = $input['display_type'];
895 - }
896 - if(isset($input['list_on_archives'])){
897 - $output['list_on_archives'] = true;
898 - } else {
899 - $output['list_on_archives'] = false;
900 - }
901 - if(isset($input['list_on_excerpts'])){
902 - $output['list_on_excerpts'] = true;
903 - } else {
904 - $output['list_on_excerpts'] = false;
905 - }
906 - $output['image_list_headline'] = esc_html($input['image_list_headline_field']);
907 - if (isset($input['use_authorname_ckbox'])) {
908 - // Don't worry about the custom text if the author name is selected.
909 - $output['use_authorname'] = true;
910 - } else {
911 - $output['use_authorname'] = false;
912 - $output['by_author_text'] = esc_html($input['by_author_text_field']);
913 - }
914 - if (isset($input['exclude_own_images'])) {
915 - $output['exclude_own_images'] = true;
916 - } else {
917 - $output['exclude_own_images'] = false;
918 - }
919 - if (isset($input['webgilde_field'])) {
920 - $output['webgilde'] = true;
921 - } else {
922 - $output['webgilde'] = false;
923 - }
924 - if (isset($input['enable_licences'])) {
925 - $output['enable_licences'] = true;
926 - } else {
927 - $output['enable_licences'] = false;
928 - }
929 - if (isset($input['licences'])) {
930 - $output['licences'] = esc_textarea($input['licences']);
931 - } else {
932 - $output['licences'] = false;
933 - }
934 - if (isset($input['use_thumbnail'])) {
935 - $output['thumbnail_in_list'] = true;
936 - if (in_array($input['size_select'], $this->_thumbnail_size)) {
937 - $output['thumbnail_size'] = $input['size_select'];
938 - }
939 - if ('custom' == $input['size_select']) {
940 - if (is_numeric($input['thumbnail_width'])) {
941 - // Ensures that the value stored in database in a positive integer.
942 - $output['thumbnail_width'] = absint(round($input['thumbnail_width']));
943 - }
944 - if (is_numeric($input['thumbnail_height'])) {
945 - $output['thumbnail_height'] = absint(round($input['thumbnail_height']));
946 - }
947 - }
948 - } else {
949 - $output['thumbnail_in_list'] = false;
950 - }
951 - if (isset($input['no_source'])) {
952 - $output['warning_nosource'] = true;
953 - } else {
954 - $output['warning_nosource'] = false;
955 - }
956 - if (isset($input['one_source'])) {
957 - $output['warning_onesource_missing'] = true;
958 - } else {
959 - $output['warning_onesource_missing'] = false;
960 - }
961 - if (isset($input['hide_list'])){
962 - $output['hide_list'] = true;
963 - } else {
964 - $output['hide_list'] = false;
965 - }
966 - if (in_array($input['cap_pos'], $this->_caption_position))
967 - $output['caption_position'] = $input['cap_pos'];
968 - if (isset($input['source_pretext'])) {
969 - $output['source_pretext'] = esc_textarea($input['source_pretext']);
970 - }
971 - return $output;
972 - }
973 -
974 - }
975 -}
148 + /**
149 + * Actions to perform when an attachment is removed
150 + */
151 + public function clear_unused_images_stats() {
152 + // remove the transient with the unused image numbers
153 + delete_transient( 'isc-unused-attachments-stats' );
154 + }
155 +}