Issue showing attachments / $this->renderer->render($txt)

Discussion forum for Extension Writers regarding Extension Development.
Post Reply
User avatar
3Di
I've Been Banned!
Posts: 17538
Joined: Mon Apr 04, 2005 11:09 pm
Location: I'm with Ukraine 🇺🇦
Name: Marco
Contact:

Issue showing attachments / $this->renderer->render($txt)

Post by 3Di »

Hi all,
a tricky situation, for an extension (not yet publicly available) I am using the s9e facilities, in order to keep the code up to date with the latest trend, so far so good, everything's working like a charm, just this issue I wasn't able to solve after a session of many hours, tonight.

Let's see what I am talking about..

- controller/mode='view'
(that's the mode which will take you to a separate page where there is 'who marked this post as read' and the search facilities for that list (like memberlist), plus, above all, there is view of the post related. Alike viewtopic.. so to say.

- here I am using the renderer to show the post's view iver there, with..
'POST_TEXT' => $this->renderer->render($post['post_text']),

post_text it's taken directly from the DB with a query and there it's stored this way.. (logically)

Code: Select all

<r>Test post 152  <E>:P</E> <br/>

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

<E>:geek:</E> <br/>

<ATTACHMENT filename="Lighthouse.jpg" index="0"><s>[attachment=0]</s>Lighthouse.jpg<e>[/attachment]</e></ATTACHMENT></r>
- well, I used all of the methods I know and explored a ton of code, tried to no avail a lot of strategies but..

Attachments aren't parsed :geek: That's the issue.
.
Image

Whilst BBcodes, smilies, etc.. everything goes.

Definitly I need some help here, that's new stuff. The controller has already all of this ready and in use

Code: Select all

	{
		$this->auth				= $auth;
		$this->config				= $config;
		$this->db					= $db;
		$this->group_helper			= $group_helper;
		$this->helper				= $helper;
		$this->lang				= $lang;
		$this->log					= $log;
		$this->notification_manager	= $notification_manager;
		$this->pagination			= $pagination;
		$this->parser				= $parser;
		$this->renderer				= $renderer;
		$this->request				= $request;
		$this->template				= $template;
		$this->user				= $user;
		$this->utils				= $utils;
		$this->hlposts_utils			= $hlposts_utils;

		$this->root_path			= $root_path;
		$this->php_ext				= $php_ext;

		$this->post_read_table		= $post_read_table;
		$this->highlights_table		= $highlights_table;
	}
I would like to avoid to get rid momentanely of the post's view (I like it), and face the issue from the right point.
Thank you IA.
🆓 Free support for our extensions also provided here: phpBB Studio
🚀 Looking for a specific feature or alternative option? We will rock you!
Please PM me only to request paid works. Thx. Buy me a coffee -> Image
My development's activity º PhpStorm's proud user º Extensions, Scripts, MOD porting, Update/Upgrades
rxu
Extensions Development Team
Posts: 3711
Joined: Wed Oct 25, 2006 12:46 pm
Location: Siberia, Russian Federation
Contact:

Re: Issue showing attachments / $this->renderer->render($txt)

Post by rxu »

I guess that is because attachment rendering requires a separate style template file - attachment.html to be involved.
User avatar
3Di
I've Been Banned!
Posts: 17538
Joined: Mon Apr 04, 2005 11:09 pm
Location: I'm with Ukraine 🇺🇦
Name: Marco
Contact:

Re: Issue showing attachments / $this->renderer->render($txt)

Post by 3Di »

rxu wrote: Sat Feb 03, 2018 9:06 am I guess that is because attachment rendering requires a separate style template file - attachment.html to be involved.
Hi rxu, thx for chiming in, and no..
the above template file is devoted for when the user have to upload files /attachments AFAIK, I need to show the already posted attachments instead.
And for just for one post_id at time.

But thanks to your reply I guess I got the point here, the solution should be to mimic viewtopic.php/vietopic_body.html

HTML: I just have...

Code: Select all

<div class="content">{{ POST_TEXT }}</div>
I should add (that's the original which I have to adapt to fit into my code)

Code: Select all

			<!-- IF postrow.S_HAS_ATTACHMENTS -->
				<dl class="attachbox">
					<dt>
						{L_ATTACHMENTS}
					</dt>
					<!-- BEGIN attachment -->
						<dd>{postrow.attachment.DISPLAY_ATTACHMENT}</dd>
					<!-- END attachment -->
				</dl>
			<!-- ENDIF -->
The PHP side is pretty done (the query to the attachments table, to be joined to the present query), that's part of my nightly session.

I will try and apply this concept later on and report. :) (finger crossed)
🆓 Free support for our extensions also provided here: phpBB Studio
🚀 Looking for a specific feature or alternative option? We will rock you!
Please PM me only to request paid works. Thx. Buy me a coffee -> Image
My development's activity º PhpStorm's proud user º Extensions, Scripts, MOD porting, Update/Upgrades
User avatar
canonknipser
Registered User
Posts: 2096
Joined: Thu Sep 08, 2011 4:16 am
Location: Germany
Name: Frank Jakobs
Contact:

Re: Issue showing attachments / $this->renderer->render($txt)

Post by canonknipser »

You also need a separate php file, which is download/file.php to render the file into a image
Greetings, Frank
phpbb.de support team member
English is not my native language - no support via PM or mail
New arrival - Extensions and scripts for phpBB
rxu
Extensions Development Team
Posts: 3711
Joined: Wed Oct 25, 2006 12:46 pm
Location: Siberia, Russian Federation
Contact:

Re: Issue showing attachments / $this->renderer->render($txt)

Post by rxu »

3Di wrote: Sat Feb 03, 2018 10:39 am the above template file is devoted for when the user have to upload files /attachments AFAIK
It's used to output parsed attachments markup in viewtopic ;) See https://github.com/phpbb/phpbb/blob/mas ... .php#L1096
User avatar
3Di
I've Been Banned!
Posts: 17538
Joined: Mon Apr 04, 2005 11:09 pm
Location: I'm with Ukraine 🇺🇦
Name: Marco
Contact:

Re: Issue showing attachments / $this->renderer->render($txt)

Post by 3Di »

rxu wrote: Sat Feb 03, 2018 11:08 am
3Di wrote: Sat Feb 03, 2018 10:39 am the above template file is devoted for when the user have to upload files /attachments AFAIK
It's used to output parsed attachments markup in viewtopic ;) See https://github.com/phpbb/phpbb/blob/mas ... .php#L1096
Ah yes, the old and lovely function parse_attachments() :)
canonknipser wrote: Sat Feb 03, 2018 10:51 am You also need a separate php file, which is download/file.php to render the file into a image
Oh well, thx, I did read it now.

