Actualización
This commit is contained in:
2
main/inc/lib/svg-edit/README
Normal file
2
main/inc/lib/svg-edit/README
Normal file
@@ -0,0 +1,2 @@
|
||||
This directory includes the changes made to the svgedit library.
|
||||
Just copy this dir and paste it in clean svg editor package.
|
||||
17
main/inc/lib/svg-edit/config.js
Normal file
17
main/inc/lib/svg-edit/config.js
Normal file
@@ -0,0 +1,17 @@
|
||||
/* see https://code.google.com/p/svg-edit/wiki/ConfigOptions */
|
||||
svgEditor.setConfig({
|
||||
extensions: [
|
||||
'ext-php_savefile_chamilo.js',
|
||||
'ext-eyedropper.js',
|
||||
'ext-shapes.js',
|
||||
'ext-polygon.js',
|
||||
'ext-star.js'
|
||||
],
|
||||
noStorageOnLoad: 'true',
|
||||
selectNew: true,
|
||||
no_save_warning: true,
|
||||
emptyStorageOnDecline: true,
|
||||
iconsize: 'm',
|
||||
allowedOrigins: [window.location.origin]
|
||||
// May be 'null' (as a string) when used as a file:// URL
|
||||
});
|
||||
6
main/inc/lib/svg-edit/custom.css
Normal file
6
main/inc/lib/svg-edit/custom.css
Normal file
@@ -0,0 +1,6 @@
|
||||
#main_icon {
|
||||
width:38px !important;
|
||||
}
|
||||
#tools_top {
|
||||
left: 55px !important;
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
<?xml version="1.0"?>
|
||||
<svg width="1000" height="1000" xmlns="http://www.w3.org/2000/svg" xmlns:svg="http://www.w3.org/2000/svg">
|
||||
<g>
|
||||
<title>Layer 1</title>
|
||||
<rect id="svg_2" height="717.432104" width="862.814821" y="87.209869" x="63.851915" stroke-linecap="null" stroke-linejoin="null" stroke-dasharray="null" stroke-width="null" fill="#00ffff"/>
|
||||
<text font-style="italic" font-weight="normal" transform="matrix(14.5579, 0, 0, 19.1025, -3784.43, -4491.74)" xml:space="preserve" text-anchor="middle" font-family="Cursive" font-size="24" id="svg_1" y="267.244915" x="291.750555" stroke-linecap="null" stroke-linejoin="null" stroke-dasharray="null" stroke-width="0" fill="#000000">ICO</text>
|
||||
</g>
|
||||
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 708 B |
67
main/inc/lib/svg-edit/extensions/ext-executablebuilder.js
Normal file
67
main/inc/lib/svg-edit/extensions/ext-executablebuilder.js
Normal file
@@ -0,0 +1,67 @@
|
||||
/*globals svgEditor*/
|
||||
/*
|
||||
Depends on Firefox add-on and executables from https://github.com/brettz9/webappfind
|
||||
|
||||
Todos:
|
||||
1. See WebAppFind Readme for SVG-related todos
|
||||
*/
|
||||
(function () {'use strict';
|
||||
|
||||
var pathID,
|
||||
saveMessage = 'webapp-save',
|
||||
readMessage = 'webapp-read',
|
||||
excludedMessages = [readMessage, saveMessage];
|
||||
|
||||
window.addEventListener('message', function(e) {
|
||||
if (e.origin !== window.location.origin || // PRIVACY AND SECURITY! (for viewing and saving, respectively)
|
||||
(!Array.isArray(e.data) || excludedMessages.indexOf(e.data[0]) > -1) // Validate format and avoid our post below
|
||||
) {
|
||||
return;
|
||||
}
|
||||
var svgString,
|
||||
messageType = e.data[0];
|
||||
switch (messageType) {
|
||||
case 'webapp-view':
|
||||
// Populate the contents
|
||||
pathID = e.data[1];
|
||||
|
||||
svgString = e.data[2];
|
||||
svgEditor.loadFromString(svgString);
|
||||
|
||||
/*if ($('#tool_save_file')) {
|
||||
$('#tool_save_file').disabled = false;
|
||||
}*/
|
||||
break;
|
||||
case 'webapp-save-end':
|
||||
alert('save complete for pathID ' + e.data[1] + '!');
|
||||
break;
|
||||
default:
|
||||
throw 'Unexpected mode';
|
||||
}
|
||||
}, false);
|
||||
|
||||
window.postMessage([readMessage], window.location.origin !== 'null' ? window.location.origin : '*'); // Avoid "null" string error for file: protocol (even though file protocol not currently supported by add-on)
|
||||
|
||||
svgEditor.addExtension('WebAppFind', function() {
|
||||
|
||||
return {
|
||||
name: 'WebAppFind',
|
||||
svgicons: svgEditor.curConfig.extPath + 'executablebuilder-icocreator.svg',
|
||||
buttons: [{
|
||||
id: 'webappfind_ico_export', //
|
||||
type: 'app_menu',
|
||||
title: 'Export ICO Image back to Disk',
|
||||
position: 4, // Before 0-based index position 4 (after the regular "Save Image (S)")
|
||||
events: {
|
||||
click: function () {
|
||||
if (!pathID) { // Not ready yet as haven't received first payload
|
||||
return;
|
||||
}
|
||||
window.postMessage([saveMessage, pathID, svgEditor.canvas.getSvgString()], window.location.origin);
|
||||
}
|
||||
}
|
||||
}]
|
||||
};
|
||||
});
|
||||
|
||||
}());
|
||||
474
main/inc/lib/svg-edit/extensions/ext-imagelib.js
Normal file
474
main/inc/lib/svg-edit/extensions/ext-imagelib.js
Normal file
@@ -0,0 +1,474 @@
|
||||
/*globals $, svgEditor, svgedit, svgCanvas, DOMParser*/
|
||||
/*jslint vars: true, eqeq: true, es5: true, todo: true */
|
||||
/*
|
||||
* ext-imagelib.js
|
||||
*
|
||||
* Licensed under the MIT License
|
||||
*
|
||||
* Copyright(c) 2010 Alexis Deveria
|
||||
*
|
||||
*/
|
||||
|
||||
svgEditor.addExtension("imagelib", function() {'use strict';
|
||||
|
||||
var uiStrings = svgEditor.uiStrings;
|
||||
|
||||
$.extend(uiStrings, {
|
||||
imagelib: {
|
||||
select_lib: 'Select an image library',
|
||||
show_list: 'Show library list',
|
||||
import_single: 'Import single',
|
||||
import_multi: 'Import multiple',
|
||||
open: 'Open as new document'
|
||||
}
|
||||
});
|
||||
|
||||
var img_libs = [
|
||||
{
|
||||
name: 'Local library (local)',
|
||||
url: 'extensions/imagelib/index.php',
|
||||
//description: 'Demonstration library for SVG-edit on this server'// Chamilo change this line by below
|
||||
description: 'Course gallery'
|
||||
},
|
||||
{
|
||||
name: 'Local library',
|
||||
url: 'extensions/imagelib/groups.php',
|
||||
//description: 'Demonstration library for SVG-edit on this server'// Chamilo change this line by below
|
||||
description: 'Group gallery'
|
||||
},
|
||||
{
|
||||
name: 'Local library',
|
||||
url: 'extensions/imagelib/users.php',
|
||||
//description: 'Demonstration library for SVG-edit on this server'// Chamilo change this line by below
|
||||
description: 'Personal gallery'
|
||||
},
|
||||
{
|
||||
name: 'IAN Symbol Libraries',
|
||||
url: 'http://ian.umces.edu/symbols/catalog/svgedit/album_chooser.php',
|
||||
description: 'Free library of illustrations'
|
||||
}
|
||||
];
|
||||
|
||||
function closeBrowser() {
|
||||
$('#imgbrowse_holder').hide();
|
||||
}
|
||||
|
||||
function importImage(url) {
|
||||
var newImage = svgCanvas.addSvgElementFromJson({
|
||||
"element": "image",
|
||||
"attr": {
|
||||
"x": 0,
|
||||
"y": 0,
|
||||
"width": 0,
|
||||
"height": 0,
|
||||
"id": svgCanvas.getNextId(),
|
||||
"style": "pointer-events:inherit"
|
||||
}
|
||||
});
|
||||
svgCanvas.clearSelection();
|
||||
svgCanvas.addToSelection([newImage]);
|
||||
svgCanvas.setImageURL(url);
|
||||
}
|
||||
|
||||
var mode = 's';
|
||||
var multi_arr = [];
|
||||
var cur_meta;
|
||||
var tranfer_stopped = false;
|
||||
var pending = {};
|
||||
var preview, submit;
|
||||
|
||||
window.addEventListener("message", function(evt) {
|
||||
// Receive postMessage data
|
||||
var response = evt.data;
|
||||
|
||||
if (!response || typeof response !== "string") { // Todo: Should namespace postMessage API for this extension and filter out here
|
||||
// Do nothing
|
||||
return;
|
||||
}
|
||||
try { // This block can be removed if embedAPI moves away from a string to an object (if IE9 support not needed)
|
||||
var res = JSON.parse(response);
|
||||
if (res.namespace) { // Part of embedAPI communications
|
||||
return;
|
||||
}
|
||||
}
|
||||
catch (e) {}
|
||||
|
||||
var char1 = response.charAt(0);
|
||||
var id;
|
||||
var svg_str;
|
||||
var img_str;
|
||||
|
||||
if (char1 != "{" && tranfer_stopped) {
|
||||
tranfer_stopped = false;
|
||||
return;
|
||||
}
|
||||
|
||||
if (char1 == '|') {
|
||||
var secondpos = response.indexOf('|', 1);
|
||||
id = response.substr(1, secondpos-1);
|
||||
response = response.substr(secondpos+1);
|
||||
char1 = response.charAt(0);
|
||||
}
|
||||
|
||||
|
||||
// Hide possible transfer dialog box
|
||||
$('#dialog_box').hide();
|
||||
var entry, cur_meta;
|
||||
switch (char1) {
|
||||
case '{':
|
||||
// Metadata
|
||||
tranfer_stopped = false;
|
||||
cur_meta = JSON.parse(response);
|
||||
|
||||
pending[cur_meta.id] = cur_meta;
|
||||
|
||||
var name = (cur_meta.name || 'file');
|
||||
|
||||
var message = uiStrings.notification.retrieving.replace('%s', name);
|
||||
|
||||
if (mode != 'm') {
|
||||
$.process_cancel(message, function() {
|
||||
tranfer_stopped = true;
|
||||
// Should a message be sent back to the frame?
|
||||
|
||||
$('#dialog_box').hide();
|
||||
});
|
||||
} else {
|
||||
entry = $('<div>' + message + '</div>').data('id', cur_meta.id);
|
||||
preview.append(entry);
|
||||
cur_meta.entry = entry;
|
||||
}
|
||||
|
||||
return;
|
||||
case '<':
|
||||
svg_str = true;
|
||||
break;
|
||||
case 'd':
|
||||
if (response.indexOf('data:image/svg+xml') === 0) {
|
||||
var pre = 'data:image/svg+xml;base64,';
|
||||
var src = response.substring(pre.length);
|
||||
response = svgedit.utilities.decode64(src);
|
||||
svg_str = true;
|
||||
break;
|
||||
} else if (response.indexOf('data:image/') === 0) {
|
||||
img_str = true;
|
||||
break;
|
||||
}
|
||||
// Else fall through
|
||||
default:
|
||||
// TODO: See if there's a way to base64 encode the binary data stream
|
||||
// var str = 'data:;base64,' + svgedit.utilities.encode64(response, true);
|
||||
|
||||
// Assume it's raw image data
|
||||
// importImage(str);
|
||||
|
||||
// Don't give warning as postMessage may have been used by something else
|
||||
if (mode !== 'm') {
|
||||
closeBrowser();
|
||||
} else {
|
||||
pending[id].entry.remove();
|
||||
}
|
||||
// $.alert('Unexpected data was returned: ' + response, function() {
|
||||
// if (mode !== 'm') {
|
||||
// closeBrowser();
|
||||
// } else {
|
||||
// pending[id].entry.remove();
|
||||
// }
|
||||
// });
|
||||
return;
|
||||
}
|
||||
|
||||
switch (mode) {
|
||||
case 's':
|
||||
// Import one
|
||||
if (svg_str) {
|
||||
svgCanvas.importSvgString(response);
|
||||
} else if (img_str) {
|
||||
importImage(response);
|
||||
}
|
||||
closeBrowser();
|
||||
break;
|
||||
case 'm':
|
||||
// Import multiple
|
||||
multi_arr.push([(svg_str ? 'svg' : 'img'), response]);
|
||||
var title;
|
||||
cur_meta = pending[id];
|
||||
if (svg_str) {
|
||||
if (cur_meta && cur_meta.name) {
|
||||
title = cur_meta.name;
|
||||
} else {
|
||||
// Try to find a title
|
||||
var xml = new DOMParser().parseFromString(response, 'text/xml').documentElement;
|
||||
title = $(xml).children('title').first().text() || '(SVG #' + response.length + ')';
|
||||
}
|
||||
if (cur_meta) {
|
||||
preview.children().each(function() {
|
||||
if ($(this).data('id') == id) {
|
||||
if (cur_meta.preview_url) {
|
||||
$(this).html('<img src="' + cur_meta.preview_url + '">' + title);
|
||||
} else {
|
||||
$(this).text(title);
|
||||
}
|
||||
submit.removeAttr('disabled');
|
||||
}
|
||||
});
|
||||
} else {
|
||||
preview.append('<div>'+title+'</div>');
|
||||
submit.removeAttr('disabled');
|
||||
}
|
||||
} else {
|
||||
if (cur_meta && cur_meta.preview_url) {
|
||||
title = cur_meta.name || '';
|
||||
}
|
||||
if (cur_meta && cur_meta.preview_url) {
|
||||
entry = '<img src="' + cur_meta.preview_url + '">' + title;
|
||||
} else {
|
||||
entry = '<img src="' + response + '">';
|
||||
}
|
||||
|
||||
if (cur_meta) {
|
||||
preview.children().each(function() {
|
||||
if ($(this).data('id') == id) {
|
||||
$(this).html(entry);
|
||||
submit.removeAttr('disabled');
|
||||
}
|
||||
});
|
||||
} else {
|
||||
preview.append($('<div>').append(entry));
|
||||
submit.removeAttr('disabled');
|
||||
}
|
||||
|
||||
}
|
||||
break;
|
||||
case 'o':
|
||||
// Open
|
||||
if (!svg_str) {break;}
|
||||
svgEditor.openPrep(function(ok) {
|
||||
if (!ok) {return;}
|
||||
svgCanvas.clear();
|
||||
svgCanvas.setSvgString(response);
|
||||
// updateCanvas();
|
||||
});
|
||||
closeBrowser();
|
||||
break;
|
||||
}
|
||||
}, true);
|
||||
|
||||
function toggleMulti(show) {
|
||||
|
||||
$('#lib_framewrap, #imglib_opts').css({right: (show ? 200 : 10)});
|
||||
if (!preview) {
|
||||
preview = $('<div id=imglib_preview>').css({
|
||||
position: 'absolute',
|
||||
top: 45,
|
||||
right: 10,
|
||||
width: 180,
|
||||
bottom: 45,
|
||||
background: '#fff',
|
||||
overflow: 'auto'
|
||||
}).insertAfter('#lib_framewrap');
|
||||
|
||||
submit = $('<button disabled>Import selected</button>')
|
||||
.appendTo('#imgbrowse')
|
||||
.on("click touchend", function() {
|
||||
$.each(multi_arr, function(i) {
|
||||
var type = this[0];
|
||||
var data = this[1];
|
||||
if (type == 'svg') {
|
||||
svgCanvas.importSvgString(data);
|
||||
} else {
|
||||
importImage(data);
|
||||
}
|
||||
svgCanvas.moveSelectedElements(i*20, i*20, false);
|
||||
});
|
||||
preview.empty();
|
||||
multi_arr = [];
|
||||
$('#imgbrowse_holder').hide();
|
||||
}).css({
|
||||
position: 'absolute',
|
||||
bottom: 10,
|
||||
right: -10
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
preview.toggle(show);
|
||||
submit.toggle(show);
|
||||
}
|
||||
|
||||
function showBrowser() {
|
||||
|
||||
var browser = $('#imgbrowse');
|
||||
if (!browser.length) {
|
||||
$('<div id=imgbrowse_holder><div id=imgbrowse class=toolbar_button>\
|
||||
</div></div>').insertAfter('#svg_docprops');
|
||||
browser = $('#imgbrowse');
|
||||
|
||||
var all_libs = uiStrings.imagelib.select_lib;
|
||||
|
||||
var lib_opts = $('<ul id=imglib_opts>').appendTo(browser);
|
||||
var frame = $('<iframe/>').prependTo(browser).hide().wrap('<div id=lib_framewrap>');
|
||||
|
||||
var header = $('<h1>').prependTo(browser).text(all_libs).css({
|
||||
position: 'absolute',
|
||||
top: 0,
|
||||
left: 0,
|
||||
width: '100%'
|
||||
});
|
||||
|
||||
var cancel = $('<button>' + uiStrings.common.cancel + '</button>')
|
||||
.appendTo(browser)
|
||||
.on("click touchend", function() {
|
||||
$('#imgbrowse_holder').hide();
|
||||
}).css({
|
||||
position: 'absolute',
|
||||
top: 5,
|
||||
right: -10
|
||||
});
|
||||
|
||||
var leftBlock = $('<span>').css({position:'absolute',top:5,left:10}).appendTo(browser);
|
||||
|
||||
var back = $('<button hidden>' + uiStrings.imagelib.show_list + '</button>')
|
||||
.appendTo(leftBlock)
|
||||
.on("click touchend", function() {
|
||||
frame.attr('src', 'about:blank').hide();
|
||||
lib_opts.show();
|
||||
header.text(all_libs);
|
||||
back.hide();
|
||||
}).css({
|
||||
'margin-right': 5
|
||||
}).hide();
|
||||
|
||||
var type = $('<select><option value=s>' +
|
||||
uiStrings.imagelib.import_single + '</option><option value=m>' +
|
||||
uiStrings.imagelib.import_multi + '</option><option value=o>' +
|
||||
uiStrings.imagelib.open + '</option></select>').appendTo(leftBlock).change(function() {
|
||||
mode = $(this).val();
|
||||
switch (mode) {
|
||||
case 's':
|
||||
case 'o':
|
||||
toggleMulti(false);
|
||||
break;
|
||||
|
||||
case 'm':
|
||||
// Import multiple
|
||||
toggleMulti(true);
|
||||
break;
|
||||
}
|
||||
}).css({
|
||||
'margin-top': 10
|
||||
});
|
||||
|
||||
cancel.prepend($.getSvgIcon('cancel', true));
|
||||
back.prepend($.getSvgIcon('tool_imagelib', true));
|
||||
|
||||
$.each(img_libs, function(i, opts) {
|
||||
$('<li>')
|
||||
.appendTo(lib_opts)
|
||||
.text(opts.name)
|
||||
.on("click touchend", function() {
|
||||
frame.attr('src', opts.url).show();
|
||||
header.text(opts.name);
|
||||
lib_opts.hide();
|
||||
back.show();
|
||||
}).append('<span>' + opts.description + '</span>');
|
||||
});
|
||||
|
||||
} else {
|
||||
$('#imgbrowse_holder').show();
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
svgicons: svgEditor.curConfig.extPath + "ext-imagelib.xml",
|
||||
buttons: [{
|
||||
id: "tool_imagelib",
|
||||
type: "app_menu", // _flyout
|
||||
position: 4,
|
||||
title: "Image library",
|
||||
events: {
|
||||
"mouseup": showBrowser
|
||||
}
|
||||
}],
|
||||
callback: function() {
|
||||
|
||||
$('<style>').text('\
|
||||
#imgbrowse_holder {\
|
||||
position: absolute;\
|
||||
top: 0;\
|
||||
left: 0;\
|
||||
width: 100%;\
|
||||
height: 100%;\
|
||||
background-color: rgba(0, 0, 0, .5);\
|
||||
z-index: 5;\
|
||||
}\
|
||||
\
|
||||
#imgbrowse {\
|
||||
position: absolute;\
|
||||
top: 25px;\
|
||||
left: 25px;\
|
||||
right: 25px;\
|
||||
bottom: 25px;\
|
||||
min-width: 300px;\
|
||||
min-height: 200px;\
|
||||
background: #B0B0B0;\
|
||||
border: 1px outset #777;\
|
||||
}\
|
||||
#imgbrowse h1 {\
|
||||
font-size: 20px;\
|
||||
margin: .4em;\
|
||||
text-align: center;\
|
||||
}\
|
||||
#lib_framewrap,\
|
||||
#imgbrowse > ul {\
|
||||
position: absolute;\
|
||||
top: 45px;\
|
||||
left: 10px;\
|
||||
right: 10px;\
|
||||
bottom: 10px;\
|
||||
background: white;\
|
||||
margin: 0;\
|
||||
padding: 0;\
|
||||
}\
|
||||
#imgbrowse > ul {\
|
||||
overflow: auto;\
|
||||
}\
|
||||
#imgbrowse > div {\
|
||||
border: 1px solid #666;\
|
||||
}\
|
||||
#imglib_preview > div {\
|
||||
padding: 5px;\
|
||||
font-size: 12px;\
|
||||
}\
|
||||
#imglib_preview img {\
|
||||
display: block;\
|
||||
margin: 0 auto;\
|
||||
max-height: 100px;\
|
||||
}\
|
||||
#imgbrowse li {\
|
||||
list-style: none;\
|
||||
padding: .5em;\
|
||||
background: #E8E8E8;\
|
||||
border-bottom: 1px solid #B0B0B0;\
|
||||
line-height: 1.2em;\
|
||||
font-style: sans-serif;\
|
||||
}\
|
||||
#imgbrowse li > span {\
|
||||
color: #666;\
|
||||
font-size: 15px;\
|
||||
display: block;\
|
||||
}\
|
||||
#imgbrowse li:hover {\
|
||||
background: #FFC;\
|
||||
cursor: pointer;\
|
||||
}\
|
||||
#imgbrowse iframe {\
|
||||
width: 100%;\
|
||||
height: 100%;\
|
||||
border: 0;\
|
||||
}\
|
||||
').appendTo('head');
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
34
main/inc/lib/svg-edit/extensions/ext-php_savefile_chamilo.js
Normal file
34
main/inc/lib/svg-edit/extensions/ext-php_savefile_chamilo.js
Normal file
@@ -0,0 +1,34 @@
|
||||
/*globals $, svgCanvas, svgEditor*/
|
||||
/*jslint regexp:true*/
|
||||
// TODO: Might add support for "exportImage" custom
|
||||
// handler as in "ext-server_opensave.js" (and in savefile.php)
|
||||
|
||||
svgEditor.addExtension("php_savefile_chamilo", {
|
||||
callback: function() {
|
||||
'use strict';
|
||||
function getFileNameFromTitle () {
|
||||
var title = svgCanvas.getDocumentTitle();
|
||||
return $.trim(title);
|
||||
}
|
||||
var save_svg_action = svgEditor.curConfig.extPath + 'savefile.php';
|
||||
svgEditor.setCustomHandlers({
|
||||
save: function(win, data) {
|
||||
var svg = '<?xml version="1.0" encoding="UTF-8"?>\n' + data,
|
||||
filename = getFileNameFromTitle();
|
||||
|
||||
$.post(
|
||||
save_svg_action,
|
||||
{output_svg: svg, filename: filename}
|
||||
).done(function(data) {
|
||||
var response = jQuery.parseJSON(data);
|
||||
console.log(response.message);
|
||||
alert(response.message);
|
||||
if (response.url != '') {
|
||||
window.top.location.href = response.url;
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
3
main/inc/lib/svg-edit/extensions/fileopen.php
Normal file
3
main/inc/lib/svg-edit/extensions/fileopen.php
Normal file
@@ -0,0 +1,3 @@
|
||||
<!DOCTYPE html>
|
||||
<?php
|
||||
exit;
|
||||
11
main/inc/lib/svg-edit/extensions/filesave.php
Normal file
11
main/inc/lib/svg-edit/extensions/filesave.php
Normal file
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
/*
|
||||
* filesave.php
|
||||
* To be used with ext-server_opensave.js for SVG-edit
|
||||
*
|
||||
* Licensed under the MIT License
|
||||
*
|
||||
* Copyright(c) 2010 Alexis Deveria
|
||||
*
|
||||
*/
|
||||
exit;
|
||||
1
main/inc/lib/svg-edit/extensions/form-test.html
Normal file
1
main/inc/lib/svg-edit/extensions/form-test.html
Normal file
@@ -0,0 +1 @@
|
||||
<!DOCTYPE html>
|
||||
152
main/inc/lib/svg-edit/extensions/imagelib/groups.php
Normal file
152
main/inc/lib/svg-edit/extensions/imagelib/groups.php
Normal file
@@ -0,0 +1,152 @@
|
||||
<?php
|
||||
/* Integrate svg-edit libraries with Chamilo default documents
|
||||
* @author Juan Carlos Raña Trabado
|
||||
* @since 25/september/2010
|
||||
*/
|
||||
|
||||
require_once '../../../../../../inc/global.inc.php';
|
||||
|
||||
//Add security from Chamilo
|
||||
api_protect_course_script();
|
||||
api_block_anonymous_users();
|
||||
|
||||
$is_allowed_to_edit = api_is_allowed_to_edit(null, true);
|
||||
|
||||
$course_info = api_get_course_info();
|
||||
$groupId = api_get_group_id();
|
||||
|
||||
$group_properties = GroupManager::get_group_properties($groupId);
|
||||
$groupIid = 0;
|
||||
if ($group_properties) {
|
||||
$groupdirpath = $group_properties['directory'];
|
||||
$groupIid = $group_properties['iid'];
|
||||
}
|
||||
$group_disk_path = api_get_path(SYS_COURSE_PATH).$course_info['path'].'/document'.$groupdirpath.'/';
|
||||
$group_web_path = api_get_path(WEB_COURSE_PATH).$course_info['path'].'/document'.$groupdirpath.'/';
|
||||
|
||||
//get all group files and folders
|
||||
$docs_and_folders = DocumentManager::getAllDocumentData(
|
||||
$course_info,
|
||||
$groupdirpath,
|
||||
$groupIid,
|
||||
null,
|
||||
$is_allowed_to_edit,
|
||||
false
|
||||
);
|
||||
|
||||
// get all group filenames
|
||||
$array_to_search = !empty($docs_and_folders) ? $docs_and_folders : array();
|
||||
|
||||
if (count($array_to_search) > 0) {
|
||||
while (list($key) = each($array_to_search)) {
|
||||
$all_files[] = basename($array_to_search[$key]['path']);
|
||||
}
|
||||
}
|
||||
|
||||
//get all svg and png group files
|
||||
$accepted_extensions = array('.svg', '.png');
|
||||
|
||||
if (is_array($all_files) && count($all_files) > 0) {
|
||||
foreach ($all_files as & $file) {
|
||||
$slideshow_extension = strrchr($file, '.');
|
||||
$slideshow_extension = strtolower($slideshow_extension);
|
||||
if (in_array($slideshow_extension, $accepted_extensions)) {
|
||||
$png_svg_files[] =$file;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$style = '<style>';
|
||||
$style .= '@import "'.api_get_path(WEB_CSS_PATH).'base.css";';
|
||||
$style .= '@import "'.api_get_path(WEB_CSS_PATH).'themes/'.api_get_visual_theme().'/default.css";';
|
||||
$style .='</style>';
|
||||
|
||||
?>
|
||||
<!doctype html>
|
||||
<?php echo api_get_jquery_js(); ?>
|
||||
<?php echo $style ?>
|
||||
<body>
|
||||
<?php
|
||||
echo '<h2>'.get_lang('GroupSingle').': '.$group_properties['name'].'</h2>';
|
||||
|
||||
if ((
|
||||
$group_properties['doc_state'] == 2 &&
|
||||
($is_allowed_to_edit || GroupManager :: is_user_in_group($_user['user_id'], $group_properties))) || $group_properties['doc_state'] == 1
|
||||
){
|
||||
|
||||
if (!empty($png_svg_files)) {
|
||||
echo '<h3>'.get_lang('SelectSVGEditImage').'</h3>';
|
||||
echo '<ul>';
|
||||
foreach($png_svg_files as $filename) {
|
||||
$image = $group_disk_path.$filename;
|
||||
|
||||
if (strpos($filename, "svg")){
|
||||
$new_sizes['width'] = 60;
|
||||
$new_sizes['height'] = 60;
|
||||
} else {
|
||||
$new_sizes = api_resize_image($image, 60, 60);
|
||||
}
|
||||
echo '<li style="display:inline; padding:8px;">';
|
||||
echo '<a href = "'.$group_web_path.$filename.'" alt="'.$filename.'" title="'.$filename.'">';
|
||||
echo '<img src = "'.$group_web_path.$filename.'" width = "'.$new_sizes['width'].'" height="'.$new_sizes['height'].'" border="0"></a></li>';
|
||||
}
|
||||
echo '</ul>';
|
||||
}
|
||||
} else {
|
||||
echo Display::return_message(get_lang('OnlyAccessFromYourGroup'), 'warning');
|
||||
}
|
||||
?>
|
||||
</body>
|
||||
|
||||
<script>
|
||||
|
||||
$('a').click(function() {
|
||||
var href = this.href;
|
||||
|
||||
// Convert Non-SVG images to data URL first
|
||||
// (this could also have been done server-side by the library)
|
||||
if(this.href.indexOf('.svg') === -1) {
|
||||
|
||||
var meta_str = JSON.stringify({
|
||||
name: $(this).text(),
|
||||
id: href
|
||||
});
|
||||
window.top.postMessage(meta_str, "*");
|
||||
|
||||
var img = new Image();
|
||||
img.onload = function() {
|
||||
var canvas = document.createElement("canvas");
|
||||
canvas.width = this.width;
|
||||
canvas.height = this.height;
|
||||
// load the raster image into the canvas
|
||||
canvas.getContext("2d").drawImage(this,0,0);
|
||||
// retrieve the data: URL
|
||||
try {
|
||||
var dataurl = canvas.toDataURL();
|
||||
} catch(err) {
|
||||
// This fails in Firefox with file:// URLs :(
|
||||
alert("Data URL conversion failed: " + err);
|
||||
var dataurl = "";
|
||||
}
|
||||
window.top.postMessage('|' + href + '|' + dataurl, "*");
|
||||
}
|
||||
img.src = href;
|
||||
} else {
|
||||
// Send metadata (also indicates file is about to be sent)
|
||||
var meta_str = JSON.stringify({
|
||||
name: $(this).text(),
|
||||
id: href
|
||||
});
|
||||
window.top.postMessage(meta_str, "*");
|
||||
// Do ajax request for image's href value
|
||||
$.get(href, function(data) {
|
||||
data = '|' + href + '|' + data;
|
||||
// This is where the magic happens!
|
||||
window.top.postMessage(data, "*");
|
||||
|
||||
}, 'html'); // 'html' is necessary to keep returned data as a string
|
||||
}
|
||||
return false;
|
||||
});
|
||||
|
||||
</script>
|
||||
70
main/inc/lib/svg-edit/extensions/imagelib/index.html
Normal file
70
main/inc/lib/svg-edit/extensions/imagelib/index.html
Normal file
@@ -0,0 +1,70 @@
|
||||
<!DOCTYPE html>
|
||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<h1>Select an image:</h1>
|
||||
<a href="smiley.svg">smiley.svg</a>
|
||||
<br>
|
||||
<a href="../../images/logo.png">logo.png</a>
|
||||
|
||||
<script>
|
||||
/*globals $*/
|
||||
/*jslint vars: true*/
|
||||
$('a').click(function() {'use strict';
|
||||
var meta_str;
|
||||
var href = this.href;
|
||||
var target = window.parent;
|
||||
// Convert Non-SVG images to data URL first
|
||||
// (this could also have been done server-side by the library)
|
||||
if (this.href.indexOf('.svg') === -1) {
|
||||
|
||||
meta_str = JSON.stringify({
|
||||
name: $(this).text(),
|
||||
id: href
|
||||
});
|
||||
target.postMessage(meta_str, '*');
|
||||
|
||||
var img = new Image();
|
||||
img.onload = function() {
|
||||
var canvas = document.createElement('canvas');
|
||||
canvas.width = this.width;
|
||||
canvas.height = this.height;
|
||||
// load the raster image into the canvas
|
||||
canvas.getContext('2d').drawImage(this, 0, 0);
|
||||
// retrieve the data: URL
|
||||
var dataurl;
|
||||
try {
|
||||
dataurl = canvas.toDataURL();
|
||||
} catch(err) {
|
||||
// This fails in Firefox with file:// URLs :(
|
||||
alert("Data URL conversion failed: " + err);
|
||||
dataurl = "";
|
||||
}
|
||||
target.postMessage('|' + href + '|' + dataurl, '*');
|
||||
};
|
||||
img.src = href;
|
||||
} else {
|
||||
// Send metadata (also indicates file is about to be sent)
|
||||
meta_str = JSON.stringify({
|
||||
name: $(this).text(),
|
||||
id: href
|
||||
});
|
||||
target.postMessage(meta_str, '*');
|
||||
// Do ajax request for image's href value
|
||||
$.get(href, function(data) {
|
||||
data = '|' + href + '|' + data;
|
||||
// This is where the magic happens!
|
||||
target.postMessage(data, '*');
|
||||
|
||||
}, 'html'); // 'html' is necessary to keep returned data as a string
|
||||
}
|
||||
return false;
|
||||
});
|
||||
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
136
main/inc/lib/svg-edit/extensions/imagelib/index.php
Normal file
136
main/inc/lib/svg-edit/extensions/imagelib/index.php
Normal file
@@ -0,0 +1,136 @@
|
||||
<?php
|
||||
/* Integrate svg-edit libraries with Chamilo default documents
|
||||
* @author Juan Carlos Raña Trabado
|
||||
* @since 25/september/2010
|
||||
*/
|
||||
require_once '../../../../../../inc/global.inc.php';
|
||||
|
||||
//Add security from Chamilo
|
||||
api_protect_course_script();
|
||||
api_block_anonymous_users();
|
||||
|
||||
$is_allowed_to_edit = api_is_allowed_to_edit(null, true);
|
||||
|
||||
$curdirpath='/images/gallery'; //path of library directory
|
||||
|
||||
$course_info = api_get_course_info();
|
||||
|
||||
//get all files and folders
|
||||
$docs_and_folders = DocumentManager::getAllDocumentData(
|
||||
$course_info,
|
||||
$curdirpath,
|
||||
0,
|
||||
null,
|
||||
$is_allowed_to_edit,
|
||||
false
|
||||
);
|
||||
|
||||
//get all filenames
|
||||
$array_to_search = !empty($docs_and_folders) ? $docs_and_folders : array();
|
||||
|
||||
if (count($array_to_search) > 0) {
|
||||
while (list($key) = each($array_to_search)) {
|
||||
$all_files[] = basename($array_to_search[$key]['path']);
|
||||
}
|
||||
}
|
||||
|
||||
//get all svg and png files
|
||||
$accepted_extensions = array('.svg', '.png');
|
||||
|
||||
if (is_array($all_files) && count($all_files) > 0) {
|
||||
foreach ($all_files as & $file) {
|
||||
$slideshow_extension = strrchr($file, '.');
|
||||
$slideshow_extension = strtolower($slideshow_extension);
|
||||
if (in_array($slideshow_extension, $accepted_extensions)) {
|
||||
$png_svg_files[] =$file;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$disk_path = api_get_path(SYS_COURSE_PATH).$course_info['path'].'/document/images/gallery/';
|
||||
$web_path = api_get_path(WEB_COURSE_PATH).$course_info['path'].'/document/images/gallery/';
|
||||
|
||||
$style = '<style>';
|
||||
$style .= '@import "'.api_get_path(WEB_CSS_PATH).'base.css";';
|
||||
$style .= '@import "'.api_get_path(WEB_CSS_PATH).'themes/'.api_get_visual_theme().'/default.css";';
|
||||
$style .='</style>';
|
||||
|
||||
?>
|
||||
<!doctype html>
|
||||
<?php echo api_get_jquery_js(); ?>
|
||||
<?php echo $style ?>
|
||||
<body>
|
||||
<?php
|
||||
echo '<h2>'.get_lang('Course').': '.$course_info['name'].'</h2>';
|
||||
if (!empty($png_svg_files)) {
|
||||
echo '<h3>'.get_lang('SelectSVGEditImage').'</h3>';
|
||||
echo '<ul>';
|
||||
foreach($png_svg_files as $filename) {
|
||||
$image=$disk_path.$filename;
|
||||
|
||||
if (strpos($filename, "svg")){
|
||||
$new_sizes['width'] = 60;
|
||||
$new_sizes['height'] = 60;
|
||||
}
|
||||
else {
|
||||
$new_sizes = api_resize_image($image, 60, 60);
|
||||
}
|
||||
|
||||
echo '<li style="display:inline; padding:8px;"><a href="'.$web_path.$filename.'" alt "'.$filename.'" title="'.$filename.'"><img src="'.$web_path.$filename.'" width="'.$new_sizes['width'].'" height="'.$new_sizes['height'].'" border="0"></a></li>';
|
||||
}
|
||||
echo '</ul>';
|
||||
} else {
|
||||
echo Display::return_message(get_lang('NoSVGImagesInImagesGalleryPath'), 'warning');
|
||||
}
|
||||
?>
|
||||
</body>
|
||||
<script>
|
||||
$('a').click(function() {
|
||||
var href = this.href;
|
||||
|
||||
// Convert Non-SVG images to data URL first
|
||||
// (this could also have been done server-side by the library)
|
||||
if(this.href.indexOf('.svg') === -1) {
|
||||
|
||||
var meta_str = JSON.stringify({
|
||||
name: $(this).text(),
|
||||
id: href
|
||||
});
|
||||
window.top.postMessage(meta_str, "*");
|
||||
|
||||
var img = new Image();
|
||||
img.onload = function() {
|
||||
var canvas = document.createElement("canvas");
|
||||
canvas.width = this.width;
|
||||
canvas.height = this.height;
|
||||
// load the raster image into the canvas
|
||||
canvas.getContext("2d").drawImage(this,0,0);
|
||||
// retrieve the data: URL
|
||||
try {
|
||||
var dataurl = canvas.toDataURL();
|
||||
} catch(err) {
|
||||
// This fails in Firefox with file:// URLs :(
|
||||
alert("Data URL conversion failed: " + err);
|
||||
var dataurl = "";
|
||||
}
|
||||
window.top.postMessage('|' + href + '|' + dataurl, "*");
|
||||
}
|
||||
img.src = href;
|
||||
} else {
|
||||
// Send metadata (also indicates file is about to be sent)
|
||||
var meta_str = JSON.stringify({
|
||||
name: $(this).text(),
|
||||
id: href
|
||||
});
|
||||
window.top.postMessage(meta_str, "*");
|
||||
// Do ajax request for image's href value
|
||||
$.get(href, function(data) {
|
||||
data = '|' + href + '|' + data;
|
||||
// This is where the magic happens!
|
||||
window.top.postMessage(data, "*");
|
||||
|
||||
}, 'html'); // 'html' is necessary to keep returned data as a string
|
||||
}
|
||||
return false;
|
||||
});
|
||||
</script>
|
||||
12
main/inc/lib/svg-edit/extensions/imagelib/smiley.svg
Normal file
12
main/inc/lib/svg-edit/extensions/imagelib/smiley.svg
Normal file
@@ -0,0 +1,12 @@
|
||||
<svg width="137" height="137" xmlns="http://www.w3.org/2000/svg">
|
||||
<title>Cool smiley</title>
|
||||
<path fill="url(#svg_4)" stroke="#000000" stroke-width="3" d="m32.18682,97.71674q36.3159,24.94076 72.54585,0m-64.67542,-49.25576c0,-3.8554 3.12526,-6.98079 6.98068,-6.98079c3.85449,0 6.97872,3.12539 6.97872,6.98079c0,3.85346 -3.12423,6.97867 -6.97872,6.97867c-3.85542,0 -6.98068,-3.12521 -6.98068,-6.97867m42.93047,0c0,-3.8554 3.12529,-6.98079 6.97963,-6.98079c3.8544,0 6.97971,3.12539 6.97971,6.98079c0,3.85346 -3.12531,6.97867 -6.97971,6.97867c-3.85434,0 -6.97963,-3.12521 -6.97963,-6.97867m-81.48596,20.036l0,0c0,-37.00197 29.99679,-66.99892 67.00095,-66.99892c37.00303,0 66.99998,29.99695 66.99998,66.99892c0,37.00409 -29.99695,67.00101 -66.99998,67.00101c-37.00416,0 -67.00095,-29.99692 -67.00095,-67.00101zm0,0l0,0c0,-37.00197 29.99679,-66.99892 67.00095,-66.99892c37.00303,0 66.99998,29.99695 66.99998,66.99892c0,37.00409 -29.99695,67.00101 -66.99998,67.00101c-37.00416,0 -67.00095,-29.99692 -67.00095,-67.00101z" id="svg_1"/>
|
||||
<path id="svg_5" d="m23.84005,41.03445l17.57052,0l5.42937,-19.67914l5.42941,19.67914l17.5706,0l-14.21488,12.16242l5.42982,19.67939l-14.21495,-12.16281l-14.21489,12.16281l5.42991,-19.67939l-14.21491,-12.16242l0,0z" stroke-width="3" fill="#000000"/>
|
||||
<path id="svg_6" d="m65.84005,41.03445l17.57052,0l5.42937,-19.67914l5.42941,19.67914l17.5706,0l-14.21487,12.16242l5.42982,19.67939l-14.21496,-12.1628l-14.2149,12.1628l5.42992,-19.67939l-14.21491,-12.16242l0,0z" stroke-width="3" fill="#000000"/>
|
||||
<defs>
|
||||
<linearGradient y2="0.25391" x2="0.46484" y1="0.94922" x1="0.44531" id="svg_4">
|
||||
<stop stop-color="#ff0000" offset="0"/>
|
||||
<stop stop-color="#ffff00" offset="1"/>
|
||||
</linearGradient>
|
||||
</defs>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 1.7 KiB |
119
main/inc/lib/svg-edit/extensions/imagelib/users.php
Normal file
119
main/inc/lib/svg-edit/extensions/imagelib/users.php
Normal file
@@ -0,0 +1,119 @@
|
||||
<?php
|
||||
/* Integrate svg-edit libraries with Chamilo default documents
|
||||
* @author Juan Carlos Raña Trabado
|
||||
* @since 25/september/2010
|
||||
*/
|
||||
require_once '../../../../../../inc/global.inc.php';
|
||||
|
||||
//Add security from Chamilo
|
||||
api_protect_course_script();
|
||||
api_block_anonymous_users();
|
||||
|
||||
$userId = api_get_user_id();
|
||||
$user_disk_path = UserManager::getUserPathById($userId, 'system').'my_files/';
|
||||
$user_web_path = UserManager::getUserPathById($userId, 'web').'my_files/';
|
||||
|
||||
//get all files and folders
|
||||
$scan_files = [];
|
||||
if (is_dir($user_disk_path)) {
|
||||
$scan_files = scandir($user_disk_path);
|
||||
}
|
||||
//get all svg and png files
|
||||
$accepted_extensions = array('.svg', '.png');
|
||||
|
||||
if (is_array($scan_files) && count($scan_files) > 0) {
|
||||
foreach ($scan_files as & $file) {
|
||||
$slideshow_extension = strrchr($file, '.');
|
||||
$slideshow_extension = strtolower($slideshow_extension);
|
||||
if (in_array($slideshow_extension, $accepted_extensions)) {
|
||||
$png_svg_files[] =$file;
|
||||
}
|
||||
}
|
||||
}
|
||||
$style = '<style>';
|
||||
$style .= '@import "'.api_get_path(WEB_CSS_PATH).'base.css";';
|
||||
$style .= '@import "'.api_get_path(WEB_CSS_PATH).'themes/'.api_get_visual_theme().'/default.css";';
|
||||
$style .='</style>';
|
||||
|
||||
?>
|
||||
<!doctype html>
|
||||
<?php echo api_get_jquery_js(); ?>
|
||||
<?php echo $style ?>
|
||||
|
||||
<body>
|
||||
|
||||
<?php
|
||||
|
||||
echo '<h2>'.get_lang('SocialNetwork').': '.get_lang('MyFiles').'</h2>';
|
||||
|
||||
if (!empty($png_svg_files)) {
|
||||
echo '<h3>'.get_lang('SelectSVGEditImage').'</h3>';
|
||||
echo '<ul>';
|
||||
foreach($png_svg_files as $filename) {
|
||||
$image = $user_disk_path.$filename;
|
||||
|
||||
if (strpos($filename, "svg")){
|
||||
$new_sizes['width'] = 60;
|
||||
$new_sizes['height'] = 60;
|
||||
} else {
|
||||
$new_sizes = api_resize_image($image, 60, 60);
|
||||
}
|
||||
|
||||
echo '<li style="display:inline; padding:8px;"><a href="'.$user_web_path.$filename.'" alt "'.$filename.'" title="'.$filename.'"><img src="'.$user_web_path.$filename.'" width="'.$new_sizes['width'].'" height="'.$new_sizes['height'].'" border="0"></a></li>';
|
||||
}
|
||||
echo '</ul>';
|
||||
} else {
|
||||
echo Display::return_message(get_lang('NoSVGImages'), 'warning');
|
||||
}
|
||||
?>
|
||||
</body>
|
||||
<script>
|
||||
$('a').click(function() {
|
||||
var href = this.href;
|
||||
|
||||
// Convert Non-SVG images to data URL first
|
||||
// (this could also have been done server-side by the library)
|
||||
if(this.href.indexOf('.svg') === -1) {
|
||||
|
||||
var meta_str = JSON.stringify({
|
||||
name: $(this).text(),
|
||||
id: href
|
||||
});
|
||||
window.top.postMessage(meta_str, "*");
|
||||
|
||||
var img = new Image();
|
||||
img.onload = function() {
|
||||
var canvas = document.createElement("canvas");
|
||||
canvas.width = this.width;
|
||||
canvas.height = this.height;
|
||||
// load the raster image into the canvas
|
||||
canvas.getContext("2d").drawImage(this,0,0);
|
||||
// retrieve the data: URL
|
||||
try {
|
||||
var dataurl = canvas.toDataURL();
|
||||
} catch(err) {
|
||||
// This fails in Firefox with file:// URLs :(
|
||||
alert("Data URL conversion failed: " + err);
|
||||
var dataurl = "";
|
||||
}
|
||||
window.top.postMessage('|' + href + '|' + dataurl, "*");
|
||||
}
|
||||
img.src = href;
|
||||
} else {
|
||||
// Send metadata (also indicates file is about to be sent)
|
||||
var meta_str = JSON.stringify({
|
||||
name: $(this).text(),
|
||||
id: href
|
||||
});
|
||||
window.top.postMessage(meta_str, "*");
|
||||
// Do ajax request for image's href value
|
||||
$.get(href, function(data) {
|
||||
data = '|' + href + '|' + data;
|
||||
// This is where the magic happens!
|
||||
window.top.postMessage(data, "*");
|
||||
|
||||
}, 'html'); // 'html' is necessary to keep returned data as a string
|
||||
}
|
||||
return false;
|
||||
});
|
||||
</script>
|
||||
8
main/inc/lib/svg-edit/extensions/saved.svg
Normal file
8
main/inc/lib/svg-edit/extensions/saved.svg
Normal file
File diff suppressed because one or more lines are too long
|
After Width: | Height: | Size: 14 KiB |
215
main/inc/lib/svg-edit/extensions/savefile_config.php
Normal file
215
main/inc/lib/svg-edit/extensions/savefile_config.php
Normal file
@@ -0,0 +1,215 @@
|
||||
<?php
|
||||
|
||||
use ChamiloSession as Session;
|
||||
|
||||
/*
|
||||
* filesave.php
|
||||
* To be used with ext-server_opensave.js for SVG-edit
|
||||
*
|
||||
* Licensed under the Apache License, Version 2
|
||||
*
|
||||
* Copyright(c) 2010 Alexis Deveria
|
||||
*
|
||||
* Integrate svg-edit with Chamilo
|
||||
* @author Juan Carlos Raña Trabado
|
||||
* @since 25/september/2010
|
||||
*/
|
||||
|
||||
require_once '../../../../../inc/global.inc.php';
|
||||
|
||||
// Add security from Chamilo
|
||||
api_protect_course_script();
|
||||
api_block_anonymous_users();
|
||||
|
||||
if (!isset($_POST['output_svg']) && !isset($_POST['output_png'])) {
|
||||
api_not_allowed();//from Chamilo
|
||||
die();
|
||||
}
|
||||
|
||||
$file = '';
|
||||
$suffix = isset($_POST['output_svg']) ? 'svg' : 'png';
|
||||
|
||||
$_course = api_get_course_info();
|
||||
|
||||
if (isset($_POST['filename']) && strlen($_POST['filename']) > 0) {
|
||||
$file = $_POST['filename'];
|
||||
} else {
|
||||
$file = 'image';
|
||||
}
|
||||
|
||||
if ($suffix == 'svg') {
|
||||
$mime = 'image/svg+xml';
|
||||
$contents = rawurldecode($_POST['output_svg']);
|
||||
} else {
|
||||
$mime = 'image/png';
|
||||
$contents = $_POST['output_png'];
|
||||
$pos = (strpos($contents, 'base64,') + 7);
|
||||
$contents = base64_decode(substr($contents, $pos));
|
||||
}
|
||||
|
||||
//get SVG-Edit values
|
||||
$filename = $file;//from svg-edit
|
||||
$extension = $suffix;// from svg-edit
|
||||
$content = $contents;//from svg-edit
|
||||
|
||||
$title = Database::escape_string(str_replace('_',' ',$filename));
|
||||
|
||||
//get Chamilo variables
|
||||
$relativeUrlPath = Session::read('draw_dir');
|
||||
|
||||
if (empty($relativeUrlPath)) {
|
||||
api_not_allowed();//from Chamilo
|
||||
die();
|
||||
}
|
||||
|
||||
$current_session_id = api_get_session_id();
|
||||
$groupId = api_get_group_id();
|
||||
$groupInfo = GroupManager::get_group_properties($groupId);
|
||||
$dirBaseDocuments = api_get_path(SYS_COURSE_PATH).$_course['path'].'/document';
|
||||
$saveDir = $dirBaseDocuments.$relativeUrlPath;
|
||||
|
||||
// a bit title security
|
||||
$filename = addslashes(trim($filename));
|
||||
$filename = Security::remove_XSS($filename);
|
||||
$filename = api_replace_dangerous_char($filename);
|
||||
$filename = disable_dangerous_file($filename);
|
||||
|
||||
// a bit extension
|
||||
if ($suffix != 'svg' && $suffix != 'png') {
|
||||
die();
|
||||
}
|
||||
|
||||
//a bit mime security
|
||||
//comment because finfo seems stopping the save process files in some php vers.
|
||||
/*
|
||||
if (phpversion() >= '5.3' && extension_loaded('fileinfo')) {
|
||||
$finfo = new finfo(FILEINFO_MIME);
|
||||
$current_mime=$finfo->buffer($contents);
|
||||
finfo_close($finfo);
|
||||
$mime_png='image/png';//svg-edit return image/png; charset=binary
|
||||
$mime_svg='image/svg+xml';
|
||||
$mime_xml='application/xml';//hack for svg-edit because original code return application/xml; charset=us-ascii. See
|
||||
if(strpos($current_mime, $mime_png)===false && $extension=='png') {
|
||||
die();//File extension does not match its content
|
||||
} elseif(strpos($current_mime, $mime_svg)===false && strpos($current_mime, $mime_xml)===false && $extension=='svg') {
|
||||
die();//File extension does not match its content
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
//checks if the file exists, then rename the new
|
||||
if (file_exists($saveDir.'/'.$filename.'.'.$extension) && $currentTool=='document/createdraw') {
|
||||
$message = get_lang('FileExistsChangeToSave');
|
||||
$params = array(
|
||||
'message' => $message,
|
||||
'url' => ''
|
||||
);
|
||||
echo json_encode($params);
|
||||
exit;
|
||||
} else {
|
||||
$drawFileName = $filename.'.'.$extension;
|
||||
$title = $title.'.'.$extension;
|
||||
}
|
||||
|
||||
$documentPath = $saveDir.'/'.$drawFileName;
|
||||
|
||||
//add new document to disk
|
||||
file_put_contents($documentPath, $contents);
|
||||
if ($currentTool == 'document/createdraw') {
|
||||
//add document to database
|
||||
$doc_id = add_document(
|
||||
$_course,
|
||||
$relativeUrlPath.'/'.$drawFileName,
|
||||
'file',
|
||||
filesize($documentPath),
|
||||
$title
|
||||
);
|
||||
api_item_property_update(
|
||||
$_course,
|
||||
TOOL_DOCUMENT,
|
||||
$doc_id,
|
||||
'DocumentAdded',
|
||||
$_user['user_id'],
|
||||
$groupInfo,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
$current_session_id
|
||||
);
|
||||
|
||||
} elseif ($currentTool == 'document/editdraw') {
|
||||
//check path
|
||||
if (!isset($_SESSION['draw_file'])) {
|
||||
api_not_allowed();//from Chamilo
|
||||
die();
|
||||
}
|
||||
if ($_SESSION['draw_file'] == $drawFileName) {
|
||||
$document_id = DocumentManager::get_document_id(
|
||||
$_course,
|
||||
$relativeUrlPath.'/'.$drawFileName
|
||||
);
|
||||
update_existing_document(
|
||||
$_course,
|
||||
$document_id,
|
||||
filesize($documentPath),
|
||||
null
|
||||
);
|
||||
api_item_property_update(
|
||||
$_course,
|
||||
TOOL_DOCUMENT,
|
||||
$document_id,
|
||||
'DocumentUpdated',
|
||||
$_user['user_id'],
|
||||
$groupInfo,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
$current_session_id
|
||||
);
|
||||
} else {
|
||||
//add a new document
|
||||
$doc_id = add_document(
|
||||
$_course,
|
||||
$relativeUrlPath.'/'.$drawFileName,
|
||||
'file',
|
||||
filesize($documentPath),
|
||||
$title
|
||||
);
|
||||
api_item_property_update(
|
||||
$_course,
|
||||
TOOL_DOCUMENT,
|
||||
$doc_id,
|
||||
'DocumentAdded',
|
||||
$_user['user_id'],
|
||||
$groupInfo,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
$current_session_id
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
//clean sessions and add messages and return to current document list
|
||||
Session::erase('draw_dir');
|
||||
Session::erase('draw_file');
|
||||
|
||||
if ($suffix != 'png') {
|
||||
if ($relativeUrlPath == '') {
|
||||
$relativeUrlPath = '/';
|
||||
};
|
||||
$url = api_get_path(WEB_CODE_PATH).'document/document.php?'.api_get_cidreq().'&curdirpath='.urlencode($relativeUrlPath);
|
||||
$message = get_lang('FileSavedAs').': '.$title;
|
||||
//echo 'alert("'.get_lang('FileSavedAs').': '.$title.'");';
|
||||
//echo 'window.top.location.href="'.$interbreadcrumb.'";';//return to current document list
|
||||
} else {
|
||||
$url = '';
|
||||
$message = get_lang('FileExportAs').': '.$title;
|
||||
}
|
||||
|
||||
$params = array(
|
||||
'message' => $message,
|
||||
'url' => $url
|
||||
);
|
||||
echo json_encode($params);
|
||||
exit;
|
||||
Reference in New Issue
Block a user