function oxy_fetch_api_lists() { if (isset($_POST['nonce'])) { if (wp_verify_nonce($_POST['nonce'], 'oxygenna-fetch-api-lists-nonce')) { header('Content-Type: application/json'); $resp = new stdClass(); $apikey = $_POST['api_key']; $api = new MCAPI($apikey); $retval = $api->lists(); if ($api->errorCode) { $resp->status = 'error'; $resp->message = $api->errorMessage; } else { $resp->status = 'ok'; $resp->count = $retval['total']; $resp->lists = array(); foreach ($retval['data'] as $list) { $resp->lists[$list['id']] = $list['name']; } // we got a new list , so we update the theme options global $oxy_theme_options; $oxy_theme_options['unregistered']['mailchimp_lists'] = (array) $resp->lists; if (isset($oxy_theme_options['unregistered']['mailchimp_lists'])) { $oxy_theme_options['unregistered']['mailchimp_lists'] = (array) $resp->lists; } else { $oxy_theme_options['unregistered'] = array('mailchimp_lists' => $resp->lists); } update_option(THEME_SHORT . '-options', $oxy_theme_options); } echo json_encode($resp); die; } } }
function form($instance) { $instance = wp_parse_args( (array) $instance,array( 'title' => "", "list_id" => "") ); $title = empty($instance['title']) ? '' : strip_tags($instance['title']); $desc = empty($instance['title']) ? '' : strip_tags($instance['desc']); $list_id = empty($instance['list_id']) ? '' : strip_tags($instance['list_id']); if( dttheme_option('general','mailchimp-key') ): require_once(IAMD_FW."theme_widgets/mailchimp/MCAPI.class.php"); $mcapi = new MCAPI( dttheme_option('general','mailchimp-key') ); $lists = $mcapi->lists();?> <p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:','dt_themes');?> <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo esc_attr($title); ?>" /></label></p> <p><label for="<?php echo $this->get_field_id('desc'); ?>"><?php _e('Description:','dt_themes');?> <textarea class="widefat" id="<?php echo $this->get_field_id('desc'); ?>" name="<?php echo $this->get_field_name('desc'); ?>" ><?php echo esc_attr($desc); ?></textarea> </label></p> <p><label for="<?php echo $this->get_field_id('list_id'); ?>"><?php _e('Select List:','dt_themes'); ?></label> <select id="<?php echo $this->get_field_id('list_id'); ?>" name="<?php echo $this->get_field_name('list_id'); ?>"> <?php foreach ($lists['data'] as $key => $value): $id = $value['id']; $name = $value['name']; $selected = ( $list_id == $id ) ? ' selected="selected" ' : ''; echo "<option $selected value='$id'>$name</option>"; endforeach;?></select></p> <?php else: echo "<p>".__("Paste your mailchimp api key in BPanel at General Settings tab",'dt_themes')."</p>"; endif; }
public function getCMSFields() { $fieldBody = new TextareaField('Body', 'Inhoud'); $fieldBody->setRows(5); $oFields = new FieldList(new TextField('Header', 'Title'), $fieldBody, new TextField('FieldLabelName', 'Dummy text in name field'), new TextField('FieldLabelEmail', 'Dummy text in email field'), new TextField('BtnLabel', 'Button label')); if (Config::inst()->get(NewsLetterWidget_Name, NewsLetterWidget_Storage_Sys) == NewsLetterWidget_Storage_Sys_Mailchimp) { $fldTextFieldListId = new TextField('MailChimpListID', 'Mailchimp lijst id'); $sApiKey = Config::inst()->get(NewsLetterWidget_Name, NewsLetterWidget_Storage_Sys_Mailchimp_APIKey); if ($sApiKey == null || trim($sApiKey) == '') { $oFields->push($fldTextFieldListId); } else { // fetch lists $api = new MCAPI($sApiKey); $retval = $api->lists(); if ($api->errorCode) { //echo "Unable to load lists()!"; //echo "\n\tCode=".$api->errorCode; //echo "\n\tMsg=".$api->errorMessage."\n"; } else { //echo "Lists that matched:".$retval['total']."\n"; //echo "Lists returned:".sizeof($retval['data'])."\n"; $aOptions = array(); foreach ($retval['data'] as $list) { //echo "Id = ".$list['id']." - ".$list['name']."\n"; //echo "Web_id = ".$list['web_id']."\n"; $aOptions[$list['id']] = $list['name']; } $oFields->push(new DropdownField('MailChimpListID', 'Mailchimp lijst id', $aOptions)); } } } return $oFields; }
/** * Retrieves the MailChimp API key with the get_valid_mailchimp_key function above, then retrieves the MailChimp lists associated with the retrieved Key. * * No parameters are required. * * @return string containing a select box with all MailChimp Lists associated with the API key. * If the API key is no longer valid, return nothing. This avoids an empty MailChimp List Integration option within the Add / Edit Event dialogs. * */ function get_lists() { global $wpdb; $key = MailChimpController::get_valid_mailchimp_key(); $listSelection = null; $currentMailChimpID = null; if (!is_array($key) && !empty($key)) { //if the user is editing an existing event, get the previously selected MailChimp List ID if ($_REQUEST["action"] == "edit" && $_REQUEST["page"] == "events") { $MailChimpRow = $wpdb->get_row("SELECT mailchimp_list_id FROM " . EVENTS_MAILCHIMP_EVENT_REL_TABLE . " WHERE event_id = '{$_REQUEST["event_id"]}'", ARRAY_A); if (!empty($MailChimpRow)) { $currentMailChimpID = $MailChimpRow["mailchimp_list_id"]; } } $api = new MCAPI($key, 1); $lists = $api->lists(); $listSelection = "<label for='mailchimp-lists'>Select an available list " . apply_filters('espresso_help', 'mailchimp-list-integration') . "</label><select id='mailchimp-lists' name='mailchimp_list_id'>"; $listSelection .= "<option value='0'>Do not send to MailChimp</option>"; foreach ($lists["data"] as $listVars) { $selected = $listVars["id"] == $currentMailChimpID ? " selected" : ""; $listSelection .= "<option value='{$listVars["id"]}'{$selected}>{$listVars["name"]}</option>"; } $listSelection .= "</select>"; } return $listSelection; }
public function addAction() { $api = new MCAPI($this->_apiKey); $email = $this->getRequest()->getParam('email'); $retval = $api->lists(); if ($api->errorCode) { Mage::getSingleton('core/session')->addError($this->__('Error: %s', $api->errorMessage)); } else { /*foreach($retval['data'] as $val) { if ($val['name'] === "Prospects") { $prospectListId = $val['id']; } elseif ($val['name'] === "Fashion Eyewear Customers") { $customerListId = $val['id']; } }*/ $customers = Mage::getModel('customer/customer')->getCollection()->addAttributeToSelect('*')->addAttributeToFilter('email', $email)->getData(); $customerId = $customers[0]['entity_id']; $orders = Mage::getResourceModel('sales/order_collection')->addFieldToSelect('*')->addFieldToFilter('customer_id', $customerId)->getData(); if (!empty($orders)) { //add to Customer List $listId = $this->customerListId; } else { //add to Prospect list $listId = $this->prospectListId; } $merge_vars = array('FNAME' => $this->getRequest()->getParam('firstname')); if ($api->listSubscribe($listId, $email, $merge_vars) === true) { Mage::getSingleton('core/session')->addSuccess($this->__('Success! Check your email to confirm sign up.')); } else { Mage::getSingleton('core/session')->addError($this->__('Error: %s', $api->errorMessage)); } } $this->_redirectReferer(); }
/** * Method to get the field options. * * @return array The field option objects. * @since 1.6 */ protected function getOptions() { // Initialize variables. $options = array(); $app = JFactory::getApplication(); require_once JPATH_SITE . '/components/com_jms/helpers/MCAPI.class.php'; require_once JPATH_SITE . '/components/com_jms/helpers/MCauth.php'; $MCauth = new MCauth(); // Get the component config/params object. $params = JComponentHelper::getParams('com_joomailermailchimpintegration'); $paramsPrefix = version_compare(JVERSION, '1.6.0', 'ge') ? 'params.' : ''; $api_key = $params->get($paramsPrefix . 'MCapi'); if ($MCauth->MCauth()) { $api = new MCAPI($api_key); $retval = $api->lists(); if (is_array($retval['data'])) { foreach ($retval['data'] as $list) { $options[] = JHTML::_('select.option', $list['id'], JText::_($list['name'])); } } } // Merge any additional options in the XML definition. $options = array_merge(parent::getOptions(), $options); return $options; }
public static function getList($params = array()) { require_once OSEMSC_B_LIB . DS . 'MCAPI.class.php'; $oseMscConfig = oseRegistry::call('msc')->getConfig(null, 'obj'); $APIKey = $oseMscConfig->mailchimp_api_key; $api = new MCAPI($APIKey); $lists = $api->lists(); $data = $lists['data']; $items = array(); $item = array(); foreach ($data as $value) { $item['list_id'] = $value['id']; $item['name'] = $value['name']; $items[] = $item; } $result = array(); if (count($items) < 1) { $result['total'] = 0; $result['results'] = ''; } else { $result['total'] = count($items); $result['results'] = $items; } return $result; }
function form($instance) { $instance = wp_parse_args((array) $instance, array('title' => "", "list_id" => "")); $title = empty($instance['title']) ? '' : strip_tags($instance['title']); $list_id = empty($instance['list_id']) ? '' : strip_tags($instance['list_id']); if (dt_theme_option('general', 'mailchimp-key')) { require_once IAMD_FW . "theme_widgets/mailchimp/MCAPI.class.php"; $mcapi = new MCAPI(dt_theme_option('general', 'mailchimp-key')); $lists = $mcapi->lists(); ?> <p><label for="<?php echo $this->get_field_id('title'); ?> "><?php _e('Title:', 'iamd_text_domain'); ?> <input class="widefat" id="<?php echo $this->get_field_id('title'); ?> " name="<?php echo $this->get_field_name('title'); ?> " type="text" value="<?php echo esc_attr($title); ?> " /></label></p> <p><label for="<?php echo $this->get_field_id('list_id'); ?> "><?php _e('Select List:', 'iamd_text_domain'); ?> </label> <select id="<?php echo $this->get_field_id('list_id'); ?> " name="<?php echo $this->get_field_name('list_id'); ?> "> <?php foreach ($lists['data'] as $key => $value) { $id = $value['id']; $name = $value['name']; $selected = $list_id == $id ? ' selected="selected" ' : ''; echo "<option {$selected} value='{$id}'>{$name}</option>"; } ?> </select></p> <?php } else { echo "<p>" . __("Paste your mailchimp api key in BPanel at General Settings tab", 'iamd_text_domain') . "</p>"; } }
public function moveSubscriber() { $api = new MCAPI($this->_apiKey); $retval = $api->lists(); if ($api->errorCode) { Mage::getSingleton('core/session')->addError($this->__('Error: %s', $api->errorMessage)); } else { foreach ($retval['data'] as $val) { if ($val['name'] === "Prospects") { $prospectListId = $val['id']; } elseif ($val['name'] === "Fashion Eyewear Customers") { $customerListId = $val['id']; } } if ($api->errorCode != '') { // an error occurred while logging in Mage::log('Error Code: ' . $api->errorCode); Mage::log('Error Message: ' . $api->errorMessage); die; } $retval = $api->listMembers($prospectListId, 'subscribed', null, 0, 10000); //var_dump($retval);die; if (!$retval) { Mage::log('Error Code: ' . $api->errorCode); Mage::log('Error Message: ' . $api->errorMessage); } else { foreach ($retval['data'] as $member) { //echo $member['email']." - ".$member['timestamp']."<br />"; $customerModel = Mage::getModel('customer/customer')->getCollection()->addAttributeToSelect('*')->addAttributeToFilter('email', $member['email'])->setPage(1, 1); $customers = $customerModel->getData(); $customerId = $customers[0]['entity_id']; $orders = Mage::getResourceModel('sales/order_collection')->addFieldToSelect('*')->addFieldToFilter('customer_id', $customerId)->getData(); if (!empty($orders)) { //if ($member['email'] === '*****@*****.**') { $memInfo = $api->listMemberInfo($prospectListId, array($member['email'])); $firstname = $memInfo['data'][0]['merges']['FNAME']; if (empty($firstname)) { $firstname = Mage::getModel('customer/customer')->load($customerId)->getFirstname(); } $retuns = $api->listUnsubscribe($prospectListId, $member['email'], 1); if (!$retuns) { Mage::log('Unsubscribe Error Code: ' . $api->errorCode); Mage::log('Unsubscribe Error Message: ' . $api->errorMessage); } $merge_vars = array('FNAME' => $firstname); $retsub = $api->listSubscribe($customerListId, $member['email'], $merge_vars); if (!$retsub) { Mage::log('Subscribe Error Code: ' . $api->errorCode); Mage::log('Subscribe Error Message: ' . $api->errorMessage); } //} } } } } }
/** * Get information about a specific mailing list. * * @param string $id The id of the list to get information about. * @param bool $useCache If true, use the cached result if available. * @return array Array of data about a list. * @link MailingList::listMailinglists. */ public function getMailinglist($id, $useCache = true) { $cacheName = $this->__getCacheName(__FUNCTION__, array($id)); if ($useCache) { $cachedResult = $this->__getCachedResult($cacheName); if ($cachedResult !== false) { return $cachedResult; } } $result = $this->__api->lists(array('list_id' => $id)); $this->__cacheResult($cacheName, $result); return $result; }
/** * subscribe to a mailinglist * * @return status */ function Mailinglists_subscribe() { $list = (int) $_REQUEST['list']; $email = $_REQUEST['email']; if (!filter_var($email, FILTER_VALIDATE_EMAIL)) { return array('error' => __('Not an email address')); } $sql = 'select * from mailinglists_lists'; if ($list) { $sql .= ' where id=' . $list; } $list = dbRow($sql); if (!$list) { return array('error' => __('No such mailing list')); } $listMeta = json_decode($list['meta'], true); switch ($listMeta['engine']) { case 'Ubivox': // { $apiusername = $listMeta['ubivox-apiusername']; $apipassword = $listMeta['ubivox-apipassword']; $listId = preg_replace('/\\|.*/', '', $listMeta['ubivox-list']); $response = Mailinglists_xmlrpcClient($apiusername, $apipassword, xmlrpc_encode_request('ubivox.create_subscription', array($email, array($listId), true))); $data = xmlrpc_decode(trim($response)); break; // } // } default: // { $apikey = $listMeta['mailchimp-apikey']; require_once dirname(__FILE__) . '/MCAPI.class.php'; $api = new MCAPI($apikey); $data = $api->lists(); $api->listSubscribe(preg_replace('/\\|.*/', '', $listMeta['mailchimp-list']), $email); if ($api->errorCode) { return array('error' => $api->errorCode, 'message' => $api->errorMessage); } // } } return array('ok' => true); }
/** * Given a user, the name of a MailChimp list, and the MailChimp API credentials, * subscribe user to named list. <b>Will die() on any errors from MailChimp.</b> * * For the MailChimp API documentation pertinent to subscribing a user, see here: * <a href="http://www.mailchimp.com/api/1.0/listsubscribe.func.php">MailChimp * API</a> * * @param array $user Contains the information about the user to subscribe. Keys: * 'first_name' => string; the user's first name * 'last_name' => string; the user's last name * 'email' => string; the user's email address * 'format' (optional) => string; list format preference, * either 'html' or 'text' * If not present, defaults to 'html'. * 'confirm' (optional) => boolean; when true, send a * subscription confirmation. * If not present, defaults to true. * * @param string $list_name The name of the list to subscribe to. * * @param array $credentials Contains the credentials for the MailChimp account * that owns the list. Keys: * 'user' => string; MailChimp username * 'pass' => string; MailChimp password * * @return boolean Returns true if member subscribed to the list. */ function subscribe_user_to_list($user, $list_name, $credentials) { if (isset($credentials['apikey'])) { $credentials['user'] = $credentials['apikey']; // With an API key, pass it as the first parameter to the MCAPI constructor. } $mc = new MCAPI($credentials['user']); $mc or die("Unable to connect to MailChimp API, error: " . $mc->errorMessage); $lists = $mc->lists() or die($mc->errorMessage); $list_id = null; foreach ($lists['data'] as $list) { // Iterate, finding the list named $list_name if ($list['name'] == $list_name) { $list_id = $list['id']; } } $list_id or die("Couldn't find a list named '{$list_name}'!"); $retval = $mc->listSubscribe($list_id, $user['email'], array('FNAME' => $user['first_name'], 'LNAME' => $user['last_name']), isset($user['format']) ? $user['format'] : 'html', isset($user['confirm']) ? $user['confirm'] : true); $retval or preg_match("/already subscribed/i", $mc->errorMessage) or die("Unable to load listSubscribe()! " . "MailChimp reported error:\n\tCode=" . $mc->errorCode . "\n\tMsg=" . $mc->errorMessage . "\n"); return true; // All's well. }
function dh_get_mailchimplist() { $options = array(__('Nothing Found...', DH_DOMAIN)); if ($mailchimp_api = dh_get_theme_option('mailchimp_api', '')) { if (!class_exists('MCAPI')) { include_once DHINC_DIR . '/lib/MCAPI.class.php'; } $api = new MCAPI($mailchimp_api); $lists = $api->lists(); if ($api->errorCode) { $options = array(__("Unable to load MailChimp lists, check your API Key.", DH_DOMAIN)); } else { if ($lists['total'] == 0) { $options = array(__("You have not created any lists at MailChimp", DH_DOMAIN)); } else { $options = array(__('Select a list', DH_DOMAIN)); foreach ($lists['data'] as $list) { $options[$list['id']] = $list['name']; } } } } return $options; }
function getMailChimpLists() { require_once PREMISE_LIB_DIR . 'mailchimp_api/MCAPI.class.php'; $settings = $this->getSettings(); $mailchimp = new MCAPI($settings['optin']['mailchimp-api']); $data = $mailchimp->lists(array(), 0, 100); $lists = array(); if (is_array($data) && is_array($data['data'])) { foreach ($data['data'] as $item) { $lists[] = array('id' => $item['id'], 'name' => $item['name']); } } return $lists; }
</div> <div class="hr"></div> <div class="clear"> </div> <h6><?php _e('Select Mailchimp List', 'dt_themes'); ?> </h6> <div class="column one-half"> <?php $list_id = dttheme_option('general', 'mailchimp-listid') != '' ? dttheme_option('general', 'mailchimp-listid') : ''; require_once IAMD_FW . "theme_widgets/mailchimp/MCAPI.class.php"; $mcapi = new MCAPI(dttheme_option('general', 'mailchimp-key')); $lists = $mcapi->lists(); ?> <select id="mytheme-mailchimp-listid" name="mytheme[general][mailchimp-listid]"> <?php foreach ($lists['data'] as $key => $value) { $id = $value['id']; $name = $value['name']; $selected = $list_id == $id ? ' selected="selected" ' : ''; echo "<option {$selected} value='{$id}'>{$name}</option>"; } ?> </select> </div> <div class="column one-half last">
function a360_dashboard() { global $a360_api_key, $a360_ga_token, $a360_has_key; $notification = isset($_GET['a360_error']) ? '<span class="error" style="padding:3px;"><strong>Error</strong>: ' . stripslashes($_GET['a360_error']) . '</span>' : ''; $a360_list_options = array(); if (!empty($a360_api_key)) { if (!class_exists('MCAPI')) { include_once ABSPATH . PLUGINDIR . '/analytics360/php/MCAPI.class.php'; } $api = new MCAPI($a360_api_key); if (empty($api->errorCode)) { $lists = $api->lists(); if (is_array($lists)) { foreach ($lists as $list) { $a360_list_options[] = '<option value="' . $list['id'] . '">' . $list['name'] . '</option>'; } } else { $a360_list_options[] = '<option value="">Error: ' . $api->errorMessage . '</option>'; } } else { $a360_list_options[] = '<option value="">API Key Error: ' . $api->errorMessage . '</option>'; } } include 'php/header.php'; include 'php/dashboard.php'; include 'php/footer.php'; }
public function getNewsletterLists($type, array $info) { $mail_service_path = dirname(__FILE__) . '/mail_service/' . $type . '.php'; if (file_exists($mail_service_path)) { require_once $mail_service_path; if ($type == 'icontact') { // Give the API your information iContactApi::getInstance()->setConfig(array('appId' => $info['icontact_app_key'], 'apiUsername' => $info['icontact_username'], 'apiPassword' => $info['icontact_password'])); // Store the singleton $oiContact = iContactApi::getInstance(); try { $lists = $oiContact->getLists(); $results = array(); foreach ($lists as $list) { $results[$list->listId] = $list->name; } } catch (Exception $e) { $errors = $oiContact->getErrors(); throw new Exception(current($errors)); } } else { if ($type == 'mailchimp') { $api = new MCAPI($info['mailchimp_api_key']); $results = array(); if ($api) { $lists = $api->lists(); if ($lists && !empty($lists['data'])) { foreach ($lists['data'] as $list) { $results[$list['id']] = $list['name']; } } } } } } else { throw new Exception(_t('This mail service is not available!')); } return $results; }
private static function is_valid_login($username_or_apikey, $password = null) { if ($password) { if (!class_exists("MCAPI_Legacy")) { require_once "api/MCAPI_Legacy.class.php"; } self::log("Validating login for Legacy API Info for username {$username_or_apikey} and password {$password}", "debug"); $api = new MCAPI_Legacy(trim($username_or_apikey), trim($password)); } else { if (!class_exists("MCAPI")) { require_once "api/MCAPI.class.php"; } self::log("Validating login for API Info for key {$username_or_apikey}", "debug"); $api = new MCAPI(trim($username_or_apikey), trim($password)); $api->lists(); } $GLOBALS["mc_api_key"] = null; if ($api->errorCode) { self::log("Login valid: false. Error " . $api->errorCode . " - " . $api->errorMessage, "error"); } else { self::log("Login valid: true", "debug"); } return $api->errorCode ? false : true; }
function form($instance) { $title = isset($instance['title']) ? $instance['title'] : ''; $button_text = isset($instance['button_text']) ? $instance['button_text'] : ''; $zn_mailchimp_intro = isset($instance['zn_mailchimp_intro']) ? $instance['zn_mailchimp_intro'] : ''; $zn_mailchimp_outro = isset($instance['zn_mailchimp_outro']) ? $instance['zn_mailchimp_outro'] : ''; $zn_mailchimp_list = isset($instance['zn_mailchimp_list']) ? $instance['zn_mailchimp_list'] : ''; $data = $this->data; if (!function_exists('curl_init')) { echo __('Curl is not enabled on your hosting environment. Please contact your hosting company and ask them to enable CURL for your account.', THEMENAME); return; } if (!isset($data['mailchimp_api']) && empty($data['mailchimp_api'])) { echo __('Please enter your MailChimp API KEY in the theme options pannel prior of using this widget.', THEMENAME); return; } if (isset($data['mailchimp_api']) && !empty($data['mailchimp_api'])) { if (!class_exists('MCAPI')) { include_once TEMPLATEPATH . '/widgets/mailchimp/MCAPI.class.php'; } $api_key = $data['mailchimp_api']; $mcapi = new MCAPI($api_key); $lists = $mcapi->lists(); } //print_r($lists); ?> <p> <label for="<?php echo $this->get_field_id('title'); ?> "><?php _e('Title:', THEMENAME); ?> </label> <input type="text" class="widefat" id="<?php echo $this->get_field_id('title'); ?> " name="<?php echo $this->get_field_name('title'); ?> " value="<?php echo $title; ?> " /> </p> <p> <label for="<?php echo $this->get_field_id('zn_mailchimp_list'); ?> "><?php _e('Select List:', THEMENAME); ?> </label> <select id="<?php echo $this->get_field_id('zn_mailchimp_list'); ?> " name="<?php echo $this->get_field_name('zn_mailchimp_list'); ?> "> <?php if (isset($lists['data']) && is_array($lists['data'])) { foreach ($lists['data'] as $key => $value) { $selected = isset($zn_mailchimp_list) && $zn_mailchimp_list == $value['id'] ? ' selected="selected" ' : ''; ?> <option <?php echo $selected; ?> value="<?php echo $value['id']; ?> "><?php echo $value['name']; ?> </option> <?php } } ?> </select> </p> <p> <div><label for="<?php echo $this->get_field_id('zn_mailchimp_intro'); ?> "><?php echo __('Intro Text :', THEMENAME); ?> </label></div> <div><textarea id="<?php echo $this->get_field_id('zn_mailchimp_intro'); ?> " name="<?php echo $this->get_field_name('zn_mailchimp_intro'); ?> " cols="35" rows="5"><?php echo $zn_mailchimp_intro; ?> </textarea></div> </p> <p> <div><label for="<?php echo $this->get_field_id('zn_mailchimp_outro'); ?> "><?php echo __('After Form Text :', THEMENAME); ?> </label></div> <div><textarea id="<?php echo $this->get_field_id('zn_mailchimp_outro'); ?> " name="<?php echo $this->get_field_name('zn_mailchimp_outro'); ?> " cols="35" rows="5"><?php echo $zn_mailchimp_outro; ?> </textarea></div> </p> <p> <label for="<?php echo $this->get_field_id('button_text'); ?> "><?php _e('Button text:', THEMENAME); ?> </label> <input type="text" class="widefat" id="<?php echo $this->get_field_id('button_text'); ?> " name="<?php echo $this->get_field_name('button_text'); ?> " value="<?php echo $button_text; ?> " /> </p> <?php }
public function us_fan_counts() { header('content-type: application/json'); $ajax_debug = UltimateSocialDeux::opt('us_ajax_debug', false); if (wp_verify_nonce($_REQUEST['nonce'], 'us_nonce') || $ajax_debug) { if (!class_exists('Requests')) { require_once plugin_dir_path(__FILE__) . '/includes/Requests.php'; Requests::register_autoloader(); } $args = $_REQUEST['args'] ? $_REQUEST['args'] : die('Args not set'); $args = urldecode(stripslashes($args)); $args = json_decode($args, true); $option = maybe_unserialize(get_option('us_fan_counts', array())); $json = array(); $networks = explode(',', $args['networks']); $networks = array_keys(array_flip($networks)); $timestamp = time(); foreach ($networks as $key => $network) { $option[$network]['count'] = isset($option[$network]['count']) ? $option[$network]['count'] : 0; $json[$network]['count'] = $option[$network]['count']; $option[$network]['timestamp'] = $timestamp; $id = ''; $key = ''; $secret = ''; $api = ''; $app = ''; $user = ''; $name = ''; $username = ''; switch ($network) { case 'facebook': $app_token = UltimateSocialDeux::opt('us_facebook_token'); $fb_token = $app_token ? "?access_token=" . $app_token : ''; $id = UltimateSocialDeux::opt('us_facebook_id'); if ($id) { $requests[$network] = array('url' => "https://graph.facebook.com/" . $id . $fb_token); } break; case 'twitter': $id = UltimateSocialDeux::opt('us_twitter_id'); $key = UltimateSocialDeux::opt('us_twitter_key'); $secret = UltimateSocialDeux::opt('us_twitter_secret'); if ($id && $key && $secret) { $token = get_option('us_fan_count_twitter_token'); if (!$token) { $credentials = $key . ':' . $secret; $encode = base64_encode($credentials); $args = array('method' => 'POST', 'httpversion' => '1.1', 'blocking' => true, 'headers' => array('Authorization' => 'Basic ' . $encode, 'Content-Type' => 'application/x-www-form-urlencoded;charset=UTF-8'), 'body' => array('grant_type' => 'client_credentials')); add_filter('https_ssl_verify', '__return_false'); $response = wp_remote_post('https://api.twitter.com/oauth2/token', $args); $keys = json_decode(wp_remote_retrieve_body($response)); if (!isset($keys->errors) && $keys) { update_option('us_fan_count_twitter_token', $keys->access_token); $token = $keys->access_token; } } $requests[$network] = array('url' => 'https://api.twitter.com/1.1/users/show.json?screen_name=' . $id, 'headers' => array('Authorization' => "Bearer {$token}")); } break; case 'google': $id = UltimateSocialDeux::opt('us_google_id'); $key = UltimateSocialDeux::opt('us_google_key'); if ($key && $id) { $requests[$network] = array('url' => "https://www.googleapis.com/plus/v1/people/" . $id . "?key=" . $key); } break; case 'behance': $id = UltimateSocialDeux::opt('us_behance_id'); $api = UltimateSocialDeux::opt('us_behance_api'); if ($id && $api) { $requests[$network] = array('url' => "http://www.behance.net/v2/users/" . $id . "?api_key=" . $api); } break; case 'delicious': $id = UltimateSocialDeux::opt('us_delicious_id'); if ($id) { $requests[$network] = array('url' => "http://feeds.delicious.com/v2/json/userinfo/" . $id); } break; case 'linkedin': $id = UltimateSocialDeux::opt('us_linkedin_id'); $app = UltimateSocialDeux::opt('us_linkedin_app'); $api = UltimateSocialDeux::opt('us_linkedin_api'); if (!class_exists('LinkedIn')) { require_once plugin_dir_path(__FILE__) . 'includes/linkedin/linkedin.php'; } if (!class_exists('OAuthServer')) { require_once plugin_dir_path(__FILE__) . 'includes/OAuth/OAuth.php'; } if ($id && $api && $id) { $count = 0; $opt = array('appKey' => $app, 'appSecret' => $api, 'callbackUrl' => ''); $api_call = new LinkedIn($opt); $response = $api_call->company(trim('universal-name=' . $id . ':(num-followers)')); if ($ajax_debug) { print_r($response); } if (false !== $response['success']) { $company = new SimpleXMLElement($response['linkedin']); if (isset($company->{'num-followers'})) { $count = intval(current($company->{'num-followers'})); } } $option[$network]['count'] = $count; $json[$network]['count'] = $count; } break; case 'youtube': $id = UltimateSocialDeux::opt('us_youtube_id'); if ($id) { $requests[$network] = array('url' => "http://gdata.youtube.com/feeds/api/users/" . $id . "?alt=json"); } break; case 'soundcloud': $id = UltimateSocialDeux::opt('us_soundcloud_id'); $user = UltimateSocialDeux::opt('us_soundcloud_username'); if ($id && $user) { $requests[$network] = array('url' => 'http://api.soundcloud.com/users/' . $user . '.json?client_id=' . $id); } break; case 'vimeo': $id = UltimateSocialDeux::opt('us_vimeo_id'); if ($id) { $requests[$network] = array('url' => "http://vimeo.com/api/v2/channel/" . $id . "/info.json"); } break; case 'dribbble': $id = UltimateSocialDeux::opt('us_dribbble_id'); if ($id) { $requests[$network] = array('url' => "http://api.dribbble.com/" . $id); } break; case 'github': $id = UltimateSocialDeux::opt('us_github_id'); if ($id) { $requests[$network] = array('url' => "https://api.github.com/users/" . $id); } break; case 'envato': $id = UltimateSocialDeux::opt('us_envato_id'); if ($id) { $requests[$network] = array('url' => "http://marketplace.envato.com/api/edge/user:"******".json"); } break; case 'instagram': $api = UltimateSocialDeux::opt('us_instagram_api'); $id = explode(".", $api); if ($api && $id) { $requests[$network] = array('url' => "https://api.instagram.com/v1/users/" . $id[0] . "/?access_token=" . $api); } break; case 'mailchimp': $name = UltimateSocialDeux::opt('us_mailchimp_name'); $api = UltimateSocialDeux::opt('us_mailchimp_api'); $count = 0; if ($name && $api) { if (!class_exists('MCAPI')) { require_once plugin_dir_path(__FILE__) . 'includes/MCAPI.class.php'; } $api = new MCAPI($api); $retval = $api->lists(); if ($ajax_debug) { print_r($retval); } if (count($retval['data']) > 0) { foreach ($retval['data'] as $list) { if ($list['name'] == $name) { $count = intval($list['stats']['member_count']); break; } } } } $option[$network]['count'] = intval($count); $json[$network]['count'] = intval($count); break; case 'vkontakte': $id = UltimateSocialDeux::opt('us_vkontakte_id'); if ($id) { $requests[$network] = array('url' => "http://api.vk.com/method/groups.getById?gid=" . $id . "&fields=members_count"); } break; case 'pinterest': $username = UltimateSocialDeux::opt('us_pinterest_username'); if ($username) { $requests[$network] = array('url' => 'http://www.pinterest.com/' . $username . '/'); } break; case 'flickr': $id = UltimateSocialDeux::opt('us_flickr_id'); $api = UltimateSocialDeux::opt('us_flickr_api'); if ($id && $api) { $requests[$network] = array('url' => "https://api.flickr.com/services/rest/?method=flickr.groups.getInfo&api_key=" . $api . "&group_id=" . $id . "&format=json&nojsoncallback=1"); } break; case 'feedpress': $manual = intval(UltimateSocialDeux::opt('us_feedpress_manual', 0)); $url = UltimateSocialDeux::opt('us_feedpress_url'); if (filter_var($url, FILTER_VALIDATE_URL)) { $requests[$network] = array('url' => $url); } if ($manual) { $option[$network]['count'] = $manual; $json[$network]['count'] = $manual; } break; default: unset($option[$network]); unset($json[$network]); break; } } $responses = !empty($requests) ? Requests::request_multiple($requests) : die('No requests sent.'); foreach ($responses as $network => $data) { switch ($network) { case 'facebook': if (isset($responses[$network]->body)) { $content = $responses[$network]->body; if ($ajax_debug) { print_r($content); } $content = json_decode($content, true); $option[$network]['count'] = intval($content['likes']); $json[$network]['count'] = intval($content['likes']); } break; case 'twitter': case 'soundcloud': case 'dribbble': if (isset($responses[$network]->body)) { $content = $responses[$network]->body; if ($ajax_debug) { print_r($content); } $content = json_decode($content, true); $option[$network]['count'] = intval($content['followers_count']); $json[$network]['count'] = intval($content['followers_count']); } break; case 'google': if (isset($responses[$network]->body)) { $content = $responses[$network]->body; if ($ajax_debug) { print_r($content); } $content = json_decode($content, true); $option[$network]['count'] = intval($content['circledByCount']); $json[$network]['count'] = intval($content['circledByCount']); } break; case 'behance': if (isset($responses[$network]->body)) { $content = $responses[$network]->body; if ($ajax_debug) { print_r($content); } $content = json_decode($content, true); $option[$network]['count'] = intval($content['user']['stats']['followers']); $json[$network]['count'] = intval($content['user']['stats']['followers']); } break; case 'delicious': if (isset($responses[$network]->body)) { $content = $responses[$network]->body; if ($ajax_debug) { print_r($content); } $content = json_decode($content, true); $option[$network]['count'] = intval($content[2]['n']); $json[$network]['count'] = intval($content[2]['n']); } break; case 'youtube': if (isset($responses[$network]->body)) { $content = $responses[$network]->body; if ($ajax_debug) { print_r($content); } $content = json_decode($content, true); $option[$network]['count'] = intval($content['entry']['yt$statistics']['subscriberCount']); $json[$network]['count'] = intval($content['entry']['yt$statistics']['subscriberCount']); } break; case 'vimeo': if (isset($responses[$network]->body)) { $content = $responses[$network]->body; if ($ajax_debug) { print_r($content); } $content = json_decode($content, true); $option[$network]['count'] = intval($content['total_subscribers']); $json[$network]['count'] = intval($content['total_subscribers']); } break; case 'github': if (isset($responses[$network]->body)) { $content = $responses[$network]->body; if ($ajax_debug) { print_r($content); } $content = json_decode($content, true); $option[$network]['count'] = intval($content['followers']); $json[$network]['count'] = intval($content['followers']); } break; case 'envato': if (isset($responses[$network]->body)) { $content = $responses[$network]->body; if ($ajax_debug) { print_r($content); } $content = json_decode($content, true); $option[$network]['count'] = intval($content['user']['followers']); $json[$network]['count'] = intval($content['user']['followers']); } break; case 'instagram': if (isset($responses[$network]->body)) { $content = $responses[$network]->body; if ($ajax_debug) { print_r($content); } $content = json_decode($content, true); $option[$network]['count'] = intval($content['data']['counts']['followed_by']); $json[$network]['count'] = intval($content['data']['counts']['followed_by']); } break; case 'vkontakte': if (isset($responses[$network]->body)) { $content = $responses[$network]->body; if ($ajax_debug) { print_r($content); } $content = json_decode($content, true); $option[$network]['count'] = intval($content['response'][0]['members_count']); $json[$network]['count'] = intval($content['response'][0]['members_count']); } break; case 'pinterest': if (isset($responses[$network]->body)) { $html = $responses[$network]->body; if ($ajax_debug) { print_r($html); } $doc = new DOMDocument(); @$doc->loadHTML($html); $metas = $doc->getElementsByTagName('meta'); for ($i = 0; $i < $metas->length; $i++) { $meta = $metas->item($i); if ($meta->getAttribute('name') == 'pinterestapp:followers') { $count = intval($meta->getAttribute('content')); break; } } $option[$network]['count'] = $count; $json[$network]['count'] = $count; } break; case 'flickr': if (isset($responses[$network]->body)) { $content = $responses[$network]->body; if ($ajax_debug) { print_r($content); } $content = json_decode($content, true); $option[$network]['count'] = intval($content['group']['members']['_content']); $json[$network]['count'] = intval($content['group']['members']['_content']); } break; case 'feedpress': if (isset($responses[$network]->body)) { $content = $responses[$network]->body; if ($ajax_debug) { print_r($content); } $content = json_decode($content, true); $option[$network]['count'] = intval($content['subscribers']) + $manuel; $json[$network]['count'] = intval($content['subscribers']) + $manuel; } break; } } maybe_serialize(update_option('us_fan_counts', $option)); echo str_replace('\\/', '/', json_encode($json)); } else { die('Nonce not verified'); } die; }
<?php /* * Example connect to mailchimp */ //============================================== require_once 'MCAPI.class.php'; $apikey = 'xzxzxzxzxzxzxzxzxzxzxzxzxzxzxzxzx-us1'; // Enter your API key here $api = new MCAPI($apikey); //============================================== $retval = $api->lists(); // get all info from lists //============ details for sending ============= $listid = 'xxxxxxxxx'; // Enter your list Id here that you want to use $req_email = $_GET['email']; $first_name = $_GET['fname']; $last_name = $_GET['lname']; $person_id = $_GET['id']; //============================================== // By default this sends a confirmation email - you will not see new members // until the link contained in it is clicked! // But if you put 'false' option it will not send a confirmation email. $merge_vars = array('FNAME' => $first_name, 'LNAME' => $last_name, 'PERSONID' => $person_id, 'optin-confirm' => 'on'); // FNAME , LNAME , PERSONID -> these fields in mailchimp $api->listSubscribe($listid, $req_email, $merge_vars, 'html', false);
public function form($instance) { $title = isset($instance['title']) && $instance['title'] ? esc_attr($instance['title']) : ''; $list = isset($instance['list']) && $instance['list'] ? esc_attr($instance['list']) : ''; $opt_in = isset($instance['opt_in']) && $instance['opt_in'] ? 'yes' : 'no'; $text_before = isset($instance['text_before']) && $instance['text_before'] ? esc_attr($instance['text_before']) : ''; $text_after = isset($instance['text_after']) && $instance['text_after'] ? esc_attr($instance['text_after']) : ''; $content = isset($instance['content']) && $instance['content'] ? esc_attr($instance['content']) : 'Success! Check your inbox or spam folder for a message containing a confirmation link.'; $layout = isset($instance['layout']) && $instance['layout'] ? esc_attr($instance['layout']) : 'one'; $height_desktop = isset($instance['height_desktop']) && intval($instance['height_desktop']) > 0 ? intval($instance['height_desktop']) : 0; $height_tablet = isset($instance['height_tablet']) && intval($instance['height_tablet']) > 0 ? intval($instance['height_tablet']) : 0; $height_mobile = isset($instance['height_mobile']) && intval($instance['height_mobile']) > 0 ? intval($instance['height_mobile']) : 0; $css = isset($instance['css']) && $instance['css'] ? esc_attr($instance['css']) : ''; $options = get_option('kt_mailchimp_option'); $api_key = $options['api_key']; $html = '<option value="0">Choose List</option>'; if (isset($api_key) && !empty($api_key)) { $mcapi = new MCAPI($api_key); $lists = $mcapi->lists(); if ($lists['data']) { foreach ($lists['data'] as $item) { $html .= '<option value="' . $item['id'] . '" ' . selected($list, $item['name']) . '>' . $item['name'] . '</option>'; } } } ?> <div class="widget-content"> <p> <label><?php _e('Title:', 'kutetheme'); ?> </label> <input class="widefat" id="<?php echo $this->get_field_id('title'); ?> " name="<?php echo $this->get_field_name('title'); ?> " type="text" value="<?php echo esc_attr($title); ?> " /> </p> <p> <label><?php _e('Newsletter layout:', 'kutetheme'); ?> </label> <select class="widefat" id="<?php echo $this->get_field_id('layout'); ?> " name="<?php echo $this->get_field_name('layout'); ?> "> <option value="one"<?php selected($layout, 'one'); ?> ><?php _e('One line', 'kutetheme'); ?> </option> <option value="two"<?php selected($layout, 'two'); ?> ><?php _e('Two line', 'kutetheme'); ?> </option> </select> </p> <p> <label><?php _e('List:', 'kutetheme'); ?> </label> <select class="widefat" id="<?php echo $this->get_field_id('list'); ?> " name="<?php echo $this->get_field_name('list'); ?> "> <?php echo $html; ?> </select> </p> <p> <label><?php _e('Double opt-in:', 'kutetheme'); ?> </label> <input <?php checked($opt_in, "yes"); ?> value="<?php _e('Yes, please', 'kutetheme'); ?> " class="widefat" id="<?php echo $this->get_field_id('opt_in'); ?> " name="<?php echo $this->get_field_name('opt_in'); ?> " type="checkbox" /> </p> <p> <label><?php _e('Text before form:', 'kutetheme'); ?> </label> <textarea class="widefat" rows="3" id="<?php echo $this->get_field_id('text_before'); ?> " name="<?php echo $this->get_field_name('text_before'); ?> "><?php echo esc_textarea($text_before); ?> </textarea> </p> <p> <label><?php _e('Text after form:', 'kutetheme'); ?> </label> <textarea class="widefat" rows="3" id="<?php echo $this->get_field_id('text_after'); ?> " name="<?php echo $this->get_field_name('text_after'); ?> "><?php echo esc_textarea($text_after); ?> </textarea> </p> <p> <label><?php _e('Success Message:', 'kutetheme'); ?> </label> <textarea class="widefat" rows="3" id="<?php echo $this->get_field_id('content'); ?> " name="<?php echo $this->get_field_name('content'); ?> "><?php echo esc_textarea($content); ?> </textarea> </p> <p> <label><?php _e('Extra class name:', 'kutetheme'); ?> </label> <input class="widefat" id="<?php echo $this->get_field_id('css'); ?> " name="<?php echo $this->get_field_name('css'); ?> " type="text" value="<?php echo esc_attr($css); ?> " /> </p> <p> <label><?php _e('Min Height On Desktop:', 'kutetheme'); ?> </label> <input class="widefat" id="<?php echo $this->get_field_id('height_desktop'); ?> " name="<?php echo $this->get_field_name('height_desktop'); ?> " type="text" value="<?php echo esc_attr($height_desktop); ?> " /> </p> <p> <label><?php _e('Min Height On Tablet:', 'kutetheme'); ?> </label> <input class="widefat" id="<?php echo $this->get_field_id('height_tablet'); ?> " name="<?php echo $this->get_field_name('height_tablet'); ?> " type="text" value="<?php echo esc_attr($height_tablet); ?> " /> </p> <p> <label><?php _e('Min Height On Mobile:', 'kutetheme'); ?> </label> <input class="widefat" id="<?php echo $this->get_field_id('height_mobile'); ?> " name="<?php echo $this->get_field_name('height_mobile'); ?> " type="text" value="<?php echo esc_attr($height_mobile); ?> " /> </p> </div> <?php }
public function get_mailing_list_choices() { $api_key = g1_get_theme_option('mailchimp', 'api_key', ''); $choices = array(); if (!empty($api_key)) { $api_version = G1_Mailchimp_Module()->get_api_version(); $debug_mode = true === G1_Mailchimp_Module()->get_debug_mode(); if ($api_version === '1.0') { if (!class_exists('MCAPI')) { require_once dirname(__FILE__) . '/lib/MCAPI.class.php'; } $mcapi = new MCAPI($api_key); $mc_lists = $mcapi->lists(); if (empty($mcapi->errorCode) && $mc_lists['total'] > 0) { foreach ($mc_lists['data'] as $mc_list) { $list_id = $mc_list['id']; $list_name = $mc_list['name']; $choices[$list_id] = $list_name; } } } if ($api_version === '2.0') { if (!class_exists('Mailchimp')) { require_once dirname(__FILE__) . '/lib/Mailchimp.php'; } $api = new Mailchimp($api_key, array('debug' => $debug_mode)); try { $res = $api->call('lists/list', array()); if (!empty($res['errors'])) { foreach ($res['errors'] as $error) { $choices[] = $error; } } else { if (abs($res['total']) > 0) { foreach ($res['data'] as $list) { $id = $list['id']; $name = $list['name']; $choices[$id] = $name; } } } } catch (Mailchimp_Error $e) { if ($debug_mode) { $choices[] = $e->getMessage() . ' (code: ' . $e->getCode() . ')'; } } } } else { $choices[] = __('To fetch the list you need to enter your MailChimp Api Key in the theme options panel.', 'g1_theme'); } if (empty($choices)) { $choices[] = __('Some errors occurred while fetching Mailchimp data.', 'g1_theme'); } return $choices; }
function mailchimp_getLists($appKey) { require_once 'mailchimp/MCAPI.class.php'; $api = new MCAPI($appKey); $retval = $api->lists(); if ($api->errorCode) { return null; } else { return $retval['data']; } }
-<?php echo $data['dc']; ?> </strong> which can be passed into most API wrappers. </li> </ol> <h2>Want to see an authorization fail?</h2> The <strong>code</strong> being exchange for an OAuth Access Token expires within 30 seconds - simply refresh this page in a minute. <h3>Want proof? Here are 5 of your lists:</h3> <ol> <?php $apikey = $session['access_token'] . '-' . $data['dc']; $api = new MCAPI($apikey); $api->useSecure(true); $lists = $api->lists('', 0, 5); foreach ($lists['data'] as $list) { ?> <li><?php echo $list['name']; ?> with <?php echo $list['stats']['member_count']; ?> subscribers</li> <?php } ?> </ul> <br/><br/><br/> <a href="<?php
if (!defined('DSN')) { define('DSN', constant('PRIVATE_DSN')); } require_once JETHRO_ROOT . '/include/init.php'; require_once JETHRO_ROOT . '/include/user_system.class.php'; $GLOBALS['user_system'] = new User_System(); $GLOBALS['user_system']->setPublic(); require_once JETHRO_ROOT . '/include/system_controller.class.php'; $GLOBALS['system'] = System_Controller::get(); if (empty($api_key)) { trigger_error("API key not specified", E_USER_ERROR); } $api = new MCAPI($api_key); // Check for / look for a list ID if (empty($list_id)) { $lists = $api->lists(); if (!empty($api->errorMessage)) { trigger_error("Mailchimp API Error calling lists(): " . $api->errorMessage, E_USER_ERROR); } if (count($lists['data']) == 1) { $list_id = $lists['data'][0]['id']; } if (empty($list_id)) { trigger_error("Looked for a single List ID in Mailchimp but couldn't find one", E_USER_NOTICE); print_r($lists); } } if (empty($list_id)) { trigger_error("No List ID found - correct your config within " . __FILE__, E_USER_ERROR); } // Check that the list has the necessary merge vars
function form($instance) { global $javo_tso; $title = isset($instance['title']) ? $instance['title'] : ''; $mailchimp_before_text = isset($instance['mailchimp_before_text']) ? $instance['mailchimp_before_text'] : ''; $mailchimp_after_text = isset($instance['mailchimp_after_text']) ? $instance['mailchimp_after_text'] : ''; $mailchimp_list = isset($instance['mailchimp_list']) ? $instance['mailchimp_list'] : ''; if (!function_exists('curl_init')) { echo __('Curl is not enabled. Please contact your hosting company and ask them to enable CURL.', 'javo_fr'); return; } if (!isset($this->api_key) && empty($this->api_key)) { echo __('You need to enter your MailChimp API_KEY in theme options before using this widget.', 'javo_fr'); return; } if (isset($this->api_key) && !empty($this->api_key)) { include_once JAVO_SYS_DIR . '/functions/MCAPI.class.php'; $api_key = $javo_tso->get('mailchimp_api', '55fe57298275c135cad2e8eb7fe36983-us7'); $mcapi = new MCAPI($api_key); $lists = $mcapi->lists(); } ?> <p> <label for="<?php echo $this->get_field_id('title'); ?> "><?php _e('Title:', 'javo_fr'); ?> </label> <input type="text" class="widefat" id="<?php echo $this->get_field_id('title'); ?> " name="<?php echo $this->get_field_name('title'); ?> " value="<?php echo $title; ?> " /> </p> <p> <label for="<?php echo $this->get_field_id('mailchimp_list'); ?> "><?php _e('Select List:', 'javo_fr'); ?> </label> <select id="<?php echo $this->get_field_id('mailchimp_list'); ?> " name="<?php echo $this->get_field_name('mailchimp_list'); ?> "> <?php foreach ($lists['data'] as $key => $value) { $selected = isset($mailchimp_list) && $mailchimp_list == $value['id'] ? ' selected="selected" ' : ''; ?> <option <?php echo $selected; ?> value="<?php echo $value['id']; ?> "><?php echo $value['name']; ?> </option> <?php } ?> </select> </p> <p> <div><label for="<?php echo $this->get_field_id('mailchimp_before_text'); ?> "><?php echo __('Text before form :', 'javo_fr'); ?> </label></div> <div><textarea class="widefat" id="<?php echo $this->get_field_id('mailchimp_before_text'); ?> " name="<?php echo $this->get_field_name('mailchimp_before_text'); ?> " rows="5"><?php echo $mailchimp_before_text; ?> </textarea></div> </p> <p> <div><label for="<?php echo $this->get_field_id('mailchimp_after_text'); ?> "><?php echo __(' Text after form:', 'javo_fr'); ?> </label></div> <div><textarea class="widefat" id="<?php echo $this->get_field_id('mailchimp_after_text'); ?> " name="<?php echo $this->get_field_name('mailchimp_after_text'); ?> " rows="5"><?php echo $mailchimp_after_text; ?> </textarea></div> </p> <?php }
private static function is_valid_login($username_or_apikey, $password = null) { if ($password) { if (!class_exists("MCAPI_Legacy")) { require_once "api/MCAPI_Legacy.class.php"; } $api = new MCAPI_Legacy(trim($username_or_apikey), trim($password)); } else { if (!class_exists("MCAPI")) { require_once "api/MCAPI.class.php"; } $api = new MCAPI(trim($username_or_apikey), trim($password)); $api->lists(); } $GLOBALS["mc_api_key"] = null; return $api->errorCode ? false : true; }
/** * Processes mailchimp list field. Called by AJAX script. */ public static function field_mailchimp_list_ajax() { if (!class_exists(MCAPI)) { require CH_Manager::$plugin_dir . 'lib/MCAPI.class.php'; } $api_key = $_POST['apikey']; $mcapi = new MCAPI($api_key, false); $lists = $mcapi->lists(); $value = ''; if (!empty($_POST['value'])) { $value = $_POST['value']; } $output = ''; if (is_array($lists) && is_array($lists['data'])) { foreach ($lists['data'] as $entry) { $selected = ''; if ($entry['id'] == $value) { $selected = ' selected="selected"'; } $output .= '<option value="' . $entry['id'] . '"' . $selected . '>' . $entry['name'] . '</option>'; } } echo $output; die; }
/** * Get List from MailChimp */ function get_mailchimp_lists($apikey) { $mailchimp_lists = unserialize(get_transient('seedprod_comingsoon_mailinglist')); if ($mailchimp_lists === false) { require_once 'lib/MCAPI.class.php'; $seedprod_comingsoon_options = get_option('seedprod_comingsoon_options'); if (!isset($apikey)) { $apikey = $seedprod_comingsoon_options['comingsoon_mailchimp_api_key']; } $api = new MCAPI($apikey); $retval = $api->lists(); if ($api->errorCode) { $mailchimp_lists['false'] = __("Unable to load lists, check your API Key!", 'ultimate-coming-soon-page'); } else { foreach ($retval['data'] as $list) { $mailchimp_lists[$list['id']] = 'MailChimp - ' . $list['name']; } set_transient('seedprod_comingsoon_mailinglist', serialize($mailchimp_lists), 86400); } } return $mailchimp_lists; }