コード例 #1
0
ファイル: Core.php プロジェクト: Seravo/WP-Filebase
 static function DownloadRedirect()
 {
     $file = null;
     if (!empty($_GET['wpfb_dl'])) {
         wpfb_loadclass('File');
         $file = WPFB_File::GetFile($_GET['wpfb_dl']);
         @ob_end_clean();
         // FIX: clean the OB so any output before the actual download is truncated (OB is started in wp-filebase.php)
     } else {
         if (!WPFB_Core::$settings->download_base || is_admin()) {
             return;
         }
         $dl_url_path = parse_url(home_url(WPFB_Core::$settings->download_base . '/'), PHP_URL_PATH);
         $pos = strpos($_SERVER['REQUEST_URI'], $dl_url_path);
         if ($pos === 0) {
             $filepath = trim(substr(stripslashes($_SERVER['REQUEST_URI']), strlen($dl_url_path)), '/');
             if (($qs = strpos($filepath, '?')) !== false) {
                 $filepath = substr($filepath, 0, $qs);
             }
             // remove query string
             if (!empty($filepath)) {
                 wpfb_loadclass('File', 'Category');
                 $file = is_null($file = WPFB_File::GetByPath($filepath)) ? WPFB_File::GetByPath(urldecode($filepath)) : $file;
             }
         }
     }
     if (!empty($file) && is_object($file) && !empty($file->is_file)) {
         $file->Download();
         exit;
     }
     /* else { // don't set coockies anymore
     		// no download, a normal request: set site visited coockie to disable referer check
     		if(empty($_COOKIE[WPFB_OPT_NAME])) {
     			@setcookie(WPFB_OPT_NAME, '1');
     			$_COOKIE[WPFB_OPT_NAME] = '1';
     		}
     	} */
 }
