TinyMCE and Zend_Auth – Simple Authentication checking.

I’ve been using TinyMCE for a good long while and wanted to integrate their fantastic FileManager plugin and ImageManager plugin’s (Both Commercial) in with my ZF client site. This is relatively easy, the easiest way is to create a controller action and a iframe in the view that points to the location of the imagemanager or filemanager plugins. eg

<iframe src="/js/tiny_mce/plugins/filemanager/index.php?type=fm">

This works well, but I wanted to make sure that the plugn was not accessible unless the user logged in. I already used Zend_Auth and this doesn’t exactly play well with the basic SessionAuthenticator. So I set out to create a basic simple plugin for TinyMCE that would allow it to work with the Zend_Auth System.

- Creating the plugin -
first off we have to create our plugin and plugin folder within the tinymce plugin’s plugin folder. If you think that’s a lot of use of plugin, you can understand where my brain decided to up and leave.

1st locate your tinymce folder, in there you should find plugins and then go into the filemanager folder. Of course this assumes you have purchased and installed the filemanager plugin. Your path should be something like the following:
<path_to_tiny_mce>/plugins/filemanager/ – this is what we shall refer to our “Base Path” from now on.

now we are at a comfortable location to proceed, we can go ahead and create our folder and file
<Base Path>/plugins/ZendAuthenticator
in here place a file name ZendAuthenticator.php containing this code:

<?php
/**
 * Use Zend_Auth to validate the logged in user.
 *
 * @author BinaryKitten
 */
class BinaryKitten_ZendAuthenticator extends Moxiecode_ManagerPlugin {

    private $auth = null;
    public function  __construct($man) 
    {
        $config = $man->getConfig();
        if (isset($config['ZendAuthenticator.LibraryPath']) && !empty($config['ZendAuthenticator.LibraryPath'])) {
            set_include_path(
                implode(
                    PATH_SEPARATOR, array(
                        realpath(
                        $config['ZendAuthenticator.LibraryPath']
                        ),
                        get_include_path(),
                    )
                )
            );
        }
        require "Zend/Auth.php";
        $this->auth = Zend_Auth::getInstance();
    }

    //put your code here
    public function onAuthenticate(&$man) 
    {
        return $this->auth->hasIdentity();
    }
}

$man->registerPlugin("ZendAuthenticator", new BinaryKitten_ZendAuthenticator($man));

Voila the plugin is ready.

- Configuring the plugin -
Now open up the config.php found in the “Base Path” mentioned earlier.
locate: $mcFileManagerConfig['authenticator'] and set it’s value to the following
$mcFileManagerConfig['authenticator'] = 'ZendAuthenticator';

- Library Location -

Finally, If your Zend_Framework is not located on the include path (like mine is) then you will need to tell the system where to find the library, to do this add the following to the config.php
$mcFileManagerConfig['ZendAuthenticator.LibraryPath'] = ' ';
Please remember though that this is relative to the “Base Path” and not the Document_Root unless you specify it as such.

– - – - –
The last thing I will leave you with is that this only checks to see if there is a stored session for Zend_Auth. I’ll leave it up to you if you want to get roles and other fancy stuff integrated.

2 thoughts on “TinyMCE and Zend_Auth – Simple Authentication checking.

Comments are closed.