<?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 dhtml($string) {
	if(is_array($string)) {
		foreach($string as $key => $val) {
			$string[$key] = dhtml($val);
		}
	} else {
		$string = str_replace(array('"', '\'', '<', '>', "\t", "\r", '{', '}'), array('&quot;', '&#39;', '&lt;', '&gt;', '&nbsp;&nbsp;', '', '&#123;', '&#125;'), $string);
	}
	return $string;
}
/**
 * 转换网址
 */
function cvhttp($http){
	if ($http==''){
		return $http;
	}else {
		$link=substr($http,0,7)=="http://"?$http:'http://'.$http;
		return $link;
	}
	
}
/**
 * 返回格式化文件尺寸
 * 
 * @param Int $size 文件尺寸单位（B）
 */
function RealSize($size)
{
	if ($size < 1024)
	{
		return $size.' Byte';
	}
	if ($size < 1048576)
	{
		return round($size / 1024, 2).' KB';
	}
	if ($size < 1073741824)
	{
		return round($size / 1048576, 2).' MB';
	}
	if ($size < 1099511627776)
	{
		return round($size / 1073741824, 2).' GB';
	}
}
/**
 * 清空或删除文件夹
 */
function cpweb_delete_folder($dirName,$all=false,$delete=false){
	if(!is_dir($dirName)){
		return false;
	}
	$handle=@opendir($dirName);
	while(($file=@readdir($handle))!==false){
		if($file!='.' && $file!='..'){
			$dir=$dirName.'/'.$file;
			if(is_dir($dir)){
				if($all) cpweb_delete_folder($dir);
			}else{
				@unlink($dir);
			}
		}
	}
	closedir($handle);
	if($delete){
		return rmdir($dirName);
	}else{
		return $dirName;
	}
}
/**
 * 获取附件地址
 *
 * @access  public
 * @param   array   $name       内容数组
 * @param   int     $model      模块地址
 * @param   int     $id         网站ID
 * @return  mix
 */
function attach($name,$model=false,$attachdir='Attachments',$root=true){
	$cprood=$root?__ROOT__.'/':'';
	if($name['attachment']){
		if(preg_match('/(\/)/',$name['attachment'],$i)){
			$attach=$cprood.$name['attachment'];
		}else{
			if($name['attachpath']){
				$attach=$cprood.C(ATTACHDIR).'/'.$name['attachfolder'].'/'.strtolower($name['address']).'/'.$name['attachpath'].'/'.$name['attachment'];
			}else{
				$attach=$cprood.C(ATTACHDIR).'/'.$attachdir.'/'.strtolower($model).'/file/'.$name['attachment'];
			}
		}
		return $attach;
	}
}
function attachthumb($name,$model=false,$attachdir='Attachments',$root=true){
	$cprood=$root?__ROOT__.'/':'';
	if($name['attachthumb']){
		if(preg_match('/(\/)/',$name['attachthumb'],$i)){
			$attachthumb=$cprood.$name['attachthumb'];
		}else{
			if($name['attachpath']){
				$attachthumb=$cprood.C(ATTACHDIR).'/'.$name['attachfolder'].'/'.strtolower($name['address']).'/'.$name['attachpath'].'/'.$name['attachthumb'];
			}else{
				$attachthumb=$cprood.C(ATTACHDIR).'/'.$attachdir.'/'.strtolower($model).'/file/'.$name['attachthumb'];
			}
		}
		return $attachthumb;
	}
}
?>