users.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. <?php
  2. /* Integrate svg-edit libraries with Chamilo default documents
  3. * @author Juan Carlos Raña Trabado
  4. * @since 25/september/2010
  5. */
  6. $language_file = array('userInfo');
  7. //Chamilo load libraries
  8. require_once '../../../../../inc/global.inc.php';
  9. //Add security from Chamilo
  10. api_protect_course_script();
  11. api_block_anonymous_users();
  12. $user_disk_path = api_get_path(SYS_PATH).'main/upload/users/'.api_get_user_id().'/my_files/';
  13. $user_web_path = api_get_path(WEB_PATH).'main/upload/users/'.api_get_user_id().'/my_files/';
  14. //get all files and folders
  15. $scan_files = scandir($user_disk_path);
  16. //get all svg and png files
  17. $accepted_extensions = array('.svg', '.png');
  18. if (is_array($scan_files) && count($scan_files) > 0) {
  19. foreach ($scan_files as & $file) {
  20. $slideshow_extension = strrchr($file, '.');
  21. $slideshow_extension = strtolower($slideshow_extension);
  22. if (in_array($slideshow_extension, $accepted_extensions)) {
  23. $png_svg_files[] =$file;
  24. }
  25. }
  26. }
  27. $style = '<style>';
  28. $style .= '@import "'.api_get_path(WEB_CSS_PATH).'base.css";';
  29. $style .= '@import "'.api_get_path(WEB_CSS_PATH).api_get_visual_theme().'/default.css";';
  30. $style .='</style>';
  31. ?>
  32. <!doctype html>
  33. <?php echo api_get_js('jquery.js'); ?>
  34. <?php echo $style ?>
  35. <body>
  36. <?php
  37. echo '<h2>'.get_lang('SocialNetwork').': '.get_lang('MyFiles').'</h2>';
  38. if (!empty($png_svg_files)) {
  39. echo '<h3>'.get_lang('SelectSVGEditImage').'</h3>';
  40. echo '<ul>';
  41. foreach($png_svg_files as $filename) {
  42. $image=$user_disk_path.$filename;
  43. if (strpos($filename, "svg")){
  44. $new_sizes['width'] = 60;
  45. $new_sizes['height'] = 60;
  46. }
  47. else {
  48. $new_sizes = api_resize_image($image, 60, 60);
  49. }
  50. 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>';
  51. }
  52. echo '</ul>';
  53. } else {
  54. Display::display_warning_message(get_lang('NoSVGImages'));
  55. }
  56. ?>
  57. </body>
  58. <script>
  59. $('a').click(function() {
  60. var href = this.href;
  61. // Convert Non-SVG images to data URL first
  62. // (this could also have been done server-side by the library)
  63. if(this.href.indexOf('.svg') === -1) {
  64. var meta_str = JSON.stringify({
  65. name: $(this).text(),
  66. id: href
  67. });
  68. window.top.postMessage(meta_str, "*");
  69. var img = new Image();
  70. img.onload = function() {
  71. var canvas = document.createElement("canvas");
  72. canvas.width = this.width;
  73. canvas.height = this.height;
  74. // load the raster image into the canvas
  75. canvas.getContext("2d").drawImage(this,0,0);
  76. // retrieve the data: URL
  77. try {
  78. var dataurl = canvas.toDataURL();
  79. } catch(err) {
  80. // This fails in Firefox with file:// URLs :(
  81. alert("Data URL conversion failed: " + err);
  82. var dataurl = "";
  83. }
  84. window.top.postMessage('|' + href + '|' + dataurl, "*");
  85. }
  86. img.src = href;
  87. } else {
  88. // Send metadata (also indicates file is about to be sent)
  89. var meta_str = JSON.stringify({
  90. name: $(this).text(),
  91. id: href
  92. });
  93. window.top.postMessage(meta_str, "*");
  94. // Do ajax request for image's href value
  95. $.get(href, function(data) {
  96. data = '|' + href + '|' + data;
  97. // This is where the magic happens!
  98. window.top.postMessage(data, "*");
  99. }, 'html'); // 'html' is necessary to keep returned data as a string
  100. }
  101. return false;
  102. });
  103. </script>