Skip to content

Commit

Permalink
Merge pull request #11 from Pardot/1.4.1
Browse files Browse the repository at this point in the history
1.4.1
  • Loading branch information
Cliff Seal committed Sep 21, 2016
2 parents 8cf1494 + 432eb96 commit 80a8b05
Show file tree
Hide file tree
Showing 6 changed files with 132 additions and 47 deletions.
17 changes: 17 additions & 0 deletions README.md
Expand Up @@ -133,8 +133,25 @@ function pardot_custom_append_querystring($body_html) {
add_filter( 'pardot_form_embed_code_54796', 'pardot_custom_append_querystring' );
```

`pardot_https_regex`

Filter the regular expression used to find URLs to be converted to https://go.pardot.com. This is only used when "Use HTTPS?" is checked in the settings. You may want to filter this regex if you find it's not properly capturing and converting your URLs.

```php
function pardot_custom_filter_https_regex() {
return "/(http|https|ftp|ftps)\:\/\/[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,63}(\/\S*)?/";
}

add_filter( 'pardot_https_regex', 'pardot_custom_filter_https_regex' );
```

## Changelog ##

### 1.4.1 ###

1. Allow connection with API v4
1. Improve regex for HTTPS and add filtering

### 1.4 ###

1. Add HTTPS option
Expand Down
33 changes: 26 additions & 7 deletions trunk/README.txt
@@ -1,10 +1,10 @@
=== Pardot ===
Contributors: cliffseal, NewClarity, MikeSchinkel
Contributors: cliffseal
Donate link: http://pardot.com
Tags: pardot, marketing automation, forms, dynamic content, tracking, web tracking
Requires at least: 4.5
Tested up to: 4.6
Stable tag: 1.4
Tested up to: 4.6.1
Stable tag: 1.4.1
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html

Expand Down Expand Up @@ -103,7 +103,7 @@ Filter the entire embed code for a given form. A common usage for this is condit
function pardot_custom_append_querystring($body_html) {
return preg_replace( '/src="([^"]+)"/', 'src="$1?this=that&postID=' . get_the_ID() . '"', $body_html );
}

add_filter( 'pardot_form_embed_code_54796', 'pardot_custom_append_querystring' );

You can apply any conditional logic you want. For instance, this will append the same information, but only if you're on the "About" page:
Expand All @@ -114,9 +114,19 @@ You can apply any conditional logic you want. For instance, this will append the
}
return $body_html;
}

add_filter( 'pardot_form_embed_code_54796', 'pardot_custom_append_querystring' );

`pardot_https_regex`

Filter the regular expression used to find URLs to be converted to https://go.pardot.com. This is only used when "Use HTTPS?" is checked in the settings. You may want to filter this regex if you find it's not properly capturing and converting your URLs.

function pardot_custom_filter_https_regex() {
return "/(http|https|ftp|ftps)\:\/\/[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,63}(\/\S*)?/";
}

add_filter( 'pardot_https_regex', 'pardot_custom_filter_https_regex' );

== Screenshots ==

1. Settings area
Expand All @@ -129,6 +139,11 @@ You can apply any conditional logic you want. For instance, this will append the

== Changelog ==

= 1.4.1 =

1. Allow connection with API v4
1. Improve regex for HTTPS and add filtering

= 1.4 =

1. Add HTTPS option
Expand Down Expand Up @@ -241,13 +256,17 @@ Initial release.

== Upgrade Notice ==

= 1.4.1 =

This update fixes an issue with the new Pardot API version and improves the HTTPS functionality used to find and replace the Pardot URLs.

= 1.4 =

This updates adds an option to embed HTTPS forms (activate it in Settings > Pardot), adds the "querystring" parameter to the shortcode, makes the form embed code filterable, allows custom overrides for various directory configurations, updates branding, and fixes some bugs.
This update adds an option to embed HTTPS forms (activate it in Settings > Pardot), adds the "querystring" parameter to the shortcode, makes the form embed code filterable, allows custom overrides for various directory configurations, updates branding, and fixes some bugs.

= 1.3.10 =

This updates improves compatibility with WordPress 3.9 in the Visual Editor.
This update improves compatibility with WordPress 3.9 in the Visual Editor.

= 1.3.9 =

Expand Down
41 changes: 24 additions & 17 deletions trunk/includes/pardot-api-class.php
Expand Up @@ -29,7 +29,7 @@ class Pardot_API {
*
* @since 1.0.0
*/
const VERSION = '3';
const VERSION = '4';

/**
* @var string Defacto constant defining the URL path template for the API.
Expand Down Expand Up @@ -190,20 +190,6 @@ function get_campaigns( $args = array() ) {
return $campaigns;
}

/*function get_campaigns( $args = array() ) {
$campaigns = false;
if ( $response = $this->get_response( 'campaign', $args ) ) {
$campaigns = array();
for( $i = 0; $i < $response->result->total_results; $i++ ) {
$campaign = (object)$response->result->campaign[$i];
if ( isset($campaign->id) ) {
$campaigns[(int)$campaign->id] = $this->SimpleXMLElement_to_stdClass( $campaign );
}
}
}
return $campaigns;
}*/

/**
* Returns an account object from Pardot's API
*
Expand Down Expand Up @@ -454,6 +440,11 @@ function get_response( $item_type, $args = array(), $property = 'result', $paged
if( wp_remote_retrieve_response_code( $http_response ) == 200 ) {
$response = new SimpleXMLElement( wp_remote_retrieve_body( $http_response ) );
if ( ! empty( $response->err ) ) {
if ( 'Your account is unable to use version 4 of the API.' == $response->err ) {
Pardot_Settings::set_setting( 'version', '3' );
} elseif ( 'Your account must use version 4 of the API.' == $response->err ) {
Pardot_Settings::set_setting( 'version', '4' );
}
$this->error = $response->err;
if ( 'login' == $item_type ) {
$this->api_key = false;
Expand Down Expand Up @@ -524,16 +515,32 @@ function get_auth() {
private function _get_url( $item_type, $args = array() ) {
if ( 'login' == $item_type ) {
$this->set_auth( $args );
$base_url = str_replace( '%%VERSION%%', self::VERSION, self::$LOGIN_URL_PATH_TEMPLATE );
$base_url = str_replace( '%%VERSION%%', self::_get_version(), self::$LOGIN_URL_PATH_TEMPLATE );
$url = $base_url;
} else {
$base_url = str_replace(
array( '%%VERSION%%', '%%ITEM_TYPE%%', '%%ACTION%%' ),
array( self::VERSION, $item_type, 'account' == $item_type ? 'read' : 'query' ),
array( self::_get_version(), $item_type, 'account' == $item_type ? 'read' : 'query' ),
self::$URL_PATH_TEMPLATE
);
$url = $base_url;
}
return self::ROOT_URL . $url;
}

/**
* Update to the correct API version when necessary
*
* @param boolean $override_version Look for overriding API version string
* @return string Url for a valid API call.
*
* @since 1.4.1
*/
private function _get_version() {
if ( Pardot_Settings::get_setting( 'version' ) ) {
return Pardot_Settings::get_setting( 'version' );
} else {
return self::VERSION;
}
}
}
51 changes: 37 additions & 14 deletions trunk/includes/pardot-plugin-class.php
Expand Up @@ -626,21 +626,9 @@ static function get_form_body( $args = array() ) {
$form_html = $matches[2];

/**
* If HTTPS is desired, override the protocol and domain
* Filter the embed code for HTTPS
*/
if ( Pardot_Settings::get_setting( 'https' ) ) {
/**
* Look for URLs in the embed code
*/
$reg_exUrl = "/(http|https|ftp|ftps)\:\/\/[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(\/\S*)?/";
preg_match( $reg_exUrl, $form_html, $url );
/**
* Replace whatever is there with the approved Pardot HTTPS URL
*/
$urlpieces = parse_url($url[0]);
$httpsurl = 'https://go.pardot.com' . $urlpieces['path'];
$form_html = preg_replace( $reg_exUrl, $httpsurl, $form_html );
}
$form_html = self::convert_embed_code_https($form_html);
}
}
/**
Expand Down Expand Up @@ -728,6 +716,10 @@ static function get_form_body( $args = array() ) {
} else {
$form_html = str_replace( '<iframe', "<iframe class=\"pardotform\"", $form_html );
}
/**
* Filter the embed code for HTTPS
*/
$form_html = self::convert_embed_code_https($form_html);
} else {
/**
* But if it's INLINE then we need to do some work; extract URL from embed code
Expand Down Expand Up @@ -850,6 +842,32 @@ static function get_form_body( $args = array() ) {
return apply_filters('pardot_form_embed_code_' . $args['form_id'], $body_html);
}

/**
* If HTTPS is desired, override the protocol and domain
*
* @static
* @param string $embed_code Contains HTML for embedding forms, dynamic content, etc.
* @return string
*
* @since 1.4.1
*/
static function convert_embed_code_https( $embed_code ) {
if ( Pardot_Settings::get_setting( 'https' ) ) {
/**
* Look for URLs in the embed code
*/
$reg_exUrl = apply_filters("pardot_https_regex", "/(http|https)\:\/\/[a-zA-Z0-9\-\.]+\.[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,63}(\/\S*)?/");
preg_match( $reg_exUrl, $embed_code, $url );
/**
* Replace whatever is there with the approved Pardot HTTPS URL
*/
$urlpieces = parse_url($url[0]);
$httpsurl = 'https://go.pardot.com' . $urlpieces['path'];
$embed_code = preg_replace( $reg_exUrl, $httpsurl, $embed_code );
}
return $embed_code;
}

/**
* Grab the HTML for the Pardot Dynamic Content to be displayed via a widget or via a shortcode.
*
Expand Down Expand Up @@ -907,6 +925,11 @@ static function get_dynamic_content_body( $args = array() ) {
$dynamicContent_html = str_replace( 'pardotdc', "pardotdc {$args['class']}", $dynamicContent_html );
}

/**
* Filter the embed code for HTTPS
*/
$dynamicContent_html = self::convert_embed_code_https($dynamicContent_html);

return $dynamicContent_html;

}
Expand Down
33 changes: 26 additions & 7 deletions trunk/includes/pardot-settings-class.php
Expand Up @@ -271,6 +271,7 @@ function admin_init() {
'password' => __( 'Password', 'pardot' ),
'user_key' => __( 'User Key', 'pardot' ),
'campaign' => __( 'Campaign (for Tracking Code)', 'pardot' ),
'version' => __( 'API Version', 'pardot' ),
'https' => __( 'Use HTTPS?', 'pardot' ),
'submit' => '',
'clearcache'=> '',
Expand Down Expand Up @@ -692,6 +693,29 @@ function campaign_field() {
}
}

/**
* Displays the API Version drop-down field for the Settings API
*
* @since 1.4.1
*/
function version_field() {
$version = self::get_setting( 'version' );
$html_name = $this->_get_html_name( 'version' );
$html = '<div id="version-wrap"><select id="version" name="' . $html_name . '">';
$html .= '<option';
if ( $version === '3' ) {
$html .= ' selected="selected"';
}
$html .= ' value="3">3</option>';
$html .= '<option';
if ( $version === '4' ) {
$html .= ' selected="selected"';
}
$html .= ' value="4">4</option>';
$html .= '</select></div>';
echo $html;
}

/**
* Displays the HTTPS-only checkbox for the Settings API
*
Expand Down Expand Up @@ -848,15 +872,15 @@ static function get_settings() {
*/
$settings = array();

} else if ( isset( $settings['password'] ) ) {
} elseif ( isset( $settings['password'] ) ) {

/**
* If there was infothere's nothing in the database make sure all
* expected setting keys are in returned array.
*/
$settings['password'] = self::pardot_decrypt( $settings['password'], 'pardot_key' );

}
}

/**
* Merge in the empty settings to make sure all expected setting keys are in returned array.
Expand Down Expand Up @@ -901,11 +925,6 @@ static function set_setting( $key, $value ) {
*/
$settings[$key] = $value;

/**
* Encode password for 'prying eyes' security
*/
$settings['password'] = self::pardot_encrypt( $settings['password'], 'pardot_key' );

/**
* Now update all the settings as a serialized array
*/
Expand Down
4 changes: 2 additions & 2 deletions trunk/pardot.php
Expand Up @@ -7,7 +7,7 @@
* Plugin URI: http://wordpress.org/extend/plugins/pardot/
* Developer: Cliff Seal of Pardot and Mike Schinkel of NewClarity LLC
* Developer URI: http://pardot.com
* Version: 1.4
* Version: 1.4.1
* License: GPLv2
*
* Copyright 2012 Pardot LLC
Expand All @@ -28,7 +28,7 @@
*/

define( 'PARDOT_PLUGIN_DIR', dirname( __FILE__ ) );
define( 'PARDOT_PLUGIN_VER', '1.4' );
define( 'PARDOT_PLUGIN_VER', '1.4.1' );

if ( ! defined( 'PARDOT_FORM_INCLUDE_TYPE' ) )
define( 'PARDOT_FORM_INCLUDE_TYPE', 'iframe' ); // iframe or inline
Expand Down

0 comments on commit 80a8b05

Please sign in to comment.