Ejemplo n.º 1
0
 public function action($parent)
 {
     $s = new SessionHandler($parent->app);
     $s->setClipboardPath(null);
     $s->setClipboardPathThumb(null);
     $this->r = array("", 200);
 }
Ejemplo n.º 2
0
 public function action($parent)
 {
     if (isset($_GET['type'])) {
         $s = new SessionHandler($parent->app);
         $s->setFilter($_GET['type']);
         $this->r = array("", 200);
         return;
     } else {
         $this->r = array('filter type number missing', 400);
         return;
     }
 }
Ejemplo n.º 3
0
 public function action($parent)
 {
     $s = new SessionHandler($parent->app);
     $util = new Utility();
     $c = $parent->config;
     if ($_POST['sub_action'] != 'copy' && $_POST['sub_action'] != 'cut') {
         $this->error('wrong sub-action');
         return;
     }
     if (trim($_POST['path']) == '' || trim($_POST['path_thumb']) == '') {
         $this->error('no path');
         return;
     }
     $path = $c['current_path'] . $_POST['path'];
     if (is_dir($path)) {
         // can't copy/cut dirs
         if ($c['copy_cut_dirs'] === false) {
             $this->error(sprintf('You are not allowed to %s $s.', $_POST['sub_action'] == 'copy' ? 'copy' : 'cut', 'folders'));
             return;
         }
         // size over limit
         if ($c['copy_cut_max_size'] !== false && is_int($c['copy_cut_max_size'])) {
             if ($copy_cut_max_size * 1024 * 1024 < $util->foldersize($path)) {
                 $this->error(sprintf('The selected files/folders are too big to %s. Limit: %d MB/operation', $_POST['sub_action'] == 'copy' ? 'copy' : 'cut', $c['copy_cut_max_size']));
                 return;
             }
         }
         // file count over limit
         if ($copy_cut_max_count !== false && is_int($copy_cut_max_count)) {
             if ($copy_cut_max_count < filescount($path)) {
                 $this->error(sprintf('You selected too many files/folders to %s. Limit: %d files/operation', $_POST['sub_action'] == 'copy' ? 'copy' : 'cut', $c['copy_cut_max_count']));
                 return;
             }
         }
     } else {
         // can't copy/cut files
         if ($c['copy_cut_files'] === false) {
             $this->error(sprintf('You are not allowed to %s files.', $_POST['sub_action'] == 'copy' ? 'copy' : 'cut', 'files'));
             exit;
         }
     }
     $s->setClipboardPath($_POST['path']);
     $s->setClipboardPathThumb($_POST['path_thumb']);
     $s->setClipboardAction($_POST['sub_action']);
 }
Ejemplo n.º 4
0
 public function action($parent)
 {
     $s = new SessionHandler($parent->app);
     if (isset($_GET['sort_by'])) {
         $s->setSortBy($_GET['sort_by']);
         $this->success();
         return;
     } else {
         $this->error("invalid sort_by");
         return;
     }
     if (isset($_GET['descending'])) {
         $descending = $_GET['descending'] === "TRUE";
         $s->setDescending($descending);
         return;
     } else {
         $this->error("invalid descending");
         return;
     }
     $this->error("invalid sorting action");
     return;
 }
