Skip to content

Commit 671030d

Browse files
committed
Messages with images
Basic support for messages with images for "say" function (and events to other modules).
1 parent eb39327 commit 671030d

File tree

4 files changed

+303
-277
lines changed

4 files changed

+303
-277
lines changed

Diff for: lib/messages.class.php

+12-2
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,18 @@ function say($ph, $level = 0, $member_id = 0, $source = '')
145145
verbose_log("SAY (level: $level; member: $member; source: $source): " . $ph);
146146
//DebMes("SAY (level: $level; member: $member; source: $source): ".$ph,'say');
147147

148+
$image = '';
149+
if (preg_match('/image:([\w\d\_\/\-\.]+)/is',$ph,$m)) {
150+
if (file_exists($m[1])) {
151+
$image=$m[1];
152+
}
153+
$ph = str_replace($m[0],'',$ph);
154+
$ph = preg_replace('/\n+$/','',$ph);
155+
}
156+
148157
$rec = array();
149158
$rec['MESSAGE'] = $ph;
159+
$rec['IMAGE'] = $image;
150160
$rec['ADDED'] = date('Y-m-d H:i:s');
151161
$rec['ROOM_ID'] = 0;
152162
$rec['MEMBER_ID'] = $member_id;
@@ -156,7 +166,7 @@ function say($ph, $level = 0, $member_id = 0, $source = '')
156166
$rec['ID'] = SQLInsert('shouts', $rec);
157167

158168
if ($member_id) {
159-
$processed = processSubscriptionsSafe('COMMAND', array('level' => $level, 'message' => $ph, 'member_id' => $member_id, 'source' => $source));
169+
$processed = processSubscriptionsSafe('COMMAND', array('level' => $level, 'message' => $ph, 'member_id' => $member_id, 'source' => $source, 'image' => $image));
160170
return;
161171
}
162172

@@ -184,7 +194,7 @@ function say($ph, $level = 0, $member_id = 0, $source = '')
184194
}
185195

186196

187-
processSubscriptionsSafe('SAY', array('level' => $level, 'message' => $ph, 'member_id' => $member_id)); //, 'ignoreVoice'=>$ignoreVoice
197+
processSubscriptionsSafe('SAY', array('level' => $level, 'message' => $ph, 'member_id' => $member_id, 'image' => $image)); //, 'ignoreVoice'=>$ignoreVoice
188198

