/[drupal]/contributions/modules/undisposable/undisposable.module
ViewVC logotype

Contents of /contributions/modules/undisposable/undisposable.module

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


Revision 1.7 - (show annotations) (download) (as text)
Sat Sep 19 21:28:19 2009 UTC (2 months ago) by mustafau
Branch: MAIN
CVS Tags: HEAD
Changes since 1.6: +7 -7 lines
File MIME type: text/x-php
D7 version.
1 <?php
2 // $Id: undisposable.module,v 1.6 2008/12/14 13:19:15 mustafau Exp $
3
4 /**
5 * @file
6 * Functions for detecting disposable e-mail addresses.
7 *
8 * PHP serialization support is built-in.
9 * If you want to use XML-RPC, JASON or REST services read lib/README.txt
10 *
11 * @see http://undisposable.org/
12 */
13
14 /**
15 * Implement hook_help().
16 */
17 function undisposable_help($path, $arg) {
18 switch ($path) {
19 case 'admin/help#undisposable':
20 return '<p>'. t('Undisposable.org is a collaborative protection system against disposable email addressing (DEA) - services like 10minutemail.com, jetable.com, pookmail.org etc.') .'</p>';
21 }
22 }
23
24 function undisposable_get_library() {
25 return drupal_get_path('module', 'undisposable') .'/lib/undisposable.inc.php';
26 }
27
28 /**
29 * Implement hook_requirements().
30 */
31 function undisposable_requirements($phase) {
32 $requirements = array();
33
34 switch ($phase) {
35 case 'runtime':
36 $requirements['undisposable'] = array('title' => t('Disposable email protection'));
37
38 $library = undisposable_get_library();
39
40 if (file_exists($library)) {
41 // $requirements['undisposable']['severity'] = REQUIREMENT_OK;
42 $requirements['undisposable']['value'] = t('Installed');
43 }
44 else {
45 // $requirements['undisposable']['description'] = t('The <a href="@url" target="_blank">Undisposable</a> client library was not found.', array('@url' => 'http://undisposable.net'));
46 // $requirements['undisposable']['severity'] = REQUIREMENT_OK;
47 $requirements['undisposable']['value'] = t('Built-in');
48 }
49 }
50
51 return $requirements;
52 }
53
54 /**
55 * Implement hook_user_validate().
56 */
57 function undisposable_user_validate(&$edit, $user, $category) {
58 if ($category == 'account') {
59 // Validate the e-mail address.
60 $respond = _undisposable('isDisposableEmail', $edit['mail']);
61 if (isset($respond['stat']) && $respond['stat'] == 'ok' && $respond['email']['isdisposable']) {
62 form_set_error('mail', t('The e-mail address %email has been reported as disposable.', array('%email' => $edit['mail'])));
63 watchdog('user', 'Rejected registration attempt with disposable e-mail address: %name (%email).', array('%name' => $edit['name'], '%email' => $edit['mail']));
64 }
65 }
66 }
67
68 /**
69 * Helper function for querying Undisposable.org database.
70 *
71 * Example:
72 * @code
73 * $respond = _undisposable('isDisposableEmail', $email);
74 * return ($respond['stat'] == 'ok') ? $respond['email']['isdisposable'] : FALSE;
75 * @endcode
76 *
77 * @param $op
78 * Service to query.
79 * @param $arg
80 * Either an e-mail address or hostname.
81 */
82 function _undisposable($op, $arg) {
83 $uri = 'http://www.undisposable.net/services/php/';
84 switch ($op) {
85 case 'isDisposableEmail':
86 $uri .= 'isDisposableEmail/?email=';
87 break;
88 case 'isValidEmail':
89 $uri .= 'isValidEmail/?email=';
90 break;
91 case 'isDisposableHost':
92 $uri .= 'isDisposableHost/?host=';
93 break;
94 default:
95 $uri .= $op;
96 }
97
98 $respond = drupal_http_request($uri . $arg);
99 return @unserialize($respond->data);
100 }

  ViewVC Help
Powered by ViewVC 1.1.2