Seite 2 von 3

Re: Zusätzliche Mitgliederinformationen

Verfasst: 19.05.2017 15:31
von befubo
Hi :)

Danke schonmal für die Antwort.
Also, ich hab jetzt versucht und versucht und versucht.
Folgenden Aufbau hab ich inzwischen:

board/ext/kv13/kv13/composer.json

Code: Alles auswählen

{
    "name" : "kv13/kv13",
    "type" : "phpbb-extension",
    "description" : "Test Erweiterung KV13",
    "version" : "1.0.0",
    "license" : "GPL-2.0",
    "require" : {
        "php" : ">=5.3.3"
    },
    "authors" : [{
        "name" : "befubo",
        "email" : "befubo@gmx.ch",
        "homepage" : "http://kampfverband-13.de",
        "role" : "Lead developer"
    }],
    "extra" : {
        "display-name" : "KV13 Erweiterung",
        "soft-require" : {
            "phpbb/phpbb" : ">=3.1.5,<3.2@dev"
        }
    }
}
board/ext/kv13/kv13/config/service.yml

Code: Alles auswählen

kv13.kv13.events.global_events:
    class: gn36\infobar\event\global_events
    arguments:
        - '@user'
        - '@template'
        - '@config'
    tags:
        - { name: event.listener }
board/ext/kv13/kv13/event/global_events.php

Code: Alles auswählen

<?php
namespace kv13\kv13\event;

class global_events implements \Symfony\Component\EventDispatcher\EventSubscriberInterface
{
        static public function getSubscribedEvents()
        {
                return array(
                        'core.viewtopic_assign_template_vars_before'    => 'kv13_erweiterung',
                        // Weitere Events
                );
        }

        /** @var \phpbb\user */
        protected $user;

        /** @var \phpbb\template\template */
        protected $template;

        /** @var \phpbb\config\config */
        protected $config;
        public function __construct(\phpbb\user $user, \phpbb\template\template $template, \phpbb\config\config $config)
        {
                $this->user = $user;
                $this->template = $template;
                $this->config = $config;
        }

        public function kv13_erweiterung($event)
        {
                //Sprachdateien in beliebigen Dateien einbinden wenn sie gerade gebraucht werden
                //$this->user->add_lang_ext('kv13/kv13', 'global');
                // Sprachdateien global einbinden
                $kv13_ary = $event['kv13_event'];
                $kv13_ary[] = array(
                        'KV13_EXT'      => 'Das ist ein Erweiterungs-Test',
                );
                $event['kv13_event'] = $kv13_ary;
        }
}
?>
board/ext/kv13/kv13/styles/we_universal_kv13/template/event/viewtopic_body_postrow_rank_before.html

Code: Alles auswählen

<p>DEBUG {KV13_EXT} TEXT</p>
Das Event, auf welches ich mich beziehe ist in der viewtopic.php:

Code: Alles auswählen

//[...]
/**
* Event to modify data before template variables are being assigned
*
* @event core.viewtopic_assign_template_vars_before
* @var	string	base_url			URL to be passed to generate pagination
* @var	int		forum_id			Forum ID
* @var	int		post_id				Post ID
* @var	array	quickmod_array		Array with quick moderation options data
* @var	int		start				Pagination information
* @var	array	topic_data			Array with topic data
* @var	int		topic_id			Topic ID
* @var	array	topic_tracking_info	Array with topic tracking data
* @var	int		total_posts			Topic total posts count
* @var	string	viewtopic_url		URL to the topic page
* @since 3.1.0-RC4
* @change 3.1.2-RC1 Added viewtopic_url
*/
$vars = array(
	'base_url',
	'forum_id',
	'post_id',
	'quickmod_array',
	'start',
	'topic_data',
	'topic_id',
	'topic_tracking_info',
	'total_posts',
	'viewtopic_url',
);
extract($phpbb_dispatcher->trigger_event('core.viewtopic_assign_template_vars_before', compact($vars)));

$pagination->generate_template_pagination($base_url, 'pagination', 'start', $total_posts, $config['posts_per_page'], $start);

