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

Apps/View/Admin/default/content/content_update.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\Admin\Content\FormContentUpdate */
4
/** @var $this object */
5
6
use Apps\ActiveRecord\ContentCategory;
7
use Ffcms\Core\Helper\HTML\Form;
8
use Ffcms\Core\Helper\Type\Str;
9
use Ffcms\Core\Helper\Url;
10
use Ffcms\Core\Helper\HTML\Bootstrap\Nav;
11
12
$this->title = __('Content update');
13
14
$this->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
echo Ffcms\Widgets\Ckeditor\Ckeditor::widget(['targetClass' => 'wysiwyg', 'config' => 'config-full']);
22
23
?>
24
25
<?= $this->render('content/_tabs') ?>
26
27
<h1><?= __('Content manage') ?></h1>
28
<hr />
29
<?php
30
$form = new Form(
31
    $model,
32
    ['action' => ''],
33
    ['base' => '<div class="form-group"><label for="%name%" class="col-md-3 control-label"><span class="pull-right" style="padding-top: 5px;">%label%</span></label><div class="col-md-9">%item% <p class="help-block">%help%</p></div></div>']
34
);
35
36
echo $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...
37
38
$formFullFieldStructure = '<div class="form-group"><label for="%name%">%label%</label>%item% <p class="help-block">%help%</p></div>';
39
40
$generalTab = null;
41
$generalItems = [];
42
$propertiesItems = [];
43
// generate language tabs
44
foreach (\App::$Properties->get('languages') as $lang) {
45
    $generalItems[] = [
46
        'type' => 'tab',
47
        'text' => __('Lang') . ': ' . Str::upperCase($lang),
48
        'content' => $form->field('title.' . $lang, 'text', ['class' => 'form-control'], __('Please, enter the title of your material for current language locale'), $formFullFieldStructure) .
49
            $form->field('text.' . $lang, 'textarea', ['class' => 'form-control wysiwyg', 'rows' => 7, 'html' => true], null, $formFullFieldStructure),
50
        'html' => true,
51
        'active' => $lang === \App::$Request->getLanguage(),
52
        '!secure' => true
53
    ];
54
55
    $propertiesItems[] = [
56
        'type' => 'tab',
57
        'text' => __('Lang') . ': ' . Str::upperCase($lang),
58
        'content' => $form->field('metaTitle.' . $lang, 'text', ['class' => 'form-control'], __('Enter meta param title for page title. Recoomended: 50-70 characters')) .
59
            $form->field('metaKeywords.' . $lang, 'text', ['class' => 'form-control'], __('Enter meta param keywords for this content, separated by comma. Example: home, door, dog')) .
60
            $form->field('metaDescription.' . $lang, 'text', ['class' => 'form-control'], __('Enter meta param description for this content. Recommended is 100-150 characters')),
61
        'html' => true,
62
        '!secure' => true,
63
        'active' => $lang === \App::$Request->getLanguage()
64
    ];
65
}
66
67
$generalTab = Nav::display([
68
    'property' => ['class' => 'nav-pills'],
69
    'blockProperty' => ['class' => 'nav-locale-block'],
70
    'tabAnchor' => 'content-update-general-locale',
71
    'items' => $generalItems
72
]);
73
74
$propertiesTab = $form->field('path', 'text', ['class' => 'form-control'], __('Slug of URL pathway for this content item'));
75
$propertiesTab .= $form->field('categoryId', 'select', ['class' => 'form-control', 'size' => 4, 'options' => ContentCategory::getSortedCategories(), 'optionsKey' => true], __('Select content category'));
76
$propertiesTab .= Nav::display([
77
    'property' => ['class' => 'nav-pills'],
78
    'tabAnchor' => 'content-update-properties-locale',
79
    'items' => $propertiesItems
80
]);
81
82
$otherTab = $form->field('display', 'checkbox', null, __('Can users view this content or it only available for administrators?'));
83
$otherTab .= $form->field('createdAt', 'text', ['class' => 'form-control datapick'], __('Set the date of creation or less this field empty to set current'));
84
$otherTab .= $form->field('authorId', 'text', ['class' => 'form-control'], __('Enter user id to change author of this content'));
85
$otherTab .= $form->field('source', 'text', ['class' => 'form-control'], __('Set the source URL if this content is copied from someone other url'));
86
$otherTab .= $form->field('addRating', 'text', ['class' => 'form-control'], __('Add or reduce rating of this content. Example: 5 gives +5 to total rating, -5 gives -5 to total'));
87
88
$galleryTab = '<div class="row" id="gallery-files"></div>
89
90
<div class="row">
91
<div class="col-md-4">
92
            <span class="btn btn-success fileinput-button btn-block">
