[Problem] Problem about <xsl>

Discussion forum for Extension Writers regarding Extension Development.
Post Reply
User avatar
Dakin Quelia
Registered User
Posts: 291
Joined: Thu Feb 14, 2008 10:07 pm
Location: Belgium
Name: Daniel Chalsèche
Contact:

[Problem] Problem about <xsl>

Post by Dakin Quelia » Sat Sep 02, 2017 1:39 am

Hello everybody,

I've a little problem with my code below :

Code: Select all

        // Let's create the new BBCode
        $configurator->BBCodes->addCustom(
            '[groupmsg gid={NUMBER}]{TEXT}[/groupmsg]',
            '<xsl:choose>
				<xsl:when test="$S_USER_LOGGED_IN and $S_GROUP_@gid">
					{TEXT}
                </xsl:when>
				<xsl:otherwise>
					<span style="color: #FF0000; font-weight: bold;"><xsl:value-of select="$L_GROUPBBCODE_ACCESS"/></span>
				</xsl:otherwise>
            </xsl:choose>'
        );
This part doesn't work :

Code: Select all

				<xsl:when test="$S_USER_LOGGED_IN and $S_GROUP_@gid">
I don't know how to get "group_id" via my BBCode. :?

Best regards

User avatar
JoshyPHP
Code Contributor
Posts: 684
Joined: Mon Jul 11, 2011 12:28 am

Re: [Problem] Problem about <xsl>

Post by JoshyPHP » Sat Sep 02, 2017 3:15 pm

If you're trying to test against a variable named $S_GROUP_7 that won't work because there's no dynamic evaluation.

There's some info about how to set template parameters there: https://area51.phpbb.com/docs/dev/32x/e ... parameters

I would try creating template parameter that contains a comma-separated list of group IDs, then I'd look up the dynamic group ID using a string function. To avoid false-positives, each group ID should be surrounded by commas.

Code: Select all

$configurator->BBCodes->addCustom(
	'[groupmsg gid={NUMBER}]{TEXT}[/groupmsg]',
	'<xsl:choose>
		<xsl:when test="contains($USER_GROUPS, concat(\',\', @gid, \',\'))">
			{TEXT}
		</xsl:when>
		<xsl:otherwise>
			<span style="color: #FF0000; font-weight: bold;">{L_GROUPBBCODE_ACCESS}</span>
		</xsl:otherwise>
	</xsl:choose>'
);
Use core.text_formatter_s9e_renderer_setup to set the template parameter, e.g.:

Code: Select all

$event['renderer']->get_renderer()->setParameter('USER_GROUPS', ',1,2,3,');
I wrote the thing that does the BBCodes in 3.2. Unless it broke yours, in which case it was somebody else with a similar name.

User avatar
Dakin Quelia
Registered User
Posts: 291
Joined: Thu Feb 14, 2008 10:07 pm
Location: Belgium
Name: Daniel Chalsèche
Contact:

Re: [Problem] Problem about <xsl>

Post by Dakin Quelia » Sat Sep 02, 2017 5:05 pm

I've tested but I've an error :

Code: Select all

Fatal error: Call to a member function get_renderer() on a non-object in C:\wamp\www\quickinstall\boards\odlf\ext\odlf\odlfbbcodes\event\listener.php on line 84
Call Stack

User avatar
JoshyPHP
Code Contributor
Posts: 684
Joined: Mon Jul 11, 2011 12:28 am

Re: [Problem] Problem about <xsl>

Post by JoshyPHP » Sat Sep 02, 2017 5:07 pm

Hard to know what's wrong without the actual code.
I wrote the thing that does the BBCodes in 3.2. Unless it broke yours, in which case it was somebody else with a similar name.

User avatar
Dakin Quelia
Registered User
Posts: 291
Joined: Thu Feb 14, 2008 10:07 pm
Location: Belgium
Name: Daniel Chalsèche
Contact:

Re: [Problem] Problem about <xsl>

Post by Dakin Quelia » Sat Sep 02, 2017 5:11 pm

Here is my code

Code: Select all

<?php
/**
*
* @package odlfbbcodes
* @copyright (c) 2017 Dakin Quelia (http://www.danielchalseche.fr.cr/)
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/

namespace odlf\odlfbbcodes\event;

/**
* Event listener
*/
use Symfony\Component\EventDispatcher\EventSubscriberInterface;

class listener implements EventSubscriberInterface
{
	/* @var db */
	protected $db;

	/* @var template */
	protected $template;

	/* @var user */
	protected $user;
	
	/**
	 * @param db $db
	 * @param template $template
	 * @param user $user
	*/
	public function __construct(\phpbb\db\driver\driver_interface $db, \phpbb\template\template $template, \phpbb\user $user)
	{
		$this->db = $db;
		$this->template = $template;
		$this->user = $user;
	}
	
    public static function getSubscribedEvents()
    {
        return array(
			'core.user_setup'								=> 'load_language_on_setup',
			'core.text_formatter_s9e_renderer_setup'		=> 'core_groupbbcode',
			'core.text_formatter_s9e_configure_before'      => 'core_groupbbcode',
            'core.text_formatter_s9e_configure_after'       => 'configure_groupbbcode',
        );
    }
	
	public function load_language_on_setup($event)
	{
		$lang_set_ext = $event['lang_set_ext'];
		$lang_set_ext[] = array(
			'ext_name' => 'odlf/odlfbbcodes',
			'lang_set' => 'groupbbcode',
		);
		$event['lang_set_ext'] = $lang_set_ext;
	}
	
	public function core_groupbbcode($event)
	{
		$template_vars = array();
		$user_id = $this->user->data['user_id'];

		$sql = 'SELECT group_id 
				FROM ' . USER_GROUP_TABLE . '
				WHERE user_id = ' . $user_id . '
					AND user_pending = 0';

		$result = $this->db->sql_query($sql);

		while ($group_id = $this->db->sql_fetchfield('group_id'))
		{
			$template_vars['S_GROUP_' . $group_id] = true;
		}

		$this->db->sql_freeresult($result);

		if (sizeof($template_vars))
		{
			//$this->template->assign_vars($template_vars);
			$event['renderer']->get_renderer()->setParameter($template_vars);
		}
	}
	
	/*public function core_groupbbcode($event)
	{
		$user_id = $this->user->data['user_id'];

		$sql = 'SELECT group_id 
				FROM ' . USER_GROUP_TABLE . '
				WHERE user_id = ' . $user_id . '
					AND user_pending = 0';

		$result = $this->db->sql_query($sql);

		$group_id = $this->db->sql_fetchfield('group_id')
		$this->db->sql_freeresult($result);
		$event['renderer']->get_renderer()->setParameter('S_GROUP_' . $group_id, true);
	}
	
	public function render_groupbbcode($event)
	{
		$event['renderer']->get_renderer()->setParameter('S_GROUP_' . $group_id, true);
	}*/

    public function configure_groupbbcode($event)
    {
        // Get the BBCode configurator
        $configurator = $event['configurator'];

        // Let's unset any existing BBCode that might already exist
        unset($configurator->BBCodes['groupmsg']);
        unset($configurator->tags['groupmsg']);

        // Let's create the new BBCode
        $configurator->BBCodes->addCustom(
            '[groupmsg gid={NUMBER}]{TEXT}[/groupmsg]',
            '<xsl:choose>
				<xsl:when test="contains(concat($S_GROUP_, @gid))">
					{TEXT}
                </xsl:when>
				<xsl:otherwise>
					<span style="color: #FF0000; font-weight: bold;"><xsl:value-of select="$L_GROUPBBCODE_ACCESS"/></span>
				</xsl:otherwise>
            </xsl:choose>'
        );
    }
}

?>

User avatar
JoshyPHP
Code Contributor
Posts: 684
Joined: Mon Jul 11, 2011 12:28 am

Re: [Problem] Problem about <xsl>

Post by JoshyPHP » Sat Sep 02, 2017 5:19 pm

I don't know, that seems to match what's in the docs. Inspect $event['renderer'] see what kind of object this is. You're going to have to do the normal debugging thing.

You should declare static methods as static too.
I wrote the thing that does the BBCodes in 3.2. Unless it broke yours, in which case it was somebody else with a similar name.

User avatar
JoshyPHP
Code Contributor
Posts: 684
Joined: Mon Jul 11, 2011 12:28 am

Re: [Problem] Problem about <xsl>

Post by JoshyPHP » Sat Sep 02, 2017 6:08 pm

Tried locally, I don't have this error. The only error I get is that you use setParameter with an array. The correct use is either setParameter($name, $value) or setParameters($array).
I wrote the thing that does the BBCodes in 3.2. Unless it broke yours, in which case it was somebody else with a similar name.

User avatar
Steve
Registered User
Posts: 992
Joined: Tue Apr 07, 2009 7:48 pm
Location: UK ,up north!!
Name: Steven Clark
Contact:

Re: [Problem] Problem about <xsl>

Post by Steve » Sat Sep 02, 2017 9:56 pm

call the class as new, and then you can object chain.

Post Reply

Return to “Extension Writers Discussion”

Who is online

Users browsing this forum: TWEagle and 13 guests

cron