Example #1
0
 function inject_coupon($button_code, $code, $pack_id)
 {
     if ($code != $this->code) {
         return $button_code;
     } else {
         $ym_custom_fields = ym_get_custom_field_array(ym_get_user_id());
         $coupon = isset($ym_custom_fields['coupon']) ? $ym_custom_fields['coupon'] : '';
         $button_code['coupon'] = '';
         if ($coupon) {
             if ($id = ym_get_coupon_id_by_name($coupon)) {
                 $button_code['coupon'] = 'ym_' . $id;
             }
         }
         return $button_code;
     }
 }
function ym_export_users($offset = 0, $limit = 300, $package_type = null, $package = NULL, $active = null)
{
    global $wpdb, $duration_str;
    if (!$package_type) {
        $package_type = 'all';
    }
    $user_list = array();
    $path = trailingslashit(ym_post('backup_temp_path'));
    global $ym_sys;
    $ym_sys->update(array('export_last_tmp_path' => $path));
    $format = ym_post('bkformat', 'xls');
    $all_users = get_users(array('exclude' => array(1), 'offset' => $offset, 'number' => $limit));
    foreach ($all_users as $user) {
        $user = (array) $user;
        $ym_user = new YourMember_User($user['ID']);
        // build rest of object
        /*$user_data = (array)$user_data;
        
        		unset($user_data['spawn']);
        		unset($user_data['data']);
        		unset($user_data['userId']);
        		unset($user_data['custom_fields']);*/
        $user_data = array();
        $user_data['ID'] = $ym_user->ID;
        $user_data['username'] = $ym_user->data->user_login;
        $user_data['email'] = $ym_user->data->user_email;
        $user_data['registered'] = date(YM_DATE, strtotime($ym_user->data->user_registered) + get_option('gmt_offset') * 3600);
        //date(YM_DATE, $ym_display_a_user->expire_date)
        $user_data['last_pay_date'] = date(YM_DATE, $ym_user->last_pay_date + get_option('gmt_offset') * 3600);
        $user_data['expire_date'] = date(YM_DATE, $ym_user->expire_date + get_option('gmt_offset') * 3600);
        $user_data['package_join_date'] = date(YM_DATE, $ym_user->account_type_join_date + get_option('gmt_offset') * 3600);
        $user_data['role'] = $ym_user->role;
        $user_data['status'] = $ym_user->status;
        //PAckages data
        $user_data['package_type'] = $ym_user->account_type;
        $user_data['package_id'] = $ym_user->pack_id;
        //$user = array_merge($user, $user_data);
        if ($customs = ym_get_custom_field_array($ym_user->ID)) {
            //			$user = array_merge($user, $customs);
            // as apposed to merge the other way
            // I want field order....
            // saves doing merge($user, $custom, $merge);
            foreach ($customs as $i => $d) {
                // don't overwrite....
                $user_data[$i] = isset($user_data[$i]) ? $user_data[$i] : $d;
            }
        }
        if (($package_type == 'all' || strtolower($package_type) == strtolower($user_data['package_type'])) && ($package == 'all' || $package == $user_data['package_id'])) {
            $status = $user_data['status'];
            if ($status == YM_STATUS_ACTIVE || $active) {
                $user_list[] = $user_data;
            }
        }
    }
    $chunk = ym_export_users_do_chunk($path, $user_list, $format);
    if ($chunk) {
        // check for more data needed
        if (count($user_list) == $limit) {
            // more needed
            echo '<p>Loading Next Chunk ' . $offset . '</p>';
            ym_export_users_operation_form($path, $offset + $limit);
        } else {
            // lets send the file
            ym_export_users_operation_send($path, $format);
            // complete or did last batch
            echo '<p>Complete</p>';
        }
    } else {
        echo 'Could not Open Temproary File';
    }
}
Example #3
0
 function sync_with_gateway()
 {
     global $wpdb;
     if ($_GET['mm_action']) {
         if (!strpos($_SERVER['SERVER_SOFTWARE'], 'Debian')) {
             ob_end_flush();
             // echo as we go
             ob_implicit_flush(true);
         }
         echo '<pre>';
         echo 'Syncing with Gateway' . "\n";
     }
     if ($_GET['mm_action']) {
         echo 'Syncing YM Custom Fields with MailChimp Merge Vars' . "\n";
     }
     $local_fields = $live_fields = $fields_to_add = array();
     $fields = get_option('ym_custom_fields');
     $order = explode(';', $fields->order);
     $words = $custom_field_data = array();
     foreach ($order as $index) {
         $field = ym_get_custom_field_by_id($index);
         if ($field['name'] != 'subscription_introduction' && $field['name'] != 'subscription_options' && strlen($field['name']) <= 10 && $field['name'] != 'first_name' && $field['name'] != 'last_name' && $field['name'] != 'user_email' && $field['name'] != 'ym_password' && $field['name'] != 'user_url') {
             $word = strtoupper($field['name']);
             $local_fields[] = $word;
             $words[$word] = $field['name'];
             if ($field['name'] == 'birthdate') {
                 $field['type'] = 'birthday';
             }
             $custom_field_data[$word] = $field;
         }
     }
     $live_fieldsd = $this->mailchimp->listMergeVars($this->options->list);
     if ($live_fieldsd->error) {
         echo 'An Error Occured';
         return;
     }
     // process
     foreach ($live_fieldsd as $field) {
         $live_fields[] = $field->tag;
     }
     $fields_to_add = array_diff($local_fields, $live_fields);
     foreach ($fields_to_add as $field) {
         switch ($custom_field_data[$field]['type']) {
             case 'birthday':
                 $type = 'birthday';
                 break;
             case 'text':
             default:
                 $type = 'text';
         }
         $r = $this->mailchimp->listMergeVarAdd($this->options->list, $field, $words[$field], array('field_type' => $type));
         if ($_GET['mm_action']) {
             echo 'Result for: ' . $field . ' - ' . $r . "\n";
         }
     }
     if ($_GET['mm_action']) {
         echo 'Syncing All Users to list' . "\n";
     }
     $all_local_users = $all_live_users_subscribed = $all_live_users_unsubscribed = array();
     $list = 'wordpress_users';
     $subd = $this->mailchimp->listMembers($this->options->list, 'subscribed', FALSE, FALSE, 15000);
     $unsubd = $this->mailchimp->listMembers($this->options->list, 'unsubscribed', FALSE, FALSE, 15000);
     if ($subd->error || $unsubd->error) {
         // error
         echo 'An Error Occured';
         return;
     }
     foreach ($subd->data as $user) {
         $all_live_users_subscribed[] = $user->email;
     }
     foreach ($unsubd->data as $user) {
         $all_live_users_unsubscribed[] = $user->email;
     }
     foreach ($wpdb->get_results(mailmanager_get_sql($list)) as $row) {
         $all_local_users[] = strtolower($row->email);
     }
     if ($_GET['mm_action']) {
         echo 'There are locally: ' . sizeof($all_local_users) . "\n";
         echo 'There are live: ' . sizeof($all_live_users_subscribed) . " Subscribed\n";
         echo 'There are live: ' . sizeof($all_live_users_unsubscribed) . " Unsubcribed\n";
     }
     // sync delete
     // umsubed
     // clean all in order to handle resubscribe.....
     $sql = 'DELETE FROM ' . $wpdb->prefix . 'mm_list_unsubscribe WHERE list_name = \'' . $this->options->list . '\'';
     $wpdb->query($sql);
     foreach ($all_live_users_unsubscribed as $user_email) {
         $user_id = get_user_by_email($user_email);
         $user_id = $user_id->ID;
         // log unsub
         mailmanager_unsubscribe_user($this->options->list, $user_id);
     }
     $users_to_add = array_diff($all_local_users, $all_live_users_subscribed, $all_live_users_unsubscribed);
     if ($_GET['mm_action']) {
         echo 'There are ' . sizeof($users_to_add) . ' Users to add' . "\n";
     }
     include YM_MM_INCLUDES_DIR . 'countries.inc.php';
     foreach ($users_to_add as $user_email) {
         $data = get_user_by_email($user_email);
         $merge = array();
         $merge = array('FNAME' => $data->first_name, 'LNAME' => $data->last_name);
         $fields = ym_get_custom_field_array($data->ID);
         foreach ((array) $fields as $field => $value) {
             $merge[strtoupper(str_replace(' ', '_', $field))] = $value;
         }
         if ($merge['COUNTRY']) {
             $merge['COUNTRY'] = $countries[$merge['COUNTRY']];
         }
         if (isset($merge['BIRTHDATE']) && $merge['BIRTHDATE']) {
             $merge['BIRTHDATE'] = explode('-', $merge['BIRTHDATE']);
             // m d y
             //				$merge['BIRTHDATE'] = $merge['BIRTHDATE'][2] . '-' . $merge['BIRTHDATE'][0] . '-' . $merge['BIRTHDATE'][1];
             $merge['BIRTHDATE'] = $merge['BIRTHDATE'][0] . '/' . $merge['BIRTHDATE'][1];
         }
         if ($_GET['mm_action']) {
             echo 'Adding ' . $user_email . "\n";
         }
         $this->mailchimp->listSubscribe($this->options->list, $user_email, $merge, $this->options->double_opt_in, $this->options->welcome_message);
     }
     // for exitinst subscribed update fields
     if ($_GET['mm_action']) {
         echo 'Updating existing users' . "\n";
     }
     $counter = 0;
     foreach ($all_live_users_subscribed as $index => $user_email) {
         $data = get_user_by_email($user_email);
         $merge = array();
         $merge = array('FNAME' => $data->first_name, 'LNAME' => $data->last_name);
         $fields = ym_get_custom_field_array($data->ID);
         foreach ((array) $fields as $field => $value) {
             $merge[strtoupper($field)] = $value;
         }
         if (isset($merge['COUNTRY'])) {
             $merge['COUNTRY'] = $countries[$merge['COUNTRY']];
         }
         if (isset($merge['BIRTHDATE']) && $merge['BIRTHDATE']) {
             $merge['BIRTHDATE'] = explode('-', $merge['BIRTHDATE']);
             // m d y
             //				$merge['BIRTHDATE'] = $merge['BIRTHDATE'][2] . '-' . $merge['BIRTHDATE'][0] . '-' . $merge['BIRTHDATE'][1];
             $merge['BIRTHDATE'] = $merge['BIRTHDATE'][0] . '/' . $merge['BIRTHDATE'][1];
         }
         echo $this->mailchimp->listUpdateMember($this->options->list, $user_email, $merge);
         $counter++;
         if ($counter >= 20) {
             $counter = 0;
             echo ' ' . ($index + 1) . '/' . count($all_live_users_subscribed);
             echo "\n";
         }
     }
     echo "\n";
     // hadnle lists and segments
     if ($_GET['mm_action']) {
         echo 'General Sync Complete - Moving on to YM MM List/Segmentation' . "\n";
     }
     // what segments exists
     // if list associations are to a segment.....
     // validate segemetns
     // in case deleted server side
     // server side
     $segments = $this->mailchimp->listSegments($this->options->list);
     $this->associations = new StdClass();
     foreach ($segments as $segment) {
         $name = $segment->name;
         $this->associations->{$name} = $segment->id;
     }
     $this->saveassociations();
     // any segments left to make?
     foreach (mailmanager_get_recipients() as $nice_key => $word_name) {
         $assoc = $this->associations->{$nice_key};
         if (!$assoc) {
             if ($_GET['mm_action']) {
                 echo 'Creating Segment: ' . $nice_key . "\n";
             }
             // the ym list needs a segment
             if ($id = $this->mailchimp->listStaticSegmentAdd($this->options->list, $nice_key)) {
                 $this->associations->{$nice_key} = $id;
                 $assoc = $id;
                 // just to be safe in case of crash
                 $this->saveassociations();
             } else {
                 if ($_GET['mm_action']) {
                     echo 'There was an error, creating a list segment' . "\n";
                 }
                 return;
             }
             // ought to error catch.....
         }
     }
     // just in case
     $this->saveassociations();
     $emails = array();
     foreach ($this->associations as $nice_key => $word_name) {
         foreach ($wpdb->get_results(mailmanager_get_sql($nice_key)) as $row) {
             if ($row->email) {
                 $emails[$row->email][] = $this->associations->{$nice_key};
             }
         }
     }
     // member iterate
     $subd = $this->mailchimp->listMembers($this->options->list, 'subscribed', FALSE, FALSE, 15000);
     $counter = 0;
     foreach ($subd->data as $index => $user) {
         $email = $user->email;
         // ping
         // should generally do nothing
         // but in case admin switch the level
         // or the ipn was missed
         // do this first to stop multiple existings
         $user_data = get_user_by_email($email);
         if ($user_data) {
             $this->change_user_list(array('user_id' => $user_data->ID));
         }
         // obeslete below now?
         $data = $this->mailchimp->listMemberInfo($this->options->list, $email);
         $segments = array();
         foreach ((array) $data->data[0]->static_segments as $segment) {
             $segments[] = $segment->id;
         }
         $diff = array_diff((array) $emails[$email], $segments);
         // add or remove a user from a segment
         foreach ($diff as $item) {
             $r = $this->mailchimp->listStaticSegmentMembersAdd($this->options->list, $item, array($email));
             if ($_GET['mm_action']) {
                 echo 'a';
                 //					echo 'Adding ' . $email . ' to ' . $item . "\n";
                 if ($r->success) {
                     echo $r->success;
                 } else {
                     echo $r->error;
                 }
             }
         }
         $counter++;
         if ($counter >= 20) {
             $counter = 0;
             echo ' ' . ($index + 1) . '/' . count($subd->data);
             echo "\n";
         }
     }
     // complete
     if ($_GET['mm_action']) {
         echo 'Segmentation Complete' . "\n";
         echo 'WebHook check' . "\n";
     }
     $url = site_url() . '/?mm_webhook=1';
     if (FALSE === stripos($url, 'localhost')) {
         $hooks = $this->mailchimp->listWebHooks($this->options->list);
         $found = FALSE;
         foreach ($hooks as $hook) {
             if ($hook->url == $url) {
                 $found = TRUE;
             }
         }
         if (!$found) {
             // can't handle upemail properly
             $this->mailchimp->listWebhookAdd($this->options->list, $url, '11111');
         }
     } else {
         if ($_GET['mm_action']) {
             echo 'On Localhost' . "\n";
         }
     }
     if ($_GET['mm_action']) {
         echo 'Checking for abuse/spam reports' . "\n";
     }
     // cron job, runs daily....
     // so get the last day only
     $reports = $this->mailchimp->listAbuseReports($this->options->list, 0, 1000, time() - 86400);
     if ($reports->total) {
         foreach ($reports->data as $report) {
             $email = $report['email'];
             $user = get_user_by_email($email);
             $user_id = $user->ID;
             @ym_log_transaction(YM_USER_STATUS_UPDATE, 'Inactive', $user_id);
             update_user_option($user_id, 'ym_status', 'Inactive', true);
             if ($_GET['mm_action']) {
                 echo $email . ' reported spam removing/inactivising' . "\n";
             }
         }
     }
     if ($_GET['mm_action']) {
         echo 'All Done' . "\n";
         echo '</pre>';
         if (!strpos($_SERVER['SERVER_SOFTWARE'], 'Debian')) {
             ob_flush();
             // restart wordpress ob
             ob_start();
         }
     }
 }
