/** * 发悄悄话或群聊天 * im/message/:type/:to_id\d */ public function message_post() { $this->check_token(); $to_id = I('get.to_id', null, 'intval'); if (!$to_id) { $this->error(1001); } $type = I('get.type', 'single'); $message_info = $this->get_request_data(); $message = D('Imessage'); $created = $message->create($message_info); if (!$created) { $this->error(1500); } if ($type == 'single') { $message->is_to_group = 0; } elseif ($type == 'group') { $message->is_to_group = 1; } $message->from_member_id = $this->uid; $message->to_id = $to_id; $success = $message->add(); if (!$success) { $this->error(1500); } $new_msg = array('id' => $message->getLastInsID(), 'content' => $message_info['content'], 'mime_type' => $message_info['mime_type'], 'filename' => $message_info['filename'], 'type' => 1, 'is_to_group' => $type = 'single' ? 0 : 1, 'from_member_id' => $this->uid, 'to_id' => $to_id, 'is_read' => 0, 'add_time' => date('Y-m-d H:i:s')); $from_member = M('member')->field('id, nickname, avatar')->find($this->uid); $from_member['avatar'] = GetSmallAvatar($this->uid); $new_msg['from_member'] = $from_member; $to_im_server = I('get.tis', '1', 'intval'); if ($to_im_server) { @urlopen('http://localhost:5000/send_message', json_encode($new_msg)); } $this->success($new_msg); }
function wp_check_version() { global $dsq_version; $response = @urlopen(DISQUS_MEDIA_URL . '/wp/LATEST_VERSION'); $latest_version = floatval($response['data']); if ($dsq_version < $latest_version) { return $latest_version; } return false; }
function urlopen($site, $resource, &$status) { # Connect to the server $fp = fsockopen($site, 80, $errno, $errstr, 15.0); $fp || die("Error #{$errno}: {$errstr}"); # Construct the request $request = "GET {$resource} HTTP/1.1\r\n"; $request .= "Host: {$site}\r\n"; $request .= "Connection: Close\r\n"; $request .= "Referrer: http://www.shift2bikes.org/cal/vfyaddress.php\r\n"; $request .= "User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)\r\n"; $request .= "\r\n"; # Send the request fwrite($fp, $request); # Read the response header $status = ""; $buffer = fgets($fp); if (substr($buffer, -2) == "\r\n") { $buffer = substr($buffer, 0, strlen($buffer) - 2); } while (!feof($fp) && $buffer != "") { if (preg_match("/^HTTP\\/1\\.. /", $buffer)) { $status = substr($buffer, 9, 3); } else { if (preg_match("/^Location: /i", $buffer) && $status == "302") { fclose($fp); $resource = substr($buffer, 10); return urlopen($site, $resource, $status); } } $buffer = fgets($fp); if (substr($buffer, -2) == "\r\n") { $buffer = substr($buffer, 0, strlen($buffer) - 2); } } # return the file descriptor return $fp; }
function shorten_bitly($url, $bitly_key, $bitly_login) { if ($bitly_key && $bitly_login && function_exists('json_decode')) { $bitly_params = '?login='******'&apiKey=' . $bitly_key . '&longUrl=' . urlencode($url); $bitly_response = urlopen('http://api.j.mp/v3/shorten' . $bitly_params); if ($bitly_response) { $bitly_data = json_decode($bitly_response, true); if (isset($bitly_data['data']['url'])) { $bitly_url = $bitly_data['data']['url']; } } } return $bitly_url; }
// set to 1 for short URLs on your own domain. 0 to turn this off $settings = json_encode($headers); print $settings; exit; } // Do not edit below this line // function immediate_redirect($url) { header("Location: {$url}"); header("Content-Length: 0"); header("Connection: close"); flush(); } if (isset($_GET['check_install'])) { supr_check_install(); } if (isset($_GET['supr'])) { $hash = $_GET['supr']; } else { immediate_redirect($domain); } $url = "http://su.pr/api/forward?domain=" . urlencode($domain) . "&hash=" . $hash . "&login="******"&apiKey=" . $apikey; $response = @urlopen($url); $data = $response['data']; $results = json_decode($data, true); if (isset($results['results'][$hash]['forwardUrl'])) { $redir = $results['results'][$hash]['forwardUrl']; } else { $redir = $domain; } immediate_redirect($redir);