主页修补功能的源代码

9 天前 文章归档 50

home。php

<?php

/**
 * 站点首页模板
 */
if (!defined('EMLOG_ROOT')) exit('error!');

// 面包屑导航
include View::getView('components/bread');

$home_custom = _g('home_custom');

doAction('index_loglist_top');
$sort_icons = _g('sort_icon');
$arr = explode(',', $home_custom);
echo '<div class="layout-container home">';
echo '<div class="layout-left light-shadow transition-2"><div class="side-menu" id="side-menu"></div></div>';

echo '<div class="layout-right" id="layout-right">';
$side_menus = [];

// 搜索框
include View::getView('components/search-box');

foreach ($arr as $item) {
    $item = trim($item);
    $key = 'id-' . $item;
    if ($item === 'new_nav') {
        $logs = getNewLogsFromTemplate('log_list_link', _g('home_new_nav_count'));
        $icon = _g('new_link_icon');
        $icon = "<i class='iconfont {$icon}'></i>";

        echo "<div class='home-section' id='{$key}'><div class='home-section-header'>{$icon}" . _t('new_websites') . "</div><div class='home-section-body'>";
        if (_g('new_nav_list_type') === 'card') {
            log_list_link_card($logs);
        }
        if (_g('new_nav_list_type') === 'icon') {
            log_list_link($logs);
        }
        echo '</div></div>';
        $side_menus[] = [
            'id' => $key,
            'name' => _t('new_websites'),
            'icon' => $icon
        ];
    } else if ($item === 'new_log') {
        $logs = getNewLogsFromTemplate('', _g('home_new_log_count'));
        $icon = _g('new_article_icon');
        $icon = "<i class='iconfont {$icon}'></i>";
        // 最新资讯 添加 更多按钮 https://www.panda.tw/sort/7
        echo "<div class='home-section' id='{$key}'><div class='home-section-header'> {$icon}" . _t('new_articles') . " <a href='https://www.panda.tw/sort/7' class='more'>" . _t('more') . "<i class='iconfont icon-right'> </i></a>" . "</div><div class='home-section-body'>";
        if (_g('new_log_list_type') === 'log_list_log_normal') {
            log_list_log_normal($logs);
        } else {
            log_list_card($logs);
        }
        echo '</div></div>';
        $side_menus[] = [
            'id' => $key,
            'name' => _t('new_articles'),
            'icon' => $icon
        ];
    } else if (_g($item)) {
        // 广告位
        echo "<div class='home-section'><div class='home-section-body'>";
        echo _g($item);
        echo "</div></div>";
    }
}

// 获取所有导航分类并展示
if (_g('home_sorts') === 'all') {
    $sorts = get_sorts_by_templates([]);
} elseif (_g('home_sorts') === 'log_list') {
    $sorts = get_sorts_by_template('');
} else {
    $sorts = get_sorts_by_template();
}
$sorts_cache = Cache::getInstance()->readCache('sort');

$dict = [];
foreach ($sorts_cache as $sort) {
    if (isset($sort['children'])) {
        foreach ($sort['children'] as $child) {
            $dict[$sort['sid']][] = $sorts_cache[$child];
        }
    }
}
$hide_sorts = explode(",", _g('home_sorts_hide'));
foreach ($sorts as $sort) {
    $sid = $sort['sid'];

    if (in_array($sid, $hide_sorts)) {
        continue;
    }
    $key = 'id-' . $sid;
    if ($sort) {
        $sort_url = Url::sort($sid);

        $count = $sort['template'] === 'log_list_link' ? _g('sort_nav_count') : _g('sort_log_count');
        $logs = getArticleBySortID($sid, $count);

        $icon = $sort['sortimg'] ? "<img src='{$sort['sortimg']}' class='iconfont'>" : "<i class='iconfont {$sort_icons[$sid]}'></i>";

        $children = [];
        if (isset($dict[$sid])) {
            $children = array_map(function ($item) {
                $url = Url::sort($item['sid']);
                return "<a href='{$url}' class='child-sort'>{$item['sortname']}</a>";
            }, $dict[$sid]);
        }
?>

        <div class='home-section' id='<?= $key; ?>'>
            <div class='home-section-header'><?= $icon; ?><a href='<?= $sort_url; ?>'><?= $sort['sortname']; ?></a>

                <?= implode("", $children) ?>
                <a href='<?= $sort_url; ?>'
                    class='more'><?= _t('more') ?>
                    <i class='iconfont icon-right'></i></a>
            </div>
            <div class='home-section-body'>
        <?php

        if ($sort['template'] === 'log_list_link') {
            if (_g('nav_list_type') === 'card') {
                log_list_link_card($logs);
            }
            if (_g('nav_list_type') === 'icon') {
                log_list_link($logs);
            }
        } else {
            log_list_card($logs);
        }
        echo '</div></div>';
        $side_menus[] = [
            'id' => $key,
            'name' => $sort['sortname'],
            'icon' => $icon
        ];
    }
}

        ?>

        <?php
        global $CACHE;
        $links = $CACHE->readCache('link');
        $links = array_slice($links, 0, _g('home_links_num'));
        $bar = TEMPLATE_URL . 'static/images/link.png';

        if (count($links) > 0):
        ?>
            <section class="home-section" id="links">
                <div class='home-section-header'>
                    <i class="iconfont icon-shejiao-fenxiang"></i>
                    <span><?= _t('friendly_links') ?></span>
                </div>
                <div class="home-section-body">
                    <div class="link-items light-shadow">
                        <?php foreach ($links as $link) :

                        ?>
                            <div class="link-item">
                                <a href="<?= $link['url']; ?>" target="_blank" rel="nofollow" title="<?= $link['des']; ?>">
                                    <?php if ($link['icon']): ?>
                                        <img data-src="<?= $link['icon']; ?>" src="<?= $bar; ?>" class="lazyload ico" alt="ico"
                                            onerror="this.src='<?= $bar; ?>'">
                                    <?php else: ?>
                                        <img data-src="<?= $link['url']; ?>/favicon.ico" src="<?= $bar; ?>" class="lazyload ico"
                                            alt="ico" onerror="this.src='<?= $bar; ?>'">
                                    <?php endif; ?>
                                    <span><?= $link['link']; ?></span>
                                </a>
                            </div>
                        <?php endforeach; ?>
                    </div>
                </div>
            </section>
        <?php endif; ?>
        <?php
        include View::getView('components/footer');
        echo '</div>';
        echo '</div>';

        $side_menu_url = OpzNavTemplate::getInstance()->load_static('js/side-menu.js');
        $side_menu_data = json_encode($side_menus, JSON_UNESCAPED_SLASHES);
        echo "<script>var side_menu_data = {$side_menu_data};</script>";
        echo "<script src='{$side_menu_url}'></script>";

        include View::getView('footer');
工欲善其事,必先利其器。
收藏