This commit is contained in:
64
changyandandian/Action.php
Normal file
64
changyandandian/Action.php
Normal file
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
|
||||
|
||||
class changyandandian_Action extends Widget_Abstract_Contents implements Widget_Interface_Do
|
||||
{
|
||||
|
||||
|
||||
public function __construct($request, $response, $params = NULL) {
|
||||
parent::__construct($request, $response, $params);
|
||||
}
|
||||
|
||||
public function execute()
|
||||
{
|
||||
}
|
||||
|
||||
public function action()
|
||||
{
|
||||
|
||||
|
||||
if($this->user->hasLogin()){
|
||||
$ret=array(
|
||||
"is_login"=>1, //已登录,返回登录的用户信息
|
||||
"user"=>array(
|
||||
"user_id"=>$this->user->uid,
|
||||
"nickname"=>$this->user->screenName,
|
||||
"img_url"=>"https://gravatar.helingqi.com/wavatar/".md5($this->user->mail)."?d=mm",
|
||||
"profile_url"=>$this->user->url,
|
||||
"sign"=>"zezechupin", //注意这里的sign签名验证已弃用,任意赋值即可
|
||||
'reload_page'=>1,
|
||||
));
|
||||
setcookie("cyCookie",'1');//畅言已通过站点账号自动登录,使用cookie做个标记,用于判断进行同步登出
|
||||
|
||||
}else{
|
||||
$ret=array("is_login"=>0);//未登录
|
||||
}
|
||||
|
||||
echo $_GET['callback'].'('.json_encode($ret).')';
|
||||
|
||||
}
|
||||
|
||||
public function logout(){
|
||||
|
||||
if(!$this->user->hasLogin()){
|
||||
$return=array(
|
||||
'code'=>1,
|
||||
'reload_page'=>1,
|
||||
);
|
||||
}else{
|
||||
$this->user->logout();
|
||||
$return=array(
|
||||
'code'=>1,
|
||||
'reload_page'=>1,
|
||||
);
|
||||
}
|
||||
echo $_GET['callback'].'('.json_encode($return).')';
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
93
changyandandian/Plugin.php
Normal file
93
changyandandian/Plugin.php
Normal file
@@ -0,0 +1,93 @@
|
||||
<?php
|
||||
if (!defined('__TYPECHO_ROOT_DIR__')) exit;
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @package 畅言单点登录插件
|
||||
* @author 泽泽社长
|
||||
* @version 1.0.0
|
||||
* @link https://zezeshe.com/archives/typecho-changyan-plugin.html
|
||||
*/
|
||||
class changyandandian_Plugin implements Typecho_Plugin_Interface
|
||||
{
|
||||
|
||||
/**
|
||||
* 激活插件方法,如果激活失败,直接抛出异常
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
* @throws Typecho_Plugin_Exception
|
||||
*/
|
||||
public static function activate()
|
||||
{
|
||||
Helper::addRoute("route_changyan","/changyan","changyandandian_Action",'action');
|
||||
Helper::addRoute("route_changyanlogout","/changyan/logout","changyandandian_Action",'logout');
|
||||
Typecho_Plugin::factory('Widget_Archive')->footer = array('changyandandian_Plugin', 'footer');
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 禁用插件方法,如果禁用失败,直接抛出异常
|
||||
*
|
||||
* @static
|
||||
* @access public
|
||||
* @return void
|
||||
* @throws Typecho_Plugin_Exception
|
||||
*/
|
||||
public static function deactivate()
|
||||
{
|
||||
Helper::removeRoute("route_changyan");
|
||||
Helper::removeRoute("route_changyanlogout");
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取插件配置面板
|
||||
*
|
||||
* @access public
|
||||
* @param Typecho_Widget_Helper_Form $form 配置面板
|
||||
* @return void
|
||||
*/
|
||||
public static function config(Typecho_Widget_Helper_Form $form)
|
||||
{
|
||||
|
||||
$set1 = new Typecho_Widget_Helper_Form_Element_Textarea('loginjsurl', NULL,$f, _t('网站登录地址'), _t('请在此处填写网站登录地址,不填则调用默认的typecho登录地址,如果您的主题用的是弹窗式的登录界面,您也可以在此写js代码调用出登录弹窗!'));
|
||||
$form->addInput($set1);
|
||||
}
|
||||
|
||||
public static function footer($obj)
|
||||
{
|
||||
$loginurl=Typecho_Widget::widget('Widget_Options')->adminUrl.'login.php';
|
||||
$url=Helper::options()->Plugin('changyandandian')->loginjsurl;
|
||||
if(empty($url)){
|
||||
$url='window.location.href="'.$loginurl.'";';
|
||||
}
|
||||
elseif(strpos($url,'https://') !== false||strpos($url,'http://') !== false){
|
||||
$url='window.location.href="'.$url.'";';
|
||||
}
|
||||
?>
|
||||
<script>
|
||||
function changyanlogin() {
|
||||
<?php echo $url;?>
|
||||
}
|
||||
<?php
|
||||
if (!Typecho_Widget::widget('Widget_User')->hasLogin()&&$_COOKIE["cyCookie"]){setcookie("cyCookie",''); echo 'if(localStorage.getItem("cy_lt")){localStorage.removeItem("cy_lt");window.location.reload();}';
|
||||
}
|
||||
?>
|
||||
</script>
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* 个人用户的配置面板
|
||||
*
|
||||
* @access public
|
||||
* @param Typecho_Widget_Helper_Form $form
|
||||
* @return void
|
||||
*/
|
||||
public static function personalConfig(Typecho_Widget_Helper_Form $form){
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
27
changyandandian/README.md
Normal file
27
changyandandian/README.md
Normal file
@@ -0,0 +1,27 @@
|
||||
### 什么是单点评论
|
||||
当接入畅言云评论的网站有自己的账号系统时,想实现和云评论目前的账号体系兼容时,云评论提供以下单点登录解决方案,达到的效果为:您的网站登录了,云评论评论框自动登录;云评论评论框退出,您的网站自动退出!
|
||||
|
||||
具体就是网站登录好账号后,网站的畅言账号也会自动登录;或者点击畅言上边的登录点击设定好图标进入登录页面或者弹窗进行站点的登录;值得说明的是使用畅言里面的第三方登录并不会关联站点(此时就相当于站点的游客评论【未来也许能攻克,不过不太想花大量时间研究了,建议忽略哈!】)。
|
||||
|
||||
### Typecho畅言单点登录插件
|
||||
|
||||
### 使用方法
|
||||
**0,提醒**
|
||||
这个插件是畅言云评论的单点登录插件,在使用前请确保已经引用好畅言评论,引用方法详见畅言官网https://changyan.kuaizhan.com/
|
||||
|
||||
**1,上传并启动插件**
|
||||
将插件压缩包解压得到`changyandandian`的文件夹,将文件夹上传至`typecho`插件目录下(一般为`usr/plugins`),然后打开`typecho`后台,插件页面找到并启动该插件,插件设置里可设置登录页面地址或者登录弹窗调用函数(不懂也可以不填)!
|
||||
|
||||
**2,畅言PC版设置**
|
||||
打开畅言PC版设置开启单点登录,上传icon图标,然后选择js弹框登录,然后在下方输入`changyanlogin();`;用户信息接口url填写为`http://你的域名/changyan`;用户退出接口url填写为`http://你的域名/changyan/logout`;具体如下图。
|
||||
|
||||
![Typecho畅言单点登录插件.jpg][1]
|
||||
|
||||
**3,畅言WAP版设置**
|
||||
基本和pc版设置一样,唯一区别的是需要设置登录地址,一般设置为`http://你的域名/admin/login.php`即可,如下图
|
||||
|
||||
![Typecho畅言单点登录插件.jpg][2]
|
||||
|
||||
|
||||
[1]: https://static.yecdn.com/jrotty/2021/04/1525294631.jpg
|
||||
[2]: https://static.yecdn.com/jrotty/2021/04/1271132681.jpg
|
||||
Reference in New Issue
Block a user