<?php
// plugin needs to work on Nucleus versions <=2.0 as well
-if (!function_exists('removeBreaks')){
- function removeBreaks($var) { return preg_replace("/<br \/>([\r\n])/","$1",$var); }
+if (!function_exists('removeBreaks')) {
+ function removeBreaks($var)
+ {
+ return preg_replace("/<br \/>([\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';
}
}
}
- 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[] = " ";
$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 = '';
//__________
'$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]."<br />";
+ $text .= $tmp_lines[$i] . '<br />';
}
//__________
- 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 .= '<h'.$level[h].' class="wiki">'.$tmp_lines[$i].'</h'.$level[h].'>';
+ if ($level[h]) {
+ $tmp_lines[$i] = ltrim(substr($tmp_lines[$i], $level[h]));
+ $text .= '<h' . intval($level[h]) . ' class="wiki">' . $tmp_lines[$i] . '</h' . intval($level[h]) . '>';
}
//__________
- 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] = '<li>'.$tmp_lines[$i].'</li>';
+ if ($level[u] && !$level[r]) {
+ $tmp_lines[$i] = ltrim(substr($tmp_lines[$i], $level[u]));
+// $tmp_lines[$i] = '<li>' . $tmp_lines[$i] . '</li>';
//_-------------
- if($temptoplevel == 'u' && $templevel[o]){
- $tmp_lines[$i] = str_repeat("</ol>\n",$templevel[o])."\n".'<li>'.$tmp_lines[$i].'</li>';
+ if ($temptoplevel == 'u' && $templevel[o]) {
+ $tmp_lines[$i] = str_repeat("</ol>\n",$templevel[o]) . "\n" . '<li>' . $tmp_lines[$i] . '</li>';
$templevel[o] = 0;
}else{
- $tmp_lines[$i] = '<li>'.$tmp_lines[$i].'</li>';
+ $tmp_lines[$i] = '<li>' . $tmp_lines[$i] . '</li>';
}
//_-------------
$difflevel = $level[u] - $templevel[u];
- if($difflevel < 0)
- $text .= str_repeat("</ul>\n",0-$difflevel);
- if( $difflevel > 0)
- $text .= str_repeat("<ul>\n",$difflevel);
+ if ($difflevel < 0) {
+ $text .= str_repeat("</ul>\n", 0 - $difflevel);
+ }
+ if ( $difflevel > 0) {
+ $text .= str_repeat("<ul>\n", $difflevel);
+ }
$text .= $tmp_lines[$i];
- if(!array_sum($templevel))
+ if (!array_sum($templevel)) {
$temptoplevel = 'u';
+ }
$templevel[u] = $level[u];
}
//__________
- if($level[r]){
- $tmp_lines[$i] = ltrim(substr($tmp_lines[$i],$level[r]));
+ if ($level[r]) {
+ $tmp_lines[$i] = ltrim(substr($tmp_lines[$i], $level[r]));
$text .= '<div class="hr"><hr /></div>';
}
//__________
- if (($level[o] = strspn($tmp_lines[$i],'+')) > 3)
+ if (($level[o] = strspn($tmp_lines[$i],'+')) > 3) {
$level[o] = 3; // limitation ;(
- if($level[o]){
- $tmp_lines[$i] = ltrim(substr($tmp_lines[$i],$level[o]));
+ }
+ if ($level[o]) {
+ $tmp_lines[$i] = ltrim(substr($tmp_lines[$i], $level[o]));
-// $tmp_lines[$i] = '<li>'.$tmp_lines[$i].'</li>';
+// $tmp_lines[$i] = '<li>' . $tmp_lines[$i] . '</li>';
//_-------------
- if($temptoplevel == 'o' && $templevel[u]){
- $tmp_lines[$i] = str_repeat("</ul>\n",$templevel[u])."\n".'<li>'.$tmp_lines[$i].'</li>';
+ if ($temptoplevel == 'o' && $templevel[u]) {
+ $tmp_lines[$i] = str_repeat("</ul>\n", $templevel[u]) . "\n" . '<li>' . $tmp_lines[$i] . '</li>';
$templevel[u] = 0;
- }else{
- $tmp_lines[$i] = '<li>'.$tmp_lines[$i].'</li>';
+ } else {
+ $tmp_lines[$i] = '<li>' . $tmp_lines[$i] . '</li>';
}
//_-------------
$difflevel = $level[o] - $templevel[o];
- if($difflevel < 0)
- $text .= str_repeat("</ol>\n",0-$difflevel);
- if( $difflevel > 0)
- $text .= str_repeat("<ol>\n",$difflevel);
+ if ($difflevel < 0) {
+ $text .= str_repeat("</ol>\n", 0 - $difflevel);
+ }
+ if ( $difflevel > 0) {
+ $text .= str_repeat("<ol>\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("</ul>\n",$templevel[u]);
- if($templevel[o])
- $text .= str_repeat("</ol>\n",$templevel[o]);
+ if (array_sum($level) == 0) {
+ if (array_sum($templevel)) {
+ if ($templevel[u]) {
+ $text .= str_repeat("</ul>\n", $templevel[u]);
+ }
+ if ($templevel[o]) {
+ $text .= str_repeat("</ol>\n", $templevel[o]);
+ }
$templevel = array();
$temptoplevel = '';
}
- if($tmp_lines[$i] && $i != $endline)
+ if ($tmp_lines[$i] && $i != $endline) {
$text .= $tmp_lines[$i]."<br />";
+ }
}
- 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
$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 . '<a href="'.$linkedUrl.'" target="_blank">'.$displayedUrl.'</a>' . $post;
+ }
+ return $pre . '<a href="' . htmlspecialchars($linkedUrl) . '" target="_blank">' . htmlspecialchars($displayedUrl) . '</a>' . $post;
}
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';
}
}
}
- 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);
$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"] = '<td rowspan="'.$rowspan.'">'.$val.'</td>';
+ } elseif($rowspan > 1) {
+ $row["$key"]["$c"] = '<td rowspan="' . intval($rowspan) . '">' . $val . '</td>';
$rowspan = 1;
}else{
- $row["$key"]["$c"] = '<td>'.$val.'</td>';
+ $row["$key"]["$c"] = '<td>' . $val . '</td>';
}
}
}
$row = array_reverse ($row, TRUE);
// print_r($row);
- for($r = 0; $r < count($row); $r++){
+ for ($r = 0; $r < count($row); $r++) {
$out .= '<tr>';
$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('<td>','<td colspan="'.$colspan.'">',$row["$r"]["$c"]);
+ } elseif ($colspan > 1) {
+ $out .= str_replace('<td>', '<td colspan="' . intval($colspan) . '">', $row["$r"]["$c"]);
$colspan = 1;
- }else{
+ } else {
$out .= $row["$r"]["$c"];
}
}
$out .= '</tr>';
}
- return '<table border=1>'.$out.'</table>';
+ return '<table border=1>' . $out . '</table>';
}
}
?>
\ No newline at end of file