Proyectos de Subversion LeadersLinked - Services

Rev

Rev 747 | Rev 764 | 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
 
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
 
754 stevensc 279
    public function themeAction()
280
    {
281
        $currentNetworkPlugin = $this->plugin('currentNetworkPlugin');
282
        $currentNetwork = $currentNetworkPlugin->getNetwork();
1 efrain 283
 
754 stevensc 284
        $request = $this->getRequest();
285
 
286
        if(!$request->isGet()) {
287
            $data = [
288
                'success' => false,
289
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
290
            ];
291
 
292
            return new JsonModel($data);
293
        }
1 efrain 294
 
754 stevensc 295
        if(!$currentNetwork) {
296
            $data = [
297
                'success' => false,
298
                'data' => 'ERROR_NETWORK_NOT_FOUND'
299
            ];
1 efrain 300
 
754 stevensc 301
            return new JsonModel($data);
302
        }
303
 
304
        $data = [
305
            'success' => true,
306
            'theme' => [
307
                'bg-color' => $currentNetwork->css_bg_color,
308
                'body-bg-color' => $currentNetwork->css_body_bg_color,
309
                'bg-color-secondary' => $currentNetwork->css_bg_color_secondary,
310
                'font-color' => $currentNetwork->css_font_color,
311
                'font-color-hover' => $currentNetwork->css_font_color_hover,
312
                'title-color' => $currentNetwork->css_title_color,
313
                'subtitle-color' => $currentNetwork->css_subtitle_color,
314
                'icons-color' => $currentNetwork->css_icons_color,
315
                'button-bg' => $currentNetwork->css_button_bg,
316
                'button-bg-hover' => $currentNetwork->css_button_bg_hover,
317
                'button-text-color' => $currentNetwork->css_button_text_color,
318
                'button-bg-secondary' => $currentNetwork->css_button_bg_secondary,
319
                'button-bg-secondary-hover' => $currentNetwork->css_button_bg_secondary_hover,
320
                'button-text-color-secondary' => $currentNetwork->css_button_text_color_secondary,
321
                'button-bg-tertiary' => $currentNetwork->css_button_bg_tertiary,
322
                'button-text-color-tertiary' => $currentNetwork->css_button_text_color_tertiary,
323
                'border-primary' => $currentNetwork->css_border_primary,
324
                'border-trasnparent' => $currentNetwork->css_border_trasnparent,
325
                'chat-received' => $currentNetwork->css_chat_received,
326
                'chat-send' => $currentNetwork->css_chat_send,
327
                'chat-color' => $currentNetwork->css_chat_color,
328
                'light-gray' => $currentNetwork->css_light_gray,
329
                'gray' => $currentNetwork->css_gray,
330
                'danger' => $currentNetwork->css_danger,
331
                'danger-hover' => $currentNetwork->css_danger_hover,
332
                'online-green' => $currentNetwork->css_online_green,
333
                'border-gray-primary' => $currentNetwork->css_border_gray_primary,
334
                'white' => $currentNetwork->css_white,
335
                'white-backdrop' => $currentNetwork->css_white_backdrop,
336
                'border-radius' => $currentNetwork->css_border_radius,
337
                'light-shadow' => $currentNetwork->css_light_shadow,
338
                'shadow' => $currentNetwork->css_shadow
339
            ]
340
        ];
341
 
342
        return new JsonModel($data);
343
    }
344
 
1 efrain 345
    public function privacyPolicyAction()
