News:

Wondering if this will always be free?  See why free is better.

Main Menu

@mention members

Started by Dragooon, May 02, 2014, 01:07:58 PM

Previous topic - Next topic

James Gryphon

Quote from: Koppo on April 11, 2016, 07:02:15 AM
I installed the mentions mod, it works fine. But I would like to make the mentions as an own button on the navigation bar. I am using the Core theme, i cant find any clue on how to edit the navigation bar as the wiki article seems outdated?! I cant find the code snippets related to the help article in index.template.php.

Would be great if someone could help me out  :'(
Hey Koppo,
I made up a hack for my Core theme not too long ago to do just that. It's neither pretty nor likely follows approved coding practices, but if you want it anyway, I can take some time to go into the files I edited, figure out what I did and post the changes back here.

Right now my schedule's a little hectic, but I can get this done for you when I have some spare time this week (maybe Tuesday or Thursday).

~ James

Arantor

Core theme in 2.0 does not require any changes to index.template.php since it's driven from the single menu code in setupMenuContext in Subs.php...

Nícholas Carballo

Quote from: Arantor on April 24, 2016, 04:54:45 AM
It would need a complete rewrite to work on 1.1, which is largely not supported any more, I don't even know if it's getting security patches any more.
I'm sorry to hear that. SMF still releases security patches. I'm currently using 1.1.21
Would you recommend me to upgrade to 2.0? Would I need to change my theme or just adapt it?

Arantor

SMF ha not patched some things in 1.1 and they won't ever be patched; if your host upgrades PHP, it probably won't work properly, as SMF 1.1 came out almost 10 years ago.

Upgrading to 2.0 should definitely be on the plans.

Nícholas Carballo

Quote from: Arantor on April 25, 2016, 12:59:11 PM
SMF ha not patched some things in 1.1 and they won't ever be patched; if your host upgrades PHP, it probably won't work properly, as SMF 1.1 came out almost 10 years ago.

Upgrading to 2.0 should definitely be on the plans.
And what about my current theme?

Arantor

The theme would need to be adapted, unfortunately, but depending on theme it might already have been converted.

James Gryphon

#466
All right, I have the Subs.php and Mentions.php files up, and here's what the hack I did looked like.

In Subs.php, I included this code right below the existing PM button.

Quote'pm' => array(
            'title' => $txt['pm_short'],
            'href' => $scripturl . '?action=pm',
            'show' => $context['allow_pm'],
            'sub_buttons' => array(
               'pm_read' => array(
                  'title' => $txt['pm_menu_read'],
                  'href' => $scripturl . '?action=pm',
                  'show' => allowedTo('pm_read'),
               ),
               'pm_send' => array(
                  'title' => $txt['pm_menu_send'],
                  'href' => $scripturl . '?action=pm;sa=send',
                  'show' => allowedTo('pm_send'),
                  'is_last' => true,
               ),
            ),
         ),
// Dirty mentions hack
'mentions' => array(
            'title' => 'Mentions',
            'href' => $scripturl . '?action=profile;area=mentions',
            'show' => !$user_info['is_guest'],
            'sub_buttons' => array(
            ),
         ),
      

That should add the Mention button to the menu bar. I believe the only thing that's needed to do after this is to edit the Mentions.php file to use the Mentions button instead of Profile. Look for the following text:
Quote$menu_buttons['profile']['sub_buttons']['mentions'] = array(
      'title' => $txt['mentions'] . (!empty($user_settings['unread_mentions']) ? ' [' . $user_settings['unread_mentions'] . ']' : ''),
      'href' => $scripturl . '?action=profile;area=mentions',
      'show' => true,
   );
   $menu_buttons['profile']['title'] .=  (!empty($user_settings['unread_mentions']) ? ' [' . $user_settings['unread_mentions'] . ']' : '');

And replace it with this:
Quote$menu_buttons['mentions']['sub_buttons']['mentions'] = array(
      'title' => $txt['mentions'] . (!empty($user_settings['unread_mentions']) ? ' [' . $user_settings['unread_mentions'] . ']' : ''),
      'href' => $scripturl . '?action=profile;area=mentions',
      'show' => true,
   );
   $menu_buttons['mentions']['title'] .=  (!empty($user_settings['unread_mentions']) ? ' [' . $user_settings['unread_mentions'] . ']' : '');
l'm sure the code isn't pretty, and if you ever want to uninstall @mentions, you'll have to go back to these files later and remove these manually first. But it seemed to work for my forum.

Arantor

Note that the 'tags' part in your Subs.php edit is for a different mod...

James Gryphon

