-
Notifications
You must be signed in to change notification settings - Fork 1
/
send_to_friends.module
178 lines (159 loc) · 5.14 KB
/
send_to_friends.module
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
<?php
/**
* @file
* Send to friends module main file.
*/
/**
* Implements of hook_permission().
*/
function send_to_friends_permission() {
return array(
'use send to friends form' => array(
'title' => t('Use Send To Friends'),
'description' => t('Use Send To Friends Form'),
),
);
}
/**
* Implements of hook_menu().
*/
function send_to_friends_menu() {
$items = array();
$items['admin/config/content/send_to_friends'] = array(
'title' => 'Send to friends',
'description' => 'Manage Send to friends e-mail messages',
'page callback' => 'drupal_get_form',
'page arguments' => array('send_to_friends_general_settings'),
'access callback' => 'user_access',
'access arguments' => array('administer site configuration'),
'file' => 'send_to_friends.admin.inc',
'file path' => drupal_get_path('module', 'send_to_friends'),
);
$items['send-form'] = array(
'title' => 'Send to friends',
'description' => 'Page with send to friends form',
'page callback' => 'drupal_get_form',
'page arguments' => array('send_to_friends_form'),
'access callback' => 'user_access',
'access arguments' => array('use send to friends form'),
);
$items['send-to-friends/%ctools_js/form'] = array(
'title' => 'Send to friends',
'page callback' => 'send_to_friends_page_callback',
'page arguments' => array(1),
'access arguments' => array('use send to friends form'),
'delivery callback' => 'ajax_deliver',
'theme callback' => 'ajax_base_page_theme',
);
return $items;
}
/**
* Implements hook_block_info().
*/
function send_to_friends_block_info() {
$blocks['send_to_friends'] = array(
'info' => t('Send to friends form'),
'cache' => DRUPAL_NO_CACHE,
);
return $blocks;
}
/**
* Implements hook_block_view().
*/
function send_to_friends_block_view($delta = '') {
$blocks = array();
if (user_access('use send to friends form') && $delta == 'send_to_friends') {
// Include js libraries, add setting for modal window.
SendToFriends::ModalFormSettings();
$blocks['content'] = ctools_modal_text_button(variable_get('send_to_friends_link_text', t('Send this page to your friends')), 'send-to-friends/nojs/form/', t('Send to friends'), 'ctools-modal-sent-to-friends-style');
}
return $blocks;
}
/**
* Page call back for calling modal window.
*
* @param mixed $js
* ctools variable that check js status on browser.
*
* @return array
* commands for modal window.
*/
function send_to_friends_page_callback($js = NULL) {
if (!$js) {
// If js is disabled show message about it.
drupal_set_message(t("Enable javascript on your browser please."));
drupal_goto($_SERVER['HTTP_REFERER']);
}
// Include library.
ctools_include('modal');
$form_state = array(
'title' => t('Send to friends'),
'ajax' => TRUE,
'build_info' => array(
'args' => array(),
),
);
// Include 'send to friend' from.
form_load_include($form_state, 'inc', 'send_to_friends', 'send_to_friends.form');
$commands = array();
$commands = ctools_modal_form_wrapper('send_to_friends_form', $form_state);
$commands[] = ajax_command_invoke(".send_to_friends_page_path", 'send_to_friends_set_page_path');
if (!empty($form_state['executed'])) {
$thy_message_status = variable_get('send_to_friends_thanks_message_in_popup', 'popup');
$commands = array();
if ($thy_message_status == 'popup') {
$commands[] = ajax_command_replace('.send-to-friends-form', variable_get('send_to_friends_thanks_message', t("Thank you.")));
// Simulate a message showing that it will not show after page reload
// on this step we have not '.send-to-friends-form' class.
$commands[] = ajax_command_prepend('.send-to-friends-form', theme('status_messages'));
}
elseif ($thy_message_status == 'status') {
$commands[] = ajax_command_prepend('#content', theme('status_messages'));
$commands[] = ctools_modal_command_dismiss();
}
}
return array('#type' => 'ajax', '#commands' => $commands);
}
/**
* Implements hook_mail().
*
* @param string $key
* Identifier of the mail.
* @param array $message
* Sending data.
* @param array $params
* An array of parameters.
*/
function send_to_friends_mail($key, &$message, $params) {
if ($key == "send_to_friends") {
$message['subject'] = $params['subject'];
$message['body'][] = $params['body'];
$message['headers'] = array_merge($message['headers'], $params['headers']);
}
}
/**
* Implements hook_mollom_form_list().
*/
function send_to_friends_mollom_form_list() {
$forms['send_to_friends_form'] = array(
'title' => t('Send to friends form'),
);
return $forms;
}
/**
* Implemenents hook_mollom_form_info().
*/
function send_to_friends_mollom_form_info($form_id) {
switch ($form_id) {
case 'send_to_friends_form':
$form_info = array(
'elements' => array(
'friend_name' => t("Friend's Name"),
'send-to-friends-mail' => t("Friend's E-mail Address"),
'sender_name' => t('Your name'),
),
);
break;
}
return $form_info;
}