Skip to content

Commit

Permalink
Merge pull request #62 from 3D-I/tops_ever_cache
Browse files Browse the repository at this point in the history
Tops ever cache
  • Loading branch information
3Di authored Oct 16, 2017
2 parents 1a0176a + 08a470e commit fd14c73
Show file tree
Hide file tree
Showing 10 changed files with 151 additions and 59 deletions.
32 changes: 28 additions & 4 deletions acp/tpotm_module.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

namespace threedi\tpotm\acp;

use \threedi\tpotm\ext;

/**
* Top Poster Of The Month ACP module.
*/
Expand Down Expand Up @@ -49,6 +51,26 @@ public function main($id, $mode)
trigger_error($user->lang('TPOTM_BADGE_IMG_INVALID') . adm_back_link($this->u_action), E_USER_WARNING);
}

/**
* Drop down construct inspired by MChat.
*/
$time_modes = [
ext::NO_CACHE => 'no_cache',
ext::ONE_DAY => 'one_day',
ext::ONE_WEEK => 'one_week',
ext::TWO_WEEKS => 'two_weeks',
ext::ONE_MONTH => 'one_month',
];

$selected = $time_row_options = '';

foreach ($time_modes as $val => $time_mode)
{
$time_row_options .= '<option value="' . $val . '"' . (($val == $time_mode) ? ' selected="selected"' : '') . '>';
$time_row_options .= $user->lang('TPOTM_ACP_' . strtoupper($time_mode));
$time_row_options .= '</option>';
}

/* Do this now and forget */
$errors = [];

Expand Down Expand Up @@ -80,6 +102,8 @@ public function main($id, $mode)
$config->set('threedi_tpotm_forums', $request->variable('threedi_tpotm_forums', (int) $config['threedi_tpotm_forums']));
$config->set('threedi_tpotm_hall', $request->variable('threedi_tpotm_hall', (int) $config['threedi_tpotm_hall']));
$config->set('threedi_tpotm_users_page', $request->variable('threedi_tpotm_users_page', (int) $config['threedi_tpotm_users_page']));
$config->set('threedi_tpotm_ttl_mode', $request->variable('threedi_tpotm_ttl_mode', (int) $config['threedi_tpotm_ttl_mode']));
$config->set('threedi_tpotm_ttl_tpe', $request->variable('threedi_tpotm_ttl_tpe', (int) $config['threedi_tpotm_ttl_tpe']));
$config->set('threedi_tpotm_since_epoch', $request->variable('threedi_tpotm_since_epoch', (int) $config['threedi_tpotm_since_epoch']));
$config->set('threedi_tpotm_ttl', $request->variable('threedi_tpotm_ttl', (int) $config['threedi_tpotm_ttl']));
$config->set('threedi_tpotm_miniavatar', $request->variable('threedi_tpotm_miniavatar', (int) $config['threedi_tpotm_miniavatar']));
Expand All @@ -98,18 +122,18 @@ public function main($id, $mode)
'S_ERRORS' => ($errors) ? true : false,
'ERRORS_MSG' => ($errors) ? implode('<br /><br />', $errors) : '',
'U_ACTION' => $this->u_action,
// Template locations

'TPOTM_INDEX' => ($config['threedi_tpotm_index']) ? true : false,
'TPOTM_FORUMS' => ($config['threedi_tpotm_forums']) ? true : false,
// Hall of fame
'TPOTM_HALL' => ($config['threedi_tpotm_hall']) ? true : false,
'TPOTM_USERS_PAGE' => (int) $config['threedi_tpotm_users_page'],
'TPOTM_TTL_MODE' => $config['threedi_tpotm_ttl_mode'] ? true : false,
'S_TPOTM_TTL_TPE' => $time_row_options,
'TPOTM_TTL_TPE' => (int) $config['threedi_tpotm_ttl_tpe'],
'TPOTM_HALL_EPOCH' => ($config['threedi_tpotm_since_epoch']) ? true : false,
// General Settings
'TPOTM_TTL' => (int) $config['threedi_tpotm_ttl'],
'TPOTM_MINIAVATAR' => ($config['threedi_tpotm_miniavatar']) ? true : false,
'TPOTM_MINIPROFILE' => ($config['threedi_tpotm_miniprofile']) ? true : false,
// Founders, admin and mods
'TPOTM_ADM_MODS' => ($config['threedi_tpotm_adm_mods']) ? true : false,
'TPOTM_FOUNDERS' => ($config['threedi_tpotm_founders']) ? true : false,
'TPOTM_BANNEDS' => ($config['threedi_tpotm_banneds']) ? true : false,
Expand Down
12 changes: 12 additions & 0 deletions adm/style/tpotm_acp.css
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
/* CSS Document */

