123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428 |
- <?php
- require_once __DIR__.'/../inc/global.inc.php';
- api_protect_course_script();
- $noPHP_SELF = true;
- $header_file = isset($_GET['file']) ? Security::remove_XSS($_GET['file']) : null;
- $document_id = intval($_GET['id']);
- $originIsLearnpath = isset($_GET['origin']) && $_GET['origin'] === 'learnpathitem';
- $courseInfo = api_get_course_info();
- $course_code = api_get_course_id();
- $session_id = api_get_session_id();
- if (empty($courseInfo)) {
- api_not_allowed(true);
- }
- $show_web_odf = false;
- if (!$document_id) {
- $document_id = DocumentManager::get_document_id($courseInfo, $header_file);
- }
- $document_data = DocumentManager::get_document_data_by_id(
- $document_id,
- $course_code,
- true,
- $session_id
- );
- if ($session_id != 0 && !$document_data) {
- $document_data = DocumentManager::get_document_data_by_id(
- $document_id,
- $course_code,
- true,
- 0
- );
- }
- if (empty($document_data)) {
- api_not_allowed(true);
- }
- $header_file = $document_data['path'];
- $name_to_show = $document_data['title'];
- $path_array = explode('/', str_replace('\\', '/', $header_file));
- $path_array = array_map('urldecode', $path_array);
- $header_file = implode('/', $path_array);
- $file = Security::remove_XSS(urldecode($document_data['path']));
- $file_root = $courseInfo['path'].'/document'.str_replace('%2F', '/', $file);
- $file_url_sys = api_get_path(SYS_COURSE_PATH).$file_root;
- $file_url_web = api_get_path(WEB_COURSE_PATH).$file_root;
- if (!file_exists($file_url_sys)) {
- api_not_allowed(true);
- }
- if (is_dir($file_url_sys)) {
- api_not_allowed(true);
- }
- $is_allowed_to_edit = api_is_allowed_to_edit();
- $is_allowed_in_course = api_is_allowed_in_course() || $is_allowed_to_edit;
- if ($is_allowed_in_course == false) {
- api_not_allowed(true);
- }
- $is_visible = DocumentManager::check_visibility_tree(
- $document_id,
- api_get_course_id(),
- api_get_session_id(),
- api_get_user_id(),
- api_get_group_id()
- );
- if (!$is_allowed_to_edit && !$is_visible) {
- api_not_allowed(true);
- }
- $pathinfo = pathinfo($header_file);
- $jplayer_supported_files = array('mp4', 'ogv', 'flv', 'm4v');
- $jplayer_supported = false;
- if (in_array(strtolower($pathinfo['extension']), $jplayer_supported_files)) {
- $jplayer_supported = true;
- }
- $group_id = api_get_group_id();
- $current_group = GroupManager::get_group_properties($group_id);
- $current_group_name = $current_group['name'];
- if (isset($group_id) && $group_id != '') {
- $interbreadcrumb[] = array(
- 'url' => api_get_path(WEB_CODE_PATH).'group/group.php?'.api_get_cidreq(),
- 'name' => get_lang('Groups'),
- );
- $interbreadcrumb[] = array(
- 'url' => api_get_path(WEB_CODE_PATH).'group/group_space.php?'.api_get_cidreq(),
- 'name' => get_lang('GroupSpace').' '.$current_group_name,
- );
- $name_to_show = explode('/', $name_to_show);
- unset($name_to_show[1]);
- $name_to_show = implode('/', $name_to_show);
- }
- $interbreadcrumb[] = array(
- 'url' => './document.php?curdirpath='.dirname($header_file).'&'.api_get_cidreq(),
- 'name' => get_lang('Documents'),
- );
- if (empty($document_data['parents'])) {
- if (isset($_GET['createdir'])) {
- $interbreadcrumb[] = array(
- 'url' => $document_data['document_url'],
- 'name' => $document_data['title'],
- );
- } else {
- $interbreadcrumb[] = array(
- 'url' => '#',
- 'name' => $document_data['title'],
- );
- }
- } else {
- foreach ($document_data['parents'] as $document_sub_data) {
- if (!isset($_GET['createdir']) && $document_sub_data['id'] == $document_data['id']) {
- $document_sub_data['document_url'] = '#';
- }
- $interbreadcrumb[] = array(
- 'url' => $document_sub_data['document_url'],
- 'name' => $document_sub_data['title'],
- );
- }
- }
- $this_section = SECTION_COURSES;
- $_SESSION['whereami'] = 'document/view';
- $nameTools = get_lang('Documents');
- header('Expires: Wed, 01 Jan 1990 00:00:00 GMT');
- header('Last-Modified: Wed, 01 Jan 2100 00:00:00 GMT');
- header('Cache-Control: no-cache, must-revalidate');
- header('Pragma: no-cache');
- $browser_display_title = 'Documents - '.Security::remove_XSS($_GET['cidReq']).' - '.$file;
- $frameheight = 135;
- if ($is_courseAdmin) {
- $frameheight = 165;
- }
- $js_glossary_in_documents = '
- $.frameReady(function(){
- // $("<div>I am a div courses</div>").prependTo("body");
- }, "top.mainFrame",
- {
- load: [
- { type:"script", id:"_fr1", src:"'.api_get_jquery_web_path().'"},
- { type:"script", id:"_fr7", src:"'.api_get_path(WEB_PATH).'web/assets/MathJax/MathJax.js?config=AM_HTMLorMML"},
- { type:"script", id:"_fr4", src:"'.api_get_path(WEB_PATH).'web/assets/jquery-ui/jquery-ui.min.js"},
- { type:"stylesheet", id:"_fr5", src:"'.api_get_path(WEB_PATH).'web/assets/jquery-ui/themes/smoothness/jquery-ui.min.css"},
- { type:"stylesheet", id:"_fr6", src:"'.api_get_path(WEB_PATH).'web/assets/jquery-ui/themes/smoothness/theme.css"},
- { type:"script", id:"_fr2", src:"'.api_get_path(WEB_LIBRARY_PATH).'javascript/jquery.highlight.js"},
- { type:"script", id:"_fr3", src:"'.api_get_path(WEB_CODE_PATH).'glossary/glossary.js.php"}
- ]
- });';
- $web_odf_supported_files = DocumentManager::get_web_odf_extension_list();
- $web_odf_supported_files[] = 'pdf';
- if (in_array(strtolower($pathinfo['extension']), $web_odf_supported_files)) {
- $show_web_odf = true;
-
- $htmlHeadXtra[] = '
- <script>
- resizeIframe = function() {
- var bodyHeight = $("body").height();
- var topbarHeight = $("#topbar").height();
- $("#viewerJSContent").height((bodyHeight - topbarHeight));
- }
- $(document).ready(function() {
- $(window).resize(resizeIframe());
- });
- </script>'
- ;
- }
- $isChatFolder = false;
- if (isset($document_data['parents']) && isset($document_data['parents'][0])) {
- $chatFolder = $document_data['parents'][0];
- if (isset($chatFolder['path']) && $chatFolder['path'] == '/chat_files') {
- $isChatFolder = true;
- }
- }
- if ($isChatFolder) {
- $htmlHeadXtra[] = api_get_js('highlight/highlight.pack.js');
- $htmlHeadXtra[] = api_get_css(api_get_path(WEB_CSS_PATH).'chat.css');
- $htmlHeadXtra[] = api_get_css(
- api_get_path(WEB_LIBRARY_PATH).'javascript/highlight/styles/github.css'
- );
- $htmlHeadXtra[] = '
- <script>
- hljs.initHighlightingOnLoad();
- </script>';
- }
- $execute_iframe = true;
- if ($jplayer_supported) {
- $extension = api_strtolower($pathinfo['extension']);
- if ($extension == 'mp4') {
- $extension = 'm4v';
- }
- $js_path = api_get_path(WEB_LIBRARY_PATH).'javascript/';
- $htmlHeadXtra[] = '<link rel="stylesheet" href="'.$js_path.'jquery-jplayer/skin/blue.monday/css/jplayer.blue.monday.css" type="text/css">';
- $htmlHeadXtra[] = '<script type="text/javascript" src="'.$js_path.'jquery-jplayer/jplayer/jquery.jplayer.min.js"></script>';
- $jquery = '
- $("#jquery_jplayer_1").jPlayer({
- ready: function() {
- $(this).jPlayer("setMedia", {
- '.$extension.' : "'.$document_data['direct_url'].'"
- });
- },
- cssSelectorAncestor: "#jp_container_1",
- swfPath: "'.$js_path.'jquery-jplayer/jplayer/",
- supplied: "'.$extension.'",
- useStateClassSkin: true,
- autoBlur: false,
- keyEnabled: false,
- remainingDuration: true,
- toggleDuration: true,
- solution: "html, flash",
- errorAlerts: false,
- warningAlerts: false
- });
- ';
- $htmlHeadXtra[] = '<script>
- $(document).ready( function() {
- //Experimental changes to preview mp3, ogg files
- '.$jquery.'
- });
- </script>';
- $execute_iframe = false;
- }
- if ($show_web_odf) {
- $execute_iframe = false;
- }
- $is_freemind_available = $pathinfo['extension'] == 'mm' && api_get_setting('enable_freemind') == 'true';
- if ($is_freemind_available) {
- $execute_iframe = false;
- }
- if (!$jplayer_supported && $execute_iframe) {
- $htmlHeadXtra[] = '<script>
- <!--
- var jQueryFrameReadyConfigPath = \''.api_get_jquery_web_path().'\';
- -->
- </script>';
- $htmlHeadXtra[] = '<script type="text/javascript" src="'.api_get_path(WEB_LIBRARY_PATH).'javascript/jquery.frameready.js"></script>';
- $htmlHeadXtra[] = '<script>
- var updateContentHeight = function() {
- my_iframe = document.getElementById("mainFrame");
- if (my_iframe) {
- //this doesnt seem to work in IE 7,8,9
- new_height = my_iframe.contentWindow.document.body.scrollHeight;
- my_iframe.height = my_iframe.contentWindow.document.body.scrollHeight + "px";
- }
- };
- // Fixes the content height of the frame
- window.onload = function() {
- updateContentHeight();
- '.$js_glossary_in_documents.'
- }
- </script>';
- }
- if ($originIsLearnpath) {
- Display::display_reduced_header();
- } else {
- Display::display_header('');
- }
- echo '<div class="text-center">';
- $file_url = api_get_path(WEB_COURSE_PATH).$courseInfo['path'].'/document'.$header_file;
- $file_url_web = $file_url.'?'.api_get_cidreq();
- if ($show_web_odf) {
- $browser = api_get_navigator();
- $pdfUrl = api_get_path(WEB_LIBRARY_PATH).'javascript/ViewerJS/index.html#'.$file_url;
- if ($browser['name'] == 'Mozilla' && preg_match('|.*\.pdf|i', $header_file)) {
- $pdfUrl = $file_url;
- }
- echo '<div id="viewerJS">';
- echo '<iframe id="viewerJSContent" frameborder="0" allowfullscreen="allowfullscreen" webkitallowfullscreen style="width:100%;"
- src="' . $pdfUrl.'">
- </iframe>';
- echo '</div>';
- }
- echo '</div>';
- if ($jplayer_supported) {
- echo DocumentManager::generate_video_preview($document_data);
-
- Display::$global_template->assign('show_media_element', 0);
- }
- if ($is_freemind_available) {
- ?>
- <script type="text/javascript" src="<?php echo api_get_path(WEB_LIBRARY_PATH) ?>swfobject/swfobject.js"></script>
- <style type="text/css">
-
- height: 500px;
- padding-top:10px;
- }
- </style>
- <div id="flashcontent" onmouseover="giveFocus();">
- Flash plugin or Javascript are turned off.
- Activate both and reload to view the mindmap
- </div>
- <script>
- function giveFocus() {
- document.visorFreeMind.focus();
- }
- document.onload=giveFocus;
-
-
- function getMap(map){
- var result=map;
- var loc=document.location+'';
- if(loc.indexOf(".mm")>0 && loc.indexOf("?")>0){
- result=loc.substring(loc.indexOf("?")+1);
- }
- return result;
- }
- var fo = new FlashObject("<?php echo api_get_path(WEB_LIBRARY_PATH); ?>freeMindFlashBrowser/visorFreemind.swf", "visorFreeMind", "100%", "100%", 6, "#ffffff");
- fo.addParam("quality", "high");
-
- fo.addVariable("openUrl", "_blank");
- fo.addVariable("startCollapsedToLevel","3");
- fo.addVariable("maxNodeWidth","200");
-
- fo.addVariable("mainNodeShape","elipse");
- fo.addVariable("justMap","false");
- fo.addVariable("initLoadFile",getMap("<?php echo $file_url_web; ?>"));
- fo.addVariable("defaultToolTipWordWrap",200);
- fo.addVariable("offsetX","left");
- fo.addVariable("offsetY","top");
- fo.addVariable("buttonsPos","top");
- fo.addVariable("min_alpha_buttons",20);
- fo.addVariable("max_alpha_buttons",100);
- fo.addVariable("scaleTooltips","false");
-
-
-
-
-
-
-
-
-
-
-
-
- fo.write("flashcontent");
-
- </script>
- <?php
- }
- if ($execute_iframe) {
- if ($isChatFolder) {
- $content = Security::remove_XSS(file_get_contents($file_url_sys));
- echo $content;
- } else {
- 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>';
- }
- }
- Display::display_footer();
|