Exemplo n.º 1
0
 private static function SyncPase1($sync_data, $output)
 {
     self::PrintDebugTrace("sync_phase_1");
     if ($output) {
         $ms = self::GetMemStats();
         self::DEcho('<p>' . sprintf(__('Starting sync. Memory usage: %s - Limit: %s', WPFB), WPFB_Output::FormatFilesize($ms['used']), WPFB_Output::FormatFilesize($ms['limit'])) . ' ' . ($ms['used'] > self::HIGH_START_MEM ? __('<b>Note:</b> The memory usage seems to be quite high. Please disable other plugins to lower the memory consumption.') : '') . '</p>');
     }
     if ($output) {
         self::DEcho('<p>' . __('Checking for file changes...', WPFB) . ' ');
     }
     self::CheckChangedFiles($sync_data);
     if ($output) {
         self::DEcho('done!</p>');
     }
     foreach ($sync_data->cats as $id => $cat) {
         $cat_path = $cat->GetLocalPath(true);
         if (!@is_dir($cat_path) || !@is_readable($cat_path)) {
             if (WPFB_Core::$settings->remove_missing_files) {
                 $cat->Delete();
             }
             $sync_data->log['missing_folders'][$id] = $cat;
             continue;
         }
     }
     if ($output) {
         self::DEcho('<p>' . __('Searching for new files...', WPFB) . ' ');
     }
     self::PrintDebugTrace("new_files");
     // search for not added files
     $upload_dir = self::cleanPath(WPFB_Core::UploadDir());
     $all_files = self::cleanPath(list_files($upload_dir));
     $sync_data->num_all_files = count($all_files);
     $num_new_files = 0;
     // 1ps filter	 (check extension, special file names, and filter existing file names and thumbnails)
     $fext_blacklist = array_map('strtolower', array_map('trim', explode(',', WPFB_Core::$settings->fext_blacklist)));
     for ($i = 0; $i < $sync_data->num_all_files; $i++) {
         // $fn = $upload_dir.implode('/',array_map('urlencode', explode('/', substr($all_files[$i], strlen($upload_dir)))));
         $fn = $all_files[$i];
         $fbn = basename($fn);
         if (strlen($fn) < 2 || $fbn[0] == '.' || strpos($fn, '/.tmp') !== false || $fbn == '_wp-filebase.css' || strpos($fbn, '_caticon.') !== false || strpos($fbn, '_wpfb_') === 0 || strpos($fbn, '.__info.xml') !== false || in_array(substr($fn, strlen($upload_dir)), $sync_data->known_filenames) || !is_file($fn) || !is_readable($fn) || !empty($fext_blacklist) && self::fast_in_array(trim(strrchr($fbn, '.'), '.'), $fext_blacklist)) {
             continue;
         }
         // look for an equal missing file -> this file has been moved then!
         foreach ($sync_data->missing_files as $mf) {
             if ($fbn == $mf->file_name && filesize($fn) == $mf->file_size && filemtime($fn) == $mf->file_mtime) {
                 // make sure cat tree to new file location exists, and set the cat of the moved file
                 $cat_id = WPFB_Admin::CreateCatTree($fn);
                 if (!empty($cat_id['error'])) {
                     $sync_data->log['error'][] = $cat_id['error'];
                     continue 2;
                 }
                 $result = $mf->ChangeCategoryOrName($cat_id, null, true);
                 if (is_array($result) && !empty($result['error'])) {
                     $sync_data->log['error'][] = $result['error'];
                     continue 2;
                 }
                 // rm form missing list, add to changed
                 unset($sync_data->missing_files[$mf->file_id]);
                 $sync_data->log['changed'][$mf->file_id] = $mf;
                 continue 2;
             }
         }
         $sync_data->new_files[$num_new_files] = $fn;
         $num_new_files++;
     }
     foreach ($sync_data->missing_files as $mf) {
         if (WPFB_Core::$settings->remove_missing_files) {
             $mf->Remove();
         } elseif (!$mf->file_offline) {
             $mf->file_offline = true;
             // set offline if not found
             if (!$mf->locked) {
                 $mf->DBSave();
             }
         }
         $sync_data->log['missing_files'][$mf->file_id] = $mf;
     }
     self::PrintDebugTrace("new_files_end");
     $sync_data->num_files_to_add = $num_new_files;
     // handle thumbnails
     self::GetThumbnails($sync_data);
     self::PrintDebugTrace("post_get_thumbs");
 }