File: OpenDb_XML.php

package info (click to toggle)
opendb 0.62p9-3
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 3,544 kB
  • ctags: 3,560
  • sloc: php: 26,575; sql: 1,982; sh: 250; makefile: 54
file content (118 lines) | stat: -rw-r--r-- 3,140 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
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
<?php
/* 	OpenDb - Open Lending Database Project
	Copyright (C) 2001,2002 by Jason Pell

	This program is free software; you can redistribute it and/or
	modify it under the terms of the GNU General Public License
	as published by the Free Software Foundation; either version 2
	of the License, or (at your option) any later version.

	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License
	along with this program; if not, write to the Free Software
	Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
*/

include_once("./functions/widgets.php");
include_once("./functions/utils.php");

//
// XML Export Plugin
//

/*
* The content type, when saved as file.
*/
function file_content_type()
{
	return "text/xml";
}

/*
* The filename extension, when saved as file.
*/
function file_extension()
{
	return "xml";
}

/*
* The file header, when saved as file.
*/
function file_header($title)
{
	return "<?xml version=\"1.0\" encoding=\"ISO-8859-1\" ?>\n".
			"<!DOCTYPE opendb-items SYSTEM \"http://opendb.i-am-vegan.net/dtd/opendb-items.dtd\">\n\n".
			"<!--\n".
			"\t$title\n".
			"-->\n".
			"<opendb-items>";
}

/*
* The file footer, when saved as file.
*/
function file_footer()
{
	return "\n</opendb-items>\n";
}

function start_item($level, $item_id, $s_item_type, $title, $category)
{
	return "\n".tab_indent($level)."<item item_id=\"$item_id\" s_item_type=\"$s_item_type\" title=\"".escape_xml_entities($title)."\" category=\"".escape_xml_entities($category)."\">";
}

function end_item($level, $item_id)
{
	return "\n".tab_indent($level)."</item>";
}

function item_instance($level, $item_id, $instance_no, $owner_id, $borrow_duration, $s_status_type, $status_comment)
{
	return "\n".tab_indent($level)."<instance instance_no=\"$instance_no\" owner_id=\"$owner_id\" borrow_duration=\"$borrow_duration\" s_status_type=\"$s_status_type\" status_comment=\"".escape_xml_entities($status_comment)."\"/>";
}

function item_attribute($level, $item_id, $s_attribute_type, $order_no, $attribute_val)
{
	return "\n".tab_indent($level)."<attribute s_attribute_type=\"$s_attribute_type\" order_no=\"$order_no\">".
		"\n".tab_indent($level+1)."<![CDATA[".
		"\n".tab_indent_lines($level+1, $attribute_val).
		"".tab_indent($level+1)."]]>".
		"\n".tab_indent($level)."</attribute>";
}

function tab_indent_lines($level, $value)
{
	$buffer = "";
	$lines = explode_lines($value);
	if(is_not_empty_array($lines))
	{
		while(list(,$line) = each($lines))
		{
			$buffer .= tab_indent($level).$line."\n";
		}
	}
	return $buffer;
}

//utility functions
function tab_indent($level)
{
	if(is_numeric($level) && $level>0)
		return str_repeat("\t", $level);
	else
		return "";
}

function escape_xml_entities($str)
{
	return str_replaces(
				array("\"", "<", ">", "\n", "\r", "&"), // find
				array("&#34;", "&#60;", "&#62;", "&#10;", "&#13;", "&#38;"), // replace
				$str);
}
?>