From 7ea82756fa83189e36ee71c05285ac1347497f9c Mon Sep 17 00:00:00 2001 From: Sudipto Shakhari Date: Thu, 3 Feb 2022 16:34:05 +0600 Subject: [PATCH] Update campaign id and text domain.Refer to issue #147 --- includes/action-functions.php | 88 +++++++++---------- includes/admin/class-wpcp-help.php | 10 +-- includes/admin/metabox-functions.php | 16 ++-- .../admin/views/metabox/advanced-settings.php | 8 +- includes/admin/views/page/help-page.php | 10 +-- includes/class-wpcp-logger.php | 2 +- includes/class-wpcp-module.php | 13 ++- includes/core-functions.php | 6 +- includes/modules/class-wpcp-article.php | 6 +- includes/modules/class-wpcp-flickr.php | 2 + includes/modules/class-wpcp-youtube.php | 2 +- 11 files changed, 82 insertions(+), 81 deletions(-) diff --git a/includes/action-functions.php b/includes/action-functions.php index 8cb10a7..37e671a 100644 --- a/includes/action-functions.php +++ b/includes/action-functions.php @@ -6,43 +6,43 @@ function wpcp_handle_manual_campaign() { if ( ! wp_verify_nonce( $_REQUEST['nonce'], 'wpcp_run_campaign' ) ) { wp_die( __( 'No Cheating', 'wp-content-pilot' ) ); } - + $campaign_id = intval( $_REQUEST['campaign_id'] ); - - + + $target = wpcp_get_post_meta( $campaign_id, '_campaign_target', 0 ); $posted = wpcp_get_post_meta( $campaign_id, '_post_count', 0 ); $edit_link = admin_url( sprintf( 'post.php?post=%d&action=edit', $campaign_id ) ); - + $campaign_post = get_post( $campaign_id ); - + if ( empty( $campaign_post ) || 'wp_content_pilot' !== $campaign_post->post_type ) { wp_die( __( 'Invalid post action', 'wp-content-pilot' ) ); } - + $campaign_type = wpcp_get_post_meta( $campaign_id, '_campaign_type', 'feed' ); - + if ( $posted >= $target ) { wpcp_disable_campaign( $campaign_id ); wpcp_admin_notice( 'Campaign reached its targeted posts, automatically disabled.', 'error' ); wp_safe_redirect( $edit_link ); exit(); } - + $article_id = content_pilot()->modules()->load( $campaign_type )->process_campaign( $campaign_id, '', 'user' ); - + if ( is_wp_error( $article_id ) ) { wpcp_admin_notice( $article_id->get_error_message(), 'error' ); wp_safe_redirect( $edit_link ); exit(); } - + $title = empty( get_the_title( $article_id ) ) ? 'Untitled' : get_the_title( $article_id ); $article_title = '' . $title . ''; $message = sprintf( __( 'A post successfully created by %s titled %s', 'wp-content-pilot' ), '' . get_the_title( $campaign_id ) . '', $article_title ); wpcp_admin_notice( $message ); - - + + wp_safe_redirect( $edit_link ); exit(); } @@ -61,20 +61,20 @@ function wpcp_run_automatic_campaign() { global $wpdb; $sql = "select * from {$wpdb->posts} p left join {$wpdb->postmeta} m on p.id = m.post_id having m.meta_key = '_campaign_status' AND m.meta_value = 'active' AND p.post_status <> 'trash'"; $campaigns = $wpdb->get_results( $sql ); - + if ( empty( $campaigns ) ) { return; } - - + + $campaigns = wp_list_pluck( $campaigns, 'ID' ); - + $last_campaign = get_option( 'wpcp_last_ran_campaign', '' ); if ( ! empty( $last_campaign ) && count( $campaigns ) > 1 ) { unset( $campaigns[ $last_campaign ] ); } - - + + if ( ! empty( $campaigns ) ) { // $automatic_campaign = new WPCP_Automatic_Campaign(); foreach ( $campaigns as $campaign_id ) { @@ -87,20 +87,20 @@ function wpcp_run_automatic_campaign() { if ( $diff < $frequency ) { continue; } - + if ( $posted >= $target ) { wpcp_logger()->info( __( 'Reached campaign post limit. So campaign stopping publish new post', 'wp-content-pilot' ), $campaign_id ); wpcp_disable_campaign( $campaign_id ); continue; } - + $campaign_type = wpcp_get_post_meta( $campaign_id, '_campaign_type', '' ); if ( ! empty( $campaign_type ) ) { content_pilot()->modules()->load( $campaign_type )->process_campaign( $campaign_id, '', 'cron' ); } } } - + } add_action( 'wpcp_per_minute_scheduled_events', 'wpcp_run_automatic_campaign' ); @@ -112,28 +112,28 @@ function wpcp_delete_all_campaign_posts() { if ( ! isset( $_REQUEST['nonce'] ) || ! isset( $_REQUEST['camp_id'] ) || ! wp_verify_nonce( $_REQUEST['nonce'], 'wpcp_delete_posts' ) ) { wp_send_json_error( 'Unauthorized!!!' ); } - + $camp_id = isset( $_REQUEST['camp_id'] ) && ! empty( $_REQUEST['camp_id'] ) ? $_REQUEST['camp_id'] : false; if ( ! $camp_id ) { wp_send_json_error( 'Invalid campaign ID.' ); } - + $args = array( 'meta_key' => '_campaign_id', 'meta_value' => $camp_id, 'posts_per_page' => - 1, 'post_type' => wpcp_get_post_meta( $camp_id, '_post_type', 'post' ), - + ); - + $posts = wpcp_get_posts( $args ); - + if ( is_array( $posts ) && count( $posts ) ) { foreach ( $posts as $post ) { wp_delete_post( $post->ID, true ); } } - + wp_send_json_success( 'Done' ); } @@ -143,7 +143,7 @@ function wpcp_clear_logs() { if ( ! isset( $_REQUEST['nonce'] ) || ! wp_verify_nonce( $_REQUEST['nonce'], 'wpcp_clear_logs' ) ) { wp_send_json_error( 'Unauthorized!!!' ); } - + global $wpdb; $wpdb->query( "TRUNCATE TABLE $wpdb->wpcp_logs" ); wp_send_json_success( 'success' ); @@ -156,7 +156,7 @@ function wpcp_clear_logs() { if ( ! function_exists( 'wpcp_pro_get_keyword_suggestion' ) ): function wpcp_pro_get_keyword_suggestion() { $word = $_REQUEST['input']; - + $curl = new Curl\Curl(); $curl->setOpt( CURLOPT_FOLLOWLOCATION, true ); $curl->setOpt( CURLOPT_TIMEOUT, 30 ); @@ -169,7 +169,7 @@ function wpcp_pro_get_keyword_suggestion() { 'q' => $word, 'client' => 'firefox', ) ); - + if ( is_wp_error( $curl->isError() ) ) { wp_send_json_success( [] ); } @@ -187,7 +187,7 @@ function wpcp_pro_get_keyword_suggestion() { // } } } - + $suggestion = array_unique( $suggestion ); wp_send_json_success( $suggestion ); } @@ -221,7 +221,7 @@ function wpcp_post_publish_mail_notification( $post_id, $campaign_id, $article ) } else { $excerpt = $article['excerpt']; } - + $post_link = get_the_permalink( $post_id ); $subject = __( 'Post Publish', 'wp-content-pilot' ); $body = sprintf( "

