Advertisement

JCE editor stripping PHP date code Topic is solved

This forum is for general questions about extensions for Joomla! 5.x.

Moderators: pe7er, General Support Moderators

Forum rules
Forum Rules
Absolute Beginner's Guide to Joomla! <-- please read before posting, this means YOU.
Forum Post Assistant - If you are serious about wanting help, you will use this tool to help you post.
Windows Defender SmartScreen Issues <-- please read this if using Windows 10.
Post Reply
stuffdone
Joomla! Guru
Joomla! Guru
Posts: 736
Joined: Tue Oct 28, 2008 11:06 pm
Location: NE Florida
Contact:

JCE editor stripping PHP date code

Post by stuffdone » Sat Mar 23, 2024 11:13 pm

Trying to place date code in footer for copyright but JCE editor keeps commenting it out. I have profile set to permit php code but it still breaks the code.

<?php
echo date("Y") . "
";
?>

I have tried both with and without the <?php ?> and it comments out or only displays the code, not a date.
Last edited by toivo on Sat Mar 23, 2024 11:58 pm, edited 1 time in total.
Reason: mod note: typo in subject
--- http://www.Stuffdone.com ---
Wow. Doing web sites for over 28+ years now. Still learn new tricks...not bad for an old dog

Advertisement
User avatar
toivo
Joomla! Master
Joomla! Master
Posts: 17848
Joined: Thu Feb 15, 2007 5:48 am
Location: Sydney, Australia

Re: JCE editor stripping PHP date code

Post by toivo » Sun Mar 24, 2024 1:08 am

Where was this PHP code inserted?

If your code was inserted into a newly created Custom module, please note that PHP code is not run unless the website has a plugin that executes PHP code, for example Sourcerer.
Toivo Talikka, Global Moderator

User avatar
Webdongle
Joomla! Master
Joomla! Master
Posts: 44681
Joined: Sat Apr 05, 2008 9:58 pm

Re: JCE editor stripping PHP date code

Post by Webdongle » Sun Mar 24, 2024 2:09 am

If 'Prepare Content' (in the Options tab) is set to Yes, will the php code be run then?

Did you allow php in the Profile Editor parameters Advanced?
http://www.weblinksonline.co.uk/
https://www.weblinksonline.co.uk/updating-joomla.html
"When I'm right no one remembers but when I'm wrong no one forgets".

User avatar
toivo
Joomla! Master
Joomla! Master
Posts: 17848
Joined: Thu Feb 15, 2007 5:48 am
Location: Sydney, Australia

Re: JCE editor stripping PHP date code

Post by toivo » Sun Mar 24, 2024 2:48 am

Webdongle wrote: Sun Mar 24, 2024 2:09 amIf 'Prepare Content' (in the Options tab) is set to Yes, will the php code be run then?
It will, as long as a plugin like Sourcerer is enabled and executes the code.
Toivo Talikka, Global Moderator

User avatar
leolam
Joomla! Master
Joomla! Master
Posts: 20661
Joined: Mon Aug 29, 2005 10:17 am
Location: Netherlands/ Germany/ S'pore/Bogor/ North America
Contact:

Re: JCE editor stripping PHP date code

Post by leolam » Sun Mar 24, 2024 3:01 pm

Yes @Toivo that is correct. You can use PHP-code directly with JCE if the mentioned plugin below is installed or sourcerer or similar plugin
Go to the tab Editor Parameters - Advanced. Set the option 'Allow PHP' to Yes, then Save & Close. Once you have installed and enabled the DirectPHP plugin, go to Extensions - Modules, create a new Custom module and you can now enter embed PHP scripts inside the HTML code
Alternative to sourcerer https://extensions.joomla.org/extension ... ss-script/

Leo 8)
Joomla's #1 Professional Services Provider:
#Joomla Professional Support: https://gws-desk.com -
#Joomla Specialized Hosting Solutions: https://gws-host.com -

stuffdone
Joomla! Guru
Joomla! Guru
Posts: 736
Joined: Tue Oct 28, 2008 11:06 pm
Location: NE Florida
Contact:

Re: JCE editor stripping PHP date code

Post by stuffdone » Sat Mar 30, 2024 3:49 pm

I did install sourcere but wasn't able to find the other extension suggested.

