public static function go($obj) { $api = new CurlUtil($obj); return $api->getContent(); }
public function start() { if (is_null($this->folderName)) { if (isset($_GET['pageID'])) { $this->folderName = $_GET['pageID']; } } //--------------------------------------------------------- $folderName = Compile::$minifiedPath; //--------------------------------------------------------- $GET = array_merge($_GET, array()); //--------------------------------------------------------- unset($GET["pageID"]); //--------------------------------------------------------- //$GET["compile"]=0; //$GET['print_cookie'] = 1; unset($GET['refresh']); $_COOKIE['compile_curl'] = 1; //--------------------------------------------------------- $this->url .= "?" . http_build_query($GET); //--------------------------------------------------------- if (is_null($folderName) && FileFolder::getFileName($this->url) != "") { $folderName = explode("/", $this->url); end($folderName); $folderName = prev($folderName); } //--------------------------------------------------------- $this->fileCss = Compile::$minifiedPath . "global/css/" . $this->folderName . "/min.css"; $this->fileJs = Compile::$minifiedPath . "global/js/" . $this->folderName . "/min.js"; $this->fileTmpl = Compile::$minifiedPath . $this->folderName . "/min.php"; //--------------------------------------------------------- $this->fileCssAb = GenFun::get_full_url($this->fileCss); $this->fileJsAb = GenFun::get_full_url($this->fileJs); //--------------------------------------------------------- FileFolder::createFolderStructure($this->fileCss); //--------------------------------------------------------- FileFolder::folderCopy(Import::getImportPath(), Compile::$minifiedPath); FileFolder::folderCopy(Import::getImportPath(), Compile::$unminifiedPath); //--------------------------------------------------------- $this->content = CurlUtil::go(array("url" => $this->url)); //--------------------------------------------------------- preg_match_all('/Fatal error(.*?)<br \\/>/s', $this->content, $errors); //--------------------------------------------------------- if (sizeof($errors[0]) > 0) { krumo($errors[0]); die; } //--------------------------------------------------------- $this->content = $this->css_CFG(); $this->script_CFG(); $this->content = str_replace("<head>", '<head><script type="text/javascript" src="' . $this->fileJsAb . '"></script>' . PHP_EOL, $this->content); $this->content = str_replace("<head>", '<head><link rel="stylesheet" type="text/css" href="' . $this->fileCssAb . '"/>' . PHP_EOL, $this->content); $this->content = str_replace("<head>", '<head>' . PHP_EOL . file_get_contents($this->fileTmpl), $this->content); //--------------------------------------------------------- $this->project = str_replace("<head>", '<head>' . PHP_EOL . file_get_contents($this->fileTmpl), $this->project); //--------------------------------------------------------- FileFolder::delete($this->fileTmpl); //--------------------------------------------------------- $this->project = StringUtil::removeWhiteLines($this->project); //--------------------------------------------------------- file_put_contents(Import::getImportPath() . "project/index.php", $this->project); //--------------------------------------------------------- $this->content = StringUtil::removeWhiteLines($this->content); FileFolder::file_put_contents(Compile::$minifiedPath . "index.php", $this->content); //--------------------------------------------------------- return $this->content; }
public function parse_match_post() { //----------------------------------------------------- if (!empty($this->match[1]) || $this->match[1] != "") { $this->src_path_markup = $this->match[1]; $this->src_path = $this->match[2]; /*if (is_null($this->link_compile_file)) { krumo($this->save_path); $this->save_path_relative = Compiler::cleanURL($this->src_path, ""); $this->save_path = $this->compilePath.$this->save_path_relative; krumo($this->save_path); }*/ } //----------------------------------------------------- if (is_null($this->save_path)) { if (!is_null($this->content)) { if (!file_exists($this->src_path) && !CurlUtil::is_url_exist($this->src_path)) { $this->markup_CFG(); $this->inline = true; $this->save_path_relative = $this->savePath_CFG() . "inline_" . $this->index . "." . $this->saveas_ext; $this->save_path = $this->compilePath . $this->save_path_relative; } else { $path = is_null($this->save_dir) ? Compiler::cleanURL(FileFolder::getFileName($this->src_path, true, true)) : $this->save_dir . FileFolder::getFileName($this->src_path, true); $path = $this->removeModified($path); $this->save_path_relative = $path . "." . $this->saveas_ext; $this->save_path = $this->compilePath . $this->save_path_relative; //krumo(basename($this->save_path)); } } } //----------------------------------------------------- /*if (!is_null($this->replacePath) && !is_null($this->save_path)) { foreach ($this->replacePath as $key => $value) { $this->save_path_relative = str_replace($key, $value, $this->save_path_relative); $this->save_path = str_replace($key, $value, $this->save_path); } }*/ //----------------------------------------------------- /*if (!is_null($this->str_replace_silent)) { foreach ($this->str_replace_silent as $key => $value) { $txt = str_replace($key, $value, $txt); } }*/ //----------------------------------------------------- //if ($this->compileType == "seperate") { //} //----------------------------------------------------- if (!is_null($this->content)) { $prop = array("src_content" => $this->content, "compilerGlobal" => $this->compilerGlobal, "forceDownload" => $this->forceDownload, "src_content_type" => $this->codeType, "src_dir" => !is_null($this->src_path) ? dirname($this->src_path) . "/" : $this->src_path, "src_save_dir" => !is_null($this->save_path_relative) ? dirname($this->save_path_relative) . "/" : $this->save_path_relative, "compilePath" => $this->compilePath); //krumo($this->content); //--------------------------------------------- $this->images = new Compile_Images($prop); //--------------------------------------------- SetPublicProp::go($this->images, $this->imagesProp); //--------------------------------------------- SetPublicProp::go($this->images, $this->filesObj, false); //--------------------------------------------- $this->images->init(); $this->content_updated = $this->images->src_content_updated; if ($this->removeInline && !is_null($this->output_updated)) { $replaceWith = $this->onRemoveMatch_CHK("code"); $this->output_updated = str_replace($this->match[0], $replaceWith, $this->output_updated); } } //----------------------------------------------------- }
private function getTitle($url) { $output = CurlUtil::go(array("url" => $url)); preg_match_all("/<title>(.*?)<\\/title>/s", $output, $matches, PREG_SET_ORDER); return sizeof($matches) == 0 ? NULL : $matches[0][1]; }
public function start() { //--------------------------------------------------------- $GET = array_merge($_GET, array()); //--------------------------------------------------------- unset($GET["pageID"]); //--------------------------------------------------------- unset($GET['refresh']); //--------------------------------------------------------- $_COOKIE['compile_curl'] = 1; //--------------------------------------------------------- $this->url .= strpos($this->url, "?") === false ? "?" : "&"; $this->url .= http_build_query($GET); //--------------------------------------------------------- $this->output = CurlUtil::go(array("url" => $this->url)); //--------------------------------------------------------- $this->compile_id = Compiler::getCompile_id(); //--------------------------------------------------------- if ($this->useTitleAsId) { $this->title = $this->getTitle(); } if (!is_null($this->title)) { $this->compile_id = $this->title; } //--------------------------------------------------------- preg_match_all('/Fatal error(.*?)<br \\/>/s', $this->output, $errors); //--------------------------------------------------------- if (sizeof($errors[0]) > 0) { print_r($errors[0]); die; } //--------------------------------------------------------- foreach ($this->compile as $key => $value) { $value['compilerGlobal'] = $this->compilerGlobal; $value['output'] = $this->output; //$value['useTitleAsId'] = $this->useTitleAsId; $this->compilers[] = new Compile($value); } //--------------------------------------------------------- return $this->output; }
private function getAvatarImageUrl($size, $addScheme = false) { assert('is_int($size)'); if (isset($this->serializedAvatarData)) { $avatar = unserialize($this->serializedAvatarData); } // Begin Not Coding Standard $baseGravatarUrl = '//www.gravatar.com/avatar/%s?s=' . $size . '&r=g'; $gravatarUrlFormat = $baseGravatarUrl . '&d=identicon'; $gravatarDefaultUrlFormat = $baseGravatarUrl . '&d=mm'; // End Not Coding Standard if (isset($avatar['avatarType']) && $avatar['avatarType'] == static::AVATAR_TYPE_DEFAULT) { $avatarUrl = sprintf($gravatarDefaultUrlFormat, ''); } elseif (isset($avatar['avatarType']) && $avatar['avatarType'] == static::AVATAR_TYPE_PRIMARY_EMAIL) { $email = $this->primaryEmail->emailAddress; $emailHash = md5(strtolower(trim($email))); $avatarUrl = sprintf($gravatarUrlFormat, $emailHash); } elseif (isset($avatar['avatarType']) && $avatar['avatarType'] == static::AVATAR_TYPE_CUSTOM_EMAIL) { $email = $avatar['customAvatarEmailAddress']; $emailHash = md5(strtolower(trim($email))); $avatarUrl = sprintf($gravatarUrlFormat, $emailHash); } else { $avatarUrl = sprintf($gravatarDefaultUrlFormat, ''); } if (isset($this->avatarImageUrl)) { $this->avatarImageUrl = $avatarUrl; } else { if (CurlUtil::urlExists('http:' . $avatarUrl)) { $this->avatarImageUrl = $avatarUrl; } else { $this->avatarImageUrl = Yii::app()->theme->baseUrl . '/images/offline_user.png'; } } if ($addScheme) { return 'http:' . $this->avatarImageUrl; } return $this->avatarImageUrl; }
public function file_CHK() { //----------------------------------------------------- $content = NULL; $getContent = true; //----------------------------------------------------- if (preg_match('/\\.(jpg|jpeg|png|gif)(?:[\\?\\#].*)?$/i', $this->filePath)) { $this->fileType = "image"; } //----------------------------------------------------- $filePath = explode("?", $this->filePath); $filePath = $filePath[0]; //----------------------------------------------------- if (strpos($filePath, "../") !== false) { $this->filePath_local = FileFolder::getParDirFromSrc($filePath, $this->url_local . $this->src_dir); //--------------------------------------------- if (FileFolder::file_exists($this->filePath_local)) { $this->exist = true; $this->content = $this->getContent($this->filePath_local); } //--------------------------------------------- $result = StringUtil::replaceOverlap($this->url_local, $this->filePath_local, "", "/"); //--------------------------------------------- if ($this->relativeToSrc && $this->exist) { $this->save_path = $this->compilePath . str_replace($this->url_local, "", $this->filePath_local); //----------------------------------------- if ($result['overlap'] != $this->url_local) { krumo($result); krumo($this->filePath_local . " cannot be saved outside of " . $this->compilePath . " ,'relativeToSrc' will be set to 'false'"); //----------------------------------------- $this->relativeToSrc = false; } } //--------------------------------------------- $filePath = str_replace($result["overlap"], "", $this->filePath_local); } else { if (strpos($filePath, "http://") !== false || strpos($filePath, "https://") !== false) { if (FileFolder::file_exists($filePath_local = GenFun::get_local_url($filePath))) { $this->filePath_local = $filePath_local; $this->content = $this->getContent($this->filePath_local); $this->filePath_local_relative = Compiler::cleanURL($this->filePath_local, ""); $filePath = !is_null($this->save_dir) ? basename($this->filePath_local_relative) : $this->filePath_local_relative; $this->exist = true; } else { if (CurlUtil::is_url_exist($this->filePath)) { $this->exist = true; if ($this->forceDownload) { $filePath = (!is_null($this->save_dir) ? "" : "global/forced/") . basename($filePath); $this->content = $this->getContent($this->filePath); $this->forced = true; } else { $this->link = Html::getExtLink($this->filePath); } } } } else { if (!is_null($this->src_save_dir) && $this->src_content_type == "css") { if (FileFolder::file_exists($this->filePath_local = (!is_null($this->src_dir) ? GenFun::get_local_url($this->src_dir) : $this->url_local) . $filePath)) { $this->exist = true; } $this->content = $this->getContent($this->filePath_local); if ($this->relativeToSrc) { $filePath = $this->src_save_dir . $filePath; } $this->save_path = $this->compilePath . $filePath; } else { if (FileFolder::file_exists($this->filePath_local = $this->url_local . $filePath)) { $this->content = $this->getContent($this->filePath_local); $filePath = $this->filePath; $this->exist = true; } } } } //------------------------------------------------- if (!$this->base64 || $this->fileType != "image") { if ($this->relativeToSrc && $this->src_content_type == "css") { $this->save_path_relative = $filePath; } else { if (!is_null($this->filePath_local)) { //--------------------------------------------- $this->save_path_relative = $this->get_savePath($filePath); $this->save_path = $this->compilePath . $this->save_path_relative; } else { //$this->save_path = $filePath; } } //------------------------------------------------- if ($this->relativeToSrc && !is_null($this->src_save_dir)) { $this->save_path_relative = StringUtil::pathRelativeToPath($this->save_path, $this->compilePath . $this->src_save_dir, "/", true); } } else { if ($this->fileType == "image") { $info = getimagesize($this->filePath_local); if ($info['mime'] == "image/png") { $this->base64_content = Image::compress_png($this->filePath_local, $this->quality, true); } else { if ($info['mime'] == "image/jpeg") { $this->base64_content = Image::compress_jpeg($this->filePath_local, $this->quality, true); } else { $this->base64_content = GenFun::fileToBase64($this->filePath_local, $info['mime']); } } } } //------------------------------------------------- if ($this->exist) { $this->src_content_updated = str_replace($this->filePath, !is_null($this->base64_content) ? $this->base64_content : $this->save_path_relative, $this->src_content); } else { $this->existCaseInsensitive = FileFolder::file_exists($this->filePath_local, false); array_push($this->compilerGlobal->notifications, array("existCaseInsensitive" => $this->existCaseInsensitive, "file" => $this->filePath)); } }
/** * Perform request and populate data from response * * @throws ChurnBeeException */ public function flush() { if ($this->cbconf->isAsync() == false) { foreach ($this->queue as $k => $r) { $r['url'] = $this->appendTo($r['url'], "accessToken", $this->cbconf->getAccessToken()); $curl = new CurlUtil($r['method'], $r['url']); $curl->setTimeOut($this->cbconf->getCurlTimeout()); $curl->send(); $this->splitHeaderAndResponse($k, $curl->getResult()); $this->sentHeaders[$k] = $curl->getSentHeaders(); $this->statusCode[$k] = $curl->getStatusCode(); $this->addError($k, $curl->getError()); } $this->handleErrors(); $this->debug(); $this->clearQueue(); } else { foreach ($this->queue as $k => $r) { $r['url'] = $this->appendTo($r['url'], "accessToken", $this->cbconf->getAccessToken()); $this->flushAsync($k, $r['method'], $r['url']); } } }
/** * 查询某一班级的人数 * @param string $college_code 学院代码 * @param string $class_code 班级代码 * @return number 班级的人数 */ function classMember($college_code, $class_code, array &$not_exit_student_arr = null) { $url = "http://dean.swjtu.edu.cn/public/QueryStudentInfo.jsp"; $post_field = "query_action=query&query_type=class_code_all&check_type=name&student_id=&college_code={$college_code}&class_code={$class_code}"; $curl = new CurlUtil(); $html = $curl->post($url, $post_field); //返回的是一个html,需要正则匹配 // echo $html; $pattern = '/<td height="28" align="center" bgcolor="#FFFFFF">(.*?)<\\/td>/si'; preg_match_all($pattern, $html, $matches); if (empty($matches)) { return 0; } //处理无学籍情况 $matchescount = count($matches[1]); $not_exit_student_arr = array(); $count = 0; for ($i = 0; $i < $matchescount; $i++) { $row = $matches[1][$i]; if (stripos($row, "无学籍") !== false) { //无学籍 $student = new Student($matches[1][$i - 6], $matches[1][$i - 5], $matches[1][$i - 3], $matches[1][$i - 2], $matches[1][$i - 1], false); $not_exit_student_arr[$count] = $student; $count = $count + 1; } } return count($matches[0]) / 7; }
public static function getGeoIP() { return json_decode(CurlUtil::go(array("url" => "http://freegeoip.net/json/github.com/" . GenFun::getUserIP())), true); }
/** * Updates a language */ public function updateLanguage($languageCode) { try { $language = ActiveLanguage::getByCode($languageCode); } catch (NotFoundException $e) { throw new NotFoundException(Zurmo::t('ZurmoModule', 'Language not active.')); } $translationUrl = ZurmoTranslationServerUtil::getPoFileUrl($language->code); // Check if the po file exists if (!CurlUtil::urlExists($translationUrl)) { throw new NotFoundException(Zurmo::t('ZurmoModule', 'Translation not available.')); } if (ZurmoMessageSourceUtil::importPoFile($language->code, $translationUrl)) { $language->lastUpdateDatetime = DateTimeUtil::convertTimestampToDbFormatDateTime(time()); if ($language->save()) { return true; } } throw new FailedServiceException(Zurmo::t('ZurmoModule', 'Unexpected error. Please try again later.')); }