<?php
@$vercode=''; //此处取值请自行修改
if(!empty($vercode)){
		if ($_POST['vercode']!=$vercode){
		 echo("[err]invalid vercode[/err]");
		 exit();
		}
}



//zzcity add 

$_GET['m']='content';
$_GET['c']='content';
$_GET['a']='add';
$_POST['dosubmit']='保存后自动关闭';
$siteid=!empty($_POST['siteid']) ? trim($_POST['siteid']) : 1;
$_POST['siteid']=$_POST['default_siteid']=$_GET['siteid']=$siteid;
$_POST['status']=!empty($_POST['status']) ? trim($_POST['status']) : 99;
//$_POST['info']['copyfrom']=isset($_POST['info']['copyfrom']) ? trim($_POST['info']['copyfrom']) : '';
$_POST['copyfrom_data']=0;
$_POST['status']=$_POST['status'] ? intval($_POST['status']) : 99;
$_POST['info']['username'] = $_POST['username'];
$_POST['introcude_length']=!empty($_POST['introcude_length']) ? trim($_POST['introcude_length']) : 200;
$_POST['introcude_length']=$_POST['introcude_length'] ? intval($_POST['introcude_length']) : 200;
$_POST['auto_thumb_no']=!empty($_POST['auto_thumb_no']) ? trim($_POST['auto_thumb_no']) : 1;
$_POST['auto_thumb_no']=$_POST['auto_thumb_no'] ? intval($_POST['auto_thumb_no']) : 1;
$_POST['info']['paginationtype']=!empty($_POST['info']['paginationtype']) ? trim($_POST['info']['paginationtype']) : 0;
$_POST['info']['paginationtype']=$_POST['info']['paginationtype'] ? intval($_POST['info']['paginationtype']) : 0;

$_POST['info']['maxcharperpage']=!empty($_POST['info']['maxcharperpage']) ? trim($_POST['info']['maxcharperpage']) : 1000;
$_POST['info']['maxcharperpage']=$_POST['info']['maxcharperpage'] ? intval($_POST['info']['maxcharperpage']) : 1000;
$_POST['info']['posids'][]=-1;
//$_POST['info']['groupids_view']=1;
if (!empty($_POST['info']['content'])){
    $_POST['info']['content']=trim($_POST['info']['content']);
}
$_POST['info']['keywords']=!empty($_POST['info']['keywords']) ? trim($_POST['info']['keywords']) : '';
$_POST['info']['keywords']=$_POST['info']['keywords'] ? $_POST['info']['keywords'] : '';


define('PHPCMS_PATH', dirname(__FILE__).DIRECTORY_SEPARATOR);


//include PHPCMS_PATH.'/phpcms/base.php';
//替换base.php
/**
 *  base.php PHPCMS框架入口文件
 *
 * @copyright            (C) 2005-2010 PHPCMS
 * @license                http://www.phpcms.cn/license/
 * @lastmodify            2010-6-7
 */
define('IN_PHPCMS', true);

//PHPCMS框架路径
//define('PC_PATH', dirname(__FILE__).DIRECTORY_SEPARATOR); 
define('PC_PATH', dirname(__FILE__).DIRECTORY_SEPARATOR.'phpcms'.DIRECTORY_SEPARATOR); //zzcity modi

if(!defined('PHPCMS_PATH')) define('PHPCMS_PATH', PC_PATH.'..'.DIRECTORY_SEPARATOR);

//缓存文件夹地址
define('CACHE_PATH', PHPCMS_PATH.'caches'.DIRECTORY_SEPARATOR);
//主机协议
define('SITE_PROTOCOL', isset($_SERVER['SERVER_PORT']) && $_SERVER['SERVER_PORT'] == '443' ? 'https://' : 'http://');
//当前访问的主机名
define('SITE_URL', (isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : ''));
//来源
define('HTTP_REFERER', isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '');

//系统开始时间
define('SYS_START_TIME', microtime());

//加载公用函数库
//pc_base::load_sys_func('global'); //替换base.php的目的，就是为了替换global.func.php
        //global.func.php开始
        /**
         *  global.func.php 公共函数库
         *
         * @copyright            (C) 2005-2010 PHPCMS
         * @license                http://www.phpcms.cn/license/
         * @lastmodify            2010-6-1
         */
        
        /**
         * 返回经addslashes处理过的字符串或数组
         * @param $string 需要处理的字符串或数组
         * @return mixed
         */
        function new_addslashes($string){
            if(!is_array($string)) return addslashes($string);
            foreach($string as $key => $val) $string[$key] = new_addslashes($val);
            return $string;
        }
        
        /**
         * 返回经stripslashes处理过的字符串或数组
         * @param $string 需要处理的字符串或数组
         * @return mixed
         */
        function new_stripslashes($string) {
            if(!is_array($string)) return stripslashes($string);
            foreach($string as $key => $val) $string[$key] = new_stripslashes($val);
            return $string;
        }
        
        /**
         * 返回经htmlspecialchars处理过的字符串或数组
         * @param $obj 需要处理的字符串或数组
         * @return mixed
         */
        function new_html_special_chars($string) {
            if(!is_array($string)) return htmlspecialchars($string);
            foreach($string as $key => $val) $string[$key] = new_html_special_chars($val);
            return $string;
        }
        /**
         * 安全过滤函数
         *
         * @param $string
         * @return string
         */
        function safe_replace($string) {
            $string = str_replace('%20','',$string);
            $string = str_replace('%27','',$string);
            $string = str_replace('%2527','',$string);
            $string = str_replace('*','',$string);
            $string = str_replace('"','&quot;',$string);
            $string = str_replace("'",'',$string);
            $string = str_replace('"','',$string);
            $string = str_replace(';','',$string);
            $string = str_replace('<','&lt;',$string);
            $string = str_replace('>','&gt;',$string);
            $string = str_replace("{",'',$string);
            $string = str_replace('}','',$string);
            $string = str_replace('\\','',$string);
            return $string;
        }
        
        
        
        /**
         * 过滤ASCII码从0-28的控制字符
         * @return String
         */
        function trim_unsafe_control_chars($str) {
            $rule = '/[' . chr ( 1 ) . '-' . chr ( 8 ) . chr ( 11 ) . '-' . chr ( 12 ) . chr ( 14 ) . '-' . chr ( 31 ) . ']*/';
            return str_replace ( chr ( 0 ), '', preg_replace ( $rule, '', $str ) );
        }
        
        /**
         * 格式化文本域内容
         *
         * @param $string 文本域内容
         * @return string
         */
        function trim_textarea($string) {
            $string = nl2br ( str_replace ( ' ', '&nbsp;', $string ) );
            return $string;
        }
        
        /**
         * 将文本格式成适合js输出的字符串
         * @param string $string 需要处理的字符串
         * @param intval $isjs 是否执行字符串格式化，默认为执行
         * @return string 处理后的字符串
         */
        function format_js($string, $isjs = 1) {
            $string = addslashes(str_replace(array("\r", "\n", "\t"), array('', '', ''), $string));
            return $isjs ? 'document.write("'.$string.'");' : $string;
        }
        
        /**
         * 转义 javascript 代码标记
         *
         * @param $str
         * @return mixed
         */
         function trim_script($str) {
            if(is_array($str)){
                foreach ($str as $key => $val){
                    $str[$key] = trim_script($val);
                }
            }else{
                $str = preg_replace ( '/\<([\/]?)script([^\>]*?)\>/si', '&lt;\\1script\\2&gt;', $str );
                $str = preg_replace ( '/\<([\/]?)iframe([^\>]*?)\>/si', '&lt;\\1iframe\\2&gt;', $str );
                $str = preg_replace ( '/\<([\/]?)frame([^\>]*?)\>/si', '&lt;\\1frame\\2&gt;', $str );
                $str = preg_replace ( '/]]\>/si', ']] >', $str );
            }
            return $str;
        }
        /**
         * 获取当前页面完整URL地址
         */
        function get_url() {
            $sys_protocal = isset($_SERVER['SERVER_PORT']) && $_SERVER['SERVER_PORT'] == '443' ? 'https://' : 'http://';
            $php_self = $_SERVER['PHP_SELF'] ? safe_replace($_SERVER['PHP_SELF']) : safe_replace($_SERVER['SCRIPT_NAME']);
            $path_info = isset($_SERVER['PATH_INFO']) ? safe_replace($_SERVER['PATH_INFO']) : '';
            $relate_url = isset($_SERVER['REQUEST_URI']) ? safe_replace($_SERVER['REQUEST_URI']) : $php_self.(isset($_SERVER['QUERY_STRING']) ? '?'.safe_replace($_SERVER['QUERY_STRING']) : $path_info);
            return $sys_protocal.(isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : '').$relate_url;
        }
        /**
         * 字符截取 支持UTF8/GBK
         * @param $string
         * @param $length
         * @param $dot
         */
        function str_cut($string, $length, $dot = '...') {
            $strlen = strlen($string);
            if($strlen <= $length) return $string;
    $string = str_replace(array(' ','&nbsp;', '&amp;', '&quot;', '&#039;', '&ldquo;', '&rdquo;', '&mdash;', '&lt;', '&gt;', '&middot;', '&hellip;'), array('∵',' ', '&', '"', "'", '"', '"', '—', '<', '>', '·', '…'), $string);
            $strcut = '';
            if(strtolower(CHARSET) == 'utf-8') {
                $length = intval($length-strlen($dot)-$length/3);
                $n = $tn = $noc = 0;
                while($n < strlen($string)) {
                    $t = ord($string[$n]);
                    if($t == 9 || $t == 10 || (32 <= $t && $t <= 126)) {
                        $tn = 1; $n++; $noc++;
                    } elseif(194 <= $t && $t <= 223) {
                        $tn = 2; $n += 2; $noc += 2;
                    } elseif(224 <= $t && $t <= 239) {
                        $tn = 3; $n += 3; $noc += 2;
                    } elseif(240 <= $t && $t <= 247) {
                        $tn = 4; $n += 4; $noc += 2;
                    } elseif(248 <= $t && $t <= 251) {
                        $tn = 5; $n += 5; $noc += 2;
                    } elseif($t == 252 || $t == 253) {
                        $tn = 6; $n += 6; $noc += 2;
                    } else {
                        $n++;
                    }
                    if($noc >= $length) {
                        break;
                    }
                }
                if($noc > $length) {
                    $n -= $tn;
                }
                $strcut = substr($string, 0, $n);
        $strcut = str_replace(array('∵', '&', '"', "'", '"', '"', '—', '<', '>', '·', '…'), array(' ', '&amp;', '&quot;', '&#039;', '&ldquo;', '&rdquo;', '&mdash;', '&lt;', '&gt;', '&middot;', '&hellip;'), $strcut);
            } else {
                $dotlen = strlen($dot);
                $maxi = $length - $dotlen - 1;
                $current_str = '';
        $search_arr = array('&',' ', '"', "'", '"', '"', '—', '<', '>', '·', '…','∵');
                $replace_arr = array('&amp;','&nbsp;', '&quot;', '&#039;', '&ldquo;', '&rdquo;', '&mdash;', '&lt;', '&gt;', '&middot;', '&hellip;',' ');
                $search_flip = array_flip($search_arr);
                for ($i = 0; $i < $maxi; $i++) {
                    $current_str = ord($string[$i]) > 127 ? $string[$i].$string[++$i] : $string[$i];
                    if (in_array($current_str, $search_arr)) {
                        $key = $search_flip[$current_str];
                        $current_str = str_replace($search_arr[$key], $replace_arr[$key], $current_str);
                    }
                    $strcut .= $current_str;
                }
            }
            return $strcut.$dot;
        }
        
        
        
        /**
         * 获取请求ip
         *
         * @return ip地址
         */
        function ip() {
            if(getenv('HTTP_CLIENT_IP') && strcasecmp(getenv('HTTP_CLIENT_IP'), 'unknown')) {
                $ip = getenv('HTTP_CLIENT_IP');
            } elseif(getenv('HTTP_X_FORWARDED_FOR') && strcasecmp(getenv('HTTP_X_FORWARDED_FOR'), 'unknown')) {
                $ip = getenv('HTTP_X_FORWARDED_FOR');
            } elseif(getenv('REMOTE_ADDR') && strcasecmp(getenv('REMOTE_ADDR'), 'unknown')) {
                $ip = getenv('REMOTE_ADDR');
            } elseif(isset($_SERVER['REMOTE_ADDR']) && $_SERVER['REMOTE_ADDR'] && strcasecmp($_SERVER['REMOTE_ADDR'], 'unknown')) {
                $ip = $_SERVER['REMOTE_ADDR'];
            }
            return preg_match ( '/[\d\.]{7,15}/', $ip, $matches ) ? $matches [0] : '';
        }
        
        function get_cost_time() {
            $microtime = microtime ( TRUE );
            return $microtime - SYS_START_TIME;
        }
        /**
         * 程序执行时间
         *
         * @return    int    单位ms
         */
        function execute_time() {
            $stime = explode ( ' ', SYS_START_TIME );
            $etime = explode ( ' ', microtime () );
            return number_format ( ($etime [1] + $etime [0] - $stime [1] - $stime [0]), 6 );
        }
        
        /**
        * 产生随机字符串
        *
        * @param    int        $length  输出长度
        * @param    string     $chars   可选的 ，默认为 0123456789
        * @return   string     字符串
        */
        function random($length, $chars = '0123456789') {
            $hash = '';
            $max = strlen($chars) - 1;
            for($i = 0; $i < $length; $i++) {
                $hash .= $chars[mt_rand(0, $max)];
            }
            return $hash;
        }
        
        /**
        * 将字符串转换为数组
        *
        * @param    string    $data    字符串
        * @return    array    返回数组格式，如果，data为空，则返回空数组
        */
        function string2array($data) {
            if($data == '') return array();
            @eval("\$array = $data;");
            return $array;
        }
        /**
        * 将数组转换为字符串
        *
        * @param    array    $data        数组
        * @param    bool    $isformdata    如果为0，则不使用new_stripslashes处理，可选参数，默认为1
        * @return    string    返回字符串，如果，data为空，则返回空
        */
        function array2string($data, $isformdata = 1) {
            if($data == '') return '';
            if($isformdata) $data = new_stripslashes($data);
            return addslashes(var_export($data, TRUE));
        }
        
        /**
        * 转换字节数为其他单位
        *
        *
        * @param    string    $filesize    字节大小
        * @return    string    返回大小
        */
        function sizecount($filesize) {
            if ($filesize >= 1073741824) {
                $filesize = round($filesize / 1073741824 * 100) / 100 .' GB';
            } elseif ($filesize >= 1048576) {
                $filesize = round($filesize / 1048576 * 100) / 100 .' MB';
            } elseif($filesize >= 1024) {
                $filesize = round($filesize / 1024 * 100) / 100 . ' KB';
            } else {
                $filesize = $filesize.' Bytes';
            }
            return $filesize;
        }
        /**
        * 字符串加密、解密函数
        *
        *
        * @param    string    $txt        字符串
        * @param    string    $operation    ENCODE为加密，DECODE为解密，可选参数，默认为ENCODE，
        * @param    string    $key        密钥：数字、字母、下划线
        * @param    string    $expiry        过期时间
        * @return    string
        */
        function sys_auth($string, $operation = 'ENCODE', $key = '', $expiry = 0) {
            $key_length = 4;
            $key = md5($key != '' ? $key : pc_base::load_config('system', 'auth_key'));
            $fixedkey = md5($key);
            $egiskeys = md5(substr($fixedkey, 16, 16));
            $runtokey = $key_length ? ($operation == 'ENCODE' ? substr(md5(microtime(true)), -$key_length) : substr($string, 0, $key_length)) : '';
            $keys = md5(substr($runtokey, 0, 16) . substr($fixedkey, 0, 16) . substr($runtokey, 16) . substr($fixedkey, 16));
            $string = $operation == 'ENCODE' ? sprintf('%010d', $expiry ? $expiry + time() : 0).substr(md5($string.$egiskeys), 0, 16) . $string : base64_decode(substr($string, $key_length));
        
            $i = 0; $result = '';
            $string_length = strlen($string);
            for ($i = 0; $i < $string_length; $i++){
                $result .= chr(ord($string{$i}) ^ ord($keys{$i % 32}));
            }
            if($operation == 'ENCODE') {
                return $runtokey . str_replace('=', '', base64_encode($result));
            } else {
                if((substr($result, 0, 10) == 0 || substr($result, 0, 10) - time() > 0) && substr($result, 10, 16) == substr(md5(substr($result, 26).$egiskeys), 0, 16)) {
                    return substr($result, 26);
                } else {
                    return '';
                }
            }
        }
        /**
        * 语言文件处理
        *
        * @param    string        $language    标示符
        * @param    array        $pars    转义的数组,二维数组 ,'key1'=>'value1','key2'=>'value2',
        * @param    string        $modules 多个模块之间用半角逗号隔开，如：member,guestbook
        * @return    string        语言字符
        */
        function L($language = 'no_language',$pars = array(), $modules = '') {
            static $LANG = array();
            static $LANG_MODULES = array();
            static $lang = '';
            if(defined('IN_ADMIN')) {
                $lang = SYS_STYLE ? SYS_STYLE : 'zh-cn';
            } else {
                $lang = pc_base::load_config('system','lang');
            }
            if(!$LANG) {
                require_once PC_PATH.'languages'.DIRECTORY_SEPARATOR.$lang.DIRECTORY_SEPARATOR.'system.lang.php';
                if(defined('IN_ADMIN')) require_once PC_PATH.'languages'.DIRECTORY_SEPARATOR.$lang.DIRECTORY_SEPARATOR.'system_menu.lang.php';
                if(file_exists(PC_PATH.'languages'.DIRECTORY_SEPARATOR.$lang.DIRECTORY_SEPARATOR.ROUTE_M.'.lang.php')) require PC_PATH.'languages'.DIRECTORY_SEPARATOR.$lang.DIRECTORY_SEPARATOR.ROUTE_M.'.lang.php';
            }
            if(!empty($modules)) {
                $modules = explode(',',$modules);
                foreach($modules AS $m) {
                    if(!isset($LANG_MODULES[$m])) require PC_PATH.'languages'.DIRECTORY_SEPARATOR.$lang.DIRECTORY_SEPARATOR.$m.'.lang.php';
                }
            }
            if(!array_key_exists($language,$LANG)) {
                return $language;
            } else {
                $language = $LANG[$language];
                if($pars) {
                    foreach($pars AS $_k=>$_v) {
                        $language = str_replace('{'.$_k.'}',$_v,$language);
                    }
                }
                return $language;
            }
        }
        
        /**
         * 模板调用
         *
         * @param $module
         * @param $template
         * @param $istag
         * @return unknown_type
         */
        function template($module = 'content', $template = 'index', $style = '') {
        
            if(strpos($module, 'plugin/')!== false) {
                $plugin = str_replace('plugin/', '', $module);
                return p_template($plugin, $template,$style);
            }
            $module = str_replace('/', DIRECTORY_SEPARATOR, $module);
            if(!empty($style) && preg_match('/([a-z0-9\-_]+)/is',$style)) {
            } elseif (empty($style) && !defined('STYLE')) {                
                if(defined('SITEID')) {
                    $siteid = SITEID;
                } else {
                    $siteid = param::get_cookie('siteid');
                }
                if (!$siteid) $siteid = 1;
                $sitelist = getcache('sitelist','commons');
                if(!empty($siteid)) {
                    $style = $sitelist[$siteid]['default_style'];
                }
            } elseif (empty($style) && defined('STYLE')) {
                $style = STYLE;
            } else {
                $style = 'default';
            }
            if(!$style) $style = 'default';
            $template_cache = pc_base::load_sys_class('template_cache');
            $compiledtplfile = PHPCMS_PATH.'caches'.DIRECTORY_SEPARATOR.'caches_template'.DIRECTORY_SEPARATOR.$style.DIRECTORY_SEPARATOR.$module.DIRECTORY_SEPARATOR.$template.'.php';
            if(file_exists(PC_PATH.'templates'.DIRECTORY_SEPARATOR.$style.DIRECTORY_SEPARATOR.$module.DIRECTORY_SEPARATOR.$template.'.html')) {
                if(!file_exists($compiledtplfile) || (@filemtime(PC_PATH.'templates'.DIRECTORY_SEPARATOR.$style.DIRECTORY_SEPARATOR.$module.DIRECTORY_SEPARATOR.$template.'.html') > @filemtime($compiledtplfile))) {
                    $template_cache->template_compile($module, $template, $style);
                }
            } else {
                $compiledtplfile = PHPCMS_PATH.'caches'.DIRECTORY_SEPARATOR.'caches_template'.DIRECTORY_SEPARATOR.'default'.DIRECTORY_SEPARATOR.$module.DIRECTORY_SEPARATOR.$template.'.php';
                if(!file_exists($compiledtplfile) || (file_exists(PC_PATH.'templates'.DIRECTORY_SEPARATOR.'default'.DIRECTORY_SEPARATOR.$module.DIRECTORY_SEPARATOR.$template.'.html') && filemtime(PC_PATH.'templates'.DIRECTORY_SEPARATOR.'default'.DIRECTORY_SEPARATOR.$module.DIRECTORY_SEPARATOR.$template.'.html') > filemtime($compiledtplfile))) {
                    $template_cache->template_compile($module, $template, 'default');
                } elseif (!file_exists(PC_PATH.'templates'.DIRECTORY_SEPARATOR.'default'.DIRECTORY_SEPARATOR.$module.DIRECTORY_SEPARATOR.$template.'.html')) {
                    zzshowmessage('Template does not exist.'.DIRECTORY_SEPARATOR.$style.DIRECTORY_SEPARATOR.$module.DIRECTORY_SEPARATOR.$template.'.html');
                }
            }
            return $compiledtplfile;
        }
        
        /**
         * 输出自定义错误
         *
         * @param $errno 错误号
         * @param $errstr 错误描述
         * @param $errfile 报错文件地址
         * @param $errline 错误行号
         * @return string 错误提示
         */
        
        function my_error_handler($errno, $errstr, $errfile, $errline) {
            if($errno==8) return '';
            $errfile = str_replace(PHPCMS_PATH,'',$errfile);
            if(pc_base::load_config('system','errorlog')) {
                error_log('<?php exit;?>'.date('m-d H:i:s',SYS_TIME).' | '.$errno.' | '.str_pad($errstr,30).' | '.$errfile.' | '.$errline."\r\n", 3, CACHE_PATH.'error_log.php');
            } else {
                $str = '<div style="font-size:12px;text-align:left; border-bottom:1px solid #9cc9e0; border-right:1px solid #9cc9e0;padding:1px 4px;color:#000000;font-family:Arial, Helvetica,sans-serif;"><span>errorno:' . $errno . ',str:' . $errstr . ',file:<font color="blue">' . $errfile . '</font>,line' . $errline .'<br /><a href="http://faq.phpcms.cn/?type=file&errno='.$errno.'&errstr='.urlencode($errstr).'&errfile='.urlencode($errfile).'&errline='.$errline.'" target="_blank" style="color:red">Need Help?</a></span></div>';
                echo $str;
            }
        }
        
        /**
         * 提示信息页面跳转，跳转地址如果传入数组，页面会提示多个地址供用户选择，默认跳转地址为数组的第一个值，时间为5秒。
         * zzshowmessage('登录成功', array('默认跳转地址'=>'http://www.phpcms.cn'));
         * @param string $msg 提示信息
         * @param mixed(string/array) $url_forward 跳转地址
         * @param int $ms 跳转等待时间
         */
        function showmessage($msg, $url_forward = 'goback', $ms = 1250, $dialog = '', $returnjs = '') {
            if(defined('IN_ADMIN')) {
                include(admin::admin_tpl('zzshowmessage', 'admin'));
            } else {
                include(template('content', 'message'));
            }
            exit;
        }
        /**
         * 查询字符是否存在于某字符串
         *
         * @param $haystack 字符串
         * @param $needle 要查找的字符
         * @return bool
         */
        function str_exists($haystack, $needle)
        {
            return !(strpos($haystack, $needle) === FALSE);
        }
        
        /**
         * 取得文件扩展
         *
         * @param $filename 文件名
         * @return 扩展名
         */
        function fileext($filename) {
            return strtolower(trim(substr(strrchr($filename, '.'), 1, 10)));

        }
        
        /**
         * 加载模板标签缓存
         * @param string $name 缓存名
         * @param integer $times 缓存时间
         */
        function tpl_cache($name,$times = 0) {
            $filepath = 'tpl_data';
            $info = getcacheinfo($name, $filepath);
            if (SYS_TIME - $info['filemtime'] >= $times) {
                return false;
            } else {
                return getcache($name,$filepath);
            }
        }
        
        /**
         * 写入缓存，默认为文件缓存，不加载缓存配置。
         * @param $name 缓存名称
         * @param $data 缓存数据
         * @param $filepath 数据路径（模块名称） caches/cache_$filepath/
         * @param $type 缓存类型[file,memcache,apc]
         * @param $config 配置名称
         * @param $timeout 过期时间
         */
        function setcache($name, $data, $filepath='', $type='file', $config='', $timeout=0) {
            pc_base::load_sys_class('cache_factory','',0);
            if($config) {
                $cacheconfig = pc_base::load_config('cache');
                $cache = cache_factory::get_instance($cacheconfig)->get_cache($config);
            } else {
                $cache = cache_factory::get_instance()->get_cache($type);
            }
        
            return $cache->set($name, $data, $timeout, '', $filepath);
        }
        
        /**
         * 读取缓存，默认为文件缓存，不加载缓存配置。
         * @param string $name 缓存名称
         * @param $filepath 数据路径（模块名称） caches/cache_$filepath/
         * @param string $config 配置名称
         */
        function getcache($name, $filepath='', $type='file', $config='') {
            pc_base::load_sys_class('cache_factory','',0);
            if($config) {
                $cacheconfig = pc_base::load_config('cache');
                $cache = cache_factory::get_instance($cacheconfig)->get_cache($config);
            } else {
                $cache = cache_factory::get_instance()->get_cache($type);
            }
            return $cache->get($name, '', '', $filepath);
        }
        
        /**
         * 删除缓存，默认为文件缓存，不加载缓存配置。
         * @param $name 缓存名称
         * @param $filepath 数据路径（模块名称） caches/cache_$filepath/
         * @param $type 缓存类型[file,memcache,apc]
         * @param $config 配置名称
         */
        function delcache($name, $filepath='', $type='file', $config='') {
            pc_base::load_sys_class('cache_factory','',0);
            if($config) {
                $cacheconfig = pc_base::load_config('cache');
                $cache = cache_factory::get_instance($cacheconfig)->get_cache($config);
            } else {
                $cache = cache_factory::get_instance()->get_cache($type);
            }
            return $cache->delete($name, '', '', $filepath);
        }
        
        /**
         * 读取缓存，默认为文件缓存，不加载缓存配置。
         * @param string $name 缓存名称
         * @param $filepath 数据路径（模块名称） caches/cache_$filepath/
         * @param string $config 配置名称
         */
        function getcacheinfo($name, $filepath='', $type='file', $config='') {
            pc_base::load_sys_class('cache_factory');
            if($config) {
                $cacheconfig = pc_base::load_config('cache');
                $cache = cache_factory::get_instance($cacheconfig)->get_cache($config);
            } else {
                $cache = cache_factory::get_instance()->get_cache($type);
            }
            return $cache->cacheinfo($name, '', '', $filepath);
        }
        
        /**
         * 生成sql语句，如果传入$in_cloumn 生成格式为 IN('a', 'b', 'c')
         * @param $data 条件数组或者字符串
         * @param $front 连接符
         * @param $in_column 字段名称
         * @return string
         */
        function to_sqls($data, $front = ' AND ', $in_column = false) {
            if($in_column && is_array($data)) {
                $ids = '\''.implode('\',\'', $data).'\'';
                $sql = "$in_column IN ($ids)";
                return $sql;
            } else {
                if ($front == '') {
                    $front = ' AND ';
                }
                if(is_array($data) && count($data) > 0) {
                    $sql = '';
                    foreach ($data as $key => $val) {
                        $sql .= $sql ? " $front `$key` = '$val' " : " `$key` = '$val' ";
                    }
                    return $sql;
                } else {
                    return $data;
                }
            }
        }
        
        /**
         * 分页函数
         *
         * @param $num 信息总数
         * @param $curr_page 当前分页
         * @param $perpage 每页显示数
         * @param $urlrule URL规则
         * @param $array 需要传递的数组，用于增加额外的方法
         * @return 分页
         */
        function pages($num, $curr_page, $perpage = 20, $urlrule = '', $array = array(),$setpages = 10) {
            if(defined('URLRULE') && $urlrule == '') {
                $urlrule = URLRULE;
                $array = $GLOBALS['URL_ARRAY'];
            } elseif($urlrule == '') {
                $urlrule = url_par('page={$page}');
            }
            $multipage = '';
            if($num > $perpage) {
                $page = $setpages+1;
                $offset = ceil($setpages/2-1);
                $pages = ceil($num / $perpage);
                if (defined('IN_ADMIN') && !defined('PAGES')) define('PAGES', $pages);
                $from = $curr_page - $offset;
                $to = $curr_page + $offset;
                $more = 0;
                if($page >= $pages) {
                    $from = 2;
                    $to = $pages-1;
                } else {
                    if($from <= 1) {
                        $to = $page-1;
                        $from = 2;
                    }  elseif($to >= $pages) {
                        $from = $pages-($page-2);
                        $to = $pages-1;
                    }
                    $more = 1;
                }
                $multipage .= '<a class="a1">'.$num.L('page_item').'</a>';
                if($curr_page>0) {
                    $multipage .= ' <a href="'.pageurl($urlrule, $curr_page-1, $array).'" class="a1">'.L('previous').'</a>';
                    if($curr_page==1) {
                        $multipage .= ' <span>1</span>';
                    } elseif($curr_page>6 && $more) {
                        $multipage .= ' <a href="'.pageurl($urlrule, 1, $array).'">1</a>..';
                    } else {
                        $multipage .= ' <a href="'.pageurl($urlrule, 1, $array).'">1</a>';
                    }
                }
                for($i = $from; $i <= $to; $i++) {
                    if($i != $curr_page) {
                        $multipage .= ' <a href="'.pageurl($urlrule, $i, $array).'">'.$i.'</a>';
                    } else {
                        $multipage .= ' <span>'.$i.'</span>';
                    }
                }
                if($curr_page<$pages) {
                    if($curr_page<$pages-5 && $more) {
                        $multipage .= ' ..<a href="'.pageurl($urlrule, $pages, $array).'">'.$pages.'</a> <a href="'.pageurl($urlrule, $curr_page+1, $array).'" class="a1">'.L('next').'</a>';
                    } else {
                        $multipage .= ' <a href="'.pageurl($urlrule, $pages, $array).'">'.$pages.'</a> <a href="'.pageurl($urlrule, $curr_page+1, $array).'" class="a1">'.L('next').'</a>';
                    }
                } elseif($curr_page==$pages) {
                    $multipage .= ' <span>'.$pages.'</span> <a href="'.pageurl($urlrule, $curr_page, $array).'" class="a1">'.L('next').'</a>';
                } else {
                    $multipage .= ' <a href="'.pageurl($urlrule, $pages, $array).'">'.$pages.'</a> <a href="'.pageurl($urlrule, $curr_page+1, $array).'" class="a1">'.L('next').'</a>';
                }
            }
            return $multipage;
        }
        /**
         * 返回分页路径
         *
         * @param $urlrule 分页规则
         * @param $page 当前页
         * @param $array 需要传递的数组，用于增加额外的方法
         * @return 完整的URL路径
         */
        function pageurl($urlrule, $page, $array = array()) {
            if(strpos($urlrule, '~')) {
                $urlrules = explode('~', $urlrule);
                $urlrule = $page < 2 ? $urlrules[0] : $urlrules[1];
            }
            $findme = array('{$page}');
            $replaceme = array($page);
            if (is_array($array)) foreach ($array as $k=>$v) {
                $findme[] = '{$'.$k.'}';
                $replaceme[] = $v;
            }
            $url = str_replace($findme, $replaceme, $urlrule);
            $url = str_replace(array('http://','//','~'), array('~','/','http://'), $url);
            return $url;
        }
        
        /**
         * URL路径解析，pages 函数的辅助函数
         *
         * @param $par 传入需要解析的变量 默认为，page={$page}
         * @param $url URL地址
         * @return URL
         */
        function url_par($par, $url = '') {
            if($url == '') $url = get_url();
            $pos = strpos($url, '?');
            if($pos === false) {
                $url .= '?'.$par;
            } else {
                $querystring = substr(strstr($url, '?'), 1);
                parse_str($querystring, $pars);
                $query_array = array();
                foreach($pars as $k=>$v) {
                    if($k != 'page') $query_array[$k] = $v;
                }
                $querystring = http_build_query($query_array).'&'.$par;
                $url = substr($url, 0, $pos).'?'.$querystring;
            }
            return $url;
        }
        
        /**
         * 判断email格式是否正确
         * @param $email
         */
        function is_email($email) {
            return strlen($email) > 6 && preg_match("/^[\w\-\.]+@[\w\-\.]+(\.\w+)+$/", $email);
        }
        
        /**
         * iconv 编辑转换
         */
        if (!function_exists('iconv')) {
            function iconv($in_charset, $out_charset, $str) {
                $in_charset = strtoupper($in_charset);
                $out_charset = strtoupper($out_charset);
                if (function_exists('mb_convert_encoding')) {
                    return mb_convert_encoding($str, $out_charset, $in_charset);
                } else {
                    pc_base::load_sys_func('iconv');
                    $in_charset = strtoupper($in_charset);
                    $out_charset = strtoupper($out_charset);
                    if ($in_charset == 'UTF-8' && ($out_charset == 'GBK' || $out_charset == 'GB2312')) {
                        return utf8_to_gbk($str);
                    }
                    if (($in_charset == 'GBK' || $in_charset == 'GB2312') && $out_charset == 'UTF-8') {
                        return gbk_to_utf8($str);
                    }
                    return $str;
                }
            }
        }
        
        /**
         * 代码广告展示函数
         * @param intval $siteid 所属站点
         * @param intval $id 广告ID
         * @return 返回广告代码
         */
        function show_ad($siteid, $id) {
            $siteid = intval($siteid);
            $id = intval($id);
            if(!$id || !$siteid) return false;
            $p = pc_base::load_model('poster_model');
            $r = $p->get_one(array('spaceid'=>$id, 'siteid'=>$siteid), 'disabled, setting', '`id` ASC');
            if ($r['disabled']) return '';
            if ($r['setting']) {
                $c = string2array($r['setting']);
            } else {
                $r['code'] = '';
            }
            return $c['code'];
        }
        
        /**
         * 获取当前的站点ID
         */
        function get_siteid() {
//            static $siteid;         
            global $siteid;         //zzcity modi ，替换global.func.php 为修改这里            
            if (!empty($siteid)) return $siteid;
    if (!defined('IN_ADMIN')) {        
                if ($d = param::get_cookie('siteid')) {
                    $siteid = $d;
                } else {
                    return '';
                }
            } else {
                $data = getcache('sitelist', 'commons');
                if(!is_array($data)) return '1';
                $site_url = SITE_PROTOCOL.SITE_URL;
                foreach ($data as $v) {
                    if ($v['url'] == $site_url.'/') $siteid = $v['siteid'];
                }
            }
            if (empty($siteid)) $siteid = 1;
            return $siteid;
        }
        
        /**
         * 获取用户昵称
         * 不传入userid取当前用户nickname,如果nickname为空取username
         * 传入field，取用户$field字段信息
         */
        function get_nickname($userid='', $field='') {
            $return = '';
            if(is_numeric($userid)) {
                $member_db = pc_base::load_model('member_model');
                $memberinfo = $member_db->get_one(array('userid'=>$userid));
                if(!empty($field) && $field != 'nickname' && isset($memberinfo[$field]) &&!empty($memberinfo[$field])) {
                    $return = $memberinfo[$field];
                } else {
                    $return = isset($memberinfo['nickname']) && !empty($memberinfo['nickname']) ? $memberinfo['nickname'].'('.$memberinfo['username'].')' : $memberinfo['username'];
                }
            } else {
                if (param::get_cookie('_nickname')) {
                    $return .= '('.param::get_cookie('_nickname').')';
                } else {
                    $return .= '('.param::get_cookie('_username').')';
                }
            }
            return $return;
        }
        
        /**
         * 获取用户信息
         * 不传入$field返回用户所有信息,
         * 传入field，取用户$field字段信息
         */
        function get_memberinfo($userid, $field='') {
            if(!is_numeric($userid)) {
                return false;
            } else {
                static $memberinfo;
                if (!isset($memberinfo[$userid])) {
                    $member_db = pc_base::load_model('member_model');
                    $memberinfo[$userid] = $member_db->get_one(array('userid'=>$userid));
                }
                if(!empty($field) && !empty($memberinfo[$userid][$field])) {
                    return $memberinfo[$userid][$field];
                } else {
                    return $memberinfo[$userid];
                }
            }
        }
        
        /**
         * 通过 username 值，获取用户所有信息
         * 获取用户信息
         * 不传入$field返回用户所有信息,
         * 传入field，取用户$field字段信息
         */
        function get_memberinfo_buyusername($username, $field='') {
            if(empty($username)){return false;}
            static $memberinfo;
            if (!isset($memberinfo[$username])) {
                $member_db = pc_base::load_model('member_model');
                $memberinfo[$username] = $member_db->get_one(array('username'=>$username));
            }
            if(!empty($field) && !empty($memberinfo[$username][$field])) {
                return $memberinfo[$username][$field];
            } else {
                return $memberinfo[$username];
            }
        }
        
        /**
         * 获取用户头像，建议传入phpssouid
         * @param $uid 默认为phpssouid
         * @param $is_userid $uid是否为v9 userid，如果为真，执行sql查询此用户的phpssouid
         * @param $size 头像大小 有四种[30x30 45x45 90x90 180x180] 默认30
         */
        function get_memberavatar($uid, $is_userid='', $size='30') {
            if($is_userid) {
                $db = pc_base::load_model('member_model');
                $memberinfo = $db->get_one(array('userid'=>$uid));
                if(isset($memberinfo['phpssouid'])) {
                    $uid = $memberinfo['phpssouid'];
                } else {
                    return false;
                }
            }
        
            pc_base::load_app_class('client', 'member', 0);
            define('APPID', pc_base::load_config('system', 'phpsso_appid'));
            $phpsso_api_url = pc_base::load_config('system', 'phpsso_api_url');
            $phpsso_auth_key = pc_base::load_config('system', 'phpsso_auth_key');
            $client = new client($phpsso_api_url, $phpsso_auth_key);
            $avatar = $client->ps_getavatar($uid);
            if(isset($avatar[$size])) {
                return $avatar[$size];
            } else {
                return false;
            }
        }
        
        /**
         * 调用关联菜单
         * @param $linkageid 联动菜单id
         * @param $id 生成联动菜单的样式id
         * @param $defaultvalue 默认值
         */
        function menu_linkage($linkageid = 0, $id = 'linkid', $defaultvalue = 0) {
            $linkageid = intval($linkageid);
            $datas = array();
            $datas = getcache($linkageid,'linkage');
            $infos = $datas['data'];
        
            if($datas['style']=='1') {
                $title = $datas['title'];
                $container = 'content'.random(3).date('is');
                if(!defined('DIALOG_INIT_1')) {
                    define('DIALOG_INIT_1', 1);
                    $string .= '<script type="text/javascript" src="'.JS_PATH.'dialog.js"></script>';
                    //TODO $string .= '<link href="'.CSS_PATH.'dialog.css" rel="stylesheet" type="text/css">';
                }
                if(!defined('LINKAGE_INIT_1')) {
                    define('LINKAGE_INIT_1', 1);
                    $string .= '<script type="text/javascript" src="'.JS_PATH.'linkage/js/pop.js"></script>';
                }
                $var_div = $defaultvalue && (ROUTE_A=='edit' || ROUTE_A=='account_manage_info'  || ROUTE_A=='info_publish' || ROUTE_A=='orderinfo') ? menu_linkage_level($defaultvalue,$linkageid,$infos) : $datas['title'];
                $var_input = $defaultvalue && (ROUTE_A=='edit' || ROUTE_A=='account_manage_info'  || ROUTE_A=='info_publish') ? '<input type="hidden" name="info['.$id.']" value="'.$defaultvalue.'">' : '<input type="hidden" name="info['.$id.']" value="">';
                $string .= '<div name="'.$id.'" value="" id="'.$id.'" class="ib">'.$var_div.'</div>'.$var_input.' <input type="button" name="btn_'.$id.'" class="button" value="'.L('linkage_select').'" onclick="open_linkage(\''.$id.'\',\''.$title.'\','.$container.',\''.$linkageid.'\')">';
                $string .= '<script type="text/javascript">';
                $string .= 'var returnid_'.$id.'= \''.$id.'\';';
                $string .= 'var returnkeyid_'.$id.' = \''.$linkageid.'\';';
                $string .=  'var '.$container.' = new Array(';
                foreach($infos AS $k=>$v) {
                    if($v['parentid'] == 0) {
                        $s[]='new Array(\''.$v['linkageid'].'\',\''.$v['name'].'\',\''.$v['parentid'].'\')';
                    } else {
                        continue;
                    }
                }
                $s = implode(',',$s);
                $string .=$s;
                $string .= ')';
                $string .= '</script>';
                
            } elseif($datas['style']=='2') {
                if(!defined('LINKAGE_INIT_1')) {
                    define('LINKAGE_INIT_1', 1);
                    $string .= '<script type="text/javascript" src="'.JS_PATH.'linkage/js/jquery.ld.js"></script>';
                }
                $default_txt = '';
                if($defaultvalue) {
                        $default_txt = menu_linkage_level($defaultvalue,$linkageid,$infos);
                        $default_txt = '["'.str_replace(' > ','","',$default_txt).'"]';
                }
                $string .= $defaultvalue && (ROUTE_A=='edit' || ROUTE_A=='account_manage_info'  || ROUTE_A=='info_publish') ? '<input type="hidden" name="info['.$id.']"  id="'.$id.'" value="'.$defaultvalue.'">' : '<input type="hidden" name="info['.$id.']"  id="'.$id.'" value="">';
        
                for($i=1;$i<=$datas['setting']['level'];$i++) {
                    $string .='<select class="pc-select-'.$id.'" name="'.$id.'-'.$i.'" id="'.$id.'-'.$i.'" width="100"><option value="">请选择菜单</option></select> ';
                }
        
                $string .= '<script type="text/javascript">
                            $(function(){
                                var $ld5 = $(".pc-select-'.$id.'");                      
                                $ld5.ld({ajaxOptions : {"url" : "'.APP_PATH.'api.php?op=get_linkage&act=ajax_select&keyid='.$linkageid.'"},defaultParentId : 0,style : {"width" : 120}})     
                                var ld5_api = $ld5.ld("api");
                                ld5_api.selected('.$default_txt.');
                                $ld5.bind("change",onchange);
                                function onchange(e){
                                    var $target = $(e.target);
                                    var index = $ld5.index($target);
                                    $("#'.$id.'-'.$i.'").remove();
                                    $("#'.$id.'").val($ld5.eq(index).show().val());
                                    index ++;
                                    $ld5.eq(index).show();                                }
                            })
                </script>';
                    
            } else {
                $title = $defaultvalue ? $infos[$defaultvalue]['name'] : $datas['title'];
                $colObj = random(3).date('is');
                $string = '';
                if(!defined('LINKAGE_INIT')) {
                    define('LINKAGE_INIT', 1);
                    $string .= '<script type="text/javascript" src="'.JS_PATH.'linkage/js/mln.colselect.js"></script>';
                    if(defined('IN_ADMIN')) {
                        $string .= '<link href="'.JS_PATH.'linkage/style/admin.css" rel="stylesheet" type="text/css">';
                    } else {
                        $string .= '<link href="'.JS_PATH.'linkage/style/css.css" rel="stylesheet" type="text/css">';
                    }
                }
                $string .= '<input type="hidden" name="info['.$id.']" value="1"><div id="'.$id.'"></div>';
                $string .= '<script type="text/javascript">';
                $string .= 'var colObj'.$colObj.' = {"Items":[';
        
                foreach($infos AS $k=>$v) {
                    $s .= '{"name":"'.$v['name'].'","topid":"'.$v['parentid'].'","colid":"'.$k.'","value":"'.$k.'","fun":function(){}},';
                }
        
                $string .= substr($s, 0, -1);
                $string .= ']};';
                $string .= '$("#'.$id.'").mlnColsel(colObj'.$colObj.',{';
                $string .= 'title:"'.$title.'",';
                $string .= 'value:"'.$defaultvalue.'",';
                $string .= 'width:100';
                $string .= '});';
                $string .= '</script>';
            }
            return $string;
        }
        
        /**
         * 联动菜单层级
         */
        
        function menu_linkage_level($linkageid,$keyid,$infos,$result=array()) {
            if(array_key_exists($linkageid,$infos)) {
                $result[]=$infos[$linkageid]['name'];
                return menu_linkage_level($infos[$linkageid]['parentid'],$keyid,$infos,$result);
            }
            krsort($result);
            return implode(' > ',$result);
        }
        /**
         * 通过catid获取显示菜单完整结构
         * @param  $menuid 菜单ID
         * @param  $cache_file 菜单缓存文件名称
         * @param  $cache_path 缓存文件目录
         * @param  $key 取得缓存值的键值名称
         * @param  $parentkey 父级的ID
         * @param  $linkstring 链接字符
         */
        function menu_level($menuid, $cache_file, $cache_path = 'commons', $key = 'catname', $parentkey = 'parentid', $linkstring = ' > ', $result=array()) {
            $menu_arr = getcache($cache_file, $cache_path);
            if (array_key_exists($menuid, $menu_arr)) {
                $result[] = $menu_arr[$menuid][$key];
                return menu_level($menu_arr[$menuid][$parentkey], $cache_file, $cache_path, $key, $parentkey, $linkstring, $result);
            }
            krsort($result);
            return implode($linkstring, $result);
        }
        /**
         * 通过id获取显示联动菜单
         * @param  $linkageid 联动菜单ID
         * @param  $keyid 菜单keyid
         * @param  $space 菜单间隔符
         * @param  $tyoe 1 返回间隔符链接，完整路径名称 3 返回完整路径数组，2返回当前联动菜单名称，4 直接返回ID
         * @param  $result 递归使用字段1
         * @param  $infos 递归使用字段2
         */
        function get_linkage($linkageid, $keyid, $space = '>', $type = 1, $result = array(), $infos = array()) {
            if($space=='' || !isset($space))$space = '>';
            if(!$infos) {
                $datas = getcache($keyid,'linkage');
                $infos = $datas['data'];
            }
            if($type == 1 || $type == 3 || $type == 4) {
                if(array_key_exists($linkageid,$infos)) {
                    $result[]= ($type == 1) ? $infos[$linkageid]['name'] : (($type == 4) ? $linkageid :$infos[$linkageid]);
                    return get_linkage($infos[$linkageid]['parentid'], $keyid, $space, $type, $result, $infos);
                } else {
                    if(count($result)>0) {
                        krsort($result);
                        if($type == 1 || $type == 4) $result = implode($space,$result);
                        return $result;
                    } else {
                        return $result;
                    }
                }
            } else {
                return $infos[$linkageid]['name'];
            }
        }
        /**
         * IE浏览器判断
         */
        
        function is_ie() {
            $useragent = strtolower($_SERVER['HTTP_USER_AGENT']);
            if((strpos($useragent, 'opera') !== false) || (strpos($useragent, 'konqueror') !== false)) return false;
            if(strpos($useragent, 'msie ') !== false) return true;
            return false;
        }
        
        
        /**
         * 文件下载
         * @param $filepath 文件路径
         * @param $filename 文件名称
         */
        
        function file_down($filepath, $filename = '') {
            if(!$filename) $filename = basename($filepath);
            if(is_ie()) $filename = rawurlencode($filename);
            $filetype = fileext($filename);
            $filesize = sprintf("%u", filesize($filepath));
            if(ob_get_length() !== false) @ob_end_clean();
            header('Pragma: public');
            header('Last-Modified: '.gmdate('D, d M Y H:i:s') . ' GMT');
            header('Cache-Control: no-store, no-cache, must-revalidate');
            header('Cache-Control: pre-check=0, post-check=0, max-age=0');
            header('Content-Transfer-Encoding: binary');
            header('Content-Encoding: none');
            header('Content-type: '.$filetype);
            header('Content-Disposition: attachment; filename="'.$filename.'"');
            header('Content-length: '.$filesize);
            readfile($filepath);
            exit;
        }
        
        /**
         * 判断字符串是否为utf8编码，英文和半角字符返回ture
         * @param $string
         * @return bool
         */
        function is_utf8($string) {
            return preg_match('%^(?:
                            [\x09\x0A\x0D\x20-\x7E] # ASCII
                            | [\xC2-\xDF][\x80-\xBF] # non-overlong 2-byte
                            | \xE0[\xA0-\xBF][\x80-\xBF] # excluding overlongs
                            | [\xE1-\xEC\xEE\xEF][\x80-\xBF]{2} # straight 3-byte
                            | \xED[\x80-\x9F][\x80-\xBF] # excluding surrogates
                            | \xF0[\x90-\xBF][\x80-\xBF]{2} # planes 1-3
                            | [\xF1-\xF3][\x80-\xBF]{3} # planes 4-15
                            | \xF4[\x80-\x8F][\x80-\xBF]{2} # plane 16
                            )*$%xs', $string);
        }
        
        /**
         * 组装生成ID号
         * @param $modules 模块名
         * @param $contentid 内容ID
         * @param $siteid 站点ID
         */
        function id_encode($modules,$contentid, $siteid) {
            return urlencode($modules.'-'.$contentid.'-'.$siteid);
        }
        
        /**
         * 解析ID
         * @param $id 评论ID
         */
        function id_decode($id) {
            return explode('-', $id);
        }
        
        /**
         * 对用户的密码进行加密
         * @param $password
         * @param $encrypt //传入加密串，在修改密码时做认证
         * @return array/password
         */
        function password($password, $encrypt='') {
            $pwd = array();
            $pwd['encrypt'] =  $encrypt ? $encrypt : create_randomstr();
            $pwd['password'] = md5(md5(trim($password)).$pwd['encrypt']);
            return $encrypt ? $pwd['password'] : $pwd;
        }
        /**
         * 生成随机字符串
         * @param string $lenth 长度
         * @return string 字符串
         */
        function create_randomstr($lenth = 6) {
            return random($lenth, '123456789abcdefghijklmnpqrstuvwxyzABCDEFGHIJKLMNPQRSTUVWXYZ');
        }
        
        /**
         * 检查密码长度是否符合规定
         *
         * @param STRING $password
         * @return     TRUE or FALSE
         */
        function is_password($password) {
            $strlen = strlen($password);
            if($strlen >= 6 && $strlen <= 20) return true;
            return false;
        }
        
         /**
        
         * 检测输入中是否含有错误字符
         *
         * @param char $string 要检查的字符串名称
         * @return TRUE or FALSE
         */
        function is_badword($string) {
            $badwords = array("\\",'&',' ',"'",'"','/','*',',','<','>',"\r","\t","\n","#");
            foreach($badwords as $value){
                if(strpos($string, $value) !== FALSE) {
                    return TRUE;
                }
            }
            return FALSE;
        }
        
        /**
         * 检查用户名是否符合规定
         *
         * @param STRING $username 要检查的用户名
         * @return     TRUE or FALSE
         */
        function is_username($username) {
            $strlen = strlen($username);
            if(is_badword($username) || !preg_match("/^[a-zA-Z0-9_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]+$/", $username)){
                return false;
            } elseif ( 20 < $strlen || $strlen < 2 ) {
                return false;
            }
            return true;
        }
        
        /**
         * 检查id是否存在于数组中
         *
         * @param $id
         * @param $ids
         * @param $s
         */
        function check_in($id, $ids = '', $s = ',') {
            if(!$ids) return false;
            $ids = explode($s, $ids);
            return is_array($id) ? array_intersect($id, $ids) : in_array($id, $ids);
        }
        
        /**
         * 对数据进行编码转换
         * @param array/string $data       数组
         * @param string $input     需要转换的编码
         * @param string $output    转换后的编码
         */
        function array_iconv($data, $input = 'gbk', $output = 'utf-8') {
            if (!is_array($data)) {
                return iconv($input, $output, $data);
            } else {
                foreach ($data as $key=>$val) {
                    if(is_array($val)) {
                        $data[$key] = array_iconv($val, $input, $output);
                    } else {
                        $data[$key] = iconv($input, $output, $val);
                    }
                }
                return $data;
            }
        }
        
        /**
         * 生成缩略图函数
         * @param  $imgurl 图片路径
         * @param  $width  缩略图宽度
         * @param  $height 缩略图高度
         * @param  $autocut 是否自动裁剪 默认裁剪，当高度或宽度有一个数值为0是，自动关闭
         * @param  $smallpic 无图片是默认图片路径
         */
        function thumb($imgurl, $width = 100, $height = 100 ,$autocut = 1, $smallpic = 'nopic.gif') {
            global $image;
            $upload_url = pc_base::load_config('system','upload_url');
            $upload_path = pc_base::load_config('system','upload_path');
            if(empty($imgurl)) return IMG_PATH.$smallpic;
            $imgurl_replace= str_replace($upload_url, '', $imgurl);
            if(!extension_loaded('gd') || strpos($imgurl_replace, '://')) return $imgurl;
            if(!file_exists($upload_path.$imgurl_replace)) return IMG_PATH.$smallpic;
        
            list($width_t, $height_t, $type, $attr) = getimagesize($upload_path.$imgurl_replace);
            if($width>=$width_t || $height>=$height_t) return $imgurl;
        
            $newimgurl = dirname($imgurl_replace).'/thumb_'.$width.'_'.$height.'_'.basename($imgurl_replace);
        
            if(file_exists($upload_path.$newimgurl)) return $upload_url.$newimgurl;
        
            if(!is_object($image)) {
                pc_base::load_sys_class('image','','0');
                $image = new image(1,0);
            }
            return $image->thumb($upload_path.$imgurl_replace, $upload_path.$newimgurl, $width, $height, '', $autocut) ? $upload_url.$newimgurl : $imgurl;
        }
        
        /**
         * 水印添加
         * @param $source 原图片路径
         * @param $target 生成水印图片途径，默认为空，覆盖原图
         * @param $siteid 站点id，系统需根据站点id获取水印信息
         */
        function watermark($source, $target = '',$siteid) {
            global $image_w;
            if(empty($source)) return $source;
            if(!extension_loaded('gd') || strpos($source, '://')) return $source;
            if(!$target) $target = $source;
            if(!is_object($image_w)){
                pc_base::load_sys_class('image','','0');
                $image_w = new image(0,$siteid);
            }
                $image_w->watermark($source, $target);
            return $target;
        }
        
        /**
         * 当前路径
         * 返回指定栏目路径层级
         * @param $catid 栏目id
         * @param $symbol 栏目间隔符
         */
        function catpos($catid, $symbol=' > '){
            $category_arr = array();
            $siteids = getcache('category_content','commons');
            $siteid = $siteids[$catid];
            $category_arr = getcache('category_content_'.$siteid,'commons');
            if(!isset($category_arr[$catid])) return '';
            $pos = '';
            $siteurl = siteurl($category_arr[$catid]['siteid']);
            $arrparentid = array_filter(explode(',', $category_arr[$catid]['arrparentid'].','.$catid));
            foreach($arrparentid as $catid) {
                $url = $category_arr[$catid]['url'];
                if(strpos($url, '://') === false) $url = $siteurl.$url;
                $pos .= '<a href="'.$url.'">'.$category_arr[$catid]['catname'].'</a>'.$symbol;
            }
            return $pos;
        }
        
        /**
         * 根据catid获取子栏目数据的sql语句
         * @param string $module 缓存文件名
         * @param intval $catid 栏目ID
         */
        
        function get_sql_catid($file = 'category_content_1', $catid = 0, $module = 'commons') {
            $category = getcache($file,$module);
            $catid = intval($catid);
            if(!isset($category[$catid])) return false;
            return $category[$catid]['child'] ? " `catid` IN(".$category[$catid]['arrchildid'].") " : " `catid`=$catid ";
        }
        
        /**
         * 获取子栏目
         * @param $parentid 父级id
         * @param $type 栏目类型
         * @param $self 是否包含本身 0为不包含
         * @param $siteid 站点id
         */
        function subcat($parentid = NULL, $type = NULL,$self = '0', $siteid = '') {
            if (empty($siteid)) $siteid = get_siteid();
            $category = getcache('category_content_'.$siteid,'commons');
            foreach($category as $id=>$cat) {
                if($cat['siteid'] == $siteid && ($parentid === NULL || $cat['parentid'] == $parentid) && ($type === NULL || $cat['type'] == $type)) $subcat[$id] = $cat;
                if($self == 1 && $cat['catid'] == $parentid && !$cat['child'])  $subcat[$id] = $cat;
            }
            return $subcat;
        }
        
        /**
         * 获取内容地址
         * @param $catid   栏目ID
         * @param $id      文章ID
         * @param $allurl  是否以绝对路径返回
         */
        function go($catid,$id, $allurl = 0) {
            static $category;
            if(empty($category)) {
                $siteids = getcache('category_content','commons');
                $siteid = $siteids[$catid];
                $category = getcache('category_content_'.$siteid,'commons');
            }
            $id = intval($id);
            if(!$id || !isset($category[$catid])) return '';
            $modelid = $category[$catid]['modelid'];
            if(!$modelid) return '';
            //$db = pc_base::load_model('content_model'); 
            $db=new zzcontent_model; //zzcity modi
            
            
            $db->set_model($modelid);
            $r = $db->get_one(array('id'=>$id), '`url`');
            if (!empty($allurl)) {
                if (strpos($r['url'], '://')===false) {
                    if (strpos($category[$catid]['url'], '://') === FALSE) {
                        $site = siteinfo($category[$catid]['siteid']);
                        $r['url'] = substr($site['domain'], 0, -1).$r['url'];
                    } else {
                        $r['url'] = $category[$catid]['url'].$r['url'];
                    }
                }
            }
        
            return $r['url'];
        }
        
        /**
         * 将附件地址转换为绝对地址
         * @param $path 附件地址
         */
        function atturl($path) {
            if(strpos($path, ':/')) {
                return $path;
            } else {
                $sitelist = getcache('sitelist','commons');
                $siteid =  get_siteid();
                $siteurl = $sitelist[$siteid]['domain'];
                $domainlen = strlen($sitelist[$siteid]['domain'])-1;
                $path = $siteurl.$path;
                $path = substr_replace($path, '/', strpos($path, '//',$domainlen),2);
                return     $path;
            }
        }
        
        /**
         * 判断模块是否安装
         * @param $m    模块名称
         */
        function module_exists($m = '') {
            if ($m=='admin') return true;
            $modules = getcache('modules', 'commons');
            $modules = array_keys($modules);
            return in_array($m, $modules);
        }
        
        /**
         * 生成SEO
         * @param $siteid       站点ID
         * @param $catid        栏目ID
         * @param $title        标题
         * @param $description  描述
         * @param $keyword      关键词
         */
        function seo($siteid, $catid = '', $title = '', $description = '', $keyword = '') {
            if (!empty($title))$title = strip_tags($title);
            if (!empty($description)) $description = strip_tags($description);
            if (!empty($keyword)) $keyword = str_replace(' ', ',', strip_tags($keyword));
            $sites = getcache('sitelist', 'commons');
            $site = $sites[$siteid];
            $cat = array();
            if (!empty($catid)) {
                $siteids = getcache('category_content','commons');
                $siteid = $siteids[$catid];
                $categorys = getcache('category_content_'.$siteid,'commons');
                $cat = $categorys[$catid];
                $cat['setting'] = string2array($cat['setting']);
            }
            $seo['site_title'] =isset($site['site_title']) && !empty($site['site_title']) ? $site['site_title'] : $site['name'];
            $seo['keyword'] = !empty($keyword) ? $keyword : $site['keywords'];
            $seo['description'] = isset($description) && !empty($description) ? $description : (isset($cat['setting']['meta_description']) && !empty($cat['setting']['meta_description']) ? $cat['setting']['meta_description'] : (isset($site['description']) && !empty($site['description']) ? $site['description'] : ''));
            $seo['title'] =  (isset($title) && !empty($title) ? $title.' - ' : '').(isset($cat['setting']['meta_title']) && !empty($cat['setting']['meta_title']) ? $cat['setting']['meta_title'].' - ' : (isset($cat['catname']) && !empty($cat['catname']) ? $cat['catname'].' - ' : ''));
            foreach ($seo as $k=>$v) {
                $seo[$k] = str_replace(array("\n","\r"),    '', $v);
            }
            return $seo;
        }
        
        /**
         * 获取站点的信息
         * @param $siteid   站点ID
         */
        function siteinfo($siteid) {
            static $sitelist;
            if (empty($sitelist)) $sitelist  = getcache('sitelist','commons');
            return isset($sitelist[$siteid]) ? $sitelist[$siteid] : '';
        }
        
        /**
         * 生成CNZZ统计代码
         */
        
        function tjcode() {
            if(!module_exists('cnzz')) return false;
            $config = getcache('cnzz', 'commons');
            if (empty($config)) {
                return false;
            } else {
                return '<script src=\'http://pw.cnzz.com/c.php?id='.$config['siteid'].'&l=2\' language=\'JavaScript\' charset=\'gb2312\'></script>';
            }
        }
        
        /**
         * 生成标题样式
         * @param $style   样式
         * @param $html    是否显示完整的STYLE
         */
        function title_style($style, $html = 1) {
            $str = '';
            if ($html) $str = ' style="';
            $style_arr = explode(';',$style);
            if (!empty($style_arr[0])) $str .= 'color:'.$style_arr[0].';';
            if (!empty($style_arr[1])) $str .= 'font-weight:'.$style_arr[1].';';
            if ($html) $str .= '" ';
            return $str;
        }
        
        /**
         * 获取站点域名
         * @param $siteid   站点id
         */
        function siteurl($siteid) {
            static $sitelist;
            if(!$siteid) return WEB_PATH;
            if(empty($sitelist)) $sitelist = getcache('sitelist','commons');
            return substr($sitelist[$siteid]['domain'],0,-1);
        }
        /**
         * 生成上传附件验证
         * @param $args   参数
         * @param $operation   操作类型(加密解密)
         */
        
        function upload_key($args) {
            $pc_auth_key = md5(pc_base::load_config('system','auth_key').$_SERVER['HTTP_USER_AGENT']);
            $authkey = md5($args.$pc_auth_key);
            return $authkey;
        }
        
        /**
         * 文本转换为图片
         * @param string $txt 图形化文本内容
         * @param int $fonttype 无外部字体时生成文字大小，取值范围1-5
         * @param int $fontsize 引入外部字体时，字体大小
         * @param string $font 字体名称 字体请放于phpcms\libs\data\font下
         * @param string $fontcolor 字体颜色 十六进制形式 如FFFFFF,FF0000
         */
        function string2img($txt, $fonttype = 5, $fontsize = 16, $font = '', $fontcolor = 'FF0000',$transparent = '1') {
            if(empty($txt)) return false;
            if(function_exists("imagepng")) {
                $txt = urlencode(sys_auth($txt));
                $txt = '<img src="'.APP_PATH.'api.php?op=creatimg&txt='.$txt.'&fonttype='.$fonttype.'&fontsize='.$fontsize.'&font='.$font.'&fontcolor='.$fontcolor.'&transparent='.$transparent.'" align="absmiddle">';
            }
            return $txt;
        }
        
        /**
         * 获取phpcms版本号
         */
        function get_pc_version($type='') {
            $version = pc_base::load_config('version');
            if($type==1) {
                return $version['pc_version'];
            } elseif($type==2) {
                return $version['pc_release'];
            } else {
                return $version['pc_version'].' '.$version['pc_release'];
            }
        }
        /**
         * 运行钩子（插件使用）
         */
        function runhook($method) {
            $time_start = getmicrotime();
            $data  = '';
            $getpclass = FALSE;
            $hook_appid = getcache('hook','plugins');
            if(!empty($hook_appid)) {
                foreach($hook_appid as $appid => $p) {
                    $pluginfilepath = PC_PATH.'plugin'.DIRECTORY_SEPARATOR.$p.DIRECTORY_SEPARATOR.'hook.class.php';
                    $getpclass = TRUE;
                    include_once $pluginfilepath;
                }
                $hook_appid = array_flip($hook_appid);
                if($getpclass) {
                    $pclass = new ReflectionClass('hook');
                    foreach($pclass->getMethods() as $r) {
                        $legalmethods[] = $r->getName();
                    }
                }
                if(in_array($method,$legalmethods)) {
                    foreach (get_declared_classes() as $class){
                         $refclass = new ReflectionClass($class);
                         if($refclass->isSubclassOf('hook')){
                            if ($_method = $refclass->getMethod($method)) {
                                    $classname = $refclass->getName();
                                if ($_method->isPublic() && $_method->isFinal()) {
                                    plugin_stat($hook_appid[$classname]);
                                    $data .= $_method->invoke(null);
                                }
                            }
                         }
                    }
                }
                return $data;
            }
        }
        
        function getmicrotime() {
            list($usec, $sec) = explode(" ",microtime());
            return ((float)$usec + (float)$sec);
        }
        
        /**
         * 插件前台模板加载
         * Enter description here ...
         * @param unknown_type $module
         * @param unknown_type $template
         * @param unknown_type $style
         */
        function p_template($plugin = 'content', $template = 'index',$style='default') {
            if(!$style) $style = 'default';
            $template_cache = pc_base::load_sys_class('template_cache');
            $compiledtplfile = PHPCMS_PATH.'caches'.DIRECTORY_SEPARATOR.'caches_template'.DIRECTORY_SEPARATOR.$style.DIRECTORY_SEPARATOR.'plugin'.DIRECTORY_SEPARATOR.$plugin.DIRECTORY_SEPARATOR.$template.'.php';
        
            if(!file_exists($compiledtplfile) || (file_exists(PC_PATH.'plugin'.DIRECTORY_SEPARATOR.$plugin.DIRECTORY_SEPARATOR.'templates'.DIRECTORY_SEPARATOR.$template.'.html') && filemtime(PC_PATH.'plugin'.DIRECTORY_SEPARATOR.$plugin.DIRECTORY_SEPARATOR.'templates'.DIRECTORY_SEPARATOR.$template.'.html') > filemtime($compiledtplfile))) {
                $template_cache->template_compile('plugin/'.$plugin, $template, 'default');
            } elseif (!file_exists(PC_PATH.'plugin'.DIRECTORY_SEPARATOR.$plugin.DIRECTORY_SEPARATOR.'templates'.DIRECTORY_SEPARATOR.$template.'.html')) {
                zzshowmessage('Template does not exist.'.DIRECTORY_SEPARATOR.'plugin'.DIRECTORY_SEPARATOR.$plugin.DIRECTORY_SEPARATOR.$template.'.html');
            }
        
            return $compiledtplfile;
        }
        /**
         * 读取缓存动态页面
         */
        function cache_page_start() {
            $relate_url = isset($_SERVER['REQUEST_URI']) ? safe_replace($_SERVER['REQUEST_URI']) : $php_self.(isset($_SERVER['QUERY_STRING']) ? '?'.safe_replace($_SERVER['QUERY_STRING']) : $path_info);
            define('CACHE_PAGE_ID', md5($relate_url));
            $contents = getcache(CACHE_PAGE_ID, 'page_tmp/'.substr(CACHE_PAGE_ID, 0, 2));
            if($contents && intval(substr($contents, 15, 10)) > SYS_TIME) {
                echo substr($contents, 29);
                exit;
            }
            if (!defined('HTML')) define('HTML',true);
            return true;
        }
        /**
         * 写入缓存动态页面
         */
        function cache_page($ttl = 360, $isjs = 0) {
            if($ttl == 0 || !defined('CACHE_PAGE_ID')) return false;
            $contents = ob_get_contents();
        
            if($isjs) $contents = format_js($contents);
            $contents = "<!--expiretime:".(SYS_TIME + $ttl)."-->\n".$contents;
            setcache(CACHE_PAGE_ID, $contents, 'page_tmp/'.substr(CACHE_PAGE_ID, 0, 2));
        }
        
        /**
         *
         * 获取远程内容
         * @param $url 接口url地址
         * @param $timeout 超时时间
         */
        function pc_file_get_contents($url, $timeout=30) {
            $stream = stream_context_create(array('http' => array('timeout' => $timeout)));
            return @file_get_contents($url, 0, $stream);
        }

        //global.func.php结束

