Getting phpbb_root_path in core.modify_posting_parameters event

Discussion forum for Extension Writers regarding Extension Development.
User avatar
zlisiecki
Registered User
Posts: 134
Joined: Fri Jan 25, 2002 1:38 pm
Location: Warsaw
Contact:

Getting phpbb_root_path in core.modify_posting_parameters event

Post by zlisiecki » Mon Mar 25, 2019 11:06 pm

Hi,
i created some additional buttons above each post with core.viewtopic_modify_post_row event.
Now I'd like to acomplish certain tasks on a post by pressing these buttons.
If a button is pressed core.modify_posting_parameters event calls a button_pressed() routine.
This works fine, but I need also $phpbb_root_path inside of button_pressed() code, which I cannot find :

Code: Select all

class listener implements EventSubscriberInterface
{
   ...
    /** @var string phpBB root path */
    protected $phpbb_root_path;
    
    public function __construct(
       ...
        $phpbb_root_path,
        $php_ext)
    {
        ....
        $this->phpbb_root_path  = $phpbb_root_path;
        $this->php_ext          = $php_ext;

        $user->session_begin();
        $auth->acl($user->data);
        $user->setup();
        ...
     }
    
    static public function getSubscribedEvents()
    {
        return array(
            'core.viewtopic_modify_post_row'                	=>  'link_a_button',
            'core.viewtopic_assign_template_vars_before'	=>  'link_t_button',
            'core.modify_posting_parameters'			=>  'button_pressed',
        );
    }

