Kookaburra PHP Syntax Error in Sample

I am trying to get PHP working in Kookaburra. When I enable PHP and use the phplugins-kookaburra-test.php file and uncomment the sample “insert custom CSS into the document head” I get a syntax error. Please see the attachment. Does anybody know what the issue is? Thanks.

I don’t know why the sample code doesn’t work (I’m not that familiar with <<<SCRIPT)

But try this instead

// Insert custom CSS into the document head
		function style() {
			echo '
				<style>
					* { background-color: rgba(255, 0, 0, 0.25) !important; }
				</style>
			';
			return false;
		} // END /**/

@rod_barbee , it’s called heredoc (among others).

I’m wondering it the code doesn’t work since there are whitespaces before the second SCRIPT.

1 Like

I just tested that function as it is in phplugins-kookaburra-sample.php and it’s working fine or me.

there may be another syntax error in the file. Can you post the entire file?

It looks like there is something with the syntax of the sample file that is not liked by the PHP on my hosts server. Here is a test I created from the sample file with comments about what is going on. The sample function creates a syntax error in the editor when uncommented. Rod’s function works just fine. Thanks for your help with this.

The upload button seems to allow me to only upload images. Is there something I need to do to upload the php file?

just post the code. click on </> in the toolbar at the top of the post text area and paste

<?php
	function userLoad($style, $path) {
		$g_tsvrl = explode(' ', $style); // Extract gallery type
		define ('G_STYLE', strtoupper($g_tsvrl[1])); // and set global for later
		$g_path = str_ireplace('\\','/',$path); // change \ to /
		$chunks = explode('/',$g_path); // and put into array
		define ('G_PATH', strtoupper($chunks[count($chunks)-2])); // gallery folder name is second to last
		//define ( 'TTG_SITE', ''); // set new site root for navigation, resources, etc.
	}

	if (defined('BACKLIGHT_HOOK')) {
		require_once(realpath(BACKLIGHT_HOOK).'/modules/module-designer/application/helpers/APHPlugins.php');
	}

	class PHPlugins extends APHPlugins {
	/**
	 *
	 *  *************************************************************************************
	 *  *                                                                                   *
	 *  * Warning! When using echo or print special care must be qiven to using quotes.     *
	 *  *                                                                                   *
	 *  * Strings inside single quotes must contain only double quotes                      *
	 *  * or all single quotes must be escaped (ie \') or vice-versa                        *
	 *  *                                                                                   *
	 *  *************************************************************************************
	 *
	 *  A number of user exits are defined in all web engines - all are optional
	 *  (i.e. userLoad.php may be the only processing)
	 *
	 *  Some web engines will have additional exits defined, specific to that gallery type
	 *
	 *  Each is called with the same parameters:
	 *    %1 - TTG gallery-style gallery-release
	 *       - 3 blank delimited values
	 *         - %1.1 - 'TTG'
	 *         - %1.2 - string describing gallery type; no embedded blanks
	 *         - %1.3 - a series of two to three period delimited integers
	 *                  describing gallery release level; x.y or x.y.z
	 *    %2 - server filesystem file name and path of calling file
	 *
	 *  Defined exits:
	 *
	 *    userLoad
	 *      - return value ignored
	 *      - called immediately after this file returns
	 *      - called before any output is produced
	 *      - all header and response variables are accessible
	 *      - cookie and session processing can be initialized
	 *      - globals to be used by later hook calls can be defined
	 *
	 *    style
	 *      - return value ignored
	 *      - called after template stylesheets, before custom stylesheets
	 *      - encompasses nothing; use to insert styles into the <head>; use either:
	 *        - <link href="path/to/style.css" rel="stylesheet" />
	 *        - <style> ... </style>
	 *
	 *    head
	 *      - return value ignored
	 *      - called immediately before </head>
	 *      - encompasses nothing; use to insert content into the <head>
	 *
	 *    skipToContent
	 *      - if return=false, the "Skip to Content" link is omitted (not recommended)
	 *      - can be used to replace the "Skip to Content" link
	 * 
	 *    footer_top
	 *      - if return=false, the contents of the normal footer are skipped
	 *      - called immediately within the footer section
	 *      - encompasses the full contents of the footer; can be used to replace those contents
	 * 
	 *    footer_bottom
	 *      - return value ignored
	 *      - called last in the footer section
	 *      - encompasses nothing; use to insert content at the end of the footer section
	 * 
	 *    symbols_top
	 *      - if return=false, normal symbol definitions are skipped
	 *      - called within the SVG element, immediately before the symbol definitions
	 *      - fully encompasses the symbol definitions; can be used to replace them
	 * 
	 *    symbols_bottom
	 *      - return value ignored
	 *      - called immediately after the symbol definitions, before closing the SVG element
	 *      - encompasses nothing; use to insert additional symbols
	 * 
	 *    scripts
	 *      - return value ignored
	 *      - called immediately before </body>, after other scripts
	 *      - encompasses nothing; use to insert content or JavaScript at the very bottom of the page
	 * 
	**/

// SET USER FUNCTIONS BELOW
// Some example functions are included below. Feel free to delete or modify unwanted functions.
// ****************************************************************************************************



/* DELETE THIS LINE
		// Basic structure for a PHPlugins function
		function _HOOK_() {
			echo <<<SCRIPT

        // do HTML here.

      SCRIPT;
			return false;
		} // END /**/



/* DELETE THIS LINE - when this is deleted the code editor shows syntax errors
//              and all code snippets from here to the end become uncommented
		// Insert custom CSS into the document head
		function style() {
			echo <<<SCRIPT
				<style>
					* { background-color: rgba(255, 0, 0, 0.25) !important; }
				</style>
			SCRIPT;
			return false;
		} // END /**/



/* DELETE THIS LINE - this will work fine, code provided by Rod  
// Insert custom CSS into the document head
        function style() {
            echo '
                    <style>
                            * { background-color: rgba(255, 0, 0, 0.25) !important; }
                    </style>
            ';

            return false;

        } // END /**/

	// ****************************************************************************************************
	// END USER FUNCTIONS
	}
?>

I copied the code you posted and put it in. a text/code editor. I deleted the indicated line and none of the other functions were uncommented.

Further, I uploaded and used it and it’s working for me.

It could be as you guessed earlier: the php used by your host. What version is being used on your site? You can see by going to Backlight > Admin > Special Links > View PHP info

Zend Engine PHP Version 7.2.34 I can provide all the info if you are curious.

My guess is that the issue is due to your host using php 7.2

As Daniel pointed out above, using <<< SCRIPT is called heredoc and from what I’ve read, the syntax for using that changed in php 7.3.

You don’t need to use heretic though; it’s just a way of not having to escape quote marks in the code.

But if you want to use it, see if you can update the version of php that your site uses. I believe Backlight is compatible with php 8.2

Prior to 7.3 the trailing HEREDOC delimiter had to be placed at the very start of the line. Have you tried that?

This is why it’s usually best for me to stay in my lane, the hell away from the PHP. :sweat_smile:

Do you reckon it would be worthwhile for me to make the file uglier and put these at the start of the line by default?

@Matthew, yes I think that would be best. I was not even aware that PHP had made that change to allow whitespace before the ending delimiter. After so many years of it being that way, the version with space looks incorrect to me, whether prettier or not.