WordPress.org

Plugin Directory

Changeset 503438


Ignore:
Timestamp:
02/11/12 00:07:47 (2 years ago)
Author:
joshuabettigole
Message:

Updated to work with CF7 v3.1

Location:
contact-form-7-campaignmonitor-addon/trunk
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • contact-form-7-campaignmonitor-addon/trunk/cf7-campaignmonitor.php

    r414018 r503438  
    66Author: Joshua Bettigole 
    77Author URI: http://www.bettigole.us 
    8 Version: 1.02 
     8Version: 1.03 
    99*/ 
    1010 
    11 /*  Copyright 2010-2011 Joshua Bettigole (email: joshua at bettigole.us) 
     11/*  Copyright 2010 Joshua Bettigole (email: joshua at bettigole.us) 
    1212 
    1313    This program is free software; you can redistribute it and/or modify 
     
    2626*/ 
    2727 
    28 define( 'WPCF7_CM_VERSION', '1.02' ); 
     28define( 'WPCF7_CM_VERSION', '1.03' ); 
    2929 
    3030if ( ! defined( 'WPCF7_CM_PLUGIN_BASENAME' ) ) 
     
    3838} 
    3939 
    40  
    41 add_action( 'wpcf7_admin_after_mail_2', 'wpcf7_cm_add_campaignmonitor' ); 
    42  
     40add_action( 'wpcf7_admin_before_subsubsub', 'add_cm_meta' ); 
     41 
     42function 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 
     53add_action( 'wpcf7_admin_after_mail_2', 'show_cm_metabox' ); 
     54 
     55function show_cm_metabox($cf){ 
     56    do_meta_boxes( 'cfseven', 'cf7_cm', $cf ); 
     57} 
     58             
    4359function wpcf7_cm_add_campaignmonitor($args) 
    4460{ 
    45     if ( wpcf7_admin_has_edit_cap() )  
    46     { 
    4761                $cf7_cm_defaults = array(); 
    4862                $cf7_cm = get_option( 'cf7_cm_'.$args->id, $cf7_cm_defaults ); 
    49                 ?> 
    50  
    51         <table class="widefat" style="margin-top: 1em;"> 
    52         <thead><tr><th scope="col" colspan="2"><?php echo esc_html( __( 'Campaign Monitor', 'wpcf7' ) ); ?> <span id="campaignmonitor-fields-toggle-switch"></span></th></tr></thead> 
    53  
    54                 <tbody> 
    55                 <tr> 
    56                     <td scope="col" colspan="2"> 
    57                     <input type="checkbox" id="wpcf7-campaignmonitor-active" name="wpcf7-campaignmonitor[active]" value="1"<?php echo ( $cf7_cm['active'] ) ? ' checked="checked"' : ''; ?> /> 
    58                     <label for="wpcf7-campaignmonitor-active"><?php echo esc_html( __( 'Use CampaignMonitor', 'wpcf7' ) ); ?></label> 
    59                     </td> 
    60                 </tr> 
    61  
    62                 <tr class="campaignmonitor-fields"> 
    63                     <td scope="col" style="width: 50%;"> 
    64                              
    65                         <div class="mail-field"> 
    66                         <label for="wpcf7-campaignmonitor-email"><?php echo esc_html( __( 'Subscriber Email:', 'wpcf7' ) ); ?></label><br /> 
    67                         <input type="text" id="wpcf7-campaignmonitor-email" name="wpcf7-campaignmonitor[email]" class="wide" size="70" value="<?php echo esc_attr( $cf7_cm['email'] ); ?>" /> 
    68                         </div> 
    69  
    70                         <div class="mail-field"> 
    71                         <label for="wpcf7-campaignmonitor-name"><?php echo esc_html( __( 'Subscriber Full Name:', 'wpcf7' ) ); ?></label><br /> 
    72                         <input type="text" id="wpcf7-campaignmonitor-name" name="wpcf7-campaignmonitor[name]" class="wide" size="70" value="<?php echo esc_attr( $cf7_cm['name'] ); ?>" /> 
    73                         </div> 
    74  
    75                         <div class="mail-field"> 
    76                         <label for="wpcf7-campaignmonitor-accept"><?php echo esc_html( __( 'Required Acceptance Field:', 'wpcf7' ) ); ?></label><br /> 
    77                         <input type="text" id="wpcf7-campaignmonitor-accept" name="wpcf7-campaignmonitor[accept]" class="wide" size="70" value="<?php echo esc_attr( $cf7_cm['accept'] ); ?>" /> 
    78                         </div> 
    79  
    80                         <div class="mail-field"><br/> 
    81                         <input type="checkbox" id="wpcf7-campaignmonitor-cf-active" name="wpcf7-campaignmonitor[cfactive]" value="1"<?php echo ( $cf7_cm['cfactive'] ) ? ' checked="checked"' : ''; ?> /> 
    82                         <label for="wpcf7-campaignmonitor-cfactive"><?php echo esc_html( __( 'Use Custom Fields', 'wpcf7' ) ); ?></label><br/><br/> 
    83                         </div> 
    84      
    85                     </td> 
    86                     <td scope="col" style="width: 50%;"> 
    87  
    88                         <div class="mail-field"> 
    89                         <label for="wpcf7-campaignmonitor-api"><?php echo esc_html( __( 'API Key:', 'wpcf7' ) ); ?></label><br /> 
    90                         <input type="text" id="wpcf7-campaignmonitor-api" name="wpcf7-campaignmonitor[api]" class="wide" size="70" value="<?php echo esc_attr( $cf7_cm['api'] ); ?>" /> 
    91                         </div> 
    92  
    93                         <div class="mail-field"> 
    94                         <label for="wpcf7-campaignmonitor-client"><?php echo esc_html( __( 'Client ID:', 'wpcf7' ) ); ?></label><br /> 
    95                         <input type="text" id="wpcf7-campaignmonitor-client" name="wpcf7-campaignmonitor[client]" class="wide" size="70" value="<?php echo esc_attr( $cf7_cm['client'] ); ?>" /> 
    96                         </div> 
    97  
    98                         <div class="mail-field"> 
    99                         <label for="wpcf7-campaignmonitor-list"><?php echo esc_html( __( 'List ID:', 'wpcf7' ) ); ?></label><br /> 
    100                         <input type="text" id="wpcf7-campaignmonitor-list" name="wpcf7-campaignmonitor[list]" class="wide" size="70" value="<?php echo esc_attr( $cf7_cm['list'] ); ?>" /> 
    101                         </div> 
    102  
    103                         <div class="mail-field"><br/> 
    104                         <input type="checkbox" id="wpcf7-campaignmonitor-resubscribeoption" name="wpcf7-campaignmonitor[resubscribeoption]" value="1"<?php echo ( $cf7_cm['resubscribeoption'] ) ? ' checked="checked"' : ''; ?> /> 
    105                         <label for="wpcf7-campaignmonitor-resubscribeoption"><?php echo esc_html( __( 'Allow Users to Resubscribe after being Deleted or Unsubscribed? (checked = true)', 'wpcf7' ) ); ?></label><br/><br/> 
    106                         </div> 
    107  
    108                     </td> 
    109                 </tr> 
    110  
    111  
    112                 <?php for($i=1;$i<=20;$i++){ ?> 
    113                 <tr class="campaignmonitor-custom-fields"> 
    114                     <td> 
    115                                 <div class="mail-field"> 
    116                                 <label for="wpcf7-campaignmonitor-CustomKey<?php echo $i; ?>"><?php echo esc_html( __( 'CustomKey'.$i.':', 'wpcf7' ) ); ?></label><br /> 
    117                                 <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] ); ?>" /> 
    118                                 </div> 
    119                     </td> 
    120                     <td> 
    121                                 <div class="mail-field"> 
    122                                 <label for="wpcf7-campaignmonitor-CustomValue<?php echo $i; ?>"><?php echo esc_html( __( 'CustomValue'.$i.':', 'wpcf7' ) ); ?></label><br /> 
    123                                 <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] ); ?>" /> 
    124                                 </div> 
    125                     </td> 
    126                 </tr> 
    127                 <?php } ?> 
    128  
    129  
    130         <div style="margin:10px; height:20px;"> 
    131             <!-- just put here for even spacing in the split cols --> 
    132         </div> 
    133              
    134             <div class="mail-field">&nbsp;</div> 
    135          
    136          
    137         </td> 
    138         </tr> 
    139         </tbody> 
    140         </table> 
     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> 
    141139 
    142140                <?php 
    143     } 
     141 
    144142} 
    145143 
     
    169167 
    170168        $regex = '/\[\s*([a-zA-Z_][0-9a-zA-Z:._-]*)\s*\]/'; 
    171         $callback = array( &$obj, 'mail_callback' ); 
    172      
    173         $email = preg_replace_callback( $regex, $callback, $cf7_cm['email'] ); 
    174         $name = preg_replace_callback( $regex, $callback, $cf7_cm['name'] ); 
    175          
    176         $lists = preg_replace_callback( $regex, $callback, $cf7_cm['list'] ); 
     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 ); 
    177175        $listarr = explode(',',$lists); 
    178          
    179         error_log('email: '.$email); 
    180         error_log('name: '.$name); 
    181176 
    182177        if( isset($cf7_cm['accept']) && strlen($cf7_cm['accept']) != 0 ) 
    183178        { 
    184             $accept = preg_replace_callback( $regex, $callback, $cf7_cm['accept'] ); 
     179            $accept = cf7_cm_tag_replace( $regex, $cf7_cm['accept'], $obj->posted_data ); 
    185180            if($accept != $cf7_cm['accept']) 
    186181            { 
     
    189184            } 
    190185        } 
    191          
    192186        else 
    193          
    194187        { 
    195188            $subscribe = true; 
    196189        } 
    197          
    198190 
    199191        for($i=1;$i<=20;$i++){ 
     
    201193            if( isset($cf7_cm['CustomKey'.$i]) && isset($cf7_cm['CustomValue'.$i]) && strlen(trim($cf7_cm['CustomValue'.$i])) != 0 ) 
    202194            { 
    203                 $CustomFields[] = array('Key'=>trim($cf7_cm['CustomKey'.$i]), 'Value'=>preg_replace_callback( $regex, $callback, trim($cf7_cm['CustomValue'.$i]) ) ); 
     195                $CustomFields[] = array('Key'=>trim($cf7_cm['CustomKey'.$i]), 'Value'=>cf7_cm_tag_replace( $regex, trim($cf7_cm['CustomValue'.$i]), $obj->posted_data ) ); 
    204196            } 
    205197 
     
    221213            require_once(dirname(__FILE__).DIRECTORY_SEPARATOR.'csrest_subscribers.php'); 
    222214             
    223             $wrap = new CF7CM_CS_REST_Subscribers( trim($listarr[0]), $cf7_cm['api'] ); 
     215            $wrap = new CS_REST_Subscribers( trim($listarr[0]), $cf7_cm['api'] ); 
    224216            foreach($listarr as $listid) 
    225217            { 
     
    238230} 
    239231 
     232function 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 
    240262function wpcf7_cm_plugin_url( $path = '' ) { 
    241263    return plugins_url( $path, WPCF7_CM_PLUGIN_BASENAME ); 
  • contact-form-7-campaignmonitor-addon/trunk/class/base_classes.php

    r413967 r503438  
    55require_once dirname(__FILE__).'/log.php'; 
    66 
    7 define('CF7CM_CS_REST_WRAPPER_VERSION', '1.0.10'); 
    8  
    9 define('CF7CM_CS_REST_WEBHOOK_FORMAT_JSON', 'json'); 
    10 define('CF7CM_CS_REST_WEBHOOK_FORMAT_XML', 'xml'); 
     7define('CS_REST_WRAPPER_VERSION', '1.0.10'); 
     8 
     9define('CS_REST_WEBHOOK_FORMAT_JSON', 'json'); 
     10define('CS_REST_WEBHOOK_FORMAT_XML', 'xml'); 
    1111 
    1212/** 
     
    1515 * 
    1616 */ 
    17 class CF7CM_CS_REST_Wrapper_Result { 
     17class CS_REST_Wrapper_Result { 
    1818    /** 
    1919     * The deserialised result of the API call 
     
    2828    var $http_status_code; 
    2929     
    30     function CF7CM_CS_REST_Wrapper_Result($response, $code) { 
     30    function CS_REST_Wrapper_Result($response, $code) { 
    3131        $this->response = $response; 
    3232        $this->http_status_code = $code; 
     
    5050 * 
    5151 */ 
    52 class CF7CM_CS_REST_Wrapper_Base { 
     52class CS_REST_Wrapper_Base { 
    5353    /** 
    5454     * The protocol to use while accessing the api 
     
    6868     * The serialiser to use for serialisation and deserialisation 
    6969     * of API request and response data 
    70      * @var CF7CM_CS_REST_JsonSerialiser or CF7CM_CS_REST_XmlSerialiser 
     70     * @var CS_REST_JsonSerialiser or CS_REST_XmlSerialiser 
    7171     * @access private 
    7272     */ 
     
    7575    /** 
    7676     * The transport to use to send API requests 
    77      * @var CF7CM_CS_REST_CurlTransport or CF7CM_CS_REST_SocketTransport or your own custom transport. 
     77     * @var CS_REST_CurlTransport or CS_REST_SocketTransport or your own custom transport. 
    7878     * @access private 
    7979     */ 
     
    8282    /** 
    8383     * The logger to use for debugging of all API requests 
    84      * @var CF7CM_CS_REST_Log 
     84     * @var CS_REST_Log 
    8585     * @access private 
    8686     */ 
     
    107107     * @param $api_key string Your api key (Ignored for get_apikey requests) 
    108108     * @param $protocol string The protocol to use for requests (http|https) 
    109      * @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 
     109     * @param $debug_level int The level of debugging required CS_REST_LOG_NONE | CS_REST_LOG_ERROR | CS_REST_LOG_WARNING | CS_REST_LOG_VERBOSE 
    110110     * @param $host string The host to send API requests to. There is no need to change this 
    111      * @param $log CF7CM_CS_REST_Log The logger to use. Used for dependency injection 
     111     * @param $log CS_REST_Log The logger to use. Used for dependency injection 
    112112     * @param $serialiser The serialiser to use. Used for dependency injection 
    113113     * @param $transport The transport to use. Used for dependency injection 
    114114     * @access public 
    115115     */ 
    116     function CF7CM_CS_REST_Wrapper_Base( 
     116    function CS_REST_Wrapper_Base( 
    117117        $api_key, 
    118118        $protocol = 'https', 
    119         $debug_level = CF7CM_CS_REST_LOG_NONE, 
     119        $debug_level = CS_REST_LOG_NONE, 
    120120        $host = 'api.createsend.com', 
    121121        $log = NULL, 
     
    123123        $transport = NULL) { 
    124124             
    125         $this->_log = is_null($log) ? new CF7CM_CS_REST_Log($debug_level) : $log; 
     125        $this->_log = is_null($log) ? new CS_REST_Log($debug_level) : $log; 
    126126             
    127127        $this->_protocol = $protocol; 
    128128        $this->_base_route = $protocol.'://'.$host.'/api/v3/'; 
    129129 
    130         $this->_log->log_message('Creating wrapper for '.$this->_base_route, get_class($this), CF7CM_CS_REST_LOG_VERBOSE); 
     130        $this->_log->log_message('Creating wrapper for '.$this->_base_route, get_class($this), CS_REST_LOG_VERBOSE); 
    131131 
    132132        $this->_transport = is_null($transport) ? 
    133             CF7CM_CS_REST_TRANSPORT_get_available($this->is_secure(), $this->_log) : 
     133            CS_REST_TRANSPORT_get_available($this->is_secure(), $this->_log) : 
    134134            $transport; 
    135135 
    136136        $transport_type = method_exists($this->_transport, 'get_type') ? $this->_transport->get_type() : 'Unknown'; 
    137         $this->_log->log_message('Using '.$transport_type.' for transport', get_class($this), CF7CM_CS_REST_LOG_WARNING); 
     137        $this->_log->log_message('Using '.$transport_type.' for transport', get_class($this), CS_REST_LOG_WARNING); 
    138138 
    139139        $this->_serialiser = is_null($serialiser) ? 
    140             CF7CM_CS_REST_SERIALISATION_get_available($this->_log) : $serialiser; 
    141              
    142         $this->_log->log_message('Using '.$this->_serialiser->get_type().' json serialising', get_class($this), CF7CM_CS_REST_LOG_WARNING); 
     140            CS_REST_SERIALISATION_get_available($this->_log) : $serialiser; 
     141             
     142        $this->_log->log_message('Using '.$this->_serialiser->get_type().' json serialising', get_class($this), CS_REST_LOG_WARNING); 
    143143 
    144144        $this->_default_call_options = array ( 
    145145            'credentials' => $api_key.':nopass', 
    146             'userAgent' => 'CF7CM_CS_REST_Wrapper v'.CF7CM_CS_REST_WRAPPER_VERSION. 
     146            'userAgent' => 'CS_REST_Wrapper v'.CS_REST_WRAPPER_VERSION. 
    147147                ' PHPv'.phpversion().' over '.$transport_type.' with '.$this->_serialiser->get_type(), 
    148148            'contentType' => 'application/json; charset=utf-8',  
     
    162162     
    163163    function put_request($route, $data, $call_options = array()) { 
    164         return $this->_call($call_options, CF7CM_CS_REST_PUT, $route, $data); 
     164        return $this->_call($call_options, CS_REST_PUT, $route, $data); 
    165165    } 
    166166     
    167167    function post_request($route, $data, $call_options = array()) { 
    168         return $this->_call($call_options, CF7CM_CS_REST_POST, $route, $data); 
     168        return $this->_call($call_options, CS_REST_POST, $route, $data); 
    169169    } 
    170170     
    171171    function delete_request($route, $call_options = array()) { 
    172         return $this->_call($call_options, CF7CM_CS_REST_DELETE, $route); 
     172        return $this->_call($call_options, CS_REST_DELETE, $route); 
    173173    } 
    174174     
    175175    function get_request($route, $call_options = array()) { 
    176         return $this->_call($call_options, CF7CM_CS_REST_GET, $route); 
     176        return $this->_call($call_options, CS_REST_GET, $route); 
    177177    } 
    178178     
     
    216216         
    217217        $call_options = array_merge($this->_default_call_options, $call_options); 
    218         $this->_log->log_message('Making '.$call_options['method'].' call to: '.$call_options['route'], get_class($this), CF7CM_CS_REST_LOG_WARNING); 
     218        $this->_log->log_message('Making '.$call_options['method'].' call to: '.$call_options['route'], get_class($this), CS_REST_LOG_WARNING); 
    219219             
    220220        $call_result = $this->_transport->make_call($call_options); 
    221221 
    222222        $this->_log->log_message('Call result: <pre>'.var_export($call_result, true).'</pre>', 
    223             get_class($this), CF7CM_CS_REST_LOG_VERBOSE); 
     223            get_class($this), CS_REST_LOG_VERBOSE); 
    224224 
    225225        if($call_options['deserialise']) { 
     
    227227        } 
    228228          
    229         return new CF7CM_CS_REST_Wrapper_Result($call_result['response'], $call_result['code']); 
     229        return new CS_REST_Wrapper_Result($call_result['response'], $call_result['code']); 
    230230    } 
    231231} 
  • contact-form-7-campaignmonitor-addon/trunk/class/log.php

    r413967 r503438  
    11<?php 
    2 define('CF7CM_CS_REST_LOG_VERBOSE', 1000); 
    3 define('CF7CM_CS_REST_LOG_WARNING', 500); 
    4 define('CF7CM_CS_REST_LOG_ERROR', 250); 
    5 define('CF7CM_CS_REST_LOG_NONE', 0); 
     2define('CS_REST_LOG_VERBOSE', 1000); 
     3define('CS_REST_LOG_WARNING', 500); 
     4define('CS_REST_LOG_ERROR', 250); 
     5define('CS_REST_LOG_NONE', 0); 
    66 
    7 class CF7CM_CS_REST_Log { 
     7class CS_REST_Log { 
    88    var $_level; 
    99 
    10     function CF7CM_CS_REST_Log($level) { 
     10    function CS_REST_Log($level) { 
    1111        $this->_level = $level; 
    1212    } 
     
    1414    function log_message($message, $module, $level) { 
    1515        if($this->_level >= $level) { 
    16             error_log($module.': '.$message); 
     16            error_log(date('G:i:s').' - '.$module.': '.$message); 
    1717        } 
    1818    } 
  • contact-form-7-campaignmonitor-addon/trunk/class/serialisation.php

    r413967 r503438  
    33require_once dirname(__FILE__).'/services_json.php'; 
    44 
    5 function CF7CM_CS_REST_SERIALISATION_get_available($log) {  
    6     $log->log_message('Getting serialiser', __FUNCTION__, CF7CM_CS_REST_LOG_VERBOSE); 
     5function CS_REST_SERIALISATION_get_available($log) {  
     6    $log->log_message('Getting serialiser', __FUNCTION__, CS_REST_LOG_VERBOSE); 
    77    if(function_exists('json_decode') && function_exists('json_encode')) { 
    8         return new CF7CM_CS_REST_NativeJsonSerialiser($log); 
     8        return new CS_REST_NativeJsonSerialiser($log); 
    99    } else { 
    10         return new CF7CM_CS_REST_ServicesJsonSerialiser($log); 
     10        return new CS_REST_ServicesJsonSerialiser($log); 
    1111    }     
    1212} 
    13 class CF7CM_CS_REST_BaseSerialiser { 
     13class CS_REST_BaseSerialiser { 
    1414 
    1515    var $_log; 
    1616     
    17     function CF7CM_CS_REST_BaseSerialiser($log) {  
     17    function CS_REST_BaseSerialiser($log) {  
    1818        $this->_log = $log; 
    1919    } 
     
    4444} 
    4545 
    46 class CF7CM_CS_REST_NativeJsonSerialiser extends CF7CM_CS_REST_BaseSerialiser { 
     46class CS_REST_NativeJsonSerialiser extends CS_REST_BaseSerialiser { 
    4747 
    48     function CF7CM_CS_REST_NativeJsonSerialiser($log) { 
    49         $this->CF7CM_CS_REST_BaseSerialiser($log); 
     48    function CS_REST_NativeJsonSerialiser($log) { 
     49        $this->CS_REST_BaseSerialiser($log); 
    5050    } 
    5151 
     
    8181} 
    8282 
    83 class CF7CM_CS_REST_ServicesJsonSerialiser extends CF7CM_CS_REST_BaseSerialiser { 
     83class CS_REST_ServicesJsonSerialiser extends CS_REST_BaseSerialiser { 
    8484     
    8585    var $_serialiser; 
    8686     
    87     function CF7CM_CS_REST_ServicesJsonSerialiser($log) { 
    88         $this->CF7CM_CS_REST_BaseSerialiser($log); 
     87    function CS_REST_ServicesJsonSerialiser($log) { 
     88        $this->CS_REST_BaseSerialiser($log); 
    8989        $this->_serialiser = new Services_JSON(); 
    9090    } 
  • contact-form-7-campaignmonitor-addon/trunk/class/services_json.php

    r413967 r503438  
    5959 * Marker constant for Services_JSON::decode(), used to flag stack state 
    6060 */ 
    61 define('CF7CM_SERVICES_JSON_SLICE',   1); 
     61define('SERVICES_JSON_SLICE',   1); 
    6262 
    6363/** 
    6464 * Marker constant for Services_JSON::decode(), used to flag stack state 
    6565 */ 
    66 define('CF7CM_SERVICES_JSON_IN_STR',  2); 
     66define('SERVICES_JSON_IN_STR',  2); 
    6767 
    6868/** 
    6969 * Marker constant for Services_JSON::decode(), used to flag stack state 
    7070 */ 
    71 define('CF7CM_SERVICES_JSON_IN_ARR',  3); 
     71define('SERVICES_JSON_IN_ARR',  3); 
    7272 
    7373/** 
    7474 * Marker constant for Services_JSON::decode(), used to flag stack state 
    7575 */ 
    76 define('CF7CM_SERVICES_JSON_IN_OBJ',  4); 
     76define('SERVICES_JSON_IN_OBJ',  4); 
    7777 
    7878/** 
    7979 * Marker constant for Services_JSON::decode(), used to flag stack state 
    8080 */ 
    81 define('CF7CM_SERVICES_JSON_IN_CMT', 5); 
     81define('SERVICES_JSON_IN_CMT', 5); 
    8282 
    8383/** 
    8484 * Behavior switch for Services_JSON::decode() 
    8585 */ 
    86 define('CF7CM_SERVICES_JSON_LOOSE_TYPE', 16); 
     86define('SERVICES_JSON_LOOSE_TYPE', 16); 
    8787 
    8888/** 
    8989 * Behavior switch for Services_JSON::decode() 
    9090 */ 
    91 define('CF7CM_SERVICES_JSON_SUPPRESS_ERRORS', 32); 
     91define('SERVICES_JSON_SUPPRESS_ERRORS', 32); 
    9292 
    9393/** 
     
    112112 * </code> 
    113113 */ 
    114 class CF7CM_Services_JSON 
     114class Services_JSON 
    115115{ 
    116116   /** 
     
    130130    *                                   from encode() should be checked with isError() 
    131131    */ 
    132     function CF7CM_Services_JSON($use = 0) 
     132    function Services_JSON($use = 0) 
    133133    { 
    134134        $this->use = $use; 
     
    771771} 
    772772 
    773 class CF7CM_Services_JSON_Error 
     773class Services_JSON_Error 
    774774{ 
    775     function CF7CM_Services_JSON_Error($message = 'unknown error', $code = null, 
     775    function Services_JSON_Error($message = 'unknown error', $code = null, 
    776776                                 $mode = null, $options = null, $userinfo = null) 
    777777    { 
     
    779779    } 
    780780} 
    781      
    782 ?> 
  • contact-form-7-campaignmonitor-addon/trunk/class/transport.php

    r413967 r503438  
    11<?php 
    22 
    3 define('CF7CM_CS_REST_GET', 'GET'); 
    4 define('CF7CM_CS_REST_POST', 'POST'); 
    5 define('CF7CM_CS_REST_PUT', 'PUT'); 
    6 define('CF7CM_CS_REST_DELETE', 'DELETE'); 
    7 define('CF7CM_CS_REST_SOCKET_TIMEOUT', 1); 
    8  
    9 function CF7CM_CS_REST_TRANSPORT_get_available($requires_ssl, $log) { 
     3define('CS_REST_GET', 'GET'); 
     4define('CS_REST_POST', 'POST'); 
     5define('CS_REST_PUT', 'PUT'); 
     6define('CS_REST_DELETE', 'DELETE'); 
     7define('CS_REST_SOCKET_TIMEOUT', 1); 
     8 
     9function CS_REST_TRANSPORT_get_available($requires_ssl, $log) { 
    1010    if(function_exists('curl_init') && function_exists('curl_exec')) { 
    11         return new CF7CM_CS_REST_CurlTransport($log); 
    12     } else if(CF7CM_CS_REST_TRANSPORT_can_use_raw_socket($requires_ssl)) { 
    13         return new CF7CM_CS_REST_SocketTransport($log); 
     11        return new CS_REST_CurlTransport($log); 
     12    } else if(CS_REST_TRANSPORT_can_use_raw_socket($requires_ssl)) { 
     13        return new CS_REST_SocketTransport($log); 
    1414    } else {  
    15         $log->log_message('No transport is available', __FUNCTION__, CF7CM_CS_REST_LOG_ERROR); 
     15        $log->log_message('No transport is available', __FUNCTION__, CS_REST_LOG_ERROR); 
    1616        trigger_error('No transport is available.'. 
    1717            ($requires_ssl ? ' Try using non-secure (http) mode or ' : ' Please '). 
     
    1919    }     
    2020} 
    21 function CF7CM_CS_REST_TRANSPORT_can_use_raw_socket($requires_ssl) { 
     21function CS_REST_TRANSPORT_can_use_raw_socket($requires_ssl) { 
    2222    if(function_exists('fsockopen')) { 
    2323        if($requires_ssl) { 
     
    3030    return false; 
    3131}    
    32 class CF7CM_CS_REST_BaseTransport { 
     32class CS_REST_BaseTransport { 
    3333     
    3434    var $_log; 
    3535     
    36     function CF7CM_CS_REST_BaseTransport($log) { 
     36    function CS_REST_BaseTransport($log) { 
    3737        $this->_log = $log; 
    3838    } 
     
    4545     
    4646            $this->_log->log_message('Inflated gzipped response: '.$original_length.' bytes ->'. 
    47                 strlen($result).' bytes', get_class(), CF7CM_CS_REST_LOG_VERBOSE); 
     47                strlen($result).' bytes', get_class(), CS_REST_LOG_VERBOSE); 
    4848        } 
    4949         
     
    5757 * @since 1.0 
    5858 */ 
    59 class CF7CM_CS_REST_CurlTransport extends CF7CM_CS_REST_BaseTransport { 
     59class CS_REST_CurlTransport extends CS_REST_BaseTransport { 
    6060 
    6161    var $_curl_zlib; 
    6262 
    63     function CF7CM_CS_REST_CurlTransport($log) { 
    64         $this->CF7CM_CS_REST_BaseTransport($log); 
     63    function CS_REST_CurlTransport($log) { 
     64        $this->CS_REST_BaseTransport($log); 
    6565         
    6666        $curl_version = curl_version(); 
     
    9090        if($this->_curl_zlib) { 
    9191            $this->_log->log_message('curl+zlib support available. Requesting gzipped response.', 
    92                 get_class($this), CF7CM_CS_REST_LOG_VERBOSE); 
     92                get_class($this), CS_REST_LOG_VERBOSE); 
    9393            curl_setopt($ch, CURLOPT_ENCODING, 'gzip'); 
    9494        } else if(function_exists('gzinflate')) { 
     
    104104 
    105105        switch($call_options['method']) { 
    106             case CF7CM_CS_REST_PUT: 
    107                 curl_setopt($ch, CURLOPT_CUSTOMREQUEST, CF7CM_CS_REST_PUT); 
     106            case CS_REST_PUT: 
     107                curl_setopt($ch, CURLOPT_CUSTOMREQUEST, CS_REST_PUT); 
    108108                $headers[] = 'Content-Length: '.strlen($call_options['data']); 
    109109                curl_setopt($ch, CURLOPT_POSTFIELDS, $call_options['data']); 
    110110                break; 
    111             case CF7CM_CS_REST_POST: 
     111            case CS_REST_POST: 
    112112                curl_setopt($ch, CURLOPT_POST, true); 
    113113                curl_setopt($ch, CURLOPT_POSTFIELDS, $call_options['data']); 
    114114                break; 
    115             case CF7CM_CS_REST_DELETE: 
    116                 curl_setopt($ch, CURLOPT_CUSTOMREQUEST, CF7CM_CS_REST_DELETE); 
     115            case CS_REST_DELETE: 
     116                curl_setopt($ch, CURLOPT_CUSTOMREQUEST, CS_REST_DELETE); 
    117117                break; 
    118118        } 
     
    125125        if(!$response && $response !== '') { 
    126126            $this->_log->log_message('Error making request with curl_error: '.curl_errno($ch), 
    127                 get_class($this), CF7CM_CS_REST_LOG_ERROR); 
     127                get_class($this), CS_REST_LOG_ERROR); 
    128128            trigger_error('Error making request with curl_error: '.curl_error($ch), E_USER_ERROR); 
    129129        } 
     
    135135            ' bytes uploaded. '.curl_getinfo($ch, CURLINFO_SIZE_DOWNLOAD).' bytes downloaded'. 
    136136            ' Total time (seconds): '.curl_getinfo($ch, CURLINFO_TOTAL_TIME),  
    137         get_class($this), CF7CM_CS_REST_LOG_VERBOSE); 
     137        get_class($this), CS_REST_LOG_VERBOSE); 
    138138 
    139139        $result = array( 
     
    148148} 
    149149 
    150 class CF7CM_CS_REST_SocketWrapper { 
     150class CS_REST_SocketWrapper { 
    151151    var $socket; 
    152152 
    153153    function open($domain, $port) { 
    154         $this->socket = fsockopen($domain, $port, $errno, $errstr, CF7CM_CS_REST_SOCKET_TIMEOUT); 
     154        $this->socket = fsockopen($domain, $port, $errno, $errstr, CS_REST_SOCKET_TIMEOUT); 
    155155 
    156156        if(!$this->socket) { 
     
    158158            return false; 
    159159        } else if(function_exists('stream_set_timeout')) { 
    160             stream_set_timeout($this->socket, CF7CM_CS_REST_SOCKET_TIMEOUT); 
     160            stream_set_timeout($this->socket, CS_REST_SOCKET_TIMEOUT); 
    161161        } 
    162162 
     
    180180} 
    181181 
    182 class CF7CM_CS_REST_SocketTransport extends CF7CM_CS_REST_BaseTransport { 
     182class CS_REST_SocketTransport extends CS_REST_BaseTransport { 
    183183 
    184184    var $_socket_wrapper; 
    185185 
    186     function CF7CM_CS_REST_SocketTransport($log, $socket_wrapper = NULL) { 
    187         $this->CF7CM_CS_REST_BaseTransport($log); 
     186    function CS_REST_SocketTransport($log, $socket_wrapper = NULL) { 
     187        $this->CS_REST_BaseTransport($log); 
    188188 
    189189        if(is_null($socket_wrapper)) { 
    190             $socket_wrapper = new CF7CM_CS_REST_SocketWrapper(); 
     190            $socket_wrapper = new CS_REST_SocketWrapper(); 
    191191        } 
    192192 
     
    212212 
    213213        $this->_log->log_message('Creating socket to '.$domain.' over '.$protocol.' for request to '.$path, 
    214             get_class($this), CF7CM_CS_REST_LOG_VERBOSE); 
     214            get_class($this), CS_REST_LOG_VERBOSE); 
    215215 
    216216        if($protocol === 'https://') { 
     
    224224            $request = $this->_build_request($call_options, $host, $path, $inflate_response); 
    225225            $this->_log->log_message('Sending <pre>'.$request.'</pre> down the socket', 
    226             get_class($this), CF7CM_CS_REST_LOG_VERBOSE); 
     226            get_class($this), CS_REST_LOG_VERBOSE); 
    227227              
    228228            $this->_socket_wrapper->write($request); 
     
    233233            $call_options['route'].': '.strlen($request). 
    234234                ' bytes uploaded. '.strlen($response).' bytes downloaded',  
    235             get_class($this), CF7CM_CS_REST_LOG_VERBOSE); 
     235            get_class($this), CS_REST_LOG_VERBOSE); 
    236236                 
    237237            list( $headers, $result ) = $this->split_and_inflate($response, $inflate_response); 
    238238                 
    239239            $this->_log->log_message('Received headers <pre>'.$headers.'</pre>', 
    240                 get_class($this), CF7CM_CS_REST_LOG_VERBOSE); 
     240                get_class($this), CS_REST_LOG_VERBOSE); 
    241241                 
    242242            return array( 
     
    250250        if (preg_match('%^\s*HTTP/1\.1 (?P<code>\d{3})%', $headers, $regs)) { 
    251251            $this->_log->log_message('Got HTTP Status Code: '.$regs['code'], 
    252             get_class($this), CF7CM_CS_REST_LOG_VERBOSE); 
     252            get_class($this), CS_REST_LOG_VERBOSE); 
    253253            return $regs['code']; 
    254254        } 
    255255 
    256256        $this->_log->log_message('Failed to get HTTP status code from request headers <pre>'.$headers.'</pre>', 
    257             get_class($this), CF7CM_CS_REST_LOG_ERROR); 
     257            get_class($this), CS_REST_LOG_ERROR); 
    258258        trigger_error('Failed to get HTTP status code from request', E_USER_ERROR);         
    259259    } 
  • contact-form-7-campaignmonitor-addon/trunk/csrest_subscribers.php

    r415090 r503438  
    11<?php 
    2 require_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  */ 
    11 class 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  
    207 } 
     2/* 
     3Plugin Name: Contact Form 7 - Campaign Monitor Addon 
     4Plugin URI: http://www.bettigole.us/published-work/wordpress-contributions/campaign-monitor-addon-for-contact-form-7/ 
     5Description: Add the power of CampaignMonitor to Contact Form 7 
     6Author: Joshua Bettigole 
     7Author URI: http://www.bettigole.us 
     8Version: 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 
     28define( 'WPCF7_CM_VERSION', '1.03' ); 
     29 
     30if ( ! defined( 'WPCF7_CM_PLUGIN_BASENAME' ) ) 
     31    define( 'WPCF7_CM_PLUGIN_BASENAME', plugin_basename( __FILE__ ) ); 
     32 
     33add_action( 'wpcf7_after_save', 'wpcf7_cm_save_campaignmonitor' ); 
     34 
     35function wpcf7_cm_save_campaignmonitor($args) 
     36{ 
     37    update_option( 'cf7_cm_'.$args->id, $_POST['wpcf7-campaignmonitor'] ); 
     38} 
     39 
     40add_action( 'wpcf7_admin_before_subsubsub', 'add_cm_meta' ); 
     41 
     42function 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 
     53add_action( 'wpcf7_admin_after_mail_2', 'show_cm_metabox' ); 
     54 
     55function show_cm_metabox($cf){ 
     56    do_meta_boxes( 'cfseven', 'cf7_cm', $cf ); 
     57} 
     58             
     59function 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 
     145add_action( 'admin_print_scripts', 'wpcf7_cm_admin_enqueue_scripts' ); 
     146 
     147function 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 
     159add_action( 'wpcf7_before_send_mail', 'wpcf7_cm_subscribe' ); 
     160 
     161function 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 
     232function 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 
     262function wpcf7_cm_plugin_url( $path = '' ) { 
     263    return plugins_url( $path, WPCF7_CM_PLUGIN_BASENAME ); 
     264} 
     265 
     266 
     267add_filter( 'plugin_action_links', 'wpcf7_cm_plugin_action_links', 10, 2 ); 
     268 
     269 
     270function 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/readme.txt

    r413976 r503438  
    33Donate link: http://www.bettigole.us/donate/ 
    44Tags: Campaign Monitor, Contact Form 7, Newsletter, Opt In, Email Marketing 
    5 Requires at least: 2.9 
    6 Tested up to: 3.2.1 
    7 Stable tag: 1.02 
     5Requires at least: 3.2 
     6Tested up to: 3.3.1 
     7Stable tag: 1.04 
     8 
     9> 
     10> **This plugin requires Contact Form 7, version 3.1** 
     11> 
     12- - - 
    813 
    914Add the capability to create newsletter opt-in forms with Contact Form 7. Automatically submit subscribers to predetermined lists in Campaign Monitor. 
     
    1318The Contact Form 7 - Campaign Monitor Addon plugin adds functionality into Contact Form 7 generated forms to automatically submit subscribers to a predetermined list within a Campaign Monitor client account. The plugin settings are configured on a per-form basis on the Contact Form 7 configuration pages. 
    1419 
     20> 
     21> If you like this plugin, consider [donating](http://www.bettigole.us/donate/) to help me offset the time spent working on it. In return, I promise not to bother you with nag dialogs on your Wordpress admin pages! 
     22> 
     23 
    1524### Requirements 
    1625 
    1726#### WordPress 
    18 This plugin was built and tested on WordPress version 3.2.1 It should work with version 2.9, but this configuration is untested. Earlier versions are not supported by Contact Form 7, therefore, can not be supported by this plugin. 
     27This plugin was built and tested on WordPress version 3.3.1 It should work with version 3.2, but this configuration is untested. Earlier versions are not supported by Contact Form 7, therefore, can not be supported by this plugin. 
    1928 
    2029#### Contact Form 7 
     
    5766There is no settings page specifically for this plugin. Configuration occurs within the Contact Form 7 form administration pages. Each form gets its own configuration. 
    5867 
     68= This plugin doesn't appear to have been updated in a while = 
     69 
     70Simply put, it doesn't need to. Very little of this plugin relies on Wordpress core functionality, and Campaign Monitor doesn't change their API all that often, so unless something is completely broken, updating it every other week isn't necessary. 
    5971 
    6072== Screenshots == 
     
    6577== Changelog == 
    6678 
     79= 1.04 = 
     80- Fixed issues related to the Contact Form 7, v3.1 update which prevented submitting data to Campaign Monitor. 
     81- Updated admin config to use a repositionable meta box  
     82 
    6783= 1.02 = 
    68 Fixed incompatibility issue when installed along with other Campaign Monitor plugins 
     84- Fixed incompatibility issue when installed along with other Campaign Monitor plugins 
    6985 
    7086= 1.00 = 
    71 Added custom field handling (Courtesy of Josh Middleton). Added multiple list capability. Updated to latest Campaign Monitor API 
     87- Added custom field handling (Courtesy of Josh Middleton). Added multiple list capability. Updated to latest Campaign Monitor API 
    7288 
    7389= 0.99 = 
    74 First Release 
     90- First Release 
    7591 
    7692== ToDo == 
  • contact-form-7-campaignmonitor-addon/trunk/scripts.js

    r410847 r503438  
    33 
    44        if (! jQuery('#wpcf7-campaignmonitor-active').is(':checked')) 
    5             jQuery('.campaignmonitor-fields, .campaignmonitor-custom-fields').hide(); 
     5            jQuery('#cf7cmdiv .mail-fields').hide(); 
    66 
    77        jQuery('#wpcf7-campaignmonitor-active').click(function() { 
    8             if (jQuery('.campaignmonitor-fields').is(':hidden') 
     8            if (jQuery('#cf7cmdiv .mail-fields').is(':hidden') 
    99            && jQuery('#wpcf7-campaignmonitor-active').is(':checked')) { 
    10                 jQuery('.campaignmonitor-fields').slideDown('fast'); 
     10                jQuery('#cf7cmdiv .mail-fields').slideDown('fast'); 
    1111                if (jQuery('.campaignmonitor-custom-fields').is(':hidden') 
    1212                && jQuery('#wpcf7-campaignmonitor-cf-active').is(':checked')) { 
    1313                    jQuery('.campaignmonitor-custom-fields').slideDown('fast'); 
    1414                } 
    15             } else if (jQuery('.campaignmonitor-fields').is(':visible') 
     15            } else if (jQuery('#cf7cmdiv .mail-fields').is(':visible') 
    1616            && jQuery('#wpcf7-campaignmonitor-active').not(':checked')) { 
    17                 jQuery('.campaignmonitor-fields, .campaignmonitor-custom-fields').slideUp('fast'); 
     17                jQuery('#cf7cmdiv .mail-fields').slideUp('fast'); 
    1818            } 
    1919        }); 
Note: See TracChangeset for help on using the changeset viewer.