Passed
Push — master ( 29baaf...069627 )
by Mihail
06:51
created

Apps/View/Front/default/profile/show.php (5 issues)

Labels

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
use Apps\ActiveRecord\ProfileField;
3
use Ffcms\Core\Helper\Date;
4
use Ffcms\Core\Helper\HTML\Form;
5
use Ffcms\Core\Helper\HTML\Listing;
6
use Ffcms\Core\Helper\Type\Obj;
7
use Ffcms\Core\Helper\Serialize;
8
use Ffcms\Core\Helper\Type\Str;
9
use Ffcms\Core\Helper\Url;
10
11
/** @var $user Apps\ActiveRecord\User */
12
/** @var $viewer Apps\ActiveRecord\User */
13
/** @var $wall Apps\ActiveRecord\WallPost|null */
14
/** @var $notify array|null */
15
/** @var $wallRecords object */
16
/** @var $pagination Ffcms\Core\Helper\HTML\SimplePagination */
17
/** @var $isSelf bool */
18
/** @var $ratingOn bool */
19
20
// $user is a target profile depended object(not current user!!!)
21
22
$name = \App::$Security->strip_tags($user->getProfile()->nick);
23
24
if (Str::likeEmpty($name)) {
25
    $name = __('No name');
26
}
27
28
$this->title = __('Profile') . ': ' . $name;
29
30
$this->breadcrumbs = [
31
    Url::to('/') => __('Home'),
32
    $this->title
33
];
34
35
?>
36
<div class="row">
37
    <div class="col-md-12">
38
        <h1><?= $name ?> <sup><small>id: <?= $user->id; ?></small></sup></h1>
39
    </div>
40
</div>
41
<hr/>
42
<div class="row">
43
    <div class="col-md-4">
44
        <img src="<?= $user->getProfile()->getAvatarUrl('big') ?>" class="img-responsive center-block img-rounded" />
45
        <?php
46
        if ($ratingOn):
47
            $rateClass = 'btn-default';
48
            $rateValue = (int)$user->getProfile()->rating;
49
            if ($user->getProfile()->rating > 0) {
50
                $rateClass = 'btn-info';
51
            } elseif ($user->getProfile()->rating < 0) {
52
                $rateClass = 'btn-warning';
53
            }
54
        ?>
55
        <?php if ($isSelf): ?>
56
        <div class="row">
57
            <div class="col-md-12">
58
                <a href="javascript:void(0);" class="btn btn-block <?= $rateClass ?>">
59
                    <?= __('Rating') ?>: <span class="badge"><?= $rateValue ?></span>
60
                </a>
61
            </div>
62
        </div>
63
        <?php else: ?>
64
        <div class="row">
65
            <div class="col-md-8" style="padding-right: 0;">
66
                <a href="javascript:void(0);" class="btn btn-block <?= $rateClass ?>">
67
                    <?= __('Rating') ?>:
68
                    <span class="badge"><?= $rateValue > 0 ? '+' : null ?>
69
                        <span id="ratingValue"><?= $rateValue ?></span>
70
                    </span>
71
                </a>
72
            </div>
73
            <div class="col-md-2" style="padding-left: 1px;padding-right: 0;">
74
                <button id="addRating" class="btn btn-block btn-success">+</button>
75
            </div>
76
            <div class="col-md-2" style="padding-left: 1px; padding-right: 0;">
77
                <button class="btn btn-block btn-danger" id="reduceRating">-</button>
78
            </div>
79
        </div>
80
        <?php endif; ?>
81
        <?php endif; ?>
82
        <?php
83
        $userMenu = null;
84
        if (true === $isSelf) {
85
            $userMenu = [
86
                ['type' => 'link', 'link' => ['profile/avatar'], 'text' => '<i class="fa fa-camera"></i> ' . __('Avatar'), 'html' => true],
87
                ['type' => 'link', 'link' => ['profile/messages'], 'text' => '<i class="fa fa-envelope"> ' . __('Messages') . ' <span class="badge pm-count-block">0</span>', 'html' => true],
88
                ['type' => 'link', 'link' => ['profile/settings'], 'text' => '<i class="fa fa-cogs"></i> ' . __('Settings'), 'html' => true]
89
            ];
90
        } elseif (\App::$User->isAuth()) {
91
            $userMenu = [
92
                [
93
                    'type' => 'link', 'link' => Url::to('profile/messages', null, null, ['newdialog' => $user->id]),
94
                    'text' => '<i class="fa fa-pencil-square-o"></i> ' . __('Write message'), 'html' => true
95
                ],
96
                [
97
                    'type' => 'link', 'link' => Url::to('profile/ignore', null, null, ['id' => $user->id]),
98
                    'text' => '<i class="fa fa-user-times"></i> ' . __('Block'), 'html' => true, 'property' => ['class' => 'alert-danger']
99
                ]
100
            ];
101
        }
