Add Code to Posts That Contain Image

Discussion forum for MOD Writers regarding MOD Development.
Locked
GoremanX
Registered User
Posts: 27
Joined: Wed Apr 21, 2010 5:44 am

Add Code to Posts That Contain Image

Post by GoremanX »

What would be the best way to add custom code to a post which contains images, either from IMG bbcode tags or as attachments. My goal is to add a header with specific text to each post that has images in it (but ignoring images in signatures).
Drummer
Registered User
Posts: 199
Joined: Wed Jul 21, 2010 11:49 am

Re: Add Code to Posts That Contain Image

Post by Drummer »

I think the easiest solution is checking it while it's parsing.
Well, have a look at message_parser.php and find

Code: Select all

					if (preg_match($regexp, $this->message))
					{
						$this->message = preg_replace($regexp, $replacement, $this->message);
						$bitfield->set($bbcode_data['bbcode_id']);
					}
Before the preg_replace you can add a check like

Code: Select all

						if ($bbcodename == 'img')
						{
							//do something
						}
For the attachments... in the same file, add your "//do something" after

Code: Select all

				if ($filedata['post_attach'] && !sizeof($error))
				{
GoremanX
Registered User
Posts: 27
Joined: Wed Apr 21, 2010 5:44 am

Re: Add Code to Posts That Contain Image

Post by GoremanX »

oops, I should clarify: I want to add this code only upon viewing the topic, I don't want to add it to the post that gets stored. So I'm looking for a way to set a variable which I can then use in viewtopic.php (and subsequently in viewtopic_body.html).

The goal is this: I've added an option in users' profiles called "Critique Welcome", which is enabled by default. When a user disables this option, I want that user's posts which contain images to have a header that states "No Critique Please", so other members know that this user doesn't want his pictures critiqued. I want users to be able to turn this option on or off at will.

I've already got it working, except the header shows up for ALL of a user's posts. I'm trying to limit it to just posts which contain images so it's more relevant and less cluttered.
Drummer
Registered User
Posts: 199
Joined: Wed Jul 21, 2010 11:49 am

Re: Add Code to Posts That Contain Image

Post by Drummer »

Well, viewtopic.php already has a variable called $has_attachments. About the [img] you would need to "re-parse" it with preg_match, not that hard as viewtopic.php already queries all the post info (including enable_bbcode, bbcode_bitfield and bbcode_uid).
You're also still able to include something during the second bbcode pass (now look at includes/bbcode.php)
Locked

Return to “[3.0.x] MOD Writers Discussion”