Heim  >  Artikel  >  Backend-Entwicklung  >  Typecho 新浪登陆插件 Sinauth

Typecho 新浪登陆插件 Sinauth

WBOY
WBOYOriginal
2016-08-08 09:23:381040Durchsuche

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

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

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

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

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

<code>Plugin.php
AuthorizeAction.php</code>

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

<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>');%0A%20%20%20%20%7D%0A%20%20%20%20%0A%20%20%20%20public%20static%20function%20install()%0A%20%20%20%20%7B%0A%20%20%20%20%20%20%20//db%E5%88%9B%E5%BB%BA%0A%20%20%20%20%7D%0A%0A%20%20%20%20/**%0A%20%20%20%20%20*%20%E8%8E%B7%E5%8F%96%E6%8F%92%E4%BB%B6%E9%85%8D%E7%BD%AE%E9%9D%A2%E6%9D%BF%0A%20%20%20%20%20*%20%0A%20%20%20%20%20*%20@access%20public%0A%20%20%20%20%20*%20@param%20Typecho_Widget_Helper_Form%20%24form%20%E9%85%8D%E7%BD%AE%E9%9D%A2%E6%9D%BF%0A%20%20%20%20%20*%20@return%20void%0A%20%20%20%20%20*/%0A%20%20%20%20public%20static%20function%20config(Typecho_Widget_Helper_Form%20%24form)%0A%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%24client_id%20=%20new%20Typecho_Widget_Helper_Form_Element_Text('client_id',%20NULL,'',%20_t('App%20Key'),'%E8%AF%B7%E5%9C%A8%E5%BE%AE%E5%8D%9A%E5%BC%80%E6%94%BE%E5%B9%B3%E5%8F%B0%E6%9F%A5%E7%9C%8Bhttp://open.weibo.com');%0A%20%20%20%20%20%20%20%20%24form->addInput(%24client_id);%0A%20%20%20%20%20%20%20%20%0A%20%20%20%20%20%20%20%20%24client_secret%20=%20new%20Typecho_Widget_Helper_Form_Element_Text('client_secret',%20NULL,'',%20_t('App%20Secret'),'%E8%AF%B7%E5%9C%A8%E5%BE%AE%E5%8D%9A%E5%BC%80%E6%94%BE%E5%B9%B3%E5%8F%B0%E6%9F%A5%E7%9C%8Bhttp://open.weibo.com');%0A%20%20%20%20%20%20%20%20%24form->addInput(%24client_secret);%0A%20%20%20%20%20%20%20%20%0A%20%20%20%20%20%20%20%20%24callback_url%20=%20new%20Typecho_Widget_Helper_Form_Element_Text('callback_url',%20NULL,'http://',%20_t('%E5%9B%9E%E8%B0%83%E5%9C%B0%E5%9D%80'),'%E8%AF%B7%E4%B8%8E%E5%BE%AE%E5%8D%9A%E5%BC%80%E6%94%BE%E5%B9%B3%E5%8F%B0%E4%B8%AD%E8%AE%BE%E7%BD%AE%E4%B8%80%E8%87%B4');%0A%20%20%20%20%20%20%20%20%24form->addInput(%24callback_url);%0A%20%20%20%20%20%20%20%20%0A%20%20%20%20%7D%0A%7D</code>
<code>class%20Sinauth_AuthorizeAction%20extends%20Typecho_Widget%20implements%20Widget_Interface_Do%0A%7B%0A%20%20%20%20public%20function%20action()%7B%0A%20%20%20%20%20%20%20%20%0A%20%20%20%20%7D%0A%0A%20%20%20%20public%20function%20callback()%7B%0A%20%20%20%20%20%20%20%20%0A%20%20%20%20%7D%0A%7D</code>

%E5%9C%A8%E9%9C%80%E8%A6%81%E6%94%BE%E5%85%A5%E5%8F%A3%E7%9A%84%E5%9C%B0%E6%96%B9%EF%BC%8C%E5%8A%A0%E4%B8%8A

<code><?php%20%24this->user->sinauthAuthorizeIcon();%20?></code>
%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20

%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%E4%BB%A5%E4%B8%8A%E5%B0%B1%E4%BB%8B%E7%BB%8D%E4%BA%86Typecho%20%E6%96%B0%E6%B5%AA%E7%99%BB%E9%99%86%E6%8F%92%E4%BB%B6%20Sinauth%EF%BC%8C%E5%8C%85%E6%8B%AC%E4%BA%86%E6%96%B9%E9%9D%A2%E7%9A%84%E5%86%85%E5%AE%B9%EF%BC%8C%E5%B8%8C%E6%9C%9B%E5%AF%B9PHP%E6%95%99%E7%A8%8B%E6%9C%89%E5%85%B4%E8%B6%A3%E7%9A%84%E6%9C%8B%E5%8F%8B%E6%9C%89%E6%89%80%E5%B8%AE%E5%8A%A9%E3%80%82

%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20

%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20

%0A%20%20%20%20%20%20%20%20%20%20%20%20%20">
Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn