Proyectos de Subversion LeadersLinked - Services

Rev

Rev 812 | Rev 814 | Ir a la última revisión | | Comparar con el anterior | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 1
<?php
2
 
3
declare(strict_types=1);
4
 
5
namespace LeadersLinked\Controller;
6
 
7
 
8
use Laminas\Mvc\Controller\AbstractActionController;
283 www 9
 
1 efrain 10
use Laminas\View\Model\JsonModel;
11
use LeadersLinked\Model\Page;
12
use LeadersLinked\Mapper\NotificationMapper;
13
use LeadersLinked\Mapper\PageMapper;
14
use LeadersLinked\Mapper\UserMapper;
15
use LeadersLinked\Mapper\ConnectionMapper;
16
 
17
use LeadersLinked\Mapper\PostMapper;
18
use LeadersLinked\Model\Post;
19
 
20
use LeadersLinked\Mapper\FeedMapper;
21
use LeadersLinked\Model\Feed;
22
use LeadersLinked\Model\User;
23
use LeadersLinked\Model\Connection;
24
use LeadersLinked\Mapper\NetworkMapper;
25
use LeadersLinked\Library\Functions;
26
use LeadersLinked\Model\Network;
27
 
257 efrain 28
use LeadersLinked\Library\ExternalCredentials;
341 www 29
use Nullix\CryptoJsAes\CryptoJsAes;
345 www 30
use LeadersLinked\Library\Storage;
257 efrain 31
 
