/** * 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; }
/** * 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) { $forced_refresh_thumb = $forced_refresh_thumb || $file->file_rescan_pending > 1; $file->file_rescan_pending = max($file->file_rescan_pending, $forced_refresh_thumb ? 2 : 1); if (!$file->TryScanLock()) { WPFB_Core::LogMsg("ERROR: ScanFile {$file} locking failed!", 'sync'); return false; } $file_path = $file->GetLocalPath(); if (!$file->IsLocal()) { $res = WPFB_Admin::SideloadFile($file, $file_path); if ($res['error']) { WPFB_Core::LogMsg("ERROR: ScanFile({$file}) download {$file->GetRemoteUri()} failed {$res['error']}!", 'sync'); $file->file_rescan_pending = 0; $file->DbSave(true); return false; } } elseif (!is_file($file_path) || !is_readable($file_path)) { if (WPFB_Core::$settings->remove_missing_files) { WPFB_Core::LogMsg("ScanFile({$file}) removing missing file!", 'sync'); $file->Remove(); return true; } else { $file->file_offline = true; $file->file_mtime = 0; $file->DbSave(true); 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) || !is_file($file->GetThumbPath()))) { $pwe = substr($file->GetLocalPath(), 0, strrpos($file->GetLocalPath(), '.') + 1); if ($pwe && (file_exists($thumb = $pwe . 'png') || file_exists($thumb = $pwe . 'thumb.png') || file_exists($thumb = $pwe . 'jpg') || file_exists($thumb = $pwe . 'thumb.jpg') || file_exists($thumb = $pwe . 'gif') || file_exists($thumb = $pwe . 'thumb.gif'))) { $file->file_thumbnail = basename($thumb); $dest_thumb = $file->GetThumbPath(true); if ($dest_thumb != $thumb) { $dir = dirname($dest_thumb); if (!is_dir($dir)) { WPFB_Admin::Mkdir($dir); } rename($thumb, $dest_thumb); } } } } $file->DBSave(true); // the UpdateCachedFileInfo/StoreFileInfo will delete the file if necessary! (no need of $tmp_file value!) if (!WPFB_GetID3::UpdateCachedFileInfo($file)) { WPFB_Core::LogMsg("ScanFile({$file}) file scan failed!", 'sync'); return false; } return true; }
?> </label> <input name="file_remote_uri" id="file_remote_uri" type="text" value="<?php echo esc_attr($file->file_remote_uri); ?> " style="width:98%" /><br /> <fieldset><legend class="hidden"></legend> <label><input type="radio" name="file_remote_redirect" value="1" <?php checked($file->IsRemote()); ?> onchange="jQuery('#wpfilebase-remote-scan-wrap').show();" /><?php _e('Redirect download to URL', WPFB); ?> </label> <label><input type="radio" name="file_remote_redirect" value="0" <?php checked($file->IsLocal()); ?> onchange="jQuery('#wpfilebase-remote-scan-wrap').hide();" /><?php _e('Copy file into Filebase (sideload)', WPFB); ?> </label> <span id="wpfilebase-remote-scan-wrap" class="hidden"><br /><label><input type="checkbox" name="file_remote_scan" value="1" checked="checked" /><?php _e('Scan remote file (disable for large files)', WPFB); ?> </label></span> </fieldset> </div> </div> </td> </tr> <tr>