1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Apps\Controller\Front; |
4
|
|
|
|
5
|
|
|
use Apps\ActiveRecord\Profile as ProfileRecords; |
6
|
|
|
use Apps\ActiveRecord\UserLog; |
7
|
|
|
use Apps\ActiveRecord\UserNotification; |
8
|
|
|
use Apps\Model\Front\Profile\FormSettings; |
9
|
|
|
use Apps\Model\Front\Sitemap\EntityBuildMap; |
10
|
|
|
use Extend\Core\Arch\FrontAppController; |
11
|
|
|
use Ffcms\Core\App; |
12
|
|
|
use Ffcms\Core\Exception\ForbiddenException; |
13
|
|
|
use Ffcms\Core\Exception\SyntaxException; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Class Profile. User profiles application front controller |
17
|
|
|
* @package Apps\Controller\Front |
18
|
|
|
*/ |
19
|
|
|
class Profile extends FrontAppController |
20
|
|
|
{ |
21
|
|
|
const BLOCK_PER_PAGE = 10; |
22
|
|
|
const EVENT_CHANGE_PASSWORD = 'profile.changepassword.success'; |
23
|
|
|
const NOTIFY_PER_PAGE = 25; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Fatty action like actionIndex(), actionShow() are located in standalone traits. |
27
|
|
|
* This feature allow provide better read&write accessibility |
28
|
|
|
*/ |
29
|
|
|
|
30
|
|
|
use Profile\ActionIndex { |
31
|
|
|
index as actionIndex; |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
use Profile\ActionShow { |
35
|
|
|
show as actionShow; |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
use Profile\ActionFeed { |
39
|
|
|
feed as actionFeed; |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
use Profile\ActionWallDelete { |
43
|
|
|
wallDelete as actionWalldelete; |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
use Profile\ActionAvatar { |
47
|
|
|
avatar as actionAvatar; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
use Profile\ActionNotifications { |
51
|
|
|
notifications as actionNotifications; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
use Profile\ActionIgnore { |
55
|
|
|
ignore as actionIgnore; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
use Profile\ActionSearch { |
59
|
|
|
search as actionSearch; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
use Profile\ActionUnblock { |
63
|
|
|
unblock as actionUnblock; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
use Profile\ActionPassword { |
67
|
|
|
password as actionPassword; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* Show user messages (based on ajax, all in template) |
73
|
|
|
* @return string |
74
|
|
|
* @throws \Ffcms\Core\Exception\SyntaxException |
75
|
|
|
* @throws ForbiddenException |
76
|
|
|
*/ |
77
|
|
|
public function actionMessages() |
78
|
|
|
{ |
79
|
|
|
if (!App::$User->isAuth()) { |
80
|
|
|
throw new ForbiddenException(); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
return $this->view->render('messages'); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* User profile settings |
88
|
|
|
* @return string |
89
|
|
|
* @throws \Ffcms\Core\Exception\SyntaxException |
90
|
|
|
* @throws ForbiddenException |
91
|
|
|
*/ |
92
|
|
|
public function actionSettings() |
93
|
|
|
{ |
94
|
|
|
// check if auth |
95
|
|
|
if (!App::$User->isAuth()) { |
96
|
|
|
throw new ForbiddenException(); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
// get user object |
100
|
|
|
$user = App::$User->identity(); |
101
|
|
|
// create model and pass user object |
102
|
|
|
$model = new FormSettings($user); |
103
|
|
|
|
104
|
|
|
// check if form is submited |
105
|
|
|
if ($model->send() && $model->validate()) { |
106
|
|
|
$model->save(); |
107
|
|
|
App::$Session->getFlashBag()->add('success', __('Profile data are successful updated')); |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
// render view |
111
|
|
|
return $this->view->render('settings', [ |
112
|
|
|
'model' => $model |
113
|
|
|
]); |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
/** |
117
|
|
|
* Show user logs |
118
|
|
|
* @return string |
119
|
|
|
* @throws \Ffcms\Core\Exception\SyntaxException |
120
|
|
|
* @throws ForbiddenException |
121
|
|
|
*/ |
122
|
|
|
public function actionLog() |
123
|
|
|
{ |
124
|
|
|
// check if user is authorized |
125
|
|
|
if (!App::$User->isAuth()) { |
126
|
|
|
throw new ForbiddenException(); |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
// get log records |
130
|
|
|
$records = UserLog::where('user_id', App::$User->identity()->getId()); |
131
|
|
|
if ($records->count() > 0) { |
132
|
|
|
$records = $records->orderBy('id', 'DESC'); |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
// render output view |
136
|
|
|
return $this->view->render('log', [ |
137
|
|
|
'records' => $records |
138
|
|
|
]); |
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
/** |
142
|
|
|
* Cron schedule - build user profiles sitemap |
143
|
|
|
*/ |
144
|
|
|
public static function buildSitemapSchedule() |
145
|
|
|
{ |
146
|
|
|
// get not empty user profiles |
147
|
|
|
$profiles = ProfileRecords::whereNotNull('nick'); |
148
|
|
|
if ($profiles->count() < 1) { |
149
|
|
|
return; |
150
|
|
|
} |
151
|
|
|
|
152
|
|
|
// get languages if multilanguage enabled |
153
|
|
|
$langs = null; |
154
|
|
|
if (App::$Properties->get('multiLanguage')) { |
155
|
|
|
$langs = App::$Properties->get('languages'); |
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
// build sitemap from content items via business model |
159
|
|
|
$sitemap = new EntityBuildMap($langs); |
160
|
|
|
foreach ($profiles->get() as $user) { |
161
|
|
|
$sitemap->add('profile/show/' . $user->user_id, $user->updated_at, 'weekly', 0.2); |
162
|
|
|
} |
163
|
|
|
|
164
|
|
|
try { |
165
|
|
|
$sitemap->save('profile'); |
166
|
|
|
} catch (SyntaxException $e) { |
|
|
|
|
167
|
|
|
} |
168
|
|
|
} |
169
|
|
|
|
170
|
|
|
/** |
171
|
|
|
* Cleanup tables as scheduled action |
172
|
|
|
*/ |
173
|
|
|
public static function cleanupTablesSchedule() |
174
|
|
|
{ |
175
|
|
|
// calculate date (now - 1week) for sql query |
176
|
|
|
$date = (new \DateTime('now'))->modify('-1 week')->format('Y-m-d'); |
177
|
|
|
try { |
178
|
|
|
UserNotification::where('created_at', '<=', $date)->delete(); |
179
|
|
|
UserLog::where('created_at', '<=', $date)->delete(); |
180
|
|
|
} catch (\Exception $e) { |
|
|
|
|
181
|
|
|
} |
182
|
|
|
} |
183
|
|
|
} |
184
|
|
|
|