/**
Non Flow Register/Upgrade
*/
function ym_available_modules($username = false, $return = false, $coupon_type = 0)
{
    //	echo 'ym_available_modules: ' . $username . ', ' . $return . ', ' . $coupon_type . '<br />';
    global $ym_active_modules, $ym_packs;
    //coupons
    $user_id = ym_get_user_id();
    $ym_custom_fields = ym_get_custom_field_array($user_id);
    $ym_home = site_url();
    $base = $ym_home . '/index.php?ym_subscribe=1&username='******'';
    if ($pack_id = ym_get('pack_id')) {
        // pack ID has been selected
        $pack = ym_get_pack_by_id($pack_id);
        // strip commas
        $cost = str_replace(',', '', $pack['cost']);
        $override = FALSE;
        $code_to_use = 'custom';
        // coupon check
        if (isset($ym_custom_fields['coupon']) && $ym_custom_fields['coupon']) {
            $cost = ym_apply_coupon($ym_custom_fields['coupon'], $coupon_type, $cost);
            if (substr($cost, 0, 4) == 'pack') {
                $pack_id = substr($cost, 5);
                // apply new pack
                $pack = ym_get_pack($pack_id);
                // import data
                $cost = $pack['cost'];
                $duration = $pack['duration'];
                $duration_type = $pack['duration_type'];
                $account_type = $pack['account_type'];
                $num_cycles = $pack['num_cycles'];
            } else {
                // makre sure formatted ok
                $cost = number_format($cost, 2);
                $override = $cost;
                $code_to_use = 'freebie_code';
            }
            ym_register_coupon_use($ym_custom_fields['coupon'], ym_get_user_id(), 'buy_subscription_' . $pack_id);
        }
        // is it free?
        if ($cost == 0) {
            // auto redirect
            $redirector = ym_get('redirector');
            // attempt to redirect to the processor.
            // if attempt fails, we show the button
            $loc = $ym_home . '/index.php?ym_process=ym_free&' . (ym_get('ym_autologin') ? 'ym_autologin=1&' : '') . $code_to_use . '=buy_subscription_' . $pack['id'] . '_' . ym_get_user_id() . '&redirector=' . urlencode($redirector);
            if (!headers_sent()) {
                header('Location: ' . $loc);
                exit;
            } else {
                echo '<script type="text/javascript">window.location = "' . $loc . '";</script>';
            }
            die;
        }
        // gateway selection BuyNow
        $shown = 0;
        $shown_name = '';
        $shown_button = '';
        foreach ($ym_active_modules as $module) {
            $get_button = FALSE;
            if ($module == 'ym_free') {
                continue;
            } else {
                // do pack gateway check
                $get_button = TRUE;
            }
            if ($get_button) {
                ${$module} = new $module();
                $this_button = ${$module}->getButton($pack_id, $override, 'ym_available_modules');
                // a button pay not be returned (pack restrict gateway)
                if ($this_button) {
                    $shown_name = $module;
                    $shown_button = $this_button;
                    $shown++;
                    $html .= $this_button;
                }
            }
        }
        if ($shown == 0) {
            $html .= __('There are no payment gateways available at this time.', 'ym');
        } else {
            if ($shown == 1) {
                if (!method_exists(${$shown_name}, 'abort_auto')) {
                    // TODO: Are we on a page where HTML has been outputted?
                    // auto fire
                    $html = '<html>
						<head>
							<title>Redirecting...</title>
							<script type="text/javascript">
								function load() {
									document.forms["' . $shown_name . '_form"].submit();
								}
							</script>
						</head>
						<body onload="load();">';
                    $html .= '<div style="display: none;">' . $shown_button . '</div>' . '<div style="color: #333333; font-size: 14px; margin: 180px 250px; font-family: tahoma; text-align: center; padding: 50px; border: 1px solid silver;" id="ym_pay_redirect">' . '<div>You are being redirected. If this page does not refresh in 5 seconds then click <a onclick="document.forms[\'' . $module . '_form\'].submit();">here</a>.</div>' . '<div style="margin-top: 10px;"><img alt="" src="' . YM_IMAGES_DIR_URL . 'loading.gif" /></div>' . '</div>' . '</body></html>';
                    echo $html;
                    die;
                } else {
                    // aborted the auto fire step
                    $html .= ${$shown_name}->abort_auto();
                }
            }
        }
    } else {
        if (!ym_get('sel', FALSE)) {
            $html .= '<table width="100%" cellpadding="3" cellspacing="0" border="0" align="center" class="like_form">' . '<tr>' . '<th><h3 class="ym_register_heading">' . __('Select Payment Gateway', 'ym') . '</h3></th>' . '</tr>';
            /**
            No Gateway Selected
            Show Gateway Selection
            */
            $shown = 0;
            $shown_name = '';
            foreach ($ym_active_modules as $module) {
                $pay = new $module();
                $packs = $ym_packs->packs;
                $packs = apply_filters('ym_packs', $packs, $pay->code);
                if (count($packs)) {
                    $html .= '<tr>' . '<td align="center" style="padding: 5px; text-align: center;">' . '<a href="' . $base . '&sel=' . $module . '">' . '<div class="ym_module_name"><strong>' . $pay->name . '</strong></div>' . '<img class="ym_module_logo" src="' . $pay->logo . '" alt="' . $pay->name . '" title="' . $pay->name . '" />' . '</a>' . '</td>' . '</tr>';
                    $shown++;
                    $no_gateway = FALSE;
                    $shown_name = $module;
                }
                unset($pay, $packs);
            }
            $html .= '</table>';
            if ($shown == 0) {
                $html .= __('There are no payment gateways available at this time.', 'ym');
            } else {
                if ($shown == 1) {
                    // we only have one to show....
                    // auto fire
                    $loc = $base . '&sel=' . $shown_name;
                    if (!headers_sent()) {
                        header('Location: ' . $loc);
                    } else {
                        echo '<script type="text/javascript">window.location="' . $loc . '";</script>';
                    }
                    exit;
                }
            }
        } else {
            if ($selected = ym_get('sel')) {
                /**
                Gateway selected
                Show Buy Now Buttons for this gateway
                */
                // user has selected a gateway
                if (!class_exists($selected)) {
                    wp_die(sprintf(__('Unknown Module: %s', 'ym'), $selected));
                }
                $pay = new $selected();
                $html .= $pay->generateButtons(true);
            } else {
                /**
                Should not get here
                */
                wp_die(__('An error Occured (Code: YM_AVAILABLE_MODULES'));
            }
        }
    }
    /**
    Return
    */
    if ($return) {
        return $html;
    } else {
        echo $html;
        return;
    }
}
 function sync_with_gateway()
 {
     global $wpdb;
     if ($_GET['mm_action']) {
         echo '<pre>';
         echo 'sync' . "\n";
     }
     foreach (mailmanager_get_recipients() as $list => $text) {
         if ($_GET['mm_action']) {
             echo $list;
         }
         if ($listid = $this->associations->{$list}) {
             if ($_GET['mm_action']) {
                 echo ' has ';
             }
             $sql = 'SELECT id FROM ' . $wpdb->prefix . 'mm_series WHERE description = \'' . $listid . '\'';
             $series_id = $wpdb->get_var($sql);
             if (!$series_id) {
                 $sql = 'INSERT INTO ' . $wpdb->prefix . 'mm_series(name, description, recipient_list) VALUES (\'' . $this->name . ': ' . $text . '\', \'' . $listid . '\', \'' . $list . '\')';
                 $wpdb->query($sql);
                 $series_id = $wpdb->insert_id;
             }
             // its associated
             $users_sub = array();
             $users_unsub = array();
             // get lists
             $subscribed = $this->construct->active_subscribers($listid);
             $unsubscribed = $this->construct->unsubscribed_subscribers($listid);
             // hope no list is greater than 1000
             foreach ($subscribed->Results as $user) {
                 $users_sub[] = $user->EmailAddress;
                 $user_id = get_user_by_email($user->EmailAddress);
                 $user_id = $user_id->ID;
                 $timestamp = strtotime($user->Date);
                 mailmanager_get_user_in_series($user_id, $series_id, $list, $timestamp);
             }
             // unsub
             // hope no list is greater than 1000
             $sql = 'DELETE FROM ' . $wpdb->prefix . 'mm_list_unsubscribe WHERE list_name = \'' . $list . '\'';
             $wpdb->query($sql);
             foreach ($unsubscribed->Results as $user) {
                 $users_unsub[] = $user->EmailAddress;
                 $user = get_user_by_email($user->EmailAddress);
                 $user_id = $user_id->ID;
                 $timestamp = strtotime($user->Date);
                 // log unsub
                 mailmanager_unsubscribe_user($list, $user_id);
             }
             $users = array();
             foreach ($wpdb->get_results(mailmanager_get_sql($list)) as $row) {
                 $users[] = $row->email;
             }
             $users_to_add = array_diff($users, $users_sub, $users_unsub);
             if ($_GET['mm_action']) {
                 echo 'Live: ' . sizeof($users_sub) . ' Local: ' . sizeof($users) . ' To Add: ' . sizeof($users_to_add);
             }
             foreach ($users_to_add as $user) {
                 // fields
                 $data = get_user_by_email($user);
                 $theirname = $data->first_name . ' ' . $data->last_name;
                 // assemble and add custom fields
                 $custom = array();
                 $fields = ym_get_custom_field_array($data->ID);
                 if (sizeof($fields)) {
                     foreach ($fields as $field => $value) {
                         $custom[strtoupper($field)] = $value;
                     }
                 }
                 if ($_GET['mm_action']) {
                     echo "\n" . ' Adding ' . $user;
                 }
                 $this->construct->add_subscriber($listid, $user, $theirname, $custom);
             }
             if ($_GET['mm_action']) {
                 echo "\n";
             }
         }
         if ($_GET['mm_action']) {
             echo "\n";
         }
     }
     if ($_GET['mm_action']) {
         echo '</pre>';
     }
 }