Good catch! I didn't notice (it's been a while since I've looked in or thought anything about those files, so I used the difference checker to help me out and didn't look too carefully at the results), but I'll remove that from the post ASAP.

mktek

Hi Dragooon,

Thanks for this mod.

I use smf 2.0.x, mention 1.1.3

Language: Turkish ISO-8859-9

I'm having problems in the Turkish character. For example: "AL GÜLÜM"

How can I solve this problem?

Thanks...

Miker1029

Quote from: Steelio on June 30, 2014, 04:08:07 AM
thanks for this Dragoon!

i do have an issue similar to Sigyn, except my issue is that the mentions doesnt seem to work if there is a space between the user's name.
for example:

@Dr Who
@Keyser Soze

... btw i applied the tweak you mentioned below, hoping this will fix my issue, but it doesnt. i'm still having the same problem :(

Quote from: Dragooon on June 06, 2014, 12:33:50 PM
Quote from: phantomm on June 06, 2014, 11:29:24 AM
It's selected from dropdown so yes, I'm sure it is followed by @ sign, exactly like this:
@Username <")))/
Try this, open mentions.php
Code (Find) Select
$names = array_unique(array_map('trim', $names));
Code (Replace) Select
$names = array_unique(array_map('htmlspecialchars', array_map('trim', $names)));

I am Also Having this Problem, One of my test Accounts is "Black Death" and when you hit the Space the Drop-Down Goes away, I complete the Username (Death), and It doesn't send e-mail, Or make the "@Black Death" into a Clickable link...

Also, If I click the username in the drop down, It also Doesn't work, Same as above...

I searched here for "Space Username", and didn't see a fix.

Anyone have an Idea on how to fix this?

Thanks

Mike

Gluz

Quote from: Miker1029 on May 23, 2016, 02:04:33 PM
I am Also Having this Problem, One of my test Accounts is "Black Death" and when you hit the Space the Drop-Down Goes away, I complete the Username (Death), and It doesn't send e-mail, Or make the "@Black Death" into a Clickable link...

Also, If I click the username in the drop down, It also Doesn't work, Same as above...

I searched here for "Space Username", and didn't see a fix.

Anyone have an Idea on how to fix this?

Thanks

Mike

Change the content of file /Themes/default/scripts/mentions.js to this (from the Github of the author):

/**
* Javascript interface for active suggestions while posting
*
* @author ******iz Garg <[email protected]>
* @copyright 2014 ******iz Garg
* @license Simplified BSD (2-Clause) License
*/

var mentionInit = function()
{
var fails = [];

var config = {
at: '@',
data: [],
show_the_at: true,
limit: 10,
callbacks: {
matcher: function(flag, subtext, should_start_with_space) {
var match = '', started = false;
var string = subtext.split('');
for (var i = 0; i < string.length; i++)
{
if (string[i] == flag && (!should_start_with_space || i == 0 || /[\s\n]/gi.test(string[i - 1])))
{
started = true;
match = '';
}
else if (started)
match = match + string[i];
}

if (match.length > 0)
return match;

return null;
},
remote_filter: function (query, callback) {
if (typeof query == 'undefined' || query.length < 2 || query.length > 60)
return;

for (i in fails)
if (query.substr(0, fails[i].length) == fails[i])
return;

$.ajax({
url: smf_scripturl + '?action=suggest;' + smf_sessvar + '=' + smf_sessid + ';xml',
method: 'GET',
data: {
search: query,
suggest_type: 'member'
},
success: function (data) {
var members = $(data).find('smf > items > item');
if (members.length == 0)
fails[fails.length] = query;

var callbackArray = [];
$.each(members, function (index, item) {
callbackArray[callbackArray.length] = {
name: $(item).text()
};
});

callback(callbackArray);
}
});
}
}
};

if (typeof $.fn.atwho == 'undefined' && typeof jQuery.fn.atwho != 'undefined')
{
var iframe = jQuery('#html_message');

if (typeof iframe[0] != 'undefined')
jQuery(iframe[0].contentDocument.body).atwho(config);
jQuery('textarea[name=message]').atwho(config);
}
else
{
var iframe = $('#html_message');
if (typeof iframe[0] != 'undefined')
$(iframe[0].contentDocument.body).atwho(config);
$('textarea[name=message]').atwho(config);
}
};

var atWhoElement = document.createElement('script');
atWhoElement.src = atwho_url;
atWhoElement.type = 'text/javascript';
atWhoElement.onload = mentionInit;

