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

4.2.1 #3

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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,668 changes: 1,668 additions & 0 deletions class-gf-zapier.php

Large diffs are not rendered by default.

123 changes: 0 additions & 123 deletions data.php

This file was deleted.

44 changes: 44 additions & 0 deletions includes/class-feeds-list-table.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

if ( ! defined( 'ABSPATH' ) ) {
exit;
}

if ( ! class_exists( 'GFForms' ) ) {
die();
}

/**
* Class GF_Zapier_Feeds_List_Table
*
* @since 4.1
*/
class GF_Zapier_Feeds_List_Table extends GFAddOnFeedsTable {

/**
* Outputs the feeds message and list table.
*
* @since 4.1
*/
public function display() {
if ( gf_zapier()->is_gravityforms_supported( '2.5-rc-1' ) ) {
$open = '<div class="alert info">';
$close = '</div>';
} else {
$open = '<p class="notice notice-large notice-info">';
$close = '</p>';
}

echo $open . sprintf(
// Translators: 1. Opening <a> tag for link to Zapier, 2. Closing <a> tag. 3. Opening <a> tag for link to Gravity Forms Zapier documentation. 4. Closing <a> tag.
esc_html__( 'Zapier feeds are created automatically when %1$szaps are configured%2$s on zapier.com. %3$sLearn more%4$s.', 'gravityformszapier' ),
'<a href="' . esc_url( 'https://zapier.com/apps/gravity-forms/integrations' ) . '" target="_blank">',
'</a>',
'<a href="' . esc_url( 'https://docs.gravityforms.com/zapier-add-on/' ) . '" target="_blank">',
'</a>'
) . $close;

parent::display();
}

}
87 changes: 87 additions & 0 deletions includes/rest/class-feeds-controller.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
<?php

namespace Gravity_Forms\Gravity_Forms_Zapier\REST;

defined( 'ABSPATH' ) || die();

use WP_REST_Server;
use WP_REST_Request;
use WP_REST_Response;
use WP_Error;

class Feeds_Controller extends Zapier_Controller {

/**
* The base of this controller's route.
*
* @since 4.1
*
* @var string
*/
protected $rest_base = 'forms/(?P<form_id>[\d]+)/zapier-feeds/(?P<zap_id>[\d]+)';

/**
* Register the routes for the objects of the controller.
*
* @since 4.1
*/
public function register_routes() {
register_rest_route( $this->namespace, '/' . $this->rest_base, array(
array(
'methods' => WP_REST_Server::READABLE,
'callback' => array( $this, 'get_item' ),
'permission_callback' => array( $this, 'get_item_permissions_check' ),
),
) );
}

/**
* Gets a Zapier feed by the zapID stored in the feed meta.
*
* @since 4.1
*
* @param WP_REST_Request $request Full data about the request.
*
* @return WP_Error|WP_REST_Response
*/
public function get_item( $request ) {
$form_id_valid = $this->is_url_form_id_valid( $request );
if ( is_wp_error( $form_id_valid ) ) {
return $form_id_valid;
}

$result = $this->query_item( $request );

if ( empty( $result ) ) {
return new WP_Error( 'feed_not_found', __( 'Feed not found.', 'gravityformszapier' ), array( 'status' => 404 ) );
}

$result['meta'] = json_decode( $result['meta'], true );

return new WP_REST_Response( $result, 200 );
}

/**
* Performs the database query to retrieve the feed.
*
* @since 4.1
*
* @param WP_REST_Request $request Full data about the request.
*
* @return array|null
*/
public function query_item( $request ) {
global $wpdb;

$table = $wpdb->prefix . 'gf_addon_feed';
$like = '%' . $wpdb->esc_like( sprintf( '"zapID":"%d"', $request->get_param( 'zap_id' ) ) ) . '%';

return $wpdb->get_row( $wpdb->prepare(
"SELECT * FROM {$table} WHERE (form_id=%d) AND (addon_slug=%s) AND (meta LIKE %s) ORDER BY id DESC",
$request->get_param( 'form_id' ),
'gravityformszapier',
$like
), ARRAY_A );
}

}
52 changes: 52 additions & 0 deletions includes/rest/class-requirements-controller.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php

