create_paint.php 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. use ChamiloSession as Session;
  4. /**
  5. * This file allows creating audio files from a text.
  6. *
  7. * @package chamilo.document
  8. *
  9. * @author Juan Carlos Raña Trabado
  10. * @since 30/January/2011
  11. * @todo clean all file
  12. */
  13. require_once __DIR__.'/../inc/global.inc.php';
  14. $this_section = SECTION_COURSES;
  15. $nameTools = get_lang('PhotoRetouching');
  16. $groupRights = Session::read('group_member_with_upload_rights');
  17. api_protect_course_script();
  18. api_block_anonymous_users();
  19. $_course = api_get_course_info();
  20. if (api_get_setting('enabled_support_paint') === 'false') {
  21. api_not_allowed(true);
  22. }
  23. $document_data = DocumentManager::get_document_data_by_id($_GET['id'], api_get_course_id(), true);
  24. if (empty($document_data)) {
  25. if (api_is_in_group()) {
  26. $group_properties = GroupManager::get_group_properties(api_get_group_id());
  27. $document_id = DocumentManager::get_document_id(api_get_course_info(), $group_properties['directory']);
  28. $document_data = DocumentManager::get_document_data_by_id($document_id, api_get_course_id());
  29. }
  30. }
  31. $document_id = $document_data['id'];
  32. $dir = $document_data['path'];
  33. //$dir = isset($_GET['dir']) ? Security::remove_XSS($_GET['dir']) : Security::remove_XSS($_POST['dir']);
  34. $is_allowed_to_edit = api_is_allowed_to_edit(null, true);
  35. //path for pixlr save
  36. $paintDir = Security::remove_XSS($dir);
  37. if ($paintDir == '/') {
  38. $paintDir = '';
  39. }
  40. Session::write('paint_dir', $paintDir);
  41. Session::write('paint_file', get_lang('NewImage'));
  42. // Please, do not modify this dirname formatting
  43. if (strstr($dir, '..')) {
  44. $dir = '/';
  45. }
  46. if ($dir[0] == '.') {
  47. $dir = substr($dir, 1);
  48. }
  49. if ($dir[0] != '/') {
  50. $dir = '/'.$dir;
  51. }
  52. if ($dir[strlen($dir) - 1] != '/') {
  53. $dir .= '/';
  54. }
  55. $filepath = api_get_path(SYS_COURSE_PATH).$_course['path'].'/document'.$dir;
  56. if (!is_dir($filepath)) {
  57. $filepath = api_get_path(SYS_COURSE_PATH).$_course['path'].'/document/';
  58. $dir = '/';
  59. }
  60. $groupId = api_get_group_id();
  61. if (!empty($groupId)) {
  62. $interbreadcrumb[] = array(
  63. "url" => api_get_path(WEB_CODE_PATH)."group/group_space.php?".api_get_cidreq(),
  64. "name" => get_lang('GroupSpace'),
  65. );
  66. $noPHP_SELF = true;
  67. $group = GroupManager::get_group_properties($groupId);
  68. $path = explode('/', $dir);
  69. if ('/'.$path[1] != $group['directory']) {
  70. api_not_allowed(true);
  71. }
  72. }
  73. $interbreadcrumb[] = array(
  74. "url" => "./document.php?curdirpath=".urlencode($dir)."&".api_get_cidreq(),
  75. "name" => get_lang('Documents'),
  76. );
  77. if (!api_is_allowed_in_course()) {
  78. api_not_allowed(true);
  79. }
  80. if (!($is_allowed_to_edit || $groupRights ||
  81. DocumentManager::is_my_shared_folder($_user['user_id'], Security::remove_XSS($dir), api_get_session_id()))
  82. ) {
  83. api_not_allowed(true);
  84. }
  85. /* Header */
  86. Event::event_access_tool(TOOL_DOCUMENT);
  87. $display_dir = $dir;
  88. if (isset ($group)) {
  89. $display_dir = explode('/', $dir);
  90. unset($display_dir[0]);
  91. unset($display_dir[1]);
  92. $display_dir = implode('/', $display_dir);
  93. }
  94. // Interbreadcrumb for the current directory root path
  95. if (empty($document_data['parents'])) {
  96. $interbreadcrumb[] = array('url' => '#', 'name' => $document_data['title']);
  97. } else {
  98. foreach ($document_data['parents'] as $document_sub_data) {
  99. $interbreadcrumb[] = array(
  100. 'url' => $document_sub_data['document_url'],
  101. 'name' => $document_sub_data['title']
  102. );
  103. }
  104. }
  105. Display :: display_header($nameTools, 'Doc');
  106. echo '<div class="actions">';
  107. echo '<a href="document.php?id='.$document_id.'">'.
  108. Display::return_icon(
  109. 'back.png',
  110. get_lang('BackTo').' '.get_lang('DocumentsOverview'),
  111. '',
  112. ICON_SIZE_MEDIUM
  113. ).
  114. '</a>';
  115. echo '</div>';
  116. // pixlr
  117. // max size 1 Mb ??
  118. $title = urlencode(utf8_encode(get_lang('NewImage'))); //TODO:check
  119. //
  120. $image = Display::returnIconPath('canvas1024x768.png');
  121. //
  122. $pixlr_code_translation_table = array('' => 'en', 'pt' => 'pt-Pt', 'sr' => 'sr_latn');
  123. $langpixlr = api_get_language_isocode();
  124. $langpixlr = isset($pixlr_code_translation_table[$langpixlr]) ? $pixlredit_code_translation_table[$langpixlr] : $langpixlr;
  125. $loc = $langpixlr; // deprecated ?? TODO:check pixlr read user browser
  126. $exit_path = api_get_path(WEB_CODE_PATH).'document/exit_pixlr.php';
  127. Session::write('exit_pixlr', $document_data['path']);
  128. $referrer = "Chamilo";
  129. $target_path = api_get_path(WEB_CODE_PATH).'document/save_pixlr.php';
  130. $target = $target_path;
  131. $locktarget = "true";
  132. $locktitle = "false";
  133. if ($_SERVER['HTTP_HOST'] == "localhost") {
  134. $path_and_file = api_get_path(SYS_PATH).'/crossdomain.xml';
  135. if (!file_exists($path_and_file)) {
  136. $crossdomain = '<?xml version="1.0"?>
  137. <!DOCTYPE cross-domain-policy SYSTEM "http://www.adobe.com/xml/dtds/cross-domain-policy.dtd">
  138. <cross-domain-policy>
  139. <allow-access-from domain="cdn.pixlr.com" />
  140. <site-control permitted-cross-domain-policies="master-only"/>
  141. <allow-http-request-headers-from domain="cnd.pixlr.com" headers="*" secure="true"/>
  142. </cross-domain-policy>';//more open domain="*"
  143. @file_put_contents($path_and_file, $crossdomain);
  144. }
  145. $credentials = "true";
  146. } else {
  147. $credentials = "false";
  148. }
  149. $pixlr_url = '//pixlr.com/editor/?title='.$title.'&image='.$image.'&loc='.$loc.'&referrer='.$referrer.'&target='.$target.'&exit='.$exit_path.'&locktarget='.$locktarget.'&locktitle='.$locktitle.'&credentials='.$credentials;
  150. ?>
  151. <script>
  152. 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></div>');
  153. function resizeIframe() {
  154. var height = window.innerHeight;
  155. //max lower size
  156. if (height<600) {
  157. height=600;
  158. }
  159. document.getElementById('frame').style.height = height +"px";
  160. };
  161. document.getElementById('frame').onload = resizeIframe;
  162. window.onresize = resizeIframe;
  163. </script>
  164. <?php
  165. echo '<noscript>';
  166. 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>';
  167. echo '</noscript>';
  168. Display::display_footer();