// Send vars to template
$template->assign_vars(array(
	'FORUM_ID' 		=> $forum_id,
	'FORUM_NAME' 	=> $topic_data['forum_name'],
	'FORUM_DESC'	=> generate_text_for_display($topic_data['forum_desc'], $topic_data['forum_desc_uid'], $topic_data['forum_desc_bitfield'], $topic_data['forum_desc_options']),
	'TOPIC_ID' 		=> $topic_id,
	'TOPIC_TITLE' 	=> $topic_data['topic_title'],
	'TOPIC_POSTER'	=> $topic_data['topic_poster'],

	'TOPIC_AUTHOR_FULL'		=> get_username_string('full', $topic_data['topic_poster'], $topic_data['topic_first_poster_name'], $topic_data['topic_first_poster_colour']),
	'TOPIC_AUTHOR_COLOUR'	=> get_username_string('colour', $topic_data['topic_poster'], $topic_data['topic_first_poster_name'], $topic_data['topic_first_poster_colour']),
	'TOPIC_AUTHOR'			=> get_username_string('username', $topic_data['topic_poster'], $topic_data['topic_first_poster_name'], $topic_data['topic_first_poster_colour']),

	'TOTAL_POSTS'	=> $user->lang('VIEW_TOPIC_POSTS', (int) $total_posts),
	'U_MCP' 		=> ($auth->acl_get('m_', $forum_id)) ? append_sid("{$phpbb_root_path}mcp.$phpEx", "i=main&mode=topic_view&f=$forum_id&t=$topic_id" . (($start == 0) ? '' : "&start=$start") . ((strlen($u_sort_param)) ? "&$u_sort_param" : ''), true, $user->session_id) : '',
	'MODERATORS'	=> (isset($forum_moderators[$forum_id]) && sizeof($forum_moderators[$forum_id])) ? implode($user->lang['COMMA_SEPARATOR'], $forum_moderators[$forum_id]) : '',

	'POST_IMG' 			=> ($topic_data['forum_status'] == ITEM_LOCKED) ? $user->img('button_topic_locked', 'FORUM_LOCKED') : $user->img('button_topic_new', 'POST_NEW_TOPIC'),
	'QUOTE_IMG' 		=> $user->img('icon_post_quote', 'REPLY_WITH_QUOTE'),
	'REPLY_IMG'			=> ($topic_data['forum_status'] == ITEM_LOCKED || $topic_data['topic_status'] == ITEM_LOCKED) ? $user->img('button_topic_locked', 'TOPIC_LOCKED') : $user->img('button_topic_reply', 'REPLY_TO_TOPIC'),
	'EDIT_IMG' 			=> $user->img('icon_post_edit', 'EDIT_POST'),
	'DELETE_IMG' 		=> $user->img('icon_post_delete', 'DELETE_POST'),
	'DELETED_IMG'		=> $user->img('icon_topic_deleted', 'POST_DELETED_RESTORE'),
	'INFO_IMG' 			=> $user->img('icon_post_info', 'VIEW_INFO'),
	'PROFILE_IMG'		=> $user->img('icon_user_profile', 'READ_PROFILE'),
	'SEARCH_IMG' 		=> $user->img('icon_user_search', 'SEARCH_USER_POSTS'),
	'PM_IMG' 			=> $user->img('icon_contact_pm', 'SEND_PRIVATE_MESSAGE'),
	'EMAIL_IMG' 		=> $user->img('icon_contact_email', 'SEND_EMAIL'),
	'JABBER_IMG'		=> $user->img('icon_contact_jabber', 'JABBER') ,
	'REPORT_IMG'		=> $user->img('icon_post_report', 'REPORT_POST'),
	'REPORTED_IMG'		=> $user->img('icon_topic_reported', 'POST_REPORTED'),
	'UNAPPROVED_IMG'	=> $user->img('icon_topic_unapproved', 'POST_UNAPPROVED'),
	'WARN_IMG'			=> $user->img('icon_user_warn', 'WARN_USER'),

	'S_IS_LOCKED'			=> ($topic_data['topic_status'] == ITEM_UNLOCKED && $topic_data['forum_status'] == ITEM_UNLOCKED) ? false : true,
	'S_SELECT_SORT_DIR' 	=> $s_sort_dir,
	'S_SELECT_SORT_KEY' 	=> $s_sort_key,
	'S_SELECT_SORT_DAYS' 	=> $s_limit_days,
	'S_SINGLE_MODERATOR'	=> (!empty($forum_moderators[$forum_id]) && sizeof($forum_moderators[$forum_id]) > 1) ? false : true,
	'S_TOPIC_ACTION' 		=> append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f=$forum_id&t=$topic_id" . (($start == 0) ? '' : "&start=$start")),
	'S_MOD_ACTION' 			=> $s_quickmod_action,

	'L_RETURN_TO_FORUM'		=> $user->lang('RETURN_TO', $topic_data['forum_name']),
	'S_VIEWTOPIC'			=> true,
	'S_UNREAD_VIEW'			=> $view == 'unread',
	'S_DISPLAY_SEARCHBOX'	=> ($auth->acl_get('u_search') && $auth->acl_get('f_search', $forum_id) && $config['load_search']) ? true : false,
	'S_SEARCHBOX_ACTION'	=> append_sid("{$phpbb_root_path}search.$phpEx"),
	'S_SEARCH_LOCAL_HIDDEN_FIELDS'	=> build_hidden_fields($s_search_hidden_fields),

	'S_DISPLAY_POST_INFO'	=> ($topic_data['forum_type'] == FORUM_POST && ($auth->acl_get('f_post', $forum_id) || $user->data['user_id'] == ANONYMOUS)) ? true : false,
	'S_DISPLAY_REPLY_INFO'	=> ($topic_data['forum_type'] == FORUM_POST && ($auth->acl_get('f_reply', $forum_id) || $user->data['user_id'] == ANONYMOUS)) ? true : false,
	'S_ENABLE_FEEDS_TOPIC'	=> ($config['feed_topic'] && !phpbb_optionget(FORUM_OPTION_FEED_EXCLUDE, $topic_data['forum_options'])) ? true : false,

	'U_TOPIC'				=> "{$server_path}viewtopic.$phpEx?f=$forum_id&t=$topic_id",
	'U_FORUM'				=> $server_path,
	'U_VIEW_TOPIC' 			=> $viewtopic_url,
	'U_CANONICAL'			=> generate_board_url() . '/' . append_sid("viewtopic.$phpEx", "t=$topic_id" . (($start) ? "&start=$start" : ''), true, ''),
	'U_VIEW_FORUM' 			=> append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $forum_id),
	'U_VIEW_OLDER_TOPIC'	=> append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f=$forum_id&t=$topic_id&view=previous"),
	'U_VIEW_NEWER_TOPIC'	=> append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f=$forum_id&t=$topic_id&view=next"),
	'U_PRINT_TOPIC'			=> ($auth->acl_get('f_print', $forum_id)) ? $viewtopic_url . '&view=print' : '',
	'U_EMAIL_TOPIC'			=> ($auth->acl_get('f_email', $forum_id) && $config['email_enable']) ? append_sid("{$phpbb_root_path}memberlist.$phpEx", "mode=email&t=$topic_id") : '',

	'U_WATCH_TOPIC'			=> $s_watching_topic['link'],
	'U_WATCH_TOPIC_TOGGLE'	=> $s_watching_topic['link_toggle'],
	'S_WATCH_TOPIC_TITLE'	=> $s_watching_topic['title'],
	'S_WATCH_TOPIC_TOGGLE'	=> $s_watching_topic['title_toggle'],
	'S_WATCHING_TOPIC'		=> $s_watching_topic['is_watching'],

	'U_BOOKMARK_TOPIC'		=> ($user->data['is_registered'] && $config['allow_bookmarks']) ? $viewtopic_url . '&bookmark=1&hash=' . generate_link_hash("topic_$topic_id") : '',
	'S_BOOKMARK_TOPIC'		=> ($user->data['is_registered'] && $config['allow_bookmarks'] && $topic_data['bookmarked']) ? $user->lang['BOOKMARK_TOPIC_REMOVE'] : $user->lang['BOOKMARK_TOPIC'],
	'S_BOOKMARK_TOGGLE'		=> (!$user->data['is_registered'] || !$config['allow_bookmarks'] || !$topic_data['bookmarked']) ? $user->lang['BOOKMARK_TOPIC_REMOVE'] : $user->lang['BOOKMARK_TOPIC'],
	'S_BOOKMARKED_TOPIC'	=> ($user->data['is_registered'] && $config['allow_bookmarks'] && $topic_data['bookmarked']) ? true : false,

	'U_POST_NEW_TOPIC' 		=> ($auth->acl_get('f_post', $forum_id) || $user->data['user_id'] == ANONYMOUS) ? append_sid("{$phpbb_root_path}posting.$phpEx", "mode=post&f=$forum_id") : '',
	'U_POST_REPLY_TOPIC' 	=> ($auth->acl_get('f_reply', $forum_id) || $user->data['user_id'] == ANONYMOUS) ? append_sid("{$phpbb_root_path}posting.$phpEx", "mode=reply&f=$forum_id&t=$topic_id") : '',
	'U_BUMP_TOPIC'			=> (bump_topic_allowed($forum_id, $topic_data['topic_bumped'], $topic_data['topic_last_post_time'], $topic_data['topic_poster'], $topic_data['topic_last_poster_id'])) ? append_sid("{$phpbb_root_path}posting.$phpEx", "mode=bump&f=$forum_id&t=$topic_id&hash=" . generate_link_hash("topic_$topic_id")) : '')
);
//[...]