namespace Gravity_Forms\Gravity_Forms_Zapier\REST;

defined( 'ABSPATH' ) || die();

use WP_REST_Server;
use WP_REST_Request;
use WP_REST_Response;

class Requirements_Controller extends Zapier_Controller {

/**
* @since 4.0
*
* @var string
*/
protected $rest_base = 'zapier-requirements';

/**
* Register the routes for the objects of the controller.
*
* @since 4.0
*/
public function register_routes() {
register_rest_route( $this->namespace, '/' . $this->rest_base, array(
array(
'methods' => WP_REST_Server::READABLE,
'callback' => array( $this, 'get_items' ),
'permission_callback' => array( $this, 'get_item_permissions_check' ),
),
) );
}

/**
* Returns the Zapier app requirements for this version of the Zapier Add-On.
*
* @since 4.0
*
* @param WP_REST_Request $request Full data about the request.
*
* @return WP_REST_Response
*/
public function get_items( $request ) {
$response = array(
'zapier-version' => GF_ZAPIER_TARGET_ZAPIER_APP_VERSION,
);

return new WP_REST_Response( $response, 200 );
}

}
84 changes: 84 additions & 0 deletions includes/rest/class-sample-entries-controller.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<?php

namespace Gravity_Forms\Gravity_Forms_Zapier\REST;

defined( 'ABSPATH' ) || die();

use WP_REST_Server;
use WP_REST_Request;
use WP_REST_Response;
use GFAPI;
use WP_Error;

class Sample_Entries_Controller extends Zapier_Controller {

/**
* @since 4.1
*
* @var string
*/
protected $rest_base = 'forms/(?P<form_id>[\d]+)/zapier-sample-entries';

/**
* Register the routes for the objects of the controller.
*
* @since 4.1
*/
public function register_routes() {
register_rest_route( $this->namespace, '/' . $this->rest_base, array(
array(
'methods' => WP_REST_Server::READABLE,
'callback' => array( $this, 'get_sample_entries' ),
'permission_callback' => array( $this, 'get_item_permissions_check' ),
'args' => array(
'_admin_labels' => array(
'description' => __( 'Indicates if admin labels should be used instead of frontend labels.', 'gravityformszapier' ),
'type' => 'boolean',
)
),
),
) );
}

/**
* Get a collection of the latest 3 entries for the requested from.
*
* If the there are no entries, or the user doesn't have the gravityforms_view_entries capability, it will return the sample data returned by the '/sample-entry' endpoint.
*
* @since 4.1
*
* @param WP_REST_Request $request Full data about the request.
*
* @return WP_Error|WP_REST_Response
*/
public function get_sample_entries( $request ) {
$form_id_valid = $this->is_url_form_id_valid( $request );
if ( is_wp_error( $form_id_valid ) ) {
return $form_id_valid;
}

$form_id = $request->get_param( 'form_id' );
$form = GFAPI::get_form( $form_id );
$admin_labels = ! empty( $request->get_param( '_admin_labels' ) );

if ( ! $this->current_user_can_any( 'gravityforms_view_entries', $request ) ) {
return new WP_REST_Response( $this->get_sample_data( $form, $admin_labels ), 200 );
}

$entries = GFAPI::get_entries( $form_id, array( 'status' => 'active' ), null, array( 'offset' => 0, 'page_size' => 3 ) );
if ( is_wp_error( $entries ) ) {
return $entries;
}

foreach ( $entries as $entry ) {
$sample_data[] = $this->get_sample_data( $form, $admin_labels, $entry );
}

if ( empty( $sample_data ) ) {
$sample_data[] = $this->get_sample_data( $form, $admin_labels );
}

return new WP_REST_Response( $sample_data, 200 );
}

}
Loading