This commit is contained in:
2017-06-24 00:58:56 +03:00
commit 315d1fded7
2331 changed files with 296580 additions and 0 deletions
.gitignore.htaccessREADME.md
admin
.htaccessadmin.favicon.icoadmin.phpblocks.phpbrowser.phpdbsettings.phpdocs.phpfields.phpfinder.php
functions
groups.phpindex.phpinit.php
lang
logs.phpmodules.phpnavigation.phprequest.phprubs.phpsettings.phpstart.phpsysblocks.phptemplates.php
templates
blocks
browser
css
dbactions
documents
error.tpl
finder
fonts
groups
images
IconHome.gifNavBg.pngaccordion_off.pngaccordion_on.pngadd.pngalertOpacityOverlay.pngarrow.gif
backgrounds
blanc.gifchevron.gifchosen-sprite.pngchosen-sprite@2x.pngclippy.svgdarkBg.jpgdarkBg.png
fancybox
file.giffolder.giffolder_up.gif
forms
icons
jquery_ui
leftNavBg.pngleftNavSub.pngleft_menu_show.pnglevel.pngloader2.gifloader3.gifloading.gifloginLogo.pnglogosmall.png
mediapool
middlebg.pngnav_level_2.gifnav_level_3.gifnumberTop.pngref.pngsearchSmall.pngsprites.gifsprites_doc.pngtable_level.pngtabsSep.pngtipsy.giftitleBg.pngtopNav.jpgui.totop.png
ui
upload.png
uploader
user.pnguserPic.pngwidgetBg.png
js
login.tpllogin_scripts.tpl
logs
main.tpl
modules
navi
navigation
noperm.tplonlycontent.tplpop.tpl
request
rubs
scripts.tpl
settings
start.tpl
sysblocks
templates
user
user.php
backup
cache
class
fields
.htaccess
checkbox
code
date
doc_from_rub
doc_from_rub_check
doc_from_rub_search
download
drop_down
drop_down_key
flash
image_mega
image_multi
image_multi_new_3inputs
image_single
link
multi_checkbox
multi_line
multi_line_simple
multi_line_slim
multi_list
multi_list_single
multi_list_triple
multi_select
single_line
single_line_numeric
teasers
text_to_image
youtube
functions
inc
index.php
install
lib
Smarty
.htaccessConfig_File.class.phpSmarty.class.phpSmarty_Compiler.class.phpdebug.tpl
internals
plugins
StripTagsSmart
SwiftMailer
classes
Swift.php
Swift
Attachment.php
ByteStream
CharacterReader.php
CharacterReader
CharacterReaderFactory.php
CharacterReaderFactory
CharacterStream.php
CharacterStream
ConfigurableSpool.phpDependencyContainer.phpDependencyException.phpEmbeddedFile.phpEncoder.php
Encoder
Encoding.php
Events
FailoverTransport.phpFileSpool.phpFileStream.phpFilterable.phpImage.phpInputByteStream.phpIoException.phpKeyCache.php
KeyCache
LoadBalancedTransport.phpMailTransport.phpMailer.php
Mailer
MemorySpool.phpMessage.php
Mime
MimePart.phpNullTransport.phpOutputByteStream.php
Plugins
Preferences.phpReplacementFilterFactory.phpRfcComplianceException.phpSendmailTransport.phpSignedMessage.phpSigner.php
Signers
SmtpTransport.phpSpool.phpSpoolTransport.phpStreamFilter.php
StreamFilters
SwiftException.phpTransport.php
Transport
TransportException.phpValidate.php
dependency_maps
mime_types.phppreferences.phpswift_init.phpswift_required.phpswift_required_pear.phpswiftmailer_generate_mimes_config.phpversion.txt
bootstrap
combine
flags
ad.pngae.pngaf.pngag.pngai.pngal.pngam.pngan.pngao.pngar.pngas.pngat.pngau.pngaw.pngax.pngaz.pngba.pngbb.pngbd.pngbe.pngbf.pngbg.pngbh.pngbi.pngbj.pngbm.pngbn.pngbo.pngbr.pngbs.pngbt.pngbv.pngbw.pngby.pngbz.pngca.pngcatalonia.pngcc.pngcd.pngcf.pngcg.pngch.pngci.pngck.pngcl.pngcm.pngcn.pngco.pngcr.pngcs.pngcu.pngcv.pngcx.pngcy.pngcz.pngde.pngdj.pngdk.pngdm.pngdo.pngdz.pngec.pngee.pngeg.pngeh.pngen.pngengland.pnger.pnges.pnget.pngeu.pngfam.pngfi.pngfj.pngfk.pngfm.pngfo.pngfr.pngga.pnggb.pnggd.pngge.pnggf.pnggh.pnggi.pnggl.pnggm.pnggn.pnggp.pnggq.pnggr.pnggs.pnggt.pnggu.pnggw.pnggy.pnghk.pnghm.pnghn.pnghr.pnght.pnghu.pngid.pngie.pngil.pngin.pngio.pngiq.pngir.pngis.pngit.pngjm.pngjo.pngjp.pngke.pngkg.pngkh.pngki.pngkm.pngkn.pngkp.pngkr.pngkw.pngky.pngkz.pngla.pnglb.pnglc.pngli.pnglk.pnglr.pngls.pnglt.pnglu.pnglv.pngly.pngma.pngmc.pngmd.pngme.pngmg.pngmh.pngmk.pngml.pngmm.pngmn.pngmo.pngmp.pngmq.pngmr.pngms.pngmt.pngmu.pngmv.pngmw.pngmx.pngmy.pngmz.pngna.pngnc.pngne.pngnf.pngng.pngni.pngnl.pngno.pngnp.pngnr.pngnu.pngnz.pngom.pngpa.pngpe.pngpf.pngpg.pngph.pngpk.pngpl.pngpm.pngpn.pngpr.pngps.pngpt.pngpw.pngpy.pngqa.pngre.pngro.pngrs.pngru.pngrw.pngsa.pngsb.pngsc.pngscotland.pngsd.pngse.pngsg.pngsh.pngsi.pngsj.pngsk.pngsl.pngsm.pngsn.pngso.pngsp.pngsr.pngst.pngsv.pngsy.pngsz.pngtc.pngtd.pngtf.pngtg.pngth.pngtj.pngtk.pngtl.pngtm.pngtn.pngto.pngtr.pngtt.pngtv.pngtw.pngtz.pngua.pngug.pngum.pnguy.pnguz.pngva.pngvc.pngve.pngvg.pngvi.pngvn.pngvu.pngwales.pngwf.pngws.pngye.pngyt.pngza.pngzm.pngzw.png
kcaptcha
mobile_detect
redactor
ckeditor
.htaccess
adapters
block.jsckeditor.jsconfig.default.jsconfig.jscontents.css
lang
plugins
a11yhelp
about
clipboard
dialogs
codemirror
css
icons
js
lang
plugin.js
theme
colordialog
copyformatting
dialog
div
dialogs
find
dialogs
flash
forms
icons.pngicons_hidpi.png
iframe
image
dialogs
images
link
liststyle
magicline
pagebreak
pastefromword
placeholder
preview
savedocs
scayt
showblocks
smiley
specialchar
table
dialogs
tabletools
templates
wsc
skins
styles.jssysblock.js
codemirror
addon
codemirror_connect.tplcodemirror_editor.tplconfig.jsconfig_css.jsfunctions.jsindex.php
lib
mode
theme
elfinder
css
img
inc
js
sounds
elrte
scripts
translate
license.txt
modules
robots.txt
session
templates
uploads

