function validate_cfg() { $OSCOM_Db = Registry::get('Db'); $this->valid_cfg = false; if (empty($this->apikey)) { $this->complain('You have not entered your API key. Please read the installation instructions.'); return; } if (!$this->key_valid) { $GLOBALS["mc_api_key"] = $this->apikey; $api = new MCAPI('notused', 'notused'); $res = $api->ping(); if ($api->errorMessage != '') { $this->complain('Server said: "' . $api->errorMessage . '". Your API key is likely invalid. Please read the installation instructions.'); return; } else { $this->key_valid = true; $OSCOM_Db->save('configuration', ['configuration_value' => 'true'], ['configuration_key' => 'MODULE_HEADER_TAGS_MAILCHIMP_360_KEY_VALID']); if (empty($this->store_id)) { $this->store_id = md5(uniqid(rand(), true)); $OSCOM_Db->save('configuration', ['configuration_value' => $this->store_id], ['configuration_key' => 'MODULE_HEADER_TAGS_MAILCHIMP_360_STORE_ID']); } } } if (empty($this->store_id)) { $this->complain('Your Store ID has not been set. This is not good. Contact support.'); } else { $this->valid_cfg = true; } }
function validate_cfg() { $this->valid_cfg = false; if (empty($this->apikey)) { $this->complain('You have not entered your API key. Please read the installation instructions.'); return; } if (!$this->key_valid) { $GLOBALS["mc_api_key"] = $this->apikey; $api = new MCAPI('notused', 'notused'); $res = $api->ping(); if ($api->errorMessage != '') { $this->complain('Server said: "' . $api->errorMessage . '". Your API key is likely invalid. Please read the installation instructions.'); return; } else { $this->key_valid = true; tep_db_query("update " . TABLE_CONFIGURATION . " set configuration_value = 'true' where configuration_key = 'MODULE_HEADER_TAGS_MAILCHIMP_360_KEY_VALID'"); if (empty($this->store_id)) { $this->store_id = md5(uniqid(rand(), true)); tep_db_query("update " . TABLE_CONFIGURATION . " set configuration_value = '" . $this->store_id . "' where configuration_key = 'MODULE_HEADER_TAGS_MAILCHIMP_360_STORE_ID'"); } } } if (empty($this->store_id)) { $this->complain('Your Store ID has not been set. This is not good. Contact support.'); } else { $this->valid_cfg = true; } }
function MCauth() { if (!isset($_SESSION['MCping'])) { jimport('joomla.html.parameter'); jimport('joomla.application.component.helper'); $params =& JComponentHelper::getParams('com_joomailermailchimpintegration'); $paramsPrefix = version_compare(JVERSION, '1.6.0', 'ge') ? 'params.' : ''; $MCapi = $params->get($paramsPrefix . 'MCapi'); $MC = new MCAPI($MCapi); $ping = $MC->ping(); $_SESSION['MCping'] = $ping; } else { $ping = $_SESSION['MCping']; } return $ping; }
function validate_mailchimp_key($key) { require_once PREMISE_LIB_DIR . 'mailchimp_api/MCAPI.class.php'; $mailchimp = new MCAPI($key); if (!$mailchimp->ping()) { return array('error' => __('Invalid MailChimp API key.', 'premise')); } return true; }
function tfuse_ajax_newsletter_save_mailchimp_api_key() { #MailChimp tf_can_ajax(); require_once dirname(__FILE__) . '/library/MCAPI.class.php'; $api_key = $this->request->POST('api_key'); $api = new MCAPI($api_key); $api->ping(); if ($api->errorCode) { tfjecho(array('status' => -1, 'message' => __('API key is invalid.', 'tfuse'))); } else { $this->model->set_mc_key($api_key); tfjecho(array('status' => 1)); } die; }
function updateSettings($variables) { if (!isset($variables["mailchimp_secure"])) { $variables["mailchimp_secure"] = 0; } /** * Check for a valid api key. */ if ($variables["apikey_changed"] == "1" && $variables["mailchimp_apikey"] != "") { include_once "include/MCAPI.class.php"; $api = new MCAPI($variables["mailchimp_apikey"]); $api->ping(); if ($api->errorCode) { unset($variables["mailchimp_apikey"]); $this->updateErrorMessage = "Unable to change the MailChimp apikey: " . $api->errorMessage . " (" . $api->errorCode . ")"; return $variables; } //end if } //end if /** * Check for valid list id */ if ($variables["apilist_changed"] == "1" && $variables["mailchimp_list_id"] != "") { include_once "include/MCAPI.class.php"; /** * Check to see if api is already defined (from a possible api key check) * If not, define it and check the key/connection */ if (!isset($api)) { $api = new MCAPI($variables["mailchimp_apikey"]); $api->ping(); if ($api->errorCode) { unset($variables["mailchimp_list_id"]); $this->updateErrorMessage = "Unable to change the MailChimp list id: " . $api->errorMessage . " (" . $api->errorCode . ")"; return $variables; } //end if } //end if /** * Look up the lists */ $lists = $api->lists(); if ($api->errorCode) { unset($variables["mailchimp_list_id"]); $this->updateErrorMessage = "Unable to change the MailChimp list id: " . $api->errorMessage . " (" . $api->errorCode . ")"; return $variables; } else { /** * Check to see if list id is valid */ $validId = false; foreach ($lists as $list) { if ($list["id"] == $variables["mailchimp_list_id"]) { $validId = true; break; } } //endif if (!$validId) { unset($variables["mailchimp_list_id"]); $this->updateErrorMessage = "Unable to change the MailChimp list id: the id does not match a valid id on the account."; return $variables; } else { /** * Check to see if the list has a uuid. */ $hasUuid = false; $hasCompany = false; $hasType = false; $mergeVars = $api->listMergeVars($variables["mailchimp_list_id"]); if ($api->errorCode) { unset($variables["mailchimp_list_id"]); $this->updateErrorMessage = "Unable to change the MailChimp list id: " . $api->errorMessage . " (" . $api->errorCode . ")"; return $variables; } //end if $req = array(); foreach ($mergeVars as $mergeVar) { switch ($mergeVar["tag"]) { case "UUID": $hasUuid = true; break; case "COMPANY": $hasCompany = true; break; case "TYPE": $hasType = true; break; } //end switch } //end foreach /** * If it doesn't have a uuid field, create it. */ if (!$hasUuid) { $req = array("req" => true, "public" => false, "field_type" => "text"); $api->listMergeVarAdd($variables["mailchimp_list_id"], "UUID", "phpBMS unique user id", $req); if ($api->errorCode) { unset($variables["mailchimp_list_id"]); $this->updateErrorMessage = "Unable to change the MailChimp list id: " . $api->errorMessage . " (" . $api->errorCode . ")"; return $variables; } //end if } //end if /** * If it doesn't have a company field, create it. */ if (!$hasCompany) { $req = array("req" => false, "public" => true, "field_type" => "text"); $api->listMergeVarAdd($variables["mailchimp_list_id"], "COMPANY", "Company", $req); if ($api->errorCode) { unset($variables["mailchimp_list_id"]); $this->updateErrorMessage = "Unable to change the MailChimp list id: " . $api->errorMessage . " (" . $api->errorCode . ")"; return $variables; } //end if } //end if /** * If it doesn't have a type field, create it. */ if (!$hasType) { $req = array("req" => false, "public" => true, "field_type" => "text"); $api->listMergeVarAdd($variables["mailchimp_list_id"], "TYPE", "Type", $req); if ($api->errorCode) { unset($variables["mailchimp_list_id"]); $this->updateErrorMessage = "Unable to change the MailChimp list id: " . $api->errorMessage . " (" . $api->errorCode . ")"; return $variables; } //end if } //end if /** * If the date list id has changed, the last sync date must be reset: */ $variables["mailchimp_last_sync_date"] = ""; } //end if } //end if } //end if return $variables; }
public function getMailChimpTimestamp() { $api = new MCAPI($this->apikey); $retval = $api->ping(); if ($api->errorCode) { SS_Log::log("Unable to load lists()! Error Code = " . $api->errorCode . " Error Msg = " . $api->errorMessage, SS_Log::ERR); return false; } else { return gmdate('Y-m-d H:i:s', strtotime($retval['headers']['Date'])); } }