Guys, do you need more info/code to read in order to give me the short road to reach my goal?
I feel a bit confused now, lol.

It will be so easy to get rid of the post's view over there, but why?
🆓 Free support for our extensions also provided here: phpBB Studio
🚀 Looking for a specific feature or alternative option? We will rock you!
Please PM me only to request paid works. Thx. Buy me a coffee -> Image
My development's activity º PhpStorm's proud user º Extensions, Scripts, MOD porting, Update/Upgrades
rxu
Extensions Development Team
Posts: 3711
Joined: Wed Oct 25, 2006 12:46 pm
Location: Siberia, Russian Federation
Contact:

Re: Issue showing attachments / $this->renderer->render($txt)

Post by rxu »

3Di wrote: Sat Feb 03, 2018 11:22 am give me the short road to reach my goal
I think that after rendering the post text, you need to parse it for attachments just like viewtopic.php does https://github.com/phpbb/phpbb/blob/mas ... .php#L1662
User avatar
3Di
I've Been Banned!
Posts: 17538
Joined: Mon Apr 04, 2005 11:09 pm
Location: I'm with Ukraine 🇺🇦
Name: Marco
Contact:

Re: Issue showing attachments / $this->renderer->render($txt)

Post by 3Di »

rxu wrote: Sat Feb 03, 2018 11:28 am
3Di wrote: Sat Feb 03, 2018 11:22 am give me the short road to reach my goal
I think that after rendering the post text, you need to parse it for attachments just like viewtopic.php does https://github.com/phpbb/phpbb/blob/mas ... .php#L1662
Exactly, we are talking about an unique post_id, as I said... that's it. :) Thx.

