Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 3382 | Rev 3453 | 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
 
3380 efrain 250
            $share_params = [
3379 efrain 251
                'type' => 'post',
252
                'code' => $post->uuid,
253
                'user' => $currentUser->uuid,
254
                'timestamp' => $timestamp,
255
                'rand' => $rand,
256
                'password' => $password,
257
            ];
3364 efrain 258
 
3379 efrain 259
 
3380 efrain 260
            $share_external_url = $this->url()->fromRoute('share',$share_params  , ['force_canonical' => true]);
3379 efrain 261
 
3364 efrain 262
            $this->layout()->setTemplate('layout/layout.phtml');
263
            $viewModel = new ViewModel();
264
            $viewModel->setTemplate('leaders-linked/home/post.phtml');
265
            $viewModel->setVariables([
266
                'post' => $post,
267
                'id' => $post->id,
268
                'uuid' => $post->uuid,
269
                'title' => $post->title,
270
                'description' => $post->description,
271
                'url' => $post->url,
272
                'date' => $post->date,
273
                'status' => $post->status,
274
                'image' => $post->image,
275
                'file' => $post->file,
276
                'added_on' => $post->added_on,
3379 efrain 277
                'share_external_url' =>  $share_external_url,
3364 efrain 278
 
279
            ]);
280
            return $viewModel;
281
 
282
        } else {
283
            $response = [
284
                'success' => false,
285
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
286
            ];
287
 
288
            return new JsonModel($response);
289
        }
1 www 290
    }
3298 efrain 291
 
292
    public function shareAction()
