You need to be logged in to post in the forum - Log In

An active JCE Pro Subscription is required to post in the forum - Buy a Subscription

Support is currently Offline

Official support hours
Monday to Friday
09:00 - 17:00 Europe/London (BST)

Please create a new Ticket and we will get back to you as soon as we can.

#116995 Latest JCE fails again in combination with Sorcerer and PHP code.

Posted in ‘Editor’
This is a public ticket

Everybody will be able to see its contents. Do not include usernames, passwords or any other sensitive information.

Latest post by BraGIS on Friday, 13 December 2024 13:17 GMT

BraGIS

In februari of this year we received a special version to be able to write PHP and Javascript code in a Joomla article. The version was: JCE Pro 2.9.62 Beta. That did the job correct. When I install the latest JCE, the error we had back then, returned. When an article is opened in the Code editor, JCE adds spaces. Example PHP code:

$db->('#__users');

When this is in the article and JCE opens the article, this is what happens: $db - > ('#__users'); That is not valid PHP code.

Is there a fix or are we stuck at versionJCE Pro 2.9.62 Beta?

Ryan

Please post a screenshot of the complete code you are trying to add in the editor.

Ryan Demmer

Lead Developer / CEO / CTO

Just because you're not paranoid doesn't mean everybody isn't out to get you.

BraGIS

This is working code that is displayed in the JCE code Editor with version: JCE Pro 2.9.62 Beta

{source raw="true"} 
<script>
  var infostr = <?php
    $userarr = [];
	try {      
	  $query = $db->getQuery(true);
	  $query->select($db->quoteName(['id', 'name']));
	  $query->from($db->quoteName('#__users'));
	  $db->setQuery($query);
	  $datas = $db->loadObjectList();
	  if (isset($datas)){
		foreach($datas as $data) {
		  $userarr[] = array('id' => $data->id, 'na' => $data->name);
		}
	  }
	}
	catch (\InvalidArgumentException $e) {
	  echo json_encode(array('error' => $e->getMessage()));
	}
	$query->clear();
  	echo "'".json_encode(array('users' => $userarr))."'"; ?> ;
	alert(infostr);
</script> {/source}

This is what I get in JCE code Editor with version: JCE Pro 2.9.82, no settings changed. Pay attention to all the inserted spaces. This is not valid code anymore when saved.

{source raw="true"}
<script>
	var infostr = < ? php
	$userarr = [];
	try {
		$query = $db - > getQuery(true);
		$query - > select($db - > quoteName(['id', 'name']));
		$query - > from($db - > quoteName('#__users'));
		$db - > setQuery($query);
		$datas = $db - > loadObjectList();
		if (isset($datas)) {
			foreach($datas as $data) {
				$userarr[] = array('id' => $data - > id, 'na' => $data - > name);
			}
		}
	} catch (\InvalidArgumentException $e) {
		echo json_encode(array('error' => $e - > getMessage()));
	}
	$query - > clear();

	echo "'".json_encode(array('users' => $userarr)).
	"'"; ? > ;

	alert(infostr);
</script> {/source}

Ryan

Please try this:

In Editor Profiles -> Editor Parameters -> Advanced, set Allow Custom XML to Yes and Protect Shortcode to No.

Change your code, by wrapping it in a custom element, eg: <sourcerer>, eg:

<sourcerer>
{source raw="true"} 
<script>
  var infostr = <?php
    $userarr = [];
	try {      
	  $query = $db->getQuery(true);
	  $query->select($db->quoteName(['id', 'name']));
	  $query->from($db->quoteName('#__users'));
	  $db->setQuery($query);
	  $datas = $db->loadObjectList();
	  if (isset($datas)){
		foreach($datas as $data) {
		  $userarr[] = array('id' => $data->id, 'na' => $data->name);
		}
	  }
	}
	catch (\InvalidArgumentException $e) {
	  echo json_encode(array('error' => $e->getMessage()));
	}
	$query->clear();
  	echo "'".json_encode(array('users' => $userarr))."'"; ?> ;
	alert(infostr);
</script> {/source}
</sourcerer>

Ryan Demmer

Lead Developer / CEO / CTO

Just because you're not paranoid doesn't mean everybody isn't out to get you.

BraGIS

Thank you Ryan for your reply. Unfortunately these settings:

In Editor Profiles -> Editor Parameters -> Advanced, set Allow Custom XML to Yes and Protect Shortcode to No.

Did not change the issue. When I open the article, I still get the extra spaces inserted, the code will be invalid.

The strange behaviour is that when I put the tag <sourcerer> in my code the way you described it, JCE Pro 2.9.62 Beta does not change anything surrounding this tag when opening in the code editor, but when I install JCE Pro 2.9.82, directly after the <sourcerer> tag, the </sourcerer> is placed:  <sourcerer></sourcerer>. This won't help either...

Ryan

Did not change the issue. When I open the article, I still get the extra spaces inserted, the code will be invalid.

Does this only happen in the Code tab? In my tests, I see tha spaces inserted in the Code tab only, not when I save the code in the editor.

Ryan Demmer

Lead Developer / CEO / CTO

Just because you're not paranoid doesn't mean everybody isn't out to get you.

BraGIS

Hi Brian, the spaces are not inserted when you save the article. In the database there are no extra spaces. They appear when the article opens. I have them in the Code tab and in the Editor tab. So working with JCE Pro 2.9.62 Beta, no spaces are added when the article opens, also not when the article is saved. Articles made in JCE Pro 2.9.62 Beta, show unwanted extra spaces after I update to JCE Pro 2.9.82, and open the article (no saving involved). All I want is the article text to be displayed in the Code editor exactly the way it is stored in the database.

Ryan

Please try JCE Pro 2.9.83 Beta - https://www.joomlacontenteditor.net/downloads/editor/pro/development

Clear you browser cache after install.

in Editor Profiles -> Plugin Parameters -> Code Editor, make sure the Format HTML option is set to No.

Ryan Demmer

Lead Developer / CEO / CTO

Just because you're not paranoid doesn't mean everybody isn't out to get you.

BraGIS

Thank you Ryan! JCE Pro 2.9.83 Beta fixed the issue. I hope the fix will be permanent in the next versions. Your help is appreciated. Keep up the good work!