Ejemplo n.º 1
0
/**
 * 发表文章自动发表微博插件
 */
function plgWeibo(&$row, $isNew)
{
    $plugin =& JPluginHelper::getPlugin('content', 'weibo');
    $pluginParams = new JParameter($plugin->params);
    // 只处理新建的文章,所以如果不是新文章,直接返回
    if (!$isNew) {
        return true;
    }
    // 如果没有启用本插件,则直接返回
    if ($pluginParams) {
        if (!JPluginHelper::isEnabled('content', 'weibo')) {
            return true;
        }
    }
    // 参数的设置
    $P['sinaenabled'] = $pluginParams->get('sinaenabled');
    //是否启用新浪微博
    if ($P['sinaenabled']) {
        // 如果启动新浪微博,则取得数据库中存储的新浪微博授权码
        $db =& JFactory::getDBO();
        $sql = "SELECT  oauth_token, oauth_token_secret, name FROM #__weibo_auth WHERE id = '2' AND type='sina'";
        $db->setQuery($sql);
        $result = $db->loadAssoc();
        $P['sinalastkey'] = $result;
    }
    $P['tencentenabled'] = $pluginParams->get('tencentenabled');
    //是否启用腾讯微博
    if ($P['tencentenabled']) {
        // 如果启动腾讯微博,则取得数据库中存储的腾讯微博授权码
        $db =& JFactory::getDBO();
        $sql = "SELECT  oauth_token, oauth_token_secret, name FROM #__weibo_auth WHERE id = '1' AND type='tencent'";
        $db->setQuery($sql);
        $result = $db->loadAssoc();
        $P['tencentlastkey'] = $result;
    }
    $P['weibotype'] = $pluginParams->get('weibotype');
    // 微博发表方式(fulltext,onlytitle,introtext或者custom)
    $P['catid'] = $pluginParams->get('catid');
    // 所指定的分类
    $P['customstring'] = $pluginParams->get('customstring');
    // 自定义的字符串
    $P['picsend'] = $pluginParams->get('picsend');
    // 将文章中的第一幅图片发布到微博上
    // 如果设置的文章的分类,则检查本文是否属于这个分类,如果不是,直接返回
    if ($P['catid']) {
        if ($row->catid != $P['catid']) {
            return true;
        }
    }
    // 准备微博文字和图片
    getWeiboText($row, $P, $weibocontent);
    // 发送新浪微博
    if ($P['sinaenabled'] && $P['sinalastkey']) {
        sendSinaWeibo($weibocontent, $P);
    }
    // 发送腾讯微博
    if ($P['tencentenabled'] && $P['tencentlastkey']) {
        sendTencentWeibo($weibocontent, $P);
    }
    return true;
}
Ejemplo n.º 2
0
/**
 * 发送网易微博
 */
function sendTwitterWeibo($row, $P)
{
    // 如果没有得到本类微博的授权,不发表
    if (!$P['neteaselastkey']) {
        return false;
    }
    $option = $P['typeoption']['twitter'];
    if (!$option) {
        return false;
    }
    // 准备微博文字和图片
    getWeiboText($row, $option, $weibocontent);
    $tmhOAuth = new tmhOAuth(array('consumer_key' => TW_AKEY, 'consumer_secret' => TW_SKEY, 'user_token' => $P['twitterlastkey']['oauth_token'], 'user_secret' => $P['twitterlastkey']['oauth_token_secret']));
    $code = $tmhOAuth->request('POST', $tmhOAuth->url('1/statuses/update'), array('status' => $weibocontent['text']));
    return '';
}