| 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;
|
| 3674 |
efrain |
35 |
use LeadersLinked\Mapper\NetworkMapper;
|
| 1 |
www |
36 |
|
|
|
37 |
class HomeController extends AbstractActionController
|
|
|
38 |
{
|
|
|
39 |
/**
|
|
|
40 |
*
|
|
|
41 |
* @var AdapterInterface
|
|
|
42 |
*/
|
|
|
43 |
private $adapter;
|
| 2466 |
stevensc |
44 |
|
|
|
45 |
|
| 1 |
www |
46 |
/**
|
|
|
47 |
*
|
|
|
48 |
* @var AbstractAdapter
|
|
|
49 |
*/
|
|
|
50 |
private $cache;
|
| 2466 |
stevensc |
51 |
|
| 1 |
www |
52 |
/**
|
|
|
53 |
*
|
|
|
54 |
* @var LoggerInterface
|
|
|
55 |
*/
|
|
|
56 |
private $logger;
|
|
|
57 |
|
| 2466 |
stevensc |
58 |
|
| 1 |
www |
59 |
/**
|
|
|
60 |
*
|
|
|
61 |
* @var array
|
|
|
62 |
*/
|
|
|
63 |
private $config;
|
| 2466 |
stevensc |
64 |
|
| 1 |
www |
65 |
/**
|
|
|
66 |
*
|
|
|
67 |
* @param AdapterInterface $adapter
|
|
|
68 |
* @param AbstractAdapter $cache
|
|
|
69 |
* @param LoggerInterface $logger
|
|
|
70 |
* @param array $config
|
|
|
71 |
*/
|
| 2466 |
stevensc |
72 |
public function __construct($adapter, $cache, $logger, $config)
|
| 1 |
www |
73 |
{
|
|
|
74 |
$this->adapter = $adapter;
|
|
|
75 |
$this->cache = $cache;
|
|
|
76 |
$this->logger = $logger;
|
|
|
77 |
$this->config = $config;
|
|
|
78 |
}
|
| 2466 |
stevensc |
79 |
|
|
|
80 |
|
|
|
81 |
|
| 1 |
www |
82 |
public function indexAction()
|
|
|
83 |
{
|
|
|
84 |
|
| 3298 |
efrain |
85 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
| 3302 |
efrain |
86 |
if ($currentUserPlugin->hasIdentity()) {
|
| 2466 |
stevensc |
87 |
return $this->redirect()->toRoute('dashboard');
|
| 1 |
www |
88 |
} else {
|
| 2466 |
stevensc |
89 |
return $this->redirect()->toRoute('signin');
|
| 1 |
www |
90 |
}
|
|
|
91 |
}
|
| 2466 |
stevensc |
92 |
|
|
|
93 |
|
|
|
94 |
|
|
|
95 |
|
| 1 |
www |
96 |
public function privacyPolicyAction()
|
|
|
97 |
{
|
| 3674 |
efrain |
98 |
$pageCode = Page::PAGE_CODE_PRIVACY_POLICY;
|
|
|
99 |
|
|
|
100 |
$currentNetworkPlugin = $this->plugin('currentNetworkPlugin');
|
|
|
101 |
$currentNetwork = $currentNetworkPlugin->getNetwork();
|
|
|
102 |
|
| 1 |
www |
103 |
$pageMapper = PageMapper::getInstance($this->adapter);
|
| 3674 |
efrain |
104 |
$page = $pageMapper->fetchOneByCodeAndNetworkId($pageCode, $currentNetwork->id);
|
|
|
105 |
|
|
|
106 |
if(!$page) {
|
|
|
107 |
$networkMapper = NetworkMapper::getInstance($this->adapter);
|
|
|
108 |
$network = $networkMapper->fetchOneByDefault();
|
|
|
109 |
|
|
|
110 |
$pageDefault = $pageMapper->fetchOneByCodeAndNetworkId($pageCode, $network->id);
|
|
|
111 |
if($pageDefault) {
|
|
|
112 |
$page = new Page();
|
|
|
113 |
$page->network_id = $currentNetwork->id;
|
|
|
114 |
$page->code = $pageDefault->code;
|
|
|
115 |
$page->content = $pageDefault->content;
|
|
|
116 |
$page->fixed = $pageDefault->fixed;
|
|
|
117 |
$page->page_default_id = $pageDefault->id;
|
|
|
118 |
$page->title = $pageDefault->title;
|
|
|
119 |
$page->status = $pageDefault->status;
|
|
|
120 |
$page->type = $pageDefault->type;
|
|
|
121 |
$page->url = $pageDefault->url;
|
|
|
122 |
|
|
|
123 |
$pageMapper->insert($page);
|
|
|
124 |
}
|
|
|
125 |
|
|
|
126 |
}
|
| 2466 |
stevensc |
127 |
|
| 1 |
www |
128 |
$this->layout()->setTemplate('layout/layout.phtml');
|
|
|
129 |
$viewModel = new ViewModel();
|
|
|
130 |
$viewModel->setTemplate('leaders-linked/home/privacy-policy.phtml');
|
|
|
131 |
$viewModel->setVariable('page', $page);
|
| 2466 |
stevensc |
132 |
return $viewModel;
|
| 1 |
www |
133 |
}
|
| 2466 |
stevensc |
134 |
|
| 1 |
www |
135 |
public function cookiesAction()
|
|
|
136 |
{
|
| 3674 |
efrain |
137 |
|
|
|
138 |
$pageCode = Page::PAGE_CODE_COOKIES;
|
|
|
139 |
|
|
|
140 |
$currentNetworkPlugin = $this->plugin('currentNetworkPlugin');
|
|
|
141 |
$currentNetwork = $currentNetworkPlugin->getNetwork();
|
|
|
142 |
|
| 1 |
www |
143 |
$pageMapper = PageMapper::getInstance($this->adapter);
|
| 3674 |
efrain |
144 |
$page = $pageMapper->fetchOneByCodeAndNetworkId($pageCode, $currentNetwork->id);
|
|
|
145 |
|
|
|
146 |
if(!$page) {
|
|
|
147 |
$networkMapper = NetworkMapper::getInstance($this->adapter);
|
|
|
148 |
$network = $networkMapper->fetchOneByDefault();
|
|
|
149 |
|
|
|
150 |
$pageDefault = $pageMapper->fetchOneByCodeAndNetworkId($pageCode, $network->id);
|
|
|
151 |
if($pageDefault) {
|
|
|
152 |
$page = new Page();
|
|
|
153 |
$page->network_id = $currentNetwork->id;
|
|
|
154 |
$page->code = $pageDefault->code;
|
|
|
155 |
$page->content = $pageDefault->content;
|
|
|
156 |
$page->fixed = $pageDefault->fixed;
|
|
|
157 |
$page->page_default_id = $pageDefault->id;
|
|
|
158 |
$page->title = $pageDefault->title;
|
|
|
159 |
$page->status = $pageDefault->status;
|
|
|
160 |
$page->type = $pageDefault->type;
|
|
|
161 |
$page->url = $pageDefault->url;
|
|
|
162 |
|
|
|
163 |
$pageMapper->insert($page);
|
|
|
164 |
}
|
|
|
165 |
|
|
|
166 |
}
|
|
|
167 |
|
| 2466 |
stevensc |
168 |
|
| 1 |
www |
169 |
$this->layout()->setTemplate('layout/layout.phtml');
|
|
|
170 |
$viewModel = new ViewModel();
|
|
|
171 |
$viewModel->setTemplate('leaders-linked/home/cookies.phtml');
|
|
|
172 |
$viewModel->setVariable('page', $page);
|
| 2466 |
stevensc |
173 |
return $viewModel;
|
| 1 |
www |
174 |
}
|
| 2466 |
stevensc |
175 |
|
| 1 |
www |
176 |
public function professionalismPolicyAction()
|
|
|
177 |
{
|
| 3674 |
efrain |
178 |
$pageCode = Page::PAGE_CODE_PROFESSIONALISM_POLICY;
|
|
|
179 |
|
|
|
180 |
$currentNetworkPlugin = $this->plugin('currentNetworkPlugin');
|
|
|
181 |
$currentNetwork = $currentNetworkPlugin->getNetwork();
|
|
|
182 |
|
| 1 |
www |
183 |
$pageMapper = PageMapper::getInstance($this->adapter);
|
| 3674 |
efrain |
184 |
$page = $pageMapper->fetchOneByCodeAndNetworkId($pageCode, $currentNetwork->id);
|
|
|
185 |
|
|
|
186 |
if(!$page) {
|
|
|
187 |
$networkMapper = NetworkMapper::getInstance($this->adapter);
|
|
|
188 |
$network = $networkMapper->fetchOneByDefault();
|
|
|
189 |
|
|
|
190 |
$pageDefault = $pageMapper->fetchOneByCodeAndNetworkId($pageCode, $network->id);
|
|
|
191 |
if($pageDefault) {
|
|
|
192 |
$page = new Page();
|
|
|
193 |
$page->network_id = $currentNetwork->id;
|
|
|
194 |
$page->code = $pageDefault->code;
|
|
|
195 |
$page->content = $pageDefault->content;
|
|
|
196 |
$page->fixed = $pageDefault->fixed;
|
|
|
197 |
$page->page_default_id = $pageDefault->id;
|
|
|
198 |
$page->title = $pageDefault->title;
|
|
|
199 |
$page->status = $pageDefault->status;
|
|
|
200 |
$page->type = $pageDefault->type;
|
|
|
201 |
$page->url = $pageDefault->url;
|
|
|
202 |
|
|
|
203 |
$pageMapper->insert($page);
|
|
|
204 |
}
|
|
|
205 |
|
|
|
206 |
}
|
| 2466 |
stevensc |
207 |
|
| 3674 |
efrain |
208 |
|
| 1 |
www |
209 |
$this->layout()->setTemplate('layout/layout.phtml');
|
|
|
210 |
$viewModel = new ViewModel();
|
|
|
211 |
$viewModel->setTemplate('leaders-linked/home/professionalism-policy');
|
|
|
212 |
$viewModel->setVariable('page', $page);
|
| 2466 |
stevensc |
213 |
return $viewModel;
|
| 1 |
www |
214 |
}
|
| 2466 |
stevensc |
215 |
|
|
|
216 |
|
| 1 |
www |
217 |
public function termsAndConditionsAction()
|
|
|
218 |
{
|
| 3674 |
efrain |
219 |
$pageCode = Page::PAGE_CODE_TERMS_AND_CONDITIONS;
|
|
|
220 |
|
|
|
221 |
$currentNetworkPlugin = $this->plugin('currentNetworkPlugin');
|
|
|
222 |
$currentNetwork = $currentNetworkPlugin->getNetwork();
|
|
|
223 |
|
| 1 |
www |
224 |
$pageMapper = PageMapper::getInstance($this->adapter);
|
| 3674 |
efrain |
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 |
}
|
| 2466 |
stevensc |
248 |
|
| 1 |
www |
249 |
$this->layout()->setTemplate('layout/layout.phtml');
|
|
|
250 |
$viewModel = new ViewModel();
|
|
|
251 |
$viewModel->setTemplate('leaders-linked/home/terms-and-conditions.phtml');
|
|
|
252 |
$viewModel->setVariable('page', $page);
|
| 2466 |
stevensc |
253 |
return $viewModel;
|
| 1 |
www |
254 |
}
|
| 2466 |
stevensc |
255 |
|
| 1 |
www |
256 |
public function checkSessionAction()
|
|
|
257 |
{
|
|
|
258 |
|
|
|
259 |
$request = $this->getRequest();
|
| 2466 |
stevensc |
260 |
if ($request->isGet()) {
|
|
|
261 |
|
| 1 |
www |
262 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
| 2466 |
stevensc |
263 |
if (!$currentUserPlugin->hasIdentity()) {
|
| 3768 |
efrain |
264 |
//$flashMessenger = $this->plugin('FlashMessenger');
|
|
|
265 |
//$flashMessenger->addErrorMessage('ERROR_SESSION_NOT_FOUND');
|
| 2466 |
stevensc |
266 |
|
| 1 |
www |
267 |
$response = [
|
|
|
268 |
'success' => false,
|
|
|
269 |
'data' => [
|
| 3768 |
efrain |
270 |
'message' => '', //ERROR_SESSION_NOT_FOUND',
|
| 1 |
www |
271 |
'url' => $this->url()->fromRoute('signout')
|
|
|
272 |
]
|
|
|
273 |
];
|
| 2466 |
stevensc |
274 |
|
| 1 |
www |
275 |
return new JsonModel($response);
|
|
|
276 |
}
|
| 2466 |
stevensc |
277 |
|
| 1 |
www |
278 |
$currentUser = $currentUserPlugin->getUser();
|
| 2466 |
stevensc |
279 |
|
|
|
280 |
|
|
|
281 |
if ($currentUser->last_activity_on) {
|
| 1 |
www |
282 |
$last_activity_on = strtotime($currentUser->last_activity_on);
|
|
|
283 |
} else {
|
|
|
284 |
$last_activity_on = strtotime('-1 day');
|
|
|
285 |
}
|
|
|
286 |
|
|
|
287 |
$expiry_time = $last_activity_on + $this->config['leaderslinked.security.last_activity_expired'];
|
|
|
288 |
if (time() > $expiry_time) {
|
| 2466 |
stevensc |
289 |
//$flashMessenger = $this->plugin('FlashMessenger');
|
|
|
290 |
//$flashMessenger->addErrorMessage('ERROR_SESSION_EXPIRED');
|
| 1 |
www |
291 |
|
|
|
292 |
$response = [
|
|
|
293 |
'success' => false,
|
|
|
294 |
'data' => [
|
|
|
295 |
'message' => 'ERROR_SESSION_EXPIRED',
|
|
|
296 |
'url' => $this->url()->fromRoute('signout')
|
|
|
297 |
]
|
|
|
298 |
];
|
|
|
299 |
} else {
|
|
|
300 |
$notificationMapper = NotificationMapper::getInstance($this->adapter);
|
|
|
301 |
$total_notifications = $notificationMapper->fetchUnreadNotificationsCount($currentUser->id);
|
| 2466 |
stevensc |
302 |
|
|
|
303 |
$messageMapper = MessageMapper::getInstance($this->adapter);
|
| 1 |
www |
304 |
$total_messages = $messageMapper->fetchCountUnreadMessagesReceiverId($currentUser->id);
|
|
|
305 |
$response = [
|
|
|
306 |
'success' => true,
|
|
|
307 |
'data' => [
|
|
|
308 |
'total_notifications' => $total_notifications,
|
|
|
309 |
'total_messages' => $total_messages
|
|
|
310 |
]
|
|
|
311 |
];
|
|
|
312 |
}
|
|
|
313 |
} else {
|
|
|
314 |
$response = [
|
|
|
315 |
'success' => false,
|
|
|
316 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
|
|
317 |
];
|
|
|
318 |
}
|
| 2466 |
stevensc |
319 |
|
| 1 |
www |
320 |
return new JsonModel($response);
|
|
|
321 |
}
|
| 2466 |
stevensc |
322 |
|
| 3262 |
efrain |
323 |
|
| 1 |
www |
324 |
public function postAction()
|
|
|
325 |
{
|
| 3364 |
efrain |
326 |
$request = $this->getRequest();
|
|
|
327 |
if ($request->isGet()) {
|
|
|
328 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
329 |
$currentUser = $currentUserPlugin->getUser();
|
|
|
330 |
|
|
|
331 |
|
|
|
332 |
$id = $this->params()->fromRoute('id');
|
|
|
333 |
|
|
|
334 |
$postMapper = PostMapper::getInstance($this->adapter);
|
|
|
335 |
$post = $postMapper->fetchOneByUuid($id);
|
|
|
336 |
|
|
|
337 |
if (!$post || $post->status != Post::STATUS_ACTIVE) {
|
|
|
338 |
$flashMessenger = $this->plugin('FlashMessenger');
|
|
|
339 |
|
|
|
340 |
if (!$id) {
|
|
|
341 |
$flashMessenger->addErrorMessage('ERROR_POST_NOT_AVAILABLE');
|
|
|
342 |
return $this->redirect()->toRoute('dashboard');
|
|
|
343 |
}
|
| 1 |
www |
344 |
}
|
| 3364 |
efrain |
345 |
|
|
|
346 |
|
| 4778 |
efrain |
347 |
|
| 3364 |
efrain |
348 |
$timestamp = time();
|
|
|
349 |
|
|
|
350 |
list($usec, $sec) = explode(' ', microtime());
|
|
|
351 |
$seed = intval($sec + ((float) $usec * 100000));
|
|
|
352 |
mt_srand($seed, MT_RAND_MT19937);
|
|
|
353 |
$rand = mt_rand();
|
|
|
354 |
|
|
|
355 |
|
| 2466 |
stevensc |
356 |
|
| 3366 |
efrain |
357 |
$password = md5('user-' . $currentUser->uuid . '-post-' . $post->uuid . '-timestamp-' . $timestamp . '-rand-' . $rand . '-share-key-' . $currentUser->share_key) ;
|
| 3298 |
efrain |
358 |
|
| 3364 |
efrain |
359 |
|
| 3380 |
efrain |
360 |
$share_params = [
|
| 3379 |
efrain |
361 |
'type' => 'post',
|
|
|
362 |
'code' => $post->uuid,
|
|
|
363 |
'user' => $currentUser->uuid,
|
|
|
364 |
'timestamp' => $timestamp,
|
|
|
365 |
'rand' => $rand,
|
|
|
366 |
'password' => $password,
|
|
|
367 |
];
|
| 3364 |
efrain |
368 |
|
| 3379 |
efrain |
369 |
|
| 4778 |
efrain |
370 |
$share_increment_external_counter_url = $this->url()->fromRoute('share/increment-external-counter',$share_params , ['force_canonical' => true]);
|
|
|
371 |
|
| 3775 |
efrain |
372 |
|
|
|
373 |
$share_external_url = $this->url()->fromRoute('shorter/generate', ['code' => $post->uuid, 'type' => 'post' ] , ['force_canonical' => true]);
|
|
|
374 |
|
|
|
375 |
|
|
|
376 |
|
| 3364 |
efrain |
377 |
$this->layout()->setTemplate('layout/layout.phtml');
|
|
|
378 |
$viewModel = new ViewModel();
|
|
|
379 |
$viewModel->setTemplate('leaders-linked/home/post.phtml');
|
|
|
380 |
$viewModel->setVariables([
|
|
|
381 |
'post' => $post,
|
|
|
382 |
'id' => $post->id,
|
|
|
383 |
'uuid' => $post->uuid,
|
|
|
384 |
'title' => $post->title,
|
|
|
385 |
'description' => $post->description,
|
|
|
386 |
'url' => $post->url,
|
|
|
387 |
'date' => $post->date,
|
|
|
388 |
'status' => $post->status,
|
|
|
389 |
'image' => $post->image,
|
|
|
390 |
'file' => $post->file,
|
|
|
391 |
'added_on' => $post->added_on,
|
| 3379 |
efrain |
392 |
'share_external_url' => $share_external_url,
|
| 4778 |
efrain |
393 |
'total_share_external' => $post->total_external_shared,
|
|
|
394 |
'share_increment_external_counter_url' => $share_increment_external_counter_url,
|
| 3364 |
efrain |
395 |
|
|
|
396 |
]);
|
|
|
397 |
return $viewModel;
|
|
|
398 |
|
|
|
399 |
} else {
|
|
|
400 |
$response = [
|
|
|
401 |
'success' => false,
|
|
|
402 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
|
|
403 |
];
|
|
|
404 |
|
|
|
405 |
return new JsonModel($response);
|
|
|
406 |
}
|
| 1 |
www |
407 |
}
|
| 3298 |
efrain |
408 |
|
| 4778 |
efrain |
409 |
|
|
|
410 |
public function incTotalExternalSharedAction()
|
|
|
411 |
{
|
|
|
412 |
|
|
|
413 |
$request = $this->getRequest();
|
|
|
414 |
if ($request->isPost()) {
|
|
|
415 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
416 |
$currentUser = $currentUserPlugin->getUser();
|
|
|
417 |
|
|
|
418 |
$currentNetworkPlugin = $this->plugin('currentNetworkPlugin');
|
|
|
419 |
$currentNetwork = $currentNetworkPlugin->getNetwork();
|
|
|
420 |
|
|
|
421 |
$code = $this->params()->fromRoute('code');
|
|
|
422 |
$type = $this->params()->fromRoute('type');
|
|
|
423 |
$user = $this->params()->fromRoute('user');
|
|
|
424 |
$timestamp = intval($this->params()->fromRoute('timestamp'), 10);
|
|
|
425 |
$rand = intval($this->params()->fromRoute('rand'), 10);
|
|
|
426 |
$password = $this->params()->fromRoute('password');
|
|
|
427 |
|
|
|
428 |
|
|
|
429 |
|
|
|
430 |
$checkpassword = '';
|
|
|
431 |
|
|
|
432 |
|
|
|
433 |
$userCheck = '';
|
|
|
434 |
if($user && $timestamp > 0 && $rand > 0 && $password) {
|
|
|
435 |
$userMapper = UserMapper::getInstance($this->adapter);
|
|
|
436 |
$userCheck = $userMapper->fetchOneByUuid($user);
|
|
|
437 |
if($userCheck) {
|
|
|
438 |
$checkpassword = md5('user-' . $userCheck->uuid . '-'.$type.'-' . $code . '-timestamp-' . $timestamp . '-rand-' . $rand . '-share-key-' . $userCheck->share_key) ;
|
|
|
439 |
}
|
|
|
440 |
}
|
|
|
441 |
|
|
|
442 |
if(empty($password) || $password != $checkpassword) {
|
|
|
443 |
$data = [
|
|
|
444 |
'success' => false,
|
|
|
445 |
'data' => 'ERROR_UNAUTHORIZED'
|
|
|
446 |
];
|
|
|
447 |
|
|
|
448 |
return new JsonModel($data);
|
|
|
449 |
}
|
|
|
450 |
|
|
|
451 |
|
|
|
452 |
|
|
|
453 |
|
|
|
454 |
|
|
|
455 |
|
|
|
456 |
|
|
|
457 |
|
|
|
458 |
|
|
|
459 |
if($type == 'feed' && $code ) {
|
|
|
460 |
$feedMapper = FeedMapper::getInstance($this->adapter);
|
|
|
461 |
$feed = $feedMapper->fetchOneByUuidAnyStatus($code);
|
|
|
462 |
|
|
|
463 |
|
|
|
464 |
if($feed) {
|
|
|
465 |
|
|
|
466 |
if($feed->network_id != $currentNetwork->id) {
|
|
|
467 |
$data = [
|
|
|
468 |
'success' => false,
|
|
|
469 |
'data' => 'ERROR_UNAUTHORIZED'
|
|
|
470 |
];
|
|
|
471 |
|
|
|
472 |
return new JsonModel($data);
|
|
|
473 |
}
|
|
|
474 |
|
|
|
475 |
if($feedMapper->incTotalExternalShared($feed->id)) {
|
|
|
476 |
$total = $feedMapper->fetchTotalExternalShared($feed->id);
|
|
|
477 |
|
|
|
478 |
$this->logger->info('El usuario : ' . trim($currentUser->first_name . ' ' . $currentUser->last_name) . ' (' . $currentUser->email . ') compartio externamente el feed : ' . $feed->title);
|
|
|
479 |
|
|
|
480 |
$data = [
|
|
|
481 |
'success' => true,
|
|
|
482 |
'data' => $total,
|
|
|
483 |
];
|
|
|
484 |
|
|
|
485 |
return new JsonModel($data);
|
|
|
486 |
|
|
|
487 |
} else {
|
|
|
488 |
$data = [
|
|
|
489 |
'success' => false,
|
|
|
490 |
'data' => $feedMapper->getError()
|
|
|
491 |
];
|
|
|
492 |
|
|
|
493 |
return new JsonModel($data);
|
|
|
494 |
}
|
|
|
495 |
|
|
|
496 |
} else {
|
|
|
497 |
$data = [
|
|
|
498 |
'success' => false,
|
|
|
499 |
'data' => 'ERROR_FEED_NOT_FOUND',
|
|
|
500 |
];
|
|
|
501 |
|
|
|
502 |
return new JsonModel($data);
|
|
|
503 |
|
|
|
504 |
}
|
|
|
505 |
|
|
|
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 |
|
|
|
538 |
} else {
|
|
|
539 |
$data = [
|
|
|
540 |
'success' => false,
|
|
|
541 |
'data' => $postMapper->getError()
|
|
|
542 |
];
|
|
|
543 |
|
|
|
544 |
return new JsonModel($data);
|
|
|
545 |
}
|
|
|
546 |
} else {
|
|
|
547 |
$data = [
|
|
|
548 |
'success' => false,
|
|
|
549 |
'data' => 'ERROR_POST_NOT_FOUND'
|
|
|
550 |
];
|
|
|
551 |
|
|
|
552 |
return new JsonModel($data);
|
|
|
553 |
|
|
|
554 |
|
|
|
555 |
|
|
|
556 |
}
|
|
|
557 |
}
|
|
|
558 |
|
|
|
559 |
|
|
|
560 |
|
|
|
561 |
|
|
|
562 |
} else {
|
|
|
563 |
$response = [
|
|
|
564 |
'success' => false,
|
|
|
565 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
|
|
566 |
];
|
|
|
567 |
|
|
|
568 |
return new JsonModel($response);
|
|
|
569 |
}
|
|
|
570 |
|
|
|
571 |
|
|
|
572 |
}
|
|
|
573 |
|
| 3298 |
efrain |
574 |
public function shareAction()
|
|
|
575 |
{
|
|
|
576 |
$request = $this->getRequest();
|
|
|
577 |
if ($request->isGet()) {
|
|
|
578 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
579 |
$currentUser = $currentUserPlugin->getUser();
|
|
|
580 |
|
| 3364 |
efrain |
581 |
$code = $this->params()->fromRoute('code');
|
|
|
582 |
$type = $this->params()->fromRoute('type');
|
| 3379 |
efrain |
583 |
$user = $this->params()->fromRoute('user');
|
|
|
584 |
$timestamp = intval($this->params()->fromRoute('timestamp'), 10);
|
|
|
585 |
$rand = intval($this->params()->fromRoute('rand'), 10);
|
|
|
586 |
$password = $this->params()->fromRoute('password');
|
| 3377 |
efrain |
587 |
|
| 3379 |
efrain |
588 |
|
|
|
589 |
|
| 3364 |
efrain |
590 |
$checkpassword = '';
|
|
|
591 |
|
| 3383 |
efrain |
592 |
|
| 3364 |
efrain |
593 |
$userCheck = '';
|
|
|
594 |
if($user && $timestamp > 0 && $rand > 0 && $password) {
|
|
|
595 |
$userMapper = UserMapper::getInstance($this->adapter);
|
|
|
596 |
$userCheck = $userMapper->fetchOneByUuid($user);
|
|
|
597 |
if($userCheck) {
|
| 3366 |
efrain |
598 |
$checkpassword = md5('user-' . $userCheck->uuid . '-'.$type.'-' . $code . '-timestamp-' . $timestamp . '-rand-' . $rand . '-share-key-' . $userCheck->share_key) ;
|
| 3364 |
efrain |
599 |
}
|
|
|
600 |
}
|
| 3349 |
efrain |
601 |
|
| 3364 |
efrain |
602 |
if(empty($password) || $password != $checkpassword) {
|
|
|
603 |
$data = [
|
| 3349 |
efrain |
604 |
'success' => false,
|
|
|
605 |
'data' => 'ERROR_UNAUTHORIZED'
|
|
|
606 |
];
|
|
|
607 |
|
| 3364 |
efrain |
608 |
return new JsonModel($data);
|
| 3383 |
efrain |
609 |
}
|
| 3371 |
efrain |
610 |
|
| 4778 |
efrain |
611 |
/*
|
|
|
612 |
$share_params = [
|
|
|
613 |
'type' => $type,
|
|
|
614 |
'code' => $code,
|
|
|
615 |
'user' => $currentUser->uuid,
|
|
|
616 |
'timestamp' => $timestamp,
|
|
|
617 |
'rand' => $rand,
|
|
|
618 |
'password' => $password,
|
|
|
619 |
];
|
| 3364 |
efrain |
620 |
|
| 4778 |
efrain |
621 |
$share_increment_external_counter_url = $this->url()->fromRoute('share/increment-external-counter', $share_params , ['force_canonical' => true]);
|
|
|
622 |
*/
|
| 3364 |
efrain |
623 |
|
|
|
624 |
|
|
|
625 |
|
| 4778 |
efrain |
626 |
|
| 3357 |
efrain |
627 |
|
| 3298 |
efrain |
628 |
|
| 3335 |
efrain |
629 |
|
|
|
630 |
if(strpos(strtolower($_SERVER['REQUEST_SCHEME']), 'https') === false) {
|
| 3355 |
efrain |
631 |
$base_share = 'http://' . $_SERVER['HTTP_HOST'];
|
| 3298 |
efrain |
632 |
} else {
|
| 3355 |
efrain |
633 |
$base_share = 'https://' . $_SERVER['HTTP_HOST'];
|
| 3298 |
efrain |
634 |
}
|
|
|
635 |
|
|
|
636 |
|
| 3374 |
efrain |
637 |
/*
|
| 3372 |
efrain |
638 |
echo '<pre>';
|
|
|
639 |
print_r($_SERVER);
|
|
|
640 |
echo '</pre>';
|
| 3374 |
efrain |
641 |
*/
|
| 3298 |
efrain |
642 |
|
| 3372 |
efrain |
643 |
|
| 3355 |
efrain |
644 |
$share_url = $base_share . $_SERVER['REQUEST_URI'];
|
|
|
645 |
$share_image = $base_share . '/images/ll-logo.png';
|
| 3298 |
efrain |
646 |
$share_title = '';
|
|
|
647 |
$share_description = '';
|
| 3364 |
efrain |
648 |
|
| 3298 |
efrain |
649 |
|
|
|
650 |
if($type == 'feed' && $code ) {
|
|
|
651 |
$feedMapper = FeedMapper::getInstance($this->adapter);
|
| 3731 |
efrain |
652 |
$feed = $feedMapper->fetchOneByUuidAnyStatus($code);
|
| 3298 |
efrain |
653 |
|
| 3731 |
efrain |
654 |
// if($feed && $feed->status == Feed::STATUS_PUBLISHED) {
|
|
|
655 |
|
|
|
656 |
if($feed) {
|
| 3453 |
efrain |
657 |
|
| 3731 |
efrain |
658 |
$share_title = $feed->title ? $feed->title : '';
|
| 3453 |
efrain |
659 |
|
|
|
660 |
if($feed->posted_or_shared == Feed::SHARED) {
|
|
|
661 |
|
|
|
662 |
|
|
|
663 |
$feed = $feedMapper->fetchOneAnyStatus($feed->shared_feed_id);
|
|
|
664 |
if($feed->title) {
|
|
|
665 |
|
|
|
666 |
$share_title = $share_title . ' - ' .$feed->title;
|
|
|
667 |
}
|
|
|
668 |
|
|
|
669 |
|
|
|
670 |
}
|
|
|
671 |
|
|
|
672 |
|
| 3298 |
efrain |
673 |
$share_description = $feed->description;
|
|
|
674 |
|
|
|
675 |
$image_name = '';
|
|
|
676 |
if($feed->file_type == Feed::FILE_TYPE_IMAGE) {
|
|
|
677 |
|
|
|
678 |
$image_name = $feed->file_name;
|
|
|
679 |
|
|
|
680 |
} else if($feed->file_image_preview) {
|
|
|
681 |
$image_name = $feed->file_image_preview;
|
|
|
682 |
}
|
|
|
683 |
|
|
|
684 |
|
|
|
685 |
|
|
|
686 |
if( $image_name ) {
|
|
|
687 |
|
|
|
688 |
$source = $this->config['leaderslinked.fullpath.feed'] . $feed->uuid . DIRECTORY_SEPARATOR . $image_name;
|
|
|
689 |
|
|
|
690 |
|
|
|
691 |
$target_path = 'public' . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . 'feed'. DIRECTORY_SEPARATOR . $feed->uuid;
|
|
|
692 |
|
|
|
693 |
if(!file_exists($target_path)) {
|
|
|
694 |
mkdir($target_path, 0755, true);
|
|
|
695 |
}
|
|
|
696 |
|
|
|
697 |
|
|
|
698 |
|
|
|
699 |
$target = $target_path . DIRECTORY_SEPARATOR . $image_name;
|
|
|
700 |
|
|
|
701 |
|
|
|
702 |
|
|
|
703 |
if(!file_exists($target)) {
|
|
|
704 |
|
|
|
705 |
copy($source, $target);
|
| 3355 |
efrain |
706 |
$share_image = $base_share . '/images/feed/' . $feed->uuid . '/' . $image_name;
|
| 3298 |
efrain |
707 |
|
|
|
708 |
} else {
|
| 3355 |
efrain |
709 |
$share_image = $base_share . '/images/feed/' . $feed->uuid . '/' . $image_name;
|
| 3298 |
efrain |
710 |
|
|
|
711 |
}
|
|
|
712 |
|
|
|
713 |
|
|
|
714 |
|
|
|
715 |
|
|
|
716 |
}
|
|
|
717 |
|
| 3349 |
efrain |
718 |
} else {
|
|
|
719 |
|
|
|
720 |
if($currentUserPlugin->hasIdentity()) {
|
|
|
721 |
$this->layout()->setTemplate('layout/layout.phtml');
|
|
|
722 |
} else {
|
|
|
723 |
$this->layout()->setTemplate('layout/share.phtml');
|
|
|
724 |
}
|
|
|
725 |
$viewModel = new ViewModel();
|
|
|
726 |
$viewModel->setTemplate('leaders-linked/error/404.phtml');
|
|
|
727 |
return $viewModel;
|
| 3298 |
efrain |
728 |
}
|
|
|
729 |
|
|
|
730 |
|
|
|
731 |
} else if ($type == 'post' && $code) {
|
|
|
732 |
|
|
|
733 |
$postMapper = PostMapper::getInstance($this->adapter);
|
|
|
734 |
$post = $postMapper->fetchOneByUuid($code);
|
|
|
735 |
|
|
|
736 |
if($post && $post->status == Post::STATUS_ACTIVE) {
|
|
|
737 |
$share_title = $post->title;
|
|
|
738 |
$share_description = $post->description;
|
|
|
739 |
|
|
|
740 |
|
|
|
741 |
if($post->image) {
|
|
|
742 |
$source = $this->config['leaderslinked.fullpath.post'] . $post->uuid . DIRECTORY_SEPARATOR . $post->image;
|
|
|
743 |
|
|
|
744 |
|
|
|
745 |
$target_path = 'public' . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . 'post'. DIRECTORY_SEPARATOR . $post->uuid;
|
|
|
746 |
|
|
|
747 |
if(!file_exists($target_path)) {
|
|
|
748 |
mkdir($target_path, 0755, true);
|
|
|
749 |
}
|
|
|
750 |
|
|
|
751 |
|
|
|
752 |
|
|
|
753 |
$target = $target_path . DIRECTORY_SEPARATOR . $post->image;
|
|
|
754 |
|
|
|
755 |
|
|
|
756 |
|
|
|
757 |
if(!file_exists($target)) {
|
|
|
758 |
|
|
|
759 |
copy($source, $target);
|
| 3355 |
efrain |
760 |
$share_image = $base_share . '/images/post/' . $post->uuid . '/' . $post->image;
|
| 3298 |
efrain |
761 |
|
|
|
762 |
} else {
|
| 3355 |
efrain |
763 |
$share_image = $base_share . '/images/post/' . $post->uuid . '/' . $post->image;
|
| 3298 |
efrain |
764 |
|
|
|
765 |
}
|
|
|
766 |
}
|
| 3349 |
efrain |
767 |
} else {
|
|
|
768 |
|
|
|
769 |
if($currentUserPlugin->hasIdentity()) {
|
|
|
770 |
$this->layout()->setTemplate('layout/layout.phtml');
|
|
|
771 |
} else {
|
|
|
772 |
$this->layout()->setTemplate('layout/share.phtml');
|
|
|
773 |
}
|
|
|
774 |
$viewModel = new ViewModel();
|
|
|
775 |
$viewModel->setTemplate('leaders-linked/error/404.phtml');
|
|
|
776 |
return $viewModel;
|
| 3298 |
efrain |
777 |
}
|
|
|
778 |
}
|
| 3374 |
efrain |
779 |
|
| 3382 |
efrain |
780 |
/*
|
| 3372 |
efrain |
781 |
echo '<pre>';
|
| 3371 |
efrain |
782 |
print_r([ 'share_image' => $share_image,
|
|
|
783 |
'share_url' => $share_url,
|
|
|
784 |
'share_title' => strip_tags($share_title),
|
| 3372 |
efrain |
785 |
'share_description' => strip_tags($share_description)]); echo '</pre>';
|
|
|
786 |
exit;
|
| 3382 |
efrain |
787 |
*/
|
| 3298 |
efrain |
788 |
|
| 3349 |
efrain |
789 |
if($currentUserPlugin->hasIdentity()) {
|
| 3364 |
efrain |
790 |
$currentUser = $currentUserPlugin->getUser();
|
|
|
791 |
if($userCheck && $userCheck->status == User::STATUS_ACTIVE && $userCheck->id != $currentUser->id ) {
|
|
|
792 |
|
|
|
793 |
$connectionMapper = ConnectionMapper::getInstance($this->adapter);
|
|
|
794 |
$connection = $connectionMapper->fetchOneByUserId1AndUserId2($currentUser->id, $userCheck->id);
|
|
|
795 |
|
|
|
796 |
if($connection) {
|
|
|
797 |
|
|
|
798 |
if($connection->status != Connection::STATUS_ACCEPTED) {
|
|
|
799 |
$connectionMapper->approve($connection);
|
|
|
800 |
}
|
|
|
801 |
|
|
|
802 |
} else {
|
|
|
803 |
$connection = new Connection();
|
|
|
804 |
$connection->request_from = $currentUser->id;
|
|
|
805 |
$connection->request_to = $userCheck->id;
|
|
|
806 |
$connection->status = Connection::STATUS_ACCEPTED;
|
|
|
807 |
|
|
|
808 |
$connectionMapper->insert($connection);
|
|
|
809 |
}
|
|
|
810 |
}
|
|
|
811 |
|
|
|
812 |
|
| 3383 |
efrain |
813 |
|
| 3364 |
efrain |
814 |
|
| 3349 |
efrain |
815 |
$this->layout()->setTemplate('layout/layout.phtml');
|
|
|
816 |
} else {
|
| 3383 |
efrain |
817 |
$this->cache->addItem('user_share_invitation', $user);
|
| 3364 |
efrain |
818 |
|
| 3349 |
efrain |
819 |
$this->layout()->setTemplate('layout/share.phtml');
|
|
|
820 |
}
|
| 3298 |
efrain |
821 |
$viewModel = new ViewModel();
|
|
|
822 |
$viewModel->setTemplate('leaders-linked/home/share.phtml');
|
|
|
823 |
$viewModel->setVariables([
|
| 3352 |
efrain |
824 |
'share_image' => $share_image,
|
|
|
825 |
'share_url' => $share_url,
|
| 3356 |
efrain |
826 |
'share_title' => strip_tags($share_title),
|
|
|
827 |
'share_description' => strip_tags($share_description),
|
| 4778 |
efrain |
828 |
// 'share_increment_external_counter_url' => $share_increment_external_counter_url,
|
| 3349 |
efrain |
829 |
|
| 3298 |
efrain |
830 |
]);
|
|
|
831 |
|
|
|
832 |
|
|
|
833 |
return $viewModel;
|
|
|
834 |
|
|
|
835 |
|
|
|
836 |
} else {
|
|
|
837 |
$response = [
|
|
|
838 |
'success' => false,
|
|
|
839 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
|
|
840 |
];
|
|
|
841 |
|
|
|
842 |
return new JsonModel($response);
|
|
|
843 |
}
|
|
|
844 |
|
|
|
845 |
|
|
|
846 |
}
|
|
|
847 |
|
| 3364 |
efrain |
848 |
|
| 1 |
www |
849 |
}
|