More than one member group icon

Started by Belisarius, July 21, 2013, 01:36:28 PM

Previous topic - Next topic

Belisarius

Hi again

When a user of my board is in more than just member group, then only the group symbol of the chosen main member group is displayed under the user's nick in postings. Is it possible to enable all the group symbols of groups the user is in?

That would be nice.

kat

Admin>Current theme>Hide post group titles for grouped members: (Near the bottom).

For reasons that I will never understand, this is not a global setting. It's done on a theme-by-theme basis.

So, you'll need to do this for every theme, individually. :(

Chalky


Belisarius

ChalkCat ninja'd me as I wrote my more precised explanation.

Thanks, that's what I meant.

kat


Chalky


kat


Belisarius

Hm... The mod installation worked when I emulated 2.0, but still I had a few errors in the install log. Installed never the less, but it doesn't show the mod options. Looks like a theme related problem, as it only seems to support the default core theme, but I only have the default curve theme installed. Anyone any idea what could help?

Chalky

If you continued to install in spite of test failed errors, the mod didn't install properly.  See here  http://wiki.simplemachines.org/smf/Error_in_mod_installation.

Do you know which edits it failed on?  If not you will have to go through the edits the mod makes, ensuring that each of them was made correctly and manually editing any that weren't.  Click the Parse button on the mod download page for the manual install instructions.

If it only failed on the custom theme then it's just a case of applying the manual edits to any files of which your custom theme has its own, such as index.css, index.template.php and possibly Boardindex.template.php if your custom theme contains one of those too.

Belisarius

Nope, it failed on Load.php, ManageSettings.php, PersonalMessage.template.php and Display.template.php. I'm editing the files now manually, though I'm a bit in trouble doing the third edit on the Load.php file as it is already modified by another mod and I'm taking a long time to find the right parts of the code that has to be replaced with the modified part.

The modification that already altered the code is, when looking at the parse section of the Modifications site, not compatible with my SMF version, though it works just fine, so I can't instantly see the altered code and have to look into it by reviewing the backups of the file, which are numerous, because I always make a backup of a file that is being edited by a mod.

Chalky

I'm relieved to know you keep backups   :). Sounds like you're going the right way about everything. If there's anything you're not sure about please give us a shout  :)

In the parse area if you view the parse instructions for the latest version of SMF that the mod claims to support, that shouldn't be too far off the mark.

Belisarius

Hah! The obvious way wasn't that obvious to me, so thanks. :D

Yeah, I could use some advise.

The Member Color Link mod did the modification and altered a small code segment that I'm a bit troubled with now.

This one is looked for by the mentioned mod and I found it.

Code (find) Select
// Load a theme, by ID.

Member Color Link then add this.

Code (Replace with) Select
//This is the universial load colors function, can be used by each person who need it :)
//I think it's intressting for mod Creators =D
//SMF 2.0.x Version