346
    {
347
 
348
 
349
 
350
 
351
        $pageCode = Page::PAGE_CODE_PRIVACY_POLICY;
352
 
353
        $currentNetworkPlugin = $this->plugin('currentNetworkPlugin');
354
        $currentNetwork = $currentNetworkPlugin->getNetwork();
355
 
356
        $currentUserPlugin = $this->plugin('currentUserPlugin');
357
 
358
        $pageMapper = PageMapper::getInstance($this->adapter);
359
        $page = $pageMapper->fetchOneByCodeAndNetworkId($pageCode, $currentNetwork->id);
360
 
361
        if (!$page) {
362
            $networkMapper = NetworkMapper::getInstance($this->adapter);
363
            $network = $networkMapper->fetchOneByDefault();
364
 
365
            $pageDefault = $pageMapper->fetchOneByCodeAndNetworkId($pageCode, $network->id);
366
            if ($pageDefault) {
367
                $page = new Page();
368
                $page->network_id = $currentNetwork->id;
369
                $page->code = $pageDefault->code;
370
                $page->content = $pageDefault->content;
371
                $page->fixed = $pageDefault->fixed;
372
                $page->page_default_id = $pageDefault->id;
373
                $page->title = $pageDefault->title;
374
                $page->status = $pageDefault->status;
375
                $page->type = $pageDefault->type;
376
                $page->url = $pageDefault->url;
377
 
378
                $pageMapper->insert($page);
379
            }
380
        }
381
 
382
        return new JsonModel([
383
            'success' => true,
384
            'data' => [
385
                'title' => $page->title,
386
                'content' => $page->content
387
            ]
388
        ]);
389
 
390
    }
391
 
392
    public function cookiesAction()
393
    {
394
 
395
        $pageCode = Page::PAGE_CODE_COOKIES;
396
 
397
        $currentNetworkPlugin = $this->plugin('currentNetworkPlugin');
398
        $currentNetwork = $currentNetworkPlugin->getNetwork();
399
 
400
        $currentUserPlugin = $this->plugin('currentUserPlugin');
401
 
402
        $pageMapper = PageMapper::getInstance($this->adapter);
403
        $page = $pageMapper->fetchOneByCodeAndNetworkId($pageCode, $currentNetwork->id);
404
 
405
        if (!$page) {
406
            $networkMapper = NetworkMapper::getInstance($this->adapter);
407
            $network = $networkMapper->fetchOneByDefault();
408
 
409
            $pageDefault = $pageMapper->fetchOneByCodeAndNetworkId($pageCode, $network->id);
410
            if ($pageDefault) {
411
                $page = new Page();
412
                $page->network_id = $currentNetwork->id;
413
                $page->code = $pageDefault->code;
414
                $page->content = $pageDefault->content;
415
                $page->fixed = $pageDefault->fixed;
416
                $page->page_default_id = $pageDefault->id;
417
                $page->title = $pageDefault->title;
418
                $page->status = $pageDefault->status;
419
                $page->type = $pageDefault->type;
420
                $page->url = $pageDefault->url;
421
 
422
                $pageMapper->insert($page);
423
            }
424
        }
425
 
426
        return new JsonModel([
427
            'success' => true,
428
            'data' => [
429
                'title' => $page->title,
430
                'content' => $page->content
431
            ]
432
        ]);
433
    }
434
 
435
    public function professionalismPolicyAction()
436
    {
437
        $pageCode = Page::PAGE_CODE_PROFESSIONALISM_POLICY;
438
 
439
        $currentNetworkPlugin = $this->plugin('currentNetworkPlugin');
440
        $currentNetwork = $currentNetworkPlugin->getNetwork();
441
 
442
        $currentUserPlugin = $this->plugin('currentUserPlugin');
443
 
444
 
445
        $pageMapper = PageMapper::getInstance($this->adapter);
446
        $page = $pageMapper->fetchOneByCodeAndNetworkId($pageCode, $currentNetwork->id);
447
 
448
        if (!$page) {
449
            $networkMapper = NetworkMapper::getInstance($this->adapter);
450
            $network = $networkMapper->fetchOneByDefault();
451
 
452
            $pageDefault = $pageMapper->fetchOneByCodeAndNetworkId($pageCode, $network->id);
453
            if ($pageDefault) {
454
                $page = new Page();
455
                $page->network_id = $currentNetwork->id;
456
                $page->code = $pageDefault->code;
457
                $page->content = $pageDefault->content;
458
                $page->fixed = $pageDefault->fixed;
459
                $page->page_default_id = $pageDefault->id;
460
                $page->title = $pageDefault->title;
461
                $page->status = $pageDefault->status;
462
                $page->type = $pageDefault->type;
463
                $page->url = $pageDefault->url;
464
 
465
                $pageMapper->insert($page);
466
            }
467
        }
468
 
469
        return new JsonModel([
470
            'success' => true,
471
            'data' => [
472
                'title' => $page->title,
473
                'content' => $page->content
474
            ]
475
        ]);
476
    }