    public function button_pressed ($event)
    {
        $this->user->setup();
        $this->user->add_lang_ext ....
        $post_id    = $event['post_id'];
        $topic_id   = $event['topic_id'];
        $forum_id   = $event['forum_id'];
        
echo "root_path: $phpbb_root_path <br>";
die ();

echo shows $phpbb_root_path is an empty variable. Where could I get it from ?

User avatar
zlisiecki
Registered User
Posts: 134
Joined: Fri Jan 25, 2002 1:38 pm
Location: Warsaw
Contact:

Re: Getting phpbb_root_path in core.modify_posting_parameters event

Post by zlisiecki » Mon Mar 25, 2019 11:09 pm

Possibly somebody knows an example with new buttons after edit/report/cite buttons, which utilizes $phpbb_root_path in the code.

User avatar
kinerity
Community Team Member
Community Team Member
Posts: 2228
Joined: Mon Sep 01, 2014 1:00 am
Location: sudo rm -rf /
Name: Kailey Truscott
Contact:

Re: Getting phpbb_root_path in core.modify_posting_parameters event

Post by kinerity » Tue Mar 26, 2019 12:05 am

Is it defined in your services file?

Code: Select all

- '%core.root_path%'
Also, in your listener, its actually $root_path.
Kailey Truscott - Community Team

Paul
Infrastructure Team Leader
Infrastructure Team Leader
Posts: 25182
Joined: Sat Dec 04, 2004 3:44 pm
Location: The netherlands.
Name: Paul Sohier
Contact:

Re: Getting phpbb_root_path in core.modify_posting_parameters event

Post by Paul » Tue Mar 26, 2019 1:17 am

You should use $this->phpbb_root_path as it is a property of.your class.

Also, why are you starting the session in your event handler? You really should not do.that.
Knock knock
Race condition
Who's there?

My BlogMy Photosmy phpBB Extensionscustom phpBB work & Development

User avatar
zlisiecki
Registered User
Posts: 134
Joined: Fri Jan 25, 2002 1:38 pm
Location: Warsaw
Contact:

Re: Getting phpbb_root_path in core.modify_posting_parameters event

Post by zlisiecki » Tue Mar 26, 2019 2:24 am

Hi Paul, yes, I deleted user session and setup

Code: Select all

        //$user->session_begin();
        $auth->acl($user->data);
        //$user->setup();
now. I possibly copied this from some example, which is wrong here. Thank you for your notice.


Well, the variable $this->phpbb_root_path of the listener instance is set in its' constructor

Code: Select all

    public function __construct(
        \phpbb\request\request $request,
        \phpbb\template\template $template,
        \phpbb\user $user,
        \phpbb\auth\auth $auth,
        $phpbb_root_path,
        $php_ext)
    {
        $this->request          = $request;
        $this->template         = $template;
        $this->user             = $user;
        $this->auth             = $auth;
        $this->phpbb_root_path  = $phpbb_root_path;
but the value is

Code: Select all

  $this->phpbb_root_path:  ./
whereas for example

Code: Select all

  $this->php_ext:  .php
, which seems to be correct.

The action started by some of my buttons is to move the entire post to some other place. I'd like to append a notice to the post itself where this post is coming from:

Code: Select all

moderators' notice:
Post moved from: http://localhost/./viewtopic.php?f=16&t=16396
The correct notice is

Code: Select all

Post moved from: http://localhost/~zbyszek/subdir/viewtopic.php?f=16&t=16396
It is this variable "~zbyszek/subdir" as it is written in script_path in phpbb_config table, which I am looking for. How could I get it directly in the button pressed event without consulting the database ?

Possibly I need something like

Code: Select all

use phpbb\event\data;
use phpbb\user; 
before "use Symfony\...." at the begining of the listener.php file or a additional namespace ? What do you think ?

User avatar
3Di
Former Team Member
Posts: 13664
Joined: Mon Apr 04, 2005 11:09 pm
Location: Milan (IT) Frankfurt (DE)
Name: Marco
Contact:

Re: Getting phpbb_root_path in core.modify_posting_parameters event

Post by 3Di » Tue Mar 26, 2019 3:17 am

This is the continue of this one of yours adding a simple button isn't?

I recall of it, you have been asked to put the extension as its whole on a place where we can lurk at the code in order to help you.

A good place, we all use it, it is GitHub.com.
Please PM me only to request paid works. Thx.
Want to compensate me for my interest? Donate
My development's activity º PhpStorm's proud user
Extensions, Scripts, MOD porting, Update/Upgrades
👨‍🏫 | Take a tour to | The Studio | 👨‍🏫

User avatar
zlisiecki
Registered User
Posts: 134
Joined: Fri Jan 25, 2002 1:38 pm
Location: Warsaw
Contact:

Re: Getting phpbb_root_path in core.modify_posting_parameters event

Post by zlisiecki » Tue Mar 26, 2019 9:03 am

Yes, this is the continuation of my former questions. My ext is actually running, but obviously it may be written more efficiently. I try to correct same errors. I am also not sure if I have chosen the best events for my buttons. Here is the repository, you've asked : https://github.com/zlisiecki/phpbb/branches . I put only three main files there for now. But it suffices if you read only the listener.php to answer the question of this thread. Once I change comments from polish to english and you find it has no very, very big errors, which I had to be ashamed of, I'll copy the whole ext to the github.

You'll find an explanation, why I need this ext in the header of listener.php .
Thank you in advance for all your suggestions.

Paul
Infrastructure Team Leader
Infrastructure Team Leader
Posts: 25182
Joined: Sat Dec 04, 2004 3:44 pm
Location: The netherlands.
Name: Paul Sohier
Contact:

Re: Getting phpbb_root_path in core.modify_posting_parameters event

Post by Paul » Tue Mar 26, 2019 9:28 am

./ is a correct root path. If you want the full board URL you should use generate_board_url()
Knock knock
Race condition
Who's there?

My BlogMy Photosmy phpBB Extensionscustom phpBB work & Development

User avatar
mrgoldy
Jr. Extension Validator
Posts: 1040
Joined: Tue Oct 06, 2009 7:34 pm
Location: The Netherlands
Name: Gijs

Re: Getting phpbb_root_path in core.modify_posting_parameters event

Post by mrgoldy » Tue Mar 26, 2019 10:17 am

There are no files in that github repository.
Also, don't feel ashamed of 'big errors' or any other coding, most of us "have seen it all" already anyways, we don't judge nor bite ;).
But in order to properly debug, usually we need to be able to browse the entire code, not parts of it.

As you're inside a viewtopic (viewtopic.php), the $phpbb_root_path should be ./, as you are already inside the root directory.
And as a small side note, $php_ext contains 'php', without the leading dot/period.

What you're probably misunderstanding, is that $phpbb_root_path generates a relative path, from the file you're currently in, to the file you want to go to. If you want to have a complete url with the your website and possible any subdirectory (script path), you have to indeed use generate_board_url() as Paul mentioned.
phpBB Studio / ''Proud member of the Studio"

User avatar
zlisiecki
Registered User
Posts: 134
Joined: Fri Jan 25, 2002 1:38 pm
Location: Warsaw
Contact:

Re: Getting phpbb_root_path in core.modify_posting_parameters event

Post by zlisiecki » Sun Mar 31, 2019 6:00 pm

Hi 3Di, could you pull my ext from github now and check it. I hope you can find it in https://github.com/zlisiecki/evot-buttons-for-phpbb

This project is not quite ready, but I hope after installing this ext you'll find a three new buttons over each post, some longer buttons over each topic and the same in tools. I hope the graphical buttons will be seen. I put them in my style, which you can consider to be a copy of prosilver. So you can simply copy png files in styles/prosilver/theme/images with a evot.css file above.

Let's concentrate on one button- the first one. It pushes a post to a special topic with the name "unwanted posts". You can also push it back from there.

What I'd like to know is your general advice about chosen events and the way I manage them in event/listener.php . Two other files move.php and movelib.php are important, the rest is standard. Stuff in acp and adm folders is not ready.

And now - what do I need it for ?
We have absolute no censorship in our forum, so we do not delete any posts. But some of them are quite disturbing. What moderators of my forum do is just moving such posts around to another places, so they do not disturb proper discussions, but also do not disappear.
We collect even spam in subfora for their IP numbers. Such places are not scanned by search machines, they are not seen by forum users, so they do not disturb there.

User avatar
zlisiecki
Registered User
Posts: 134
Joined: Fri Jan 25, 2002 1:38 pm
Location: Warsaw
Contact:

Re: Getting phpbb_root_path in core.modify_posting_parameters event

Post by zlisiecki » Tue Apr 02, 2019 9:12 pm

Let me specify also some other questions I have:
I am not sure, what is the easiest and most stright way to change the post, like to append some text to it, or delete some trailing sentences. I am doing it with the function append_text_to_post ($post_id, $text) in movelib.php . Is it ok, what I did ?

User avatar
zlisiecki
Registered User
Posts: 134
Joined: Fri Jan 25, 2002 1:38 pm
Location: Warsaw
Contact:

Re: Getting phpbb_root_path in core.modify_posting_parameters event

Post by zlisiecki » Thu Apr 11, 2019 6:17 am

By the way: do you provide a more exact description how to change add_log() into $phpbb_log->add('mod', ... ? The first form will deprecate soon. The best place for the new usage is somewhere in phpbb/log/log_interface.php code.

Especially I'd like to know how to insert %n parameters into the log string. For example I have in my language file:

Code: Select all

    'EMOVE_LOG_NIP_MOVED'   =>  '<strong>Post „%1$s” has been moved to ...
and now I'd like to add a log entry with:

Code: Select all

        $phpbb_log->add('mod',
            $user->data['user_id'],
            $user->ip,
            'EMOVE_LOG_NIP_MOVED',
            time(),
            array(
                'forum_id' => $forum_id,
                'topic_id' => $topic_id,
                $subject,
                $who_moves,
                ...
Surely I'd like to insert a string '<a href="post adres">post subject</a>' instaed of
„%1$s” into moderators logfile.

The logfile entry regards a specific post, so I'd like to offer for the logfile reader the possibility to read the post subject and to jump directly to this post.

User avatar
mrgoldy
Jr. Extension Validator
Posts: 1040
Joined: Tue Oct 06, 2009 7:34 pm
Location: The Netherlands
Name: Gijs

Re: Getting phpbb_root_path in core.modify_posting_parameters event

Post by mrgoldy » Thu Apr 11, 2019 1:57 pm

That's not really how logs work.
Logs are generally just strings, nothing more, nothing less.
Describing an action that took place. If you want to link to a certain place, you can let the log itself handle it automatically, by providing the forum id, topic id and post id. If they are provided, automatically a link with "View forum", "view topic" and "view post" will be shown.

But you're log entry looks good. Some data from the $additional_data is inserted into specific columns, mostly identifiers (forum, topic, post, reportee, etc) and the rest will be inserted into the language string ('EMOVE_LOG_NIP_MOVED' in your case).
phpBB Studio / ''Proud member of the Studio"

User avatar
zlisiecki
Registered User
Posts: 134
Joined: Fri Jan 25, 2002 1:38 pm
Location: Warsaw
Contact:

Re: Getting phpbb_root_path in core.modify_posting_parameters event

Post by zlisiecki » Sun Apr 28, 2019 4:39 pm

Hi, Mr.Goldy, could you explain it more exact, please ? What is $additional_data ? What are specific columns ? Is there an exact $phpbb_log->add()function usage description written somewhere ?

My log string 'EMOVE_LOG_NIP_MOVED' won't be find. It appears as such in the moderators log with a %1s parameter expanded ! But if i put $user->lang['EMOVE_LOG_NIP_MOVED'] instaed, than it is correct in the log, which means language file of my ext is correctly read. But in this case the parameter „%1$s”, which is inside it won't be expanded.

User avatar
mrgoldy
Jr. Extension Validator
Posts: 1040
Joined: Tue Oct 06, 2009 7:34 pm
Location: The Netherlands
Name: Gijs

Re: Getting phpbb_root_path in core.modify_posting_parameters event

Post by mrgoldy » Wed May 01, 2019 11:11 am

Have a look at the core files:
https://github.com/phpbb/phpbb/blob/mas ... g.php#L219
https://github.com/phpbb/phpbb/blob/mas ... ce.php#L69

Have a look at how other extensions log additional data.
For example, phpBB's Pages extension:
https://github.com/phpbb-extensions/pag ... r.php#L290
phpBB Studio / ''Proud member of the Studio"

Post Reply

Return to “Extension Writers Discussion”