You are here

constant_contact.install in Constant Contact 6.2

File

constant_contact.install
View source
<?php

require_once 'constant_contact.config.php';

/**
 * @file
 */

/**
 * Check they have entered account details
 */
function constant_contact_check_details() {
  $username = variable_get('constant_contact_username', '');
  $password = variable_get('constant_contact_password', '');
  $api_key = variable_get('constant_contact_api_key', '');
  if ($username && $password && $api_key) {
    return true;
  }
  return false;
}

/**
 * Implementation of hook_requirements().
 * This helps admin know if the module is functioning correctly.
 * Adds status report to the admin area.
 */
function constant_contact_requirements($phase) {
  $requirements = array();

  // try to change the allow_url_fopen setting
  @ini_get('allow_url_fopen', 1);
  if ($phase == 'runtime') {

    // running the module...
    $details = constant_contact_check_details();
    if ($details) {
      $requirements['constant_contact'] = array(
        'value' => t('Configured'),
        'severity' => REQUIREMENT_OK,
        'description' => t('The Constant Contact account settings have been configured'),
      );
    }
    else {
      $requirements['constant_contact'] = array(
        'value' => t('Not configured'),
        'severity' => REQUIREMENT_ERROR,
        'description' => t('The Constant Contact account settings have not been configured, <a href="@settings">configure now</a>', array(
          '@settings' => url('admin/constant_contact/settings'),
        )),
      );
    }
    $requirements['constant_contact']['title'] = t('Constant Contact');
  }
  else {

    // installing...
    if (!extension_loaded('xml')) {
      $requirements['xml'] = array(
        'value' => t('XML extension Not installed'),
        'severity' => REQUIREMENT_ERROR,
        'description' => t('The XML extension for PHP is missing or outdated. Please check the PHP XML documentation for information on how to correct this.'),
      );
      $requirements['xml']['title'] = t('Constant Contact');
    }
    if (!extension_loaded('openssl')) {
      $requirements['openssl'] = array(
        'value' => t('openssl extension Not installed'),
        'severity' => REQUIREMENT_ERROR,
        'description' => t('The openssl extension for PHP is missing or outdated. Please check the PHP openssl documentation for information on how to correct this.'),
      );
      $requirements['openssl']['title'] = t('Constant Contact');
    }
    if (!ini_get('allow_url_fopen')) {
      $requirements['allow_url_fopen'] = array(
        'value' => t('allow_url_fopen setting Not enabled'),
        'severity' => REQUIREMENT_ERROR,
        'description' => t('The allow_url_fopen setting is not enabled in your php.ini config file'),
      );
      $requirements['allow_url_fopen']['title'] = t('Constant Contact');
    }
  }
  return $requirements;
}

/**
 * Installs the variables we need for the module
 */
function constant_contact_install() {
  variable_set('constant_contact_username', '');
  variable_set('constant_contact_password', '');
  variable_set('constant_contact_api_key', '');
  variable_set('constant_contact_custom_fields', CONSTANT_CONTACT_CUSTOM_FIELDS);
  variable_set('constant_contact_show_on_register', CONSTANT_CONTACT_SHOW_ON_REGISTER);
  variable_set('constant_contact_show_list_selection', CONSTANT_CONTACT_SHOW_LIST_SELECTION);
  variable_set('constant_contact_signup_lists_description', CONSTANT_CONTACT_SIGNUP_LISTS_DESCRIPTION);
  variable_set('constant_contact_signup_title', CONSTANT_CONTACT_SIGNUP_TITLE);
  variable_set('constant_contact_signup_description', CONSTANT_CONTACT_SIGNUP_DESCRIPTION);
  variable_set('constant_contact_show_firstname', CONSTANT_CONTACT_SHOW_FIRSTNAME);
  variable_set('constant_contact_show_lastname', CONSTANT_CONTACT_SHOW_LASTNAME);
  variable_set('constant_contact_show_job_title', CONSTANT_CONTACT_SHOW_JOB_TITLE);
  variable_set('constant_contact_show_company_name', CONSTANT_CONTACT_SHOW_COMPANY_NAME);
}

/**
 * Remvoves the variables we have set for the module
 */
function constant_contact_uninstall() {
  variable_del('constant_contact_username');
  variable_del('constant_contact_password');
  variable_del('constant_contact_api_key');
  variable_del('constant_contact_custom_fields');
  variable_del('constant_contact_show_on_register');
  variable_del('constant_contact_show_list_selection');
  variable_del('constant_contact_signup_lists_description');
  variable_del('constant_contact_signup_title');
  variable_del('constant_contact_signup_description');
  variable_del('constant_contact_show_firstname');
  variable_del('constant_contact_show_lastname');
  variable_del('constant_contact_show_job_title');
  variable_del('constant_contact_show_company_name');
  variable_del('constant_contact_lists');
  cache_clear_all('variables', 'cache');
}

/**
 * Implementation of hook_disable().
 */
function constant_contact_disable() {
  drupal_set_message(t('The Constant Contact module has been disabled, to upgrade please uninstall.'));
}

/**
 * Implementation of hook_enable().
 */
function constant_contact_enable() {
  drupal_set_message(t('The Constant Contact module has been enabled, please visit the settings page to configure your account details.'));
}

Functions

Namesort descending Description
constant_contact_check_details Check they have entered account details
constant_contact_disable Implementation of hook_disable().
constant_contact_enable Implementation of hook_enable().
constant_contact_install Installs the variables we need for the module
constant_contact_requirements Implementation of hook_requirements(). This helps admin know if the module is functioning correctly. Adds status report to the admin area.
constant_contact_uninstall Remvoves the variables we have set for the module