Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change likes to reactions... #8187

Draft
wants to merge 59 commits into
base: release-3.0
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
130cca4
Initial commit to change likes to reactions...
Oldiesmann Apr 27, 2024
ab2b1d5
Create the reactions table and change the ID column to match SMF stan…
Oldiesmann Apr 28, 2024
08ca4ad
Handle upgrades - creating/renaming things as needed.
Oldiesmann Apr 29, 2024
5714530
Consistency is a good thing...
Oldiesmann Apr 29, 2024
47ebfbd
Update with changes from recurring events
Oldiesmann May 2, 2024
55fdca3
Merge branch 'smf3' of github.com:Oldiesmann/SMF21 into reactions
Oldiesmann May 3, 2024
9e85a05
Update permission and setting...
Oldiesmann May 4, 2024
0b0b869
Rename Like.php and the Like class. Also adjusted another language st…
Oldiesmann May 5, 2024
ac040fa
More renaming. Also some other minor fixes
Oldiesmann May 5, 2024
54a02fd
Missed something
Oldiesmann May 5, 2024
a089270
Pull in latest upstream changes
Oldiesmann May 5, 2024
f6bf12b
Merge branch 'smf3' of github.com:Oldiesmann/SMF21 into reactions
Oldiesmann May 11, 2024
632bb5f
Merge latest upstream changes
Oldiesmann May 16, 2024
b7e845b
Merge branch 'smf3' of github.com:Oldiesmann/SMF21 into reactions
Oldiesmann May 16, 2024
58a6dfb
Merge branch 'smf3' of github.com:Oldiesmann/SMF21 into reactions
Oldiesmann May 18, 2024
4a3289f
Add support for changing the order of available reactions
Oldiesmann May 18, 2024
bd372a2
Change getLikedMsgs to getReactedMsgs and update the logic slightly
Oldiesmann May 18, 2024
7f1ab57
Change a few more things...
Oldiesmann May 18, 2024
ab846bf
Merge branch 'release-3.0' of github.com:SimpleMachines/SMF into reac…
Oldiesmann May 27, 2024
0c39327
Fix a typo and update the stats info.
Oldiesmann May 27, 2024
09c5379
Language file tweak for stats.
Oldiesmann May 27, 2024
26bbca9
Merge branch 'smf3' of github.com:Oldiesmann/SMF21 into reactions
Oldiesmann May 29, 2024
7cea89f
Rename the template and a bunch of other stuff...
Oldiesmann Jun 1, 2024
b49770a
Create a new trait for loading reactions.
Oldiesmann Jun 2, 2024
0cbfb60
This is handled by the trait so don't need it now...
Oldiesmann Jun 2, 2024
5ab2119
A couple of minor tweaks...
Oldiesmann Jun 6, 2024
5cb6c5d
Add the initial file for the admin stuff and modify the admin menu
Oldiesmann Jun 8, 2024
e7e5b8a
Move the settings to the new file and add initial code for handling u…
Oldiesmann Jun 10, 2024
82cbe71
Minor tweaks and such
Oldiesmann Jun 10, 2024
51c8f6a
Fix the typo, add a comment block and remove the unneeded trait property
Oldiesmann Jun 10, 2024
ef25d62
Merge branch 'smf3' of github.com:Oldiesmann/SMF21 into reactions
Oldiesmann Jun 10, 2024
b38c849
Code to handle adding/removing/updating reactions and initial code fo…
Oldiesmann Jun 14, 2024
2992985
HTML5, not XHTML...
Oldiesmann Jun 14, 2024
2b51004
More random fixes and such
Oldiesmann Jun 17, 2024
5b3cbc1
A few more minor tweaks:
Oldiesmann Jun 22, 2024
968de8a
More fun...
Oldiesmann Jun 22, 2024
2f5926f
- Change new row thing from link to button
Oldiesmann Jun 22, 2024
1c1c313
Add function to output the data for the check column
Oldiesmann Jun 23, 2024
dad8ba0
Add constructor, change the likes permission text string and create l…
Oldiesmann Jun 23, 2024
9172e3e
Finish menu and add language strings
Oldiesmann Jun 23, 2024
2424ffb
Merge branch 'smf3' of github.com:Oldiesmann/SMF21 into reactions
Oldiesmann Jun 23, 2024
67d86b0
Merge branch 'smf3' of github.com:Oldiesmann/SMF21 into reactions
Oldiesmann Jun 27, 2024
cf7d01f
Consistency and all that...
Oldiesmann Jun 27, 2024
0370de9
Oops
Oldiesmann Jun 27, 2024
197d3e4
Another typo; also fix typos in Postgres
Oldiesmann Jun 27, 2024
92381b2
Another typo and work around upgrade_query not supporting {db_prefix}
Oldiesmann Jun 27, 2024
564b974
Fun fact: PHP doesn't like trying to implode() a string
Oldiesmann Jun 27, 2024
e4c6223
A few more minor fixes
Oldiesmann Jun 27, 2024
c5fd7cc
More fixes and general cleanup.
Oldiesmann Jun 28, 2024
3688a33
Missing language strings
Oldiesmann Jun 28, 2024
c34c257
There's such a thing as too many permissions, right?
Oldiesmann Jun 28, 2024
1a8c0d6
Forgot to finish the settings stuff...
Oldiesmann Jun 28, 2024
7578e14
More missing language strings
Oldiesmann Jun 28, 2024
9a880be
A couple more typos
Oldiesmann Jun 28, 2024
e373a4f
More bugs
Oldiesmann Jun 28, 2024
495f1f2
More typos and missing language strings
Oldiesmann Jun 28, 2024
608173b
Typos are sooo much fun...
Oldiesmann Jun 28, 2024
d4a472a
More cleanup
Oldiesmann Jun 28, 2024
b91fd9c
Remove currently unused column from install SQL files
Oldiesmann Jun 28, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 50 additions & 14 deletions Sources/Actions/Admin/Reactions.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,15 +129,15 @@ public function editreactions(): void
$reactions = $this->getReactions();