477
 
478
 
479
    public function termsAndConditionsAction()
480
    {
481
        $pageCode = Page::PAGE_CODE_TERMS_AND_CONDITIONS;
482
 
483
        $currentNetworkPlugin = $this->plugin('currentNetworkPlugin');
484
        $currentNetwork = $currentNetworkPlugin->getNetwork();
485
 
486
        $currentUserPlugin = $this->plugin('currentUserPlugin');
487
 
488
 
489
        $pageMapper = PageMapper::getInstance($this->adapter);
490
        $page = $pageMapper->fetchOneByCodeAndNetworkId($pageCode, $currentNetwork->id);
491
 
492
        if (!$page) {
493
            $networkMapper = NetworkMapper::getInstance($this->adapter);
494
            $network = $networkMapper->fetchOneByDefault();
495
 
496
            $pageDefault = $pageMapper->fetchOneByCodeAndNetworkId($pageCode, $network->id);
497
            if ($pageDefault) {
498
                $page = new Page();
499
                $page->network_id = $currentNetwork->id;
500
                $page->code = $pageDefault->code;
501
                $page->content = $pageDefault->content;
502
                $page->fixed = $pageDefault->fixed;
503
                $page->page_default_id = $pageDefault->id;
504
                $page->title = $pageDefault->title;
505
                $page->status = $pageDefault->status;
506
                $page->type = $pageDefault->type;
507
                $page->url = $pageDefault->url;
508
 
509
                $pageMapper->insert($page);
510
            }
511
        }
512
 
513
        return new JsonModel([
514
            'success' => true,
515
            'data' => [
516
                'title' => $page->title,
517
                'content' => $page->content
518
            ]
519
        ]);
520
    }
521
 
522
    public function checkSessionAction()
523
    {
524
 
525
        $request = $this->getRequest();
526
        if ($request->isGet()) {
527
 
528
            $currentUserPlugin = $this->plugin('currentUserPlugin');
529
            if (!$currentUserPlugin->hasIdentity()) {
530
                //$flashMessenger = $this->plugin('FlashMessenger');
531
                //$flashMessenger->addErrorMessage('ERROR_SESSION_NOT_FOUND');
532
 
533
                $response = [
534
                    'success' => false,
535
                    'data' => [
536
                        'message' =>  '', //ERROR_SESSION_NOT_FOUND',
537
                        'url' => $this->url()->fromRoute('signout')
538
                    ]
539
                ];
540
 
541
                return new JsonModel($response);
542
            }
543
 
544
            $currentUser = $currentUserPlugin->getUser();
545
 
546
 
547
            if ($currentUser->last_activity_on) {
548
                $last_activity_on = strtotime($currentUser->last_activity_on);
549
            } else {
550
                $last_activity_on = strtotime('-1 day');
551
            }
552
 
553
            $expiry_time = $last_activity_on + $this->config['leaderslinked.security.last_activity_expired'];
554
            if (time() > $expiry_time) {
555
                //$flashMessenger = $this->plugin('FlashMessenger');
556
                //$flashMessenger->addErrorMessage('ERROR_SESSION_EXPIRED');
557
 
558
                $response = [
559
                    'success' => false,
560
                    'data' => [
561
                        'message' => 'ERROR_SESSION_EXPIRED',
562
                        'url' => $this->url()->fromRoute('signout')
563
                    ]
564
                ];
565
            } else {
566
                $notificationMapper = NotificationMapper::getInstance($this->adapter);
567
                $total_notifications = $notificationMapper->fetchUnreadNotificationsCount($currentUser->id);
568
 
283 www 569
                /*
1 efrain 570
                $messageMapper = MessageMapper::getInstance($this->adapter);
283 www 571
                $total_messages =  $messageMapper->fetchCountUnreadMessagesReceiverId($currentUser->id);*/
572
 
573
                $total_messages = 0;
1 efrain 574
                $response = [
575
                    'success' => true,
576
                    'data' => [
577
                        'total_notifications' => $total_notifications,
578
                        'total_messages' => $total_messages
579
                    ]
580
                ];
581
            }
582
        } else {
583
            $response = [
584
                'success' => false,
585
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
586
            ];
587
        }
588
 
589
        return new JsonModel($response);
590
    }
