<?php
/*
* 项目: iOrange(橘子)
* 作者: 离家出走(yzxh24)
* Email: yzxh24@gmail.com
* 主页: www.iorange.cc
*/
/* vim: set ts=4 sw=4: */
define('IN_IORANGE', true);
require_once 'include/init.php';

if (!isWebRequest())
{
    $commendarray = getCommend();
    if ($commendarray)
    {
        shuffle($commendarray);
        $commendarray = array_splice($commendarray, 0, 5);
    }

    $tpl = 'index_web';
    if (!isPc() || IS_MOBILE)
    {
        $tpl = 'index';
        $feeds = iFeed::single()->getNews(5);
    }

    $sql = 'SELECT bookid,bookname,updatedate FROM '.Book::table().' WHERE type = 2 AND view = 1 ORDER BY updatedate DESC LIMIT 5';
    $originalBooks = $db->setQueryString($sql)->find();
    if (!empty($originalBooks))
    {
        foreach ($originalBooks as &$value)
        {
            $chapters = Chapter::single()->getChapterList($value['bookid']);
            $last = $chapters[count($chapters) - 1];
            $value['size'] = $last['size'];
        }
    }

    $sql = 'SELECT id,uid,subject,hits,replies FROM '.Threads::table().' WHERE isdelete = 0 ORDER BY lastpost DESC LIMIT 5';
    $threads = $db->setQueryString($sql)->find();
}
else
{
    $tpl = 'index';
    $condition = 'b.view = 1';
    $sql = 'SELECT b.bookid,b.bookname,b.author,b.updatedate,b.wlastchapterid,b.wlastchaptername,b.lastchapterid,b.lastchaptername,t.typename FROM '.Book::table().' AS b INNER JOIN `'.Types::table().'` AS t ON t.typeid = b.typeid WHERE ' . $condition .' ORDER BY b.updatedate DESC LIMIT 20';

    $updateList = $db->setQueryString($sql)->find();
}

include_once tpl($tpl);