cache.func.php

Jun 23, 2016 pm 02:34 PM

function cache_all()
{
@set_time_limit(600);
cache_common();
cache_module();
cache_model();
cache_category();
cache_area();
cache_type();
cache_member_group();
cache_role();
cache_author();
cache_keyword();
cache_copyfrom();
cache_pos();
cache_status();
cache_workflow();
tags_update();
return TRUE;
}
function cache_common()
{
global $db;
$data = array();
$result = $db->query("SELECT `module`,`name`,`path`,`url`,`iscore`,`version` FROM `".DB_PRE."module` WHERE `disabled`=0");
//取出模块表中的基本数据,module 为module的英文名,name为中文名,path为它的所在目录,url和path数据一样子,也是表示目录,iscore判断是否为内置核心模块,version为版本号
while($r = $db->fetch_array($result))
{
if(!$r['path']) $r['path'] = $r['module'] == 'phpcms' ? '' : $r['module'].'/'; //设置模块当没有指定路径时,指向phpcms
if(!$r['url']) $r['url'] = $r['module'] == 'phpcms' ? '' : $r['module'].'/'; // //设置模块当没有指定路径时,指向url
$data[$r['module']] = $r;//value=array $r
}
$db->free_result($result);
$CACHE['MODULE'] = $data; //给值给cahe的module变量,值包含path,url此外应该为 所有模块 path/url
$data = array();
$result = $db->query("SELECT * FROM `".DB_PRE."model` WHERE `disabled`=0"); //加载内容模版`disabled`=0", 意思为没有设置关闭的 model表如下
//No. 字段 类型 Null Key 默认值|说明
//1 modelid tinyint(3) unsigned NO PRI | 模型ID auto_increment
//2 name varchar(30) NO | 模型名称
//3 description varchar(255) NO | 描述
//4 tablename varchar(20) NO | 保存表名
//5 itemname varchar(10) NO | 项目名称
//6 itemunit varchar(10) NO | 项目单位
//7 workflowid tinyint(3) unsigned NO 0 | 工作流方案
//8 template_category varchar(30) NO | 栏目首页模板
//9 template_list varchar(30) NO | 栏目列表页模板
//10 template_show varchar(30) NO | 内容页模板
//11 template_print varchar(30) NO | 打印页模板
//12 ishtml tinyint(1) unsigned NO 0 | 是否生成html
//13 category_urlruleid tinyint(1) unsigned NO 0 | 栏目URL规则
//14 show_urlruleid tinyint(1) unsigned NO 0 | 内容页URL规则
//15 enablesearch tinyint(1) unsigned NO 1 |
//16 ischeck tinyint(1) unsigned NO 1 |
//17 isrelated tinyint(1) unsigned NO 1 |
//18 disabled tinyint(1) unsigned NO 0 | 禁用
//19 modeltype tinyint(1) unsigned NO 0 | 类型
while($r = $db->fetch_array($result))
{
$data[$r['modelid']] = $r; //取所有的model_Id
}
$db->free_result($result);
$CACHE['MODEL'] = $data; //给cache变量
$data = array();
$result = $db->query("SELECT `catid`,`module`,`type`,`modelid`,`catname`,`style`,`image`,`catdir`,`url`,`parentid`,`arrparentid`,`parentdir`,`child`,`arrchildid`,`items`,`ismenu` FROM `".DB_PRE."category` WHERE 1 ORDER BY `listorder`,`catid`");
//自己可以在机器上,跑一下如上sql语句,结果是
//cartoary 表结构 字段 类型 Null Key 默认值|说明
//1 catid smallint(5) unsigned NO PRI | 栏目ID auto_increment
//2 module varchar(15) NO MUL | 模块
//3 type tinyint(1) unsigned NO 0 | 栏目类型
//4 modelid tinyint(3) unsigned NO 0 | 模型ID
//5 parentid smallint(5) unsigned NO 0 | 上级栏目ID
//6 arrparentid varchar(255) NO | 所有上级栏目ID
//7 child tinyint(1) unsigned NO 0 | 是否有子栏目
//8 arrchildid mediumtext NO | 所有子栏目ID
//9 catname varchar(30) NO | 栏目名称
//10 style varchar(5) NO | 样式
//11 image varchar(100) NO | 栏目图片
//12 description mediumtext NO | 描述
//13 parentdir varchar(100) NO | 父目录
//14 catdir varchar(30) NO | 栏目目录
//15 url varchar(100) NO | 链接
//16 content mediumtext NO | 单网页内容
//17 items mediumint(8) unsigned NO 0 | 信息数
//18 hits int(10) unsigned NO 0 | 点击数
//19 setting mediumtext NO | 设置
//20 listorder smallint(5) unsigned NO 0 | 排序
//21 ismenu tinyint(1) unsigned NO 1 | 在导航显示
//也就是生成了目录树
while($r = $db->fetch_array($result))
{
$r['url'] = url($r['url']); // url varchar(100) NO | 链接 如生成后,显示为 /module_目录/index.html
$data[$r['catid']] = $r; //目录id,这些在形成首页head里的那个导行非常有用,我测试了下就是从这里调用的数据,如果导航数据有错,可以调整这里
}
$db->free_result($result);
$CACHE['CATEGORY'] = $data; //给cache变量,方便以后调用
$data = array();
$result = $db->query("SELECT `typeid`,`module`,`name`,`style`,`typedir`,`url` FROM `".DB_PRE."type` WHERE 1 ORDER BY `listorder`,`typeid`");
// 1 link 默认分类
// 2 error_report 错字
// 3 error_report 无效URL
// 0 好像为内部栏目类别
while($r = $db->fetch_array($result))
{
$data[$r['typeid']] = $r;
}
$db->free_result($result);
$CACHE['TYPE'] = $data;
$data = array();
$result = $db->query("SELECT `areaid`,`name`,`style`,`parentid`,`arrparentid`,`child`,`arrchildid` FROM `".DB_PRE."area` WHERE 1 ORDER BY `listorder`,`areaid`");
//生成位置数组
while($r = $db->fetch_array($result))
{
$data[$r['areaid']] = $r;
}
$db->free_result($result);
$CACHE['AREA'] = $data;
$data = array();
$result = $db->query("SELECT `urlruleid`,`urlrule` FROM `".DB_PRE."urlrule` WHERE 1 ORDER BY `urlruleid`");
while($r = $db->fetch_array($result))
{
$data[$r['urlruleid']] = $r['urlrule'];
}
$db->free_result($result);
$CACHE['URLRULE'] = $data; //module的url规则 2008默认为it/product/2006/1010/1_2.html格式
$data = array();
$r = $db->get_one("SELECT `setting` FROM `".DB_PRE."module` WHERE `module`='phpcms'");
//SQL查出来,如下数据,这是网站配置的基本信息,在后台可以设置,写到这个表里
//------------------------------------------------------------------------
$setting = $r['setting'];
eval("\$PHPCMS = $setting;");
if($PHPCMS['siteurl'] =='') $PHPCMS['siteurl'] = SITE_URL; // 'siteurl' => 'http://127.0.0.1/phpcms/',
$CACHE['PHPCMS'] = $PHPCMS;
cache_write('common.php', $CACHE); //将上面生成的 $CACHE变量,写到common.php中,也就是形成了data/cache/common.php
return $CACHE;
}
function cache_module()
{
//此函数的目的,是生成单独页的配置信息,把前面setting关于的一些网站基本信息,与 模块的信息组成一个新的数组,并写到 /dada/cache/module_xxx.php
global $db;
$data = array();
$result = $db->query("SELECT `module`,`name`,`path`,`url`,`iscore`,`version`,`publishdate`,`installdate`,`updatedate`,`setting` FROM `".DB_PRE."module` WHERE `disabled`=0");
while($r = $db->fetch_array($result))
{
if(!$r['path']) $r['path'] = $r['module'] == 'phpcms' ? '' : $r['module'].'/';
if(!$r['url']) //当url为空值时,给module值给它,从数据库来看,这两个值通常是一样子的
{
$r['url'] = $r['module'] == 'phpcms' ? '' : $r['module'].'/';
$db->query("UPDATE `".DB_PRE."module` SET `url`='$r[url]' WHERE module='$r[module]' LIMIT 1");
}
if($r['setting'])
{
$setting = $r['setting'];
eval("\$setting = $setting;"); //将setting重新给一个数据变量
unset($r['setting']); //清空数组r里的setting变量,
if(is_array($setting)) $r = array_merge($r, $setting);
//这一句要注意,把setting数组合并$r模块里的关于`module`,`name`,`path`,`url`,`iscore`,`version`,`publishdate`,`installdate`,`updatedate`信息,方便后面调用
}
cache_write('module_'.$r['module'].'.php', $r); //生成 module_xxx.php,这里跑完这一句后,就生成了,最新的模块配置的信息,里面是最基础的数据并没有网站内容
}
$db->free_result($result);
}
function cache_model() //生成模形数据
{
cache_table(DB_PRE.'model', '*', '', '', 'modelid', 1);
}
function cache_category() //生成目录数据
{
cache_table(DB_PRE.'category', '*', '', '', 'listorder,catid', 1);
}
function cache_type() //生成栏目类别数据
{
cache_table(DB_PRE.'type', '*', '', '', 'listorder,typeid', 1);
}
function cache_area() //生成地区数据
{
cache_table(DB_PRE.'area', '*', '', '', 'listorder,areaid', 1);
}
function cache_member_group() //生成用户权限组数据
{
cache_table(DB_PRE.'member_group', '*', '', '', 'groupid', 1);
cache_table(DB_PRE.'member_group', '*', 'name', '', 'groupid', 0);
}
function cache_role() //生成用户角色数据 如admin,栏目编辑等
{
cache_table(DB_PRE.'role', '*', 'name', '', 'listorder,roleid');
}
function cache_author() //生成新闻作者数据
{
cache_table(DB_PRE.'author', '*', 'name', '', 'listorder,authorid', 0, 100);
}
function cache_keyword()//生成标签数据
{
cache_table(DB_PRE.'keyword', '*', 'tag', '', 'listorder,usetimes', 0, 100);
}
function cache_copyfrom() //新闻的来源配置表
{
cache_table(DB_PRE.'copyfrom', '*', '', '', 'listorder,usetimes', 0, 100);
}
function cache_pos() //生成位置数据
{
cache_table(DB_PRE.'position', '*', 'name', '', 'listorder,posid', 0);
}
function cache_status() //状态数据
{
global $db;
$array = array();
$result = $db->query("SELECT * FROM `".DB_PRE."status` ORDER BY `status` ASC");
while($r = $db->fetch_array($result))
{
$array[$r['status']] = $r['name'];
}
cache_write('status.php', $array);
return $array;
}
function cache_workflow() //工作流
{
global $db;
$array = array();
$result = $db->query("SELECT * FROM `".DB_PRE."workflow` ORDER BY `workflowid` ASC");
while($r = $db->fetch_array($result))
{
$array[$r['workflowid']] = $r['name'];
}
cache_write('workflow.php', $array);
return $array;
}
function cache_formguid()
{
cache_table(DB_PRE.'formguide', '*', '', '', 0);
}
//生成表的cache文件函数
//本函数会将数据库中,按主键ID生成数据表的cache文件,典型例子是 /data/cache/下category_*.php 的文件
function cache_table($table, $fields = '*', $valfield = '', $where = '', $order = '', $iscacheline = 0, $number = 0)
{
global $db; //调用全局变量数据库
$keyfield = $db->get_primary($table); //取表的主键名
$data = array();
if($where) $where = " WHERE $where";
if(!$order) $order = $keyfield; //设置order顺序
$limit = $number ? "LIMIT 0,$number" : ''; //设置跑多少条数
$result = $db->query("SELECT $fields FROM `$table` $where ORDER BY $order $limit"); //sql
$table = preg_replace("/^".DB_PRE."(.*)$/", "http://www.cnblogs.com/igaofen/admin/file://0.0.0.1/", $table); //取table名去掉了表前缀
while($r = $db->fetch_array($result))
{
if(isset($r['setting']) && !empty($r['setting'])) //因为 一行数据中 setting是一个数组,所以要把它另拿出来,作为变量再与前面的merge
{
$setting = $r['setting'];
eval("\$setting = $setting;");
unset($r['setting']);
if(is_array($setting)) $r = array_merge($r, $setting); //merge两个组组
}
$key = $r[$keyfield];
$value = $valfield ? $r[$valfield] : $r;
$data[$key] = $value;
if($iscacheline) cache_write($table.'_'.$key.'.php', $value); //生成cache文件,格式为 表名_主键id.php $iscacheline=1表示生成cache否则不开启
}
$db->free_result($result);
cache_write($table.'.php', $data); //生成表的全部数据 如/data/caceh/category.php 可以看一下数据结构就会明白了
}
?>

