discuz3.1添加diy模板

来源:互联网 发布:交换机端口有ip地址吗 编辑:程序博客网 时间:2024/05/18 00:41


注意:1文档编码用editplus改为utf8或者你的论坛编码否则会乱码
2类名和文件名要一致否则无法显示 block_XX.php


代表各框




存着 中文文字定义





、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、以下内容为转载

在论坛上好几天,都没有解决这个问题。。
最后是在这个帖子找到的灵感。。。

PS:此教程只适合编程人员观看,不会PHP的请跳过。谢谢

http://ggmmchou.blog.163.com/blog/static/59333149201142075017844/

具体如下:
打开文件夹source\class\block\
然后在此目录新建一个文件夹 名称自己写。必须英文的.例如 mdir
然后在source\class\block\mdir里建立一个文件
文件名:blockclass.php 这个不能变,必须是这个名
编辑blockclass.php
写入以下内容:
  1. <?php
  2.         $blockclass = array(
  3.                 'name' => '我的小小模块', //为此目录定义一个名字
  4.         );
  5. ?>
复制代码
当当当。重点来了。。
新建一个.php文件  文件名必须以block_开头 例如block_mdir.php
然后写入以下内容:
  1. <?php


  2. if(!defined('IN_DISCUZ')) {
  3.         exit('Access Denied');
  4. }


  5. class block_prices {
  6.         function block_prices(){
  7.                 
  8.                 }

  9.         /**
  10.          * 必须!
  11.          * 返回本数据调用类的显示名称(显示在创建模块时选择“模块数据”的下拉列表里)
  12.          * @return 
  13.          */
  14.         function name() {
  15.                 return '示例数据类';
  16.         }

  17.         /**
  18.          * 必须!
  19.          * 返回一个数组: 第一个值为本数据类所在的模块分类;第二个值为模块分类显示的名称(显示在 DIY 模块面板)
  20.          * @return 
  21.          */
  22.         function blockclass() {
  23.                 return array('sample', '示例分类');
  24.         }

  25.         /**
  26.          * 必须!
  27.          * 返回数据类中可供“模块样式”使用的字段。
  28.          * 格式见示例:
  29.          * name 为该字段的显示名称
  30.          * formtype 决定编辑单条数据时该字段的显示方式: 类型有: text, textarea, date, title, summary, pic; 详见 portalcp_block.htm 模板(搜 $field[formtype] )
  31.          * datatype 决定该字段的数据展示,类型有: string, int, date, title, summary, pic; 详见 function_block.php 中 block_template 函数
  32.          * @return 
  33.          */
  34.         function fields() {
  35.                 return array(
  36.                         'field1' => array('name' => '示例字段1', 'formtype' => 'text', 'datatype' => 'string'),
  37.                         'field2' => array('name' => '示例字段2', 'formtype' => 'title', 'datatype' => 'title'),
  38.                 );
  39.         }

  40.         /**
  41.          * 必须!
  42.          * 返回使用本数据类调用数据时的设置项
  43.          * 格式见示例:
  44.          * title 为显示的名称
  45.          * type 为表单类型, 有: text, password, number, textarea, radio, select, mselect, mradio, mcheckbox, calendar; 详见 function_block.php 中 block_makeform() 函数
  46.          * @return 
  47.          */
  48.         function getsetting() {
  49.                 return array(
  50.                         'param1' => array(
  51.                                 'title' => '数据调用参数1',
  52.                                 'type' => 'text',
  53.                                 'default' => ''
  54.                         ),
  55.                         'param2' => array(
  56.                                 'title' => '数据调用参数2',
  57.                                 'type' => 'mcheckbox',
  58.                                 'value' => array(
  59.                                         array('1', '选项1'),
  60.                                         array('2', '选项2'),
  61.                                 ),
  62.                                 'default' => '1'
  63.                         ),
  64.                 );
  65.         }

  66.         /**
  67.          * 必须!
  68.          * 处理设置参数,返回数据
  69.          * 返回数据有两种:
  70.          * 一种是返回 html,放到模块 summary 字段,直接显示; 返回格式为: array('html'=>'返回内容', 'data'=>null)
  71.          * 一种是返回 data,通过模块样式渲染后展示,返回的数据应该包含 fields() 函数中指定的所有字段; 返回格式为: array('html'=>'', 'data'=>array(array('title'=>'value1'), array('title'=>'value2')))
  72.          * 特别的:
  73.          * parameter 参数包含 getsetting() 提交后的内容; 并附加了字段:
  74.          * items ,为用户指定显示的模块数据条数;
  75.          * bannedids ,为用户选择屏蔽某数据时记录在模块中的该数据 id。 应该在获取数据时屏蔽该数据;
  76.          *
  77.          * 如果返回的数据给 data, 那么应该包含 fields() 函数指定的所有字段。并附加以下字段:
  78.          * id 标志该数据的 id,如果用户屏蔽某数据时,会将该数据的 id 添加到 parameter[bannedids] 里
  79.          * idtype 标志该数据的 idtype
  80.          *
  81.          * @param  $style 模块样式(见 common_block_style 表)。 可以根据模块样式中用到的字段来选择性的获取/不获取某些数据
  82.          * @param  $parameter 用户对 getsetting() 给出的表单提交后的内容。
  83.          * @return 
  84.          */
  85.         function getdata($style, $parameter) {

  86.                 // 返回summary
  87.                 return array('html' => '这是一个演示模块数据类', 'data' => null);

  88.                 // 返回数据
  89.                 // 需要注意: 除 id,idtype, title, url, pic, picflag, summary 几个字段外,其它字段需要放到 fields 数组里。 可以参考系统内置模块类 source/class/block/block_thread.php
  90.                 return array('html'=>'', 'data' => array(
  91.                         array(
  92.                                 'id' => '1',
  93.                                 'idtype' => 'sampleid',
  94.                                 'title' => 'title1',
  95.                                 'url' => '#',
  96.                                 'pic' => 'nophoto.gif',
  97.                                 'picflag' => '1',
  98.                                 'summary' => '',
  99.                                 'fields' => array(
  100.                                         'field1' => 'value1'
  101.                                 )
  102.                         )
  103.                 ));
  104.         }

  105. }

  106. ?>
复制代码
请自行编辑以上内容。以上是你最终要处理的事情了。  
然后在:后台——工具——更新缓存  只选择DIY模块分类缓存   然后 点更新  ..去前台看看。有无你亲爱的小模块。。

什么??看不懂?? sorry! 那不是本帖的内容,请去baidusearch 找PHP教程了。 end.





0 0