This commit is contained in:
xesmyd committed 2025-08-14 22:37:50 +02:00
1 parent fb6d5d5926
commit 3641e93527
9156 files changed
+1813532

No files matched your search

@@ -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

@@ -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);
}
}
}]
};
});
}());
@@ -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');
}
};
});
@@ -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;
}
}
);
}
});
}
});
@@ -0,0 +1,3 @@
<!DOCTYPE html>
<?php
exit;
@@ -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;
@@ -0,0 +1 @@
<!DOCTYPE html>
@@ -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>
@@ -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>
@@ -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>
@@ -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

@@ -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>
@@ -0,0 +1,8 @@
<?xml version="1.0"?>
<svg width="640" height="480" xmlns="http://www.w3.org/2000/svg" xmlns:svg="http://www.w3.org/2000/svg">
<!-- Created with SVG-edit - http://svg-edit.googlecode.com/ -->
<g>
<title>Layer 1</title>
<path d="m251.833344,223.833344c0,2.625336 0,3.482666 0,4.290161c0,0.963165 0.025406,1.778748 -0.035995,2.505844c-0.087982,1.041809 -0.414047,1.959854 -0.611343,2.599487c-0.307632,0.997314 -0.368271,1.913635 -0.436661,2.46051c-0.176331,1.410019 -0.274826,1.837723 -0.436829,2.810669c-0.090775,0.545181 -0.288895,1.762833 -0.479172,3.166656c-0.104797,0.773224 -0.201584,1.590637 -0.304504,2.443512c-0.106415,0.88179 -0.213882,1.785965 -0.331497,2.704498c-0.118713,0.927155 -0.231674,1.857452 -0.53067,3.685333c-0.145889,0.891937 -0.314468,1.764282 -0.481491,2.623489c-0.164993,0.848801 -0.334702,1.688309 -0.490509,2.524506c-0.155182,0.832825 -0.320572,1.664246 -0.528,3.35199c-0.104797,0.852692 -0.169586,1.714264 -0.218994,2.576996c-0.04924,0.859985 -0.076569,1.7146 -0.093002,2.559021c-0.016159,0.830261 -0.019638,1.64267 -0.021332,3.197327c-0.000793,0.735321 0.000549,1.442688 -0.009003,2.123993c-0.009216,0.65741 -0.026062,1.29303 -0.063004,1.90802c-0.035904,0.597748 -0.068314,1.183472 -0.261322,2.301331c-0.094543,0.547607 -0.221588,1.082306 -0.517334,2.109314c-0.143036,0.496704 -0.456253,1.434937 -0.581345,1.885345c-0.440811,1.587219 -0.524841,2.277039 -0.55899,3.148651c-0.041199,1.05188 0.086014,1.922882 0.727829,2.318848c0.609955,0.376312 2.095779,0.546234 2.570663,0.583008c1.077026,0.083405 1.67244,0.088165 2.296677,0.100647c0.649109,0.01297 2.002502,0.020172 3.395828,0.020844c0.700333,0.000336 1.402664,0 2.108994,0c0.712326,0 1.432663,0 2.16301,0c1.498657,0 3.06134,0 3.871002,0c0.827667,0 1.671326,0 2.528992,0c0.869659,0 1.749329,0 2.636993,0c0.893677,0 2.69101,0 3.591187,0c0.901154,0 1.804321,0 2.71048,0c0.910187,0 1.825348,0 2.746521,0c0.928162,0 2.809479,0 3.763153,0c0.955658,0 1.905334,0 2.841003,0c0.913666,0 1.797333,0 2.643005,0c0.799652,0 2.229004,0 2.847504,0c0.569489,0 1.110992,0 1.645477,0c0.548523,0 1.132019,0 1.771515,0c0.716492,0 2.464508,0 3.53183,0c1.191345,0 2.490662,0 3.881989,0c1.467346,0 2.99469,0 4.56601,0c1.599335,0 4.817993,0.001007 6.407837,-0.000336c1.568848,-0.001312 3.115692,-0.004517 4.639496,-0.020996c1.499908,-0.016235 2.974915,-0.043121 4.423492,-0.092987c1.422119,-0.04895 4.181396,-0.208618 5.515503,-0.328674c1.305969,-0.117523 2.581055,-0.263397 3.825012,-0.429016c1.216064,-0.161896 2.400879,-0.343903 3.554993,-0.536987c1.125885,-0.188354 3.285461,-0.588623 4.320007,-0.790833c1.005463,-0.196533 1.980225,-0.394623 2.924988,-0.589508c0.915222,-0.188812 1.799957,-0.375031 2.654999,-0.553497c0.824951,-0.17218 2.384583,-0.492737 3.120331,-0.635498c0.706909,-0.137146 1.388153,-0.263092 2.046021,-0.375c0.634827,-0.107971 1.250122,-0.203888 1.847992,-0.285004c0.580841,-0.078796 1.703674,-0.199127 2.24884,-0.240173c0.533539,-0.040192 1.055542,-0.067108 1.564484,-0.08548c0.494751,-0.017853 0.97464,-0.026794 1.438507,-0.031525c0.446838,-0.004547 1.285492,-0.005035 1.675842,-0.004333c0.372314,0.000671 0.728729,0.002167 1.070984,0.010529c0.330414,0.008057 0.65094,0.021576 0.963013,0.046478c0.306641,0.024475 0.909729,0.10556 1.208832,0.164185c0.299622,0.058716 0.596039,0.129883 0.889496,0.203979c0.290192,0.073273 0.574402,0.150391 0.853516,0.222015c0.271576,0.069672 0.790039,0.188599 1.036499,0.231659c0.241547,0.042206 0.486267,0.075592 0.737976,0.117004c0.266327,0.043823 0.55307,0.09668 0.864014,0.17099c0.345276,0.08252 1.153198,0.32962 1.626678,0.497162c0.523987,0.185425 1.087799,0.408142 2.358643,0.856689c0.69281,0.244537 1.423126,0.492584 2.196014,0.712494c1.629028,0.463531 2.500763,0.631439 3.395996,0.799988c0.920471,0.173309 1.870728,0.326263 2.84549,0.487518c0.999908,0.165436 2.026001,0.329254 3.070496,0.532501c2.163818,0.421051 3.269806,0.703766 4.393341,0.998657c1.139191,0.299011 2.282684,0.623993 3.432007,0.947998c1.149323,0.324005 2.291565,0.653748 3.432007,0.947998c2.228821,0.575043 3.323578,0.795258 4.397339,1c1.054993,0.201141 2.098816,0.375183 3.128998,0.552002c1.020477,0.175171 2.035645,0.343109 3.039001,0.552002c2.009064,0.418274 3.004456,0.703369 3.997314,0.998657c0.989868,0.294403 1.962921,0.613953 2.921997,0.928497c0.939575,0.308136 1.850677,0.618774 2.742004,0.883514c1.667572,0.4953 2.453186,0.664734 3.202667,0.79599c0.716858,0.125549 1.415222,0.20697 2.097015,0.257996c0.670349,0.050171 1.337921,0.070374 2.006989,0.078003c1.36792,0.015625 2.076843,0.005341 2.798676,0.005341c0.727814,0 1.454651,0 2.173492,0c0.703827,0 1.385681,0 2.038513,0c1.190643,0 1.716156,0 2.194641,0c0.434509,0 0.828003,0 1.183502,0c0.320496,0 0.609009,0 0.8685,0c0.444,0 0.634338,0 0.806671,0c0.156342,0 0.298676,0.000244 0.429016,0c0.740326,-0.001343 1.576416,-0.450897 1.458984,-1.221344c-0.157227,-1.031494 -0.803589,-1.607849 -1.174652,-2.08667c-0.918335,-1.185059 -1.159943,-1.560028 -1.722351,-2.363495c-0.306915,-0.438446 -1.002441,-1.367737 -1.410645,-1.84198c-0.428864,-0.49826 -1.435883,-1.494812 -2.022675,-1.992523c-0.649933,-0.55127 -1.424133,-1.152496 -2.319,-1.877991c-1.063019,-0.861847 -2.31781,-1.902161 -3.777008,-3.174011c-1.723755,-1.502441 -6.000153,-5.432373 -8.59433,-7.909821c-2.873505Line truncated
</g>
</svg>

After

Width:  |  Height:  |  Size: 14 KiB

@@ -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;