93
                <i class="glyphicon glyphicon-plus"></i>
94
                <span>' . __('Upload image') . '</span>
95
                <!-- The file input field used as target for the file upload widget -->
96
                <input id="fileupload" type="file" name="gallery-files" multiple>
97
            </span>
98
</div>
99
<div class="col-md-8">
100
    ' . $form->field('poster', 'select', ['options' => [__('Not selected...')], 'class' => 'form-control'], __('Select image from gallery as a poster for this content')) . '
101
</div>
102
</div><br/><br/>';
103
?>
104
<?= Nav::display([
105
    'property' => ['class' => 'nav-tabs'],
106
    'tabAnchor' => 'content-update',
107
    'items' => [
108
        ['type' => 'tab', 'text' => __('General'), 'content' => $generalTab, 'html' => true, '!secure' => true],
109
        ['type' => 'tab', 'text' => __('Properties'), 'content' => $propertiesTab, 'html' => true, '!secure' => true],
110
        ['type' => 'tab', 'text' => __('Gallery'), 'content' => $galleryTab, 'html' => true, '!secure' => true],
111
        ['type' => 'tab', 'text' => __('Other'), 'content' => $otherTab, 'html' => true, '!secure' => true]
112
    ]
113
]);?>
114
115
<?= $form->field('galleryFreeId', 'hidden') ?>
116
<?= $form->submitButton(__('Save'), ['class' => 'btn btn-primary']) ?>
117
118
<?= $form->finish() ?>
119
120
<?php
121
// load max length display plugin
122
\App::$Alias->setCustomLibrary('js', \App::$Alias->currentViewUrl . '/assets/js/plugins/maxlength.js');
123
// load datapicker plugin
124
\App::$Alias->setCustomLibrary('css', \App::$Alias->currentViewUrl . '/assets/css/plugins/datapick/datapick.css');
125
\App::$Alias->setCustomLibrary('js', \App::$Alias->currentViewUrl . '/assets/js/plugins/datapick.js');
126
// load jquery-upload plugin
127
\App::$Alias->setCustomLibrary('css', \App::$Alias->scriptUrl . '/vendor/bower/blueimp-file-upload/css/jquery.fileupload.css');
128
\App::$Alias->setCustomLibrary('js', \App::$Alias->scriptUrl . '/vendor/bower/blueimp-file-upload/js/vendor/jquery.ui.widget.js');
129
\App::$Alias->setCustomLibrary('js', \App::$Alias->scriptUrl . '/vendor/bower/blueimp-file-upload/js/jquery.iframe-transport.js');
130
\App::$Alias->setCustomLibrary('js', \App::$Alias->scriptUrl . '/vendor/bower/blueimp-file-upload/js/jquery.fileupload.js');
131
?>
132
133
<!-- dom model for gallery items -->
134
<div class="col-md-3 well hidden" id="gallery-item">
135
    <div class="text-center"><strong id="item-title"></strong></div>
136
    <img id="item-image" src="" class="img-responsive image-item"/>
137
    <div class="text-center">
138
        <a id="item-view-link" href="#" target="_blank" class="label label-info"><?= __('View') ?></a>
139
        <a id="item-delete-link" href="javascript:void(0);" class="label label-danger delete-gallery-item"><?= __('Delete') ?></a>
140
    </div>
141
</div>
142
143
<script>
144
    window.jQ.push(function(){
145
        $(function(){
146
            // onbeforeUnload hook
147
            var isChanged = false;
148
            var pathChanged = false;
149
            var galleryItem = $('#gallery-item').clone().removeClass('hidden').removeAttr('id');
150
            // init ckeditor
151
            CKEDITOR.disableAutoInline = true;
152
            // init maxlength plugin
153
            $('input[maxlength]').maxlength();
154
            // init datapick plugin
155
            $('.datapick').datepicker({
156
                format: 'dd.mm.yyyy'
157
            });
158
159
            // prevent sending form if session is closed
160
            $('form').submit(function() {
161
                var is_fail = true;
162
                $.ajax({
163
                    async: false,
164
                    type: 'GET',
165
                    url: script_url + '/api/user/auth?lang='+script_lang,
166
                    contentType: 'json',
167
                    success: function(response) {
168
                        response = jQuery.parseJSON(response);
169
                        if (response.status === 1) {
170
                            is_fail = false;
171
                        }
172
                    }
173
                });
174
                if(is_fail) {
175
                    alert('<?= __('Attention! Your session is deprecated. You need to make auth in new window!') ?>');
176
                    return false;
177
                }
178
                window.onbeforeunload = null;
179
            });
180
            // if something in form is changed - lets set isChanged
181
            $('input,textarea').keyup(function(){
182
                isChanged = true;
183
            });
184
185
            var pathObject = $('#FormContentUpdate-path');
186
            if (pathObject.val().length > 1) {
187
                pathChanged = true;
188
            }
189
190
            // pathway from title
191
            $('#FormContentUpdate-title-<?= \App::$Request->getLanguage() ?>').on('keyup', function() {
192
                if (pathChanged === true) {
193
                    return false;
194
                }
195
                pathObject.val(translit($(this).val()));
196
            });
197
198
            // gallery remove
199
            $(document).on('click', '.delete-gallery-item', function() {
200
                var itemId = (this.id);
201
                $.getJSON(script_url+"/api/content/gallerydelete/<?= $model->galleryFreeId ?>/"+(this.id)+"?lang="+script_lang, function (data){
202
                    if (data.status === 1) {
203
                        document.getElementById('image-'+itemId).remove();
204
                    } else {
205
                        alert('Could not delete this image: ' + itemId);
206
                    }
207
                });
208
            });
209
210
            // gallery file listing
211
            $.getJSON(script_url+"/api/content/gallerylist/<?= $model->galleryFreeId ?>?lang="+script_lang,
212
                function (data) {
213
                    $.each(data.files, function (index, file) {
214
                        var gItem = galleryItem.clone();
215
                        // make dom for gallery item
216
                        gItem.attr('id', 'image-'+file.name);
217
                        gItem.find('#item-title').text(file.name).removeAttr('id');
218
                        gItem.find('#item-image').attr('src', script_url+file.thumbnailUrl).removeAttr('id');
219
                        gItem.find('#item-view-link').attr('href', script_url + file.url).removeAttr('id');
220
                        gItem.find('#item-delete-link').attr('id', file.name);
221
                        $('#gallery-files').append(gItem);
222
223
                        var option = '<option value="'+file.name+'">'+file.name+'</option>';
224
                        if (file.name == '<?= $model->poster ?>') {
225
                            option = '<option value="'+file.name+'" selected>'+file.name+'</option>';
226
                        }
227
                        $('#FormContentUpdate-poster').append(option);
228
                    });
229
                });
230
231
            // gallery file upload
232
            $('#fileupload').fileupload({
233
                url: script_url+'/api/content/galleryupload/<?= $model->galleryFreeId ?>?lang='+script_lang,
234
                dataType: 'json',
235
                done: function (e, data) {
236
                    if (data.result.status !== 1) {
237
                        alert(data.result.message);
238
                    }
239
                    $.each(data.result.files, function (index, file) {
240
                        var gItem = galleryItem.clone();
241
                        // make dom for gallery item
242
                        gItem.attr('id', 'image-'+file.name);
243
                        gItem.find('#item-title').text(file.name).removeAttr('id');
244
                        gItem.find('#item-image').attr('src', script_url+file.thumbnailUrl).removeAttr('id');
245
                        gItem.find('#item-view-link').attr('href', script_url + file.url).removeAttr('id');
246
                        gItem.find('#item-delete-link').attr('id', file.name);
247
                        $('#gallery-files').append(gItem);
248
249
                        var option = '<option value="'+file.name+'">'+file.name+'</option>';
250
                        if (file.name == '<?= $model->poster ?>') {
251
                            option = '<option value="'+file.name+'" selected>'+file.name+'</option>';
252
                        }
253
                        $('#FormContentUpdate-poster').append(option);
254
                    });
255
                },
256
                progressall: function (e, data) {
257
                    var progress = parseInt(data.loaded / data.total * 100, 10);
258
                    $('#progress .progress-bar').css(
259
                        'width',
260
                        progress + '%'
261
                    );
262
                }
263
            }).prop('disabled', !$.support.fileInput)
264
                .parent().addClass($.support.fileInput ? undefined : 'disabled');
265
266
            window.onbeforeunload = function (evt) {
267
                if (!isChanged) return;
268
                var message = "Page is not saved!";
269
                if (typeof evt == "undefined") {
270
                    evt = window.event;
271
                }
272
                if (evt) {
273
                    evt.returnValue = message;
274
                }
275
                return message;
276
            }
277
        });
278
    });
279
</script>