コード例 #1
0
ファイル: TestOfURLExpander.php プロジェクト: dgw/ThinkUp
 public function testGetWebPageDetails()
 {
     $details = URLExpander::getWebPageDetails('http://google.com');
     print_r($details);
     $details = URLExpander::getWebPageDetails('http://smarterware.org');
     print_r($details);
     $details = URLExpander::getWebPageDetails("http://www.slate.com/blogs/future_tense/2013/08/29/klout_deletes" . "_tweet_martin_luther_king_would_have_had_an_awesome_klout_score.html?utm_content=buffer9b03f&utm_source=bu" . "ffer&utm_medium=twitter&utm_campaign=Buffer");
     print_r($details);
     $details = URLExpander::getWebPageDetails('https://twitter.com/LamarrWilson/status/372582861548703745/photo/1');
     print_r($details);
     $details = URLExpander::getWebPageDetails('http://justdelete.me/');
     print_r($details);
     $details = URLExpander::getWebPageDetails('https://stellar.io/x/manage/membership');
     print_r($details);
     $details = URLExpander::getWebPageDetails('https://www.wepay.com/donations/free-barrett-brown');
     print_r($details);
 }
コード例 #2
0
 public function testGetWebPageDetails()
 {
     $details = URLExpander::getWebPageDetails('http://google.com');
     print_r($details);
     $details = URLExpander::getWebPageDetails('http://smarterware.org');
     print_r($details);
     $details = URLExpander::getWebPageDetails("http://www.slate.com/blogs/future_tense/2013/08/29/klout_deletes" . "_tweet_martin_luther_king_would_have_had_an_awesome_klout_score.html?utm_content=buffer9b03f&utm_source=bu" . "ffer&utm_medium=twitter&utm_campaign=Buffer");
     print_r($details);
     $details = URLExpander::getWebPageDetails('https://twitter.com/LamarrWilson/status/372582861548703745/photo/1');
     print_r($details);
     $details = URLExpander::getWebPageDetails('http://justdelete.me/');
     print_r($details);
     $details = URLExpander::getWebPageDetails('https://stellar.io/x/manage/membership');
     print_r($details);
     $details = URLExpander::getWebPageDetails('https://www.wepay.com/donations/free-barrett-brown');
     print_r($details);
     $details = URLExpander::getWebPageDetails('https://www.facebook.com/photo.php?fbid=386789799914&set=' . 'at.386779984914.169691.68330209914.606837591&type=1&relevant_count=1');
     print_r($details);
     $details = URLExpander::getWebPageDetails('https://www.facebook.com/photo.php?fbid=10152071367417592&' . 'set=a.10150271482787592.335919.606837591&type=1&relevant_count=1');
     print_r($details);
 }
コード例 #3
0
 /**
  * Save expanded version of all unexpanded URLs to data store, as well as intermediary short links.
  */
 public function expandOriginalURLs($flickr_api_key = null)
 {
     $links_to_expand = $this->link_dao->getLinksToExpand($this->link_limit);
     $this->logger->logUserInfo(count($links_to_expand) . " links to expand. Please wait. Working...", __METHOD__ . ',' . __LINE__);
     $total_expanded = 0;
     $total_errors = 0;
     $has_expanded_flickr_link = false;
     foreach ($links_to_expand as $index => $link) {
         if (Utils::validateURL($link->url)) {
             $endless_loop_prevention_counter = 0;
             $this->logger->logInfo("Expanding " . ($total_expanded + 1) . " of " . count($links_to_expand) . " (" . $link->url . ")", __METHOD__ . ',' . __LINE__);
             //make sure shortened short links--like t.co--get fully expanded
             $fully_expanded = false;
             $short_link = $link->url;
             while (!$fully_expanded) {
                 //begin Flickr thumbnail processing
                 if (isset($flickr_api_key) && substr($short_link, 0, strlen('http://flic.kr/')) == 'http://flic.kr/') {
                     self::expandFlickrThumbnail($flickr_api_key, $short_link, $link->url);
                     $has_expanded_flickr_link = true;
                     $fully_expanded = true;
                 }
                 //end Flickr thumbnail processing
                 $expanded_url = URLExpander::expandURL($short_link, $link->url, $index, count($links_to_expand), $this->link_dao, $this->logger);
                 if ($expanded_url == $short_link || $expanded_url == '' || $endless_loop_prevention_counter > self::EXPANSION_CAP) {
                     $fully_expanded = true;
                 } else {
                     try {
                         $this->short_link_dao->insert($link->id, $short_link);
                     } catch (DataExceedsColumnWidthException $e) {
                         $this->logger->logError($short_link . " short link record exceeds column width, cannot save", __METHOD__ . ',' . __LINE__);
                         $fully_expanded = true;
                     }
                 }
                 if (strlen($expanded_url) < 256) {
                     $short_link = $expanded_url;
                 } else {
                     $fully_expanded = true;
                 }
                 $endless_loop_prevention_counter++;
             }
             if (!$has_expanded_flickr_link) {
                 if ($expanded_url != '') {
                     $image_src = URLProcessor::getImageSource($expanded_url);
                     $url_details = URLExpander::getWebPageDetails($expanded_url);
                     try {
                         $this->link_dao->saveExpandedUrl($link->url, $expanded_url, $url_details['title'], $image_src, $url_details['description']);
                         $total_expanded = $total_expanded + 1;
                     } catch (DataExceedsColumnWidthException $e) {
                         $this->logger->logError($link->url . " record exceeds column width, cannot save", __METHOD__ . ',' . __LINE__);
                         $this->link_dao->saveExpansionError($link->url, "URL exceeds column width");
                         $total_errors = $total_errors + 1;
                     }
                 } else {
                     $this->logger->logError($link->url . " not a valid URL - relocates to nowhere", __METHOD__ . ',' . __LINE__);
                     $this->link_dao->saveExpansionError($link->url, "Invalid URL - relocates to nowhere");
                     $total_errors = $total_errors + 1;
                 }
             }
         } else {
             $this->logger->logError($link->url . " not a valid URL", __METHOD__ . ',' . __LINE__);
             $this->link_dao->saveExpansionError($link->url, "Invalid URL");
             $total_errors = $total_errors + 1;
         }
         $has_expanded_flickr_link = false;
     }
     $this->logger->logUserSuccess($total_expanded . " URLs successfully expanded (" . $total_errors . " errors).", __METHOD__ . ',' . __LINE__);
 }
