Skip to content
This repository has been archived by the owner on Feb 4, 2021. It is now read-only.

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
ramlev committed Dec 30, 2010
0 parents commit 9974391
Show file tree
Hide file tree
Showing 9 changed files with 352 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
@@ -0,0 +1 @@
*swp
135 changes: 135 additions & 0 deletions APSIS.class.php
@@ -0,0 +1,135 @@
<?php

// Apsis Newsletter Pro v2 - PHP5 example code

// Include NUSOAP classes
@require_once(libraries_get_path('nusoap') .'/nusoap.php');

// Exceptions
class AnpSoapClientException extends Exception
{
public function __construct($message = null, $code = 0)
{
parent::__construct($message, $code);
}
}

// NUSOAP wrapper for ANP API
class AnpSoapclient
{
protected $service_username = null, $service_password = null;
protected $soap_client = null;

public function __construct($username, $password, $wsdl = 'http://api.anpdm.com/ExternalAPIService.asmx?wsdl')
{
// Init soapclient
$this->soap_client = $soap_client = new nusoap_client($wsdl, 'wsdl');
if(($soap_error = $soap_client->getError())) $this->ThrowError($soap_error, -1, true);

// Set authentication
$this->SetAuthenticationDetails($username, $password);
}

// public array Call( string method, array arguments )
// @method - the method to call
// @arguments - assoc array of arguments ex; ('Parameter1' => 'Value1', 'Parameter2' => 'Value2') ..
public function Call($method, $arguments = array())
{
// Init
$soap_client = $this->soap_client;

// Append anp username and password to parameters vector
$arguments = array_merge(array('strUsername' => $this->service_username, 'strPassword' => $this->service_password), (array) $arguments);
$soap_result = @$soap_client->Call($method, array('parameters' => $arguments), '', '', false, true);

// Print error/return result
return ($soap_client->fault ? $this->ThrowError($soap_result, -2, true) :
(($soap_error = $soap_client->getError()) ? $this->ThrowError($soap_error, -3, true) : $soap_result));
}

protected function ThrowError($description, $error_code = -1, $dump_description = false)
{
if($dump_description)
{
@ob_start(); print_r($description);
$description = @str_replace(chr(32) . chr(32), "&nbsp;", @nl2br(@ob_get_clean()));
}
throw new AnpSoapClientException($description, $error_code);
}

protected function SetAuthenticationDetails($username, $password)
{
if((strlen($username) == 0) || (strlen($password) == 0) || $username == null || $password == null)
$this->ThrowError("Username or Password empty!", -5);

$this->service_username = $username;
$this->service_password = $password;
}
}

// Demographics class
class AnpDemographicsData extends BaseDictionary
{
public function __construct($demographics_data = null)
{
// Call base constructor
parent::__construct();

// Populate demographics data
if($demographics_data != null && count($demographics_data) > 0)
foreach($demographics_data as $key => $val) $this->Add($key, $val);
}

public function GetKeys($delim = ';')
{
return implode($delim, array_keys($this->dictionary));
}

public function GetValues($delim = ';')
{
return implode($delim, array_values($this->dictionary));
}

public function Remove($key)
{
parent::Remove("DD" . $key);
}

public function Add($key, $value)
{
parent::Add("DD" . $key, $value);
}
}

class BaseDictionary
{
protected $dictionary = null;

public function __construct()
{
$this->dictionary = array();
}

public function Add($key, $value)
{
if($this->ContainsKey($key)) throw new Exception("Dictionary already contains key {$key}");
$this->dictionary[$key] = $value;
}

public function Remove($key)
{
unset($this->dictionary[$key]);
}

public function Get($key)
{
return $this->dictionary[$key];
}

public function ContainsKey($key)
{
return array_key_exists($key, $this->dictionary);
}
}

?>
96 changes: 96 additions & 0 deletions emf_apsis.api.inc
@@ -0,0 +1,96 @@
<?php

/**
* @file
* Apsis API call wrappers
*
* @author Hasse Ramlev Hansen <hasse@reload.dk>
*/

@require_once(drupal_get_path('module', 'emf_apsis') .'/APSIS.class.php');

/**
* Implements hook_api_subscribe()
*/
function emf_apsis_api_subscribe($email, $fields, $lid) {
$anp = new AnpSoapclient(variable_get('emf_apsis_api_username', ''), variable_get('emf_apsis_api_password', ''));
$return = $anp->Call('InsertSubscriber', array(
'strEmail' => $email,
'strName' => '',
'strFormat' => '',
'strMailingListID' => $lid,
));
}

/**
* Implements hook_api_unsubscribe()
*/
function emf_apsis_api_unsubscribe($email, $lid) {
$anp = new AnpSoapclient(variable_get('emf_apsis_api_username', ''), variable_get('emf_apsis_api_password', ''));
$return = $anp->Call('DeleteSubscriber', array(
'strEmail' => $email,
'strMailingListID' => $lid,
));
}

/**
* Implements hook_api_get_subscribers_unsubscribed()
*/
function emf_apsis_api_get_subscribers_unsubscribed($date = 0, $lid = NULL) {
return array();
}

/**
* Implements hook_api_get_subscribers_subscribed()
*/

function emf_apsis_api_get_subscribers_subscribed($date = 0, $lid = NULL) {
$subscribers = array();
$anp = new AnpSoapclient(variable_get('emf_apsis_api_username', ''), variable_get('emf_apsis_api_password', ''));
$all_subscribers = $anp->call('GetSubscribers', array(
'strMailingListId' => $lid,
));

foreach ($all_subscribers['GetSubscribersResult']['diffgram']['NewDataSet']['Subscriber'] as $subscriber) {
$subscribers[] = $subscriber['Email'];
}
return $subscribers;
}

