discuz论坛门户资讯入库接口【原创】

最近想打造一个社区门户站点,所以写了这个入库接口,可以对接数据入库。

<?php
/*
 * Discuz x3.2 门户免登陆发布接口
 * 2018-08-10
 * Copyright 68xi.Ltd
 * Author: 68xi
 *
 * 获取栏目列表: /jiekou_portal.php?get_cat=true&password=PWD
 *
 * 发布参数: (说明: 参数前面带 "*" 的为必填参数)
 *     *uid: 发布用户ID, 可单个, 也可多个, 多个发布用户ID之间请使用逗号(,)分割 (当填写多个用户ID, 接口会随机使用其中一个, 发布用户ID必须是系统已存在的用户ID)
 *     *catid: 栏目ID
 *     *title: 标题
 *     *content: 内容
 *     dateline: 发布时间, 默认当前时间, 格式: 2013-11-15 15:30:11
 *     summary: 内容摘要, 此参数为空时, 将使用discuz内部提取正文方式来获取摘要
 *     author: 原作者
 *     from: 来源
 *     fromurl: 来源网址
 *     viewnum: 文章阅读数字, 默认1
 *     setconver: 提取内容里的第一张图片为封面, 无论是本地图片还是网络图片, 都会尝试提取
*/

header(‘Content-type:text/html;charset=UTF-8‘);

//接口密码, 请保持与采集器上设置的密码一致, 为了网站安全, 强烈建议修改此值!!!
define(‘PASSWORD‘, ‘123456‘);

//调试模式, 上线后务必设置成false!!!
define(‘DEBUG‘, false);

//输出信息并退出
function showMsg($msg) {
	echo $msg;
	exit;
}

//打印变量信息 - 用于DEBUG
function dd($data, $exit = false) {
	echo ‘<pre>‘;
	print_r($data);
	echo ‘</pre>‘;
	if($exit) exit;
}

//检测接口密码
if(!isset($_GET[‘password‘]) || $_GET[‘password‘] != PASSWORD) showMsg(‘接口密码不正确!‘);

/******************* discuz头文件 开始 ********************/

#/portal.php
define(‘APPTYPEID‘, 4);
define(‘CURSCRIPT‘, ‘portal‘);

require ‘./source/class/class_core.php‘;
$discuz = C::app();

$cachelist = array(‘userapp‘, ‘portalcategory‘, ‘diytemplatenameportal‘);
$discuz->cachelist = $cachelist;
$discuz->init();

require DISCUZ_ROOT.‘./source/function/function_home.php‘;
require DISCUZ_ROOT.‘./source/function/function_portal.php‘;

define(‘CURMODULE‘, ‘portalcp‘);

#/souce/module/portal/portalportalcp.php
$ac = ‘article‘;

require_once libfile(‘function/portalcp‘);

#/source/include/portalcp/portalcp_article.php

/******************* discuz头文件 结束 ********************/

$app = new App();

class App {
	protected $global; //equal $_G
	protected $uid; //发布用户ID

	//构造函数
	public function __construct() {
		global $_G;
		$this->global = &$_G;

		//当前时间
		define(‘DATE_TIME‘, date(‘Y-m-d H:i:s‘));

		if(isset($_GET[‘get_cat‘]) && $_GET[‘get_cat‘] == ‘true‘) {
			$this->get_cat(); //获取栏目
		} else {
			$this->publish_content(); //发布内容
		}
	}

	//获取栏目
	protected function get_cat() {
		$cat = $this->get_cat_list();
		if(empty($cat)) showMsg(‘当前网站栏目为空, 请添加门户栏目后再重试‘);

		$catStr = ‘‘;
		foreach($cat as $key => $value) {
			$catStr .= ‘<option value="‘. $value[‘catid‘] .‘">‘. $value[‘catname‘] .‘</option>‘;
		}
		$catStr = ‘<select>‘. $catStr .‘</select>‘;
		showMsg($catStr);
	}

	//获取栏目列表
	protected function get_cat_list() {
		//优化提示: 如果您网站的门户栏目在发布数据期间不会变动, 可以注释下面一行代码, 来加速接口执行速度
		loadcache(‘portalcategory‘);
		return $this->global[‘cache‘][‘portalcategory‘];
	}

