forked from typecho/typecho
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmedia.php
192 lines (161 loc) · 8.05 KB
/
media.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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
<?php
include 'common.php';
include 'header.php';
include 'menu.php';
Typecho_Widget::widget('Widget_Contents_Attachment_Edit')->to($attachment);
?>
<div class="main">
<div class="body container">
<?php include 'page-title.php'; ?>
<div class="col-group typecho-page-main">
<div class="col-mb-12 col-tb-8">
<?php if ($attachment->attachment->isImage): ?>
<p><img src="<?php $attachment->attachment->url(); ?>" alt="<?php $attachment->attachment->name(); ?>" class="typecho-attachment-photo" /></p>
<?php endif; ?>
<p>
<?php $mime = Typecho_Common::mimeIconType($attachment->attachment->mime); ?>
<span class="typecho-mime typecho-mime-<?php echo $mime; ?>"></span>
<a href=""><strong><?php $attachment->attachment->name(); ?></strong></a>
<span><?php echo number_format(ceil($attachment->attachment->size / 1024)); ?> Kb</span>
</p>
<p>
<input id="attachment-url" type="text" class="mono w-100" value="<?php $attachment->attachment->url(); ?>" readonly />
</p>
<div id="upload-panel" class="p">
将要替换的文件拖放到这里 或者 <a href="" class="upload-file">选择替换文件</a><input type="file" class="visuallyhidden">
<ul id="file-list">
<li class="loading">上传中</li>
</ul>
</div>
</div>
<div class="col-mb-12 col-tb-4">
<?php $attachment->form()->render(); ?>
</div>
</div>
</div>
</div>
<?php
include 'copyright.php';
include 'common-js.php';
?>
<script type="text/javascript" src="<?php $options->adminUrl('javascript/swfupload/swfupload.js?v=' . $suffixVersion); ?>"></script>
<script type="text/javascript" src="<?php $options->adminUrl('javascript/swfupload/swfupload.queue.js?v=' . $suffixVersion); ?>"></script>
<script type="text/javascript">
(function () {
window.addEvent('domready', function() {
$(document).getElement('.typecho-attachment-photo-box .description input').addEvent('click', function () {
this.select();
});
var swfuploadLoaded = function () {
var btn = $(document)
.getElement('.typecho-attachment-photo-box button#exchange');
var obj = $(document)
.getElement('.typecho-attachment-photo-box .description ul li #swfu');
offset = obj.getCoordinates(btn);
obj.setStyles({
'width': btn.getSize().x,
'height': btn.getSize().y,
'left': 0 - offset.left,
'top': 0 - offset.top
});
btn.removeAttribute('disabled');
};
var fileDialogComplete = function (numFilesSelected, numFilesQueued) {
try {
this.startUpload();
} catch (ex) {
this.debug(ex);
}
};
var uploadStart = function (file) {
$(document)
.getElement('.typecho-attachment-photo-box button#exchange')
.set('html', '<?php _e('上传中'); ?>')
.setAttribute('disabled', '');
};
var uploadSuccess = function (file, serverData) {
var _el = $(document).getElement('#attachment-url');
var _result = JSON.decode(serverData);
_el.set('tween', {duration: 1500});
_el.setStyles({
'background-position' : '-1000px 0',
'background-color' : '#D3DBB3'
});
<?php if ($attachment->attachment->isImage): ?>
var _img = new Image(), _date = new Date();
_img.src = _result.url + (_result.url.indexOf('?') > 0 ? '&' : '?') + '__rds=' + _date.toUTCString();
_img.alt = _result.title;
$(document).getElement('.typecho-attachment-photo-box img').destroy();
$(_img).inject($(document).getElement('.typecho-attachment-photo-box'), 'top');
<?php endif; ?>
$(document).getElement('.typecho-attachment-photo-box .description small')
.set('html', Math.ceil(_result.size / 1024) + ' Kb');
_el.tween('background-color', '#D3DBB3', '#EEEEEE');
};
var uploadComplete = function (file) {
$(document)
.getElement('.typecho-attachment-photo-box button#exchange')
.set('html', '<?php _e('替换'); ?>')
.removeAttribute('disabled');
};
var uploadError = function (file, errorCode, message) {
var _el = $(document).getElement('#attachment-url');
var _fx = new Fx.Tween(_el, {duration: 3000});
_fx.start('background-color', '#CC0000', '#EEEEEE');
};
var uploadProgress = function (file, bytesLoaded, bytesTotal) {
var _el = $(document).getElement('#attachment-url');
var percent = Math.ceil((1 - (bytesLoaded / bytesTotal)) * _el.getSize().x);
_el.setStyle('background-position', '-' + percent + 'px 0');
};
var swfu, _size = $(document).getElement('.typecho-attachment-photo-box button#exchange').getCoordinates(),
settings = {
flash_url : "<?php $options->adminUrl('javascript/swfupload/swfupload.swf'); ?>",
upload_url: "<?php $options->index('/action/upload?do=modify&cid=' . $attachment->cid); ?>",
post_params: {"__typecho_uid" : "<?php echo Typecho_Cookie::get('__typecho_uid'); ?>",
"__typecho_authCode" : "<?php echo addslashes(Typecho_Cookie::get('__typecho_authCode')); ?>"},
file_size_limit : "<?php $val = function_exists('ini_get') ? trim(ini_get('upload_max_filesize')) : 0;
$last = strtolower($val[strlen($val)-1]);
switch($last) {
// The 'G' modifier is available since PHP 5.1.0
case 'g':
$val *= 1024;
case 'm':
$val *= 1024;
case 'k':
$val *= 1024;
}
echo $val;
?> byte",
file_types : "<?php echo '' == $attachment->attachment->type ? $attachment->attachment->name :
'*.' . $attachment->attachment->type; ?>",
file_types_description : "<?php _e('所有文件'); ?>",
file_upload_limit : 0,
file_queue_limit : 1,
debug: false,
//Handle Settings
file_dialog_complete_handler : fileDialogComplete,
upload_start_handler : uploadStart,
upload_progress_handler : uploadProgress,
upload_success_handler : uploadSuccess,
queue_complete_handler : uploadComplete,
upload_error_handler : uploadError,
swfupload_loaded_handler : swfuploadLoaded,
// Button Settings
button_placeholder_id : "swfu-placeholder",
button_height: _size.height,
button_text: '',
button_text_style: '',
button_text_left_padding: 14,
button_text_top_padding: 0,
button_width: _size.width,
button_window_mode: SWFUpload.WINDOW_MODE.TRANSPARENT,
button_cursor: SWFUpload.CURSOR.HAND
};
swfu = new SWFUpload(settings);
});
})();
</script>
<?php
include 'footer.php';
?>