Completed
Push — master ( faee41...e921e2 )
by David
02:42
created
src/modules/analyzer/wordlift_analyzer.php 2 patches
Indentation   +32 added lines, -32 removed lines patch added patch discarded remove patch
@@ -14,11 +14,11 @@  discard block
 block discarded – undo
14 14
  */
15 15
 function wl_ajax_analyze_action() {
16 16
 
17
-	check_admin_referer( 'wl_analyze' );
17
+    check_admin_referer( 'wl_analyze' );
18 18
 
19
-	$data = filter_input( INPUT_POST, 'data' );
19
+    $data = filter_input( INPUT_POST, 'data' );
20 20
 
21
-	wp_send_json_success( wl_analyze_content( $data, 'application/json; charset=' . get_bloginfo( 'charset' ) ) );
21
+    wp_send_json_success( wl_analyze_content( $data, 'application/json; charset=' . get_bloginfo( 'charset' ) ) );
22 22
 
23 23
 }
24 24
 
@@ -45,47 +45,47 @@  discard block
 block discarded – undo
45 45
 //	// Set the content type to the request content type or to text/plain by default.
46 46
 //	$content_type = isset( $_SERVER['CONTENT_TYPE'] ) ? $_SERVER['CONTENT_TYPE'] : 'text/plain';
47 47
 
48
-	add_filter( 'wl_api_service_api_url_path', 'wl_use_analysis_on_api_wordlift_io' );
49
-	$json = Wordlift_Api_Service::get_instance()
50
-	                            ->post_custom_content_type( 'analysis/single', $data, $content_type );
51
-	remove_filter( 'wl_api_service_api_url_path', 'wl_use_analysis_on_api_wordlift_io' );
48
+    add_filter( 'wl_api_service_api_url_path', 'wl_use_analysis_on_api_wordlift_io' );
49
+    $json = Wordlift_Api_Service::get_instance()
50
+                                ->post_custom_content_type( 'analysis/single', $data, $content_type );
51
+    remove_filter( 'wl_api_service_api_url_path', 'wl_use_analysis_on_api_wordlift_io' );
52 52
 
53
-	// If it's an error log it.
54
-	if ( is_wp_error( $json ) ) {
55
-		$request_body = json_decode( $data, true );
53
+    // If it's an error log it.
54
+    if ( is_wp_error( $json ) ) {
55
+        $request_body = json_decode( $data, true );
56 56
 
57
-		return Analysis_Response_Ops_Factory::get_instance()
58
-		                                    ->create( json_decode( '{ "entities": {}, "annotations": {}, "topics": {} }' ) )
59
-		                                    ->make_entities_local()
60
-		                                    ->add_occurrences( $request_body['content'] )
61
-		                                    ->get_json();
62
-	}
57
+        return Analysis_Response_Ops_Factory::get_instance()
58
+                                            ->create( json_decode( '{ "entities": {}, "annotations": {}, "topics": {} }' ) )
59
+                                            ->make_entities_local()
60
+                                            ->add_occurrences( $request_body['content'] )
61
+                                            ->get_json();
62
+    }
63 63
 
64
-	/*
64
+    /*
65 65
 	 * We pass the response to the Analysis_Response_Ops to ensure that we make remote entities local.
66 66
 	 *
67 67
 	 * @see https://github.com/insideout10/wordlift-plugin/issues/944
68 68
 	 * @since 3.21.5
69 69
 	 */
70 70
 
71
-	// Get the actual content sent to the analysis, so that we can pass it to the Analysis_Response_Ops to populate
72
-	// the occurrences for the local entities.
73
-	if ( 0 === strpos( $content_type, 'application/json' ) ) {
74
-		$request_json    = json_decode( $data );
75
-		$request_content = $request_json->content;
76
-	} else {
77
-		$request_content = $data;
78
-	}
79
-
80
-	return Analysis_Response_Ops_Factory::get_instance()
81
-	                                    ->create( $json )
82
-	                                    ->make_entities_local()
83
-	                                    ->add_occurrences( $request_content )
84
-	                                    ->get_json();
71
+    // Get the actual content sent to the analysis, so that we can pass it to the Analysis_Response_Ops to populate
72
+    // the occurrences for the local entities.
73
+    if ( 0 === strpos( $content_type, 'application/json' ) ) {
74
+        $request_json    = json_decode( $data );
75
+        $request_content = $request_json->content;
76
+    } else {
77
+        $request_content = $data;
78
+    }
79
+
80
+    return Analysis_Response_Ops_Factory::get_instance()
81
+                                        ->create( $json )
82
+                                        ->make_entities_local()
83
+                                        ->add_occurrences( $request_content )
84
+                                        ->get_json();
85 85
 
86 86
 }
87 87
 
88 88
 function wl_use_analysis_on_api_wordlift_io( $value ) {
89 89
 
90
-	return preg_replace( '|https://api\.wordlift\.it/|', 'https://api.wordlift.io/', $value );
90
+    return preg_replace( '|https://api\.wordlift\.it/|', 'https://api.wordlift.io/', $value );
91 91
 }
