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
image-source-control-isc / includes / settings / sections / caption.php

caption.php in Image Source Control Lite – Show Image Credits and Captions trunk, at includes/settings/sections/caption.php

271 lines 9.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace ISC\Settings\Sections;
4
5 use ISC\Settings;
6
7 /**
8 * Handle caption/overlay settings
9 */
10 class Caption extends Settings\Section {
11
12 /**
13 * Position of image's caption
14 *
15 * @var array available positions for the image source overlay.
16 */
17 protected $caption_position = [
18 'top-left',
19 'top-center',
20 'top-right',
21 'center',
22 'bottom-left',
23 'bottom-center',
24 'bottom-right',
25 ];
26
27 /**
28 * Add settings section
29 */
30 public function add_settings_section() {
31
32 // source in caption
33 add_settings_section( 'isc_settings_section_overlay', __( 'Overlay', 'image-source-control-isc' ), '__return_false', 'isc_settings_page' );
34 add_settings_field( 'source_type_overlay', __( 'Enable', 'image-source-control-isc' ), [ $this, 'render_field_source_type_overlay' ], 'isc_settings_page', 'isc_settings_section_overlay' );
35 add_settings_field( 'source_overlay', __( 'Overlay prefix', 'image-source-control-isc' ), [ $this, 'render_field_overlay_text' ], 'isc_settings_page', 'isc_settings_section_overlay' );
36 add_settings_field( 'overlay_style', __( 'Layout', 'image-source-control-isc' ), [ $this, 'render_field_overlay_style' ], 'isc_settings_page', 'isc_settings_section_overlay' );
37 add_settings_field( 'overlay_included_images', __( 'Included images', 'image-source-control-isc' ), [ $this, 'render_field_overlay_included_images' ], 'isc_settings_page', 'isc_settings_section_overlay' );
38
39 if ( defined( 'ELEMENTOR_VERSION' ) ) {
40 add_action( 'isc_admin_settings_overlay_included_images_after', [ $this, 'render_field_elementor' ] );
41 }
42
43 if ( class_exists( 'ET_Builder_Element', false ) ) {
44 add_action( 'isc_admin_settings_overlay_included_images_after', [ $this, 'render_field_divi' ] );
45 }
46 }
47
48 /**
49 * Render the option to enable Overlays
50 */
51 public function render_field_source_type_overlay() {
52 $options = $this->get_options();
53 require_once ISCPATH . '/admin/templates/settings/caption/enable.php';
54 }
55
56 /**
57 * Render option for the text preceding the source.
58 */
59 public function render_field_overlay_text() {
60 $options = $this->get_options();
61 require_once ISCPATH . '/admin/templates/settings/caption/overlay-text.php';
62 }
63
64 /**
65 * Render option for the style of the overlay
66 */
67 public function render_field_overlay_style() {
68 $options = $this->get_options();
69 $caption_style = $this->get_caption_style();
70 $caption_style_options = $this->get_caption_style_options();
71 require_once ISCPATH . '/admin/templates/settings/caption/style.php';
72 require_once ISCPATH . '/admin/templates/settings/caption/overlay-position.php';
73 }
74
75 /**
76 * Render option to define which images should show the overlay
77 */
78 public function render_field_overlay_included_images() {
79 $options = $this->get_options();
80 $included_images = ! empty( $options['overlay_included_images'] ) ? $options['overlay_included_images'] : '';
81 $included_images_options = $this->get_included_images_options();
82 require_once ISCPATH . '/admin/templates/settings/caption/overlay-included-images.php';
83 $checked_advanced_options = ! empty( $options['overlay_included_advanced'] ) && is_array( $options['overlay_included_advanced'] ) ? $options['overlay_included_advanced'] : [];
84 $advanced_options = $this->get_advanced_included_images_options();
85 require_once ISCPATH . '/admin/templates/settings/caption/overlay-advanced-included-images.php';
86 }
87
88 /**
89 * Get the selected caption style option
90 *
91 * @return string
92 */
93 public function get_caption_style(): string {
94 $options = $this->get_options();
95 return ! empty( $options['caption_style'] ) ? $options['caption_style'] : 'fulltext';
96 }
97
98 /**
99 * Get the options for the caption style
100 */
101 public function get_caption_style_options() {
102 $caption_style_options = [
103 'fulltext' => [
104 'label' => __( 'Full credit line', 'image-source-control-isc' ),
105 'value' => 'fulltext',
106 ],
107 'hover' => [
108 'label' => __( 'Prefix extends on hover', 'image-source-control-isc' ),
109 'value' => 'hover',
110 'is_pro' => true,
111 ],
112 'click' => [
113 'label' => __( 'Prefix extends on click', 'image-source-control-isc' ),
114 'value' => 'click',
115 'is_pro' => true,
116 ],
117 'none' => [
118 'label' => __( 'Unstyled credit line below the image', 'image-source-control-isc' ),
119 'description' => __( 'Deliver the overlay content without any markup and style.', 'image-source-control-isc' ) . ' ' .
120 sprintf(
121 // translators: %s is "<code>captions.js</code>"
122 __( 'Removes also %s.', 'image-source-control-isc' ),
123 '<code>captions.js</code>'
124 ),
125 'value' => 'none',
126 ],
127 ];
128
129 return apply_filters( 'isc_caption_style_options', $caption_style_options );
130 }
131
132 /**
133 * Get the options for images that get an overlay with the source
134 */
135 public function get_included_images_options() {
136 $included_images_options = [
137 'default' => [
138 'label' => __( 'Images in the content', 'image-source-control-isc' ),
139 'description' => sprintf(
140 // translators: %1$s is "img" and %2$s stands for "the_content" wrapped in "code" tags
141 __( 'Technically: %1$s tags within %2$s.', 'image-source-control-isc' ),
142 '<code>img</code>',
143 '<code>the_content</code>'
144 ),
145 'value' => '',
146 'coming_soon' => false,
147 ],
148 'body_img' => [
149 'label' => __( 'Images on the whole page', 'image-source-control-isc' ),
150 'description' =>
151 __( 'Including featured image, header, sidebar, and footer.', 'image-source-control-isc' ) . ' ' .
152 sprintf(
153 // translators: %1$s is "img" and %2$s stands for "body" wrapped in "code" tags
154 __( 'Technically: %1$s tags within %2$s.', 'image-source-control-isc' ),
155 '<code>img</code>',
156 '<code>body</code>'
157 ),
158 'value' => 'body_img',
159 'is_pro' => true,
160 ],
161 ];
162
163 return apply_filters( 'isc_overlay_included_images_options', $included_images_options );
164 }
165
166 /**
167 * Get the advanced options for images that get an overlay with the source
168 * These will be checkboxes. One can enable multiple options at once.
169 */
170 public function get_advanced_included_images_options() {
171 $options = [
172 'inline_style_data' => [
173 'label' => __( 'Load the overlay text for inline styles', 'image-source-control-isc' ),
174 'value' => 'inline_style_data',
175 'is_pro' => true,
176 ],
177 'inline_style_show' => [
178 'label' => __( 'Display the overlay within HTML tags that use inline styles', 'image-source-control-isc' ),
179 'value' => 'inline_style_show',
180 'is_pro' => true,
181 ],
182 'style_block_data' => [
183 'label' => sprintf(
184 // translators: %s is "<code>style</code>"
185 __( 'Load the overlay text for %s tags', 'image-source-control-isc' ),
186 '<code>style</code>'
187 ),
188 'value' => 'style_block_data',
189 'is_pro' => true,
190 ],
191 'style_block_show' => [
192 'label' => sprintf(
193 // translators: %s is "<code>style</code>"
194 __( 'Display the overlay after %s tags', 'image-source-control-isc' ),
195 '<code>style</code>'
196 ),
197 'value' => 'style_block_show',
198 'is_pro' => true,
199 ],
200 ];
201
202 // push Avada Builder option as the first option
203 if ( defined( 'FUSION_BUILDER_VERSION' ) ) {
204 $avada_builder_option = [
205 'label' => 'Avada Builder: ' . __( 'Display the overlay text for background images', 'image-source-control-isc' ),
206 'value' => 'avada_background_overlay',
207 'is_pro' => true,
208 ];
209 array_unshift( $options, $avada_builder_option );
210 }
211
212 // push WP Bakery option as the first option
213 if ( defined( 'WPB_VC_VERSION' ) ) {
214 $wp_bakery_option = [
215 'label' => 'WP Bakery: ' . __( 'Display the overlay text for background images', 'image-source-control-isc' )
216 . '. ' . sprintf(
217 '<a href="%s" target="_blank">%s</a>',
218 'https://imagesourcecontrol.com/documentation/compatibility/#WPBakery_Page_Builder',
219 __( 'Manual', 'image-source-control-isc' )
220 ),
221 'value' => 'wp_bakery_background_overlay',
222 'is_pro' => true,
223 ];
224 array_unshift( $options, $wp_bakery_option );
225 }
226
227 return apply_filters( 'isc_overlay_advanced_included_images_options', $options );
228 }
229
230 /**
231 * Validate settings
232 *
233 * @param array $output output data.
234 * @param array $input input data.
235 *
236 * @return array $output
237 */
238 public function validate_settings( array $output, array $input ): array {
239 if ( isset( $input['caption_position'] ) && in_array( $input['caption_position'], $this->caption_position, true ) ) {
240 $output['caption_position'] = $input['caption_position'];
241 }
242 $output['caption_style'] = ! empty( $input['caption_style'] ) ? $input['caption_style'] : null;
243 if ( isset( $input['source_pretext'] ) ) {
244 $output['source_pretext'] = esc_textarea( $input['source_pretext'] );
245 }
246
247 $output['overlay_included_images'] = isset( $input['overlay_included_images'] ) ? esc_attr( $input['overlay_included_images'] ) : '';
248 $output['overlay_included_advanced'] = isset( $input['overlay_included_advanced'] ) && is_array( $input['overlay_included_advanced'] ) ? $input['overlay_included_advanced'] : [];
249
250 return $output;
251 }
252
253 /**
254 * Render option for Elementor background images support in the Included Images section
255 */
256 public function render_field_elementor() {
257 if ( ! \ISC\Plugin::is_pro() ) {
258 require_once ISCPATH . '/admin/templates/settings/caption/elementor.php';
259 }
260 }
261
262 /**
263 * Render option for Divi background images support in the Included Images section
264 */
265 public function render_field_divi() {
266 if ( ! \ISC\Plugin::is_pro() ) {
267 require_once ISCPATH . '/admin/templates/settings/caption/divi.php';
268 }
269 }
270 }
271