[3.2][3.3][RC] Display Only First Post

A place for Extension Authors to post and receive feedback on Extensions still in development. No Extensions within this forum should be used within a live environment!
Suggested Hosts
Forum rules
READ: phpBB.com Board-Wide Rules and Regulations

IMPORTANT: Extensions Development rules

IMPORTANT FOR NEEDED EVENTS!!!
If you need an event for your extension please read this for the steps to follow to request the event(s)
User avatar
axe70
Registered User
Posts: 751
Joined: Sun Nov 17, 2002 10:55 am
Location: Italy
Name: Alessio

[3.2][3.3][RC] Display Only First Post

Post by axe70 »

Has been passed for validation this new extension:

Display Only the First Post to specified groups


In the while it has not been approved you can find out the code here:
https://github.com/axew3/phpbb-display-only-first-post

The (very easy and fast) code just accomplish with this:
Display Only the First Post to specified groups, or display Only the First Post to specified groups and replace replies post's content with custom content

To install just copy as is the folder w3all into your phpBB /ext folder

-> I want to display custom content in place of the default text!

Notes: attachments have not been considered since attachments rules can be managed independently as needed for each group, it is a default phpBB option.

The result will be (+-, old pics) this, and any suggestion or help on improve it is welcome!
You do not have the required permissions to view the files attached to this post.
Do not take me too serious
Anyway i do not like Discourse
User avatar
warmweer
Jr. Extension Validator
Posts: 11856
Joined: Fri Jul 04, 2003 6:34 am
Location: Van Allen Bel ... gium

Re: [3.2][3.3][RC] Display Only First Post

Post by warmweer »

axe70 wrote: Wed Aug 17, 2022 7:39 am Has been passed for validation this new extension:
Just to be clear: it was submitted for validation (which doesn't imply that it's approved)
In essence you're requiring that the administrator edits an/some extension file(s).

Although this method works, I think this conflicts with extension policy (I'll have to check up on that).
it would be better to provide an option in the extension settings: an area in which the administrator can enter a text which would override the default language entry (per each language installed).
Spelling is freeware, which means you can use it for free.
On the other hand, it is not open source, which means you cannot change it or publish it in a modified form.


Time flies like an arrow, but fruit flies like a banana.
User avatar
axe70
Registered User
Posts: 751
Joined: Sun Nov 17, 2002 10:55 am
Location: Italy
Name: Alessio

Re: [3.2][3.3][RC] Display Only First Post

Post by axe70 »

No, you can also use as is.
If you want to change the phrase on lang file with a custom content it is up to you.
May it can be a feature to add, it will be easy, if someone may like it as option on acp.

While there is another problem that has been just patched.
The hidden post is the first on each page, if the topic is divided into more than one page.
That was wrong.
Also the asort() into array was wrong, so removed.
It has been now resolved, the code logic has been simplified using
the topic_first_post_id value
and the main_listener.php file has been patched

https://github.com/axew3/phpbb-display- ... stener.php

[EDITED]
Do not take me too serious
Anyway i do not like Discourse
User avatar
warmweer
Jr. Extension Validator
Posts: 11856
Joined: Fri Jul 04, 2003 6:34 am
Location: Van Allen Bel ... gium

Re: [3.2][3.3][RC] Display Only First Post

Post by warmweer »

axe70 wrote: Wed Aug 17, 2022 12:42 pm ...
While there is another problem that has been just patched.
The hidden post is the first on each page, if the topic is divided into more than one page.
That was wrong.
I'm assuming your statement is incorrect due to English not being your native language.
The only post(s) NOT hidden were the oldest posts on each page, irrespective of sort order, however !!! sortorder can be changed by the user and thus, in playing around with sortorder I could read even more posts than the number of pages (which in itself was already wrong).
topic_first_post_id is at first sight correct BUT: if the extension Change Post Time was used, either forwarding the post_time of the topic_first_post_id, or antedating another post) the result won't be consistent
First post should be seen as a temporal criterium independent of post_id (IMHO).
Spelling is freeware, which means you can use it for free.
On the other hand, it is not open source, which means you cannot change it or publish it in a modified form.


Time flies like an arrow, but fruit flies like a banana.
User avatar
GanstaZ
Registered User
Posts: 1221
Joined: Wed Oct 11, 2017 10:29 pm
Location: GZOverse

Re: [3.2][3.3][RC] Display Only First Post

Post by GanstaZ »

