edit_paint.php 7.8 KB

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