1 efrain 32
class HomeController extends AbstractActionController
33
{
34
    /**
35
     *
36
     * @var \Laminas\Db\Adapter\AdapterInterface
37
     */
38
    private $adapter;
39
 
40
    /**
41
     *
42
     * @var \LeadersLinked\Cache\CacheInterface
43
     */
44
    private $cache;
45
 
46
 
47
    /**
48
     *
49
     * @var \Laminas\Log\LoggerInterface
50
     */
51
    private $logger;
52
 
53
    /**
54
     *
55
     * @var array
56
     */
57
    private $config;
58
 
59
 
60
    /**
61
     *
62
     * @var \Laminas\Mvc\I18n\Translator
63
     */
64
    private $translator;
65
 
66
 
67
    /**
68
     *
69
     * @param \Laminas\Db\Adapter\AdapterInterface $adapter
70
     * @param \LeadersLinked\Cache\CacheInterface $cache
71
     * @param \Laminas\Log\LoggerInterface LoggerInterface $logger
72
     * @param array $config
73
     * @param \Laminas\Mvc\I18n\Translator $translator
74
     */
75
    public function __construct($adapter, $cache, $logger, $config, $translator)
76
    {
77
        $this->adapter      = $adapter;
78
        $this->cache        = $cache;
79
        $this->logger       = $logger;
80
        $this->config       = $config;
81
        $this->translator   = $translator;
82
    }
341 www 83
 
84
    public function cryptoAction()
85
    {
86
        header('Content-type: text/plain');
87
 
88
 
343 www 89
        $email = '{"ct":"eZd1aD5p3miv+UsN/7CfAst+8U/Tu4de/n5Rmaf/VsicEYlJG3DH4JvRoxCUwcSA","iv":"8abe13978c33e8701857c6377f09864c","s":"cb61b5d25010408b"}';
90
        $password  = '{"ct":"v5maMXocpQT5Jr02vBzXhw==","iv":"a2f8244c89dd690c60ded5f49092d552","s":"522aeee2356f0677"}';
341 www 91
        $aes = 'HP8Rc6vBnr2CJyVG';
92
 
93
        echo "Email = $email \r\n";
94
        echo "Password = $password \r\n";
95
        echo "AES = $aes \r\n\r\n";
96
 
97
        $emailDecrypt  = CryptoJsAes::decrypt($email, $aes);
98
        $passwordDecrypt  = CryptoJsAes::decrypt($password, $aes);
99
 
100
        echo "EmailDecrypt = $emailDecrypt \r\n";
101
        echo "PasswordDecrypt = $passwordDecrypt \r\n";
102
 
103
        exit;
104
    }
1 efrain 105
 
333 www 106
 
107
    public function storageAction()
108
    {
109
        $currentNetworkPlugin = $this->plugin('currentNetworkPlugin');
110
        $currentNetwork = $currentNetworkPlugin->getNetwork();
111
 
112
        $request = $this->getRequest();
113
        if ($request->isGet()) {
114
 
115
            $code = $this->params()->fromRoute('code');
116
            if(empty($code)) {
117
                $data = [
118
                    'success' => false,
119
                    'data' => 'ERROR_STORAGE_CODE_INVALID'
120
                ];
121
 
122
                return new JsonModel($data);
123
            }
124
 
125
            $storageFileMapper = \LeadersLinked\Mapper\StorageFileMapper::getInstance($this->adapter);
126
            $storageFile = $storageFileMapper->fetchOneByCode($code);
127
 
812 stevensc 128
            $storageDir = $this->config['leaderslinked'] ?? '';
809 stevensc 129
            $storageFileFullPath = $storageDir . DIRECTORY_SEPARATOR . $storageFile->path;
333 www 130
 
807 stevensc 131
            if($storageFileFullPath) {
132
                if(file_exists($storageFileFullPath)) {
333 www 133
 
770 stevensc 134
                    // Check if the path is a directory instead of a file
807 stevensc 135
                    if(is_dir($storageFileFullPath)) {
770 stevensc 136
                        $this->logger->err('StorageFile path is a directory instead of a file: ' . $storageFile->path . ' (code: ' . $code . ')');
137
                        return $this->getResponse()->setStatusCode(500);
138
                    }
139
 
333 www 140
                    // Try to open file
807 stevensc 141
                    if (!is_readable($storageFileFullPath)) {
333 www 142
                        return $this->getResponse()->setStatusCode(500);
143
                    }
144
 
145
                    // Get file size in bytes.
807 stevensc 146
                    $fileSize = filesize($storageFileFullPath);
333 www 147
 
148
                    // Get MIME type of the file.
807 stevensc 149
                    $mimeType = mime_content_type($storageFileFullPath);
333 www 150
                    if($mimeType===false) {
151
                        $mimeType = 'application/octet-stream';
152
                    }
153
 
810 stevensc 154
                    $fileContent = file_get_contents($storageFile->path);
333 www 155
 
156
                    $response = $this->getResponse();
157
                    $headers = $response->getHeaders();
158
                    $headers->addHeaderLine('Content-type: ' . $mimeType);
159
                    $headers->addHeaderLine('Content-length: ' . $fileSize);
160
 
161
                    if($fileContent!==false) {
162
                        $response->setContent($fileContent);
163
                        return $response;
164
                    } else {
165
                        $this->getResponse()->setStatusCode(500);
166
                        return;
167
                    }
168
                } else {
813 stevensc 169
                    $this->logger->err('storageFileFullPath not found = ' . $storageFileFullPath);
333 www 170
                    return $this->getResponse()->setStatusCode(404);
171
                }
172
            } else {
173
                return $this->getResponse()->setStatusCode(404);
174
            }
175
 
176
        } else {
177
            $data = [
178
                'success' => false,
179
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
180
            ];
181
 
182
            return new JsonModel($data);
183
        }
184
    }
1 efrain 185
 
186
 
764 stevensc 187
    public function dataStorageAction()
188
    {
189
        $request = $this->getRequest();
190
        if ($request->isGet()) {
191
 
192
            $type = $this->params()->fromRoute('type');
193
            $uuid = $this->params()->fromRoute('uuid');
194
            $filename = $this->params()->fromRoute('filename');
195
 
196
            if(empty($type) || empty($uuid) || empty($filename)) {
197
                return $this->getResponse()->setStatusCode(404);
198
            }
199
 
200
            // Map type to config key
201
            $configKey = 'leaderslinked.fullpath.' . $type;
202
            if(!isset($this->config[$configKey])) {
203
                return $this->getResponse()->setStatusCode(404);
204
            }
205
 
206
            // Build the file path using the configured base path
207
            $basePath = $this->config[$configKey];
208
            $filePath = $basePath . $uuid . DIRECTORY_SEPARATOR . $filename;
209
 
210
            // Security check: ensure the path is within the allowed directory
211
            $realFilePath = realpath($filePath);
212
            $realBasePath = realpath($basePath);
213
            if(!$realFilePath || !$realBasePath || strpos($realFilePath, $realBasePath) !== 0) {
214
                return $this->getResponse()->setStatusCode(403);
215
            }
216
 
217
            if(file_exists($realFilePath)) {
218
 
219
                // Try to open file
220
                if (!is_readable($realFilePath)) {
221
                    return $this->getResponse()->setStatusCode(500);
222
                }
223
 
224
                // Get file size in bytes.
225
                $fileSize = filesize($realFilePath);
226
 
227
                // Get MIME type of the file.
228
                $mimeType = mime_content_type($realFilePath);
229
                if($mimeType===false) {
230
                    $mimeType = 'application/octet-stream';
231
                }
232
 
233
                $fileContent = file_get_contents($realFilePath);
234
 
235
                $response = $this->getResponse();
236
                $headers = $response->getHeaders();
237
                $headers->addHeaderLine('Content-type: ' . $mimeType);
238
                $headers->addHeaderLine('Content-length: ' . $fileSize);
239
 
240
                if($fileContent!==false) {
241
                    $response->setContent($fileContent);
242
                    return $response;
243
                } else {
244
                    return $this->getResponse()->setStatusCode(500);
245
                }
246
            } else {
247
                return $this->getResponse()->setStatusCode(404);
248
            }
249
 
250
        } else {
251
            $data = [
252
                'success' => false,
253
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
254
            ];
255
 
256
            return new JsonModel($data);
257
        }
258
    }
259
 
260
 
1 efrain 261
    public function indexAction()
262
    {
263
        /*
264
        if(!empty($this->config['leaderslinked.runmode.autologin'])) {
265
 
266
            $currentNetworkPlugin = $this->plugin('currentNetworkPlugin');
267
            $currentNetwork = $currentNetworkPlugin->getNetwork();
268
 
269
            $authService = new AuthenticationService();
270
            if(!$authService->hasIdentity()) {
271
                $adapter = new AuthEmailAdapter($this->adapter);
272
                $adapter->setData('santiago.olivera@leaderslinked.com',  $currentNetwork->id);
273
 
274
                $authService->authenticate($adapter);
275
            }
276
        }
257 efrain 277
        /*
1 efrain 278
        $currentUserPlugin = $this->plugin('currentUserPlugin');
279
        if ($currentUserPlugin->hasIdentity()) {
280
            return $this->redirect()->toRoute('dashboard');
281
        } else {
282
            return $this->redirect()->toRoute('signin');
283
        }*/
284
 
285
        $currentNetworkPlugin = $this->plugin('currentNetworkPlugin');
286
        $currentNetwork = $currentNetworkPlugin->getNetwork();
287
 
288
        $request = $this->getRequest();
289
        if ($request->isGet()) {
290
 
291
            $currentUserPlugin = $this->plugin('currentUserPlugin');
292
 
293
            if (empty($_SESSION['aes'])) {
294
                $_SESSION['aes'] = Functions::generatePassword(16);
295
            }
296
 
297
            if ($this->config['leaderslinked.runmode.sandbox']) {
298
                $site_key      = $this->config['leaderslinked.google_captcha.sandbox_site_key'];
299
            } else {
300
                $site_key      = $this->config['leaderslinked.google_captcha.production_site_key'];
301
            }
302
 
303
            $access_usign_social_networks = $this->config['leaderslinked.runmode.access_usign_social_networks'];
304
 
305
 
306
 
307
            $sandbox = $this->config['leaderslinked.runmode.sandbox'];
308
            if ($sandbox) {
309
                $google_map_key  = $this->config['leaderslinked.google_map.sandbox_api_key'];
310
            } else {
311
                $google_map_key  = $this->config['leaderslinked.google_map.production_api_key'];
312
            }
257 efrain 313
 
314
 
315
 
1 efrain 316
 
257 efrain 317
            $data = [
1 efrain 318
                'site_key'  => $site_key,
319
                'google_map_key' => $google_map_key,
320
                'aes'       => $_SESSION['aes'],
321
                'defaultNetwork' => $currentNetwork->default,
322
                'is_logged_in' =>  $currentUserPlugin->hasIdentity() ? true : false,
7 efrain 323
                'access_usign_social_networks' => $access_usign_social_networks &&  $currentNetwork && $currentNetwork->default == Network::DEFAULT_YES ? 'y' : 'n',
257 efrain 324
            ];
1 efrain 325
 
257 efrain 326
            if($currentNetwork->default == Network::DEFAULT_YES) {
327
                $currentUserPlugin = $this->plugin('currentUserPlugin');
328
                if ($currentUserPlugin->hasIdentity()) {
329
                  $externalCredentials = ExternalCredentials::getInstancia($this->config, $this->adapter);
330
                  $externalCredentials->getUserBy($currentUserPlugin->getUserId());
331
 
332
                  if($currentNetwork->xmpp_active) {
333
                      $data['xmpp_domain']      = $currentNetwork->xmpp_domain;
334
                      $data['xmpp_hostname']    = $currentNetwork->xmpp_hostname;
335
                      $data['xmpp_port']        = $currentNetwork->xmpp_port;
336
                      $data['xmpp_username']    = $externalCredentials->getUsernameXmpp();
337
                      $data['xmpp_password']    = $externalCredentials->getPasswordXmpp();
283 www 338
                      $data['inmail_username']    = $externalCredentials->getUsernameInmail();
339
                      $data['inmail_password']    = $externalCredentials->getPasswordInmail();
257 efrain 340
                  }
341
                }
342
            }
343
 
344
            return  new JsonModel($data);
345
 
1 efrain 346
 
347
        } else {
348
            $data = [
349
                'success' => false,
350
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
351
            ];
352
 
353
            return new JsonModel($data);
354
        }
355
 
356
    }
357
 
754 stevensc 358
    public function themeAction()
359
    {
360
        $currentNetworkPlugin = $this->plugin('currentNetworkPlugin');
361
        $currentNetwork = $currentNetworkPlugin->getNetwork();
1 efrain 362
 
754 stevensc 363
        $request = $this->getRequest();
364
 
365
        if(!$request->isGet()) {
366
            $data = [
367
                'success' => false,
368
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
369
            ];
370
 
371
            return new JsonModel($data);
372
        }
1 efrain 373
 
754 stevensc 374
        if(!$currentNetwork) {
375
            $data = [
376
                'success' => false,
377
                'data' => 'ERROR_NETWORK_NOT_FOUND'
378
            ];
1 efrain 379
 
754 stevensc 380
            return new JsonModel($data);
381
        }
382
 
383
        $data = [
384
            'success' => true,
385
            'theme' => [
386
                'bg-color' => $currentNetwork->css_bg_color,
387
                'body-bg-color' => $currentNetwork->css_body_bg_color,
388
                'bg-color-secondary' => $currentNetwork->css_bg_color_secondary,
389
                'font-color' => $currentNetwork->css_font_color,
390
                'font-color-hover' => $currentNetwork->css_font_color_hover,
391
                'title-color' => $currentNetwork->css_title_color,
392
                'subtitle-color' => $currentNetwork->css_subtitle_color,
393
                'icons-color' => $currentNetwork->css_icons_color,
394
                'button-bg' => $currentNetwork->css_button_bg,
395
                'button-bg-hover' => $currentNetwork->css_button_bg_hover,
396
                'button-text-color' => $currentNetwork->css_button_text_color,
397
                'button-bg-secondary' => $currentNetwork->css_button_bg_secondary,
398
                'button-bg-secondary-hover' => $currentNetwork->css_button_bg_secondary_hover,
399
                'button-text-color-secondary' => $currentNetwork->css_button_text_color_secondary,
400
                'button-bg-tertiary' => $currentNetwork->css_button_bg_tertiary,
401
                'button-text-color-tertiary' => $currentNetwork->css_button_text_color_tertiary,
402
                'border-primary' => $currentNetwork->css_border_primary,
403
                'border-trasnparent' => $currentNetwork->css_border_trasnparent,
404
                'chat-received' => $currentNetwork->css_chat_received,
405
                'chat-send' => $currentNetwork->css_chat_send,
406
                'chat-color' => $currentNetwork->css_chat_color,
407
                'light-gray' => $currentNetwork->css_light_gray,
408
                'gray' => $currentNetwork->css_gray,
409
                'danger' => $currentNetwork->css_danger,
410
                'danger-hover' => $currentNetwork->css_danger_hover,
411
                'online-green' => $currentNetwork->css_online_green,
412
                'border-gray-primary' => $currentNetwork->css_border_gray_primary,
413
                'white' => $currentNetwork->css_white,
414
                'white-backdrop' => $currentNetwork->css_white_backdrop,
415
                'border-radius' => $currentNetwork->css_border_radius,
416
                'light-shadow' => $currentNetwork->css_light_shadow,
417
                'shadow' => $currentNetwork->css_shadow
418
            ]
419
        ];
420
 
421
        return new JsonModel($data);
422
    }
423
 
1 efrain 424
    public function privacyPolicyAction()
425
    {
426
 
427
 
428
 
429
 
430
        $pageCode = Page::PAGE_CODE_PRIVACY_POLICY;
431
 
432
        $currentNetworkPlugin = $this->plugin('currentNetworkPlugin');
433
        $currentNetwork = $currentNetworkPlugin->getNetwork();
434
 
435
        $currentUserPlugin = $this->plugin('currentUserPlugin');
436
 
437
        $pageMapper = PageMapper::getInstance($this->adapter);
438
        $page = $pageMapper->fetchOneByCodeAndNetworkId($pageCode, $currentNetwork->id);
439
 
440
        if (!$page) {
441
            $networkMapper = NetworkMapper::getInstance($this->adapter);
442
            $network = $networkMapper->fetchOneByDefault();
443
 
444
            $pageDefault = $pageMapper->fetchOneByCodeAndNetworkId($pageCode, $network->id);
445
            if ($pageDefault) {
446
                $page = new Page();
447
                $page->network_id = $currentNetwork->id;
448
                $page->code = $pageDefault->code;
449
                $page->content = $pageDefault->content;
450
                $page->fixed = $pageDefault->fixed;
451
                $page->page_default_id = $pageDefault->id;
452
                $page->title = $pageDefault->title;
453
                $page->status = $pageDefault->status;
454
                $page->type = $pageDefault->type;
455
                $page->url = $pageDefault->url;
456
 
457
                $pageMapper->insert($page);
458
            }
459
        }
460
 
461
        return new JsonModel([
462
            'success' => true,
463
            'data' => [
464
                'title' => $page->title,
465
                'content' => $page->content
466
            ]
467
        ]);
468
 
469
    }
470
 
471
    public function cookiesAction()
472
    {
473
 
474
        $pageCode = Page::PAGE_CODE_COOKIES;
475
 
476
        $currentNetworkPlugin = $this->plugin('currentNetworkPlugin');
477
        $currentNetwork = $currentNetworkPlugin->getNetwork();
478
 
479
        $currentUserPlugin = $this->plugin('currentUserPlugin');
480
 
481
        $pageMapper = PageMapper::getInstance($this->adapter);
482
        $page = $pageMapper->fetchOneByCodeAndNetworkId($pageCode, $currentNetwork->id);
483
 
484
        if (!$page) {
485
            $networkMapper = NetworkMapper::getInstance($this->adapter);
486
            $network = $networkMapper->fetchOneByDefault();
487
 
488
            $pageDefault = $pageMapper->fetchOneByCodeAndNetworkId($pageCode, $network->id);
489
            if ($pageDefault) {
490
                $page = new Page();
491
                $page->network_id = $currentNetwork->id;
492
                $page->code = $pageDefault->code;
493
                $page->content = $pageDefault->content;
494
                $page->fixed = $pageDefault->fixed;
495
                $page->page_default_id = $pageDefault->id;
496
                $page->title = $pageDefault->title;
497
                $page->status = $pageDefault->status;
498
                $page->type = $pageDefault->type;
499
                $page->url = $pageDefault->url;
500
 
501
                $pageMapper->insert($page);
502
            }
503
        }
504
 
505
        return new JsonModel([
506
            'success' => true,
507
            'data' => [
508
                'title' => $page->title,
509
                'content' => $page->content
510
            ]
511
        ]);
512
    }
513
 
514
    public function professionalismPolicyAction()
515
    {
516
        $pageCode = Page::PAGE_CODE_PROFESSIONALISM_POLICY;
517
 
518
        $currentNetworkPlugin = $this->plugin('currentNetworkPlugin');
519
        $currentNetwork = $currentNetworkPlugin->getNetwork();
520
 
521
        $currentUserPlugin = $this->plugin('currentUserPlugin');
522
 
523
 
524
        $pageMapper = PageMapper::getInstance($this->adapter);
525
        $page = $pageMapper->fetchOneByCodeAndNetworkId($pageCode, $currentNetwork->id);
526
 
527
        if (!$page) {
528
            $networkMapper = NetworkMapper::getInstance($this->adapter);
529
            $network = $networkMapper->fetchOneByDefault();
530
 
531
            $pageDefault = $pageMapper->fetchOneByCodeAndNetworkId($pageCode, $network->id);
532
            if ($pageDefault) {
533
                $page = new Page();
534
                $page->network_id = $currentNetwork->id;
535
                $page->code = $pageDefault->code;
536
                $page->content = $pageDefault->content;
537
                $page->fixed = $pageDefault->fixed;
538
                $page->page_default_id = $pageDefault->id;
539
                $page->title = $pageDefault->title;
540
                $page->status = $pageDefault->status;
541
                $page->type = $pageDefault->type;
542
                $page->url = $pageDefault->url;
543
 
544
                $pageMapper->insert($page);
545
            }
546
        }
547
 
548
        return new JsonModel([
549
            'success' => true,
550
            'data' => [
551
                'title' => $page->title,
552
                'content' => $page->content
553
            ]
554
        ]);
555
    }
556
 
557
 
558
    public function termsAndConditionsAction()
559
    {
560
        $pageCode = Page::PAGE_CODE_TERMS_AND_CONDITIONS;
561
 
562
        $currentNetworkPlugin = $this->plugin('currentNetworkPlugin');
563
        $currentNetwork = $currentNetworkPlugin->getNetwork();
564
 
565
        $currentUserPlugin = $this->plugin('currentUserPlugin');
566
 
567
 
568
        $pageMapper = PageMapper::getInstance($this->adapter);
569
        $page = $pageMapper->fetchOneByCodeAndNetworkId($pageCode, $currentNetwork->id);
570
 
571
        if (!$page) {
572
            $networkMapper = NetworkMapper::getInstance($this->adapter);
573
            $network = $networkMapper->fetchOneByDefault();
574
 
575
            $pageDefault = $pageMapper->fetchOneByCodeAndNetworkId($pageCode, $network->id);
576
            if ($pageDefault) {
577
                $page = new Page();
578
                $page->network_id = $currentNetwork->id;
579
                $page->code = $pageDefault->code;
580
                $page->content = $pageDefault->content;
581
                $page->fixed = $pageDefault->fixed;
582
                $page->page_default_id = $pageDefault->id;
583
                $page->title = $pageDefault->title;
584
                $page->status = $pageDefault->status;
585
                $page->type = $pageDefault->type;
586
                $page->url = $pageDefault->url;
587
 
588
                $pageMapper->insert($page);
589
            }
590
        }
591
 
592
        return new JsonModel([
593
            'success' => true,
594
            'data' => [
595
                'title' => $page->title,
596
                'content' => $page->content
597
            ]
598
        ]);
599
    }
600
 
601
    public function checkSessionAction()
602
    {
603
 
604
        $request = $this->getRequest();
605
        if ($request->isGet()) {
606
 
607
            $currentUserPlugin = $this->plugin('currentUserPlugin');
608
            if (!$currentUserPlugin->hasIdentity()) {
609
                //$flashMessenger = $this->plugin('FlashMessenger');
610
                //$flashMessenger->addErrorMessage('ERROR_SESSION_NOT_FOUND');
611
 
612
                $response = [
613
                    'success' => false,
614
                    'data' => [
615
                        'message' =>  '', //ERROR_SESSION_NOT_FOUND',
616
                        'url' => $this->url()->fromRoute('signout')
617
                    ]
618
                ];
619
 
620
                return new JsonModel($response);
621
            }
622
 
623
            $currentUser = $currentUserPlugin->getUser();
624
 
625
 
626
            if ($currentUser->last_activity_on) {
627
                $last_activity_on = strtotime($currentUser->last_activity_on);
628
            } else {
629
                $last_activity_on = strtotime('-1 day');
630
            }
631
 
632
            $expiry_time = $last_activity_on + $this->config['leaderslinked.security.last_activity_expired'];
633
            if (time() > $expiry_time) {
634
                //$flashMessenger = $this->plugin('FlashMessenger');
635
                //$flashMessenger->addErrorMessage('ERROR_SESSION_EXPIRED');
636
 
637
                $response = [
638
                    'success' => false,
639
                    'data' => [
640
                        'message' => 'ERROR_SESSION_EXPIRED',
641
                        'url' => $this->url()->fromRoute('signout')
642
                    ]
643
                ];
644
            } else {
645
                $notificationMapper = NotificationMapper::getInstance($this->adapter);
646
                $total_notifications = $notificationMapper->fetchUnreadNotificationsCount($currentUser->id);
647
 
283 www 648
                /*
1 efrain 649
                $messageMapper = MessageMapper::getInstance($this->adapter);
283 www 650
                $total_messages =  $messageMapper->fetchCountUnreadMessagesReceiverId($currentUser->id);*/
651
 
652
                $total_messages = 0;
1 efrain 653
                $response = [
654
                    'success' => true,
655
                    'data' => [
656
                        'total_notifications' => $total_notifications,
657
                        'total_messages' => $total_messages
658
                    ]
659
                ];
660
            }
661
        } else {
662
            $response = [
663
                'success' => false,
664
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
665
            ];
666
        }
667
 
668
        return new JsonModel($response);
669
    }
670
 
671
 
672
 
673
 
674
 
675
    public function incTotalExternalSharedAction()
676
    {
677
 
678
        $request = $this->getRequest();
679
        if ($request->isPost()) {
680
            $currentUserPlugin = $this->plugin('currentUserPlugin');
681
            $currentUser = $currentUserPlugin->getUser();
682
 
683
            $currentNetworkPlugin = $this->plugin('currentNetworkPlugin');
684
            $currentNetwork = $currentNetworkPlugin->getNetwork();
685
 
686
            $code       = $this->params()->fromRoute('code');
687
            $type       = $this->params()->fromRoute('type');
688
            $user       = $this->params()->fromRoute('user');
689
            $timestamp  = intval($this->params()->fromRoute('timestamp'), 10);
690
            $rand       = intval($this->params()->fromRoute('rand'), 10);
691
            $password   = $this->params()->fromRoute('password');
692
 
693
 
694
 
695
            $checkpassword = '';
696
 
697
 
698
            $userCheck = '';
699
            if ($user && $timestamp > 0 && $rand > 0 && $password) {
700
                $userMapper = UserMapper::getInstance($this->adapter);
701
                $userCheck = $userMapper->fetchOneByUuid($user);
702
                if ($userCheck) {
703
                    $checkpassword  = md5('user-' . $userCheck->uuid . '-' . $type . '-' . $code . '-timestamp-' . $timestamp . '-rand-' . $rand . '-share-key-' . $userCheck->share_key);
704
                }
705
            }
706
 
707
            if (empty($password) || $password != $checkpassword) {
708
                $data = [
709
                    'success' => false,
710
                    'data' => 'ERROR_UNAUTHORIZED'
711
                ];
712
 
713
                return new JsonModel($data);
714
            }
715
 
716
 
717
 
718
 
719
 
720
 
721
 
722
 
723
 
724
            if ($type == 'feed' && $code) {
725
                $feedMapper =  FeedMapper::getInstance($this->adapter);
726
                $feed = $feedMapper->fetchOneByUuidAnyStatus($code);
727
 
728
 
729
                if ($feed) {
730
 
731
                    if ($feed->network_id != $currentNetwork->id) {
732
                        $data = [
733
                            'success' => false,
734
                            'data' =>    'ERROR_UNAUTHORIZED'
735
                        ];
736
 
737
                        return new JsonModel($data);
738
                    }
739
 
740
                    if ($feedMapper->incTotalExternalShared($feed->id)) {
741
                        $total = $feedMapper->fetchTotalExternalShared($feed->id);
742
 
743
                        $this->logger->info('El usuario : ' . trim($currentUser->first_name . ' ' . $currentUser->last_name) . ' (' . $currentUser->email . ') compartio externamente el feed : ' . $feed->title);
744
 
745
                        $data = [
746
                            'success' => true,
747
                            'data' => $total,
748
                        ];
749
 
750
                        return new JsonModel($data);
751
                    } else {
752
                        $data = [
753
                            'success' => false,
754
                            'data' => $feedMapper->getError()
755
                        ];
756
 
757
                        return new JsonModel($data);
758
                    }
759
                } else {
760
                    $data = [
761
                        'success' => false,
762
                        'data' => 'ERROR_FEED_NOT_FOUND',
763
                    ];
764
 
765
                    return new JsonModel($data);
766
                }
767
            } else if ($type == 'post' && $code) {
768
 
769
                $postMapper = PostMapper::getInstance($this->adapter);
770
                $post = $postMapper->fetchOneByUuid($code);
771
 
772
                if ($post && $post->status == Post::STATUS_ACTIVE) {
773
 
774
                    if ($post->network_id != $currentNetwork->id) {
775
                        $data = [
776
                            'success' => false,
777
                            'data' =>    'ERROR_UNAUTHORIZED'
778
                        ];
779
 
780
                        return new JsonModel($data);
781
                    }
782
 
783
 
784
                    if ($postMapper->incTotalExternalShared($post->id)) {
785
                        $total = $postMapper->fetchTotalExternalShared($post->id);
786
 
787
                        $this->logger->info('El usuario : ' . trim($currentUser->first_name . ' ' . $currentUser->last_name) . ' (' . $currentUser->email . ') compartio externamente el post : ' . $post->title);
788
 
789
 
790
 
791
                        $data = [
792
                            'success' => true,
793
                            'data' => $total,
794
                        ];
795
 
796
                        return new JsonModel($data);
797
                    } else {
798
                        $data = [
799
                            'success' => false,
800
                            'data' => $postMapper->getError()
801
                        ];
802
 
803
                        return new JsonModel($data);
804
                    }
805
                } else {
806
                    $data = [
807
                        'success' => false,
808
                        'data' => 'ERROR_POST_NOT_FOUND'
809
                    ];
810
 
811
                    return new JsonModel($data);
812
                }
813
            }
814
        } else {
815
            $response = [
816
                'success' => false,
817
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
818
            ];
819
 
820
            return new JsonModel($response);
821
        }
822
    }
823
 
247 efrain 824
 
825
 
826
    public function languageAction()
827
    {
828
        $request = $this->getRequest();
829
 
830
        if ($request->isGet()) {
831
 
832
 
833
 
834
            $pathname = dirname(__DIR__);
835
            $filename = $pathname . DIRECTORY_SEPARATOR . 'i18n' . DIRECTORY_SEPARATOR . 'spanish.php';
836
 
837
 
838
            if(file_exists($filename)) {
839
 
840
                $arr =  include $filename;
841
                $arr = array_filter($arr, function($a)  {
842
                    return strpos($a, 'LABEL_') !== false;
843
                }, ARRAY_FILTER_USE_KEY);
844
 
845
 
846
                $data = [];
847
                foreach($arr as $key => $value)
848
                {
849
                    $key = str_replace('LABEL_', 'LANG_', $key);
850
 
851
                    $data[ $key ] = $value;
852
 
853
                }
854
 
855
 
856
 
857
                $response = [
858
                    'success' => true,
859
                    'data' => $data
860
                ];
861
 
862
                return new JsonModel($response);
863
 
864
 
865
            } else {
866
                $response = [
867
                    'success' => false,
868
                    'data' => 'ERROR_METHOD_NOT_ALLOWED'
869
                ];
870
 
871
                return new JsonModel($response);
872
            }
873
 
874
 
875
 
876
 
877
 
878
        } else {
879
            $response = [
880
                'success' => false,
881
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
882
            ];
883
 
884
            return new JsonModel($response);
885
        }
886
 
887
 
888
    }
889
 
1 efrain 890
    public function shareAction()
891
    {
892
        $request = $this->getRequest();
893
        if ($request->isGet()) {
894
            $currentUserPlugin = $this->plugin('currentUserPlugin');
895
            $currentUser = $currentUserPlugin->getUser();
247 efrain 896
 
1 efrain 897
            $code       = $this->params()->fromRoute('code');
898
            $type       = $this->params()->fromRoute('type');
899
            $user       = $this->params()->fromRoute('user');
900
            $timestamp  = intval($this->params()->fromRoute('timestamp'), 10);
901
            $rand       = intval($this->params()->fromRoute('rand'), 10);
902
            $password   = $this->params()->fromRoute('password');
247 efrain 903
 
904
 
905
 
1 efrain 906
            $checkpassword = '';
247 efrain 907
 
908
 
1 efrain 909
            $userCheck = '';
910
            if ($user && $timestamp > 0 && $rand > 0 && $password) {
911
                $userMapper = UserMapper::getInstance($this->adapter);
912
                $userCheck = $userMapper->fetchOneByUuid($user);
913
                if ($userCheck) {
914
                    $checkpassword  = md5('user-' . $userCheck->uuid . '-' . $type . '-' . $code . '-timestamp-' . $timestamp . '-rand-' . $rand . '-share-key-' . $userCheck->share_key);
915
                }
916
            }
247 efrain 917
 
1 efrain 918
            if (empty($password) || $password != $checkpassword) {
919
                $data = [
920
                    'success' => false,
921
                    'data' => 'ERROR_UNAUTHORIZED'
922
                ];
247 efrain 923
 
1 efrain 924
                return new JsonModel($data);
925
            }
247 efrain 926
 
1 efrain 927
            /*
247 efrain 928
             $share_params = [
929
             'type' => $type,
930
             'code' => $code,
931
             'user' => $currentUser->uuid,
932
             'timestamp' => $timestamp,
933
             'rand' => $rand,
934
             'password' => $password,
935
             ];
936
 
937
             $share_increment_external_counter_url = $this->url()->fromRoute('share/increment-external-counter', $share_params  , ['force_canonical' => true]);
938
             */
1 efrain 939
 
254 efrain 940
            $hostname = empty($_SERVER['HTTP_HOST']) ?  '' : $_SERVER['HTTP_HOST'];
247 efrain 941
 
254 efrain 942
            $networkMapper = NetworkMapper::getInstance($this->adapter);
943
            $network = $networkMapper->fetchOneByHostnameForFrontend($hostname);
247 efrain 944
 
254 efrain 945
            if(!$network) {
946
                $network = $networkMapper->fetchOneByDefault();
137 efrain 947
            }
247 efrain 948
 
254 efrain 949
            $hostname = trim($network->main_hostname);
950
            $base_share = 'https://' . $hostname;
247 efrain 951
 
1 efrain 952
            $share_url          = $base_share . $_SERVER['REQUEST_URI'];
953
            $share_image        = $base_share . '/images/ll-logo.png';
954
            $share_title        = '';
955
            $share_description  = '';
249 efrain 956
 
247 efrain 957
 
958
 
1 efrain 959
            if ($type == 'feed' && $code) {
960
                $feedMapper =  FeedMapper::getInstance($this->adapter);
961
                $feed = $feedMapper->fetchOneByUuidAnyStatus($code);
247 efrain 962
 
1 efrain 963
                // if($feed && $feed->status == Feed::STATUS_PUBLISHED) {
247 efrain 964
 
1 efrain 965
                if ($feed) {
247 efrain 966
 
1 efrain 967
                    $share_title = $feed->title ? $feed->title : '';
247 efrain 968
 
1 efrain 969
                    if ($feed->posted_or_shared  == Feed::SHARED) {
247 efrain 970
 
971
 
1 efrain 972
                        $feed = $feedMapper->fetchOneAnyStatus($feed->shared_feed_id);
973
                        if ($feed->title) {
247 efrain 974
 
1 efrain 975
                            $share_title = $share_title  .  ' -  ' . $feed->title;
976
                        }
977
                    }
247 efrain 978
 
979
 
1 efrain 980
                    $share_description = $feed->description;
247 efrain 981
 
1 efrain 982
                    $image_name = '';
345 www 983
                    if ($feed->file_type == Storage::FILE_TYPE_IMAGE) {
247 efrain 984
 
1 efrain 985
                        $image_name = $feed->file_name;
986
                    } else  if ($feed->file_image_preview) {
987
                        $image_name = $feed->file_image_preview;
988
                    }
247 efrain 989
 
990
 
991
 
992
                        if ($image_name) {
993
 
994
                            $source = $this->config['leaderslinked.fullpath.feed'] . $feed->uuid . DIRECTORY_SEPARATOR . $image_name;
995
 
257 efrain 996
                            $target_path = $this->config['leaderslinked.frontend.frontend']. DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . 'feed' . DIRECTORY_SEPARATOR . $feed->uuid;
997
 
247 efrain 998
 
999
 
257 efrain 1000
                            //$target_path = 'public' . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . 'feed' . DIRECTORY_SEPARATOR . $feed->uuid;
1001
 
247 efrain 1002
                            if (!file_exists($target_path)) {
1003
                                mkdir($target_path, 0755, true);
1004
                            }
1005
 
1006
 
1007
 
1008
                            $target = $target_path . DIRECTORY_SEPARATOR . $image_name;
1009
 
1010
 
1011
 
1012
                            if (!file_exists($target)) {
1013
 
1014
                                copy($source, $target);
1015
                                $share_image =  $base_share . '/images/feed/' . $feed->uuid . '/' . $image_name;
1016
                            } else {
1017
                                $share_image =  $base_share . '/images/feed/' . $feed->uuid . '/' . $image_name;
1018
                            }
1 efrain 1019
                        }
1020
                } else {
247 efrain 1021
 
249 efrain 1022
                    return new JsonModel([
1023
                        'success' => false,
1024
                        'data' => 'ERROR_FEED_OR_POST_SHARED'
1025
                    ]);
1 efrain 1026
                }
1027
            } else if ($type == 'post' && $code) {
247 efrain 1028
 
1 efrain 1029
                $postMapper = PostMapper::getInstance($this->adapter);
1030
                $post = $postMapper->fetchOneByUuid($code);
247 efrain 1031
 
1 efrain 1032
                if ($post && $post->status == Post::STATUS_ACTIVE) {
1033
                    $share_title = $post->title;
1034
                    $share_description = $post->description;
247 efrain 1035
 
1036
 
1 efrain 1037
                    if ($post->image) {
1038
                        $source = $this->config['leaderslinked.fullpath.post'] . $post->uuid . DIRECTORY_SEPARATOR . $post->image;
247 efrain 1039
 
1040
 
257 efrain 1041
                       // $target_path = 'public' . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . 'post' . DIRECTORY_SEPARATOR . $post->uuid;
247 efrain 1042
 
257 efrain 1043
                        $target_path = $this->config['leaderslinked.frontend.frontend'] . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . 'post' . DIRECTORY_SEPARATOR . $post->uuid;
1044
 
1 efrain 1045
                        if (!file_exists($target_path)) {
1046
                            mkdir($target_path, 0755, true);
1047
                        }
247 efrain 1048
 
1049
 
1050
 
1 efrain 1051
                        $target = $target_path . DIRECTORY_SEPARATOR . $post->image;
247 efrain 1052
 
1053
 
1054
 
1 efrain 1055
                        if (!file_exists($target)) {
247 efrain 1056
 
1 efrain 1057
                            copy($source, $target);
1058
                            $share_image =  $base_share . '/images/post/' . $post->uuid . '/' . $post->image;
1059
                        } else {
1060
                            $share_image =  $base_share . '/images/post/' . $post->uuid . '/' . $post->image;
1061
                        }
1062
                    }
1063
                } else {
247 efrain 1064
 
249 efrain 1065
                    return new JsonModel([
1066
                        'success' => false,
1067
                        'data' => 'ERROR_FEED_OR_POST_SHARED'
1068
                    ]);
1 efrain 1069
                }
1070
            }
247 efrain 1071
 
1 efrain 1072
            if ($currentUserPlugin->hasIdentity()) {
1073
                $currentUser = $currentUserPlugin->getUser();
1074
                if ($userCheck && $userCheck->status == User::STATUS_ACTIVE && $userCheck->id != $currentUser->id) {
247 efrain 1075
 
1 efrain 1076
                    $connectionMapper = ConnectionMapper::getInstance($this->adapter);
1077
                    $connection = $connectionMapper->fetchOneByUserId1AndUserId2($currentUser->id, $userCheck->id);
247 efrain 1078
 
1 efrain 1079
                    if ($connection) {
247 efrain 1080
 
1 efrain 1081
                        if ($connection->status != Connection::STATUS_ACCEPTED) {
1082
                            $connectionMapper->approve($connection);
1083
                        }
1084
                    } else {
1085
                        $connection = new Connection();
1086
                        $connection->request_from = $currentUser->id;
1087
                        $connection->request_to = $userCheck->id;
1088
                        $connection->status = Connection::STATUS_ACCEPTED;
247 efrain 1089
 
1 efrain 1090
                        $connectionMapper->insert($connection);
1091
                    }
1092
                }
1093
 
1094
            } else {
249 efrain 1095
                $this->cache->setItem('user_share_invitation', [
1096
                    'code' => $code,
1097
                    'type' => $type,
1098
                    'user' => $user
1099
                ]);
1 efrain 1100
            }
1101
            return new JsonModel([
249 efrain 1102
                'success' => true,
1103
                'data' => [
1104
                    'image' => $share_image,
1105
                    'url' => $share_url,
1106
                    'title' => strip_tags($share_title),
1107
                    'description' => strip_tags($share_description),
1108
                ]
247 efrain 1109
 
1 efrain 1110
            ]);
1111
 
1112
        } else {
1113
            $response = [
1114
                'success' => false,
1115
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
1116
            ];
1117
 
1118
            return new JsonModel($response);
1119
        }
1120
    }
333 www 1121
 
1122
 
1 efrain 1123
}