102
        ?>
103
        <?= Listing::display([
104
            'type' => 'ul',
105
            'property' => ['class' => 'nav nav-pills nav-stacked'],
106
            'items' => $userMenu
107
        ]) ?>
108
    </div>
109
    <div class="col-md-8">
110
        <h2><?= __('Profile data'); ?></h2>
111
        <div class="table-responsive">
112
            <table class="table table-striped">
113
                <tr>
114
                    <td><?= __('Join date'); ?></td>
115
                    <td><?= Date::convertToDatetime($user->created_at, Date::FORMAT_TO_DAY); ?></td>
116
                </tr>
117
                <?php if ($user->getProfile()->birthday !== null && !Str::startsWith('0000-', $user->getProfile()->birthday)): ?>
118
                <tr>
119
                    <td><?= __('Birthday'); ?></td>
120
                    <td>
121
                        <?= Url::link(
122
                            ['profile/index', 'born', Date::convertToDatetime($user->getProfile()->birthday, 'Y')],
123
                            Date::convertToDatetime($user->getProfile()->birthday, Date::FORMAT_TO_DAY)
124
                            ) ?>
125
                    </td>
126
                </tr>
127
                <?php endif; ?>
128
                <?php $sex = $user->getProfile()->sex ?>
129
                <tr>
130
                    <td><?= __('Sex'); ?></td>
131
                    <td>
132
                        <?php
133
                            if ($sex == 1) { // could be string(1) "1" or int(1) 1
134
                                echo __('Male');
135
                            } elseif ($sex == 2) {
136
                                echo __('Female');
137
                            } else {
138
                                echo __('Unknown');
139
                            }
140
                        ?>
141
                    </td>
142
                </tr>
143 View Code Duplication
                <?php if ($user->getProfile()->phone !== null && Str::length($user->getProfile()->phone) > 0): ?>
144
                <tr>
145
                    <td><?= __('Phone'); ?></td>
146
                    <td><?= \App::$Security->strip_tags($user->getProfile()->phone); ?></td>
147
                </tr>
148
                <?php endif; ?>
149 View Code Duplication
                <?php if ($user->getProfile()->url !== null && Str::length($user->getProfile()->url) > 0): ?>
150
                <tr>
151
                    <td><?= __('Website'); ?></td>
152
                    <td>
153
                        <a rel="nofollow" target="_blank" href="<?= \App::$Security->strip_tags($user->getProfile()->url); ?>"><?= __('Visit'); ?></a>
154
                    </td>
155
                </tr>
156
                <?php endif; ?>
157
                <?php if ($user->getProfile()->city !== null && Str::length($user->getProfile()->city) > 0):
158
                    $city = \App::$Security->strip_tags($user->getProfile()->city);
159
                ?>
160
                <tr>
161
                    <td><?= __('City') ?></td>
162
                    <td><?= Url::link(['profile/index', 'city', trim($city, ' ')], $city) ?></td>
0 ignored issues
show
It seems like $city defined by \App::$Security->strip_t...er->getProfile()->city) on line 158 can also be of type array; however, Ffcms\Core\Helper\Url::link() does only seem to accept string, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
163
                </tr>
164
                <?php endif; ?>
165
                <?php if ($user->getProfile()->hobby !== null && Str::length($user->getProfile()->hobby) > 0): ?>
166
                <tr>
167
                    <td><?= __('Interests'); ?></td>
168
                    <td>
169
                        <?php
170
                        $hobbyArray = explode(',', $user->getProfile()->hobby);
