Support Forum

Advanced Search
Forum Scope


Match



Forum Options



Minimum search word length is 3 characters - maximum search word length is 84 characters
themes-topic
Able to add ID to sp_SectionStart()?
Avatar
Lee H
Coastal New England (USA)
Member
Free Members
sp_UserOfflineSmall Offline
Sep 12, 2011 - 1:30 pm

So far I can only see how to add a class to sp_SectionStart(). Is there a way to add a ID as well?

I tried to figure out how to via the filters but can't figure out how to without a preg_replace. Could we consider $rowId as a arg available if the switch goes to default? Or even a filter within default?

If not, theme/plugin devs will often have to resort to making divs outside of the api or is this not a concern?

Avatar
Mr Papa
Simi Valley, CA
SP Master
Free Members
sp_UserOfflineSmall Offline
Sep 12, 2011 - 10:03 pm

We do add some IDs for specific page views... but we do not have a general argument for passing an ID...

out of curiosity, since section start is likely used many times on a page, what is the use case for an ID? sure one exists...

but yes, my expectation is that folks will quite often make divs outside of the api...  In fact, if I was writing a theme, unless I specifically need the benefit of a sectionStart, I would just add a standard html div tag...  I fully expect when folks start playing with themes, you will see a lot of non generic php populating the themes... the template files are indeed simply a php file so any php you want to add to control how the theme operates is fair game...  just look at a wp theme template file...  we have gone perhaps a bit overboard with the api to make it easier for some to read and follow... but as I said, I would expect the hardcore coders and themers to revert to php...

that said, I can chat with Andy about some IDs... the biggest issue will be that each ID will have to be unique in order to validate and we wont put that kind of checking into the api...

Avatar
Lee H
Coastal New England (USA)
Member
Free Members
sp_UserOfflineSmall Offline
Sep 13, 2011 - 8:39 am

I needed to use a ID to make css targeting more bulletproof in a widget div in the WP sidebar.

Going by the default template as an example, I thought I'd try to stick to the api as much as possible. I like how the section start has the hook with the dynamic name. Freaking clever!

do_action('sph_AfterSectionStart_'.$sectionName, $a);

