推荐使用,
$val) { $string[$key] = dhtmlspecialchars($val, $flags); } } else { if($flags === null) { $string = str_replace(array('&', '"', '<', '>'), array('&', '"', '<', '>'), $string); if(strpos($string, '&#') !== false) { $string = preg_replace('/&((#(\d{3,5}|x[a-fa-f0-9]{4}));)/', '&\\1', $string); } } else { $string = htmlspecialchars($string, $flags); } } return $string; }; } if(!defined('dstripslashes')){ function dstripslashes($string) { if(empty($string)) return $string; if(is_array($string)) { foreach($string as $key => $val) { $string[$key] = dstripslashes($val); } } else { $string = stripslashes($string); } return $string; } } if(!defined('libfile')){ function libfile($libname, $folder = '') { $libpath = '/source/'.$folder; if(strstr($libname, '/')) { list($pre, $name) = explode('/', $libname); $path = "{$libpath}/{$pre}/{$pre}_{$name}"; } else { $path = "{$libpath}/{$libname}"; } return preg_match('/^[\w\d\/_] $/i', $path) ? realpath($globals['discuz_root'].$path.'.php') : false; } } } /** * 示例:discuz发帖 * 您可参考代码自行开发discuz的更多功能 * 您可以使用 thinkphp5的函数 */ namespace plugin\release\cms{ class discuzdemoskycaiji extends basecms{ public $siteurl;//discuz网站网址 public function init_extend(){ //获取站点url $siteurl=$this->db()->table('__common_setting__')->where("`skey`='siteurl'")->find(); $this->siteurl=rtrim($siteurl['svalue'],'\\\/').'/'; //调用discuz函数 define('in_discuz',1); $globals['discuz_root']=$this->cmspath.'/'; include_once $this->cmspath.'/source/function/function_editor.php'; } //参数 public $_params = array ( 'forumid' => array ( 'name' => '版块id', 'require' => 1, 'tag' => 'select', 'option' => 'function:param_option_forumid', ), 'author' => array ( 'name' => '用户名或id', 'require' => 1, 'tag' => 'text', ), 'title' => array ( 'name' => '帖子标题', 'require' => 1, 'tag' => 'select', 'option' => 'function:param_option_fields', ), 'content' => array ( 'name' => '帖子内容', 'require' => 1, 'tag' => 'select', 'option' => 'function:param_option_fields', ), 'typeid' => array ( 'name' => '版块分类id', 'require' => 0, 'tag' => 'number', ), ); /* * 导入数据 * 必须以数组形式返回: * id(必填)表示入库返回的自增id或状态 * target(可选)记录入库的数据位置(发布的网址等) * desc(可选)记录入库的数据位置附加信息 * error(可选)记录入库失败的错误信息 * 入库的信息可在“已采集数据”中查看 * return array('id'=>0,'target'=>'','desc'=>'','error'=>''); */ public function runimport($params){ //判断用户存在 $userdata=$this->db()->table('__common_member__')->where('username',$params['author'])->whereor('uid',$params['author'])->find(); if(empty($userdata)){ return array('id'=>0,'error'=>$params['author'].'用户不存在');//返回错误信息 } //添加新主题 $newthread=array( 'fid'=>$params['forumid'], 'author'=>$userdata['username'], 'authorid'=>$userdata['uid'], 'subject'=>$params['title'], 'dateline'=>time(), 'lastpost'=>time(), 'lastposter'=>$userdata['username'], 'typeid'=>$params['typeid'], ); $target='';//目标网址 $error='';//错误信息 $threadid=$this->db()->table('__forum_thread__')->insert($newthread,false,true);//返回的id if($threadid>0){ $postid=$this->db()->table('__forum_post_tableid__')->insert(array('pid'=>0),false,true);//获取pid if($postid>0){ //添加帖子 $newpost=array( 'pid'=>$postid, 'fid'=>$params['forumid'], 'tid'=>$threadid, 'first'=>1, 'author'=>$userdata['username'], 'authorid'=>$userdata['uid'], 'subject'=>$params['title'], 'dateline'=>time(), 'message'=>html2bbcode($params['content']),//html转成discuz格式 'position'=>1, ); $this->db()->table('__forum_post__')->insert($newpost); $forumdata=$this->db()->table('__forum_forum__')->where('fid',$params['forumid'])->find(); $this->db()->table('__forum_forum__')->where('fid',$params['forumid'])->update(array( 'threads'=>$forumdata['threads'] 1, 'posts'=>$forumdata['posts'] 1, 'todayposts'=>$forumdata['todayposts'] 1, )); $target=$this->siteurl.'forum.php?mod=viewthread&tid='.$threadid; }else{ $error='添加帖子失败'; } }else{ $error='添加主题失败'; } return array('id'=>$threadid,'target'=>$target,'error'=>$error); } /* * 自定义方法:版块选项 * 必须返回键值对形式的数组 */ public function param_option_forumid(){ $forumdb=$this->db()->table('__forum_forum__')->where("`status`=1 and `type`<>'group'")->select(); //读取论坛版块 $forumlist=array(); foreach ($forumdb as $forum){ $forumlist[$forum['fid']]=auto_convert2utf8($forum['name']);//自动转码 } return $forumlist; } } } ?>