本帖最后由 危险的蘑菇 于 2010-6-29 18:30 编辑
- function block_spacenews($paramarr) {
- global $_SGLOBAL, $_SGET;
-
- $_SGLOBAL['attachsql'] = 'a.aid AS a_aid, a.type AS a_type, a.itemid AS a_itemid, a.uid AS a_uid, a.dateline AS a_dateline, a.filename AS a_filename, a.subject AS a_subject, a.attachtype AS a_attachtype, a.isimage AS a_isimage, a.size AS a_size, a.filepath AS a_filepath, a.thumbpath AS a_thumbpath, a.downloads AS a_downloads';
-
- if(empty($paramarr['sql'])) {
- $sql = array();
- $sql['select'] = 'SELECT i.*';
- if(!empty($paramarr['ss6'])) {
- $sql['from'] = 'FROM blog_spaceitems i';
- }else{
- $sql['from'] = 'FROM '.tname('spaceitems').' i';
- }
- $sql['join'] = '';
-
- $wherearr = array();
- $showpic = 0;
-
- //where
- if(!empty($paramarr['itemid'])) {
- $paramarr['itemid'] = getdotstring($paramarr['itemid'], 'int');
- if($paramarr['itemid']) $wherearr[] = 'i.itemid IN ('.$paramarr['itemid'].')';
- } else {
- //作者
- if(!empty($paramarr['uid'])) {
- $paramarr['uid'] = getdotstring($paramarr['uid'], 'int');
- if($paramarr['uid']) $wherearr[] = 'i.uid IN ('.$paramarr['uid'].')';
- }
-
- //分类
- if(!empty($paramarr['catid'])) {
- $paramarr['catid'] = getdotstring($paramarr['catid'], 'int');
- if($paramarr['catid']) $wherearr[] = 'i.catid IN ('.$paramarr['catid'].')';
- }
-
- //限制
- if(empty($paramarr['catid'])) {
- if(!empty($paramarr['type'])) {
- $wherearr[] = 'i.type=\''.$paramarr['type'].'\'';
- }
- }
- //站点审核
- if(!empty($paramarr['grade'])) {
- $paramarr['grade'] = getdotstring($paramarr['grade'], 'int');
- if(!empty($paramarr['grade'])) $wherearr[] = 'i.grade IN ('.$paramarr['grade'].')';
- } else {
- if(empty($paramarr['uid'])) {
- if(!empty($_SCONFIG['needcheck'])) {
- $wherearr[] = 'i.grade>0';
- }
- }
- }
-
- if(!empty($paramarr['digest'])) {
- $paramarr['digest'] = getdotstring($paramarr['digest'], 'int');
- if($paramarr['digest']) $wherearr[] = 'i.digest IN ('.$paramarr['digest'].')';
- }
-
- if(!empty($paramarr['top'])) {
- $paramarr['top'] = getdotstring($paramarr['top'], 'int');
- if($paramarr['top']) $wherearr[] = 'i.top IN ('.$paramarr['top'].')';
- }
-
- if(!empty($paramarr['dateline'])) {
- $paramarr['dateline'] = intval($paramarr['dateline']);
- if($paramarr['dateline']) $wherearr[] = 'i.dateline >= '.($_SGLOBAL['timestamp']-$paramarr['dateline']);
- }
-
- if(!empty($paramarr['lastpost'])) {
- $paramarr['lastpost'] = intval($paramarr['lastpost']);
- if($paramarr['lastpost']) $wherearr[] = 'i.lastpost >= '.($_SGLOBAL['timestamp']-$paramarr['lastpost']);
- }
-
- $scopequery = getscopequery('i', 'viewnum', $paramarr);
- if(!empty($scopequery)) $wherearr[] = $scopequery;
-
- $scopequery = getscopequery('i', 'replynum', $paramarr);
- if(!empty($scopequery)) $wherearr[] = $scopequery;
-
- @include_once S_ROOT.'/data/system/click.cache.php';
- $clickgroupids = array_keys($_SGLOBAL['clickgroup']['spaceitems']);
-
- foreach ($_SGLOBAL['click'] as $key => $kvalue) {
- if(in_array($key, $clickgroupids)) {
- foreach ($kvalue as $value) {
- if(!is_int($value['name'])){
- $scopequery = getscopequery('i', 'click_'.$value['clickid'], $paramarr);
- if(!empty($scopequery)) $wherearr[] = $scopequery;
- }
- }
- }
- }
-
- $scopequery = getscopequery('i', 'hot', $paramarr);
- if(!empty($scopequery)) $wherearr[] = $scopequery;
-
- $paramarr['haveattach'] = intval($paramarr['haveattach']);
- if(!empty($paramarr['haveattach']) && $paramarr['haveattach'] == 1) {
- $wherearr[] = 'i.haveattach = 1';
- }
- //兼容早期的图文$paramarr['showattach']
- if(!empty($paramarr['showattach']) || (!empty($paramarr['haveattach']) && $paramarr['haveattach'] == 2)) {
- $showpic = 1;
- $wherearr[] = 'i.picid != 0';
- }
- }
- 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'])) {
- if(!empty($paramarr['ss6'])) {
- $listcount = $_SGLOBAL['db']->result($_SGLOBAL['db']->query('SELECT COUNT(*) FROM blog_spaceitems i '.$sql['where']), 0);
- }else{
- $listcount = $_SGLOBAL['db']->result($_SGLOBAL['db']->query('SELECT COUNT(*) FROM '.tname('spaceitems').' i '.$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['messagedot'])) $paramarr['messagedot'] = 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']);
- }
- //处理标题样式
- if(!empty($value['styletitle'])) {
- $value['subject'] = '<span style=\''.mktitlestyle($value['styletitle']).'\'>'.$value['subject'].'</span>';
- }
- //链接
- $value['url'] = geturl('action/viewnews/itemid/'.$value['itemid'].'/cate/'.$value['catid']);
-
- //附件
- if($value['picid'] && $value['hash']) {
- $aids[] = $value['picid'];
- }
- $allitemids[] = $value['itemid'];
-
- //相关tag
- if(!empty($value['relativetags'])) $value['relativetags'] = $value['tags'] = unserialize($value['relativetags']);
-
- //分类名
- if(!empty($_SGLOBAL['category'][$value['catid']])) $value['catname'] = $_SGLOBAL['category'][$value['catid']];
-
- //附件
- if(!empty($value['picid']) && ($value['type'] == 'blog' || $value['type'] == 'news')) $value['subject'] = $value['subject'].$lang['block_image'];
-
- $theblockarr[$value['itemid']] = $value;
- }
-
- //分页内容处理/取第一页
- if(!empty($paramarr['showdetail'])) {
- if(!empty($allitemids)) {
- $theitemarr = array();
- if(!empty($paramarr['ss6'])) {
- $query = $_SGLOBAL['db']->query('SELECT * FROM blog_spacenews WHERE itemid IN (\''.implode('\',\'', $allitemids).'\') ORDER BY nid');
- }else{
- $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;
- $theblockarr[$value['itemid']] = array_merge($theblockarr[$value['itemid']], $value);
- }
- }
- }
- }
-
- if(!empty($showpic) || !empty($paramarr['onshowpic'])) {
- $attacharr = array();
- if(!empty($aids)) {
- if(!empty($paramarr['ss6'])) {
- $query = $_SGLOBAL['db']->query('SELECT '.$_SGLOBAL['attachsql'].' FROM blog_attachments a WHERE a.aid IN (\''.implode('\',\'', $aids).'\') ORDER BY a.dateline');
- }else{
- $query = $_SGLOBAL['db']->query('SELECT '.$_SGLOBAL['attachsql'].' FROM '.tname('attachments').' a WHERE a.aid IN (\''.implode('\',\'', $aids).'\') ORDER BY a.dateline');
- }
- while ($value = $_SGLOBAL['db']->fetch_array($query)) {
- //处理
- if(!empty($attacharr[$value['a_itemid']])) continue;
-
- $value['a_subjectall'] = $value['a_subject'];
- if(!empty($value['a_subject']) && !empty($paramarr['subjectlen'])) {
- $value['a_subject'] = cutstr($value['a_subject'], $paramarr['subjectlen'], $paramarr['subjectdot']);
- }
- //附件处理
- if(!empty($value['a_thumbpath'])) $value['a_thumbpath'] = A_URL.'/'.$value['a_thumbpath'];
- if(!empty($value['a_filepath'])) $value['a_filepath'] = A_URL.'/'.$value['a_filepath'];
- if(empty($value['a_thumbpath'])) {
- if(empty($value['a_filepath'])) {
- $value['a_thumbpath'] = S_URL.'/images/base/nopic.gif';
- } else {
- $value['a_thumbpath'] = $value['a_filepath'];
- }
- }
- if(empty($value['a_filepath'])) $value['a_filepath'] = $value['a_thumbpath'];
- $attacharr[$value['a_itemid']] = $value;
- $theblockarr[$value['a_itemid']] = array_merge($theblockarr[$value['a_itemid']], $value);
- }
- }
- }
- }
- return $theblockarr;
- }
- function block_spacetag($paramarr) {
- global $_SGLOBAL, $_SGET;
- if(empty($paramarr['sql'])) {
-
- $wherearr = array();
- if(!empty($paramarr['type'])) {
- $paramarr['type'] = getdotstring($paramarr['type'], 'char', false, $_SGLOBAL['type']);
- if($paramarr['type']) $wherearr[] = 'i.type IN ('.$paramarr['type'].')';
- }
- if(!empty($paramarr['haveattach'])) {
- $wherearr[] = 'i.haveattach = 1';
- }
- if(!empty($paramarr['uid'])) {
- $paramarr['uid'] = getdotstring($paramarr['uid'], 'int');
- if($paramarr['uid']) $wherearr[] = 'i.uid IN ('.$paramarr['uid'].')';
- }
- if(!empty($paramarr['digest'])) {
- $paramarr['digest'] = getdotstring($paramarr['digest'], 'int');
- if($paramarr['digest']) $wherearr[] = 'i.digest IN ('.$paramarr['digest'].')';
- }
- if(!empty($paramarr['lastpost'])) {
- $paramarr['lastpost'] = intval($paramarr['lastpost']);
- if($paramarr['lastpost']) $wherearr[] = 'i.lastpost >= '.($_SGLOBAL['timestamp']-$paramarr['lastpost']);
- }
- $scopequery = getscopequery('i', 'viewnum', $paramarr);
- if(!empty($scopequery)) $wherearr[] = $scopequery;
- $scopequery = getscopequery('i', 'replynum', $paramarr);
- if(!empty($scopequery)) $wherearr[] = $scopequery;
- $innersql = empty($wherearr) ? '1' : implode(' AND ', $wherearr);
-
- $sql = array();
- $sql['select'] = 'SELECT st.tagid, i.*';
- $sql['from'] = 'FROM '.tname('spacetags').' st INNER JOIN '.tname('spaceitems').' i ON i.itemid=st.itemid AND '.$innersql;
- $sql['join'] = '';
-
- if(!empty($paramarr['showdetail'])) {
- if(str_replace("'", '', $paramarr['type'])) {
- $sql['select'] .= ', ii.*';
- $sql['join'] .= ' LEFT JOIN '.tname('spacenews').' ii ON ii.itemid=st.itemid';
- }
- }
-
- //where
- $wherearr = array();
- $paramarr['tagid'] = getdotstring($paramarr['tagid'], 'int');
- if($paramarr['tagid']) {
- $wherearr[] = 'st.tagid IN ('.$paramarr['tagid'].')';
- }
-
- if(!empty($paramarr['dateline'])) {
- $paramarr['dateline'] = intval($paramarr['dateline']);
- if($paramarr['dateline']) $wherearr[] = 'st.dateline >= '.($_SGLOBAL['timestamp']-$paramarr['dateline']);
- }
-
- $sql['where'] = '';
- 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(*) '.$sql['from'].' '.$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['messagedot'])) $paramarr['messagedot'] = 0;
-
- if(!empty($paramarr['showcategory'])) {
- include_once(S_ROOT.'./data/system/category.cache.php');
- }
-
- //查询
- $query = $_SGLOBAL['db']->query($sqlstring);
- while ($value = $_SGLOBAL['db']->fetch_array($query)) {
-
- //处理
- $value['subjectall'] = $value['subject'];
- if(!empty($value['subject']) && !empty($paramarr['subjectlen'])) {
- $value['subject'] = cutstr($value['subject'], $paramarr['subjectlen'], $paramarr['subjectdot']);
- }
-
- if(!empty($value['message']) && !empty($paramarr['messagelen'])) {
- $value['message'] = trim(strip_tags($value['message']));
- $value['message'] = trim(cutstr($value['message'], $paramarr['messagelen'], $paramarr['messagedot']));
- }
-
- //类型
- if(!empty($value['type'])) $value['typename'] = $lang[$value['type']];
-
- //链接
- $value['url'] = geturl('action/viewnews/itemid/'.$value['itemid'].'/cate/'.$value['catid']);
- //相关tag
- if(!empty($value['relativetags'])) $value['relativetags'] = $value['tags'] = unserialize($value['relativetags']);
-
- //分类名
- if(!empty($_SGLOBAL['category'][$value['catid']])) $value['catname'] = $_SGLOBAL['category'][$value['catid']];
-
- //图片处理
- if(empty($value['thumb'])) {
- $value['thumb'] = S_URL.'/images/base/nopic.gif';
- } else {
- $value['thumb'] = A_URL.'/'.$value['thumb'];
- }
- if(empty($value['image'])) {
- $value['image'] = S_URL.'/images/base/nopic.gif';
- } else {
- $value['image'] = A_URL.'/'.$value['image'];
- }
-
- $theblockarr[] = $value;
- }
- }
- return $theblockarr;
- }
- function block_announcement($paramarr) {
- global $_SGLOBAL, $_SGET;
-
- if(empty($paramarr['sql'])) {
- //set sql var
- $sql = array();
-
- //select
- $sql['select'] = 'SELECT id, author, subject, starttime, endtime';
- if(!empty($paramarr['showdetail'])) {
- $sql['select'] .= ', message';
- }
-
- //from
- $sql['from'] = 'FROM '.tname('announcements');
-
- //where
- $wherearr = array();
- if(!empty($paramarr['id'])) {
- $paramarr['id'] = getdotstring($paramarr['id'], 'int');
- if($paramarr['id']) $wherearr[] = 'id IN ('.$paramarr['id'].')';
- } else {
- $wherearr[] = 'starttime <= '.$_SGLOBAL['timestamp'].' AND (endtime =0 OR endtime >= '.$_SGLOBAL['timestamp'].')';
- if(!empty($paramarr['author'])) {
- $paramarr['author'] = getdotstring($paramarr['author'], 'char');
- if($paramarr['author']) $wherearr[] = 'author IN ('.$paramarr['author'].')';
- }
- }
- 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('announcements').' '.$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['messagedot'])) $paramarr['messagedot'] = 0;
-
- //查询
- $query = $_SGLOBAL['db']->query($sqlstring);
- while ($value = $_SGLOBAL['db']->fetch_array($query)) {
-
- //标题处理
- $value['subjectall'] = $value['subject'];
- if(!empty($value['subject']) && !empty($paramarr['subjectlen'])) {
- $value['subject'] = cutstr($value['subject'], $paramarr['subjectlen'], $paramarr['subjectdot']);
- }
-
- //内容处理
- if(!empty($value['message']) && !empty($paramarr['messagelen'])) {
- $value['message'] = trim(strip_tags($value['message']));
- $value['message'] = trim(cutstr($value['message'], $paramarr['messagelen'], $paramarr['messagedot']));
- }
-
- //链接
- $value['url'] = geturl('action/announcement/id/'.$value['id']);
-
- $theblockarr[] = $value;
- }
- }
- return $theblockarr;
- }
- function block_bbsannouncement($paramarr) {
- global $_SGLOBAL, $_SGET;
- dbconnect(1);
- if(empty($paramarr['sql'])) {
- //set sql var
- $sql = array();
-
- //select
- $sql['select'] = 'SELECT id, author, subject, starttime, endtime';
- if(!empty($paramarr['showdetail'])) {
- $sql['select'] .= ', message';
- }
-
- //from
- $sql['from'] = 'FROM '.tname('announcements', 1);
-
- //where
- $wherearr = array();
- if(!empty($paramarr['aid'])) {
- $paramarr['aid'] = getdotstring($paramarr['aid'], 'int');
- if($paramarr['aid']) $wherearr[] = 'id IN ('.$paramarr['aid'].')';
- } else {
- $wherearr[] = 'starttime <= '.$_SGLOBAL['timestamp'].' AND (endtime =0 OR endtime >= '.$_SGLOBAL['timestamp'].')';
- if(!empty($paramarr['author'])) {
- $paramarr['author'] = getdotstring($paramarr['author'], 'char');
- if($paramarr['author']) $wherearr[] = 'author IN ('.$paramarr['author'].')';
- }
- }
- 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_bbs']->result($_SGLOBAL['db_bbs']->query('SELECT COUNT(*) FROM '.tname('announcements', 1).' '.$sql['where']), 0);
- if($listcount) {
- $urlarr = $_SGET;
- unset($urlarr['page']);
- $theblockarr['multipage'] = multi($listcount, $paramarr['perpage'], $_SGET['page'], $urlarr, 0);
- }
- }
- } else {
-
- $bbsdb = $_SGLOBAL['db_bbs'];
- include_once(S_ROOT.'./function/block_sql.func.php');
- list($sqlstring, $listcount) = runsql($paramarr, $bbsdb);
- 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['messagedot'])) $paramarr['messagedot'] = 0;
-
- //查询
- $query = $_SGLOBAL['db_bbs']->query($sqlstring);
- while ($value = $_SGLOBAL['db_bbs']->fetch_array($query)) {
-
- //标题处理
- $value['subjectall'] = $value['subject'];
- if(!empty($value['subject']) && !empty($paramarr['subjectlen'])) {
- $value['subject'] = cutstr($value['subject'], $paramarr['subjectlen'], $paramarr['subjectdot']);
- }
-
- //内容处理
- if(!empty($value['message']) && !empty($paramarr['messagelen'])) {
- $value['message'] = trim(strip_tags($value['message']));
- $value['message'] = trim(cutstr($value['message'], $paramarr['messagelen'], $paramarr['messagedot']));
- }
-
- //链接
- $value['url'] = B_URL.'/announcement.php?id='.$value['id'];
-
- $theblockarr[] = $value;
- }
- }
- return $theblockarr;
- }
复制代码 |