pc_base::load_sys_func('extention');
pc_base::auto_load_func();

pc_base::load_config('system','errorlog') ? set_error_handler('my_error_handler') : error_reporting(E_ERROR | E_WARNING | E_PARSE);
//设置本地时差
function_exists('date_default_timezone_set') && date_default_timezone_set(pc_base::load_config('system','timezone'));

define('CHARSET' ,pc_base::load_config('system','charset'));
//输出页面字符集
header('Content-type: text/html; charset='.CHARSET);

define('SYS_TIME', time());
//定义网站根路径
define('WEB_PATH',pc_base::load_config('system','web_path'));
//js 路径
define('JS_PATH',pc_base::load_config('system','js_path'));
//css 路径
define('CSS_PATH',pc_base::load_config('system','css_path'));
//img 路径
define('IMG_PATH',pc_base::load_config('system','img_path'));
//动态程序路径
define('APP_PATH',pc_base::load_config('system','app_path'));

//应用静态文件路径
define('PLUGIN_STATICS_PATH',WEB_PATH.'statics/plugin/');

if(pc_base::load_config('system','gzip') && function_exists('ob_gzhandler')) {
    ob_start('ob_gzhandler');
} else {
    ob_start();
}

class pc_base {
    
    /**
     * 初始化应用程序
     */
    public static function creat_app() {
        return self::load_sys_class('application');
    }
    /**
     * 加载系统类方法
     * @param string $classname 类名
     * @param string $path 扩展地址
     * @param intger $initialize 是否初始化
     */
    public static function load_sys_class($classname, $path = '', $initialize = 1) {
            return self::_load_class($classname, $path, $initialize);
    }
    
