-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathos2web_print_send_to_friend.module
executable file
·161 lines (139 loc) · 5.49 KB
/
os2web_print_send_to_friend.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
<?php
/**
* @file
* os2web_print_send_to_friend
*
* PHP version 5
*
* @category OS2Web
* @package OS2Web_Print_Send_to_Friend
* @author Stanislav Kutasevits <stan@bellcom.dk>
* @license http://www.gnu.org/licenses/gpl-2.0.html GNU General Public License, version 2
* @link http://bellcom.dk
*/
/**
* Implements hook_menu().
*/
function os2web_print_send_to_friend_menu() {
$items = array();
$items['dagsorden_punkt/%/print'] = array(
'title' => 'Print Dagsorden Punkt',
'type' => MENU_CALLBACK,
'page callback' => 'os2web_print_send_to_friend_print_bullet_point',
'page arguments' => array(1),
'access arguments' => array(1),
'access callback' => 'os2web_print_send_to_friend_bullet_point_access',
);
$items['dagsorden_punkt/%/send_to_friend_form'] = array(
'title' => 'Send dagsorden punkt til venner',
'type' => MENU_CALLBACK,
'page callback' => 'os2web_print_send_to_friend_send_to_friend_form',
'page arguments' => array(1),
'access arguments' => array(1),
'access callback' => 'os2web_print_send_to_friend_bullet_point_access',
);
$items['dagsorden_punkt/%/send_to_friend_service'] = array(
'title' => 'Dagsorden Punkt Send til venner',
'type' => MENU_CALLBACK,
'page callback' => 'os2web_print_send_to_friend_send_to_friend',
'page arguments' => array(1),
'access arguments' => array(1),
'access callback' => 'os2web_print_send_to_friend_bullet_point_access',
);
return $items;
}
/**
* Creates a light version of the bullet point for printing.
*
* @param int $bullet_point_id
* bullet point id
*/
function os2web_print_send_to_friend_print_bullet_point($bullet_point_id) {
$bullet_point = node_load($bullet_point_id);
if (strcmp($bullet_point->type, 'os2web_meetings_bullet') == 0) {
$html = '<h1>' . $bullet_point->title . '</h1>';
foreach ($bullet_point->field_os2web_meetings_attach['und'] as $attachment_id) {
$attachment = node_load($attachment_id['target_id']);
$html .= '<h3>' . $attachment->title . '</h3>';
$html .= $attachment->field_os2web_meetings_bpa_body['und'][0]['value'];
}
}
return ('<div class="node" id="content">' . $html . '</div>');
}
/**
* Form callback for send_to_friend_form.
*
* Creates a form that allows to send the content of the
* bullet point to an email addess.
*/
function os2web_print_send_to_friend_send_to_friend_form($bullet_point_id) {
// Adding css that tweaks the elements for the modal window.
drupal_add_css(drupal_get_path('module', 'os2web_print_send_to_friend') . '/css/os2web_print_send_to_friend.css');
drupal_add_js(drupal_get_path('module', 'os2web_print_send_to_friend') . '/js/os2web_print_send_to_friend.js');
$html = t('Fill out the fields below and press "Send", when you want to send the e-mail');
$html .= '<form id="send_to_friend_form">';
$html .= '<label>' . t('Your name') . ':</label><input type="text" name="name" />';
$html .= '<label>' . t('Message') . ':</label><textarea name="message"> </textarea>';
$html .= '<label>' . t('Recipients email') . ':</label><input type="text" name="email" id="field_send_to_friend_email" />';
$html .= '<input type="hidden" name="base_url" value="' . $GLOBALS['base_url'] . '" />';
$html .= '<input type="hidden" name="bullet_point_id" id="field_bullet_point_id" value="' . $bullet_point_id . '" />';
$html .= '<button type="submit" id="btn_send_to_friend">Send</button>';
$html .= '<div class="throbber"></div>';
$html .= '</form>';
return '<div class="bullet-point-send-to-friend-form ajax-progress">' . $html . '</div>';
}
/**
* Form access callback.
*/
function os2web_print_send_to_friend_bullet_point_access($bullet_point_id) {
$bullet_point = node_load($bullet_point_id);
if (strcmp($bullet_point->type, 'os2web_meetings_bullet') == 0) {
if ($bullet_point->field_os2web_meetings_bul_closed['und'][0]['value']) {
return FALSE;
}
}
return TRUE;
}
/**
* Form callback for os2web_print_send_to_friend_send_to_friend.
*
* Does the actual sending to the provided email
*
* @param int $bullet_point_id
* bullet point id
*/
function os2web_print_send_to_friend_send_to_friend($bullet_point_id) {
$bullet_point = node_load($bullet_point_id);
// Find the parent meeting. Use to generate an URL.
$query = new EntityFieldQuery();
$meetings = $query
->entityCondition('entity_type', 'node')
->fieldCondition('field_os2web_meetings_bullets', 'target_id', $bullet_point_id, '=')
->execute();
$meeting = !empty($meetings['node']) ? array_pop($meetings['node']) : NULL;
$subject = 'Dagsorden Punkt: ' . $bullet_point->title;
$body = "Hej \n\n" . $_POST['name'] . " har sendt dig et dagsordenspunkt. \n\n";
if ($meeting) {
$body .= "URL:\n" . url('node/' . $meeting->nid, array('absolute' => TRUE)) . "\n\n";
}
$body .= "Med beskeden:\n" . trim($_POST['message']) . "\n\n";
$body .= os2web_print_send_to_friend_print_bullet_point($bullet_point_id);
$from = variable_get('site_mail');
$message = array(
'id' => 'send_to_friend_',
'to' => $_POST['email'],
'subject' => $subject,
'body' => array($body),
'headers' => array(
'From' => $from,
'Sender' => $from,
'Return-Path' => $from,
'Content-Type' => 'text/plain; charset=UTF-8;',
'Content-Transfer-Encoding' => '8Bit',
),
);
$system = drupal_mail_system("os2web_print_send_to_friend", "");
// The format function must be called before calling the mail function.
$message = $system->format($message);
$system->mail($message);
}