Typecho Sina login plug-in Sinauth

WBOY
Release: 2016-08-08 09:23:38
Original
1087 people have browsed it

It took me some time to get a plug-in.

Code address: https://github.com/web3d/plugins/tree/master/Sinauth

Typecho’s expansion mechanism is relatively complete. You can add Action, Route, extend existing Widget functions, and background plug-in configuration interface. wait.

I am lazy and use the SDK packaged in SAE to access Sina Open Platform data.

Put the plug-in in the /root_path/usr/plugins/Sinauth directory:

<code>Plugin.php
AuthorizeAction.php</code>
Copy after login

Plugin.php is used for plug-in initialization, and AuthorizeAction.php is used for extended functions.

<code><?php
class Sinauth_Plugin implements Typecho_Plugin_Interface
{
    /**
     * 激活插件方法,如果激活失败,直接抛出异常
     * 
     * @access public
     * @return void
     * @throws Typecho_Plugin_Exception
     */
    public static function activate()
    {
        Typecho_Plugin::factory(&#39;Widget_User&#39;)->___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?c/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);
        
    }
}</code>
Copy after login
<code>class Sinauth_AuthorizeAction extends Typecho_Widget implements Widget_Interface_Do
{
    public function action(){
        
    }

    public function callback(){
        
    }
}</code>
Copy after login

Add

<code><?php $this->user->sinauthAuthorizeIcon(); ?></code>
Copy after login
where you need to put it in your mouth

The above introduces the Typecho Sina login plug-in Sinauth, including the relevant content. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template