예제 #1
0
    /**
     * Main view
     */
    public function _default()
    {
        // We can show only files if user is locked to current folder
        $files_only = isset($_GET['files_only']);
        // We can set range of allowed file extensions to be uploaded
        $allowed_extensions = isset($_GET['allowed_extensions']) ? explode(',', $_GET['allowed_extensions']) : [];
        // If page is shown in modal widow
        if (IS_AJAX_REQUEST) {
            ob_start();
        }
        // Directory to be shown is supplied from url
        $dir = isset($_GET['path']) ? $_GET['path'] : NULL;
        // Maybe user hav access only to public folder, so we have to check and change folder
        if (Users::getInstance()->getGroupData('filemanager_limited') && stripos($dir, DIR_PUBLIC_URL) === false) {
            $dir = DIR_PUBLIC_URL;
        }
        // If no dir - set default directory for public files
        if (!$dir) {
            $dir = DIR_PUBLIC_URL;
        }
        // Check that we have no slash as first symbol
        if ($dir[0] === '/') {
            $dir = substr($dir, 1);
        }
        // Create requested directory if not exists
        if (!file_exists(DIR_BASE . $dir)) {
            FileSystem::mkDir(DIR_BASE . $dir);
        }
        // Create list of folders and files in requested location
        $file_list = $dir_list = [];
        foreach (array_diff(scandir(DIR_BASE . $dir), ['.', '..']) as $v) {
            $p = $dir . $v;
            if (is_dir(DIR_BASE . $p)) {
                $dir_list[] = $p . '/';
            } else {
                $file_list[] = $p;
            }
        }
        // Generate path to upper folder
        $tmp = [];
        $path_up = explode('/', $dir);
        foreach ($path_up as $v) {
            if ($v) {
                $tmp[] = $v;
            }
        }
        $path_up = $tmp;
        array_pop($path_up);
        $path_up = '/' . implode('/', $path_up) . '/';
        // Show current path and generate links on page parts
        $path_links = [];
        $tmp = '/';
        foreach (explode('/', $dir) as $v) {
            if (trim($v) == '') {
                continue;
            }
            $tmp .= $v . '/';
            $path_links[] = '<a onclick="filemanager_helpers.loadDirectory(this); return false;" href="?p=' . P . '&nomenu&path=' . $tmp . '">' . $v . '</a>';
        }
        // Show top bar if we are allowed to view folders
        if (!$files_only) {
            ?>
            <!--suppress JSUnresolvedFunction -->
            <div style="padding: 10px; position: relative">
                <a onclick="filemanager_helpers.show_create_directory(); return false;" href="?p=<?php 
            echo P;
            ?>
&do=create_directory&nomenu&path=<?php 
            echo $dir;
            ?>
">Create directory</a>
                &nbsp;&nbsp;|&nbsp;&nbsp;
                <a href="?p=<?php 
            echo P;
            ?>
&do=filemanager&nomenu&path=<?php 
            echo $path_up;
            ?>
" onclick="filemanager_helpers.loadDirectory(this); return false;">Go up</a>
                &nbsp;&nbsp;|&nbsp;&nbsp;
                Current path: /<?php 
            echo implode('/', $path_links);
            ?>
                <hr>
                <a onclick="filemanager_helpers.show_create_file(); return false;" href="?p=<?php 
            echo P;
            ?>
&do=create_file&nomenu&path=<?php 
            echo $dir;
            ?>
">Create file</a>
                &nbsp;&nbsp;|&nbsp;&nbsp;
                Filter by name&nbsp;&nbsp;<input type="text" id="filter_name" placeholder="File or folder name">
                <hr>
                <span id="multiple_commands">
                    <var onclick="multiple.download(this)"><?php 
            echo __('Download');
            ?>
</var>
                    &nbsp;&nbsp;
                    <var onclick="if (confirm('<?php 
            echo __('Are you sure?');
            ?>
')) multiple.delete_files()"><?php 
            echo __('Delete');
            ?>
</var>
                    &nbsp;&nbsp;
                    <var onclick="multiple.copy(this)"><?php 
            echo __('Copy');
            ?>
</var>
                    &nbsp;&nbsp;
                    <var id="multiple_paste" style="display:none;" onclick="multiple.paste(this)"><?php 
            echo __('Paste');
            ?>
</var>
                </span>
                <hr>
                <div style="position: absolute; top: 0; right: 0; width: 300px; z-index: 10">
                    <img width="300" id="filemanager_current_image" style="display: none" src="<?php 
            echo DIR_CMS_IMAGES_URL;
            ?>
_.gif">
                </div>
            </div>
        <?php 
        }
        ?>

        <div style="min-height: 350px; overflow-y: auto; padding: 10px" id="file_list_zone">
            <table cellspacing="0" cellpadding="0" style="line-height:20px">
                <?php 
        if (!$files_only) {
            ?>
                    <tr>
                        <td width="100%"></td>
                        <td></td>
                        <td width="75"></td>
                        <td width="30"></td>
                    </tr>
                    <tr>
                        <td colspan="5">Folders:</td>
                    </tr>
                    <?php 
            foreach ($dir_list as $k => $v) {
                ?>
                        <?php 
                if ($v[0] != '/') {
                    $v = '/' . $v;
                }
                ?>
                        <tr class="bg_mouseover toggle_checkbox">
                            <td>
                                <input class="cb_hide" type="checkbox" name="<?php 
                echo $v;
                ?>
" value="">
                                &nbsp;
                                <a class="dir_context" href="?p=<?php 
                echo P;
                ?>
&do=filemanager&nomenu&path=<?php 
                echo $v;
                ?>
" onclick="return setSelectedToInput(this);" data-path="<?php 
                echo $v;
                ?>
" ondblclick="filemanager_helpers.loadDirectory(this); return false;" data-name="<?php 
                echo basename($v);
                ?>
"><?php 
                echo basename($v);
                ?>
</a>
                            </td>
                            <td></td>
                            <td></td>
                            <td align="center">
                                <a href="?p=<?php 
                echo P;
                ?>
&do=_delete&path=<?php 
                echo $v;
                ?>
" onclick="filemanager_helpers.delete_files('<?php 
                echo $v;
                ?>
'); return false;">x</a>
                            </td>
                        </tr>
                    <?php 
            }
            ?>
                    <tr>
                        <td colspan="5">&nbsp;</td>
                    </tr>
                <?php 
        }
        ?>
                <tr>
                    <td colspan="5">Files:</td>
                </tr>
                <?php 
        foreach ($file_list as $k => $v) {
            // Need to have slash in name to set absolute paths
            if ($v[0] != '/') {
                $v = '/' . $v;
            }
            // Check special file type to show context menu
            $ext = strtolower(pathinfo($v, PATHINFO_EXTENSION));
            $type_by_extension = '';
            if (in_array($ext, ['txt', 'html', 'php', 'js', 'htaccess', 'css', ''])) {
                $type_by_extension = '_text';
            } elseif (in_array(strtolower($ext), ['bmp', 'jpg', 'png', 'jpeg', 'gif'])) {
                $type_by_extension = '_img';
            } elseif (in_array(strtolower($ext), ['zip'])) {
                $type_by_extension = '_archive';
            }
            ?>
                    <tr class="bg_mouseover toggle_checkbox">
                        <td>
                            <input class="cb_hide" type="checkbox" name="<?php 
            echo $v;
            ?>
" value="">
                            &nbsp;
                            <a class="file_context<?php 
            echo $type_by_extension;
            ?>
" href="" onclick="return setSelectedToInput(this);" data-path="<?php 
            echo $v;
            ?>
" ondblclick="done();"
                                <?php 
            if ($type_by_extension == '_img') {
                ?>
                                    onmouseover="$('#filemanager_current_image').attr('src', '<?php 
                echo $v;
                ?>
').show()"
                                    onmouseout="$('#filemanager_current_image').attr('src', '<?php 
                echo DIR_CMS_IMAGES_URL;
                ?>
_.gif').hide()"
                                <?php 
            }
            ?>
                                data-name="<?php 
            echo basename($v);
            ?>
"><?php 
            echo basename($v);
            ?>
</a>
                        </td>
                        <td></td>
                        <td><?php 
            echo Converter::formatDataSize(filesize(DIR_BASE . $v));
            ?>
</td>
                        <td align="center">
                            <a href="?p=<?php 
            echo P;
            ?>
&do=_delete&path=<?php 
            echo $v;
            ?>
" onclick="filemanager_helpers.delete_files('<?php 
            echo $v;
            ?>
'); return false;">x</a>
                        </td>
                    </tr>
                <?php 
        }
        ?>
            </table>




            <?php 
        if ($files_only) {
            // Stop further rendering if we can locked to see only files
            echo ob_get_clean();
            die;
        }
        ?>
        </div>
        <br>
        <div style="margin: auto 5px">
        <?php 
        // Simple upload form
        echo CmsForm::getInstance()->addField('Selected file (<a href="" onclick="done(); return false">Set</a>)', CmsInputText::getInstance('filename')->disableBackupBlock()->enableReadOnly());
        ?>
        </div>
        <?php 
        // Get maximum allowed size of chunk of uploaded file
        $max_upload_file = $max_post = Converter::formatIniSize(ini_get('post_max_size'));
        $max_upload = Converter::formatIniSize(ini_get('upload_max_filesize'));
        if ($max_upload < $max_upload_file) {
            $max_upload_file = $max_upload;
        }
        // Modern upload form with multiple file selects and large file uploads
        $upload_form = CmsForm::getInstance()->setSubmitButton(CmsButton::getInstance('Upload')->setElementIdAttribute('upload_files'))->setEnctype(CmsForm::ENCTYPE_MULTIPART)->setAction('?p=' . P . '&do=_upload')->addField('Upload files', CmsHtml::getInstance('file')->enableMultiple()->setValue('
        <div id="filelist">
            <input id="file" type="file" name="file[]" class="form-control" multiple="">
        </div>
        <div id="container">
            <a id="pickfiles" href="javascript:;" style="display: block; letter-spacing: 3px; padding-top: 15px; height: 50px; font-size: 13px; text-align: center; border: 1px solid black">Click to select files, or drag files here</a>
        </div>
        <pre id="console" style="display: none"></pre>'))->addField('Extract .zip files', CmsCheckbox::getInstance('extract')->setIsChecked())->addField('If file exists', CmsRadioBox::getInstance('exists')->setRadioButtons(['skip' => 'Skip upload', 'overwrite' => 'Overwrite', 'rename' => 'Make new name'])->setSelected('skip'));
        // Render textarea with form
        echo $upload_form;
        ?>

        <script>
            // Choose folder or file
            function setSelectedToInput(link) {
                $('a[data-path="' + link.getAttribute('data-path') + '"')
                    .parents('#modal-popup_inner')
                    .find('#filename')
                    .val(link.getAttribute('data-path'));

                return false;
            }
            // Set value in opener and close window
            function done() {
                var filenameInput = $('#filename'),
                    modalWindow = filenameInput.parents('#modal-popup_inner');

                modalWindow.trigger('popup:return_result', [filenameInput.val()]);
                modalWindow.trigger('popup:close');
            }

            // Main Container
            var _ = {
                con: {
                    close: function () {
                        $('#con_bg_in').hide().width(400).height(200).css('margin-left', -200);
                        $('#con_bg, #con_bg_in, #con_rename, #con_file_create, #con_dir_create').hide();
                    },
                    open: function () {
                        var $w = $(window);
                        var w_h = $w.height();
                        $('#con_bg').show().width('100%').height(w_h);
                        $('#con_bg_in').show();
                    }
                }
            };

            // Bind checkbox events
            function events_on_checkboxes() {
                // Checkboxes toggle
                $('.toggle_checkbox input').change(function () {
                    var $container = $('#multiple_commands');
                    if ($('.toggle_checkbox input:checked').length > 0) {
                        $container.show();
                    } else {
                        $container.hide();
                    }
                });

                $('#con_bg').click(function () {
                    _.con.close();
                });
            }
            events_on_checkboxes();

            // Filter by name
            $('#filter_name').focus().keyup(function (el) {
                var value = el.target.value;
                if (!value.length) {
                    $('a[data-name').closest('tr').show();
                } else {
                    $('a[data-name').closest('tr').hide();
                }

                $('a[data-name*="' + value + '"]').closest('tr').show();
            });

            // Actions with multiple selected items
            var multiple = {
                // Start storage
                init: function () {
                    var storage = this.getLocalStorage();
                    var items_copy = storage.get('multiple_copy_items');

                    if (items_copy) {
                        $('#multiple_paste').show();
                    }
                },
                // Get list of selected items
                get_selected_item_sources: function () {
                    var items = [];
                    $('.toggle_checkbox input:checked').each(function (k, v) {
                        items.push($(v).attr('name'));
                    });
                    return items;
                },
                // Show / hide available button
                toggleButton: function (el) {
                    $(el).stop().fadeOut('fast', function () {
                        $(el).fadeIn('fast');
                    });
                },
                getLocalStorage: function () {
                    return new Storage('filemanager_multiple');
                },
                // Delete files from server
                delete_files: function () {
                    var items = this.get_selected_item_sources();

                    $.post('?p=filemanager&nomenu&do=_multiple_delete&ajax' + Date.now(),
                        {pathes: items},
                        function () {
                            filemanager_helpers.reloadFiles();
                        });
                },
                // Delete files from server
                download: function () {
                    var items = this.get_selected_item_sources();

                    $.post('?p=filemanager&nomenu&do=_multiple_download&ajax' + Date.now(),
                        {pathes: items},
                        function (link) {
                            location.href = link;
                        });
                },
                // Copy selected items
                copy: function (el) {
                    // Save item paths into buffer
                    var items = this.get_selected_item_sources();
                    var storage = this.getLocalStorage();
                    storage.set('multiple_copy_items', items);
                    this.toggleButton(el);
                    this.init();
                },
                // Paste (create copied)
                paste: function (el) {
                    var storage = this.getLocalStorage();

                    // Check copied items
                    var items = storage.get('multiple_copy_items');
                    if (items) {
                        $.get('?p=filemanager&nomenu&do=_multiple_copy&ajax' + Date.now(),
                            {pathes: items, current_path: '<?php 
        echo $dir;
        ?>
'},
                            function () {
                                filemanager_helpers.reloadFiles();
                            }
                        );
                    }
                    this.toggleButton(el);
                }
            };
            multiple.init();

            // File uploader plugin with chunk upload possibility, drag and drop, and multiple selectes
            var uploader = new plupload.Uploader({
                runtimes: 'html5,flash,silverlight,html4',
                browse_button: 'pickfiles',
                max_retries: 3,
                chunk_size: '<?php 
        echo $max_upload_file;
        ?>
',
                container: document.getElementById('container'),
                drop_element: document.getElementById('container'),
                url: "?p=<?php 
        echo P;
        ?>
&do=_upload_multiple&path=<?php 
        echo $dir;
        ?>
&allowed_extensions=<?php 
        echo implode(',', $allowed_extensions);
        ?>
",

                // Flash settings
                flash_swf_url: '<?php 
        echo DIR_CMS_SCRIPTS_URL;
        ?>
plupload/Moxie.swf',

                // Silverlight settings
                silverlight_xap_url: '<?php 
        echo DIR_CMS_SCRIPTS_URL;
        ?>
plupload/Moxie.xap',

                init: {
                    PostInit: function () {
                        document.getElementById('filelist').innerHTML = '';

                        document.getElementById('upload_files').onclick = function () {
                            uploader.start();
                            return false;
                        };
                    },

                    FilesAdded: function (up, files) {
                        plupload.each(files, function (file) {
                            document.getElementById('filelist').innerHTML += '<div onclick="filemanager_helpers.removeFile(\''+ file.id +'\')" style="cursor: no-drop" id="' + file.id + '"><var id="deleteFile' + file.id + '">X</var>&nbsp;&nbsp;&nbsp; ' + file.name + ' (' + plupload.formatSize(file.size) + ') <b></b></div>';
                            filemanager_helpers.upload_object = up;
                            filemanager_helpers.file_handlers[file.id] = file;
                        });
                    },

                    UploadProgress: function (up, file) {
                        document.getElementById(file.id).getElementsByTagName('b')[0].innerHTML = '<span style="float: right; color: #fff; text-align: center; display: inline-block; width: 100px"><span style="background: green; width: '+ file.percent +'%; display: inline-block">' + file.percent + "%</span></span>";
                    },

                    Error: function (up, err) {
                        document.getElementById('console').style.display = 'block';
                        document.getElementById('console').innerHTML += "\nError #" + err.code + ": " + err.message;
                    },

                    UploadComplete: function () { // (up, err)
                        filemanager_helpers.reloadFiles();
                    },

                    BeforeUpload: function () { // (up, err)
                        uploader.setOption('url', "?p=<?php 
        echo P;
        ?>
&do=_upload_multiple&path=<?php 
        echo $dir;
        ?>
&allowed_extensions=<?php 
        echo implode(',', $allowed_extensions);
        ?>
&exists=" + $('input[name=exists]:checked').val() + '&extract=' + $('input[name=extract]:checked').length + '&cache=<?php 
        echo NOW;
        ?>
');
                    }
                }
            });

            // Helper function for uploader plugin
            var filemanager_helpers = {
                upload_object: null,
                file_handlers: {},
                removeFile: function(file_id) {
                    var file = filemanager_helpers.file_handlers[file_id];
                    filemanager_helpers.upload_object.removeFile(file);
                    $("#" + file_id).remove();
                },
                reloadFiles: function() {
                    $('#file_list_zone').load(filemanager_helpers.current_url + '&files_only');
                    setTimeout(function() {
                        events_on_checkboxes();
                        ajax_toasters.request_new_messages();
                        filemanager_helpers.reinit_context_menues();
                    }, 100);
                },
                current_url: '<?php 
        echo SELF;
        ?>
',
                loadDirectory: function (link) {
                    // From CKEditor - in separate window
                    if ('<?php 
        echo (int) isset($_GET['CKEditor']);
        ?>
' == '1') {
                        window.location.href = link.href + '&CKEditor=<?php 
        echo isset($_GET['CKEditor']) ? $_GET['CKEditor'] : '';
        ?>
&CKEditorFuncNum=<?php 
        echo isset($_GET['CKEditorFuncNum']) ? $_GET['CKEditorFuncNum'] : '';
        ?>
&langCode=<?php 
        echo isset($_GET['langCode']) ? $_GET['langCode'] : '';
        ?>
';
                    } else {
                        // Ajax
                        filemanager_helpers.current_url = link.href;
                        $(link).parents('#modal-popup_inner').trigger('popup:load_content', [link.href]);
                    }

                    return false;
                },
                show_create_directory: function() {
                    _.con.open();
                    $('#con_file_create').hide();
                    $('#con_dir_create').show();
                },
                show_create_file: function() {
                    _.con.open();
                    $('#con_dir_create').hide();
                    $('#con_file_create').show();
                },
                delete_files: function(path) {
                    if (!confirm('<?php 
        echo __('Are you sure?');
        ?>
')) return false;

                    $.get("?p=<?php 
        echo P;
        ?>
&do=_delete&path="+ path, {
                        'path': path
                    }, function () {
                        filemanager_helpers.reloadFiles();
                    });
                },
                reinit_context_menues: function() {
                    // Move all contextMenues to the BODY element - to calculate proper CSS
                    if ($('body > .contextMenu').length < 1) {
                        $('.contextMenu').appendTo(document.body);
                    } else {
                        // Delete new from ajaxed data
                        $('.contextMenu').not('body > .contextMenu').remove();
                    }
                }
            };

            uploader.init();
            filemanager_helpers.reinit_context_menues();
        </script><?php 
        if (IS_AJAX_REQUEST) {
            echo ob_get_clean();
            die;
        }
    }
예제 #2
0
 /**
  * @param $table
  * @param array $params [data, action, button, fields[], unset[], order[]]
  * @return CmsForm
  */
 public static function outputForm($table, array $params = [])
 {
     // Maybe only one argument
     if (!$params) {
         $params['db_table'] = $table;
     }
     // Convert data to array
     if (isset($params['data']) && is_object($params['data'])) {
         /** @var Entity $obj */
         $obj = $params['data'];
         $params['data'] = $obj->getAsArray();
     }
     if (!isset($params['fields'])) {
         $params['fields'] = [];
     } else {
         $params['fields'] = self::normalizeFields($params['fields']);
     }
     // Generate fields from DB and combine with provided params
     if (isset($params['combine']) && $params['combine']) {
         $sort_order = isset($params['order']) ? $params['order'] : array_keys($params['fields']);
         $params['fields'] = array_merge(self::combineParamsFromDB($table, $sort_order), $params['fields']);
     }
     if (isset($params['unset'])) {
         foreach ($params['unset'] as $v) {
             unset($params['fields'][$v]);
         }
     }
     // Generate form
     $form = new CmsForm();
     if (!isset($params['action'])) {
         $tmp = $_GET;
         $tmp['do'] = '_' . $tmp['do'];
         $params['action'] = urldecode('?' . http_build_query($tmp));
     }
     if (isset($params['action'])) {
         $form->setAction($params['action']);
     }
     if (isset($params['title'])) {
         $form->setFormTitle($params['title']);
     }
     if (isset($params['button'])) {
         $form->setSubmitButton($params['button']);
     }
     if (isset($params['collapsed'])) {
         $form->setCollapsed($params['collapsed']);
     }
     if (isset($params['ajax']) && $params['ajax']) {
         $form->enableAjax();
     }
     if (isset($params['cancel']) && $params['cancel']) {
         if (is_bool($params['cancel'])) {
             $params['cancel'] = __('Cancel');
         }
         $form->setCancelButton($params['cancel']);
     }
     if (isset($params['fields'])) {
         foreach ($params['fields'] as $key => $field) {
             if (!is_array($field)) {
                 $key = $field;
             }
             // Field label
             if (isset($field['title'])) {
                 $name = $field['title'];
             } elseif (isset($field['name'])) {
                 $name = $field['name'];
             } else {
                 $name = Converter::symb2Ttl($key);
             }
             //
             if (isset($params['field_key_prefix'])) {
                 $key = $params['field_key_prefix'] . $key;
             }
             // Input type
             $cms_field = NULL;
             // Known types
             if (!isset($field['type']) && isset($field['options'])) {
                 $field['type'] = 'select';
             }
             if (!isset($field['type']) && isset($field['checked'])) {
                 $field['type'] = 'checkbox';
             }
             if (!isset($field['type']) && isset($field['rows'])) {
                 $field['type'] = 'textarea';
             }
             // Set field object
             if (!isset($field['type']) || $field['type'] == 'text') {
                 $cms_field = CmsInputText::getInstance($key);
             } elseif ($field['type'] == 'select' && (!isset($field['multi']) || isset($field['multi']) && !$field['multi'])) {
                 $cms_field = CmsSelect::getInstance($key);
                 // Selected value
                 if (isset($field['value'])) {
                     $cms_field->setSelected($field['value']);
                 }
             } elseif ($field['type'] == 'multiselect' || $field['type'] == 'multi' || isset($field['multi']) && $field['multi']) {
                 $cms_field = CmsMultipleSelect::getInstance($key);
             } elseif ($field['type'] == 'checkbox_list') {
                 $cms_field = CmsCheckboxList::getInstance($key);
                 // Set checked checkboxes in list
                 if (isset($params['data'][$key])) {
                     $field['checked'] = (array) $params['data'][$key];
                 }
             } elseif ($field['type'] == 'datetime' || $field['type'] == 'time' || $field['type'] == 'date') {
                 // Options for JS datepicker plugin
                 if (!isset($field['options'])) {
                     $field['options'] = [];
                 }
                 $cms_field = CmsInputText::getInstance($key)->enableDateTimePicker($field['options']);
                 // Default time
                 if (!isset($params['data'][$key])) {
                     $params['data'][$key] = NOW;
                 }
                 // Set value from db in required format from timestamp
                 if (isset($params['data'][$key]) && ctype_digit((string) $params['data'][$key])) {
                     $params['data'][$key] = date('Y-m-d H:i', $params['data'][$key]);
                     // Convert ts to date
                 }
                 if (isset($field['format'])) {
                     $cms_field->setFormat($field['format']);
                 }
             } elseif ($field['type'] == 'password') {
                 $cms_field = CmsInputPassword::getInstance($key);
             } elseif ($field['type'] == 'row') {
                 if (isset($field['value'])) {
                     $cms_field = CmsRow::getInstance($key)->value($field['value']);
                 }
             } elseif ($field['type'] == 'random') {
                 $cms_field = CmsInputTextRandom::getInstance($key);
             } elseif ($field['type'] == 'checkbox') {
                 $cms_field = CmsCheckbox::getInstance($key);
                 // checked box
                 if (isset($field['value']) && $field['value']) {
                     $cms_field->setChecked(true);
                 }
             } elseif ($field['type'] == 'radio_group') {
                 $cms_field = CmsRadioBox::getInstance($key);
             } elseif ($field['type'] == 'email') {
                 $cms_field = CmsInputEmail::getInstance($key);
             } elseif ($field['type'] == 'textarea' || $field['type'] == 'text') {
                 $cms_field = CmsTextarea::getInstance($key);
             } elseif ($field['type'] == 'number' || $field['type'] == 'digit' || $field['type'] == 'int') {
                 $cms_field = CmsInputNumber::getInstance($key);
             } elseif ($field['type'] == 'datalist') {
                 $cms_field = CmsInputDataList::getInstance($key);
             } elseif ($field['type'] == 'hidden') {
                 $cms_field = CmsInputHidden::getInstance($key);
             } elseif ($field['type'] == 'file') {
                 $cms_field = CmsInputFile::getInstance($key);
             } elseif ($field['type'] == 'color') {
                 $cms_field = CmsInputColor::getInstance($key);
             }
             if ($cms_field) {
                 // Extra params
                 if (isset($field['options']) && is_array($field['options'])) {
                     $cms_field->setOptions($field['options']);
                 }
                 if (isset($field['options']) && $field['type'] == 'checkbox_list') {
                     $cms_field->setCheckboxes($field['options']);
                 }
                 if (isset($field['buttons']) && $field['type'] == 'radio_group') {
                     $cms_field->setRadioButtons($field['buttons']);
                     if (isset($params['data'][$key])) {
                         $cms_field->setSelected($params['data'][$key]);
                     }
                 }
                 if (isset($field['checked'])) {
                     $cms_field->setChecked($field['checked']);
                 }
                 if (isset($field['value'])) {
                     $cms_field->value($field['value']);
                 }
                 if (isset($field['selected'])) {
                     $cms_field->setSelected($field['selected']);
                 }
                 if (isset($field['multiple'])) {
                     $cms_field->multiple(true);
                 }
                 if (isset($field['multilng'])) {
                     $cms_field->enableMultiLng();
                 }
                 if (isset($field['translation'])) {
                     $cms_field->enableMultiLng();
                 }
                 if (isset($field['required'])) {
                     $cms_field->validateRequired();
                 }
                 if (isset($field['uid'])) {
                     $cms_field->setUid($field['uid']);
                 }
                 // Disable custom css styles for select elements
                 if (isset($field['disable_custom_plugin'])) {
                     $cms_field->disableCustomStyled();
                 }
                 // Autogenerated slug
                 if (isset($field['uid'])) {
                     $to = $field['uid'];
                     // Check if we need to change key for current language translation
                     if (isset($params['fields'][$field['uid']]['translation']) && $params['fields'][$field['uid']]['translation']) {
                         $to = $to . '_' . LNG . '_';
                     }
                     $cms_field->enableSlugGenerationUidFromField($key, $to);
                 }
                 if (isset($field['readonly']) && $field['readonly']) {
                     $cms_field->readonly(true);
                 }
                 if (isset($field['html'])) {
                     $cms_field->html($field['html']);
                 }
                 if (isset($field['rows'])) {
                     $cms_field->rows($field['rows']);
                 }
                 if (isset($field['backup'])) {
                     $cms_field->backup($field['backup']);
                 }
                 if (isset($field['hint'])) {
                     $cms_field->setHintText($field['hint']);
                 }
                 if (isset($field['min'])) {
                     $cms_field->min($field['min']);
                 }
                 if (isset($field['max'])) {
                     $cms_field->max($field['max']);
                 }
                 if (isset($field['step'])) {
                     $cms_field->step($field['step']);
                 }
                 if (isset($field['reveal'])) {
                     $cms_field->reveal($field['reveal']);
                 }
                 if (isset($field['maxlength'])) {
                     $cms_field->maxlength($field['maxlength']);
                 }
                 // Editors
                 if (isset($field['edit'])) {
                     switch ($field['edit']) {
                         default:
                             dump('Widget for edit type "' . $field['edit'] . '" not found');
                             break;
                             // Visual editor
                         // Visual editor
                         case 'wysiwyg':
                             $cms_field->enableWysiwyg();
                             break;
                             // Google map for choosing coordinates
                         // Google map for choosing coordinates
                         case 'map':
                             $cms_field->enableGoogleMap();
                             break;
                             // Structure pages
                         // Structure pages
                         case 'pages':
                             $cms_field->setWidget(new SitemapPages());
                             break;
                             // SVG image handling for choosing polygon section
                         // SVG image handling for choosing polygon section
                         case 'svg_map':
                             // We need path to set for widget
                             if (!isset($params['fields'][$key . '_path'])) {
                                 dump('Form must have field "' . $key . '_path" with path for svg image.');
                             }
                             $path = '';
                             if (isset($params['data'][$key . '_path'])) {
                                 $path = $params['data'][$key . '_path'];
                             }
                             $svg_map = new SvgMap();
                             $svg_map->setSvgImagePath($path);
                             $cms_field->setWidget($svg_map);
                             break;
                             // Integrated filemanager
                         // Integrated filemanager
                         case 'files':
                         case 'filemanager':
                             $file_manager = FileManager::getInstance();
                             // Default path for filemanager
                             if (isset($field['path'])) {
                                 $file_manager->path($field['path']);
                             }
                             // Allow upload of only these extensions
                             if (isset($field['allowed_extensions'])) {
                                 $file_manager->setAllowedExtensions($field['allowed_extensions']);
                             }
                             // Refresh page after filemanager is closed
                             if (isset($field['reload'])) {
                                 $file_manager->enablePageReloadOnClose();
                             }
                             $cms_field->setWidget($file_manager);
                             break;
                             // Structure pages
                         // Structure pages
                         case 'custom':
                             $widget = Custom::getInstance();
                             if (isset($field['url'])) {
                                 $widget->setModalPopupAjaxUrl($field['url']);
                             }
                             $cms_field->setWidget($widget);
                             break;
                     }
                 }
                 // Validators
                 if (isset($field['validate'])) {
                     if (isset($field['validate']['required']) || in_array('required', $field['validate'])) {
                         $cms_field->validateRequired();
                     }
                     if (isset($field['validate']['is_digit']) || in_array('is_digit', $field['validate'])) {
                         $cms_field->validateDigits();
                     }
                     if (isset($field['validate']['number']) || in_array('number', $field['validate'])) {
                         $cms_field->validateNumber();
                     }
                     if (isset($field['validate']['alphanum']) || in_array('alphanum', $field['validate'])) {
                         $cms_field->validateAlphaNumeric();
                     }
                     if (isset($field['validate']['url']) || in_array('url', $field['validate'])) {
                         $cms_field->validateUrl();
                     }
                     if (isset($field['validate']['email']) || in_array('email', $field['validate'])) {
                         $cms_field->validateEmail();
                     }
                 }
                 $form->addField($name, $cms_field);
             }
         }
     }
     if (isset($params['data'])) {
         $form->addData($params['data']);
     }
     return $form;
 }