Skip to content

Commit a9ddc79

Browse files
#12041 Support direct use of vue.js components in submission wizard (#12042)
1 parent f155593 commit a9ddc79

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

classes/template/PKPTemplateManager.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,8 @@ public function initialize(PKPRequest $request)
359359
$this->registerPlugin('modifier', 'count', count(...));
360360
$this->registerPlugin('modifier', 'intval', intval(...));
361361
$this->registerPlugin('modifier', 'json_encode', json_encode(...));
362+
// Register the safe JSON modifier
363+
$this->registerPlugin('modifier', 'json_encode_html_attribute', $this->smartyJsonEncodeHtmlAttribute(...));
362364
$this->registerPlugin('modifier', 'uniqid', uniqid(...));
363365
$this->registerPlugin('modifier', 'substr', substr(...));
364366
$this->registerPlugin('modifier', 'strstr', strstr(...));
@@ -1792,6 +1794,26 @@ public function smartyTranslate(array $params, Smarty_Internal_Template $smarty)
17921794
return $count === null ? __($key, $variables, $locale) : __p($key, $count, $variables, $locale);
17931795
}
17941796

1797+
/**
1798+
* Smarty modifier: json_encode_html_attribute
1799+
*
1800+
* Encodes a value to JSON with full HTML-attribute safety.
1801+
* Escapes ", ', <, >, & as \u0022, \u0027, \u003C, \u003E, \u0026
1802+
* so the output can be safely placed inside any HTML attribute
1803+
*/
1804+
function smartyJsonEncodeHtmlAttribute($value)
1805+
{
1806+
return json_encode(
1807+
$value,
1808+
JSON_HEX_TAG // < →
1809+
| JSON_HEX_AMP // & →
1810+
| JSON_HEX_APOS // ' →
1811+
| JSON_HEX_QUOT // " →
1812+
| JSON_UNESCAPED_UNICODE
1813+
| JSON_UNESCAPED_SLASHES // optional but highly recommended
1814+
);
1815+
}
1816+
17951817
/**
17961818
* Smarty usage: {html_options_translate ...}
17971819
* For parameter usage, see http://smarty.php.net/manual/en/language.function.html.options.php

templates/submission/wizard.tpl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,8 @@
106106
{foreach from=$reviewSteps item=$step}
107107
{if $step.reviewTemplate}
108108
{include file=$step.reviewTemplate}
109+
{elseif $step.component}
110+
<component :is="'{$step.component}'" v-bind='{$step.props|json_encode_html_attribute}'></component>
109111
{/if}
110112
{call_hook name="Template::SubmissionWizard::Section::Review" submission=$submission step=$step.id}
111113
{/foreach}
@@ -120,6 +122,7 @@
120122
</span>
121123
</transition>
122124
</template>
125+
<component v-else-if="section.component" :is="section.component" v-bind="section?.props || {}"></component>
123126
<pkp-form
124127
v-if="section.type === 'confirm'"
125128
v-bind="section.form"

0 commit comments

Comments
 (0)