1

Topic: PHP Plugin for TinyMCE

********************************* READ THIS AND THE NEXT POST FIRST ****************************************

Hello all,

     The PHP plugin is now live on sourceforge.  Here is the link:

PHP Plugin Download

First of all I would like to thank the authors of TinyMCE and Moxiecode Systems AB for creating such a wonderful product and allowing me to contribute to it.  Also I would like to thank those of you, in advance, who will be posting your findings, suggestions and comments in this thread.  Though I have written code for quite sometime, this is the first javascript project of any magnitude that I have done.  So be somewhat kind if you will.

Now for the fun stuff cool

The plugin is easy to install, just unzip and copy the php directory to your installation of TinyMCE plugin directory.
add "php" to your list of called plugins in your init and your done.  There is currently one configuarable option which is:

php_external_list_url : "(path to tinymce here)/tinymce/jscripts/tiny_mce/plugins/php/examples/example_php_list.js"

I have provided an example .js file with this in the examples directory.  This shows how to use the file to create a dropdown list of pre-programmed php code "assets" which can then be inserted from the popup.



A note on configuration:

     The plugin does "atempt" to preserve the formating in your code, however, I would suggest that you leave the TinyMCE setting apply_source_formatting set to false (which is default btw if you do not have it set in your init string).  I tried it with this setting on but all the indents would then be removed from the code.  With it off it seems to perform fairly well (at least for the php stuff that is).

     Also I would not have the codeprotect plugin loaded along with the php plugin.  I am pretty sure they will not play nice together.  The php plugin was designed to replace the codeprotect pugin.

2 other settings I use to help preserve code format.
            remove_linebreaks : false
            force_p_newlines : false


Help me make this plugin better and lets discuss what it needs, what it's limitations are and so on.
More about what it does in the next post.

gforce301

Last edited by gforce301 (2006-06-03 22:21:24)

Duct tape is like the force,
it has a light side, a dark side
and it holds the universe together

2

Re: PHP Plugin for TinyMCE

What the plugin does:

The php plugin attempts to preserve any php code in the document and encapsulate it in a nice little php.gif that you can see
in your document.  It will parse the entire content of the editor and do it's best to capture the php code.
   
    Current php/html formats the parser captures and what it does to them:
   
        1)  <?php (yes the "php" is optional on the open tag) Any thing you want may be placed in here! ?>

            The parser will capture everything between the php open tag and the close tag
       
        2)  html/xhtml tags of this style: <a href="<? some php code to generate the url ?>">link</a>

            The parser will capture everything from the open html tag to the end of it's closing tag
            (from the <a> to the </a> inclusive).  This is so the TinyMCE engine does not try to
            change what it will see as broken html.
           
        3)  html/xhtml tags of this style: <img src="<? some php code to generate a url ?>"> (/> if you are using xhtml style tags)

            The parser grabs everything from the start of the tag to the end of the "empty tag".
              (from the < to the > inclusive)
   
How to use it:

    There are 2 ways that you should use the pugin to insert the php code.

    1) Use the popup!!  Thats one reason I created it.  Just type or paste your php code into
        the code area in the popup and hit the insert button.  Too easy huh?  When using the popup
        please take note of the types of php and mixed php/html above.  If you are unsure as to
        which type your code may fall under use option 2 below and the parser will convert your
        code for you.

    2) Use the html editor view built into TinyMCE.  Open the html editor view
        (if you have it configured in your init) and type or paste your code there.

What it does not do:

    The php plugin parser does not check for valid syntax of any kind.  I figured I needed to say this one up front.
    I do not believe that the parser ever will check syntax.  I believe it is way beyond the scope of such a plugin.
   
    Currently, even though the Description field is a text input, it only stores descriptions for the assets from the
    dropdown.  All other code will have the description "Custom Code".  (I am working on implementing this).
   
    Even though the PHP place holder is re-sizable in the editor, it does not retain this information at this time.
    (I am working on implementing this)
   
    And just so everyone is aware this is a BETA VERSION.  Make no mistakes about it.  It has not been tested in all
    or even close to all configurations of TinyMCE.  One configuration I have for sure not tested it in is the full
    page (full document?) editing mode.  I forget what it is called at the moment.  It's the mode that allows the creation
    of all the html/xhtml entities (html, head, meta, doctype, etc...).  I hope someone besides me does test it in this way.




