| 1 |
<?php |
| 2 |
|
| 3 |
namespace ISC\Settings\Sections; |
| 4 |
|
| 5 |
use ISC\Settings; |
| 6 |
use ISC\Image_Sources\Image_Sources; |
| 7 |
|
| 8 |
/** |
| 9 |
* Handle settings for page-list image source displays |
| 10 |
*/ |
| 11 |
class Global_List extends Settings\Section { |
| 12 |
|
| 13 |
/** |
| 14 |
* Add settings section |
| 15 |
*/ |
| 16 |
public function add_settings_section() { |
| 17 |
add_settings_section( 'isc_settings_section_complete_list', __( 'Global list', 'image-source-control-isc' ), [ $this, 'render_settings_section' ], 'isc_settings_page' ); |
| 18 |
add_settings_field( 'global_list_included_images', __( 'Included images', 'image-source-control-isc' ), [ $this, 'render_field_global_list_included_images' ], 'isc_settings_page', 'isc_settings_section_complete_list' ); |
| 19 |
add_settings_field( 'images_per_page_in_list', __( 'Images per page', 'image-source-control-isc' ), [ $this, 'render_field_images_per_page_in_list' ], 'isc_settings_page', 'isc_settings_section_complete_list' ); |
| 20 |
add_settings_field( 'global_list_layout', __( 'Layout', 'image-source-control-isc' ), [ $this, 'render_field_global_list_layout' ], 'isc_settings_page', 'isc_settings_section_complete_list' ); |
| 21 |
add_settings_field( 'global_list_included_data', __( 'Included data', 'image-source-control-isc' ), [ $this, 'render_field_global_list_data' ], 'isc_settings_page', 'isc_settings_section_complete_list' ); |
| 22 |
} |
| 23 |
|
| 24 |
/** |
| 25 |
* Render the settings section |
| 26 |
*/ |
| 27 |
public function render_settings_section() { |
| 28 |
require_once ISCPATH . '/admin/templates/settings/global-list/section.php'; |
| 29 |
} |
| 30 |
|
| 31 |
/** |
| 32 |
* Render option to define which images should show in the global list |
| 33 |
*/ |
| 34 |
public function render_field_global_list_included_images() { |
| 35 |
$options = $this->get_options(); |
| 36 |
$included_images = ! empty( $options['global_list_included_images'] ) ? $options['global_list_included_images'] : ''; |
| 37 |
$included_images_options = $this->get_included_images_options(); |
| 38 |
$indexed_images = ! empty( $options['global_list_indexed_images'] ); |
| 39 |
$is_pro_enabled = \ISC\Plugin::is_pro(); |
| 40 |
|
| 41 |
require_once ISCPATH . '/admin/templates/settings/global-list/included-images.php'; |
| 42 |
require_once ISCPATH . '/admin/templates/settings/global-list/indexed-images.php'; |
| 43 |
} |
| 44 |
|
| 45 |
/** |
| 46 |
* Render option for the number of images per page in the Global list |
| 47 |
*/ |
| 48 |
public function render_field_images_per_page_in_list() { |
| 49 |
$options = $this->get_options(); |
| 50 |
$images_per_page = isset( $options['images_per_page'] ) ? absint( $options['images_per_page'] ) : 99999; |
| 51 |
require_once ISCPATH . '/admin/templates/settings/global-list/images-per-page.php'; |
| 52 |
} |
| 53 |
|
| 54 |
/** |
| 55 |
* Render option to define the layout of the global list |
| 56 |
*/ |
| 57 |
public function render_field_global_list_layout() { |
| 58 |
$manual_url = \ISC\Admin_Utils::get_isc_localized_website_url( |
| 59 |
'documentation/customizations/#Styling_the_global_list', |
| 60 |
'dokumentation/anpassungen/#Die_Globale_Quellenliste_stylen', |
| 61 |
'global-list-layout' |
| 62 |
); |
| 63 |
require_once ISCPATH . '/admin/templates/settings/global-list/layout.php'; |
| 64 |
} |
| 65 |
|
| 66 |
/** |
| 67 |
* Render option to define which columns show up the global list |
| 68 |
*/ |
| 69 |
public function render_field_global_list_data() { |
| 70 |
$options = $this->get_options(); |
| 71 |
$included_columns = ! empty( $options['global_list_included_data'] ) ? $options['global_list_included_data'] : []; |
| 72 |
$included_columns_options = $this->get_included_data_options(); |
| 73 |
require_once ISCPATH . '/admin/templates/settings/global-list/data.php'; |
| 74 |
} |
| 75 |
|
| 76 |
/** |
| 77 |
* Render option to display thumbnails in the Global list |
| 78 |
*/ |
| 79 |
public function render_field_thumbnail_in_list() { |
| 80 |
$options = $this->get_options(); |
| 81 |
$sizes = []; |
| 82 |
$sizes_labels = [ |
| 83 |
'thumbnail' => _x( 'Thumbnail', 'image size label', 'image-source-control-isc' ), |
| 84 |
'medium' => _x( 'Medium', 'image size label', 'image-source-control-isc' ), |
| 85 |
'large' => _x( 'Large', 'image size label', 'image-source-control-isc' ), |
| 86 |
'custom' => _x( 'Custom', 'image size label', 'image-source-control-isc' ), |
| 87 |
]; |
| 88 |
|
| 89 |
// convert the sizes array to match key and value |
| 90 |
foreach ( Image_Sources::get_thumbnail_sizes() as $_size ) { |
| 91 |
$sizes[ $_size ] = $_size; |
| 92 |
} |
| 93 |
|
| 94 |
// go through sizes we consider for thumbnails and get their current sizes as set up in WordPress |
| 95 |
$wp_image_sizes = wp_get_registered_image_subsizes(); |
| 96 |
if ( is_array( $wp_image_sizes ) ) { |
| 97 |
foreach ( $wp_image_sizes as $_name => $_sizes ) { |
| 98 |
if ( isset( $sizes[ $_name ] ) ) { |
| 99 |
$sizes[ $_name ] = $_sizes; |
| 100 |
} |
| 101 |
} |
| 102 |
} |
| 103 |
|
| 104 |
require_once ISCPATH . '/admin/templates/settings/global-list/thumbnail-enable.php'; |
| 105 |
} |
| 106 |
|
| 107 |
|
| 108 |
/** |
| 109 |
* Get the options for which columns appear in the global list |
| 110 |
*/ |
| 111 |
public function get_included_data_options() { |
| 112 |
$included_columns_options = [ |
| 113 |
'attachment_id' => [ |
| 114 |
'label' => __( 'Attachment ID', 'image-source-control-isc' ), |
| 115 |
'is_pro' => true, |
| 116 |
], |
| 117 |
'title' => [ |
| 118 |
'label' => __( 'Title', 'image-source-control-isc' ), |
| 119 |
'is_pro' => true, |
| 120 |
], |
| 121 |
'posts' => [ |
| 122 |
'label' => __( 'Attached to', 'image-source-control-isc' ), |
| 123 |
'is_pro' => true, |
| 124 |
], |
| 125 |
'source' => [ |
| 126 |
'label' => __( 'Source', 'image-source-control-isc' ), |
| 127 |
'is_pro' => true, |
| 128 |
], |
| 129 |
]; |
| 130 |
|
| 131 |
return apply_filters( 'isc_global_list_included_data_options', $included_columns_options ); |
| 132 |
} |
| 133 |
|
| 134 |
|
| 135 |
/** |
| 136 |
* Get the options for images that appear in the global list |
| 137 |
*/ |
| 138 |
public function get_included_images_options() { |
| 139 |
$included_images_options = [ |
| 140 |
'in_posts' => [ |
| 141 |
'label' => __( 'Images in the content', 'image-source-control-isc' ), |
| 142 |
'description' => __( 'Only images that are used within the post and page content.', 'image-source-control-isc' ), |
| 143 |
'value' => '', |
| 144 |
], |
| 145 |
'all' => [ |
| 146 |
'label' => __( 'All images', 'image-source-control-isc' ), |
| 147 |
'description' => __( 'All images in the Media library, regardless of whether they are used within the post and page content or not', 'image-source-control-isc' ), |
| 148 |
'value' => 'all', |
| 149 |
'is_pro' => false, |
| 150 |
], |
| 151 |
'with_sources' => [ |
| 152 |
'label' => __( 'Images with sources', 'image-source-control-isc' ), |
| 153 |
'description' => __( 'All images in the Media library that have an individual source or use the standard source.', 'image-source-control-isc' ), |
| 154 |
'value' => 'with_sources', |
| 155 |
'is_pro' => true, |
| 156 |
], |
| 157 |
]; |
| 158 |
|
| 159 |
return apply_filters( 'isc_global_list_included_images_options', $included_images_options ); |
| 160 |
} |
| 161 |
|
| 162 |
|
| 163 |
/** |
| 164 |
* Validate settings |
| 165 |
* |
| 166 |
* @param array $output output data. |
| 167 |
* @param array $input input data. |
| 168 |
* |
| 169 |
* @return array $output |
| 170 |
*/ |
| 171 |
public function validate_settings( array $output, array $input ): array { |
| 172 |
$output['images_per_page'] = absint( $input['images_per_page'] ); |
| 173 |
$output['global_list_included_images'] = isset( $input['global_list_included_images'] ) ? esc_attr( $input['global_list_included_images'] ) : ''; |
| 174 |
|
| 175 |
if ( ! empty( $input['thumbnail_in_list'] ) ) { |
| 176 |
$output['thumbnail_in_list'] = true; |
| 177 |
if ( in_array( $input['thumbnail_size'], Image_Sources::get_thumbnail_sizes(), true ) ) { |
| 178 |
$output['thumbnail_size'] = $input['thumbnail_size']; |
| 179 |
} |
| 180 |
if ( 'custom' === $input['thumbnail_size'] ) { |
| 181 |
if ( is_numeric( $input['thumbnail_width'] ) ) { |
| 182 |
// Ensures that the value stored in database in a positive integer. |
| 183 |
$output['thumbnail_width'] = absint( round( $input['thumbnail_width'] ) ); |
| 184 |
} |
| 185 |
if ( is_numeric( $input['thumbnail_height'] ) ) { |
| 186 |
$output['thumbnail_height'] = absint( round( $input['thumbnail_height'] ) ); |
| 187 |
} |
| 188 |
} |
| 189 |
} else { |
| 190 |
$output['thumbnail_in_list'] = false; |
| 191 |
} |
| 192 |
|
| 193 |
return $output; |
| 194 |
} |
| 195 |
} |
| 196 |
|