Code Monkey home page Code Monkey logo

cakephp-wysiwyg's Introduction

Build Status Coverage Status Total Downloads Latest Stable Version Documentation Status Gratipay

Wysiwyg Helpers Plugin 2.0

Include Wysiwyg Editors quickly and easily

Background

I've been on a small refactoring spree as part of my work on Marcy Avenue. I realize, after years of working with Joomla and Wordpress, that people prefer different WYSIWYG editors. So to alleviate this, I am attempting to build a set of CakePHP helpers for each of the major WYSIWYG editors on the market, and as many small ones as possible.

The plugin also allows you to automatically change from one WYSIWYG Editor to another when using the WysiwygHelper and configuring it in the controller. You may also change the Editor within the view.

Requirements

  • CakePHP 2.x

Installation

Download the JS distribution of your editor of choice and install it in your js folder.

[Using Composer]

Add the plugin to your project's composer.json - something like this:

{
	"require": {
		"josegonzalez/cakephp-wysiwyg": "dev-master"
	}
}

Because this plugin has the type cakephp-plugin set in it's own composer.json, composer knows to install it inside your /Plugins directory, rather than in the usual vendors file. It is recommended that you add /Plugins/Upload to your .gitignore file. (Why? read this.)

[Manual]

[GIT Submodule]

In your app directory type:

git submodule add git://github.com/josegonzalez/cakephp-wysiwyg-helper.git Plugin/Wysiwyg
git submodule init
git submodule update

[GIT Clone]

In your plugin directory type

git clone git://github.com/josegonzalez/cakephp-wysiwyg-helper.git Wysiwyg

Enable plugin

In 2.0 you need to enable the plugin your app/Config/bootstrap.php file:

CakePlugin::load('Wysiwyg');

If you are already using CakePlugin::loadAll();, then this is not necessary.

Usage

Available Helpers

The default editor is Tinymce

To use any of these helpers, you should create a folder in the web/js folder which is named the lowercase version of your editor of choice. This folder should contain the entire distribution of files necessary for your editor to be in use. For example, the NiceditHelper requires the web/js/nicedit/nicEdit.js and web/js/nicedit/nicEditorIcons.gif files.

To configure where these files exist, please see the helper code.

  • CKEditor (Wysiwyg.Ck)
  • Jwysiwyg (Wysiwyg.Jwysiwyg)
  • Markitup (Wysiwyg.Markitup)
  • Nicedit (Wysiwyg.Nicedit)
  • TinyMCE (Wysiwyg.Tinymce)

Using the Generic WyswigHelper

Add the following to the controller where you'd like to use your preferred editor. You can omit the parameters if you like, the default editor is tinymce:

public $helpers = array('Wysiwyg.Wysiwyg' => array('editor' => 'Ck'));

Replace your textarea inputs with either of the following:

echo $this->Wysiwyg->input('ModelName.fieldName', $inputOptions, $helperOptions);
echo $this->Wysiwyg->textarea('ModelName.fieldName', $inputOptions, $helperOptions);

Array Options for the FormHelper are contained in the second parameter, while the third parameter contains and array of options for the editor

You can also change the editor within the view. Changes come into affect for the proceeding editor:

$this->Wysiwyg->changeEditor('Nicedit', $helperOptions);

At this point, everything should theoretically work.

Other Helpers

If hardcoding your editor, you can do the following in your Controller:

<?php
class AppController extends Controller {

  public $helpers = array('Wysiwyg.Nicedit');

}

Then usage in your views is as follows:

echo $this->Nicedit->input("ModelName.fieldName");

echo $this->Nicedit->textarea("ModelName.fieldName");

Settings

Most editors take a javascript object as settings. The WysiwygHelper allows you to specify optional settings in three ways.

Special settings

The following are special settings that are used internally by the Wysiwyg plugin

  • _buffer: A boolean for whether we should buffer input transformation js
  • _css: An array of css files to buffer
  • _cssText: A text string containing relevant css
  • _editor: The editor class. Used only when you specify the Wysiwyg.Wysiwyg helper
  • _scripts: An array of scripts to buffer
  • _scriptBlock: Override which block the scripts will be added to
  • _inline: Prints js in script block insted of next to input. Default: true

