Exemplo n.º 1
0
 /**
  * Fetches HTML body with the specified URL with caching functionality.
  * 
  * @return      string
  */
 public function getHTML($sURL, $bUseFileGetContents = false, $iCacheDuration = 86400)
 {
     if ($bUseFileGetContents) {
         $_oHTML = new AmazonAutoLinks_HTTPClient_FileGetContents($sURL, $iCacheDuration);
         return $_oHTML->get();
     }
     $_oHTML = new AmazonAutoLinks_HTTPClient($sURL, $iCacheDuration);
     return $_oHTML->get();
 }
 /**
  * Retrieves the sidebar category list.
  * 
  * @since            2.0.0
  * @remark           Due to missing elements with the DOMDocument class in some Japanese pages, 
  * this method uses the simple_html_dom library.
  */
 protected function _getSidebar($sPageURL, $sLocale = 'US', $iAttempt = 0)
 {
     // Include the library.
     if (!class_exists('simple_html_dom_node')) {
         include_once AmazonAutoLinks_Registry::$sDirPath . '/include/library/simple_html_dom.php';
     }
     // This has a caching functionality.
     $_oHTTP = new AmazonAutoLinks_HTTPClient($sPageURL);
     $sHTML = $_oHTTP->get();
     if (!$sHTML) {
         return array('error' => __("Could not retrieve the category list: {$sPageURL}. Please consult the plugin developer.", 'amazon-auto-links')) + self::$aStructure_Sidebar;
     }
     // Instantiate the class.
     $_oSimpleDOM = str_get_html($sHTML);
     if (!$_oSimpleDOM->find("#zg_browseRoot", 0)) {
         $_oHTTP->deleteCache();
         // Try with a R18 confirmation redirect - must use file_get_contents(), not wp_remote()
         if ($iAttempt >= 2) {
             $_sRedirectURL = AmazonAutoLinks_Property::$aCategoryBlackCurtainURLs[$sLocale] . '?redirect=true&redirectUrl=' . urlencode($sPageURL);
             $_oHTTP = new AmazonAutoLinks_HTTPClient_FileGetContents($_sRedirectURL);
             $sHTML = $_oHTTP->get();
             if (!$sHTML) {
                 $_oHTTP->deleteCache();
                 return array('error' => __("Could not load the page for the second attempt: {$_sRedirectURL}. Please consult the plugin developer.", 'amazon-auto-links')) + self::$aStructure_Sidebar;
             }
             $_oSimpleDOM = str_get_html($sHTML);
             if (!$_oSimpleDOM->find("#zg_browseRoot", 0)) {
                 $sHTML = $_oSimpleDOM->outertext;
                 $_oHTTP->deleteCache();
                 return array('error' => sprintf(__('Could not find the category in this page: %1$s Please consult the plugin developer.', 'amazon-auto-links'), $_sRedirectURL)) + self::$aStructure_Sidebar;
             }
             return array('sRSSURL' => $this->_getCategoryFeedURL($_oSimpleDOM), 'sCategoryList' => $this->_getCategoryList($_oSimpleDOM), 'sBreadcrumb' => $this->_getBreadcrumb($_oSimpleDOM, $sLocale));
         }
         return $this->_getSidebar($sPageURL, $sLocale, ++$iAttempt);
     }
     return array('sRSSURL' => $this->_getCategoryFeedURL($_oSimpleDOM), 'sCategoryList' => $this->_getCategoryList($_oSimpleDOM), 'sBreadcrumb' => $this->_getBreadcrumb($_oSimpleDOM, $sLocale));
 }