你的位置:LAMP之窗 >> 资讯 >> SupeSite >> 详细内容 在线投稿

新增supesite提取附件的系统函数功能

排行榜 收藏 打印 发给朋友 举报 来源: 365coding   发布者:危险的蘑菇
热度22票  浏览91次 【共0条评论】【我要评论 时间:2010年8月10日 11:27
本文介绍一下新增supesite提取附件系统函数功能的方法,希望能够对图片站或者附件展示的站长们有所帮助

修改function/block.func.php文件

新增如下代码

/*
    $Id: block_attachments 13493 2010-08-10 11:01:20Z zj $
    paramarr:
      1,sql  使用自定义sql
      2,aid  附件id 多id之间可以使用",",","," "分割
      3,uid  上传附件的uid 多id之间可以使用",",","," "分割
      4,showpic 只提取图片
      5,catid   附件所属分类 多id之间可以使用",",","," "分割
      6,itemid  附件所属资讯id 多id之间可以使用",",","," "分割
      7,type    附件所属系统分类类型 如news等
      8,dateline 附件上传时间大于此时间,即最新上传的附件
      9,perpage  每页显示数量
      10,order   排序规则
      11,limit   
      12,subjectdot  标题截取是否显示后缀
      13,subjectlen  标题长度
      14,newssubject  标题提取附件所属资讯标题,如不设置为附件文件名。此参数会增加系统负担
      15,showdetail   提取内容。此参数会增加系统负担
      16,messagelen   内容长度
      17,messagedot   内容截取是否显示后缀
      16,showcategory  提取分类信息

      模板使用规则例如
      <!--{block name="attachments" parameter="aid/23,22/showpic/1/catid/7/itemid/15/newssubject/1/showdetail/1/showcategory/1/order/dateline DESC/limit/0,2/cachetime/83400/subjectlen/40/subjectdot/0/cachename/test_attachments"}-->
*/

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;
}

ps:请仔细阅读参数描述并依照模板使用方法修改
TAG: supesite 函数 功能 系统 附件
顶:5 踩:2
对本文中的事件或人物打分:
当前平均分:-2.63 (8次打分)
对本篇资讯内容的质量打分:
当前平均分:-5 (3次打分)
上一篇 下一篇
发表评论

网友评论仅供网友表达个人看法,并不表明本网同意其观点或证实其描述。

查看全部回复【已有0位网友发表了看法】
       

网络资源