<?php
/*
　* @$Id
　* @
　* @Ver: 2.0
　* @Create: 2009-11-18 8:10
　* @Modify: 
　* @Author: CPWEB http://www.cpweb.net.cn
　* @Copyright (C) 2008 www.cpweb.net.cn. All Rights Reserved.
　* @License CPWEB is free software and use is subject to license terms
　*/
if (!defined('THINK_PATH')){
	echo '<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>CPWEB企业网站管理系统</title></head><body>欢迎使用<a href="http://www.cpweb.net.cn">CPWEB企业网站管理系统</a></body></html>';
	exit();
}
function CPWEBA($name,$app='@'){
	static $_action = array();
	if(isset($_action[$app.$name]))
		return $_action[$app.$name];
	$OriClassName = $name;
	if(strpos($name,C('APP_GROUP_DEPR'))) {
		$array   =  explode(C('APP_GROUP_DEPR'),$name);
		$name = array_pop($array);
		$className =  $name.'Action';
		import($app.'.CpwebModel.'.implode('.',$array).'.'.$className);
	}else{
		$className =  $name.'Action';
		import($app.'.CpwebModel.'.$className);
	}
	if(class_exists($className)) {
		$action = new $className();
		$_action[$app.$OriClassName] = $action;
		return $action;
	}else {
		return false;
	}
}
/**
 * 获取地址
 */
function cpweb_url()
{
	return __APP__;
}
function cpweb_url_channel($name=false,$folder=false)
{
	$url='';
	if($folder){
		if(C('URL_MODEL')==0 || !C('URL_DISPATCH_ON')){
			$url=__APP__.'?m='.$folder;
		}elseif(C('URL_MODEL')==1){
			$url=__APP__.C('URL_PATHINFO_DEPR').$folder.C('URL_PATHINFO_DEPR');
		}elseif(C('URL_MODEL')==2){
			$url=__ROOT__.C('URL_PATHINFO_DEPR').$folder.C('URL_PATHINFO_DEPR');
		}elseif(C('URL_MODEL')==3){
			$url=__APP__.$folder;
		}
	}elseif($name){
		if(!$name['folder']){
			$name['folder']=$name['address'];
		}else{
			preg_match("/http:\/\//",$name['folder'], $matches);
			if($matches){
				return $name['folder'];
			}
		}
		if(C('URL_MODEL')==0 || !C('URL_DISPATCH_ON')){
			$url=__APP__.'?m='.$name['folder'];
		}elseif(C('URL_MODEL')==1){
			$url=__APP__.C('URL_PATHINFO_DEPR').$name['folder'].C('URL_PATHINFO_DEPR');
		}elseif(C('URL_MODEL')==2){
			$url=__ROOT__.C('URL_PATHINFO_DEPR').$name['folder'].C('URL_PATHINFO_DEPR');
		}elseif(C('URL_MODEL')==3){
			$url=__APP__.$name['folder'];
		}
	}
	return $url;
}
function cpweb_url_category($name,$folder=false)
{
	if($name['category_id']) $name['id']=$name['category_id'];
	if($folder) $name['id']=$folder;
	if(C('URL_MODEL')==0 || !C('URL_DISPATCH_ON')){
		$url=__APP__.'?m='.$name['folder'].'&a=sorts&id='.$name['id'];
	}elseif(C('URL_MODEL')==1){
		$url=__APP__.C('URL_PATHINFO_DEPR').$name['folder'].C('URL_PATHINFO_DEPR').'sorts'.C('URL_PATHINFO_DEPR').'id'.C('URL_PATHINFO_DEPR').$name['id'].C('URL_HTML_SUFFIX');
	}elseif(C('URL_MODEL')==2){
		$url=__ROOT__.C('URL_PATHINFO_DEPR').$name['folder'].C('URL_PATHINFO_DEPR').'sorts'.C('URL_PATHINFO_DEPR').'id'.C('URL_PATHINFO_DEPR').$name['id'].C('URL_HTML_SUFFIX');
	}elseif(C('URL_MODEL')==3){
		$url=__APP__.$name['folder'].C('URL_PATHINFO_DEPR').'sorts'.C('URL_PATHINFO_DEPR').'id'.C('URL_PATHINFO_DEPR').$name['id'].C('URL_HTML_SUFFIX');
	}
	return $url;
}
function cpweb_url_read($name,$folder=false)
{
	if($folder) $name['folder']=$folder;
	if(C('URL_MODEL')==0 || !C('URL_DISPATCH_ON')){
		$url=__APP__.'?m='.$name['folder'].'&a=read&id='.$name['id'];
	}elseif(C('URL_MODEL')==1){
		$url=__APP__.C('URL_PATHINFO_DEPR').$name['folder'].C('URL_PATHINFO_DEPR').'read'.C('URL_PATHINFO_DEPR').'id'.C('URL_PATHINFO_DEPR').$name['id'].C('URL_HTML_SUFFIX');
	}elseif(C('URL_MODEL')==2){
		$url=__ROOT__.C('URL_PATHINFO_DEPR').$name['folder'].C('URL_PATHINFO_DEPR').'read'.C('URL_PATHINFO_DEPR').'id'.C('URL_PATHINFO_DEPR').$name['id'].C('URL_HTML_SUFFIX');
	}elseif(C('URL_MODEL')==3){
		$url=__APP__.$name['folder'].C('URL_PATHINFO_DEPR').'read'.C('URL_PATHINFO_DEPR').'id'.C('URL_PATHINFO_DEPR').$name['id'].C('URL_HTML_SUFFIX');
	}
	return $url;
}
function get_name($name , $name_empty , $i=0)
{
	if(strlen($name) > $name_empty){
		$g_name = substr($name , $i , $name_empty).'...';
	}else{
		$g_name = $name;
	}
	return $g_name;
}
/**
 * 获取附件地址
 *
 * @access  public
 * @param   array   $name       内容数组
 * @param   int     $model      模块地址
 * @return  mix
 */
function attach($name,$model=false,$attachdir='Attachments'){
	if($name['attachment']){
		if(preg_match('/(\/)/',$name['attachment'],$i)){
			$attach=__ROOT__.'/'.$name['attachment'];
		}else{
			if($name['attachpath']){
				$attach=__ROOT__.'/'.C(ATTACHDIR).'/'.$name['attachfolder'].'/'.strtolower($name['address']).'/'.$name['attachpath'].'/'.$name['attachment'];
			}else{
				$attach=__ROOT__.'/'.C(ATTACHDIR).'/'.$attachdir.'/'.strtolower($model).'/file/'.$name['attachment'];
			}
		}
		return $attach;
	}
}
function attachthumb($name,$model=false,$attachdir='Attachments'){
	if($name['attachthumb']){
		if(preg_match('/(\/)/',$name['attachthumb'],$i)){
			$attachthumb=__ROOT__.'/'.$name['attachthumb'];
		}else{
			if($name['attachpath']){
				$attachthumb=__ROOT__.'/'.C(ATTACHDIR).'/'.$name['attachfolder'].'/'.strtolower($name['address']).'/'.$name['attachpath'].'/'.$name['attachthumb'];
			}else{
				$attachthumb=__ROOT__.'/'.C(ATTACHDIR).'/'.$attachdir.'/'.strtolower($model).'/file/'.$name['attachthumb'];
			}
		}
		return $attachthumb;
	}
}
?>