Completed
Push — develop ( ea9474...483e8f )
by
unknown
03:00
created
src/admin/WL_Metabox/class-wl-metabox-field-sameas.php 2 patches
Indentation   +132 added lines, -132 removed lines patch added patch discarded remove patch
@@ -16,131 +16,131 @@  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
-	}
102
+    }
103 103
 
104
-	/**
105
-	 * @inheritdoc
106
-	 */
107
-	protected function get_stored_values_html( &$count ) {
104
+    /**
105
+     * @inheritdoc
106
+     */
107
+    protected function get_stored_values_html( &$count ) {
108 108
 
109
-		return  parent::get_stored_values_html( $count );
110
-	}
109
+        return  parent::get_stored_values_html( $count );
110
+    }
111 111
 
112
-	/**
113
-	 * @inheritdoc
114
-	 */
115
-	public function html() {
112
+    /**
113
+     * @inheritdoc
114
+     */
115
+    public function html() {
116 116
 
117
-		// Open main <div> for the Field.
118
-		$html = $this->html_wrapper_open();
117
+        // Open main <div> for the Field.
118
+        $html = $this->html_wrapper_open();
119 119
 
120
-		// Label.
121
-		$html .= $this->get_heading_html();
120
+        // Label.
121
+        $html .= $this->get_heading_html();
122 122
 
123
-		// print nonce.
124
-		$html .= $this->html_nonce();
123
+        // print nonce.
124
+        $html .= $this->html_nonce();
125 125
 
126
-		// print data loaded from DB.
127
-		$count = 0;
126
+        // print data loaded from DB.
127
+        $count = 0;
128 128
 
129
-		// If cardinality allows it, print button to add new values.
130
-		$html .= $this->get_add_button_html( $count );
129
+        // If cardinality allows it, print button to add new values.
130
+        $html .= $this->get_add_button_html( $count );
131 131
 
132
-		// Close the HTML wrapper.
133
-		$html .= $this->html_wrapper_close();
132
+        // Close the HTML wrapper.
133
+        $html .= $this->html_wrapper_close();
134 134
 
135
-		return $html;
136
-	}
135
+        return $html;
136
+    }
137 137
 
138
-	/**
139
-	 * @inheritdoc
140
-	 */
141
-	public function html_input( $value ) {
142
-		@ob_start();
143
-		?>
138
+    /**
139
+     * @inheritdoc
140
+     */
141
+    public function html_input( $value ) {
142
+        @ob_start();
143
+        ?>
144 144
         <div class="wl-input-wrapper wl-input-wrapper-readonly">
145 145
             <input
146 146
                     type="text"
@@ -154,29 +154,29 @@  discard block
 block discarded – undo
154 154
         </div>
155 155
 		<?php
156 156
 
157
-		$html = ob_get_clean();
158
-
159
-		return $html;
160
-	}
161
-
162
-	/**
163
-	 * @param array $urls
164
-	 *
165
-	 * @return array
166
-	 */
167
-	private function filter_urls( $urls ) {
168
-		$configuration_service = Wordlift_Configuration_Service::get_instance();
169
-		$dataset_uri           = $configuration_service->get_dataset_uri();
170
-
171
-		return array_filter( $urls, function ( $url ) use ( $dataset_uri ) {
172
-			$url_validation = filter_var( $url, FILTER_VALIDATE_URL );
173
-			if ( null === $dataset_uri ) {
174
-				return $url_validation;
175
-			}
176
-
177
-			// URLs should not start with local dataset uri.
178
-			return $url_validation && ( strpos( $url, $dataset_uri, 0 ) === false );
179
-		} );
180
-	}
157
+        $html = ob_get_clean();
158
+
159
+        return $html;
160
+    }
161
+
162
+    /**
163
+     * @param array $urls
164
+     *
165
+     * @return array
166
+     */
167
+    private function filter_urls( $urls ) {
168
+        $configuration_service = Wordlift_Configuration_Service::get_instance();
169
+        $dataset_uri           = $configuration_service->get_dataset_uri();
170
+
171
+        return array_filter( $urls, function ( $url ) use ( $dataset_uri ) {
172
+            $url_validation = filter_var( $url, FILTER_VALIDATE_URL );
173
+            if ( null === $dataset_uri ) {
174
+                return $url_validation;
175
+            }
176
+
177
+            // URLs should not start with local dataset uri.
178
+            return $url_validation && ( strpos( $url, $dataset_uri, 0 ) === false );
179
+        } );
180
+    }
181 181
 
182 182
 }
Please login to merge, or discard this patch.
Spacing   +31 added lines, -31 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
 	/**
@@ -127,7 +127,7 @@  discard block
 block discarded – undo
127 127
 		$count = 0;
128 128
 
129 129
 		// If cardinality allows it, print button to add new values.
130
-		$html .= $this->get_add_button_html( $count );
130
+		$html .= $this->get_add_button_html($count);
131 131
 
132 132
 		// Close the HTML wrapper.
133 133
 		$html .= $this->html_wrapper_close();
@@ -138,7 +138,7 @@  discard block
 block discarded – undo
138 138
 	/**
139 139
 	 * @inheritdoc
140 140
 	 */
141
-	public function html_input( $value ) {
141
+	public function html_input($value) {
142 142
 		@ob_start();
143 143
 		?>
144 144
         <div class="wl-input-wrapper wl-input-wrapper-readonly">
@@ -164,18 +164,18 @@  discard block
 block discarded – undo
164 164
 	 *
165 165
 	 * @return array
166 166
 	 */
167
-	private function filter_urls( $urls ) {
167
+	private function filter_urls($urls) {
168 168
 		$configuration_service = Wordlift_Configuration_Service::get_instance();
169 169
 		$dataset_uri           = $configuration_service->get_dataset_uri();
170 170
 
171
-		return array_filter( $urls, function ( $url ) use ( $dataset_uri ) {
172
-			$url_validation = filter_var( $url, FILTER_VALIDATE_URL );
173
-			if ( null === $dataset_uri ) {
171
+		return array_filter($urls, function($url) use ($dataset_uri) {
172
+			$url_validation = filter_var($url, FILTER_VALIDATE_URL);
173
+			if (null === $dataset_uri) {
174 174
 				return $url_validation;
175 175
 			}
176 176
 
177 177
 			// URLs should not start with local dataset uri.
178
-			return $url_validation && ( strpos( $url, $dataset_uri, 0 ) === false );
178
+			return $url_validation && (strpos($url, $dataset_uri, 0) === false);
179 179
 		} );
180 180
 	}
181 181
 
Please login to merge, or discard this patch.