edit_paint.php 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. use ChamiloSession as Session;
  4. /**
  5. * This file allows creating new svg and png documents with an online editor.
  6. *
  7. * @package chamilo.document
  8. * @todo used the document_id instead of the curdirpath
  9. *
  10. * @author Juan Carlos Raña Trabado
  11. * @since 30/january/2011
  12. */
  13. require_once __DIR__.'/../inc/global.inc.php';
  14. $this_section = SECTION_COURSES;
  15. $groupRights = Session::read('group_member_with_upload_rights');
  16. api_protect_course_script(true);
  17. api_block_anonymous_users();
  18. $groupId = api_get_group_id();
  19. $document_data = DocumentManager::get_document_data_by_id(
  20. $_GET['id'],
  21. api_get_course_id(),
  22. true
  23. );
  24. if (empty($document_data)) {
  25. api_not_allowed();
  26. } else {
  27. $document_id = $document_data['id'];
  28. $file_path = $document_data['path'];
  29. $dir = dirname($document_data['path']);
  30. $parent_id = DocumentManager::get_document_id(api_get_course_info(), $dir);
  31. $my_cur_dir_path = isset($_GET['curdirpath']) ? Security::remove_XSS($_GET['curdirpath']) : null;
  32. }
  33. $dir = str_replace('\\', '/', $dir); //and urlencode each url $curdirpath (hack clean $curdirpath under Windows - Bug #3261)
  34. /* Constants & Variables */
  35. $current_session_id = api_get_session_id();
  36. //path for pixlr save
  37. Session::write('paint_dir', Security::remove_XSS($dir));
  38. if ($dir == '/') {
  39. Session::write('paint_dir', '');
  40. }
  41. Session::write('paint_file', basename(Security::remove_XSS($file_path)));
  42. $get_file = Security::remove_XSS($file_path);
  43. $file = basename($get_file);
  44. $temp_file = explode(".", $file);
  45. $filename = $temp_file[0];
  46. $nameTools = get_lang('EditDocument').': '.$filename;
  47. $courseDir = $_course['path'].'/document';
  48. $is_allowed_to_edit = api_is_allowed_to_edit(null, true);
  49. /* Other initialization code */
  50. /* Please, do not modify this dirname formatting */
  51. if (strstr($dir, '..')) {
  52. $dir = '/';
  53. }
  54. if ($dir[0] == '.') {
  55. $dir = substr($dir, 1);
  56. }
  57. if ($dir[0] != '/') {
  58. $dir = '/'.$dir;
  59. }
  60. if ($dir[strlen($dir) - 1] != '/') {
  61. $dir .= '/';
  62. }
  63. $filepath = api_get_path(SYS_COURSE_PATH).$_course['path'].'/document'.$dir;
  64. if (!is_dir($filepath)) {
  65. $filepath = api_get_path(SYS_COURSE_PATH).$_course['path'].'/document/';
  66. $dir = '/';
  67. }
  68. //groups //TODO:clean
  69. if (!empty($groupId)) {
  70. $interbreadcrumb[] = array(
  71. 'url' => api_get_path(WEB_CODE_PATH).'group/group_space.php?'.api_get_cidreq(),
  72. 'name' => get_lang('GroupSpace'),
  73. );
  74. $group_document = true;
  75. $noPHP_SELF = true;
  76. }
  77. $is_certificate_mode = DocumentManager::is_certificate_mode($dir);
  78. if (!$is_certificate_mode) {
  79. $interbreadcrumb[] = array(
  80. "url" => "./document.php?curdirpath=".urlencode($my_cur_dir_path).'&'.api_get_cidreq(),
  81. "name" => get_lang('Documents')
  82. );
  83. } else {
  84. $interbreadcrumb[] = array(
  85. 'url' => Category::getUrl(),
  86. 'name' => get_lang('Gradebook')
  87. );
  88. }
  89. // Interbreadcrumb for the current directory root path
  90. if (empty($document_data['parents'])) {
  91. $interbreadcrumb[] = array('url' => '#', 'name' => $document_data['title']);
  92. } else {
  93. foreach ($document_data['parents'] as $document_sub_data) {
  94. if ($document_data['title'] == $document_sub_data['title']) {
  95. continue;
  96. }
  97. $interbreadcrumb[] = array('url' => $document_sub_data['document_url'], 'name' => $document_sub_data['title']);
  98. }
  99. }
  100. $is_allowedToEdit = api_is_allowed_to_edit(null, true) || $groupRights ||
  101. DocumentManager::is_my_shared_folder(api_get_user_id(), $dir, $current_session_id);
  102. if (!$is_allowedToEdit) {
  103. api_not_allowed(true);
  104. }
  105. Event::event_access_tool(TOOL_DOCUMENT);
  106. Display :: display_header($nameTools, 'Doc');
  107. echo '<div class="actions">';
  108. echo '<a href="document.php?id='.$parent_id.'&'.api_get_cidreq().'">'.
  109. Display::return_icon('back.png', get_lang('BackTo').' '.get_lang('DocumentsOverview'), '', ICON_SIZE_MEDIUM).'</a>';
  110. echo '<a href="edit_document.php?'.api_get_cidreq().'&id='.$document_id.'&'.api_get_cidreq().'&origin=editpaint">'.
  111. Display::return_icon('edit.png', get_lang('Rename').'/'.get_lang('Comment'), '', ICON_SIZE_MEDIUM).'</a>';
  112. echo '</div>';
  113. ///pixlr
  114. $title = $file; //disk name. No sql name because pixlr return this when save
  115. $pixlr_code_translation_table = array('' => 'en', 'pt' => 'pt-Pt', 'sr' => 'sr_latn');
  116. $langpixlr = api_get_language_isocode();
  117. $langpixlr = isset($pixlr_code_translation_table[$langpixlr]) ? $pixlredit_code_translation_table[$langpixlr] : $langpixlr;
  118. $loc = $langpixlr; // deprecated ?? TODO:check pixlr read user browser
  119. $exit_path = api_get_path(WEB_CODE_PATH).'document/exit_pixlr.php';
  120. Session::write('exit_pixlr', Security::remove_XSS($parent_id));
  121. $referrer = "Chamilo";
  122. $target_path = api_get_path(WEB_CODE_PATH).'document/save_pixlr.php';
  123. $target = $target_path;
  124. $locktarget = "true";
  125. $locktitle = "false";
  126. if ($_SERVER['HTTP_HOST'] == "localhost") {
  127. $path_and_file = api_get_path(SYS_PATH).'/crossdomain.xml';
  128. if (!file_exists($path_and_file)) {
  129. $crossdomain = '<?xml version="1.0"?>
  130. <!DOCTYPE cross-domain-policy SYSTEM "http://www.adobe.com/xml/dtds/cross-domain-policy.dtd">
  131. <cross-domain-policy>
  132. <allow-access-from domain="cdn.pixlr.com" />
  133. <site-control permitted-cross-domain-policies="master-only"/>
  134. <allow-http-request-headers-from domain="cnd.pixlr.com" headers="*" secure="true"/>
  135. </cross-domain-policy>';//more open domain="*"
  136. @file_put_contents($path_and_file, $crossdomain);
  137. }
  138. $credentials = "true";
  139. } else {
  140. $credentials = "false";
  141. }
  142. //make temp images
  143. $temp_folder = api_get_path(SYS_ARCHIVE_PATH).'temp/images';
  144. if (!file_exists($temp_folder)) {
  145. @mkdir($temp_folder, api_get_permissions_for_new_directories(), true); //TODO:check $permissions value, now empty;
  146. }
  147. //make htaccess with allow from all, and file index.html into temp/images
  148. $htaccess = api_get_path(SYS_ARCHIVE_PATH).'temp/images/.htaccess';
  149. if (!file_exists($htaccess)) {
  150. $htaccess_content = "order deny,allow\r\nallow from all\r\nOptions -Indexes";
  151. $fp = @ fopen(api_get_path(SYS_ARCHIVE_PATH).'temp/images/.htaccess', 'w');
  152. if ($fp) {
  153. fwrite($fp, $htaccess_content);
  154. fclose($fp);
  155. }
  156. }
  157. $html_index = api_get_path(SYS_ARCHIVE_PATH).'temp/images/index.html';
  158. if (!file_exists($html_index)) {
  159. $html_index_content = "<html><head></head><body></body></html>";
  160. $fp = @ fopen(api_get_path(SYS_ARCHIVE_PATH).'temp/images/index.html', 'w');
  161. if ($fp) {
  162. fwrite($fp, $html_index_content);
  163. fclose($fp);
  164. }
  165. }
  166. //encript temp name file
  167. $name_crip = sha1(uniqid()); //encript
  168. $findext = explode(".", $file);
  169. $extension = $findext[count($findext) - 1];
  170. $file_crip = $name_crip.'.'.$extension;
  171. //copy file to temp/images directory
  172. $from = $filepath.$file;
  173. $to = api_get_path(SYS_ARCHIVE_PATH).'temp/images/'.$file_crip;
  174. copy($from, $to);
  175. Session::write('temp_realpath_image', $to);
  176. //load image to url
  177. $to_url = api_get_path(WEB_ARCHIVE_PATH).'temp/images/'.$file_crip;
  178. $image = urlencode($to_url);
  179. $pixlr_url = '//pixlr.com/editor/?title='.$title.'&image='.$image.'&loc='.$loc.'&referrer='.$referrer.'&target='.$target.'&exit='.$exit_path.'&locktarget='.$locktarget.'&locktitle='.$locktitle.'&credentials='.$credentials;
  180. //make frame an send image
  181. ?>
  182. <script>
  183. document.write ('<iframe id="frame" frameborder="0" scrolling="no" src="<?php echo $pixlr_url; ?>" width="100%" height="100%"><noframes><p>Sorry, your browser does not handle frames</p></noframes></iframe>');
  184. function resizeIframe() {
  185. var height = window.innerHeight;
  186. //max lower size
  187. if (height<600) {
  188. height=600;
  189. }
  190. document.getElementById('frame').style.height = height +"px";
  191. };
  192. document.getElementById('frame').onload = resizeIframe;
  193. window.onresize = resizeIframe;
  194. </script>
  195. <?php
  196. echo '<noscript>';
  197. echo '<iframe style="height: 600px; width: 100%;" scrolling="no" frameborder="0" src="'.$pixlr_url.'"><noframes><p>Sorry, your browser does not handle frames</p></noframes></iframe>';
  198. echo '</noscript>';
  199. Display::display_footer();