more to come...........

gforce301

Last edited by gforce301 (2006-06-01 04:43:05)

Duct tape is like the force,
it has a light side, a dark side
and it holds the universe together

3

Re: PHP Plugin for TinyMCE

Sorry for the wait on the feed back. Ive been working on another issue with forms. Specifically the textareas. This may be a Firefox issue. So I need to do more testing on that one. Heres the link about textarea and form issues:
http://tinymce.moxiecode.com/punbb/view … 094#p12094




Now to the good stuff.
Nice work gforce301 on the new duct tape beta version of your visual php icon pluggin!
Forgive any of the typos as I have sleep little in the past 3 days=)



Issues:
I was able to see a couple of things that may be fixable.
I have some unique lines of php code in a link that has caused a mce_thref to be imputed from the code editor or just inserted on the save(this save is done using php form submission and not tinymce's). This also is the case with a line of code that is a link to a css, essentially the same kind of link.

Here are the examples:

Should stay like this:
<a href="<?php echo "$domain"; ?>index.php?page=Contact&page_url=site/contact.php">Contact  Us</a>

Turns into this:
<a mce_thref="<?php echo "$domain"; ?>index.php?page=Contact&page_url=site/contact.php">Contact  Us</a>


Should stay like this:
<link rel='stylesheet' href='../admin/includes/modules/<?php echo "$stylesheet"; ?>.css' type='text/css'>

Turns into this:
<link rel='stylesheet' mce_thref='../admin/includes/modules/<?php echo "$stylesheet"; ?>.css' type='text/css'>

Questions:
I have not used the codeprotect pluggin:
http://tinymce.moxiecode.com/punbb/view … hp?id=1604

This topic was brought up about problems with the pluggin that it could not handle php, except with a fix:
http://tinymce.moxiecode.com/punbb/view … hp?id=3460

Question to gforce301 is does your php  pluggin work with codeprotect, or is it a replacement?





Paypal:
Ok on another note. I am using tinymce to edit pages, and have not had it configured ever to work with Paypal shopping cart, buy now buttons. The problem was that Paypal form button code would vanish when updated from the code edit window in tinymce.
I did not have a chance to use the codeprotect pluggin to see if that worked.
But this php pluggin FIXED MY PROBLEM!!! Now my Paypal buttons update to my page. I have not tested them to see if they work. But the code looks right to me. Tinymce moves the input type and values around in the tag, but that is now big deal, and the php pluggin is not the cause for this.


I am very impressed and gforce301 should be commended!! Now its time for some sleep, its almost 4am and I have to get up at 7am=P

Last edited by acm (2006-06-01 13:10:19)

4

Re: PHP Plugin for TinyMCE

acm

Thank you for the compliment and thank you for the quick feedback.  I will look into the 2 strings above and get back to you today.  I am not sure where the mce_thref is coming from.

As for your question about the codeprotect plugin, the answer is no they should not be used together.  The php plugin is designed to replace the codeprotect one and I do believe that if they are both loaded something "bad" will happen to your code.

ok acm I looked into the strings that are getting "mangled".  I am still not sure where the mce_t is coming from or why it is being applied in the front of the href attribute in your tags.  I do not think it is something that the php plugin is adding (but I could be wrong, I am still testing).  I tested those exact strings in my copy of the plugin and they remained unchanged.  I also verified that the copy I uploaded to sf was the same copy I am using.  (just to be sure. I have the "ugly" copy and yes it's even uglier than the "cleaned up" one).

When you get a chance can you provide your init string and version of TinyMCE that you are using?  I would like to see what other settings you are configuring that the plugin may be reacting to.  The php plugin was developed and tested on the latest release of TinyMCE  Version: 2.0.6.1 (2006-05-04) which I downloaded on 05-23-06.

gforce301

Last edited by gforce301 (2006-06-01 15:24:08)

Duct tape is like the force,
it has a light side, a dark side
and it holds the universe together

5

Re: PHP Plugin for TinyMCE

Hi gforce301.

First of all I would want to thank you for this wonderful plugin, I've been waiting for something like this smile
It was easy to add a different button as the placeholder for the php code in the content as it was all defined in a CSS file. I salute you for that.

Though, there is one little problem. Please note that it's nothing related to the functionality of the script what-so-ever, just some cosmetics when it comes to the popup window:

There are some display errors due to faulty CSS that sets the tab container to a fixed size (100px in height to be exact). Anyway, here's a fix:

.panel_wrapper div.current {
    min-height: 100px;
}

div.current {
    padding-bottom: 15px;
}

Add it to your css and it should pretty much display correctly no matter what browser.

Again, thanks for the plugin, it's great. smile

Last edited by Andy^ (2006-06-01 23:35:15)

6

Re: PHP Plugin for TinyMCE

Andy^ thank you for the help!!

Yes there are a few things wrong with the popup and I will add your fix to the next release. (found a minor javascript error today so next release will be very soon).

Please keep the help coming!

Duct tape is like the force,
it has a light side, a dark side
and it holds the universe together

7

Re: PHP Plugin for TinyMCE

Ok, forgot to give the system environment used to test.

The errors occured using:
Firefox on Windows XP Service Pack 2 with Tinymce 2.0.6 latest download
Firefox on OSX 10.2.8 with Tinymce 2.0.6 lastest download

There were no errors that I have found yet for the link problem using:
IE on Windows XP Service Pack 2 with Tinymce 2.0.6 latest download

And Tinymce does not work on OSX IE at all.

Hope this helps you gforce301.  So it does work, and Firefox have many issues as it is when it comes to code. Very nice pluggin. Dont suppose you have time to look at the textarea issue?=)
http://tinymce.moxiecode.com/punbb/view … 094#p12094

Last edited by acm (2006-06-02 04:45:57)

8

Re: PHP Plugin for TinyMCE

I will see what I can do acm, provided you are willing to live with this plugin as is for a few days tongue

I posted a few more notes at the top of this thread on configuration to preserve code format.

I am also going to possibly look at some of the issuse with using the php plugin with the full page plugin.

Duct tape is like the force,
it has a light side, a dark side
and it holds the universe together

9

Re: PHP Plugin for TinyMCE

Hi gforce301,

This plugin works! Firefox is just glitchy, definetely not your problem. This pluggin is a Godsend! If you figure out how it can work on a IE and Firefox osx platform, then it will be nice for those who use them. I have noticed some questions that come about do to osx, but the users are not aware that osx is a different animal.

I think open source and collaboration for code that can work on all systems is what this place is all about! Sharing!!

10

Re: PHP Plugin for TinyMCE

Damn cool plugin!! Maybe it could be combined with the plugin I converted lately. "My" plugin is a conversion of Ryan Demmer's (Joomla) template-plugin. With this plugin you can open and save html-files (css-support added by myself) which are on the server.

These features (plus smarty-support) I would love to see in your plugin.

Keep up the good work.

P.S.: If anyone is interested I could rewrite "my" plugin, because it is tailored to the CMS I use, and release it?

11

Re: PHP Plugin for TinyMCE

frankblack,

Thank you for the compliment.  I believe you should rewrite your plugin to be "generic" if you can and release it.  The ability to open and save files would be a nice touch and if it was available I would definitely try to make the php plugin play nicely with it.  One of the reasons that TinyMCE does not include file capabilities bundled with it's release, is that it would not be cross-platform if they did.  Any file capabilities are dependant on server side technology, but others can learn from your example how to adapt to their particular environment.  I myself would be interested in your approach at least.

As for smarty, I do not use it because nothing that smarty does can not be done by php, only better.  I do not wish the discussion on this thread to turn away from the php plugin too much.  So here is a link to a discussion about template engines in general and feel free to email me directly with thoughts on this.

Template Engine Discussion  read the comments by voostind.

Last edited by gforce301 (2006-06-03 22:22:53)

Duct tape is like the force,
it has a light side, a dark side
and it holds the universe together

12

Re: PHP Plugin for TinyMCE

Hi All,
I just want to through in my 2 cents. I think its nice how gforce301's pluggin works, as it works nice with many cms programs as well as my custom coded one. I am in favor of new additions, but as a tandem project pluggin that does not stop the progression of the original basic and versital php pluggin.

I know many here have been looking for and trying to create a solution like gforce301's pluggin for a couple of years. I would hate to see it grow beyond the point that it would stop working with peoples projects that progress with tinymce releases.

I want to be clear in that there are always thing that can be added and should be looked at. Viewed threw lenses with compatibility and versatility=)
ACM

