class_post.php

来自「sabreipb 2.1.6 utf-8中文版本!」· PHP 代码 · 共 2,030 行 · 第 1/5 页

PHP
2,030
字号
			return $attach_data;		}				//-----------------------------------------		// Space left...		//-----------------------------------------				$this->_get_attachment_sum();				$this->cur_post_attach = array();		$this->per_post_count  = 0;			if ( $this->ipsclass->input['post_key'] )		{			$this->ipsclass->DB->simple_construct( array( "select" => '*', 'from' => 'attachments', 'where' => "attach_post_key='{$this->ipsclass->input['post_key']}'") );			$this->ipsclass->DB->simple_exec();						while( $r = $this->ipsclass->DB->fetch_row() )			{				$this->per_post_count   += $r['attach_filesize'];				$this->cur_post_attach[] = $r;			}		}				if ( $this->ipsclass->member['g_attach_max'] > 0 )		{			if ( $this->ipsclass->member['g_attach_per_post'] )			{				$main_space_left   = intval( ( $this->ipsclass->member['g_attach_per_post'] * 1024 ) - $this->per_post_count );				$main_space_left_g = intval( ( $this->ipsclass->member['g_attach_max'] * 1024 ) - $this->attach_sum );								if ( $main_space_left_g < $main_space_left )				{					$main_space_left = $main_space_left_g;				}			}			else			{				$main_space_left = intval( ( $this->ipsclass->member['g_attach_max'] * 1024 ) - $this->attach_sum );			}		}		else		{			if ( $this->ipsclass->member['g_attach_per_post'] )			{				$main_space_left = intval( ( $this->ipsclass->member['g_attach_per_post'] * 1024 ) - $this->per_post_count );			}			else			{				$main_space_left = 1000000000;			}		}							//-----------------------------------------		// Load the library		//-----------------------------------------				require_once( KERNEL_PATH.'class_upload.php' );		$upload = new class_upload();				//-----------------------------------------		// Set up the variables		//-----------------------------------------				$upload->out_file_name    = 'post-'.$this->ipsclass->member['id'].'-'.time();		$upload->out_file_dir     = $this->ipsclass->vars['upload_dir'];		$upload->max_file_size    = $main_space_left;		$upload->make_script_safe = 1;		$upload->force_data_ext   = 'ipb';				//-----------------------------------------		// Populate allowed extensions		//-----------------------------------------				if ( is_array( $this->ipsclass->cache['attachtypes'] ) and count( $this->ipsclass->cache['attachtypes'] ) )		{			foreach( $this->ipsclass->cache['attachtypes'] as $idx => $data )			{				if ( $data['atype_post'] )				{					$upload->allowed_file_ext[] = $data['atype_extension'];				}			}		}				//-----------------------------------------		// Upload...		//-----------------------------------------				$upload->upload_process();				//-----------------------------------------		// Error?		//-----------------------------------------				if ( $upload->error_no )		{			switch( $upload->error_no )			{				case 1:					// No upload					return $attach_data;				case 2:					// Invalid file ext					$this->obj['post_errors'] = 'invalid_mime_type';					return $attach_data;				case 3:					// Too big...					$this->obj['post_errors'] = 'upload_to_big';					return $attach_data;				case 4:					// Cannot move uploaded file					$this->obj['post_errors'] = 'upload_failed';					return $attach_data;				case 5:					// Possible XSS attack (image isn't an image)					$this->obj['post_errors'] = 'upload_failed';					return $attach_data;			}		}							//-----------------------------------------		// Still here?		//-----------------------------------------				if ( $upload->saved_upload_name and @file_exists( $upload->saved_upload_name ) )		{			$attach_data['attach_filesize']   = @filesize( $upload->saved_upload_name  );			$attach_data['attach_location']   = $upload->parsed_file_name;			$attach_data['attach_file']       = $upload->original_file_name;			$attach_data['attach_is_image']   = $upload->is_image;			$attach_data['attach_ext']        = $upload->real_file_extension;						if ( $attach_data['attach_is_image'] == 1 )			{				$this->watermark($upload->saved_upload_name, $attach_data);				$thumb_data = $this->create_thumbnail( $attach_data );								if ( $thumb_data['thumb_location'] )				{					$attach_data['attach_thumb_width']    = $thumb_data['thumb_width'];					$attach_data['attach_thumb_height']   = $thumb_data['thumb_height'];					$attach_data['attach_thumb_location'] = $thumb_data['thumb_location'];				}			}						$this->ipsclass->DB->do_insert( 'attachments', $attach_data );						$newid = $this->ipsclass->DB->get_insert_id();						$attach_data['attach_id'] = $newid;						$this->per_post_count    += $attach_data['attach_filesize'];			$this->cur_post_attach[]  = $attach_data;						return $newid;		}	}	/*-------------------------------------------------------------------------*/	// Create thumbnail	/*-------------------------------------------------------------------------*/		function create_thumbnail( $data )	{		//-----------------------------------------		// Load class		//-----------------------------------------				$return = array();				require_once( KERNEL_PATH.'class_image.php' );		$image = new class_image();				$image->in_type        = 'file';		$image->out_type       = 'file';		$image->in_file_dir    = $this->ipsclass->vars['upload_dir'];		$image->in_file_name   = $data['attach_location'];		$image->desired_width  = $this->ipsclass->vars['siu_width'];		$image->desired_height = $this->ipsclass->vars['siu_height'];		$image->gd_version     = $this->ipsclass->vars['gd_version'];				if ( $this->ipsclass->vars['siu_thumb'] )		{			$return = $image->generate_thumbnail();		}				return $return;	}		/*-------------------------------------------------------------------------*/	// Increment user's post	// ------------------	// if +1 post, +1 member's cumulative	/*-------------------------------------------------------------------------*/		function pf_increment_user_post_count()	{		$pcount = "";		$mgroup = "";				if ($this->ipsclass->member['id'])		{			if ($this->forum['inc_postcount'])			{				// Increment the users post count								$pcount = "posts=posts+1, ";			}						// Are we checking for auto promotion?						if ($this->ipsclass->member['g_promotion'] != '-1&-1')			{				list($gid, $gposts) = explode( '&', $this->ipsclass->member['g_promotion'] );								if ( $gid > 0 and $gposts > 0 )				{					if ( $this->ipsclass->member['posts'] + 1 >= $gposts )					{						$mgroup = "mgroup='$gid', ";												if ( USE_MODULES == 1 )						{							$this->modules->register_class($this);							$this->modules->on_group_change($this->ipsclass->member['id'], $gid);						}					}				}			}						$this->ipsclass->member['last_post'] = time();						$this->ipsclass->DB->simple_construct( array( 'update' => 'members',														  'set'    => $pcount.$mgroup." last_post=".intval($this->ipsclass->member['last_post']),														  'where'  => 'id='.$this->ipsclass->member['id']												 )      );								 			$this->ipsclass->DB->simple_exec();		}		}		/*-------------------------------------------------------------------------*/	// Update forum's last information	// ------------------	// ^^ proper chrimbo!	/*-------------------------------------------------------------------------*/		function pf_update_forum_and_stats($tid, $title, $type='new')	{		$moderated = 0;				//-----------------------------------------		// Moderated?		//-----------------------------------------				if ( $this->obj['moderate'] )		{			if ( $type == 'new' and ( $this->obj['moderate'] == 1 or $this->obj['moderate'] == 2 ) )			{				$moderate = 1;			}			else if ( $type == 'reply' and ( $this->obj['moderate'] == 1 or $this->obj['moderate'] == 3 ) )			{				$moderate = 1;			}		}				//-----------------------------------------		// Add to forum's last post?		//-----------------------------------------				if ( ! $moderate )		{			$dbs = array( 'last_title'       => $title,						  'last_id'          => $tid,						  'last_post'        => time(),						  'last_poster_name' => $this->ipsclass->member['id'] ?  $this->ipsclass->member['members_display_name'] : $this->ipsclass->input['UserName'],						  'last_poster_id'   => $this->ipsclass->member['id'],					   );					if ( $type == 'new' )			{				$this->ipsclass->cache['stats']['total_topics']++;								$this->forum['topics'] = intval($this->forum['topics']);				$dbs['topics']         = ++$this->forum['topics'];			}			else			{				$this->ipsclass->cache['stats']['total_replies']++;								$this->forum['posts'] = intval($this->forum['posts']);				$dbs['posts']         = ++$this->forum['posts'];			}		}		else		{			if ( $type == 'new' )			{				$this->forum['queued_topics'] = intval($this->forum['queued_topics']);				$dbs['queued_topics']         = ++$this->forum['queued_topics'];			}			else			{				$this->forum['queued_posts'] = intval($this->forum['queued_posts']);				$dbs['queued_posts']         = ++$this->forum['queued_posts'];			}		}				//-----------------------------------------		// Merging posts?		// Don't update counter		//-----------------------------------------				if ( $this->is_merging_posts )		{			unset($dbs['posts']);			unset($dbs['queued_posts']);						$this->ipsclass->cache['stats']['total_replies'] -= 1;		}				//-----------------------------------------		// Update		//-----------------------------------------				$this->ipsclass->DB->do_update( 'forums', $dbs, "id=".intval($this->forum['id']) );				//-----------------------------------------		// Update forum cache		//-----------------------------------------				$this->ipsclass->update_forum_cache();				$this->ipsclass->update_cache( array( 'name' => 'stats', 'array' => 1, 'deletefirst' => 0, 'donow' => 1 ) );	}		/*-------------------------------------------------------------------------*/	// Remove attachment	// ------------------	// ^^ proper new year!	/*-------------------------------------------------------------------------*/		function pf_remove_attachment($aid, $post_key)	{		$this->ipsclass->DB->simple_construct( array( "select" => '*', 'from' => 'attachments',  'where' => "attach_post_key='$post_key' AND attach_id=$aid") );		$o = $this->ipsclass->DB->simple_exec();				if ( $killmeh = $this->ipsclass->DB->fetch_row( $o ) )		{			if ( $killmeh['attach_location'] )			{				@unlink( $this->ipsclass->vars['upload_dir']."/".$killmeh['attach_location'] );			}			if ( $killmeh['attach_thumb_location'] )			{				@unlink( $this->ipsclass->vars['upload_dir']."/".$killmeh['attach_thumb_location'] );			}						$this->ipsclass->DB->simple_construct( array( 'delete' => 'attachments', 'where' => "attach_id={$killmeh['attach_id']}" ) );			$this->ipsclass->DB->simple_exec();						//-----------------------------------------			// Remove from post			//-----------------------------------------						$_POST['Post'] = str_replace( '[attachmentID='.$aid.']', '', $_POST['Post'] );		}	}		/*-------------------------------------------------------------------------*/	// Convert temp uploads into permanent ones! YAY	// ------------------	// ^^ proper chinese new year!	/*-------------------------------------------------------------------------*/		function pf_make_attachments_permanent($post_key="", $tid="", $pid="", $msg="")	{		//-----------------------------------------		// Delete old unattached uploads		//-----------------------------------------				$time_cutoff = time() - 7200;		$deadid      = array();				$this->ipsclass->DB->simple_construct( array( "select" => '*', 'from' => 'attachments',  'where' => "attach_pid=0 and attach_msg=0 and attach_date < $time_cutoff") );		$this->ipsclass->DB->simple_exec();				while( $killmeh = $this->ipsclass->DB->fetch_row() )		{			if ( $killmeh['attach_location'] )			{				@unlink( $this->ipsclass->vars['upload_dir']."/".$killmeh['attach_location'] );			}			if ( $killmeh['attach_thumb_location'] )			{				@unlink( $this->ipsclass->vars['upload_dir']."/".$killmeh['attach_thumb_location'] );			}						$deadid[] = $killmeh['attach_id'];		}				if ( count($deadid) )		{			$this->ipsclass->DB->simple_construct( array( 'delete' => 'attachments', 'where' => "attach_id IN(".implod

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?