コード例 #2
0
ファイル: wpfb-ajax.php プロジェクト: parsonsc/dofe
     if (empty($_REQUEST['url']) && (empty($_REQUEST['id']) || !is_numeric($_REQUEST['id']))) {
         die('-1');
     }
     $file = null;
     if (!empty($_REQUEST['url'])) {
         $url = $_REQUEST['url'];
         $matches = array();
         if (preg_match('/\\?wpfb_dl=([0-9]+)$/', $url, $matches) || preg_match('/#wpfb-file-([0-9]+)$/', $url, $matches)) {
             $file = WPFB_File::GetFile($matches[1]);
         } else {
             $base = trailingslashit(get_option('home')) . trailingslashit(WPFB_Core::$settings->download_base);
             $path = substr($url, strlen($base));
             $path_u = substr(urldecode($url), strlen($base));
             $file = WPFB_File::GetByPath($path);
             if ($file == null) {
                 $file = WPFB_File::GetByPath($path_u);
             }
         }
     } else {
         $file = WPFB_File::GetFile((int) $_REQUEST['id']);
     }
     if ($file != null && $file->CurUserCanAccess(true)) {
         wpfb_print_json(array('id' => $file->GetId(), 'url' => $file->GetUrl(), 'path' => $file->GetLocalPathRel()));
     } else {
         echo '-1';
     }
     exit;
 case 'catinfo':
     wpfb_loadclass('Category', 'Output');
     if (empty($_REQUEST['id']) || !is_numeric($_REQUEST['id'])) {
         die('-1');
コード例 #3
0
 function ChangeCategoryOrName($new_cat_id, $new_name = null, $add_existing = false, $overwrite = false)
 {
     // 1. apply new values (inherit permissions if nothing (Everyone) set!)
     // 2. check for name collision and rename
     // 3. move stuff
     // 4. notify parents
     // 5. update child paths
     if (empty($new_name)) {
         $new_name = $this->GetName();
     }
     $this->Lock(true);
     $new_cat_id = intval($new_cat_id);
     $old_cat_id = $this->GetParentId();
     $old_path_rel = $this->GetLocalPathRel(true);
     $old_path = $this->GetLocalPath();
     $old_name = $this->GetName();
     if ($this->is_file) {
         $old_thumb_path = $this->GetThumbPath();
     }
     $old_cat = $this->GetParent();
     $new_cat = WPFB_Category::GetCat($new_cat_id);
     if (!$new_cat) {
         $new_cat_id = 0;
     }
     $cat_changed = $new_cat_id != $old_cat_id;
     if ($cat_changed && $new_cat_id > 0 && $this->IsAncestorOf($new_cat)) {
         return array('error' => __('Cannot move category into a sub-category of itself.', WPFB));
     }
     if ($this->is_file) {
         $this->file_category = $new_cat_id;
         $this->file_name = $new_name;
         $this->file_category_name = $new_cat_id == 0 ? '' : $new_cat->GetTitle();
     } else {
         $this->cat_parent = $new_cat_id;
         $this->cat_folder = $new_name;
     }
     // inherit user roles
     if (count($this->GetReadPermissions()) == 0) {
         $this->SetReadPermissions($new_cat_id != 0 ? $new_cat->GetReadPermissions() : WPFB_Core::$settings->default_roles);
     }
     // flush cache
     $this->last_parent_id = -1;
     $new_path_rel = $this->GetLocalPathRel(true);
     $new_path = $this->GetLocalPath();
     if ($new_path_rel != $old_path_rel) {
         $i = 1;
         if (!$add_existing) {
             $name = $this->GetName();
             if ($overwrite) {
                 if (@file_exists($new_path)) {
                     $ex_file = WPFB_File::GetByPath($new_path_rel);
                     if (!is_null($ex_file)) {
                         $ex_file->Remove();
                     } else {
                         @unlink($new_path);
                     }
                 }
             } else {
                 // rename item if filename collision (ignore if coliding with $this)
                 while (@file_exists($new_path) || !is_null($ex_file = WPFB_File::GetByPath($new_path_rel)) && !$this->Equals($ex_file)) {
                     $i++;
                     if ($this->is_file) {
                         $p = strrpos($name, '.');
                         $this->file_name = $p <= 0 ? "{$name}({$i})" : substr($name, 0, $p) . "({$i})" . substr($name, $p);
                     } else {
                         $this->cat_folder = "{$name}({$i})";
                     }
                     $new_path_rel = $this->GetLocalPathRel(true);
                     $new_path = $this->GetLocalPath();
                 }
             }
         }
         // finally move it!
         if (!empty($old_name) && @file_exists($old_path)) {
             if ($this->is_file && $this->IsLocal()) {
                 if (!@rename($old_path, $new_path)) {
                     return array('error' => sprintf('Unable to move file %s!', $old_path));
                 }
                 @chmod($new_path, octdec(WPFB_PERM_FILE));
             } else {
                 if (!@is_dir($new_path)) {
                     wp_mkdir_p($new_path);
                 }
                 wpfb_loadclass('FileUtils');
                 if (!@WPFB_FileUtils::MoveDir($old_path, $new_path)) {
                     return array('error' => sprintf('Could not move folder %s to %s', $old_path, $new_path));
                 }
             }
         } else {
             if ($this->is_category) {
                 if (!@is_dir($new_path) && !wp_mkdir_p($new_path)) {
                     return array('error' => sprintf(__('Unable to create directory %s. Is it\'s parent directory writable?'), $new_path));
                 }
             }
         }
         // move thumb
         if ($this->is_file && !empty($old_thumb_path) && @is_file($old_thumb_path)) {
             $thumb_path = $this->GetThumbPath();
             if ($i > 1) {
                 $p = strrpos($thumb_path, '-');
                 if ($p <= 0) {
                     $p = strrpos($thumb_path, '.');
                 }
                 $thumb_path = substr($thumb_path, 0, $p) . "({$i})" . substr($thumb_path, $p);
                 $this->file_thumbnail = basename($thumb_path);
             }
             if (!is_dir(dirname($thumb_path))) {
                 WPFB_Admin::Mkdir(dirname($thumb_path));
             }
             if (!@rename($old_thumb_path, $thumb_path)) {
                 return array('error' => 'Unable to move thumbnail! ' . $thumb_path);
             }
             @chmod($thumb_path, octdec(WPFB_PERM_FILE));
         }
         $all_files = $this->is_file || $this->GetId() > 0 ? $this->GetChildFiles(true) : array();
         // all children files (recursively)
         if (!empty($all_files)) {
             foreach ($all_files as $file) {
                 if ($cat_changed) {
                     if ($old_cat) {
                         $old_cat->NotifyFileRemoved($file);
                     }
                     // notify parent cat to remove files
                     if ($new_cat) {
                         $new_cat->NotifyFileAdded($file);
                     }
                 }
                 $file->GetLocalPathRel(true);
                 // update file's path
             }
         }
         unset($all_files);
         if ($this->is_category && $this->GetId() > 0) {
             $cats = $this->GetChildCats(true);
             if (!empty($cats)) {
                 foreach ($cats as $cat) {
                     $cat->GetLocalPathRel(true);
                     // update cats's path
                 }
             }
             unset($cats);
         }
     }
     $this->Lock(false);
     if (!$this->locked) {
         $this->DBSave();
     }
     return array('error' => false);
     /*
     * 		// create the directory if it doesnt exist
     		// move file
     		if($this->IsLocal() && !empty($old_file_path) && @is_file($old_file_path) && $new_file_path != $old_file_path) {
     			if(!@rename($old_file_path, $new_file_path)) return array( 'error' => sprintf('Unable to move file %s!', $this->GetLocalPath()));
     			@chmod($new_file_path, octdec(WPFB_PERM_FILE));
     		}
     */
 }
コード例 #4
0
ファイル: Ajax.php プロジェクト: noxian/WP-Filebase
 private static function fileInfo($args)
 {
     wpfb_loadclass('File', 'Category');
     if (empty($args['url']) && (empty($args['id']) || !is_numeric($args['id']))) {
         die('-1');
     }
     $file = null;
     if (!empty($args['url'])) {
         $url = $args['url'];
         $matches = array();
         if (preg_match('/\\?wpfb_dl=([0-9]+)$/', $url, $matches) || preg_match('/#wpfb-file-([0-9]+)$/', $url, $matches)) {
             $file = WPFB_File::GetFile($matches[1]);
         } else {
             $base = trailingslashit(get_option('home')) . trailingslashit(WPFB_Core::$settings->download_base);
             $path = substr($url, strlen($base));
             $path_u = substr(urldecode($url), strlen($base));
             $file = WPFB_File::GetByPath($path);
             if ($file == null) {
                 $file = WPFB_File::GetByPath($path_u);
             }
         }
     } else {
         $file = WPFB_File::GetFile((int) $args['id']);
     }
     if ($file != null && $file->CurUserCanAccess(true)) {
         wp_send_json(array('id' => $file->GetId(), 'url' => $file->GetUrl(), 'path' => $file->GetLocalPathRel()));
     } else {
         echo '-1';
     }
 }