Proyectos de Subversion LeadersLinked - Services

Rev

Rev 1 | Rev 137 | 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
use Laminas\Db\Adapter\AdapterInterface;
8
 
9
use Laminas\Mvc\Controller\AbstractActionController;
10
use Laminas\Log\LoggerInterface;
11
use Laminas\View\Model\ViewModel;
12
use Laminas\View\Model\JsonModel;
13
use LeadersLinked\Model\Page;
14
use LeadersLinked\Mapper\NotificationMapper;
15
use LeadersLinked\Mapper\PageMapper;
16
use LeadersLinked\Mapper\MessageMapper;
17
use LeadersLinked\Mapper\UserMapper;
18
use LeadersLinked\Mapper\ConnectionMapper;
19
 
20
use LeadersLinked\Mapper\PostMapper;
21
use LeadersLinked\Model\Post;
22
 
23
use LeadersLinked\Mapper\FeedMapper;
24
use LeadersLinked\Model\Feed;
25
use LeadersLinked\Model\User;
26
use LeadersLinked\Model\Connection;
27
use LeadersLinked\Mapper\NetworkMapper;
28
use Laminas\Authentication\AuthenticationService;
29
use LeadersLinked\Authentication\AuthEmailAdapter;
30
use LeadersLinked\Cache\CacheInterface;
31
use LeadersLinked\Cache\CacheImpl;
32
use LeadersLinked\Library\Functions;
33
use LeadersLinked\Model\Network;
34
use Laminas\Http\Response;
35
 
