1 | <?php |
||
2 | |||
3 | use Ffcms\Core\Helper\Type\Any; |
||
4 | use Ffcms\Templex\Url\Url; |
||
0 ignored issues
–
show
|
|||
5 | |||
6 | /** @var \Ffcms\Templex\Template\Template $this */ |
||
7 | |||
8 | $this->layout('_layouts/default', [ |
||
9 | 'title' => __('My dialogs'), |
||
10 | 'breadcrumbs' => [ |
||
11 | Url::to('main/index') => __('Home'), |
||
12 | Url::to('profile/show', [\App::$User->identity()->id]) => __('Profile'), |
||
13 | __('My messages') |
||
14 | ], |
||
15 | 'fullgrid' => true |
||
16 | ]); |
||
17 | |||
18 | ?> |
||
19 | |||
20 | <?php $this->start('body') ?> |
||
21 | <div class="row" id="msg-layout"> |
||
22 | <div class="col-sm-4 d-none d-sm-block"> |
||
23 | <div class="well-light"> |
||
24 | <div id="message-user-list" class="pt-1"></div> |
||
25 | <div class="row"> |
||
26 | <div class="col-md-12"> |
||
27 | <a href="#" class="btn btn-primary btn-block btn-sm" id="show-more-dialogs"><?= __('Show more') ?></a> |
||
28 | </div> |
||
29 | </div> |
||
30 | </div> |
||
31 | </div> |
||
32 | <div class="col-sm-8 col-12 m-0 p-0"> |
||
33 | <!-- user info --> |
||
34 | <div class="row"> |
||
35 | <div class="col-md-12"> |
||
36 | <div class="well-light"> |
||
37 | <div class="row"> |
||
38 | <div class="col-md-12"> |
||
39 | <div id="dialog-user-streak"> |
||
40 | <div class="float-right"> |
||
41 | <img src="<?= \App::$Alias->scriptUrl ?>/upload/user/avatar/small/default.jpg" class="float-right img-fluid img-circle" style="max-height: 50px;" /> |
||
42 | <div class="float-right" style="padding-top: 12px;"> |
||
43 | <span class="media-person-uname"><?= __('No data') ?></span> |
||
44 | </div> |
||
45 | </div> |
||
46 | </div> |
||
47 | </div> |
||
48 | </div> |
||
49 | </div> |
||
50 | </div> |
||
51 | </div> |
||
52 | <div class="message-scroll-body d-none"> |
||
53 | <div class="col-md-12"> |
||
54 | <p class="text-center"><a href="javascript:void(0);" id="message-load-before"><?= __('Load previous') ?></a></p> |
||
55 | </div> |
||
56 | <div id="messages-before"></div> |
||
57 | <div id="messages-now"></div> |
||
58 | <div id="messages-after"></div> |
||
59 | <div id="messages-blocked-user" class="d-none alert alert-danger"><?= __('This user are in your black list or you are in blacklist!') ?></div> |
||
60 | <div id="message-end-position"></div> |
||
61 | </div> |
||
62 | <div class="message-add-container d-none" style="padding-top: 10px;"> |
||
63 | <textarea class="form-control" id="msg-text" maxlength="1000"></textarea> |
||
64 | <a href="javascript:void(0);" class="btn btn-primary" id="send-new-message"><?= __('Send message') ?></a> |
||
65 | </div> |
||
66 | </div> |
||
67 | </div> |
||
68 | |||
69 | <!-- dynamic dom templates --> |
||
70 | <!-- 1. Userlist --> |
||
71 | <div class="d-none" id="msg-user"> |
||
72 | <div id="msg-user-background"> |
||
73 | <div class="row"> |
||
74 | <div class="col-md-12"> |
||
75 | <img id="msg-user-avatar" src="<?= \App::$Alias->scriptUrl ?>/upload/user/avatar/small/default.jpg" class="pull-left img-fluid img-circle" style="max-height: 50px;padding-right: 5px;" /> |
||
76 | <div style="padding-top: 12px;"> |
||
77 | <span class="media-person-uname" id="msg-user-name"><?= __('Unknown') ?></span> |
||
78 | <span class="d-none" id="msg-user-isnew"><i class="glyphicon glyphicon-envelope"></i></span> |
||
79 | </div> |
||
80 | </div> |
||
81 | </div> |
||
82 | </div> |
||
83 | </div> |
||
84 | <!-- 2. Current dialog title --> |
||
85 | <div class="d-none" id="dialog-title"> |
||
86 | <img id="msg-user-avatar" src="<?= \App::$Alias->scriptUrl ?>/upload/user/avatar/small/default.jpg" class="float-right img-fluid img-circle" style="max-height: 50px;" /> |
||
87 | <div class="float-right" style="padding-top: 12px;padding-right: 5px;"> |
||
88 | <a href="#" target="_blank" id="msg-user-link"><span class="media-person-uname" id="msg-user-name">unknown</span></a> |
||
89 | </div> |
||
90 | </div> |
||
91 | |||
92 | <!-- 3.1. Messages between users - owner message --> |
||
93 | <div class="d-none" id="msg-owner"> |
||
94 | <div class="row pt-1"> |
||
95 | <div class="col-md-6 col-xs-12"> |
||
96 | <div class="message-text"> |
||
97 | <div> |
||
98 | <small id="msg-user-nick"><?= __('You') ?></small> |
||
99 | <small class="float-right text-secondary" id="msg-date">01.01.1970</small> |
||
100 | </div> |
||
101 | <div id="msg-text" style="word-break: break-all">text</div> |
||
102 | </div> |
||
103 | </div> |
||
104 | </div> |
||
105 | </div> |
||
106 | <!-- 3.2. Messages between users - oponent message --> |
||
107 | <div class="d-none" id="msg-remote"> |
||
108 | <div class="row pt-1"> |
||
109 | <div class="offset-md-6 col-md-6 col-xs-12"> |
||
110 | <div class="message-text message-text-remote"> |
||
111 | <div> |
||
112 | <small id="msg-user-nick">target</small> |
||
113 | <small class="float-right text-secondary" id="msg-date">01.01.1970</small> |
||
114 | </div> |
||
115 | <div id="msg-text" style="word-break: break-all">text</div> |
||
116 | </div> |
||
117 | </div> |
||
118 | </div> |
||
119 | </div> |
||
120 | |||
121 | <script> |
||
122 | /** Css class for default, selected and blocked user display in list */ |
||
123 | var cssUserList = { |
||
124 | 'default': 'media-person', |
||
125 | 'active': 'media-person-selected', |
||
126 | 'blocked': 'media-person-blocked' |
||
127 | }; |
||
128 | var active_dialog_id = 0; |
||
129 | var user_object = []; |
||
130 | var dialog_offset = 0; |
||
131 | var new_dialog = 0; |
||
132 | var profile_link = '<?= Url::to('profile/show') ?>'; |
||
133 | var last_msg = []; |
||
134 | var first_msg = []; |
||
135 | $(document).ready(function(){ |
||
136 | $(function(){ |
||
137 | var userListDom = $('#msg-user').clone(); |
||
138 | var dialogPanelDom = $('#dialog-title').clone(); |
||
139 | var myMsgDom = $('#msg-owner').clone(); |
||
140 | var remMsgDom = $('#msg-remote').clone(); |
||
141 | // load users with active dialog |
||
142 | loadDialogUsers = function() { |
||
143 | $.getJSON(script_url+'/api/profile/listmessagedialog/'+dialog_offset+'/'+new_dialog+'/?lang='+script_lang, function(response){ |
||
144 | if (response.status !== 1) { |
||
145 | $('#show-more-dialogs').addClass('d-none'); |
||
146 | return false; |
||
147 | } |
||
148 | if (response.data.length < 1) { |
||
149 | $('#msg-layout').after('<p><?= __('You have no active dialogs. Find users to message with: %u%', ['u' => Url::a(['profile/index', ['all']], __('user list'))]) ?></p>'); |
||
150 | $('#msg-layout').remove(); |
||
151 | return false; |
||
152 | } |
||
153 | var userMap = ''; |
||
154 | $('.media-person').removeClass(cssUserList.active); |
||
155 | $.each(response.data, function(key, row){ |
||
156 | var itemClass = cssUserList.default; |
||
157 | if (row.user_id == active_dialog_id) { |
||
158 | itemClass += ' '+cssUserList.active; |
||
159 | } |
||
160 | if (row.user_block == true) { |
||
161 | itemClass += ' '+cssUserList.blocked; |
||
162 | } |
||
163 | // clone user list dom template |
||
164 | var itemDom = userListDom.clone(); |
||
165 | // set id attr |
||
166 | itemDom.find('#msg-user-background').attr('id', 'msg-user-'+row.user_id).addClass(itemClass); |
||
167 | // set user obj avatar |
||
168 | itemDom.find('#msg-user-avatar').attr('src', row.user_avatar).removeAttr('id'); |
||
169 | // set user name |
||
170 | if (row.user_block == true) { |
||
171 | itemDom.find('#msg-user-name').html('<s>'+row.user_nick+'</s>').removeAttr('id'); |
||
172 | } else { |
||
173 | itemDom.find('#msg-user-name').text(row.user_nick).removeAttr('id'); |
||
174 | } |
||
175 | // check if new messages inside |
||
176 | if (row.message_new === true) { |
||
177 | itemDom.find('#msg-user-isnew').removeClass('d-none').removeAttr('id'); |
||
178 | } |
||
179 | // store object data |
||
180 | user_object[row.user_id] = row; |
||
181 | // concat string result |
||
182 | userMap += itemDom.html(); |
||
183 | }); |
||
184 | $('#message-user-list').html(userMap); |
||
185 | |||
186 | }).done(function(){ |
||
187 | if (new_dialog < 1) |
||
188 | return false; |
||
189 | |||
190 | $('.message-scroll-body').removeClass('d-none'); |
||
191 | // set message streak title |
||
192 | var current_user = user_object[new_dialog]; |
||
193 | var dialogDom = dialogPanelDom.clone(); |
||
194 | // cleanup global id |
||
195 | dialogDom.removeClass('d-none').removeAttr('id'); |
||
196 | // set user avatar in title panel |
||
197 | dialogDom.find('#msg-user-avatar').attr('src', current_user.user_avatar).removeAttr('id'); |
||
198 | // set user nickname |
||
199 | dialogDom.find('#msg-user-name').text(current_user.user_nick).removeAttr('id'); |
||
200 | // set user profile link |
||
201 | dialogDom.find('#msg-user-link').attr('href', profile_link + '/' + current_user.user_id).removeAttr('id'); |
||
202 | $('#dialog-user-streak').html(dialogDom.html()); |
||
203 | // load 'now' dialog messages |
||
204 | loadMessageDialog('now'); |
||
205 | $('.message-add-container').removeClass('d-none'); |
||
206 | }); |
||
207 | }; |
||
208 | loadMessageDialog = function (type) { |
||
209 | // prevent empty cycles |
||
210 | if (active_dialog_id < 1) { |
||
211 | return false; |
||
212 | } |
||
213 | var msg_query = script_url+'/api/profile/messagelist/'+active_dialog_id+'?lang='+script_lang; |
||
214 | if (type == 'before') { |
||
215 | if (first_msg[active_dialog_id] == null) { |
||
216 | return false; |
||
217 | } |
||
218 | msg_query += '&id='+first_msg[active_dialog_id]+'&type=before'; |
||
219 | } else if (type == 'after') { |
||
220 | if (last_msg[active_dialog_id] == null) { |
||
221 | return false; |
||
222 | } |
||
223 | msg_query += '&id='+last_msg[active_dialog_id]+'&type=after'; |
||
224 | } else { |
||
225 | msg_query += '&type=now'; |
||
226 | } |
||
227 | $.getJSON(msg_query, function(resp){ |
||
228 | if (resp.status !== 1) { |
||
229 | return false; |
||
230 | } |
||
231 | // mark blocked user |
||
232 | if (resp.blocked == true) { |
||
233 | $('#messages-blocked-user').removeClass('d-none'); |
||
234 | $('#send-new-message').addClass('disabled'); |
||
235 | } else { |
||
236 | $('#send-new-message').removeClass('disabled'); |
||
237 | $('#messages-blocked-user').addClass('d-none'); |
||
238 | } |
||
239 | var msgBody = ''; |
||
240 | var isFirst = true; |
||
241 | $.each(resp.data, function(idx,row){ |
||
242 | if (type != 'after' && isFirst) { |
||
243 | first_msg[active_dialog_id] = row.id; |
||
244 | isFirst = false; |
||
245 | } |
||
246 | // get message dom element |
||
247 | var msgDom = (!row.my ? remMsgDom.clone() : myMsgDom.clone()); |
||
248 | // set msg date |
||
249 | msgDom.find('#msg-date').text(row.date).removeAttr('id'); |
||
250 | // set msg text |
||
251 | msgDom.find('#msg-text').text(row.message).removeAttr('id'); |
||
252 | // add target user name from obj cache |
||
253 | if (!row.my && user_object[active_dialog_id] != null) { |
||
254 | msgDom.find('#msg-user-nick').text(user_object[active_dialog_id].user_nick); |
||
255 | } |
||
256 | // compile output concat var |
||
257 | msgBody += msgDom.html(); |
||
258 | if (type != 'before') { |
||
259 | last_msg[active_dialog_id] = row.id; |
||
260 | } |
||
261 | }); |
||
262 | if (type == 'now') { |
||
263 | $('#messages-now').html(msgBody); |
||
264 | $(".message-scroll-body").animate({ scrollTop: 100000 }, "fast"); |
||
265 | } else if(type == 'before') { |
||
266 | $('#messages-before').prepend(msgBody); |
||
267 | } else if (type == 'after') { |
||
268 | $('#messages-now').append(msgBody); |
||
269 | $(".message-scroll-body").animate({ scrollTop: 100000 }, "fast"); |
||
270 | } |
||
271 | }); |
||
272 | }; |
||
273 | <?php // check if defined ?newdialog=userid |
||
274 | $dialogId = \App::$Request->query->get('newdialog', false); |
||
275 | if ($dialogId && Any::isInt($dialogId) && $dialogId > 0) : ?> |
||
276 | new_dialog = <?= $dialogId ?>; |
||
277 | active_dialog_id = new_dialog; |
||
278 | <?php endif; ?> |
||
279 | // load dialogs when page ready |
||
280 | loadDialogUsers(); |
||
281 | // set scheduled loader |
||
282 | window.setInterval(loadDialogUsers, 15 * 1000); |
||
283 | // callback for user onclick -> show dialogs |
||
284 | $(document).on('click', '.media-person', function() { |
||
285 | var selected_dialog_id = this.id.replace('msg-user-', ''); |
||
286 | if (selected_dialog_id === active_dialog_id) { |
||
287 | return false; |
||
288 | } |
||
289 | // set active id |
||
290 | active_dialog_id = selected_dialog_id; |
||
291 | $('.media-person').removeClass(cssUserList.active); |
||
292 | $(this).addClass(cssUserList.active); |
||
293 | // make msg body visible |
||
294 | $('.message-scroll-body').removeClass('d-none'); |
||
295 | // set message streak title |
||
296 | var current_user = user_object[selected_dialog_id]; |
||
297 | var dialogDom = dialogPanelDom.clone(); |
||
298 | // cleanup global id |
||
299 | dialogDom.removeClass('d-none').removeAttr('id'); |
||
300 | // set user avatar in title panel |
||
301 | dialogDom.find('#msg-user-avatar').attr('src', current_user.user_avatar).removeAttr('id'); |
||
302 | // set user nickname |
||
303 | dialogDom.find('#msg-user-name').text(current_user.user_nick).removeAttr('id'); |
||
304 | // set user profile link |
||
305 | dialogDom.find('#msg-user-link').attr('href', profile_link + '/' + current_user.user_id).removeAttr('id'); |
||
306 | $('#dialog-user-streak').html(dialogDom.html()); |
||
307 | // load 'now' dialog messages |
||
308 | loadMessageDialog('now'); |
||
309 | $('.message-add-container').removeClass('d-none'); |
||
310 | }); |
||
311 | $(document).on('click', '#message-load-before', function(){ |
||
312 | loadMessageDialog('before'); |
||
313 | }); |
||
314 | // set schedule to show new messages |
||
315 | window.setInterval(function(){loadMessageDialog('after')}, 15 * 1000); |
||
316 | // if clicked "show more" - increase offset and load permamently |
||
317 | $('#show-more-dialogs').on('click', function(){ |
||
318 | var obj = $(this); |
||
319 | obj.addClass('disabled'); |
||
320 | setTimeout(function(){ |
||
321 | obj.removeClass('disabled'); |
||
322 | }, 5000); |
||
323 | dialog_offset += 1; |
||
324 | loadDialogUsers(); |
||
325 | }); |
||
326 | // if click to btn send message to target |
||
327 | $('#send-new-message').on('click', function(){ |
||
328 | if (active_dialog_id == 0) { |
||
329 | return false; |
||
330 | } |
||
331 | var msgText = $('#msg-text').val(); |
||
332 | if (msgText.length < 1) { |
||
333 | return false; |
||
334 | } |
||
335 | $.post(script_url+'/api/profile/messagesend/'+active_dialog_id+'?lang='+script_lang, {message: msgText}, function(resp){ |
||
336 | if (resp.status === 1) { |
||
337 | loadMessageDialog('after'); |
||
338 | $('#msg-text').val(null); |
||
339 | } |
||
340 | }, 'json').done(function(){ |
||
341 | if (active_dialog_id == new_dialog) { |
||
342 | new_dialog = 0; |
||
343 | loadMessageDialog('now'); |
||
344 | } |
||
345 | }); |
||
346 | }); |
||
347 | // send message by pressing enter |
||
348 | $('#msg-text').keypress(function(e){ |
||
349 | if (e.which == 13) { |
||
350 | $('#send-new-message').focus().click(); |
||
351 | $(this).focus(); |
||
352 | } |
||
353 | }); |
||
354 | }); |
||
355 | }); |
||
356 | </script> |
||
357 | |||
358 | <?php $this->stop() ?> |
Let?s assume that you have a directory layout like this:
and let?s assume the following content of
Bar.php
:If both files
OtherDir/Foo.php
andSomeDir/Foo.php
are loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php
However, as
OtherDir/Foo.php
does not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php
, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: