Skip to content

Commit cdecbbd

Browse files
committed
Extract decode entities into a method in the listener
1 parent f5a43aa commit cdecbbd

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

event/listener.php

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ public function pwa_icon_name($value, $key)
210210
*/
211211
public function pwa_short_sitename($value, $key)
212212
{
213-
$placeholder = $this->trim_shortname($this->config['sitename']);
213+
$placeholder = $this->trim_shortname($this->decode_entities($this->config['sitename']));
214214

215215
return '<input id="' . $key . '" type="text" size="40" maxlength="12" name="config[' . $key . ']" value="' . $value . '" placeholder="' . $placeholder . '">';
216216
}
@@ -242,7 +242,7 @@ public function validate_pwa_options($event)
242242
return;
243243
}
244244

245-
$short_name = html_entity_decode($event['cfg_array']['pwa_short_name'], ENT_QUOTES, 'UTF-8');
245+
$short_name = $this->decode_entities($event['cfg_array']['pwa_short_name']);
246246

247247
// Do not allow strings longer than 12 characters
248248
if (mb_strlen($short_name, 'UTF-8') > 12)
@@ -365,6 +365,17 @@ protected function can_use_notifications()
365365
*/
366366
protected function trim_shortname($name)
367367
{
368-
return utf8_substr(html_entity_decode($name, ENT_QUOTES, 'UTF-8'), 0, 12);
368+
return utf8_substr($name, 0, 12);
369+
}
370+
371+
/**
372+
* Decode entities, used primarily to fix emoji for display
373+
*
374+
* @param $text
375+
* @return string Decoded string
376+
*/
377+
protected function decode_entities($text)
378+
{
379+
return html_entity_decode($text, ENT_QUOTES, 'UTF-8');
369380
}
370381
}

0 commit comments

Comments
 (0)