/**
* Implements hook_api_get_lists()
*/
function emf_apsis_api_get_lists() {
$lists = array();
$anp = new AnpSoapclient(variable_get('emf_apsis_api_username', ''), variable_get('emf_apsis_api_password', ''));
$mailinglists = $anp->call('GetMailingLists');

foreach ($mailinglists['GetMailingListsResult']['diffgram']['NewDataSet']['MailingList'] as $list) {
$lists[$list['MailingListID']] = (object) array(
'lid' => $list['MailingListID'],
'name_api' => $list['Name'],
);
}
return $lists;
}

/**
* Implements hook_api_get_custom_fields()
*/
function emf_apsis_api_get_custom_fields($lid) {
$anp = new AnpSoapclient(variable_get('emf_apsis_api_username', ''), variable_get('emf_apsis_api_password', ''), 'http://api.anp.se/anp.asmx?wsdl');
}

/**
* Implements hook_api_get_system_time()
*/
function emf_apsis_api_get_system_time() {
return time() - 3600;
}

/**
* Implements hook_api_unix_to_service_time()
*/
function emf_apsis_api_unix_to_service_time($date) {
return $date;
}
7 changes: 7 additions & 0 deletions emf_apsis.info
@@ -0,0 +1,7 @@
name = EMF Apsis Plugin
description = E-mail Marketing Framework plugin for Apsis integration.
version = 0.8beta
core = 6.x
package = E-mail Marketing Framework
dependencies[] = emf
dependencies[] = libraries
25 changes: 25 additions & 0 deletions emf_apsis.install
@@ -0,0 +1,25 @@
<?php

/**
* Implementation of hook_requirements()
*/
function emf_apsis_requirements($phase) {
$requirements = array();
$t = get_t();

if ($phase == 'runtime') {

// Raise warning if Apsis API nformation has not been set yet.
if (trim(variable_get('emf_apsis_api_username', '')) == '' || trim(variable_get('emf_apsis_api_password', '')) == '') {
$requirements['emf_apsis'] = array(
'title' => $t('Apsis API Information'),
'description' => $t('Your Apsis API information has not been set yet. Please specify it on the <a href="@url">Apsis settings page</a>.', array('@url' => url('admin/settings/emf_apsis'))),
'severity' => REQUIREMENT_ERROR,
'value' => $t('Not configured'),
);
}
}

return $requirements;
}

36 changes: 36 additions & 0 deletions emf_apsis.module
@@ -0,0 +1,36 @@
<?php

/**
* Drupal hooks
*
* @author Hasse Ramlev Hansen
*/

/**
* Implementation of hook_menu()
*/
function emf_apsis_menu() {

// settings
$items['admin/settings/emf_apsis'] = array(
'title' => 'Apsis',
'description' => 'Configure Apsis settings.',
'page callback' => 'drupal_get_form',
'page arguments' => array('emf_apsis_settings'),
'access arguments' => array('administer site configuration'),
'file' => 'emf_apsis.settings.inc',
);

return $items;
}

/**
* Implementation of hook_emf_info()
*/
function emf_apsis_emf_info() {
return array(
'name' => 'Apsis',
'file' => 'emf_apsis.api.inc',
);
}

32 changes: 32 additions & 0 deletions emf_apsis.settings.inc
@@ -0,0 +1,32 @@
<?php

/**
* @file
* Settings functions and callbacks.
*
* @author Hasse R. Hansen
*/

/**
* Generate a form which handles Apsis login information
*/
function emf_apsis_settings() {
$form = array();

$form['emf_apsis_api_username'] = array(
'#type' => 'textfield',
'#title' => t('API Username'),
'#description' => t('Your Apsis API Username.'),
'#default_value' => variable_get('emf_apsis_api_username', ''),
'#required' => TRUE,
);
$form['emf_apsis_api_password'] = array(
'#type' => 'textfield',
'#title' => t('API Password'),
'#description' => t('Your Apsis API Password.'),
'#default_value' => variable_get('emf_apsis_api_password', ''),
'#required' => TRUE,
);

return system_settings_form($form);
}
10 changes: 10 additions & 0 deletions install.txt
@@ -0,0 +1,10 @@
Installation guide

* Download http://sourceforge.net/projects/nusoap/ and extract to /sites/all/libraries/nusoap
* drush dl emf libraries
* git clone git://github.com/reload/emf_apsis.git sites/all/modules/emf_apsis
* drush en emf_apsis (should enable emf, emf_apsis and libraries modules)
* Go to /admin/settings/emf_apsis and enter the required information.
* Define which user roles who can subscribe to lists (/admin/user/permissions)
* Show the 'E-mail Marketing Framework : common subscription block' somewhere on the website, and you're ready to go.

10 changes: 10 additions & 0 deletions readme.md
@@ -0,0 +1,10 @@
# E-mail Marketing Framework plugin for Apsis integration

Apsis is a hosted email newsletter manager. The Apsis EMF module extends the E-mail Marketing Framework module to provide user account synchronization with Drupal and simple sign-up/list subscription management for users.

This module requires the E-mail Marketing Framework and an account at Apsis.

See the install.txt for more information.

This is an early beta, the dependency to the nusoap library will be removed in the near future.

0 comments on commit 9974391

Please sign in to comment.