showinframes.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450
  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. $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 and !$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. //fix the screen when you try to access a protected course through the url
  73. $is_allowed_in_course = $_SESSION['is_allowed_in_course'];
  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 (!api_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');
  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' => '../group/group.php?'.api_get_cidreq(),
  100. 'name' => get_lang('Groups'),
  101. );
  102. $interbreadcrumb[] = array(
  103. 'url' => '../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. $_SESSION['whereami'] = 'document/view';
  139. $nameTools = get_lang('Documents');
  140. /**
  141. * Main code section
  142. */
  143. header('Expires: Wed, 01 Jan 1990 00:00:00 GMT');
  144. //header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
  145. header('Last-Modified: Wed, 01 Jan 2100 00:00:00 GMT');
  146. header('Cache-Control: no-cache, must-revalidate');
  147. header('Pragma: no-cache');
  148. $browser_display_title = 'Documents - '.Security::remove_XSS($_GET['cidReq']).' - '.$file;
  149. // Only admins get to see the "no frames" link in pageheader.php, so students get a header that's not so high
  150. $frameheight = 135;
  151. if ($is_courseAdmin) {
  152. $frameheight = 165;
  153. }
  154. $js_glossary_in_documents = '';
  155. $js_glossary_in_documents = '
  156. $.frameReady(function(){
  157. // $("<div>I am a div courses</div>").prependTo("body");
  158. }, "top.mainFrame",
  159. {
  160. load: [
  161. { type:"script", id:"_fr1", src:"'.api_get_jquery_web_path().'"},
  162. { type:"script", id:"_fr7", src:"'.api_get_path(WEB_PATH).'web/assets/MathJax/MathJax.js?config=AM_HTMLorMML"},
  163. { type:"script", id:"_fr4", src:"'.api_get_path(WEB_PATH).'web/assets/jquery-ui/jquery-ui.min.js"},
  164. { type:"stylesheet", id:"_fr5", src:"'.api_get_path(WEB_PATH).'web/assets/jquery-ui/themes/smoothness/jquery-ui.min.css"},
  165. { type:"stylesheet", id:"_fr6", src:"'.api_get_path(WEB_PATH).'web/assets/jquery-ui/themes/smoothness/theme.css"},
  166. { type:"script", id:"_fr2", src:"'.api_get_path(WEB_LIBRARY_PATH).'javascript/jquery.highlight.js"},
  167. { type:"script", id:"_fr3", src:"'.api_get_path(WEB_CODE_PATH).'glossary/glossary.js.php"}
  168. ]
  169. });';
  170. $web_odf_supported_files = DocumentManager::get_web_odf_extension_list();
  171. // PDF should be displayed with viewerJS
  172. $web_odf_supported_files[] = 'pdf';
  173. if (in_array(strtolower($pathinfo['extension']), $web_odf_supported_files)) {
  174. $show_web_odf = true;
  175. /*
  176. $htmlHeadXtra[] = api_get_js('webodf/webodf.js');
  177. $htmlHeadXtra[] = api_get_css(api_get_path(WEB_LIBRARY_PATH).'javascript/webodf/webodf.css');
  178. $htmlHeadXtra[] = '
  179. <script charset="utf-8">
  180. function init() {
  181. var odfelement = document.getElementById("odf"),
  182. odfcanvas = new odf.OdfCanvas(odfelement);
  183. odfcanvas.load("'.$file_url_web.'");
  184. }
  185. $(document).ready(function() {
  186. window.setTimeout(init, 0);
  187. });
  188. </script>';
  189. */
  190. $htmlHeadXtra[] = '
  191. <script>
  192. resizeIframe = function() {
  193. var bodyHeight = $("body").height();
  194. var topbarHeight = $("#topbar").height();
  195. $("#viewerJSContent").height((bodyHeight - topbarHeight));
  196. }
  197. $(document).ready(function() {
  198. $(window).resize(resizeIframe());
  199. });
  200. </script>'
  201. ;
  202. }
  203. // Activate code highlight.
  204. $isChatFolder = false;
  205. if (isset($document_data['parents']) && isset($document_data['parents'][0])) {
  206. $chatFolder = $document_data['parents'][0];
  207. if (isset($chatFolder['path']) && $chatFolder['path'] == '/chat_files') {
  208. $isChatFolder = true;
  209. }
  210. }
  211. if ($isChatFolder) {
  212. $htmlHeadXtra[] = api_get_js('highlight/highlight.pack.js');
  213. $htmlHeadXtra[] = api_get_css(api_get_path(WEB_CSS_PATH).'chat.css');
  214. $htmlHeadXtra[] = api_get_css(
  215. api_get_path(WEB_LIBRARY_PATH) . 'javascript/highlight/styles/github.css'
  216. );
  217. $htmlHeadXtra[] = '
  218. <script>
  219. hljs.initHighlightingOnLoad();
  220. </script>';
  221. }
  222. $execute_iframe = true;
  223. if ($jplayer_supported) {
  224. $extension = api_strtolower($pathinfo['extension']);
  225. $js_path = api_get_path(WEB_LIBRARY_PATH).'javascript/';
  226. $htmlHeadXtra[] = '<link rel="stylesheet" href="'.$js_path.'jquery-jplayer/skins/blue/jplayer.blue.monday.css" type="text/css">';
  227. $htmlHeadXtra[] = '<script type="text/javascript" src="'.$js_path.'jquery-jplayer/jquery.jplayer.min.js"></script>';
  228. $jquery = ' $("#jquery_jplayer_1").jPlayer({
  229. ready: function() {
  230. $(this).jPlayer("setMedia", {
  231. '.$extension.' : "'.$document_data['direct_url'].'"
  232. });
  233. },
  234. errorAlerts: false,
  235. warningAlerts: false,
  236. //swfPath: "../inc/lib/javascript/jquery-jplayer",
  237. swfPath: "'.$js_path.'jquery-jplayer",
  238. //supplied: "m4a, oga, mp3, ogg, wav",
  239. supplied: "'.$extension.'",
  240. //wmode: "window",
  241. solution: "flash, html", // Do not change this setting
  242. cssSelectorAncestor: "#jp_container_1",
  243. });';
  244. $htmlHeadXtra[] = '<script>
  245. $(document).ready( function() {
  246. //Experimental changes to preview mp3, ogg files
  247. '.$jquery.'
  248. });
  249. </script>';
  250. $execute_iframe = false;
  251. }
  252. if ($show_web_odf) {
  253. $execute_iframe = false;
  254. }
  255. $is_freemind_available = $pathinfo['extension']=='mm' && api_get_setting('enable_freemind') == 'true';
  256. if ($is_freemind_available) {
  257. $execute_iframe = false;
  258. }
  259. $is_nanogong_available = $pathinfo['extension']=='wav' && preg_match('/_chnano_.wav/i', $file_url_web) && api_get_setting('enable_nanogong') == 'true';
  260. if ($is_nanogong_available) {
  261. $execute_iframe = false;
  262. }
  263. if (!$jplayer_supported && $execute_iframe) {
  264. $htmlHeadXtra[] = '<script type="text/javascript">
  265. <!--
  266. var jQueryFrameReadyConfigPath = \''.api_get_jquery_web_path().'\';
  267. -->
  268. </script>';
  269. $htmlHeadXtra[] = '<script type="text/javascript" src="'.api_get_path(WEB_LIBRARY_PATH).'javascript/jquery.frameready.js"></script>';
  270. $htmlHeadXtra[] = '<script>
  271. var updateContentHeight = function() {
  272. my_iframe = document.getElementById("mainFrame");
  273. if (my_iframe) {
  274. //this doesnt seem to work in IE 7,8,9
  275. new_height = my_iframe.contentWindow.document.body.scrollHeight;
  276. my_iframe.height = my_iframe.contentWindow.document.body.scrollHeight + "px";
  277. }
  278. };
  279. // Fixes the content height of the frame
  280. window.onload = function() {
  281. updateContentHeight();
  282. '.$js_glossary_in_documents.'
  283. }
  284. </script>';
  285. }
  286. Display::display_header('');
  287. echo '<div align="center">';
  288. $file_url = api_get_path(WEB_COURSE_PATH).$courseInfo['path'].'/document'.$header_file;
  289. $file_url_web = $file_url.'?'.api_get_cidreq();
  290. if (!$is_nanogong_available) {
  291. if (in_array(strtolower($pathinfo['extension']) , array('html', "htm"))) {
  292. echo '<a class="btn btn-default" href="'.$file_url_web.'" target="_blank">'.get_lang('CutPasteLink').'</a>';
  293. }
  294. }
  295. if ($show_web_odf) {
  296. $browser = api_get_navigator();
  297. $pdfUrl = api_get_path(WEB_LIBRARY_PATH) . 'javascript/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. } else {
  307. // ViewerJS already have download button
  308. echo '<a class="btn btn-default" href="'.$file_url_web.'" target="_blank"><i class="fa fa-download"></i>
  309. '.get_lang('Download').'</a>';
  310. }
  311. echo '</div>';
  312. if ($jplayer_supported) {
  313. echo '<br /><div class="span12" style="margin:0 auto; width:100%; text-align:center;">';
  314. echo DocumentManager::generate_video_preview($document_data);
  315. echo '</div>';
  316. }
  317. if ($is_freemind_available) {
  318. ?>
  319. <script type="text/javascript" src="<?php echo api_get_path(WEB_LIBRARY_PATH) ?>swfobject/swfobject.js"></script>
  320. <style type="text/css">
  321. #flashcontent {
  322. height: 500px;
  323. padding-top:10px;
  324. }
  325. </style>
  326. <div id="flashcontent" onmouseover="giveFocus();">
  327. Flash plugin or Javascript are turned off.
  328. Activate both and reload to view the mindmap
  329. </div>
  330. <script>
  331. function giveFocus() {
  332. document.visorFreeMind.focus();
  333. }
  334. document.onload=giveFocus;
  335. // <![CDATA[
  336. // for allowing using http://.....?mindmap.mm mode
  337. function getMap(map){
  338. var result=map;
  339. var loc=document.location+'';
  340. if(loc.indexOf(".mm")>0 && loc.indexOf("?")>0){
  341. result=loc.substring(loc.indexOf("?")+1);
  342. }
  343. return result;
  344. }
  345. var fo = new FlashObject("<?php echo api_get_path(WEB_LIBRARY_PATH); ?>freeMindFlashBrowser/visorFreemind.swf", "visorFreeMind", "100%", "100%", 6, "#ffffff");
  346. fo.addParam("quality", "high");
  347. //fo.addParam("bgcolor", "#a0a0f0");
  348. fo.addVariable("openUrl", "_blank");//Default value "_self"
  349. 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.
  350. fo.addVariable("maxNodeWidth","200");
  351. //
  352. fo.addVariable("mainNodeShape","elipse");//"rectangle", "elipse", "none". None hide the main node. Default is "elipse"
  353. fo.addVariable("justMap","false");
  354. fo.addVariable("initLoadFile",getMap("<?php echo $file_url_web; ?>"));
  355. fo.addVariable("defaultToolTipWordWrap",200);//max width for tooltips. Default "600" pixels
  356. fo.addVariable("offsetX","left");//for the center of the mindmap. Admit also "left" and "right"
  357. fo.addVariable("offsetY","top");//for the center of the mindmap. Admit also "top" and "bottom"
  358. fo.addVariable("buttonsPos","top");//"top" or "bottom"
  359. fo.addVariable("min_alpha_buttons",20);//for dynamic view of buttons
  360. fo.addVariable("max_alpha_buttons",100);//for dynamic view of buttons
  361. fo.addVariable("scaleTooltips","false");
  362. //
  363. //extra
  364. //fo.addVariable("CSSFile","<?php // echo api_get_path(WEB_LIBRARY_PATH); ?>freeMindFlashBrowser/flashfreemind.css");//
  365. //fo.addVariable("baseImagePath","<?php // echo api_get_path(WEB_LIBRARY_PATH); ?>freeMindFlashBrowser/");//
  366. //fo.addVariable("justMap","false");//Hides all the upper control options. Default value "false"
  367. //fo.addVariable("noElipseMode","anyvalue");//for changing to old elipseNode edges. Default = not set
  368. //fo.addVariable("ShotsWidth","200");//The width of snapshots, in pixels.
  369. //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
  370. //fo.addVariable("unfoldAll","true"); //For each mindmap loaded start the display with all nodes unfolded. Another variable to be wary of!
  371. //fo.addVariable("toolTipsBgColor","0xaaeeaa");: bgcolor for tooltips ej;"0xaaeeaa"
  372. //fo.addVariable("defaultWordWrap","300"); //default 600
  373. //
  374. fo.write("flashcontent");
  375. // ]]>
  376. </script>
  377. <?php
  378. }
  379. if ($is_nanogong_available) {
  380. $file_url_web = DocumentManager::generateAudioTempFolder($file_url_sys);
  381. echo '<div align="center">';
  382. echo '<a class="btn btn-default" href="'.$file_url_web.'" target="_blank"><i class="fa fa-download"></i> '.get_lang('Download').'</a>';
  383. echo '<br/>';
  384. echo '<br/>';
  385. echo DocumentManager::readNanogongFile($to_url);
  386. // Erase temp file in tmp directory when return to documents
  387. echo '</div>';
  388. }
  389. if ($execute_iframe) {
  390. if ($isChatFolder) {
  391. $content = Security::remove_XSS(file_get_contents($file_url_sys));
  392. echo $content;
  393. } else {
  394. 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>';
  395. }
  396. }
  397. Display::display_footer();