From a6b322b178e49af012b0b38a2d15bd551e552221 Mon Sep 17 00:00:00 2001 From: src386 Date: Thu, 17 Mar 2016 13:44:43 +0100 Subject: [PATCH] update to movim upstream --- sources/app/assets/js/movim_electron.js | 13 +++++ sources/app/helpers/StringHelper.php | 50 ++++--------------- sources/app/models/message/Message.php | 4 +- .../widgets/AccountNext/_accountnext_oob.tpl | 5 +- .../app/widgets/Contact/_contact_explore.tpl | 2 +- .../app/widgets/Contact/_contact_public.tpl | 13 +++-- sources/app/widgets/Post/Post.php | 1 + sources/system/Picture.php | 12 +++-- sources/system/controllers/BaseController.php | 1 + 9 files changed, 46 insertions(+), 55 deletions(-) create mode 100644 sources/app/assets/js/movim_electron.js diff --git a/sources/app/assets/js/movim_electron.js b/sources/app/assets/js/movim_electron.js new file mode 100644 index 0000000..f5c03d1 --- /dev/null +++ b/sources/app/assets/js/movim_electron.js @@ -0,0 +1,13 @@ +/** + * @brief Open the URLs in the default browser + */ +if(typeof require !== 'undefined') { + document.addEventListener('click', function(event) { + if(event.target.target == '_blank' + || (event.target.hostname != null && event.target.hostname != BASE_HOST)) { + event.preventDefault(); + var shell = require('electron').shell; + shell.openExternal(event.target.href); + } + }); +} diff --git a/sources/app/helpers/StringHelper.php b/sources/app/helpers/StringHelper.php index 1ea7f95..5e039a4 100644 --- a/sources/app/helpers/StringHelper.php +++ b/sources/app/helpers/StringHelper.php @@ -98,46 +98,6 @@ function addHFR($string) { function prepareString($string, $large = false, $preview = false) { $string = addUrls($string, $preview); - // We remove all the style attributes - /*$string = preg_replace_callback( - '/(<[^>]+) style=".*?"/i', function($match) { - return $match[1]; - }, $string - ); - - // Twitter hashtags - $string = preg_replace_callback( - "/ #[a-zA-Z0-9_-]{3,}/", function ($match) { return ' '. trim($match[0]). ''; }, ' ' . $string); - $string = preg_replace_callback( - "/ @[a-zA-Z0-9_-]{3,}/", function ($match) { - return - ' '. - trim($match[0]). - ''; - }, ' ' . $string - ); - - //remove all scripts - $string = preg_replace_callback( - '#<[/]?script[^>]*>#is', function ($match) { - return ''; - }, ' ' . $string - ); - //remove all iframe - $string = preg_replace_callback( - '#<[/]?iframe[^>]*>#is', function ($match) { - return ''; - }, ' ' . $string - ); - //remove all iframe - $string = preg_replace_callback( - '#<[/]?ss[^>]*>#is', function ($match) { - return ''; - }, ' ' . $string - );*/ - // We add some smileys... $emoji = MovimEmoji::getInstance(); $string = $emoji->replace($string, $large); @@ -157,6 +117,16 @@ function fixSelfClosing($string) { , $string); } +/** + * @desc Escape the unescaped ampersand + */ +function escapeAmpersands($string) { + return preg_replace( + '/&[^; ]{0,6}.?/e', + "((substr('\\0',-1) == ';') ? '\\0' : '&'.substr('\\0',1))", + $string); +} + /** * Remove the content, body and html tags */ diff --git a/sources/app/models/message/Message.php b/sources/app/models/message/Message.php index 881947f..81e92c9 100644 --- a/sources/app/models/message/Message.php +++ b/sources/app/models/message/Message.php @@ -98,8 +98,10 @@ class Message extends Model { $images = (bool)($this->type == 'chat'); + \movim_log((string)$stanza->html->body); + if($stanza->html) { - $xhtml = new \SimpleXMLElement(''.(string)$stanza->html->body.''); + $xhtml = new \SimpleXMLElement(''.escapeAmpersands((string)$stanza->html->body).''); $xhtml->registerXPathNamespace('xhtml', 'http://www.w3.org/1999/xhtml'); $img = $xhtml->xpath('//xhtml:img/@src')[0]; if($img) { diff --git a/sources/app/widgets/AccountNext/_accountnext_oob.tpl b/sources/app/widgets/AccountNext/_accountnext_oob.tpl index 225e262..380c71c 100644 --- a/sources/app/widgets/AccountNext/_accountnext_oob.tpl +++ b/sources/app/widgets/AccountNext/_accountnext_oob.tpl @@ -1,8 +1,9 @@ -