showinframes.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * This file will show documents in a separate frame.
  5. * We don't like frames, but it was the best of two bad things.
  6. *
  7. * display html files within Chamilo - html files have the Chamilo header.
  8. *
  9. * --- advantages ---
  10. * users "feel" like they are in Chamilo,
  11. * and they can use the navigation context provided by the header.
  12. * --- design ---
  13. * a file gets a parameter (an html file) and shows
  14. * - chamilo header
  15. * - html file from parameter
  16. * - (removed) chamilo footer
  17. *
  18. * @version 0.6
  19. *
  20. * @author Roan Embrechts (roan.embrechts@vub.ac.be)
  21. *
  22. * @package chamilo.document
  23. */
  24. require_once __DIR__.'/../inc/global.inc.php';
  25. api_protect_course_script();
  26. $header_file = isset($_GET['file']) ? Security::remove_XSS($_GET['file']) : null;
  27. $document_id = (int) $_GET['id'];
  28. $originIsLearnpath = isset($_GET['origin']) && $_GET['origin'] === 'learnpathitem';
  29. $courseInfo = api_get_course_info();
  30. $course_code = api_get_course_id();
  31. $session_id = api_get_session_id();
  32. if (empty($courseInfo)) {
  33. api_not_allowed(true);
  34. }
  35. $show_web_odf = false;
  36. // Generate path
  37. if (!$document_id) {
  38. $document_id = DocumentManager::get_document_id($courseInfo, $header_file);
  39. }
  40. $document_data = DocumentManager::get_document_data_by_id(
  41. $document_id,
  42. $course_code,
  43. true,
  44. $session_id
  45. );
  46. if ($session_id != 0 && !$document_data) {
  47. $document_data = DocumentManager::get_document_data_by_id(
  48. $document_id,
  49. $course_code,
  50. true,
  51. 0
  52. );
  53. }
  54. if (empty($document_data)) {
  55. api_not_allowed(true);
  56. }
  57. $header_file = $document_data['path'];
  58. $name_to_show = $document_data['title'];
  59. $path_array = explode('/', str_replace('\\', '/', $header_file));
  60. $path_array = array_map('urldecode', $path_array);
  61. $header_file = implode('/', $path_array);
  62. $file = Security::remove_XSS(urldecode($document_data['path']));
  63. $file_root = $courseInfo['path'].'/document'.str_replace('%2F', '/', $file);
  64. $file_url_sys = api_get_path(SYS_COURSE_PATH).$file_root;
  65. $file_url_web = api_get_path(WEB_COURSE_PATH).$file_root;
  66. if (!file_exists($file_url_sys)) {
  67. api_not_allowed(true);
  68. }
  69. if (is_dir($file_url_sys)) {
  70. api_not_allowed(true);
  71. }
  72. $is_allowed_to_edit = api_is_allowed_to_edit();
  73. //fix the screen when you try to access a protected course through the url
  74. $is_allowed_in_course = api_is_allowed_in_course() || $is_allowed_to_edit;
  75. if ($is_allowed_in_course == false) {
  76. api_not_allowed(true);
  77. }
  78. // Check user visibility.
  79. $is_visible = DocumentManager::check_visibility_tree(
  80. $document_id,
  81. api_get_course_info(),
  82. api_get_session_id(),
  83. api_get_user_id(),
  84. api_get_group_id(),
  85. false
  86. );
  87. if (!$is_allowed_to_edit && !$is_visible) {
  88. api_not_allowed(true);
  89. }
  90. $pathinfo = pathinfo($header_file);
  91. $playerSupportedFiles = ['mp3', 'mp4', 'ogv', 'flv', 'm4v', 'webm'];
  92. $playerSupported = false;
  93. if (in_array(strtolower($pathinfo['extension']), $playerSupportedFiles)) {
  94. $playerSupported = true;
  95. }
  96. $group_id = api_get_group_id();
  97. $current_group = GroupManager::get_group_properties($group_id);
  98. $current_group_name = $current_group['name'];
  99. if (isset($group_id) && $group_id != '') {
  100. $interbreadcrumb[] = [
  101. 'url' => api_get_path(WEB_CODE_PATH).'group/group.php?'.api_get_cidreq(),
  102. 'name' => get_lang('Groups'),
  103. ];
  104. $interbreadcrumb[] = [
  105. 'url' => api_get_path(WEB_CODE_PATH).'group/group_space.php?'.api_get_cidreq(),
  106. 'name' => get_lang('GroupSpace').' '.$current_group_name,
  107. ];
  108. $name_to_show = explode('/', $name_to_show);
  109. unset($name_to_show[1]);
  110. $name_to_show = implode('/', $name_to_show);
  111. }
  112. $interbreadcrumb[] = [
  113. 'url' => './document.php?curdirpath='.dirname($header_file).'&'.api_get_cidreq(),
  114. 'name' => get_lang('Documents'),
  115. ];
  116. if (empty($document_data['parents'])) {
  117. if (isset($_GET['createdir'])) {
  118. $interbreadcrumb[] = [
  119. 'url' => $document_data['document_url'],
  120. 'name' => $document_data['title'],
  121. ];
  122. } else {
  123. $interbreadcrumb[] = [
  124. 'url' => '#',
  125. 'name' => $document_data['title'],
  126. ];
  127. }
  128. } else {
  129. foreach ($document_data['parents'] as $document_sub_data) {
  130. if (!isset($_GET['createdir']) && $document_sub_data['id'] == $document_data['id']) {
  131. $document_sub_data['document_url'] = '#';
  132. }
  133. $interbreadcrumb[] = [
  134. 'url' => $document_sub_data['document_url'],
  135. 'name' => $document_sub_data['title'],
  136. ];
  137. }
  138. }
  139. $this_section = SECTION_COURSES;
  140. $nameTools = get_lang('Documents');
  141. /**
  142. * Main code section.
  143. */
  144. header('Expires: Wed, 01 Jan 1990 00:00:00 GMT');
  145. //header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
  146. header('Last-Modified: Wed, 01 Jan 2100 00:00:00 GMT');
  147. header('Cache-Control: no-cache, must-revalidate');
  148. header('Pragma: no-cache');
  149. $browser_display_title = 'Documents - '.Security::remove_XSS($_GET['cidReq']).' - '.$file;
  150. // Only admins get to see the "no frames" link in pageheader.php, so students get a header that's not so high
  151. $frameheight = 135;
  152. if (api_is_course_admin()) {
  153. $frameheight = 165;
  154. }
  155. $frameReady = Display::getFrameReadyBlock('top.mainFrame');
  156. $web_odf_supported_files = DocumentManager::get_web_odf_extension_list();
  157. // PDF should be displayed with viewerJS
  158. $web_odf_supported_files[] = 'pdf';
  159. if (in_array(strtolower($pathinfo['extension']), $web_odf_supported_files)) {
  160. $show_web_odf = true;
  161. $htmlHeadXtra[] = '
  162. <script>
  163. resizeIframe = function() {
  164. var bodyHeight = $("body").height();
  165. var topbarHeight = $("#topbar").height();
  166. $("#viewerJSContent").height((bodyHeight - topbarHeight));
  167. }
  168. $(function() {
  169. $(window).resize(resizeIframe());
  170. });
  171. </script>'
  172. ;
  173. }
  174. // Activate code highlight.
  175. $isChatFolder = false;
  176. if (isset($document_data['parents']) && isset($document_data['parents'][0])) {
  177. $chatFolder = $document_data['parents'][0];
  178. if (isset($chatFolder['path']) && $chatFolder['path'] == '/chat_files') {
  179. $isChatFolder = true;
  180. }
  181. }
  182. if ($isChatFolder) {
  183. $htmlHeadXtra[] = api_get_js('highlight/highlight.pack.js');
  184. $htmlHeadXtra[] = api_get_css(api_get_path(WEB_CSS_PATH).'chat.css');
  185. $htmlHeadXtra[] = api_get_css(api_get_path(WEB_LIBRARY_PATH).'javascript/highlight/styles/github.css');
  186. $htmlHeadXtra[] = '
  187. <script>
  188. hljs.initHighlightingOnLoad();
  189. </script>';
  190. }
  191. $execute_iframe = true;
  192. if ($playerSupported) {
  193. $extension = api_strtolower($pathinfo['extension']);
  194. $execute_iframe = false;
  195. }
  196. if ($show_web_odf) {
  197. $execute_iframe = false;
  198. }
  199. $is_freemind_available = $pathinfo['extension'] == 'mm' && api_get_setting('enable_freemind') == 'true';
  200. if ($is_freemind_available) {
  201. $execute_iframe = false;
  202. }
  203. if (!$playerSupported && $execute_iframe) {
  204. $htmlHeadXtra[] = '<script>
  205. <!--
  206. var jQueryFrameReadyConfigPath = \''.api_get_jquery_web_path().'\';
  207. -->
  208. </script>';
  209. $htmlHeadXtra[] = '<script type="text/javascript" src="'.api_get_path(WEB_LIBRARY_PATH).'javascript/jquery.frameready.js"></script>';
  210. $htmlHeadXtra[] = '<script>
  211. // Fixes the content height of the frame
  212. $(function() {
  213. $(\'#mainFrame\').on(\'load\', function () {
  214. this.style.height = (this.contentWindow.document.body.scrollHeight + 50) + \'px\';
  215. });
  216. '.$frameReady.'
  217. });
  218. </script>';
  219. }
  220. if ($originIsLearnpath) {
  221. Display::display_reduced_header();
  222. } else {
  223. Display::display_header();
  224. }
  225. $file_url = api_get_path(WEB_COURSE_PATH).$courseInfo['path'].'/document'.$header_file;
  226. $file_url_web = $file_url.'?'.api_get_cidreq();
  227. if ($show_web_odf) {
  228. echo '<div class="text-center">';
  229. $browser = api_get_navigator();
  230. $pdfUrl = api_get_path(WEB_LIBRARY_PATH).'javascript/ViewerJS/index.html#'.$file_url;
  231. if ($browser['name'] == 'Mozilla' && preg_match('|.*\.pdf|i', $header_file)) {
  232. $pdfUrl = $file_url;
  233. }
  234. echo '<div id="viewerJS">';
  235. echo '<iframe id="viewerJSContent" frameborder="0" allowfullscreen="allowfullscreen" webkitallowfullscreen style="width:100%;"
  236. src="'.$pdfUrl.'">
  237. </iframe>';
  238. echo '</div>';
  239. echo '</div>';
  240. }
  241. if ($playerSupported) {
  242. echo DocumentManager::generateMediaPreview($file_url_web, $extension);
  243. }
  244. if ($is_freemind_available) {
  245. ?>
  246. <script type="text/javascript" src="<?php echo api_get_path(WEB_LIBRARY_PATH); ?>swfobject/swfobject.js"></script>
  247. <style type="text/css">
  248. #flashcontent {
  249. height: 500px;
  250. padding-top:10px;
  251. }
  252. </style>
  253. <div id="flashcontent" onmouseover="giveFocus();">
  254. Flash plugin or Javascript are turned off.
  255. Activate both and reload to view the mindmap
  256. </div>
  257. <script>
  258. function giveFocus() {
  259. document.visorFreeMind.focus();
  260. }
  261. document.onload=giveFocus;
  262. // <![CDATA[
  263. // for allowing using http://.....?mindmap.mm mode
  264. function getMap(map){
  265. var result=map;
  266. var loc=document.location+'';
  267. if(loc.indexOf(".mm")>0 && loc.indexOf("?")>0){
  268. result=loc.substring(loc.indexOf("?")+1);
  269. }
  270. return result;
  271. }
  272. var fo = new FlashObject("<?php echo api_get_path(WEB_LIBRARY_PATH); ?>freeMindFlashBrowser/visorFreemind.swf", "visorFreeMind", "100%", "100%", 6, "#ffffff");
  273. fo.addParam("quality", "high");
  274. //fo.addParam("bgcolor", "#a0a0f0");
  275. fo.addVariable("openUrl", "_blank");//Default value "_self"
  276. fo.addVariable("startCollapsedToLevel","3");//Default value = "-1", meaning do nothing, the mindmap will open as it was saved. The root node, or central node, of your mindmap is level zero. You could force the browser to open (unfold) your mind map to an expanded level using this variable.
  277. fo.addVariable("maxNodeWidth","200");
  278. //
  279. fo.addVariable("mainNodeShape","elipse");//"rectangle", "elipse", "none". None hide the main node. Default is "elipse"
  280. fo.addVariable("justMap","false");
  281. fo.addVariable("initLoadFile",getMap("<?php echo $file_url_web; ?>"));
  282. fo.addVariable("defaultToolTipWordWrap",200);//max width for tooltips. Default "600" pixels
  283. fo.addVariable("offsetX","left");//for the center of the mindmap. Admit also "left" and "right"
  284. fo.addVariable("offsetY","top");//for the center of the mindmap. Admit also "top" and "bottom"
  285. fo.addVariable("buttonsPos","top");//"top" or "bottom"
  286. fo.addVariable("min_alpha_buttons",20);//for dynamic view of buttons
  287. fo.addVariable("max_alpha_buttons",100);//for dynamic view of buttons
  288. fo.addVariable("scaleTooltips","false");
  289. //
  290. //extra
  291. //fo.addVariable("CSSFile","<?php // echo api_get_path(WEB_LIBRARY_PATH);?>freeMindFlashBrowser/flashfreemind.css");//
  292. //fo.addVariable("baseImagePath","<?php // echo api_get_path(WEB_LIBRARY_PATH);?>freeMindFlashBrowser/");//
  293. //fo.addVariable("justMap","false");//Hides all the upper control options. Default value "false"
  294. //fo.addVariable("noElipseMode","anyvalue");//for changing to old elipseNode edges. Default = not set
  295. //fo.addVariable("ShotsWidth","200");//The width of snapshots, in pixels.
  296. //fo.addVariable("genAllShots","true");//Preview shots (like the samples on the Shots Width page) will be generated for all linked maps when your main map loads. If you have a lot of linked maps, this could take some time to complete
  297. //fo.addVariable("unfoldAll","true"); //For each mindmap loaded start the display with all nodes unfolded. Another variable to be wary of!
  298. //fo.addVariable("toolTipsBgColor","0xaaeeaa");: bgcolor for tooltips ej;"0xaaeeaa"
  299. //fo.addVariable("defaultWordWrap","300"); //default 600
  300. //
  301. fo.write("flashcontent");
  302. // ]]>
  303. </script>
  304. <?php
  305. }
  306. if ($execute_iframe) {
  307. if ($isChatFolder) {
  308. $content = Security::remove_XSS(file_get_contents($file_url_sys));
  309. echo $content;
  310. } else {
  311. $parentId = $document_data['parent_id'];
  312. $url = api_get_path(WEB_CODE_PATH).'document/document.php?'.api_get_cidreq().'&id='.$parentId;
  313. $actionsLeft = Display::url(
  314. Display::return_icon('back.png', get_lang('Back'), '', ICON_SIZE_MEDIUM),
  315. $url
  316. );
  317. $groupMemberWithEditRights = false;
  318. $groupId = api_get_group_id();
  319. if (!empty($groupId)) {
  320. $groupInfo = GroupManager::get_group_properties($groupId);
  321. if ($groupInfo) {
  322. $groupMemberWithEditRights = GroupManager::allowUploadEditDocument(
  323. api_get_user_id(),
  324. api_get_course_int_id(),
  325. $groupInfo,
  326. $document_data
  327. );
  328. }
  329. }
  330. $allowToEdit = api_is_allowed_to_edit(null, true) || $groupMemberWithEditRights;
  331. if ($allowToEdit) {
  332. $actionsLeft .= Display::url(
  333. Display::return_icon(
  334. 'edit.png',
  335. get_lang('Modify'),
  336. '',
  337. ICON_SIZE_MEDIUM
  338. ),
  339. api_get_path(WEB_CODE_PATH).'document/edit_document.php?'.api_get_cidreq().'&id='.$document_id
  340. );
  341. $titleToShow = addslashes(basename($document_data['title']));
  342. $urlDeleteParams = http_build_query(
  343. [
  344. 'action' => 'delete_item',
  345. 'id' => $parentId,
  346. 'deleteid' => $document_data['id'],
  347. ]
  348. );
  349. $actionsLeft .= Display::url(
  350. Display::return_icon('delete.png', get_lang('Delete'), '', ICON_SIZE_MEDIUM),
  351. '#',
  352. [
  353. 'data-item-title' => $titleToShow,
  354. 'data-href' => api_get_path(WEB_CODE_PATH).'document/document.php?'.api_get_cidreq(
  355. ).'&'.$urlDeleteParams,
  356. 'data-toggle' => 'modal',
  357. 'data-target' => '#confirm-delete',
  358. ]
  359. );
  360. $actionsLeft .= Display::url(
  361. Display::return_icon('pdf.png', get_lang('Export2PDF'), [], ICON_SIZE_MEDIUM),
  362. api_get_path(WEB_CODE_PATH).'document/document.php?'.api_get_cidreq(
  363. ).'&action=export_to_pdf&id='.$document_id
  364. );
  365. }
  366. echo $toolbar = Display::toolbarAction('actions-documents', [$actionsLeft]);
  367. echo '<iframe
  368. id="mainFrame"
  369. name="mainFrame"
  370. border="0"
  371. frameborder="0"
  372. scrolling="no"
  373. style="width:100%;" height="600"
  374. src="'.$file_url_web.'&rand='.mt_rand(1, 10000).'"
  375. height="500" allowfullscreen="true" webkitallowfullscreen="true" mozallowfullscreen="true"></iframe>';
  376. }
  377. }
  378. Display::display_footer();