00001 <?php
00002
00003
00004
00005 define( "GLOBAL_QUOTA_DEFAULT", 5000000 );
00006
00012 class GalleryResourceQuotas
00013 {
00014
00021 function getGlobalResourceQuota()
00022 {
00023 lt_include( PLOG_CLASS_PATH."class/config/config.class.php" );
00024 $config =& Config::getConfig();
00025 $quota = $config->getValue( "resources_quota", GLOBAL_QUOTA_DEFAULT );
00026
00027 return $quota;
00028 }
00029
00037 function getBlogResourceQuotaUsage( $userId )
00038 {
00039
00040
00041
00042
00043
00044 $model = new Model();
00045 $prefix = $model->getPrefix();
00046
00047
00048 $query = "SELECT SUM(file_size) AS total_size FROM {$prefix}gallery_resources
00049 WHERE owner_id = '".Db::qstr( $userId )."'";
00050 $result = $model->Execute( $query );
00051
00052 if( !$result )
00053 return 0;
00054 $row = $result->FetchRow();
00055 $result->Close();
00056 if( isset( $row["total_size"] ))
00057 $quota = $row["total_size"];
00058 else
00059 $quota = 0;
00060
00061 return( $quota );
00062 }
00063
00073 function isBlogOverResourceQuota( $blogId, $fileSize )
00074 {
00075
00076 lt_include( PLOG_CLASS_PATH."class/dao/blogs.class.php" );
00077 $blogs = new Blogs();
00078 $blog = $blogs->getBlogInfo( $blogId );
00079 if( !$blog )
00080 return false;
00081
00082 $blogQuota = $blog->getResourcesQuota();
00083
00084
00085 if( $blogQuota == 0 )
00086 return false;
00087
00088
00089 $currentBytes = GalleryResourceQuotas::getBlogResourceQuotaUsage( $blogId );
00090
00091 if( ($currentBytes + $fileSize) > $blogQuota )
00092 return true;
00093 else
00094 return false;
00095 }
00096 }
00097 ?>