Please login to merge, or discard this patch.
Spacing   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -14,15 +14,15 @@  discard block
 block discarded – undo
14 14
  */
15 15
 function wl_ajax_analyze_action() {
16 16
 
17
-	check_admin_referer( 'wl_analyze' );
17
+	check_admin_referer('wl_analyze');
18 18
 
19
-	$data = filter_input( INPUT_POST, 'data' );
19
+	$data = filter_input(INPUT_POST, 'data');
20 20
 
21
-	wp_send_json_success( wl_analyze_content( $data, 'application/json; charset=' . get_bloginfo( 'charset' ) ) );
21
+	wp_send_json_success(wl_analyze_content($data, 'application/json; charset='.get_bloginfo('charset')));
22 22
 
23 23
 }
24 24
 
25
-add_action( 'wp_ajax_wl_analyze', 'wl_ajax_analyze_action' );
25
+add_action('wp_ajax_wl_analyze', 'wl_ajax_analyze_action');
26 26
 
27 27
 /**
28 28
  * Analyze the provided content. The analysis will make use of the method *wl_ajax_analyze_action*
@@ -40,24 +40,24 @@  discard block
 block discarded – undo
40 40
  * @since 3.24.2 We don't return an error anymore, but an empty analysis response. This is required to allow the editor
41 41
  *   to manage entities or to manually add them even when analysis isn't available.
42 42
  */
43
-function wl_analyze_content( $data, $content_type ) {
43
+function wl_analyze_content($data, $content_type) {
44 44
 
45 45
 //	// Set the content type to the request content type or to text/plain by default.
46 46
 //	$content_type = isset( $_SERVER['CONTENT_TYPE'] ) ? $_SERVER['CONTENT_TYPE'] : 'text/plain';
47 47
 
48
-	add_filter( 'wl_api_service_api_url_path', 'wl_use_analysis_on_api_wordlift_io' );
48
+	add_filter('wl_api_service_api_url_path', 'wl_use_analysis_on_api_wordlift_io');
49 49
 	$json = Wordlift_Api_Service::get_instance()
50
-	                            ->post_custom_content_type( 'analysis/single', $data, $content_type );
51
-	remove_filter( 'wl_api_service_api_url_path', 'wl_use_analysis_on_api_wordlift_io' );
50
+	                            ->post_custom_content_type('analysis/single', $data, $content_type);
51
+	remove_filter('wl_api_service_api_url_path', 'wl_use_analysis_on_api_wordlift_io');
52 52
 
53 53
 	// If it's an error log it.
54
-	if ( is_wp_error( $json ) ) {
55
-		$request_body = json_decode( $data, true );
54
+	if (is_wp_error($json)) {
55
+		$request_body = json_decode($data, true);
56 56
 
57 57
 		return Analysis_Response_Ops_Factory::get_instance()
58
-		                                    ->create( json_decode( '{ "entities": {}, "annotations": {}, "topics": {} }' ) )
58
+		                                    ->create(json_decode('{ "entities": {}, "annotations": {}, "topics": {} }'))
59 59
 		                                    ->make_entities_local()
60
-		                                    ->add_occurrences( $request_body['content'] )
60
+		                                    ->add_occurrences($request_body['content'])
61 61
 		                                    ->get_json();
62 62
 	}
63 63
 
@@ -70,22 +70,22 @@  discard block
 block discarded – undo
70 70
 
71 71
 	// Get the actual content sent to the analysis, so that we can pass it to the Analysis_Response_Ops to populate
72 72
 	// the occurrences for the local entities.
73
-	if ( 0 === strpos( $content_type, 'application/json' ) ) {
74
-		$request_json    = json_decode( $data );
73
+	if (0 === strpos($content_type, 'application/json')) {
74
+		$request_json    = json_decode($data);
75 75
 		$request_content = $request_json->content;
76 76
 	} else {
77 77
 		$request_content = $data;
78 78
 	}
79 79
 
80 80
 	return Analysis_Response_Ops_Factory::get_instance()
81
-	                                    ->create( $json )
81
+	                                    ->create($json)
82 82
 	                                    ->make_entities_local()
83
-	                                    ->add_occurrences( $request_content )
83
+	                                    ->add_occurrences($request_content)
84 84
 	                                    ->get_json();
85 85
 
86 86
 }
87 87
 
88
-function wl_use_analysis_on_api_wordlift_io( $value ) {
88
+function wl_use_analysis_on_api_wordlift_io($value) {
89 89
 
90
-	return preg_replace( '|https://api\.wordlift\.it/|', 'https://api.wordlift.io/', $value );
90
+	return preg_replace('|https://api\.wordlift\.it/|', 'https://api.wordlift.io/', $value);
91 91
 }
Please login to merge, or discard this patch.