/** * Create a FileManagerItem given a path. This function can be overriden to customize the displayed information * @return FileManagerItem */ protected function _populate_file_item($path, $folder) { $item = new FileManagerItem(); $item->path = $path; $item->folder = $folder; $item->name = basename($path); $item->is_folder = is_dir($path); if ($item->is_folder) { if (!$this->manager->allow_folders) { return false; } $item->info = str_replace('%', max(0, iterator_count(new DirectoryIterator($path)) - 2), $this->manager->strings['number_files']); } else { $item->size = filesize($path); $item->info = jQueryFM_Helper::format_size($item->size); //Extract preview if ($this->manager->image_preview_limit < 0 || $item->size < $this->manager->image_preview_limit) { $extension = strtolower(pathinfo($item->name, PATHINFO_EXTENSION)); if (in_array($extension, array('jpg', 'jpeg', 'png', 'gif', 'bmp', 'webp'))) { //Inline icon (all images in one request, but disable cache) //$item->icon = "data:image/$extension;base64," . base64_encode(file_get_contents($item->path)); $item->icon = $this->manager->ajax_endpoint . (strpos($this->manager->ajax_endpoint, '?') !== false ? '&' : '?') . http_build_query(array('action' => 'show', 'file' => $item->name, 'folder' => $item->folder)); } } } return $item; }
/** * Gets the required settings to initialize the JS file manager * @return array */ public function js_config() { $settings = array('allow_upload' => $this->allow_upload, 'allow_editing' => $this->allow_editing, 'allow_folders' => $this->allow_folders, 'allow_paste_upload' => $this->allow_paste_upload, 'max_file_size' => $this->max_size, 'max_file_size_readable' => jQueryFM_Helper::format_size($this->max_size), 'accept_file_types' => $this->accept_file_types, 'ajax_endpoint' => $this->ajax_endpoint, 'icons_url' => $this->icons_url, 'drag_selector' => $this->drag_selector, 'force_downloads' => $this->force_downloads, 'strings' => $this->strings); if ($this->preload) { $files = array(); foreach ($this->provider->read() as $f) { $files[] = $this->_export_file($f); } $settings['files'] = $files; } return $settings; }