links posted within my chat extension...

Discussion forum for Extension Writers regarding Extension Development.
Post Reply
User avatar
spaceace
Registered User
Posts: 1857
Joined: Wed Jan 30, 2008 8:50 pm
Contact:

links posted within my chat extension...

Post by spaceace » Thu Dec 03, 2015 11:53 pm

this is actually an extension question for phpBB 3.2 and i was not sure if it should be posted here or at area51 so it's at both :roll:

i just tried my chat extension on phpBB 3.2.0-a1 and everything seems to work fine except where forum posts get put into chat. they show up like this
when i view the source, it is showing the link in 2 sets of <a href> tags. and also outputting the link as this
instead of this
while my extension outputs everything as it should in phpBB 3.1.x, it won't in 3.2 and i don't know how to go about fixing it.

here's the part of the listener that does it... maybe it's all wrong and should be fixed. i just don't know as the person that was helping me with chat has stopped :roll:

Code: Select all

		$url			 = append_sid(generate_board_url() . '/viewtopic.' . $this->php_ext, 'f=' . $event['data']['forum_id'] . '&t=' . $event['data']['topic_id'] . '&p=' . $event['data']['post_id'] . '#p' . $event['data']['post_id']);
		$username		 = get_username_string('full', $this->user->data['user_id'], $this->user->data['username'], $this->user->data['user_colour']);
		$message		 = sprintf($lang, $url, $event['post_data']['post_subject']);
		$uid			 = $bitfield		 = $options		 = '';
		$allow_bbcode	 = $allow_urls		 = $allow_smilies	 = true;
		generate_text_for_storage($message, $uid, $bitfield, $options, $allow_bbcode, $allow_urls, $allow_smilies);
		$sql_ary = array(
			'chat_id'			 => 0,
			'user_id'			 => $this->user->data['user_id'],
			'username'			 => $this->user->data['username'],
			'user_colour'		 => $this->user->data['user_colour'],
			'message'			 => $message,
			'bbcode_bitfield'	 => $bitfield,
			'bbcode_uid'		 => $uid,
			'bbcode_options'	 => $options,
			'time'				 => time(),
			'forum_id'			 => $event['forum_id'],
			'post_id'			 => $event['data']['post_id'],
		);
		$sql	 = 'INSERT INTO ' . CHAT_TABLE . ' ' . $this->db->sql_build_array('INSERT', $sql_ary);
		$this->db->sql_query($sql);
also, in my language file

Code: Select all

'CHAT_NEW_TOPIC'				=> 'has started a new topic: <a href="%1$s">%2$s</a>',

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

Re: links posted within my chat extension...

Post by david63 » Fri Dec 04, 2015 8:46 am

If it is working fine in 3.1 but not in 3.2 then there are two possibilities.

1. There is a bug in 3.1 which is allowing it to work that has been fixed in 3.2

2. Something has been changed in 3.2 and it has created a bug.

I would post it in the bug tracker and see what the developers have to say about it.

EDIT: Just seen this on area51 - don't know if it is related
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
spaceace
Registered User
Posts: 1857
Joined: Wed Jan 30, 2008 8:50 pm
Contact:

Re: links posted within my chat extension...

Post by spaceace » Fri Dec 04, 2015 11:26 am

david63 wrote:If it is working fine in 3.1 but not in 3.2 then there are two possibilities.

1. There is a bug in 3.1 which is allowing it to work that has been fixed in 3.2

2. Something has been changed in 3.2 and it has created a bug.

I would post it in the bug tracker and see what the developers have to say about it.

EDIT: Just seen this on area51 - don't know if it is related
it seems that 3.2 generates urls differently than 3.1

i managed to get rid of the duplicate <a href> by removing it from my language file to have this now

Code: Select all

'CHAT_NEW_POST'					=> 'has replied to: %1$s %2$s',
but that creates a new problem.

i need to have the url displayed as the post subject and have no clue how to get that done... if it's even possible with how the chat is coded.

right now, link output looks like this
when i want it like this
has replied to: Re: 456

User avatar
mrgoldy
Jr. Extension Validator
Posts: 1051
Joined: Tue Oct 06, 2009 7:34 pm
Location: The Netherlands
Name: Gijs

