/
functions.php
104 lines (82 loc) · 3.5 KB
/
functions.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
<?php
function remove_mlf_suffix($file, $languages) {
$xml = new DOMDocument();
$xml->formatOutput = true;
$xml->preserveWhiteSpace = false;
$xml->load($file) or die("Error: Cannot create object");
$post_types = $xml->getElementsByTagName('post_type');
for ($i = 0; $i < $post_types->length; $i++) {
$pt = $post_types->item($i)->nodeValue;
foreach ($languages as $lang) {
$pos = strpos($pt, '_t_'.$lang);
if ($pos !== false) {
$pt = str_replace( '_t_'.$lang, '', $pt );
break;
}
}
$post_types->item($i)->nodeValue = $pt;
}
$guid = $xml->getElementsByTagName('guid');
for ($i = 0; $i < $guid->length; $i++) {
$link = $guid->item($i)->nodeValue;
foreach ($languages as $lang) {
$pos = strpos($link, '_t_'.$lang);
if ($pos !== false) {
$link = str_replace( '_t_'.$lang, '', $link );
break;
}
}
$guid->item($i)->nodeValue = htmlentities($link);
}
$xml->save($file);
}
function merge_output_files($files) {
global $help;
if ( count( $files ) < 2 )
exit($help);
else {
$xml = new DOMDocument();
$xml->formatOutput = true;
$xml->preserveWhiteSpace = false;
$xml->load($files[0]) or die("Error: Cannot create object");
$authors = array();
$users = $xml->getElementsByTagName('author');
foreach ($users as $user)
$authors[] = (int) $user->getElementsByTagName('author_id')->item(0)->nodeValue;
foreach($files as $index => $file) {
if ( $index == 0 ) continue;
$content = new DOMDocument();
$content->formatOutput = true;
$content->preserveWhiteSpace = false;
$content->load($file) or die("Error: Cannot create object");
// append authors
$users = $content->getElementsByTagName('author');
foreach ($users as $user){
$author = (int) $user->getElementsByTagName('author_id')->item(0)->nodeValue;
if ( !in_array($author, $authors) ) {
$authors[] = $author;
$node = $xml->importNode($user, true);
$xml->getElementsByTagName('channel')->item(0)->appendChild($node);
}
}
// append items
$items = $content->getElementsByTagName('item');
foreach ($items as $item) {
$node = $xml->importNode($item, true);
$xml->getElementsByTagName('channel')->item(0)->appendChild($node);
}
// append post_translations terms
$terms = $content->getElementsByTagName('term');
foreach ($terms as $key => $term) {
$taxonomy = $term->getElementsByTagName('term_taxonomy')->item(0)->nodeValue;
if ( 'post_translations' == $taxonomy ) {
$node = $xml->importNode($term, true);
$xml->getElementsByTagName('channel')->item(0)->appendChild($node);
}
}
}
$xml->save('output.xml');
}
exit();
}
?>