I ran into issues with that however as Sourcerer added <SPAN> with it's own CSS and each time I try to add to that to reduce the font size and save it, the PHP code is again commented out.

I tried using the CODE section to include the font size but that is stripped by Sorcerer and replaces by it's own css.

After multiple variations I gave up and hard coded 2024 for the copyright/credits and will just change again next hear.
--- http://www.Stuffdone.com ---
Wow. Doing web sites for over 28+ years now. Still learn new tricks...not bad for an old dog

User avatar
AMurray
Joomla! Master
Joomla! Master
Posts: 10270
Joined: Sat Feb 13, 2010 7:35 am
Location: Australia

Re: JCE editor stripping PHP date code

Post by AMurray » Sat Mar 30, 2024 9:54 pm

Sourcer doesn't "add its own CSS" Your site uses whatever CSS you specify (i.e. custom CSS needs to go in the template's user.css file).
Regards - A Murray
General Support Moderator

User avatar
toivo
Joomla! Master
Joomla! Master
Posts: 17848
Joined: Thu Feb 15, 2007 5:48 am
Location: Sydney, Australia

Re: JCE editor stripping PHP date code

Post by toivo » Sat Mar 30, 2024 10:32 pm

As an afterthought, it is possible to customise the Joomla Footer module that changes the year in the copyright clause automatically. Create a template override of mod_footer and edit the PHP code in the override file. That way future Joomla updates do not overwrite the custom code.

If the site uses Cassiopeia, the override file is templates/cassiopeia/html/mod_footer/default.php. Copy and paste the following code into default.php with your modifications:

Code: Select all

<?php
/**
 * @package     Joomla.Site
 * @subpackage  mod_footer
 *
 * @copyright   (C) 2006 Open Source Matters, Inc. <https://www.joomla.org>
 * @license     GNU General Public License version 2 or later; see LICENSE.txt
 */
defined('_JEXEC') or die;
use Joomla\CMS\Language\Text;
use Joomla\CMS\HTML\HTMLHelper;

$lineone = 'Copyright &#169; ' . HTMLHelper::_('date', 'now', 'Y') . ' Example Pty Ltd. All Rights Reserved.'
?>
<div class="mod-footer">
    <div class="footer1"><?php echo $lineone; ?></div>
</div>
footer-before.png
footer-after.png
You do not have the required permissions to view the files attached to this post.
Toivo Talikka, Global Moderator

AlCher
Joomla! Intern
Joomla! Intern
Posts: 62
Joined: Mon Sep 19, 2005 8:33 am

Re: JCE editor stripping PHP date code

Post by AlCher » Mon Apr 01, 2024 10:09 am

toivo wrote: Sat Mar 30, 2024 10:32 pm If the site uses Cassiopeia, the override file is templates/cassiopeia/html/mod_footer/default.php.
Thank you, Toivo!
A simple, excellent solution.
Sincerely, Alexander

User avatar
imanickam
Joomla! Master
Joomla! Master
Posts: 28286
Joined: Wed Aug 13, 2008 2:57 am
Location: Chennai, India

Re: JCE editor stripping PHP date code

Post by imanickam » Tue Apr 02, 2024 3:43 am

If there is not much of processing to be done for displaying the footer, the footer module text could be changed using language override as shown below:

Original language sting:

Code: Select all

MOD_FOOTER_LINE1="Copyright &#169; %date% %sitename%. All Rights Reserved." ; Note : %date% will be auto replaced by current year! Don't translate
MOD_FOOTER_LINE2="<a href=\"https://www.joomla.org\">Joomla!</a> is Free Software released under the <a href=\"https://www.gnu.org/licenses/gpl-2.0.html\">GNU General Public License.</a>"
Overridden language sting:

Code: Select all

MOD_FOOTER_LINE1="Copyright &#169; %date% Example Pty Ltd. All Rights Reserved. All Rights Reserved." ; Note : %date% will be auto replaced by current year! Don't translate
MOD_FOOTER_LINE2=""
Note:
Ilagnayeru (MIG) Manickam | இளஞாயிறு மாணிக்கம்
Joomla! - Global Moderators Team | Joomla! Core - Tamil (தமிழ்) Translation Team Coordinator
Former Joomla! Translations Coordination Team Lead
Eegan - Support the poor and underprivileged

Advertisement

Post Reply

Return to “Extensions for Joomla! 5.x”