PageRenderTime 27ms CodeModel.GetById 2ms app.highlight 20ms RepoModel.GetById 1ms app.codeStats 0ms

/post.php

https://bitbucket.org/johnroyer/phpwind8.7
PHP | 305 lines | 262 code | 22 blank | 21 comment | 147 complexity | 43be7993838b7ddfce4fc2cbf5af0c97 MD5 | raw file
  1<?php
  2define('SCR','post');
  3if (isset($_POST['ajax']) && $_POST['ajax'] == 1) {
  4	define("AJAX",1);
  5}
  6require_once('global.php');
  7L::loadClass('forum', 'forum', false);
  8L::loadClass('post', 'forum', false);
  9//* include_once pwCache::getPath(D_P.'data/bbscache/cache_post.php');
 10pwCache::getData(D_P.'data/bbscache/cache_post.php');
 11/**
 12* 版塊緩衝文件
 13*/
 14
 15empty($fid) && Showmsg('undefined_action');
 16$pwforum = new PwForum($fid);
 17$pwpost  = new PwPost($pwforum);
 18if (!S::inArray($windid, $manager)) {
 19	$pwpost->forumcheck();
 20	$pwpost->postcheck();
 21}
 22
 23$foruminfo =& $pwforum->foruminfo;
 24$forumset =& $pwforum->forumset;
 25
 26if ($forumset['link']) {
 27	Showmsg('本版塊為外鏈版塊,禁止發帖');
 28}
 29
 30S::gp(array('action','article','pid','page'));
 31S::gp(array('special','modelid','pcid', 'cyid','actmid'),GP,2);
 32$replacedb = array();
 33$secondurl = "thread.php?fid=$fid";
 34!$action && $action = "new";
 35$replayorder_default = 'checked';
 36if ($action == 'new') {
 37
 38	$theSpecialFlag = false;//是否是特殊帖子(分類、團購、活動)
 39	if ($modelid > 0) {/*主題分類*/
 40		L::loadClass('posttopic', 'forum', false);
 41		$postTopic = new postTopic($pwpost);
 42		if (!$_G['allowmodelid']) {
 43			Showmsg('post_allowpost');
 44		}
 45		if (strpos(",".$pwforum->foruminfo['modelid'].",",",".$modelid.",") === false) {
 46			Showmsg('forum_model_undefined');
 47		}
 48		if (!$postTopic->topiccatedb[$postTopic->topicmodeldb[$modelid]['cateid']]['ifable']) {
 49			Showmsg('topic_cate_unable');
 50		}
 51		!$postTopic->topicmodeldb[$modelid]['ifable'] && Showmsg('topic_model_unable');
 52		$special = $pcid = $actmid = 0;
 53		$theSpecialFlag = true;
 54	} elseif ($pcid > 0) {/*團購*/
 55		L::loadClass('postcate', 'forum', false);
 56		$postCate = new postCate($pwpost);
 57		if (strpos(",".$pwforum->foruminfo['pcid'].",",",".$pcid.",") === false) {
 58			Showmsg('post_allowtype');
 59		}
 60		if (!$postCate->postcatedb[$pcid]['ifable']) {
 61			Showmsg('forum_pc_undefined');
 62		}
 63		if (strpos(",".$_G['allowpcid'].",",",".$pcid.",") === false) {
 64			Showmsg('post_allowpost');
 65		}
 66		$special = $modelid = $actmid = 0;
 67		$theSpecialFlag = true;
 68	} elseif ($actmid > 0) {/*活動分類*/
 69		L::loadClass('ActivityForBbs', 'activity', false);
 70		$postActForBbs = new PW_ActivityForBbs($pwpost);
 71		if (!$_G['allowactivity']) {
 72			Showmsg('post_allowpost');
 73		}
 74		if (strpos(",".$pwforum->foruminfo['actmids'].",",",".$actmid.",") === false) {
 75			Showmsg('forum_model_undefined');
 76		}
 77		if (!$postActForBbs->activitycatedb[$postActForBbs->activitymodeldb[$actmid]['actid']]['ifable']) {
 78			Showmsg('topic_cate_unable');
 79		}
 80		!$postActForBbs->activitymodeldb[$actmid]['ifable'] && Showmsg('topic_model_unable');
 81		$special = $pcid = $modelid = 0;
 82		$theSpecialFlag = true;
 83	} elseif (!($pwforum->foruminfo['allowtype'] & pow(2,$special))) {
 84		$modelid = $pcid = $actmid = 0;
 85		if (empty($special) && $pwforum->foruminfo['allowtype'] > 0) {
 86			$special = (int)log($pwforum->foruminfo['allowtype'],2);
 87		} elseif ($pwforum->foruminfo['modelid'] || $pwforum->foruminfo['pcid'] || $pwforum->foruminfo['actmids']) {
 88			L::loadClass('posttopic', 'forum', false);
 89			$postTopic = new postTopic($pwpost);
 90			$modeliddb = explode(",",$pwforum->foruminfo['modelid']);
 91	
 92			/*判斷分類信息是否存在*/
 93			foreach ($modeliddb as $value) {
 94				if ($postTopic->topiccatedb[$postTopic->topicmodeldb[$value]['cateid']]['ifable'] && $_G['allowmodelid'] && $postTopic->topicmodeldb[$value]['ifable']) {
 95					$modelid = $value;
 96					$theSpecialFlag = true;
 97					break;
 98				}
 99			}
100
101			/*判斷團購是否存在*/
102			if (!$modelid) {
103				L::loadClass('postcate', 'forum', false);
104				$postCate = new postCate($pwpost);
105				$pciddb = explode(",",$pwforum->foruminfo['pcid']);
106			
107				foreach ($pciddb as $value) {
108					if ($postCate->postcatedb[$value]['ifable'] && strpos(",".$_G['allowpcid'].",",",".$value.",") !== false) {
109						$theSpecialFlag = true;
110						$pcid = $value;
111						break;
112					}
113				}
114			}
115
116			/*判斷活動是否存在*/
117			if (!$pcid && !$modelid) {
118				L::loadClass('ActivityForBbs', 'activity', false);
119				$postActForBbs = new PW_ActivityForBbs($pwpost);
120
121				$actmiddb = explode(",",$pwforum->foruminfo['actmids']);
122				foreach ($actmiddb as $value) {
123					if ($postActForBbs->activitycatedb[$postActForBbs->activitymodeldb[$value]['actid']]['ifable'] && $_G['allowactivity'] && $postActForBbs->activitymodeldb[$value]['ifable']) {
124						$actmid = $value;
125						$theSpecialFlag = true;
126						break;
127					}
128				}
129				if (!$actmid) {
130					Showmsg('post_allowtype');
131				}
132			}
133		} else {
134			Showmsg('post_allowtype');
135		}
136
137	}
138}
139/**
140* 禁止受限制用戶發言
141*/
142if ($groupid == 6 || getstatus($winddb['userstatus'], PW_USERSTATUS_BANUSER)) {
143	$flag  = 0;
144	$bandb = $delban = array();
145	$query = $db->query("SELECT * FROM pw_banuser WHERE uid=".S::sqlEscape($winduid));
146	while ($rt = $db->fetch_array($query)) {
147		if ($rt['type'] == 1 && $timestamp - $rt['startdate'] > $rt['days']*86400) {
148			$delban[] = $rt['id'];
149		} elseif ($rt['fid'] == 0 || $rt['fid'] == $fid) {
150			$bandb[$rt['fid']] = $rt;
151		} else {
152			$flag = 1;
153		}
154	}
155	$delban && $db->update('DELETE FROM pw_banuser WHERE id IN('.S::sqlImplode($delban).')');
156
157	$updateUser = array();
158	if ($groupid == 6 && !isset($bandb[0])) {
159		$updateUser['groupid'] = -1;
160	}
161	if (getstatus($winddb['userstatus'], PW_USERSTATUS_BANUSER) && !isset($bandb[$fid]) && !$flag) {
162		$userService = L::loadClass('UserService', 'user'); /* @var $userService PW_UserService */
163		$userService->setUserStatus($winduid, PW_USERSTATUS_BANUSER, false);
164	}
165	if (count($updateUser)) {
166		$userService = L::loadClass('UserService', 'user'); /* @var $userService PW_UserService */
167		$userService->update($winduid, $updateUser);
168	}
169	if ($bandb) {
170		$bandb = current($bandb);
171		if ($bandb['type'] == 1) {
172			$s_date = get_date($bandb['startdate']);
173			$e_date = $bandb['startdate'] + $bandb['days']*86400;
174			$e_date = get_date($e_date);
175			Showmsg('ban_info1');
176		} else {
177			if ($bandb['type'] == 3) {
178				Cookie('force',$winduid);
179				Showmsg('ban_info3');
180			} else {
181				Showmsg('ban_info2');
182			}
183		}
184	}
185}
186if (GetCookie('force') && $winduid != GetCookie('force')) {
187	$force = GetCookie('force');
188	$bandb = $db->get_one("SELECT type FROM pw_banuser WHERE uid=".S::sqlEscape($force)." AND fid='0'");
189	if ($bandb['type'] == 3) {
190		Showmsg('ban_info3');
191	} else {
192		Cookie('force','',0);
193	}
194}
195
196$userlastptime = $groupid != 'guest' ?  $winddb['lastpost'] : GetCookie('userlastptime');
197/**
198* 灌水預防
199*/
200$tdtime  >= $winddb['lastpost'] && $winddb['todaypost'] = 0;
201$montime >= $winddb['lastpost'] && $winddb['monthpost'] = 0;
202if ($_G['postlimit'] && $winddb['todaypost'] >= $_G['postlimit']) {
203	Showmsg('post_gp_limit');
204}
205if (!empty($_POST['step']) && !$pwpost->isGM && $_G['postpertime'] && $timestamp>=$userlastptime && $timestamp-$userlastptime<=$_G['postpertime'] && !pwRights($pwpost->isBM,'postpers')) {
206	Showmsg('post_limit');
207}
208list($postq,$showq) = explode("\t", $db_qcheck);
209$_G['uploadtype'] && $db_uploadfiletype = $_G['uploadtype'];
210$db_uploadfiletype = !empty($db_uploadfiletype) ? (is_array($db_uploadfiletype) ? $db_uploadfiletype : unserialize($db_uploadfiletype)) : array();
211empty($db_sellset['type']) && $db_sellset['type'] = array('money');
212empty($db_enhideset['type']) && $db_enhideset['type'] = array('rvrc');
213
214if (empty($_POST['step'])) {
215
216	require_once(R_P.'require/credit.php');
217	$editor = getstatus($winddb['userstatus'], PW_USERSTATUS_EDITOR) ? 'wysiwyg' : 'textmode';
218	!is_numeric($db_attachnum) && $db_attachnum = 1;
219	$htmlsell = ($pwforum->foruminfo['allowsell'] && $_G['allowsell']) ? '' : 'disabled';
220	$htmlhide = ($pwforum->forumset['allowencode'] && $_G['allowencode']) ? '' : 'disabled';
221	$htmlpost = $attachHide = ($pwforum->foruminfo['allowhide'] && $_G['allowhidden']) ? '' : 'disabled';
222	$ifanonymous= ($pwpost->isGM || $pwforum->forumset['anonymous'] && $_G['anonymous']) ? '' : 'disabled';
223	$groupid   == 'guest' && $userrvrc = 0;
224	$atc_title  = $atc_content = $ifmailck = $selltype = $enhidetype = $alltype = $replyrewardcredit = '';
225	$sellCredit = $enhideCredit = $customCreditValue = $userAllCredits = array();
226
227	$attachAllow = pwJsonEncode($db_uploadfiletype);
228	$imageAllow = pwJsonEncode(getAllowKeysFromArray($db_uploadfiletype, array('jpg','jpeg','gif','png','bmp')));
229	
230	if (S::inArray($action, array('new', 'modify')) && $_G['allowreplyreward'] && S::isArray($_CREDITDB)) {
231		$customCreditValue = $credit->get($winduid, 'CUSTOM');
232	}
233	foreach ($credit->cType as $key => $value) {
234		if (S::inArray($action, array('new', 'modify')) && $_G['allowreplyreward'] && ($winddb[$key] || $customCreditValue[$key])) {
235			$replyrewardcredit .= "<option value=\"$key\">" . $value . "</option>";
236			$userAllCredits['c' . $key] = array(
237				$winddb[$key] ? ($key == 'rvrc' ? $winddb[$key] / 10 : $winddb[$key]) : $customCreditValue[$key],
238				$value,
239				$credit->cUnit[$key]
240			);
241		}
242		$alltype .= "<option value=\"$key\">".$value."</option>";
243	}
244	$userAllCredits && $userAllCredits = pwJsonEncode($userAllCredits);
245	foreach ($db_sellset['type'] as $key => $value) {
246		$selltype .= "<option value=\"$value\">".$credit->cType[$value]."</option>";
247		$sellCredit[$value] = $credit->cType[$value];
248	}
249	if (is_array($db_enhideset['type'])) {
250		foreach ($db_enhideset['type'] as $key => $value) {
251			$enhidetype .= "<option value=\"$value\">".$credit->cType[$value]."</option>";
252			$enhideCredit[$value] = $credit->cType[$value];
253		}
254	}
255	list($sellCredit, $enhideCredit) = array(pwJsonEncode($sellCredit), pwJsonEncode($enhideCredit));
256
257	require_once(R_P.'require/showimg.php');
258	list($postFaceUrl) = showfacedesign($winddb['icon'],1,'m');
259
260	$icondb = array();
261	if ($db_threademotion) {
262		$emotion = @opendir(S::escapeDir("$imgdir/post/emotion"));
263		while (($emotionimg = @readdir($emotion)) !== false) {
264			if ($emotionimg != "." && $emotionimg != ".." && $emotionimg != "" && preg_match("/^(\d+)\.(gif|jpg|png|bmp)$/i", $emotionimg, $emotionMatch)) {
265				$icondb[$emotionMatch[1]] = $emotionimg;
266			}
267		}
268		ksort($icondb);
269		@closedir($emotion);
270	}
271
272	//multiple post types
273	if ($foruminfo['allowtype'] && (($foruminfo['allowtype'] & 1) || ($foruminfo['allowtype'] & 2 && $_G['allownewvote']) || ($foruminfo['allowtype'] & 4 && $_G['allowactive']) || ($foruminfo['allowtype'] & 8 && $_G['allowreward'])|| ($foruminfo['allowtype'] & 16) || $foruminfo['allowtype'] & 32 && $_G['allowdebate'])) {
274		$N_allowtypeopen = true;
275	} else {
276		$N_allowtypeopen = false;
277	}
278	
279} else {
280	if ($db_cloudgdcode && defined('AJAX') && S::inArray($action, array('reply', 'quote'))) $keepCloudCaptchaCode = true;
281	PostCheck(1, ($db_gdcheck & 4) && (!$db_postgd || $winddb['postnum'] < $db_postgd), ($db_ckquestion & 4 && (!$postq || $winddb['postnum'] < $postq) && $db_question));
282	!$windid && $windid = '遊客';
283	/*
284	if ($db_xforwardip && $_POST['_hexie'] != GetVerify($onlineip.$winddb['regdate'].$fid.$tid)) {
285		Showmsg('undefined_action');
286	}
287	*/
288}
289
290//默認動漫表情處理
291if ($db_windmagic && ($action == 'new' || ($action == 'modify' && $pid == 'tpc'))) {
292	$mDef = '';
293	//* @include_once pwCache::getPath(D_P."data/bbscache/myshow_default.php");
294	pwCache::getData(D_P."data/bbscache/myshow_default.php");
295}
296if ($action == "new") {
297	require_once(R_P.'require/postnew.php');
298} elseif ($action == "reply" || $action == "quote") {
299	require_once(R_P.'require/postreply.php');
300} elseif ($action == "modify") {
301	require_once(R_P.'require/postmodify.php');
302} else {
303	Showmsg('undefined_action');
304}
305?>