.tpotm-select select {
background: transparent;
width: auto;
padding: 5px;
font-size: inherit;
line-height: inherit;
border: 0;
border-radius: 0;
height: 32px;
webkit-appearance: none;
}

.tpotm-acp-inner {
}

Expand Down
106 changes: 64 additions & 42 deletions adm/style/tpotm_body.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,48 +36,46 @@ <h1>{{ lang('ACP_TPOTM_TITLE') }}</h1>
<fieldset class="tpotm-acp-outer">
<fieldset class="tpotm-acp-middle">
<fieldset class="tpotm-acp-inner">
<legend>{{ lang('ACP_TPOTM_TEMPLATE_LOCATIONS') }}</legend>
<div class="tpotm-acp-rules">{{ lang('ACP_TPOTM_TEMPLATE_LOCATIONS_EXPLAIN') }}</div>
<legend>{{ lang('ACP_TPOTM_HALL') }}</legend>
<dl>
<dt>
<label for="threedi_tpotm_index">{{ lang('TPOTM_INDEX') }}{{ lang('COLON') }}</label><br />
<label for="threedi_tpotm_hall">{{ lang('TPOTM_HALL') }}{{ lang('COLON') }}</label><br>{{ lang('TPOTM_HALL_EXPLAIN') }}
</dt>
<dd>
<input type="radio" class="radio" name="threedi_tpotm_index" value="1"{% if TPOTM_INDEX %} checked="checked"{% endif %}/> {{ lang('TPOTM_BOTTOM') }} &nbsp;
<input type="radio" class="radio" name="threedi_tpotm_index" value="0"{% if not TPOTM_INDEX %} checked="checked"{% endif %} /> {{ lang('TPOTM_TOP') }}
<input type="radio" class="radio" name="threedi_tpotm_hall" value="1"{% if TPOTM_HALL %} checked="checked"{% endif %}/> {{ lang('YES') }} &nbsp;
<input type="radio" class="radio" name="threedi_tpotm_hall" value="0"{% if not TPOTM_HALL %} checked="checked"{% endif %} /> {{ lang('NO') }}
</dd>
</dl>

<dl>
<dt>
<label for="threedi_tpotm_forums">{{ lang('TPOTM_FORUMS') }}{{ lang('COLON') }}</label><br />
<label for="threedi_tpotm_users_page">{{ lang('TPOTM_USERS_PAGE') }}{{ lang('COLON') }}</label><br>{{ lang('TPOTM_USERS_PAGE_EXPLAIN') }}
</dt>
<dd>
<input type="radio" class="radio" name="threedi_tpotm_forums" value="1"{% if TPOTM_FORUMS %} checked="checked"{% endif %}/> {{ lang('YES') }} &nbsp;
<input type="radio" class="radio" name="threedi_tpotm_forums" value="0"{% if not TPOTM_FORUMS %} checked="checked"{% endif %} /> {{ lang('NO') }}
<input type="number" min="1" max="300" name="threedi_tpotm_users_page" id="threedi_tpotm_users_page" size="6" value="{{ TPOTM_USERS_PAGE }}" />
</dd>
</dl>
</fieldset>

