zoukankan      html  css  js  c++  java
  • Typecho 新浪登陆插件 Sinauth

    花了点时间弄了一个插件。

    代码地址:https://github.com/web3d/plugins/tree/master/Sinauth

    Typecho的扩展机制还是比较完善的,可以自行增加Action、Route、扩展现有Widget功能、后台插件配置界面等。

    偷懒,使用的是SAE中封装的sdk访问新浪开放平台数据。

    插件放到/root_path/usr/plugins/Sinauth 目录下:

    Plugin.php
    AuthorizeAction.php
    

    Plugin.php用于插件初始化,AuthorizeAction.php用于扩展功能。

    <?php
    class Sinauth_Plugin implements Typecho_Plugin_Interface
    {
        /**
         * 激活插件方法,如果激活失败,直接抛出异常
         * 
         * @access public
         * @return void
         * @throws Typecho_Plugin_Exception
         */
        public static function activate()
        {
            Typecho_Plugin::factory('Widget_User')->___sinauthAuthorizeIcon = array('Sinauth_Plugin', 'authorizeIcon');
            
            Helper::addAction('sinauthAuthorize', 'Sinauth_AuthorizeAction');
            Helper::addRoute('sinauthAuthorize', '/sinauthAuthorize/', 'Sinauth_AuthorizeAction', 'action');
            Helper::addRoute('sinauthCallback', '/sinauthCallback/', 'Sinauth_AuthorizeAction', 'callback');
            
            return _t($meg.'。请进行<a href="options-plugin.php?config='.self::$pluginName.'">初始化设置</a>');
        }
        
        public static function install()
        {
           //db创建
        }
    
        /**
         * 获取插件配置面板
         * 
         * @access public
         * @param Typecho_Widget_Helper_Form $form 配置面板
         * @return void
         */
        public static function config(Typecho_Widget_Helper_Form $form)
        {
            $client_id = new Typecho_Widget_Helper_Form_Element_Text('client_id', NULL,'', _t('App Key'),'请在微博开放平台查看http://open.weibo.com');
            $form->addInput($client_id);
            
            $client_secret = new Typecho_Widget_Helper_Form_Element_Text('client_secret', NULL,'', _t('App Secret'),'请在微博开放平台查看http://open.weibo.com');
            $form->addInput($client_secret);
            
            $callback_url = new Typecho_Widget_Helper_Form_Element_Text('callback_url', NULL,'http://', _t('回调地址'),'请与微博开放平台中设置一致');
            $form->addInput($callback_url);
            
        }
    }
    
    class Sinauth_AuthorizeAction extends Typecho_Widget implements Widget_Interface_Do
    {
        public function action(){
            
        }
    
        public function callback(){
            
        }
    }
    

    在需要放入口的地方,加上

    <?php $this->user->sinauthAuthorizeIcon(); ?>
    
  • 相关阅读:
    Set / Map 集合 -ES6
    getter/setter
    构造函数-class类 -语法糖 -ES6
    原型链-继承
    创建对象/克隆
    Generator生成器函数- ES6
    iframe跨域访问
    setTimeout延迟加载
    adt新建项目后去掉appcompat_v7的解决方法
    PHP数组的操作
  • 原文地址:https://www.cnblogs.com/x3d/p/typecho-plugin-sinauth.html
Copyright © 2011-2022 走看看