예제 #1
0
function xmt_twt_raw_imp($acc, $req, $typ = 'twt')
{
    global $xmt_acc;
    if ($typ == 'dmg') {
        $req = str_replace('direct-messages', 'statuses', $req);
        $req = str_replace('direct_message', 'status', $req);
        $req = str_replace('sender', 'user', $req);
    }
    if ($req == '') {
        return;
    }
    $arr_twt = json_decode($req, true);
    if (!$arr_twt) {
        xmt_log($req);
        return;
    } elseif ($arr_twt['errors']) {
        xmt_log($arr_twt['errors'][0]['message'] . ' (Code: ' . $arr_twt['errors'][0]['code'] . ')');
        return;
    }
    foreach ($arr_twt as $res) {
        $twt_typ = $typ;
        if ($res['retweeted']) {
            $twt_typ = 'rtw';
        }
        $rpl = (string) $res['in_reply_to_screen_name'];
        if ($rpl != '') {
            if ($rpl == $xmt_acc[$acc]['cfg']['twt_usr_nme']) {
                $twt_typ = 'rty';
            } else {
                $twt_typ = 'rfy';
            }
        }
        xmt_twt_ins($acc, array('id' => (string) $res['id_str'], 'twt' => (string) $res['text'], 'ath' => (string) $res['user']['screen_name'], 'src' => (string) $res['source'], 'dtp' => date('Y-m-d H:i:s', xmt_get_time((string) $res['created_at'])), 'typ' => $twt_typ));
        xmt_ath_ins(array('uid' => (string) $res['user']['screen_name'], 'nme' => (string) $res['user']['name'], 'img_url' => (string) $res['user']['profile_image_url']));
    }
    unset($arr_twt);
}
예제 #2
0
function xmt_get_file($name)
{
    $res = '';
    $res = @file_get_contents($name);
    if ($res === false || $res == '') {
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $name);
        curl_setopt($ch, CURLOPT_AUTOREFERER, 0);
        curl_setopt($ch, CURLOPT_HEADER, 0);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_REFERER, $name);
        @curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
        @curl_setopt($ch, CURLOPT_TIMEOUT, 10);
        @curl_setopt($ch, CURLOPT_TIMEVALUE, null);
        @curl_setopt($ch, CURLOPT_TIMECONDITION, 0);
        curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.1.17) Gecko/20110121 Firefox/3.5.17');
        $res = curl_exec($ch);
        if ($res === false) {
            xmt_log('Failed to read feeds from twitter because of ' . curl_error($ch));
        }
        curl_close($ch);
    }
    return $res;
}
function widget_xmt($args, $acc)
{
    global $wpdb;
    global $xmt_tmd;
    global $xmt_acc;
    $xmt_tmd = time();
    xmt_log('Starting to generate output');
    extract($args);
    $cur_role = xmt_get_role();
    $alw_twt = false;
    $msg = '';
    if ($cur_role == 'administrator' && $xmt_acc[$acc]['cfg']['oah_use'] && $xmt_acc[$acc]['cfg']['shw_pst_frm']) {
        $alw_twt = true;
    }
    $frc = false;
    if (isset($_GET['xmt_debug_show']) || isset($_GET['xmt_debug'])) {
        $frc = true;
    }
    xmt_twt_imp($acc, $frc);
    if ($alw_twt && isset($_POST['cmd_xmt_' . $acc . '_post'])) {
        $t_tweet = trim(xmt_form_post('txa_xmt_' . $acc . '_tweet'));
        if (!wp_verify_nonce($_POST['vrf_xmt_wgt_twt_frm_' . $acc], 'xmt_twt_frm')) {
            $msg = 'Invalid form verification token';
        }
        if ($t_tweet == '') {
            $msg = 'Your tweet is empty!';
        }
        if (strlen($t_tweet) > 140) {
            $msg = 'Your tweet exceeds 140 characters!';
        }
        if ($msg == '') {
            xmt_twt_oah_twt_pst($acc, $t_tweet);
            $msg = 'Your tweet has been posted';
            $xmt_acc[$acc]['las_twt_imp_dtp'] = 0;
            xmt_twt_cch_rst($acc);
            xmt_twt_imp($acc);
        }
    }
    if ($cur_role == 'administrator' && isset($_GET['xmt_' . $acc . '_twt_id'])) {
        if (wp_verify_nonce($_GET['_wpnonce'], 'xmt_wgt_act')) {
            $twt_id = trim(xmt_form_get('xmt_' . $acc . '_twt_id'));
            xmt_twt_del($acc, $twt_id);
            xmt_twt_cch_rst($acc);
            $msg = 'Your tweet has been deleted';
        }
    }
    $res = xmt_twt_get($acc);
    if (!$res || !is_array($res)) {
        $res = array();
    }
    $tpl = xmt_base_dir . '/theme/' . $xmt_acc[$acc]['cfg']['thm'] . '/widget.php';
    if (!file_exists($tpl)) {
        $tpl = xmt_base_dir . '/theme/default/widget.php';
    }
    include $tpl;
    xmt_tmd('Finished');
}