歡迎光臨, 訪客. 請先 登入註冊一個帳號.
三月 29, 2024, 08:38:04 上午
19595 文章 在 3865 主題 由 4580 會員
最新註冊會員: aa123aa1
LifeType 中文開發論壇  |  開發  |  外掛程式  |  默认启用外挂? « 上篇主題 下篇主題 »
頁: 1 [2]
作者 主題: 默认启用外挂?  (閱讀 46955 次)
lss
我不是被~拉~~出來的,不要叫我大大!
總版主
超級會員
*****
文章: 1511



檢視個人資料 個人網站
« 回覆文章 #15 於: 四月 18, 2006, 07:35:56 上午 »

hi maomaode:

謝謝你囉 微笑

當初寫這個部份時,原本就很實驗性質 吐舌頭 ,正是要靠大家一起來完善他  微笑

我會先在我的文章中加個連結過來。最近很忙,再找時間研究看看。

lss
已記錄

沒找過 常見問題集或不知道 如何在 LifeType 中文開發論壇發問的人,恕不回答問題
maomaode
一般會員
***
文章: 115


檢視個人資料
« 回覆文章 #16 於: 四月 18, 2006, 04:16:46 下午 »

这里给出最终解决方案;
将原来的register方法修改成如下:
引用
    $config =& Config::getConfig();
    $this->cacheFolder = $config->getValue('temp_folder');
    $this->cacheFolder = $this->cacheFolder.'/authimage/'.$this->blogInfo->getId();
    if( !File::exists( $this->cacheFolder )) {
      File::createDir( $this->cacheFolder );
    }
         
    $blogSettings = $this->blogInfo->getSettings();
    $this->pluginEnabled = $blogSettings->getValue( "plugin_authimage_enabled" );
    $this->length = $this->_getSetting( "plugin_authimage_length" , 4);
    $this->key = $this->_getSetting( "plugin_authimage_key" , "pLog");
    $this->expiredTime = $this->_getSetting("plugin_authimage_expiredtime", 3600);
    $this->default = $this->_getSetting( "plugin_authimage_default", "marble.gif");

    if ( empty($this->pluginEnabled) ) {
      $blogSettings->setValue( "plugin_authimage_enabled", true );
      $blogSettings->setValue( "plugin_authimage_length", $this->length );
      $blogSettings->setValue( "plugin_authimage_key", $this->key );
      $blogSettings->setValue( "plugin_authimage_expiredtime", $this->expiredTime );
      $blogSettings->setValue( "plugin_authimage_default", $this->default );
     
      $this->blogInfo->setSettings( $blogSettings );
      $blogs = new Blogs();
      $blogs->updateBlog( $this->blogInfo->getId(), $this->blogInfo );

      $this->pluginEnabled = $blogSettings->getValue( "plugin_authimage_enabled" );

再添加如下方法:
引用
  function _getSetting($key, $defaultValue)
  {
    $value = $this->blogInfo->_settings->getValue($key);
    return empty($value) ? $defaultValue : $value;
  }

应该可以工作了, 不过还是有的小毛病
1。 blogsetting段在pluginauthimageupdateconfigaction.class.php中也出现了, 所以有点重复, 可以提取出来
2。 默认值在pluginauthimage.class.php 中和pluginauthimageconfigview.class.php中同时出现, 应该可以提取出来
3。 pluginauthimage.class.php中的updateBlog没有判断是否成功,没有相关错误处理。
4。最大的一个缺点是, 没有办法关闭这个plugin了

因为register这个方法在每个action触发中都会被调用, 所以当pluginauthimageupdateconfigaction被调用时候, register方法又一次被调用, 导致每次写入的都是register方法里设定的值。 参考adminaction.class.php 的setCommonData()方法。

问题还不少,如何改进就留给读者了吧。。。
« 最後編輯時間: 四月 18, 2006, 04:41:08 下午 由 maomaode » 已記錄

我的blog:
               http://maomaode.bokeland.com
Blog搬家/同步
               http://banjia.bokeland.com
maomaode
一般會員
***
文章: 115


檢視個人資料
« 回覆文章 #17 於: 四月 18, 2006, 07:53:10 下午 »

这个问题最终还是可以解决,
我已经将具体的解决方案写在 LifeType 外挂如何实现默认启动?
« 最後編輯時間: 四月 18, 2006, 07:56:30 下午 由 maomaode » 已記錄

我的blog:
               http://maomaode.bokeland.com
Blog搬家/同步
               http://banjia.bokeland.com
maomaode
一般會員
***
文章: 115


檢視個人資料
« 回覆文章 #18 於: 十一月 27, 2006, 03:12:56 下午 »

1.1.1 是否已经包含了这个功能?
我们还需要按照这个步骤来实现默认启用外挂吗?

或者说什么时候可以包含到核心里呢?
已記錄

我的blog:
               http://maomaode.bokeland.com
Blog搬家/同步
               http://banjia.bokeland.com
panying
新手見習
*
文章: 39


檢視個人資料
« 回覆文章 #19 於: 十一月 27, 2006, 03:24:11 下午 »

其实我曾经做了一个更通用的插件版本, 吐舌頭

可以查看: http://www.pactofshadow.com/lifetype/~nest/article/35.html

最新版本可以察看: http://www.pactofshadow.com/lifetype/~nest/article/53.html

实现就是重载blogsettings.php的function getValue( $key, $defaultValue = null ),然后通过插件判断是否读取默认值,并且有个简陋的界面。
已記錄

maomaode
一般會員
***
文章: 115


檢視個人資料
« 回覆文章 #20 於: 十一月 27, 2006, 05:37:07 下午 »

你的例子, 只给出了一个authimage 的设置方法, 如果是有多个plugin的情况下, defaultProperty  和 same setting property 会不会因为放入太多的内容, 而显的零乱.

不过这个想法非常好, 也感谢你的分享
已記錄

我的blog:
               http://maomaode.bokeland.com
Blog搬家/同步
               http://banjia.bokeland.com
maomaode
一般會員
***
文章: 115


檢視個人資料
« 回覆文章 #21 於: 十一月 27, 2006, 07:42:05 下午 »

OK, 看样子, 我们的1.1.1里面还没有加入默认启用外挂这个功能,

我又重新做了调整,
下面是我的解决方案:
1. 在/class/plugin/pluginbase下加入下面两个方法:
引用
      function _getSetting($key, $defaultValue)
      {
        $value = $this->blogSettings->getValue($key);
        return empty($value) ? $defaultValue : $value;
      }
     
      function update2Default($defaultValues = null) {
        $plugin_is_virgin = 'plugin_' . $this->id . '_virgin';
       
        $this->virgin = $this->_getSetting( $plugin_is_virgin, true);
       
        if ( empty($this->pluginEnabled) && $this->virgin === true ) {
          $base = 'plugin_' . $this->id . '_';
         
          $this->blogSettings->setValue( $base . 'enabled', true );
          $this->blogSettings->setValue( $base . 'virgin', 'no' );

          if (!empty($defaultValues)) {
            foreach($defaultValues as $key => $value) {
              $this->blogSettings->setValue($base . $key, $value);
            }
          }

          $this->blogInfo->setSettings( $this->blogSettings );
          $blogs = new Blogs();
          $blogs->updateBlog( $this->blogInfo );
          $this->pluginEnabled = $this->blogSettings->getValue( $base . 'enabled' );
        }
       
      }

在你所需要默认的plugin 的register 方法末尾添加如下代码:
引用

            $this->update2Default();
如果你希望加入默认值, 就将以上代码替换为: (以authimage) 为例:
引用
              $defaultValues = array('length' => $this->length,
                                   'key' => $this->key,
                                   'expiredtime' => $this->expiredTime,
                                   'default' => $this->default
                                   );
            $this->update2Default($defaultValues);

更详细的内容可以参考LifeType 外挂如何实现默认启动? (续)
« 最後編輯時間: 十一月 27, 2006, 08:11:16 下午 由 maomaode » 已記錄

我的blog:
               http://maomaode.bokeland.com
Blog搬家/同步
               http://banjia.bokeland.com
頁: 1 [2]
LifeType 中文開發論壇  |  開發  |  外掛程式  |  默认启用外挂? « 上篇主題 下篇主題 »
    前往: