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

Apps/View/Admin/default/content/content_update.php (1 issue)

Labels
Severity
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\Type\Str;
8
use Ffcms\Templex\Helper\Html\Dom;
9
use Ffcms\Templex\Url\Url;
0 ignored issues
show
This use statement conflicts with another class in this namespace, Url. Consider defining an alias.

Let?s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let?s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/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 before OtherDir/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:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
10
11
$this->layout('_layouts/default', [
12
    'title' => __('Content edit'),
13
    'breadcrumbs' => [
14
        Url::to('main/index') => __('Main'),
15
        Url::to('application/index') => __('Applications'),
16
        Url::to('content/index') => __('Contents'),
17
        __('Content manage')
18
    ]
19
]);
20
?>
21
22
<?php $this->push('css') ?>
23
<!-- jquery ui plugin -->
24
<link rel="stylesheet" href="<?= \App::$Alias->scriptUrl ?>/vendor/phpffcms/ffcms-assets/node_modules/jquery-ui-dist/jquery-ui.min.css" />
25
<!-- dropzone css plugin -->
26
<link rel="stylesheet" href="<?= \App::$Alias->scriptUrl ?>/vendor/phpffcms/ffcms-assets/node_modules/dropzone/dist/dropzone.css" />
27
<style>
28
    .dropzone {
29
        border: 2px dashed #0087F7;
30
        border-radius: 5px;
31
        background: white;
32
    }
33
</style>
34
<?php $this->stop() ?>
35
36
<?php $this->start('body') ?>
37
<?= $this->insert('content/_tabs') ?>
38
<h1><?= __('Content manage') ?></h1>
39
<?php
40
$form = $this->form($model);
41
echo $form->start();
42
43
$menu = $this->bootstrap()->nav('ul', ['class' => 'nav-tabs'])
44
    ->menu(['text' => __('General'), 'tab' => function () use ($form) {
45
        /** @var \Ffcms\Templex\Template\Template $this */
46
        $langMenu = $this->bootstrap()->nav('ul', ['class' => 'nav-tabs']);
47
        foreach (\App::$Properties->get('languages') as $lang) {
48
            $langMenu->menu([
49
                'text' => Str::upperCase($lang),
50
                'tab' => function () use ($form, $lang) {
51
                    return $form->fieldset()->text('title.' . $lang, null, __('Fill the title of the content for current language locale')) .
52
                        '<strong>' . __('Content text') . '</strong><br />' .
53
                        $form->field()->textarea('text.' . $lang, ['class' => 'form-control wysiwyg', 'rows' => 7]);
54
                },
55
                'tabActive' => $lang === \App::$Request->getLanguage()
56
            ]);
57
        }
58
        return (new Dom())->div(function () use ($langMenu) {
59
            return $langMenu->display();
60
        }, ['class' => 'nav-border']);
61
    }, 'tabActive' => true])
62
    ->menu(['text' => __('Properties'), 'tab' => function () use ($form) {
63
        /** @var \Ffcms\Templex\Template\Template $this */
64
        $langMenu = $this->bootstrap()->nav('ul', ['class' => 'nav-tabs']);
65
        $context = $form->fieldset()->text('path', null, __('Slug of URL pathway for this content item'))
66
            . $form->fieldset()->select('categoryId', ['options' => ContentCategory::getSortedCategories(), 'optionsKey' => true, 'multiple' => null], __('Select content category'));
67
68
        foreach (\App::$Properties->get('languages') as $lang) {
69
            $langMenu->menu([
70
                'text' => Str::upperCase($lang),
71
                'tab' => function () use ($form, $lang) {
72
                    return $form->fieldset()->text('metaTitle.' . $lang, null, __('Set meta title for content page (displayed in browser head). Recommended length: 50-70 chars')).
73
                        $form->fieldset()->text('metaKeywords.' . $lang, null, __('Set meta keywords for this content (for search engine crawlers) separated by comma')).
74
                        $form->fieldset()->text('metaTitle.' . $lang, null, __('Set meta description for this content (for search engine crawlers). Recommended length: 200-250 chars'));
75
                },
76
                'tabActive' => $lang === \App::$Request->getLanguage()
77
            ]);
78
        }
79
80
        // compile context with lang menu
81
        $context .= $langMenu->display();
82
83
        return $context;
84
    }])
85
    ->menu(['text' => __('Gallery'), 'tab' => function () use ($form) {
86
        return '<div class="row" id="gallery-files"></div>
87
    <div class="row">
88
        <div class="col-md-8">
89
            <div class="dropzone dropzone-previews" id="ffcms-dropzone"></div>
90
        </div>
91
        <div class="col-md-4">
92
        ' . $form->fieldset()->select('poster', ['options' => [__('Not selected...')]], __("Select image from gallery as a poster for this content")) . '
93
        </div>
94
    </div><br/><br/>';
95
    }])
96
    ->menu(['text' => __('Other'), 'tab' => function () use ($form) {
97
        return $form->fieldset()->boolean('display', null, __('Can users view this content or only available for administrators?')) .
98
            $form->fieldset()->boolean('important', null, __('Make this material important and stack it on top of all news?')) .
99
            $form->fieldset()->text('createdAt', ['class' => 'form-control datepick'], __('Set the date of creation or leave empty for current date')) .
100
            $form->fieldset()->text('authorId', null, __('Enter author user_id or leave empty to set current user as author')) .
101
            $form->fieldset()->text('source', null, __('Set source URL if this content is copied from another website')) .
102
            $form->fieldset()->text('addRating', null, __('Add or reduce this content rating. Example: 5 gives +5 to total rating, -5 gives -5 to total'));
103
    }]);