// They must have submitted a form.
if (isset($_POST['react_save'])) {
if (isset($_POST['react_save']) || isset($_POST['react_delete'])) {
User::$me->checkSession();
SecurityToken::validate('admin-mss', 'request');

// This will indicate whether we need to update the reactions cache later...
$do_update = false;

// Anything to delete?
if (isset($_POST['delete_reacts'])) {
if (isset($_POST['react_delete']) && isset($_POST['delete_reacts'])) {
$do_update = true;
$deleted = [];

Expand Down Expand Up @@ -181,9 +181,8 @@ public function editreactions(): void
}
}
}

// Updating things?
if (isset($_POST['reacts'])) {
elseif (isset($_POST['reacts'])) {
// Adding things?
if (isset($_POST['react_add'])) {
foreach($_POST['react_add'] as $new_react)
Expand Down Expand Up @@ -221,13 +220,14 @@ public function editreactions(): void
// Do the update
Db::$db->insert('replace', ['id_react, name'], $updates, 'id_react');
}
}

// If we updated anything, re-cache everything
if ($do_update) {
// Re-cache the reactions and update the reactions variable
CacheApi::put('reactions', null);
$reactions = $this->getReactions();
}
// If we updated anything, re-cache everything
if ($do_update) {
// Re-cache the reactions and update the reactions variable so the form will show the changes
CacheApi::put('reactions', null);
$reactions = $this->getReactions();
CacheApi::put('reactions', $reactions, 480);
}
}

Expand All @@ -243,11 +243,13 @@ public function editreactions(): void
'no_items_label' => Lang::$txt['no_reactions'],
'base_href' => Config::$scripturl . '?action=admin;area=reactions;sa=edit',
'get_items' => [
'function' => function() use ($reactions) : array {
'function' => function(int $start, int $items_per_page, string $sort_by, array $params) use ($reactions) : array {
$items = [];
foreach ($reactions as $id => $name) {
// Make a nice text field...
$items[] = '<input type="text" name="reacts[' . $id . ']" value="' . $name . '">';
$items[] = [
'name' => '<input type="text" name="reacts[' . $id . ']" value="' . $name . '">',
'check' => '<input type="check" name="delete_reacts[]" value="' . $id . '">',
];
}
return $items;
},
Expand Down Expand Up @@ -285,6 +287,39 @@ public function editreactions(): void
'class' => 'centertext',
];

// Add a row for a blank field to add a reaction, and a link to add another blank field.
$listOptions['additional_rows'][] = [
[
'position' => 'bottom_of_list',
'data' => [
'value' => '<input type="text" name="reacts_add[]">'
]
],
[
// Clicking this magic link adds a new row...
'position' => 'bottom_of_list',
'data' => [
'value' => '<a href="javascript:void(0);" onclick="addrow()">' . Lang::$txt['reacts_add'] . '</a>'
Oldiesmann marked this conversation as resolved.
Show resolved Hide resolved
]
],
[
// And last but not least our buttons
'position' => 'below_table_data',
'data' => [
'value' => '<input type="submit" name="reacts_save" value="' . Lang::$txt['reacts_save'] . '" class="button">
<input type="submit" name="reacts_delete" value="' . Lang::$txt['reacts_delete'] . '" data-confirm="' . Lang::$txt['reacts_delete_confirm'] . '" class="button you_sure>'
]
]
];

// And some inline JS to handle adding another row
$listOptions['javascript'] = [
'
function addrow() {
document.getElementByName(blah);
}',
];

// Now that we have our list options set up, have some fun...
$listOptions['form'] = [
'href' => Config::$scripturl . '?action=admin;area=react;sa=edit;' . Utils::$context['session_var'] . '=' . Utils::$context['session_id'],
Expand All @@ -297,4 +332,5 @@ public function editreactions(): void
Utils::$context['sub_template'] = 'show_list';
Utils::$context['default_list'] = 'list_reactions';
}
}
}
?>
4 changes: 2 additions & 2 deletions Sources/ReactionTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ trait ReactionTrait
*/
public function getReactions(): array
{
if (is_null($reactions = CacheApi::get('reactions'))) {
if (is_null($reactions = CacheApi::get('reactions', 480))) {
$request = Db::$db->query(
'',
'SELECT * FROM {db_prefix}reactions',
Expand All @@ -43,7 +43,7 @@ public function getReactions(): array
Db::$db->free($request);

// Cache the results
CacheApi::put('reactions', $reactions);
CacheApi::put('reactions', $reactions, 480);
}
return $reactions;
}
Expand Down