36
class HomeController extends AbstractActionController
37
{
38
    /**
39
     *
40
     * @var \Laminas\Db\Adapter\AdapterInterface
41
     */
42
    private $adapter;
43
 
44
    /**
45
     *
46
     * @var \LeadersLinked\Cache\CacheInterface
47
     */
48
    private $cache;
49
 
50
 
51
    /**
52
     *
53
     * @var \Laminas\Log\LoggerInterface
54
     */
55
    private $logger;
56
 
57
    /**
58
     *
59
     * @var array
60
     */
61
    private $config;
62
 
63
 
64
    /**
65
     *
66
     * @var \Laminas\Mvc\I18n\Translator
67
     */
68
    private $translator;
69
 
70
 
71
    /**
72
     *
73
     * @param \Laminas\Db\Adapter\AdapterInterface $adapter
74
     * @param \LeadersLinked\Cache\CacheInterface $cache
75
     * @param \Laminas\Log\LoggerInterface LoggerInterface $logger
76
     * @param array $config
77
     * @param \Laminas\Mvc\I18n\Translator $translator
78
     */
79
    public function __construct($adapter, $cache, $logger, $config, $translator)
80
    {
81
        $this->adapter      = $adapter;
82
        $this->cache        = $cache;
83
        $this->logger       = $logger;
84
        $this->config       = $config;
85
        $this->translator   = $translator;
86
    }
87
 
88
 
89
 
90
    public function indexAction()
91
    {
92
        /*
93
        if(!empty($this->config['leaderslinked.runmode.autologin'])) {
94
 
95
            $currentNetworkPlugin = $this->plugin('currentNetworkPlugin');
96
            $currentNetwork = $currentNetworkPlugin->getNetwork();
97
 
98
            $authService = new AuthenticationService();
99
            if(!$authService->hasIdentity()) {
100
                $adapter = new AuthEmailAdapter($this->adapter);
101
                $adapter->setData('santiago.olivera@leaderslinked.com',  $currentNetwork->id);
102
 
103
                $authService->authenticate($adapter);
104
            }
105
        }
106
 
107
        $currentUserPlugin = $this->plugin('currentUserPlugin');
108
        if ($currentUserPlugin->hasIdentity()) {
109
            return $this->redirect()->toRoute('dashboard');
110
        } else {
111
            return $this->redirect()->toRoute('signin');
112
        }*/
113
 
114
        $currentNetworkPlugin = $this->plugin('currentNetworkPlugin');
115
        $currentNetwork = $currentNetworkPlugin->getNetwork();
116
 
117
        $request = $this->getRequest();
118
        if ($request->isGet()) {
119
 
120
            $currentUserPlugin = $this->plugin('currentUserPlugin');
121
 
122
            if (empty($_SESSION['aes'])) {
123
                $_SESSION['aes'] = Functions::generatePassword(16);
124
            }
125
 
126
            if ($this->config['leaderslinked.runmode.sandbox']) {
127
                $site_key      = $this->config['leaderslinked.google_captcha.sandbox_site_key'];
128
            } else {
129
                $site_key      = $this->config['leaderslinked.google_captcha.production_site_key'];
130
            }
131
 
132
            $access_usign_social_networks = $this->config['leaderslinked.runmode.access_usign_social_networks'];
133
 
134
 
135
 
136
            $sandbox = $this->config['leaderslinked.runmode.sandbox'];
137
            if ($sandbox) {
138
                $google_map_key  = $this->config['leaderslinked.google_map.sandbox_api_key'];
139
            } else {
140
                $google_map_key  = $this->config['leaderslinked.google_map.production_api_key'];
141
            }
142
 
143
            return  new JsonModel([
144
                'site_key'  => $site_key,
145
                'google_map_key' => $google_map_key,
146
                'aes'       => $_SESSION['aes'],
147
                'defaultNetwork' => $currentNetwork->default,
148
                'is_logged_in' =>  $currentUserPlugin->hasIdentity() ? true : false,
7 efrain 149
                'access_usign_social_networks' => $access_usign_social_networks &&  $currentNetwork && $currentNetwork->default == Network::DEFAULT_YES ? 'y' : 'n',
1 efrain 150
            ]);
151
 
152
 
153
        } else {
154
            $data = [
155
                'success' => false,
156
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
157
            ];
158
 
159
            return new JsonModel($data);
160
        }
161
 
162
    }
163
 
164
 
165
 
166
 
167
    public function privacyPolicyAction()
168
    {
169
 
170
 
171
 
172
 
173
        $pageCode = Page::PAGE_CODE_PRIVACY_POLICY;
174
 
175
        $currentNetworkPlugin = $this->plugin('currentNetworkPlugin');
176
        $currentNetwork = $currentNetworkPlugin->getNetwork();
177
 
178
        $currentUserPlugin = $this->plugin('currentUserPlugin');
179
 
180
        $pageMapper = PageMapper::getInstance($this->adapter);
181
        $page = $pageMapper->fetchOneByCodeAndNetworkId($pageCode, $currentNetwork->id);
182
 
183
        if (!$page) {
184
            $networkMapper = NetworkMapper::getInstance($this->adapter);
185
            $network = $networkMapper->fetchOneByDefault();
186
 
187
            $pageDefault = $pageMapper->fetchOneByCodeAndNetworkId($pageCode, $network->id);
188
            if ($pageDefault) {
189
                $page = new Page();
190
                $page->network_id = $currentNetwork->id;
191
                $page->code = $pageDefault->code;
192
                $page->content = $pageDefault->content;
193
                $page->fixed = $pageDefault->fixed;
194
                $page->page_default_id = $pageDefault->id;
195
                $page->title = $pageDefault->title;
196
                $page->status = $pageDefault->status;
197
                $page->type = $pageDefault->type;
198
                $page->url = $pageDefault->url;
199
 
200
                $pageMapper->insert($page);
201
            }
202
        }
203
 
204
        return new JsonModel([
205
            'success' => true,
206
            'data' => [
207
                'title' => $page->title,
208
                'content' => $page->content
209
            ]
210
        ]);
211
 
212
    }
213
 
214
    public function cookiesAction()
215
    {
216
 
217
        $pageCode = Page::PAGE_CODE_COOKIES;
218
 
219
        $currentNetworkPlugin = $this->plugin('currentNetworkPlugin');
220
        $currentNetwork = $currentNetworkPlugin->getNetwork();
221
 
222
        $currentUserPlugin = $this->plugin('currentUserPlugin');
223
 
224
        $pageMapper = PageMapper::getInstance($this->adapter);
225
        $page = $pageMapper->fetchOneByCodeAndNetworkId($pageCode, $currentNetwork->id);
226
 
227
        if (!$page) {
228
            $networkMapper = NetworkMapper::getInstance($this->adapter);
229
            $network = $networkMapper->fetchOneByDefault();
230
 
231
            $pageDefault = $pageMapper->fetchOneByCodeAndNetworkId($pageCode, $network->id);
232
            if ($pageDefault) {
233
                $page = new Page();
234
                $page->network_id = $currentNetwork->id;
235
                $page->code = $pageDefault->code;
236
                $page->content = $pageDefault->content;
237
                $page->fixed = $pageDefault->fixed;
238
                $page->page_default_id = $pageDefault->id;
239
                $page->title = $pageDefault->title;
240
                $page->status = $pageDefault->status;
241
                $page->type = $pageDefault->type;
242
                $page->url = $pageDefault->url;
243
 
244
                $pageMapper->insert($page);
245
            }
246
        }
247
 
248
        return new JsonModel([
249
            'success' => true,
250
            'data' => [
251
                'title' => $page->title,
252
                'content' => $page->content
253
            ]
254
        ]);
255
    }
256
 
257
    public function professionalismPolicyAction()
258
    {
259
        $pageCode = Page::PAGE_CODE_PROFESSIONALISM_POLICY;
260
 
261
        $currentNetworkPlugin = $this->plugin('currentNetworkPlugin');
262
        $currentNetwork = $currentNetworkPlugin->getNetwork();
263
 
264
        $currentUserPlugin = $this->plugin('currentUserPlugin');
265
 
266
 
267
        $pageMapper = PageMapper::getInstance($this->adapter);
268
        $page = $pageMapper->fetchOneByCodeAndNetworkId($pageCode, $currentNetwork->id);
269
 
270
        if (!$page) {
271
            $networkMapper = NetworkMapper::getInstance($this->adapter);
272
            $network = $networkMapper->fetchOneByDefault();
273
 
274
            $pageDefault = $pageMapper->fetchOneByCodeAndNetworkId($pageCode, $network->id);
275
            if ($pageDefault) {
276
                $page = new Page();
277
                $page->network_id = $currentNetwork->id;
278
                $page->code = $pageDefault->code;
279
                $page->content = $pageDefault->content;
280
                $page->fixed = $pageDefault->fixed;
281
                $page->page_default_id = $pageDefault->id;
282
                $page->title = $pageDefault->title;
283
                $page->status = $pageDefault->status;
284
                $page->type = $pageDefault->type;
285
                $page->url = $pageDefault->url;
286
 
287
                $pageMapper->insert($page);
288
            }
289
        }
290
 
291
        return new JsonModel([
292
            'success' => true,
293
            'data' => [
294
                'title' => $page->title,
295
                'content' => $page->content
296
            ]
297
        ]);
298
    }
299
 
300
 
301
    public function termsAndConditionsAction()
302
    {
303
        $pageCode = Page::PAGE_CODE_TERMS_AND_CONDITIONS;
304
 
305
        $currentNetworkPlugin = $this->plugin('currentNetworkPlugin');
306
        $currentNetwork = $currentNetworkPlugin->getNetwork();
307
 
308
        $currentUserPlugin = $this->plugin('currentUserPlugin');
309
 
310
 
311
        $pageMapper = PageMapper::getInstance($this->adapter);
312
        $page = $pageMapper->fetchOneByCodeAndNetworkId($pageCode, $currentNetwork->id);
313
 
314
        if (!$page) {
315
            $networkMapper = NetworkMapper::getInstance($this->adapter);
316
            $network = $networkMapper->fetchOneByDefault();
317
 
318
            $pageDefault = $pageMapper->fetchOneByCodeAndNetworkId($pageCode, $network->id);
319
            if ($pageDefault) {
320
                $page = new Page();
321
                $page->network_id = $currentNetwork->id;
322
                $page->code = $pageDefault->code;
323
                $page->content = $pageDefault->content;
324
                $page->fixed = $pageDefault->fixed;
325
                $page->page_default_id = $pageDefault->id;
326
                $page->title = $pageDefault->title;
327
                $page->status = $pageDefault->status;
328
                $page->type = $pageDefault->type;
329
                $page->url = $pageDefault->url;
330
 
331
                $pageMapper->insert($page);
332
            }
333
        }
334
 
335
        return new JsonModel([
336
            'success' => true,
337
            'data' => [
338
                'title' => $page->title,
339
                'content' => $page->content
340
            ]
341
        ]);
342
    }
343
 
344
    public function checkSessionAction()
345
    {
346
 
347
        $request = $this->getRequest();
348
        if ($request->isGet()) {
349
 
350
            $currentUserPlugin = $this->plugin('currentUserPlugin');
351
            if (!$currentUserPlugin->hasIdentity()) {
352
                //$flashMessenger = $this->plugin('FlashMessenger');
353
                //$flashMessenger->addErrorMessage('ERROR_SESSION_NOT_FOUND');
354
 
355
                $response = [
356
                    'success' => false,
357
                    'data' => [
358
                        'message' =>  '', //ERROR_SESSION_NOT_FOUND',
359
                        'url' => $this->url()->fromRoute('signout')
360
                    ]
361
                ];
362
 
363
                return new JsonModel($response);
364
            }
365
 
366
            $currentUser = $currentUserPlugin->getUser();
367
 
368
 
369
            if ($currentUser->last_activity_on) {
370
                $last_activity_on = strtotime($currentUser->last_activity_on);
371
            } else {
372
                $last_activity_on = strtotime('-1 day');
373
            }
374
 
375
            $expiry_time = $last_activity_on + $this->config['leaderslinked.security.last_activity_expired'];
376
            if (time() > $expiry_time) {
377
                //$flashMessenger = $this->plugin('FlashMessenger');
378
                //$flashMessenger->addErrorMessage('ERROR_SESSION_EXPIRED');
379
 
380
                $response = [
381
                    'success' => false,
382
                    'data' => [
383
                        'message' => 'ERROR_SESSION_EXPIRED',
384
                        'url' => $this->url()->fromRoute('signout')
385
                    ]
386
                ];
387
            } else {
388
                $notificationMapper = NotificationMapper::getInstance($this->adapter);
389
                $total_notifications = $notificationMapper->fetchUnreadNotificationsCount($currentUser->id);
390
 
391
                $messageMapper = MessageMapper::getInstance($this->adapter);
392
                $total_messages =  $messageMapper->fetchCountUnreadMessagesReceiverId($currentUser->id);
393
                $response = [
394
                    'success' => true,
395
                    'data' => [
396
                        'total_notifications' => $total_notifications,
397
                        'total_messages' => $total_messages
398
                    ]
399
                ];
400
            }
401
        } else {
402
            $response = [
403
                'success' => false,
404
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
405
            ];
406
        }
407
 
408
        return new JsonModel($response);
409
    }
410
 
411
 
412
 
413
 
414
 
415
    public function incTotalExternalSharedAction()
416
    {
417
 
418
        $request = $this->getRequest();
419
        if ($request->isPost()) {
420
            $currentUserPlugin = $this->plugin('currentUserPlugin');
421
            $currentUser = $currentUserPlugin->getUser();
422
 
423
            $currentNetworkPlugin = $this->plugin('currentNetworkPlugin');
424
            $currentNetwork = $currentNetworkPlugin->getNetwork();
425
 
426
            $code       = $this->params()->fromRoute('code');
427
            $type       = $this->params()->fromRoute('type');
428
            $user       = $this->params()->fromRoute('user');
429
            $timestamp  = intval($this->params()->fromRoute('timestamp'), 10);
430
            $rand       = intval($this->params()->fromRoute('rand'), 10);
431
            $password   = $this->params()->fromRoute('password');
432
 
433
 
434
 
435
            $checkpassword = '';
436
 
437
 
438
            $userCheck = '';
439
            if ($user && $timestamp > 0 && $rand > 0 && $password) {
440
                $userMapper = UserMapper::getInstance($this->adapter);
441
                $userCheck = $userMapper->fetchOneByUuid($user);
442
                if ($userCheck) {
443
                    $checkpassword  = md5('user-' . $userCheck->uuid . '-' . $type . '-' . $code . '-timestamp-' . $timestamp . '-rand-' . $rand . '-share-key-' . $userCheck->share_key);
444
                }
445
            }
446
 
447
            if (empty($password) || $password != $checkpassword) {
448
                $data = [
449
                    'success' => false,
450
                    'data' => 'ERROR_UNAUTHORIZED'
451
                ];
452
 
453
                return new JsonModel($data);
454
            }
455
 
456
 
457
 
458
 
459
 
460
 
461
 
462
 
463
 
464
            if ($type == 'feed' && $code) {
465
                $feedMapper =  FeedMapper::getInstance($this->adapter);
466
                $feed = $feedMapper->fetchOneByUuidAnyStatus($code);
467
 
468
 
469
                if ($feed) {
470
 
471
                    if ($feed->network_id != $currentNetwork->id) {
472
                        $data = [
473
                            'success' => false,
474
                            'data' =>    'ERROR_UNAUTHORIZED'
475
                        ];
476
 
477
                        return new JsonModel($data);
478
                    }
479
 
480
                    if ($feedMapper->incTotalExternalShared($feed->id)) {
481
                        $total = $feedMapper->fetchTotalExternalShared($feed->id);
482
 
483
                        $this->logger->info('El usuario : ' . trim($currentUser->first_name . ' ' . $currentUser->last_name) . ' (' . $currentUser->email . ') compartio externamente el feed : ' . $feed->title);
484
 
485
                        $data = [
486
                            'success' => true,
487
                            'data' => $total,
488
                        ];
489
 
490
                        return new JsonModel($data);
491
                    } else {
492
                        $data = [
493
                            'success' => false,
494
                            'data' => $feedMapper->getError()
495
                        ];
496
 
497
                        return new JsonModel($data);
498
                    }
499
                } else {
500
                    $data = [
501
                        'success' => false,
502
                        'data' => 'ERROR_FEED_NOT_FOUND',
503
                    ];
504
 
505
                    return new JsonModel($data);
506
                }
507
            } else if ($type == 'post' && $code) {
508
 
509
                $postMapper = PostMapper::getInstance($this->adapter);
510
                $post = $postMapper->fetchOneByUuid($code);
511
 
512
                if ($post && $post->status == Post::STATUS_ACTIVE) {
513
 
514
                    if ($post->network_id != $currentNetwork->id) {
515
                        $data = [
516
                            'success' => false,
517
                            'data' =>    'ERROR_UNAUTHORIZED'
518
                        ];
519
 
520
                        return new JsonModel($data);
521
                    }
522
 
523
 
524
                    if ($postMapper->incTotalExternalShared($post->id)) {
525
                        $total = $postMapper->fetchTotalExternalShared($post->id);
526
 
527
                        $this->logger->info('El usuario : ' . trim($currentUser->first_name . ' ' . $currentUser->last_name) . ' (' . $currentUser->email . ') compartio externamente el post : ' . $post->title);
528
 
529
 
530
 
531
                        $data = [
532
                            'success' => true,
533
                            'data' => $total,
534
                        ];
535
 
536
                        return new JsonModel($data);
537
                    } else {
538
                        $data = [
539
                            'success' => false,
540
                            'data' => $postMapper->getError()
541
                        ];
542
 
543
                        return new JsonModel($data);
544
                    }
545
                } else {
546
                    $data = [
547
                        'success' => false,
548
                        'data' => 'ERROR_POST_NOT_FOUND'
549
                    ];
550
 
551
                    return new JsonModel($data);
552
                }
553
            }
554
        } else {
555
            $response = [
556
                'success' => false,
557
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
558
            ];
559
 
560
            return new JsonModel($response);
561
        }
562
    }
563
 
564
    public function shareAction()
565
    {
566
        $request = $this->getRequest();
567
        if ($request->isGet()) {
568
            $currentUserPlugin = $this->plugin('currentUserPlugin');
569
            $currentUser = $currentUserPlugin->getUser();
570
 
571
            $code       = $this->params()->fromRoute('code');
572
            $type       = $this->params()->fromRoute('type');
573
            $user       = $this->params()->fromRoute('user');
574
            $timestamp  = intval($this->params()->fromRoute('timestamp'), 10);
575
            $rand       = intval($this->params()->fromRoute('rand'), 10);
576
            $password   = $this->params()->fromRoute('password');
577
 
578
 
579
 
580
            $checkpassword = '';
581
 
582
 
583
            $userCheck = '';
584
            if ($user && $timestamp > 0 && $rand > 0 && $password) {
585
                $userMapper = UserMapper::getInstance($this->adapter);
586
                $userCheck = $userMapper->fetchOneByUuid($user);
587
                if ($userCheck) {
588
                    $checkpassword  = md5('user-' . $userCheck->uuid . '-' . $type . '-' . $code . '-timestamp-' . $timestamp . '-rand-' . $rand . '-share-key-' . $userCheck->share_key);
589
                }
590
            }
591
 
592
            if (empty($password) || $password != $checkpassword) {
593
                $data = [
594
                    'success' => false,
595
                    'data' => 'ERROR_UNAUTHORIZED'
596
                ];
597
 
598
                return new JsonModel($data);
599
            }
600
 
601
            /*
602
            $share_params = [
603
                'type' => $type,
604
                'code' => $code,
605
                'user' => $currentUser->uuid,
606
                'timestamp' => $timestamp,
607
                'rand' => $rand,
608
                'password' => $password,
609
            ];
610
 
611
            $share_increment_external_counter_url = $this->url()->fromRoute('share/increment-external-counter', $share_params  , ['force_canonical' => true]);
612
            */
613
 
614
 
615
 
616
 
617
 
618
 
619
 
620
            if (strpos(strtolower($_SERVER['REQUEST_SCHEME']), 'https') === false) {
621
                $base_share = 'http://' . $_SERVER['HTTP_HOST'];
622
            } else {
623
                $base_share = 'https://' . $_SERVER['HTTP_HOST'];
624
            }
625
 
626
 
627
            /*
628
            echo '<pre>';
629
            print_r($_SERVER);
630
            echo '</pre>';
631
            */
632
 
633
 
634
            $share_url          = $base_share . $_SERVER['REQUEST_URI'];
635
            $share_image        = $base_share . '/images/ll-logo.png';
636
            $share_title        = '';
637
            $share_description  = '';
638
 
639
 
640
            if ($type == 'feed' && $code) {
641
                $feedMapper =  FeedMapper::getInstance($this->adapter);
642
                $feed = $feedMapper->fetchOneByUuidAnyStatus($code);
643
 
644
                // if($feed && $feed->status == Feed::STATUS_PUBLISHED) {
645
 
646
                if ($feed) {
647
 
648
                    $share_title = $feed->title ? $feed->title : '';
649
 
650
                    if ($feed->posted_or_shared  == Feed::SHARED) {
651
 
652
 
653
                        $feed = $feedMapper->fetchOneAnyStatus($feed->shared_feed_id);
654
                        if ($feed->title) {
655
 
656
                            $share_title = $share_title  .  ' -  ' . $feed->title;
657
                        }
658
                    }
659
 
660
 
661
                    $share_description = $feed->description;
662
 
663
                    $image_name = '';
664
                    if ($feed->file_type == Feed::FILE_TYPE_IMAGE) {
665
 
666
                        $image_name = $feed->file_name;
667
                    } else  if ($feed->file_image_preview) {
668
                        $image_name = $feed->file_image_preview;
669
                    }
670
 
671
 
672
 
673
                    if ($image_name) {
674
 
675
                        $source = $this->config['leaderslinked.fullpath.feed'] . $feed->uuid . DIRECTORY_SEPARATOR . $image_name;
676
 
677
 
678
                        $target_path = 'public' . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . 'feed' . DIRECTORY_SEPARATOR . $feed->uuid;
679
 
680
                        if (!file_exists($target_path)) {
681
                            mkdir($target_path, 0755, true);
682
                        }
683
 
684
 
685
 
686
                        $target = $target_path . DIRECTORY_SEPARATOR . $image_name;
687
 
688
 
689
 
690
                        if (!file_exists($target)) {
691
 
692
                            copy($source, $target);
693
                            $share_image =  $base_share . '/images/feed/' . $feed->uuid . '/' . $image_name;
694
                        } else {
695
                            $share_image =  $base_share . '/images/feed/' . $feed->uuid . '/' . $image_name;
696
                        }
697
                    }
698
                } else {
699
 
700
                    $response = new Response();
701
                    $headers = $response->getHeaders();
702
                    $headers->clearHeaders();
703
                    $headers->addHeaderLine('Content-type', 'application/json; charset=UTF-8');
704
 
705
                    $response->setStatusCode(404);
706
                    $response->setContent(json_encode(['success' => false, 'data' => 'error-router-no-match', 'fatal' => true]));
707
                    return $response;
708
                }
709
            } else if ($type == 'post' && $code) {
710
 
711
                $postMapper = PostMapper::getInstance($this->adapter);
712
                $post = $postMapper->fetchOneByUuid($code);
713
 
714
                if ($post && $post->status == Post::STATUS_ACTIVE) {
715
                    $share_title = $post->title;
716
                    $share_description = $post->description;
717
 
718
 
719
                    if ($post->image) {
720
                        $source = $this->config['leaderslinked.fullpath.post'] . $post->uuid . DIRECTORY_SEPARATOR . $post->image;
721
 
722
 
723
                        $target_path = 'public' . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . 'post' . DIRECTORY_SEPARATOR . $post->uuid;
724
 
725
                        if (!file_exists($target_path)) {
726
                            mkdir($target_path, 0755, true);
727
                        }
728
 
729
 
730
 
731
                        $target = $target_path . DIRECTORY_SEPARATOR . $post->image;
732
 
733
 
734
 
735
                        if (!file_exists($target)) {
736
 
737
                            copy($source, $target);
738
                            $share_image =  $base_share . '/images/post/' . $post->uuid . '/' . $post->image;
739
                        } else {
740
                            $share_image =  $base_share . '/images/post/' . $post->uuid . '/' . $post->image;
741
                        }
742
                    }
743
                } else {
744
 
745
                    $response = new Response();
746
                    $headers = $response->getHeaders();
747
                    $headers->clearHeaders();
748
                    $headers->addHeaderLine('Content-type', 'application/json; charset=UTF-8');
749
 
750
                    $response->setStatusCode(404);
751
                    $response->setContent(json_encode(['success' => false, 'data' => 'error-router-no-match', 'fatal' => true]));
752
                    return $response;
753
                }
754
            }
755
 
756
            /*
757
            echo '<pre>';
758
            print_r([ 'share_image' => $share_image,
759
                'share_url' => $share_url,
760
                'share_title' => strip_tags($share_title),
761
                'share_description' => strip_tags($share_description)]);  echo '</pre>';
762
            exit;
763
            */
764
 
765
            if ($currentUserPlugin->hasIdentity()) {
766
                $currentUser = $currentUserPlugin->getUser();
767
                if ($userCheck && $userCheck->status == User::STATUS_ACTIVE && $userCheck->id != $currentUser->id) {
768
 
769
                    $connectionMapper = ConnectionMapper::getInstance($this->adapter);
770
                    $connection = $connectionMapper->fetchOneByUserId1AndUserId2($currentUser->id, $userCheck->id);
771
 
772
                    if ($connection) {
773
 
774
                        if ($connection->status != Connection::STATUS_ACCEPTED) {
775
                            $connectionMapper->approve($connection);
776
                        }
777
                    } else {
778
                        $connection = new Connection();
779
                        $connection->request_from = $currentUser->id;
780
                        $connection->request_to = $userCheck->id;
781
                        $connection->status = Connection::STATUS_ACCEPTED;
782
 
783
                        $connectionMapper->insert($connection);
784
                    }
785
                }
786
 
787
 
788
 
789
 
790
                $this->layout()->setTemplate('layout/layout.phtml');
791
            } else {
792
                $this->cache->setItem('user_share_invitation', $user);
793
 
794
                $this->layout()->setTemplate('layout/share.phtml');
795
            }
796
            return new JsonModel([
797
                'share_image' => $share_image,
798
                'share_url' => $share_url,
799
                'share_title' => strip_tags($share_title),
800
                'share_description' => strip_tags($share_description),
801
                // 'share_increment_external_counter_url' => $share_increment_external_counter_url,
802
 
803
            ]);
804
 
805
        } else {
806
            $response = [
807
                'success' => false,
808
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
809
            ];
810
 
811
            return new JsonModel($response);
812
        }
813
    }
814
 
815
    public function languageAction()
816
    {
817
        $request = $this->getRequest();
818
 
819
        if ($request->isGet()) {
820
 
821
 
822
 
823
            $pathname = dirname(__DIR__);
824
            $filename = $pathname . DIRECTORY_SEPARATOR . 'i18n' . DIRECTORY_SEPARATOR . 'spanish.php';
825
 
826
 
827
            if(file_exists($filename)) {
828
 
829
                $arr =  include $filename;
830
                $arr = array_filter($arr, function($a)  {
831
                    return strpos($a, 'LABEL_') !== false;
832
                }, ARRAY_FILTER_USE_KEY);
833
 
834
 
835
                $data = [];
836
                foreach($arr as $key => $value)
837
                {
838
                    $key = str_replace('LABEL_', 'LANG_', $key);
839
 
840
                    $data[ $key ] = $value;
841
 
842
                }
843
 
844
 
845
 
846
                $response = [
847
                    'success' => true,
848
                    'data' => $data
849
                ];
850
 
851
                return new JsonModel($response);
852
 
853
 
854
            } else {
855
                $response = [
856
                    'success' => false,
857
                    'data' => 'ERROR_METHOD_NOT_ALLOWED'
858
                ];
859
 
860
                return new JsonModel($response);
861
            }
862
 
863
 
864
 
865
 
866
 
867
        } else {
868
            $response = [
869
                'success' => false,
870
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
871
            ];
872
 
873
            return new JsonModel($response);
874
        }
875
 
876
 
877
    }
878
}