Re: links posted within my chat extension...

Post by mrgoldy » Fri Dec 04, 2015 3:23 pm

Try using one of the following and see if that works:

Code: Select all

'CHAT_NEW_POST'               => 'has replied to: %1$s "%2$s"',
or

Code: Select all

'CHAT_NEW_POST'               => 'has replied to: (%1$s "%2$s")',
phpBB Studio / ''Proud member of the Studio"

User avatar
spaceace
Registered User
Posts: 1857
Joined: Wed Jan 30, 2008 8:50 pm
Contact:

Re: links posted within my chat extension...

Post by spaceace » Fri Dec 04, 2015 6:14 pm

posey wrote:Try using one of the following and see if that works:

Code: Select all

'CHAT_NEW_POST'               => 'has replied to: %1$s "%2$s"',
or

Code: Select all

'CHAT_NEW_POST'               => 'has replied to: (%1$s "%2$s")',
thanks but they are still not showing correctly. they display with either " " or ( ) around the topic/post name but do not change the link at all

User avatar
RMcGirr83
Recognised Extension Developer
Posts: 21034
Joined: Wed Jun 22, 2005 4:33 pm
Location: Your display
Name: Rich McGirr
Contact:

Re: links posted within my chat extension...

Post by RMcGirr83 » Fri Dec 04, 2015 7:04 pm

Code: Select all

$message       = $this->user->lang('CHAT_NEW_TOPIC', '[url=' . $url . ']' . $event['post_data']['post_subject'] . '[/url]');

Code: Select all

'CHAT_NEW_POST'               => 'has replied to: %s',
:?:
In times of change, learners inherit the earth, while the learned find themselves beautifully equipped to deal with a world that no longer exists - Eric Hoffer
Former Modifications/Extensions Team Member | My extensions
Appreciate the extensions/mods/support then buy me a beer
All requests for support via PM will be ignored

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

Re: links posted within my chat extension...

Post by david63 » Fri Dec 04, 2015 7:10 pm

Sorry to be pedantic - but do you not mean

Code: Select all

'CHAT_NEW_TOPIC' => 'has replied to: %s',
:o
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
RMcGirr83
Recognised Extension Developer
Posts: 21034
Joined: Wed Jun 22, 2005 4:33 pm
Location: Your display
Name: Rich McGirr
Contact:

Re: links posted within my chat extension...

Post by RMcGirr83 » Fri Dec 04, 2015 7:59 pm

:shrug: was just going off of what was posted before my post.
In times of change, learners inherit the earth, while the learned find themselves beautifully equipped to deal with a world that no longer exists - Eric Hoffer
Former Modifications/Extensions Team Member | My extensions
Appreciate the extensions/mods/support then buy me a beer
All requests for support via PM will be ignored

User avatar
spaceace
Registered User
Posts: 1857
Joined: Wed Jan 30, 2008 8:50 pm
Contact:

Re: links posted within my chat extension...

Post by spaceace » Fri Dec 04, 2015 9:44 pm

RMcGirr83 wrote:

Code: Select all

$message       = $this->user->lang('CHAT_NEW_TOPIC', '[url=' . $url . ']' . $event['post_data']['post_subject'] . '[/url]'); 

Code: Select all

'CHAT_NEW_POST'               => 'has replied to: %s', 
:?:
this works great. thank you :D

now i'm guessing that i will have to use an if to control the modes as that only posts "has started a new topic:". but at least the link is showing up right now

User avatar
RMcGirr83
Recognised Extension Developer
Posts: 21034
Joined: Wed Jun 22, 2005 4:33 pm
Location: Your display
Name: Rich McGirr
Contact:

Re: links posted within my chat extension...

Post by RMcGirr83 » Sat Dec 05, 2015 1:15 am

Yes you will need if statements depending on the mode being sent (reply, quote, post, etc.) to then have the correct lang var used.
In times of change, learners inherit the earth, while the learned find themselves beautifully equipped to deal with a world that no longer exists - Eric Hoffer
Former Modifications/Extensions Team Member | My extensions
Appreciate the extensions/mods/support then buy me a beer
All requests for support via PM will be ignored