13

Re: PHP Plugin for TinyMCE

Great plugin, but i keep geting my http://domain/admin/ link infront of my <?php code... is this normal?
I can't seem to get around it here is an example
[HTML Source Editor]
<?php BDPRSS2::output(1); ?>
[Update]
[HTML Source Editor]
http://www.stephenhonea.com/wp-admin/<?php BDPRSS2::output(1); ?>
I'm sure its something simple please advise.

14

Re: PHP Plugin for TinyMCE

stephen,

No it would not be considered normal behaviour for the plugin.  It is not something the php plugin would/should add.  I tested that string and did not get the extra stuff in front of it.  Is that the whole string or is it embedded in something else? Like an anchor tag for instance? Also what other plugins do you have loaded?  Maybe you could post your init here.  I will help you figure it out any way I can, but I need a little more to go on.

A note on what I mean by embedded:

     At the top of this thread in the second post I describe the 3 "types" of php strings the parser captures.  I will elaborate here for more clarity.
     The parser first atempts to determine what type of php string it is dealing with.  There is one "non-mixed" type and two "mixed" types.  The difference
     between the two mixed types is subtle.

     Type 1)  <?php (yes the "php" is optional on the open tag) Any thing you want may be placed in here! ?>
     
     This is the "non-mixed" type.  It is not contained inside any html/xhtml tag.  This will become more clear on the next type.  When the
     parser encouters this type it captures everything between the php open tag and the php close tag and inserts a place holder in the editor.

     Type 2)  html/xhtml tags of this style: <a href="<?php some php code to generate the url ?>">link</a>
     
     This is the first "mixed" type.  Notice the php string is actually embedded within the open anchor tag.  When the parser encouters this type
     it will capture the entire open tag and all text up to and including the anchor closing tag </a>.  It must do this because otherwise TinyMCE will
     see the string "link</a>" as invalid html and atempt to correct the situation.  So the parser captures the entire anchor entity and inserts a place
     holder in the editor.
     
     Type 3)  html/xhtml tags of this style: <img src="<?php some php code to generate a url ?>"> (/> if you are using xhtml style tags)
     
     This is the second "mixed" type.  When the parser encouters this type it captures the entire "empty" tag as it is known. From < to >.  There is
     a subtle but distinct difference between this type and and type 2.  As we all know empty tags do not have a matching close tag.

