Discuz code analysis-index. php

Source: Internet
Author: User
/*
[Discuz!] (C) 2001-2007 Comsenz Inc.
This is NOT a freeware, use is subject to license terms
$ Id: index. php 13764 2008-05-19 03: 14: 01Z heyond $
*/
Define ('curscript', 'index'); // defines the name of the currently running script
Require_once './include/common. inc. php'; // introduce the common file
Require_once DISCUZ_ROOT. './include/forum. func. php'; // introduces the forum processing function forum. func. php.
$ Discuz_action = 1 ;//?
If ($ cacheindexlife &&! $ Discuz_uid & $ showoldetails! = 'Yes '&&(! $ _ DCACHE ['settings'] ['frameon'] | $ _ DCACHE ['settings'] ['frameon'] & $ _ GET ['frameon']! = 'Yes') & emptyempty ($ gid )){
// Analysis: $ cacheindexlife-homepage cache validity period, $ discuz_uid exists, $ showoldetails-show online details, $ _ DCACHE ['settings'] ['frameon']-left/right partition mode switch, $ gid-Forum Group id. Check it for yourself, it is probably a condition for determining whether a static htm page is used. This is determined by whether the homepage cache time is enabled on the background.
$ Indexcache = getcacheinfo (0); // obtain the homepage cache. For details about this function, see include/forum. func. php 157. the main function is to process index.htm.
// In the following example, if an error occurs, delete index.htm. Otherwise, read the file and determine whether to display the debug information based on the system configuration.
If ($ timestamp-$ indexcache ['filemtime']> $ cacheindexlife ){
@ Unlink ($ indexcache ['filename']);
Define ('cache _ file', $ indexcache ['filename']);
$ Styleid = $ _ DCACHE ['settings'] ['styleid'];
} Elseif ($ indexcache ['filename']) {
@ Readfile ($ indexcache ['filename']);
$ Debug & debuginfo ();
$ Debug? Die ('<mce: script type = "text/javascript"> <! --
Document. getElementById ("debuginfo"). innerHTML = "'. ($ debug? 'Updated '. gmdate ("H: I: s", $ indexcache ['filemtime'] + 3600*8 ). ', Processed in '. $ debuginfo ['time']. 'Second (s ),'. $ debuginfo ['querys']. 'querys '. ($ gzipcompress? ', Gzip enabled ':''):'').'";
// --> </Mce: script> '): die ();
}
}
// $ Validdays? User Group effective time?
$ Validdays = $ discuz_uid &&! Emptyempty ($ groupexpiry) & $ groupexpiry >=$ timestamp? Ceil ($ groupexpiry-$ timestamp)/86400): 0;
// Whether the online status is displayed
If (isset ($ showoldetails )){
Switch ($ showoldetails ){
Case 'no': dsetcookie ('onlineindex', 0, 86400*365); break;
Case 'yes': dsetcookie ('onlineindex', 1, 86400*365); break;
}
} Else {
$ Showoldetails = false;
}
$ Currenttime = gmdate ($ timeformat, $ timestamp + $ timeoffset * 3600); // The current time
$ Lastvisittime = gmdate ("$ dateformat $ timeformat", $ lastvisit + $ timeoffset * 3600); // last access time
$ Memberenc = rawurlencode ($ lastmember); // The last registered user-the URL is encoded.
$ Newthreads = round ($ timestamp-$ lastvisit + 600)/1000) * 1000; // What does this variable do not know?
$ Rsshead = $ rssstatus? ('<Link rel = "alternate" type = "application/rss + xml" title = "'. $ bbname. '"href = "'. $ boardurl. 'rss. php? Auth = '. $ rssauth. "mce_href ="'. $ boardurl. 'rss. php? Auth = '. $ rssauth. "\"/> \ n "):''; // rss link
$ Customtopics = '';
If ($ qihoo ['maxtopics ']) {
Foreach (explode ("\ t", isset ($ _ DCOOKIE ['customkw '])? $ _ DCOOKIE ['customkw ']: '') as $ topic ){
$ Topic = dhtmlspecialchars (trim (stripslashes ($ topic )));
$ Customtopics. = '<a href = "topic. php? Keyword = '. rawurlencode ($ topic).' "mce_href =" topic. php? Keyword = '. rawurlencode ($ topic).' "target =" _ blank "> '. $ topic.' </a> ';
}
} // What are the topics of qihoo in the above two paragraphs? -Backend extension-qihoo search can be set
$ Hottagstatus = $ tagstatus & $ hottags & $ _ DCACHE ['tags']; // display hot tags
$ Catlist = $ forumlist = $ sublist = $ forumname = $ collapseimg = $ collapse = array (); // array of the initialization area, forum, and sub-version
$ Threads = $ posts = $ todayposts = $ fids = $ announcepm = 0; // initialize the array of posts, replies, replies today, and Forum IDS
$ Postdata = $ historyposts? Explode ("\ t", $ historyposts): array (); // historical posting?
Foreach (array ('forumlink', 'birthdays') as $ key) {// process the display of links and birthday users
If (! Isset ($ _ COOKIE ['discuz _ collapse']) | strpos ($ _ COOKIE ['discuz _ collapse'], $ key) === FALSE ){
$ Collapseimg [$ key] = 'collapsed_no.gif ';
$ Collapse [$ key] = '';
} Else {
$ Collapseimg [$ key] = 'collapsed_yes.gif ';
$ Collapse [$ key] = 'display: none ';
}
}
$ Gid =! Emptyempty ($ gid )? Intval ($ gid): 0; // Display Mode
If (! $ Gid) {// if it is not a display area, the homepage of all sections is displayed by default.
$ Announcements = ''; // The following section describes how to handle Forum announcements.
If ($ _ DCACHE ['announcements']) {
$ Readapmids =! Emptyempty ($ _ DCOOKIE ['readapmid '])? Explode ('D', $ _ DCOOKIE ['readapmid ']): array ();
Foreach ($ _ DCACHE ['announcements'] as $ announcement ){
If (emptyempty ($ announcement ['groupup']) | in_array ($ groupid, $ announcement ['groupup']) {
If (emptyempty ($ announcement ['type']) {
$ Announcements. = '<li> <a href = "announcement. php? Id = '. $ announcement ['id'].' "mce_href =" announcement. php? Id = '. $ announcement ['id'].' "> '. $ announcement ['subobject'].
'<I> ('. gmdate ($ dateformat, $ announcement ['starttime'] + $ timeoffset * 3600 ). ') </I> </a> </li> ';
} Elseif ($ announcement ['type'] = 1 ){
$ Announcements. = '<li> <a href = "'. $ announcement ['message']. '"mce_href = "'. $ announcement ['message']. '"target =" _ blank "> '. $ announcement ['subobject'].
'<I> ('. gmdate ($ dateformat, $ announcement ['starttime'] + $ timeoffset * 3600 ). ') </I> </a> </li> ';
}
}
}
}
Unset ($ _ DCACHE ['announcements']); // clear the announcement array in time after obtaining the announcement string
// Select the SQL statement for the Forum list. check whether there are access restrictions. If $ accessmasks is not empty, select the. allowview field according to the special access rules of a user.
$ SQL =! Emptyempty ($ accessmasks )?
"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,. allowview FROM {$ tablepre} forums f
Left join {$ tablepre} forumfields ff ON ff. fid = f. fid
Left join {$ tablepre} access a ON a. uid = '$ discuz_uid' AND a. fid = f. fid
WHERE f. status> 0 order by f. type, f. displayorder"
: "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
Left join {$ tablepre} forumfields ff USING (fid)
WHERE f. status> 0 order by f. type, f. displayorder ";
$ Query = $ db-> query ($ SQL );
While ($ forum = $ db-> fetch_array ($ query) {// get two important arrays from here $ catlist $ forumlist, saving area information and forum list information
$ Forumname [$ forum ['fid'] = strip_tags ($ forum ['name']); // removes the html and php tags and saves them to the $ forumname array, take fid as the key
If ($ forum ['type']! = 'Group') {// if it is a common forum (for example, type = forum or forum = sub) rather than a partition
$ Threads + = $ forum ['threads']; // The total number of topics.
$ Posts + = $ forum ['posts']; // total number of posts (subject and reply)
$ Todayposts + = $ forum ['todayposts']; // post today
If ($ forum ['type'] = 'Forum ') {// forum of non-final subversion (that is, type is not equal to sub and group)
If (forum ($ forum) {// The forum function comes from include/forum. func. php. The processing section gets the moderator icon or something.
$ Catlist [$ forum ['fup'] ['forums'] [] = $ forum ['fid']; // partition array $ catlist update
$ Forum ['orderid'] = $ catlist [$ forum ['fup'] ['forumscount '] ++; // obtain the order of the forum, the total number of sections in the partition is increased by 1. Each time you get a sub-version, the number increases by 1.
$ Forum ['subforums'] = ''; // set the sub-version string to null. It is not clear here. In the forum function, a string with the same name is obtained, why do we need to clear it here?
$ Forumlist [$ forum ['fid'] = $ forum; // assign the $ forum array to an element of $ forumlist.
}
} Elseif (isset ($ forumlist [$ forum ['fup']) {// if the parent Forum id of this Forum exists in $ forumlist (obtained from the if above ),
$ Forumlist [$ forum ['fup'] ['threads'] + = $ forum ['threads'];
$ Forumlist [$ forum ['fup'] ['posts'] + = $ forum ['posts'];
$ Forumlist [$ forum ['fup'] ['todayposts'] + = $ forum ['todayposts']; // Add three values
If ($ subforumsindex & $ forumlist [$ forum ['fup'] ['permission'] = 2 &&! ($ Forumlist [$ forum ['fup'] ['simple'] & 16) | ($ forumlist [$ forum ['fup'] ['simple'] & 8 )){
$ Forumlist [$ forum ['fup'] ['subforums']. = '<a href = "forumdisplay. php? Fid = '. $ forum ['fid'].' "mce_href =" forumdisplay. php? Fid = '. $ forum ['fid'].' "> '. $ forum ['name'].' </a> ';
} // Process the sub-version string of the Forum
}
} Else {// otherwise, if it is a partition
If (! Isset ($ _ COOKIE ['discuz _ collapse']) | strpos ($ _ COOKIE ['discuz _ collapse'], 'category _'. $ forum ['fid']) ===false ){
$ Forum ['collapseimg '] = 'collapsed_no.gif ';
$ Collapse ['category _ '. $ forum ['fid'] = '';
} Else {
$ Forum ['collapseimg '] = 'collapsed_yes.gif ';
$ Collapse ['category _ '. $ forum ['fid'] = 'display: none ';
} // What is the preceding process for enabling and disabling partitions?
If ($ forum ['moderator']) {
$ Forum ['moderator'] = moddisplay ($ forum ['moderator'], 'Flat ');
} // Moderator
$ Forum ['forumscount '] = 0;
$ Catlist [$ forum ['fid'] = $ forum; // array of newer sections
}
}
Foreach ($ catlist as $ catid => $ category) {// process the display of partitions, such as the table width and horizontal layout
If ($ catlist [$ catid] ['forumscount '] & $ category ['forumcolumn']) {
$ Catlist [$ catid] ['forumcolwidth'] = floor (100/$ category ['forumcolums']). '% ';
$ Catlist [$ catid] ['endrows '] = '';
If ($ colspan = $ category ['forumscount '] % $ category ['forumcolumn']) {
While ($ category ['forumcolumn']-$ colspan)> 0 ){
$ Catlist [$ catid] ['endrows ']. =' <td> </td> ';
$ Colspan ++;
}
$ Catlist [$ catid] ['endrows ']. =' </tr> ';
}
} Elseif (emptyempty ($ category ['forumscount ']) {
Unset ($ catlist [$ catid]);
}
}
Unset ($ catid, $ category );
If (isset ($ catlist [0]) & $ catlist [0] ['forumscount ']) {// 0 indicates a "virtual partition" at the higher level of the score area (this is understandable for the time being, because sometimes fid = 0 appears in the url)
$ Catlist [0] ['fid'] = 0;
$ Catlist [0] ['type'] = 'group ';
$ Catlist [0] ['name'] = $ bbname;
$ Catlist [0] ['collapseimg '] = 'collapsed_no.gif ';
} Else {
Unset ($ catlist [0]);
}
If ($ whosonlinestatus = 1 | $ whosonlinestatus = 3) {// display the online status
$ Whosonlinestatus = 1;
$ Onlineinfo = explode ("\ t", $ onlinerecord); // $ onlineinfo variable, $ onlinerecord from index. php extract ($ _ DCACHE) Processing
If (emptyempty ($ _ DCOOKIE ['onlineusernum']) {
$ Onlinenum = $ db-> result_first ("select count (*) FROM {$ tablepre} sessions"); // number of online users
If ($ onlinenum> $ onlineinfo [0]) {// if the number of online users obtained in the current database is greater than the original number of online users, update $ onlinerecord
$ _ DCACHE ['settings'] ['onlinerecord '] = $ onlinerecord = "$ onlinenum \ t $ timestamp ";
$ Db-> query ("UPDATE {$ tablepre} settings SET value = '$ onlinerecord' WHERE variable = 'onlinerecord '"); // UPDATE the settings table at the same time
Require_once DISCUZ_ROOT. './include/cache. func. php ';
Updatesettings (); // updates the settings cache.
$ Onlineinfo = array ($ onlinenum, $ timestamp); // update the $ onlineinfo array
}
Dsetcookie ('onlineusernum', intval ($ onlinenum), 300); // write the number of online users to the cookie
} Else {
$ Onlinenum = intval ($ _ DCOOKIE ['onlineusernum']); // if the number of online users in the cookie is not empty, read it directly.
}
$ Onlineinfo [1] = gmdate ($ dateformat, $ onlineinfo [1] + ($ timeoffset * 3600); // update the timestamp of online Conditions
$ Detailstatus = $ showoldetails = 'yes' | (((! Isset ($ _ DCOOKIE ['onlineindex']) &! $ Whosonline_contract) | $ _ DCOOKIE ['onlineindex']) & $ onlinenum <500 &&! $ Showoldetails); // determines the online details variable. It is complicated here. Take a closer look, mainly because $ showoldetails = 'yes' and some conditions are displayed on the homepage of cookies.
If ($ detailstatus) {// The following is the list of online users processed
@ Include language ('actions'); // reference the language file/templates/default/actions. lang. php
$ Discuz_uid & updatesession (); // update the session
$ Membercount = $ invisiblecount = 0; // number of initial members and invisible members
$ Whosonline = array (); // initializes an array.
$ Maxonlinelist = $ maxonlinelist? $ Maxonlinelist: 500; // maximum number of online users. If not set, the value is initialized to 500.
$ Query = $ db-> query ("SELECT uid, username, groupid, invisible, action, lastactivity, fid FROM {$ tablepre} sessions ". (isset ($ _ DCACHE ['onlinelist'] [7])? '': 'Where uid <> 0')." order by uid desc limit ". $ maxonlinelist );
While ($ online = $ db-> fetch_array ($ query )){
If ($ online ['uid']) {// Member
$ Membercount ++; // Total Number of Members
If ($ online ['invisable']) {// invisible user
$ Invisiblecount ++;
Continue;
} Else {
$ Online ['icon '] = isset ($ _ DCACHE ['onlinelist'] [$ online ['groupid'])? $ _ DCACHE ['onlinelist'] [$ online ['groupid']: $ _ DCACHE ['onlinelist'] [0]; // user group icon
}
} Else {// visitor, the difference is that in the data table session, the uid is 0
$ Online ['icon '] = $ _ DCACHE ['onlinelist'] [7];
$ Online ['username'] = $ _ DCACHE ['onlinelist'] ['guest '];
}
$ Online ['fid'] = $ online ['fid']? $ Forumname [$ online ['fid']: 0; // is the user browsing the Forum?
$ Online ['action'] = $ actioncode [$ online ['action']; // the action that the user is performing.
$ Online ['lastactivity'] = gmdate ($ timeformat, $ online ['lastactive'] + ($ timeoffset * 3600); // What is the last time the user accessed?
$ Whosonline [] = $ online; // assign a value to the $ whosonline Array
}
Unset ($ actioncode, $ online); // clear two variables
If ($ onlinenum> $ maxonlinelist) {// if the total number of online users exceeds the maximum number of online users (the default value is 500), the logged-on users and invisible users are retrieved respectively.
$ Membercount = $ db-> result_first ("select count (*) FROM {$ tablepre} sessions WHERE uid <> '0 '");
$ Invisiblecount = $ db-> result_first ("select count (*) FROM {$ tablepre} sessions WHERE invisible = '1 '");
}
If ($ onlinenum <$ membercount) {// if the total number of online users is less than the number of online members, the number of online users in the cookie is updated. Note that onlineusernum is not onlinenum.
$ Onlinenum = $ db-> result_first ("select count (*) FROM {$ tablepre} sessions ");
Dsetcookie ('onlineusernum', intval ($ onlinenum), 300 );
}
// Conclusion: this is a bit confusing, such as the total number of online users and online members. Because the variables are similar, it is easy to read errors and understand errors. Read them several times...
$ Guestcount = $ onlinenum-$ membercount;
$ Db-> free_result ($ query); // release the database connection
Unset ($ online); // clear. Isn't row 230 available? Empty again?
}
} Else {
$ Whosonlinestatus = 0; // if the number of online users is not displayed in the background, the online list is not displayed.
}
} Else {// corresponds to 77th rows. For example, the url is index. php? Gid = 2, then the following file is called,
Require_once DISCUZ_ROOT. './include/category. inc. php ';
}
Include template ('discuz'); // parse the template file on the homepage

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.