Beispiel #1
0
 function display($params)
 {
     $Log_Model = new Log_Model();
     $options_cache = Option::getAll();
     extract($options_cache);
     $page = isset($params[4]) && $params[4] == 'page' ? abs(intval($params[5])) : 1;
     $tag = isset($params[1]) && $params[1] == 'tag' ? addslashes(urldecode(trim($params[2]))) : '';
     $pageurl = '';
     //page meta
     $site_title = stripslashes($tag) . ' - ' . $site_title;
     $Tag_Model = new Tag_Model();
     $blogIdStr = $Tag_Model->getTagByName($tag);
     if ($blogIdStr === false) {
         show_404_page();
     }
     $sqlSegment = "and gid IN ({$blogIdStr}) order by date desc";
     $lognum = $Log_Model->getLogNum('n', $sqlSegment);
     $total_pages = ceil($lognum / $index_lognum);
     if ($page > $total_pages) {
         $page = $total_pages;
     }
     $pageurl .= Url::tag(urlencode($tag), 'page');
     $logs = $Log_Model->getLogsForHome($sqlSegment, $page, $index_lognum);
     $page_url = pagination($lognum, $index_lognum, $page, $pageurl);
     include View::getView('header');
     include View::getView('log_list');
 }
Beispiel #2
0
/**
 * 相关日志插件的功能集合到J3中;related_log插件没有用了 模板中也不再埋入相关日志加载点
 * @param  array $logData 文章显示时的文章数据
 * @return array
 */
function getRelatedLog($logData)
{
    global $CACHE;
    $logid = $logData['logid'];
    $sortid = $logData['sortid'];
    $sortType = _g('related_log_sort_type');
    $sortBy = _g('related_log_sort_by');
    $countNum = _g('related_log_count');
    #DbModel
    $DbModel = Database::getInstance();
    $sql = "SELECT gid,title,date FROM " . DB_PREFIX . "blog WHERE hide='n' AND type='blog'";
    #排序类别的sql拼装
    if ($sortType == 'tags') {
        $log_cache_tags = $CACHE->readCache('logtags');
        // dump($log_cache_tags[$logid]);
        $TagModel = new Tag_Model();
        $log_id_str = '0';
        foreach ($log_cache_tags[$logid] as $key => $val) {
            $log_id_str .= ',' . $TagModel->getTagByName($val['tagname']);
        }
        $log_id_str = implode(',', array_unique(explode(',', ltrim($log_id_str, '0,'))));
        $sql .= " AND gid!={$logid} AND gid IN ({$log_id_str})";
    } else {
        $sql .= " AND gid!={$logid} AND sortid={$sortid}";
    }
    #排序规则
    switch ($sortBy) {
        case 'viewDesc':
            $sql .= " ORDER BY views DESC";
            break;
        case 'viewASC':
            $sql .= " ORDER BY views ASC";
            break;
        case 'comnuDesc':
            $sql .= " ORDER BY comnum DESC";
            break;
        case 'comnuASC':
            $sql .= " ORDER BY comnum ASC";
            break;
        default:
            #按索引键随机降序或升序多读出几行 随后使用php随机处理,不再在mysql中使用rand函数
            if (mt_rand(1, 10) >= 5) {
                $sql .= " ORDER BY gid DESC";
            } else {
                $sql .= " ORDER BY gid ASC";
            }
            break;
    }
    #结果条数限制
    if ($sortBy == 'random') {
        $sliceLen = $countNum;
        $countNum = $countNum * 2;
        #随机的情况多一倍的数据出来
    }
    $sql .= " LIMIT 0,{$countNum}";
    $relatedLogs = array();
    $res = $DbModel->query($sql);
    while ($row = $DbModel->fetch_array($res)) {
        $row['gid'] = intval($row['gid']);
        $row['title'] = htmlspecialchars($row['title']);
        $row['time'] = date('Y-m-d', $row['date']);
        $relatedLogs[] = $row;
    }
    if (!$relatedLogs) {
        return '';
        #没有相关日志数据
    }
    #随机处理
    if ($sortBy == 'random') {
        shuffle($relatedLogs);
        #打乱数组,引用传值函数
        $relatedLogs = array_slice($relatedLogs, 0, $sliceLen);
    }
    // dump($relatedLogs);
    $relatedString = '<div class="article_related"><h3>相关推荐</h3><ul>';
    foreach ($relatedLogs as $key => $val) {
        $relatedString .= '<li><a href="' . Url::log($val['gid']) . '">' . $val['title'] . '</a><time>' . $val['time'] . '</time></li>';
    }
    return $relatedString . '</ul></div>';
}