/** * @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; }
public function get_m3u_data() { if (!$this->isAjax || $this->method != 'POST') { $this->app->abort(404, 'Page not found...'); } if ($no_auth = $this->checkAuth()) { return $no_auth; } $data = array(); $data['action'] = 'loadM3UData'; $data['data'] = array('channels' => array(), 'last_channel_number' => 0, 'free_number_exists' => 1); $error = $this->setLocalization('Upload failed'); $storage = new \Upload\Storage\FileSystem('/tmp', TRUE); $file = new \Upload\File('qqfile', $storage); try { // Success! $file->upload(); $obj = new M3uParser\M3uParser(); $m3u_data = $obj->parseFile($file->getPath() . '/' . $file->getNameWithExtension()); @unlink($file->getPath() . '/' . $file->getNameWithExtension()); $data['data']['last_channel_number'] = (int) $this->db->getLastChannelNumber(); if ($data['data']['last_channel_number'] + count($m3u_data) > 9999) { $data['data']['free_number_exists'] = (int) ($this->db->getAllChannels(array(), 'COUNT') + count($m3u_data) <= 9999); } foreach ($m3u_data as $entry) { $name = trim($entry->getName()); if (!mb_check_encoding($name, 'UTF-8')) { $name = mb_convert_encoding($name, 'UTF-8', array('CP1251')); } $data['data']['channels'][] = array('name' => $name, 'cmd' => trim($entry->getPath())); } $error = ''; } catch (\Exception $e) { // Fail! $data['msg'] = $error = $file->getErrors(); } $response = $this->generateAjaxResponse($data, $error); $json_string = json_encode($response); if (json_last_error() !== JSON_ERROR_NONE) { $error = $this->setLocalization('Error m3u parse. Check the file encoding. Required UTF-8 encoding.'); $json_string = json_encode(array('msg' => $error, 'error' => $error)); } return new Response($json_string, empty($error) ? 200 : 500); }