    /**
     * 加载应用类方法
     * @param string $classname 类名
     * @param string $m 模块
     * @param intger $initialize 是否初始化
     */
    public static function load_app_class($classname, $m = '', $initialize = 1) {
        $m = empty($m) && defined('ROUTE_M') ? ROUTE_M : $m;
        if (empty($m)) return false;
        return self::_load_class($classname, 'modules'.DIRECTORY_SEPARATOR.$m.DIRECTORY_SEPARATOR.'classes', $initialize);
    }
    
    /**
     * 加载数据模型
     * @param string $classname 类名
     */
    public static function load_model($classname) {
        return self::_load_class($classname,'model');
    }
        
    /**
     * 加载类文件函数
     * @param string $classname 类名
     * @param string $path 扩展地址
     * @param intger $initialize 是否初始化
     */
    private static function _load_class($classname, $path = '', $initialize = 1) {
        static $classes = array();
        if (empty($path)) $path = 'libs'.DIRECTORY_SEPARATOR.'classes';

        $key = md5($path.$classname);
        if (isset($classes[$key])) {
            if (!empty($classes[$key])) {
                return $classes[$key];
            } else {
                return true;
            }
        }
        if (file_exists(PC_PATH.$path.DIRECTORY_SEPARATOR.$classname.'.class.php')) {
            include PC_PATH.$path.DIRECTORY_SEPARATOR.$classname.'.class.php';
            $name = $classname;
            if ($my_path = self::my_path(PC_PATH.$path.DIRECTORY_SEPARATOR.$classname.'.class.php')) {
                include $my_path;
                $name = 'MY_'.$classname;
            }
            if ($initialize) {
                $classes[$key] = new $name;
            } else {
                $classes[$key] = true;
            }
            return $classes[$key];
        } else {
            return false;
        }
    }
    
    /**
     * 加载系统的函数库
     * @param string $func 函数库名
     */
    public static function load_sys_func($func) {
        return self::_load_func($func);
    }
    
    /**
     * 自动加载autoload目录下函数库
     * @param string $func 函数库名
     */
    public static function auto_load_func($path='') {
        return self::_auto_load_func($path);
    }
    
    /**
     * 加载应用函数库
     * @param string $func 函数库名
     * @param string $m 模型名
     */
    public static function load_app_func($func, $m = '') {
        $m = empty($m) && defined('ROUTE_M') ? ROUTE_M : $m;
        if (empty($m)) return false;
        return self::_load_func($func, 'modules'.DIRECTORY_SEPARATOR.$m.DIRECTORY_SEPARATOR.'functions');
    }
    
    /**
     * 加载插件类库
     */
    public static function load_plugin_class($classname, $identification = '' ,$initialize = 1) {
        $identification = empty($identification) && defined('PLUGIN_ID') ? PLUGIN_ID : $identification;
        if (empty($identification)) return false;
        return pc_base::load_sys_class($classname, 'plugin'.DIRECTORY_SEPARATOR.$identification.DIRECTORY_SEPARATOR.'classes', $initialize);
    }
    
    /**
     * 加载插件函数库
     * @param string $func 函数文件名称
     * @param string $identification 插件标识
     */
    public static function load_plugin_func($func,$identification) {
        static $funcs = array();
        $identification = empty($identification) && defined('PLUGIN_ID') ? PLUGIN_ID : $identification;
        if (empty($identification)) return false;
        $path = 'plugin'.DIRECTORY_SEPARATOR.$identification.DIRECTORY_SEPARATOR.'functions'.DIRECTORY_SEPARATOR.$func.'.func.php';
        $key = md5($path);
        if (isset($funcs[$key])) return true;
        if (file_exists(PC_PATH.$path)) {
            include PC_PATH.$path;
        } else {
            $funcs[$key] = false;
            return false;
        }
        $funcs[$key] = true;
        return true;
    }
    
    /**
     * 加载插件数据模型
     * @param string $classname 类名
     */
    public static function load_plugin_model($classname,$identification) {
        $identification = empty($identification) && defined('PLUGIN_ID') ? PLUGIN_ID : $identification;
        $path = 'plugin'.DIRECTORY_SEPARATOR.$identification.DIRECTORY_SEPARATOR.'model';
        return self::_load_class($classname,$path);
    }
    
    /**
     * 加载函数库
     * @param string $func 函数库名
     * @param string $path 地址
     */
    private static function _load_func($func, $path = '') {
        static $funcs = array();
        if (empty($path)) $path = 'libs'.DIRECTORY_SEPARATOR.'functions';
        $path .= DIRECTORY_SEPARATOR.$func.'.func.php';
        $key = md5($path);
        if (isset($funcs[$key])) return true;
        if (file_exists(PC_PATH.$path)) {
            include PC_PATH.$path;
        } else {
            $funcs[$key] = false;
            return false;
        }
        $funcs[$key] = true;
        return true;
    }
    
    /**
     * 加载函数库
     * @param string $func 函数库名
     * @param string $path 地址
     */
    private static function _auto_load_func($path = '') {
        if (empty($path)) $path = 'libs'.DIRECTORY_SEPARATOR.'functions'.DIRECTORY_SEPARATOR.'autoload';
        $path .= DIRECTORY_SEPARATOR.'*.func.php';
        $auto_funcs = glob(PC_PATH.DIRECTORY_SEPARATOR.$path);
        if(!empty($auto_funcs) && is_array($auto_funcs)) {
            foreach($auto_funcs as $func_path) {
                include $func_path;
            }
        }
    }
    /**
     * 是否有自己的扩展文件
     * @param string $filepath 路径
     */
    public static function my_path($filepath) {
        $path = pathinfo($filepath);
        if (file_exists($path['dirname'].DIRECTORY_SEPARATOR.'MY_'.$path['basename'])) {
            return $path['dirname'].DIRECTORY_SEPARATOR.'MY_'.$path['basename'];
        } else {
            return false;
        }
    }
    
