diff --git a/README.TXT b/README.TXT index 61ab5e0a6..482a9d19b 100644 --- a/README.TXT +++ b/README.TXT @@ -37,7 +37,6 @@ Looking for other types of directories? Check out [Business Directory Plugin](ht * Classified ads can have character limits, supported by plans (different plans can have different limits) * Classified ads can be displayed on any page for a single category using shortcodes * Auto-verify ads with email links to post immediately upon click -* Classified ads can be 'Sent to Facebook' inside of ad management * Support for displaying ad events in BuddyPress activity stream with [BuddyPress module](https://awpcp.com/downloads/buddypress-module/?utm_source=wprepo&utm_medium=link&utm_campaign=liteversion) * Classified ads can be edited via front end, back end with or without registration (depending on settings) * Multiple levels of directory categories supported @@ -72,7 +71,6 @@ Looking for other types of directories? Check out [Business Directory Plugin](ht * Ad Management panel, visible by users and admins for easier ad creation/editing/delete. * Admin can post ads on behalf of other users with the ads displaying as if the user posted them initially * Email verification step can be used to auto-post ads upon successful verification link click -* Ads can be posted to a Facebook page manually or automatically == Classified Directory Image Features == diff --git a/admin/class-settings-admin-page.php b/admin/class-settings-admin-page.php index 013812712..8fdd9b614 100644 --- a/admin/class-settings-admin-page.php +++ b/admin/class-settings-admin-page.php @@ -57,7 +57,7 @@ public function enqueue_scripts() { * Renders the page. */ public function dispatch() { - $groups = $this->settings_manager->get_settings_groups(); + $groups = $this->settings_manager->get_settings_groups( true ); $subgroups = $this->settings_manager->get_settings_subgroups(); $current_groups = $this->get_current_groups( $groups, $subgroups ); @@ -113,11 +113,8 @@ private function sort_group_subgroups( $group, $subgroups ) { return $group; } - // phpcs:disable - private function instantiate_auxiliar_pages() { $pages = awpcp_classfieds_pages_settings(); - $facebook = new AWPCP_Facebook_Page_Settings(); } } @@ -125,9 +122,6 @@ function awpcp_classfieds_pages_settings() { return new AWPCP_Classified_Pages_Settings( awpcp_missing_pages_finder() ); } -/** - * @SuppressWarnings(PHPMD) - */ class AWPCP_Classified_Pages_Settings { private $missing_pages_finder; @@ -167,117 +161,15 @@ private function should_restore_pages() { class AWPCP_Facebook_Page_Settings { - /** - * @var Settings - */ - private $settings; - - public function __construct() { - $this->settings = awpcp()->settings; - - add_action( 'current_screen', array( $this, 'maybe_redirect' ) ); - add_action( 'awpcp-admin-settings-page--facebook-settings', array($this, 'dispatch')); - } - - /** - * @SuppressWarnings(PHPMD.ExitExpression) - */ public function maybe_redirect() { - if ( !isset( $_GET['g'] ) || $_GET['g'] != 'facebook-settings' || $this->get_current_action() != 'obtain_user_token' ) - return; - - if ( isset( $_GET[ 'error_code' ] ) ) { - return $this->redirect_with_error( $_GET[ 'error_code' ], urlencode( $_GET['error_message'] ) ); - } - - $code = isset( $_GET['code'] ) ? $_GET['code'] : ''; - - $fb = AWPCP_Facebook::instance(); - $access_token = $fb->token_from_code( $code ); - - if ( ! $access_token ) { - return $this->redirect_with_error( 1, 'Unkown error trying to exchange code for access token.' ); - } - - $this->settings->update_option( 'facebook-user-access-token', $access_token ); - - wp_redirect( admin_url( 'admin.php?page=awpcp-admin-settings&g=facebook-settings' ) ); - die(); + _deprecated_function( __FUNCTION__, '4.1.8' ); } public function get_current_action() { - if ( isset( $_POST['diagnostics'] ) ) - return 'diagnostics'; - - if ( isset( $_REQUEST['obtain_user_token'] ) && $_REQUEST['obtain_user_token'] == 1 ) - return 'obtain_user_token'; - - return 'display_settings'; - } - - /** - * @SuppressWarnings(PHPMD.ExitExpression) - */ - private function redirect_with_error( $error_code, $error_message ) { - $params = array( 'code_error' => $error_code, 'error_message' => $error_message ); - $settings_url = admin_url( 'admin.php?page=awpcp-admin-settings&g=facebook-settings' ); - wp_redirect( add_query_arg( urlencode_deep( $params ), $settings_url ) ); - die(); + _deprecated_function( __FUNCTION__, '4.1.8' ); } public function dispatch() { - $action = $this->get_current_action(); - - switch ( $action ) { - case 'diagnostics': - case 'display_settings': - default: - return $this->display_settings(); - break; - } - } - - /** - * @SuppressWarnings(PHPMD.ElseExpression) - * @SuppressWarnings(PHPMD.UnusedLocalVariable) - */ - private function display_settings( $errors=array() ) { - $fb = AWPCP_Facebook::instance(); - - $redirect_uri = add_query_arg( 'obtain_user_token', 1, admin_url( '/admin.php?page=awpcp-admin-settings&g=facebook-settings' ) ); - - if ( isset( $_GET['code_error'] ) && isset( $_GET['error_message'] ) ) { - $error_message = __( 'We could not obtain a valid access token from Facebook. The API returned the following error: %s', 'another-wordpress-classifieds-plugin' ); - $error_message = sprintf( $error_message, wp_unslash( urldecode_deep( $_GET['error_message'] ) ) ); - - $errors[] = esc_html( $error_message ); - } else if ( isset( $_GET['code_error'] ) ) { - $errors[] = esc_html( __( 'We could not obtain a valid access token from Facebook. Please try again.', 'another-wordpress-classifieds-plugin' ) ); - } - - if ( $this->get_current_action() == 'diagnostics' ) { - $diagnostics_errors = array(); - $fb->validate_config( $diagnostics_errors ); - - $error_msg = ''; - $error_msg .= '' . __( 'Facebook Config Diagnostics', 'another-wordpress-classifieds-plugin' ) . '
'; - - if ( $diagnostics_errors ) { - foreach ( $diagnostics_errors as &$e ) { - $error_msg .= '• ' . $e . '
'; - } - } else { - $error_msg .= __( 'Everything looks OK.', 'another-wordpress-classifieds-plugin' ); - } - - $errors[] = $error_msg; - } - - ob_start(); - include(AWPCP_DIR . '/admin/templates/admin-panel-settings-facebook-settings.tpl.php'); - $content = ob_get_contents(); - ob_end_clean(); - - echo $content; + _deprecated_function( __FUNCTION__, '4.1.8' ); } } diff --git a/admin/templates/admin-panel-settings-facebook-settings.tpl.php b/admin/templates/admin-panel-settings-facebook-settings.tpl.php deleted file mode 100755 index 61831256f..000000000 --- a/admin/templates/admin-panel-settings-facebook-settings.tpl.php +++ /dev/null @@ -1,115 +0,0 @@ -
- - __( 'Facebook Integration', 'another-wordpress-classifieds-plugin' ) ) ); // XSS Ok. ?> - -

- -

- -

-https://developers.facebook.com/blog/post/2018/04/04/facebook-api-platform-product-changes/', $content ); - - echo $content; // XSS Ok. -?> -

- -

- -

- -

-', $content ); - $content = str_replace( '{/link_to_how_to_register_facebook_apps}', '', $content ); - $content = str_replace( '{link_to_facebook_integration_documentation}', '', $content ); - $content = str_replace( '{/link_to_facebook_integration_documentation}', '', $content ); - - echo $content; // XSS Ok. -?> -

- -

- -
- -

- -

- -

-', $content ); - $content = str_replace( '{/webhook_instructions_for_zapier}', '', $content ); - $content = str_replace( '{webhook_instructions_for_ifttt}', '', $content ); - $content = str_replace( '{/webhook_instructions_for_ifttt}', '', $content ); - - echo $content; // XSS Ok. -?> -

- -

- -

-', $content ); - $content = str_replace( '{/link_to_how_to_register_facebook_apps}', '', $content ); - $content = str_replace( '{link_to_facebook_integration_documentation}', '', $content ); - $content = str_replace( '{/link_to_facebook_integration_documentation}', '', $content ); - - echo $content; // XSS Ok. -?> -

- -

- -
- -

- -

- -

Invalid Scopes: manage_pages, publish_pages, publish_to_groups. This message is only shown to developers. Users of your app will ignore these permissions if present. Please read the documentation for valid permissions at: https://developers.facebook.com/docs/facebook-login/permissions

- -

- -

- -

(#200) Requires either publish_to_groups permission and app being installed in the group, or manage_pages and publish_pages as an admin with sufficient administrative permission.

- -

-', $content ); - $content = str_replace( '{/link_to_how_to_add_apps_to_a_group}', '', $content ); - - echo $content; // XSS Ok. -?> -

- -
-

- - - -

-
- -
- -
diff --git a/includes/admin/class-admin-container-configuration.php b/includes/admin/class-admin-container-configuration.php index 1ce80a026..d114ab133 100644 --- a/includes/admin/class-admin-container-configuration.php +++ b/includes/admin/class-admin-container-configuration.php @@ -242,22 +242,6 @@ public function modify( $container ) { ); } ); - $container['SendToFacebookPageListingTableAction'] = $container->service( function( $container ) { - return new AWPCP_SendToFacebookPageListingTableAction( - $container['SendListingToFacebookHelper'], - $container['RolesAndCapabilities'], - $container['WordPress'] - ); - } ); - - $container['SendToFacebookGroupListingTableAction'] = $container->service( function( $container ) { - return new AWPCP_SendToFacebookGroupListingTableAction( - $container['SendListingToFacebookHelper'], - $container['RolesAndCapabilities'], - $container['WordPress'] - ); - } ); - $container['ListingsTableNavHandler'] = $container->service( function( $container ) { return new AWPCP_ListingsTableNavHandler( $container['HTMLRenderer'], diff --git a/includes/admin/class-admin.php b/includes/admin/class-admin.php index 802c14ada..6296300fe 100644 --- a/includes/admin/class-admin.php +++ b/includes/admin/class-admin.php @@ -208,8 +208,6 @@ public function register_listings_table_actions( $actions ) { $actions['mark-paid'] = $this->container['MarkPaidListingTableAction']; $actions['mark-verified'] = $this->container['MarkVerifiedListingTableAction']; $actions['send-verification-email'] = $this->container['SendVerificationEmailTableAction']; - $actions['send-to-facebook-page'] = $this->container['SendToFacebookPageListingTableAction']; - $actions['send-to-facebook-group'] = $this->container['SendToFacebookGroupListingTableAction']; return $actions; } diff --git a/includes/admin/listings/class-send-to-facebook-group-listing-table-action.php b/includes/admin/listings/class-send-to-facebook-group-listing-table-action.php index 4a1199306..64ce32447 100644 --- a/includes/admin/listings/class-send-to-facebook-group-listing-table-action.php +++ b/includes/admin/listings/class-send-to-facebook-group-listing-table-action.php @@ -10,188 +10,66 @@ class AWPCP_SendToFacebookGroupListingTableAction implements AWPCP_ListTableActionInterface, AWPCP_ConditionalListTableActionInterface { - /** - * @var object - */ - private $facebook_helper; - - /** - * @var object - */ - private $wordpress; - - /** - * @var object - */ - private $roles; - - /** - * @since 4.0.0 - * - * @param object $facebook_helper An instance of Send To Facebook Helper. - * @param object $roles An instance of Roles and Capabilities. - * @param object $wordpress An instance of WordPress. - */ - public function __construct( $facebook_helper, $roles, $wordpress ) { - $this->facebook_helper = $facebook_helper; - $this->roles = $roles; - $this->wordpress = $wordpress; - } - /** * @since 4.0.0 */ public function is_needed() { + _deprecated_function( __FUNCTION__, '4.1.8' ); return $this->roles->current_user_is_moderator(); } /** * @since 4.0.0 - * - * @param object $post An instance of WP_Post. - * - * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ - public function should_show_action_for( $post ) { + public function should_show_action_for() { + _deprecated_function( __FUNCTION__, '4.1.8' ); return false; // Available as a bulk action only. } /** * @since 4.0.0 - * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ - public function get_icon_class( $post ) { - return awpcp_add_font_awesome_style_class_for_brands( 'fa-facebook-square' ); + public function get_icon_class() { + _deprecated_function( __FUNCTION__, '4.1.8' ); + return ''; } /** * @since 4.0.0 */ public function get_title() { - return _x( 'Send to Facebook Group', 'listing row action', 'another-wordpress-classifieds-plugin' ); + _deprecated_function( __FUNCTION__, '4.1.8' ); + return ''; } /** - * @param object $post An instance of WP_Post. * @since 4.0.0 - * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ - public function get_label( $post ) { + public function get_label() { + _deprecated_function( __FUNCTION__, '4.1.8' ); return $this->get_title(); } /** - * @param object $post An instance of WP_Post. - * @param string $current_url The URL of the current page. * @since 4.0.0 */ - public function get_url( $post, $current_url ) { - $params = array( - 'action' => 'send-to-facebook-group', - 'ids' => $post->ID, - ); - - return add_query_arg( $params, $current_url ); + public function get_url() { + _deprecated_function( __FUNCTION__, '4.1.8' ); } /** - * @param object $post An instance of WP_Post. * @since 4.0.0 */ - public function process_item( $post ) { - try { - $this->facebook_helper->send_listing_to_facebook_group( $post ); - } catch ( AWPCP_NoIntegrationMethodDefined $e ) { - return 'no-integration-method'; - } catch ( AWPCP_NoFacebookObjectSelectedException $e ) { - return 'no-group'; - } catch ( AWPCP_ListingAlreadySharedException $e ) { - return 'already-sent'; - } catch ( AWPCP_ListingDisabledException $e ) { - return 'disabled'; - } catch ( AWPCP_WebhooksNotCurrentlySupported $e ) { - return 'webhooks-not-supported'; - } catch ( AWPCP_Exception $e ) { - return 'error'; - } - + public function process_item() { + _deprecated_function( __FUNCTION__, '4.1.8' ); return 'success'; } /** - * @param array $result_codes An array of result codes from this action. * @since 4.0.0 */ - public function get_messages( $result_codes ) { - $messages = array(); - - foreach ( $result_codes as $code => $count ) { - $messages[] = $this->get_message( $code, $count ); - } - - return $messages; - } - - /** - * @param string $code Result code. - * @param int $count Number of posts associated with the given result - * code. - * @since 4.0.0 - */ - private function get_message( $code, $count ) { - if ( 'success' === $code ) { - $message = _n( 'Ad sent to Facebook group.', '{count} ads sent to Facebook group.', $count, 'another-wordpress-classifieds-plugin' ); - $message = str_replace( '{count}', $count, $message ); - - return awpcp_render_dismissible_success_message( $message ); - } - - if ( 'no-integration-method' === $code ) { - $url = awpcp_get_admin_settings_url( [ 'g' => 'facebook-settings' ] ); - - $message = _n( "1 ad couldn't be sent to Facebook because there is no integration method selected on {facebook_settings_link}Facebook Settings{/facebook_settings_link}.", "{count} ads couldn't be sent to Facebook because there is no integration method selected on {facebook_settings_link}Facebook Settings{/facebook_settings_link}.", $count, 'another-wordpress-classifieds-plugin' ); - $message = str_replace( '{count}', $count, $message ); - $message = str_replace( '{facebook_settings_link}', "", $message ); - $message = str_replace( '{/facebook_settings_link}', '', $message ); - - return awpcp_render_dismissible_error_message( $message ); - } - - if ( 'webhooks-not-supported' === $code ) { - $message = _n( "1 ad couldn't be sent to Facebook because sending ads to Facebook groups using webhooks is not currently supported.", "{count} ads couldn't be sent to Facebook because sending ads to Facebook groups using webhooks is not currently supported.", $count, 'another-wordpress-classifieds-plugin' ); - $message = str_replace( '{count}', $count, $message ); - - return awpcp_render_dismissible_error_message( $message ); - } - - if ( 'no-group' === $code ) { - $message = _n( "1 ad couldn't be sent to Facebook because there is no group selected.", "{count} ads couldn't be sent to Facebook because there is no group selected.", $count, 'another-wordpress-classifieds-plugin' ); - $message = str_replace( '{count}', $count, $message ); - - return awpcp_render_dismissible_error_message( $message ); - } - - if ( 'disabled' === $code ) { - $message = _n( "1 ad was not sent to Facebook because it is currenlty disabled. If you share it, Facebook servers and users won't be able to access it.", "{count} ads were not sent to Facebook because they are currenlty disabled. If you share them, Facebook servers and users won't be able to access them.", $count, 'another-wordpress-classifieds-plugin' ); - $message = str_replace( '{count}', $count, $message ); - - return awpcp_render_dismissible_error_message( $message ); - } - - if ( 'already-sent' === $code ) { - $message = _n( '1 ad was already sent to the Facebook group.', '{count} ads were already sent to the Facebook group.', $count, 'another-wordpress-classifieds-plugin' ); - $message = str_replace( '{count}', $count, $message ); - - return awpcp_render_dismissible_error_message( $message ); - } - - if ( 'error' === $code ) { - $message = _n( 'An error occurred trying to sent an ad to the Facebook group.', 'An error occurred trying to sent {count} ads to the Facebook group.', $count, 'another-wordpress-classifieds-plugin' ); - $message = str_replace( '{count}', $count, $message ); - - return awpcp_render_dismissible_error_message( $message ); - } - - return ''; + public function get_messages() { + _deprecated_function( __FUNCTION__, '4.1.8' ); + return array(); } } diff --git a/includes/admin/listings/class-send-to-facebook-page-listing-table-action.php b/includes/admin/listings/class-send-to-facebook-page-listing-table-action.php index 1f42aa2bd..2bb68dabb 100644 --- a/includes/admin/listings/class-send-to-facebook-page-listing-table-action.php +++ b/includes/admin/listings/class-send-to-facebook-page-listing-table-action.php @@ -10,11 +10,6 @@ class AWPCP_SendToFacebookPageListingTableAction implements AWPCP_ListTableActionInterface, AWPCP_ConditionalListTableActionInterface { - /** - * @var object - */ - private $facebook_helper; - /** * @var object */ @@ -33,7 +28,6 @@ class AWPCP_SendToFacebookPageListingTableAction implements * @param object $wordpress An instance of WordPress. */ public function __construct( $facebook_helper, $roles, $wordpress ) { - $this->facebook_helper = $facebook_helper; $this->roles = $roles; $this->wordpress = $wordpress; } @@ -59,14 +53,14 @@ public function should_show_action_for( $post ) { * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function get_icon_class( $post ) { - return awpcp_add_font_awesome_style_class_for_brands( 'fa-facebook-square' ); + return ''; } /** * @since 4.0.0 */ public function get_title() { - return _x( 'Send to Facebook Page', 'listing row action', 'another-wordpress-classifieds-plugin' ); + return ''; } /** @@ -84,12 +78,7 @@ public function get_label( $post ) { * @since 4.0.0 */ public function get_url( $post, $current_url ) { - $params = array( - 'action' => 'send-to-facebook-page', - 'ids' => $post->ID, - ); - - return add_query_arg( $params, $current_url ); + return ''; } /** @@ -97,20 +86,6 @@ public function get_url( $post, $current_url ) { * @since 4.0.0 */ public function process_item( $post ) { - try { - $this->facebook_helper->send_listing_to_facebook_page( $post ); - } catch ( AWPCP_NoIntegrationMethodDefined $e ) { - return 'no-integration-method'; - } catch ( AWPCP_NoFacebookObjectSelectedException $e ) { - return 'no-page'; - } catch ( AWPCP_ListingAlreadySharedException $e ) { - return 'already-sent'; - } catch ( AWPCP_ListingDisabledException $e ) { - return 'disabled'; - } catch ( AWPCP_Exception $e ) { - return 'error'; - } - return 'success'; } @@ -119,68 +94,6 @@ public function process_item( $post ) { * @since 4.0.0 */ public function get_messages( $result_codes ) { - $messages = array(); - - foreach ( $result_codes as $code => $count ) { - $messages[] = $this->get_message( $code, $count ); - } - - return $messages; - } - - /** - * @param string $code Result code. - * @param int $count Number of posts associated with the given result - * code. - * @since 4.0.0 - */ - private function get_message( $code, $count ) { - if ( 'success' === $code ) { - $message = _n( 'Ad sent to Facebook page.', '{count} ads sent to Facebook page.', $count, 'another-wordpress-classifieds-plugin' ); - $message = str_replace( '{count}', $count, $message ); - - return awpcp_render_dismissible_success_message( $message ); - } - - if ( 'no-integration-method' === $code ) { - $url = awpcp_get_admin_settings_url( [ 'g' => 'facebook-settings' ] ); - - $message = _n( "1 ad couldn't be sent to Facebook because there is no integration method selected on {facebook_settings_link}Facebook Settings{/facebook_settings_link}.", "{count} ads couldn't be sent to Facebook because there is no integration method selected on {facebook_settings_link}Facebook Settings{/facebook_settings_link}.", $count, 'another-wordpress-classifieds-plugin' ); - $message = str_replace( '{count}', $count, $message ); - $message = str_replace( '{facebook_settings_link}', "", $message ); - $message = str_replace( '{/facebook_settings_link}', '', $message ); - - return awpcp_render_dismissible_error_message( $message ); - } - - if ( 'no-page' === $code ) { - $message = _n( "1 ad couldn't be sent to Facebook because there is no page selected.", "{count} ads couldn't be sent to Facebook because there is no page selected.", $count, 'another-wordpress-classifieds-plugin' ); - $message = str_replace( '{count}', $count, $message ); - - return awpcp_render_dismissible_error_message( $message ); - } - - if ( 'disabled' === $code ) { - $message = _n( "1 ad was not sent to Facebook because it is currenlty disabled. If you share it, Facebook servers and users won't be able to access it.", "{count} ads were not sent to Facebook because they are currenlty disabled. If you share them, Facebook servers and users won't be able to access them.", $count, 'another-wordpress-classifieds-plugin' ); - $message = str_replace( '{count}', $count, $message ); - - return awpcp_render_dismissible_error_message( $message ); - } - - if ( 'already-sent' === $code ) { - $message = _n( '1 ad was already sent to the Facebook page.', '{count} ads were already sent to the Facebook page.', $count, 'another-wordpress-classifieds-plugin' ); - $message = str_replace( '{count}', $count, $message ); - - return awpcp_render_dismissible_error_message( $message ); - } - - if ( 'error' === $code ) { - $message = _n( 'An error occurred trying to sent an ad to the Facebook page.', 'An error occurred trying to sent {count} ads to the Facebook page.', $count, 'another-wordpress-classifieds-plugin' ); - $message = str_replace( '{count}', $count, $message ); - - return awpcp_render_dismissible_error_message( $message ); - } - - return ''; + return array(); } } diff --git a/includes/class-awpcp.php b/includes/class-awpcp.php index 27d8f76bf..681026edf 100644 --- a/includes/class-awpcp.php +++ b/includes/class-awpcp.php @@ -221,7 +221,6 @@ public function register_settings_handlers() { add_action( 'awpcp_register_settings', array( $general_settings, 'register_settings' ) ); add_filter( 'awpcp_validate_settings_general-settings', array( $general_settings, 'validate_group_settings' ), 10, 2 ); add_filter( 'awpcp_validate_settings_general-settings', array( $general_settings, 'validate_general_settings' ), 10, 2 ); - add_filter( 'awpcp_validate_settings_facebook-settings', [ $general_settings, 'validate_facebook_settings' ] ); add_filter( 'awpcp_validate_settings_subgroup_date-time-format-settings', array( $general_settings, 'validate_date_time_format_settings' ), 10, 2 ); add_filter( 'awpcp_validate_settings_subgroup_registration-settings',[ $general_settings, 'validate_registration_settings' ] ); add_filter( 'awpcp_validate_settings_subgroup_currency-format-settings',[ $general_settings, 'validate_currency_settings' ] ); @@ -263,6 +262,7 @@ public function register_settings_renderers( $renderers ) { $renderers['select'] = $this->container['SelectSettingsRenderer']; $renderers['textarea'] = $this->container['TextareaSettingsRenderer']; $renderers['radio'] = $this->container['RadioSettingsRenderer']; + $renderers['hidden'] = $this->container['HiddenSettingsRenderer']; $renderers['textfield'] = $this->container['TextfieldSettingsRenderer']; $renderers['button'] = $this->container['ButtonSettingsRenderer']; $renderers['password'] = $this->container['TextfieldSettingsRenderer']; @@ -355,13 +355,6 @@ public function init() { add_action( 'awpcp-transaction-status-updated', array( $handler, 'process_payment_transaction' ), 20 ); add_filter( 'awpcp-process-payment-transaction', array( $handler, 'process_payment_transaction' ), 20 ); - // load resources always required - $facebook_cache_helper = awpcp_facebook_cache_helper(); - add_action( 'awpcp-clear-ad-facebook-cache', array( $facebook_cache_helper, 'handle_clear_cache_event_hook' ), 10, 1 ); - - $send_to_facebook_helper = $this->container['SendListingToFacebookHelper']; - add_action( 'awpcp-send-listing-to-facebook', array( $send_to_facebook_helper, 'send_listing_to_facebook' ) ); - $categories_list_cache = $this->container['CategoriesListCache']; add_action( 'awpcp_clear_categories_list_cache', [ $categories_list_cache, 'clear' ] ); diff --git a/includes/class-container-configuration.php b/includes/class-container-configuration.php index 8ac534285..13066a397 100644 --- a/includes/class-container-configuration.php +++ b/includes/class-container-configuration.php @@ -99,17 +99,6 @@ public function modify( $container ) { return new AWPCP_Template_Renderer(); } ); - $container['SendListingToFacebookHelper'] = $container->service( function( $container ) { - return new AWPCP_SendToFacebookHelper( - AWPCP_Facebook::instance(), - awpcp_facebook_integration(), - $container['ListingRenderer'], - $container['ListingsCollection'], - $container['Settings'], - $container['WordPress'] - ); - } ); - $container['FormFieldsData'] = $container->service( function( $container ) { return new AWPCP_FormFieldsData( $container['ListingAuthorization'], diff --git a/includes/constructor-functions.php b/includes/constructor-functions.php index 47edbd761..535213ee6 100644 --- a/includes/constructor-functions.php +++ b/includes/constructor-functions.php @@ -175,17 +175,10 @@ function awpcp_attachments_logic() { } /** - * @since 4.0.0 Extracted from class-facebook-cache-helper.php. + * @since 4.0.0 */ function awpcp_facebook_cache_helper() { - $container = awpcp()->container; - - return new AWPCP_FacebookCacheHelper( - awpcp_facebook_integration(), - $container['ListingRenderer'], - $container['ListingsCollection'], - $container['Settings'] - ); + _deprecated_function( __FUNCTION__, '4.1.8' ); } /** diff --git a/includes/helpers/class-facebook-cache-helper.php b/includes/helpers/class-facebook-cache-helper.php index b8be900f2..bdf305a4c 100644 --- a/includes/helpers/class-facebook-cache-helper.php +++ b/includes/helpers/class-facebook-cache-helper.php @@ -9,94 +9,7 @@ */ class AWPCP_FacebookCacheHelper { - /** - * @var FacebookIntegration - */ - private $facebook_integration; - - /** - * @var ListingRenderer - */ - private $listing_renderer; - - /** - * @var ListingsCollection - */ - private $ads; - - /** - * @var Settings - */ - private $settings; - - public function __construct( $facebook_integration, $listing_renderer, $ads, $settings ) { - $this->facebook_integration = $facebook_integration; - $this->listing_renderer = $listing_renderer; - $this->ads = $ads; - $this->settings = $settings; - } - public function handle_clear_cache_event_hook( $ad_id ) { - try { - $ad = $this->ads->get( $ad_id ); - } catch ( AWPCP_Exception $e ) { - return; - } - - $this->clear_ad_cache( $ad ); - } - - /** - * @SuppressWarnings(ElseExpression) - */ - private function clear_ad_cache( $ad ) { - if ( is_null( $ad ) || ! $this->listing_renderer->is_public( $ad ) ) { - return; - } - - $user_token = $this->settings->get_option( 'facebook-user-access-token' ); - - if ( ! $user_token ) { - return; - } - - $args = array( - 'timeout' => 30, - 'body' => array( - 'id' => url_showad( $ad->ID ), - 'scrape' => true, - 'access_token' => $user_token, - ), - ); - - $response = wp_remote_post( 'https://graph.facebook.com/', $args ); - - if ( $this->is_successful_response( $response ) ) { - do_action( 'awpcp-listing-facebook-cache-cleared', $ad ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores - } else { - $this->facebook_integration->schedule_clear_cache_action( $ad, 5 * MINUTE_IN_SECONDS ); - } - } - - private function is_successful_response( $response ) { - if ( is_wp_error( $response ) || ! is_array( $response ) ) { - return false; - } elseif ( ! isset( $response['response']['code'] ) ) { - return false; - } elseif ( intval( $response['response']['code'] ) !== 200 ) { - return false; - } - - $listing_info = json_decode( $response['body'] ); - - if ( ! isset( $listing_info->type ) || $listing_info->type !== 'article' ) { - return false; - } elseif ( empty( $listing_info->title ) ) { - return false; - } elseif ( ! isset( $listing_info->description ) ) { - return false; - } - - return true; + _deprecated_function( __FUNCTION__, '4.1.8' ); } } diff --git a/includes/helpers/class-send-to-facebook-helper.php b/includes/helpers/class-send-to-facebook-helper.php index bca7c4411..1d259a581 100644 --- a/includes/helpers/class-send-to-facebook-helper.php +++ b/includes/helpers/class-send-to-facebook-helper.php @@ -3,14 +3,9 @@ * @package AWPCP\Listings\Facebook */ -// phpcs:disable - -/** - * @SuppressWarnings(PHPMD) - */ function awpcp_send_to_facebook_helper() { return new AWPCP_SendToFacebookHelper( - AWPCP_Facebook::instance(), + '', awpcp_facebook_integration(), awpcp_listing_renderer(), awpcp_listings_collection(), @@ -21,16 +16,6 @@ function awpcp_send_to_facebook_helper() { class AWPCP_SendToFacebookHelper { - /** - * @var Facebook - */ - private $facebook; - - /** - * @var FacebookIntegration - */ - private $facebook_integration; - /** * @var ListingsCollection */ @@ -42,8 +27,6 @@ class AWPCP_SendToFacebookHelper { private $settings; public function __construct( $facebook, $facebook_integration, $listing_renderer, $listings, $settings, $wordpress ) { - $this->facebook = $facebook; - $this->facebook_integration = $facebook_integration; $this->listing_renderer = $listing_renderer; $this->listings = $listings; $this->settings = $settings; @@ -62,14 +45,6 @@ public function send_listing_to_facebook( $listing_id ) { } catch ( AWPCP_Exception $e ) { // pass } - - try { - $this->send_listing_to_facebook_group( $listing ); - } catch ( AWPCP_Exception $e ) { - // pass - } - - $this->facebook_integration->maybe_schedelue_send_to_facebook_action( $listing ); } /** @@ -92,10 +67,6 @@ public function send_listing_to_facebook_page( $listing ) { throw new AWPCP_NoIntegrationMethodDefined(); } - if ( 'facebook-api' === $integration_method ) { - $listing_sent = $this->send_listing_to_facebook_page_using_facebook_api( $listing ); - } - if ( 'webhooks' === $integration_method ) { $listing_sent = $this->send_listing_to_facebook_page_using_webhook( $listing ); } @@ -109,48 +80,6 @@ public function send_listing_to_facebook_page( $listing ) { return $listing_sent; } - /** - * @since 3.8.6 - */ - private function send_listing_to_facebook_page_using_facebook_api( $listing ) { - $this->facebook->set_access_token( 'page_token' ); - - if ( ! $this->facebook->is_page_set() ) { - throw new AWPCP_NoFacebookObjectSelectedException( 'There is no Facebook Page selected.' ); - } - - $this->do_facebook_request( - $listing, - '/' . $this->settings->get_option( 'facebook-page' ) . '/feed', - 'POST' - ); - - return true; - } - - /** - * @SuppressWarnings(PHPMD) - */ - private function do_facebook_request( $listing, $path, $method ) { - $params = array( - 'link' => url_showad( $listing->ID ), - ); - - try { - $response = $this->facebook->api_request( $path, $method, $params ); - } catch ( Exception $e ) { - $message = __( "There was an error trying to contact Facebook servers: %s.", 'another-wordpress-classifieds-plugin' ); - $message = sprintf( $message, $e->getMessage() ); - throw new AWPCP_Exception( $message ); - } - - if ( ! $response || ! isset( $response->id ) ) { - $message = __( 'Facebook API returned the following errors: %s.', 'another-wordpress-classifieds-plugin' ); - $message = sprintf( $message, $this->facebook->get_last_error()->message ); - throw new AWPCP_Exception( $message ); - } - } - /** * @since 3.8.6 */ @@ -266,89 +195,6 @@ private function process_webhooks( $webhooks ) { * @throws AWPCP_Exception If the listing is not public. */ public function send_listing_to_facebook_group( $listing ) { - if ( $this->wordpress->get_post_meta( $listing->ID, '_awpcp_sent_to_facebook_group', true ) ) { - throw new AWPCP_ListingAlreadySharedException( __( 'The ad was already sent to a Facebook Group.', 'another-wordpress-classifieds-plugin' ) ); - } - - if ( ! $this->listing_renderer->is_public( $listing ) ) { - throw new AWPCP_ListingDisabledException( __( "The ad is currently disabled. If you share it, Facebook servers and users won't be able to access it.", 'another-wordpress-classifieds-plugin' ) ); - } - - $integration_method = $this->settings->get_option( 'facebook-integration-method' ); - $listing_sent = false; - - if ( empty( $integration_method ) ) { - throw new AWPCP_NoIntegrationMethodDefined(); - } - - if ( 'facebook-api' === $integration_method ) { - $listing_sent = $this->send_listing_to_facebook_group_using_facebook_api( $listing ); - } - - if ( 'webhooks' === $integration_method ) { - throw new AWPCP_WebhooksNotCurrentlySupported(); - } - - if ( ! $listing_sent ) { - throw new AWPCP_Exception( 'Unknown error.' ); - } - - $this->wordpress->update_post_meta( $listing->ID, '_awpcp_sent_to_facebook_group', true ); - - return $listing_sent; - } - - /** - * @since 3.8.6 - */ - private function send_listing_to_facebook_group_using_facebook_api( $listing ) { - $this->facebook->set_access_token( 'user_token' ); - - if ( ! $this->facebook->is_group_set() ) { - throw new AWPCP_NoFacebookObjectSelectedException( 'There is no Facebook Group selected.' ); - } - - $this->do_facebook_request( - $listing, - '/' . $this->settings->get_option( 'facebook-group' ) . '/feed', - 'POST' - ); - - return true; - } - - /** - * Users should choose Friends (or something more public), not Only Me, when the application - * request the permission, to avoid error: - * - * OAuthException: (#200) Insufficient permission to post to target on behalf of the viewer. - * - * http://stackoverflow.com/a/19653226/201354 - * - * @since 3.8.6 - * @SuppressWarnings(PHPMD.UnusedPrivateMethod) - */ - private function send_listing_to_facebook_group_using_webhook( $listing ) { - $webhooks = $this->get_webhooks_for_facebook_group_integration( $listing ); - - if ( empty( $webhooks ) ) { - throw new AWPCP_Exception( 'There is no webhook configured to send ads to a Facebook Group.' ); - } - - return $this->process_webhooks( $webhooks ); - } - - /** - * We expect to add support for sending ads to Facebook Groups using webhooks - * in the near future as the corresponding Zapier and IFTTT integrations - * get approved. - * - * @since 3.8.6 - * @SuppressWarnings(PHPMD.UnusedFormalParameter) - */ - private function get_webhooks_for_facebook_group_integration( $listing ) { - return array(); + _deprecated_function( __FUNCTION__, '4.1.8' ); } } - -// phpcs:enable diff --git a/includes/helpers/facebook.php b/includes/helpers/facebook.php index f61561941..c99a59711 100755 --- a/includes/helpers/facebook.php +++ b/includes/helpers/facebook.php @@ -8,126 +8,20 @@ class AWPCP_Facebook { const GRAPH_API_VERSION = 'v2.12'; - private static $instance = null; - private $access_token = ''; - private $last_error = null; - - /** - * @var Settings - */ - private $settings; - - public function __construct( $settings ) { - $this->settings = $settings; - } - - public function validate_config( &$errors ) { - $errors = !$errors ? array() : $errors; - - $app_id = $this->settings->get_option( 'facebook-app-id' ); - $app_secret = $this->settings->get_option( 'facebook-app-secret' ); - $user_token = $this->settings->get_option( 'facebook-user-access-token' ); - $page_id = $this->settings->get_option( 'facebook-page' ); - $page_token = $this->settings->get_option( 'facebook-page-access-token' ); - - $app_access_token = ''; - - if ( !$app_id || !$app_secret ) { - $errors[] = __( 'Missing App ID and Secret.', 'another-wordpress-classifieds-plugin' ); - return; - } - - if ( ! $user_id || ! $user_token ) { - $errors[] = __( 'Missing a valid User Access Token.', 'another-wordpress-classifieds-plugin' ); - return; - } - - $required_permissions = $this->get_required_permissions(); - - try { - $required_permissions_included = $this->user_token_has_required_permissions( $required_permissions ); - } catch ( AWPCP_Exception $e ) { - $errors[] = $e->getMessage(); - - return; - } - - if ( ! $required_permissions_included ) { - $message = __( 'User Access Token is valid but doesn\'t have the permissions required for AWPCP integration ({permissions}).', 'another-wordpress-classifieds-plugin' ); - $message = str_replace( '{permissions}', implode( ', ', $required_permissions ), $message ); - - $errors[] = $message; - - return; - } - - if ( !$page_token || !$page_id ) { - $errors[] = __( 'No Facebook page is selected (missing page id or token).', 'another-wordpress-classifieds-plugin' ); - } + public function validate_config() { + _deprecated_function( __FUNCTION__, '4.1.8' ); } /** * @since 3.8.6 */ public function get_required_permissions() { - if ( 'facebook-api' === $this->settings->get_option( 'facebook-integration-method' ) ) { - // From Access Token Debugger: manage_pages, pages_show_list, publish_pages, publish_to_groups, public_profile - // Required for API 3.1? - return array( - 'manage_pages', - 'publish_pages', - 'publish_to_groups', - ); - } - + _deprecated_function( __FUNCTION__, '4.1.8' ); return array(); } - /** - * @since 3.8.6 - */ - private function user_token_has_required_permissions( $required_permissions ) { - $this->set_access_token( 'user_token' ); - - $response = $this->api_request( '/me/permissions', 'GET', array() ); - - if ( ! $response && is_object( $response->last_error ) ) { - throw new AWPCP_Exception( $this->last_error->message ); - } - - if ( ! $response || ! isset( $response->data ) ) { - throw new AWPCP_Exception( __( 'Could not validate User Access Token.', 'another-wordpress-classifieds-plugin' ) ); - } - - $permissions = array(); - - foreach ( $response->data as $entry ) { - if ( $entry->status == 'granted' ) { - $permissions[] = $entry->permission; - } - } - - foreach ( $required_permissions as $permission ) { - if ( ! in_array( $permission, $permissions, true ) ) { - return false; - } - } - - return true; - } - - public function set_access_token( $key_or_token = '' ) { - $token = $key_or_token; - - if ( $key_or_token == 'page_token' ) { - $token = $this->settings->get_option( 'facebook-page-access-token' ); - } - - if ( $key_or_token == 'user_token' ) { - $token = $this->settings->get_option( 'facebook-user-access-token' ); - } - - $this->access_token = $token; + public function set_access_token() { + _deprecated_function( __FUNCTION__, '4.1.8' ); } public static function instance() { @@ -138,206 +32,40 @@ public static function instance() { } public function get_user_pages() { - $user_access_token = $this->settings->get_option( 'facebook-user-access-token' ); - - if ( empty( $user_access_token ) ) { - return array(); - } - - $this->set_access_token( $user_access_token ); - - $pages = array(); - - // Add own user page. - $response = $this->api_request( '/me', 'GET', array( 'fields' => 'id,name' ) ); - - if ( $response ) { - $pages[] = array( 'id' => $response->id, - 'name' => $response->name, - 'access_token' => $user_access_token, - 'profile' => true ); - } - - $after = null; - - do { - $response = $this->api_request( '/me/accounts', 'GET', array( - 'fields' => 'id,name,access_token,perms', - 'summary' => 'total_count', - 'after' => $after, - ) ); - - if ( $response && isset( $response->data ) ) { - foreach ( $response->data as &$p ) { - if ( in_array( 'CREATE_CONTENT', $p->perms, true ) ) { - $pages[] = array( - 'id' => $p->id, - 'name' => $p->name, - 'access_token' => $p->access_token - ); - } - } - } - - if ( ! isset( $response->paging->cursors->after ) || ! isset( $response->paging->next ) ) { - break; - } - - $after = $response->paging->cursors->after; - } while( $after ); - - return $pages; + _deprecated_function( __FUNCTION__, '4.1.8' ); } public function get_user_groups() { - $user_access_token = $this->settings->get_option( 'facebook-user-access-token' ); - - if ( empty( $user_access_token ) ) { - return array(); - } - - $this->set_access_token( $user_access_token ); - - $groups = array(); - $after = null; - - do { - $response = $this->api_request( '/me/groups', 'GET', array( - 'after' => $after, - ) ); - - if ( $response && isset( $response->data ) ) { - foreach ( $response->data as &$p ) { - $groups[] = array( - 'id' => $p->id, - 'name' => $p->name - ); - } - } - - if ( ! isset( $response->paging->cursors->after ) || ! isset( $response->paging->next ) ) { - break; - } - - $after = $response->paging->cursors->after; - } while( $after ); - - return $groups; + _deprecated_function( __FUNCTION__, '4.1.8' ); } public function get_login_url( $redirect_uri = '', $scope = '' ) { - $app_id = $this->settings->get_option( 'facebook-app-id' ); - - return sprintf( 'https://www.facebook.com/' . self::GRAPH_API_VERSION . '/dialog/oauth?client_id=%s&redirect_uri=%s&scope=%s', - $app_id, - urlencode( $redirect_uri ), - urlencode( $scope ) - ); + _deprecated_function( __FUNCTION__, '4.1.8' ); } - public function token_from_code( $code, $redirect_uri='' ) { - if ( !$code ) - return false; - - if ( !$redirect_uri ) { - // Assume $redirect_uri is the current URL sans stuff added by FB. - $redirect_uri = remove_query_arg( array( 'client_id', 'code', 'error', 'error_reason', 'error_description', 'redirect_uri' ), awpcp_current_url() ); - } - - $response = $this->api_request( '/oauth/access_token', - 'GET', - array( 'redirect_uri' => $redirect_uri, - 'code' => $code ), - true - ); - - if ( $response && isset( $response->access_token ) ) { - return $response->access_token; - } else { - return ''; - } + public function token_from_code() { + _deprecated_function( __FUNCTION__, '4.1.8' ); } - public function api_request( $path, $method = 'GET', $args = array(), $notoken=false, $json_decode=true ) { - $this->last_error = ''; - - $app_secret = $this->settings->get_option( 'facebook-app-secret' ); - - $url = 'https://graph.facebook.com/' . self::GRAPH_API_VERSION . '/' . ltrim( $path, '/' ); - $url .= '?client_id=' . $this->settings->get_option( 'facebook-app-id' ); - $url .= '&client_secret=' . $app_secret; - - if ( !$notoken && $this->access_token ) { - $url .= '&access_token=' . $this->access_token; - $url .= '&appsecret_proof=' . hash_hmac( 'sha256', $this->access_token, $app_secret ); - } - - if ( $method == 'GET' && $args ) { - foreach ( $args as $k => $v ) { - if ( in_array( $k, array( 'client_id', 'client_secret', 'access_token' ) ) ) - continue; - - $url .= '&' . $k . '=' . urlencode( $v ); - } - } - - $c = curl_init(); - curl_setopt( $c, CURLOPT_URL, $url ); - curl_setopt( $c, CURLOPT_HEADER, 0 ); - curl_setopt( $c, CURLOPT_RETURNTRANSFER, 1 ); - curl_setopt( $c, CURLOPT_SSL_VERIFYPEER, 1 ); - curl_setopt( $c, CURLOPT_CAINFO, AWPCP_DIR . '/cacert.pem' ); - - if ( $method == 'POST' ) { - curl_setopt( $c, CURLOPT_POST, 1 ); - curl_setopt( $c, CURLOPT_POSTFIELDS, $args ); - } - - $res = curl_exec( $c ); - $curl_error_number = curl_errno( $c ); - $curl_error_message = curl_error( $c ); - curl_close( $c ); - - if ( $curl_error_number === 0 ) { - $res = $json_decode ? json_decode( $res ) : $res; - - if ( isset( $res->error ) ) - $this->last_error = $res->error; - - $response = !$res || isset( $res->error ) ? false : $res; - } else { - $this->last_error = new stdClass(); - $this->last_error->message = $curl_error_message; - $response = false; - } - - return $response; + public function api_request() { + _deprecated_function( __FUNCTION__, '4.1.8' ); } /** * @since 3.0.2 */ public function get_last_error() { - return $this->last_error; + _deprecated_function( __FUNCTION__, '4.1.8' ); + return ''; } public function is_page_set() { - $page_id = $this->settings->get_option( 'facebook-page' ); - - if ( empty( $page_id ) ) { - return false; - } - - $page_token = $this->settings->get_option( 'facebook-page-access-token' ); - - if ( empty( $page_id ) ) { - return false; - } - - return true; + _deprecated_function( __FUNCTION__, '4.1.8' ); + return false; } public function is_group_set() { - return (bool) $this->settings->get_option( 'facebook-group' ); + _deprecated_function( __FUNCTION__, '4.1.8' ); + return false; } } diff --git a/includes/integrations/facebook/class-facebook-integration.php b/includes/integrations/facebook/class-facebook-integration.php index 609399091..1c0811bc0 100644 --- a/includes/integrations/facebook/class-facebook-integration.php +++ b/includes/integrations/facebook/class-facebook-integration.php @@ -31,26 +31,6 @@ public function __construct( $listing_renderer, $settings, $wordpress ) { * @since 3.8.6 */ public function on_ad_modified( $ad ) { - if ( $this->settings->get_option( 'clear-facebook-cache-when-listings-are-modified' ) ) { - $this->maybe_schedule_clear_cache_action( $ad ); - - return; - } - - $this->maybe_schedelue_send_to_facebook_action( $ad ); - } - - /** - * @since 3.8.6 - */ - private function maybe_schedule_clear_cache_action( $ad ) { - $user_token = $this->settings->get_option( 'facebook-user-access-token' ); - - if ( ! $user_token ) { - return; - } - - $this->schedule_clear_cache_action( $ad ); } /** @@ -75,31 +55,7 @@ private function schedule_action_seconds_from_now( $ad, $action, $wait_time ) { * @since 3.8.6 */ public function maybe_schedelue_send_to_facebook_action( $ad ) { - if ( ! $this->settings->get_option( 'sends-listings-to-facebook-automatically', true ) ) { - return; - } - - if ( ! $this->listing_renderer->is_public( $ad ) ) { - return; - } - - $page_integration_configured = $this->is_facebook_page_integration_configured(); - $already_sent_to_a_fb_page = $this->wordpress->get_post_meta( $ad->ID, '_awpcp_sent_to_facebook_page', true ); - - if ( $page_integration_configured && ! $already_sent_to_a_fb_page ) { - $this->schedule_send_to_facebook_action( $ad ); - - return; - } - - $group_integration_configured = $this->is_facebook_group_integration_configured(); - $already_sent_to_a_fb_group = $this->wordpress->get_post_meta( $ad->ID, '_awpcp_sent_to_facebook_group', true ); - - if ( $group_integration_configured && ! $already_sent_to_a_fb_group ) { - $this->schedule_send_to_facebook_action( $ad ); - - return; - } + _deprecated_function( __FUNCTION__, '4.1.8' ); } /** @@ -108,10 +64,6 @@ public function maybe_schedelue_send_to_facebook_action( $ad ) { public function is_facebook_page_integration_configured() { $integration_method = $this->settings->get_option( 'facebook-integration-method' ); - if ( 'facebook-api' === $integration_method && $this->settings->get_option( 'facebook-page' ) ) { - return true; - } - if ( 'webhooks' === $integration_method && $this->settings->get_option( 'zapier-webhook-for-facebook-page-integration' ) ) { return true; } @@ -142,12 +94,6 @@ private function is_ifttt_webhook_configured() { * @since 3.8.6 */ public function is_facebook_group_integration_configured() { - $integration_method = $this->settings->get_option( 'facebook-integration-method' ); - - if ( 'facebook-api' === $integration_method && $this->settings->get_option( 'facebook-group' ) ) { - return true; - } - return false; } @@ -162,6 +108,5 @@ private function schedule_send_to_facebook_action( $ad, $wait_time = 10 ) { * @since 3.8.6 */ public function on_ad_facebook_cache_cleared( $ad ) { - $this->maybe_schedelue_send_to_facebook_action( $ad ); } } diff --git a/includes/listings/facebook/class-webhooks-not-currently-supported.php b/includes/listings/facebook/class-webhooks-not-currently-supported.php deleted file mode 100644 index 0ed1cc9e3..000000000 --- a/includes/listings/facebook/class-webhooks-not-currently-supported.php +++ /dev/null @@ -1,14 +0,0 @@ - __( 'Facebook', 'another-wordpress-classifieds-plugin' ), 'id' => 'facebook-settings', 'priority' => 100, + 'conditions' => array( + 'sends-listings-to-facebook-automatically', + ), ] ); @@ -725,154 +728,39 @@ private function register_facebook_settings( $settings_manager ) { $settings_manager->add_settings_section( [ 'id' => 'general', - 'name' => __( 'General Settings', 'another-wordpress-classifieds-plugin' ), + 'name' => '', 'priority' => 10, 'subgroup' => 'facebook-settings', ] ); - $settings_manager->add_setting( - [ - 'id' => 'facebook-integration-method', - 'name' => __( 'Facebook Integration Method', 'another-wordpress-classifieds-plugin' ), - 'type' => 'radio', - 'default' => 'webhooks', - 'description' => __( 'Please note that sending ads to Facebook Groups is currently not available using Webhooks, after Facebook significantly reduced access to their APIs across all apps. You can read more about these changes here: https://developers.facebook.com/blog/post/2018/04/04/facebook-api-platform-product-changes/', 'another-wordpress-classifieds-plugin' ), - 'options' => [ - 'facebook-api' => __( 'Facebook API', 'another-wordpress-classifieds-plugin' ), - 'webhooks' => __( 'Zapier/IFTTT Webhooks', 'another-wordpress-classifieds-plugin' ), - ], - 'section' => 'general', - ] - ); - $settings_manager->add_setting( [ 'id' => 'sends-listings-to-facebook-automatically', 'name' => __( 'Send Ads to Facebook Automatically', 'another-wordpress-classifieds-plugin' ), 'type' => 'checkbox', - 'default' => 1, + 'default' => 0, 'description' => __( 'If checked, Ads will be sent to Facebook shortly after they are posted, enabled or edited, whichever occurs first. Please note that ads will be sent only once and disabled ads cannot be sent to Facebook.', 'another-wordpress-classifieds-plugin' ), 'section' => 'general', ] ); - $settings_manager->add_setting( - [ - 'id' => 'clear-facebook-cache-for-ads-pages', - 'name' => __( 'Ask Facebook to clear cache for ads pages', 'another-wordpress-classifieds-plugin' ), - 'type' => 'checkbox', - 'default' => false, - 'description' => __( 'Clearing Facebook cache is useful to ensure users always see the latest version when the ad is shared on Facebook Pages, Groups and user feeds.' ), - 'section' => 'general', - ] - ); - - $key = $settings_manager->add_settings_section( - [ - 'id' => 'facebook-application', - 'name' => __( 'Facebook Application', 'another-wordpress-classifieds-plugin' ), - 'priority' => 20, - 'callback' => array( $this, 'facebook_application_settings_section' ), - 'subgroup' => 'facebook-settings', - ] - ); - - $settings_manager->add_setting( - [ - 'id' => 'facebook-app-id', - 'name' => __( 'App Id', 'another-wordpress-classifieds-plugin' ), - 'type' => 'textfield', - 'default' => '', - 'description' => __( 'An application identifier associates your site, its pages, and visitor actions with a registered Facebook application.', 'another-wordpress-classifieds-plugin' ), - 'section' => 'facebook-application', - ] - ); - - $settings_manager->add_setting( - [ - 'id' => 'facebook-app-secret', - 'name' => __( 'App Secret', 'another-wordpress-classifieds-plugin' ), - 'type' => 'textfield', - 'default' => '', - 'description' => __( 'An application secret is a secret shared between Facebook and your application, similar to a password.', 'another-wordpress-classifieds-plugin' ), - 'section' => 'facebook-application', - ] - ); - - $settings_manager->add_settings_section( - [ - 'id' => 'facebook-user-authorization', - 'name' => __( 'Facebook User Authorization', 'another-wordpress-classifieds-plugin' ), - 'priority' => 30, - 'callback' => array( $this, 'facebook_user_authorization_section' ), - 'subgroup' => 'facebook-settings', - ] - ); - - $settings_manager->add_setting( - [ - 'id' => 'facebook-user-access-token', - 'name' => __( 'User Access Token', 'another-wordpress-classifieds-plugin' ), - 'type' => 'textfield', - 'default' => '', - 'description' => __( 'You can manually enter your user access token (if you know it) or log in to Facebook to get one using the link above.', 'another-wordpress-classifieds-plugin' ), - 'section' => 'facebook-user-authorization', - ] - ); - $settings_manager->add_settings_section( [ - 'id' => 'facebook-page-and-group-selection', - 'name' => __( 'Facebook Page and Group Selection', 'another-wordpress-classifieds-plugin' ), - 'priority' => 40, - 'callback' => array( $this, 'facebook_page_and_group_selection_section' ), + 'id' => 'zapier', + 'name' => __( 'Zapier Integration', 'another-wordpress-classifieds-plugin' ), + 'priority' => 50, 'subgroup' => 'facebook-settings', ] ); $settings_manager->add_setting( [ - 'id' => 'facebook-page', - 'name' => __( 'Facebook Page', 'another-wordpress-classifieds-plugin' ), - 'type' => 'radio', - 'default' => '', - 'description' => '', - 'options' => array( $this, 'facebook_page_options' ), - 'section' => 'facebook-page-and-group-selection', - ] - ); - - $settings_manager->add_setting( - [ - 'id' => 'facebook-group', - 'name' => __( 'Facebook Group', 'another-wordpress-classifieds-plugin' ), - 'type' => 'radio', - 'default' => '', - 'description' => '', - 'options' => array( $this, 'facebook_group_options' ), - 'section' => 'facebook-page-and-group-selection', - ] - ); - - $settings_manager->add_setting( - [ - 'id' => 'facebook-page-access-token', - 'name' => __( 'Facebook Page Access Token', 'another-wordpress-classifieds-plugin' ), - 'type' => 'textfield', + 'id' => 'facebook-integration-method', + 'name' => __( 'Facebook Integration Method', 'another-wordpress-classifieds-plugin' ), + 'type' => 'hidden', 'default' => '', - 'description' => '', - 'readonly' => true, - 'section' => 'facebook-page-and-group-selection', - ] - ); - - $settings_manager->add_settings_section( - [ - 'id' => 'zapier', - 'name' => __( 'Zapier Integration', 'another-wordpress-classifieds-plugin' ), - 'priority' => 50, - 'subgroup' => 'facebook-settings', + 'section' => 'zapier', ] ); @@ -923,104 +811,30 @@ private function register_facebook_settings( $settings_manager ) { * @since 3.8.6 */ public function facebook_application_settings_section() { - $content = __( 'You can find your application information in the Facebook Developer Apps page.', 'another-wordpress-classifieds-plugin' ); - $content = str_replace( '', '', $content ); - - // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped - echo $content; } /** * @since 3.8.6 - * @SuppressWarnings(PHPMD.ElseExpression) */ public function facebook_user_authorization_section() { - /** - * Choosing Public is important because: - * - http://stackoverflow.com/a/19653226/201354 - * - https://github.com/drodenbaugh/awpcp/issues/1288#issuecomment-134198377 - */ - $content = '

' . esc_html__( 'AWPCP needs to get an authorization token from Facebook to work correctly. You\'ll be redirected to Facebook to login. AWPCP does not store or obtain any personal information from your profile.', 'another-wordpress-classifieds-plugin' ) . '

'; - $content .= '

' . esc_html__( "Please choose Public as the audience for posts made by the application, even if you are just testing the integration. Facebook won't allow us to post content in some cases if you choose something else.", 'another-wordpress-classifieds-plugin' ) . '

'; - - if ( $this->settings->get_option( 'facebook-app-id' ) && $this->settings->get_option( 'facebook-app-secret' ) ) { - $facebook = AWPCP_Facebook::instance(); - - $redirect_uri = add_query_arg( 'obtain_user_token', 1, admin_url( '/admin.php?page=awpcp-admin-settings&g=facebook-settings' ) ); - $required_permissions = $facebook->get_required_permissions(); - $login_url = $facebook->get_login_url( $redirect_uri, implode( ',', $required_permissions ) ); - - $content .= '

' . __( 'Click here to obtain an access token from Facebook', 'another-wordpress-classifieds-plugin' ) . '

'; - } else { - $content .= '

' . esc_html__( 'Please provide a value for the App Id and App Secret settings before trying to get an access token from Facebook.', 'another-wordpress-classifieds-plugin' ) . '

'; - } - - // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped - echo $content; } /** * @sicne 3.8.6 */ public function facebook_page_and_group_selection_section() { - $content = '

' . esc_html__( 'Available Facebook Pages and Groups will be displayed after you enter a valid User Access Token.', 'another-wordpress-classifieds-plugin' ) . '

'; - $content .= '

' . __( 'As of April 4, 2018, all applications need to go through App Review in order to get access to the Page API and Groups API. That means that you may need to submit your app for review (ask for the manage_pages, publish_pages, publish_to_groups permissions), before AWPCP can display the list of pages and groups you manage and be able to post classifieds ads to those groups and pages.', 'another-wordpress-classifieds-plugin' ) . '

'; - - // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped - echo $content; } /** * @since 3.8.6 */ public function facebook_page_options() { - $facebook = AWPCP_Facebook::instance(); - $facebook_pages = $facebook->get_user_pages(); - - if ( empty( $facebook_pages ) ) { - return array(); - } - - $pages = array( - 'none' => __( 'None (Do not sent ads to a Facebook Page)', 'another-wordpress-classifieds-plugin' ), - ); - - foreach ( $facebook_pages as $page ) { - $page_name = $page['name']; - - if ( ! empty( $page['profile'] ) ) { - $page_name = $page_name . ' ' . __( '(Your own profile page)', 'another-wordpress-classifieds-plugin' ); - } - - $pages[ $page['id'] ] = array( - 'value' => "{$page['id']}|{$page['access_token']}", - 'label' => $page_name, - ); - } - - return $pages; } /** * @since 3.8.6 */ public function facebook_group_options() { - $facebook = AWPCP_Facebook::instance(); - $facebook_groups = $facebook->get_user_groups(); - - if ( empty( $facebook_groups ) ) { - return array(); - } - - $groups = array( - 'none' => __( 'None (Do not sent ads to a Facebook Group)', 'another-wordpress-classifieds-plugin' ), - ); - - foreach ( $facebook_groups as $group ) { - $groups[ $group['id'] ] = $group['name']; - } - - return $groups; } @@ -1177,34 +991,6 @@ public function validate_registration_settings( $options ) { * @since 3.8.6 */ public function validate_facebook_settings( $options ) { - $options['facebook-app-id'] = trim( $options['facebook-app-id'] ); - $options['facebook-app-secret'] = trim( $options['facebook-app-secret'] ); - $options['facebook-user-access-token'] = trim( $options['facebook-user-access-token'] ); - - if ( $options['facebook-app-id'] !== $this->settings->get_option( 'facebook-app-id' ) || $options['facebook-app-secret'] !== $this->settings->get_option( 'facebook-app-secret' ) ) { - $options['facebook-user-access-token'] = ''; - $options['facebook-page'] = ''; - $options['facebook-group'] = ''; - $options['facebook-page-access-token'] = ''; - } - - if ( $options['facebook-user-access-token'] !== $this->settings->get_option( 'facebook-user-access-token' ) ) { - $options['facebook-page'] = ''; - $options['facebook-group'] = ''; - $options['facebook-page-access-token'] = ''; - } - - if ( ! empty( $options['facebook-page'] ) && 'none' === $options['facebook-page'] ) { - $options['facebook-page-access-token'] = ''; - } - - if ( ! empty( $options['facebook-page'] ) && strpos( $options['facebook-page'], '|' ) !== false ) { - $parts = explode( '|', $options['facebook-page'] ); - - $options['facebook-page'] = $parts[0]; - $options['facebook-page-access-token'] = $parts[1]; - } - return $options; } } diff --git a/includes/settings/class-settings-container-configuration.php b/includes/settings/class-settings-container-configuration.php index 09683038e..75394d341 100644 --- a/includes/settings/class-settings-container-configuration.php +++ b/includes/settings/class-settings-container-configuration.php @@ -123,6 +123,12 @@ private function define_settings_renderers( $container ) { ); } ); + $container['HiddenSettingsRenderer'] = $container->service( function( $container ) { + return new AWPCP_HiddenSettingsRenderer( + $container['Settings'] + ); + } ); + $container['TextfieldSettingsRenderer'] = $container->service( function( $container ) { return new AWPCP_TextfieldSettingsRenderer( $container['Settings'] diff --git a/includes/settings/class-settings-integration.php b/includes/settings/class-settings-integration.php index 44d3aefc2..36fceb697 100644 --- a/includes/settings/class-settings-integration.php +++ b/includes/settings/class-settings-integration.php @@ -65,7 +65,7 @@ public function setup() { * @since 4.0.0 */ public function add_settings_sections() { - foreach ( $this->settings_manager->get_settings_groups() as $group ) { + foreach ( $this->settings_manager->get_settings_groups( true ) as $group ) { $this->add_settings_sections_for_group( $group ); } } @@ -117,7 +117,7 @@ private function add_settings_sections_for_section( $section ) { add_settings_field( $setting['id'], - $setting['name'], + $setting['type'] === 'hidden' ? '' : $setting['name'], [ $this->settings_renderer, 'render_setting' ], $section['subgroup'], $section['id'], diff --git a/includes/settings/class-settings-manager.php b/includes/settings/class-settings-manager.php index 057331968..0fa049413 100644 --- a/includes/settings/class-settings-manager.php +++ b/includes/settings/class-settings-manager.php @@ -31,8 +31,30 @@ class AWPCP_SettingsManager { /** * @since 4.0.0 */ - public function get_settings_groups() { - return $this->groups; + public function get_settings_groups( $conditions = false ) { + $groups = $this->groups; + if ( ! $conditions ) { + return $groups; + } + + // Check if the group should be included. + foreach ( $groups as $k => $group ) { + if ( empty( $group['conditions'] ) ) { + continue; + } + + $clear = true; + foreach ( $group['conditions'] as $condition ) { + $value = get_awpcp_option( $condition ); + if ( ! empty( $value ) ) { + $clear = false; + } + } + if ( $clear ) { + unset( $groups[ $k ] ); + } + } + return $groups; } /** @@ -54,6 +76,7 @@ public function add_settings_group( $params ) { 'id' => null, 'name' => null, 'priority' => 10, + 'conditions' => '', ] ); $group['subgroups'] = []; diff --git a/includes/settings/renderers/class-hidden-settings-renderer.php b/includes/settings/renderers/class-hidden-settings-renderer.php new file mode 100644 index 000000000..99a43f6e9 --- /dev/null +++ b/includes/settings/renderers/class-hidden-settings-renderer.php @@ -0,0 +1,31 @@ +settings = $settings; + } + + /** + * @since x.x + */ + public function render_setting( $setting ) { + $current = esc_html( stripslashes( $this->settings->get_option( $setting['id'] ) ) ); + + echo ''; + } +} diff --git a/installer.php b/installer.php index 34017a0ec..5065c35ad 100644 --- a/installer.php +++ b/installer.php @@ -289,9 +289,6 @@ private function get_upgrade_routines() { 'convert_tables_to_innodb', 'create_listings_table_if_missing', ), - '3.8.6' => array( - 'migrate_facebook_integration_settings', - ), '4.0.0beta1' => array( 'create_old_listing_id_column_in_listing_regions_table', 'migrate_wordpress_page_settings', @@ -785,46 +782,6 @@ private function create_listings_table_if_missing() { } } - /** - * @since 3.8.6 - */ - private function migrate_facebook_integration_settings() { - $settings = awpcp()->settings; - $config = get_option( 'awpcp-facebook-config', array() ); - - if ( ! empty( $config['app_id'] ) ) { - $settings->set_or_update_option( 'facebook-app-id', $config['app_id'] ); - } - - if ( ! empty( $config['app_secret'] ) ) { - $settings->set_or_update_option( 'facebook-app-secret', $config['app_secret'] ); - } - - if ( ! empty( $config['user_token'] ) ) { - $settings->set_or_update_option( 'facebook-user-access-token', $config['user_token'] ); - } - - if ( ! empty( $config['page_id'] ) ) { - $settings->set_or_update_option( 'facebook-page', $config['page_id'] . '|' . $config['page_token'] ); - } - - if ( ! empty( $config['page_token'] ) ) { - $settings->set_or_update_option( 'facebook-page-access-token', $config['page_token'] ); - } - - if ( ! empty( $config['group_id'] ) ) { - $settings->set_or_update_option( 'facebook-group', $config['group_id'] ); - } - - if ( ! empty( $config['app_id'] ) && ! empty( $config['app_secret'] ) && ! empty( $config['user_token'] ) ) { - $settings->set_or_update_option( 'clear-facebook-cache-for-ads-pages', true ); - } - - if ( ! empty( $config['app_id'] ) && ! empty( $config['app_secret'] ) ) { - $settings->set_or_update_option( 'facebook-integration-method', 'facebook-api' ); - } - } - private function create_old_listing_id_column_in_listing_regions_table() { global $wpdb; diff --git a/requires.php b/requires.php index 324421239..134dcf5fb 100644 --- a/requires.php +++ b/requires.php @@ -85,7 +85,6 @@ require_once AWPCP_DIR . '/includes/helpers/class-akismet-wrapper.php'; require_once AWPCP_DIR . '/includes/helpers/class-akismet-wrapper-factory.php'; require_once AWPCP_DIR . '/includes/helpers/class-awpcp-request.php'; -require_once AWPCP_DIR . '/includes/helpers/class-facebook-cache-helper.php'; require_once AWPCP_DIR . '/includes/helpers/class-file-cache.php'; require_once AWPCP_DIR . '/includes/helpers/class-http.php'; require_once AWPCP_DIR . '/includes/helpers/class-listing-akismet-data-source.php'; @@ -94,10 +93,8 @@ require_once AWPCP_DIR . '/includes/helpers/class-page-title-builder.php'; require_once AWPCP_DIR . '/includes/helpers/class-payment-transaction-helper.php'; require_once AWPCP_DIR . '/includes/helpers/class-recaptcha-v3.php'; -require_once AWPCP_DIR . '/includes/helpers/class-send-to-facebook-helper.php'; require_once AWPCP_DIR . '/includes/helpers/class-spam-filter.php'; require_once AWPCP_DIR . '/includes/helpers/class-spam-submitter.php'; -require_once AWPCP_DIR . '/includes/helpers/facebook.php'; require_once AWPCP_DIR . '/includes/helpers/list-table.php'; require_once AWPCP_DIR . '/includes/helpers/email.php'; require_once AWPCP_DIR . '/includes/helpers/javascript.php'; diff --git a/resources/less/legacy/admin.less b/resources/less/legacy/admin.less index 9d4c78573..b519451c9 100644 --- a/resources/less/legacy/admin.less +++ b/resources/less/legacy/admin.less @@ -453,16 +453,3 @@ #awpcp-admin-comments .comments .column-content { width: 30%; } - - -/* Facebook Settings. */ -.awpcp-facebook-inline-documentation { - padding: 0 0 40px; -} - -#awpcp-admin-settings .facebook-integration-diagnostics { - padding: 2px 10px; - background: #d7f5ff; - border: solid 1px #bad5df; - border-radius: 4px; -} diff --git a/tests/suite/admin/listings/test-send-to-facebook-group-listing-table-action.php b/tests/suite/admin/listings/test-send-to-facebook-group-listing-table-action.php deleted file mode 100644 index f95c36798..000000000 --- a/tests/suite/admin/listings/test-send-to-facebook-group-listing-table-action.php +++ /dev/null @@ -1,229 +0,0 @@ -facebook_helper = null; - $this->roles_and_capabilities = Mockery::mock( 'AWPCP_RolesAndCapabilities' ); - $this->wordpress = null; - } - - /** - * @since 4.0.0 - */ - public function test_should_show_action_for() { - $post = (object) []; - - $this->roles_and_capabilities->shouldReceive( 'current_user_is_moderator' ) - ->andReturn( true ); - - $action = $this->get_test_subject(); - - // Execution. - $should = $action->should_show_action_for( $post ); - - // Verification. - $this->assertFalse( $should ); - } - - /** - * @since 4.0.0 - */ - private function get_test_subject() { - return new AWPCP_SendToFacebookGroupListingTableAction( - $this->facebook_helper, - $this->roles_and_capabilities, - $this->wordpress - ); - } - - /** - * @since 4.0.0 - */ - public function test_get_label() { - $action = $this->get_test_subject(); - - // Execution. - $label = $action->get_label( null ); - - // Verification. - $this->assertStringContainsString( 'Facebook Group', $label ); - } - - /** - * @since 4.0.0 - */ - public function test_get_url() { - $post = (object) array( - 'ID' => wp_rand() + 1, - ); - - $current_url = 'https://example.org'; - $params = array( - 'action' => 'send-to-facebook-group', - 'ids' => $post->ID, - ); - - Functions\expect( 'add_query_arg' ) - ->once() - ->with( $params, $current_url ) - ->andReturn( $current_url ); - - $action = $this->get_test_subject(); - - // Execution. - $url = $action->get_url( $post, $current_url ); - - // Verification. - $this->assertNotEmpty( $url ); - } - - /** - * @since 4.0.0 - */ - public function test_process_item() { - $post = (object) array( - 'ID' => wp_rand() + 1, - ); - - $this->facebook_helper = Mockery::mock( 'AWPCP_SendToFacebookHelper' ); - - $this->facebook_helper->shouldReceive( 'send_listing_to_facebook_group' ) - ->once() - ->with( $post ) - ->andReturn( true ); - - $action = $this->get_test_subject(); - - // Execution. - $result_code = $action->process_item( $post ); - - // Verification. - $this->assertEquals( 'success', $result_code ); - } - - /** - * @since 4.0.0 - */ - public function test_process_item_returns_error() { - $post = (object) array( - 'ID' => wp_rand() + 1, - ); - - $this->facebook_helper = Mockery::mock( 'AWPCP_SendToFacebookHelper' ); - - $this->facebook_helper->shouldReceive( 'send_listing_to_facebook_group' ) - ->once() - ->with( $post ) - ->andThrow( new AWPCP_Exception() ); - - $action = $this->get_test_subject(); - - // Execution. - $result_code = $action->process_item( $post ); - - // Verification. - $this->assertEquals( 'error', $result_code ); - } - - /** - * @since 4.0.0 - */ - public function test_get_success_messages() { - $result_codes = array( - 'success' => 1, - ); - - $action = $this->get_test_subject(); - - // Execution. - $messages = $action->get_messages( $result_codes ); - - // Verification. - $this->assertStringContainsString( 'notice-success', $messages[0] ); - $this->assertStringContainsString( 'sent to Facebook group', $messages[0] ); - } - - /** - * @since 4.0.0 - */ - public function test_get_no_group_error_messages() { - $result_codes = array( - 'no-group' => 1, - ); - - $action = $this->get_test_subject(); - - // Execution. - $messages = $action->get_messages( $result_codes ); - - // Verification. - $this->assertStringContainsString( 'notice-error', $messages[0] ); - $this->assertStringContainsString( 'group selected', $messages[0] ); - } - - /** - * @since 4.0.0 - */ - public function test_get_disabled_error_messages() { - $result_codes = array( - 'disabled' => 1, - ); - - $action = $this->get_test_subject(); - - // Execution. - $messages = $action->get_messages( $result_codes ); - - // Verification. - $this->assertStringContainsString( 'notice-error', $messages[0] ); - $this->assertStringContainsString( 'disabled', $messages[0] ); - } - - /** - * @since 4.0.0 - */ - public function test_get_already_sent_error_messages() { - $result_codes = array( - 'already-sent' => 1, - ); - - $action = $this->get_test_subject(); - - // Execution. - $messages = $action->get_messages( $result_codes ); - - // Verification. - $this->assertStringContainsString( 'notice-error', $messages[0] ); - $this->assertStringContainsString( 'already sent', $messages[0] ); - } - - /** - * @since 4.0.0 - */ - public function test_get_error_messages() { - $result_codes = array( - 'error' => 1, - ); - - $action = $this->get_test_subject(); - - // Execution. - $messages = $action->get_messages( $result_codes ); - - // Verification. - $this->assertStringContainsString( 'notice-error', $messages[0] ); - $this->assertStringContainsString( 'to the Facebook group.', $messages[0] ); - } -} diff --git a/tests/suite/admin/listings/test-send-to-facebook-page-listing-table-action.php b/tests/suite/admin/listings/test-send-to-facebook-page-listing-table-action.php deleted file mode 100644 index 6c597dd5f..000000000 --- a/tests/suite/admin/listings/test-send-to-facebook-page-listing-table-action.php +++ /dev/null @@ -1,229 +0,0 @@ -facebook_helper = null; - $this->roles_and_capabilities = Mockery::mock( 'AWPCP_RolesAndCapabilities' ); - $this->wordpress = null; - } - - /** - * @since 4.0.0 - */ - public function test_should_show_action_for() { - $post = (object) []; - - $this->roles_and_capabilities->shouldReceive( 'current_user_is_moderator' ) - ->andReturn( true ); - - $action = $this->get_test_subject(); - - // Execution. - $should = $action->should_show_action_for( $post ); - - // Verification. - $this->assertFalse( $should ); - } - - /** - * @since 4.0.0 - */ - private function get_test_subject() { - return new AWPCP_SendToFacebookPageListingTableAction( - $this->facebook_helper, - $this->roles_and_capabilities, - $this->wordpress - ); - } - - /** - * @since 4.0.0 - */ - public function test_get_label() { - $action = $this->get_test_subject(); - - // Execution. - $label = $action->get_label( null ); - - // Verification. - $this->assertStringContainsString( 'Facebook Page', $label ); - } - - /** - * @since 4.0.0 - */ - public function test_get_url() { - $post = (object) array( - 'ID' => wp_rand() + 1, - ); - - $current_url = 'https://example.org'; - $params = array( - 'action' => 'send-to-facebook-page', - 'ids' => $post->ID, - ); - - Functions\expect( 'add_query_arg' ) - ->once() - ->with( $params, $current_url ) - ->andReturn( $current_url ); - - $action = $this->get_test_subject(); - - // Execution. - $url = $action->get_url( $post, $current_url ); - - // Verification. - $this->assertNotEmpty( $url ); - } - - /** - * @since 4.0.0 - */ - public function test_process_item() { - $post = (object) array( - 'ID' => wp_rand() + 1, - ); - - $this->facebook_helper = Mockery::mock( 'AWPCP_SendToFacebookHelper' ); - - $this->facebook_helper->shouldReceive( 'send_listing_to_facebook_page' ) - ->once() - ->with( $post ) - ->andReturn( true ); - - $action = $this->get_test_subject(); - - // Execution. - $result_code = $action->process_item( $post ); - - // Verification. - $this->assertEquals( 'success', $result_code ); - } - - /** - * @since 4.0.0 - */ - public function test_process_item_returns_error() { - $post = (object) array( - 'ID' => wp_rand() + 1, - ); - - $this->facebook_helper = Mockery::mock( 'AWPCP_SendToFacebookHelper' ); - - $this->facebook_helper->shouldReceive( 'send_listing_to_facebook_page' ) - ->once() - ->with( $post ) - ->andThrow( new AWPCP_Exception() ); - - $action = $this->get_test_subject(); - - // Execution. - $result_code = $action->process_item( $post ); - - // Verification. - $this->assertEquals( 'error', $result_code ); - } - - /** - * @since 4.0.0 - */ - public function test_get_success_messages() { - $result_codes = array( - 'success' => 1, - ); - - $action = $this->get_test_subject(); - - // Execution. - $messages = $action->get_messages( $result_codes ); - - // Verification. - $this->assertStringContainsString( 'notice-success', $messages[0] ); - $this->assertStringContainsString( 'sent to Facebook page', $messages[0] ); - } - - /** - * @since 4.0.0 - */ - public function test_get_no_page_error_messages() { - $result_codes = array( - 'no-page' => 1, - ); - - $action = $this->get_test_subject(); - - // Execution. - $messages = $action->get_messages( $result_codes ); - - // Verification. - $this->assertStringContainsString( 'notice-error', $messages[0] ); - $this->assertStringContainsString( 'page selected', $messages[0] ); - } - - /** - * @since 4.0.0 - */ - public function test_get_disabled_error_messages() { - $result_codes = array( - 'disabled' => 1, - ); - - $action = $this->get_test_subject(); - - // Execution. - $messages = $action->get_messages( $result_codes ); - - // Verification. - $this->assertStringContainsString( 'notice-error', $messages[0] ); - $this->assertStringContainsString( 'disabled', $messages[0] ); - } - - /** - * @since 4.0.0 - */ - public function test_get_already_sent_error_messages() { - $result_codes = array( - 'already-sent' => 1, - ); - - $action = $this->get_test_subject(); - - // Execution. - $messages = $action->get_messages( $result_codes ); - - // Verification. - $this->assertStringContainsString( 'notice-error', $messages[0] ); - $this->assertStringContainsString( 'already sent', $messages[0] ); - } - - /** - * @since 4.0.0 - */ - public function test_get_error_messages() { - $result_codes = array( - 'error' => 1, - ); - - $action = $this->get_test_subject(); - - // Execution. - $messages = $action->get_messages( $result_codes ); - - // Verification. - $this->assertStringContainsString( 'notice-error', $messages[0] ); - $this->assertStringContainsString( 'to the Facebook page.', $messages[0] ); - } -} diff --git a/tests/suite/admin/test-admin.php b/tests/suite/admin/test-admin.php index 4ac05a054..6fae2c642 100644 --- a/tests/suite/admin/test-admin.php +++ b/tests/suite/admin/test-admin.php @@ -163,8 +163,6 @@ public function test_register_listings_table_actions() { $this->container['MarkPaidListingTableAction'] = null; $this->container['MarkVerifiedListingTableAction'] = null; $this->container['SendVerificationEmailTableAction'] = null; - $this->container['SendToFacebookPageListingTableAction'] = null; - $this->container['SendToFacebookGroupListingTableAction'] = null; $admin = $this->get_test_subject(); @@ -182,8 +180,6 @@ public function test_register_listings_table_actions() { $this->assertArrayHasKey( 'renew', $actions ); $this->assertArrayHasKey( 'make-featured', $actions ); $this->assertArrayHasKey( 'make-standard', $actions ); - $this->assertArrayHasKey( 'send-to-facebook-page', $actions ); - $this->assertArrayHasKey( 'send-to-facebook-group', $actions ); $this->assertArrayHasKey( 'mark-reviewed', $actions ); // // $this->assertArrayHasKey( 'manage-attachments', $actions ); // // phpcs:enable Squiz.PHP.CommentedOutCode.Found diff --git a/tests/suite/includes/helpers/test-facebook-integration.php b/tests/suite/includes/helpers/test-facebook-integration.php deleted file mode 100644 index eef05d08e..000000000 --- a/tests/suite/includes/helpers/test-facebook-integration.php +++ /dev/null @@ -1,62 +0,0 @@ -facebook_config = Phake::mock( 'AWPCP_Facebook' ); - $this->facebook_helper = Phake::mock( 'AWPCP_SendToFacebookHelper' ); - $this->settings = Phake::mock( 'AWPCP_Settings_API' ); - $this->listing_renderer = Phake::mock( 'AWPCP_ListingRenderer' ); - $this->wordpress = Phake::mock( 'AWPCP_WordPress' ); - } - - public function test_schedule_listing_if_necessary() { - $listing = (object) [ - 'ID' => wp_rand(), - ]; - - $current_time = wp_rand(); - $cron_parameters = array( $listing->ID, $current_time ); - - Phake::when( $this->settings )->get_option( 'sends-listings-to-facebook-automatically', true )->thenReturn( true ); - Phake::when( $this->settings )->get_option( 'facebook-integration-method' )->thenReturn( 'facebook-api' ); - Phake::when( $this->settings )->get_option( 'facebook-page' )->thenReturn( 'FACEBOOKPAGEID' ); - - Phake::when( $this->listing_renderer )->is_public->thenReturn( true ); - - Phake::when( $this->wordpress )->current_time->thenReturn( $current_time ); - - Functions\when( 'wp_next_scheduled' )->justReturn( false ); - - $this->get_test_subject()->maybe_schedelue_send_to_facebook_action( $listing ); - - Phake::verify( $this->wordpress )->schedule_single_event( - Phake::capture( $timestamp ), - Phake::capture( $hook ), - Phake::capture( $args ) - ); - - $this->assertEquals( 'awpcp-send-listing-to-facebook', $hook ); - $this->assertEquals( $cron_parameters, $args ); - } - - /** - * @since 3.8.6 - */ - private function get_test_subject() { - return new AWPCP_FacebookIntegration( - $this->listing_renderer, - $this->settings, - $this->wordpress - ); - } -} diff --git a/tests/suite/includes/test-awpcp.php b/tests/suite/includes/test-awpcp.php index cdada77b4..41813b789 100644 --- a/tests/suite/includes/test-awpcp.php +++ b/tests/suite/includes/test-awpcp.php @@ -69,8 +69,6 @@ public function test_init_register_listing_payment_transaction_handler_hooks_on_ $this->container['SendListingToFacebookHelper'] = Mockery::mock( 'AWPCP_SendToFacebookHelper' ); $this->container['CategoriesListCache'] = Mockery::mock( 'AWPCP_CategoriesListCache' ); - Functions\when( 'awpcp_facebook_cache_helper' )->justReturn( Mockery::mock( 'AWPCP_FacebookCacheHelper' ) ); - Functions\when( 'wp_doing_ajax' )->justReturn( true ); Functions\when( 'is_admin' )->justReturn( true ); diff --git a/tests/suite/listings/facebook/test-send-to-facebook-helper.php b/tests/suite/listings/facebook/test-send-to-facebook-helper.php deleted file mode 100644 index 8b1fff6a9..000000000 --- a/tests/suite/listings/facebook/test-send-to-facebook-helper.php +++ /dev/null @@ -1,119 +0,0 @@ -facebook = Mockery::mock( 'AWPCP_SendToFacebookHelper' ); - $this->listing_renderer = Mockery::mock( 'AWPCP_ListingRenderer' ); - $this->settings = Mockery::mock( 'AWPCP_Settings' ); - $this->wordpress = Mockery::mock( 'AWPCP_WordPress' ); - } - - /** - * @expectedException AWPCP_NoFacebookObjectSelectedException - * @expectedExceptionMessage There is no Facebook Group selected. - */ - public function test_send_listing_to_facebook_group_when_no_group_is_selected() { - $listing = (object) array( - 'ID' => wp_rand(), - ); - - $this->facebook->shouldReceive( 'set_access_token' ) - ->andReturn( null ); - - $this->facebook->shouldReceive( 'is_group_set' ) - ->andReturn( false ); - - $this->listing_renderer->shouldReceive( 'is_public' ) - ->andReturn( true ); - - $this->settings->shouldReceive( 'get_option' ) - ->with( 'facebook-integration-method' ) - ->andReturn( 'facebook-api' ); - - $this->wordpress->shouldReceive( 'get_post_meta' ) - ->andReturn( false ); - - $helper = $this->get_test_subject(); - - // Execution. - $helper->send_listing_to_facebook_group( $listing ); - } - - /** - * @since 4.0.0 - */ - private function get_test_subject() { - return new AWPCP_SendToFacebookHelper( - $this->facebook, - null, - $this->listing_renderer, - null, - $this->settings, - $this->wordpress - ); - } - - /** - * @expectedException AWPCP_ListingAlreadySharedException - * @expectedExceptionMessage The ad was already sent to a Facebook Group. - */ - public function test_send_listing_to_facebook_group_when_listing_was_already_sent() { - $listing = (object) array( - 'ID' => wp_rand(), - ); - - $this->facebook->shouldReceive( 'set_access_token' ) - ->andReturn( null ); - - $this->facebook->shouldReceive( 'is_group_set' ) - ->andReturn( true ); - - $this->wordpress->shouldReceive( 'get_post_meta' ) - ->with( $listing->ID, '_awpcp_sent_to_facebook_group', true ) - ->andReturn( true ); - - $helper = $this->get_test_subject(); - - // Execution. - $helper->send_listing_to_facebook_group( $listing ); - } - - /** - * @expectedException AWPCP_ListingDisabledException - * @expectedExceptionMessage The ad is currently disabled. If you share it, Facebook servers and users won't be able to access it. - */ - public function test_send_listing_to_facebook_group_when_listing_is_not_public() { - $listing = (object) array( - 'ID' => wp_rand(), - ); - - $this->facebook->shouldReceive( 'set_access_token' ) - ->andReturn( null ); - - $this->facebook->shouldReceive( 'is_group_set' ) - ->andReturn( true ); - - $this->wordpress->shouldReceive( 'get_post_meta' ) - ->with( $listing->ID, '_awpcp_sent_to_facebook_group', true ) - ->andReturn( false ); - - $this->listing_renderer->shouldReceive( 'is_public' ) - ->with( $listing ) - ->andReturn( false ); - - $helper = $this->get_test_subject(); - - // Execution. - $helper->send_listing_to_facebook_group( $listing ); - } -} diff --git a/vendor/composer/autoload_classmap.php b/vendor/composer/autoload_classmap.php index 50fe824db..2d646c067 100644 --- a/vendor/composer/autoload_classmap.php +++ b/vendor/composer/autoload_classmap.php @@ -215,6 +215,7 @@ 'AWPCP_HTML_Text_Renderer' => $baseDir . '/includes/html/class-html-text-renderer.php', 'AWPCP_HTTP' => $baseDir . '/includes/helpers/class-http.php', 'AWPCP_HTTP_Exception' => $baseDir . '/includes/exceptions.php', + 'AWPCP_HiddenSettingsRenderer' => $baseDir . '/includes/settings/renderers/class-hidden-settings-renderer.php', 'AWPCP_IDListingsTableSearchMode' => $baseDir . '/includes/admin/listings/class-id-listings-table-search-mode.php', 'AWPCP_IOError' => $baseDir . '/includes/exceptions.php', 'AWPCP_ImageFileProcessor' => $baseDir . '/includes/media/class-image-file-processor.php', diff --git a/vendor/composer/autoload_static.php b/vendor/composer/autoload_static.php index e450c443a..9640655c6 100644 --- a/vendor/composer/autoload_static.php +++ b/vendor/composer/autoload_static.php @@ -216,6 +216,7 @@ class ComposerStaticInit0d2ab1280316e8e18ee92f08de988c8d 'AWPCP_HTML_Text_Renderer' => __DIR__ . '/../..' . '/includes/html/class-html-text-renderer.php', 'AWPCP_HTTP' => __DIR__ . '/../..' . '/includes/helpers/class-http.php', 'AWPCP_HTTP_Exception' => __DIR__ . '/../..' . '/includes/exceptions.php', + 'AWPCP_HiddenSettingsRenderer' => __DIR__ . '/../..' . '/includes/settings/renderers/class-hidden-settings-renderer.php', 'AWPCP_IDListingsTableSearchMode' => __DIR__ . '/../..' . '/includes/admin/listings/class-id-listings-table-search-mode.php', 'AWPCP_IOError' => __DIR__ . '/../..' . '/includes/exceptions.php', 'AWPCP_ImageFileProcessor' => __DIR__ . '/../..' . '/includes/media/class-image-file-processor.php',