showinframes.php 16 KB

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