	//设置发布用户ID
	private function set_uid() {
		if(empty($_POST[‘uid‘])) showMsg(‘发布用户ID不能为空‘);
		$uidstr = str_replace(‘ ‘, ‘‘, $_POST[‘uid‘]);
		if(strpos($uidstr, ‘,‘)) { //多发布用户ID
			$uid_list = explode(‘,‘, $uidstr);
			shuffle($uid_list);
			$uid = intval(array_shift($uid_list));
		} else { //单发布用户ID
			$uid = intval($uidstr);
		}

		if($uid == 0) showMsg(‘发布用户ID格式不正确‘);

		$info = C::t(‘common_member‘)->fetch($uid);
		if(empty($info)) showMsg(‘不存在该用户 (uid: ‘. $uid .‘)‘);

		$this->uid = $uid;

		$this->global[‘uid‘] = $uid;
		$this->global[‘member‘][‘uid‘] = $uid;
		$this->global[‘username‘] = $info[‘username‘];
		$this->global[‘session‘][‘uid‘] = $uid;

		//绕过discuz权限检测
		$this->global[‘group‘][‘allowmanagearticle‘] = true;
		$this->global[‘group‘][‘allowpostarticlemod‘] = true;
	}

	//将一些POST参数赋值至GET中, 因为discuz是通过$_GET来获取这些参数
	private function post2get() {
		foreach(array(‘author‘, ‘url‘, ‘from‘, ‘fromurl‘, ‘dateline‘, ‘highlight_style‘) as $key) {
			$_GET[$key] = isset($_POST[$key]) && $_POST[$key] ? $_POST[$key] : ‘‘;
		}
	}

	//发布内容前的初始化
	private function init() {
		//构造以下POST参数仅用于程序不抛错误提示
		$_POST[‘id‘] = ‘‘;
		$_POST[‘url‘] = ‘‘;
		$_POST[‘raids‘] = ‘‘; //相关文章ID
		$_POST[‘tag‘] = ‘‘; //聚合标签
		$_POST[‘pagetitle‘] = ‘‘;
		$_POST[‘htmlname‘] = ‘‘;
		$_POST[‘highlight_style‘] = ‘‘;
		$_POST[‘pagetitle‘] = ‘‘;
		$_POST[‘attach_ids‘] = ‘‘;
		$_POST[‘highlight_style‘] = array(
			‘#000‘,
			0,
			0,
			0,
		);

		//设置文章阅读数
		$_POST[‘viewnum‘] = isset($_POST[‘viewnum‘]) && $_POST[‘viewnum‘] ? intval($_POST[‘viewnum‘]) : 1;
	}

	//处理上传图片
	private function process_attach() {
		global $_G;

		if($_G[‘uid‘]) {
			$_G[‘member‘] = getuserbyuid($_G[‘uid‘]);
		}
		$_G[‘groupid‘] = $_G[‘member‘][‘groupid‘];
		loadcache(‘usergroup_‘.$_G[‘member‘][‘groupid‘]);
		$_G[‘group‘] = $_G[‘cache‘][‘usergroup_‘.$_G[‘member‘][‘groupid‘]];

		$aid = 0;
		$catid = intval($_POST[‘catid‘]);

		$msg = ‘‘;
		$errorcode = 0;
		require_once libfile(‘function/portalcp‘);
		if($aid) {
			$article = C::t(‘portal_article_title‘)->fetch($aid);
			if(!$article) {
				$errorcode = 1;
			}

			if(check_articleperm($catid, $aid, $article, false, true) !== true) {
				$errorcode = 2;
			}

		} else {
			if(0 && check_articleperm($catid, $aid, null, false, true) !== true) {
				$errorcode = 3;
			}
		}

		$upload = new discuz_upload();

		$_FILES["Filedata"][‘name‘] = addslashes(diconv(urldecode($_FILES["Filedata"][‘name‘]), ‘UTF-8‘));
		$upload->init($_FILES[‘Filedata‘], ‘portal‘);
		$attach = $upload->attach;
		if(!$upload->error()) {
			$upload->save();
		}
		if($upload->error()) {
			$errorcode = 4;
		}

		if(!$errorcode) {
			if($attach[‘isimage‘] && empty($_G[‘setting‘][‘portalarticleimgthumbclosed‘])) {
				require_once libfile(‘class/image‘);
				$image = new image();
				$thumbimgwidth = $_G[‘setting‘][‘portalarticleimgthumbwidth‘] ? $_G[‘setting‘][‘portalarticleimgthumbwidth‘] : 300;
				$thumbimgheight = $_G[‘setting‘][‘portalarticleimgthumbheight‘] ? $_G[‘setting‘][‘portalarticleimgthumbheight‘] : 300;
				$attach[‘thumb‘] = $image->Thumb($attach[‘target‘], ‘‘, $thumbimgwidth, $thumbimgheight, 2);
				$image->Watermark($attach[‘target‘], ‘‘, ‘portal‘);
			}

			if(0 && getglobal(‘setting/ftp/on‘) && ((!$_G[‘setting‘][‘ftp‘][‘allowedexts‘] && !$_G[‘setting‘][‘ftp‘][‘disallowedexts‘]) || ($_G[‘setting‘][‘ftp‘][‘allowedexts‘] && in_array($attach[‘ext‘], $_G[‘setting‘][‘ftp‘][‘allowedexts‘])) || ($_G[‘setting‘][‘ftp‘][‘disallowedexts‘] && !in_array($attach[‘ext‘], $_G[‘setting‘][‘ftp‘][‘disallowedexts‘]))) && (!$_G[‘setting‘][‘ftp‘][‘minsize‘] || $attach[‘size‘] >= $_G[‘setting‘][‘ftp‘][‘minsize‘] * 1024)) {
				if(ftpcmd(‘upload‘, ‘portal/‘.$attach[‘attachment‘]) && (!$attach[‘thumb‘] || ftpcmd(‘upload‘, ‘portal/‘.getimgthumbname($attach[‘attachment‘])))) {
					@unlink($_G[‘setting‘][‘attachdir‘].‘/portal/‘.$attach[‘attachment‘]);
					@unlink($_G[‘setting‘][‘attachdir‘].‘/portal/‘.getimgthumbname($attach[‘attachment‘]));
					$attach[‘remote‘] = 1;
				} else {
					if(getglobal(‘setting/ftp/mirror‘)) {
						@unlink($attach[‘target‘]);
						@unlink(getimgthumbname($attach[‘target‘]));
						$errorcode = 5;
					}
				}
			}

			$setarr = array(
				‘uid‘ => $_G[‘uid‘],
				‘filename‘ => $attach[‘name‘],
				‘attachment‘ => $attach[‘attachment‘],
				‘filesize‘ => $attach[‘size‘],
				‘isimage‘ => $attach[‘isimage‘],
				‘thumb‘ => $attach[‘thumb‘],
				‘remote‘ => $attach[‘remote‘],
				‘filetype‘ => $attach[‘extension‘],
				‘dateline‘ => $_G[‘timestamp‘],
				‘aid‘ => $aid
			);
			$setarr[‘attachid‘] = C::t(‘portal_attachment‘)->insert($setarr, true);
			if($attach[‘isimage‘]) {
				require_once libfile(‘function/home‘);
				$smallimg = pic_get($attach[‘attachment‘], ‘portal‘, $attach[‘thumb‘], $attach[‘remote‘]);
				$bigimg = pic_get($attach[‘attachment‘], ‘portal‘, 0, $attach[‘remote‘]);
				$coverstr = addslashes(serialize(array(‘pic‘=>‘portal/‘.$attach[‘attachment‘], ‘thumb‘=>$attach[‘thumb‘], ‘remote‘=>$attach[‘remote‘])));
				$returnstr = "{\"aid\":$setarr[attachid], \"isimage\":$attach[isimage], \"smallimg\":\"$smallimg\", \"bigimg\":\"$bigimg\", \"errorcode\":$errorcode, \"cover\":\"$coverstr\"}";
				return json_decode($returnstr, true);
				exit();
			} else {
				$fileurl = ‘portal.php?mod=attachment&id=‘.$attach[‘attachid‘];
				echo "{\"aid\":$setarr[attachid], \"isimage\":$attach[isimage], \"file\":\"$fileurl\", \"errorcode\":$errorcode}";
				exit();
			}
		} else {
			echo "{\"aid\":0, \"errorcode\":$errorcode}";
		}
	}

	//获取网络图片, 用于封面图片
	private function downloadremotefile($imageurl) {
		global $_G;
		$aid = 0;

		$upload = new discuz_upload();

		$attach[‘ext‘] = $upload->fileext($imageurl);
		if(!$upload->is_image_ext($attach[‘ext‘])) return;

		$content = dfsockopen($imageurl);

		if(empty($content)) continue;
		$temp = explode(‘/‘, $imageurl);

		$attach[‘name‘] =  trim($temp[count($temp)-1]);
		$attach[‘thumb‘] = ‘‘;

		$attach[‘isimage‘] = $upload -> is_image_ext($attach[‘ext‘]);
		$attach[‘extension‘] = $upload -> get_target_extension($attach[‘ext‘]);
		$attach[‘attachdir‘] = $upload -> get_target_dir(‘portal‘);
		$attach[‘attachment‘] = $attach[‘attachdir‘] . $upload->get_target_filename(‘portal‘).‘.‘.$attach[‘extension‘];
		$attach[‘target‘] = getglobal(‘setting/attachdir‘).‘./portal/‘.$attach[‘attachment‘];

		if([email protected]$fp = fopen($attach[‘target‘], ‘wb‘)) {
			return;
		} else {
			flock($fp, 2);
			fwrite($fp, $content);
			fclose($fp);
		}
		if(!$upload->get_image_info($attach[‘target‘])) {
			@unlink($attach[‘target‘]);
			return;
		}
		$attach[‘size‘] = filesize($attach[‘target‘]);
		$attach = daddslashes($attach);

		if(!$attach) return;

		if($attach[‘isimage‘] || empty($_G[‘setting‘][‘portalarticleimgthumbclosed‘])) {
			require_once libfile(‘class/image‘);
			$image = new image();
			$thumbimgwidth = $_G[‘setting‘][‘portalarticleimgthumbwidth‘] ? $_G[‘setting‘][‘portalarticleimgthumbwidth‘] : 300;
			$thumbimgheight = $_G[‘setting‘][‘portalarticleimgthumbheight‘] ? $_G[‘setting‘][‘portalarticleimgthumbheight‘] : 300;
			$attach[‘thumb‘] = $image->Thumb($attach[‘target‘], ‘‘, $thumbimgwidth, $thumbimgheight, 2);
			$image->Watermark($attach[‘target‘], ‘‘, ‘portal‘);
		}

		$setarr = array(
			‘uid‘ => $_G[‘uid‘],
			‘filename‘ => $attach[‘name‘],
			‘attachment‘ => $attach[‘attachment‘],
			‘filesize‘ => $attach[‘size‘],
			‘isimage‘ => $attach[‘isimage‘],
			‘thumb‘ => $attach[‘thumb‘],
			‘remote‘ => $attach[‘remote‘],
			‘filetype‘ => $attach[‘extension‘],
			‘dateline‘ => $_G[‘timestamp‘],
			‘aid‘ => $aid
		);
		$setarr[‘attachid‘] = C::t(‘portal_attachment‘)->insert($setarr, true);

		if($attach[‘isimage‘]) {
			$errorcode = 0;
			require_once libfile(‘function/home‘);
			$smallimg = pic_get($attach[‘attachment‘], ‘portal‘, $attach[‘thumb‘], $attach[‘remote‘]);
			$bigimg = pic_get($attach[‘attachment‘], ‘portal‘, 0, $attach[‘remote‘]);
			$coverstr = addslashes(serialize(array(‘pic‘=>‘portal/‘.$attach[‘attachment‘], ‘thumb‘=>$attach[‘thumb‘], ‘remote‘=>$attach[‘remote‘])));
			$returnstr = "{\"aid\":$setarr[attachid], \"isimage\":$attach[isimage], \"smallimg\":\"$smallimg\", \"bigimg\":\"$bigimg\", \"errorcode\":$errorcode, \"cover\":\"$coverstr\"}";
			$return = json_decode($returnstr, true);
			return $return;
		}
		return;
	}