171
                        foreach ($hobbyArray as $item) {
172
                            $item = \App::$Security->strip_tags($item);
173
                            if ($item !== null && Str::length($item) > 1) {
0 ignored issues
show
It seems like $item defined by \App::$Security->strip_tags($item) on line 172 can also be of type array; however, Ffcms\Core\Helper\Type\Str::length() does only seem to accept string, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
174
                                echo Url::link(['profile/index', 'hobby', trim($item, ' ')], $item, ['class' => 'label label-success']) . ' ';
0 ignored issues
show
It seems like $item defined by \App::$Security->strip_tags($item) on line 172 can also be of type array; however, Ffcms\Core\Helper\Url::link() does only seem to accept string, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
175
                            }
176
                        }
177
                        ?>
178
                    </td>
179
                </tr>
180
                <?php endif; ?>
181
                <?php
182
                $custom_fields = Serialize::decode($user->getProfile()->custom_data);
183
                if ($custom_fields !== null && Obj::isArray($custom_fields) && count($custom_fields) > 0): ?>
184
                    <?php foreach ($custom_fields as $cid => $value): ?>
185
                        <?php if (!Str::likeEmpty($value)): ?>
186
                            <tr>
187
                                <td><?= ProfileField::getNameById($cid) ?></td>
188
                                <td>
189
                                    <?php
190
                                    if (ProfileField::getTypeById($cid) === 'link') {
191
                                        echo Url::link($value, Str::sub($value, 30));
192
                                    } else {
193
                                        echo \App::$Security->strip_tags($value);
194
                                    }
195
                                    ?>
196
                                </td>
197
                            </tr>
198
                        <?php endif; ?>
199
                    <?php endforeach; ?>
200
                <?php endif; ?>
201
            </table>
202
        </div>
203
        <h2><?= __('Wall') ?></h2>
204
        <?php if ($wall !== null): ?>
205
            <?php
206
            // show notification if exist
207
            if (Obj::isArray($notify) && count($notify) > 0) {
208
                echo $this->render('macro/notify', ['notify' => $notify]);
209
            }
210
            ?>
211
            <?php $form = new Form(
212
                $wall,
213
                ['class' => 'form-horizontal', 'method' => 'post', 'action' => ''],
214
                ['base' => '<div class="form-group no-margin-bottom"><div class="col-md-12">%item% <p class="help-block">%help%</p></div></div>']
215
            ); ?>
216
            <?= $form->start() ?>
0 ignored issues
show
The method start() does not seem to exist on object<Ffcms\Core\Helper\HTML\Form>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
217
            <?= $form->field('message', 'textarea', ['class' => 'form-control']); ?>
218
            <div class="text-right"><?= $form->submitButton(__('Send'), ['class' => 'btn btn-default']); ?></div>
219
            <?= $form->finish(); ?>
220
            <?php \App::$Alias->addPlainCode('js', "$('#" . $wall->getFormName() . "').on('change keyup keydown paste cut', 'textarea', function () { $(this).height(0).height(this.scrollHeight);}).find('textarea').change();") ?>
221
        <?php endif; ?>
222
        <?php
223
        if ($wallRecords !== null):
224
            foreach ($wallRecords as $post):
225
                /** @var $referObject object */
226
                $referObject = \App::$User->identity($post->sender_id);
227
                if ($referObject === null) { // caster not founded? skip ...
228
                    continue;
229
                }
230
                $referNickname = ($referObject->getProfile()->nick == null ?
231
                    __('No name') . ' <sup>id' . $referObject->getId() . '</sup>' :
232
                    \App::$Security->strip_tags($referObject->getProfile()->nick));
233
                ?>
234
                <div class="row object-lightborder" id="wall-post-<?= $post->id ?>">
235
                    <div class="col-md-2">
236
                        <div class="text-center"><img class="img-responsive img-rounded" alt="Avatar of <?= $referNickname ?>"
237
                             src="<?= $referObject->getProfile()->getAvatarUrl('small') ?>" />
238
                        </div>
239
                    </div>
240
                    <div class="col-md-10">
241
                        <h5 style="margin-top: 0;">
242
                            <i class="fa fa-pencil"></i> <?= Url::link(['profile/show', $post->sender_id], $referNickname) ?>
0 ignored issues
show
It seems like $referNickname defined by $referObject->getProfile...ct->getProfile()->nick) on line 230 can also be of type array; however, Ffcms\Core\Helper\Url::link() does only seem to accept string, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
243
                            <small class="pull-right"><?= Date::convertToDatetime($post->updated_at, Date::FORMAT_TO_SECONDS); ?></small>
