[MTOS-dev] "Print this Page" plugin

Reed A. Cartwright reed at scit.us
Wed Feb 27 15:53:29 PST 2008


Okay, here is my mtpipe.pl plugin.  It's out of date and will need to be 
updated to work with MTOS 4.1, but I grant permission for anyone to use 
or modify it with proper credit.

It can be used as follows:

<MTPipe cmd="cat -b">
<!--
Some template code.
-->
</MTPipe>

For my PDF individual archives, I created a simple html template and 
wrapped it inside the pipe, which fed the template to a command which 
processed the html and turned it into a pdf, which mt pipe then returned 
  to movable type which saved the output to a file which had a pdf 
extension.

<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
package plugins::mtpipe;

use strict;
use vars qw($VERSION);
$VERSION = '0.1.0';

use MT;
use MT::Plugin;

use FileHandle;
use IPC::Open2;

my $about = {
     name => 'System Pipe',
     description => "Version $VERSION",
};
my $plugin = new MT::Plugin($about);
MT->add_plugin($plugin);

MT::Template::Context->add_container_tag(Pipe => \&mtpipe);

sub mtpipe {
	my ($ctx, $args) = @_;
	return '' unless($args->{cmd});
	$args->{arg} ||= '';
	
	my $builder = $ctx->stash('builder');
	my $tokens = $ctx->stash('tokens');
	my $in = $builder->build($ctx, $tokens);
	my @a = split(/\s/, $args->{arg});
	my $pid = open2(*Reader, *Writer, $args->{cmd}, @a);
	print Writer $in; 

	close Writer;
	my @out = <Reader>;
	close Reader;
	waitpid($pid,0);
	join('', at out);
}
 >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

-- 
*********************************************************
Reed A. Cartwright, PhD     http://scit.us/
Postdoctoral Researcher     http://www.dererumnatura.us/
Department of Genetics      http://www.pandasthumb.org/

Bioinformatics Research Center
North Carolina State University
Campus Box 7566
Raleigh, NC 27695-7566

Cuiusvis hominis est errare, nullius nisi
insipientis in errore perserverare. --Cicero


More information about the MTOS-dev mailing list