function load($path,$module='phpcms',$dir='',$isint=1){ global $MODULE; if(!isset($MODULE[$module]))return false; $path = PHPCMS_ROOT.$MODULE[$module]['path'].($dir?$dir.'/':'include/').$file; if(!(@include_once $path))return false; if($isint && strpos($file,'.class.php')!==false) { $classname = substr($file,0,-10); if(is_object($classname)){ return true; }else{ return new $classname(); } } return true; } function cache_common(){ global $db; $data = array(); $result = $db->query("SELECT module,name,path,url,iscore,version FROM ".DB_PRE."module WHERE); while($r = $db->fetch_array($result)){ if(!$r['path'])$r['path'] = $r['module'] == 'scms'?'':$r['module'].'/'; if(!$r['url'])$r['url'] == $r['module'] == 'scms'?'':$r['module'].'/'; $data[$r['module']] = $r; } $db->free_result($result); $CACHE['MODULE'] = $data; //然后是用相同的方法获取数据 还有$CACHE['CATEGORY'] = $data; CACHE['URLRULE'] ,全局变量CACHE['PHPCMS']; cache_write('common.php', $CACHE); //缓存都写入这个文件 例如网站信息啊 ,系统设置啊等等。 return $CACHE; } function module_setting($module, $setting) { global $db,$MODULE; if(!is_array($setting) || !array_key_exists($module, $MODULE)) return FALSE; if(isset($setting['url'])) { $url = $setting['url']; if($setting['url'] && substr($url, -1) != '/') { $url .= '/'; } $db->query("UPDATE ".DB_PRE."module SET url='$url' WHERE module='$module'"); unset($setting['url']); } $setting = new_stripslashes($setting); $setting = addslashes(var_export($setting, TRUE)); $db->query("UPDATE ".DB_PRE."module SET setting='$setting' WHERE module='$module'"); cache_module(); //在cache_func.php cache_common(); //在cache_func.php return TRUE; } 写入缓存 funciton cache_write($file,$array,$path=''){ if(!is_array($array))return false; $array = "<?php/nreturn> ".var_export($array,true).";/n?>"; $cachefile = ($path?$path:CACHE_PATH).$file; $strlen = file_put_contents($cachefile,$array); @chmod($cachefile,0777); return $strlen; } 读取缓存函数 获取栏目子菜单 function subcat($module='phpcms',$parent=null,$type=null){ global $CATEGORY; $subcat = array(); foreach($CATEGORY as $id=>$cat){ if($cat['module'] == $module && ($parentid == NULL || $cat['parentid'] == $parentid) && ($type == NULL || $cat['type'] == $type))$subcat[$id] = $cat; } return $subcat; } function submodelcat($modelid = 1, $parentid = NULL, $type = NULL) { global $CATEGORY; $subcat = array(); foreach($CATEGORY as $id=>$cat) { if($cat['modelid'] == $modelid && ($parentid === NULL || $cat['parentid'] == $parentid) && $cat['parentid'] !=0 && ($type === NULL || $cat['type'] == $type)) $subcat[$id] = $cat; } return $subcat; } 读取缓存函数 function cache_read($file, $path = '', $iscachevar = 0) { if(!$path) $path = CACHE_PATH; $cachefile = $path.$file; if($iscachevar) { global $TEMP; $key = 'cache_'.substr($file, 0, -4); return isset($TEMP[$key]) ? $TEMP[$key] : $TEMP[$key] = @include $cachefile; } return @include $cachefile; }