diff --git a/src/Module/Like.php b/src/Module/Item/Activity.php similarity index 78% rename from src/Module/Like.php rename to src/Module/Item/Activity.php index 8d699be5e..69f5db75d 100644 --- a/src/Module/Like.php +++ b/src/Module/Item/Activity.php @@ -19,7 +19,7 @@ * */ -namespace Friendica\Module; +namespace Friendica\Module\Item; use Friendica\BaseModule; use Friendica\Content\Text\BBCode; @@ -34,9 +34,10 @@ use Friendica\Network\HTTPException; use Friendica\Util\Strings; /** - * Performs a like and optionally redirects to a return path + * Performs an activity (like, dislike, announce, attendyes, attendno, attendmaybe) + * and optionally redirects to a return path */ -class Like extends BaseModule +class Activity extends BaseModule { public static function rawContent(array $parameters = []) { @@ -44,16 +45,12 @@ class Like extends BaseModule throw new HTTPException\ForbiddenException(); } - $verb = Strings::escapeTags(trim($_GET['verb'])); - - if (!$verb) { - $verb = 'like'; + if (empty($parameters['id']) || empty($parameters['verb'])) { + throw new HTTPException\BadRequestException(); } - $app = DI::app(); - - // @TODO: Replace with parameter from router - $itemId = (($app->argc > 1) ? Strings::escapeTags(trim($app->argv[1])) : 0); + $verb = $parameters['verb']; + $itemId = $parameters['id']; if (in_array($verb, ['announce', 'unannounce'])) { $item = Post::selectFirst(['network'], ['id' => $itemId]); @@ -66,22 +63,27 @@ class Like extends BaseModule throw new HTTPException\BadRequestException(); } - // Decide how to return. If we were called with a 'return' argument, - // then redirect back to the calling page. If not, just quietly end - $returnPath = $_REQUEST['return'] ?? ''; - - if (!empty($returnPath)) { + // See if we've been passed a return path to redirect to + $return_path = $_REQUEST['return'] ?? ''; + if (!empty($return_path)) { $rand = '_=' . time(); - if (strpos($returnPath, '?')) { + if (strpos($return_path, '?')) { $rand = "&$rand"; } else { $rand = "?$rand"; } - DI::baseUrl()->redirect($returnPath . $rand); + DI::baseUrl()->redirect($return_path . $rand); } - System::jsonExit(['status' => 'OK']); + $return = [ + 'status' => 'ok', + 'item_id' => $itemId, + 'verb' => $verb, + 'state' => 1, + ]; + + System::jsonExit($return); } private static function performDiasporaReshare(int $itemId) diff --git a/static/routes.config.php b/static/routes.config.php index 5a2ee2ffd..564b920d6 100644 --- a/static/routes.config.php +++ b/static/routes.config.php @@ -292,10 +292,10 @@ return [ '/item' => [ '/ignore/{id}' => [Module\Item\Ignore::class, [R::GET]], - '/{id:\d+}/pin' => [Module\Item\Pin::class, [ R::POST]], + '/{id:\d+}/activity/{verb}' => [Module\Item\Activity::class, [ R::POST]], + '/{id:\d+}/pin' => [Module\Item\Pin::class, [ R::POST]], ], - '/like/{item:\d+}' => [Module\Like::class, [R::GET]], '/localtime' => [Module\Debug\Localtime::class, [R::GET, R::POST]], '/login' => [Module\Security\Login::class, [R::GET, R::POST]], '/logout' => [Module\Security\Logout::class, [R::GET, R::POST]], diff --git a/view/js/main.js b/view/js/main.js index 1503529d1..1e051de83 100644 --- a/view/js/main.js +++ b/view/js/main.js @@ -665,11 +665,11 @@ function imgdull(node) { * @param {string} verb The verb of the action * @param {boolean} un Whether to perform an activity removal instead of creation */ -function dolike(ident, verb, un) { +function doActivityItem(ident, verb, un) { unpause(); $('#like-rotator-' + ident.toString()).show(); verb = un ? 'un' + verb : verb; - $.get('like/' + ident.toString() + '?verb=' + verb, NavUpdate); + $.post('item/' + ident.toString() + '/activity/' + verb, NavUpdate); liking = 1; force_update = true; update_item = ident.toString(); diff --git a/view/templates/like_noshare.tpl b/view/templates/like_noshare.tpl index 4419a5b97..3272c2831 100644 --- a/view/templates/like_noshare.tpl +++ b/view/templates/like_noshare.tpl @@ -1,8 +1,8 @@
- + {{if $dislike}} - + {{/if}}
diff --git a/view/templates/wall_thread.tpl b/view/templates/wall_thread.tpl index 4b1a42785..7dcdb15a5 100644 --- a/view/templates/wall_thread.tpl +++ b/view/templates/wall_thread.tpl @@ -84,9 +84,9 @@
{{if $item.vote}}
- - {{if $item.vote.dislike}}{{/if}} - {{if $item.vote.announce}}{{/if}} + + {{if $item.vote.dislike}}{{/if}} + {{if $item.vote.announce}}{{/if}} {{if $item.vote.share}}{{/if}}
@@ -115,9 +115,9 @@ {{/if}} {{if $item.isevent }}
- - - + + +
{{/if}}
diff --git a/view/theme/frio/js/theme.js b/view/theme/frio/js/theme.js index fcf99dc5e..18215d5d5 100644 --- a/view/theme/frio/js/theme.js +++ b/view/theme/frio/js/theme.js @@ -774,13 +774,13 @@ function htmlToText(htmlString) { * @param {string} verb The verb of the action * @param {boolean} un Whether to perform an activity removal instead of creation */ -function doLikeAction(ident, verb, un) { +function doActivityItemAction(ident, verb, un) { if (verb.indexOf("attend") === 0) { $(".item-" + ident + " .button-event:not(#" + verb + "-" + ident + ")").removeClass("active"); } $("#" + verb + "-" + ident).toggleClass("active"); - dolike(ident, verb, un); + doActivityItem(ident, verb, un); } // Decodes a hexadecimally encoded binary string diff --git a/view/theme/frio/templates/like_noshare.tpl b/view/theme/frio/templates/like_noshare.tpl index dd3fa2e5f..df335c32e 100644 --- a/view/theme/frio/templates/like_noshare.tpl +++ b/view/theme/frio/templates/like_noshare.tpl @@ -3,7 +3,7 @@ @@ -13,7 +13,7 @@ class="btn-link button-likes{{if $responses.dislike.self}} active" aria-pressed="true{{/if}}" id="dislike-{{$id}}" title="{{$dislike_title}}" - onclick="doLikeAction({{$id}}, 'dislike'{{if $responses.dislike.self}}, true{{/if}});" + onclick="doActivityItemAction({{$id}}, 'dislike'{{if $responses.dislike.self}}, true{{/if}});" data-toggle="button"> {{$dislike}} {{/if}} diff --git a/view/theme/frio/templates/search_item.tpl b/view/theme/frio/templates/search_item.tpl index 835b3d667..3f03f822a 100644 --- a/view/theme/frio/templates/search_item.tpl +++ b/view/theme/frio/templates/search_item.tpl @@ -143,14 +143,14 @@ {{* Buttons for like and dislike *}} {{if $item.vote}} {{if $item.vote.like}} - + {{/if}} {{if $item.vote.like AND $item.vote.dislike}} {{/if}} {{if $item.vote.dislike}} - + {{/if}} {{if ($item.vote.like OR $item.vote.dislike) AND $item.comment_html}} @@ -254,9 +254,9 @@ {{* Event attendance buttons *}} {{if $item.isevent}} - - - + + + {{/if}} diff --git a/view/theme/frio/templates/wall_thread.tpl b/view/theme/frio/templates/wall_thread.tpl index b98cefb9c..b8286dd46 100644 --- a/view/theme/frio/templates/wall_thread.tpl +++ b/view/theme/frio/templates/wall_thread.tpl @@ -286,13 +286,13 @@ as the value of $top_child_total (this is done at the end of this file) {{* Buttons for like and dislike *}} {{if $item.vote}} {{if $item.vote.like}} - + {{/if}} {{if $item.vote.like AND $item.vote.dislike}} {{/if}} {{if $item.vote.dislike}} - + {{/if}} {{if ($item.vote.like OR $item.vote.dislike) AND $item.comment_html}} @@ -317,7 +317,7 @@ as the value of $top_child_total (this is done at the end of this file) {{/if}} {{/if}} {{if $item.vote.announce}} - + {{/if}} {{if $item.vote.share}} @@ -412,9 +412,9 @@ as the value of $top_child_total (this is done at the end of this file) {{* Event attendance buttons *}} {{if $item.isevent}} - - - + + + {{/if}} @@ -431,10 +431,10 @@ as the value of $top_child_total (this is done at the end of this file) {{if $item.vote}}
{{if $item.vote.like}} - + {{/if}} {{if $item.vote.dislike}} - + {{/if}}
{{/if}} @@ -455,11 +455,11 @@ as the value of $top_child_total (this is done at the end of this file) {{if $item.vote.announce}} {{* edit the posting *}}
  • {{if $item.responses.announce.self}} - + {{$item.vote.unannounce.1}} {{else}} - + {{$item.vote.announce.1}} {{/if}} @@ -486,9 +486,9 @@ as the value of $top_child_total (this is done at the end of this file) {{* Event attendance buttons *}} {{if $item.isevent}}
    - - - + + +
    {{/if}} diff --git a/view/theme/quattro/templates/photo_item.tpl b/view/theme/quattro/templates/photo_item.tpl index e14caa542..182607ab3 100644 --- a/view/theme/quattro/templates/photo_item.tpl +++ b/view/theme/quattro/templates/photo_item.tpl @@ -39,8 +39,8 @@ {{/if}} {{if $vote}} - {{$vote.like.1}} - {{$vote.dislike.1}} + {{$vote.like.1}} + {{$vote.dislike.1}} {{/if}} {{if $vote.share}} diff --git a/view/theme/quattro/templates/search_item.tpl b/view/theme/quattro/templates/search_item.tpl index dca5d31a1..70aa2ed86 100644 --- a/view/theme/quattro/templates/search_item.tpl +++ b/view/theme/quattro/templates/search_item.tpl @@ -58,10 +58,10 @@ {{/if}} {{if $item.vote.like}} - {{$item.vote.like.1}} + {{$item.vote.like.1}} {{/if}} {{if $item.vote.dislike}} - {{$item.vote.dislike.1}} + {{$item.vote.dislike.1}} {{/if}} {{if $item.vote.share}} diff --git a/view/theme/quattro/templates/wall_thread.tpl b/view/theme/quattro/templates/wall_thread.tpl index 5f682dd3e..58c68968b 100644 --- a/view/theme/quattro/templates/wall_thread.tpl +++ b/view/theme/quattro/templates/wall_thread.tpl @@ -121,12 +121,12 @@ {{/if}} {{if $item.vote}} - {{$item.vote.like.1}} + {{$item.vote.like.1}} {{if $item.vote.dislike}} - {{$item.vote.dislike.1}} + {{$item.vote.dislike.1}} {{/if}} {{if $item.vote.announce}} - {{$item.vote.announce.1}} + {{$item.vote.announce.1}} {{/if}} {{if $item.vote.share}} {{$item.vote.share.1}} @@ -135,9 +135,9 @@ {{if $item.isevent}}
    {{/if}} diff --git a/view/theme/smoothly/templates/wall_thread.tpl b/view/theme/smoothly/templates/wall_thread.tpl index 817d4d5ed..4f70ea6d5 100644 --- a/view/theme/smoothly/templates/wall_thread.tpl +++ b/view/theme/smoothly/templates/wall_thread.tpl @@ -94,12 +94,12 @@ {{if $item.vote}}