showinframes.php 15 KB

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