本文来自CSDN博客:http://blog.csdn.net/guwenzhong/archive/2009/03/05/3959505.aspx

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

11 Best PHP URL Shortener Scripts (Free and Premium) 11 Best PHP URL Shortener Scripts (Free and Premium) Mar 03, 2025 am 10:49 AM

Long URLs, often cluttered with keywords and tracking parameters, can deter visitors. A URL shortening script offers a solution, creating concise links ideal for social media and other platforms. These scripts are valuable for individual websites a

Introduction to the Instagram API Introduction to the Instagram API Mar 02, 2025 am 09:32 AM

Following its high-profile acquisition by Facebook in 2012, Instagram adopted two sets of APIs for third-party use. These are the Instagram Graph API and the Instagram Basic Display API.As a developer building an app that requires information from a

Working with Flash Session Data in Laravel Working with Flash Session Data in Laravel Mar 12, 2025 pm 05:08 PM

Laravel simplifies handling temporary session data using its intuitive flash methods. This is perfect for displaying brief messages, alerts, or notifications within your application. Data persists only for the subsequent request by default: $request-

Build a React App With a Laravel Back End: Part 2, React Build a React App With a Laravel Back End: Part 2, React Mar 04, 2025 am 09:33 AM

This is the second and final part of the series on building a React application with a Laravel back-end. In the first part of the series, we created a RESTful API using Laravel for a basic product-listing application. In this tutorial, we will be dev