    /**
     * 加载配置文件
     * @param string $file 配置文件
     * @param string $key  要获取的配置荐
     * @param string $default  默认配置。当获取配置项目失败时该值发生作用。
     * @param boolean $reload 强制重新加载。
     */
    public static function load_config($file, $key = '', $default = '', $reload = false) {
        static $configs = array();
        if (!$reload && isset($configs[$file])) {
            if (empty($key)) {
                return $configs[$file];
            } elseif (isset($configs[$file][$key])) {
                return $configs[$file][$key];
            } else {
                return $default;
            }
        }
        $path = CACHE_PATH.'configs'.DIRECTORY_SEPARATOR.$file.'.php';
        if (file_exists($path)) {
            $configs[$file] = include $path;
        }
        if (empty($key)) {
            return $configs[$file];
        } elseif (isset($configs[$file][$key])) {
            return $configs[$file][$key];
        } else {
            return $default;
        }
    }
}

//替换base.php结束

//消息处理
function zzshowmessage($msg, $url_forward = 'goback', $ms = 1250, $dialog = '', $returnjs = '') {
    echo('[err]'.$msg.'[err]');
    exit;
}


//登陆处理
function zzlogin() {
    global $siteid;    
        $admindb = pc_base::load_model('admin_model');
        $username = isset($_POST['username']) ? trim($_POST['username']) : exit('[err]用户名不能为空[/err]');
        //查询帐号
        $r = $admindb->get_one(array('username'=>$username));
        if(!$r) exit('[err]无此用户名[/err]');
        $password = md5(md5(trim((!isset($_GET['card']) ? $_POST['password'] : $_SESSION['card_password']))).$r['encrypt']);
        
        if($r['password'] != $password) {            
            exit('[err]密码错误[/err]');
        }
        
        $admindb->update(array('lastloginip'=>ip(),'lastlogintime'=>SYS_TIME),array('userid'=>$r['userid']));
        $_SESSION['userid'] = $r['userid'];
        $_SESSION['roleid'] = $r['roleid'];

        $_GET['pc_hash']=$_SESSION['pc_hash'] = random(6,'abcdefghigklmnopqrstuvwxwyABCDEFGHIGKLMNOPQRSTUVWXWY0123456789');
        
        $_SESSION['lock_screen'] = 0;
        
        //$siteid=$_POST['default_siteid']=$default_siteid = admin::return_siteid();    
        $siteid=$_POST['default_siteid']=$default_siteid =$_POST['siteid']; //zzcity add
        $cookie_time = SYS_TIME+86400*30;
        if(!$r['lang']) $r['lang'] = 'zh-cn';
        param::set_cookie('admin_username',$username,$cookie_time);
        param::set_cookie('siteid', $default_siteid,$cookie_time);
        param::set_cookie('userid', $r['userid'],$cookie_time);
        param::set_cookie('admin_email', $r['email'],$cookie_time);
        param::set_cookie('sys_lang', $r['lang'],$cookie_time);
        //zzshowmessage(L('login_success'),'?m=admin&c=index');
}

//pc_base::creat_app();

//zzcity 替代 pc_base::creat_app();
$param = pc_base::load_sys_class('param');

//api关键词开始
define('API_URL_GET_KEYWORDS', 'http://tool.phpcms.cn/api/get_keywords.php');

//自动关键词 zzcity add
if($_POST['info']['keywords']=='') {
    $_POST['info']['keywords']=get_keywords($_POST['info']['title'], 3);
}

function get_keywords($data, $number = 3) {
    $data = trim(strip_tags($data));
    if(empty($data)) return '';
    $http = pc_base::load_sys_class('http');
    if(CHARSET == 'utf-8') {
        $data = iconv('utf-8', 'gbk', $data);
    }
    $http->post(API_URL_GET_KEYWORDS, array('siteurl'=>SITE_URL, 'charset'=>CHARSET, 'data'=>$data, 'number'=>$number));
    if($http->is_ok()) {
        if(CHARSET != 'utf-8') {
            return $http->get_data();
        } else {
            return iconv('gbk', 'utf-8', $http->get_data());
        }
    }
    return '';
}
//api关键词结束



define('ROUTE_M', $param->route_m());
define('ROUTE_C', $param->route_c());
define('ROUTE_A', $param->route_a());


//content_input.class.php类开始

class zzcontent_input {
    var $modelid;
    var $fields;
    var $data;

    function __construct($modelid) {
        $this->db = pc_base::load_model('sitemodel_field_model');
        $this->db_pre = $this->db->db_tablepre;
        $this->modelid = $modelid;
        $this->fields = getcache('model_field_'.$modelid,'model');
        //初始化附件类
        pc_base::load_sys_class('attachment','',0);
        //$this->siteid = param::get_cookie('siteid');
        //zzcity modi
        $this->siteid=get_siteid();
        $this->attachment = new attachment('content','0',$this->siteid);
        $this->site_config = getcache('sitelist','commons');

        $this->site_config = $this->site_config[$this->siteid];
    }

    function get($data,$isimport = 0) {
        $this->data = $data = trim_script($data);
        $info = array();
        foreach($data as $field=>$value) {
            //if(!isset($this->fields[$field]) || check_in($_roleid, $this->fields[$field]['unsetroleids']) || check_in($_groupid, $this->fields[$field]['unsetgroupids'])) continue;
            $name = $this->fields[$field]['name'];
            $minlength = $this->fields[$field]['minlength'];
            $maxlength = $this->fields[$field]['maxlength'];
            $pattern = $this->fields[$field]['pattern'];
            $errortips = $this->fields[$field]['errortips'];
            if(empty($errortips)) $errortips = $name.' '.L('not_meet_the_conditions');
            $length = empty($value) ? 0 : (is_string($value) ? strlen($value) : count($value));

            if($minlength && $length < $minlength) {
                if($isimport) {
                    return false;
                } else {
                    showmessage($name.' '.L('not_less_than').' '.$minlength.L('characters'));
                }
            }
            if($maxlength && $length > $maxlength) {
                if($isimport) {
                    $value = str_cut($value,$maxlength,'');
                } else {
                    showmessage($name.' '.L('not_more_than').' '.$maxlength.L('characters'));
                }
            } elseif($maxlength) {
                $value = str_cut($value,$maxlength,'');
            }
            if($pattern && $length && !preg_match($pattern, $value) && !$isimport) showmessage($errortips);
            $MODEL = getcache('model', 'commons');
            $this->db->table_name = $this->fields[$field]['issystem'] ? $this->db_pre.$MODEL[$this->modelid]['tablename'] : $this->db_pre.$MODEL[$this->modelid]['tablename'].'_data';
            if($this->fields[$field]['isunique'] && $this->db->get_one(array($field=>$value),$field) && ROUTE_A != 'edit') showmessage($name.L('the_value_must_not_repeat'));
            $func = $this->fields[$field]['formtype'];
            if(method_exists($this, $func)) $value = $this->$func($field, $value);
            if($this->fields[$field]['issystem']) {
                $info['system'][$field] = $value;
            } else {
                $info['model'][$field] = $value;
            }
            //颜色选择为隐藏域 在这里进行取值
            $info['system']['style'] = $_POST['style_color'] ? strip_tags($_POST['style_color']) : '';
            if($_POST['style_font_weight']) $info['system']['style'] = $info['system']['style'].';'.strip_tags($_POST['style_font_weight']);
        }
        return $info;
    }
    function textarea($field, $value) {
        if(!$this->fields[$field]['enablehtml']) $value = strip_tags($value);
        return $value;
    }
    function editor($field, $value) {
        $setting = string2array($this->fields[$field]['setting']);
        $enablesaveimage = $setting['enablesaveimage'];
        if(isset($_POST['spider_img'])) $enablesaveimage = 0;
        if($enablesaveimage) {
            $site_setting = string2array($this->site_config['setting']);
            $watermark_enable = intval($site_setting['watermark_enable']);
            $value = $this->attachment->download('content', $value,$watermark_enable);
        }
        return $value;
    }
    function box($field, $value) {
        if($this->fields[$field]['boxtype'] == 'checkbox') {
            if(!is_array($value) || empty($value)) return false;
            array_shift($value);
            $value = ','.implode(',', $value).',';
            return $value;
        } elseif($this->fields[$field]['boxtype'] == 'multiple') {
            if(is_array($value) && count($value)>0) {
                $value = ','.implode(',', $value).',';
                return $value;
            }
        } else {
            return $value;
        }
    }
    function image($field, $value) {
        return trim($value);
    }
    function images($field, $value) {
        //取得图片列表
        $pictures = $_POST[$field.'_url'];
        //取得图片说明
        $pictures_alt = isset($_POST[$field.'_alt']) ? $_POST[$field.'_alt'] : array();
        $array = $temp = array();
        if(!empty($pictures)) {
            foreach($pictures as $key=>$pic) {
                $temp['url'] = $pic;
                $temp['alt'] = $pictures_alt[$key];
                $array[$key] = $temp;
            }
        }
        $array = array2string($array);
        return $array;
    }
    function datetime($field, $value) {
        $setting = string2array($this->fields[$field]['setting']);
        if($setting['fieldtype']=='int') {
            $value = strtotime($value);
        }
        return $value;
    }
    function posid($field, $value) {
        $number = count($value);
        $value = $number==1 ? 0 : 1;
        return $value;
    }
    function copyfrom($field, $value) {
        $field_data = $field.'_data';
        if(isset($_POST[$field_data])) {
            $value .= '|'.$_POST[$field_data];
        }
        return $value;
    }
    function groupid($field, $value) {
        $datas = '';
        if(!empty($_POST[$field]) && is_array($_POST[$field])) {
            $datas = implode(',',$_POST[$field]);
        }
        return $datas;
    }
    function downfile($field, $value) {
        //取得镜像站点列表
        $result = '';
        $server_list = count($_POST[$field.'_servers']) > 0 ? implode(',' ,$_POST[$field.'_servers']) : '';
        $result = $value.'|'.$server_list;
        return $result;
    }
    function downfiles($field, $value) {
        $files = $_POST[$field.'_fileurl'];
        $files_alt = $_POST[$field.'_filename'];
        $array = $temp = array();
        if(!empty($files)) {
            foreach($files as $key=>$file) {
                    $temp['fileurl'] = $file;
                    $temp['filename'] = $files_alt[$key];
                    $array[$key] = $temp;
            }
        }
        $array = array2string($array);
        return $array;
    }
    
    function video($field, $value) {
        $post_f = $field.'_video';
        if (isset($_POST[$post_f]) && !empty($_POST[$post_f])) {
            $value = 1;
            $video_store_db = pc_base::load_model('video_store_model');
            $setting = getcache('video', 'video');
            pc_base::load_app_class('ku6api', 'video', 0);
            $ku6api = new ku6api($setting['sn'], $setting['skey']);
            pc_base::load_app_class('v', 'video', 0);
            $v_class =  new v($video_store_db);
            $GLOBALS[$field] = '';
            foreach ($_POST[$post_f] as $_k => $v) {
                if (!$v['vid'] && !$v['videoid']) unset($_POST[$post_f][$_k]);
                $info = array();
                if ($v['vid']) {
                    if (!$v['title']) $v['title'] = safe_replace($this->data['title']);
                    $info = array('vid'=>$v['vid'], 'title'=>$v['title'], 'cid'=>intval($this->data['catid']));
                    if ($this->data['keywords']) $info['tag'] = addslashes($this->data['keywords']);
                    if ($this->data['description']) $info['description'] = addslashes($this->data['description']);
                    $get_data = $ku6api->vms_add($info);
                    if (!$get_data) {
                        continue;
                    }
                    $info['vid'] = $get_data['vid'];
                    $info['addtime'] = SYS_TIME;
                    $info['keywords'] = $info['tag'];
                    unset($info['cid'], $info['tag']);
                    $info['userupload'] = 1;
                    $videoid = $v_class->add($info);
                    $GLOBALS[$field][] = array('videoid' => $videoid, 'listorder' => $v['listorder']);
                } else {
                    $GLOBALS[$field][] = array('videoid' => $v['videoid'], 'listorder' => $v['listorder']);
                }
            }
        } else {
            $value = 0;
        }
        return $value;
    }

 } 

//content_input.class.php类结束



//content_model.class.php类开始
if(!defined('CACHE_MODEL_PATH')) define('CACHE_MODEL_PATH',CACHE_PATH.'caches_model'.DIRECTORY_SEPARATOR.'caches_data'.DIRECTORY_SEPARATOR);

/**
 * 内容模型数据库操作类
 */
pc_base::load_sys_class('model', '', 0);
class zzcontent_model extends model {
    public $table_name = '';
    public $category = '';
    public function __construct() {
        $this->db_config = pc_base::load_config('database');
        $this->db_setting = 'default';
        parent::__construct();
        $this->url = pc_base::load_app_class('url', 'content');
        $this->siteid = get_siteid();
    }
    public function set_model($modelid) {
        $this->model = getcache('model', 'commons');
        $this->modelid = $modelid;
        $this->table_name = $this->db_tablepre.$this->model[$modelid]['tablename'];
        $this->model_tablename = $this->model[$modelid]['tablename'];
    }
    /**
     * 添加内容
     * 
     * @param $datas
     * @param $isimport 是否为外部接口导入
     */
    public function add_content($data,$isimport = 0) {
        if($isimport) $data = new_addslashes($data);
        $this->search_db = pc_base::load_model('search_model');
        $modelid = $this->modelid;
        //require_once CACHE_MODEL_PATH.'content_input.class.php';  //zzcity modi
        require_once CACHE_MODEL_PATH.'content_update.class.php';
        $content_input = new zzcontent_input($this->modelid);
        $inputinfo = $content_input->get($data,$isimport);

        $systeminfo = $inputinfo['system'];
        $modelinfo = $inputinfo['model'];

        if($data['inputtime'] && !is_numeric($data['inputtime'])) {
            $systeminfo['inputtime'] = strtotime($data['inputtime']);
        } elseif(!$data['inputtime']) {
            $systeminfo['inputtime'] = SYS_TIME;
        } else {
            $systeminfo['inputtime'] = $data['inputtime'];
        }
        
        //读取模型字段配置中，关于日期配置格式，来组合日期数据
        $this->fields = getcache('model_field_'.$modelid,'model');
        $setting = string2array($this->fields['inputtime']['setting']);
        extract($setting);
        if($fieldtype=='date') {
            $systeminfo['inputtime'] = date('Y-m-d');
        }elseif($fieldtype=='datetime'){
             $systeminfo['inputtime'] = date('Y-m-d H:i:s');
        }

        if($data['updatetime'] && !is_numeric($data['updatetime'])) {
            $systeminfo['updatetime'] = strtotime($data['updatetime']);
        } elseif(!$data['updatetime']) {
            $systeminfo['updatetime'] = SYS_TIME;
        } else {
            $systeminfo['updatetime'] = $data['updatetime'];
        }
        $systeminfo['username'] = $data['username'] ? $data['username'] : param::get_cookie('admin_username');
        $systeminfo['sysadd'] = defined('IN_ADMIN') ? 1 : 0;
        
        //自动提取摘要
        if(isset($_POST['add_introduce']) && $systeminfo['description'] == '' && isset($modelinfo['content'])) {
            $content = stripslashes($modelinfo['content']);
            $introcude_length = intval($_POST['introcude_length']);
            $systeminfo['description'] = str_cut(str_replace(array("\r\n","\t",'[page]','[/page]','&ldquo;','&rdquo;','&nbsp;'), '', strip_tags($content)),$introcude_length);
            $inputinfo['system']['description'] = $systeminfo['description'] = addslashes($systeminfo['description']);
        }
        //自动提取缩略图
        if(isset($_POST['auto_thumb']) && $systeminfo['thumb'] == '' && isset($modelinfo['content'])) {
            $content = $content ? $content : stripslashes($modelinfo['content']);
            $auto_thumb_no = intval($_POST['auto_thumb_no'])-1;
            if(preg_match_all("/(src)=([\"|']?)([^ \"'>]+\.(gif|jpg|jpeg|bmp|png))\\2/i", $content, $matches)) {
                $systeminfo['thumb'] = $matches[3][$auto_thumb_no];
            }
        }
        //主表
        $tablename = $this->table_name = $this->db_tablepre.$this->model_tablename;
        $id = $modelinfo['id'] = $this->insert($systeminfo,true);
        $this->update($systeminfo,array('id'=>$id));
        //更新URL地址
        if($data['islink']==1) {
            $urls[0] = $_POST['linkurl'];
        } else {
            $urls = $this->url->show($id, 0, $systeminfo['catid'], $systeminfo['inputtime'], $data['prefix'],$inputinfo,'add');
        }
        $this->table_name = $tablename;
        $this->update(array('url'=>$urls[0]),array('id'=>$id));
        //附属表
        $this->table_name = $this->table_name.'_data';
        $this->insert($modelinfo);
        //添加统计
        $this->hits_db = pc_base::load_model('hits_model');
        $hitsid = 'c-'.$modelid.'-'.$id;
        $this->hits_db->insert(array('hitsid'=>$hitsid,'catid'=>$systeminfo['catid'],'updatetime'=>SYS_TIME));
        //更新到全站搜索
        $this->search_api($id,$inputinfo);
        //更新栏目统计数据
        $this->update_category_items($systeminfo['catid'],'add',1);
        //调用 update
        $content_update = new content_update($this->modelid,$id);
        //合并后，调用update
        $merge_data = array_merge($systeminfo,$modelinfo);
        $merge_data['posids'] = $data['posids'];
        $content_update->update($merge_data);
        
        //发布到审核列表中
        if(!defined('IN_ADMIN') || $data['status']!=99) {
            $this->content_check_db = pc_base::load_model('content_check_model');
            $check_data = array(
                'checkid'=>'c-'.$id.'-'.$modelid,
                'catid'=>$systeminfo['catid'],
                'siteid'=>$this->siteid,
                'title'=>$systeminfo['title'],
                'username'=>$systeminfo['username'],
                'inputtime'=>$systeminfo['inputtime'],
                'status'=>$data['status'],
                );
            $this->content_check_db->insert($check_data);
        }
        //END发布到审核列表中
        if(!$isimport) {
            $html = pc_base::load_app_class('html', 'content');
            $urls['data']['system']['id'] = $id;
            if($urls['content_ishtml'] && $data['status']==99) $html->show($urls[1],$urls['data']);
            $catid = $systeminfo['catid'];
        }
        //发布到其他栏目
        if($id && isset($_POST['othor_catid']) && is_array($_POST['othor_catid'])) {
            $linkurl = $urls[0];
            $r = $this->get_one(array('id'=>$id));
            foreach ($_POST['othor_catid'] as $cid=>$_v) {
                $this->set_catid($cid);
                $mid = $this->category[$cid]['modelid'];
                if($modelid==$mid) {
                    //相同模型的栏目插入新的数据
                    $inputinfo['system']['catid'] = $systeminfo['catid'] = $cid;
                    $newid = $modelinfo['id'] = $this->insert($systeminfo,true);
                    $this->table_name = $tablename.'_data';
                    $this->insert($modelinfo);
                    if($data['islink']==1) {
                        $urls = $_POST['linkurl'];
                    } else {
                        $urls = $this->url->show($newid, 0, $cid, $systeminfo['inputtime'], $data['prefix'],$inputinfo,'add');
                    }
                    $this->table_name = $tablename;
                    $this->update(array('url'=>$urls[0]),array('id'=>$newid));
                    //发布到审核列表中
                    if($data['status']!=99) {
                        $check_data = array(
                            'checkid'=>'c-'.$newid.'-'.$mid,
                            'catid'=>$cid,
                            'siteid'=>$this->siteid,
                            'title'=>$systeminfo['title'],
                            'username'=>$systeminfo['username'],
                            'inputtime'=>$systeminfo['inputtime'],
                            'status'=>1,
                            );
                        $this->content_check_db->insert($check_data);
                    }
                    if($urls['content_ishtml'] && $data['status']==99) $html->show($urls[1],$urls['data']);
                } else {
                    //不同模型插入转向链接地址
                    $newid = $this->insert(
                    array('title'=>$systeminfo['title'],
                        'style'=>$systeminfo['style'],
                        'thumb'=>$systeminfo['thumb'],
                        'keywords'=>$systeminfo['keywords'],
                        'description'=>$systeminfo['description'],
                        'status'=>$systeminfo['status'],
                        'catid'=>$cid,'url'=>$linkurl,
                        'sysadd'=>1,
                        'username'=>$systeminfo['username'],
                        'inputtime'=>$systeminfo['inputtime'],
                        'updatetime'=>$systeminfo['updatetime'],
                        'islink'=>1
                    ),true);
                    $this->table_name = $this->table_name.'_data';
                    $this->insert(array('id'=>$newid));
                    //发布到审核列表中
                    if($data['status']!=99) {
                        $check_data = array(
                            'checkid'=>'c-'.$newid.'-'.$mid,
                            'catid'=>$systeminfo['catid'],
                            'siteid'=>$this->siteid,
                            'title'=>$systeminfo['title'],
                            'username'=>$systeminfo['username'],
                            'inputtime'=>$systeminfo['inputtime'],
                            'status'=>1,
                            );
                        $this->content_check_db->insert($check_data);
                    }
                }
                $hitsid = 'c-'.$mid.'-'.$newid;
                $this->hits_db->insert(array('hitsid'=>$hitsid,'catid'=>$cid,'updatetime'=>SYS_TIME));
            }
        }
        //END 发布到其他栏目
        //更新附件状态
        if(pc_base::load_config('system','attachment_stat')) {
            $this->attachment_db = pc_base::load_model('attachment_model');
            $this->attachment_db->api_update('','c-'.$systeminfo['catid'].'-'.$id,2);
        }
        //生成静态
        if(!$isimport && $data['status']==99) {
            //在添加和修改内容处定义了 INDEX_HTML
            if(defined('INDEX_HTML')) $html->index();
            if(defined('RELATION_HTML')) $html->create_relation_html($catid);
        }
        return $id;
    }
    /**
     * 修改内容
     * 
     * @param $datas
     */
    public function edit_content($data,$id) {
        $model_tablename = $this->model_tablename;
        //前台权限判断
        if(!defined('IN_ADMIN')) {
            $_username = param::get_cookie('_username');
            $us = $this->get_one(array('id'=>$id,'username'=>$_username));
            if(!$us) return false;
        }
        
        $this->search_db = pc_base::load_model('search_model');
                                                    
        require_once CACHE_MODEL_PATH.'content_input.class.php';  
        require_once CACHE_MODEL_PATH.'content_update.class.php';
        $content_input = new content_input($this->modelid);
        $inputinfo = $content_input->get($data);

        $systeminfo = $inputinfo['system'];
        $modelinfo = $inputinfo['model'];
        if($data['inputtime'] && !is_numeric($data['inputtime'])) {
            $systeminfo['inputtime'] = strtotime($data['inputtime']);
        } elseif(!$data['inputtime']) {
            $systeminfo['inputtime'] = SYS_TIME;
        } else {
            $systeminfo['inputtime'] = $data['inputtime'];
        }
        
        if($data['updatetime'] && !is_numeric($data['updatetime'])) {
            $systeminfo['updatetime'] = strtotime($data['updatetime']);
        } elseif(!$data['updatetime']) {
            $systeminfo['updatetime'] = SYS_TIME;
        } else {
            $systeminfo['updatetime'] = $data['updatetime'];
        }
        //自动提取摘要
        if(isset($_POST['add_introduce']) && $systeminfo['description'] == '' && isset($modelinfo['content'])) {
            $content = stripslashes($modelinfo['content']);
            $introcude_length = intval($_POST['introcude_length']);
            $systeminfo['description'] = str_cut(str_replace(array("\r\n","\t",'[page]','[/page]','&ldquo;','&rdquo;','&nbsp;'), '', strip_tags($content)),$introcude_length);
            $inputinfo['system']['description'] = $systeminfo['description'] = addslashes($systeminfo['description']);
        }
        //自动提取缩略图
        if(isset($_POST['auto_thumb']) && $systeminfo['thumb'] == '' && isset($modelinfo['content'])) {
            $content = $content ? $content : stripslashes($modelinfo['content']);
            $auto_thumb_no = intval($_POST['auto_thumb_no'])-1;
            if(preg_match_all("/(src)=([\"|']?)([^ \"'>]+\.(gif|jpg|jpeg|bmp|png))\\2/i", $content, $matches)) {
                $systeminfo['thumb'] = $matches[3][$auto_thumb_no];
            }
        }
        if($data['islink']==1) {
            $systeminfo['url'] = $_POST['linkurl'];
        } else {
            //更新URL地址
            $urls = $this->url->show($id, 0, $systeminfo['catid'], $systeminfo['inputtime'], $data['prefix'],$inputinfo,'edit');
            $systeminfo['url'] = $urls[0];
        }
        //主表
        $this->table_name = $this->db_tablepre.$model_tablename;
        $this->update($systeminfo,array('id'=>$id));

        //附属表
        $this->table_name = $this->table_name.'_data';
        $this->update($modelinfo,array('id'=>$id));
        $this->search_api($id,$inputinfo);
        //调用 update
        $content_update = new content_update($this->modelid,$id);
        $content_update->update($data);
        //更新附件状态
        if(pc_base::load_config('system','attachment_stat')) {
            $this->attachment_db = pc_base::load_model('attachment_model');
            $this->attachment_db->api_update('','c-'.$systeminfo['catid'].'-'.$id,2);
        }
        //更新审核列表
        $this->content_check_db = pc_base::load_model('content_check_model');
        $check_data = array(
            'catid'=>$systeminfo['catid'],
            'siteid'=>$this->siteid,
            'title'=>$systeminfo['title'],
            'status'=>$systeminfo['status'],
            );
        if(!isset($systeminfo['status'])) unset($check_data['status']);
        $this->content_check_db->update($check_data,array('checkid'=>'c-'.$id.'-'.$this->modelid));
        //生成静态
        $html = pc_base::load_app_class('html', 'content');
        if($urls['content_ishtml']) {
            $html->show($urls[1],$urls['data']);
        }
        //在添加和修改内容处定义了 INDEX_HTML
        if(defined('INDEX_HTML')) $html->index();
        if(defined('RELATION_HTML')) $html->create_relation_html($systeminfo['catid']);
        return true;
    }
    
