PluginProbe ʕ •ᴥ•ʔ
External Links – nofollow, noopener & new window / 2.48
External Links – nofollow, noopener & new window v2.48
0.31 0.32 0.33 0.34 0.35 1.01 1.02 1.03 1.10 1.20 1.21 1.30 1.31 1.40 1.41 1.50 1.51 1.52 1.53 1.54 1.55 1.56 1.60 1.61 1.62 1.70 1.80 1.81 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.1.0 2.1.1 2.1.2 2.1.3 2.2.0 2.3 2.32 2.35 2.40 2.42 2.43 2.45 2.46 2.47 2.48 2.50 2.51 2.55 2.56 2.57 2.58 2.59 2.60 2.61 2.62 2.63 2.64 2.65 trunk 0.10 0.11 0.12 0.20 0.21 0.30
wp-external-links / includes / admin / settings-fields / class-wpel-link-fields-base.php
wp-external-links / includes / admin / settings-fields Last commit date
class-wpel-admin-fields.php 7 years ago class-wpel-exceptions-fields.php 7 years ago class-wpel-excluded-link-fields.php 7 years ago class-wpel-external-link-fields.php 6 years ago class-wpel-internal-link-fields.php 7 years ago class-wpel-link-fields-base.php 6 years ago
class-wpel-link-fields-base.php
341 lines
1 <?php
2 /**
3 * Class WPEL_Link_Fields_Base
4 *
5 * @package WPEL
6 * @category WordPress Plugin
7 * @version 2.3
8 * @link https://www.webfactoryltd.com/
9 * @license Dual licensed under the MIT and GPLv2+ licenses
10 */
11 abstract class WPEL_Link_Fields_Base extends FWP_Settings_Section_Base_1x0x0
12 {
13
14 /**
15 * Get general fields
16 * @return array
17 */
18 final protected function get_general_fields()
19 {
20 return array(
21 'apply_settings' => array(
22 'label' => __( 'Settings for links:', 'wp-external-links' ),
23 'class' => 'js-apply-settings',
24 ),
25 'target' => array(
26 'label' => __( 'Open links:', 'wp-external-links' ),
27 'class' => 'wpel-hidden',
28 'default_value' => '',
29 ),
30 'target_overwrite' => array(
31 'label' => '',
32 'class' => 'wpel-no-label wpel-hidden',
33 ),
34 'rel_follow' => array(
35 'label' => __( 'Set <code>follow</code> or <code>nofollow</code>:', 'wp-external-links' ),
36 'class' => 'wpel-hidden',
37 'default_value' => '',
38 ),
39 'rel_follow_overwrite' => array(
40 'label' => '',
41 'class' => 'wpel-no-label wpel-hidden',
42 ),
43 'rel_noopener' => array(
44 'label' => __( 'Also add to <code>rel</code> attribute:', 'wp-external-links' ),
45 'class' => 'wpel-hidden',
46 'default_value' => '1',
47 ),
48 'rel_noreferrer' => array(
49 'label' => '',
50 'class' => 'wpel-no-label wpel-hidden',
51 'default_value' => '1',
52 ),
53 'title' => array(
54 'label' => __( 'Set <code>title</code>:', 'wp-external-links' ),
55 'class' => 'wpel-hidden',
56 'default_value' => '{title}',
57 ),
58 'class' => array(
59 'label' => __( 'Add CSS class(es):', 'wp-external-links' ),
60 'class' => 'wpel-hidden',
61 ),
62 'icon_type' => array(
63 'label' => __( 'Choose icon type:', 'wp-external-links' ),
64 'class' => 'js-icon-type wpel-hidden',
65 ),
66 'icon_image' => array(
67 'label' => __( 'Choose icon image:', 'wp-external-links' ),
68 'class' => 'js-icon-type-child js-icon-type-image wpel-hidden',
69 'default_value' => '1',
70 ),
71 'icon_dashicon' => array(
72 'label' => __( 'Choose dashicon:', 'wp-external-links' ),
73 'class' => 'js-icon-type-child js-icon-type-dashicon wpel-hidden',
74 ),
75 'icon_fontawesome' => array(
76 'label' => __( 'Choose FA icon:', 'wp-external-links' ),
77 'class' => 'js-icon-type-child js-icon-type-fontawesome wpel-hidden',
78 ),
79 'icon_position' => array(
80 'label' => __( 'Icon position:', 'wp-external-links' ),
81 'class' => 'js-icon-type-depend wpel-hidden',
82 'default_value' => 'right',
83 ),
84 'no_icon_for_img' => array(
85 'label' => __( 'Skip icon with <code>&lt;img&gt;</code>:', 'wp-external-links' ),
86 'class' => 'js-icon-type-depend wpel-hidden',
87 'default_value' => '1',
88 ),
89 );
90
91 parent::init();
92 }
93
94 /**
95 * Show field methods
96 */
97
98 protected function show_apply_settings( array $args )
99 {
100 $this->get_html_fields()->check_with_label(
101 $args[ 'key' ]
102 , __( 'Apply these settings', 'wp-external-links' )
103 , '1'
104 , ''
105 );
106 }
107
108 protected function show_target( array $args )
109 {
110 $this->get_html_fields()->select(
111 $args[ 'key' ]
112 , array(
113 '' => __( '- keep as is -', 'wp-external-links' ),
114 '_self' => __( 'in the same window, tab or frame', 'wp-external-links' ),
115 '_blank' => __( 'each in a separate new window or tab', 'wp-external-links' ),
116 '_new' => __( 'all in the same new window or tab (NOT recommended)', 'wp-external-links' ),
117 '_top' => __( 'in the topmost frame (NOT recommended)', 'wp-external-links' ),
118 )
119 );
120 }
121
122 protected function show_target_overwrite( array $args )
123 {
124 $this->get_html_fields()->check_with_label(
125 $args[ 'key' ]
126 , __( 'Overwrite existing values.', 'wp-external-links' )
127 , '1'
128 , ''
129 );
130 }
131
132 protected function show_rel_follow( array $args )
133 {
134 $this->get_html_fields()->select(
135 $args[ 'key' ]
136 , array(
137 '' => __( '- keep as is -', 'wp-external-links' ),
138 'follow' => __( 'follow', 'wp-external-links' ),
139 'nofollow' => __( 'nofollow', 'wp-external-links' ),
140 )
141 );
142 }
143
144 protected function show_rel_follow_overwrite( array $args )
145 {
146 $this->get_html_fields()->check_with_label(
147 $args[ 'key' ]
148 , __( 'Overwrite existing values.', 'wp-external-links' )
149 , '1'
150 , ''
151 );
152 }
153
154 protected function show_rel_noopener( array $args )
155 {
156 $this->get_html_fields()->check_with_label(
157 $args[ 'key' ]
158 , __( 'Add <code>"noopener"</code>', 'wp-external-links' )
159 , '1'
160 , ''
161 );
162 }
163
164 protected function show_rel_noreferrer( array $args )
165 {
166 $this->get_html_fields()->check_with_label(
167 $args[ 'key' ]
168 , __( 'Add <code>"noreferrer"</code>', 'wp-external-links' )
169 , '1'
170 , ''
171 );
172 }
173
174 protected function show_rel_sponsored( array $args )
175 {
176 $this->get_html_fields()->check_with_label(
177 $args[ 'key' ]
178 , __( 'Add <code>"sponsored"</code>', 'wp-external-links' )
179 , '1'
180 , ''
181 );
182 }
183
184 protected function show_rel_ugc( array $args )
185 {
186 $this->get_html_fields()->check_with_label(
187 $args[ 'key' ]
188 , __( 'Add <code>"ugc"</code>', 'wp-external-links' )
189 , '1'
190 , ''
191 );
192 }
193
194 protected function show_title( array $args )
195 {
196 $this->get_html_fields()->text( $args[ 'key' ], array(
197 'class' => 'regular-text',
198 ) );
199
200 echo '<p class="description">'
201 . __( 'Use this <code>{title}</code> for the original title value '
202 .'and <code>{text}</code> for the link text (or <code>{text_clean}</code> for text stripped of HTML) as shown on the page', 'wp-external-links' )
203 .'</p>';
204 }
205
206 protected function show_class( array $args )
207 {
208 $this->get_html_fields()->text( $args[ 'key' ], array(
209 'class' => 'regular-text',
210 ) );
211 }
212
213 protected function show_icon_type( array $args )
214 {
215 $this->get_html_fields()->select(
216 $args[ 'key' ]
217 , array(
218 '' => __( '- no icon -', 'wp-external-links' ),
219 'image' => __( 'Image', 'wp-external-links' ),
220 'dashicon' => __( 'Dashicon', 'wp-external-links' ),
221 'fontawesome' => __( 'Font Awesome', 'wp-external-links' ),
222 )
223 );
224 }
225
226 protected function show_icon_image( array $args )
227 {
228 echo '<fieldset>';
229 echo '<div class="wpel-icon-type-image-column">';
230
231 for ( $x = 1; $x <= 20; $x++ ) {
232 echo '<label>';
233 echo $this->get_html_fields()->radio( $args[ 'key' ], strval( $x ) );
234 echo '<img src="'. plugins_url( '/public/images/wpel-icons/icon-'. esc_attr( $x ) .'.png', WPEL_Plugin::get_plugin_file() ) .'">';
235 echo '</label>';
236 echo '<br>';
237
238 if ( $x % 5 === 0 ) {
239 echo '</div>';
240 echo '<div class="wpel-icon-type-image-column">';
241 }
242 }
243
244 echo '</div>';
245 echo '</fieldset>';
246 }
247
248 protected function show_icon_dashicon( array $args )
249 {
250 $dashicons_str = file_get_contents( WPEL_Plugin::get_plugin_dir( '/data/json/dashicons.json' ) );
251 $dashicons_json = json_decode( $dashicons_str, true );
252 $dashicons = $dashicons_json[ 'icons' ];
253
254 $options = array();
255 foreach ( $dashicons as $icon ) {
256 $options[ $icon[ 'className' ] ] = '&#x'. $icon[ 'unicode' ];
257 }
258
259 $this->get_html_fields()->select( $args[ 'key' ], $options, array(
260 'style' => 'font-family:dashicons',
261 ) );
262 }
263
264 protected function show_icon_fontawesome( array $args )
265 {
266 $fa_icons_str = file_get_contents( WPEL_Plugin::get_plugin_dir( '/data/json/fontawesome.json' ) );
267 $fa_icons_json = json_decode( $fa_icons_str, true );
268 $fa_icons = $fa_icons_json[ 'icons' ];
269
270 $options = array();
271 foreach ( $fa_icons as $icon ) {
272 $options[ $icon[ 'className' ] ] = '&#x'. $icon[ 'unicode' ];
273 }
274
275 $this->get_html_fields()->select( $args[ 'key' ], $options, array(
276 'style' => 'font-family:FontAwesome',
277 ) );
278 }
279
280 protected function show_icon_position( array $args )
281 {
282 $this->get_html_fields()->select(
283 $args[ 'key' ]
284 , array(
285 'left' => __( 'Left side of the link', 'wp-external-links' ),
286 'right' => __( 'Right side of the link', 'wp-external-links' ),
287 )
288 );
289 }
290
291 protected function show_no_icon_for_img( array $args )
292 {
293 $this->get_html_fields()->check_with_label(
294 $args[ 'key' ]
295 , __( 'No icon for links already containing an <code>&lt;img&gt;</code>-tag.', 'wp-external-links' )
296 , '1'
297 , ''
298 );
299 }
300
301 /**
302 * Validate and sanitize user input before saving to databse
303 * @param array $new_values
304 * @param array $old_values
305 * @return array
306 */
307 protected function before_update( array $new_values, array $old_values )
308 {
309 $update_values = $new_values;
310 $is_valid = true;
311
312 $is_valid = $is_valid && in_array( $new_values[ 'apply_settings' ], array( '', '1' ) );
313 $is_valid = $is_valid && in_array( $new_values[ 'target_overwrite' ], array( '', '1' ) );
314 $is_valid = $is_valid && in_array( $new_values[ 'rel_follow_overwrite' ], array( '', '1' ) );
315 $is_valid = $is_valid && in_array( $new_values[ 'rel_noopener' ], array( '', '1' ) );
316 $is_valid = $is_valid && in_array( $new_values[ 'rel_noreferrer' ], array( '', '1' ) );
317 $is_valid = $is_valid && in_array( $new_values[ 'no_icon_for_img' ], array( '', '1' ) );
318
319 if ( false === $is_valid ) {
320 // error when user input is not valid conform the UI, probably tried to "hack"
321 $this->add_error( __( 'Something went wrong. One or more values were invalid.', 'wp-external-links' ) );
322 return $old_values;
323 }
324
325 $update_values[ 'target' ] = sanitize_text_field( $new_values[ 'target' ] );
326 $update_values[ 'rel_follow' ] = sanitize_text_field( $new_values[ 'rel_follow' ] );
327 $update_values[ 'title' ] = sanitize_text_field( $new_values[ 'title' ] );
328 $update_values[ 'class' ] = sanitize_text_field( $new_values[ 'class' ] );
329 $update_values[ 'icon_type' ] = sanitize_text_field( $new_values[ 'icon_type' ] );
330 $update_values[ 'icon_image' ] = sanitize_text_field( $new_values[ 'icon_image' ] );
331 $update_values[ 'icon_dashicon' ] = sanitize_text_field( $new_values[ 'icon_dashicon' ] );
332 $update_values[ 'icon_fontawesome' ] = sanitize_text_field( $new_values[ 'icon_fontawesome' ] );
333 $update_values[ 'icon_position' ] = sanitize_text_field( $new_values[ 'icon_position' ] );
334
335 return $update_values;
336 }
337
338 }
339
340 /*?>*/
341