mirror of
https://github.com/typecho/typecho.git
synced 2025-03-23 19:40:22 +01:00
Merge branch 'master' of https://github.com/typecho/typecho-replica
This commit is contained in:
commit
832ff97d9a
@ -30,7 +30,8 @@
|
||||
$('a').each(function () {
|
||||
var t = $(this), href = t.attr('href');
|
||||
|
||||
if (/^<?php echo preg_quote($options->adminUrl, '/'); ?>.*$/.exec(href)
|
||||
if ((href.length > 1 && href[0] == '#')
|
||||
/^<?php echo preg_quote($options->adminUrl, '/'); ?>.*$/.exec(href)
|
||||
|| /^<?php echo substr(preg_quote(Typecho_Common::url('s', $options->index), '/'), 0, -1); ?>action\/[_a-zA-Z0-9\/]+.*$/.exec(href)) {
|
||||
return;
|
||||
}
|
||||
|
@ -1980,7 +1980,6 @@ ul.typecho-list-notable li .loading {
|
||||
|
||||
.visuallyhidden {
|
||||
border: 0;
|
||||
clip: rect(0 0 0 0);
|
||||
height: 1px;
|
||||
margin: -1px;
|
||||
overflow: hidden;
|
||||
|
@ -50,16 +50,17 @@ $(document).ready(function() {
|
||||
$('.upload-file').fileUpload({
|
||||
url : '<?php $options->index('/action/upload'
|
||||
. (isset($fileParentContent) ? '?cid=' . $fileParentContent->cid : '')); ?>',
|
||||
types : '<?php
|
||||
$attachmentTypes = $options->allowedAttachmentTypes;
|
||||
$attachmentTypesCount = count($attachmentTypes);
|
||||
for ($i = 0; $i < $attachmentTypesCount; $i ++) {
|
||||
echo '*.' . $attachmentTypes[$i];
|
||||
if ($i < $attachmentTypesCount - 1) {
|
||||
echo ';';
|
||||
}
|
||||
types : <?php
|
||||
$attachmenttypes = $options->allowedattachmenttypes;
|
||||
$attachmenttypescount = count($attachmenttypes);
|
||||
$types = array();
|
||||
|
||||
for ($i = 0; $i < $attachmenttypescount; $i ++) {
|
||||
$types[] = '.' . $attachmenttypes[$i];
|
||||
}
|
||||
?>',
|
||||
|
||||
echo json_encode($types);
|
||||
?>,
|
||||
typesError : '<?php _e('附件 %s 的类型不被支持'); ?>',
|
||||
onUpload : fileUploadStart,
|
||||
onError : function (id) {
|
||||
@ -72,16 +73,17 @@ $(document).ready(function() {
|
||||
$('#upload-panel').filedrop({
|
||||
url : '<?php $options->index('/action/upload'
|
||||
. (isset($fileParentContent) ? '?cid=' . $fileParentContent->cid : '')); ?>',
|
||||
allowedfileextensions : [<?php
|
||||
$attachmentTypes = $options->allowedAttachmentTypes;
|
||||
$attachmentTypesCount = count($attachmentTypes);
|
||||
for ($i = 0; $i < $attachmentTypesCount; $i ++) {
|
||||
echo '".' . $attachmentTypes[$i] . '"';
|
||||
if ($i < $attachmentTypesCount - 1) {
|
||||
echo ',';
|
||||
}
|
||||
allowedfileextensions : <?php
|
||||
$attachmenttypes = $options->allowedattachmenttypes;
|
||||
$attachmenttypescount = count($attachmenttypes);
|
||||
$types = array();
|
||||
|
||||
for ($i = 0; $i < $attachmenttypescount; $i ++) {
|
||||
$types[] = '.' . $attachmenttypes[$i];
|
||||
}
|
||||
?>],
|
||||
|
||||
echo json_encode($types);
|
||||
?>,
|
||||
|
||||
maxfilesize : <?php
|
||||
$val = function_exists('ini_get') ? trim(ini_get('upload_max_filesize')) : 0;
|
||||
|
@ -13,7 +13,7 @@ if (isset($post) || isset($page)) {
|
||||
?>
|
||||
|
||||
<div id="upload-panel" class="p">
|
||||
将要上传的文件拖放到这里 或者 <a href="" class="upload-file">选择文件上传</a><input type="file" class="visuallyhidden">
|
||||
将要上传的文件拖放到这里 或者 <a href="###" class="upload-file">选择文件上传</a>
|
||||
<ul id="file-list">
|
||||
<?php while ($attachment->next()): ?>
|
||||
<li data-cid="<?php $attachment->cid(); ?>" data-url="<?php echo $attachment->attachment->url; ?>" data-image="<?php echo $attachment->attachment->isImage ? 1 : 0; ?>"><input type="hidden" name="attachment[]" value="<?php $attachment->cid(); ?>" /><a class="file" target="_blank" href="<?php $options->adminUrl('media.php?cid=' . $attachment->cid); ?>"><?php $attachment->title(); ?></a> <?php echo number_format(ceil($attachment->attachment->size / 1024)); ?> Kb <a href="#" class="insert">插入</a> <a href="#" class="delete">×</a></li>
|
||||
|
@ -91,22 +91,22 @@
|
||||
onUpload : null,
|
||||
onComplete : null,
|
||||
onError : null,
|
||||
types : null,
|
||||
types : [],
|
||||
name : 'file',
|
||||
typesError : 'file type error',
|
||||
single : false
|
||||
}, options),
|
||||
p = this.parent().css('position', 'relative'),
|
||||
input = $('<input name="' + s.name + '" type="file" />').css({
|
||||
input = $('<input class="visuallyhidden" name="' + s.name + '" type="file" />').css({
|
||||
opacity : 0,
|
||||
cursor : 'pointer',
|
||||
position : 'absolute',
|
||||
width : this.outerWidth(),
|
||||
height : this.outerHeight,
|
||||
height : this.outerHeight(),
|
||||
left : this.offset().left - p.offset().left,
|
||||
top : this.offset().top - p.offset().top
|
||||
}).insertAfter(this), queue = {}, prefix = 'queue-',
|
||||
index = 0, types = [];
|
||||
index = 0;
|
||||
|
||||
window.fileUploadComplete = function (id, url, data) {
|
||||
if (s.single) {
|
||||
@ -138,15 +138,6 @@
|
||||
}
|
||||
};
|
||||
|
||||
if (!!s.types) {
|
||||
var list = s.types.split(';');
|
||||
for (var i = 0; i < list.length; i ++) {
|
||||
var parts = list[i].split('.');
|
||||
parts.shift();
|
||||
types.push('.' + parts.join('.'));
|
||||
}
|
||||
}
|
||||
|
||||
function upload (frame, id) {
|
||||
var form = $('<form action="' + s.url + '" method="post" enctype="multipart/form-data"><input type="hidden" name="_id" value="' + id + '" /></form>'),
|
||||
replace = input.clone(true).val(''),
|
||||
@ -162,12 +153,12 @@
|
||||
}
|
||||
|
||||
function checkTypes (file) {
|
||||
if (!types.length) {
|
||||
if (!s.types.length) {
|
||||
return true;
|
||||
}
|
||||
|
||||
for (var i = 0; i < types.length; i ++) {
|
||||
var ext = types[i];
|
||||
for (var i = 0; i < s.types.length; i ++) {
|
||||
var ext = s.types[i];
|
||||
|
||||
if (file.length <= ext.length) {
|
||||
continue;
|
||||
|
278
admin/media.php
278
admin/media.php
@ -27,10 +27,8 @@ Typecho_Widget::widget('Widget_Contents_Attachment_Edit')->to($attachment);
|
||||
</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>
|
||||
将要替换的文件拖放到这里 或者 <a href="###" class="upload-file">选择替换文件</a>
|
||||
<ul id="file-list"></ul>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-mb-12 col-tb-4">
|
||||
@ -44,148 +42,144 @@ Typecho_Widget::widget('Widget_Contents_Attachment_Edit')->to($attachment);
|
||||
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 src="<?php $options->adminUrl('javascript/filedrop.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;
|
||||
$(document).ready(function() {
|
||||
var errorWord = '<?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;
|
||||
}
|
||||
|
||||
$val = number_format(ceil($val / (1024 *1024)));
|
||||
_e('附件上传失败, 请确认附件尺寸没有超过 %s 并且服务器附件目录可以写入', "{$val}Mb"); ?>',
|
||||
loading = $('<img src="<?php $options->adminUrl('images/ajax-loader.gif'); ?>" style="display:none" />')
|
||||
.appendTo(document.body);
|
||||
|
||||
$('#attachment-url').click(function () {
|
||||
$(this).select();
|
||||
});
|
||||
|
||||
$('.operate-delete').click(function () {
|
||||
var t = $(this), href = t.attr('href');
|
||||
|
||||
if (confirm(t.attr('lang'))) {
|
||||
window.location.href = href;
|
||||
}
|
||||
|
||||
return false;
|
||||
});
|
||||
|
||||
function fileUploadStart (file, id) {
|
||||
$('<li id="' + id + '" class="loading">'
|
||||
+ file + '</li>').prependTo('#file-list');
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
function fileUploadComplete (id, url, data) {
|
||||
$('#' + id).html('<?php _e('附件 %s 已经替换'); ?>'.replace('%s', data.title))
|
||||
.effect('highlight', '#AACB36', 1000, function () {
|
||||
$(this).remove();
|
||||
});
|
||||
})();
|
||||
}
|
||||
|
||||
$('.upload-file').fileUpload({
|
||||
url : '<?php $options->index('/action/upload?do=modify&cid=' . $attachment->cid); ?>',
|
||||
types : ['.<?php $attachment->attachment->type(); ?>'],
|
||||
typesError : '<?php _e('附件 %s 的类型与要替换的原文件不一致'); ?>',
|
||||
onUpload : fileUploadStart,
|
||||
onError : function (id) {
|
||||
$('#' + id).remove();
|
||||
alert(errorWord);
|
||||
},
|
||||
onComplete : fileUploadComplete
|
||||
});
|
||||
|
||||
$('#upload-panel').filedrop({
|
||||
url : '<?php $options->index('/action/upload'
|
||||
. (isset($fileParentContent) ? '?cid=' . $fileParentContent->cid : '')); ?>',
|
||||
allowedfileextensions : ['.<?php $attachment->attachment->type(); ?>'],
|
||||
|
||||
maxfilesize : <?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 ceil($val / (1024 * 1024));
|
||||
?>,
|
||||
|
||||
maxfiles : 1,
|
||||
|
||||
error: function(err, file) {
|
||||
switch(err) {
|
||||
case 'BrowserNotSupported':
|
||||
alert('<?php _e('浏览器不支持拖拽上传'); ?>');
|
||||
break;
|
||||
case 'TooManyFiles':
|
||||
alert('<?php _e('一次只能上传一个文件'); ?>');
|
||||
break;
|
||||
case 'FileTooLarge':
|
||||
alert('<?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;
|
||||
}
|
||||
|
||||
$val = number_format(ceil($val / (1024 *1024)));
|
||||
_e('附件尺寸不能超过 %s', "{$val}Mb"); ?>');
|
||||
break;
|
||||
case 'FileTypeNotAllowed':
|
||||
// The file type is not in the specified list 'allowedfiletypes'
|
||||
break;
|
||||
case 'FileExtensionNotAllowed':
|
||||
alert('<?php _e('附件 %s 的类型不被支持'); ?>'.replace('%s', file.name));
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
dragOver : function () {
|
||||
$(this).addClass('drag');
|
||||
},
|
||||
|
||||
dragLeave : function () {
|
||||
$(this).removeClass('drag');
|
||||
},
|
||||
|
||||
drop : function () {
|
||||
$(this).removeClass('drag');
|
||||
},
|
||||
|
||||
uploadOpened : function (i, file, len) {
|
||||
fileUploadStart(file.name, 'drag-' + i);
|
||||
},
|
||||
|
||||
uploadFinished : function (i, file, response) {
|
||||
fileUploadComplete('drag-' + i, response[0], response[1]);
|
||||
}
|
||||
});
|
||||
});
|
||||
</script>
|
||||
<?php
|
||||
include 'footer.php';
|
||||
|
@ -275,11 +275,7 @@ class Widget_Upload extends Widget_Abstract_Contents implements Widget_Interface
|
||||
if (0 == $file['error'] && is_uploaded_file($file['tmp_name'])) {
|
||||
$result = self::uploadHandle($file);
|
||||
|
||||
if (false === $result) {
|
||||
$this->response->setStatus(502);
|
||||
exit;
|
||||
} else {
|
||||
|
||||
if (false !== $result) {
|
||||
$struct = array(
|
||||
'title' => $result['name'],
|
||||
'slug' => $result['name'],
|
||||
@ -370,11 +366,7 @@ class Widget_Upload extends Widget_Abstract_Contents implements Widget_Interface
|
||||
|
||||
$result = self::modifyHandle($this->row, $file);
|
||||
|
||||
if (false === $result) {
|
||||
$this->response->setStatus(502);
|
||||
exit;
|
||||
} else {
|
||||
|
||||
if (false !== $result) {
|
||||
$this->update(array(
|
||||
'text' => serialize($result)
|
||||
), $this->db->sql()->where('cid = ?', $this->cid));
|
||||
|
Loading…
x
Reference in New Issue
Block a user