189199
if (defined('SETTINGS_HOOK_AFTER_SAY') && SETTINGS_HOOK_AFTER_SAY != '') {
190200
eval(SETTINGS_HOOK_AFTER_SAY);

Diff for: modules/connect/connect.class.php

+34-22
Original file line numberDiff line numberDiff line change
@@ -38,16 +38,16 @@ function __construct()
3838
function saveParams($data = 0)
3939
{
4040
$p = array();
41-
if (IsSet($this->id)) {
41+
if (isset($this->id)) {
4242
$p["id"] = $this->id;
4343
}
44-
if (IsSet($this->view_mode)) {
44+
if (isset($this->view_mode)) {
4545
$p["view_mode"] = $this->view_mode;
4646
}
47-
if (IsSet($this->edit_mode)) {
47+
if (isset($this->edit_mode)) {
4848
$p["edit_mode"] = $this->edit_mode;
4949
}
50-
if (IsSet($this->tab)) {
50+
if (isset($this->tab)) {
5151
$p["tab"] = $this->tab;
5252
}
5353
return parent::saveParams($p);
@@ -100,10 +100,10 @@ function run()
100100
} else {
101101
$this->usual($out);
102102
}
103-
if (IsSet($this->owner->action)) {
103+
if (isset($this->owner->action)) {
104104
$out['PARENT_ACTION'] = $this->owner->action;
105105
}
106-
if (IsSet($this->owner->name)) {
106+
if (isset($this->owner->name)) {
107107
$out['PARENT_NAME'] = $this->owner->name;
108108
}
109109
$out['VIEW_MODE'] = $this->view_mode;
@@ -130,11 +130,12 @@ function processSubscription($event_name, &$details)
130130
if ($event_name == 'SAY') {
131131
$level = (int)$details['level'];
132132
$message = $details['message'];
133-
$this->sendMessageToConnect($message, $level);
133+
$image = $details['image'];
134+
$this->sendMessageToConnect($message, $level, $image);
134135
}
135136
}
136137

137-
function sendMessageToConnect($message, $level)
138+
function sendMessageToConnect($message, $level = 0, $image = '')
138139
{
139140
$this->getConfig();
140141
$connect_username = $this->config['CONNECT_USERNAME']; //username
@@ -148,9 +149,20 @@ function sendMessageToConnect($message, $level)
148149
'message' => $message,
149150
'level' => (int)$level
150151
);
152+
if ($image != '' && file_exists($image)) {
153+
if (function_exists('curl_file_create')) { // php 5.6+
154+
$size = getimagesize($image);
155+
$cfile = curl_file_create($image, $size['mime'], basename($image));
156+
} else { //
157+
$cfile = '@' . realpath($image);
158+
}
159+
$fields['image'] = $cfile;
160+
}
161+
//DebMes("sending data: " . json_encode($fields), 'connect_msg');
151162
$url = 'https://connect.smartliving.ru/sync_device_data.php';
152163
$ch = curl_init();
153164
curl_setopt($ch, CURLOPT_URL, $url);
165+
curl_setopt($ch, CURLOPT_HEADER, array("Content-Type:multipart/form-data"));
154166
curl_setopt($ch, CURLOPT_POST, 1);
155167
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
156168
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
@@ -167,8 +179,8 @@ function sendMessageToConnect($message, $level)
167179
}
168180
}
169181
$result = curl_exec($ch);
182+
//DebMes("sending result: " . $result, 'connect_msg');
170183
curl_close($ch);
171-
//DebMes("Sending message result: $result",'connect_push');
172184
}
173185

174186
function cloudBackup()
@@ -467,7 +479,7 @@ function requestReverseFull($msg)
467479
$result = curl_exec($ch);
468480
$redirectURL = curl_getinfo($ch, CURLINFO_REDIRECT_URL);
469481
if ($redirectURL != '') {
470-
$redirectURL = str_replace(BASE_URL,'',$redirectURL);
482+
$redirectURL = str_replace(BASE_URL, '', $redirectURL);
471483
$result = 'redirect:' . $redirectURL;
472484
$data['content_type'] = 'redirect';
473485
} else {
@@ -499,10 +511,10 @@ function sendReverseURL($data, $result)
499511
$header = array('Content-Type: multipart/form-data');
500512
$url_requested = $data['url'];
501513
$fields = array('url' => $url_requested);
502-
if (IsSet($data['watermark'])) {
514+
if (isset($data['watermark'])) {
503515
$fields['watermark'] = $data['watermark'];
504516
}
505-
if (IsSet($data['content_type'])) {
517+
if (isset($data['content_type'])) {
506518
$fields['content_type'] = $data['content_type'];
507519
}
508520
if (preg_match('/\.css$/is', $url_requested)
@@ -573,7 +585,7 @@ function sendAllDevices()
573585
if (is_object($object)) {
574586
$props = $cl->getParentProperties($object->class_id, '', 1);
575587
$my_props = SQLSelect("SELECT ID,TITLE FROM properties WHERE OBJECT_ID='" . $object->id . "'");
576-
if (IsSet($my_props[0])) {
588+
if (isset($my_props[0])) {
577589
foreach ($my_props as $p) {
578590
if ($p['TITLE'] == 'updated' || $p['TITLE'] == 'updatedText') continue;
579591
$props[] = $p;
@@ -1019,17 +1031,17 @@ function usual(&$out)
10191031
$this->requestReverseFull($msg);
10201032
}
10211033
}
1022-
1023-
if ($this->ajax && $_GET['op'] == 'status') {
1024-
$status = gg('ThisComputer.cycle_connectRun');
1025-
1034+
1035+
if ($this->ajax && $_GET['op'] == 'status') {
1036+
$status = gg('ThisComputer.cycle_connectRun');
1037+
10261038
if ($status == '') {
1027-
echo json_encode(array('status' => 0));
1039+
echo json_encode(array('status' => 0));
10281040
} else {
1029-
echo json_encode(array('status' => 1));
1030-
}
1031-
1032-
exit;
1041+
echo json_encode(array('status' => 1));
1042+
}
1043+
1044+
exit;
10331045
}
10341046
}
10351047

0 commit comments

Comments
 (0)