From 62e0ff9c5a947ecf550a3c4518bc80d869d73d02 Mon Sep 17 00:00:00 2001 From: puneet0191 Date: Wed, 6 Sep 2017 00:49:50 +0530 Subject: [PATCH 01/12] Changes in Composer.json to load SDK --- composer.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index e13cb1a..68c099a 100644 --- a/composer.json +++ b/composer.json @@ -29,8 +29,9 @@ ], "require": { "yiisoft/yii2": "^2.0", - "froala/wysiwyg-editor": "^2.6.0", - "rmrevin/yii2-fontawesome": "^2.0" + "bower-asset/froala-wysiwyg-editor": "^2.6.0", + "rmrevin/yii2-fontawesome": "*", + "froala/wysiwyg-editor-php-sdk": "*" }, "autoload": { "psr-4": { From eb18901ca5522c8ae33f63cc15edb0abc4c675ed Mon Sep 17 00:00:00 2001 From: puneet0191 Date: Wed, 6 Sep 2017 00:50:17 +0530 Subject: [PATCH 02/12] Adding imageUploadURL config in widget function --- src/FroalaEditorWidget.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/FroalaEditorWidget.php b/src/FroalaEditorWidget.php index d16eecc..43bb6cc 100644 --- a/src/FroalaEditorWidget.php +++ b/src/FroalaEditorWidget.php @@ -110,4 +110,14 @@ public function registerClientScript() $view->registerJs("\$('#$id').froalaEditor($jsOptions);"); } + + public static function widget($config = []) + { + if (!isset($config['clientOptions']['imageUploadURL'])) + { + $config['clientOptions']['imageUploadURL'] = \yii\helpers\Url::to(['froala/default/upload']); + } + + return parent::widget($config); + } } From 2d5eeffb8b4756c7659bd3fe21681c997db067b7 Mon Sep 17 00:00:00 2001 From: puneet0191 Date: Wed, 6 Sep 2017 00:50:35 +0530 Subject: [PATCH 03/12] Creating a Module for Froala Editor --- src/Module.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100755 src/Module.php diff --git a/src/Module.php b/src/Module.php new file mode 100755 index 0000000..613d5c7 --- /dev/null +++ b/src/Module.php @@ -0,0 +1,13 @@ + Date: Wed, 6 Sep 2017 00:51:37 +0530 Subject: [PATCH 04/12] Adding Controller, with UploadAction which used the SDK upload method --- src/controllers/DefaultController.php | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100755 src/controllers/DefaultController.php diff --git a/src/controllers/DefaultController.php b/src/controllers/DefaultController.php new file mode 100755 index 0000000..4c18909 --- /dev/null +++ b/src/controllers/DefaultController.php @@ -0,0 +1,26 @@ +module->uploadFolder; + + $response = \FroalaEditor_Image::upload($uploadFolder); + echo stripslashes(json_encode($response)); + } + catch (Exception $e) { + http_response_code(404); + } + + } +} From 6e9f38e40992dc5cf7e30cd1cedb19856d08c269 Mon Sep 17 00:00:00 2001 From: puneet0191 Date: Wed, 6 Sep 2017 10:42:00 +0530 Subject: [PATCH 05/12] Minor changes in composer --- composer.json | 1 - src/controllers/DefaultController.php | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 68c099a..505c463 100644 --- a/composer.json +++ b/composer.json @@ -29,7 +29,6 @@ ], "require": { "yiisoft/yii2": "^2.0", - "bower-asset/froala-wysiwyg-editor": "^2.6.0", "rmrevin/yii2-fontawesome": "*", "froala/wysiwyg-editor-php-sdk": "*" }, diff --git a/src/controllers/DefaultController.php b/src/controllers/DefaultController.php index 4c18909..b926937 100755 --- a/src/controllers/DefaultController.php +++ b/src/controllers/DefaultController.php @@ -7,7 +7,7 @@ class DefaultController extends Controller { // Without false it will give "Bad Request (#400) Unable to verify your data submission." - public $enableCsrfValidation = false; + public $enableCsrfValidation = false; public function actionUpload() { From 0019b0848f619e5c28452221cfb871e63494e931 Mon Sep 17 00:00:00 2001 From: puneet0191 Date: Wed, 6 Sep 2017 11:39:56 +0530 Subject: [PATCH 06/12] revert b ack version change --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 505c463..02c12cb 100644 --- a/composer.json +++ b/composer.json @@ -29,7 +29,7 @@ ], "require": { "yiisoft/yii2": "^2.0", - "rmrevin/yii2-fontawesome": "*", + "rmrevin/yii2-fontawesome": "^2.0", "froala/wysiwyg-editor-php-sdk": "*" }, "autoload": { From 99004528ab015923fde2ef38005c5e7dbfff2250 Mon Sep 17 00:00:00 2001 From: puneet0191 Date: Wed, 6 Sep 2017 19:38:21 +0530 Subject: [PATCH 07/12] Changes in readme --- README.md | 76 +++++++++++++------------------------------------------ 1 file changed, 17 insertions(+), 59 deletions(-) diff --git a/README.md b/README.md index e7827ae..7691722 100644 --- a/README.md +++ b/README.md @@ -7,18 +7,23 @@ ## Installation -The preferred way to install this extension is through [composer](http://getcomposer.org/download/). +The preferred way to install this extension is through [composer](http://getcomposer.org/download/). yii2-froala editor depends on Froala PHP SDK +To use and Install the editor, one must install PHP SDK also. Either run ``` php composer.phar require --prefer-dist froala/yii2-froala-editor +php composer.phar require --prefer-dist froala/wysiwyg-editor-php-sdk + ``` or add ``` -"froala/yii2-froala-editor": "^2.6.0" +"froala/yii2-froala-editor": "^2.6.0", +"froala/wysiwyg-editor-php-sdk" : "*" + ``` to the require section of your `composer.json` file. @@ -63,65 +68,19 @@ or use with a model: ## Upload example -Using the basic Yii template make a new folder under /web/ called uploads. - -For controler: - -```php -public function actionUpload() { - $base_path = Yii::getAlias('@app'); - $web_path = Yii::getAlias('@web'); - $model = new UploadForm(); - - if (Yii::$app->request->isPost) { - $model->file = UploadedFile::getInstanceByName('file'); - - if ($model->validate()) { - $model->file->saveAs($base_path . '/web/uploads/' . $model->file->baseName . '.' . $model->file->extension); - } - } - - // Get file link - $res = [ - 'link' => $web_path . '/uploads/' . $model->file->baseName . '.' . $model->file->extension, - ]; - - // Response data - Yii::$app->response->format = Yii::$app->response->format = Response::FORMAT_JSON; - return $res; -} -``` - -For model: +Using the Froala PHP SDK with Froala Editor widget, the first step would be to add the configuration in web.php config file, make an entry for Froala Module +in the Config Array. ```php -namespace app\models; -use yii\base\Model; -use yii\web\UploadedFile; - -/** - * UploadForm is the model behind the upload form. - */ -class UploadForm extends Model -{ - /** - * @var UploadedFile|Null file attribute - */ - public $file; - - /** - * @return array the validation rules. - */ - public function rules() - { - return [ - [['file'], 'file'] - ]; - } -} +'modules' => [ + 'froala' => [ + 'class' => '\froala\froalaeditor\Module', + 'uploadFolder' => '/uploads/' + ] + ], ``` -For the view: +Make sure you have a folder called "uploads" in your web root directory,Now to use the Froala Widget on any view just use the following code in the view: ```php 'royal',//optional: dark, red, gray, royal 'language' => 'en_gb' , 'toolbarButtons' => ['fullscreen', 'bold', 'italic', 'underline', '|', 'paragraphFormat', 'insertImage'], - 'imageUploadParam' => 'file', - 'imageUploadURL' => \yii\helpers\Url::to(['site/upload/']) + 'imageUploadParam' => 'file' ], 'clientPlugins'=> ['fullscreen', 'paragraph_format', 'image'] ]); ?> From e963fd4fa636813957f0b9b0ed13f2a67fce3f6f Mon Sep 17 00:00:00 2001 From: puneet0191 Date: Wed, 6 Sep 2017 19:40:26 +0530 Subject: [PATCH 08/12] More updates --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 7691722..9b3d46a 100644 --- a/README.md +++ b/README.md @@ -15,6 +15,7 @@ Either run ``` php composer.phar require --prefer-dist froala/yii2-froala-editor php composer.phar require --prefer-dist froala/wysiwyg-editor-php-sdk +php composer.phar require --prefer-dist bower-asset/froala-wysiwyg-editor ``` @@ -22,7 +23,8 @@ or add ``` "froala/yii2-froala-editor": "^2.6.0", -"froala/wysiwyg-editor-php-sdk" : "*" +"froala/wysiwyg-editor-php-sdk" : "*", +"bower-asset/froala-wysiwyg-editor": "^2.6.0" ``` From be3f28837134dcce062a685504e6b6a59f08a55d Mon Sep 17 00:00:00 2001 From: puneet0191 Date: Wed, 6 Sep 2017 19:41:05 +0530 Subject: [PATCH 09/12] Updating Composer.json --- composer.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 02c12cb..e5197b0 100644 --- a/composer.json +++ b/composer.json @@ -30,7 +30,8 @@ "require": { "yiisoft/yii2": "^2.0", "rmrevin/yii2-fontawesome": "^2.0", - "froala/wysiwyg-editor-php-sdk": "*" + "froala/wysiwyg-editor-php-sdk": "*", + "bower-asset/froala-wysiwyg-editor": "^2.6.0" }, "autoload": { "psr-4": { From 87d30e1fb81ca1353933123b0f6d182d53bb47e8 Mon Sep 17 00:00:00 2001 From: puneet0191 Date: Tue, 12 Sep 2017 13:26:20 +0530 Subject: [PATCH 10/12] Read me Changes --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 9b3d46a..3676fce 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,7 @@ Either run php composer.phar require --prefer-dist froala/yii2-froala-editor php composer.phar require --prefer-dist froala/wysiwyg-editor-php-sdk php composer.phar require --prefer-dist bower-asset/froala-wysiwyg-editor +php composer.phar require --prefer-dist froala/wysiwyg-editor ``` @@ -25,6 +26,7 @@ or add "froala/yii2-froala-editor": "^2.6.0", "froala/wysiwyg-editor-php-sdk" : "*", "bower-asset/froala-wysiwyg-editor": "^2.6.0" +"froala/wysiwyg-editor": "^2.6.5" ``` @@ -93,7 +95,6 @@ Make sure you have a folder called "uploads" in your web root directory,Now to u 'theme' => 'royal',//optional: dark, red, gray, royal 'language' => 'en_gb' , 'toolbarButtons' => ['fullscreen', 'bold', 'italic', 'underline', '|', 'paragraphFormat', 'insertImage'], - 'imageUploadParam' => 'file' ], 'clientPlugins'=> ['fullscreen', 'paragraph_format', 'image'] ]); ?> From 2793f4a627c3bac7263cdb3f2f9ff5ac5aa06282 Mon Sep 17 00:00:00 2001 From: puneet0191 Date: Tue, 12 Sep 2017 13:27:08 +0530 Subject: [PATCH 11/12] Fixing PR comments --- composer.json | 3 ++- src/FroalaEditorWidget.php | 1 + src/controllers/DefaultController.php | 23 +++++++++++------------ 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/composer.json b/composer.json index e5197b0..d1bb7fe 100644 --- a/composer.json +++ b/composer.json @@ -31,7 +31,8 @@ "yiisoft/yii2": "^2.0", "rmrevin/yii2-fontawesome": "^2.0", "froala/wysiwyg-editor-php-sdk": "*", - "bower-asset/froala-wysiwyg-editor": "^2.6.0" + "bower-asset/froala-wysiwyg-editor": "^2.6.0", + "froala/wysiwyg-editor": "^2.6.5" }, "autoload": { "psr-4": { diff --git a/src/FroalaEditorWidget.php b/src/FroalaEditorWidget.php index 43bb6cc..f0ca40a 100644 --- a/src/FroalaEditorWidget.php +++ b/src/FroalaEditorWidget.php @@ -116,6 +116,7 @@ public static function widget($config = []) if (!isset($config['clientOptions']['imageUploadURL'])) { $config['clientOptions']['imageUploadURL'] = \yii\helpers\Url::to(['froala/default/upload']); + $config['clientOptions']['imageUploadParam'] = 'file'; } return parent::widget($config); diff --git a/src/controllers/DefaultController.php b/src/controllers/DefaultController.php index b926937..ec21cfd 100755 --- a/src/controllers/DefaultController.php +++ b/src/controllers/DefaultController.php @@ -7,20 +7,19 @@ class DefaultController extends Controller { // Without false it will give "Bad Request (#400) Unable to verify your data submission." - public $enableCsrfValidation = false; + public $enableCsrfValidation = false; - public function actionUpload() - { + public function actionUpload() + { // Store the image. - try { - $uploadFolder = $this->module->uploadFolder; + try { + $uploadFolder = $this->module->uploadFolder; $response = \FroalaEditor_Image::upload($uploadFolder); - echo stripslashes(json_encode($response)); - } - catch (Exception $e) { - http_response_code(404); - } - - } + echo stripslashes(json_encode($response)); + } + catch (Exception $e) { + http_response_code(404); + } + } } From e3eabfac3ba0f0b83f5a3ca34c83b5a44d47f619 Mon Sep 17 00:00:00 2001 From: NunoLopes96 Date: Wed, 13 Sep 2017 17:49:01 +0100 Subject: [PATCH 12/12] Changed namespace froala/froalaeditor to Froala/Editor --- README.md | 8 ++++---- src/FroalaEditorAsset.php | 2 +- src/FroalaEditorWidget.php | 6 +++--- src/Module.php | 4 ++-- src/controllers/DefaultController.php | 2 +- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 3676fce..2cb7a62 100644 --- a/README.md +++ b/README.md @@ -38,7 +38,7 @@ to the require section of your `composer.json` file. Once the extension is installed, simply use it in your code by : ```php - 'content', 'options' => [ // html attributes @@ -55,7 +55,7 @@ Once the extension is installed, simply use it in your code by : or use with a model: ```php - $model, 'attribute' => 'content', 'options' => [ @@ -78,7 +78,7 @@ in the Config Array. ```php 'modules' => [ 'froala' => [ - 'class' => '\froala\froalaeditor\Module', + 'class' => '\Froala\Editor\Module', 'uploadFolder' => '/uploads/' ] ], @@ -87,7 +87,7 @@ in the Config Array. Make sure you have a folder called "uploads" in your web root directory,Now to use the Froala Widget on any view just use the following code in the view: ```php - 'body', 'clientOptions' => [ 'toolbarInline'=> false, diff --git a/src/FroalaEditorAsset.php b/src/FroalaEditorAsset.php index 6a75f18..12a5540 100644 --- a/src/FroalaEditorAsset.php +++ b/src/FroalaEditorAsset.php @@ -1,6 +1,6 @@ clientOptions['theme']) ? $this->clientOptions['theme'] : 'default'; if ($themeType != 'default') { - $view->registerCssFile("{$asset->baseUrl}/css/themes/{$themeType}.css", ['depends' => '\froala\froalaeditor\FroalaEditorAsset']); + $view->registerCssFile("{$asset->baseUrl}/css/themes/{$themeType}.css", ['depends' => '\Froala\Editor\FroalaEditorAsset']); } //language $langType = isset($this->clientOptions['language']) ? $this->clientOptions['language'] : 'en_gb'; if ($langType != 'es_gb') { - $view->registerJsFile("{$asset->baseUrl}/js/languages/{$langType}.js", ['depends' => '\froala\froalaeditor\FroalaEditorAsset']); + $view->registerJsFile("{$asset->baseUrl}/js/languages/{$langType}.js", ['depends' => '\Froala\Editor\FroalaEditorAsset']); } $id = $this->options['id']; diff --git a/src/Module.php b/src/Module.php index 613d5c7..84ff1e4 100755 --- a/src/Module.php +++ b/src/Module.php @@ -1,10 +1,10 @@