Passed
Push — master ( ef8807...c1ca83 )
by Mihail
05:17
created

Apps/View/Front/default/content/read.php (3 issues)

1
<?php
2
3
use Ffcms\Core\Helper\Date;
4
use Ffcms\Core\Helper\Type\Any;
5
use Ffcms\Core\Helper\Type\Arr;
6
use Ffcms\Core\Helper\Type\Str;
7
use Ffcms\Templex\Url\Url;
8
9
/** @var Apps\Model\Front\Content\EntityContentRead $model */
10
/** @var Apps\Model\Front\Content\EntityContentSearch $search */
11
/** @var \Ffcms\Templex\Template\Template $this */
12
/** @var bool $trash */
13
/** @var array $configs */
14
15
// check if content is trashed or hidden from display and show it only for admin with content.index permissions
16
if (($trash || !$model->display) && (!\App::$User->isAuth() || !\App::$User->identity()->role->can('Admin/Content/Index'))) {
17
    throw new \Ffcms\Core\Exception\NotFoundException(__('Page not found'));
18
}
19
// set meta title
20
$title = $model->metaTitle;
21
if (Any::isEmpty($title)) {
22
    $title = $model->title;
23
}
24
// set meta description
25
$description = $model->metaDescription;
26
// set meta keywords
27
$keywords = null;
28
if (Any::isArray($model->metaKeywords) && count($model->metaKeywords) > 0) {
29
    $keywords = implode(', ', $model->metaKeywords);
30
}
31
// don't use breadcrumbs on injected pathway rule
32
$breadcrumbs = null;
33
if (!\App::$Request->isPathInjected() && (bool)$model->getCategory()->getProperty('showCategory')) {
34
    $breadcrumbs = [
35
        Url::to('/') => __('Home')
36
    ];
37
    if (Any::isArray($model->catNesting)) {
38
        foreach ($model->catNesting as $cat) {
39
            if (Str::likeEmpty($cat['path'])) {
40
                $breadcrumbs[Url::to('content/list', [$cat['path']])] = __('Contents');
41
            } else {
42
                $breadcrumbs[Url::to('content/list', [$cat['path']])] = $cat['name'];
43
            }
44
        }
45
        $breadcrumbs[] = __('Content') . ': ' . Str::sub($title, 0, 40);
46
    }
47
}
48
49
// render with global layout
50
$this->layout('_layouts/default', [
51
    'title' => $title,
52
    'keywords' => $keywords,
53
    'description' => $description,
54
    'breadcrumbs' => $breadcrumbs
55
]);
56
57
$properties = [
58
    'date' => (bool)$model->getCategory()->getProperty('showDate'),
59
    'author' => (bool)$model->getCategory()->getProperty('showAuthor'),
60
    'views' => (bool)$model->getCategory()->getProperty('showViews'),
61
    'category' => (bool)$model->getCategory()->getProperty('showCategory'),
62
    'rating' => (bool)$model->getCategory()->getProperty('showRating'),
63
    'tags' => (bool)$model->getCategory()->getProperty('showTags')
64
];
65
$showComments = (bool)$model->getCategory()->getProperty('showComments');
66
$showPoster = (bool)$model->getCategory()->getProperty('showPoster');
67
?>
68
<?php $this->start('body') ?>
69
    <article class="article-item article-border" itemscope="itemscope" itemtype="https://schema.org/NewsArticle">
70
        <h1><?= $model->title ?></h1>
71
        <?php if (Arr::in(true, $properties)): ?>
72
            <div class="meta">
73
                <?php if ((bool)$properties['category']): ?>
74
                    <span class="spaced"><i class="fa fa-list"></i> <?= Url::a(['content/list', [$model->catPath]], $model->catName, ['itemprop' => 'genre']) ?></span>
75
                <?php endif; ?>
76
                <?php if ((bool)$properties['date']): ?>
