Discuz教程网

[代码修改] Discuz X2 diy 增强模块 SQL调用

[复制链接]
authicon dly 发表于 2011-9-1 17:10:26 | 显示全部楼层 |阅读模式
查了很久才查到需要的 不过不全  

现在把X2的发出来

首先block_sql.php文件

大家先保存到 source\class\block\html目录下
  1. <?php
  2. /**
  3. *
  4. *
  5. *
  6. */
  7. if(!defined('IN_DISCUZ')) {
  8. exit('Access Denied');
  9. }
  10. require_once libfile('commonblock_html', 'class/block/html');
  11. class block_sql extends commonblock_html {
  12. function block_sql() {}
  13. function name() {
  14. return 'SQL脚本';
  15. }
  16. function getsetting() {
  17. global $_G;
  18. $settings = array(
  19. 'sql' => array(
  20. 'title' => 'SQL语句',
  21. 'type' => 'textarea',
  22. 'default' => 'SELECT *
  23. FROM `pre_forum_forum`'
  24. ),

  25. /*'fieldlist' => array(
  26. 'title' => '可引用字段',
  27. 'type' => 'textarea',
  28. 'default' => '{$tablepre} '
  29. ),*/

  30. 'template' => array(
  31. 'title' => 'HTML模板',
  32. 'type' => 'textarea',
  33. 'default' => '[node]{name}<BR>[/node]'
  34. ),

  35. 'start' => array(
  36. 'title' => '起始数据行数',
  37. 'type' => 'text',
  38. 'default' => 0
  39. ),
  40. 'limit' => array(
  41. 'title' => '显示数据条数',
  42. 'type' => 'text',
  43. 'default' => 5
  44. )
  45. );
  46. return $settings;
  47. }
  48. function getdata($style, $parameter) {
  49. require_once libfile('function/home');
  50. /// $return = getstr($parameter['content'], '', 1, 0, 1, 0, 1);
  51. ///
  52. global $_G;
  53. $tablepre = $_G['config']['db']['1']['tablepre'];
  54. $sql = !empty($parameter['sql']) ? ($parameter['sql']) : '';
  55. $start = !empty($parameter['start']) ? intval($parameter['start']) : 0;
  56. $limit = !empty($parameter['limit']) ? intval($parameter['limit']) : 5;

  57. $writedata = '';
  58. if ($sql != '')
  59. {
  60. $searchs1 = $replaces1 = array();
  61. $searchs1[] = '{$tablepre}';
  62. $replaces1[] = $tablepre;//'`'.$dbname.'`.'.$tablepre;
  63. $sql = str_replace($searchs1, $replaces1, stripslashes($sql));
  64. $sql = ltrim(strtolower($sql));
  65. $i = strpos($sql , 'select');
  66. if ($i != 0){
  67. $writedata = '只能定义SELECT语句';
  68. return array('html' => $writedata, 'data' => null);
  69. }
  70. $sqldata = $sql.' limit '.$start.','.$limit.';';
  71. $query = DB::query($sqldata);

  72. $writedata = '';
  73. $requesttemplatebody = '';
  74. $requesttemplate = stripslashes($parameter['template']);
  75. if(preg_match("/\[node\](.+?)\[\/node\]/is", $requesttemplate, $node)) {
  76. $requesttemplatebody = $requesttemplate;
  77. $requesttemplate = $node[1];
  78. }
  79. while($thread = DB::fetch($query)) {
  80. $searchs = $replaces = array();
  81. foreach(array_keys($thread) as $key) {
  82. $searchs[] = '{'.$key.'}';
  83. $replaces[] = htmlspecialchars($thread[$key]);
  84. $searchs[] = '{rawurlencode('.$key.')}';
  85. $replaces[] = rawurlencode($thread[$key]);
  86. }
  87. $writedata .= str_replace($searchs, $replaces, $requesttemplate);
  88. }
  89. if ($requesttemplatebody){
  90. $oldwritedata = $writedata;
  91. $writedata = str_replace($node[0], $oldwritedata, $requesttemplatebody);
  92. }
  93. }else{
  94. $writedata = '没有定义SQL';
  95. }
  96. ///
  97. return array('html' => $writedata, 'data' => null);
  98. }
  99. }
  100. ?>
复制代码

然后在 source/language/ 找到 lang_blockclass.php文件 在 'blockclass_html_script_category' => '分类信息', 下面加上'sql' => 'SQL脚本', 保存,开始实验!




上一篇:挂机自动采集,针对cx采集模拟点击
下一篇:站长工具-SEO综合查询
authicon exgolddizzy 发表于 2014-11-20 15:20:12 | 显示全部楼层
bucuoockclass.php文件 在 'blockclass_html_script_category' =
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

1314学习网 ( 浙ICP备10214163号 )

GMT+8, 2025-5-2 18:54

Powered by Discuz! X3.4

© 2001-2013 Comsenz Inc.

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