<fieldset class="tpotm-acp-inner">
<legend>{{ lang('ACP_TPOTM_HALL') }}</legend>
<div class="tpotm-acp-rules">{{ lang('ACP_TPOTM_TTL_MODE') }}</div>
<dl>
<dt>
<label for="threedi_tpotm_hall">{{ lang('TPOTM_HALL') }}{{ lang('COLON') }}</label><br />{{ lang('TPOTM_HALL_EXPLAIN') }}
<label for="threedi_tpotm_ttl_mode">{{ lang('TPOTM_TTL_MODE') }}{{ lang('COLON') }}</label>
</dt>
<dd>
<input type="radio" class="radio" name="threedi_tpotm_hall" value="1"{% if TPOTM_HALL %} checked="checked"{% endif %}/> {{ lang('YES') }} &nbsp;
<input type="radio" class="radio" name="threedi_tpotm_hall" value="0"{% if not TPOTM_HALL %} checked="checked"{% endif %} /> {{ lang('NO') }}
<input type="radio" class="radio" name="threedi_tpotm_ttl_mode" value="1"{% if TPOTM_TTL_MODE %} checked="checked"{% endif %}/> {{ lang('YES') }}&nbsp;
<input type="radio" class="radio" name="threedi_tpotm_ttl_mode" value="0"{% if not TPOTM_TTL_MODE %} checked="checked"{% endif %} /> {{ lang('NO') }}
</dd>
</dl>

<dl>
<dt>
<label for="threedi_tpotm_users_page">{{ lang('TPOTM_USERS_PAGE') }}{{ lang('COLON') }}</label><br />{{ lang('TPOTM_USERS_PAGE_EXPLAIN') }}
<label for="threedi_tpotm_ttl_tpe">{{ lang('TPOTM_TTL_TPE') }}{{ lang('COLON') }}</label>
</dt>
<dd>
<input type="number" min="1" max="300" name="threedi_tpotm_users_page" id="threedi_tpotm_users_page" size="6" value="{{ TPOTM_USERS_PAGE }}" />
</dd>
<div class="tpotm-select">
<dd>
<input type="text" name="threedi_tpotm_ttl_tpe" size="10" id="threedi_tpotm_ttl_tpe" value="{{ TPOTM_TTL_TPE }}" />
<select name="threedi_tpotm_ttl_tpe" id="threedi_tpotm_ttl_tpe" title="{{ lang('TPOTM_TTL_TPE') }}">{{ S_TPOTM_TTL_TPE }}</select>
</dd>
</div>
</dl>

<div class="tpotm-acp-rules">{{ lang('ACP_TPOTM_HALL_EPOCH_EXPLAIN') }}</div>
Expand All @@ -86,74 +84,98 @@ <h1>{{ lang('ACP_TPOTM_TITLE') }}</h1>
<label for="threedi_tpotm_since_epoch">{{ lang('TPOTM_HALL_EPOCH') }}{{ lang('COLON') }}</label>
</dt>
<dd>
<input type="radio" class="radio" name="threedi_tpotm_since_epoch" value="1"{% if TPOTM_HALL_EPOCH %} checked="checked"{% endif %}/> {{ lang('YES') }} &nbsp;
<input type="radio" class="radio" name="threedi_tpotm_since_epoch" value="0"{% if not TPOTM_HALL_EPOCH %} checked="checked"{% endif %} /> {{ lang('NO') }}
<input type="radio" class="radio" name="threedi_tpotm_since_epoch" value="1"{% if TPOTM_HALL_EPOCH %} checked="checked"{% endif %}/> {{ lang('TPOTM_EPOCH') }} &nbsp;
<input type="radio" class="radio" name="threedi_tpotm_since_epoch" value="0"{% if not TPOTM_HALL_EPOCH %} checked="checked"{% endif %} /> {{ lang('TPOTM_BOARD_S_DATE') }}
</dd>
</dl>
</fieldset>

<hr>
<fieldset class="tpotm-acp-inner">
<legend>{{ lang('ACP_TPOTM_VARIOUSES') }}</legend>
<legend>{{ lang('ACP_TPOTM_MANAGEMENT') }}</legend>
<div class="tpotm-acp-rules">{{ lang('ACP_TPOTM_MANAGEMENT_EXPLAIN') }}</div>
<dl>
<dt>
<label for="threedi_tpotm_ttl">{{ lang('TPOTM_TTL') }}{{ lang('COLON') }}</label><br />{{ lang('TPOTM_TTL_EXPLAIN') }}
<label for="threedi_tpotm_adm_mods">{{ lang('TPOTM_ADM_MODS') }}{{ lang('COLON') }}</label><br>{{ lang('TPOTM_ADM_MODS_EXPLAIN') }}
</dt>
<dd>
<input type="number" min="0" name="threedi_tpotm_ttl" id="threedi_tpotm_ttl" size="6" value="{{ TPOTM_TTL }}" />
<input type="radio" class="radio" name="threedi_tpotm_adm_mods" value="1"{% if TPOTM_ADM_MODS %} checked="checked"{% endif %}/> {{ lang('YES') }} &nbsp;
<input type="radio" class="radio" name="threedi_tpotm_adm_mods" value="0"{% if not TPOTM_ADM_MODS %} checked="checked"{% endif %} /> {{ lang('NO') }}
</dd>
</dl>

<dl>
<dt>
<label for="threedi_tpotm_miniavatar">{{ lang('TPOTM_AVATAR') }}{{ lang('COLON') }}</label><br />{{ lang('TPOTM_AVATAR_EXPLAIN') }}
<label for="threedi_tpotm_founders">{{ lang('TPOTM_FOUNDERS') }}{{ lang('COLON') }}</label><br>{{ lang('TPOTM_FOUNDERS_EXPLAIN') }}
</dt>
<dd>
<input type="radio" class="radio" name="threedi_tpotm_miniavatar" value="1"{% if TPOTM_MINIAVATAR %} checked="checked"{% endif %}/> {{ lang('YES') }} &nbsp;
<input type="radio" class="radio" name="threedi_tpotm_miniavatar" value="0"{% if not TPOTM_MINIAVATAR %} checked="checked"{% endif %} /> {{ lang('NO') }}
<input type="radio" class="radio" name="threedi_tpotm_founders" value="1"{% if TPOTM_FOUNDERS %} checked="checked"{% endif %}/> {{ lang('YES') }} &nbsp;
<input type="radio" class="radio" name="threedi_tpotm_founders" value="0"{% if not TPOTM_FOUNDERS %} checked="checked"{% endif %} /> {{ lang('NO') }}
</dd>
</dl>

<dl>
<dt>
<label for="threedi_tpotm_miniprofile">{{ lang('TPOTM_MINIPROFILE') }}{{ lang('COLON') }}</label><br />{{ lang('TPOTM_MINIPROFILE_EXPLAIN') }}
<label for="threedi_tpotm_banneds">{{ lang('TPOTM_BANNEDS') }}{{ lang('COLON') }}</label><br>{{ lang('TPOTM_BANNEDS_EXPLAIN') }}
</dt>
<dd>
<input type="radio" class="radio" name="threedi_tpotm_miniprofile" value="1"{% if TPOTM_MINIPROFILE %} checked="checked"{% endif %}/> {{ lang('YES') }} &nbsp;
<input type="radio" class="radio" name="threedi_tpotm_miniprofile" value="0"{% if not TPOTM_MINIPROFILE %} checked="checked"{% endif %} /> {{ lang('NO') }}
<input type="radio" class="radio" name="threedi_tpotm_banneds" value="1"{% if TPOTM_BANNEDS %} checked="checked"{% endif %}/> {{ lang('YES') }} &nbsp;
<input type="radio" class="radio" name="threedi_tpotm_banneds" value="0"{% if not TPOTM_BANNEDS %} checked="checked"{% endif %} /> {{ lang('NO') }}
</dd>
</dl>
</fieldset>
<hr>
<fieldset class="tpotm-acp-inner">
<legend>{{ lang('ACP_TPOTM_TEMPLATE_LOCATIONS') }}</legend>
<div class="tpotm-acp-rules">{{ lang('ACP_TPOTM_TEMPLATE_LOCATIONS_EXPLAIN') }}</div>
<dl>
<dt>
<label for="threedi_tpotm_index">{{ lang('TPOTM_INDEX') }}{{ lang('COLON') }}</label><br>
</dt>
<dd>
<input type="radio" class="radio" name="threedi_tpotm_index" value="1"{% if TPOTM_INDEX %} checked="checked"{% endif %}/> {{ lang('TPOTM_BOTTOM') }} &nbsp;
<input type="radio" class="radio" name="threedi_tpotm_index" value="0"{% if not TPOTM_INDEX %} checked="checked"{% endif %} /> {{ lang('TPOTM_TOP') }}
</dd>
</dl>

