Completed
Push — develop ( fd3a23...23810d )
by
unknown
03:02 queued 11s
created
src/admin/WL_Metabox/class-wl-metabox-field-sameas.php 2 patches
Indentation   +154 added lines, -154 removed lines patch added patch discarded remove patch
@@ -16,142 +16,142 @@  discard block
 block discarded – undo
16 16
  */
17 17
 class WL_Metabox_Field_sameas extends WL_Metabox_Field {
18 18
 
19
-	/**
20
-	 * @inheritdoc
21
-	 */
22
-	public function __construct( $args ) {
23
-		parent::__construct( $args['sameas'] );
24
-	}
25
-
26
-	/**
27
-	 * @inheritdoc
28
-	 */
29
-	public function save_data( $values ) {
30
-		// The autocomplete select may send JSON arrays in input values.
31
-
32
-		// Only use mb_* functions when mbstring is available.
33
-		//
34
-		// See https://github.com/insideout10/wordlift-plugin/issues/693.
35
-		if ( extension_loaded( 'mbstring' ) ) {
36
-			mb_regex_encoding( 'UTF-8' );
37
-
38
-			$merged = array_reduce( (array) $values, function ( $carry, $item ) {
39
-				return array_merge( $carry, mb_split( "\x{2063}", wp_unslash( $item ) ) );
40
-			}, array() );
41
-		} else {
42
-			$merged = array_reduce( (array) $values, function ( $carry, $item ) {
43
-				return array_merge( $carry, preg_split( "/\x{2063}/u", wp_unslash( $item ) ) );
44
-			}, array() );
45
-		}
46
-
47
-		// Convert all escaped special characters to their original.
48
-		$merged = array_map( 'urldecode', $merged );
49
-
50
-		$merged = $this->filter_urls( $merged );
51
-
52
-		parent::save_data( $merged );
53
-	}
54
-
55
-	/**
56
-	 * @inheritdoc
57
-	 */
58
-	public function sanitize_data_filter( $value ) {
59
-
60
-		// Call our sanitizer helper.
61
-		return Wordlift_Sanitizer::sanitize_url( $value );
62
-	}
63
-
64
-	/**
65
-	 * @inheritdoc
66
-	 */
67
-	protected function get_heading_html() {
68
-
69
-		// Add the select html fragment after the heading.
70
-		return parent::get_heading_html()
71
-		       . $this->get_select_html();
72
-	}
73
-
74
-	/**
75
-	 * Get the select html fragment.
76
-	 *
77
-	 * @return string The html fragment.
78
-	 * @since 3.15.0
79
-	 */
80
-	private function get_select_html() {
81
-		// Return an element where the new Autocomplete Select will attach to.
82
-		return '<p>'
83
-		       . esc_html__( 'Use the search below to link this entity with equivalent entities in the linked data cloud.', 'wordlift' )
84
-		       . '<div id="wl-metabox-field-sameas"></div></p>';
85
-	}
86
-
87
-	/**
88
-	 * @inheritdoc
89
-	 */
90
-	protected function get_add_button_html( $count ) {
91
-
92
-		$placeholder = esc_attr_x( 'Type here the URL of an equivalent entity from another dataset.', 'sameAs metabox input', 'wordlift' );
93
-
94
-		return
95
-  		'<button type="button" class="wl-add-input wl-add-input--link">'.esc_html__( 'Click here to manually add URLs', 'wordlift' ).'</button>'
19
+    /**
20
+     * @inheritdoc
21
+     */
22
+    public function __construct( $args ) {
23
+        parent::__construct( $args['sameas'] );
24
+    }
25
+
26
+    /**
27
+     * @inheritdoc
28
+     */
29
+    public function save_data( $values ) {
30
+        // The autocomplete select may send JSON arrays in input values.
31
+
32
+        // Only use mb_* functions when mbstring is available.
33
+        //
34
+        // See https://github.com/insideout10/wordlift-plugin/issues/693.
35
+        if ( extension_loaded( 'mbstring' ) ) {
36
+            mb_regex_encoding( 'UTF-8' );
37
+
38
+            $merged = array_reduce( (array) $values, function ( $carry, $item ) {
39
+                return array_merge( $carry, mb_split( "\x{2063}", wp_unslash( $item ) ) );
40
+            }, array() );
41
+        } else {
42
+            $merged = array_reduce( (array) $values, function ( $carry, $item ) {
43
+                return array_merge( $carry, preg_split( "/\x{2063}/u", wp_unslash( $item ) ) );
44
+            }, array() );
45
+        }
46
+
47
+        // Convert all escaped special characters to their original.
48
+        $merged = array_map( 'urldecode', $merged );
49
+
50
+        $merged = $this->filter_urls( $merged );
51
+
52
+        parent::save_data( $merged );
53
+    }
54
+
55
+    /**
56
+     * @inheritdoc
57
+     */
58
+    public function sanitize_data_filter( $value ) {
59
+
60
+        // Call our sanitizer helper.
61
+        return Wordlift_Sanitizer::sanitize_url( $value );
62
+    }
63
+
64
+    /**
65
+     * @inheritdoc
66
+     */
67
+    protected function get_heading_html() {
68
+
69
+        // Add the select html fragment after the heading.
70
+        return parent::get_heading_html()
71
+                . $this->get_select_html();
72
+    }
73
+
74
+    /**
75
+     * Get the select html fragment.
76
+     *
77
+     * @return string The html fragment.
78
+     * @since 3.15.0
79
+     */
80
+    private function get_select_html() {
81
+        // Return an element where the new Autocomplete Select will attach to.
82
+        return '<p>'
83
+                . esc_html__( 'Use the search below to link this entity with equivalent entities in the linked data cloud.', 'wordlift' )
84
+                . '<div id="wl-metabox-field-sameas"></div></p>';
85
+    }
86
+
87
+    /**
88
+     * @inheritdoc
89
+     */
90
+    protected function get_add_button_html( $count ) {
91
+
92
+        $placeholder = esc_attr_x( 'Type here the URL of an equivalent entity from another dataset.', 'sameAs metabox input', 'wordlift' );
93
+
94
+        return
95
+            '<button type="button" class="wl-add-input wl-add-input--link">'.esc_html__( 'Click here to manually add URLs', 'wordlift' ).'</button>'
96 96
         .'<div style="display: none;"><div class="wl-input-wrapper">'
97 97
         ."<input type='text' id='$this->meta_name' name='wl_metaboxes[$this->meta_name][]' placeholder='$placeholder' />"
98 98
         .'<button type="button" class="wl-remove-input wl-remove-input--sameas"></button>'
99 99
         .'</div></div>'
100 100
         . '<fieldset id="wl-input-container">'.$this->get_stored_values_html( $count ).'</fieldset>'
101 101
         .parent::get_add_custom_button_html( $count, 'Add Another URL', 'hide' );
102
-	}
103
-
104
-	/**
105
-	 * @inheritdoc
106
-	 */
107
-	protected function get_stored_values_html( &$count ) {
108
-
109
-		return  parent::get_stored_values_html( $count );
110
-	}
111
-
112
-	/**
113
-	 * @inheritdoc
114
-	 */
115
-	public function html() {
116
-
117
-		/**
118
-		 * Filter: wl_feature__enable__metabox__sameas.
119
-		 *
120
-		 * @param bool whether the sameAs metabox should be shown, defaults to true.
121
-		 *
122
-		 * @return bool
123
-		 * @since 3.29.1
124
-		 */
125
-		if ( apply_filters( 'wl_feature__enable__metabox__sameas', true ) ) {
126
-
127
-			// Open main <div> for the Field.
128
-			$html = $this->html_wrapper_open();
129
-
130
-			// Label.
131
-			$html .= $this->get_heading_html();
132
-
133
-			// print nonce.
134
-			$html .= $this->html_nonce();
135
-
136
-			// print data loaded from DB.
137
-			$count = 0;
138
-
139
-			// If cardinality allows it, print button to add new values.
140
-			$html .= $this->get_add_button_html( $count );
141
-
142
-			// Close the HTML wrapper.
143
-			$html .= $this->html_wrapper_close();
144
-
145
-			return $html;
146
-		}
147
-	}
148
-
149
-	/**
150
-	 * @inheritdoc
151
-	 */
152
-	public function html_input( $value ) {
153
-		@ob_start();
154
-		?>
102
+    }
103
+
104
+    /**
105
+     * @inheritdoc
106
+     */
107
+    protected function get_stored_values_html( &$count ) {
108
+
109
+        return  parent::get_stored_values_html( $count );
110
+    }
111
+
112
+    /**
113
+     * @inheritdoc
114
+     */
115
+    public function html() {
116
+
117
+        /**
118
+         * Filter: wl_feature__enable__metabox__sameas.
119
+         *
120
+         * @param bool whether the sameAs metabox should be shown, defaults to true.
121
+         *
122
+         * @return bool
123
+         * @since 3.29.1
124
+         */
125
+        if ( apply_filters( 'wl_feature__enable__metabox__sameas', true ) ) {
126
+
127
+            // Open main <div> for the Field.
128
+            $html = $this->html_wrapper_open();
129
+
130
+            // Label.
131
+            $html .= $this->get_heading_html();
132
+
133
+            // print nonce.
134
+            $html .= $this->html_nonce();
135
+
136
+            // print data loaded from DB.
137
+            $count = 0;
138
+
139
+            // If cardinality allows it, print button to add new values.
140
+            $html .= $this->get_add_button_html( $count );
141
+
142
+            // Close the HTML wrapper.
143
+            $html .= $this->html_wrapper_close();
144
+
145
+            return $html;
146
+        }
147
+    }
148
+
149
+    /**
150
+     * @inheritdoc
151
+     */
152
+    public function html_input( $value ) {
153
+        @ob_start();
154
+        ?>
155 155
         <div class="wl-input-wrapper wl-input-wrapper-readonly">
156 156
             <input
157 157
                     type="text"
@@ -165,29 +165,29 @@  discard block
 block discarded – undo
165 165
         </div>
166 166
 		<?php
167 167
 
168
-		$html = ob_get_clean();
169
-
170
-		return $html;
171
-	}
172
-
173
-	/**
174
-	 * @param array $urls
175
-	 *
176
-	 * @return array
177
-	 */
178
-	private function filter_urls( $urls ) {
179
-		$configuration_service = Wordlift_Configuration_Service::get_instance();
180
-		$dataset_uri           = $configuration_service->get_dataset_uri();
181
-
182
-		return array_filter( $urls, function ( $url ) use ( $dataset_uri ) {
183
-			$url_validation = filter_var( $url, FILTER_VALIDATE_URL );
184
-			if ( null === $dataset_uri ) {
185
-				return $url_validation;
186
-			}
187
-
188
-			// URLs should not start with local dataset uri.
189
-			return $url_validation && ( strpos( $url, $dataset_uri, 0 ) === false );
190
-		} );
191
-	}
168
+        $html = ob_get_clean();
169
+
170
+        return $html;
171
+    }
172
+
173
+    /**
174
+     * @param array $urls
175
+     *
176
+     * @return array
177
+     */
178
+    private function filter_urls( $urls ) {
179
+        $configuration_service = Wordlift_Configuration_Service::get_instance();
180
+        $dataset_uri           = $configuration_service->get_dataset_uri();
181
+
182
+        return array_filter( $urls, function ( $url ) use ( $dataset_uri ) {
183
+            $url_validation = filter_var( $url, FILTER_VALIDATE_URL );
184
+            if ( null === $dataset_uri ) {
185
+                return $url_validation;
186
+            }
187
+
188
+            // URLs should not start with local dataset uri.
189
+            return $url_validation && ( strpos( $url, $dataset_uri, 0 ) === false );
190
+        } );
191
+    }
192 192
 
193 193
 }
