@@ -16,136 +16,136 @@ discard block |
||
| 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 | - "<label for='$this->meta_name'>" |
|
| 96 | - . esc_html__( 'If you already know the URL of the entity that you would like to link, add it in the field below.', 'wordlift' ) |
|
| 97 | - . '</label>' |
|
| 98 | - . '<div class="wl-input-wrapper">' |
|
| 99 | - . "<input type='text' id='$this->meta_name' name='wl_metaboxes[$this->meta_name][]' placeholder='$placeholder' style='width:88%' />" |
|
| 100 | - . '<button class="button wl-remove-input wl-button" type="button">Remove</button>' |
|
| 101 | - . '</div>' |
|
| 102 | - . parent::get_add_button_html( $count ); |
|
| 103 | - } |
|
| 104 | - |
|
| 105 | - /** |
|
| 106 | - * @inheritdoc |
|
| 107 | - */ |
|
| 108 | - protected function get_stored_values_html( &$count ) { |
|
| 109 | - |
|
| 110 | - return '<p>' |
|
| 111 | - . parent::get_stored_values_html( $count ) |
|
| 112 | - . '</p>'; |
|
| 113 | - } |
|
| 114 | - |
|
| 115 | - /** |
|
| 116 | - * @inheritdoc |
|
| 117 | - */ |
|
| 118 | - public function html() { |
|
| 119 | - |
|
| 120 | - // Open main <div> for the Field. |
|
| 121 | - $html = $this->html_wrapper_open(); |
|
| 122 | - |
|
| 123 | - // Label. |
|
| 124 | - $html .= $this->get_heading_html(); |
|
| 125 | - |
|
| 126 | - // print nonce. |
|
| 127 | - $html .= $this->html_nonce(); |
|
| 128 | - |
|
| 129 | - // print data loaded from DB. |
|
| 130 | - $count = 0; |
|
| 131 | - |
|
| 132 | - // If cardinality allows it, print button to add new values. |
|
| 133 | - $html .= $this->get_add_button_html( $count ); |
|
| 134 | - |
|
| 135 | - $html .= $this->get_stored_values_html( $count ); |
|
| 136 | - |
|
| 137 | - // Close the HTML wrapper. |
|
| 138 | - $html .= $this->html_wrapper_close(); |
|
| 139 | - |
|
| 140 | - return $html; |
|
| 141 | - } |
|
| 142 | - |
|
| 143 | - /** |
|
| 144 | - * @inheritdoc |
|
| 145 | - */ |
|
| 146 | - public function html_input( $value ) { |
|
| 147 | - @ob_start(); |
|
| 148 | - ?> |
|
| 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 | + "<label for='$this->meta_name'>" |
|
| 96 | + . esc_html__( 'If you already know the URL of the entity that you would like to link, add it in the field below.', 'wordlift' ) |
|
| 97 | + . '</label>' |
|
| 98 | + . '<div class="wl-input-wrapper">' |
|
| 99 | + . "<input type='text' id='$this->meta_name' name='wl_metaboxes[$this->meta_name][]' placeholder='$placeholder' style='width:88%' />" |
|
| 100 | + . '<button class="button wl-remove-input wl-button" type="button">Remove</button>' |
|
| 101 | + . '</div>' |
|
| 102 | + . parent::get_add_button_html( $count ); |
|
| 103 | + } |
|
| 104 | + |
|
| 105 | + /** |
|
| 106 | + * @inheritdoc |
|
| 107 | + */ |
|
| 108 | + protected function get_stored_values_html( &$count ) { |
|
| 109 | + |
|
| 110 | + return '<p>' |
|
| 111 | + . parent::get_stored_values_html( $count ) |
|
| 112 | + . '</p>'; |
|
| 113 | + } |
|
| 114 | + |
|
| 115 | + /** |
|
| 116 | + * @inheritdoc |
|
| 117 | + */ |
|
| 118 | + public function html() { |
|
| 119 | + |
|
| 120 | + // Open main <div> for the Field. |
|
| 121 | + $html = $this->html_wrapper_open(); |
|
| 122 | + |
|
| 123 | + // Label. |
|
| 124 | + $html .= $this->get_heading_html(); |
|
| 125 | + |
|
| 126 | + // print nonce. |
|
| 127 | + $html .= $this->html_nonce(); |
|
| 128 | + |
|
| 129 | + // print data loaded from DB. |
|
| 130 | + $count = 0; |
|
| 131 | + |
|
| 132 | + // If cardinality allows it, print button to add new values. |
|
| 133 | + $html .= $this->get_add_button_html( $count ); |
|
| 134 | + |
|
| 135 | + $html .= $this->get_stored_values_html( $count ); |
|
| 136 | + |
|
| 137 | + // Close the HTML wrapper. |
|
| 138 | + $html .= $this->html_wrapper_close(); |
|
| 139 | + |
|
| 140 | + return $html; |
|
| 141 | + } |
|
| 142 | + |
|
| 143 | + /** |
|
| 144 | + * @inheritdoc |
|
| 145 | + */ |
|
| 146 | + public function html_input( $value ) { |
|
| 147 | + @ob_start(); |
|
| 148 | + ?> |
|
| 149 | 149 | <div class="wl-input-wrapper wl-input-wrapper-readonly"> |
| 150 | 150 | <input |
| 151 | 151 | type="text" |
@@ -162,29 +162,29 @@ discard block |
||
| 162 | 162 | </div> |
| 163 | 163 | <?php |
| 164 | 164 | |
| 165 | - $html = ob_get_clean(); |
|
| 166 | - |
|
| 167 | - return $html; |
|
| 168 | - } |
|
| 169 | - |
|
| 170 | - /** |
|
| 171 | - * @param array $urls |
|
| 172 | - * |
|
| 173 | - * @return array |
|
| 174 | - */ |
|
| 175 | - private function filter_urls( $urls ) { |
|
| 176 | - $configuration_service = Wordlift_Configuration_Service::get_instance(); |
|
| 177 | - $dataset_uri = $configuration_service->get_dataset_uri(); |
|
| 178 | - |
|
| 179 | - return array_filter( $urls, function ( $url ) use ( $dataset_uri ) { |
|
| 180 | - $url_validation = filter_var( $url, FILTER_VALIDATE_URL ); |
|
| 181 | - if ( null === $dataset_uri ) { |
|
| 182 | - return $url_validation; |
|
| 183 | - } |
|
| 184 | - |
|
| 185 | - // URLs should not start with local dataset uri. |
|
| 186 | - return $url_validation && ( strpos( $url, $dataset_uri, 0 ) === false ); |
|
| 187 | - } ); |
|
| 188 | - } |
|
| 165 | + $html = ob_get_clean(); |
|
| 166 | + |
|
| 167 | + return $html; |
|
| 168 | + } |
|
| 169 | + |
|
| 170 | + /** |
|
| 171 | + * @param array $urls |
|
| 172 | + * |
|
| 173 | + * @return array |
|
| 174 | + */ |
|
| 175 | + private function filter_urls( $urls ) { |
|
| 176 | + $configuration_service = Wordlift_Configuration_Service::get_instance(); |
|
| 177 | + $dataset_uri = $configuration_service->get_dataset_uri(); |
|
| 178 | + |
|
| 179 | + return array_filter( $urls, function ( $url ) use ( $dataset_uri ) { |
|
| 180 | + $url_validation = filter_var( $url, FILTER_VALIDATE_URL ); |
|
| 181 | + if ( null === $dataset_uri ) { |
|
| 182 | + return $url_validation; |
|
| 183 | + } |
|
| 184 | + |
|
| 185 | + // URLs should not start with local dataset uri. |
|
| 186 | + return $url_validation && ( strpos( $url, $dataset_uri, 0 ) === false ); |
|
| 187 | + } ); |
|
| 188 | + } |
|
| 189 | 189 | |
| 190 | 190 | } |
@@ -19,46 +19,46 @@ discard block |
||
| 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,35 +80,35 @@ discard block |
||
| 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 | 95 | "<label for='$this->meta_name'>" |
| 96 | - . esc_html__( 'If you already know the URL of the entity that you would like to link, add it in the field below.', 'wordlift' ) |
|
| 96 | + . esc_html__('If you already know the URL of the entity that you would like to link, add it in the field below.', 'wordlift') |
|
| 97 | 97 | . '</label>' |
| 98 | 98 | . '<div class="wl-input-wrapper">' |
| 99 | 99 | . "<input type='text' id='$this->meta_name' name='wl_metaboxes[$this->meta_name][]' placeholder='$placeholder' style='width:88%' />" |
| 100 | 100 | . '<button class="button wl-remove-input wl-button" type="button">Remove</button>' |
| 101 | 101 | . '</div>' |
| 102 | - . parent::get_add_button_html( $count ); |
|
| 102 | + . parent::get_add_button_html($count); |
|
| 103 | 103 | } |
| 104 | 104 | |
| 105 | 105 | /** |
| 106 | 106 | * @inheritdoc |
| 107 | 107 | */ |
| 108 | - protected function get_stored_values_html( &$count ) { |
|
| 108 | + protected function get_stored_values_html(&$count) { |
|
| 109 | 109 | |
| 110 | 110 | return '<p>' |
| 111 | - . parent::get_stored_values_html( $count ) |
|
| 111 | + . parent::get_stored_values_html($count) |
|
| 112 | 112 | . '</p>'; |
| 113 | 113 | } |
| 114 | 114 | |
@@ -130,9 +130,9 @@ discard block |
||
| 130 | 130 | $count = 0; |
| 131 | 131 | |
| 132 | 132 | // If cardinality allows it, print button to add new values. |
| 133 | - $html .= $this->get_add_button_html( $count ); |
|
| 133 | + $html .= $this->get_add_button_html($count); |
|
| 134 | 134 | |
| 135 | - $html .= $this->get_stored_values_html( $count ); |
|
| 135 | + $html .= $this->get_stored_values_html($count); |
|
| 136 | 136 | |
| 137 | 137 | // Close the HTML wrapper. |
| 138 | 138 | $html .= $this->html_wrapper_close(); |
@@ -143,7 +143,7 @@ discard block |
||
| 143 | 143 | /** |
| 144 | 144 | * @inheritdoc |
| 145 | 145 | */ |
| 146 | - public function html_input( $value ) { |
|
| 146 | + public function html_input($value) { |
|
| 147 | 147 | @ob_start(); |
| 148 | 148 | ?> |
| 149 | 149 | <div class="wl-input-wrapper wl-input-wrapper-readonly"> |
@@ -157,7 +157,7 @@ discard block |
||
| 157 | 157 | /> |
| 158 | 158 | |
| 159 | 159 | <button class="button wl-remove-input wl-button" type="button"> |
| 160 | - <?php esc_html_e( 'Remove', 'wordlift' ); ?> |
|
| 160 | + <?php esc_html_e('Remove', 'wordlift'); ?> |
|
| 161 | 161 | </button> |
| 162 | 162 | </div> |
| 163 | 163 | <?php |
@@ -172,18 +172,18 @@ discard block |
||
| 172 | 172 | * |
| 173 | 173 | * @return array |
| 174 | 174 | */ |
| 175 | - private function filter_urls( $urls ) { |
|
| 175 | + private function filter_urls($urls) { |
|
| 176 | 176 | $configuration_service = Wordlift_Configuration_Service::get_instance(); |
| 177 | 177 | $dataset_uri = $configuration_service->get_dataset_uri(); |
| 178 | 178 | |
| 179 | - return array_filter( $urls, function ( $url ) use ( $dataset_uri ) { |
|
| 180 | - $url_validation = filter_var( $url, FILTER_VALIDATE_URL ); |
|
| 181 | - if ( null === $dataset_uri ) { |
|
| 179 | + return array_filter($urls, function($url) use ($dataset_uri) { |
|
| 180 | + $url_validation = filter_var($url, FILTER_VALIDATE_URL); |
|
| 181 | + if (null === $dataset_uri) { |
|
| 182 | 182 | return $url_validation; |
| 183 | 183 | } |
| 184 | 184 | |
| 185 | 185 | // URLs should not start with local dataset uri. |
| 186 | - return $url_validation && ( strpos( $url, $dataset_uri, 0 ) === false ); |
|
| 186 | + return $url_validation && (strpos($url, $dataset_uri, 0) === false); |
|
| 187 | 187 | } ); |
| 188 | 188 | } |
| 189 | 189 | |