I'm desperate. I never searched and tried so long to get something running. A few days ago I replaced FCKEditor with CKEditor. After setting it up I tried to edit a page with PHP code in it:
<?php global $user;echo $user->uid; ?>
and every time I go from source to normal view and back to source I see:
<!--{cke_protected}%3C%3Fphp%20global%20%24user%3Becho%20%24user-%3Euid%3B%20%3F%3E-->
I followed all instructions I could find but none worked. Maybe I'm not smart enough to understand
The most "logical" thing I ended up with is to put this line in the ckeditor/config.js:
CKEDITOR.config.protectedSource.push( /<\?[\s\S]*?\?>/g );
But ... nada
The only thing I want is that when I type in some PHP code, it stays that way. What did I wrong, what did I forgot, can someone explain in simple actions what to do?
Please help
Thanks in advance
Jan
Sat, 02/06/2010 - 02:10
#1
Re: PHP code in CKEditor
Works for me here with :
I am using a recent CKEditor snapshot FTW. Try that.
Thanks,
Zanpakutō
Re: PHP code in CKEditor
The protectedSource will leave your php code alone, but you won't be able to edit it in the WYSISWYG window. This will result in the php code being actually executed as the page loads.
If you're trying to display code on your site, you may need to use a syntax highlighter. I've documented my solution using GeSHi syntax filter at http://peterpetrik.com/blog/ckeditor-and-geshi-filter
Re: PHP code in CKEditor
Before:
After:
This only a small example but editing PHP is the case After: is a little bit difficult, don't you think? Is there something else I have to do to keep the code untouched?
Thanks in advance
Re: PHP code in CKEditor
Which means you shouldn't see any php code in the WYSIWYG window, only in the Source view.
Are you entering the php code in the WYSIWYG or in the Source view? From the symptoms you reference, it seems like you're trying to enter in WYSIWYG. Switch to Source view, enter your code, then save. See if that works.
Re: PHP code in CKEditor
Normally I have enabled CKE and switch to source when I want to change php. I would like to have this behavior back so I can work like before. I even thought switching back to FCK but that wouldn't solve the problem for the future.
So, is it possible the have NO changes when switching from WYSIWYG to source and back? I expected a simple option to switch it all off but ...
Many thanks already and in advance ^^
Re: PHP code in CKEditor
I would recommend you change your code to:
Re: PHP code in CKEditor
Re: PHP code in CKEditor
sorry if this reply is too late, but it seems that this patch solves the problem you have.
Re: PHP code in CKEditor
1.) Add the following line to config.js:
2.) Make sure to add your php code from the 'Source' view of the editor.
3.) When outputting your mixed html/php from the database, (let's say it's $row['body']), do it like this:
Step 1 prevents the <?php and ?> tags from being stripped before saving to the database. The default behavior strips these for security reasons, so this basically overrides this safety feature.
In Step 3, the function basically helps preserve the switching in and out of php.
I'm not an expert in CKEditor, so if I got something wrong, please let me know, but I hope this helps piece it together for someone.
Now what we need is a way to somehow display the php code in a block in the WYSIWYG view, so if someone else is editing a page I inserted PHP into, they will see it (and hopefully not delete it). As it stands, they could delete it without ever knowing it unless they looked at the Source view. Any suggestions?
Re: PHP code in CKEditor
Re: PHP code in CKEditor
I'm using OpenCart which makes use of CKEditor and am trying to input php to be ran on the cart's welcome screen.
I've added config.protectedSource.push(/<\?[\s\S]*?\?>/g); to the config file and I can confirm that when I save my source it appears to preserve the code correctly and no longer adds <!-- --> however the issue is that it does still add these when I leave the editor and attempt to look at the code on the main page.
Any suggestions?
Cheers
This is what I use...
I know this is an old topic, but this is still an issue...
I'm using the plugin "Show Protected" to show PHP, and edit my HTML/PHP mixed files.
It shows an icon where your hidden (protected) PHP code lives. When you click the icon, you can edit the source from a dialog.