These will be ignored when passing settings onto the wysiwyg javascript you are configuring.

Via Controller Setup

This mode results in all non-special settings being set as defaults for every instantiation of the Wysiwyg editor areas.

<?php
class AppController extends Controller {
    public $helpers = array(
        'Wysiwyg.Wysiwyg' => array(
            '_editor' => 'Tinymce',
            'theme_advanced_toolbar_align' => 'right',
        )
    );
}

Via ->changeEditor()

The second argument on Wysiwyg->changeEditor() can also be used to completely override any already set defaults:

echo $this->Wysiwyg->changeEditor('Tinymce', $helperOptions);

Via ->updateSettings()

A call ->updateSettings() can be used to completely override any already set defaults:

echo $this->Wysiwyg->updateSettings($helperOptions);

echo $this->Tinymce->updateSettings($helperOptions);

You can also retrieve currently set editor settings by calling ->getSettings():

$settings = $this->Wysiwyg->getSettings();

Via Helper Call

Both ->input() and ->textarea() calls accept a third argument array, $helperOptions, which may be used to configure the helper. These are merged onto any defaults that have been specified:

echo $this->Wysiwyg->input('Post.body', $inputOptions, $helperOptions);

echo $this->Wysiwyg->textarea('Post.body', $inputOptions, $helperOptions);

TODO:

  • Better code commenting
  • Figure out how to include the JS distributions
  • Enable file-uploading using whatever is native to the editor
  • Refactor where possible
  • Create a WysiwygHelper that will auto-create the type of helper you want based upon settings given to the view~~~
  • Tests

License

The MIT License (MIT)

Copyright (c) 2009 Jose Diaz-Gonzalez

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.

cakephp-wysiwyg's People

Contributors

chrisvogt avatar josegonzalez avatar nojimage avatar pjosephson avatar plugs avatar rchavik avatar slamkajs avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

cakephp-wysiwyg's Issues

Trouble buffering JS

I am loading Wysiwyg like so in my controller:

public $helpers = array('Wysiwyg.Wysiwyg' => array('_editor' => 'Markitup'));

The _editor option seems to be working fine for me - I can switch between the two editors I have tested. What does not seem to have an effect are any of the other options.

I would like to buffer the Markitup scripts instead of having them called in the header. I have tried setting _buffer to true, but that doesn't seem to have an effect. I have also tried setting _scripts to false, hoping that it would prevent the scripts from being loaded and I could then add them later in my view, but this also has no effect.

In going through the options and trying to change each one, _editor is the only one I seem to get a response from.

Am I understanding or setting these options incorrectly?

Wrong implementation of Helper API (CakePHP 2.1.2)

Hi and first thanks for your plugin,

I wanted to use this in a project with CakePHP 2.1.2 but it seems like the Plugin doesn't implement the Helper Interface correctly. I'm not when exactly this changed (as far as I know it changed already with 2.0), but there are some problems now.

Just some of the problems I saw:

  1. The signature of WysiwygHelper::__construct is public function __construct($options) but according to the docs this should be public function __construct(View $view, $options = array()). The View object needs to be passed to the other helpers, too.
  2. There's something wrong with the loading of other helpers in WysiwygHelper.php. The helpers are loaded via App::import() (L82) and later they are assumed to be available as $this->$editorHelper where $editorHelper is the uppercase Editor name, i.e. Tinymce. But they have never been initialized to this. Also, I think it would be better to use App::uses() here instead of App::import, but I'm not sure what would be the best way to do this.

With kind regards,
Marc

wysiwyg helper

First thanks for the all the work.
A couple issues (at least with the tinymce editor of the wysiwyg helper). First I assume on the textarea function you mean to set the option type to "textarea" not "textareas". But more importantly, on the section where you define adding or creating a class option you need to add space when you add to an option that has class already definee otherwise. Something like: $options['class'] .= ' ' . $selector;

TinyMce bug with multiple text areas