77
                    <span class="spaced"><i class="fa fa-calendar"></i> <time datetime="<?= date('c', Date::convertToTimestamp($model->getRecord()->created_at)) ?> itemprop="datePublished"><?= $model->createDate ?></time></span>
78
                <?php endif; ?>
79
                <?php if ((bool)$properties['author']): ?>
80
                    <?php if ($model->authorId && $model->authorId > 0): ?>
81
                        <span class="spaced"><i class="fa fa-user"></i> <?= Url::a(['profile/show', [$model->authorId]], $model->authorName, ['itemprop' => 'author']) ?></span>
82
                    <?php else: ?>
83
                        <span class="spaced"><i class="fa fa-user"></i> <s><?= $model->authorName ?></s></span>
84
                    <?php endif; ?>
85
                <?php endif; ?>
86
                <?php if ((bool)$properties['views']): ?>
87
                    <span class="spaced"><i class="fa fa-eye"></i> <?= $model->views ?></span>
88
                <?php endif ?>
89
                <?php if (\App::$User->isAuth() && \App::$User->identity()->role->can('Admin/Content/Update')): ?>
90
                    <span class="float-right"><a href="<?= \App::$Alias->scriptUrl . '/admin/content/update/' . $model->id ?>" target="_blank"><i class="fa fa-pencil" style="color: #ff0000;"></i></a></span>
91
                <?php endif; ?>
92
            </div>
93
        <?php else: ?>
94
            <hr />
95
        <?php endif; ?>
96
        <?php if ($trash): ?>
97
            <p class="alert alert-danger"><i class="fa fa-trash"></i> <?= __('This content is placed in trash') ?></p>
98
        <?php endif; ?>
99
        <?php if (!$model->display): ?>
100
            <p class="alert alert-warning"><i class="fa fa-pencil"></i> <?= __('This content now is on moderation stage') ?></p>
101
        <?php endif; ?>
102
        <div id="content-text">
103
            <?php if ($showPoster === true && $model->posterFull !== null && $model->posterThumb !== null): ?>
104
                <a href="#showPoster" data-toggle="modal" data-target="#showPoster">
105
                    <img alt="<?= __('Poster for') ?>: <?= Str::lowerCase($model->title) ?>" src="<?= \App::$Alias->scriptUrl . $model->posterThumb ?>" class="image_poster img-thumbnail" />
106
                </a>
107
                <!-- Modal poster pop-up -->
108
                <div class="modal fade" id="showPoster" tabindex="-1" role="dialog" aria-labelledby="showPosterModal">
109
                    <div class="modal-dialog modal-lg" role="document">
110
                        <div class="modal-content">
111
                            <div class="modal-header">
112
                                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
113
                                <h4 class="modal-title" id="myModalLabel"><?= __('View poster') ?></h4>
114
                            </div>
115
                            <div class="modal-body">
116
                                <img class="img-fluid" src="<?= \App::$Alias->scriptUrl . $model->posterFull ?>" alt="<?= __('Poster image') ?>" style="margin: 0 auto;" />
117
                            </div>
118
                        </div>
119
                    </div>
120
                </div>
121
            <?php endif ;?>
122
            <?= $model->text ?>
123
        </div>
124
        <?php if ($model->galleryItems !== null && Any::isArray($model->galleryItems)): ?>
125
            <div class="row">
126
                <?php $i = 1; ?>
127
                <?php foreach ($model->galleryItems as $thumbPic => $fullPic): ?>
128
                    <div class="col-md-2 well">
129
                        <a href="#showGallery" class="modalGallery" content="<?= \App::$Alias->scriptUrl . $fullPic ?>" id="gallery-<?= $i ?>">
130
                            <img src="<?= \App::$Alias->scriptUrl . $thumbPic ?>" class="img-fluid image-item" />
131
                        </a>
132
                    </div>
133
                    <?php $i++ ?>
134
                <?php endforeach; ?>
