Advertisement:

Author Topic: Help me write this code...  (Read 5608 times)

Offline Shuban

  • SMF Hero
  • ******
  • Posts: 2,389
    • Free Homework Help
Help me write this code...
« on: March 09, 2012, 06:33:30 PM »
In messageindex... I want the following argument:

If the person who started the topic is in group 15 or 21, show the topic title in red.

I have narrowed down where I am supposed to make the changes in MessageIndex.php.

Code: [Select]
// 'Print' the topic info.
$context['topics'][$row['ID_TOPIC']] = array(
'id' => $row['ID_TOPIC'],
'first_post' => array(
'id' => $row['ID_FIRST_MSG'],
'member' => array(
'membergroup' => $context['redbold']['member'][$row['firstID_MEMBER']]['membergroup'],
'username' => $row['firstMemberName'],
'name' => $row['firstDisplayName'],
'id' => $row['firstID_MEMBER'],
'href' => !empty($row['firstID_MEMBER']) ? $scripturl . '?action=profile;u=' . $row['firstID_MEMBER'] : '',
'link' => !empty($row['firstID_MEMBER']) ? '<a href="' . $scripturl . '?action=profile;u=' . $row['firstID_MEMBER'] . '" title="' . $txt[92] . ' ' . $row['firstDisplayName'] . '">' . $row['firstDisplayName'] . '</a>' : (!empty($modSettings['MemberColorGuests']) ? '<span style="color:'.$modSettings['MemberColorGuests'].';">' : '').$row['firstDisplayName'].(!empty($modSettings['MemberColorGuests']) ? '</span>' : '')
),
'time' => timeformat($row['firstPosterTime']),
'timestamp' => forum_time(true, $row['firstPosterTime']),
'subject' => $row['firstSubject'],
'preview' => $row['firstBody'],
'icon' => $row['firstIcon'],
'icon_url' => $settings[$context['icon_sources'][$row['firstIcon']]] . '/post/' . $row['firstIcon'] . '.gif',
'href' => $scripturl . '?topic=' . $row['ID_TOPIC'] . '.0',
'link' => '<a href="' . $scripturl . '?topic=' . $row['ID_TOPIC'] . '.0"'  . $row['nice_tooltip_first_msg'] . '>' . $row['firstSubject'] . '</a>'

Specifically where it says: 'link' => '<a href="' . $scripturl . '?topic=' . $row['ID_TOPIC'] . '.0"'  . $row['nice_tooltip_first_msg'] . '>' . $row['firstSubject'] . '</a>'

This is for 1.x
« Last Edit: March 09, 2012, 06:39:34 PM by Liam_michael »


Offline DanCarroll

  • Jr. Member
  • **
  • Posts: 125
  • Gender: Male
  • Technologist
Re: Help me write this code...
« Reply #2 on: March 11, 2012, 04:45:07 PM »
Liam, I am not familiar with that section of code but if I was really wanting to change the style myself given a certain condition I might look at jQuery or inline styles. Can you identify which ones you want to change? How about adding an inline <span style="color:red;">?



Offline Shuban

  • SMF Hero
  • ******
  • Posts: 2,389
    • Free Homework Help
Re: Help me write this code...
« Reply #3 on: March 11, 2012, 05:21:13 PM »
Liam, I am not familiar with that section of code but if I was really wanting to change the style myself given a certain condition I might look at jQuery or inline styles. Can you identify which ones you want to change? How about adding an inline <span style="color:red;">?

I want it to be red when a person of a particular membergroup posts the topic. For instance, all topics started by users of membergroup 5 will have red topics.

Offline DanCarroll

  • Jr. Member
  • **
  • Posts: 125
  • Gender: Male
  • Technologist
Re: Help me write this code...
« Reply #4 on: March 11, 2012, 06:12:48 PM »
Okay, without developing the code for you, let's see what you have. You say you have the code to be modified narrowed down to the 'link' line of code? Do you have the logic set up to filter by the groups you need? If so, you can set a style class up in the anchor tag and then set the color in your style sheet. Or if you don't mind inline styles, just set the color style in your anchor tag.

Hopefully all of this makes sense to you. I don't know what your level of proficiency or understanding is but this is a problem that will require some php, html, and css to synthesize a solution.

Offline Shuban

  • SMF Hero
  • ******
  • Posts: 2,389
    • Free Homework Help
Re: Help me write this code...
« Reply #5 on: March 11, 2012, 09:57:12 PM »
Okay, without developing the code for you, let's see what you have. You say you have the code to be modified narrowed down to the 'link' line of code? Do you have the logic set up to filter by the groups you need? If so, you can set a style class up in the anchor tag and then set the color in your style sheet. Or if you don't mind inline styles, just set the color style in your anchor tag.

Hopefully all of this makes sense to you. I don't know what your level of proficiency or understanding is but this is a problem that will require some php, html, and css to synthesize a solution.

I understand what you mean.

No, I don't mind in-line styles at all.

I just want all topics displayed in the message index to show a different color, let's say red, when the original author (topic starter) is in membergroup 15, for instance.

Offline IchBin™

  • SMF Friend
  • SMF Super Hero
  • *
  • Posts: 11,110
  • Gender: Male
  • I don't speak German.
    • IchBin.us
Re: Help me write this code...
« Reply #6 on: March 12, 2012, 01:21:31 PM »
Not as easy as you'd think. You'll need to pull the user's member group based on the ID of the $row['id_first_msg']. Most likely will cost you an additional query. Once you have their groups, then you can do a check to see if their groups match any of the groups you want. If it matches then you just change the 'link' section in the first post to put a style tag in with the color you want.
Brad "IchBin™" Grow        TinyPortal        Themes
Coding Guidelines       

Offline Labradoodle-360

  • SMF Friend
  • SMF Super Hero
  • *
  • Posts: 12,196
  • Gender: Male
    • matthew.kerle on Facebook
    • Labradoodle-360 on GitHub
    • @matthew_kerle on Twitter
Re: Help me write this code...
« Reply #7 on: March 12, 2012, 01:44:19 PM »
As Brad said, for something so small and minor, it's really not worth the performance (although you wouldn't notice it, it's still there).
Former SMF Developer
My Modifications

Offline Shuban

  • SMF Hero
  • ******
  • Posts: 2,389
    • Free Homework Help
Re: Help me write this code...
« Reply #8 on: March 12, 2012, 02:10:34 PM »
As Brad said, for something so small and minor, it's really not worth the performance (although you wouldn't notice it, it's still there).

I still would like this done, can anyone help.

Offline Labradoodle-360

  • SMF Friend
  • SMF Super Hero
  • *
  • Posts: 12,196
  • Gender: Male
    • matthew.kerle on Facebook
    • Labradoodle-360 on GitHub
    • @matthew_kerle on Twitter
Re: Help me write this code...
« Reply #9 on: March 12, 2012, 02:11:10 PM »
IchBin did. He told you exactly what you need to do.
Former SMF Developer
My Modifications

Offline Shuban

  • SMF Hero
  • ******
  • Posts: 2,389
    • Free Homework Help
Re: Help me write this code...
« Reply #10 on: March 12, 2012, 02:32:17 PM »
IchBin did. He told you exactly what you need to do.

I understand what he means, but I don't know how to put it together. I'm really not a computer programmer.

Offline IchBin™

  • SMF Friend
  • SMF Super Hero
  • *
  • Posts: 11,110
  • Gender: Male
  • I don't speak German.
    • IchBin.us
Re: Help me write this code...
« Reply #11 on: March 12, 2012, 03:07:52 PM »
Don't be afraid to try Liam_michael. You'll never learn if you don't. If you get stuck you post your code and people can show you how to fix things.

Code: (add above the code you posted) [Select]
$myquery = $smcFunc['db_query']('', '
SELECT id_group
FROM {db_prefix}members
WHERE id_member = {int:id_mem}',
array('id_mem' => $row['first_id_member'])
);
$style = '';
$mygroups = array(1,3);
$groups = array();
while($row2 = $smcFunc['db_fetch_row']($myquery))
$groups[] = $row2[0];

if(array_intersect($groups, $mygroups))
$style = 'style="color: red;"';

You can of course change the style color to be anything you want.

Code: (Find in your code) [Select]
'link' => '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.0">' . $row['first_subject'] . '</a>'

Code: (Replace with this) [Select]
'link' => '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.0" ' . $style . '>' . $row['first_subject'] . '</a>'
Brad "IchBin™" Grow        TinyPortal        Themes
Coding Guidelines       

Offline Labradoodle-360

  • SMF Friend
  • SMF Super Hero
  • *
  • Posts: 12,196
  • Gender: Male
    • matthew.kerle on Facebook
    • Labradoodle-360 on GitHub
    • @matthew_kerle on Twitter
Re: Help me write this code...
« Reply #12 on: March 12, 2012, 03:46:26 PM »
He's not using SMF 2.0 as he said above, so the code would have to utilize db_query() rather than $smcFunc, and mysql_fetch_assoc() rather than $smcFunc['db_fetch_assoc']().

Furthermore, it may be more simple to use loadMemberData and loadMemberContext in this scenario.
Former SMF Developer
My Modifications

Offline Shuban

  • SMF Hero
  • ******
  • Posts: 2,389
    • Free Homework Help
Re: Help me write this code...
« Reply #13 on: March 12, 2012, 04:12:21 PM »
Don't be afraid to try Liam_michael. You'll never learn if you don't. If you get stuck you post your code and people can show you how to fix things.

Thanks for the encouragement, IchBin™. It's just that my knowledge in php is *very* limited. I know how to create simple arguments, but that's just it. I tried your code and I forgot to mention it's for 1.x.

Offline IchBin™

  • SMF Friend
  • SMF Super Hero
  • *
  • Posts: 11,110
  • Gender: Male
  • I don't speak German.
    • IchBin.us
Re: Help me write this code...
« Reply #14 on: March 12, 2012, 04:28:41 PM »
There's no need to use loadMemberData() when all your doing is grabbing the groups. You'll be pulling in much more information than you need.

Code change for SMF 1.1.x
Code: [Select]
$myquery = db_query("
SELECT id_group
FROM {$db_prefix}members
WHERE id_member = ". $row['first_id_member'],  __FILE__, __LINE__);

$style = '';
$mygroups = array(1,3);
$groups = array();
while($row2 = mysql_fetch_row($myquery))
$groups[] = $row2[0];

if(array_intersect($groups, $mygroups))
$style = 'style="color: red;"';

Code: [Select]
'link' => '<a href="' . $scripturl . '?topic=' . $row['ID_TOPIC'] . '.0" ' . $style . '>' . $row['firstSubject'] . '</a>'
« Last Edit: March 12, 2012, 04:44:31 PM by IchBin™ »
Brad "IchBin™" Grow        TinyPortal        Themes
Coding Guidelines       

Offline Labradoodle-360

  • SMF Friend
  • SMF Super Hero
  • *
  • Posts: 12,196
  • Gender: Male
    • matthew.kerle on Facebook
    • Labradoodle-360 on GitHub
    • @matthew_kerle on Twitter
Re: Help me write this code...
« Reply #15 on: March 12, 2012, 04:40:12 PM »
Forgot something that's supposed to be at the end of 1.1x queries.
Code: [Select]
, __FILE__, __LINE__Usage:
Code: [Select]
$myquery = db_query("
SELECT id_group
FROM {$db_prefix}members
WHERE id_member = ". $row['first_id_member'], __FILE__, __LINE__
);
Former SMF Developer
My Modifications

Offline IchBin™

  • SMF Friend
  • SMF Super Hero
  • *
  • Posts: 11,110
  • Gender: Male
  • I don't speak German.
    • IchBin.us
Re: Help me write this code...
« Reply #16 on: March 12, 2012, 04:44:43 PM »
Thanks, forgot about that. UPdated the post.
Brad "IchBin™" Grow        TinyPortal        Themes
Coding Guidelines       

Offline Labradoodle-360

  • SMF Friend
  • SMF Super Hero
  • *
  • Posts: 12,196
  • Gender: Male
    • matthew.kerle on Facebook
    • Labradoodle-360 on GitHub
    • @matthew_kerle on Twitter
Re: Help me write this code...
« Reply #17 on: March 12, 2012, 04:47:18 PM »
No problem...I don't even think it really matters, I think it's more for recording the queries.
Former SMF Developer
My Modifications

Offline Shuban

  • SMF Hero
  • ******
  • Posts: 2,389
    • Free Homework Help
Re: Help me write this code...
« Reply #18 on: March 12, 2012, 05:17:50 PM »
Thanks guys, this next question stems from my poor php understanding... Where exactly do I place this code in messageindex.php?:

Code: [Select]
$myquery = db_query("
SELECT id_group
FROM {$db_prefix}members
WHERE id_member = ". $row['firstID_MEMBER'],  __FILE__, __LINE__);

$style = '';
$mygroups = array(1,3);
$groups = array();
while($row2 = mysql_fetch_row($myquery))
$groups[] = $row2[0];

if(array_intersect($groups, $mygroups))
$style = 'style="color: red;"';

I've attached my messageindex.php file for reference.

Offline Labradoodle-360

  • SMF Friend
  • SMF Super Hero
  • *
  • Posts: 12,196
  • Gender: Male
    • matthew.kerle on Facebook
    • Labradoodle-360 on GitHub
    • @matthew_kerle on Twitter
Re: Help me write this code...
« Reply #19 on: March 12, 2012, 05:21:02 PM »
You have to add it above the other code you need to modify.
Code: [Select]
// 'Print' the topic info.
$context['topics'][$row['ID_TOPIC']] = array(
Former SMF Developer
My Modifications