首頁  >  文章  >  後端開發  >  Typecho 新浪登陸外掛程式 Sinauth

Typecho 新浪登陸外掛程式 Sinauth

WBOY
WBOY原創
2016-08-08 09:23:381039瀏覽

花了點時間弄了一個插件。

程式碼位址: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>');
    }
    
    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>
<code>class Sinauth_AuthorizeAction extends Typecho_Widget implements Widget_Interface_Do
{
    public function action(){
        
    }

    public function callback(){
        
    }
}</code>

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

<code><?php $this->user->sinauthAuthorizeIcon(); ?></code>

以上就介紹了Typecho 新浪登陸外掛程式 Sinauth,包含了方面的內容,希望對PHP教學有興趣的朋友有幫助。

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn