From eb5ab4511684a39a46c7a32f81e8c91c2eb76118 Mon Sep 17 00:00:00 2001 From: shizuki Date: Mon, 2 Oct 2006 13:14:13 +0000 Subject: [PATCH] temp git-svn-id: https://svn.sourceforge.jp/svnroot/nucleus-jp/plugin@398 1ca29b6e-896d-4ea0-84a5-967f57386b96 --- trunk/NP_Wikistyle/NP_Wikistyle.php | 161 +++++++++++++++++++++--------------- trunk/NP_Wtable/NP_Wtable.php | 90 +++++++++++--------- 2 files changed, 146 insertions(+), 105 deletions(-) diff --git a/trunk/NP_Wikistyle/NP_Wikistyle.php b/trunk/NP_Wikistyle/NP_Wikistyle.php index d134e4c..d94a60e 100644 --- a/trunk/NP_Wikistyle/NP_Wikistyle.php +++ b/trunk/NP_Wikistyle/NP_Wikistyle.php @@ -1,30 +1,37 @@ ([\r\n])/","$1",$var); } +if (!function_exists('removeBreaks')) { + function removeBreaks($var) + { + return preg_replace("/
([\r\n])/", "$1", $var); + } } class NP_Wikistyle extends NucleusPlugin { - function getName() { // name of plugin + function getName() + { return 'Wikistyle'; } - function getAuthor() { // author of plugin - return 'nakahara21'; + function getAuthor() + { + return 'nakahara21'; } - function getURL() { // an URL to the plugin website - return 'http://xx.nakahara21.net/'; + function getURL() + { + return 'http://nakahara21.com'; } - function getVersion() { // version of the plugin - return '0.5'; + function getVersion() + { + return '0.51'; } - // a description to be shown on the installed plugins listing - function getDescription() { + function getDescription() + { return 'convert WikiTag'; } @@ -37,16 +44,24 @@ class NP_Wikistyle extends NucleusPlugin { } } - function getEventList() { return array('PreItem'); } + function getEventList() + { + return array( + 'PreItem' + ); + } - function event_PreItem(&$data) { - $this->currentItem = &$data["item"]; - $this->convert_wikitag($this->currentItem->body); - if($this->currentItem->more) - $this->convert_wikitag($this->currentItem->more); + function event_PreItem(&$data) + { + $this->currentItem =& $data["item"]; + $this->convert_wikitag($this->currentItem->body); + if ($this->currentItem->more) { + $this->convert_wikitag($this->currentItem->more); + } } - function convert_wikitag(&$text) { + function convert_wikitag(&$text) + { $text = removeBreaks($text); $tmp_lines = explode("\n", $text); $tmp_lines[] = " "; @@ -55,7 +70,7 @@ class NP_Wikistyle extends NucleusPlugin { $templevel = array(); $endline = count($tmp_lines) - 1; - for($i=0;$i<=$endline;$i++){ + for ($i=0;$i<=$endline;$i++) { // $tmp_lines[$i] = trim($tmp_lines[$i]); $level = ''; //__________ @@ -72,97 +87,109 @@ class NP_Wikistyle extends NucleusPlugin { '$this->createLinkCodeWiki("\\1", "\\3","mailto")' ); - if ($level[p] = preg_match('/^(https:\/\/|http:\/\/|www\.|ftp:\/\/|ftp\.|mailto:)/ie',$tmp_lines[$i]) ){ + if ($level[p] = preg_match('/^(https:\/\/|http:\/\/|www\.|ftp:\/\/|ftp\.|mailto:)/ie', $tmp_lines[$i])) { $tmp_lines[$i] = preg_replace($replaceFrom, $replaceTo, $tmp_lines[$i]); - $text .= $tmp_lines[$i]."
"; + $text .= $tmp_lines[$i] . '
'; } //__________ - if (($level[h] = strspn($tmp_lines[$i],'*')) > 6) { + if (($level[h] = strspn($tmp_lines[$i], '*')) > 6) { $level[h] = 6; // limitation ;( } - if($level[h]){ - $tmp_lines[$i] = ltrim(substr($tmp_lines[$i],$level[h])); - $text .= ''.$tmp_lines[$i].''; + if ($level[h]) { + $tmp_lines[$i] = ltrim(substr($tmp_lines[$i], $level[h])); + $text .= '' . $tmp_lines[$i] . ''; } //__________ - if (($level[u] = strspn($tmp_lines[$i],'-')) > 3){ + if (($level[u] = strspn($tmp_lines[$i], '-')) > 3) { $level[r] = 4; $level[u] = 3; // limitation ;( } - if($level[u] && !$level[r]){ - $tmp_lines[$i] = ltrim(substr($tmp_lines[$i],$level[u])); -// $tmp_lines[$i] = '
  • '.$tmp_lines[$i].'
  • '; + if ($level[u] && !$level[r]) { + $tmp_lines[$i] = ltrim(substr($tmp_lines[$i], $level[u])); +// $tmp_lines[$i] = '
  • ' . $tmp_lines[$i] . '
  • '; //_------------- - if($temptoplevel == 'u' && $templevel[o]){ - $tmp_lines[$i] = str_repeat("\n",$templevel[o])."\n".'
  • '.$tmp_lines[$i].'
  • '; + if ($temptoplevel == 'u' && $templevel[o]) { + $tmp_lines[$i] = str_repeat("\n",$templevel[o]) . "\n" . '
  • ' . $tmp_lines[$i] . '
  • '; $templevel[o] = 0; }else{ - $tmp_lines[$i] = '
  • '.$tmp_lines[$i].'
  • '; + $tmp_lines[$i] = '
  • ' . $tmp_lines[$i] . '
  • '; } //_------------- $difflevel = $level[u] - $templevel[u]; - if($difflevel < 0) - $text .= str_repeat("\n",0-$difflevel); - if( $difflevel > 0) - $text .= str_repeat("\n", 0 - $difflevel); + } + if ( $difflevel > 0) { + $text .= str_repeat("\n",$templevel[u])."\n".'
  • '.$tmp_lines[$i].'
  • '; + if ($temptoplevel == 'o' && $templevel[u]) { + $tmp_lines[$i] = str_repeat("\n", $templevel[u]) . "\n" . '
  • ' . $tmp_lines[$i] . '
  • '; $templevel[u] = 0; - }else{ - $tmp_lines[$i] = '
  • '.$tmp_lines[$i].'
  • '; + } else { + $tmp_lines[$i] = '
  • ' . $tmp_lines[$i] . '
  • '; } //_------------- $difflevel = $level[o] - $templevel[o]; - if($difflevel < 0) - $text .= str_repeat("\n",0-$difflevel); - if( $difflevel > 0) - $text .= str_repeat("
      \n",$difflevel); + if ($difflevel < 0) { + $text .= str_repeat("
    \n", 0 - $difflevel); + } + if ( $difflevel > 0) { + $text .= str_repeat("
      \n", $difflevel); + } $text .= $tmp_lines[$i]; - if(!array_sum($templevel)) + if (!array_sum($templevel)) { $temptoplevel = 'o'; + } $templevel[o] = $level[o]; } //__________ - if(array_sum($level) == 0){ - if(array_sum($templevel)){ - if($templevel[u]) - $text .= str_repeat("\n",$templevel[u]); - if($templevel[o]) - $text .= str_repeat("
    \n",$templevel[o]); + if (array_sum($level) == 0) { + if (array_sum($templevel)) { + if ($templevel[u]) { + $text .= str_repeat("\n", $templevel[u]); + } + if ($templevel[o]) { + $text .= str_repeat("\n", $templevel[o]); + } $templevel = array(); $temptoplevel = ''; } - if($tmp_lines[$i] && $i != $endline) + if ($tmp_lines[$i] && $i != $endline) { $text .= $tmp_lines[$i]."
    "; + } } - if($tmp_lines[$i] && $i != $endline) + if ($tmp_lines[$i] && $i != $endline) { $text .= "\n"; + } } } - function createLinkCodeWiki($pre, $url, $protocol = 'http') { + function createLinkCodeWiki($pre, $url, $protocol = 'http') + { $post = ''; // it's possible that $url ends with an entities @@ -172,17 +199,19 @@ class NP_Wikistyle extends NucleusPlugin { $url = substr($url, 0, strlen($url) - strlen($post)); } - if (!ereg('^'.$protocol.'://',$url)) + if (!ereg('^'.$protocol.'://',$url)) { $linkedUrl = $protocol . (($protocol == 'mailto') ? ':' : '://') . $url; - else + } else { $linkedUrl = $url; + } - if ($protocol != 'mailto') + if ($protocol != 'mailto') { $displayedUrl = $linkedUrl; - else + } else { $displayedUrl = $url; - return $pre . ''.$displayedUrl.'' . $post; + } + return $pre . '' . htmlspecialchars($displayedUrl) . '' . $post; } diff --git a/trunk/NP_Wtable/NP_Wtable.php b/trunk/NP_Wtable/NP_Wtable.php index 3d5da7d..94746b5 100644 --- a/trunk/NP_Wtable/NP_Wtable.php +++ b/trunk/NP_Wtable/NP_Wtable.php @@ -2,24 +2,28 @@ class NP_Wtable extends NucleusPlugin { - function getName() { // name of plugin - return 'Convert table'; + function getName() + { + return 'Convert table'; } - - function getAuthor() { // author of plugin - return 'nakahara21'; + + function getAuthor() + { + return 'nakahara21'; } - - function getURL() { // an URL to the plugin website - return 'http://xx.nakahara21.net/'; + + function getURL() + { + return 'http://nakahara21.com'; } - function getVersion() { // version of the plugin - return '0.2'; //tate array + function getVersion() + { + return '0.21'; } - - // a description to be shown on the installed plugins listing - function getDescription() { + + function getDescription() + { return 'Convert table'; } @@ -32,13 +36,19 @@ class NP_Wtable extends NucleusPlugin { } } - function getEventList() { return array('PreItem'); } + function getEventList() + { + return array( + 'PreItem' + ); + } - function event_PreItem(&$data) { - $this->currentItem = &$data["item"]; + function event_PreItem(&$data) + { + $this->currentItem =& $data["item"]; $this->currentItem->body = removeBreaks($this->currentItem->body); -// $this->currentItem->body = str_replace("\r\n","\n",$this->currentItem->body); +// $this->currentItem->body = str_replace("\r\n", "\n", $this->currentItem->body); $this->currentItem->body = preg_replace_callback("#\|(.*)\|\r\n#", array(&$this, 'list_table'), $this->currentItem->body); $this->currentItem->body = preg_replace_callback("#\!(.*)\!#", array(&$this, 'convert_table'), $this->currentItem->body); $this->currentItem->body = addBreaks($this->currentItem->body); @@ -46,53 +56,55 @@ class NP_Wtable extends NucleusPlugin { $this->currentItem->more = preg_replace_callback("#\|(.*?)\|#", array(&$this, 'convert_table'), $this->currentItem->more); } - function list_table($text) { - return "!".$text[1]."!"; + function list_table($text) + { + return "!" . $text[1] . "!"; } - function convert_table($text) { - $rows = explode('!!',$text[1]); - for($r =0; $r < count($rows); $r++){ - $cell = explode('|',$rows["$r"]); - for($c = 0; $c < count($cell); $c++){ + function convert_table($text) + { + $rows = explode('!!', $text[1]); + for ($r =0; $r < count($rows); $r++) { + $cell = explode('|', $rows["$r"]); + for ($c = 0; $c < count($cell); $c++) { $cols["$c"]["$r"] = $cell["$c"]; } } - for($c = 0; $c < count($cols); $c++){ + for ($c = 0; $c < count($cols); $c++) { $cols["$c"] = array_reverse ($cols["$c"], TRUE); $rowspan = 1; // print_r($cols["$c"]); - foreach($cols["$c"] as $key => $val){ - if($val == '~'){ + foreach($cols["$c"] as $key => $val) { + if ($val == '~') { $rowspan ++; $row["$key"]["$c"] = $val; - }elseif($val == '>'){ + } elseif($val == '>') { $row["$key"]["$c"] = $val; - }elseif($rowspan > 1){ - $row["$key"]["$c"] = ''.$val.''; + } elseif($rowspan > 1) { + $row["$key"]["$c"] = '' . $val . ''; $rowspan = 1; }else{ - $row["$key"]["$c"] = ''.$val.''; + $row["$key"]["$c"] = '' . $val . ''; } } } $row = array_reverse ($row, TRUE); // print_r($row); - for($r = 0; $r < count($row); $r++){ + for ($r = 0; $r < count($row); $r++) { $out .= ''; $colspan = 1; - for($c =0; $c < count($row["$r"]); $c++){ - if($row["$r"]["$c"] == '~'){ + for ($c =0; $c < count($row["$r"]); $c++) { + if ($row["$r"]["$c"] == '~') { $out .= ''; - }elseif($row["$r"]["$c"] == '>'){ + } elseif ($row["$r"]["$c"] == '>') { $out .= ''; $colspan ++; - }elseif($colspan >1){ - $out .= str_replace('','',$row["$r"]["$c"]); + } elseif ($colspan > 1) { + $out .= str_replace('', '', $row["$r"]["$c"]); $colspan = 1; - }else{ + } else { $out .= $row["$r"]["$c"]; } } @@ -100,7 +112,7 @@ class NP_Wtable extends NucleusPlugin { $out .= ''; } - return ''.$out.'
    '; + return '' . $out . '
    '; } } ?> \ No newline at end of file -- 2.11.0