commit
3ea7c0ecee
@ -0,0 +1,240 @@ |
||||
/* For licensing terms, see /LICENSE */ |
||||
|
||||
(function () { |
||||
CKEDITOR.dialog.add( |
||||
'vimeoEmbedDialog', |
||||
function (editor) { |
||||
var lang = editor.lang.ckeditor_vimeo_embed; |
||||
|
||||
function post(url, data, callback) { |
||||
var xhr = new XMLHttpRequest(); |
||||
xhr.open( 'POST', url, true ); |
||||
xhr.onreadystatechange = function() { |
||||
if ( xhr.readyState == 4 ) { |
||||
callback(xhr.response); |
||||
xhr = null; |
||||
} |
||||
}; |
||||
xhr.send(data); |
||||
|
||||
return xhr; |
||||
} |
||||
|
||||
function setUploadStatus(status) { |
||||
var elStatus = document.getElementById('ve-upload-status'); |
||||
|
||||
if ('process' === status) { |
||||
elStatus.textContent = lang.uploadProcess; |
||||
|
||||
return; |
||||
} |
||||
|
||||
if ('end' === status) { |
||||
elStatus.textContent = lang.uploadEnd; |
||||
|
||||
return; |
||||
} |
||||
|
||||
elStatus.textContent = ''; |
||||
} |
||||
|
||||
var xhrPost = null; |
||||
var stillUploading = false; |
||||
var embedHtml = ''; |
||||
|
||||
return { |
||||
title: 'Vimeo Embed', |
||||
minWidth: 600, |
||||
minHeight: 400, |
||||
contents: [ |
||||
{ |
||||
id: 've-basic', |
||||
title: lang.upload, |
||||
label: lang.upload, |
||||
elements: [ |
||||
{ |
||||
type: 'text', |
||||
id: 'title', |
||||
label: lang.title, |
||||
}, |
||||
{ |
||||
type: 'textarea', |
||||
id: 'description', |
||||
label: lang.description |
||||
}, |
||||
{ |
||||
type: 'html', |
||||
html: '<input id="ve-file" type="file" accept="video/*">' |
||||
}, |
||||
{ |
||||
type: 'vbox', |
||||
children: [ |
||||
{ |
||||
type: 'checkbox', |
||||
id: 'privacy-download', |
||||
label: lang.privacyDownload |
||||
}, |
||||
{ |
||||
type: 'hbox', |
||||
widths: ['65%', '35%'], |
||||
children: [ |
||||
{ |
||||
type: 'select', |
||||
id: 'privacy-embed', |
||||
label: lang.privacyEmbed, |
||||
items: [ |
||||
// [lang.privacyEmbedPrivate, 'private'],
|
||||
[lang.privacyEmbedPublic, 'public'], |
||||
[lang.privacyEmbedWhitelist, 'whitelist'], |
||||
], |
||||
'default': 'public' |
||||
}, |
||||
{ |
||||
type: 'text', |
||||
id: 'privacy-embed-whitelist', |
||||
label: lang.privacyEmbedWhitelistList |
||||
}, |
||||
] |
||||
}, |
||||
{ |
||||
type: 'select', |
||||
id: 'privacy-view', |
||||
label: lang.privacyView, |
||||
items: [ |
||||
[lang.privacyViewAnybody, 'anybody'], |
||||
[lang.privacyViewContacts, 'contacts'], |
||||
[lang.privacyViewDisable, 'disable'], |
||||
[lang.privacyViewNobody, 'nobody'], |
||||
[lang.privacyViewUnlisted, 'unlisted'], |
||||
// [lang.privacyViewPassword, 'password'],
|
||||
// [lang.privacyViewUsers, 'users'],
|
||||
], |
||||
'default': 'unlisted' |
||||
} |
||||
] |
||||
}, |
||||
{ |
||||
type: 'hbox', |
||||
widths: ['1%', '100%'], |
||||
children: [ |
||||
{ |
||||
type: 'button', |
||||
id: 'submit', |
||||
label: lang.uploadFile, |
||||
title: lang.uploadFile, |
||||
onClick: function () { |
||||
var dialog = this.getDialog(); |
||||
|
||||
var title = dialog.getValueOf('ve-basic', 'title').trim(); |
||||
var description = dialog.getValueOf('ve-basic', 'description').trim(); |
||||
var privacyDownload = dialog.getValueOf('ve-basic', 'privacy-download'); |
||||
var privacyEmbed = dialog.getValueOf('ve-basic', 'privacy-embed'); |
||||
var privacyEmbedWhiteList = dialog.getValueOf('ve-basic', 'privacy-embed-whitelist').trim(); |
||||
var privacyView = dialog.getValueOf('ve-basic', 'privacy-view'); |
||||
var files = document.getElementById('ve-file').files; |
||||
|
||||
if (xhrPost) { |
||||
return; |
||||
} |
||||
|
||||
if (!title || !title.length) { |
||||
dialog.getContentElement('ve-basic', 'title').focus(); |
||||
|
||||
return; |
||||
} |
||||
|
||||
if (!files || files.length !== 1) { |
||||
document.getElementById('ve-file').focus(); |
||||
|
||||
return; |
||||
} |
||||
|
||||
if (privacyEmbed === 'whitelist' && !privacyEmbedWhiteList.length) { |
||||
dialog.getContentElement('ve-basic', 'privacy-embed-whitelist').focus(); |
||||
|
||||
return; |
||||
} |
||||
|
||||
stillUploading = true; |
||||
embedHtml = ''; |
||||
|
||||
setUploadStatus('process'); |
||||
|
||||
var formData = new FormData(); |
||||
formData.append('title', title); |
||||
formData.append('description', description); |
||||
formData.append('ve_file', files[0], files[0].name); |
||||
formData.append('privacy_download', privacyDownload); |
||||
formData.append('privacy_embed', privacyEmbed); |
||||
formData.append('privacy_embed_whitelist', privacyEmbedWhiteList); |
||||
formData.append('privacy_view', privacyView); |
||||
|
||||
xhrPost = post( |
||||
CKEDITOR.plugins.getPath('ckeditor_vimeo_embed') + 'integration/upload.php', |
||||
formData, |
||||
function (response) { |
||||
xhrPost = null; |
||||
|
||||
if (!response) { |
||||
return; |
||||
} |
||||
|
||||
stillUploading = false; |
||||
|
||||
var json = JSON.parse(response); |
||||
|
||||
if (json.error) { |
||||
alert(json.message); |
||||
setUploadStatus(''); |
||||
} else { |
||||
embedHtml = json.embed; |
||||
|
||||
setUploadStatus('end'); |
||||
|
||||
dialog.disableButton('cancel'); |
||||
} |
||||
} |
||||
); |
||||
} |
||||
}, |
||||
{ |
||||
type: 'html', |
||||
html: '<span id="ve-upload-status" style="font-weight: bold;font-size: 14px;line-height: 28px;vertical-align: middle;height: 28px;display: table-cell;"></span>' |
||||
} |
||||
] |
||||
}, |
||||
] |
||||
}, |
||||
], |
||||
onShow: function () { |
||||
xhrPost = null; |
||||
stillUploading = false; |
||||
embedHtml = ''; |
||||
|
||||
setUploadStatus(''); |
||||
|
||||
document.getElementById('ve-file').value = null; |
||||
|
||||
this.enableButton('cancel'); |
||||
}, |
||||
onOk: function () { |
||||
if (stillUploading) { |
||||
alert(lang.alertStillUploading); |
||||
|
||||
return false; |
||||
} |
||||
|
||||
if (embedHtml) { |
||||
editor.insertHtml(embedHtml); |
||||
} |
||||
}, |
||||
onCancel: function (evt) { |
||||
if (evt.data.hide && xhrPost) { |
||||
xhrPost.abort(); |
||||
xhrPost = null; |
||||
} |
||||
} |
||||
}; |
||||
} |
||||
); |
||||
})(); |
||||
|
After Width: | Height: | Size: 2.2 KiB |
@ -0,0 +1,106 @@ |
||||
<?php |
||||
/* For licensing terms, see /LICENSE */ |
||||
|
||||
use Vimeo\Vimeo; |
||||
|
||||
require __DIR__.'/../../../../../../global.inc.php'; |
||||
|
||||
$config = api_get_configuration_sub_value('ckeditor_vimeo_embed/config'); |
||||
|
||||
if (false === $config || |
||||
empty($config['client_id']) || empty($config['client_secret']) || empty($config['access_token']) |
||||
) { |
||||
echo json_encode(['error' => true, 'message' => get_lang('NotAllowed')]); |
||||
exit; |
||||
} |
||||
|
||||
header('Content-Type: application/json'); |
||||
|
||||
try { |
||||
if (empty($_FILES) || |
||||
empty($_POST) || |
||||
empty($_POST['title']) || |
||||
!isset($_POST['description']) || |
||||
empty($_FILES['ve_file']) || |
||||
!isset($_POST['privacy_download']) || |
||||
empty($_POST['privacy_embed']) || |
||||
!isset($_POST['privacy_embed_whitelist']) || |
||||
empty($_POST['privacy_view']) |
||||
) { |
||||
throw new Exception('Missing params.'); |
||||
} |
||||
|
||||
if ($_FILES['ve_file']['error'] !== UPLOAD_ERR_OK) { |
||||
throw new Exception("File error ({$_FILES['ve_file']['error']})."); |
||||
} |
||||
|
||||
if (empty($config['access_token'])) { |
||||
throw new Exception( |
||||
'You can not upload a file without an access token. You can find this token on your app page.' |
||||
); |
||||
} |
||||
|
||||
$vimeo = new Vimeo($config['client_id'], $config['client_secret'], $config['access_token']); |
||||
|
||||
$uri = $vimeo->upload( |
||||
$_FILES['ve_file']['tmp_name'], |
||||
array( |
||||
'name' => $_POST['title'], |
||||
'description' => $_POST['description'], |
||||
'privacy' => [ |
||||
'download' => $_POST['privacy_download'] === 'true', |
||||
'embed' => $_POST['privacy_embed'], |
||||
'view' => $_POST['privacy_view'], |
||||
], |
||||
) |
||||
); |
||||
|
||||
if ('whitelist' === $_POST['privacy_embed'] && !empty($_POST['privacy_embed_whitelist'])) { |
||||
$vimeo->request( |
||||
"$uri/privacy/domains/{$_POST['privacy_embed_whitelist']}", |
||||
[], |
||||
'PUT' |
||||
); |
||||
} |
||||
|
||||
$videoData = $vimeo->request("$uri?fields=link"); |
||||
|
||||
$singleUri = str_replace('videos', 'video', $uri); |
||||
|
||||
$embed = '<div class="embeddedContent"> |
||||
<div style="padding:56.25% 0 0 0;position:relative;"> |
||||
<iframe allow="autoplay; fullscreen" allowfullscreen frameborder="0" |
||||
src="https://player.vimeo.com'.$singleUri.'" |
||||
style="position:absolute;top:0;left:0;width:100%;height:100%;"></iframe> |
||||
</div> |
||||
</div>'; |
||||
|
||||
echo json_encode( |
||||
[ |
||||
'uploaded' => true, |
||||
'url' => $videoData['body']['link'], |
||||
'embed' => $embed, |
||||
] |
||||
); |
||||
} catch (VimeoUploadException $exception) { |
||||
echo json_encode( |
||||
[ |
||||
'error' => true, |
||||
'message' => $e->getMessage(), |
||||
] |
||||
); |
||||
} catch (VimeoRequestException $exception) { |
||||
echo json_encode( |
||||
[ |
||||
'error' => true, |
||||
'message' => $exception->getMessage(), |
||||
] |
||||
); |
||||
} catch (Exception $exception) { |
||||
echo json_encode( |
||||
[ |
||||
'error' => true, |
||||
'message' => $exception->getMessage(), |
||||
] |
||||
); |
||||
} |
||||
@ -0,0 +1,27 @@ |
||||
/* For licensing terms, see /LICENSE */ |
||||
|
||||
CKEDITOR.plugins.setLang('ckeditor_vimeo_embed', 'en', { |
||||
upload: 'Upload', |
||||
privacy: 'Privacy', |
||||
title: 'Title', |
||||
description: 'Description', |
||||
selectFile: 'Select video file from your computer', |
||||
uploadFile: 'Upload file', |
||||
privacyDownload: 'Whether people can download the video', |
||||
privacyEmbed: 'Where the video can be embedded?', |
||||
privacyEmbedPrivate: "The video can't be embedded", |
||||
privacyEmbedPublic: 'The video can be embedded', |
||||
privacyEmbedWhitelist: 'The video can be embedded on the specified domains only', |
||||
privacyView: 'Who can view the video on Vimeo?', |
||||
privacyViewAnybody: 'Anyone can access the video', |
||||
privacyViewContacts: "Only the owner's contacts can access the video", |
||||
privacyViewDisable: 'The video is disabled', |
||||
privacyViewNobody: 'No one except the owner can access the video', |
||||
privacyViewPassword: 'Only those with the password can access the video', |
||||
privacyViewUnlisted: 'The video is unlisted. Anyone can access it, but it doesn\'t appear in search', |
||||
privacyViewUsers: 'Only Vimeo members can access the video', |
||||
privacyEmbedWhitelistList: 'Whitelist (indicate domain)', |
||||
alertStillUploading: 'Current video file is uploading…', |
||||
uploadEnd: 'Video uploaded ✔', |
||||
uploadProcess: 'Uploading video, please wait…', |
||||
}); |
||||
@ -0,0 +1,27 @@ |
||||
/* For licensing terms, see /LICENSE */ |
||||
|
||||
CKEDITOR.plugins.setLang('ckeditor_vimeo_embed', 'es', { |
||||
upload: 'Subir', |
||||
privacy: 'Privacidad', |
||||
title: 'Título', |
||||
description: 'Descripción', |
||||
selectFile: 'Seleccionar archivo de video de tu computadora', |
||||
uploadFile: 'Subir archivo', |
||||
privacyDownload: 'Las personas pueden descargar el video', |
||||
privacyEmbed: '¿Dónde se puede incrustar el video?', |
||||
privacyEmbedPrivate: "El vídeo no se puede insertar", |
||||
privacyEmbedPublic: 'El vídeo se puede insertar', |
||||
privacyEmbedWhitelist: 'El vídeo se puede insertar sólo en los dominios especificados', |
||||
privacyView: '¿Quién puede ver el vídeo en Vimeo?', |
||||
privacyViewAnybody: 'Cualquiera puede acceder al video', |
||||
privacyViewContacts: "Sólo los contactos del propietario pueden acceder al vídeo", |
||||
privacyViewDisable: 'El vídeo está deshabilitado', |
||||
privacyViewNobody: 'Nadie, excepto el propietario, puede acceder al vídeo', |
||||
privacyViewPassword: 'Sólo aquellos con la contraseña pueden acceder al vídeo', |
||||
privacyViewUnlisted: 'El vídeo no está en la lista. Cualquiera puede acceder a él, pero no aparece en la búsqueda', |
||||
privacyViewUsers: 'Sólo los miembros de Vimeo pueden acceder al vídeo', |
||||
privacyEmbedWhitelistList: 'Lista blanca (indicar dominio)', |
||||
alertStillUploading: 'El archivo de video actual se está cargando…', |
||||
uploadEnd: 'Vídeo subido ✔', |
||||
uploadProcess: 'Subiendo video, por favor espere…', |
||||
}); |
||||
@ -0,0 +1,22 @@ |
||||
/* For licensing terms, see /LICENSE */ |
||||
|
||||
(function () { |
||||
CKEDITOR.plugins.add('ckeditor_vimeo_embed', { |
||||
lang: ['en', 'es'], |
||||
icons: 'VimeoEmbed', |
||||
init: function (editor) { |
||||
editor.addCommand( |
||||
'vimeoEmbed', |
||||
new CKEDITOR.dialogCommand('vimeoEmbedDialog') |
||||
); |
||||
|
||||
editor.ui.addButton('VimeoEmbed', { |
||||
label: 'Embed a Vimeo video', |
||||
command: 'vimeoEmbed', |
||||
toolbar: 'insert,0' |
||||
}); |
||||
|
||||
CKEDITOR.dialog.add('vimeoEmbedDialog', this.path + 'dialogs/vimeo_embed.js'); |
||||
} |
||||
}); |
||||
})(); |
||||
Loading…
Reference in new issue