root/trunk/mirror/mirror.pl

Revision 701, 1.4 kB (checked in by mpaschal, 18 months ago)

Move mirror plugin from mt extras to mtplugins repo

Line 
1# Movable Type (r) Open Source (C) 2005-2008 Six Apart, Ltd.
2# This program is distributed under the terms of the
3# GNU General Public License, version 2.
4#
5# $Id: mirror.pl 1174 2008-01-08 21:02:50Z bchoate $
6
7use strict;
8
9my $PLUGIN_NAME = "Mirror";
10
11sub replicate {
12    my ($cb, $entry) = @_;
13   
14    if (!$entry->id) {               # If it's a new post,
15        if ($entry->blog_id == 3) {  #    on my blog
16            use XML::Atom;
17            use XML::Atom::Entry;
18            use XML::Atom::Client;
19            my $atom_entry = new XML::Atom::Entry;
20            $atom_entry->title($entry->title);
21            $atom_entry->content($entry->text);
22           
23            my $atom_client = new XML::Atom::Client;
24            $atom_client->username('Melody');
25            $atom_client->password('waSiIiKV27v..');
26            my $post_endpt = 'http://koro:4141/cgi-bin/mt/mt-atom.cgi/weblog/blog_id=6';
27            $atom_client->createEntry($post_endpt, $atom_entry);
28            if ($atom_client->errstr()) {
29                return $cb->error($atom_client->errstr());
30            } else {
31                return 1;
32            }
33        } else {
34            return 1;
35        }
36    }
37}
38
39require MT::Plugin;
40
41my $plugin = new MT::Plugin(name => $PLUGIN_NAME, 
42                            dir_name => 'mirror',
43                            description => "Replicates each post you make to another weblog using Atom.",
44                            config_link => "mt-mirror.cgi");
45
46MT->model('entry')->add_callback("pre_save", 9, $plugin, \&replicate);
47
48MT->add_plugin($plugin);
49
50# Return the return value of MT->add_plugin so that we'll be disabled
51# if add_plugin chooses to disable us.
Note: See TracBrowser for help on using the browser.