PluginProbe ʕ •ᴥ•ʔ
External Links – nofollow, noopener & new window / 2.32
External Links – nofollow, noopener & new window v2.32
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 7 years ago class-wpel-internal-link-fields.php 7 years ago class-wpel-link-fields-base.php 7 years ago
class-wpel-link-fields-base.php
321 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_title( array $args )
175 {
176 $this->get_html_fields()->text( $args[ 'key' ], array(
177 'class' => 'regular-text',
178 ) );
179
180 echo '<p class="description">'
181 . __( 'Use this <code>{title}</code> for the original title value '
182 .'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' )
183 .'</p>';
184 }
185
186 protected function show_class( array $args )
187 {
188 $this->get_html_fields()->text( $args[ 'key' ], array(
189 'class' => 'regular-text',
190 ) );
191 }
192
193 protected function show_icon_type( array $args )
194 {
195 $this->get_html_fields()->select(
196 $args[ 'key' ]
197 , array(
198 '' => __( '- no icon -', 'wp-external-links' ),
199 'image' => __( 'Image', 'wp-external-links' ),
200 'dashicon' => __( 'Dashicon', 'wp-external-links' ),
201 'fontawesome' => __( 'Font Awesome', 'wp-external-links' ),
202 )
203 );
204 }
205
206 protected function show_icon_image( array $args )
207 {
208 echo '<fieldset>';
209 echo '<div class="wpel-icon-type-image-column">';
210
211 for ( $x = 1; $x <= 20; $x++ ) {
212 echo '<label>';
213 echo $this->get_html_fields()->radio( $args[ 'key' ], strval( $x ) );
214 echo '<img src="'. plugins_url( '/public/images/wpel-icons/icon-'. esc_attr( $x ) .'.png', WPEL_Plugin::get_plugin_file() ) .'">';
215 echo '</label>';
216 echo '<br>';
217
218 if ( $x % 5 === 0 ) {
219 echo '</div>';
220 echo '<div class="wpel-icon-type-image-column">';
221 }
222 }
223
224 echo '</div>';
225 echo '</fieldset>';
226 }
227
228 protected function show_icon_dashicon( array $args )
229 {
230 $dashicons_str = file_get_contents( WPEL_Plugin::get_plugin_dir( '/data/json/dashicons.json' ) );
231 $dashicons_json = json_decode( $dashicons_str, true );
232 $dashicons = $dashicons_json[ 'icons' ];
233
234 $options = array();
235 foreach ( $dashicons as $icon ) {
236 $options[ $icon[ 'className' ] ] = '&#x'. $icon[ 'unicode' ];
237 }
238
239 $this->get_html_fields()->select( $args[ 'key' ], $options, array(
240 'style' => 'font-family:dashicons',
241 ) );
242 }
243
244 protected function show_icon_fontawesome( array $args )
245 {
246 $fa_icons_str = file_get_contents( WPEL_Plugin::get_plugin_dir( '/data/json/fontawesome.json' ) );
247 $fa_icons_json = json_decode( $fa_icons_str, true );
248 $fa_icons = $fa_icons_json[ 'icons' ];
249
250 $options = array();
251 foreach ( $fa_icons as $icon ) {
252 $options[ $icon[ 'className' ] ] = '&#x'. $icon[ 'unicode' ];
253 }
254
255 $this->get_html_fields()->select( $args[ 'key' ], $options, array(
256 'style' => 'font-family:FontAwesome',
257 ) );
258 }
259
260 protected function show_icon_position( array $args )
261 {
262 $this->get_html_fields()->select(
263 $args[ 'key' ]
264 , array(
265 'left' => __( 'Left side of the link', 'wp-external-links' ),
266 'right' => __( 'Right side of the link', 'wp-external-links' ),
267 )
268 );
269 }
270
271 protected function show_no_icon_for_img( array $args )
272 {
273 $this->get_html_fields()->check_with_label(
274 $args[ 'key' ]
275 , __( 'No icon for links already containing an <code>&lt;img&gt;</code>-tag.', 'wp-external-links' )
276 , '1'
277 , ''
278 );
279 }
280
281 /**
282 * Validate and sanitize user input before saving to databse
283 * @param array $new_values
284 * @param array $old_values
285 * @return array
286 */
287 protected function before_update( array $new_values, array $old_values )
288 {
289 $update_values = $new_values;
290 $is_valid = true;
291
292 $is_valid = $is_valid && in_array( $new_values[ 'apply_settings' ], array( '', '1' ) );
293 $is_valid = $is_valid && in_array( $new_values[ 'target_overwrite' ], array( '', '1' ) );
294 $is_valid = $is_valid && in_array( $new_values[ 'rel_follow_overwrite' ], array( '', '1' ) );
295 $is_valid = $is_valid && in_array( $new_values[ 'rel_noopener' ], array( '', '1' ) );
296 $is_valid = $is_valid && in_array( $new_values[ 'rel_noreferrer' ], array( '', '1' ) );
297 $is_valid = $is_valid && in_array( $new_values[ 'no_icon_for_img' ], array( '', '1' ) );
298
299 if ( false === $is_valid ) {
300 // error when user input is not valid conform the UI, probably tried to "hack"
301 $this->add_error( __( 'Something went wrong. One or more values were invalid.', 'wp-external-links' ) );
302 return $old_values;
303 }
304
305 $update_values[ 'target' ] = sanitize_text_field( $new_values[ 'target' ] );
306 $update_values[ 'rel_follow' ] = sanitize_text_field( $new_values[ 'rel_follow' ] );
307 $update_values[ 'title' ] = sanitize_text_field( $new_values[ 'title' ] );
308 $update_values[ 'class' ] = sanitize_text_field( $new_values[ 'class' ] );
309 $update_values[ 'icon_type' ] = sanitize_text_field( $new_values[ 'icon_type' ] );
310 $update_values[ 'icon_image' ] = sanitize_text_field( $new_values[ 'icon_image' ] );
311 $update_values[ 'icon_dashicon' ] = sanitize_text_field( $new_values[ 'icon_dashicon' ] );
312 $update_values[ 'icon_fontawesome' ] = sanitize_text_field( $new_values[ 'icon_fontawesome' ] );
313 $update_values[ 'icon_position' ] = sanitize_text_field( $new_values[ 'icon_position' ] );
314
315 return $update_values;
316 }
317
318 }
319
320 /*?>*/
321