Passed
Push — master ( 6084dc...68443e )
by Mihail
05:40
created

Apps/View/Front/default/content/read.php (1 issue)

Labels
Severity

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
3
/** @var $model Apps\Model\Front\Content\EntityContentRead */
4
/** @var $search Apps\Model\Front\Content\EntityContentSearch */
5
/** @var $this object */
6
/** @var $trash bool */
7
/** @var $configs array */
8
use Ffcms\Core\Helper\Type\Arr;
9
use Ffcms\Core\Helper\Type\Obj;
10
use Ffcms\Core\Helper\Type\Str;
11
use Ffcms\Core\Helper\Url;
12
13
// set meta title
14
$this->title = \App::$Security->strip_tags($model->metaTitle);
15
if (Str::likeEmpty($this->title)) {
16
    $this->title = \App::$Security->strip_tags($model->title);
17
}
18
// set meta description
19
$this->description = \App::$Security->strip_tags($model->metaDescription);
20
// set meta keywords
21
if (Obj::isArray($model->metaKeywords) && count($model->metaKeywords) > 0) {
22
    $this->keywords = implode(', ', $model->metaKeywords);
23
}
24
25
// don't use breadcrumbs on injected pathway rule
26
if (!\App::$Request->isPathInjected()) {
27
    $breadcrumbs = [
28
            Url::to('/') => __('Home')
29
    ];
30
    if (Obj::isArray($model->catNesting)) {
31
        foreach ($model->catNesting as $cat) {
32
            if (Str::likeEmpty($cat['path'])) {
33
                $breadcrumbs[Url::to('content/list', $cat['path'])] = __('Contents');
34
            } else {
35
                $breadcrumbs[Url::to('content/list', $cat['path'], null, [], false)] = $cat['name'];
36
            }
37
        }
38
        $breadcrumbs[] = __('Content') . ': ' . Str::sub($this->title, 0, 40);
39
    }
40
41
    $this->breadcrumbs = $breadcrumbs;
42
}
43
44
$properties = [
45
    'date' => (int)$model->getCategory()->getProperty('showDate') === 1,
46
    'author' => (int)$model->getCategory()->getProperty('showAuthor') === 1,
47
    'views' => (int)$model->getCategory()->getProperty('showViews') === 1,
48
    'category' => (int)$model->getCategory()->getProperty('showCategory') === 1
49
];
50
$showComments = (int)$model->getCategory()->getProperty('showComments') === 1;
51
$showPoster = (int)$model->getCategory()->getProperty('showPoster') === 1;
52
53
\App::$Cache->set('test.me.baby.1', ['key' => 'value']);
54
?>
55
56
<article class="article-item">
57
    <h1><?= \App::$Security->strip_tags($model->title); ?></h1>
58
    <?php if (Arr::in(true, $properties)): ?>
59
    <div class="meta">
60
        <?php if ($properties['category'] === true): ?>
61
        <span><i class="fa fa-list"></i><?= Url::link(['content/list', $model->catPath, null, [], false], $model->catName, ['itemprop' => 'genre']) ?></span>
62
        <?php endif; ?>
63
        <?php if ($properties['date'] === true): ?>
64
        <span><i class="fa fa-calendar"></i><time datetime="<?= date('c', $model->createDate) ?> itemprop="datePublished"><?= $model->createDate ?></time></span>
65
        <?php endif; ?>
66
        <?php if ($properties['author'] === true): ?>
67
            <?php if ($model->authorId !== null && $model->authorId > 0): ?>
68
                <span><i class="fa fa-user"></i><?= Url::link(['profile/show', $model->authorId], $model->authorName, ['itemprop' => 'author']) ?></span>
69
            <?php else: ?>
70
                <span><i class="fa fa-user"></i><s><?= $model->authorName ?></s></span>
71
            <?php endif; ?>
72
        <?php endif; ?>
73
        <?php if ($properties['views'] === true): ?>
74
        <span><i class="fa fa-eye"></i><?= $model->views ?></span>
75
        <?php endif ?>
76
        <?php if (\App::$User->isAuth() && \App::$User->identity()->getRole()->can('Admin/Content/Update')): ?>
77
        <span class="pull-right"><a href="<?= \App::$Alias->scriptUrl . '/admin/content/update/' . $model->id ?>" target="_blank"><i class="fa fa-pencil" style="color: #ff0000;"></i></a></span>
78
        <?php endif; ?>
79
    </div>
80
    <?php else: ?>
81
    <hr />
82
    <?php endif; ?>
83
    <?php if ($trash): ?>
84
    <p class="alert alert-danger"><i class="fa fa-trash-o"></i> <?= __('This content is placed in trash') ?></p>
85
    <?php endif; ?>
86
    <div id="content-text">
87
        <?php if ($showPoster === true && $model->posterFull !== null && $model->posterThumb !== null): ?>
88
            <a href="#showPoster" data-toggle="modal" data-target="#showPoster">
89
                <img alt="<?= __('Poster for') ?>: <?= Str::lowerCase(\App::$Security->strip_tags($model->title)) ?>" src="<?= \App::$Alias->scriptUrl . $model->posterThumb ?>" class="image_poster img-thumbnail" />
90
            </a>
91
92
            <!-- Modal poster pop-up -->
93
            <div class="modal fade" id="showPoster" tabindex="-1" role="dialog" aria-labelledby="showPosterModal">
94
                <div class="modal-dialog modal-lg" role="document">
95
                    <div class="modal-content">
96
                        <div class="modal-header">
97
                            <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
98
                            <h4 class="modal-title" id="myModalLabel"><?= __('View poster') ?></h4>
99
                        </div>
100
                        <div class="modal-body">
101
                            <img class="img-responsive" src="<?= \App::$Alias->scriptUrl . $model->posterFull ?>" alt="<?= __('Poster image') ?>" style="margin: 0 auto;" />
102
                        </div>
103
                    </div>
104
                </div>
105
            </div>
106
        <?php endif ;?>
107
        <?= $model->text ?>
108
    </div>
109
    <?php if ($model->galleryItems !== null && Obj::isArray($model->galleryItems)): ?>
110
        <div class="row">
111
        <?php foreach ($model->galleryItems as $thumbPic => $fullPic): ?>
112
            <div class="col-md-2 well">
113
                <a href="#showGallery" class="modalGallery" content="<?= \App::$Alias->scriptUrl . $fullPic ?>"><img src="<?= \App::$Alias->scriptUrl . $thumbPic ?>" class="img-responsive image-item" /></a>
114
            </div>
115
        <?php endforeach; ?>
116
        </div>
117
        <div class="modal fade" id="showGallery" tabindex="-1" role="dialog" aria-labelledby="showshowGallery">
118
            <div class="modal-dialog modal-lg" role="document">
119
                <div class="modal-content">
120
                    <div class="modal-header">
121
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
122
                        <h4 class="modal-title" id="showModalLabel"><?= __('View picture') ?></h4>
123
                    </div>
124
                    <div class="modal-body" id="modal-gallery-body">
125
                        <img class="img-responsive" src="<?= \App::$Alias->scriptUrl . $model->posterFull ?>" alt="<?= __('Gallery picture') ?>" style="margin: 0 auto;" />
126
                    </div>
127
                </div>
128
            </div>
129
        </div>
130
    <?php endif; ?>
131
    <?php if ($search->items !== null && Obj::isArray($search->items)): ?>
132
        <div class="h3"><?= __('Similar content') ?></div>
133
        <div class="panel-group">
134
        <?php $idx = 1; ?>
135
        <?php foreach ($search->items as $item): ?>
136
            <div id="similar-group" class="panel panel-default">
137
                <div class="panel-heading">
138
                    <h4 class="panel-title">
139
                        <a data-toggle="collapse" data-parent="#similar-group" href="#similar<?= $idx ?>">
140
                            <i class="fa fa-arrows-v"></i> <?= $item['title'] ?>
141
                        </a>
142
                    </h4>
143
                </div>
144
                <div id="similar<?= $idx ?>" class="panel-collapse collapse">
145
                    <div class="panel-body">
146
                        <a href="<?= \App::$Alias->baseUrl . $item['uri'] ?>">
147
                            <?= $item['snippet'] ?>
148
                        </a>
149
                    </div>
150
                </div>
151
            </div>
152
            <?php ++$idx; ?>
153
        <?php endforeach; ?>
154
        </div>
155
    <?php endif; ?>
156
    <?php if ((int)$configs['keywordsAsTags'] === 1): ?>
157
    <div id="content-tags">
158
        <?php
159
        if (Obj::isArray($model->metaKeywords) && count($model->metaKeywords) > 0 && Str::length($model->metaKeywords[0]) > 0) {
160
            echo '<i class="fa fa-tags hidden-xs"></i> ';
161 View Code Duplication
            foreach ($model->metaKeywords as $tag) {
162
                $tag = \App::$Security->strip_tags(trim($tag));
163
                echo Url::link(['content/tag', $tag], $tag, ['class' => 'label label-default']) . "&nbsp;";
0 ignored issues
show
It seems like $tag defined by \App::$Security->strip_tags(trim($tag)) on line 162 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...
164
            }
165
        }
166
        ?>
167
    </div>
168
    <?php endif; ?>
169
    <?php if (!Str::likeEmpty($model->source)): ?>
170
    <div id="content-source" style="padding-top: 5px;">
171
        <?php
172
        $sourceUrl = \App::$Security->strip_tags($model->source);
173
        $parseUrl = parse_url($sourceUrl);
174
        $sourceHost = $parseUrl['host'];
175
        ?>
176
        <i class="fa fa-thumb-tack"></i> <?= __('Source') ?>: <a href="<?= $sourceUrl ?>" rel="nofollow" target="_blank">
177
            <?= $sourceHost ?>
178
        </a>
179
    </div>
180
    <?php endif; ?>
181
</article>
182
<?php if ($showComments === true): ?>
183
<div class="row">
184
    <div class="col-md-12">
185
        <div class="h3 text-success"><?= __('Comments') ?></div>
186
        <hr />
187
        <?= \Widgets\Front\Comments\Comments::widget(['targetClass' => 'wysi-comments', 'config' => 'config-small']); ?>
188
    </div>
189
</div>
190
<?php endif; ?>
191
<?php if ($model->galleryItems !== null && Obj::isArray($model->galleryItems)): ?>
192
<script>
193
    window.jQ.push(function(){
194
        $('.modalGallery').on('click', function() {
195
            var picture = $(this).attr('content');
196
            if (picture != null && picture.length > 0) {
197
                $('#modal-gallery-body').html('<img class="img-responsive" alt="Picture" style="margin: 0 auto;" src="' + picture + '"/>');
198
                $('#showGallery').modal('show');
199
            }
200
        });
201
    });
202
</script>
203
<?php endif; ?>