I don't know if rules for validation have changed or not, but you should really re-check your code.
For example in main-listener file: has a lot of readability issues or in other words its' not based on (phpBB) coding guidelines.
Usus est magister optimus! phpBB pre-Triton & latest php environment.
When answer lies in the question, question becomes redundant!
User avatar
axe70
Registered User
Posts: 751
Joined: Sun Nov 17, 2002 10:55 am
Location: Italy
Name: Alessio

Re: [3.2][3.3][RC] Display Only First Post

Post by axe70 »

About code rules, you may speak about some var name?
It can be easily changed. But it is not what about validators warned me.
While there is another problem that has been just patched.
The hidden post is the first on each page, if the topic is divided into more than one page.
That was wrong.
I mean to say (wrongly sorry) that the first post into each page was display, if the post divided into more pages.
And it has been solved.

As the code is it work perfect now on my tests, please if you can substitute the main_listener.php with the new one (may you tested, if tested, with the old code)
https://github.com/axew3/phpbb-display- ... s/main.zip

... so let say about an user that set to view the topic by author, and of course, the first post of the topic may result to be into the middle of the page (as on attach), and it is not the first on page. But it is very normal i assume. And correct.
I think that an user that is not registered or is not allowed to view the content, will not follow on setting up by author and so on.
May will think to register.
And more than this: the important is about descendant or ascendant, that is correct now, without using asort().
The important is to hide REPLIES, not the FIRST post on the topic depending on how the user setup the view option, isn't it?
It need to display ONLY the first post of the topic. Beside and despite any user view setting
You do not have the required permissions to view the files attached to this post.
Do not take me too serious
Anyway i do not like Discourse
User avatar
warmweer
Jr. Extension Validator
Posts: 11856
Joined: Fri Jul 04, 2003 6:34 am
Location: Van Allen Bel ... gium

Re: [3.2][3.3][RC] Display Only First Post

Post by warmweer »

axe70 wrote: Wed Aug 17, 2022 5:22 pm ...
I think that an user that is not registered or is not allowed to view the content, will not follow on setting up by author and so on.
May will think to register.
...
But for the small detail that you allow selecting groups for which the extension feature is active, and the members of some of those groups can probably change display options (and thus bypass the extension objective) (that is in the extension version I tested - I take it that will be changed, or has been changed already).
Spelling is freeware, which means you can use it for free.
On the other hand, it is not open source, which means you cannot change it or publish it in a modified form.


Time flies like an arrow, but fruit flies like a banana.
User avatar
axe70
Registered User
Posts: 751
Joined: Sun Nov 17, 2002 10:55 am
Location: Italy
Name: Alessio

Re: [3.2][3.3][RC] Display Only First Post

Post by axe70 »

I follow on to not understand sorry, my limit.

There is no way to bypass the fact that the first post, intended as the first post that started the topic, is the unique that is visible, despite any setting you can change.
And it will affect all groups as it is set into related ACP option.

You may mean to say, that you would like to see on top of the topic, despite any setting, the first post, despite the topic accessed with option "order by author"?

Or could you please indicate to me what is wrong, may a screenshot, so that i can reproduce and better understand your point?
Thank you
Do not take me too serious
Anyway i do not like Discourse
User avatar
warmweer
Jr. Extension Validator
Posts: 11856
Joined: Fri Jul 04, 2003 6:34 am
Location: Van Allen Bel ... gium

Re: [3.2][3.3][RC] Display Only First Post

Post by warmweer »

axe70 wrote: Wed Aug 17, 2022 5:44 pm You mean to say, that you would like to see on top of the topic, despite any setting, the first post, despite the topic accessed with option "order by author"?
NO

The extension is meant to show the post which starts a topic only.
The important part here is: what is the starting post and this could be up for discussion because when a topic is started, that post is the first post, and has a fixed post_id and a unique timestamp. So generally that post would be considered the first post, irrespective of post sorting order.
However, in special cases the timestamp of that post can be edited and then that post_id may not be the "starting" post of that topic anymore.

Granted: it's a special case, but I've done it very often and not only on my boards. In that case the oldest post in that topic will not be the original topic_start_post, but there will still be only 1 current starting post and that will be the post with the lowest/smallest timestamp, and that is the 1 and only post which should be readable (according to the intention of the extension) irrespective of sort order. This does imply that the position of that "starting" post will depend on sort_order and sort criterium UNLESS you always show that post before all the others (which are "censored") (meaning on top of topic_page 1). In fact an extension like this shouldn't even show the timestamps and authors of other posts.