Ich hoffe man kann erkennen, was ich möchte:
Beim Profil links von einem Verfassten Post möchte ich jetzt über der Anzahl Beiträge testweise einfach den Satz "Das ist ein Erweiterungs-Test" einfügen lassen (Das kann ich dann ja später durch dynamischen Inhalt ersetzen).
Allerdings mach ich vermutlich alles falsch ^^
Zwar wird der Text "DEBUG TEXT" an genau der Stelle eingefügt, aber natürlich erscheint dazwischen nicht mein Testsatz.

Ausserdem versteh ich die Aufgabe von diesem Abschnitt (In der global_events.php):

Code: Alles auswählen

        public function __construct(\phpbb\user $user, \phpbb\template\template $template, \phpbb\config\config $config)
        {
                $this->user = $user;
                $this->template = $template;
                $this->config = $config;
        }
Ich steh aufm Schlauch und versuchs seit einer Woche ^^
Kann mir hier jemand mal vor Augen führen, was da noch fehlt?

Vielen Dank!

Re: Zusätzliche Mitgliederinformationen

Verfasst: 20.05.2017 00:19
von gn#36
Nah dran :D

Was du mit der Variablen $event anfangen kannst hängt davon ab, welches Event du verwendest. Hier versuchst du eine Templatevariable zu befüllen. Dafür brauchst du das Event eigentlich nur als Trigger und nicht um die Variablen an der Stelle im Ablauf zu manipulieren. Die Daten im Event kannst du z.B. nutzen, um nur auf bestimmte Foren oder Beiträge zu reagieren, oder den Beitragsinhalt zu manipulieren. Das brauchst du hier alles nicht, daher kannst du die Variable einfach links liegen lassen.