User avatar
spaceace
Registered User
Posts: 1857
Joined: Wed Jan 30, 2008 8:50 pm
Contact:

Re: links posted within my chat extension...

Post by spaceace » Sat Dec 05, 2015 2:50 am

RMcGirr83 wrote:Yes you will need if statements depending on the mode being sent (reply, quote, post, etc.) to then have the correct lang var used.
that is what i did. i'm hoping everything is correct as everything has tested to be working with the following code in phpBB 3.1 as well as 3.2

thank you again :D

Code: Select all

    /**
     * Adds message in chat when someone posts to the forum
     *
     *
     *
     */
    public function add_forum_id($event)
    {
        if (!$this->config['ajax_chat_forum_posts'])
        {
            return;
        }

        if (!defined('CHAT_TABLE'))
        {
            $chat_table = $this->table_prefix . 'ajax_chat';
            define('CHAT_TABLE', $chat_table);
        }

        if (!defined('CHAT_SESSIONS_TABLE'))
        {
            $chat_session_table = $this->table_prefix . 'ajax_chat_sessions';
            define('CHAT_SESSIONS_TABLE', $chat_session_table);
        }

        $this->user->add_lang_ext('spaceace/ajaxchat', 'ajax_chat');

        if ($event['mode'] == 'reply' && $this->config['ajax_chat_forum_reply'])
        {
            $lang = $this->user->lang['CHAT_NEW_POST'];
        }
        else if ($event['mode'] == 'edit' && $this->config['ajax_chat_forum_edit'])
        {
            $lang = $this->user->lang['CHAT_POST_EDIT'];
        }
        else if ($event['mode'] == 'post' && $this->config['ajax_chat_forum_topic'])
        {
            $lang = $this->user->lang['CHAT_NEW_TOPIC'];
        }
        else if ($event['mode'] == 'quote' && $this->config['ajax_chat_forum_quote'])
        {
            $lang = $this->user->lang['CHAT_NEW_QUOTE'];
        }
        else
        {
            return;
        }

        $url                = append_sid(generate_board_url() . '/viewtopic.' . $this->php_ext, 'f=' . $event['data']['forum_id'] . '&t=' . $event['data']['topic_id'] . '&p=' . $event['data']['post_id'] . '#p' . $event['data']['post_id']);
        $username            = get_username_string('full', $this->user->data['user_id'], $this->user->data['username'], $this->user->data['user_colour']);
        if ($event['mode'] == 'post')
        {
            $message        = $this->user->lang('CHAT_NEW_TOPIC', '[url=' . $url . ']' . $event['post_data']['post_subject'] . '[/url]');
        }
        else if ($event['mode'] == 'edit')
        {
            $message        = $this->user->lang('CHAT_POST_EDIT', '[url=' . $url . ']' . $event['post_data']['post_subject'] . '[/url]');
        }
        else if ($event['mode'] == 'reply')
        {
            $message        = $this->user->lang('CHAT_NEW_POST', '[url=' . $url . ']' . $event['post_data']['post_subject'] . '[/url]');
        }
        else if ($event['mode'] == 'quote')
        {
            $message        = $this->user->lang('CHAT_NEW_QUOTE', '[url=' . $url . ']' . $event['post_data']['post_subject'] . '[/url]');
        }
        $uid                = $bitfield         = $options         = '';
        $allow_bbcode        = $allow_urls         = $allow_smilies     = true;
        generate_text_for_storage($message, $uid, $bitfield, $options, $allow_bbcode, $allow_urls, $allow_smilies);
        $sql_ary = array(
            'chat_id'             => 0,
            'user_id'             => $this->user->data['user_id'],
            'username'             => $this->user->data['username'],
            'user_colour'         => $this->user->data['user_colour'],
            'message'             => $message,
            'bbcode_bitfield'     => $bitfield,
            'bbcode_uid'         => $uid,
            'bbcode_options'     => $options,
            'time'                 => time(),
            'forum_id'             => $event['forum_id'],
            'post_id'             => $event['data']['post_id'],
        );
        $sql     = 'INSERT INTO ' . CHAT_TABLE . ' ' . $this->db->sql_build_array('INSERT', $sql_ary);
        $this->db->sql_query($sql);

    }

