【UCHome二次开发】全局变量
UCHome定义了一些全局变量保存常用信息,了解这些变量存放的内容将大大方便我们的二次开发。
- $_SC:系统全局配置
- $_SBLOCK:未知
- $_SCONFIG:个人空间配置
- $_SCOOKIE:Cookie信息
- $_SGLOBAL:各类全局信息
- $_SN:昵称信息
- $_TPL:未知
- 举例说明
以上个别全局变量在不同页面的值会有所不同,使用前最好先测试一下值是否存在。
下面是用print_r函数打印出来的各全局变量信息,方便参考(为节省篇幅,删除了部分结构重复的数据):
01 | $_SC: Array |
02 | ( |
03 | [dbhost] => localhost |
04 | [dbuser] => root |
05 | [dbpw] => root |
06 | [dbcharset] => utf8 |
07 | [pconnect] => 0 |
08 | [dbname] => uchome |
09 | [tablepre] => uchome_ |
10 | [charset] => utf-8 |
11 | [gzipcompress] => 0 |
12 | [cookiepre] => uchome_ |
13 | [cookiedomain] => |
14 | [cookiepath] => / |
15 | [attachdir] => ./attachment/ |
16 | [attachurl] => attachment/ |
17 | [siteurl] => http://localhost/uchome/ |
18 | [tplrefresh] => 0 |
19 | [founder] => 1 |
20 | [allowedittpl] => 0 |
21 | ) |
001 | $_SCONFIG: Array |
002 | ( |
003 | [sitename] => 我的空间 |
004 | [sitelogo] => image/logo.gif |
005 | [template] => default |
006 | [adminemail] => webmaster@localhost |
007 | [onlinehold] => 1800 |
008 | [timeoffset] => 8 |
009 | [maxpage] => 50 |
010 | [starcredit] => 100 |
011 | [starlevelnum] => 5 |
012 | [cachemode] => database |
013 | [cachegrade] => 0 |
014 | [allowcache] => 1 |
015 | [allowdomain] => 0 |
016 | [allowrewrite] => 0 |
017 | [allowwatermark] => 0 |
018 | [allowftp] => 0 |
019 | [holddomain] => www|*blog*|*space*|x |
020 | [mtagminnum] => 5 |
021 | [feedday] => 15 |
022 | [feedmaxnum] => 50 |
023 | [feedfilternum] => 10 |
024 | [importnum] => 100 |
025 | [singlesent] => 50 |
026 | [groupnum] => 8 |
027 | [closeregister] => 0 |
028 | [closeinvite] => 0 |
029 | [close] => 0 |
030 | [networkpublic] => 1 |
031 | [networkpage] => 1 |
032 | [networkupdate] => 300 |
033 | [seccode_register] => 1 |
034 | [uc_tagrelated] => 1 |
035 | [manualmoderator] => 1 |
036 | [linkguide] => 1 |
037 | [showall] => 1 |
038 | [sendmailday] => 0 |
039 | [realname] => 0 |
040 | [namecheck] => 0 |
041 | [namechange] => 0 |
042 | [name_allowfriend] => 1 |
043 | [name_allowpoke] => 1 |
044 | [name_allowdoing] => 1 |
045 | [name_allowblog] => 1 |
046 | [name_allowalbum] => 1 |
047 | [name_allowthread] => 1 |
048 | [name_allowshare] => 1 |
049 | [name_allowcomment] => 1 |
050 | [name_allowpost] => 1 |
051 | [showallfriendnum] => 10 |
052 | [feedtargetblank] => 1 |
053 | [feedread] => 1 |
054 | [uc_tagrelatedtime] => 86400 |
055 | [privacy] => Array |
056 | ( |
057 | [view] => Array |
058 | ( |
059 | [index] => 0 |
060 | [profile] => 0 |
061 | [friend] => 0 |
062 | [wall] => 0 |
063 | [feed] => 0 |
064 | [doing] => 0 |
065 | [blog] => 0 |
066 | [album] => 0 |
067 | [share] => 0 |
068 | [mtag] => 0 |
069 | ) |
070 | |
071 | [feed] => Array |
072 | ( |
073 | [doing] => 1 |
074 | [blog] => 1 |
075 | [album] => 1 |
076 | [upload] => 1 |
077 | [share] => 1 |
078 | [thread] => 1 |
079 | [post] => 1 |
080 | [mtag] => 1 |
081 | [friend] => 1 |
082 | [comment] => 1 |
083 | [trace] => 1 |
084 | ) |
085 | |
086 | ) |
087 | |
088 | [cronnextrun] => 1254829800 |
089 | [my_status] => 0 |
090 | [sitekey] => 2a37854626AdS662 |
091 | [siteallurl] => http://localhost/uchome/ |
092 | [licensed] => 0 |
093 | [debuginfo] => 0 |
094 | [miibeian] => |
095 | [headercharset] => 0 |
096 | [avatarreal] => 0 |
097 | [uc_dir] => |
098 | [my_ip] => |
099 | [closereason] => |
100 | [feeddefaultfilter] => all |
101 | [my_closecheckupdate] => 0 |
102 | [spacebarusername] => |
103 | [defaultfusername] => |
104 | [domainroot] => |
105 | [ftpurl] => |
106 | [login_action] => 1812d4b322672381d1dc7396a8a52ef7 |
107 | [register_action] => 0d7f87d7c19770cac7d20679586b362f |
108 | ) |
1 | $_SCOOKIE: Array |
2 | ( |
3 | [loginuser] => admin |
4 | [checkpm] => 1 |
5 | [synfriend] => 1 |
6 | [sendmail] => 1 |
7 | [auth] => 61087Cgwu3hoB35cDmXGpe3juvbjJQC2e+wlWJ79GPejIYhB1j/d9VwyKGy8DPYcKQCHUYvYg+EBqJoQS5Vc |
8 | ) |
001 | $_SGLOBAL: Array |
002 | ( |
003 | [timestamp] => 1254829664 |
004 | [supe_starttime] => 1254829664.1719 |
005 | [db] => dbstuff Object |
006 | ( |
007 | [querynum] => 3 |
008 | [link] => Resource id #7 |
009 | [charset] => utf8 |
010 | ) |
011 | |
012 | [app] => Array |
013 | ( |
014 | [1] => Array |
015 | ( |
016 | [name] => Forer |
017 | [url] => http://localhost/bbs |
018 | [type] => DISCUZ |
019 | [open] => 1 |
020 | [icon] => discuz |
021 | ) |
022 | |
023 | [2] => Array |
024 | ( |
025 | [name] => 个人家园 |
026 | [url] => http://localhost/uch |
027 | [type] => UCHOME |
028 | [open] => 0 |
029 | [icon] => uchome |
030 | ) |
031 | |
032 | ) |
033 | |
034 | [userapp] => Array |
035 | ( |
036 | ) |
037 | |
038 | [ad] => Array |
039 | ( |
040 | ) |
041 | |
042 | [supe_uid] => 1 |
043 | [supe_username] => admin |
044 | [inajax] => 0 |
045 | [ajaxmenuid] => |
046 | [refer] => http://localhost/uchome/space.php?do=mtag |
047 | [session] => Array |
048 | ( |
049 | [uid] => 1 |
050 | [username] => admin |
051 | [password] => 8ae86ee69cba169f8691011ea3c5691f |
052 | [lastactivity] => 1254829662 |
053 | [ip] => 127000000 |
054 | ) |
055 | |
056 | [username] => admin |
057 | [my_menu] => Array |
058 | ( |
059 | ) |
060 | |
061 | [my_userapp] => Array |
062 | ( |
063 | ) |
064 | |
065 | [my_menu_more] => 0 |
066 | [appmenu] => Array |
067 | ( |
068 | [name] => Forer |
069 | [url] => http://localhost/bbs |
070 | [type] => DISCUZ |
071 | [open] => 1 |
072 | [icon] => discuz |
073 | ) |
074 | |
075 | [appmenus] => Array |
076 | ( |
077 | ) |
078 | |
079 | [member] => Array |
080 | ( |
081 | [uid] => 1 |
082 | [sex] => 0 |
083 | [email] => |
084 | [emailcheck] => 0 |
085 | [qq] => |
086 | [msn] => |
087 | [birthyear] => 0 |
088 | [birthmonth] => 0 |
089 | [birthday] => 0 |
090 | [blood] => |
091 | [marry] => 0 |
092 | [birthprovince] => |
093 | [birthcity] => |
094 | [resideprovince] => |
095 | [residecity] => |
096 | [note] => |
097 | [spacenote] => |
098 | [authstr] => |
099 | [theme] => |
100 | [nocss] => 0 |
101 | [menunum] => 0 |
102 | [css] => |
103 | [privacy] => Array |
104 | ( |
105 | [view] => Array |
106 | ( |
107 | [index] => 0 |
108 | [profile] => 0 |
109 | [friend] => 0 |
110 | [wall] => 0 |
111 | [feed] => 0 |
112 | [doing] => 0 |
113 | [blog] => 0 |
114 | [album] => 0 |
115 | [share] => 0 |
116 | [mtag] => 0 |
117 | ) |
118 | |
119 | [feed] => Array |
120 | ( |
121 | [doing] => 1 |
122 | [blog] => 1 |
123 | [album] => 1 |
124 | [upload] => 1 |
125 | [share] => 1 |
126 | [thread] => 1 |
127 | [post] => 1 |
128 | [mtag] => 1 |
129 | [friend] => 1 |
130 | [comment] => 1 |
131 | [trace] => 1 |
132 | ) |
133 | |
134 | ) |
135 | |
136 | [friend] => |
137 | [feedfriend] => |
138 | [sendmail] => |
139 | [groupid] => 1 |
140 | [credit] => 0 |
141 | [username] => admin |
142 | [name] => |
143 | [namestatus] => 0 |
144 | [domain] => |
145 | [viewnum] => 0 |
146 | [notenum] => 0 |
147 | [friendnum] => 0 |
148 | [dateline] => 1245599521 |
149 | [updatetime] => 0 |
150 | [lastsearch] => 0 |
151 | [lastpost] => 0 |
152 | [lastlogin] => 1254829560 |
153 | [lastsend] => 0 |
154 | [attachsize] => 0 |
155 | [addsize] => 0 |
156 | [flag] => 1 |
157 | [newpm] => 0 |
158 | [avatar] => 0 |
159 | [ip] => 127000000 |
160 | [mood] => 0 |
161 | [self] => 1 |
162 | [friends] => Array |
163 | ( |
164 | ) |
165 | |
166 | ) |
167 | |
168 | [space_1_uid] => Array |
169 | ( |
170 | [uid] => 1 |
171 | [sex] => 1 |
172 | [email] => |
173 | [emailcheck] => 0 |
174 | [qq] => |
175 | [msn] => |
176 | [birthyear] => 0 |
177 | [birthmonth] => 0 |
178 | [birthday] => 0 |
179 | [blood] => |
180 | [marry] => 0 |
181 | [birthprovince] => |
182 | [birthcity] => |
183 | [resideprovince] => |
184 | [residecity] => |
185 | [note] => |
186 | [spacenote] => |
187 | [authstr] => |
188 | [theme] => t10 |
189 | [nocss] => 0 |
190 | [menunum] => 0 |
191 | [css] => |
192 | [privacy] => Array |
193 | ( |
194 | [view] => Array |
195 | ( |
196 | [index] => 0 |
197 | [profile] => 0 |
198 | [friend] => 0 |
199 | [wall] => 0 |
200 | [feed] => 0 |
201 | [doing] => 0 |
202 | [blog] => 0 |
203 | [album] => 0 |
204 | [share] => 0 |
205 | [mtag] => 0 |
206 | ) |
207 | |
208 | [feed] => Array |
209 | ( |
210 | [doing] => 1 |
211 | [blog] => 1 |
212 | [album] => 1 |
213 | [upload] => 1 |
214 | [share] => 1 |
215 | [thread] => 1 |
216 | [post] => 1 |
217 | [mtag] => 1 |
218 | [friend] => 1 |
219 | [comment] => 1 |
220 | [trace] => 1 |
221 | ) |
222 | |
223 | ) |
224 | |
225 | [friend] => |
226 | [feedfriend] => |
227 | [sendmail] => |
228 | [groupid] => 1 |
229 | [credit] => 0 |
230 | [username] => admin |
231 | [name] => Rerof |
232 | [namestatus] => 1 |
233 | [domain] => |
234 | [viewnum] => 0 |
235 | [notenum] => 0 |
236 | [friendnum] => 0 |
237 | [dateline] => 1245599521 |
238 | [updatetime] => 0 |
239 | [lastsearch] => 0 |
240 | [lastpost] => 0 |
241 | [lastlogin] => 1254831926 |
242 | [lastsend] => 0 |
243 | [attachsize] => 0 |
244 | [addsize] => 0 |
245 | [flag] => 1 |
246 | [newpm] => 0 |
247 | [avatar] => 0 |
248 | [ip] => 127000000 |
249 | [mood] => 0 |
250 | [self] => 1 |
251 | [friends] => Array |
252 | ( |
253 | ) |
254 | |
255 | ) |
256 | |
257 | [profield] => Array |
258 | ( |
259 | [1] => Array |
260 | ( |
261 | [fieldid] => 1 |
262 | [title] => 自由联盟 |
263 | [note] => |
264 | [formtype] => text |
265 | [inputnum] => 100 |
266 | [choice] => |
267 | [mtagminnum] => 0 |
268 | [manualmoderator] => 0 |
269 | [manualmember] => 1 |
270 | [displayorder] => 0 |
271 | ) |
272 | |
273 | [2] => Array |
274 | ( |
275 | [fieldid] => 2 |
276 | [title] => 地区联盟 |
277 | [note] => |
278 | [formtype] => text |
279 | [inputnum] => 100 |
280 | [choice] => |
281 | [mtagminnum] => 0 |
282 | [manualmoderator] => 0 |
283 | [manualmember] => 1 |
284 | [displayorder] => 0 |
285 | ) |
286 | |
287 | ) |
288 | |
289 | [usergroup] => Array |
290 | ( |
291 | |
292 | [1] => Array |
293 | ( |
294 | [gid] => 1 |
295 | [grouptitle] => 站点管理员 |
296 | [system] => -1 |
297 | [creditlower] => 0 |
298 | [maxfriendnum] => 0 |
299 | [maxattachsize] => 0 |
300 | [allowhtml] => 1 |
301 | [allowcomment] => 1 |
302 | [searchinterval] => 0 |
303 | [postinterval] => 0 |
304 | [allowblog] => 1 |
305 | [allowdoing] => 1 |
306 | [allowupload] => 1 |
307 | [allowshare] => 1 |
308 | [allowmtag] => 1 |
309 | [allowthread] => 1 |
310 | [allowpost] => 1 |
311 | [allowcss] => 1 |
312 | [allowpoke] => 1 |
313 | [allowfriend] => 1 |
314 | [allowtrace] => 1 |
315 | [edittrail] => 0 |
316 | [domainlength] => 1 |
317 | [closeignore] => 1 |
318 | [seccode] => 0 |
319 | [color] => red |
320 | [icon] => image/group/admin.gif |
321 | [manageconfig] => 1 |
322 | [managenetwork] => 1 |
323 | [manageprofilefield] => 1 |
324 | [manageprofield] => 1 |
325 | [manageusergroup] => 1 |
326 | [managefeed] => 1 |
327 | [manageshare] => 1 |
328 | [managedoing] => 1 |
329 | [manageblog] => 1 |
330 | [managetag] => 1 |
331 | [managetagtpl] => 0 |
332 | [managealbum] => 1 |
333 | [managecomment] => 1 |
334 | [managemtag] => 1 |
335 | [managethread] => 1 |
336 | [managespace] => 1 |
337 | [managecensor] => 1 |
338 | [managead] => 1 |
339 | [managesitefeed] => 1 |
340 | [managebackup] => 1 |
341 | [manageblock] => 1 |
342 | [managetemplate] => 1 |
343 | [managestat] => 1 |
344 | [managecache] => 1 |
345 | [managecredit] => 1 |
346 | [managecron] => 1 |
347 | [managename] => 1 |
348 | [manageapp] => 1 |
349 | [managetask] => 1 |
350 | [managereport] => 1 |
351 | ) |
352 | |
353 | [5] => Array |
354 | ( |
355 | [gid] => 5 |
356 | [grouptitle] => 普通会员 |
357 | [system] => 0 |
358 | [creditlower] => 0 |
359 | [maxfriendnum] => 100 |
360 | [maxattachsize] => 20971520 |
361 | [allowhtml] => 0 |
362 | [allowcomment] => 1 |
363 | [searchinterval] => 60 |
364 | [postinterval] => 60 |
365 | [allowblog] => 1 |
366 | [allowdoing] => 1 |
367 | [allowupload] => 1 |
368 | [allowshare] => 1 |
369 | [allowmtag] => 1 |
370 | [allowthread] => 1 |
371 | [allowpost] => 1 |
372 | [allowcss] => 0 |
373 | [allowpoke] => 1 |
374 | [allowfriend] => 1 |
375 | [allowtrace] => 1 |
376 | [edittrail] => 0 |
377 | [domainlength] => 0 |
378 | [closeignore] => 0 |
379 | [seccode] => 0 |
380 | [color] => |
381 | [icon] => |
382 | [manageconfig] => 0 |
383 | [managenetwork] => 0 |
384 | [manageprofilefield] => 0 |
385 | [manageprofield] => 0 |
386 | [manageusergroup] => 0 |
387 | [managefeed] => 0 |
388 | [manageshare] => 0 |
389 | [managedoing] => 0 |
390 | [manageblog] => 0 |
391 | [managetag] => 0 |
392 | [managetagtpl] => 0 |
393 | [managealbum] => 0 |
394 | [managecomment] => 0 |
395 | [managemtag] => 0 |
396 | [managethread] => 0 |
397 | [managespace] => 0 |
398 | [managecensor] => 0 |
399 | [managead] => 0 |
400 | [managesitefeed] => 0 |
401 | [managebackup] => 0 |
402 | [manageblock] => 0 |
403 | [managetemplate] => 0 |
404 | [managestat] => 0 |
405 | [managecache] => 0 |
406 | [managecredit] => 0 |
407 | [managecron] => 0 |
408 | [managename] => 0 |
409 | [manageapp] => 0 |
410 | [managetask] => 0 |
411 | [managereport] => 0 |
412 | [credithigher] => 99 |
413 | ) |
414 | |
415 | ) |
416 | |
417 | ) |
1 | $_SN: Array |
2 | ( |
3 | [1] => Rerof |
4 | ) |
在UCHome上增加一个功能,希望某些群组类别下只允许有群组管理的人才能新建群组,其他人无法新建这些类别的群组。只需修改模板中的cp_mtag.htm文件,将如下代码:
1 | <div class = "l_status" >1. <strong>请选择一个群组分类</strong></div> |
2 | <table><tr> |
3 | <!--{ eval $i =0;}--> |
4 | <!--{loop $fields $value }--> |
5 | <td><input type= "radio" id= "fieldid_$value[fieldid]" name= "fieldid" value= "$value[fieldid]" onclick= "fieldselect(this.value)" ><label for = "fieldid_$value[fieldid]" > $value [title]</label></td> |
6 | <!--{ if $i %3==2}--></tr><tr><!--{/ if }--> |
7 | <!--{ eval $i ++;}--> |
8 | <!--{/loop}--> |
9 | </tr></table> |
更改为:
01 | <div class = "l_status" >1. <strong>请选择一个群组分类</strong></div> |
02 | <table><tr> |
03 | <!--{ eval $i =0;}--> |
04 | <!--{loop $fields $value }--> |
05 | |
06 | <!--{ eval if (!( $_SGLOBAL [ 'usergroup' ][ $_SGLOBAL [ 'member' ][ 'groupid' ]][ 'manageprofield' ])){ /*判断当前用户是否有群组管理权限*/ }--> |
07 | <!--{ eval if (in_array( $value [fieldid], array (1,4,5,6))) continue ; /*过滤不允许普通用户创建的群组*/ }--> |
08 | <!--{ eval } }--> |
09 | |
10 | <td><input type= "radio" id= "fieldid_$value[fieldid]" name= "fieldid" value= "$value[fieldid]" onclick= "fieldselect(this.value)" ><label for = "fieldid_$value[fieldid]" > $value [title]</label></td> |
11 | <!--{ if $i %3==2}--></tr><tr><!--{/ if }--> |
12 | <!--{ eval $i ++;}--> |
13 | <!--{/loop}--> |
14 | </tr></table> |
简单说明一下:$_SGLOBAL['member']['groupid']返回当前用户的用户组编 号,$_SGLOBAL['usergroup'][用户组编号]['manageprofield']返回特定用户组是否有群组管理权限,结合起来判断 当前用户是否有群组管理权限。
效果就是当管理员登陆后,新建群组可选择所有分类。
管理员新建群组界面
而普通会员登录后,新建群组只能选个别分类。
普通会员新建群组界面
以上为个人实践的总结,如有不对之处,敬请指出!