244
                        </h5>
245
                        <div class="object-text">
246
                            <?= \App::$Security->strip_tags($post->message); ?>
247
                        </div>
248
                        <hr style="margin: 5px;" />
249
                        <div><i class="fa fa-comment-o"></i>
250
                            <a href="#wall-post-<?= $post->id ?>" id="wall-post-response-<?= $post->id ?>" class="show-wall-response">
251
                                <?= __('Answers') ?> (<span id="wall-post-response-count-<?= $post->id ?>">0</span>)
252
                            </a>
253
                            <?php if ($post->target_id === $viewer->id || $post->sender_id === $viewer->id): ?>
254
                                <?= Url::link(['profile/walldelete', $post->id], __('Delete'), ['class' => 'pull-right']) ?>
255
                            <?php endif; ?>
256
                        </div>
257
                        <div id="wall-answer-dom-<?= $post->id; ?>" class="hidden"></div>
258
                    </div>
259
                </div>
260
            <?php
261
            endforeach;
262
        endif;
263
        ?>
264
        <div class="text-center">
265
            <?= $pagination->display(['class' => 'pagination pagination-centered']) ?>
266
        </div>
267
    </div>
268
</div>
269
<script>
270
    var hideAnswers = [];
271
    window.jQ.push(function(){
272
        $(function(){
273
            var elements = $('.object-lightborder');
274
            var viewer_id = 0;
275
            var target_id = 0;
276
            var is_self_profile = <?= $isSelf === true ? 'true' : 'false' ?>;
277
            <?php if (\App::$User->isAuth()): ?>
278
            viewer_id = <?= $viewer->getId() ?>;
279
            <?php endif; ?>
280
            target_id = <?= $user->getId() ?>;
281
            var postIds = [];
282
            $.each(elements, function(key, val) {
283
                postIds.push(val.id.replace('wall-post-', ''));
284
            });
285
286
            // load answers count via JSON
287
            if (postIds.length > 0) {
288
                $.getJSON(script_url+'/api/profile/wallanswercount/' + postIds.join(',') + '?lang='+script_lang, function (json) {
289
                    // data is successful loaded, pharse
290
                    if (json.status === 1) {
291
                        $.each(json.data, function(key, val){
292
                            $('#wall-post-response-count-'+key).text(val);
293
                        });
294
                    }
295
                });
296
            }
297
298
            // load answers via JSON and add to current DOM
299
            $.fn.loadAnswers = function(postId) {
300
                $.getJSON(script_url+'/api/profile/showwallanswers/' + postId +'?lang='+script_lang, function (json) {
301
                    if (json.status !== 1) {
302
                        return null;
303
                    }
304
                    var htmlAnswer = '<hr style="margin: 5px;" />';
305
                    htmlAnswer += '<div class="well">';
306
                    htmlAnswer += '<div id="send-wall-object-'+postId+'"></div>';
307
                    htmlAnswer += '<input type="text" id="make-answer-'+postId+'" placeHolder="<?= __('Write comment') ?>" class="form-control wall-answer-text" maxlength="200" />';
308
                    htmlAnswer += '<a style="margin-top: 5px;" href="#wall-post-'+postId+'" class="send-wall-answer btn btn-primary btn-sm" id="send-wall-'+postId+'"><?= __('Send') ?></a>';
309
                    htmlAnswer += '<span class="pull-right" id="answer-counter-'+postId+'">200</span>';
310
                    htmlAnswer += "</div>";
311
                    $.each(json.data, function(idx, row){
312
                        htmlAnswer += '<div class="row wall-answer">';
313
                        htmlAnswer += '<div class="col-md-2"><img src="'+row.user_avatar+'" alt="avatar" class="img-responsive img-rounded" /></div>';
314
                        htmlAnswer += '<div class="col-md-10">';
315
                        htmlAnswer += '<div class="answer-header">';
316
                        htmlAnswer += '<a href="<?= \App::$Alias->baseUrl ?>/profile/show/'+row.user_id+'">'+row.user_nick+'</a>';
317
                        htmlAnswer += '<small class="pull-right">'+row.answer_date;
318
                        if (is_self_profile || row.user_id === viewer_id) {
319
                            htmlAnswer += '<a href="#send-wall-object-' + postId + '" class="delete-answer" id="delete-answer-' + row.answer_id + '-' + postId +'"><i class="fa fa-lg fa-times"></i></a>';
320
                        }
321
                        htmlAnswer += '</small>';
322
                        htmlAnswer += '</div>';
323
                        htmlAnswer += '<div>' + row.answer_message + '</div>';
324
                        htmlAnswer += '</div></div>';
325
                    });
326
                    $('#wall-answer-dom-'+postId).html(htmlAnswer);
327
                })
328
            };
329
330
            $.fn.addAnswer = function(postId, message) {
331
                $.post(script_url+'/api/profile/sendwallanswer/'+postId+'?lang='+script_lang, {message: message}, function(response){
332
                    if (response.status === 1) {
333
                        $.fn.loadAnswers(postId);
334
                    }
335
                }, 'json').done(function() {
336
                    return true;
337
                });
338
                return false;
339
            };
340
341
342
            // if clicked on "Answers" - show it and send form
343
            $('.show-wall-response').on('click', function(){
344
                var postId = this.id.replace('wall-post-response-', '');
345
                // control hide-display on clicking to "Answers" link
346
                if (hideAnswers[postId] === true) {
347
                    hideAnswers[postId] = false;
348
                    $('#wall-answer-dom-'+postId).addClass('hidden');
349
                    return null;
350
                } else {
351
                    hideAnswers[postId] = true;
352
                    $('#wall-answer-dom-'+postId).removeClass('hidden');
353
                }
354
                // load data and set html
355
                $.fn.loadAnswers(postId);
356
            });
357
358
            // calc entered symbols
359
            $(document).on('keyup', '.wall-answer-text', function() {
360
                var postId = this.id.replace('make-answer-', '');
361
                var msglimit = 200;
362
                var msglength = $(this).val().length;
363
364
                var limitObject = $('#answer-counter-' + postId);
365
366
                if (msglength >= msglimit) {
367
                    limitObject.html('<span class="label label-danger">0</span>');
368
                } else {
369
                    limitObject.text(msglimit-msglength);
370
                }
371
            });
372
373
            $(document).on('click', '.delete-answer', function(){
374
                var answerIdPostId = this.id.replace('delete-answer-', '').split('-');
375
                $.getJSON(script_url+'/api/profile/deleteanswerowner/'+answerIdPostId[0]+'?lang='+script_lang, function(response){
376
                    $.fn.loadAnswers(answerIdPostId[1]);
377
                });
378
            });
379
380
            // delegate live event simple for add-ed dom element
381
            $(document).on('click', '.send-wall-answer', function(){
382
                var answerToId = this.id.replace('send-wall-', '');
383
                var message = $('#make-answer-'+answerToId).val();
384
                if (message == null || message.length < 3) {
385
                    alert('Message is too short');
386
                    return null;
387
                }
388
389
                var result = $.fn.addAnswer(answerToId, message);
390
                // sending going wrong !
391
                if (false === result) {
392
                    $('#send-wall-object-'+answerToId).html('<p class="alert alert-warning"><?= __('Comment send was failed! Wait few moments') ?></p>');
393
                }
394
            });
395
396
            // work with + and - rating clicks
397
            $.fn.changeRating = function(type) {
398
                // prevent some shits
399
                if (is_self_profile || viewer_id == 0) {
400
                    return false;
401
                }
402
403
                $.post(script_url+'/api/profile/changerating?lang='+script_lang, {type: type, target: target_id}, function(resp){
404
                    if (resp.status === 1) {
405
                        var rV = parseInt($('#ratingValue').text());
406
                        if (type == '+') {
407
                            $('#ratingValue').text(rV+1);
408
                        } else {
409
                            $('#ratingValue').text(rV-1);
410
                        }
411
                        alert('<?= __('Rating was successful changed') ?>');
412
                    } else {
413
                        alert('<?= __('Rating cannot be changed') ?>');
414
                    }
415
                    $('#addRating').addClass('disabled');
416
                    $('#reduceRating').addClass('disabled');
417
                }, 'json');
418
            };
419
420
            $('#addRating').on('click', function(){
421
                $.fn.changeRating('+');
422
            });
423
            $('#reduceRating').on('click', function(){
424
                $.fn.changeRating('-');
425
            });
426
        });
427
    });
428
</script>