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