<?php
//本地头条


//处理页数和分页数量
$page = isset($page) ? $page : intval($_GET['page']);
$page = $page < 1 ? 1 : $page;
$pagesize =  isset($pagesize) ? $pagesize : (isset($_GET['pagesize']) ? $_GET['pagesize'] : 20);
$offset = ($page - 1) * $pagesize;
//获取block_id+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--------------------------------------------++++++++++++++++++++++++++++++++++++++++++++++---------------------------------------  ,
$odz_index_hot_news = get_mocuz_setting('index_hot_news');

$odz_index_hot_news = $odz_index_hot_news['index_hot_news'];

if(!empty($odz_index_hot_news)){

 
    //总数
    $total = DB::result_first('SELECT count(*) FROM ' . DB::table('common_block_item') . " as c left join " . DB::table('forum_thread') . " as f on c.id = f.tid WHERE c.bid = " . $odz_index_hot_news . " AND f.displayorder IN(0,1,2,3)" );
    $total_page = ceil($total/$pagesize);


    //获取数据
    $sql = 'SELECT c.id, c.title, c.pic,f.tid, c.picflag, c.makethumb, c.thumbpath, c.fields,f.views  FROM ' . DB::table('common_block_item') . " as c left join " . DB::table('forum_thread') . " as f on c.id = f.tid WHERE c.bid = " . $odz_index_hot_news . " AND f.displayorder IN(0,1,2,3)  ORDER BY c.displayorder ASC LIMIT $offset, $pagesize";
    if (strpos($_G['setting']['attachurl'], 'http') !== false) {
        $img_url = $_G['setting']['attachurl'];
    } else {
        $img_url = $_G['baseurl'] . $_G['setting']['attachurl'];
    }

    $query = DB::query($sql);
    $list = array();

    while ($row = DB::fetch($query)) {
        $row['fields'] = unserialize($row['fields']);
        if (!$row['fields']['dateline']) {
            continue;
        }
        $arr = array(
            'subject' => (string)odz_format_subject($row['title']),
            'date' => dgmdate($row['fields']['dateline'],'mu'),
            'views' => (string)$row['views'],
            'tid' => (string)$row['tid']
        );
        if ($row['makethumb']) {
            $imgpath = $row['thumbpath'];
        } else {
            $imgpath = $row['pic'];
        }
        $arr['pic'] = array();

        if ($row['picflag'] == 0) {
            if (strpos($_G['setting']['attachurl'], 'http') !== false) {
                $img_url = $_G['setting']['attachurl'];
            } else {
                $img_url = $_G['baseurl'] . $_G['setting']['attachurl'];
            }
            $arr['pic'] = array($img_url . $imgpath);
        } elseif ($row['picflag'] == 2) {
            $arr['pic'] = array($_G['setting']['ftp']['attachurl'] . $imgpath);
        } else {
            $arr['pic'] = array($img_url . $imgpath);
        }
        if (strpos($arr['pic'][0], 'nophoto.gif') !== false) {
            $arr['pic'] = array();
        }
        $arr['pic'] = array_shift($arr['pic']);
        $arr['pic'] = empty($arr['pic']) ? '' : $arr['pic'];
        //$arr['pic'] = str_replace('/', '\/', $arr['pic']);
        $list[] = $arr;
    }
}else{
    $list = array();
}

?>