591
 
592
 
593
 
594
 
595
 
596
    public function incTotalExternalSharedAction()
597
    {
598
 
599
        $request = $this->getRequest();
600
        if ($request->isPost()) {
601
            $currentUserPlugin = $this->plugin('currentUserPlugin');
602
            $currentUser = $currentUserPlugin->getUser();
603
 
604
            $currentNetworkPlugin = $this->plugin('currentNetworkPlugin');
605
            $currentNetwork = $currentNetworkPlugin->getNetwork();
606
 
607
            $code       = $this->params()->fromRoute('code');
608
            $type       = $this->params()->fromRoute('type');
609
            $user       = $this->params()->fromRoute('user');
610
            $timestamp  = intval($this->params()->fromRoute('timestamp'), 10);
611
            $rand       = intval($this->params()->fromRoute('rand'), 10);
612
            $password   = $this->params()->fromRoute('password');
613
 
614
 
615
 
616
            $checkpassword = '';
617
 
618
 
619
            $userCheck = '';
620
            if ($user && $timestamp > 0 && $rand > 0 && $password) {
621
                $userMapper = UserMapper::getInstance($this->adapter);
622
                $userCheck = $userMapper->fetchOneByUuid($user);
623
                if ($userCheck) {
624
                    $checkpassword  = md5('user-' . $userCheck->uuid . '-' . $type . '-' . $code . '-timestamp-' . $timestamp . '-rand-' . $rand . '-share-key-' . $userCheck->share_key);
625
                }
626
            }
627
 
628
            if (empty($password) || $password != $checkpassword) {
629
                $data = [
630
                    'success' => false,
631
                    'data' => 'ERROR_UNAUTHORIZED'
632
                ];
633
 
634
                return new JsonModel($data);
635
            }
636
 
637
 
638
 
639
 
640
 
641
 
642
 
643
 
644
 
645
            if ($type == 'feed' && $code) {
646
                $feedMapper =  FeedMapper::getInstance($this->adapter);
647
                $feed = $feedMapper->fetchOneByUuidAnyStatus($code);
648
 
649
 
650
                if ($feed) {
651
 
652
                    if ($feed->network_id != $currentNetwork->id) {
653
                        $data = [
654
                            'success' => false,
655
                            'data' =>    'ERROR_UNAUTHORIZED'
656
                        ];
657
 
658
                        return new JsonModel($data);
659
                    }
660
 
661
                    if ($feedMapper->incTotalExternalShared($feed->id)) {
662
                        $total = $feedMapper->fetchTotalExternalShared($feed->id);
663
 
664
                        $this->logger->info('El usuario : ' . trim($currentUser->first_name . ' ' . $currentUser->last_name) . ' (' . $currentUser->email . ') compartio externamente el feed : ' . $feed->title);
665
 
666
                        $data = [
667
                            'success' => true,
668
                            'data' => $total,
669
                        ];
670
 
671
                        return new JsonModel($data);
672
                    } else {
673
                        $data = [
674
                            'success' => false,
675
                            'data' => $feedMapper->getError()
676
                        ];
677
 
678
                        return new JsonModel($data);
679
                    }
680
                } else {
681
                    $data = [
682
                        'success' => false,
683
                        'data' => 'ERROR_FEED_NOT_FOUND',
684
                    ];
685
 
686
                    return new JsonModel($data);
687
                }
688
            } else if ($type == 'post' && $code) {
689
 
690
                $postMapper = PostMapper::getInstance($this->adapter);
691
                $post = $postMapper->fetchOneByUuid($code);
692
 
693
                if ($post && $post->status == Post::STATUS_ACTIVE) {
694
 
695
                    if ($post->network_id != $currentNetwork->id) {
696
                        $data = [
697
                            'success' => false,
698
                            'data' =>    'ERROR_UNAUTHORIZED'
699
                        ];
700
 
701
                        return new JsonModel($data);
702
                    }
703
 
704
 
705
                    if ($postMapper->incTotalExternalShared($post->id)) {
706
                        $total = $postMapper->fetchTotalExternalShared($post->id);
707
 
708
                        $this->logger->info('El usuario : ' . trim($currentUser->first_name . ' ' . $currentUser->last_name) . ' (' . $currentUser->email . ') compartio externamente el post : ' . $post->title);
709
 
710
 
711
 
712
                        $data = [
713
                            'success' => true,
714
                            'data' => $total,
715
                        ];
716
 
717
                        return new JsonModel($data);
718
                    } else {
719
                        $data = [
720
                            'success' => false,
721
                            'data' => $postMapper->getError()
722
                        ];
723
 
724
                        return new JsonModel($data);
725
                    }
726
                } else {
727
                    $data = [
728
                        'success' => false,
729
                        'data' => 'ERROR_POST_NOT_FOUND'
730
                    ];
731
 
732
                    return new JsonModel($data);
733
                }
734
            }
735
        } else {
736
            $response = [
737
                'success' => false,
738
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
739
            ];
740
 
741
            return new JsonModel($response);
742
        }
743
    }
