Plugin Directory

Changeset 2628765


Ignore:
Timestamp:
11/12/2021 06:28:51 PM (4 years ago)
Author:
dejanmarkovic
Message:

fixed he issue with count() function that was causing the problems with newer php versions

Location:
social-web-suite/trunk
Files:
1 deleted
3 edited
1 moved

Legend:

Unmodified
Added
Removed
  • social-web-suite/trunk/includes/admin/class-socialwebsuite-admin.php

    r2628283 r2628765  
    1111
    1212
    13 
    1413    private $ui;
    1514
    1615    public function __construct() {
    1716        SocialWebSuite::load_required( 'includes/admin/class-socialwebsuite-admin-ui.php' );
    18         $this->ui = new SocialWebSuite_Admin_UI;
    19         $this->is_rest =  strpos( $_SERVER['REQUEST_URI'], 'wp/v2/posts/');
    20 
    21 
    22 
     17        $this->ui      = new SocialWebSuite_Admin_UI;
     18        $this->is_rest = strpos( $_SERVER['REQUEST_URI'], 'wp/v2/posts/' );
    2319    }
    2420
     
    3329
    3430
    35 
    3631        // add api handlers
    3732        $this->register_ajax_apis();
     
    4035        add_action( 'init', array( $this, 'public_init' ), 10 );
    4136        add_action( 'admin_init', array( $this, 'admin_init' ), 10 );
    42 
    4337
    4438
     
    8680
    8781        // admin notice rate action
    88         add_action( 'wp_ajax_sws_notice_rate', array( $this, 'ajax_notice_rate' ) );
     82        add_action( 'wp_ajax_sws_notice_rate', array( $this, 'ajax_notice_rate' ) );
    8983
    9084    }
     
    9589    public function admin_menu() {
    9690        add_menu_page(
    97             esc_html__( SocialWebSuite::get_plugin_name(),'social-web-suite' ),
    98             esc_html__( 'Social Web Suite','social-web-suite' ),
     91            esc_html__( SocialWebSuite::get_plugin_name(), 'social-web-suite' ),
     92            esc_html__( 'Social Web Suite', 'social-web-suite' ),
    9993            'manage_options', 'social-web-suite',
    10094            array(
    101             $this->ui,
    102             'main_page',
     95                $this->ui,
     96                'main_page',
    10397            ), 'dashicons-megaphone'
    10498        );
     
    109103     * Called on init hook
    110104     */
    111     public function public_init(){
     105    public function public_init() {
    112106        //$gutenberg = function_exists( 'gutenberg_can_edit_post_type' );
    113107
    114108        // SocialWebSuite_Log::info('Request URI' . $_SERVER['REQUEST_URI']);
    115         if( false !== $this->is_rest  ){ //only for gutenberg workaround
     109        if ( false !== $this->is_rest ) { //only for gutenberg workaround
    116110            //
    117111            //classic-editor-replace
    118112            $settings = SocialWebSuite::get_settings();
    119             SocialWebSuite_Log::info('Gutenberg is present');
     113            SocialWebSuite_Log::info( 'Gutenberg is present' );
    120114            if ( ! empty( $settings->activated ) ) {
    121115
     
    136130
    137131
    138 
    139132        // plugin links
    140         add_action( 'plugin_action_links_' . plugin_basename( SocialWebSuite::get_plugin_path() ), array( $this, 'add_plugin_links' ) );
     133        add_action( 'plugin_action_links_' . plugin_basename( SocialWebSuite::get_plugin_path() ), array(
     134            $this,
     135            'add_plugin_links'
     136        ) );
    141137
    142138        // enqueue css & js
     
    154150
    155151            // add auto-post sharing actions
    156             if( $this->is_rest === false ) {
     152            if ( $this->is_rest === false ) {
    157153                $this->register_share_actions( $settings );
    158154            }
     
    187183
    188184
    189         add_action( 'pending_to_publish', array( $this, 'action_send_post_to_stack' ),  11, 1);
    190         add_action( 'new_to_publish', array( $this, 'action_send_post_to_stack' ), 11, 1);
    191         add_action( 'draft_to_publish', array( $this, 'action_send_post_to_stack' ), 11, 1);
    192         add_action( 'auto-draft_to_publish', array( $this, 'action_send_post_to_stack' ), 11, 1);
    193 
    194     }
    195 
    196     public function action_share_rest_post( $post, $request, $sit) {
    197         SocialWebSuite_Log::info( 'insert $post' . json_encode($post) . "\n" . '$request' . json_encode($request) );
    198     }
     185        add_action( 'pending_to_publish', array( $this, 'action_send_post_to_stack' ), 11, 1 );
     186        add_action( 'new_to_publish', array( $this, 'action_send_post_to_stack' ), 11, 1 );
     187        add_action( 'draft_to_publish', array( $this, 'action_send_post_to_stack' ), 11, 1 );
     188        add_action( 'auto-draft_to_publish', array( $this, 'action_send_post_to_stack' ), 11, 1 );
     189
     190    }
     191
     192    public function action_share_rest_post( $post, $request, $sit ) {
     193        SocialWebSuite_Log::info( 'insert $post' . json_encode( $post ) . "\n" . '$request' . json_encode( $request ) );
     194    }
     195
    199196    public function action_transitions( $new_status, $old_status, $post ) {
    200197        $transition = $old_status . '_to_' . $new_status;
    201198
    202         $sws_transitions = array( 'pending_to_publish', 'new_to_publish', 'draft_to_publish', 'auto-draft_to_publish');
    203 
    204         if(in_array( $transition, $sws_transitions )){
     199        $sws_transitions = array( 'pending_to_publish', 'new_to_publish', 'draft_to_publish', 'auto-draft_to_publish' );
     200
     201        if ( in_array( $transition, $sws_transitions ) ) {
    205202            SocialWebSuite_Log::info( 'From ' . $old_status . ' to ' . $new_status . ' for post ' . $post->ID );
    206203            $this->action_share_on_publish( $post );
     
    209206
    210207    }
     208
    211209    /**
    212210     * Add metaboxes in editor
     
    218216        $include_non_public = SocialWebSuite::get_option( 'include_non_public_post_types' );
    219217
    220         if( $include_non_public == true ){
     218        if ( $include_non_public == true ) {
    221219            $args = array(
    222220                //  'public'   => false,
    223221                '_builtin' => false,
    224222            );
    225         }else{
     223        } else {
    226224            $args = array(
    227225                'public'   => true,
     
    236234
    237235
    238 
    239236        if ( count( $excluded_post_types ) > 0 ) {
    240237            $custom_posts = array_diff( $custom_posts, $excluded_post_types );
    241238        }
    242239
    243         $post_types   = array_merge( array( 'post', 'page' ), (array) $custom_posts );
     240        $post_types = array_merge( array( 'post', 'page' ), (array) $custom_posts );
    244241
    245242        // add meta box for each post type
     
    258255     * Action links on index page for plugins
    259256     *
     257     * @param array $links
     258     *
     259     * @return  array
    260260     * @since 1.0.0
    261261     *
    262      * @param   array $links
    263      * @return  array
    264262     */
    265263    public function add_plugin_links( $links ) {
     
    286284        //wp_enqueue_style( 'sws_admin-bootstrap', $url . 'css/bootstrap.min.css', array(), $version, 'all' );
    287285
    288         // js
    289         wp_enqueue_script( 'sws-admin', $url . 'js/sws-admin.js', array( 'jquery', 'jquery-ui-datepicker' ), $version, false );
     286        // js
     287        wp_enqueue_script( 'sws-admin', $url . 'js/sws-admin.js', array(
     288            'jquery',
     289            'jquery-ui-datepicker'
     290        ), $version, false );
    290291    }
    291292
     
    312313
    313314            $data = array(
    314              'tmp_key' => filter_input( INPUT_POST, 'tmp_key' ),
    315              'user_id' => filter_input( INPUT_POST, 'user_id' ),
     315                'tmp_key' => filter_input( INPUT_POST, 'tmp_key' ),
     316                'user_id' => filter_input( INPUT_POST, 'user_id' ),
    316317            );
    317318
     
    323324
    324325            //} else {
    325              $headers = array();
     326            $headers = array();
    326327            //}
    327328
    328329            $response = wp_remote_post(
    329330                $url, array(
    330                 'method'      => 'POST',
    331                 'timeout'     => 120,
    332                 'redirection' => 5,
    333                 'httpversion' => '1.0',
    334                 'blocking'    => true,
    335                 'headers'     => $headers,
    336                 'body'        => $data,
    337                 'cookies'     => array(),
    338                 //'sslverify'   => false, //only for debugging
     331                    'method'      => 'POST',
     332                    'timeout'     => 120,
     333                    'redirection' => 5,
     334                    'httpversion' => '1.0',
     335                    'blocking'    => true,
     336                    'headers'     => $headers,
     337                    'body'        => $data,
     338                    'cookies'     => array(),
     339                    //'sslverify'   => false, //only for debugging
    339340                )
    340341            );
    341342
    342343            if ( is_wp_error( $response ) ) {
    343                       SocialWebSuite_Log::error( $response->get_error_message() );
    344                       throw new Exception( $response->get_error_message() );
     344                SocialWebSuite_Log::error( $response->get_error_message() );
     345                throw new Exception( $response->get_error_message() );
    345346
    346347            } else {
    347348
    348                          $data = json_decode( $response['body'] );
     349                $data = json_decode( $response['body'] );
    349350
    350351                if ( empty( $data->settings ) || empty( $data->token ) ) {
     
    354355                }
    355356
    356                          // add settings
    357                          SocialWebSuite::merge_settings( $data->settings );
    358 
    359                          // activate plugin
    360                          SocialWebSuite::set_option( 'api_token', $data->token );
    361                          SocialWebSuite::set_option( 'site_id', (int) filter_input( INPUT_POST, 'site_id' ) );
    362                          SocialWebSuite::set_option( 'activated', true );
    363 
    364                          $reply = array(
    365                        'status' => 'OK',
    366                          );
     357                // add settings
     358                SocialWebSuite::merge_settings( $data->settings );
     359
     360                // activate plugin
     361                SocialWebSuite::set_option( 'api_token', $data->token );
     362                SocialWebSuite::set_option( 'site_id', (int) filter_input( INPUT_POST, 'site_id' ) );
     363                SocialWebSuite::set_option( 'activated', true );
     364
     365                $reply = array(
     366                    'status' => 'OK',
     367                );
    367368            }
    368369        } catch ( Exception $e ) {
    369370            SocialWebSuite_Log::error( $e->getMessage() );
    370371            $reply = array(
    371              'status' => 'Error',
    372              'msg'    => $e->getMessage(),
     372                'status' => 'Error',
     373                'msg'    => $e->getMessage(),
    373374            );
    374375        }// End try().
     
    399400
    400401            $reply = array(
    401              'status' => 'OK',
     402                'status' => 'OK',
    402403            );
    403404
     
    405406            SocialWebSuite_Log::error( $e->getMessage() );
    406407            $reply = array(
    407              'status' => 'Error',
    408              'msg'    => $e->getMessage(),
     408                'status' => 'Error',
     409                'msg'    => $e->getMessage(),
    409410            );
    410411        }
     
    415416
    416417    /**
    417     * retrieves posts from database and outputs them in json format
    418     *
    419     * @return void
    420     */
     418     * retrieves posts from database and outputs them in json format
     419     *
     420     * @return void
     421     */
    421422    public function ajax_list_posts() {
    422423
     
    425426        try {
    426427            // validate call
    427             $hash      = filter_input( INPUT_GET, 'hash' );
    428             $timestamp = filter_input( INPUT_GET, 'timestamp' );
    429             $search = filter_input( INPUT_GET, 'search', FILTER_SANITIZE_STRING );
    430             $category = filter_input( INPUT_GET, 'category', FILTER_SANITIZE_STRING );
    431             $exclude_posts = filter_input( INPUT_GET, 'exclude_posts', FILTER_SANITIZE_STRING );
     428            $hash              = filter_input( INPUT_GET, 'hash' );
     429            $timestamp         = filter_input( INPUT_GET, 'timestamp' );
     430            $search            = filter_input( INPUT_GET, 'search', FILTER_SANITIZE_STRING );
     431            $category          = filter_input( INPUT_GET, 'category', FILTER_SANITIZE_STRING );
     432            $exclude_posts     = filter_input( INPUT_GET, 'exclude_posts', FILTER_SANITIZE_STRING );
    432433            $ignore_exclusions = filter_input( INPUT_GET, 'ignore_exclusions', FILTER_SANITIZE_STRING );
    433             $limit = (int) filter_input( INPUT_GET, 'limit' );
    434             $offset = filter_input( INPUT_GET, 'offset' );
    435             $prefs   = (object) $_GET; // WPCS: CSRF ok.
     434            $limit             = (int) filter_input( INPUT_GET, 'limit' );
     435            $offset            = filter_input( INPUT_GET, 'offset' );
     436            $prefs             = (object) $_GET; // WPCS: CSRF ok.
    436437            if ( $limit < 50 || empty( $limit ) ) {
    437438                $limit = 1000;
     
    458459            //}
    459460
    460             if(!empty($category)){
    461 
    462                 $include_categories = array();
    463                 $include_categories[]  = $category;
     461            if ( ! empty( $category ) ) {
     462
     463                $include_categories   = array();
     464                $include_categories[] = $category;
    464465            }
    465466
     
    473474            $exclude_posts_list = array();
    474475            if ( ! empty( $exclude_posts ) ) {
    475                 $sql_exclude = 'SELECT posts.ID, posts.post_title, posts.post_type FROM ' . $wpdb->posts . ' AS posts WHERE posts.ID IN (' . $exclude_posts . ')';
     476                $sql_exclude  = 'SELECT posts.ID, posts.post_title, posts.post_type FROM ' . $wpdb->posts . ' AS posts WHERE posts.ID IN (' . $exclude_posts . ')';
    476477                $posts_not_in = 'posts.ID NOT IN (' . $exclude_posts . ') AND ';
    477478
     
    491492                $include_non_public = SocialWebSuite::get_option( 'include_non_public_post_types' );
    492493
    493                 if( $include_non_public == true ){
     494                if ( $include_non_public == true ) {
    494495                    $args2 = array(
    495496                        //  'public'   => false,
    496497                        '_builtin' => false,
    497498                    );
    498                 }else{
     499                } else {
    499500                    $args2 = array(
    500501                        'public'   => true,
     
    504505                $custom_types = array_values(
    505506                    get_post_types(
    506                          $args2
     507                        $args2
    507508                    )
    508509                );
     
    510511
    511512            if ( ! $custom_types ) {
    512                       $custom_types = array();
     513                $custom_types = array();
    513514            } else {
    514515                if ( count( $excluded_post_types ) > 0 ) {
     
    526527            $post_types = "'" . implode( "','", $all_post_types ) . "'";
    527528
    528             $terms_sql = '';
     529            $terms_sql           = '';
    529530            $terms_sql_condition = '';
    530531
    531             if ( ( ! empty( $exclude_categories_string )  || ! empty( $include_categories_string ) ) && !empty( $ignore_exclusions ) ) {
     532            if ( ( ! empty( $exclude_categories_string ) || ! empty( $include_categories_string ) ) && ! empty( $ignore_exclusions ) ) {
    532533
    533534                if ( ! empty( $include_categories_string ) ) {
    534                     $terms_sql = 'INNER JOIN ' . $wpdb->term_relationships . ' AS terms ON posts.ID = terms.object_id';
     535                    $terms_sql           = 'INNER JOIN ' . $wpdb->term_relationships . ' AS terms ON posts.ID = terms.object_id';
    535536                    $terms_sql_condition = ' AND terms.term_taxonomy_id IN (SELECT term_taxonomy_id FROM ' . $wpdb->term_taxonomy . ' WHERE term_id IN (' . $include_categories_string . ')) ';
    536537                }
    537538                if ( ! empty( $exclude_categories_string ) ) {
    538                     $terms_sql = 'LEFT JOIN ' . $wpdb->term_relationships . ' AS terms ON posts.ID = terms.object_id';
     539                    $terms_sql           = 'LEFT JOIN ' . $wpdb->term_relationships . ' AS terms ON posts.ID = terms.object_id';
    539540                    $terms_sql_condition = ' AND (terms.term_taxonomy_id NOT IN (SELECT term_taxonomy_id FROM ' . $wpdb->term_taxonomy . ' WHERE term_id IN (' . $exclude_categories_string . ')) OR terms.object_id IS NULL) ';
    540541                }
     
    548549
    549550            //build the date query part if needed
    550             $date_query = $this->sws_get_date_query($prefs);
    551 
    552             if($date_query !== false){
    553                 $q .= ' ' . str_replace($wpdb->posts, 'posts', $date_query) . ' ';
    554             }
    555             $q .= $terms_sql_condition;
    556             $sql_count = sprintf( $q, 'count(*) as total' ); // select count
     551            $date_query = $this->sws_get_date_query( $prefs );
     552
     553            if ( $date_query !== false ) {
     554                $q .= ' ' . str_replace( $wpdb->posts, 'posts', $date_query ) . ' ';
     555            }
     556            $q             .= $terms_sql_condition;
     557            $sql_count     = sprintf( $q, 'count(*) as total' ); // select count
    557558            $results_count = $wpdb->get_row( $sql_count ); // WPCS: unprepared SQL OK.
    558559
    559             $posts_with_data = array();
     560            $posts_with_data = array();
    560561            if ( null !== $results_count ) {
    561562                $sql = sprintf( $q, 'DISTINCT posts.ID, posts.post_title, posts.post_type, posts.post_excerpt, posts.post_content' ); // select posts
     
    571572                if ( $results && count( $results ) > 0 ) {
    572573                    $posts = $results;
    573                     foreach($posts as $post){
     574                    foreach ( $posts as $post ) {
    574575                        $posts_with_data[] = SocialWebSuite::get_post_data( $post );
    575576                    }
     
    579580
    580581            $reply = array(
    581                 'status' => 'OK',
    582                 'data' => $posts,
    583                 'posts'=> $posts_with_data,
     582                'status'        => 'OK',
     583                'data'          => $posts,
     584                'posts'         => $posts_with_data,
    584585                'excluded_data' => $exclude_posts_list,
    585                 'total' => is_null( $results_count ) ? 0 : $results_count->total,
     586                'total'         => is_null( $results_count ) ? 0 : $results_count->total,
    586587            );
    587588
     
    589590            SocialWebSuite_Log::error( $e->getMessage() );
    590591            $reply = array(
    591              'status' => 'Error',
    592              'msg'    => $e->getMessage(),
     592                'status' => 'Error',
     593                'msg'    => $e->getMessage(),
    593594            );
    594595        }// End try().
     
    604605        try {
    605606            // validate call
    606             $hash      = filter_input( INPUT_GET, 'hash' );
    607             $timestamp = filter_input( INPUT_GET, 'timestamp' );
    608             $search = filter_input( INPUT_GET, 'search', FILTER_SANITIZE_STRING );
    609             $category = filter_input( INPUT_GET, 'category', FILTER_SANITIZE_STRING );
    610             $exclude_posts = filter_input( INPUT_GET, 'exclude_posts', FILTER_SANITIZE_STRING );
     607            $hash              = filter_input( INPUT_GET, 'hash' );
     608            $timestamp         = filter_input( INPUT_GET, 'timestamp' );
     609            $search            = filter_input( INPUT_GET, 'search', FILTER_SANITIZE_STRING );
     610            $category          = filter_input( INPUT_GET, 'category', FILTER_SANITIZE_STRING );
     611            $exclude_posts     = filter_input( INPUT_GET, 'exclude_posts', FILTER_SANITIZE_STRING );
    611612            $ignore_exclusions = filter_input( INPUT_GET, 'ignore_exclusions', FILTER_SANITIZE_STRING );
    612             $limit = (int) filter_input( INPUT_GET, 'limit' );
    613             $offset = filter_input( INPUT_GET, 'offset' );
    614             $prefs   = (object) $_GET; // WPCS: CSRF ok.
     613            $limit             = (int) filter_input( INPUT_GET, 'limit' );
     614            $offset            = filter_input( INPUT_GET, 'offset' );
     615            $prefs             = (object) $_GET; // WPCS: CSRF ok.
    615616
    616617            if ( ! SocialWebSuite::verify( $hash, $timestamp ) ) {
     
    619620            }
    620621
    621             $reply = wp_count_posts();
     622            $reply = wp_count_posts();
    622623
    623624        } catch ( Exception $e ) {
    624625            SocialWebSuite_Log::error( $e->getMessage() );
    625626            $reply = array(
    626              'status' => 'Error',
    627              'msg'    => $e->getMessage(),
     627                'status' => 'Error',
     628                'msg'    => $e->getMessage(),
    628629            );
    629630        }// End try().
     
    632633        exit;
    633634    }
     635
    634636    /**
    635637     * retrieves post types from database and outputs them in json format
     
    649651            $include_non_public = SocialWebSuite::get_option( 'include_non_public_post_types' );
    650652
    651             if( $include_non_public == true ){
     653            if ( $include_non_public == true ) {
    652654                $args2 = array(
    653                 //  'public'   => false,
     655                    //  'public'   => false,
    654656                    '_builtin' => false,
    655657                );
    656             }else{
     658            } else {
    657659                $args2 = array(
    658660                    'public'   => true,
     
    665667
    666668            $all_post_types = array(
    667             //  array( 'name' => 'page', 'label' => 'Pages' ),
    668             //  array( 'name' => 'post', 'label' => 'Posts' ),
     669                //  array( 'name' => 'page', 'label' => 'Pages' ),
     670                //  array( 'name' => 'post', 'label' => 'Posts' ),
    669671            );
    670672
     
    674676                foreach ( $custom_types as $custom_type ) {
    675677                    $all_post_types[] = array(
    676                         'name' => $custom_type->name,
     678                        'name'  => $custom_type->name,
    677679                        'label' => $custom_type->label,
    678680                    );
     
    697699
    698700    }
     701
    699702    public function ajax_list_categories() {
    700703        try {
     
    714717            $taxonomies = get_taxonomies(
    715718                array(
    716                 'public' => true,
     719                    'public' => true,
    717720                ), 'objects'
    718721            );
     
    726729                    }
    727730
    728                      $terms = get_terms(
    729                          $taxonomy->name, array(
    730                          'hide_empty' => false,
    731                          )
    732                      );
     731                    $terms = get_terms(
     732                        $taxonomy->name, array(
     733                            'hide_empty' => false,
     734                        )
     735                    );
    733736
    734737                    foreach ( $terms as $term ) {
    735                                                 $cats[] = array(
    736                                                  'id'          => $term->term_id,
    737                                                  'term_id'     => $term->term_id,
    738                                                  'name'        => $term->name,
    739                                                  'slug'        => $term->slug,
    740                                                  'group'       => $term->term_group,
    741                                                  'taxonomy_id' => $term->term_taxonomy_id,
    742                                                  'description' => $term->description,
    743                                                  'parent'      => $term->parent,
    744                                                  'count'       => $term->count,
    745                                                 );
     738                        $cats[] = array(
     739                            'id'          => $term->term_id,
     740                            'term_id'     => $term->term_id,
     741                            'name'        => $term->name,
     742                            'slug'        => $term->slug,
     743                            'group'       => $term->term_group,
     744                            'taxonomy_id' => $term->term_taxonomy_id,
     745                            'description' => $term->description,
     746                            'parent'      => $term->parent,
     747                            'count'       => $term->count,
     748                        );
    746749                    }
    747750                }
     
    749752
    750753            $reply = array(
    751              'status' => 'OK',
    752              'data'   => $cats,
     754                'status' => 'OK',
     755                'data'   => $cats,
    753756            );
    754757
     
    756759            SocialWebSuite_Log::error( $e->getMessage() );
    757760            $reply = array(
    758              'status' => 'Error',
    759              'msg'    => $e->getMessage(),
     761                'status' => 'Error',
     762                'msg'    => $e->getMessage(),
    760763            );
    761764        }// End try().
     
    797800            // we're done
    798801            $reply = array(
    799              'status' => 'OK',
    800              'data'   => $content,
     802                'status' => 'OK',
     803                'data'   => $content,
    801804            );
    802805
     
    804807            SocialWebSuite_Log::error( $e->getMessage() );
    805808            $reply = array(
    806              'status' => 'Error',
    807              'msg'    => $e->getMessage(),
     809                'status' => 'Error',
     810                'msg'    => $e->getMessage(),
    808811            );
    809812        }// End try().
     
    813816    }
    814817
    815     public function ajax_get_single_post(){
     818    public function ajax_get_single_post() {
    816819
    817820        try {
     
    826829
    827830            // get post
    828             $post_id      = filter_input( INPUT_GET, 'id' );
    829             $post = get_post( $post_id );
    830             $data = SocialWebSuite::get_post_data( $post );
     831            $post_id = filter_input( INPUT_GET, 'id' );
     832            $post    = get_post( $post_id );
     833            $data    = SocialWebSuite::get_post_data( $post );
    831834
    832835
     
    848851        exit;
    849852    }
    850     public function ajax_get_post_image(){
     853
     854    public function ajax_get_post_image() {
    851855
    852856        try {
     
    861865
    862866            // get posts
    863             $post_id      = filter_input( INPUT_GET, 'id' );
    864             $post = get_post( $post_id );
    865             $data = array();
     867            $post_id = filter_input( INPUT_GET, 'id' );
     868            $post    = get_post( $post_id );
     869            $data    = array();
    866870            //$post_data = SocialWebSuite::get_post_data( $post );
    867871            $thumb_id = get_post_thumbnail_id( $post->ID );
     
    895899        exit;
    896900    }
     901
    897902    public function ajax_unlink_site() {
    898903
     
    910915
    911916            $reply = array(
    912              'status' => 'OK',
     917                'status' => 'OK',
    913918            );
    914919
     
    916921            SocialWebSuite_Log::error( $e->getMessage() );
    917922            $reply = array(
    918              'status' => 'Error',
    919              'msg'    => $e->getMessage(),
     923                'status' => 'Error',
     924                'msg'    => $e->getMessage(),
    920925            );
    921926        }
     
    924929        exit;
    925930    }
     931
    926932    public function ajax_ping_site() {
    927933        try {
     
    938944
    939945            $reply = array(
    940              'status' => 'OK',
     946                'status' => 'OK',
    941947            );
    942948
     
    944950            SocialWebSuite_Log::error( $e->getMessage() );
    945951            $reply = array(
    946              'status' => 'Error',
    947              'msg'    => $e->getMessage(),
     952                'status' => 'Error',
     953                'msg'    => $e->getMessage(),
    948954            );
    949955        }
     
    954960
    955961    public function ajax_submit_uninstall_reason() {
    956         $reason_id = filter_input( INPUT_POST, 'reason_id' );
     962        $reason_id   = filter_input( INPUT_POST, 'reason_id' );
    957963        $reason_info = filter_input( INPUT_POST, 'reason_info' );
    958964
    959965        $data = array(
    960           'event_type' => 'plugin_deactivated',
    961           'event_description' => 'Plugin Has Been Uninstalled',
    962           'deactivation_reason' => $reason_id,
    963           'deactivation_reason_custom' => $reason_info,
     966            'event_type'                => 'plugin_deactivated',
     967            'event_description'          => 'Plugin Has Been Uninstalled',
     968            'deactivation_reason'        => $reason_id,
     969            'deactivation_reason_custom' => $reason_info,
    964970        );
    965971
    966972        $data['ajax_url'] = admin_url( 'admin-ajax.php' );
    967         $tmp_token = md5( wp_generate_password( rand( 32, 64 ), true, true ) );
     973        $tmp_token        = md5( wp_generate_password( rand( 32, 64 ), true, true ) );
    968974        SocialWebSuite::set_option( 'optin_secret_key', $tmp_token );
    969975        $data['secret'] = $tmp_token;
     
    981987
    982988
    983 
    984         if($this->is_rest === false){
    985             SocialWebSuite_Log::info('sharing post' . json_encode($post));
     989        if ( $this->is_rest === false ) {
     990            SocialWebSuite_Log::info( 'sharing post' . json_encode( $post ) );
    986991            $this->save_post_meta( $post->ID, $post, ' called from action_share_on_publish ' );
    987992            SocialWebSuite::auto_share_post( $post );
    988         }else{
    989             SocialWebSuite_Log::info('sharing post gutenberg' . json_encode($post));
    990             update_post_meta($post->ID, 'sws_gutenberg_share_on_publish', true);
    991         }
    992 
    993 
    994 
    995     }
    996 
     993        } else {
     994            SocialWebSuite_Log::info( 'sharing post gutenberg' . json_encode( $post ) );
     995            update_post_meta( $post->ID, 'sws_gutenberg_share_on_publish', true );
     996        }
     997
     998
     999    }
    9971000
    9981001
     
    10001003     * Save meta fields when post is saved
    10011004     *
     1005     * @param integer $post_id
     1006     * @param WP_Post $post
     1007     *
    10021008     * @since 1.0.0
    10031009     *
    1004      * @param integer   $post_id
    1005      * @param WP_Post   $post
    10061010     */
    10071011    public function save_post_meta( $post_id, $post, $from_action_share = false ) {
    10081012
    1009         if($from_action_share !== false){
    1010             SocialWebSuite_Log::info('save_post_meta - ' . $from_action_share  . ' - '. json_encode($_POST));
    1011         }else{
    1012             SocialWebSuite_Log::info('save_post_meta - from action - '. json_encode($_POST));
     1013
     1014        if ( $from_action_share !== false ) {
     1015            SocialWebSuite_Log::info( 'save_post_meta - ' . $from_action_share . ' - ' . json_encode( $_POST ) );
     1016        } else {
     1017            SocialWebSuite_Log::info( 'save_post_meta - from action - ' . json_encode( $_POST ) );
    10131018        }
    10141019
    10151020        $sws_post_nonce = filter_input( INPUT_POST, 'sws_post_nonce' );
    1016         if ( empty( $sws_post_nonce )  || ! wp_verify_nonce( $sws_post_nonce, 'save-post-meta' ) ) {
     1021        if ( empty( $sws_post_nonce ) || ! wp_verify_nonce( $sws_post_nonce, 'save-post-meta' ) ) {
    10171022            return;
    10181023        }
     
    10371042
    10381043        $fields = array(
    1039          'sws_meta_manual',            // [default, skip, custom]
    1040          'sws_meta_send_now',            // [now, schedule]
    1041          'sws_meta_schedule_calendar',    // date as shown in the calendar
    1042          'sws_meta_schedule_date',        // YYYY-mm-dd date
    1043          'sws_meta_schedule_hours',        // 0 - 12
    1044          'sws_meta_schedule_mins',        // 0 - 60
    1045          'sws_meta_schedule_ampm',        // [am, pm]
    1046          'sws_meta_include_image',        // [default, skip, include]
    1047          'sws_meta_use_hashtags',        // [default, none, cats, tags, custom]
    1048          'sws_meta_hashtags',            // string
    1049          'sws_meta_format',                // string
    1050          'sws_meta_custom_message',           //string
    1051          'sws_meta_custom_message_variations_data',           //string
    1052          'sws_meta_startdate_date',          //timestamp
    1053          'sws_meta_enddate_date',          //timestamp
    1054          'sws_meta_use_cutom_messages', //boolean
    1055          'sws_meta_social_accounts_exclude', //array
    1056 
    1057          // 'sws_show_misc_options',          //boolean
     1044            'sws_meta_manual',            // [default, skip, custom]
     1045            'sws_meta_send_now',            // [now, schedule]
     1046            'sws_meta_schedule_calendar',    // date as shown in the calendar
     1047            'sws_meta_schedule_date',        // YYYY-mm-dd date
     1048            'sws_meta_schedule_hours',        // 0 - 12
     1049            'sws_meta_schedule_mins',        // 0 - 60
     1050            'sws_meta_schedule_ampm',        // [am, pm]
     1051            'sws_meta_include_image',        // [default, skip, include]
     1052            'sws_meta_use_hashtags',        // [default, none, cats, tags, custom]
     1053            'sws_meta_hashtags',            // string
     1054            'sws_meta_format',                // string
     1055            'sws_meta_custom_message',           //string
     1056            'sws_meta_custom_message_variations_data',           //string
     1057            'sws_meta_startdate_date',          //timestamp
     1058            'sws_meta_enddate_date',          //timestamp
     1059            'sws_meta_use_cutom_messages', //boolean
     1060            'sws_meta_social_accounts_exclude', //array
     1061
     1062            // 'sws_show_misc_options',          //boolean
    10581063        );
    10591064
     
    10621067        if ( 'notevergreen' !== $meta_manual ) {
    10631068            $_POST['sws_meta_startdate_date'] = '';
    1064             $_POST['sws_meta_enddate_date'] = '';
     1069            $_POST['sws_meta_enddate_date']   = '';
    10651070        } else {
    10661071            $dates = $this->convert_nonevergreen_dates( $_POST );
    10671072
    10681073            $_POST['sws_meta_startdate_date'] = $dates['startdate'];
    1069             $_POST['sws_meta_enddate_date'] = $dates['enddate'];
     1074            $_POST['sws_meta_enddate_date']   = $dates['enddate'];
    10701075            if ( empty( $dates['startdate'] ) && empty( $dates['enddate'] ) ) {
    10711076                $_POST['sws_meta_manual'] = 'default';
     
    10741079
    10751080        foreach ( $fields as $field ) {
    1076             if( 'sws_meta_custom_message_variations_data' !== $field  && 'sws_meta_social_accounts_exclude' !== $field){
    1077                 if( 'sws_meta_format' === $field ){
     1081            if ( 'sws_meta_custom_message_variations_data' !== $field && 'sws_meta_social_accounts_exclude' !== $field ) {
     1082                if ( 'sws_meta_format' === $field ) {
    10781083                    $new = isset( $_POST[ $field ] ) ? implode( "\n", array_map( 'sanitize_text_field', explode( "\n", $_POST[ $field ] ) ) ) : ''; //preserve line breaks for format
    1079                 }else{
     1084                } else {
    10801085                    $new = isset( $_POST[ $field ] ) ? sanitize_text_field( $_POST[ $field ] ) : '';
    10811086                }
     
    10851090            $old = get_post_meta( $post_id, $field, true );
    10861091
    1087             if( 'sws_meta_custom_message_variations_data' === $field ) {
    1088 
    1089                 $custom_message_variations_data = (array)json_decode( get_post_meta( $post->ID, 'sws_meta_custom_message_variations_data', true ) );
    1090 
    1091                 $last_shared_variation = isset( $custom_message_variations_data['last_shared_key'] ) ? $custom_message_variations_data['last_shared_key'] : -1;
    1092                 $custom_message_variations_data['last_shared_key'] = -1;
    1093                 $variations_old = ( isset( $custom_message_variations_data['variations'] ) ) ? $custom_message_variations_data['variations'] : array();
    1094 
    1095 
    1096                 $variations = filter_input(INPUT_POST, 'sws_meta_custom_message_variations', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY);
    1097                 $variations_share_times = filter_input(INPUT_POST, 'sws_meta_variations_share_times', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY);
    1098                 $variations_share_count_reset = filter_input(INPUT_POST, 'sws_meta_variations_share_count_reset', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY);
    1099 
    1100 
    1101 
    1102 
    1103                 $variations_new = array();
     1092            if ( 'sws_meta_custom_message_variations_data' === $field ) {
     1093
     1094                $custom_message_variations_data = (array) json_decode( get_post_meta( $post->ID, 'sws_meta_custom_message_variations_data', true ) );
     1095
     1096                $last_shared_variation                             = isset( $custom_message_variations_data['last_shared_key'] ) ? $custom_message_variations_data['last_shared_key'] : - 1;
     1097                $custom_message_variations_data['last_shared_key'] = - 1;
     1098                $variations_old                                    = ( isset( $custom_message_variations_data['variations'] ) ) ? $custom_message_variations_data['variations'] : array();
     1099
     1100
     1101                $variations                   = filter_input( INPUT_POST, 'sws_meta_custom_message_variations', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY );
     1102                $variations_share_times       = filter_input( INPUT_POST, 'sws_meta_variations_share_times', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY );
     1103                $variations_share_count_reset = filter_input( INPUT_POST, 'sws_meta_variations_share_count_reset', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY );
     1104
     1105
     1106                $variations_new            = array();
    11041107                $last_shared_key_reindexed = false;
    1105                 //echo 'variations - ';
    1106                 //print_r($variations);
    1107                 //echo ' - end variations ';
    1108                 foreach( $variations as $v_key => $variation ){
    1109                     $variation = trim($variation);
     1108
     1109                foreach ( $variations as $v_key => $variation ) {
     1110                    $variation = trim( $variation );
    11101111                    //echo 'variation key ' . $v_key . ' variation - ' . $variation;
    11111112                    //$variation = addslashes($variation);
    11121113
    1113                     $variation = str_replace(array(PHP_EOL, "\r\n", "\n", "\r"), ' ', $variation);
    1114                     $variation = preg_replace('!\s+!', ' ', $variation);
    1115 
    1116                     $variation_hash = md5($variation);
    1117                     if( !empty( $variation ) ){
    1118                         $variation_data = array( 'message' => $variation, 'hash' => $variation_hash, 'share_times'=> (int)$variations_share_times[ $v_key ], 'share_count' => 0);
    1119 
    1120                         foreach( $variations_old as $vo_key => $variation_old ){
    1121                             $variation_old = (array)$variation_old;
    1122                             if( $variation_old[ 'hash' ] === $variation_data[ 'hash' ] ){
    1123                                 if( $last_shared_variation === $vo_key && $last_shared_key_reindexed === false ){
     1114                    $variation = str_replace( array( PHP_EOL, "\r\n", "\n", "\r" ), ' ', $variation );
     1115                    $variation = preg_replace( '!\s+!', ' ', $variation );
     1116
     1117                    $variation_hash = md5( $variation );
     1118                    if ( ! empty( $variation ) ) {
     1119                        $variation_data = array(
     1120                            'message'     => $variation,
     1121                            'hash'        => $variation_hash,
     1122                            'share_times' => (int) $variations_share_times[ $v_key ],
     1123                            'share_count' => 0
     1124                        );
     1125
     1126                        foreach ( $variations_old as $vo_key => $variation_old ) {
     1127                            $variation_old = (array) $variation_old;
     1128                            if ( $variation_old['hash'] === $variation_data['hash'] ) {
     1129                                if ( $last_shared_variation === $vo_key && $last_shared_key_reindexed === false ) {
    11241130                                    $custom_message_variations_data['last_shared_key'] = count( $variations_new ); //if index has changed for last shared variation
    1125                                     $last_shared_key_reindexed = true;
     1131                                    $last_shared_key_reindexed                         = true;
    11261132                                }
    1127                                 if( (int)$variations_share_count_reset[ $v_key ] !== 1){
    1128                                     $variation_data[ 'share_count' ] = $variation_old[ 'share_count' ];
     1133                                if ( (int) $variations_share_count_reset[ $v_key ] !== 1 ) {
     1134                                    $variation_data['share_count'] = $variation_old['share_count'];
    11291135                                }
    11301136
     
    11381144                }
    11391145
    1140                 $custom_message_variations_data[ 'variations' ] = $variations_new;
     1146                $custom_message_variations_data['variations'] = $variations_new;
    11411147
    11421148                //print_r($custom_message_variations_data);
    11431149                //exit;
    1144                 $new = json_encode( $custom_message_variations_data, JSON_UNESCAPED_UNICODE|JSON_PRETTY_PRINT);
    1145 
    1146 
    1147             }
    1148 
    1149             if( 'sws_meta_social_accounts_exclude' === $field ){
    1150                 $new = filter_input(INPUT_POST, 'sws_meta_social_accounts_exclude', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY);
    1151                 if( ! is_array( $new ) ){
     1150                $new = json_encode( $custom_message_variations_data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT );
     1151
     1152
     1153            }
     1154
     1155            if ( 'sws_meta_social_accounts_exclude' === $field ) {
     1156                $new = filter_input( INPUT_POST, 'sws_meta_social_accounts_exclude', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY );
     1157                if ( ! is_array( $new ) ) {
    11521158                    $new = array();
    11531159                }
    11541160                $exclude_social_accounts = array();
    1155                 $social_accounts = SocialWebSuite::get_social_accounts();
    1156                 $twitter_included = false;
    1157                 foreach( $social_accounts as $social_account ){
    1158                     if( ! in_array( $social_account->id, $new ) ){
     1161                $social_accounts         = SocialWebSuite::get_social_accounts();
     1162                $twitter_included        = false;
     1163                foreach ( $social_accounts as $social_account ) {
     1164                    if ( ! in_array( $social_account->id, $new ) ) {
    11591165                        $exclude_social_accounts[] = $social_account->id;
    1160                         $exclude_action = 'add';
    1161                     }else{
    1162                         if( $social_account->service !== 'twitter' ){
     1166                        $exclude_action            = 'add';
     1167                    } else {
     1168                        if ( $social_account->service !== 'twitter' ) {
    11631169                            $exclude_action = 'remove';
    1164                         }else{
    1165                             if( $twitter_included === false ){
    1166                                 $exclude_action = 'remove';
     1170                        } else {
     1171                            if ( $twitter_included === false ) {
     1172                                $exclude_action   = 'remove';
    11671173                                $twitter_included = true;
    1168                             }else{
     1174                            } else {
    11691175                                $exclude_social_accounts[] = $social_account->id;
    1170                                 $exclude_action = 'add';
     1176                                $exclude_action            = 'add';
    11711177                            }
    11721178                        }
     
    11741180                    }
    11751181                    //update option, so we can use it in query, rather than searching through post meta using too complex meta query combination
    1176                     SocialWebSuite::update_excluded_social_accounts_posts( $post_id, $social_account->id, $exclude_action);
    1177                 }
    1178                 $new = implode(',', $exclude_social_accounts);
     1182                    SocialWebSuite::update_excluded_social_accounts_posts( $post_id, $social_account->id, $exclude_action );
     1183                }
     1184                $new = implode( ',', $exclude_social_accounts );
    11791185            }
    11801186
     
    11881194            }
    11891195        }
    1190         SocialWebSuite_Log::info('saved_post_meta' . json_encode($post));
     1196
     1197        SocialWebSuite_Log::info( 'saved_post_meta' . json_encode( $post ) );
    11911198        $gutenberg_share_on_publish = get_post_meta( $post_id, 'sws_gutenberg_share_on_publish' );
    1192         if( $gutenberg_share_on_publish && !empty( $gutenberg_share_on_publish ) && 0 !== count( $post ) ){
     1199
     1200        if ( $gutenberg_share_on_publish && ! empty( $gutenberg_share_on_publish ) && ! empty( $post ) ) {
    11931201            delete_post_meta( $post_id, 'sws_gutenberg_share_on_publish' );
    1194             SocialWebSuite_Log::info('calling auto_share_post from saved post meta ' . $post_id);
     1202            SocialWebSuite_Log::info( 'calling auto_share_post from saved post meta ' . $post_id );
    11951203            SocialWebSuite::auto_share_post( $post );
    11961204        }
    11971205        $gutenberg_share_manually = get_post_meta( $post_id, 'sws_gutenberg_share_manually' );
    1198         if( $gutenberg_share_manually && !empty( $gutenberg_share_manually ) && 0 !== count( $post ) ){
     1206
     1207
     1208        if ( $gutenberg_share_manually && ! empty( $gutenberg_share_manually ) && ! empty( $post ) ) {
    11991209            delete_post_meta( $post_id, 'sws_gutenberg_share_manually' );
    1200             SocialWebSuite_Log::info('calling manually_share_post from saved post meta manually ' . $post_id);
     1210            SocialWebSuite_Log::info( 'calling manually_share_post from saved post meta manually ' . $post_id );
    12011211            SocialWebSuite::manually_share_post( $post );
    12021212        }
    12031213
    12041214    }
     1215
    12051216    /**
    1206     * takes the submitted values for dates and converts them in timestamp
    1207     *
    1208     * @since 1.0.5
    1209     *
    1210     * @param array $data post data from submitted post form
    1211     *
    1212     * @return array $dates dates converted in timestamp
    1213     */
     1217     * takes the submitted values for dates and converts them in timestamp
     1218     *
     1219     * @param array $data post data from submitted post form
     1220     *
     1221     * @return array $dates dates converted in timestamp
     1222     * @since 1.0.5
     1223     *
     1224     */
    12141225    public function convert_nonevergreen_dates( $data ) {
    12151226
    1216         $prefix = 'sws_meta_';
    1217         $dates_prefixes = array( 'startdate' , 'enddate' );
    1218         $dates = array();
     1227        $prefix         = 'sws_meta_';
     1228        $dates_prefixes = array( 'startdate', 'enddate' );
     1229        $dates          = array();
    12191230        foreach ( $dates_prefixes as $date_prefix ) {
    12201231            $date_string = '';
     
    12501261
    12511262        }
     1263
    12521264        return $dates;
    12531265
     
    12551267
    12561268
    1257     public function pre_action_share_on_update($new_status, $old_status, $post){
     1269    public function pre_action_share_on_update( $new_status, $old_status, $post ) {
    12581270        //avoid triggering share when restoring from trash
    1259         if ( $old_status == 'publish' && $new_status == 'publish' ){
    1260             $this->action_share_on_update($post);
     1271        if ( $old_status == 'publish' && $new_status == 'publish' ) {
     1272            $this->action_share_on_update( $post );
    12611273        }
    12621274    }
     
    12701282        // SocialWebSuite::auto_share_post( $post );
    12711283
    1272         if($this->is_rest === false){
    1273             SocialWebSuite_Log::info('sharing post' . json_encode($post));
     1284        if ( $this->is_rest === false ) {
     1285            SocialWebSuite_Log::info( 'sharing post' . json_encode( $post ) );
    12741286            $this->save_post_meta( $post->ID, $post, ' called from action_share_on_update ' );
    12751287            SocialWebSuite::auto_share_post( $post );
    1276         }else{
     1288        } else {
    12771289            //in case of rest API call, we need to wait for post meta to be updated first.
    1278             SocialWebSuite_Log::info('sharing post gutenberg' . json_encode($post));
    1279             update_post_meta($post->ID, 'sws_gutenberg_share_on_update', true);
     1290            SocialWebSuite_Log::info( 'sharing post gutenberg' . json_encode( $post ) );
     1291            update_post_meta( $post->ID, 'sws_gutenberg_share_on_update', true );
    12801292        }
    12811293
     
    12851297        // meta is already saved, just share it if set so
    12861298
    1287         if($this->is_rest === false){
    1288             SocialWebSuite_Log::info('sharing post' . json_encode($post));
     1299        if ( $this->is_rest === false ) {
     1300            SocialWebSuite_Log::info( 'sharing post' . json_encode( $post ) );
    12891301            //$this->save_post_meta( $post->ID, $post, ' called from action_share_on_publish ' );
    12901302            SocialWebSuite::manually_share_post( $post );
    1291         }else{
    1292             SocialWebSuite_Log::info('manually sharing post gutenberg' . json_encode($post));
    1293             update_post_meta($post->ID, 'sws_gutenberg_share_manually', true);
     1303        } else {
     1304            SocialWebSuite_Log::info( 'manually sharing post gutenberg' . json_encode( $post ) );
     1305            update_post_meta( $post->ID, 'sws_gutenberg_share_manually', true );
    12941306        }
    12951307
     
    13081320    }
    13091321
    1310     public function admin_plugin_rate_notice(){
     1322    public function admin_plugin_rate_notice() {
    13111323        //check if user has fulfilled conditions to show him notice
    1312         $rate_notice_hide = SocialWebSuite::get_option('rate_notice_hide' );
    1313         $rate_notice_time = SocialWebSuite::get_option('rate_notice_time' );
    1314         if( empty( $rate_notice_time ) ){
     1324        $rate_notice_hide = SocialWebSuite::get_option( 'rate_notice_hide' );
     1325        $rate_notice_time = SocialWebSuite::get_option( 'rate_notice_time' );
     1326        if ( empty( $rate_notice_time ) ) {
    13151327            $rate_notice_time = strtotime( '+ 2 weeks' );
    1316             SocialWebSuite::set_option( 'rate_notice_time' , $rate_notice_time );
     1328            SocialWebSuite::set_option( 'rate_notice_time', $rate_notice_time );
     1329
    13171330            return;
    13181331        }
     
    13201333        $current_time = strtotime( 'now' );
    13211334
    1322         if( $current_time > $rate_notice_time && ( false === $rate_notice_hide || empty( $rate_notice_hide ) ) ){
     1335        if ( $current_time > $rate_notice_time && ( false === $rate_notice_hide || empty( $rate_notice_hide ) ) ) {
    13231336
    13241337            //show user notice every two weeks
    13251338            /* disabled after requests from some users */
    13261339            //$this->ui->show_admin_rate_notice();
    1327         }
    1328 
    1329     }
    1330 
    1331     public function ajax_notice_rate(){
     1340        }
     1341
     1342    }
     1343
     1344    public function ajax_notice_rate() {
    13321345
    13331346        // Continue only if the nonce is correct
    13341347        check_admin_referer( 'sws_rate_action_nonce', '_n' );
    13351348
    1336         $rate_action = filter_input( INPUT_POST,'rate_action' );
    1337 
    1338         if ( 'do-rate' === $rate_action  || 'done-rating' === $rate_action ) {
    1339         //don't show notice any more
    1340             SocialWebSuite::set_option('rate_notice_hide', true );
     1349        $rate_action = filter_input( INPUT_POST, 'rate_action' );
     1350
     1351        if ( 'do-rate' === $rate_action || 'done-rating' === $rate_action ) {
     1352            //don't show notice any more
     1353            SocialWebSuite::set_option( 'rate_notice_hide', true );
    13411354        } else {
    13421355            //postpone showing
    1343             SocialWebSuite::set_option('rate_notice_hide', false );
     1356            SocialWebSuite::set_option( 'rate_notice_hide', false );
    13441357            $rate_notice_time = strtotime( '+ 2 weeks' );
    1345             SocialWebSuite::set_option( 'rate_notice_time' , $rate_notice_time );
    1346 
    1347         }
    1348 
    1349         echo  1 ;
     1358            SocialWebSuite::set_option( 'rate_notice_time', $rate_notice_time );
     1359
     1360        }
     1361
     1362        echo 1;
    13501363        exit;
    13511364    }
     
    13531366    public function action_send_post_to_stack( $post ) {
    13541367        // we have to save meta here because this hook comes before save_post hook
    1355     //  $this->save_post_meta( $post->ID, $post );
     1368        //  $this->save_post_meta( $post->ID, $post );
    13561369
    13571370
    13581371        //SocialWebSuite::auto_share_post( $post );
    1359         SocialWebSuite::send_post_to_stack($post);
    1360     }
    1361 
    1362     public function sws_get_date_query($prefs){
    1363 
    1364         if((isset($prefs->min_age_post) && !empty($prefs->min_age_post)) ||  (isset($prefs->max_age_post) && !empty($prefs->max_age_post))){
     1372        SocialWebSuite::send_post_to_stack( $post );
     1373    }
     1374
     1375    public function sws_get_date_query( $prefs ) {
     1376
     1377        if ( ( isset( $prefs->min_age_post ) && ! empty( $prefs->min_age_post ) ) || ( isset( $prefs->max_age_post ) && ! empty( $prefs->max_age_post ) ) ) {
    13651378            $date_query = array();
    13661379
    1367             if(isset($prefs->min_age_post) && !empty($prefs->min_age_post)){
     1380            if ( isset( $prefs->min_age_post ) && ! empty( $prefs->min_age_post ) ) {
    13681381                $date_query[] = array(
    1369                     'before' => $prefs->min_age_post .' days ago',
     1382                    'before' => $prefs->min_age_post . ' days ago',
    13701383                );
    13711384            }
    13721385
    1373             if(isset($prefs->max_age_post) && !empty($prefs->max_age_post)){
     1386            if ( isset( $prefs->max_age_post ) && ! empty( $prefs->max_age_post ) ) {
    13741387                $date_query[] = array(
    1375                     'after' => $prefs->max_age_post .' days ago',
     1388                    'after' => $prefs->max_age_post . ' days ago',
    13761389                );
    13771390            }
    1378             $dates = new WP_Date_Query($date_query);
     1391            $dates = new WP_Date_Query( $date_query );
    13791392
    13801393
  • social-web-suite/trunk/readme.txt

    r2628283 r2628765  
    236236
    237237== Change Log ==
     238== 3.1.3 - 2021-11-12
     239- fixed he issue with count() function that was causing the problems with newer php versions
     240
    238241== 3.1.2 - 2021-11-11
    239242- deleted the error logs
  • social-web-suite/trunk/social-web-suite.php

    r2628283 r2628765  
    44 * Plugin URI: https://socialwebsuite.com/
    55 * Description: Manage all your social media accounts from one place. Automate, schedule & publish your posts/custom post types/pages to major social networks. Social Web Suite is premium (paid) social media scheduler service and our plans start at $9.
    6  * Version: 3.1.2
     6 * Version: 3.1.3
    77 * Author: hypestudio,nytogroup,dejanmarkovic,tinat
    88 * Author URI: https://hypestudio.org/
Note: See TracChangeset for help on using the changeset viewer.