Proyectos de Subversion LeadersLinked - Services

Rev

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