/[drupal]/contributions/modules/dcl_importer/dcl_importer_api.inc
ViewVC logotype

Contents of /contributions/modules/dcl_importer/dcl_importer_api.inc

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.2 - (show annotations) (download) (as text)
Sun Jul 12 03:00:18 2009 UTC (4 months, 2 weeks ago) by hadsie
Branch: MAIN
CVS Tags: HEAD
Branch point for: DRUPAL-6--1, DRUPAL-6--2
Changes since 1.1: +37 -8 lines
File MIME type: text/x-php
 * #268482: Converting simple email array to an associative array with email and name
(more can be added as required) (item 1)
 * #268482: Removing hardcoding of the drupal_goto('invite') (item 4)
1 <?php
2 // $Id: dcl_importer_api.inc,v 1.1 2009/07/10 00:01:51 hadsie Exp $
3 /**
4 *
5 * @file
6 * Contains the DCL Importer API calls
7 *
8 */
9
10 function dcl_importer_authenticate($provider, $username, $password) {
11 include_once('OpenInviter/openinviter.php');
12 $inviter = new OpenInviter();
13 $inviter->startPlugin($provider);
14 $internal = $inviter->getInternalError();
15
16 $errors = array();
17 if ($internal) {
18 $errors['inviter'] = $internal;
19 }
20 elseif (!$inviter->login($username, $password)) {
21 $internal = $inviter->getInternalError();
22 $errors['login'] = $internal ? $internal : t('Login failed. Please check the email and password you have provided and try again later');
23 }
24
25 return array($inviter, $errors);
26 }
27
28 function dcl_importer_get_contacts($inviter) {
29 $contacts = $inviter->getMyContacts();
30 if ($contacts === FALSE) {
31 drupal_set_message(t('Unable to get contacts.'), 'error');
32 }
33 $inviter->stopPlugin(TRUE);
34
35 // Cleanup the results
36 $contact_list = array();
37 foreach ($contacts as $email => $name) {
38 $email = trim($email);
39 if ($email) {
40 $contact_list[] = array(
41 'mail' => $email,
42 'name' => $name,
43 );
44 }
45 }
46
47 return $contact_list;
48 }
49
50 /**
51 * Get a list of providers
52 *
53 * @param $all - If TRUE then returns all of the possible providers, if FALSE
54 * then returns only those providers that have been selected in the settings
55 * page.
56 * @return
57 * an array containing available plugins in the form of
58 * (plugin_type, plugin_name) pairs, for example:
59 * Array(('gmail', 'GMail'), ('msn', 'MSN'))
60 *
61 */
62 function dcl_importer_get_providers($all = FALSE) {
63 include_once('OpenInviter/openinviter.php');
64 $inviter = new OpenInviter();
65
66 $plugin_settings = variable_get('openinviter_plugins', NULL);
67 $plugin_arr = array();
68 foreach ($inviter->getPlugins() as $plugin_type => $plugins) {
69 foreach ($plugins as $plugin => $plugin_details) {
70 if ($all ||
71 ($plugin_settings == NULL || $plugin_settings[$plugin])) {
72 $plugin_arr[$plugin] = $plugin_details['name'];
73 }
74 }
75 }
76 return $plugin_arr;
77 }
78
79 /**
80 * @return a list with two values:
81 * 1. new contacts
82 * 2. contacts that exist in the user table
83 *
84 * The two arrays returned are of the same format as get_contacts;
85 */
86 function dcl_importer_split_users($contacts) {
87 if (empty($contacts)) {
88 return $contacts;
89 }
90
91 $emails = array();
92 foreach ($contacts as $contact) {
93 $emails[] = $contact['mail'];
94 }
95
96 $query = db_query(
97 'SELECT uid, name, mail FROM {users} WHERE mail in (' . implode(', ', array_fill(0, count($emails), "'%s'")) . ')',
98 $emails);
99
100 $exists = array();
101 $emails = array();
102 while ($user = db_fetch_object($query)) {
103 $exists[$user->uid] = array(
104 'mail' => $user->mail,
105 'name' => $user->name,
106 );
107 $emails[] = $user->mail;
108 }
109
110 // Remove existing emails from the original $contacts array
111 $new = array();
112 foreach ($contacts as $contact) {
113 if (!in_array($contact['mail'], $emails)) {
114 $new[] = $contact;
115 }
116 }
117
118 return array($new, $exists);
119 }

  ViewVC Help
Powered by ViewVC 1.1.2