Simple Machines Community Forum

Customizing SMF => SMF Coding Discussion => Topic started by: Rock Lee on January 31, 2019, 12:06:41 PM

Title: doubt with hardcoded text
Post by: Rock Lee on January 31, 2019, 12:06:41 PM
I am trying to create a modification for the users to change color, which everything is fine or so I thought. I was thinking about sending it to SMF when I realize something:

Code: [Select]
<a href="' . $scripturl . '?action=profile;u='. $message['member']['id'] . '" style="color: ' . $message['member']['color'] . ';" title="' . $txt['profile_color'] . ' ' . $message['member']['name'] . '">', $message['member']['name'], '</a>';
I have reference other modifications of how to add it and I remembered hardcoded text is not accepted... Search and look at several codes but I can not find what I want :'( How can I get it out and fulfill the same function "style="color:"?


Regards!

ADD: Looking at some SMF files I found that in Subs-MembersOnline.php on the line 106-110:
Code: [Select]
// Some basic color coding...
if (!empty($row['online_color']))
$link = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '" style="color: ' . $row['online_color'] . ';">' . $row['real_name'] . '</a>';

That is why I am doubtful about the regulation for the approval of the modifications! ???
Title: Re: doubt with hardcoded text
Post by: Aleksi "Lex" Kilpinen on January 31, 2019, 12:12:59 PM
If I understand right, and that's part of the url - then no worries. Hardcoded text refers to actual text output, which should be translatable.
To do a translatable string, you just use a $translatablestring and add a corresponding language string in modifications.english.php :)
Title: Re: doubt with hardcoded text
Post by: SychO on January 31, 2019, 12:14:08 PM
hardcoded text refers to hardcoded language text strings, not inline CSS which is what I'm assuming you mean
looks okay since there is no better way of assigning custom colors
Title: Re: doubt with hardcoded text
Post by: Kindred on January 31, 2019, 12:14:21 PM
that's not hardcoded text... :)


color is a CSS statement and, as such is acceptable.

However, you are including that because you have included inline styles.
Those should be avoided, in favor of actual CSS, if possible.
Instead of
style="color: ' . $message['member']['color'] . ';"
try something like
class="colorize-'. $message['member']['color'] .';"

and then in the CSS file
a.colorize-blue { color:"blue"; }
Title: Re: doubt with hardcoded text
Post by: Rock Lee on January 31, 2019, 12:20:00 PM
To my mistake then for misinterpreting it :P what modifications.english.php with the previous envie I understood, now I just need to solve that. Thank you so much @Lex!

@Kindred That way I had thought about it but in this case what I try to achieve is to assign each member a predetermined color, which I do not know how to achieve it the way you tell me. It can be easier if the same user declares said variable and I keep it together with other configurations of the user but I am again in the same doubt when I show that color to each user.

hardcoded text refers to hardcoded language text strings, not inline CSS which is what I'm assuming you mean
looks okay since there is no better way of assigning custom colors

Looking at other modifications and looking for several references I found the best solution, but I was left with some doubts when translating some words I did not finish understanding them.
Title: Re: doubt with hardcoded text
Post by: SychO on January 31, 2019, 12:38:28 PM
Kindred's right if you were to give users a selection of colors to choose from, however if the users specify the color value themselves then there is no better way of doing it then how you're doing it.