showinframes.php 16 KB

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