Example #6
0
 function sync_with_gateway()
 {
     global $wpdb;
     if ($_GET['mm_action']) {
         echo '<pre>';
         echo 'sync' . "\n";
     }
     //print_r($this->associations);
     // this function will iterate thru all the local lists
     // it the list is associated
     // if will go get all the subscribed/unsubscribed users from aweber
     // then update the local tables
     // if it hits a user email that doth not exists locally it will? (skip it)
     foreach (mailmanager_get_recipients() as $list => $text) {
         if ($_GET['mm_action']) {
             echo $list;
         }
         if ($aweberid = $this->associations->{$list}) {
             if ($_GET['mm_action']) {
                 echo ' has ';
             }
             $sql = 'SELECT id FROM ' . $wpdb->prefix . 'mm_series WHERE description = \'' . $aweberid . '\'';
             $series_id = $wpdb->get_var($sql);
             if (!$series_id) {
                 $sql = 'INSERT INTO ' . $wpdb->prefix . 'mm_series(name, description, recipient_list) VALUES (\'Aweber: ' . $text . '\', \'' . $aweberid . '\', \'' . $list . '\')';
                 $wpdb->query($sql);
                 $series_id = $wpdb->insert_id;
             }
             // its associated
             $users_sub = array();
             $users_unsub = array();
             // go aweber
             // will contain all subed and unsubbed users
             $list_members = $this->construct->subscribers($aweberid);
             if ($this->construct_check()) {
                 // has d/c
                 if ($_GET['mm_action']) {
                     echo 'DISCONNECTED';
                 }
                 return;
             }
             $subscribed = $unsubscribed = array();
             // sort
             foreach ($list_members->entries as $entry) {
                 $status = $entry->status;
                 switch ($status) {
                     case 'unsubscribed':
                         $unsubscribed[] = $entry;
                         break;
                     case 'subscribed':
                     case 'unconfirmed':
                     default:
                         $subscribed[] = $entry;
                         break;
                 }
             }
             // le run
             foreach ($subscribed as $user) {
                 $users_sub[] = $user->email;
                 $user_id = get_user_by_email($user->email);
                 $user_id = $user_id->ID;
                 $timestamp = strtotime($user->subscribed_at);
                 // return timestamp....
                 mailmanager_get_user_in_series($user_id, $series_id, $list, $timestamp);
             }
             // umsubed
             // clean all in order to handle resubscribe.....
             $sql = 'DELETE FROM ' . $wpdb->prefix . 'mm_list_unsubscribe WHERE list_name = \'' . $list . '\'';
             $wpdb->query($sql);
             foreach ($unsubscribed as $user) {
                 $users_unsub[] = $user->email;
                 $user_id = get_user_by_email($user->email);
                 $user_id = $user_id->ID;
                 $timestamp = strtotime($user->unsubscribed_at);
                 // log unsub
                 mailmanager_unsubscribe_user($list, $user_id);
             }
             $users = array();
             foreach ($wpdb->get_results(mailmanager_get_sql($list)) as $row) {
                 $users[] = $row->email;
             }
             $users_to_add = array_diff($users, $users_sub, $users_unsub);
             if ($_GET['mm_action']) {
                 echo ' Live: ' . sizeof($users_sub) . ' Local: ' . sizeof($users) . ' To Add: ' . sizeof($users_to_add);
                 //print_r($mc_users_sub);
                 //print_r($mc_users_unsub);
                 //print_r($users);
                 //print_r($users_to_add);
             }
             // need list name
             $list_data = $this->construct->alist($aweberid);
             $awebername = $list_data->name;
             // get the web form
             $forms = $this->construct->web_forms($aweberid);
             foreach ($forms->entries as $entry) {
                 if ($entry->is_active) {
                     $form_id = $entry->id;
                 }
             }
             foreach ($users_to_add as $user) {
                 // get fname lname
                 $data = get_user_by_email($user);
                 $theirname = $data->first_name . ' ' . $data->last_name;
                 if ($theirname == ' ') {
                     list($theirname, $null) = explode('@', $user);
                 }
                 // assemble and add custom fields
                 $fields = ym_get_custom_field_array($data->ID);
                 /*
                 					foreach ($fields as $field => $value) {
                 						$custom[strtoupper($field)] = $value;
                 					}
                 */
                 if ($_GET['mm_action']) {
                     echo "\n" . ' Adding ' . $user;
                 }
                 $aweber_data = array('listname' => $awebername, 'redirect' => get_bloginfo('siteurl'), 'meta_adtracking' => 'MailManager', 'meta_required' => 'name,email', 'meta_forward_vars' => '0', 'name' => $theirname, 'email' => $user, 'submit' => 'Subscribe');
                 // prepare to hack the form
                 $this->construct->add_subscriber($aweberid, $aweber_data);
             }
             /*
             update
             foreach ($mc_users_sub as $user) {
             	// get fname lname
             	$data = get_user_by_email($user);
             	$theirname = array(
             		'FNAME'	=> $data->first_name,
             		'LNAME'	=> $data->last_name
             	);
             	// assemble and add custom fields
             	$fields = ym_get_custom_field_array($data->ID);
             	foreach ($fields as $field => $value) {
             		$theirname[strtoupper($field)] = $value;
             	}
             	if ($_GET['mm_action']) {
             		echo "\n" . ' Updating ' . $user;
             	}
             	$this->mailchimp->listUpdateMember($mcid, $user, $theirname);
             }
             */
             if ($_GET['mm_action']) {
                 echo "\n";
             }
         }
         if ($_GET['mm_action']) {
             echo "\n";
         }
     }
     if ($_GET['mm_action']) {
         echo '</pre>';
     }
 }
