Couple Blog作者qining啊,你在哪儿

插件开发及发布

版主: woniou

回复
以码为梦
帖子: 14
注册时间: 2016年 10月 31日 21:42

Couple Blog作者qining啊,你在哪儿

帖子 以码为梦 »

代码: 全选

<?php
/**
 * 情侣博客插件, 可以把文章按作者成不同的栏目
 *
 * @package Couple Blog
 * @author qining
 * @version 1.0.0
 * @dependence 9.11.25-*
 * @link http://typecho.org
 */
class CoupleBlog implements Typecho_Plugin_Interface
{
    /**
     * 激活插件方法,如果激活失败,直接抛出异常
     *
     * @access public
     * @return void
     * @throws Typecho_Plugin_Exception
     */
    public static function activate()
    {
        Typecho_Plugin::factory('Widget_Archive')->query = array('CoupleBlog', 'query');
        Typecho_Plugin::factory('Widget_Archive')->___isLeft = array('CoupleBlog', '___isLeft');
        Typecho_Plugin::factory('Widget_Archive')->___isRight = array('CoupleBlog', '___isRight');
       
        return _t('请到插件配置里设置双栏分别显示的作者');
    }
   
    /**
     * 禁用插件方法,如果禁用失败,直接抛出异常
     *
     * @static
     * @access public
     * @return void
     * @throws Typecho_Plugin_Exception
     */
    public static function deactivate(){}
   
    /**
     * 获取插件配置面板
     *
     * @access public
     * @param Typecho_Widget_Helper_Form $form 配置面板
     * @return void
     */
    public static function config(Typecho_Widget_Helper_Form $form)
    {
        $db = Typecho_Db::get();
        $result = $db->fetchAll($db->select('uid', 'screenName')->from('table.users'));
        $authors = array();
       
        foreach ($result as $row) {
            $authors[$row['uid']] = $row['screenName'];
        }
   
        $leftAuthor = new Typecho_Widget_Helper_Form_Element_Select('leftAuthorId', $authors, 0, '第一栏显示的作者');
        $form->addInput($leftAuthor);
       
        $rightAuthor = new Typecho_Widget_Helper_Form_Element_Select('rightAuthorId', $authors, 0, '第二栏显示的作者');
        $form->addInput($rightAuthor);
    }
   
    /**
     * 个人用户的配置面板
     *
     * @access public
     * @param Typecho_Widget_Helper_Form $form
     * @return void
     */
    public static function personalConfig(Typecho_Widget_Helper_Form $form){}
   
    /**
     * 是否为左侧
     *
     * @access public
     * @param Typecho_Archive $widget archive组件
     * @return void
     */
    public static function ___isLeft($widget)
    {
        return $widget->authorId == Helper::options()->plugin('CoupleBlog')->leftAuthorId;
    }
   
    /**
     * 是否为右侧
     *
     * @access public
     * @param Typecho_Archive $widget archive组件
     * @return void
     */
    public static function ___isRight($widget)
    {   
      
        return $widget->authorId == Helper::options()->plugin('CoupleBlog')->rightAuthorId;
    }
   
    /**
     * 插件实现方法
     *
     * @access public
     * @return void
     */
    public static function query($widget, $select)
    {
        $db = Typecho_Db::get();
   
        /** 排除一些特殊情况 */
        if ($widget->is('single') || $widget->is('author')) {
            $db->fetchAll($select, array($widget, 'push'));
            return;
        }
       
        /** 精彩部分来了 */
        $leftCountSql = $widget->getCountSql();
        $rightCountSql = clone $leftCountSql;
       
        $leftCountSql->where('table.contents.authorId = ?', Helper::options()->plugin('CoupleBlog')->leftAuthorId);
        $rightCountSql->where('table.contents.authorId = ?', Helper::options()->plugin('CoupleBlog')->rightAuthorId);
       
        $leftCount = $widget->size($leftCountSql);
        $rightCount  =$widget->size($rightCountSql);
       
        /** 翻页依据文章数最多的那一位 */
        $widget->setTotal(max($leftCount, $rightCount));
       
        $leftSql = $select;
        $rightSql = clone $select;
       
        $leftSql->where('table.contents.authorId = ?', Helper::options()->plugin('CoupleBlog')->leftAuthorId);
        $rightSql->where('table.contents.authorId = ?', Helper::options()->plugin('CoupleBlog')->rightAuthorId);
       
        $db->fetchAll($leftSql, array($widget, 'push'));
        $db->fetchAll($rightSql, array($widget, 'push'));
    }
}


以上是你的插件,但是我用了莫名其妙的有个BUG,右边比左边少一篇文章,但是左右同一作者的话,文章数又相同。
头像
ClayMore
帖子: 2481
注册时间: 2007年 11月 29日 02:55
来自: Sleeping Forest
联系:

Re: Couple Blog作者qining啊,你在哪儿

帖子 ClayMore »

作者就是SF的联合创始人



__________________

新版阿里百秀Alibaixiu主题 v11.1 For Typecho
http://xiu.160.me/
以码为梦
帖子: 14
注册时间: 2016年 10月 31日 21:42

Re: Couple Blog作者qining啊,你在哪儿

帖子 以码为梦 »

意思是我去SF问了?
头像
ClayMore
帖子: 2481
注册时间: 2007年 11月 29日 02:55
来自: Sleeping Forest
联系:

Re: Couple Blog作者qining啊,你在哪儿

帖子 ClayMore »

意思是你不用找 作者很忙



__________________

新版阿里百秀Alibaixiu主题 v11.1 For Typecho
http://xiu.160.me/
头像
m4go
帖子: 857
注册时间: 2010年 3月 29日 02:33
来自: https://www.vpshu.com
联系:

Re: Couple Blog作者qining啊,你在哪儿

帖子 m4go »

你看一下,你后台设置的每页文章数量是多少?如果是奇数,弄成偶数试试。
以码为梦
帖子: 14
注册时间: 2016年 10月 31日 21:42

Re: Couple Blog作者qining啊,你在哪儿

帖子 以码为梦 »

m4go 写了:你看一下,你后台设置的每页文章数量是多少?如果是奇数,弄成偶数试试。

试了,还是不行 :(
以码为梦
帖子: 14
注册时间: 2016年 10月 31日 21:42

Re: Couple Blog作者qining啊,你在哪儿

帖子 以码为梦 »

ClayMore 写了:意思是你不用找 作者很忙



__________________

新版阿里百秀Alibaixiu主题 v11.1 For Typecho
http://xiu.160.me/


哭晕在厕所
爱微语
帖子: 9
注册时间: 2016年 11月 9日 16:14
联系:

Re: Couple Blog作者qining啊,你在哪儿

帖子 爱微语 »

其实TY插件真的很老旧了,很少人更新了,没活力
还是用代码吧


__________________


so.com专注于文字,社交,资源分享为一体的综合型网站,是一个值得收藏的网站!http://so.com
回复