edit_paint.php 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  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(
  70. 'url' => api_get_path(WEB_CODE_PATH).'group/group_space.php?'.api_get_cidreq(),
  71. 'name' => get_lang('GroupSpace'),
  72. );
  73. $group_document = true;
  74. $noPHP_SELF = true;
  75. }
  76. $is_certificate_mode = DocumentManager::is_certificate_mode($dir);
  77. if (!$is_certificate_mode)
  78. $interbreadcrumb[]= array("url" => "./document.php?curdirpath=".urlencode($my_cur_dir_path).'&'.api_get_cidreq(), "name"=> get_lang('Documents'));
  79. else
  80. $interbreadcrumb[]= array ('url' => '../gradebook/'.$_SESSION['gradebook_dest'], 'name' => get_lang('Gradebook'));
  81. // Interbreadcrumb for the current directory root path
  82. if (empty($document_data['parents'])) {
  83. $interbreadcrumb[] = array('url' => '#', 'name' => $document_data['title']);
  84. } else {
  85. foreach($document_data['parents'] as $document_sub_data) {
  86. if ($document_data['title'] == $document_sub_data['title']) {
  87. continue;
  88. }
  89. $interbreadcrumb[] = array('url' => $document_sub_data['document_url'], 'name' => $document_sub_data['title']);
  90. }
  91. }
  92. $is_allowedToEdit = api_is_allowed_to_edit(null, true) || $_SESSION['group_member_with_upload_rights'] ||
  93. DocumentManager::is_my_shared_folder(api_get_user_id(), $dir, $current_session_id);
  94. if (!$is_allowedToEdit) {
  95. api_not_allowed(true);
  96. }
  97. Event::event_access_tool(TOOL_DOCUMENT);
  98. Display :: display_header($nameTools, 'Doc');
  99. echo '<div class="actions">';
  100. echo '<a href="document.php?id='.$parent_id.'&'.api_get_cidreq().'">'.
  101. Display::return_icon('back.png',get_lang('BackTo').' '.get_lang('DocumentsOverview'),'',ICON_SIZE_MEDIUM).'</a>';
  102. echo '<a href="edit_document.php?'.api_get_cidreq().'&id='.$document_id.'&'.api_get_cidreq().'&origin=editpaint">'.
  103. Display::return_icon('edit.png', get_lang('Rename').'/'.get_lang('Comment'),'',ICON_SIZE_MEDIUM).'</a>';
  104. echo '</div>';
  105. ///pixlr
  106. $title=$file;//disk name. No sql name because pixlr return this when save
  107. $pixlr_code_translation_table = array('' => 'en', 'pt' => 'pt-Pt', 'sr' => 'sr_latn');
  108. $langpixlr = api_get_language_isocode();
  109. $langpixlr = isset($pixlr_code_translation_table[$langpixlr]) ? $pixlredit_code_translation_table[$langpixlr] : $langpixlr;
  110. $loc=$langpixlr;// deprecated ?? TODO:check pixlr read user browser
  111. $exit_path=api_get_path(WEB_CODE_PATH).'document/exit_pixlr.php';
  112. $_SESSION['exit_pixlr']= Security::remove_XSS($parent_id);
  113. $referrer="Chamilo";
  114. $target_path=api_get_path(WEB_CODE_PATH).'document/save_pixlr.php';
  115. $target=$target_path;
  116. $locktarget="true";
  117. $locktitle="false";
  118. if ($_SERVER['HTTP_HOST']=="localhost") {
  119. $path_and_file= api_get_path(SYS_SERVER_ROOT_PATH).'/crossdomain.xml';
  120. if (!file_exists($path_and_file)) {
  121. $crossdomain='<?xml version="1.0"?>
  122. <!DOCTYPE cross-domain-policy SYSTEM "http://www.adobe.com/xml/dtds/cross-domain-policy.dtd">
  123. <cross-domain-policy>
  124. <allow-access-from domain="cdn.pixlr.com" />
  125. <site-control permitted-cross-domain-policies="master-only"/>
  126. <allow-http-request-headers-from domain="cnd.pixlr.com" headers="*" secure="true"/>
  127. </cross-domain-policy>';//more open domain="*"
  128. @file_put_contents($path_and_file, $crossdomain);
  129. }
  130. $credentials="true";
  131. }
  132. else {
  133. $credentials="false";
  134. }
  135. //make temp images
  136. $temp_folder=api_get_path(SYS_ARCHIVE_PATH).'temp/images';
  137. if (!file_exists($temp_folder)) {
  138. @mkdir($temp_folder, api_get_permissions_for_new_directories(), true);//TODO:check $permissions value, now empty;
  139. }
  140. //make htaccess with allow from all, and file index.html into temp/images
  141. $htaccess=api_get_path(SYS_ARCHIVE_PATH).'temp/images/.htaccess';
  142. if (!file_exists($htaccess)) {
  143. $htaccess_content="order deny,allow\r\nallow from all\r\nOptions -Indexes";
  144. $fp = @ fopen(api_get_path(SYS_ARCHIVE_PATH).'temp/images/.htaccess', 'w');
  145. if ($fp) {
  146. fwrite($fp, $htaccess_content);
  147. fclose($fp);
  148. }
  149. }
  150. $html_index=api_get_path(SYS_ARCHIVE_PATH).'temp/images/index.html';
  151. if (!file_exists($html_index)) {
  152. $html_index_content="<html><head></head><body></body></html>";
  153. $fp = @ fopen(api_get_path(SYS_ARCHIVE_PATH).'temp/images/index.html', 'w');
  154. if ($fp) {
  155. fwrite($fp, $html_index_content);
  156. fclose($fp);
  157. }
  158. }
  159. //encript temp name file
  160. $name_crip=sha1(uniqid());//encript
  161. $findext= explode(".", $file);
  162. $extension= $findext[count($findext)-1];
  163. $file_crip=$name_crip.'.'.$extension;
  164. //copy file to temp/images directory
  165. $from=$filepath.$file;
  166. $to=api_get_path(SYS_ARCHIVE_PATH).'temp/images/'.$file_crip;
  167. copy($from, $to);
  168. $_SESSION['temp_realpath_image']=$to;
  169. //load image to url
  170. $to_url=api_get_path(WEB_ARCHIVE_PATH).'temp/images/'.$file_crip;
  171. $image=urlencode($to_url);
  172. $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;
  173. //make frame an send image
  174. ?>
  175. <script type="text/javascript">
  176. 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>');
  177. function resizeIframe() {
  178. var height = window.innerHeight;
  179. //max lower size
  180. if (height<600) {
  181. height=600;
  182. }
  183. document.getElementById('frame').style.height = height +"px";
  184. };
  185. document.getElementById('frame').onload = resizeIframe;
  186. window.onresize = resizeIframe;
  187. </script>
  188. <?php
  189. echo '<noscript>';
  190. 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>';
  191. echo '</noscript>';
  192. Display::display_footer();