It's not possible to use the TinyMce on multiple textareas. The last one never loads. This is independent on how many there are. I've tried with 4 and 2. Last one is always a simple textarea.

Documentation Typo

In the Settings listing, when used inside the helper the indexes for the array should not be '_buffer' but 'buffer'.
Change in the doc or the code?

Documentation typo

in the usage documentation i think the line
public $helper = array('Wysiwyg.Wysiwyg' => array('editor' => 'fck'));

should be
public $helpers = array('Wysiwyg.Wysiwyg' => array('editor' => 'fck'));

It may help newcomers.

--Sujoy

Error

I tried all your recommended settings and receive this error. Can't find variable: tinyMCE when viewing the form. I am using cakephp 2.4.3

Does not work. Notice (8): Undefined index: model and Notice (8): Undefined index: field

Cakephp 2.2.5 - Tinymce 3.5.8

Controller
class PostsController extends AppController {
public $helpers = array('Html', 'Form', 'Session', 'Wysiwyg.Wysiwyg' => array('editor' => 'tinymce'));

View:
echo $this->Wysiwyg->input("Post.body");

Notice (8): Undefined index: model [APP/Plugin/Wysiwyg/View/Helper/TinymceHelper.php, line 65]
Code Context
TinymceHelper::input() - APP/Plugin/Wysiwyg/View/Helper/TinymceHelper.php, line 65
WysiwygHelper::input() - APP/Plugin/Wysiwyg/View/Helper/WysiwygHelper.php, line 106
include - APP/View/Posts/edit.ctp, line 10
View::_evaluate() - CORE/Cake/View/View.php, line 923
View::_render() - CORE/Cake/View/View.php, line 886
View::render() - CORE/Cake/View/View.php, line 476
Controller::render() - CORE/Cake/Controller/Controller.php, line 956
Dispatcher::_invoke() - CORE/Cake/Routing/Dispatcher.php, line 193
Dispatcher::dispatch() - CORE/Cake/Routing/Dispatcher.php, line 161
[main] - APP/webroot/index.php, line 92

Notice (8): Undefined index: field [APP/Plugin/Wysiwyg/View/Helper/TinymceHelper.php, line 65]
Code Context
TinymceHelper::input() - APP/Plugin/Wysiwyg/View/Helper/TinymceHelper.php, line 65
WysiwygHelper::input() - APP/Plugin/Wysiwyg/View/Helper/WysiwygHelper.php, line 106
include - APP/View/Posts/edit.ctp, line 10
View::_evaluate() - CORE/Cake/View/View.php, line 923
View::_render() - CORE/Cake/View/View.php, line 886
View::render() - CORE/Cake/View/View.php, line 476
Controller::render() - CORE/Cake/Controller/Controller.php, line 956
Dispatcher::_invoke() - CORE/Cake/Routing/Dispatcher.php, line 193
Dispatcher::dispatch() - CORE/Cake/Routing/Dispatcher.php, line 161
[main] - APP/webroot/index.php, line 92

Choosing Ck editor has no effect

hi, thanks for this plugin, I tried using it with CK editor but apparently it has some problems:

  1. Ck is not used
    I try loading it according to the docs:
    public $helpers = array('Wysiwyg.Wysiwyg' => array('editor' => 'Ck'));

and the ckeditor.js is loaded, but it tries to initialize tinyMCE anyway in the field:

  1. field id is not correctly detected:
    having a model called 'Post', this code
Wysiwyg->input('content', array('div'=>'form-group', 'class'=>'form-control')) ?>

generates an element with id: "PostContent", but the plugin tries to initialize "#content"

  1. it doesn't wait for the code to load before initializing:
    I found a workaround for the problems above, and just use $this->Wysiwyg->changeEditor('Ck') in my code to use CK. but I am getting error:
    Uncaught ReferenceError: CKEDITOR is not defined

because the field code doesn't wait for the editor to load.

thanks, best
Dan

a dependency not found

hi, when I try to install this package, I get the following error:

The requested package josegonzalez/cakephp-page-route could not be found in any version, there may be a typo in the package name

thanks! best, dan

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.