1. <?php
  2. /*
  3. *  April 19,2012
  4. *    discuz二次开发学习
  5. *    author:xuqin
  6. *    不能为了完成任务去做一件事,要举一反三,融会贯
  7. *
  8. * @$conn=mysql_connect("localhost","root","123456") or die ("连接数据库服务器失败");
  9. mysql_select_db("test",$conn);
  10. mysql_query("set names 'gbk'");
  11. $sql00="select * from `admin` where `name`='admin'";
  12. $query=mysql_query($sql00,$conn);
  13. $row=mysql_fetch_array($query);
  14. $username=$row['name'];
  15. echo $username;
  16. *
  17. * 如果用自己的方法连接数据库,只有这里(最上面)才能连接成功,不报错。
  18. * 如果在require_once './include/common.inc.php'; 一下用这个方法连接数据库,会报错。
  19. * 因为在common.inc.php中引用了db_mysql.class.php严格定义了discuz连接数据库的方法。别的方法视为非法。
  20. *
  21. * 单个数据获取载入前台页面:
  22. $sql="select * from {$tablepre}members where `username`='admin'";
  23. $query=$db->query($sql);
  24. $row=mysql_fetch_array($query);
  25. $password=$row['password'];
  26. 多条数据循环载入前台页面:
  27.   $query = $db->query("SELECT * FROM {$tablepre}members");
  28. while( $result = $db->fetch_array($query) ){ //后台
  29.  $oklist[] = $result;
  30. }
  31. <!--{loop $oklist $key $a}--> //前台
  32.   $a[username]:$a[email]
  33. <!--{/loop}-->
  34. */
  35. define('CURSCRIPT', 'index');    //定义当前运行脚本名
  36. require_once './include/common.inc.php'; //引入common文件
  37. require_once DISCUZ_ROOT.'./include/forum.func.php'; //引入版块处理函数forum.func.php
  38. $discuz_action = 1;
  39. /*
  40. *  “当前动作”,sessions里面保存的是一个代号,相对应的文 字在templates/default/action.lang.php文件里面
  41. *    “当前动作”是一个全局变量$discuz_action ,在不同页面有不同的值,如在:
  42. *    index.php     $discuz_action = 1;(浏览论坛首页)
  43. *    logging.php    $discuz_action = 6;(登录论坛)
  44. *    viewthread.php  $discuz_action = 3;(浏览帖子)等等很多
  45. *
  46. *    但是用处是什么呢????
  47. *    个人感觉只是起到"跟踪用户"的作用,比如Discuz不是有这个功能:当前板块正在浏览的用户有哪些啊,还有点击进入首页下方”在线用户“也页面会看到一个列表,并详细记录了当前用户的”当前动作“;
  48. *    甚至在表cdb_sessions里面专门有个字段记录用户当前的action代号
  49. */
  50. if($cacheindexlife && !$discuz_uid && $showoldetails != 'yes' && (!$_DCACHE['settings']['frameon'] || $_DCACHE['settings']['frameon'] && $_GET['frameon'] != 'yes') && emptyempty($gid)) {
  51. $indexcache = getcacheinfo(0); //得到首页缓存,此函数见include/forum.func.php 157行,主要是处理index.htm
  52. if($timestamp - $indexcache['filemtime'] > $cacheindexlife) {//判断缓存时间是否过期,如果过期,就删除index.htm,否则读取文件,并根据系统配置决定是否显示debug信息
  53. @unlink($indexcache['filename']); //过期就删除
  54. define('CACHE_FILE', $indexcache['filename']);
  55. $styleid = $_DCACHE['settings']['styleid'];
  56. } elseif($indexcache['filename']) { //没有过期就读取
  57. @readfile($indexcache['filename']);
  58. $debug && debuginfo();
  59. $debug ? die('<script type="text/javascript">document.getElementById("debuginfo").innerHTML = " '.($debug ? 'Updated at '.gmdate("H:i:s", $indexcache['filemtime'] + 3600 * 8).', Processed in '.$debuginfo['time'].' second(s), '.$debuginfo['queries'].' Queries'.($gzipcompress ? ', Gzip enabled' : '') : '').'";</script>') : die();
  60. }
  61. }
  62. /*
  63. * 分析:$cacheindexlife-首页缓存有效期,$discuz_uid存在,$showoldetails-显示在线详情,$_DCACHE['settings']['frameon']-左右分栏模式开关,$gid-版块组id,
  64. * 大概就是判断是否使用一个静态htm页面的条件,这个由后台是否开启首页缓存时间来决定的
  65. */
  66. $validdays = $discuz_uid && !emptyempty($groupexpiry) && $groupexpiry >= $timestamp ? ceil(($groupexpiry - $timestamp) / 86400) : 0;   //网上说是:用户组有效时间   恩? 做什么用的?
  67. if(isset($showoldetails)) {//首页下方 在线会员列表是要【展开】还是【收缩】显示
  68. switch($showoldetails) {
  69. case 'no': dsetcookie('onlineindex', 0, 86400 * 365); break; //收缩
  70. case 'yes': dsetcookie('onlineindex', 1, 86400 * 365); break; //展开
  71. }
  72. } else {
  73. $showoldetails = false;
  74. }
  75. $currenttime = gmdate($timeformat, $timestamp + $timeoffset * 3600); //当前时间
  76. $lastvisittime = gmdate("$dateformat $timeformat", $lastvisit + $timeoffset * 3600);//上次访问时间
  77. /*
  78. * time():标准时间戳-指返回自从 Unix 纪元(格林威治时间 1970 年 1 月 1 日 00:00:00)到当前时间(指的是当前GMT标准时间)的秒数,它的值跟php系统设置的时区无关。
  79. * date():返回的是当前 GMT标准时间的本地化时间的“自定义格式”时间,跟php系统设置的时区有关。
  80. * gmdate():返回的是当前 GMT标准时间的“自定义格式”时间,跟php系统设置的时区无关。
  81. *
  82. * PHP中的时间有2个格式化函数:date()和gmdate(),在官方的文档中的描述为:
  83. * date -- 格式化一个本地时间/日期
  84. * gmdate -- 格式化一个 GMT/UTC 日期/时间,返回的是格林威治标准时(GMT)。
  85. * 举个例子,我们现在所在的时区是+8,那么服务器运行以下脚本返回的时间应该是这样的:
  86. * 当前时间假定是2007-03-14 12:15:27
  87. * echo date('Y-m-d H:i:s', time()); 输出为:2007-03-14 12:15:27
  88. * echo gmdate('Y-m-d H:i:s', time()); 输出为:2007-03-14 04:15:27
  89. * 但是这只是在Linux+Apache下运行PHP所得的结果,如果在Windows下运行,则2个函数返回都是:2007-03-14 04:15:27。
  90. * 所以,我们应该给一个兼容性的写法,统一使用gmdate,并手工设置当前时区,写法改进如下:
  91. * echo gmdate('Y-m-d H:i:s', time() + 3600 * 8);
  92. * 这样不管在Linux+Apache下还是Windows下都得到了正确的结果,当然这样写还有一个好处,当网站是面向全世界的时候,那么网站用户只要设置所在的时区,程序自动根据用
  93. * 户设置的时区进行时间计算,数据库中信息发布时间只存当前的time()所生成的时间,那么在中国+8时区看到的发布时间是:2007-03-14 12:15:27,那么在欧洲+2时区用户看到这
  94. * 个信息的发布时间是:2007-03-14 06:15:27,这样信息的时间就全部对应正确了。
  95. */
  96. $memberenc = rawurlencode($lastmember);    //对最后注册用户URL进行了编码      ??为什么编码,作用是?
  97. $newthreads = round(($timestamp - $lastvisit + 600) / 1000) * 1000;   //??
  98. $rsshead = $rssstatus ? ('<link rel="alternate" type="application/rss+xml" title="'.$bbname.'" href="'.$boardurl.'rss.php?auth='.$rssauth."\" />\n") : '';
  99. $customtopics = '';
  100. if($qihoo['maxtopics']) {
  101. foreach(explode("\t", isset($_DCOOKIE['customkw']) ? $_DCOOKIE['customkw'] : '') as $topic) {
  102. $topic = dhtmlspecialchars(trim(stripslashes($topic)));
  103. $customtopics .= '<a href="topic.php?keyword='.rawurlencode($topic).'" target="_blank">'.$topic.'</a> &nbsp;';
  104. }
  105. }
  106. //以上两段,RSS和qihoo专题 - 后台的扩展-qihoo搜索那里可以设置
  107. $hottagstatus = $tagstatus && $hottags && $_DCACHE['tags'];  //显示热门标签
  108. $catlist = $forumlist = $sublist = $forumname = $collapseimg = $collapse = array();    //初始化区、版块、子版等数组
  109. $threads = $posts = $todayposts = $fids = $announcepm = 0;  //初始化帖子、回复、今日回复、版块id等数组
  110. $postdata = $historyposts ? explode("\t", $historyposts) : array();   //历史发帖
  111. foreach(array('forumlinks', 'birthdays') as $key){   //友情链接与生日用户的显示
  112. if(!isset($_COOKIE['discuz_collapse']) || strpos($_COOKIE['discuz_collapse'], $key) === FALSE) {
  113. $collapseimg[$key] = 'collapsed_no.gif';
  114. $collapse[$key] = '';
  115. } else {
  116. $collapseimg[$key] = 'collapsed_yes.gif';
  117. $collapse[$key] = 'display: none';
  118. }
  119. }
  120. $gid = !emptyempty($gid) ? intval($gid) : 0;        //$gid板块区大类  下面包含个板块:比如:当$gid=1时,首页下面“在线会员“板块 不见了
  121. /*
  122. * 感觉有点怪怪的,$gid定义后,好像在哪个文件中在数据库cdb_forms表中查询了下,$gid定义的区板块存不存在。
  123. */
  124. if(!$gid) {        //如果指定的区板块不存在,即不是区显示方式,则默认的显示所有版块的首页
  125. $announcements = '';       //此句与下面一段是处理论坛公告
  126. if($_DCACHE['announcements']) {
  127. $readapmids = !emptyempty($_DCOOKIE['readapmid']) ? explode('D', $_DCOOKIE['readapmid']) : array();
  128. foreach($_DCACHE['announcements'] as $announcement) {
  129. if(emptyempty($announcement['groups']) || in_array($groupid, $announcement['groups'])) {
  130. if(emptyempty($announcement['type'])) {
  131. $announcements .= '<li><a href="announcement.php?id='.$announcement['id'].'">'.$announcement['subject'].
  132. '<em>('.gmdate($dateformat, $announcement['starttime'] + $timeoffset * 3600).')</em></a></li>';
  133. } elseif($announcement['type'] == 1) {
  134. $announcements .= '<li><a href="'.$announcement['message'].'" target="_blank">'.$announcement['subject'].
  135. '<em>('.gmdate($dateformat, $announcement['starttime'] + $timeoffset * 3600).')</em></a></li>';
  136. }
  137. }
  138. }
  139. }
  140. unset($_DCACHE['announcements']);    //得到公告的字符串后,及时清空这个公告数组
  141. //下面是首页板块显示逻辑处理
  142. $sql = !emptyempty($accessmasks) ?
  143. "SELECT f.fid, f.fup, f.type, f.name, f.threads, f.posts, f.todayposts, f.lastpost, f.inheritedmod, f.forumcolumns, f.simple, ff.description, ff.moderators, ff.icon, ff.viewperm, ff.redirect, a.allowview FROM {$tablepre}forums f
  144. LEFT JOIN {$tablepre}forumfields ff ON ff.fid=f.fid
  145. LEFT JOIN {$tablepre}access a ON a.uid='$discuz_uid' AND a.fid=f.fid
  146. WHERE f.status>0 ORDER BY f.type, f.displayorder"
  147. : "SELECT f.fid, f.fup, f.type, f.name, f.threads, f.posts, f.todayposts, f.lastpost, f.inheritedmod, f.forumcolumns, f.simple, ff.description, ff.moderators, ff.icon, ff.viewperm, ff.redirect FROM {$tablepre}forums f
  148. LEFT JOIN {$tablepre}forumfields ff USING(fid)
  149. WHERE f.status>0 ORDER BY f.type, f.displayorder";
  150. $query = $db->query($sql);
  151. /*
  152. * 选出论坛列表的sql,注意这里判断了是否有访问限制,如果$accessmasks(Access标志 ,cdb_members 用户表中有这个字段)不为空,则根据某用户的特殊访问规则选出了 a.allowview这个字段等
  153. */
  154. while($forum = $db->fetch_array($query)) {    //从这里开始得到两个重要数组$catlist $forumlist,保存区信息与版块列表信息
  155. $forumname[$forum['fid']] = strip_tags($forum['name']);    //去掉html与php标记,并存入$forumname数组,以fid为键
  156. if($forum['type'] != 'group') {    //如果是普通版块(如type=forum或forum=sub)而不是分区
  157. $threads += $forum['threads'];    //主题总数
  158. $posts += $forum['posts'];    //帖子总数(主题与回复)
  159. $todayposts += $forum['todayposts'];    //今日帖子
  160. if($forum['type'] == 'forum') {    //非最终子版(即type不等于sub和group)的版块
  161. if(forum($forum)) {    //forum函数来自include/forum.func.php,处理版块,得到比如版主啊图标啊什么的
  162. $catlist[$forum['fup']]['forums'][] = $forum['fid'];    //分区数组$catlist更新
  163. $forum['orderid'] = $catlist[$forum['fup']]['forumscount']++;   //得到版块的排序,所在分区的版块总数加1,每得到一个子版,就自增1
  164. $forum['subforums'] = '';    //将子版字符串设置为空的,这里不是很明白,forum函数里得到了一个相同名的字符串,这里为何要清空?
  165. $forumlist[$forum['fid']] = $forum;    //将$forum数组赋值给$forumlist的一个元素
  166. }
  167. } elseif(isset($forumlist[$forum['fup']])) {    //如果此版块的父版块id在$forumlist中存在(由上面的if中得到),则
  168. $forumlist[$forum['fup']]['threads'] += $forum['threads'];
  169. $forumlist[$forum['fup']]['posts'] += $forum['posts'];
  170. $forumlist[$forum['fup']]['todayposts'] += $forum['todayposts'];  //累加三个值
  171. if($subforumsindex && $forumlist[$forum['fup']]['permission'] == 2 && !($forumlist[$forum['fup']]['simple'] & 16) || ($forumlist[$forum['fup']]['simple'] & 8)) {
  172. $forumlist[$forum['fup']]['subforums'] .= '<a href="forumdisplay.php?fid='.$forum['fid'].'">'.$forum['name'].'</a>&nbsp;&nbsp;';
  173. }
  174. }
  175. }
  176. else {   //否则,如果是分区
  177. if(!isset($_COOKIE['discuz_collapse']) || strpos($_COOKIE['discuz_collapse'], 'category_'.$forum['fid']) === FALSE) {
  178. $forum['collapseimg'] = 'collapsed_no.gif';
  179. $collapse['category_'.$forum['fid']] = '';
  180. }
  181. else {    //上面是对分区开启关闭按钮的处理
  182. $forum['collapseimg'] = 'collapsed_yes.gif';
  183. $collapse['category_'.$forum['fid']] = 'display: none';
  184. }
  185. if($forum['moderators']) {  //区版主
  186. $forum['moderators'] = moddisplay($forum['moderators'], 'flat');
  187. }
  188. $forum['forumscount']     = 0;
  189. $catlist[$forum['fid']] = $forum;  //更新区版块数组
  190. }
  191. }
  192. foreach($catlist as  $catid => $category) {    //对分区的显示进行处理,如表格宽度,是否横排版块等等
  193. if($catlist[$catid]['forumscount'] && $category['forumcolumns']) {
  194. $catlist[$catid]['forumcolwidth'] = floor(100 / $category['forumcolumns']).'%';
  195. $catlist[$catid]['endrows'] = '';
  196. if($colspan = $category['forumscount'] % $category['forumcolumns']) {
  197. while(($category['forumcolumns'] - $colspan) > 0) {
  198. $catlist[$catid]['endrows'] .= '<td>&nbsp;</td>';
  199. $colspan ++;
  200. }
  201. $catlist[$catid]['endrows'] .= '</tr>';
  202. }
  203. } elseif(emptyempty($category['forumscount'])) {
  204. unset($catlist[$catid]);
  205. }
  206. }
  207. unset($catid, $category);
  208. if(isset($catlist[0]) && $catlist[0]['forumscount']) {   //0表示比分区更大一级的一个“虚拟分区”(暂时这么理解,因为有时候url中有fid=0这样的出现)
  209. $catlist[0]['fid'] = 0;
  210. $catlist[0]['type'] = 'group';
  211. $catlist[0]['name'] = $bbname;
  212. $catlist[0]['collapseimg'] = 'collapsed_no.gif';
  213. } else {
  214. unset($catlist[0]);
  215. }
  216. ?>

本文转自许琴 51CTO博客,原文链接:http://blog.51cto.com/xuqin/882318,如需转载请自行联系原作者

第三天 入口文件index.php 01相关推荐

  1. thinkphp5/phpstudy分析入口文件index.php及localhost和配置域名访问网站根目录www

    文章目录 1.thinkphp5入口文件简介 2.访问网站根目录www (1)localhost访问网站根目录www (2)配置域名访问网站根目录www 第一步:点击站点域名管理 第二步:站点域名设置 ...

  2. ThhinkPHP5隐藏入口文件index.php

    原文链接1:https://blog.csdn.net/lw545034502/article/details/79374172/ 原文链接2:https://www.cnblogs.com/chq3 ...

  3. index.php文件下载,此文件时入口文件index.php,_PHP教程

    此文件时入口文件index.php, 此文件时入口文件index.php //定义一下ThinkPHP框架存放的路径 define('THINK_PATH','./ThinkPHP/'); //定义当 ...

  4. ThinkPHP3.2URL重写隐藏应用的入口文件index.php

    可以通过URL重写隐藏应用的入口文件index.PHP,下面是相关服务器的配置参考: [ Apache ] httpd.conf配置文件中加载了mod_rewrite.so模块 AllowOverri ...

  5. php好的mvc中index方法,创建一个mvc应用目录架构并创建入口文件index.php

    摘要:<?php require 'vendor/autoload.php'; require 'pig/Base.php'; define('ROOT_PATH',__DIR__.'/'); ...

  6. nginx给php做统一入口,Nginx如何来配置隐藏入口文件index.php(代码)

    这篇文章给大家介绍的内容是关于Nginx配置 隐藏入口文件index.php,有一定的参考价值,有需要的朋友可以参考一下,希望对你有所帮助. Nginx配置文件里放入这段代码server { loca ...

  7. thinkphp 去掉URL地址里面的入口文件index.php

    可以去掉URL地址里面的入口文件index.php,但是需要额外配置WEB服务器的重写规则. 以Apache为例,需要在入口文件的同级添加.htaccess文件(官方默认自带了该文件),内容如下 ? ...

  8. phpyii框架倒叙_Yii框架入口文件index.php功能分

    在YII代码自动生成工具生成的项目下,有一个index.php文件.这个文件是整个基于yii框架的web项目的启动入口文件.默认情况下,访问路径为:http://hostname:port/webro ...

  9. Nginx隐藏PHP入口文件index.php

    如果没有自定义域名,则打开Nginx配置文件:nginx-conf 对应着改 如果自定义了域名,则打开Nginx配置文件:vhosts-conf 对应着改 location / {index inde ...

最新文章

  1. c语言正确理解以下名词及其含义,C程序作业答案.doc
  2. Java ObjectOutputStream writeLong()方法与示例
  3. FullCalendar 二:FullCalendar日历插件说明文档
  4. [C指针] 用图表解读C声明:Unscrambling C Declarations by Diagram
  5. C++ .template 关键字
  6. 弹琴、cosplay、打羽毛球……现在的机器人都是戏精丨世界机器人大会
  7. 文本框焦点清空以及回车键提交表单的实现
  8. Emacs学习笔记(8): 使用emacs浏览网页
  9. iOS UI自动化测试详解
  10. 【电子商务安全与支付实验】数字证书的申请及使用
  11. 城市三级联动带城市数据
  12. XAMARIN运行IPHONE模拟器
  13. 忘记网站服务器密码怎么办,忘记远程服务器的密码怎么办
  14. python百度ai文字识别、不精确、进行处理,python利用百度AI实现文字识别功能
  15. Python爬虫实战案例讲解——爬虫爬取地铁线路图
  16. 海盗湾(The Pirate Bay)的战争——每一名技术人员都应该思考的问题
  17. 实验四:《操作系统》之管道通信
  18. 蓝桥信用卡号验证-枚举法应用 JAVA暴解
  19. 跌才是机会,涨才是风险
  20. 分享一个电气仿真软件

热门文章

  1. 【矩阵乘法】行为方案
  2. 一篇文章弄懂变压器的等效原理
  3. 《工程伦理与学术道德》之《工程活动中的环境伦理》
  4. 乔布斯在斯坦福大学的演讲稿
  5. 2022年下半年软就测试就业浅谈
  6. Android 8.1 【FriendlyARM】温度压力传感器-BMP180 驱动开发
  7. 查询除某一列外的所有列的数据
  8. mysql查询数据库结构_mysql查询数据库下的表结构
  9. 【javasim】一个java下的建模仿真平台
  10. ACRush 楼天成 回忆录