Skip to content

Commit

Permalink
Bump required PHP version + minor CS improvements.
Browse files Browse the repository at this point in the history
  • Loading branch information
rob006 committed Sep 7, 2019
1 parent ed349dc commit c9a63ce
Show file tree
Hide file tree
Showing 12 changed files with 173 additions and 197 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ CHANGELOG
-------------------------

- Update elFinder to 2.1.50.
- Bump required PHP version to 5.4.


1.1.2 (2017-06-04)
Expand Down
15 changes: 8 additions & 7 deletions ElFinderConnectorAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,27 @@
class ElFinderConnectorAction extends CAction {

/**
* Connector configuration
* Connector configuration.
*
* @see https://github.com/Studio-42/elFinder/wiki/Connector-configuration-options
* @var array
*/
public $settings = array();
public $settings = [];

public function run() {
require_once dirname(__FILE__) . '/ElFinderHelper.php';
require_once __DIR__ . '/ElFinderHelper.php';
$assetsDir = ElFinderHelper::getAssetsDir();
// @todo seems to be unused?
define('ELFINDER_IMG_PARENT_URL', $assetsDir);

Yii::import('elFindervendor.php.elFinderSession');
Yii::import('elFindervendor.php.elFinderSessionInterface');

$php_path = Yii::getPathOfAlias('elFindervendor.php');
require_once($php_path . '/autoload.php');
$phpPath = Yii::getPathOfAlias('elFindervendor.php');
require_once $phpPath . '/autoload.php';

header("Content-Type: application/json");
header('Content-Type: application/json');
$fm = new elFinderConnector(new elFinder($this->settings));
$fm->run();
}

}
19 changes: 9 additions & 10 deletions ElFinderHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@ class ElFinderHelper extends CComponent {

/**
* Available elFinder translations.
*
* @see directory: vendor/assets/js/i18n
* @var array
*/
public static $availableLanguages = array(
public static $availableLanguages = [
'ar',
'bg',
'ca',
Expand Down Expand Up @@ -49,11 +50,8 @@ class ElFinderHelper extends CComponent {
'vi',
'zh_CN',
'zh_TW',
);

/**
* @var string
*/
];
/** @var string */
private static $_assetsDir;

/**
Expand Down Expand Up @@ -84,10 +82,10 @@ public static function registerAssets() {

// elFinder translation
$lang = Yii::app()->language;
if (!in_array($lang, self::$availableLanguages)) {
if (!in_array($lang, self::$availableLanguages, true)) {
if (strpos($lang, '_')) {
$lang = substr($lang, 0, strpos($lang, '_'));
if (!in_array($lang, self::$availableLanguages)) {
if (!in_array($lang, self::$availableLanguages, true)) {
$lang = false;
}
} else {
Expand All @@ -102,7 +100,7 @@ public static function registerAssets() {
Yii::app()->clientScript->registerCss(
'elfinder-file-bg-fixer',
'.elfinder-cwd-file,.elfinder-cwd-file .elfinder-cwd-file-wrapper,.elfinder-cwd-file .elfinder-cwd-filename{background-image:none !important;}'
.'.elfinder-resize-preview{max-width: 50%}'
. '.elfinder-resize-preview{max-width: 50%}'
);
}

Expand All @@ -111,7 +109,7 @@ public static function registerAssets() {
*/
public static function registerAlias() {
if (!Yii::getPathOfAlias('elFinder')) {
Yii::setPathOfAlias('elFinder', dirname(__FILE__));
Yii::setPathOfAlias('elFinder', __DIR__);
}
if (!Yii::getPathOfAlias('elFindervendor')) {
Yii::setPathOfAlias('elFindervendor', Yii::getPathOfAlias('elFinder.vendor'));
Expand All @@ -120,6 +118,7 @@ public static function registerAlias() {

/**
* Register assets directory and return assets url path.
*
* @return string
*/
public static function getAssetsDir() {
Expand Down
25 changes: 9 additions & 16 deletions ElFinderWidget.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,18 @@ class ElFinderWidget extends CWidget {

/**
* Client settings.
*
* @see https://github.com/Studio-42/elFinder/wiki/Client-configuration-options
* @var array
*/
public $settings = array();

/**
*
* @var string
*/
public $settings = [];
/** @var string */
public $connectorRoute = false;

/**
* @var array
*/
public $connectorParams = array();
/** @var array */
public $connectorParams = [];

public function run() {
require_once dirname(__FILE__) . '/ElFinderHelper.php';
require_once __DIR__ . '/ElFinderHelper.php';
ElFinderHelper::registerAssets();

// set required options
Expand All @@ -40,16 +34,15 @@ public function run() {
$this->settings['lang'] = Yii::app()->language;

if (Yii::app()->getRequest()->enableCsrfValidation) {
$this->settings['customData'] = array(
$this->settings['customData'] = [
Yii::app()->request->csrfTokenName => Yii::app()->request->csrfToken,
);
];
}

$id = $this->getId();
$settings = CJavaScript::encode($this->settings);
$cs = Yii::app()->getClientScript();
$cs->registerScript("elFinder#$id", "$('#$id').elfinder($settings);");
echo CHtml::tag('div', array('id' => $id), '');
echo CHtml::tag('div', ['id' => $id], '');
}

}
141 changes: 70 additions & 71 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ How to use
You can use custom elFinder code, just set `elFindervendor` alias to point your elFinder code directory.

```php
'aliases' => array(
'elFindervendor' => 'vendor.myCystomElFinder',
),
'aliases' => [
'elFindervendor' => 'vendor.myCystomElFinder',
],
```

You can get elFinder from https://github.com/Studio-42/elFinder/releases - remember to move `css`, `img`, `js`
Expand All @@ -24,88 +24,87 @@ How to use

```php
class ElfinderController extends Controller {

// don't forget configure access rules

public function actions() {
return array(
// main action for elFinder connector
'connector' => array(
'class' => 'ext.elFinder.ElFinderConnectorAction',
// elFinder connector configuration
// https://github.com/Studio-42/elFinder/wiki/Connector-configuration-options
'settings' => array(
'roots' => array(
array(
'driver' => 'LocalFileSystem',
'path' => Yii::getPathOfAlias('webroot') . '/files/',
'URL' => Yii::app()->baseUrl . '/files/',
'alias' => 'Root Alias',
'acceptedName' => '/^[^\.].*$/', // disable creating dotfiles
'attributes' => array(
array(
'pattern' => '/\/[.].*$/', // hide dotfiles
'read' => false,
'write' => false,
'hidden' => true,
),
),
)
),
)
),
// action for TinyMCE popup with elFinder widget
'elfinderTinyMce' => array(
'class' => 'ext.elFinder.TinyMceElFinderPopupAction',
'connectorRoute' => 'connector', // main connector action id
),
// action for file input popup with elFinder widget
'elfinderFileInput' => array(
'class' => 'ext.elFinder.ServerFileInputElFinderPopupAction',
'connectorRoute' => 'connector', // main connector action id
),
);
}


// don't forget configure access rules

public function actions() {
return [
// main action for elFinder connector
'connector' => [
'class' => 'ext.elFinder.ElFinderConnectorAction',
// elFinder connector configuration
// https://github.com/Studio-42/elFinder/wiki/Connector-configuration-options
'settings' => [
'roots' => [
[
'driver' => 'LocalFileSystem',
'path' => Yii::getPathOfAlias('webroot') . '/files/',
'URL' => Yii::app()->baseUrl . '/files/',
'alias' => 'Root Alias',
'acceptedName' => '/^[^\.].*$/', // disable creating dotfiles
'attributes' => [
[
'pattern' => '/\/[.].*$/', // hide dotfiles
'read' => false,
'write' => false,
'hidden' => true,
],
],
],
],
],
],
// action for TinyMCE popup with elFinder widget
'elfinderTinyMce' => [
'class' => 'ext.elFinder.TinyMceElFinderPopupAction',
'connectorRoute' => 'connector', // main connector action id
],
// action for file input popup with elFinder widget
'elfinderFileInput' => [
'class' => 'ext.elFinder.ServerFileInputElFinderPopupAction',
'connectorRoute' => 'connector', // main connector action id
],
];
}
}
```

3. ServerFileInput - use this widget to choose file on server using elFinder pop-up

```php
$this->widget('ext.elFinder.ServerFileInput', array(
'model' => $model,
'attribute' => 'field_name',
'popupConnectorRoute' => 'elfinder/elfinderFileInput', // relative route for file input action
// ability to customize "Browse" button
// 'customButton' => TbHtml::button('Browse images', array(
// 'id' => TbHtml::getIdByName(TbHtml::activeName($model, 'field_name')) . 'browse',
// 'class' => 'btn', 'color' => TbHtml::BUTTON_COLOR_DEFAULT,
// 'size' => TbHtml::BUTTON_SIZE_DEFAULT, 'style' => 'margin-left:10px;')),
// title for popup window (optional)
'popupTitle' => 'Files',
));
$this->widget('ext.elFinder.ServerFileInput', [
'model' => $model,
'attribute' => 'field_name',
'popupConnectorRoute' => 'elfinder/elfinderFileInput', // relative route for file input action
// ability to customize "Browse" button
// 'customButton' => CHtml::button('Browse images', [
// 'id' => CHtml::getIdByName(CHtml::activeName($model, 'field_name')) . 'browse',
// 'class' => 'btn', 'style' => 'margin-left:10px',
// ]),
// title for popup window (optional)
'popupTitle' => 'Files',
]);
```

4. ElFinderWidget - use this widget to manage files

```php
$this->widget('ext.elFinder.ElFinderWidget', array(
'connectorRoute' => 'elfinder/connector', // relative route for elFinder connector action
));
$this->widget('ext.elFinder.ElFinderWidget', [
'connectorRoute' => 'elfinder/connector', // relative route for elFinder connector action
]);
```

5. TinyMceElFinder - use this widget to integrate elFinder with [yii-tinymce](https://github.com/rob006/yii-tinymce)

```php
$this->widget('ext.tinymce.TinyMce', array(
'model' => $model,
'attribute' => 'content',
'fileManager' => array(
'class' => 'ext.elFinder.TinyMceElFinder',
'popupConnectorRoute' => 'elfinder/elfinderTinyMce', // relative route for TinyMCE popup action
// title for popup window (optional)
'popupTitle' => "Files",
),
));
$this->widget('ext.tinymce.TinyMce', [
'model' => $model,
'attribute' => 'content',
'fileManager' => [
'class' => 'ext.elFinder.TinyMceElFinder',
'popupConnectorRoute' => 'elfinder/elfinderTinyMce', // relative route for TinyMCE popup action
// title for popup window (optional)
'popupTitle' => 'Files',
],
]);
```
Loading

0 comments on commit c9a63ce

Please sign in to comment.