/**
  * Returns an array of the allowed upload sizes in bytes.
  * Return 'space_allowed' as -1 to not allow uploads.
  * Return 'space_allowed' as 0 to allow unlimited uploads
  * Return 'max_single_upload' as 0 to not set a limit
  *
  * @access	public
  * @param	string		MD5 post key
  * @param	id			Member ID
  * @return	array 		[ 'space_used', 'space_left', 'space_allowed', 'max_single_upload' ]
  */
 public function getSpaceAllowance($post_key = '', $member_id = '')
 {
     $max_php_size = intval(IPSLib::getMaxPostSize());
     $member_id = intval($member_id ? $member_id : $this->memberData['member_id']);
     $space_left = 0;
     $space_used = 0;
     $space_allowed = 0;
     $max_single_upload = 0;
     $space_calculated = 0;
     if ($post_key) {
         //-----------------------------------------
         // Check to make sure we're not attempting
         // to upload to another's post...
         //-----------------------------------------
         if (!$this->memberData['g_is_supmod']) {
             $post = $this->DB->buildAndFetch(array('select' => '*', 'from' => 'posts', 'where' => "post_key='" . $post_key . "'"));
             if ($post['post_key'] and $post['author_id'] != $member_id) {
                 $space_allowed = -1;
                 $space_calculated = 1;
             }
         }
     }
     //-----------------------------------------
     // Generate total space allowed
     //-----------------------------------------
     $total_space_allowed = ($this->memberData['g_blog_attach_per_entry'] ? $this->memberData['g_blog_attach_per_entry'] : $this->memberData['g_blog_attach_max']) * 1024;
     //-----------------------------------------
     // Allowed to attach?
     //-----------------------------------------
     if (!$member_id) {
         $space_allowed = -1;
     }
     if (!$space_calculated) {
         //-----------------------------------------
         // Generate space allowed figure
         //-----------------------------------------
         if ($total_space_allowed > 0) {
             if ($this->memberData['g_blog_attach_per_entry']) {
                 //-----------------------------------------
                 // Per post limit...
                 //-----------------------------------------
                 $_space_used = $this->DB->buildAndFetch(array('select' => 'SUM(attach_filesize) as figure', 'from' => 'attachments', 'where' => "attach_post_key='" . $post_key . "'"));
                 $space_used = intval($_space_used['figure']);
                 $space_allowed = intval($this->memberData['g_blog_attach_per_entry'] * 1024 - $space_used);
                 $space_allowed = $space_allowed < 0 ? 0 : $space_allowed;
             } else {
                 //-----------------------------------------
                 // Global limit...
                 //-----------------------------------------
                 $_space_used = $this->DB->buildAndFetch(array('select' => 'SUM(attach_filesize) as figure', 'from' => 'attachments', 'where' => 'attach_member_id=' . $member_id . " AND attach_rel_module in('blogentry','blogcblock')"));
                 $space_used = intval($_space_used['figure']);
                 $space_allowed = intval($this->memberData['g_blog_attach_max'] * 1024 - $space_used);
                 $space_allowed = $space_allowed < 0 ? 0 : $space_allowed;
             }
         } else {
             # Unlimited
             $space_allowed = 0;
         }
         //-----------------------------------------
         // Generate space left figure
         //-----------------------------------------
         $space_left = $space_allowed ? $space_allowed : 0;
         $space_left = $space_left < 0 ? 0 : $space_left;
         //-----------------------------------------
         // Generate max upload size
         //-----------------------------------------
         if (!$max_single_upload) {
             if ($space_left > 0 and $space_left < $max_php_size) {
                 $max_single_upload = $space_left;
             } else {
                 if ($max_php_size) {
                     $max_single_upload = $max_php_size;
                 }
             }
         }
     }
     $return = array('space_used' => $space_used, 'space_left' => $space_left, 'space_allowed' => $space_allowed, 'max_single_upload' => $max_single_upload, 'total_space_allowed' => $total_space_allowed);
     return $return;
 }