135
            </div>
136
            <div class="modal fade" id="showGallery" tabindex="-1" role="dialog" aria-labelledby="showshowGallery">
137
                <div class="modal-dialog modal-max" role="document">
138
                    <div class="modal-content">
139
                        <div class="modal-header">
140
                            <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
141
                            <h4 class="modal-title" id="showModalLabel"><?= __('View picture') ?></h4>
142
                        </div>
143
                        <div class="modal-body" id="modal-gallery-body">
144
                            <img class="img-fluid" src="<?= \App::$Alias->scriptUrl . $model->posterFull ?>" alt="<?= __('Gallery picture') ?>" style="margin: 0 auto;" />
145
                        </div>
146
                    </div>
147
                </div>
148
            </div>
149
        <?php endif; ?>
150
        <?php if ($search->items !== null && Any::isArray($search->items)): ?>
151
            <div class="h3"><?= __('Similar content') ?></div>
152
            <div class="panel-group">
153
                <?php $idx = 1; ?>
154
                <?php foreach ($search->items as $item): ?>
155
                    <div id="similar-group" class="panel panel-default">
156
                        <div class="panel-heading">
157
                            <h4 class="panel-title">
158
                                <a data-toggle="collapse" data-parent="#similar-group" href="#similar<?= $idx ?>">
159
                                    <i class="fa fa-sort-amount-desc"></i> <?= $item['title'] ?>
160
                                </a>
161
                            </h4>
162
                        </div>
163
                        <div id="similar<?= $idx ?>" class="panel-collapse collapse">
164
                            <div class="panel-body">
165
                                <a href="<?= \App::$Alias->baseUrl . $item['uri'] ?>">
166
                                    <?= $item['snippet'] ?>
167
                                </a>
168
                            </div>
169
                        </div>
170
                    </div>
171
                    <?php ++$idx; ?>
172
                <?php endforeach; ?>
173
            </div>
174
        <?php endif; ?>
175
        <div class="row">
176
            <div class="col-md-12">
177
                <div class="float-left">
178
                    <?php if ($properties['rating']) {
0 ignored issues
show
This if statement is empty and can be removed.

This check looks for the bodies of if statements that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.

These if bodies can be removed. If you have an empty if but statements in the else branch, consider inverting the condition.

if (rand(1, 6) > 3) {
//print "Check failed";
} else {
    print "Check succeeded";
}

could be turned into

if (rand(1, 6) <= 3) {
    print "Check succeeded";
}

This is much more concise to read.

Loading history...
179
                        /**echo \App::$View->render('content/_rate', [
0 ignored issues
show
Unused Code Comprehensibility introduced by
61% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
180
                            'id' => $model->id,
181
                            'rating' => $model->rating,
182
                            'canRate' => $model->canRate
183
                        ]);*/
184
                    } ?>
185
                    <?php //\App::$View->render('content/_rateJs') ?>
0 ignored issues
show
Unused Code Comprehensibility introduced by
78% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
186
                </div>
187
                <div class="float-right">
188
                    <?php if ($properties['tags']): ?>
189
                        <div id="content-tags">
190
                            <?php
191
                            if (Any::isArray($model->metaKeywords) && count($model->metaKeywords) > 0 && Str::length($model->metaKeywords[0]) > 0) {
192
                                echo '<i class="fa fa-tags"></i> ';
193
                                foreach ($model->metaKeywords as $tag) {
194
                                    $tag = trim($tag);
195
                                    echo Url::a(['content/tag', [urlencode($tag)]], $tag, ['class' => 'badge badge-secondary']) . "&nbsp;";
196
                                }
197
                            }
198
                            ?>
199
                        </div>
200
                    <?php endif; ?>
201
                </div>
202
            </div>
203
        </div>
204
        <?php if (!Str::likeEmpty($model->source)): ?>
205
            <div id="content-source" style="padding-top: 5px;">
206
                <?php
207
                $sourceUrl = $model->source;
208
                $parseUrl = parse_url($sourceUrl);
209
                $sourceHost = $parseUrl['host'];
210
                ?>
211
                <i class="fa fa-link"></i> <?= __('Source') ?>: <a href="<?= $sourceUrl ?>" rel="nofollow" target="_blank">
212
                    <?= $sourceHost ?>
213
                </a>
214
            </div>
215
        <?php endif; ?>
216
    </article>
217
<?php if ($showComments === true): ?>
218
    <div class="row">
219
        <div class="col-md-12">
220
            <div class="h3 text-success"><?= __('Comments') ?></div>
221
            <hr />
222
            <?= \Widgets\Front\Comments\Comments::widget(['name' => 'content', 'id' => $model->id, 'config' => 'small']); ?>
223
        </div>
224
    </div>
225
<?php endif; ?>
226
<?php if ($model->galleryItems && Any::isArray($model->galleryItems)): ?>
227
    <script>
228
        $(document).ready(function(){
229
            var galleryPos = 1;
230
            $('.modalGallery').on('click', function() {
231
                galleryPos = parseInt($(this).attr('id').replace('gallery-', ''));
232
                var picture = $(this).attr('content');
233
                if (picture != null && picture.length > 0) {
234
                    var gallerySelector = $('#modal-gallery-body');
235
                    gallerySelector.html('<img class="img-fluid gallery-img" alt="Picture" style="margin: 0 auto;" src="' + picture + '"/>');
236
                    gallerySelector.append('<hr />');
237
                    // add previous & next buttons
238
                    var gSelectors = '<p class="text-center">';
239
                    gSelectors += '<a href="#showGallery" id="gallery-show-prev"><i class="fa fa-arrow-left fa-2x"></i></a> ';
240
                    gSelectors += '<a href="#showGallery" id="gallery-show-next"><i class="fa fa-arrow-right fa-2x"></i></a>';
241
                    gSelectors += '</p>';
242
                    gallerySelector.append(gSelectors);
243
                    $('#showGallery').modal('show');
244
                }
245
            });
246
            // click next image in gallery
247
            $(document).on('click', '#gallery-show-next', function() {
248
                galleryPos += 1;
249
                var imgSel = $('#gallery-'+galleryPos);
250
                if (imgSel.length < 1) {
251
                    galleryPos -= 1;
252
                    return;
253
                }
254
                var newImg = imgSel.attr('content');
255
                $(this).parent().parent().find('.gallery-img').fadeOut('fast').attr('src', newImg).fadeIn('fast');
256
            });
257
            // click previous image in gallery
258
            $(document).on('click', '#gallery-show-prev', function(){
259
                galleryPos -= 1;
260
                var imgSel = $('#gallery-'+galleryPos);
261
                if (imgSel.length < 1) {
262
                    galleryPos += 1;
263
                    return;
264
                }
265
                var newImg = imgSel.attr('content');
266
                $(this).parent().parent().find('.gallery-img').fadeOut('fast').attr('src', newImg).fadeIn('fast');
267
            });
268
            // bind keydown (left * right arrows)
269
            $(document).keydown(function(e){
270
                var modalActive = $('#showGallery').hasClass('in');
271
                switch (e.which) {
272
                    case 37: // left arrow
273
                        if (modalActive) {
274
                            $('#gallery-show-prev').trigger('click');
275
                        }
276
                        break;
277
                    case 39: // right arrow
278
                        if (modalActive) {
279
                            $('#gallery-show-next').trigger('click');
280
                        }
281
                        break;
282
                }
283
            })
284
        });
285
    </script>
286
<?php endif; ?>
287
<?php $this->stop() ?>
288
289
<?php $this->push('javascript') ?>
290
291
<?= \Widgets\Tinymce\Tinymce::widget(['config' => 'small']); ?>
292
293
<?php $this->stop() ?>
294