protected function _getPagination($top = 10, $verbs = "all") { $pg = new Pagination(); $pg->Skip = UrlUtils::GetRequestParamOrDefault("skip", 0, $verbs); $pg->Top = UrlUtils::GetRequestParamOrDefault("top", $top, $verbs); return $pg; }
public static function getVersions() { $response = array(); if (UrlUtils::checkRemoteFile('http://www.technicpack.net/api/minecraft', 15)['success']) { $response = UrlUtils::get_url_contents('http://www.technicpack.net/api/minecraft', 15); if ($response['success']) { $response = json_decode($response['data'], true); krsort($response); Cache::put('minecraftversions', $response, 180); return $response; } } if (UrlUtils::checkRemoteFile('https://s3.amazonaws.com/Minecraft.Download/versions/versions.json', 15)['success']) { $response = UrlUtils::get_url_contents('https://s3.amazonaws.com/Minecraft.Download/versions/versions.json', 15); if ($response['success']) { $mojangResponse = json_decode($response['data'], true); $versions = array(); foreach ($mojangResponse['versions'] as $versionEntry) { if ($versionEntry['type'] != 'release') { continue; } $mcVersion = $versionEntry['id']; $versions[$mcVersion] = array('version' => $mcVersion); } krsort($versions); Cache::put('minecraftversions', $versions, 180); return $versions; } } return $response; }
function _login() { $doLogin = UrlUtils::GetRequestParamOrDefault("DoLogin", "false", "all"); if ("false" == $doLogin) { session_unset(); session_destroy(); return; } $uid = UrlUtils::GetRequestParam("UserId", "post"); $pwd = md5(UrlUtils::GetRequestParam("Password", "post")); $udb = new UserDb(); $user = null; $ar = $udb->GetAllRows(); foreach ($ar as $row) { if ($row->Enabled && strtolower($uid) == strtolower($row->Email) || $uid == $row->UserId) { if ($pwd == $row->Md5Password) { $user = $row; break; } } } //echo "Loggedin ".$doLogin; if ($user == null) { session_unset(); session_destroy(); return; } $this->IsLoggedIn = true; $this->UserId = $row->UserId; $this->Admin = $row->Admin; $this->Packages = $row->Packages; $_SESSION["UserId"] = $this->UserId; $_SESSION["Admin"] = $this->Admin; $_SESSION["Packages"] = $this->Packages; }
private static function execRequest($httpMethod, $url, $parameters, $authHandlers, $contentType, $encodeJson) { // first, collect the headers and parameters we'll need from the authentication handlers list($headers, $authParameters) = HttpUtils::handleAuthentication($authHandlers); if (is_array($parameters)) { $parameters = array_merge($parameters, $authParameters); } // prepare the request $ch = curl_init(); if ($httpMethod == HttpMethod::GET) { $url = UrlUtils::buildUrlWithQueryString($url, $parameters); } else { $data = HttpUtils::buildDataForContentType($contentType, $parameters, $headers); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $httpMethod); curl_setopt($ch, CURLOPT_POSTFIELDS, $data); } curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); curl_setopt($ch, CURLINFO_HEADER_OUT, true); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); $response = curl_exec($ch); if (curl_error($ch)) { throw new MashapeClientException(EXCEPTION_CURL . ":" . curl_error($ch), EXCEPTION_CURL_CODE); } $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); $responseHeaders = curl_getinfo($ch, CURLINFO_HEADER_OUT); curl_close($ch); return new MashapeResponse($response, $httpCode, $responseHeaders, $encodeJson); }
/** * fetches all embeded images * * @param string $url * @return array */ public static function fetch($url, $limit = 5, $flat = true) { //get the html as string $html = UrlUtils::getUrlContent(urldecode($url), 'GET'); $images = self::detect($html); $result = array(); foreach ($images as $image) { $image = UrlUtils::abslink($image, $url); $size = @getimagesize($image); $size = $size[0] + $size[1]; // ignore all (stats)images smaller than 5x5 if ($size >= 10) { $result[] = array('size' => $size, 'image' => $image); } } usort($result, array("ImageParser", "sort")); //$result = array_unique($result); $result = array_slice($result, 0, $limit - 1); // return only the images and crop the size if ($flat) { $flat = array(); foreach ($result as $image) { $flat[] = $image['image']; } $result = $flat; } return $result; }
public static function IsUploadRequest() { if ("post" != UrlUtils::RequestMethod()) { return false; } return sizeof($_FILES) > 0; }
/** * Imports all likes from a facebook account to store it in the mongodb * * @param int $online_identity */ public static function importInterests($online_identity) { $token = AuthTokenTable::getByUserAndOnlineIdentity($online_identity->getUserId(), $online_identity->getId()); if (!$token) { $online_identity->deactivate(); throw new Exception('damn theres no token!', '666'); } // get likes $response = UrlUtils::sendGetRequest("https://graph.facebook.com/me/likes?access_token=" . $token->getTokenKey()); // mongo manager $dm = MongoManager::getDM(); // check likes if ($response && ($objects = json_decode($response, true))) { if (!isset($objects['data'])) { return false; } // iterate and save in mongodb foreach ($objects["data"] as $object) { $interest = $dm->getRepository('Documents\\Interest')->upsert($object); // check interest if ($interest) { $user_interest = $dm->getRepository('Documents\\UserInterest')->upsert($online_identity, $interest); } } } return; }
/** * Need to override this method for facebook, since they use oauth2 * */ protected function send($pPostBody) { $this->onlineIdentity->scheduleImportJob(); Queue\Queue::getInstance()->put(new Documents\InterestImportJob($this->onlineIdentity->getId())); $lToken = $this->getAuthToken(); $pPostBody .= "&access_token=" . $lToken->getTokenKey(); return UrlUtils::sendPostRequest(sfConfig::get("app_" . $this->classToIdentifier() . "_post_api"), $pPostBody); }
/** * Need to override this method for flattr, since they use oauth2 */ protected function send($pPostBody) { $lToken = $this->getAuthToken(); if ($pPostBody) { return UrlUtils::sendPostRequest(sfConfig::get("app_" . $this->classToIdentifier() . "_post_api"), $pPostBody, array("Authorization: Bearer " . $lToken->getTokenKey(), "Content-type: application/json")); } return null; }
public function ReadList() { $ndb = new NuGetDb(); $queryString = UrlUtils::GetRequestParam("searchQuery", "post"); if ($queryString == null) { return $ndb->GetAllRows(Settings::$ResultsPerPage); } return array(); }
public function testGetRemoteMD5Non200() { $json = UrlUtils::get_remote_md5("http://speedtest.wdc01.softlayer.com/downloads/testbob.zip", 5); $this->assertTrue(is_array($json)); $this->assertTrue(array_key_exists('success', $json)); $this->assertFalse($json['success']); $this->assertTrue(array_key_exists('message', $json)); $this->assertTrue(array_key_exists('info', $json)); $this->assertEquals('404', $json['info']['http_code']); }
public function getMinecraft() { if (Config::has('solder.minecraft_api')) { $url = Config::get('solder.minecraft_api'); } else { $url = self::MINECRAFT_API; } $response = UrlUtils::get_url_contents($url); return json_decode($response); }
/** * returns shares on facebook * * @param string $url * @return string */ function facebook_count($url) { $facebook_data = UrlUtils::getUrlContent("http://graph.facebook.com/?ids=" . urlencode($url)); if ($facebook_data = json_decode($facebook_data, true)) { if (array_key_exists($url, $facebook_data) && array_key_exists('shares', $facebook_data[$url])) { return intval($facebook_data[$url]['shares']); } } return intval(0); }
private function getMicroidsFromDomain() { $url = $this->getDomain(); $protocol = $this->getProtocol(); if (UrlUtils::checkUrlWithCurl($url, true)) { return MicroID::parseString(UrlUtils::getUrlContent($url)); } else { return null; } }
/** * Enter description here... * * @param string $url */ public static function requestCoupon($url) { $json = UrlUtils::sendGetRequest($url); // check json if ($coupon = json_decode($json, true)) { // check coupon-code if (array_key_exists("coupon", $coupon) && array_key_exists("code", $coupon["coupon"])) { return $coupon["coupon"]["code"]; } } return null; }
/** * Добавление урлов на страницы с данными в список */ function addPageUrls($urls) { if (sizeof($urls) <= 0) { return; } foreach ($urls as $url) { $url = UrlUtils::getRealUrl(UrlUtils::basePath($this->url), $url); if ($this->isNewUrl($url)) { $this->pagesUrls[] = $url; } } }
/** * returns the klout rank of a user * * @return string */ public function getKloutRank() { if ($this->getCommunity()->getName() == "twitter") { $profile = str_replace("http://twitter.com/", "", $this->getProfileUri()); $result = UrlUtils::sendGetRequest("http://api.klout.com/1/klout.json?key=n7mb4vu5ka7um88remypp2bw&users=" . $profile); if ($kloutobj = json_decode($result, true)) { if (array_key_exists("status", $kloutobj) && $kloutobj["status"] == 200 && array_key_exists("users", $kloutobj)) { return $kloutobj["users"][0]["kscore"]; } } } return "NaN"; }
/** * Parse a given html for meta and title-tags * * @param string $pUrl * @return array $lValues */ public static function parse($pHtml, $pUrl) { if (!preg_match("~<meta.*http-equiv\\s*=\\s*(\"|\\')\\s*Content-Type\\s*(\"|\\').*\\/?>~", $pHtml)) { $pHtml = preg_replace('/<head[^>]*>/i', '<head> <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=utf-8"> ', $pHtml); } try { $lValues = array(); //supress html-validation-warnings libxml_use_internal_errors(true); $lDoc = new DOMDocument(); $lDoc->loadHTML($pHtml); //get all meta-elements $lTags = $lDoc->getElementsByTagName('meta'); //loop the metas foreach ($lTags as $lTag) { //if attribute name isset make a new entry in an array with key=name and value=content if ($lTag->hasAttribute('name')) { $lName = strtolower($lTag->getAttribute('name')); $lValues['meta'][$lName] = $lTag->getAttribute('content'); } } //get all title elements $lTitles = $lDoc->getElementsByTagName('title'); //loop the titles foreach ($lTitles as $lMetaTitle) { $lTitle = $lMetaTitle->nodeValue; //and save the value to an array with key=title. if a title is found, break the loop and continue if ($lTitle) { $lValues['title'] = $lTitle; continue; } } //get all meta-elements $lLinks = $lDoc->getElementsByTagName('link'); //loop the metas foreach ($lLinks as $lLink) { //if attribute name isset make a new entry in an array with key=name and value=content if ($lLink->hasAttribute('rel')) { $lName = $lLink->getAttribute('rel'); $lValues['links'][$lName] = UrlUtils::abslink($lLink->getAttribute('href'), $pUrl); } } return $lValues; } catch (Exception $e) { continue; } }
/** * Executes index action * * @param sfRequest $request A request object */ public function executeIndex(sfWebRequest $request) { $lUrl = $request->getParameter("url", null); $lUrl = UrlUtils::narmalizeUrlScheme($lUrl); $request->setParameter("url", $lUrl); $this->url = $lUrl; $this->error = $this->pError = null; if (!$lUrl) { return $this->setTemplate("share"); } if ($request->getMethod() == "POST") { $lParams = $request->getParameter('like'); $lParams['u_id'] = $this->getUser()->getUserId(); $lActivity = new Documents\YiidActivity(); $lActivity->fromArray($lParams); // try to save activity try { $lActivity->save(); $this->redirect("@deal?url=" . urlencode($lUrl)); } catch (Exception $e) { // send error on exception $this->getLogger()->err($e->getMessage()); $this->pError = $e->getMessage(); } } $dm = MongoManager::getDM(); $this->pActivity = $dm->getRepository("Documents\\YiidActivity")->findOneBy(array("url" => $lUrl, "u_id" => intval($this->getUser()->getId()), "d_id" => array('$exists' => false))); // if user has already liked if ($this->pActivity) { $this->redirect("@deal?url=" . urlencode($lUrl)); } $lYiidMeta = new YiidMeta(); $lYiidMeta->fromParams($request->getParameterHolder()); $this->pYiidMeta = SocialObjectParser::fetch($request->getParameter("url"), $lYiidMeta); if ($this->pYiidMeta === false) { $this->error = "the url '{$lUrl}' is not well formed!"; return $this->setTemplate("share"); } $domainProfile = DomainProfileTable::getInstance()->retrieveByUrl($lUrl); $this->trackingUrl = null; if ($domainProfile) { $this->trackingUrl = $domainProfile->getTrackingUrl(); } $this->getResponse()->setSlot('js_document_ready', $this->getPartial('like/js_init_like.js', array('pImgCount' => count($this->pYiidMeta->getImages()), 'pUrl' => $request->getParameter("url")))); }
/** * Enter description here... * * @param unknown_type $url * @return unknown */ public static function request($url, $format) { $content = UrlUtils::getUrlContent($url); if ($format == "json") { $result = json_decode(trim($content), false); if (is_object($result)) { return $result; } else { return false; } } else { $result = simplexml_load_string(trim($content)); if (is_object($result)) { return $result; } } return false; }
private static function getMojangMD5($MCVersion) { $url = 'https://s3.amazonaws.com/Minecraft.Download/versions/' . $MCVersion . '/' . $MCVersion . '.jar'; $response = UrlUtils::getHeaders($url, 15); if (!empty($response)) { $response = str_replace('"', '', $response); $data = explode("\n", $response, 11); $headers = array(); array_shift($data); foreach ($data as $part) { if (strpos($part, ':') !== FALSE) { $middle = explode(": ", $part, 2); $headers[trim($middle[0])] = trim($middle[1]); } } return $headers['ETag']; } return ''; }
public function Execute() { header('Content-Type: application/json'); $action = UrlUtils::GetRequestParamOrDefault("action", null); $packageId = UrlUtils::GetRequestParamOrDefault("id", "angularjs"); $version = UrlUtils::GetRequestParamOrDefault("version", "1.0.3"); $data = array(); switch ($action) { case 'resources': //header("Location: https://api.nuget.org/v3/index.json"); $data = $this->Resources(); break; case 'searchServices': //header("Location: https://api-search.nuget.org/"); $data = $this->SearchServices(); break; case 'searchResources': //header("Location: https://api-search.nuget.org/search"); $data = $this->SearchResources(); break; case 'searchFields': $data = "Location: https://api-search.nuget.org/search/fields"; break; case 'searchQuery': $data = "Location: https://api-search.nuget.org/search/query"; break; case 'searchDiag': $data = "Location: https://api-search.nuget.org/search/diag"; break; case 'packages': $data = "Location: https://api.nuget.org/v3/registration0/" . $packageId . "/index.json"; break; case 'package': $data = "Location: https://api.nuget.org/v3/registration0/" . $packageId . "/" . $version . ".json"; break; default: HttpUtils::ApiError(404, "Not found"); break; } echo json_encode($data, JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT); die; }
public function executeGet_button(sfWebRequest $request) { $this->getResponse()->setContentType('application/json'); $lParams = $request->getParameter('likebutton'); $lUrl = "http://www.spreadly.com"; $lSocial = 0; if (isset($lParams['url']) && UrlUtils::isUrlValid($lParams['url'])) { $lUrl = $lParams['url']; } if (isset($lParams['wt']) && $lParams['wt'] == 'stand_social') { $lSocial = 1; } if (isset($lParams['text'])) { $lLabel = $lParams['text']; } if (isset($lParams['color'])) { $lColor = $lParams['color']; } $lService = isset($lParams['service']) ? $lParams['service'] : null; $lReturn['iframe'] = $this->getPartial('configurator/preview_widgets', array('pUrl' => $lUrl, 'pSocial' => $lSocial, 'pService' => $lService)); return $this->renderText(json_encode($lReturn)); }
/** * get the data_series informations * * @link http://chartbeat.pbworks.com/w/page/26872013/data_series * @param string $selecor * @return array */ public function getVisitorsByDate($selector) { switch ($selector) { case "today": $timestamp = strtotime("today"); $days = 1; $minutes = 1; break; case "yesterday": $timestamp = strtotime("yesterday"); $days = 2; $minutes = 1; break; case "last7d": $days = 7; $minutes = 1; break; case "last30d": $days = 30; $minutes = 1; break; } $url = "http://chartbeat.com/data_series/?days=" . $days . "&host=spread.ly&type=summary&val=people&minutes=" . $minutes . "&apikey=" . $this->apikey; if (isset($timestamp)) { $url .= '&timestamp=' . $timestamp; } $json = UrlUtils::getUrlContent($url); $data = json_decode($json, true); array_walk($data['people'], function (&$el) { if ($el == null) { $el = 0; } }); if ($selector == "yesterday") { $data['people'] = array_slice($data['people'], 0, 1440); } return array_sum($data['people']); }
/** * handles the parsing of a new social-object * currently parsed: opengraph and metatags * * @param string $pUrl * @return array $pArray */ public static function fetch($pUrl, $pYiidMeta = null) { $pUrl = trim(urldecode($pUrl)); $pUrl = str_replace(" ", "+", $pUrl); try { //get the html as string $lHtml = UrlUtils::getUrlContent($pUrl, 'GET'); if (!$lHtml) { return false; } // boost performance and use alreade the header $lHeader = substr($lHtml, 0, stripos($lHtml, '</head>')); if (!$pYiidMeta) { $pYiidMeta = new YiidMeta(); } $pYiidMeta->setUrl($pUrl); if ((preg_match('~http://opengraphprotocol.org/schema/~i', $lHeader) || preg_match('~http://ogp.me/ns#~i', $lHeader) || preg_match('~property=[\\"\']og:~i', $lHeader)) && !$pYiidMeta->isComplete()) { //get the opengraph-tags $lOpenGraph = OpenGraph::parse($lHeader); $pYiidMeta->fromOpenGraph($lOpenGraph); } if (preg_match('~application/(xml|json)\\+oembed"~i', $lHeader) && !$pYiidMeta->isComplete()) { try { $lOEmbed = OEmbedParser::fetchByCode($lHeader); $pYiidMeta->fromOembed($lOEmbed); } catch (Exception $e) { // catch exception and try to go on } } if (!$pYiidMeta->isComplete()) { $lMeta = MetaTagParser::getKeys($lHtml, $pUrl); $pYiidMeta->fromMeta($lMeta); } return $pYiidMeta; } catch (Exception $e) { return false; } }
function getLinkCount($urlFrom, $urlTo) { $urlFrom = UrlUtils::removeWWW($urlFrom); $urlTo = UrlUtils::removeWWW($urlTo); $res = $this->grabbCount($urlTo, $urlFrom); $num = $res["num"]; $searcher = $res["url"]; $res = $this->grabbCount("www." . $urlTo, $urlFrom); if ($num < $res["num"]) { $num = $res["num"]; $searcher = $res["url"]; } $res = $this->grabbCount($urlTo, "www." . $urlFrom); if ($num < $res["num"]) { $num = $res["num"]; $searcher = $res["url"]; } $res = $this->grabbCount("www." . $urlTo, "www." . $urlFrom); if ($num < $res["num"]) { $num = $res["num"]; $searcher = $res["url"]; } return "<a target='_blank' href='{$searcher}'\n\t\t\ttitle='Links count from {$urlFrom} to {$urlTo}'>{$num}</a>"; }
/** * returns the url of a favicon * * @param string $pUrl * @return string */ function get_favicon($pUrl) { return UrlUtils::getFavicon($pUrl); }
/** * Tests AddParamsToUrl. * @param string $url the URL to perform to add parameters to * @param string $params the parameters to add * @param string $expected the expected value of the final URL * @dataProvider AddParamsToUrlProvider */ public function testAddParamsToUrl($url, $params, $expected) { $value = UrlUtils::AddParamsToUrl($url, $params); $this->assertEquals($expected, $value); }
<?php require_once dirname(__FILE__) . "/../root.php"; require_once __ROOT__ . "/settings.php"; require_once __ROOT__ . "/inc/api_users.php"; require_once __ROOT__ . "/inc/commons/url.php"; require_once __ROOT__ . "/inc/commons/http.php"; require_once __ROOT__ . "/inc/api_nuget.php"; $id = UrlUtils::GetRequestParamOrDefault("id", null); $version = UrlUtils::GetRequestParamOrDefault("version", null); if ($id == null || $version == null) { HttpUtils::ApiError(500, "Wrong data. Missing param."); } if (strlen($id) == 0 || strlen($version) == 0) { HttpUtils::ApiError(500, "Wrong data. Empty id or version."); } $query = "Id eq '" . $id . "' and Version eq '" . $version . "'"; $db = new NuGetDb(); $os = new PhpNugetObjectSearch(); $os->Parse($query, $db->GetAllColumns()); $allRows = $db->GetAllRows(1, 0, $os); if (sizeof($allRows) == 0) { HttpUtils::ApiError(404, "Not found."); } $file = $allRows[0]->Id . "." . $allRows[0]->Version . ".nupkg"; $path = Path::Combine(Settings::$PackagesRoot, $file); if (!file_exists($path)) { HttpUtils::ApiError(404, "Not found " . $file); } header('Content-Type: application/zip'); header('Content-Disposition: attachment; filename=' . basename($path));
function parseItems() { $items = array(); $logger =& Log::singleton("null", "results.log", "ident"); $pattern = '{ <td width="80%"> <a href="([^"]+)"> <b class="c-t-[^>]+">(.+?)</b> </a> <div[^>]*>(.+?)</div> }si'; $pattern = preg_replace("{\\s+}", "\\s*", $pattern); if (!preg_match_all($pattern, $this->pageContent, $matches, PREG_PATTERN_ORDER)) { return new PEAR_Error("Items not found."); } for ($i = 0; $i < sizeof($matches[1]); $i++) { $item = array(); $url = UrlUtils::getRealUrl(UrlUtils::basePath($this->url), $matches[1][$i]); $item["url"] = $url; $item["name"] = StrUtils::cleanString($matches[2][$i]); $item["address"] = StrUtils::cleanString($matches[3][$i]); //if (!$this->checkUpdate($item["name"], $item["address"])) { // $logger->log("Exists item: " . $item["name"] . ", " . $item["address"]); // continue; //} $logger->log("New item: " . $item["name"] . ", " . $item["address"]); $item = array_merge($item, $this->getItemInfo($url)); $pattern = "{.+?bo(\\d+)/ru(\\d+)}si"; if (preg_match($pattern, $url, $numMatches)) { $item["ru"] = $numMatches[2]; $item["bo"] = $numMatches[1]; } else { $item["ru"] = 0; $item["bo"] = 0; } $this->setStatus($item); $items[] = $item; } $logger->log("Size of items: " . sizeof($items)); $logger->log(print_r($items, true)); $this->rubricsData->addNextNums(sizeof($matches[1])); return $items; }