@@ -5,71 +5,71 @@ discard block |
||
| 5 | 5 | */ |
| 6 | 6 | function wl_shortcode_faceted_search( $atts ) { |
| 7 | 7 | |
| 8 | - // Extract attributes and set default values. |
|
| 9 | - $shortcode_atts = shortcode_atts( array( |
|
| 10 | - 'title' => __( 'Related articles', 'wordlift' ), |
|
| 11 | - 'show_facets' => true, |
|
| 12 | - 'with_carousel' => true, |
|
| 13 | - 'squared_thumbs' => false, |
|
| 14 | - |
|
| 15 | - ), $atts ); |
|
| 16 | - |
|
| 17 | - foreach ( |
|
| 18 | - array( |
|
| 19 | - 'show_facets', |
|
| 20 | - 'with_carousel', |
|
| 21 | - 'squared_thumbs', |
|
| 22 | - ) as $att |
|
| 23 | - ) { |
|
| 24 | - |
|
| 25 | - // See http://wordpress.stackexchange.com/questions/119294/pass-boolean-value-in-shortcode |
|
| 26 | - $shortcode_atts[ $att ] = filter_var( |
|
| 27 | - $shortcode_atts[ $att ], FILTER_VALIDATE_BOOLEAN |
|
| 28 | - ); |
|
| 29 | - } |
|
| 30 | - |
|
| 31 | - |
|
| 32 | - // If the current post is not an entity and has no related entities |
|
| 33 | - // than the shortcode cannot be rendered |
|
| 34 | - // TODO Add an alert visibile only for connected admin users |
|
| 35 | - $current_post = get_post(); |
|
| 36 | - |
|
| 37 | - $entity_ids = ( Wordlift_Entity_Service::TYPE_NAME === $current_post->post_type ) ? |
|
| 38 | - $current_post->ID : |
|
| 39 | - wl_core_get_related_entity_ids( $current_post->ID ); |
|
| 40 | - |
|
| 41 | - if ( 0 === count( $entity_ids ) ) { |
|
| 42 | - return ''; |
|
| 43 | - } |
|
| 44 | - |
|
| 45 | - $div_id = 'wordlift-faceted-entity-search-widget'; |
|
| 46 | - |
|
| 47 | - wp_enqueue_style( 'wordlift-faceted-search', dirname( plugin_dir_url( __FILE__ ) ) . '/css/wordlift-faceted-entity-search-widget.min.css' ); |
|
| 48 | - wp_enqueue_script( 'angularjs', 'https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.3.11/angular.min.js' ); |
|
| 49 | - wp_enqueue_script( 'angularjs-touch', 'https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.3.11/angular-touch.min.js' ); |
|
| 50 | - |
|
| 51 | - wp_enqueue_script( 'wordlift-faceted-search', dirname( plugin_dir_url( __FILE__ ) ) . '/js/wordlift-faceted-entity-search-widget.min.js' ); |
|
| 52 | - |
|
| 53 | - wp_localize_script( |
|
| 54 | - 'wordlift-faceted-search', |
|
| 55 | - 'wl_faceted_search_params', array( |
|
| 56 | - 'ajax_url' => admin_url( 'admin-ajax.php' ), |
|
| 57 | - 'action' => 'wl_faceted_search', |
|
| 58 | - 'post_id' => $current_post->ID, |
|
| 59 | - 'entity_ids' => $entity_ids, |
|
| 60 | - 'div_id' => $div_id, |
|
| 61 | - 'defaultThumbnailPath' => WL_DEFAULT_THUMBNAIL_PATH, |
|
| 62 | - 'attrs' => $shortcode_atts, |
|
| 63 | - 'l10n' => array( |
|
| 64 | - 'what' => _x( 'What', 'Faceted Search Widget', 'wordlift' ), |
|
| 65 | - 'who' => _x( 'Who', 'Faceted Search Widget', 'wordlift' ), |
|
| 66 | - 'where' => _x( 'Where', 'Faceted Search Widget', 'wordlift' ), |
|
| 67 | - 'when' => _x( 'When', 'Faceted Search Widget', 'wordlift' ), |
|
| 68 | - ), |
|
| 69 | - ) |
|
| 70 | - ); |
|
| 71 | - |
|
| 72 | - return '<div id="' . $div_id . '" style="width:100%"></div>'; |
|
| 8 | + // Extract attributes and set default values. |
|
| 9 | + $shortcode_atts = shortcode_atts( array( |
|
| 10 | + 'title' => __( 'Related articles', 'wordlift' ), |
|
| 11 | + 'show_facets' => true, |
|
| 12 | + 'with_carousel' => true, |
|
| 13 | + 'squared_thumbs' => false, |
|
| 14 | + |
|
| 15 | + ), $atts ); |
|
| 16 | + |
|
| 17 | + foreach ( |
|
| 18 | + array( |
|
| 19 | + 'show_facets', |
|
| 20 | + 'with_carousel', |
|
| 21 | + 'squared_thumbs', |
|
| 22 | + ) as $att |
|
| 23 | + ) { |
|
| 24 | + |
|
| 25 | + // See http://wordpress.stackexchange.com/questions/119294/pass-boolean-value-in-shortcode |
|
| 26 | + $shortcode_atts[ $att ] = filter_var( |
|
| 27 | + $shortcode_atts[ $att ], FILTER_VALIDATE_BOOLEAN |
|
| 28 | + ); |
|
| 29 | + } |
|
| 30 | + |
|
| 31 | + |
|
| 32 | + // If the current post is not an entity and has no related entities |
|
| 33 | + // than the shortcode cannot be rendered |
|
| 34 | + // TODO Add an alert visibile only for connected admin users |
|
| 35 | + $current_post = get_post(); |
|
| 36 | + |
|
| 37 | + $entity_ids = ( Wordlift_Entity_Service::TYPE_NAME === $current_post->post_type ) ? |
|
| 38 | + $current_post->ID : |
|
| 39 | + wl_core_get_related_entity_ids( $current_post->ID ); |
|
| 40 | + |
|
| 41 | + if ( 0 === count( $entity_ids ) ) { |
|
| 42 | + return ''; |
|
| 43 | + } |
|
| 44 | + |
|
| 45 | + $div_id = 'wordlift-faceted-entity-search-widget'; |
|
| 46 | + |
|
| 47 | + wp_enqueue_style( 'wordlift-faceted-search', dirname( plugin_dir_url( __FILE__ ) ) . '/css/wordlift-faceted-entity-search-widget.min.css' ); |
|
| 48 | + wp_enqueue_script( 'angularjs', 'https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.3.11/angular.min.js' ); |
|
| 49 | + wp_enqueue_script( 'angularjs-touch', 'https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.3.11/angular-touch.min.js' ); |
|
| 50 | + |
|
| 51 | + wp_enqueue_script( 'wordlift-faceted-search', dirname( plugin_dir_url( __FILE__ ) ) . '/js/wordlift-faceted-entity-search-widget.min.js' ); |
|
| 52 | + |
|
| 53 | + wp_localize_script( |
|
| 54 | + 'wordlift-faceted-search', |
|
| 55 | + 'wl_faceted_search_params', array( |
|
| 56 | + 'ajax_url' => admin_url( 'admin-ajax.php' ), |
|
| 57 | + 'action' => 'wl_faceted_search', |
|
| 58 | + 'post_id' => $current_post->ID, |
|
| 59 | + 'entity_ids' => $entity_ids, |
|
| 60 | + 'div_id' => $div_id, |
|
| 61 | + 'defaultThumbnailPath' => WL_DEFAULT_THUMBNAIL_PATH, |
|
| 62 | + 'attrs' => $shortcode_atts, |
|
| 63 | + 'l10n' => array( |
|
| 64 | + 'what' => _x( 'What', 'Faceted Search Widget', 'wordlift' ), |
|
| 65 | + 'who' => _x( 'Who', 'Faceted Search Widget', 'wordlift' ), |
|
| 66 | + 'where' => _x( 'Where', 'Faceted Search Widget', 'wordlift' ), |
|
| 67 | + 'when' => _x( 'When', 'Faceted Search Widget', 'wordlift' ), |
|
| 68 | + ), |
|
| 69 | + ) |
|
| 70 | + ); |
|
| 71 | + |
|
| 72 | + return '<div id="' . $div_id . '" style="width:100%"></div>'; |
|
| 73 | 73 | } |
| 74 | 74 | |
| 75 | 75 | add_shortcode( 'wl_faceted_search', 'wl_shortcode_faceted_search' ); |
@@ -80,125 +80,125 @@ discard block |
||
| 80 | 80 | */ |
| 81 | 81 | function wl_shortcode_faceted_search_ajax( $http_raw_data = null ) { |
| 82 | 82 | |
| 83 | - // Post ID must be defined |
|
| 84 | - if ( ! isset( $_GET['post_id'] ) ) { |
|
| 85 | - wp_die( 'No post_id given' ); |
|
| 83 | + // Post ID must be defined |
|
| 84 | + if ( ! isset( $_GET['post_id'] ) ) { |
|
| 85 | + wp_die( 'No post_id given' ); |
|
| 86 | 86 | |
| 87 | - return; |
|
| 88 | - } |
|
| 87 | + return; |
|
| 88 | + } |
|
| 89 | 89 | |
| 90 | - // Extract filtering conditions |
|
| 91 | - $filtering_entity_uris = ( null == $http_raw_data ) ? file_get_contents( "php://input" ) : $http_raw_data; |
|
| 92 | - $filtering_entity_uris = json_decode( $filtering_entity_uris ); |
|
| 90 | + // Extract filtering conditions |
|
| 91 | + $filtering_entity_uris = ( null == $http_raw_data ) ? file_get_contents( "php://input" ) : $http_raw_data; |
|
| 92 | + $filtering_entity_uris = json_decode( $filtering_entity_uris ); |
|
| 93 | 93 | |
| 94 | - $current_post_id = $_GET['post_id']; |
|
| 95 | - $current_post = get_post( $current_post_id ); |
|
| 94 | + $current_post_id = $_GET['post_id']; |
|
| 95 | + $current_post = get_post( $current_post_id ); |
|
| 96 | 96 | |
| 97 | - // Post ID has to match an existing item |
|
| 98 | - if ( null === $current_post ) { |
|
| 99 | - wp_die( 'No valid post_id given' ); |
|
| 97 | + // Post ID has to match an existing item |
|
| 98 | + if ( null === $current_post ) { |
|
| 99 | + wp_die( 'No valid post_id given' ); |
|
| 100 | 100 | |
| 101 | - return; |
|
| 102 | - } |
|
| 101 | + return; |
|
| 102 | + } |
|
| 103 | 103 | |
| 104 | - // If the current post is an entity, |
|
| 105 | - // the current post is used as main entity. |
|
| 106 | - // Otherwise, current post related entities are used. |
|
| 107 | - $entity_ids = ( Wordlift_Entity_Service::TYPE_NAME === $current_post->post_type ) ? |
|
| 108 | - array( $current_post->ID ) : |
|
| 109 | - wl_core_get_related_entity_ids( $current_post->ID ); |
|
| 104 | + // If the current post is an entity, |
|
| 105 | + // the current post is used as main entity. |
|
| 106 | + // Otherwise, current post related entities are used. |
|
| 107 | + $entity_ids = ( Wordlift_Entity_Service::TYPE_NAME === $current_post->post_type ) ? |
|
| 108 | + array( $current_post->ID ) : |
|
| 109 | + wl_core_get_related_entity_ids( $current_post->ID ); |
|
| 110 | 110 | |
| 111 | - // If there are no entities we cannot render the widget |
|
| 112 | - if ( 0 === count( $entity_ids ) ) { |
|
| 113 | - wp_die( 'No entities available' ); |
|
| 111 | + // If there are no entities we cannot render the widget |
|
| 112 | + if ( 0 === count( $entity_ids ) ) { |
|
| 113 | + wp_die( 'No entities available' ); |
|
| 114 | 114 | |
| 115 | - return; |
|
| 116 | - } |
|
| 115 | + return; |
|
| 116 | + } |
|
| 117 | 117 | |
| 118 | - // Retrieve requested type |
|
| 119 | - $required_type = ( isset( $_GET['type'] ) ) ? $_GET['type'] : null; |
|
| 118 | + // Retrieve requested type |
|
| 119 | + $required_type = ( isset( $_GET['type'] ) ) ? $_GET['type'] : null; |
|
| 120 | 120 | |
| 121 | - // Set up data structures |
|
| 122 | - $referencing_posts = wl_core_get_posts( array( |
|
| 123 | - 'get' => 'posts', |
|
| 124 | - 'post__not_in' => array( $current_post_id ), |
|
| 125 | - 'related_to__in' => $entity_ids, |
|
| 126 | - 'post_type' => 'post', |
|
| 127 | - 'as' => 'subject', |
|
| 128 | - 'post_status' => 'publish', |
|
| 129 | - ) ); |
|
| 121 | + // Set up data structures |
|
| 122 | + $referencing_posts = wl_core_get_posts( array( |
|
| 123 | + 'get' => 'posts', |
|
| 124 | + 'post__not_in' => array( $current_post_id ), |
|
| 125 | + 'related_to__in' => $entity_ids, |
|
| 126 | + 'post_type' => 'post', |
|
| 127 | + 'as' => 'subject', |
|
| 128 | + 'post_status' => 'publish', |
|
| 129 | + ) ); |
|
| 130 | 130 | |
| 131 | - $referencing_post_ids = array_map( function ( $p ) { |
|
| 132 | - return $p->ID; |
|
| 133 | - }, $referencing_posts ); |
|
| 134 | - $results = array(); |
|
| 131 | + $referencing_post_ids = array_map( function ( $p ) { |
|
| 132 | + return $p->ID; |
|
| 133 | + }, $referencing_posts ); |
|
| 134 | + $results = array(); |
|
| 135 | 135 | |
| 136 | - if ( 'posts' === $required_type ) { |
|
| 136 | + if ( 'posts' === $required_type ) { |
|
| 137 | 137 | |
| 138 | - // Required filtered posts. |
|
| 139 | - wl_write_log( "Going to find related posts for the current post [ post ID :: $current_post_id ]" ); |
|
| 138 | + // Required filtered posts. |
|
| 139 | + wl_write_log( "Going to find related posts for the current post [ post ID :: $current_post_id ]" ); |
|
| 140 | 140 | |
| 141 | - $filtered_posts = ( empty( $filtering_entity_uris ) ) ? |
|
| 142 | - $referencing_posts : |
|
| 143 | - wl_core_get_posts( array( |
|
| 144 | - 'get' => 'posts', |
|
| 145 | - 'post__in' => $referencing_post_ids, |
|
| 146 | - 'related_to__in' => wl_get_entity_post_ids_by_uris( $filtering_entity_uris ), |
|
| 147 | - 'post_type' => 'post', |
|
| 148 | - 'as' => 'subject', |
|
| 149 | - ) ); |
|
| 141 | + $filtered_posts = ( empty( $filtering_entity_uris ) ) ? |
|
| 142 | + $referencing_posts : |
|
| 143 | + wl_core_get_posts( array( |
|
| 144 | + 'get' => 'posts', |
|
| 145 | + 'post__in' => $referencing_post_ids, |
|
| 146 | + 'related_to__in' => wl_get_entity_post_ids_by_uris( $filtering_entity_uris ), |
|
| 147 | + 'post_type' => 'post', |
|
| 148 | + 'as' => 'subject', |
|
| 149 | + ) ); |
|
| 150 | 150 | |
| 151 | - if ( $filtered_posts ) { |
|
| 152 | - foreach ( $filtered_posts as $post_obj ) { |
|
| 151 | + if ( $filtered_posts ) { |
|
| 152 | + foreach ( $filtered_posts as $post_obj ) { |
|
| 153 | 153 | |
| 154 | - $thumbnail = wp_get_attachment_url( get_post_thumbnail_id( $post_obj->ID, 'thumbnail' ) ); |
|
| 155 | - $post_obj->thumbnail = ( $thumbnail ) ? |
|
| 156 | - $thumbnail : WL_DEFAULT_THUMBNAIL_PATH; |
|
| 157 | - $post_obj->permalink = get_post_permalink( $post_obj->ID ); |
|
| 154 | + $thumbnail = wp_get_attachment_url( get_post_thumbnail_id( $post_obj->ID, 'thumbnail' ) ); |
|
| 155 | + $post_obj->thumbnail = ( $thumbnail ) ? |
|
| 156 | + $thumbnail : WL_DEFAULT_THUMBNAIL_PATH; |
|
| 157 | + $post_obj->permalink = get_post_permalink( $post_obj->ID ); |
|
| 158 | 158 | |
| 159 | - $results[] = $post_obj; |
|
| 160 | - } |
|
| 161 | - } |
|
| 162 | - } else { |
|
| 159 | + $results[] = $post_obj; |
|
| 160 | + } |
|
| 161 | + } |
|
| 162 | + } else { |
|
| 163 | 163 | |
| 164 | - global $wpdb; |
|
| 164 | + global $wpdb; |
|
| 165 | 165 | |
| 166 | - wl_write_log( "Going to find related entities for the current post [ post ID :: $current_post_id ]" ); |
|
| 166 | + wl_write_log( "Going to find related entities for the current post [ post ID :: $current_post_id ]" ); |
|
| 167 | 167 | |
| 168 | - // Retrieve Wordlift relation instances table name |
|
| 169 | - $table_name = wl_core_get_relation_instances_table_name(); |
|
| 168 | + // Retrieve Wordlift relation instances table name |
|
| 169 | + $table_name = wl_core_get_relation_instances_table_name(); |
|
| 170 | 170 | |
| 171 | - $subject_ids = implode( ',', $referencing_post_ids ); |
|
| 171 | + $subject_ids = implode( ',', $referencing_post_ids ); |
|
| 172 | 172 | |
| 173 | - $query = <<<EOF |
|
| 173 | + $query = <<<EOF |
|
| 174 | 174 | SELECT object_id as ID, count( object_id ) as counter |
| 175 | 175 | FROM $table_name |
| 176 | 176 | WHERE subject_id IN ($subject_ids) and object_id != ($current_post_id) |
| 177 | 177 | GROUP BY object_id; |
| 178 | 178 | EOF; |
| 179 | - wl_write_log( "Going to find related entities for the current post [ post ID :: $current_post_id ] [ query :: $query ]" ); |
|
| 179 | + wl_write_log( "Going to find related entities for the current post [ post ID :: $current_post_id ] [ query :: $query ]" ); |
|
| 180 | 180 | |
| 181 | - $entities = $wpdb->get_results( $query, OBJECT ); |
|
| 181 | + $entities = $wpdb->get_results( $query, OBJECT ); |
|
| 182 | 182 | |
| 183 | - wl_write_log( "Entities found " . count( $entities ) ); |
|
| 183 | + wl_write_log( "Entities found " . count( $entities ) ); |
|
| 184 | 184 | |
| 185 | - foreach ( $entities as $obj ) { |
|
| 185 | + foreach ( $entities as $obj ) { |
|
| 186 | 186 | |
| 187 | - $entity = get_post( $obj->ID ); |
|
| 188 | - // Ensure only valid and published entities are returned |
|
| 189 | - if ( ( null !== $entity ) && ( 'publish' === $entity->post_status ) ) { |
|
| 187 | + $entity = get_post( $obj->ID ); |
|
| 188 | + // Ensure only valid and published entities are returned |
|
| 189 | + if ( ( null !== $entity ) && ( 'publish' === $entity->post_status ) ) { |
|
| 190 | 190 | |
| 191 | - $serialized_entity = wl_serialize_entity( $entity ); |
|
| 192 | - $serialized_entity['counter'] = $obj->counter; |
|
| 193 | - $serialized_entity['createdAt'] = $entity->post_date; |
|
| 191 | + $serialized_entity = wl_serialize_entity( $entity ); |
|
| 192 | + $serialized_entity['counter'] = $obj->counter; |
|
| 193 | + $serialized_entity['createdAt'] = $entity->post_date; |
|
| 194 | 194 | |
| 195 | - $results[] = $serialized_entity; |
|
| 196 | - } |
|
| 197 | - } |
|
| 195 | + $results[] = $serialized_entity; |
|
| 196 | + } |
|
| 197 | + } |
|
| 198 | 198 | |
| 199 | - } |
|
| 199 | + } |
|
| 200 | 200 | |
| 201 | - wl_core_send_json( $results ); |
|
| 201 | + wl_core_send_json( $results ); |
|
| 202 | 202 | |
| 203 | 203 | } |
| 204 | 204 | |
@@ -3,16 +3,16 @@ discard block |
||
| 3 | 3 | /** |
| 4 | 4 | * Function in charge of diplaying the [wl-faceted-search] |
| 5 | 5 | */ |
| 6 | -function wl_shortcode_faceted_search( $atts ) { |
|
| 6 | +function wl_shortcode_faceted_search($atts) { |
|
| 7 | 7 | |
| 8 | 8 | // Extract attributes and set default values. |
| 9 | - $shortcode_atts = shortcode_atts( array( |
|
| 10 | - 'title' => __( 'Related articles', 'wordlift' ), |
|
| 9 | + $shortcode_atts = shortcode_atts(array( |
|
| 10 | + 'title' => __('Related articles', 'wordlift'), |
|
| 11 | 11 | 'show_facets' => true, |
| 12 | 12 | 'with_carousel' => true, |
| 13 | 13 | 'squared_thumbs' => false, |
| 14 | 14 | |
| 15 | - ), $atts ); |
|
| 15 | + ), $atts); |
|
| 16 | 16 | |
| 17 | 17 | foreach ( |
| 18 | 18 | array( |
@@ -23,8 +23,8 @@ discard block |
||
| 23 | 23 | ) { |
| 24 | 24 | |
| 25 | 25 | // See http://wordpress.stackexchange.com/questions/119294/pass-boolean-value-in-shortcode |
| 26 | - $shortcode_atts[ $att ] = filter_var( |
|
| 27 | - $shortcode_atts[ $att ], FILTER_VALIDATE_BOOLEAN |
|
| 26 | + $shortcode_atts[$att] = filter_var( |
|
| 27 | + $shortcode_atts[$att], FILTER_VALIDATE_BOOLEAN |
|
| 28 | 28 | ); |
| 29 | 29 | } |
| 30 | 30 | |
@@ -34,26 +34,25 @@ discard block |
||
| 34 | 34 | // TODO Add an alert visibile only for connected admin users |
| 35 | 35 | $current_post = get_post(); |
| 36 | 36 | |
| 37 | - $entity_ids = ( Wordlift_Entity_Service::TYPE_NAME === $current_post->post_type ) ? |
|
| 38 | - $current_post->ID : |
|
| 39 | - wl_core_get_related_entity_ids( $current_post->ID ); |
|
| 37 | + $entity_ids = (Wordlift_Entity_Service::TYPE_NAME === $current_post->post_type) ? |
|
| 38 | + $current_post->ID : wl_core_get_related_entity_ids($current_post->ID); |
|
| 40 | 39 | |
| 41 | - if ( 0 === count( $entity_ids ) ) { |
|
| 40 | + if (0 === count($entity_ids)) { |
|
| 42 | 41 | return ''; |
| 43 | 42 | } |
| 44 | 43 | |
| 45 | 44 | $div_id = 'wordlift-faceted-entity-search-widget'; |
| 46 | 45 | |
| 47 | - wp_enqueue_style( 'wordlift-faceted-search', dirname( plugin_dir_url( __FILE__ ) ) . '/css/wordlift-faceted-entity-search-widget.min.css' ); |
|
| 48 | - wp_enqueue_script( 'angularjs', 'https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.3.11/angular.min.js' ); |
|
| 49 | - wp_enqueue_script( 'angularjs-touch', 'https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.3.11/angular-touch.min.js' ); |
|
| 46 | + wp_enqueue_style('wordlift-faceted-search', dirname(plugin_dir_url(__FILE__)).'/css/wordlift-faceted-entity-search-widget.min.css'); |
|
| 47 | + wp_enqueue_script('angularjs', 'https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.3.11/angular.min.js'); |
|
| 48 | + wp_enqueue_script('angularjs-touch', 'https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.3.11/angular-touch.min.js'); |
|
| 50 | 49 | |
| 51 | - wp_enqueue_script( 'wordlift-faceted-search', dirname( plugin_dir_url( __FILE__ ) ) . '/js/wordlift-faceted-entity-search-widget.min.js' ); |
|
| 50 | + wp_enqueue_script('wordlift-faceted-search', dirname(plugin_dir_url(__FILE__)).'/js/wordlift-faceted-entity-search-widget.min.js'); |
|
| 52 | 51 | |
| 53 | 52 | wp_localize_script( |
| 54 | 53 | 'wordlift-faceted-search', |
| 55 | 54 | 'wl_faceted_search_params', array( |
| 56 | - 'ajax_url' => admin_url( 'admin-ajax.php' ), |
|
| 55 | + 'ajax_url' => admin_url('admin-ajax.php'), |
|
| 57 | 56 | 'action' => 'wl_faceted_search', |
| 58 | 57 | 'post_id' => $current_post->ID, |
| 59 | 58 | 'entity_ids' => $entity_ids, |
@@ -61,42 +60,42 @@ discard block |
||
| 61 | 60 | 'defaultThumbnailPath' => WL_DEFAULT_THUMBNAIL_PATH, |
| 62 | 61 | 'attrs' => $shortcode_atts, |
| 63 | 62 | 'l10n' => array( |
| 64 | - 'what' => _x( 'What', 'Faceted Search Widget', 'wordlift' ), |
|
| 65 | - 'who' => _x( 'Who', 'Faceted Search Widget', 'wordlift' ), |
|
| 66 | - 'where' => _x( 'Where', 'Faceted Search Widget', 'wordlift' ), |
|
| 67 | - 'when' => _x( 'When', 'Faceted Search Widget', 'wordlift' ), |
|
| 63 | + 'what' => _x('What', 'Faceted Search Widget', 'wordlift'), |
|
| 64 | + 'who' => _x('Who', 'Faceted Search Widget', 'wordlift'), |
|
| 65 | + 'where' => _x('Where', 'Faceted Search Widget', 'wordlift'), |
|
| 66 | + 'when' => _x('When', 'Faceted Search Widget', 'wordlift'), |
|
| 68 | 67 | ), |
| 69 | 68 | ) |
| 70 | 69 | ); |
| 71 | 70 | |
| 72 | - return '<div id="' . $div_id . '" style="width:100%"></div>'; |
|
| 71 | + return '<div id="'.$div_id.'" style="width:100%"></div>'; |
|
| 73 | 72 | } |
| 74 | 73 | |
| 75 | -add_shortcode( 'wl_faceted_search', 'wl_shortcode_faceted_search' ); |
|
| 74 | +add_shortcode('wl_faceted_search', 'wl_shortcode_faceted_search'); |
|
| 76 | 75 | |
| 77 | 76 | |
| 78 | 77 | /* |
| 79 | 78 | * Ajax call for the faceted search widget |
| 80 | 79 | */ |
| 81 | -function wl_shortcode_faceted_search_ajax( $http_raw_data = null ) { |
|
| 80 | +function wl_shortcode_faceted_search_ajax($http_raw_data = null) { |
|
| 82 | 81 | |
| 83 | 82 | // Post ID must be defined |
| 84 | - if ( ! isset( $_GET['post_id'] ) ) { |
|
| 85 | - wp_die( 'No post_id given' ); |
|
| 83 | + if ( ! isset($_GET['post_id'])) { |
|
| 84 | + wp_die('No post_id given'); |
|
| 86 | 85 | |
| 87 | 86 | return; |
| 88 | 87 | } |
| 89 | 88 | |
| 90 | 89 | // Extract filtering conditions |
| 91 | - $filtering_entity_uris = ( null == $http_raw_data ) ? file_get_contents( "php://input" ) : $http_raw_data; |
|
| 92 | - $filtering_entity_uris = json_decode( $filtering_entity_uris ); |
|
| 90 | + $filtering_entity_uris = (null == $http_raw_data) ? file_get_contents("php://input") : $http_raw_data; |
|
| 91 | + $filtering_entity_uris = json_decode($filtering_entity_uris); |
|
| 93 | 92 | |
| 94 | 93 | $current_post_id = $_GET['post_id']; |
| 95 | - $current_post = get_post( $current_post_id ); |
|
| 94 | + $current_post = get_post($current_post_id); |
|
| 96 | 95 | |
| 97 | 96 | // Post ID has to match an existing item |
| 98 | - if ( null === $current_post ) { |
|
| 99 | - wp_die( 'No valid post_id given' ); |
|
| 97 | + if (null === $current_post) { |
|
| 98 | + wp_die('No valid post_id given'); |
|
| 100 | 99 | |
| 101 | 100 | return; |
| 102 | 101 | } |
@@ -104,57 +103,55 @@ discard block |
||
| 104 | 103 | // If the current post is an entity, |
| 105 | 104 | // the current post is used as main entity. |
| 106 | 105 | // Otherwise, current post related entities are used. |
| 107 | - $entity_ids = ( Wordlift_Entity_Service::TYPE_NAME === $current_post->post_type ) ? |
|
| 108 | - array( $current_post->ID ) : |
|
| 109 | - wl_core_get_related_entity_ids( $current_post->ID ); |
|
| 106 | + $entity_ids = (Wordlift_Entity_Service::TYPE_NAME === $current_post->post_type) ? |
|
| 107 | + array($current_post->ID) : wl_core_get_related_entity_ids($current_post->ID); |
|
| 110 | 108 | |
| 111 | 109 | // If there are no entities we cannot render the widget |
| 112 | - if ( 0 === count( $entity_ids ) ) { |
|
| 113 | - wp_die( 'No entities available' ); |
|
| 110 | + if (0 === count($entity_ids)) { |
|
| 111 | + wp_die('No entities available'); |
|
| 114 | 112 | |
| 115 | 113 | return; |
| 116 | 114 | } |
| 117 | 115 | |
| 118 | 116 | // Retrieve requested type |
| 119 | - $required_type = ( isset( $_GET['type'] ) ) ? $_GET['type'] : null; |
|
| 117 | + $required_type = (isset($_GET['type'])) ? $_GET['type'] : null; |
|
| 120 | 118 | |
| 121 | 119 | // Set up data structures |
| 122 | - $referencing_posts = wl_core_get_posts( array( |
|
| 120 | + $referencing_posts = wl_core_get_posts(array( |
|
| 123 | 121 | 'get' => 'posts', |
| 124 | - 'post__not_in' => array( $current_post_id ), |
|
| 122 | + 'post__not_in' => array($current_post_id), |
|
| 125 | 123 | 'related_to__in' => $entity_ids, |
| 126 | 124 | 'post_type' => 'post', |
| 127 | 125 | 'as' => 'subject', |
| 128 | 126 | 'post_status' => 'publish', |
| 129 | - ) ); |
|
| 127 | + )); |
|
| 130 | 128 | |
| 131 | - $referencing_post_ids = array_map( function ( $p ) { |
|
| 129 | + $referencing_post_ids = array_map(function($p) { |
|
| 132 | 130 | return $p->ID; |
| 133 | - }, $referencing_posts ); |
|
| 131 | + }, $referencing_posts); |
|
| 134 | 132 | $results = array(); |
| 135 | 133 | |
| 136 | - if ( 'posts' === $required_type ) { |
|
| 134 | + if ('posts' === $required_type) { |
|
| 137 | 135 | |
| 138 | 136 | // Required filtered posts. |
| 139 | - wl_write_log( "Going to find related posts for the current post [ post ID :: $current_post_id ]" ); |
|
| 137 | + wl_write_log("Going to find related posts for the current post [ post ID :: $current_post_id ]"); |
|
| 140 | 138 | |
| 141 | - $filtered_posts = ( empty( $filtering_entity_uris ) ) ? |
|
| 142 | - $referencing_posts : |
|
| 143 | - wl_core_get_posts( array( |
|
| 139 | + $filtered_posts = (empty($filtering_entity_uris)) ? |
|
| 140 | + $referencing_posts : wl_core_get_posts(array( |
|
| 144 | 141 | 'get' => 'posts', |
| 145 | 142 | 'post__in' => $referencing_post_ids, |
| 146 | - 'related_to__in' => wl_get_entity_post_ids_by_uris( $filtering_entity_uris ), |
|
| 143 | + 'related_to__in' => wl_get_entity_post_ids_by_uris($filtering_entity_uris), |
|
| 147 | 144 | 'post_type' => 'post', |
| 148 | 145 | 'as' => 'subject', |
| 149 | - ) ); |
|
| 146 | + )); |
|
| 150 | 147 | |
| 151 | - if ( $filtered_posts ) { |
|
| 152 | - foreach ( $filtered_posts as $post_obj ) { |
|
| 148 | + if ($filtered_posts) { |
|
| 149 | + foreach ($filtered_posts as $post_obj) { |
|
| 153 | 150 | |
| 154 | - $thumbnail = wp_get_attachment_url( get_post_thumbnail_id( $post_obj->ID, 'thumbnail' ) ); |
|
| 155 | - $post_obj->thumbnail = ( $thumbnail ) ? |
|
| 151 | + $thumbnail = wp_get_attachment_url(get_post_thumbnail_id($post_obj->ID, 'thumbnail')); |
|
| 152 | + $post_obj->thumbnail = ($thumbnail) ? |
|
| 156 | 153 | $thumbnail : WL_DEFAULT_THUMBNAIL_PATH; |
| 157 | - $post_obj->permalink = get_post_permalink( $post_obj->ID ); |
|
| 154 | + $post_obj->permalink = get_post_permalink($post_obj->ID); |
|
| 158 | 155 | |
| 159 | 156 | $results[] = $post_obj; |
| 160 | 157 | } |
@@ -163,12 +160,12 @@ discard block |
||
| 163 | 160 | |
| 164 | 161 | global $wpdb; |
| 165 | 162 | |
| 166 | - wl_write_log( "Going to find related entities for the current post [ post ID :: $current_post_id ]" ); |
|
| 163 | + wl_write_log("Going to find related entities for the current post [ post ID :: $current_post_id ]"); |
|
| 167 | 164 | |
| 168 | 165 | // Retrieve Wordlift relation instances table name |
| 169 | 166 | $table_name = wl_core_get_relation_instances_table_name(); |
| 170 | 167 | |
| 171 | - $subject_ids = implode( ',', $referencing_post_ids ); |
|
| 168 | + $subject_ids = implode(',', $referencing_post_ids); |
|
| 172 | 169 | |
| 173 | 170 | $query = <<<EOF |
| 174 | 171 | SELECT object_id as ID, count( object_id ) as counter |
@@ -176,19 +173,19 @@ discard block |
||
| 176 | 173 | WHERE subject_id IN ($subject_ids) and object_id != ($current_post_id) |
| 177 | 174 | GROUP BY object_id; |
| 178 | 175 | EOF; |
| 179 | - wl_write_log( "Going to find related entities for the current post [ post ID :: $current_post_id ] [ query :: $query ]" ); |
|
| 176 | + wl_write_log("Going to find related entities for the current post [ post ID :: $current_post_id ] [ query :: $query ]"); |
|
| 180 | 177 | |
| 181 | - $entities = $wpdb->get_results( $query, OBJECT ); |
|
| 178 | + $entities = $wpdb->get_results($query, OBJECT); |
|
| 182 | 179 | |
| 183 | - wl_write_log( "Entities found " . count( $entities ) ); |
|
| 180 | + wl_write_log("Entities found ".count($entities)); |
|
| 184 | 181 | |
| 185 | - foreach ( $entities as $obj ) { |
|
| 182 | + foreach ($entities as $obj) { |
|
| 186 | 183 | |
| 187 | - $entity = get_post( $obj->ID ); |
|
| 184 | + $entity = get_post($obj->ID); |
|
| 188 | 185 | // Ensure only valid and published entities are returned |
| 189 | - if ( ( null !== $entity ) && ( 'publish' === $entity->post_status ) ) { |
|
| 186 | + if ((null !== $entity) && ('publish' === $entity->post_status)) { |
|
| 190 | 187 | |
| 191 | - $serialized_entity = wl_serialize_entity( $entity ); |
|
| 188 | + $serialized_entity = wl_serialize_entity($entity); |
|
| 192 | 189 | $serialized_entity['counter'] = $obj->counter; |
| 193 | 190 | $serialized_entity['createdAt'] = $entity->post_date; |
| 194 | 191 | |
@@ -198,10 +195,10 @@ discard block |
||
| 198 | 195 | |
| 199 | 196 | } |
| 200 | 197 | |
| 201 | - wl_core_send_json( $results ); |
|
| 198 | + wl_core_send_json($results); |
|
| 202 | 199 | |
| 203 | 200 | } |
| 204 | 201 | |
| 205 | -add_action( 'wp_ajax_wl_faceted_search', 'wl_shortcode_faceted_search_ajax' ); |
|
| 206 | -add_action( 'wp_ajax_nopriv_wl_faceted_search', 'wl_shortcode_faceted_search_ajax' ); |
|
| 202 | +add_action('wp_ajax_wl_faceted_search', 'wl_shortcode_faceted_search_ajax'); |
|
| 203 | +add_action('wp_ajax_nopriv_wl_faceted_search', 'wl_shortcode_faceted_search_ajax'); |
|
| 207 | 204 | |
@@ -22,136 +22,136 @@ |
||
| 22 | 22 | */ |
| 23 | 23 | class Wordlift_Admin { |
| 24 | 24 | |
| 25 | - /** |
|
| 26 | - * The ID of this plugin. |
|
| 27 | - * |
|
| 28 | - * @since 1.0.0 |
|
| 29 | - * @access private |
|
| 30 | - * @var string $plugin_name The ID of this plugin. |
|
| 31 | - */ |
|
| 32 | - private $plugin_name; |
|
| 33 | - |
|
| 34 | - /** |
|
| 35 | - * The version of this plugin. |
|
| 36 | - * |
|
| 37 | - * @since 1.0.0 |
|
| 38 | - * @access private |
|
| 39 | - * @var string $version The current version of this plugin. |
|
| 40 | - */ |
|
| 41 | - private $version; |
|
| 42 | - |
|
| 43 | - /** |
|
| 44 | - * Initialize the class and set its properties. |
|
| 45 | - * |
|
| 46 | - * @since 1.0.0 |
|
| 47 | - * |
|
| 48 | - * @param string $plugin_name The name of this plugin. |
|
| 49 | - * @param string $version The version of this plugin. |
|
| 50 | - * @param \Wordlift_Configuration_Service $configuration_service The configuration service. |
|
| 51 | - * @param \Wordlift_Notice_Service $notice_service The notice service. |
|
| 52 | - */ |
|
| 53 | - public function __construct( $plugin_name, $version, $configuration_service, $notice_service ) { |
|
| 54 | - |
|
| 55 | - $this->plugin_name = $plugin_name; |
|
| 56 | - $this->version = $version; |
|
| 57 | - |
|
| 58 | - $dataset_uri = $configuration_service->get_dataset_uri(); |
|
| 59 | - $key = $configuration_service->get_key(); |
|
| 60 | - |
|
| 61 | - if ( empty( $dataset_uri ) ) { |
|
| 62 | - if ( empty( $key ) ) { |
|
| 63 | - $error = __( 'WordLift\'s key is unset: WordLift requires a key.', 'wordlift' ); |
|
| 64 | - } else { |
|
| 65 | - $error = __( 'WordLift\'s dataset URI is unset: please retry WordLift\'s configuration.', 'wordlift' ); |
|
| 66 | - } |
|
| 67 | - $notice_service->add_error( $error ); |
|
| 68 | - } |
|
| 69 | - |
|
| 70 | - } |
|
| 71 | - |
|
| 72 | - /** |
|
| 73 | - * Register the stylesheets for the admin area. |
|
| 74 | - * |
|
| 75 | - * @since 1.0.0 |
|
| 76 | - */ |
|
| 77 | - public function enqueue_styles() { |
|
| 78 | - |
|
| 79 | - /** |
|
| 80 | - * This function is provided for demonstration purposes only. |
|
| 81 | - * |
|
| 82 | - * An instance of this class should be passed to the run() function |
|
| 83 | - * defined in Wordlift_Loader as all of the hooks are defined |
|
| 84 | - * in that particular class. |
|
| 85 | - * |
|
| 86 | - * The Wordlift_Loader will then create the relationship |
|
| 87 | - * between the defined hooks and the functions defined in this |
|
| 88 | - * class. |
|
| 89 | - */ |
|
| 90 | - |
|
| 91 | - wp_enqueue_style( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'css/wordlift-admin.css', array(), $this->version, 'all' ); |
|
| 92 | - |
|
| 93 | - } |
|
| 94 | - |
|
| 95 | - /** |
|
| 96 | - * Register the JavaScript for the admin area. |
|
| 97 | - * |
|
| 98 | - * @since 1.0.0 |
|
| 99 | - */ |
|
| 100 | - public function enqueue_scripts() { |
|
| 101 | - |
|
| 102 | - /** |
|
| 103 | - * This function is provided for demonstration purposes only. |
|
| 104 | - * |
|
| 105 | - * An instance of this class should be passed to the run() function |
|
| 106 | - * defined in Wordlift_Loader as all of the hooks are defined |
|
| 107 | - * in that particular class. |
|
| 108 | - * |
|
| 109 | - * The Wordlift_Loader will then create the relationship |
|
| 110 | - * between the defined hooks and the functions defined in this |
|
| 111 | - * class. |
|
| 112 | - */ |
|
| 113 | - |
|
| 114 | - $configuration_service = Wordlift_Configuration_Service::get_instance(); |
|
| 115 | - |
|
| 116 | - // Enqueue the admin scripts. |
|
| 117 | - wp_enqueue_script( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'js/wordlift-admin.bundle.js', array( |
|
| 118 | - 'jquery', |
|
| 119 | - 'underscore', |
|
| 120 | - 'backbone', |
|
| 121 | - ), $this->version, false ); |
|
| 122 | - |
|
| 123 | - // Set the basic params. |
|
| 124 | - $params = array( |
|
| 125 | - // @todo scripts in admin should use wp.post. |
|
| 126 | - 'ajax_url' => admin_url( 'admin-ajax.php' ), |
|
| 127 | - // @todo remove specific actions from settings. |
|
| 128 | - 'action' => 'entity_by_title', |
|
| 129 | - 'datasetUri' => $configuration_service->get_dataset_uri(), |
|
| 130 | - 'language' => $configuration_service->get_language_code(), |
|
| 131 | - 'link_by_default' => $configuration_service->is_link_by_default(), |
|
| 132 | - 'l10n' => array( |
|
| 133 | - 'You already published an entity with the same name' => __( 'You already published an entity with the same name: ', 'wordlift' ), |
|
| 134 | - 'logo_selection_title' => __( 'WordLift Choose Logo', 'wordlift' ), |
|
| 135 | - 'logo_selection_button' => array( 'text' => __( 'Choose Logo', 'wordlift' ) ), |
|
| 136 | - ), |
|
| 137 | - ); |
|
| 138 | - |
|
| 139 | - // Set post-related values if there's a current post. |
|
| 140 | - if ( null !== $post = $entity_being_edited = get_post() ) { |
|
| 141 | - |
|
| 142 | - $params['post_id'] = $entity_being_edited->ID; |
|
| 143 | - $params['entityBeingEdited'] = isset( $entity_being_edited->post_type ) && Wordlift_Entity_Service::TYPE_NAME == $entity_being_edited->post_type && is_numeric( get_the_ID() ); |
|
| 144 | - // We add the `itemId` here to give a chance to the analysis to use it in order to tell WLS to exclude it |
|
| 145 | - // from the results, since we don't want the current entity to be discovered by the analysis. |
|
| 146 | - // |
|
| 147 | - // See https://github.com/insideout10/wordlift-plugin/issues/345 |
|
| 148 | - $params['itemId'] = Wordlift_Entity_Service::get_instance()->get_uri( $entity_being_edited->ID ); |
|
| 149 | - |
|
| 150 | - } |
|
| 151 | - |
|
| 152 | - // Finally output the params as `wlSettings` for JavaScript code. |
|
| 153 | - wp_localize_script( $this->plugin_name, 'wlSettings', $params ); |
|
| 154 | - |
|
| 155 | - } |
|
| 25 | + /** |
|
| 26 | + * The ID of this plugin. |
|
| 27 | + * |
|
| 28 | + * @since 1.0.0 |
|
| 29 | + * @access private |
|
| 30 | + * @var string $plugin_name The ID of this plugin. |
|
| 31 | + */ |
|
| 32 | + private $plugin_name; |
|
| 33 | + |
|
| 34 | + /** |
|
| 35 | + * The version of this plugin. |
|
| 36 | + * |
|
| 37 | + * @since 1.0.0 |
|
| 38 | + * @access private |
|
| 39 | + * @var string $version The current version of this plugin. |
|
| 40 | + */ |
|
| 41 | + private $version; |
|
| 42 | + |
|
| 43 | + /** |
|
| 44 | + * Initialize the class and set its properties. |
|
| 45 | + * |
|
| 46 | + * @since 1.0.0 |
|
| 47 | + * |
|
| 48 | + * @param string $plugin_name The name of this plugin. |
|
| 49 | + * @param string $version The version of this plugin. |
|
| 50 | + * @param \Wordlift_Configuration_Service $configuration_service The configuration service. |
|
| 51 | + * @param \Wordlift_Notice_Service $notice_service The notice service. |
|
| 52 | + */ |
|
| 53 | + public function __construct( $plugin_name, $version, $configuration_service, $notice_service ) { |
|
| 54 | + |
|
| 55 | + $this->plugin_name = $plugin_name; |
|
| 56 | + $this->version = $version; |
|
| 57 | + |
|
| 58 | + $dataset_uri = $configuration_service->get_dataset_uri(); |
|
| 59 | + $key = $configuration_service->get_key(); |
|
| 60 | + |
|
| 61 | + if ( empty( $dataset_uri ) ) { |
|
| 62 | + if ( empty( $key ) ) { |
|
| 63 | + $error = __( 'WordLift\'s key is unset: WordLift requires a key.', 'wordlift' ); |
|
| 64 | + } else { |
|
| 65 | + $error = __( 'WordLift\'s dataset URI is unset: please retry WordLift\'s configuration.', 'wordlift' ); |
|
| 66 | + } |
|
| 67 | + $notice_service->add_error( $error ); |
|
| 68 | + } |
|
| 69 | + |
|
| 70 | + } |
|
| 71 | + |
|
| 72 | + /** |
|
| 73 | + * Register the stylesheets for the admin area. |
|
| 74 | + * |
|
| 75 | + * @since 1.0.0 |
|
| 76 | + */ |
|
| 77 | + public function enqueue_styles() { |
|
| 78 | + |
|
| 79 | + /** |
|
| 80 | + * This function is provided for demonstration purposes only. |
|
| 81 | + * |
|
| 82 | + * An instance of this class should be passed to the run() function |
|
| 83 | + * defined in Wordlift_Loader as all of the hooks are defined |
|
| 84 | + * in that particular class. |
|
| 85 | + * |
|
| 86 | + * The Wordlift_Loader will then create the relationship |
|
| 87 | + * between the defined hooks and the functions defined in this |
|
| 88 | + * class. |
|
| 89 | + */ |
|
| 90 | + |
|
| 91 | + wp_enqueue_style( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'css/wordlift-admin.css', array(), $this->version, 'all' ); |
|
| 92 | + |
|
| 93 | + } |
|
| 94 | + |
|
| 95 | + /** |
|
| 96 | + * Register the JavaScript for the admin area. |
|
| 97 | + * |
|
| 98 | + * @since 1.0.0 |
|
| 99 | + */ |
|
| 100 | + public function enqueue_scripts() { |
|
| 101 | + |
|
| 102 | + /** |
|
| 103 | + * This function is provided for demonstration purposes only. |
|
| 104 | + * |
|
| 105 | + * An instance of this class should be passed to the run() function |
|
| 106 | + * defined in Wordlift_Loader as all of the hooks are defined |
|
| 107 | + * in that particular class. |
|
| 108 | + * |
|
| 109 | + * The Wordlift_Loader will then create the relationship |
|
| 110 | + * between the defined hooks and the functions defined in this |
|
| 111 | + * class. |
|
| 112 | + */ |
|
| 113 | + |
|
| 114 | + $configuration_service = Wordlift_Configuration_Service::get_instance(); |
|
| 115 | + |
|
| 116 | + // Enqueue the admin scripts. |
|
| 117 | + wp_enqueue_script( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'js/wordlift-admin.bundle.js', array( |
|
| 118 | + 'jquery', |
|
| 119 | + 'underscore', |
|
| 120 | + 'backbone', |
|
| 121 | + ), $this->version, false ); |
|
| 122 | + |
|
| 123 | + // Set the basic params. |
|
| 124 | + $params = array( |
|
| 125 | + // @todo scripts in admin should use wp.post. |
|
| 126 | + 'ajax_url' => admin_url( 'admin-ajax.php' ), |
|
| 127 | + // @todo remove specific actions from settings. |
|
| 128 | + 'action' => 'entity_by_title', |
|
| 129 | + 'datasetUri' => $configuration_service->get_dataset_uri(), |
|
| 130 | + 'language' => $configuration_service->get_language_code(), |
|
| 131 | + 'link_by_default' => $configuration_service->is_link_by_default(), |
|
| 132 | + 'l10n' => array( |
|
| 133 | + 'You already published an entity with the same name' => __( 'You already published an entity with the same name: ', 'wordlift' ), |
|
| 134 | + 'logo_selection_title' => __( 'WordLift Choose Logo', 'wordlift' ), |
|
| 135 | + 'logo_selection_button' => array( 'text' => __( 'Choose Logo', 'wordlift' ) ), |
|
| 136 | + ), |
|
| 137 | + ); |
|
| 138 | + |
|
| 139 | + // Set post-related values if there's a current post. |
|
| 140 | + if ( null !== $post = $entity_being_edited = get_post() ) { |
|
| 141 | + |
|
| 142 | + $params['post_id'] = $entity_being_edited->ID; |
|
| 143 | + $params['entityBeingEdited'] = isset( $entity_being_edited->post_type ) && Wordlift_Entity_Service::TYPE_NAME == $entity_being_edited->post_type && is_numeric( get_the_ID() ); |
|
| 144 | + // We add the `itemId` here to give a chance to the analysis to use it in order to tell WLS to exclude it |
|
| 145 | + // from the results, since we don't want the current entity to be discovered by the analysis. |
|
| 146 | + // |
|
| 147 | + // See https://github.com/insideout10/wordlift-plugin/issues/345 |
|
| 148 | + $params['itemId'] = Wordlift_Entity_Service::get_instance()->get_uri( $entity_being_edited->ID ); |
|
| 149 | + |
|
| 150 | + } |
|
| 151 | + |
|
| 152 | + // Finally output the params as `wlSettings` for JavaScript code. |
|
| 153 | + wp_localize_script( $this->plugin_name, 'wlSettings', $params ); |
|
| 154 | + |
|
| 155 | + } |
|
| 156 | 156 | |
| 157 | 157 | } |
@@ -50,7 +50,7 @@ discard block |
||
| 50 | 50 | * @param \Wordlift_Configuration_Service $configuration_service The configuration service. |
| 51 | 51 | * @param \Wordlift_Notice_Service $notice_service The notice service. |
| 52 | 52 | */ |
| 53 | - public function __construct( $plugin_name, $version, $configuration_service, $notice_service ) { |
|
| 53 | + public function __construct($plugin_name, $version, $configuration_service, $notice_service) { |
|
| 54 | 54 | |
| 55 | 55 | $this->plugin_name = $plugin_name; |
| 56 | 56 | $this->version = $version; |
@@ -58,13 +58,13 @@ discard block |
||
| 58 | 58 | $dataset_uri = $configuration_service->get_dataset_uri(); |
| 59 | 59 | $key = $configuration_service->get_key(); |
| 60 | 60 | |
| 61 | - if ( empty( $dataset_uri ) ) { |
|
| 62 | - if ( empty( $key ) ) { |
|
| 63 | - $error = __( 'WordLift\'s key is unset: WordLift requires a key.', 'wordlift' ); |
|
| 61 | + if (empty($dataset_uri)) { |
|
| 62 | + if (empty($key)) { |
|
| 63 | + $error = __('WordLift\'s key is unset: WordLift requires a key.', 'wordlift'); |
|
| 64 | 64 | } else { |
| 65 | - $error = __( 'WordLift\'s dataset URI is unset: please retry WordLift\'s configuration.', 'wordlift' ); |
|
| 65 | + $error = __('WordLift\'s dataset URI is unset: please retry WordLift\'s configuration.', 'wordlift'); |
|
| 66 | 66 | } |
| 67 | - $notice_service->add_error( $error ); |
|
| 67 | + $notice_service->add_error($error); |
|
| 68 | 68 | } |
| 69 | 69 | |
| 70 | 70 | } |
@@ -88,7 +88,7 @@ discard block |
||
| 88 | 88 | * class. |
| 89 | 89 | */ |
| 90 | 90 | |
| 91 | - wp_enqueue_style( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'css/wordlift-admin.css', array(), $this->version, 'all' ); |
|
| 91 | + wp_enqueue_style($this->plugin_name, plugin_dir_url(__FILE__).'css/wordlift-admin.css', array(), $this->version, 'all'); |
|
| 92 | 92 | |
| 93 | 93 | } |
| 94 | 94 | |
@@ -114,43 +114,43 @@ discard block |
||
| 114 | 114 | $configuration_service = Wordlift_Configuration_Service::get_instance(); |
| 115 | 115 | |
| 116 | 116 | // Enqueue the admin scripts. |
| 117 | - wp_enqueue_script( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'js/wordlift-admin.bundle.js', array( |
|
| 117 | + wp_enqueue_script($this->plugin_name, plugin_dir_url(__FILE__).'js/wordlift-admin.bundle.js', array( |
|
| 118 | 118 | 'jquery', |
| 119 | 119 | 'underscore', |
| 120 | 120 | 'backbone', |
| 121 | - ), $this->version, false ); |
|
| 121 | + ), $this->version, false); |
|
| 122 | 122 | |
| 123 | 123 | // Set the basic params. |
| 124 | 124 | $params = array( |
| 125 | 125 | // @todo scripts in admin should use wp.post. |
| 126 | - 'ajax_url' => admin_url( 'admin-ajax.php' ), |
|
| 126 | + 'ajax_url' => admin_url('admin-ajax.php'), |
|
| 127 | 127 | // @todo remove specific actions from settings. |
| 128 | 128 | 'action' => 'entity_by_title', |
| 129 | 129 | 'datasetUri' => $configuration_service->get_dataset_uri(), |
| 130 | 130 | 'language' => $configuration_service->get_language_code(), |
| 131 | 131 | 'link_by_default' => $configuration_service->is_link_by_default(), |
| 132 | 132 | 'l10n' => array( |
| 133 | - 'You already published an entity with the same name' => __( 'You already published an entity with the same name: ', 'wordlift' ), |
|
| 134 | - 'logo_selection_title' => __( 'WordLift Choose Logo', 'wordlift' ), |
|
| 135 | - 'logo_selection_button' => array( 'text' => __( 'Choose Logo', 'wordlift' ) ), |
|
| 133 | + 'You already published an entity with the same name' => __('You already published an entity with the same name: ', 'wordlift'), |
|
| 134 | + 'logo_selection_title' => __('WordLift Choose Logo', 'wordlift'), |
|
| 135 | + 'logo_selection_button' => array('text' => __('Choose Logo', 'wordlift')), |
|
| 136 | 136 | ), |
| 137 | 137 | ); |
| 138 | 138 | |
| 139 | 139 | // Set post-related values if there's a current post. |
| 140 | - if ( null !== $post = $entity_being_edited = get_post() ) { |
|
| 140 | + if (null !== $post = $entity_being_edited = get_post()) { |
|
| 141 | 141 | |
| 142 | 142 | $params['post_id'] = $entity_being_edited->ID; |
| 143 | - $params['entityBeingEdited'] = isset( $entity_being_edited->post_type ) && Wordlift_Entity_Service::TYPE_NAME == $entity_being_edited->post_type && is_numeric( get_the_ID() ); |
|
| 143 | + $params['entityBeingEdited'] = isset($entity_being_edited->post_type) && Wordlift_Entity_Service::TYPE_NAME == $entity_being_edited->post_type && is_numeric(get_the_ID()); |
|
| 144 | 144 | // We add the `itemId` here to give a chance to the analysis to use it in order to tell WLS to exclude it |
| 145 | 145 | // from the results, since we don't want the current entity to be discovered by the analysis. |
| 146 | 146 | // |
| 147 | 147 | // See https://github.com/insideout10/wordlift-plugin/issues/345 |
| 148 | - $params['itemId'] = Wordlift_Entity_Service::get_instance()->get_uri( $entity_being_edited->ID ); |
|
| 148 | + $params['itemId'] = Wordlift_Entity_Service::get_instance()->get_uri($entity_being_edited->ID); |
|
| 149 | 149 | |
| 150 | 150 | } |
| 151 | 151 | |
| 152 | 152 | // Finally output the params as `wlSettings` for JavaScript code. |
| 153 | - wp_localize_script( $this->plugin_name, 'wlSettings', $params ); |
|
| 153 | + wp_localize_script($this->plugin_name, 'wlSettings', $params); |
|
| 154 | 154 | |
| 155 | 155 | } |
| 156 | 156 | |
@@ -18,49 +18,49 @@ discard block |
||
| 18 | 18 | */ |
| 19 | 19 | class Wordlift_Admin_Radio_Input_Element implements Wordlift_Admin_Element { |
| 20 | 20 | |
| 21 | - /** |
|
| 22 | - * Output the HTML for an input box type settings_page. |
|
| 23 | - * |
|
| 24 | - * @since 3.13.0 |
|
| 25 | - * |
|
| 26 | - * @param array $args { |
|
| 27 | - * An array of arguments. |
|
| 28 | - * |
|
| 29 | - * @type string $name The name attribute of the input element. Mandatory. |
|
| 30 | - * @type string $id The id attribute of the input element. Optional, |
|
| 31 | - * randomly generated one is used if not supplied. |
|
| 32 | - * @type string $value The value of the input element. Optional, defaults |
|
| 33 | - * to empty string. |
|
| 34 | - * @type string $css_class The class attribute for the input element. If empty |
|
| 35 | - * string no class attribute will be added. Optional, |
|
| 36 | - * defaults to empty string. |
|
| 37 | - * @type string $description The description text to be displayed below the element. |
|
| 38 | - * Can include some HTML element. If empty string no |
|
| 39 | - * description will be displayed. Optional, defaults to |
|
| 40 | - * empty string. |
|
| 41 | - * } |
|
| 42 | - * @return $this|Wordlift_Admin_Element |
|
| 43 | - */ |
|
| 44 | - public function render( $args ) { |
|
| 21 | + /** |
|
| 22 | + * Output the HTML for an input box type settings_page. |
|
| 23 | + * |
|
| 24 | + * @since 3.13.0 |
|
| 25 | + * |
|
| 26 | + * @param array $args { |
|
| 27 | + * An array of arguments. |
|
| 28 | + * |
|
| 29 | + * @type string $name The name attribute of the input element. Mandatory. |
|
| 30 | + * @type string $id The id attribute of the input element. Optional, |
|
| 31 | + * randomly generated one is used if not supplied. |
|
| 32 | + * @type string $value The value of the input element. Optional, defaults |
|
| 33 | + * to empty string. |
|
| 34 | + * @type string $css_class The class attribute for the input element. If empty |
|
| 35 | + * string no class attribute will be added. Optional, |
|
| 36 | + * defaults to empty string. |
|
| 37 | + * @type string $description The description text to be displayed below the element. |
|
| 38 | + * Can include some HTML element. If empty string no |
|
| 39 | + * description will be displayed. Optional, defaults to |
|
| 40 | + * empty string. |
|
| 41 | + * } |
|
| 42 | + * @return $this|Wordlift_Admin_Element |
|
| 43 | + */ |
|
| 44 | + public function render( $args ) { |
|
| 45 | 45 | |
| 46 | - /* |
|
| 46 | + /* |
|
| 47 | 47 | * Parse the arguments and merge with default values. |
| 48 | 48 | * Name intentionally do not have a default as it has to be in SyncEvent |
| 49 | 49 | * with form handling code |
| 50 | 50 | */ |
| 51 | - $params = wp_parse_args( $args, array( |
|
| 52 | - 'id' => uniqid( 'wl-input-' ), |
|
| 53 | - 'value' => '', |
|
| 54 | - 'css_class' => '', |
|
| 55 | - 'description' => '', |
|
| 56 | - ) ); |
|
| 51 | + $params = wp_parse_args( $args, array( |
|
| 52 | + 'id' => uniqid( 'wl-input-' ), |
|
| 53 | + 'value' => '', |
|
| 54 | + 'css_class' => '', |
|
| 55 | + 'description' => '', |
|
| 56 | + ) ); |
|
| 57 | 57 | |
| 58 | - // Set the readonly and class attributes and the description. |
|
| 59 | - $value = $params['value']; |
|
| 60 | - $css_class = ! empty( $params['css_class'] ) ? ' class="' . esc_attr( $params['css_class'] ) . '"' : ''; |
|
| 61 | - $description = ! empty( $params['description'] ) ? '<p>' . wp_kses( $params['description'], array( 'a' => array( 'href' => array() ) ) ) . '</p>' : ''; |
|
| 58 | + // Set the readonly and class attributes and the description. |
|
| 59 | + $value = $params['value']; |
|
| 60 | + $css_class = ! empty( $params['css_class'] ) ? ' class="' . esc_attr( $params['css_class'] ) . '"' : ''; |
|
| 61 | + $description = ! empty( $params['description'] ) ? '<p>' . wp_kses( $params['description'], array( 'a' => array( 'href' => array() ) ) ) . '</p>' : ''; |
|
| 62 | 62 | |
| 63 | - ?> |
|
| 63 | + ?> |
|
| 64 | 64 | |
| 65 | 65 | <input type="radio" id="<?php echo esc_attr( $params['id'] ); ?>" |
| 66 | 66 | name="<?php echo esc_attr( $params['name'] ); ?>" |
@@ -74,7 +74,7 @@ discard block |
||
| 74 | 74 | <?php echo $description; ?> |
| 75 | 75 | |
| 76 | 76 | <?php |
| 77 | - return $this; |
|
| 78 | - } |
|
| 77 | + return $this; |
|
| 78 | + } |
|
| 79 | 79 | |
| 80 | 80 | } |
@@ -41,35 +41,35 @@ |
||
| 41 | 41 | * } |
| 42 | 42 | * @return $this|Wordlift_Admin_Element |
| 43 | 43 | */ |
| 44 | - public function render( $args ) { |
|
| 44 | + public function render($args) { |
|
| 45 | 45 | |
| 46 | 46 | /* |
| 47 | 47 | * Parse the arguments and merge with default values. |
| 48 | 48 | * Name intentionally do not have a default as it has to be in SyncEvent |
| 49 | 49 | * with form handling code |
| 50 | 50 | */ |
| 51 | - $params = wp_parse_args( $args, array( |
|
| 52 | - 'id' => uniqid( 'wl-input-' ), |
|
| 51 | + $params = wp_parse_args($args, array( |
|
| 52 | + 'id' => uniqid('wl-input-'), |
|
| 53 | 53 | 'value' => '', |
| 54 | 54 | 'css_class' => '', |
| 55 | 55 | 'description' => '', |
| 56 | - ) ); |
|
| 56 | + )); |
|
| 57 | 57 | |
| 58 | 58 | // Set the readonly and class attributes and the description. |
| 59 | 59 | $value = $params['value']; |
| 60 | - $css_class = ! empty( $params['css_class'] ) ? ' class="' . esc_attr( $params['css_class'] ) . '"' : ''; |
|
| 61 | - $description = ! empty( $params['description'] ) ? '<p>' . wp_kses( $params['description'], array( 'a' => array( 'href' => array() ) ) ) . '</p>' : ''; |
|
| 60 | + $css_class = ! empty($params['css_class']) ? ' class="'.esc_attr($params['css_class']).'"' : ''; |
|
| 61 | + $description = ! empty($params['description']) ? '<p>'.wp_kses($params['description'], array('a' => array('href' => array()))).'</p>' : ''; |
|
| 62 | 62 | |
| 63 | 63 | ?> |
| 64 | 64 | |
| 65 | - <input type="radio" id="<?php echo esc_attr( $params['id'] ); ?>" |
|
| 66 | - name="<?php echo esc_attr( $params['name'] ); ?>" |
|
| 65 | + <input type="radio" id="<?php echo esc_attr($params['id']); ?>" |
|
| 66 | + name="<?php echo esc_attr($params['name']); ?>" |
|
| 67 | 67 | value="yes" <?php echo $css_class; ?> |
| 68 | - <?php checked( $value, 'yes' ); ?> /> Yes |
|
| 69 | - <input type="radio" id="<?php echo esc_attr( $params['id'] ); ?>" |
|
| 70 | - name="<?php echo esc_attr( $params['name'] ); ?>" |
|
| 68 | + <?php checked($value, 'yes'); ?> /> Yes |
|
| 69 | + <input type="radio" id="<?php echo esc_attr($params['id']); ?>" |
|
| 70 | + name="<?php echo esc_attr($params['name']); ?>" |
|
| 71 | 71 | value="no" <?php echo $css_class; ?> |
| 72 | - <?php checked( $value, 'no' ); ?>/> No |
|
| 72 | + <?php checked($value, 'no'); ?>/> No |
|
| 73 | 73 | |
| 74 | 74 | <?php echo $description; ?> |
| 75 | 75 | |
@@ -18,300 +18,300 @@ |
||
| 18 | 18 | */ |
| 19 | 19 | class Wordlift_Admin_Settings_Page extends Wordlift_Admin_Page { |
| 20 | 20 | |
| 21 | - /** |
|
| 22 | - * A {@link Wordlift_Entity_Service} instance. |
|
| 23 | - * |
|
| 24 | - * @since 3.11.0 |
|
| 25 | - * @access private |
|
| 26 | - * @var \Wordlift_Entity_Service $entity_service A {@link Wordlift_Entity_Service} instance. |
|
| 27 | - */ |
|
| 28 | - private $entity_service; |
|
| 29 | - |
|
| 30 | - /** |
|
| 31 | - * A {@link Wordlift_Configuration_Service} instance. |
|
| 32 | - * |
|
| 33 | - * @since 3.11.0 |
|
| 34 | - * @access private |
|
| 35 | - * @var \Wordlift_Configuration_Service $configuration_service A {@link Wordlift_Configuration_Service} instance. |
|
| 36 | - */ |
|
| 37 | - private $configuration_service; |
|
| 38 | - |
|
| 39 | - /** |
|
| 40 | - * A {@link Wordlift_Admin_Input_Element} element renderer. |
|
| 41 | - * |
|
| 42 | - * @since 3.11.0 |
|
| 43 | - * @access private |
|
| 44 | - * @var \Wordlift_Admin_Input_Element $input_element An {@link Wordlift_Admin_Input_Element} element renderer. |
|
| 45 | - */ |
|
| 46 | - private $input_element; |
|
| 47 | - |
|
| 48 | - /** |
|
| 49 | - * A {@link Wordlift_Admin_Radio_Input_Element} element renderer. |
|
| 50 | - * |
|
| 51 | - * @since 3.13.0 |
|
| 52 | - * @access protected |
|
| 53 | - * @var \Wordlift_Admin_Radio_Input_Element $radio_input_element A {@link Wordlift_Admin_Radio_Input_Element} element renderer. |
|
| 54 | - */ |
|
| 55 | - private $radio_input_element; |
|
| 56 | - |
|
| 57 | - /** |
|
| 58 | - * A {@link Wordlift_Admin_Language_Select_Element} element renderer. |
|
| 59 | - * |
|
| 60 | - * @since 3.11.0 |
|
| 61 | - * @access private |
|
| 62 | - * @var \Wordlift_Admin_Language_Select_Element $language_select_element A {@link Wordlift_Admin_Language_Select_Element} element renderer. |
|
| 63 | - */ |
|
| 64 | - private $language_select_element; |
|
| 65 | - |
|
| 66 | - /** |
|
| 67 | - * A {@link Wordlift_Admin_Publisher_Element} element renderer. |
|
| 68 | - * |
|
| 69 | - * @since 3.11.0 |
|
| 70 | - * @access private |
|
| 71 | - * @var \Wordlift_Admin_Publisher_Element $publisher_element A {@link Wordlift_Admin_Publisher_Element} element renderer. |
|
| 72 | - */ |
|
| 73 | - private $publisher_element; |
|
| 74 | - |
|
| 75 | - /** |
|
| 76 | - * Create a {@link Wordlift_Admin_Settings_Page} instance. |
|
| 77 | - * |
|
| 78 | - * @since 3.11.0 |
|
| 79 | - * |
|
| 80 | - * @param \Wordlift_Configuration_Service $configuration_service |
|
| 81 | - * @param \Wordlift_Entity_Service $entity_service |
|
| 82 | - * @param \Wordlift_Admin_Input_Element $input_element |
|
| 83 | - * @param \Wordlift_Admin_Language_Select_Element $language_select_element |
|
| 84 | - * @param \Wordlift_Admin_Publisher_Element $publisher_element |
|
| 85 | - * @param \Wordlift_Admin_Radio_Input_Element $radio_input_element |
|
| 86 | - */ |
|
| 87 | - function __construct( $configuration_service, $entity_service, $input_element, $language_select_element, $publisher_element, $radio_input_element ) { |
|
| 88 | - |
|
| 89 | - $this->configuration_service = $configuration_service; |
|
| 90 | - $this->entity_service = $entity_service; |
|
| 91 | - |
|
| 92 | - // Set a reference to the UI elements. |
|
| 93 | - $this->input_element = $input_element; |
|
| 94 | - $this->radio_input_element = $radio_input_element; |
|
| 95 | - $this->language_select_element = $language_select_element; |
|
| 96 | - $this->publisher_element = $publisher_element; |
|
| 97 | - |
|
| 98 | - } |
|
| 99 | - |
|
| 100 | - /** |
|
| 101 | - * @inheritdoc |
|
| 102 | - */ |
|
| 103 | - function get_parent_slug() { |
|
| 104 | - |
|
| 105 | - return 'wl_admin_menu'; |
|
| 106 | - } |
|
| 107 | - |
|
| 108 | - /** |
|
| 109 | - * @inheritdoc |
|
| 110 | - */ |
|
| 111 | - function get_capability() { |
|
| 112 | - |
|
| 113 | - return 'manage_options'; |
|
| 114 | - } |
|
| 115 | - |
|
| 116 | - /** |
|
| 117 | - * @inheritdoc |
|
| 118 | - */ |
|
| 119 | - function get_page_title() { |
|
| 120 | - |
|
| 121 | - return 'WorldLift Settings'; |
|
| 122 | - } |
|
| 123 | - |
|
| 124 | - /** |
|
| 125 | - * @inheritdoc |
|
| 126 | - */ |
|
| 127 | - function get_menu_title() { |
|
| 128 | - |
|
| 129 | - return 'Settings'; |
|
| 130 | - } |
|
| 131 | - |
|
| 132 | - /** |
|
| 133 | - * @inheritdoc |
|
| 134 | - */ |
|
| 135 | - function get_menu_slug() { |
|
| 136 | - |
|
| 137 | - return 'wl_configuration_admin_menu'; |
|
| 138 | - } |
|
| 139 | - |
|
| 140 | - /** |
|
| 141 | - * @inheritdoc |
|
| 142 | - */ |
|
| 143 | - function get_partial_name() { |
|
| 144 | - |
|
| 145 | - return 'wordlift-admin-settings-page.php'; |
|
| 146 | - } |
|
| 147 | - |
|
| 148 | - /** |
|
| 149 | - * @inheritdoc |
|
| 150 | - */ |
|
| 151 | - public function enqueue_scripts() { |
|
| 152 | - |
|
| 153 | - // Enqueue the media scripts to be used for the publisher's logo selection. |
|
| 154 | - wp_enqueue_media(); |
|
| 155 | - |
|
| 156 | - // JavaScript required for the settings page. |
|
| 157 | - // @todo: try to move to the `wordlift-admin.bundle.js`. |
|
| 158 | - wp_enqueue_script( 'wordlift-admin-settings-page', plugin_dir_url( dirname( __FILE__ ) ) . 'admin/js/wordlift-admin-settings-page.bundle.js', array( 'wp-util' ) ); |
|
| 159 | - |
|
| 160 | - } |
|
| 161 | - |
|
| 162 | - /** |
|
| 163 | - * Configure all the configuration parameters. |
|
| 164 | - * |
|
| 165 | - * Called by the *admin_init* hook. |
|
| 166 | - * |
|
| 167 | - * @since 3.11.0 |
|
| 168 | - */ |
|
| 169 | - function admin_init() { |
|
| 170 | - |
|
| 171 | - // Register WordLift's general settings, providing our own sanitize callback |
|
| 172 | - // which will also check whether the user filled the WL Publisher form. |
|
| 173 | - register_setting( |
|
| 174 | - 'wl_general_settings', |
|
| 175 | - 'wl_general_settings', |
|
| 176 | - array( $this, 'sanitize_callback', ) |
|
| 177 | - ); |
|
| 178 | - |
|
| 179 | - // Add the general settings section. |
|
| 180 | - add_settings_section( |
|
| 181 | - 'wl_general_settings_section', // ID used to identify this section and with which to register options. |
|
| 182 | - '', // Section header. |
|
| 183 | - '', // Callback used to render the description of the section. |
|
| 184 | - 'wl_general_settings' // Page on which to add this section of options. |
|
| 185 | - ); |
|
| 186 | - |
|
| 187 | - $key_args = array( |
|
| 188 | - 'id' => 'wl-key', |
|
| 189 | - 'name' => 'wl_general_settings[' . Wordlift_Configuration_Service::KEY . ']', |
|
| 190 | - 'value' => $this->configuration_service->get_key(), |
|
| 191 | - 'description' => _x( 'Insert the <a href="https://www.wordlift.io/blogger">WordLift Key</a> you received via email.', 'wordlift' ), |
|
| 192 | - ); |
|
| 193 | - |
|
| 194 | - // Set the class for the key field based on the validity of the key. |
|
| 195 | - // Class should be "untouched" for an empty (virgin) value, "valid" |
|
| 196 | - // if the key is valid, or "invalid" otherwise. |
|
| 197 | - $validation_service = new Wordlift_Key_Validation_Service(); |
|
| 198 | - |
|
| 199 | - if ( empty( $key_args['value'] ) ) { |
|
| 200 | - $key_args['css_class'] = 'untouched'; |
|
| 201 | - } elseif ( $validation_service->is_valid( $key_args['value'] ) ) { |
|
| 202 | - $key_args['css_class'] = 'valid'; |
|
| 203 | - } else { |
|
| 204 | - $key_args['css_class'] = 'invalid'; |
|
| 205 | - } |
|
| 206 | - |
|
| 207 | - // Add the `key` field. |
|
| 208 | - add_settings_field( |
|
| 209 | - 'wl-key', // Element id used to identify the field throughout the theme. |
|
| 210 | - _x( 'WordLift Key', 'wordlift' ), // The label to the left of the option interface element. |
|
| 211 | - // The name of the function responsible for rendering the option interface. |
|
| 212 | - array( $this->input_element, 'render', ), |
|
| 213 | - 'wl_general_settings', // The page on which this option will be displayed. |
|
| 214 | - 'wl_general_settings_section', // The name of the section to which this field belongs. |
|
| 215 | - $key_args // The array of arguments to pass to the callback. In this case, just a description. |
|
| 216 | - ); |
|
| 217 | - |
|
| 218 | - // Entity Base Path input. |
|
| 219 | - $entity_base_path_args = array( |
|
| 220 | - // The array of arguments to pass to the callback. In this case, just a description. |
|
| 221 | - 'id' => 'wl-entity-base-path', |
|
| 222 | - 'name' => 'wl_general_settings[' . Wordlift_Configuration_Service::ENTITY_BASE_PATH_KEY . ']', |
|
| 223 | - 'value' => $this->configuration_service->get_entity_base_path(), |
|
| 224 | - 'description' => sprintf( _x( 'All new pages created with WordLift, will be stored inside your internal vocabulary. You can customize the url pattern of these pages in the field above. Check our <a href="%s">FAQs</a> if you need more info.', 'wordlift' ), 'https://wordlift.io/wordlift-user-faqs/#10-why-and-how-should-i-customize-the-url-of-the-entity-pages-created-in-my-vocabulary' ), |
|
| 225 | - ); |
|
| 226 | - |
|
| 227 | - $entity_base_path_args['readonly'] = 0 < $this->entity_service->count(); |
|
| 228 | - |
|
| 229 | - // Add the `wl_entity_base_path` field. |
|
| 230 | - add_settings_field( |
|
| 231 | - 'wl-entity-base-path', // ID used to identify the field throughout the theme |
|
| 232 | - _x( 'Entity Base Path', 'wordlift' ), // The label to the left of the option interface element |
|
| 233 | - // The name of the function responsible for rendering the option interface |
|
| 234 | - array( $this->input_element, 'render', ), |
|
| 235 | - 'wl_general_settings', // The page on which this option will be displayed |
|
| 236 | - 'wl_general_settings_section', // The name of the section to which this field belongs |
|
| 237 | - $entity_base_path_args |
|
| 238 | - ); |
|
| 239 | - |
|
| 240 | - // Add the `language_name` field. |
|
| 241 | - add_settings_field( |
|
| 242 | - 'wl-site-language', |
|
| 243 | - _x( 'Site Language', 'wordlift' ), |
|
| 244 | - array( $this->language_select_element, 'render' ), |
|
| 245 | - 'wl_general_settings', |
|
| 246 | - 'wl_general_settings_section', |
|
| 247 | - array( |
|
| 248 | - // The array of arguments to pass to the callback. In this case, just a description. |
|
| 249 | - 'id' => 'wl-site-language', |
|
| 250 | - 'name' => 'wl_general_settings[' . Wordlift_Configuration_Service::LANGUAGE . ']', |
|
| 251 | - 'value' => $this->configuration_service->get_language_code(), |
|
| 252 | - 'description' => __( 'Each WordLift Key can be used only in one language. Pick yours.', 'wordlift' ), |
|
| 253 | - ) |
|
| 254 | - ); |
|
| 255 | - |
|
| 256 | - // Add the `publisher` field. |
|
| 257 | - add_settings_field( |
|
| 258 | - 'wl-publisher-id', |
|
| 259 | - _x( 'Publisher', 'wordlift' ), |
|
| 260 | - array( $this->publisher_element, 'render' ), |
|
| 261 | - 'wl_general_settings', |
|
| 262 | - 'wl_general_settings_section', |
|
| 263 | - array( |
|
| 264 | - 'id' => 'wl-publisher-id', |
|
| 265 | - 'name' => 'wl_general_settings[' . Wordlift_Configuration_Service::PUBLISHER_ID . ']', |
|
| 266 | - ) |
|
| 267 | - ); |
|
| 268 | - |
|
| 269 | - // Add the `link by default` field. |
|
| 270 | - add_settings_field( |
|
| 271 | - 'wl-link-by-default', |
|
| 272 | - _x( 'Link by Default', 'wordlift' ), |
|
| 273 | - array( $this->radio_input_element, 'render' ), |
|
| 274 | - 'wl_general_settings', |
|
| 275 | - 'wl_general_settings_section', |
|
| 276 | - array( |
|
| 277 | - 'id' => 'wl-link-by-default', |
|
| 278 | - 'name' => 'wl_general_settings[' . Wordlift_Configuration_Service::LINK_BY_DEFAULT . ']', |
|
| 279 | - 'value' => $this->configuration_service->is_link_by_default() ? 'yes' : 'no', |
|
| 280 | - 'description' => _x( 'Whether to link entities by default or not. This setting applies to all the entities.', 'wordlift' ), |
|
| 281 | - ) |
|
| 282 | - ); |
|
| 283 | - |
|
| 284 | - } |
|
| 285 | - |
|
| 286 | - /** |
|
| 287 | - * Sanitize the configuration settings to be stored. |
|
| 288 | - * |
|
| 289 | - * If a new entity is being created for the publisher, create it and set The |
|
| 290 | - * publisher setting. |
|
| 291 | - * |
|
| 292 | - * @since 3.11.0 |
|
| 293 | - * |
|
| 294 | - * @param array $input The configuration settings array. |
|
| 295 | - * |
|
| 296 | - * @return array The sanitized input array. |
|
| 297 | - */ |
|
| 298 | - function sanitize_callback( $input ) { |
|
| 299 | - |
|
| 300 | - // Check whether a publisher name has been set. |
|
| 301 | - if ( isset( $_POST['wl_publisher'] ) && ! empty( $_POST['wl_publisher']['name'] ) ) { |
|
| 302 | - $name = $_POST['wl_publisher']['name']; |
|
| 303 | - $type = $_POST['wl_publisher']['type']; |
|
| 304 | - $thumbnail_id = $_POST['wl_publisher']['thumbnail_id'] ?: null; |
|
| 305 | - |
|
| 306 | - // Set the type URI, either http://schema.org/Person or http://schema.org/Organization. |
|
| 307 | - $type_uri = sprintf( 'http://schema.org/%s', 'organization' === $type ? 'Organization' : 'Person' ); |
|
| 308 | - |
|
| 309 | - // Create an entity for the publisher and assign it to the input |
|
| 310 | - // parameter which WordPress automatically saves into the settings. |
|
| 311 | - $input['publisher_id'] = $this->entity_service->create( $name, $type_uri, $thumbnail_id, 'publish' ); |
|
| 312 | - } |
|
| 313 | - |
|
| 314 | - return $input; |
|
| 315 | - } |
|
| 21 | + /** |
|
| 22 | + * A {@link Wordlift_Entity_Service} instance. |
|
| 23 | + * |
|
| 24 | + * @since 3.11.0 |
|
| 25 | + * @access private |
|
| 26 | + * @var \Wordlift_Entity_Service $entity_service A {@link Wordlift_Entity_Service} instance. |
|
| 27 | + */ |
|
| 28 | + private $entity_service; |
|
| 29 | + |
|
| 30 | + /** |
|
| 31 | + * A {@link Wordlift_Configuration_Service} instance. |
|
| 32 | + * |
|
| 33 | + * @since 3.11.0 |
|
| 34 | + * @access private |
|
| 35 | + * @var \Wordlift_Configuration_Service $configuration_service A {@link Wordlift_Configuration_Service} instance. |
|
| 36 | + */ |
|
| 37 | + private $configuration_service; |
|
| 38 | + |
|
| 39 | + /** |
|
| 40 | + * A {@link Wordlift_Admin_Input_Element} element renderer. |
|
| 41 | + * |
|
| 42 | + * @since 3.11.0 |
|
| 43 | + * @access private |
|
| 44 | + * @var \Wordlift_Admin_Input_Element $input_element An {@link Wordlift_Admin_Input_Element} element renderer. |
|
| 45 | + */ |
|
| 46 | + private $input_element; |
|
| 47 | + |
|
| 48 | + /** |
|
| 49 | + * A {@link Wordlift_Admin_Radio_Input_Element} element renderer. |
|
| 50 | + * |
|
| 51 | + * @since 3.13.0 |
|
| 52 | + * @access protected |
|
| 53 | + * @var \Wordlift_Admin_Radio_Input_Element $radio_input_element A {@link Wordlift_Admin_Radio_Input_Element} element renderer. |
|
| 54 | + */ |
|
| 55 | + private $radio_input_element; |
|
| 56 | + |
|
| 57 | + /** |
|
| 58 | + * A {@link Wordlift_Admin_Language_Select_Element} element renderer. |
|
| 59 | + * |
|
| 60 | + * @since 3.11.0 |
|
| 61 | + * @access private |
|
| 62 | + * @var \Wordlift_Admin_Language_Select_Element $language_select_element A {@link Wordlift_Admin_Language_Select_Element} element renderer. |
|
| 63 | + */ |
|
| 64 | + private $language_select_element; |
|
| 65 | + |
|
| 66 | + /** |
|
| 67 | + * A {@link Wordlift_Admin_Publisher_Element} element renderer. |
|
| 68 | + * |
|
| 69 | + * @since 3.11.0 |
|
| 70 | + * @access private |
|
| 71 | + * @var \Wordlift_Admin_Publisher_Element $publisher_element A {@link Wordlift_Admin_Publisher_Element} element renderer. |
|
| 72 | + */ |
|
| 73 | + private $publisher_element; |
|
| 74 | + |
|
| 75 | + /** |
|
| 76 | + * Create a {@link Wordlift_Admin_Settings_Page} instance. |
|
| 77 | + * |
|
| 78 | + * @since 3.11.0 |
|
| 79 | + * |
|
| 80 | + * @param \Wordlift_Configuration_Service $configuration_service |
|
| 81 | + * @param \Wordlift_Entity_Service $entity_service |
|
| 82 | + * @param \Wordlift_Admin_Input_Element $input_element |
|
| 83 | + * @param \Wordlift_Admin_Language_Select_Element $language_select_element |
|
| 84 | + * @param \Wordlift_Admin_Publisher_Element $publisher_element |
|
| 85 | + * @param \Wordlift_Admin_Radio_Input_Element $radio_input_element |
|
| 86 | + */ |
|
| 87 | + function __construct( $configuration_service, $entity_service, $input_element, $language_select_element, $publisher_element, $radio_input_element ) { |
|
| 88 | + |
|
| 89 | + $this->configuration_service = $configuration_service; |
|
| 90 | + $this->entity_service = $entity_service; |
|
| 91 | + |
|
| 92 | + // Set a reference to the UI elements. |
|
| 93 | + $this->input_element = $input_element; |
|
| 94 | + $this->radio_input_element = $radio_input_element; |
|
| 95 | + $this->language_select_element = $language_select_element; |
|
| 96 | + $this->publisher_element = $publisher_element; |
|
| 97 | + |
|
| 98 | + } |
|
| 99 | + |
|
| 100 | + /** |
|
| 101 | + * @inheritdoc |
|
| 102 | + */ |
|
| 103 | + function get_parent_slug() { |
|
| 104 | + |
|
| 105 | + return 'wl_admin_menu'; |
|
| 106 | + } |
|
| 107 | + |
|
| 108 | + /** |
|
| 109 | + * @inheritdoc |
|
| 110 | + */ |
|
| 111 | + function get_capability() { |
|
| 112 | + |
|
| 113 | + return 'manage_options'; |
|
| 114 | + } |
|
| 115 | + |
|
| 116 | + /** |
|
| 117 | + * @inheritdoc |
|
| 118 | + */ |
|
| 119 | + function get_page_title() { |
|
| 120 | + |
|
| 121 | + return 'WorldLift Settings'; |
|
| 122 | + } |
|
| 123 | + |
|
| 124 | + /** |
|
| 125 | + * @inheritdoc |
|
| 126 | + */ |
|
| 127 | + function get_menu_title() { |
|
| 128 | + |
|
| 129 | + return 'Settings'; |
|
| 130 | + } |
|
| 131 | + |
|
| 132 | + /** |
|
| 133 | + * @inheritdoc |
|
| 134 | + */ |
|
| 135 | + function get_menu_slug() { |
|
| 136 | + |
|
| 137 | + return 'wl_configuration_admin_menu'; |
|
| 138 | + } |
|
| 139 | + |
|
| 140 | + /** |
|
| 141 | + * @inheritdoc |
|
| 142 | + */ |
|
| 143 | + function get_partial_name() { |
|
| 144 | + |
|
| 145 | + return 'wordlift-admin-settings-page.php'; |
|
| 146 | + } |
|
| 147 | + |
|
| 148 | + /** |
|
| 149 | + * @inheritdoc |
|
| 150 | + */ |
|
| 151 | + public function enqueue_scripts() { |
|
| 152 | + |
|
| 153 | + // Enqueue the media scripts to be used for the publisher's logo selection. |
|
| 154 | + wp_enqueue_media(); |
|
| 155 | + |
|
| 156 | + // JavaScript required for the settings page. |
|
| 157 | + // @todo: try to move to the `wordlift-admin.bundle.js`. |
|
| 158 | + wp_enqueue_script( 'wordlift-admin-settings-page', plugin_dir_url( dirname( __FILE__ ) ) . 'admin/js/wordlift-admin-settings-page.bundle.js', array( 'wp-util' ) ); |
|
| 159 | + |
|
| 160 | + } |
|
| 161 | + |
|
| 162 | + /** |
|
| 163 | + * Configure all the configuration parameters. |
|
| 164 | + * |
|
| 165 | + * Called by the *admin_init* hook. |
|
| 166 | + * |
|
| 167 | + * @since 3.11.0 |
|
| 168 | + */ |
|
| 169 | + function admin_init() { |
|
| 170 | + |
|
| 171 | + // Register WordLift's general settings, providing our own sanitize callback |
|
| 172 | + // which will also check whether the user filled the WL Publisher form. |
|
| 173 | + register_setting( |
|
| 174 | + 'wl_general_settings', |
|
| 175 | + 'wl_general_settings', |
|
| 176 | + array( $this, 'sanitize_callback', ) |
|
| 177 | + ); |
|
| 178 | + |
|
| 179 | + // Add the general settings section. |
|
| 180 | + add_settings_section( |
|
| 181 | + 'wl_general_settings_section', // ID used to identify this section and with which to register options. |
|
| 182 | + '', // Section header. |
|
| 183 | + '', // Callback used to render the description of the section. |
|
| 184 | + 'wl_general_settings' // Page on which to add this section of options. |
|
| 185 | + ); |
|
| 186 | + |
|
| 187 | + $key_args = array( |
|
| 188 | + 'id' => 'wl-key', |
|
| 189 | + 'name' => 'wl_general_settings[' . Wordlift_Configuration_Service::KEY . ']', |
|
| 190 | + 'value' => $this->configuration_service->get_key(), |
|
| 191 | + 'description' => _x( 'Insert the <a href="https://www.wordlift.io/blogger">WordLift Key</a> you received via email.', 'wordlift' ), |
|
| 192 | + ); |
|
| 193 | + |
|
| 194 | + // Set the class for the key field based on the validity of the key. |
|
| 195 | + // Class should be "untouched" for an empty (virgin) value, "valid" |
|
| 196 | + // if the key is valid, or "invalid" otherwise. |
|
| 197 | + $validation_service = new Wordlift_Key_Validation_Service(); |
|
| 198 | + |
|
| 199 | + if ( empty( $key_args['value'] ) ) { |
|
| 200 | + $key_args['css_class'] = 'untouched'; |
|
| 201 | + } elseif ( $validation_service->is_valid( $key_args['value'] ) ) { |
|
| 202 | + $key_args['css_class'] = 'valid'; |
|
| 203 | + } else { |
|
| 204 | + $key_args['css_class'] = 'invalid'; |
|
| 205 | + } |
|
| 206 | + |
|
| 207 | + // Add the `key` field. |
|
| 208 | + add_settings_field( |
|
| 209 | + 'wl-key', // Element id used to identify the field throughout the theme. |
|
| 210 | + _x( 'WordLift Key', 'wordlift' ), // The label to the left of the option interface element. |
|
| 211 | + // The name of the function responsible for rendering the option interface. |
|
| 212 | + array( $this->input_element, 'render', ), |
|
| 213 | + 'wl_general_settings', // The page on which this option will be displayed. |
|
| 214 | + 'wl_general_settings_section', // The name of the section to which this field belongs. |
|
| 215 | + $key_args // The array of arguments to pass to the callback. In this case, just a description. |
|
| 216 | + ); |
|
| 217 | + |
|
| 218 | + // Entity Base Path input. |
|
| 219 | + $entity_base_path_args = array( |
|
| 220 | + // The array of arguments to pass to the callback. In this case, just a description. |
|
| 221 | + 'id' => 'wl-entity-base-path', |
|
| 222 | + 'name' => 'wl_general_settings[' . Wordlift_Configuration_Service::ENTITY_BASE_PATH_KEY . ']', |
|
| 223 | + 'value' => $this->configuration_service->get_entity_base_path(), |
|
| 224 | + 'description' => sprintf( _x( 'All new pages created with WordLift, will be stored inside your internal vocabulary. You can customize the url pattern of these pages in the field above. Check our <a href="%s">FAQs</a> if you need more info.', 'wordlift' ), 'https://wordlift.io/wordlift-user-faqs/#10-why-and-how-should-i-customize-the-url-of-the-entity-pages-created-in-my-vocabulary' ), |
|
| 225 | + ); |
|
| 226 | + |
|
| 227 | + $entity_base_path_args['readonly'] = 0 < $this->entity_service->count(); |
|
| 228 | + |
|
| 229 | + // Add the `wl_entity_base_path` field. |
|
| 230 | + add_settings_field( |
|
| 231 | + 'wl-entity-base-path', // ID used to identify the field throughout the theme |
|
| 232 | + _x( 'Entity Base Path', 'wordlift' ), // The label to the left of the option interface element |
|
| 233 | + // The name of the function responsible for rendering the option interface |
|
| 234 | + array( $this->input_element, 'render', ), |
|
| 235 | + 'wl_general_settings', // The page on which this option will be displayed |
|
| 236 | + 'wl_general_settings_section', // The name of the section to which this field belongs |
|
| 237 | + $entity_base_path_args |
|
| 238 | + ); |
|
| 239 | + |
|
| 240 | + // Add the `language_name` field. |
|
| 241 | + add_settings_field( |
|
| 242 | + 'wl-site-language', |
|
| 243 | + _x( 'Site Language', 'wordlift' ), |
|
| 244 | + array( $this->language_select_element, 'render' ), |
|
| 245 | + 'wl_general_settings', |
|
| 246 | + 'wl_general_settings_section', |
|
| 247 | + array( |
|
| 248 | + // The array of arguments to pass to the callback. In this case, just a description. |
|
| 249 | + 'id' => 'wl-site-language', |
|
| 250 | + 'name' => 'wl_general_settings[' . Wordlift_Configuration_Service::LANGUAGE . ']', |
|
| 251 | + 'value' => $this->configuration_service->get_language_code(), |
|
| 252 | + 'description' => __( 'Each WordLift Key can be used only in one language. Pick yours.', 'wordlift' ), |
|
| 253 | + ) |
|
| 254 | + ); |
|
| 255 | + |
|
| 256 | + // Add the `publisher` field. |
|
| 257 | + add_settings_field( |
|
| 258 | + 'wl-publisher-id', |
|
| 259 | + _x( 'Publisher', 'wordlift' ), |
|
| 260 | + array( $this->publisher_element, 'render' ), |
|
| 261 | + 'wl_general_settings', |
|
| 262 | + 'wl_general_settings_section', |
|
| 263 | + array( |
|
| 264 | + 'id' => 'wl-publisher-id', |
|
| 265 | + 'name' => 'wl_general_settings[' . Wordlift_Configuration_Service::PUBLISHER_ID . ']', |
|
| 266 | + ) |
|
| 267 | + ); |
|
| 268 | + |
|
| 269 | + // Add the `link by default` field. |
|
| 270 | + add_settings_field( |
|
| 271 | + 'wl-link-by-default', |
|
| 272 | + _x( 'Link by Default', 'wordlift' ), |
|
| 273 | + array( $this->radio_input_element, 'render' ), |
|
| 274 | + 'wl_general_settings', |
|
| 275 | + 'wl_general_settings_section', |
|
| 276 | + array( |
|
| 277 | + 'id' => 'wl-link-by-default', |
|
| 278 | + 'name' => 'wl_general_settings[' . Wordlift_Configuration_Service::LINK_BY_DEFAULT . ']', |
|
| 279 | + 'value' => $this->configuration_service->is_link_by_default() ? 'yes' : 'no', |
|
| 280 | + 'description' => _x( 'Whether to link entities by default or not. This setting applies to all the entities.', 'wordlift' ), |
|
| 281 | + ) |
|
| 282 | + ); |
|
| 283 | + |
|
| 284 | + } |
|
| 285 | + |
|
| 286 | + /** |
|
| 287 | + * Sanitize the configuration settings to be stored. |
|
| 288 | + * |
|
| 289 | + * If a new entity is being created for the publisher, create it and set The |
|
| 290 | + * publisher setting. |
|
| 291 | + * |
|
| 292 | + * @since 3.11.0 |
|
| 293 | + * |
|
| 294 | + * @param array $input The configuration settings array. |
|
| 295 | + * |
|
| 296 | + * @return array The sanitized input array. |
|
| 297 | + */ |
|
| 298 | + function sanitize_callback( $input ) { |
|
| 299 | + |
|
| 300 | + // Check whether a publisher name has been set. |
|
| 301 | + if ( isset( $_POST['wl_publisher'] ) && ! empty( $_POST['wl_publisher']['name'] ) ) { |
|
| 302 | + $name = $_POST['wl_publisher']['name']; |
|
| 303 | + $type = $_POST['wl_publisher']['type']; |
|
| 304 | + $thumbnail_id = $_POST['wl_publisher']['thumbnail_id'] ?: null; |
|
| 305 | + |
|
| 306 | + // Set the type URI, either http://schema.org/Person or http://schema.org/Organization. |
|
| 307 | + $type_uri = sprintf( 'http://schema.org/%s', 'organization' === $type ? 'Organization' : 'Person' ); |
|
| 308 | + |
|
| 309 | + // Create an entity for the publisher and assign it to the input |
|
| 310 | + // parameter which WordPress automatically saves into the settings. |
|
| 311 | + $input['publisher_id'] = $this->entity_service->create( $name, $type_uri, $thumbnail_id, 'publish' ); |
|
| 312 | + } |
|
| 313 | + |
|
| 314 | + return $input; |
|
| 315 | + } |
|
| 316 | 316 | |
| 317 | 317 | } |
@@ -84,7 +84,7 @@ discard block |
||
| 84 | 84 | * @param \Wordlift_Admin_Publisher_Element $publisher_element |
| 85 | 85 | * @param \Wordlift_Admin_Radio_Input_Element $radio_input_element |
| 86 | 86 | */ |
| 87 | - function __construct( $configuration_service, $entity_service, $input_element, $language_select_element, $publisher_element, $radio_input_element ) { |
|
| 87 | + function __construct($configuration_service, $entity_service, $input_element, $language_select_element, $publisher_element, $radio_input_element) { |
|
| 88 | 88 | |
| 89 | 89 | $this->configuration_service = $configuration_service; |
| 90 | 90 | $this->entity_service = $entity_service; |
@@ -155,7 +155,7 @@ discard block |
||
| 155 | 155 | |
| 156 | 156 | // JavaScript required for the settings page. |
| 157 | 157 | // @todo: try to move to the `wordlift-admin.bundle.js`. |
| 158 | - wp_enqueue_script( 'wordlift-admin-settings-page', plugin_dir_url( dirname( __FILE__ ) ) . 'admin/js/wordlift-admin-settings-page.bundle.js', array( 'wp-util' ) ); |
|
| 158 | + wp_enqueue_script('wordlift-admin-settings-page', plugin_dir_url(dirname(__FILE__)).'admin/js/wordlift-admin-settings-page.bundle.js', array('wp-util')); |
|
| 159 | 159 | |
| 160 | 160 | } |
| 161 | 161 | |
@@ -173,22 +173,22 @@ discard block |
||
| 173 | 173 | register_setting( |
| 174 | 174 | 'wl_general_settings', |
| 175 | 175 | 'wl_general_settings', |
| 176 | - array( $this, 'sanitize_callback', ) |
|
| 176 | + array($this, 'sanitize_callback',) |
|
| 177 | 177 | ); |
| 178 | 178 | |
| 179 | 179 | // Add the general settings section. |
| 180 | 180 | add_settings_section( |
| 181 | 181 | 'wl_general_settings_section', // ID used to identify this section and with which to register options. |
| 182 | - '', // Section header. |
|
| 183 | - '', // Callback used to render the description of the section. |
|
| 182 | + '', // Section header. |
|
| 183 | + '', // Callback used to render the description of the section. |
|
| 184 | 184 | 'wl_general_settings' // Page on which to add this section of options. |
| 185 | 185 | ); |
| 186 | 186 | |
| 187 | 187 | $key_args = array( |
| 188 | 188 | 'id' => 'wl-key', |
| 189 | - 'name' => 'wl_general_settings[' . Wordlift_Configuration_Service::KEY . ']', |
|
| 189 | + 'name' => 'wl_general_settings['.Wordlift_Configuration_Service::KEY.']', |
|
| 190 | 190 | 'value' => $this->configuration_service->get_key(), |
| 191 | - 'description' => _x( 'Insert the <a href="https://www.wordlift.io/blogger">WordLift Key</a> you received via email.', 'wordlift' ), |
|
| 191 | + 'description' => _x('Insert the <a href="https://www.wordlift.io/blogger">WordLift Key</a> you received via email.', 'wordlift'), |
|
| 192 | 192 | ); |
| 193 | 193 | |
| 194 | 194 | // Set the class for the key field based on the validity of the key. |
@@ -196,9 +196,9 @@ discard block |
||
| 196 | 196 | // if the key is valid, or "invalid" otherwise. |
| 197 | 197 | $validation_service = new Wordlift_Key_Validation_Service(); |
| 198 | 198 | |
| 199 | - if ( empty( $key_args['value'] ) ) { |
|
| 199 | + if (empty($key_args['value'])) { |
|
| 200 | 200 | $key_args['css_class'] = 'untouched'; |
| 201 | - } elseif ( $validation_service->is_valid( $key_args['value'] ) ) { |
|
| 201 | + } elseif ($validation_service->is_valid($key_args['value'])) { |
|
| 202 | 202 | $key_args['css_class'] = 'valid'; |
| 203 | 203 | } else { |
| 204 | 204 | $key_args['css_class'] = 'invalid'; |
@@ -206,12 +206,12 @@ discard block |
||
| 206 | 206 | |
| 207 | 207 | // Add the `key` field. |
| 208 | 208 | add_settings_field( |
| 209 | - 'wl-key', // Element id used to identify the field throughout the theme. |
|
| 210 | - _x( 'WordLift Key', 'wordlift' ), // The label to the left of the option interface element. |
|
| 209 | + 'wl-key', // Element id used to identify the field throughout the theme. |
|
| 210 | + _x('WordLift Key', 'wordlift'), // The label to the left of the option interface element. |
|
| 211 | 211 | // The name of the function responsible for rendering the option interface. |
| 212 | - array( $this->input_element, 'render', ), |
|
| 213 | - 'wl_general_settings', // The page on which this option will be displayed. |
|
| 214 | - 'wl_general_settings_section', // The name of the section to which this field belongs. |
|
| 212 | + array($this->input_element, 'render',), |
|
| 213 | + 'wl_general_settings', // The page on which this option will be displayed. |
|
| 214 | + 'wl_general_settings_section', // The name of the section to which this field belongs. |
|
| 215 | 215 | $key_args // The array of arguments to pass to the callback. In this case, just a description. |
| 216 | 216 | ); |
| 217 | 217 | |
@@ -219,65 +219,65 @@ discard block |
||
| 219 | 219 | $entity_base_path_args = array( |
| 220 | 220 | // The array of arguments to pass to the callback. In this case, just a description. |
| 221 | 221 | 'id' => 'wl-entity-base-path', |
| 222 | - 'name' => 'wl_general_settings[' . Wordlift_Configuration_Service::ENTITY_BASE_PATH_KEY . ']', |
|
| 222 | + 'name' => 'wl_general_settings['.Wordlift_Configuration_Service::ENTITY_BASE_PATH_KEY.']', |
|
| 223 | 223 | 'value' => $this->configuration_service->get_entity_base_path(), |
| 224 | - 'description' => sprintf( _x( 'All new pages created with WordLift, will be stored inside your internal vocabulary. You can customize the url pattern of these pages in the field above. Check our <a href="%s">FAQs</a> if you need more info.', 'wordlift' ), 'https://wordlift.io/wordlift-user-faqs/#10-why-and-how-should-i-customize-the-url-of-the-entity-pages-created-in-my-vocabulary' ), |
|
| 224 | + 'description' => sprintf(_x('All new pages created with WordLift, will be stored inside your internal vocabulary. You can customize the url pattern of these pages in the field above. Check our <a href="%s">FAQs</a> if you need more info.', 'wordlift'), 'https://wordlift.io/wordlift-user-faqs/#10-why-and-how-should-i-customize-the-url-of-the-entity-pages-created-in-my-vocabulary'), |
|
| 225 | 225 | ); |
| 226 | 226 | |
| 227 | 227 | $entity_base_path_args['readonly'] = 0 < $this->entity_service->count(); |
| 228 | 228 | |
| 229 | 229 | // Add the `wl_entity_base_path` field. |
| 230 | 230 | add_settings_field( |
| 231 | - 'wl-entity-base-path', // ID used to identify the field throughout the theme |
|
| 232 | - _x( 'Entity Base Path', 'wordlift' ), // The label to the left of the option interface element |
|
| 231 | + 'wl-entity-base-path', // ID used to identify the field throughout the theme |
|
| 232 | + _x('Entity Base Path', 'wordlift'), // The label to the left of the option interface element |
|
| 233 | 233 | // The name of the function responsible for rendering the option interface |
| 234 | - array( $this->input_element, 'render', ), |
|
| 235 | - 'wl_general_settings', // The page on which this option will be displayed |
|
| 236 | - 'wl_general_settings_section', // The name of the section to which this field belongs |
|
| 234 | + array($this->input_element, 'render',), |
|
| 235 | + 'wl_general_settings', // The page on which this option will be displayed |
|
| 236 | + 'wl_general_settings_section', // The name of the section to which this field belongs |
|
| 237 | 237 | $entity_base_path_args |
| 238 | 238 | ); |
| 239 | 239 | |
| 240 | 240 | // Add the `language_name` field. |
| 241 | 241 | add_settings_field( |
| 242 | 242 | 'wl-site-language', |
| 243 | - _x( 'Site Language', 'wordlift' ), |
|
| 244 | - array( $this->language_select_element, 'render' ), |
|
| 243 | + _x('Site Language', 'wordlift'), |
|
| 244 | + array($this->language_select_element, 'render'), |
|
| 245 | 245 | 'wl_general_settings', |
| 246 | 246 | 'wl_general_settings_section', |
| 247 | 247 | array( |
| 248 | 248 | // The array of arguments to pass to the callback. In this case, just a description. |
| 249 | 249 | 'id' => 'wl-site-language', |
| 250 | - 'name' => 'wl_general_settings[' . Wordlift_Configuration_Service::LANGUAGE . ']', |
|
| 250 | + 'name' => 'wl_general_settings['.Wordlift_Configuration_Service::LANGUAGE.']', |
|
| 251 | 251 | 'value' => $this->configuration_service->get_language_code(), |
| 252 | - 'description' => __( 'Each WordLift Key can be used only in one language. Pick yours.', 'wordlift' ), |
|
| 252 | + 'description' => __('Each WordLift Key can be used only in one language. Pick yours.', 'wordlift'), |
|
| 253 | 253 | ) |
| 254 | 254 | ); |
| 255 | 255 | |
| 256 | 256 | // Add the `publisher` field. |
| 257 | 257 | add_settings_field( |
| 258 | 258 | 'wl-publisher-id', |
| 259 | - _x( 'Publisher', 'wordlift' ), |
|
| 260 | - array( $this->publisher_element, 'render' ), |
|
| 259 | + _x('Publisher', 'wordlift'), |
|
| 260 | + array($this->publisher_element, 'render'), |
|
| 261 | 261 | 'wl_general_settings', |
| 262 | 262 | 'wl_general_settings_section', |
| 263 | 263 | array( |
| 264 | 264 | 'id' => 'wl-publisher-id', |
| 265 | - 'name' => 'wl_general_settings[' . Wordlift_Configuration_Service::PUBLISHER_ID . ']', |
|
| 265 | + 'name' => 'wl_general_settings['.Wordlift_Configuration_Service::PUBLISHER_ID.']', |
|
| 266 | 266 | ) |
| 267 | 267 | ); |
| 268 | 268 | |
| 269 | 269 | // Add the `link by default` field. |
| 270 | 270 | add_settings_field( |
| 271 | 271 | 'wl-link-by-default', |
| 272 | - _x( 'Link by Default', 'wordlift' ), |
|
| 273 | - array( $this->radio_input_element, 'render' ), |
|
| 272 | + _x('Link by Default', 'wordlift'), |
|
| 273 | + array($this->radio_input_element, 'render'), |
|
| 274 | 274 | 'wl_general_settings', |
| 275 | 275 | 'wl_general_settings_section', |
| 276 | 276 | array( |
| 277 | 277 | 'id' => 'wl-link-by-default', |
| 278 | - 'name' => 'wl_general_settings[' . Wordlift_Configuration_Service::LINK_BY_DEFAULT . ']', |
|
| 278 | + 'name' => 'wl_general_settings['.Wordlift_Configuration_Service::LINK_BY_DEFAULT.']', |
|
| 279 | 279 | 'value' => $this->configuration_service->is_link_by_default() ? 'yes' : 'no', |
| 280 | - 'description' => _x( 'Whether to link entities by default or not. This setting applies to all the entities.', 'wordlift' ), |
|
| 280 | + 'description' => _x('Whether to link entities by default or not. This setting applies to all the entities.', 'wordlift'), |
|
| 281 | 281 | ) |
| 282 | 282 | ); |
| 283 | 283 | |
@@ -295,20 +295,20 @@ discard block |
||
| 295 | 295 | * |
| 296 | 296 | * @return array The sanitized input array. |
| 297 | 297 | */ |
| 298 | - function sanitize_callback( $input ) { |
|
| 298 | + function sanitize_callback($input) { |
|
| 299 | 299 | |
| 300 | 300 | // Check whether a publisher name has been set. |
| 301 | - if ( isset( $_POST['wl_publisher'] ) && ! empty( $_POST['wl_publisher']['name'] ) ) { |
|
| 301 | + if (isset($_POST['wl_publisher']) && ! empty($_POST['wl_publisher']['name'])) { |
|
| 302 | 302 | $name = $_POST['wl_publisher']['name']; |
| 303 | 303 | $type = $_POST['wl_publisher']['type']; |
| 304 | 304 | $thumbnail_id = $_POST['wl_publisher']['thumbnail_id'] ?: null; |
| 305 | 305 | |
| 306 | 306 | // Set the type URI, either http://schema.org/Person or http://schema.org/Organization. |
| 307 | - $type_uri = sprintf( 'http://schema.org/%s', 'organization' === $type ? 'Organization' : 'Person' ); |
|
| 307 | + $type_uri = sprintf('http://schema.org/%s', 'organization' === $type ? 'Organization' : 'Person'); |
|
| 308 | 308 | |
| 309 | 309 | // Create an entity for the publisher and assign it to the input |
| 310 | 310 | // parameter which WordPress automatically saves into the settings. |
| 311 | - $input['publisher_id'] = $this->entity_service->create( $name, $type_uri, $thumbnail_id, 'publish' ); |
|
| 311 | + $input['publisher_id'] = $this->entity_service->create($name, $type_uri, $thumbnail_id, 'publish'); |
|
| 312 | 312 | } |
| 313 | 313 | |
| 314 | 314 | return $input; |
@@ -18,52 +18,52 @@ discard block |
||
| 18 | 18 | */ |
| 19 | 19 | class Wordlift_Admin_Input_Element implements Wordlift_Admin_Element { |
| 20 | 20 | |
| 21 | - /** |
|
| 22 | - * Output the HTML for an input box type settings_page |
|
| 23 | - * |
|
| 24 | - * @param array $args An array with the following keys: |
|
| 25 | - * Parameters controlling the result. |
|
| 26 | - * |
|
| 27 | - * @type string name The name attribute of the input element. Mandatory. |
|
| 28 | - * |
|
| 29 | - * @type string id The id attribute of the input element. Optional. |
|
| 30 | - * @type string id The id attribute of the input element. |
|
| 31 | - * Optional, randomly generated one is used if not supplied. |
|
| 32 | - * @type string value The value of the input element. |
|
| 33 | - * Optional, defaults to empty string. |
|
| 34 | - * @type bool readonly Indicates whether the input is read only. |
|
| 35 | - * Optional, defaults to read-write |
|
| 36 | - * @type string css_class The class attribute for the input element. |
|
| 37 | - * If empty string no class attribute will be added. |
|
| 38 | - * Optional, defaults to empty string. |
|
| 39 | - * @type string description The descriptio text to be displayed below the element. |
|
| 40 | - * Can include some HTML element. |
|
| 41 | - * If empty string no description will be displayed. |
|
| 42 | - * Optional, defaults to empty string. |
|
| 43 | - * |
|
| 44 | - * @return $this|Wordlift_Admin_Element |
|
| 45 | - */ |
|
| 46 | - public function render( $args ) { |
|
| 21 | + /** |
|
| 22 | + * Output the HTML for an input box type settings_page |
|
| 23 | + * |
|
| 24 | + * @param array $args An array with the following keys: |
|
| 25 | + * Parameters controlling the result. |
|
| 26 | + * |
|
| 27 | + * @type string name The name attribute of the input element. Mandatory. |
|
| 28 | + * |
|
| 29 | + * @type string id The id attribute of the input element. Optional. |
|
| 30 | + * @type string id The id attribute of the input element. |
|
| 31 | + * Optional, randomly generated one is used if not supplied. |
|
| 32 | + * @type string value The value of the input element. |
|
| 33 | + * Optional, defaults to empty string. |
|
| 34 | + * @type bool readonly Indicates whether the input is read only. |
|
| 35 | + * Optional, defaults to read-write |
|
| 36 | + * @type string css_class The class attribute for the input element. |
|
| 37 | + * If empty string no class attribute will be added. |
|
| 38 | + * Optional, defaults to empty string. |
|
| 39 | + * @type string description The descriptio text to be displayed below the element. |
|
| 40 | + * Can include some HTML element. |
|
| 41 | + * If empty string no description will be displayed. |
|
| 42 | + * Optional, defaults to empty string. |
|
| 43 | + * |
|
| 44 | + * @return $this|Wordlift_Admin_Element |
|
| 45 | + */ |
|
| 46 | + public function render( $args ) { |
|
| 47 | 47 | |
| 48 | - /* |
|
| 48 | + /* |
|
| 49 | 49 | * Parse the arguments and merge with default values. |
| 50 | 50 | * Name intentionally do not have a default as it has to be in SyncEvent |
| 51 | 51 | * with form handling code |
| 52 | 52 | */ |
| 53 | - $params = wp_parse_args( $args, array( |
|
| 54 | - 'id' => uniqid( 'wl-input-' ), |
|
| 55 | - 'value' => '', |
|
| 56 | - 'readonly' => false, |
|
| 57 | - 'css_class' => '', |
|
| 58 | - 'description' => '', |
|
| 59 | - ) ); |
|
| 53 | + $params = wp_parse_args( $args, array( |
|
| 54 | + 'id' => uniqid( 'wl-input-' ), |
|
| 55 | + 'value' => '', |
|
| 56 | + 'readonly' => false, |
|
| 57 | + 'css_class' => '', |
|
| 58 | + 'description' => '', |
|
| 59 | + ) ); |
|
| 60 | 60 | |
| 61 | - // Set the readonly and class attributes and the description. |
|
| 62 | - $readonly = $params['readonly'] ? ' readonly="readonly"' : ''; |
|
| 63 | - $css_class = ! empty( $params['css_class'] ) ? ' class="' . esc_attr( $params['css_class'] ) . '"' : ''; |
|
| 64 | - $description = ! empty( $params['description'] ) ? '<p>' . wp_kses( $params['description'], array( 'a' => array( 'href' => array() ) ) ) . '</p>' : ''; |
|
| 61 | + // Set the readonly and class attributes and the description. |
|
| 62 | + $readonly = $params['readonly'] ? ' readonly="readonly"' : ''; |
|
| 63 | + $css_class = ! empty( $params['css_class'] ) ? ' class="' . esc_attr( $params['css_class'] ) . '"' : ''; |
|
| 64 | + $description = ! empty( $params['description'] ) ? '<p>' . wp_kses( $params['description'], array( 'a' => array( 'href' => array() ) ) ) . '</p>' : ''; |
|
| 65 | 65 | |
| 66 | - ?> |
|
| 66 | + ?> |
|
| 67 | 67 | |
| 68 | 68 | <input type="text" |
| 69 | 69 | id="<?php echo esc_attr( $params['id'] ); ?>" |
@@ -76,7 +76,7 @@ discard block |
||
| 76 | 76 | |
| 77 | 77 | <?php |
| 78 | 78 | |
| 79 | - return $this; |
|
| 80 | - } |
|
| 79 | + return $this; |
|
| 80 | + } |
|
| 81 | 81 | |
| 82 | 82 | } |
@@ -43,32 +43,32 @@ |
||
| 43 | 43 | * |
| 44 | 44 | * @return $this|Wordlift_Admin_Element |
| 45 | 45 | */ |
| 46 | - public function render( $args ) { |
|
| 46 | + public function render($args) { |
|
| 47 | 47 | |
| 48 | 48 | /* |
| 49 | 49 | * Parse the arguments and merge with default values. |
| 50 | 50 | * Name intentionally do not have a default as it has to be in SyncEvent |
| 51 | 51 | * with form handling code |
| 52 | 52 | */ |
| 53 | - $params = wp_parse_args( $args, array( |
|
| 54 | - 'id' => uniqid( 'wl-input-' ), |
|
| 53 | + $params = wp_parse_args($args, array( |
|
| 54 | + 'id' => uniqid('wl-input-'), |
|
| 55 | 55 | 'value' => '', |
| 56 | 56 | 'readonly' => false, |
| 57 | 57 | 'css_class' => '', |
| 58 | 58 | 'description' => '', |
| 59 | - ) ); |
|
| 59 | + )); |
|
| 60 | 60 | |
| 61 | 61 | // Set the readonly and class attributes and the description. |
| 62 | 62 | $readonly = $params['readonly'] ? ' readonly="readonly"' : ''; |
| 63 | - $css_class = ! empty( $params['css_class'] ) ? ' class="' . esc_attr( $params['css_class'] ) . '"' : ''; |
|
| 64 | - $description = ! empty( $params['description'] ) ? '<p>' . wp_kses( $params['description'], array( 'a' => array( 'href' => array() ) ) ) . '</p>' : ''; |
|
| 63 | + $css_class = ! empty($params['css_class']) ? ' class="'.esc_attr($params['css_class']).'"' : ''; |
|
| 64 | + $description = ! empty($params['description']) ? '<p>'.wp_kses($params['description'], array('a' => array('href' => array()))).'</p>' : ''; |
|
| 65 | 65 | |
| 66 | 66 | ?> |
| 67 | 67 | |
| 68 | 68 | <input type="text" |
| 69 | - id="<?php echo esc_attr( $params['id'] ); ?>" |
|
| 70 | - name="<?php echo esc_attr( $params['name'] ); ?>" |
|
| 71 | - value="<?php echo esc_attr( $params['value'] ); ?>" |
|
| 69 | + id="<?php echo esc_attr($params['id']); ?>" |
|
| 70 | + name="<?php echo esc_attr($params['name']); ?>" |
|
| 71 | + value="<?php echo esc_attr($params['value']); ?>" |
|
| 72 | 72 | <?php echo $readonly; ?> |
| 73 | 73 | <?php echo $css_class; ?> |
| 74 | 74 | /> |
@@ -5,14 +5,14 @@ discard block |
||
| 5 | 5 | |
| 6 | 6 | // Define the basic options for HTTP calls to REDLINK. |
| 7 | 7 | define( 'WL_REDLINK_API_HTTP_OPTIONS', serialize( array( |
| 8 | - 'timeout' => 300, |
|
| 9 | - 'redirection' => 5, |
|
| 10 | - 'httpversion' => '1.1', |
|
| 11 | - 'blocking' => true, |
|
| 12 | - 'cookies' => array(), |
|
| 13 | - 'sslverify' => ( 'false' === getenv( 'WL_SSL_VERIFY_ENABLED' ) ) ? false : true, |
|
| 14 | - 'sslcertificates' => dirname( __FILE__ ) . '/ssl/ca-bundle.crt', |
|
| 15 | - 'decompress' => false, |
|
| 8 | + 'timeout' => 300, |
|
| 9 | + 'redirection' => 5, |
|
| 10 | + 'httpversion' => '1.1', |
|
| 11 | + 'blocking' => true, |
|
| 12 | + 'cookies' => array(), |
|
| 13 | + 'sslverify' => ( 'false' === getenv( 'WL_SSL_VERIFY_ENABLED' ) ) ? false : true, |
|
| 14 | + 'sslcertificates' => dirname( __FILE__ ) . '/ssl/ca-bundle.crt', |
|
| 15 | + 'decompress' => false, |
|
| 16 | 16 | ) ) ); |
| 17 | 17 | |
| 18 | 18 | // Create a unique ID for this request, useful to hook async HTTP requests. |
@@ -43,14 +43,14 @@ discard block |
||
| 43 | 43 | */ |
| 44 | 44 | function wl_prefixes() { |
| 45 | 45 | |
| 46 | - $items = wl_prefixes_list(); |
|
| 47 | - $prefixes = array(); |
|
| 46 | + $items = wl_prefixes_list(); |
|
| 47 | + $prefixes = array(); |
|
| 48 | 48 | |
| 49 | - foreach ( $items as $item ) { |
|
| 50 | - $prefixes[ $item['prefix'] ] = $item['namespace']; |
|
| 51 | - } |
|
| 49 | + foreach ( $items as $item ) { |
|
| 50 | + $prefixes[ $item['prefix'] ] = $item['namespace']; |
|
| 51 | + } |
|
| 52 | 52 | |
| 53 | - return $prefixes; |
|
| 53 | + return $prefixes; |
|
| 54 | 54 | |
| 55 | 55 | } |
| 56 | 56 | |
@@ -63,22 +63,22 @@ discard block |
||
| 63 | 63 | */ |
| 64 | 64 | function wl_predicates() { |
| 65 | 65 | |
| 66 | - return array( |
|
| 67 | - 'a', |
|
| 68 | - 'dct:references', |
|
| 69 | - 'dct:relation', |
|
| 70 | - 'dct:title', |
|
| 71 | - 'dct:subject', |
|
| 72 | - 'owl:sameAs', |
|
| 73 | - 'rdfs:label', |
|
| 74 | - 'schema:author', |
|
| 75 | - 'schema:dateModified', |
|
| 76 | - 'schema:datePublished', |
|
| 77 | - 'schema:locationCreated', |
|
| 78 | - 'schema:description', |
|
| 79 | - 'schema:image', |
|
| 80 | - 'schema:interactionCount', |
|
| 81 | - 'schema:url', |
|
| 82 | - ); |
|
| 66 | + return array( |
|
| 67 | + 'a', |
|
| 68 | + 'dct:references', |
|
| 69 | + 'dct:relation', |
|
| 70 | + 'dct:title', |
|
| 71 | + 'dct:subject', |
|
| 72 | + 'owl:sameAs', |
|
| 73 | + 'rdfs:label', |
|
| 74 | + 'schema:author', |
|
| 75 | + 'schema:dateModified', |
|
| 76 | + 'schema:datePublished', |
|
| 77 | + 'schema:locationCreated', |
|
| 78 | + 'schema:description', |
|
| 79 | + 'schema:image', |
|
| 80 | + 'schema:interactionCount', |
|
| 81 | + 'schema:url', |
|
| 82 | + ); |
|
| 83 | 83 | |
| 84 | 84 | } |
@@ -4,36 +4,36 @@ discard block |
||
| 4 | 4 | */ |
| 5 | 5 | |
| 6 | 6 | // Define the basic options for HTTP calls to REDLINK. |
| 7 | -define( 'WL_REDLINK_API_HTTP_OPTIONS', serialize( array( |
|
| 7 | +define('WL_REDLINK_API_HTTP_OPTIONS', serialize(array( |
|
| 8 | 8 | 'timeout' => 300, |
| 9 | 9 | 'redirection' => 5, |
| 10 | 10 | 'httpversion' => '1.1', |
| 11 | 11 | 'blocking' => true, |
| 12 | 12 | 'cookies' => array(), |
| 13 | - 'sslverify' => ( 'false' === getenv( 'WL_SSL_VERIFY_ENABLED' ) ) ? false : true, |
|
| 14 | - 'sslcertificates' => dirname( __FILE__ ) . '/ssl/ca-bundle.crt', |
|
| 13 | + 'sslverify' => ('false' === getenv('WL_SSL_VERIFY_ENABLED')) ? false : true, |
|
| 14 | + 'sslcertificates' => dirname(__FILE__).'/ssl/ca-bundle.crt', |
|
| 15 | 15 | 'decompress' => false, |
| 16 | -) ) ); |
|
| 16 | +))); |
|
| 17 | 17 | |
| 18 | 18 | // Create a unique ID for this request, useful to hook async HTTP requests. |
| 19 | -define( 'WL_REQUEST_ID', uniqid() ); |
|
| 19 | +define('WL_REQUEST_ID', uniqid()); |
|
| 20 | 20 | |
| 21 | 21 | // Set the temporary files folder. |
| 22 | -defined( 'WL_TEMP_DIR' ) || define( 'WL_TEMP_DIR', get_temp_dir() ); |
|
| 22 | +defined('WL_TEMP_DIR') || define('WL_TEMP_DIR', get_temp_dir()); |
|
| 23 | 23 | |
| 24 | -define( 'WL_ENABLE_SPARQL_UPDATE_QUERIES_BUFFERING', 'true' !== getenv( 'WL_DISABLE_SPARQL_UPDATE_QUERIES_BUFFERING' ) ); |
|
| 24 | +define('WL_ENABLE_SPARQL_UPDATE_QUERIES_BUFFERING', 'true' !== getenv('WL_DISABLE_SPARQL_UPDATE_QUERIES_BUFFERING')); |
|
| 25 | 25 | |
| 26 | 26 | // Define the meta name used to store the entity URL. |
| 27 | -define( 'WL_ENTITY_URL_META_NAME', 'entity_url' ); |
|
| 27 | +define('WL_ENTITY_URL_META_NAME', 'entity_url'); |
|
| 28 | 28 | |
| 29 | 29 | // Max number of recursions when printing microdata |
| 30 | -define( 'WL_RECURSION_DEPTH_ON_ENTITY_METADATA_PRINTING', 3 ); |
|
| 30 | +define('WL_RECURSION_DEPTH_ON_ENTITY_METADATA_PRINTING', 3); |
|
| 31 | 31 | |
| 32 | 32 | // 3.13.0, we use by default WLS 1.11 which provides us with the new, faster |
| 33 | 33 | // chunked analysis. |
| 34 | -define( 'WL_CONFIG_WORDLIFT_API_URL_DEFAULT_VALUE', defined( 'WORDLIFT_API_URL' ) ? WORDLIFT_API_URL . '/' : 'https://api.wordlift.it/1.11/' ); |
|
| 34 | +define('WL_CONFIG_WORDLIFT_API_URL_DEFAULT_VALUE', defined('WORDLIFT_API_URL') ? WORDLIFT_API_URL.'/' : 'https://api.wordlift.it/1.11/'); |
|
| 35 | 35 | |
| 36 | -define( 'WL_CONFIG_TEST_GOOGLE_RICH_SNIPPETS_URL', 'https://developers.google.com/structured-data/testing-tool/?url=' ); |
|
| 36 | +define('WL_CONFIG_TEST_GOOGLE_RICH_SNIPPETS_URL', 'https://developers.google.com/structured-data/testing-tool/?url='); |
|
| 37 | 37 | |
| 38 | 38 | |
| 39 | 39 | /** |
@@ -46,8 +46,8 @@ discard block |
||
| 46 | 46 | $items = wl_prefixes_list(); |
| 47 | 47 | $prefixes = array(); |
| 48 | 48 | |
| 49 | - foreach ( $items as $item ) { |
|
| 50 | - $prefixes[ $item['prefix'] ] = $item['namespace']; |
|
| 49 | + foreach ($items as $item) { |
|
| 50 | + $prefixes[$item['prefix']] = $item['namespace']; |
|
| 51 | 51 | } |
| 52 | 52 | |
| 53 | 53 | return $prefixes; |
@@ -18,104 +18,104 @@ |
||
| 18 | 18 | */ |
| 19 | 19 | class Wordlift_Geomap_Shortcode extends Wordlift_Shortcode { |
| 20 | 20 | |
| 21 | - const SHORTCODE = 'wl_geomap'; |
|
| 22 | - |
|
| 23 | - /** |
|
| 24 | - * Create a {@link Wordlift_Geomap_Shortcode} instance. |
|
| 25 | - * |
|
| 26 | - * @since 3.5.4 |
|
| 27 | - */ |
|
| 28 | - public function __construct() { |
|
| 29 | - parent::__construct(); |
|
| 30 | - |
|
| 31 | - // Hook to the `amp_post_template_css` to hide ourselves when in AMP |
|
| 32 | - // rendering. |
|
| 33 | - add_action( 'amp_post_template_css', array( |
|
| 34 | - $this, |
|
| 35 | - 'amp_post_template_css', |
|
| 36 | - ) ); |
|
| 37 | - |
|
| 38 | - } |
|
| 39 | - |
|
| 40 | - /** |
|
| 41 | - * Render the shortcode. |
|
| 42 | - * |
|
| 43 | - * @since 3.5.4 |
|
| 44 | - * |
|
| 45 | - * @param array $atts An array of shortcode attributes as set by the editor. |
|
| 46 | - * |
|
| 47 | - * @return string The output html code. |
|
| 48 | - */ |
|
| 49 | - public function render( $atts ) { |
|
| 50 | - |
|
| 51 | - // Extract attributes and set default values. |
|
| 52 | - $geomap_atts = shortcode_atts( array( |
|
| 53 | - 'width' => '100%', |
|
| 54 | - 'height' => '300px', |
|
| 55 | - 'global' => false, |
|
| 56 | - ), $atts ); |
|
| 57 | - |
|
| 58 | - // Get id of the post |
|
| 59 | - $post_id = get_the_ID(); |
|
| 60 | - |
|
| 61 | - if ( $geomap_atts['global'] || is_null( $post_id ) ) { |
|
| 62 | - // Global geomap |
|
| 63 | - $geomap_id = 'wl_geomap_global'; |
|
| 64 | - $post_id = null; |
|
| 65 | - } else { |
|
| 66 | - // Post-specific geomap |
|
| 67 | - $geomap_id = 'wl_geomap_' . $post_id; |
|
| 68 | - } |
|
| 69 | - |
|
| 70 | - // Add leaflet css and library. |
|
| 71 | - wp_enqueue_style( |
|
| 72 | - 'leaflet', |
|
| 73 | - dirname( plugin_dir_url( __FILE__ ) ) . '/bower_components/leaflet/dist/leaflet.css' |
|
| 74 | - ); |
|
| 75 | - wp_enqueue_script( |
|
| 76 | - 'leaflet', |
|
| 77 | - dirname( plugin_dir_url( __FILE__ ) ) . '/bower_components/leaflet/dist/leaflet.js' |
|
| 78 | - ); |
|
| 79 | - |
|
| 80 | - // Add wordlift-ui css and library. |
|
| 81 | - wp_enqueue_style( 'wordlift-ui-css', dirname( plugin_dir_url( __FILE__ ) ) . '/css/wordlift-ui.min.css' ); |
|
| 82 | - |
|
| 83 | - $this->enqueue_scripts(); |
|
| 84 | - |
|
| 85 | - wp_localize_script( 'wordlift-ui', 'wl_geomap_params', array( |
|
| 86 | - 'ajax_url' => admin_url( 'admin-ajax.php' ), // Global param |
|
| 87 | - 'action' => 'wl_geomap' // Global param |
|
| 88 | - ) ); |
|
| 89 | - |
|
| 90 | - // Escaping atts. |
|
| 91 | - $esc_id = esc_attr( $geomap_id ); |
|
| 92 | - $esc_width = esc_attr( $geomap_atts['width'] ); |
|
| 93 | - $esc_height = esc_attr( $geomap_atts['height'] ); |
|
| 94 | - $esc_post_id = esc_attr( $post_id ); |
|
| 95 | - |
|
| 96 | - // Return HTML template. |
|
| 97 | - return <<<EOF |
|
| 21 | + const SHORTCODE = 'wl_geomap'; |
|
| 22 | + |
|
| 23 | + /** |
|
| 24 | + * Create a {@link Wordlift_Geomap_Shortcode} instance. |
|
| 25 | + * |
|
| 26 | + * @since 3.5.4 |
|
| 27 | + */ |
|
| 28 | + public function __construct() { |
|
| 29 | + parent::__construct(); |
|
| 30 | + |
|
| 31 | + // Hook to the `amp_post_template_css` to hide ourselves when in AMP |
|
| 32 | + // rendering. |
|
| 33 | + add_action( 'amp_post_template_css', array( |
|
| 34 | + $this, |
|
| 35 | + 'amp_post_template_css', |
|
| 36 | + ) ); |
|
| 37 | + |
|
| 38 | + } |
|
| 39 | + |
|
| 40 | + /** |
|
| 41 | + * Render the shortcode. |
|
| 42 | + * |
|
| 43 | + * @since 3.5.4 |
|
| 44 | + * |
|
| 45 | + * @param array $atts An array of shortcode attributes as set by the editor. |
|
| 46 | + * |
|
| 47 | + * @return string The output html code. |
|
| 48 | + */ |
|
| 49 | + public function render( $atts ) { |
|
| 50 | + |
|
| 51 | + // Extract attributes and set default values. |
|
| 52 | + $geomap_atts = shortcode_atts( array( |
|
| 53 | + 'width' => '100%', |
|
| 54 | + 'height' => '300px', |
|
| 55 | + 'global' => false, |
|
| 56 | + ), $atts ); |
|
| 57 | + |
|
| 58 | + // Get id of the post |
|
| 59 | + $post_id = get_the_ID(); |
|
| 60 | + |
|
| 61 | + if ( $geomap_atts['global'] || is_null( $post_id ) ) { |
|
| 62 | + // Global geomap |
|
| 63 | + $geomap_id = 'wl_geomap_global'; |
|
| 64 | + $post_id = null; |
|
| 65 | + } else { |
|
| 66 | + // Post-specific geomap |
|
| 67 | + $geomap_id = 'wl_geomap_' . $post_id; |
|
| 68 | + } |
|
| 69 | + |
|
| 70 | + // Add leaflet css and library. |
|
| 71 | + wp_enqueue_style( |
|
| 72 | + 'leaflet', |
|
| 73 | + dirname( plugin_dir_url( __FILE__ ) ) . '/bower_components/leaflet/dist/leaflet.css' |
|
| 74 | + ); |
|
| 75 | + wp_enqueue_script( |
|
| 76 | + 'leaflet', |
|
| 77 | + dirname( plugin_dir_url( __FILE__ ) ) . '/bower_components/leaflet/dist/leaflet.js' |
|
| 78 | + ); |
|
| 79 | + |
|
| 80 | + // Add wordlift-ui css and library. |
|
| 81 | + wp_enqueue_style( 'wordlift-ui-css', dirname( plugin_dir_url( __FILE__ ) ) . '/css/wordlift-ui.min.css' ); |
|
| 82 | + |
|
| 83 | + $this->enqueue_scripts(); |
|
| 84 | + |
|
| 85 | + wp_localize_script( 'wordlift-ui', 'wl_geomap_params', array( |
|
| 86 | + 'ajax_url' => admin_url( 'admin-ajax.php' ), // Global param |
|
| 87 | + 'action' => 'wl_geomap' // Global param |
|
| 88 | + ) ); |
|
| 89 | + |
|
| 90 | + // Escaping atts. |
|
| 91 | + $esc_id = esc_attr( $geomap_id ); |
|
| 92 | + $esc_width = esc_attr( $geomap_atts['width'] ); |
|
| 93 | + $esc_height = esc_attr( $geomap_atts['height'] ); |
|
| 94 | + $esc_post_id = esc_attr( $post_id ); |
|
| 95 | + |
|
| 96 | + // Return HTML template. |
|
| 97 | + return <<<EOF |
|
| 98 | 98 | <div class="wl-geomap" id="$esc_id" data-post-id="$esc_post_id" |
| 99 | 99 | style="width:$esc_width; height:$esc_height; background-color: gray;"> |
| 100 | 100 | </div> |
| 101 | 101 | EOF; |
| 102 | - } |
|
| 103 | - |
|
| 104 | - /** |
|
| 105 | - * Customize the CSS when in AMP. |
|
| 106 | - * |
|
| 107 | - * See https://github.com/Automattic/amp-wp/blob/master/readme.md#custom-css |
|
| 108 | - * |
|
| 109 | - * @since 3.13.0 |
|
| 110 | - * |
|
| 111 | - * @param object $amp_template The template. |
|
| 112 | - */ |
|
| 113 | - public function amp_post_template_css( $amp_template ) { |
|
| 114 | - |
|
| 115 | - // Hide the `wl-geomap` when in AMP. |
|
| 116 | - ?> |
|
| 102 | + } |
|
| 103 | + |
|
| 104 | + /** |
|
| 105 | + * Customize the CSS when in AMP. |
|
| 106 | + * |
|
| 107 | + * See https://github.com/Automattic/amp-wp/blob/master/readme.md#custom-css |
|
| 108 | + * |
|
| 109 | + * @since 3.13.0 |
|
| 110 | + * |
|
| 111 | + * @param object $amp_template The template. |
|
| 112 | + */ |
|
| 113 | + public function amp_post_template_css( $amp_template ) { |
|
| 114 | + |
|
| 115 | + // Hide the `wl-geomap` when in AMP. |
|
| 116 | + ?> |
|
| 117 | 117 | .wl-geomap { display: none; } |
| 118 | 118 | <?php |
| 119 | - } |
|
| 119 | + } |
|
| 120 | 120 | |
| 121 | 121 | } |
@@ -30,10 +30,10 @@ discard block |
||
| 30 | 30 | |
| 31 | 31 | // Hook to the `amp_post_template_css` to hide ourselves when in AMP |
| 32 | 32 | // rendering. |
| 33 | - add_action( 'amp_post_template_css', array( |
|
| 33 | + add_action('amp_post_template_css', array( |
|
| 34 | 34 | $this, |
| 35 | 35 | 'amp_post_template_css', |
| 36 | - ) ); |
|
| 36 | + )); |
|
| 37 | 37 | |
| 38 | 38 | } |
| 39 | 39 | |
@@ -46,52 +46,52 @@ discard block |
||
| 46 | 46 | * |
| 47 | 47 | * @return string The output html code. |
| 48 | 48 | */ |
| 49 | - public function render( $atts ) { |
|
| 49 | + public function render($atts) { |
|
| 50 | 50 | |
| 51 | 51 | // Extract attributes and set default values. |
| 52 | - $geomap_atts = shortcode_atts( array( |
|
| 52 | + $geomap_atts = shortcode_atts(array( |
|
| 53 | 53 | 'width' => '100%', |
| 54 | 54 | 'height' => '300px', |
| 55 | 55 | 'global' => false, |
| 56 | - ), $atts ); |
|
| 56 | + ), $atts); |
|
| 57 | 57 | |
| 58 | 58 | // Get id of the post |
| 59 | 59 | $post_id = get_the_ID(); |
| 60 | 60 | |
| 61 | - if ( $geomap_atts['global'] || is_null( $post_id ) ) { |
|
| 61 | + if ($geomap_atts['global'] || is_null($post_id)) { |
|
| 62 | 62 | // Global geomap |
| 63 | 63 | $geomap_id = 'wl_geomap_global'; |
| 64 | 64 | $post_id = null; |
| 65 | 65 | } else { |
| 66 | 66 | // Post-specific geomap |
| 67 | - $geomap_id = 'wl_geomap_' . $post_id; |
|
| 67 | + $geomap_id = 'wl_geomap_'.$post_id; |
|
| 68 | 68 | } |
| 69 | 69 | |
| 70 | 70 | // Add leaflet css and library. |
| 71 | 71 | wp_enqueue_style( |
| 72 | 72 | 'leaflet', |
| 73 | - dirname( plugin_dir_url( __FILE__ ) ) . '/bower_components/leaflet/dist/leaflet.css' |
|
| 73 | + dirname(plugin_dir_url(__FILE__)).'/bower_components/leaflet/dist/leaflet.css' |
|
| 74 | 74 | ); |
| 75 | 75 | wp_enqueue_script( |
| 76 | 76 | 'leaflet', |
| 77 | - dirname( plugin_dir_url( __FILE__ ) ) . '/bower_components/leaflet/dist/leaflet.js' |
|
| 77 | + dirname(plugin_dir_url(__FILE__)).'/bower_components/leaflet/dist/leaflet.js' |
|
| 78 | 78 | ); |
| 79 | 79 | |
| 80 | 80 | // Add wordlift-ui css and library. |
| 81 | - wp_enqueue_style( 'wordlift-ui-css', dirname( plugin_dir_url( __FILE__ ) ) . '/css/wordlift-ui.min.css' ); |
|
| 81 | + wp_enqueue_style('wordlift-ui-css', dirname(plugin_dir_url(__FILE__)).'/css/wordlift-ui.min.css'); |
|
| 82 | 82 | |
| 83 | 83 | $this->enqueue_scripts(); |
| 84 | 84 | |
| 85 | - wp_localize_script( 'wordlift-ui', 'wl_geomap_params', array( |
|
| 86 | - 'ajax_url' => admin_url( 'admin-ajax.php' ), // Global param |
|
| 85 | + wp_localize_script('wordlift-ui', 'wl_geomap_params', array( |
|
| 86 | + 'ajax_url' => admin_url('admin-ajax.php'), // Global param |
|
| 87 | 87 | 'action' => 'wl_geomap' // Global param |
| 88 | - ) ); |
|
| 88 | + )); |
|
| 89 | 89 | |
| 90 | 90 | // Escaping atts. |
| 91 | - $esc_id = esc_attr( $geomap_id ); |
|
| 92 | - $esc_width = esc_attr( $geomap_atts['width'] ); |
|
| 93 | - $esc_height = esc_attr( $geomap_atts['height'] ); |
|
| 94 | - $esc_post_id = esc_attr( $post_id ); |
|
| 91 | + $esc_id = esc_attr($geomap_id); |
|
| 92 | + $esc_width = esc_attr($geomap_atts['width']); |
|
| 93 | + $esc_height = esc_attr($geomap_atts['height']); |
|
| 94 | + $esc_post_id = esc_attr($post_id); |
|
| 95 | 95 | |
| 96 | 96 | // Return HTML template. |
| 97 | 97 | return <<<EOF |
@@ -110,7 +110,7 @@ discard block |
||
| 110 | 110 | * |
| 111 | 111 | * @param object $amp_template The template. |
| 112 | 112 | */ |
| 113 | - public function amp_post_template_css( $amp_template ) { |
|
| 113 | + public function amp_post_template_css($amp_template) { |
|
| 114 | 114 | |
| 115 | 115 | // Hide the `wl-geomap` when in AMP. |
| 116 | 116 | ?> |
@@ -13,124 +13,124 @@ discard block |
||
| 13 | 13 | */ |
| 14 | 14 | class Wordlift_Rebuild_Service extends Wordlift_Listable { |
| 15 | 15 | |
| 16 | - /** |
|
| 17 | - * A {@link Wordlift_Log_Service} instance. |
|
| 18 | - * |
|
| 19 | - * @since 3.6.0 |
|
| 20 | - * @access private |
|
| 21 | - * @var \Wordlift_Log_Service $log A {@link Wordlift_Log_Service} instance. |
|
| 22 | - */ |
|
| 23 | - private $log; |
|
| 24 | - |
|
| 25 | - /** |
|
| 26 | - * A {@link Wordlift_Sparql_Service} instance. |
|
| 27 | - * @since 3.6.0 |
|
| 28 | - * @access private |
|
| 29 | - * @var \Wordlift_Sparql_Service $sparql_service A {@link Wordlift_Sparql_Service} instance. |
|
| 30 | - */ |
|
| 31 | - private $sparql_service; |
|
| 32 | - |
|
| 33 | - /** |
|
| 34 | - * @var \Wordlift_Uri_Service |
|
| 35 | - */ |
|
| 36 | - private $uri_service; |
|
| 37 | - |
|
| 38 | - /** |
|
| 39 | - * Create an instance of Wordlift_Rebuild_Service. |
|
| 40 | - * |
|
| 41 | - * @since 3.6.0 |
|
| 42 | - * |
|
| 43 | - * @param \Wordlift_Sparql_Service $sparql_service A {@link Wordlift_Sparql_Service} instance used to query the remote dataset. |
|
| 44 | - * @param \Wordlift_Uri_Service $uri_service |
|
| 45 | - */ |
|
| 46 | - public function __construct( $sparql_service, $uri_service ) { |
|
| 47 | - |
|
| 48 | - $this->log = Wordlift_Log_Service::get_logger( 'Wordlift_Rebuild_Service' ); |
|
| 49 | - |
|
| 50 | - $this->sparql_service = $sparql_service; |
|
| 51 | - $this->uri_service = $uri_service; |
|
| 52 | - } |
|
| 53 | - |
|
| 54 | - /** |
|
| 55 | - * Rebuild the Linked Data remote dataset by clearing it out and repopulating |
|
| 56 | - * it with local data. |
|
| 57 | - * |
|
| 58 | - * @since 3.6.0 |
|
| 59 | - */ |
|
| 60 | - public function rebuild() { |
|
| 61 | - |
|
| 62 | - ob_clean(); |
|
| 63 | - |
|
| 64 | - // Give ourselves some time to process the data. |
|
| 65 | - set_time_limit( 21600 ); // 6 hours |
|
| 66 | - |
|
| 67 | - // Send textual output. |
|
| 68 | - header( 'Content-type: text/plain; charset=utf-8' ); |
|
| 69 | - |
|
| 70 | - // We start at 0 by default and get to max. |
|
| 71 | - $offset = $_GET['offset'] ?: 0; |
|
| 72 | - $limit = $_GET['limit'] ?: 1; |
|
| 73 | - $entity_only = isset( $_GET['entity_only'] ) && '1' === $_GET['entity_only']; |
|
| 74 | - $max = $offset + $limit; |
|
| 75 | - |
|
| 76 | - // If we're starting at offset 0, then delete existing URIs and data from |
|
| 77 | - // the remote dataset. |
|
| 78 | - if ( 0 === $offset ) { |
|
| 79 | - |
|
| 80 | - // Clear out all generated URIs, since the dataset URI might have changed |
|
| 81 | - // in the process. |
|
| 82 | - $this->uri_service->delete_all(); |
|
| 83 | - |
|
| 84 | - // Delete all the triples in the remote dataset. |
|
| 85 | - $this->sparql_service->queue( 'DELETE { ?s ?p ?o } WHERE { ?s ?p ?o };' ); |
|
| 86 | - |
|
| 87 | - } |
|
| 88 | - |
|
| 89 | - // Go through the list of published entities and posts and call the (legacy) |
|
| 90 | - // `wl_linked_data_save_post` function for each one. We're using the `process` |
|
| 91 | - // function which is provided by the parent `Wordlift_Listable` abstract class |
|
| 92 | - // and will cycle through all the posts w/ a very small memory footprint |
|
| 93 | - // in order to avoid memory errors. |
|
| 94 | - |
|
| 95 | - $count = 0; |
|
| 96 | - $this->process( function ( $post ) use ( &$count ) { |
|
| 97 | - $count ++; |
|
| 98 | - wl_linked_data_save_post( $post->ID ); |
|
| 99 | - }, array( |
|
| 100 | - 'post_status' => 'publish', |
|
| 101 | - 'post_type' => $entity_only ? 'entity' : array( |
|
| 102 | - 'entity', |
|
| 103 | - 'post', |
|
| 104 | - ), |
|
| 105 | - ), $offset, $max ); |
|
| 106 | - |
|
| 107 | - // Redirect to the next chunk. |
|
| 108 | - if ( $count == $limit ) { |
|
| 109 | - $this->redirect( admin_url( 'admin-ajax.php?action=wl_rebuild&offset=' . ( $offset + $limit ) . '&limit=' . $limit . '&entity_only=' . ( $entity_only ? '1' : '0' ) ) ); |
|
| 110 | - } |
|
| 111 | - |
|
| 112 | - echo( "done [ count :: $count ][ limit :: $limit ]" ); |
|
| 113 | - |
|
| 114 | - // If we're being called as AJAX, die here. |
|
| 115 | - if ( DOING_AJAX ) { |
|
| 116 | - wp_die(); |
|
| 117 | - } |
|
| 118 | - |
|
| 119 | - } |
|
| 120 | - |
|
| 121 | - /** |
|
| 122 | - * Redirect using a client-side meta to avoid browsers' redirect restrictions. |
|
| 123 | - * |
|
| 124 | - * @since 3.9.8 |
|
| 125 | - * |
|
| 126 | - * @param string $url The URL to redirect to. |
|
| 127 | - */ |
|
| 128 | - private function redirect( $url ) { |
|
| 129 | - |
|
| 130 | - ob_clean(); |
|
| 131 | - |
|
| 132 | - @header( 'Content-Type: text/html; charset=' . get_option( 'blog_charset' ) ); |
|
| 133 | - ?> |
|
| 16 | + /** |
|
| 17 | + * A {@link Wordlift_Log_Service} instance. |
|
| 18 | + * |
|
| 19 | + * @since 3.6.0 |
|
| 20 | + * @access private |
|
| 21 | + * @var \Wordlift_Log_Service $log A {@link Wordlift_Log_Service} instance. |
|
| 22 | + */ |
|
| 23 | + private $log; |
|
| 24 | + |
|
| 25 | + /** |
|
| 26 | + * A {@link Wordlift_Sparql_Service} instance. |
|
| 27 | + * @since 3.6.0 |
|
| 28 | + * @access private |
|
| 29 | + * @var \Wordlift_Sparql_Service $sparql_service A {@link Wordlift_Sparql_Service} instance. |
|
| 30 | + */ |
|
| 31 | + private $sparql_service; |
|
| 32 | + |
|
| 33 | + /** |
|
| 34 | + * @var \Wordlift_Uri_Service |
|
| 35 | + */ |
|
| 36 | + private $uri_service; |
|
| 37 | + |
|
| 38 | + /** |
|
| 39 | + * Create an instance of Wordlift_Rebuild_Service. |
|
| 40 | + * |
|
| 41 | + * @since 3.6.0 |
|
| 42 | + * |
|
| 43 | + * @param \Wordlift_Sparql_Service $sparql_service A {@link Wordlift_Sparql_Service} instance used to query the remote dataset. |
|
| 44 | + * @param \Wordlift_Uri_Service $uri_service |
|
| 45 | + */ |
|
| 46 | + public function __construct( $sparql_service, $uri_service ) { |
|
| 47 | + |
|
| 48 | + $this->log = Wordlift_Log_Service::get_logger( 'Wordlift_Rebuild_Service' ); |
|
| 49 | + |
|
| 50 | + $this->sparql_service = $sparql_service; |
|
| 51 | + $this->uri_service = $uri_service; |
|
| 52 | + } |
|
| 53 | + |
|
| 54 | + /** |
|
| 55 | + * Rebuild the Linked Data remote dataset by clearing it out and repopulating |
|
| 56 | + * it with local data. |
|
| 57 | + * |
|
| 58 | + * @since 3.6.0 |
|
| 59 | + */ |
|
| 60 | + public function rebuild() { |
|
| 61 | + |
|
| 62 | + ob_clean(); |
|
| 63 | + |
|
| 64 | + // Give ourselves some time to process the data. |
|
| 65 | + set_time_limit( 21600 ); // 6 hours |
|
| 66 | + |
|
| 67 | + // Send textual output. |
|
| 68 | + header( 'Content-type: text/plain; charset=utf-8' ); |
|
| 69 | + |
|
| 70 | + // We start at 0 by default and get to max. |
|
| 71 | + $offset = $_GET['offset'] ?: 0; |
|
| 72 | + $limit = $_GET['limit'] ?: 1; |
|
| 73 | + $entity_only = isset( $_GET['entity_only'] ) && '1' === $_GET['entity_only']; |
|
| 74 | + $max = $offset + $limit; |
|
| 75 | + |
|
| 76 | + // If we're starting at offset 0, then delete existing URIs and data from |
|
| 77 | + // the remote dataset. |
|
| 78 | + if ( 0 === $offset ) { |
|
| 79 | + |
|
| 80 | + // Clear out all generated URIs, since the dataset URI might have changed |
|
| 81 | + // in the process. |
|
| 82 | + $this->uri_service->delete_all(); |
|
| 83 | + |
|
| 84 | + // Delete all the triples in the remote dataset. |
|
| 85 | + $this->sparql_service->queue( 'DELETE { ?s ?p ?o } WHERE { ?s ?p ?o };' ); |
|
| 86 | + |
|
| 87 | + } |
|
| 88 | + |
|
| 89 | + // Go through the list of published entities and posts and call the (legacy) |
|
| 90 | + // `wl_linked_data_save_post` function for each one. We're using the `process` |
|
| 91 | + // function which is provided by the parent `Wordlift_Listable` abstract class |
|
| 92 | + // and will cycle through all the posts w/ a very small memory footprint |
|
| 93 | + // in order to avoid memory errors. |
|
| 94 | + |
|
| 95 | + $count = 0; |
|
| 96 | + $this->process( function ( $post ) use ( &$count ) { |
|
| 97 | + $count ++; |
|
| 98 | + wl_linked_data_save_post( $post->ID ); |
|
| 99 | + }, array( |
|
| 100 | + 'post_status' => 'publish', |
|
| 101 | + 'post_type' => $entity_only ? 'entity' : array( |
|
| 102 | + 'entity', |
|
| 103 | + 'post', |
|
| 104 | + ), |
|
| 105 | + ), $offset, $max ); |
|
| 106 | + |
|
| 107 | + // Redirect to the next chunk. |
|
| 108 | + if ( $count == $limit ) { |
|
| 109 | + $this->redirect( admin_url( 'admin-ajax.php?action=wl_rebuild&offset=' . ( $offset + $limit ) . '&limit=' . $limit . '&entity_only=' . ( $entity_only ? '1' : '0' ) ) ); |
|
| 110 | + } |
|
| 111 | + |
|
| 112 | + echo( "done [ count :: $count ][ limit :: $limit ]" ); |
|
| 113 | + |
|
| 114 | + // If we're being called as AJAX, die here. |
|
| 115 | + if ( DOING_AJAX ) { |
|
| 116 | + wp_die(); |
|
| 117 | + } |
|
| 118 | + |
|
| 119 | + } |
|
| 120 | + |
|
| 121 | + /** |
|
| 122 | + * Redirect using a client-side meta to avoid browsers' redirect restrictions. |
|
| 123 | + * |
|
| 124 | + * @since 3.9.8 |
|
| 125 | + * |
|
| 126 | + * @param string $url The URL to redirect to. |
|
| 127 | + */ |
|
| 128 | + private function redirect( $url ) { |
|
| 129 | + |
|
| 130 | + ob_clean(); |
|
| 131 | + |
|
| 132 | + @header( 'Content-Type: text/html; charset=' . get_option( 'blog_charset' ) ); |
|
| 133 | + ?> |
|
| 134 | 134 | <html> |
| 135 | 135 | <head> |
| 136 | 136 | <meta http-equiv="refresh" |
@@ -139,32 +139,32 @@ discard block |
||
| 139 | 139 | </html> |
| 140 | 140 | <?php |
| 141 | 141 | |
| 142 | - exit; |
|
| 143 | - |
|
| 144 | - } |
|
| 145 | - |
|
| 146 | - /** |
|
| 147 | - * List the items starting at the specified offset and up to the specified limit. |
|
| 148 | - * |
|
| 149 | - * @since 3.6.0 |
|
| 150 | - * |
|
| 151 | - * @param int $offset The start offset. |
|
| 152 | - * @param int $limit The maximum number of items to return. |
|
| 153 | - * @param array $args Additional arguments. |
|
| 154 | - * |
|
| 155 | - * @return array A array of items (or an empty array if no items are found). |
|
| 156 | - */ |
|
| 157 | - function find( $offset = 0, $limit = 10, $args = array() ) { |
|
| 158 | - |
|
| 159 | - return get_posts( wp_parse_args( $args, array( |
|
| 160 | - 'offset' => $offset, |
|
| 161 | - 'numberposts' => $limit, |
|
| 162 | - 'fields' => 'all', |
|
| 163 | - 'orderby' => 'ID', |
|
| 164 | - 'order' => 'ASC', |
|
| 165 | - 'post_status' => 'any', |
|
| 166 | - 'post_type' => 'post', |
|
| 167 | - ) ) ); |
|
| 168 | - } |
|
| 142 | + exit; |
|
| 143 | + |
|
| 144 | + } |
|
| 145 | + |
|
| 146 | + /** |
|
| 147 | + * List the items starting at the specified offset and up to the specified limit. |
|
| 148 | + * |
|
| 149 | + * @since 3.6.0 |
|
| 150 | + * |
|
| 151 | + * @param int $offset The start offset. |
|
| 152 | + * @param int $limit The maximum number of items to return. |
|
| 153 | + * @param array $args Additional arguments. |
|
| 154 | + * |
|
| 155 | + * @return array A array of items (or an empty array if no items are found). |
|
| 156 | + */ |
|
| 157 | + function find( $offset = 0, $limit = 10, $args = array() ) { |
|
| 158 | + |
|
| 159 | + return get_posts( wp_parse_args( $args, array( |
|
| 160 | + 'offset' => $offset, |
|
| 161 | + 'numberposts' => $limit, |
|
| 162 | + 'fields' => 'all', |
|
| 163 | + 'orderby' => 'ID', |
|
| 164 | + 'order' => 'ASC', |
|
| 165 | + 'post_status' => 'any', |
|
| 166 | + 'post_type' => 'post', |
|
| 167 | + ) ) ); |
|
| 168 | + } |
|
| 169 | 169 | |
| 170 | 170 | } |
@@ -43,9 +43,9 @@ discard block |
||
| 43 | 43 | * @param \Wordlift_Sparql_Service $sparql_service A {@link Wordlift_Sparql_Service} instance used to query the remote dataset. |
| 44 | 44 | * @param \Wordlift_Uri_Service $uri_service |
| 45 | 45 | */ |
| 46 | - public function __construct( $sparql_service, $uri_service ) { |
|
| 46 | + public function __construct($sparql_service, $uri_service) { |
|
| 47 | 47 | |
| 48 | - $this->log = Wordlift_Log_Service::get_logger( 'Wordlift_Rebuild_Service' ); |
|
| 48 | + $this->log = Wordlift_Log_Service::get_logger('Wordlift_Rebuild_Service'); |
|
| 49 | 49 | |
| 50 | 50 | $this->sparql_service = $sparql_service; |
| 51 | 51 | $this->uri_service = $uri_service; |
@@ -62,27 +62,27 @@ discard block |
||
| 62 | 62 | ob_clean(); |
| 63 | 63 | |
| 64 | 64 | // Give ourselves some time to process the data. |
| 65 | - set_time_limit( 21600 ); // 6 hours |
|
| 65 | + set_time_limit(21600); // 6 hours |
|
| 66 | 66 | |
| 67 | 67 | // Send textual output. |
| 68 | - header( 'Content-type: text/plain; charset=utf-8' ); |
|
| 68 | + header('Content-type: text/plain; charset=utf-8'); |
|
| 69 | 69 | |
| 70 | 70 | // We start at 0 by default and get to max. |
| 71 | 71 | $offset = $_GET['offset'] ?: 0; |
| 72 | 72 | $limit = $_GET['limit'] ?: 1; |
| 73 | - $entity_only = isset( $_GET['entity_only'] ) && '1' === $_GET['entity_only']; |
|
| 73 | + $entity_only = isset($_GET['entity_only']) && '1' === $_GET['entity_only']; |
|
| 74 | 74 | $max = $offset + $limit; |
| 75 | 75 | |
| 76 | 76 | // If we're starting at offset 0, then delete existing URIs and data from |
| 77 | 77 | // the remote dataset. |
| 78 | - if ( 0 === $offset ) { |
|
| 78 | + if (0 === $offset) { |
|
| 79 | 79 | |
| 80 | 80 | // Clear out all generated URIs, since the dataset URI might have changed |
| 81 | 81 | // in the process. |
| 82 | 82 | $this->uri_service->delete_all(); |
| 83 | 83 | |
| 84 | 84 | // Delete all the triples in the remote dataset. |
| 85 | - $this->sparql_service->queue( 'DELETE { ?s ?p ?o } WHERE { ?s ?p ?o };' ); |
|
| 85 | + $this->sparql_service->queue('DELETE { ?s ?p ?o } WHERE { ?s ?p ?o };'); |
|
| 86 | 86 | |
| 87 | 87 | } |
| 88 | 88 | |
@@ -93,26 +93,26 @@ discard block |
||
| 93 | 93 | // in order to avoid memory errors. |
| 94 | 94 | |
| 95 | 95 | $count = 0; |
| 96 | - $this->process( function ( $post ) use ( &$count ) { |
|
| 97 | - $count ++; |
|
| 98 | - wl_linked_data_save_post( $post->ID ); |
|
| 96 | + $this->process(function($post) use (&$count) { |
|
| 97 | + $count++; |
|
| 98 | + wl_linked_data_save_post($post->ID); |
|
| 99 | 99 | }, array( |
| 100 | 100 | 'post_status' => 'publish', |
| 101 | 101 | 'post_type' => $entity_only ? 'entity' : array( |
| 102 | 102 | 'entity', |
| 103 | 103 | 'post', |
| 104 | 104 | ), |
| 105 | - ), $offset, $max ); |
|
| 105 | + ), $offset, $max); |
|
| 106 | 106 | |
| 107 | 107 | // Redirect to the next chunk. |
| 108 | - if ( $count == $limit ) { |
|
| 109 | - $this->redirect( admin_url( 'admin-ajax.php?action=wl_rebuild&offset=' . ( $offset + $limit ) . '&limit=' . $limit . '&entity_only=' . ( $entity_only ? '1' : '0' ) ) ); |
|
| 108 | + if ($count == $limit) { |
|
| 109 | + $this->redirect(admin_url('admin-ajax.php?action=wl_rebuild&offset='.($offset + $limit).'&limit='.$limit.'&entity_only='.($entity_only ? '1' : '0'))); |
|
| 110 | 110 | } |
| 111 | 111 | |
| 112 | - echo( "done [ count :: $count ][ limit :: $limit ]" ); |
|
| 112 | + echo("done [ count :: $count ][ limit :: $limit ]"); |
|
| 113 | 113 | |
| 114 | 114 | // If we're being called as AJAX, die here. |
| 115 | - if ( DOING_AJAX ) { |
|
| 115 | + if (DOING_AJAX) { |
|
| 116 | 116 | wp_die(); |
| 117 | 117 | } |
| 118 | 118 | |
@@ -125,16 +125,16 @@ discard block |
||
| 125 | 125 | * |
| 126 | 126 | * @param string $url The URL to redirect to. |
| 127 | 127 | */ |
| 128 | - private function redirect( $url ) { |
|
| 128 | + private function redirect($url) { |
|
| 129 | 129 | |
| 130 | 130 | ob_clean(); |
| 131 | 131 | |
| 132 | - @header( 'Content-Type: text/html; charset=' . get_option( 'blog_charset' ) ); |
|
| 132 | + @header('Content-Type: text/html; charset='.get_option('blog_charset')); |
|
| 133 | 133 | ?> |
| 134 | 134 | <html> |
| 135 | 135 | <head> |
| 136 | 136 | <meta http-equiv="refresh" |
| 137 | - content="1; <?php echo esc_attr( $url ); ?>"> |
|
| 137 | + content="1; <?php echo esc_attr($url); ?>"> |
|
| 138 | 138 | </head> |
| 139 | 139 | </html> |
| 140 | 140 | <?php |
@@ -154,9 +154,9 @@ discard block |
||
| 154 | 154 | * |
| 155 | 155 | * @return array A array of items (or an empty array if no items are found). |
| 156 | 156 | */ |
| 157 | - function find( $offset = 0, $limit = 10, $args = array() ) { |
|
| 157 | + function find($offset = 0, $limit = 10, $args = array()) { |
|
| 158 | 158 | |
| 159 | - return get_posts( wp_parse_args( $args, array( |
|
| 159 | + return get_posts(wp_parse_args($args, array( |
|
| 160 | 160 | 'offset' => $offset, |
| 161 | 161 | 'numberposts' => $limit, |
| 162 | 162 | 'fields' => 'all', |
@@ -164,7 +164,7 @@ discard block |
||
| 164 | 164 | 'order' => 'ASC', |
| 165 | 165 | 'post_status' => 'any', |
| 166 | 166 | 'post_type' => 'post', |
| 167 | - ) ) ); |
|
| 167 | + ))); |
|
| 168 | 168 | } |
| 169 | 169 | |
| 170 | 170 | } |
@@ -11,7 +11,7 @@ discard block |
||
| 11 | 11 | */ |
| 12 | 12 | |
| 13 | 13 | if ( ! defined( 'ABSPATH' ) ) { |
| 14 | - exit; |
|
| 14 | + exit; |
|
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | /** |
@@ -21,292 +21,292 @@ discard block |
||
| 21 | 21 | */ |
| 22 | 22 | class Wordlift_Languages { |
| 23 | 23 | |
| 24 | - /** |
|
| 25 | - * An array that will contain language codes => language names pairs. It gets lazily loaded the first time by the |
|
| 26 | - * `get_languages` function. |
|
| 27 | - * |
|
| 28 | - * @since 3.9.0 |
|
| 29 | - * @var array|null An array of language codes => language names pairs or NULL if not initialized yet. |
|
| 30 | - */ |
|
| 31 | - private static $languages = null; |
|
| 24 | + /** |
|
| 25 | + * An array that will contain language codes => language names pairs. It gets lazily loaded the first time by the |
|
| 26 | + * `get_languages` function. |
|
| 27 | + * |
|
| 28 | + * @since 3.9.0 |
|
| 29 | + * @var array|null An array of language codes => language names pairs or NULL if not initialized yet. |
|
| 30 | + */ |
|
| 31 | + private static $languages = null; |
|
| 32 | 32 | |
| 33 | - /** |
|
| 34 | - * The list of supported language codes. |
|
| 35 | - * |
|
| 36 | - * @since 3.9.0 |
|
| 37 | - * |
|
| 38 | - * @var array An array of language codes. |
|
| 39 | - */ |
|
| 40 | - private static $codes = array( |
|
| 41 | - 'be', |
|
| 42 | - 'bg', |
|
| 43 | - 'ca', |
|
| 44 | - 'cs', |
|
| 45 | - 'da', |
|
| 46 | - 'de', |
|
| 47 | - 'en', |
|
| 48 | - 'es', |
|
| 49 | - 'et', |
|
| 50 | - 'fi', |
|
| 51 | - 'fr', |
|
| 52 | - 'hr', |
|
| 53 | - 'hu', |
|
| 54 | - 'id', |
|
| 55 | - 'is', |
|
| 56 | - 'it', |
|
| 57 | - 'lt', |
|
| 58 | - 'lv', |
|
| 59 | - 'nl', |
|
| 60 | - 'no', |
|
| 61 | - 'pl', |
|
| 62 | - 'pt', |
|
| 63 | - 'ro', |
|
| 64 | - 'ru', |
|
| 65 | - 'sk', |
|
| 66 | - 'sl', |
|
| 67 | - 'sq', |
|
| 68 | - 'sr', |
|
| 69 | - 'sv', |
|
| 70 | - 'tr', |
|
| 71 | - 'uk', |
|
| 72 | - 'zh-cn', |
|
| 73 | - ); |
|
| 33 | + /** |
|
| 34 | + * The list of supported language codes. |
|
| 35 | + * |
|
| 36 | + * @since 3.9.0 |
|
| 37 | + * |
|
| 38 | + * @var array An array of language codes. |
|
| 39 | + */ |
|
| 40 | + private static $codes = array( |
|
| 41 | + 'be', |
|
| 42 | + 'bg', |
|
| 43 | + 'ca', |
|
| 44 | + 'cs', |
|
| 45 | + 'da', |
|
| 46 | + 'de', |
|
| 47 | + 'en', |
|
| 48 | + 'es', |
|
| 49 | + 'et', |
|
| 50 | + 'fi', |
|
| 51 | + 'fr', |
|
| 52 | + 'hr', |
|
| 53 | + 'hu', |
|
| 54 | + 'id', |
|
| 55 | + 'is', |
|
| 56 | + 'it', |
|
| 57 | + 'lt', |
|
| 58 | + 'lv', |
|
| 59 | + 'nl', |
|
| 60 | + 'no', |
|
| 61 | + 'pl', |
|
| 62 | + 'pt', |
|
| 63 | + 'ro', |
|
| 64 | + 'ru', |
|
| 65 | + 'sk', |
|
| 66 | + 'sl', |
|
| 67 | + 'sq', |
|
| 68 | + 'sr', |
|
| 69 | + 'sv', |
|
| 70 | + 'tr', |
|
| 71 | + 'uk', |
|
| 72 | + 'zh-cn', |
|
| 73 | + ); |
|
| 74 | 74 | |
| 75 | - /** |
|
| 76 | - * Get the list of WordLift's supported languages in an array with language code => language name pairs. |
|
| 77 | - * |
|
| 78 | - * @since 3.9.0 |
|
| 79 | - * |
|
| 80 | - * @return array An array with language code => language name pairs. |
|
| 81 | - */ |
|
| 82 | - public static function get_languages() { |
|
| 75 | + /** |
|
| 76 | + * Get the list of WordLift's supported languages in an array with language code => language name pairs. |
|
| 77 | + * |
|
| 78 | + * @since 3.9.0 |
|
| 79 | + * |
|
| 80 | + * @return array An array with language code => language name pairs. |
|
| 81 | + */ |
|
| 82 | + public static function get_languages() { |
|
| 83 | 83 | |
| 84 | - // Lazily load the languages. |
|
| 85 | - if ( null === self::$languages ) { |
|
| 84 | + // Lazily load the languages. |
|
| 85 | + if ( null === self::$languages ) { |
|
| 86 | 86 | |
| 87 | - // Get the language names from WP's own (multisite) function. |
|
| 88 | - foreach ( self::$codes as $key ) { |
|
| 89 | - self::$languages[ $key ] = self::format_code_lang( $key ); |
|
| 90 | - } |
|
| 87 | + // Get the language names from WP's own (multisite) function. |
|
| 88 | + foreach ( self::$codes as $key ) { |
|
| 89 | + self::$languages[ $key ] = self::format_code_lang( $key ); |
|
| 90 | + } |
|
| 91 | 91 | |
| 92 | - // Sort by language name. |
|
| 93 | - asort( self::$languages ); |
|
| 94 | - } |
|
| 92 | + // Sort by language name. |
|
| 93 | + asort( self::$languages ); |
|
| 94 | + } |
|
| 95 | 95 | |
| 96 | - return self::$languages; |
|
| 97 | - } |
|
| 96 | + return self::$languages; |
|
| 97 | + } |
|
| 98 | 98 | |
| 99 | - /** |
|
| 100 | - * Returns the language for a language code. This function is a clone of WP's function provided in `ms.php`. |
|
| 101 | - * |
|
| 102 | - * @since 3.9.3 |
|
| 103 | - * |
|
| 104 | - * @param string $code Optional. The two-letter language code. Default empty. |
|
| 105 | - * |
|
| 106 | - * @return string The language corresponding to $code if it exists. If it does not exist, |
|
| 107 | - * then the first two letters of $code is returned. |
|
| 108 | - */ |
|
| 109 | - private static function format_code_lang( $code = '' ) { |
|
| 110 | - $code = strtolower( substr( $code, 0, 2 ) ); |
|
| 111 | - $lang_codes = array( |
|
| 112 | - 'aa' => 'Afar', |
|
| 113 | - 'ab' => 'Abkhazian', |
|
| 114 | - 'af' => 'Afrikaans', |
|
| 115 | - 'ak' => 'Akan', |
|
| 116 | - 'sq' => 'Albanian', |
|
| 117 | - 'am' => 'Amharic', |
|
| 118 | - 'ar' => 'Arabic', |
|
| 119 | - 'an' => 'Aragonese', |
|
| 120 | - 'hy' => 'Armenian', |
|
| 121 | - 'as' => 'Assamese', |
|
| 122 | - 'av' => 'Avaric', |
|
| 123 | - 'ae' => 'Avestan', |
|
| 124 | - 'ay' => 'Aymara', |
|
| 125 | - 'az' => 'Azerbaijani', |
|
| 126 | - 'ba' => 'Bashkir', |
|
| 127 | - 'bm' => 'Bambara', |
|
| 128 | - 'eu' => 'Basque', |
|
| 129 | - 'be' => 'Belarusian', |
|
| 130 | - 'bn' => 'Bengali', |
|
| 131 | - 'bh' => 'Bihari', |
|
| 132 | - 'bi' => 'Bislama', |
|
| 133 | - 'bs' => 'Bosnian', |
|
| 134 | - 'br' => 'Breton', |
|
| 135 | - 'bg' => 'Bulgarian', |
|
| 136 | - 'my' => 'Burmese', |
|
| 137 | - 'ca' => 'Catalan; Valencian', |
|
| 138 | - 'ch' => 'Chamorro', |
|
| 139 | - 'ce' => 'Chechen', |
|
| 140 | - 'zh' => 'Chinese', |
|
| 141 | - 'cu' => 'Church Slavic; Old Slavonic; Church Slavonic; Old Bulgarian; Old Church Slavonic', |
|
| 142 | - 'cv' => 'Chuvash', |
|
| 143 | - 'kw' => 'Cornish', |
|
| 144 | - 'co' => 'Corsican', |
|
| 145 | - 'cr' => 'Cree', |
|
| 146 | - 'cs' => 'Czech', |
|
| 147 | - 'da' => 'Danish', |
|
| 148 | - 'dv' => 'Divehi; Dhivehi; Maldivian', |
|
| 149 | - 'nl' => 'Dutch; Flemish', |
|
| 150 | - 'dz' => 'Dzongkha', |
|
| 151 | - 'en' => 'English', |
|
| 152 | - 'eo' => 'Esperanto', |
|
| 153 | - 'et' => 'Estonian', |
|
| 154 | - 'ee' => 'Ewe', |
|
| 155 | - 'fo' => 'Faroese', |
|
| 156 | - 'fj' => 'Fijjian', |
|
| 157 | - 'fi' => 'Finnish', |
|
| 158 | - 'fr' => 'French', |
|
| 159 | - 'fy' => 'Western Frisian', |
|
| 160 | - 'ff' => 'Fulah', |
|
| 161 | - 'ka' => 'Georgian', |
|
| 162 | - 'de' => 'German', |
|
| 163 | - 'gd' => 'Gaelic; Scottish Gaelic', |
|
| 164 | - 'ga' => 'Irish', |
|
| 165 | - 'gl' => 'Galician', |
|
| 166 | - 'gv' => 'Manx', |
|
| 167 | - 'el' => 'Greek, Modern', |
|
| 168 | - 'gn' => 'Guarani', |
|
| 169 | - 'gu' => 'Gujarati', |
|
| 170 | - 'ht' => 'Haitian; Haitian Creole', |
|
| 171 | - 'ha' => 'Hausa', |
|
| 172 | - 'he' => 'Hebrew', |
|
| 173 | - 'hz' => 'Herero', |
|
| 174 | - 'hi' => 'Hindi', |
|
| 175 | - 'ho' => 'Hiri Motu', |
|
| 176 | - 'hu' => 'Hungarian', |
|
| 177 | - 'ig' => 'Igbo', |
|
| 178 | - 'is' => 'Icelandic', |
|
| 179 | - 'io' => 'Ido', |
|
| 180 | - 'ii' => 'Sichuan Yi', |
|
| 181 | - 'iu' => 'Inuktitut', |
|
| 182 | - 'ie' => 'Interlingue', |
|
| 183 | - 'ia' => 'Interlingua (International Auxiliary Language Association)', |
|
| 184 | - 'id' => 'Indonesian', |
|
| 185 | - 'ik' => 'Inupiaq', |
|
| 186 | - 'it' => 'Italian', |
|
| 187 | - 'jv' => 'Javanese', |
|
| 188 | - 'ja' => 'Japanese', |
|
| 189 | - 'kl' => 'Kalaallisut; Greenlandic', |
|
| 190 | - 'kn' => 'Kannada', |
|
| 191 | - 'ks' => 'Kashmiri', |
|
| 192 | - 'kr' => 'Kanuri', |
|
| 193 | - 'kk' => 'Kazakh', |
|
| 194 | - 'km' => 'Central Khmer', |
|
| 195 | - 'ki' => 'Kikuyu; Gikuyu', |
|
| 196 | - 'rw' => 'Kinyarwanda', |
|
| 197 | - 'ky' => 'Kirghiz; Kyrgyz', |
|
| 198 | - 'kv' => 'Komi', |
|
| 199 | - 'kg' => 'Kongo', |
|
| 200 | - 'ko' => 'Korean', |
|
| 201 | - 'kj' => 'Kuanyama; Kwanyama', |
|
| 202 | - 'ku' => 'Kurdish', |
|
| 203 | - 'lo' => 'Lao', |
|
| 204 | - 'la' => 'Latin', |
|
| 205 | - 'lv' => 'Latvian', |
|
| 206 | - 'li' => 'Limburgan; Limburger; Limburgish', |
|
| 207 | - 'ln' => 'Lingala', |
|
| 208 | - 'lt' => 'Lithuanian', |
|
| 209 | - 'lb' => 'Luxembourgish; Letzeburgesch', |
|
| 210 | - 'lu' => 'Luba-Katanga', |
|
| 211 | - 'lg' => 'Ganda', |
|
| 212 | - 'mk' => 'Macedonian', |
|
| 213 | - 'mh' => 'Marshallese', |
|
| 214 | - 'ml' => 'Malayalam', |
|
| 215 | - 'mi' => 'Maori', |
|
| 216 | - 'mr' => 'Marathi', |
|
| 217 | - 'ms' => 'Malay', |
|
| 218 | - 'mg' => 'Malagasy', |
|
| 219 | - 'mt' => 'Maltese', |
|
| 220 | - 'mo' => 'Moldavian', |
|
| 221 | - 'mn' => 'Mongolian', |
|
| 222 | - 'na' => 'Nauru', |
|
| 223 | - 'nv' => 'Navajo; Navaho', |
|
| 224 | - 'nr' => 'Ndebele, South; South Ndebele', |
|
| 225 | - 'nd' => 'Ndebele, North; North Ndebele', |
|
| 226 | - 'ng' => 'Ndonga', |
|
| 227 | - 'ne' => 'Nepali', |
|
| 228 | - 'nn' => 'Norwegian Nynorsk; Nynorsk, Norwegian', |
|
| 229 | - 'nb' => 'Bokmål, Norwegian, Norwegian Bokmål', |
|
| 230 | - 'no' => 'Norwegian', |
|
| 231 | - 'ny' => 'Chichewa; Chewa; Nyanja', |
|
| 232 | - 'oc' => 'Occitan, Provençal', |
|
| 233 | - 'oj' => 'Ojibwa', |
|
| 234 | - 'or' => 'Oriya', |
|
| 235 | - 'om' => 'Oromo', |
|
| 236 | - 'os' => 'Ossetian; Ossetic', |
|
| 237 | - 'pa' => 'Panjabi; Punjabi', |
|
| 238 | - 'fa' => 'Persian', |
|
| 239 | - 'pi' => 'Pali', |
|
| 240 | - 'pl' => 'Polish', |
|
| 241 | - 'pt' => 'Portuguese', |
|
| 242 | - 'ps' => 'Pushto', |
|
| 243 | - 'qu' => 'Quechua', |
|
| 244 | - 'rm' => 'Romansh', |
|
| 245 | - 'ro' => 'Romanian', |
|
| 246 | - 'rn' => 'Rundi', |
|
| 247 | - 'ru' => 'Russian', |
|
| 248 | - 'sg' => 'Sango', |
|
| 249 | - 'sa' => 'Sanskrit', |
|
| 250 | - 'sr' => 'Serbian', |
|
| 251 | - 'hr' => 'Croatian', |
|
| 252 | - 'si' => 'Sinhala; Sinhalese', |
|
| 253 | - 'sk' => 'Slovak', |
|
| 254 | - 'sl' => 'Slovenian', |
|
| 255 | - 'se' => 'Northern Sami', |
|
| 256 | - 'sm' => 'Samoan', |
|
| 257 | - 'sn' => 'Shona', |
|
| 258 | - 'sd' => 'Sindhi', |
|
| 259 | - 'so' => 'Somali', |
|
| 260 | - 'st' => 'Sotho, Southern', |
|
| 261 | - 'es' => 'Spanish; Castilian', |
|
| 262 | - 'sc' => 'Sardinian', |
|
| 263 | - 'ss' => 'Swati', |
|
| 264 | - 'su' => 'Sundanese', |
|
| 265 | - 'sw' => 'Swahili', |
|
| 266 | - 'sv' => 'Swedish', |
|
| 267 | - 'ty' => 'Tahitian', |
|
| 268 | - 'ta' => 'Tamil', |
|
| 269 | - 'tt' => 'Tatar', |
|
| 270 | - 'te' => 'Telugu', |
|
| 271 | - 'tg' => 'Tajik', |
|
| 272 | - 'tl' => 'Tagalog', |
|
| 273 | - 'th' => 'Thai', |
|
| 274 | - 'bo' => 'Tibetan', |
|
| 275 | - 'ti' => 'Tigrinya', |
|
| 276 | - 'to' => 'Tonga (Tonga Islands)', |
|
| 277 | - 'tn' => 'Tswana', |
|
| 278 | - 'ts' => 'Tsonga', |
|
| 279 | - 'tk' => 'Turkmen', |
|
| 280 | - 'tr' => 'Turkish', |
|
| 281 | - 'tw' => 'Twi', |
|
| 282 | - 'ug' => 'Uighur; Uyghur', |
|
| 283 | - 'uk' => 'Ukrainian', |
|
| 284 | - 'ur' => 'Urdu', |
|
| 285 | - 'uz' => 'Uzbek', |
|
| 286 | - 've' => 'Venda', |
|
| 287 | - 'vi' => 'Vietnamese', |
|
| 288 | - 'vo' => 'Volapük', |
|
| 289 | - 'cy' => 'Welsh', |
|
| 290 | - 'wa' => 'Walloon', |
|
| 291 | - 'wo' => 'Wolof', |
|
| 292 | - 'xh' => 'Xhosa', |
|
| 293 | - 'yi' => 'Yiddish', |
|
| 294 | - 'yo' => 'Yoruba', |
|
| 295 | - 'za' => 'Zhuang; Chuang', |
|
| 296 | - 'zu' => 'Zulu' |
|
| 297 | - ); |
|
| 99 | + /** |
|
| 100 | + * Returns the language for a language code. This function is a clone of WP's function provided in `ms.php`. |
|
| 101 | + * |
|
| 102 | + * @since 3.9.3 |
|
| 103 | + * |
|
| 104 | + * @param string $code Optional. The two-letter language code. Default empty. |
|
| 105 | + * |
|
| 106 | + * @return string The language corresponding to $code if it exists. If it does not exist, |
|
| 107 | + * then the first two letters of $code is returned. |
|
| 108 | + */ |
|
| 109 | + private static function format_code_lang( $code = '' ) { |
|
| 110 | + $code = strtolower( substr( $code, 0, 2 ) ); |
|
| 111 | + $lang_codes = array( |
|
| 112 | + 'aa' => 'Afar', |
|
| 113 | + 'ab' => 'Abkhazian', |
|
| 114 | + 'af' => 'Afrikaans', |
|
| 115 | + 'ak' => 'Akan', |
|
| 116 | + 'sq' => 'Albanian', |
|
| 117 | + 'am' => 'Amharic', |
|
| 118 | + 'ar' => 'Arabic', |
|
| 119 | + 'an' => 'Aragonese', |
|
| 120 | + 'hy' => 'Armenian', |
|
| 121 | + 'as' => 'Assamese', |
|
| 122 | + 'av' => 'Avaric', |
|
| 123 | + 'ae' => 'Avestan', |
|
| 124 | + 'ay' => 'Aymara', |
|
| 125 | + 'az' => 'Azerbaijani', |
|
| 126 | + 'ba' => 'Bashkir', |
|
| 127 | + 'bm' => 'Bambara', |
|
| 128 | + 'eu' => 'Basque', |
|
| 129 | + 'be' => 'Belarusian', |
|
| 130 | + 'bn' => 'Bengali', |
|
| 131 | + 'bh' => 'Bihari', |
|
| 132 | + 'bi' => 'Bislama', |
|
| 133 | + 'bs' => 'Bosnian', |
|
| 134 | + 'br' => 'Breton', |
|
| 135 | + 'bg' => 'Bulgarian', |
|
| 136 | + 'my' => 'Burmese', |
|
| 137 | + 'ca' => 'Catalan; Valencian', |
|
| 138 | + 'ch' => 'Chamorro', |
|
| 139 | + 'ce' => 'Chechen', |
|
| 140 | + 'zh' => 'Chinese', |
|
| 141 | + 'cu' => 'Church Slavic; Old Slavonic; Church Slavonic; Old Bulgarian; Old Church Slavonic', |
|
| 142 | + 'cv' => 'Chuvash', |
|
| 143 | + 'kw' => 'Cornish', |
|
| 144 | + 'co' => 'Corsican', |
|
| 145 | + 'cr' => 'Cree', |
|
| 146 | + 'cs' => 'Czech', |
|
| 147 | + 'da' => 'Danish', |
|
| 148 | + 'dv' => 'Divehi; Dhivehi; Maldivian', |
|
| 149 | + 'nl' => 'Dutch; Flemish', |
|
| 150 | + 'dz' => 'Dzongkha', |
|
| 151 | + 'en' => 'English', |
|
| 152 | + 'eo' => 'Esperanto', |
|
| 153 | + 'et' => 'Estonian', |
|
| 154 | + 'ee' => 'Ewe', |
|
| 155 | + 'fo' => 'Faroese', |
|
| 156 | + 'fj' => 'Fijjian', |
|
| 157 | + 'fi' => 'Finnish', |
|
| 158 | + 'fr' => 'French', |
|
| 159 | + 'fy' => 'Western Frisian', |
|
| 160 | + 'ff' => 'Fulah', |
|
| 161 | + 'ka' => 'Georgian', |
|
| 162 | + 'de' => 'German', |
|
| 163 | + 'gd' => 'Gaelic; Scottish Gaelic', |
|
| 164 | + 'ga' => 'Irish', |
|
| 165 | + 'gl' => 'Galician', |
|
| 166 | + 'gv' => 'Manx', |
|
| 167 | + 'el' => 'Greek, Modern', |
|
| 168 | + 'gn' => 'Guarani', |
|
| 169 | + 'gu' => 'Gujarati', |
|
| 170 | + 'ht' => 'Haitian; Haitian Creole', |
|
| 171 | + 'ha' => 'Hausa', |
|
| 172 | + 'he' => 'Hebrew', |
|
| 173 | + 'hz' => 'Herero', |
|
| 174 | + 'hi' => 'Hindi', |
|
| 175 | + 'ho' => 'Hiri Motu', |
|
| 176 | + 'hu' => 'Hungarian', |
|
| 177 | + 'ig' => 'Igbo', |
|
| 178 | + 'is' => 'Icelandic', |
|
| 179 | + 'io' => 'Ido', |
|
| 180 | + 'ii' => 'Sichuan Yi', |
|
| 181 | + 'iu' => 'Inuktitut', |
|
| 182 | + 'ie' => 'Interlingue', |
|
| 183 | + 'ia' => 'Interlingua (International Auxiliary Language Association)', |
|
| 184 | + 'id' => 'Indonesian', |
|
| 185 | + 'ik' => 'Inupiaq', |
|
| 186 | + 'it' => 'Italian', |
|
| 187 | + 'jv' => 'Javanese', |
|
| 188 | + 'ja' => 'Japanese', |
|
| 189 | + 'kl' => 'Kalaallisut; Greenlandic', |
|
| 190 | + 'kn' => 'Kannada', |
|
| 191 | + 'ks' => 'Kashmiri', |
|
| 192 | + 'kr' => 'Kanuri', |
|
| 193 | + 'kk' => 'Kazakh', |
|
| 194 | + 'km' => 'Central Khmer', |
|
| 195 | + 'ki' => 'Kikuyu; Gikuyu', |
|
| 196 | + 'rw' => 'Kinyarwanda', |
|
| 197 | + 'ky' => 'Kirghiz; Kyrgyz', |
|
| 198 | + 'kv' => 'Komi', |
|
| 199 | + 'kg' => 'Kongo', |
|
| 200 | + 'ko' => 'Korean', |
|
| 201 | + 'kj' => 'Kuanyama; Kwanyama', |
|
| 202 | + 'ku' => 'Kurdish', |
|
| 203 | + 'lo' => 'Lao', |
|
| 204 | + 'la' => 'Latin', |
|
| 205 | + 'lv' => 'Latvian', |
|
| 206 | + 'li' => 'Limburgan; Limburger; Limburgish', |
|
| 207 | + 'ln' => 'Lingala', |
|
| 208 | + 'lt' => 'Lithuanian', |
|
| 209 | + 'lb' => 'Luxembourgish; Letzeburgesch', |
|
| 210 | + 'lu' => 'Luba-Katanga', |
|
| 211 | + 'lg' => 'Ganda', |
|
| 212 | + 'mk' => 'Macedonian', |
|
| 213 | + 'mh' => 'Marshallese', |
|
| 214 | + 'ml' => 'Malayalam', |
|
| 215 | + 'mi' => 'Maori', |
|
| 216 | + 'mr' => 'Marathi', |
|
| 217 | + 'ms' => 'Malay', |
|
| 218 | + 'mg' => 'Malagasy', |
|
| 219 | + 'mt' => 'Maltese', |
|
| 220 | + 'mo' => 'Moldavian', |
|
| 221 | + 'mn' => 'Mongolian', |
|
| 222 | + 'na' => 'Nauru', |
|
| 223 | + 'nv' => 'Navajo; Navaho', |
|
| 224 | + 'nr' => 'Ndebele, South; South Ndebele', |
|
| 225 | + 'nd' => 'Ndebele, North; North Ndebele', |
|
| 226 | + 'ng' => 'Ndonga', |
|
| 227 | + 'ne' => 'Nepali', |
|
| 228 | + 'nn' => 'Norwegian Nynorsk; Nynorsk, Norwegian', |
|
| 229 | + 'nb' => 'Bokmål, Norwegian, Norwegian Bokmål', |
|
| 230 | + 'no' => 'Norwegian', |
|
| 231 | + 'ny' => 'Chichewa; Chewa; Nyanja', |
|
| 232 | + 'oc' => 'Occitan, Provençal', |
|
| 233 | + 'oj' => 'Ojibwa', |
|
| 234 | + 'or' => 'Oriya', |
|
| 235 | + 'om' => 'Oromo', |
|
| 236 | + 'os' => 'Ossetian; Ossetic', |
|
| 237 | + 'pa' => 'Panjabi; Punjabi', |
|
| 238 | + 'fa' => 'Persian', |
|
| 239 | + 'pi' => 'Pali', |
|
| 240 | + 'pl' => 'Polish', |
|
| 241 | + 'pt' => 'Portuguese', |
|
| 242 | + 'ps' => 'Pushto', |
|
| 243 | + 'qu' => 'Quechua', |
|
| 244 | + 'rm' => 'Romansh', |
|
| 245 | + 'ro' => 'Romanian', |
|
| 246 | + 'rn' => 'Rundi', |
|
| 247 | + 'ru' => 'Russian', |
|
| 248 | + 'sg' => 'Sango', |
|
| 249 | + 'sa' => 'Sanskrit', |
|
| 250 | + 'sr' => 'Serbian', |
|
| 251 | + 'hr' => 'Croatian', |
|
| 252 | + 'si' => 'Sinhala; Sinhalese', |
|
| 253 | + 'sk' => 'Slovak', |
|
| 254 | + 'sl' => 'Slovenian', |
|
| 255 | + 'se' => 'Northern Sami', |
|
| 256 | + 'sm' => 'Samoan', |
|
| 257 | + 'sn' => 'Shona', |
|
| 258 | + 'sd' => 'Sindhi', |
|
| 259 | + 'so' => 'Somali', |
|
| 260 | + 'st' => 'Sotho, Southern', |
|
| 261 | + 'es' => 'Spanish; Castilian', |
|
| 262 | + 'sc' => 'Sardinian', |
|
| 263 | + 'ss' => 'Swati', |
|
| 264 | + 'su' => 'Sundanese', |
|
| 265 | + 'sw' => 'Swahili', |
|
| 266 | + 'sv' => 'Swedish', |
|
| 267 | + 'ty' => 'Tahitian', |
|
| 268 | + 'ta' => 'Tamil', |
|
| 269 | + 'tt' => 'Tatar', |
|
| 270 | + 'te' => 'Telugu', |
|
| 271 | + 'tg' => 'Tajik', |
|
| 272 | + 'tl' => 'Tagalog', |
|
| 273 | + 'th' => 'Thai', |
|
| 274 | + 'bo' => 'Tibetan', |
|
| 275 | + 'ti' => 'Tigrinya', |
|
| 276 | + 'to' => 'Tonga (Tonga Islands)', |
|
| 277 | + 'tn' => 'Tswana', |
|
| 278 | + 'ts' => 'Tsonga', |
|
| 279 | + 'tk' => 'Turkmen', |
|
| 280 | + 'tr' => 'Turkish', |
|
| 281 | + 'tw' => 'Twi', |
|
| 282 | + 'ug' => 'Uighur; Uyghur', |
|
| 283 | + 'uk' => 'Ukrainian', |
|
| 284 | + 'ur' => 'Urdu', |
|
| 285 | + 'uz' => 'Uzbek', |
|
| 286 | + 've' => 'Venda', |
|
| 287 | + 'vi' => 'Vietnamese', |
|
| 288 | + 'vo' => 'Volapük', |
|
| 289 | + 'cy' => 'Welsh', |
|
| 290 | + 'wa' => 'Walloon', |
|
| 291 | + 'wo' => 'Wolof', |
|
| 292 | + 'xh' => 'Xhosa', |
|
| 293 | + 'yi' => 'Yiddish', |
|
| 294 | + 'yo' => 'Yoruba', |
|
| 295 | + 'za' => 'Zhuang; Chuang', |
|
| 296 | + 'zu' => 'Zulu' |
|
| 297 | + ); |
|
| 298 | 298 | |
| 299 | - /** |
|
| 300 | - * Filters the language codes. |
|
| 301 | - * |
|
| 302 | - * @since MU |
|
| 303 | - * |
|
| 304 | - * @param array $lang_codes Key/value pair of language codes where key is the short version. |
|
| 305 | - * @param string $code A two-letter designation of the language. |
|
| 306 | - */ |
|
| 307 | - $lang_codes = apply_filters( 'lang_codes', $lang_codes, $code ); |
|
| 299 | + /** |
|
| 300 | + * Filters the language codes. |
|
| 301 | + * |
|
| 302 | + * @since MU |
|
| 303 | + * |
|
| 304 | + * @param array $lang_codes Key/value pair of language codes where key is the short version. |
|
| 305 | + * @param string $code A two-letter designation of the language. |
|
| 306 | + */ |
|
| 307 | + $lang_codes = apply_filters( 'lang_codes', $lang_codes, $code ); |
|
| 308 | 308 | |
| 309 | - return strtr( $code, $lang_codes ); |
|
| 310 | - } |
|
| 309 | + return strtr( $code, $lang_codes ); |
|
| 310 | + } |
|
| 311 | 311 | |
| 312 | 312 | } |