phpBB extension code confuse me

Discussion forum for Extension Writers regarding Extension Development.
Post Reply
YoOoster
Registered User
Posts: 6
Joined: Mon Aug 06, 2018 5:51 pm

phpBB extension code confuse me

Post by YoOoster » Sun Apr 28, 2019 1:23 am

As someone who programmed in Java, C#, C++, C and even dabbled in Assembly you would think that this wouldn't be too hard to understand...
So maybe someone here can help me understand how to make an extension.

I've already typed out some stuff while trying to figure it out, but this is pretty much what I want below each topic (the topic_id is just an example):

Code: Select all

$sql = "SELECT attach_id FROM phpbb_attachments WHERE topic_id = 1762 ORDER BY attach_id DESC LIMIT 5";
$result = $conn->query($sql);

if ($result->num_rows > 0) {
	echo "<br>";
	echo "<div style=\"height:100px;display:inline-block;\">";
	// output data of each row
	while($row = $result->fetch_assoc()) {
		echo "<img src=\"/forum/download/file.php?id=" . $row["attach_id"]. "&t=1\" style=\"display:inline-block;width:100px;height:100px;\"/>";
	}
echo "</div>";
}
$conn->close();
I know that I would need to make an topiclist_row_append.html and probably do something like

Code: Select all

for each image
show the image
and I'll probably need to get the images via the controller, but I have no idea how to do it and how you would "bind" those two things together.

I've already looked at the acme demo, hello world extensions and tried with the skeleton extension. Even looked at extensions that use topiclist_row_append.html but I'm at a loss.

rxu
Extensions Development Team
Posts: 2970
Joined: Wed Oct 25, 2006 12:46 pm
Location: Siberia, Russian Federation
Name: Ruslan
Contact:

Re: phpBB extension code confuse me

Post by rxu » Sun Apr 28, 2019 4:47 am

Did you try extension development tutorials? https://area51.phpbb.com/docs/dev/3.2.x/extensions/

User avatar
david63
Registered User
Posts: 16535
Joined: Thu Dec 19, 2002 8:08 am
Location: Lancashire, UK
Name: David Wood
Contact:

Re: phpBB extension code confuse me

Post by david63 » Sun Apr 28, 2019 6:46 am

or the Extension Skeleton extension?
David
Remember: You only know what you know and - you don't know what you don't know!
My CDB Contributions | How to install an extension
I will not be accepting translations for any of my extensions in Github - please post any translations in the appropriate topic.
No support requests via PM or email as they will be ignored

User avatar
battye
Extension Customisations
Extension Customisations
Posts: 10940
Joined: Wed Feb 11, 2004 11:02 am
Location: Australia
Contact:

Re: phpBB extension code confuse me

Post by battye » Sun Apr 28, 2019 9:55 am

You will need to access the event variable which contains the templating vars that you want to modify (or add to). That's what "binds" the main logic to the view.

For example, see what I did at https://github.com/battye/show-subforum ... ORUM_IMAGE

I wanted to add that new templating var "U_SUBFORUM_IMAGE", but I had to access the event and then add my own var, then save it back to the original event var before I could use it in the HTML.
Customisations Team Member

https://github.com/battye/php-array-parser - Give it a Star! :D

YoOoster
Registered User
Posts: 6
Joined: Mon Aug 06, 2018 5:51 pm

Re: phpBB extension code confuse me

Post by YoOoster » Sun Apr 28, 2019 4:40 pm

battye wrote:
Sun Apr 28, 2019 9:55 am
You will need to access the event variable which contains the templating vars that you want to modify (or add to). That's what "binds" the main logic to the view.

For example, see what I did at https://github.com/battye/show-subforum ... ORUM_IMAGE

I wanted to add that new templating var "U_SUBFORUM_IMAGE", but I had to access the event and then add my own var, then save it back to the original event var before I could use it in the HTML.
Thank you, this explanation and with your code it actually makes a lot of more sense.

One question about your code. You do this to get the subforum ids

Code: Select all

$query_string = parse_url($subforum['U_SUBFORUM'], PHP_URL_QUERY);
parse_str($query_string, $output);
$forum_id = (int) $output['f'];
Aren't you able to get the subforum 'object' and then just use FORUM_ID? Or is this out of the scope of the display_forums_modify_template_vars event?

Also what's the best way to determine the most logical event to use, because I assume you could add the same things via multiple events if you wanted too.

User avatar
david63
Registered User
Posts: 16535
Joined: Thu Dec 19, 2002 8:08 am
Location: Lancashire, UK
Name: David Wood
Contact:

Re: phpBB extension code confuse me

Post by david63 » Sun Apr 28, 2019 5:44 pm

YoOoster wrote:
Sun Apr 28, 2019 4:40 pm
Also what's the best way to determine the most logical event to use, because I assume you could add the same things via multiple events if you wanted too.
Trial and error first followed by experience
David
Remember: You only know what you know and - you don't know what you don't know!
My CDB Contributions | How to install an extension
I will not be accepting translations for any of my extensions in Github - please post any translations in the appropriate topic.
No support requests via PM or email as they will be ignored

Post Reply

Return to “Extension Writers Discussion”