/** View one */ public function view() { if (!isset($_GET['id']) || !ctype_digit((string) $_GET['id'])) { return; } $feedback_id = $_GET['id']; $feedback = new Feedback($feedback_id); if (!$feedback) { return; } $feedback_data = $feedback->getAsArray(); $form = CmsForm::getInstance()->outputTagForm(false); $feedback_data['date_created'] = date(CFG_CMS_DATETIME_FORMAT, $feedback_data['date_created']); unset($feedback_data['id']); unset($feedback_data['client_id']); foreach ($feedback_data as $k => $item) { if (!is_string($item)) { continue; } $form->addField(Converter::symb2Ttl($k), CmsHtml::getInstance($k)->value(htmlspecialchars($item, ENT_QUOTES))); } echo $form; }
/** * 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> | <a href="?p=<?php echo P; ?> &do=filemanager&nomenu&path=<?php echo $path_up; ?> " onclick="filemanager_helpers.loadDirectory(this); return false;">Go up</a> | 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> | Filter by name <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> <var onclick="if (confirm('<?php echo __('Are you sure?'); ?> ')) multiple.delete_files()"><?php echo __('Delete'); ?> </var> <var onclick="multiple.copy(this)"><?php echo __('Copy'); ?> </var> <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=""> <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"> </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=""> <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> ' + 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; } }