Discuz教程网

[插件制作] Discuz X2.5特殊主题开发:发帖处不显示特殊主题?

  [复制链接]
authicon dly 发表于 2012-10-13 14:51:00 | 显示全部楼层 |阅读模式
大约半年多没碰康盛的东西了,年前在DZ7.2开发了几个插件,我们这边的开发任务就停止了,现在又有项目需要做dzx2.5的开发,于是开始搞特殊主题。
尼玛我参照开发手册
游客,如果您要查看本帖隐藏内容请回复
写的开始开发,结果就是在论坛的设置处可以看到自定义的特殊主题,发帖的时候却没有这个选项。蛋疼。断断续续折腾了两天,蛋疼,直接翻DZ相关源码,终于找到问题所在:尼玛。。。弄个特殊主题光在论坛设置里面设置还不够,还特么要在用户组给用户使用这个特殊主题的权限。。。
0×1这特么是怎么个情况?
断断续续两天时间,太纠结了。找了个不靠谱的人问了问,毛也没给解决,这些事还是得自力更生。反复测试了很久也没找到问题,索性直接翻DZ相关源码。
入口看URL:http://dzx/forum.php?mod=post&action=newthread&specialextra=dabing&fid=2&cedit=yes&extra=,这里以随便找了个安装了特殊主题的插件为例。
首先看forum.php,最后一句required了mod,如下
  1. require DISCUZ_ROOT.'./source/module/forum/forum_'.$mod.'.php';
复制代码
mod=post,于是找source/module/forum/forum_post.php。
连个注释也没有,这特么蛋疼,在看action=newthread,直接搜newthread。
newthread.png
在347行找到了newthread的具体处理流程。首先加载缓存处理数据什么的,然后用了libfile函数。
  1. /**
  2. *
  3. * @param string $libname lib的名字,依靠是否有/来判断引用路径
  4. * @param string $folder 指定引用的二级目录,默认没有
  5. * @return Ambi**s <boolean, string> 如果路径正确则返回包含文件位置,否则返回false
  6. */
  7. function libfile($libname, $folder = '') {
  8. $libpath = '/source/'.$folder;
  9. //处理引用的位置
  10. if(strstr($libname, '/')) {
  11. list($pre, $name) = explode('/', $libname);
  12. $path = "{$libpath}/{$pre}/{$pre}_{$name}";
  13. } else {
  14. $path = "{$libpath}/{$libname}";
  15. }
  16. //判断是否是合法引用
  17. return preg_match('/^[\w\d\/_]+$/i', $path) ? realpath(DISCUZ_ROOT.$path.'.php') : false;
  18. }
复制代码
根据提交的参数libfile(‘post/newthread’, ‘include’);,打开source/include/post/post_newthread.php。
  1. ....
  2. //从第84行开始
  3. } elseif($specialextra) {
  4. //开始调用特殊主题
  5. $threadpluginclass = null;
  6. if(isset($_G['setting']['threadplugins'][$specialextra]['module'])) {
  7. //module是特殊主题的类名,就是在模块-特殊主题-名字的地方填写的,这里是preview
  8. $threadpluginfile = DISCUZ_ROOT.'./source/plugin/'.$_G['setting']['threadplugins'][$specialextra]['module'].'.class.php';
  9. //可以直接echo出来看看:F:\PHP_Work\DZX\./source/plugin/dabing/preview.class.php
  10. echo DISCUZ_ROOT.'./source/plugin/'.$_G['setting']['threadplugins'][$specialextra]['module'].'.class.php';
  11. //开始引用
  12. if(file_exists($threadpluginfile)) {
  13. @include_once $threadpluginfile;
  14. $classname = 'threadplugin_'.$specialextra;//$specialextra这个?应该返回去搜索了。这里是插件的ID
  15. //在文件存在,类存在,方法存在的情况下,就开始调用该类的newthread方法了。
  16. if(class_exists($classname) && method_exists($threadpluginclass = new $classname, 'newthread')) {
  17. $threadplughtml = $threadpluginclass->newthread($_G['fid']);
  18. $buttontext = lang('plugin/'.$specialextra, $threadpluginclass->buttontext);
  19. $iconfile = $threadpluginclass->iconfile;
  20. $ic**flip = array_flip($_G['cache']['ic**']);
  21. $thread['iconid'] = $ic**flip[$iconfile];
  22. }
  23. }
  24. }
复制代码
顿时觉得特殊主题的逻辑和实现其实超级简单,呵呵。
然后切换成我们的主题,发现就是不显示,哪怕你手动指定了specialextra也会跳转到发表普通帖子的页面。
于是回到forum_post.php,肯定对specialextra参数进行了处理。
在第236行让我吃了一惊,亲,听说过圈复杂度么。。。。莫不是发行版本是经过压缩优化过的?尼玛啊。。
untitled5.bmp
  1. if($specialextra && $_G['group']['allowpost'] && $_G['setting']['threadplugins'] &&
  2. (!array_key_exists($specialextra, $_G['setting']['threadplugins']) ||
  3. !@in_array($specialextra, is_array($_G['forum']['threadplugin']) ? $_G['forum']['threadplugin'] : dunserialize($_G['forum']['threadplugin'])) ||
  4. !@in_array($specialextra, $_G['group']['allowthreadplugin']))) {
  5. $specialextra = '';
  6. }
复制代码
$specialextra:dabing,非空值,true。
$_G['group']['allowpost']:1,看名字应该是组权限允许发帖),true。
$_G['setting']['threadplugins']:Array,非空,打印出来是所有的特殊主题的数组,表明存在特殊主题,true。
!array_key_exists($specialextra, $_G['setting']['threadplugins']):判断URL输入的特殊主题ID是否真的存在,存在取反,为false。
三目运算符:is_array($_G['forum']['threadplugin']) ? $_G['forum']['threadplugin'] : dunserialize($_G['forum']['threadplugin'])) :判断该论坛的允许使用的特殊主题列表的保存形式,如果是数组则不变,如果是序列化果断反序列化之,返回数组。这里本来就是数组,无所谓。
!@in_array($specialextra, $_G['forum']['threadplugin']):这个特殊主题是否在这个论坛中允许使用,这个在论坛的帖子相关设置过,存在取反为false。
!@in_array($specialextra, $_G['group']['allowthreadplugin']):问题出现了,尼玛这个 $_G['group']['allowthreadplugin']没有刚才自己写的插件的ID,看名字应该是组允许使用的特殊主题列表,这里是false,取反为true。
则以上为
  1. if(true && true && true && (false || false || true)) {
  2. $specialextra = '';
  3. }
复制代码
最终为true,于是$specialextra被赋空值了。
根据名字猜测是用户组/管理组权限问题,马上翻后台去看看,果然有这个选项。。。蛋疼。。。看来做DZ二次开发,要同时配备开发手册和使用手册。。。
到此为止找到原因,突然觉得特殊主题的逻辑好简单:)是否可以山寨一个呢亲?
呵呵,问题很好解决,关键是又复习了~

作者:疯狂的大饼

Discuz!X2.5特殊主题简单开发教程





上一篇:Discuz BBS(论坛)linux迁移方法 .
下一篇:Discuz X2.5特殊主题简单开发教程
authicon SHoTDoG 发表于 2012-10-25 19:32:33 | 显示全部楼层
强烈支持楼主ing……
authicon 阿勋 发表于 2012-10-30 17:34:50 | 显示全部楼层
真是被感动的痛哭流涕……
authicon 阿勋 发表于 2012-10-30 17:35:28 | 显示全部楼层
真是被感动的痛哭流涕……
authicon Wesley 发表于 2012-11-23 10:41:43 | 显示全部楼层
楼主加油,我们都看好你哦。
authicon mooncake 发表于 2013-1-12 16:07:56 | 显示全部楼层
学习一下,想做个商品的
authicon t5442107 发表于 2013-6-4 10:58:38 | 显示全部楼层
强烈支持楼主ing……
authicon 北海家 发表于 2013-6-6 18:00:36 | 显示全部楼层
认真学习,做好网站
authicon 蓝色忧郁 发表于 2013-6-7 11:22:09 | 显示全部楼层
强烈支持楼主ing……
authicon 得了 发表于 2013-8-8 14:46:04 | 显示全部楼层
强烈支持楼主ing……
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

1314学习网 ( 浙ICP备10214163号 )

GMT+8, 2024-5-2 09:47

Powered by Discuz! X3.4

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表