Post Title: %s

@@ -230,7 +230,7 @@ function wpcp_post_publish_mail_notification( $post_id, $campaign_id, $article ) View Post", esc_html( $title ), $excerpt, esc_url( $post_link ) ); $headers = array( 'Content-Type: text/html; charset=UTF-8' ); - + wp_mail( $to, $subject, $body, $headers ); } @@ -260,13 +260,13 @@ function wpcp_campaign_reset_search_campaign() { if ( ! wp_verify_nonce( $_REQUEST['nonce'], 'wpcp_campaign_reset_search' ) ) { wp_die( __( 'No Cheating', 'wp-content-pilot' ) ); } - + $campaign_id = intval( $_REQUEST['campaign_id'] ); - + $delete_query = "DELETE FROM {$wpdb->postmeta} where post_id=$campaign_id AND meta_key NOT IN ('_post_count','_campaign_type','_post_status','_campaign_target','_last_run','_last_post')"; - + $clear_query = "DELETE FROM {$wpdb->wpcp_links} where camp_id=$campaign_id"; - + $wpdb->query( $delete_query ); $wpdb->query( $clear_query ); wp_safe_redirect( get_edit_post_link( $campaign_id, 'edit' ) ); @@ -282,13 +282,13 @@ function wpcp_ajax_run_manual_campaign() { 'time' => date( 'H:i:s', current_time( 'timestamp' ) ) ] ); } - + $campaign_id = intval( $_REQUEST['campaign_id'] ); $instance = intval( $_REQUEST['instance'] ); if ( ! defined( 'WPCP_CAMPAIGN_INSTANCE' ) ) { define( 'WPCP_CAMPAIGN_INSTANCE', $instance ); } - + $campaign_post = get_post( $campaign_id ); if ( empty( $campaign_post ) || 'wp_content_pilot' !== $campaign_post->post_type ) { wp_send_json( [ @@ -297,12 +297,12 @@ function wpcp_ajax_run_manual_campaign() { 'time' => date( 'H:i:s', current_time( 'timestamp' ) ) ] ); } - + global $current_user; - wpcp_logger()->info( sprintf( __( 'Campaign %s manually initiated by %s', 'wp-content-pilot' ), get_the_title( $campaign_id ), $current_user->display_name ) ); - + wpcp_logger()->info( sprintf( __( 'Campaign %s manually initiated by %s', 'wp-content-pilot' ), get_the_title( $campaign_id ), $current_user->display_name ), $campaign_id ); + $campaign_type = wpcp_get_post_meta( $campaign_id, '_campaign_type', 'feed' ); - + $article_id = content_pilot()->modules()->load( $campaign_type )->process_campaign( $campaign_id, '', 'user' ); if ( is_wp_error( $article_id ) ) { wp_send_json( [ @@ -346,7 +346,7 @@ function wpcp_get_campaign_instance_log() { ] ] ); } - + global $wpdb; $data = $wpdb->get_results( "select `level`, message, DATE_FORMAT(created_at, '%H:%i:%s') as time from {$wpdb->prefix}wpcp_logs where instance_id={$instance} order by id ASC limit 9999 offset {$offset}" ); wp_send_json( $data ); diff --git a/includes/admin/class-wpcp-help.php b/includes/admin/class-wpcp-help.php index c45a73d..17666c4 100644 --- a/includes/admin/class-wpcp-help.php +++ b/includes/admin/class-wpcp-help.php @@ -123,7 +123,7 @@ public function help_page() {
-

