Skip to content
Permalink
Browse files

prep-RC4 v1.0.3

  • Loading branch information...
3Di
3Di committed Jan 12, 2016
1 parent bfeb867 commit d80774319617a3d9accb38563e2cc04e27a8d59c
Showing with 80 additions and 34 deletions.
  1. +1 −1 README.md
  2. +3 −4 composer.json
  3. +2 −0 config/services.yml
  4. +31 −25 event/listener.php
  5. +35 −0 ext.php
  6. +7 −3 language/en/common.php
  7. +1 −1 styles/prosilver/template/event/index_body_block_stats_append.html
@@ -1,6 +1,6 @@
# tpotm

Top Poster of the month is an extension that requires at least phpBB version 3.1.0-b3.
Top Poster of the month is an extension that requires at least phpBB version 3.1.3.

This is a port of the MOD I made first for phpBB2 and for phpBB3 (Olympus) then.

@@ -1,10 +1,9 @@
{
"name": "threedi/tpotm",
"type": "phpbb-extension",
"description": "Have a Top Poster of the Month to show on your phpBB. Founder, Admins and Global Moderators are not included.",
"description": "Have a Top Poster of the Month to show on your phpBB. Founder, Admins and Moderators are excluded by default. The last poster with the max posts in the current month wins ",
"homepage": "http://3d-i.github.io/tpotm/",
"version": "1.0.2",
"time": "2015-10-07",
"version": "1.0.3",
"license": "GPL-2.0",
"authors":
[
@@ -41,7 +40,7 @@
"Top Poster Of The Month",
"soft-require":
{
"phpbb/phpbb": ">=3.1.0-b3,<3.2.*@dev"
"phpbb/phpbb": ">=3.1.3,<3.2.*@dev"
},
"version-check":
{
@@ -2,7 +2,9 @@ services:
threedi.tpotm.listener:
class: threedi\tpotm\event\listener
arguments:
- @auth
- @cache
- @config
- @template
- @user
- @dbal.conn
@@ -1,8 +1,8 @@
<?php
/**
*
* @package phpBB Extension - tpotm 1.0.2-(Top Poster Of The Month)
* @copyright (c) 2015 3Di (Marco T.)
* @package phpBB Extension - tpotm 1.0.3-(Top Poster Of The Month)
* @copyright (c) 2005 - 2008 - 2015 3Di (Marco T.)
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/
@@ -20,13 +20,13 @@
class listener implements EventSubscriberInterface
{
/** @var \phpbb\auth\auth */
//protected $auth; // not yet in use
protected $auth;
/** @var \phpbb\cache\service */
protected $cache;
/** @var \phpbb\config\config */
//protected $config; // not yet in use
protected $config;
/** @var \phpbb\template\template */
protected $template;
@@ -48,12 +48,11 @@ class listener implements EventSubscriberInterface
* @param \phpbb\db\driver\driver $db Database object
* @access public
*/
public function __construct(
\phpbb\cache\service $cache, \phpbb\template\template $template, \phpbb\user $user, \phpbb\db\driver\driver_interface $db)
public function __construct(\phpbb\auth\auth $auth, \phpbb\cache\service $cache, \phpbb\config\config $config, \phpbb\template\template $template, \phpbb\user $user, \phpbb\db\driver\driver_interface $db)
{
//$this->auth = $auth; // not yet in use
$this->auth = $auth;
$this->cache = $cache;
//$this->config = $config; // not yet in use
$this->config = $config;
$this->template = $template;
$this->user = $user;
$this->db = $db;
@@ -83,38 +82,42 @@ public function display_tpotm($event)
{
$now = time();
$date_today = gmdate("Y-m-d", $now);
list($year_cur, $month_cur, $day1) = split('-', $date_today);
list($year_cur, $month_cur, $day1) = explode('-', $date_today);
/* Start time for current month */
$month_start_cur = gmmktime (0,0,0, $month_cur, 1, $year_cur);
$month_start = $month_start_cur;
$month_end = $now;
/*
* group_id 5 = administrators
* group_id 4 = global moderators
* per default into a Vanilla 3.1.x board
*/
$group_ids = array(5, 4);
/* config time for cache, hinerits from View online time span */
$config_time_cache = (int) ($this->config['load_online_time'] * 60);
/* grabs the number of minutes to show for templating purgoses */
$config_time_cache_min = (int) ($this->config['load_online_time']);
/*
* config time for cache, still to be fully implemented thus hardcoded
* 900 = 15 minutes
* Borrowed from Top Five ext
* grabs all admins and mods, it is a catch all
*/
$config_time_cache = 900;
$admin_ary = $this->auth->acl_get_list(false, 'a_', false);
$admin_ary = (!empty($admin_ary[0]['a_'])) ? $admin_ary[0]['a_'] : array();
$mod_ary = $this->auth->acl_get_list(false,'m_', false);
$mod_ary = (!empty($mod_ary[0]['m_'])) ? $mod_ary[0]['m_'] : array();
/* groups the above results */
$admin_mod_array = array_unique(array_merge($admin_ary, $mod_ary));
/* Check cached data */
if (($row = $this->cache->get('_tpotm')) === false)
{
$sql = 'SELECT u.username, u.user_id, u.user_colour, u.user_type, u.group_id, p.poster_id, p.post_time, COUNT(p.post_id) AS total_posts
$sql = 'SELECT u.username, u.user_id, u.user_colour, u.user_type, p.poster_id, p.post_time, COUNT(p.post_id) AS total_posts
FROM ' . USERS_TABLE . ' u, ' . POSTS_TABLE . ' p
WHERE u.user_id > ' . ANONYMOUS . '
AND u.user_id = p.poster_id
AND (u.user_type <> ' . USER_FOUNDER . ')
AND ' . $this->db->sql_in_set('u.group_id', $group_ids, true) . '
AND ' . $this->db->sql_in_set('u.user_id', $admin_mod_array, true) . '
AND p.post_time BETWEEN ' . $month_start . ' AND ' . $month_end . '
GROUP BY u.user_id
ORDER BY total_posts DESC';
ORDER BY total_posts DESC, p.post_time DESC';
$result = $this->db->sql_query_limit($sql, 1);
$row = $this->db->sql_fetchrow($result);
@@ -127,20 +130,23 @@ public function display_tpotm($event)
/* Let's show the Top Poster then */
$tpotm_tot_posts = (int) $row['total_posts'];
$tpotm_un_string = get_username_string('full', $row['user_id'], $row['username'], $row['user_colour']);
/* Fresh installs or new Month starts give zero posts */
/* only auth'd users can view the profile */
$tpotm_un_string = ($this->auth->acl_get('u_viewprofile')) ? get_username_string('full', $row['user_id'], $row['username'], $row['user_colour']) : get_username_string('no_profile', $row['user_id'], $row['username'], $row['user_colour']);
/* Fresh install or when a new Month starts gives zero posts */
$tpotm_un_nobody = $this->user->lang['TPOTM_NOBODY'];
$tpotm_post = $this->user->lang('TPOTM_POST', (int) $tpotm_tot_posts);
$tpotm_cache = $this->user->lang('TPOTM_CACHE', (int) $config_time_cache_min);
$tpotm_name = ($tpotm_tot_posts < 1) ? $tpotm_un_nobody : $tpotm_un_string;
/* you know.. template stuffs */
$this->template->assign_vars(array(
'TPOTM_NAME' => $tpotm_name,
'L_TPOTM_CAT' => $this->user->lang['TPOTM_CAT'],
'L_TPOTM_NOW' => $this->user->lang['TPOTM_NOW'],
'L_TPOTM_POST' => $tpotm_post,
'L_TPOTM_CACHE' => $tpotm_cache,
));
}
}
35 ext.php
@@ -0,0 +1,35 @@
<?php
/**
*
* @package Online Since
*
* @package phpBB Extension - tpotm 1.0.3-(Top Poster Of The Month)
* @copyright (c) 2005 - 2008 - 2015 3Di (Marco T.)
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/
namespace threedi\tpotm;
/**
* Extension class for custom enable/disable/purge actions
*/
class ext extends \phpbb\extension\base
{
/**
* Check whether or not the extension can be enabled.
* The current phpBB version should meet or exceed
* the minimum version required by this extension:
*
* Requires phpBB 3.1.3 due to usage of http_exception.
*
* @return bool
* @access public
*/
public function is_enableable()
{
$config = $this->container->get('config');
return phpbb_version_compare($config['version'], '3.1.3', '>=');
}
}
@@ -3,7 +3,7 @@
*
* tpotm 1.0.2 [English]
*
* @package phpBB Extension - tpotm 1.0.2-(Top Poster Of The Month)
* @package phpBB Extension - tpotm 1.0.3-(Top Poster Of The Month)
* @copyright (c) 2005 - 2008 - 2015 3Di (Marco T.)
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*
@@ -37,8 +37,12 @@
$lang = array_merge($lang, array(
'TPOTM_CAT' => 'Top Poster of the Month',
'TPOTM_NOW' => 'At the present time is ',
'TPOTM_NOBODY' => '<strong>N/A</strong>',
'TPOTM_CACHE_EXPLAIN' => ' (<i>updates every 15 minutes</i>)',
'TPOTM_NOBODY' => 'not yet available,',
'TPOTM_CACHE' => array(
1 => ' (<i>updates every <strong>%d</strong> minute</i>)',
2 => ' (<i>updates every <strong>%d</strong> minutes</i>)',
),
'TPOTM_POST' => array(
1 => ' with a total of <strong>%d</strong> post',
@@ -1,2 +1,2 @@
<h3>{L_TPOTM_CAT}</h3>
<p>{L_TPOTM_NOW}<b>{TPOTM_NAME}</b>{L_TPOTM_POST}{L_TPOTM_CACHE_EXPLAIN}</p>
<p>{L_TPOTM_NOW}<b>{TPOTM_NAME}</b>{L_TPOTM_POST}{L_TPOTM_CACHE}</p>

0 comments on commit d807743

Please sign in to comment.
You can’t perform that action at this time.