WordPress.org

Plugin Directory

Changeset 504353


Ignore:
Timestamp:
02/13/12 15:47:15 (2 years ago)
Author:
joshuabettigole
Message:

update errant version string

Location:
contact-form-7-campaignmonitor-addon
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • contact-form-7-campaignmonitor-addon/tags/1.04/csrest_subscribers.php

    r503439 r504353  
    11<?php 
    2 /* 
    3 Plugin Name: Contact Form 7 - Campaign Monitor Addon 
    4 Plugin URI: http://www.bettigole.us/published-work/wordpress-contributions/campaign-monitor-addon-for-contact-form-7/ 
    5 Description: Add the power of CampaignMonitor to Contact Form 7 
    6 Author: Joshua Bettigole 
    7 Author URI: http://www.bettigole.us 
    8 Version: 1.03 
    9 */ 
    10  
    11 /*  Copyright 2010 Joshua Bettigole (email: joshua at bettigole.us) 
    12  
    13     This program is free software; you can redistribute it and/or modify 
    14     it under the terms of the GNU General Public License as published by 
    15     the Free Software Foundation; either version 2 of the License, or 
    16     (at your option) any later version. 
    17  
    18     This program is distributed in the hope that it will be useful, 
    19     but WITHOUT ANY WARRANTY; without even the implied warranty of 
    20     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
    21     GNU General Public License for more details. 
    22  
    23     You should have received a copy of the GNU General Public License 
    24     along with this program; if not, write to the Free Software 
    25     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA 
    26 */ 
    27  
    28 define( 'WPCF7_CM_VERSION', '1.03' ); 
    29  
    30 if ( ! defined( 'WPCF7_CM_PLUGIN_BASENAME' ) ) 
    31     define( 'WPCF7_CM_PLUGIN_BASENAME', plugin_basename( __FILE__ ) ); 
    32  
    33 add_action( 'wpcf7_after_save', 'wpcf7_cm_save_campaignmonitor' ); 
    34  
    35 function wpcf7_cm_save_campaignmonitor($args) 
    36 { 
    37     update_option( 'cf7_cm_'.$args->id, $_POST['wpcf7-campaignmonitor'] ); 
     2require_once dirname(__FILE__).'/class/base_classes.php'; 
     3 
     4/** 
     5 * Class to access a subscribers resources from the create send API. 
     6 * This class includes functions to add and remove subscribers , 
     7 * along with accessing statistics for a single subscriber 
     8 * @author tobyb 
     9 * 
     10 */ 
     11class CF7CM_CS_REST_Subscribers extends CF7CM_CS_REST_Wrapper_Base { 
     12 
     13    /** 
     14     * The base route of the subscriber resource. 
     15     * @var string 
     16     * @access private 
     17     */ 
     18    var $_subscribers_base_route; 
     19 
     20    /** 
     21     * Constructor. 
     22     * @param $list_id string The list id to access (Ignored for create requests) 
     23     * @param $api_key string Your api key (Ignored for get_apikey requests) 
     24     * @param $protocol string The protocol to use for requests (http|https) 
     25     * @param $debug_level int The level of debugging required CF7CM_CS_REST_LOG_NONE | CF7CM_CS_REST_LOG_ERROR | CF7CM_CS_REST_LOG_WARNING | CF7CM_CS_REST_LOG_VERBOSE 
     26     * @param $host string The host to send API requests to. There is no need to change this 
     27     * @param $log CF7CM_CS_REST_Log The logger to use. Used for dependency injection 
     28     * @param $serialiser The serialiser to use. Used for dependency injection 
     29     * @param $transport The transport to use. Used for dependency injection 
     30     * @access public 
     31     */ 
     32    function CF7CM_CS_REST_Subscribers ( 
     33    $list_id, 
     34    $api_key, 
     35    $protocol = 'https', 
     36    $debug_level = CF7CM_CS_REST_LOG_NONE, 
     37    $host = 'api.createsend.com', 
     38    $log = NULL, 
     39    $serialiser = NULL, 
     40    $transport = NULL) { 
     41             
     42        $this->CF7CM_CS_REST_Wrapper_Base($api_key, $protocol, $debug_level, $host, $log, $serialiser, $transport); 
     43        $this->set_list_id($list_id); 
     44 
     45    } 
     46 
     47    /** 
     48     * Change the list id used for calls after construction 
     49     * @param $list_id 
     50     * @access public 
     51     */ 
     52    function set_list_id($list_id) { 
     53        $this->_subscribers_base_route = $this->_base_route.'subscribers/'.$list_id; 
     54    } 
     55 
     56    /** 
     57     * Adds a new subscriber to the specified list 
     58     * @param array $subscriber The subscriber details to use during creation. 
     59     *     This array should be of the form 
     60     *     array ( 
     61     *         'EmailAddress' => The new subscribers email address 
     62     *         'Name' => The name of the new subscriber 
     63     *         'CustomFields' => array( 
     64     *             array( 
     65     *                 'Key' => The custom fields personalisation tag 
     66     *                 'Value' => The value for this subscriber 
     67     *             ) 
     68     *         ) 
     69     *         'Resubscribe' => Whether we should resubscribe this subscriber if they already exist in the list 
     70     *     ) 
     71     * @access public 
     72     * @return CS_REST_Wrapper_Result A successful response will be empty 
     73     */ 
     74    function add($subscriber) { 
     75        return $this->post_request($this->_subscribers_base_route.'.json', $subscriber); 
     76    } 
     77 
     78    /** 
     79     * Updates an existing subscriber (email, name, state, or custom fields) in the specified list. 
     80     * The update is performed even for inactive subscribers, but will return an error in the event of the 
     81     * given email not existing in the list. 
     82     * @param string $email The email address of the susbcriber to be updated 
     83     * @param array $subscriber The subscriber details to use for the update. Empty parameters will remain unchanged 
     84     *     This array should be of the form 
     85     *     array ( 
     86     *         'EmailAddress' => The new  email address 
     87     *         'Name' => The name of the subscriber 
     88     *         'CustomFields' => array( 
     89     *             array( 
     90     *                 'Key' => The custom fields personalisation tag 
     91     *                 'Value' => The value for this subscriber 
     92     *             ) 
     93     *         ) 
     94     *         'Resubscribe' => Whether we should resubscribe this subscriber if they already exist in the list 
     95     *     ) 
     96     * @access public 
     97     * @return CS_REST_Wrapper_Result A successful response will be empty 
     98     */ 
     99    function update($email, $subscriber) { 
     100        return $this->put_request($this->_subscribers_base_route.'.json?email='.urlencode($email), $subscriber); 
     101    } 
     102 
     103    /** 
     104     * Imports an array of subscribers into the current list 
     105     * @param array $subscribers An array of subscribers to import. 
     106     *     This array should be of the form 
     107     *     array ( 
     108     *         array ( 
     109     *             'EmailAddress' => The new subscribers email address 
     110     *             'Name' => The name of the new subscriber 
     111     *             'CustomFields' => array( 
     112     *                 array( 
     113     *                     'Key' => The custom fields personalisation tag 
     114     *                     'Value' => The value for this subscriber 
     115     *                 ) 
     116     *             ) 
     117     *         ) 
     118     *     ) 
     119     * @param $resubscribe Whether we should resubscribe any existing subscribers 
     120     * @access public 
     121     * @return CS_REST_Wrapper_Result A successful response will be an object of the form 
     122     * { 
     123     *     'TotalUniqueEmailsSubmitted' => The number of unique emails submitted in the call 
     124     *     'TotalExistingSubscribers' => The number of subscribers who already existed in the list 
     125     *     'TotalNewSubscribers' => The number of new subscriptions to the list 
     126     *     'DuplicateEmailsInSubmission' => array<string> The emails which appeared more than once in the batch 
     127     *     'FailureDetails' => array ( 
     128     *         { 
     129     *             'EmailAddress' => The email address which failed 
     130     *             'Code' => The Create Send API Error code 
     131     *             'Message' => The reason for the failure 
     132     *         } 
     133     *     ) 
     134     * } 
     135     * 
     136     */ 
     137    function import($subscribers, $resubscribe) { 
     138        $subscribers = array( 
     139            'Resubscribe' => $resubscribe, 
     140            'Subscribers' => $subscribers 
     141        ); 
     142         
     143        return $this->post_request($this->_subscribers_base_route.'/import.json', $subscribers); 
     144    } 
     145 
     146    /** 
     147     * Gets a subscriber details, including custom fields 
     148     * @access public 
     149     * @return CS_REST_Wrapper_Result A successful response will be an object of the form 
     150     * { 
     151     *     'EmailAddress' => The subscriber email address 
     152     *     'Name' => The subscribers name 
     153     *     'Date' => The date the subscriber was added to the list 
     154     *     'State' => The current state of the subscriber 
     155     *     'CustomFields' => array( 
     156     *         { 
     157     *             'Key' => The custom fields personalisation tag 
     158     *             'Value' => The custom field value for this subscriber 
     159     *         } 
     160     *     ) 
     161     * } 
     162     */ 
     163    function get($email) { 
     164        return $this->get_request($this->_subscribers_base_route.'.json?email='.urlencode($email)); 
     165    } 
     166 
     167    /** 
     168     * Gets the sending history to a specific subscriber 
     169     * @access public 
     170     * @return CS_REST_Wrapper_Result A successful response will be an object of the form 
     171     * array( 
     172     *     { 
     173     *         ID => The id of the email which was sent 
     174     *         Type => 'Campaign' 
     175     *         Name => The name of the email 
     176     *         Actions => array( 
     177     *             { 
     178     *                 Event => The type of action (Click, Open, Unsubscribe etc) 
     179     *                 Date => The date the event occurred 
     180     *                 IPAddress => The IP that the event originated from 
     181     *                 Detail => Any available details about the event i.e the URL for clicks 
     182     *             } 
     183     *         ) 
     184     *     } 
     185     * ) 
     186     */ 
     187    function get_history($email) { 
     188        return $this->get_request($this->_subscribers_base_route.'/history.json?email='.urlencode($email)); 
     189    } 
     190 
     191    /** 
     192     * Unsubscribes the given subscriber from the current list 
     193     * @param string $email The email address to unsubscribe 
     194     * @access public 
     195     * @return CS_REST_Wrapper_Result A successful response will be empty 
     196     */ 
     197    function unsubscribe($email) { 
     198        // We need to build the subscriber data structure. 
     199        $email = array( 
     200            'EmailAddress' => $email  
     201        ); 
     202         
     203        return $this->post_request($this->_subscribers_base_route.'/unsubscribe.json', $email); 
     204    } 
     205 
     206 
    38207} 
    39  
    40 add_action( 'wpcf7_admin_before_subsubsub', 'add_cm_meta' ); 
    41  
    42 function add_cm_meta (){ 
    43     if ( wpcf7_admin_has_edit_cap() ) { 
    44         add_meta_box( 'cf7cmdiv', __( 'Campaign Monitor', 'wpcf7' ), 
    45             'wpcf7_cm_add_campaignmonitor', 'cfseven', 'cf7_cm', 'core', 
    46             array( 
    47                 'id' => 'wpcf7-cf7', 
    48                 'name' => 'cf7_cm', 
    49                 'use' => __( 'Use Campaign Monitor', 'wpcf7' ) ) ); 
    50     } 
    51 } 
    52  
    53 add_action( 'wpcf7_admin_after_mail_2', 'show_cm_metabox' ); 
    54  
    55 function show_cm_metabox($cf){ 
    56     do_meta_boxes( 'cfseven', 'cf7_cm', $cf ); 
    57 } 
    58              
    59 function wpcf7_cm_add_campaignmonitor($args) 
    60 { 
    61                 $cf7_cm_defaults = array(); 
    62                 $cf7_cm = get_option( 'cf7_cm_'.$args->id, $cf7_cm_defaults ); 
    63             ?> 
    64                  
    65 <div class="mail-field"> 
    66     <input type="checkbox" id="wpcf7-campaignmonitor-active" name="wpcf7-campaignmonitor[active]" value="1"<?php echo ( $cf7_cm['active']==1 ) ? ' checked="checked"' : ''; ?> /> 
    67     <label for="wpcf7-campaignmonitor-active"><?php echo esc_html( __( 'Use CampaignMonitor', 'wpcf7' ) ); ?></label> 
    68 <div class="pseudo-hr"></div> 
    69 </div> 
    70  
    71 <br class="clear" /> 
    72  
    73 <div class="mail-fields"> 
    74     <div class="half-left"> 
    75         <div class="mail-field"> 
    76             <label for="wpcf7-campaignmonitor-email"><?php echo esc_html( __( 'Subscriber Email:', 'wpcf7' ) ); ?></label><br /> 
    77             <input type="text" id="wpcf7-campaignmonitor-email" name="wpcf7-campaignmonitor[email]" class="wide" size="70" value="<?php echo esc_attr( $cf7_cm['email'] ); ?>" /> 
    78         </div> 
    79      
    80         <div class="mail-field"> 
    81         <label for="wpcf7-campaignmonitor-name"><?php echo esc_html( __( 'Subscriber Full Name:', 'wpcf7' ) ); ?></label><br /> 
    82         <input type="text" id="wpcf7-campaignmonitor-name" name="wpcf7-campaignmonitor[name]" class="wide" size="70" value="<?php echo esc_attr( $cf7_cm['name'] ); ?>" /> 
    83         </div> 
    84      
    85         <div class="mail-field"> 
    86         <label for="wpcf7-campaignmonitor-accept"><?php echo esc_html( __( 'Required Acceptance Field:', 'wpcf7' ) ); ?></label><br /> 
    87         <input type="text" id="wpcf7-campaignmonitor-accept" name="wpcf7-campaignmonitor[accept]" class="wide" size="70" value="<?php echo esc_attr( $cf7_cm['accept'] ); ?>" /> 
    88         </div> 
    89      
    90         <div class="mail-field"><br/> 
    91         <input type="checkbox" id="wpcf7-campaignmonitor-cf-active" name="wpcf7-campaignmonitor[cfactive]" value="1"<?php echo ( $cf7_cm['cfactive'] ) ? ' checked="checked"' : ''; ?> /> 
    92         <label for="wpcf7-campaignmonitor-cfactive"><?php echo esc_html( __( 'Use Custom Fields', 'wpcf7' ) ); ?></label><br/><br/> 
    93         </div> 
    94     </div> 
    95      
    96     <div class="half-right"> 
    97         <div class="mail-field"> 
    98         <label for="wpcf7-campaignmonitor-api"><?php echo esc_html( __( 'API Key:', 'wpcf7' ) ); ?></label><br /> 
    99         <input type="text" id="wpcf7-campaignmonitor-api" name="wpcf7-campaignmonitor[api]" class="wide" size="70" value="<?php echo esc_attr( $cf7_cm['api'] ); ?>" /> 
    100         </div> 
    101  
    102         <div class="mail-field"> 
    103         <label for="wpcf7-campaignmonitor-client"><?php echo esc_html( __( 'Client ID:', 'wpcf7' ) ); ?></label><br /> 
    104         <input type="text" id="wpcf7-campaignmonitor-client" name="wpcf7-campaignmonitor[client]" class="wide" size="70" value="<?php echo esc_attr( $cf7_cm['client'] ); ?>" /> 
    105         </div> 
    106  
    107         <div class="mail-field"> 
    108         <label for="wpcf7-campaignmonitor-list"><?php echo esc_html( __( 'List ID:', 'wpcf7' ) ); ?></label><br /> 
    109         <input type="text" id="wpcf7-campaignmonitor-list" name="wpcf7-campaignmonitor[list]" class="wide" size="70" value="<?php echo esc_attr( $cf7_cm['list'] ); ?>" /> 
    110         </div> 
    111  
    112         <div class="mail-field"><br/> 
    113         <input type="checkbox" id="wpcf7-campaignmonitor-resubscribeoption" name="wpcf7-campaignmonitor[resubscribeoption]" value="1"<?php echo ( $cf7_cm['resubscribeoption'] ) ? ' checked="checked"' : ''; ?> /> 
    114         <label for="wpcf7-campaignmonitor-resubscribeoption"><?php echo esc_html( __( 'Allow Users to Resubscribe after being Deleted or Unsubscribed? (checked = true)', 'wpcf7' ) ); ?></label><br/><br/> 
    115         </div> 
    116     </div> 
    117      
    118     <br class="clear" /> 
    119  
    120     <div class="campaignmonitor-custom-fields"> 
    121         <?php for($i=1;$i<=20;$i++){ ?> 
    122             <div class="half-left"> 
    123                 <div class="mail-field"> 
    124                 <label for="wpcf7-campaignmonitor-CustomKey<?php echo $i; ?>"><?php echo esc_html( __( 'CustomKey'.$i.':', 'wpcf7' ) ); ?></label><br /> 
    125                 <input type="text" id="wpcf7-campaignmonitor-CustomKey<?php echo $i; ?>" name="wpcf7-campaignmonitor[CustomKey<?php echo $i; ?>]" class="wide" size="70" value="<?php echo esc_attr( $cf7_cm['CustomKey'.$i] ); ?>" /> 
    126                 </div> 
    127             </div> 
    128             <div class="half-left"> 
    129                 <div class="mail-field"> 
    130                 <label for="wpcf7-campaignmonitor-CustomValue<?php echo $i; ?>"><?php echo esc_html( __( 'CustomValue'.$i.':', 'wpcf7' ) ); ?></label><br /> 
    131                 <input type="text" id="wpcf7-campaignmonitor-CustomValue<?php echo $i; ?>" name="wpcf7-campaignmonitor[CustomValue<?php echo $i; ?>]" class="wide" size="70" value="<?php echo esc_attr( $cf7_cm['CustomValue'.$i] ); ?>" /> 
    132                 </div> 
    133             </div> 
    134             <br class="clear" />     
    135         <?php } ?> 
    136          
    137     </div> 
    138 </div> 
    139  
    140                 <?php 
    141  
    142 } 
    143  
    144  
    145 add_action( 'admin_print_scripts', 'wpcf7_cm_admin_enqueue_scripts' ); 
    146  
    147 function wpcf7_cm_admin_enqueue_scripts () 
    148 { 
    149     global $plugin_page; 
    150  
    151     if ( ! isset( $plugin_page ) || 'wpcf7' != $plugin_page ) 
    152         return; 
    153  
    154     wp_enqueue_script( 'wpcf7-cm-admin', wpcf7_cm_plugin_url( 'scripts.js' ), 
    155         array( 'jquery', 'wpcf7-admin' ), WPCF7_CM_VERSION, true ); 
    156 } 
    157  
    158  
    159 add_action( 'wpcf7_before_send_mail', 'wpcf7_cm_subscribe' ); 
    160  
    161 function wpcf7_cm_subscribe($obj) 
    162 { 
    163     $cf7_cm = get_option( 'cf7_cm_'.$obj->id ); 
    164     if( $cf7_cm ) 
    165     { 
    166         $subscribe = false; 
    167  
    168         $regex = '/\[\s*([a-zA-Z_][0-9a-zA-Z:._-]*)\s*\]/'; 
    169         $callback = array( &$obj, 'cf7_cm_callback' ); 
    170      
    171         $email = cf7_cm_tag_replace( $regex, $cf7_cm['email'], $obj->posted_data ); 
    172         $name = cf7_cm_tag_replace( $regex, $cf7_cm['name'], $obj->posted_data ); 
    173          
    174         $lists = cf7_cm_tag_replace( $regex, $cf7_cm['list'], $obj->posted_data ); 
    175         $listarr = explode(',',$lists); 
    176  
    177         if( isset($cf7_cm['accept']) && strlen($cf7_cm['accept']) != 0 ) 
    178         { 
    179             $accept = cf7_cm_tag_replace( $regex, $cf7_cm['accept'], $obj->posted_data ); 
    180             if($accept != $cf7_cm['accept']) 
    181             { 
    182                 if(strlen($accept) > 0) 
    183                     $subscribe = true; 
    184             } 
    185         } 
    186         else 
    187         { 
    188             $subscribe = true; 
    189         } 
    190  
    191         for($i=1;$i<=20;$i++){ 
    192          
    193             if( isset($cf7_cm['CustomKey'.$i]) && isset($cf7_cm['CustomValue'.$i]) && strlen(trim($cf7_cm['CustomValue'.$i])) != 0 ) 
    194             { 
    195                 $CustomFields[] = array('Key'=>trim($cf7_cm['CustomKey'.$i]), 'Value'=>cf7_cm_tag_replace( $regex, trim($cf7_cm['CustomValue'.$i]), $obj->posted_data ) ); 
    196             } 
    197  
    198         } 
    199          
    200          
    201         if( isset($cf7_cm['resubscribeoption']) && strlen($cf7_cm['resubscribeoption']) != 0 ) 
    202         { 
    203             $ResubscribeOption = true; 
    204         }  
    205             else 
    206         { 
    207             $ResubscribeOption = false; 
    208         } 
    209          
    210         if($subscribe && $email != $cf7_cm['email']) 
    211         { 
    212              
    213             require_once(dirname(__FILE__).DIRECTORY_SEPARATOR.'csrest_subscribers.php'); 
    214              
    215             $wrap = new CS_REST_Subscribers( trim($listarr[0]), $cf7_cm['api'] ); 
    216             foreach($listarr as $listid) 
    217             { 
    218                 $wrap->set_list_id(trim($listid)); 
    219                 $wrap->add(array( 
    220                     'EmailAddress' => $email, 
    221                     'Name' => $name, 
    222                     'CustomFields' => $CustomFields, 
    223                     'Resubscribe' => $ResubscribeOption 
    224                 )); 
    225             } 
    226              
    227         } 
    228          
    229     } 
    230 } 
    231  
    232 function cf7_cm_tag_replace( $pattern, $subject, $posted_data, $html = false ) { 
    233     if( preg_match($pattern,$subject,$matches) > 0) 
    234     { 
    235      
    236         if ( isset( $posted_data[$matches[1]] ) ) { 
    237             $submitted = $posted_data[$matches[1]]; 
    238      
    239             if ( is_array( $submitted ) ) 
    240                 $replaced = join( ', ', $submitted ); 
    241             else 
    242                 $replaced = $submitted; 
    243      
    244             if ( $html ) { 
    245                 $replaced = strip_tags( $replaced ); 
    246                 $replaced = wptexturize( $replaced ); 
    247             } 
    248      
    249             $replaced = apply_filters( 'wpcf7_mail_tag_replaced', $replaced, $submitted ); 
    250      
    251             return stripslashes( $replaced ); 
    252         } 
    253      
    254         if ( $special = apply_filters( 'wpcf7_special_mail_tags', '', $matches[1] ) ) 
    255             return $special; 
    256      
    257         return $matches[0]; 
    258     } 
    259     return $subject; 
    260 } 
    261  
    262 function wpcf7_cm_plugin_url( $path = '' ) { 
    263     return plugins_url( $path, WPCF7_CM_PLUGIN_BASENAME ); 
    264 } 
    265  
    266  
    267 add_filter( 'plugin_action_links', 'wpcf7_cm_plugin_action_links', 10, 2 ); 
    268  
    269  
    270 function wpcf7_cm_plugin_action_links( $links, $file ) { 
    271  
    272     if ( $file != plugin_basename( __FILE__ ) ) 
    273         return $links; 
    274  
    275     $url = wpcf7_admin_url( array( 'page' => 'wpcf7' ) ); 
    276  
    277     $settings_link = '<a href="' . esc_attr( $url ) . '">' . esc_html( __( 'Settings', 'wpcf7' ) ) . '</a>'; 
    278  
    279     array_unshift( $links, $settings_link ); 
    280  
    281     return $links; 
    282  
    283 } 
  • contact-form-7-campaignmonitor-addon/trunk/csrest_subscribers.php

    r503438 r504353  
    11<?php 
    2 /* 
    3 Plugin Name: Contact Form 7 - Campaign Monitor Addon 
    4 Plugin URI: http://www.bettigole.us/published-work/wordpress-contributions/campaign-monitor-addon-for-contact-form-7/ 
    5 Description: Add the power of CampaignMonitor to Contact Form 7 
    6 Author: Joshua Bettigole 
    7 Author URI: http://www.bettigole.us 
    8 Version: 1.03 
    9 */ 
    10  
    11 /*  Copyright 2010 Joshua Bettigole (email: joshua at bettigole.us) 
    12  
    13     This program is free software; you can redistribute it and/or modify 
    14     it under the terms of the GNU General Public License as published by 
    15     the Free Software Foundation; either version 2 of the License, or 
    16     (at your option) any later version. 
    17  
    18     This program is distributed in the hope that it will be useful, 
    19     but WITHOUT ANY WARRANTY; without even the implied warranty of 
    20     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
    21     GNU General Public License for more details. 
    22  
    23     You should have received a copy of the GNU General Public License 
    24     along with this program; if not, write to the Free Software 
    25     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA 
    26 */ 
    27  
    28 define( 'WPCF7_CM_VERSION', '1.03' ); 
    29  
    30 if ( ! defined( 'WPCF7_CM_PLUGIN_BASENAME' ) ) 
    31     define( 'WPCF7_CM_PLUGIN_BASENAME', plugin_basename( __FILE__ ) ); 
    32  
    33 add_action( 'wpcf7_after_save', 'wpcf7_cm_save_campaignmonitor' ); 
    34  
    35 function wpcf7_cm_save_campaignmonitor($args) 
    36 { 
    37     update_option( 'cf7_cm_'.$args->id, $_POST['wpcf7-campaignmonitor'] ); 
     2require_once dirname(__FILE__).'/class/base_classes.php'; 
     3 
     4/** 
     5 * Class to access a subscribers resources from the create send API. 
     6 * This class includes functions to add and remove subscribers , 
     7 * along with accessing statistics for a single subscriber 
     8 * @author tobyb 
     9 * 
     10 */ 
     11class CF7CM_CS_REST_Subscribers extends CF7CM_CS_REST_Wrapper_Base { 
     12 
     13    /** 
     14     * The base route of the subscriber resource. 
     15     * @var string 
     16     * @access private 
     17     */ 
     18    var $_subscribers_base_route; 
     19 
     20    /** 
     21     * Constructor. 
     22     * @param $list_id string The list id to access (Ignored for create requests) 
     23     * @param $api_key string Your api key (Ignored for get_apikey requests) 
     24     * @param $protocol string The protocol to use for requests (http|https) 
     25     * @param $debug_level int The level of debugging required CF7CM_CS_REST_LOG_NONE | CF7CM_CS_REST_LOG_ERROR | CF7CM_CS_REST_LOG_WARNING | CF7CM_CS_REST_LOG_VERBOSE 
     26     * @param $host string The host to send API requests to. There is no need to change this 
     27     * @param $log CF7CM_CS_REST_Log The logger to use. Used for dependency injection 
     28     * @param $serialiser The serialiser to use. Used for dependency injection 
     29     * @param $transport The transport to use. Used for dependency injection 
     30     * @access public 
     31     */ 
     32    function CF7CM_CS_REST_Subscribers ( 
     33    $list_id, 
     34    $api_key, 
     35    $protocol = 'https', 
     36    $debug_level = CF7CM_CS_REST_LOG_NONE, 
     37    $host = 'api.createsend.com', 
     38    $log = NULL, 
     39    $serialiser = NULL, 
     40    $transport = NULL) { 
     41             
     42        $this->CF7CM_CS_REST_Wrapper_Base($api_key, $protocol, $debug_level, $host, $log, $serialiser, $transport); 
     43        $this->set_list_id($list_id); 
     44 
     45    } 
     46 
     47    /** 
     48     * Change the list id used for calls after construction 
     49     * @param $list_id 
     50     * @access public 
     51     */ 
     52    function set_list_id($list_id) { 
     53        $this->_subscribers_base_route = $this->_base_route.'subscribers/'.$list_id; 
     54    } 
     55 
     56    /** 
     57     * Adds a new subscriber to the specified list 
     58     * @param array $subscriber The subscriber details to use during creation. 
     59     *     This array should be of the form 
     60     *     array ( 
     61     *         'EmailAddress' => The new subscribers email address 
     62     *         'Name' => The name of the new subscriber 
     63     *         'CustomFields' => array( 
     64     *             array( 
     65     *                 'Key' => The custom fields personalisation tag 
     66     *                 'Value' => The value for this subscriber 
     67     *             ) 
     68     *         ) 
     69     *         'Resubscribe' => Whether we should resubscribe this subscriber if they already exist in the list 
     70     *     ) 
     71     * @access public 
     72     * @return CS_REST_Wrapper_Result A successful response will be empty 
     73     */ 
     74    function add($subscriber) { 
     75        return $this->post_request($this->_subscribers_base_route.'.json', $subscriber); 
     76    } 
     77 
     78    /** 
     79     * Updates an existing subscriber (email, name, state, or custom fields) in the specified list. 
     80     * The update is performed even for inactive subscribers, but will return an error in the event of the 
     81     * given email not existing in the list. 
     82     * @param string $email The email address of the susbcriber to be updated 
     83     * @param array $subscriber The subscriber details to use for the update. Empty parameters will remain unchanged 
     84     *     This array should be of the form 
     85     *     array ( 
     86     *         'EmailAddress' => The new  email address 
     87     *         'Name' => The name of the subscriber 
     88     *         'CustomFields' => array( 
     89     *             array( 
     90     *                 'Key' => The custom fields personalisation tag 
     91     *                 'Value' => The value for this subscriber 
     92     *             ) 
     93     *         ) 
     94     *         'Resubscribe' => Whether we should resubscribe this subscriber if they already exist in the list 
     95     *     ) 
     96     * @access public 
     97     * @return CS_REST_Wrapper_Result A successful response will be empty 
     98     */ 
     99    function update($email, $subscriber) { 
     100        return $this->put_request($this->_subscribers_base_route.'.json?email='.urlencode($email), $subscriber); 
     101    } 
     102 
     103    /** 
     104     * Imports an array of subscribers into the current list 
     105     * @param array $subscribers An array of subscribers to import. 
     106     *     This array should be of the form 
     107     *     array ( 
     108     *         array ( 
     109     *             'EmailAddress' => The new subscribers email address 
     110     *             'Name' => The name of the new subscriber 
     111     *             'CustomFields' => array( 
     112     *                 array( 
     113     *                     'Key' => The custom fields personalisation tag 
     114     *                     'Value' => The value for this subscriber 
     115     *                 ) 
     116     *             ) 
     117     *         ) 
     118     *     ) 
     119     * @param $resubscribe Whether we should resubscribe any existing subscribers 
     120     * @access public 
     121     * @return CS_REST_Wrapper_Result A successful response will be an object of the form 
     122     * { 
     123     *     'TotalUniqueEmailsSubmitted' => The number of unique emails submitted in the call 
     124     *     'TotalExistingSubscribers' => The number of subscribers who already existed in the list 
     125     *     'TotalNewSubscribers' => The number of new subscriptions to the list 
     126     *     'DuplicateEmailsInSubmission' => array<string> The emails which appeared more than once in the batch 
     127     *     'FailureDetails' => array ( 
     128     *         { 
     129     *             'EmailAddress' => The email address which failed 
     130     *             'Code' => The Create Send API Error code 
     131     *             'Message' => The reason for the failure 
     132     *         } 
     133     *     ) 
     134     * } 
     135     * 
     136     */ 
     137    function import($subscribers, $resubscribe) { 
     138        $subscribers = array( 
     139            'Resubscribe' => $resubscribe, 
     140            'Subscribers' => $subscribers 
     141        ); 
     142         
     143        return $this->post_request($this->_subscribers_base_route.'/import.json', $subscribers); 
     144    } 
     145 
     146    /** 
     147     * Gets a subscriber details, including custom fields 
     148     * @access public 
     149     * @return CS_REST_Wrapper_Result A successful response will be an object of the form 
     150     * { 
     151     *     'EmailAddress' => The subscriber email address 
     152     *     'Name' => The subscribers name 
     153     *     'Date' => The date the subscriber was added to the list 
     154     *     'State' => The current state of the subscriber 
     155     *     'CustomFields' => array( 
     156     *         { 
     157     *             'Key' => The custom fields personalisation tag 
     158     *             'Value' => The custom field value for this subscriber 
     159     *         } 
     160     *     ) 
     161     * } 
     162     */ 
     163    function get($email) { 
     164        return $this->get_request($this->_subscribers_base_route.'.json?email='.urlencode($email)); 
     165    } 
     166 
     167    /** 
     168     * Gets the sending history to a specific subscriber 
     169     * @access public 
     170     * @return CS_REST_Wrapper_Result A successful response will be an object of the form 
     171     * array( 
     172     *     { 
     173     *         ID => The id of the email which was sent 
     174     *         Type => 'Campaign' 
     175     *         Name => The name of the email 
     176     *         Actions => array( 
     177     *             { 
     178     *                 Event => The type of action (Click, Open, Unsubscribe etc) 
     179     *                 Date => The date the event occurred 
     180     *                 IPAddress => The IP that the event originated from 
     181     *                 Detail => Any available details about the event i.e the URL for clicks 
     182     *             } 
     183     *         ) 
     184     *     } 
     185     * ) 
     186     */ 
     187    function get_history($email) { 
     188        return $this->get_request($this->_subscribers_base_route.'/history.json?email='.urlencode($email)); 
     189    } 
     190 
     191    /** 
     192     * Unsubscribes the given subscriber from the current list 
     193     * @param string $email The email address to unsubscribe 
     194     * @access public 
     195     * @return CS_REST_Wrapper_Result A successful response will be empty 
     196     */ 
     197    function unsubscribe($email) { 
     198        // We need to build the subscriber data structure. 
     199        $email = array( 
     200            'EmailAddress' => $email  
     201        ); 
     202         
     203        return $this->post_request($this->_subscribers_base_route.'/unsubscribe.json', $email); 
     204    } 
     205 
     206 
    38207} 
    39  
    40 add_action( 'wpcf7_admin_before_subsubsub', 'add_cm_meta' ); 
    41  
    42 function add_cm_meta (){ 
    43     if ( wpcf7_admin_has_edit_cap() ) { 
    44         add_meta_box( 'cf7cmdiv', __( 'Campaign Monitor', 'wpcf7' ), 
    45             'wpcf7_cm_add_campaignmonitor', 'cfseven', 'cf7_cm', 'core', 
    46             array( 
    47                 'id' => 'wpcf7-cf7', 
    48                 'name' => 'cf7_cm', 
    49                 'use' => __( 'Use Campaign Monitor', 'wpcf7' ) ) ); 
    50     } 
    51 } 
    52  
    53 add_action( 'wpcf7_admin_after_mail_2', 'show_cm_metabox' ); 
    54  
    55 function show_cm_metabox($cf){ 
    56     do_meta_boxes( 'cfseven', 'cf7_cm', $cf ); 
    57 } 
    58              
    59 function wpcf7_cm_add_campaignmonitor($args) 
    60 { 
    61                 $cf7_cm_defaults = array(); 
    62                 $cf7_cm = get_option( 'cf7_cm_'.$args->id, $cf7_cm_defaults ); 
    63             ?> 
    64                  
    65 <div class="mail-field"> 
    66     <input type="checkbox" id="wpcf7-campaignmonitor-active" name="wpcf7-campaignmonitor[active]" value="1"<?php echo ( $cf7_cm['active']==1 ) ? ' checked="checked"' : ''; ?> /> 
    67     <label for="wpcf7-campaignmonitor-active"><?php echo esc_html( __( 'Use CampaignMonitor', 'wpcf7' ) ); ?></label> 
    68 <div class="pseudo-hr"></div> 
    69 </div> 
    70  
    71 <br class="clear" /> 
    72  
    73 <div class="mail-fields"> 
    74     <div class="half-left"> 
    75         <div class="mail-field"> 
    76             <label for="wpcf7-campaignmonitor-email"><?php echo esc_html( __( 'Subscriber Email:', 'wpcf7' ) ); ?></label><br /> 
    77             <input type="text" id="wpcf7-campaignmonitor-email" name="wpcf7-campaignmonitor[email]" class="wide" size="70" value="<?php echo esc_attr( $cf7_cm['email'] ); ?>" /> 
    78         </div> 
    79      
    80         <div class="mail-field"> 
    81         <label for="wpcf7-campaignmonitor-name"><?php echo esc_html( __( 'Subscriber Full Name:', 'wpcf7' ) ); ?></label><br /> 
    82         <input type="text" id="wpcf7-campaignmonitor-name" name="wpcf7-campaignmonitor[name]" class="wide" size="70" value="<?php echo esc_attr( $cf7_cm['name'] ); ?>" /> 
    83         </div> 
    84      
    85         <div class="mail-field"> 
    86         <label for="wpcf7-campaignmonitor-accept"><?php echo esc_html( __( 'Required Acceptance Field:', 'wpcf7' ) ); ?></label><br /> 
    87         <input type="text" id="wpcf7-campaignmonitor-accept" name="wpcf7-campaignmonitor[accept]" class="wide" size="70" value="<?php echo esc_attr( $cf7_cm['accept'] ); ?>" /> 
    88         </div> 
    89      
    90         <div class="mail-field"><br/> 
    91         <input type="checkbox" id="wpcf7-campaignmonitor-cf-active" name="wpcf7-campaignmonitor[cfactive]" value="1"<?php echo ( $cf7_cm['cfactive'] ) ? ' checked="checked"' : ''; ?> /> 
    92         <label for="wpcf7-campaignmonitor-cfactive"><?php echo esc_html( __( 'Use Custom Fields', 'wpcf7' ) ); ?></label><br/><br/> 
    93         </div> 
    94     </div> 
    95      
    96     <div class="half-right"> 
    97         <div class="mail-field"> 
    98         <label for="wpcf7-campaignmonitor-api"><?php echo esc_html( __( 'API Key:', 'wpcf7' ) ); ?></label><br /> 
    99         <input type="text" id="wpcf7-campaignmonitor-api" name="wpcf7-campaignmonitor[api]" class="wide" size="70" value="<?php echo esc_attr( $cf7_cm['api'] ); ?>" /> 
    100         </div> 
    101  
    102         <div class="mail-field"> 
    103         <label for="wpcf7-campaignmonitor-client"><?php echo esc_html( __( 'Client ID:', 'wpcf7' ) ); ?></label><br /> 
    104         <input type="text" id="wpcf7-campaignmonitor-client" name="wpcf7-campaignmonitor[client]" class="wide" size="70" value="<?php echo esc_attr( $cf7_cm['client'] ); ?>" /> 
    105         </div> 
    106  
    107         <div class="mail-field"> 
    108         <label for="wpcf7-campaignmonitor-list"><?php echo esc_html( __( 'List ID:', 'wpcf7' ) ); ?></label><br /> 
    109         <input type="text" id="wpcf7-campaignmonitor-list" name="wpcf7-campaignmonitor[list]" class="wide" size="70" value="<?php echo esc_attr( $cf7_cm['list'] ); ?>" /> 
    110         </div> 
    111  
    112         <div class="mail-field"><br/> 
    113         <input type="checkbox" id="wpcf7-campaignmonitor-resubscribeoption" name="wpcf7-campaignmonitor[resubscribeoption]" value="1"<?php echo ( $cf7_cm['resubscribeoption'] ) ? ' checked="checked"' : ''; ?> /> 
    114         <label for="wpcf7-campaignmonitor-resubscribeoption"><?php echo esc_html( __( 'Allow Users to Resubscribe after being Deleted or Unsubscribed? (checked = true)', 'wpcf7' ) ); ?></label><br/><br/> 
    115         </div> 
    116     </div> 
    117      
    118     <br class="clear" /> 
    119  
    120     <div class="campaignmonitor-custom-fields"> 
    121         <?php for($i=1;$i<=20;$i++){ ?> 
    122             <div class="half-left"> 
    123                 <div class="mail-field"> 
    124                 <label for="wpcf7-campaignmonitor-CustomKey<?php echo $i; ?>"><?php echo esc_html( __( 'CustomKey'.$i.':', 'wpcf7' ) ); ?></label><br /> 
    125                 <input type="text" id="wpcf7-campaignmonitor-CustomKey<?php echo $i; ?>" name="wpcf7-campaignmonitor[CustomKey<?php echo $i; ?>]" class="wide" size="70" value="<?php echo esc_attr( $cf7_cm['CustomKey'.$i] ); ?>" /> 
    126                 </div> 
    127             </div> 
    128             <div class="half-left"> 
    129                 <div class="mail-field"> 
    130                 <label for="wpcf7-campaignmonitor-CustomValue<?php echo $i; ?>"><?php echo esc_html( __( 'CustomValue'.$i.':', 'wpcf7' ) ); ?></label><br /> 
    131                 <input type="text" id="wpcf7-campaignmonitor-CustomValue<?php echo $i; ?>" name="wpcf7-campaignmonitor[CustomValue<?php echo $i; ?>]" class="wide" size="70" value="<?php echo esc_attr( $cf7_cm['CustomValue'.$i] ); ?>" /> 
    132                 </div> 
    133             </div> 
    134             <br class="clear" />     
    135         <?php } ?> 
    136          
    137     </div> 
    138 </div> 
    139  
    140                 <?php 
    141  
    142 } 
    143  
    144  
    145 add_action( 'admin_print_scripts', 'wpcf7_cm_admin_enqueue_scripts' ); 
    146  
    147 function wpcf7_cm_admin_enqueue_scripts () 
    148 { 
    149     global $plugin_page; 
    150  
    151     if ( ! isset( $plugin_page ) || 'wpcf7' != $plugin_page ) 
    152         return; 
    153  
    154     wp_enqueue_script( 'wpcf7-cm-admin', wpcf7_cm_plugin_url( 'scripts.js' ), 
    155         array( 'jquery', 'wpcf7-admin' ), WPCF7_CM_VERSION, true ); 
    156 } 
    157  
    158  
    159 add_action( 'wpcf7_before_send_mail', 'wpcf7_cm_subscribe' ); 
    160  
    161 function wpcf7_cm_subscribe($obj) 
    162 { 
    163     $cf7_cm = get_option( 'cf7_cm_'.$obj->id ); 
    164     if( $cf7_cm ) 
    165     { 
    166         $subscribe = false; 
    167  
    168         $regex = '/\[\s*([a-zA-Z_][0-9a-zA-Z:._-]*)\s*\]/'; 
    169         $callback = array( &$obj, 'cf7_cm_callback' ); 
    170      
    171         $email = cf7_cm_tag_replace( $regex, $cf7_cm['email'], $obj->posted_data ); 
    172         $name = cf7_cm_tag_replace( $regex, $cf7_cm['name'], $obj->posted_data ); 
    173          
    174         $lists = cf7_cm_tag_replace( $regex, $cf7_cm['list'], $obj->posted_data ); 
    175         $listarr = explode(',',$lists); 
    176  
    177         if( isset($cf7_cm['accept']) && strlen($cf7_cm['accept']) != 0 ) 
    178         { 
    179             $accept = cf7_cm_tag_replace( $regex, $cf7_cm['accept'], $obj->posted_data ); 
    180             if($accept != $cf7_cm['accept']) 
    181             { 
    182                 if(strlen($accept) > 0) 
    183                     $subscribe = true; 
    184             } 
    185         } 
    186         else 
    187         { 
    188             $subscribe = true; 
    189         } 
    190  
    191         for($i=1;$i<=20;$i++){ 
    192          
    193             if( isset($cf7_cm['CustomKey'.$i]) && isset($cf7_cm['CustomValue'.$i]) && strlen(trim($cf7_cm['CustomValue'.$i])) != 0 ) 
    194             { 
    195                 $CustomFields[] = array('Key'=>trim($cf7_cm['CustomKey'.$i]), 'Value'=>cf7_cm_tag_replace( $regex, trim($cf7_cm['CustomValue'.$i]), $obj->posted_data ) ); 
    196             } 
    197  
    198         } 
    199          
    200          
    201         if( isset($cf7_cm['resubscribeoption']) && strlen($cf7_cm['resubscribeoption']) != 0 ) 
    202         { 
    203             $ResubscribeOption = true; 
    204         }  
    205             else 
    206         { 
    207             $ResubscribeOption = false; 
    208         } 
    209          
    210         if($subscribe && $email != $cf7_cm['email']) 
    211         { 
    212              
    213             require_once(dirname(__FILE__).DIRECTORY_SEPARATOR.'csrest_subscribers.php'); 
    214              
    215             $wrap = new CS_REST_Subscribers( trim($listarr[0]), $cf7_cm['api'] ); 
    216             foreach($listarr as $listid) 
    217             { 
    218                 $wrap->set_list_id(trim($listid)); 
    219                 $wrap->add(array( 
    220                     'EmailAddress' => $email, 
    221                     'Name' => $name, 
    222                     'CustomFields' => $CustomFields, 
    223                     'Resubscribe' => $ResubscribeOption 
    224                 )); 
    225             } 
    226              
    227         } 
    228          
    229     } 
    230 } 
    231  
    232 function cf7_cm_tag_replace( $pattern, $subject, $posted_data, $html = false ) { 
    233     if( preg_match($pattern,$subject,$matches) > 0) 
    234     { 
    235      
    236         if ( isset( $posted_data[$matches[1]] ) ) { 
    237             $submitted = $posted_data[$matches[1]]; 
    238      
    239             if ( is_array( $submitted ) ) 
    240                 $replaced = join( ', ', $submitted ); 
    241             else 
    242                 $replaced = $submitted; 
    243      
    244             if ( $html ) { 
    245                 $replaced = strip_tags( $replaced ); 
    246                 $replaced = wptexturize( $replaced ); 
    247             } 
    248      
    249             $replaced = apply_filters( 'wpcf7_mail_tag_replaced', $replaced, $submitted ); 
    250      
    251             return stripslashes( $replaced ); 
    252         } 
    253      
    254         if ( $special = apply_filters( 'wpcf7_special_mail_tags', '', $matches[1] ) ) 
    255             return $special; 
    256      
    257         return $matches[0]; 
    258     } 
    259     return $subject; 
    260 } 
    261  
    262 function wpcf7_cm_plugin_url( $path = '' ) { 
    263     return plugins_url( $path, WPCF7_CM_PLUGIN_BASENAME ); 
    264 } 
    265  
    266  
    267 add_filter( 'plugin_action_links', 'wpcf7_cm_plugin_action_links', 10, 2 ); 
    268  
    269  
    270 function wpcf7_cm_plugin_action_links( $links, $file ) { 
    271  
    272     if ( $file != plugin_basename( __FILE__ ) ) 
    273         return $links; 
    274  
    275     $url = wpcf7_admin_url( array( 'page' => 'wpcf7' ) ); 
    276  
    277     $settings_link = '<a href="' . esc_attr( $url ) . '">' . esc_html( __( 'Settings', 'wpcf7' ) ) . '</a>'; 
    278  
    279     array_unshift( $links, $settings_link ); 
    280  
    281     return $links; 
    282  
    283 } 
Note: See TracChangeset for help on using the changeset viewer.