Support Forum

'iconUnread' in Group View when custom Icon used for forum Icons

CF Conrad_Farlow
Conrad_Farlow
Member

I am using a custom Icon for the forums and I have created another Icon with an indicator to show that there are unread posts in that forum when in group view.

I have used the iconUnread facility in forum view with no problems and copied what I did into spGroupView.php but to no avail.

Here’s the code from the relevant section of the sp-group-view-functions.php file. Why is my alternate icon not being displayed? I figure it may have something to do with the first if statement but question

function sp_ForumIndexIcon($args='') {

    global $spThisForum;

    $defs = array('tagId'         => 'spForumIndexIcon%ID%',

                  'tagClass'     => 'spRowIcon',

                  'icon'         => 'sp_ForumIcon.png',

                  'iconUnread'    => 'sp_ForumIcon_new_post.png',

                  'echo'        => 1,

                  'get'            => 0,

                  );

    $a = wp_parse_args($args, $defs);

    $a = apply_filters('sph_ForumIndexIcon_args', $a);

    extract($a, EXTR_SKIP);



    # sanitize before use

    $tagId        = esc_attr($tagId);

    $tagClass    = esc_attr($tagClass);

    $echo        = (int) $echo;

    $get        = (int) $get;



    $tagId = str_ireplace('%ID%', $spThisForum->forum_id, $tagId);



    # Check if a custom icon

    if (!empty($spThisForum->forum_icon)) {

        $icon = SFCUSTOMURL.$spThisForum->forum_icon;

        

    } else {

        if ($spThisForum->unread) $icon = $iconUnread;

        $icon = SPTHEMEICONS.sanitize_file_name($icon);

    }



    if ($get) return $icon;



    $out = "<img id='$tagId' class='$tagClass' src='$icon' alt='' />n";

    $out = apply_filters('sph_ForumIndexIcon', $out, $a);



    if ($echo) {

        echo $out;

    } else {

        return $out;

    }

Of course the icon is in the theme images folder, the custom icon is still displayed for the forum.

24 Answers

New Answer

MP Mr Papa
Mr Papa
Member

you said you have custom icons…  the code above first checks for that and uses it if it exists… so your check never occurs…

CF Conrad_Farlow
Conrad_Farlow
Member

Ah I see it now, the code below works and will insert an icon when there are unread posts whether you have a custom forum icon or not. 

I don’t know if it’s a good way of doing it or not but if there is a better way I’d like to know it.

    if ($spThisForum->unread) {
        $icon = $iconUnread;
        $icon = SPTHEMEICONS.sanitize_file_name($icon);
    }
    else if (!empty($spThisForum->forum_icon)) {
        $icon = SFCUSTOMURL.$spThisForum->forum_icon;
    }
    else {
        $icon = SPTHEMEICONS.sanitize_file_name($icon);
    }
    
    if ($get) {
        return $icon;
YS Yellow Swordfish
Yellow Swordfish
Member

Yes – the way things stand at the moment if you have a custom icon set then the same one will be used in all circumstances.

This is a much bigger change than just adding something to a theme template as it would mean a change to the database tables for groups and forums, and changes to the create/edit forum and group forms in the admin so that two custom icons could be applied to items instead of one.

I am not saying it wont happen but it is beyond the scope of V5.0 now in RC. We will revisit though for a future change.

CF Conrad_Farlow
Conrad_Farlow
Member

I’m quite happy to just have it in group view for now Andy. In fact I get so myopic that I’d never even considered other scenarios where I might need it.

Group view was the main one, just to make it consistent with forum view.

I’d better start writing some of this stuff down embarassed

YS Yellow Swordfish
Yellow Swordfish
Member

Which should be in last nights update I believe.

CF Conrad_Farlow
Conrad_Farlow
Member

I broke this when I did an svn up. Am I now able to do this in the theme instead of changing the core like I did last time?

Conrad

CF Conrad_Farlow
Conrad_Farlow
Member

Forget that I just found the huge thread all about it embarassed

YS Yellow Swordfish
Yellow Swordfish
Member

It should have been done in the theme from when when introduced it. Once in the function code – it is available to the theme…

PR Propheticus
Propheticus
Member

In your code I see: $icon = SPTHEMEICONS.sanitize_file_name($icon);

The SPTHEMEICONS constant no longer exists. You should replace it with SPTHEMEICONSURL and see if that helps.

CF Conrad_Farlow
Conrad_Farlow
Member

Yes I saw your post on the other thread and if you look there I have corrected it. Thanks for the heads up, I would have been scratching my head for a while without it.

Conrad

MP Mr Papa
Mr Papa
Member

until we release final, may still be few of those tweaks… should check the changelong on each update…

CF Conrad_Farlow
Conrad_Farlow
Member

I’ve been reading bug tracker, it’s a good way of realising just how much work is going on behind the scenes. I only became aware of the changelog in the last few daysembarassed

If I’d found it sooner I suspect that you’d have had a few less questions, but maybe the questions aren’t a bad thing in the scheme of things.

Conrad

YS Yellow Swordfish
Yellow Swordfish
Member

The change log has only been in place for the last two updates.
One of the nice things is that when you know there is an update available you will be able to look at the changelog to see what is in it before upgrading.

CF Conrad_Farlow
Conrad_Farlow
Member

So does this still have to be done in sp-group-view-functions.php or can I now achieve the same thing in my theme spGroupView.php?

If so how?

 

Conrad