From b7eec9e359337a0fa129dc3f050d8fc83242c59c Mon Sep 17 00:00:00 2001 From: Stanislas Date: Wed, 10 Jul 2024 11:17:13 +0200 Subject: [PATCH] Fix(Core): fix js/css injection conflict with other plugin --- css/fields.css | 3 --- setup.php | 32 +++++++++++++++++++++++++++----- 2 files changed, 27 insertions(+), 8 deletions(-) diff --git a/css/fields.css b/css/fields.css index ab68fd4e..c6a46935 100644 --- a/css/fields.css +++ b/css/fields.css @@ -51,6 +51,3 @@ div.fields_clear { clear: both; width:100%; } -.drag { - background: none !important; -} \ No newline at end of file diff --git a/setup.php b/setup.php index 74833020..190aec75 100644 --- a/setup.php +++ b/setup.php @@ -144,11 +144,16 @@ function plugin_init_fields() $PLUGIN_HOOKS['pre_item_purge']['fields']['Profile'] = ["PluginFieldsProfile", "deleteProfile"]; //load drag and drop javascript library on Package Interface - $PLUGIN_HOOKS['add_javascript']['fields'][] = "lib/redips-drag-min.js"; - if (!$debug && file_exists(__DIR__ . '/js/drag-field-row.min.js')) { - $PLUGIN_HOOKS['add_javascript']['fields'][] = 'js/drag-field-row.min.js'; - } else { - $PLUGIN_HOOKS['add_javascript']['fields'][] = 'js/drag-field-row.js'; + + if ( + plugin_fields_script_endswith("container.form.php") + ) { + $PLUGIN_HOOKS['add_javascript']['fields'][] = "lib/redips-drag-min.js"; + if (!$debug && file_exists(__DIR__ . '/js/drag-field-row.min.js')) { + $PLUGIN_HOOKS['add_javascript']['fields'][] = 'js/drag-field-row.min.js'; + } else { + $PLUGIN_HOOKS['add_javascript']['fields'][] = 'js/drag-field-row.js'; + } } } @@ -189,6 +194,23 @@ function plugin_init_fields() } +/** + * Check if the script name finish by + * + * @param string $scriptname + * @return boolean + */ +function plugin_fields_script_endswith($scriptname) +{ + //append plugin directory to avoid dumb errors... + $scriptname = 'fields/front/' . $scriptname; + $script_name = $_SERVER['SCRIPT_NAME']; + + return substr($script_name, -strlen($scriptname)) === $scriptname; +} + + + /** * Get the name and the version of the plugin * REQUIRED