Passed
Push — master ( ef80b0...df5b6f )
by Mihail
04:52
created

Apps/View/Admin/default/content/content_update.php (4 issues)

1
<?php
2
3
/** @var Apps\Model\Admin\Content\FormContentUpdate $model */
4
/** @var \Ffcms\Templex\Template\Template $this */
5
6
use Apps\ActiveRecord\ContentCategory;
7
use Ffcms\Core\Helper\Text;
8
use Ffcms\Core\Helper\Type\Str;
9
use Ffcms\Templex\Helper\Html\Dom;
10
use Ffcms\Templex\Url\Url;
11
12
$this->layout('_layouts/default', [
13
    'title' => __('Content edit'),
14
    'breadcrumbs' => [
15
        Url::to('main/index') => __('Main'),
16
        Url::to('application/index') => __('Applications'),
17
        Url::to('content/index') => __('Contents'),
18
        __('Content manage')
19
    ]
20
]);
21
?>
22
23
<?php $this->push('css') ?>
24
<!-- jquery ui plugin -->
25
<link rel="stylesheet" href="<?= \App::$Alias->scriptUrl ?>/vendor/phpffcms/ffcms-assets/node_modules/jquery-ui-dist/jquery-ui.min.css" />
26
<!-- dropzone css plugin -->
27
<link rel="stylesheet" href="<?= \App::$Alias->scriptUrl ?>/vendor/phpffcms/ffcms-assets/node_modules/dropzone/dist/dropzone.css" />
28
<style>
29
    .dropzone {
30
        border: 2px dashed #0087F7;
31
        border-radius: 5px;
32
        background: white;
33
    }
34
</style>
35
<!-- selectize plugin -->
36
<link rel="stylesheet" href="<?= \App::$Alias->scriptUrl ?>/vendor/phpffcms/ffcms-assets/node_modules/selectize/dist/css/selectize.default.css" />
37
<?php $this->stop() ?>
38
39
<?php $this->start('body') ?>
40
<?= $this->insert('content/_tabs') ?>
41
<h1><?= __('Content manage') ?></h1>
42
<?php
43
$form = $this->form($model);
44
echo $form->start();
45
46
$menu = $this->bootstrap()->nav('ul', ['class' => 'nav-tabs'])
47
    ->menu(['text' => __('General'), 'tab' => function() use ($form) {
48
        /** @var \Ffcms\Templex\Template\Template $this */
49
        $langMenu = $this->bootstrap()->nav('ul', ['class' => 'nav-tabs']);
50
        foreach (\App::$Properties->get('languages') as $lang) {
51
            $langMenu->menu([
52
                'text' => Str::upperCase($lang),
53
                'tab' => function() use ($form, $lang) {
54
                    return $form->fieldset()->text('title.' . $lang, null, __('Fill the title of the content for current language locale')) .
55
                        '<strong>' . __('Content text') . '</strong><br />' .
56
                        $form->field()->textarea('text.' . $lang, ['class' => 'form-control wysiwyg', 'rows' => 7]);
57
                },
58
                'tabActive' => $lang === \App::$Request->getLanguage()
59
            ]);
60
        }
61
        return (new Dom())->div(function() use ($langMenu) {
62
            return $langMenu->display();
63
            }, ['class' => 'nav-border']);
64
    }, 'tabActive' => true])
65
    ->menu(['text' => __('Properties'), 'tab' => function() use ($form) {
66
        /** @var \Ffcms\Templex\Template\Template $this */
67
        $langMenu = $this->bootstrap()->nav('ul', ['class' => 'nav-tabs']);
68
        $context = $form->fieldset()->text('path', null, __('Slug of URL pathway for this content item'))
69
            . $form->fieldset()->select('categoryId', ['options' => ContentCategory::getSortedCategories(), 'optionsKey' => true, 'multiple' => null], __('Select content category'));
70
71
        foreach (\App::$Properties->get('languages') as $lang) {
72
            $langMenu->menu([
73
                'text' => Str::upperCase($lang),
74
                'tab' => function() use ($form, $lang) {
75
                    return $form->fieldset()->text('metaTitle.' . $lang, null, __('Set meta title for content page (displayed in browser head). Recommended length: 50-70 chars')).
76
                        $form->fieldset()->text('metaKeywords.' . $lang, ['class' => 'tag-selectize'], __('Set meta keywords for this content (for search engine crawlers) separated by comma')).
77
                        $form->fieldset()->text('metaTitle.' . $lang, null, __('Set meta description for this content (for search engine crawlers). Recommended length: 200-250 chars'));
78
                },
79
                'tabActive' => $lang === \App::$Request->getLanguage()
80
            ]);
81
        }
82
83
        // compile context with lang menu
84
        $context .= $langMenu->display();
85
86
        return $context;
87
    }])
88
    ->menu(['text' => __('Gallery'), 'tab' => function() use ($form) {
89
        return '<div class="row" id="gallery-files"></div>
90
    <div class="row">
91
        <div class="col-md-8">
92
            <div class="dropzone dropzone-previews" id="ffcms-dropzone"></div>
93
        </div>
94
        <div class="col-md-4">
95
        ' . $form->fieldset()->select('poster', ['options' => [__('Not selected...')]], __("Select image from gallery as a poster for this content")) . '
96
        </div>
97
    </div><br/><br/>';
98
    }])
99
    ->menu(['text' => __('Other'), 'tab' => function() use ($form, $model) {
100
        return $form->fieldset()->boolean('display', null, __('Can users view this content or only available for administrators?')) .
101
            $form->fieldset()->boolean('important', null, __('Make this material important and stack it on top of all news?')) .
102
            $form->fieldset()->text('createdAt', ['class' => 'form-control datepick'], __('Set the date of creation or leave empty for current date')) .
103
            $form->fieldset()->select('authorId', ['options' => $model->getUserIdName(), 'optionsKey' => true, 'class' => 'selectize-option'], __('Enter author user_id or leave empty to set current user as author')) .
104
            $form->fieldset()->text('source', null, __('Set source URL if this content is copied from another website')) .
105
            $form->fieldset()->text('addRating', null, __('Add or reduce this content rating. Example: 5 gives +5 to total rating, -5 gives -5 to total'));
106
    }]);
107
108
if (!$model->isNew()) {
109
    $menu->menu(['text' => __('Comments'), 'tab' => function() use ($form, $model) {
0 ignored issues
show
The import $form is not used and could be removed.

This check looks for imports that have been defined, but are not used in the scope.

Loading history...
110
        /** @var \Ffcms\Templex\Template\Template $this */
111
        $comments = $model->getComments();
112
113
        if (!$comments || $comments->count() < 1) {
114
            return $this->bootstrap()->alert('warning', __('No comments found'));
0 ignored issues
show
Comprehensibility Best Practice introduced by zenn
The variable $this seems to be never defined.
Loading history...
115
        }
116
117
        $table = $this->table(['class' => 'table table-striped'])
118
            ->head([
119
                ['text' => '#'],
120
                ['text' => __('Message')],
121
                ['text' => __('Answers')],
122
                ['text' => __('Author')],
123
                ['text' => __('Actions'), 'properties' => ['class' => 'text-center']]
124
            ]);
125
126
        foreach ($comments as $comment) {
127
            $table->row([
128
                ['text' => $comment->id],
129
                ['text' => Text::snippet(\App::$Security->strip_tags($comment->message), 100)],
0 ignored issues
show
It seems like App::Security->strip_tags($comment->message) can also be of type array and null; however, parameter $text of Ffcms\Core\Helper\Text::snippet() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

129
                ['text' => Text::snippet(/** @scrutinizer ignore-type */ \App::$Security->strip_tags($comment->message), 100)],
Loading history...
130
                ['text' => $comment->getAnswerCount()],
131
                ['text' => Url::a(['user/update', [$comment->user_id]], ($comment->user->profile->nick ?? 'id' . $comment->user->id)), 'html' => true],
132
                ['text' => $this->bootstrap()->btngroup(['class' => 'btn-group btn-group-sm'])
0 ignored issues
show
The method btngroup() does not exist on Ffcms\Templex\Helper\Html\Bootstrap4. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

132
                ['text' => $this->bootstrap()->/** @scrutinizer ignore-call */ btngroup(['class' => 'btn-group btn-group-sm'])

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...
133
                    ->add('<i class="fa fa-pencil"></i>', ['comments/read', [$comment->id]], ['html' => true, 'class' => 'btn btn-primary', 'target' => '_blank'])
134
                    ->add('<i class="fa fa-trash-o"></i>', ['comments/delete', ['comment', $comment->id]], ['html' => true, 'class' => 'btn btn-danger', 'target' => '_blank'])
135
                    ->display(),'properties' => ['class' => 'text-center'], 'html' => true
136
                ]
137
            ]);
138
        }
139
        return (new Dom())->div(function() use ($table){
140
            return $table->display();
141
        }, ['class' => 'table-responsive']);
142
    }]);
143
}
144
145
echo $menu->display();
146
echo $form->button()->submit(__('Save'), ['class' => 'btn btn-primary mt-2']);
147
148
?>
149
150
<?= $form->field()->hidden('galleryFreeId') ?>
151
152
<?= $form->stop() ?>
153
154
<?php $this->stop() ?>
155
156
<?php $this->push('javascript') ?>
157
<!-- jquery ui plugin -->
158
<script src="<?= \App::$Alias->scriptUrl ?>/vendor/phpffcms/ffcms-assets/node_modules/jquery-ui-dist/jquery-ui.min.js"></script>
159
<!-- tinymce plugin -->
160
<?= \Widgets\Tinymce\Tinymce::widget([
161
    'config' => 'full'
162
]); ?>
163
<!-- dropzone js plugin -->
164
<script src="<?= \App::$Alias->scriptUrl ?>/vendor/phpffcms/ffcms-assets/node_modules/dropzone/dist/dropzone.js"></script>
165
<script>Dropzone.autoDiscover = false</script>
166
<!-- jquery datepicker plugin (over jquery-ui) -->
167
<script src="<?= \App::$Alias->scriptUrl ?>/vendor/phpffcms/ffcms-assets/node_modules/jquery-datepicker/jquery-datepicker.js"></script>
168
<script src="<?= \App::$Alias->scriptUrl ?>/vendor/phpffcms/ffcms-assets/node_modules/selectize/dist/js/standalone/selectize.min.js"></script>
169
<script>
170
$(document).ready(function(){
171
    var isChanged = false;
172
    var pathChanged = false;
173
    $('.datepick').datepicker({
174
        dateFormat: 'dd.mm.yy'
175
    });
176
177
    // prevent send submit if authorization session gone away
178
    $('form').submit(function () {
179
        var valid = false;
180
        $.ajax({
181
            async: false,
182
            type: 'GET',
183
            url: script_url + '/api/user/auth?lang=' + script_lang,
184
            contentType: 'json',
185
            success: function(r){
186
                if (r.status === 1)
187
                    valid = true;
188
            }
189
        });
190
        if (!valid) {
191
            alert('<?= __('Attention! Your session is deprecated. You need to make auth in new window!') ?>');
192
            return false;
193
        }
194
        window.onbeforeunload = null;
195
    });
196
197
    // listen form(input,textarea) changes event
198
    $('input,textarea').keyup(function(){
199
        isChanged = true;
200
    });
201
202
    // check if changes is saved before page is unloaded
203
    window.onbeforeunload = function(e){
204
        if (!isChanged)
205
            return;
206
207
        var msg = 'Page not saved! Please save changes!';
208
        if (typeof e === 'undefined')
209
            e = window.event;
210
211
        if (e)
212
            e.returnValue = msg;
213
        return msg;
214
    };
215
216
    // dropzone gallery file listing and display
217
    // gallery file listing
218
    $.getJSON(script_url + "/api/content/gallerylist/<?= $model->galleryFreeId ?>?lang=" + script_lang, function (data) {
219
        if (data.status !== 1)
220
            return;
221
        $.each(data.files, function (index, file) {
222
            var DropzoneObj = Dropzone.forElement('#ffcms-dropzone');
223
            var FileObj = {name: file.name, size: file.size, status: Dropzone.ADDED, accepted: true};
224
            DropzoneObj.emit('addedfile', FileObj);
225
            DropzoneObj.emit('thumbnail', FileObj, file.thumbnailUrl);
226
            DropzoneObj.emit('complete', FileObj);
227
            DropzoneObj.files.push(FileObj);
228
229
            var option = '<option value="' + file.name + '">' + file.name + '</option>';
230
            if (file.name == '<?= $model->poster ?>') {
231
                option = '<option value="' + file.name + '" selected>' + file.name + '</option>';
232
            }
233
            $('#FormContentUpdate-poster').append(option);
234
        });
235
    });
236
237
    // manual initialize & configure dropzone file uploading
238
    var DropzoneFiles = [];
239
    $('#ffcms-dropzone').dropzone({
240
        url: script_url + '/api/content/galleryupload/<?= $model->galleryFreeId ?>?lang=' + script_lang,
241
        dictDefaultMessage: '<?= __('Drop files here to upload in gallery') . '<br />' . __('(or click here)') ?>',
242
        acceptedFiles: ".jpeg,.jpg,.png,.gif,.webp",
243
        addRemoveLinks: true,
244
        removedfile: function (file) { // file remove click, lets try to remove file from server & make visual changes
245
            var serverFile = DropzoneFiles[file.name] != null ? DropzoneFiles[file.name] : file.name;
246
            $.getJSON(script_url + "/api/content/gallerydelete/<?= $model->galleryFreeId ?>?lang=" + script_lang + "&file=" + serverFile, function (data) {
247
                if (data.status === 1) {
248
                    if (file.previewElement != null)
249
                        return file.previewElement.parentNode.removeChild(file.previewElement);
250
                }
251
                return void 0;
252
            });
253
        },
254
        success: function (file, response) { // upload is successful done. Lets try to check server response & build file list
255
            // save files as array ClientFileName => ServerFileName
256
            if (response.status !== 1) {
257
                if (file.previewElement != null)
258
                    file.previewElement.parentNode.removeChild(file.previewElement);
259
                alert(response.message);
260
                return;
261
            }
262
            DropzoneFiles[file.name] = response.file.name;
263
            // add to <select> poster options
264
            var posterOption = '<option value="' + response.file.name + '">' + file.name + '</option>';
265
            $('#FormContentUpdate-poster').append(posterOption);
266
            //console.log('Client file: [' + file.name + ']/Server file:[' + response.file.name + ']');
267
        }
268
    });
269
270
    // prepare selectize features
271
    $('.tag-selectize').selectize({
272
        delimiter: ',',
273
        persist: false,
274
        create: function (input) {
275
            return {
276
                value: input,
277
                text: input
278
            }
279
        }
280
281
    });
282
    $('.selectize-option').selectize({
283
        sortField: 'text'
284
    });
285
286
});
287
</script>
288
<?php $this->stop() ?>
289