Look, I have found a necro-script from the old days here while searching, which is basically the same stuff... (very ugly) :geek:

Code: Select all

//Now we need some posts, replace the foreach line with whatever your like

foreach($db->fetch("SELECT * FROM phpbb3_posts WHERE blah blah blah") as $post)
{
	//parse BBCode
	$post['bbcode_options'] = (($post['enable_bbcode']) ? OPTION_FLAG_BBCODE : 0) + (($post['enable_smilies']) ? OPTION_FLAG_SMILIES : 0) + (($post['enable_magic_url']) ? OPTION_FLAG_LINKS : 0);

	$text = generate_text_for_display($post['post_text'], $post['bbcode_uid'], $post['bbcode_bitfield'], $post['bbcode_options']);

	//ok, now for the attachment
	if($post['post_attachment']) //if we have attachments on this post
	{
		//get the infomation from the attachment table
		$attachmentinfo = $db->fetch("SELECT * FROM phpbb3_attachments WHERE post_msg_id = {$post['post_id']}");
		//parse attachment info
		$updatecount = Array();
		parse_attachments($post['forum_id'], $text, $attachmentinfo, $updatecount);
	}

	// $text now contains our post with parsed BBCode and attachements ready to output
	echo $text
}//end post foreach
:)
🆓 Free support for our extensions also provided here: phpBB Studio
🚀 Looking for a specific feature or alternative option? We will rock you!
Please PM me only to request paid works. Thx. Buy me a coffee -> Image
My development's activity º PhpStorm's proud user º Extensions, Scripts, MOD porting, Update/Upgrades
rxu
Extensions Development Team
Posts: 3711
Joined: Wed Oct 25, 2006 12:46 pm
Location: Siberia, Russian Federation
Contact:

Re: Issue showing attachments / $this->renderer->render($txt)

Post by rxu »

Assuming (just for example) that post id is 6, it would be something like that

Code: Select all

$sql = 'SELECT * FROM ' . POSTS_TABLE . '
	WHERE post_id = ' . 6;
$result = $db->sql_query($sql);
$post = $db->sql_fetchrow($result);
$db->sql_freeresult($result);

$update_count = array();
$renderer = $phpbb_container->get('text_formatter.renderer');
$text = $renderer->render($post['post_text']);

if ($post['post_attachment'])
{
	$sql = 'SELECT *
		FROM ' . ATTACHMENTS_TABLE . '
		WHERE ' . $db->sql_in_set('post_msg_id', $post['post_id']) . '
			AND in_message = 0
		ORDER BY attach_id DESC, post_msg_id ASC';
	$result = $db->sql_query($sql);
	$attachments_data[$post['post_id']] = $db->sql_fetchrow($result);
	$db->sql_freeresult($result);

	parse_attachments($post['forum_id'], $text, $attachments_data, $update_count);
}
User avatar
3Di
I've Been Banned!
Posts: 17538
Joined: Mon Apr 04, 2005 11:09 pm
Location: I'm with Ukraine 🇺🇦
Name: Marco
Contact:

Re: Issue showing attachments / $this->renderer->render($txt)

Post by 3Di »

Nothing's more clear than this, to me. I do appreciated. :)
🆓 Free support for our extensions also provided here: phpBB Studio
🚀 Looking for a specific feature or alternative option? We will rock you!
Please PM me only to request paid works. Thx. Buy me a coffee -> Image
My development's activity º PhpStorm's proud user º Extensions, Scripts, MOD porting, Update/Upgrades
User avatar
3Di
I've Been Banned!
Posts: 17538
Joined: Mon Apr 04, 2005 11:09 pm
Location: I'm with Ukraine 🇺🇦
Name: Marco
Contact:

Re: Issue showing attachments / $this->renderer->render($txt)

Post by 3Di »

rxu wrote: Sat Feb 03, 2018 11:56 am Assuming (just for example) that post id is 6, it would be something like that
... snip ..
So, simply I used (the rest was already there)

Code: Select all

$update_count = array();
$text = $this->renderer->render($post['post_text']);

