PageRenderTime 8ms CodeModel.GetById 2ms app.highlight 75ms RepoModel.GetById 1ms app.codeStats 1ms

/source/function/function_delete.php

https://github.com/kuaileshike/upload
PHP | 983 lines | 851 code | 126 blank | 6 comment | 200 complexity | 241b5d239bda6bcd2fef57968d6d87d9 MD5 | raw file
  1<?php
  2
  3/**
  4 *      [Discuz!] (C)2001-2099 Comsenz Inc.
  5 *      This is NOT a freeware, use is subject to license terms
  6 *
  7 *      $Id: function_delete.php 32007 2012-10-30 09:59:48Z zhangjie $
  8 */
  9
 10if(!defined('IN_DISCUZ')) {
 11	exit('Access Denied');
 12}
 13
 14require_once libfile('function/home');
 15
 16function deletemember($uids, $delpost = true) {
 17	global $_G;
 18	if(!$uids) {
 19		return;
 20	}
 21	if($_G['setting']['plugins']['func'][HOOKTYPE]['deletemember']) {
 22		$_G['deleteposuids'] = & $uids;
 23		$hookparam = func_get_args();
 24		hookscript('deletemember', 'global', 'funcs', array('param' => $hookparam, 'step' => 'check'), 'deletemember');
 25	}
 26	if($delpost) {
 27		deleteattach($uids, 'uid');
 28		deletepost($uids, 'authorid');
 29	}
 30
 31	$arruids = $uids;
 32	$uids = dimplode($uids);
 33	$numdeleted = count($arruids);
 34	foreach(array('common_member_field_forum', 'common_member_field_home', 'common_member_count',
 35		'common_member_profile', 'common_member_status',) as $table) {
 36		C::t($table)->delete($arruids, true, 1);
 37	}
 38
 39	foreach(array( 'common_member_log', 'common_member_verify', 'common_member_validate', 'common_member_magic') as $table) {
 40		C::t($table)->delete($arruids, true);
 41	}
 42
 43	C::t('forum_access')->delete_by_uid($arruids);
 44	C::t('common_member_verify_info')->delete_by_uid($arruids);
 45	C::t('common_member_action_log')->delete_by_uid($arruids);
 46	C::t('forum_moderator')->delete_by_uid($arruids);
 47	C::t('forum_post_location')->delete_by_uid($arruids);
 48	$doids = array();
 49	$query = C::t('home_doing')->fetch_all_by_uid_doid($arruids);
 50	foreach($query as $value) {
 51		$doids[$value['doid']] = $value['doid'];
 52	}
 53
 54	C::t('home_docomment')->delete_by_doid_uid($doids, $arruids);
 55	C::t('common_domain')->delete_by_id_idtype($arruids, 'home');
 56	C::t('home_feed')->delete_by_uid($arruids);
 57	C::t('home_notification')->delete_by_uid($arruids);
 58	C::t('home_poke')->delete_by_uid_or_fromuid($uids);
 59	C::t('home_comment')->delete_by_uid($arruids);
 60	C::t('home_visitor')->delete_by_uid_or_vuid($uids);
 61	C::t('home_friend')->delete_by_uid_fuid($arruids);
 62	C::t('home_friend_request')->delete_by_uid_or_fuid($arruids);
 63	C::t('common_invite')->delete_by_uid_or_fuid($arruids);
 64	C::t('common_myinvite')->delete_by_touid_or_fromuid($uids);
 65	C::t('common_moderate')->delete($arruids, 'uid_cid');
 66
 67	foreach(C::t('forum_collectionfollow')->fetch_all_by_uid($arruids) as $follow) {
 68		C::t('forum_collection')->update_by_ctid($follow['ctid'], 0, -1);
 69	}
 70
 71	foreach(C::t('forum_collectioncomment')->fetch_all_by_uid($arruids) as $comment) {
 72		C::t('forum_collection')->update_by_ctid($comment['ctid'], 0, 0, -1);
 73	}
 74
 75	$query = C::t('home_pic')->fetch_all_by_uid($uids);
 76	foreach($query as $value) {
 77		$pics[] = $value;
 78	}
 79	deletepicfiles($pics);
 80
 81	include_once libfile('function/home');
 82	$query = C::t('home_album')->fetch_all_by_uid($arruids);
 83	foreach($query as $value) {
 84		pic_delete($value['pic'], 'album', 0, ($value['picflag'] == 2 ? 1 : 0));
 85	}
 86
 87	C::t('common_mailcron')->delete_by_touid($arruids);
 88
 89	foreach(array('home_doing', 'home_share', 'home_album', 'common_credit_rule_log', 'common_credit_rule_log_field',
 90		'home_pic', 'home_blog', 'home_blogfield', 'home_class', 'home_clickuser',
 91		'home_userapp', 'home_userappfield', 'home_show', 'forum_collectioncomment', 'forum_collectionfollow', 'forum_collectionteamworker') as $table) {
 92		C::t($table)->delete_by_uid($arruids);
 93	}
 94	C::t('common_member')->delete($arruids, 1, 1);
 95
 96	manyoulog('user', $uids, 'delete');
 97	if($_G['setting']['plugins']['func'][HOOKTYPE]['deletemember']) {
 98		hookscript('deletemember', 'global', 'funcs', array('param' => $hookparam, 'step' => 'delete'), 'deletemember');
 99	}
100	return $numdeleted;
101}
102
103function deletepost($ids, $idtype = 'pid', $credit = false, $posttableid = false, $recycle = false) {
104	global $_G;
105	$recycle = $recycle && $idtype == 'pid' ? true : false;
106	if($_G['setting']['plugins']['func'][HOOKTYPE]['deletepost']) {
107		$_G['deletepostids'] = & $ids;
108		$hookparam = func_get_args();
109		hookscript('deletepost', 'global', 'funcs', array('param' => $hookparam, 'step' => 'check'), 'deletepost');
110	}
111	if(!$ids || !in_array($idtype, array('authorid', 'tid', 'pid'))) {
112		return 0;
113	}
114
115	loadcache('posttableids');
116	$posttableids = !empty($_G['cache']['posttableids']) ? ($posttableid !== false && in_array($posttableid, $_G['cache']['posttableids']) ? array($posttableid) : $_G['cache']['posttableids']): array('0');
117
118	$count = count($ids);
119	$idsstr = dimplode($ids);
120
121	if($credit) {
122		$tuidarray = $ruidarray = array();
123		foreach($posttableids as $id) {
124			$postlist = array();
125			if($idtype == 'pid') {
126				$postlist = C::t('forum_post')->fetch_all($id, $ids, false);
127			} elseif($idtype == 'tid') {
128				$postlist = C::t('forum_post')->fetch_all_by_tid($id, $ids, false);
129			} elseif($idtype == 'authorid') {
130				$postlist = C::t('forum_post')->fetch_all_by_authorid($id, $ids, false);
131			}
132			foreach($postlist as $post) {
133				if($post['invisible'] != -1 && $post['invisible'] != -5) {
134					if($post['first']) {
135						$tuidarray[$post['fid']][] = $post['authorid'];
136					} else {
137						$ruidarray[$post['fid']][] = $post['authorid'];
138						if($post['authorid'] > 0 && $post['replycredit'] > 0) {
139							$replycredit_list[$post['authorid']][$post['tid']] += $post['replycredit'];
140						}
141					}
142					$tids[] = $post['tid'];
143				}
144			}
145			unset($postlist);
146		}
147
148		if($tuidarray || $ruidarray) {
149			require_once libfile('function/post');
150		}
151		if($tuidarray) {
152			foreach($tuidarray as $fid => $tuids) {
153				updatepostcredits('-', $tuids, 'post', $fid);
154			}
155		}
156		if($ruidarray) {
157			foreach($ruidarray as $fid => $ruids) {
158				updatepostcredits('-', $ruids, 'reply', $fid);
159			}
160		}
161	}
162
163	foreach($posttableids as $id) {
164		if($recycle) {
165			C::t('forum_post')->update($id, $ids, array('invisible' => -5));
166		} else {
167			if($idtype == 'pid') {
168				C::t('forum_post')->delete($id, $ids);
169				C::t('forum_postcomment')->delete_by_pid($ids);
170			} elseif($idtype == 'tid') {
171				C::t('forum_post')->delete_by_tid($id, $ids);
172				C::t('forum_postcomment')->delete_by_tid($ids);
173			} elseif($idtype == 'authorid') {
174				C::t('forum_post')->delete_by_authorid($id, $ids);
175				C::t('forum_postcomment')->delete_by_authorid($ids);
176			}
177			C::t('forum_trade')->delete_by_id_idtype($ids, ($idtype == 'authorid' ? 'sellerid' : $idtype));
178			C::t('home_feed')->delete_by_id_idtype($ids, ($idtype == 'authorid' ? 'uid' : $idtype));
179		}
180	}
181	if(!$recycle && $idtype != 'authorid') {
182		if($idtype == 'pid') {
183			C::t('forum_poststick')->delete_by_pid($ids);
184		} elseif($idtype == 'tid') {
185			C::t('forum_poststick')->delete_by_tid($ids);
186		}
187
188	}
189	if($idtype == 'pid') {
190		C::t('forum_postcomment')->delete_by_rpid($ids);
191		C::t('common_moderate')->delete($ids, 'pid');
192		C::t('forum_post_location')->delete($ids);
193	} elseif($idtype == 'tid') {
194		C::t('forum_post_location')->delete_by_tid($ids);
195	} elseif($idtype == 'authorid') {
196		C::t('forum_post_location')->delete_by_uid($ids);
197	}
198	if($replycredit_list) {
199		foreach(C::t('forum_replycredit')->fetch_all($tids) as $rule) {
200			$rule['extcreditstype'] = $rule['extcreditstype'] ? $rule['extcreditstype'] : $_G['setting']['creditstransextra'][10] ;
201			$replycredity_rule[$rule['tid']] = $rule;
202		}
203		foreach($replycredit_list AS $uid => $tid_credit) {
204			foreach($tid_credit AS $tid => $credit) {
205				$uid_credit[$replycredity_rule[$tid]['extcreditstype']] -= $credit;
206			}
207			updatemembercount($uid, $uid_credit, true);
208		}
209	}
210	if(!$recycle) {
211		deleteattach($ids, $idtype);
212	}
213	if($_G['setting']['plugins']['func'][HOOKTYPE]['deletepost']) {
214		hookscript('deletepost', 'global', 'funcs', array('param' => $hookparam, 'step' => 'delete'), 'deletepost');
215	}
216	return $count;
217}
218
219function deletethreadcover($tids) {
220	global $_G;
221	loadcache(array('threadtableids', 'posttableids'));
222	$threadtableids = !empty($_G['cache']['threadtableids']) ? $_G['cache']['threadtableids'] : array(0);
223	$deletecover = array();
224	foreach($threadtableids as $tableid) {
225		foreach(C::t('forum_thread')->fetch_all_by_tid($tids, 0, 0, $tableid) as $row) {
226			if($row['cover']) {
227				$deletecover[$row['tid']] = $row['cover'];
228			}
229		}
230	}
231	if($deletecover) {
232		foreach($deletecover as $tid => $cover) {
233			$filename = getthreadcover($tid, 0, 1);
234			$remote = $cover < 0 ? 1 : 0;
235			dunlink(array('attachment' => $filename, 'remote' => $remote, 'thumb' => 0));
236		}
237	}
238}
239
240function deletethread($tids, $membercount = false, $credit = false, $ponly = false) {
241	global $_G;
242	if($_G['setting']['plugins']['func'][HOOKTYPE]['deletethread']) {
243		$_G['deletethreadtids'] = & $tids;
244		$hookparam = func_get_args();
245		hookscript('deletethread', 'global', 'funcs', array('param' => $hookparam, 'step' => 'check'), 'deletethread');
246	}
247	if(!$tids) {
248		return 0;
249	}
250
251	$count = count($tids);
252	$arrtids = $tids;
253	$tids = dimplode($tids);
254
255	loadcache(array('threadtableids', 'posttableids'));
256	$threadtableids = !empty($_G['cache']['threadtableids']) ? $_G['cache']['threadtableids'] : array();
257	$posttableids = !empty($_G['cache']['posttableids']) ? $_G['cache']['posttableids'] : array('0');
258	if(!in_array(0, $threadtableids)) {
259		$threadtableids = array_merge(array(0), $threadtableids);
260	}
261
262	C::t('common_moderate')->delete($arrtids, 'tid');
263	C::t('forum_threadclosed')->delete($arrtids);
264
265	$cachefids = $atids = $fids = $postids = $threadtables = array();
266	foreach($threadtableids as $tableid) {
267		foreach(C::t('forum_thread')->fetch_all_by_tid($arrtids, 0, 0, $tableid) as $row) {
268			$atids[] = $row['tid'];
269			$row['posttableid'] = !empty($row['posttableid']) && in_array($row['posttableid'], $posttableids) ? $row['posttableid'] : '0';
270			$postids[$row['posttableid']][$row['tid']] = $row['tid'];
271			if($tableid) {
272				$fids[$row['fid']][] = $tableid;
273			}
274			$cachefids[$row['fid']] = $row['fid'];
275		}
276		if(!$tableid && !$ponly) {
277			$threadtables[] = $tableid;
278		}
279	}
280
281	if($credit || $membercount) {
282		$losslessdel = $_G['setting']['losslessdel'] > 0 ? TIMESTAMP - $_G['setting']['losslessdel'] * 86400 : 0;
283
284		$postlist = $uidarray = $tuidarray = $ruidarray = array();
285		foreach($postids as $posttableid => $posttabletids) {
286			foreach(C::t('forum_post')->fetch_all_by_tid($posttableid, $posttabletids, false) as $post) {
287				if($post['invisible'] != -1 && $post['invisible'] != -5) {
288					$postlist[] = $post;
289				}
290			}
291		}
292		foreach(C::t('forum_replycredit')->fetch_all($arrtids) as $rule) {
293			$rule['extcreditstype'] = $rule['extcreditstype'] ? $rule['extcreditstype'] : $_G['setting']['creditstransextra'][10] ;
294			$replycredit_rule[$rule['tid']] = $rule;
295		}
296
297		foreach($postlist as $post) {
298			if($post['dateline'] < $losslessdel) {
299				if($membercount) {
300					if($post['first']) {
301						updatemembercount($post['authorid'], array('threads' => -1, 'post' => -1), false);
302					} else {
303						updatemembercount($post['authorid'], array('posts' => -1), false);
304					}
305				}
306			} else {
307				if($credit) {
308					if($post['first']) {
309						$tuidarray[$post['fid']][] = $post['authorid'];
310					} else {
311						$ruidarray[$post['fid']][] = $post['authorid'];
312					}
313				}
314			}
315			if($credit || $membercount) {
316				if($post['authorid'] > 0 && $post['replycredit'] > 0) {
317					if($replycredit_rule[$post['tid']]['extcreditstype']) {
318						updatemembercount($post['authorid'], array($replycredit_rule[$post['tid']]['extcreditstype'] => (int)('-'.$post['replycredit'])));
319					}
320				}
321			}
322		}
323
324		if($credit) {
325			if($tuidarray || $ruidarray) {
326				require_once libfile('function/post');
327			}
328			if($tuidarray) {
329				foreach($tuidarray as $fid => $tuids) {
330					updatepostcredits('-', $tuids, 'post', $fid);
331				}
332			}
333			if($ruidarray) {
334				foreach($ruidarray as $fid => $ruids) {
335					updatepostcredits('-', $ruids, 'reply', $fid);
336				}
337			}
338			$auidarray = $attachtables = array();
339			foreach($atids as $tid) {
340				$attachtables[getattachtableid($tid)][] = $tid;
341			}
342			foreach($attachtables as $attachtable => $attachtids) {
343				foreach(C::t('forum_attachment_n')->fetch_all_by_id($attachtable, 'tid', $attachtids) as $attach) {
344					if($attach['dateline'] > $losslessdel) {
345						$auidarray[$attach['uid']] = !empty($auidarray[$attach['uid']]) ? $auidarray[$attach['uid']] + 1 : 1;
346					}
347				}
348			}
349			if($auidarray) {
350				$postattachcredits = !empty($_G['forum']['postattachcredits']) ? $_G['forum']['postattachcredits'] : $_G['setting']['creditspolicy']['postattach'];
351				updateattachcredits('-', $auidarray, $postattachcredits);
352			}
353		}
354	}
355
356	$relatecollection = C::t('forum_collectionthread')->fetch_all_by_tids($arrtids);
357	if(count($relatecollection) > 0) {
358		$collectionids = array();
359		foreach($relatecollection as $collection) {
360			$collectionids[] = $collection['ctid'];
361		}
362		$collectioninfo = C::t('forum_collection')->fetch_all($collectionids);
363		foreach($relatecollection as $collection) {
364			$decthread = C::t('forum_collectionthread')->delete_by_ctid_tid($collection['ctid'], $arrtids);
365			$lastpost = null;
366			if(in_array($collectioninfo[$collection['ctid']]['lastpost'], $arrtids) && ($collectioninfo[$collection['ctid']]['threadnum'] - $decthread) > 0) {
367				$collection_thread = C::t('forum_collectionthread')->fetch_by_ctid_dateline($collection['ctid']);
368				if($collection_thread) {
369					$thread = C::t('forum_thread')->fetch($collection_thread['tid']);
370					$lastpost = array(
371						'lastpost' => $thread['tid'],
372						'lastsubject' => $thread['subject'],
373						'lastposttime' => $thread['dateline'],
374						'lastposter' => $thread['authorid']
375					);
376				}
377			}
378			C::t('forum_collection')->update_by_ctid($collection['ctid'], -$decthread, 0, 0, 0, 0, 0, $lastpost);
379		}
380		C::t('forum_collectionrelated')->delete($arrtids);
381	}
382	if($cachefids) {
383		C::t('forum_thread')->clear_cache($cachefids, 'forumdisplay_');
384	}
385	if($ponly) {
386		if($_G['setting']['plugins']['func'][HOOKTYPE]['deletethread']) {
387			hookscript('deletethread', 'global', 'funcs', array('param' => $hookparam, 'step' => 'delete'), 'deletethread');
388		}
389		C::t('forum_thread')->update($arrtids, array('displayorder'=>-1, 'digest'=>0, 'moderated'=>1));
390		foreach($postids as $posttableid=>$oneposttids) {
391			C::t('forum_post')->update_by_tid($posttableid, $oneposttids, array('invisible' => '-1'));
392		}
393		return $count;
394	}
395
396	C::t('forum_replycredit')->delete($arrtids);
397	C::t('forum_post_location')->delete_by_tid($arrtids);
398	C::t('common_credit_log')->delete_by_operation_relatedid(array('RCT', 'RCA', 'RCB'), $arrtids);
399	deletethreadcover($arrtids);
400	foreach($threadtables as $tableid) {
401		C::t('forum_thread')->delete_by_tid($arrtids, false, $tableid);
402	}
403
404	if($atids) {
405		foreach($postids as $posttableid=>$oneposttids) {
406			deletepost($oneposttids, 'tid', false, $posttableid);
407		}
408		deleteattach($atids, 'tid');
409	}
410	if($fids) {
411		loadcache('forums');
412		foreach($fids as $fid => $tableids) {
413			if(empty($_G['cache']['forums'][$fid]['archive'])) {
414				continue;
415			}
416			foreach(C::t('forum_thread')->count_posts_by_fid($fid) as $row) {
417				C::t('forum_forum_threadtable')->insert(array(
418						'fid' => $fid,
419						'threadtableid' => $tableid,
420						'threads' => $row['threads'],
421						'posts' => $row['posts']
422				), false, true);
423			}
424		}
425	}
426
427	foreach(array('forum_forumrecommend', 'forum_polloption', 'forum_poll', 'forum_activity', 'forum_activityapply', 'forum_debate',
428		'forum_debatepost', 'forum_threadmod', 'forum_relatedthread',
429		'forum_pollvoter', 'forum_threadimage', 'forum_threadpreview') as $table) {
430		C::t($table)->delete_by_tid($arrtids);
431	}
432	C::t('forum_typeoptionvar')->delete_by_tid($arrtids);
433	C::t('forum_poststick')->delete_by_tid($arrtids);
434	C::t('home_feed')->delete_by_id_idtype($arrtids, 'tid');
435	C::t('common_tagitem')->delete(0, $arrtids, 'tid');
436	C::t('forum_threadrush')->delete($arrtids);
437	if($_G['setting']['plugins']['func'][HOOKTYPE]['deletethread']) {
438		hookscript('deletethread', 'global', 'funcs', array('param' => $hookparam, 'step' => 'delete'), 'deletethread');
439	}
440	return $count;
441}
442
443function deleteattach($ids, $idtype = 'aid') {
444	global $_G;
445	if(!$ids || !in_array($idtype, array('authorid', 'uid', 'tid', 'pid'))) {
446		return;
447	}
448	$idtype = $idtype == 'authorid' ? 'uid' : $idtype;
449
450	$pics = $attachtables = array();
451
452	foreach(C::t('forum_attachment')->fetch_all_by_id($idtype, $ids) as $attach) {
453		$attachtables[$attach['tableid']][] = $attach['aid'];
454	}
455
456	foreach($attachtables as $attachtable => $aids) {
457		if($attachtable == 127) {
458			continue;
459		}
460		$attachs = C::t('forum_attachment_n')->fetch_all($attachtable, $aids);
461		foreach($attachs as $attach) {
462			if($attach['picid']) {
463				$pics[] = $attach['picid'];
464			}
465			dunlink($attach);
466		}
467		C::t('forum_attachment_exif')->delete($aids);
468		C::t('forum_attachment_n')->delete($attachtable, $aids);
469	}
470	C::t('forum_attachment')->delete_by_id($idtype, $ids);
471	if($pics) {
472		$albumids = array();
473		C::t('home_pic')->delete($pics);
474		$query = C::t('home_pic')->fetch_all($pics);
475		foreach($query as $album) {
476			if(!in_array($album['albumid'], $albumids)) {
477				C::t('home_album')->update($album['albumid'], array('picnum' => C::t('home_pic')->check_albumpic($album['albumid'])));
478				$albumids[] = $album['albumid'];
479			}
480		}
481	}
482}
483
484function deletecomments($cids) {
485	global $_G;
486
487	$blognums = $newcids = $dels = $counts = array();
488	$allowmanage = checkperm('managecomment');
489
490	$query = C::t('home_comment')->fetch_all($cids);
491	$deltypes = array();
492	foreach($query as $value) {
493		if($allowmanage || $value['authorid'] == $_G['uid'] || $value['uid'] == $_G['uid']) {
494			$dels[] = $value;
495			$newcids[] = $value['cid'];
496			$deltypes[] = $value['idtype'].'_cid';
497			if($value['authorid'] != $_G['uid'] && $value['uid'] != $_G['uid']) {
498				$counts[$value['authorid']]['coef'] -= 1;
499			}
500			if($value['idtype'] == 'blogid') {
501				$blognums[$value['id']]++;
502			}
503		}
504	}
505
506	if(empty($dels)) return array();
507
508	C::t('home_comment')->delete($newcids);
509	for($i = 0; $i < count($newcids); $i++) {
510		C::t('common_moderate')->delete($newcids[$i], $deltypes[$i]);
511	}
512
513	if($counts) {
514		foreach ($counts as $uid => $setarr) {
515			batchupdatecredit('comment', $uid, array(), $setarr['coef']);
516		}
517	}
518	if($blognums) {
519		$nums = renum($blognums);
520		foreach ($nums[0] as $num) {
521			C::t('home_blog')->increase($nums[1][$num], 0, array('replynum' => -$num));
522		}
523	}
524	return $dels;
525}
526
527function deleteblogs($blogids) {
528	global $_G;
529
530	$blogs = $newblogids = $counts = array();
531	$allowmanage = checkperm('manageblog');
532
533	$query = C::t('home_blog')->fetch_all($blogids);
534	foreach($query as $value) {
535		if($allowmanage || $value['uid'] == $_G['uid']) {
536			$blogs[] = $value;
537			$newblogids[] = $value['blogid'];
538
539			if($value['status'] == 0) {
540				if($value['uid'] != $_G['uid']) {
541					$counts[$value['uid']]['coef'] -= 1;
542				}
543				$counts[$value['uid']]['blogs'] -= 1;
544			}
545		}
546	}
547	if(empty($blogs)) return array();
548
549	C::t('home_blog')->delete($newblogids);
550	C::t('home_blogfield')->delete($newblogids);
551	C::t('home_comment')->delete('', $newblogids, 'blogid');
552	C::t('home_feed')->delete_by_id_idtype($newblogids, 'blogid');
553	C::t('home_clickuser')->delete_by_id_idtype($newblogids, 'blogid');
554	C::t('common_moderate')->delete($newblogids, 'blogid');
555	C::t('common_moderate')->delete($newblogids, 'blogid_cid');
556
557	if($counts) {
558		foreach ($counts as $uid => $setarr) {
559			batchupdatecredit('publishblog', $uid, array('blogs' => $setarr['blogs']), $setarr['coef']);
560		}
561	}
562
563	C::t('common_tagitem')->delete(0, $newblogids, 'blogid');
564
565	return $blogs;
566}
567
568function deletefeeds($feedids) {
569	global $_G;
570
571	$allowmanage = checkperm('managefeed');
572
573	$feeds = $newfeedids = array();
574	$query = C::t('home_feed')->fetch_all($feedids);
575	foreach($query as $value) {
576		if($allowmanage || $value['uid'] == $_G['uid']) {
577			$newfeedids[] = $value['feedid'];
578			$feeds[] = $value;
579		}
580	}
581
582	if(empty($newfeedids)) return array();
583
584	C::t('home_feed')->delete($newfeedids);
585
586	return $feeds;
587}
588
589function deleteshares($sids) {
590	global $_G;
591
592	$allowmanage = checkperm('manageshare');
593
594	$shares = $newsids = $counts = array();
595	foreach(C::t('home_share')->fetch_all($sids) as $value) {
596		if($allowmanage || $value['uid'] == $_G['uid']) {
597			$shares[] = $value;
598			$newsids[] = $value['sid'];
599
600			if($value['uid'] != $_G['uid']) {
601				$counts[$value['uid']]['coef'] -= 1;
602			}
603			$counts[$value['uid']]['sharings'] -= 1;
604		}
605	}
606	if(empty($shares)) return array();
607
608	C::t('home_share')->delete($newsids);
609	C::t('home_comment')->delete('', $newsids, 'sid');
610	C::t('home_feed')->delete_by_id_idtype($newsids, 'sid');
611	C::t('common_moderate')->delete($newsids, 'sid');
612	C::t('common_moderate')->delete($newsids, 'sid_cid');
613
614	if($counts) {
615		foreach ($counts as $uid => $setarr) {
616			batchupdatecredit('createshare', $uid, array('sharings' => $setarr['sharings']), $setarr['coef']);
617		}
618	}
619
620	return $shares;
621}
622
623function deletedoings($ids) {
624	global $_G;
625
626	$allowmanage = checkperm('managedoing');
627
628	$doings = $newdoids = $counts = array();
629	$query = C::t('home_doing')->fetch_all($ids);
630	foreach($query as $value) {
631		if($allowmanage || $value['uid'] == $_G['uid']) {
632			$doings[] = $value;
633			$newdoids[] = $value['doid'];
634
635			if($value['uid'] != $_G['uid']) {
636				$counts[$value['uid']]['coef'] -= 1;
637			}
638			$counts[$value['uid']]['doings'] -= 1;
639		}
640	}
641
642	if(empty($doings)) return array();
643
644	C::t('home_doing')->delete($newdoids);
645	C::t('home_docomment')->delete_by_doid_uid($newdoids);
646	C::t('home_feed')->delete_by_id_idtype($newdoids, 'doid');
647	C::t('common_moderate')->delete($newdoids, 'doid');
648
649	if($counts) {
650		foreach ($counts as $uid => $setarr) {
651			if ($uid) {
652				batchupdatecredit('doing', $uid, array('doings' => $setarr['doings']), $setarr['coef']);
653				$lastdoing = C::t('home_doing')->fetch_all_by_uid_doid($uid, '', 'dateline', 0, 1, true, true);
654				$setarr = array('recentnote'=>$lastdoing[0]['message'], 'spacenote'=>$lastdoing[0]['message']);
655				C::t('common_member_field_home')->update($_G['uid'], $setarr);
656			}
657		}
658	}
659
660	return $doings;
661}
662
663function deletespace($uid) {
664	global $_G;
665
666	$allowmanage = checkperm('managedelspace');
667
668	if($allowmanage) {
669		C::t('common_member')->update($uid, array('status' => 1));
670		manyoulog('user', $uid, 'delete');
671		return true;
672	} else {
673		return false;
674	}
675}
676
677function deletepics($picids) {
678	global $_G;
679
680	$albumids = $sizes = $pics = $newids = array();
681	$allowmanage = checkperm('managealbum');
682
683	$haveforumpic = false;
684	$query = C::t('home_pic')->fetch_all($picids);
685	foreach($query as $value) {
686		if($allowmanage || $value['uid'] == $_G['uid']) {
687			$pics[] = $value;
688			$newids[] = $value['picid'];
689			$sizes[$value['uid']] = $sizes[$value['uid']] + $value['size'];
690			$albumids[$value['albumid']] = $value['albumid'];
691			if(!$haveforumpic && $value['remote'] > 1) {
692				$haveforumpic = true;
693			}
694		}
695	}
696	if(empty($pics)) return array();
697
698	C::t('home_pic')->delete($newids);
699	if($haveforumpic) {
700		for($i = 0;$i < 10;$i++) {
701			C::t('forum_attachment_n')->reset_picid($i, $newids);
702		}
703	}
704
705	C::t('home_comment')->delete('', $newids, 'picid');
706	C::t('home_feed')->delete_by_id_idtype($newids, 'picid');
707	C::t('home_clickuser')->delete_by_id_idtype($newids, 'picid');
708	C::t('common_moderate')->delete($newids, 'picid');
709	C::t('common_moderate')->delete($newids, 'picid_cid');
710
711	if($sizes) {
712		foreach ($sizes as $uid => $setarr) {
713			$attachsize = intval($sizes[$uid]);
714			updatemembercount($uid, array('attachsize' => -$attachsize), false);
715		}
716	}
717
718	require_once libfile('function/spacecp');
719	foreach ($albumids as $albumid) {
720		if($albumid) {
721			album_update_pic($albumid);
722		}
723	}
724
725	deletepicfiles($pics);
726
727	return $pics;
728}
729
730function deletepicfiles($pics) {
731	global $_G;
732	$remotes = array();
733	include_once libfile('function/home');
734	foreach ($pics as $pic) {
735		pic_delete($pic['filepath'], 'album', $pic['thumb'], $pic['remote']);
736	}
737}
738
739function deletealbums($albumids) {
740	global $_G;
741
742	$sizes = $dels = $newids = $counts = array();
743	$allowmanage = checkperm('managealbum');
744
745	$albums = C::t('home_album')->fetch_all($albumids);
746	foreach($albums as $value) {
747		if($value['albumid']) {
748			if($allowmanage || $value['uid'] == $_G['uid']) {
749				$dels[] = $value;
750				$newids[] = $value['albumid'];
751				if(!empty($value['pic'])) {
752					include_once libfile('function/home');
753					pic_delete($value['pic'], 'album', 0, ($value['picflag'] == 2 ? 1 : 0));
754				}
755			}
756			$counts[$value['uid']]['albums'] -= 1;
757		}
758	}
759
760	if(empty($dels)) return array();
761
762	$pics = $picids = array();
763	$query = C::t('home_pic')->fetch_all_by_albumid($newids);
764	foreach($query as $value) {
765		$pics[] = $value;
766		$picids[] = $value['picid'];
767		$sizes[$value['uid']] = $sizes[$value['uid']] + $value['size'];
768	}
769
770	if($picids) {
771		deletepics($picids);
772	}
773	C::t('home_album')->delete($newids);
774	C::t('home_feed')->delete_by_id_idtype($newids, 'albumid');
775	if($picids) {
776		C::t('home_clickuser')->delete_by_id_idtype($picids, 'picid');
777	}
778
779	if($sizes) {
780		foreach ($sizes as $uid => $value) {
781			$attachsize = intval($sizes[$uid]);
782			$albumnum = $counts[$uid]['albums'] ? $counts[$uid]['albums'] : 0;
783			updatemembercount($uid, array('albums' => $albumnum, 'attachsize' => -$attachsize), false);
784		}
785	}
786	return $dels;
787}
788
789function deletetrasharticle($aids) {
790	global $_G;
791
792	require_once libfile('function/home');
793	$articles = $trashid = $pushs = $dels = array();
794	foreach(C::t('portal_article_trash')->fetch_all($aids) as $value) {
795		$dels[$value['aid']] = $value['aid'];
796		$article = dunserialize($value['content']);
797		$articles[$article['aid']] = $article;
798		if(!empty($article['idtype'])) $pushs[$article['idtype']][] = $article['id'];
799		if($article['pic']) {
800			pic_delete($article['pic'], 'portal', $article['thumb'], $article['remote']);
801		}
802	}
803
804	if($dels) {
805		C::t('portal_article_trash')->delete($dels, 'UNBUFFERED');
806		deletearticlepush($pushs);
807		deletearticlerelated($dels);
808	}
809
810	return $articles;
811}
812
813function deletearticle($aids, $istrash = true) {
814	global $_G;
815
816	if(empty($aids)) return false;
817	$trasharr = $article = $bids = $dels = $attachment = $attachaid = $catids = $pushs = array();
818	$query = C::t('portal_article_title')->fetch_all($aids);
819	foreach($query as $value) {
820		$catids[] = intval($value['catid']);
821		$dels[$value['aid']] = $value['aid'];
822		$article[] = $value;
823		if(!empty($value['idtype'])) $pushs[$value['idtype']][] = $value['id'];
824	}
825	if($dels) {
826		foreach($article as $key => $value) {
827			if($istrash) {
828				$trasharr[] = array('aid' => $value['aid'], 'content'=>serialize($value));
829			} elseif($value['pic']) {
830				pic_delete($value['pic'], 'portal', $value['thumb'], $value['remote']);
831				$attachaid[] = $value['aid'];
832			}
833		}
834		if($istrash && $trasharr) {
835			C::t('portal_article_trash')->insert_batch($trasharr);
836		} else {
837			deletearticlepush($pushs);
838			deletearticlerelated($dels);
839		}
840
841		C::t('portal_article_title')->delete($dels);
842		C::t('common_moderate')->delete($dels, 'aid');
843
844		$catids = array_unique($catids);
845		if($catids) {
846			foreach($catids as $catid) {
847				$cnt = C::t('portal_article_title')->fetch_count_for_cat($catid);
848				C::t('portal_category')->update($catid, array('articles'=>dintval($cnt)));
849			}
850		}
851	}
852	return $article;
853}
854
855function deletearticlepush($pushs) {
856	if(!empty($pushs) && is_array($pushs)) {
857		foreach($pushs as $idtype=> $fromids) {
858			switch ($idtype) {
859				case 'blogid':
860					if(!empty($fromids)) C::t('home_blogfield')->update($fromids, array('pushedaid'=>'0'));
861					break;
862				case 'tid':
863					if(!empty($fromids)) C::t('forum_thread')->update($fromids, array('pushedaid'=>'0'));
864					break;
865			}
866		}
867	}
868}
869
870function deletearticlerelated($dels) {
871
872	C::t('portal_article_count')->delete($dels);
873	C::t('portal_article_content')->delete($dels);
874
875	if($attachment = C::t('portal_attachment')->fetch_all_by_aid($dels)) {
876		require_once libfile('function/home');
877		foreach ($attachment as $value) {
878			pic_delete($value['attachment'], 'portal', $value['thumb'], $value['remote']);
879		}
880		C::t('portal_attachment')->delete(array_keys($attachment));
881	}
882
883	C::t('portal_comment')->delete_by_id_idtype($dels, 'aid');
884	C::t('common_moderate')->delete($dels, 'aid_cid');
885
886	C::t('portal_article_related')->delete_by_aid_raid($dels);
887
888}
889
890function deleteportaltopic($dels) {
891	if(empty($dels)) return false;
892	$targettplname = array();
893	foreach ((array)$dels as $key => $value) {
894		$targettplname[] = 'portal/portal_topic_content_'.$value;
895	}
896	C::t('common_diy_data')->delete($targettplname, null);
897
898	require_once libfile('class/blockpermission');
899	$tplpermission = & template_permission::instance();
900	$templates = array();
901	$tplpermission->delete_allperm_by_tplname($targettplname);
902
903	deletedomain($dels, 'topic');
904	C::t('common_template_block')->delete_by_targettplname($targettplname);
905
906	require_once libfile('function/home');
907
908	$picids = array();
909	foreach(C::t('portal_topic')->fetch_all($dels) as $value) {
910		if($value['picflag'] != '0') pic_delete(str_replace('portal/', '', $value['cover']), 'portal', 0, $value['picflag'] == '2' ? '1' : '0');
911	}
912
913	$picids = array();
914	foreach(C::t('portal_topic_pic')->fetch_all($dels) as $value) {
915		$picids[] = $value['picid'];
916		pic_delete($value['filepath'], 'portal', $value['thumb'], $value['remote']);
917	}
918	if (!empty($picids)) {
919		C::t('portal_topic_pic')->delete($picids, true);
920	}
921
922
923	C::t('portal_topic')->delete($dels);
924	C::t('portal_comment')->delete_by_id_idtype($dels, 'topicid');
925	C::t('common_moderate')->delete($dels, 'topicid_cid');
926
927	include_once libfile('function/block');
928	block_clear();
929
930	include_once libfile('function/cache');
931	updatecache('diytemplatename');
932}
933
934function deletedomain($ids, $idtype) {
935	if($ids && $idtype) {
936		C::t('common_domain')->delete_by_id_idtype($ids, $idtype);
937	}
938}
939
940function deletecollection($ctid) {
941	$tids = array();
942	$threadlist = C::t('forum_collectionthread')->fetch_all_by_ctid($ctid);
943	$tids = array_keys($threadlist);
944
945	deleterelatedtid($tids, $ctid);
946
947	$collectionteamworker = C::t('forum_collectionteamworker')->fetch_all_by_ctid($ctid);
948	foreach ($collectionteamworker as $worker) {
949		notification_add($worker['uid'], "system", 'collection_removed', array('ctid'=>$collectiondata['ctid'], 'collectionname'=>$collectiondata['name']), 1);
950	}
951
952	C::t('forum_collectionthread')->delete_by_ctid($ctid);
953	C::t('forum_collectionfollow')->delete_by_ctid($ctid);
954	C::t('forum_collectioncomment')->delete_by_ctid($ctid);
955	C::t('forum_collectionteamworker')->delete_by_ctid($ctid);
956	C::t('forum_collectioninvite')->delete_by_ctid($ctid);
957	C::t('forum_collection')->delete($ctid, true);
958}
959
960function deleterelatedtid($tids, $ctid) {
961	$loadreleated = C::t('forum_collectionrelated')->fetch_all($tids, true);
962	foreach($loadreleated as $loadexist) {
963		if($loadexist['tid']) {
964			$collectionlist = explode("\t", $loadexist['collection']);
965			if(count($collectionlist)>0) {
966				foreach ($collectionlist as $collectionkey=>$collectionvalue) {
967					if ($collectionvalue == $ctid) {
968						unset($collectionlist[$collectionkey]);
969						break;
970					}
971				}
972			}
973			$newcollection = implode("\t", $collectionlist);
974			if (trim($newcollection) == '') {
975				C::t('forum_collectionrelated')->delete($loadexist['tid']);
976				C::t('forum_thread')->update_status_by_tid($loadexist['tid'], '1111111011111111', '&');
977			} else {
978				C::t('forum_collectionrelated')->update_collection_by_ctid_tid($newcollection, $loadexist['tid'], true);
979			}
980		}
981	}
982}
983?>