Example #1
0
 /**
  * @return bool
  */
 public function isEmpty()
 {
     if (!$this->_isEmpty) {
         $this->_isEmpty = IOHelper::isFileEmpty($this->getRealPath());
     }
     return $this->_isEmpty;
 }
 /**
  * Import Featured Image from Posts
  *
  * @param mixed $settings Array of settings
  * @param string $postUrl Url of WordPress post
  * @param string $baseUrl domain and uri path to Wordpress site
  *
  * @return string $postContent Post content with image url attributes updated.
  */
 private function _importFeaturedImage($settings, $postUrl, $baseUrl)
 {
     // Scrape post for featured image
     $tempFileName = md5($postUrl) . '.tmp';
     $tempFolder = craft()->path->getStoragePath() . 'instablog/';
     $tempFile = $tempFolder . $tempFileName;
     $postUrl = $this->_getAbsoluteUrl($postUrl, $baseUrl);
     $curlResponse = $this->_getRemoteFile($postUrl, $tempFile);
     $remoteImagePath = false;
     if ($curlResponse && false === IOHelper::isFileEmpty($tempFile, true)) {
         $dom = new \domDocument();
         // load the html into the object
         $dom->loadHTMLFile($tempFile);
         $dom->preserveWhiteSpace = false;
         $imgEls = $dom->getElementsByTagName('img');
         foreach ($imgEls as $img) {
             if (strpos($img->getAttribute('class'), 'wp-post-image')) {
                 $remoteImagePath = $img->getAttribute('src');
             }
         }
         IOHelper::deleteFile($tempFile, true);
     }
     // Add asset
     if ($remoteImagePath) {
         if ($assetId = $this->_addAsset($settings, $remoteImagePath, $baseUrl, false)) {
             return $assetId;
         }
     }
     return false;
 }