Пример #2
0
 /**
  * Returns an array of the allowed upload sizes in bytes.
  * Return 'space_allowed' as -1 to not allow uploads.
  * Return 'space_allowed' as 0 to allow unlimited uploads
  * Return 'max_single_upload' as 0 to not set a limit
  *
  * @param	string		MD5 post key
  * @param	id			Member ID
  * @return	array 		[ 'space_used', 'space_left', 'space_allowed', 'max_single_upload' ]
  */
 public function getSpaceAllowance($post_key = '', $member_id = '')
 {
     $max_php_size = IPSLib::getMaxPostSize();
     $member_id = intval($member_id ? $member_id : $this->memberData['member_id']);
     $forum_id = intval(ipsRegistry::$request['forum_id'] ? ipsRegistry::$request['forum_id'] : ipsRegistry::$request['f']);
     $space_left = 0;
     $space_used = 0;
     $space_allowed = 0;
     $max_single_upload = 0;
     $space_calculated = 0;
     if ($post_key) {
         //-----------------------------------------
         // Check to make sure we're not attempting
         // to upload to another's post...
         //-----------------------------------------
         if (!$this->memberData['g_is_supmod'] and !$this->memberData['is_mod']) {
             $post = $this->DB->buildAndFetch(array('select' => '*', 'from' => 'posts', 'where' => "post_key='{$post_key}'"));
             if ($post['post_key'] and $post['author_id'] != $member_id) {
                 $space_allowed = -1;
                 $space_calculated = 1;
             }
         }
     }
     //-----------------------------------------
     // Generate total space allowed
     //-----------------------------------------
     $total_space_allowed = ($this->memberData['g_attach_per_post'] ? $this->memberData['g_attach_per_post'] : $this->memberData['g_attach_max']) * 1024;
     //-----------------------------------------
     // Allowed to attach?
     //-----------------------------------------
     if (!$member_id or !$forum_id) {
         $space_allowed = -1;
     }
     if (IPSMember::checkPermissions('upload', $forum_id) !== TRUE) {
         $space_allowed = -1;
     } else {
         if (!$space_calculated) {
             //-----------------------------------------
             // Generate space allowed figure
             //-----------------------------------------
             if ($this->memberData['g_attach_per_post']) {
                 //-----------------------------------------
                 // Per post limit...
                 //-----------------------------------------
                 $_space_used = $this->DB->buildAndFetch(array('select' => 'SUM(attach_filesize) as figure', 'from' => 'attachments', 'where' => "attach_post_key='{$post_key}'"));
                 $space_used = $_space_used['figure'] ? $_space_used['figure'] : 0;
             } else {
                 //-----------------------------------------
                 // Global limit...
                 //-----------------------------------------
                 $_space_used = $this->DB->buildAndFetch(array('select' => 'SUM(attach_filesize) as figure', 'from' => 'attachments', 'where' => "attach_member_id={$member_id} AND attach_rel_module IN( 'post', 'msg' )"));
                 $space_used = $_space_used['figure'] ? $_space_used['figure'] : 0;
             }
             if ($this->memberData['g_attach_max'] > 0) {
                 if ($this->memberData['g_attach_per_post']) {
                     $_g_space_used = $this->DB->buildAndFetch(array('select' => 'SUM(attach_filesize) as figure', 'from' => 'attachments', 'where' => "attach_member_id={$member_id} AND attach_rel_module IN( 'post', 'msg' )"));
                     $g_space_used = $_g_space_used['figure'] ? $_g_space_used['figure'] : 0;
                     if ($this->memberData['g_attach_max'] * 1024 - $g_space_used < 0) {
                         $space_used = $g_space_used;
                         $total_space_allowed = $this->memberData['g_attach_max'] * 1024;
                         $space_allowed = $this->memberData['g_attach_max'] * 1024 - $space_used;
                         $space_allowed = $space_allowed < 0 ? -1 : $space_allowed;
                     } else {
                         $space_allowed = $this->memberData['g_attach_per_post'] * 1024 - $space_used;
                         $space_allowed = $space_allowed < 0 ? -1 : $space_allowed;
                     }
                 } else {
                     $space_allowed = $this->memberData['g_attach_max'] * 1024 - $space_used;
                     $space_allowed = $space_allowed < 0 ? -1 : $space_allowed;
                 }
             } else {
                 if ($this->memberData['g_attach_per_post']) {
                     $space_allowed = $this->memberData['g_attach_per_post'] * 1024 - $space_used;
                     $space_allowed = $space_allowed < 0 ? -1 : $space_allowed;
                 } else {
                     # Unlimited
                     $space_allowed = 0;
                 }
             }
             //-----------------------------------------
             // Generate space left figure
             //-----------------------------------------
             $space_left = $space_allowed ? $space_allowed : 0;
             $space_left = $space_left < 0 ? -1 : $space_left;
             //-----------------------------------------
             // Generate max upload size
             //-----------------------------------------
             if (!$max_single_upload) {
                 if ($space_left > 0 and $space_left < $max_php_size) {
                     $max_single_upload = $space_left;
                 } else {
                     if ($max_php_size) {
                         $max_single_upload = $max_php_size;
                     }
                 }
             }
         }
     }
     IPSDebug::fireBug('info', array('Space left: ' . $space_left));
     IPSDebug::fireBug('info', array('Max PHP size: ' . $max_php_size));
     IPSDebug::fireBug('info', array('Max single file size: ' . $max_single_upload));
     $return = array('space_used' => $space_used, 'space_left' => $space_left, 'space_allowed' => $space_allowed, 'max_single_upload' => $max_single_upload, 'total_space_allowed' => $total_space_allowed);
     return $return;
 }
