Example #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;
}
Example #2
0
 /**
  * Joomla 1.7 发表文章自动发表微博用插件函数
  */
 function onContentAfterSave($context, &$row, $isNew)
 {
     global $mainframe;
     // 只处理新建的文章,所以如果不是新文章,直接返回
     if (!$isNew) {
         return true;
     }
     // 如果没有启用本插件,则直接返回
     if (!$this->params->get('enabled', 1)) {
         return true;
     }
     //取得数据库中存储的新浪微博授权码
     $db =& JFactory::getDBO();
     $sql = "SELECT  oauth_token, oauth_token_secret, name FROM #__weibo_auth WHERE type='sina'";
     $db->setQuery($sql);
     $result = $db->loadAssoc();
     $P['sinalastkey'] = $result;
     $sql = "SELECT  oauth_token, oauth_token_secret, name FROM #__weibo_auth WHERE type='sinakey'";
     $db->setQuery($sql);
     $result = $db->loadAssoc();
     $P['sinakey'] = $result;
     // 取得数据库中存储的腾讯微博授权码
     $sql = "SELECT  oauth_token, oauth_token_secret, name FROM #__weibo_auth WHERE type='tencent'";
     $db->setQuery($sql);
     $result = $db->loadAssoc();
     $P['tencentlastkey'] = $result;
     // 取得数据库中存储的网易微博授权码
     $sql = "SELECT  oauth_token, oauth_token_secret, name FROM #__weibo_auth WHERE type='netease'";
     $db->setQuery($sql);
     $result = $db->loadAssoc();
     $P['neteaselastkey'] = $result;
     // 取得数据库中存储的Twitter授权码
     $db =& JFactory::getDBO();
     $sql = "SELECT  oauth_token, oauth_token_secret, name FROM #__weibo_auth WHERE type='twitter'";
     $db->setQuery($sql);
     $result = $db->loadAssoc();
     $P['twitterlastkey'] = $result;
     // 本微博的分类ID
     $P['row_catid'] = $row->catid;
     // 参数的设置
     $P['catoption'] = array();
     // 这个是对各个分类的设定
     $catp = array();
     $catp['catid'] = $this->params->get('catid') ? $this->params->get('catid') : 'all';
     // 所指定的分类
     $catp['weibotype'] = $this->params->get('weibotype', 'fulltext');
     // 微博发表方式(fulltext,onlytitle,introtext或者custom)
     $P['weibotype'] = $catp['weibotype'];
     // 缺省时也使用这个参数
     $catp['customstring'] = $this->params->get('customstring');
     // 自定义的字符串
     $P['customstring'] = $catp['customstring'];
     $catp['picsend'] = $this->params->get('picsend', true);
     // 将文章中的第一幅图片发布到微博上
     $P['picsend'] = $catp['picsend'];
     $P['sinaenabled'] = $this->params->get('sinaenabled', false);
     //是否启用新浪微博
     $catp['sina'] = $P['sinaenabled'];
     $P['tencentenabled'] = $this->params->get('tencentenabled', false);
     //是否启用腾讯微博
     $catp['tencent'] = $P['tencentenabled'];
     $P['neteaseenabled'] = $this->params->get('neteaseenabled', false);
     //是否启用网易微博
     $catp['netease'] = $P['neteaseenabled'];
     $P['twitterenabled'] = $this->params->get('twitterenabled', false);
     //是否启用twitter
     $catp['twitter'] = $P['twitterenabled'];
     $catp['norecursive'] = 0;
     // 仅对1.6及以上版本有用,缺省时分类的判断是依据分类及子分类
     $P['norecursive'] = 0;
     $P['cat_option'][] = $catp;
     // 加入分类设定之中
     $P['customoption'] = $this->params->get('customoption', true);
     // 获取高级自定义设置
     // 这里对customoption进行分解
     $optionlines = explode("\n", $P['customoption']);
     // 对于某一个类型微博指定类型的话,可以用
     //  catid=23,sina=1,tencent=1,weibotype=fulltext,picsend=0,customstring=aaaa
     foreach ($optionlines as $optionline) {
         $temp = explode(',', $optionline);
         $temp3 = array();
         foreach ($temp as $temp1) {
             $temp2 = explode('=', $temp1);
             if ($temp2[0]) {
                 $temp3[$temp2[0]] = $temp2[1] ? $temp2[1] : NULL;
             }
         }
         if ($temp3['catid']) {
             // 目前,只有含有catid设置的才被认为是有意义的设置,其他的行都忽略
             $P['cat_option'][] = $temp3;
         }
     }
     $P['typeoption'] = array();
     // 对于每一个分类的设置,看看本次微博是不是属于此分类
     foreach ($P['cat_option'] as $option) {
         if (inCat($P['row_catid'], $option['catid'], $option['norecursive'])) {
             // 如果属于这类
             if ($option['sina']) {
                 $P['typeoption']['sina'] = $option;
             }
             if ($option['twitter']) {
                 $P['typeoption']['twitter'] = $option;
             }
             if ($option['tencent']) {
                 $P['typeoption']['tencent'] = $option;
             }
             if ($option['netease']) {
                 $P['typeoption']['netease'] = $option;
             }
         }
     }
     $rtntext = '';
     // 发送新浪微博
     $rtninfo = sendSinaWeibo($row, $P);
     if ($rtninfo) {
         $rtntext .= $rtninfo . ';';
     }
     // 发送腾讯微博
     $rtninfo = sendTencentWeibo($row, $P);
     if ($rtninfo) {
         $rtntext .= $rtninfo . ';';
     }
     // 发送网易微博
     $rtninfo = sendNeteaseWeibo($row, $P);
     if ($rtninfo) {
         $rtntext .= $rtninfo . ';';
     }
     // 发送网易微博
     $rtninfo = sendTwitterWeibo($row, $P);
     if ($rtninfo) {
         $rtntext .= $rtninfo;
     }
     if ($rtntext) {
         $row->fulltext .= "<!-- Donot delete this comment 请勿删除此句 {" . $rtntext . '} -->';
     }
     return true;
 }