forums.php

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

PHP
1,549
字号
		{			$this->ipsclass->DB->simple_construct( array( 'select' => '*',														  'from'   => 'topics t',														  'where'  =>  $query . $add_query,														  'order'  => 't.pinned DESC, '.$topic_sort.' t.'.$sort_key .' '. $r_sort_by,														  'limit'  => array( intval($First), $this->ipsclass->vars['display_max_topics'] )												 )      );			$this->ipsclass->DB->simple_exec();		}				while ( $t = $this->ipsclass->DB->fetch_row() )		{			$topic_array[ $t['tid'] ] = $t;			$topic_ids[ $t['tid'] ]   = $t['tid'];		}					ksort($topic_ids);				//-----------------------------------------		// Are we dotty?		//-----------------------------------------				if ( ($this->ipsclass->vars['show_user_posted'] == 1) and ($this->ipsclass->member['id']) and ( count($topic_ids) ) and ( $parse_dots ) )		{			$this->ipsclass->DB->simple_construct( array( 'select' => 'author_id, topic_id',														  'from'   => 'posts',														  'where'  => "author_id=".$this->ipsclass->member['id']." AND topic_id IN(".implode( ",", $topic_ids ).")",												)      );									  			$this->ipsclass->DB->simple_exec();						while( $p = $this->ipsclass->DB->fetch_row() )			{				if ( is_array( $topic_array[ $p['topic_id'] ] ) )				{					$topic_array[ $p['topic_id'] ]['author_id'] = $p['author_id'];				}			}		}				//-----------------------------------------		// Get topic trackers table?		//-----------------------------------------				if ( $this->ipsclass->vars['db_topic_read_cutoff'] and count($topic_ids) )		{			if ( $this->ipsclass->forums->forum_by_id[ $this->forum['id'] ]['_db_row'] )			{				$this->db_row = $this->ipsclass->forums->forum_by_id[ $this->forum['id'] ]['_db_row'];			}			else			{				$this->ipsclass->DB->simple_construct( array( 'select' => '*',															  'from'   => 'topic_markers',															  'where'  => "marker_forum_id=".$this->forum['id']." AND marker_member_id=".$this->ipsclass->member['id'],													)      );										  				$this->ipsclass->DB->simple_exec();								$this->db_row   = $this->ipsclass->DB->fetch_row();			}						$this->my_topics_read  = unserialize(stripslashes($this->db_row['marker_topics_read']) );			$this->read_topics_tid = array();						//-----------------------------------------			// Got read topics?			//-----------------------------------------						if ( is_array( $this->my_topics_read ) and count ( $this->my_topics_read ) )			{				foreach( $this->my_topics_read as $tid => $date )				{					if ( is_array( $topic_array[ $tid ] ) )					{						$this->read_topics_tid[]        = $tid;						$topic_array[ $tid ]['db_read'] = $date > $this->db_row['marker_last_cleared'] ? $date : $this->db_row['marker_last_cleared'];					}				}			}						//-----------------------------------------			// No? Got a last cleared date?			//-----------------------------------------						else if ( $this->db_row['marker_last_cleared'] )			{				if ( is_array( $topic_array ) )				{					foreach( $topic_array as $tid => $data )					{						$topic_array[ $tid ]['db_read'] = $this->db_row['marker_last_cleared'];					}				}			}		}				//-----------------------------------------		// Show meh the topics!		//-----------------------------------------				foreach( $topic_array as $tid => $topic )		{			if ( $topic['pinned'] )			{				$this->pinned_topic_count++;			}						$this->output .= $this->render_entry( $topic );						$total_topics_printed++;		}				//-----------------------------------------		// Finish off the rest of the page  $filter_keys[$topicfilter]))		//-----------------------------------------				foreach ($sort_by_keys as $k => $v)		{			$sort_by_html   .= $k == $sort_by     ? "<option value='$k' selected='selected'>" . $this->ipsclass->lang[ $sort_by_keys[ $k ] ] . "</option>\n"											      : "<option value='$k'>"                     . $this->ipsclass->lang[ $sort_by_keys[ $k ] ] . "</option>\n";		}			foreach ($sort_keys as  $k => $v)		{			$sort_key_html  .= $k == $sort_key    ? "<option value='$k' selected='selected'>" . $this->ipsclass->lang[ $sort_keys[ $k ] ]    . "</option>\n"											      : "<option value='$k'>"                     . $this->ipsclass->lang[ $sort_keys[ $k ] ]    . "</option>\n";		}				foreach ($prune_by_day as  $k => $v)		{			$prune_day_html .= $k == $prune_value ? "<option value='$k' selected='selected'>" . $this->ipsclass->lang[ $prune_by_day[ $k ] ] . "</option>\n"												  : "<option value='$k'>"                     . $this->ipsclass->lang[ $prune_by_day[ $k ] ] . "</option>\n";		}				foreach ($filter_keys as  $k => $v)		{			$filter_html    .= $k == $topicfilter ? "<option value='$k' selected='selected'>" . $this->ipsclass->lang[ $filter_keys[ $k ] ]  . "</option>\n"												  : "<option value='$k'>"                     . $this->ipsclass->lang[ $filter_keys[ $k ] ]  . "</option>\n";		}			$this->ipsclass->show['sort_by']      = $sort_key_html;		$this->ipsclass->show['sort_order']   = $sort_by_html;		$this->ipsclass->show['sort_prune']   = $prune_day_html;		$this->ipsclass->show['topic_filter'] = $filter_html;				if( $this->ipsclass->member['is_mod'] )		{			$count = 0;						if( $this->ipsclass->input['selectedtids'] != "" )			{				$tids = explode( ",",$this->ipsclass->input['selectedtids'] );								if( is_array($tids) AND count($tids) )				{					foreach( $tids as $tid )					{						if( $tid != '' )						{							$count++;						}					}				}			}						$this->ipsclass->lang['f_go'] .= " ({$count})";		}			$this->output .= $this->ipsclass->compiled_templates['skin_forum']->TableEnd($this->forum, $this->auth_key);				//-----------------------------------------		// Multi-moderation?		//-----------------------------------------				if ( $this->ipsclass->member['is_mod'] )		{			$mm_array = $this->ipsclass->get_multimod( $this->forum['id'] );						if ( is_array( $mm_array ) and count( $mm_array ) )			{				foreach( $mm_array as $m )				{					$mm_html .= $this->ipsclass->compiled_templates['skin_forum']->mm_entry( $m[0], $m[1] );				}			}						if ( $mm_html )			{				$this->output = str_replace( '<!--IBF.MMOD-->', $this->ipsclass->compiled_templates['skin_forum']->mm_start() . $mm_html . $this->ipsclass->compiled_templates['skin_forum']->mm_end(), $this->output );			}		}				//-----------------------------------------		// Need to update topics?		//-----------------------------------------				if ( count( $this->update_topics_open ) )		{			$this->ipsclass->DB->do_shutdown_update( 'topics', array( 'state' => 'open' ), 'tid IN ('.implode( ",", $this->update_topics_open ) .')' );		}				if ( count( $this->update_topics_close ) )		{			$this->ipsclass->DB->do_shutdown_update( 'topics', array( 'state' => 'closed' ), 'tid IN ('.implode( ",", $this->update_topics_close ) .')' );		}				//-----------------------------------------		// Update forum read table?		//-----------------------------------------				if ( $this->ipsclass->vars['db_topic_read_cutoff'] AND $this->ipsclass->member['id'] AND count($topic_ids) )		{			//-----------------------------------------			// More posts since last update?			// OR: unread == 0 but we have unread topics			// Can happen when no marker DB row and we			// view a topic			//-----------------------------------------						$db_time = $this->db_row['marker_last_cleared'] > $this->ipsclass->member['members_markers']['board'] ? $this->db_row['marker_last_cleared'] : $this->ipsclass->member['members_markers']['board'];							if ( ( $this->db_row['marker_unread'] <= 0 AND ( $this->db_row['marker_last_update'] < $this->forum['last_post'] ) )			 OR  ( $this->forum['forum_last_deletion'] > $this->db_row['marker_last_update'] ) )			{				//-----------------------------------------				// Get unread count				//-----------------------------------------								$notin = count($this->read_topics_tid) ? "AND t.tid NOT IN(0,".implode(",",$this->read_topics_tid).")" : "";								$count = $this->ipsclass->DB->build_and_exec_query( array( 'select' => 'COUNT(*) as cnt, MIN(last_post) as min_last_post',																		   'from'   => 'topics t',																		   'where'  => "t.forum_id={$this->forum['id']} {$approved} {$notin} AND t.last_post > ".intval($db_time) ) );				$save_array = array();								//-----------------------------------------				// Update counter				//-----------------------------------------								$save_array['marker_unread'] = intval($count['cnt']);								//-----------------------------------------				// Topics unread: Clean out old topics				//-----------------------------------------								if ( $save_array['marker_unread'] > 0 )				{					$this->ipsclass->vars['db_topic_read_cutoff'] = $count['min_last_post'] - 1;										if ( is_array( $this->my_topics_read ) and count( $this->my_topics_read ) )					{						$this->my_topics_read = array_filter( $this->my_topics_read, array( 'ipsclass', "array_filter_clean_read_topics" ) );					}					else					{						$this->my_topics_read = array();					}										$save_array['marker_topics_read'] = serialize( $this->my_topics_read );				}								//-----------------------------------------				// Else, mark as read				//-----------------------------------------								else				{					$save_array['marker_topics_read']  = serialize( array() );					$save_array['marker_last_cleared'] = time();					$save_array['marker_unread']       = 0;				}								$save_array['marker_last_update'] = time();								if ( $this->db_row['marker_forum_id'] )				{					$this->ipsclass->DB->do_shutdown_update( 'topic_markers', $save_array, 'marker_member_id='.$this->ipsclass->member['id'].' AND marker_forum_id='.$this->forum['id'] );				}				else				{					$save_array['marker_member_id'] = $this->ipsclass->member['id'];					$save_array['marker_forum_id']  = $this->forum['id'];										$this->ipsclass->DB->do_shutdown_insert( 'topic_markers', $save_array );				}			}		}				//-----------------------------------------		// Update forum read cookie, too		//----------------------------------------- 				if ( $this->forum_has_unread_topics < 1 and ! $this->ipsclass->input['st'] )		{			$this->ipsclass->forum_read[ $this->forum['id'] ] = time();						$this->ipsclass->hdl_forum_read_cookie('set');		}				//-----------------------------------------		// Process users active in this forum		//-----------------------------------------				if ($this->ipsclass->vars['no_au_forum'] != 1)		{			//-----------------------------------------			// Get the users			//-----------------------------------------						$cut_off = ($this->ipsclass->vars['au_cutoff'] != "") ? $this->ipsclass->vars['au_cutoff'] * 60 : 900;			$time    = time() - $cut_off;						$this->ipsclass->DB->cache_add_query('forums_get_active_users',  array( 'fid' => $this->forum['id'], 'time' => $time ) );			$this->ipsclass->DB->simple_exec();						//-----------------------------------------			// ACTIVE USERS			//-----------------------------------------						$ar_time = time();			$cached = array();			$active = array( 'guests' => 0, 'anon' => 0, 'members' => 0, 'names' => "");			$rows   = array( $ar_time => array( 'login_type'   => substr($this->ipsclass->member['login_anonymous'],0, 1),												'running_time' => $ar_time,												'member_id'    => $this->ipsclass->member['id'],												'member_name'  => $this->ipsclass->member['members_display_name'],												'member_group' => $this->ipsclass->member['mgroup'] ) );						//-----------------------------------------			// FETCH...			//-----------------------------------------						while ($r = $this->ipsclass->DB->fetch_row() )			{				$rows[ $r['running_time'].'.'.$r['id'] ] = $r;			}						krsort( $rows );						//-----------------------------------------			// PRINT...			//-----------------------------------------						foreach( $rows as $i => $result )			{				$result['suffix'] = $this->ipsclass->cache['group_cache'][ $result['member_group'] ]['suffix'];				$result['prefix'] = $this->ipsclass->cache['group_cache'][ $result['member_group'] ]['prefix'];								$last_date = $this->ipsclass->get_time( $result['running_time'] );								if ($result['member_id'] == 0)				{					$active['guests']++;				}				else				{					if (empty( $cached[ $result['member_id'] ] ) )					{						$cached[ $result['member_id'] ] = 1;												$p_start = "";						$p_end   = "";						$p_title = " title='".sprintf( $this->ipsclass->lang['au_reading'], $last_date )."' ";												if ( strstr( $result['location'], 'post' ) )						{							$p_start = "<span class='activeuserposting'>";							$p_end   = "</span>";							$p_title = " title='".sprintf( $this->ipsclass->lang['au_posting'], $last_date )."' ";						}												if ($result['login_type'] == 1)						{							if ( ($this->ipsclass->member['mgroup'] == $this->ipsclass->vars['admin_group']) and ($this->ipsclass->vars['disable_admin_anon'] != 1) )							{								$active['names'] .= "$p_start<a href='{$this->ipsclass->base_url}showuser={$result['member_id']}'$p_title>{$result['prefix']}{$result['member_name']}{$result['suffix']}</a>*$p_end, ";								$active['anon']++;							}							else							{								$active['anon']++;							}						}						else						{							$active['members']++;							$active['names'] .= "$p_start<a href='{$this->ipsclass->base_url}showuser={$result['member_id']}'$p_title>{$result['prefix']}{$result['member_name']}{$result['suffix']}</a>$p_end, ";

⌨️ 快捷键说明

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