-
Notifications
You must be signed in to change notification settings - Fork 0
/
vozmob_envaya.module
52 lines (51 loc) · 2.31 KB
/
vozmob_envaya.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
<?php
/**
* Implements hook_sms_incoming().
*/
function vozmob_envaya_sms_incoming($op, $number, $message, $options) {
global $user;
if ($op != 'process') {
return;
}
watchdog('vozmob_envaya', '<pre>' . check_plain(print_r($options['sms_envaya_action'], TRUE)) . '</pre>', NULL);
$node->type = 'article';
node_object_prepare($node);
$node->title = truncate_utf8($message, 140, TRUE, TRUE, 10);
$node->uid = $user->uid;
$node->language = LANGUAGE_NONE;
$node->body[$node->language][0]['format'] = 'filtered_html';
$node->body[$node->language][0]['summary'] = text_summary($message);
$node->body[$node->language][0]['value'] = $message;
if ($options['sms_envaya_action']->mms_parts) {
$allowed_extensions = '3g2 3gp 3gpp amr asc avi bmp gif jpeg jpg m4a m4v mp3 mp4 mpeg mpg png qcelp qcp smil txt wav wbmp';
$directory = 'public://' . gmdate('Y/m/d');
file_prepare_directory($directory, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS);
foreach ($options['sms_envaya_action']->mms_parts as $mms_part) {
if (file_get_mimetype($mms_part->filename) == 'application/octet-stream') {
$mapping = file_default_mimetype_mapping();
$mapping['mimetypes'] = array_flip($mapping['mimetypes']);
$mapping['extensions'] = array_flip($mapping['extensions']);
if (isset($mapping['mimetypes'][$mms_part->type])) {
$_FILES['files']['name'][$mms_part->form_name] .= '.' . $mapping['extensions'][$mapping['mimetypes'][$mms_part->type]];
}
}
$file = file_save_upload($mms_part->form_name, array('file_validate_extensions' => array($allowed_extensions)), $directory, FILE_EXISTS_RENAME);
if ($file) {
$field = preg_match('!^image/(gif|jpeg|png)$!', $file->filemime) ? 'field_image' : 'field_file';
$node->{$field}[$node->language][] = array(
'display' => (int) ($file->filemime != 'text/plain' && $file->filemime != 'application/smil'),
'fid' => $file->fid,
'filename' => $file->filename,
'filemime' => $file->filemime,
'uid' => 1,
'uri' => $file->uri,
'status' => 1,
);
}
else {
watchdog('vozmob_envaya', 'file_save_upload() failed for %mms_part.', array('%mms_part' => print_r($mms_part, TRUE)), WATCHDOG_ERROR);
}
}
}
node_save($node);
}