@@ -9,15 +9,15 @@ discard block |
||
| 9 | 9 | * @since 3.27.6 |
| 10 | 10 | */ |
| 11 | 11 | function wl_ajax_analyze_disabled_action() { |
| 12 | - // adding the below header for debugging purpose. |
|
| 13 | - if ( ! headers_sent() ) { |
|
| 14 | - header( 'X-WordLift-Analysis: OFF' ); |
|
| 15 | - } |
|
| 16 | - wp_send_json_success( array( |
|
| 17 | - 'entities' => array(), |
|
| 18 | - 'annotations' => array(), |
|
| 19 | - 'topics' => array() |
|
| 20 | - ) ); |
|
| 12 | + // adding the below header for debugging purpose. |
|
| 13 | + if ( ! headers_sent() ) { |
|
| 14 | + header( 'X-WordLift-Analysis: OFF' ); |
|
| 15 | + } |
|
| 16 | + wp_send_json_success( array( |
|
| 17 | + 'entities' => array(), |
|
| 18 | + 'annotations' => array(), |
|
| 19 | + 'topics' => array() |
|
| 20 | + ) ); |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | /** |
@@ -31,13 +31,13 @@ discard block |
||
| 31 | 31 | */ |
| 32 | 32 | function wl_ajax_analyze_action() { |
| 33 | 33 | |
| 34 | - check_admin_referer( 'wl_analyze' ); |
|
| 34 | + check_admin_referer( 'wl_analyze' ); |
|
| 35 | 35 | |
| 36 | - // If you use `filter_input` here, `Ajax_Content_Analysis_Test` would fail because `filter_input` doesn't use |
|
| 37 | - // `$_POST`. |
|
| 38 | - $data = $_POST['data']; |
|
| 36 | + // If you use `filter_input` here, `Ajax_Content_Analysis_Test` would fail because `filter_input` doesn't use |
|
| 37 | + // `$_POST`. |
|
| 38 | + $data = $_POST['data']; |
|
| 39 | 39 | |
| 40 | - wp_send_json_success( wl_analyze_content( $data, 'application/json; charset=' . strtolower( get_bloginfo( 'charset' ) ) ) ); |
|
| 40 | + wp_send_json_success( wl_analyze_content( $data, 'application/json; charset=' . strtolower( get_bloginfo( 'charset' ) ) ) ); |
|
| 41 | 41 | |
| 42 | 42 | } |
| 43 | 43 | |
@@ -59,61 +59,61 @@ discard block |
||
| 59 | 59 | */ |
| 60 | 60 | function wl_analyze_content( $data, $content_type ) { |
| 61 | 61 | |
| 62 | - $default_response = json_decode( '{ "entities": {}, "annotations": {}, "topics": {} }' ); |
|
| 63 | - $request_body = json_decode( $data, true ); |
|
| 64 | - $request_body['contentLanguage'] = Wordlift_Configuration_Service::get_instance()->get_language_code(); |
|
| 65 | - $data = wp_json_encode( $request_body ); |
|
| 66 | - |
|
| 67 | - // If dataset is not enabled, return a locally prepared response without analysis API. |
|
| 68 | - if ( ! apply_filters( 'wl_features__enable__dataset', true ) ) { |
|
| 69 | - |
|
| 70 | - return Analysis_Response_Ops_Factory::get_instance() |
|
| 71 | - ->create( $default_response ) |
|
| 72 | - ->make_entities_local() |
|
| 73 | - ->add_occurrences( $request_body['content'] ) |
|
| 74 | - ->add_local_entities() |
|
| 75 | - ->get_json(); |
|
| 76 | - } |
|
| 77 | - |
|
| 78 | - add_filter( 'wl_api_service_api_url_path', 'wl_use_analysis_on_api_wordlift_io' ); |
|
| 79 | - $json = Wordlift_Api_Service::get_instance() |
|
| 80 | - ->post_custom_content_type( 'analysis/single', $data, $content_type ); |
|
| 81 | - remove_filter( 'wl_api_service_api_url_path', 'wl_use_analysis_on_api_wordlift_io' ); |
|
| 82 | - |
|
| 83 | - // If it's an error log it. |
|
| 84 | - if ( is_wp_error( $json ) ) { |
|
| 85 | - |
|
| 86 | - return Analysis_Response_Ops_Factory::get_instance() |
|
| 87 | - ->create( $default_response ) |
|
| 88 | - ->make_entities_local() |
|
| 89 | - ->add_occurrences( $request_body['content'] ) |
|
| 90 | - ->get_json(); |
|
| 91 | - } |
|
| 92 | - |
|
| 93 | - /* |
|
| 62 | + $default_response = json_decode( '{ "entities": {}, "annotations": {}, "topics": {} }' ); |
|
| 63 | + $request_body = json_decode( $data, true ); |
|
| 64 | + $request_body['contentLanguage'] = Wordlift_Configuration_Service::get_instance()->get_language_code(); |
|
| 65 | + $data = wp_json_encode( $request_body ); |
|
| 66 | + |
|
| 67 | + // If dataset is not enabled, return a locally prepared response without analysis API. |
|
| 68 | + if ( ! apply_filters( 'wl_features__enable__dataset', true ) ) { |
|
| 69 | + |
|
| 70 | + return Analysis_Response_Ops_Factory::get_instance() |
|
| 71 | + ->create( $default_response ) |
|
| 72 | + ->make_entities_local() |
|
| 73 | + ->add_occurrences( $request_body['content'] ) |
|
| 74 | + ->add_local_entities() |
|
| 75 | + ->get_json(); |
|
| 76 | + } |
|
| 77 | + |
|
| 78 | + add_filter( 'wl_api_service_api_url_path', 'wl_use_analysis_on_api_wordlift_io' ); |
|
| 79 | + $json = Wordlift_Api_Service::get_instance() |
|
| 80 | + ->post_custom_content_type( 'analysis/single', $data, $content_type ); |
|
| 81 | + remove_filter( 'wl_api_service_api_url_path', 'wl_use_analysis_on_api_wordlift_io' ); |
|
| 82 | + |
|
| 83 | + // If it's an error log it. |
|
| 84 | + if ( is_wp_error( $json ) ) { |
|
| 85 | + |
|
| 86 | + return Analysis_Response_Ops_Factory::get_instance() |
|
| 87 | + ->create( $default_response ) |
|
| 88 | + ->make_entities_local() |
|
| 89 | + ->add_occurrences( $request_body['content'] ) |
|
| 90 | + ->get_json(); |
|
| 91 | + } |
|
| 92 | + |
|
| 93 | + /* |
|
| 94 | 94 | * We pass the response to the Analysis_Response_Ops to ensure that we make remote entities local. |
| 95 | 95 | * |
| 96 | 96 | * @see https://github.com/insideout10/wordlift-plugin/issues/944 |
| 97 | 97 | * @since 3.21.5 |
| 98 | 98 | */ |
| 99 | 99 | |
| 100 | - // Get the actual content sent to the analysis, so that we can pass it to the Analysis_Response_Ops to populate |
|
| 101 | - // the occurrences for the local entities. |
|
| 102 | - if ( 0 === strpos( $content_type, 'application/json' ) ) { |
|
| 103 | - $request_content = $request_body['content']; |
|
| 104 | - } else { |
|
| 105 | - $request_content = $data; |
|
| 106 | - } |
|
| 100 | + // Get the actual content sent to the analysis, so that we can pass it to the Analysis_Response_Ops to populate |
|
| 101 | + // the occurrences for the local entities. |
|
| 102 | + if ( 0 === strpos( $content_type, 'application/json' ) ) { |
|
| 103 | + $request_content = $request_body['content']; |
|
| 104 | + } else { |
|
| 105 | + $request_content = $data; |
|
| 106 | + } |
|
| 107 | 107 | |
| 108 | - return Analysis_Response_Ops_Factory::get_instance() |
|
| 109 | - ->create( $json ) |
|
| 110 | - ->make_entities_local() |
|
| 111 | - ->add_occurrences( $request_content ) |
|
| 112 | - ->get_json(); |
|
| 108 | + return Analysis_Response_Ops_Factory::get_instance() |
|
| 109 | + ->create( $json ) |
|
| 110 | + ->make_entities_local() |
|
| 111 | + ->add_occurrences( $request_content ) |
|
| 112 | + ->get_json(); |
|
| 113 | 113 | |
| 114 | 114 | } |
| 115 | 115 | |
| 116 | 116 | function wl_use_analysis_on_api_wordlift_io( $value ) { |
| 117 | 117 | |
| 118 | - return preg_replace( '|https://api\.wordlift\.it/|', apply_filters( 'wl_api_base_url', 'https://api.wordlift.io' ) . '/', $value ); |
|
| 118 | + return preg_replace( '|https://api\.wordlift\.it/|', apply_filters( 'wl_api_base_url', 'https://api.wordlift.io' ) . '/', $value ); |
|
| 119 | 119 | } |
@@ -10,14 +10,14 @@ discard block |
||
| 10 | 10 | */ |
| 11 | 11 | function wl_ajax_analyze_disabled_action() { |
| 12 | 12 | // adding the below header for debugging purpose. |
| 13 | - if ( ! headers_sent() ) { |
|
| 14 | - header( 'X-WordLift-Analysis: OFF' ); |
|
| 13 | + if ( ! headers_sent()) { |
|
| 14 | + header('X-WordLift-Analysis: OFF'); |
|
| 15 | 15 | } |
| 16 | - wp_send_json_success( array( |
|
| 16 | + wp_send_json_success(array( |
|
| 17 | 17 | 'entities' => array(), |
| 18 | 18 | 'annotations' => array(), |
| 19 | 19 | 'topics' => array() |
| 20 | - ) ); |
|
| 20 | + )); |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | /** |
@@ -31,13 +31,13 @@ discard block |
||
| 31 | 31 | */ |
| 32 | 32 | function wl_ajax_analyze_action() { |
| 33 | 33 | |
| 34 | - check_admin_referer( 'wl_analyze' ); |
|
| 34 | + check_admin_referer('wl_analyze'); |
|
| 35 | 35 | |
| 36 | 36 | // If you use `filter_input` here, `Ajax_Content_Analysis_Test` would fail because `filter_input` doesn't use |
| 37 | 37 | // `$_POST`. |
| 38 | 38 | $data = $_POST['data']; |
| 39 | 39 | |
| 40 | - wp_send_json_success( wl_analyze_content( $data, 'application/json; charset=' . strtolower( get_bloginfo( 'charset' ) ) ) ); |
|
| 40 | + wp_send_json_success(wl_analyze_content($data, 'application/json; charset='.strtolower(get_bloginfo('charset')))); |
|
| 41 | 41 | |
| 42 | 42 | } |
| 43 | 43 | |
@@ -57,36 +57,36 @@ discard block |
||
| 57 | 57 | * @since 3.24.2 We don't return an error anymore, but an empty analysis response. This is required to allow the editor |
| 58 | 58 | * to manage entities or to manually add them even when analysis isn't available. |
| 59 | 59 | */ |
| 60 | -function wl_analyze_content( $data, $content_type ) { |
|
| 60 | +function wl_analyze_content($data, $content_type) { |
|
| 61 | 61 | |
| 62 | - $default_response = json_decode( '{ "entities": {}, "annotations": {}, "topics": {} }' ); |
|
| 63 | - $request_body = json_decode( $data, true ); |
|
| 62 | + $default_response = json_decode('{ "entities": {}, "annotations": {}, "topics": {} }'); |
|
| 63 | + $request_body = json_decode($data, true); |
|
| 64 | 64 | $request_body['contentLanguage'] = Wordlift_Configuration_Service::get_instance()->get_language_code(); |
| 65 | - $data = wp_json_encode( $request_body ); |
|
| 65 | + $data = wp_json_encode($request_body); |
|
| 66 | 66 | |
| 67 | 67 | // If dataset is not enabled, return a locally prepared response without analysis API. |
| 68 | - if ( ! apply_filters( 'wl_features__enable__dataset', true ) ) { |
|
| 68 | + if ( ! apply_filters('wl_features__enable__dataset', true)) { |
|
| 69 | 69 | |
| 70 | 70 | return Analysis_Response_Ops_Factory::get_instance() |
| 71 | - ->create( $default_response ) |
|
| 71 | + ->create($default_response) |
|
| 72 | 72 | ->make_entities_local() |
| 73 | - ->add_occurrences( $request_body['content'] ) |
|
| 73 | + ->add_occurrences($request_body['content']) |
|
| 74 | 74 | ->add_local_entities() |
| 75 | 75 | ->get_json(); |
| 76 | 76 | } |
| 77 | 77 | |
| 78 | - add_filter( 'wl_api_service_api_url_path', 'wl_use_analysis_on_api_wordlift_io' ); |
|
| 78 | + add_filter('wl_api_service_api_url_path', 'wl_use_analysis_on_api_wordlift_io'); |
|
| 79 | 79 | $json = Wordlift_Api_Service::get_instance() |
| 80 | - ->post_custom_content_type( 'analysis/single', $data, $content_type ); |
|
| 81 | - remove_filter( 'wl_api_service_api_url_path', 'wl_use_analysis_on_api_wordlift_io' ); |
|
| 80 | + ->post_custom_content_type('analysis/single', $data, $content_type); |
|
| 81 | + remove_filter('wl_api_service_api_url_path', 'wl_use_analysis_on_api_wordlift_io'); |
|
| 82 | 82 | |
| 83 | 83 | // If it's an error log it. |
| 84 | - if ( is_wp_error( $json ) ) { |
|
| 84 | + if (is_wp_error($json)) { |
|
| 85 | 85 | |
| 86 | 86 | return Analysis_Response_Ops_Factory::get_instance() |
| 87 | - ->create( $default_response ) |
|
| 87 | + ->create($default_response) |
|
| 88 | 88 | ->make_entities_local() |
| 89 | - ->add_occurrences( $request_body['content'] ) |
|
| 89 | + ->add_occurrences($request_body['content']) |
|
| 90 | 90 | ->get_json(); |
| 91 | 91 | } |
| 92 | 92 | |
@@ -99,21 +99,21 @@ discard block |
||
| 99 | 99 | |
| 100 | 100 | // Get the actual content sent to the analysis, so that we can pass it to the Analysis_Response_Ops to populate |
| 101 | 101 | // the occurrences for the local entities. |
| 102 | - if ( 0 === strpos( $content_type, 'application/json' ) ) { |
|
| 102 | + if (0 === strpos($content_type, 'application/json')) { |
|
| 103 | 103 | $request_content = $request_body['content']; |
| 104 | 104 | } else { |
| 105 | 105 | $request_content = $data; |
| 106 | 106 | } |
| 107 | 107 | |
| 108 | 108 | return Analysis_Response_Ops_Factory::get_instance() |
| 109 | - ->create( $json ) |
|
| 109 | + ->create($json) |
|
| 110 | 110 | ->make_entities_local() |
| 111 | - ->add_occurrences( $request_content ) |
|
| 111 | + ->add_occurrences($request_content) |
|
| 112 | 112 | ->get_json(); |
| 113 | 113 | |
| 114 | 114 | } |
| 115 | 115 | |
| 116 | -function wl_use_analysis_on_api_wordlift_io( $value ) { |
|
| 116 | +function wl_use_analysis_on_api_wordlift_io($value) { |
|
| 117 | 117 | |
| 118 | - return preg_replace( '|https://api\.wordlift\.it/|', apply_filters( 'wl_api_base_url', 'https://api.wordlift.io' ) . '/', $value ); |
|
| 118 | + return preg_replace('|https://api\.wordlift\.it/|', apply_filters('wl_api_base_url', 'https://api.wordlift.io').'/', $value); |
|
| 119 | 119 | } |