forked from Needlworks/Textcube
/
index.php
166 lines (157 loc) · 6 KB
/
index.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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
<?php
/// Copyright (c) 2004-2016, Needlworks / Tatter Network Foundation
/// All rights reserved. Licensed under the GPL.
/// See the GNU General Public License for more details. (/documents/LICENSE, /documents/COPYRIGHT)
if(count($_POST) > 0) {
$IV = array(
'FILES' => array(
'attachment' => array('file')
),
'POST' => array(
'fileName' => array('string', 'mandatory' => false)
)
);
}
require ROOT . '/library/preprocessor.php';
importlib("model.blog.attachment");
requireStrictRoute();
$context = Model_Context::getInstance();
?>
<!DOCTYPE html>
<html lang="<?php echo $context->getProperty('blog.language','ko');?>">
<head>
<title><?php echo _t('File Uploader');?></title>
<meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=no" />
<link rel="stylesheet" type="text/css" media="screen" href="<?php echo $context->getProperty('service.path').$context->getProperty('panel.skin');?>/editor.css" />
<!--[if IE 7]><link rel="stylesheet" type="text/css" media="screen" href="<?php echo $context->getProperty('service.path').$context->getProperty('panel.skin');?>/editor.ie7.css" /><![endif]-->
<script type="text/javascript" src="<?php echo $context->getProperty('service.jqueryURL');?>jquery-<?php echo JQUERY_VERSION;?>.js"></script>
<script type="text/javascript">jQuery.noConflict();</script>
<script type="text/javascript" src="<?php echo $context->getProperty('service.path');?>/resources/script/EAF4.js"></script>
<script type="text/javascript" src="<?php echo $context->getProperty('service.path');?>/resources/script/common3.min.js"></script>
<script type="text/javascript">
//<![CDATA[
var servicePath = "<?php echo $context->getProperty('service.path');?>";
var blogURL = "<?php echo $context->getProperty('uri.blog');?>";
var adminSkin = "<?php echo $context->getProperty('panel.skin');?>";
var oSelect = window.parent.document.getElementById('TCfilelist');
function addAttachOption(fileField) {
<?php
if (defined('__TEXTCUBE_GAE__')) {
?>
var request = new HTTPRequest("POST", "<?php echo $blogURL;?>/owner/api/uploadurl", false);
request.send("target=<?php echo $_SERVER["REQUEST_URI"];?>");
fileField.parentElement.action = request.getText('/response/url');
<?php
}
?>
try {
//window.parent.makeCrossDamainSubmit("<?php echo $context->getProperty('uri.blog');?>/owner/entry/attach/<?php echo $suri['id'];?>","ie");
if (!isSafari) {
if (isWin) {
var fileName = fileField.value.substring(fileField.value.lastIndexOf('\\')+1);
} else {
var fileName = fileField.value.substring(fileField.value.lastIndexOf('/')+1);
}
var oOption = window.parent.document.createElement("option");
oOption.text = fileName + " <?php echo _t('업로드 중..');?>";
oOption.value = fileName;
oSelect.options.add(oOption);
oSelect.setAttribute('size', Math.max(8,Math.min(oSelect.length,30)));
document.getElementById('fileNameInput').setAttribute('value', fileName);
}
} catch(e) {
alert(e.message);
}
}
function checkUploadMode(oEvent) {
try {
if(isIE)
uploader = window.parent.document.getElementById("uploader");
else
uploader = window.parent.document.getElementById("uploader2");
} catch(e) {
uploader = null;
}
if (uploader!=null) {
uploader.SetVariable('/:openBroswer','true');
}
}
<?php
if (count($_FILES) == 1) {
$file = array_pop($_FILES);
if (getAttachmentByLabel($blogid, $suri['id'], Path::getBaseName($file['name']))) {
print ('alert("' . _t('동일한 이름을 가진 파일이 이미 첨부되었습니다.') . '");');
?>
for( i=0; i<oSelect.options.length; i++) {
if(oSelect.options[i].value == "<?php echo escapeJSInCData($_POST['fileName']);?>") {
oSelect.remove(i);
}
}
<?php
} else if (($attachment = addAttachment($blogid, $suri['id'], $file)) === false) {
print ('alert("' . _t('첨부하지 못했습니다.') . '");');
?>
for( i=0; i<oSelect.options.length; i++) {
if(oSelect.options[i].value == "<?php echo escapeJSInCData($_POST['fileName']);?>") {
oSelect.remove(i);
}
}
<?php
} else {
?>
var oOption = window.parent.document.createElement("option");
oOption.innerHTML= "<?php echo escapeJSInCData(getPrettyAttachmentLabel($attachment));?>";
oOption.value = "<?php echo escapeJSInCData(getAttachmentValue($attachment));?>";
try {
<?php
if (!empty($attachment)) {
?>
for( i=0; i<oSelect.options.length; i++) {
//alert(oSelect.options[i].value+" "+ "<?php echo escapeJSInCData($attachment['label']);?>");
if(oSelect.options[i].value == "<?php echo escapeJSInCData($attachment['label']);?>") {
oSelect.remove(i);
}
}
<?php
}
?>
oSelect.appendChild(oOption);
//oSelect.selectedIndex = oSelect.options.length - 1;
//window.parent.document.getElementById("selectedImage").src = "<?php echo (strncmp($attachment['mime'], 'image/', 6) == 0 ? "{$context->getProperty('uri.blog')}/attach/$blogid/{$attachment['name']}" : "{$context->getProperty('uri.blog')}/resources/image/spacer.gif");?>";
parent.refreshFileSize();
} catch(e) {
alert('['+e.message+']');
}
<?php
}
}
?>
//]]>
</script>
<style type="text/css">
/*<![CDATA[*/
body,
form
{
margin : 0 !important;
padding : 0 !important;
}
.input-file
{
font-size : 75%;
width:180px;
}
/*]]>*/
</style>
</head>
<body id="body-editor-attachment">
<form method="post" action="" enctype="multipart/form-data" id="uploadForm">
<script type="text/javascript">
//<![CDATA[
document.write('<input type="file" class="input-file" name="attachment" size="16" onchange="addAttachOption(this); document.getElementById(\'uploadForm\').submit();" />');
//]]>
</script>
<input type="hidden" id="fileNameInput" name="fileName" value="" />
</form>
</body>
</html>