setDefaultSettings();
if (func_num_args() >= 3){
$args = func_get_args();
$builder -> setDescription( array_shift($args) );
$builder -> setHeading( array_shift($args) );
foreach( $args as $value ){
if( preg_match("/^open/i", $value) ) {
$builder -> setOpened();
continue;
}
if( preg_match("/^close/i", $value) ) {
$builder -> setClosed();
continue;
}
}
}
$args = func_get_args();
$contents = $args[func_num_args()-1];
$contents = preg_replace("/\r\n|\r/", "\n", $contents);
$contents = explode("\n", $contents);
return $builder -> build()
.convert_html($contents)
.(PLUGIN_ACCORDION_DISPLAY ? '' : '');
}
class AccordionPlugin {
private $description;
private $heading;
private $isOpened;
private $scriptVarName;
private $callCount;
private $display;
public function __construct() {
$this -> callCount = 0;
$this -> setDefaultSettings();
}
public function setDefaultSettings() {
$this -> description = "...";
$this -> heading = "h2";
$this -> isOpened = false;
$this -> display = PLUGIN_ACCORDION_DISPLAY ? $display = "block" : $display = "inline";
}
public function setClosed() { $this -> isOpened = false; }
public function setOpened() { $this -> isOpened = true; }
public function setDescription($description) {
$this -> description = convert_html($description);
$this -> description = preg_replace( "/^/i", "", $this -> description);
$this -> description = preg_replace( "/<\/p>$/i", "", $this -> description);
}
public function setHeading($heading) {
if ($heading == "1" || !(strcmp($heading,"*"))) $this -> heading = "h2";
if ($heading == "2" || !(strcmp($heading,"**"))) $this -> heading = "h3";
if ($heading == "3" || !(strcmp($heading,"***"))) $this -> heading = "h4";
if ($heading == "4" || !(strcmp($heading,"****"))) $this -> heading = "h5";
}
public function build() {
$this -> callCount++;
$html = array();
if ($this -> callCount <= 1){
$style = "\n";
if (PLUGIN_ACCORDION_COMPATIBILITY_STYLE) {
array_push($html, $style);
} else {
global $head_tags;
$head_tags[] .= $style;
}
}
array_push( $html, $this -> buildButtonHtml() );
array_push( $html, $this -> buildContentHtml() );
return join($html);
}
private function buildButtonHtml() {
$button = ($this -> isOpened) ? "-" : "+";
$onClick = <<";
return << heading} class="acd_btn" $onHeaderClick>
callCount} $onSpanClick>$button {$this -> description}
{$this -> heading}>
{$startTag}
EOD;
}
private function buildContentHtml() {
$startTag = PLUGIN_ACCORDION_DISPLAY ? "div" : "td";
$contentStyle = ($this -> isOpened) ? "display:{$this -> display};" : "display:none;";
return << callCount} style="{$contentStyle}">
EOD;
}
}