Skip to content

Commit

Permalink
Perform minor maintenance/fix-ups (#286)
Browse files Browse the repository at this point in the history
* Correct the test in thankyoulike.php and tylsearch.php for the plugin
being active and enabled.

* Move the hard-coded language string "This" into the language file.

* Check for the non-existence of the recently-added indexes on the
thankyoulike table before trying to add them on plugin auto-upgrade.

* Bump the versioning of the thankyoulike.min.js file via the "ver"
query parameter given that this file was updated a few commits ago.

* Add missing settings to the Javascript Peeker so that all other
settings correctly disappear when the Enabled/Disabled plugin setting is
set to Off.
  • Loading branch information
lairdshaw authored Nov 27, 2020
1 parent f64e503 commit 5b5d42d
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 19 deletions.
4 changes: 3 additions & 1 deletion inc/languages/english/thankyoulike.lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,11 @@

$l['tyl_wol_searching'] = "<a href=\"{1}\">Searching {2}</a>";

$l['tyl_this'] = 'This';

$l['tyl_error'] = "Thank You/Like System Error Message";
$l['tyl_error_invalid_action'] = "You are trying to perform an invalid action.";
$l['tyl_error_disabled'] = "{1} Feature has been disabled.";
$l['tyl_error_disabled'] = "{1} feature has been disabled.";
$l['tyl_error_not_allowed'] = "Not allowed for this post.";
$l['tyl_error_first_post_only'] = "You may only add/remove a {1} for the first post of threads in this forum.";
$l['tyl_error_excluded'] = "Not allowed for this post because this forum has been excluded.";
Expand Down
37 changes: 29 additions & 8 deletions inc/plugins/thankyoulike.php
Original file line number Diff line number Diff line change
Expand Up @@ -576,12 +576,33 @@ function tyl_check_update_db_table_and_cols($from_version = false)

if($from_version !== false && $from_version < 30308)
{
// To speed up the member profile tyl statistics (tabulated display of date range counts of tyls).
$db->query("ALTER TABLE ".TABLE_PREFIX.$prefix."thankyoulike ADD KEY uid_dateline (uid , dateline)");
$db->query("ALTER TABLE ".TABLE_PREFIX.$prefix."thankyoulike ADD KEY puid_dateline (puid, dateline)");
$db->query("ALTER TABLE ".TABLE_PREFIX.$prefix."thankyoulike ADD KEY puid_uid (puid, uid)");
// To speed up the determination of the member profile trophy post.
$db->query("ALTER TABLE ".TABLE_PREFIX.$prefix."thankyoulike ADD KEY puid_pid (puid, pid)");
// These indexes speed up the member profile tyl statistics (tabulated display of date range counts of tyls).
$query = $db->query("SHOW INDEX FROM ".TABLE_PREFIX.$prefix."thankyoulike WHERE Key_name='uid_dateline'");
if($db->num_rows($query) == 0)
{
$db->query("ALTER TABLE ".TABLE_PREFIX.$prefix."thankyoulike ADD KEY uid_dateline (uid , dateline)");
}
$db->free_result($query);
$query = $db->query("SHOW INDEX FROM ".TABLE_PREFIX.$prefix."thankyoulike WHERE Key_name='puid_dateline'");
if($db->num_rows($query) == 0)
{
$db->query("ALTER TABLE ".TABLE_PREFIX.$prefix."thankyoulike ADD KEY puid_dateline (puid, dateline)");
}
$db->free_result($query);
$query = $db->query("SHOW INDEX FROM ".TABLE_PREFIX.$prefix."thankyoulike WHERE Key_name='puid_uid'");
if($db->num_rows($query) == 0)
{
$db->query("ALTER TABLE ".TABLE_PREFIX.$prefix."thankyoulike ADD KEY puid_uid (puid, uid)");
}
$db->free_result($query);

// This index speeds up the determination of the member profile trophy post.
$query = $db->query("SHOW INDEX FROM ".TABLE_PREFIX.$prefix."thankyoulike WHERE Key_name='puid_pid'");
if($db->num_rows($query) == 0)
{
$db->query("ALTER TABLE ".TABLE_PREFIX.$prefix."thankyoulike ADD KEY puid_pid (puid, pid)");
}
$db->free_result($query);
}

// Added puid field after v1.0 so check for that
Expand Down Expand Up @@ -1252,7 +1273,7 @@ function thankyoulike_activate()

require_once MYBB_ROOT."/inc/adminfunctions_templates.php";

find_replace_templatesets("showthread", "#".preg_quote('</head>')."#i", '<script type="text/javascript" src="{$mybb->settings[\'bburl\']}/jscripts/thankyoulike.min.js?ver=30306"></script>
find_replace_templatesets("showthread", "#".preg_quote('</head>')."#i", '<script type="text/javascript" src="{$mybb->settings[\'bburl\']}/jscripts/thankyoulike.min.js?ver=30309"></script>
<script type="text/javascript">
<!--
var tylEnabled = "{$mybb->settings[\'g33k_thankyoulike_enabled\']}";
Expand Down Expand Up @@ -3340,7 +3361,7 @@ function thankyoulike_settings_peeker()
{
echo '<script type="text/javascript">
$(document).ready(function(){
new Peeker($(".setting_'.$prefix.'enabled"), $("#row_setting_'.$prefix.'thankslike, #row_setting_'.$prefix.'firstall, #row_setting_'.$prefix.'firstalloverride, #row_setting_'.$prefix.'removing, #row_setting_'.$prefix.'tylownposts, #row_setting_'.$prefix.'reputation_add, #row_setting_'.$prefix.'remowntylfroms, #row_setting_'.$prefix.'remowntylfromc, #row_setting_'.$prefix.'closedthreads, #row_setting_'.$prefix.'exclude, #row_setting_'.$prefix.'exclude_count, #row_setting_'.$prefix.'unameformat, #row_setting_'.$prefix.'hideforgroups, #row_setting_'.$prefix.'showdt, #row_setting_'.$prefix.'dtformat, #row_setting_'.$prefix.'sortorder, #row_setting_'.$prefix.'collapsible, #row_setting_'.$prefix.'colldefault, #row_setting_'.$prefix.'hidelistforgroups, #row_setting_'.$prefix.'displaygrowl, #row_setting_'.$prefix.'limits, #row_setting_'.$prefix.'highlight_popular_posts, #row_setting_'.$prefix.'show_memberprofile_box"), 1, true),
new Peeker($(".setting_'.$prefix.'enabled"), $("#row_setting_'.$prefix.'thankslike, #row_setting_'.$prefix.'firstall, #row_setting_'.$prefix.'firstalloverride, #row_setting_'.$prefix.'removing, #row_setting_'.$prefix.'tylownposts, #row_setting_'.$prefix.'reputation_add, #row_setting_'.$prefix.'remowntylfroms, #row_setting_'.$prefix.'remowntylfromc, #row_setting_'.$prefix.'closedthreads, #row_setting_'.$prefix.'exclude, #row_setting_'.$prefix.'exclude_count, #row_setting_'.$prefix.'unameformat, #row_setting_'.$prefix.'hideforgroups, #row_setting_'.$prefix.'showdt, #row_setting_'.$prefix.'dtformat, #row_setting_'.$prefix.'sortorder, #row_setting_'.$prefix.'collapsible, #row_setting_'.$prefix.'colldefault, #row_setting_'.$prefix.'hidelistforgroups, #row_setting_'.$prefix.'displaygrowl, #row_setting_'.$prefix.'limits, #row_setting_'.$prefix.'highlight_popular_posts, #row_setting_'.$prefix.'show_memberprofile_box, #row_setting_'.$prefix.'likersdisplay, #row_setting_'.$prefix.'rcvdlikesclassranges, #row_setting_'.$prefix.'display_tyl_counter_forumdisplay, #row_setting_'.$prefix.'display_tyl_counter_search_page, #row_setting_'.$prefix.'show_memberprofile_stats"), 1, true),
new Peeker($(".setting_'.$prefix.'firstall"), $("#row_setting_'.$prefix.'firstalloverride"), "first", true),
new Peeker($(".setting_'.$prefix.'tylownposts"), $("#row_setting_'.$prefix.'remowntylfroms, #row_setting_'.$prefix.'remowntylfromc"), 1, true),
new Peeker($(".setting_'.$prefix.'reputation_add"), $("#row_setting_'.$prefix.'reputation_add_reppoints, #row_setting_'.$prefix.'reputation_add_repcomment"), 1, true),
Expand Down
8 changes: 4 additions & 4 deletions thankyoulike.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@
error_no_permission();
}

// Access to this file only if plugin is existant and active
if (!$mybb->settings[$prefix.'enabled'])
// Access to this file only if plugin is active and enabled
if(!in_array('thankyoulike', $cache->read('plugins')['active']) || !$mybb->settings[$prefix.'enabled'])
{
error($lang->sprintf($lang->tyl_error_disabled, "This"));
error($lang->sprintf($lang->tyl_error_disabled, $lang->tyl_this));
}

if ($mybb->settings[$prefix.'thankslike'] == "like")
if($mybb->settings[$prefix.'thankslike'] == "like")
{
$pre = $lang->tyl_like;
$pre1 = $lang->tyl_liked;
Expand Down
10 changes: 4 additions & 6 deletions tylsearch.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,21 +46,19 @@
$lang->load("search");
$lang->load("thankyoulike");

// Access to this file only if plugin is existant and active
if (!$mybb->settings[$prefix.'enabled'])
// Access to this file only if plugin is active and enabled
if(!in_array('thankyoulike', $cache->read('plugins')['active']) || !$mybb->settings[$prefix.'enabled'])
{
error($lang->sprintf($lang->tyl_error_disabled, "This"));
error($lang->sprintf($lang->tyl_error_disabled, $lang->tyl_this));
}

if ($mybb->settings[$prefix.'thankslike'] == "like")
if($mybb->settings[$prefix.'thankslike'] == "like")
{
$pre = $lang->tyl_like;
$pre1 = $lang->tyl_liked;
}
else
{
$pre = $lang->tyl_thankyou;
$pre1 = $lang->tyl_thanked;
}

if($mybb->settings[$prefix.'enabled'] != "1")
Expand Down

0 comments on commit 5b5d42d

Please sign in to comment.