Пример #3
0
 /**
  * Returns an array of the allowed upload sizes in bytes.
  * Return 'space_allowed' as -1 to not allow uploads.
  * Return 'space_allowed' as 0 to allow unlimited uploads
  * Return 'max_single_upload' as 0 to not set a limit
  *
  * @param	string		MD5 post key
  * @param	id			Member ID
  * @return	array 		[ 'space_used', 'space_left', 'space_allowed', 'max_single_upload' ]
  */
 public function getSpaceAllowance($post_key = '', $member_id = '')
 {
     $max_php_size = IPSLib::getMaxPostSize();
     $member_id = intval($member_id ? $member_id : $this->memberData['member_id']);
     $space_left = 0;
     $space_used = 0;
     $space_allowed = 0;
     $max_single_upload = 0;
     //-----------------------------------------
     // Allowed to attach?
     //-----------------------------------------
     if (!$member_id) {
         $space_allowed = -1;
     } else {
         //-----------------------------------------
         // Generate total space allowed
         //-----------------------------------------
         $total_space_allowed = ($this->memberData['g_attach_per_post'] ? $this->memberData['g_attach_per_post'] : $this->memberData['g_attach_max']) * 1024;
         //-----------------------------------------
         // Generate space used figure
         //-----------------------------------------
         if ($this->memberData['g_attach_per_post']) {
             //-----------------------------------------
             // Per post limit...
             //-----------------------------------------
             $_space_used = $this->DB->buildAndFetch(array('select' => 'SUM(attach_filesize) as figure', 'from' => 'attachments', 'where' => "attach_post_key='" . $post_key . "'"));
             $space_used = $_space_used['figure'] ? $_space_used['figure'] : 0;
         } else {
             //-----------------------------------------
             // Global limit...
             //-----------------------------------------
             $_space_used = $this->DB->buildAndFetch(array('select' => 'SUM(attach_filesize) as figure', 'from' => 'attachments', 'where' => 'attach_member_id=' . $member_id . " AND attach_rel_module IN( 'post', 'msg' )"));
             $space_used = $_space_used['figure'] ? $_space_used['figure'] : 0;
         }
         //-----------------------------------------
         // Generate space allowed figure
         //-----------------------------------------
         if ($this->memberData['g_attach_max'] > 0) {
             if ($this->memberData['g_attach_per_post']) {
                 $_g_space_used = $this->DB->buildAndFetch(array('select' => 'SUM(attach_filesize) as figure', 'from' => 'attachments', 'where' => 'attach_member_id=' . $member_id . " AND attach_rel_module IN( 'post', 'msg' )"));
                 $g_space_used = $_g_space_used['figure'] ? $_g_space_used['figure'] : 0;
                 if ($this->memberData['g_attach_max'] * 1024 - $g_space_used < 0) {
                     $space_used = $g_space_used;
                     $total_space_allowed = $this->memberData['g_attach_max'] * 1024;
                     $space_allowed = $this->memberData['g_attach_max'] * 1024 - $space_used;
                     $space_allowed = $space_allowed < 0 ? -1 : $space_allowed;
                 } else {
                     $space_allowed = $this->memberData['g_attach_per_post'] * 1024 - $space_used;
                     $space_allowed = $space_allowed < 0 ? -1 : $space_allowed;
                 }
             } else {
                 $space_allowed = $this->memberData['g_attach_max'] * 1024 - $space_used;
                 $space_allowed = $space_allowed < 0 ? -1 : $space_allowed;
             }
         } else {
             if ($this->memberData['g_attach_per_post']) {
                 $space_allowed = $this->memberData['g_attach_per_post'] * 1024 - $space_used;
                 $space_allowed = $space_allowed < 0 ? -1 : $space_allowed;
             } else {
                 # Unlimited
                 $space_allowed = 0;
             }
         }
         //-----------------------------------------
         // Generate space left figure
         //-----------------------------------------
         $space_left = $space_allowed ? $space_allowed : 0;
         $space_left = $space_left < 0 ? -1 : $space_left;
         //-----------------------------------------
         // Generate max upload size
         //-----------------------------------------
         if (!$max_single_upload) {
             if ($space_left > 0 and $space_left < $max_php_size) {
                 $max_single_upload = $space_left;
             } else {
                 if ($max_php_size) {
                     $max_single_upload = $max_php_size;
                 }
             }
         }
     }
     IPSDebug::fireBug('info', array('Space left: ' . $space_left));
     IPSDebug::fireBug('info', array('Max PHP size: ' . $max_php_size));
     IPSDebug::fireBug('info', array('Max single file size: ' . $max_single_upload));
     $return = array('space_used' => $space_used, 'space_left' => $space_left, 'space_allowed' => $space_allowed, 'max_single_upload' => $max_single_upload, 'total_space_allowed' => $total_space_allowed);
     return $return;
 }