Jump to content

PHP code from page file seems to be interpreted differently in an essentially identical file.


bobbintb

Recommended Posts

I was dissecting some of the webui *.page files to copy some UI elements for my plugin. I reduced the `ShareEdit.page` file to this:
 

Menu="Share:1"
Title="Share Settings"
Tag="share-alt-square"
---
<?
$width = [123,300];
?>

<form markdown="1" name="share_edit" method="POST" action="/update.htm" target="progressFrame" onsubmit="return prepareEdit()"<?=$name?:">"?>
<div markdown="1" class="shade-<?=$display['theme']?>">
_(Included disk(s))_:
: <select id="s1" name="shareInclude1" multiple>
  <?foreach ($shares as $list):?>
  <?=mk_option("", $list['name'], compress($list['name']))?>
  <?endforeach;?>
  </select>

:share_edit_included_disks_help:

_(Excluded disk(s))_:
: <select id="s2" name="shareExclude1" multiple>
<?foreach ($shares as $list):?>
  <?=mk_option("", $list['name'], compress($list['name']))?>
  <?endforeach;?>
  </select>

:share_edit_excluded_disks_help:
</div>

&nbsp;
: <input type="button" value="_(Done)_" onclick="done()">
</form>

<script>



function initializeDropdown(selector, emptyText, width, firstItemChecksAll = false) {
	try {
		$(selector).dropdownchecklist({
			emptyText: emptyText,
			width: width,
			explicitClose: "..._(close)_",
			firstItemChecksAll: firstItemChecksAll
		});
	} catch (e) {
		console.error(`Error initializing ${selector}: ` + e.message);
	}
}

function destroyDropdownIfExists(selector) {
	try {
		$(selector).dropdownchecklist('destroy');
	} catch (e) {
		if (e.message.includes('prior to initialization')) {
			console.log(`${selector} not initialized, skipping destroy.`);
		} else {
			console.error(`Error destroying ${selector}: ` + e.message);
		}
	}
}

function readShare() {
	/* Declare variables at the function scope */
	var name, data, disk, include, exclude, i, j;

	name = $('select[name="readshare"]').val();
	initDropdown(true);
}

/* Remove characters not allowed in share name. */
function checkName(name) {
	/* Declare variables at the function scope */
	var isValidName;

	isValidName = /^[A-Za-z0-9-_.: ]*$/.test(name);

	if (isValidName) {
		$('#zfs-name').hide();
	} else {
		$('#zfs-name').show();
	}
}

$(function() {
	initializeDropdown('#s1', "_(Select shares to monitor...)_", <?=$width[1]?>);
	initializeDropdown('#s2', "_(None)_", <?=$width[1]?>);
	checkName($('#shareName').val());
});
</script>


I copied that, changed the top three lines accordingly for my plugin, and saved it in my plugin folder with a different name. It shows the literal text:
 

Included disk(s):
: <select id="s1" name="shareInclude1" multiple>
    <?foreach ($shares as $list):?>
        <?=mk_option("", $list['name'], compress($list['name']))?>
    <?endforeach;?>
</select>

:share_edit_included_disks_help:

Excluded disk(s):
: <select id="s2" name="shareExclude1" multiple>
    <?foreach ($shares as $list):?>
        <?=mk_option("", $list['name'], compress($list['name']))?>
    <?endforeach;?>
</select>

:share_edit_excluded_disks_help:


Here is a visual comparison:
image.thumb.png.fb844813a59b15b576f3fa3d3bde7dce.png

image.thumb.png.2d008aa994587b3e43861823d19b1248.png
I've had similar issue before but worked around them. There must be something I am missing or don't understand about the plugin system because I can't make sense of it. As far as my understanding goes, I don't see why the same code is being interpreted differently.

Can someone enlighten me?

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...