get_isc_options(); if( empty( $options['warning_onesource_missing'] ) ){ return; }; $show_warning = get_transient( 'isc-show-missing-sources-warning' ); // attachments without sources if( ! $show_warning ){ $args = array( 'post_type' => 'attachment', 'numberposts' => 1, 'post_status' => null, 'post_parent' => null, 'meta_query' => array( array( 'key' => 'isc_image_source', 'value' => '', 'compare' => '=' ), array( 'key' => 'isc_image_source_own', 'value' => '1', 'compare' => '!=', ) ) ); $attachments = get_posts($args); if( !empty( $attachments ) ){ $show_warning = true; } else { // load unindexed attachments $args = array( 'post_type' => 'attachment', 'numberposts' => 1, 'post_status' => null, 'post_parent' => null, 'meta_query' => array( array( 'key' => 'isc_image_source', 'value' => 'any', 'compare' => 'NOT EXISTS' ), ) ); $attachments2 = get_posts($args); if( !empty( $attachments2 ) ){ $show_warning = true; } } } if ( $show_warning ){ $missing_src = esc_url(admin_url('upload.php?page=isc_missing_sources_page')); ?>

missing sources list', 'image-source-control-isc'), $missing_src); ?>

section of admin page. Useful for creating js variables in the js global namespace. */ public function admin_headjs() { global $pagenow; $options = $this->get_isc_options(); if ('post.php' == $pagenow) { ?> ID, 'isc_image_source', true); $form_fields['isc_image_source']['helps'] = __('Include the image source here.', 'image-source-control-isc' ); // add checkbox to mark as your own image $form_fields['isc_image_source_own']['input'] = 'html'; $form_fields['isc_image_source_own']['label'] = ''; $form_fields['isc_image_source_own']['helps'] = __('Check this box if this is your own image and doesn\'t need a source.', 'image-source-control-isc'); $form_fields['isc_image_source_own']['html'] = "ID, 'isc_image_source_own', true), 1, false ) . " style=\"width:14px\"/> " . __('This is my image', 'image-source-control-isc'); // add input field for source url $form_fields['isc_image_source_url']['label'] = __('Image Source URL', 'image-source-control-isc'); $form_fields['isc_image_source_url']['value'] = get_post_meta($post->ID, 'isc_image_source_url', true); $form_fields['isc_image_source_url']['helps'] = __('URL to link the source text to.', 'image-source-control-isc'); // add input field for source $options = $this->get_isc_options(); if($options['enable_licences'] && $licences = $this->licences_text_to_array($options['licences'])) { $form_fields['isc_image_licence']['input'] = 'html'; $form_fields['isc_image_licence']['label'] = __('Image License', 'image-source-control-isc'); $form_fields['isc_image_licence']['helps'] = __('Choose the image license.', 'image-source-control-isc'); $html = ''; $form_fields['isc_image_licence']['html'] = $html; } return $form_fields; } /** * save image source to post_meta * * @updated 1.5 added field for url * * @param object $post * @param $attachment * @return object $post */ public function isc_fields_save($post, $attachment) { if (isset($attachment['isc_image_source'])) { update_post_meta($post['ID'], 'isc_image_source', trim($attachment['isc_image_source'])); } if (isset($attachment['isc_image_source_url'])) { $url = esc_url_raw($attachment['isc_image_source_url']); update_post_meta($post['ID'], 'isc_image_source_url', $url); } $own = (isset($attachment['isc_image_source_own'])) ? $attachment['isc_image_source_own'] : ''; update_post_meta($post['ID'], 'isc_image_source_own', $own); if (isset($attachment['isc_image_licence'])) { update_post_meta($post['ID'], 'isc_image_licence', $attachment['isc_image_licence']); } // remove transient that shows the warning, if true, to re-check image source warning with next call to admin_notices() $options = $this->get_isc_options(); if( isset( $options['warning_onesource_missing'] ) && $options['warning_onesource_missing'] && get_transient( 'isc-show-missing-sources-warning' ) ){ delete_transient( 'isc-show-missing-sources-warning' ); }; return $post; } /** * this is an entry function to save image information to a post when it is saved * @since 1.1 * @param type $post_id */ public function save_image_information_on_post_save($post_id) { // return, if save_post is called more than one time if ( did_action('save_post') !== 1 || ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) || ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) { return; } /** * don’t save meta data for non-public post types, since those shouldn’t be visible in the frontend * ignore also attachment posts */ if ( ! isset( $_POST['post_type'] ) || ! in_array( $_POST['post_type'], get_post_types( array( 'public' => true ), 'names' ) ) // is the post type public || 'attachment' == $_POST['post_type']) { return; } // check if this is a revision and if so, use parent post id if ($_id = wp_is_post_revision($post_id)) { $post_id = $_id; } $_content = ''; if ( !empty( $_POST['content']) ) { $_content = stripslashes($_POST['content']); } else { // retrieve content with Gutenberg, because no content included in $_POST object then $_post = get_post( $post_id ); if( isset( $_post->post_content ) ){ $_content = $_post->post_content; } } // Needs to be called before the 'isc_post_images' field is updated. $this->update_image_posts_meta($post_id, $_content); $this->save_image_information($post_id, $_content); } public function attachment_added($att_id) { foreach ($this->_fields as $field) { update_post_meta($att_id, $field['id'], $field['default']); } } /** * The activation function */ public function activation() { if (!is_array(get_option('isc_options'))) { update_option( 'isc_options', $this->default_options() ); } $options = $this->get_isc_options(); if (!$options['installed']) { /** * Here, all jobs to perform during first activation, especially options and custom fields. * Important: NO add_action('something', 'somefunction') here. */ /** * auto indexation removed in version 1.6 * not needed due to NOT EXISTS for meta fields since WP 3.5 * * @todo remove the functions completely */ // adds meta fields for attachments // $this->add_meta_values_to_attachments(); // set all isc_image_posts meta fields. // $this->init_image_posts_metafield(); $options['installed'] = true; update_option('isc_options', $options); } } /** * create the menu pages for isc * * @since 1.0 */ public function create_menu() { global $isc_missing; global $isc_setting; // These pages should be available only for editors and higher $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')); $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')); } /** * Settings API initialization * * @update 1.3.5 added settings for sources * @todo rewrite this and following functions to a more practical form (esp. shorter) or at least bundle field into more useful sections */ public function SAPI_init() { $this->upgrade_management(); register_setting('isc_options_group', 'isc_options', array($this, 'settings_validation')); add_settings_section('isc_settings_section', '', '__return_false', 'isc_settings_page'); // handle type of source display 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'); // settings for archive pages 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'); 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'); // settings for sources list below single pages add_settings_field('image_list_headline', __('Image list headline', 'image-source-control-isc'), array($this, 'renderfield_list_headline'), 'isc_settings_page', 'isc_settings_section'); // source in caption add_settings_field('source_caption', __("Overlay pre-text", 'image-source-control-isc'), array($this, 'renderfield_overlay_text'), 'isc_settings_page', 'isc_settings_section'); add_settings_field('caption_position', __("Overlay position", 'image-source-control-isc'), array($this, 'renderfield_overlay_position'), 'isc_settings_page', 'isc_settings_section'); // full image sources list group 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'); add_settings_field('thumbnail_width', __("Thumbnails max-width", 'image-source-control-isc'), array($this, 'renderfield_thumbnail_width'), 'isc_settings_page', 'isc_settings_section'); add_settings_field('thumbnail_height', __("Thumbnails max-height", 'image-source-control-isc'), array($this, 'renderfield_thumbnail_height'), 'isc_settings_page', 'isc_settings_section'); // Licence settings group add_settings_field('enable_licences', __("Enable licenses", 'image-source-control-isc'), array($this, 'renderfield_enable_licences'), 'isc_settings_page', 'isc_settings_section'); add_settings_field('licences', __('List of licenses', 'image-source-control-isc'), array($this, 'renderfield_licences'), 'isc_settings_page', 'isc_settings_section'); // Misc settings group 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'); add_settings_field('use_authorname', __('Use authors names', 'image-source-control-isc'), array($this, 'renderfield_use_authorname'), 'isc_settings_page', 'isc_settings_section'); 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'); add_settings_field('webgilde_backlink', __("Link to webgilde's website", 'image-source-control-isc'), array($this, 'renderfield_webgile'), 'isc_settings_page', 'isc_settings_section'); 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'); 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'); } /** * manage data structure upgrading of outdated versions */ public function upgrade_management() { /* * Since the activation hook is not executed on plugin upgrade, this function checks options in database * during the admin_init hook to handle plugin's upgrade. */ $options = get_option('isc_options'); if (is_array($options)) { // version 1.7 and higher if(version_compare('1.7', $options['version'], '>')){ // convert old into new settings if(isset($options['attach_list_to_post'])){ $options['display_type'][] = 'list'; } if(isset($options['source_on_image'])){ $options['display_type'][] = 'overlay'; } } } else { // special case for version prior to 1.2 (which don't have options) $options = $this->default_options(); $this->init_image_posts_metafield(); $options['installed'] = true; update_option('isc_options', $options); } if (ISCVERSION != $options['version']) { $options = $options + $this->default_options(); $options['version'] = ISCVERSION; update_option('isc_options', $options); } } /** * Image_control's page callback */ public function render_isc_settings_page() { ?>

get_isc_options(); ?>


/>

/>

here', 'image-source-control-isc');; ?>

get_isc_options(); ?>
/>

get_isc_options(); ?>
/>

get_isc_options(); $description = __('The headline of the image list added via shortcode or function in your theme.', 'image-source-control-isc'); ?>

get_isc_options(); ?>

get_isc_options(); $description = __('Position of overlay into images' ,'image-source-control-isc'); ?>

get_isc_options(); $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'); ?>
/>

get_isc_options(); $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'); ?>
/>

get_isc_options(); $description = __("Enter the custom text to display if you do not want to use the author's public name.", 'image-source-control-isc'); ?>
class="regular-text" />

get_isc_options(); $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'); ?>
/>

get_isc_options(); $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. CC BY 2.0|http://creativecommons.org/licenses/by/2.0/legalcode).' ,'image-source-control-isc'); // fall back to default if field is empty if( empty( $options['licences'] ) ){ // retrieve default options $default = ISC_Class::get_instance()->default_options(); if( !empty( $default['licences'] ) ){ $options['licences'] = $default['licences']; } } ?>

get_isc_options(); $description = sprintf(__('Display a link to Image Source Control plugin's website below the list of all images in the blog?', 'image-source-control-isc'), WEBGILDE); ?>
/>

get_isc_options(); $description = __('Display thumbnails on the list of all images in the blog.' ,'image-source-control-isc'); ?>
/>

get_isc_options(); $description = __('Custom value of the maximum allowed width for thumbnail.' ,'image-source-control-isc'); ?>
px

get_isc_options(); $description = __('Custom value of the maximum allowed height for thumbnail.' ,'image-source-control-isc'); ?>
px

get_isc_options(); $description = __('Warn and prevent data to be saved when an attachment is edited and the source has not been specified.' ,'image-source-control-isc'); ?>
/>

get_isc_options(); $description = __('Display an admin notice in admin pages when one or more image sources are missing.' ,'image-source-control-isc'); ?>
/>

'attachment', 'numberposts' => -1, 'post_status' => null, 'post_parent' => null, 'meta_query' => array( // image source is empty array( 'key' => 'isc_image_source', 'value' => '', 'compare' => '=', ), // and does not belong to an author array( 'key' => 'isc_image_source_own', 'value' => '1', 'compare' => '!=', ), ) ); $attachments = get_posts($args); if (!empty($attachments)) { return $attachments; } } /** * get all attachments without the proper meta values (needed mostly after installing the plugin for unindexed images) * * @since 1.6 */ public function get_attachments_without_sources() { $args = array( 'post_type' => 'attachment', 'numberposts' => -1, 'post_status' => null, 'post_parent' => null, 'meta_query' => array( // image source is empty array( 'key' => 'isc_image_source', 'value' => 'any', /* any string; needed prior to WP 3.9 */ 'compare' => 'NOT EXISTS', ), ) ); $attachments = get_posts($args); if (!empty($attachments)) { return $attachments; } } /** * list image post relations (called with ajax) * * @since 1.6.1 */ public function list_post_image_relations(){ // get all meta fields $args = array( 'posts_per_page' => -1, 'post_status' => null, 'post_parent' => null, 'meta_query' => array( array( 'key' => 'isc_post_images', ), ) ); $posts_with_images = new WP_Query($args); if($posts_with_images->have_posts()){ require_once(ISCPATH . '/admin/templates/post_images_list.php'); } wp_reset_postdata(); die(); } /** * list post image relations (called with ajax) * * @since 1.6.1 */ public function list_image_post_relations(){ // get all images $args = array( 'post_type' => 'attachment', 'posts_per_page' => -1, 'post_status' => 'inherit', 'meta_query' => array( array( 'key' => 'isc_image_posts', ), ) ); $images_with_posts = new WP_Query($args); if($images_with_posts->have_posts()){ require_once(ISCPATH . '/admin/templates/image_posts_list.php'); } wp_reset_postdata(); die(); } /** * Input validation function. * @param array $input values from the admin panel * @updated 1.3.5 added licenses fields */ public function settings_validation($input) { $output = $this->get_isc_options(); if(!is_array($input['display_type'])){ $output['display_type'] = array(); } else { $output['display_type'] = $input['display_type']; } if(isset($input['list_on_archives'])){ $output['list_on_archives'] = true; } else { $output['list_on_archives'] = false; } if(isset($input['list_on_excerpts'])){ $output['list_on_excerpts'] = true; } else { $output['list_on_excerpts'] = false; } $output['image_list_headline'] = esc_html($input['image_list_headline_field']); if (isset($input['use_authorname_ckbox'])) { // Don't worry about the custom text if the author name is selected. $output['use_authorname'] = true; } else { $output['use_authorname'] = false; $output['by_author_text'] = esc_html($input['by_author_text_field']); } if (isset($input['exclude_own_images'])) { $output['exclude_own_images'] = true; } else { $output['exclude_own_images'] = false; } if (isset($input['webgilde_field'])) { $output['webgilde'] = true; } else { $output['webgilde'] = false; } if (isset($input['enable_licences'])) { $output['enable_licences'] = true; } else { $output['enable_licences'] = false; } if (isset($input['licences'])) { $output['licences'] = esc_textarea($input['licences']); } else { $output['licences'] = false; } if (isset($input['use_thumbnail'])) { $output['thumbnail_in_list'] = true; if (in_array($input['size_select'], $this->_thumbnail_size)) { $output['thumbnail_size'] = $input['size_select']; } if ('custom' == $input['size_select']) { if (is_numeric($input['thumbnail_width'])) { // Ensures that the value stored in database in a positive integer. $output['thumbnail_width'] = absint(round($input['thumbnail_width'])); } if (is_numeric($input['thumbnail_height'])) { $output['thumbnail_height'] = absint(round($input['thumbnail_height'])); } } } else { $output['thumbnail_in_list'] = false; } if (isset($input['no_source'])) { $output['warning_nosource'] = true; } else { $output['warning_nosource'] = false; } if (isset($input['one_source'])) { $output['warning_onesource_missing'] = true; } else { $output['warning_onesource_missing'] = false; } if (isset($input['hide_list'])){ $output['hide_list'] = true; } else { $output['hide_list'] = false; } if (in_array($input['cap_pos'], $this->_caption_position)) $output['caption_position'] = $input['cap_pos']; if (isset($input['source_pretext'])) { $output['source_pretext'] = esc_textarea($input['source_pretext']); } return $output; } } }