En~MoniWiki › MacroMarket
This is a marketplace for your macros. Please state your name, your email, and upload or link your macros.
Contents
- 1
NewWindow - 2 UsenetMacro
- 3 RSS
- 4 Comment
- 5 'List Of' Macro
- 6 EMailAddress
- 7 InformationRadiator›1
- 8 Calendar Events Extension
- 9 Removable RCS history
- 10 Discussions
- 1
1
NewWindow ¶
<?php
// Copyright 2003 by Yeon Hyeong Yang <yhgogo@postech.ac.kr>
// All rights reserved. Distributable under GPL see COPYING
// NewWindow plugin for the MoniWiki
//
// Usage: [[NewWindow("url","caption")]]
//
function macro_NewWindow($formatter,$value) {
list($dummy1,$url,$dummy2,$desc) = explode('"',$value);
$url = $url . " " . $desc;
return $formatter->link_repl($url,"target='_blank'");
}
?>
With above 1.0.9 release, You can use [^http://blahblah.com blah blah] syntax instead.
3 RSS ¶
Enhanced RSS macro
<?php
/**
* RSS macro plugin for the MoniWiki
* - This enables to aggregate remote RSS.
* - You need XML_RSS module of PEAR.
* - Macro format is [[MyRSS(URI ItemCount Encoding)]].
* ex) [[MyRSS(http://www.gatorlog.com/index.xml 5 utf-8)]]
* - Last 2 parameter(ItemCount, Encoding) can be omitted.
* Default ItemCount value is 5.
* Default Encoding is MoniWiki's charset.
* http://nohmad.sub-port.net/wiki?RSSMacro
*
* Copyright 2003 by Gyoung-Yoon Noh <nohmad at sub-port.net>
* All rights reserved. Distributable under GPL see COPYING.
*/
function macro_MyRSS($formatter, $value)
{
global $DBInfo;
require_once 'XML/RSS.php';
list($uri, $loop, $enc) = @explode(' ', $value);
$uri = $uri ? $uri : $value;
if (!isUrlAlive($uri)) return "Dead URL: $uri";
$loop = $loop ? $loop : 5;
$enc = $enc ? $enc : $DBInfo->charset;
$rss =& new XML_RSS($uri);
$rss->parse();
foreach ($rss->getItems() as $item) {
if ($loop <= 0) break;
$link = $item['link'];
$title = iconv($enc, $DBInfo->charset, $item['title']);
$date = $item['dc:date']?' @'.$item['dc:date']:'';
$row[] = sprintf('<A href="%s">%s</A>%s', $link, $title, $date);
$loop--;
}
return @join("<br />
", $row);
}
function isUrlAlive($url)
{
$purl = parse_url($url);
$purl['path'] .= $purl['query'] ? '?'.$purl['query'] : '';
$purl['port'] = $purl['port'] ? $purl['port'] : 80;
$CRLF = "\n";
$buf[] = "GET {$purl['path']} HTTP/1.0";
$buf[] = "Host: {$purl['host']}";
$buf[] = "Content-Type: text/html";
$buf[] = "User-Agent: MoniWiki (moniwiki.sf.net)";
$msg_send = @join($CRLF, $buf).$CRLF.$CRLF;
$timeout = 5;
$conn = @fsockopen($purl['host'], $purl['port'], $errno, $errstr, $timeout);
if (!$conn) return false;
socket_set_timeout($conn, $timeout);
@fputs($conn, $msg_send);
$msg_recv = fread($conn, 4000);
list($header) = preg_split('/(\r?\n){2}/', $msg_recv);
@fclose($conn);
$respcode = substr($header, 0, strpos($header, "\n"));
if (ereg('200', $respcode)) return true;
else if (ereg('302', $respcode)) {
@preg_match('/^Location: ([^\s]*)\s/m', $header, $match);
return isUrlAlive($match[1]);
} else return false;
}
?>
4 Comment ¶
<?php
# Copyright
# Just show my name. I don't care what you do with it.
#
# Author: Choi, Jong-wook
# Address: http://choijw.net/
#
# replace "##Comment" string with submitted comment when it available
# added by Lee Jae-Hong, http://www.pyrasis.com
function macro_Comment($formatter, $value) {
return "<table class='comment'><tr><form method='post' action=''><td><textarea class='comment' cols=60 rows=8 name='comment'></textarea></td><td align='center'> name: <input name='author' class='comment'><br> <input type='submit' value='comment' class='comment'><br>".$formatter->link_tag("HelpOnComment")."<input type='hidden' name='action' value='comment'/></td></form></tr></table>";
}
function do_comment($formatter,$options) {
global $DBInfo;
if (!$options['comment'] or !$options['author']) return '<html><h1>Error</h1></html>';
$raw_body=$formatter->page->get_raw_body();
$comment=stripslashes($options['comment']);
$author=stripslashes($options['author']);
$entry = "----
".$comment." --".$author."\n";
if (preg_match("/\n##Comment\n/i",$raw_body))
$raw_body=preg_replace("/\n##Comment\n/i","\n##Comment\n$entry",$raw_body,1);
else
$raw_body.=$entry;
$formatter->page->write($raw_body);
$DBInfo->savePage($formatter->page,"Comment",$options);
$options[msg]=_("Commented Successfully");
$formatter->send_header("",$options);
$formatter->send_title("","",$options);
$formatter->send_page();
$formatter->send_footer("",$options);
return;
}
?>
obsolute
5 'List Of' Macro ¶
<?php
# Copyright
# Just show my name. I don't care what you do with it.
#
# Author: Choi, Jong-wook
# Address: http://choijw.net/
function macro_ListOf($formatter,$value="") {
global $DBInfo;
$out="<ul>
";
$pagename=strtok($value, " ,");
$max=strtok(" ,");
if (!($pagename and $DBInfo->hasPage($pagename))) return '';
if (!$max) $max=10;
$page=$DBInfo->getPage($pagename);
if (!$page->exists()) return '';
$raw=$page->get_raw_body();
$lines=explode("\n",$raw);
foreach($lines as $line) {
if (preg_match("/^\s\* (.*)$/",$line,$match))
$quotes[]=$match[1];
}
if (!($count=sizeof($quotes))) return '';
for ($i=0; $i<$count; $i++) {
if ($i>=$max){
$out.="<li>".$formatter->link_tag($pagename,'', "...")."</li>\n";
break;
}
$quote=$quotes[$i];
#format a line
$quote=str_replace("<","<",$quote);
$quote=preg_replace($formatter->baserule,$formatter->baserepl,$quote);
$quote=preg_replace("/(".$formatter->wordrule.")/e","\$formatter->link_repl('\\1')",
$quote);
$out.="<li>".$quote."</li>\n";
}
return $out."</ul>\n";
}
?>
7 InformationRadiator›1 ¶
<?php
/**
Information Radiator Macro
@param Done as a Double
@param Todo as a Double
@version 1.0
@date 2004.11.05
@author Bae Jae Hyun (delphix at dreamwiz dot net)
@note Usage : [[IR(Done, Todo)]]
Sample: [[IR(10, 20)]]
This version tested in Moniwiki 1.0.9. (only!)
**/
function macro_IR($formatter,$value) {
global $DBInfo;
$imgdir=$DBInfo->imgs_dir;
$TodoIconSet='red';
$DoneIconSet='blue';
$TodoValue=0.0;
$DoneValue=0.0;
$Percentage=0.0;
# parse args
$Argument=explode(',',$value);
$TodoValue=trim(array_pop($Argument));
$DoneValue=trim(array_pop($Argument));
$DiffValue=$TodoValue-$DoneValue;
if ($TodoValue != 0) $Percentage=($DoneValue * 100.0) / $TodoValue;
$Info=' '.$DoneValue.'/'.$TodoValue.' ('.sprintf('%.1f', $Percentage).'%)';
$LeftBarIconSet=$TodoIconSet;
if ($DoneValue > 0) $LeftBarIconSet=$DoneIconSet;
$RightBarIconSet=$DoneIconSet;
if ($DiffValue > 0) $RightBarIconSet=$TodoIconSet;
# html src
$img.="<img src='$imgdir/vote/".$LeftBarIconSet."/leftbar.gif' align='middle' alt='LeftBarImage'/> ";
if ($DoneValue > 0) {
for($i=0;$i<round($DoneValue);$i++) {
$img.="<img src='$imgdir/vote/".$DoneIconSet."/mainbar.gif' height='14' width='4' align='middle' alt='DoneBarImage'/> ";
}
}
if ($DiffValue > 0) {
for($i=0;$i<round($DiffValue);$i++) {
$img.="<img src='$imgdir/vote/".$TodoIconSet."/mainbar.gif' height='14' width='4' align='middle' alt='TodoBarImage'/> ";
}
}
$img.="<img src='$imgdir/vote/".$RightBarIconSet."/rightbar.gif' align='middle' alt='RightBarImage'/>".$Info;
return $img;
}
?>
Bar.php support similar feature.
8 Calendar Events Extension ¶
<?php
/**
* Copyright 2005 by Fabian Dennler <fd@insecta.ch>
* All rights reserved. Distributable under GPL see COPYING
* an extension plugin for the MoniWiki Calendar
*
* Description:
* Display the next Calendar Items, this are named in the form:
* PageName/Year-Month-Day
*
* Usage:
* [[CalendarEvents(20)]]
*
* $Id: MacroMarket,v 1.21 2008/04/26 15:04:05 root Exp $
*/
// vim:et:ts=2:
function macro_CalendarEvents($formatter,$value) {
global $DBInfo;
$amount = $value;
$pagename = $pagename=$formatter->page->name;
$out = '';
for ($i=0;$i<=$amount;$i++) {
$value = $pagename."/".date("Y-m-d",time()+($i*3600*24));
#echo $value."<br>";
if ($value and $DBInfo->hasPage($value)) {
$ipage=$DBInfo->getPage($value);
$if=new Formatter($ipage);
$ibody=$ipage->_get_raw_body();
$ibody = str_replace("[[Blog]]","",$ibody);
$ibody .= "----";
$opt['nosisters']=1;
ob_start();
$if->send_page($title.$ibody,$opt);
$out .= ob_get_contents();
ob_end_clean();
# $formatter->pagelinks=$savelinks;
}
}
return $out;
}
?>
9 Removable RCS history ¶
- nick: cheeky
- email: tinydesks at gmail.com
- homepage: http://tinydesk.com
please, email me when you find out something wrong or any concerns. Don't blame on me even if you see the spaghetti source. Thanks.









![[http]](/imgs/http.png)
