1

Topic: Best way to "preserve" php coding on a page being edited?

If the HTML being edited by tinyMCE contains any PHP code, then the PHP code is killed.  It no longer works.

What is the best way to stop this from happening?

I know that with other editors, php code is "represented" by little "php" icons and the user is unable to modify that portion of the code.

Is this possible with tinyMCE? 

I see the codeprotect plugin, but this just seems to convert into comments, and doesn't actually show that it's PHP code to the user.

Is there an official "PHP protector" plugin by the developers? 

Any ideas?

Thanks!

2

Re: Best way to "preserve" php coding on a page being edited?

The codprotect plugin also does not work with "<?php".  It only works for "<?".

Any ideas?

3

Re: Best way to "preserve" php coding on a page being edited?

hstraf wrote:

The codprotect plugin also does not work with "<?php".  It only works for "<?".

Any ideas?

Could you not just use <? my php here ?>
Id say the file your saving to will also have to be .php extension!

4

Re: Best way to "preserve" php coding on a page being edited?

I won't know beforehand what "style" of specifying a php tag the user might be using.  PHP allows for "<?" and also "<?php". 

I fixed this by modifying the codeprotect plugin to work with BOTH methods.

But now, the big problem is that if the php is in a URL or link, then tinyMCE rewrites it to be "URL safe" (even with the codeprotect plugin)

So codeprotect plugin does NOT work for php that is in a link or URL.  If we have this:

<a href="images/<?php echo($year.'/images/'.$month.'-1.gif'); ?>">link</a>asd

It is changed by tinyMCE to this:

<a href="images/<!--PHPCODEPHP%20echo($year.'/images/'.$month.'-1.gif');%20PHPCODE-->">link</a>

Is there any way to "turn off" automatic URL conversion ONLY if it is within PHP code tags?

5

Re: Best way to "preserve" php coding on a page being edited?

How about using setupcontent_callback and save_callback? You could do a exchange there and replace the php-tags with your "special" tags. I used these features for relative URLs, because using the editor was allowed on the user- and the admin-side and therefore I had some problems with the paths.

6

Re: Best way to "preserve" php coding on a page being edited?

Possible solution is here:

http://tinymce.moxiecode.com/punbb/view … hp?id=3460

7

Re: Best way to "preserve" php coding on a page being edited?

Hello all first time on the forum,

As a newb to this forum and to TinyMCE please pardon in advance any ignorance I may have of the way things work around here.

First of all I would like to say wow, just wow.  TinyMCE is an awsome system.  Many thanks to those who wrote it or have contributed.

Next I have a few questions:
1) Does anybody read this forum?
2) (this one is more to the pont of this thread) Is anyone interested in a plugin which I have developed for keeping PHP, in all of it's wonderful forms, fully intact while providing a visual placeholder and a popup editor with some built in features?