if (typeof $ == 'undefined' || (parseInt($.fn.jquery.substr(0, 1)) == 1 && parseInt($.fn.jquery.substr(2, 3)) < 8) || jQuery.fn.jquery != $.fn.jquery)
{
var scriptElement = document.createElement('script');
scriptElement.src = jquery_url;
scriptElement.type = 'text/javascript';

scriptElement.onload = function () {
document.body.appendChild(atWhoElement);
};

document.body.appendChild(scriptElement);
}
else
document.body.appendChild(atWhoElement);









Though this is not relevant for the issue with spaces in names, is worth to mention it and fix it (all from the author's Github).

In the /Sources/mentions.php file search:
if (count($matches[count($matches) - $i]) > 60)
{
$depth--;
break;
}


and replace for:
if (count($matches[count($matches) - $i]) > 60)
{
$depth--;
continue;
}



Find:
$subject = str_replace(array_keys($replacements), array_values($replacements), $txt['mentions_subject']);
$body = str_replace(array_keys($replacements), array_values($replacements), $txt['mentions_body']);
sendmail($mention['email_address'], $subject, $body);

and replace for:
$emailsubject = str_replace(array_keys($replacements), array_values($replacements), $txt['mentions_subject']);
$body = str_replace(array_keys($replacements), array_values($replacements), $txt['mentions_body']);
sendmail($mention['email_address'], $emailsubject, $body);



Find:
$subject = str_replace(array_keys($replacements), array_values($replacements), $txt['mentions_subject']);
$body = str_replace(array_keys($replacements), array_values($replacements), $txt['mentions_body']);
sendmail($row['email_address'], $subject, $body);

Replace for:
$emailsubject = str_replace(array_keys($replacements), array_values($replacements), $txt['mentions_subject']);
$body = str_replace(array_keys($replacements), array_values($replacements), $txt['mentions_body']);
sendmail($row['email_address'], $emailsubject, $body);



Find:
'base_href' => $scripturl . '?action=profile;area=tracking;sa=user;u=' . $memID,
Replace for:
'base_href' => $scripturl . '?action=profile;area=mentions;sa=user;u=' . $memID,

Miker1029

Ok, Good deal, Thanks for that!  Editing code now.

Mike

Dream of Omnimaga

By the way, is this mod still being maintained? I was wondering because the bug mentioned at http://www.simplemachines.org/community/index.php?topic=522005.msg3748982#msg3748982 is still present in the latest version.

Kindred

Last modification was May 2014... That bug was reported in sept 2014.
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

Paracelsus

Quote from: Gluz on June 01, 2016, 08:49:02 PM
Quote from: Miker1029 on May 23, 2016, 02:04:33 PM
I am Also Having this Problem, One of my test Accounts is "Black Death" and when you hit the Space the Drop-Down Goes away, I complete the Username (Death), and It doesn't send e-mail, Or make the "@Black Death" into a Clickable link...

Also, If I click the username in the drop down, It also Doesn't work, Same as above...

I searched here for "Space Username", and didn't see a fix.

Anyone have an Idea on how to fix this?

Thanks

Mike

Change the content of file /Themes/default/scripts/mentions.js to this (from the Github of the author):

/**
* Javascript interface for active suggestions while posting
*
* @author ******iz Garg <[email protected]>
* @copyright 2014 ******iz Garg
* @license Simplified BSD (2-Clause) License
*/

var mentionInit = function()
{
var fails = [];

var config = {
at: '@',
data: [],
show_the_at: true,
limit: 10,
callbacks: {
matcher: function(flag, subtext, should_start_with_space) {
var match = '', started = false;
var string = subtext.split('');
for (var i = 0; i < string.length; i++)
{
if (string[i] == flag && (!should_start_with_space || i == 0 || /[\s\n]/gi.test(string[i - 1])))
{
started = true;
match = '';
}
else if (started)
match = match + string[i];
}

if (match.length > 0)
return match;

return null;
},
remote_filter: function (query, callback) {
if (typeof query == 'undefined' || query.length < 2 || query.length > 60)
return;

for (i in fails)
if (query.substr(0, fails[i].length) == fails[i])
return;

$.ajax({
url: smf_scripturl + '?action=suggest;' + smf_sessvar + '=' + smf_sessid + ';xml',
method: 'GET',
data: {
search: query,
suggest_type: 'member'
},
success: function (data) {
var members = $(data).find('smf > items > item');
if (members.length == 0)
fails[fails.length] = query;

var callbackArray = [];
$.each(members, function (index, item) {
callbackArray[callbackArray.length] = {
name: $(item).text()
};
});

callback(callbackArray);
}
});
}
}
};

if (typeof $.fn.atwho == 'undefined' && typeof jQuery.fn.atwho != 'undefined')
{
var iframe = jQuery('#html_message');

if (typeof iframe[0] != 'undefined')
jQuery(iframe[0].contentDocument.body).atwho(config);
jQuery('textarea[name=message]').atwho(config);
}
else
{
var iframe = $('#html_message');
if (typeof iframe[0] != 'undefined')
$(iframe[0].contentDocument.body).atwho(config);
$('textarea[name=message]').atwho(config);
}
};

var atWhoElement = document.createElement('script');
atWhoElement.src = atwho_url;
atWhoElement.type = 'text/javascript';
atWhoElement.onload = mentionInit;

if (typeof $ == 'undefined' || (parseInt($.fn.jquery.substr(0, 1)) == 1 && parseInt($.fn.jquery.substr(2, 3)) < 8) || jQuery.fn.jquery != $.fn.jquery)
{
var scriptElement = document.createElement('script');
scriptElement.src = jquery_url;
scriptElement.type = 'text/javascript';

scriptElement.onload = function () {
document.body.appendChild(atWhoElement);
};

document.body.appendChild(scriptElement);
}
else
document.body.appendChild(atWhoElement);









Though this is not relevant for the issue with spaces in names, is worth to mention it and fix it (all from the author's Github).

In the /Sources/mentions.php file search:
if (count($matches[count($matches) - $i]) > 60)
{
$depth--;
break;
}


and replace for:
if (count($matches[count($matches) - $i]) > 60)
{
$depth--;
continue;
}



Find:
$subject = str_replace(array_keys($replacements), array_values($replacements), $txt['mentions_subject']);
$body = str_replace(array_keys($replacements), array_values($replacements), $txt['mentions_body']);
sendmail($mention['email_address'], $subject, $body);

and replace for:
$emailsubject = str_replace(array_keys($replacements), array_values($replacements), $txt['mentions_subject']);
$body = str_replace(array_keys($replacements), array_values($replacements), $txt['mentions_body']);
sendmail($mention['email_address'], $emailsubject, $body);



Find:
$subject = str_replace(array_keys($replacements), array_values($replacements), $txt['mentions_subject']);
$body = str_replace(array_keys($replacements), array_values($replacements), $txt['mentions_body']);
sendmail($row['email_address'], $subject, $body);

Replace for:
$emailsubject = str_replace(array_keys($replacements), array_values($replacements), $txt['mentions_subject']);
$body = str_replace(array_keys($replacements), array_values($replacements), $txt['mentions_body']);
sendmail($row['email_address'], $emailsubject, $body);



Find:
'base_href' => $scripturl . '?action=profile;area=tracking;sa=user;u=' . $memID,
Replace for:
'base_href' => $scripturl . '?action=profile;area=mentions;sa=user;u=' . $memID,


Hi, unfortunately these changes don't solve the problem on tagging those with ' in their names, which has been reported by other users.

Can anyone find an effective solution for this?

Miker1029

Ya didn't work for me either, I even went to the GIT to see if I could find the Info, and nothing, and DL'd the ZIP from the GIT to try and resolve the issues, Guessing maybe It's not supported anymore, Really Dunno, Shame, It's a Nice MOD, With a Few Bug Fixes it'd be a Long Standing MOD, But as It stands the SPACE thing really is a Killer, As I've got 2600+ Users and Unfortunately didn't set things up for No Space in Users.....

If anyone else has Any ideas it'd be Appreciated..

Mike

Boskonovic

Hello!

First of all Thank you for this Mod, really useful and future-oriented, something which would be absolutely needed in the 2.1.

I have one question:

I would like to expand the profile page where the mentions are displayed, to show their Status (read or new).
In the DB we have the "unseen" column, which is 0/1 and i would like to translate it to a string when displaying the mention list.

I tried to take a look at the "$ListOptions" variable and i have been able to include the new header and the column as well, but i don't know how to convert the boolean value to a string, inside this variable, using the different methods available in the List template (http://wiki.simplemachines.org/smf/Generic_List).


Let me know if the question is not clear enough.

Thank You

Boskonovic

Hello!

I have been able to solve my issue, by using the "function" callback method.

I have also completed the translation to Italian (both standard and utf-8).
A piece of the strings is included directly in the "install-english.xml".

Best Regards

tjbalon

For any of you dealing with users unable to visit previous mentions from their profile (action=profile;area=mentions) here's a quick fix you can perform in Sources/Mentions.php

Replace line 405 with:
'base_href' => $scripturl . '?action=profile;area=mentions',

Advertisement: