2017 © Pedro Peláez
 

library connector

Jodit FileBrowser and Uploader connector

image

jodit/connector

Jodit FileBrowser and Uploader connector

  • Monday, March 5, 2018
  • by xdan
  • Repository
  • 1 Watchers
  • 2 Stars
  • 95 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 3 Forks
  • 0 Open issues
  • 27 Versions
  • 9 % Grown

The README.md

Jodit FileBrowser Connector for Jodit v.3.0

Official Jodit WYSIWYG PHP connector

old version for Jodit 2.x, (*1)

Install

composer create-project --no-dev jodit/connector

or download ZIP archive, (*2)

Configuration

Available options:, (*3)

  • $config['saveSameFileNameStrategy'] = "addNumber" - Strategy in case the uploaded file has the same name as the file on the server.
    • "addNumber" - The number "olsen.png" => "olsen(1).png" is added number to the file name, if such a file exists, it will be "olsen(2).png", etc.
    • "replace" - Just replace the file
    • "error" - Throw the error - "File already exists"
  • $config['quality'] = 90 - image quality
  • $config['datetimeFormat'] = 'd/m/Y' - Date format
  • $config['root'] = __DIR__ - the root directory for user files
  • $config['baseurl'] = ($_SERVER['HTTPS'] ? 'https://' : 'http://') . $_SERVER['HTTP_HOST'] . '/' - Root URL for user files (exp. http://xdsoft.net)
  • $config['createThumb'] = true - boolean, true - create thumbnails for previews (true)
  • $config['safeThumbsCountInOneTime'] = 20 - int, If the createThumb option is enabled, then with a large number of files in the folder, the server will noticeably slow down when generating so many previews. Therefore, at a time, only such a number of pictures are processed.
  • $config['thumbFolderName'] = '_thumbs' - thumbnails folder
  • $config['excludeDirectoryNames'] = ['.tmb', '.quarantine'], - exclude these folders
  • $config['extensions'] = ['jpg', 'png', 'gif', 'jpeg'] - an array of valid file extensions that are permitted to be loaded (['jpg', 'png', 'gif', 'jpeg'])
  • $config['maxFileSize'] = 8mb - Maximum file size (0 - is unlimited) default 8Mb
  • $config['allowCrossOrigin'] = false - Allow cross origin request
  • $config['allowReplaceSourceFile'] = true - Allow replace source image on resized or croped version
  • $config['sources'] - Array of options
  • $config['accessControl'] - Array for checking allow/deny permissions Read more
  • $config['defaultRole']="guest" - Default role for Access Control
  • $config['roleSessionVar']="JoditUserRole" - The session key name that Jodit connector will use for checking the role for current user. Read more

you can defined several sources, and override some options:, (*4)

$config['sources'] = [
    'images' => [
        'root' => __DIR__ . '/images',
        'baseurl' => 'http://xdsoft.net/images',
        'maxFileSize' => '100kb',
        'createThumb' => false,
        'extensions' => ['jpg'],
    ]
];

How use with Jodit

Filebrowser settings Detailt options, (*5)

new Jodit('#editor', {
    filebrowser: {
        ajax: {
            url: 'connector/index.php'
        }
    }
});

and uploader options Default options, (*6)

new Jodit('#editor', {
    uploader: {
        url: 'connector/index.php?action=fileUpload',
    }
});

Customize config

Change config.php, (*7)

Do not modify the default.config.php file, instead, override the settings in the config.php file, (*8)

return [
    'sources' => [
        'joomla Images' => [
            'root' => JPATH_BASE.'/images/',
            'baseurl' => '/images/',
            'createThumb' => true,
            'thumbFolderName' => '_thumbs',
            'extensions' => array('jpg', 'png', 'gif', 'jpeg'),
        ],
        'joomla Media' => [
            'root' => JPATH_BASE.'/media/',
            'baseurl' => '/medias/',
            'createThumb' => false,
            'thumbFolderName' => '_thumbs',
            'extensions' => array('jpg', 'png', 'gif', 'jpeg'),
        ],
    ]
];

Authentication

Change connector/checkAuthentication in connector/Application.php, (*9)

Like this:, (*10)

function checkAuthentication () {
    /********************************************************************************/
    if (empty($_SESSION['filebrowser'])) {
        throw new \ErrorException('You do not have permission to view this directory', 403);
    }
    /********************************************************************************/
}

Example Integrate with Joomla

Change Application.php, (*11)

<?php
define('_JEXEC', 1);
define('JPATH_BASE', realpath(realpath(__DIR__).'/../../../../../')); // replace to valid path

require_once JPATH_BASE . '/includes/defines.php';
require_once JPATH_BASE . '/includes/framework.php';

JFactory::getApplication('site');


class JoditRestApplication extends \jodit\JoditApplication {
    function checkAuthentication() {
        $user = JFactory::getUser();
        if (!$user->id) {
            trigger_error('You are not authorized!', E_USER_WARNING);
        }
    }
}

You can use $action for allow or deny access, (*12)

function checkPermissions () {
    /********************************************************************************/
    if (!empty($_SESSION['filebrowser'])) {
        switch ($this->action) {
        case "imageResize":
        case "fileMove":
        case "folderCreate":
        case "fileRemove":
        case "fileUploadRemote":
        case "fileUpload":
            throw new \ErrorException('You do not have permission to view this action', 403);
        }
        return true;
    }

    throw new \ErrorException('You do not have permission to view this directory', 403);
    /********************************************************************************/
}

but better use AllowControl option, (*13)

Access Control

roleSessionVar - The session key name that Jodit connector will use for checking the role for current user., (*14)

$config['roleSessionVar'] = 'JoditUserRole';

After this you will be able to use $_SESSION['JoditUserRole'] to set inside your script - user role, after that user was authenticated:, (*15)

Somewhere in your script, (*16)

session_start();
//...
$_SESSION['JoditUserRole'] = 'administrator';

In deafult.config.php you can find default ACL config, (*17)

$config['roleSessionVar'] = 'JoditUserRole';

$config['accessControl'][] = array(
    'role'                => '*',
    'extensions'          => '*',
    'path'                => '/',
    'FILES'               => true,
    'FILE_MOVE'           => true,
    'FILE_UPLOAD'         => true,
    'FILE_UPLOAD_REMOTE'  => true,
    'FILE_REMOVE'         => true,
    'FILE_RENAME'         => true,

    'FOLDERS'             => true,
    'FOLDER_MOVE'         => true,
    'FOLDER_REMOVE'       => true,
    'FOLDER_RENAME'       => true,

    'IMAGE_RESIZE'        => true,
    'IMAGE_CROP'          => true,
);

$config['accessControl'][] = array(
    'role'                => '*',

    'extensions'          => 'exe,bat,com,sh,swf',

    'FILE_MOVE'           => false,
    'FILE_UPLOAD'         => false,
    'FILE_UPLOAD_REMOTE'  => false,
    'FILE_RENAME'         => false,
);

It means that all authenticated user will have all permissions but they are not allowed to download executable files., (*18)

In config.php you can customize it. For example set read-only permission for all users, but give to users with the role - administrator full access:, (*19)

$config['accessControl'][] = Array(
 'role'                => '*',

 'FILES'               => false,
 'FILE_MOVE'           => false,
 'FILE_UPLOAD'         => false,
 'FILE_UPLOAD_REMOTE'  => false,
 'FILE_REMOVE'         => false,
 'FILE_RENAME'         => false,

 'FOLDERS'             => false,
 'FOLDER_MOVE'         => false,
 'FOLDER_REMOVE'       => false,
 'FOLDER_RENAME'       => false,

 'IMAGE_RESIZE'        => false,
 'IMAGE_CROP'          => false,
);

$config['accessControl'][] = Array(
 'role' => 'administrator',
 'FILES'               => true,
 'FILE_MOVE'           => true,
 'FILE_UPLOAD'         => true,
 'FILE_UPLOAD_REMOTE'  => true,
 'FILE_REMOVE'         => true,
 'FILE_RENAME'         => true,

 'FOLDERS'             => true,
 'FOLDER_MOVE'         => true,
 'FOLDER_REMOVE'       => true,
 'FOLDER_RENAME'       => true,

 'IMAGE_RESIZE'        => true,
 'IMAGE_CROP'          => true,
);

API

All actions case-sensitive, (*20)

Actions

permissions - get permissions to current path. This action should call after every changing path.

GET index.php?action=permission&source=:source&path=:path
  • [:source=default] - key from config (ex. from Joomla config - `joomla Media)
  • [:path=source.root] - relative path for source.root

See tests/api/PermissionsCept.php, (*21)

Answer JSON example:, (*22)

{
    "success": true,
    "time": "2018-03-05 10:14:44",
    "data": {
        "permissions": {
            "allowFiles": true,
            "allowFileMove": true,
            "allowFileUpload": true,
            "allowFileUploadRemote": true,
            "allowFileRemove": true,
            "allowFileRename": true,
            "allowFolders": true,
            "allowFolderMove": true,
            "allowFolderCreate": true,
            "allowFolderRemove": true,
            "allowFolderRename": true,
            "allowImageResize": true,
            "allowImageCrop": true
        },
        "code": 220
    }
}

files - Get all files from folder

GET index.php?action=files&source=:source&path=:path
  • [:source=default] - key from config (ex. from Joomla config - `joomla Media)
  • [:path=source.root] - relative path for source.root

See tests/api/getAllFilesByAllSourcesCept.php and tests/api/getAllFilesByOneSourceCept.php, (*23)

Answer JSON example:, (*24)

{
    "success": true,
    "time": "2017-07-10 17:10:26",
    "data": {
        "sources": {
            "test": {
                "baseurl": "http://localhost:8181/tests/files/",
                "path": "",
                "files": [
                    {
                        "file": "artio.jpg",
                        "thumb": "_thumbs\\artio.jpg",
                        "changed": "07/07/2017 3:06 PM",
                        "size": "53.50kB"
                    }
                ]
            },
            "folder1": {
                "baseurl": "http://localhost:8181/tests/files/folder1/",
                "path": "",
                "files": [
                    {
                        "file": "artio2.jpg",
                        "thumb": "_thumbs\\artio2.jpg",
                        "changed": "07/07/2017 3:06 PM",
                        "size": "53.50kB"
                    }
                ]
            }
        },
        "code": 220
    }
}

folders - Get all folders from path

GET index.php?action=folders&source=:source&path=:path
  • [:source=default] - key from config (ex. from Joomla config - `joomla Media)
  • [:path=source.root] - relative path for source.root.

See tests/api/getAllFoldersByAllSourcesCept.php and tests/api/getAllFoldersByOneSourceCept.php, (*25)

Answer JSON example:, (*26)

{
    "success": true,
    "time": "2017-07-10 17:11:10",
    "data": {
        "sources": {
            "test": {
                "baseurl": "http://localhost:8181/tests/files/",
                "path": "",
                "folders": [
                    ".",
                    "folder1"
                ]
            },
            "folder1": {
                "baseurl": "http://localhost:8181/tests/files/folder1/",
                "path": "",
                "folders": [
                    ".",
                    "folder2"
                ]
            }
        },
        "code": 220
    }
}

fileUploadRemote - Download image from another server

GET index.php?action=fileUploadRemote&source=:source&path=:path&url=:url
  • [:source=default] - key from config (ex. from Joomla config - `joomla Media)
  • [:path=source.root] - relative path for source.root.
  • :url - full image URL

See tests/api/uploadImageByUrlToServerCept.php, (*27)

Answer JSON example:, (*28)

{
    "success": true,
    "time": "2017-07-10 17:13:49",
    "data": {
        "newfilename": "icon-joomla.png",
        "baseurl": "http://localhost:8181/tests/files/",
        "code": 220
    }
}

fileUpload - Upload files to server

POST index.php
$_POST = [
    action=fileUpload,
    source=:source,
    path=:path,
]
$_FILES = [
    files=[...]
]
  • [:source=default] - key from config (ex. from Joomla config - `joomla Media)
  • [:path=source.root] - relative path for source.root.
  • :files - files

See tests/api/uploadImageToServerCept.php, (*29)

fileRemove - Remove file

GET index.php?action=fileRemove&source=:source&path=:path&name=:name
  • [:source=default] - key from config (ex. from Joomla config - `joomla Media)
  • [:path=source.root] - relative path for source.root.
  • :name - file name or folder name

See tests/api/removeImageFromServerCept.php, (*30)

folderRemove - Remove folder from server

GET index.php?action=folderRemove&source=:source&path=:path&name=:name
  • [:source=default] - key from config (ex. from Joomla config - `joomla Media)
  • [:path=source.root] - relative path for source.root.
  • :name - file name or folder name

folderCreate - Create folder on server

GET index.php?action=folderCreate&source=:source&path=:path&name=:name
  • [:source=default] - key from config (ex. from Joomla config - `joomla Media)
  • [:path=source.root] - relative path for source.root.
  • :name - new folder name

See tests/api/createFolderCept.php, (*31)

folderMove - Move folder to another place

GET index.php?action=folderMove&source=:source&path=:path&from=:from
  • [:source=default] - key from config (ex. from Joomla config - `joomla Media)
  • [:path=source.root] - relative path for source.root. This is where the file will be move
  • :from - relative path (from source.root) file or folder

See tests/api/moveFileCept.php, (*32)

fileMove - Move file to another place

GET index.php?action=fileMove&source=:source&path=:path&from=:from
  • [:source=default] - key from config (ex. from Joomla config - `joomla Media)
  • [:path=source.root] - relative path for source.root. This is where the file will be move
  • :from - relative path (from source.root) file or folder

See tests/api/moveFileCept.php, (*33)

imageResize - Resize image

GET index.php?action=imageResize&source=:source&path=:path&name=:name&box[w]=:box_width&box[h]=:box_height
  • [:source=default] - key from config (ex. from Joomla config - `joomla Media)
  • [:path=source.root] - relative path for source.root.
  • :name - File source in :path
  • :newname - new file name in :path. Can be equal :name
  • :box - new width and height

See tests/api/resizeImageCept.php, (*34)

imageCrop - Crop image

GET index.php?action=crop&source=:source&path=:path&name=:name&box[w]=:box_width&box[h]=:box_height&box[x]=:box_start_x&box[y]=:box_start_y
  • [:source=default] - key from config (ex. from Joomla config - `joomla Media)
  • [:path=source.root] - relative path for source.root.
  • :name - File source in :path
  • :newname - new file name in :path. Can be equal :name
  • :box - bounding box

See tests/api/cropImageCept.php, (*35)

getLocalFileByUrl - Get local file by URL

GET index.php?action=getlocalfilebyurl&source=:source&path=:path&url=:url
  • [:source=default] - key from config (ex. from Joomla config - `joomla Media)
  • [:path=source.root] - relative path for source.root.
  • :url - Full fil url for source

See tests/api/getlocalFileByURLCept.php Example:, (*36)

index.php?action=getLocalFileByUrl&source=test&url=http://localhost:8181/tests/files/artio.jpg

Answer JSON example:, (*37)

{
    "success": true,
    "time": "2017-07-10 17:34:29",
    "data": {
        "path": "",
        "name": "artio.jpg",
        "code": 220
    }
}

Road map

  • [x] Cross Origin requests
  • [ ] Add pagination
  • [ ] Create FTP/SFTP sources
  • [ ] Create image filters (noise, gray scale etc.)

Contacts

The Versions

05/03 2018

dev-master

9999999-dev

Jodit FileBrowser and Uploader connector

  Sources   Download

MIT

The Requires

 

The Development Requires

05/03 2018

3.0.29

3.0.29.0

Jodit FileBrowser and Uploader connector

  Sources   Download

MIT

The Requires

 

14/12 2017

3.0.28

3.0.28.0

Jodit FileBrowser and Uploader connector

  Sources   Download

MIT

The Requires

 

14/12 2017

3.0.27

3.0.27.0

Jodit FileBrowser and Uploader connector

  Sources   Download

MIT

The Requires

 

14/12 2017

3.0.26

3.0.26.0

Jodit FileBrowser and Uploader connector

  Sources   Download

MIT

The Requires

 

14/12 2017

3.0.25

3.0.25.0

Jodit FileBrowser and Uploader connector

  Sources   Download

MIT

The Requires

 

11/12 2017

3.0.24

3.0.24.0

Jodit FileBrowser and Uploader connector

  Sources   Download

MIT

The Requires

 

The Development Requires

11/12 2017

3.0.23

3.0.23.0

Jodit FileBrowser and Uploader connector

  Sources   Download

MIT

The Requires

 

The Development Requires

11/12 2017

3.0.22

3.0.22.0

Jodit FileBrowser and Uploader connector

  Sources   Download

MIT

The Requires

 

The Development Requires

07/12 2017

3.0.21

3.0.21.0

Jodit FileBrowser and Uploader connector

  Sources   Download

MIT

The Requires

 

The Development Requires

05/12 2017

3.0.20

3.0.20.0

Jodit FileBrowser and Uploader connector

  Sources   Download

MIT

The Requires

 

The Development Requires

05/12 2017

3.0.19

3.0.19.0

Jodit FileBrowser and Uploader connector

  Sources   Download

MIT

The Requires

 

The Development Requires

05/12 2017

3.0.18

3.0.18.0

Jodit FileBrowser and Uploader connector

  Sources   Download

MIT

The Requires

 

The Development Requires

05/12 2017

3.0.17

3.0.17.0

Jodit FileBrowser and Uploader connector

  Sources   Download

MIT

The Requires

 

The Development Requires

05/12 2017

3.0.16

3.0.16.0

Jodit FileBrowser and Uploader connector

  Sources   Download

MIT

The Requires

 

The Development Requires

04/09 2017

3.0.15

3.0.15.0

Jodit FileBrowser and Uploader connector

  Sources   Download

MIT

The Requires

 

The Development Requires

04/09 2017

3.0.14

3.0.14.0

Jodit FileBrowser and Uploader connector

  Sources   Download

MIT

The Requires

 

The Development Requires

14/07 2017

3.0.2

3.0.2.0

Jodit FileBrowser and Uploader connector

  Sources   Download

MIT

The Requires

 

The Development Requires

10/07 2017

3.0.0

3.0.0.0

Jodit FileBrowser and Uploader connector

  Sources   Download

MIT

The Requires

 

The Development Requires

30/06 2016

1.1.1

1.1.1.0

Jodit FileBrowser and Uploader connector

  Sources   Download

MIT

The Requires

 

28/04 2016

1.1.0

1.1.0.0

Jodit FileBrowser and Uploader connector

  Sources   Download

MIT

The Requires

 

29/02 2016

1.0.8

1.0.8.0

Jodit FileBrowser and Uploader connector

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

27/02 2016

1.0.7

1.0.7.0

Jodit FileBrowser and Uploader connector

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

27/02 2016

1.0.6

1.0.6.0

Jodit FileBrowser and Uploader connector

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

21/02 2016

1.0.5

1.0.5.0

Jodit FileBrowser and Uploader connector

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

18/02 2016

1.0.2

1.0.2.0

Jodit FileBrowser and Uploader connector

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

18/02 2016

1.0.1

1.0.1.0

Jodit FileBrowser and Uploader connector

  Sources   Download

MIT

The Requires

  • php >=5.3.0