-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwp_import.php
142 lines (116 loc) · 3.35 KB
/
wp_import.php
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
<?php
/*Reads a wordpress exportfile into abstract data types
*Example at the bottom of the file
*@author schmiddi
*@date 30.03.10
* licence: feel free to use it.
*/
require_once('adt.php');
class CWp_import{
private $xml; //handle for the simplexml object
public function __construct($file){
if (file_exists($file)) {
$this->xml = simplexml_load_file($file);
} else {
echo "File not found";
die();
}//else
}//construct
public function getPosts(){
/*returns an array of ADT_posts objects
*
*/
$xml=$this->xml;
$arr_posts = array();
foreach ( $xml->channel->item as $item){
$post = new ADT_post();
$post->title = $item->title;
$post->pubdate = $item->pubDate;
$post->creator = $item->children('dc', true)->creator;
$post->content = $item->children('content', true)->encoded;
//Add comments
if (!empty( $item->children('wp',true)->comment) ) {
foreach ($item->children('wp',true)->comment as $comment){
$c = new ADT_comment(
$comment->comment_id,
$comment->comment_author,
$comment->comment_author_email,
$comment->comment_author_url,
$comment->comment_author_IP,
$comment->comment_date,
$comment->comment_date_gmt,
$comment->comment_content,
$comment->comment_approved,
$comment->comment_user_id,
$comment->comment_parent
);
array_push($post->comments, $c);
}//each
}//fi
//tags & categories
foreach ($item->category as $cat){
$nicename =$cat->attributes()->nicename;
if ($cat->attributes()->domain =='tag' &&$cat->attributes()->nicename!=''){
$t = new ADT_tag($nicename, $cat);
$post->add_tag($t);
}
if ($cat->attributes()->domain=='category'){
$c = new ADT_category($nicename, '', $cat);
$post->add_category($c);
}
}//each
array_push($arr_posts, $post);
}//each
return $arr_posts;
}//function
public function getTags(){
/*returns an array of ADT_tag objects
*
*/
$xml=$this->xml;
$arr_tags = array();
foreach ( $xml->channel->children('wp',true)->tag as $item){
$tag = new ADT_tag();
$tag->slug = $item->tag_slug;
$tag->name = $item->tag_name;
array_push($arr_tags, $tag);
}//each
return $arr_tags;
}//function
public function getCategories(){
/*returns an array of ADT_category objects
*
*/
$xml=$this->xml;
$arr_categories = array();
foreach ( $xml->channel->children('wp',true)->category as $item){
$cat = new ADT_category();
$cat->nicename = $item->category_nicename;
$cat->parent= $item->category_parent;
$cat->name = $item->cat_name;
array_push($arr_categories, $cat);
}//each
return $arr_categories;
}//function
public function getMetaInfo (){
/*returns an ADT_wp_meta object
*/
$xml=$this->xml;
$wp_meta = new ADT_wp_meta();
$wp_meta->title = $xml->channel->title;
$wp_meta->link = $xml->channel->link;
$wp_meta->description = $xml->channel->description;
$wp_meta->pubDate = $xml->channel->pubDate;
$wp_meta->language = $xml->channel->language;
$wp_meta->base_blog_url =$xml->channel->children('wp',true)->base_blog_url;
return $wp_meta;
}
}//class
$file='wordpress.2010-03-29.xml';
$arr = array();
$import = new CWp_import($file);
$arr= $import->getPosts();
foreach ($arr as $post){
$post->print_vars();
}
?>