From 1754a2d68da639907c59dcaf8c21835f918278f4 Mon Sep 17 00:00:00 2001 From: Fabian Schlieper Date: Thu, 28 Jan 2016 20:57:25 +0100 Subject: [PATCH] fixed sync permission issue --- classes/Admin.php | 2 +- classes/AdminBar.php | 4 +++- classes/AdminGuiTpls.php | 2 +- classes/AdminLite.php | 13 ++++-------- classes/File.php | 5 ++--- classes/Output.php | 14 ++++++++----- classes/Settings.php | 2 +- classes/Setup.php | 12 ++++++++--- classes/Sync.php | 45 +++++++++++++++++++++++++++++++++++----- readme.txt | 7 ++----- tinymce/editor_plugin.js | 2 +- wp-filebase.php | 6 +++--- 12 files changed, 76 insertions(+), 38 deletions(-) diff --git a/classes/Admin.php b/classes/Admin.php index d0d4263..29f8711 100644 --- a/classes/Admin.php +++ b/classes/Admin.php @@ -441,7 +441,7 @@ static function InsertFile($data, $in_gui = false) { @unlink($file->GetLocalPath()); // when download redircet the actual files is not needed anymore } else { // set permissions - @chmod($file->GetLocalPath(), octdec(WPFB_PERM_FILE)); + is_file($file->GetLocalPath()) && @chmod($file->GetLocalPath(), octdec(WPFB_PERM_FILE)); $file->file_remote_uri = $data->file_remote_uri = ''; // no redirection, URI is not neede anymore } diff --git a/classes/AdminBar.php b/classes/AdminBar.php index 7517e87..b47c122 100644 --- a/classes/AdminBar.php +++ b/classes/AdminBar.php @@ -1,4 +1,6 @@ post_type != 'wpfb_filepage') { $is_filebrowser = ($current_object->ID == WPFB_Core::$settings->file_browser_post_id); - $link = esc_attr(admin_url('?wpfilebase-screen=editor-plugin&manage_attachments=1&post_id='.$current_object->ID)); + $link = esc_attr(admin_url('admin.php?wpfilebase-screen=editor-plugin&manage_attachments=1&post_id='.$current_object->ID)); $wp_admin_bar->add_menu( array( 'parent' => WPFB, 'id' => WPFB.'-attachments', 'title' => __('Manage attachments','wp-filebase'), 'href' => $link, 'meta' => array('onclick' => 'window.open("'.$link.'", "wpfb-manage-attachments", "width=680,height=400,menubar=no,location=no,resizable=no,status=no,toolbar=no,scrollbars=yes");return false;'))); } else { diff --git a/classes/AdminGuiTpls.php b/classes/AdminGuiTpls.php index cf6ea4c..e434206 100644 --- a/classes/AdminGuiTpls.php +++ b/classes/AdminGuiTpls.php @@ -276,7 +276,7 @@ static function TplsTable($type, $exclude=array(), $include=array()) {
- + get_var("SELECT COUNT(`{$wpdb->wpfilebase_files}`.`file_id`) FROM " . self::genSelectSql($where, $check_permissions)); @@ -636,8 +636,6 @@ function Download() update_user_option($user_ID, WPFB_OPT_NAME . '_last_dl', time()); } - WPFB_Core::LogMsg(json_encode($_SERVER)); - $head_only = ($_SERVER["REQUEST_METHOD"] == "HEAD"); list($begin, $end) = WPFB_Download::ParseRangeHeader($this->file_size); @@ -676,6 +674,7 @@ function Download() 'filename' => empty($this->file_name_original) ? $this->file_name : $this->file_name_original )); } else { + // avoid redirect caching //header('HTTP/1.1 301 Moved Permanently'); header('Cache-Control: no-store, no-cache, must-revalidate'); header('Expires: Thu, 01 Jan 1970 00:00:00 GMT'); diff --git a/classes/Output.php b/classes/Output.php index c61e931..f409142 100644 --- a/classes/Output.php +++ b/classes/Output.php @@ -53,7 +53,7 @@ static function PrintJS() echo "\n//]]>\n\n"; } - static function ProcessShortCode($args, $content = null, $tag = null) + static function ProcessShortCode($args) { $id = empty($args ['id']) ? -1 : intval($args ['id']); if ($id <= 0 && !empty($args['path'])) { // path indentification @@ -127,6 +127,12 @@ static function ParseSorting($sort = '', $for_cat = false) return array($sort, $desc ? 'DESC' : 'ASC'); } + /** + * @param WPFB_File[] $files + * @param string $tpl_tag + * + * @return string + */ private static function genFileList(&$files, $tpl_tag = null) { $content = ''; @@ -338,12 +344,10 @@ static function GetTreeItems($parent_id, $args = array()) $where .= " AND `file_post_id` = 0"; - // $files = WPFB_File::GetFiles2(WPFB_File::GetSqlCatWhereStr($root_id), WPFB_Core::$settings->hide_inaccessible, $sql_file_order); //$files = WPFB_File::GetFiles2(WPFB_File::GetSqlCatWhereStr($root_id), WPFB_Core::$settings->hide_inaccessible, $sql_file_order); - $files = WPFB_File::GetFiles2( - $where, (WPFB_Core::$settings->hide_inaccessible && !($filesel && wpfb_call('Core', 'CurUserCanUpload')) && !($is_admin && current_user_can('manage_options'))), $sql_sort_files - ); + $check_permissions = (WPFB_Core::$settings->hide_inaccessible && !($filesel && wpfb_call('Core', 'CurUserCanUpload')) && !($is_admin && current_user_can('manage_options'))) ; + $files = WPFB_File::GetFiles2( $where, $check_permissions, $sql_sort_files ); foreach ($files as $f) $file_items[$i++] = (object)array( diff --git a/classes/Settings.php b/classes/Settings.php index 03ec8d8..e4851c7 100644 --- a/classes/Settings.php +++ b/classes/Settings.php @@ -115,7 +115,7 @@ static function Schema() 'range_download' => array('default' => true, 'title' => __('Send HTTP-Range header','wp-filebase'), 'type' => 'checkbox', 'desc' => __('Allows users to pause downloads and continue later. In addition download managers can use multiple connections at the same time.','wp-filebase')), 'hide_links' => array('default' => false, 'title' => __('Hide download links','wp-filebase'), 'type' => 'checkbox', 'desc' => sprintf(__('File download links wont be displayed in the browser\'s status bar. You should enable \'%s\' to make it even harder to find out the URL.','wp-filebase'), __('Always force download','wp-filebase'))), 'ignore_admin_dls' => array('default' => true, 'title' => __('Ignore downloads by admins','wp-filebase'), 'type' => 'checkbox', 'desc' => sprintf(__('Download by an admin user does not increase hit counter. Reset All Hit Counters to 0'),esc_attr(admin_url('admin.php?page=wpfilebase_manage&action=reset-hits')))), - 'hide_inaccessible' => array('default' => true, 'title' => __('Hide inaccessible files and categories','wp-filebase'), 'type' => 'checkbox', 'desc' => __('If enabled files tagged For members only will not be listed for guests or users whith insufficient rights.','wp-filebase')), + 'hide_inaccessible' => array('default' => false, 'title' => __('Hide inaccessible files and categories','wp-filebase'), 'type' => 'checkbox', 'desc' => __('If enabled files tagged For members only will not be listed for guests or users whith insufficient rights.','wp-filebase')), 'inaccessible_msg' => array('default' => __('You are not allowed to access this file!','wp-filebase'), 'title' => __('Inaccessible file message','wp-filebase'), 'type' => 'text', 'size' => 65, 'desc' => (__('This message will be displayed if users try to download a file they cannot access','wp-filebase').'. '.__('You can enter a URL to redirect users.','wp-filebase'))), 'inaccessible_redirect' => array('default' => false, 'title' => __('Redirect to login','wp-filebase'), 'type' => 'checkbox', 'desc' => __('Guests trying to download inaccessible files are redirected to the login page if this option is enabled.','wp-filebase')), 'cat_inaccessible_msg' => array('default' => __('Access to category denied!','wp-filebase'), 'title' => __('Inaccessible category message','wp-filebase'), 'type' => 'text', 'size' => 65, 'desc' => (__('This message will be displayed if users try to access a category without permission.','wp-filebase'))), diff --git a/classes/Setup.php b/classes/Setup.php index d030cea..1e2b997 100644 --- a/classes/Setup.php +++ b/classes/Setup.php @@ -580,9 +580,9 @@ static function ProtectUploadPath() if(WPFB_Core::$settings->protect_upload_path && is_writable(WPFB_Core::UploadDir()) && ($fp = @fopen($htaccess, 'w')) ) { - @fwrite($fp, "Order deny,allow\n"); - @fwrite($fp, "Deny from all\n"); - @fclose($fp); + fwrite($fp, "Order deny,allow\n"); + fwrite($fp, "Deny from all\n"); + fclose($fp); return @chmod($htaccess, octdec(WPFB_PERM_FILE)); } return false; @@ -659,6 +659,12 @@ static function OnActivateOrVerChange($old_ver=null) { } //delete_option('wpfilebase_dismiss_support_ending'); + // fixes files that where offline + if($old_ver === "3.4.2") { + $wpdb->query("UPDATE `$wpdb->wpfilebase_files` SET file_offline = '0' WHERE 1"); + wpfb_loadclass('Sync'); + WPFB_Sync::list_files(WPFB_Core::UploadDir()); + } } static function OnDeactivate() { diff --git a/classes/Sync.php b/classes/Sync.php index ec2b327..6910e2d 100644 --- a/classes/Sync.php +++ b/classes/Sync.php @@ -114,6 +114,35 @@ private static function PreSync($sync_data) WPFB_Admin::SyncCustomFields(); } + + public static function list_files( $folder = '', $levels = 100 ) { + if ( empty($folder) ) + return false; + + if ( ! $levels ) + return false; + + $files = array(); + // if opendir fails, try to chmod and try again + if ( ($dir = @opendir( $folder )) || (is_dir($folder) && chmod($folder, octdec(WPFB_PERM_DIR)) && ($dir = @opendir( $folder )) ) ) { + while (($file = readdir( $dir ) ) !== false ) { + if ( in_array($file, array('.', '..') ) ) + continue; + if ( is_dir( $folder . '/' . $file ) ) { + $files2 = self::list_files( $folder . '/' . $file, $levels - 1); + if ( $files2 ) + $files = array_merge($files, $files2 ); + else + $files[] = $folder . '/' . $file . '/'; + } else { + $files[] = $folder . '/' . $file; + } + } + } + @closedir( $dir ); + return $files; + } + /** * @param WPFB_SyncData $sync_data * @param boolean $output @@ -157,7 +186,7 @@ private static function SyncPhase1($sync_data, $output) // search for not added files $upload_dir = self::cleanPath(WPFB_Core::UploadDir()); - $all_files = self::cleanPath(list_files($upload_dir)); + $all_files = self::cleanPath(self::list_files($upload_dir)); $sync_data->num_all_files = count($all_files); if ($output) { @@ -350,11 +379,11 @@ private static function PostSync($sync_data, $output) // chmod if ($output) { - self::DEcho('

Setting permissions...'); + self::DEcho('

Setting permissions (files: 0'.(WPFB_PERM_FILE).', folders: 0'.(WPFB_PERM_DIR).')...'); } $sync_data->log['warnings'] += self::Chmod(self::cleanPath(WPFB_Core::UploadDir()), - array_keys($sync_data->known_filenames)); + array_filter(array_keys($sync_data->known_filenames))); if ($output) { self::DEcho('done!

'); } @@ -444,6 +473,10 @@ private static function CheckChangedFiles($sync_data, $output) $file_path = $upload_dir . $fs->path_rel; $rel_file_path = $fs->path_rel; + if(empty($fs->path_rel)) { + $rel_file_path = $fs->getFile()->GetLocalPath(true); + } + $progress_reporter->SetProgress(++$i); $progress_reporter->SetField($rel_file_path); @@ -901,7 +934,7 @@ static function Chmod($base_dir, $files) for ($i = 0; $i < count($files); $i++) { $f = "$base_dir/" . $files[$i]; if (file_exists($f)) { - @chmod($f, octdec(WPFB_PERM_FILE)); + @chmod($f, octdec(is_file($f) ? WPFB_PERM_FILE : WPFB_PERM_DIR)); if ( ! is_writable($f) && ! is_writable(dirname($f))) { $result[] = sprintf(__('File %s is not writable!', 'wp-filebase'), substr($f, $upload_dir_len)); @@ -1043,6 +1076,7 @@ class WPFB_FileState { * @return string */ public function getThumbPath() { + if(empty($this->thumb_file_name)) return false; $p = strrpos($this->path_rel, '/'); return ($p === false || $p === 0) ? $this->thumb_file_name : (substr($this->path_rel, 0, $p+1).$this->thumb_file_name); } @@ -1167,7 +1201,8 @@ private function queryDbState() { $this->num_db_files = count($this->db_file_states); for($i = 0; $i < $this->num_db_files; $i++) { $this->known_filenames[$this->db_file_states[$i]->path_rel] = 1; - $this->known_filenames[$this->db_file_states[$i]->getThumbPath()] = 1; + $t = $this->db_file_states[$i]->getThumbPath(); + if($t) $this->known_filenames[$t] = 1; } } diff --git a/readme.txt b/readme.txt index 8d2cae7..2350ca3 100644 --- a/readme.txt +++ b/readme.txt @@ -4,7 +4,7 @@ Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=wpfil Tags: filebase, filemanager, file, files, manager, upload, download, downloads, downloadmanager, images, pdf, widget, filelist, list, thumbnails, thumbnail, attachment, attachments, category, categories, media, template, ftp, http, mp3, id3 Requires at least: 3.1 Tested up to: 4.4.1 -Stable tag: 3.4.2 +Stable tag: 3.4.3 Adds a powerful download manager including file categories, downloads counter, widgets, sorted file lists and more to your WordPress blog. @@ -120,10 +120,7 @@ Goto WP-Filebase Settings and disable Permalinks under "Download". Try to disabl == Changelog == - - - -= 3.4.2 = += 3.4.3 = * New Dashboard * New upload box -- More responsive, new coloring adapts to admin theme * Added logging system diff --git a/tinymce/editor_plugin.js b/tinymce/editor_plugin.js index d5c6728..05a1f30 100644 --- a/tinymce/editor_plugin.js +++ b/tinymce/editor_plugin.js @@ -1 +1 @@ -(function() { tinymce.create('tinymce.plugins.wpfilebase', { init: function(ed, url) { ed.addButton('wpfbInsertTag', { title: 'WP-Filebase', image: url + '/images/btn.gif', onclick: (function() { var postId = ''; try { postId = tinymce.DOM.get("post_ID").value; } catch(ex) {} ed.windowManager.open( {file: (ajaxurl.replace("admin-ajax.php","?wpfilebase-screen=editor-plugin")+'&post_id='+postId+'&content='+escape(tinyMCE.activeEditor.selection.getContent())), title:'WP-Filebase', width: 810, height: 400, inline: 1}, {plugin_url: url} ); }) }); }, createControl: function(n, cm) { return null; }, getInfo: function() { return { longname: 'WP-Filebase', author: 'Fabian Schlieper', authorurl: 'http://fabi.me/', infourl: 'http://fabi.me/wp-filebase/', version: '1.0' }; } }); tinymce.PluginManager.add('wpfilebase', tinymce.plugins.wpfilebase); })(); \ No newline at end of file +(function() { tinymce.create('tinymce.plugins.wpfilebase', { init: function(ed, url) { ed.addButton('wpfbInsertTag', { title: 'WP-Filebase', image: url + '/images/btn.gif', onclick: (function() { var postId = ''; try { postId = tinymce.DOM.get("post_ID").value; } catch(ex) {} ed.windowManager.open( {file: (ajaxurl.replace("admin-ajax.php","admin.php?wpfilebase-screen=editor-plugin" ).replace('editor-plugin?','editor-plugin&')+'&post_id='+postId+'&content='+encodeURIComponent(tinyMCE.activeEditor.selection.getContent())), title:'WP-Filebase', width: 810, height: 400, inline: 1}, {plugin_url: url} ); }) }); }, createControl: function(n, cm) { return null; }, getInfo: function() { return { longname: 'WP-Filebase', author: 'Fabian Schlieper', authorurl: 'http://fabi.me/', infourl: 'http://fabi.me/wp-filebase/', version: '1.0' }; } }); tinymce.PluginManager.add('wpfilebase', tinymce.plugins.wpfilebase); })(); \ No newline at end of file diff --git a/wp-filebase.php b/wp-filebase.php index a21d88e..0793391 100644 --- a/wp-filebase.php +++ b/wp-filebase.php @@ -4,7 +4,7 @@ Plugin Name: WP-Filebase Plugin URI: https://wpfilebase.com/ Description: Adds a powerful downloads manager supporting file categories, download counter, widgets, sorted file lists and more to your WordPress blog. - Version: 3.4.2 + Version: 3.4.3 Author: Fabian Schlieper Author URI: http://fabi.me/ License: GPL2 @@ -16,7 +16,7 @@ if (!defined('WPFB')) { define('WPFB', 'wpfb'); - define('WPFB_VERSION', '3.4.2'); + define('WPFB_VERSION', '3.4.3'); define('WPFB_PLUGIN_ROOT', str_replace('\\', '/', dirname(__FILE__)) . '/'); if (!defined('ABSPATH')) { define('ABSPATH', dirname(dirname(dirname(dirname(__FILE__))))); @@ -27,7 +27,7 @@ if (!defined('WPFB_PERM_FILE')) define('WPFB_PERM_FILE', 666); if (!defined('WPFB_PERM_DIR')) - define('WPFB_PERM_DIR', 777); + define('WPFB_PERM_DIR', 777); // default unix 755 define('WPFB_OPT_NAME', 'wpfilebase'); define('WPFB_PLUGIN_NAME', 'WP-Filebase'); define('WPFB_TAG_VER', 2);