293
    {
294
        $request = $this->getRequest();
295
        if ($request->isGet()) {
296
            $currentUserPlugin = $this->plugin('currentUserPlugin');
297
            $currentUser = $currentUserPlugin->getUser();
298
 
3364 efrain 299
            $code       = $this->params()->fromRoute('code');
300
            $type       = $this->params()->fromRoute('type');
3379 efrain 301
            $user       = $this->params()->fromRoute('user');
302
            $timestamp  = intval($this->params()->fromRoute('timestamp'), 10);
303
            $rand       = intval($this->params()->fromRoute('rand'), 10);
304
            $password   = $this->params()->fromRoute('password');
3377 efrain 305
 
3379 efrain 306
 
307
 
3364 efrain 308
            $checkpassword = '';
309
 
3383 efrain 310
 
3364 efrain 311
            $userCheck = '';
312
            if($user && $timestamp > 0 && $rand > 0 && $password) {
313
                $userMapper = UserMapper::getInstance($this->adapter);
314
                $userCheck = $userMapper->fetchOneByUuid($user);
315
                if($userCheck) {
3366 efrain 316
                    $checkpassword  = md5('user-' . $userCheck->uuid . '-'.$type.'-' . $code . '-timestamp-' . $timestamp . '-rand-' . $rand . '-share-key-' . $userCheck->share_key) ;
3364 efrain 317
                }
318
            }
3349 efrain 319
 
3364 efrain 320
            if(empty($password) || $password != $checkpassword) {
321
                $data = [
3349 efrain 322
                    'success' => false,
323
                    'data' => 'ERROR_UNAUTHORIZED'
324
                ];
325
 
3364 efrain 326
                return new JsonModel($data);
3383 efrain 327
            }
3371 efrain 328
 
3364 efrain 329
 
330
 
331
 
332
 
3357 efrain 333
 
3298 efrain 334
 
3335 efrain 335
 
336
            if(strpos(strtolower($_SERVER['REQUEST_SCHEME']), 'https') === false) {
3355 efrain 337
                $base_share = 'http://' . $_SERVER['HTTP_HOST'];
3298 efrain 338
            } else {
3355 efrain 339
                $base_share = 'https://' . $_SERVER['HTTP_HOST'];
3298 efrain 340
            }
341
 
342
 
3374 efrain 343
            /*
3372 efrain 344
            echo '<pre>';
345
            print_r($_SERVER);
346
            echo '</pre>';
3374 efrain 347
            */
3298 efrain 348
 
3372 efrain 349
 
3355 efrain 350
            $share_url          = $base_share . $_SERVER['REQUEST_URI'];
351
            $share_image        = $base_share . '/images/ll-logo.png';
3298 efrain 352
            $share_title        = '';
353
            $share_description  = '';
3364 efrain 354
 
3298 efrain 355
 
356
            if($type == 'feed' && $code ) {
357
                $feedMapper =  FeedMapper::getInstance($this->adapter);
358
                $feed = $feedMapper->fetchOneByUuid($code);
359
 
360
                if($feed && $feed->status == Feed::STATUS_PUBLISHED) {
361
                    $share_title = $feed->title ? $feed->title : $feed->description;
362
                    $share_description = $feed->description;
363
 
364
                    $image_name = '';
365
                    if($feed->file_type == Feed::FILE_TYPE_IMAGE) {
366
 
367
                        $image_name = $feed->file_name;
368
 
369
                    } else  if($feed->file_image_preview) {
370
                        $image_name = $feed->file_image_preview;
371
                    }
372
 
373
 
374
 
375
                    if( $image_name ) {
376
 
377
                        $source = $this->config['leaderslinked.fullpath.feed'] . $feed->uuid . DIRECTORY_SEPARATOR . $image_name;
378
 
379
 
380
                        $target_path = 'public' . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . 'feed'. DIRECTORY_SEPARATOR . $feed->uuid;
381
 
382
                        if(!file_exists($target_path)) {
383
                            mkdir($target_path, 0755, true);
384
                        }
385
 
386
 
387
 
388
                        $target = $target_path . DIRECTORY_SEPARATOR . $image_name;
389
 
390
 
391
 
392
                        if(!file_exists($target)) {
393
 
394
                            copy($source, $target);
3355 efrain 395
                            $share_image =  $base_share . '/images/feed/' . $feed->uuid . '/' . $image_name;
3298 efrain 396
 
397
                        } else {
3355 efrain 398
                            $share_image =  $base_share . '/images/feed/' . $feed->uuid . '/' . $image_name;
3298 efrain 399
 
400
                        }
401
 
402
 
403
 
404
 
405
                    }
406
 
3349 efrain 407
                } else {
408
 
409
                    if($currentUserPlugin->hasIdentity()) {
410
                        $this->layout()->setTemplate('layout/layout.phtml');
411
                    } else {
412
                        $this->layout()->setTemplate('layout/share.phtml');
413
                    }
414
                    $viewModel = new ViewModel();
415
                    $viewModel->setTemplate('leaders-linked/error/404.phtml');
416
                    return $viewModel;
3298 efrain 417
                }
418
 
419
 
420
            } else if ($type == 'post' && $code) {
421
 
422
                $postMapper = PostMapper::getInstance($this->adapter);
423
                $post = $postMapper->fetchOneByUuid($code);
424
 
425
                if($post && $post->status == Post::STATUS_ACTIVE) {
426
                    $share_title = $post->title;
427
                    $share_description = $post->description;
428
 
429
 
430
                    if($post->image) {
431
                        $source = $this->config['leaderslinked.fullpath.post'] . $post->uuid . DIRECTORY_SEPARATOR . $post->image;
432
 
433
 
434
                        $target_path = 'public' . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . 'post'. DIRECTORY_SEPARATOR . $post->uuid;
435
 
436
                        if(!file_exists($target_path)) {
437
                            mkdir($target_path, 0755, true);
438
                        }
439
 
440
 
441
 
442
                        $target = $target_path . DIRECTORY_SEPARATOR . $post->image;
443
 
444
 
445
 
446
                        if(!file_exists($target)) {
447
 
448
                            copy($source, $target);
3355 efrain 449
                            $share_image =  $base_share . '/images/post/' . $post->uuid . '/' . $post->image;
3298 efrain 450
 
451
                        } else {
3355 efrain 452
                            $share_image =  $base_share . '/images/post/' . $post->uuid . '/' . $post->image;
3298 efrain 453
 
454
                        }
455
                    }
3349 efrain 456
                } else {
457
 
458
                    if($currentUserPlugin->hasIdentity()) {
459
                        $this->layout()->setTemplate('layout/layout.phtml');
460
                    } else {
461
                        $this->layout()->setTemplate('layout/share.phtml');
462
                    }
463
                    $viewModel = new ViewModel();
464
                    $viewModel->setTemplate('leaders-linked/error/404.phtml');
465
                    return $viewModel;
3298 efrain 466
                }
467
            }
3374 efrain 468
 
3382 efrain 469
            /*
3372 efrain 470
            echo '<pre>';
3371 efrain 471
            print_r([ 'share_image' => $share_image,
472
                'share_url' => $share_url,
473
                'share_title' => strip_tags($share_title),
3372 efrain 474
                'share_description' => strip_tags($share_description)]);  echo '</pre>';
475
            exit;
3382 efrain 476
            */
3298 efrain 477
 
3349 efrain 478
            if($currentUserPlugin->hasIdentity()) {
3364 efrain 479
                $currentUser = $currentUserPlugin->getUser();
480
                if($userCheck && $userCheck->status == User::STATUS_ACTIVE && $userCheck->id != $currentUser->id ) {
481
 
482
                    $connectionMapper = ConnectionMapper::getInstance($this->adapter);
483
                    $connection = $connectionMapper->fetchOneByUserId1AndUserId2($currentUser->id, $userCheck->id);
484
 
485
                    if($connection) {
486
 
487
                        if($connection->status != Connection::STATUS_ACCEPTED) {
488
                            $connectionMapper->approve($connection);
489
                        }
490
 
491
                    } else {
492
                        $connection = new Connection();
493
                        $connection->request_from = $currentUser->id;
494
                        $connection->request_to = $userCheck->id;
495
                        $connection->status = Connection::STATUS_ACCEPTED;
496
 
497
                        $connectionMapper->insert($connection);
498
                    }
499
                }
500
 
501
 
3383 efrain 502
 
3364 efrain 503
 
3349 efrain 504
                $this->layout()->setTemplate('layout/layout.phtml');
505
            } else {
3383 efrain 506
                $this->cache->addItem('user_share_invitation', $user);
3364 efrain 507
 
3349 efrain 508
                $this->layout()->setTemplate('layout/share.phtml');
509
            }
3298 efrain 510
            $viewModel = new ViewModel();
511
            $viewModel->setTemplate('leaders-linked/home/share.phtml');
512
            $viewModel->setVariables([
3352 efrain 513
                'share_image' => $share_image,
514
                'share_url' => $share_url,
3356 efrain 515
                'share_title' => strip_tags($share_title),
516
                'share_description' => strip_tags($share_description),
3349 efrain 517
 
3298 efrain 518
            ]);
519
 
520
 
521
            return $viewModel;
522
 
523
 
524
        } else {
525
            $response = [
526
                'success' => false,
527
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
528
            ];
529
 
530
            return new JsonModel($response);
531
        }
532
 
533
 
534
    }
535
 
3364 efrain 536
 
1 www 537
}