@ -0,0 +1,121 @@
<?php
/**
* elFinder Plugin AutoResize
*
* Auto resize on file upload.
*
* ex. binding, configure on connector options
* $opts = array(
* 'bind' => array(
* 'upload.presave' => array(
* 'Plugin.AutoResize.onUpLoadPreSave'
* )
* ),
* // global configure (optional)
* 'plugin' => array(
* 'AutoResize' => array(
* 'enable' => true, // For control by volume driver
* 'maxWidth' => 1024, // Path to Water mark image
* 'maxHeight' => 1024, // Margin right pixel
* 'quality' => 95, // JPEG image save quality
* 'preserveExif' => false, // Preserve EXIF data (Imagick only)
* 'forceEffect' => false, // For change quality of small images
* 'targetType' => IMG_GIF|IMG_JPG|IMG_PNG|IMG_WBMP, // Target image formats ( bit-field )
* 'offDropWith' => null // To disable it if it is dropped with pressing the meta key
* // Alt: 8, Ctrl: 4, Meta: 2, Shift: 1 - sum of each value
* // In case of using any key, specify it as an array
* )
* ),
* // each volume configure (optional)
* 'roots' => array(
* array(
* 'driver' => 'LocalFileSystem',
* 'path' => '/path/to/files/',
* 'URL' => 'http://localhost/to/files/'
* 'plugin' => array(
* 'AutoResize' => array(
* 'enable' => true, // For control by volume driver
* 'maxWidth' => 1024, // Path to Water mark image
* 'maxHeight' => 1024, // Margin right pixel
* 'quality' => 95, // JPEG image save quality
* 'preserveExif' => false, // Preserve EXIF data (Imagick only)
* 'forceEffect' => false, // For change quality of small images
* 'targetType' => IMG_GIF|IMG_JPG|IMG_PNG|IMG_WBMP, // Target image formats ( bit-field )
* 'offDropWith' => null // To disable it if it is dropped with pressing the meta key
* // Alt: 8, Ctrl: 4, Meta: 2, Shift: 1 - sum of each value
* // In case of using any key, specify it as an array
* )
* )
* )
* )
* );
*
* @package elfinder
* @author Naoki Sawada
* @license New BSD
*/
class elFinderPluginAutoResize extends elFinderPlugin {
public function __construct($opts) {
$defaults = array(
'enable' => true, // For control by volume driver
'maxWidth' => 1024, // Path to Water mark image
'maxHeight' => 1024, // Margin right pixel
'quality' => 95, // JPEG image save quality
'preserveExif' => false, // Preserve EXIF data (Imagick only)
'forceEffect' => false, // For change quality of small images
'targetType' => IMG_GIF|IMG_JPG|IMG_PNG|IMG_WBMP, // Target image formats ( bit-field )
'offDropWith' => null // To disable it if it is dropped with pressing the meta key
// Alt: 8, Ctrl: 4, Meta: 2, Shift: 1 - sum of each value
// In case of using any key, specify it as an array
);
$this->opts = array_merge($defaults, $opts);
}
public function onUpLoadPreSave(&$path, &$name, $src, $elfinder, $volume) {
$opts = $this->getCurrentOpts($volume);
if (! $this->iaEnabled($opts)) {
return false;
}
$mime = mime_content_type($src);
if (substr($mime, 0, 5) !== 'image') {
return false;
}
$srcImgInfo = getimagesize($src);
if ($srcImgInfo === false) {
return false;
}
// check target image type
$imgTypes = array(
IMAGETYPE_GIF => IMG_GIF,
IMAGETYPE_JPEG => IMG_JPEG,
IMAGETYPE_PNG => IMG_PNG,
IMAGETYPE_BMP => IMG_WBMP,
IMAGETYPE_WBMP => IMG_WBMP
);
if (! isset($imgTypes[$srcImgInfo[2]]) || ! ($opts['targetType'] & $imgTypes[$srcImgInfo[2]])) {
return false;
}
if ($opts['forceEffect'] || $srcImgInfo[0] > $opts['maxWidth'] || $srcImgInfo[1] > $opts['maxHeight']) {
return $this->resize($volume, $src, $srcImgInfo, $opts['maxWidth'], $opts['maxHeight'], $opts['quality'], $opts['preserveExif']);
}
return false;
}
private function resize($volume, $src, $srcImgInfo, $maxWidth, $maxHeight, $jpgQuality, $preserveExif) {
$zoom = min(($maxWidth/$srcImgInfo[0]),($maxHeight/$srcImgInfo[1]));
$width = round($srcImgInfo[0] * $zoom);
$height = round($srcImgInfo[1] * $zoom);
$unenlarge = true;
return $volume->imageUtil('resize', $src, compact('width', 'height', 'jpgQuality', 'preserveExif', 'unenlarge'));
}
}