Please login to merge, or discard this patch.
Spacing   +32 added lines, -32 removed lines patch added patch discarded remove patch
@@ -19,46 +19,46 @@  discard block
 block discarded – undo
19 19
 	/**
20 20
 	 * @inheritdoc
21 21
 	 */
22
-	public function __construct( $args ) {
23
-		parent::__construct( $args['sameas'] );
22
+	public function __construct($args) {
23
+		parent::__construct($args['sameas']);
24 24
 	}
25 25
 
26 26
 	/**
27 27
 	 * @inheritdoc
28 28
 	 */
29
-	public function save_data( $values ) {
29
+	public function save_data($values) {
30 30
 		// The autocomplete select may send JSON arrays in input values.
31 31
 
32 32
 		// Only use mb_* functions when mbstring is available.
33 33
 		//
34 34
 		// See https://github.com/insideout10/wordlift-plugin/issues/693.
35
-		if ( extension_loaded( 'mbstring' ) ) {
36
-			mb_regex_encoding( 'UTF-8' );
35
+		if (extension_loaded('mbstring')) {
36
+			mb_regex_encoding('UTF-8');
37 37
 
38
-			$merged = array_reduce( (array) $values, function ( $carry, $item ) {
39
-				return array_merge( $carry, mb_split( "\x{2063}", wp_unslash( $item ) ) );
40
-			}, array() );
38
+			$merged = array_reduce((array) $values, function($carry, $item) {
39
+				return array_merge($carry, mb_split("\x{2063}", wp_unslash($item)));
40
+			}, array());
41 41
 		} else {
42
-			$merged = array_reduce( (array) $values, function ( $carry, $item ) {
43
-				return array_merge( $carry, preg_split( "/\x{2063}/u", wp_unslash( $item ) ) );
44
-			}, array() );
42
+			$merged = array_reduce((array) $values, function($carry, $item) {
43
+				return array_merge($carry, preg_split("/\x{2063}/u", wp_unslash($item)));
44
+			}, array());
45 45
 		}
46 46
 
47 47
 		// Convert all escaped special characters to their original.
48
-		$merged = array_map( 'urldecode', $merged );
48
+		$merged = array_map('urldecode', $merged);
49 49
 
50
-		$merged = $this->filter_urls( $merged );
50
+		$merged = $this->filter_urls($merged);
51 51
 
52
-		parent::save_data( $merged );
52
+		parent::save_data($merged);
53 53
 	}
54 54
 
55 55
 	/**
56 56
 	 * @inheritdoc
57 57
 	 */
58
-	public function sanitize_data_filter( $value ) {
58
+	public function sanitize_data_filter($value) {
59 59
 
60 60
 		// Call our sanitizer helper.
61
-		return Wordlift_Sanitizer::sanitize_url( $value );
61
+		return Wordlift_Sanitizer::sanitize_url($value);
62 62
 	}
63 63
 
64 64
 	/**
@@ -80,33 +80,33 @@  discard block
 block discarded – undo
80 80
 	private function get_select_html() {
81 81
 		// Return an element where the new Autocomplete Select will attach to.
82 82
 		return '<p>'
83
-		       . esc_html__( 'Use the search below to link this entity with equivalent entities in the linked data cloud.', 'wordlift' )
83
+		       . esc_html__('Use the search below to link this entity with equivalent entities in the linked data cloud.', 'wordlift')
84 84
 		       . '<div id="wl-metabox-field-sameas"></div></p>';
85 85
 	}
86 86
 
87 87
 	/**
88 88
 	 * @inheritdoc
89 89
 	 */
90
-	protected function get_add_button_html( $count ) {
90
+	protected function get_add_button_html($count) {
91 91
 
92
-		$placeholder = esc_attr_x( 'Type here the URL of an equivalent entity from another dataset.', 'sameAs metabox input', 'wordlift' );
92
+		$placeholder = esc_attr_x('Type here the URL of an equivalent entity from another dataset.', 'sameAs metabox input', 'wordlift');
93 93
 
94 94
 		return
95
-  		'<button type="button" class="wl-add-input wl-add-input--link">'.esc_html__( 'Click here to manually add URLs', 'wordlift' ).'</button>'
95
+  		'<button type="button" class="wl-add-input wl-add-input--link">'.esc_html__('Click here to manually add URLs', 'wordlift').'</button>'
96 96
         .'<div style="display: none;"><div class="wl-input-wrapper">'
97 97
         ."<input type='text' id='$this->meta_name' name='wl_metaboxes[$this->meta_name][]' placeholder='$placeholder' />"
98 98
         .'<button type="button" class="wl-remove-input wl-remove-input--sameas"></button>'
99 99
         .'</div></div>'
100
-        . '<fieldset id="wl-input-container">'.$this->get_stored_values_html( $count ).'</fieldset>'
101
-        .parent::get_add_custom_button_html( $count, 'Add Another URL', 'hide' );
100
+        . '<fieldset id="wl-input-container">'.$this->get_stored_values_html($count).'</fieldset>'
101
+        .parent::get_add_custom_button_html($count, 'Add Another URL', 'hide');
102 102
 	}
103 103
 
104 104
 	/**
105 105
 	 * @inheritdoc
106 106
 	 */
107
-	protected function get_stored_values_html( &$count ) {
107
+	protected function get_stored_values_html(&$count) {
108 108
 
109
-		return  parent::get_stored_values_html( $count );
109
+		return  parent::get_stored_values_html($count);
110 110
 	}
111 111
 
112 112
 	/**
@@ -122,7 +122,7 @@  discard block
 block discarded – undo
122 122
 		 * @return bool
123 123
 		 * @since 3.29.1
124 124
 		 */
125
-		if ( apply_filters( 'wl_feature__enable__metabox__sameas', true ) ) {
125
+		if (apply_filters('wl_feature__enable__metabox__sameas', true)) {
126 126
 
127 127
 			// Open main <div> for the Field.
128 128
 			$html = $this->html_wrapper_open();
@@ -137,7 +137,7 @@  discard block
 block discarded – undo
137 137
 			$count = 0;
138 138
 
139 139
 			// If cardinality allows it, print button to add new values.
140
-			$html .= $this->get_add_button_html( $count );
140
+			$html .= $this->get_add_button_html($count);
141 141
 
142 142
 			// Close the HTML wrapper.
143 143
 			$html .= $this->html_wrapper_close();
@@ -149,7 +149,7 @@  discard block
 block discarded – undo
149 149
 	/**
150 150
 	 * @inheritdoc
151 151
 	 */
152
-	public function html_input( $value ) {
152
+	public function html_input($value) {
153 153
 		@ob_start();
154 154
 		?>
155 155
         <div class="wl-input-wrapper wl-input-wrapper-readonly">
@@ -175,18 +175,18 @@  discard block
 block discarded – undo
175 175
 	 *
176 176
 	 * @return array
177 177
 	 */
178
-	private function filter_urls( $urls ) {
178
+	private function filter_urls($urls) {
179 179
 		$configuration_service = Wordlift_Configuration_Service::get_instance();
180 180
 		$dataset_uri           = $configuration_service->get_dataset_uri();
181 181
 
182
-		return array_filter( $urls, function ( $url ) use ( $dataset_uri ) {
183
-			$url_validation = filter_var( $url, FILTER_VALIDATE_URL );
184
-			if ( null === $dataset_uri ) {
182
+		return array_filter($urls, function($url) use ($dataset_uri) {
183
+			$url_validation = filter_var($url, FILTER_VALIDATE_URL);
184
+			if (null === $dataset_uri) {
185 185
 				return $url_validation;
186 186
 			}
187 187
 
188 188
 			// URLs should not start with local dataset uri.
189
-			return $url_validation && ( strpos( $url, $dataset_uri, 0 ) === false );
189
+			return $url_validation && (strpos($url, $dataset_uri, 0) === false);
190 190
 		} );
191 191
 	}
192 192
 
Please login to merge, or discard this patch.