if ($post['post_attachment'])
{
	$sql = 'SELECT *
		FROM ' . ATTACHMENTS_TABLE . '
		WHERE ' . $this->db->sql_in_set('post_msg_id', (int) $post['post_id'], true, true) . '
			AND in_message = 0
		ORDER BY attach_id DESC, post_msg_id ASC';
	$result = $this->db->sql_query($sql);
	$attachments_data[$post['post_id']] = $this->db->sql_fetchrow($result);
	$this->db->sql_freeresult($result);

	parse_attachments((int) $post['forum_id'], $text, $attachments_data, $update_count);
}
and

Code: Select all

'POST_TEXT'			=> $text,
and here we go..
Image

You saved my day rxu. Great. :)
🆓 Free support for our extensions also provided here: phpBB Studio
🚀 Looking for a specific feature or alternative option? We will rock you!
Please PM me only to request paid works. Thx. Buy me a coffee -> Image
My development's activity º PhpStorm's proud user º Extensions, Scripts, MOD porting, Update/Upgrades
User avatar
3Di
I've Been Banned!
Posts: 17538
Joined: Mon Apr 04, 2005 11:09 pm
Location: I'm with Ukraine 🇺🇦
Name: Marco
Contact:

Re: Issue showing attachments / $this->renderer->render($txt)

Post by 3Di »

Well, that works with 1 attachment as I can see.

Adding a second one throws a debug error
functions_content.php on line 1360: Undefined index: MISSING_INLINE_ATTACHMENT
and it shows just the last attachment.

So, multiple attachments needs a tuning.. I am at this point in time at 90% done then.
🆓 Free support for our extensions also provided here: phpBB Studio
🚀 Looking for a specific feature or alternative option? We will rock you!
Please PM me only to request paid works. Thx. Buy me a coffee -> Image
My development's activity º PhpStorm's proud user º Extensions, Scripts, MOD porting, Update/Upgrades
User avatar
3Di
I've Been Banned!
Posts: 17538
Joined: Mon Apr 04, 2005 11:09 pm
Location: I'm with Ukraine 🇺🇦
Name: Marco
Contact:

Re: Issue showing attachments / $this->renderer->render($txt)

Post by 3Di »

Oky, solved.

Code: Select all

		/* First let's render the text */
		$text = $this->renderer->render($post['post_text']);

		/**
		 * Attachments - Include files needed for display attachments
		 */
		if (!function_exists('parse_attachments'))
		{
			include $this->root_path . 'includes/functions_content.' . $this->php_ext;
		}

		if ($post['post_attachment'])
		{
			$sql = 'SELECT *
				FROM ' . ATTACHMENTS_TABLE . '
				WHERE post_msg_id = ' . (int) $post_id . '
					AND in_message = 0
				ORDER BY attach_id DESC';
			$result = $this->db->sql_query($sql);
			
			while ($row = $this->db->sql_fetchrow($result))
			{
				$attachments[] = $row;
			}
			$this->db->sql_freeresult($result);

			if (count($attachments))
			{
				$update_count = array();

				/* Only parses attachments placed inline? */
				parse_attachments((int) $post['forum_id'], $text, $attachments, $update_count);
			}
		}

Hopefully. :ugeek: :)

Edit: posted final code, tested.
🆓 Free support for our extensions also provided here: phpBB Studio
🚀 Looking for a specific feature or alternative option? We will rock you!
Please PM me only to request paid works. Thx. Buy me a coffee -> Image
My development's activity º PhpStorm's proud user º Extensions, Scripts, MOD porting, Update/Upgrades
User avatar
3Di
I've Been Banned!
Posts: 17538
Joined: Mon Apr 04, 2005 11:09 pm
Location: I'm with Ukraine 🇺🇦
Name: Marco
Contact:

Re: Issue showing attachments / $this->renderer->render($txt)

Post by 3Di »

I amended the above post of mine with the last and final code, for this use case.

One question,
seems like the parse_attachments() function only parses attachs which have been "placed inline", am I missing something?

Thx
🆓 Free support for our extensions also provided here: phpBB Studio
🚀 Looking for a specific feature or alternative option? We will rock you!
Please PM me only to request paid works. Thx. Buy me a coffee -> Image
My development's activity º PhpStorm's proud user º Extensions, Scripts, MOD porting, Update/Upgrades
Post Reply

Return to “Extension Writers Discussion”