/** * @return void */ private function pluginImage() { if (empty($this->controller->action)) { return; } $publicPath = __DIR__ . '/../../public'; $imageDomain = trim($this->config->get('admin', 'imageDomain'), '/'); $imagePath = trim($this->config->get('admin', 'imagePath'), '/'); if (!empty($_FILES)) { if (isset($_FILES['image']['error']) && $_FILES['image']['error'] === 0) { if (!is_dir($publicPath . '/' . $imagePath . '/' . $this->controller->table)) { mkdir($publicPath . '/' . $imagePath . '/' . $this->controller->table); } $storage = new \Upload\Storage\FileSystem($publicPath . '/' . $imagePath . '/' . $this->controller->table, true); $file = new \Upload\File('image', $storage); $file->addValidations([new \Upload\Validation\Mimetype(['image/png', 'image/jpg', 'image/jpeg', 'image/gif', 'image/tif']), new \Upload\Validation\Size('5M')]); $file->upload(); } return; } $structure = []; $directory = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($publicPath . '/' . $imagePath, \RecursiveDirectoryIterator::SKIP_DOTS)); foreach ($directory as $file) { if ('.' === substr($file->getFilename(), 0, 1)) { continue; } $pathname = $file->getPathname(); $dir = basename($file->getPath()); //structure by modification time and filename $structure[$dir][$file->getMtime() . $file->getFilename()] = str_replace($publicPath, '', $pathname); krsort($structure[$dir]); } $content = $this->factory->template()->file(__DIR__ . '/../Views/Admin/Plugins/Image')->set('structure', $structure)->set('data', $this->data)->set('imageDomain', $imageDomain)->set('imagePath', $imagePath)->set('table', $this->controller->table)->set('action', $this->controller->action)->set('id', $this->controller->id); foreach ($this->data[$this->controller->table]['columns'] as $columnName => $column) { if (isset($column['type']) && $column['type'] == 'image') { $this->data[$this->controller->table]['plugins'][$columnName] = $content->set('column', $columnName)->render(); } } return; }