744
 
247 efrain 745
 
746
 
747
    public function languageAction()
748
    {
749
        $request = $this->getRequest();
750
 
751
        if ($request->isGet()) {
752
 
753
 
754
 
755
            $pathname = dirname(__DIR__);
756
            $filename = $pathname . DIRECTORY_SEPARATOR . 'i18n' . DIRECTORY_SEPARATOR . 'spanish.php';
757
 
758
 
759
            if(file_exists($filename)) {
760
 
761
                $arr =  include $filename;
762
                $arr = array_filter($arr, function($a)  {
763
                    return strpos($a, 'LABEL_') !== false;
764
                }, ARRAY_FILTER_USE_KEY);
765
 
766
 
767
                $data = [];
768
                foreach($arr as $key => $value)
769
                {
770
                    $key = str_replace('LABEL_', 'LANG_', $key);
771
 
772
                    $data[ $key ] = $value;
773
 
774
                }
775
 
776
 
777
 
778
                $response = [
779
                    'success' => true,
780
                    'data' => $data
781
                ];
782
 
783
                return new JsonModel($response);
784
 
785
 
786
            } else {
787
                $response = [
788
                    'success' => false,
789
                    'data' => 'ERROR_METHOD_NOT_ALLOWED'
790
                ];
791
 
792
                return new JsonModel($response);
793
            }
794
 
795
 
796
 
797
 
798
 
799
        } else {
800
            $response = [
801
                'success' => false,
802
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
803
            ];
804
 
805
            return new JsonModel($response);
806
        }
807
 
808
 
809
    }
810
 
1 efrain 811
    public function shareAction()
