コード例 #1
0
 /**
  *
  * This method returns the metrics about a URL or set of URLs.
  *
  * @param mixed <array|string> objectURL - if array is passed then batch request
  * @param string cols
  * @return response
  */
 public function getUrlMetrics($objectURL, $cols)
 {
     $urlToFetch = "http://lsapi.seomoz.com/linkscape/url-metrics/";
     $postParams = null;
     // if passed more then 1 url - pass them through post
     if (!is_array($objectURL)) {
         $urlToFetch .= urlencode($objectURL);
     } else {
         $postParams = json_encode($objectURL);
     }
     $urlToFetch .= "?" . $this->getAuthenticator()->getAuthenticationStr();
     $urlToFetch .= "&Cols=" . $cols;
     $response = ConnectionUtility::makeRequest($urlToFetch, $postParams);
     $i = $this->getAuthenticator()->getRateLimit();
     // if request fails retry with exponential backoff
     if (isset($response['http']) && $response['http'] != "200") {
         do {
             $i = $i + $i;
             // output message (optional)
             echo "\n\nERROR: HTTP Response Code (" . $response['http'] . ")";
             echo "\nWaiting {$i} seconds to retry";
             sleep($i);
             $response = ConnectionUtility::makeRequest($urlToFetch, $postParams);
         } while ($response['http'] != "200");
     }
     unset($response['http']);
     return $response;
 }
コード例 #2
0
 /**
  * This method returns a set of anchor text terms of phrases aggregated across links to a page or domain.
  *
  * @param string objectURL
  * @param array options
  * @return a set of anchor text terms of phrases aggregated across links to a page or domain.
  */
 public function getAnchorText($objectURL, array $options = array())
 {
     $urlToFetch = "http://lsapi.seomoz.com/linkscape/anchor-text/" . urlencode($objectURL) . "?" . $this->getAuthenticator()->getAuthenticationStr();
     /**
      * scope determines the scope of the link, and takes one of the following values:
      *    phrase_to_page: returns a set of phrases found in links to the specified page
      *    phrase_to_subdomain: returns a set of phrases found in links to the specified subdomain
      *    phrase_to_domain: returns a set of phrases found in links to the specified root domain
      *    term_to_page: returns a set of terms found in links to the specified page
      *    term_to_subdomain: returns a a set of terms found in links to the specified subdomain
      *    term_to_domain: returns a a set of terms found in links to the specified root domain
      */
     if (isset($options['scope']) && $options['scope'] !== null) {
         $urlToFetch .= "&Scope=" . $options['scope'];
     }
     /**
      *  sort determines the sorting of the links, in combination with limit and offset, this allows fast access to the top links by several orders:
      *    domains_linking_page: the phrases or terms found in links from the most number of root domains linking are returned first
      */
     if (isset($options['sort']) && $options['sort'] !== null) {
         $urlToFetch .= "&Sort=" . $options['sort'];
     }
     /**
      * cols determines what fields are returned
      */
     if (isset($options['cols']) && (int) $options['cols'] > 0) {
         $urlToFetch .= "&Cols=" . (int) $options['cols'];
     }
     /**
      *  Offset The start record of the page can be specified using the Offset parameter
      */
     if (isset($options['offset']) && (int) $options['offset'] > 0) {
         $urlToFetch .= "&Offset=" . (int) $options['offset'];
     }
     /**
      * limit The size of the page can by specified using the Limit parameter.
      */
     if (isset($options['limit']) && (int) $options['limit'] > 0) {
         $urlToFetch .= "&Limit=" . $options['limit'];
     }
     $response = ConnectionUtility::makeRequest($urlToFetch);
     $i = $this->getAuthenticator()->getRateLimit();
     // if request fails retry with exponential backoff
     if (isset($response['http']) && $response['http'] != "200") {
         do {
             $i = $i + $i;
             // output message (optional)
             echo "\n\nERROR: HTTP Response Code (" . $response['http'] . ")";
             echo "\nWaiting {$i} seconds to retry";
             sleep($i);
             $response = ConnectionUtility::makeRequest($urlToFetch, $postParams);
         } while ($response['http'] != "200");
     }
     unset($response['http']);
     return $response;
 }
