/
example.php
58 lines (45 loc) · 992 Bytes
/
example.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<?php
defined('_JEXEC') or die;
class PlgMediaEditorExample extends JPlugin
{
public function onMediaEditorAllowed($fileType)
{
if ($fileType == 'image')
{
return true;
}
return false;
}
public function onMediaEditorButtonLabel()
{
return 'Example';
}
public function onMediaEditorDisplay($filePath)
{
// @suggestion: Add CSS, JavaScript
$data = array('filePath' => $filePath);
$layout = new JLayoutFile('form', __DIR__ . '/layout');
$html = $layout->render($data);
return $html;
}
public function onMediaEditorProcess($filePath)
{
jimport('joomla.filesystem.file');
$image = new JImage($filePath);
if ($image->isLoaded() == false)
{
throw new LogicException('Failed to load image');
}
$image->rotate(180, 0, false);
$extension = JFile::getExt($filePath);
if (in_array($extension, array('png', 'gif')))
{
$imageType = $extension;
}
else
{
$imageType = 'jpg';
}
$image->toFile($filePath, $imageType);
}
}