3 if(!isset($_SESSION)){
\r
6 include_once('mobile_device_detect.php');
\r
7 mobile_device_detect(true,true,true,true,true,true,'https://t.orzdream.com/',false);
\r
8 include_once('config.php');
\r
9 include_once('utility.php');
\r
10 include_once('twitteroauth.php');
\r
11 include_once('oauth_lib.php');
\r
13 function refreshProfile(){
\r
15 $user = $t->veverify();
\r
16 $time = $_SERVER['REQUEST_TIME']+3600*24*365;
\r
17 setcookie('friends_count', $user->friends_count, $time, '/');
\r
18 setcookie('statuses_count', $user->statuses_count, $time, '/');
\r
19 setcookie('followers_count', $user->followers_count, $time, '/');
\r
20 setcookie('imgurl', getAvatar($user->profile_image_url), $time, '/');
\r
21 setcookie('name', $user->screen_name, $time, '/');
\r
22 setcookie('listed_count', GetListed($t), $time, '/');
\r
25 function getDefCookie($name, $default="") {
\r
26 if (getCookie($name)) return getCookie($name);
\r
27 else return $default;
\r
29 function format_time($time){
\r
30 date_default_timezone_set('UTC');
\r
31 return strtotime($time);
\r
33 function formatText($text) {
\r
34 //如果开启了魔术引号\" \' 转回来
\r
35 if (get_magic_quotes_gpc()) {
\r
36 $text = stripslashes($text);
\r
40 $urlReg = '/(((http|https|ftp):\/\/){1}([[:alnum:]\-\.])+(\.)(([[:alnum:]]){2,4})?([[:alnum:]\/+=%#&@\:\;_\.~\?\!\-\,]*))/i';
\r
41 $text = preg_replace($urlReg, '<a href="\1" target="_blank" rel="noreferrer">\1</a>', $text);
\r
44 $atReg = '/\B@{1}(([a-zA-Z0-9\_\.\-])+)/i';
\r
45 $text = preg_replace($atReg, '<a href="user.php?id=\1" target="_blank">\0</a>', $text);
\r
48 $listReg = '/(\<a[\w+=\:\%\#\&\.~\?\"\'\/\- ]+\>@{1}([a-zA-Z0-9_\.\-]+)<\/a\>([\/a-zA-Z0-9_\.\-]+))/i';
\r
49 $text = preg_replace($listReg, '<a href="list.php?id=\2\3" target="_blank">@\2\3</a>', $text);
\r
52 $tagReg = "/\B(\#{1}([\w]*[\pN\pC\pL]+[\w]*))([\s]*)/u";
\r
53 $text = preg_replace($tagReg, '<a target="_blank" href="search.php?q=%23\2">#<span class="hashtag">\2</span></a>\3', $text);
\r
55 $text = formatTweetID($text);
\r
60 function formatEntities(&$entities,$html){
\r
61 $user_mentions = $entities->user_mentions;
\r
62 $hashtags = $entities->hashtags;
\r
63 $urls = $entities->urls;
\r
64 if(count($user_mentions) > 0) {
\r
65 foreach($user_mentions as $user_mention) {
\r
66 $name = $user_mention->screen_name;
\r
67 $html = str_replace("@$name","<a href=\"user.php?id=$name\" target=\"_blank\">@$name</a>",$html);
\r
70 if(count($hashtags) > 0) {
\r
71 foreach($hashtags as $hashtag) {
\r
72 $text = $hashtag->text;
\r
73 $html = str_replace("#$text","<a target=\"_blank\" href=\"search.php?q=%23$text\">#<span class=\"hashtag\">$text</span></a>",$html);
\r
76 if(count($urls) > 0) {
\r
77 $scheme = (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != "on") ? 'http' : 'https';
\r
78 foreach($urls as $url) {
\r
79 $exp = is_null($url->expanded_url) ? $url->url : $url->expanded_url;
\r
80 if(substr($url->url,0,4) != 'http') $url->url = 'http://'.$url->url;
\r
81 if(isset($url->display_url)) {
\r
82 $dis = $url->display_url;
\r
84 $tmp = explode('://', $url->url);
\r
87 $html = str_replace($url->url,"<a href=\"$exp\" target=\"_blank\" rel=\"noreferrer\" class=\"tweet_url\">$dis</a>",$html);
\r
90 if(isset($entities->media)) {
\r
91 $medias = $entities->media;
\r
92 foreach($medias as $media) {
\r
93 $url = $media->media_url_https;
\r
94 if (getcookie('p_avatar') == 'true') {
\r
95 $url = 'img.php?imgurl='.$url;
\r
97 $html = str_replace($media->url,"<a href=\"$url\" target=\"_blank\" rel=\"noreferrer\">$media->display_url</a>",$html);
\r
103 function formatTweetID($text){
\r
104 $reg = '/(\<a[\w+=@\:\%\#\&\.~\?\"\'\/\-\! ]+\>[\S]+<\/a\>)/i';
\r
105 preg_match_all($reg, $text, $tmpMatches);
\r
106 if(count($tmpMatches) > 0){
\r
107 $text = preg_replace($reg, '$_holder_$', $text);
\r
109 preg_match_all('/([\d]{10,})/', $text, $matches);
\r
110 if(count($matches) > 0){
\r
111 $matches = array_unique($matches[0]);
\r
112 foreach($matches as $match){
\r
113 $text = str_replace($match, '<a title="We think it\'s a tweet ID, isn\'t it?" href="status.php?id='.$match.'" target="_blank">'.$match.'</a>', $text);
\r
115 $tmpReg = '/\$_holder_\$/i';
\r
116 foreach($tmpMatches[0] as $match){
\r
117 $text = preg_replace($tmpReg, $match, $text, 1);
\r
123 function processCurl($url,$postdata=false,$header=false)
\r
125 $ch = curl_init($url);
\r
127 curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
\r
128 curl_setopt($ch, CURLOPT_VERBOSE, 1);
\r
129 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
\r
130 curl_setopt($ch, CURLOPT_TIMEOUT,120);
\r
132 if($postdata !== false) {
\r
133 curl_setopt ($ch, CURLOPT_POST, true);
\r
134 curl_setopt ($ch, CURLOPT_POSTFIELDS, $postdata);
\r
137 if($header !== false) {
\r
138 curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
\r
141 $response = curl_exec($ch);
\r
142 $responseInfo=curl_getinfo($ch);
\r
144 if( intval( $responseInfo['http_code'] ) == 200 )
\r
150 function objectifyXml( $data ){
\r
152 if( function_exists('simplexml_load_string') ) {
\r
153 $obj = simplexml_load_string( $data );
\r
155 if (isset($obj->error) || !$obj) return false;
\r
161 function objectifyJson($data){
\r
162 if(function_exists("json_decode")){
\r
163 $obj = json_decode($data);
\r
165 if(!isset($obj->error) || $obj){
\r
172 function imageUpload($image){
\r
174 $signingurl = 'https://api.twitter.com/1/account/verify_credentials.json';
\r
175 $request = OAuthRequest::from_consumer_and_token($t->consumer, $t->token, 'GET', $signingurl, array());
\r
176 $request->sign_request($t->sha1_method, $t->consumer, $t->token);
\r
177 $r_header = $request->to_header("http://api.twitter.com/");
\r
179 $url = 'http://img.ly/api/2/upload.json';
\r
180 $postdata = array('media' => $image);
\r
181 $ch = curl_init($url);
\r
182 if($postdata !== false)
\r
184 curl_setopt ($ch, CURLOPT_POST, true);
\r
185 curl_setopt ($ch, CURLOPT_POSTFIELDS, $postdata);
\r
187 curl_setopt($ch, CURLOPT_HTTPHEADER, array('X-Auth-Service-Provider: '.$signingurl,'X-Verify-Credentials-'.$r_header));
\r
188 curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
\r
189 curl_setopt($ch, CURLOPT_USERAGENT, 'embr');
\r
190 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
\r
191 curl_setopt($ch, CURLOPT_TIMEOUT,120);
\r
192 curl_setopt($ch, CURLOPT_CONNECTTIMEOUT,5);
\r
194 $response = curl_exec($ch);
\r
195 $response_info=curl_getinfo($ch);
\r
198 if ($response_info['http_code'] == 200) {
\r
199 return objectifyJson($response);
\r
205 function getTwitter() {
\r
207 $access_token = $_SESSION['access_token'] ? $_SESSION['access_token'] : null;
\r
208 $oauth_token = $access_token ? $access_token['oauth_token'] : $_COOKIE['oauth_token'];
\r
209 $oauth_token_secret = $access_token ? $access_token['oauth_token_secret'] : $_COOKIE['oauth_token_secret'];
\r
210 $oauth = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, $access_token['oauth_token'], $access_token['oauth_token_secret']);
\r
216 function loginStatus() {
\r
217 if(isset($_SESSION['login_status'])){
\r
218 return $_SESSION['login_status'] == 'verified' ? true : false;
\r
219 }elseif(getEncryptCookie("oauth_token") != "" && getEncryptCookie("oauth_token_secret") != "" && getEncryptCookie("user_id") != "" && getEncryptCookie("twitese_name") != ""){
\r
220 $access_token = array("oauth_token" => getEncryptCookie("oauth_token"), "oauth_token_secret" => getEncryptCookie("oauth_token_secret"), "user_id" => getEncryptCookie("user_id"), "screen_name" => getEncryptCookie("twitese_name"));
\r
221 $_SESSION['access_token'] = $access_token;
\r
222 $_SESSION['login_status'] = 'verified';
\r
229 function GetListed($t, $cursor = false){
\r
230 $lists = $t->beAddedLists($t->username, $cursor);
\r
231 $listed = count($lists->lists);
\r
232 if($lists->next_cursor > 1){
\r
233 $listed += GetListed($t, $lists->next_cursor);
\r
238 function getAvatar($profileImg){
\r
239 if (getcookie('p_avatar') == 'true') {
\r
240 return 'img.php?imgurl='.$profileImg;
\r
242 return preg_replace('/https?:\/\/\w+([0-9])\.twimg\.com/i','https://s3.amazonaws.com/twitter_production',$profileImg);
\r
245 // $target: can't be current user
\r
246 // $source: use the current user as the source user implicitly if not specified
\r
247 // 9 => no relationship
\r
248 // 1 => fo each other
\r
249 // 2 => $source fo $target
\r
250 // 3 => $target fo $source
\r
251 // 4 => $source blocking $target
\r
252 function getRelationship($target, $source = false){
\r
253 $relationship = getTwitter()->relationship($target, $source)->relationship;
\r
254 $target = $relationship->target;
\r
255 $source = $relationship->source;
\r
256 if($source->blocking == 1){
\r
259 if($source->following == 1 && $target->following == 1){
\r
262 if($source->following == 1 && $target->following != 1){
\r
265 if($source->following != 1 && $target->following == 1){
\r
271 function urlshorten($url, $type='goo.gl'){
\r
274 $data = json_encode(array('longUrl' => $url));
\r
275 $api = 'https://www.googleapis.com/urlshortener/v1/url?key=AIzaSyDsX2BAo9Jc2yG3Pq1VbLQALqdrtDFvXkg';
\r
276 $header = array('Content-type: application/json');
\r
277 $result = objectifyJson(processCurl($api,$data,$header))->id;
\r
280 $api = 'http://zi.mu/api.php?format=simple&action=shorturl&url=';
\r
281 $result = objectifyJson(processCurl($api.rawurlencode($url)));
\r