コード例 #3
0
 /**
  * This method returns a set of links to a page or domain.
  *
  * @param string $objectURL
  * @param array $options    options which can be passed to make request
  * @return stdObject
  */
 public function getLinks($objectURL, array $options = array())
 {
     $urlToFetch = "http://lsapi.seomoz.com/linkscape/links/" . urlencode($objectURL) . "?" . $this->getAuthenticator()->getAuthenticationStr();
     // scope determines the scope of the Target link, as well as the Source results
     if (isset($options['scope'])) {
         $urlToFetch .= "&Scope=" . $options['scope'];
     }
     // filters the links returned to only include links of the specified type.  You may include one or more of the following values separated by '+'
     if (isset($options['filters'])) {
         $urlToFetch .= "&Filter=" . $options['filters'];
     }
     // sort determines the sorting of the links, in combination with limit and offset, this allows fast access to the top links by several orders.
     if (isset($options['sort'])) {
         $urlToFetch .= "&Sort=" . $options['sort'];
     }
     // specifies data about the source of the link is included
     if (isset($options['source_cols'])) {
         $urlToFetch .= "&SourceCols=" . $options['source_cols'];
     }
     // specifies data about the target of the link is included
     if (isset($options['target_cols'])) {
         $urlToFetch .= "&TargetCols=" . $options['target_cols'];
     }
     // specifies data about the link itself (e.g. if the link is nofollowed)
     if (isset($options['link_cols'])) {
         $urlToFetch .= "&LinkCols=" . $options['link_cols'];
     }
     // The start record of the page can be specified using the Offset parameter
     if (isset($options['offset']) && (int) $options['offset'] >= 0) {
         $urlToFetch .= "&Offset=" . (int) $options['offset'];
     }
     // The size of the page can by specified using the Limit parameter.
     if (isset($options['limit']) && (int) $options['limit'] >= 0) {
         $urlToFetch .= "&Limit=" . (int) $options['limit'];
     }
     $response = ConnectionUtility::makeRequest($urlToFetch);
     $i = $this->getAuthenticator()->getRateLimit();
     // if request fails retry with exponential backoff
     if (isset($response['http']) && $response['http'] != "200") {
         do {
             $i = $i + $i;
             // output message (optional)
             echo "\n\nERROR: HTTP Response Code (" . $response['http'] . ")";
             echo "\nWaiting {$i} seconds to retry";
             sleep($i);
             $response = ConnectionUtility::makeRequest($urlToFetch, $postParams);
         } while ($response['http'] != "200");
     }
     unset($response['http']);
     return $response;
 }
コード例 #4
0
 /**
  * This method returns the metrics about many URLs on a given subdomain
  *
  * @param string objectURL
  * @param array $options
  * @return
  */
 public function getTopPages($objectURL, array $options = array())
 {
     $urlToFetch = "http://lsapi.seomoz.com/linkscape/top-pages/" . urlencode($objectURL) . "?" . $this->getAuthenticator()->getAuthenticationStr();
     /**
      * @param cols - A set of metrics can be requested by indicating them as bit flags in the Cols query parameter.
      */
     if (isset($options['cols']) && (int) $options['cols'] > 0) {
         $urlToFetch .= "&Cols=" . $options['cols'];
     }
     /**
      * @param offset - The start record of the page can be specified using the Offset parameter
      */
     if (isset($options['offset']) && (int) $options['offset'] > 0) {
         $urlToFetch .= "&Offset=" . $options['offset'];
     }
     /**
      * @param limit - The size of the page can by specified using the Limit parameter.
      */
     if (isset($options['limit']) && (int) $options['limit'] > 0) {
         $urlToFetch .= "&Limit=" . $options['limit'];
     }
     $response = ConnectionUtility::makeRequest($urlToFetch);
     $i = $this->getAuthenticator()->getRateLimit();
     // if request fails retry with exponential backoff
     if (isset($response['http']) && $response['http'] != "200") {
         do {
             $i = $i + $i;
             // output message (optional)
             echo "\n\nERROR: HTTP Response Code (" . $response['http'] . ")";
             echo "\nWaiting {$i} seconds to retry";
             sleep($i);
             $response = ConnectionUtility::makeRequest($urlToFetch, $postParams);
         } while ($response['http'] != "200");
     }
     unset($response['http']);
     return $response;
 }