🎉 Hello World!
This commit is contained in:
50
cloudinary.php
Normal file
50
cloudinary.php
Normal file
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
namespace Grav\Plugin;
|
||||
|
||||
use Grav\Common\Plugin;
|
||||
use RocketTheme\Toolbox\Event\Event;
|
||||
|
||||
class CloudinaryPlugin extends Plugin
|
||||
{
|
||||
protected $cloudinary;
|
||||
|
||||
public static function getSubscribedEvents()
|
||||
{
|
||||
return [
|
||||
'onPluginsInitialized' => ['onPluginsInitialized', 0],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Activate plugin if path matches to the configured one.
|
||||
*/
|
||||
public function onPluginsInitialized()
|
||||
{
|
||||
if ($this->isAdmin()) {
|
||||
$this->active = false;
|
||||
return;
|
||||
}
|
||||
|
||||
\Cloudinary::config([
|
||||
"cloud_name" => $this->config->get('plugins.cloudinary.license_key'),
|
||||
"api_key" => $this->config->get('plugins.cloudinary.license_key'),
|
||||
"api_secret" => $this->config->get('plugins.cloudinary.license_key'),
|
||||
]);
|
||||
|
||||
$this->enable([
|
||||
'onImageMediumSaved' => ['onImageMediumSaved', 0],
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
public function onImageMediumSaved(Event $event)
|
||||
{
|
||||
|
||||
$path = $event['image'];
|
||||
$cloudinary_image = \Cloudinary\Uploader::upload($path);
|
||||
|
||||
if (!empty($cloudinary_image)) {
|
||||
file_put_contents($path, $cloudinary_image['secure_url']);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user