Proyectos de Subversion LeadersLinked - Services

Rev

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