diff --git a/includes/class-sf-debug.php b/includes/class-sf-debug.php
index bfced89..35cbe72 100755
--- a/includes/class-sf-debug.php
+++ b/includes/class-sf-debug.php
@@ -122,6 +122,16 @@ protected function __construct() {
* @access public
*/
public function on_init() {
+ /** TC Edit - Only allow the 'Debug' setting if we're not on VIP. */
+ if ( defined( 'VIP_GO_APP_ENVIRONMENT' ) && VIP_GO_APP_ENVIRONMENT !== false ) {
+ $this->debug = false;
+ return;
+ }
+
+ /** TC Edit - Fix "Debug mode" checkbox not actually enabling/disabling debug mode. */
+ global $socialflow;
+ $this->debug = $socialflow->options->get( 'debug_mode' );
+
if ( ! $this->debug ) {
return;
}
diff --git a/includes/class-socialflow-methods.php b/includes/class-socialflow-methods.php
index 55045b2..f715533 100644
--- a/includes/class-socialflow-methods.php
+++ b/includes/class-socialflow-methods.php
@@ -6,6 +6,9 @@
* @package SocialFlow
*/
+/** TC Edit - We need to check if we're on our local env. */
+use function TC\Utilities\Environments\is_local;
+
/**
* Plugin Methods class
*
@@ -55,7 +58,8 @@ public function get_api( $token = '', $secret = '' ) {
}
// Catch error.
- $socialflow->api = new WP_SocialFlow( SF_KEY, SF_SECRET, $token, $secret );
+ /** TC Edit - We're loading our own key/secret via filter rather than use SF_KEY / SF_SECRET. */
+ $socialflow->api = new WP_SocialFlow( apply_filters( 'tc_sf_key', '' ), apply_filters( 'tc_sf_secret', '' ), $token, $secret );
}
return $socialflow->api;
@@ -504,7 +508,9 @@ public function get_image_id_by_url( $url = '' ) {
// search for image id.
$id = wp_cache_get( $url );
if ( ! $id ) {
- $id = $wpdb->get_var( $wpdb->prepare( "SELECT ID $wpdb->posts FROM WHERE guid LIKE %d LIMIT 1", [ "%$url%" ] ) );
+ /** TC Edit - Fixed broken SQL statement. */
+ // $id = $wpdb->get_var( $wpdb->prepare( "SELECT ID $wpdb->posts FROM WHERE guid LIKE %d LIMIT 1", [ "%$url%" ] ) );
+ $id = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE guid LIKE %d LIMIT 1", [ "%$url%" ] ) );
wp_cache_set( $url, $id );
}
@@ -525,7 +531,8 @@ public function is_ajax() {
*/
public function is_localhost() {
$socialflow_params = filter_input_array( INPUT_SERVER );
- if ( 'localhost' === $socialflow_params['HTTP_HOST'] ) {
+ /** TC Edit - We need to check if we're on our local env. */
+ if ( is_local() || 'localhost' === $socialflow_params['HTTP_HOST'] ) {
return true;
}
diff --git a/includes/class-socialflow-post.php b/includes/class-socialflow-post.php
index 0a0becc..6ab340e 100644
--- a/includes/class-socialflow-post.php
+++ b/includes/class-socialflow-post.php
@@ -133,7 +133,9 @@ public function add_meta_box() {
continue;
}
- add_meta_box( 'socialflow', __( 'SocialFlow', 'socialflow' ), array( $this, 'meta_box' ), $type, 'side', 'high', array( 'post_page' => true ) );
+ /** TC Edit - Fixed escaping. */
+ // add_meta_box( 'socialflow', __( 'SocialFlow', 'socialflow' ), array( $this, 'meta_box' ), $type, 'side', 'high', array( 'post_page' => true ) );
+ add_meta_box( 'socialflow', esc_html__( 'SocialFlow', 'socialflow' ), array( $this, 'meta_box' ), $type, 'side', 'high', array( 'post_page' => true ) );
}
}
@@ -301,8 +303,11 @@ public function save_meta( $post_id ) {
$media = $socialflow_params['socialflow']['global']['media'];
$this->data( $post_id )->save_global_settings( $data );
$this->data( $post_id )->save_social_messages( $data );
+ /** TC Edit - Fix bug with "Image" not able to be unchecked once saved as checked. */
+ $this->data( $post_id )->save_social_compose_media( $media );
if ( $media ) {
- $this->data( $post_id )->save_social_compose_media( $media );
+ /** TC Edit - Fix bug with "Image" not able to be unchecked once saved as checked. */
+ //$this->data( $post_id )->save_social_compose_media( $media );
if ( strlen( $media['compose_media_pos_twitter'] ) ) {
$this->data( $post_id )->save_media_slider_position( (int) $media['compose_media_pos_twitter'], 'twitter' );
$this->save_curent_url_for_social( $post_id, 'twitter', $media['compose_media_url_twitter'] );
@@ -408,6 +413,8 @@ protected function get_compose_data( $post_id ) {
'is_compose_media_facebook' => $is_compose_media_facebook,
'is_compose_media_google_plus' => $is_compose_media_google_plus,
'media' => $media,
+ /** TC Edit - Pass the post_id to the compose class so that we know what post we're working with. */
+ 'post_id' => $post_id,
)
);
@@ -778,7 +785,9 @@ public function ajax_compose() {
$form_message = '
' . $form_message . '
';
} else {
$status = 1;
- $form_message = '' . __( 'Message was successfully sent. View statistics block for more information.', 'socialflow' ) . '
';
+ /** TC Edit - Fixed escaping. */
+ // $form_message = '' . __( 'Message was successfully sent. View statistics block for more information.', 'socialflow' ) . '
';
+ $form_message = '' . esc_html__( 'Message was successfully sent. View statistics block for more information.', 'socialflow' ) . '
';
}
wp_send_json(
@@ -829,7 +838,9 @@ public function get_compose_log() {
$status = $compose_log['status'];
if ( $compose_log['is_deleted'] ) {
- $status .= ' ' . __( 'deleted', 'socialflow' ) . '';
+ /** TC Edit - Fixed escaping. */
+ // $status .= ' ' . __( 'deleted', 'socialflow' ) . '';
+ $status .= ' ' . esc_html__( 'deleted', 'socialflow' ) . '';
}
$is_updated = $logs->update_by_content_item_id(
@@ -841,7 +852,9 @@ public function get_compose_log() {
if ( $is_updated ) {
$status .= ' → ';
- $status .= ( 0 === $compose_log['is_published'] ) ? __( 'In Queue', 'socialflow' ) : __( 'Published', 'socialflow' );
+ /** TC Edit - Fixed escaping. */
+ // $status .= ( 0 === $compose_log['is_published'] ) ? __( 'In Queue', 'socialflow' ) : __( 'Published', 'socialflow' );
+ $status .= ( 0 === $compose_log['is_published'] ) ? esc_html__( 'In Queue', 'socialflow' ) : esc_html__( 'Published', 'socialflow' );
$status .= '';
}
}
@@ -915,7 +928,9 @@ public function default_message( $message, $type, $post ) {
* @return array of filtered list columns.
*/
public function add_column( $columns ) {
- $columns['socialflow'] = __( 'SocialFlow', 'socialflow' );
+ /** TC Edit - Fixed escaping. */
+ // $columns['socialflow'] = __( 'SocialFlow', 'socialflow' );
+ $columns['socialflow'] = esc_html__( 'SocialFlow', 'socialflow' );
return $columns;
}
@@ -936,12 +951,16 @@ public function custom_column( $column, $post_id ) {
if ( 'socialflow' === $column ) {
// if sf_compose == 0 than message was already composed.
if ( $this->data( $post_id )->logs()->get() ) {
- echo wp_kses_post( '
' );
+ /** TC Edit - Fixed escaping. */
+ // echo wp_kses_post( '
' );
+ echo wp_kses_post( '
' );
// Render compact stats table.
$socialflow->render_view( 'stats/compact', $this->get_view_stat_data( $post_id ) );
} elseif ( 'publish' !== get_post_status( $post_id ) && ( get_post_meta( $post_id, 'sf_message_facebook', true ) || get_post_meta( $post_id, 'sf_message_twitter', true ) ) ) {
- echo wp_kses_post( '
' );
+ /** TC Edit - Fixed escaping. */
+ // echo wp_kses_post( '
' );
+ echo wp_kses_post( '
' );
} else {
echo wp_kses_post( '
' );
}
@@ -964,9 +983,13 @@ public function row_actions( $actions, $post ) {
return $actions;
}
- $title = esc_attr__( 'Send to SocialFlow', 'socialflow' );
+ /** TC Edit - Fixed escaping. */
+ // $title = esc_attr__( 'Send to SocialFlow', 'socialflow' );
+ $title_attr = esc_attr__( 'Send to SocialFlow', 'socialflow' );
+ $title = esc_html__( 'Send to SocialFlow', 'socialflow' );
- $actions['sf-compose-action'] = '';
+ // $actions['sf-compose-action'] = '';
+ $actions['sf-compose-action'] = '';
return $actions;
}
@@ -1006,7 +1029,9 @@ public function post_updated_messages( $messages ) {
// Add message only for enabled post types.
if ( $socialflow->options->get( 'post_type' ) ) {
foreach ( $socialflow->options->get( 'post_type' ) as $type ) {
- $mess = 'Notice: ' . $type . ' was not published, because some errors occurred when sending messages to SocialFlow. View More.';
+ /** TC Edit - Fixed escaping. */
+ // $mess = 'Notice: ' . $type . ' was not published, because some errors occurred when sending messages to SocialFlow. View More.';
+ $mess = 'Notice: ' . esc_html( $type ) . ' was not published, because some errors occurred when sending messages to SocialFlow. View More.';
$messages[ $type ][20] = $mess;
}
}
diff --git a/includes/class-tc-sf-debug.php b/includes/class-tc-sf-debug.php
new file mode 100755
index 0000000..75b5048
--- /dev/null
+++ b/includes/class-tc-sf-debug.php
@@ -0,0 +1,182 @@
+log( $msg, $data, 'debug' );
+ }
+}
+
+require_once(ABSPATH . 'wp-admin/includes/file.php');
+
+if ( ! function_exists( 'sf_log' ) ) {
+ /**
+ * Social flow debug
+ *
+ * @param string $msg sf debug message.
+ * @param array $data sf debug data.
+ */
+ function sf_log( $msg, $data = array() ) {
+ SF_Debug::get_instance()->log( $msg, $data, 'post' );
+ }
+}
+
+if ( ! function_exists( 'sf_log_post' ) ) {
+ /**
+ * Social flow log post
+ *
+ * @param string $msg sf debug message.
+ * @param object $post sf debug data.
+ */
+ function sf_log_post( $msg, $post ) {
+ SF_Debug::get_instance()->log_post( $msg, $post );
+ }
+}
+
+/**
+ * Social flow debug
+ *
+ * @package SF_Debug
+ */
+class SF_Debug {
+
+ /**
+ * Field Instance
+ *
+ * @since 1.0
+ * @var object
+ */
+ protected static $instance;
+
+ /**
+ * Use debug
+ *
+ * @since 1.0
+ * @var bool
+ */
+ protected $debug = true;
+
+ /**
+ * Create Add actions
+ *
+ * @since 1.0
+ * @access public
+ */
+ protected function __construct() {
+ add_action( 'init', array( $this, 'on_init' ) );
+ }
+
+ /**
+ * Init debug
+ *
+ * @since 1.0
+ * @access public
+ */
+ public function on_init() {
+ /** TC Edit - Fix "Debug mode" checkbox not actually enabling/disabling debug mode. */
+ global $socialflow;
+ $this->debug = $socialflow->options->get( 'debug_mode' );
+
+ if ( ! $this->debug ) {
+ return;
+ }
+
+ if ( ! defined( 'SF_DEBUG' ) ) {
+ define( 'SF_DEBUG', true );
+ }
+ }
+
+ /**
+ * Get instance field
+ */
+ public static function get_instance() {
+ if ( ! self::$instance ) {
+ self::$instance = new self();
+ }
+
+ return self::$instance;
+ }
+
+ /**
+ * Log
+ *
+ * @param string $msg .
+ * @param array $data .
+ * @param string $file .
+ */
+ public function log( $msg, $data = array(), $file = 'post' ) {
+ if ( ! $this->debug ) {
+ return;
+ }
+
+ $date = date( 'Y-m-d H:i:s' );
+
+ if ( $msg ) {
+ if ( $data ) {
+ $msg .= "\n" . print_r( $data, true );
+ }
+
+ $msg = "$date: $msg";
+ }
+
+ $this->write_log( $file, $msg );
+ }
+
+ /**
+ * Log post
+ *
+ * @param string $msg .
+ * @param object $post .
+ */
+ public function log_post( $msg, $post ) {
+ if ( is_object( $post ) ) {
+ if ( 'post' !== $post->post_type ) {
+ return;
+ }
+
+ if ( in_array( $post->post_status, array( 'new', 'any', 'auto-draft' ), true ) ) {
+ return;
+ }
+
+ $post_id = $post->ID;
+ } else {
+ $post_id = $post;
+ }
+
+ $this->log( "post_ID: {$post_id} - $msg" );
+ }
+
+ /**
+ * Write in log
+ *
+ * @param string $file .
+ * @param string $msg .
+ * @return bool
+ */
+ protected function write_log( $file, $msg = '' ) {
+ $key = 'tc_socialflow_log_' . $file;
+
+ $log = (array) get_option( $key, [] );
+ $log[] = $msg;
+
+ // Limit log size.
+ if ( count( $log ) > 5000 ) {
+ array_shift( $log );
+ }
+
+ update_option( $key, $log, false );
+ }
+}
+if ( is_admin() ) {
+ SF_Debug::get_instance();
+}
diff --git a/includes/post/class-socialflow-post-compose.php b/includes/post/class-socialflow-post-compose.php
index bfe3cad..e73ed0d 100755
--- a/includes/post/class-socialflow-post-compose.php
+++ b/includes/post/class-socialflow-post-compose.php
@@ -42,6 +42,8 @@ class SocialFlow_Post_Compose {
'is_compose_media_google_plus' => false,
'media' => array(),
'shorten_links' => false,
+ /** TC Edit - Pass the post_id in so that we know what post we're working with. */
+ 'post_id' => 0,
);
/**
@@ -543,13 +545,37 @@ protected function set_message() {
return;
}
- if ( $this->is_compose_socials_networks() && ( ! $this->is_post_attachment() ) ) {
- $message .= " {$this->post_permalink}";
+ /** TC Edit - Submit twitter postfix even with image posts. */
+ if ( ! $this->is_social_type( 'twitter' ) && $this->is_compose_socials_networks() && ( ! $this->is_post_attachment() ) ) {
+// if ( $this->is_compose_socials_networks() && ( ! $this->is_post_attachment() ) ) {
+
+ /** TC Edit - Allow overriding the permalink to include a tracking param. */
+ //$message .= " {$this->post_permalink}";
+ /**
+ * Filters the post permalink that's used for the share to allow injecting tracking params.
+ *
+ * @param string $permalink The post permalink.
+ * @param int $post_id The ID of the post this permalink is for.
+ * @param string $social_type The social network this permalink will be used with.
+ */
+ $message .= ' ' . apply_filters( 'tc_sf_post_permalink', $this->post_permalink, $this->post_id, $this->social_type );
} elseif ( $this->is_social_type( 'twitter' ) ) {
- $message .= " {$this->post_permalink}";
+ /** TC Edit - Allow overriding the permalink to include a tracking param. */
+ //$message .= " {$this->post_permalink}";
+ $message .= ' ' . apply_filters( 'tc_sf_post_permalink', $this->post_permalink, $this->post_id, $this->social_type );
if ( $this->fields['message_postfix'] ) {
$message .= " {$this->fields['message_postfix']}";
}
+ /** TC Edit - Allow overriding the Twitter postfix if nothing is submitted. */
+ /**
+ * Filters the custom twitter postfix we want to set.
+ *
+ * @param string $postfix The string to print after the URL on twitter posts.
+ * @param int $post_id The ID of the post this postfix is for.
+ */
+ elseif ( apply_filters( 'tc_sf_twitter_postfix', '', $this->post_id ) ) {
+ $message .= ' ' . apply_filters( 'tc_sf_twitter_postfix', '', $this->post_id );
+ }
}
$message = $this->validate_text( 'message', $message );
@@ -717,7 +743,9 @@ protected function set_error( $error_key ) {
$error = array(
'code' => 'empty_message:',
/* translators: %s: search term */
- 'message' => printf( esc_html( __( 'Error: Publish options are required for: %s.' ) ) ),
+ /** TC Edit - Fixed escaping. */
+ // 'message' => printf( esc_html( __( 'Error: Publish options are required for: %s.' ) ) ),
+ 'message' => __( 'Error: Publish options are required for: %s.' ),
'data' => $this->social_type,
);
break;
diff --git a/includes/post/class-socialflow-post-form-data.php b/includes/post/class-socialflow-post-form-data.php
index e97007c..9fae9a2 100755
--- a/includes/post/class-socialflow-post-form-data.php
+++ b/includes/post/class-socialflow-post-form-data.php
@@ -628,10 +628,19 @@ public function get_saved_social_messages() {
* @param array $data .
*/
public function save_social_compose_media( $data ) {
-
- foreach ( $data as $key => $item ) {
- update_post_meta( $this->post->ID, 'sf_' . $key, $item );
+ /** TC Edit - Fix bug with "Image" not able to be unchecked once saved as checked. */
+ $networks = [ 'twitter', 'facebook', 'google_plus', 'linkedin' ];
+ foreach ( $networks as $network ) {
+ $key = "compose_media_{$network}";
+ if ( is_array( $data ) && array_key_exists( $key, $data ) ) {
+ update_post_meta( $this->post->ID, 'sf_' . $key, $data[ $key ] );
+ } else {
+ update_post_meta( $this->post->ID, 'sf_' . $key, 0 );
+ }
}
+ //foreach ( $data as $key => $item ) {
+ // update_post_meta( $this->post->ID, 'sf_' . $key, $item );
+ //}
}
/**
diff --git a/includes/settings/class-socialflow-admin-settings-general.php b/includes/settings/class-socialflow-admin-settings-general.php
index ffdd0f0..3178ba0 100644
--- a/includes/settings/class-socialflow-admin-settings-general.php
+++ b/includes/settings/class-socialflow-admin-settings-general.php
@@ -328,7 +328,8 @@ public function authorize_settings() {
}
$signup = 'http://socialflow.com/signup';
- $links = $api->get_account_links( SF_KEY );
+ /** TC Edit - We're loading our own key/secret via filter rather than use SF_KEY. */
+ $links = $api->get_account_links( apply_filters( 'tc_sf_key', '' ) );
if ( $links ) {
$signup = $links->signup;
}
@@ -393,6 +394,9 @@ public function save_settings( $settings = array() ) {
$settings['must_send'] = isset( $data['must_send'] ) ? absint( $data['must_send'] ) : 0;
$settings['compose_now'] = isset( $data['compose_now'] ) ? absint( $data['compose_now'] ) : 0;
$settings['global_disable_autocomplete'] = isset( $data['global_disable_autocomplete'] ) ? absint( $data['global_disable_autocomplete'] ) : 0;
+
+ /** TC Edit - Fix "Debug mode" checkbox not saving when unchecked. */
+ $settings['debug_mode'] = isset( $data['debug_mode'] ) ? absint( $data['debug_mode'] ) : 0;
}
return $settings;
diff --git a/includes/settings/class-socialflow-admin-settings-messages.php b/includes/settings/class-socialflow-admin-settings-messages.php
index c712e0c..f3893d2 100644
--- a/includes/settings/class-socialflow-admin-settings-messages.php
+++ b/includes/settings/class-socialflow-admin-settings-messages.php
@@ -173,7 +173,8 @@ public function delete_message() {
if ( isset( $socialflow_params['sf_action'] ) && ( 'delete' === $socialflow_params['sf_action'] ) && current_user_can( 'manage_options' ) ) {
require_once SF_ABSPATH . '/libs/class-wp-socialflow.php';
$token = $socialflow->options->get( 'access_token' );
- $api = new WP_SocialFlow( SF_KEY, SF_SECRET, $token['oauth_token'], $token['oauth_token_secret'] );
+ /** TC Edit - We're loading our own key/secret via filter rather than use SF_KEY / SF_SECRET. */
+ $api = new WP_SocialFlow( apply_filters( 'tc_sf_key', '' ), apply_filters( 'tc_sf_secret', '' ), $token['oauth_token'], $token['oauth_token_secret'] );
// check for required vars and remove message from queue.
$result = false;
diff --git a/socialflow.php b/socialflow.php
index e5e83d3..c87076d 100644
--- a/socialflow.php
+++ b/socialflow.php
@@ -65,14 +65,23 @@
*
* @since 1.0
*/
-define( 'SF_KEY', 'acbe74e2cc182d888412' );
+/** TC Edit - We're using our encrypted saved key/secret, rather than hard-coding
+define( 'SF_KEY', '' );
+*/
+
/**
* Define Consumer Secret
*
* @since 1.0
*/
-define( 'SF_SECRET', '650108a50ea3cb2bd6f9' );
-require_once SF_ABSPATH . '/includes/class-sf-debug.php';
+/** TC Edit - We're using our encrypted saved key/secret, rather than hard-coding
+define( 'SF_SECRET', '' );
+*/
+
+/** TC Edit - Load in our custom VIP-safe debug class. */
+// require_once SF_ABSPATH . '/includes/class-sf-debug.php';
+require_once SF_ABSPATH . '/includes/class-tc-sf-debug.php';
+
require_once SF_ABSPATH . '/includes/class-socialflow-methods.php';
require_once SF_ABSPATH . '/includes/class-socialflow.php';
require_once SF_ABSPATH . '/includes/class-socialflow-admin.php';
diff --git a/techcrunch-edits.txt b/techcrunch-edits.txt
new file mode 100644
index 0000000..d9e1598
--- /dev/null
+++ b/techcrunch-edits.txt
@@ -0,0 +1,3 @@
+Edits were made to this version of the the Socialflow plugin.
+
+They can be found by searching for "TC Edit" on the folder.