812
    {
813
        $request = $this->getRequest();
814
        if ($request->isGet()) {
815
            $currentUserPlugin = $this->plugin('currentUserPlugin');
816
            $currentUser = $currentUserPlugin->getUser();
247 efrain 817
 
1 efrain 818
            $code       = $this->params()->fromRoute('code');
819
            $type       = $this->params()->fromRoute('type');
820
            $user       = $this->params()->fromRoute('user');
821
            $timestamp  = intval($this->params()->fromRoute('timestamp'), 10);
822
            $rand       = intval($this->params()->fromRoute('rand'), 10);
823
            $password   = $this->params()->fromRoute('password');
247 efrain 824
 
825
 
826
 
1 efrain 827
            $checkpassword = '';
247 efrain 828
 
829
 
1 efrain 830
            $userCheck = '';
831
            if ($user && $timestamp > 0 && $rand > 0 && $password) {
832
                $userMapper = UserMapper::getInstance($this->adapter);
833
                $userCheck = $userMapper->fetchOneByUuid($user);
834
                if ($userCheck) {
835
                    $checkpassword  = md5('user-' . $userCheck->uuid . '-' . $type . '-' . $code . '-timestamp-' . $timestamp . '-rand-' . $rand . '-share-key-' . $userCheck->share_key);
836
                }
837
            }
247 efrain 838
 
1 efrain 839
            if (empty($password) || $password != $checkpassword) {
840
                $data = [
841
                    'success' => false,
842
                    'data' => 'ERROR_UNAUTHORIZED'
843
                ];
247 efrain 844
 
1 efrain 845
                return new JsonModel($data);
846
            }
247 efrain 847
 
1 efrain 848
            /*
247 efrain 849
             $share_params = [
850
             'type' => $type,
851
             'code' => $code,
852
             'user' => $currentUser->uuid,
853
             'timestamp' => $timestamp,
854
             'rand' => $rand,
855
             'password' => $password,
856
             ];
857
 
858
             $share_increment_external_counter_url = $this->url()->fromRoute('share/increment-external-counter', $share_params  , ['force_canonical' => true]);
859
             */
1 efrain 860
 
254 efrain 861
            $hostname = empty($_SERVER['HTTP_HOST']) ?  '' : $_SERVER['HTTP_HOST'];
247 efrain 862
 
254 efrain 863
            $networkMapper = NetworkMapper::getInstance($this->adapter);
864
            $network = $networkMapper->fetchOneByHostnameForFrontend($hostname);
247 efrain 865
 
254 efrain 866
            if(!$network) {
867
                $network = $networkMapper->fetchOneByDefault();
137 efrain 868
            }
247 efrain 869
 
254 efrain 870
            $hostname = trim($network->main_hostname);
871
            $base_share = 'https://' . $hostname;
247 efrain 872
 
1 efrain 873
            $share_url          = $base_share . $_SERVER['REQUEST_URI'];
874
            $share_image        = $base_share . '/images/ll-logo.png';
875
            $share_title        = '';
876
            $share_description  = '';
249 efrain 877
 
247 efrain 878
 
879
 
1 efrain 880
            if ($type == 'feed' && $code) {
881
                $feedMapper =  FeedMapper::getInstance($this->adapter);
882
                $feed = $feedMapper->fetchOneByUuidAnyStatus($code);
247 efrain 883
 
1 efrain 884
                // if($feed && $feed->status == Feed::STATUS_PUBLISHED) {
247 efrain 885
 
1 efrain 886
                if ($feed) {
247 efrain 887
 
1 efrain 888
                    $share_title = $feed->title ? $feed->title : '';
247 efrain 889
 
1 efrain 890
                    if ($feed->posted_or_shared  == Feed::SHARED) {
247 efrain 891
 
892
 
1 efrain 893
                        $feed = $feedMapper->fetchOneAnyStatus($feed->shared_feed_id);
894
                        if ($feed->title) {
247 efrain 895
 
1 efrain 896
                            $share_title = $share_title  .  ' -  ' . $feed->title;
897
                        }
898
                    }
247 efrain 899
 
900
 
1 efrain 901
                    $share_description = $feed->description;
247 efrain 902
 
1 efrain 903
                    $image_name = '';
345 www 904
                    if ($feed->file_type == Storage::FILE_TYPE_IMAGE) {
247 efrain 905
 
1 efrain 906
                        $image_name = $feed->file_name;
907
                    } else  if ($feed->file_image_preview) {
908
                        $image_name = $feed->file_image_preview;
909
                    }
247 efrain 910
 
911
 
912
 
913
                        if ($image_name) {
914
 
915
                            $source = $this->config['leaderslinked.fullpath.feed'] . $feed->uuid . DIRECTORY_SEPARATOR . $image_name;
916
 
257 efrain 917
                            $target_path = $this->config['leaderslinked.frontend.frontend']. DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . 'feed' . DIRECTORY_SEPARATOR . $feed->uuid;
918
 
247 efrain 919
 
920
 
257 efrain 921
                            //$target_path = 'public' . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . 'feed' . DIRECTORY_SEPARATOR . $feed->uuid;
922
 
247 efrain 923
                            if (!file_exists($target_path)) {
924
                                mkdir($target_path, 0755, true);
925
                            }
926
 
927
 
928
 
929
                            $target = $target_path . DIRECTORY_SEPARATOR . $image_name;
930
 
931
 
932
 
933
                            if (!file_exists($target)) {
934
 
935
                                copy($source, $target);
936
                                $share_image =  $base_share . '/images/feed/' . $feed->uuid . '/' . $image_name;
937
                            } else {
938
                                $share_image =  $base_share . '/images/feed/' . $feed->uuid . '/' . $image_name;
939
                            }
1 efrain 940
                        }
941
                } else {
247 efrain 942
 
249 efrain 943
                    return new JsonModel([
944
                        'success' => false,
945
                        'data' => 'ERROR_FEED_OR_POST_SHARED'
946
                    ]);
1 efrain 947
                }
948
            } else if ($type == 'post' && $code) {
247 efrain 949
 
1 efrain 950
                $postMapper = PostMapper::getInstance($this->adapter);
951
                $post = $postMapper->fetchOneByUuid($code);
247 efrain 952
 
1 efrain 953
                if ($post && $post->status == Post::STATUS_ACTIVE) {
954
                    $share_title = $post->title;
955
                    $share_description = $post->description;
247 efrain 956
 
957
 
1 efrain 958
                    if ($post->image) {
959
                        $source = $this->config['leaderslinked.fullpath.post'] . $post->uuid . DIRECTORY_SEPARATOR . $post->image;
247 efrain 960
 
961
 
257 efrain 962
                       // $target_path = 'public' . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . 'post' . DIRECTORY_SEPARATOR . $post->uuid;
247 efrain 963
 
257 efrain 964
                        $target_path = $this->config['leaderslinked.frontend.frontend'] . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . 'post' . DIRECTORY_SEPARATOR . $post->uuid;
965
 
1 efrain 966
                        if (!file_exists($target_path)) {
967
                            mkdir($target_path, 0755, true);
968
                        }
247 efrain 969
 
970
 
971
 
1 efrain 972
                        $target = $target_path . DIRECTORY_SEPARATOR . $post->image;
247 efrain 973
 
974
 
975
 
1 efrain 976
                        if (!file_exists($target)) {
247 efrain 977
 
1 efrain 978
                            copy($source, $target);
979
                            $share_image =  $base_share . '/images/post/' . $post->uuid . '/' . $post->image;
980
                        } else {
981
                            $share_image =  $base_share . '/images/post/' . $post->uuid . '/' . $post->image;
982
                        }
983
                    }
984
                } else {
247 efrain 985
 
249 efrain 986
                    return new JsonModel([
987
                        'success' => false,
988
                        'data' => 'ERROR_FEED_OR_POST_SHARED'
989
                    ]);
1 efrain 990
                }
991
            }
247 efrain 992
 
1 efrain 993
            if ($currentUserPlugin->hasIdentity()) {
994
                $currentUser = $currentUserPlugin->getUser();
995
                if ($userCheck && $userCheck->status == User::STATUS_ACTIVE && $userCheck->id != $currentUser->id) {
247 efrain 996
 
1 efrain 997
                    $connectionMapper = ConnectionMapper::getInstance($this->adapter);
998
                    $connection = $connectionMapper->fetchOneByUserId1AndUserId2($currentUser->id, $userCheck->id);
247 efrain 999
 
1 efrain 1000
                    if ($connection) {
247 efrain 1001
 
1 efrain 1002
                        if ($connection->status != Connection::STATUS_ACCEPTED) {
1003
                            $connectionMapper->approve($connection);
1004
                        }
1005
                    } else {
1006
                        $connection = new Connection();
1007
                        $connection->request_from = $currentUser->id;
1008
                        $connection->request_to = $userCheck->id;
1009
                        $connection->status = Connection::STATUS_ACCEPTED;
247 efrain 1010
 
1 efrain 1011
                        $connectionMapper->insert($connection);
1012
                    }
1013
                }
1014
 
1015
            } else {
249 efrain 1016
                $this->cache->setItem('user_share_invitation', [
1017
                    'code' => $code,
1018
                    'type' => $type,
1019
                    'user' => $user
1020
                ]);
1 efrain 1021
            }
1022
            return new JsonModel([
249 efrain 1023
                'success' => true,
1024
                'data' => [
1025
                    'image' => $share_image,
1026
                    'url' => $share_url,
1027
                    'title' => strip_tags($share_title),
1028
                    'description' => strip_tags($share_description),
1029
                ]
247 efrain 1030
 
1 efrain 1031
            ]);
1032
 
1033
        } else {
1034
            $response = [
1035
                'success' => false,
1036
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
1037
            ];
1038
 
1039
            return new JsonModel($response);
1040
        }
1041
    }
333 www 1042
 
1043
 
1 efrain 1044
}