Skip to content

Commit

Permalink
Add support for recent topics extension
Browse files Browse the repository at this point in the history
  • Loading branch information
rmcgirr83 committed Dec 1, 2024
1 parent be6c4aa commit ef7a10c
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 4 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
"type": "phpbb-extension",
"description": "Allows a user to be able to choose a national flag and have a top (those with the most users selecting the flag) number of flags display on the index page of a phpBB forum. Header is link to a listing of all users of a flag. Clicking on user count of the flag displays the users that have that flag set. This extension requires at least phpBB version 3.3.4. Must have version 2.0.0 of Collapsible Forum Categories to take advantage of that extension.",
"homepage": "https://github.com/rmcgirr83/nationalflags",
"version": "2.4.0",
"time": "2024-08-10",
"version": "2.4.1",
"time": "2024-12-01",
"keywords": [
"phpbb",
"extension",
Expand Down
1 change: 1 addition & 0 deletions config/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ services:
- '%core.root_path%'
- '%core.php_ext%'
- '@rmcgirr83.nationalflags.nationalflags'
- '@?paybas.recenttopics.functions'
tags:
- { name: event.listener }

Expand Down
3 changes: 2 additions & 1 deletion core/nationalflags.php
Original file line number Diff line number Diff line change
Expand Up @@ -253,14 +253,15 @@ public function top_flags()
$count = 0;
for ($i = 0; $i < $max_display; ++$i)
{
++$count;
if (!empty($cached_flags[$i]['user_count']))
{
$this->template->assign_block_vars('flag', [
'FLAG' => $this->get_user_flag($cached_flags[$i]['flag_id']),
'FLAG_USERS' => $this->user->lang('FLAG_USERS', (int) $cached_flags[$i]['user_count']),
'U_FLAG' => $this->helper->route('rmcgirr83_nationalflags_getflags', ['flag_id' => $cached_flags[$i]['flag_id']]),
]);

++$count;
}
}

Expand Down
30 changes: 29 additions & 1 deletion event/listener.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
use phpbb\user;
use phpbb\extension\manager;
use rmcgirr83\nationalflags\core\nationalflags;
use paybas\recenttopics\core\recenttopics;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;

/**
Expand Down Expand Up @@ -66,6 +67,9 @@ class listener implements EventSubscriberInterface
/* @var nationalflags $nationalflags */
protected $nationalflags;

/* @var recenttopics $recenttopics */
protected $recenttopics;

/**
* Constructor
*
Expand All @@ -81,6 +85,7 @@ class listener implements EventSubscriberInterface
* @param string $root_path phpBB root path
* @param string $php_ext phpEx
* @param nationalflags $nationalflags methods to be used by class
* @param recenttopics $recenttopics recent topics extension
* @access public
*/
public function __construct(
Expand All @@ -95,7 +100,8 @@ public function __construct(
manager $ext_manager,
string $root_path,
string $php_ext,
nationalflags $nationalflags)
nationalflags $nationalflags,
recenttopics $recenttopics = null)
{
$this->auth = $auth;
$this->config = $config;
Expand All @@ -109,6 +115,7 @@ public function __construct(
$this->root_path = $root_path;
$this->php_ext = $php_ext;
$this->nationalflags = $nationalflags;
$this->recenttopics = $recenttopics;

$this->ext_path = $this->ext_manager->get_extension_path('rmcgirr83/nationalflags', true);
}
Expand Down Expand Up @@ -150,6 +157,7 @@ static public function getSubscribedEvents()
'core.display_forums_modify_template_vars' => 'display_forums_modify_template_vars',
'core.viewforum_modify_page_title' => 'viewforum_modify_page_title',
'core.viewforum_modify_topicrow' => 'viewforum_modify_topicrow',
'paybas.recenttopics.modify_tpl_ary' => 'recenttopics_modify_tpl_ary',
];
}

Expand Down Expand Up @@ -611,4 +619,24 @@ public function viewforum_modify_topicrow($event)

$event['topic_row'] = $template_vars;
}


public function recenttopics_modify_tpl_ary($event)
{
$row = $event['row'];
$topic_starter = $this->nationalflags->user_flag_id($event['row']['topic_poster']);
$last_post_author = $this->nationalflags->user_flag_id($event['row']['topic_last_poster_id']);
$template_vars = $event['tpl_ary'];

if (!empty($topic_starter) && $this->nationalflags->display_flags_on_forum($this->config['flags_forumrow']))
{
$template_vars['TOPIC_AUTHOR_FULL'] .= '&nbsp;' . $this->nationalflags->get_user_flag($topic_starter, 12);
}
if (!empty($last_post_author) && $this->nationalflags->display_flags_on_forum($this->config['flags_forumrow']))
{
$template_vars['LAST_POST_AUTHOR_FULL'] .= '&nbsp;' . $this->nationalflags->get_user_flag($last_post_author, 12);
}

$event['tpl_ary'] = $template_vars;
}
}

0 comments on commit ef7a10c

Please sign in to comment.