create_paint.php 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * This file allows creating audio files from a text.
  5. *
  6. * @package chamilo.document
  7. *
  8. * @author Juan Carlos Raña Trabado
  9. * @since 30/January/2011
  10. * @todo clean all file
  11. */
  12. /**
  13. * Code
  14. */
  15. /* INIT SECTION */
  16. $language_file = array('document');
  17. //require_once '../inc/global.inc.php';
  18. $_SESSION['whereami'] = 'document/createpaint';
  19. $this_section = SECTION_COURSES;
  20. require_once 'document.inc.php';
  21. $nameTools = get_lang('PhotoRetouching');
  22. api_protect_course_script();
  23. api_block_anonymous_users();
  24. if (api_get_setting('enabled_support_paint') == 'false') {
  25. api_not_allowed(true);
  26. }
  27. $document_data = DocumentManager::get_document_data_by_id($_GET['id'], api_get_course_id(), true);
  28. if (empty($document_data)) {
  29. if (api_is_in_group()) {
  30. $group_properties = GroupManager::get_group_properties(api_get_group_id());
  31. $document_id = DocumentManager::get_document_id(api_get_course_info(), $group_properties['directory']);
  32. $document_data = DocumentManager::get_document_data_by_id($document_id, api_get_course_id());
  33. }
  34. }
  35. $document_id = $document_data['id'];
  36. $dir = $document_data['path'];
  37. //$dir = isset($_GET['dir']) ? Security::remove_XSS($_GET['dir']) : Security::remove_XSS($_POST['dir']);
  38. $is_allowed_to_edit = api_is_allowed_to_edit(null, true);
  39. //path for pixlr save
  40. $_SESSION['paint_dir']=Security::remove_XSS($dir);
  41. if ($_SESSION['paint_dir']=='/'){
  42. $_SESSION['paint_dir']='';
  43. }
  44. $_SESSION['paint_file']=get_lang('NewImage');
  45. // Please, do not modify this dirname formatting
  46. if (strstr($dir, '..')) {
  47. $dir = '/';
  48. }
  49. if ($dir[0] == '.') {
  50. $dir = substr($dir, 1);
  51. }
  52. if ($dir[0] != '/') {
  53. $dir = '/'.$dir;
  54. }
  55. if ($dir[strlen($dir) - 1] != '/') {
  56. $dir .= '/';
  57. }
  58. $filepath = api_get_path(SYS_COURSE_PATH).$_course['path'].'/document'.$dir;
  59. if (!is_dir($filepath)) {
  60. $filepath = api_get_path(SYS_COURSE_PATH).$_course['path'].'/document/';
  61. $dir = '/';
  62. }
  63. //groups //TODO: clean
  64. if (isset ($_SESSION['_gid']) && $_SESSION['_gid'] != 0) {
  65. $req_gid = '&amp;gidReq='.$_SESSION['_gid'];
  66. $interbreadcrumb[] = array ("url" => "../group/group_space.php?gidReq=".$_SESSION['_gid'], "name" => get_lang('GroupSpace'));
  67. $noPHP_SELF = true;
  68. $to_group_id = $_SESSION['_gid'];
  69. $group = GroupManager :: get_group_properties($to_group_id);
  70. $path = explode('/', $dir);
  71. if ('/'.$path[1] != $group['directory']) {
  72. api_not_allowed(true);
  73. }
  74. }
  75. $interbreadcrumb[] = array ("url" => "./document.php?curdirpath=".urlencode($dir).$req_gid, "name" => get_lang('Documents'));
  76. if (!$is_allowed_in_course) {
  77. api_not_allowed(true);
  78. }
  79. if (!($is_allowed_to_edit || GroupManager::groupMemberWithUploadRights() || is_my_shared_folder($_user['user_id'], Security::remove_XSS($dir),api_get_session_id()))) {
  80. api_not_allowed(true);
  81. }
  82. /* Header */
  83. Event::event_access_tool(TOOL_DOCUMENT);
  84. $display_dir = $dir;
  85. if (isset ($group)) {
  86. $display_dir = explode('/', $dir);
  87. unset ($display_dir[0]);
  88. unset ($display_dir[1]);
  89. $display_dir = implode('/', $display_dir);
  90. }
  91. // Interbreadcrumb for the current directory root path
  92. if (empty($document_data['parents'])) {
  93. $interbreadcrumb[] = array('url' => '#', 'name' => $document_data['title']);
  94. } else {
  95. foreach($document_data['parents'] as $document_sub_data) {
  96. $interbreadcrumb[] = array('url' => $document_sub_data['document_url'], 'name' => $document_sub_data['title']);
  97. }
  98. }
  99. Display :: display_header($nameTools, 'Doc');
  100. echo '<div class="actions">';
  101. echo '<a href="document.php?id='.$document_id.'">'.Display::return_icon('back.png',get_lang('BackTo').' '.get_lang('DocumentsOverview'),'',ICON_SIZE_MEDIUM).'</a>';
  102. echo '</div>';
  103. ///pixlr
  104. // max size 1 Mb ??
  105. $title=urlencode(utf8_encode(get_lang('NewImage')));//TODO:check
  106. //
  107. $image=api_get_path(WEB_IMG_PATH).'canvas1024x768.png';
  108. //
  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']=$document_data['path'];
  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_SERVER_ROOT_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. $pixlr_url = api_get_protocol().'://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;
  138. ?>
  139. <script type="text/javascript">
  140. 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>');
  141. function resizeIframe() {
  142. var height = window.innerHeight;
  143. //max lower size
  144. if (height<600) {
  145. height=600;
  146. }
  147. document.getElementById('frame').style.height = height +"px";
  148. };
  149. document.getElementById('frame').onload = resizeIframe;
  150. window.onresize = resizeIframe;
  151. </script>
  152. <?php
  153. echo '<noscript>';
  154. 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>';
  155. echo '</noscript>';
  156. Display::display_footer();