Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions includes/class-sf-debug.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
13 changes: 10 additions & 3 deletions includes/class-socialflow-methods.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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 );
}

Expand All @@ -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;
}

Expand Down
47 changes: 36 additions & 11 deletions includes/class-socialflow-post.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) );
}
}

Expand Down Expand Up @@ -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'] );
Expand Down Expand Up @@ -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,
)
);

Expand Down Expand Up @@ -778,7 +785,9 @@ public function ajax_compose() {
$form_message = '<p class="sf-error">' . $form_message . '</p>';
} else {
$status = 1;
$form_message = '<p class="success">' . __( 'Message was successfully sent. View statistics block for more information.', 'socialflow' ) . '</p>';
/** TC Edit - Fixed escaping. */
// $form_message = '<p class="success">' . __( 'Message was successfully sent. View statistics block for more information.', 'socialflow' ) . '</p>';
$form_message = '<p class="success">' . esc_html__( 'Message was successfully sent. View statistics block for more information.', 'socialflow' ) . '</p>';
}

wp_send_json(
Expand Down Expand Up @@ -829,7 +838,9 @@ public function get_compose_log() {
$status = $compose_log['status'];

if ( $compose_log['is_deleted'] ) {
$status .= ' <i class="deleted">' . __( 'deleted', 'socialflow' ) . '</i>';
/** TC Edit - Fixed escaping. */
// $status .= ' <i class="deleted">' . __( 'deleted', 'socialflow' ) . '</i>';
$status .= ' <i class="deleted">' . esc_html__( 'deleted', 'socialflow' ) . '</i>';
}

$is_updated = $logs->update_by_content_item_id(
Expand All @@ -841,7 +852,9 @@ public function get_compose_log() {

if ( $is_updated ) {
$status .= ' &rarr; <span style="display:inline-block">';
$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 .= '</span>';
}
}
Expand Down Expand Up @@ -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;
}

Expand All @@ -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( '<img class="js-sf-extended-stat-toggler" src="' . plugins_url( 'assets/images/success.gif', SF_FILE ) . '" width="12" height="12" title="' . __( 'Successfully sent', 'socialflow' ) . '" alt="' . __( 'Successfully sent', 'socialflow' ) . '" />' );
/** TC Edit - Fixed escaping. */
// echo wp_kses_post( '<img class="js-sf-extended-stat-toggler" src="' . plugins_url( 'assets/images/success.gif', SF_FILE ) . '" width="12" height="12" title="' . __( 'Successfully sent', 'socialflow' ) . '" alt="' . __( 'Successfully sent', 'socialflow' ) . '" />' );
echo wp_kses_post( '<img class="js-sf-extended-stat-toggler" src="' . plugins_url( 'assets/images/success.gif', SF_FILE ) . '" width="12" height="12" title="' . esc_attr__( 'Successfully sent', 'socialflow' ) . '" alt="' . esc_attr__( 'Successfully sent', 'socialflow' ) . '" />' );

// 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( '<img src="' . plugins_url( 'assets/images/notice.gif', SF_FILE ) . '" width="12" height="12" title="' . __( 'SocialFlow data filled', 'socialflow' ) . '" alt="' . __( 'SocialFlow data filled', 'socialflow' ) . '" />' );
/** TC Edit - Fixed escaping. */
// echo wp_kses_post( '<img src="' . plugins_url( 'assets/images/notice.gif', SF_FILE ) . '" width="12" height="12" title="' . __( 'SocialFlow data filled', 'socialflow' ) . '" alt="' . __( 'SocialFlow data filled', 'socialflow' ) . '" />' );
echo wp_kses_post( '<img src="' . plugins_url( 'assets/images/notice.gif', SF_FILE ) . '" width="12" height="12" title="' . esc_attr__( 'SocialFlow data filled', 'socialflow' ) . '" alt="' . esc_attr__( 'SocialFlow data filled', 'socialflow' ) . '" />' );
} else {
echo wp_kses_post( '<img src="' . plugins_url( 'assets/images/default.gif', SF_FILE ) . '" width="12" height="12" />' );
}
Expand All @@ -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'] = '<a class="thickbox sf-open-popup" href="#TB_inline?width=770&inlineId=sf-form-popup" data-post-id="' . $post->ID . '" title="' . $title . '">' . $title . '</a>';
// $actions['sf-compose-action'] = '<a class="thickbox sf-open-popup" href="#TB_inline?width=770&inlineId=sf-form-popup" data-post-id="' . $post->ID . '" title="' . $title . '">' . $title . '</a>';
$actions['sf-compose-action'] = '<a class="thickbox sf-open-popup" href="#TB_inline?width=770&inlineId=sf-form-popup" data-post-id="' . (int) $post->ID . '" title="' . $title_attr . '">' . $title . '</a>';

return $actions;
}
Expand Down Expand Up @@ -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 = '<b>Notice:</b> ' . $type . ' was not published, because some errors occurred when sending messages to SocialFlow. <a href="#socialflow">View More.</a>';
/** TC Edit - Fixed escaping. */
// $mess = '<b>Notice:</b> ' . $type . ' was not published, because some errors occurred when sending messages to SocialFlow. <a href="#socialflow">View More.</a>';
$mess = '<b>Notice:</b> ' . esc_html( $type ) . ' was not published, because some errors occurred when sending messages to SocialFlow. <a href="#socialflow">View More.</a>';
$messages[ $type ][20] = $mess;
}
}
Expand Down
182 changes: 182 additions & 0 deletions includes/class-tc-sf-debug.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
<?php
/**
* Holds main SocialFlow plugin class
*
* @package SocialFlow
*/

if ( ! function_exists( 'sf_debug' ) ) {
/**
* Social flow debug
*
* @param string $msg sf debug message.
* @param array $data sf debug data.
*/
function sf_debug( $msg, $data = array() ) {
SF_Debug::get_instance()->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();
}
Loading