Ejemplo n.º 5
0
 public function Dialog(Application $app, Request $request)
 {
     $config = $app['FileManager'];
     $config['ext'] = array_merge($config['ext_img'], $config['ext_file'], $config['ext_misc'], $config['ext_video'], $config['ext_music']);
     //handle sessions
     $session = new SessionHandler($app);
     $util = new Utility();
     //handle additional parameters to set views ect
     if (isset($_GET['view'])) {
         $session->setViewType($util->fix_get_params($_GET['view']));
     }
     if (isset($_GET["filter"])) {
         $session->setFilter($util->fix_get_params($_GET['filter']));
     }
     if (isset($_GET["sort_by"])) {
         $session->setSortBy($util->fix_get_params($_GET["sort_by"]));
     }
     if (isset($_GET["descending"])) {
         $session->setDescending($util->fix_get_params($_GET["descending"]));
     }
     $subdir = '';
     if (isset($_GET['fldr']) && !empty($_GET['fldr']) && strpos($_GET['fldr'], '../') === FALSE && strpos($_GET['fldr'], './') === FALSE) {
         $subdir = urldecode(trim(strip_tags($_GET['fldr']), "/") . "/");
         $session->setFilter('');
     }
     // If hidden folders are specified
     if (count($config['hidden_folders'])) {
         // If hidden folder appears in the path specified in URL parameter "fldr"
         $dirs = explode('/', $subdir);
         foreach ($dirs as $dir) {
             if ($dir !== '' && in_array($dir, $hidden_folders)) {
                 // Ignore the path
                 $subdir = "";
                 break;
             }
         }
     }
     /***
      *SUB-DIR CODE
      ***/
     if (!isset($_SESSION['RF']["subfolder"])) {
         $_SESSION['RF']["subfolder"] = '';
     }
     $rfm_subfolder = '';
     if (!empty($_SESSION['RF']["subfolder"]) && strpos($_SESSION['RF']["subfolder"], '../') === FALSE && strpos($_SESSION['RF']["subfolder"], './') === FALSE && strpos($_SESSION['RF']["subfolder"], "/") !== 0 && strpos($_SESSION['RF']["subfolder"], '.') === FALSE) {
         $rfm_subfolder = $_SESSION['RF']['subfolder'];
     }
     if ($rfm_subfolder != "" && $rfm_subfolder[strlen($rfm_subfolder) - 1] != "/") {
         $rfm_subfolder .= "/";
     }
     if (!file_exists($config['current_path'] . $rfm_subfolder . $subdir)) {
         $subdir = '';
         if (!file_exists($config['current_path'] . $rfm_subfolder . $subdir)) {
             $rfm_subfolder = "";
         }
     }
     if (trim($rfm_subfolder) == "") {
         $this->cur_dir = $config['upload_dir'] . $subdir;
         $cur_path = $config['current_path'] . $subdir;
         $thumbs_path = $config['thumbs_base_path'];
         $parent = $subdir;
     } else {
         $this->cur_dir = $config['upload_dir'] . $rfm_subfolder . $subdir;
         $cur_path = $config['current_path'] . $rfm_subfolder . $subdir;
         $thumbs_path = $config['thumbs_base_path'] . $rfm_subfolder;
         $parent = $rfm_subfolder . $subdir;
     }
     $cycle = TRUE;
     $max_cycles = 50;
     $i = 0;
     while ($cycle && $i < $max_cycles) {
         $i++;
         if ($parent == "./") {
             $parent = "";
         }
         if (file_exists($config['current_path'] . $parent . "config.php")) {
             require_once $config['current_path'] . $parent . "config.php";
             $cycle = FALSE;
         }
         if ($parent == "") {
             $cycle = FALSE;
         } else {
             $parent = $util->fix_dirname($parent) . "/";
         }
     }
     if (!is_dir($thumbs_path . $subdir)) {
         $util->create_folder(FALSE, $thumbs_path . $subdir);
     }
     if (isset($_GET['popup'])) {
         $popup = strip_tags($_GET['popup']);
     } else {
         $popup = 0;
     }
     //Sanitize popup
     $popup = !!$popup;
     if (isset($_GET['crossdomain'])) {
         $crossdomain = strip_tags($_GET['crossdomain']);
     } else {
         $crossdomain = 0;
     }
     //Sanitize crossdomain
     $crossdomain = !!$crossdomain;
     //view type
     $view = $session->getViewType();
     //filter
     $filter = $session->getFilter();
     //sorting method
     $sort_by = $session->getSortBy();
     //sorting order
     $descending = $session->getDescending();
     $boolarray = array(false => 'false', true => 'true');
     $return_relative_url = isset($_GET['relative_url']) && $_GET['relative_url'] == "1" ? true : false;
     if (!isset($_GET['type'])) {
         $_GET['type'] = 0;
     }
     if (isset($_GET['editor'])) {
         $editor = strip_tags($_GET['editor']);
     } else {
         if ($_GET['type'] == 0) {
             $editor = false;
         } else {
             $editor = 'tinymce';
         }
     }
     if (!isset($_GET['field_id'])) {
         $_GET['field_id'] = '';
     }
     $field_id = isset($_GET['field_id']) ? $util->fix_get_params($_GET['field_id']) : '';
     $type_param = $util->fix_get_params($_GET['type']);
     if ($type_param == 1) {
         $apply = 'apply_img';
     } elseif ($type_param == 2) {
         $apply = 'apply_link';
     } elseif ($type_param == 0 && $_GET['field_id'] == '') {
         $apply = 'apply_none';
     } elseif ($type_param == 3) {
         $apply = 'apply_video';
     } else {
         $apply = 'apply';
     }
     $get_params = http_build_query(array('editor' => $editor, 'type' => $type_param, 'lang' => $config['default_language'], 'popup' => $popup, 'crossdomain' => $crossdomain, 'field_id' => $field_id, 'relative_url' => $return_relative_url, 'akey' => isset($_GET['akey']) && $_GET['akey'] != '' ? $_GET['akey'] : 'key', 'fldr' => ''));
     //get base config options
     $twigArr = $app['FileManager'];
     //overwrite specific's
     $twigArr['lang'] = $app['FileManager']['default_language'];
     $twigArr['ext'] = array_merge($config['ext_img'], $config['ext_file'], $config['ext_misc'], $config['ext_video'], $config['ext_music']);
     $twigArr['apply'] = $apply;
     $twigArr['field_id'] = $field_id;
     $twigArr['popup'] = $popup;
     $twigArr['crossdomain'] = $crossdomain;
     $twigArr['editor'] = $editor;
     $twigArr['view'] = $view;
     $twigArr['filter'] = $filter;
     $twigArr['sort_by'] = $sort_by;
     $twigArr['descending'] = $descending;
     $twigArr['subdir'] = $subdir;
     $twigArr['field_id'] = $field_id;
     $twigArr['type_param'] = $type_param;
     $twigArr['cur_dir'] = $config['upload_dir'] . $subdir;
     $twigArr['cur_path'] = $config['current_path'] . $subdir;
     $twigArr['thumbs_path'] = $config['thumbs_base_path'];
     $twigArr['cur_dir_thumb'] = $twigArr['thumbs_path'] . $twigArr['subdir'];
     $twigArr['parent'] = $subdir;
     $twigArr['duplicate_files'] = 0;
     $twigArr['rfm_subfolder'] = "";
     $twigArr['base_url_func'] = $util->base_url();
     $twigArr['current_url'] = str_replace(array('&filter=' . $filter, '&sort_by=' . $sort_by, '&descending=' . intval($descending)), array(''), $twigArr['base_url'] . $_SERVER['REQUEST_URI']);
     $twigArr['get_type'] = $_GET['type'];
     $twigArr['home_link'] = $_GET['type'];
     $twigArr['get_params'] = $get_params;
     $twigArr['return_relative_url'] = 0;
     if ($return_relative_url == true) {
         $twigArr['return_relative_url'] = 1;
     }
     if ($twigArr['duplicate_files'] === true) {
         $twigArr['duplicate_files'] = 1;
     }
     //        array(
     //            'ext_img' => $config['ext_img'],
     //            'ext' => array_merge($config['ext_img'], $config['ext_file'], $config['ext_misc'], $config['ext_video'], $config['ext_music']),
     //            'aviary_active' => $config['aviary_active'],
     //            'Error_extension'
     //            'MaxSizeUpload' => (int)$config['MaxSizeUpload'],
     //        );
     $template = 'FileManager/view.html.twig';
     $class_ext = '';
     $src = '';
     $files = scandir($config['current_path'] . $rfm_subfolder . $subdir);
     $n_files = count($files);
     //php sorting
     $sorted = array();
     $current_folder = array();
     $prev_folder = array();
     foreach ($files as $k => $file) {
         if ($file == ".") {
             $current_folder = array('file' => $file);
         } elseif ($file == "..") {
             $prev_folder = array('file' => $file);
         } elseif (is_dir($config['current_path'] . $rfm_subfolder . $subdir . $file)) {
             $date = filemtime($config['current_path'] . $rfm_subfolder . $subdir . $file);
             if ($config['show_folder_size']) {
                 $size = $util->foldersize($config['current_path'] . $rfm_subfolder . $subdir . $file);
             } else {
                 $size = 0;
             }
             $file_ext = 'dir';
             $sorted[$k] = array('file' => $file, 'file_lcase' => strtolower($file), 'date' => $date, 'size' => $size, 'extension' => $file_ext, 'extension_lcase' => strtolower($file_ext));
         } else {
             $file_path = $config['current_path'] . $rfm_subfolder . $subdir . $file;
             $date = filemtime($file_path);
             $size = filesize($file_path);
             $file_ext = substr(strrchr($file, '.'), 1);
             $sorted[$k] = array('file' => $file, 'file_lcase' => strtolower($file), 'date' => $date, 'size' => $size, 'extension' => $file_ext, 'extension_lcase' => strtolower($file_ext));
         }
     }
     // Should lazy loading be enabled
     $lazy_loading_enabled = $config['lazy_loading_file_number_threshold'] == 0 || $config['lazy_loading_file_number_threshold'] != -1 && $n_files > $config['lazy_loading_file_number_threshold'] ? true : false;
     $twigArr['lazy_loading_enabled'] = $lazy_loading_enabled;
     switch ($sort_by) {
         case 'date':
             usort($sorted, array($this, 'dateSort'));
             break;
         case 'size':
             usort($sorted, array($this, 'sizeSort'));
             break;
         case 'extension':
             usort($sorted, array($this, 'extensionSort'));
             break;
         default:
             usort($sorted, array($this, 'filenameSort'));
             break;
     }
     if (!$descending) {
         $sorted = array_reverse($sorted);
     }
     $files = array_merge(array($prev_folder), array($current_folder), $sorted);
     //Add file / folder stuff to array
     $twigArr['n_files'] = $n_files;
     $twigArr['uniqid'] = uniqid();
     //can open current dir?
     $open_dir = false;
     if (@opendir($config['current_path'] . $rfm_subfolder . $subdir)) {
         $open_dir = true;
     }
     $twigArr['clipboard'] = 0;
     $clipboard_path = $session->getClipboardPath();
     //var_dump($clipboard_path);
     if (isset($clipboard_path) && trim($clipboard_path) != null) {
         $twigArr['clipboard'] = 1;
     }
     //$twigArr['open_dir'] = uniqid();
     $twigArr['open_dir'] = $open_dir;
     $twigArr['render_need_name'] = $this->render_need_name($app, $files, $twigArr, $config, $subdir, $filter, $config['transliteration'], $thumbs_path, $get_params, $rfm_subfolder);
     $twigArr['render_need_name_2'] = $this->two;
     $twigArr['files_prevent_duplicate'] = $this->files_prevent_duplicate;
     return $app['twig']->render($template, $twigArr);
 }
