-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
38 changed files
with
1,889 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
Software License Agreement | ||
========================== | ||
|
||
Copyright (c) 2015, CKSource - Frederico Knabben. All rights reserved. | ||
|
||
CKFinder bundle for Symfony is licensed under the terms of the MIT license (see Appendix A). | ||
|
||
Trademarks | ||
---------- | ||
|
||
CKFinder is a trademark of CKSource - Frederico Knabben. All other brand | ||
and product names are trademarks, registered trademarks or service | ||
marks of their respective holders. | ||
|
||
Sources of Intellectual Property required by bundle. | ||
---------------------------------------------------- | ||
|
||
The installation instruction requires user to run the following command to download | ||
CKFinder separately (the file manager itself): | ||
|
||
```bash | ||
php bin/console ckfinder:download | ||
``` | ||
|
||
The downloaded CKFinder distribution is licensed under a separate CKFinder License. | ||
|
||
--- | ||
|
||
Appendix A: The MIT License | ||
--------------------------- | ||
|
||
The MIT License (MIT) | ||
|
||
Copyright (c) 2015, CKSource - Frederico Knabben | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,214 @@ | ||
CKFinder 3 Bundle for Symfony | ||
=============================== | ||
|
||
[![Continuous Integration](https://github.com/Kocal/ckfinder-symfony-bundle/actions/workflows/continuous-integration.yaml/badge.svg)](https://github.com/Kocal/ckfinder-symfony-bundle/actions/workflows/continuous-integration.yaml) | ||
[![kocal/ckfinder-symfony-bundle](https://img.shields.io/packagist/v/kocal/ckfinder-symfony-bundle)](https://packagist.org/packages/kocal/ckfinder-symfony-bundle) | ||
|
||
> :information_source: This project is a fork of [the official and _abandoned_ CKFinder Symfony Bundle](https://github.com/ckfinder/ckfinder-symfony-bundle). | ||
> | ||
> This bundle is fully compatible with Symfony 6.0 and more (Symfony 3 and 4 have been removed, see [branch `1.x` for Symfony 5.4 support](https://github.com/Kocal/ckfinder-symfony-bundle/tree/1.x)), compatible with PHP 8.1+, Flysystem 3+, | ||
> and use many tools to ensure the code quality ([PHPUnit](https://github.com/sebastianbergmann/phpunit), [Easy Coding Standard](https://github.com/symplify/easy-coding-standard) and [Rector](https://github.com/rectorphp/rector)) with a functional CI. | ||
## Installation | ||
|
||
1. Add Composer dependency and install the bundle. | ||
|
||
```bash | ||
composer require kocal/ckfinder-symfony-bundle | ||
``` | ||
|
||
2. Run the command to download the CKFinder distribution package. | ||
|
||
After installing the bundle you need to download CKFinder distribution package. It is not shipped | ||
with the bundle due to different license terms. To install it, run the following Symfony command: | ||
|
||
```bash | ||
php bin/console ckfinder:download | ||
``` | ||
|
||
It will download the code and place it in the `Resource/public` directory of the bundle. After that you may also want to install | ||
assets, so the public directory will be updated with CKFinder code. | ||
|
||
```bash | ||
php bin/console assets:install | ||
``` | ||
|
||
3. Enable bundle routing. | ||
|
||
Create `config/routes/ckfinder.yaml` with following contents: | ||
|
||
```yaml | ||
# config/routes/ckfinder.yaml | ||
|
||
ckfinder_connector: | ||
resource: "@CKSourceCKFinderBundle/Resources/config/routing.yaml" | ||
prefix: / | ||
``` | ||
|
||
|
||
4. Create a directory for CKFinder files and allow for write access to it. By default CKFinder expects it to be placed in `<public folder>/userfiles` (this can be altered in configuration). | ||
|
||
```bash | ||
mkdir -m 777 public/userfiles | ||
``` | ||
|
||
|
||
**NOTE:** Since usually setting permissions to 0777 is insecure, it is advisable to change the group ownership of the directory to the same user as Apache and add group write permissions instead. Please contact your system administrator in case of any doubts. | ||
|
||
At this point you should see the connector JSON response after navigating to the `/ckfinder/connector?command=Init` route. | ||
Authentication for CKFinder is not configured yet, so you will see an error response saying that CKFinder is not enabled. | ||
|
||
## Configuring Authentication | ||
|
||
CKFinder connector authentication is managed by the `ckfinder.connector.auth` service, which by default is defined in | ||
the `CKSourceCKFinderBundle\Authentication\Authentication` class. It contains the `authenticate` method that should return a Boolean value to decide if the user should have access to CKFinder. | ||
As you can see the default service implementation is not complete and simply returns `false` inside the `authenticate` method, | ||
but you can find it useful as a starting stub code. | ||
|
||
To configure authentication for the CKFinder connector you need to create a class that implements `CKSource\Bundle\CKFinderBundle\Authentication\AuthenticationInterface`, | ||
and point the CKFinder connector to use it. | ||
|
||
A basic implementation that returns `true` from the `authenticate` method (which is obviously **not secure**) can look like below: | ||
|
||
**Symfony 5+** | ||
|
||
```php | ||
// src/CustomCKFinderAuth/CustomCKFinderAuth.php | ||
|
||
namespace App\CustomCKFinderAuth; | ||
|
||
use CKSource\Bundle\CKFinderBundle\Authentication\Authentication as AuthenticationBase; | ||
|
||
class CustomCKFinderAuth extends AuthenticationBase | ||
{ | ||
public function authenticate() | ||
{ | ||
return true; | ||
} | ||
} | ||
``` | ||
|
||
You may have noticed that `AuthenticationInterface` extends `ContainerAwareInterface`, so you have access to the service | ||
container from the authentication class scope. | ||
|
||
When your custom authentication is ready, you need to tell the CKFinder connector to start using it. To do that add the following option to your configuration: | ||
|
||
**Symfony 5+** | ||
|
||
Create `config/packages/ckfinder.yaml` file: | ||
|
||
```yaml | ||
# config/packages/ckfinder.yaml | ||
|
||
ckfinder: | ||
connector: | ||
authenticationClass: App\CustomCKFinderAuth\CustomCKFinderAuth | ||
``` | ||
## Configuration Options | ||
The default CKFinder connector configuration is taken from the `@CKSourceCKFinder/Resources/config/ckfinder_config.php` file. | ||
Thanks to the Symfony configuration merging mechanism there are multiple ways you can overwrite it. The default configuration | ||
is provided in form of a regular PHP file, but you can use the format you prefer (YAML, XML) as long as the structure is valid. | ||
|
||
The simplest way to overwrite the default configuration is copying the `ckfinder_config.php` file to your application config | ||
directory, and then importing it in the main configuration file: | ||
|
||
**Symfony 5+** | ||
|
||
```yaml | ||
# config/packages/ckfinder.yaml | ||
imports: | ||
- { resource: ckfinder_config.php } | ||
... | ||
``` | ||
|
||
From now all connector configuration options will be taken from copied `ckfinder_config.php`. | ||
|
||
Another way to configure CKFinder is to include required options under the `ckfinder` node, directly in your config file. | ||
|
||
**Symfony 5+** | ||
|
||
```yaml | ||
# config/packages/ckfinder.yaml | ||
ckfinder: | ||
connector: | ||
licenseName: LICENSE-NAME | ||
licenseKey: LICENSE-KEY | ||
authenticationClass: AppBundle\CustomCKFinderAuth\CustomCKFinderAuth | ||
resourceTypes: | ||
MyResource: | ||
name: MyResource | ||
backend: default | ||
directory: myResource | ||
``` | ||
|
||
**Note**: All options that are not defined will be taken from the default configuration file. | ||
|
||
To find out more about possible connector configuration options please refer to [CKFinder 3 – PHP Connector Documentation](https://ckeditor.com/docs/ckfinder/ckfinder3-php/configuration.html). | ||
|
||
The CKFinder bundle provides two extra options: | ||
- `authenticationClass` – the name of the CKFinder authentication service class (defaults to `CKSource\Bundle\CKFinderBundle\Authentication\Authentication`) | ||
- `connectorClass` – the name of the CKFinder connector service class (defaults to `CKSource\CKFinder\CKFinder`) | ||
|
||
## Usage | ||
|
||
The bundle code contains a few usage examples that you may find useful. To enable them uncomment the `ckfinder_examples` | ||
route in `@CKSourceCKFinder/Resources/config/routing.yaml`: | ||
|
||
```yaml | ||
ckfinder_examples: | ||
pattern: /ckfinder/examples/{example} | ||
defaults: { _controller: CKSource\Bundle\CKFinderBundle\Controller::examplesAction, example: null } | ||
``` | ||
|
||
After that you can navigate to the `/ckfinder/examples` path and have a look at the list of available examples. To find out about the code behind them, check the `CKFinderController` class (`CKSourceCKFinderBundle::Controller/CKFinderController.php`). | ||
|
||
### Including the Main CKFinder JavaScript File in Templates | ||
|
||
The preferred way to include `ckfinder.js` in a template is including the CKFinder setup template, like presented below: | ||
|
||
```twig | ||
{% include "@CKSourceCKFinder/setup.html.twig" %} | ||
``` | ||
|
||
The included template renders the required `script` tags and configures a valid connector path. | ||
|
||
```html | ||
<script type="text/javascript" src="/bundles/cksourceckfinder/ckfinder/ckfinder.js"></script> | ||
<script>CKFinder.config( { connectorPath: '/ckfinder/connector' } );</script> | ||
``` | ||
|
||
### CKFinder File Chooser | ||
|
||
The bundle registers a form field type — `CKFinderFileChooserType` — that allows for easy integration of CKFinder as a file chooser in your forms. | ||
After choosing the file in CKFinder the corresponding input field is automaticaly filled with the file URL. You can see a working example under the `/ckfinder/examples/filechooser` path. | ||
|
||
The file chooser field is built on top of the regular `text` type, so it inherits all configuration options. It also provides a few custom options: | ||
|
||
Name | Type | Default Value | Description | ||
---------------|-----------|---------------|------------- | ||
`mode` | `string` | `popup` | Mode in which CKFinder will be opened after clicking the "Browse" button. Allowed values are `modal` and `popup`. | ||
`button_text` | `string` | `Browse` | The text displayed in the button. | ||
`button_attr` | `array` | `[]` | Attributes for the button element. | ||
|
||
A simple usage example may look like below: | ||
|
||
```php | ||
$form = $this | ||
->createFormBuilder() | ||
->add('file_chooser1', CKFinderFileChooserType::class, [ | ||
'label' => 'Photo', | ||
'button_text' => 'Browse photos', | ||
'button_attr' => [ | ||
'class' => 'my-fancy-class' | ||
] | ||
]) | ||
->getForm(); | ||
``` | ||
|
||
**Note**: To use CKFinder file chooser in your forms you still need to include the main CKFinder JavaScript file in your template (see *Including the main CKFinder JavaScript file in templates*). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
{ | ||
"name": "bsdrazor/ckfinder-symfony-bundle", | ||
"description": "CKFinder bundle for Symfony 7+", | ||
"type": "symfony-bundle", | ||
"license": "MIT", | ||
"authors": [ | ||
{ | ||
"name": "CKSource", | ||
"homepage": "http://cksource.com" | ||
}, | ||
{ | ||
"name": "BsdRazor", | ||
"email": "[email protected]" | ||
} | ||
], | ||
"require": { | ||
"php": ">=8.1", | ||
"ext-zip": "*", | ||
"league/flysystem": "^3.0", | ||
"league/flysystem-aws-s3-v3": "^3.0.1", | ||
"league/flysystem-ftp": "^3.0", | ||
"symfony/framework-bundle": "^7.1", | ||
"symfony/form": "^7.1", | ||
"symfony/finder": "^7.1", | ||
"symfony/console": "^7.1", | ||
"symfony/mime": "^v7.1", | ||
"symfony/http-client": "^7.1", | ||
"pimple/pimple": "^3.0", | ||
"monolog/monolog": "^3.0", | ||
"ext-json": "*", | ||
"ext-gd": "*", | ||
"ext-zip": "*" | ||
}, | ||
"require-dev": { | ||
"friendsofphp/php-cs-fixer": "^3.11", | ||
"symplify/easy-coding-standard": "^10.1", | ||
"symfony/yaml": "^6.0", | ||
"rector/rector": "^0.14.2", | ||
"phpstan/phpstan": "^1.8", | ||
"phpstan/phpstan-phpunit": "^1.0", | ||
"phpunit/phpunit": "^9.5", | ||
"aws/aws-sdk-php": "^3.269.8" | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"CKSource\\Bundle\\CKFinderBundle\\": "src", | ||
"CKSource\\CKFinder\\": "src/_connector" | ||
} | ||
}, | ||
"autoload-dev": { | ||
"psr-4": { | ||
"CKSource\\Bundle\\CKFinderBundle\\Tests\\": "tests" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.5/phpunit.xsd" | ||
bootstrap="vendor/autoload.php" | ||
cacheResultFile=".cache/phpunit/test-results" | ||
executionOrder="depends,defects" | ||
forceCoversAnnotation="false" | ||
beStrictAboutCoversAnnotation="true" | ||
beStrictAboutOutputDuringTests="true" | ||
beStrictAboutTodoAnnotatedTests="true" | ||
convertDeprecationsToExceptions="true" | ||
failOnRisky="true" | ||
failOnWarning="true" | ||
verbose="true"> | ||
<testsuites> | ||
<testsuite name="default"> | ||
<directory>tests</directory> | ||
</testsuite> | ||
</testsuites> | ||
|
||
<coverage cacheDirectory=".cache/phpunit/code-coverage" | ||
processUncoveredFiles="true"> | ||
<include> | ||
<directory suffix=".php">src</directory> | ||
</include> | ||
</coverage> | ||
</phpunit> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use Rector\Config\RectorConfig; | ||
use Rector\Set\ValueObject\LevelSetList; | ||
use Rector\Set\ValueObject\SetList; | ||
|
||
return static function (RectorConfig $rectorConfig): void { | ||
$rectorConfig->paths([ | ||
__DIR__ . '/src', | ||
__DIR__ . '/tests', | ||
__DIR__ . '/playground/symfony-6.0/src', | ||
__DIR__ . '/playground/symfony-6.1/src', | ||
__DIR__ . '/playground/symfony-6.2/src', | ||
]); | ||
|
||
$rectorConfig->skip([ | ||
__DIR__ . '/src/_connector', | ||
]); | ||
|
||
// Define what rule sets will be applied | ||
$rectorConfig->sets([ | ||
LevelSetList::UP_TO_PHP_80, | ||
SetList::TYPE_DECLARATION, | ||
SetList::TYPE_DECLARATION_STRICT, | ||
SetList::CODE_QUALITY, | ||
SetList::DEAD_CODE, | ||
]); | ||
|
||
// get services (needed for register a single rule) | ||
// $services = $containerConfigurator->services(); | ||
|
||
// register a single rule | ||
// $services->set(TypedPropertyRector::class); | ||
}; |
Oops, something went wrong.