/** * 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; }
/** * 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 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; }
/** * 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; } }
/** * saves the favicon of a communitiy * * @author Matthias Pfefferle * * @param Object $pCommunity * @return boolean true|false */ public static function importFavicon($pCommunity, $pPath = self::PATH_TYPE_URL) { try { // try to get an image from websnapr $lImage = UrlUtils::getUrlContent($pCommunity->getFavicon()); $lBasePath = DIRECTORY_SEPARATOR . 'favicons' . DIRECTORY_SEPARATOR . $pCommunity->getSlug() . '.png'; // create folder structure and save the image to our local filesystem $path = sfConfig::get('sf_upload_dir') . $lBasePath; $fp = fopen($path, 'w+'); fputs($fp, $lImage); fclose($fp); // get mime-type $lImgData = GetImageSize($path); if ($lImgData['mime'] != "image/png") { $lImg = new sfImage($path, $lImgData['mime'], 'GD'); $lImg->getMIMEType(); $lImg->setQuality(100); $lImg->saveAs($path, 'image/png'); } unset($lImage); if ($pPath == self::PATH_TYPE_URL) { return DIRECTORY_SEPARATOR . sfConfig::get('sf_upload_dir_name') . $lBasePath; } else { return $path; } } catch (Exception $e) { sfContext::getInstance()->getLogger()->err("{ImageImporter} Exception: " . print_r($e, true)); return null; } }
public function testNewApiDealIsActiveImmediately() { $user = Doctrine_Core::getTable('sfGuardUser')->createQuery('u')->where('u.is_active = ?', true)->fetchOne(); $this->assertEquals(10, DealTable::getInstance()->count()); $data = UrlUtils::getUrlContent("http://api.spreadly.local/deals?access_token=" . $user->getAccessToken(), UrlUtils::HTTP_POST, self::$VALID_TEST_JSON); $this->assertEquals(11, DealTable::getInstance()->count()); $deal = DealTable::getInstance()->findOneByName('Kampagne Like'); $this->assertFalse($deal->isActive()); $this->assertEquals(DealTable::STATE_SUBMITTED, $deal->getState()); $data = UrlUtils::getUrlContent("http://api.spreadly.local/deals?access_token=" . $user->getAccessToken(), UrlUtils::HTTP_POST, self::$VALID_AUTOACTIVATE_TEST_JSON); $deal = DealTable::getInstance()->findOneByName('Kampagne Activate'); $this->assertTrue($deal->isActive()); $this->assertEquals(DealTable::STATE_ACTIVE, $deal->getState()); }
/** * looks up the informations of a given URL * * @param string $pUrl an URL or SGN-Link * @return string|null */ public static function verifyRelMe($pUrl, $pYiidIdentity) { $lJson = UrlUtils::getUrlContent('http://socialgraph.apis.google.com/lookup?q=' . $pUrl . '&fme=1'); //var_dump($lJson);die(); $lSGObject = json_decode($lJson, true); //var_dump($lSGObject);die(); $lUrl = $lSGObject["canonical_mapping"][$pUrl]; //var_dump($lUrl);die(); //$lAttributes = $lSGObject[$lUrl]; foreach ($lSGObject['nodes'][$lUrl]['claimed_nodes'] as $lClaimed) { if (stristr($pYiidIdentity, $lClaimed) != '') { return true; } } return false; }