Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

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

Rev Autor Línea Nro. Línea
1 www 1
<?php
2466 stevensc 2
 
1 www 3
declare(strict_types=1);
4
 
5
namespace LeadersLinked\Controller;
6
 
7
use Laminas\Db\Adapter\AdapterInterface;
8
use Laminas\Cache\Storage\Adapter\AbstractAdapter;
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\CompanyMapper;
16
use LeadersLinked\Mapper\CompanyUserMapper;
17
use LeadersLinked\Model\Company;
18
use LeadersLinked\Mapper\PageMapper;
19
use LeadersLinked\Mapper\MessageMapper;
2466 stevensc 20
use LeadersLinked\Mapper\UserMapper;
21
use LeadersLinked\Mapper\UserProfileMapper;
1 www 22
use LeadersLinked\Mapper\CompanyUserRoleMapper;
23
use LeadersLinked\Model\Role;
24
use LeadersLinked\Library\Functions;
2466 stevensc 25
use LeadersLinked\Mapper\ConnectionMapper;
26
use LeadersLinked\Mapper\LocationMapper;
1 www 27
use LeadersLinked\Mapper\PostMapper;
2466 stevensc 28
use LeadersLinked\Mapper\ProfileVisitMapper;
1 www 29
use LeadersLinked\Model\Post;
3138 efrain 30
use LeadersLinked\Mapper\UtilMapper;
3298 efrain 31
use LeadersLinked\Mapper\FeedMapper;
32
use LeadersLinked\Model\Feed;
33
use LeadersLinked\Model\User;
34
use LeadersLinked\Model\Connection;
1 www 35
 
