Old Fetch Forum/Topic Title Mod with 3.2

Need some custom code changes to the phpBB core simple enough that you feel doesn't require an extension? Then post your request here so that community members can provide some assistance.

NOTE: NO OFFICIAL SUPPORT IS PROVIDED IN THIS SUB-FORUM
Forum rules
READ: phpBB.com Board-Wide Rules and Regulations

NOTE: NO OFFICIAL SUPPORT IS PROVIDED IN THIS SUB-FORUM
Post Reply
User avatar
thecoalman
Former Team Member
Posts: 2286
Joined: Wed Dec 22, 2004 3:52 am
Location: Pennsylvania, U.S.A.

Old Fetch Forum/Topic Title Mod with 3.2

Post by thecoalman » Sun Oct 15, 2017 4:27 am

I've integrated the old fetch forum title mod with 3.2.

viewtopic.php?f=70&t=1053375&p=6091645& ... e#p6091645

I have a custom function file that is loaded with common.php with the fetch_forumtitle function.

Around line 57 of /phpbbroot/phpbb/textformatter/s9e/link_helper.php I edited in the function.

Code: Select all

	public function generate_link_text_tag(\s9e\TextFormatter\Parser\Tag $tag, \s9e\TextFormatter\Parser $parser)
	{

		
		// Only create a LINK_TEXT tag if the start tag is paired with an end
		// tag, which is the case with tags from the Autolink plugins and with
		// the [url] BBCode when its content is used for the URL
		if (!$tag->getEndTag() || !$this->should_shorten($tag, $parser->getText()))
		{
			return true;
		}

		// Capture the text between the start tag and its end tag
		$start  = $tag->getPos() + $tag->getLen();
		$end    = $tag->getEndTag()->getPos();
		$length = $end - $start;
		$text   = substr($parser->getText(), $start, $length);
		//Start forum - topic title mod
		if (stripos($text, 'https://yourdomain.com/phpbbroot/view') === 0)
		{
			$text   = fetch_forumtitle($text);
			$text   = html_entity_decode ($text);
		}
		//End forum - topic title mod
		// Create a tag that consumes the link's text
		$parser->addSelfClosingTag('LINK_TEXT', $start, $length)->setAttribute('text', $text);

		return true;
	}
Seems to be working well.....

The issue I'm having is around line 106 which truncates the text.

Code: Select all

	/**
	* Truncate the replacement text set in a LINK_TEXT tag
	*
	* @param  \s9e\TextFormatter\Parser\Tag $tag LINK_TEXT tag
	* @return bool                               Always true to indicate that the tag is valid
	*/
	public function truncate_text(\s9e\TextFormatter\Parser\Tag $tag)
	{
		$text = $tag->getAttribute('text');
		if (utf8_strlen($text) > 50)
		{
			$text = utf8_substr($text, 0, 39) . ' ... ' . utf8_substr($text, -10);
		}

		$tag->setAttribute('text', $text);

		return true;
	}
I know I can change if (utf8_strlen($text) > 50) to whatever number I want but that affects every link.

The function is being called here /phpbbroot/phpbb/textformatter/s9e/factory.php

Code: Select all

	protected function configure_autolink(Configurator $configurator)
	{
		$configurator->plugins->load('Autoemail');
		$configurator->plugins->load('Autolink', array('matchWww' => true));

		// Add a tag filter that creates a tag that stores and replace the
		// content of a link created by the Autolink plugin
		$configurator->Autolink->getTag()->filterChain
			->add(array($this->link_helper, 'generate_link_text_tag'))
			->resetParameters()
			->addParameterByName('tag')
			->addParameterByName('parser');

		// Create a tag that will be used to display the truncated text by
		// replacing the original content with the content of the @text attribute
		$tag = $configurator->tags->add('LINK_TEXT');
		$tag->attributes->add('text');
		$tag->template = '<xsl:value-of select="@text"/>';

		$tag->filterChain
			->add(array($this->link_helper, 'truncate_local_url'))
			->resetParameters()
			->addParameterByName('tag')
			->addParameterByValue(generate_board_url() . '/');
		$tag->filterChain
			->add(array($this->link_helper, 'truncate_text'))
			->resetParameters()
			->addParameterByName('tag');
		$tag->filterChain
			->add(array($this->link_helper, 'cleanup_tag'))
			->resetParameters()
			->addParameterByName('tag')
			->addParameterByName('parser');
	}
Prseumably I need a parameter for viewforum and viewtopic links so they do not get truncated?

I guess I add some kind of random text at the start of the string when the text is changed to the titles to identify them and strip it out for the truncate function but thats a hack and half. LOL

Post Reply

Return to “phpBB Custom Coding”

Who is online

Users browsing this forum: No registered users and 4 guests

cron