WP Content Pilot - Help

+

@@ -140,12 +140,12 @@ public function help_page() {
-

Are you looking for more? Checkout our Pro Version.

+

- - - + + + diff --git a/includes/admin/metabox-functions.php b/includes/admin/metabox-functions.php index 314395a..ba8e60c 100644 --- a/includes/admin/metabox-functions.php +++ b/includes/admin/metabox-functions.php @@ -361,13 +361,13 @@ function wpcp_target_rel_field() { function wpcp_search_replace_metafield( $post ) { ?>
- +
FeaturesFreePro
- - + + @@ -379,7 +379,7 @@ function wpcp_search_replace_metafield( $post ) {
SearchReplace
- +
- + - - + + @@ -409,7 +409,7 @@ function wpcp_post_meta_metafield( $post ) {
Meta KeyMeta Value
- +
__( 'Limit Title', 'wp-content-pilot' ), 'type' => 'number', 'name' => '_title_limit', - 'tooltip' => 'Input the number of words to limit the title. Default full title.', + 'tooltip' => __( 'Input the number of words to limit the title. Default full title.', 'wp-content-pilot' ) ) ); echo WPCP_HTML::text_input( array( 'label' => __( 'Limit Content', 'wp-content-pilot' ), 'type' => 'number', 'name' => '_content_limit', - 'tooltip' => 'Input the number of words to limit content. Default full content.', + 'tooltip' => __( 'Input the number of words to limit content. Default full content.', 'wp-content-pilot' ) ) ); echo WPCP_HTML::text_input( array( @@ -36,8 +36,8 @@ 'wrapper_class' => 'pro', 'options' => array( '' => __( 'No Translation', 'wp-content-pilot' ), - 'yandex' => 'Yandex', - 'deepl' => 'deepL', + 'yandex' => __( 'Yandex', 'wp-content-pilot' ), + 'deepl' => __( 'deepL', 'wp-content-pilot' ) ), 'attrs' => array( 'disabled' => 'disabled', diff --git a/includes/admin/views/page/help-page.php b/includes/admin/views/page/help-page.php index dca9f4e..671d51e 100644 --- a/includes/admin/views/page/help-page.php +++ b/includes/admin/views/page/help-page.php @@ -306,7 +306,7 @@
-

WP Content Pilot - Help

+

@@ -323,12 +323,12 @@
-

Are you looking for more? Checkout our Pro Version.

+

- - - + + + diff --git a/includes/class-wpcp-logger.php b/includes/class-wpcp-logger.php index 7b3aad5..fdbda30 100644 --- a/includes/class-wpcp-logger.php +++ b/includes/class-wpcp-logger.php @@ -104,7 +104,7 @@ public function warning( $message, $campaign_id = 0 ) { * @return void */ public function error( $message, $campaign_id = 0 ) { - $this->writeLog( $message, 'ERROR', $campaign_id = 0 ); + $this->writeLog( $message, 'ERROR', $campaign_id ); } /** diff --git a/includes/class-wpcp-module.php b/includes/class-wpcp-module.php index 0928a91..a92cb70 100644 --- a/includes/class-wpcp-module.php +++ b/includes/class-wpcp-module.php @@ -141,21 +141,20 @@ abstract public function get_post( $campaign_id ); public function process_campaign( $campaign_id, $source = null, $user = 'cron' ) { $wp_post = get_post( $campaign_id ); if ( ! $wp_post || 'wp_content_pilot' !== $wp_post->post_type ) { - wpcp_logger()->error( 'Could not find any campaign with the provided id', $campaign_id ); + wpcp_logger()->error( __( 'Could not find any campaign with the provided id', 'wp-content-pilot' ), $campaign_id ); return new WP_Error( 'invalid-campaign-id', __( 'Could not find the campaign', 'wp-content-pilot' ) ); } $campaign_type = get_post_meta( $campaign_id, '_campaign_type', true ); if ( $campaign_type !== $this->campaign_type ) { - wpcp_logger()->error( 'Campaign type mismatch', $campaign_id ); + wpcp_logger()->error( __( 'Campaign type mismatch', 'wp-content-pilot' ), $campaign_id ); return new WP_Error( 'invalid-campaign-id', __( 'Campaign type mismatch', 'wp-content-pilot' ) ); } if ( $this->try_count > $this->max_try ) { - $message = __( 'Tried maximum time but could not generate article check log', 'wp-content-pilot' ); - wpcp_logger()->error( $message, $campaign_id ); + wpcp_logger()->error( __( 'Tried maximum time but could not generate article check log', 'wp-content-pilot' ), $campaign_id ); return new WP_Error( 'time-out', __( 'Tried maximum time but could not generate article check log', 'wp-content-pilot' ) ); } @@ -274,7 +273,7 @@ public function process_campaign( $campaign_id, $source = null, $user = 'cron' ) //spin $spin_article = wpcp_get_post_meta( $campaign_id, '_spin_article', '' ); if ( 'on' == $spin_article ) { - wpcp_logger()->debug( 'Spinning article ...', $campaign_id ); + wpcp_logger()->debug( __( 'Spinning article ...', 'wp-content-pilot' ), $campaign_id ); $separator = str_repeat( '#', ceil( rand( 10, 20 ) ) ); $spinable = $post_title . $separator . $post_content; $spinned = explode( $separator, wpcp_spin_article( $campaign_id, $spinable ), 2 ); @@ -432,7 +431,7 @@ public function process_campaign( $campaign_id, $source = null, $user = 'cron' ) update_post_meta( $campaign_id, '_post_count', ( $posted + 1 ) ); do_action( 'wpcp_after_post_publish', $post_id, $campaign_id, $article ); do_action( 'wpcp_' . $campaign_type . '_after_post_publish', $post_id, $campaign_id, $article ); - wpcp_logger()->info( 'hurray! successfully generated article', $campaign_id ); + wpcp_logger()->info( __( 'hurray! successfully generated article', 'wp-content-pilot' ), $campaign_id ); return $post_id; } @@ -456,7 +455,7 @@ protected function setup_curl() { * @since 1.2.0 */ protected function deactivate_key( $campaign_id, $key, $hours = 1 ) { - wpcp_logger()->warning( sprintf( 'Deactivating key [%s] for [%d] hour', $key, $hours ), $campaign_id ); + wpcp_logger()->warning( sprintf( __( 'Deactivating key [%s] for [%d] hour', 'wp-content-pilot' ), $key, $hours ), $campaign_id ); $deactivated_until = current_time( 'timestamp' ) + ( $hours * HOUR_IN_SECONDS ); update_post_meta( $campaign_id, '_' . md5( $key ), $deactivated_until ); } diff --git a/includes/core-functions.php b/includes/core-functions.php index 69e714d..2db7eef 100644 --- a/includes/core-functions.php +++ b/includes/core-functions.php @@ -596,7 +596,7 @@ function wpcp_spin_article( $campaign_id, $content ) { ] ); if ( empty( $args['email_address'] ) || empty( $args['api_key'] ) ) { - wpcp_logger()->error( __( 'spinwritter API details is not set, aborting article spinner', 'wp-content-pilot' ) ); + wpcp_logger()->error( __( 'spinwritter API details is not set, aborting article spinner', 'wp-content-pilot' ), $campaign_id ); return $content; } @@ -605,14 +605,14 @@ function wpcp_spin_article( $campaign_id, $content ) { $endpoint = 'http://www.spinrewriter.com/action/api'; $curl->post( $endpoint, $args ); if ( $curl->isError() ) { - wpcp_logger()->error( __( 'Spinwritter could not send API request, aborting article spinner', 'wp-content-pilot' ) ); + wpcp_logger()->error( __( 'Spinwritter could not send API request, aborting article spinner', 'wp-content-pilot' ), $campaign_id ); return $content; } $response = json_decode( $curl->getResponse() ); if ( isset( $response->status ) && $response->status == 'ERROR' ) { - wpcp_logger()->error( sprintf( __( 'Aborting article spinner Because [%s]', 'wp-content-pilot' ), $response->response ) ); + wpcp_logger()->error( sprintf( __( 'Aborting article spinner Because [%s]', 'wp-content-pilot' ), $response->response ), $campaign_id ); return $content; } diff --git a/includes/modules/class-wpcp-article.php b/includes/modules/class-wpcp-article.php index 2c9f5b2..68dbc9a 100644 --- a/includes/modules/class-wpcp-article.php +++ b/includes/modules/class-wpcp-article.php @@ -294,11 +294,11 @@ protected function discover_links( $campaign_id, $keyword ) { //check if links exist if ( empty( $response ) || ! isset( $matches ) || ! isset( $matches ) || empty( $matches ) ) { - $message = __( 'Could not find any links from search engine, deactivating keyword for an hour.', 'wp-content-pilot' ); - wpcp_logger()->error( $message, $campaign_id ); + //$message = __( 'Could not find any links from search engine, deactivating keyword for an hour.', 'wp-content-pilot' ); + wpcp_logger()->error( __( 'Could not find any links from search engine, deactivating keyword for an hour.', 'wp-content-pilot' ), $campaign_id ); $this->deactivate_key( $campaign_id, $keyword ); - return new WP_Error( 'no-links-found', $message ); + return new WP_Error( 'no-links-found', __( 'Could not find any links from search engine, deactivating keyword for an hour.', 'wp-content-pilot' ) ); } $items = $matches; diff --git a/includes/modules/class-wpcp-flickr.php b/includes/modules/class-wpcp-flickr.php index 5d68927..300d2fb 100644 --- a/includes/modules/class-wpcp-flickr.php +++ b/includes/modules/class-wpcp-flickr.php @@ -206,6 +206,8 @@ public function get_post( $campaign_id ) { $keywords = $this->get_campaign_meta( $campaign_id ); if ( empty( $keywords ) ) { + wpcp_logger()->error( __( 'Campaign do not have keyword to proceed, please set keyword', 'wp-content-pilot' ), $campaign_id ); + return new WP_Error( 'missing-data', __( 'Campaign do not have keyword to proceed, please set keyword', 'wp-content-pilot' ) ); } diff --git a/includes/modules/class-wpcp-youtube.php b/includes/modules/class-wpcp-youtube.php index 978667d..81271da 100644 --- a/includes/modules/class-wpcp-youtube.php +++ b/includes/modules/class-wpcp-youtube.php @@ -462,7 +462,7 @@ protected function discover_links( $campaign_id, $source ) { } $endpoint = add_query_arg( $query_args, $endpoint ); - wpcp_logger()->info( sprintf( __( 'Requesting urls from Youtube [%s]', 'wp-content-pilot' ), preg_replace( '/key=([^&]+)/m', 'key=X', $endpoint ) ) ); + wpcp_logger()->info( sprintf( __( 'Requesting urls from Youtube [%s]', 'wp-content-pilot' ), preg_replace( '/key=([^&]+)/m', 'key=X', $endpoint ) ), $campaign_id ); $curl = $this->setup_curl(); $curl->get( $endpoint );
FeaturesFreePro