It may be difficult at times to determine which "type" of php string we are atempting to insert, depending on how complex our code is.  It should be noted that any text (not just php strings) can be inserted through the popup window and will for a brief time be encapsulated within a php place holder.  However, upon going to html editor mode, saving the contents of the editor to the server, initial loading of the editor or any number of other events which cause the editor to run its cleanup routines, will cause the php plugin parser to "convert" the non php text back to normal.  In other words if we put the string click <a href="<?php (some php code) ?>">here</a> to view into the popup editor upon a cleanup event the php place holder will only contain <a href=" (some php code) ?>">here</a> and the rest of the text will be "plain" text in the editor.

When in doubt insert the php text in the html editor mode of TinyMCE until you get a "feel" for the way the parser captures and converts php/html strings.

hope this helps
gforce301

Last edited by gforce301 (2006-06-06 09:25:54)

Duct tape is like the force,
it has a light side, a dark side
and it holds the universe together

15

Re: PHP Plugin for TinyMCE

PHP programs:
wp2.0
gallery2
WP Plugins:
BDP RSS Aggregator
EditorMonkey
WPG2 image gallery embed plugin
Weather Icon
Trying to use the tinymce editor in wp to embed a rss feed into a page saved in mysql
ie http://localhost/?page_id=8
no tags visible to me anchor or otherwise, only thing visible is the <?php echo"blah"; ?>

