function avatars_remove_user_files($user) { global $globals; if ($globals['Amazon_S3_media_bucket']) { Media::rm("avatars/{$user}-*"); } if ($globals['Amazon_S3_local_cache'] || !$globals['Amazon_S3_media_bucket']) { $subdir = @get_avatars_dir() . '/' . get_cache_dir_chain($user); if ($subdir && ($handle = @opendir($subdir))) { while (false !== ($file = readdir($handle))) { if (preg_match("/^{$user}-/", $file)) { @unlink($subdir . '/' . $file); } } closedir($handle); } } }
function has_thumb() { global $globals; if ($this->thumb_x > 0 && $this->thumb_y > 0) { $chain = get_cache_dir_chain($this->id); $file = $globals['cache_dir']."/$chain/thumb-$this->id.jpg"; $filepath = mnmpath."/$file"; if (is_readable($filepath)) { return $globals['base_static'] . $file; } elseif ($globals['Amazon_S3_media_bucket'] && $globals['Amazon_S3_local_cache']) { create_cache_dir_chain(mnmpath.'/'.$globals['cache_dir'], $chain); // Get thumbnail from S3 if (Media::get("$this->id.jpg", 'thumbs', $filepath)) { return $globals['base_static'] . $file; } else { // Do extra check, if S3 is working, mark thumb as deleted if (($buckets = Media::buckets(false)) && in_array($globals['Amazon_S3_media_bucket'], $buckets) && is_writable(mnmpath.'/'.$globals['cache_dir'])) { // Double check syslog(LOG_NOTICE, "Meneame, deleting unexisting thumb for $this->id"); $this->delete_thumb(); } } } } return false; }
function get_avatar_url($user, $avatar, $size) { global $globals, $db; // If it does not get avatar status, check the database if ($user > 0 && $avatar < 0) { $avatar = (int) $db->get_var("select user_avatar from users where user_id = $user"); } if ($avatar > 0) { if ($globals['Amazon_S3_media_url'] && !$globals['Amazon_S3_local_cache']) { return $globals['Amazon_S3_media_url']."/avatars/$user-$avatar-$size.jpg"; } elseif ($globals['cache_dir']) { $file = $globals['cache_dir'].'/'.get_cache_dir_chain($user). "/$user-$avatar-$size.jpg"; // Don't check every time, but 1/10, decrease VM pressure // Disabled for the moment, it fails just too much for size 40 //if (rand(0, 10) < 10) return $globals['base_url'] . $file; $file_path = mnmpath.'/'.$file; if ($globals['avatars_check_always']) { if (is_readable($file_path)) { return $globals['base_static'] . $file; } else { return $globals['base_url'] . "backend/get_avatar.php?id=$user&size=$size&time=$avatar"; } } else { return $globals['base_static'] . $file; } } } return get_no_avatar_url($size); }