分页: 1 / 1

Couple Blog作者qining啊,你在哪儿

发表于 : 2016年 10月 31日 21:49
以码为梦

代码: 全选

<?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,右边比左边少一篇文章,但是左右同一作者的话,文章数又相同。

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

发表于 : 2016年 11月 2日 01:02
ClayMore
作者就是SF的联合创始人



__________________

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

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

发表于 : 2016年 11月 2日 09:22
以码为梦
意思是我去SF问了?

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

发表于 : 2016年 11月 2日 23:45
ClayMore
意思是你不用找 作者很忙



__________________

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

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

发表于 : 2016年 11月 3日 08:14
m4go
你看一下,你后台设置的每页文章数量是多少?如果是奇数,弄成偶数试试。

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

发表于 : 2016年 11月 7日 14:16
以码为梦
m4go 写了:你看一下,你后台设置的每页文章数量是多少?如果是奇数,弄成偶数试试。

试了,还是不行 :(

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

发表于 : 2016年 11月 7日 14:16
以码为梦
ClayMore 写了:意思是你不用找 作者很忙



__________________

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


哭晕在厕所

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

发表于 : 2016年 11月 10日 17:34
爱微语
其实TY插件真的很老旧了,很少人更新了,没活力
还是用代码吧


__________________


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