Embed type 1 atm, but eventually it would evolve to type 3 being an rss feed.

I'm using EditorMonkye to load the php plugin from tinymce plugin directory, it works fine placing the php icon in the window, i cannot find tinyMCE.init file to modify. 

I have deactivated all plugins except for editor monkey and still produce the same results.
I tried deactivating editor monkey, but then i can't load up the Html Source Editor

16

Re: PHP Plugin for TinyMCE

I installed wordpress from scrach, I can't seem to install the plugin
I edited [tiny_mce_gzip.php];
    $plugins = apply_filters('mce_plugins', array('wordpress', 'autosave','wphelp'));
I added;
    $plugins = apply_filters('mce_plugins', array('php', 'wordpress', 'autosave','wphelp'));
The TinyMCE editor goes from rich graphical to some ascii grey button interface.

I also added;
    plugins : "php",
    php_external_list_url : "./tinymce/jscripts/tiny_mce/plugins/php/examples/example_php_list.js",
Which seemed to have no effect on the interface.
initArray = {
    mode : "specific_textareas",
    plugins : "php",
    php_external_list_url : "./tinymce/jscripts/tiny_mce/plugins/php/examples/example_php_list.js",
    textarea_trigger : "title",
    ...

there is a line I manipulated;
    plugins : "<?php echo $plugins; ?>"
    plugins:"php",

So far no sucess,
Please advise:

17

Re: PHP Plugin for TinyMCE

stephen,

I myself am unfamiliar with wordpress and editormonkey.  Hopefully someone else on the forum can help you there.  I am also unsure as to why you would have to edit the tiny_mce_gzip.php file directly.  I myself do use the gzip compressor "addon" for TinyMCE and have not had to modify this file for any reason.  Is it something that wordpress or editormonkey requires you to do?

As for the one setting for the plugin php_external_list_url the path here needs to be either relative to the document or an absolute URL to where the file example_php_list.js exists.

For instance on my developement server the relative path I have to use is:
"../tinymce/jscripts/tiny_mce/plugins/php/examples/example_php_list.js"
notice the "../" becasue the "page" I am calling TinyMCE from is in a different directory than where the files for the package are.  The path in the readme file is only an example of how the path should look.  It might have been better written to read
php_external_list_url : "(path to TinyMce here)/tinymce/jscripts/tiny_mce/plugins/php/examples/example_php_list.js",

Would it be possible for you to build a simple test page?  Just a document with a textarea and a basic tinymce configuration.  When I hear things like "The TinyMCE editor goes from rich graphical to some ascii grey button interface." it seems like there is more wrong than the php plugin.  I have had issues of this magnitude, but I was also poking around in the core and plugins and the like and caused these issues myself as I learned how the core system worked.

I can say however that I do not know of anyone who has tested the php plugin with wordpress and editormonkey so I am interested to see how it will perform.

Last edited by gforce301 (2006-06-07 16:46:08)

Duct tape is like the force,
it has a light side, a dark side
and it holds the universe together

18

Re: PHP Plugin for TinyMCE

Update:
I can create a webpage using TinyMCE2061, and the plugin works flawlessly, along with other desired plugins. However accessing the same setup with wordpress returns undesirable results.

The interaction between wordpress and TinyMCE is outside of my current understanding.  I'm not sure how TinyMCE is called from within wordpress asside from tiny_mce_gzip.php.  the gzip is a bit confusing, but its similar to a tinyMCE.init{()}; call.

I will continue to post my findings, however I have a basic understanding of php, which means a resolution may not arrive in the near future.

Thanks for your help, and your patience.

19

Re: PHP Plugin for TinyMCE

I have the same problem as stephen. I use tinyMCE with XOOPS. When the php-code is inserted the php-image and everything looks fine, but when I want to view the source /subfolder/modules/news/admin is right before the php-code. When I leave the source-window and enter it again then the path is doubled.

I still haven't found the place WHERE the path is inserted.

20

Re: PHP Plugin for TinyMCE

frankblack,

If you do find how/where the path information is being inserted please post it here as I'm sure others will be having similar problems.  The php plugin does not insert anything in front of, or add to the captured string in any way.  I am not familiar with XOOPS so I am sorry I really do not know where it could be comming from.  If I had to guess it has something to do with the "place holder" image that the plugin uses to encapsulate the php code.  Just a question, does the flash plugin behave in a similar manner?  The reason I ask is that the php plugin is based largely on that source.

Duct tape is like the force,
it has a light side, a dark side
and it holds the universe together

21

Re: PHP Plugin for TinyMCE

Just a question, does the flash plugin behave in a similar manner?

No problem with the flash plugin.

22

Re: PHP Plugin for TinyMCE

Hello gforce301,

i got 2 suggestions to make. Just some thoughts while looking at your code.

a) When you parse the php content and add it to the editor you store it in the alt attribute of an img tag.
To do that you convert all " > etc. to entities. This will result in a multiline alt attribute if the php code has multiple lines.
I don't know if tinyMCE will clean this up, but in the end isn't it easier and (better?) to use JavaScript escape resp. unescape functions to prepare the code for the alt attribute, as escape will convert all newlines, tabs > " etc. at once and will result in a one line string.

