function constant_contact_create_object in Constant Contact 6.3
Same name and namespace in other branches
- 6.2 constant_contact.module \constant_contact_create_object()
- 7.3 constant_contact.module \constant_contact_create_object()
Helper method, creates an object of the cc class Used in many functions throughout Handles startup errors
20 calls to constant_contact_create_object()
- constant_contact_add_list_form_submit in ./
admin.lists.inc - Submit handler for the add contact list admin page
- constant_contact_cron in ./
constant_contact.module - Cron job to handle syncing unsubscribers
- constant_contact_delete_list_form_submit in ./
admin.lists.inc - Submit handler for the delete contact list admin page
- constant_contact_download_activity in ./
admin.activities.inc - Download an activity file
- constant_contact_edit_list_form in ./
admin.lists.inc - Displays the manage contact lists page in the admin
File
- ./
constant_contact.module, line 1227
Code
function constant_contact_create_object() {
global $user;
$username = variable_get('cc_username', '');
$password = variable_get('cc_password', '');
module_load_include('php', 'constant_contact', 'class.cc');
$cc = new cc($username, $password);
if (!$username || !$password) {
if (isset($user->uid) && $user->uid) {
if (in_array('Administrator', $user->roles) || intval($user->uid) === 1) {
drupal_set_message(t('Please enter your Constant Contact account username and password'), 'error');
}
}
watchdog('Constant Contact', 'Account settings not entered', array(), WATCHDOG_ERROR);
return false;
}
if (is_object($cc)) {
// we have an object
return $cc;
}
elseif ($cc->http_response_code) {
// oops, problem occured and we have an error code
$error = $cc
->http_get_response_code_error($cc->http_response_code);
watchdog('Constant Contact', '%error', array(
'%error' => $error,
), WATCHDOG_ERROR);
// if we get an unauthorized 401 error code reset the username and password
// if we don't do this the CC account will be temporarily blocked after a few tries
if (intval($cc->http_response_code) === 401) {
variable_set('cc_username', '');
variable_set('cc_password', '');
}
if (isset($user->uid) && $user->uid) {
if (in_array('Administrator', $user->roles) || intval($user->uid) === 1) {
drupal_set_message("Constant Contact - {$error}", 'error');
}
}
}
// return false for everyone else, admin will see an error but users won't
// other functions will fail silently
return false;
}