src/Common.php
public function accordion($class, array $sections, $open = 1)
    {
        $html = '';
        $count = 0;
        $id = $this->page->id('accordion');
        foreach ($sections as $head => $body) {
            ++$count;
            $heading = $this->page->id('heading');
            $collapse = $this->page->id('collapse');
            $in = ($open == $count) ? ' in' : '';
            $attributes = array(
                'role' => 'button',
                'data-toggle' => 'collapse',
                'data-parent' => '#'.$id,
                'href' => '#'.$collapse,
                'aria-expanded' => !empty($in) ? 'true' : 'false',
                'aria-controls' => $collapse,
            );
            $begin = strpos($head, '>') + 1;
            $end = strrpos($head, '</');
            $head = substr($head, 0, $begin).$this->page->tag('a', $attributes, substr($head, $begin, $end - $begin)).substr($head, $end);
            $head = substr($this->panel($class, array('head' => $head)), 0, -6); // </div>
            $html .= substr_replace($head, ' role="tab" id="'.$heading.'"', strpos($head, 'class="panel-heading"') + 21, 0);
            $html .= $this->page->tag('div', array(
                    'id' => $collapse,
                    'class' => 'panel-collapse collapse'.$in,
                    'role' => 'tabpanel',
                    'aria-labelledby' => $heading,
                ), strpos($body, 'class="list-group"') ? $body : '<div class="panel-body">'.$body.'</div>');
            $html .= '</div>'; // the one we removed from the $head up top
        }

        return $this->page->tag('div', array(
            'class' => 'panel-group',
            'id' => $id,
            'role' => 'tablist',
            'aria-multiselectable' => 'true',
        ), $html);
    }
public function accordion($class, array $sections, $open = 1)
    {
        $html = '';
        $count = 0;
        $id = $this->page->id('accordion');
        foreach ($sections as $head => $body) {
            ++$count;
            $heading = $this->page->id('heading');
            $collapse = $this->page->id('collapse');
            $in = ($open == $count) ? ' in' : '';
            $attributes = array(
                'role' => 'button',
                'data-toggle' => 'collapse',
                'data-parent' => '#'.$id,
                'href' => '#'.$collapse,
                'aria-expanded' => !empty($in) ? 'true' : 'false',
                'aria-controls' => $collapse,
            );
            $begin = strpos($head, '>') + 1;
            $end = strrpos($head, '</');
            $head = substr($head, 0, $begin).$this->page->tag('a', $attributes, substr($head, $begin, $end - $begin)).substr($head, $end);
            $head = substr($this->panel($class, array('head' => $head)), 0, -6); // </div>
            $html .= substr_replace($head, ' role="tab" id="'.$heading.'"', strpos($head, 'class="panel-heading"') + 21, 0);
            $html .= $this->page->tag('div', array(
                    'id' => $collapse,
                    'class' => 'panel-collapse collapse'.$in,
                    'role' => 'tabpanel',
                    'aria-labelledby' => $heading,
                ), strpos($body, 'class="list-group"') ? $body : '<div class="panel-body">'.$body.'</div>');
            $html .= '</div>'; // the one we removed from the $head up top
        }

        return $this->page->tag('div', array(
            'class' => 'panel-group',
            'id' => $id,
            'role' => 'tablist',
            'aria-multiselectable' => 'true',
        ), $html);
    }
public function accordion ( $ class , array $ sections , $ open = 1 ) { $ html = '' ; $ count = 0 ; $ id = $ this -> page -> id ( 'accordion' ) ; foreach ( $ sections as $ head => $ body ) { ++ $ count ; $ heading = $ this -> page -> id ( 'heading' ) ; $ collapse = $ this -> page -> id ( 'collapse' ) ; $ in = ( $ open == $ count ) ? ' in' : '' ; $ attributes = array ( 'role' => 'button' , 'data-toggle' => 'collapse' , 'data-parent' => '#' . $ id , 'href' => '#' . $ collapse , 'aria-expanded' => ! empty ( $ in ) ? 'true' : 'false' , 'aria-controls' => $ collapse , ) ; $ begin = strpos ( $ head , '>' ) + 1 ; $ end = strrpos ( $ head , '</' ) ; $ head = substr ( $ head , 0 , $ begin ) . $ this -> page -> tag ( 'a' , $ attributes , substr ( $ head , $ begin , $ end - $ begin ) ) . substr ( $ head , $ end ) ; $ head = substr ( $ this -> panel ( $ class , array ( 'head' => $ head ) ) , 0 , - 6 ) ; // </div> $ html .= substr_replace ( $ head , ' role="tab" id="' . $ heading . '"' , strpos ( $ head , 'class="panel-heading"' ) + 21 , 0 ) ; $ html .= $ this -> page -> tag ( 'div' , array ( 'id' => $ collapse , 'class' => 'panel-collapse collapse' . $ in , 'role' => 'tabpanel' , 'aria-labelledby' => $ heading , ) , strpos ( $ body , 'class="list-group"' ) ? $ body : '<div class="panel-body">' . $ body . '</div>' ) ; $ html .= '</div>' ; // the one we removed from the $head up top } return $ this -> page -> tag ( 'div' , array ( 'class' => 'panel-group' , 'id' => $ id , 'role' => 'tablist' , 'aria-multiselectable' => 'true' , ) , $ html ) ; }
Bootstrap accordions are basically collapsible panels. That is essentially what you are creating here.

@param string $class    Either '**default**', '**primary**', '**success**', '**info**', '**warning**', or '**danger**'. These only apply to the head section, and are passed directly by us into ``$bp->panel()``.
@param array  $sections An ``array($heading => $body, ...)`` of sections that will become your accordion. The ``<h1-6>`` headers in the **$heading** will be automatically classed appropriately. Accordions are definitely nestable, but we don't create them via nested arrays through this method. Just add a pre-made accordion to the **$body** you would like it to reside in ie. the **$body** should never be an array.
@param int    $open     This is the panel number you would like be open from the get-go (starting at 1). If you don't want any panel to be opened initially, then set this to 0.

@return string

@example

```php
echo $bp->accordion('info', array(
'<h4>Group Item #1</h4>' => 'One',
'<h4>Group Item #2</h4>' => 'Two',
'<h4>Group Item #3</h4>' => 'Three',
), 2);
```
Bootstrap accordions are basically collapsible panels . That is essentially what you are creating here .