Simplified HTTP Response Mocking in Laravel Tests Simplified HTTP Response Mocking in Laravel Tests Mar 12, 2025 pm 05:09 PM

Laravel provides concise HTTP response simulation syntax, simplifying HTTP interaction testing. This approach significantly reduces code redundancy while making your test simulation more intuitive. The basic implementation provides a variety of response type shortcuts: use Illuminate\Support\Facades\Http; Http::fake([ 'google.com' => 'Hello World', 'github.com' => ['foo' => 'bar'], 'forge.laravel.com' =>

cURL in PHP: How to Use the PHP cURL Extension in REST APIs cURL in PHP: How to Use the PHP cURL Extension in REST APIs Mar 14, 2025 am 11:42 AM

The PHP Client URL (cURL) extension is a powerful tool for developers, enabling seamless interaction with remote servers and REST APIs. By leveraging libcurl, a well-respected multi-protocol file transfer library, PHP cURL facilitates efficient execution of various network protocols, including HTTP, HTTPS, and FTP. This extension offers granular control over HTTP requests, supports multiple concurrent operations, and provides built-in security features.

12 Best PHP Chat Scripts on CodeCanyon 12 Best PHP Chat Scripts on CodeCanyon Mar 13, 2025 pm 12:08 PM

Do you want to provide real-time, instant solutions to your customers' most pressing problems? Live chat lets you have real-time conversations with customers and resolve their problems instantly. It allows you to provide faster service to your custom

Announcement of 2025 PHP Situation Survey Announcement of 2025 PHP Situation Survey Mar 03, 2025 pm 04:20 PM

The 2025 PHP Landscape Survey investigates current PHP development trends. It explores framework usage, deployment methods, and challenges, aiming to provide insights for developers and businesses. The survey anticipates growth in modern PHP versio

See all articles