    public function status($ids = array(), $status = 99) {
        $this->content_check_db = pc_base::load_model('content_check_model');
        $this->message_db = pc_base::load_model('message_model');
        $this->set_model($this->modelid);
        if(is_array($ids) && !empty($ids)) {
            foreach($ids as $id) {
                $this->update(array('status'=>$status),array('id'=>$id));
                $del = false;
                $r = $this->get_one(array('id'=>$id));
                if($status==0) {
                //退稿发送短消息、邮件
                    $message = L('reject_message_tips').$r['title']."<BR><a href=\'index.php?m=member&c=content&a=edit&catid={$r[catid]}&id={$r[id]}\'><font color=red>".L('click_edit')."</font></a><br>";
                    if(isset($_POST['reject_c']) && $_POST['reject_c'] != L('reject_msg')) {
                        $message .= $_POST['reject_c'];
                    } elseif(isset($_GET['reject_c']) && $_GET['reject_c'] != L('reject_msg')) {
                        $message .= $_GET['reject_c'];
                    }
                    $this->message_db->add_message($r['username'],'SYSTEM',L('reject_message'),$message);
                } elseif($status==99 && $r['sysadd']) {
                    $this->content_check_db->delete(array('checkid'=>'c-'.$id.'-'.$this->modelid));
                    $del = true;
                }
                if(!$del) $this->content_check_db->update(array('status'=>$status),array('checkid'=>'c-'.$id.'-'.$this->modelid));
            }
        } else {
            $this->update(array('status'=>$status),array('id'=>$ids));
            $del = false;
            $r = $this->get_one(array('id'=>$ids));
            if($status==0) {
                //退稿发送短消息、邮件
                $message = L('reject_message_tips').$r['title']."<BR><a href=\'index.php?m=member&c=content&a=edit&catid={$r[catid]}&id={$r[id]}\'><font color=red>".L('click_edit')."</font></a><br>";
                if(isset($_POST['reject_c']) && $_POST['reject_c'] != L('reject_msg')) {
                    $message .= $_POST['reject_c'];
                } elseif(isset($_GET['reject_c']) && $_GET['reject_c'] != L('reject_msg')) {
                    $message .= $_GET['reject_c'];
                }
                $this->message_db->add_message($r['username'],'SYSTEM',L('reject_message'),$message);
            } elseif($status==99 && $r['sysadd']) {
                $this->content_check_db->delete(array('checkid'=>'c-'.$ids.'-'.$this->modelid));
                $del = true;
            }
            if(!$del) $this->content_check_db->update(array('status'=>$status),array('checkid'=>'c-'.$ids.'-'.$this->modelid));
        }
        return true;
    }
    /**
     * 删除内容
     * @param $id 内容id
     * @param $file 文件路径
     * @param $catid 栏目id
     */
    public function delete_content($id,$file,$catid = 0) {
        //删除主表数据
        $this->delete(array('id'=>$id));
        //删除从表数据
        $this->table_name = $this->table_name.'_data';
        $this->delete(array('id'=>$id));
        //重置默认表
        $this->table_name = $this->db_tablepre.$this->model_tablename;
        //更新栏目统计
        $this->update_category_items($catid,'delete');
    }
    
    
    private function search_api($id = 0, $data = array(), $action = 'update') {
        $type_arr = getcache('search_model_'.$this->siteid,'search');
        $typeid = $type_arr[$this->modelid]['typeid'];
        if($action == 'update') {
            $fulltext_array = getcache('model_field_'.$this->modelid,'model');
            foreach($fulltext_array AS $key=>$value){
                if($value['isfulltext']) {
                    $fulltextcontent .= $data['system'][$key] ? $data['system'][$key] : $data['model'][$key];
                }
            }
            $this->search_db->update_search($typeid ,$id, $fulltextcontent,addslashes($data['system']['title']).' '.addslashes($data['system']['keywords']),$data['system']['inputtime']);
        } elseif($action == 'delete') {
            $this->search_db->delete_search($typeid ,$id);
        }
    }
    /**
     * 获取单篇信息
     * 
     * @param $catid
     * @param $id
     */
    public function get_content($catid,$id) {
        $catid = intval($catid);
        $id = intval($id);
        if(!$catid || !$id) return false;
        $siteids = getcache('category_content','commons');
        $siteid = $siteids[$catid];
        $this->category = getcache('category_content_'.$siteid,'commons');
        if(isset($this->category[$catid]) && $this->category[$catid]['type'] == 0) {
            $modelid = $this->category[$catid]['modelid'];
            $this->set_model($modelid);
            $r = $this->get_one(array('id'=>$id));
            //附属表
            $this->table_name = $this->table_name.'_data';
            $r2 = $this->get_one(array('id'=>$id));
            if($r2) {
                return array_merge($r,$r2);
            } else {
                return $r;
            }
        }
        return true;
    }
    /**
     * 设置catid 所在的模型数据库
     * 
     * @param $catid
     */
    public function set_catid($catid) {
        $catid = intval($catid);
        if(!$catid) return false;
        if(empty($this->category)) {
            $siteids = getcache('category_content','commons');
            $siteid = $siteids[$catid];
            $this->category = getcache('category_content_'.$siteid,'commons');
        }
        if(isset($this->category[$catid]) && $this->category[$catid]['type'] == 0) {
            $modelid = $this->category[$catid]['modelid'];
            $this->set_model($modelid);
        }
    }
    
    private function update_category_items($catid,$action = 'add',$cache = 0) {
        $this->category_db = pc_base::load_model('category_model');
        if($action=='add') {
            $this->category_db->update(array('items'=>'+=1'),array('catid'=>$catid));
        }  else {
            $this->category_db->update(array('items'=>'-=1'),array('catid'=>$catid));
        }
        if($cache) $this->cache_items();
    }
    
    public function cache_items() {
        $datas = $this->category_db->select(array('modelid'=>$this->modelid),'catid,type,items',10000);
        $array = array();
        foreach ($datas as $r) {
            if($r['type']==0) $array[$r['catid']] = $r['items'];
        }
        setcache('category_items_'.$this->modelid, $array,'commons');
    }
}

