Proyectos de Subversion LeadersLinked - Services

Rev

Rev 206 | Rev 268 | Ir a la última revisión | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 206 Rev 261
Línea 17... Línea 17...
17
 
17
 
Línea 18... Línea 18...
18
use LeadersLinked\Mapper\UserBlockedMapper;
18
use LeadersLinked\Mapper\UserBlockedMapper;
19
 
19
 
20
use LeadersLinked\Mapper\CompanyMapper;
-
 
21
use LeadersLinked\Mapper\CompanyUserMapper;
-
 
22
use LeadersLinked\Mapper\ConversationMapper;
-
 
23
use LeadersLinked\Mapper\MessageMapper;
20
use LeadersLinked\Mapper\CompanyMapper;
24
use LeadersLinked\Model\Conversation;
21
use LeadersLinked\Mapper\CompanyUserMapper;
25
use LeadersLinked\Library\Image;
-
 
26
use Laminas\View\Model\JsonModel;
-
 
27
use LeadersLinked\Form\InMail\SendForm;
-
 
28
use LeadersLinked\Model\Message;
-
 
29
use LeadersLinked\Model\VideoConvert;
22
use LeadersLinked\Library\Image;
30
use LeadersLinked\Mapper\VideoConvertMapper;
23
use Laminas\View\Model\JsonModel;
31
use Laminas\Mvc\I18n\Translator;
24
use Laminas\Mvc\I18n\Translator;
-
 
25
use LeadersLinked\Mapper\AbuseReportMapper;
-
 
26
use LeadersLinked\Model\AbuseReport;
-
 
27
use LeadersLinked\Library\ExternalCredentials;
-
 
28
use LeadersLinked\Library\Storage;
-
 
29
use LeadersLinked\Form\InMail\SendForm;
Línea 32... Línea 30...
32
use LeadersLinked\Mapper\AbuseReportMapper;
30
use PHPMailer\PHPMailer\PHPMailer;
33
use LeadersLinked\Model\AbuseReport;
31
 
-
 
32
 
-
 
33
class InMailController extends AbstractActionController
-
 
34
{
34
 
35
    const _SIZE_PAGE = 10;
35
class InMailController extends AbstractActionController
36
    const _USE_S3 = false;
36
{
37
    
37
    /**
38
    /**
38
     *
39
     *
Línea 89... Línea 90...
89
     * Generación del listado de conversationes
90
     * Generación del listado de conversationes
90
     * 
91
     * 
91
     * [
92
     * [
92
     *  success: true,
93
     *  success: true,
93
     *  data:[
94
     *  data:[
-
 
95
     *    messages : 
94
     *    [
96
     *    [
95
     *       uuid: uuid con quien se tiene la conversación,
97
     *       uuid: uuid con quien se tiene la conversación,
96
     *       name: nombre de con quien se tiene la conversacion,
98
     *       name: nombre de con quien se tiene la conversacion,
97
     *       image: imagen de con quien se tiene la conversación,
99
     *       image: imagen de con quien se tiene la conversación,
98
     *       profile: url del profile con quien se tiene la conversación,
100
     *       subject: asunto del mensaje
99
     *       last_message: fecha del ultimo mensaje,
101
     *       date: fecha del ultimo mensaje,
100
     *       count_unread: cantidad de mensajes sin leer,
-
 
101
     *       messages_link: url para recuperar los mensajes,
102
     *       seen: true|false,
102
     *       send_link: url para enviar el mensaje,
103
     *       send_link: url para enviar el mensaje,
-
 
104
     *       open_link : url para leer el mensaje,
103
     *       selected: 0 = no seleccionado, 1 = seleccionado
105
     *       delete_link : url para leer el mensaje,
104
     *     ]
106
     *     ],
-
 
107
     *     'total_messages' : total de mensajes,
-
 
108
     *     'total_pages' : total de páginas 10 en 10,
-
 
109
     *     'current_page' : página actual 
105
     *  ]
110
     *  ]
106
     * 
111
     * 
107
     * 
112
     * 
108
     * @return \Laminas\View\Model\JsonModel
113
     * @return \Laminas\View\Model\JsonModel
109
     */
114
     */
Línea 111... Línea 116...
111
    {
116
    {
112
        $request = $this->getRequest();
117
        $request = $this->getRequest();
113
        if ($request->isGet()) {
118
        if ($request->isGet()) {
114
            $currentUserPlugin = $this->plugin('currentUserPlugin');
119
            $currentUserPlugin = $this->plugin('currentUserPlugin');
115
            $currentUser = $currentUserPlugin->getUser();
120
            $currentUser = $currentUserPlugin->getUser();
116
 
-
 
117
            $id = $this->params()->fromRoute('id');
-
 
118
 
-
 
119
            $currentUserPlugin = $this->plugin('currentUserPlugin');
-
 
120
            $currentUser = $currentUserPlugin->getUser();
-
 
Línea 121... Línea 121...
121
            
121
            
122
                $userBlockedMapper = UserBlockedMapper::getInstance($this->adapter);
-
 
Línea -... Línea 122...
-
 
122
            $page = intval($this->params()->fromQuery('page', 0), 10);
123
                $user_blocked_ids = $userBlockedMapper ->fetchAllBlockedReturnIds($currentUser->id);
123
            
-
 
124
            if(self::_USE_S3) {
-
 
125
                $storage = Storage::getInstance($this->config);
124
            
126
            } else {
Línea -... Línea 127...
-
 
127
                $storage = '';
-
 
128
            }
-
 
129
 
-
 
130
            $externalCredentials = ExternalCredentials::getInstancia($this->config, $this->adapter);
-
 
131
            $externalCredentials->getUserBy($currentUser->id);
-
 
132
            
-
 
133
            $host       = trim($this->config['leaderslinked.inmail.host']);
-
 
134
            $port       = intval($this->config['leaderslinked.inmail.port_imap'], 10);
-
 
135
            $mailbox    = trim($this->config['leaderslinked.inmail.mailbox']);
-
 
136
            
-
 
137
 
125
                $user_blocked_me_ids = $userBlockedMapper->fetchAllUserBlockMeReturnIds($currentUser->id);                
138
            $username   = $externalCredentials->getUsernameInmail();
-
 
139
            $password   =  $externalCredentials->getPasswordInmail();
-
 
140
            
-
 
141
            $userMapper = \LeadersLinked\Mapper\UserMapper::getInstance($this->adapter);
126
 
142
 
-
 
143
            try { 
-
 
144
                \Eden\Core\Control::i();
-
 
145
                $client = eden('mail')->imap(
-
 
146
                    $host,
-
 
147
                    $username,
Línea 127... Línea -...
127
 
-
 
128
                $userMapper = UserMapper::getInstance($this->adapter);
-
 
129
                $now = $userMapper->getDatebaseNow();
148
                    $password,
130
                
149
                    $port,
131
                $conversationMapper = ConversationMapper::getInstance($this->adapter);
150
                    false);
132
                $messageMapper = MessageMapper::getInstance($this->adapter);
-
 
133
                $conversations = [];
151
                
134
 
-
 
Línea -... Línea 152...
-
 
152
                $client->setActiveMailbox($mailbox);
-
 
153
                 
-
 
154
                //$emails = $imap->getEmails(0, 3);
135
                $selected_user_id = 0;
155
                $maxMessages = $client->getEmailTotal(); 
136
 
156
 
137
                $id = $this->params()->fromRoute('id');
157
                if($maxMessages > self::_SIZE_PAGE) {
-
 
158
                    
-
 
159
                
-
 
160
                    $maxPages = (int)  $maxMessages / self::_SIZE_PAGE;
-
 
161
                    if(($maxPages * self::_SIZE_PAGE) <  $maxMessages) {
-
 
162
                        $maxPages++;
138
                if ($id) {
163
                    }
-
 
164
                } else {
139
 
165
                    $maxPages = 1; 
-
 
166
                    $page = 1;
-
 
167
                }
-
 
168
                 
-
 
169
                $page = $page > 0 ? $page : 1;
-
 
170
                $page = $page > $maxPages ? $maxPages : $page;
-
 
171
                 
-
 
172
                if($page == 1) {
-
 
173
                    $low = 0;
-
 
174
                    $high = self::_SIZE_PAGE - 1;
-
 
175
                } else {
-
 
176
                    $low = ($page - 1) * self::_SIZE_PAGE;
-
 
177
                    $high = $low + ( self::_SIZE_PAGE - 1); 
140
                    $companyMapper = CompanyMapper::getInstance($this->adapter);
178
                }
-
 
179
      
-
 
180
                $users = [];
Línea 141... Línea -...
141
                    $company = $companyMapper->fetchOneByUuid($id);
-
 
142
                    if ($company) {
-
 
143
 
-
 
144
                        $companyUserMapper = CompanyUserMapper::getInstance($this->adapter);
181
                $messages = [];
145
                        $companyUser = $companyUserMapper->fetchOwnerByCompanyId($company->id);
-
 
146
                        
-
 
147
                        if(!in_array($companyUser->user_id, $user_blocked_ids) && !in_array($companyUser->id, $user_blocked_me_ids)) {
-
 
148
                            $user  = $userMapper->fetchOne($companyUser->user_id);
182
                if( $maxMessages ) {
149
                            
183
                    $emails = $client->getEmails($low, $high);
150
                            
-
 
151
                            $selected_user_id = $user->id;
-
 
152
                            $conversation = $conversationMapper->fetchOneByUserId1AndUserId2($currentUser->id, $user->id);
-
 
153
                            
184
                    foreach($emails as $email)
154
                            
185
                    {
155
                            $timeElapsedString = '';
-
 
156
                            if ($conversation) {
-
 
157
                                $unread = $messageMapper->fetchCountUnreadMessagesByConversationIdAndReceiverId($conversation->id, $currentUser->id);
-
 
158
                                $lastMessage = $messageMapper->fetchLastUnreadMessagesByConversationIdAndReceiverId($conversation->id, $currentUser->id);
186
                        
159
                                
187
                      
160
                                if ($lastMessage) {
-
 
161
                                    $timeElapsedString =  $this->timeAgo($lastMessage, $now);
-
 
162
                                }
-
 
163
                            } else {
-
 
164
                                $unread = 0;
-
 
165
                            }
-
 
166
                            
-
 
167
                            
-
 
168
                            array_push($conversations, [
-
 
169
                                'uuid' => $company->uuid,
-
 
170
                                'name' => $company->name,
188
                     
171
                                'image' => $this->url()->fromRoute('storage', ['type' => 'company', 'code' => $company->uuid, 'filename' => $company->image],['force_canonical' => true]),
189
                        $from = $email['from']['email'];
172
                                'profile' => $this->url()->fromRoute('company/view', ['id' => $company->uuid]),
-
 
173
                                'last_message' => $timeElapsedString,
-
 
174
                                'count_unread' => $unread,
-
 
175
                                'messages_link' => $this->url()->fromRoute('inmail/message', ['id' => $user->uuid]),
190
             
Línea 176... Línea -...
176
                                'send_link' => $this->url()->fromRoute('inmail/message/send', ['id' => $user->uuid]),
-
 
177
                                'selected' => 1,
191
                        if(isset($users[ $from ])) {
178
                                'delete_link' => $this->url()->fromRoute('inmail/delete',  ['id' => $user->uuid]),
192
                            $user = $users[ $from ];
179
                            ]);
-
 
180
                            
193
                        } else {
181
                        }
-
 
182
                        
-
 
183
 
-
 
184
                        
194
                            $user = $userMapper->fetchOneByUsernameInmailAndNetworkId($from, $currentUser->network_id);
185
                    } else {
-
 
186
                        $user = $userMapper->fetchOneByUuid($id);
-
 
187
                        if ($user) {
-
 
188
                            
195
                            $users[ $from ] = $user;
189
                            if(!in_array($user->id, $user_blocked_ids) && !in_array($user->id, $user_blocked_me_ids)) {
-
 
190
 
-
 
191
                                $timeElapsedString = '';
196
                        }
192
    
-
 
193
                                $selected_user_id = $user->id;
-
 
194
                                $conversation = $conversationMapper->fetchOneByUserId1AndUserId2($currentUser->id, $user->id);
197
                        
195
                                if ($conversation) {
198
             
196
                                    $unread = $messageMapper->fetchCountUnreadMessagesByConversationIdAndReceiverId($conversation->id, $currentUser->id);
199
                        $seen = false;
197
                                    $lastMessage = $messageMapper->fetchLastUnreadMessagesByConversationIdAndReceiverId($conversation->id, $currentUser->id);
-
 
198
                                    if ($lastMessage) {
-
 
199
                                        $timeElapsedString =  $this->timeAgo($lastMessage, $now);
-
 
200
                                    }
-
 
201
                                } else {
-
 
202
                                    $unread = 0;
-
 
203
                                }
-
 
204
    
-
 
205
    
-
 
206
                                array_push($conversations, [
-
 
207
                                    'uuid' => $user->uuid,
-
 
208
                                    'name' => trim($user->first_name . ' ' . $user->last_name),
-
 
209
                                    'image' => $this->url()->fromRoute('storage', ['type' => 'user', 'code' => $user->uuid, 'filename' => $user->image],['force_canonical' => true]),
-
 
210
                                    'profile' => $this->url()->fromRoute('profile/view', ['id' => $user->uuid]),
-
 
211
                                    'last_message' => $timeElapsedString,
200
                        if(is_array($email['flags'])) {
212
                                    'count_unread' => $unread,
201
                            foreach($email['flags'] as $flag)
213
                                    'messages_link' => $this->url()->fromRoute('inmail/message', ['id' => $user->uuid]),
-
 
214
                                    'send_link' => $this->url()->fromRoute('inmail/message/send', ['id' => $user->uuid]),
-
 
215
                                    'selected' => 1,
-
 
216
                                    'delete_link' => $this->url()->fromRoute('inmail/delete',  ['id' => $user->uuid]),
-
 
217
                                ]);
-
 
218
                            }
-
 
219
                        }
-
 
220
                    }
-
 
221
                }
-
 
222
 
-
 
223
 
-
 
224
                $records = $conversationMapper->fetchAllByUserId($currentUser->id);
-
 
225
                foreach ($records as $record) {
-
 
226
                    if ($selected_user_id) {
-
 
227
                        if ($record->sender_id == $currentUser->id && $record->receiver_id == $selected_user_id) {
-
 
228
                            continue;
-
 
229
                        }
-
 
230
                        if ($record->receiver_id == $currentUser->id && $record->sender_id == $selected_user_id) {
-
 
231
                            continue;
-
 
232
                        }
-
 
Línea -... Línea 202...
-
 
202
                            {
-
 
203
                                if($flag == 'seen') {
233
                    }
204
                                    $seen = 1;
234
 
205
                                    break;
-
 
206
                                }
-
 
207
                            }
235
                    if ($record->sender_id == $currentUser->id) {
208
                        }
236
                        $user = $userMapper->fetchOne($record->receiver_id);
209
                        
237
                    }
-
 
238
                    if ($record->receiver_id == $currentUser->id) {
210
                 
-
 
211
                        
239
                        $user = $userMapper->fetchOne($record->sender_id);
212
                        $message =  [
240
                        
213
                            'uuid' => $user->uuid,
-
 
214
                            'name' => $user->first_name . ' ' . $user->last_name,
-
 
215
                            'image' => $storage ? $storage->getUserImage($user) : $this->url()->fromRoute('storage', ['code' => $user->uuid, 'type' => '$user', 'filename' => $user->image]), 
241
                        if(in_array($user->id, $user_blocked_ids) || in_array($user->id, $user_blocked_me_ids)) {
216
                            'subject' => $email['subject'],
242
                            continue;
217
                            'date' => date('Y-m-d h:i a', $email['date']),
243
                        }
218
                            'seen' => $seen,
244
                    }
-
 
-
 
219
                            'block_link' => $this->url()->fromRoute('inmail/user/block',[ 'id' => $user->uuid ], ['force_canonical' => true]),
245
 
220
                            'send_link' => $this->url()->fromRoute('inmail/message/send',[ 'id' => $user->uuid ], ['force_canonical' => true]),
246
                    $timeElapsedString = '';
221
                            'get_link' =>  $this->url()->fromRoute('inmail/message/get',[ 'id' => $email['uid'] ], ['force_canonical' => true]),
247
                    $unread = $messageMapper->fetchCountUnreadMessagesByConversationIdAndReceiverId($record->id, $currentUser->id);
-
 
248
                    $lastMessage = $messageMapper->fetchLastMessagesByConversationIdAndReceiverId($record->id, $currentUser->id);
-
 
249
 
-
 
250
 
-
 
251
                    if ($lastMessage) {
-
 
252
                        $timeElapsedString =  $this->timeAgo($lastMessage, $now);
-
 
253
                    }
-
 
254
 
-
 
255
                    array_push($conversations, [
-
 
256
                        'uuid' => $user->uuid,
-
 
257
                        'name' => trim($user->first_name . ' ' . $user->last_name),
-
 
258
                        'image' => $this->url()->fromRoute('storage', ['type' => 'user', 'code' => $user->uuid, 'filename' => $user->image],['force_canonical' => true]),
-
 
259
                        'profile' => $this->url()->fromRoute('profile/view', ['id' => $user->uuid]),
222
                            'delete_link'=>    $this->url()->fromRoute('inmail/message/delete',[ 'id' => $email['uid'] ], ['force_canonical' => true]),
260
                        'last_message' => $timeElapsedString,
223
                       ];
-
 
224
                        
261
                        'count_unread' => $unread,
225
         
262
                        'messages_link' => $this->url()->fromRoute('inmail/message', ['id' => $user->uuid]),
226
                        array_push($messages, $message);
263
                        'send_link' => $this->url()->fromRoute('inmail/message/send', ['id' => $user->uuid]),
-
 
264
                        'selected' => 0,
-
 
265
                        'delete_link' => $this->url()->fromRoute('inmail/delete',  ['id' => $user->uuid]),
227
                        
266
                    ]);
228
                    }
267
                }
229
                     
268
 
230
                }
269
 
231
                 
270
                usort($conversations, function ($a, $b) {
232
                $client->disconnect(); 
271
                    if ($a['selected'] == $b['selected']) {
233
                 
272
                        if ($a['last_message'] == $b['last_message']) {
234
                $data = [
-
 
235
                    'success' => true, 
-
 
236
                    'data' => [
-
 
237
                        'messages'          => $messages,  
273
                            return 0;
238
                        'total_messages'    => $maxMessages,
-
 
239
                        'total_pages'       => $maxPages,
274
                        } else {
240
                        'current_page'      => $page,
275
                            return $a['last_message'] < $b['last_message'] ? -1 : 1;
241
                    ]
276
                        }
242
                ];
277
                    } else {
243
                     
278
                        return $a['selected'] < $b['selected'] ? -1 : 1;
244
                     
-
 
245
                return new JsonModel($data);   
-
 
246
                     
-
 
247
            } catch (\Exception $e) {
-
 
248
                
-
 
249
                return new JsonModel([
-
 
250
                    'success' => false, 
-
 
251
                    'data' => 'ERROR_INMAIL_MESSAGE_LIST_UNAVAILABLE' 
-
 
252
                ]);
-
 
253
            }
-
 
254
             
-
 
255
           /*
-
 
256
            * 
-
 
257
            * (
-
 
258
    [0] => Array
-
 
259
        (
-
 
260
            [id] => <6f27ed6a-d554-4f0b-b9ee-7c708cca8b33@inmail.leaderslinked.com>
-
 
261
            [parent] => 
-
 
262
            [topic] => Test 1
-
 
263
            [mailbox] => INBOX
-
 
264
            [uid] => 8
-
 
265
            [date] => 1721906994
-
 
266
            [subject] => Test 1
-
 
267
            [from] => Array
-
 
268
                (
-
 
269
                    [name] => Efrain Yanez
-
 
270
                    [email] => efrain.yanez@inmail.leaderslinked.com
-
 
271
                )
-
 
272
 
-
 
273
            [flags] => Array
-
 
274
                (
-
 
275
                    [0] => seen
-
 
276
                )
-
 
277
 
-
 
278
            [to] => Array
-
 
279
                (
-
 
280
                    [0] => Array
-
 
281
                        (
-
 
282
                            [name] => 
-
 
283
                            [email] => santiago.olivera@inmail.leaderslinked.com
-
 
284
                        )
-
 
285
 
-
 
286
                )
-
 
287
 
-
 
288
            [cc] => Array
-
 
289
                (
-
 
290
                )
-
 
291
 
-
 
292
            [bcc] => Array
-
 
293
                (
-
 
294
                )
-
 
295
 
-
 
296
            [attachment] => 1
-
 
297
            
-
 
298
        )
-
 
299
        (
-
 
300
    [id] => <6f27ed6a-d554-4f0b-b9ee-7c708cca8b33@inmail.leaderslinked.com>
-
 
301
    [parent] =>
-
 
302
    [topic] => Test 1
-
 
303
    [mailbox] => INBOX
-
 
304
    [uid] => 8
-
 
305
    [date] => 1721906994
-
 
306
    [subject] => Test 1
-
 
307
    [from] => Array
-
 
308
        (
-
 
309
            [name] => Efrain Yanez
-
 
310
            [email] => efrain.yanez@inmail.leaderslinked.com
-
 
311
        )
-
 
312
 
-
 
313
    [flags] => Array
-
 
314
        (
-
 
315
            [0] => seen
-
 
316
        )
-
 
317
 
-
 
318
    [to] => Array
-
 
319
        (
-
 
320
            [0] => Array
-
 
321
                (
-
 
322
                    [name] =>
-
 
323
                    [email] => santiago.olivera@inmail.leaderslinked.com
-
 
324
                )
-
 
325
 
-
 
326
        )
-
 
327
 
-
 
328
    [cc] => Array
-
 
329
        (
-
 
330
        )
-
 
331
 
-
 
332
    [bcc] => Array
-
 
333
        (
-
 
334
        )
-
 
335
[body] => 'esto es una pryeba',
-
 
336
    [attachment] => Array
-
 
337
        (
-
 
338
            [POST 1080X1080-03-37.png] => Array
-
 
339
                (
-
 
340
                    [image/png] => �PNG
-
 
341
 
-
 
342
 
-
 
343
 
-
 
344
 
-
 
345
 
-
 
346
 
-
 
347
        [futbol-720p-230714 - Copy (1).mp4] => Array
-
 
348
                (
-
 
349
                    [video/mp4]
-
 
350
        
-
 
351
            * 
-
 
352
            * 
-
 
353
            Array
-
 
354
(
-
 
355
    [0] => __construct
-
 
356
    [1] => connect
-
 
357
    [2] => disconnect
-
 
358
    [3] => getActiveMailbox
-
 
359
    [4] => getEmails
-
 
360
    [5] => getEmailTotal
-
 
361
    [6] => getNextUid
-
 
362
    [7] => getMailboxes
-
 
363
    [8] => getUniqueEmails
-
 
364
    [9] => move
-
 
365
    [10] => copy
-
 
366
    [11] => remove
-
 
367
    [12] => expunge
-
 
368
    [13] => search
-
 
369
    [14] => searchTotal
-
 
370
    [15] => setActiveMailbox
-
 
371
    [16] => i
-
 
372
    [17] => __call
-
 
373
    [18] => __invoke
-
 
374
    [19] => __toString
-
 
375
    [20] => addMethod
-
 
376
    [21] => callArray
-
 
377
    [22] => inspect
-
 
378
    [23] => loadState
279
                    }
379
    [24] => loop
280
                });
380
    [25] => off
281
 
381
    [26] => on
282
 
382
    [27] => saveState
283
                return new JsonModel([
383
    [28] => trigger
284
                    'success' => true,
384
    [29] => when
285
                    'data' => $conversations
385
)
286
                ]);
386
            */
287
 
-
 
288
        } else {
387
     
289
            return new JsonModel([
-
 
290
                'success' => false,
-
 
291
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
-
 
292
            ]);
-
 
293
        }
-
 
294
    }
-
 
295
 
-
 
296
 
-
 
297
    /**
-
 
298
     * Esta función remueve el usuario del grupo
-
 
299
     * Es una petición GET el url recuperado en /inmail
-
 
300
     * [ruta del servidor]/inmail/[uuid]/message
-
 
301
     * retorna un json en caso de ser  positivo
-
 
302
     * [
-
 
303
     *   success: true,
-
 
304
     *      data: [
-
 
305
     *          [ 
-
 
306
     *              sender_name: nombre de quien que envia el mensaje,
-
 
307
     *              sender_image: imagen de quien que recibe el mensaje,
-
 
308
     *              sender_profile: url de profile de quien que envia el mensaje,
-
 
309
     *              receiver_name: nombre de quien que recibe el mensaje,
-
 
310
     *              receiver_image: url de la imagen de quien  que recibe el mensaje,
-
 
311
     *              receiver_profile: url del profile de quien recibe el mensaje,
-
 
312
     *              side: left/righ de que lado de la pantalla se mostrara,
-
 
313
     *              message: texto del mensaje,
-
 
314
     *              type: text|image|video|document,
-
 
315
     *              filename: url del archivo enviado,
-
 
316
     *              date: cadena que describe hace cuanto se recibio el mensaje
-
 
317
     *          ]
-
 
318
     *      ]
-
 
319
     *   ]
388
        } else {
320
     * En caso de ser negativo puede haber 2 formatos
389
            return new JsonModel([
321
     * [
390
                'success' => false,
322
     *  'success' : false,
391
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
323
     *  'data' : mensaje de error
-
 
324
     * ]
-
 
325
     * @return \Laminas\View\Model\JsonModel
392
            ]);
326
     */
393
        }
327
    public function messageAction()
-
 
328
    {
-
 
329
        $request = $this->getRequest();
-
 
Línea 330... Línea -...
330
        if ($request->isGet()) {
-
 
331
            $page = intval($this->params()->fromQuery('page', 0), 10);
-
 
332
 
-
 
333
            $currentUserPlugin = $this->plugin('currentUserPlugin');
-
 
334
            $currentUser = $currentUserPlugin->getUser();
394
    }
335
 
-
 
336
            $userMapper = UserMapper::getInstance($this->adapter);
-
 
337
            $now = $userMapper->getDatebaseNow();
-
 
338
            
-
 
339
            $conversationMapper = ConversationMapper::getInstance($this->adapter);
-
 
340
 
-
 
341
            $messageMapper = MessageMapper::getInstance($this->adapter);
-
 
342
 
395
    
343
            $id = $this->params()->fromRoute('id');
-
 
344
            if (!$id) {
-
 
345
                return new JsonModel([
-
 
346
                    'success' => false,
-
 
347
                    'data' => 'ERROR_PARAMETERS_ARE_INVALID'
-
 
348
                ]);
-
 
Línea 349... Línea 396...
349
            }
396
    public function getAttachmentAction()
350
 
397
    {
Línea -... Línea 398...
-
 
398
        $request = $this->getRequest();
-
 
399
        if ($request->isGet()) {
-
 
400
            $currentUserPlugin = $this->plugin('currentUserPlugin');
351
            $user = $userMapper->fetchOneByUuid($id);
401
            $currentUser = $currentUserPlugin->getUser();
-
 
402
            
352
            if (!$user) {
403
            $id = intval($this->params()->fromRoute('id'), 10);
353
                return new JsonModel([
404
            $attachment = intval($this->params()->fromRoute('attachment'), 10);
354
                    'success' => false,
405
            
355
                    'data' => 'ERROR_REQUEST_IS_INVALID'
-
 
356
                ]);
-
 
357
            }
-
 
-
 
406
            $externalCredentials = ExternalCredentials::getInstancia($this->config, $this->adapter);
358
            
407
            $externalCredentials->getUserBy($currentUser->id);
359
            $abuseReportMapper = AbuseReportMapper::getInstance($this->adapter);
408
            
-
 
409
            $host       = trim($this->config['leaderslinked.inmail.host']);
-
 
410
            $port       = intval($this->config['leaderslinked.inmail.port_imap'], 10);
360
            $abuse_report_message_ids = $abuseReportMapper->fetchAllDataByUserReportingIdAndTypeReturnIds($currentUser->id, AbuseReport::TYPE_INMAIL_MESSAGE);
411
            $mailbox    = trim($this->config['leaderslinked.inmail.mailbox']);
361
            
412
            
362
 
413
            
363
            $conversationMapper = ConversationMapper::getInstance($this->adapter);
414
            $username   = $externalCredentials->getUsernameInmail();
-
 
415
            $password   =  $externalCredentials->getPasswordInmail();
364
            $conversation = $conversationMapper->fetchOneByUserId1AndUserId2($currentUser->id, $user->id);
416
            
365
 
417
           
366
            $messages = [];
418
            
367
            if ($conversation) {
-
 
368
                $records = $messageMapper->getAllMessagesPaginatorByConversationId($conversation->id, $page);
419
 
369
 
420
            try {
370
 
421
                \Eden\Core\Control::i();
-
 
422
                $client = eden('mail')->imap(
371
                foreach ($records as $record) {
423
                    $host,
372
                    /*
-
 
373
                    echo '<pre>'; 
-
 
374
                    print_r($record); 
-
 
375
                    echo '</pre>'; */
-
 
376
 
-
 
377
                    $timeElapsedString = $this->timeAgo($record->added_on, $now);
-
 
-
 
424
                    $username,
-
 
425
                    $password,
378
 
426
                    $port,
379
 
-
 
380
                    if ($record->sender_id == $currentUser->id) {
-
 
381
                        array_push($messages, [
-
 
382
                            'uuid' => $record->uuid,
-
 
383
                            'sender_name' => trim($currentUser->first_name . ' ' . $currentUser->last_name),
427
                    false);
384
                            'sender_image' => $this->url()->fromRoute('storage', ['type' => 'user', 'filename' => $currentUser->image, 'code' => $currentUser->uuid],['force_canonical' => true]),
428
                
-
 
429
                $client->setActiveMailbox($mailbox);
385
                            'sender_profile' => $this->url()->fromRoute('profile/view', ['id' => $currentUser->uuid]),
430
      
Línea 386... Línea -...
386
                            'receiver_name' => trim($user->first_name . ' ' . $user->last_name),
-
 
387
                            'receiver_image' => $this->url()->fromRoute('storage', ['type' => 'user', 'filename' => $user->image, 'code' => $user->uuid],['force_canonical' => true]),
431
                $email = $client->getUniqueEmails($id, true);
388
                            'receiver_profile' => $this->url()->fromRoute('profile/view', ['id' => $user->uuid]),
-
 
389
                            'side' => 'left',
-
 
390
                            'message' => $record->message,
-
 
391
                            'type' => $record->type,
-
 
392
                            'filename' => $record->filename ? $this->url()->fromRoute('storage', ['type' => 'message', 'filename' => $record->filename, 'code' => $record->uuid],['force_canonical' => true]) : '',
-
 
393
                            'date' => $timeElapsedString,
-
 
394
                            'url_abuse_report' => '',
-
 
395
                        ]);
-
 
396
                    } else {
-
 
397
                        
-
 
398
                        if(in_array($record->id, $abuse_report_message_ids)) {
-
 
399
                            
-
 
400
                            array_push($messages, [
-
 
401
                                'uuid' => $record->uuid,
-
 
402
                                'sender_name' => trim($user->first_name . ' ' . $user->last_name),
-
 
403
                                'sender_image' => $this->url()->fromRoute('storage', ['type' => 'user', 'filename' => $user->image, 'code' => $user->uuid],['force_canonical' => true]),
-
 
404
                                'sender_profile' => $this->url()->fromRoute('profile/view', ['id' => $user->uuid]),
-
 
405
                                'receiver_name' => trim($currentUser->first_name . ' ' . $currentUser->last_name),
-
 
Línea 406... Línea 432...
406
                                'receiver_image' => $this->url()->fromRoute('storage', ['type' => 'user', 'filename' => $currentUser->image, 'code' => $user->uuid],['force_canonical' => true]),
432
                $client->disconnect();
407
                                'receiver_profile' => $this->url()->fromRoute('profile/view', ['id' => $currentUser->uuid]),
433
                
-
 
434
                if($email['uid']) {
408
                                'side' => 'right',
435
                    
409
                                'message' => 'LABEL_ABUSE_CONTENT_REPORTED',
-
 
410
                                'type' => Message::TYPE_TEXT,
436
                    
411
                                'filename' => '',
437
                    $base64         = '';
412
                                'date' => $timeElapsedString,
-
 
413
                                'url_abuse_report' => '',
-
 
414
                            ]);
438
                    $contentType    = '';
415
                            
439
                    $filename       = '';
416
                        } else {
440
                  
417
                            $url_abuse_report = $this->url()->fromRoute('helpers/abuse-report', ['type' => 'message', 'id' => $record->uuid], ['force_canonical' => true]);
-
 
418
                        
441
                    if(!empty($email['attachment']) &&  is_array($email['attachment'])) {
419
                            array_push($messages, [
442
                        
420
                                'uuid' => $record->uuid,
443
                       
421
                                'sender_name' => trim($user->first_name . ' ' . $user->last_name),
444
                        
422
                                'sender_image' => $this->url()->fromRoute('storage', ['type' => 'user', 'filename' => $user->image, 'code' => $user->uuid],['force_canonical' => true]),
-
 
423
                                'sender_profile' => $this->url()->fromRoute('profile/view', ['id' => $user->uuid]),
-
 
424
                                'receiver_name' => trim($currentUser->first_name . ' ' . $currentUser->last_name),
445
                        foreach($email['attachment'] as $filename => $data)
-
 
446
                        {
-
 
447
                         
-
 
448
                            $i = 0;
-
 
449
                            foreach($data as $contentType => $value)
-
 
450
                            {
-
 
451
                                if($i == $attachment) {
-
 
452
                                    $base64 = base64_encode($value);
-
 
453
                                    break;
-
 
454
                                }
-
 
455
                                $i++;
-
 
456
                            }
-
 
457
                        }
-
 
458
                    }
-
 
459
                    
-
 
460
                    if($base64) {
425
                                'receiver_image' => $this->url()->fromRoute('storage', ['type' => 'user', 'filename' => $currentUser->image, 'code' => $user->uuid],['force_canonical' => true]),
461
                        return new JsonModel([
-
 
462
                            'success' => true,
-
 
463
                            'data' => [
-
 
464
                                'filename' => $filename, 
-
 
465
                                'mime-type' => $contentType,
-
 
466
                                'base64' =>  $base64,
Línea -... Línea 467...
-
 
467
                            ]
-
 
468
                        ]);
-
 
469
                    } else {
-
 
470
                        return new JsonModel([
-
 
471
                            'success' => false,
-
 
472
                            'data' =>  'ERROR_INMAIL_MESSAGE_ATTACHMENT_NOT_FOUND'
-
 
473
                        ]);
-
 
474
                    }
-
 
475
                    
-
 
476
                    
-
 
477
                   
426
                                'receiver_profile' => $this->url()->fromRoute('profile/view', ['id' => $currentUser->uuid]),
478
                   
427
                                'side' => 'right',
479
                   
428
                                'message' => $record->message,
480
 
429
                                'type' => $record->type,
-
 
430
                                'filename' => $record->filename ? $this->url()->fromRoute('storage', ['type' => 'message', 'filename' => $record->filename, 'code' => $record->uuid],['force_canonical' => true]) : '',
481
                    
431
                                'date' => $timeElapsedString,
482
                } else {
432
                                'url_abuse_report' => $url_abuse_report,
483
                    return new JsonModel([
433
                            ]);
484
                        'success' => false,
434
                        }
-
 
435
 
-
 
436
                        $messageMapper->markAsRead($record->id);
-
 
437
                    }
-
 
438
                }
485
                        'data' => 'ERROR_INMAIL_MESSAGE_NOT_FOUND'
439
 
486
                    ]);
440
                return new JsonModel([
487
                }
441
                    'success' => true,
488
          
442
                    'data' => $messages,
489
                
443
                    'pagination' => $records->getPages()
490
            } catch (\Exception $e) {
444
                ]);
491
                
445
            }
492
                return new JsonModel([
446
 
493
                    'success' => false,
447
 
-
 
448
            return new JsonModel([
-
 
449
                'success' => true,
-
 
450
                'data' => $messages,
-
 
451
                'pagination' => 1
-
 
452
            ]);
-
 
453
        } else {
-
 
454
            return new JsonModel([
-
 
455
                'success' => false,
-
 
456
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
-
 
457
            ]);
-
 
458
        }
-
 
459
    }
-
 
460
 
-
 
461
    /**
-
 
462
     * Esta función envia un mensaje
-
 
463
     * Es una petición POST el url recuperado en /inmail
-
 
464
     * [ruta del servidor]/inmail/[uidd del usuario]/message/send 
-
 
465
     * Lo párametros son
-
 
466
     * message: text plain requerido
-
 
467
     * file: no requerido puede jpg, png, jpeg, mp3, mp4, webm o pdf
-
 
468
     * o
-
 
469
     * [ruta del servidor]/inmail/[uidd del usuario]/message/send/encoding/base64 para el caso de react-native
-
 
470
     * Los párametros son
-
 
471
     * message: text plain requerido
-
 
472
     * fileBase64Name: nombre del archivo  que se envia en base64 solo requerido si se envia un archivo
-
 
473
     * fileBase64Content: contenido en base 64 del archivo
-
 
474
     * 
-
 
475
     * retorna un json en caso de ser  positivo
-
 
476
     * [
-
 
477
     *   success: true,
-
 
478
     *      data:{
-
 
479
     *          sender_name: nombre de quien que envia el mensaje,
-
 
480
     *          sender_image: imagen de quien que recibe el mensaje,
-
 
481
     *          sender_profile: url de profile de quien que envia el mensaje,
-
 
482
     *          receiver_name: nombre de quien que recibe el mensaje,
-
 
483
     *          receiver_image: url de la imagen de quien  que recibe el mensaje,
-
 
484
     *          receiver_profile: url del profile de quien recibe el mensaje,
-
 
485
     *          side: left/righ de que lado de la pantalla se mostrara,
494
                    'data' => 'ERROR_INMAIL_MESSAGE_LIST_UNAVAILABLE'
486
     *          message: texto del mensaje,
495
                ]);
487
     *          type: text|image|video|document,
496
            }
488
     *          filename: url del archivo enviado,
497
            
489
     *          date: cadena que describe hace cuanto se recibio el mensaje
498
          
490
     *      ]
499
            
491
     *   ]   
-
 
492
     * En caso de ser negativo puede haber 2 formatos
-
 
493
     * [
-
 
Línea 494... Línea -...
494
     *  'success' : false,
-
 
495
     *  'data' : mensaje de error
500
        } else {
496
     * ]
-
 
497
     * @return \Laminas\View\Model\JsonModel
-
 
498
     */
-
 
499
    public function sendMessageAction()
-
 
500
    {
-
 
501
        $request = $this->getRequest();
-
 
502
        if ($request->isPost()) {
-
 
503
            $currentUserPlugin = $this->plugin('currentUserPlugin');
501
            return new JsonModel([
504
            $currentUser = $currentUserPlugin->getUser();
-
 
505
 
502
                'success' => false,
506
            $userMapper = UserMapper::getInstance($this->adapter);
-
 
507
            $now = $userMapper->getDatebaseNow();
-
 
508
            
503
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
509
 
504
            ]);
510
            $id = $this->params()->fromRoute('id');
-
 
511
            if (!$id) {
-
 
512
                return new JsonModel([
-
 
513
                    'success' => false,
-
 
514
                    'data' => 'ERROR_PARAMETERS_ARE_INVALID'
-
 
515
                ]);
-
 
516
            }
505
        }
517
 
506
    }
Línea 518... Línea -...
518
 
-
 
519
            $user = $userMapper->fetchOneByUuidAndNetworkId($id, $currentUser->network_id);
-
 
520
            if (!$user) {
-
 
521
                return new JsonModel([
-
 
522
                    'success' => false,
-
 
523
                    'data' => 'ERROR_REQUEST_IS_INVALID'
-
 
524
                ]);
-
 
525
            }
-
 
526
 
507
    
527
 
508
    public function getMessageAction()
528
            $data = array_merge($request->getPost()->toArray(), $request->getFiles()->toArray());
509
    {
529
           
510
        $request = $this->getRequest();
530
            if(!empty($data['file']) && empty($data['file']['error'])) {
511
        if ($request->isGet()) {
531
                $data['message'] = $data['file']['name'];
512
            $currentUserPlugin = $this->plugin('currentUserPlugin');
532
            }
513
            $currentUser = $currentUserPlugin->getUser();
533
            
-
 
534
            $form = new SendForm();
-
 
535
            $form->setData($data);
-
 
536
 
-
 
537
            if ($form->isValid()) {
-
 
538
 
-
 
539
                $dataPost = (array) $form->getData();
-
 
540
       
-
 
541
 
-
 
542
                $conversationMapper = ConversationMapper::getInstance($this->adapter);
-
 
543
                $conversation = $conversationMapper->fetchOneByUserId1AndUserId2($currentUser->id, $user->id);
-
 
544
 
-
 
545
                if ($conversation) {
514
            
546
                    $conversation->receiver_status = Conversation::STATUS_NORMAL;
515
            $id = intval($this->params()->fromRoute('id'), 10);
547
                    $conversation->sender_status = Conversation::STATUS_NORMAL;
-
 
548
 
-
 
549
                    if (!$conversationMapper->update($conversation)) {
516
            
550
                        return new JsonModel([
-
 
551
                            'success'  => false,
-
 
552
                            'data' => $conversationMapper->getError()
-
 
553
                        ]);
-
 
554
                    }
-
 
555
                } else {
-
 
556
                    $conversation = new Conversation();
-
 
557
                    $conversation->sender_id = $currentUser->id;
-
 
558
                    $conversation->sender_status = Conversation::STATUS_NORMAL;
517
            if(self::_USE_S3) {
559
                    $conversation->receiver_id = $user->id;
-
 
560
                    $conversation->receiver_status = Conversation::STATUS_NORMAL;
-
 
561
 
-
 
562
                    if (!$conversationMapper->insert($conversation)) {
518
                $storage = Storage::getInstance($this->config);
563
                        return new JsonModel([
-
 
564
                            'success'  => false,
519
            } else {
565
                            'data' => $conversationMapper->getError()
520
                $storage = '';
566
                        ]);
-
 
567
                    }
521
            }
568
                }
-
 
569
                $files                  = $this->getRequest()->getFiles()->toArray();
522
            
570
                $type                   = Message::TYPE_TEXT;
-
 
571
                $message_tmp_filename   = '';
523
            $externalCredentials = ExternalCredentials::getInstancia($this->config, $this->adapter);
572
                $message_filename       = '';
524
            $externalCredentials->getUserBy($currentUser->id);
573
 
525
            
574
 
-
 
575
                if (isset($files['file']) && empty($files['file']['error'])) {
-
 
576
                    $message_tmp_filename  = $files['file']['tmp_name'];
-
 
577
                    $message_filename      = $this->normalizeString($files['file']['name']);
-
 
578
 
526
            $host       = trim($this->config['leaderslinked.inmail.host']);
579
                    $mime_type = mime_content_type($message_tmp_filename);
-
 
580
 
527
            $port       = intval($this->config['leaderslinked.inmail.port_imap'], 10);
581
 
-
 
582
                    if ($mime_type == 'image/jpg' || $mime_type == 'image/jpeg' || $mime_type == 'image/png') {
-
 
583
                        $type = Message::TYPE_IMAGE;
-
 
584
                    } else if ($mime_type == 'video/webm' || $mime_type == 'video/mpeg' || $mime_type == 'video/mpg' || $mime_type == 'video/mp4') {
-
 
585
                        $type = Message::TYPE_VIDEO;
-
 
586
                    } else if ($mime_type == 'application/pdf') {
528
            $mailbox    = trim($this->config['leaderslinked.inmail.mailbox']);
587
                        $type = Message::TYPE_DOCUMENT;
-
 
588
                    }
-
 
589
                }
-
 
590
 
-
 
591
 
529
            
592
 
-
 
593
 
530
            
594
                $message = new Message();
531
            $username   = $externalCredentials->getUsernameInmail();
595
                $message->conversation_id = $conversation->id;
532
            $password   =  $externalCredentials->getPasswordInmail();
596
                $message->read = Message::NO;
-
 
-
 
533
            
597
                $message->message = $type == Message::TYPE_TEXT ? $dataPost['message'] : '';
534
            
598
                $message->receiver_id = $user->id;
-
 
599
                $message->receiver_status = Message::STATUS_NORMAL;
535
            
600
                $message->sender_id = $currentUser->id;
-
 
601
                $message->sender_status = Message::STATUS_NORMAL;
536
            
602
                $message->type = $type;
537
            try {
603
 
538
                \Eden\Core\Control::i();
-
 
539
                $client = eden('mail')->imap(
604
 
540
                    $host,
605
 
541
                    $username,
606
 
-
 
607
 
-
 
608
                $messageMapper = MessageMapper::getInstance($this->adapter);
542
                    $password,
609
                if ($messageMapper->insert($message)) {
-
 
610
 
-
 
611
                    $message = $messageMapper->fetchOne($message->id);
-
 
612
 
-
 
613
 
543
                    $port,
614
                    if ($type == Message::TYPE_DOCUMENT) {
-
 
615
                        try {
-
 
616
                            $target_path = $this->config['leaderslinked.fullpath.message'] . $message->uuid;
544
                    false);
617
                            if (!file_exists($target_path)) {
-
 
618
                                mkdir($target_path, 0755);
-
 
619
                            }
-
 
620
 
545
                
621
                            $full_filename = $target_path  . DIRECTORY_SEPARATOR . $message_filename;
-
 
622
                            /*
-
 
623
                            if($encoding == 'base64') {
546
                $client->setActiveMailbox($mailbox);
624
                                $resultMoveOrRename = rename($message_tmp_filename , $full_filename);
547
                
625
                            } else {
548
                $email = $client->getUniqueEmails($id, true);
626
                                $resultMoveOrRename = move_uploaded_file($message_tmp_filename , $full_filename);
-
 
627
                            }
-
 
628
                            */
-
 
629
 
-
 
630
                            $resultMoveOrRename = move_uploaded_file($message_tmp_filename, $full_filename);
549
                $client->disconnect();
631
                            if ($resultMoveOrRename) {
550
                
632
 
551
                if($email['uid']) {
633
                                $message->type = $type;
-
 
634
                                $message->filename = basename($message_filename);
-
 
635
                                $messageMapper->update($message);
-
 
636
                            } else {
-
 
637
                                error_log('no se pudo mover o renombrar el documento : ' . $message_tmp_filename . ' al directorio : ' . $full_filename);
-
 
638
                            }
-
 
639
                        } catch (\Throwable $e) {
-
 
640
                            error_log($e->getTraceAsString());
-
 
641
                        }
-
 
642
                    }
-
 
643
                    if ($type == Message::TYPE_IMAGE) {
-
 
644
                        try {
-
 
645
                            $target_path = $this->config['leaderslinked.fullpath.message'] . $message->uuid;
552
                    $from = $email['from']['email'];
646
                            if (!file_exists($target_path)) {
-
 
647
                                mkdir($target_path, 0755);
-
 
648
                            }
553
                    $subject = $email['subject'];
649
 
554
                    $body   = empty($email['body']['text/html']) ?  $email['body']['text/plain'] : $email['body']['text/html'];
650
                            list($target_width, $target_height) = explode('x', $this->config['leaderslinked.image_sizes.message_image_size']);
-
 
651
 
-
 
652
                            $message_filename = substr($message_filename, 0, strrpos($message_filename, '.'))  . '.png';
-
 
653
 
-
 
654
                            //echo "target_path = $target_path message_tmp_filename = $message_tmp_filename message_filename = $message_filename"; exit;
-
 
655
 
-
 
656
                            $crop_to_dimensions = false;
555
                    
657
                            if (Image::uploadImage($message_tmp_filename, $target_path, $message_filename, $target_width, $target_height, $crop_to_dimensions)) {
-
 
658
                                $message->type = $type;
-
 
659
                                $message->filename = basename($message_filename);
-
 
660
                                $messageMapper->update($message);
-
 
661
                            }
-
 
662
                        } catch (\Throwable $e) {
-
 
663
                            error_log($e->getTraceAsString());
-
 
664
                        }
-
 
665
                    }
556
                    
666
                    if ($type == Message::TYPE_VIDEO) {
-
 
667
                        try {
-
 
668
                            $target_path = $this->config['leaderslinked.fullpath.message'] . $message->uuid;
557
                    $userMapper = \LeadersLinked\Mapper\UserMapper::getInstance($this->adapter);
669
                            if (!file_exists($target_path)) {
-
 
670
                                mkdir($target_path, 0755);
558
                    $user = $userMapper->fetchOneByUsernameInmailAndNetworkId($from, $currentUser->network_id);
671
                            }
-
 
672
 
-
 
673
                            $full_filename = $target_path  . DIRECTORY_SEPARATOR . $message_filename;
559
                    
674
 
560
                    
675
                            /*
-
 
676
                            if($encoding == 'base64') {
561
                    $seen = false;
677
                                $resultMoveOrRename = rename($message_tmp_filename , $full_filename);
-
 
678
                            } else {
-
 
679
                                $resultMoveOrRename = move_uploaded_file($message_tmp_filename , $full_filename);
562
                    if(is_array($email['flags'])) {
680
                            }*/
563
                        foreach($email['flags'] as $flag)
681
 
-
 
682
                            $resultMoveOrRename = move_uploaded_file($message_tmp_filename, $full_filename);
564
                        {
683
                            if ($resultMoveOrRename) {
-
 
684
 
565
                            if($flag == 'seen') {
685
                                $size = $this->config['leaderslinked.image_sizes.message_image_size'];
566
                                $seen = 1;
686
                                $getFromSecound = 2;
567
                                break;
687
 
-
 
688
                                //extracción del cover
568
                            }
689
                                $generateFileName = substr($message_filename, 0, strrpos($message_filename, '.'));
569
                        }
690
                                $generateFile =  $target_path  . DIRECTORY_SEPARATOR . $generateFileName .  '.png';
570
                    }
691
                                $cmd            = "/usr/bin/ffmpeg -i $full_filename -an -ss $getFromSecound -s $size $generateFile";
-
 
692
                                exec($cmd);
571
                    
693
 
-
 
694
 
-
 
695
                                $message->type = $type;
572
                    
696
                                $message->filename = basename($message_filename);
573
                    
697
                                $message->image_preview = basename($generateFile);
574
                    $attachments = [];
698
                                $messageMapper->update($message);
-
 
699
 
-
 
700
                                $videoConvert = new VideoConvert();
-
 
701
                                $videoConvert->filename = $full_filename;
-
 
702
                                $videoConvert->type = VideoConvert::TYPE_FEED;
-
 
703
 
-
 
704
                                $videoConvertMapper = VideoConvertMapper::getInstance($this->adapter);
-
 
705
                                $videoConvertMapper->insert($videoConvert);
-
 
706
                            } else {
-
 
707
                                error_log('no se pudo mover o renombrar el documento : ' . $message_tmp_filename . ' al directorio : ' . $full_filename);
-
 
708
                            }
-
 
709
                        } catch (\Throwable $e) {
-
 
710
                            error_log($e->getTraceAsString());
-
 
711
                        }
-
 
712
                    }
575
                    if(!empty($email['attachment']) &&  is_array($email['attachment'])) {
713
 
576
                        foreach($email['attachment'] as $filename => $attachment)
714
                    $message = $messageMapper->fetchOne($message->id);
577
                        {
715
 
578
                            $i = 0;
716
                    if ($message->filename) {
-
 
717
                        $filename = $this->url()->fromRoute('storage', ['type' => 'message', 'filename' => $message->filename, 'code' => $message->uuid],['force_canonical' => true]);
-
 
718
                    } else {
579
                            foreach($attachment as $contentType => $value)
719
                        $filename = '';
580
                            {
720
                    }
581
                                array_push($attachments, [
721
 
582
                                    'filename' => $filename,
722
                    $dt = \DateTime::createFromFormat('Y-m-d H:i:s', $message->added_on);
583
                                    'content-type' => $contentType,
723
 
584
                                    'attachment_link' =>  $this->url()->fromRoute('inmail/message/attachment',[ 'id' => $email['uid'], 'attachment' => $i ], ['force_canonical' => true]),
-
 
585
                                ]);
724
                    $userMapper->updateLastActivity($currentUser->id);
586
                                $i++;
-
 
587
                            }
725
 
588
                        }
726
 
589
                    }
727
 
590
                    
-
 
591
                    return new JsonModel([
-
 
592
                        'success' => true,
728
                    return new JsonModel([
593
                        'data' => [
729
                        'success'   => true,
594
                            'uuid' => $user->uuid,
730
                        'data'   => [
595
                            'name' => $user->first_name . ' ' . $user->last_name,
731
                            'sender_name' => trim($currentUser->first_name . ' ' . $currentUser->last_name),
596
                            'image' => $storage ? $storage->getUserImage($user) : $this->url()->fromRoute('storage', ['code' => $user->uuid, 'type' => '$user', 'filename' => $user->image]), 
732
                            'sender_image' => $this->url()->fromRoute('storage', ['type' => 'user', 'filename' => $currentUser->image, 'code' => $currentUser->uuid],['force_canonical' => true]),
597
                            'subject' => $subject,
733
                            'sender_profile' => $this->url()->fromRoute('profile/view', ['id' => $currentUser->uuid]),
598
                            'body' => $body,
734
                            'receiver_name' => trim($user->first_name . ' ' . $user->last_name),
-
 
735
                            'receiver_image' => $this->url()->fromRoute('storage', ['type' => 'user', 'filename' => $user->image, 'code' => $user->uuid],['force_canonical' => true]),
599
                            'date' => date('Y-m-d h:i a', $email['date']),
736
                            'receiver_profile' => $this->url()->fromRoute('profile/view', ['id' => $user->uuid]),
600
                            'seen' => $seen,
737
                            'side' => 'left',
601
                            'block_link' => $this->url()->fromRoute('inmail/user/block',[ 'id' => $user->uuid ], ['force_canonical' => true]),
738
                            'message' => $message->message,
-
 
739
                            'type' => $message->type,
-
 
740
                            'filename' => $filename,
-
 
741
                            'date' => $this->timeAgo($now, $now),
-
 
742
                        ]
602
                            'send_link' => $this->url()->fromRoute('inmail/message/send',[ 'id' => $user->uuid ], ['force_canonical' => true]),
743
                    ]);
603
                            'delete_link'=>    $this->url()->fromRoute('inmail/message/delete',[ 'id' => $email['uid'] ], ['force_canonical' => true]),
744
                } else {
604
                            'attachments' => $attachments,
745
                    return new JsonModel([
605
                        ]
746
                        'success'   => false,
606
                    ]);
747
                        'data'   => $messageMapper->getError()
607
                    
-
 
608
                    
-
 
609
                } else {
-
 
610
                    return new JsonModel([
748
                    ]);
611
                        'success' => false,
749
                }
612
                        'data' => 'ERROR_INMAIL_MESSAGE_NOT_FOUND'
750
            } else {
613
                    ]);
751
 
614
                }
752
 
615
                
753
                $messages = [];
616
                
754
                $form_messages = (array) $form->getMessages();
617
            } catch (\Exception $e) {
755
                foreach ($form_messages  as $fieldname => $field_messages) {
-
 
756
                    $messages[$fieldname] = array_values($field_messages);
618
                
757
                }
619
                return new JsonModel([
758
 
620
                    'success' => false,
759
                return new JsonModel([
-
 
760
                    'success'   => false,
-
 
761
                    'data'   => $messages
-
 
762
                ]);
-
 
763
            }
-
 
764
        } else {
-
 
765
            return new JsonModel([
-
 
766
                'success' => false,
-
 
767
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
-
 
768
            ]);
-
 
769
        }
-
 
770
    }
-
 
771
 
-
 
772
 
-
 
773
 
-
 
774
    private function normalizeString($str = '')
-
 
775
    {
-
 
776
        $basename  = substr($str, 0, strrpos($str, '.'));
-
 
777
        $basename  = str_replace('.', '-', $basename);
-
 
778
 
-
 
779
        $extension  = substr($str, strrpos($str, '.'));
-
 
780
 
-
 
781
        $str = $basename . $extension;
-
 
782
 
-
 
783
        $str = strip_tags($str);
-
 
784
        $str = preg_replace('/[\r\n\t ]+/', ' ', $str);
-
 
785
        $str = preg_replace('/[\"\*\/\:\<\>\?\'\|\,]+/', ' ', $str);
-
 
786
        $str = strtolower($str);
-
 
787
        $str = html_entity_decode($str, ENT_QUOTES, "utf-8");
621
                    'data' => 'ERROR_INMAIL_MESSAGE_LIST_UNAVAILABLE'
-
 
622
                ]);
-
 
623
            }
-
 
624
            
-
 
625
            
788
        $str = htmlentities($str, ENT_QUOTES, "utf-8");
626
            
789
        $str = preg_replace("/(&)([a-z])([a-z]+;)/i", '$2', $str);
627
        } else {
-
 
628
            return new JsonModel([
790
        $str = str_replace(' ', '-', $str);
629
                'success' => false,
-
 
630
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
-
 
631
            ]);
-
 
632
        }
-
 
633
    }
-
 
634
    
-
 
635
    
-
 
636
    public function deleteMessageAction()
-
 
637
    {
-
 
638
        $request = $this->getRequest();
-
 
639
        if ($request->isPost()) {
-
 
640
            $currentUserPlugin = $this->plugin('currentUserPlugin');
-
 
641
            $currentUser = $currentUserPlugin->getUser();
-
 
642
            
-
 
643
            $id = intval($this->params()->fromRoute('id'), 10);
-
 
644
            
791
        $str = rawurlencode($str);
645
            $storage = Storage::getInstance($this->config);
792
        $str = str_replace('%', '-', $str);
646
            
793
        return trim(strtolower($str));
647
            $externalCredentials = ExternalCredentials::getInstancia($this->config, $this->adapter);
-
 
648
            $externalCredentials->getUserBy($currentUser->id);
-
 
649
            
-
 
650
            $host       = trim($this->config['leaderslinked.inmail.host']);
794
    }
651
            $port       = intval($this->config['leaderslinked.inmail.port_imap'], 10);
-
 
652
            $mailbox    = trim($this->config['leaderslinked.inmail.mailbox']);
-
 
653
            
795
 
654
            
796
    /**
655
            $username   = $externalCredentials->getUsernameInmail();
797
     *
656
            $password   =  $externalCredentials->getPasswordInmail();
798
     * @param string $timestamp
657
            
-
 
658
            
799
     * @param string $now
659
            
800
     * @return string
660
            
801
     */
661
            try {
802
    private function timeAgo($timestamp, $now = '')
662
                \Eden\Core\Control::i();
803
    {
663
                $client = eden('mail')->imap(
804
        
-
 
805
        if ($now) {
664
                    $host,
806
            $datetime1 = \DateTime::createFromFormat('Y-m-d H:i:s', $now);
665
                    $username,
807
        } else {
666
                    $password,
808
            $now = date('Y-m-d H:i:s');
667
                    $port,
809
            $datetime1 = date_create($now);
668
                    false);
810
        }
-
 
811
        $datetime2 = date_create($timestamp);
669
                
-
 
670
                $client->setActiveMailbox($mailbox);
-
 
671
                
812
        
672
                $response = $client->remove($id, true); 
-
 
673
                $client->disconnect();
-
 
674
              
-
 
675
                if($response) {
813
        $diff = date_diff($datetime1, $datetime2);
676
                    return new JsonModel([
-
 
677
                        'success' => true,
-
 
678
                        'data' => 'LABEL_INMAIL_MESSAGE_DELETED'
-
 
679
                    ]);
-
 
680
                } else {
-
 
681
                    return new JsonModel([
814
        $timemsg = '';
682
                        'success' => false,
-
 
683
                        'data' =>  'ERROR_INMAIL_MESSAGE_NOT_DELETE'
-
 
684
                    ]);
815
        if ($diff->y > 0) {
685
                }
-
 
686
                
816
            $timemsg = $diff->y . ' ' .($diff->y > 1 ? $this->translator->translate('LABEL_YEARS_SMALL')  : $this->translator->translate('LABEL_YEAR_SMALL') );
687
                
817
        } else if ($diff->m > 0) {
-
 
818
            $timemsg = $diff->m  . ' ' .($diff->m > 1 ? $this->translator->translate('LABEL_MONTHS_SMALL')  : $this->translator->translate('LABEL_MONTH_SMALL') );
-
 
819
        } else if ($diff->d > 0) {
688
            } catch (\Exception $e) {
820
            $timemsg = $diff->d . ' ' .($diff->d > 1 ? $this->translator->translate('LABEL_DAYS_SMALL')  : $this->translator->translate('LABEL_DAY_SMALL') );
689
                
821
        } else if ($diff->h > 0) {
690
                return new JsonModel([
822
            $timemsg = $diff->h  . ' ' .($diff->h > 1 ? $this->translator->translate('LABEL_HOURS_SMALL')  : $this->translator->translate('LABEL_HOUR_SMALL') );
691
                    'success' => false,
823
        } else if ($diff->i > 0) {
692
                    'data' => 'ERROR_INMAIL_MESSAGE_LIST_UNAVAILABLE'
824
            $timemsg = $diff->i  . ' ' .($diff->i > 1 ? $this->translator->translate('LABEL_MINUTES_SMALL')  : $this->translator->translate('LABEL_MINUTE_SMALL') );
693
                ]);
825
        } else if ($diff->s > 0) {
694
            }
826
            $timemsg = $diff->s  . ' ' . ($diff->s > 1 ? $this->translator->translate('LABEL_SECONDS_SMALL')  : $this->translator->translate('LABEL_SECOND_SMALL') );
695
            
827
        }
696
            
Línea -... Línea 697...
-
 
697
            
-
 
698
        } else {
828
        if (!$timemsg) {
699
            return new JsonModel([
829
            $timemsg = $this->translator->translate('LABEL_NOW') ;
700
                'success' => false,
830
        } else {
701
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
831
            $timemsg = $this->translator->translate('LABEL_AGO_SMALL') . ' '. $timemsg . '';
702
            ]);
832
        }
703
        }
833
        return $timemsg;
704
    }
834
        
705
    
Línea 835... Línea -...
835
    }
-
 
-
 
706
    
836
 
707
    public function sendMessageAction()
837
 
708
    {
838
    public function deleteAction()
709
        $request = $this->getRequest();
839
    {
710
        if ($request->isPost()) {
840
        $request = $this->getRequest();
711
            $currentUserPlugin = $this->plugin('currentUserPlugin');
841
        if ($request->isPost()) {
712
            $currentUser = $currentUserPlugin->getUser();
842
            $currentUserPlugin = $this->plugin('currentUserPlugin');
713
            
Línea 843... Línea 714...
843
            $currentUser = $currentUserPlugin->getUser();
714
            $userMapper = UserMapper::getInstance($this->adapter);
844
            
715
            
-
 
716
            $id = $this->params()->fromRoute('id');
-
 
717
            if (!$id) {
-
 
718
                return new JsonModel([
-
 
719
                    'success' => false,
-
 
720
                    'data' => 'ERROR_PARAMETERS_ARE_INVALID'
-
 
721
                ]);
-
 
722
            }
-
 
723
            
Línea -... Línea 724...
-
 
724
            
-
 
725
            $user = $userMapper->fetchOneByUuidAndNetworkId($id, $currentUser->network_id);
-
 
726
            if (!$user) {
-
 
727
                return new JsonModel([
-
 
728
                    'success' => false,
-
 
729
                    'data' => 'ERROR_REQUEST_IS_INVALID'
845
            $id = $this->params()->fromRoute('id');
730
                ]);
Línea 846... Línea 731...
846
            if (!$id) {
731
            }
-
 
732
            
-
 
733
            $externalCredentials = ExternalCredentials::getInstancia($this->config, $this->adapter);
847
                return new JsonModel([
734
            $externalCredentials->getUserBy($currentUser->id);
848
                    'success' => false,
735
            
849
                    'data' => 'ERROR_PARAMETERS_ARE_INVALID'
736
            $host       = trim($this->config['leaderslinked.inmail.host']);
850
                ]);
737
            $port       = intval($this->config['leaderslinked.inmail.port_smtp'], 10);
851
            }
738
 
852
            
739
            
853
            $userMapper = UserMapper::getInstance($this->adapter);
740
            $username   = $externalCredentials->getUsernameInmail();
-
 
741
            $password   =  $externalCredentials->getPasswordInmail();
-
 
742
            
-
 
743
            
-
 
744
            
-
 
745
            $data = array_merge($request->getPost()->toArray(), $request->getFiles()->toArray());
-
 
746
     
854
            $user = $userMapper->fetchOneByUuid($id);
747
            
-
 
748
            $form = new SendForm();
-
 
749
            $form->setData($data);
-
 
750
            
Línea 855... Línea -...
855
            if (!$user) {
-
 
856
                return new JsonModel([
-
 
857
                    'success' => false,
-
 
858
                    'data' => 'ERROR_REQUEST_IS_INVALID'
-
 
859
                ]);
751
            if ($form->isValid()) {
-
 
752
                
-
 
753
                $dataPost = (array) $form->getData();
-
 
754
                
-
 
755
                try { 
-
 
756
                    \Eden\Core\Control::i();
-
 
757
                    $smtp = eden('mail')->smtp(
-
 
758
                        $host,
-
 
759
                        $username,
-
 
760
                        $password,
-
 
761
                        $port,
-
 
762
                        false
-
 
763
                    );
-
 
764
                   
-
 
765
                    $smtp->setSubject( $dataPost['subject']);
-
 
766
                    $smtp->setBody( $dataPost['body'], true);
-
 
767
                    $smtp->setBody($dataPost['body']);
-
 
768
                    $smtp->addTo($user->username_inmail);
860
            }
769
    
Línea -... Línea 770...
-
 
770
                    $files  = $this->getRequest()->getFiles()->toArray();
-
 
771
                    if (isset($files['file']) && empty($files['file']['error'])) {
-
 
772
                        $smtp->addAttachment($files['file']['name'], $files['file']['tmp_name']);
-
 
773
                        
861
            
774
                    }
-
 
775
                    
862
            $conversationMapper = ConversationMapper::getInstance($this->adapter);
776
                    
863
            $conversation = $conversationMapper->fetchOneByUserId1AndUserId2($currentUser->id, $user->id);
777
                    
864
            
778
                    $smtp->send();
865
            
779
                    
866
            if ($conversation) {
780
                    $smtp->disconnect(); 
867
                
781
                    
868
                if ($conversation->sender_id == $currentUser->id && $conversation->receiver_id == $user->id) {
782
                    return new JsonModel([
869
                    $conversation->sender_status = Conversation::STATUS_DELETED;
-
 
-
 
783
                        'success'   => true,
-
 
784
                        'data'   => 'LABEL_INMAIL_MESSAGE_SENT'
-
 
785
                    ]);
-
 
786
                    
-
 
787
                } catch (\Exception $e) {
870
                    if ($conversationMapper->update($conversation)) {
788
                    return new JsonModel([
871
                        $response = [
789
                        'success'   => false,
872
                            'success' => true,
790
                        'data'   => 'ERROR_INMAIL_MESSAGE_NOT_SENT'
873
                            'data' => 'LABEL_CONVERSATION_WAS_DELETED'
791
                    ]);
874
                        ];
792
                }
875
                    } else {
-
 
-
 
793
                
876
                        
794
                $phpMailer = new PHPMailer();
Línea 877... Línea -...
877
                        
-
 
Línea -... Línea 795...
-
 
795
                $phpMailer->isSMTP();
-
 
796
                
-
 
797
                $phpMailer->addAddress($user->username_inmail, $user->first_name . ' ' . $user->last_name);
-
 
798
                $phpMailer->setFrom($currentUser->username_inmail, $currentUser->first_name . ' ' . $currentUser->last_name);
-
 
799
                $phpMailer->SMTPDebug    = false;
-
 
800
                $phpMailer->Host         = $host;
-
 
801
                $phpMailer->Port         = $port;
-
 
802
                $phpMailer->IsHTML(true);
-
 
803
                $phpMailer->SMTPAuth    = true;
-
 
804
                //$phpMailer->SMTPSecure   = 'tls';
-
 
805
                $phpMailer->SMTPAuth     = true;
-
 
806
                $phpMailer->Username     = $username;
-
 
807
                $phpMailer->Password     = $password;
-
 
808
                $phpMailer->Subject      = $dataPost['subject'];
-
 
809
                $phpMailer->Body         = $dataPost['body'];
-
 
810
                $phpMailer->AltBody      = $dataPost['body'];
878
                        $response = [
811
                $phpMailer->CharSet      = 'UTF-8';
-
 
812
                
-
 
813
                $files  = $this->getRequest()->getFiles()->toArray();
879
                            'success' => false,
814
                if (isset($files['file']) && empty($files['file']['error'])) {
-
 
815
                    $phpMailer->addAttachment($files['file']['tmp_name'],
-
 
816
                        $files['file']['name']);
-
 
817
            
-
 
818
                }
-
 
819
                
-
 
820
                
880
                            'data' => $conversationMapper->getError()
821
                
881
                        ];
822
                
882
                    }
823
                
883
                }
824
                if($phpMailer->send()) {
884
                
-
 
885
                if ($conversation->receiver_id == $currentUser->id && $conversation->sender_id == $user->id) {
-
 
886
                    $conversation->receiver_status = Conversation::STATUS_DELETED;
825
                    return new JsonModel([
887
                    if ($conversationMapper->update($conversation)) {
826
                        'success'   => true,
888
                        $response = [
827
                        'data'   => 'LABEL_INMAIL_MESSAGE_SENT'
889
                            'success' => true,
828
                    ]);
890
                            'data' => 'LABEL_CONVERSATION_WAS_DELETED'
829
                } else {
891
                        ];
830
              
892
                    } else {
-
 
893
                        
-
 
894
                        
831
               
-
 
832
                    return new JsonModel([
-
 
833
                        'success'   => false,
895
                        $response = [
834
                        'data'   => 'ERROR_INMAIL_MESSAGE_NOT_SENT'
-
 
835
                    ]);