function block_attachments($paramarr) { global $_SGLOBAL, $_SGET; if(empty($paramarr['sql'])) { $sql = array(); $sql['select'] = 'SELECT *'; $sql['from'] = 'FROM '.tname('attachments').' i'; $sql['join'] = ''; $wherearr = array(); $showpic = 0; //where if(!empty($paramarr['aid'])) { $paramarr['aid'] = getdotstring($paramarr['aid'], 'int'); if($paramarr['aid']) $wherearr[] = 'aid IN ('.$paramarr['aid'].')'; } else { //作者 if(!empty($paramarr['uid'])) { $paramarr['uid'] = getdotstring($paramarr['uid'], 'int'); if($paramarr['uid']) $wherearr[] = 'i.uid IN ('.$paramarr['uid'].')'; } //是否显示图片 if(!empty($paramarr['showpic'])) { $wherearr[] = 'isimage=1'; } //分类 if(!empty($paramarr['catid'])) { $paramarr['catid'] = getdotstring($paramarr['catid'], 'int'); if($paramarr['catid']) $wherearr[] = 'catid IN ('.$paramarr['catid'].')'; } //资讯 if(!empty($paramarr['itemid'])) { $paramarr['itemid'] = getdotstring($paramarr['itemid'], 'int'); if($paramarr['itemid']) $wherearr[] = 'itemid IN ('.$paramarr['itemid'].')'; } //系统分类 if(empty($paramarr['type'])) { if(!empty($paramarr['type'])) { $wherearr[] = 'type=\''.$paramarr['type'].'\''; } } if(!empty($paramarr['dateline'])) { $paramarr['dateline'] = intval($paramarr['dateline']); if($paramarr['dateline']) $wherearr[] = 'dateline >= '.($_SGLOBAL['timestamp']-$paramarr['dateline']); } } if(!empty($wherearr)) $sql['where'] = 'WHERE '.implode(' AND ', $wherearr); //order if(!empty($paramarr['order'])) { $sql['order'] = 'ORDER BY '.$paramarr['order']; } //limit if(!empty($paramarr['perpage'])) { $paramarr['perpage'] = intval($paramarr['perpage']); if(empty($paramarr['perpage'])) $paramarr['perpage'] = 20; if(empty($_SGET['page'])) $_SGET['page'] = 1; $_SGET['page'] = intval($_SGET['page']); if($_SGET['page'] < 1) $_SGET['page'] = 1; $start = ($_SGET['page']-1)*$paramarr['perpage']; $sql['limit'] = 'LIMIT '.$start.','.$paramarr['perpage']; } else { if(empty($paramarr['limit'])) { $sql['limit'] = 'LIMIT 0,1'; } else { $paramarr['limit'] = getdotstring($paramarr['limit'], 'int', true, array(), 1, false); if($paramarr['limit']) { $sql['limit'] = 'LIMIT '.$paramarr['limit']; } else { $sql['limit'] = 'LIMIT 0,1'; } } } //query $sqlstring = implode(' ', $sql); //multi $listcount = 1; if(!empty($paramarr['perpage'])) { $listcount = $_SGLOBAL['db']->result($_SGLOBAL['db']->query('SELECT COUNT(*) FROM '.tname('attachments').' '.$sql['where']), 0); if($listcount) { $urlarr = $_SGET; unset($urlarr['page']); $theblockarr['multipage'] = multi($listcount, $paramarr['perpage'], $_SGET['page'], $urlarr, 0); } } } else { include_once(S_ROOT.'./function/block_sql.func.php'); list($sqlstring, $listcount) = runsql($paramarr); if(!empty($paramarr['perpage'])) { if($listcount) { $urlarr = $_SGET; unset($urlarr['page']); $theblockarr['multipage'] = multi($listcount, $paramarr['perpage'], $_SGET['page'], $urlarr, 0); } } } if($listcount) { //预处理 if(empty($paramarr['subjectdot'])) $paramarr['subjectdot'] = 0; if(!empty($paramarr['showcategory'])) { include_once(S_ROOT.'./data/system/category.cache.php'); } $query = $_SGLOBAL['db']->query($sqlstring); $allitemids = $aids = array(); while($value = $_SGLOBAL['db']->fetch_array($query)) { //生成HTML时 if(defined('CREATEHTML')) { $_SGLOBAL['item_cache']['viewnews_'.$value['itemid']] = array('catid' => $value['catid'], 'dateline' => $value['dateline']); } //图片标题处理 $value['subjectall'] = $value['subject']; if(!empty($value['subject']) && !empty($paramarr['subjectlen'])) { $value['subject'] = cutstr($value['subject'], $paramarr['subjectlen'], $paramarr['subjectdot']); } //链接 $value['url'] = geturl('action/viewnews/itemid/'.$value['itemid']); if(!in_array($value['itemid'],$allitemids)) $allitemids[] = $value['itemid']; //分类名 if(!empty($_SGLOBAL['category'][$value['catid']])) $value['catname'] = $_SGLOBAL['category'][$value['catid']]; $theblockarr[$value['aid']] = $value; } $zjitemarr = array(); //取资讯标题 if(!empty($paramarr['newssubject'])) { if(!empty($allitemids)) { $query = $_SGLOBAL['db']->query('SELECT * FROM '.tname('spaceitems').' WHERE itemid IN (\''.implode('\',\'', $allitemids).'\') ORDER BY itemid'); while ($value = $_SGLOBAL['db']->fetch_array($query)) { $zjitemarr[$value['itemid']]['subject'] = $zjitemarr[$value['itemid']]['subjectall'] = $value['subject']; if(!empty($value['subject']) && !empty($paramarr['subjectlen'])) { $zjitemarr[$value['itemid']]['subject'] = cutstr($value['subject'], $paramarr['subjectlen'], $paramarr['subjectdot']); } } } } //分页内容处理/取第一页 if(!empty($paramarr['showdetail'])) { if(!empty($allitemids)) { $theitemarr = array(); $query = $_SGLOBAL['db']->query('SELECT * FROM '.tname('spacenews').' WHERE itemid IN (\''.implode('\',\'', $allitemids).'\') ORDER BY nid'); while ($value = $_SGLOBAL['db']->fetch_array($query)) { if(empty($theitemarr[$value['itemid']])) { if(!empty($value['message']) && !empty($paramarr['messagelen'])) { $value['message'] = strip_tags(trim($value['message'])); $value['message'] = trim(cutstr($value['message'], $paramarr['messagelen'], $paramarr['messagedot'])); } $theitemarr[$value['itemid']] = 1; $zjitemarr[$value['itemid']]['message'] = $value['message']; } } } } if(!empty($paramarr['newssubject']) || !empty($paramarr['showdetail'])){ foreach($theblockarr as $key => $value){ $theblockarr[$key]['subject'] = $zjitemarr[$value['itemid']]['subject']; $theblockarr[$key]['subjectall'] = $zjitemarr[$value['itemid']]['subjectall']; $theblockarr[$key]['message'] = $zjitemarr[$value['itemid']]['message']; } } } return $theblockarr; } |