<dl>
<dt>
<label for="threedi_tpotm_forums">{{ lang('TPOTM_FORUMS') }}{{ lang('COLON') }}</label><br>
</dt>
<dd>
<input type="radio" class="radio" name="threedi_tpotm_forums" value="1"{% if TPOTM_FORUMS %} checked="checked"{% endif %}/> {{ lang('YES') }} &nbsp;
<input type="radio" class="radio" name="threedi_tpotm_forums" value="0"{% if not TPOTM_FORUMS %} checked="checked"{% endif %} /> {{ lang('NO') }}
</dd>
</dl>
</fieldset>

<fieldset class="tpotm-acp-inner">
<legend>{{ lang('ACP_TPOTM_MANAGEMENT') }}</legend>
<div class="tpotm-acp-rules">{{ lang('ACP_TPOTM_MANAGEMENT_EXPLAIN') }}</div>
<legend>{{ lang('ACP_TPOTM_VARIOUSES') }}</legend>
<dl>
<dt>
<label for="threedi_tpotm_adm_mods">{{ lang('TPOTM_ADM_MODS') }}{{ lang('COLON') }}</label><br />{{ lang('TPOTM_ADM_MODS_EXPLAIN') }}
<label for="threedi_tpotm_ttl">{{ lang('TPOTM_TTL') }}{{ lang('COLON') }}</label><br>{{ lang('TPOTM_TTL_EXPLAIN') }}
</dt>
<dd>
<input type="radio" class="radio" name="threedi_tpotm_adm_mods" value="1"{% if TPOTM_ADM_MODS %} checked="checked"{% endif %}/> {{ lang('YES') }} &nbsp;
<input type="radio" class="radio" name="threedi_tpotm_adm_mods" value="0"{% if not TPOTM_ADM_MODS %} checked="checked"{% endif %} /> {{ lang('NO') }}
<input type="number" min="0" name="threedi_tpotm_ttl" id="threedi_tpotm_ttl" size="6" value="{{ TPOTM_TTL }}" />
</dd>
</dl>

<dl>
<dt>
<label for="threedi_tpotm_founders">{{ lang('TPOTM_FOUNDERS') }}{{ lang('COLON') }}</label><br />{{ lang('TPOTM_FOUNDERS_EXPLAIN') }}
<label for="threedi_tpotm_miniavatar">{{ lang('TPOTM_AVATAR') }}{{ lang('COLON') }}</label><br>{{ lang('TPOTM_AVATAR_EXPLAIN') }}
</dt>
<dd>
<input type="radio" class="radio" name="threedi_tpotm_founders" value="1"{% if TPOTM_FOUNDERS %} checked="checked"{% endif %}/> {{ lang('YES') }} &nbsp;
<input type="radio" class="radio" name="threedi_tpotm_founders" value="0"{% if not TPOTM_FOUNDERS %} checked="checked"{% endif %} /> {{ lang('NO') }}
<input type="radio" class="radio" name="threedi_tpotm_miniavatar" value="1"{% if TPOTM_MINIAVATAR %} checked="checked"{% endif %}/> {{ lang('YES') }} &nbsp;
<input type="radio" class="radio" name="threedi_tpotm_miniavatar" value="0"{% if not TPOTM_MINIAVATAR %} checked="checked"{% endif %} /> {{ lang('NO') }}
</dd>
</dl>

