-
Notifications
You must be signed in to change notification settings - Fork 0
/
maker.php
110 lines (100 loc) · 2.44 KB
/
maker.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
<?php
class OPML_Maker {
function __construct($OPML_obj){
if ( 'OPML_Object' != get_class( $OPML_obj ) ){
return false;
} else {
$this->obj = $OPML_obj;
}
$this->force_safe = true;
if (OPML_DEFAULT_PATH){
$this->path = OPML_DEFAULT_PATH;
} else {
$this->path = dirname(__FILE__);
}
}
function force_safe($force = true){
if ($force){
$this->force_safe = true;
return true;
}
}
function assemble_tag($tag, $obj, $self_closing = false, $filter = false){
if (empty($obj)){
return '';
}
$s = "<$tag";
foreach ($obj as $property=>$value){
if ( !empty($filter) && in_array( $property, $filter ) ){
continue;
}
if ($this->force_safe){
$s .= ' '.esc_attr($property).'="'.esc_attr($value).'"';
} else {
$s .= ' '.$property.'="'.$value.'"';
}
}
if ($self_closing){
$s .= '/>';
} else {
$s .= '>';
}
$s .= "\n";
return $s;
}
public function template( $title = 'Blogroll' ){
ob_start();
echo '<?xml version="1.0" encoding="UTF-8"?>' . "\n";
?>
<opml version="2.0">
<head>
<title><?php echo $title; ?></title>
<expansionState></expansionState>
<linkPublicUrl><?php //@todo ?></linkPublicUrl>
<lastCursor>1</lastCursor>
</head>
<body>
<?php
$c = 0;
foreach ($this->obj->folders as $folder){
if ($c > 0){
echo "\n\t\t\t";
} else {
}
echo $this->assemble_tag('outline', $folder);
$feeds = $this->obj->get_feeds_by_folder($folder->slug);
if (!empty($feeds)){
foreach ($feeds as $feed){
echo "\t\t\t\t".$this->assemble_tag('outline',$feed,true,array('folder','feedUrl'));
}
}
echo "\t\t\t".'</outline>';
$c++;
}
echo "\n";
$folderless_count = 0;
foreach ($this->obj->get_feeds_without_folder() as $feed){
if ($c > 0){
echo "\t\t\t";
}
echo $this->assemble_tag('outline',$feed,true,array('folder','feedUrl'));
$c++;
}
echo "\n";
?>
</body>
</opml>
<?php
// get OPML from buffer and save to file
$opml = ob_get_clean();
$this->file_contents = $opml;
return $opml;
}
public function make_as_file($filepath = false){
if ( !$filepath ){
file_put_contents($this->path.'blogroll.opml', $this->file_contents);
} else {
file_put_contents($filepath, $this->file_contents);
}
}
}