IMHO the best way to do this would be to show the topic with 1 post (the starting post based on timestamp) and a following area showing a message stating something like xxx more posts in this topic can be read if ...
Spelling is freeware, which means you can use it for free.
On the other hand, it is not open source, which means you cannot change it or publish it in a modified form.


Time flies like an arrow, but fruit flies like a banana.
User avatar
axe70
Registered User
Posts: 751
Joined: Sun Nov 17, 2002 10:55 am
Location: Italy
Name: Alessio

Re: [3.2][3.3][RC] Display Only First Post

Post by axe70 »

In fact an extension like this shouldn't even show the timestamps and authors of other posts.
You can choose to hide post changing option.
Granted: it's a special case, but I've done it very often and not only on my boards
I assumed that the array coming with
['topic_data']['topic_first_post_id'] always contain the right first post ID.
How it can be reproduced the fact that the array instead, change the first topic_first_post_id that is not correctly set to the first post, even if it changed? Deleting some post? phpBB do not update the value?
Do not take me too serious
Anyway i do not like Discourse
User avatar
warmweer
Jr. Extension Validator
Posts: 11856
Joined: Fri Jul 04, 2003 6:34 am
Location: Van Allen Bel ... gium

Re: [3.2][3.3][RC] Display Only First Post

Post by warmweer »

axe70 wrote: Wed Aug 17, 2022 6:25 pm
Granted: it's a special case, but I've done it very often and not only on my boards
I assumed that the array coming with
['topic_data']['topic_first_post_id'] always contain the right first post ID.
It does (unless an Extension such as Change post Time is used, or some manual database edits).Too long to explain but on one of my boards where I needed to split posts in 2 or 3 and moving to new topics or adding to existing topics, sometimes as a topic starter, required timestamp editing to get the sorting right.

There is a topic cloning feature but no post cloning, so instead of cloning a topic and then removing unnecessary posts from the cloned topic, I created new posts and then edited timestamps. In a case like that post_ids cannot be used as a sort criterium, but timestamps are always a good criterium.
So: to cut this discussion short (because it's going way off-topic): post_id are fine as long as no post_timestamps are edited.
My point is that if sorting should be done based on time, then time should be used in the query.
Spelling is freeware, which means you can use it for free.
On the other hand, it is not open source, which means you cannot change it or publish it in a modified form.


Time flies like an arrow, but fruit flies like a banana.
User avatar
axe70
Registered User
Posts: 751
Joined: Sun Nov 17, 2002 10:55 am
Location: Italy
Name: Alessio

Re: [3.2][3.3][RC] Display Only First Post

Post by axe70 »

Thank for all your info. ok i understand, may since the code is very simple, can be modified with easy on each case.
It will be done, included the form to put custom content.

Beside the language phrases, that i've be warned to change, and that i will go to change now, or variables names,
what i worry is that to rewrite the value of post text or to set as hidden the related record into the event array, it require to clone the passed event param, then re-assign to it the new one cloned and modified.

Anybody want to help on understand why, the event array values cannot be overwritten within a foreach inside the event function?

https://github.com/axew3/phpbb-display- ... er.php#L87

how could be switched this simple code so to not have to do $tempRW = $e['rowset']; , but doing a foreach directly into the $e['rowset'] without cloning it? I know that this question make you all laugh, anyway i only have to hide posts here in the right way, so i will do the question without shame :D

Code: Select all

$vx = $e['topic_data']['topic_first_post_id'];
$tempRW = $e['rowset'];

      // Replacement mode:
      // $this->config['w3all_displayonlyfirstpost_rep_mode'] == 1 (Hide the entire post content)
      // $this->config['w3all_displayonlyfirstpost_rep_mode'] == 0 (Replace the post text with custom content)

        foreach($tempRW as $r => &$v){ // set as hidden (or replace the post content) all posts except the first
         if($r != $vx){
          if( $this->config['w3all_displayonlyfirstpost_rep_mode'] > 0 )
          {
           $v['hide_post'] = 1;
          } else {
            $v['post_text'] = $this->language->lang('DISPLAYONLYFIRSTPOST_EVENT_REPLACEMENT_TEXT');
           }
         }
        }

        $e['rowset'] = $tempRW;
        unset($v,$tempRW);
Thank you!

ps
to be more clear, doing this:

Code: Select all

 foreach($e['rowset'] as $k => &$v){ // set as hidden (or replace the post content) all posts except the first
          print_r($e['rowset'][$k]['post_text']);
        $e['rowset'][$k]['post_text'] = 'test';//$this->language->lang('DISPLAYONLYFIRSTPOST_EVENT_REPLACEMENT_TEXT');
          print_r($e['rowset'][$k]['post_text']);exit;
        }
change nothing into $e['rowset'], the second print_r($e['rowset'][$k]['post_text']) still show the old value and not the word test
Do not take me too serious
Anyway i do not like Discourse
User avatar
axe70
Registered User
Posts: 751
Joined: Sun Nov 17, 2002 10:55 am
Location: Italy
Name: Alessio

Re: [3.2][3.3][RC] Display Only First Post

Post by axe70 »

Here we go. 1.0.2 has been released:
https://github.com/axew3/phpbb-display-only-first-post

Finally, the best has been to follow with suggestions, and the code has been switched to get this result:

Get only, and display ever, only the first post.
Append into it a custom content or phrase (or not).
It has been possible with easy after looking into vars that are available, and an easy redirect trick when the page is not containing the first post topic id.
I think it bring a clean result without changing nothing into template files, for example.
The code resolve all suggested problems, also the Indirect modification of overloaded element i suppose.

Changed files:
phpbb-display-only-first-post/w3all/displayonlyfirstpost/language/en/common.php
phpbb-display-only-first-post/w3all/displayonlyfirstpost/adm/style/acp_displayonlyfirstpost_body.html
phpbb-display-only-first-post/w3all/displayonlyfirstpost/event/main_listener.php

check the new listener code
https://github.com/axew3/phpbb-display- ... post/event

The code has been also shortened and all should look fine now! WoW! Hope you'll like, enjoy lovely people :o
hiddenPostsAdminConfig00.png
onlyFirstPostResult.png
You do not have the required permissions to view the files attached to this post.
Do not take me too serious
Anyway i do not like Discourse
User avatar
axe70
Registered User
Posts: 751
Joined: Sun Nov 17, 2002 10:55 am
Location: Italy
Name: Alessio

Re: [3.2][3.3][RC] Display Only First Post

Post by axe70 »

Version 1.0.3 on github has been released.
https://github.com/axew3/phpbb-display-only-first-post

Add custom content as option into ACP, that will prepend the first post text. It can be any html code. If empty, the default phrase will show.
Fix phrases.
Reduce the code to the minimum.

Install Notes: to install this new version, just deactivate the old extension and delete data.
Remove the old /ext/w3all/displayonlyfirstpost and substitute with the new one..
Activate and configure the new extension.

P.s
What will be may done more?
Do not know, may you can suggest.

What may surely will be done?
Unify all the four config values into one single record, so to store all ext data into a single (serialized) config value.
Switch from in_array() to isset() 3/4 lines of code.

P.s as it is now, the extension has been submitted for validation.
In the hope that will be validated simply (and fast) as it is, anyway you'll find it anytime also on github
Enjoy!

https://github.com/axew3/phpbb-display-only-first-post

hiddenPostsAdminConfig0000.png
onlyFirstPostResult.png
You do not have the required permissions to view the files attached to this post.
Do not take me too serious
Anyway i do not like Discourse
User avatar
axe70
Registered User
Posts: 751
Joined: Sun Nov 17, 2002 10:55 am
Location: Italy
Name: Alessio

Re: [3.2][3.3][RC] Display Only First Post

Post by axe70 »

Hello cool people.
For what it worth to mention, the regexp on this line, on file /controller/acp_controller.php:

https://github.com/axew3/phpbb-display- ... er.php#L88

Code: Select all

if ( preg_match('/[^,0-9a{1}l{2}]/i',$this->request->variable('w3all_displayonlyfirstpost_forums_ids', '')) ){
that try to check for a string that should only contain the word
all or
commas or
numbers

is obviously wrong.

The correct pattern is this instead:

Code: Select all

       if ( preg_match('/[^\ball\b|,|0-9]+/',$this->request->variable('w3all_displayonlyfirstpost_forums_ids', '')) ){    
so that after, since /event/main_listener.php use
in_array() that is case-sensitive, all will work ever as expected without to worry about anything else, or the need to add more code for more checks. The unique allowed word is all lowercase

so it will be updated on the github repo (at moment) only.

[EDITED]
Do not take me too serious
Anyway i do not like Discourse

Return to “Extensions in Development”