Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove Facebook API #21

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions README.TXT
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 ==

Expand Down
116 changes: 4 additions & 112 deletions admin/class-settings-admin-page.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );

Expand Down Expand Up @@ -113,21 +113,15 @@ 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();
}
}

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;
Expand Down Expand Up @@ -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 .= '<strong>' . __( 'Facebook Config Diagnostics', 'another-wordpress-classifieds-plugin' ) . '</strong><br />';

if ( $diagnostics_errors ) {
foreach ( $diagnostics_errors as &$e ) {
$error_msg .= '&#149; ' . $e . '<br />';
}
} 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' );
}
}
115 changes: 0 additions & 115 deletions admin/templates/admin-panel-settings-facebook-settings.tpl.php

This file was deleted.

16 changes: 0 additions & 16 deletions includes/admin/class-admin-container-configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
Expand Down
2 changes: 0 additions & 2 deletions includes/admin/class-admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Loading