showinframes.php 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463
  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. *
  13. * --- design ---
  14. * a file gets a parameter (an html file)
  15. * and shows
  16. * - chamilo header
  17. * - html file from parameter
  18. * - (removed) chamilo footer
  19. *
  20. * @version 0.6
  21. * @author Roan Embrechts (roan.embrechts@vub.ac.be)
  22. * @package chamilo.document
  23. */
  24. require_once '../inc/global.inc.php';
  25. api_protect_course_script();
  26. $noPHP_SELF = true;
  27. $header_file = isset($_GET['file']) ? Security::remove_XSS($_GET['file']) : null;
  28. $document_id = intval($_GET['id']);
  29. $originIsLearnpath = isset($_GET['origin']) && $_GET['origin'] === 'learnpathitem';
  30. $courseInfo = api_get_course_info();
  31. $course_code = api_get_course_id();
  32. $session_id = api_get_session_id();
  33. if (empty($courseInfo)) {
  34. api_not_allowed(true);
  35. }
  36. $show_web_odf = false;
  37. // Generate path
  38. if (!$document_id) {
  39. $document_id = DocumentManager::get_document_id($courseInfo, $header_file);
  40. }
  41. $document_data = DocumentManager::get_document_data_by_id(
  42. $document_id,
  43. $course_code,
  44. true,
  45. $session_id
  46. );
  47. if ($session_id != 0 and !$document_data) {
  48. $document_data = DocumentManager::get_document_data_by_id(
  49. $document_id,
  50. $course_code,
  51. true,
  52. 0
  53. );
  54. }
  55. if (empty($document_data)) {
  56. api_not_allowed(true);
  57. }
  58. $header_file = $document_data['path'];
  59. $name_to_show = $document_data['title'];
  60. $path_array = explode('/', str_replace('\\', '/', $header_file));
  61. $path_array = array_map('urldecode', $path_array);
  62. $header_file = implode('/', $path_array);
  63. $file = Security::remove_XSS(urldecode($document_data['path']));
  64. $file_root = $courseInfo['path'].'/document'.str_replace('%2F', '/', $file);
  65. $file_url_sys = api_get_path(SYS_COURSE_PATH).$file_root;
  66. $file_url_web = api_get_path(WEB_COURSE_PATH).$file_root;
  67. if (!file_exists($file_url_sys)) {
  68. api_not_allowed(true);
  69. }
  70. if (is_dir($file_url_sys)) {
  71. api_not_allowed(true);
  72. }
  73. $is_allowed_to_edit = api_is_allowed_to_edit();
  74. //fix the screen when you try to access a protected course through the url
  75. $is_allowed_in_course = api_is_allowed_in_course() || $is_allowed_to_edit;
  76. if ($is_allowed_in_course == false) {
  77. api_not_allowed(true);
  78. }
  79. // Check user visibility.
  80. $is_visible = DocumentManager::check_visibility_tree(
  81. $document_id,
  82. api_get_course_id(),
  83. api_get_session_id(),
  84. api_get_user_id(),
  85. api_get_group_id()
  86. );
  87. if (!$is_allowed_to_edit && !$is_visible) {
  88. api_not_allowed(true);
  89. }
  90. $pathinfo = pathinfo($header_file);
  91. $jplayer_supported_files = array('mp4', 'ogv', 'flv', 'm4v');
  92. $jplayer_supported = false;
  93. if (in_array(strtolower($pathinfo['extension']), $jplayer_supported_files)) {
  94. $jplayer_supported = 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[] = array(
  101. 'url' => api_get_path(WEB_CODE_PATH).'group/group.php?'.api_get_cidreq(),
  102. 'name' => get_lang('Groups'),
  103. );
  104. $interbreadcrumb[] = array(
  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[] = array(
  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[] = array(
  119. 'url' => $document_data['document_url'],
  120. 'name' => $document_data['title'],
  121. );
  122. } else {
  123. $interbreadcrumb[] = array(
  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[] = array(
  134. 'url' => $document_sub_data['document_url'],
  135. 'name' => $document_sub_data['title'],
  136. );
  137. }
  138. }
  139. $this_section = SECTION_COURSES;
  140. $_SESSION['whereami'] = 'document/view';
  141. $nameTools = get_lang('Documents');
  142. /**
  143. * Main code section
  144. */
  145. header('Expires: Wed, 01 Jan 1990 00:00:00 GMT');
  146. //header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
  147. header('Last-Modified: Wed, 01 Jan 2100 00:00:00 GMT');
  148. header('Cache-Control: no-cache, must-revalidate');
  149. header('Pragma: no-cache');
  150. $browser_display_title = 'Documents - '.Security::remove_XSS($_GET['cidReq']).' - '.$file;
  151. // Only admins get to see the "no frames" link in pageheader.php, so students get a header that's not so high
  152. $frameheight = 135;
  153. if ($is_courseAdmin) {
  154. $frameheight = 165;
  155. }
  156. $js_glossary_in_documents = '';
  157. $js_glossary_in_documents = '
  158. $.frameReady(function(){
  159. // $("<div>I am a div courses</div>").prependTo("body");
  160. }, "top.mainFrame",
  161. {
  162. load: [
  163. { type:"script", id:"_fr1", src:"'.api_get_jquery_web_path().'"},
  164. { type:"script", id:"_fr7", src:"'.api_get_path(WEB_PATH).'web/assets/MathJax/MathJax.js?config=AM_HTMLorMML"},
  165. { type:"script", id:"_fr4", src:"'.api_get_path(WEB_PATH).'web/assets/jquery-ui/jquery-ui.min.js"},
  166. { type:"stylesheet", id:"_fr5", src:"'.api_get_path(WEB_PATH).'web/assets/jquery-ui/themes/smoothness/jquery-ui.min.css"},
  167. { type:"stylesheet", id:"_fr6", src:"'.api_get_path(WEB_PATH).'web/assets/jquery-ui/themes/smoothness/theme.css"},
  168. { type:"script", id:"_fr2", src:"'.api_get_path(WEB_LIBRARY_PATH).'javascript/jquery.highlight.js"},
  169. { type:"script", id:"_fr3", src:"'.api_get_path(WEB_CODE_PATH).'glossary/glossary.js.php"}
  170. ]
  171. });';
  172. $web_odf_supported_files = DocumentManager::get_web_odf_extension_list();
  173. // PDF should be displayed with viewerJS
  174. $web_odf_supported_files[] = 'pdf';
  175. if (in_array(strtolower($pathinfo['extension']), $web_odf_supported_files)) {
  176. $show_web_odf = true;
  177. /*
  178. $htmlHeadXtra[] = api_get_js('webodf/webodf.js');
  179. $htmlHeadXtra[] = api_get_css(api_get_path(WEB_LIBRARY_PATH).'javascript/webodf/webodf.css');
  180. $htmlHeadXtra[] = '
  181. <script charset="utf-8">
  182. function init() {
  183. var odfelement = document.getElementById("odf"),
  184. odfcanvas = new odf.OdfCanvas(odfelement);
  185. odfcanvas.load("'.$file_url_web.'");
  186. }
  187. $(document).ready(function() {
  188. window.setTimeout(init, 0);
  189. });
  190. </script>';
  191. */
  192. $htmlHeadXtra[] = '
  193. <script>
  194. resizeIframe = function() {
  195. var bodyHeight = $("body").height();
  196. var topbarHeight = $("#topbar").height();
  197. $("#viewerJSContent").height((bodyHeight - topbarHeight));
  198. }
  199. $(document).ready(function() {
  200. $(window).resize(resizeIframe());
  201. });
  202. </script>'
  203. ;
  204. }
  205. // Activate code highlight.
  206. $isChatFolder = false;
  207. if (isset($document_data['parents']) && isset($document_data['parents'][0])) {
  208. $chatFolder = $document_data['parents'][0];
  209. if (isset($chatFolder['path']) && $chatFolder['path'] == '/chat_files') {
  210. $isChatFolder = true;
  211. }
  212. }
  213. if ($isChatFolder) {
  214. $htmlHeadXtra[] = api_get_js('highlight/highlight.pack.js');
  215. $htmlHeadXtra[] = api_get_css(api_get_path(WEB_CSS_PATH).'chat.css');
  216. $htmlHeadXtra[] = api_get_css(
  217. api_get_path(WEB_LIBRARY_PATH) . 'javascript/highlight/styles/github.css'
  218. );
  219. $htmlHeadXtra[] = '
  220. <script>
  221. hljs.initHighlightingOnLoad();
  222. </script>';
  223. }
  224. $execute_iframe = true;
  225. if ($jplayer_supported) {
  226. $extension = api_strtolower($pathinfo['extension']);
  227. if ($extension == 'mp4') {
  228. $extension = 'm4v';
  229. }
  230. $js_path = api_get_path(WEB_LIBRARY_PATH).'javascript/';
  231. $htmlHeadXtra[] = '<link rel="stylesheet" href="'.$js_path.'jquery-jplayer/skin/blue.monday/css/jplayer.blue.monday.css" type="text/css">';
  232. $htmlHeadXtra[] = '<script type="text/javascript" src="'.$js_path.'jquery-jplayer/jplayer/jquery.jplayer.min.js"></script>';
  233. $jquery = '
  234. $("#jquery_jplayer_1").jPlayer({
  235. ready: function() {
  236. $(this).jPlayer("setMedia", {
  237. '.$extension.' : "'.$document_data['direct_url'].'"
  238. });
  239. },
  240. cssSelectorAncestor: "#jp_container_1",
  241. swfPath: "'.$js_path.'jquery-jplayer/jplayer/",
  242. supplied: "'.$extension.'",
  243. useStateClassSkin: true,
  244. autoBlur: false,
  245. keyEnabled: false,
  246. remainingDuration: true,
  247. toggleDuration: true,
  248. solution: "html, flash",
  249. errorAlerts: false,
  250. warningAlerts: false
  251. });
  252. ';
  253. $htmlHeadXtra[] = '<script>
  254. $(document).ready( function() {
  255. //Experimental changes to preview mp3, ogg files
  256. '.$jquery.'
  257. });
  258. </script>';
  259. $execute_iframe = false;
  260. }
  261. if ($show_web_odf) {
  262. $execute_iframe = false;
  263. }
  264. $is_freemind_available = $pathinfo['extension']=='mm' && api_get_setting('enable_freemind') == 'true';
  265. if ($is_freemind_available) {
  266. $execute_iframe = false;
  267. }
  268. $is_nanogong_available = $pathinfo['extension']=='wav' && preg_match('/_chnano_.wav/i', $file_url_web) && api_get_setting('enable_nanogong') == 'true';
  269. if ($is_nanogong_available) {
  270. $execute_iframe = false;
  271. }
  272. if (!$jplayer_supported && $execute_iframe) {
  273. $htmlHeadXtra[] = '<script type="text/javascript">
  274. <!--
  275. var jQueryFrameReadyConfigPath = \''.api_get_jquery_web_path().'\';
  276. -->
  277. </script>';
  278. $htmlHeadXtra[] = '<script type="text/javascript" src="'.api_get_path(WEB_LIBRARY_PATH).'javascript/jquery.frameready.js"></script>';
  279. $htmlHeadXtra[] = '<script>
  280. var updateContentHeight = function() {
  281. my_iframe = document.getElementById("mainFrame");
  282. if (my_iframe) {
  283. //this doesnt seem to work in IE 7,8,9
  284. new_height = my_iframe.contentWindow.document.body.scrollHeight;
  285. my_iframe.height = my_iframe.contentWindow.document.body.scrollHeight + "px";
  286. }
  287. };
  288. // Fixes the content height of the frame
  289. window.onload = function() {
  290. updateContentHeight();
  291. '.$js_glossary_in_documents.'
  292. }
  293. </script>';
  294. }
  295. if ($originIsLearnpath) {
  296. Display::display_reduced_header();
  297. } else {
  298. Display::display_header('');
  299. }
  300. echo '<div class="text-center">';
  301. $file_url = api_get_path(WEB_COURSE_PATH).$courseInfo['path'].'/document'.$header_file;
  302. $file_url_web = $file_url.'?'.api_get_cidreq();
  303. if (!$is_nanogong_available) {
  304. if (in_array(strtolower($pathinfo['extension']) , array('html', "htm"))) {
  305. echo '<a class="btn btn-default" href="'.$file_url_web.'" target="_blank">'.get_lang('CutPasteLink').'</a>';
  306. }
  307. }
  308. if ($show_web_odf) {
  309. $browser = api_get_navigator();
  310. $pdfUrl = api_get_path(WEB_LIBRARY_PATH) . 'javascript/ViewerJS/index.html#' . $file_url;
  311. if ($browser['name'] == 'Mozilla' && preg_match('|.*\.pdf|i', $header_file)) {
  312. $pdfUrl = $file_url;
  313. }
  314. echo '<div id="viewerJS">';
  315. echo '<iframe id="viewerJSContent" frameborder="0" allowfullscreen="allowfullscreen" webkitallowfullscreen style="width:100%;"
  316. src="' . $pdfUrl. '">
  317. </iframe>';
  318. echo '</div>';
  319. } elseif (!$originIsLearnpath) {
  320. // ViewerJS already have download button
  321. echo '<p>';
  322. echo Display::toolbarButton(get_lang('Download'), $file_url_web, 'download', 'default', ['target' => '_blank']);
  323. echo '</p>';
  324. }
  325. echo '</div>';
  326. if ($jplayer_supported) {
  327. echo DocumentManager::generate_video_preview($document_data);
  328. // media_element blocks jplayer disable it
  329. Display::$global_template->assign('show_media_element', 0);
  330. }
  331. if ($is_freemind_available) {
  332. ?>
  333. <script type="text/javascript" src="<?php echo api_get_path(WEB_LIBRARY_PATH) ?>swfobject/swfobject.js"></script>
  334. <style type="text/css">
  335. #flashcontent {
  336. height: 500px;
  337. padding-top:10px;
  338. }
  339. </style>
  340. <div id="flashcontent" onmouseover="giveFocus();">
  341. Flash plugin or Javascript are turned off.
  342. Activate both and reload to view the mindmap
  343. </div>
  344. <script>
  345. function giveFocus() {
  346. document.visorFreeMind.focus();
  347. }
  348. document.onload=giveFocus;
  349. // <![CDATA[
  350. // for allowing using http://.....?mindmap.mm mode
  351. function getMap(map){
  352. var result=map;
  353. var loc=document.location+'';
  354. if(loc.indexOf(".mm")>0 && loc.indexOf("?")>0){
  355. result=loc.substring(loc.indexOf("?")+1);
  356. }
  357. return result;
  358. }
  359. var fo = new FlashObject("<?php echo api_get_path(WEB_LIBRARY_PATH); ?>freeMindFlashBrowser/visorFreemind.swf", "visorFreeMind", "100%", "100%", 6, "#ffffff");
  360. fo.addParam("quality", "high");
  361. //fo.addParam("bgcolor", "#a0a0f0");
  362. fo.addVariable("openUrl", "_blank");//Default value "_self"
  363. 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.
  364. fo.addVariable("maxNodeWidth","200");
  365. //
  366. fo.addVariable("mainNodeShape","elipse");//"rectangle", "elipse", "none". None hide the main node. Default is "elipse"
  367. fo.addVariable("justMap","false");
  368. fo.addVariable("initLoadFile",getMap("<?php echo $file_url_web; ?>"));
  369. fo.addVariable("defaultToolTipWordWrap",200);//max width for tooltips. Default "600" pixels
  370. fo.addVariable("offsetX","left");//for the center of the mindmap. Admit also "left" and "right"
  371. fo.addVariable("offsetY","top");//for the center of the mindmap. Admit also "top" and "bottom"
  372. fo.addVariable("buttonsPos","top");//"top" or "bottom"
  373. fo.addVariable("min_alpha_buttons",20);//for dynamic view of buttons
  374. fo.addVariable("max_alpha_buttons",100);//for dynamic view of buttons
  375. fo.addVariable("scaleTooltips","false");
  376. //
  377. //extra
  378. //fo.addVariable("CSSFile","<?php // echo api_get_path(WEB_LIBRARY_PATH); ?>freeMindFlashBrowser/flashfreemind.css");//
  379. //fo.addVariable("baseImagePath","<?php // echo api_get_path(WEB_LIBRARY_PATH); ?>freeMindFlashBrowser/");//
  380. //fo.addVariable("justMap","false");//Hides all the upper control options. Default value "false"
  381. //fo.addVariable("noElipseMode","anyvalue");//for changing to old elipseNode edges. Default = not set
  382. //fo.addVariable("ShotsWidth","200");//The width of snapshots, in pixels.
  383. //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
  384. //fo.addVariable("unfoldAll","true"); //For each mindmap loaded start the display with all nodes unfolded. Another variable to be wary of!
  385. //fo.addVariable("toolTipsBgColor","0xaaeeaa");: bgcolor for tooltips ej;"0xaaeeaa"
  386. //fo.addVariable("defaultWordWrap","300"); //default 600
  387. //
  388. fo.write("flashcontent");
  389. // ]]>
  390. </script>
  391. <?php
  392. }
  393. if ($is_nanogong_available) {
  394. $file_url_web = DocumentManager::generateAudioTempFolder($file_url_sys);
  395. echo '<div align="center">';
  396. echo '<a class="btn btn-default" href="'.$file_url_web.'" target="_blank"><em class="fa fa-download"></em> '.get_lang('Download').'</a>';
  397. echo '<br/>';
  398. echo '<br/>';
  399. echo DocumentManager::readNanogongFile($to_url);
  400. // Erase temp file in tmp directory when return to documents
  401. echo '</div>';
  402. }
  403. if ($execute_iframe) {
  404. if ($isChatFolder) {
  405. $content = Security::remove_XSS(file_get_contents($file_url_sys));
  406. echo $content;
  407. } else {
  408. echo '<iframe id="mainFrame" name="mainFrame" border="0" frameborder="0" scrolling="no" style="width:100%;" height="600" src="'.$file_url_web.'&rand='.mt_rand(1, 10000).'" height="500" allowfullscreen="true" webkitallowfullscreen="true" mozallowfullscreen="true"></iframe>';
  409. }
  410. }
  411. Display::display_footer();