/** * 从新浪获取头像,然后生成指定的3种尺寸图像供后续指定的$uid使用。(保护方法) * 该方法是该类进行主要操作时第一个必须要运行的方法,否则将因为无法初始化对应参数而出错。 * * @param integer $uid DZ uid * @return integer 成功则返回0,否则返回错误代码: * -1:初始化失败(无法获取新浪用户信息) * -2:传uid参数错误(小于1) * -3:无法获取服务器上的头像 * -4:服务器返回错误数据(非头像数据或者给出来的头像太小);或者临时目录权限问题导致无大头像文件 * -5:GD库没有加载,无法进行头像同步操作 */ function _getFaceAndCreateTemp($uid) { if (!extension_loaded('gd')) { return -5; } if (empty($this->sina_userinfo) || !isset($this->sina_userinfo['id'])) { return -1; } $this->uid = (int) $uid; if ($this->uid < 1) { return -2; } //获取大头像 $faceurl = str_replace($this->sina_userinfo['id'] . '/50/', $this->sina_userinfo['id'] . '/180/', $this->sina_userinfo['profile_image_url']); $body = $this->http->Get($faceurl); if ($this->http->getState() !== 200 || empty($body)) { return -3; } //写入临时目录 $this->faceTempPath[1] = XWB_P_DATA . '/temp/' . $this->uid . '_1_xwb_face_temp.jpg'; file_put_contents($this->faceTempPath[1], $body, LOCK_EX); //大头像安全性和有效性检查(服务器给出来的头像太小,也丢弃处理) $imageSize = getimagesize($this->faceTempPath[1]); if (false === $imageSize || $imageSize[0] < 30 || $imageSize[1] < 30) { $this->_delTempFace(); return -4; } //创建中小头像 foreach ($this->faceSize as $key => $size) { //大头像无需处理 if (1 === $key) { continue; } $imgProc = XWB_plugin::N('images'); $imgProc->loadFile($this->faceTempPath[1]); //载入大头像 //$imgProc->crop(0,0,180,180); $imgProc->resize($size['w'], $size['h']); $this->faceTempPath[$key] = XWB_P_DATA . '/temp/' . $this->uid . '_' . $key . '_xwb_face_temp.jpg'; $imgProc->save($this->faceTempPath[$key]); $imgProc = null; //释放资源,让其自动调用__destruct } return 0; }
function proverb_fsockopen($url, $referer = '') { $content = @file_get_contents($url); if (empty($content)) { include_once ROOT_PATH . '/inc/http/fsockopenHttp.class.php'; $f = new fsockopenHttp(); $f->setHeader('Referer', $referer); $content = $f->Get($url); } if (empty($content)) { include_once ROOT_PATH . '/inc/http/curlHttp.class.php'; $f = new curlHttp(); $f->_option[CURLOPT_REFERER] = $referer; $content = $f->Get($url); } return $content; }
/** * 统计上报(通过服务器进行上报) * @param string $type stat类型 * @param array $args stat参数 * @return bool */ function statReport($type, $args = array()) { if (defined('XWB_P_STAT_DISABLE')) { return false; } $statUrl = XWB_plugin::statUrl($type, $args); if ('' == $statUrl) { return false; } if (!class_exists('fsockopenHttp')) { require_once "fsockopenHttp.class.php"; } $httpObj = new fsockopenHttp(); $httpObj->setUrl($statUrl); $httpObj->max_retries = 0; $httpObj->request(); return true; }