setDefaultSettings(); // 引数が指定されているようなので解析 if (func_num_args() >= 1){ $args = func_get_args(); $builder->setDescription( array_shift($args) ); foreach( $args as $value ){ // opened が指定されたら初期表示は開いた状態に設定 if( preg_match("/^open/i", $value) ){ $builder->setOpened(); // closed が指定されたら初期表示は閉じた状態に設定。 }elseif( preg_match("/^close/i", $value) ){ $builder->setClosed(); } } } // HTML返却 return $builder->build(); } // クラスの作り方⇒http://php.s3.to/man/language.oop.object-comparison-php4.html class RegionPluginHTMLBuilder { var $description; var $isopened; var $scriptVarName; //↓ buildメソッドを呼んだ回数をカウントする。 //↓ これは、このプラグインが生成するJavaScript内でユニークな変数名(被らない変数名)を生成するために使います var $callcount; function RegionPluginHTMLBuilder() { $this->__construct; } function __construct() { $this->callcount = 0; $this->setDefaultSettings(); } function setDefaultSettings(){ $this->description = "..."; $this->isopened = false; } function setClosed(){ $this->isopened = false; } function setOpened(){ $this->isopened = true; } // convert_html()を使って、概要の部分にブランケットネームを使えるように改良。 function setDescription($description){ $this->description = convert_html($description); // convert_htmlを使うと
タグで囲まれてしまう。Mozzilaだと表示がずれるので
タグを消す。 $this->description = preg_replace( "/^
/i", "", $this->description);
		$this->description = preg_replace( "/<\/p>$/i", "", $this->description);
	}
	function build(){
		$this->callcount++;
		$html = array();
		// 以降、HTML作成処理
		array_push( $html, $this->buildButtonHtml() );
		array_push( $html, $this->buildBracketHtml() );
		array_push( $html, $this->buildSummaryHtml() );
		array_push( $html, $this->buildContentHtml() );
		return join($html);
	}
	// ■ ボタンの部分。
	function buildButtonHtml(){
		$button = ($this->isopened) ? "-" : "+";
		// JavaScriptでsummaryrgn1、contentrgn1などといった感じのユニークな変数名を使用。かぶったら一巻の終わりです。万事休す。id指定せずオブジェクト取れるような、なんかよい方法があればいいんだけど。
		return <<
 
	
 
EOD;
	}
	// ■ 展開したときの左側の囲いの部分。こんなやつ ⇒ [ 。 ボーダーで上下左をsolid。右側だけnoneにして [ に見せかける。
	function buildBracketHtml(){
		$bracketstyle = ($this->isopened) ? "border-style: solid none solid solid;" : "border-style:none;";
		return <<の閉じタグは endregion 側にある。
	function buildContentHtml(){
		$contentstyle = ($this->isopened) ? "display:block;" : "display:none;";
		return <<