+ @rmdir($folderPath);
+ }
+
+ /**
+ * Setup base folder where all images are going to be saved.
+ */
+ private function setFolder()
+ {
+ // if folder doesn't exist, attempt to create one and store the folder name in property $folder
+ if (!file_exists($this->baseFolder)) {
+ mkdir($this->baseFolder, 0755, true);
+ }
+ }
+
+ /**
+ * Generate the folder where we are going to save images based on the entry url.
+ *
+ * @param int $entryId ID of the entry
+ *
+ * @return string
+ */
+ private function getRelativePath($entryId)
+ {
+ $hashId = hash('crc32', $entryId);
+ $relativePath = $hashId[0] . '/' . $hashId[1] . '/' . $hashId;
+ $folderPath = $this->baseFolder . '/' . $relativePath;
+
+ if (!file_exists($folderPath)) {
+ mkdir($folderPath, 0777, true);
+ }
+
+ $this->logger->debug('DownloadImages: Folder used for that Entry id', ['folder' => $folderPath, 'entryId' => $entryId]);
+
+ return $relativePath;
+ }
+
+ /**
+ * Make an $url absolute based on the $base.
+ *
+ * @see Graby->makeAbsoluteStr
+ *
+ * @param string $base Base url
+ * @param string $url Url to make it absolute
+ *
+ * @return false|string
+ */
+ private function getAbsoluteLink($base, $url)
+ {
+ if (preg_match('!^https?://!i', $url)) {
+ // already absolute
+ return $url;
+ }
+
+ $base = new \SimplePie_IRI($base);
+
+ // remove '//' in URL path (causes URLs not to resolve properly)
+ if (isset($base->ipath)) {
+ $base->ipath = preg_replace('!//+!', '/', $base->ipath);
+ }
+
+ if ($absolute = \SimplePie_IRI::absolutize($base, $url)) {
+ return $absolute->get_uri();