1717use phpbb \event \data ;
1818use phpbb \auth \auth ;
1919use phpbb \template \template ;
20+ use phpbb \language \language ;
2021use phpbb \titania \controller \helper ;
2122use phpbb \titania \ext ;
2223use phpbb \user ;
@@ -44,6 +45,9 @@ class main_listener implements EventSubscriberInterface
4445 /** @var \phpbb\template\template */
4546 protected $ template ;
4647
48+ /** @var \phpbb\language\language */
49+ protected $ language ;
50+
4751 /** @var \phpbb\titania\controller\helper */
4852 protected $ controller_helper ;
4953
@@ -79,12 +83,13 @@ class main_listener implements EventSubscriberInterface
7983 * @param string $ext_root_path Titania root path
8084 * @param string $php_ext PHP file extension
8185 */
82- public function __construct (request $ request , db_driver_interface $ db , user $ user , template $ template , helper $ controller_helper , access $ access , type_collection $ types , $ phpbb_root_path , $ ext_root_path , $ php_ext )
86+ public function __construct (request $ request , db_driver_interface $ db , user $ user , template $ template , language $ language , helper $ controller_helper , access $ access , type_collection $ types , $ phpbb_root_path , $ ext_root_path , $ php_ext )
8387 {
8488 $ this ->request = $ request ;
8589 $ this ->db = $ db ;
8690 $ this ->user = $ user ;
8791 $ this ->template = $ template ;
92+ $ this ->language = $ language ;
8893 $ this ->controller_helper = $ controller_helper ;
8994 $ this ->access = $ access ;
9095 $ this ->types = $ types ;
@@ -97,16 +102,18 @@ public function __construct(request $request, db_driver_interface $db, user $use
97102 static public function getSubscribedEvents ()
98103 {
99104 return array (
100- 'core.permissions ' => 'add_permissions ' ,
101- 'kernel.request ' => array (array ('startup ' , -1 )),
102- 'core.page_header_after ' => 'overwrite_template_vars ' ,
103- 'core.text_formatter_s9e_configure_after ' => 'inject_bbcode_code_lang ' ,
105+ 'core.permissions ' => 'add_permissions ' ,
106+ 'kernel.request ' => array (array ('startup ' , -1 )),
107+ 'core.page_header_after ' => 'overwrite_template_vars ' ,
108+ 'core.text_formatter_s9e_configure_after ' => 'inject_bbcode_code_lang ' ,
104109
105110 // Check whether a user is removed from a team
106- 'core.group_delete_user_after ' => 'remove_users_from_subscription ' ,
111+ 'core.group_delete_user_after ' => 'remove_users_from_subscription ' ,
107112
108113 // Include quoted text when private messaging
109- 'core.ucp_pm_compose_predefined_message ' => 'quote_text_upon_pm ' ,
114+ 'core.ucp_pm_compose_predefined_message ' => 'quote_text_upon_pm ' ,
115+
116+ 'core.memberlist_view_profile ' => 'add_memberlist_template_vars ' ,
110117 );
111118 }
112119
@@ -406,4 +413,40 @@ public function quote_text_upon_pm($event)
406413 }
407414 }
408415 }
416+
417+ /**
418+ * Display contribution count and link to Titania profile in memberlist.php.
419+ * @param $event
420+ */
421+ public function add_memberlist_template_vars ($ event )
422+ {
423+ if (!defined ('TITANIA_CONTRIBS_TABLE ' ))
424+ {
425+ // Include Titania so we can access the constants
426+ require ($ this ->ext_root_path . 'common. ' . $ this ->php_ext );
427+ }
428+
429+ $ this ->language ->add_lang (['memberlist ' ], 'phpbb/titania ' );
430+
431+ $ sql = 'SELECT COUNT(contrib_id) as contribs
432+ FROM ' . TITANIA_CONTRIBS_TABLE . '
433+ WHERE contrib_user_id = ' . (int ) $ event ['member ' ]['user_id ' ] . '
434+ AND contrib_status = 2 ' ;
435+
436+ $ result = $ this ->db ->sql_query ($ sql );
437+
438+ $ u_total_contribs = (int ) $ this ->db ->sql_fetchfield ('contribs ' );
439+
440+ $ this ->db ->sql_freeresult ($ result );
441+
442+ $ u_user_contribs = $ this ->controller_helper ->route ('phpbb.titania.author ' , array (
443+ 'author ' => urlencode ($ event ['member ' ]['username_clean ' ]),
444+ 'page ' => 'contributions ' ,
445+ ));
446+
447+ $ this ->template ->assign_vars (array (
448+ 'U_USER_CONTRIB_TOTAL ' => $ u_total_contribs ,
449+ 'U_USER_CONTRIB_LINK ' => $ this ->controller_helper ->get_real_url ($ u_user_contribs ),
450+ ));
451+ }
409452}
0 commit comments