function load_onlineColors($users, $returnarray = true, $singleuser = false) {
global $color_profile, $modSettings, $smcFunc;
static $color_array;

//Make something for sure :)
if(!isset($color_profile))
$color_profile = array();
//This will hold the array data for later ;)
if(!isset($color_array))
$color_array = array();
//Set a standard empty array for guest errors ;) (Deleted users, which are not resetet)
if(!isset($color_profile[0]))
$color_profile[0] = array('member_group_color' => '', 'post_group_color' => '');

// Can't just look for no users :P.
if (empty($users))
return false;

// Make sure it's an array.
$users = !is_array($users) ? array($users) : array_unique($users);

//... SSI can insert empty users :x
foreach($users as $k => $u)
if(empty($u) || $u < 0 || !is_numeric($u))
unset($users[$k]);

//Now i will use this as a chache, too
$loaded_ids = array();
$all_loaded_ids = array_keys($color_profile);
//All the users that allready loaded
$loaded_ids = array_intersect($all_loaded_ids, $users);
//Now i need only the new users to load
$users = array_diff($users, $all_loaded_ids);

if(!empty($users)) {
// Load the data.
$request = $smcFunc['db_query']('', "
SELECT
mem.id_member AS id_member, mem.real_name AS real_name, mem.is_activated AS is_activated,
mem.birthdate AS birthdate,
mg.online_color AS member_group_color, IFnull(mg.group_name, '') AS member_group,
pg.online_color AS post_group_color, IFnull(pg.group_name, '') AS post_group
FROM {db_prefix}members AS mem
LEFT JOIN {db_prefix}membergroups AS pg ON (pg.id_group = mem.id_post_group)
LEFT JOIN {db_prefix}membergroups AS mg ON (mg.id_group = mem.id_group)
WHERE mem.id_member ".(count($users) == 1 ? " = '" . current($users) . "'" : " IN ('" . implode("', '", $users) . "')"));

while ($row = $smcFunc['db_fetch_assoc']($request))
{
$loaded_ids[] = $row['id_member'];
$color_profile[$row['id_member']] = $row;
//Happy Birthday Color ;D Hope you love it :D
if(!empty($modSettings['MemberColorBirthdayColor']) && !empty($row['birthdate']) && compare_colorBirthdate($row['birthdate'])) {
$color_profile[$row['id_member']]['post_group_color'] = $modSettings['MemberColorBirthdayColor'];
$color_profile[$row['id_member']]['member_group_color'] = $modSettings['MemberColorBirthdayColor'];
}
//Banned User hope it is not a mod ;)
if(!empty($modSettings['MemberColorBanned']) && isset($row['is_activated']) && $row['is_activated'] >= 10) {
$color_profile[$row['id_member']]['post_group_color'] = $modSettings['MemberColorBanned'];
$color_profile[$row['id_member']]['member_group_color'] = $modSettings['MemberColorBanned'];
}
}
$smcFunc['db_free_result']($request);
}

//Build the Array ;D
$array = array();
if(!empty($loaded_ids) && $returnarray == true) {
global $txt, $scripturl, $board_info;
foreach($loaded_ids as $id) {
$mod = false;
//Rewrite Moderator Color!
if(isset($board_info['moderators'][$id]) && (empty($color_array[$id]) || !$color_array[$id]['moderator'])) {
if(isset($color_array[$id]))
unset($color_array[$id]);
if(empty($color_profile[$id]['member_group_color']))
$color_profile[$id]['member_group_color'] = load_mod_color(true);
$mod = true;
}
//Load a prepared Data?
if(!isset($color_array[$id])) {
$profile = $color_profile[$id];
$onlineColor = !empty($profile['member_group_color']) ? $profile['member_group_color'] : $profile['post_group_color'];
$color_array[$id] = array(
'id' => $id,
'online_color' => $onlineColor,
'colored_name' => (!empty($onlineColor) ? '<span style="color:'. $onlineColor .';">' : '' ) . $profile['real_name'] . (!empty($onlineColor) ? '</span>' : ''),
//Make it compatible old and new style
'colored_link' => (empty($modSettings['MemberColorLinkOldSpanStyle']) ?
'<a href="' . $scripturl . '?action=profile;u=' . $profile['id_member'] . '" title="' . $txt['profile_of'] . ' ' . $profile['real_name'] . '"'.(!empty($onlineColor) ? ' style="color:'.$onlineColor.';"' : '').'>' . $profile['real_name'] .'</a>' :
'<a href="' . $scripturl . '?action=profile;u=' . $profile['id_member'] . '" title="' . $txt['profile_of'] . ' ' . $profile['real_name'] . '">' . ( !empty($profile['member_group_color']) || !empty($profile['post_group_color']) ? '<span style="color:'. ( !empty($profile['member_group_color']) ? $profile['member_group_color'] : $profile['post_group_color'] ) .';">' : '' ) . $profile['real_name'] . (!empty($profile['member_group_color']) || !empty($profile['post_group_color']) ? '</span>' : '' ).'</a>'),
'moderator' => $mod,
);
}
$array[$id] = $color_array[$id];
}
}

//This option return only a single user, i hope you know what you do ;)
if($singleuser === true)
$array = current($array);

//Return that what should returned XD
return (empty($loaded_ids) ? false : ($returnarray == true ? $array : $loaded_ids));
}

//Load in a fast way the Moderator color... i think i cashe it sometimes...
//$update it's only for me that the mod is fast ;)
function load_mod_color($return = false, $update = null) {
global $context, $modSettings, $smcFunc;

//Need a update?
if($update !== null && $return === false) {
updateSettings(array('MemberColorLinkModColor' => $update));
return true;
}

//This settings is loaded in the loadMemberData
if(isset($modSettings['MemberColorLinkModColor']) && !isset($context['modGroupColor']))
$context['modGroupColor'] = $modSettings['MemberColorLinkModColor'];

if(!isset($context['modGroupColor'])) {
$context['modGroupColor'] = '';
$modColor = $smcFunc['db_query']('', "
SELECT online_color AS online_color
FROM {db_prefix}membergroups
WHERE ID_GROUP = 3
LIMIT 1");
list($context['modGroupColor']) = $smcFunc['db_fetch_row']($modColor);
$smcFunc['db_free_result']($modColor);
}

//Need a update?
if(!isset($modSettings['MemberColorLinkModColor']))
updateSettings(array('MemberColorLinkModColor' => $context['modGroupColor']));

$return = (bool) $return;
return $return ? $context['modGroupColor'] : true;
}

//Compare Birthday, return true on todays brithday
function compare_colorBirthdate($birthday = '')
{
if (empty($birthday))
return false;
$d = explode('-', trim($birthday));
if (count($d) != 3)
return false;
$d['0'] = (int) $d['0'];
$d['1'] = (int) $d['1'];
$d['2'] = (int) $d['2'];
if (empty($d['2']) || empty($d['1']) || $d['0'] <= 1)
return false;
return date('md') == date('md', mktime(0,0,0,$d['1'],$d['2'],0)) ? true : false;
}

// Load a theme, by ID.


It's quite an amount of code, so as I'm really a newbie to php (is it really called coding what I try to do here?) coding I'm really cautious here.

Now  the Stars and Badges mod is looking for this...

Code (Find) Select
return true;
}

// Load a theme, by ID.


...to replace it with this.

Code (Replace) Select
$context['badges']['ownline'] = !empty($modSettings['badge_ownline']) ? explode(',', $modSettings['badge_ownline'], 20) : '';
 
$groups = $profile['additional_groups'];
// Load additional membergroups
if (!empty($groups))
{
$result_stars = $smcFunc['db_query']('', '
SELECT id_group, group_name, stars, online_color
FROM {db_prefix}membergroups
WHERE id_group IN (' . $groups . ')
',
array()
);

// additional groups
while ($row_stars = $smcFunc['db_fetch_assoc']($result_stars))
if (!empty($row_stars['stars']))
{
$memberContext[$user]['additional_groups']['id'][] = $row_stars['id_group'];
$memberContext[$user]['additional_groups']['stars'][] = str_repeat('<img src="' . str_replace('$language', $context['user']['language'], isset($row_stars['stars'][1]) ? $settings['images_url'] . '/' . $smcFunc['substr']($row_stars['stars'], 2, strlen($row_stars['stars'])) : '') . '" alt="*" border="0" />', empty($row_stars['stars'][0]) || empty($row_stars['stars'][1]) ? 0 : $row_stars['stars'][0]);
$memberContext[$user]['additional_groups']['name'][] = $row_stars['group_name'];
$memberContext[$user]['additional_groups']['ag_color'][] = $row_stars['online_color'];
}
$smcFunc['db_free_result']($result_stars);
}

return true;
}

