📄 itemcp.php
字号:
<?php
!function_exists('usermsg') && exit('Forbidden');
$basename .= '&type='.$type;
!N_InArray($type,array('blog','bookmark','file','goods','music','photo')) && usermsg('undefined_action');
$articleurl = $db_articleurl ? 'article.php' : 'blog.php?do=showone';
if ($job != 'update') {
InitGP(array('page','cid','dirid','ifcheck','orderby','sc'));
$sltorder = $sltsc = $sltcheck = $itemdb = array();
$cateop = $cateslt = $dirop = $dirslt = $sql = $addpage = $pages = '';
include_once(D_P."data/cache/forum_cache_$type.php");
$catedb = ${strtoupper('_'.$type)};
foreach ($catedb as $key => $value) {
$add = '';
for ($i=0;$i<$value['type'];$i++) {
$add .= '>';
}
$cateslt = ($value['cid'] == $cid) ? ' SELECTED' : '';
$cateop .= "<option value=\"$value[cid]\"$cateslt>$add $value[name]</option>";
}
$dirdb = $admindb['dirdb'] ? unserialize($admindb['dirdb']) : array();
$dirdb = (array)$dirdb[$type];
foreach ($dirdb as $key => $value) {
$dirslt = ($value['typeid'] == $dirid) ? ' SELECTED' : '';
$dirop .= "<option value=\"$value[typeid]\"$dirslt>$value[name]</option>";
}
$sltorder[$orderby] = $sltsc[$sc] = $sltcheck[$ifcheck] = ' SELECTED';
if (strlen($cid) > 0 && (int)$cid > -1) {
$sql .= ($sql ? ' AND' : '')." cid='$cid'";
$addpage .= "cid=$cid&";
}
if (strlen($dirid) > 0 && (int)$dirid > -1) {
$sql .= ($sql ? ' AND' : '')." dirid='$dirid'";
$addpage .= "cid=$dirid&";
}
if (strlen($ifcheck) > 0 && (int)$ifcheck > -1) {
$sql .= ($sql ? ' AND' : '')." ifcheck='$ifcheck'";
$addpage .= "ifcheck=$ifcheck&";
}
$sql && $sql = ' AND '.$sql;
$orderby != 'lastpost' && $orderby != 'replies' && $orderby != 'hits' && $orderby = 'postdate';
$sc != 'asc' && $sc = 'desc';
!$db_perpage && $db_perpage = 30;
$addpage .= ($orderby == 'postdate' ? '' : "orderby=$orderby&")."sc=$sc&";
$orderby = " ORDER BY $orderby $sc";
(int)$page<1 && $page = 1;
$limit = 'LIMIT '.($page-1)*$db_perpage.",$db_perpage";
$query = $db->query("SELECT itemid,cid,dirid,subject,ifcheck,postdate,replies,hits FROM pw_items WHERE uid='$admin_uid' AND type='$type'$sql $orderby $limit");
while ($rt = $db->fetch_array($query)) {
$rt['cate'] = $rt['cid'] ? $catedb[$rt['cid']]['name'] : $ulang['none'];
$rt['dir'] = $rt['dirid'] ? $dirdb[$rt['dirid']]['name'] : $ulang['none'];
$rt['ifcheck'] = $ulang['ifcheck_'.$rt['ifcheck']];
$rt['postdate'] = get_date($rt['postdate'],'Y-m-d');
$rt['subject'] = str_replace(array("\r","\n"),'',$rt['subject']);
$rt['subject'] = substrs($rt['subject'],40);
$itemdb[] = $rt;
}
$db->free_result($query);
$count = $db->get_value("SELECT COUNT(*) FROM pw_items WHERE uid='$admin_uid' AND type='$type'$sql");
if ($count > $db_perpage) {
require_once(R_P.'mod/page_mod.php');
$pages = page($count,$page,$db_perpage,"$basename&$addpage");
}
include PrintEot('itemcp');footer();
} else {
InitGP(array('selid','ntype','atccid'),'P');
$tids = '';
!is_array($selid) && $selid = array();
foreach ($selid as $value) {
if ((int)$value > 0) {
$tids .= ($tids ? ',' : '')."'$value'";
}
}
!$tids && usermsg('operate_error');
$tids = strpos($tids,',')===false ? "=$tids" : " IN ($tids)";
$query = $db->query("SELECT itemid,cid,uid,ifcheck FROM pw_items WHERE itemid{$tids}");
$catedb = array();
if ($ntype == 'delete') {
$itemids = '';
$userdb = $typedb = $typesdb = array();
while ($rt = $db->fetch_array($query)) {
if ($rt['ifcheck']) {
$catedb[$rt['cid']]['num']++;
$userdb[$rt['uid']]['items']++;
$itemids .= ($itemids ? ',' : '')."'$rt[itemid]'";
}
}
if ($itemids) {
$itemids = strpos($itemids,',')===false ? "=$itemids" : " IN ($itemids)";
$query = $db->query("SELECT uid FROM pw_comment WHERE itemid{$itemids}");
while ($rt = $db->fetch_array($query)) {
$userdb[$rt['uid']]['comments']++;
}
$query = $db->query("SELECT tagid,tagtype,COUNT(*) AS tagnum FROM pw_taginfo WHERE itemid{$itemids} GROUP BY tagid");
while ($rt = $db->fetch_array($query)) {
if ($rt['tagid'] && $rt['tagtype']) {
$tagnum = "{$rt[tagtype]}num";
$db->update("UPDATE pw_tags SET allnum=allnum-$rt[tagnum],$tagnum=$tagnum-$rt[tagnum] WHERE tagid='$rt[tagid]'");
}
}
}
$query = $db->query("SELECT attachurl,ifthumb FROM pw_upload WHERE itemid{$tids}");
while ($rt = $db->fetch_array($query)) {
P_unlink("$attachdir/$rt[attachurl]");
if ($rt['ifthumb'] == 1) {
$ext = substr(strrchr($rt['attachurl'],'.'),1);
$name = substr($rt['attachurl'],0,strrpos($rt['attachurl'],'.'));
P_unlink(R_P."$attachdir/{$name}_thumb.{$ext}");
}
}
$db->free_result($query);
foreach ($catedb as $key => $value) {
$db->update("UPDATE pw_categories SET counts=counts-'$value[num]' WHERE cid='$key'");
}
foreach ($userdb as $key => $value) {
$updatesql = '';
if ((int)$value['items'] > 0) {
$updatesql .= ($updatesql ? ',' : '')."{$type}s={$type}s-'$value[items]',items=items-'$value[items]'";
}
if ((int)$value['comments'] > 0) {
$updatesql .= ($updatesql ? ',' : '')."comments=comments-'$value[comments]'";
}
if (!empty($typesdb)) {
foreach ($typesdb as $v) {
if ($value[$v]) {
$updatesql .= ($updatesql ? ',' : '')."$v=$v-'$value[$v]'";
}
}
}
$updatesql && $db->update("UPDATE pw_user SET $updatesql WHERE uid='$key'");
}
$db->update("DELETE FROM pw_carticle WHERE itemid{$tids}");
$db->update("DELETE FROM pw_collections WHERE itemid{$tids}");
$db->update("DELETE FROM pw_comment WHERE itemid{$tids}");
$db->update("DELETE FROM pw_footprint WHERE itemid{$tids}");
$db->update("DELETE FROM pw_items WHERE itemid{$tids}");
$db->update("DELETE FROM pw_$type WHERE itemid{$tids}");
$db->update("DELETE FROM pw_taginfo WHERE itemid{$tids}");
$db->update("DELETE FROM pw_tblog WHERE itemid{$tids}");
$db->update("DELETE FROM pw_upload WHERE itemid{$tids}");
updatecache_cate($type);
} elseif ($ntype == 'setcid') {
while ($rt = $db->fetch_array($query)) {
if ($rt['ifcheck'] && $rt['cid'] != $atccid) {
$catedb[$rt['cid']]++;
$itemids .= ($itemids ? ',' : '')."'$rt[itemid]'";
}
}
$db->free_result($query);
if ($itemids) {
$itemids = strpos($itemids,',')===false ? "=$itemids" : " IN ($itemids)";
foreach ($catedb as $key => $value) {
$db->update("UPDATE pw_categories SET counts=counts-'$value' WHERE cid='$key'");
}
$db->update("UPDATE pw_items SET cid='".(int)$atccid."' WHERE itemid{$itemids}");
updatecache_cate($type);
}
}
usermsg('operate_success',"$basename");
}
function updatecache_cate($catetype = null){
global $db;
$where = !empty($catetype) ? "WHERE catetype='$catetype'" : '';
$db->update("UPDATE pw_categories SET type='0',cupinfo='' $where".($where ? " AND" : "WHERE")." cup='0'");
$catedb = $subdb = array();
$typedb = array('blog','bookmark','file','goods','music','photo','team','user');
$query = $db->query("SELECT cid,cup,type,name,descrip,cupinfo,counts,vieworder,_ifshow,catetype,fid FROM pw_categories $where ORDER BY vieworder,cid");
while ($rt = $db->fetch_array($query)) {
if (in_array($rt['catetype'],$typedb)) {
P_unlink(D_P."data/cache/cate_cid_$rt[cid].php");
!is_array(${'_'.$rt['catetype']}) && ${'_'.$rt['catetype']} = array();
$rt['name'] = Char_cv($rt['name'],'N');
$rt['descrip'] = Char_cv($rt['descrip'],'N');
if ($rt['cup'] == 0) {
$catedb[] = $rt;
} else {
$subdb[$rt['cup']][] = $rt;
}
}
}
foreach ($catedb as $cate) {
if (empty($cate)) continue;
${'_'.$cate['catetype']}[$cate['cid']] = $cate;
if (empty($subdb[$cate['cid']])) continue;
${'_'.$cate['catetype']} += get_subcate($subdb,$cate['cid']);
}
foreach ($typedb as $value) {
if (!empty($catetype) && $value != $catetype) {
continue;
}
$writecache = '$_'.strtoupper($value).' = '.N_var_export(${'_'.$value}).";\r\n";
writeover(D_P."data/cache/forum_cache_{$value}.php","<?php\r\n$writecache?>");
}
}
function get_subcate($array,$cid){
global $db;
static $type = 0;
static $cupinfo = null;
$type++;
$cupinfo .= (empty($cupinfo) ? '' : ',').$cid;
foreach ($array[$cid] as $cate) {
if (empty($cate)) continue;
$sql = '';
if ($cate['type'] != $type) {
$cate['type'] = $type;
$sql .= "type='$type'";
}
if ($cate['cupinfo'] != $cupinfo) {
$cate['cupinfo'] = $cupinfo;
$sql && $sql .= ',';
$sql .= "cupinfo='$cupinfo'";
}
$sql && $db->update("UPDATE pw_categories SET $sql WHERE cid='$cate[cid]'");
${'_'.$cate['catetype']}[$cate['cid']] = $cate;
if (empty($array[$cate['cid']])) {
$type = 0;
$cupinfo = null;
continue;
}
${'_'.$cate['catetype']} += get_subcate($array,$cate['cid']);
}
return ${'_'.$cate['catetype']};
}
function N_var_export($input,$f = 1,$t = null) {
$output = '';
if (is_array($input)) {
$output .= "array(\r\n";
foreach ($input as $key => $value) {
$output .= $t."\t".N_var_export($key,$f,$t."\t").' => '.N_var_export($value,$f,$t."\t");
$output .= ",\r\n";
}
$output .= $t.')';
} elseif (is_string($input)) {
$output .= $f ? "'".str_replace(array("\\","'"),array("\\\\","\'"),$input)."'" : "'$input'";
} elseif (is_int($input) || is_double($input)) {
$output .= "'".(string)$input."'";
} elseif (is_bool($input)) {
$output .= $input ? 'true' : 'false';
} else {
$output .= 'NULL';
}
return $output;
}
?>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -