edit_paint.php 7.7 KB

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