Пример #1
0
 function tweets()
 {
     if (!class_exists('Codebird')) {
         include_once 'codebird.php';
     }
     $cb = new Codebird();
     $method = sh_set($_POST, 'method');
     $theme_options = get_option(SH_NAME . '_theme_options');
     //printr($theme_options);
     $api = sh_set($theme_options, 'twitter_api');
     $api_secret = sh_set($theme_options, 'twitter_api_secret');
     $token = sh_set($theme_options, 'twitter_token');
     $token_secret = sh_set($theme_options, 'twitter_token_Secret');
     if (!$api && $api_secret) {
         _e('Please provide tiwtter api information to fetch feed', SH_NAME);
         exit;
     }
     $cb->setConsumerKey($api, $api_secret);
     $cb->setToken($token, $token_secret);
     $reply = (array) $cb->statuses_userTimeline(array('count' => sh_set($_POST, 'number'), 'screen_name' => sh_set($_POST, 'screen_name')));
     if (isset($reply['httpstatus'])) {
         unset($reply['httpstatus']);
     }
     foreach ($reply as $k => $v) {
         //if( $k == 'httpstatus' ) continue;
         //$time = human_time_diff( strtotime( sh_set( $v, 'created_at') ), current_time('timestamp') ) . __(' ago', SH_NAME);
         $text = preg_replace('@(https?://([-\\w\\.]+[-\\w])+(:\\d+)?(/([\\w/_\\.#-]*(\\?\\S+)?[^\\.\\s])?)?)@', '<a href="$1" target="_blank">$1</a>', sh_set($v, 'text'));
         echo '<li>' . $text . '</li>';
     }
 }
Пример #2
0
 function tweets()
 {
     if (!class_exists('Codebird')) {
         include_once 'codebird.php';
     }
     $cb = new Codebird();
     $method = sh_set($_GET, 'method');
     $theme_options = _WSH()->option();
     //printr($theme_options);
     $api = sh_set($theme_options, 'twitter_api');
     $api_secret = sh_set($theme_options, 'twitter_api_secret');
     $token = sh_set($theme_options, 'twitter_token');
     $token_secret = sh_set($theme_options, 'twitter_token_secret');
     if (!$api && $api_secret) {
         _e('Please provide tiwtter api information to fetch feed', SH_NAME);
         exit;
     }
     $cb->setConsumerKey($api, $api_secret);
     $cb->setToken($token, $token_secret);
     $resp = array();
     $reply = (array) $cb->statuses_userTimeline(array('count' => sh_set($_GET, 'number'), 'screen_name' => sh_set($_GET, 'screen_name')));
     if (isset($reply['httpstatus'])) {
         unset($reply['httpstatus']);
     }
     foreach ($reply as $k => $v) {
         //if( $k == 'httpstatus' ) continue;
         $time = human_time_diff(strtotime(sh_set($v, 'created_at')), current_time('timestamp')) . __(' ago', SH_NAME);
         $text = preg_replace('@(https?://([-\\w\\.]+[-\\w])+(:\\d+)?(/([\\w/_\\.#-]*(\\?\\S+)?[^\\.\\s])?)?)@', '<a href="$1" target="_blank">$1</a>', sh_set($v, 'text'));
         if (sh_set($_POST, 'template') === 'lead') {
             echo '<i class="fa fa-twitter"></i>' . $text . ' <a href="#"> ' . $time . '</a>';
         } else {
             $res[$k]['date'] = $time;
             //array('date'=>$time, 'tweet'=>$text);
             $res[$k]['tweet'] = $text;
             //echo
             //'<li><span></span><p>'.$text.' <a href="#">'.__(' about ', SH_NAME).$time.'</a></p></li>';
         }
     }
     //printr($res);
     echo json_encode($res);
 }