@ -0,0 +1,112 @@
<?php
/**
* elFinder Plugin AutoRotate
*
* Auto rotation on file upload of JPEG file by EXIF Orientation.
*
* ex. binding, configure on connector options
* $opts = array(
* 'bind' => array(
* 'upload.presave' => array(
* 'Plugin.AutoRotate.onUpLoadPreSave'
* )
* ),
* // global configure (optional)
* 'plugin' => array(
* 'AutoRotate' => array(
* 'enable' => true, // For control by volume driver
* 'quality' => 95, // JPEG image save quality
* 'offDropWith' => null // To disable it if it is dropped with pressing the meta key
* // Alt: 8, Ctrl: 4, Meta: 2, Shift: 1 - sum of each value
* // In case of using any key, specify it as an array
* )
* ),
* // each volume configure (optional)
* 'roots' => array(
* array(
* 'driver' => 'LocalFileSystem',
* 'path' => '/path/to/files/',
* 'URL' => 'http://localhost/to/files/'
* 'plugin' => array(
* 'AutoRotate' => array(
* 'enable' => true, // For control by volume driver
* 'quality' => 95, // JPEG image save quality
* 'offDropWith' => null // To disable it if it is dropped with pressing the meta key
* // Alt: 8, Ctrl: 4, Meta: 2, Shift: 1 - sum of each value
* // In case of using any key, specify it as an array
* )
* )
* )
* )
* );
*
* @package elfinder
* @author Naoki Sawada
* @license New BSD
*/
class elFinderPluginAutoRotate extends elFinderPlugin {
public function __construct($opts) {
$defaults = array(
'enable' => true, // For control by volume driver
'quality' => 95, // JPEG image save quality
'offDropWith' => null // To disable it if it is dropped with pressing the meta key
// Alt: 8, Ctrl: 4, Meta: 2, Shift: 1 - sum of each value
// In case of using any key, specify it as an array
);
$this->opts = array_merge($defaults, $opts);
}
public function onUpLoadPreSave(&$path, &$name, $src, $elfinder, $volume) {
$opts = $this->getCurrentOpts($volume);
if (! $this->iaEnabled($opts)) {
return false;
}
$mime = mime_content_type($src);
if (substr($mime, 0, 5) !== 'image') {
return false;
}
$srcImgInfo = getimagesize($src);
if ($srcImgInfo === false) {
return false;
}
// check target image type
if ($srcImgInfo[2] !== IMAGETYPE_JPEG) {
return false;
}
return $this->rotate($volume, $src, $srcImgInfo, $opts['quality']);
}
private function rotate($volume, $src, $srcImgInfo, $quality) {
if (! function_exists('exif_read_data')) {
return false;
}
$degree = 0;
$exif = exif_read_data($src);
if($exif && !empty($exif['Orientation'])) {
switch($exif['Orientation']) {
case 8:
$degree = 270;
break;
case 3:
$degree = 180;
break;
case 6:
$degree = 90;
break;
}
}
$opts = array(
'degree' => $degree,
'jpgQuality' => $quality
);
return $volume->imageUtil('rotate', $src, $opts);
}
}