Ejemplo n.º 6
0
 public function action($parent)
 {
     $util = new Utility();
     $app = $parent->app;
     $session = new SessionHandler($app);
     $path = $parent->path;
     $path_thumb = $parent->path_thumb;
     $c = $parent->config;
     $action = $session->getClipboardAction();
     $data = array("path" => $session->getClipboardPath(), "path_thumb" => $session->getClipboardPathThumb());
     if (!isset($action, $data['path'], $data['path_thumb']) || $action == '' || $data['path'] == '' || $data['path_thumb'] == '') {
         $this->r = array('no clipboard data found.', 200);
         return;
     }
     $data['path'] = $c['current_path'] . $data['path'];
     $pinfo = pathinfo($data['path']);
     // user wants to paste to the same dir. nothing to do here...
     if ($pinfo['dirname'] == rtrim($path, '/')) {
         $this->r = array('', 200);
         return;
     }
     // user wants to paste folder to it's own sub folder.. baaaah.
     if (is_dir($data['path']) && strpos($path, $data['path']) !== FALSE) {
         $this->r = array('', 200);
         return;
     }
     // something terribly gone wrong
     if ($action != 'copy' && $action != 'cut') {
         $this->r = array('no action', 400);
         return;
     }
     // check for writability
     if ($util->is_really_writable($path) === FALSE || $util->is_really_writable($path_thumb) === FALSE) {
         $this->r = array('The directory you selected is not writable <br/>' . str_replace('../', '', $path) . '<br/>' . str_replace('../', '', $path_thumb), 403);
         return;
     }
     // check if server disables copy or rename
     if ($util->is_function_callable($action == 'copy' ? 'copy' : 'rename') === FALSE) {
         $response = sprintf('The %s function has been disabled by the server.', $action == 'copy' ? 'copy' : 'cut');
         $this->r = array($response, 403);
         return;
     }
     if ($action == 'copy') {
         $util->rcopy($data['path'], $path);
         $util->rcopy($data['path_thumb'], $path_thumb);
     } elseif ($action == 'cut') {
         $util->rrename($data['path'], $path);
         $util->rrename($data['path_thumb'], $path_thumb);
         // cleanup
         if (is_dir($data['path']) === TRUE) {
             $util->rrename_after_cleaner($data['path']);
             $util->rrename_after_cleaner($data['path_thumb']);
         }
     }
     // cleanup
     $session->setClipboardAction(NULL);
     $session->setClipboardPath(NULL);
     $session->setClipboardPathThumb(NULL);
     $response = $action . ' successful';
     $this->r = array($response, 200);
 }