Skip to content

Commit

Permalink
= 3.4.4 =
Browse files Browse the repository at this point in the history
* Fixed jQuery treeview compatibility issue
* Sync: improved thumbnail handling (stop thumbnails from being added as files)
  • Loading branch information
fl4p committed Apr 18, 2016
1 parent 1754a2d commit 0aa7dc5
Show file tree
Hide file tree
Showing 6 changed files with 473 additions and 9 deletions.
6 changes: 3 additions & 3 deletions classes/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -403,8 +403,8 @@ function DeleteThumbnail()
$this->DBSave();
}

// completly removes the file from DB and FS
function Remove($bulk = false)
// completly removes the file from DB (and FS)
function Remove($bulk = false, $dont_delete = false)
{
global $wpdb;

Expand All @@ -422,7 +422,7 @@ function Remove($bulk = false)

$this->Lock(true); // prevent Delete() from saving to DB!

return $this->Delete();
return $dont_delete || $this->Delete();
}

private function getInfoValue($path)
Expand Down
38 changes: 37 additions & 1 deletion classes/Sync.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ class WPFB_Sync
static $error_log_file;
static $debug_output = false;

const OLD_THUMB_SUFFIX = '/-([0-9]+)x([0-9]+)\.(jpg|jpeg|png|gif)$/i';

static function InitClass()
{
wpfb_loadclass("Admin", "GetID3", "FileUtils", "Misc");
Expand Down Expand Up @@ -631,6 +633,9 @@ static function GetMemStats()
);
}

/**
* @param WPFB_SyncData $sync_data
*/
static function GetThumbnails($sync_data)
{
$num_files_to_add = $num_new_files = count($sync_data->new_files);
Expand Down Expand Up @@ -738,7 +743,23 @@ static function GetThumbnails($sync_data)
$sync_data->num_files_to_add--;
}
}
}

// FIX: check for db files with a thumbnail-style file name and assign it to a file with similar name
foreach($sync_data->db_file_states as $fs_thumb) {
$matches = array();
if (preg_match(self::OLD_THUMB_SUFFIX, $fs_thumb->path_rel, $matches)
&& ($file=$sync_data->getDbStateByPathPrefix(substr($fs_thumb->path_rel, 0, -strlen($matches[0])).'.'))
&& $file->getFile()->IsLocal()
&& ($is = getimagesize($fs_thumb->getFile()->GetLocalPath()))
&& $is[0] == $matches[1] && $is[1] == $matches[2]
) {
$fs_thumb->getFile()->DeleteThumbnail();
$file->getFile()->DeleteThumbnail();
$file->getFile()->file_thumbnail = basename($fs_thumb->getFile()->GetLocalPath());
$file->getFile()->DBSave(true);
$fs_thumb->getFile()->Remove(false, true);
}
}}

static function SyncCats($cats = null, $output = false)
{
Expand Down Expand Up @@ -1206,4 +1227,19 @@ private function queryDbState() {
}
}

/**
* @param string $prefix
*
* @return WPFB_FileState
*/
public function getDbStateByPathPrefix($prefix) {
$pl = strlen($prefix);
foreach($this->db_file_states as $fs) {
if( strlen($fs->path_rel) > $pl && strncmp($fs->path_rel, $prefix, $pl) === 0 ) {
return $fs;
}
}
return null;
}

}
Loading

0 comments on commit 0aa7dc5

Please sign in to comment.