Um Daten ins Template zu schreiben musst du lediglich die Variable $this->template in deiner Methode kv13_erweiterung verwenden, und zwar genau so wie das auch in der phpBB Originaldatei passiert:

Code: Alles auswählen

$this->template->assign_vars(array(
'TEMPLATE_VARIABLE1' => 'textinhalt',
'KV13_EVENT' => 'Noch ein Textinhalt',
)); 

Re: Zusätzliche Mitgliederinformationen

Verfasst: 08.05.2018 12:37
von befubo
Moin zusammen,

ein Jahr her und mein Problem hab ich noch immer nicht lösen können ^^
Nachdem ich das Projekt vorerst wieder auf Eis gelegt hatte, hab ich mich jetzt mal wieder rangesetzt und neu eingelesen.
Tatsächlich stehe ich wieder am gleichen Punkt wie vor eine Jahr...

EDIT:
Ein paar neue Lichter sind mir nun aufgegangen. Hier mein aktueller Code:

service.yml

Code: Alles auswählen

kv13.rangsystem.events.global_events:
    class: kv13\rangsystem\event\global_events
	arguments:
    - '@template'
    tags:
        - { name: event.listener }
global_events.php

Code: Alles auswählen

<?php
namespace kv13\rangsystem\event;

class global_events implements \Symfony\Component\EventDispatcher\EventSubscriberInterface
{
        static public function getSubscribedEvents()
        {
                return array(
                        'core.viewtopic_assign_template_vars_before'    => 'kv13_erweiterung',
                );
        }
		
