region2.inc.php

サマリregionプラグインのマルチライン版
リビジョン1.4
対応バージョン1.5.x
投稿者K
投稿日2020-12-05 (土) 14:51:34

概要

region.inc.phpのマルチライン版

使い方

書式

#region2(折りたたみ){{
折りたたむ文字列など
}}

ダウンロード

予め、PKWKEXP_DISABLE_MULTILINE_PLUGIN_HACKを0にしてください。

PukiWiki本体のpluginフォルダに以下のコードをコピーしてregion2.inc.phpとして保存するか、上記のURLの「ダウンロードはこちら」からダウンロードし、pluginフォルダに入れてください。

コード

<?php
// $Id: region2.inc.php,v 1.4 2021/07/07 00:00:00 K,xxxxx Exp $

/** 
* @link http&#58;//pkom.ml/?プラグイン/region2.inc.php
* @author K,xxxxx
* @license http&#58;//www.gnu.org/licenses/gpl.ja.html GPL
*/

// サマリー(true) or 開くボタン(false) で開閉
define('PLUGIN_REGION2_CLICK_SUMMARY', false);

// falseで<head>に、trueで<body>にスタイルの要素を生成します
define('PLUGIN_REGION2_COMPATIBILITY_STYLE', false);

// スタイルシートの定義
define('PLUGIN_REGION2_STYLE', 
<<<EOD
.rgn2_btn {
	cursor:pointer;
	font-family: "MS Pゴシック", "MS PGothic", "ヒラギノ角ゴ Pro W3","Hiragino Kaku Gothic Pro", Osaka, arial, verdana, sans-serif;
	padding:3px 6px;
	border:gray 1px solid;
	color:gray;
}
.rgn2_summary {
	color:gray;
	padding:1px 4px;
	border:gray 1px solid;
}
EOD);

function plugin_region2_convert()
{
	static $builder = 0;
	if ($builder == 0) $builder = new Region2Plugin();
	
	$builder -> setDefaultSettings();
	
	if (func_num_args() >= 2) {
		$args = func_get_args();
		$builder -> setDescription( 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)
	.<<<EOD
	</td></tr></table>
	EOD;
}

class Region2Plugin
{
	private $description;
	private $isOpened;
	private $scriptVarName;
	private $callCount;
	
	public function __construct() {
		$this -> callCount = 0;
		$this -> setDefaultSettings();
	}
	
	public function setDefaultSettings() {
		$this -> description = "...";
		$this -> isOpened = false;
	}
	
	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( "/^<p>/i", "", $this -> description);
		$this -> description = preg_replace( "/<\/p>$/i", "", $this -> description);
	}
	
	public function build() {
		$this -> callCount++;
		$html = array();
 		if ($this -> callCount <= 1) {
 			$style = "<style>\n" . PLUGIN_REGION2_STYLE . "\n</style>\n";
 			if (PLUGIN_REGION2_COMPATIBILITY_STYLE) {
 				array_push($html, $style);
 			} else {
 				global $head_tags;
 				$head_tags[] .= $style;
 			}
 		}
		array_push($html, $this -> buildButtonHtml());
		array_push($html, $this -> buildBracketHtml());
		array_push($html, $this -> buildSummaryHtml());
		array_push($html, $this -> buildContentHtml());
		return join($html);
	}

	private function buildButtonHtml() {
		$button = ($this -> isOpened) ? "-" : "+";
		return <<<EOD
		<table cellpadding=1 cellspacing=2><tr>
		<td valign="top">
			<span class="rgn2_btn" id="rgn2_button{$this -> callCount}"
			onclick="
			{$this -> getJavaScriptTag()}
			">$button</span>
		</td>
		EOD;
	}

	private function buildBracketHtml() {
		$bracketStyle = ($this -> isOpened) ? "border-style: solid none solid solid;" : "border-style:none;";
		return <<<EOD
		<td id=rgn2_bracket{$this -> callCount} style="font-size:1pt;border:gray 1px;{$bracketStyle}">&nbsp;</td>
		EOD;
	}

	private function buildSummaryHtml() {
		$summaryStyle = ($this -> isOpened) ? "display:none;" : "display:block;";
		$onClick = PLUGIN_REGION2_CLICK_SUMMARY ? 'onclick="' . $this -> getJavaScriptTag() . '"' : "";
		return <<<EOD
		<td class="rgn2_summary" id=rgn2_summary{$this -> callCount} $onClick style="{$summaryStyle}">{$this -> description}</td>
		EOD;
	}

	private function buildContentHtml() {
		$contentStyle = ($this -> isOpened) ? "display:block;" : "display:none;";
		return <<<EOD
		<td valign="top" id=rgn2_content{$this -> callCount} style="{$contentStyle}">
		EOD;
	}
	
	private function getJavaScriptTag() {
		return <<<EOD
		if(document.getElementById('rgn2_summary{$this -> callCount}').style.display!='none'){
			document.getElementById('rgn2_summary{$this -> callCount}').style.display='none';
			document.getElementById('rgn2_content{$this -> callCount}').style.display='block';
			document.getElementById('rgn2_bracket{$this -> callCount}').style.borderStyle='solid none solid solid';
			document.getElementById('rgn2_button{$this -> callCount}').innerHTML='-';
		}else{
			document.getElementById('rgn2_summary{$this -> callCount}').style.display='block';
			document.getElementById('rgn2_content{$this -> callCount}').style.display='none';
			document.getElementById('rgn2_bracket{$this -> callCount}').style.borderStyle='none';
			document.getElementById('rgn2_button{$this -> callCount}').innerHTML='+';
		}
		EOD;
	}
}

ライセンス

GPLv3

コメント



トップ   編集 凍結 差分 履歴 添付 複製 名前変更 リロード   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS
Last-modified: 2023-11-21 (火) 23:42:13
Site admin: PukiWiki Development Team

PukiWiki 1.5.4+ © 2001-2022 PukiWiki Development Team. Powered by PHP 8.2.12. HTML convert time: 0.427 sec.

SourceForge