create_paint.php 6.0 KB

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