Skip to content

Commit

Permalink
fixed sync permission issue
Browse files Browse the repository at this point in the history
  • Loading branch information
fl4p committed Jan 28, 2016
1 parent 6ff4089 commit 1754a2d
Show file tree
Hide file tree
Showing 12 changed files with 76 additions and 38 deletions.
2 changes: 1 addition & 1 deletion classes/Admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
4 changes: 3 additions & 1 deletion classes/AdminBar.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php class WPFB_AdminBar {


static function AdminBar() {
global $wp_admin_bar;

Expand All @@ -14,7 +16,7 @@ static function AdminBar() {

if($current_object->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 {
Expand Down
2 changes: 1 addition & 1 deletion classes/AdminGuiTpls.php
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ static function TplsTable($type, $exclude=array(), $include=array()) {
<div class="entry-content wpfilebase-tpl-preview">
<div id="tpl-preview_<?php echo $tpl_tag ?>">
<?php if(!empty($_GET['iframe-preview'])) { ?>
<iframe src="<?php echo admin_url("?wpfilebase-screen=tpl-preview&type=$type&tag=$tpl_tag"); ?>" style="width:100%;height:220px;"></iframe>
<iframe src="<?php echo admin_url("admin.php?wpfilebase-screen=tpl-preview&type=$type&tag=$tpl_tag"); ?>" style="width:100%;height:220px;"></iframe>
<?php } else {
$table_found = !$list && (strpos($tpl_src, '<table') !== false);
if(!$list && !$table_found && strpos($tpl_src, '<tr') !== false) {
Expand Down
13 changes: 4 additions & 9 deletions classes/AdminLite.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,16 +109,11 @@ static function Init()


if (isset($_GET['wpfilebase-screen'])) {
$screen = $_GET['wpfilebase-screen'];
if ($screen == 'editor-plugin') {
require_once(WPFB_PLUGIN_ROOT . 'screens/editor-plugin.php');
switch($_GET['wpfilebase-screen']) {
case 'editor-plugin': require_once (WPFB_PLUGIN_ROOT . 'screens/editor-plugin.php'); exit;
case 'tpl-preview': require_once (WPFB_PLUGIN_ROOT . 'screens/tpl-preview.php'); exit;
}

if ($screen == 'tpl-preview') {
require_once(WPFB_PLUGIN_ROOT . 'screens/tpl-preview.php');
}

exit;
wp_die('Unknown screen '.esc_html($_GET['wpfilebase-screen']).'!');
}
}

Expand Down
5 changes: 2 additions & 3 deletions classes/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ static function GetNumFiles($sql_or_cat = -1)
return $nn;
}

static function GetNumFiles2($where, $check_permissions = true)
static function GetNumFiles2($where='', $check_permissions = true)
{
global $wpdb;
$n = $wpdb->get_var("SELECT COUNT(`{$wpdb->wpfilebase_files}`.`file_id`) FROM " . self::genSelectSql($where, $check_permissions));
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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');
Expand Down
14 changes: 9 additions & 5 deletions classes/Output.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ static function PrintJS()
echo "\n//]]>\n</script>\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
Expand Down Expand Up @@ -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 = '';
Expand Down Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion classes/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -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. <a href="%s" class="button" onclick="alert(\'Sure?\');" style="vertical-align: baseline;">Reset All Hit Counters to 0</a>'),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 <i>For members only</i> 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 <i>For members only</i> 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'))),
Expand Down
12 changes: 9 additions & 3 deletions classes/Setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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() {
Expand Down
45 changes: 40 additions & 5 deletions classes/Sync.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -350,11 +379,11 @@ private static function PostSync($sync_data, $output)

// chmod
if ($output) {
self::DEcho('<p>Setting permissions...');
self::DEcho('<p>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!</p>');
}
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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 <b>%s</b> is not writable!',
'wp-filebase'), substr($f, $upload_dir_len));
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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;
}
}

Expand Down
7 changes: 2 additions & 5 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tinymce/editor_plugin.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions wp-filebase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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__)))));
Expand All @@ -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);
Expand Down

0 comments on commit 1754a2d

Please sign in to comment.