UPDATES EasyBlog 6.0.14 Released! Joomla 5.x and PHP 8.x compatible now!

Helpdesk

Your Time
Our Time
Response Time
24 — 48 hours
We strive to provide the fastest ever response possible. However, we are not super beings.

Allow at least 24 — 48 hours
  Support is online
Our support specialists is available now. We will attend to you as soon as we can.
  Support is online

Custom Code Breaking Change

Christopher Ambler · ·
11:26 PM Monday, 20 September 2021
High
Please find, below, some custom code that you guys helped provide a while back. Given the path to an image, this processes the image so it can be used as a post cover. As of this beta, this code is now breaking.

Specifically, this code is throwing an error:


// Read the external image file
$connector = EB::connector();


I suspect you've made a breaking change. Could you please advise?


public static function downloadImage(string $url, $post): ?stdClass
{
$config = EB::config();

if (!$config) {
return null;
}

// Store the image on a temporary location
$temporaryPath = JPATH_ROOT . '/tmp/' . md5($url);

// Read the external image file
$connector = EB::connector();
$connector->addUrl($url);
$connector->execute();

$contents = $connector->getResult($url);

// Save the image to a temporary location
JFile::write($temporaryPath, $contents);

// Prepare the image data
$file = getimagesize($temporaryPath);
$file['name'] = basename($url);
$file['tmp_name'] = $temporaryPath;
$file['type'] = $file['mime'];

$media = EB::mediamanager();
$uri = 'user:' . $post->created_by;

$adapter = $media->getAdapter($uri);
$result = $adapter->upload($file);

// Delete the temporary file
JFile::delete($temporaryPath);

if (!isset($result->type)) {
return null;
}

$path = $config->get('main_image_path');
$path = rtrim($path, '/');

$relative = $path . '/' . $post->created_by;

$relativeImagePath = $relative . '/' . $file['name'];
$result->html = '<img src="' . $relativeImagePath . '" />';

return $result;
}
The replies under this section are restricted to logged in users or users with an active subscription with us