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

Contents of /contributions/modules/google_groups/google_groups.module

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


Revision 1.4 - (show annotations) (download) (as text)
Sat Oct 17 06:30:53 2009 UTC (5 weeks, 6 days ago) by dragonwize
Branch: MAIN
CVS Tags: DRUPAL-6--2-0, HEAD
Changes since 1.3: +2 -2 lines
File MIME type: text/x-php
Test and fix registration request email.
1 <?php
2 // $Id: google_groups.module,v 1.3 2009/10/17 06:05:27 dragonwize Exp $
3
4 /**
5 * @file
6 * Interactions between Drupal and Google Groups.
7 */
8 ini_set('display_errors', true);
9
10 /**
11 * Implementation of hook_perm().
12 */
13 function google_groups_perm() {
14 return array('administer google groups');
15 }
16
17 /**
18 * Implementation of hook_menu().
19 */
20 function google_groups_menu() {
21 $items = array();
22 $items['admin/settings/googlegroups'] = array(
23 'title' => 'Google Groups',
24 'description' => t('Google Groups module settings.'),
25 'access arguments' => array('administer google groups'),
26 'page callback' => 'google_groups_list_page',
27 'file' => 'google_groups.admin.inc',
28 'type' => MENU_NORMAL_ITEM,
29 );
30 $items['admin/settings/googlegroups/list'] = array(
31 'title' => 'List',
32 'type' => MENU_DEFAULT_LOCAL_TASK,
33 'weight' => -25,
34 );
35 $items['admin/settings/googlegroups/add'] = array(
36 'title' => 'Add a group',
37 'description' => t('Add a new Google Group.'),
38 'access arguments' => array('administer google groups'),
39 'page callback' => 'drupal_get_form',
40 'page arguments' => array('google_groups_add_form'),
41 'file' => 'google_groups.admin.inc',
42 'type' => MENU_LOCAL_TASK,
43 );
44 $items['admin/settings/googlegroups/edit/%'] = array(
45 'title' => 'Edit a group',
46 'description' => t('Edit a Google Group.'),
47 'access arguments' => array('administer google groups'),
48 'page callback' => 'drupal_get_form',
49 'page arguments' => array('google_groups_add_form'),
50 'file' => 'google_groups.admin.inc',
51 'type' => MENU_CALLBACK,
52 );
53 $items['admin/settings/googlegroups/delete/%'] = array(
54 'title' => 'Delete a group',
55 'description' => t('Delete a Google Group.'),
56 'access arguments' => array('administer google groups'),
57 'page callback' => 'drupal_get_form',
58 'page arguments' => array('google_groups_delete_confirm'),
59 'file' => 'google_groups.admin.inc',
60 'type' => MENU_CALLBACK,
61 );
62 return $items;
63 }
64
65 /**
66 * Generate HTML for the google_groups block
67 * @param op the operation from the URL
68 * @param delta offset
69 * @returns block HTML
70 */
71 function google_groups_block($op = 'list', $delta = 0) {
72 switch ($op) {
73 case 'list':
74 return google_groups_block_list();
75
76 case 'view':
77 $settings = variable_get('google_groups_settings', array());
78 $block['subject'] = t('Subscribe to @name', array('@name' => $settings['groups'][$delta]['name']));
79 $block['content'] = theme('google_groups_subscribe_form_block', $delta);
80 return $block;
81 }
82 }
83
84 /**
85 * Returns a list of blocks in a form suitable for hook_block() when $op == list:
86 */
87 function google_groups_block_list() {
88 $settings = variable_get('google_groups_settings', array());
89 $blocks = array();
90 foreach ($settings['groups'] as $delta => $group) {
91 $blocks[$delta]['info'] = t('Google Groups: @name', array('@name' => $group['name']));
92 }
93 return $blocks;
94 }
95
96 /**
97 * Implementation of hook_theme()
98 */
99 function google_groups_theme() {
100 return array(
101 'google_groups_subscribe_form_block' => array(
102 'template' => 'google-groups-subscribe-form-block',
103 'arguments' => array('delta' => NULL),
104 ),
105 );
106 }
107
108 /**
109 * template preprocesser
110 */
111 function template_preprocess_google_groups_subscribe_form_block(&$vars, $hook) {
112 $settings = variable_get('google_groups_settings', array());
113 $group = $settings['groups'][$vars['delta']];
114 $vars['group_id'] = $group['id'];
115 $vars['group_name'] = $group['name'];
116 }
117
118 /**
119 * Implementation of hook_user().
120 */
121 function google_groups_user($op, &$edit, &$account, $category = NULL) {
122 global $user;
123 switch ($op) {
124 case 'register':
125 module_load_include('admin.inc', 'google_groups', 'google_groups');
126 return google_groups_user_register_form();
127 break;
128
129 case 'insert':
130 module_load_include('admin.inc', 'google_groups', 'google_groups');
131 return google_groups_user_register_submit($edit);
132 break;
133
134 case 'view':
135 $settings = variable_get('google_groups_settings', array());
136 $account->content['google_groups'] = array(
137 '#type' => 'user_profile_category',
138 '#title' => 'Email lists',
139 );
140 foreach ($settings['groups'] as $delta => $group) {
141 $account->content['google_groups'][$delta] = array(
142 '#title' => $group['name'],
143 '#type' => 'user_profile_item',
144 '#value' => l(t('Manage your subscription to @name', array('@name' => $group['name'])), 'http://groups.google.com/group/' . $group['id']),
145 );
146 }
147 break;
148 }
149 }
150
151 /**
152 * Send email to google group.
153 *
154 * @param $group_email
155 * Group email address.
156 * @param $from_email
157 * Users email address.
158 * @param $op
159 * Operation. Either subscribe or unsubscribe.
160 */
161 function google_groups_mail($group_email, $from_email, $op = 'subscribe') {
162 $headers = array(
163 'From' => $from_email,
164 'MIME-Version' => '1.0',
165 'Content-Type' => 'text/plain; charset=UTF-8; format=flowed; delsp=yes',
166 'Content-Transfer-Encoding' => '8Bit',
167 'X-Mailer' => 'Drupal',
168 );
169 $message = array(
170 'id' => 'google_groups_' . $op,
171 'to' => $group_email . '+' . $op . '@googlegroups.com',
172 'subject' => $op,
173 'body' => drupal_wrap_mail($op),
174 'headers' => $headers,
175 );
176 return drupal_mail_send($message);
177 }

  ViewVC Help
Powered by ViewVC 1.1.2