<?php
/*
文章栏目区块
参数1：栏目数，默认5，可用参数：大于0整数
参数2：父栏目ID，默认0，可用参数：0（一级栏目），栏目ID，cid（系统取$_REQUEST['cid']值），$cid（系统取已定义模版变量cid值）
*/
class blockcatelist extends saxueblock {
		public $template = "block_catelist.html";
		public $exevars = array( 'listnum' => 5, 'cid' => '0' );
		public function blockcatelist( &$_vars ) {
				global $saxueTpl;
				$this -> saxueblock( $_vars );
				if ( !empty( $this -> blockvars['vars'] ) ) {
						$_fieldarr = explode( ",", trim( $this -> blockvars['vars'] ) );
						$_fieldcount = count( $_fieldarr );
						if ( 0 < $_fieldcount ) {
								$_fieldarr[0] = trim( $_fieldarr[0] );
								if ( is_numeric( $_fieldarr[0] ) && 0 < $_fieldarr[0] ) {
										$this -> exevars['listnum'] = intval( $_fieldarr[0] );
								} 
						}
						if ( 1 < $_fieldcount ) {
								$_fieldarr[1] = trim( $_fieldarr[1] );
								if ( is_numeric( $_fieldarr[1] ) ) {
										$this -> exevars['cid'] = $_fieldarr[1];
								} else if ( substr( $_fieldarr[1], 0, 1 ) == "\$" ) {
										$_cidvar = $saxueTpl -> get_assign( substr( $_fieldarr[1], 1 ) );
										if ( is_numeric( $_cidvar ) ) {
												$this -> exevars['cid'] = $_cidvar;
										} 
								} else if ( isset( $_REQUEST[$_fieldarr[1]] ) && is_numeric( $_REQUEST[$_fieldarr[1]] ) ) {
										$this -> exevars['cid'] = $_REQUEST[$_fieldarr[1]];
								}
						} 
				} 
				$this -> blockvars['cacheid'] = md5( serialize( $this -> exevars ) . "|" . $this -> blockvars['template'] );
		} 
		public function setcontent( $isreturn = false ) {
				global $saxueTpl;
				global $saxueCate;
				if ( !isset( $saxueCate['article'] ) ) {
						saxue_getconfigs( "cate", "article" );
				}
				$rows = array();
				$k = 0;
				foreach ( $saxueCate['article'] as $cid => $v ) {
						if ( $v['pid'] == $this -> exevars['cid'] ) {
								$rows[$cid] = $v;
								if ( ++$k >= $this -> exevars['listnum'] ) break;
						}
				}
				if ( $isreturn ) {
						return $rows;
				}
				$saxueTpl -> assign_by_ref( "rows", $rows );
		} 
} 
