mirror of
https://github.com/Studio-42/elFinder
synced 2026-06-08 12:37:09 +00:00
Page:
Logging
Pages
3rd party connectors, plugins, modules
Adding file description to Properties dialog 2.1
Adding file description to Properties dialog
Adding new column to list view in 2.1
Advisory about vulnerability of CVE 2018 9109 and CVE 2018 9110
Automatically load language
Basic Authentication Example
Build and compress elFinder from source
Client Server API 2.0
Client Server API 2.1
Client configuration options 2.1
Client configuration options
Client event API
Common issues
Connector configuration options 2.1
Connector configuration options
Create dialog with custom context menu command
Custom context menu command
Custom search function
Disable real file path from being shown
Getting encoded hash from the path
HOWTOs by external sites
Home
How to get OAuth token
How to load CSS with RequireJS
Install
Integration with CKEditor (jQuery UI dialog mode) Varian 2 (change url)
Integration with CKEditor (jQuery UI dialog mode)
Integration with CKEditor 4 (jQuery UI dialog mode)
Integration with CKEditor 4
Integration with CKEditor 5
Integration with CKEditor
Integration with CodeIgniter
Integration with Codeigniter 2
Integration with Multiple Summernote (fixed functions)
Integration with TinyMCE 3.x
Integration with TinyMCE 4.x
Integration with elRTE 1.x
Logging
Multiple Roots
Node.js connector
Simple file permissions control
Using custom editor to edit files within elfinder
Using elFinder 2.x UI with 1.x connector
Using toast() to display popup notifications in 2.1
Clone
4
Logging
Naoki Sawada edited this page 2018-05-10 00:06:07 +09:00
Table of Contents
This page demonstrates how to use elFinder connector event API to implement simple logging. Event API uses callbacks similar to jQuery.bind() and defined using bind connector option.
Using function callback
<?php
/**
* Smart logger function
* Demonstrate how to work with elFinder event api
*
* @param string $cmd command name
* @param array $result command result
* @param array $args command arguments from client
* @param elFinder $elfinder elFinder instance
* @param volume $volume elFinder current volume instance
* @return void|true
* @author Troex Nevelin
**/
function logger($cmd, $result, $args, $elfinder, $volume) {
$log = sprintf('[%s] %s:', date('r'), strtoupper($cmd));
foreach ($result as $key => $value) {
if (empty($value)) {
continue;
}
$data = array();
if (in_array($key, array('error', 'warning'))) {
array_push($data, implode(' ', $value));
} else {
if (is_array($value)) { // changes made to files
foreach ($value as $file) {
$filepath = (isset($file['realpath']) ? $file['realpath'] : $elfinder->realpath($file['hash']));
array_push($data, $filepath);
}
} else { // other value (ex. header)
array_push($data, $value);
}
}
$log .= sprintf(' %s(%s)', $key, implode(', ', $data));
}
$log .= "\n";
$logfile = '../files/temp/log.txt';
$dir = dirname($logfile);
if (!is_dir($dir) && !mkdir($dir)) {
return;
}
if (($fp = fopen($logfile, 'a'))) {
fwrite($fp, $log);
fclose($fp);
}
}
$opts = array(
'bind' => array(
'mkdir mkfile rename duplicate upload rm paste' => 'logger'
),
'roots' => array(...)
);
Using class instance callback
<?php
/**
* Simple logger function.
* Demonstrate how to work with elFinder event api.
*
* @package elFinder
* @author Dmitry (dio) Levashov
**/
class elFinderSimpleLogger {
/**
* Log file path
*
* @var string
**/
protected $file = '';
/**
* constructor
*
* @return void
* @author Dmitry (dio) Levashov
**/
public function __construct($path) {
$this->file = $path;
$dir = dirname($path);
if (!is_dir($dir)) {
mkdir($dir);
}
}
/**
* Create log record
*
* @param string $cmd command name
* @param array $result command result
* @param array $args command arguments from client
* @param elFinder $elfinder elFinder instance
* @param volume $volume elFinder current volume instance
* @return void|true
* @author Dmitry (dio) Levashov
**/
public function log($cmd, $result, $args, $elfinder, $volume) {
$log = $cmd.' ['.date('d.m H:s')."]\n";
if (!empty($result['error'])) {
$log .= "\tERROR: ".implode(' ', $result['error'])."\n";
}
if (!empty($result['warning'])) {
$log .= "\tWARNING: ".implode(' ', $result['warning'])."\n";
}
if (!empty($result['removed'])) {
foreach ($result['removed'] as $file) {
// removed file contain additional field "realpath"
$log .= "\tREMOVED: ".$file['realpath']."\n";
}
}
if (!empty($result['added'])) {
foreach ($result['added'] as $file) {
$log .= "\tADDED: ".$elfinder->realpath($file['hash'])."\n";
}
}
if (!empty($result['changed'])) {
foreach ($result['changed'] as $file) {
$log .= "\tCHANGED: ".$elfinder->realpath($file['hash'])."\n";
}
}
$this->write($log);
}
/**
* Write log into file
*
* @param string $log log record
* @return void
* @author Dmitry (dio) Levashov
**/
protected function write($log) {
if (($fp = @fopen($this->file, 'a'))) {
fwrite($fp, $log."\n");
fclose($fp);
}
}
}
$myLogger = new elFinderSimpleLogger('files/temp/log.txt');
$opts = array(
'bind' => array(
'mkdir mkfile rename duplicate upload rm paste' => array($myLogger, 'log'),
),
'roots' => array(...)
);