<dl>
<dt>
<label for="threedi_tpotm_banneds">{{ lang('TPOTM_BANNEDS') }}{{ lang('COLON') }}</label><br />{{ lang('TPOTM_BANNEDS_EXPLAIN') }}
<label for="threedi_tpotm_miniprofile">{{ lang('TPOTM_MINIPROFILE') }}{{ lang('COLON') }}</label><br>{{ lang('TPOTM_MINIPROFILE_EXPLAIN') }}
</dt>
<dd>
<input type="radio" class="radio" name="threedi_tpotm_banneds" value="1"{% if TPOTM_BANNEDS %} checked="checked"{% endif %}/> {{ lang('YES') }} &nbsp;
<input type="radio" class="radio" name="threedi_tpotm_banneds" value="0"{% if not TPOTM_BANNEDS %} checked="checked"{% endif %} /> {{ lang('NO') }}
<input type="radio" class="radio" name="threedi_tpotm_miniprofile" value="1"{% if TPOTM_MINIPROFILE %} checked="checked"{% endif %}/> {{ lang('YES') }} &nbsp;
<input type="radio" class="radio" name="threedi_tpotm_miniprofile" value="0"{% if not TPOTM_MINIPROFILE %} checked="checked"{% endif %} /> {{ lang('NO') }}
</dd>
</dl>
</fieldset>
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"type": "phpbb-extension",
"description": " Have a Top Poster of the Month and a Hall of Fame to show on your phpBB. The last poster with the max number of posts made into the current month's lapse of time will win. Provided is a customizable Hall of fame and a bunch of options in ACP and UCP",
"homepage": "https://github.com/3D-I/tpotm",
"version": "2.0.4-RC",
"version": "2.0.5-RC",
"license": "GPL-2.0",
"authors": [
{
Expand Down
18 changes: 16 additions & 2 deletions controller/main.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,20 @@ public function handle($name)
$max_days = date( 't', gmmktime(23, 59, 59, $month, 1, $year) );
$end_last_month = gmmktime(23, 59, 59, $month, $max_days, $year);

/* Top posters ever's dynamic cache TTL */
$this_max_days = date( 't', gmmktime(23, 59, 59, $month_cur, 1, $year) );
$end_this_month = gmmktime(23, 59, 59, $month_cur, $this_max_days, $year);

/* Top posters ever's dynamic cache TTL admin choice*/
if ($this->config['threedi_tpotm_ttl_mode'])
{
$ttl_diff = (int) ($end_this_month - $now);
}
else
{
$ttl_diff = (int) $this->config['threedi_tpotm_ttl_tpe'];
}

/* These are for pagination */
$total_users = $this->request->variable('user_id', 0);
$start = $this->request->variable('start', 0);
Expand All @@ -136,12 +150,12 @@ public function handle($name)
$sql = $this->tpotm->tpotm_sql($and_admmods, $and_bans, $and_founder, (int) $board_start, (int) $end_last_month);

/* Rowset array for the viewport */
$result = $this->db->sql_query_limit($sql, $limit , $start, (int) $this->tpotm->config_time_cache());
$result = $this->db->sql_query_limit($sql, $limit , $start, (int) $ttl_diff);
$rows = $this->db->sql_fetchrowset($result);
$this->db->sql_freeresult($result);

/* Total users count for pagination */
$result2 = $this->db->sql_query($sql, (int) $this->tpotm->config_time_cache());
$result2 = $this->db->sql_query($sql, (int) $ttl_diff);
$row2 = $this->db->sql_fetchrowset($result2);
$total_users = (int) count($row2);
$this->db->sql_freeresult($result2);
Expand Down
7 changes: 7 additions & 0 deletions ext.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@

class ext extends \phpbb\extension\base
{
/* Define constants */
const NO_CACHE = '0';
const ONE_DAY = '86400';
const ONE_WEEK = '604800';
const TWO_WEEKS = '1209600';
const ONE_MONTH = '2419200';

/**
* Check whether the extension can be enabled.
* Provides meaningful(s) error message(s) and the back-link on failure.
Expand Down
Loading

0 comments on commit fd14c73

Please sign in to comment.