Skip to content

Commit bc968d2

Browse files
authored
Add files via upload
1 parent 77a0c44 commit bc968d2

File tree

1 file changed

+119
-83
lines changed

1 file changed

+119
-83
lines changed

accordion.inc.php

Lines changed: 119 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?php
2-
// $Id: accordion.inc.php,v 1.3 2020/12/01 23:20:41 K Exp $
2+
// $Id: accordion.inc.php,v 1.4 2021/07/06 00:00:00 K Exp $
33

44
/**
55
* @link http://pkom.ml/?%E3%83%97%E3%83%A9%E3%82%B0%E3%82%A4%E3%83%B3/accordion.inc.php
@@ -9,107 +9,143 @@
99

1010
// region.inc.php(author:xxxxx) https://pukiwiki.osdn.jp/?%E8%87%AA%E4%BD%9C%E3%83%97%E3%83%A9%E3%82%B0%E3%82%A4%E3%83%B3/region.inc.php
1111

12-
function plugin_accordion_convert()
13-
{
14-
static $builder = 0;
15-
if( $builder==0 ) $builder = new AccordionPluginHTMLBuilder();
12+
//-Accordionプラグインの定義
13+
14+
// 見出し(true) or 開くボタン(false) で開閉
15+
define('PLUGIN_ACCORDION_CLICK_HEADER', true);
1616

17-
$builder->setDefaultSettings();
17+
// falseで<head>に、trueで<body>にスタイルの要素を生成します
18+
define('PLUGIN_ACCORDION_COMPATIBILITY_STYLE', false);
1819

20+
// スタイルシートの定義
21+
define('PLUGIN_ACCORDION_STYLE',
22+
<<<EOD
23+
#acd_btn {
24+
cursor:pointer;
25+
}
26+
#acd_btn span {
27+
cursor:pointer;
28+
font-family: "MS Pゴシック", "MS PGothic", "ヒラギノ角ゴ Pro W3","Hiragino Kaku Gothic Pro", Osaka, arial, verdana, sans-serif;
29+
padding:1px 4px;
30+
border:gray 1px solid;
31+
color:gray;
32+
}
33+
EOD);
34+
35+
function plugin_accordion_convert() {
36+
static $builder = 0;
37+
if ($builder == 0) $builder = new AccordionPlugin();
38+
$builder -> setDefaultSettings();
1939
if (func_num_args() >= 3){
2040
$args = func_get_args();
21-
$builder->setDescription( array_shift($args) );
22-
$builder->setHeading( array_shift($args) );
41+
$builder -> setDescription( array_shift($args) );
42+
$builder -> setHeading( array_shift($args) );
2343
foreach( $args as $value ){
24-
if( preg_match("/^open/i", $value) ){
25-
$builder->setOpened();
26-
}elseif( preg_match("/^close/i", $value) ){
27-
$builder->setClosed();
44+
if( preg_match("/^open/i", $value) ) {
45+
$builder -> setOpened();
46+
continue;
47+
}
48+
if( preg_match("/^close/i", $value) ) {
49+
$builder -> setClosed();
50+
continue;
2851
}
2952
}
3053
}
31-
$args = func_get_args();
32-
$contents1 = $args[func_num_args()-1];
33-
$contents1 = preg_replace("/\r\n|\r/", "\n", $contents1);
34-
$contents1 = explode("\n",$contents1);
35-
36-
return $builder->build()
37-
.convert_html($contents1)
38-
.<<<EOD
39-
</td></tr></table>
40-
EOD;
54+
$args = func_get_args();
55+
$contents = $args[func_num_args()-1];
56+
$contents = preg_replace("/\r\n|\r/", "\n", $contents);
57+
$contents = explode("\n", $contents);
58+
return $builder -> build()
59+
.convert_html($contents)
60+
.'</td></tr></table>';
4161
}
4262

43-
class AccordionPluginHTMLBuilder
44-
{
45-
var $description;
46-
var $heading;
47-
var $isopened;
48-
var $scriptVarName;
49-
var $callcount;
63+
class AccordionPlugin {
64+
private $description;
65+
private $heading;
66+
private $isOpened;
67+
private $scriptVarName;
68+
private $callCount;
69+
70+
public function __construct() {
71+
$this -> callCount = 0;
72+
$this -> setDefaultSettings();
73+
}
5074

51-
function AccordionPluginHTMLBuilder() {
52-
$this->callcount = 0;
53-
$this->setDefaultSettings();
75+
public function setDefaultSettings() {
76+
$this -> description = "...";
77+
$this -> heading = "h2";
78+
$this -> isOpened = false;
5479
}
55-
function setDefaultSettings(){
56-
$this->description = "...";
57-
$this->heading = "h2";
58-
$this->isopened = false;
80+
81+
public function setClosed() { $this -> isOpened = false; }
82+
public function setOpened() { $this -> isOpened = true; }
83+
84+
public function setDescription($description) {
85+
$this -> description = convert_html($description);
86+
$this -> description = preg_replace( "/^<p>/i", "", $this -> description);
87+
$this -> description = preg_replace( "/<\/p>$/i", "", $this -> description);
5988
}
60-
function setClosed(){ $this->isopened = false; }
61-
function setOpened(){ $this->isopened = true; }
62-
function setDescription($description){
63-
$this->description = convert_html($description);
64-
$this->description = preg_replace( "/^<p>/i", "", $this->description);
65-
$this->description = preg_replace( "/<\/p>$/i", "", $this->description);
89+
90+
public function setHeading($heading) {
91+
if (($heading == "1" ) || ( $heading == "*")) $this -> heading = "h2";
92+
if (($heading == "2" ) || ( $heading == "**")) $this -> heading = "h3";
93+
if (($heading == "3" ) || ( $heading == "***")) $this -> heading = "h4";
94+
if (($heading == "4" ) || ( $heading == "****")) $this -> heading = "h5";
6695
}
67-
function setHeading($heading){
68-
if ($heading == "1"){$this->heading = "h2";}
69-
else if ($heading == "2"){$this->heading = "h3";}
70-
else if ($heading == "3"){$this->heading = "h4";}
71-
else if ($heading == "4"){$this->heading = "h5";}
72-
}
73-
function build(){
74-
$this->callcount++;
96+
97+
public function build() {
98+
$this -> callCount++;
7599
$html = array();
76-
array_push( $html, $this->buildButtonHtml() );
77-
array_push( $html, $this->buildContentHtml() );
100+
if ($this -> callCount <= 1){
101+
$style = "<style>\n" . PLUGIN_ACCORDION_STYLE . "\n</style>\n";
102+
if (PLUGIN_ACCORDION_COMPATIBILITY_STYLE) {
103+
array_push($html, $style);
104+
} else {
105+
global $head_tags;
106+
$head_tags[] .= $style;
107+
}
108+
}
109+
array_push( $html, $this -> buildButtonHtml() );
110+
array_push( $html, $this -> buildContentHtml() );
78111
return join($html);
79112
}
80113

81-
function buildButtonHtml(){
82-
$button = ($this->isopened) ? "-" : "+";
83-
//white style
84-
//cursor:pointer;font-family: "MS Pゴシック", "MS PGothic", "ヒラギノ角ゴ Pro W3","Hiragino Kaku Gothic Pro", Osaka, arial, verdana, sans-serif;padding:1px 4px;border:gray 1px solid;border-radius:3px;background-color:white;color:gray
85-
86-
//black style
87-
//cursor:pointer;font-family: "MS Pゴシック", "MS PGothic", "ヒラギノ角ゴ Pro W3","Hiragino Kaku Gothic Pro", Osaka, arial, verdana, sans-serif;padding:1px 4px;border:black 1px solid;border-radius:3px;background-color:black;color:white
88-
89-
//default style
90-
//cursor:pointer;font-family: "MS Pゴシック", "MS PGothic", "ヒラギノ角ゴ Pro W3","Hiragino Kaku Gothic Pro", Osaka, arial, verdana, sans-serif;padding:1px 4px;border:gray 1px solid;color:gray;
114+
private function buildButtonHtml() {
115+
$button = ($this -> isOpened) ? "-" : "+";
116+
117+
$onClick = <<<EOD
118+
onclick="
119+
if(document.getElementById('acd_content{$this -> callCount}').style.display!='inline'){
120+
document.getElementById('acd_content{$this -> callCount}').style.display='inline';
121+
document.getElementById('acd_button{$this -> callCount}').innerHTML='-';
122+
}else{
123+
document.getElementById('acd_content{$this -> callCount}').style.display='none';
124+
document.getElementById('acd_button{$this -> callCount}').innerHTML='+';
125+
}
126+
"
127+
EOD;
128+
129+
$onHeaderClick = "";
130+
$onSpanClick = "";
131+
if (PLUGIN_ACCORDION_CLICK_HEADER) {
132+
$onHeaderClick = $onClick;
133+
} else {
134+
$onSpanClick = $onClick;
135+
EOD;
136+
}
91137
return <<<EOD
92-
93-
<{$this->heading}><span id=acd_button$this->callcount style='cursor:pointer;font-family: "MS Pゴシック", "MS PGothic", "ヒラギノ角ゴ Pro W3","Hiragino Kaku Gothic Pro", Osaka, arial, verdana, sans-serif;padding:1px 4px;border:gray 1px solid;color:gray;'
94-
onclick="
95-
if(document.getElementById('acd_content$this->callcount').style.display!='inline'){
96-
document.getElementById('acd_content$this->callcount').style.display='inline';
97-
document.getElementById('acd_button$this->callcount').innerHTML='-';
98-
}else{
99-
document.getElementById('acd_content$this->callcount').style.display='none';
100-
document.getElementById('acd_button$this->callcount').innerHTML='+';
101-
}
102-
">$button</span>&nbsp;$this->description</{$this->heading}>
103-
<table><tr>
104-
EOD;
138+
<{$this -> heading} id="acd_btn" $onHeaderClick>
139+
<span id=acd_button{$this -> callCount} $onSpanClick>$button</span>&nbsp;{$this -> description}
140+
</{$this -> heading}>
141+
<table><tr>
142+
EOD;
105143
}
106-
function buildContentHtml(){
107-
$contentstyle = ($this->isopened) ? "display:block;" : "display:none;";
144+
145+
private function buildContentHtml() {
146+
$contentStyle = ($this -> isOpened) ? "display:inline;" : "display:none;";
108147
return <<<EOD
109-
<td id=acd_content$this->callcount style="{$contentstyle}">
110-
EOD;
148+
<td id=acd_content{$this -> callCount} style="{$contentStyle}">
149+
EOD;
111150
}
112-
113-
}// end class RegionPluginHTMLBuilder
114-
115-
?>
151+
}

0 commit comments

Comments
 (0)