104
echo $menu->display();
105
echo $form->button()->submit(__('Save'), ['class' => 'btn btn-primary mt-2']);
106
107
?>
108
109
<?= $form->field()->hidden('galleryFreeId') ?>
110
111
<?= $form->stop() ?>
112
113
<?php $this->stop() ?>
114
115
<?php $this->push('javascript') ?>
116
<!-- jquery ui plugin -->
117
<script src="<?= \App::$Alias->scriptUrl ?>/vendor/phpffcms/ffcms-assets/node_modules/jquery-ui-dist/jquery-ui.min.js"></script>
118
<!-- tinymce plugin -->
119
<?= \Widgets\Tinymce\Tinymce::widget([
120
    'config' => 'full'
121
]); ?>
122
<!-- dropzone js plugin -->
123
<script src="<?= \App::$Alias->scriptUrl ?>/vendor/phpffcms/ffcms-assets/node_modules/dropzone/dist/dropzone.js"></script>
124
<script>Dropzone.autoDiscover = false</script>
125
<!-- jquery datepicker plugin (over jquery-ui) -->
126
<script src="<?= \App::$Alias->scriptUrl ?>/vendor/phpffcms/ffcms-assets/node_modules/jquery-datepicker/jquery-datepicker.js"></script>
127
<script>
128
$(document).ready(function(){
129
    var isChanged = false;
130
    var pathChanged = false;
131
    $('.datepick').datepicker({
132
        dateFormat: 'dd.mm.yy'
133
    });
134
135
    // prevent send submit if authorization session gone away
136
    $('form').submit(function () {
137
        var valid = false;
138
        $.ajax({
139
            async: false,
140
            type: 'GET',
141
            url: script_url + '/api/user/auth?lang=' + script_lang,
142
            contentType: 'json',
143
            success: function(r){
144
                if (r.status === 1)
145
                    valid = true;
146
            }
147
        });
148
        if (!valid) {
149
            alert('<?= __('Attention! Your session is deprecated. You need to make auth in new window!') ?>');
150
            return false;
151
        }
152
        window.onbeforeunload = null;
153
    });
154
155
    // listen form(input,textarea) changes event
156
    $('input,textarea').keyup(function(){
157
        isChanged = true;
158
    });
159
160
    // check if changes is saved before page is unloaded
161
    window.onbeforeunload = function(e){
162
        if (!isChanged)
163
            return;
164
165
        var msg = 'Page not saved! Please save changes!';
166
        if (typeof e === 'undefined')
167
            e = window.event;
168
169
        if (e)
170
            e.returnValue = msg;
171
        return msg;
172
    };
173
174
    // dropzone gallery file listing and display
175
    // gallery file listing
176
    $.getJSON(script_url + "/api/content/gallerylist/<?= $model->galleryFreeId ?>?lang=" + script_lang, function (data) {
177
        if (data.status !== 1)
178
            return;
179
        $.each(data.files, function (index, file) {
180
            var DropzoneObj = Dropzone.forElement('#ffcms-dropzone');
181
            var FileObj = {name: file.name, size: file.size, status: Dropzone.ADDED, accepted: true};
182
            DropzoneObj.emit('addedfile', FileObj);
183
            DropzoneObj.emit('thumbnail', FileObj, file.thumbnailUrl);
184
            DropzoneObj.emit('complete', FileObj);
185
            DropzoneObj.files.push(FileObj);
186
187
            var option = '<option value="' + file.name + '">' + file.name + '</option>';
188
            if (file.name == '<?= $model->poster ?>') {
189
                option = '<option value="' + file.name + '" selected>' + file.name + '</option>';
190
            }
191
            $('#FormContentUpdate-poster').append(option);
192
        });
193
    });
194
195
    // manual initialize & configure dropzone file uploading
196
    var DropzoneFiles = [];
197
    $('#ffcms-dropzone').dropzone({
198
        url: script_url + '/api/content/galleryupload/<?= $model->galleryFreeId ?>?lang=' + script_lang,
199
        dictDefaultMessage: '<?= __('Drop files here to upload in gallery') . '<br />' . __('(or click here)') ?>',
200
        acceptedFiles: ".jpeg,.jpg,.png,.gif,.webp",
201
        addRemoveLinks: true,
202
        removedfile: function (file) { // file remove click, lets try to remove file from server & make visual changes
203
            var serverFile = DropzoneFiles[file.name] != null ? DropzoneFiles[file.name] : file.name;
204
            $.getJSON(script_url + "/api/content/gallerydelete/<?= $model->galleryFreeId ?>?lang=" + script_lang + "&file=" + serverFile, function (data) {
205
                if (data.status === 1) {
206
                    if (file.previewElement != null)
207
                        return file.previewElement.parentNode.removeChild(file.previewElement);
208
                }
209
                return void 0;
210
            });
211
        },
212
        success: function (file, response) { // upload is successful done. Lets try to check server response & build file list
213
            // save files as array ClientFileName => ServerFileName
214
            if (response.status !== 1) {
215
                if (file.previewElement != null)
216
                    file.previewElement.parentNode.removeChild(file.previewElement);
217
                alert(response.message);
218
                return;
219
            }
220
            DropzoneFiles[file.name] = response.file.name;
221
            // add to <select> poster options
222
            var posterOption = '<option value="' + response.file.name + '">' + file.name + '</option>';
223
            $('#FormContentUpdate-poster').append(posterOption);
224
            //console.log('Client file: [' + file.name + ']/Server file:[' + response.file.name + ']');
225
        }
226
    });
227
});
228
</script>
229
<?php $this->stop() ?>
230