// Load a theme, by ID.


But the "return true;" part is gone due to the alteration of the member color link modification and I don't know where to add the code the mod tries to add. Could you help me here?

I've put the "Find" and "Replace with" tag-suffixes to the codes for better understandings. Hope that helps.

kat

Personally, I'd try the old "Trial and error" thing.

I'd try adding the new code, after that block.

If it screws something, I'd try after it.

If that screwed, I'd give up! (Maybe a post in the mod's support topic, then). ;)

Chalky

Ooh that's tricky!  Looking at the the code, the Badges and stars mod doesn't actually replace the "return true", if you look at the replace code the "return true" is still there at the bottom, so it's just telling you to stick all the other code before that.

Now, looking at the member colour link code, that has actually modified the "return true" to "return... a whole lot of something else"

As K@ says it's going to be trial and error.  I would try copying all the code you've quoted from the badges mod except the

return true;
}

// Load a theme, by ID.


at the end (to avoid duplication), and paste it before all the code added by the member colour mod.

As always, take a backup and don't panic if you get a big fat parse error  ;)

Belisarius

Doing that right now.

Now I went forth to the ManageSettings.php and found something in the install-1.xml, that I'm not sure what to think of.

See the second line what it is looking for:

<!-- Sources/ManageSettings.php -->
<file name="$sourcedir/ModSettings.php">


There is no ModSettings.php on my whole server. Is it possible the mod author screwed something up or am I just oversensitive regarding filenaming in mod installation files?

Chalky

No, you're not oversensitive, file names do have to be exact.  I'm not sure what that's about though, there's nothing like that in the parse instructions on the mod site  :-\

Edit:  Wait, stop right there!  I suspect install-1.xml is the install instructions for version 1.0.x forums!  In which case you'll need install-2.xml!  But seriously, the parse page is easier.  Select version 2.0 and follow those instructions  :)

Edit 2:  Confirmed, ModSettings.php is a 1.0.x thing  ;)

Belisarius

Not quite true. The parse section tells me to do these changes in the ManageSettings.php, but the code looked for, which is just a line, doesn't even exist in that file.

<!-- Sources/ManageSettings.php -->
<file name="$sourcedir/ModSettings.php">
<operation><!-- 202 -->
<search position="after"><![CDATA[// Stats, compression, cookies.... server type stuff.]]></search>
<add><![CDATA[// Badge abd stars
array('text', 'badge_ownline'),
'',
]]></add>
</operation>
</file>


The part of the install-1.xml

Chalky

Only in install-1.xml, which isn't for your version.  Look at install-2.xml  ;)

Belisarius

Ok, the mod is quite hard to install manually. I tried my best, didn't even get parsing errors, but it doesn't work no matter what I try. It even corrupted my nav bar, due to a translation error that I seem to have done, so I have done a rollback and have to fix the nav bar error by hand. Dunno what exactly went wrong, but I'm going with K@'s third option: Giving it up, because that feature isn't worth my forum and the work I've already put into it.

Marked as solved.

kat

Quote from: K@ on July 21, 2013, 04:31:29 PM(Maybe a post in the mod's support topic, then)

I wouldn't hold my breath, though, coz the mod WAS released for an old RC version of SMF.

Advertisement: