Skip to content

Commit

Permalink
Removed references to ingores instead to return error on comment/post
Browse files Browse the repository at this point in the history
  • Loading branch information
eusonlito committed Jun 26, 2018
1 parent 8e7d384 commit 765f3a5
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 25 deletions.
9 changes: 2 additions & 7 deletions www/backend/comment_ajax.php
Expand Up @@ -171,13 +171,8 @@ function check_and_save($comment, $link)
return _('comentario no insertado, enlace a sitio deshabilitado (y usuario reciente)');
}

if ($error = User::checkReferencesToIgnores($comment->content)) {
return $error;
}

if ($error = User::checkReferencesToLinkCommentsIgnores($link, $comment->content)) {
return $error;
}
$comment->content = User::removeReferencesToIgnores($comment->content);
$comment->content = User::removeReferencesToLinkCommentsIgnores($link, $comment->content);

if (mb_strlen($comment->content) > 0) {
$comment->store();
Expand Down
8 changes: 2 additions & 6 deletions www/backend/post_edit.php
Expand Up @@ -88,9 +88,7 @@ function save_post($post_id)
$poll->read('post_id', $post->id);
$poll->post_id = $post->id;

if ($error = User::checkReferencesToIgnores($post->content)) {
die('ERROR: '.$error);
}
$post->content = User::removeReferencesToIgnores($post->content);

$db->transaction();

Expand Down Expand Up @@ -139,9 +137,7 @@ function save_post($post_id)
die('ERROR: '._('comentario grabado previamente'));
}

if ($error = User::checkReferencesToIgnores($post->content)) {
die('ERROR: '.$error);
}
$post->content = User::removeReferencesToIgnores($post->content);

$poll = new Poll;

Expand Down
9 changes: 2 additions & 7 deletions www/libs/comment.php
Expand Up @@ -721,13 +721,8 @@ public static function save_from_post($link, $redirect = true)
return _('comentario duplicado');
}

if ($error = User::checkReferencesToIgnores($comment->content)) {
return $error;
}

if ($error = User::checkReferencesToLinkCommentsIgnores($link, $comment->content)) {
return $error;
}
$comment->content = User::removeReferencesToIgnores($comment->content);
$comment->content = User::removeReferencesToLinkCommentsIgnores($link, $comment->content);

if ($karma_penalty > 0) {
$db->rollback();
Expand Down
32 changes: 27 additions & 5 deletions www/libs/user.php
Expand Up @@ -1122,9 +1122,20 @@ public static function checkReferencesToIgnores($message)
);
';

if ($ignored = $db->get_col($query)) {
return sprintf(_('No es posible hacer referencias a usuarios que te tienen ignorado (%s).'), implode(', ', $ignored));
return $db->get_col($query);
}

public static function removeReferencesToIgnores($message)
{
if (!($ignores = static::checkReferencesToIgnores($message))) {
return $message;
}

foreach ($ignores as $user) {
$message = preg_replace('/@'.preg_quote($user, '/').'(,[0-9]+)?/', '', $message);
}

return $message;
}

public static function checkReferencesToLinkCommentsIgnores($link, $message)
Expand All @@ -1142,7 +1153,7 @@ public static function checkReferencesToLinkCommentsIgnores($link, $message)
}

$query = '
SELECT SQL_CACHE `users`.`user_login`
SELECT SQL_CACHE `comments`.`comment_order`
FROM `comments`, `friends`, `users`
WHERE (
`comments`.`comment_link_id` = "'.(int)$link->id.'"
Expand All @@ -1155,8 +1166,19 @@ public static function checkReferencesToLinkCommentsIgnores($link, $message)
);
';

if ($ignored = $db->get_col($query)) {
return sprintf(_('No es posible hacer referencias a usuarios que te tienen ignorado (%s).'), implode(', ', $ignored));
return $db->get_col($query);
}

public static function removeReferencesToLinkCommentsIgnores($link, $message)
{
if (!($ignores = static::checkReferencesToLinkCommentsIgnores($link, $message))) {
return $message;
}

foreach ($ignores as $order) {
$message = preg_replace('/#'.$order.'([^0-9]|$)/', '$1', $message);
}

return $message;
}
}

0 comments on commit 765f3a5

Please sign in to comment.