User avatar
RMcGirr83
Recognised Extension Developer
Posts: 21034
Joined: Wed Jun 22, 2005 4:33 pm
Location: Your display
Name: Rich McGirr
Contact:

Re: links posted within my chat extension...

Post by RMcGirr83 » Sat Dec 05, 2015 4:08 am

All of this

Code: Select all

        if ($event['mode'] == 'reply' && $this->config['ajax_chat_forum_reply'])
        {
            $lang = $this->user->lang['CHAT_NEW_POST'];
        }
        else if ($event['mode'] == 'edit' && $this->config['ajax_chat_forum_edit'])
        {
            $lang = $this->user->lang['CHAT_POST_EDIT'];
        }
        else if ($event['mode'] == 'post' && $this->config['ajax_chat_forum_topic'])
        {
            $lang = $this->user->lang['CHAT_NEW_TOPIC'];
        }
        else if ($event['mode'] == 'quote' && $this->config['ajax_chat_forum_quote'])
        {
            $lang = $this->user->lang['CHAT_NEW_QUOTE'];
        }
        else
        {
            return;
        }

        $url                = append_sid(generate_board_url() . '/viewtopic.' . $this->php_ext, 'f=' . $event['data']['forum_id'] . '&t=' . $event['data']['topic_id'] . '&p=' . $event['data']['post_id'] . '#p' . $event['data']['post_id']);
        $username            = get_username_string('full', $this->user->data['user_id'], $this->user->data['username'], $this->user->data['user_colour']);
        if ($event['mode'] == 'post')
        {
            $message        = $this->user->lang('CHAT_NEW_TOPIC', '[url=' . $url . ']' . $event['post_data']['post_subject'] . '[/url]');
        }
        else if ($event['mode'] == 'edit')
        {
            $message        = $this->user->lang('CHAT_POST_EDIT', '[url=' . $url . ']' . $event['post_data']['post_subject'] . '[/url]');
        }
        else if ($event['mode'] == 'reply')
        {
            $message        = $this->user->lang('CHAT_NEW_POST', '[url=' . $url . ']' . $event['post_data']['post_subject'] . '[/url]');
        }
        else if ($event['mode'] == 'quote')
        {
            $message        = $this->user->lang('CHAT_NEW_QUOTE', '[url=' . $url . ']' . $event['post_data']['post_subject'] . '[/url]');
        }
can now be set like this

Code: Select all

        $url                = append_sid(generate_board_url() . '/viewtopic.' . $this->php_ext, 'f=' . $event['data']['forum_id'] . '&t=' . $event['data']['topic_id'] . '&p=' . $event['data']['post_id'] . '#p' . $event['data']['post_id']);
        $username            = get_username_string('full', $this->user->data['user_id'], $this->user->data['username'], $this->user->data['user_colour']);
        if ($event['mode'] == 'post' && $this->config['ajax_chat_forum_topic'])
        {
            $message        = $this->user->lang('CHAT_NEW_TOPIC', '[url=' . $url . ']' . $event['post_data']['post_subject'] . '[/url]');
        }
        else if ($event['mode'] == 'edit'  && $this->config['ajax_chat_forum_edit'])
        {
            $message        = $this->user->lang('CHAT_POST_EDIT', '[url=' . $url . ']' . $event['post_data']['post_subject'] . '[/url]');
        }
        else if ($event['mode'] == 'reply' && $this->config['ajax_chat_forum_reply'])
        {
            $message        = $this->user->lang('CHAT_NEW_POST', '[url=' . $url . ']' . $event['post_data']['post_subject'] . '[/url]');
        }
        else if ($event['mode'] == 'quote' && $this->config['ajax_chat_forum_quote'])
        {
            $message        = $this->user->lang('CHAT_NEW_QUOTE', '[url=' . $url . ']' . $event['post_data']['post_subject'] . '[/url]');
        }
        else
        {
            return;
        }
and you're welcome. :)
In times of change, learners inherit the earth, while the learned find themselves beautifully equipped to deal with a world that no longer exists - Eric Hoffer
Former Modifications/Extensions Team Member | My extensions
Appreciate the extensions/mods/support then buy me a beer
All requests for support via PM will be ignored

Post Reply

Return to “Extension Writers Discussion”