	//发布内容
	protected function publish_content() {
		if(DEBUG) {
			//调试模式下显示所有级别错误提示
			error_reporting(E_ALL);
			if(0) {
				//构造发布参数, 用于页面调试
				$_POST = array(
					‘uid‘ => ‘1‘,
					‘catid‘ => ‘1‘,
					‘title‘ => ‘测试标题 - ‘. DATE_TIME,
					‘content‘ => ‘测试内容 - ‘. DATE_TIME,
					‘summary‘ => ‘测试摘要~ - ‘. DATE_TIME,
					‘dateline‘ => DATE_TIME,
					‘author‘ => ‘清顽于世‘,
					‘from‘ => ‘新浪网‘,
					‘fromurl‘ => ‘http://www.baidu.com/‘,
					‘viewnum‘ => ‘15‘,
					‘setconver‘ => ‘1‘,
				);
			}
		}

		//图片上传
		$upload = array();
		if(!empty($_FILES) && !empty($_FILES[‘attach_0‘][‘name‘])) {
			$files = $_FILES;
			foreach ($files as $key => $value) {
				$_FILES[‘Filedata‘] = $value;
				$attach = $this->process_attach();

				//处理内容里的图片地址
				if(!empty($attach)) {
					$upload[] = $attach;
					$_POST[‘content‘] = preg_replace(‘#<img src="(‘. preg_quote($value[‘name‘]) .‘)" />#iUs‘, ‘<img src="‘. $attach[‘bigimg‘] .‘" />‘, $_POST[‘content‘]);
				}
			}
		}

		////提取第一张图片至封面
		if(!empty($_POST[‘setconver‘])) {
			//检测否是需要下载网络图片, 用于封面
			preg_match_all("/\<img.+src=(‘|\"|)?(.*)(\\1)([\s].*)?\>/ismUe", $_POST[‘content‘], $matches, PREG_SET_ORDER);
			if(!empty($matches) && is_array($matches)) {
				$imageurl = $matches[0][2];
				if(substr($imageurl, 0, 7) == ‘http://‘ || substr($imageurl, 0, 8) == ‘https://‘) { //内容里第一张图片是网络图片
					$data = $this->downloadremotefile($imageurl);
					if(!empty($data)) {
						$conver = $data[‘cover‘];
					} else {
						$conver = ‘‘;
					}
				} else { //第一张图片为本地图片
					$conver = $upload[0][‘cover‘];
				}

				$_POST[‘conver‘] = $conver;
			}
		}

		//发布内容前的初始化
		$this->init();

		//POST参数转为GET参数
		$this->post2get();

		//设置发布用户ID
		$this->set_uid();

		$catid = $_POST[‘catid‘];
		check_articleperm($catid);

		$_POST[‘title‘] = getstr(trim($_POST[‘title‘]), 80);

		if(strlen($_POST[‘title‘]) < 1) {
			showMsg(‘标题不能少于 2 个字符‘);
		}

		$_POST[‘title‘] = censor($_POST[‘title‘]);

		$_POST[‘pagetitle‘] = getstr(trim($_POST[‘pagetitle‘]), 60);
		$_POST[‘pagetitle‘] = censor($_POST[‘pagetitle‘]);
		$htmlname = basename(trim($_POST[‘htmlname‘]));

		$highlight_style = $_GET[‘highlight_style‘];
		$style = ‘‘;
		$style = implode(‘|‘, $highlight_style);
		if(empty($_POST[‘summary‘])) $_POST[‘summary‘] = preg_replace("/(\s|\<strong\>##########NextPage(\[title=.*?\])?##########\<\/strong\>)+/", ‘ ‘, $_POST[‘content‘]);

		$summary = portalcp_get_summary($_POST[‘summary‘]);
		$summary = censor($summary);

		$_GET[‘author‘] = dhtmlspecialchars($_GET[‘author‘]);
		$_GET[‘url‘] = str_replace(‘&‘, ‘&‘, dhtmlspecialchars($_GET[‘url‘]));
		$_GET[‘from‘] = dhtmlspecialchars($_GET[‘from‘]);
		$_GET[‘fromurl‘] = str_replace(‘&‘, ‘&‘, dhtmlspecialchars($_GET[‘fromurl‘]));
		$_GET[‘dateline‘] = !empty($_GET[‘dateline‘]) ? strtotime($_GET[‘dateline‘]) : TIMESTAMP;
		if(empty($_GET[‘dateline‘])) $_GET[‘dateline‘] = TIMESTAMP;
		if(substr($_GET[‘url‘], 0, 7) !== ‘http://‘) {
			$_GET[‘url‘] = ‘‘;
		}
		if(substr($_GET[‘fromurl‘], 0, 7) !== ‘http://‘) {
			$_GET[‘fromurl‘] = ‘‘;
		}

		if(0 && (censormod($_POST[‘title‘]) || $_G[‘group‘][‘allowpostarticlemod‘])) { //让文章发布状态始终为true
			$article_status = 1;
		} else {
			$article_status = 0;
		}

		$setarr = array(
			‘idtype‘ => ‘‘,
			‘title‘ => $_POST[‘title‘],
			‘author‘ => $_GET[‘author‘],
			‘from‘ => $_GET[‘from‘],
			‘fromurl‘ => $_GET[‘fromurl‘],
			‘dateline‘ => intval($_GET[‘dateline‘]),
			‘url‘ => $_GET[‘url‘],
			‘allowcomment‘ => !empty($_POST[‘forbidcomment‘]) ? ‘0‘ : ‘1‘,
			‘summary‘ => $summary,
			‘catid‘ => intval($_POST[‘catid‘]),
			‘tag‘ => article_make_tag($_POST[‘tag‘]),
			‘status‘ => $article_status,
			‘highlight‘ => $style,
			‘showinnernav‘ => empty($_POST[‘showinnernav‘]) ? ‘0‘ : ‘1‘,
		);

		if(empty($setarr[‘catid‘])) {
			showMsg(‘栏目不能为空‘);
		}

		if(!empty($_POST[‘conver‘])) {
			$converfiles = dunserialize($_POST[‘conver‘]);
			$setarr[‘pic‘] = $converfiles[‘pic‘];
			$setarr[‘thumb‘] = intval($converfiles[‘thumb‘]);
			$setarr[‘remote‘] = intval($converfiles[‘remote‘]);
		}

		$id = 0;
		$idtype = ‘‘;

		if(empty($article)) {
			$setarr[‘uid‘] = $this->global[‘uid‘];
			$setarr[‘username‘] = $this->global[‘username‘];
			$setarr[‘id‘] = intval($_POST[‘id‘]);
			$setarr[‘htmlname‘] = $htmlname;
			$table = ‘‘;
			if(0 && $setarr[‘id‘]) {
				if($_POST[‘idtype‘]==‘blogid‘) {
					$table = ‘home_blogfield‘;
					$setarr[‘idtype‘] = ‘blogid‘;
					$id = $setarr[‘id‘];
					$idtype = $setarr[‘idtype‘];
				} else {
					$table = ‘forum_thread‘;
					$setarr[‘idtype‘] = ‘tid‘;

					require_once libfile(‘function/discuzcode‘);
					$id = C::t(‘forum_post‘)->fetch_threadpost_by_tid_invisible($setarr[‘id‘]);
					$id = $id[‘pid‘];
					$idtype = ‘pid‘;
				}
			}

			$aid = C::t(‘portal_article_title‘)->insert($setarr, 1);

			if(0 && $table) {
				if($_POST[‘idtype‘]==‘blogid‘) {
					C::t(‘home_blogfield‘)->update($setarr[‘id‘], array(‘pushedaid‘ => $aid));
				} elseif($setarr[‘idtype‘]==‘tid‘) {
					$modarr = array(
						‘tid‘ => $setarr[‘id‘],
						‘uid‘ => $_G[‘uid‘],
						‘username‘ => $_G[‘username‘],
						‘dateline‘ => TIMESTAMP,
						‘action‘ => ‘PTA‘,
						‘status‘ => ‘1‘,
						‘stamp‘ => ‘‘,
					);
					C::t(‘forum_threadmod‘)->insert($modarr);

					C::t(‘forum_thread‘)->update($setarr[‘id‘], array(‘moderated‘ => 1, ‘pushedaid‘ => $aid));
				}
			}
			C::t(‘common_member_status‘)->update($this->global[‘uid‘], array(‘lastpost‘ => TIMESTAMP), ‘UNBUFFERED‘);
			C::t(‘portal_category‘)->increase($setarr[‘catid‘], array(‘articles‘ => 1));
			C::t(‘portal_category‘)->update($setarr[‘catid‘], array(‘lastpublish‘ => TIMESTAMP));
			C::t(‘portal_article_count‘)->insert(array(‘aid‘=>$aid, ‘catid‘=>$setarr[‘catid‘], ‘viewnum‘=>$_POST[‘viewnum‘]));
		} else {
			//这里面基本不可能执行到
			if($htmlname && $article[‘htmlname‘] !== $htmlname) {
				$setarr[‘htmlname‘] = $htmlname;
				$oldarticlename = $article[‘htmldir‘].$article[‘htmlname‘];
				unlink($oldarticlename.‘.‘.$_G[‘setting‘][‘makehtml‘][‘extendname‘]);
				for($i = 1; $i < $article[‘contents‘]; $i++) {
					unlink($oldarticlename.$i.‘.‘.$_G[‘setting‘][‘makehtml‘][‘extendname‘]);
				}
			}
			C::t(‘portal_article_title‘)->update($aid, $setarr);
		}

		$content = getstr($_POST[‘content‘], 0, 0, 0, 0, 1);
		$content = censor($content);
		if(0 && (censormod($content) || $this->global[‘group‘][‘allowpostarticlemod‘])) {
			$article_status = 1;
		} else {
			$article_status = 0;
		}

		$regexp = ‘/(\<strong\>##########NextPage(\[title=(.*?)\])?##########\<\/strong\>)+/is‘;
		preg_match_all($regexp, $content ,$arr);
		$pagetitle = !empty($arr[3]) ? $arr[3] : array();
		$pagetitle = array_map(‘trim‘, $pagetitle);
		array_unshift($pagetitle, $_POST[‘pagetitle‘]);
		$contents = preg_split($regexp, $content);
		$cpostcount = count($contents);

		$dbcontents = C::t(‘portal_article_content‘)->fetch_all($aid);

		$pagecount = $cdbcount = count($dbcontents);
		if($cdbcount > $cpostcount) {
			$cdelete = array();
			foreach(array_splice($dbcontents, $cpostcount) as $value) {
				$cdelete[$value[‘cid‘]] = $value[‘cid‘];
			}
			if(!empty($cdelete)) {
				C::t(‘portal_article_content‘)->delete($cdelete);
			}
			$pagecount = $cpostcount;
		}

		foreach($dbcontents as $key => $value) {
			C::t(‘portal_article_content‘)->update($value[‘cid‘], array(‘title‘ => $pagetitle[$key], ‘content‘ => $contents[$key], ‘pageorder‘ => $key+1));
			unset($pagetitle[$key], $contents[$key]);
		}

		if($cdbcount < $cpostcount) {
			foreach($contents as $key => $value) {
				C::t(‘portal_article_content‘)->insert(array(‘aid‘ => $aid, ‘id‘ => $setarr[‘id‘], ‘idtype‘ => $setarr[‘idtype‘], ‘title‘ => $pagetitle[$key], ‘content‘ => $contents[$key], ‘pageorder‘ => $key+1, ‘dateline‘ => TIMESTAMP));
			}
			$pagecount = $cpostcount;
		}

		$updatearticle = array(‘contents‘ => $pagecount);
		if($article_status == 1) {
			$updatearticle[‘status‘] = 1;
			updatemoderate(‘aid‘, $aid);
			manage_addnotify(‘verifyarticle‘);
		}

		$updatearticle = array_merge($updatearticle, portalcp_article_pre_next($catid, $aid));
		C::t(‘portal_article_title‘)->update($aid, $updatearticle);

		$newaids = array();
		$_POST[‘attach_ids‘] = explode(‘,‘, $_POST[‘attach_ids‘]);
		foreach ($_POST[‘attach_ids‘] as $newaid) {
			$newaid = intval($newaid);
			if($newaid) $newaids[$newaid] = $newaid;
		}
		if($newaids) {
			C::t(‘portal_attachment‘)->update_to_used($newaids, $aid);
		}

		addrelatedarticle($aid, $_POST[‘raids‘]);

		if(0 && $_GET[‘from_idtype‘] && $_GET[‘from_id‘]) {

			$id = intval($_GET[‘from_id‘]);
			$notify = array();
			switch ($_GET[‘from_idtype‘]) {
				case ‘blogid‘:
					$blog = C::t(‘home_blog‘)->fetch($id);
					if(!empty($blog)) {
						$notify = array(
							‘url‘ => "home.php?mod=space&uid=$blog[uid]&do=blog&id=$id",
							‘subject‘ => $blog[‘subject‘]
						);
						$touid = $blog[‘uid‘];
					}
					break;
				case ‘tid‘:
					$thread = C::t(‘forum_thread‘)->fetch($id);
					if(!empty($thread)) {
						$notify = array(
							‘url‘ => "forum.php?mod=viewthread&tid=$id",
							‘subject‘ => $thread[‘subject‘]
						);
						$touid = $thread[‘authorid‘];
					}
					break;
			}
			if(!empty($notify)) {
				$notify[‘newurl‘] = ‘portal.php?mod=view&aid=‘.$aid;
				notification_add($touid, ‘pusearticle‘, ‘puse_article‘, $notify, 1);
			}
		}

		if(trim($_GET[‘from‘]) != ‘‘) {
			$from_cookie = ‘‘;
			$from_cookie_array = array();
			$from_cookie = getcookie(‘from_cookie‘);
			$from_cookie_array = explode("\t", $from_cookie);
			$from_cookie_array[] = $_GET[‘from‘];
			$from_cookie_array = array_unique($from_cookie_array);
			$from_cookie_array = array_filter($from_cookie_array);
			$from_cookie_num = count($from_cookie_array);
			$from_cookie_start = $from_cookie_num - 10;
			$from_cookie_start = $from_cookie_start > 0 ? $from_cookie_start : 0;
			$from_cookie_array = array_slice($from_cookie_array, $from_cookie_start, $from_cookie_num);
			$from_cookie = implode("\t", $from_cookie_array);
			dsetcookie(‘from_cookie‘, $from_cookie);
		}
		dsetcookie(‘clearUserdata‘, ‘home‘);
		$op = ‘add_success‘;
		$article_add_url = ‘portal.php?mod=portalcp&ac=article&catid=‘.$catid;

		$article = C::t(‘portal_article_title‘)->fetch($aid);
		$viewarticleurl = $_POST[‘url‘] ? "portal.php?mod=list&catid=$_POST[catid]" : fetch_article_url($article);

		showMsg(‘发布成功‘);
	}
}

//接口需要用到的函数库
function portalcp_get_summary($message) {
	$message = preg_replace(array("/\[attach\].*?\[\/attach\]/", "/\&[a-z]+\;/i", "/\<script.*?\<\/script\>/"), ‘‘, $message);
	$message = preg_replace("/\[.*?\]/", ‘‘, $message);
	$message = getstr(strip_tags($message), 200);
	return $message;
}

function portalcp_article_pre_next($catid, $aid) {
	$data = array(
		‘preaid‘ => C::t(‘portal_article_title‘)->fetch_preaid_by_catid_aid($catid, $aid),
		‘nextaid‘ => C::t(‘portal_article_title‘)->fetch_nextaid_by_catid_aid($catid, $aid),
	);
	if($data[‘preaid‘]) {
		C::t(‘portal_article_title‘)->update($data[‘preaid‘], array(
			‘preaid‘ => C::t(‘portal_article_title‘)->fetch_preaid_by_catid_aid($catid, $data[‘preaid‘]),
			‘nextaid‘ => C::t(‘portal_article_title‘)->fetch_nextaid_by_catid_aid($catid, $data[‘preaid‘]),
			)
		);
	}
	return $data;
}
?>

  

原文地址:https://www.cnblogs.com/68xi/p/9455812.html

时间: 08-10

discuz论坛门户资讯入库接口【原创】的相关文章

在CentOS 6.7部署wordpress博客系统Discuz论坛系统

在CentOS 6.7部署wordpress博客系统Discuz论坛系统 服务器操作系统:CentOS6.7 博客部署服务器:Httpd-2.2 后台语言:PHP 数据库:MySql 前端框架:WordPress 1.首先安装需要的软件 yum -y install mysql-server httpd phpphp-mysql 2.启动mysql以及httpd服务 service mysqld start service httpd start 3.创建虚拟主机 4.测试 PHP 和Httpd

Discuz论坛写出的php加密解密处理类(代码+使用方法)

PHP加密解密也是常有的事,最近在弄相关的东西,发现discuz论坛里的PHP加密解密处理类代码,感觉挺不错,在用的时候,要参考Discuz论坛的passport相关函数,后面我会附上使用方法,先把类代码帖上来: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 <?php /*

LAMP搭建discuz论坛

discuz论坛下载地址(我用的3.2_GBK) http://www.comsenz.com/downloads/install/discuzx 建立一个目录放程序目录 mkdir /data/www/ 进入目录,并下载,解压 unzip Discuz_X3.2_SC_GBK.zip 在此需要的是/upload/内的文件,其它的不需要.因此把该文件下东西移到此出,删除其余文件 mv upload/* ./ rm -rf Discuz_X3.2_SC_GBK.zip  readme/ utili

基于LNMP搭建Discuz!论坛,并配置nginx,php

前面我们已经搭建好了LNMP环境:http://1015489314.blog.51cto.com/8637744/1688048 下面我们基于LNMP来搭建一个Discuz!论坛 一.安装Discuz! 1.新建目录来存放网页等 [[email protected] ~]# mkdir /data/www[[email protected] ~]# cd /data/www   [[email protected] www]# wget http://download.comsenz.com/

LAMP架构搭建+Discuz论坛搭建【weber出品必属精品】

一.     本机简介: 本机系统: CentOS-6.4-x86_64 主机名:oracle.ywb IP地址:192.168.146.129 二.     在Linux环境下安装Apache步骤 首先将准备好的文件通过PSCP发送至Linux的/Root/test/soft目录下 在windows下按住Ctrl+R,打开运行,输入CMD进入DOS命令行.在dos命令行中使用pscp –scp  命令将要上传的文件上传至Linux中. 上传成功后.我们总共要安装四个文件.第一个我们首先解压:a

CentOS下lamp的实现之rpm包构建discuz论坛

一.安装需要用的软件 [[email protected] ~]# yum install php php-gdphp-xml php-mysql mysql mysql-server httpd –y 启动mysql和httpd并设置为2.3.4.5级别自动启动 [[email protected] ~]# service mysqld start [[email protected] ~]# chkconfig mysqld on [[email protected] ~]# service

Oracle EBS 采购 接收入库 接口开发

http://blog.itpub.net/25164132/viewspace-746657/ 接收入库是项目中会经常碰到的开发,这类开发一般来说比较简单,但是接收入库在Oracle中其实涉及到很多模块,其中层次较多,也可以做得比较复杂.本文将尽可能深入细致地讨论接收入库的流程,种类,数据来源,数据的流动路径,以及各个数据点之间的对应关系.最后将给出一个较为全面的接收入库的样例代码.接收入库的种类接收入库可以按照数据来源分为2种:1.         对于po订单以及发放的接收入库:2.   

CentOS 7中的httpd-2.4和CentOS 6中的httpd-2.2搭建wordpress博客系统和Discuz!论坛系统

在搭建wordpress博客系统和Discuz!论坛系统之前,我们需要在Centos中准备好LAMP环境. 现在以Centos 6为例演示其过程. LAMP环境=linux+apche+mysql+php 在安装好的Centos 6.7中使用yun安装apche+mysql+php,在命令行中输入以下命令: ~]# yum -y install httpd mysql mysql-server php php-mysql postgresql postgresql-server php-post

DISCUZ论坛添加页头及页尾背景图片的几种方法

先给大家分享页头添加背景图片的两种方法: 1. 第一种效果,是给discuz的整体框架添加背景图片,见图示: 添加方法如下:找到你现在使用模板common文件下的header.html文件,在<head></head>部分添加以下代码: <style>body { background-image:url(你的背景图片地址,如http://abc.com/imgs/bg.jpg); background-repeat:no-repeat; background-posi

NFS实现(双httpd + php-fpm + nfs + mysql 搭建discuz论坛)的方法

NFS相关介绍 一.NFS简介 1. NFS(Network File System):NFS是一个文件共享协议, 也是是在类Unix系统中在内核中实现的文件系统. 2. 起源:最早是由SUN公司研发,非常古老,只是实现文件共享,安全控制方面比较简陋. 版本有, NFSv1, NFSv2,NFSv3,NFSv4. v4版开始支持kerberos 认证. 3. RPC(Remote Procedure Call):NFS协议是基于PRC(远程过程调用)实现的. 基本过程如下图,客户端某程序发起过程