//content_model.class.php类结束

    //content.php类开始
    defined('IN_PHPCMS') or exit('No permission resources.');
    //模型缓存路径
    define('CACHE_MODEL_PATH',CACHE_PATH.'caches_model'.DIRECTORY_SEPARATOR.'caches_data'.DIRECTORY_SEPARATOR);
    //定义在单独操作内容的时候，同时更新相关栏目页面
    define('RELATION_HTML',true);
    
    pc_base::load_app_class('admin','admin',0);
    
    pc_base::load_sys_class('form','',0);
    pc_base::load_app_func('util');
    pc_base::load_sys_class('format','',0);

    class content extends admin {
        private $db,$priv_db;
        public $siteid,$categorys;
        public function __construct() {            
            parent::__construct();            
            //$this->db = pc_base::load_model('content_model');
            $this->db=new zzcontent_model; //zzcity modi
    
            $this->siteid = $_POST['default_siteid']; //zzcity add
            
            //$this->siteid = $this->get_siteid();            
            $this->categorys = getcache('category_content_'.$this->siteid,'commons');
            //权限判断
            if(isset($_GET['catid']) && $_SESSION['roleid'] != 1 && ROUTE_A !='pass' && strpos(ROUTE_A,'public_')===false) {            
                $catid = intval($_GET['catid']);
                $this->priv_db = pc_base::load_model('category_priv_model');
                $action = $this->categorys[$catid]['type']==0 ? ROUTE_A : 'init';
                $priv_datas = $this->priv_db->get_one(array('catid'=>$catid,'is_admin'=>1,'action'=>$action));
                if(!$priv_datas) zzshowmessage(L('permission_to_operate'),'blank');
            }

        }
        
        public function init() {
            $show_header = $show_dialog  = $show_pc_hash = '';
            if(isset($_GET['catid']) && $_GET['catid'] && $this->categorys[$_GET['catid']]['siteid']==$this->siteid) {
            $catid = $_GET['catid'] = intval($_GET['catid']);
            $category = $this->categorys[$catid];
            $modelid = $category['modelid'];
            $model_arr = getcache('model', 'commons');
            $MODEL = $model_arr[$modelid];
            unset($model_arr);
                $admin_username = param::get_cookie('admin_username');
                //查询当前的工作流
                $setting = string2array($category['setting']);
                $workflowid = $setting['workflowid'];
                $workflows = getcache('workflow_'.$this->siteid,'commons');
                $workflows = $workflows[$workflowid];
                $workflows_setting = string2array($workflows['setting']);
    
                //将有权限的级别放到新数组中
                $admin_privs = array();
                foreach($workflows_setting as $_k=>$_v) {
                    if(empty($_v)) continue;
                    foreach($_v as $_value) {
                        if($_value==$admin_username) $admin_privs[$_k] = $_k;
                    }
                }
                //工作流审核级别
                $workflow_steps = $workflows['steps'];
                $workflow_menu = '';
                $steps = isset($_GET['steps']) ? intval($_GET['steps']) : 0;
                //工作流权限判断
                if($_SESSION['roleid']!=1 && $steps && !in_array($steps,$admin_privs)) zzshowmessage(L('permission_to_operate'));
                $this->db->set_model($modelid);
                if($this->db->table_name==$this->db->db_tablepre) zzshowmessage(L('model_table_not_exists'));;
                $status = $steps ? $steps : 99;
                if(isset($_GET['reject'])) $status = 0;
                $where = 'catid='.$catid.' AND status='.$status;
                //搜索
                
                if(isset($_GET['start_time']) && $_GET['start_time']) {
                    $start_time = strtotime($_GET['start_time']);
                    $where .= " AND `inputtime` > '$start_time'";
                }
                if(isset($_GET['end_time']) && $_GET['end_time']) {
                    $end_time = strtotime($_GET['end_time']);
                    $where .= " AND `inputtime` < '$end_time'";
                }
                if($start_time>$end_time) zzshowmessage(L('starttime_than_endtime'));
                if(isset($_GET['keyword']) && !empty($_GET['keyword'])) {
                    $type_array = array('title','description','username');
                    $searchtype = intval($_GET['searchtype']);
                    if($searchtype < 3) {
                        $searchtype = $type_array[$searchtype];
                        $keyword = strip_tags(trim($_GET['keyword']));
                        $where .= " AND `$searchtype` like '%$keyword%'";
                    } elseif($searchtype==3) {
                        $keyword = intval($_GET['keyword']);
                        $where .= " AND `id`='$keyword'";
                    }
                }
                if(isset($_GET['posids']) && !empty($_GET['posids'])) {
                    $posids = $_GET['posids']==1 ? intval($_GET['posids']) : 0;
                    $where .= " AND `posids` = '$posids'";
                }
                
                $datas = $this->db->listinfo($where,'id desc',$_GET['page']);
                $pages = $this->db->pages;
                $pc_hash = $_SESSION['pc_hash'];
                for($i=1;$i<=$workflow_steps;$i++) {
                    if($_SESSION['roleid']!=1 && !in_array($i,$admin_privs)) continue;
                    $current = $steps==$i ? 'class=on' : '';
                    $r = $this->db->get_one(array('catid'=>$catid,'status'=>$i));
                    $newimg = $r ? '<img src="'.IMG_PATH.'icon/new.png" style="padding-bottom:2px" onclick="window.location.href=\'?m=content&c=content&a=&menuid='.$_GET['menuid'].'&catid='.$catid.'&steps='.$i.'&pc_hash='.$pc_hash.'\'">' : '';
                    $workflow_menu .= '<a href="?m=content&c=content&a=&menuid='.$_GET['menuid'].'&catid='.$catid.'&steps='.$i.'&pc_hash='.$pc_hash.'" '.$current.' ><em>'.L('workflow_'.$i).$newimg.'</em></a><span>|</span>';
                }
                if($workflow_menu) {
                    $current = isset($_GET['reject']) ? 'class=on' : '';
                    $workflow_menu .= '<a href="?m=content&c=content&a=&menuid='.$_GET['menuid'].'&catid='.$catid.'&pc_hash='.$pc_hash.'&reject=1" '.$current.' ><em>'.L('reject').'</em></a><span>|</span>';
                }
            $template = $MODEL['admin_list_template'] ? $MODEL['admin_list_template'] : 'content_list';
            include $this->admin_tpl($template);
            } else {
                include $this->admin_tpl('content_quick');
            }
        }
        public function add() {
            
//            if(isset($_POST['dosubmit']) || isset($_POST['dosubmit_continue'])) {
                define('INDEX_HTML',true);                
                $catid = $_POST['info']['catid'] = intval($_POST['info']['catid']);
                if(trim($_POST['info']['title'])=='') zzshowmessage(L('title_is_empty'));
                $category = $this->categorys[$catid];
                if($category['type']==0) {
                    $modelid = $this->categorys[$catid]['modelid'];
                    
                    $this->db->set_model($modelid);
                    //如果该栏目设置了工作流，那么必须走工作流设定
                    $setting = string2array($category['setting']);
                    $workflowid = $setting['workflowid'];
                    if($workflowid && $_POST['status']!=99) {
                        //如果用户是超级管理员，那么则根据自己的设置来发布
                        $_POST['info']['status'] = $_SESSION['roleid']==1 ? intval($_POST['status']) : 1;
                    } else {
                        $_POST['info']['status'] = 99;
                    }
                    
                    $this->db->add_content($_POST['info']);
                    
//                    if(isset($_POST['dosubmit'])) {
//                        zzshowmessage(L('add_success').L('2s_close'),'blank','','','function set_time() {$("#secondid").html(1);}setTimeout("set_time()", 500);setTimeout("window.close()", 1200);');
//                    } else {
//                        zzshowmessage(L('add_success'),HTTP_REFERER);
//                    }
                } else {
                    //单网页
                    $this->page_db = pc_base::load_model('page_model');
                    $style_font_weight = $_POST['style_font_weight'] ? 'font-weight:'.strip_tags($_POST['style_font_weight']) : '';
                    $_POST['info']['style'] = strip_tags($_POST['style_color']).';'.$style_font_weight;
                    
                    if($_POST['edit']) {
                        $this->page_db->update($_POST['info'],array('catid'=>$catid));
                    } else {
                        $catid = $this->page_db->insert($_POST['info'],1);
                    }
                    $this->page_db->create_html($catid,$_POST['info']);
                    $forward = HTTP_REFERER;
                }
                //zzshowmessage(L('add_success'),$forward);
                
                echo('[ok]');
//            } else {
//                $show_header = $show_dialog = $show_validator = '';
//                //设置cookie 在附件添加处调用
//                param::set_cookie('module', 'content');
//    
//                if(isset($_GET['catid']) && $_GET['catid']) {
//                    $catid = $_GET['catid'] = intval($_GET['catid']);
//                    
//                    param::set_cookie('catid', $catid);
//                    $category = $this->categorys[$catid];
//                    if($category['type']==0) {
//                        $modelid = $category['modelid'];
//                        //取模型ID，依模型ID来生成对应的表单
//                        require CACHE_MODEL_PATH.'content_form.class.php';
//                        $content_form = new content_form($modelid,$catid,$this->categorys);
//                        $forminfos = $content_form->get();
//                        $formValidator = $content_form->formValidator;
//                        $setting = string2array($category['setting']);
//                        $workflowid = $setting['workflowid'];
//                        $workflows = getcache('workflow_'.$this->siteid,'commons');
//                        $workflows = $workflows[$workflowid];
//                        $workflows_setting = string2array($workflows['setting']);
//                        $nocheck_users = $workflows_setting['nocheck_users'];
//                        $admin_username = param::get_cookie('admin_username');
//                        if(!empty($nocheck_users) && in_array($admin_username, $nocheck_users)) {
//                            $priv_status = true;
//                        } else {
//                            $priv_status = false;
//                        }
//                        include $this->admin_tpl('content_add');
//                    } else {
//                        //单网页
//                        $this->page_db = pc_base::load_model('page_model');
//                        
//                        $r = $this->page_db->get_one(array('catid'=>$catid));
//                        
//                        if($r) {
//                            extract($r);
//                            $style_arr = explode(';',$style);
//                            $style_color = $style_arr[0];
//                            $style_font_weight = $style_arr[1] ? substr($style_arr[1],12) : '';
//                        }
//                        include $this->admin_tpl('content_page');
//                    }
//                } else {
//                    include $this->admin_tpl('content_add');
//                }
//                header("Cache-control: private");
//            }
        }
        
        public function edit() {
                //设置cookie 在附件添加处调用
                param::set_cookie('module', 'content');
                if(isset($_POST['dosubmit']) || isset($_POST['dosubmit_continue'])) {
                    define('INDEX_HTML',true);
                $id = $_POST['info']['id'] = intval($_POST['id']);
                    $catid = $_POST['info']['catid'] = intval($_POST['info']['catid']);
                    if(trim($_POST['info']['title'])=='') zzshowmessage(L('title_is_empty'));
                    $modelid = $this->categorys[$catid]['modelid'];
                    $this->db->set_model($modelid);
                    $this->db->edit_content($_POST['info'],$id);
                    if(isset($_POST['dosubmit'])) {
                        zzshowmessage(L('update_success').L('2s_close'),'blank','','','function set_time() {$("#secondid").html(1);}setTimeout("set_time()", 500);setTimeout("window.close()", 1200);');
                    } else {
                        zzshowmessage(L('update_success'),HTTP_REFERER);
                    }
                } else {
                    $show_header = $show_dialog = $show_validator = '';
                    //从数据库获取内容
                    $id = intval($_GET['id']);
                    if(!isset($_GET['catid']) || !$_GET['catid']) zzshowmessage(L('missing_part_parameters'));
                    $catid = $_GET['catid'] = intval($_GET['catid']);
                    
                    $this->model = getcache('model', 'commons');
                    
                    param::set_cookie('catid', $catid);
                    $category = $this->categorys[$catid];
                    $modelid = $category['modelid'];
                    $this->db->table_name = $this->db->db_tablepre.$this->model[$modelid]['tablename'];
                    $r = $this->db->get_one(array('id'=>$id));
                    $this->db->table_name = $this->db->table_name.'_data';
                    $r2 = $this->db->get_one(array('id'=>$id));
                    if(!$r2) zzshowmessage(L('subsidiary_table_datalost'),'blank');
                    $data = array_merge($r,$r2);
                    require CACHE_MODEL_PATH.'content_form.class.php';
                    $content_form = new content_form($modelid,$catid,$this->categorys);
    
                    $forminfos = $content_form->get($data);
                    $formValidator = $content_form->formValidator;
                    include $this->admin_tpl('content_edit');
                }
                header("Cache-control: private");
        }
        /**
         * 删除
         */
        public function delete() {
            if(isset($_GET['dosubmit'])) {
                $catid = intval($_GET['catid']);
                if(!$catid) zzshowmessage(L('missing_part_parameters'));
                $modelid = $this->categorys[$catid]['modelid'];
                $sethtml = $this->categorys[$catid]['sethtml'];
                $siteid = $this->categorys[$catid]['siteid'];
                
                $html_root = pc_base::load_config('system','html_root');
                if($sethtml) $html_root = '';
                
                $setting = string2array($this->categorys[$catid]['setting']);
                $content_ishtml = $setting['content_ishtml']; 
                $this->db->set_model($modelid);
                $this->hits_db = pc_base::load_model('hits_model');
                $this->queue = pc_base::load_model('queue_model');
                if(isset($_GET['ajax_preview'])) {
                    $ids = intval($_GET['id']);
                    $_POST['ids'] = array(0=>$ids);
                }
                if(empty($_POST['ids'])) zzshowmessage(L('you_do_not_check'));
                //附件初始化
                $attachment = pc_base::load_model('attachment_model');
                $this->content_check_db = pc_base::load_model('content_check_model');
                $this->position_data_db = pc_base::load_model('position_data_model');
                $this->search_db = pc_base::load_model('search_model');
            //判断视频模块是否安装 
            if (module_exists('video') && file_exists(PC_PATH.'model'.DIRECTORY_SEPARATOR.'video_content_model.class.php')) {
                $video_content_db = pc_base::load_model('video_content_model');
                $video_install = 1;
            }
                $this->comment = pc_base::load_app_class('comment', 'comment');
                $search_model = getcache('search_model_'.$this->siteid,'search');
                $typeid = $search_model[$modelid]['typeid'];
                $this->url = pc_base::load_app_class('url', 'content');
                
                foreach($_POST['ids'] as $id) {
                    $r = $this->db->get_one(array('id'=>$id));
                    if($content_ishtml && !$r['islink']) {
                        $urls = $this->url->show($id, 0, $r['catid'], $r['inputtime']);
                        $fileurl = $urls[1];
                        if($this->siteid != 1) {
                            $sitelist = getcache('sitelist','commons');
                            $fileurl = $html_root.'/'.$sitelist[$this->siteid]['dirname'].$fileurl;
                        }
                        //删除静态文件，排除htm/html/shtml外的文件
                        $lasttext = strrchr($fileurl,'.');
                        $len = -strlen($lasttext);
                        $path = substr($fileurl,0,$len);
                        $path = ltrim($path,'/');
                        $filelist = glob(PHPCMS_PATH.$path.'*');
                        foreach ($filelist as $delfile) {
                            $lasttext = strrchr($delfile,'.');
                            if(!in_array($lasttext, array('.htm','.html','.shtml'))) continue;
                            @unlink($delfile);
                            //删除发布点队列数据
                            $delfile = str_replace(PHPCMS_PATH, '/', $delfile);
                            $this->queue->add_queue('del',$delfile,$this->siteid);
                        }
                    } else {
                        $fileurl = 0;
                    }
                    //删除内容
                    $this->db->delete_content($id,$fileurl,$catid);
                    //删除统计表数据
                    $this->hits_db->delete(array('hitsid'=>'c-'.$modelid.'-'.$id));
                    //删除附件
                    $attachment->api_delete('c-'.$catid.'-'.$id);
                    //删除审核表数据
                    $this->content_check_db->delete(array('checkid'=>'c-'.$id.'-'.$modelid));
                    //删除推荐位数据
                    $this->position_data_db->delete(array('id'=>$id,'catid'=>$catid,'module'=>'content'));
                    //删除全站搜索中数据
                    $this->search_db->delete_search($typeid,$id);
                //删除视频库与内容对应关系数据
                if ($video_install ==1) {
                    $video_content_db->delete(array('contentid'=>$id, 'modelid'=>$modelid));
                }
                    
                    //删除相关的评论,删除前应该判断是否还存在此模块
                    if(module_exists('comment')){
                        $commentid = id_encode('content_'.$catid, $id, $siteid);
                        $this->comment->del($commentid, $siteid, $id, $catid);
                    }
                    
                }
                //更新栏目统计
                $this->db->cache_items();
                zzshowmessage(L('operation_success'),HTTP_REFERER);
            } else {
                zzshowmessage(L('operation_failure'));
            }
        }
        /**
         * 过审内容
         */
        public function pass() {
            $admin_username = param::get_cookie('admin_username');
            $catid = intval($_GET['catid']);
            
            if(!$catid) zzshowmessage(L('missing_part_parameters'));
            $category = $this->categorys[$catid];
            $setting = string2array($category['setting']);
            $workflowid = $setting['workflowid'];
            //只有存在工作流才需要审核
            if($workflowid) {
                $steps = intval($_GET['steps']);
                //检查当前用户有没有当前工作流的操作权限
                $workflows = getcache('workflow_'.$this->siteid,'commons');
                $workflows = $workflows[$workflowid];
                $workflows_setting = string2array($workflows['setting']);
                //将有权限的级别放到新数组中
                $admin_privs = array();
                foreach($workflows_setting as $_k=>$_v) {
                    if(empty($_v)) continue;
                    foreach($_v as $_value) {
                        if($_value==$admin_username) $admin_privs[$_k] = $_k;
                    }
                }
                if($_SESSION['roleid']!=1 && $steps && !in_array($steps,$admin_privs)) zzshowmessage(L('permission_to_operate'));
                //更改内容状态
                    if(isset($_GET['reject'])) {
                    //退稿
                        $status = 0;
                    } else {
                        //工作流审核级别
                        $workflow_steps = $workflows['steps'];
                        
                        if($workflow_steps>$steps) {
                            $status = $steps+1;
                        } else {
                            $status = 99;
                        }
                    }
                    
                    $modelid = $this->categorys[$catid]['modelid'];
                    $this->db->set_model($modelid);
    
                    //审核通过，检查投稿奖励或扣除积分
                    if ($status==99) {
                        $html = pc_base::load_app_class('html', 'content');
                        $this->url = pc_base::load_app_class('url', 'content');
                        $member_db = pc_base::load_model('member_model');
                        if (isset($_POST['ids']) && !empty($_POST['ids'])) {
                            foreach ($_POST['ids'] as $id) {
                                $content_info = $this->db->get_content($catid,$id);
                                $memberinfo = $member_db->get_one(array('username'=>$content_info['username']), 'userid, username');
                                $flag = $catid.'_'.$id;
                                if($setting['presentpoint']>0) {
                                    pc_base::load_app_class('receipts','pay',0);
                                    receipts::point($setting['presentpoint'],$memberinfo['userid'], $memberinfo['username'], $flag,'selfincome',L('contribute_add_point'),$memberinfo['username']);
                                } else {
                                    pc_base::load_app_class('spend','pay',0);
                                    spend::point($setting['presentpoint'], L('contribute_del_point'), $memberinfo['userid'], $memberinfo['username'], '', '', $flag);
                                }
                                if($setting['content_ishtml'] == '1'){//栏目有静态配置
                                        $urls = $this->url->show($id, 0, $content_info['catid'], $content_info['inputtime'], '',$content_info,'add');
                                        $html->show($urls[1],$urls['data'],0);
                                }
                            }
                        } else if (isset($_GET['id']) && $_GET['id']) {
                            $id = intval($_GET['id']);
                        $content_info = $this->db->get_content($catid,$id);
                            $memberinfo = $member_db->get_one(array('username'=>$content_info['username']), 'userid, username');
                            $flag = $catid.'_'.$id;
                            if($setting['presentpoint']>0) {
                                pc_base::load_app_class('receipts','pay',0);
                                receipts::point($setting['presentpoint'],$memberinfo['userid'], $memberinfo['username'], $flag,'selfincome',L('contribute_add_point'),$memberinfo['username']);
                            } else {
                                pc_base::load_app_class('spend','pay',0);
                                spend::point($setting['presentpoint'], L('contribute_del_point'), $memberinfo['userid'], $memberinfo['username'], '', '', $flag);
                            }
                        //单篇审核，生成静态
                        if($setting['content_ishtml'] == '1'){//栏目有静态配置
                        $urls = $this->url->show($id, 0, $content_info['catid'], $content_info['inputtime'], '',$content_info,'add');
                        $html->show($urls[1],$urls['data'],0);
                        }
                    }
                }
                    if(isset($_GET['ajax_preview'])) {
                        $_POST['ids'] = $_GET['id'];
                    }
                    $this->db->status($_POST['ids'],$status);
            }
            zzshowmessage(L('operation_success'),HTTP_REFERER);
        }
        /**
         * 排序
         */
        public function listorder() {
            if(isset($_GET['dosubmit'])) {
                $catid = intval($_GET['catid']);
                if(!$catid) zzshowmessage(L('missing_part_parameters'));
                $modelid = $this->categorys[$catid]['modelid'];
                $this->db->set_model($modelid);
                foreach($_POST['listorders'] as $id => $listorder) {
                    $this->db->update(array('listorder'=>$listorder),array('id'=>$id));
                }
                zzshowmessage(L('operation_success'));
            } else {
                zzshowmessage(L('operation_failure'));
            }
        }
        /**
         * 显示栏目菜单列表
         */
        public function public_categorys() {
            $show_header = '';
            $cfg = getcache('common','commons');
            $ajax_show = intval($cfg['category_ajax']);
            $from = isset($_GET['from']) && in_array($_GET['from'],array('block')) ? $_GET['from'] : 'content';
            $tree = pc_base::load_sys_class('tree');
            if($from=='content' && $_SESSION['roleid'] != 1) {    
                $this->priv_db = pc_base::load_model('category_priv_model');
                $priv_result = $this->priv_db->select(array('action'=>'init','roleid'=>$_SESSION['roleid'],'siteid'=>$this->siteid,'is_admin'=>1));
                $priv_catids = array();
                foreach($priv_result as $_v) {
                    $priv_catids[] = $_v['catid'];
                }
                if(empty($priv_catids)) return '';
            }
            $categorys = array();
            if(!empty($this->categorys)) {
                foreach($this->categorys as $r) {
                    if($r['siteid']!=$this->siteid ||  ($r['type']==2 && $r['child']==0)) continue;
                    if($from=='content' && $_SESSION['roleid'] != 1 && !in_array($r['catid'],$priv_catids)) {
                        $arrchildid = explode(',',$r['arrchildid']);
                        $array_intersect = array_intersect($priv_catids,$arrchildid);
                        if(empty($array_intersect)) continue;
                    }
                    if($r['type']==1 || $from=='block') {
                        if($r['type']==0) {
                            $r['vs_show'] = "<a href='?m=block&c=block_admin&a=public_visualization&menuid=".$_GET['menuid']."&catid=".$r['catid']."&type=show' target='right'>[".L('content_page')."]</a>";
                        } else {
                            $r['vs_show'] ='';
                        }
                        $r['icon_type'] = 'file';
                        $r['add_icon'] = '';
                        $r['type'] = 'add';
                    } else {
                        $r['icon_type'] = $r['vs_show'] = '';
                        $r['type'] = 'init';
                        $r['add_icon'] = "<a target='right' href='?m=content&c=content&menuid=".$_GET['menuid']."&catid=".$r['catid']."' onclick=javascript:openwinx('?m=content&c=content&a=add&menuid=".$_GET['menuid']."&catid=".$r['catid']."&hash_page=".$_SESSION['hash_page']."','')><img src='".IMG_PATH."add_content.gif' alt='".L('add')."'></a> ";
                    }
                    $categorys[$r['catid']] = $r;
                }
            }
            if(!empty($categorys)) {
                $tree->init($categorys);
                    switch($from) {
                        case 'block':
                            $strs = "<span class='\$icon_type'>\$add_icon<a href='?m=block&c=block_admin&a=public_visualization&menuid=".$_GET['menuid']."&catid=\$catid&type=list' target='right'>\$catname</a> \$vs_show</span>";
                            $strs2 = "<img src='".IMG_PATH."folder.gif'> <a href='?m=block&c=block_admin&a=public_visualization&menuid=".$_GET['menuid']."&catid=\$catid&type=category' target='right'>\$catname</a>";
                        break;
    
                        default:
                            $strs = "<span class='\$icon_type'>\$add_icon<a href='?m=content&c=content&a=\$type&menuid=".$_GET['menuid']."&catid=\$catid' target='right' onclick='open_list(this)'>\$catname</a></span>";
                            $strs2 = "<span class='folder'>\$catname</span>";
                            break;
                    }
                $categorys = $tree->get_treeview(0,'category_tree',$strs,$strs2,$ajax_show);
            } else {
                $categorys = L('please_add_category');
            }
                    include $this->admin_tpl('category_tree');
            exit;
        }
        /**
         * 检查标题是否存在
         */
        public function public_check_title() {
            if($_GET['data']=='' || (!$_GET['catid'])) return '';
            $catid = intval($_GET['catid']);
            $modelid = $this->categorys[$catid]['modelid'];
            $this->db->set_model($modelid);
            $title = $_GET['data'];
            if(CHARSET=='gbk') $title = iconv('utf-8','gbk',$title);
            $r = $this->db->get_one(array('title'=>$title));
            if($r) {
                exit('1');
            } else {
                exit('0');
            }
        }
        
        /**
         * 图片裁切
         */
        public function public_crop() {
            if (isset($_GET['picurl']) && !empty($_GET['picurl'])) {
                $picurl = $_GET['picurl'];
                $catid = intval($_GET['catid']);
                if (isset($_GET['module']) && !empty($_GET['module'])) {
                    $module = $_GET['module'];
                }
                $show_header =  '';
                include $this->admin_tpl('crop');
            }
        }
        /**
         * 相关文章选择
         */
        public function public_relationlist() {
            pc_base::load_sys_class('format','',0);
            $show_header = '';
            $model_cache = getcache('model','commons');
            if(!isset($_GET['modelid'])) {
                zzshowmessage(L('please_select_modelid'));
            } else {
                $page = intval($_GET['page']);
                
                $modelid = intval($_GET['modelid']);
                $this->db->set_model($modelid);
                $where = '';
                if($_GET['catid']) {
                    $catid = intval($_GET['catid']);
                    $where .= "catid='$catid'";
                }
                $where .= $where ?  ' AND status=99' : 'status=99';
                
                if(isset($_GET['keywords'])) {
                    $keywords = trim($_GET['keywords']);
                    $field = $_GET['field'];
                    if(in_array($field, array('id','title','keywords','description'))) {
                        if($field=='id') {
                            $where .= " AND `id` ='$keywords'";
                        } else {
                            $where .= " AND `$field` like '%$keywords%'";
                        }
                    }
                }
                $infos = $this->db->listinfo($where,'',$page,12);
                $pages = $this->db->pages;
                include $this->admin_tpl('relationlist');
            }
        }
        public function public_getjson_ids() {
            $modelid = intval($_GET['modelid']);
            $id = intval($_GET['id']);
            $this->db->set_model($modelid);
            $tablename = $this->db->table_name;
            $this->db->table_name = $tablename.'_data';
            $r = $this->db->get_one(array('id'=>$id),'relation');
    
            if($r['relation']) {
                $relation = str_replace('|', ',', $r['relation']);
                $relation = trim($relation,',');
                $where = "id IN($relation)";
                $infos = array();
                $this->db->table_name = $tablename;
                $datas = $this->db->select($where,'id,title');
                foreach($datas as $_v) {
                    $_v['sid'] = 'v'.$_v['id'];
                    if(strtolower(CHARSET)=='gbk') $_v['title'] = iconv('gbk', 'utf-8', $_v['title']);
                    $infos[] = $_v;
                }
                echo json_encode($infos);
            }
        }
    
        //文章预览
        public function public_preview() {
            $catid = intval($_GET['catid']);
            $id = intval($_GET['id']);
            
            if(!$catid || !$id) zzshowmessage(L('missing_part_parameters'),'blank');
            $page = intval($_GET['page']);
            $page = max($page,1);
            $CATEGORYS = getcache('category_content_'.$this->get_siteid(),'commons');
            
            if(!isset($CATEGORYS[$catid]) || $CATEGORYS[$catid]['type']!=0) zzshowmessage(L('missing_part_parameters'),'blank');
            define('HTML', true);
            $CAT = $CATEGORYS[$catid];
            
            $siteid = $CAT['siteid'];
            $MODEL = getcache('model','commons');
            $modelid = $CAT['modelid'];
    
            $this->db->table_name = $this->db->db_tablepre.$MODEL[$modelid]['tablename'];
            $r = $this->db->get_one(array('id'=>$id));
            if(!$r) zzshowmessage(L('information_does_not_exist'));
            $this->db->table_name = $this->db->table_name.'_data';
            $r2 = $this->db->get_one(array('id'=>$id));
            $rs = $r2 ? array_merge($r,$r2) : $r;
    
            //再次重新赋值，以数据库为准
            $catid = $CATEGORYS[$r['catid']]['catid'];
            $modelid = $CATEGORYS[$catid]['modelid'];
            
            require_once CACHE_MODEL_PATH.'content_output.class.php';
            $content_output = new content_output($modelid,$catid,$CATEGORYS);
            $data = $content_output->get($rs);
            extract($data);
            $CAT['setting'] = string2array($CAT['setting']);
            $template = $template ? $template : $CAT['setting']['show_template'];
            $allow_visitor = 1;
            //SEO
            $SEO = seo($siteid, $catid, $title, $description);
            
            define('STYLE',$CAT['setting']['template_list']);
            if(isset($rs['paginationtype'])) {
                $paginationtype = $rs['paginationtype'];
                $maxcharperpage = $rs['maxcharperpage'];
            }
            $pages = $titles = '';
            if($rs['paginationtype']==1) {
                //自动分页
                if($maxcharperpage < 10) $maxcharperpage = 500;
                $contentpage = pc_base::load_app_class('contentpage');
                $content = $contentpage->get_data($content,$maxcharperpage);
            }
            if($rs['paginationtype']!=0) {
                //手动分页
                $CONTENT_POS = strpos($content, '[page]');
                if($CONTENT_POS !== false) {
                    $this->url = pc_base::load_app_class('url', 'content');
                    $contents = array_filter(explode('[page]', $content));
                    $pagenumber = count($contents);
                    for($i=1; $i<=$pagenumber; $i++) {
                        $pageurls[$i] = $this->url->show($id, $i, $catid, $rs['inputtime']);
                    }
                    $END_POS = strpos($content, '[/page]');
                    if($END_POS !== false) {
                        if(preg_match_all("|\[page\](.*)\[/page\]|U", $content, $m, PREG_PATTERN_ORDER)) {
                            foreach($m[1] as $k=>$v) {
                                $p = $k+1;
                                $titles[$p]['title'] = strip_tags($v);
                                $titles[$p]['url'] = $pageurls[$p][0];
                            }
                        }
                    } else {
                        //当不存在 [/page]时，则使用下面分页
                        $pages = content_pages($pagenumber,$page, $pageurls);
                    }
                    //判断[page]出现的位置是否在第一位 
                    if($CONTENT_POS<7) {
                        $content = $contents[$page];
                    } else {
                        $content = $contents[$page-1];
                    }
                    if($titles) {
                        list($title, $content) = explode('[/page]', $content);
                        $content = trim($content);
                        if(strpos($content,'</p>')===0) {
                            $content = '<p>'.$content;
                        }
                        if(stripos($content,'<p>')===0) {
                            $content = $content.'</p>';
                        }
                    }
                }
            }
            include template('content',$template);
            $pc_hash = $_SESSION['pc_hash'];
            $steps = intval($_GET['steps']);
            echo "
            <link href=\"".CSS_PATH."dialog_simp.css\" rel=\"stylesheet\" type=\"text/css\" />
            <script language=\"javascript\" type=\"text/javascript\" src=\"".JS_PATH."dialog.js\"></script>
            <script type=\"text/javascript\">art.dialog({lock:false,title:'".L('operations_manage')."',mouse:true, id:'content_m', content:'<span id=cloading ><a href=\'javascript:ajax_manage(1)\'>".L('passed_checked')."</a> | <a href=\'javascript:ajax_manage(2)\'>".L('reject')."</a> |　<a href=\'javascript:ajax_manage(3)\'>".L('delete')."</a></span>',left:'100%',top:'100%',width:200,height:50,drag:true, fixed:true});
            function ajax_manage(type) {
                if(type==1) {
                    $.get('?m=content&c=content&a=pass&ajax_preview=1&catid=".$catid."&steps=".$steps."&id=".$id."&pc_hash=".$pc_hash."');
                } else if(type==2) {
                    $.get('?m=content&c=content&a=pass&ajax_preview=1&reject=1&catid=".$catid."&steps=".$steps."&id=".$id."&pc_hash=".$pc_hash."');
                } else if(type==3) {
                    $.get('?m=content&c=content&a=delete&ajax_preview=1&dosubmit=1&catid=".$catid."&steps=".$steps."&id=".$id."&pc_hash=".$pc_hash."');
                }
                $('#cloading').html('<font color=red>".L('operation_success')."<span id=\"secondid\">2</span>".L('after_a_few_seconds_left')."</font>');
                setInterval('set_time()', 1000);
                setInterval('window.close()', 2000);
            }
            function set_time() {
                $('#secondid').html(1);
            }
            </script>";
        }
    
        /**
         * 审核所有内容
         */
        public function public_checkall() {
            $page = isset($_GET['page']) && intval($_GET['page']) ? intval($_GET['page']) : 1;
            
            $show_header = '';
            $workflows = getcache('workflow_'.$this->siteid,'commons');
            $datas = array();
            $pagesize = 20;
            $sql = '';
            if (in_array($_SESSION['roleid'], array('1'))) {
                $super_admin = 1;
                $status = isset($_GET['status']) ? $_GET['status'] : -1;
            } else {
                $super_admin = 0;
                $status = isset($_GET['status']) ? $_GET['status'] : 1;
                if($status==-1) $status = 1;
            }
            if($status>4) $status = 4;
            $this->priv_db = pc_base::load_model('category_priv_model');;
            $admin_username = param::get_cookie('admin_username');
            if($status==-1) {
                $sql = "`status` NOT IN (99,0,-2) AND `siteid`=$this->siteid";
            } else {
                $sql = "`status` = '$status' AND `siteid`=$this->siteid";
            }
            if($status!=0 && !$super_admin) {
                //以栏目进行循环
                foreach ($this->categorys as $catid => $cat) {
                    if($cat['type']!=0) continue;
                    //查看管理员是否有这个栏目的查看权限。
                    if (!$this->priv_db->get_one(array('catid'=>$catid, 'siteid'=>$this->siteid, 'roleid'=>$_SESSION['roleid'], 'is_admin'=>'1'))) {
                        continue;
                    }
                    //如果栏目有设置工作流，进行权限检查。
                    $workflow = array();
                    $cat['setting'] = string2array($cat['setting']);
                    if (isset($cat['setting']['workflowid']) && !empty($cat['setting']['workflowid'])) {
                        $workflow = $workflows[$cat['setting']['workflowid']];
                        $workflow['setting'] = string2array($workflow['setting']);
                        $usernames = $workflow['setting'][$status];
                        if (empty($usernames) || !in_array($admin_username, $usernames)) {//判断当前管理，在工作流中可以审核几审
                            continue;
                        }
                    }
                    $priv_catid[] = $catid;
                }
                if(empty($priv_catid)) {
                    $sql .= " AND catid = -1";
                } else {
                    $priv_catid = implode(',', $priv_catid);
                    $sql .= " AND catid IN ($priv_catid)";
                }
            }
            $this->content_check_db = pc_base::load_model('content_check_model');
            $datas = $this->content_check_db->listinfo($sql,'inputtime DESC',$page);        
            $pages = $this->content_check_db->pages;
            include $this->admin_tpl('content_checkall');
        }
        
        /**
         * 批量移动文章
         */
        public function remove() {
            if(isset($_POST['dosubmit'])) {
                $this->content_check_db = pc_base::load_model('content_check_model');
                if($_POST['fromtype']==0) {
                    if($_POST['ids']=='') zzshowmessage(L('please_input_move_source'));
                    if(!$_POST['tocatid']) zzshowmessage(L('please_select_target_category'));
                    $tocatid = intval($_POST['tocatid']);
                    $modelid = $this->categorys[$tocatid]['modelid'];
                    if(!$modelid) zzshowmessage(L('illegal_operation'));
                    $ids = array_filter(explode(',', $_POST['ids']),"intval");
                    foreach ($ids as $id) {
                        $checkid = 'c-'.$id.'-'.$this->siteid;
                        $this->content_check_db->update(array('catid'=>$tocatid), array('checkid'=>$checkid));
                    }
                    $ids = implode(',', $ids);
                    $this->db->set_model($modelid);
                    $this->db->update(array('catid'=>$tocatid),"id IN($ids)");
                } else {
                    if(!$_POST['fromid']) zzshowmessage(L('please_input_move_source'));
                    if(!$_POST['tocatid']) zzshowmessage(L('please_select_target_category'));
                    $tocatid = intval($_POST['tocatid']);
                    $modelid = $this->categorys[$tocatid]['modelid'];
                    if(!$modelid) zzshowmessage(L('illegal_operation'));
                    $fromid = array_filter($_POST['fromid'],"intval");
                    $fromid = implode(',', $fromid);
                    $this->db->set_model($modelid);
                    $this->db->update(array('catid'=>$tocatid),"catid IN($fromid)");
                }
                zzshowmessage(L('operation_success'),HTTP_REFERER);
                //ids
            } else {
                $show_header = '';
                $catid = intval($_GET['catid']);
                $modelid = $this->categorys[$catid]['modelid'];
                $tree = pc_base::load_sys_class('tree');
                $tree->icon = array('&nbsp;&nbsp;│ ','&nbsp;&nbsp;├─ ','&nbsp;&nbsp;└─ ');
                $tree->nbsp = '&nbsp;&nbsp;';
                $categorys = array();
                foreach($this->categorys as $cid=>$r) {
                    if($this->siteid != $r['siteid'] || $r['type']) continue;
                    if($modelid && $modelid != $r['modelid']) continue;
                    $r['disabled'] = $r['child'] ? 'disabled' : '';
                    $r['selected'] = $cid == $catid ? 'selected' : '';
                    $categorys[$cid] = $r;
                }
                $str  = "<option value='\$catid' \$selected \$disabled>\$spacer \$catname</option>";
    
                $tree->init($categorys);
                $string .= $tree->get_tree(0, $str);
                $str  = "<option value='\$catid'>\$spacer \$catname</option>";
                $source_string = '';
                $tree->init($categorys);
                $source_string .= $tree->get_tree(0, $str);
                $ids = empty($_POST['ids']) ? '' : implode(',',$_POST['ids']);
                include $this->admin_tpl('content_remove');
            }
        }
        
        /**
         * 同时发布到其他栏目
         */
        public function add_othors() {
            $show_header = '';
            $sitelist = getcache('sitelist','commons');
            $siteid = $_GET['siteid'];
            include $this->admin_tpl('add_othors');
            
        }
        /**
         * 同时发布到其他栏目 异步加载栏目
         */
        public function public_getsite_categorys() {
            $siteid = intval($_GET['siteid']);
            $this->categorys = getcache('category_content_'.$siteid,'commons');
            $models = getcache('model','commons');
            $tree = pc_base::load_sys_class('tree');
            $tree->icon = array('&nbsp;&nbsp;&nbsp;│ ','&nbsp;&nbsp;&nbsp;├─ ','&nbsp;&nbsp;&nbsp;└─ ');
            $tree->nbsp = '&nbsp;&nbsp;&nbsp;';
            $categorys = array();
            if($_SESSION['roleid'] != 1) {
                $this->priv_db = pc_base::load_model('category_priv_model');
                $priv_result = $this->priv_db->select(array('action'=>'add','roleid'=>$_SESSION['roleid'],'siteid'=>$siteid,'is_admin'=>1));
                $priv_catids = array();
                foreach($priv_result as $_v) {
                    $priv_catids[] = $_v['catid'];
                }
                if(empty($priv_catids)) return '';
            }
            
            foreach($this->categorys as $r) {
                if($r['siteid']!=$siteid || $r['type']!=0) continue;
                if($_SESSION['roleid'] != 1 && !in_array($r['catid'],$priv_catids)) {
                    $arrchildid = explode(',',$r['arrchildid']);
                    $array_intersect = array_intersect($priv_catids,$arrchildid);
                    if(empty($array_intersect)) continue;
                }
                $r['modelname'] = $models[$r['modelid']]['name'];
                $r['style'] = $r['child'] ? 'color:#8A8A8A;' : '';
                $r['click'] = $r['child'] ? '' : "onclick=\"select_list(this,'".safe_replace($r['catname'])."',".$r['catid'].")\" class='cu' title='".L('click_to_select')."'";
                $categorys[$r['catid']] = $r;
            }
            $str  = "<tr \$click >
                        <td align='center'>\$id</td>
                        <td style='\$style'>\$spacer\$catname</td>
                        <td align='center'>\$modelname</td>
                    </tr>";
            $tree->init($categorys);
            $categorys = $tree->get_tree(0, $str);
            echo $categorys;
        }
        
        public function public_sub_categorys() {
            $cfg = getcache('common','commons');
            $ajax_show = intval(abs($cfg['category_ajax']));    
            $catid = intval($_POST['root']);
            $modelid = intval($_POST['modelid']);
            $this->categorys = getcache('category_content_'.$this->siteid,'commons');
            $tree = pc_base::load_sys_class('tree');
            if(!empty($this->categorys)) {
                foreach($this->categorys as $r) {
                    if($r['siteid']!=$this->siteid ||  ($r['type']==2 && $r['child']==0)) continue;
                    if($from=='content' && $_SESSION['roleid'] != 1 && !in_array($r['catid'],$priv_catids)) {
                        $arrchildid = explode(',',$r['arrchildid']);
                        $array_intersect = array_intersect($priv_catids,$arrchildid);
                        if(empty($array_intersect)) continue;
                    }
                    if($r['type']==1 || $from=='block') {
                        if($r['type']==0) {
                            $r['vs_show'] = "<a href='?m=block&c=block_admin&a=public_visualization&menuid=".$_GET['menuid']."&catid=".$r['catid']."&type=show' target='right'>[".L('content_page')."]</a>";
                        } else {
                            $r['vs_show'] ='';
                        }
                        $r['icon_type'] = 'file';
                        $r['add_icon'] = '';
                        $r['type'] = 'add';
                    } else {
                        $r['icon_type'] = $r['vs_show'] = '';
                        $r['type'] = 'init';
                        $r['add_icon'] = "<a target='right' href='?m=content&c=content&menuid=".$_GET['menuid']."&catid=".$r['catid']."' onclick=javascript:openwinx('?m=content&c=content&a=add&menuid=".$_GET['menuid']."&catid=".$r['catid']."&hash_page=".$_SESSION['hash_page']."','')><img src='".IMG_PATH."add_content.gif' alt='".L('add')."'></a> ";
                    }
                    $categorys[$r['catid']] = $r;
                }
            }
            if(!empty($categorys)) {
                $tree->init($categorys);
                    switch($from) {
                        case 'block':
                            $strs = "<span class='\$icon_type'>\$add_icon<a href='?m=block&c=block_admin&a=public_visualization&menuid=".$_GET['menuid']."&catid=\$catid&type=list&pc_hash=".$_SESSION['pc_hash']."' target='right'>\$catname</a> \$vs_show</span>";
                        break;
    
                        default:
                            $strs = "<span class='\$icon_type'>\$add_icon<a href='?m=content&c=content&a=\$type&menuid=".$_GET['menuid']."&catid=\$catid&pc_hash=".$_SESSION['pc_hash']."' target='right' onclick='open_list(this)'>\$catname</a></span>";
                            break;
                    }
                $data = $tree->creat_sub_json($catid,$strs);
            }        
            echo $data;
        }
    }

    //contetn.php类结束

zzlogin(); //zzcity 登陆
$_SESSION['roleid']=1;
$myclassname=ROUTE_C;
//$filepath=PC_PATH.'modules'.DIRECTORY_SEPARATOR.ROUTE_M.DIRECTORY_SEPARATOR.$myclassname.'.php';
//include_once $filepath;
$controller=new $myclassname;

call_user_func(array($controller, ROUTE_A));
//zzcity 替代结束
?>