b) Just a simple suggestion. As a PHP-pic is inserted to the Editor as placeholder for the PHP code, you may want to prevent resizing of that pic in the editor. This could easily be achieved with adding height:20px and width:20px to your content.css

Oh. And i have just recognized that your "Insert PHP" popup-window is somehow screwed up in Firefox (1.5.0.4)

Keep up the work and thanks for this great plugin.

23

Re: PHP Plugin for TinyMCE

frankblack,

I am still looking into why the plugin behaves strangely for you and for stephen, please let me know if you have any insight.


ascii,

Thank you for your comments and suggestions.  I did not know about the Firefox issue and I am sorry I missed it for those of you who use ff.  I am looking into fixing this now and then releasing v1.1 beta soon.  If anyone knows why it displays so weird in Firefox I would be grateful.

I like your suggestion about the height and width being added to the content.css and I will add that. 

Your first suggestion about using javascript to "escape" all the "special" characters sounds very promising.  I am looking at ways to improve the effciency of the parser, as in it's current form, I feel, it is just barely what would get us by for now.  I will definitely look into this and I thank you for suggesting it.  The only question I have is if the TinyMCE engine will leave the escaped characters alone.  I guess I will find out when I try it.

Last edited by gforce301 (2006-06-16 03:55:39)

Duct tape is like the force,
it has a light side, a dark side
and it holds the universe together

24

Re: PHP Plugin for TinyMCE

gforce301 wrote:

ascii,

Thank you for your comments and suggestions.  I did not know about the Firefox issue and I am sorry I missed it for those of you who use ff.  I am looking into fixing this now and then releasing v1.1 beta soon.  If anyone knows why it displays so weird in Firefox I would be grateful.

I like your suggestion about the height and width being added to the content.css and I will add that. 

Your first suggestion about using javascript to "escape" all the "special" characters sounds very promising.  I am looking at ways to improve the effciency of the parser, as in it's current form, I feel, it is just barely what would get us by for now.  I will definitely look into this and I thank you for suggesting it.  The only question I have is if the TinyMCE engine will leave the escaped characters alone.  I guess I will find out when I try it.

I already showed you a fix for this as it's a thing with the CSS.
You have set the box to a fixed value of 100px and therefore the text overflows.

Last edited by Andy^ (2006-06-16 12:26:22)

25

Re: PHP Plugin for TinyMCE

lol ok Andy^ I did not realize that was what the fix was for, sorry.  I was looking at an "older" version whithout the css fix you provided.  It is in the next release.  Sorry for the confusion guys.

Duct tape is like the force,
it has a light side, a dark side
and it holds the universe together