Browse Source

- New regex to parse the URLs

- Fix some CSS
- Fix the chat notification behaviour
- Fix some PHP warnings
pull/16/head
Jaussoin Timothée 10 years ago
parent
commit
8efcb56716
  1. 41
      app/helpers/StringHelper.php
  2. 5
      app/models/message/Message.php
  3. 1
      app/widgets/Chat/Chat.php
  4. 11
      app/widgets/Chat/chat.css
  5. 11
      app/widgets/Chats/Chats.php
  6. 4
      app/widgets/Chats/chats.js
  7. 2
      app/widgets/Contact/_contact.tpl
  8. 5
      bootstrap.php
  9. 2
      themes/material/css/list.css

41
app/helpers/StringHelper.php

@ -51,32 +51,35 @@ class MovimEmoji
* @desc Prepare the string (add the a to the links and show the smileys)
*
* @param string $string
* @param boolean display large emojis
* @param check the links and convert them to pictures (heavy)
* @return string
*/
function prepareString($string, $large = false) {
//replace begin by www
function prepareString($string, $large = false, $preview = false) {
// Add missing links
$string = preg_replace_callback(
'/(^|\s|>)(www.[^<> \n\r]+)/ix', function ($match) {
//print '<br />preg[1]';\system\Debug::dump($match);
if (strlen($match[2])>0) {
return stripslashes($match[1].'<a href=\"http://'.$match[2].'\" target=\"_blank\">'.$match[2].'</a>');
"/([\w\"'>]+\:\/\/[\w-?&;#+%~=\.\/\@]+[\w\/])/", function ($match) use($preview) {
if(!in_array(substr($match[0], 0, 1), array('>', '"', '\''))) {
if($preview) {
$embed = Embed\Embed::create($match[0]);
if($embed->type == 'photo'
&& $embed->images[0]['width'] <= 1024
&& $embed->images[0]['height'] <= 1024) {
$content = '<img src="'.$match[0].'"/>';
} else {
$content = $match[0];
}
} else {
return $match[2];
$content = $match[0];
}
}, ' ' . $string
return stripslashes('<a href=\"'.$match[0].'\" target=\"_blank\">'.$content.'</a>');
} else {
return $match[0];
}
}, $string
);
//replace begin by http - https (before www)
$string = preg_replace_callback(
'/(?(?=<a[^>]*>.+<\/a>)(?:<a[^>]*>.+<\/a>)|([^="\'])((?:https?):\/\/([^<> \n\r]+)))/ix', function ($match) {
if (isset($match[2]) && strlen($match[2])>0) {
return stripslashes($match[1].'<a href=\"'.$match[2].'\" target=\"_blank\">'.$match[3].'</a>');
} else {
return $match[0];
}
}, ' ' . $string
);
// We remove all the style attributes
$string = preg_replace_callback(
'/(<[^>]+) style=".*?"/i', function($match) {

5
app/models/message/Message.php

@ -76,9 +76,14 @@ class Message extends Model {
$this->body = (string)$stanza->body;
$this->subject = (string)$stanza->subject;
$images = (bool)($this->type == 'chat');
if($stanza->html) {
$this->html = \cleanHTMLTags($stanza->html->body->asXML());
$this->html = \fixSelfClosing($this->html);
$this->html = \prepareString($this->html, false, $images);
} else {
$this->html = \prepareString($this->body, false, $images);
}
if($stanza->delay)

1
app/widgets/Chat/Chat.php

@ -254,6 +254,7 @@ class Chat extends WidgetBase
}
$m->body = rawurldecode($message);
$m->html = prepareString($m->body, false, true);
$m->published = gmdate('Y-m-d H:i:s');
$m->delivered = gmdate('Y-m-d H:i:s');

11
app/widgets/Chat/chat.css

@ -56,6 +56,17 @@
/* Chatroom */
#chat_widget li span.icon {
top: 0%;
margin-top: 0.85rem;
}
#chat_widget li img {
max-height: 30rem;
max-width: 100%;
display: block;
}
#chat_widget li.room {
min-height: 3rem;
margin-bottom: 0.5rem;

11
app/widgets/Chats/Chats.php

@ -34,11 +34,8 @@ class Chats extends WidgetBase
} else {
// TODO notification overwrite issue
RPC::call('movim_delete', $from.'_chat_item');
$this->ajaxOpen($from);
$n = new Notification;
$n->ajaxGet();
RPC::call('movim_prepend', 'chats_widget_list', $this->prepareChat($from));
RPC::call('Chats.refresh');
}
}
}
@ -100,11 +97,7 @@ class Chats extends WidgetBase
RPC::call('movim_prepend', 'chats_widget_list', $this->prepareChat($jid));
RPC::call('Chats.refresh');
}/* else {
unset($chats[$jid]);
}
$chats[$jid] = 1;*/
}
function ajaxClose($jid)

4
app/widgets/Chats/chats.js

@ -19,6 +19,8 @@ var Chats = {
items[i].onmousedown = function(e) {
if(e.which == 2) {
Notification_ajaxClear('chat|' + this.dataset.jid);
Notification.current('chat');
Chats_ajaxClose(this.dataset.jid);
MovimTpl.hidePanel();
}
@ -29,6 +31,8 @@ var Chats = {
i++;
}
Notification_ajaxGet();
//Chat_ajaxGet();

2
app/widgets/Contact/_contact.tpl

@ -301,7 +301,7 @@
</ul>
{/if}
{if="$contactr->rostersubscription != 'both'"}
{if="$contactr && $contactr->rostersubscription != 'both'"}
<div class="card">
<ul class="middle">
<li class="condensed">

5
bootstrap.php

@ -101,10 +101,11 @@ class Bootstrap {
define('APP_VERSION', $this->getVersion());
define('APP_SECURED', $this->isServerSecured());
if(isset($_SERVER['HTTP_HOST'])) {
if(isset($_SERVER['HTTP_HOST'])
&& isset($_SERVER['SERVER_NAME'])) {
define('BASE_DOMAIN', $_SERVER["SERVER_NAME"]);
define('BASE_HOST', $_SERVER['HTTP_HOST']);
}
define('BASE_DOMAIN', $_SERVER["SERVER_NAME"]);
define('BASE_URI', $this->getBaseUri());
define('CACHE_URI', $this->getBaseUri() . 'cache/');

2
themes/material/css/list.css

@ -216,7 +216,7 @@ ul li div.bubble {
background-color: #E5E5E5;
border-color: #E5E5E5;
max-width: 100%;
min-width: 50%;
/*min-width: 50%;*/
float: left;
/*word-break: break-all;*/
}

Loading…
Cancel
Save