コード例 #4
0
 /**
  * Save expanded version of all unexpanded URLs to data store, as well as intermediary short links.
  */
 public function expandOriginalURLs($flickr_api_key = null)
 {
     $links_to_expand = $this->link_dao->getLinksToExpand($this->link_limit);
     $this->logger->logUserInfo(count($links_to_expand) . " links to expand. Please wait. Working...", __METHOD__ . ',' . __LINE__);
     $total_expanded = 0;
     $total_errors = 0;
     $has_expanded_flickr_link = false;
     foreach ($links_to_expand as $index => $link) {
         if (Utils::validateURL($link->url)) {
             $this->logger->logInfo("Expanding " . ($total_expanded + 1) . " of " . count($links_to_expand) . " (" . $link->url . ")", __METHOD__ . ',' . __LINE__);
             //make sure shortened short links--like t.co--get fully expanded
             $fully_expanded = false;
             $short_link = $link->url;
             while (!$fully_expanded) {
                 //begin Flickr thumbnail processing
                 if (isset($flickr_api_key) && substr($short_link, 0, strlen('http://flic.kr/')) == 'http://flic.kr/') {
                     self::expandFlickrThumbnail($flickr_api_key, $short_link, $link->url);
                     $has_expanded_flickr_link = true;
                     $fully_expanded = true;
                 }
                 //end Flickr thumbnail processing
                 $expanded_url = URLExpander::expandURL($short_link, $link->url, $index, count($links_to_expand), $this->link_dao, $this->logger);
                 if ($expanded_url == $short_link || $expanded_url == '') {
                     $fully_expanded = true;
                 } else {
                     $this->short_link_dao->insert($link->id, $short_link);
                 }
                 $short_link = $expanded_url;
             }
             if (!$has_expanded_flickr_link) {
                 if ($expanded_url != '') {
                     $image_src = URLProcessor::getImageSource($expanded_url);
                     $this->link_dao->saveExpandedUrl($link->url, $expanded_url, '', $image_src);
                     $total_expanded = $total_expanded + 1;
                 } else {
                     $this->logger->logError($link->url . " not a valid URL - relocates to nowhere", __METHOD__ . ',' . __LINE__);
                     $this->link_dao->saveExpansionError($link->url, "Invalid URL - relocates to nowhere");
                     $total_errors = $total_errors + 1;
                 }
             }
         } else {
             $total_errors = $total_errors + 1;
             $this->logger->logError($link->url . " not a valid URL", __METHOD__ . ',' . __LINE__);
             $this->link_dao->saveExpansionError($link->url, "Invalid URL");
         }
         $has_expanded_flickr_link = false;
     }
     $this->logger->logUserSuccess($total_expanded . " URLs successfully expanded (" . $total_errors . " errors).", __METHOD__ . ',' . __LINE__);
 }