Three days ago I started searching this forum for the very same information people in this thread have been looking for.  Not to detract from the work and contributions that the members here have provided on this subject but, the codeprotect plugin (both the one on sourceforge and the "patch" posted on this forum are, at best, patches for the problem.

So I wrote a fully visual PHP plugin based on the other plugins that are distributed with TinyMCE.  What a task, let me tell you!  Currently it handles both styles of php tags and most styles that php can be written in, except for the very specific problem that hstraf has posted here.  I am re-writting the text parser at this time and I decided to stop by here and deliver the news so that I might get some feedback on what else it should be capable of.  A few examples of the types of php strings that other programmers attempt to insert in to html docs would be helpful indeed.  As I am a fairly old-school C programmer, the syntax style I use is a very strict one and it would have never occured to me to handle a case such as the one here "<a href="images/<?php echo($year.'/images/'.$month.'-1.gif'); ?>">link</a>".  However, in that respect I do not wish to deliver anything less than a plugin which does what people need it to do.  It also has a few other nifty features like being able to have a drop down list of pre-programmed code "snipets" shall we call them?  Any way these snipets can be inserted from the popup with just a click of a button and the list is fully customizable.

So if you guys actually keep up on reading the posts on this forum and I get some responses, I would say that I would be able to provide a beta version for testing within the next two days.  So this is my test of the forum and my way of introducing myself to the community.  Hopefully someone reads this.

gforce

Last edited by gforce301 (2006-05-29 10:21:55)

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

8

Re: Best way to "preserve" php coding on a page being edited?

So if you guys actually keep up on reading the posts on this forum and I get some responses, I would say that I would be able to provide a beta version for testing within the next two days.  So this is my test of the forum and my way of introducing myself to the community.  Hopefully someone reads this.

Read it, liked it! I am very curious about your plugin. I have a similar problem with preserving tags. The CMS I use, uses the weird delimiters <{blabla}> for smarty-tags. Maybe I can learn from your plugin?

So please release your plugin for testing!

9

Re: Best way to "preserve" php coding on a page being edited?

To say the least, I hope gforce301 will post the php visual pluggin!!

10

Re: Best way to "preserve" php coding on a page being edited?

Woot!!! We have a winner smile. Ding Ding Ding!!

Ok the parser has been re-written as of this morning to handle "mixed" php/html entities of the type posted by hstraf in this thread on 05-08-06.  However, I believe that it still needs one more handler for cases like so: <img src="<?php (some code) ?>"/> (note the xhtml style of tag closing), will be testing it today.  The parser should be finished this evening, thank god for long weekends!!!  I still need some examples of code strings, not actual code (you don't have to give away the farm here), just examples of the types of strings I need to handle.

This is what we can handle so far:

<?(php)
   If ($test)
   {
      print "test is defined";
   }
   else
   {
      echo ('test is undefined');
   }
?>  (yes this can be all on one line, but the parser atempts to preserve line breaks for readability if you have them cool)

also the one found in this thread:

<a href="images/<?php echo($year.'/images/'.$month.'-1.gif'); ?>">link</a>

and any other "normal" php constructs like

<?(php) echo myfunction(); ?>

any of these can be within html (xhtml?) "elements"

<table>
   <tr><td><strong><?php print("This is 'cool'!!"); ?></strong></td></tr>
</table> (or however you structure you code/html)

So the question you guys have is WHEN DO WE GET TO SEE IT?!, and the answer I have is give me some strings of code in formats I have not thought of yet.  The ultimate good feeling for a programmer is to release a beta that becomes the package without any changes and, on a more practical note, no way do I wish to recieve 10,000 emails when it does not work.  So help me help everyone.

Last edited by gforce301 (2006-05-29 22:07:50)

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

11

Re: Best way to "preserve" php coding on a page being edited?

Ok here is some code to see if your pluggin would preserve correctly.


<?php //search_files(): 
function search_files($server_name, $doc_root, $search_dir, $file_types, $file_skip, $file_hits, $file_terms, $file_words, $file_bytes, $_GET) 
{
 global $count_hits;
 @$keywords_url=$_GET['keywords_url'];
 @$action=$_GET['action'];
 if($action == "search") 
 { 
  foreach($search_dir as $dir) 
  { 
   $handle = @opendir($doc_root.$dir);
   while($file = @readdir($handle)) 
   {
    if(in_array($file, $file_skip)) {continue;}
    elseif($count_hits>=$file_hits) {break;} 
    elseif(is_dir($doc_root.$dir."/".$file)) 
    { 
     $search_dir = array("$dir/$file");
     search_files($server_name, $doc_root, $search_dir, $file_types, $file_skip, $file_hits, $file_terms, $file_words, $file_bytes, $HTTP_GET_VARS); 
    }
    elseif(preg_match("/($file_types)$/i", $file)) 
    { 
     $fd=fopen($doc_root.$dir."/".$file,"r");
     $text=fread($fd, $file_bytes); 
     $keywords_html = htmlentities($keywords_url);
     $do=stristr($text, $keywords_url)||stristr($text, $keywords_html);
     if($do)
     {
      $count_hits++; 
      if(preg_match_all("=<title[^>]*>(.*)</title>=siU", $text, $title)) 
      { 
       if(!$title[1][0]) 
       $link_title="Search Result"; 
       else
       $link_title=$title[1][0];  
      }
      else {$link_title="Search Result";}
      $dir = str_replace("/","","$dir");
      echo "<a href=\"$server_name?page=".$link_title."&page_url="."$dir/$file\" target=\"_self\" class=\"search_url\">$count_hits. $link_title</a><br>"; 
      $dir = "/"."$dir";
      $extract = strip_tags($text);
      $keywords_url = preg_quote($keywords_url); 
      $keywords_url = str_replace("/","\/","$keywords_url");
      $keywords_html = preg_quote($keywords_html); 
      $keywords_html = str_replace("/","\/","$keywords_html");
      echo "<span>";
      if(preg_match_all("/((\s\S*){0,$file_words})($keywords_url|$keywords_html)((\s?\S*){0,$file_words})/i", $extract, $match, PREG_SET_ORDER)); 
      {
       $number=$file_terms; 
       for ($h=0;$h<$number;$h++) 
       { 
        if (!empty($match[$h][3]))
        printf("<div class=\"search_desc\"><b>..</b> %s<b>%s</b>%s <b>..</b></div>", $match[$h][1], $match[$h][3], $match[$h][4]);
       }
      }
      echo "</span><br><br>";
      flush();
     }
     fclose($fd);
    }
   }
   @closedir($handle);
  }
 }
} ?>

Thanks for working on it gforce301!!

Last edited by acm (2006-05-29 23:29:44)

12

Re: Best way to "preserve" php coding on a page being edited?

Plugin idea sounds good.  The problem is that we won't know what doesn't work until we break it.  smile

I respect your desire not to be bombarded by emails, but I think it's better to release what you have and just put a big "DO NOT EMAIL ME!!!" note on your plugin release docs.  Or don't put anything more then a link to this thread for discussion of it.. so anyone with a problem can come here and eventually you'll see it and maybe update the plugin, etc.

Thanks!

13

Re: Best way to "preserve" php coding on a page being edited?

Thank you very much acm for submitting an example.  It was exactly what I needed.  I have good news and bad news. 

First the good news.  The parser works and maintains the code to and from the popup exactly, including the visual format (spacing and indents etc.... yes acm that means the code you posted here cool)

Now the bad news.  As has been the case when viewing the page from the html button included with TinyMCE, the code views fine.  Two problems though.  First (a minor one):  the html view does not preserve the indent format of the code.  Something in the TinyMCE base cleanup routines likes to squash that, however, the newlines are preserved (we can probably live with this for a while).  Second (the major one):  if you use the update button from html view, it's all over but the crying.  I have been re-writting the parser for the return from the html view.  I do not consider just not using the html view as an acceptable solution. (as it turns out this is the same part of code that handles the submit of the form, which makes this a very major problem)

I should have the parser fixed tonight which would make the plugin beta.  hstraf, I appreciate your suggestion and I understand your desire to help "test" (break? lol tongue) it, but remember I did say 2 days.  Dammit Jim, I'm a programmer not a Deity tongue (just a little Star Trek humor there).

I am waiting on an email response from spocke regarding copyright restrictions.  Once the developers of TinyMCE give me a response to that, I can put the beta live.  Oh and before you ask, yes it will be licensed under the exact same license as TinyMCE itself.

Last edited by gforce301 (2006-05-30 00:55:33)

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

14

Re: Best way to "preserve" php coding on a page being edited?

Hello all,

     The Parser for the PHP plugin is finished.  I will have the entire BETA plugin ready for testing by anyone who wants it, tomorrow.  I appologize for it taking a little more time than I anticipated.  I did not intentionally mean to get anyone anxious and then make them wait.  I will start a new thread devoted to discussion of the plugin as soon as I put it up.  One question I have.  Is source forge the desirable place to put it up for access or is their another?  Anyone who could answer that real quick for me?  If no one reads this post before tomorrow afternoon then I believe source forge is where it will be hosted.  I will be checking this thread this evening while I am cleaning up the code if anyone has any questions.

gforce

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

15

Re: Best way to "preserve" php coding on a page being edited?

Nice!!

Mad props for the coding!!

I think Sourceforge is where most open source projects are posted. I haven't used it yet, just seen many who have.

ACM

Last edited by acm (2006-05-31 03:51:53)

16

Re: Best way to "preserve" php coding on a page being edited?

ok guys new thread started for the plugin.

PHP Plugin

will be posting info as soon as plugin is up on sf. should be within the hour.

gforce

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

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

17

Re: Best way to "preserve" php coding on a page being edited?

I assume this version will have duct tabe holding it together:)

18

Re: Best way to "preserve" php coding on a page being edited?

acm wrote:

I assume this version will have duct tabe holding it together:)

tape, string, gum from under the table at the diner wink anything I could get my hands on. btw it's up at sf the link is in the newly created php plugin thread.  Have you had a chance to check it out yet?

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

19

Re: Best way to "preserve" php coding on a page being edited?

Just a small notice..

Normally, "<?" should be avoid because it can be mis-parsed with "<?xml", so...

By the way... they are some really interesting nativ php functions to "beautify" code:
- mixed highlight_file ( string filename [, bool return] )
- mixed highlight_string ( string str [, bool return] )

it could be intersting to use them to made a "show source" thing..

Last edited by zeropaper (2006-06-01 09:42:12)

je suis distrait, distant, dispo, prêt à disparaître

20

Re: Best way to "preserve" php coding on a page being edited?

I understand your point on the format of an open php tag (<? vs <?php) and for myself I only use the <?php "long" form.  However, I attempted to make the parser able to accept any php code that is already in existance.  If you would not mind, please post this in the thread on the plugin itself and we will look into providing a configuration variable to enable or diable "short" form php open tags.

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