WordPress.org

Plugin Directory

Changeset 1599305


Ignore:
Timestamp:
02/20/17 01:05:53 (2 months ago)
Author:
katzwebdesign
Message:

Version 3.0

Location:
gravity-forms-constant-contact
Files:
34 added
9 deleted
4 edited

Legend:

Unmodified
Added
Removed
  • gravity-forms-constant-contact/trunk/api/cc_class.php

    r1218440 r1599305  
    8888        * @param string $parameter - if it is not empty then this parameter will be sent using POST method 
    8989        * @param string $type - GET/POST/PUT/DELETE 
    90         * @return a string containing server output/response 
     90        * @return string server output/response 
    9191        */ 
    9292        protected function doServerCall($request_url, $parameter = '', $type = "GET") { 
     
    228228     * Method that checks if a subscriber already exist 
    229229     * @param string $email 
    230      * @return subscriber`s id if it exists or false if it doesn't 
     230     * @return string|int subscriber`s id if it exists or false if it doesn't 
    231231     */ 
    232232     public function subscriberExists($email = '') { 
    233          $call = $this->apiPath.'/contacts?email='.$email; 
     233         $call = $this->apiPath.'/contacts?email='.rawurlencode( $email ); 
    234234         $return = $this->doServerCall($call); 
    235235         $xml = simplexml_load_string($return); 
     
    243243     * If email parameter is mentioned then only mentioned contact is retrieved. 
    244244     * @param string $email 
    245      * @return Bi-Dimenstional array with information about contacts. 
     245     * @return array Bi-Dimenstional array with information about contacts. 
    246246     */ 
    247247     public function getSubscribers($email = '', $page = '') { 
     
    250250 
    251251            if (! empty($email)) { 
    252                 $call = $this->apiPath.'/contacts?email='.$email; 
     252                $call = $this->apiPath.'/contacts?email='.rawurlencode( $email ); 
    253253            } else { 
    254254                if (! empty($page)) { 
     
    296296     * Retrieves all the details for a specific contact identified by $email. 
    297297     * @param string $email 
    298      * @return array with all information about the contact. 
     298     * @return false|array with all information about the contact, or false if contact doesn't exist 
    299299     */ 
    300300     public function getSubscriberDetails($email) { 
    301301            $contact = $this->getSubscribers($email); 
     302             if ( empty( $contact['items'] ) ) { 
     303                 return false; 
     304             } 
    302305            $fullContact = array(); 
    303306            $call = str_replace('http://', 'https://', $contact['items'][0]['id']); 
     
    430433     * @param string $id 
    431434     * @param array $params 
    432      * @return Formed XML 
     435     * @return string Formed XML 
    433436     */ 
    434437     public function createContactXML($id, $params = array()) { 
  • gravity-forms-constant-contact/trunk/constantcontact.php

    r1218440 r1599305  
    44Plugin URI: https://katz.co/plugins/gravity-forms-constant-contact/ 
    55Description: Integrates Gravity Forms with Constant Contact allowing form submissions to be automatically sent to your Constant Contact account. 
    6 Version: 2.2.2 
     6Version: 3.0 
     7Text Domain: gravity-forms-constant-contact 
    78Author: Katz Web Services, Inc. 
    8 Author URI: http://www.katzwebservices.com 
     9Author URI: https://katz.co 
     10Domain Path: /languages 
    911 
    1012------------------------------------------------------------------------ 
    11 Copyright 2015 Katz Web Services, Inc. 
     13Copyright 2017 Katz Web Services, Inc. 
    1214 
    1315This program is free software; you can redistribute it and/or modify 
     
    2628*/ 
    2729 
    28 add_action('init',  array('GFConstantContact', 'init')); 
    29 register_activation_hook( __FILE__, array("GFConstantContact", "add_permissions")); 
     30define( 'GF_CONSTANT_CONTACT_VERSION', '3.0' ); 
    3031 
    31 class GFConstantContact { 
     32add_action( 'gform_loaded', array( 'GF_Constant_Contact_Bootstrap', 'load' ), 5 ); 
    3233 
    33     private static $name = "Gravity Forms Constant Contact Add-On"; 
    34     private static $path = "gravity-forms-constant-contact/constantcontact.php"; 
    35     private static $url = "http://www.gravityforms.com"; 
    36     private static $slug = "gravity-forms-constant-contact"; 
    37     private static $version = "2.2.2"; 
    38     private static $min_gravityforms_version = "1.3.9"; 
    39     public  static $plugin_dir_path; 
     34class GF_Constant_Contact_Bootstrap { 
    4035 
    41     //Plugin starting point. Will load appropriate files 
    42     public static function init(){ 
    43         global $pagenow; 
     36    public static function load(){ 
    4437 
    45         self::$plugin_dir_path = plugin_dir_path(__FILE__); 
     38        require_once( plugin_dir_path( __FILE__ ) . 'class-gf-constant-contact.php' ); 
    4639 
    47         if($pagenow === 'plugins.php') { 
    48             add_action("admin_notices", array('GFConstantContact', 'is_gravity_forms_installed'), 10); 
    49         } 
    50  
    51         if(self::is_gravity_forms_installed(false, false) === 0){ 
    52             add_action('after_plugin_row_' . self::$path, array('GFConstantContact', 'plugin_row') ); 
    53            return; 
    54         } 
    55  
    56         if(defined('RG_CURRENT_PAGE') && RG_CURRENT_PAGE == "plugins.php"){ 
    57             //loading translations 
    58             load_plugin_textdomain('gravity-forms-constant-contact', FALSE, '/gravity-forms-constant-contact/languages' ); 
    59  
    60            //force new remote request for version info on the plugin page 
    61             self::flush_version_info(); 
    62         } 
    63  
    64         if(!self::is_gravityforms_supported()){ 
    65            return; 
    66         } 
    67  
    68         //loading data class 
    69         require_once(self::get_base_path() . "/data.php"); 
    70  
    71         if(is_admin()){ 
    72             //loading translations 
    73             load_plugin_textdomain('gravity-forms-constant-contact', FALSE, '/gravity-forms-constant-contact/languages' ); 
    74  
    75             add_filter("transient_update_plugins", array('GFConstantContact', 'check_update')); 
    76             add_filter("site_transient_update_plugins", array('GFConstantContact', 'check_update')); 
    77  
    78             add_action('install_plugins_pre_plugin-information', array('GFConstantContact', 'display_changelog')); 
    79  
    80             //creates a new Settings page on Gravity Forms' settings screen 
    81             if(self::has_access("gravityforms_constantcontact")){ 
    82                 RGForms::add_settings_page("Constant Contact", array("GFConstantContact", "settings_page"), self::get_base_url() . "/images/ctct_logo_600x90.png"); 
    83             } 
    84         } 
    85  
    86         //integrating with Members plugin 
    87         if(function_exists('members_get_capabilities')) 
    88             add_filter('members_get_capabilities', array("GFConstantContact", "members_get_capabilities")); 
    89  
    90         //creates the subnav left menu 
    91         add_filter("gform_addon_navigation", array('GFConstantContact', 'create_menu')); 
    92  
    93         if(self::is_constantcontact_page()){ 
    94  
    95             //loading Gravity Forms tooltips 
    96             require_once(GFCommon::get_base_path() . "/tooltips.php"); 
    97  
    98             //enqueueing sack for AJAX requests 
    99             wp_enqueue_script("sack"); 
    100  
    101             add_filter('gform_tooltips', array('GFConstantContact', 'tooltips')); 
    102  
    103             //loading data lib 
    104             require_once(self::get_base_path() . "/data.php"); 
    105  
    106             //loading upgrade lib 
    107             if(!class_exists("RGConstantContactUpgrade")) 
    108                 require_once("plugin-upgrade.php"); 
    109  
    110             //runs the setup when version changes 
    111             self::setup(); 
    112  
    113          } 
    114          else if(in_array(RG_CURRENT_PAGE, array("admin-ajax.php"))){ 
    115  
    116             //loading data class 
    117             require_once(self::get_base_path() . "/data.php"); 
    118  
    119             add_action('wp_ajax_rg_update_feed_active', array('GFConstantContact', 'update_feed_active')); 
    120             add_action('wp_ajax_gf_select_constantcontact_form', array('GFConstantContact', 'select_constantcontact_form')); 
    121  
    122         } 
    123         else{ 
    124              //handling post submission. 
    125             add_action("gform_post_submission", array('GFConstantContact', 'export'), 10, 2); 
    126         } 
    127     } 
    128  
    129     public static function is_gravity_forms_installed($asd = '', $echo = true) { 
    130         global $pagenow, $page; $message = ''; 
    131  
    132         $installed = 0; 
    133         $name = self::$name; 
    134         if(!class_exists('RGForms')) { 
    135             if(file_exists(WP_PLUGIN_DIR.'/gravityforms/gravityforms.php')) { 
    136                 $installed = 1; 
    137                 $message .= __(sprintf('%sGravity Forms is installed but not active. %sActivate Gravity Forms%s to use the %s plugin.%s', '<p>', '<strong><a href="'.wp_nonce_url(admin_url('plugins.php?action=activate&plugin=gravityforms/gravityforms.php'), 'activate-plugin_gravityforms/gravityforms.php').'">', '</a></strong>', $name,'</p>'), 'gravity-forms-salesforce'); 
    138             } else { 
    139                 $message .= <<<EOD 
    140 <p><a href="http://katz.si/gravityforms?con=banner" title="Gravity Forms Contact Form Plugin for WordPress"><img src="http://gravityforms.s3.amazonaws.com/banners/728x90.gif" alt="Gravity Forms Plugin for WordPress" width="728" height="90" style="border:none;" /></a></p> 
    141         <h3><a href="http://katz.si/gravityforms" target="_blank">Gravity Forms</a> is required for the $name</h3> 
    142         <p>You do not have the Gravity Forms plugin installed. <a href="http://katz.si/gravityforms">Get Gravity Forms</a> today.</p> 
    143 EOD; 
    144             } 
    145  
    146             if(!empty($message) && $echo) { 
    147                 echo '<div id="message" class="updated">'.$message.'</div>'; 
    148             } 
    149         } else { 
    150             return true; 
    151         } 
    152         return $installed; 
    153     } 
    154  
    155     public static function plugin_row(){ 
    156         if(!self::is_gravityforms_supported()){ 
    157             $message = sprintf(__("%sGravity Forms%s is required. %sPurchase it today!%s"), "<a href='http://katz.si/gravityforms'>", "</a>", "<a href='http://katz.si/gravityforms'>", "</a>"); 
    158             self::display_plugin_message($message, true); 
    159         } 
    160     } 
    161  
    162     public static function display_plugin_message($message, $is_error = false){ 
    163         $style = ''; 
    164         if($is_error) 
    165             $style = 'style="background-color: #ffebe8;"'; 
    166  
    167         echo '</tr><tr class="plugin-update-tr"><td colspan="5" class="plugin-update"><div class="update-message" ' . $style . '>' . $message . '</div></td>'; 
    168     } 
    169  
    170     public static function update_feed_active(){ 
    171         check_ajax_referer('rg_update_feed_active','rg_update_feed_active'); 
    172         $id = $_POST["feed_id"]; 
    173         $feed = GFConstantContactData::get_feed($id); 
    174         GFConstantContactData::update_feed($id, $feed["form_id"], $_POST["is_active"], $feed["meta"]); 
    175     } 
    176  
    177     //--------------   Automatic upgrade --------------------------------------------------- 
    178  
    179     public static function flush_version_info(){ 
    180         if(!class_exists("RGConstantContactUpgrade")) 
    181             require_once( self::get_base_path() . "plugin-upgrade.php"); 
    182  
    183         RGConstantContactUpgrade::set_version_info(false); 
    184     } 
    185  
    186     //Displays current version details on Plugin's page 
    187     public static function display_changelog(){ 
    188         if($_REQUEST["plugin"] != self::$slug) 
    189             return; 
    190  
    191         //loading upgrade lib 
    192         if(!class_exists("RGConstantContactUpgrade")) 
    193             require_once(self::get_base_path()."plugin-upgrade.php"); 
    194  
    195         RGConstantContactUpgrade::display_changelog(self::$slug, self::get_key(), self::$version); 
    196     } 
    197  
    198     public static function check_update($update_plugins_option){ 
    199         if(!class_exists("RGConstantContactUpgrade")) 
    200             require_once(self::get_base_path()."plugin-upgrade.php"); 
    201  
    202         return RGConstantContactUpgrade::check_update(self::$path, self::$slug, self::$url, self::$slug, self::get_key(), self::$version, $update_plugins_option); 
    203     } 
    204  
    205     private static function get_key(){ 
    206         if(self::is_gravityforms_supported()) 
    207             return GFCommon::get_key(); 
    208         else 
    209             return ""; 
    210     } 
    211     //--------------------------------------------------------------------------------------- 
    212  
    213     //Returns true if the current page is an Feed pages. Returns false if not 
    214     private static function is_constantcontact_page(){ 
    215         global $plugin_page,$pagenow; 
    216  
    217         return ($pagenow === 'admin.php' && isset($_GET['page']) && $_GET['page'] === 'gf_constantcontact'); 
    218     } 
    219  
    220     //Creates or updates database tables. Will only run when version changes 
    221     private static function setup(){ 
    222         if(get_option("gf_constantcontact_version") != self::$version) 
    223             GFConstantContactData::update_table(); 
    224  
    225         update_option("gf_constantcontact_version", self::$version); 
    226     } 
    227  
    228     //Adds feed tooltips to the list of tooltips 
    229     public static function tooltips($tooltips){ 
    230         $constantcontact_tooltips = array( 
    231             "constantcontact_contact_list" => "<h6>" . __("Constant Contact List", "gravity-forms-constant-contact") . "</h6>" . __("Select the Constant Contact list you would like to add your contacts to.", "gravity-forms-constant-contact"), 
    232             "constantcontact_gravity_form" => "<h6>" . __("Gravity Form", "gravity-forms-constant-contact") . "</h6>" . __("Select the Gravity Form you would like to integrate with Constant Contact. Contacts generated by this form will be automatically added to your Constant Contact account.", "gravity-forms-constant-contact"), 
    233             "constantcontact_map_fields" => "<h6>" . __("Map Fields", "gravity-forms-constant-contact") . "</h6>" . __("Associate your Constant Contact merge variables to the appropriate Gravity Form fields by selecting.", "gravity-forms-constant-contact"), 
    234             "constantcontact_optin_condition" => "<h6>" . __("Opt-In Condition", "gravity-forms-constant-contact") . "</h6>" . __("When the opt-in condition is enabled, form submissions will only be exported to Constant Contact when the condition is met. When disabled all form submissions will be exported.", "gravity-forms-constant-contact"), 
    235  
    236         ); 
    237         return array_merge($tooltips, $constantcontact_tooltips); 
    238     } 
    239  
    240     //Creates Constant Contact left nav menu under Forms 
    241     public static function create_menu($menus){ 
    242  
    243         // Adding submenu if user has access 
    244         $permission = self::has_access("gravityforms_constantcontact"); 
    245         if(!empty($permission)) 
    246             $menus[] = array("name" => "gf_constantcontact", "label" => __("Constant Contact", "gravity-forms-constant-contact"), "callback" =>  array("GFConstantContact", "constantcontact_page"), "permission" => $permission); 
    247  
    248         return $menus; 
    249     } 
    250  
    251     public static function settings_page(){ 
    252  
    253         if(!class_exists("RGConstantContactUpgrade")) 
    254             require_once(self::get_base_path()."plugin-upgrade.php"); 
    255  
    256         if(!empty($_POST["uninstall"])){ 
    257             check_admin_referer("uninstall", "gf_constantcontact_uninstall"); 
    258             self::uninstall(); 
    259  
    260             ?> 
    261             <div class="updated fade" style="padding:20px;"><?php _e(sprintf("Gravity Forms Constant Contact Add-On has been successfully uninstalled. It can be re-activated from the %splugins page%s.", "<a href='plugins.php'>","</a>"), "gravity-forms-constant-contact")?></div> 
    262             <?php 
    263             return; 
    264         } 
    265         else if(!empty($_POST["gf_constantcontact_submit"])){ 
    266             check_admin_referer("update", "gf_constantcontact_update"); 
    267             $settings = array("username" => stripslashes($_POST["gf_constantcontact_username"]), "password" => stripslashes($_POST["gf_constantcontact_password"])); 
    268             update_option("gf_constantcontact_settings", $settings); 
    269         } 
    270         else{ 
    271             $settings = get_option("gf_constantcontact_settings"); 
    272         } 
    273  
    274         $feedback_image = ""; 
    275         //feedback for username/password 
    276         if(!empty($settings["username"]) || !empty($settings["password"])){ 
    277  
    278             if(isset($_POST["gf_constantcontact_submit"])) { 
    279                 $is_valid = self::is_valid_login($settings["username"], $settings["password"]); 
    280                 $text = $is_valid ? 'Settings Saved: Success' : 'Settings Saved: Error'; 
    281             } else { 
    282                 $is_valid = get_option('gravity_forms_cc_valid_api'); 
    283             } 
    284  
    285             if($is_valid){ 
    286                 $message = sprintf(__("Valid username and password. Now go %sconfigure form integration with Constant Contact%s!", "gravity-forms-constant-contact"), '<a href="'.admin_url('admin.php?page=gf_constantcontact').'">', '</a>'); 
    287                 $class = 'updated notice'; 
    288                 $icon = 'yes'; 
    289                 $style = "green"; 
    290             } 
    291             else{ 
    292                 $message = __("Invalid username / password combo. Please try another combination. Please note: spaces in your username are not allowed. You can change your username in the My Account link when you are logged into your account, and this may remedy the problem.", "gravity-forms-constant-contact"); 
    293                 $class = 'error notice'; 
    294                 $icon =  'no'; 
    295                 $style = "red"; 
    296             } 
    297             $feedback_image = "<i class='dashicons dashicons-{$icon}' style='color:{$style};' title='{$icon}'></i>"; 
    298         } 
    299  
    300         if( !empty($message) ) { 
    301             $message = str_replace('Api', 'API', $message); 
    302             ?> 
    303             <div id="message" class="<?php echo $class ?>"><?php echo wpautop($message); ?></div> 
    304             <?php 
    305         } 
    306  
    307         ?> 
    308         <form method="post" action=""> 
    309             <?php wp_nonce_field("update", "gf_constantcontact_update") ?> 
    310             <?php self::ctct_logo(); ?> 
    311             <h2><?php _e("Constant Contact Account Information", "gravity-forms-constant-contact") ?></h2> 
    312             <h3><?php printf(__("If you don't have a Constant Contact account, you can %ssign up for one here%s.", 'gravity-forms-constant-contact'), "<a href='http://katz.si/6p' target='_blank'>" , "</a>"); ?></h3> 
    313             <p style="text-align: left; font-size:1.2em; line-height:1.4"> 
    314                 <?php _e("Constant Contact makes it easy to send email newsletters to your customers, manage your subscriber lists, and track campaign performance. Use Gravity Forms to collect customer information and automatically add them to your Constant Contact subscriber list.", "gravity-forms-constant-contact"); ?> 
    315             </p> 
    316  
    317             <table class="form-table"> 
    318                 <tr> 
    319                     <th scope="row"><label for="gf_constantcontact_username"><?php _e("Constant Contact Username", "gravity-forms-constant-contact"); ?></label> </th> 
    320                     <td> 
    321                         <input type="text" id="gf_constantcontact_username" name="gf_constantcontact_username" value="<?php echo esc_attr($settings["username"]) ?>" size="50"/> 
    322                         <?php echo $feedback_image?> 
    323                     </td> 
    324                 </tr> 
    325                 <tr> 
    326                     <th scope="row"><label for="gf_constantcontact_password"><?php _e("Constant Contact Password", "gravity-forms-constant-contact"); ?></label> </th> 
    327                     <td> 
    328                         <input type="password" id="gf_constantcontact_password" name="gf_constantcontact_password" value="<?php echo esc_attr($settings["password"]) ?>" size="50"/> 
    329                         <?php echo $feedback_image?> 
    330                     </td> 
    331                 </tr> 
    332                 <tr> 
    333                     <td colspan="2" ><input type="submit" name="gf_constantcontact_submit" class="button-primary" value="<?php _e("Save Settings", "gravity-forms-constant-contact") ?>" /></td> 
    334                 </tr> 
    335             </table> 
    336         </form> 
    337  
    338         <?php 
    339             include_once self::get_base_path().'gravityview-info.php'; 
    340         ?> 
    341  
    342         <form action="" method="post"> 
    343             <?php wp_nonce_field("uninstall", "gf_constantcontact_uninstall") ?> 
    344             <?php if(GFCommon::current_user_can_any("gravityforms_constantcontact_uninstall")){ ?> 
    345                 <div class="hr-divider"></div> 
    346  
    347                 <h3><?php _e("Uninstall Constant Contact Add-On", "gravity-forms-constant-contact") ?></h3> 
    348                 <div class="delete-alert"><?php _e("Warning! This operation deletes ALL Constant Contact Feeds.", "gravity-forms-constant-contact") ?> 
    349                     <?php 
    350                     $uninstall_button = '<input type="submit" name="uninstall" value="' . __("Uninstall Constant Contact Add-On", "gravity-forms-constant-contact") . '" class="button" onclick="return confirm(\'' . __("Warning! ALL Constant Contact Feeds will be deleted. This cannot be undone. \'OK\' to delete, \'Cancel\' to stop", "gravity-forms-constant-contact") . '\');"/>'; 
    351                     echo apply_filters("gform_constantcontact_uninstall_button", $uninstall_button); 
    352                     ?> 
    353                 </div> 
    354             <?php } ?> 
    355         </form> 
    356         <?php 
    357     } 
    358  
    359     public static function constantcontact_page(){ 
    360         $view = isset( $_GET['view'] ) ? $_GET['view'] : ''; 
    361         if( $view == 'edit' ) 
    362             self::edit_page( $_GET['id'] ); 
    363         else 
    364             self::list_page(); 
    365     } 
    366  
    367     private static function ctct_logo() { ?> 
    368         <div><a href='http://katz.si/6p' target='_blank' style="background: transparent url(<?php echo self::get_base_url() ?>/images/ctct_logo_600x90.png) left top no-repeat; background-size: contain; width:300px; height:45px; display:block; text-indent: -9999px; overflow:hidden; direction: ltr; margin:15px 0 10px;">CTCT</a></div> 
    369         <?php 
    370     } 
    371  
    372     //Displays the constantcontact feeds list page 
    373     private static function list_page(){ 
    374         if(!self::is_gravityforms_supported()){ 
    375             die(__(sprintf("Constant Contact Add-On requires Gravity Forms %s. Upgrade automatically on the %sPlugin page%s.", self::$min_gravityforms_version, "<a href='plugins.php'>", "</a>"), "gravity-forms-constant-contact")); 
    376         } 
    377  
    378         if(!empty($_POST["action"]) && $_POST["action"] === "delete"){ 
    379             check_admin_referer("list_action", "gf_constantcontact_list"); 
    380  
    381             $id = absint($_POST["action_argument"]); 
    382             GFConstantContactData::delete_feed($id); 
    383             ?> 
    384             <div class="updated fade" style="padding:6px"><?php _e("Feed deleted.", "gravity-forms-constant-contact") ?></div> 
    385             <?php 
    386         } 
    387         else if (!empty($_POST["bulk_action"])){ 
    388             check_admin_referer("list_action", "gf_constantcontact_list"); 
    389             $selected_feeds = $_POST["feed"]; 
    390             if(is_array($selected_feeds)){ 
    391                 foreach($selected_feeds as $feed_id) 
    392                     GFConstantContactData::delete_feed($feed_id); 
    393             } 
    394             ?> 
    395             <div class="updated fade" style="padding:6px"><?php _e("Feeds deleted.", "gravity-forms-constant-contact") ?></div> 
    396             <?php 
    397         } 
    398  
    399         ?> 
    400         <div class="wrap"> 
    401  
    402             <?php self::ctct_logo(); ?> 
    403  
    404             <h2><?php _e("Constant Contact Feeds", "gravity-forms-constant-contact") ?> <a class="button add-new-h2" href="admin.php?page=gf_constantcontact&amp;view=edit&amp;id=0"><?php _e("Add New", "gravity-forms-constant-contact") ?></a></h2> 
    405  
    406             <ul class="subsubsub"> 
    407                 <li><a href="<?php echo admin_url('admin.php?page=gf_settings&amp;addon=Constant+Contact'); ?>"><?php _e('Constant Contact Settings', 'gravity-forms-constant-contact'); ?></a> |</li> 
    408                 <li><a href="<?php echo admin_url('admin.php?page=gf_constantcontact'); ?>" class="current"><?php _e('Constant Contact Feeds', 'gravity-forms-constant-contact'); ?></a></li> 
    409             </ul> 
    410  
    411 <?php 
    412         //ensures valid credentials were entered in the settings page 
    413         if(!get_option('gravity_forms_cc_valid_api')) { 
    414             echo '<div class="wrap clear" style="padding-top: 1em;"><h3>'; 
    415             echo sprintf( __( "To get started, please configure your %sConstant Contact Settings%s.", "gravity-forms-constant-contact"), '<a href="admin.php?page=gf_settings&addon=Constant+Contact">', "</a>"); 
    416             echo '</h3></div>'; 
    417             echo '</div>'; // close .wrap 
    418             return; 
    419         } 
    420 ?> 
    421  
    422             <form id="feed_form" method="post"> 
    423                 <?php wp_nonce_field('list_action', 'gf_constantcontact_list') ?> 
    424                 <input type="hidden" id="action" name="action"/> 
    425                 <input type="hidden" id="action_argument" name="action_argument"/> 
    426  
    427                 <div class="tablenav"> 
    428                     <div class="alignleft actions" style="padding:8px 0 7px; 0"> 
    429                         <label class="hidden" for="bulk_action"><?php _e("Bulk action", "gravity-forms-constant-contact") ?></label> 
    430                         <select name="bulk_action" id="bulk_action"> 
    431                             <option value=''> <?php _e("Bulk action", "gravity-forms-constant-contact") ?> </option> 
    432                             <option value='delete'><?php _e("Delete", "gravity-forms-constant-contact") ?></option> 
    433                         </select> 
    434                         <?php 
    435                         echo '<input type="submit" class="button" value="' . __("Apply", "gravity-forms-constant-contact") . '" onclick="if( jQuery(\'#bulk_action\').val() == \'delete\' && !confirm(\'' . __("Delete selected feeds? ", "gravity-forms-constant-contact") . __("\'Cancel\' to stop, \'OK\' to delete.", "gravity-forms-constant-contact") .'\')) { return false; } return true;"/>'; 
    436                         ?> 
    437                     </div> 
    438                 </div> 
    439                 <table class="widefat fixed" cellspacing="0"> 
    440                     <thead> 
    441                         <tr> 
    442                             <th scope="col" id="cb" class="manage-column column-cb check-column" style=""><input type="checkbox" /></th> 
    443                             <th scope="col" id="active" class="manage-column check-column"></th> 
    444                             <th scope="col" class="manage-column"><?php _e("Form", "gravity-forms-constant-contact") ?></th> 
    445                             <th scope="col" class="manage-column"><?php _e("Constant Contact List", "gravity-forms-constant-contact") ?></th> 
    446                         </tr> 
    447                     </thead> 
    448  
    449                     <tfoot> 
    450                         <tr> 
    451                             <th scope="col" id="cb" class="manage-column column-cb check-column" style=""><input type="checkbox" /></th> 
    452                             <th scope="col" id="active" class="manage-column check-column"></th> 
    453                             <th scope="col" class="manage-column"><?php _e("Form", "gravity-forms-constant-contact") ?></th> 
    454                             <th scope="col" class="manage-column"><?php _e("Constant Contact List", "gravity-forms-constant-contact") ?></th> 
    455                         </tr> 
    456                     </tfoot> 
    457  
    458                     <tbody class="list:user user-list"> 
    459                         <?php 
    460  
    461                         $settings = GFConstantContactData::get_feeds(); 
    462                         if(is_array($settings) && sizeof($settings) > 0){ 
    463                             foreach($settings as $setting){ 
    464                                 ?> 
    465                                 <tr class='author-self status-inherit' valign="top"> 
    466                                     <th scope="row" class="check-column"><input type="checkbox" name="feed[]" value="<?php echo $setting["id"] ?>"/></th> 
    467                                     <td><img src="<?php echo self::get_base_url() ?>/images/active<?php echo intval($setting["is_active"]) ?>.png" alt="<?php echo $setting["is_active"] ? __("Active", "gravity-forms-constant-contact") : __("Inactive", "gravity-forms-constant-contact");?>" title="<?php echo $setting["is_active"] ? __("Active", "gravity-forms-constant-contact") : __("Inactive", "gravity-forms-constant-contact");?>" onclick="ToggleActive(this, <?php echo $setting['id'] ?>); " /></td> 
    468                                     <td class="column-title"> 
    469                                         <a href="admin.php?page=gf_constantcontact&view=edit&id=<?php echo $setting["id"] ?>" title="<?php _e("Edit", "gravity-forms-constant-contact") ?>"><?php echo $setting["form_title"] ?></a> 
    470                                         <div class="row-actions"> 
    471                                             <span class="edit"> 
    472                                             <a title="Edit this setting" href="admin.php?page=gf_constantcontact&view=edit&id=<?php echo $setting["id"] ?>" title="<?php _e("Edit", "gravity-forms-constant-contact") ?>"><?php _e("Edit", "gravity-forms-constant-contact") ?></a> 
    473                                             | 
    474                                             </span> 
    475  
    476                                             <span class="edit"> 
    477                                             <a title="<?php _e("Delete", "gravity-forms-constant-contact") ?>" href="javascript: if(confirm('<?php _e("Delete this feed? ", "gravity-forms-constant-contact") ?> <?php _e("\'Cancel\' to stop, \'OK\' to delete.", "gravity-forms-constant-contact") ?>')){ DeleteSetting(<?php echo $setting["id"] ?>);}"><?php _e("Delete", "gravity-forms-constant-contact")?></a> 
    478  
    479                                             </span> 
    480                                         </div> 
    481                                     </td> 
    482                                     <td class="column-date"><?php echo $setting["meta"]["contact_list_name"] ?></td> 
    483                                 </tr> 
    484                                 <?php 
    485                             } 
    486                         } 
    487                         else if(get_option('gravity_forms_cc_valid_api')) { 
    488                             ?> 
    489                             <tr> 
    490                                 <td colspan="4" style="padding:20px;"> 
    491                                     <?php _e(sprintf("You don't have any Constant Contact feeds configured. Let's go %screate one%s!", '<a href="admin.php?page=gf_constantcontact&view=edit&id=0">', "</a>"), "gravity-forms-constant-contact"); ?> 
    492                                 </td> 
    493                             </tr> 
    494                             <?php 
    495                         } 
    496                         else{ 
    497                             ?> 
    498                             <tr> 
    499                                 <td colspan="4" style="padding:20px;"> 
    500                                     <?php _e(sprintf("To get started, please configure your %sConstant Contact Settings%s.", '<a href="admin.php?page=gf_settings&addon=Constant+Contact">', "</a>"), "gravity-forms-constant-contact"); ?> 
    501                                 </td> 
    502                             </tr> 
    503                             <?php 
    504                         } 
    505                         ?> 
    506                     </tbody> 
    507                 </table> 
    508             </form> 
    509         </div> 
    510         <script type="text/javascript"> 
    511             function DeleteSetting(id){ 
    512                 jQuery("#action_argument").val(id); 
    513                 jQuery("#action").val("delete"); 
    514                 jQuery("#feed_form")[0].submit(); 
    515             } 
    516             function ToggleActive(img, feed_id){ 
    517                 var is_active = img.src.indexOf("active1.png") >=0 
    518                 if(is_active){ 
    519                     img.src = img.src.replace("active1.png", "active0.png"); 
    520                     jQuery(img).attr('title','<?php _e("Inactive", "gravity-forms-constant-contact") ?>').attr('alt', '<?php _e("Inactive", "gravity-forms-constant-contact") ?>'); 
    521                 } 
    522                 else{ 
    523                     img.src = img.src.replace("active0.png", "active1.png"); 
    524                     jQuery(img).attr('title','<?php _e("Active", "gravity-forms-constant-contact") ?>').attr('alt', '<?php _e("Active", "gravity-forms-constant-contact") ?>'); 
    525                 } 
    526  
    527                 var mysack = new sack("<?php echo admin_url("admin-ajax.php")?>" ); 
    528                 mysack.execute = 1; 
    529                 mysack.method = 'POST'; 
    530                 mysack.setVar( "action", "rg_update_feed_active" ); 
    531                 mysack.setVar( "rg_update_feed_active", "<?php echo wp_create_nonce("rg_update_feed_active") ?>" ); 
    532                 mysack.setVar( "feed_id", feed_id ); 
    533                 mysack.setVar( "is_active", is_active ? 0 : 1 ); 
    534                 mysack.encVar( "cookie", document.cookie, false ); 
    535                 mysack.onError = function() { alert('<?php _e("Ajax error while updating feed", "gravity-forms-constant-contact" ) ?>' )}; 
    536                 mysack.runAJAX(); 
    537  
    538                 return true; 
    539             } 
    540         </script> 
    541         <?php 
    542     } 
    543  
    544     private static function is_valid_login($user = null, $password=null){ 
    545         $api = new CC_List(); 
    546         $api->login = trim($user); 
    547         $api->password = trim($password); 
    548         $api->apiPath = str_replace('USERNAME', trim($user), $api->apiPath); 
    549         $api->actionBy = 'ACTION_BY_CONTACT'; 
    550         $api->requestLogin = $api->apikey.'%'.$user.':'.$password; 
    551  
    552         $lists = @$api->getAccountLists(); 
    553  
    554         update_option('gravity_forms_cc_valid_api', !empty($lists)); 
    555  
    556         return empty($lists) ? false : true; 
    557     } 
    558  
    559  
    560     private static function get_api(){ 
    561  
    562         if(!class_exists("CC_Utility")){ 
    563             require_once( self::get_base_path() ."api/cc_class.php"); 
    564         } 
    565  
    566         $api = new CC_GF_SuperClass(); 
    567         $api->updateSettings(); 
    568  
    569         if(!$api || !empty($api->errorCode)) { 
    570            return null; 
    571         } 
    572  
    573         return $api; 
    574     } 
    575  
    576     private static function edit_page(){ 
    577     ?> 
    578         <style> 
    579             .constantcontact_col_heading{padding-bottom:2px; border-bottom: 1px solid #ccc; font-weight:bold;} 
    580             .constantcontact_field_cell {padding: 6px 17px 0 0; margin-right:15px;} 
    581             .gfield_required{color:red;} 
    582  
    583             .feeds_validation_error{ background-color:#FFDFDF;} 
    584             .feeds_validation_error td{ margin-top:4px; margin-bottom:6px; padding-top:6px; padding-bottom:6px; border-top:1px dotted #C89797; border-bottom:1px dotted #C89797} 
    585  
    586             .left_header{float:left; width:200px;} 
    587             .margin_vertical_10{margin: 10px 0;} 
    588         </style> 
    589         <script type="text/javascript"> 
    590             var form = Array(); 
    591         </script> 
    592         <div class="wrap"> 
    593             <?php self::ctct_logo(); ?> 
    594             <h2><?php _e("Constant Contact Feed", "gravity-forms-constant-contact") ?></h2> 
    595         <div class="clear"></div> 
    596         <?php 
    597  
    598         //ensures valid credentials were entered in the settings page 
    599         if(!get_option('gravity_forms_cc_valid_api')) { 
    600             ?> 
    601             <div class="error" id="message"><p><?php echo sprintf(__("We are unable to login to Constant Contact with the provided credentials. Please make sure they are valid in the %sSettings Page%s.", "gravity-forms-constant-contact"), "<a href='?page=gf_settings&addon=Constant+Contact'>", "</a>"); ?></p></div> 
    602             <?php 
    603             return; 
    604         } 
    605  
    606         $api = self::get_api(); 
    607  
    608         //getting setting id (0 when creating a new one) 
    609         $id = !empty( $_POST["constantcontact_setting_id"] ) ? $_POST["constantcontact_setting_id"] : absint( $_GET["id"] ); 
    610         $config = empty( $id ) ? array( 'is_active' => true ) : GFConstantContactData::get_feed( $id ); 
    611  
    612         //getting merge vars from selected list (if one was selected) 
    613         $merge_vars = empty( $config['meta']['contact_list_id'] ) ? array() : $api->listMergeVars( $config['meta']['contact_list_id'] ); 
    614  
    615         //updating meta information 
    616         if( isset( $_POST['gf_constantcontact_submit'] ) ) { 
    617  
    618             list($list_id, $list_name) = self::get_constantcontact_list_details( $_POST["gf_constantcontact_list"] ); 
    619  
    620             $config["meta"]["contact_list_id"] = $list_id; 
    621             $config["meta"]["contact_list_name"] = $list_name; 
    622             $config["form_id"] = absint($_POST["gf_constantcontact_form"]); 
    623  
    624             $is_valid = true; 
    625             $merge_vars = $api->listMergeVars($config["meta"]["contact_list_id"]); 
    626             $field_map = array(); 
    627             foreach($merge_vars as $var){ 
    628                 $field_name = "constantcontact_map_field_" . $var["tag"]; 
    629                 $mapped_field = stripslashes($_POST[$field_name]); 
    630                 if(!empty($mapped_field)){ 
    631                     $field_map[$var["tag"]] = $mapped_field; 
    632                 } 
    633                 else{ 
    634                     unset($field_map[$var["tag"]]); 
    635                     if($var["req"] == "Y") 
    636                     $is_valid = false; 
    637                 } 
    638             } 
    639  
    640             $config["meta"]["field_map"] = $field_map; 
    641             $config["meta"]["optin_enabled"] = !empty( $_POST["constantcontact_optin_enable"] ) ? true : false; 
    642             $config["meta"]["optin_field_id"] = !empty( $config["meta"]["optin_enabled"] ) ? $_POST["constantcontact_optin_field_id"] : ""; 
    643             $config["meta"]["optin_operator"] = !empty( $config["meta"]["optin_enabled"] ) ? $_POST["constantcontact_optin_operator"] : ""; 
    644             $config["meta"]["optin_value"] = $config["meta"]["optin_enabled"] ? $_POST["constantcontact_optin_value"] : ""; 
    645  
    646             if($is_valid){ 
    647                 $id = GFConstantContactData::update_feed($id, $config["form_id"], $config["is_active"], $config["meta"]); 
    648                 ?> 
    649                 <div class="updated fade" style="padding:6px"><?php echo sprintf(__("Feed Updated. %sback to list%s", "gravity-forms-constant-contact"), "<a href='?page=gf_constantcontact'>", "</a>") ?></div> 
    650                 <input type="hidden" name="constantcontact_setting_id" value="<?php echo $id ?>"/> 
    651                 <?php 
    652             } 
    653             else{ 
    654                 ?> 
    655                 <div class="error" style="padding:6px"><?php echo __("Feed could not be updated. Please enter all required information below.", "gravity-forms-constant-contact") ?></div> 
    656                 <?php 
    657             } 
    658         } 
    659  
    660         ?> 
    661         <form method="POST" action="<?php echo remove_query_arg('refresh'); ?>"> 
    662             <input type="hidden" name="constantcontact_setting_id" value="<?php echo $id ?>"/> 
    663             <div class="margin_vertical_10"> 
    664                 <label for="gf_constantcontact_list" class="left_header"><?php _e("Constant Contact list", "gravity-forms-constant-contact"); ?> <?php gform_tooltip("constantcontact_contact_list") ?></label> 
    665                 <?php 
    666  
    667  
    668                 //getting all contact lists 
    669                 $lists = $api->CC_List()->getLists(); 
    670  
    671                 if (empty($lists)){ 
    672                     echo __("Could not load Constant Contact contact lists. <br/>Error: ", "gravity-forms-constant-contact") . $api->errorMessage; 
    673                 } 
    674                 else{ 
    675                     ?> 
    676                     <select id="gf_constantcontact_list" name="gf_constantcontact_list" onchange="SelectList(jQuery(this).val());"> 
    677                         <option value="" ><?php _e("Select a Constant Contact List", "gravity-forms-constant-contact"); ?></option> 
    678                     <?php 
    679                     $curr_contact_list_id = isset( $config["meta"]["contact_list_id"] ) ? $config["meta"]["contact_list_id"] : ''; 
    680                     foreach( $lists as $list ) { 
    681                         echo '<option value="'. esc_attr( self::get_cc_list_short_id( $list['id'] ) ) .'" '. selected( $list['id'] , $curr_contact_list_id, false ) .'>'. esc_html( $list['title'] ) .'</option>'; 
    682                     } 
    683                     ?> 
    684                   </select> 
    685                 <?php 
    686                 } 
    687                 ?> 
    688             </div> 
    689             <div id="constantcontact_form_container" valign="top" class="margin_vertical_10" <?php echo empty($config["meta"]["contact_list_id"]) ? "style='display:none;'" : "" ?>> 
    690                 <label for="gf_constantcontact_form" class="left_header"><?php _e("Gravity Form", "gravity-forms-constant-contact"); ?> <?php gform_tooltip("constantcontact_gravity_form") ?></label> 
    691  
    692                 <select id="gf_constantcontact_form" name="gf_constantcontact_form" onchange="SelectForm(jQuery('#gf_constantcontact_list').val(), jQuery(this).val());"> 
    693                 <option value=""><?php _e("Select a form", "gravity-forms-constant-contact"); ?> </option> 
    694                 <?php 
    695                 $curr_form_id = isset( $config['form_id'] ) ? $config['form_id'] : ''; 
    696                 $forms = RGFormsModel::get_forms(); 
    697                 foreach( $forms as $form ){ 
    698                     echo '<option value="'. absint( $form->id ) .'" '. selected( absint( $form->id ), $curr_form_id, false ) .'>'. esc_html( $form->title ) .'</option>'; 
    699                 } 
    700                 ?> 
    701                 </select> 
    702                 &nbsp;&nbsp; 
    703                 <span class="spinner" id="constantcontact_wait" style="display:none; float:none; position:absolute; margin-top: .33em;"></span> 
    704             </div> 
    705             <div id="constantcontact_field_group" valign="top" <?php echo empty($config["meta"]["contact_list_id"]) || empty($config["form_id"]) ? "style='display:none;'" : "" ?>> 
    706                 <div id="constantcontact_field_container" valign="top" class="margin_vertical_10" > 
    707                     <label for="constantcontact_fields" class="left_header"><?php _e("Map Fields", "gravity-forms-constant-contact"); ?> <?php gform_tooltip("constantcontact_map_fields") ?></label> 
    708  
    709                     <div id="constantcontact_field_list"> 
    710                     <?php 
    711                     $selection_fields = ''; 
    712                     if(!empty($config["form_id"])){ 
    713  
    714                         //getting list of all ConstantContact merge variables for the selected contact list 
    715                         if(empty($merge_vars)) { 
    716  
    717                             $merge_vars = $api->listMergeVars( $list_id ); 
    718                         } 
    719  
    720  
    721                         //getting field map UI 
    722                         echo self::get_field_mapping($config, $config["form_id"], $merge_vars); 
    723  
    724                         //getting list of selection fields to be used by the optin 
    725                         $form_meta = RGFormsModel::get_form_meta($config["form_id"]); 
    726                         $selection_fields = GFCommon::get_selection_fields($form_meta, @$config["meta"]["optin_field_id"]); 
    727                     } 
    728                     ?> 
    729                     </div> 
    730                 </div> 
    731  
    732                 <div id="constantcontact_optin_container" valign="top" class="margin_vertical_10"> 
    733                     <label for="constantcontact_optin" class="left_header"><?php _e("Opt-In Condition", "gravity-forms-constant-contact"); ?> <?php gform_tooltip("constantcontact_optin_condition") ?></label> 
    734                     <div id="constantcontact_optin"> 
    735                         <table> 
    736                             <tr> 
    737                                 <td> 
    738                                     <input type="checkbox" id="constantcontact_optin_enable" name="constantcontact_optin_enable" value="1" onclick="if(this.checked){jQuery('#constantcontact_optin_condition_field_container').show('slow');} else{jQuery('#constantcontact_optin_condition_field_container').hide('slow');}" <?php echo @$config["meta"]["optin_enabled"] ? "checked='checked'" : ""?>/> 
    739                                     <label for="constantcontact_optin_enable"><?php _e("Enable", "gravity-forms-constant-contact"); ?></label> 
    740                                 </td> 
    741                             </tr> 
    742                             <tr> 
    743                                 <td> 
    744                                     <div id="constantcontact_optin_condition_field_container" <?php echo empty($config["meta"]["optin_enabled"]) ? "style='display:none'" : "" ?>> 
    745                                         <div id="constantcontact_optin_condition_fields" <?php echo empty($selection_fields) ? "style='display:none'" : "" ?>> 
    746                                             <?php _e("Export to Constant Contact if ", "gravity-forms-constant-contact") ?> 
    747  
    748                                             <select id="constantcontact_optin_field_id" name="constantcontact_optin_field_id" class='optin_select' onchange='jQuery("#constantcontact_optin_value").html(GetFieldValues(jQuery(this).val(), "", 20));'><?php echo $selection_fields ?></select> 
    749                                             <select id="constantcontact_optin_operator" name="constantcontact_optin_operator" > 
    750                                                 <option value="is" <?php echo @$config["meta"]["optin_operator"] == "is" ? "selected='selected'" : "" ?>><?php _e("is", "gravity-forms-constant-contact") ?></option> 
    751                                                 <option value="isnot" <?php echo @$config["meta"]["optin_operator"] == "isnot" ? "selected='selected'" : "" ?>><?php _e("is not", "gravity-forms-constant-contact") ?></option> 
    752                                             </select> 
    753                                             <select id="constantcontact_optin_value" name="constantcontact_optin_value" class='optin_select'> 
    754                                             </select> 
    755  
    756                                         </div> 
    757                                         <div id="constantcontact_optin_condition_message" <?php echo !empty($selection_fields) ? "style='display:none'" : ""?>> 
    758                                             <?php _e("To create an Opt-In condition, your form must have a drop down, checkbox or multiple choice field.", "gravityform") ?> 
    759                                         </div> 
    760                                     </div> 
    761                                 </td> 
    762                             </tr> 
    763                         </table> 
    764                     </div> 
    765  
    766                     <script type="text/javascript"> 
    767                         <?php 
    768                         if(!empty($config["form_id"])){ 
    769                             ?> 
    770                             //creating Javascript form object 
    771                             form = <?php echo GFCommon::json_encode($form_meta)?> ; 
    772  
    773                             //initializing drop downs 
    774                             jQuery(document).ready(function(){ 
    775                                 var selectedField = "<?php echo str_replace('"', '\"', @$config["meta"]["optin_field_id"])?>"; 
    776                                 var selectedValue = "<?php echo str_replace('"', '\"', @$config["meta"]["optin_value"])?>"; 
    777                                 SetOptin(selectedField, selectedValue); 
    778                             }); 
    779                         <?php 
    780                         } 
    781                         ?> 
    782                     </script> 
    783                 </div> 
    784  
    785  
    786                 <div id="constantcontact_submit_container" class="margin_vertical_10"> 
    787                     <input type="submit" name="gf_constantcontact_submit" value="<?php echo empty($id) ? __("Save Feed", "gravity-forms-constant-contact") : __("Update Feed", "gravity-forms-constant-contact"); ?>" class="button-primary"/> 
    788                 </div> 
    789             </div> 
    790         </form> 
    791         </div> 
    792         <script type="text/javascript"> 
    793  
    794             function SelectList(listId){ 
    795                 if(listId){ 
    796                     jQuery("#constantcontact_form_container").slideDown(); 
    797                     jQuery("#gf_constantcontact_form").val(""); 
    798                 } 
    799                 else{ 
    800                     jQuery("#constantcontact_form_container").slideUp(); 
    801                     EndSelectForm(""); 
    802                 } 
    803             } 
    804  
    805             function SelectForm(listId, formId){ 
    806                 if(!formId){ 
    807                     jQuery("#constantcontact_field_group").slideUp(); 
    808                     return; 
    809                 } 
    810  
    811                 jQuery("#constantcontact_wait").css('display', 'inline-block'); 
    812                 jQuery("#constantcontact_field_group").slideUp(); 
    813  
    814                 var mysack = new sack("<?php bloginfo( 'wpurl' ); ?>/wp-admin/admin-ajax.php" ); 
    815                 mysack.execute = 1; 
    816                 mysack.method = 'POST'; 
    817                 mysack.setVar( "action", "gf_select_constantcontact_form" ); 
    818                 mysack.setVar( "gf_select_constantcontact_form", "<?php echo wp_create_nonce("gf_select_constantcontact_form") ?>" ); 
    819                 mysack.setVar( "list_id", listId); 
    820                 mysack.setVar( "form_id", formId); 
    821                 mysack.encVar( "cookie", document.cookie, false ); 
    822                 mysack.onError = function() {jQuery("#constantcontact_wait").hide(); alert('<?php _e("Ajax error while selecting a form", "gravity-forms-constant-contact") ?>' )}; 
    823                 mysack.runAJAX(); 
    824  
    825                 return true; 
    826             } 
    827  
    828             function SetOptin(selectedField, selectedValue){ 
    829  
    830                 //load form fields 
    831                 jQuery("#constantcontact_optin_field_id").html(GetSelectableFields(selectedField, 20)); 
    832                 var optinConditionField = jQuery("#constantcontact_optin_field_id").val(); 
    833  
    834                 if(optinConditionField){ 
    835                     jQuery("#constantcontact_optin_condition_message").hide(); 
    836                     jQuery("#constantcontact_optin_condition_fields").show(); 
    837                     jQuery("#constantcontact_optin_value").html(GetFieldValues(optinConditionField, selectedValue, 20)); 
    838                 } 
    839                 else{ 
    840                     jQuery("#constantcontact_optin_condition_message").show(); 
    841                     jQuery("#constantcontact_optin_condition_fields").hide(); 
    842                 } 
    843             } 
    844  
    845             function EndSelectForm(fieldList, form_meta){ 
    846                 //setting global form object 
    847                 form = form_meta; 
    848  
    849                 if(fieldList){ 
    850  
    851                     SetOptin("",""); 
    852  
    853                     jQuery("#constantcontact_field_list").html(fieldList); 
    854                     jQuery("#constantcontact_field_group").slideDown(); 
    855  
    856                 } 
    857                 else{ 
    858                     jQuery("#constantcontact_field_group").slideUp(); 
    859                     jQuery("#constantcontact_field_list").html(""); 
    860                 } 
    861                 jQuery("#constantcontact_wait").hide(); 
    862             } 
    863  
    864             function GetFieldValues(fieldId, selectedValue, labelMaxCharacters){ 
    865                 if(!fieldId) 
    866                     return ""; 
    867  
    868                 var str = ""; 
    869                 var field = GetFieldById(fieldId); 
    870                 if(!field || !field.choices) 
    871                     return ""; 
    872  
    873                 var isAnySelected = false; 
    874  
    875                 for(var i=0; i<field.choices.length; i++){ 
    876                     var fieldValue = field.choices[i].value ? field.choices[i].value : field.choices[i].text; 
    877                     var isSelected = fieldValue == selectedValue; 
    878                     var selected = isSelected ? "selected='selected'" : ""; 
    879                     if(isSelected) 
    880                         isAnySelected = true; 
    881  
    882                     str += "<option value='" + fieldValue.replace("'", "&#039;") + "' " + selected + ">" + TruncateMiddle(field.choices[i].text, labelMaxCharacters) + "</option>"; 
    883                 } 
    884  
    885                 if(!isAnySelected && selectedValue){ 
    886                     str += "<option value='" + selectedValue.replace("'", "&#039;") + "' selected='selected'>" + TruncateMiddle(selectedValue, labelMaxCharacters) + "</option>"; 
    887                 } 
    888  
    889                 return str; 
    890             } 
    891  
    892             function GetFieldById(fieldId){ 
    893                 for(var i=0; i<form.fields.length; i++){ 
    894                     if(form.fields[i].id == fieldId) 
    895                         return form.fields[i]; 
    896                 } 
    897                 return null; 
    898             } 
    899  
    900             function TruncateMiddle(text, maxCharacters){ 
    901                 if(text.length <= maxCharacters) 
    902                     return text; 
    903                 var middle = parseInt(maxCharacters / 2); 
    904                 return text.substr(0, middle) + "..." + text.substr(text.length - middle, middle); 
    905             } 
    906  
    907             function GetSelectableFields(selectedFieldId, labelMaxCharacters){ 
    908                 var str = ""; 
    909                 var inputType; 
    910                 for(var i=0; i<form.fields.length; i++){ 
    911                     fieldLabel = form.fields[i].adminLabel ? form.fields[i].adminLabel : form.fields[i].label; 
    912                     inputType = form.fields[i].inputType ? form.fields[i].inputType : form.fields[i].type; 
    913                     if(inputType == "checkbox" || inputType == "radio" || inputType == "select"){ 
    914                         var selected = form.fields[i].id == selectedFieldId ? "selected='selected'" : ""; 
    915                         str += "<option value='" + form.fields[i].id + "' " + selected + ">" + TruncateMiddle(fieldLabel, labelMaxCharacters) + "</option>"; 
    916                     } 
    917                 } 
    918                 return str; 
    919             } 
    920  
    921         </script> 
    922  
    923         <?php 
    924  
    925     } 
    926  
    927     public static function add_permissions(){ 
    928         global $wp_roles; 
    929         $wp_roles->add_cap("administrator", "gravityforms_constantcontact"); 
    930         $wp_roles->add_cap("administrator", "gravityforms_constantcontact_uninstall"); 
    931     } 
    932  
    933     //Target of Member plugin filter. Provides the plugin with Gravity Forms lists of capabilities 
    934     public static function members_get_capabilities( $caps ) { 
    935         return array_merge($caps, array("gravityforms_constantcontact", "gravityforms_constantcontact_uninstall")); 
    936     } 
    937  
    938     public static function disable_constantcontact(){ 
    939         delete_option("gf_constantcontact_settings"); 
    940     } 
    941  
    942     public static function select_constantcontact_form(){ 
    943  
    944         check_ajax_referer("gf_select_constantcontact_form", "gf_select_constantcontact_form"); 
    945         $form_id =  intval(@$_POST["form_id"]); 
    946         $list_id = !empty( $_POST["list_id"] ) ? self::get_constantcontact_list_endpoint( $_POST["list_id"] ) : ''; 
    947         $setting_id =  intval(@$_POST["setting_id"]); 
    948  
    949         $api = self::get_api(); 
    950         if(!$api) 
    951             die("EndSelectForm();"); 
    952  
    953         //getting list of all Constant Contact merge variables for the selected contact list 
    954         $merge_vars = $api->listMergeVars($list_id); 
    955  
    956         //getting configuration 
    957         $config = GFConstantContactData::get_feed($setting_id); 
    958  
    959         //getting field map UI 
    960         $str = self::get_field_mapping($config, $form_id, $merge_vars); 
    961  
    962         //fields meta 
    963         $form = RGFormsModel::get_form_meta($form_id); 
    964         //$fields = $form["fields"]; 
    965         die("EndSelectForm('" . str_replace("'", "\'", $str) . "', " . GFCommon::json_encode($form) . ");"); 
    966     } 
    967  
    968  
    969     /** 
    970      * Convert CC endpoint id into a number id to be used on forms (avoid issues with more strict servers) 
    971      * 
    972      * @access public 
    973      * @static 
    974      * @param mixed $endpoint 
    975      * @return string $id 
    976      */ 
    977     public static function get_cc_list_short_id( $endpoint ) { 
    978  
    979         if( empty( $endpoint ) ) { 
    980             return ''; 
    981         } 
    982  
    983         if( false !== ( $pos = strrpos( rtrim( $endpoint, '/' ), '/' ) ) ) { 
    984             return trim( substr( $endpoint, $pos + 1 ) ); 
    985         } 
    986  
    987         return ''; 
    988     } 
    989  
    990  
    991     /** 
    992      * Given a list short id (just the numeric part) return the list endpoint 
    993      * 
    994      * @access public 
    995      * @static 
    996      * @param integer $list_id 
    997      * @return string $endpoint 
    998      */ 
    999     public static function get_constantcontact_list_endpoint( $list_id ) { 
    1000  
    1001         if( empty( $list_id ) ) { 
    1002             return ''; 
    1003         } 
    1004  
    1005         $api = self::get_api(); 
    1006  
    1007         if( !$api ) { 
    1008             return ''; 
    1009         } 
    1010  
    1011         $lists = $api->CC_List()->getLists(); 
    1012  
    1013         foreach( $lists as $list ) { 
    1014             if( self::get_cc_list_short_id( $list['id'] ) == $list_id ) { 
    1015                 return $list['id']; 
    1016             } 
    1017  
    1018         } 
    1019  
    1020         return ''; 
    1021     } 
    1022  
    1023  
    1024     /** 
    1025      * Given a list short id (just the numeric part) return the list details (endpoint and title) 
    1026      * 
    1027      * @access public 
    1028      * @static 
    1029      * @param mixed $list_id 
    1030      * @return array (id, title) 
    1031      */ 
    1032     public static function get_constantcontact_list_details( $list_id ) { 
    1033  
    1034         if( empty( $list_id ) ) { 
    1035             return ''; 
    1036         } 
    1037  
    1038         $api = self::get_api(); 
    1039  
    1040         if( !$api ) { 
    1041             return ''; 
    1042         } 
    1043  
    1044         $lists = $api->CC_List()->getLists(); 
    1045  
    1046         foreach( $lists as $list ) { 
    1047             if( self::get_cc_list_short_id( $list['id'] ) == $list_id ) { 
    1048                 return array( $list['id'], $list['title'] ); 
    1049             } 
    1050  
    1051         } 
    1052  
    1053         return ''; 
    1054     } 
    1055  
    1056  
    1057  
    1058  
    1059  
    1060     private static function get_field_mapping($config, $form_id, $merge_vars){ 
    1061  
    1062         //getting list of all fields for the selected form 
    1063         $form_fields = self::get_form_fields($form_id); 
    1064  
    1065         $str = "<table cellpadding='0' cellspacing='0'><tr><td class='constantcontact_col_heading'>" . __("List Fields", "gravity-forms-constant-contact") . "</td><td class='constantcontact_col_heading'>" . __("Form Fields", "gravity-forms-constant-contact") . "</td></tr>"; 
    1066         foreach($merge_vars as $var){ 
    1067             $selected_field = @$config["meta"]["field_map"][$var["tag"]]; 
    1068             $required = $var["req"] == "Y" ? "<span class='gfield_required'>*</span>" : ""; 
    1069             $error_class = $var["req"] == "Y" && empty($selected_field) && !empty($_POST["gf_constantcontact_submit"]) ? " feeds_validation_error" : ""; 
    1070             $str .= "<tr class='$error_class'><td class='constantcontact_field_cell'>" . $var["name"]  . " $required</td><td class='constantcontact_field_cell'>" . self::get_mapped_field_list($var["tag"], $selected_field, $form_fields) . "</td></tr>"; 
    1071         } 
    1072         $str .= "</table>"; 
    1073  
    1074         return $str; 
    1075     } 
    1076  
    1077     public static function get_form_fields($form_id){ 
    1078         $form = RGFormsModel::get_form_meta($form_id); 
    1079         $fields = array(); 
    1080  
    1081         //Adding default fields 
    1082         array_push($form["fields"],array("id" => "date_created" , "label" => __("Entry Date", "gravity-forms-constant-contact"))); 
    1083         array_push($form["fields"],array("id" => "ip" , "label" => __("User IP", "gravity-forms-constant-contact"))); 
    1084         array_push($form["fields"],array("id" => "source_url" , "label" => __("Source Url", "gravity-forms-constant-contact"))); 
    1085  
    1086         if(is_array($form["fields"])){ 
    1087             foreach($form["fields"] as $field){ 
    1088                 if(isset($field["inputs"]) && is_array($field["inputs"])){ 
    1089  
    1090                     //If this is an address field, add full name to the list 
    1091                     if(RGFormsModel::get_input_type($field) == "address") 
    1092                         $fields[] =  array($field["id"], GFCommon::get_label($field) . " (" . __("Full" , "gravity-forms-constant-contact") . ")"); 
    1093  
    1094                     foreach($field["inputs"] as $input) 
    1095                         $fields[] =  array($input["id"], GFCommon::get_label($field, $input["id"])); 
    1096                 } 
    1097                 else if(empty($field["displayOnly"])){ 
    1098                     $fields[] =  array($field["id"], GFCommon::get_label($field)); 
    1099                 } 
    1100             } 
    1101         } 
    1102         return $fields; 
    1103     } 
    1104  
    1105     private static function get_address($entry, $field_id){ 
    1106         $street_value = str_replace("  ", " ", trim($entry[$field_id . ".1"])); 
    1107         $street2_value = str_replace("  ", " ", trim($entry[$field_id . ".2"])); 
    1108         $city_value = str_replace("  ", " ", trim($entry[$field_id . ".3"])); 
    1109         $state_value = str_replace("  ", " ", trim($entry[$field_id . ".4"])); 
    1110         $zip_value = trim($entry[$field_id . ".5"]); 
    1111         $country_value = GFCommon::get_country_code(trim($entry[$field_id . ".6"])); 
    1112  
    1113         $address = $street_value; 
    1114         $address .= !empty($address) && !empty($street2_value) ? "  $street2_value" : $street2_value; 
    1115         $address .= !empty($address) && (!empty($city_value) || !empty($state_value)) ? "  $city_value" : $city_value; 
    1116         $address .= !empty($address) && !empty($city_value) && !empty($state_value) ? "  $state_value" : $state_value; 
    1117         $address .= !empty($address) && !empty($zip_value) ? "  $zip_value" : $zip_value; 
    1118         $address .= !empty($address) && !empty($country_value) ? "  $country_value" : $country_value; 
    1119  
    1120         return $address; 
    1121     } 
    1122  
    1123     public static function get_mapped_field_list($variable_name, $selected_field, $fields){ 
    1124         $field_name = "constantcontact_map_field_" . $variable_name; 
    1125         $str = "<select name='$field_name' id='$field_name'><option value=''>" . __("", "gravity-forms-constant-contact") . "</option>"; 
    1126         foreach($fields as $field){ 
    1127             $field_id = $field[0]; 
    1128             $field_label = $field[1]; 
    1129  
    1130             $selected = $field_id == $selected_field ? "selected='selected'" : ""; 
    1131             $str .= "<option value='" . $field_id . "' ". $selected . ">" . $field_label . "</option>"; 
    1132         } 
    1133         $str .= "</select>"; 
    1134         return $str; 
    1135     } 
    1136  
    1137     public static function export($entry, $form){ 
    1138  
    1139         //loading data class 
    1140         require_once( self::get_base_path() . "/data.php"); 
    1141  
    1142         //getting all active feeds 
    1143         $feeds = GFConstantContactData::get_feed_by_form($form["id"], true); 
    1144  
    1145         foreach($feeds as $feed){ 
    1146  
    1147             //only export if user has opted in 
    1148             if(self::is_optin($form, $feed)) { 
    1149  
    1150                 if( !isset( $api ) ) { 
    1151  
    1152                     //Login to Constant Contact 
    1153                     $api = self::get_api(); 
    1154  
    1155                     // If no API, don't process 
    1156                     if(!$api) { 
    1157                         self::add_note($entry["id"], __('Not added/updated in Constant Contact; there was an error fetching the API.', 'gravity-forms-constant-contact')); 
    1158                         continue; 
    1159                     } 
    1160                 } 
    1161  
    1162                 self::export_feed($entry, $form, $feed, $api); 
    1163             } 
    1164         } 
    1165     } 
    1166  
    1167     public static function export_feed($entry, $form, $feed, $api){ 
    1168  
    1169         $email_field_id = $feed["meta"]["field_map"]["email_address"]; 
    1170         $email = $entry[$email_field_id]; 
    1171         $merge_vars = array(''); 
    1172         foreach($feed["meta"]["field_map"] as $var_tag => $field_id){ 
    1173  
    1174             $field = RGFormsModel::get_field($form, $field_id); 
    1175             $field_type = RGFormsModel::get_input_type($field); 
    1176  
    1177             if($field_id == intval($field_id) && $field_type == "address") { 
    1178                 //handling full address 
    1179                 $merge_vars[$var_tag] = self::get_address($entry, $field_id); 
    1180             } elseif( $field_type == 'date' ) { 
    1181                 $merge_vars[$var_tag] = apply_filters( 'gravityforms_constant_contact_change_date_format', $entry[$field_id] ); 
    1182             } else { 
    1183                 $merge_vars[$var_tag] = $entry[$field_id]; 
    1184             } 
    1185         } 
    1186  
    1187         $retval = $api->listSubscribe($feed["meta"]["contact_list_id"], $merge_vars, "html"); 
    1188  
    1189        if( !is_wp_error( $retval ) && !empty($retval)) { 
    1190            self::add_note($entry["id"], __('Successfully added/updated in Constant Contact.', 'gravity-forms-constant-contact')); 
    1191         } else { 
    1192  
    1193             $error = ''; 
    1194             if( is_wp_error( $retval ) ) { 
    1195                 $error = ': '.$retval->get_error_message(); 
    1196             } 
    1197  
    1198             self::add_note($entry["id"], __('Errors when adding/updating in Constant Contact', 'gravity-forms-constant-contact') . $error ); 
    1199         } 
    1200     } 
    1201  
    1202     /** 
    1203      * Add note to GF Entry 
    1204      * @param int $id   Entry ID 
    1205      * @param string $note Note text 
    1206      */ 
    1207     static private function add_note($id, $note) { 
    1208  
    1209         if(!apply_filters('gravityforms_constant_contact_add_notes_to_entries', true) || !class_exists('RGFormsModel')) { return; } 
    1210  
    1211         RGFormsModel::add_note($id, 0, __('Gravity Forms Constant Contact Add-on'), $note); 
    1212     } 
    1213  
    1214     public static function uninstall(){ 
    1215  
    1216         //loading data lib 
    1217         require_once(self::get_base_path() . "/data.php"); 
    1218  
    1219         if(!GFConstantContact::has_access("gravityforms_constantcontact_uninstall")) 
    1220             die(__("You don't have adequate permission to uninstall Constant Contact Add-On.", "gravity-forms-constant-contact")); 
    1221  
    1222         //droping all tables 
    1223         GFConstantContactData::drop_tables(); 
    1224  
    1225         //removing options 
    1226         delete_option("gf_constantcontact_settings"); 
    1227         delete_option("gf_constantcontact_version"); 
    1228  
    1229         //Deactivating plugin 
    1230         $plugin = "gravity-forms-constant-contact/constantcontact.php"; 
    1231         deactivate_plugins($plugin); 
    1232         update_option('recently_activated', array($plugin => time()) + (array)get_option('recently_activated')); 
    1233     } 
    1234  
    1235     public static function is_optin($form, $settings){ 
    1236         $config = $settings["meta"]; 
    1237         $operator = $config["optin_operator"]; 
    1238  
    1239         $field = RGFormsModel::get_field($form, $config["optin_field_id"]); 
    1240         $field_value = RGFormsModel::get_field_value($field, array()); 
    1241         $is_value_match = is_array($field_value) ? in_array($config["optin_value"], $field_value) : $field_value == $config["optin_value"]; 
    1242  
    1243         return  !$config["optin_enabled"] || empty($field) || ($operator == "is" && $is_value_match) || ($operator == "isnot" && !$is_value_match); 
    1244     } 
    1245  
    1246  
    1247     private static function is_gravityforms_installed(){ 
    1248         return class_exists("RGForms"); 
    1249     } 
    1250  
    1251     private static function is_gravityforms_supported(){ 
    1252         if(class_exists("GFCommon")){ 
    1253             $is_correct_version = version_compare(GFCommon::$version, self::$min_gravityforms_version, ">="); 
    1254             return $is_correct_version; 
    1255         } 
    1256         else{ 
    1257             return false; 
    1258         } 
    1259     } 
    1260  
    1261     protected static function has_access($required_permission){ 
    1262         $has_members_plugin = function_exists('members_get_capabilities'); 
    1263         $has_access = $has_members_plugin ? current_user_can($required_permission) : current_user_can("level_7"); 
    1264         if($has_access) 
    1265             return $has_members_plugin ? $required_permission : "level_7"; 
    1266         else 
    1267             return false; 
    1268     } 
    1269  
    1270     /** 
    1271      * Returns the url of the plugin's root folder 
    1272      * @return string 
    1273      */ 
    1274     static protected function get_base_url(){ 
    1275         return plugins_url(null, __FILE__); 
    1276     } 
    1277  
    1278     static public function get_file() { 
    1279         return __FILE__; 
    1280     } 
    1281  
    1282     //Returns the physical path of the plugin's root folder 
    1283     static public function get_base_path(){ 
    1284         return plugin_dir_path(__FILE__) . '/'; 
    1285     } 
    1286  
    1287 } 
    1288  
    1289 if(!class_exists("CC_Utility")) { 
    1290     require_once(GFConstantContact::get_base_path()."/api/cc_class.php"); 
    1291 } 
    1292  
    1293 class CC_GF_SuperClass extends CC_Utility { 
    1294  
    1295     function CC_GF_SuperClass($user = null, $password=null) { 
    1296         self::updateSettings($this); 
    1297     } 
    1298  
    1299     public function updateSettings($object = false) { 
    1300         if(!is_object($object)) { 
    1301             $object = new CC_GF_SuperClass; 
    1302         } 
    1303         $settings = get_option("gf_constantcontact_settings"); 
    1304  
    1305         $object->login = trim($settings['username']); 
    1306         $object->password = trim($settings['password']); 
    1307         if(isset($object->apiPath)) { 
    1308           $object->apiPath = str_replace('USERNAME', '', (string)$object->apiPath).trim($settings['username']); 
    1309         } 
    1310  
    1311         $actionBy = apply_filters('gravity_forms_constant_contact_action_by', 'ACTION_BY_CONTACT'); 
    1312         if($actionBy === 'ACTION_BY_CONTACT' || $actionBy === 'ACTION_BY_CUSTOMER') { 
    1313             $this->actionBy = $actionBy; 
    1314         } else { 
    1315             $this->actionBy = 'ACTION_BY_CUSTOMER'; 
    1316         } 
    1317  
    1318         if(isset($object->apikey)) { 
    1319           $object->requestLogin = $object->apikey.'%'.$object->login.':'.$object->password; 
    1320         } 
    1321         $object->curl_debug = isset($_GET['debug']) && ( function_exists('current_user_can') && current_user_can( 'manage_options' ) ); 
    1322     } 
    1323  
    1324     public function listSubscribe($id, $merge_vars, $email_type='html') { 
    1325         $params = $merge_vars; 
    1326  
    1327         foreach($params as $key => $p) { 
    1328             $p = trim($p); 
    1329             if(empty($p) && $p != '0') { 
    1330                 unset($params[$key]); 
    1331             } 
    1332         } 
    1333  
    1334         $params["lists"] = array($id); //array(preg_replace('/(?:.*?)\/lists\/(\d+)/ism','$1',$id)); 
    1335         $params['mail_type'] = strtolower(@$params['mail_type']); 
    1336         if($params['mail_type'] != 'html' && $params['mail_type'] != 'text') { 
    1337             $params['mail_type'] = 'html'; 
    1338         } 
    1339  
    1340         // Check if email already exists; update if it does 
    1341         if($existingID = self::CC_Contact()->subscriberExists($params['email_address'])) { 
    1342  
    1343             // Get the current subscriber data 
    1344             $contactInfo = self::CC_Contact()->getSubscriberDetails($params['email_address']); 
    1345  
    1346             // Merge the lists together 
    1347             $params['lists'] = array_merge( $params['lists'], $contactInfo['lists']); 
    1348  
    1349             $contactXML = self::CC_Contact()->createContactXML((string)$existingID,$params); 
    1350  
    1351             $return = self::CC_Contact()->editSubscriber((string)$existingID, (string)$contactXML); 
    1352         } else { 
    1353             $contactXML = self::CC_Contact()->createContactXML(null,$params); 
    1354             $contactXML = (string)$contactXML; 
    1355             $return = self::CC_Contact()->addSubscriber($contactXML); 
    1356         } 
    1357  
    1358         return $return; 
    1359  
    1360     } 
    1361  
    1362     public function CC_List() { 
    1363         $ccListOBJ = new CC_List(); 
    1364         self::updateSettings($ccListOBJ); 
    1365         return $ccListOBJ; 
    1366     } 
    1367  
    1368     public function CC_Campaign() { 
    1369         $CC_Campaign = new CC_Campaign(); 
    1370         self::updateSettings($CC_Campaign); 
    1371         return $CC_Campaign; 
    1372     } 
    1373  
    1374     public function CC_Utility() { 
    1375         $CC_Utility = new CC_Utility(); 
    1376         self::updateSettings($CC_Utility); 
    1377         return $CC_Utility; 
    1378     } 
    1379  
    1380     public function CC_Contact() { 
    1381         $CC_Contact = new CC_Contact(); 
    1382         self::updateSettings($CC_Contact); 
    1383         return $CC_Contact; 
    1384     } 
    1385  
    1386     public function listMergeVars() { 
    1387         return array( 
    1388             array('tag'=>'email_address', 'req' => true, 'name' => "Email Address"), 
    1389             array('tag'=>'first_name',    'req' => false, 'name' => "First Name"), 
    1390             array('tag'=>'middle_name',   'req' => false, 'name' => "Middle Name"), 
    1391             array('tag'=>'last_name',     'req' => false, 'name' => "Last Name"), 
    1392             array('tag'=>'job_title',     'req' => false, 'name' => "Job Title"), 
    1393             array('tag'=>'company_name',  'req' => false, 'name' => "Company Name"), 
    1394             array('tag'=>'home_number',   'req' => false, 'name' => "Home Phone"), 
    1395             array('tag'=>'work_number',   'req' => false, 'name' => "Work Phone"), 
    1396             array('tag'=>'address_line_1','req' => false, 'name' => "Address 1"), 
    1397             array('tag'=>'address_line_2','req' => false, 'name' => "Address 2"), 
    1398             array('tag'=>'address_line_3','req' => false, 'name' => "Address 3"), 
    1399             array('tag'=>'city_name',     'req' => false, 'name' => "City"), 
    1400             array('tag'=>'state_code',    'req' => false, 'name' => "State Code"), 
    1401             array('tag'=>'state_name',    'req' => false, 'name' => "State Name"), 
    1402             array('tag'=>'country_code',  'req' => false, 'name' => "Country Code"), 
    1403             array('tag'=>'country_name',  'req' => false, 'name' => "Country Name"), 
    1404             array('tag'=>'zip_code',      'req' => false, 'name' => "Postal Code"), 
    1405             array('tag'=>'sub_zip_code',  'req' => false, 'name' => "Sub Postal Code"), 
    1406             array('tag'=>'notes',         'req' => false, 'name' => "Note"), 
    1407             array('tag'=>'mail_type',     'req' => false, 'name' => "Email Type (Text or HTML)"), 
    1408             array('tag'=>'custom_field_1','req' => false, 'name' => "Custom Field 1 (Up to 50 characters)"), 
    1409             array('tag'=>'custom_field_2', 'req' => false, 'name' => "Custom Field 2 (Up to 50 characters)"), 
    1410             array('tag'=>'custom_field_3', 'req' => false, 'name' => "Custom Field 3 (Up to 50 characters)"), 
    1411             array('tag'=>'custom_field_4', 'req' => false, 'name' => "Custom Field 4 (Up to 50 characters)"), 
    1412             array('tag'=>'custom_field_5', 'req' => false, 'name' => "Custom Field 5 (Up to 50 characters)"), 
    1413             array('tag'=>'custom_field_6', 'req' => false, 'name' => "Custom Field 6 (Up to 50 characters)"), 
    1414             array('tag'=>'custom_field_7', 'req' => false, 'name' => "Custom Field 7 (Up to 50 characters)"), 
    1415             array('tag'=>'custom_field_8', 'req' => false, 'name' => "Custom Field 8 (Up to 50 characters)"), 
    1416             array('tag'=>'custom_field_9', 'req' => false, 'name' => "Custom Field 9 (Up to 50 characters)"), 
    1417             array('tag'=>'custom_field_10','req' => false, 'name' => "Custom Field 10 (Up to 50 characters)"), 
    1418             array('tag'=>'custom_field_11','req' => false, 'name' => "Custom Field 11 (Up to 50 characters)"), 
    1419             array('tag'=>'custom_field_12','req' => false, 'name' => "Custom Field 12 (Up to 50 characters)"), 
    1420             array('tag'=>'custom_field_13','req' => false, 'name' => "Custom Field 13 (Up to 50 characters)"), 
    1421             array('tag'=>'custom_field_14','req' => false, 'name' => "Custom Field 14 (Up to 50 characters)"), 
    1422             array('tag'=>'custom_field_15','req' => false, 'name' => "Custom Field 15 (Up to 50 characters)"), 
    1423         ); 
     40        GFAddOn::register( 'GF_Constant_Contact' ); 
    142441    } 
    142542 
    142643} 
    142744 
    1428 ?> 
     45function gf_constant_contact() { 
     46    return GF_Constant_Contact::get_instance(); 
     47} 
  • gravity-forms-constant-contact/trunk/gravityview-info.php

    r1218440 r1599305  
    1 <?php 
    2  
    3 /** 
    4  * To hide the add, you can add a filter: 
    5  * 
    6  * `add_filter('hide_gravityview_promotion-gravity-forms-constant-contact', '__return_true');` 
    7  * 
    8  * @var boolean 
    9  */ 
    10 $hide_promo = apply_filters( 'hide_gravityview_promotion-gravity-forms-constant-contact', class_exists('GravityView_Plugin') ); 
    11  
    12 if( $hide_promo ) { return; } 
    13  
    14 ?> 
    15  
    161<div class="hr-divider"></div> 
    172 
     
    8065<div id="kws_gravityview_info"> 
    8166    <div class="aligncenter"> 
    82         <a href="https://gravityview.co/pricing/?utm_source=plugin&amp;utm_medium=settings&amp;utm_content=logolink&amp;utm_campaign=gravity-forms-constant-contact" title="<?php esc_attr_e( 'Go to the GravityView Website', 'gravity-forms-constant-contact' ); ?>" class="aligncenter"><img src= "<?php echo plugins_url( '/images/GravityView-612x187.jpg', GFConstantContact::get_file() ); ?>" alt="GravityView Logo" width="306" height="93" /></a> 
     67        <a href="https://gravityview.co/pricing/?utm_source=plugin&amp;utm_medium=settings&amp;utm_content=logolink&amp;utm_campaign=gravity-forms-constant-contact" title="<?php esc_attr_e( 'Go to the GravityView Website', 'gravity-forms-constant-contact' ); ?>" class="aligncenter"><img src= "<?php echo GF_Constant_Contact::get_instance()->get_base_url() . '/images/GravityView-612x187.jpg'; ?>" alt="GravityView Logo" width="306" height="93" /></a> 
    8368        <h2><?php esc_html_e('GravityView is the best way to display Gravity Forms entries.', 'gravity-forms-constant-contact'); ?></h2> 
    8469 
    8570        <?php 
    86  
    87  
    88         echo '<h3>'. sprintf( esc_html__('Do you have form data you want to show on your website? Have you ever copied and pasted entries into your site? That&rsquo;s illogical! %sGravityView%s is here.', 'gravity-forms-constant-contact' ), '<a href="https://gravityview.co/pricing/?utm_source=plugin&amp;utm_medium=settings&amp;utm_content=subheadinglink&amp;utm_campaign=gravity-forms-constant-contact">', '</a>' ) .'</h3>'; 
    89  
     71            echo '<h3>'. sprintf( esc_html__('Do you have form data you want to show on your website? Have you ever copied and pasted entries into your site? That&rsquo;s illogical! %sGravityView%s is here.', 'gravity-forms-constant-contact' ), '<a href="https://gravityview.co/pricing/?utm_source=plugin&amp;utm_medium=settings&amp;utm_content=subheadinglink&amp;utm_campaign=gravity-forms-constant-contact">', '</a>' ) .'</h3>'; 
    9072        ?> 
    9173 
     
    9880            <li><?php esc_html_e('30 day money-back Guarantee', 'gravity-forms-constant-contact' ); ?></li> 
    9981        </ul> 
     82 
     83        <?php 
     84            echo '<h3 style="margin-top: 1.5em; text-align:center">' . esc_html__( 'Gravity Forms collects data. GravityView displays that data.') . '</h3>'; 
     85        ?> 
    10086 
    10187        <p class="submit"><a href="https://gravityview.co/pricing/?utm_source=plugin&amp;utm_medium=settings&amp;utm_content=buttonlink&amp;utm_campaign=gravity-forms-constant-contact" class="button button-hero button-primary"><?php esc_html_e('Try GravityView Today!', 'gravity-forms-constant-contact'); ?></a></p> 
  • gravity-forms-constant-contact/trunk/readme.txt

    r1218442 r1599305  
    11=== Gravity Forms Constant Contact === 
    2 Tags: gravity forms, forms, gravity, form, crm, gravity form, mail, email, newsletter, Constant Contact, plugin, sidebar, widget, mailing list, API, email marketing, newsletters 
    3 Requires at least: 3.3 
    4 Tested up to: 4.3 
     2Tags: gravity forms, gravity, forms, constant contact, constantcontact, newsletter, mailing list 
     3Requires at least: 4.0 
     4Tested up to: 4.7.2 
    55Stable tag: trunk 
    66Contributors: katzwebdesign, katzwebservices 
     
    1111== Description == 
    1212 
    13 > This plugin requires a <a href="http://wordpress.constantcontact.com/index.jsp" rel="nofollow">Constant Contact</a> account. 
     13> This plugin requires a <a href="http://wordpress.constantcontact.com/index.jsp" rel="nofollow">Constant Contact</a> account, and the <a href="https://www.e-junkie.com/ecom/gb.php?cl=54585&c=ib&aff=84089">Gravity Forms</a> form plugin. 
    1414 
    1515###Integrate Constant Contact with Gravity Forms 
     
    3333== Frequently Asked Questions == 
    3434 
     35= Does this plugin require Gravity Forms? = 
     36Yes, it does. <a href="https://www.e-junkie.com/ecom/gb.php?cl=54585&c=ib&aff=84089">You can purchase Gravity Forms here</a>. 
     37 
    3538= Does this plugin require Constant Contact? = 
    3639Yes, it does. If you don't have an Constant Contact account, <a href="http://wordpress.constantcontact.com/index.jsp" rel="nofollow">sign up for an account here</a>. 
     
    4851` 
    4952 
     53= How do I prevent access to the Settings page? = 
     54 
     55To see the Settings page (that has the Constant Contact username and password on it), an user must have the `gravityforms_constantcontact` capability. To enable or disable access to users, install the [Members plugin](https://wordpress.org/plugins/members/) and add or remove the capability from the user. 
     56 
    5057= How do I prevent the Entry notes confirming that the entry was added to Constant Contact? = 
    5158 
     
    5663` 
    5764 
    58  
    5965== Screenshots == 
    6066 
    61 1. Users can choose which Constant Contact lists they are added to. 
    62  
    63 == Upgrade Notice == 
    64  
    65 = 2.2.2 (August 11, 2015) = 
    66 * Fixed: Invalid login issue (thanks [@robertark](https://github.com/robertark)!) 
    67 * Confirmed plugin compatibility with WordPress 4.3 
    68  
    69 = 2.2 & 2.2.1 (January 5, 2015) =  
    70 * Fixed: Fatal error on activation for plugins located outside of `/plugins/` directory 
    71 * Modified: Converted API to use WordPress remote request functionality - now works with or without `curl` enabled. 
    72 * Fixed: PHP notices 
    73 * Tweak: Replace some images with Dashicons 
    74 * Tweak: Update Constant Contact logo for Retina displays 
    75 * Removed PressTrends reporting 
    76 * Added: Intro to GravityView plugin 
    77 * Tweak: Only fetch the API if a feed is going to be exported to CTCT 
    78  
    79  
    80 = 2.1.2 (February 5, 2014) = 
    81 * Fixed: Some servers are very sensitive to the fact of posting a form where some values are urls (in this case, the Constant Contact list endpoint). This version replaces that way of posting and adds three new methods to convert endpoint's in short id's and backwards. 
    82 * Fixed: Minor corrections (html, PHP warnings) 
    83  
    84 = 2.1.1 = 
    85 * Added: `gravityforms_constant_contact_change_date_format` filter to enable changing the format of the date field export to Constant Contact. 
    86  
    87 = 2.1 = 
    88 * Fixed: Many PHP notices. This should fix the "spinning" issue when creating a feed with `WP_DEBUG` turned on. 
    89 * Added: Now a note is added to each entry to confirm that the entry was added/updated in Constant Contact. 
    90 * Improved: PHP 5.4 support 
    91 * Improved: Look of the settings page, new CC logo 
    92  
    93 = 2.0.3 = 
    94 * Made it clearer that you need to configure the settings before creating a feed. 
    95 * Plugin now only checks username & password when saved; this prevents accounts being frozen 
    96 * Corrected "Opt-in Source" to be `ACTION_BY_CONTACT`, which is correct. It used to be `ACTION_BY_CUSTOMER`. 
    97 * Added notice when Gravity Forms isn't installed or active 
    98 * Attempted to fix bug where user names with spaces don't connect to the API properly 
    99 * Turned off curl debug for echoing errors on submitted forms. Add `?debug=true` to the page URL to turn back on. 
    100  
    101 = 2.0.2 = 
    102 * Fixed bug where Custom Fields don't get sent to Constant Contact. 
    103 * Added notice on Custom Fields feed setup to let user know that custom fields are limited to 50 characters. 
    104  
    105 = 2.0.1 = 
    106 * Fixed issue where registration notice shows up on Plugins page, even when Gravity Forms is registered. 
    107  
    108 = 2.0 = 
    109 * Converted to Gravity Forms Add-On Feeds system. If upgrading, <strong>you will need to re-configure your connected forms!</strong> 
    110 * Removed dependence on the <a href="http://wordpress.org/extend/plugins/constant-contact-api/">Constant Contact for WordPress</a> plugin 
    111  
    112 = 1.1 = 
    113 * Added list selection capability - allow users to choose which lists they are subscribed to (view the plugin's Installation tab or the Help tab on the Edit Form page to learn more) 
    114 * Improved notices if Gravity Forms or Constant Contact API is not installed or activated 
    115  
    116 = 1.0 = 
    117 * No upgrade notice, since this is the first version! 
     671. Plugin settings screen 
     682. Choose the lists form submissions are added to, and map the data (including Custom Fields!) 
     693. Add advanced logic to determine when a submission should (or should not) be added 
     704. Configure one or more feeds (Constant Contact sync rules) per form 
    11871 
    11972== Changelog == 
     73 
     74= 3.0 on February 19, 2017 = 
     75* Completely rewritten to use the Gravity Forms Feed Addon 2.0. If you are upgrading, <strong>check your feed configuration!</strong> 
     76* Now requires Gravity Forms 1.9.14+ 
     77 
     78__New Features:__ 
     79 
     80* Add subscriber to multiple lists at once 
     81* Use complex Opt-In Conditions (before, plugin only supported one condition) 
     82* Encrypt Constant Contact login settings 
     83* Improved restriction of settings page 
     84* Fixed bug that prevented emails with plus signs (+) from being processed properly 
     85* Confirmed compatibility with WordPress 4.7.2 
     86* Added improved logging 
     87* Added translation strings 
    12088 
    12189= 2.2.2 (August 11, 2015) = 
Note: See TracChangeset for help on using the changeset viewer.