-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtemplateupload.php
108 lines (98 loc) · 3.44 KB
/
templateupload.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
<?php
require_once('config.php');
if (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') === false)
header('Content-type: application/xhtml+xml; charset=utf-8');
else
header('Content-type: text/html; charset=utf-8');
$error = '';
if (isset($_FILES['userfile']['tmp_name'])) {
if (substr($_FILES['userfile']['name'], -4) == '.svg') {
$svg = file_get_contents($_FILES['userfile']['tmp_name']);
$svg = str_replace(array('ARTICLE_TITLE',
'CATEGORY_TITLE',
'CATEGORY_IMAGE',
'PHOTO',
'PARA'),
array('<xsl:value-of select="/article/title" />',
'<xsl:value-of select="/article/category/title" />',
'{article/category/img/src}',
'{/article/photo}',
'<xsl:apply-templates select="/article/para" />'),
$svg);
$tmp = explode("\n", $svg);
$tmp[0] =
'<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:exsl="http://exslt.org/common" extension-element-prefixes="exsl">
<xsl:output omit-xml-declaration="yes" media-type="image/svg+xml" doctype-public="-//W3C//DTD SVG 20010904//EN" doctype-system="http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd" standalone="no" indent="no" method="xml"/>
<xsl:template name="break" match="/article/para">
<xsl:param name="text" select="."/>
<xsl:choose>
<xsl:when test="contains($text, \'
\')">
<flowPara xmlns="http://www.w3.org/2000/svg"><xsl:value-of select="substring-before($text, \'
\')"/></flowPara>
<xsl:call-template name="break">
<xsl:with-param name="text" select="substring-after($text,\'
\')"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<flowPara xmlns="http://www.w3.org/2000/svg"><xsl:value-of select="$text"/></flowPara>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="/">';
$tmp[] =
'</xsl:template>
</xsl:stylesheet>';
$svg = implode("\n", $tmp);
$xsl = new DomDocument;
if ($xsl->loadXML($svg)) {
$xsl->save(TEMPLATEDIR.'/'.str_replace(array('&', '.svg'), array('en', '.xsl'), $_FILES['userfile']['name']));
} else {
$error = ERROR_IN_TEMPLATE;
}
} else if (substr($_FILES['userfile']['name'], -4) == '.xsl') {
$xsl = new DomDocument;
if ($xsl->load($_FILES['userfile']['tmp_name'])) {
$xsl->save(TEMPLATEDIR.'/'.str_replace('&', '.xsl', $_FILES['userfile']['name']));
} else {
$error = ERROR_IN_TEMPLATE;
}
}
}
clearstatcache();
?>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" >
<head>
<title><?php echo OWNER; ?></title>
<style type="text/css">
<![CDATA[
html {
background-color: #ffff99;
}
body {
font-family: verdana, sans-serif;
font-size: small;
}
input,textarea {
border: 1px solid #000;
width: auto;
float: left;
}
fieldset,select {
border: 1px solid #000;
}
]]>
</style>
</head>
<body>
<?php echo $error; ?>
<form method="post" enctype="multipart/form-data">
<fieldset>
<legend>Template uploaden</legend>
<input name="userfile" type="file" style="float: left;" /> <input type="submit" value="Stuur!" class="button" />
</fieldset>
</form>
<a href="toevoegen.php">Toevoegen</a>
</body>
</html>