File: ManifestFileHandler.pm

package info (click to toggle)
movabletype-opensource 4.2.3-1%2Blenny3
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 21,268 kB
  • ctags: 15,862
  • sloc: perl: 178,892; php: 26,178; sh: 161; makefile: 82
file content (80 lines) | stat: -rw-r--r-- 1,853 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# Movable Type (r) Open Source (C) 2001-2008 Six Apart, Ltd.
# This program is distributed under the terms of the
# GNU General Public License, version 2.
#
# $Id$

package MT::BackupRestore::ManifestFileHandler;

use strict;
use XML::SAX::Base;

@MT::BackupRestore::ManifestFileHandler::ISA = qw(XML::SAX::Base);

sub new {
    my $class = shift;
    my (%param) = @_;
    my $self = bless \%param, $class;
    return $self;
}

sub start_document {
    my $self = shift;
    my $data = shift;

    $self->{start} = 1;

    my $backups = {
        files => [],
        assets => [],
    };

    $self->{backups} = $backups;

    1;
}

sub start_element {
    my $self = shift;
    my $data = shift;

    my $name = $data->{LocalName};
    my %attrs = map {
        $data->{Attributes}->{$_}->{LocalName} => 
            MT::I18N::encode_text(MT::I18N::utf8_off($data->{Attributes}->{$_}->{Value}), 'utf-8')
    } keys(%{$data->{Attributes}});
    my $ns = $data->{NamespaceURI};

    if ($self->{start}) {
        die MT->translate("Uploaded file was not a valid Movable Type backup manifest file.")
            if !(('manifest' eq $name) && (MT::BackupRestore::NS_MOVABLETYPE() eq $ns));
        $self->{start} = 0;
    }
    if (MT::BackupRestore::NS_MOVABLETYPE() eq $ns) {
        my $backups = $self->{backups};
        if (('file' eq $name) && ('backup' eq $attrs{type})) {
            push @{$backups->{files}}, $attrs{name};
        } elsif (('file' eq $name) && ('asset' eq $attrs{type})) {
            push @{$backups->{assets}}, { 
                name => $attrs{name},
                asset_id => $attrs{'asset_id'},
            };
        }
        $self->{backups} = $backups;
    }
    1;
}

sub characters {
    my $self = shift;
    my $data = shift;
    1;
}

sub end_element {
    my $self = shift;
    my $data = shift;
    1;
}

1;