Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add chatbox_menu_template.php and chatbox_menu_shortcodes.php for chatbox_menu plugin. #3631

Merged
merged 1 commit into from
Jan 30, 2019
Merged

Add chatbox_menu_template.php and chatbox_menu_shortcodes.php for chatbox_menu plugin. #3631

merged 1 commit into from
Jan 30, 2019

Conversation

arunshekher
Copy link
Member

@CaMer0n,
Please review and merge. If there are changes required please advice. Yet to remove old chat_template.php from plugin folder.

Add chatbox_menu_template.php and chatbox_menu_shortcodes.php, Introduce shortcode/template combination to render avatars in chat.php

Changes:

  • Add chatbox_menu_template.php and chatbox_menu_shortcodes.php files.
  • Add bootstrap3 styling for some elements in chat.php list view markup.
  • Cleanup chat.php and chatbox_menu.php code generally and to replace legacy database calls with current standard.

Succeeded Tests:

  • Load chatbox_menu_template.php in {e_PLUGIN}/chatbox_menu/templates/chatbox_menu_template.php
  • Load chatbox_menu_template.php in {e_THEME}/templates/chatbox_menu/chatbox_menu_template.php

@CaMer0n
Copy link
Member

CaMer0n commented Jan 22, 2019

Thanks @arunshekher Have you tested it with v1 theme templates that use the following code or similar?
jayya is one example..

$CHATBOXSTYLE = "
<img src='".e_IMAGE_ABS."admin_images/chatbox_16.png' alt='' style='width: 16px; height: 16px; vertical-align: bottom' />
<b>{USERNAME}</b><br />{TIMEDATE}<br />{MESSAGE}<br /><br />";

@arunshekher
Copy link
Member Author

Yes, seems to render okay!
screen shot 2019-01-23 at 12 49 13 am
screen shot 2019-01-23 at 12 50 33 am

@arunshekher
Copy link
Member Author

This is the setup I used, tested with PHP 5.6 as well.
screen shot 2019-01-23 at 12 57 16 am

@CaMer0n
Copy link
Member

CaMer0n commented Jan 23, 2019

Thanks @arunshekher . It appears to be ignoring the template though?
Can you find admin_images/chatbox_16.png in the source?

@arunshekher
Copy link
Member Author

arunshekher commented Jan 24, 2019

Sure, I'll check that and amend the commit with the changes required.

@arunshekher
Copy link
Member Author

Please re-review, I removed the code block that fetched legacy chatbox_menu template to render chatbox_menu when legacy themes were used.

@CaMer0n
Copy link
Member

CaMer0n commented Jan 25, 2019

Thanks @arunshekher . I don't have time to check, but just wanted to confirm that $CHATBOXSTYLE is still respected when found?

@arunshekher
Copy link
Member Author

Okay @CaMer0n, I apologize if it's too obvious, but could you re-confirm if this is what you mean:

In brief should the goal be that..

  1. chatbox_menu.php should utilize the variable $CHATBOXSTYLE from legacy themes when available.
  2. But be able to remove the static asset admin_images/chatbox_16.png from it which is not resolvable in v2.
  3. And use the new $CHATBOX_MENU_TEMPLATE variable from the yet to be added {e_PLUGIN}chatbox_menu/templates/chatbox_menu_template.php in all other cases?

@arunshekher
Copy link
Member Author

@CaMer0n, Is this acceptable:
Tested with jayya, lamb and crahan apart from v2 themes and seems to work as expected.

In chatbox_menu.php :

        global $CHATBOXSTYLE;

	if($CHATBOXSTYLE) // legacy chatbox style
	{
		$legacyChatIcon = e_IMAGE_ABS . 'admin_images/chatbox_16.png';
		$legacySrch = array('{USERNAME}', '{MESSAGE}', '{TIMEDATE}', $legacyChatIcon);
		$legacyRepl = array('{CB_USERNAME}','{CB_MESSAGE}','{CB_TIMEDATE}', '{CB_ICON_16}');


		$CHATBOX_TEMPLATE['start'] = '';
		$CHATBOX_TEMPLATE['item'] = str_replace($legacySrch, $legacyRepl, $CHATBOXSTYLE);
		$CHATBOX_TEMPLATE['end'] = '';
	}
	else 	// default chatbox style
	{
		$CHATBOX_TEMPLATE = e107::getTemplate('chatbox_menu', null, 'menu');
	}

In chatbox_menu_shortcodes.php :

	public function sc_cb_icon_16()
	{
		return e_PLUGIN . 'chatbox_menu/images/chatbox_16.png';
	}

@CaMer0n
Copy link
Member

CaMer0n commented Jan 25, 2019

Thanks @arunshekher Looks good!

@arunshekher
Copy link
Member Author

@CaMer0n, I've amended PR after making the changes in chatbox_menu.php file alone as follows:

global $CHATBOXSTYLE;

	if($CHATBOXSTYLE)  // legacy chatbox style
	{
		$legacyIconSrc = e_IMAGE_ABS . 'admin_images/chatbox_16.png';
		$currentIconSrc = e_PLUGIN . 'chatbox_menu/images/chatbox_16.png';

		$legacySrch = array($legacyIconSrc, '{USERNAME}', '{MESSAGE}', '{TIMEDATE}');
		$legacyRepl = array($currentIconSrc, '{CB_USERNAME}','{CB_MESSAGE}','{CB_TIMEDATE}');


		$CHATBOX_TEMPLATE['start'] = '';
		$CHATBOX_TEMPLATE['item'] = str_replace($legacySrch, $legacyRepl, $CHATBOXSTYLE);
		$CHATBOX_TEMPLATE['end'] = '';
	}
	else 	// default chatbox style
	{
		$CHATBOX_TEMPLATE = e107::getTemplate('chatbox_menu', null, 'menu');
	}

"user_id = {$userId}");

}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This has no cache, so it could lead to a lot of queries. Use return e107::user($userId); instead.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@CaMer0n, thank you for the suggestion, I've updated the code in PR.

Introduce shortcode/template combination to render avatars in chat.php

Changes:
- Add chatbox_menu_template.php and chatbox_menu_shortcodes.php files.
- Add bootstrap3 styling for some elements in chat.php list view markup.
- Cleanup chat.php and chatbox_menu.php code generally and to replace legacy database calls with current standard.
- Add logic to search and replace legacy chat icon source path with current icon path in $CHATBOXSTYLE
- Refactor retrieveUserDataByNick() method to use e107::user() method to retireve extended user data.

Succeeded Tests:
- Load chatbox_menu_template.php in {e_PLUGIN}/chatbox_menu/templates/chatbox_menu_template.php
- Load chatbox_menu_template.php in {THEME}/templates/chatbox_menu/chatbox_menu_template.php
@CaMer0n
Copy link
Member

CaMer0n commented Jan 30, 2019

Thank you @arunshekher !

@CaMer0n CaMer0n merged commit bbc1a6c into e107inc:master Jan 30, 2019
@arunshekher arunshekher deleted the feature-branch/chat-list-avatars-chatbox-menu-template branch February 3, 2019 13:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants