登录可见 | Login 2 See Plus
为访客在帖子中隐藏链接和图像的Flarum扩展。您还可以隐藏超过设定长度的帖子内容。
由 JSLirola 更新自 WiseClock 的原始扩展。
插件安装:
composer require jslirola/flarum-ext-login2seeplus
插件更新:
composer update jslirola/flarum-ext-login2seeplus
php flarum cache:clear
管理设置
可对隐藏长度,代码、图片、链接分别设置,长度设置默认-1为不限制观看帖子长度
访客页面:点击链接直接跳出登录框
登录后页面:
插件在安装后会出现错误,以下为修复教程:
参考页面:jslirola/flarum-ext-login2seeplus@81c5067
1、找到/vendor/jslirola/flarum-ext-login2seeplus/src
目录,备份HideContentInPosts.php
文件
2、修改HideContentInPosts.php
,删除原代码,将以下代码粘贴进去,保存后刷新页面即可。
<?php
/*
* This file is part of jslirola/flarum-ext-login2seeplus.
*
* Copyright (c) 2020
* Original Extension by WiseClock
* Updated by jslirola
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace JSLirola\Login2SeePlus;
class HideContentInPosts extends FormatContent
{
public function __invoke($serializer, $model, $attributes)
{
if (isset($attributes["contentHtml"])) {
$newHTML = $attributes["contentHtml"];
$s_php = $this->settings->get('jslirola.login2seeplus.php', false);
$s_post = (int)$this->settings->get('jslirola.login2seeplus.post', 100);
if (!$serializer->getActor()->isGuest())
return $attributes;
$s_code = $this->settings->get('jslirola.login2seeplus.code', false);
$s_summary_links = $this->settings->get('jslirola.login2seeplus.link', false);
// truncate
if ($s_post != -1 && function_exists('mb_substr') && function_exists('mb_strlen')) {
$newHTML = $this->truncate_html($newHTML, $s_post);
$newHTML = preg_replace('/(<p>)([^<]*)<\/p>$/is', '$1$2...$3', $newHTML);
}
// code
if ($s_code) {
$newHTML = preg_replace('/<pre><code(.*?)>[^>]*<\/pre>/is', $this->get_link('jslirola-login2seeplus.forum.code'), $newHTML);
$newHTML = preg_replace('/<code(.*?)>[^>]*<\/code>/is', $this->get_link('jslirola-login2seeplus.forum.code'), $newHTML);
}
// show alert
if ($s_post != -1)
$newHTML .= '<div class="jslirolaLogin2seeplusAlert">' . $this->translator->trans('jslirola-login2seeplus.forum.post', array(
'{login}' => '<a class="jslirolaLogin2seeplusLogin">' . $this->translator->trans('core.forum.header.log_in_link') . '</a>',
'{register}' => '<a class="jslirolaLogin2seeplusRegister">' . $this->translator->trans('core.forum.header.sign_up_link') . '</a>'
)) . '</div>';
if (!is_null($newHTML) && $s_summary_links == 1)
$newHTML = preg_replace('/(<a((?!PostMention).)*?>)[^<]*<\/a>/is',
'[' . $this->get_link('jslirola-login2seeplus.forum.link') . ']', $newHTML);
$attributes['contentHtml'] = $newHTML;
}
return $attributes;
}
}