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?
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.
For the moment I even disabled the CKE by default so I'm in source. I type my php, switch to CKE (WYSIWYG) en click on source. That gives me the result above. I never use nor see any php in WYSIWYG but switching between the two is not doable for me this way.
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 ...
I was able to replicate your error as well by using the code snippet you provided. Seems that having the php code enclosed within the img tag is the culprit, because if I take the php code out and place it by itself, all works as expected.
Does anyone have a different solution? I have the same problem with MANY pages that output the url using php code. Changing this to the above will last days.... Please help.
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
eval()
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?
What would be the syntax to implement this per page on a case by case basis, so back-end editors can have it enabled and public side editors not have it enabled?
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.
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
http://peterpetrik.com/blog/ckeditor-and-geshi-filter
Re: PHP code in CKEditor
Before:
After:
<img border="0" alt="" src="/sites/default/files/catalog/<!--{cke_protected}%3C%3Fphp%20echo%20%24_POST%5B'product'%5D%3B%20%3F%3E-->.jpg" />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
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:
<?php echo eval('?>' . utf8_encode($row['body']) . '<?php '); ?>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.