Example #7
0
 function sync_with_gateway()
 {
     global $wpdb;
     include YM_MM_INCLUDES_DIR . 'countries.inc.php';
     $language_code = 'en';
     $fp = fopen('/Users/barrycarlyon/WebWork/CodingFutures/yourmembers/wordpress_dev/wordpress/wp-content/plugins/ym_mailmanager/mailgateway/getresponse/log.log', 'w');
     fwrite($fp, 'a');
     fclose($fp);
     if ($_GET['mm_action']) {
         ob_end_flush();
         // echo as we go
         ob_implicit_flush(true);
         echo '<pre>';
         echo 'Syncing with Gateway' . "\n";
     }
     // from check
     if ($_GET['mm_action']) {
         echo 'From Check ';
     }
     $from_email_id = $this->from_id();
     if (!$from_email_id) {
         if ($_GET['mm_action']) {
             echo 'No From Email ';
         }
         return;
     }
     if ($_GET['mm_action']) {
         echo 'Confirmations';
     }
     $confirm_subjects = $this->getresponse->get_confirmation_subjects();
     $confirm_subject_id = FALSE;
     $confirm_subjects = get_object_vars($confirm_subjects->result);
     foreach ($confirm_subjects as $id => $details) {
         if ($details->language_code == $language_code) {
             $confirm_subject_id = $id;
         }
     }
     if (!$confirm_subject_id) {
         if ($_GET['mm_action']) {
             echo 'AN ERROR ORRCURED: Subject';
         }
         return;
     }
     $confirm_bodies = $this->getresponse->get_confirmation_bodies();
     $confirm_bodies_id = FALSE;
     $confirm_bodies = get_object_vars($confirm_bodies->result);
     foreach ($confirm_bodies as $id => $details) {
         if ($details->language_code == $language_code) {
             $confirm_bodies_id = $id;
         }
     }
     if (!$confirm_bodies_id) {
         if ($_GET['mm_action']) {
             echo 'AN ERROR ORRCURED: Body';
         }
         return;
     }
     echo ' values ' . $from_email_id . '-' . $from_email_id . '-' . $confirm_subject_id . '-' . $confirm_bodies_id;
     if ($_GET['mm_action']) {
         echo "\n" . 'Syncing All Users to list. Insert/update' . "\n";
     }
     $campaignid = $this->options->campaign_id;
     $local_users = array();
     foreach ($wpdb->get_results(mailmanager_get_sql('wordpress_users')) as $row) {
         $local_users[] = $row->email;
     }
     if ($_GET['mm_action']) {
         echo 'There are locally: ' . count($local_users) . "\n";
     }
     if ($_GET['mm_action']) {
         echo 'There are ' . count($local_users) . ' Users to sync' . "\n";
     }
     foreach ($local_users as $user_email) {
         $data = get_user_by_email($user_email);
         if ($data->first_name || $data->last_name) {
             $name = $data->first_name . ' ' . $data->last_name;
         } else {
             $name = $data->display_name;
             $data->first_name = '';
             $data->last_name = $name;
         }
         $person_name = $name;
         $merge = array('LNAME' => $data->last_name);
         if ($data->first_name) {
             $merge['FNAME'] = $data->first_name;
         }
         $fields = ym_get_custom_field_array($data->ID);
         foreach ((array) $fields as $field => $value) {
             $merge[strtoupper(str_replace(' ', '_', $field))] = $value;
         }
         if ($merge['COUNTRY']) {
             $merge['COUNTRY'] = $countries[$merge['COUNTRY']];
         }
         // list
         $id = $data->ID;
         $data = get_user_meta($id, 'ym_user');
         $account_type = $data->account_type;
         $pack_id = $data->pack_id;
         $status = get_user_meta($id, 'ym_status', TRUE);
         // new data
         $segment_account_type = 'ym_ac_' . strtolower($account_type);
         $segment_pack_id = 'ym_pack_' . $pack_id;
         $segment_all = 'ym_all_' . strtolower($status);
         $merge['segment_account_type'] = $segment_account_type;
         $merge['segment_pack_id'] = $segment_pack_id;
         $merge['segment_all'] = $segment_all;
         if ($_GET['mm_action']) {
             echo 'Syncing ' . $user_email . ' ';
         }
         // build customs
         $customs = array();
         foreach ($merge as $name => $value) {
             if ($value) {
                 $customs[] = array('name' => $name, 'content' => $value);
             } else {
                 $customs[] = array('name' => $name, 'content' => 'empty');
             }
         }
         // standard does insert or update
         if ($this->getresponse->add_contact($campaignid, 'standard', $person_name, $user_email, FALSE, FALSE, $customs)) {
             if ($_GET['mm_action']) {
                 echo 'OK queued/pending';
             }
         } else {
             if ($_GET['mm_action']) {
                 echo 'Failed';
             }
         }
         if ($_GET['mm_action']) {
             echo "\n";
         }
     }
     if ($_GET['mm_action']) {
         echo 'All Done' . "\n";
         echo '</pre>';
     }
 }
function ym_get_custom_field_array_by_username($username)
{
    $user = ym_get_user_by_username($username);
    return ym_get_custom_field_array($user->ID);
}
Example #9
0
function mailmanager_custom_fields_shortcode($atts, $content = '')
{
    global $ym_mm_custom_field_user_id;
    if ($atts['field']) {
        $field = strtolower($atts['field']);
        if ($content) {
            // if
            if (get_usermeta($ym_mm_custom_field_user_id, $field)) {
                return $content;
            }
            $fields = ym_get_custom_field_array($ym_mm_custom_field_user_id);
            if (isset($fields[$field])) {
                return $content;
            }
        } else {
            // try for user_meta
            //			$user_meta = get_userdata($ym_mm_custom_field_user_id);
            //			if ($d = $user_meta->$field) {
            if ($d = get_usermeta($ym_mm_custom_field_user_id, $field)) {
                return $d;
            }
            //$ym_user = get_usermeta($ym_mm_custom_field_user_id, 'ym_user');
            //print_r($ym_user);
            $fields = ym_get_custom_field_array($ym_mm_custom_field_user_id);
            if (isset($fields[$field])) {
                return $fields[$field];
            }
        }
    }
    return '';
}