edit_paint.php 7.9 KB

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