showinframes.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429
  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. $_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. $.frameReady(function(){
  156. // $("<div>I am a div courses</div>").prependTo("body");
  157. }, "top.mainFrame",
  158. {
  159. load: [
  160. { type:"script", id:"_fr1", src:"'.api_get_jquery_web_path().'"},
  161. { type:"script", id:"_fr7", src:"'.api_get_path(WEB_PATH).'web/assets/MathJax/MathJax.js?config=AM_HTMLorMML"},
  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. if ($extension == 'mp4') {
  225. $extension = 'm4v';
  226. }
  227. $js_path = api_get_path(WEB_LIBRARY_PATH).'javascript/';
  228. $htmlHeadXtra[] = '<link rel="stylesheet" href="'.$js_path.'jquery-jplayer/skin/blue.monday/css/jplayer.blue.monday.css" type="text/css">';
  229. $htmlHeadXtra[] = '<script type="text/javascript" src="'.$js_path.'jquery-jplayer/jplayer/jquery.jplayer.min.js"></script>';
  230. $jquery = '
  231. $("#jquery_jplayer_1").jPlayer({
  232. ready: function() {
  233. $(this).jPlayer("setMedia", {
  234. '.$extension.' : "'.$document_data['direct_url'].'"
  235. });
  236. },
  237. cssSelectorAncestor: "#jp_container_1",
  238. swfPath: "'.$js_path.'jquery-jplayer/jplayer/",
  239. supplied: "'.$extension.'",
  240. useStateClassSkin: true,
  241. autoBlur: false,
  242. keyEnabled: false,
  243. remainingDuration: true,
  244. toggleDuration: true,
  245. solution: "html, flash",
  246. errorAlerts: false,
  247. warningAlerts: false
  248. });
  249. ';
  250. $htmlHeadXtra[] = '<script>
  251. $(document).ready( function() {
  252. //Experimental changes to preview mp3, ogg files
  253. '.$jquery.'
  254. });
  255. </script>';
  256. $execute_iframe = false;
  257. }
  258. if ($show_web_odf) {
  259. $execute_iframe = false;
  260. }
  261. $is_freemind_available = $pathinfo['extension'] == 'mm' && api_get_setting('enable_freemind') == 'true';
  262. if ($is_freemind_available) {
  263. $execute_iframe = false;
  264. }
  265. if (!$jplayer_supported && $execute_iframe) {
  266. $htmlHeadXtra[] = '<script>
  267. <!--
  268. var jQueryFrameReadyConfigPath = \''.api_get_jquery_web_path().'\';
  269. -->
  270. </script>';
  271. $htmlHeadXtra[] = '<script type="text/javascript" src="'.api_get_path(WEB_LIBRARY_PATH).'javascript/jquery.frameready.js"></script>';
  272. $htmlHeadXtra[] = '<script>
  273. var updateContentHeight = function() {
  274. my_iframe = document.getElementById("mainFrame");
  275. if (my_iframe) {
  276. //this doesnt seem to work in IE 7,8,9
  277. new_height = my_iframe.contentWindow.document.body.scrollHeight;
  278. my_iframe.height = my_iframe.contentWindow.document.body.scrollHeight + "px";
  279. }
  280. };
  281. // Fixes the content height of the frame
  282. window.onload = function() {
  283. updateContentHeight();
  284. '.$js_glossary_in_documents.'
  285. }
  286. </script>';
  287. }
  288. if ($originIsLearnpath) {
  289. Display::display_reduced_header();
  290. } else {
  291. Display::display_header('');
  292. }
  293. echo '<div class="text-center">';
  294. $file_url = api_get_path(WEB_COURSE_PATH).$courseInfo['path'].'/document'.$header_file;
  295. $file_url_web = $file_url.'?'.api_get_cidreq();
  296. if ($show_web_odf) {
  297. $browser = api_get_navigator();
  298. $pdfUrl = api_get_path(WEB_LIBRARY_PATH).'javascript/ViewerJS/index.html#'.$file_url;
  299. if ($browser['name'] == 'Mozilla' && preg_match('|.*\.pdf|i', $header_file)) {
  300. $pdfUrl = $file_url;
  301. }
  302. echo '<div id="viewerJS">';
  303. echo '<iframe id="viewerJSContent" frameborder="0" allowfullscreen="allowfullscreen" webkitallowfullscreen style="width:100%;"
  304. src="' . $pdfUrl.'">
  305. </iframe>';
  306. echo '</div>';
  307. }
  308. echo '</div>';
  309. if ($jplayer_supported) {
  310. echo DocumentManager::generate_video_preview($document_data);
  311. // media_element blocks jplayer disable it
  312. Display::$global_template->assign('show_media_element', 0);
  313. }
  314. if ($is_freemind_available) {
  315. ?>
  316. <script type="text/javascript" src="<?php echo api_get_path(WEB_LIBRARY_PATH) ?>swfobject/swfobject.js"></script>
  317. <style type="text/css">
  318. #flashcontent {
  319. height: 500px;
  320. padding-top:10px;
  321. }
  322. </style>
  323. <div id="flashcontent" onmouseover="giveFocus();">
  324. Flash plugin or Javascript are turned off.
  325. Activate both and reload to view the mindmap
  326. </div>
  327. <script>
  328. function giveFocus() {
  329. document.visorFreeMind.focus();
  330. }
  331. document.onload=giveFocus;
  332. // <![CDATA[
  333. // for allowing using http://.....?mindmap.mm mode
  334. function getMap(map){
  335. var result=map;
  336. var loc=document.location+'';
  337. if(loc.indexOf(".mm")>0 && loc.indexOf("?")>0){
  338. result=loc.substring(loc.indexOf("?")+1);
  339. }
  340. return result;
  341. }
  342. var fo = new FlashObject("<?php echo api_get_path(WEB_LIBRARY_PATH); ?>freeMindFlashBrowser/visorFreemind.swf", "visorFreeMind", "100%", "100%", 6, "#ffffff");
  343. fo.addParam("quality", "high");
  344. //fo.addParam("bgcolor", "#a0a0f0");
  345. fo.addVariable("openUrl", "_blank");//Default value "_self"
  346. 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.
  347. fo.addVariable("maxNodeWidth","200");
  348. //
  349. fo.addVariable("mainNodeShape","elipse");//"rectangle", "elipse", "none". None hide the main node. Default is "elipse"
  350. fo.addVariable("justMap","false");
  351. fo.addVariable("initLoadFile",getMap("<?php echo $file_url_web; ?>"));
  352. fo.addVariable("defaultToolTipWordWrap",200);//max width for tooltips. Default "600" pixels
  353. fo.addVariable("offsetX","left");//for the center of the mindmap. Admit also "left" and "right"
  354. fo.addVariable("offsetY","top");//for the center of the mindmap. Admit also "top" and "bottom"
  355. fo.addVariable("buttonsPos","top");//"top" or "bottom"
  356. fo.addVariable("min_alpha_buttons",20);//for dynamic view of buttons
  357. fo.addVariable("max_alpha_buttons",100);//for dynamic view of buttons
  358. fo.addVariable("scaleTooltips","false");
  359. //
  360. //extra
  361. //fo.addVariable("CSSFile","<?php // echo api_get_path(WEB_LIBRARY_PATH); ?>freeMindFlashBrowser/flashfreemind.css");//
  362. //fo.addVariable("baseImagePath","<?php // echo api_get_path(WEB_LIBRARY_PATH); ?>freeMindFlashBrowser/");//
  363. //fo.addVariable("justMap","false");//Hides all the upper control options. Default value "false"
  364. //fo.addVariable("noElipseMode","anyvalue");//for changing to old elipseNode edges. Default = not set
  365. //fo.addVariable("ShotsWidth","200");//The width of snapshots, in pixels.
  366. //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
  367. //fo.addVariable("unfoldAll","true"); //For each mindmap loaded start the display with all nodes unfolded. Another variable to be wary of!
  368. //fo.addVariable("toolTipsBgColor","0xaaeeaa");: bgcolor for tooltips ej;"0xaaeeaa"
  369. //fo.addVariable("defaultWordWrap","300"); //default 600
  370. //
  371. fo.write("flashcontent");
  372. // ]]>
  373. </script>
  374. <?php
  375. }
  376. if ($execute_iframe) {
  377. if ($isChatFolder) {
  378. $content = Security::remove_XSS(file_get_contents($file_url_sys));
  379. echo $content;
  380. } else {
  381. 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>';
  382. }
  383. }
  384. Display::display_footer();