<?php 
// 获取网站位置
function position($home = '首页'){
	$pos = array();
	array_push($pos, array(
		'text' => $home,
		'url' => 'Index/index',
		));
	$conname = strtolower(CONTROLLER_NAME);
	$actname = strtolower(ACTION_NAME);
	switch ($conname) {
		case 'content':
			if ($actname == 'index') {
				$id = I('id');
				$data = M('Contentcate') -> where('status=1') -> getField('id,pid,text',true);
				$pids = get_pids($id,$data);
				foreach ($pids as $key => $value) {
					array_push($pos, array(
						'text' => $value['text'],
						'url' => 'Content/index?id='.$value['id'],
						));
				}
			}elseif ($actname == 'detail') {
				$id = I('id');
				$category_id = M('Content') -> where('id='.$id) -> getField('category_id');
				$data = M('Contentcate') -> where('status=1') -> getField('id,pid,text',true);
				$pids = get_pids($category_id,$data);
				foreach ($pids as $key => $value) {
					array_push($pos, array(
						'text' => $value['text'],
						'url' => 'Content/index?id='.$value['id'],
						));
				}
			}
			break;
		case 'guestbook':
			array_push($pos, array(
				'text' =>'留言中心' ,
				'url' => 'Guestbook/index',
				));
			break;
		
		default:
			# code...
			break;
	}
	return $pos;
}

// 获取父id
function get_pids($id,$data){
	$tmp = array($data[$id]);
	if (isset($data[$data[$id]['pid']])) {
		$tmp = array_merge(get_pids($data[$id]['pid'],$data),$tmp);
	}
	return $tmp;
}

// 获取下一篇文章
function nexttoid($id,$to,$module=CONTROLLER_NAME,$category_id=false){
	$m = D($module,'ViewModel');
	$to = $to?:I('to');
	$_where = array();
	if ($to == 'next') {
		$_where['id'] = array('gt',$id);
	}else{
		$_where['id'] = array('lt',$id);
		$m -> order('id desc');
	}
	$_where['status'] = array('eq',1);
	$_where['Category.status'] = array('eq',1);
	if ($category_id == false) {
		$category_id = M($module) -> where('id='.$id) -> getField('category_id');
		$_where['category_id'] = array('eq',$category_id);
	}elseif ($category_id && is_numeric($category_id)) {
		$_where['category_id'] = array('eq',$category_id);
	}
	if ($data = $m -> where($_where) -> find()) {
		return $data['id'];
	}
	return false;
}