static function InitClass() { wpfb_loadclass("Admin", "GetID3", "FileUtils", "Misc"); require_once ABSPATH . 'wp-admin/includes/file.php'; @ini_set('max_execution_time', '0'); @set_time_limit(0); if (!empty($_GET['output']) || !empty($_GET['debug'])) { @ini_set('display_errors', 1); @error_reporting(E_ERROR | E_WARNING | E_PARSE); set_error_handler(array(__CLASS__, 'CaptureError')); set_exception_handler(array(__CLASS__, 'CaptureException')); register_shutdown_function(array(__CLASS__, 'CaptureShutdown')); } self::$error_log_file = WPFB_Core::UploadDir() . '/_wpfb_sync_errors_' . md5(WPFB_Core::UploadDir()) . '.log'; if (is_file(self::$error_log_file) && is_writable(self::$error_log_file)) { // don't append to big files (4MiB) @file_put_contents(self::$error_log_file, "\n" . str_repeat('=', 20) . "\nINIT SYNC\n", filesize(self::$error_log_file) > 4194304 ? 0 : FILE_APPEND); } @ini_set("error_log", self::$error_log_file); if (!empty($_GET['output']) || !empty($_GET['debug'])) { @ini_set('display_errors', 1); @error_reporting(E_ERROR | E_WARNING | E_PARSE); set_error_handler(array(__CLASS__, 'CaptureError')); set_exception_handler(array(__CLASS__, 'CaptureException')); register_shutdown_function(array(__CLASS__, 'CaptureShutdown')); } // raise memory limit if needed if (WPFB_Misc::ParseIniFileSize(ini_get('memory_limit')) < 64000000) { @ini_set('memory_limit', '128M'); @ini_set('memory_limit', '256M'); @ini_set('memory_limit', '512M'); } }
static function AnalyzeFile($file) { @ini_set('max_execution_time', '0'); @set_time_limit(0); $filename = is_string($file) ? $file : $file->GetLocalPath(); $info = WPFB_Core::$settings->disable_id3 ? array() : self::GetEngine()->analyze($filename); if (!empty($_GET['debug'])) { wpfb_loadclass('Sync'); WPFB_Sync::PrintDebugTrace("file_analyzed_" . $file->GetLocalPathRel()); } return $info; }
/** * Intesive analysis of file contents. Does _not_ make changes to the file or store anything in the DB! * * @param type $file * @return type */ private static function analyzeFile($file) { @ini_set('max_execution_time', '0'); @set_time_limit(0); $filename = is_string($file) ? $file : $file->GetLocalPath(); $times = array(); $times['analyze'] = microtime(true); $info = WPFB_Core::$settings->disable_id3 ? array() : self::GetEngine()->analyze($filename); if (!WPFB_Core::$settings->disable_id3 && class_exists('getid3_lib')) { getid3_lib::CopyTagsToComments($info); } if (!empty($_GET['debug'])) { wpfb_loadclass('Sync'); WPFB_Sync::PrintDebugTrace("file_analyzed_" . $file->GetLocalPathRel()); } $times['end'] = microtime(true); $t_keys = array_keys($times); $into['debug'] = array('timestamp' => $times[$t_keys[0]], 'timings' => array()); for ($i = 1; $i < count($t_keys); $i++) { $info['debug']['timings'][$t_keys[$i - 1]] = round(($times[$t_keys[$i]] - $times[$t_keys[$i - 1]]) * 1000); } return $info; }
static function OnActivateOrVerChange($old_ver = null) { global $wpdb; // make sure that either wp-filebase or wp-filebase pro is enabled bot not both! if (!function_exists('is_plugin_active')) { require_once ABSPATH . 'wp-admin/includes/plugin.php'; } if (is_plugin_active('wp-filebase-pro/wp-filebase.php')) { deactivate_plugins('wp-filebase/wp-filebase.php'); } wpfb_loadclass('Admin', 'File', 'Category'); self::SetupDBTables($old_ver); $old_options = get_option(WPFB_OPT_NAME); self::AddOptions(); self::AddTpls($old_ver); $new_options = get_option(WPFB_OPT_NAME); WPFB_Admin::SettingsUpdated($old_options, $new_options); self::ProtectUploadPath(); $sync_data_file = WPFB_Core::UploadDir() . '/._sync.data'; is_file($sync_data_file) && unlink($sync_data_file); WPFB_Admin::WPCacheRejectUri(WPFB_Core::$settings->download_base . '/', $old_options['download_base'] . '/'); // TODO, do this in background if (WPFB_Category::GetNumCats() < self::MANY_CATEGORIES && WPFB_File::GetNumFiles() < self::MANY_FILES) { // avoid long activation time wpfb_loadclass('Sync'); WPFB_Sync::SyncCats(); WPFB_Sync::UpdateItemsPath(); } if (!wp_next_scheduled(WPFB . '_cron')) { wp_schedule_event(time() + 20, 'hourly', WPFB . '_cron'); } if (!get_option('wpfb_install_time')) { add_option('wpfb_install_time', ($ft = (int) mysql2date('U', $wpdb->get_var("SELECT file_mtime FROM {$wpdb->wpfilebase_files} ORDER BY file_mtime ASC LIMIT 1"))) > 0 ? $ft : time(), null, 'no'); } $wp_upload = wp_upload_dir(); // move old css if (file_exists(WPFB_Core::GetOldCustomCssPath())) { $wp_upload_ok = empty($wp_upload['error']) && is_writable($wp_upload['basedir']); if ($wp_upload_ok && @rename(WPFB_Core::GetOldCustomCssPath(), $wp_upload['basedir'] . '/wp-filebase.css')) { update_option('wpfb_css', $wp_upload['baseurl'] . '/wp-filebase.css?t=' . time()); } } // refresh css URL (in case upload_dir changed or upgrade from free to pro) update_option('wpfb_css', trailingslashit(file_exists($wp_upload['basedir'] . '/wp-filebase.css') ? $wp_upload['baseurl'] : WPFB_PLUGIN_URI) . 'wp-filebase.css?t=' . time()); flush_rewrite_rules(); // change mapping of file browser folder icons (2340897_sdf.svg => svg-.....svg!) $image_mappings = array('1449888880_folder.svg' => 'svg-folder.svg', '1449888883_folder.svg' => 'svg-folder-blue.svg', '1449888885_folder-blue.svg' => 'svg-folderblue.svg', '1449888886_folder-green.svg' => 'svg-folder-green.svg'); $folder_icons_base = '/plugins/wp-filebase/images/folder-icons/'; $folder_icon = substr(WPFB_Core::$settings->folder_icon, strlen($folder_icons_base)); if (isset($image_mappings[$folder_icon])) { WPFB_Core::UpdateOption('folder_icon', $folder_icons_base . $image_mappings[$folder_icon]); } //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()); } }
/** * * @param WPFB_SyncData $sync_data * @param boolean $output */ private static function CheckChangedFiles($sync_data, $output) { if ($sync_data->num_db_files == 0) { return; } if ($output) { self::DEcho('<p>' . sprintf(__('Checking %d files for changes...', 'wp-filebase'), $sync_data->num_db_files) . ' '); } $sync_id3 = !WPFB_Core::$settings->disable_id3; $upload_dir = trailingslashit(self::cleanPath(WPFB_Core::UploadDir())); wpfb_loadclass('ProgressReporter'); $progress_reporter = new WPFB_ProgressReporter(!$output); $progress_reporter->InitProgress($sync_data->num_db_files); $progress_reporter->InitProgressField('Current File: %#%', '-', true); $i = 0; /* * if ($file->file_category > 0 && is_null($file->GetParent())) { $sync_data->log['warnings'][] = sprintf(__('Category (ID %d) of file %s does not exist!', 'wp-filebase'), $file->file_category, $file->GetLocalPathRel()); } */ foreach ($sync_data->db_file_states as $fs) { $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); $sync_data->known_filenames[$rel_file_path] = 1; if ($fs->thumb_file_name) { $rel_thumb_path = $fs->getThumbPath(); $sync_data->known_filenames[$rel_thumb_path] = 1; // remove thumb if missing if (!file_exists($upload_dir . $rel_thumb_path)) { $fs->getFile()->file_thumbnail = ''; $fs->getFile()->DBSave(); $sync_data->log['changed'][$fs->id] = $fs->getFile(); } } if ($fs->has_uri) { continue; } if (!@is_file($file_path) || !@is_readable($file_path)) { $sync_data->missing_files[$fs->id] = $fs->getFile(); continue; } $file_hash = $sync_data->hash_sync ? WPFB_Admin::GetFileHash($file_path) : ''; $file_size = WPFB_FileUtils::GetFileSize($file_path); $file_mtime = filemtime($file_path); if ($sync_data->hash_sync && $fs->hash != $file_hash || $fs->size != $file_size || $fs->mtime != $file_mtime) { $file = $fs->getFile(); $file->file_size = $file_size; $file->file_mtime = $file_mtime; $file->file_hash = $sync_data->hash_sync ? $file_hash : WPFB_Admin::GetFileHash($file_path); WPFB_Sync::ScanFile($file); // this can be async! $res = $file->DBSave(); if (!empty($res['error'])) { $sync_data->log['error'][$fs->id] = $res['error'] . " (file {$rel_file_path})"; } else { $sync_data->log['changed'][$fs->id] = $fs->getFile(); } } } if ($output) { self::DEcho('- done!</p>'); } }
/** * 1. Checks if file is actually present and readable on file system and either sets file offline or completly removes it * 2. If file hash not set, calculate it * 3. Try to generate a thumbnail if it does not exists * 4. Update ID3 info (with _async_ RPC if enabled) * * @param WPFB_File $file * @param bool $forced_refresh_thumb * @return bool */ static function ScanFile($file, $forced_refresh_thumb = false, $allow_async = true) { if (!empty($_GET['debug'])) { WPFB_Sync::PrintDebugTrace("scanning_file:" . $file->GetLocalPathRel()); } $file_path = $file->GetLocalPath(); $tmp_file = false; if (!$file->IsLocal()) { $res = WPFB_Admin::SideloadFile($file->GetRemoteUri(), $file_path); if ($res['error']) { return false; } $tmp_file = true; } elseif (!is_file($file_path) || !is_readable($file_path)) { if (WPFB_Core::$settings->remove_missing_files) { $file->Remove(); return true; } else { $file->file_offline = true; $file->file_mtime = 0; $file->file_rescan_pending = 1; $file->DbSave(); return true; } } if (empty($file->file_hash)) { $file->file_hash = WPFB_Admin::GetFileHash($file->GetLocalPath()); } if (empty($file->file_thumbnail) || $forced_refresh_thumb || !is_file($file->GetThumbPath())) { $file->Lock(true); $file->CreateThumbnail(); // this only deltes old thumb if success $file->Lock(false); if (WPFB_Core::$settings->base_auto_thumb && empty($file->file_thumbnail)) { $thumb = false; $pwe = substr($file->GetLocalPath(), 0, strrpos($file->GetLocalPath(), '.') + 1); if ($pwe && (file_exists($thumb = $pwe . 'png') || file_exists($thumb = $pwe . 'jpg') || file_exists($thumb = $pwe . 'gif'))) { $file->file_thumbnail = basename($thumb); $dthumb = $file->GetThumbPath(true); if ($dthumb != $thumb) { $dir = dirname($dthumb); if (!is_dir($dir)) { WPFB_Admin::Mkdir($dir); } rename($thumb, $dthumb); } } } } $file->file_rescan_pending = 1; $file->DBSave(); WPFB_GetID3::UpdateCachedFileInfo($file); return true; }
static function OnActivateOrVerChange($old_ver = null) { global $wpdb; // make sure that either wp-filebase or wp-filebase pro is enabled bot not both! if (!function_exists('is_plugin_active')) { require_once ABSPATH . 'wp-admin/includes/plugin.php'; } if (is_plugin_active('wp-filebase-pro/wp-filebase.php')) { deactivate_plugins('wp-filebase/wp-filebase.php'); } wpfb_loadclass('Admin', 'File', 'Category'); self::SetupDBTables($old_ver); $old_options = get_option(WPFB_OPT_NAME); self::AddOptions(); self::AddTpls($old_ver); $new_options = get_option(WPFB_OPT_NAME); WPFB_Admin::SettingsUpdated($old_options, $new_options); self::ProtectUploadPath(); WPFB_Admin::WPCacheRejectUri(WPFB_Core::$settings->download_base . '/', $old_options['download_base'] . '/'); $ncats = WPFB_Category::GetNumCats(); $nfiles = WPFB_File::GetNumFiles(); if ($ncats < self::MANY_CATEGORIES && $nfiles < self::MANY_FILES) { // avoid long activation time wpfb_loadclass('Sync'); WPFB_Sync::SyncCats(); WPFB_Sync::UpdateItemsPath(); } if (!wp_next_scheduled(WPFB . '_cron')) { wp_schedule_event(time(), 'hourly', WPFB . '_cron'); } if (!get_option('wpfb_install_time')) { add_option('wpfb_install_time', ($ft = (int) mysql2date('U', $wpdb->get_var("SELECT file_mtime FROM {$wpdb->wpfilebase_files} ORDER BY file_mtime ASC LIMIT 1"))) > 0 ? $ft : time(), null, 'no'); } // move old css if (file_exists(WPFB_Core::GetOldCustomCssPath())) { $wp_upload = wp_upload_dir(); $wp_upload_ok = empty($wp_upload['error']) && is_writable($wp_upload['basedir']); if ($wp_upload_ok && @rename(WPFB_Core::GetOldCustomCssPath(), $wp_upload['basedir'] . '/wp-filebase.css')) { update_option('wpfb_css', $wp_upload['baseurl'] . '/wp-filebase.css?t=' . time()); } } flush_rewrite_rules(); //delete_option('wpfilebase_dismiss_support_ending'); }
static function Display() { global $wpdb, $user_ID; //register_shutdown_function( create_function('','$error = error_get_last(); if( $error && $error[\'type\'] != E_STRICT ){print_r( $error );}else{return true;}') ); wpfb_loadclass('File', 'Category', 'Admin', 'Output'); $_POST = stripslashes_deep($_POST); $_GET = stripslashes_deep($_GET); $action = !empty($_POST['action']) ? $_POST['action'] : (!empty($_GET['action']) ? $_GET['action'] : ''); $clean_uri = remove_query_arg(array('message', 'action', 'file_id', 'cat_id', 'deltpl', 'hash_sync', 'doit', 'ids', 'files', 'cats', 'batch_sync')); // keep search keyword // switch simple/extended form if (isset($_GET['exform'])) { $exform = !empty($_GET['exform']) && $_GET['exform'] == 1; update_user_option($user_ID, WPFB_OPT_NAME . '_exform', $exform, true); } else { $exform = (bool) get_user_option(WPFB_OPT_NAME . '_exform'); } if (!empty($_GET['wpfb-hide-how-start'])) { update_user_option($user_ID, WPFB_OPT_NAME . '_hide_how_start', 1); } $show_how_start = !(bool) get_user_option(WPFB_OPT_NAME . '_hide_how_start'); WPFB_Admin::PrintFlattrHead(); ?> <script type="text/javascript"> /* Liking/Donate Bar */ if(typeof(jQuery) != 'undefined') { jQuery(document).ready(function(){ if(getUserSetting("wpfilebase_hidesuprow",false) == 1) { jQuery('#wpfb-liking').hide(); jQuery('#wpfb-liking-toggle').addClass('closed'); } jQuery('#wpfb-liking-toggle').click(function(){ jQuery('#wpfb-liking').slideToggle(); jQuery(this).toggleClass('closed'); setUserSetting("wpfilebase_hidesuprow", 1-getUserSetting("wpfilebase_hidesuprow",false), 0); }); }); } </script> <div class="wrap"> <div id="icon-wpfilebase" class="icon32"><br /></div> <h2><?php echo WPFB_PLUGIN_NAME; ?> </h2> <?php if ($show_how_start) { wpfb_call('AdminHowToStart', 'Display'); } if (!empty($_GET['action'])) { echo '<p><a href="' . $clean_uri . '" class="button">' . __('Go back') . '</a></p>'; } switch ($action) { default: $clean_uri = remove_query_arg('pagenum', $clean_uri); $upload_dir = WPFB_Core::UploadDir(); $upload_dir_rel = str_replace(ABSPATH, '', $upload_dir); $chmod_cmd = "CHMOD " . WPFB_PERM_DIR . " " . $upload_dir_rel; if (!is_dir($upload_dir)) { $result = WPFB_Admin::Mkdir($upload_dir); if ($result['error']) { $error_msg = sprintf(__('The upload directory <code>%s</code> does not exists. It could not be created automatically because the directory <code>%s</code> is not writable. Please create <code>%s</code> and make it writable for the webserver by executing the following FTP command: <code>%s</code>', WPFB), $upload_dir_rel, str_replace(ABSPATH, '', $result['parent']), $upload_dir_rel, $chmod_cmd); } else { wpfb_call('Setup', 'ProtectUploadPath'); } } elseif (!is_writable($upload_dir)) { $error_msg = sprintf(__('The upload directory <code>%s</code> is not writable. Please make it writable for PHP by executing the follwing FTP command: <code>%s</code>', WPFB), $upload_dir_rel, $chmod_cmd); } if (!empty($error_msg)) { echo '<div class="error default-password-nag"><p>' . $error_msg . '</p></div>'; } if (!empty(WPFB_Core::$settings->tag_conv_req)) { echo '<div class="updated"><p><a href="' . add_query_arg('action', 'convert-tags') . '">'; _e('WP-Filebase content tags must be converted', WPFB); echo '</a></p></div><div style="clear:both;"></div>'; } if (!get_post(WPFB_Core::$settings->file_browser_post_id)) { echo '<div class="updated"><p>'; printf(__('File Browser post or page not set! Some features like search will not work. <a href="%s">Click here to set the File Browser Post ID.</a>', WPFB), esc_attr(admin_url('admin.php?page=wpfilebase_sets#' . sanitize_title(__('File Browser', WPFB))))); echo '</p></div><div style="clear:both;"></div>'; } /* wpfb_loadclass('Config'); if(!WPFB_Config::IsWritable()) { echo '<div class="updated"><p>'; printf(__('The config file %s is not writable or could not be created. Please create the file and make it writable for the webserver.',WPFB), WPFB_Config::$file); echo '</p></div><div style="clear:both;"></div>'; } */ ?> <?php if (self::PluginHasBeenUsedAWhile(true)) { self::ProUpgradeNag(); } if (self::PluginHasBeenUsedAWhile()) { ?> <div id="wpfb-support-col"> <div id="wpfb-liking-toggle"></div> <h3><?php _e('Like WP-Filebase?', WPFB); ?> </h3> <div id="wpfb-liking"> <!-- <div style="text-align: center;"><iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwordpress.org%2Fextend%2Fplugins%2Fwp-filebase%2F&send=false&layout=button_count&width=150&show_faces=false&action=like&colorscheme=light&font&height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:140px; height:21px; display:inline-block; text-align:center;" <?php echo ' allowTransparency="true"'; ?> ></iframe></div> --> <div style="text-align: center;" ><a href="https://twitter.com/wpfilebase" class="twitter-follow-button" data-show-count="false">Follow @wpfilebase</a> <script type="text/javascript">!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="//platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script></div> <p>Please <a href="http://wordpress.org/support/view/plugin-reviews/wp-filebase">give it a good rating</a>.</p> <p>For Cloud support and lots of other advanced features consider an</p> <p style="text-align: center;"><a href="https://wpfilebase.com/?ref=dblike" class="button-primary">Upgrade to Pro</a></p> <p style="text-align:right;float:right;font-style:italic;">Thanks, Fabian</p> <!-- <div style="text-align: center;"> <?php //WPFB_Admin::PrintPayPalButton() ?> <?php //WPFB_Admin::PrintFlattrButton() ?> </div> --> </div> </div> <?php } ?> <div id="wpfb-stats-wrap" style="float:right; border-left: 1px solid #eee; margin-left: 5px;"> <div id="col-container"> <div id="col-right"> <div class="col-wrap"> <h3><?php _e('Traffic', WPFB); ?> </h3> <table class="wpfb-stats-table"> <?php $traffic_stats = wpfb_call('Misc', 'GetTraffic'); $limit_day = WPFB_Core::$settings->traffic_day * 1048576; $limit_month = WPFB_Core::$settings->traffic_month * 1073741824; ?> <tr> <td><?php if ($limit_day > 0) { self::ProgressBar($traffic_stats['today'] / $limit_day, WPFB_Output::FormatFilesize($traffic_stats['today']) . '/' . WPFB_Output::FormatFilesize($limit_day)); } else { echo WPFB_Output::FormatFilesize($traffic_stats['today']); } ?> </td> <th scope="row"><?php _e('Today', WPFB); ?> </th> </tr> <tr> <td><?php if ($limit_month > 0) { self::ProgressBar($traffic_stats['month'] / $limit_month, WPFB_Output::FormatFilesize($traffic_stats['month']) . '/' . WPFB_Output::FormatFilesize($limit_month)); } else { echo WPFB_Output::FormatFilesize($traffic_stats['month']); } ?> </td> <th scope="row"><?php _e('This Month', WPFB); ?> </th> </tr> <tr> <td><?php echo WPFB_Output::FormatFilesize($wpdb->get_var("SELECT SUM(file_size) FROM {$wpdb->wpfilebase_files}")); ?> </td> <th scope="row"><?php _e('Total File Size', WPFB); ?> </th> </tr> </table> </div> </div><!-- /col-right --> <div id="col-left"> <div class="col-wrap"> <h3><?php _e('Statistics', WPFB); ?> </h3> <table class="wpfb-stats-table"> <tr> <td><?php echo WPFB_File::GetNumFiles(); ?> </td> <th scope="row"><?php _e('Files', WPFB); ?> </th> </tr> <tr> <td><?php echo WPFB_Category::GetNumCats(); ?> </td> <th scope="row"><?php _e('Categories', WPFB); ?> </th> </tr> <tr> <td><?php echo "" . (int) $wpdb->get_var("SELECT SUM(file_hits) FROM {$wpdb->wpfilebase_files}"); ?> </td> <th scope="row"><?php _e('Downloads', WPFB); ?> </th> </tr> </table> </div> </div><!-- /col-left --> </div><!-- /col-container --> </div> <div> <!-- <h2><?php _e('Tools'); ?> </h2> --> <?php $cron_sync_desc = ''; if (WPFB_Core::$settings->cron_sync) { $cron_sync_desc .= __('Automatic sync is enabled. Cronjob scheduled hourly.'); $last_sync_time = intval(get_option(WPFB_OPT_NAME . '_cron_sync_time')); $cron_sync_desc .= $last_sync_time > 0 ? " (" . sprintf(__('Last cron sync on %1$s at %2$s.', WPFB), date_i18n(get_option('date_format'), $last_sync_time), date_i18n(get_option('time_format'), $last_sync_time)) . ")" : ''; } else { $cron_sync_desc .= __('Cron sync is disabled.', WPFB); } $tools = array(array('url' => add_query_arg(array('action' => 'sync')), 'icon' => 'activity', 'label' => __('Sync Filebase', WPFB), 'desc' => __('Synchronises the database with the file system. Use this to add FTP-uploaded files.', WPFB) . '<br />' . $cron_sync_desc)); if (current_user_can('install_plugins')) { // is admin? $new_tag = self::NewExtensionsAvailable() ? '<span class="wp-ui-notification new-exts">new</span>' : ''; $tools[] = array('url' => add_query_arg(array('action' => 'install-extensions')), 'icon' => 'plug', 'label' => __('Extensions', WPFB) . $new_tag, 'desc' => __('Install Extensions to extend functionality of WP-Filebase', WPFB)); } ?> <div id="wpfb-tools"> <h2><?php _e('Tools'); ?> </h2> <ul> <?php foreach ($tools as $id => $tool) { ?> <li id="wpfb-tool-<?php echo $id; ?> "><a href="<?php echo $tool['url']; ?> " <?php if (!empty($tool['confirm'])) { ?> onclick="return confirm('<?php echo $tool['confirm']; ?> ')" <?php } ?> class="button"><span style="background-image:url(<?php echo esc_attr(WPFB_PLUGIN_URI); ?> images/<?php echo $tool['icon']; ?> .png)"></span><?php echo $tool['label']; ?> </a></li> <?php } ?> </ul> <?php foreach ($tools as $id => $tool) { ?> <div id="wpfb-tool-desc-<?php echo $id; ?> " class="tool-desc"> <?php echo $tool['desc']; ?> </div> <?php } ?> <script> if(!jQuery(document.body).hasClass('mobile')) { jQuery('#wpfb-tools li').mouseenter(function(e) { jQuery('#wpfb-tools .tool-desc').hide(); jQuery('#wpfb-tool-desc-'+this.id.substr(10)).show(); }); } </script> <?php if (!empty(WPFB_Core::$settings->tag_conv_req)) { ?> <p><a href="<?php echo add_query_arg('action', 'convert-tags'); ?> " class="button"><?php _e('Convert old Tags', WPFB); ?> </a> <?php printf(__('Convert tags from versions earlier than %s.', WPFB), '0.2.0'); ?> </p> <?php } ?> <!-- <p><a href="<?php echo add_query_arg('action', 'add-urls'); ?> " class="button"><?php _e('Add multiple URLs', WPFB); ?> </a> <?php _e('Add multiple remote files at once.', WPFB); ?> </p> --> </div> <div style="clear: both;"></div> <?php if (WPFB_Core::CurUserCanUpload()) { WPFB_Admin::PrintForm('file', null, array('exform' => $exform)); } ?> <?php if (!$show_how_start) { // display how start here if its hidden wpfb_call('AdminHowToStart', 'Display'); } ?> <h2><?php _e('About'); ?> </h2> <p> <?php echo WPFB_PLUGIN_NAME . ' ' . WPFB_VERSION; ?> by Fabian Schlieper <a href="http://fabi.me/"> <?php if (strpos($_SERVER['SERVER_PROTOCOL'], 'HTTPS') === false) { ?> <img src="http://fabi.me/misc/wpfb_icon.gif?lang=<?php if (defined('WPLANG')) { echo WPLANG; } ?> " alt="" /><?php } ?> fabi.me</a><br/> Includes the great file analyzer <a href="http://www.getid3.org/">getID3()</a> by James Heinrich.<br /> Tools Icons by <a href="http://www.icondeposit.com/">Matt Gentile</a>. </p> <?php if (current_user_can('edit_files')) { ?> <p><a href="<?php echo admin_url('plugins.php?wpfb-uninstall=1'); ?> " class="button"><?php _e('Completely Uninstall WP-Filebase'); ?> </a></p> <?php } break; case 'convert-tags': ?> <h2><?php _e('Tag Conversion'); ?> </h2><?php if (empty($_REQUEST['doit'])) { echo '<div class="updated"><p>'; _e('<strong>Important:</strong> before updating, please <a href="http://codex.wordpress.org/WordPress_Backups">backup your database and files</a>. For help with updates, visit the <a href="http://codex.wordpress.org/Updating_WordPress">Updating WordPress</a> Codex page.'); echo '</p></div>'; echo '<p><a href="' . add_query_arg('doit', 1) . '" class="button">' . __('Continue') . '</a></p>'; break; } $result = wpfb_call('Setup', 'ConvertOldTags'); ?> <p><?php printf(__('%d Tags in %d Posts has been converted.'), $result['n_tags'], count($result['tags'])); ?> </p> <ul> <?php if (!empty($result['tags'])) { foreach ($result['tags'] as $post_title => $tags) { echo "<li><strong>" . esc_html($post_title) . "</strong><ul>"; foreach ($tags as $old => $new) { echo "<li>{$old} => {$new}</li>"; } echo "</ul></li>"; } } ?> </ul> <?php if (!empty($result['errors'])) { ?> <h2><?php _e('Errors'); ?> </h2> <ul><?php foreach ($result['errors'] as $post_title => $err) { echo "<li><strong>" . esc_html($post_title) . ": </strong> " . esc_html($err) . "<ul>"; } ?> </ul> <?php } $opts = WPFB_Core::GetOpt(); unset($opts['tag_conv_req']); update_option(WPFB_OPT_NAME, $opts); WPFB_Core::$settings = (object) $opts; break; // convert-tags // convert-tags case 'del': if (!empty($_REQUEST['files']) && WPFB_Core::CurUserCanUpload()) { $ids = explode(',', $_REQUEST['files']); $nd = 0; foreach ($ids as $id) { $id = intval($id); if (($file = WPFB_File::GetFile($id)) != null && $file->CurUserCanEdit()) { $file->Remove(true); $nd++; } } WPFB_File::UpdateTags(); echo '<div id="message" class="updated fade"><p>' . sprintf(__('%d Files removed'), $nd) . '</p></div>'; } if (!empty($_REQUEST['cats']) && WPFB_Core::CurUserCanCreateCat()) { $ids = explode(',', $_REQUEST['cats']); $nd = 0; foreach ($ids as $id) { $id = intval($id); if (($cat = WPFB_Category::GetCat($id)) != null) { $cat->Delete(); $nd++; } } echo '<div id="message" class="updated fade"><p>' . sprintf(__('%d Categories removed'), $nd) . '</p></div>'; } case 'sync': echo '<h2>' . __('Synchronisation') . '</h2>'; wpfb_loadclass('Sync'); $result = WPFB_Sync::Sync(!empty($_GET['hash_sync']), true); if (!is_null($result)) { WPFB_Sync::PrintResult($result); } if (empty($_GET['hash_sync'])) { echo '<p><a href="' . add_query_arg('hash_sync', 1) . '" class="button">' . __('Complete file sync', WPFB) . '</a> ' . __('Checks files for changes, so more reliable but might take much longer. Do this if you uploaded/changed files with FTP.', WPFB) . '</p>'; } break; // sync // sync case 'batch-upload': wpfb_loadclass('BatchUploader'); $batch_uploader = new WPFB_BatchUploader(); $batch_uploader->Display(); break; case 'reset-hits': global $wpdb; $n = 0; if (current_user_can('manage_options')) { $n = $wpdb->query("UPDATE `{$wpdb->wpfilebase_files}` SET file_hits = 0 WHERE 1=1"); } echo "<p>"; printf(__('Done. %d Files affected.'), $n); echo "</p>"; break; case 'install-extensions': wpfb_call('AdmInstallExt', 'Display'); break; } // switch ?> </div> <!-- wrap --> <?php }
static function Display() { global $wpdb, $user_ID; require_once ABSPATH . 'wp-admin/includes/dashboard.php'; wpfb_loadclass('AdminDashboard'); add_thickbox(); wp_enqueue_script('dashboard'); if (wp_is_mobile()) { wp_enqueue_script('jquery-touch-punch'); } //register_shutdown_function( create_function('','$error = error_get_last(); if( $error && $error[\'type\'] != E_STRICT ){print_r( $error );}else{return true;}') ); wpfb_loadclass('File', 'Category', 'Admin', 'Output'); $_POST = stripslashes_deep($_POST); $_GET = stripslashes_deep($_GET); $action = !empty($_POST['action']) ? $_POST['action'] : (!empty($_GET['action']) ? $_GET['action'] : ''); $clean_uri = remove_query_arg(array('message', 'action', 'file_id', 'cat_id', 'deltpl', 'hash_sync', 'doit', 'ids', 'files', 'cats', 'batch_sync')); // keep search keyword WPFB_Admin::PrintFlattrHead(); ?> <script type="text/javascript"> /* Liking/Donate Bar */ if(typeof(jQuery) != 'undefined') { jQuery(document).ready(function(){ if(getUserSetting("wpfilebase_hidesuprow",false) == 1) { jQuery('#wpfb-liking').hide(); jQuery('#wpfb-liking-toggle').addClass('closed'); } jQuery('#wpfb-liking-toggle').click(function(){ jQuery('#wpfb-liking').slideToggle(); jQuery(this).toggleClass('closed'); setUserSetting("wpfilebase_hidesuprow", 1-getUserSetting("wpfilebase_hidesuprow",false), 0); }); }); } </script> <div class="wrap"> <div id="icon-wpfilebase" class="icon32"><br /></div> <h2><?php echo WPFB_PLUGIN_NAME; ?> </h2> <?php switch ($action) { default: $clean_uri = remove_query_arg('pagenum', $clean_uri); $upload_dir = WPFB_Core::UploadDir(); $upload_dir_rel = str_replace(ABSPATH, '', $upload_dir); $chmod_cmd = "CHMOD " . WPFB_PERM_DIR . " " . $upload_dir_rel; if (!is_dir($upload_dir)) { $result = WPFB_Admin::Mkdir($upload_dir); if ($result['error']) { $error_msg = sprintf(__('The upload directory <code>%s</code> does not exists. It could not be created automatically because the directory <code>%s</code> is not writable. Please create <code>%s</code> and make it writable for the webserver by executing the following FTP command: <code>%s</code>', 'wp-filebase'), $upload_dir_rel, str_replace(ABSPATH, '', $result['parent']), $upload_dir_rel, $chmod_cmd); } else { wpfb_call('Setup', 'ProtectUploadPath'); } } elseif (!is_writable($upload_dir)) { $error_msg = sprintf(__('The upload directory <code>%s</code> is not writable. Please make it writable for PHP by executing the follwing FTP command: <code>%s</code>', 'wp-filebase'), $upload_dir_rel, $chmod_cmd); } if (!empty($error_msg)) { echo '<div class="error default-password-nag"><p>' . $error_msg . '</p></div>'; } if (!empty(WPFB_Core::$settings->tag_conv_req)) { echo '<div class="updated"><p><a href="' . add_query_arg('action', 'convert-tags') . '">'; _e('WP-Filebase content tags must be converted', 'wp-filebase'); echo '</a></p></div><div style="clear:both;"></div>'; } ?> <?php if (self::PluginHasBeenUsedAWhile(true)) { self::ProUpgradeNag(); } if (self::PluginHasBeenUsedAWhile()) { ?> <div id="wpfb-support-col"> <div id="wpfb-liking-toggle"></div> <h3><?php _e('Like WP-Filebase?', 'wp-filebase'); ?> </h3> <div id="wpfb-liking"> <!-- <div style="text-align: center;"><iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwordpress.org%2Fextend%2Fplugins%2Fwp-filebase%2F&send=false&layout=button_count&width=150&show_faces=false&action=like&colorscheme=light&font&height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:140px; height:21px; display:inline-block; text-align:center;" <?php echo ' allowTransparency="true"'; ?> ></iframe></div> --> <div style="text-align: center;" ><a href="https://twitter.com/wpfilebase" class="twitter-follow-button" data-show-count="false">Follow @wpfilebase</a> <script type="text/javascript">!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="//platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script></div> <p>Please <a href="http://wordpress.org/support/view/plugin-reviews/wp-filebase">give it a good rating</a>.</p> <p>For Cloud support and lots of other advanced features consider an</p> <p style="text-align: center;"><a href="https://wpfilebase.com/?ref=dblike" class="button-primary">Upgrade to Pro</a></p> <p style="text-align: center;"><a href="http://demo.wpfilebase.com/?ref=dblike" class="button">Live Pro Demo</a></p> <p style="text-align:right;float:right;font-style:italic;">Thanks, Fabian</p> <!-- <div style="text-align: center;"> <?php //WPFB_Admin::PrintPayPalButton() ?> <?php //WPFB_Admin::PrintFlattrButton() ?> </div> --> </div> </div> <?php } ?> <div id="dashboard-widgets-wrap"> <?php wp_dashboard(); ?> </div><!-- dashboard-widgets-wrap --> <?php break; case 'convert-tags': ?> <h2><?php _e('Tag Conversion'); ?> </h2><?php if (empty($_REQUEST['doit'])) { echo '<div class="updated"><p>'; _e('<strong>Important:</strong> before updating, please <a href="http://codex.wordpress.org/WordPress_Backups">backup your database and files</a>. For help with updates, visit the <a href="http://codex.wordpress.org/Updating_WordPress">Updating WordPress</a> Codex page.'); echo '</p></div>'; echo '<p><a href="' . add_query_arg('doit', 1) . '" class="button">' . __('Continue') . '</a></p>'; break; } $result = wpfb_call('Setup', 'ConvertOldTags'); ?> <p><?php printf(__('%d Tags in %d Posts has been converted.'), $result['n_tags'], count($result['tags'])); ?> </p> <ul> <?php if (!empty($result['tags'])) { foreach ($result['tags'] as $post_title => $tags) { echo "<li><strong>" . esc_html($post_title) . "</strong><ul>"; foreach ($tags as $old => $new) { echo "<li>{$old} => {$new}</li>"; } echo "</ul></li>"; } } ?> </ul> <?php if (!empty($result['errors'])) { ?> <h2><?php _e('Errors'); ?> </h2> <ul><?php foreach ($result['errors'] as $post_title => $err) { echo "<li><strong>" . esc_html($post_title) . ": </strong> " . esc_html($err) . "<ul>"; } ?> </ul> <?php } $opts = WPFB_Core::GetOpt(); unset($opts['tag_conv_req']); update_option(WPFB_OPT_NAME, $opts); WPFB_Core::$settings = (object) $opts; break; // convert-tags // convert-tags case 'del': if (!empty($_REQUEST['files']) && WPFB_Core::CurUserCanUpload()) { $ids = explode(',', $_REQUEST['files']); $nd = 0; foreach ($ids as $id) { $id = intval($id); if (($file = WPFB_File::GetFile($id)) != null && $file->CurUserCanDelete()) { $file->Remove(true); $nd++; } } WPFB_File::UpdateTags(); echo '<div id="message" class="updated fade"><p>' . sprintf(__('%d Files removed'), $nd) . '</p></div>'; } if (!empty($_REQUEST['cats']) && WPFB_Core::CurUserCanCreateCat()) { $ids = explode(',', $_REQUEST['cats']); $nd = 0; foreach ($ids as $id) { $id = intval($id); if (($cat = WPFB_Category::GetCat($id)) != null) { $cat->Delete(); $nd++; } } echo '<div id="message" class="updated fade"><p>' . sprintf(__('%d Categories removed'), $nd) . '</p></div>'; } case 'sync': echo '<h2>' . __('Synchronisation') . '</h2>'; wpfb_loadclass('Sync'); $result = WPFB_Sync::Sync(!empty($_GET['hash_sync']), true); if (!is_null($result)) { WPFB_Sync::PrintResult($result); } if (empty($_GET['hash_sync'])) { echo '<p><a href="' . add_query_arg('hash_sync', 1) . '" class="button">' . __('Complete file sync', 'wp-filebase') . '</a> ' . __('Checks files for changes, so more reliable but might take much longer. Do this if you uploaded/changed files with FTP.', 'wp-filebase') . '</p>'; } if (empty($_GET['debug'])) { echo '<p><a href="' . add_query_arg('debug', 1) . '" class="button">' . __('Debug Sync', 'wp-filebase') . '</a> ' . __('Run to get more Debug Info in case Sync crashes', 'wp-filebase') . '</p>'; } break; // sync // sync case 'batch-upload': wpfb_loadclass('BatchUploader'); $batch_uploader = new WPFB_BatchUploader(); $batch_uploader->Display(); break; case 'reset-hits': global $wpdb; $n = 0; if (current_user_can('manage_options')) { $n = $wpdb->query("UPDATE `{$wpdb->wpfilebase_files}` SET file_hits = 0 WHERE 1=1"); } echo "<p>"; printf(__('Done. %d Files affected.'), $n); echo "</p>"; break; case 'install-extensions': wpfb_call('AdmInstallExt', 'Display'); break; } // switch if (!empty($_GET['action'])) { echo '<p><a href="' . $clean_uri . '" class="button">' . __('Go back') . '</a></p>'; } ?> </div> <!-- wrap --> <?php }
static function InsertFile($data, $in_gui = false) { if (!is_object($data)) { $data = (object) $data; } $file_id = isset($data->file_id) ? (int) $data->file_id : 0; $file = null; if ($file_id > 0) { $file = WPFB_File::GetFile($file_id); if ($file == null) { $file_id = 0; } } $update = $file_id > 0 && $file != null && $file->is_file; if (!$update) { $file = new WPFB_File(array('file_id' => 0)); } $file->Lock(true); $add_existing = !empty($data->add_existing); // if the file is added by a sync (not uploaded) if (!$add_existing) { self::SyncCustomFields(); } // dont sync custom fields when file syncing! if (!empty($data->file_flash_upload)) { // check for flash upload and validate! $file_flash_upload = json_decode($data->file_flash_upload, true); $file_flash_upload['tmp_name'] = WPFB_Core::UploadDir() . '/' . str_replace('../', '', $file_flash_upload['tmp_name']); if (is_file($file_flash_upload['tmp_name'])) { $data->file_upload = $file_flash_upload; } } // are we uploading a file? $upload = !$add_existing && ((@is_uploaded_file($data->file_upload['tmp_name']) || !empty($data->file_flash_upload)) && !empty($data->file_upload['name'])); $remote_upload = !$add_existing && !$upload && !empty($data->file_remote_uri) && (!$update || $file->file_remote_uri != $data->file_remote_uri); $remote_redirect = !empty($data->file_remote_redirect) && !empty($data->file_remote_uri); if ($remote_redirect) { $remote_scan = !empty($data->file_remote_scan); } // if we change the actual file on disk $change = $upload || $remote_upload; if ($update && ($change || !empty($data->file_rename) && $data->file_rename != $file->file_name) && $file->IsScanLocked()) { return array('error' => sprintf(__('%s is currently locked. Please try again in %s.', 'wp-filebase'), $file, human_time_diff(time(), $file->file_scan_lock))); } // are we uploading a thumbnail? $upload_thumb = !$add_existing && @is_uploaded_file($data->file_upload_thumb['tmp_name']); if ($upload_thumb && !(WPFB_FileUtils::FileHasImageExt($data->file_upload_thumb['name']) && WPFB_FileUtils::IsValidImage($data->file_upload_thumb['tmp_name']))) { return array('error' => __('Thumbnail is not a valid image!.', 'wp-filebase')); } if ($remote_upload) { unset($file_src_path); $remote_file_info = self::GetRemoteFileInfo($data->file_remote_uri); if (is_wp_error($remote_file_info)) { return array('error' => sprintf(__('Could not get file information from %s!', 'wp-filebase'), $data->file_remote_uri) . ' (' . $remote_file_info->get_error_message() . ')'); } $file_name = $remote_file_info['name']; if ($remote_file_info['size'] > 0) { $file->file_size = $remote_file_info['size']; } if ($remote_file_info['time'] > 0) { $file->SetModifiedTime($remote_file_info['time']); } } else { $file_src_path = $upload ? $data->file_upload['tmp_name'] : ($add_existing ? $data->file_path : null); $file_name = $upload ? str_replace('\\', '', $data->file_upload['name']) : (empty($file_src_path) && $update ? $file->file_name : substr(strrchr(str_replace('\\', '/', $file_src_path), '/'), 1)); // no basename here! } if ($upload) { $data->file_rename = null; } // VALIDATION $current_user = wp_get_current_user(); if (empty($data->frontend_upload) && !$add_existing && empty($current_user->ID)) { return array('error' => __('Could not get user id!', 'wp-filebase')); } if (!$update && !$add_existing && !$upload && !$remote_upload) { return array('error' => __('No file was uploaded.', 'wp-filebase')); } // check extension if ($upload || $add_existing) { if (!self::IsAllowedFileExt($file_name)) { if (isset($file_src_path)) { @unlink($file_src_path); } return array('error' => sprintf(__('The file extension of the file <b>%s</b> is forbidden!', 'wp-filebase'), $file_name)); } } // check url if ($remote_upload && !preg_match('/^(https?|file):\\/\\//', $data->file_remote_uri)) { return array('error' => __('Only HTTP links are supported.', 'wp-filebase')); } // do some simple file stuff if ($update && (!empty($data->file_delete_thumb) || $upload_thumb)) { $file->DeleteThumbnail(); } // delete thumbnail if user wants to if ($update && ($upload || $remote_upload)) { $file->Delete(true); } // if we update, delete the old file (keep thumb!) // handle display name and version if (isset($data->file_version)) { $file->file_version = $data->file_version; } if (isset($data->file_display_name)) { $file->file_display_name = $data->file_display_name; } $result = self::ParseFileNameVersion($file_name, $file->file_version); if (empty($file->file_version)) { $file->file_version = $result['version']; } if (empty($file->file_display_name)) { $file->file_display_name = $result['title']; } // handle category & name $file_category = isset($data->file_category) ? is_object($data->file_category) ? $data->file_category->GetId() : 0 + $data->file_category : 0; $new_cat = null; if ($file_category > 0 && ($new_cat = WPFB_Category::GetCat($file_category)) == null) { $file_category = 0; } // this inherits permissions as well: $result = $file->ChangeCategoryOrName($file_category, empty($data->file_rename) ? $file_name : $data->file_rename, $add_existing, !empty($data->overwrite)); if (is_array($result) && !empty($result['error'])) { return $result; } $prev_read_perms = $file->file_offline ? array('administrator') : $file->GetReadPermissions(); // explicitly set permissions: if (!empty($data->file_perm_explicit) && isset($data->file_user_roles)) { $file->SetReadPermissions(empty($data->file_user_roles) || count(array_filter($data->file_user_roles)) == 0 ? array() : $data->file_user_roles); } // if there is an uploaded file if ($upload) { $file_dest_path = $file->GetLocalPath(); $file_dest_dir = dirname($file_dest_path); if (@file_exists($file_dest_path)) { return array('error' => sprintf(__('File %s already exists. You have to delete it first!', 'wp-filebase'), $file->GetLocalPath())); } if (!is_dir($file_dest_dir)) { self::Mkdir($file_dest_dir); } // try both move_uploaded_file for http, rename for flash uploads! if (!(move_uploaded_file($file_src_path, $file_dest_path) || rename($file_src_path, $file_dest_path)) || !@file_exists($file_dest_path)) { return array('error' => sprintf(__('Unable to move file %s! Is the upload directory writeable?', 'wp-filebase'), $file->file_name) . ' ' . $file->GetLocalPathRel()); } } elseif ($remote_upload) { if (!$remote_redirect || $remote_scan) { $tmp_file = self::GetTmpFile($file->file_name); $result = self::SideloadFile($data->file_remote_uri, $tmp_file, $in_gui ? $remote_file_info['size'] : -1); if (is_array($result) && !empty($result['error'])) { return $result; } if (!rename($tmp_file, $file->GetLocalPath())) { return array('error' => "Could not rename temp file {$tmp_file} -> {$file->GetLocalPath()} !"); } if (!$remote_redirect) { $data->file_remote_uri = ''; } } } elseif (!$add_existing && !$update) { return array('error' => __('No file was uploaded.', 'wp-filebase')); } // handle date/time stuff if (!empty($data->file_date)) { $file->file_date = $data->file_date; } elseif ($add_existing || empty($file->file_date)) { $file->file_date = file_exists($file->GetLocalPath()) ? gmdate('Y-m-d H:i:s', min(filemtime($file->GetLocalPath()), time()) + get_option('gmt_offset') * HOUR_IN_SECONDS) : current_time('mysql'); } if (!$update) { // since 4.4, wpdb will acutally set NULL values, so make sure everything is an empty string $file->file_hash = ''; $file->file_remote_uri = ''; $file->file_tags = ''; $file->file_license = ''; $file->file_password = ''; $file->file_last_dl_ip = ''; $file->file_added_by = empty($current_user) ? 0 : $current_user->ID; } self::fileApplyMeta($file, $data); // save into db $file->Lock(false); $result = $file->DBSave(); if (is_array($result) && !empty($result['error'])) { return $result; } $file_id = (int) $result['file_id']; if (!$update) { // on new file, remove any existing data global $wpdb; $wpdb->query("DELETE FROM {$wpdb->wpfilebase_files_id3} WHERE file_id = {$file_id}"); } if (!empty($data->no_scan) && !empty($data->add_rsync)) { $file->file_rescan_pending = 1; } // get file info if ((!$update || !$remote_redirect) && is_file($file->GetLocalPath())) { $old_size = $file->file_size; $old_mtime = $file->file_mtime; $old_hash = $file->file_hash; $file->file_size = isset($data->file_size) ? $data->file_size : WPFB_FileUtils::GetFileSize($file->GetLocalPath()); $file->file_mtime = filemtime($file->GetLocalPath()); $size_or_mtime_changed = $old_size != $file->file_size || $old_mtime != $file->file_mtime; $file->file_hash = empty($data->no_scan) ? WPFB_Admin::GetFileHash($file->GetLocalPath()) : ($size_or_mtime_changed ? '' : $old_hash); // TODO: revise conditions / make more readable if (!empty($data->no_scan) && ($upload || $add_existing || $size_or_mtime_changed)) { $file->file_rescan_pending = 1; } elseif (empty($data->no_scan) && ($upload || !$update || $file->file_hash != $old_hash)) { wpfb_loadclass('Sync'); WPFB_Sync::ScanFile($file, false, !$remote_redirect); // dont do async scan if temporary file } } else { if (isset($data->file_size)) { $file->file_size = $data->file_size; } if (isset($data->file_hash)) { $file->file_hash = $data->file_hash; } } if ($remote_redirect) { if (file_exists($file->GetLocalPath())) { @unlink($file->GetLocalPath()); } // when download redircet the actual files is not needed anymore } else { // set permissions 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 } // handle thumbnail if ($upload_thumb) { $file->DeleteThumbnail(); // delete the old thumbnail (if existing) $thumb_dest_path = dirname($file->GetLocalPath()) . '/thumb_' . $data->file_upload_thumb['name']; if (@move_uploaded_file($data->file_upload_thumb['tmp_name'], $thumb_dest_path)) { $file->CreateThumbnail($thumb_dest_path, true); } } else { if ($upload || $remote_upload || $add_existing) { if ($add_existing && !empty($data->file_thumbnail)) { $file->file_thumbnail = $data->file_thumbnail; // we already got the thumbnail on disk! } elseif (empty($file->file_thumbnail) && !$upload_thumb && (!$remote_redirect || $remote_scan) && empty($data->no_scan)) { // WPFB_Sync::ScanFile should've done this, this may never be reached $file->CreateThumbnail(); // check if the file is an image and create thumbnail } } } // save into db again $result = $file->DBSave(); if (is_array($result) && !empty($result['error'])) { return $result; } return array('error' => false, 'file_id' => $file_id, 'file' => $file); }
/** * * @param WPFB_CCronWorker $worker */ static function BgScanWork($worker = false) { wpfb_loadclass('Sync'); WPFB_Sync::RescanFiles(); }