@ -0,0 +1,160 @@
<?php
/**
* elFinder Plugin Normalizer
*
* UTF-8 Normalizer of file-name and file-path etc.
* nfc(NFC): Canonical Decomposition followed by Canonical Composition
* nfkc(NFKC): Compatibility Decomposition followed by Canonical
*
* This plugin require Class "Normalizer" (PHP 5 >= 5.3.0, PECL intl >= 1.0.0)
* or PEAR package "I18N_UnicodeNormalizer"
*
* ex. binding, configure on connector options
* $opts = array(
* 'bind' => array(
* 'upload.pre mkdir.pre mkfile.pre rename.pre archive.pre ls.pre' => array(
* 'Plugin.Normalizer.cmdPreprocess'
* ),
* 'ls' => array(
* 'Plugin.Normalizer.cmdPostprocess'
* ),
* 'upload.presave' => array(
* 'Plugin.Normalizer.onUpLoadPreSave'
* )
* ),
* // global configure (optional)
* 'plugin' => array(
* 'Normalizer' => array(
* 'enable' => true,
* 'nfc' => true,
* 'nfkc' => true,
* 'lowercase' => false,
* 'convmap' => array()
* )
* ),
* // each volume configure (optional)
* 'roots' => array(
* array(
* 'driver' => 'LocalFileSystem',
* 'path' => '/path/to/files/',
* 'URL' => 'http://localhost/to/files/'
* 'plugin' => array(
* 'Normalizer' => array(
* 'enable' => true,
* 'nfc' => true,
* 'nfkc' => true,
* 'lowercase' => false,
* 'convmap' => array()
* )
* )
* )
* )
* );
*
* @package elfinder
* @author Naoki Sawada
* @license New BSD
*/
class elFinderPluginNormalizer extends elFinderPlugin
{
private $replaced = array();
private $keyMap = array(
'ls' => 'intersect',
'upload' => 'renames'
);
public function __construct($opts) {
$defaults = array(
'enable' => true, // For control by volume driver
'nfc' => true, // Canonical Decomposition followed by Canonical Composition
'nfkc' => true, // Compatibility Decomposition followed by Canonical
'lowercase' => false, // Make chars lowercase
'convmap' => array()// Convert map ('FROM' => 'TO') array
);
$this->opts = array_merge($defaults, $opts);
}
public function cmdPreprocess($cmd, &$args, $elfinder, $volume) {
$opts = $this->getCurrentOpts($volume);
if (! $opts['enable']) {
return false;
}
$this->replaced[$cmd] = array();
$key = (isset($this->keyMap[$cmd]))? $this->keyMap[$cmd] : 'name';
if (isset($args[$key])) {
if (is_array($args[$key])) {
foreach($args[$key] as $i => $name) {
$this->replaced[$cmd][$name] = $args[$key][$i] = $this->normalize($name, $opts);
}
} else {
$name = $args[$key];
$this->replaced[$cmd][$name] = $args[$key] = $this->normalize($name, $opts);
}
}
return true;
}
public function cmdPostprocess($cmd, &$result, $args, $elfinder) {
if ($cmd === 'ls') {
if (! empty($result['list']) && ! empty($this->replaced['ls'])) {
foreach($result['list'] as $hash => $name) {
if ($keys = array_keys($this->replaced['ls'], $name)) {
if (count($keys) === 1) {
$result['list'][$hash] = $keys[0];
} else {
$result['list'][$hash] = $keys;
}
}
}
}
}
}
public function onUpLoadPreSave(&$path, &$name, $src, $elfinder, $volume) {
$opts = $this->getCurrentOpts($volume);
if (! $opts['enable']) {
return false;
}
if ($path) {
$path = $this->normalize($path, $opts);
}
$name = $this->normalize($name, $opts);
return true;
}
private function normalize($str, $opts) {
if ($opts['nfc'] || $opts['nfkc']) {
if (class_exists('Normalizer', false)) {
if ($opts['nfc'] && ! Normalizer::isNormalized($str, Normalizer::FORM_C))
$str = Normalizer::normalize($str, Normalizer::FORM_C);
if ($opts['nfkc'] && ! Normalizer::isNormalized($str, Normalizer::FORM_KC))
$str = Normalizer::normalize($str, Normalizer::FORM_KC);
} else {
if (! class_exists('I18N_UnicodeNormalizer', false)) {
include_once 'I18N/UnicodeNormalizer.php';
}
if (class_exists('I18N_UnicodeNormalizer', false)) {
$normalizer = new I18N_UnicodeNormalizer();
if ($opts['nfc'])
$str = $normalizer->normalize($str, 'NFC');
if ($opts['nfkc'])
$str = $normalizer->normalize($str, 'NFKC');
}
}
}
if ($opts['convmap'] && is_array($opts['convmap'])) {
$str = strtr($str, $opts['convmap']);
}
if ($opts['lowercase']) {
if (function_exists('mb_strtolower')) {
$str = mb_strtolower($str, 'UTF-8');
} else {
$str = strtolower($str);
}
}
return $str;
}
}