While on the topic... how about adding one more filter to the function at the end?

    # output section starting div 
    if(!empty($rowId)) $rowId=" id='$rowId'"; 
    $out = "<div class='$tagClass$rowClass'$rowId>\n"; 
 
    if ($echo) { 
        echo $out;

Becoming

    # output section starting div 
    if(!empty($rowId)) $rowId=" id='$rowId'"; 
    $out = "<div class='$tagClass$rowClass'$rowId>\n";
    $out = apply_filters('sph_SectionStart', $out, $sectionName, $a); 
 
    if ($echo) { 
        echo $out;

Would be nice to be able to modify the output. Or eliminate empty divs left behind by rogue plugins that have removed items via hooks 'n filters. (heh, heh)

Of course sp_SectionEnd and the column related ones would need similar filters laugh

Avatar
Yellow Swordfish
Glinton, England
SP Master
sp_UserOfflineSmall Offline
Sep 14, 2011 - 3:13 am

I think we are in agreement here that we would rather not give these sections id's. If nothing else making each of them unique would probably undermine their worth. Having said that...

Steve: One thing we COULD do here is allow for a tagId to be passed as a parameter but define no default. Then we could include a section tagId only if it was explicitly passed. This would allow Lee to assign an id to a section and put the onus on the developer to ensure uniqueness. Any downside to that?

Lee: I don't see any reason why your should not get your filter request.

Steve: If you agree with the filters request and se no problems I may have missed I can get those in.

andy-signature.png
YELLOW
SWORDFISH
Avatar
Mr Papa
Simi Valley, CA
SP Master
Free Members
sp_UserOfflineSmall Offline
Sep 14, 2011 - 8:38 am

good with both...

Avatar
Lee H
Coastal New England (USA)
Member
Free Members
sp_UserOfflineSmall Offline
Sep 14, 2011 - 10:34 am

Thanks guys, it will really help me out. Hopefully someone else will benefit in the future.

Avatar
Yellow Swordfish
Glinton, England
SP Master
sp_UserOfflineSmall Offline
Sep 14, 2011 - 12:54 pm

sp_SectionStart is the difficult one as we already place rowId on all of the pre-set views. So what are you expecting here? That a tagId passed would replace all of those? That would trip most people up as far as if uniqueness goes. Seemed like a good idea last night but I am starting to doubt it.

So - what the expectations?

andy-signature.png
YELLOW
SWORDFISH
Avatar
Lee H
Coastal New England (USA)
Member
Free Members
sp_UserOfflineSmall Offline
Sep 14, 2011 - 3:22 pm

If a user doesn't pass a $sectionName that doesn't match any in the switch, it goes to default and no $rowID is created. So how about if there are no $sectionName matches, and the switch makes it to default, see if $tagID arg is set. If set make that the $rowID. But ONLY do that if $sectionName doesn't match a preset.

Forgive me...  I'm not a explainer how about a example... Note tagID is added as a new arg.

function sp_SectionStart($args='', $sectionName='') { 
    $defs = array('tagClass'     => 'spPlainSection', 
            'echo'        => 1,
            'tagID'        => '', 
                        ); 
    $a = wp_parse_args($args, $defs); 
    $a = apply_filters('sph_SectionStart_args', $a); 
    extract($a, EXTR_SKIP); 
 
    # sanitize before use 
    $tagClass    = esc_attr($tagClass);
    $tagID        = esc_attr($tagID); 
    $echo        = (int) $echo; 
 
    # notifiy custom code before we start the section code 
    do_action('sph_BeforeSectionStart', $sectionName, $a); 
    do_action('sph_BeforeSectionStart_'.$sectionName, $a); 
 
    # specific formatting based on 'defined' names 
    $rowClass = ''; 
    $rowId = ''; 
    switch ($sectionName) { 
        case 'group': 
            global $spGroupView, $spThisGroup; 
 
            $rowClass = ($spGroupView->currentGroup % 2) ? ' spOdd' : ' spEven'; 
 
            $rowId = "group$spThisGroup->group_id"; 
            break; 
 
        case 'subforum': 
        case 'forum': 
            global $spGroupView, $spThisForum; 
 
            $rowClass = ($spGroupView->currentForum % 2) ? ' spOdd' : ' spEven'; 
            if ($spThisForum->forum_status) $rowClass.= ' spLockedForum'; 
 
            $rowId = "forum$spThisForum->forum_id"; 
            break; 
 
        case 'topic': 
            global $spForumView, $spThisTopic; 
            $rowClass = ($spForumView->currentTopic % 2) ? ' spOdd' : ' spEven'; 
            if ($spThisTopic->topic_status) $rowClass.= ' spLockedTopic'; 
            if ($spThisTopic->topic_pinned) $rowClass.= ' spPinnedTopic'; 
 
            $rowId = "topic$spThisTopic->topic_id"; 
            break; 
 
        case 'post': 
            global $spTopicView, $spThisPost; 
            $rowClass = ($spTopicView->currentPost % 2) ? ' spOdd' : ' spEven'; 
            if ($spThisPost->post_pinned) $rowClass.= ' spPinnedPost'; 
            $rowClass.= ' spType-'.$spThisPost->user->usertype; 
            if (!empty($spThisPost->user->rank)) $rowClass.= ' spRank-'.sp_create_slug($spThisPost->user->rank[0]['name'], 'rank', false); 
            if (!empty($spThisPost->user->special_rank)) { 
                foreach ($spThisPost->user->special_rank as $rank) { 
                    $rowClass.= ' spSpecialRank-'.sp_create_slug($rank['name'], 'rank', false); 
                } 
            } 
            if (!empty($spThisPost->user->memberships)) { 
                foreach ($spThisPost->user->memberships as $membership) { 
                    $rowClass.= ' spUsergroup-'.sp_create_slug($membership['usergroup_name'], 'usergroup', false); 
                } 
            } 
            $rowId = "post$spThisPost->post_id"; 
            break; 
 
        case 'list': 
            global $spListView, $spThisListTopic; 
            $rowClass = ($spListView->currentTopic % 2) ? ' spOdd' : ' spEven'; 
            $rowId = "topic$spThisListTopic->topic_id"; 
            break; 
 
        case 'usergroup': 
            global $spMembersList; 
 
            $rowClass = ($spMembersList->currentMemberGroup % 2) ? ' spOdd' : ' spEven'; 
            break; 
 
        case 'member': 
            global $spMembersList; 
 
            $rowClass = ($spMembersList->currentMember % 2) ? ' spOdd' : ' spEven'; 
            break; 
 
        case 'default':
            if(!empty($tagID)) $rowID = $tagID; 
            break; 
    } 
 
    # allow filtering of the row class 
    $rowClass = apply_filters('sph_SectionStartRowClass', $rowClass, $sectionName, $a); 
 
    # output section starting div 
    if(!empty($rowId)) $rowId=" id='$rowId'"; 
    $out = "<div class='$tagClass$rowClass'$rowId>\n"; 
 
    if ($echo) { 
        echo $out; 
 
        # notifiy custom code that section has started 
        # only valid if content is echoed out ($display=1) 
        do_action('sph_AfterSectionStart', $sectionName, $a); 
        do_action('sph_AfterSectionStart_'.$sectionName, $a); 
    } else { 
        return $out; 
    } 
}
Avatar
Yellow Swordfish
Glinton, England
SP Master
sp_UserOfflineSmall Offline
Sep 14, 2011 - 3:55 pm

Good compromise.

andy-signature.png
YELLOW
SWORDFISH
Avatar
Yellow Swordfish
Glinton, England
SP Master
sp_UserOfflineSmall Offline
Sep 14, 2011 - 4:17 pm

And changes committed.

let me know if I missed anything. Or got it wrong of course!

andy-signature.png
YELLOW
SWORDFISH
Forum Timezone: Europe/Stockholm
Most Users Ever Online: 1170
Currently Online:
Guest(s) 1
Currently Browsing this Page:
1 Guest(s)
Top Posters:
Mr Papa: 19448
Ike: 2086
Brandon: 864
kvr28: 804
jim: 650
FidoSysop: 577
Conrad_Farlow: 531
fiddlerman: 358
Stefano Prete: 325
Member Stats:
Guest Posters: 619
Members: 17361
Moderators: 0
Admins: 4
Forum Stats:
Groups: 7
Forums: 17
Topics: 10127
Posts: 79625