36
class HomeController extends AbstractActionController
37
{
38
    /**
39
     *
40
     * @var AdapterInterface
41
     */
42
    private $adapter;
2466 stevensc 43
 
44
 
1 www 45
    /**
46
     *
47
     * @var AbstractAdapter
48
     */
49
    private $cache;
2466 stevensc 50
 
1 www 51
    /**
52
     *
53
     * @var  LoggerInterface
54
     */
55
    private $logger;
56
 
2466 stevensc 57
 
1 www 58
    /**
59
     *
60
     * @var array
61
     */
62
    private $config;
2466 stevensc 63
 
1 www 64
    /**
65
     *
66
     * @param AdapterInterface $adapter
67
     * @param AbstractAdapter $cache
68
     * @param LoggerInterface $logger
69
     * @param array $config
70
     */
2466 stevensc 71
    public function __construct($adapter, $cache, $logger,  $config)
1 www 72
    {
73
        $this->adapter      = $adapter;
74
        $this->cache        = $cache;
75
        $this->logger       = $logger;
76
        $this->config       = $config;
77
    }
2466 stevensc 78
 
79
 
80
 
1 www 81
    public function indexAction()
82
    {
83
 
3298 efrain 84
        $currentUserPlugin = $this->plugin('currentUserPlugin');
3302 efrain 85
        if ($currentUserPlugin->hasIdentity()) {
2466 stevensc 86
            return $this->redirect()->toRoute('dashboard');
1 www 87
        } else {
2466 stevensc 88
            return $this->redirect()->toRoute('signin');
1 www 89
        }
90
    }
2466 stevensc 91
 
92
 
93
 
94
 
1 www 95
    public function privacyPolicyAction()
96
    {
97
        $pageMapper = PageMapper::getInstance($this->adapter);
98
        $page = $pageMapper->fetchOne(Page::PAGE_ID_PRIVACY_POLICY);
2466 stevensc 99
 
1 www 100
        $this->layout()->setTemplate('layout/layout.phtml');
101
        $viewModel = new ViewModel();
102
        $viewModel->setTemplate('leaders-linked/home/privacy-policy.phtml');
103
        $viewModel->setVariable('page', $page);
2466 stevensc 104
        return $viewModel;
1 www 105
    }
2466 stevensc 106
 
1 www 107
    public function cookiesAction()
108
    {
109
        $pageMapper = PageMapper::getInstance($this->adapter);
110
        $page = $pageMapper->fetchOne(Page::PAGE_ID_COOKIES);
2466 stevensc 111
 
1 www 112
        $this->layout()->setTemplate('layout/layout.phtml');
113
        $viewModel = new ViewModel();
114
        $viewModel->setTemplate('leaders-linked/home/cookies.phtml');
115
        $viewModel->setVariable('page', $page);
2466 stevensc 116
        return $viewModel;
1 www 117
    }
2466 stevensc 118
 
1 www 119
    public function professionalismPolicyAction()
120
    {
121
        //
2466 stevensc 122
 
1 www 123
        $pageMapper = PageMapper::getInstance($this->adapter);
124
        $page = $pageMapper->fetchOne(Page::PAGE_ID_PROFESSIONALISM_POLICY);
2466 stevensc 125
 
1 www 126
        $this->layout()->setTemplate('layout/layout.phtml');
127
        $viewModel = new ViewModel();
128
        $viewModel->setTemplate('leaders-linked/home/professionalism-policy');
129
        $viewModel->setVariable('page', $page);
2466 stevensc 130
        return $viewModel;
1 www 131
    }
2466 stevensc 132
 
133
 
1 www 134
    public function termsAndConditionsAction()
135
    {
136
        $pageMapper = PageMapper::getInstance($this->adapter);
137
        $page = $pageMapper->fetchOne(Page::PAGE_ID_TERMS_AND_CONDITIONS);
2466 stevensc 138
 
1 www 139
        $this->layout()->setTemplate('layout/layout.phtml');
140
        $viewModel = new ViewModel();
141
        $viewModel->setTemplate('leaders-linked/home/terms-and-conditions.phtml');
142
        $viewModel->setVariable('page', $page);
2466 stevensc 143
        return $viewModel;
1 www 144
    }
2466 stevensc 145
 
1 www 146
    public function checkSessionAction()
147
    {
148
 
149
        $request = $this->getRequest();
2466 stevensc 150
        if ($request->isGet()) {
151
 
1 www 152
            $currentUserPlugin = $this->plugin('currentUserPlugin');
2466 stevensc 153
            if (!$currentUserPlugin->hasIdentity()) {
1 www 154
                $flashMessenger = $this->plugin('FlashMessenger');
155
                $flashMessenger->addErrorMessage('ERROR_SESSION_NOT_FOUND');
2466 stevensc 156
 
1 www 157
                $response = [
158
                    'success' => false,
159
                    'data' => [
160
                        'message' =>  'ERROR_SESSION_NOT_FOUND',
161
                        'url' => $this->url()->fromRoute('signout')
162
                    ]
163
                ];
2466 stevensc 164
 
1 www 165
                return new JsonModel($response);
166
            }
2466 stevensc 167
 
1 www 168
            $currentUser = $currentUserPlugin->getUser();
2466 stevensc 169
 
170
 
171
            if ($currentUser->last_activity_on) {
1 www 172
                $last_activity_on = strtotime($currentUser->last_activity_on);
173
            } else {
174
                $last_activity_on = strtotime('-1 day');
175
            }
176
 
177
            $expiry_time = $last_activity_on + $this->config['leaderslinked.security.last_activity_expired'];
178
            if (time() > $expiry_time) {
2466 stevensc 179
                //$flashMessenger = $this->plugin('FlashMessenger');
180
                //$flashMessenger->addErrorMessage('ERROR_SESSION_EXPIRED');
1 www 181
 
182
                $response = [
183
                    'success' => false,
184
                    'data' => [
185
                        'message' => 'ERROR_SESSION_EXPIRED',
186
                        'url' => $this->url()->fromRoute('signout')
187
                    ]
188
                ];
189
            } else {
190
                $notificationMapper = NotificationMapper::getInstance($this->adapter);
191
                $total_notifications = $notificationMapper->fetchUnreadNotificationsCount($currentUser->id);
2466 stevensc 192
 
193
                $messageMapper = MessageMapper::getInstance($this->adapter);
1 www 194
                $total_messages =  $messageMapper->fetchCountUnreadMessagesReceiverId($currentUser->id);
195
                $response = [
196
                    'success' => true,
197
                    'data' => [
198
                        'total_notifications' => $total_notifications,
199
                        'total_messages' => $total_messages
200
                    ]
201
                ];
202
            }
203
        } else {
204
            $response = [
205
                'success' => false,
206
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
207
            ];
208
        }
2466 stevensc 209
 
1 www 210
        return new JsonModel($response);
211
    }
2466 stevensc 212
 
3262 efrain 213
 
1 www 214
    public function postAction()
215
    {
3364 efrain 216
        $request = $this->getRequest();
217
        if ($request->isGet()) {
218
            $currentUserPlugin = $this->plugin('currentUserPlugin');
219
            $currentUser = $currentUserPlugin->getUser();
220
 
221
 
222
            $id = $this->params()->fromRoute('id');
223
 
224
            $postMapper = PostMapper::getInstance($this->adapter);
225
            $post = $postMapper->fetchOneByUuid($id);
226
 
227
            if (!$post || $post->status != Post::STATUS_ACTIVE) {
228
                $flashMessenger = $this->plugin('FlashMessenger');
229
 
230
                if (!$id) {
231
                    $flashMessenger->addErrorMessage('ERROR_POST_NOT_AVAILABLE');
232
                    return $this->redirect()->toRoute('dashboard');
233
                }
1 www 234
            }
3364 efrain 235
 
236
 
237
 
238
            $timestamp = time();
239
 
240
            list($usec, $sec) = explode(' ', microtime());
241
            $seed = intval($sec + ((float) $usec * 100000));
242
            mt_srand($seed, MT_RAND_MT19937);
243
            $rand =  mt_rand();
244
 
245
 
2466 stevensc 246
 
3366 efrain 247
            $password  = md5('user-' . $currentUser->uuid . '-post-' . $post->uuid . '-timestamp-' . $timestamp . '-rand-' . $rand . '-share-key-' . $currentUser->share_key) ;
3298 efrain 248
 
3364 efrain 249
 
250
            $query = [
3373 efrain 251
                'll0' => $currentUser->uuid,
252
                'll1' => $timestamp,
253
                'll2' => $rand,
254
                'll3' => $password,
3364 efrain 255
 
256
            ];
257
 
258
            $share_url = $this->url()->fromRoute('share',  ['type' => 'post', 'code' => $post->uuid], ['force_canonical' => true, 'query' => $query ]);
259
 
260
 
261
            $this->layout()->setTemplate('layout/layout.phtml');
262
            $viewModel = new ViewModel();
263
            $viewModel->setTemplate('leaders-linked/home/post.phtml');
264
            $viewModel->setVariables([
265
                'post' => $post,
266
                'id' => $post->id,
267
                'uuid' => $post->uuid,
268
                'title' => $post->title,
269
                'description' => $post->description,
270
                'url' => $post->url,
271
                'date' => $post->date,
272
                'status' => $post->status,
273
                'image' => $post->image,
274
                'file' => $post->file,
275
                'added_on' => $post->added_on,
276
                'share_external_url' => $share_url,
277
 
278
            ]);
279
            return $viewModel;
280
 
281
        } else {
282
            $response = [
283
                'success' => false,
284
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
285
            ];
286
 
287
            return new JsonModel($response);
288
        }
1 www 289
    }
3298 efrain 290
 
291
    public function shareAction()
292
    {
293
        $request = $this->getRequest();
294
        if ($request->isGet()) {
295
            $currentUserPlugin = $this->plugin('currentUserPlugin');
296
            $currentUser = $currentUserPlugin->getUser();
297
 
3364 efrain 298
            $code       = $this->params()->fromRoute('code');
299
            $type       = $this->params()->fromRoute('type');
3373 efrain 300
            $user       = $this->params()->fromQuery('ll0');
301
            $timestamp  = intval($this->params()->fromQuery('ll1'), 10);
302
            $rand       = intval($this->params()->fromQuery('ll2'), 10);
303
            $password   = $this->params()->fromQuery('ll3');
3364 efrain 304
            $checkpassword = '';
305
 
3369 efrain 306
 
307
 
3364 efrain 308
            $userCheck = '';
309
            if($user && $timestamp > 0 && $rand > 0 && $password) {
310
                $userMapper = UserMapper::getInstance($this->adapter);
311
                $userCheck = $userMapper->fetchOneByUuid($user);
312
                if($userCheck) {
3366 efrain 313
                    $checkpassword  = md5('user-' . $userCheck->uuid . '-'.$type.'-' . $code . '-timestamp-' . $timestamp . '-rand-' . $rand . '-share-key-' . $userCheck->share_key) ;
3364 efrain 314
                }
315
            }
3349 efrain 316
 
3364 efrain 317
            if(empty($password) || $password != $checkpassword) {
318
                $data = [
3349 efrain 319
                    'success' => false,
320
                    'data' => 'ERROR_UNAUTHORIZED'
321
                ];
322
 
3364 efrain 323
                return new JsonModel($data);
3349 efrain 324
            }
3371 efrain 325
 
3364 efrain 326
 
327
 
328
 
329
 
3357 efrain 330
 
3298 efrain 331
 
3335 efrain 332
 
333
            if(strpos(strtolower($_SERVER['REQUEST_SCHEME']), 'https') === false) {
3355 efrain 334
                $base_share = 'http://' . $_SERVER['HTTP_HOST'];
3298 efrain 335
            } else {
3355 efrain 336
                $base_share = 'https://' . $_SERVER['HTTP_HOST'];
3298 efrain 337
            }
338
 
339
 
3374 efrain 340
            /*
3372 efrain 341
            echo '<pre>';
342
            print_r($_SERVER);
343
            echo '</pre>';
3374 efrain 344
            */
3298 efrain 345
 
3372 efrain 346
 
3355 efrain 347
            $share_url          = $base_share . $_SERVER['REQUEST_URI'];
348
            $share_image        = $base_share . '/images/ll-logo.png';
3298 efrain 349
            $share_title        = '';
350
            $share_description  = '';
3364 efrain 351
 
3298 efrain 352
 
353
            if($type == 'feed' && $code ) {
354
                $feedMapper =  FeedMapper::getInstance($this->adapter);
355
                $feed = $feedMapper->fetchOneByUuid($code);
356
 
357
                if($feed && $feed->status == Feed::STATUS_PUBLISHED) {
358
                    $share_title = $feed->title ? $feed->title : $feed->description;
359
                    $share_description = $feed->description;
360
 
361
                    $image_name = '';
362
                    if($feed->file_type == Feed::FILE_TYPE_IMAGE) {
363
 
364
                        $image_name = $feed->file_name;
365
 
366
                    } else  if($feed->file_image_preview) {
367
                        $image_name = $feed->file_image_preview;
368
                    }
369
 
370
 
371
 
372
                    if( $image_name ) {
373
 
374
                        $source = $this->config['leaderslinked.fullpath.feed'] . $feed->uuid . DIRECTORY_SEPARATOR . $image_name;
375
 
376
 
377
                        $target_path = 'public' . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . 'feed'. DIRECTORY_SEPARATOR . $feed->uuid;
378
 
379
                        if(!file_exists($target_path)) {
380
                            mkdir($target_path, 0755, true);
381
                        }
382
 
383
 
384
 
385
                        $target = $target_path . DIRECTORY_SEPARATOR . $image_name;
386
 
387
 
388
 
389
                        if(!file_exists($target)) {
390
 
391
                            copy($source, $target);
3355 efrain 392
                            $share_image =  $base_share . '/images/feed/' . $feed->uuid . '/' . $image_name;
3298 efrain 393
 
394
                        } else {
3355 efrain 395
                            $share_image =  $base_share . '/images/feed/' . $feed->uuid . '/' . $image_name;
3298 efrain 396
 
397
                        }
398
 
399
 
400
 
401
 
402
                    }
403
 
3349 efrain 404
                } else {
405
 
406
                    if($currentUserPlugin->hasIdentity()) {
407
                        $this->layout()->setTemplate('layout/layout.phtml');
408
                    } else {
409
                        $this->layout()->setTemplate('layout/share.phtml');
410
                    }
411
                    $viewModel = new ViewModel();
412
                    $viewModel->setTemplate('leaders-linked/error/404.phtml');
413
                    return $viewModel;
3298 efrain 414
                }
415
 
416
 
417
            } else if ($type == 'post' && $code) {
418
 
419
                $postMapper = PostMapper::getInstance($this->adapter);
420
                $post = $postMapper->fetchOneByUuid($code);
421
 
422
                if($post && $post->status == Post::STATUS_ACTIVE) {
423
                    $share_title = $post->title;
424
                    $share_description = $post->description;
425
 
426
 
427
                    if($post->image) {
428
                        $source = $this->config['leaderslinked.fullpath.post'] . $post->uuid . DIRECTORY_SEPARATOR . $post->image;
429
 
430
 
431
                        $target_path = 'public' . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . 'post'. DIRECTORY_SEPARATOR . $post->uuid;
432
 
433
                        if(!file_exists($target_path)) {
434
                            mkdir($target_path, 0755, true);
435
                        }
436
 
437
 
438
 
439
                        $target = $target_path . DIRECTORY_SEPARATOR . $post->image;
440
 
441
 
442
 
443
                        if(!file_exists($target)) {
444
 
445
                            copy($source, $target);
3355 efrain 446
                            $share_image =  $base_share . '/images/post/' . $post->uuid . '/' . $post->image;
3298 efrain 447
 
448
                        } else {
3355 efrain 449
                            $share_image =  $base_share . '/images/post/' . $post->uuid . '/' . $post->image;
3298 efrain 450
 
451
                        }
452
                    }
3349 efrain 453
                } else {
454
 
455
                    if($currentUserPlugin->hasIdentity()) {
456
                        $this->layout()->setTemplate('layout/layout.phtml');
457
                    } else {
458
                        $this->layout()->setTemplate('layout/share.phtml');
459
                    }
460
                    $viewModel = new ViewModel();
461
                    $viewModel->setTemplate('leaders-linked/error/404.phtml');
462
                    return $viewModel;
3298 efrain 463
                }
464
            }
3374 efrain 465
 
3376 efrain 466
            /*
3372 efrain 467
            echo '<pre>';
3371 efrain 468
            print_r([ 'share_image' => $share_image,
469
                'share_url' => $share_url,
470
                'share_title' => strip_tags($share_title),
3372 efrain 471
                'share_description' => strip_tags($share_description)]);  echo '</pre>';
472
            exit;
3376 efrain 473
            */
3298 efrain 474
 
3349 efrain 475
            if($currentUserPlugin->hasIdentity()) {
3364 efrain 476
                $currentUser = $currentUserPlugin->getUser();
477
                if($userCheck && $userCheck->status == User::STATUS_ACTIVE && $userCheck->id != $currentUser->id ) {
478
 
479
                    $connectionMapper = ConnectionMapper::getInstance($this->adapter);
480
                    $connection = $connectionMapper->fetchOneByUserId1AndUserId2($currentUser->id, $userCheck->id);
481
 
482
                    if($connection) {
483
 
484
                        if($connection->status != Connection::STATUS_ACCEPTED) {
485
                            $connectionMapper->approve($connection);
486
                        }
487
 
488
                    } else {
489
                        $connection = new Connection();
490
                        $connection->request_from = $currentUser->id;
491
                        $connection->request_to = $userCheck->id;
492
                        $connection->status = Connection::STATUS_ACCEPTED;
493
 
494
                        $connectionMapper->insert($connection);
495
                    }
496
                }
497
 
498
 
499
 
500
 
3349 efrain 501
                $this->layout()->setTemplate('layout/layout.phtml');
502
            } else {
3364 efrain 503
                $this->cache->addItem('user_share_invitation', $user);
504
 
3349 efrain 505
                $this->layout()->setTemplate('layout/share.phtml');
506
            }
3298 efrain 507
            $viewModel = new ViewModel();
508
            $viewModel->setTemplate('leaders-linked/home/share.phtml');
509
            $viewModel->setVariables([
3352 efrain 510
                'share_image' => $share_image,
511
                'share_url' => $share_url,
3356 efrain 512
                'share_title' => strip_tags($share_title),
513
                'share_description' => strip_tags($share_description),
3349 efrain 514
 
3298 efrain 515
            ]);
516
 
517
 
518
            return $viewModel;
519
 
520
 
521
        } else {
522
            $response = [
523
                'success' => false,
524
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
525
            ];
526
 
527
            return new JsonModel($response);
528
        }
529
 
530
 
531
    }
532
 
3364 efrain 533
 
1 www 534
}