@ -0,0 +1,121 @@
<?php
/**
* elFinder Plugin Sanitizer
*
* Sanitizer of file-name and file-path etc.
*
* ex. binding, configure on connector options
* $opts = array(
* 'bind' => array(
* 'upload.pre mkdir.pre mkfile.pre rename.pre archive.pre ls.pre' => array(
* 'Plugin.Sanitizer.cmdPreprocess'
* ),
* 'ls' => array(
* 'Plugin.Sanitizer.cmdPostprocess'
* ),
* 'upload.presave' => array(
* 'Plugin.Sanitizer.onUpLoadPreSave'
* )
* ),
* // global configure (optional)
* 'plugin' => array(
* 'Sanitizer' => array(
* 'enable' => true,
* 'targets' => array('\\','/',':','*','?','"','<','>','|'), // target chars
* 'replace' => '_' // replace to this
* )
* ),
* // each volume configure (optional)
* 'roots' => array(
* array(
* 'driver' => 'LocalFileSystem',
* 'path' => '/path/to/files/',
* 'URL' => 'http://localhost/to/files/'
* 'plugin' => array(
* 'Sanitizer' => array(
* 'enable' => true,
* 'targets' => array('\\','/',':','*','?','"','<','>','|'), // target chars
* 'replace' => '_' // replace to this
* )
* )
* )
* )
* );
*
* @package elfinder
* @author Naoki Sawada
* @license New BSD
*/
class elFinderPluginSanitizer extends elFinderPlugin
{
private $replaced = array();
private $keyMap = array(
'ls' => 'intersect',
'upload' => 'renames'
);
public function __construct($opts) {
$defaults = array(
'enable' => true, // For control by volume driver
'targets' => array('\\','/',':','*','?','"','<','>','|'), // target chars
'replace' => '_' // replace to this
);
$this->opts = array_merge($defaults, $opts);
}
public function cmdPreprocess($cmd, &$args, $elfinder, $volume) {
$opts = $this->getCurrentOpts($volume);
if (! $opts['enable']) {
return false;
}
$this->replaced[$cmd] = array();
$key = (isset($this->keyMap[$cmd]))? $this->keyMap[$cmd] : 'name';
if (isset($args[$key])) {
if (is_array($args[$key])) {
foreach($args[$key] as $i => $name) {
$this->replaced[$cmd][$name] = $args[$key][$i] = $this->sanitizeFileName($name, $opts);
}
} else {
$name = $args[$key];
$this->replaced[$cmd][$name] = $args[$key] = $this->sanitizeFileName($name, $opts);
}
}
return true;
}
public function cmdPostprocess($cmd, &$result, $args, $elfinder) {
if ($cmd === 'ls') {
if (! empty($result['list']) && ! empty($this->replaced['ls'])) {
foreach($result['list'] as $hash => $name) {
if ($keys = array_keys($this->replaced['ls'], $name)) {
if (count($keys) === 1) {
$result['list'][$hash] = $keys[0];
} else {
$result['list'][$hash] = $keys;
}
}
}
}
}
}
public function onUpLoadPreSave(&$path, &$name, $src, $elfinder, $volume) {
$opts = $this->getCurrentOpts($volume);
if (! $opts['enable']) {
return false;
}
if ($path) {
$path = $this->sanitizeFileName($path, $opts, array('/'));
}
$name = $this->sanitizeFileName($name, $opts);
return true;
}
private function sanitizeFileName($filename, $opts, $allows = array()) {
$targets = $allows? array_diff($opts['targets'], $allows) : $opts['targets'];
return str_replace($targets, $opts['replace'], $filename);
}
}

Binary file not shown.

After

(image error) Size: 9.1 KiB

@ -0,0 +1,307 @@
<?php
/**
* elFinder Plugin Watermark
*
* Print watermark on file upload.
*
* ex. binding, configure on connector options
* $opts = array(
* 'bind' => array(
* 'upload.presave' => array(
* 'Plugin.Watermark.onUpLoadPreSave'
* )
* ),
* // global configure (optional)
* 'plugin' => array(
* 'Watermark' => array(
* 'enable' => true, // For control by volume driver
* 'source' => 'logo.png', // Path to Water mark image
* 'marginRight' => 5, // Margin right pixel
* 'marginBottom' => 5, // Margin bottom pixel
* 'quality' => 95, // JPEG image save quality
* 'transparency' => 70, // Water mark image transparency ( other than PNG )
* 'targetType' => IMG_GIF|IMG_JPG|IMG_PNG|IMG_WBMP, // Target image formats ( bit-field )
* 'targetMinPixel' => 200, // Target image minimum pixel size
* 'offDropWith' => null // To disable it if it is dropped with pressing the meta key
* // Alt: 8, Ctrl: 4, Meta: 2, Shift: 1 - sum of each value
* // In case of using any key, specify it as an array
* )
* ),
* // each volume configure (optional)
* 'roots' => array(
* array(
* 'driver' => 'LocalFileSystem',
* 'path' => '/path/to/files/',
* 'URL' => 'http://localhost/to/files/'
* 'plugin' => array(
* 'Watermark' => array(
* 'enable' => true, // For control by volume driver
* 'source' => 'logo.png', // Path to Water mark image
* 'marginRight' => 5, // Margin right pixel
* 'marginBottom' => 5, // Margin bottom pixel
* 'quality' => 95, // JPEG image save quality
* 'transparency' => 70, // Water mark image transparency ( other than PNG )
* 'targetType' => IMG_GIF|IMG_JPG|IMG_PNG|IMG_WBMP, // Target image formats ( bit-field )
* 'targetMinPixel' => 200, // Target image minimum pixel size
* 'offDropWith' => null // To disable it if it is dropped with pressing the meta key
* // Alt: 8, Ctrl: 4, Meta: 2, Shift: 1 - sum of each value
* // In case of using any key, specify it as an array
* )
* )
* )
* )
* );
*
* @package elfinder
* @author Naoki Sawada
* @license New BSD
*/
class elFinderPluginWatermark extends elFinderPlugin {
private $watermarkImgInfo = null;
public function __construct($opts) {
$defaults = array(
'enable' => true, // For control by volume driver
'source' => 'logo.png', // Path to Water mark image
'marginRight' => 5, // Margin right pixel
'marginBottom' => 5, // Margin bottom pixel
'quality' => 95, // JPEG image save quality
'transparency' => 70, // Water mark image transparency ( other than PNG )
'targetType' => IMG_GIF|IMG_JPG|IMG_PNG|IMG_WBMP, // Target image formats ( bit-field )
'targetMinPixel' => 200, // Target image minimum pixel size
'offDropWith' => null // To disable it if it is dropped with pressing the meta key
// Alt: 8, Ctrl: 4, Meta: 2, Shift: 1 - sum of each value
// In case of using any key, specify it as an array
);
$this->opts = array_merge($defaults, $opts);
}
public function onUpLoadPreSave(&$path, &$name, $src, $elfinder, $volume) {
$opts = $this->getCurrentOpts($volume);
if (! $this->iaEnabled($opts)) {
return false;
}
$mime = mime_content_type($src);
if (substr($mime, 0, 5) !== 'image') {
return false;
}
$srcImgInfo = getimagesize($src);
if ($srcImgInfo === false) {
return false;
}
// check Animation Gif
if (elFinder::isAnimationGif($src)) {
return false;
}
// check water mark image
if (! file_exists($opts['source'])) {
$opts['source'] = dirname(__FILE__) . "/" . $opts['source'];
}
if (is_readable($opts['source'])) {
$watermarkImgInfo = getimagesize($opts['source']);
if (! $watermarkImgInfo) {
return false;
}
} else {
return false;
}
$watermark = $opts['source'];
$marginLeft = $opts['marginRight'];
$marginBottom = $opts['marginBottom'];
$quality = $opts['quality'];
$transparency = $opts['transparency'];
// check target image type
$imgTypes = array(
IMAGETYPE_GIF => IMG_GIF,
IMAGETYPE_JPEG => IMG_JPEG,
IMAGETYPE_PNG => IMG_PNG,
IMAGETYPE_BMP => IMG_WBMP,
IMAGETYPE_WBMP => IMG_WBMP
);
if (! isset($imgTypes[$srcImgInfo[2]]) || ! ($opts['targetType'] & $imgTypes[$srcImgInfo[2]])) {
return false;
}
// check target image size
if ($opts['targetMinPixel'] > 0 && $opts['targetMinPixel'] > min($srcImgInfo[0], $srcImgInfo[1])) {
return false;
}
$watermark_width = $watermarkImgInfo[0];
$watermark_height = $watermarkImgInfo[1];
$dest_x = $srcImgInfo[0] - $watermark_width - $marginLeft;
$dest_y = $srcImgInfo[1] - $watermark_height - $marginBottom;
if (class_exists('Imagick', false)) {
return $this->watermarkPrint_imagick($src, $watermark, $dest_x, $dest_y, $quality, $transparency, $watermarkImgInfo);
} else {
return $this->watermarkPrint_gd($src, $watermark, $dest_x, $dest_y, $quality, $transparency, $watermarkImgInfo, $srcImgInfo);
}
}
private function watermarkPrint_imagick($src, $watermark, $dest_x, $dest_y, $quality, $transparency, $watermarkImgInfo) {
try {
// Open the original image
$img = new Imagick($src);
// Open the watermark
$watermark = new Imagick($watermark);
// Set transparency
if (strtoupper($watermark->getImageFormat()) !== 'PNG') {
$watermark->setImageOpacity($transparency/100);
}
// Overlay the watermark on the original image
$img->compositeImage($watermark, imagick::COMPOSITE_OVER, $dest_x, $dest_y);
// Set quality
if (strtoupper($img->getImageFormat()) === 'JPEG') {
$img->setImageCompression(imagick::COMPRESSION_JPEG);
$img->setCompressionQuality($quality);
}
$result = $img->writeImage($src);
$img->clear();
$img->destroy();
$watermark->clear();
$watermark->destroy();
return $result ? true : false;
} catch (Exception $e) {
return false;
}
}
private function watermarkPrint_gd($src, $watermark, $dest_x, $dest_y, $quality, $transparency, $watermarkImgInfo, $srcImgInfo) {
$watermark_width = $watermarkImgInfo[0];
$watermark_height = $watermarkImgInfo[1];
$ermsg = '';
switch ($watermarkImgInfo['mime']) {
case 'image/gif':
if (imagetypes() & IMG_GIF) {
$oWatermarkImg = imagecreatefromgif($watermark);
} else {
$ermsg = 'GIF images are not supported';
}
break;
case 'image/jpeg':
if (imagetypes() & IMG_JPG) {
$oWatermarkImg = imagecreatefromjpeg($watermark) ;
} else {
$ermsg = 'JPEG images are not supported';
}
break;
case 'image/png':
if (imagetypes() & IMG_PNG) {
$oWatermarkImg = imagecreatefrompng($watermark) ;
} else {
$ermsg = 'PNG images are not supported';
}
break;
case 'image/wbmp':
if (imagetypes() & IMG_WBMP) {
$oWatermarkImg = imagecreatefromwbmp($watermark);
} else {
$ermsg = 'WBMP images are not supported';
}
break;
default:
$oWatermarkImg = false;
$ermsg = $watermarkImgInfo['mime'].' images are not supported';
break;
}
if (! $ermsg) {
switch ($srcImgInfo['mime']) {
case 'image/gif':
if (imagetypes() & IMG_GIF) {
$oSrcImg = imagecreatefromgif($src);
} else {
$ermsg = 'GIF images are not supported';
}
break;
case 'image/jpeg':
if (imagetypes() & IMG_JPG) {
$oSrcImg = imagecreatefromjpeg($src) ;
} else {
$ermsg = 'JPEG images are not supported';
}
break;
case 'image/png':
if (imagetypes() & IMG_PNG) {
$oSrcImg = imagecreatefrompng($src) ;
} else {
$ermsg = 'PNG images are not supported';
}
break;
case 'image/wbmp':
if (imagetypes() & IMG_WBMP) {
$oSrcImg = imagecreatefromwbmp($src);
} else {
$ermsg = 'WBMP images are not supported';
}
break;
default:
$oSrcImg = false;
$ermsg = $srcImgInfo['mime'].' images are not supported';
break;
}
}
if ($ermsg || false === $oSrcImg || false === $oWatermarkImg) {
return false;
}
if ($srcImgInfo['mime'] === 'image/png') {
if (function_exists('imagecolorallocatealpha')) {
$bg = imagecolorallocatealpha($oSrcImg, 255, 255, 255, 127);
imagefill($oSrcImg, 0, 0 , $bg);
}
}
if ($watermarkImgInfo['mime'] === 'image/png') {
imagecopy($oSrcImg, $oWatermarkImg, $dest_x, $dest_y, 0, 0, $watermark_width, $watermark_height);
} else {
imagecopymerge($oSrcImg, $oWatermarkImg, $dest_x, $dest_y, 0, 0, $watermark_width, $watermark_height, $transparency);
}
switch ($srcImgInfo['mime']) {
case 'image/gif':
imagegif($oSrcImg, $src);
break;
case 'image/jpeg':
imagejpeg($oSrcImg, $src, $quality);
break;
case 'image/png':
if (function_exists('imagesavealpha') && function_exists('imagealphablending')) {
imagealphablending($oSrcImg, false);
imagesavealpha($oSrcImg, true);
}
imagepng($oSrcImg, $src);
break;
case 'image/wbmp':
imagewbmp($oSrcImg, $src);
break;
}
imageDestroy($oSrcImg);
imageDestroy($oWatermarkImg);
return true;
}
}