		protected $template;
		
		public function __construct(\phpbb\template\template $template)
   	   	{
            $this->template = $template;
     	}

        public function kv13_erweiterung($event)
        {
$this->template->assign_vars(array(
'KV13_EVENT' => 'Textinhalt',
)); 
        }
}
?>
viewtopic_body_postrow_rank_before.html:

Code: Alles auswählen

<dt>DEBUG {KV13_EVENT} TEXT</dt>
<hr>
Ich möchte also den Inhalte der Variable "KV13_EVENT" im Forum beim Profil neben dem Post anzeigen lassen.
Allerdings wird scheinbar die Variable nicht in das Template geschrieben und ich kann nicht nachvollziehen, wo der Fehler passiert...

Kann mir da wer helfen?
Vielen Dank!!

Re: Zusätzliche Mitgliederinformationen

Verfasst: 09.05.2018 17:00
von Kirk
Hallo
Ich habe es bei mir nachgestellt, die Variable {KV13_EVENT} wird an´s Template übergeben und erscheint auch.
Hier ein Bild davon, die rote Umrandung ist die Variable:
kv13_event_variable.jpg
kv13_event_variable.jpg (4.02 KiB) 2088 mal betrachtet

Re: Zusätzliche Mitgliederinformationen

Verfasst: 09.05.2018 19:33
von befubo
Hallo Kirk

Oha ^^
Hast du eine Ahnung, woran das liegen könnte?
Hatte jetzt auf dem Server einmal PHP 7.2 und einmal 5.6 - Dies hat keinen Unterschied gemacht.

[ externes Bild ]

Re: Zusätzliche Mitgliederinformationen

Verfasst: 09.05.2018 19:41
von Mahony
Hallo
Hast du auch den Cache geleert (vom Forum und vom Browser)?

Grüße: Mahony

Re: Zusätzliche Mitgliederinformationen

Verfasst: 09.05.2018 19:56
von befubo
@Mahony
Jop, Rekompilieren des Styles, Cache geleert und Browserdaten gelöscht...

Re: Zusätzliche Mitgliederinformationen

Verfasst: 09.05.2018 20:29
von Kirk
Ich nehme mal an das du dich mit service.yml verschrieben hast.
Davon abgesehen passt der Code in der services.yml nicht, ersetze mal den kompletten Code hiermit:

Code: Alles auswählen

services:
    kv13.rangsystem.global_events:
        class: kv13\rangsystem\event\global_events
        arguments:
            - '@template'
        tags:
        - { name: event.listener }
Edit:
Entferne zusätzlich noch das hier ?> am Ende deiner global_events.php

Re: Zusätzliche Mitgliederinformationen

Verfasst: 09.05.2018 20:54
von gn#36
Zur Ergänzung: in yml Dateien ist die Einrückung sehr wichtig. Zusätzliche Leerzeichen zerstören den Zusammenhang, und nicht nur die Lesbarkeit. Damit werden dann Arrays in PHP falsch eingelesen. Deine YML Datei hat Fehler in der Einrückung, abgesehen vom Dateinamen könnten daher die Probleme stammen.

Re: Zusätzliche Mitgliederinformationen

Verfasst: 09.05.2018 21:02
von Kirk
Was vielleicht auch noch zu erwähnen würde in der services.yml darf nur Leerzeichen zur Einrückung benutzt werden und keine Tabs.