Joe主题页面增加用户登入功能

发布于 2021-06-01  126 次阅读


1614522653575.jpg

{mtitle title="bilibili:风灵玉秀官方图"/}

Screenshot_20210601_213803.jpg
{mtitle title="图1 后台设置页效果"/}

Screenshot_20210601_212926.jpg

{mtitle title="图2 登入前效果"/}

Screenshot_20210601_212950.jpg
{mtitle title="图3 登入后效果"/}

一、修改 usr/themes/Joe/public/header.php ,增加以下代码

<ul class="joe_header__slideout-menu panel-box" style="margin-top: 15px; <?php if(Helper::options()->login4Phone !== 'on') echo 'display:none;'  ?>">
    <li>
        <?php if ($this->user->hasLogin()) : ?>
            <a class="link panel" href="#" rel="nofollow">
                <span><?php $this->user->screenName(); ?></span>
                <svg class="icon" viewBox="0 0 1024 1024" xmlns="http://www.w3.org/2000/svg" width="15" height="15">
                    <path d="M231.594 610.125C135.087 687.619 71.378 804.28 64.59 935.994c-.373 7.25 3.89 23.307 30.113 23.307s33.512-16.06 33.948-23.301c6.861-114.025 63.513-214.622 148.5-280.346 3.626-2.804 16.543-17.618 3.24-39.449-13.702-22.483-40.863-12.453-48.798-6.08zm280.112-98.44v63.96c204.109 0 370.994 159.345 383.06 360.421.432 7.219 8.649 23.347 32.44 23.347s31.991-16.117 31.62-23.342c-12.14-236.422-207.676-424.386-447.12-424.386z" />
                    <path d="M319.824 319.804c0-105.974 85.909-191.883 191.882-191.883s191.883 85.91 191.883 191.883c0 26.57-5.405 51.88-15.171 74.887-5.526 14.809-2.082 31.921 20.398 38.345 23.876 6.822 36.732-8.472 41.44-20.583 11.167-28.729 17.294-59.973 17.294-92.65 0-141.297-114.545-255.842-255.843-255.842S255.863 178.506 255.863 319.804s114.545 255.843 255.843 255.843v-63.961c-105.973-.001-191.882-85.909-191.882-191.882z" />
                    <path d="M512 255.843s21.49-5.723 21.49-31.306S512 191.882 512 191.882c-70.65 0-127.921 57.273-127.921 127.922 0 3.322.126 6.615.375 9.875.264 3.454 14.94 18.116 37.044 14.425 22.025-3.679 26.6-21.93 26.6-21.93-.028-.788-.06-1.575-.06-2.37.001-35.325 28.637-63.961 63.962-63.961z" />
                </svg>
            </a>
            <ul class="slides panel-body">
                <li>
                    <?php if ($this->user->group == 'administrator' || $this->user->group == 'editor' || $this->user->group == 'contributor') : ?>
                        <a class="link" rel="noopener noreferrer nofollow" target="_blank" href="<?php $this->options->adminUrl("manage-posts.php"); ?>">管理文章</a>
                    <?php endif; ?>
                </li>
                <li>
                    <?php if ($this->user->group == 'administrator' || $this->user->group == 'editor') : ?>
                        <a class="link" rel="noopener noreferrer nofollow" target="_blank" href="<?php $this->options->adminUrl("manage-comments.php"); ?>">管理评论</a>
                    <?php endif; ?>
                </li>
                <li>
                    <?php if ($this->user->group == 'administrator') : ?>
                        <a class="link" rel="noopener noreferrer nofollow" target="_blank" href="<?php $this->options->adminUrl("options-theme.php"); ?>">修改外观</a>
                    <?php endif; ?>
                </li>
                <li>
                    <a class="link" rel="noopener noreferrer nofollow" target="_blank" href="<?php $this->options->adminUrl(); ?>">进入后台</a>
                </li>
                <li>
                    <a class="link" rel="noopener noreferrer nofollow" href="<?php $this->options->logoutUrl(); ?>">退出登录</a>
                </li>
            </ul>
        <?php else : ?>
            <a class="link panel" href="#" rel="nofollow">
                <span>用户登录</span>
                <svg class="icon" viewBox="0 0 1024 1024" xmlns="http://www.w3.org/2000/svg" width="15" height="15">
                    <path d="M231.594 610.125C135.087 687.619 71.378 804.28 64.59 935.994c-.373 7.25 3.89 23.307 30.113 23.307s33.512-16.06 33.948-23.301c6.861-114.025 63.513-214.622 148.5-280.346 3.626-2.804 16.543-17.618 3.24-39.449-13.702-22.483-40.863-12.453-48.798-6.08zm280.112-98.44v63.96c204.109 0 370.994 159.345 383.06 360.421.432 7.219 8.649 23.347 32.44 23.347s31.991-16.117 31.62-23.342c-12.14-236.422-207.676-424.386-447.12-424.386z" />
                    <path d="M319.824 319.804c0-105.974 85.909-191.883 191.882-191.883s191.883 85.91 191.883 191.883c0 26.57-5.405 51.88-15.171 74.887-5.526 14.809-2.082 31.921 20.398 38.345 23.876 6.822 36.732-8.472 41.44-20.583 11.167-28.729 17.294-59.973 17.294-92.65 0-141.297-114.545-255.842-255.843-255.842S255.863 178.506 255.863 319.804s114.545 255.843 255.843 255.843v-63.961c-105.973-.001-191.882-85.909-191.882-191.882z" />
                    <path d="M512 255.843s21.49-5.723 21.49-31.306S512 191.882 512 191.882c-70.65 0-127.921 57.273-127.921 127.922 0 3.322.126 6.615.375 9.875.264 3.454 14.94 18.116 37.044 14.425 22.025-3.679 26.6-21.93 26.6-21.93-.028-.788-.06-1.575-.06-2.37.001-35.325 28.637-63.961 63.962-63.961z" />
                </svg>
            </a>
            <ul class="slides panel-body">
                <li>
                    <a class="link" href="<?php $this->options->adminUrl('login.php'); ?>" target="_blank" rel="noopener noreferrer nofollow">登录</a>
                    <?php if ($this->options->allowRegister) : ?>
                        <a class="link" href="<?php $this->options->adminUrl('register.php'); ?>" target="_blan" rel="noopener noreferrer nofollow">注册</a>
                    <?php endif; ?>
                </li>
            </ul>
        <?php endif; ?>
    </li>

kpe2752e.png

{mtitle title="图4 代码插入位置"/}

二、修改 usr/themes/Joe/functions.php 在末尾插入以下代码,以在后台设置页面启用

// 手机端登录
$login4Phone = new Typecho_Widget_Helper_Form_Element_Select(
    'login4Phone',
    array(
        'off' => '关闭(默认)',
        'on' => '开启',
    ),
    'on',
    '是否启用手机端登录功能',
    '介绍:开启后,手机端侧边栏将展示登录功能和登录后的操作'
);
$login4Phone->setAttribute('class', 'joe_content joe_custom'); // 如果无法展示,则将joe_custom替换为joe_other
$form->addInput($login4Phone->multiMode());

kpe2bqvm.png

{mtitle title="图5 代码插入位置"/}

2021-06-01 21:16:42 星期二

来源: Typecho的Joe主题实现手机端登录/注册功能


间接性发奋图强,持续性混吃等死